intable 0.0.58 → 0.0.60
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/LICENSE +21 -21
- package/README.md +97 -97
- package/dist/__uno.css +1 -1
- package/dist/hooks/useSelector.d.ts +2 -1
- package/dist/hooks/useSelector.js +48 -51
- package/dist/index.d.ts +4 -1
- package/dist/index.js +30 -15
- package/dist/plugins/DiffPlugin.js +4 -1
- package/dist/plugins/EditablePlugin.d.ts +1 -15
- package/dist/plugins/EditablePlugin.js +85 -80
- package/dist/plugins/ExpandPlugin.js +4 -1
- package/dist/plugins/HeaderGroup.js +38 -39
- package/dist/plugins/LoadMorePlugin.d.ts +1 -1
- package/dist/plugins/LoadMorePlugin.js +30 -31
- package/dist/plugins/PaginationPlugin.d.ts +22 -0
- package/dist/plugins/PaginationPlugin.js +105 -0
- package/dist/plugins/RenderPlugin/components.d.ts +4 -0
- package/dist/plugins/RenderPlugin/components.js +102 -47
- package/dist/plugins/RenderPlugin/index.d.ts +5 -0
- package/dist/plugins/RenderPlugin/index.js +51 -18
- package/dist/plugins/RowGroupPlugin.js +57 -58
- package/dist/plugins/RowSelectionPlugin.js +4 -1
- package/dist/plugins/TreePlugin.d.ts +4 -1
- package/dist/plugins/TreePlugin.js +54 -48
- package/dist/plugins/VirtualScrollPlugin.js +76 -77
- package/dist/style.css +2 -2
- package/dist/theme/antd.scss +41 -41
- package/dist/theme/dark.scss +46 -46
- package/dist/theme/element-plus.scss +38 -38
- package/dist/theme/github.scss +80 -80
- package/dist/theme/material.scss +73 -73
- package/dist/theme/shadcn.scss +66 -66
- package/dist/theme/stripe.scss +57 -57
- package/package.json +1 -1
|
@@ -2,9 +2,8 @@ import { chooseFile, resolveOptions, unFn } from "../utils.js";
|
|
|
2
2
|
import { mergeProps as mergeProps$2 } from "../mergeProps2.js";
|
|
3
3
|
import { Checkbox, Files } from "./RenderPlugin/components.js";
|
|
4
4
|
import Textarea_default from "../components/Textarea.js";
|
|
5
|
-
import { Ctx } from "../index.js";
|
|
6
5
|
import { addEventListener, createComponent, delegateEvents, effect, insert, memo, spread, template, use } from "solid-js/web";
|
|
7
|
-
import { createEffect, createMemo, createRoot, createSignal, on, onCleanup
|
|
6
|
+
import { createEffect, createMemo, createRoot, createSignal, on, onCleanup } from "solid-js";
|
|
8
7
|
import { createMutable } from "solid-js/store";
|
|
9
8
|
import { createAsyncMemo } from "@solid-primitives/memo";
|
|
10
9
|
import { delay } from "es-toolkit";
|
|
@@ -13,109 +12,109 @@ const EditablePlugin = {
|
|
|
13
12
|
name: "editable",
|
|
14
13
|
store: () => ({ editors: { ...editors } }),
|
|
15
14
|
rewriteProps: {
|
|
16
|
-
editable: ({ editable: e }, { store:
|
|
17
|
-
let
|
|
18
|
-
return !!
|
|
15
|
+
editable: ({ editable: e }, { store: p }) => (h) => {
|
|
16
|
+
let g = [h.col.editable, e].filter((e) => e != null);
|
|
17
|
+
return !!g.length && g.every((e) => unFn(e, h)) && !h.data[p.internal] && !h.col[p.internal];
|
|
19
18
|
},
|
|
20
|
-
Td: ({ Td: e }, { store:
|
|
21
|
-
let
|
|
22
|
-
return createMemo(() =>
|
|
23
|
-
let
|
|
24
|
-
if (
|
|
25
|
-
let e = createMemo(() => JSON.stringify(
|
|
26
|
-
createEffect(on(e, () =>
|
|
27
|
-
let
|
|
28
|
-
props:
|
|
29
|
-
col:
|
|
30
|
-
eventKey:
|
|
31
|
-
data:
|
|
32
|
-
value:
|
|
19
|
+
Td: ({ Td: e }, { store: p }) => (g) => {
|
|
20
|
+
let { props: _ } = p, v, x = () => unFn(p.props.editable, g);
|
|
21
|
+
return createMemo(() => x() ? unFn(() => {
|
|
22
|
+
let m = "", [S, w] = createSignal(!1), T = () => (([e, p]) => g.x == e && g.y == p)(p.selected.start || []), k = () => x() && !S() && T(), [A, j] = createSignal(!1), M = createAsyncMemo(() => {
|
|
23
|
+
if (S()) {
|
|
24
|
+
let e = createMemo(() => JSON.stringify(p.selected ?? "{}"));
|
|
25
|
+
createEffect(on(e, () => w(!1), { defer: !0 })), F.w = v.getBoundingClientRect().width, F.h = v.getBoundingClientRect().height;
|
|
26
|
+
let h = !1, y = g.data[g.col.id], b = ((e) => typeof e == "string" ? p.editors[e] : e)(g.col.editor ?? g.col.type ?? (g.col.enum && "select")) ?? (y == null ? null : p.editors[typeof y]) ?? p.editors.text, x = {
|
|
27
|
+
props: g.col.editorProps,
|
|
28
|
+
col: g.col,
|
|
29
|
+
eventKey: m,
|
|
30
|
+
data: g.data,
|
|
31
|
+
value: y,
|
|
33
32
|
ok: async () => {
|
|
34
|
-
await
|
|
33
|
+
await N(C.getValue()), w(!1);
|
|
35
34
|
},
|
|
36
|
-
cancel: () => (
|
|
37
|
-
onChange: (e) =>
|
|
38
|
-
},
|
|
39
|
-
return queueMicrotask(() =>
|
|
40
|
-
!
|
|
41
|
-
...
|
|
42
|
-
[
|
|
43
|
-
}),
|
|
44
|
-
}), [
|
|
35
|
+
cancel: () => (h = !0, w(!1)),
|
|
36
|
+
onChange: (e) => S() && N(e).catch(() => {})
|
|
37
|
+
}, C = b(x);
|
|
38
|
+
return queueMicrotask(() => C.focus?.()), onCleanup(() => {
|
|
39
|
+
!h && C.getValue() !== y && p.commands.rowChange({
|
|
40
|
+
..._.data[g.y],
|
|
41
|
+
[g.col.id]: C.getValue()
|
|
42
|
+
}), h || N(C.getValue()).catch(() => {}), m = "", C.destroy();
|
|
43
|
+
}), [x, C];
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
|
-
async function
|
|
46
|
+
async function N(e) {
|
|
48
47
|
try {
|
|
49
|
-
|
|
48
|
+
j(!0), await p.validateCell(e, g.data, g.col);
|
|
50
49
|
} finally {
|
|
51
|
-
|
|
50
|
+
j(!1);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
let
|
|
53
|
+
let P, F = createMutable({
|
|
55
54
|
w: 0,
|
|
56
55
|
h: 0
|
|
57
|
-
}),
|
|
58
|
-
ref: (e) => (
|
|
56
|
+
}), I = mergeProps$2(g, {
|
|
57
|
+
ref: (e) => (v = e, g.ref?.(e)),
|
|
59
58
|
get class() {
|
|
60
|
-
return [
|
|
59
|
+
return [S() ? "is-editing" : "", g.class].filter(Boolean).join(" ");
|
|
61
60
|
},
|
|
62
61
|
get style() {
|
|
63
|
-
return [
|
|
62
|
+
return [S() ? `width: ${F.w}px; height: ${F.h}px; padding: 0; ` : "", g.style].filter(Boolean).join(" ");
|
|
64
63
|
},
|
|
65
|
-
onClick: (e) => (
|
|
66
|
-
onDblClick: (e) => (
|
|
67
|
-
onKeyDown: (e) => (e.key == "Escape" &&
|
|
64
|
+
onClick: (e) => (P?.focus?.(), g.onClick?.(e)),
|
|
65
|
+
onDblClick: (e) => (w(x()), g.onDblClick?.(e)),
|
|
66
|
+
onKeyDown: (e) => (e.key == "Escape" && M()?.[0].cancel(), g.onKeyDown?.(e))
|
|
68
67
|
});
|
|
69
|
-
return createComponent(e, mergeProps$2(
|
|
70
|
-
return [() =>
|
|
68
|
+
return createComponent(e, mergeProps$2(I, { get children() {
|
|
69
|
+
return [() => M()?.[1]?.el ? (() => {
|
|
71
70
|
var e = _tmpl$();
|
|
72
71
|
return addEventListener(e, "keydown", (e) => {
|
|
73
|
-
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && (
|
|
74
|
-
}), addEventListener(e, "pointerdown", (e) => e.stopPropagation()), insert(e, () =>
|
|
75
|
-
var e = memo(() => !!
|
|
72
|
+
e.stopPropagation(), e.key == "Enter" && !e.shiftKey && (M()?.[0].ok(), e.preventDefault()), e.key == "Escape" && M()?.[0].cancel();
|
|
73
|
+
}), addEventListener(e, "pointerdown", (e) => e.stopPropagation()), insert(e, () => M()?.[1]?.el, null), insert(e, (() => {
|
|
74
|
+
var e = memo(() => !!A());
|
|
76
75
|
return () => e() && _tmpl$2();
|
|
77
76
|
})(), null), e;
|
|
78
|
-
})() :
|
|
77
|
+
})() : g.children, () => k() && (() => {
|
|
79
78
|
var e = _tmpl$3();
|
|
80
79
|
return e.addEventListener("compositionend", () => {
|
|
81
|
-
|
|
80
|
+
w(!0);
|
|
82
81
|
}), e.$$input = (e) => {
|
|
83
|
-
|
|
82
|
+
m = e.target.value, w(!e.isComposing);
|
|
84
83
|
}, e.$$keydown = (e) => {
|
|
85
84
|
e.key == " " && e.preventDefault();
|
|
86
85
|
}, use((e) => {
|
|
87
|
-
|
|
86
|
+
P = e, delay(0).then(() => e.focus({ preventScroll: !0 }));
|
|
88
87
|
}, e), e;
|
|
89
88
|
})()];
|
|
90
89
|
} }));
|
|
91
|
-
}) : createComponent(e,
|
|
90
|
+
}) : createComponent(e, g));
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
};
|
|
95
|
-
var createEditor = (e,
|
|
96
|
-
let [
|
|
94
|
+
var createEditor = (e, m, g) => ({ eventKey: _, value: v, col: y, ok: x, cancel: S, props: C, onChange: w }) => createRoot((S) => {
|
|
95
|
+
let T = m?.out ?? ((e) => e), [E, D] = createSignal(_ || v), O;
|
|
97
96
|
return createComponent(e, mergeProps$2({
|
|
98
|
-
ref: (e) =>
|
|
97
|
+
ref: (e) => O = e,
|
|
99
98
|
class: "relative block px-2 size-full z-9 box-border resize-none outline-0",
|
|
100
99
|
get value() {
|
|
101
|
-
return
|
|
100
|
+
return E();
|
|
102
101
|
},
|
|
103
|
-
onInput: (e) => (
|
|
104
|
-
onChange: (e) => (
|
|
102
|
+
onInput: (e) => (D(T(e instanceof Event ? e.target.value : e)), w?.(E())),
|
|
103
|
+
onChange: (e) => (D(T(e instanceof Event ? e.target.value : e)), w?.(E()), g && x()),
|
|
105
104
|
get options() {
|
|
106
|
-
return memo(() => !!
|
|
105
|
+
return memo(() => !!y.enum)() ? resolveOptions(y.enum ?? []) : void 0;
|
|
107
106
|
}
|
|
108
|
-
},
|
|
109
|
-
|
|
107
|
+
}, m, C)), setTimeout(() => {
|
|
108
|
+
g && O?.showPicker?.();
|
|
110
109
|
}, 0), {
|
|
111
|
-
el:
|
|
112
|
-
getValue:
|
|
113
|
-
focus: () =>
|
|
114
|
-
destroy:
|
|
110
|
+
el: O,
|
|
111
|
+
getValue: E,
|
|
112
|
+
focus: () => O.focus(),
|
|
113
|
+
destroy: S
|
|
115
114
|
};
|
|
116
115
|
}), Input = (e) => (() => {
|
|
117
|
-
var
|
|
118
|
-
return spread(
|
|
116
|
+
var p = _tmpl$4();
|
|
117
|
+
return spread(p, e, !1, !1), p;
|
|
119
118
|
})();
|
|
120
119
|
const editors = {
|
|
121
120
|
text: createEditor(Input),
|
|
@@ -125,39 +124,45 @@ const editors = {
|
|
|
125
124
|
} }, e, { get class() {
|
|
126
125
|
return `${e.class} bg-[--table-bg] outline-1.5px outline-solid outline-[--c-primary]`;
|
|
127
126
|
} }))),
|
|
128
|
-
number: createEditor(Input, {
|
|
129
|
-
|
|
127
|
+
number: createEditor(Input, {
|
|
128
|
+
type: "number",
|
|
129
|
+
out: (e) => Number(e)
|
|
130
|
+
}),
|
|
131
|
+
range: createEditor(Input, {
|
|
132
|
+
type: "range",
|
|
133
|
+
out: (e) => Number(e)
|
|
134
|
+
}),
|
|
130
135
|
date: createEditor(Input, { type: "date" }, !0),
|
|
131
136
|
time: createEditor(Input, { type: "time" }, !0),
|
|
132
137
|
datetime: createEditor(Input, { type: "datetime-local" }, !0),
|
|
133
138
|
color: createEditor(Input, { type: "color" }),
|
|
134
139
|
tel: createEditor(Input, { type: "tel" }),
|
|
135
140
|
password: createEditor(Input, { type: "password" }),
|
|
136
|
-
file: createEditor((
|
|
141
|
+
file: createEditor((p) => createComponent(Files, mergeProps$2(p, {
|
|
137
142
|
class: "relative z-9 outline-2 outline-blue min-h-a! h-a! p-1 bg-#fff",
|
|
138
|
-
onAdd: () => chooseFile({ multiple: !0 }).then((e) =>
|
|
143
|
+
onAdd: () => chooseFile({ multiple: !0 }).then((e) => p.onChange([...p.value || [], ...e.map((e) => ({
|
|
139
144
|
name: e.name,
|
|
140
145
|
size: e.size
|
|
141
146
|
}))]))
|
|
142
147
|
}))),
|
|
143
148
|
checkbox: createEditor((e) => (() => {
|
|
144
|
-
var
|
|
145
|
-
return typeof
|
|
149
|
+
var p = _tmpl$5(), m = e.ref;
|
|
150
|
+
return typeof m == "function" ? use(m, p) : e.ref = p, insert(p, createComponent(Checkbox, mergeProps$2(e, {
|
|
146
151
|
ref: () => {},
|
|
147
152
|
onInput: () => {},
|
|
148
153
|
class: "mx-3!"
|
|
149
|
-
}))),
|
|
154
|
+
}))), p;
|
|
150
155
|
})()),
|
|
151
156
|
select: createEditor((e) => (() => {
|
|
152
|
-
var
|
|
153
|
-
return spread(
|
|
154
|
-
var
|
|
155
|
-
return () =>
|
|
156
|
-
})(), null), insert(
|
|
157
|
-
var
|
|
158
|
-
return insert(
|
|
159
|
-
})()), null), effect(() =>
|
|
157
|
+
var p = _tmpl$6();
|
|
158
|
+
return spread(p, e, !1, !0), insert(p, (() => {
|
|
159
|
+
var p = memo(() => !e.multiple);
|
|
160
|
+
return () => p() && _tmpl$7();
|
|
161
|
+
})(), null), insert(p, () => e.options?.map((e) => (() => {
|
|
162
|
+
var p = _tmpl$8();
|
|
163
|
+
return insert(p, () => e.label), effect(() => p.value = e.value), p;
|
|
164
|
+
})()), null), effect(() => p.value = e.value), p;
|
|
160
165
|
})(), {}, !0)
|
|
161
166
|
};
|
|
162
|
-
delegateEvents(["keydown", "input"]);
|
|
167
|
+
editors.boolean = editors.checkbox, delegateEvents(["keydown", "input"]);
|
|
163
168
|
export { EditablePlugin, editors };
|
|
@@ -19,7 +19,10 @@ const ExpandPlugin = {
|
|
|
19
19
|
})),
|
|
20
20
|
[e.internal]: 1
|
|
21
21
|
} }),
|
|
22
|
-
commands: (e) => ({ expand: useSelector({
|
|
22
|
+
commands: (e) => ({ expand: useSelector({
|
|
23
|
+
multiple: !0,
|
|
24
|
+
key: e.props.rowKey
|
|
25
|
+
}) }),
|
|
23
26
|
rewriteProps: {
|
|
24
27
|
expand: ({ expand: e }) => mergeProps$1({ enable: !1 }, e),
|
|
25
28
|
columns: ({ columns: e }, { store: m }) => m.props.expand?.enable ? [m.expandCol, ...e] : e,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Ctx } from "../index.js";
|
|
2
1
|
import { createComponent, memo, mergeProps } from "solid-js/web";
|
|
3
|
-
import { For, Show, createEffect, createMemo, createSignal
|
|
2
|
+
import { For, Show, createEffect, createMemo, createSignal } from "solid-js";
|
|
4
3
|
function leafCount(e) {
|
|
5
4
|
return e.children?.length ? e.children.reduce((e, t) => e + leafCount(t), 0) : 1;
|
|
6
5
|
}
|
|
@@ -14,12 +13,12 @@ function flatLeaves(e, t = [], n) {
|
|
|
14
13
|
return t;
|
|
15
14
|
}
|
|
16
15
|
function buildFlatGrid(e, t, n, r, i, a) {
|
|
17
|
-
let o = n.length, s = Array.from({ length: t }, () => Array(o).fill(null)),
|
|
18
|
-
function
|
|
16
|
+
let o = n.length, s = Array.from({ length: t }, () => Array(o).fill(null)), l = 0;
|
|
17
|
+
function u(e, o) {
|
|
19
18
|
for (let d of e) {
|
|
20
|
-
let e = !!d.children?.length, f = leafCount(d), p = e ? 1 : t - o, m = e ? i[
|
|
19
|
+
let e = !!d.children?.length, f = leafCount(d), p = e ? 1 : t - o, m = e ? i[l] : d, h = r.get(m[a.ID]);
|
|
21
20
|
if (h == null) {
|
|
22
|
-
e ||
|
|
21
|
+
e || l++;
|
|
23
22
|
continue;
|
|
24
23
|
}
|
|
25
24
|
s[o][h] = {
|
|
@@ -40,10 +39,10 @@ function buildFlatGrid(e, t, n, r, i, a) {
|
|
|
40
39
|
colspan: 1,
|
|
41
40
|
rowspan: 1
|
|
42
41
|
};
|
|
43
|
-
e ?
|
|
42
|
+
e ? u(d.children, o + 1) : l++;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
l = 0, u(e, 0);
|
|
47
46
|
for (let e = 0; e < o; e++) {
|
|
48
47
|
if (s[0][e] != null) continue;
|
|
49
48
|
let r = n[e];
|
|
@@ -71,76 +70,76 @@ const HeaderGroupPlugin = {
|
|
|
71
70
|
if (!r.some((e) => e.children?.length) || maxDepth(r) <= 1) return [];
|
|
72
71
|
let i = e.props.columns || [], a = flatLeaves(r, [], e), o = /* @__PURE__ */ new Map();
|
|
73
72
|
for (let t = 0; t < i.length; t++) o.set(i[t][e.ID], t);
|
|
74
|
-
let s = [],
|
|
75
|
-
function
|
|
73
|
+
let s = [], d = 0;
|
|
74
|
+
function f(r) {
|
|
76
75
|
for (let i of r) if (i.children?.length) {
|
|
77
|
-
let r = leafCount(i),
|
|
78
|
-
if (
|
|
79
|
-
let i = o.get(
|
|
76
|
+
let r = leafCount(i), l = a[d];
|
|
77
|
+
if (l) {
|
|
78
|
+
let i = o.get(l[e.ID]);
|
|
80
79
|
if (i != null) {
|
|
81
80
|
let e = i + r - 1;
|
|
82
81
|
i <= n && e >= t && s.push(i);
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
|
|
86
|
-
} else
|
|
84
|
+
f(i.children);
|
|
85
|
+
} else d++;
|
|
87
86
|
}
|
|
88
|
-
return
|
|
87
|
+
return f(r), s;
|
|
89
88
|
} }),
|
|
90
89
|
rewriteProps: {
|
|
91
90
|
columns: ({ columns: e }, { store: t }) => flatLeaves(e, [], t),
|
|
92
|
-
Thead: ({ Thead:
|
|
93
|
-
let { props:
|
|
94
|
-
let e =
|
|
91
|
+
Thead: ({ Thead: c }, { store: f }) => (p) => {
|
|
92
|
+
let { props: m } = f, h = createMemo(() => {
|
|
93
|
+
let e = f.rawProps.columns || [], t = maxDepth(e);
|
|
95
94
|
if (t <= 1) return null;
|
|
96
|
-
let n =
|
|
97
|
-
for (let e = 0; e < n.length; e++) i.set(n[e][
|
|
95
|
+
let n = m.columns || [], r = flatLeaves(e, [], f), i = /* @__PURE__ */ new Map();
|
|
96
|
+
for (let e = 0; e < n.length; e++) i.set(n[e][f.ID], e);
|
|
98
97
|
return {
|
|
99
|
-
grid: buildFlatGrid(e, t, n, i, r,
|
|
98
|
+
grid: buildFlatGrid(e, t, n, i, r, f),
|
|
100
99
|
depth: t
|
|
101
100
|
};
|
|
102
|
-
}), [
|
|
101
|
+
}), [g, _] = createSignal(24);
|
|
103
102
|
createEffect(() => {
|
|
104
|
-
let e =
|
|
103
|
+
let e = f.thead;
|
|
105
104
|
if (!e) return;
|
|
106
105
|
let t = e.querySelectorAll(":scope > tr"), n = t[t.length - 1];
|
|
107
|
-
n &&
|
|
106
|
+
n && _(n.offsetHeight || 24);
|
|
108
107
|
});
|
|
109
|
-
let
|
|
108
|
+
let v = () => !!f.virtualizerX;
|
|
110
109
|
return createComponent(Show, {
|
|
111
110
|
get when() {
|
|
112
|
-
return
|
|
111
|
+
return h();
|
|
113
112
|
},
|
|
114
113
|
get fallback() {
|
|
115
|
-
return createComponent(
|
|
114
|
+
return createComponent(c, p);
|
|
116
115
|
},
|
|
117
|
-
children: (
|
|
116
|
+
children: (i) => createComponent(c, mergeProps(p, { get children() {
|
|
118
117
|
return createComponent(For, {
|
|
119
118
|
get each() {
|
|
120
|
-
return
|
|
119
|
+
return i().grid;
|
|
121
120
|
},
|
|
122
|
-
children: (
|
|
121
|
+
children: (n, r) => createComponent(m.Tr, {
|
|
123
122
|
get style() {
|
|
124
|
-
return memo(() => !!
|
|
123
|
+
return memo(() => !!v())() ? `height:${g()}px;overflow:visible;position:relative;z-index:${i().depth - r()}` : "";
|
|
125
124
|
},
|
|
126
125
|
get children() {
|
|
127
|
-
return createComponent(
|
|
126
|
+
return createComponent(m.EachCells, {
|
|
128
127
|
get each() {
|
|
129
|
-
return
|
|
128
|
+
return m.columns;
|
|
130
129
|
},
|
|
131
|
-
children: (
|
|
132
|
-
let a = () =>
|
|
130
|
+
children: (r, i) => {
|
|
131
|
+
let a = () => n[i()];
|
|
133
132
|
if (!a()) return null;
|
|
134
133
|
let o = () => {
|
|
135
134
|
let e = a();
|
|
136
|
-
return e.kind === "anchor" ?
|
|
135
|
+
return e.kind === "anchor" ? v() && e.rowspan > 1 && g() ? `height:${e.rowspan * g()}px;position:relative;` : "" : e.kind === "colspan-hidden" ? "display:none" : e.kind === "rowspan-hidden" ? v() ? "visibility:hidden" : "display:none" : "";
|
|
137
136
|
}, s = () => a().kind === "anchor";
|
|
138
|
-
return createComponent(
|
|
137
|
+
return createComponent(m.Th, {
|
|
139
138
|
get x() {
|
|
140
139
|
return i();
|
|
141
140
|
},
|
|
142
141
|
get col() {
|
|
143
|
-
return memo(() => !!s())() ? a().anchorCol :
|
|
142
|
+
return memo(() => !!s())() ? a().anchorCol : r();
|
|
144
143
|
},
|
|
145
144
|
get colspan() {
|
|
146
145
|
return memo(() => !!(s() && a().colspan > 1))() ? a().colspan : void 0;
|
|
@@ -12,7 +12,7 @@ declare module '../index' {
|
|
|
12
12
|
noMoreText?: string;
|
|
13
13
|
onLoadMore?: () => void | Promise<void>;
|
|
14
14
|
};
|
|
15
|
-
LoadMore?: Component<TableProps['loadMore']
|
|
15
|
+
LoadMore?: Component<Exclude<TableProps['loadMore'], undefined>>;
|
|
16
16
|
}
|
|
17
17
|
interface TableStore {
|
|
18
18
|
loadMore: {
|
|
@@ -7,18 +7,6 @@ var _tmpl$ = /* @__PURE__ */ template("<div class=\"data-table__load-more sticky
|
|
|
7
7
|
function isPromiseLike(e) {
|
|
8
8
|
return !!e && typeof e.then == "function";
|
|
9
9
|
}
|
|
10
|
-
var LoadMoreLayer = (s) => {
|
|
11
|
-
let c = () => !!s.enable && (s.loading || s.hasMore === !1), l = () => s.loading ? s.loadingText ?? "loading..." : s.noMoreText ?? "无更多数据";
|
|
12
|
-
return createComponent(Show, {
|
|
13
|
-
get when() {
|
|
14
|
-
return c();
|
|
15
|
-
},
|
|
16
|
-
get children() {
|
|
17
|
-
var e = _tmpl$();
|
|
18
|
-
return insert(e, l), e;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
10
|
const LoadMorePlugin = {
|
|
23
11
|
name: "loadMore",
|
|
24
12
|
store: () => ({ loadMore: {
|
|
@@ -26,36 +14,47 @@ const LoadMorePlugin = {
|
|
|
26
14
|
lastTriggerAt: 0
|
|
27
15
|
} }),
|
|
28
16
|
rewriteProps: {
|
|
29
|
-
loadMore: ({ loadMore: e }, { store:
|
|
17
|
+
loadMore: ({ loadMore: e }, { store: a }) => ({
|
|
30
18
|
enable: !1,
|
|
31
19
|
threshold: 100,
|
|
32
20
|
debounce: 200,
|
|
33
21
|
...e
|
|
34
22
|
}),
|
|
35
|
-
LoadMore: ({ LoadMore: o
|
|
36
|
-
|
|
37
|
-
return
|
|
23
|
+
LoadMore: ({ LoadMore: o }, { store: s }) => o ?? ((o) => {
|
|
24
|
+
let s = () => !!o.enable && (o.loading || o.hasMore === !1), c = () => o.loading ? o.loadingText ?? "loading..." : o.noMoreText ?? "无更多数据";
|
|
25
|
+
return createComponent(Show, {
|
|
26
|
+
get when() {
|
|
27
|
+
return s();
|
|
28
|
+
},
|
|
29
|
+
get children() {
|
|
30
|
+
var e = _tmpl$();
|
|
31
|
+
return insert(e, c), e;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}),
|
|
35
|
+
ScrollFooter: ({ ScrollFooter: a }, { store: c }) => (l) => createComponent(a, mergeProps(() => combineProps({ class: "contents" }, l), { get children() {
|
|
36
|
+
return [memo(() => l.children), createComponent(c.props.LoadMore, mergeProps(() => c.props.loadMore))];
|
|
38
37
|
} }))
|
|
39
38
|
},
|
|
40
39
|
onMount: (e) => {
|
|
41
|
-
let
|
|
42
|
-
let
|
|
43
|
-
if (!
|
|
44
|
-
let
|
|
45
|
-
if (!
|
|
46
|
-
let
|
|
47
|
-
if (
|
|
48
|
-
let
|
|
49
|
-
if (
|
|
50
|
-
e.loadMore.lastTriggerAt =
|
|
51
|
-
let
|
|
52
|
-
isPromiseLike(
|
|
53
|
-
e.loadMore.pending = !1, delay(0).then(
|
|
40
|
+
let a = () => {
|
|
41
|
+
let o = e.props.loadMore;
|
|
42
|
+
if (!o.enable || !o.onLoadMore || o.hasMore === !1 || o.loading || e.loadMore.pending) return;
|
|
43
|
+
let s = e.scroll_el;
|
|
44
|
+
if (!s) return;
|
|
45
|
+
let c = s.scrollHeight - s.scrollTop - s.clientHeight, l = o.threshold;
|
|
46
|
+
if (c > l) return;
|
|
47
|
+
let u = Date.now(), d = o.debounce;
|
|
48
|
+
if (u - e.loadMore.lastTriggerAt < d) return;
|
|
49
|
+
e.loadMore.lastTriggerAt = u;
|
|
50
|
+
let f = o.onLoadMore();
|
|
51
|
+
isPromiseLike(f) && (e.loadMore.pending = !0, f.finally(() => {
|
|
52
|
+
e.loadMore.pending = !1, delay(0).then(a);
|
|
54
53
|
}));
|
|
55
54
|
};
|
|
56
55
|
createEffect(() => {
|
|
57
|
-
let
|
|
58
|
-
!
|
|
56
|
+
let o = e.scroll_el, s = e.props.loadMore;
|
|
57
|
+
!o || !s.enable || (createEventListener(() => e.scroll_el, "scroll", a, { passive: !0 }), queueMicrotask(a));
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
60
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin } from '..';
|
|
2
|
+
declare module '..' {
|
|
3
|
+
interface TableProps {
|
|
4
|
+
pagination?: {
|
|
5
|
+
enable?: boolean;
|
|
6
|
+
pageSize?: number;
|
|
7
|
+
defaultValue?: number;
|
|
8
|
+
value?: number;
|
|
9
|
+
onChange?: (page: number) => void;
|
|
10
|
+
/** Server-side pagination: called on page change with (page, pageSize).
|
|
11
|
+
* Parent should update `data` and `total` in response. */
|
|
12
|
+
request?: (page: number, pageSize: number) => void | Promise<void>;
|
|
13
|
+
/** Total record count (required for server-side pagination) */
|
|
14
|
+
total?: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface TableStore {
|
|
18
|
+
_pgnTotal: number;
|
|
19
|
+
_pgnLoading: boolean;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export declare const PaginationPlugin: Plugin;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useControlled } from "../hooks/useControlled.js";
|
|
2
|
+
import { Ctx } from "../index.js";
|
|
3
|
+
import { className, createComponent, delegateEvents, effect, insert, memo, mergeProps, template } from "solid-js/web";
|
|
4
|
+
import { For, Show, createMemo, mergeProps as mergeProps$1, runWithOwner, untrack, useContext } from "solid-js";
|
|
5
|
+
var _tmpl$ = /* @__PURE__ */ template("<div class=\"data-table__pagination flex items-center justify-end gap-1 py-2 text-sm\"><span class=mr-2>共 <!> 条</span><button class=\"data-table__pagination-btn disabled:op-30\">‹</button><button class=\"data-table__pagination-btn disabled:op-30\">›"), _tmpl$2 = /* @__PURE__ */ template("<span class=\"px-1 select-none\">…"), _tmpl$3 = /* @__PURE__ */ template("<button>");
|
|
6
|
+
const PaginationPlugin = {
|
|
7
|
+
name: "pagination",
|
|
8
|
+
store: (e) => ({
|
|
9
|
+
_pgnTotal: 0,
|
|
10
|
+
_pgnLoading: !1
|
|
11
|
+
}),
|
|
12
|
+
rewriteProps: {
|
|
13
|
+
loading: ({ loading: e }, { store: l }) => l._pgnLoading || e,
|
|
14
|
+
pagination: ({ pagination: l }, { store: u }) => {
|
|
15
|
+
l = mergeProps$1({
|
|
16
|
+
enable: !1,
|
|
17
|
+
pageSize: 20,
|
|
18
|
+
defaultValue: 1
|
|
19
|
+
}, l);
|
|
20
|
+
let d = untrack(() => u._pgn ??= runWithOwner(u.owner, () => useControlled(l)));
|
|
21
|
+
return u._pgn.$setOpt(l), d;
|
|
22
|
+
},
|
|
23
|
+
data: ({ data: e }, { store: l }) => {
|
|
24
|
+
if (!e) return e;
|
|
25
|
+
let u = l.props.pagination;
|
|
26
|
+
return u?.enable ? typeof u.request == "function" ? (l._pgnTotal = u.total ?? e.length, e) : (l._pgnTotal = e.length, e) : e;
|
|
27
|
+
},
|
|
28
|
+
EachRows: ({ EachRows: e }, { store: l }) => l.props.pagination?.enable ? (u) => {
|
|
29
|
+
let f = mergeProps$1(() => l.props.pagination);
|
|
30
|
+
if (!f?.enable || typeof f.request == "function") return createComponent(e, u);
|
|
31
|
+
let p = () => (f.value - 1) * f.pageSize, m = () => u.each.slice(p(), p() + f.pageSize);
|
|
32
|
+
return createComponent(e, {
|
|
33
|
+
get each() {
|
|
34
|
+
return m();
|
|
35
|
+
},
|
|
36
|
+
children: (e, l) => u.children(e, () => p() + l())
|
|
37
|
+
});
|
|
38
|
+
} : e,
|
|
39
|
+
Footer: ({ Footer: e }, { store: l }) => (u) => createComponent(e, mergeProps(u, { get children() {
|
|
40
|
+
return [memo(() => u.children), createComponent(Show, {
|
|
41
|
+
get when() {
|
|
42
|
+
return l.props.pagination?.enable;
|
|
43
|
+
},
|
|
44
|
+
get children() {
|
|
45
|
+
return createComponent(PaginationFooter, {});
|
|
46
|
+
}
|
|
47
|
+
})];
|
|
48
|
+
} }))
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function PaginationFooter() {
|
|
52
|
+
let { store: e } = useContext(Ctx), f = mergeProps$1(() => e.props.pagination), h = () => f.value, g = () => f.pageSize, _ = () => Math.ceil(e._pgnTotal / g()), v = createMemo(() => pageNumbers(h(), _())), x = (l) => {
|
|
53
|
+
if (l < 1 || l > _()) return;
|
|
54
|
+
let u = e.props.pagination?.request;
|
|
55
|
+
if (u) {
|
|
56
|
+
if (e._pgnLoading) return;
|
|
57
|
+
e._pgnLoading = !0;
|
|
58
|
+
let d = u(l, g());
|
|
59
|
+
d && typeof d.then == "function" ? d.finally(() => {
|
|
60
|
+
e._pgnLoading = !1;
|
|
61
|
+
}) : e._pgnLoading = !1;
|
|
62
|
+
}
|
|
63
|
+
e.props.pagination?.onChange?.(l);
|
|
64
|
+
};
|
|
65
|
+
return (() => {
|
|
66
|
+
var l = _tmpl$(), f = l.firstChild, g = f.firstChild, y = g.nextSibling;
|
|
67
|
+
y.nextSibling;
|
|
68
|
+
var b = f.nextSibling, S = b.nextSibling;
|
|
69
|
+
return insert(f, () => e._pgnTotal, y), b.$$click = () => x(h() - 1), insert(l, createComponent(For, {
|
|
70
|
+
get each() {
|
|
71
|
+
return v();
|
|
72
|
+
},
|
|
73
|
+
children: (l) => {
|
|
74
|
+
let d = () => l === h();
|
|
75
|
+
return l === "..." ? _tmpl$2() : (() => {
|
|
76
|
+
var f = _tmpl$3();
|
|
77
|
+
return f.$$click = () => x(l), insert(f, l), effect((l) => {
|
|
78
|
+
var p = `data-table__pagination-btn ${d() ? "is-active" : ""}`, m = e.props.loading;
|
|
79
|
+
return p !== l.e && className(f, l.e = p), m !== l.t && (f.disabled = l.t = m), l;
|
|
80
|
+
}, {
|
|
81
|
+
e: void 0,
|
|
82
|
+
t: void 0
|
|
83
|
+
}), f;
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
}), S), S.$$click = () => x(h() + 1), effect((l) => {
|
|
87
|
+
var u = h() <= 1 || e.props.loading, d = h() >= _() || e.props.loading;
|
|
88
|
+
return u !== l.e && (b.disabled = l.e = u), d !== l.t && (S.disabled = l.t = d), l;
|
|
89
|
+
}, {
|
|
90
|
+
e: void 0,
|
|
91
|
+
t: void 0
|
|
92
|
+
}), l;
|
|
93
|
+
})();
|
|
94
|
+
}
|
|
95
|
+
function pageNumbers(e, l) {
|
|
96
|
+
if (l <= 1) return [];
|
|
97
|
+
if (l <= 7) return Array.from({ length: l }, (e, l) => l + 1);
|
|
98
|
+
let u = [1];
|
|
99
|
+
e > 4 && u.push("...");
|
|
100
|
+
let d = Math.max(2, e - 1), f = Math.min(l - 1, e + 1);
|
|
101
|
+
for (let e = d; e <= f; e++) u.push(e);
|
|
102
|
+
return e < l - 3 && u.push("..."), u.push(l), u;
|
|
103
|
+
}
|
|
104
|
+
delegateEvents(["click"]);
|
|
105
|
+
export { PaginationPlugin };
|
|
@@ -2,5 +2,9 @@ export declare const Checkbox: import("solid-js").Component<Record<string, any>>
|
|
|
2
2
|
export declare const Files: import("solid-js").Component<Record<string, any>>;
|
|
3
3
|
export declare const Tags: import("solid-js").Component<Record<string, any>>;
|
|
4
4
|
export declare const Tag: import("solid-js").Component<Record<string, any>>;
|
|
5
|
+
/** Star rating component. max defaults to 5. */
|
|
6
|
+
export declare const Rate: import("solid-js").Component<Record<string, any>>;
|
|
7
|
+
/** Progress bar component. value is 0–100 or 0–1. */
|
|
8
|
+
export declare const Progress: import("solid-js").Component<Record<string, any>>;
|
|
5
9
|
export declare const evaluateFormula: (formula: string, data: any) => any;
|
|
6
10
|
export declare const text2colorMap: Record<string, string>;
|