intable 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -1
  3. package/dist/__uno.css +1 -1
  4. package/dist/chevron-right.js +3 -5
  5. package/dist/components/Columns.js +50 -84
  6. package/dist/components/DocTree.js +21 -29
  7. package/dist/components/Menu.js +81 -105
  8. package/dist/components/Popover.js +23 -31
  9. package/dist/components/Render.js +10 -11
  10. package/dist/components/Split.js +34 -46
  11. package/dist/components/Tree.js +38 -57
  12. package/dist/components/utils.js +4 -6
  13. package/dist/hooks/index.d.ts +3 -2
  14. package/dist/hooks/index.js +93 -128
  15. package/dist/hooks/useDir.js +22 -39
  16. package/dist/hooks/useSort.d.ts +18 -0
  17. package/dist/hooks/useSort.js +83 -0
  18. package/dist/hooks/useVirtualizer.js +43 -68
  19. package/dist/index.d.ts +8 -2
  20. package/dist/index.js +175 -213
  21. package/dist/loading.js +3 -5
  22. package/dist/plugins/CellMergePlugin.d.ts +12 -0
  23. package/dist/plugins/CellMergePlugin.js +2 -0
  24. package/dist/plugins/CellSelectionPlugin.js +89 -125
  25. package/dist/plugins/CommandPlugin.js +3 -6
  26. package/dist/plugins/CopyPastePlugin.js +24 -37
  27. package/dist/plugins/DiffPlugin.js +33 -45
  28. package/dist/plugins/DragPlugin.d.ts +14 -0
  29. package/dist/plugins/DragPlugin.js +47 -0
  30. package/dist/plugins/EditablePlugin.js +88 -139
  31. package/dist/plugins/ExpandPlugin.js +26 -30
  32. package/dist/plugins/HistoryPlugin.js +16 -21
  33. package/dist/plugins/MenuPlugin.js +51 -76
  34. package/dist/plugins/RenderPlugin/components.js +45 -63
  35. package/dist/plugins/RenderPlugin/index.js +29 -42
  36. package/dist/plugins/ResizePlugin.d.ts +2 -2
  37. package/dist/plugins/ResizePlugin.js +71 -94
  38. package/dist/plugins/RowGroupPlugin.js +57 -73
  39. package/dist/plugins/RowSelectionPlugin.js +31 -42
  40. package/dist/plugins/VirtualScrollPlugin.js +54 -79
  41. package/dist/plus.js +3 -5
  42. package/dist/style.css +2 -184
  43. package/dist/utils.d.ts +1 -0
  44. package/dist/utils.js +46 -64
  45. package/dist/wc.js +11 -11
  46. package/dist/x.js +3 -5
  47. package/package.json +3 -2
  48. package/dist/plugins/DragColumnPlugin.d.ts +0 -2
  49. package/dist/plugins/DragColumnPlugin.js +0 -4
@@ -0,0 +1,18 @@
1
+ import { type MaybeAccessor } from '@solid-primitives/utils';
2
+ type Awaitable<T> = T | Promise<T>;
3
+ interface UseSortOption {
4
+ enable?: boolean;
5
+ guideLine: any;
6
+ draggable: (el: HTMLElement) => Awaitable<boolean>;
7
+ dragover: (el: HTMLElement) => boolean;
8
+ children: (el: HTMLElement) => HTMLElement[];
9
+ dragend: () => void;
10
+ }
11
+ export declare const useSort: (el: MaybeAccessor<HTMLElement | undefined>, opt: UseSortOption) => {
12
+ style: any;
13
+ drag: any;
14
+ over: any;
15
+ rel: any;
16
+ type: string;
17
+ };
18
+ export {};
@@ -0,0 +1,83 @@
1
+ import { findAsync } from "../utils.js";
2
+ import { Portal, createComponent, memo, mergeProps, spread, template } from "solid-js/web";
3
+ import { createMutable, reconcile } from "solid-js/store";
4
+ import { createEventListenerMap } from "@solid-primitives/event-listener";
5
+ import { access } from "@solid-primitives/utils";
6
+ var _tmpl$ = /* @__PURE__ */ template("<div>");
7
+ const useSort = (l, f) => {
8
+ f = mergeProps({ enable: !0 }, f);
9
+ let p = 0;
10
+ createEventListenerMap(() => f.enable ? access(l) : void 0, {
11
+ async pointerdown(i) {
12
+ let a = p, o = await findAsync(i.composedPath(), (e) => e instanceof HTMLElement && f.draggable(e));
13
+ a == p && o && (i.stopPropagation(), h.drag = o, h.drag?.setAttribute("draggable", "true"));
14
+ },
15
+ pointerup() {
16
+ p++, m();
17
+ },
18
+ pointermove() {
19
+ p++;
20
+ },
21
+ dragstart(e) {
22
+ e.dataTransfer.setDragImage(document.createElement("img"), 0, 0);
23
+ },
24
+ dragover(e) {
25
+ if (!h.drag) return;
26
+ let i = h.over = e.composedPath().filter((e) => e instanceof HTMLElement).find((e) => f.dragover(e)) ?? h.over;
27
+ if (!i) return;
28
+ e.preventDefault(), e.stopPropagation();
29
+ let a = f.children(i);
30
+ if (a) {
31
+ let i = 0, o = Infinity, s = "";
32
+ a.forEach((a, c) => {
33
+ let l = getComputedStyle(a).display, u = ["table-cell", "inline"].some((e) => l.includes(e)), d = a.getBoundingClientRect();
34
+ if (u) {
35
+ let a = Math.sqrt((e.clientX - d.x) ** 2 + (e.clientY - d.y + d.height / 2) ** 2);
36
+ a < o && (i = c, o = a, s = "l"), a = Math.sqrt((e.clientX - d.right) ** 2 + (e.clientY - d.y + d.height / 2) ** 2), a < o && (i = c, o = a, s = "r");
37
+ } else {
38
+ let a = Math.sqrt((e.clientY - d.y) ** 2 + (e.clientX - d.x + d.width / 2) ** 2);
39
+ a < o && (i = c, o = a, s = "t"), a = Math.sqrt((e.clientY - d.bottom) ** 2 + (e.clientX - d.x + d.width / 2) ** 2), a < o && (i = c, o = a, s = "b");
40
+ }
41
+ });
42
+ let c = a[i].getBoundingClientRect(), l = s == "l" || s == "r", u = s == "t" || s == "b";
43
+ h.style = {
44
+ width: `${u ? c.width : 3}px`,
45
+ height: `${u ? 3 : c.height}px`,
46
+ translate: `${u ? c.x : (s == "l" ? c.x : c.right) - 3 / 2}px ${l ? c.y : (s == "t" ? c.y : c.bottom) - 3 / 2}px`
47
+ }, h.rel = a[i], h.type = s == "l" || s == "t" ? "before" : "after";
48
+ } else {
49
+ let e = i.getBoundingClientRect();
50
+ h.style = {
51
+ width: e.width,
52
+ height: e.height,
53
+ translate: `${e.x}px ${e.y}px`
54
+ }, h.rel = i, h.type = "inner";
55
+ }
56
+ },
57
+ dragend() {
58
+ m();
59
+ }
60
+ });
61
+ function m() {
62
+ h.drag?.removeAttribute("draggable"), h.drag && h.rel && f.dragend?.(), reconcile({})(h);
63
+ }
64
+ let h = createMutable({
65
+ style: void 0,
66
+ drag: void 0,
67
+ over: void 0,
68
+ rel: void 0,
69
+ type: ""
70
+ });
71
+ return memo(() => memo(() => !!h.style)() && createComponent(Portal, {
72
+ get mount() {
73
+ return access(l);
74
+ },
75
+ get children() {
76
+ var e = _tmpl$();
77
+ return spread(e, mergeProps(() => f.guideLine, { get style() {
78
+ return h.style;
79
+ } }), !1, !1), e;
80
+ }
81
+ })), h;
82
+ };
83
+ export { useSort };
@@ -3,89 +3,64 @@ import { createMutable } from "solid-js/store";
3
3
  import { keyBy, uniqBy } from "es-toolkit";
4
4
  import { createElementSize } from "@solid-primitives/resize-observer";
5
5
  import { createScrollPosition } from "@solid-primitives/scroll";
6
- function useVirtualizer(opt) {
7
- opt = mergeProps({
6
+ function useVirtualizer(d) {
7
+ d = mergeProps({
8
8
  overscan: 0,
9
9
  batch: 0,
10
- enable: true
11
- }, opt);
12
- const size = createElementSize(opt.getScrollElement);
13
- const pos = createScrollPosition(opt.getScrollElement);
14
- const y = createMemo(() => opt.horizontal ? pos.x : pos.y);
15
- const h = createMemo(() => opt.horizontal ? size.width : size.height);
16
- const y2 = createMemo(() => y() + h());
17
- const sizes = createMutable(Array(opt.count));
10
+ enable: !0
11
+ }, d);
12
+ let f = createElementSize(d.getScrollElement), p = createScrollPosition(d.getScrollElement), m = createMemo(() => d.horizontal ? p.x : p.y), h = createMemo(() => d.horizontal ? f.width : f.height), g = createMemo(() => m() + h()), _ = createMutable(Array(d.count));
18
13
  createComputed(() => {
19
- const { count } = opt;
14
+ let { count: e } = d;
20
15
  untrack(() => {
21
- for (let i = 0; i < count; i++) sizes[i] ||= opt.estimateSize(i);
16
+ for (let o = 0; o < e; o++) _[o] ||= d.estimateSize(o);
22
17
  });
23
18
  });
24
- const [items, setItems] = createSignal([]);
19
+ let [v, y] = createSignal([]);
25
20
  createRenderEffect(() => {
26
- const { count } = opt;
27
- let arr = Array(count);
28
- let t = 0;
29
- for (let i = 0; i < count; i++) {
30
- arr[i] = {
31
- start: t,
32
- end: t + sizes[i],
33
- index: i
34
- };
35
- t = arr[i].end;
36
- }
37
- setItems(arr);
21
+ let { count: e } = d, o = Array(e), s = 0;
22
+ for (let c = 0; c < e; c++) o[c] = {
23
+ start: s,
24
+ end: s + _[c],
25
+ index: c
26
+ }, s = o[c].end;
27
+ y(o);
38
28
  });
39
- const start = createMemo((prev) => {
40
- const { batch: batch$1, overscan = 0 } = opt;
41
- let i = findClosestIndex(items(), (e) => e.start > y() ? -1 : e.end < y() ? 1 : 0);
42
- i -= overscan;
43
- if (batch$1) if (i > prev) i = i <= prev + batch$1 ? prev : i > prev + batch$1 * 2 ? i : prev + batch$1;
44
- else i -= batch$1;
45
- return Math.max(i, 0);
46
- }, 0);
47
- const end = createMemo((prev) => {
48
- const { batch: batch$1, overscan = 0 } = opt;
49
- let i = findClosestIndex(items(), (e) => e.start > y2() ? -1 : e.end < y2() ? 1 : 0);
50
- i += overscan;
51
- if (batch$1) if (i < prev) i = i >= prev - batch$1 ? prev : i < prev - batch$1 * 2 ? i : prev - batch$1;
52
- else i += batch$1;
53
- return Math.min(i, opt.count - 1);
54
- }, 0);
55
- const items2 = createMemo(() => {
56
- if (!opt.enable) return items();
57
- let arr = items().slice(start(), end() + 1);
58
- if (opt.extras) {
59
- arr.push(...opt.extras()?.map((i) => items()[i]) || []);
60
- arr = uniqBy(arr, (e) => e.index).sort((a, b) => a.index - b.index);
61
- }
62
- return arr;
29
+ let b = createMemo((e) => {
30
+ let { batch: o, overscan: s = 0 } = d, c = C(v(), (e) => e.start > m() ? -1 : e.end < m() ? 1 : 0);
31
+ return c -= s, o && (c > e ? c = c <= e + o ? e : c > e + o * 2 ? c : e + o : c -= o), Math.max(c, 0);
32
+ }, 0), x = createMemo((e) => {
33
+ let { batch: o, overscan: s = 0 } = d, c = C(v(), (e) => e.start > g() ? -1 : e.end < g() ? 1 : 0);
34
+ return c += s, o && (c < e ? c = c >= e - o ? e : c < e - o * 2 ? c : e - o : c += o), Math.min(c, d.count - 1);
35
+ }, 0), S = createMemo(() => {
36
+ if (!d.enable) return v();
37
+ let e = v().slice(b(), x() + 1);
38
+ return d.extras && (e.push(...d.extras()?.map((e) => v()[e]) || []), e = uniqBy(e, (e) => e.index).sort((e, o) => e.index - o.index)), e;
63
39
  });
64
- function findClosestIndex(arr, fn) {
65
- let l = 0, r = arr.length - 1;
66
- while (l < r) {
67
- const m = l + Math.floor((r - l) / 2);
68
- const v = fn(arr[m]);
69
- if (v < 0 && r != m) r = m;
70
- else if (v > 0 && l != m) l = m;
71
- else return m;
40
+ function C(e, o) {
41
+ let s = 0, c = e.length - 1;
42
+ for (; s < c;) {
43
+ let l = s + Math.floor((c - s) / 2), u = o(e[l]);
44
+ if (u < 0 && c != l) c = l;
45
+ else if (u > 0 && s != l) s = l;
46
+ else return l;
72
47
  }
73
- return l;
48
+ return s;
74
49
  }
75
50
  return {
76
- options: opt,
77
- getTotalSize: () => items()[items().length - 1]?.end || 0,
78
- resizeItem: (i, size$1) => {
79
- if (i <= start() && size$1 != sizes[i]) {
80
- const el = opt.getScrollElement();
81
- if ((opt.horizontal ? el.scrollLeft : el.scrollTop) != 0) opt.horizontal ? el.scrollLeft += size$1 - sizes[i] : el.scrollTop += size$1 - sizes[i];
51
+ options: d,
52
+ getTotalSize: () => v()[v().length - 1]?.end || 0,
53
+ resizeItem: (e, o) => {
54
+ if (e <= b() && o != _[e]) {
55
+ let s = d.getScrollElement();
56
+ (d.horizontal ? s.scrollLeft : s.scrollTop) != 0 && (d.horizontal ? s.scrollLeft += o - _[e] : s.scrollTop += o - _[e]);
82
57
  }
83
- sizes[i] = size$1;
58
+ _[e] = o;
84
59
  },
85
- getVirtualItems: items2,
60
+ getVirtualItems: S,
86
61
  getVirtualItem: (() => {
87
- const keybyed = createMemo(() => keyBy(items2(), (e) => e.index));
88
- return (i) => keybyed()[i];
62
+ let e = createMemo(() => keyBy(S(), (e) => e.index));
63
+ return (o) => e()[o];
89
64
  })()
90
65
  };
91
66
  }
package/dist/index.d.ts CHANGED
@@ -9,8 +9,10 @@ import './plugins/MenuPlugin';
9
9
  import './plugins/CommandPlugin';
10
10
  import './plugins/RowSelectionPlugin';
11
11
  import './plugins/ResizePlugin';
12
+ import './plugins/DragPlugin';
12
13
  export declare const Ctx: import("solid-js").Context<{
13
14
  props: TableProps2;
15
+ store: TableStore;
14
16
  }>;
15
17
  type Requireds<T, K extends keyof T> = Pri<Omit<T, K> & Required<Pick<T, K>>>;
16
18
  type Pri<T> = {
@@ -27,6 +29,7 @@ export interface Plugin {
27
29
  store?: (store: TableStore) => Partial<TableStore> | void;
28
30
  rewriteProps?: ProcessProps;
29
31
  layers?: Component<TableStore>[];
32
+ onMount?: (store: TableStore) => void;
30
33
  }
31
34
  export interface TableProps {
32
35
  columns?: TableColumn[];
@@ -51,11 +54,13 @@ export interface TableProps {
51
54
  }>;
52
55
  EachRows?: typeof For;
53
56
  EachCells?: typeof For<TableColumn[], JSX.Element>;
54
- cellClass?: ((props: Omit<TDProps, 'y'> & {
57
+ cellClass?: ((props: Omit<TDProps, 'y' | 'data'> & {
55
58
  y?: number;
59
+ data?: any;
56
60
  }) => string) | string;
57
- cellStyle?: ((props: Omit<TDProps, 'y'> & {
61
+ cellStyle?: ((props: Omit<TDProps, 'y' | 'data'> & {
58
62
  y?: number;
63
+ data?: any;
59
64
  }) => string) | string;
60
65
  renderer?: (comp: (props: any) => JSX.Element) => ((props: any) => JSX.Element);
61
66
  plugins?: Plugin[];
@@ -107,6 +112,7 @@ export interface TableStore extends Obj {
107
112
  height: number;
108
113
  }>[];
109
114
  internal: symbol;
115
+ raw: symbol;
110
116
  props?: TableProps2;
111
117
  rawProps: TableProps;
112
118
  plugins: Plugin[];