intable 0.0.27 → 0.0.29
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/dist/__uno.css +1 -1
- package/dist/hooks/useVirtualizer.d.ts +3 -0
- package/dist/hooks/useVirtualizer.js +12 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -3
- package/dist/plugins/CellMergePlugin.js +15 -16
- package/dist/plugins/CellSelectionPlugin.js +97 -69
- package/dist/plugins/CommandPlugin.js +1 -1
- package/dist/plugins/DiffPlugin.d.ts +0 -1
- package/dist/plugins/DiffPlugin.js +2 -2
- package/dist/plugins/EditablePlugin.js +62 -64
- package/dist/plugins/ExpandPlugin.js +0 -1
- package/dist/plugins/ImportExportPlugin.d.ts +9 -0
- package/dist/plugins/ImportExportPlugin.js +37 -0
- package/dist/plugins/MenuPlugin.d.ts +1 -1
- package/dist/plugins/MenuPlugin.js +3 -3
- package/dist/plugins/RenderPlugin/index.d.ts +3 -3
- package/dist/plugins/RenderPlugin/index.js +12 -12
- package/dist/plugins/ResizePlugin.js +45 -36
- package/dist/plugins/RowGroupPlugin.js +1 -1
- package/dist/plugins/TreePlugin.js +25 -23
- package/dist/plugins/ValidatorPlugin.js +14 -12
- package/dist/plugins/VirtualScrollPlugin.js +16 -2
- package/dist/style.css +1 -1
- package/package.json +3 -2
|
@@ -7,41 +7,41 @@ import { createMutable } from "solid-js/store";
|
|
|
7
7
|
import { combineProps } from "@solid-primitives/props";
|
|
8
8
|
import { createAsyncMemo } from "@solid-primitives/memo";
|
|
9
9
|
import { delay } from "es-toolkit";
|
|
10
|
-
var _tmpl$ = /* @__PURE__ */ template("<
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template("<div class=in-cell-edit-wrapper tabindex=-1>"), _tmpl$2 = /* @__PURE__ */ template("<span class=cell-validating>"), _tmpl$3 = /* @__PURE__ */ template("<input style=position:absolute;margin-top:1em;width:0;height:0;pointer-events:none;opacity:0>"), _tmpl$4 = /* @__PURE__ */ template("<input>"), _tmpl$5 = /* @__PURE__ */ template("<textarea>"), _tmpl$6 = /* @__PURE__ */ template("<label class=\"h-full flex items-center\">"), _tmpl$7 = /* @__PURE__ */ template("<select>"), _tmpl$8 = /* @__PURE__ */ template("<option>");
|
|
11
11
|
const EditablePlugin = {
|
|
12
12
|
name: "editable",
|
|
13
13
|
store: () => ({ editors: { ...editors } }),
|
|
14
14
|
rewriteProps: {
|
|
15
|
-
editable: ({ editable: e }, { store:
|
|
16
|
-
let
|
|
17
|
-
return !!
|
|
15
|
+
editable: ({ editable: e }, { store: v }) => (b) => {
|
|
16
|
+
let x = [b.col.editable, e].filter((e) => e != null);
|
|
17
|
+
return !!x.length && x.every((e) => unFn(e, b)) && !b.data[v.internal] && !b.col[v.internal];
|
|
18
18
|
},
|
|
19
|
-
Td: ({ Td: e }, { store:
|
|
20
|
-
let
|
|
21
|
-
if (
|
|
22
|
-
let e = !1,
|
|
23
|
-
props:
|
|
24
|
-
col:
|
|
25
|
-
eventKey:
|
|
26
|
-
data:
|
|
27
|
-
value:
|
|
19
|
+
Td: ({ Td: e }, { store: v }) => (b) => {
|
|
20
|
+
let x, { props: w } = useContext(Ctx), [T, D] = createSignal(!1), O = "", j = () => unFn(w.editable, b), M = () => (([e, v]) => b.x == e && b.y == v)(v.selected.start || []), N = () => M() && j() && !T(), [P, F] = createSignal(!1), I = createAsyncMemo(() => {
|
|
21
|
+
if (T()) {
|
|
22
|
+
let e = !1, y = b.data[b.col.id], x = ((e) => typeof e == "string" ? v.editors[e] : e)(b.col.editor ?? b.col.type ?? "text"), S = {
|
|
23
|
+
props: b.col.editorProps,
|
|
24
|
+
col: b.col,
|
|
25
|
+
eventKey: O,
|
|
26
|
+
data: b.data,
|
|
27
|
+
value: y,
|
|
28
28
|
ok: async () => {
|
|
29
|
-
await L(
|
|
29
|
+
await L(C.getValue()), D(!1);
|
|
30
30
|
},
|
|
31
31
|
cancel: () => (e = !0, D(!1)),
|
|
32
|
-
onChange: (e) =>
|
|
33
|
-
},
|
|
32
|
+
onChange: (e) => T() && L(e).catch(() => {})
|
|
33
|
+
}, C = x(S);
|
|
34
34
|
return onCleanup(() => {
|
|
35
|
-
!e &&
|
|
36
|
-
...
|
|
37
|
-
[
|
|
38
|
-
}), e || L(
|
|
39
|
-
}), [
|
|
35
|
+
!e && C.getValue() !== y && v.commands.rowChange({
|
|
36
|
+
...w.data[b.y],
|
|
37
|
+
[b.col.id]: C.getValue()
|
|
38
|
+
}), e || L(C.getValue()).catch(() => {}), O = "", C.destroy();
|
|
39
|
+
}), [S, C];
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
async function L(e) {
|
|
43
43
|
try {
|
|
44
|
-
F(!0), await
|
|
44
|
+
F(!0), await v.validateCell(e, b.data, b.col);
|
|
45
45
|
} finally {
|
|
46
46
|
F(!1);
|
|
47
47
|
}
|
|
@@ -49,8 +49,8 @@ const EditablePlugin = {
|
|
|
49
49
|
createEffect(() => {
|
|
50
50
|
I()?.[1]?.focus?.();
|
|
51
51
|
}), createEffect(() => {
|
|
52
|
-
if (
|
|
53
|
-
let e = createMemo(() => JSON.stringify(
|
|
52
|
+
if (T()) {
|
|
53
|
+
let e = createMemo(() => JSON.stringify(v.selected ?? "{}"));
|
|
54
54
|
createEffect(on(e, () => D(!1), { defer: !0 }));
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -58,72 +58,70 @@ const EditablePlugin = {
|
|
|
58
58
|
w: 0,
|
|
59
59
|
h: 0
|
|
60
60
|
});
|
|
61
|
-
return createComputed(() =>
|
|
62
|
-
ref: (e) =>
|
|
61
|
+
return createComputed(() => T() && (z.w = x.getBoundingClientRect().width, z.h = x.getBoundingClientRect().height)), b = combineProps(b, {
|
|
62
|
+
ref: (e) => x = e,
|
|
63
63
|
get class() {
|
|
64
|
-
return
|
|
64
|
+
return T() ? "is-editing" : "";
|
|
65
65
|
},
|
|
66
66
|
get style() {
|
|
67
|
-
return
|
|
67
|
+
return T() ? `width: ${z.w}px; height: ${z.h}px; padding: 0; ` : "";
|
|
68
68
|
},
|
|
69
69
|
onClick: () => R?.focus?.(),
|
|
70
|
-
onDblClick: () => D(
|
|
70
|
+
onDblClick: () => D(j()),
|
|
71
71
|
onKeyDown: (e) => e.key == "Escape" && I()?.[0].cancel()
|
|
72
|
-
}), createComponent(e, mergeProps(
|
|
73
|
-
return [memo(() => memo(() => !!
|
|
72
|
+
}), createComponent(e, mergeProps(b, { get children() {
|
|
73
|
+
return [memo(() => memo(() => !!I()?.[1]?.el)() ? (() => {
|
|
74
74
|
var e = _tmpl$();
|
|
75
|
+
return addEventListener(e, "keydown", (e) => {
|
|
76
|
+
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && I()?.[0].ok(), e.key == "Escape" && I()?.[0].cancel();
|
|
77
|
+
}), addEventListener(e, "pointerdown", (e) => e.stopPropagation()), insert(e, () => I()?.[1]?.el, null), insert(e, (() => {
|
|
78
|
+
var e = memo(() => !!P());
|
|
79
|
+
return () => e() && _tmpl$2();
|
|
80
|
+
})(), null), e;
|
|
81
|
+
})() : b.children), memo(() => memo(() => !!N())() && (() => {
|
|
82
|
+
var e = _tmpl$3();
|
|
75
83
|
return e.addEventListener("compositionend", () => {
|
|
76
84
|
D(!0);
|
|
77
85
|
}), e.$$input = (e) => {
|
|
78
|
-
|
|
86
|
+
O = e.target.value, D(!e.isComposing);
|
|
79
87
|
}, e.$$keydown = (e) => {
|
|
80
88
|
e.key == " " && e.preventDefault();
|
|
81
89
|
}, use((e) => {
|
|
82
90
|
R = e, delay(0).then(() => e.focus({ preventScroll: !0 }));
|
|
83
91
|
}, e), e;
|
|
84
|
-
})())
|
|
85
|
-
var e = _tmpl$2();
|
|
86
|
-
return addEventListener(e, "keydown", (e) => e.stopPropagation()), insert(e, () => I()?.[1]?.el, null), insert(e, (() => {
|
|
87
|
-
var e = memo(() => !!P());
|
|
88
|
-
return () => e() && _tmpl$3();
|
|
89
|
-
})(), null), e;
|
|
90
|
-
})() : y.children)];
|
|
92
|
+
})())];
|
|
91
93
|
} }));
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
};
|
|
95
|
-
var createEditor = (e,
|
|
96
|
-
let [O, k] = createSignal(
|
|
97
|
+
var createEditor = (e, y, b) => ({ eventKey: x, value: S, col: C, ok: w, cancel: T, props: E, onChange: D }) => createRoot((T) => {
|
|
98
|
+
let [O, k] = createSignal(x || S), A;
|
|
97
99
|
return createComponent(e, mergeProps({
|
|
98
100
|
ref: (e) => A = e,
|
|
99
101
|
class: "relative block px-2 size-full z-9 box-border resize-none outline-0",
|
|
100
102
|
get value() {
|
|
101
103
|
return O();
|
|
102
104
|
},
|
|
103
|
-
onInput: (e) => (k(e instanceof Event ? e.target.value : e),
|
|
104
|
-
onChange: (e) => (k(e instanceof Event ? e.target.value : e),
|
|
105
|
-
"on:pointerdown": (e) => e.stopPropagation(),
|
|
106
|
-
"on:keydown": (e) => {
|
|
107
|
-
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && C(), e.key == "Escape" && w();
|
|
108
|
-
},
|
|
105
|
+
onInput: (e) => (k(e instanceof Event ? e.target.value : e), D?.(O())),
|
|
106
|
+
onChange: (e) => (k(e instanceof Event ? e.target.value : e), D?.(O()), b && w()),
|
|
109
107
|
get options() {
|
|
110
|
-
return memo(() => !!
|
|
108
|
+
return memo(() => !!C.enum)() ? resolveOptions(C.enum ?? []) : void 0;
|
|
111
109
|
}
|
|
112
|
-
},
|
|
110
|
+
}, y, E)), {
|
|
113
111
|
el: A,
|
|
114
112
|
getValue: O,
|
|
115
113
|
focus: () => A.focus(),
|
|
116
|
-
destroy:
|
|
114
|
+
destroy: T
|
|
117
115
|
};
|
|
118
116
|
}), Input = (e) => (() => {
|
|
119
|
-
var
|
|
120
|
-
return spread(
|
|
117
|
+
var v = _tmpl$4();
|
|
118
|
+
return spread(v, e, !1, !1), v;
|
|
121
119
|
})();
|
|
122
120
|
const editors = {
|
|
123
121
|
text: createEditor(Input),
|
|
124
122
|
textarea: createEditor((e) => (() => {
|
|
125
|
-
var
|
|
126
|
-
return spread(
|
|
123
|
+
var v = _tmpl$5();
|
|
124
|
+
return spread(v, e, !1, !1), v;
|
|
127
125
|
})()),
|
|
128
126
|
number: createEditor(Input, { type: "number" }),
|
|
129
127
|
range: createEditor(Input, { type: "range" }),
|
|
@@ -133,27 +131,27 @@ const editors = {
|
|
|
133
131
|
color: createEditor(Input, { type: "color" }),
|
|
134
132
|
tel: createEditor(Input, { type: "tel" }),
|
|
135
133
|
password: createEditor(Input, { type: "password" }),
|
|
136
|
-
file: createEditor((
|
|
134
|
+
file: createEditor((v) => createComponent(Files, mergeProps(v, {
|
|
137
135
|
class: "relative z-9 outline-2 outline-blue min-h-a! h-a! p-1 bg-#fff",
|
|
138
|
-
onAdd: () => chooseFile({ multiple: !0 }).then((e) =>
|
|
136
|
+
onAdd: () => chooseFile({ multiple: !0 }).then((e) => v.onChange([...v.value || [], ...e.map((e) => ({
|
|
139
137
|
name: e.name,
|
|
140
138
|
size: e.size
|
|
141
139
|
}))]))
|
|
142
140
|
}))),
|
|
143
141
|
checkbox: createEditor((e) => (() => {
|
|
144
|
-
var
|
|
145
|
-
return typeof
|
|
142
|
+
var v = _tmpl$6(), y = e.ref;
|
|
143
|
+
return typeof y == "function" ? use(y, v) : e.ref = v, insert(v, createComponent(Checkbox, mergeProps(e, {
|
|
146
144
|
ref: () => {},
|
|
147
145
|
onInput: () => {},
|
|
148
146
|
class: "mx-3!"
|
|
149
|
-
}))),
|
|
147
|
+
}))), v;
|
|
150
148
|
})()),
|
|
151
149
|
select: createEditor((e) => (() => {
|
|
152
|
-
var
|
|
153
|
-
return spread(
|
|
154
|
-
var
|
|
155
|
-
return insert(
|
|
156
|
-
})())),
|
|
150
|
+
var v = _tmpl$7();
|
|
151
|
+
return spread(v, e, !1, !0), insert(v, () => e.options?.map((e) => (() => {
|
|
152
|
+
var v = _tmpl$8();
|
|
153
|
+
return insert(v, () => e.label), effect(() => v.value = e.value), v;
|
|
154
|
+
})())), v;
|
|
157
155
|
})(), {}, !0)
|
|
158
156
|
};
|
|
159
157
|
delegateEvents(["keydown", "input"]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "..";
|
|
2
|
+
declare module '../index' {
|
|
3
|
+
interface Commands {
|
|
4
|
+
createExcel(data?: any[]): Promise<Blob>;
|
|
5
|
+
exportExcel(data?: any[]): Promise<void>;
|
|
6
|
+
readExcel(file?: File): Promise<any[]>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const ImportExportPlugin: Plugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { chooseFile } from "../utils.js";
|
|
2
|
+
function readFileAsArrayBuffer(e) {
|
|
3
|
+
return new Promise((t, n) => {
|
|
4
|
+
let r = new FileReader();
|
|
5
|
+
r.onload = () => t(r.result), r.onerror = n, r.readAsArrayBuffer(e);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function downloadBlob(e, t) {
|
|
9
|
+
let n = URL.createObjectURL(e), r = document.createElement("a");
|
|
10
|
+
r.href = n, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
|
|
11
|
+
}
|
|
12
|
+
const ImportExportPlugin = {
|
|
13
|
+
name: "ImportExportPlugin",
|
|
14
|
+
commands: (r) => ({
|
|
15
|
+
createExcel: async (e = r.props.data) => {
|
|
16
|
+
let t = await import("xlsx"), n = r.props.columns.filter((e) => !e[r.internal]), i = e.map((e) => Object.fromEntries(n.map((t) => [t.name, e[t.id]]))), a = t.utils.json_to_sheet(i), o = t.utils.book_new();
|
|
17
|
+
t.utils.book_append_sheet(o, a, "Data");
|
|
18
|
+
let s = t.write(o, {
|
|
19
|
+
bookType: "xlsx",
|
|
20
|
+
type: "array"
|
|
21
|
+
});
|
|
22
|
+
return new Blob([s], { type: "application/octet-stream" });
|
|
23
|
+
},
|
|
24
|
+
exportExcel: async (e = r.props.data) => {
|
|
25
|
+
let t = await r.commands.createExcel(e);
|
|
26
|
+
downloadBlob(t, "data.xlsx");
|
|
27
|
+
},
|
|
28
|
+
readExcel: async (n) => {
|
|
29
|
+
n ??= await chooseFile({ accept: ".xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" });
|
|
30
|
+
let i = await readFileAsArrayBuffer(n), a = await import("xlsx"), o = a.read(i, { type: "array" }), s = o.Sheets[o.SheetNames[0]], c = a.utils.sheet_to_json(s);
|
|
31
|
+
if (c.length < 1) return;
|
|
32
|
+
let l = r.props.columns.filter((e) => !e[r.internal]);
|
|
33
|
+
return c.slice(1).map((e) => Object.fromEntries(l.map((t) => [t.id, e[t.name]])));
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
export { ImportExportPlugin };
|
|
@@ -10,7 +10,7 @@ declare module '../index' {
|
|
|
10
10
|
interface Commands {
|
|
11
11
|
rowEquals: (a: any, b: any) => boolean;
|
|
12
12
|
rowIndexOf: (data: any[], row: any) => number;
|
|
13
|
-
rowChange: (row: any
|
|
13
|
+
rowChange: (row: any) => void;
|
|
14
14
|
rowsChange: (rows: any) => void;
|
|
15
15
|
addRows: (i: number, rows: any[], before?: boolean) => void;
|
|
16
16
|
deleteRows: (i: number[]) => void;
|
|
@@ -78,9 +78,9 @@ const MenuPlugin = {
|
|
|
78
78
|
rowIndexOf(r, i) {
|
|
79
79
|
return r.findIndex((r) => e.commands.rowEquals(r, i));
|
|
80
80
|
},
|
|
81
|
-
rowChange(r
|
|
82
|
-
let
|
|
83
|
-
|
|
81
|
+
rowChange(r) {
|
|
82
|
+
let i = [...e.rawProps.data || []], a = e.commands.rowIndexOf(i, r);
|
|
83
|
+
a > -1 && (i[a] = r, e.props.onDataChange?.(i));
|
|
84
84
|
},
|
|
85
85
|
rowsChange(r) {
|
|
86
86
|
let i = [...e.rawProps.data || []];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type JSX } from 'solid-js';
|
|
2
|
-
import { type Plugin, type
|
|
2
|
+
import { type Plugin, type TDProps } from '../..';
|
|
3
3
|
declare module '../../index' {
|
|
4
4
|
interface TableProps {
|
|
5
5
|
}
|
|
6
6
|
interface TableColumn {
|
|
7
7
|
type?: string;
|
|
8
|
-
render?: Render;
|
|
8
|
+
render?: string | Render;
|
|
9
9
|
enum?: Record<string, any> | {
|
|
10
10
|
label?: string;
|
|
11
11
|
value: any;
|
|
@@ -17,7 +17,7 @@ declare module '../../index' {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export type RenderProps =
|
|
20
|
+
export type RenderProps = TDProps & {
|
|
21
21
|
onChange: (v: any) => void;
|
|
22
22
|
};
|
|
23
23
|
export type Render = (props: RenderProps) => JSX.Element | any;
|
|
@@ -8,36 +8,36 @@ const RenderPlugin = {
|
|
|
8
8
|
name: "render",
|
|
9
9
|
priority: -Infinity,
|
|
10
10
|
store: () => ({ renders: { ...renders } }),
|
|
11
|
-
rewriteProps: { Td: ({ Td: e }, { store:
|
|
11
|
+
rewriteProps: { Td: ({ Td: e }, { store: m }) => (h) => createComponent(e, mergeProps(h, { get children() {
|
|
12
12
|
return (() => {
|
|
13
|
-
let e = ((e) => typeof e == "string" ?
|
|
14
|
-
return renderComponent(e, mergeProps$1(
|
|
15
|
-
...
|
|
16
|
-
[
|
|
17
|
-
}
|
|
13
|
+
let e = ((e) => typeof e == "string" ? m.renders[e] : e)(h.col.render ?? h.col.type) || text;
|
|
14
|
+
return renderComponent(e, mergeProps$1(h, { onChange: (e) => m.commands.rowChange({
|
|
15
|
+
...h.data,
|
|
16
|
+
[h.col.id]: e
|
|
17
|
+
}) }), m);
|
|
18
18
|
})();
|
|
19
19
|
} })) }
|
|
20
20
|
};
|
|
21
|
-
var text = (
|
|
21
|
+
var text = (h) => memo(() => memo(() => !!h.col.enum)() ? toArr(h.value).map((m) => resolveOptions(h.col.enum).find((e) => e.value == m)?.label ?? m).join(", ") : h.value);
|
|
22
22
|
const renders = {
|
|
23
23
|
text,
|
|
24
24
|
number: text,
|
|
25
25
|
date: text,
|
|
26
26
|
checkbox: (e) => (() => {
|
|
27
|
-
var
|
|
28
|
-
return insert(
|
|
27
|
+
var m = _tmpl$();
|
|
28
|
+
return insert(m, createComponent(Checkbox, {
|
|
29
29
|
class: "",
|
|
30
30
|
get value() {
|
|
31
|
-
return e.
|
|
31
|
+
return e.value;
|
|
32
32
|
},
|
|
33
33
|
get onChange() {
|
|
34
34
|
return e.onChange;
|
|
35
35
|
}
|
|
36
|
-
})),
|
|
36
|
+
})), m;
|
|
37
37
|
})(),
|
|
38
38
|
file: (e) => createComponent(Files, {
|
|
39
39
|
get value() {
|
|
40
|
-
return e.
|
|
40
|
+
return e.value;
|
|
41
41
|
},
|
|
42
42
|
get onChange() {
|
|
43
43
|
return e.onChange;
|
|
@@ -4,38 +4,37 @@ import { Ctx } from "../index.js";
|
|
|
4
4
|
import { className, createComponent, effect, memo, mergeProps, template, use } from "solid-js/web";
|
|
5
5
|
import { batch, untrack, useContext } from "solid-js";
|
|
6
6
|
import { reconcile } from "solid-js/store";
|
|
7
|
-
import { combineProps } from "@solid-primitives/props";
|
|
8
7
|
import { clamp } from "es-toolkit";
|
|
9
8
|
import { createEventListener } from "@solid-primitives/event-listener";
|
|
10
9
|
import { defaultsDeep } from "es-toolkit/compat";
|
|
11
|
-
var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"), ColHandle = (
|
|
12
|
-
let { props:
|
|
13
|
-
return usePointerDrag(() =>
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"), ColHandle = (f) => {
|
|
11
|
+
let { props: h, store: _ } = useContext(Ctx), v;
|
|
12
|
+
return usePointerDrag(() => v, { start(e, p, m) {
|
|
14
13
|
e.stopPropagation();
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
let e =
|
|
18
|
-
|
|
19
|
-
...p
|
|
20
|
-
width:
|
|
21
|
-
},
|
|
14
|
+
let g = f.x, { min: y, max: b } = h.resizable.col, x = v.parentElement, S = x.offsetWidth;
|
|
15
|
+
p((e, { ox: p }) => _[COL][f.x] = clamp(S + p, y, b)), m(() => {
|
|
16
|
+
let e = h.columns[g], f = [..._.rawProps.columns || []], p = f.findIndex((f) => f[_.ID] === e[_.ID]);
|
|
17
|
+
p > -1 && (f[p] = {
|
|
18
|
+
...f[p],
|
|
19
|
+
width: x.offsetWidth
|
|
20
|
+
}, h.onColumnsChange?.(f)), e.onWidthChange?.(x.offsetWidth);
|
|
22
21
|
});
|
|
23
22
|
} }), (() => {
|
|
24
|
-
var e = _tmpl$(),
|
|
25
|
-
return typeof
|
|
23
|
+
var e = _tmpl$(), p = v;
|
|
24
|
+
return typeof p == "function" ? use(p, e) : v = e, effect(() => className(e, `in-cell__resize-handle absolute top-0 right-0 flex justify-center w-10px! ${f.x == h.columns.length - 1 ? "justify-end!" : "w-10px! translate-x-1/2"} after:w-1 cursor-w-resize z-1`)), e;
|
|
26
25
|
})();
|
|
27
|
-
}, RowHandle = (
|
|
28
|
-
let { props:
|
|
29
|
-
return usePointerDrag(() =>
|
|
26
|
+
}, RowHandle = (f) => {
|
|
27
|
+
let { props: h, store: _ } = useContext(Ctx), v;
|
|
28
|
+
return usePointerDrag(() => v, { start(e, p, m) {
|
|
30
29
|
e.stopPropagation();
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
let e =
|
|
34
|
-
[...
|
|
30
|
+
let g = f.y, { min: y, max: b } = h.resizable.row, x = v.parentElement.offsetHeight;
|
|
31
|
+
p((e, { oy: p }) => _[ROW][f.y] = clamp(x + p, y, b)), m(() => {
|
|
32
|
+
let e = h.data[g];
|
|
33
|
+
[..._.rawProps.data || []].findIndex((f) => f[_.ID] === e[_.ID]);
|
|
35
34
|
});
|
|
36
|
-
} }), createEventListener(() =>
|
|
37
|
-
var e = _tmpl$(),
|
|
38
|
-
return typeof
|
|
35
|
+
} }), createEventListener(() => v, "dblclick", () => f.data[COL] = void 0), (() => {
|
|
36
|
+
var e = _tmpl$(), p = v;
|
|
37
|
+
return typeof p == "function" ? use(p, e) : v = e, effect(() => className(e, `in-cell__resize-handle absolute bottom-0 left-0 flex flex-col justify-center h-1! ${f.y == h.data.length - 1 ? "justify-end!" : ""} after:h-1 cursor-s-resize z-2`)), e;
|
|
39
38
|
})();
|
|
40
39
|
};
|
|
41
40
|
const ResizePlugin = {
|
|
@@ -58,23 +57,33 @@ const ResizePlugin = {
|
|
|
58
57
|
max: 400
|
|
59
58
|
}
|
|
60
59
|
}),
|
|
61
|
-
columns: ({ columns: e }, { store:
|
|
60
|
+
columns: ({ columns: e }, { store: f }) => (e = e.map((e, p) => ({
|
|
62
61
|
...e,
|
|
63
|
-
[
|
|
62
|
+
[f.ID]: e[f.ID] ??= Symbol()
|
|
64
63
|
})), e = e.map((e) => e.resizable === void 0 ? {
|
|
65
64
|
...e,
|
|
66
|
-
resizable:
|
|
67
|
-
} : e), e = e.map((e,
|
|
65
|
+
resizable: f.props?.resizable?.col.enable
|
|
66
|
+
} : e), e = e.map((e, p) => f[COL][p] ? {
|
|
68
67
|
...e,
|
|
69
|
-
width:
|
|
70
|
-
} : e), untrack(() => batch(() => reconcile(e, { key:
|
|
71
|
-
Th: ({ Th: e }, { store:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
width: f[COL][p]
|
|
69
|
+
} : e), untrack(() => batch(() => reconcile(e, { key: f.ID })(f.__resize__cols ??= [])))),
|
|
70
|
+
Th: ({ Th: e }, { store: f }) => (f) => createComponent(e, mergeProps(f, {
|
|
71
|
+
get class() {
|
|
72
|
+
return `relative ${f.class}`;
|
|
73
|
+
},
|
|
74
|
+
get children() {
|
|
75
|
+
return [f.children, memo(() => memo(() => !!f.col.resizable)() && createComponent(ColHandle, f))];
|
|
76
|
+
}
|
|
77
|
+
})),
|
|
78
|
+
Td: ({ Td: e }, { store: f }) => f.props?.resizable?.row.enable ? (p) => createComponent(e, mergeProps(p, {
|
|
79
|
+
get class() {
|
|
80
|
+
return `relative ${p.class}`;
|
|
81
|
+
},
|
|
82
|
+
get children() {
|
|
83
|
+
return [p.children, memo(() => memo(() => !!(p.x == 0 && f.props?.resizable?.row.enable))() && createComponent(RowHandle, p))];
|
|
84
|
+
}
|
|
85
|
+
})) : e,
|
|
86
|
+
cellStyle: ({ cellStyle: e }, { store: p }) => (m) => `${unFn(e, m)};` + (p[ROW][m.y] ? `height: ${p[ROW][m.y]}px` : "")
|
|
78
87
|
}
|
|
79
88
|
};
|
|
80
89
|
export { ResizePlugin };
|
|
@@ -50,7 +50,7 @@ const RowGroupPlugin = {
|
|
|
50
50
|
return d;
|
|
51
51
|
},
|
|
52
52
|
Td: ({ Td: d }, { store: _ }) => (v) => {
|
|
53
|
-
if (!v.data?.[GROUP]) return
|
|
53
|
+
if (!v.data?.[GROUP]) return d(v);
|
|
54
54
|
let { props: y } = useContext(Ctx), b = createMemo(() => _.rowGroup.isExpand(v.data));
|
|
55
55
|
return createComponent(d, mergeProps(v, { get children() {
|
|
56
56
|
return memo(() => y.columns?.findIndex((e) => !e[_.internal]) == v.x)() ? (() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useSelector } from "../hooks/useSelector.js";
|
|
2
2
|
import chevron_right_default from "../chevron-right.js";
|
|
3
3
|
import { createComponent, effect, insert, memo, mergeProps, style, template } from "solid-js/web";
|
|
4
|
-
import { combineProps } from "@solid-primitives/props";
|
|
5
4
|
import { createLazyMemo } from "@solid-primitives/memo";
|
|
6
5
|
var _tmpl$ = /* @__PURE__ */ template("<div class=\"flex items-center\">"), _tmpl$2 = /* @__PURE__ */ template("<span style=display:inline-block;width:16px;flex-shrink:0;margin-right:4px>");
|
|
7
6
|
function flattenTree(e, t, n, r, i = 0, a = null, o = [], s = /* @__PURE__ */ new Map()) {
|
|
@@ -19,7 +18,7 @@ function flattenTree(e, t, n, r, i = 0, a = null, o = [], s = /* @__PURE__ */ ne
|
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
const TreePlugin = (c) => {
|
|
22
|
-
let
|
|
21
|
+
let p = createLazyMemo(() => c.props.columns?.findIndex((e) => !e[c.internal]) ?? -1);
|
|
23
22
|
return {
|
|
24
23
|
name: "tree",
|
|
25
24
|
store: (t) => ({
|
|
@@ -37,27 +36,30 @@ const TreePlugin = (c) => {
|
|
|
37
36
|
let n = t.props.tree.children || "children", r = t.props.rowKey, { flat: i, meta: a } = flattenTree(e, n, r, (e) => t.tree.has(e));
|
|
38
37
|
return t._treeMeta = a, t._haschildren = Object.values(Object.fromEntries(a)).some((e) => e.hasChildren), i;
|
|
39
38
|
},
|
|
40
|
-
Td: ({ Td: e }, { store: c }) => (
|
|
41
|
-
let
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
var e =
|
|
49
|
-
return (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
Td: ({ Td: e }, { store: c }) => (l) => {
|
|
40
|
+
let f = () => c.props.rowKey, m = () => c._treeMeta?.get(l.data?.[f()]);
|
|
41
|
+
return createComponent(e, mergeProps(l, {
|
|
42
|
+
onDblClick: (e) => {
|
|
43
|
+
l.onDblClick?.(e), m()?.hasChildren && c.tree.toggle(l.data?.[f()]);
|
|
44
|
+
},
|
|
45
|
+
get children() {
|
|
46
|
+
return memo(() => !!(c._haschildren && l.x === p()))() ? (() => {
|
|
47
|
+
var e = _tmpl$();
|
|
48
|
+
return insert(e, (() => {
|
|
49
|
+
var e = memo(() => !!m()?.hasChildren);
|
|
50
|
+
return () => e() ? createComponent(chevron_right_default, {
|
|
51
|
+
class: "icon-clickable mr-1",
|
|
52
|
+
get style() {
|
|
53
|
+
return `transform: rotate(${c.tree.has(l.data?.[f()]) ? 90 : 0}deg); opacity: .6; flex-shrink: 0; transition: transform .15s`;
|
|
54
|
+
},
|
|
55
|
+
onClick: (e) => {
|
|
56
|
+
e.stopPropagation(), c.tree.toggle(l.data?.[f()]);
|
|
57
|
+
}
|
|
58
|
+
}) : _tmpl$2();
|
|
59
|
+
})(), null), insert(e, () => l.children, null), effect((t) => style(e, `padding-left: ${m()?.depth * 16}px`, t)), e;
|
|
60
|
+
})() : l.children;
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
61
63
|
}
|
|
62
64
|
},
|
|
63
65
|
commands: (e, { addRows: t }) => ({ addRows(n, r, i = !0) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isEmpty } from "../utils.js";
|
|
2
2
|
import { createComponent, insert, memo, mergeProps, template } from "solid-js/web";
|
|
3
|
-
import { combineProps } from "@solid-primitives/props";
|
|
4
3
|
var _tmpl$ = /* @__PURE__ */ template("<div class=cell-validation-error>"), _tmpl$2 = /* @__PURE__ */ template("<span class=\"mr-1 c-red/75\">*");
|
|
5
4
|
const ValidatorPlugin = {
|
|
6
5
|
name: "validator",
|
|
@@ -55,19 +54,22 @@ const ValidatorPlugin = {
|
|
|
55
54
|
}
|
|
56
55
|
}),
|
|
57
56
|
rewriteProps: {
|
|
58
|
-
Td: ({ Td: e }, { store: a }) => (
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
Td: ({ Td: e }, { store: a }) => (s) => {
|
|
58
|
+
let c = () => a.cellValidationErrors[s.data[a.props.rowKey]]?.[s.col.id];
|
|
59
|
+
return createComponent(e, mergeProps(s, {
|
|
60
|
+
get class() {
|
|
61
|
+
return s.class + " " + (c() == null ? "" : "is-invalid");
|
|
62
|
+
},
|
|
63
|
+
get children() {
|
|
64
|
+
return [s.children, memo(() => memo(() => c() != null)() && (() => {
|
|
65
|
+
var e = _tmpl$();
|
|
66
|
+
return insert(e, c), e;
|
|
67
|
+
})())];
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
68
70
|
},
|
|
69
71
|
Th: ({ Th: e }, { store: n }) => (n) => createComponent(e, mergeProps(n, { get children() {
|
|
70
|
-
return [memo(() => memo(() => !!n.col.required)() && _tmpl$2()),
|
|
72
|
+
return [memo(() => memo(() => !!n.col.required)() && _tmpl$2()), n.children];
|
|
71
73
|
} }))
|
|
72
74
|
}
|
|
73
75
|
};
|
|
@@ -9,10 +9,24 @@ import { defaultRangeExtractor } from "@tanstack/solid-virtual";
|
|
|
9
9
|
var $ML = Symbol();
|
|
10
10
|
const VirtualScrollPlugin = {
|
|
11
11
|
name: "virtual-scroll",
|
|
12
|
+
store: (e) => ({
|
|
13
|
+
scrollToCell(r, i, a) {
|
|
14
|
+
r = typeof r == "object" ? e.props.columns.indexOf(r) : r, i = typeof i == "object" ? e.props.data.indexOf(i) : i;
|
|
15
|
+
let o = e.virtualizerX, s = e.virtualizerY;
|
|
16
|
+
o.scrollToIndex(r, !0), s.scrollToIndex(i, !0);
|
|
17
|
+
},
|
|
18
|
+
scrollCellIfNeeded(r, i, a) {
|
|
19
|
+
r = typeof r == "object" ? e.props.columns.indexOf(r) : r, i = typeof i == "object" ? e.props.data.indexOf(i) : i;
|
|
20
|
+
let o = e.virtualizerX, s = e.virtualizerY, c = e.table.querySelector(`[x="${r}"][y="${i}"]`);
|
|
21
|
+
if (!c) return e.scrollToCell(r, i);
|
|
22
|
+
let l = c.getBoundingClientRect(), u = e.scroll_el.getBoundingClientRect();
|
|
23
|
+
(l.top < u.top || l.bottom > u.bottom) && s.scrollToIndex(i, !0), (l.left < u.left || l.right > u.right) && o.scrollToIndex(r, !0);
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
12
26
|
rewriteProps: {
|
|
13
27
|
virtual: ({ virtual: e }) => defaultsDeep(e, {
|
|
14
|
-
x: { overscan:
|
|
15
|
-
y: { overscan:
|
|
28
|
+
x: { overscan: 2 },
|
|
29
|
+
y: { overscan: 2 }
|
|
16
30
|
}),
|
|
17
31
|
Scroll: ({ Scroll: e }, { store: r }) => (r) => (r = combineProps({ class: "virtual" }, r), createComponent(e, r)),
|
|
18
32
|
Table: ({ Table: r }, { store: o }) => (d) => {
|