intable 0.0.58 → 0.0.59
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 +3 -1
- package/dist/index.js +30 -15
- package/dist/plugins/DiffPlugin.js +4 -1
- package/dist/plugins/EditablePlugin.js +75 -76
- 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/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: h }) => (_) => {
|
|
16
|
+
let v = [_.col.editable, e].filter((e) => e != null);
|
|
17
|
+
return !!v.length && v.every((e) => unFn(e, _)) && !_.data[h.internal] && !_.col[h.internal];
|
|
19
18
|
},
|
|
20
|
-
Td: ({ Td: e }, { store:
|
|
21
|
-
let
|
|
22
|
-
return createMemo(() =>
|
|
23
|
-
let
|
|
19
|
+
Td: ({ Td: e }, { store: h }) => (v) => {
|
|
20
|
+
let y, b = () => unFn(h.props.editable, v);
|
|
21
|
+
return createMemo(() => b() ? unFn(() => {
|
|
22
|
+
let g = "", [C, w] = createSignal(!1), E = () => (([e, h]) => v.x == e && v.y == h)(h.selected.start || []), D = () => b() && !C() && E(), [A, j] = createSignal(!1), M = createAsyncMemo(() => {
|
|
24
23
|
if (C()) {
|
|
25
|
-
let e = createMemo(() => JSON.stringify(
|
|
26
|
-
createEffect(on(e, () =>
|
|
27
|
-
let
|
|
28
|
-
props:
|
|
29
|
-
col:
|
|
30
|
-
eventKey:
|
|
31
|
-
data:
|
|
32
|
-
value:
|
|
24
|
+
let e = createMemo(() => JSON.stringify(h.selected ?? "{}"));
|
|
25
|
+
createEffect(on(e, () => w(!1), { defer: !0 })), F.w = y.getBoundingClientRect().width, F.h = y.getBoundingClientRect().height;
|
|
26
|
+
let _ = !1, b = v.data[v.col.id], x = ((e) => typeof e == "string" ? h.editors[e] : e)(v.col.editor ?? v.col.type ?? (v.col.enum ? "select" : "text")), S = {
|
|
27
|
+
props: v.col.editorProps,
|
|
28
|
+
col: v.col,
|
|
29
|
+
eventKey: g,
|
|
30
|
+
data: v.data,
|
|
31
|
+
value: b,
|
|
33
32
|
ok: async () => {
|
|
34
|
-
await
|
|
33
|
+
await N(T.getValue()), w(!1);
|
|
35
34
|
},
|
|
36
|
-
cancel: () => (
|
|
37
|
-
onChange: (e) => C() &&
|
|
38
|
-
},
|
|
39
|
-
return queueMicrotask(() =>
|
|
40
|
-
!
|
|
41
|
-
...
|
|
42
|
-
[
|
|
43
|
-
}),
|
|
44
|
-
}), [
|
|
35
|
+
cancel: () => (_ = !0, w(!1)),
|
|
36
|
+
onChange: (e) => C() && N(e).catch(() => {})
|
|
37
|
+
}, T = x(S);
|
|
38
|
+
return queueMicrotask(() => T.focus?.()), onCleanup(() => {
|
|
39
|
+
!_ && T.getValue() !== b && h.commands.rowChange({
|
|
40
|
+
...props.data[v.y],
|
|
41
|
+
[v.col.id]: T.getValue()
|
|
42
|
+
}), _ || N(T.getValue()).catch(() => {}), g = "", T.destroy();
|
|
43
|
+
}), [S, T];
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
|
-
async function
|
|
46
|
+
async function N(e) {
|
|
48
47
|
try {
|
|
49
|
-
|
|
48
|
+
j(!0), await h.validateCell(e, v.data, v.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(v, {
|
|
57
|
+
ref: (e) => (y = e, v.ref?.(e)),
|
|
59
58
|
get class() {
|
|
60
|
-
return [C() ? "is-editing" : "",
|
|
59
|
+
return [C() ? "is-editing" : "", v.class].filter(Boolean).join(" ");
|
|
61
60
|
},
|
|
62
61
|
get style() {
|
|
63
|
-
return [C() ? `width: ${
|
|
62
|
+
return [C() ? `width: ${F.w}px; height: ${F.h}px; padding: 0; ` : "", v.style].filter(Boolean).join(" ");
|
|
64
63
|
},
|
|
65
|
-
onClick: (e) => (
|
|
66
|
-
onDblClick: (e) => (
|
|
67
|
-
onKeyDown: (e) => (e.key == "Escape" &&
|
|
64
|
+
onClick: (e) => (P?.focus?.(), v.onClick?.(e)),
|
|
65
|
+
onDblClick: (e) => (w(b()), v.onDblClick?.(e)),
|
|
66
|
+
onKeyDown: (e) => (e.key == "Escape" && M()?.[0].cancel(), v.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
|
+
})() : v.children, () => D() && (() => {
|
|
79
78
|
var e = _tmpl$3();
|
|
80
79
|
return e.addEventListener("compositionend", () => {
|
|
81
|
-
|
|
80
|
+
w(!0);
|
|
82
81
|
}), e.$$input = (e) => {
|
|
83
|
-
|
|
82
|
+
g = 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, v));
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
};
|
|
95
|
-
var createEditor = (e,
|
|
96
|
-
let [
|
|
94
|
+
var createEditor = (e, g, v) => ({ eventKey: y, value: b, col: x, ok: C, cancel: w, props: T, onChange: E }) => createRoot((w) => {
|
|
95
|
+
let [D, O] = createSignal(y || b), k;
|
|
97
96
|
return createComponent(e, mergeProps$2({
|
|
98
|
-
ref: (e) =>
|
|
97
|
+
ref: (e) => k = 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 D();
|
|
102
101
|
},
|
|
103
|
-
onInput: (e) => (
|
|
104
|
-
onChange: (e) => (
|
|
102
|
+
onInput: (e) => (O(e instanceof Event ? e.target.value : e), E?.(D())),
|
|
103
|
+
onChange: (e) => (O(e instanceof Event ? e.target.value : e), E?.(D()), v && C()),
|
|
105
104
|
get options() {
|
|
106
|
-
return memo(() => !!
|
|
105
|
+
return memo(() => !!x.enum)() ? resolveOptions(x.enum ?? []) : void 0;
|
|
107
106
|
}
|
|
108
|
-
},
|
|
109
|
-
|
|
107
|
+
}, g, T)), setTimeout(() => {
|
|
108
|
+
v && k?.showPicker?.();
|
|
110
109
|
}, 0), {
|
|
111
|
-
el:
|
|
112
|
-
getValue:
|
|
113
|
-
focus: () =>
|
|
114
|
-
destroy:
|
|
110
|
+
el: k,
|
|
111
|
+
getValue: D,
|
|
112
|
+
focus: () => k.focus(),
|
|
113
|
+
destroy: w
|
|
115
114
|
};
|
|
116
115
|
}), Input = (e) => (() => {
|
|
117
|
-
var
|
|
118
|
-
return spread(
|
|
116
|
+
var h = _tmpl$4();
|
|
117
|
+
return spread(h, e, !1, !1), h;
|
|
119
118
|
})();
|
|
120
119
|
const editors = {
|
|
121
120
|
text: createEditor(Input),
|
|
@@ -133,30 +132,30 @@ const editors = {
|
|
|
133
132
|
color: createEditor(Input, { type: "color" }),
|
|
134
133
|
tel: createEditor(Input, { type: "tel" }),
|
|
135
134
|
password: createEditor(Input, { type: "password" }),
|
|
136
|
-
file: createEditor((
|
|
135
|
+
file: createEditor((h) => createComponent(Files, mergeProps$2(h, {
|
|
137
136
|
class: "relative z-9 outline-2 outline-blue min-h-a! h-a! p-1 bg-#fff",
|
|
138
|
-
onAdd: () => chooseFile({ multiple: !0 }).then((e) =>
|
|
137
|
+
onAdd: () => chooseFile({ multiple: !0 }).then((e) => h.onChange([...h.value || [], ...e.map((e) => ({
|
|
139
138
|
name: e.name,
|
|
140
139
|
size: e.size
|
|
141
140
|
}))]))
|
|
142
141
|
}))),
|
|
143
142
|
checkbox: createEditor((e) => (() => {
|
|
144
|
-
var
|
|
145
|
-
return typeof
|
|
143
|
+
var h = _tmpl$5(), g = e.ref;
|
|
144
|
+
return typeof g == "function" ? use(g, h) : e.ref = h, insert(h, createComponent(Checkbox, mergeProps$2(e, {
|
|
146
145
|
ref: () => {},
|
|
147
146
|
onInput: () => {},
|
|
148
147
|
class: "mx-3!"
|
|
149
|
-
}))),
|
|
148
|
+
}))), h;
|
|
150
149
|
})()),
|
|
151
150
|
select: createEditor((e) => (() => {
|
|
152
|
-
var
|
|
153
|
-
return spread(
|
|
154
|
-
var
|
|
155
|
-
return () =>
|
|
156
|
-
})(), null), insert(
|
|
157
|
-
var
|
|
158
|
-
return insert(
|
|
159
|
-
})()), null), effect(() =>
|
|
151
|
+
var h = _tmpl$6();
|
|
152
|
+
return spread(h, e, !1, !0), insert(h, (() => {
|
|
153
|
+
var h = memo(() => !e.multiple);
|
|
154
|
+
return () => h() && _tmpl$7();
|
|
155
|
+
})(), null), insert(h, () => e.options?.map((e) => (() => {
|
|
156
|
+
var h = _tmpl$8();
|
|
157
|
+
return insert(h, () => e.label), effect(() => h.value = e.value), h;
|
|
158
|
+
})()), null), effect(() => h.value = e.value), h;
|
|
160
159
|
})(), {}, !0)
|
|
161
160
|
};
|
|
162
161
|
delegateEvents(["keydown", "input"]);
|
|
@@ -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 };
|