intable 0.0.57 → 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/dist/__uno.css +1 -1
- package/dist/components/AndOrFields.js +164 -123
- 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 +5 -2
- 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 +5 -2
- 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/package.json +1 -1
|
@@ -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 };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { mergeProps as mergeProps$2 } from "../mergeProps2.js";
|
|
2
2
|
import chevron_right_default from "../chevron-right.js";
|
|
3
|
-
import { Ctx } from "../index.js";
|
|
4
3
|
import { createComponent, delegateEvents, effect, insert, memo, style, template } from "solid-js/web";
|
|
5
|
-
import { batch, createMemo
|
|
4
|
+
import { batch, createMemo } from "solid-js";
|
|
6
5
|
import { groupBy, zipObject } from "es-toolkit";
|
|
7
6
|
import { findLast } from "es-toolkit/compat";
|
|
8
7
|
var _tmpl$ = /* @__PURE__ */ template("<div class=\"flex items-center\">"), pathKey = (e) => e.join("\0");
|
|
@@ -11,79 +10,79 @@ const RowGroupPlugin = {
|
|
|
11
10
|
priority: -Infinity,
|
|
12
11
|
store: (e) => ({ rowGroup: {
|
|
13
12
|
expandKeys: {},
|
|
14
|
-
isExpand: (
|
|
15
|
-
expand: (
|
|
16
|
-
e.rowGroup.expandKeys[pathKey(
|
|
17
|
-
}) : e.rowGroup.expandKeys[pathKey(
|
|
18
|
-
toggleExpand: (
|
|
19
|
-
let
|
|
20
|
-
e.rowGroup.expandKeys[
|
|
13
|
+
isExpand: (c) => !!e.rowGroup.expandKeys[pathKey(c[GROUP].path)],
|
|
14
|
+
expand: (c, l) => batch(() => l ? c[GROUP].path2.forEach((c) => {
|
|
15
|
+
e.rowGroup.expandKeys[pathKey(c[GROUP].path)] = !0;
|
|
16
|
+
}) : e.rowGroup.expandKeys[pathKey(c[GROUP].path)] = !0),
|
|
17
|
+
toggleExpand: (c) => {
|
|
18
|
+
let l = pathKey(c[GROUP].path);
|
|
19
|
+
e.rowGroup.expandKeys[l] ? delete e.rowGroup.expandKeys[l] : e.rowGroup.expandKeys[l] = !0;
|
|
21
20
|
}
|
|
22
21
|
} }),
|
|
23
|
-
commands: (e, { addRows:
|
|
24
|
-
let { data:
|
|
25
|
-
if (
|
|
26
|
-
let
|
|
27
|
-
if (
|
|
28
|
-
let
|
|
29
|
-
return
|
|
30
|
-
}(
|
|
31
|
-
e.rowGroup.expand(
|
|
32
|
-
let
|
|
33
|
-
|
|
22
|
+
commands: (e, { addRows: c }) => ({ addRows(l, u, d) {
|
|
23
|
+
let { data: f, rowGroup: p, rowKey: m } = e.props;
|
|
24
|
+
if (p?.fields?.length) {
|
|
25
|
+
let p = findLast(f, (e) => e[GROUP], l);
|
|
26
|
+
if (p && f[l][GROUP]) {
|
|
27
|
+
let c = function e(c) {
|
|
28
|
+
return c[GROUP]?.children[0]?.[GROUP] ? e(c[GROUP].children[0]) : c;
|
|
29
|
+
}(p);
|
|
30
|
+
e.rowGroup.expand(c, !0);
|
|
31
|
+
let u = c[GROUP].children[0];
|
|
32
|
+
l = e.props.data.indexOf(u), d = !0;
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
} else
|
|
34
|
+
c?.(l, u, d);
|
|
35
|
+
} else c?.(...arguments);
|
|
37
36
|
} }),
|
|
38
37
|
rewriteProps: {
|
|
39
|
-
data: ({ data: e }, { store:
|
|
40
|
-
newRow: ({ newRow: e }, { store:
|
|
41
|
-
let
|
|
42
|
-
if (
|
|
43
|
-
let e = findLast(
|
|
38
|
+
data: ({ data: e }, { store: c }) => c.props?.rowGroup?.fields?.length ? expandData(e, c) : e,
|
|
39
|
+
newRow: ({ newRow: e }, { store: c }) => function(l) {
|
|
40
|
+
let u = e(...arguments), { data: d, rowGroup: f } = c.props;
|
|
41
|
+
if (f?.fields?.length) {
|
|
42
|
+
let e = findLast(d, (e) => e[GROUP], l);
|
|
44
43
|
if (e) {
|
|
45
|
-
let
|
|
46
|
-
return
|
|
47
|
-
}(e),
|
|
48
|
-
Object.assign(
|
|
44
|
+
let c = function e(c) {
|
|
45
|
+
return c[GROUP]?.children[0]?.[GROUP] ? e(c[GROUP].children[0]) : c;
|
|
46
|
+
}(e), l = zipObject(f.fields, c[GROUP].path);
|
|
47
|
+
Object.assign(u, l);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
return
|
|
50
|
+
return u;
|
|
52
51
|
},
|
|
53
|
-
Td: ({ Td:
|
|
54
|
-
if (!
|
|
55
|
-
let { props:
|
|
56
|
-
return createComponent(
|
|
57
|
-
return memo(() =>
|
|
52
|
+
Td: ({ Td: u }, { store: h }) => h.props?.rowGroup?.fields ? (g) => {
|
|
53
|
+
if (!g.data?.[GROUP]) return u(g);
|
|
54
|
+
let { props: _ } = h, v = createMemo(() => h.rowGroup.isExpand(g.data));
|
|
55
|
+
return createComponent(u, mergeProps$2(g, { get children() {
|
|
56
|
+
return memo(() => _.columns?.findIndex((e) => !e[h.internal]) == g.x)() ? (() => {
|
|
58
57
|
var e = _tmpl$();
|
|
59
|
-
return e.$$dblclick = () =>
|
|
58
|
+
return e.$$dblclick = () => h.rowGroup.toggleExpand(g.data), insert(e, createComponent(chevron_right_default, {
|
|
60
59
|
class: "icon-clickable mr-2",
|
|
61
60
|
get style() {
|
|
62
|
-
return `transform: rotate(${
|
|
61
|
+
return `transform: rotate(${v() ? 90 : 0}deg); opacity: .6`;
|
|
63
62
|
},
|
|
64
|
-
onClick: () =>
|
|
65
|
-
}), null), insert(e, () =>
|
|
66
|
-
})() :
|
|
63
|
+
onClick: () => h.rowGroup.toggleExpand(g.data)
|
|
64
|
+
}), null), insert(e, () => g.data[GROUP].value, null), effect((c) => style(e, `padding-left: ${(g.data[GROUP].path.length - 1) * 16}px`, c)), e;
|
|
65
|
+
})() : g.children;
|
|
67
66
|
} }));
|
|
68
|
-
} :
|
|
67
|
+
} : u
|
|
69
68
|
}
|
|
70
69
|
};
|
|
71
|
-
var GROUP = Symbol("row-group"), expandData = (e,
|
|
72
|
-
let
|
|
73
|
-
if (!
|
|
74
|
-
let
|
|
75
|
-
return Object.keys(
|
|
76
|
-
let
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
path: [...
|
|
70
|
+
var GROUP = Symbol("row-group"), expandData = (e, c, l = []) => {
|
|
71
|
+
let u = c.props.rowGroup.fields, d = c.props.columns.find((e) => !e[c.internal]);
|
|
72
|
+
if (!d || u.length == l.length) return e;
|
|
73
|
+
let f = l[l.length - 1]?.[GROUP].path || [], p = groupBy(e, (e) => e[u[f.length]]);
|
|
74
|
+
return Object.keys(p).flatMap((e) => {
|
|
75
|
+
let u = {
|
|
76
|
+
[d.id]: e,
|
|
77
|
+
[c.internal]: 1
|
|
78
|
+
}, m = [...l, u];
|
|
79
|
+
u[GROUP] = {
|
|
80
|
+
path: [...f, e],
|
|
82
81
|
value: e,
|
|
83
|
-
path2:
|
|
84
|
-
},
|
|
85
|
-
let
|
|
86
|
-
return [
|
|
82
|
+
path2: m
|
|
83
|
+
}, u[GROUP].children = expandData(p[e], c, m);
|
|
84
|
+
let h = c.rowGroup.isExpand(u) ? u[GROUP].children : [];
|
|
85
|
+
return [u, ...h];
|
|
87
86
|
});
|
|
88
87
|
};
|
|
89
88
|
delegateEvents(["dblclick"]);
|
|
@@ -3,7 +3,7 @@ import { Checkbox } from "./RenderPlugin/components.js";
|
|
|
3
3
|
import { useSelector } from "../hooks/useSelector.js";
|
|
4
4
|
import { createComponent, insert, template } from "solid-js/web";
|
|
5
5
|
import { mergeProps as mergeProps$1 } from "solid-js";
|
|
6
|
-
var _tmpl$ = /* @__PURE__ */ template("<label class=\"flex items-center justify-center w-full h-full\">"), _tmpl$2 = /* @__PURE__ */ template("<label>");
|
|
6
|
+
var _tmpl$ = /* @__PURE__ */ template("<label class=\"flex items-center justify-center w-full h-full absolute inset-0\">"), _tmpl$2 = /* @__PURE__ */ template("<label>");
|
|
7
7
|
const RowSelectionPlugin = {
|
|
8
8
|
name: "row-selection",
|
|
9
9
|
priority: -Infinity,
|
|
@@ -40,7 +40,10 @@ const RowSelectionPlugin = {
|
|
|
40
40
|
})), l;
|
|
41
41
|
})())
|
|
42
42
|
} }),
|
|
43
|
-
commands: (e) => ({ rowSelector: useSelector(mergeProps$1(() => ({
|
|
43
|
+
commands: (e) => ({ rowSelector: useSelector(mergeProps$1(() => ({
|
|
44
|
+
...e.props?.rowSelection,
|
|
45
|
+
key: e.props.rowKey
|
|
46
|
+
}))) }),
|
|
44
47
|
rewriteProps: {
|
|
45
48
|
rowSelection: ({ rowSelection: e }) => mergeProps$1({
|
|
46
49
|
enable: !1,
|
|
@@ -8,7 +8,6 @@ declare module '../index' {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
interface TableStore {
|
|
11
|
-
tree: ReturnType<typeof useSelector<any[]>>;
|
|
12
11
|
/**
|
|
13
12
|
* Lookup map populated as a side-effect of the `data` rewriteProp.
|
|
14
13
|
* Maps each row's rowKey → its tree metadata.
|
|
@@ -18,7 +17,11 @@ declare module '../index' {
|
|
|
18
17
|
depth: number;
|
|
19
18
|
hasChildren: boolean;
|
|
20
19
|
parentKey: any;
|
|
20
|
+
row: any;
|
|
21
21
|
}>;
|
|
22
22
|
}
|
|
23
|
+
interface Commands {
|
|
24
|
+
tree: ReturnType<typeof useSelector<any[]>>;
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
export declare const TreePlugin: Plugin$0;
|