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
@@ -3,147 +3,111 @@ import { Ctx } from "../index.js";
3
3
  import { createComponent, memo, mergeProps, template } from "solid-js/web";
4
4
  import { batch, createMemo, useContext } from "solid-js";
5
5
  import { combineProps } from "@solid-primitives/props";
6
- var _tmpl$ = /* @__PURE__ */ template(`<div class=area>`);
7
- var inrange = (v, min, max) => v <= max && v >= min;
6
+ var _tmpl$ = /* @__PURE__ */ template("<div class=area>"), inrange = (e, a, o) => e <= o && e >= a;
8
7
  const CellSelectionPlugin = {
9
8
  store: () => ({ selected: {
10
9
  start: [],
11
10
  end: []
12
11
  } }),
13
- commands: (store) => ({ getAreaRows() {
14
- const { start, end } = store.selected;
15
- const [y1, y2] = [start[1], end[1]].sort((a, b) => a - b);
16
- return store.props.data.slice(y1, y2 + 1);
12
+ commands: (e) => ({ getAreaRows() {
13
+ let { start: a, end: o } = e.selected, [s, c] = [a[1], o[1]].sort((e, a) => e - a);
14
+ return e.props.data.slice(s, c + 1);
17
15
  } }),
18
16
  rewriteProps: {
19
- Th: ({ Th }, { store }) => (o) => {
20
- const clazz = createMemo(() => {
21
- const { start, end } = store.selected;
22
- return inrange(o.x, ...[start[0], end[0]].sort((a, b) => a - b)) ? "col-range-highlight" : "";
17
+ Table: ({ Table: c }, { store: l }) => (u) => {
18
+ let { props: f } = useContext(Ctx);
19
+ l.cellSelectionRect ??= createMemo(() => {
20
+ let { start: e, end: a } = l.selected, o = [e[0], a[0]].sort((e, a) => e - a), s = [e[1], a[1]].sort((e, a) => e - a);
21
+ return {
22
+ xs: o,
23
+ ys: s
24
+ };
25
+ }), usePointerDrag(() => l.table, {
26
+ preventDefault: !1,
27
+ start(e, a, o) {
28
+ batch(() => {
29
+ let o = (e) => e.composedPath().find((e) => e.tagName == "TH" || e.tagName == "TD"), s = (e) => [e.getAttribute("x"), e.getAttribute("y")], c = o(e);
30
+ if (c && !(e.buttons != 1 && c.classList.contains("range-selected"))) {
31
+ if (c.tagName == "TH") {
32
+ let [e, u] = s(c);
33
+ if (e == null) return;
34
+ l.selected.start = [+e, 0], l.selected.end = [+e, Infinity], a((e) => {
35
+ let a = o(e);
36
+ if (!a) return;
37
+ let [c, u] = s(a);
38
+ c != null && (l.selected.end = [+c, Infinity]);
39
+ });
40
+ }
41
+ if (c.classList.contains("index")) {
42
+ let [e, u] = s(c);
43
+ if (e == null || u == null) return;
44
+ l.selected.start = [0, +u], l.selected.end = [Infinity, +u], a((e) => {
45
+ let a = o(e);
46
+ if (!a) return;
47
+ let [c, u] = s(a);
48
+ c == null || u == null || (l.selected.end = [Infinity, +u]);
49
+ });
50
+ } else if (c.tagName == "TD") {
51
+ let [e, u] = s(c);
52
+ if (e == null || u == null) return;
53
+ l.selected.start = [+e, +u], l.selected.end = [...l.selected.start], a((e) => {
54
+ let a = o(e);
55
+ if (!a) return;
56
+ let [c, u] = s(a);
57
+ c == null || u == null || (l.selected.end = [+c, +u]);
58
+ });
59
+ }
60
+ }
61
+ });
62
+ }
63
+ }), useTinykeys(() => l.table, {
64
+ ArrowLeft: () => {
65
+ let { start: e, end: a } = l.selected;
66
+ e[0] = a[0] = Math.max(e[0] - 1, 0), a[1] = e[1], p();
67
+ },
68
+ ArrowRight: () => {
69
+ let { start: e, end: a } = l.selected;
70
+ e[0] = a[0] = Math.min(e[0] + 1, f.columns.length - 1), a[1] = e[1], p();
71
+ },
72
+ ArrowUp: () => {
73
+ let { start: e, end: a } = l.selected;
74
+ e[1] = a[1] = Math.max(e[1] - 1, 0), a[0] = e[0], p();
75
+ },
76
+ ArrowDown: () => {
77
+ let { start: e, end: a } = l.selected;
78
+ e[1] = a[1] = Math.min(e[1] + 1, f.data.length - 1), a[0] = e[0], p();
79
+ }
23
80
  });
24
- const mo = combineProps(o, { get class() {
25
- return clazz();
81
+ let p = () => {
82
+ let e = l.table.querySelector(`td[x="${l.selected.start[0]}"][y="${l.selected.start[1]}"]`);
83
+ e?.scrollIntoViewIfNeeded(!1), e?.focus();
84
+ };
85
+ return u = combineProps({ class: "select-none" }, u), createComponent(c, u);
86
+ },
87
+ Th: ({ Th: e }, { store: a }) => (o) => {
88
+ let u = createMemo(() => {
89
+ let { start: e, end: s } = a.selected;
90
+ return inrange(o.x, ...[e[0], s[0]].sort((e, a) => e - a)) ? "col-range-highlight" : "";
91
+ }), d = combineProps(o, { get class() {
92
+ return u();
26
93
  } });
27
- return createComponent(Th, mergeProps(mo, { get children() {
28
- return [memo(() => mo.children), memo(() => memo(() => !!clazz())() && _tmpl$())];
94
+ return createComponent(e, mergeProps(d, { get children() {
95
+ return [memo(() => d.children), memo(() => memo(() => !!u())() && _tmpl$())];
29
96
  } }));
30
97
  },
31
- Td: ({ Td }, { store }) => (o) => {
32
- const clazz = createMemo(() => {
33
- let clazz$1 = "";
34
- const { xs, ys } = store.cellSelectionRect();
35
- const inx = inrange(o.x, xs[0], xs[1]);
36
- const iny = inrange(o.y, ys[0], ys[1]);
37
- if (inx && iny) {
38
- clazz$1 += "range-selected ";
39
- if (o.x == xs[0]) clazz$1 += "range-selected-l ";
40
- if (o.x == xs[1]) clazz$1 += "range-selected-r ";
41
- if (o.y == ys[0]) clazz$1 += "range-selected-t ";
42
- if (o.y == ys[1]) clazz$1 += "range-selected-b ";
43
- }
44
- if (o.x == 0 && iny) clazz$1 += "row-range-highlight ";
45
- return clazz$1;
46
- });
47
- const mo = combineProps(o, {
98
+ Td: ({ Td: e }, { store: a }) => (o) => {
99
+ let u = createMemo(() => {
100
+ let e = "", { xs: s, ys: c } = a.cellSelectionRect(), l = inrange(o.x, s[0], s[1]), u = inrange(o.y, c[0], c[1]);
101
+ return l && u && (e += "range-selected ", o.x == s[0] && (e += "range-selected-l "), o.x == s[1] && (e += "range-selected-r "), o.y == c[0] && (e += "range-selected-t "), o.y == c[1] && (e += "range-selected-b ")), o.x == 0 && u && (e += "row-range-highlight "), e;
102
+ }), d = combineProps(o, {
48
103
  get class() {
49
- return clazz();
104
+ return u();
50
105
  },
51
106
  tabindex: -1
52
107
  });
53
- return createComponent(Td, mergeProps(mo, { get children() {
54
- return [memo(() => mo.children), memo(() => memo(() => !!clazz())() && _tmpl$())];
108
+ return createComponent(e, mergeProps(d, { get children() {
109
+ return [memo(() => d.children), memo(() => memo(() => !!u())() && _tmpl$())];
55
110
  } }));
56
- },
57
- Table: ({ Table }, { store }) => (o) => {
58
- const { props } = useContext(Ctx);
59
- store.cellSelectionRect ??= createMemo(() => {
60
- const { start, end } = store.selected;
61
- const xs = [start[0], end[0]].sort((a, b) => a - b);
62
- const ys = [start[1], end[1]].sort((a, b) => a - b);
63
- return {
64
- xs,
65
- ys
66
- };
67
- });
68
- usePointerDrag(() => store.table, { start(e, move, end) {
69
- batch(() => {
70
- const findCell = (e$1) => e$1.composedPath().find((e$2) => e$2.tagName == "TH" || e$2.tagName == "TD");
71
- const getXY = (cell$1) => [cell$1.getAttribute("x"), cell$1.getAttribute("y")];
72
- const cell = findCell(e);
73
- if (!cell) return;
74
- if (e.buttons != 1 && cell.classList.contains("range-selected")) return;
75
- if (cell.tagName == "TH") {
76
- const [x, y] = getXY(cell);
77
- if (x == null) return;
78
- store.selected.start = [+x, 0];
79
- store.selected.end = [+x, Infinity];
80
- move((e$1) => {
81
- const cell$1 = findCell(e$1);
82
- if (!cell$1) return;
83
- const [x$1, y$1] = getXY(cell$1);
84
- if (x$1 == null) return;
85
- store.selected.end = [+x$1, Infinity];
86
- });
87
- }
88
- if (cell.classList.contains("index")) {
89
- const [x, y] = getXY(cell);
90
- if (x == null || y == null) return;
91
- store.selected.start = [0, +y];
92
- store.selected.end = [Infinity, +y];
93
- move((e$1) => {
94
- const cell$1 = findCell(e$1);
95
- if (!cell$1) return;
96
- const [x$1, y$1] = getXY(cell$1);
97
- if (x$1 == null || y$1 == null) return;
98
- store.selected.end = [Infinity, +y$1];
99
- });
100
- } else if (cell.tagName == "TD") {
101
- const [x, y] = getXY(cell);
102
- if (x == null || y == null) return;
103
- store.selected.start = [+x, +y];
104
- store.selected.end = [...store.selected.start];
105
- move((e$1) => {
106
- const cell$1 = findCell(e$1);
107
- if (!cell$1) return;
108
- const [x$1, y$1] = getXY(cell$1);
109
- if (x$1 == null || y$1 == null) return;
110
- store.selected.end = [+x$1, +y$1];
111
- });
112
- }
113
- });
114
- } });
115
- useTinykeys(() => store.table, {
116
- "ArrowLeft": () => {
117
- const { start, end } = store.selected;
118
- start[0] = end[0] = Math.max(start[0] - 1, 0);
119
- end[1] = start[1];
120
- scrollIntoView();
121
- },
122
- "ArrowRight": () => {
123
- const { start, end } = store.selected;
124
- start[0] = end[0] = Math.min(start[0] + 1, props.columns.length - 1);
125
- end[1] = start[1];
126
- scrollIntoView();
127
- },
128
- "ArrowUp": () => {
129
- const { start, end } = store.selected;
130
- start[1] = end[1] = Math.max(start[1] - 1, 0);
131
- end[0] = start[0];
132
- scrollIntoView();
133
- },
134
- "ArrowDown": () => {
135
- const { start, end } = store.selected;
136
- start[1] = end[1] = Math.min(start[1] + 1, props.data.length - 1);
137
- end[0] = start[0];
138
- scrollIntoView();
139
- }
140
- });
141
- const scrollIntoView = () => {
142
- const cell = store.table.querySelector(`td[x="${store.selected.start[0]}"][y="${store.selected.start[1]}"]`);
143
- cell?.scrollIntoViewIfNeeded(false);
144
- cell?.focus();
145
- };
146
- return createComponent(Table, o);
147
111
  }
148
112
  }
149
113
  };
@@ -1,9 +1,6 @@
1
1
  import { createComponent } from "solid-js/web";
2
2
  import { createComputed } from "solid-js";
3
- const CommandPlugin = { rewriteProps: { Table: ({ Table }, { store }) => (o) => {
4
- createComputed(() => {
5
- store.commands = store.plugins.reduce((o$1, e) => Object.assign(o$1, e.commands?.(store, { ...o$1 })), {});
6
- });
7
- return createComponent(Table, o);
8
- } } };
3
+ const CommandPlugin = { rewriteProps: { Table: ({ Table: n }, { store: r }) => (i) => (createComputed(() => {
4
+ r.commands = r.plugins.reduce((e, t) => Object.assign(e, t.commands?.(r, { ...e })), {});
5
+ }), createComponent(n, i)) } };
9
6
  export { CommandPlugin };
@@ -3,51 +3,38 @@ import { createComponent } from "solid-js/web";
3
3
  import { createEffect } from "solid-js";
4
4
  import { combineProps } from "@solid-primitives/props";
5
5
  const ClipboardPlugin = {
6
- rewriteProps: { Table: ({ Table }, { store }) => (o) => {
7
- let el;
8
- useTinykeys(() => el, {
6
+ rewriteProps: { Table: ({ Table: i }, { store: a }) => (o) => {
7
+ let s;
8
+ return useTinykeys(() => s, {
9
9
  "Control+C": () => {
10
- store.commands.copy();
11
- el.classList.add("copied");
10
+ a.commands.copy(), s.classList.add("copied");
12
11
  },
13
- "Control+V": () => store.commands.paste()
14
- });
15
- createEffect(() => {
16
- JSON.stringify(store.selected);
17
- el.classList.remove("copied");
18
- });
19
- o = combineProps({
20
- ref: (e) => el = e,
12
+ "Control+V": () => a.commands.paste()
13
+ }), createEffect(() => {
14
+ JSON.stringify(a.selected), s.classList.remove("copied");
15
+ }), o = combineProps({
16
+ ref: (e) => s = e,
21
17
  tabindex: -1
22
- }, o);
23
- return createComponent(Table, o);
18
+ }, o), createComponent(i, o);
24
19
  } },
25
- menus: (store) => [],
26
- commands: (store) => ({
20
+ menus: (e) => [],
21
+ commands: (e) => ({
27
22
  copy: () => {
28
- const { start, end } = store.selected;
29
- if (start.length == 0) return;
30
- const [x1, x2] = [start[0], end[0]].sort((a, b) => a - b);
31
- const [y1, y2] = [start[1], end[1]].sort((a, b) => a - b);
32
- const cols = store.props.columns.slice(x1, x2 + 1);
33
- const text = store.props.data.slice(y1, y2 + 1).map((row) => cols.map((col) => row[col.id])).map((row) => row.join(" ")).join("\n");
34
- navigator.clipboard.writeText(text);
23
+ let { start: t, end: n } = e.selected;
24
+ if (t.length == 0) return;
25
+ let [r, i] = [t[0], n[0]].sort((e, t) => e - t), [a, o] = [t[1], n[1]].sort((e, t) => e - t), s = e.props.columns.slice(r, i + 1), c = e.props.data.slice(a, o + 1).map((e) => s.map((t) => e[t.id])).map((e) => e.join(" ")).join("\n");
26
+ navigator.clipboard.writeText(c);
35
27
  },
36
28
  paste: async () => {
37
- const { start, end } = store.selected;
38
- if (start.length == 0) return;
39
- const arr2 = (await navigator.clipboard.readText()).split("\n").map((row) => row.split(" "));
40
- const cols = store.props.columns.slice(start[0], start[0] + arr2[0].length);
41
- const data = store.props.data.slice();
42
- arr2.forEach((row, y) => {
43
- row = Object.fromEntries(cols.map((col, x) => [col.id, row[x]]));
44
- data[start[1] + y] = {
45
- ...data[start[1] + y],
46
- ...row
29
+ let { start: t, end: n } = e.selected;
30
+ if (t.length == 0) return;
31
+ let r = (await navigator.clipboard.readText()).split("\n").map((e) => e.split(" ")), i = e.props.columns.slice(t[0], t[0] + r[0].length), a = e.props.data.slice();
32
+ r.forEach((e, n) => {
33
+ e = Object.fromEntries(i.map((t, n) => [t.id, e[n]])), a[t[1] + n] = {
34
+ ...a[t[1] + n],
35
+ ...e
47
36
  };
48
- });
49
- store.selected.end = [start[0] + cols.length - 1, Math.min(start[1] + arr2.length - 1, ctx.props.data.length - 1)];
50
- store.props.onDataChange?.(data);
37
+ }), e.selected.end = [t[0] + i.length - 1, Math.min(t[1] + r.length - 1, ctx.props.data.length - 1)], e.props.onDataChange?.(a);
51
38
  }
52
39
  })
53
40
  };
@@ -6,62 +6,50 @@ import { isEqual, keyBy } from "es-toolkit";
6
6
  import { createLazyMemo } from "@solid-primitives/memo";
7
7
  import { v4 } from "uuid";
8
8
  import { diffArrays } from "diff";
9
- var DEL = Symbol("del");
10
- var NEW = Symbol("new");
9
+ var DEL = Symbol("del"), NEW = Symbol("new");
11
10
  const DiffPlugin = {
12
11
  priority: Infinity,
13
- store: (store) => {
14
- const data = store.rawProps.data || [];
15
- data.forEach((row) => unwrap(row)[store.rawProps.rowKey] ??= v4());
16
- return {
17
- diffData: structuredClone(unwrap(data || [])),
18
- diffDataKeyed: createLazyMemo(() => keyBy(store.diffData, (e) => e[store.props.rowKey]))
12
+ store: (e) => {
13
+ let r = e.rawProps.data || [];
14
+ return r.forEach((r) => unwrap(r)[e.rawProps.rowKey] ??= v4()), {
15
+ diffData: structuredClone(unwrap(r || [])),
16
+ diffDataKeyed: createLazyMemo(() => keyBy(e.diffData, (r) => r[e.props.rowKey]))
19
17
  };
20
18
  },
21
- commands: (store) => ({ async diffCommit(data = store.rawProps.data || []) {
22
- const { rowKey } = store.props || {};
23
- data.forEach((row) => unwrap(row)[rowKey] ??= v4());
24
- data = structuredClone(unwrap(data));
25
- const added = [], removed = [], changed = [];
26
- const keyed = keyBy(data, (e) => e[rowKey]);
27
- for (const e of data) {
28
- const old = store.diffDataKeyed()[e[rowKey]];
29
- if (!old) added.push(e);
30
- else if (!isEqual(e, old)) changed.push(e);
19
+ commands: (e) => ({ async diffCommit(r = e.rawProps.data || []) {
20
+ let { rowKey: a } = e.props || {};
21
+ r.forEach((e) => unwrap(e)[a] ??= v4()), r = structuredClone(unwrap(r));
22
+ let c = [], l = [], u = [], d = keyBy(r, (e) => e[a]);
23
+ for (let i of r) {
24
+ let r = e.diffDataKeyed()[i[a]];
25
+ r ? isEqual(i, r) || u.push(i) : c.push(i);
31
26
  }
32
- for (const e of store.diffData) !keyed[e[rowKey]] && removed.push(e);
33
- await store.props.diff?.onCommit?.(data, {
34
- added,
35
- removed,
36
- changed
37
- });
38
- added[NEW] = 0;
39
- store.diffData = data;
27
+ for (let r of e.diffData) !d[r[a]] && l.push(r);
28
+ await e.props.diff?.onCommit?.(r, {
29
+ added: c,
30
+ removed: l,
31
+ changed: u
32
+ }), c[NEW] = 0, e.diffData = r;
40
33
  } }),
41
34
  rewriteProps: {
42
- diff: ({ diff }) => ({
43
- added: true,
44
- removed: true,
45
- changed: true,
46
- ...diff
35
+ diff: ({ diff: e }) => ({
36
+ added: !0,
37
+ removed: !0,
38
+ changed: !0,
39
+ ...e
47
40
  }),
48
- data: ({ data }, { store }) => {
49
- const { rowKey, diff } = store.props || {};
50
- return diffArrays(store.diffData || [], data, { comparator: (a, b) => a[rowKey] == b[rowKey] }).flatMap((e) => e.added ? e.value.map((e$1) => (e$1[NEW] = 1, e$1)) : e.removed ? diff.removed ? e.value.map((e$1) => ({
51
- ...e$1,
41
+ data: ({ data: e }, { store: r }) => {
42
+ let { rowKey: i, diff: a } = r.props || {};
43
+ return diffArrays(r.diffData || [], e, { comparator: (e, r) => e[i] == r[i] }).flatMap((e) => e.added ? e.value.map((e) => (e[NEW] = 1, e)) : e.removed ? a.removed ? e.value.map((e) => ({
44
+ ...e,
52
45
  [DEL]: 1,
53
- [store.internal]: 1
46
+ [r.internal]: 1
54
47
  })) : [] : e.value);
55
48
  },
56
- Table: ({ Table }, { store }) => (o) => {
57
- useTinykeys(() => store.table, { "Control+S": () => store.commands.diffCommit() });
58
- o = combineProps({ tabindex: -1 }, o);
59
- return createComponent(Table, o);
60
- },
61
- tdProps: ({ tdProps }, { store }) => (o) => combineProps(tdProps?.(o) || {}, { get class() {
62
- const { diff } = store.props || {};
63
- const id = unwrap(o.data)[store.props.rowKey];
64
- return [o.data[NEW] ? diff?.added ? "bg-#dafaea" : "" : o.data[DEL] ? "bg-#ffe8e8" : o.data[store.internal] ? "" : diff.changed && o.data[o.col.id] != store.diffDataKeyed()[id][o.col.id] ? "bg-#dafaea" : ""].join(" ");
49
+ Table: ({ Table: i }, { store: o }) => (s) => (useTinykeys(() => o.table, { "Control+S": () => o.commands.diffCommit() }), s = combineProps({ tabindex: -1 }, s), createComponent(i, s)),
50
+ tdProps: ({ tdProps: e }, { store: r }) => (o) => combineProps(e?.(o) || {}, { get class() {
51
+ let { diff: e } = r.props || {}, a = unwrap(o.data)[r.props.rowKey];
52
+ return [o.data[NEW] ? e?.added ? "bg-#dafaea" : "" : o.data[DEL] ? "bg-#ffe8e8" : o.data[r.internal] ? "" : e.changed && o.data[o.col.id] != r.diffDataKeyed()[a][o.col.id] ? "bg-#dafaea" : ""].join(" ");
65
53
  } })
66
54
  }
67
55
  };
@@ -0,0 +1,14 @@
1
+ import { type Plugin } from "../index";
2
+ declare module '../index' {
3
+ interface TableProps {
4
+ colDrag?: boolean;
5
+ rowDrag?: boolean;
6
+ }
7
+ interface TableColumn {
8
+ }
9
+ interface TableStore {
10
+ }
11
+ interface Commands {
12
+ }
13
+ }
14
+ export declare const DragPlugin: Plugin;
@@ -0,0 +1,47 @@
1
+ import { useSort } from "../hooks/useSort.js";
2
+ import { delay } from "es-toolkit";
3
+ import { isMatch } from "es-toolkit/compat";
4
+ const DragPlugin = {
5
+ rewriteProps: {
6
+ colDrag: ({ colDrag: e = !1 }) => e,
7
+ rowDrag: ({ rowDrag: e = !1 }) => e
8
+ },
9
+ onMount(r) {
10
+ let i = useSort(() => r.scroll_el, {
11
+ get enable() {
12
+ return r.props?.colDrag;
13
+ },
14
+ guideLine: { class: "col__guide-line" },
15
+ draggable: (e) => ((i, a) => e.tagName == "TH" && isMatch(r.selected, { start: [i, 0] }) && !r.props?.columns[i][r.internal] && r.thead.contains(e) && delay(300).then(() => !0))(+e.getAttribute("x"), +e.getAttribute("y")),
16
+ dragover: (e) => e.tagName == "THEAD",
17
+ children: (e) => [...i.drag.parentElement.children].filter((e) => !r.props?.columns[e.getAttribute("x")][r.internal]),
18
+ dragend: o
19
+ }), a = useSort(() => r.scroll_el, {
20
+ get enable() {
21
+ return r.props?.rowDrag;
22
+ },
23
+ guideLine: { class: "row__guide-line" },
24
+ draggable: (e) => ((i, a) => e.tagName == "TD" && isMatch(r.selected, { start: [0, a] }) && i == 0 && !r.props?.data[a][r.internal] && r.tbody.contains(e) && delay(300).then(() => !0))(+e.getAttribute("x"), +e.getAttribute("y")),
25
+ dragover: (e) => e.tagName == "TBODY",
26
+ children: (e) => [...a.over.children].filter((e) => !r.props.data[e.getAttribute("y")][r.internal]),
27
+ dragend: s
28
+ });
29
+ async function o() {
30
+ if (i.drag == i.rel) return;
31
+ let [e, t] = [r.props.columns, [...r.rawProps.columns || []]], n = ((e) => e[r.raw] ?? e)(e[i.drag.getAttribute("x")]), a = ((e) => e[r.raw] ?? e)(e[i.rel.getAttribute("x")]), o = t.indexOf(n), s = t.indexOf(a);
32
+ if (o < 0 || s < 0) return;
33
+ t[o].fixed = t[s].fixed, t.splice(s - (o > s ? 0 : 1) + (i.type == "before" ? 0 : 1), 0, t.splice(o, 1)[0]), r.props.onColumnsChange?.(t), await Promise.resolve();
34
+ let c = r.props.columns.findIndex((e) => e == n || e[r.raw] == n);
35
+ c < 0 || (r.selected.start[0] = r.selected.end[0] = c);
36
+ }
37
+ async function s() {
38
+ if (a.drag == a.rel) return;
39
+ let [e, t] = [r.props.data, [...r.rawProps.data || []]], n = ((e) => e[r.raw] ?? e)(e[a.drag.getAttribute("y")]), i = ((e) => e[r.raw] ?? e)(e[a.rel.getAttribute("y")]), o = t.indexOf(n), s = t.indexOf(i);
40
+ if (o < 0 || s < 0) return;
41
+ t.splice(s - (o > s ? 0 : 1) + (a.type == "before" ? 0 : 1), 0, t.splice(o, 1)[0]), r.props.onDataChange?.(t), await Promise.resolve();
42
+ let c = r.props.data.findIndex((e) => e == n || e[r.raw] == n);
43
+ c < 0 || (r.selected.start[1] = r.selected.end[1] = c);
44
+ }
45
+ }
46
+ };
47
+ export { DragPlugin };