intable 0.0.7 → 0.0.9
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.
- package/README.md +263 -16
- package/dist/__uno.css +1 -0
- package/dist/chevron-right.js +6 -0
- package/dist/components/Columns.d.ts +3 -0
- package/dist/components/Columns.js +71 -0
- package/dist/components/DocTree.d.ts +4 -0
- package/dist/components/DocTree.js +32 -0
- package/dist/components/Menu.d.ts +1 -0
- package/dist/components/Menu.js +107 -0
- package/dist/components/Popover.d.ts +14 -0
- package/dist/components/Popover.js +41 -0
- package/dist/components/RecycleList.d.ts +26 -0
- package/dist/components/RecycleList.js +39 -0
- package/dist/components/Render.d.ts +4 -0
- package/dist/components/Render.js +20 -0
- package/dist/components/Split.d.ts +15 -0
- package/dist/components/Split.js +76 -0
- package/dist/components/Tree.d.ts +37 -0
- package/dist/components/Tree.js +82 -0
- package/dist/components/utils.d.ts +3 -0
- package/dist/components/utils.js +8 -0
- package/dist/hooks/index.d.ts +40 -0
- package/dist/hooks/index.js +157 -0
- package/dist/hooks/useDir.d.ts +11 -0
- package/dist/hooks/useDir.js +42 -0
- package/dist/hooks/useSelector.d.ts +16 -0
- package/dist/hooks/useSelector.js +69 -0
- package/dist/hooks/useSort.d.ts +18 -0
- package/dist/hooks/useSort.js +83 -0
- package/dist/hooks/useVirtualizer.d.ts +30 -0
- package/dist/hooks/useVirtualizer.js +97 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +386 -0
- package/dist/loading.js +6 -0
- package/dist/plugins/CellChangeHighlightPlugin.d.ts +2 -0
- package/dist/plugins/CellChangeHighlightPlugin.js +4 -0
- package/dist/plugins/CellMergePlugin.d.ts +45 -0
- package/dist/plugins/CellMergePlugin.js +78 -0
- package/dist/plugins/CellSelectionPlugin.d.ts +15 -0
- package/dist/plugins/CellSelectionPlugin.js +113 -0
- package/dist/plugins/CommandPlugin.d.ts +14 -0
- package/dist/plugins/CommandPlugin.js +31 -0
- package/dist/plugins/CopyPastePlugin.d.ts +14 -0
- package/dist/plugins/CopyPastePlugin.js +47 -0
- package/dist/plugins/DiffPlugin.d.ts +29 -0
- package/dist/plugins/DiffPlugin.js +66 -0
- package/dist/plugins/DragPlugin.d.ts +14 -0
- package/dist/plugins/DragPlugin.js +47 -0
- package/dist/plugins/EditablePlugin.d.ts +51 -0
- package/dist/plugins/EditablePlugin.js +177 -0
- package/dist/plugins/ExpandPlugin.d.ts +18 -0
- package/dist/plugins/ExpandPlugin.js +46 -0
- package/dist/plugins/HeaderGroup.d.ts +11 -0
- package/dist/plugins/HeaderGroup.js +171 -0
- package/dist/plugins/HistoryPlugin.d.ts +10 -0
- package/dist/plugins/HistoryPlugin.js +27 -0
- package/dist/plugins/MenuPlugin.d.ts +19 -0
- package/dist/plugins/MenuPlugin.js +132 -0
- package/dist/plugins/RenderPlugin/components.d.ts +5 -0
- package/dist/plugins/RenderPlugin/components.js +87 -0
- package/dist/plugins/RenderPlugin/index.d.ts +30 -0
- package/dist/plugins/RenderPlugin/index.js +49 -0
- package/dist/plugins/ResizePlugin.d.ts +27 -0
- package/dist/plugins/ResizePlugin.js +82 -0
- package/dist/plugins/RowGroupPlugin.d.ts +18 -0
- package/dist/plugins/RowGroupPlugin.js +88 -0
- package/dist/plugins/RowSelectionPlugin.d.ts +20 -0
- package/dist/plugins/RowSelectionPlugin.js +42 -0
- package/dist/plugins/TreePlugin.d.ts +24 -0
- package/dist/plugins/TreePlugin.js +110 -0
- package/dist/plugins/VirtualScrollPlugin.d.ts +15 -0
- package/dist/plugins/VirtualScrollPlugin.js +123 -0
- package/dist/plugins/ZodValidatorPlugin.d.ts +38 -0
- package/dist/plugins/ZodValidatorPlugin.js +12 -0
- package/dist/plus.js +6 -0
- package/dist/rolldown_runtime.js +9 -0
- package/dist/style.css +3 -0
- package/dist/theme/dark.scss +46 -0
- package/dist/theme/github.scss +80 -0
- package/dist/theme/material.scss +73 -0
- package/dist/theme/shadcn.scss +66 -0
- package/dist/theme/stripe.scss +57 -0
- package/dist/tree.d.ts +1 -0
- package/dist/tree.js +12 -0
- package/dist/types/auto-imports.d.js +0 -0
- package/dist/utils.d.ts +31 -0
- package/dist/utils.js +71 -0
- package/dist/wc.d.ts +1 -0
- package/dist/wc.js +21 -0
- package/dist/web-component.d.ts +1 -0
- package/dist/web-component.js +2 -0
- package/dist/x.js +6 -0
- package/package.json +38 -30
- package/docs/index-BaMALNy6.css +0 -1
- package/docs/index-CDN48t9E.js +0 -3
- package/docs/index-Cc4RNkLY.css +0 -1
- package/docs/index-MRnbkYmU.js +0 -3
- package/docs/index.html +0 -15
- package/docs/vite.svg +0 -1
- package/index.html +0 -14
- package/packages/intable/README.md +0 -379
- package/packages/intable/package.json +0 -51
- package/packages/intable/src/assets/ClearFormat.svg +0 -3
- package/packages/intable/src/assets/Forms.svg +0 -4
- package/packages/intable/src/assets/MergeCell.svg +0 -4
- package/packages/intable/src/assets/SplitCell.svg +0 -4
- package/packages/intable/src/assets/gap.svg +0 -3
- package/packages/intable/src/assets/loading.svg +0 -12
- package/packages/intable/src/assets/paint.svg +0 -9
- package/packages/intable/src/assets/solid.svg +0 -1
- package/packages/intable/src/components/Columns.tsx +0 -86
- package/packages/intable/src/components/DocTree.tsx +0 -36
- package/packages/intable/src/components/Menu.tsx +0 -109
- package/packages/intable/src/components/Popover.tsx +0 -55
- package/packages/intable/src/components/RecycleList.tsx +0 -99
- package/packages/intable/src/components/Render.tsx +0 -26
- package/packages/intable/src/components/Split.tsx +0 -56
- package/packages/intable/src/components/Tree.tsx +0 -115
- package/packages/intable/src/components/utils.tsx +0 -12
- package/packages/intable/src/hooks/index.ts +0 -200
- package/packages/intable/src/hooks/useDir.ts +0 -78
- package/packages/intable/src/hooks/useSelector.ts +0 -91
- package/packages/intable/src/hooks/useSort.tsx +0 -118
- package/packages/intable/src/hooks/useVirtualizer.ts +0 -180
- package/packages/intable/src/index.tsx +0 -481
- package/packages/intable/src/plugins/CellChangeHighlightPlugin.tsx +0 -5
- package/packages/intable/src/plugins/CellMergePlugin.tsx +0 -153
- package/packages/intable/src/plugins/CellSelectionPlugin.tsx +0 -175
- package/packages/intable/src/plugins/CommandPlugin.tsx +0 -74
- package/packages/intable/src/plugins/CopyPastePlugin.tsx +0 -63
- package/packages/intable/src/plugins/DiffPlugin.tsx +0 -107
- package/packages/intable/src/plugins/DragPlugin.tsx +0 -81
- package/packages/intable/src/plugins/EditablePlugin.tsx +0 -252
- package/packages/intable/src/plugins/ExpandPlugin.tsx +0 -80
- package/packages/intable/src/plugins/HeaderGroup.tsx +0 -289
- package/packages/intable/src/plugins/HistoryPlugin.tsx +0 -49
- package/packages/intable/src/plugins/MenuPlugin.tsx +0 -195
- package/packages/intable/src/plugins/RenderPlugin/components.tsx +0 -51
- package/packages/intable/src/plugins/RenderPlugin/index.tsx +0 -81
- package/packages/intable/src/plugins/ResizePlugin.tsx +0 -122
- package/packages/intable/src/plugins/RowGroupPlugin.tsx +0 -122
- package/packages/intable/src/plugins/RowSelectionPlugin.tsx +0 -65
- package/packages/intable/src/plugins/TreePlugin.tsx +0 -212
- package/packages/intable/src/plugins/VirtualScrollPlugin.tsx +0 -190
- package/packages/intable/src/plugins/ZodValidatorPlugin.tsx +0 -61
- package/packages/intable/src/style.scss +0 -244
- package/packages/intable/src/tree.ts +0 -13
- package/packages/intable/src/types/auto-imports.d.ts +0 -13
- package/packages/intable/src/utils.ts +0 -122
- package/packages/intable/src/wc.tsx +0 -35
- package/packages/intable/src/web-component.ts +0 -1
- package/packages/react/package.json +0 -31
- package/packages/react/src/index.ts +0 -44
- package/packages/react/src/plugins/antd.ts +0 -94
- package/packages/react/src/style.scss +0 -12
- package/packages/react/src/types/auto-imports.d.ts +0 -10
- package/packages/vue/package.json +0 -34
- package/packages/vue/src/index.ts +0 -63
- package/packages/vue/src/plugins/element-plus.ts +0 -69
- package/packages/vue/src/style.scss +0 -12
- package/packages/vue/src/types/auto-imports.d.ts +0 -10
- package/pnpm-workspace.yaml +0 -2
- package/public/vite.svg +0 -1
- package/scripts/build.js +0 -184
- package/scripts/publish.js +0 -95
- package/src/assets/ClearFormat.svg +0 -3
- package/src/assets/Forms.svg +0 -4
- package/src/assets/MergeCell.svg +0 -4
- package/src/assets/SplitCell.svg +0 -4
- package/src/assets/gap.svg +0 -3
- package/src/assets/loading.svg +0 -12
- package/src/assets/paint.svg +0 -9
- package/src/assets/solid.svg +0 -1
- package/src/demo-vue.ts +0 -54
- package/src/demo.tsx +0 -107
- package/src/index.scss +0 -105
- package/src/styles/index.scss +0 -172
- package/src/types/auto-imports.d.ts +0 -13
- package/stats.html +0 -4949
- package/tsconfig.app.json +0 -34
- package/tsconfig.json +0 -7
- package/tsconfig.node.json +0 -26
- package/vite.config.ts +0 -63
- /package/{packages/intable/src → dist}/theme/antd.scss +0 -0
- /package/{packages/intable/src → dist}/theme/element-plus.scss +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createComponent } from "solid-js/web";
|
|
2
|
+
import { createMemo, getOwner, runWithOwner } from "solid-js";
|
|
3
|
+
import { combineProps } from "@solid-primitives/props";
|
|
4
|
+
import { createEventListener } from "@solid-primitives/event-listener";
|
|
5
|
+
import { createKeybindingsHandler } from "tinykeys";
|
|
6
|
+
const CommandPlugin = {
|
|
7
|
+
name: "command",
|
|
8
|
+
priority: Infinity,
|
|
9
|
+
store: (e) => {
|
|
10
|
+
let a = getOwner(), o = createMemo(() => e.plugins.reduce((n, r) => Object.assign(n, runWithOwner(a, () => r.commands?.(e, { ...n }))), {}));
|
|
11
|
+
return { get commands() {
|
|
12
|
+
return o();
|
|
13
|
+
} };
|
|
14
|
+
},
|
|
15
|
+
rewriteProps: { Table: ({ Table: s }, { store: c }) => (l) => {
|
|
16
|
+
let u = getOwner(), d = createMemo(() => {
|
|
17
|
+
let e = {};
|
|
18
|
+
for (let n of c.plugins) {
|
|
19
|
+
let r = runWithOwner(u, () => n.keybindings?.(c));
|
|
20
|
+
r && Object.assign(e, r);
|
|
21
|
+
}
|
|
22
|
+
let n = c.props?.keybindings;
|
|
23
|
+
if (n) for (let [r, i] of Object.entries(n)) i === !1 ? delete e[r] : typeof i == "function" && (e[r] = i);
|
|
24
|
+
return createKeybindingsHandler(Object.fromEntries(Object.entries(e).map(([e, n]) => [e, (e) => {
|
|
25
|
+
e.preventDefault(), n(e);
|
|
26
|
+
}])));
|
|
27
|
+
});
|
|
28
|
+
return createEventListener(() => c.scroll_el, "keydown", (e) => d()(e)), l = combineProps({ tabindex: -1 }, l), createComponent(s, l);
|
|
29
|
+
} }
|
|
30
|
+
};
|
|
31
|
+
export { CommandPlugin };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Plugin } from '..';
|
|
2
|
+
declare module '../index' {
|
|
3
|
+
interface TableProps {
|
|
4
|
+
}
|
|
5
|
+
interface TableStore {
|
|
6
|
+
}
|
|
7
|
+
interface Plugin {
|
|
8
|
+
}
|
|
9
|
+
interface Commands {
|
|
10
|
+
copy: () => void;
|
|
11
|
+
paste: () => void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare const ClipboardPlugin: Plugin;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
const ClipboardPlugin = {
|
|
3
|
+
name: "clipboard",
|
|
4
|
+
keybindings: (e) => ({
|
|
5
|
+
"$mod+c": () => {
|
|
6
|
+
e.commands.copy(), e.scroll_el?.classList.add("copied");
|
|
7
|
+
},
|
|
8
|
+
"$mod+v": () => e.commands.paste()
|
|
9
|
+
}),
|
|
10
|
+
onMount: (t) => {
|
|
11
|
+
createEffect(() => {
|
|
12
|
+
JSON.stringify(t.selected), t.scroll_el?.classList.remove("copied");
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
menus: (e) => [],
|
|
16
|
+
commands: (e) => ({
|
|
17
|
+
copy: () => {
|
|
18
|
+
let { start: t, end: n } = e.selected;
|
|
19
|
+
if (!t?.length) return;
|
|
20
|
+
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).filter((t) => !t[e.internal]), c = e.props.data.slice(a, o + 1).map((e) => s.map((t) => {
|
|
21
|
+
let n = e[t.id] ?? "";
|
|
22
|
+
return String(n).replace(/[\t\r\n]/g, " ");
|
|
23
|
+
}).join(" ")).join("\n");
|
|
24
|
+
navigator.clipboard.writeText(c);
|
|
25
|
+
},
|
|
26
|
+
paste: async () => {
|
|
27
|
+
let { start: t, end: n } = e.selected;
|
|
28
|
+
if (!t?.length) return;
|
|
29
|
+
let r = (await navigator.clipboard.readText()).replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n$/, "").split("\n").map((e) => e.split(" ")), i = r.length, a = r[0].length, [o, s] = [t[0], n[0]].sort((e, t) => e - t), [c, l] = [t[1], n[1]].sort((e, t) => e - t), u = l - c + 1, d = s - o + 1, f = u > i && u % i === 0 ? u : i, p = d > a && d % a === 0 ? d : a, m = e.props.columns, h = [];
|
|
30
|
+
for (let t = o; t < m.length && h.length < p; t++) m[t][e.internal] || h.push(m[t]);
|
|
31
|
+
let g = e.props.data.slice(), _ = Math.min(c + f - 1, g.length - 1);
|
|
32
|
+
for (let e = 0; e <= _ - c; e++) {
|
|
33
|
+
let t = {};
|
|
34
|
+
h.forEach((n, o) => {
|
|
35
|
+
t[n.id] = r[e % i][o % a];
|
|
36
|
+
}), g[c + e] = {
|
|
37
|
+
...g[c + e],
|
|
38
|
+
...t
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
let v = o, y = 0;
|
|
42
|
+
for (let t = o; t < m.length && y < h.length; t++) m[t][e.internal] || (v = t, y++);
|
|
43
|
+
e.selected.end = [v, _], e.props.onDataChange?.(g);
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
export { ClipboardPlugin };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Plugin } from '..';
|
|
2
|
+
declare module '../index' {
|
|
3
|
+
interface TableProps {
|
|
4
|
+
diff?: {
|
|
5
|
+
/** @default false */
|
|
6
|
+
enable?: boolean;
|
|
7
|
+
data?: any[];
|
|
8
|
+
/** @default true */
|
|
9
|
+
added?: boolean;
|
|
10
|
+
/** @default true */
|
|
11
|
+
removed?: boolean;
|
|
12
|
+
/** @default true */
|
|
13
|
+
changed?: boolean;
|
|
14
|
+
onCommit?: (data: any, opt: {
|
|
15
|
+
added: any[];
|
|
16
|
+
removed: any[];
|
|
17
|
+
changed: any[];
|
|
18
|
+
}) => any;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface TableStore {
|
|
22
|
+
diffData: any[];
|
|
23
|
+
diffDataKeyed: () => any;
|
|
24
|
+
}
|
|
25
|
+
interface Commands {
|
|
26
|
+
diffCommit(data?: any[]): void;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export declare const DiffPlugin: Plugin;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createComponent } from "solid-js/web";
|
|
2
|
+
import { unwrap } from "solid-js/store";
|
|
3
|
+
import { combineProps } from "@solid-primitives/props";
|
|
4
|
+
import { createLazyMemo } from "@solid-primitives/memo";
|
|
5
|
+
import { isEqual, keyBy } from "es-toolkit";
|
|
6
|
+
import { v4 } from "uuid";
|
|
7
|
+
import { diffArrays } from "diff";
|
|
8
|
+
var DEL = Symbol("del"), NEW = Symbol("new");
|
|
9
|
+
const DiffPlugin = {
|
|
10
|
+
priority: Infinity,
|
|
11
|
+
store: (e) => {
|
|
12
|
+
let a = e.rawProps.data || [];
|
|
13
|
+
return a.forEach((a) => unwrap(a)[e.rawProps.rowKey] ??= v4()), {
|
|
14
|
+
diffData: structuredClone(unwrap(a || [])),
|
|
15
|
+
diffData2: () => e.props.diff?.data ?? e.diffData,
|
|
16
|
+
diffDataKeyed: createLazyMemo(() => keyBy(e.diffData2(), (i) => i[e.props.rowKey]))
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
commands: (e) => ({ async diffCommit(a = e.rawProps.data || []) {
|
|
20
|
+
let { rowKey: o } = e.props || {};
|
|
21
|
+
a.forEach((e) => unwrap(e)[o] ??= v4()), a = structuredClone(unwrap(a));
|
|
22
|
+
let c = [], l = [], u = [], d = keyBy(a, (e) => e[o]);
|
|
23
|
+
for (let i of a) {
|
|
24
|
+
let a = e.diffDataKeyed()[i[o]];
|
|
25
|
+
a ? isEqual(i, a) || u.push(i) : c.push(i);
|
|
26
|
+
}
|
|
27
|
+
for (let i of e.diffData2()) !d[i[o]] && l.push(i);
|
|
28
|
+
await e.props.diff?.onCommit?.(a, {
|
|
29
|
+
added: c,
|
|
30
|
+
removed: l,
|
|
31
|
+
changed: u
|
|
32
|
+
}), c[NEW] = 0, e.diffData = a;
|
|
33
|
+
} }),
|
|
34
|
+
rewriteProps: {
|
|
35
|
+
diff: ({ diff: e }) => ({
|
|
36
|
+
enable: !1,
|
|
37
|
+
added: !0,
|
|
38
|
+
removed: !0,
|
|
39
|
+
changed: !0,
|
|
40
|
+
...e
|
|
41
|
+
}),
|
|
42
|
+
data: ({ data: e }, { store: i }) => {
|
|
43
|
+
if (!i.props.diff?.enable) return e;
|
|
44
|
+
let { rowKey: a, diff: o } = i.props || {}, s = i.diffData2() || [];
|
|
45
|
+
if (e.length === s.length && e.length > 0) {
|
|
46
|
+
let i = !0;
|
|
47
|
+
for (let o = 0; o < e.length; o++) if (e[o]?.[a] !== s[o]?.[a]) {
|
|
48
|
+
i = !1;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (i) return e;
|
|
52
|
+
}
|
|
53
|
+
return diffArrays(s, e, { comparator: (e, i) => e[a] == i[a] }).flatMap((e) => e.added ? e.value.map((e) => (e[NEW] = 1, e)) : e.removed ? o.removed ? e.value.map((e) => ({
|
|
54
|
+
...e,
|
|
55
|
+
[DEL]: 1,
|
|
56
|
+
[i.internal]: 1
|
|
57
|
+
})) : [] : e.value);
|
|
58
|
+
},
|
|
59
|
+
Td: ({ Td: i }, { store: o }) => o.props.diff?.enable ? (s) => (s = combineProps(s, { get class() {
|
|
60
|
+
let { diff: e } = o.props, i = s.data[o.props.rowKey];
|
|
61
|
+
return [s.data[NEW] ? "bg-#dafaea!" : s.data[DEL] ? "bg-#ffe8e8!" : s.data[o.internal] ? "" : e.changed && s.data[s.col.id] != o.diffDataKeyed()[i]?.[s.col.id] ? "bg-#dafaea!" : ""].join(" ");
|
|
62
|
+
} }), createComponent(i, s)) : i
|
|
63
|
+
},
|
|
64
|
+
keybindings: (e) => ({ "$mod+S": () => e.commands.diffCommit() })
|
|
65
|
+
};
|
|
66
|
+
export { DiffPlugin };
|
|
@@ -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 };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type JSX } from 'solid-js';
|
|
2
|
+
import { type Plugin, type TableColumn } from '..';
|
|
3
|
+
declare module '../index' {
|
|
4
|
+
interface TableProps {
|
|
5
|
+
validator?: (value: any, data: any, col: TableColumn) => string | boolean | Promise<string | boolean>;
|
|
6
|
+
}
|
|
7
|
+
interface TableColumn {
|
|
8
|
+
editable?: boolean;
|
|
9
|
+
editor?: string | Editor;
|
|
10
|
+
editorProps?: any;
|
|
11
|
+
editorPopup?: boolean;
|
|
12
|
+
validator?: (value: any, rowData: any, col: TableColumn) => boolean | string | Promise<boolean | string>;
|
|
13
|
+
}
|
|
14
|
+
interface TableStore {
|
|
15
|
+
editors: {
|
|
16
|
+
[key: string]: Editor;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export type Editor = (props: EditorOpt) => {
|
|
21
|
+
el: JSX.Element;
|
|
22
|
+
getValue: () => any;
|
|
23
|
+
destroy: () => void;
|
|
24
|
+
focus?: () => void;
|
|
25
|
+
blur?: () => void;
|
|
26
|
+
};
|
|
27
|
+
export interface EditorOpt {
|
|
28
|
+
col: TableColumn;
|
|
29
|
+
data: any;
|
|
30
|
+
value: any;
|
|
31
|
+
eventKey?: string;
|
|
32
|
+
onChange?: (value: any) => void;
|
|
33
|
+
ok: () => void;
|
|
34
|
+
cancel: () => void;
|
|
35
|
+
props?: any;
|
|
36
|
+
}
|
|
37
|
+
export declare const EditablePlugin: Plugin;
|
|
38
|
+
export declare const editors: {
|
|
39
|
+
text: Editor;
|
|
40
|
+
number: Editor;
|
|
41
|
+
range: Editor;
|
|
42
|
+
date: Editor;
|
|
43
|
+
time: Editor;
|
|
44
|
+
datetime: Editor;
|
|
45
|
+
color: Editor;
|
|
46
|
+
tel: Editor;
|
|
47
|
+
password: Editor;
|
|
48
|
+
file: Editor;
|
|
49
|
+
checkbox: Editor;
|
|
50
|
+
select: Editor;
|
|
51
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { chooseFile, resolveOptions } from "../utils.js";
|
|
2
|
+
import { Checkbox, Files } from "./RenderPlugin/components.js";
|
|
3
|
+
import { Ctx } from "../index.js";
|
|
4
|
+
import { createComponent, delegateEvents, effect, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
5
|
+
import { createComputed, createEffect, createMemo, createRoot, createSignal, on, onCleanup, useContext } from "solid-js";
|
|
6
|
+
import { createMutable } from "solid-js/store";
|
|
7
|
+
import { combineProps } from "@solid-primitives/props";
|
|
8
|
+
import { createAsyncMemo } from "@solid-primitives/memo";
|
|
9
|
+
import { delay } from "es-toolkit";
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template("<input style=position:absolute;margin-top:1em;width:0;height:0;pointer-events:none;opacity:0>"), _tmpl$2 = /* @__PURE__ */ template("<div class=in-cell-edit-wrapper>"), _tmpl$3 = /* @__PURE__ */ template("<span class=cell-validating>"), _tmpl$4 = /* @__PURE__ */ template("<div class=cell-validation-error>"), _tmpl$5 = /* @__PURE__ */ template("<input>"), _tmpl$6 = /* @__PURE__ */ template("<select>"), _tmpl$7 = /* @__PURE__ */ template("<option>"), _tmpl$8 = /* @__PURE__ */ template("<label class=\"h-full flex items-center\">");
|
|
11
|
+
const EditablePlugin = {
|
|
12
|
+
name: "editable",
|
|
13
|
+
store: () => ({ editors: { ...editors } }),
|
|
14
|
+
rewriteProps: { Td: ({ Td: e }, { store: T }) => (E) => {
|
|
15
|
+
let D, { props: A } = useContext(Ctx), j = createMemo(() => !!E.col.editable && !E.data[T.internal] && !E.col[T.internal]), [N, P] = createSignal(!1), z = "", B = createMemo(() => (([e, T]) => E.x == e && E.y == T)(T.selected.start || [])), V = createMemo(() => B() && j() && !N()), [H, U] = createSignal(null), [W, G] = createSignal(!1);
|
|
16
|
+
createEffect(() => {
|
|
17
|
+
N() || (U(null), G(!1));
|
|
18
|
+
});
|
|
19
|
+
let K = createAsyncMemo(async () => {
|
|
20
|
+
if (N()) {
|
|
21
|
+
let e = !1, D = ((e) => typeof e == "string" ? T.editors[e] : e)(E.col.editor || "text"), O = {
|
|
22
|
+
props: E.col.editorProps,
|
|
23
|
+
col: E.col,
|
|
24
|
+
eventKey: z,
|
|
25
|
+
data: E.data,
|
|
26
|
+
value: E.data[E.col.id],
|
|
27
|
+
ok: async () => {
|
|
28
|
+
await q(k.getValue()), P(!1);
|
|
29
|
+
},
|
|
30
|
+
cancel: () => (e = !0, U(null), P(!1)),
|
|
31
|
+
onChange: (e) => q(e).catch(() => {})
|
|
32
|
+
}, k = D(O);
|
|
33
|
+
return onCleanup(() => {
|
|
34
|
+
if (!e && k.getValue() !== E.data[E.col.id]) {
|
|
35
|
+
let e = [...A.data];
|
|
36
|
+
e[E.y] = {
|
|
37
|
+
...e[E.y],
|
|
38
|
+
[E.col.id]: k.getValue()
|
|
39
|
+
}, A.onDataChange?.(e);
|
|
40
|
+
}
|
|
41
|
+
e || q(k.getValue()), k.destroy();
|
|
42
|
+
}), [O, k];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
async function q(e) {
|
|
46
|
+
if (A.validator || E.col.validator) {
|
|
47
|
+
try {
|
|
48
|
+
G(!0);
|
|
49
|
+
let T = await (async () => {
|
|
50
|
+
for (let T of [A.validator, E.col.validator]) {
|
|
51
|
+
if (!T) continue;
|
|
52
|
+
let D = await T(e, E.data, E.col);
|
|
53
|
+
if (D !== !0) return D;
|
|
54
|
+
}
|
|
55
|
+
return !0;
|
|
56
|
+
})();
|
|
57
|
+
G(!1), U(T === !0 ? null : typeof T == "string" ? T : "Error");
|
|
58
|
+
} catch (e) {
|
|
59
|
+
G(!1), U(e.message || "Error");
|
|
60
|
+
}
|
|
61
|
+
if (H() != null) throw Error(H() || "Error");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
createEffect(() => {
|
|
65
|
+
K()?.[1]?.focus?.();
|
|
66
|
+
}), createEffect(() => {
|
|
67
|
+
if (N()) {
|
|
68
|
+
let e = createMemo(() => JSON.stringify(T.selected));
|
|
69
|
+
createEffect(on(e, () => P(!1), { defer: !0 }));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
let J, Y = createMutable({
|
|
73
|
+
w: 0,
|
|
74
|
+
h: 0
|
|
75
|
+
});
|
|
76
|
+
return createComputed(() => N() && (Y.w = D.getBoundingClientRect().width, Y.h = D.getBoundingClientRect().height)), E = combineProps(E, {
|
|
77
|
+
ref: (e) => D = e,
|
|
78
|
+
get class() {
|
|
79
|
+
return [N() ? "is-editing" : "", H() === null ? "" : "is-invalid"].filter(Boolean).join(" ");
|
|
80
|
+
},
|
|
81
|
+
get style() {
|
|
82
|
+
return N() ? `width: ${Y.w}px; height: ${Y.h}px; padding: 0; ` : "";
|
|
83
|
+
},
|
|
84
|
+
onClick: () => J?.focus?.(),
|
|
85
|
+
onDblClick: () => P(j()),
|
|
86
|
+
onKeyDown: (e) => e.key == "Escape" && K()?.[0].cancel()
|
|
87
|
+
}), createComponent(e, mergeProps(E, { get children() {
|
|
88
|
+
return [
|
|
89
|
+
memo(() => memo(() => !!V())() && (() => {
|
|
90
|
+
var e = _tmpl$();
|
|
91
|
+
return e.addEventListener("compositionend", () => {
|
|
92
|
+
P(!0);
|
|
93
|
+
}), e.$$input = (e) => {
|
|
94
|
+
z = e.target.value, P(!e.isComposing);
|
|
95
|
+
}, e.$$keydown = (e) => {
|
|
96
|
+
e.key == " " && e.preventDefault();
|
|
97
|
+
}, use((e) => {
|
|
98
|
+
J = e, delay(0).then(() => e.focus({ preventScroll: !0 }));
|
|
99
|
+
}, e), e;
|
|
100
|
+
})()),
|
|
101
|
+
memo(() => memo(() => !!K()?.[1]?.el)() ? (() => {
|
|
102
|
+
var e = _tmpl$2();
|
|
103
|
+
return insert(e, () => K()?.[1]?.el, null), insert(e, (() => {
|
|
104
|
+
var e = memo(() => !!W());
|
|
105
|
+
return () => e() && _tmpl$3();
|
|
106
|
+
})(), null), e;
|
|
107
|
+
})() : E.children),
|
|
108
|
+
memo(() => memo(() => H() !== null)() && (() => {
|
|
109
|
+
var e = _tmpl$4();
|
|
110
|
+
return insert(e, H), e;
|
|
111
|
+
})())
|
|
112
|
+
];
|
|
113
|
+
} }));
|
|
114
|
+
} }
|
|
115
|
+
};
|
|
116
|
+
var createEditor = (e, E, D) => ({ eventKey: O, value: A, col: j, ok: M, cancel: N, props: P, onChange: F }) => createRoot((I) => {
|
|
117
|
+
let [L, R] = createSignal(O || A), z;
|
|
118
|
+
return createComponent(e, mergeProps({
|
|
119
|
+
ref: (e) => z = e,
|
|
120
|
+
class: "relative block px-2 size-full z-9 box-border resize-none outline-0",
|
|
121
|
+
get value() {
|
|
122
|
+
return L();
|
|
123
|
+
},
|
|
124
|
+
onInput: (e) => (R(e instanceof Event ? e.target.value : e), F?.(L())),
|
|
125
|
+
onChange: (e) => (R(e instanceof Event ? e.target.value : e), F?.(L()), D && M()),
|
|
126
|
+
"on:pointerdown": (e) => e.stopPropagation(),
|
|
127
|
+
"on:keydown": (e) => {
|
|
128
|
+
e.stopPropagation(), e.key == "Enter" && M(), e.key == "Escape" && N();
|
|
129
|
+
},
|
|
130
|
+
get options() {
|
|
131
|
+
return memo(() => !!j.enum)() ? resolveOptions(j.enum ?? []) : void 0;
|
|
132
|
+
}
|
|
133
|
+
}, E, P)), {
|
|
134
|
+
el: z,
|
|
135
|
+
getValue: L,
|
|
136
|
+
focus: () => z.focus(),
|
|
137
|
+
destroy: I
|
|
138
|
+
};
|
|
139
|
+
}), Input = (e) => (() => {
|
|
140
|
+
var T = _tmpl$5();
|
|
141
|
+
return spread(T, e, !1, !1), T;
|
|
142
|
+
})(), text = createEditor(Input), number = createEditor(Input, { type: "number" }), range$1 = createEditor(Input, { type: "range" }), color = createEditor(Input, { type: "color" }), tel = createEditor(Input, { type: "tel" }), password = createEditor(Input, { type: "password" }), date = createEditor(Input, { type: "date" }, !0), time = createEditor(Input, { type: "time" }, !0), datetime = createEditor(Input, { type: "datetime-local" }, !0), select = createEditor((e) => (() => {
|
|
143
|
+
var T = _tmpl$6();
|
|
144
|
+
return spread(T, e, !1, !0), insert(T, () => e.options?.map((e) => (() => {
|
|
145
|
+
var T = _tmpl$7();
|
|
146
|
+
return insert(T, () => e.label), effect(() => T.value = e.value), T;
|
|
147
|
+
})())), T;
|
|
148
|
+
})(), {}, !0), file = createEditor((T) => createComponent(Files, mergeProps(T, {
|
|
149
|
+
class: "relative z-9 outline-2 outline-blue min-h-a! h-a! p-1 bg-#fff",
|
|
150
|
+
onAdd: () => chooseFile({ multiple: !0 }).then((e) => T.onChange([...T.value || [], ...e.map((e) => ({
|
|
151
|
+
name: e.name,
|
|
152
|
+
size: e.size
|
|
153
|
+
}))]))
|
|
154
|
+
}))), checkbox = createEditor((e) => (() => {
|
|
155
|
+
var T = _tmpl$8(), D = e.ref;
|
|
156
|
+
return typeof D == "function" ? use(D, T) : e.ref = T, insert(T, createComponent(Checkbox, mergeProps(e, {
|
|
157
|
+
ref: () => {},
|
|
158
|
+
onInput: () => {},
|
|
159
|
+
class: "mx-3!"
|
|
160
|
+
}))), T;
|
|
161
|
+
})());
|
|
162
|
+
const editors = {
|
|
163
|
+
text,
|
|
164
|
+
number,
|
|
165
|
+
range: range$1,
|
|
166
|
+
date,
|
|
167
|
+
time,
|
|
168
|
+
datetime,
|
|
169
|
+
color,
|
|
170
|
+
tel,
|
|
171
|
+
password,
|
|
172
|
+
file,
|
|
173
|
+
checkbox,
|
|
174
|
+
select
|
|
175
|
+
};
|
|
176
|
+
delegateEvents(["keydown", "input"]);
|
|
177
|
+
export { EditablePlugin, editors };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JSX } from 'solid-js';
|
|
2
|
+
import { type Plugin } from '..';
|
|
3
|
+
import { useSelector } from '../hooks/useSelector';
|
|
4
|
+
declare module '../index' {
|
|
5
|
+
interface TableProps {
|
|
6
|
+
expand?: {
|
|
7
|
+
enable?: boolean;
|
|
8
|
+
render?: (props: {
|
|
9
|
+
data: any;
|
|
10
|
+
y: number;
|
|
11
|
+
}) => JSX.Element;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface Commands {
|
|
15
|
+
expand: ReturnType<typeof useSelector<any[]>>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare const ExpandPlugin: Plugin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { renderComponent, solidComponent } from "../components/utils.js";
|
|
2
|
+
import { useSelector } from "../hooks/useSelector.js";
|
|
3
|
+
import chevron_right_default from "../chevron-right.js";
|
|
4
|
+
import { createComponent, effect, insert, memo, mergeProps, setAttribute, template } from "solid-js/web";
|
|
5
|
+
import { combineProps } from "@solid-primitives/props";
|
|
6
|
+
import { defaultsDeep } from "es-toolkit/compat";
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template("<td style=width:100%>"), _tmpl$2 = /* @__PURE__ */ template("<div style=display:flex;align-items:center;width:100%;height:100%;opacity:.4>");
|
|
8
|
+
const ExpandPlugin = {
|
|
9
|
+
name: "expand",
|
|
10
|
+
store: (e) => ({ expandCol: {
|
|
11
|
+
id: Symbol("expand"),
|
|
12
|
+
fixed: "left",
|
|
13
|
+
width: 45,
|
|
14
|
+
render: solidComponent((m) => createComponent(ArrowCell, {
|
|
15
|
+
store: e,
|
|
16
|
+
get data() {
|
|
17
|
+
return m.data;
|
|
18
|
+
}
|
|
19
|
+
})),
|
|
20
|
+
props: (m) => ({ onClick: () => e.commands.expand.toggle(m.data) }),
|
|
21
|
+
[e.internal]: 1
|
|
22
|
+
} }),
|
|
23
|
+
commands: (e) => ({ expand: useSelector({ multiple: !0 }) }),
|
|
24
|
+
rewriteProps: {
|
|
25
|
+
expand: ({ expand: e }) => defaultsDeep(e, { enable: !1 }),
|
|
26
|
+
columns: ({ columns: e }, { store: m }) => m.props.expand?.enable ? [m.expandCol, ...e] : e,
|
|
27
|
+
Tr: ({ Tr: m }, { store: h }) => h.props.expand?.enable ? (g) => createComponent(m, mergeProps(g, { get children() {
|
|
28
|
+
return memo(() => !g.data?.[h.expandCol.id])() ? g.children : (() => {
|
|
29
|
+
var m = _tmpl$();
|
|
30
|
+
return insert(m, () => renderComponent(h.props.expand?.render, {
|
|
31
|
+
...g,
|
|
32
|
+
data: g.data[h.expandCol.id]
|
|
33
|
+
}, h.props.renderer)), effect(() => setAttribute(m, "colspan", h.props.columns?.length)), m;
|
|
34
|
+
})();
|
|
35
|
+
} })) : m,
|
|
36
|
+
Td: ({ Td: e }, { store: m }) => (h) => (h = combineProps(h, { onClick: () => h.col.id == m.expandCol.id && m.commands.expand.toggle(h.data) }), createComponent(e, h)),
|
|
37
|
+
data: ({ data: e }, { store: m }) => m.commands.expand.value.length ? e?.flatMap((e) => m.commands.expand.has(e) ? [e, { [m.expandCol.id]: e }] : e) : e
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var ArrowCell = (e) => (() => {
|
|
41
|
+
var m = _tmpl$2();
|
|
42
|
+
return insert(m, createComponent(chevron_right_default, { get style() {
|
|
43
|
+
return `transform: rotate(${e.store.commands.expand.has(e.data) ? 90 : 0}deg);`;
|
|
44
|
+
} })), m;
|
|
45
|
+
})();
|
|
46
|
+
export { ExpandPlugin };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Plugin$0 } from '..';
|
|
2
|
+
declare module '../index' {
|
|
3
|
+
interface TableColumn {
|
|
4
|
+
children?: TableColumn[];
|
|
5
|
+
}
|
|
6
|
+
interface TableStore {
|
|
7
|
+
/** Returns column indices of group anchors whose span overlaps [xStart, xEnd]. */
|
|
8
|
+
_headerGroupAnchors?: (xStart: number, xEnd: number) => number[];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const HeaderGroupPlugin: Plugin$0;
|