intable 0.0.37 → 0.0.39
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/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/plugins/EditablePlugin.js +70 -76
- package/dist/plugins/ExpandPlugin.js +1 -1
- package/dist/plugins/ImportExportPlugin.js +4 -4
- package/dist/plugins/KeyEachPlugin.d.ts +15 -0
- package/dist/plugins/KeyEachPlugin.js +29 -0
- package/dist/plugins/RowGroupPlugin.js +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ import './plugins/AggregatePlugin';
|
|
|
21
21
|
import './plugins/AutoFillPlugin';
|
|
22
22
|
import './plugins/FilterPlugin';
|
|
23
23
|
import './plugins/TooltipPlugin';
|
|
24
|
+
import './plugins/KeyEachPlugin';
|
|
24
25
|
export declare const Ctx: import("solid-js").Context<{
|
|
25
26
|
props: TableProps2;
|
|
26
27
|
store: TableStore;
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { AutoFillPlugin } from "./plugins/AutoFillPlugin.js";
|
|
|
23
23
|
import { FilterPlugin } from "./plugins/FilterPlugin.js";
|
|
24
24
|
import { ImportExportPlugin } from "./plugins/ImportExportPlugin.js";
|
|
25
25
|
import { TooltipPlugin } from "./plugins/TooltipPlugin.js";
|
|
26
|
+
import { KeyEachPlugin } from "./plugins/KeyEachPlugin.js";
|
|
26
27
|
import loading_bold_default from "./loading-bold.js";
|
|
27
28
|
import { createComponent, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
28
29
|
import { $PROXY, For, batch, createComputed, createContext, createEffect, createMemo, createRenderEffect, createSignal, getOwner, mapArray, mergeProps as mergeProps$1, on, onCleanup, onMount, runWithOwner, untrack, useContext } from "solid-js";
|
|
@@ -426,6 +427,7 @@ const defaultsPlugins = [
|
|
|
426
427
|
AggregatePlugin,
|
|
427
428
|
AutoFillPlugin,
|
|
428
429
|
ImportExportPlugin,
|
|
429
|
-
TooltipPlugin
|
|
430
|
+
TooltipPlugin,
|
|
431
|
+
KeyEachPlugin
|
|
430
432
|
];
|
|
431
433
|
export { Ctx, Intable, src_default as default, defaultsPlugins };
|
|
@@ -3,7 +3,7 @@ import { Checkbox, Files } from "./RenderPlugin/components.js";
|
|
|
3
3
|
import Textarea_default from "../components/Textarea.js";
|
|
4
4
|
import { Ctx } from "../index.js";
|
|
5
5
|
import { addEventListener, createComponent, delegateEvents, effect, insert, memo, mergeProps, spread, template, use } from "solid-js/web";
|
|
6
|
-
import {
|
|
6
|
+
import { createEffect, createMemo, createRoot, createSignal, on, onCleanup, useContext } from "solid-js";
|
|
7
7
|
import { createMutable } from "solid-js/store";
|
|
8
8
|
import { combineProps } from "@solid-primitives/props";
|
|
9
9
|
import { createAsyncMemo } from "@solid-primitives/memo";
|
|
@@ -13,112 +13,106 @@ const EditablePlugin = {
|
|
|
13
13
|
name: "editable",
|
|
14
14
|
store: () => ({ editors: { ...editors } }),
|
|
15
15
|
rewriteProps: {
|
|
16
|
-
editable: ({ editable: e }, { store:
|
|
17
|
-
let
|
|
18
|
-
return !!
|
|
16
|
+
editable: ({ editable: e }, { store: _ }) => (y) => {
|
|
17
|
+
let b = [y.col.editable, e].filter((e) => e != null);
|
|
18
|
+
return !!b.length && b.every((e) => unFn(e, y)) && !y.data[_.internal] && !y.col[_.internal];
|
|
19
19
|
},
|
|
20
|
-
Td: ({ Td: e }, { store:
|
|
21
|
-
let
|
|
22
|
-
if (
|
|
23
|
-
let e =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
Td: ({ Td: e }, { store: _ }) => (y) => {
|
|
21
|
+
let b, { props: x } = useContext(Ctx), [T, E] = createSignal(!1), O = "", k = () => unFn(x.editable, y), j = () => (([e, _]) => y.x == e && y.y == _)(_.selected.start || []), M = () => j() && k() && !T(), [N, P] = createSignal(!1), F = createAsyncMemo(() => {
|
|
22
|
+
if (T()) {
|
|
23
|
+
let e = createMemo(() => JSON.stringify(_.selected ?? "{}"));
|
|
24
|
+
createEffect(on(e, () => E(!1), { defer: !0 })), R.w = b.getBoundingClientRect().width, R.h = b.getBoundingClientRect().height;
|
|
25
|
+
let v = !1, S = y.data[y.col.id], C = ((e) => typeof e == "string" ? _.editors[e] : e)(y.col.editor ?? y.col.type ?? (y.col.enum ? "select" : "text")), w = {
|
|
26
|
+
props: y.col.editorProps,
|
|
27
|
+
col: y.col,
|
|
28
|
+
eventKey: O,
|
|
29
|
+
data: y.data,
|
|
30
|
+
value: S,
|
|
29
31
|
ok: async () => {
|
|
30
|
-
await
|
|
32
|
+
await I(D.getValue()), E(!1);
|
|
31
33
|
},
|
|
32
|
-
cancel: () => (
|
|
33
|
-
onChange: (e) =>
|
|
34
|
-
},
|
|
35
|
-
return onCleanup(() => {
|
|
36
|
-
!
|
|
37
|
-
...
|
|
38
|
-
[
|
|
39
|
-
}),
|
|
40
|
-
}), [w,
|
|
34
|
+
cancel: () => (v = !0, E(!1)),
|
|
35
|
+
onChange: (e) => T() && I(e).catch(() => {})
|
|
36
|
+
}, D = C(w);
|
|
37
|
+
return queueMicrotask(() => D.focus?.()), onCleanup(() => {
|
|
38
|
+
!v && D.getValue() !== S && _.commands.rowChange({
|
|
39
|
+
...x.data[y.y],
|
|
40
|
+
[y.col.id]: D.getValue()
|
|
41
|
+
}), v || I(D.getValue()).catch(() => {}), O = "", D.destroy();
|
|
42
|
+
}), [w, D];
|
|
41
43
|
}
|
|
42
44
|
});
|
|
43
|
-
async function
|
|
45
|
+
async function I(e) {
|
|
44
46
|
try {
|
|
45
|
-
|
|
47
|
+
P(!0), await _.validateCell(e, y.data, y.col);
|
|
46
48
|
} finally {
|
|
47
|
-
|
|
49
|
+
P(!1);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
I()?.[1]?.focus?.();
|
|
52
|
-
}), createEffect(() => {
|
|
53
|
-
if (E()) {
|
|
54
|
-
let e = createMemo(() => JSON.stringify(y.selected ?? "{}"));
|
|
55
|
-
createEffect(on(e, () => D(!1), { defer: !0 }));
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
let R, z = createMutable({
|
|
52
|
+
let L, R = createMutable({
|
|
59
53
|
w: 0,
|
|
60
54
|
h: 0
|
|
61
55
|
});
|
|
62
|
-
return
|
|
63
|
-
ref: (e) =>
|
|
56
|
+
return y = combineProps(y, {
|
|
57
|
+
ref: (e) => b = e,
|
|
64
58
|
get class() {
|
|
65
|
-
return
|
|
59
|
+
return T() ? "is-editing" : "";
|
|
66
60
|
},
|
|
67
61
|
get style() {
|
|
68
|
-
return
|
|
62
|
+
return T() ? `width: ${R.w}px; height: ${R.h}px; padding: 0; ` : "";
|
|
69
63
|
},
|
|
70
|
-
onClick: () =>
|
|
71
|
-
onDblClick: () =>
|
|
72
|
-
onKeyDown: (e) => e.key == "Escape" &&
|
|
73
|
-
}), createComponent(e, mergeProps(
|
|
74
|
-
return [memo(() => memo(() => !!
|
|
64
|
+
onClick: () => L?.focus?.(),
|
|
65
|
+
onDblClick: () => E(k()),
|
|
66
|
+
onKeyDown: (e) => e.key == "Escape" && F()?.[0].cancel()
|
|
67
|
+
}), createComponent(e, mergeProps(y, { get children() {
|
|
68
|
+
return [memo(() => memo(() => !!F()?.[1]?.el)() ? (() => {
|
|
75
69
|
var e = _tmpl$();
|
|
76
70
|
return addEventListener(e, "keydown", (e) => {
|
|
77
|
-
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && (
|
|
78
|
-
}), addEventListener(e, "pointerdown", (e) => e.stopPropagation()), insert(e, () =>
|
|
79
|
-
var e = memo(() => !!
|
|
71
|
+
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && (F()?.[0].ok(), e.preventDefault()), e.key == "Escape" && F()?.[0].cancel();
|
|
72
|
+
}), addEventListener(e, "pointerdown", (e) => e.stopPropagation()), insert(e, () => F()?.[1]?.el, null), insert(e, (() => {
|
|
73
|
+
var e = memo(() => !!N());
|
|
80
74
|
return () => e() && _tmpl$2();
|
|
81
75
|
})(), null), e;
|
|
82
|
-
})() :
|
|
76
|
+
})() : y.children), memo(() => memo(() => !!M())() && (() => {
|
|
83
77
|
var e = _tmpl$3();
|
|
84
78
|
return e.addEventListener("compositionend", () => {
|
|
85
|
-
|
|
79
|
+
E(!0);
|
|
86
80
|
}), e.$$input = (e) => {
|
|
87
|
-
|
|
81
|
+
O = e.target.value, E(!e.isComposing);
|
|
88
82
|
}, e.$$keydown = (e) => {
|
|
89
83
|
e.key == " " && e.preventDefault();
|
|
90
84
|
}, use((e) => {
|
|
91
|
-
|
|
85
|
+
L = e, delay(0).then(() => e.focus({ preventScroll: !0 }));
|
|
92
86
|
}, e), e;
|
|
93
87
|
})())];
|
|
94
88
|
} }));
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
91
|
};
|
|
98
|
-
var createEditor = (e,
|
|
99
|
-
let [
|
|
92
|
+
var createEditor = (e, v, y) => ({ eventKey: b, value: x, col: S, ok: C, cancel: T, props: E, onChange: D }) => createRoot((T) => {
|
|
93
|
+
let [O, k] = createSignal(b || x), A;
|
|
100
94
|
return createComponent(e, mergeProps({
|
|
101
|
-
ref: (e) =>
|
|
95
|
+
ref: (e) => A = e,
|
|
102
96
|
class: "relative block px-2 size-full z-9 box-border resize-none outline-0",
|
|
103
97
|
get value() {
|
|
104
|
-
return
|
|
98
|
+
return O();
|
|
105
99
|
},
|
|
106
|
-
onInput: (e) => (
|
|
107
|
-
onChange: (e) => (
|
|
100
|
+
onInput: (e) => (k(e instanceof Event ? e.target.value : e), D?.(O())),
|
|
101
|
+
onChange: (e) => (k(e instanceof Event ? e.target.value : e), D?.(O()), y && C()),
|
|
108
102
|
get options() {
|
|
109
|
-
return memo(() => !!
|
|
103
|
+
return memo(() => !!S.enum)() ? resolveOptions(S.enum ?? []) : void 0;
|
|
110
104
|
}
|
|
111
|
-
},
|
|
112
|
-
|
|
105
|
+
}, v, E)), setTimeout(() => {
|
|
106
|
+
y && A?.showPicker?.();
|
|
113
107
|
}, 0), {
|
|
114
|
-
el:
|
|
115
|
-
getValue:
|
|
116
|
-
focus: () =>
|
|
117
|
-
destroy:
|
|
108
|
+
el: A,
|
|
109
|
+
getValue: O,
|
|
110
|
+
focus: () => A.focus(),
|
|
111
|
+
destroy: T
|
|
118
112
|
};
|
|
119
113
|
}), Input = (e) => (() => {
|
|
120
|
-
var
|
|
121
|
-
return spread(
|
|
114
|
+
var _ = _tmpl$4();
|
|
115
|
+
return spread(_, e, !1, !1), _;
|
|
122
116
|
})();
|
|
123
117
|
const editors = {
|
|
124
118
|
text: createEditor(Input),
|
|
@@ -136,27 +130,27 @@ const editors = {
|
|
|
136
130
|
color: createEditor(Input, { type: "color" }),
|
|
137
131
|
tel: createEditor(Input, { type: "tel" }),
|
|
138
132
|
password: createEditor(Input, { type: "password" }),
|
|
139
|
-
file: createEditor((
|
|
133
|
+
file: createEditor((_) => createComponent(Files, mergeProps(_, {
|
|
140
134
|
class: "relative z-9 outline-2 outline-blue min-h-a! h-a! p-1 bg-#fff",
|
|
141
|
-
onAdd: () => chooseFile({ multiple: !0 }).then((e) =>
|
|
135
|
+
onAdd: () => chooseFile({ multiple: !0 }).then((e) => _.onChange([..._.value || [], ...e.map((e) => ({
|
|
142
136
|
name: e.name,
|
|
143
137
|
size: e.size
|
|
144
138
|
}))]))
|
|
145
139
|
}))),
|
|
146
140
|
checkbox: createEditor((e) => (() => {
|
|
147
|
-
var
|
|
148
|
-
return typeof
|
|
141
|
+
var _ = _tmpl$5(), v = e.ref;
|
|
142
|
+
return typeof v == "function" ? use(v, _) : e.ref = _, insert(_, createComponent(Checkbox, mergeProps(e, {
|
|
149
143
|
ref: () => {},
|
|
150
144
|
onInput: () => {},
|
|
151
145
|
class: "mx-3!"
|
|
152
|
-
}))),
|
|
146
|
+
}))), _;
|
|
153
147
|
})()),
|
|
154
148
|
select: createEditor((e) => (() => {
|
|
155
|
-
var
|
|
156
|
-
return
|
|
157
|
-
var
|
|
158
|
-
return insert(
|
|
159
|
-
})()), null),
|
|
149
|
+
var _ = _tmpl$6();
|
|
150
|
+
return _.firstChild, spread(_, e, !1, !0), insert(_, () => e.options?.map((_) => (() => {
|
|
151
|
+
var v = _tmpl$7();
|
|
152
|
+
return insert(v, () => _.label), effect(() => v.selected = _.value === e.value), effect(() => v.value = _.value), v;
|
|
153
|
+
})()), null), _;
|
|
160
154
|
})(), {}, !0)
|
|
161
155
|
};
|
|
162
156
|
delegateEvents(["keydown", "input"]);
|
|
@@ -32,7 +32,7 @@ const ExpandPlugin = {
|
|
|
32
32
|
}, h)), effect(() => setAttribute(m, "colspan", h.props.columns?.length)), m;
|
|
33
33
|
})();
|
|
34
34
|
} })) : m,
|
|
35
|
-
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)),
|
|
35
|
+
Td: ({ Td: e }, { store: m }) => m.props.expand?.enable ? (h) => (h = combineProps(h, { onClick: () => h.col.id == m.expandCol.id && m.commands.expand.toggle(h.data) }), createComponent(e, h)) : e,
|
|
36
36
|
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
|
|
37
37
|
}
|
|
38
38
|
};
|
|
@@ -6,8 +6,8 @@ function readFileAsArrayBuffer(e) {
|
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
8
|
function downloadBlob(e, t) {
|
|
9
|
-
let n =
|
|
10
|
-
|
|
9
|
+
let n = document.createElement("a");
|
|
10
|
+
n.href = URL.createObjectURL(e), n.download = t, document.body.appendChild(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(n.href), 15 * 1e3);
|
|
11
11
|
}
|
|
12
12
|
const ImportExportPlugin = {
|
|
13
13
|
name: "ImportExportPlugin",
|
|
@@ -19,7 +19,7 @@ const ImportExportPlugin = {
|
|
|
19
19
|
bookType: "xlsx",
|
|
20
20
|
type: "array"
|
|
21
21
|
});
|
|
22
|
-
return new Blob([s], { type: "application/
|
|
22
|
+
return new Blob([s], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
23
23
|
},
|
|
24
24
|
exportExcel: async (e = r.props.data) => {
|
|
25
25
|
let t = await r.commands.createExcel(e);
|
|
@@ -28,7 +28,7 @@ const ImportExportPlugin = {
|
|
|
28
28
|
readExcel: async (n) => {
|
|
29
29
|
n ??= await chooseFile({ accept: ".xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" });
|
|
30
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;
|
|
31
|
+
if (c.length < 1) return [];
|
|
32
32
|
let l = r.props.columns.filter((e) => !e[r.internal]);
|
|
33
33
|
return c.slice(1).map((e) => Object.fromEntries(l.map((t) => [t.id, e[t.name]])));
|
|
34
34
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Plugin } from '..';
|
|
2
|
+
declare module '..' {
|
|
3
|
+
interface TableProps {
|
|
4
|
+
useRowKey?: boolean;
|
|
5
|
+
useColKey?: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface TableColumn {
|
|
8
|
+
}
|
|
9
|
+
interface TableStore {
|
|
10
|
+
[COLUMNS]: TableColumn[];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
declare const COLUMNS: unique symbol;
|
|
14
|
+
export declare const KeyEachPlugin: Plugin;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { change2 } from "../utils.js";
|
|
2
|
+
import { createComponent } from "solid-js/web";
|
|
3
|
+
import { For, createMemo, untrack } from "solid-js";
|
|
4
|
+
import { keyBy } from "es-toolkit";
|
|
5
|
+
var COLUMNS = Symbol("columns");
|
|
6
|
+
const KeyEachPlugin = {
|
|
7
|
+
name: "keyEach",
|
|
8
|
+
priority: -Infinity,
|
|
9
|
+
rewriteProps: {
|
|
10
|
+
columns: ({ columns: r }, { store: i }) => {
|
|
11
|
+
if (!i.props.useColKey) return r;
|
|
12
|
+
let a = untrack(() => keyBy(i[COLUMNS] ?? [], (e) => e.id));
|
|
13
|
+
return i[COLUMNS] = r.map((r) => a[r.id] ? change2(a[r.id], r) : { ...r });
|
|
14
|
+
},
|
|
15
|
+
EachRows: ({ EachRows: e }, { store: o }) => o.props.useRowKey ? (e) => {
|
|
16
|
+
let s = createMemo(() => ({
|
|
17
|
+
list: e.each.map((e) => e[o.props.rowKey]),
|
|
18
|
+
map: keyBy(e.each, (e) => e[o.props.rowKey])
|
|
19
|
+
}));
|
|
20
|
+
return createComponent(For, {
|
|
21
|
+
get each() {
|
|
22
|
+
return s().list;
|
|
23
|
+
},
|
|
24
|
+
children: (r, i) => e.children(() => s().map[r], i)
|
|
25
|
+
});
|
|
26
|
+
} : e
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export { KeyEachPlugin };
|
|
@@ -49,7 +49,7 @@ const RowGroupPlugin = {
|
|
|
49
49
|
}
|
|
50
50
|
return d;
|
|
51
51
|
},
|
|
52
|
-
Td: ({ Td: d }, { store: _ }) => (v) => {
|
|
52
|
+
Td: ({ Td: d }, { store: _ }) => _.props?.rowGroup?.fields ? (v) => {
|
|
53
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() {
|
|
@@ -64,7 +64,7 @@ const RowGroupPlugin = {
|
|
|
64
64
|
}), null), insert(l, () => v.data[GROUP].value, null), effect((e) => style(l, `padding-left: ${(v.data[GROUP].path.length - 1) * 16}px`, e)), l;
|
|
65
65
|
})() : v.children;
|
|
66
66
|
} }));
|
|
67
|
-
}
|
|
67
|
+
} : d
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
var GROUP = Symbol("row-group"), expandData = (e, l, u = []) => {
|