intable 0.0.26 → 0.0.28
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 +378 -378
- package/dist/__uno.css +1 -1
- package/dist/components/AndOrFields.d.ts +1 -1
- package/dist/components/AndOrFields.js +193 -74
- package/dist/components/Filter.d.ts +0 -1
- package/dist/hooks/useVirtualizer.d.ts +3 -0
- package/dist/hooks/useVirtualizer.js +12 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +17 -11
- package/dist/loading-bold.js +6 -0
- package/dist/plugins/CellMergePlugin.js +15 -16
- package/dist/plugins/CellSelectionPlugin.js +97 -69
- package/dist/plugins/CommandPlugin.js +3 -1
- package/dist/plugins/CopyPastePlugin.js +1 -1
- package/dist/plugins/DiffPlugin.d.ts +0 -1
- package/dist/plugins/DiffPlugin.js +2 -2
- package/dist/plugins/EditablePlugin.js +74 -74
- package/dist/plugins/ExpandPlugin.js +0 -1
- package/dist/plugins/FilterPlugin.js +95 -53
- package/dist/plugins/ImportExportPlugin.d.ts +9 -0
- package/dist/plugins/ImportExportPlugin.js +37 -0
- package/dist/plugins/LoadMorePlugin.js +1 -1
- package/dist/plugins/MenuPlugin.d.ts +1 -0
- package/dist/plugins/MenuPlugin.js +7 -0
- package/dist/plugins/RenderPlugin/index.d.ts +3 -3
- package/dist/plugins/RenderPlugin/index.js +12 -12
- package/dist/plugins/ResizePlugin.js +45 -36
- package/dist/plugins/RowGroupPlugin.js +1 -1
- package/dist/plugins/TreePlugin.js +25 -23
- package/dist/plugins/ValidatorPlugin.js +14 -12
- package/dist/plugins/VirtualScrollPlugin.js +16 -2
- package/dist/style.css +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 +3 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toArr } from "../utils.js";
|
|
1
2
|
import { normalizeType } from "../components/AndOrFields.js";
|
|
2
3
|
import { Filter } from "../components/Filter.js";
|
|
3
4
|
import { createComponent, memo, mergeProps } from "solid-js/web";
|
|
@@ -6,32 +7,41 @@ function isBlank(e) {
|
|
|
6
7
|
return e == null || String(e).trim() === "";
|
|
7
8
|
}
|
|
8
9
|
function toNum(e) {
|
|
9
|
-
let
|
|
10
|
-
return Number.isNaN(
|
|
10
|
+
let a = Number(e);
|
|
11
|
+
return Number.isNaN(a) ? null : a;
|
|
11
12
|
}
|
|
12
13
|
function toDateTs(e) {
|
|
13
14
|
if (isBlank(e)) return null;
|
|
14
|
-
let
|
|
15
|
-
return Number.isNaN(
|
|
15
|
+
let a = new Date(String(e)).getTime();
|
|
16
|
+
return Number.isNaN(a) ? null : a;
|
|
16
17
|
}
|
|
17
18
|
function toBool(e) {
|
|
18
19
|
if (typeof e == "boolean") return e;
|
|
19
20
|
if (typeof e == "number") return e !== 0;
|
|
20
|
-
let
|
|
21
|
+
let a = String(e ?? "").trim().toLowerCase();
|
|
21
22
|
return [
|
|
22
23
|
"1",
|
|
23
24
|
"true",
|
|
24
25
|
"yes",
|
|
25
26
|
"y",
|
|
26
27
|
"on"
|
|
27
|
-
].includes(
|
|
28
|
+
].includes(a) ? !0 : [
|
|
28
29
|
"0",
|
|
29
30
|
"false",
|
|
30
31
|
"no",
|
|
31
32
|
"n",
|
|
32
33
|
"off",
|
|
33
34
|
""
|
|
34
|
-
].includes(
|
|
35
|
+
].includes(a) ? !1 : !!e;
|
|
36
|
+
}
|
|
37
|
+
function toList(e) {
|
|
38
|
+
return Array.isArray(e) ? e : e == null || String(e).trim() === "" ? [] : String(e).split(",").map((e) => e.trim()).filter(Boolean);
|
|
39
|
+
}
|
|
40
|
+
function toPair(e) {
|
|
41
|
+
if (Array.isArray(e)) return [e[0], e[1]];
|
|
42
|
+
if (e == null || String(e).trim() === "") return [void 0, void 0];
|
|
43
|
+
let a = String(e).split(",").map((e) => e.trim());
|
|
44
|
+
return [a[0], a[1]];
|
|
35
45
|
}
|
|
36
46
|
function isRuleNode(e) {
|
|
37
47
|
return "field" in e;
|
|
@@ -42,76 +52,108 @@ function hasActiveRule(e) {
|
|
|
42
52
|
function hasActiveTree(e) {
|
|
43
53
|
return e ? isRuleNode(e) ? hasActiveRule(e) : (e.children ?? []).some(hasActiveTree) : !1;
|
|
44
54
|
}
|
|
45
|
-
function matchFilter(e,
|
|
46
|
-
let
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
51
|
-
let
|
|
52
|
-
if (
|
|
53
|
-
let
|
|
54
|
-
if (
|
|
55
|
-
if (
|
|
56
|
-
if (
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
55
|
+
function matchFilter(e, a, o) {
|
|
56
|
+
let s = a.op;
|
|
57
|
+
if (s === "blank") return isBlank(e);
|
|
58
|
+
if (s === "noblank") return !isBlank(e);
|
|
59
|
+
if (s === "true") return toBool(e);
|
|
60
|
+
if (s === "false") return !toBool(e);
|
|
61
|
+
let c = a.value;
|
|
62
|
+
if (o === "number") {
|
|
63
|
+
let a = toNum(e), o = toNum(c), l = toList(c).map(toNum).filter((e) => e != null), [u, d] = toPair(c), p = toNum(u), m = toNum(d);
|
|
64
|
+
if (a == null) return !1;
|
|
65
|
+
if (s === "eq") return a === o;
|
|
66
|
+
if (s === "ne") return a !== o;
|
|
67
|
+
if (s === "in") return l.includes(a);
|
|
68
|
+
if (s === "not_in") return !l.includes(a);
|
|
69
|
+
if (s === "between") return p != null && m != null && a >= Math.min(p, m) && a <= Math.max(p, m);
|
|
70
|
+
if (s === "not_between") return p != null && m != null && (a < Math.min(p, m) || a > Math.max(p, m));
|
|
71
|
+
if (o == null) return !1;
|
|
72
|
+
if (s === "lt") return a < o;
|
|
73
|
+
if (s === "gt") return a > o;
|
|
74
|
+
if (s === "lte") return a <= o;
|
|
75
|
+
if (s === "gte") return a >= o;
|
|
60
76
|
}
|
|
61
|
-
if (
|
|
62
|
-
let
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
65
|
-
if (
|
|
66
|
-
if (
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
77
|
+
if (o === "date") {
|
|
78
|
+
let a = toDateTs(e), o = toDateTs(c), l = toList(c).map(toDateTs).filter((e) => e != null), [u, d] = toPair(c), f = toDateTs(u), m = toDateTs(d);
|
|
79
|
+
if (a == null) return !1;
|
|
80
|
+
if (s === "eq") return a === o;
|
|
81
|
+
if (s === "ne") return a !== o;
|
|
82
|
+
if (s === "in") return l.includes(a);
|
|
83
|
+
if (s === "not_in") return !l.includes(a);
|
|
84
|
+
if (s === "between") return f != null && m != null && a >= Math.min(f, m) && a <= Math.max(f, m);
|
|
85
|
+
if (s === "not_between") return f != null && m != null && (a < Math.min(f, m) || a > Math.max(f, m));
|
|
86
|
+
if (o == null) return !1;
|
|
87
|
+
if (s === "lt") return a < o;
|
|
88
|
+
if (s === "gt") return a > o;
|
|
89
|
+
if (s === "lte") return a <= o;
|
|
90
|
+
if (s === "gte") return a >= o;
|
|
69
91
|
}
|
|
70
|
-
let
|
|
71
|
-
return
|
|
92
|
+
let l = String(e ?? "").toLowerCase(), u = String(c ?? "").toLowerCase(), h = toList(c).map((e) => String(e).toLowerCase()), [g, _] = toPair(c), v = String(g ?? "").toLowerCase(), y = String(_ ?? "").toLowerCase();
|
|
93
|
+
return s === "eq" ? l === u : s === "ne" ? l !== u : s === "in" ? h.includes(l) : s === "not_in" ? !h.includes(l) : s === "between" ? v !== "" && y !== "" && l >= (v < y ? v : y) && l <= (v < y ? y : v) : s === "not_between" ? v !== "" && y !== "" && (l < (v < y ? v : y) || l > (v < y ? y : v)) : s === "startwith" ? l.startsWith(u) : s === "endwith" ? l.endsWith(u) : l.includes(u);
|
|
72
94
|
}
|
|
73
|
-
function evaluateFilterTree(e,
|
|
74
|
-
if (isRuleNode(
|
|
75
|
-
let
|
|
76
|
-
return
|
|
95
|
+
function evaluateFilterTree(e, a, o) {
|
|
96
|
+
if (isRuleNode(a)) return hasActiveRule(a) ? matchFilter(e, a, o) : !0;
|
|
97
|
+
let s = (a.children ?? []).filter(hasActiveTree);
|
|
98
|
+
return s.length ? a.op === "or" ? s.some((a) => evaluateFilterTree(e, a, o)) : s.every((a) => evaluateFilterTree(e, a, o)) : !0;
|
|
77
99
|
}
|
|
78
|
-
function passesFilters(
|
|
79
|
-
return
|
|
80
|
-
if (
|
|
81
|
-
let
|
|
82
|
-
return !
|
|
100
|
+
function passesFilters(e, o, s, c) {
|
|
101
|
+
return s.every((s) => {
|
|
102
|
+
if (s[c] || !s.filterable) return !0;
|
|
103
|
+
let l = o[s.id];
|
|
104
|
+
return !l || !hasActiveTree(l) ? !0 : evaluateFilterTree(e[s.id], l, normalizeType(s));
|
|
83
105
|
});
|
|
84
106
|
}
|
|
85
107
|
const FilterPlugin = {
|
|
86
108
|
name: "filter",
|
|
87
109
|
store: () => ({ filters: {} }),
|
|
88
110
|
rewriteProps: {
|
|
89
|
-
filter: ({ filter: e }
|
|
111
|
+
filter: ({ filter: e }) => ({
|
|
90
112
|
autoMatch: !0,
|
|
91
113
|
...e
|
|
92
114
|
}),
|
|
93
|
-
|
|
115
|
+
newRow: ({ newRow: a }, { store: o }) => function(...s) {
|
|
116
|
+
let c = a(...s), { filters: l, props: u } = o, { columns: d } = u;
|
|
117
|
+
return d.forEach((a) => {
|
|
118
|
+
if (a[o.internal] || !a.filterable) return;
|
|
119
|
+
let s = l[a.id];
|
|
120
|
+
s && isRuleNode(s) && (c[a.id] = {
|
|
121
|
+
ne: `not ${s.value}`,
|
|
122
|
+
between: toArr(s.value)[0],
|
|
123
|
+
not_between: NaN,
|
|
124
|
+
in: toArr(s.value)[0],
|
|
125
|
+
not_in: "",
|
|
126
|
+
lt: s.value - 1,
|
|
127
|
+
gt: s.value + 1,
|
|
128
|
+
blank: "",
|
|
129
|
+
noblank: "default",
|
|
130
|
+
true: !0,
|
|
131
|
+
false: !1
|
|
132
|
+
}[s.op] ?? s.value);
|
|
133
|
+
}), c;
|
|
134
|
+
},
|
|
135
|
+
data: ({ data: e }, { store: a }) => {
|
|
94
136
|
if (!e) return e;
|
|
95
|
-
let { filters:
|
|
96
|
-
return !
|
|
137
|
+
let { filters: o } = a, { columns: s, filter: c } = a.props;
|
|
138
|
+
return !c.autoMatch || !Object.values(o).some(hasActiveTree) ? e : e.filter((e) => passesFilters(e, o, s, a.internal));
|
|
97
139
|
},
|
|
98
|
-
Th: ({ Th: e }, { store:
|
|
99
|
-
let
|
|
100
|
-
return createComponent(e, mergeProps(
|
|
101
|
-
return [memo(() =>
|
|
140
|
+
Th: ({ Th: e }, { store: a }) => (d) => {
|
|
141
|
+
let f = () => !!d.col.filterable && !d.col[a.internal];
|
|
142
|
+
return createComponent(e, mergeProps(d, { get children() {
|
|
143
|
+
return [memo(() => d.children), createComponent(Show, {
|
|
102
144
|
get when() {
|
|
103
|
-
return
|
|
145
|
+
return f();
|
|
104
146
|
},
|
|
105
147
|
get children() {
|
|
106
148
|
return createComponent(Filter, {
|
|
107
149
|
get col() {
|
|
108
|
-
return
|
|
150
|
+
return d.col;
|
|
109
151
|
},
|
|
110
152
|
get tree() {
|
|
111
|
-
return
|
|
153
|
+
return a.filters[d.col.id];
|
|
112
154
|
},
|
|
113
155
|
setTree: (e) => {
|
|
114
|
-
e ?
|
|
156
|
+
e ? a.filters[d.col.id] = e : delete a.filters[d.col.id], a.props.filter?.onChange?.(Object.values(a.filters));
|
|
115
157
|
}
|
|
116
158
|
});
|
|
117
159
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "..";
|
|
2
|
+
declare module '../index' {
|
|
3
|
+
interface Commands {
|
|
4
|
+
createExcel(data?: any[]): Promise<Blob>;
|
|
5
|
+
exportExcel(data?: any[]): Promise<void>;
|
|
6
|
+
readExcel(file?: File): Promise<any[]>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const ImportExportPlugin: Plugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { chooseFile } from "../utils.js";
|
|
2
|
+
function readFileAsArrayBuffer(e) {
|
|
3
|
+
return new Promise((t, n) => {
|
|
4
|
+
let r = new FileReader();
|
|
5
|
+
r.onload = () => t(r.result), r.onerror = n, r.readAsArrayBuffer(e);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function downloadBlob(e, t) {
|
|
9
|
+
let n = URL.createObjectURL(e), r = document.createElement("a");
|
|
10
|
+
r.href = n, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
|
|
11
|
+
}
|
|
12
|
+
const ImportExportPlugin = {
|
|
13
|
+
name: "ImportExportPlugin",
|
|
14
|
+
commands: (r) => ({
|
|
15
|
+
createExcel: async (e = r.props.data) => {
|
|
16
|
+
let t = await import("xlsx"), n = r.props.columns.filter((e) => !e[r.internal]), i = e.map((e) => Object.fromEntries(n.map((t) => [t.name, e[t.id]]))), a = t.utils.json_to_sheet(i), o = t.utils.book_new();
|
|
17
|
+
t.utils.book_append_sheet(o, a, "Data");
|
|
18
|
+
let s = t.write(o, {
|
|
19
|
+
bookType: "xlsx",
|
|
20
|
+
type: "array"
|
|
21
|
+
});
|
|
22
|
+
return new Blob([s], { type: "application/octet-stream" });
|
|
23
|
+
},
|
|
24
|
+
exportExcel: async (e = r.props.data) => {
|
|
25
|
+
let t = await r.commands.createExcel(e);
|
|
26
|
+
downloadBlob(t, "data.xlsx");
|
|
27
|
+
},
|
|
28
|
+
readExcel: async (n) => {
|
|
29
|
+
n ??= await chooseFile({ accept: ".xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" });
|
|
30
|
+
let i = await readFileAsArrayBuffer(n), a = await import("xlsx"), o = a.read(i, { type: "array" }), s = o.Sheets[o.SheetNames[0]], c = a.utils.sheet_to_json(s, { header: 1 });
|
|
31
|
+
if (c.length < 1) return;
|
|
32
|
+
let l = r.props.columns.filter((e) => !e[r.internal]);
|
|
33
|
+
return c.slice(1).map((e) => Object.fromEntries(l.map((t) => [t.id, e[t.name]])));
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
export { ImportExportPlugin };
|
|
@@ -11,6 +11,7 @@ declare module '../index' {
|
|
|
11
11
|
rowEquals: (a: any, b: any) => boolean;
|
|
12
12
|
rowIndexOf: (data: any[], row: any) => number;
|
|
13
13
|
rowChange: (row: any, i?: any) => void;
|
|
14
|
+
rowsChange: (rows: any) => void;
|
|
14
15
|
addRows: (i: number, rows: any[], before?: boolean) => void;
|
|
15
16
|
deleteRows: (i: number[]) => void;
|
|
16
17
|
moveRows: (ii: number[], to: number) => void;
|
|
@@ -82,6 +82,13 @@ const MenuPlugin = {
|
|
|
82
82
|
let a = [...e.rawProps.data || []];
|
|
83
83
|
i = i == null ? e.commands.rowIndexOf(a, r) : a.findIndex((r) => e.commands.rowEquals(r, e.props.data[i])), i > -1 && (a[i] = r, e.props.onDataChange?.(a));
|
|
84
84
|
},
|
|
85
|
+
rowsChange(r) {
|
|
86
|
+
let i = [...e.rawProps.data || []];
|
|
87
|
+
r.forEach((r) => {
|
|
88
|
+
let a = e.commands.rowIndexOf(i, r);
|
|
89
|
+
a > -1 && (i[a] = r);
|
|
90
|
+
}), e.props.onDataChange?.(i);
|
|
91
|
+
},
|
|
85
92
|
addRows(r, i, a = !0) {
|
|
86
93
|
addRows(e, r, i, a);
|
|
87
94
|
},
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type JSX } from 'solid-js';
|
|
2
|
-
import { type Plugin, type
|
|
2
|
+
import { type Plugin, type TDProps } from '../..';
|
|
3
3
|
declare module '../../index' {
|
|
4
4
|
interface TableProps {
|
|
5
5
|
}
|
|
6
6
|
interface TableColumn {
|
|
7
7
|
type?: string;
|
|
8
|
-
render?: Render;
|
|
8
|
+
render?: string | Render;
|
|
9
9
|
enum?: Record<string, any> | {
|
|
10
10
|
label?: string;
|
|
11
11
|
value: any;
|
|
@@ -17,7 +17,7 @@ declare module '../../index' {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export type RenderProps =
|
|
20
|
+
export type RenderProps = TDProps & {
|
|
21
21
|
onChange: (v: any) => void;
|
|
22
22
|
};
|
|
23
23
|
export type Render = (props: RenderProps) => JSX.Element | any;
|
|
@@ -8,36 +8,36 @@ const RenderPlugin = {
|
|
|
8
8
|
name: "render",
|
|
9
9
|
priority: -Infinity,
|
|
10
10
|
store: () => ({ renders: { ...renders } }),
|
|
11
|
-
rewriteProps: { Td: ({ Td: e }, { store:
|
|
11
|
+
rewriteProps: { Td: ({ Td: e }, { store: m }) => (h) => createComponent(e, mergeProps(h, { get children() {
|
|
12
12
|
return (() => {
|
|
13
|
-
let e = ((e) => typeof e == "string" ?
|
|
14
|
-
return renderComponent(e, mergeProps$1(
|
|
15
|
-
...
|
|
16
|
-
[
|
|
17
|
-
}
|
|
13
|
+
let e = ((e) => typeof e == "string" ? m.renders[e] : e)(h.col.render ?? h.col.type) || text;
|
|
14
|
+
return renderComponent(e, mergeProps$1(h, { onChange: (e) => m.commands.rowChange({
|
|
15
|
+
...h.data,
|
|
16
|
+
[h.col.id]: e
|
|
17
|
+
}) }), m);
|
|
18
18
|
})();
|
|
19
19
|
} })) }
|
|
20
20
|
};
|
|
21
|
-
var text = (
|
|
21
|
+
var text = (h) => memo(() => memo(() => !!h.col.enum)() ? toArr(h.value).map((m) => resolveOptions(h.col.enum).find((e) => e.value == m)?.label ?? m).join(", ") : h.value);
|
|
22
22
|
const renders = {
|
|
23
23
|
text,
|
|
24
24
|
number: text,
|
|
25
25
|
date: text,
|
|
26
26
|
checkbox: (e) => (() => {
|
|
27
|
-
var
|
|
28
|
-
return insert(
|
|
27
|
+
var m = _tmpl$();
|
|
28
|
+
return insert(m, createComponent(Checkbox, {
|
|
29
29
|
class: "",
|
|
30
30
|
get value() {
|
|
31
|
-
return e.
|
|
31
|
+
return e.value;
|
|
32
32
|
},
|
|
33
33
|
get onChange() {
|
|
34
34
|
return e.onChange;
|
|
35
35
|
}
|
|
36
|
-
})),
|
|
36
|
+
})), m;
|
|
37
37
|
})(),
|
|
38
38
|
file: (e) => createComponent(Files, {
|
|
39
39
|
get value() {
|
|
40
|
-
return e.
|
|
40
|
+
return e.value;
|
|
41
41
|
},
|
|
42
42
|
get onChange() {
|
|
43
43
|
return e.onChange;
|
|
@@ -4,38 +4,37 @@ import { Ctx } from "../index.js";
|
|
|
4
4
|
import { className, createComponent, effect, memo, mergeProps, template, use } from "solid-js/web";
|
|
5
5
|
import { batch, untrack, useContext } from "solid-js";
|
|
6
6
|
import { reconcile } from "solid-js/store";
|
|
7
|
-
import { combineProps } from "@solid-primitives/props";
|
|
8
7
|
import { clamp } from "es-toolkit";
|
|
9
8
|
import { createEventListener } from "@solid-primitives/event-listener";
|
|
10
9
|
import { defaultsDeep } from "es-toolkit/compat";
|
|
11
|
-
var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"), ColHandle = (
|
|
12
|
-
let { props:
|
|
13
|
-
return usePointerDrag(() =>
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"), ColHandle = (f) => {
|
|
11
|
+
let { props: h, store: _ } = useContext(Ctx), v;
|
|
12
|
+
return usePointerDrag(() => v, { start(e, p, m) {
|
|
14
13
|
e.stopPropagation();
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
let e =
|
|
18
|
-
|
|
19
|
-
...p
|
|
20
|
-
width:
|
|
21
|
-
},
|
|
14
|
+
let g = f.x, { min: y, max: b } = h.resizable.col, x = v.parentElement, S = x.offsetWidth;
|
|
15
|
+
p((e, { ox: p }) => _[COL][f.x] = clamp(S + p, y, b)), m(() => {
|
|
16
|
+
let e = h.columns[g], f = [..._.rawProps.columns || []], p = f.findIndex((f) => f[_.ID] === e[_.ID]);
|
|
17
|
+
p > -1 && (f[p] = {
|
|
18
|
+
...f[p],
|
|
19
|
+
width: x.offsetWidth
|
|
20
|
+
}, h.onColumnsChange?.(f)), e.onWidthChange?.(x.offsetWidth);
|
|
22
21
|
});
|
|
23
22
|
} }), (() => {
|
|
24
|
-
var e = _tmpl$(),
|
|
25
|
-
return typeof
|
|
23
|
+
var e = _tmpl$(), p = v;
|
|
24
|
+
return typeof p == "function" ? use(p, e) : v = e, effect(() => className(e, `in-cell__resize-handle absolute top-0 right-0 flex justify-center w-10px! ${f.x == h.columns.length - 1 ? "justify-end!" : "w-10px! translate-x-1/2"} after:w-1 cursor-w-resize z-1`)), e;
|
|
26
25
|
})();
|
|
27
|
-
}, RowHandle = (
|
|
28
|
-
let { props:
|
|
29
|
-
return usePointerDrag(() =>
|
|
26
|
+
}, RowHandle = (f) => {
|
|
27
|
+
let { props: h, store: _ } = useContext(Ctx), v;
|
|
28
|
+
return usePointerDrag(() => v, { start(e, p, m) {
|
|
30
29
|
e.stopPropagation();
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
let e =
|
|
34
|
-
[...
|
|
30
|
+
let g = f.y, { min: y, max: b } = h.resizable.row, x = v.parentElement.offsetHeight;
|
|
31
|
+
p((e, { oy: p }) => _[ROW][f.y] = clamp(x + p, y, b)), m(() => {
|
|
32
|
+
let e = h.data[g];
|
|
33
|
+
[..._.rawProps.data || []].findIndex((f) => f[_.ID] === e[_.ID]);
|
|
35
34
|
});
|
|
36
|
-
} }), createEventListener(() =>
|
|
37
|
-
var e = _tmpl$(),
|
|
38
|
-
return typeof
|
|
35
|
+
} }), createEventListener(() => v, "dblclick", () => f.data[COL] = void 0), (() => {
|
|
36
|
+
var e = _tmpl$(), p = v;
|
|
37
|
+
return typeof p == "function" ? use(p, e) : v = e, effect(() => className(e, `in-cell__resize-handle absolute bottom-0 left-0 flex flex-col justify-center h-1! ${f.y == h.data.length - 1 ? "justify-end!" : ""} after:h-1 cursor-s-resize z-2`)), e;
|
|
39
38
|
})();
|
|
40
39
|
};
|
|
41
40
|
const ResizePlugin = {
|
|
@@ -58,23 +57,33 @@ const ResizePlugin = {
|
|
|
58
57
|
max: 400
|
|
59
58
|
}
|
|
60
59
|
}),
|
|
61
|
-
columns: ({ columns: e }, { store:
|
|
60
|
+
columns: ({ columns: e }, { store: f }) => (e = e.map((e, p) => ({
|
|
62
61
|
...e,
|
|
63
|
-
[
|
|
62
|
+
[f.ID]: e[f.ID] ??= Symbol()
|
|
64
63
|
})), e = e.map((e) => e.resizable === void 0 ? {
|
|
65
64
|
...e,
|
|
66
|
-
resizable:
|
|
67
|
-
} : e), e = e.map((e,
|
|
65
|
+
resizable: f.props?.resizable?.col.enable
|
|
66
|
+
} : e), e = e.map((e, p) => f[COL][p] ? {
|
|
68
67
|
...e,
|
|
69
|
-
width:
|
|
70
|
-
} : e), untrack(() => batch(() => reconcile(e, { key:
|
|
71
|
-
Th: ({ Th: e }, { store:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
width: f[COL][p]
|
|
69
|
+
} : e), untrack(() => batch(() => reconcile(e, { key: f.ID })(f.__resize__cols ??= [])))),
|
|
70
|
+
Th: ({ Th: e }, { store: f }) => (f) => createComponent(e, mergeProps(f, {
|
|
71
|
+
get class() {
|
|
72
|
+
return `relative ${f.class}`;
|
|
73
|
+
},
|
|
74
|
+
get children() {
|
|
75
|
+
return [f.children, memo(() => memo(() => !!f.col.resizable)() && createComponent(ColHandle, f))];
|
|
76
|
+
}
|
|
77
|
+
})),
|
|
78
|
+
Td: ({ Td: e }, { store: f }) => f.props?.resizable?.row.enable ? (p) => createComponent(e, mergeProps(p, {
|
|
79
|
+
get class() {
|
|
80
|
+
return `relative ${p.class}`;
|
|
81
|
+
},
|
|
82
|
+
get children() {
|
|
83
|
+
return [p.children, memo(() => memo(() => !!(p.x == 0 && f.props?.resizable?.row.enable))() && createComponent(RowHandle, p))];
|
|
84
|
+
}
|
|
85
|
+
})) : e,
|
|
86
|
+
cellStyle: ({ cellStyle: e }, { store: p }) => (m) => `${unFn(e, m)};` + (p[ROW][m.y] ? `height: ${p[ROW][m.y]}px` : "")
|
|
78
87
|
}
|
|
79
88
|
};
|
|
80
89
|
export { ResizePlugin };
|
|
@@ -50,7 +50,7 @@ const RowGroupPlugin = {
|
|
|
50
50
|
return d;
|
|
51
51
|
},
|
|
52
52
|
Td: ({ Td: d }, { store: _ }) => (v) => {
|
|
53
|
-
if (!v.data?.[GROUP]) return
|
|
53
|
+
if (!v.data?.[GROUP]) return d(v);
|
|
54
54
|
let { props: y } = useContext(Ctx), b = createMemo(() => _.rowGroup.isExpand(v.data));
|
|
55
55
|
return createComponent(d, mergeProps(v, { get children() {
|
|
56
56
|
return memo(() => y.columns?.findIndex((e) => !e[_.internal]) == v.x)() ? (() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useSelector } from "../hooks/useSelector.js";
|
|
2
2
|
import chevron_right_default from "../chevron-right.js";
|
|
3
3
|
import { createComponent, effect, insert, memo, mergeProps, style, template } from "solid-js/web";
|
|
4
|
-
import { combineProps } from "@solid-primitives/props";
|
|
5
4
|
import { createLazyMemo } from "@solid-primitives/memo";
|
|
6
5
|
var _tmpl$ = /* @__PURE__ */ template("<div class=\"flex items-center\">"), _tmpl$2 = /* @__PURE__ */ template("<span style=display:inline-block;width:16px;flex-shrink:0;margin-right:4px>");
|
|
7
6
|
function flattenTree(e, t, n, r, i = 0, a = null, o = [], s = /* @__PURE__ */ new Map()) {
|
|
@@ -19,7 +18,7 @@ function flattenTree(e, t, n, r, i = 0, a = null, o = [], s = /* @__PURE__ */ ne
|
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
const TreePlugin = (c) => {
|
|
22
|
-
let
|
|
21
|
+
let p = createLazyMemo(() => c.props.columns?.findIndex((e) => !e[c.internal]) ?? -1);
|
|
23
22
|
return {
|
|
24
23
|
name: "tree",
|
|
25
24
|
store: (t) => ({
|
|
@@ -37,27 +36,30 @@ const TreePlugin = (c) => {
|
|
|
37
36
|
let n = t.props.tree.children || "children", r = t.props.rowKey, { flat: i, meta: a } = flattenTree(e, n, r, (e) => t.tree.has(e));
|
|
38
37
|
return t._treeMeta = a, t._haschildren = Object.values(Object.fromEntries(a)).some((e) => e.hasChildren), i;
|
|
39
38
|
},
|
|
40
|
-
Td: ({ Td: e }, { store: c }) => (
|
|
41
|
-
let
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
var e =
|
|
49
|
-
return (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
Td: ({ Td: e }, { store: c }) => (l) => {
|
|
40
|
+
let f = () => c.props.rowKey, m = () => c._treeMeta?.get(l.data?.[f()]);
|
|
41
|
+
return createComponent(e, mergeProps(l, {
|
|
42
|
+
onDblClick: (e) => {
|
|
43
|
+
l.onDblClick?.(e), m()?.hasChildren && c.tree.toggle(l.data?.[f()]);
|
|
44
|
+
},
|
|
45
|
+
get children() {
|
|
46
|
+
return memo(() => !!(c._haschildren && l.x === p()))() ? (() => {
|
|
47
|
+
var e = _tmpl$();
|
|
48
|
+
return insert(e, (() => {
|
|
49
|
+
var e = memo(() => !!m()?.hasChildren);
|
|
50
|
+
return () => e() ? createComponent(chevron_right_default, {
|
|
51
|
+
class: "icon-clickable mr-1",
|
|
52
|
+
get style() {
|
|
53
|
+
return `transform: rotate(${c.tree.has(l.data?.[f()]) ? 90 : 0}deg); opacity: .6; flex-shrink: 0; transition: transform .15s`;
|
|
54
|
+
},
|
|
55
|
+
onClick: (e) => {
|
|
56
|
+
e.stopPropagation(), c.tree.toggle(l.data?.[f()]);
|
|
57
|
+
}
|
|
58
|
+
}) : _tmpl$2();
|
|
59
|
+
})(), null), insert(e, () => l.children, null), effect((t) => style(e, `padding-left: ${m()?.depth * 16}px`, t)), e;
|
|
60
|
+
})() : l.children;
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
61
63
|
}
|
|
62
64
|
},
|
|
63
65
|
commands: (e, { addRows: t }) => ({ addRows(n, r, i = !0) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isEmpty } from "../utils.js";
|
|
2
2
|
import { createComponent, insert, memo, mergeProps, template } from "solid-js/web";
|
|
3
|
-
import { combineProps } from "@solid-primitives/props";
|
|
4
3
|
var _tmpl$ = /* @__PURE__ */ template("<div class=cell-validation-error>"), _tmpl$2 = /* @__PURE__ */ template("<span class=\"mr-1 c-red/75\">*");
|
|
5
4
|
const ValidatorPlugin = {
|
|
6
5
|
name: "validator",
|
|
@@ -55,19 +54,22 @@ const ValidatorPlugin = {
|
|
|
55
54
|
}
|
|
56
55
|
}),
|
|
57
56
|
rewriteProps: {
|
|
58
|
-
Td: ({ Td: e }, { store: a }) => (
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
Td: ({ Td: e }, { store: a }) => (s) => {
|
|
58
|
+
let c = () => a.cellValidationErrors[s.data[a.props.rowKey]]?.[s.col.id];
|
|
59
|
+
return createComponent(e, mergeProps(s, {
|
|
60
|
+
get class() {
|
|
61
|
+
return s.class + " " + (c() == null ? "" : "is-invalid");
|
|
62
|
+
},
|
|
63
|
+
get children() {
|
|
64
|
+
return [s.children, memo(() => memo(() => c() != null)() && (() => {
|
|
65
|
+
var e = _tmpl$();
|
|
66
|
+
return insert(e, c), e;
|
|
67
|
+
})())];
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
68
70
|
},
|
|
69
71
|
Th: ({ Th: e }, { store: n }) => (n) => createComponent(e, mergeProps(n, { get children() {
|
|
70
|
-
return [memo(() => memo(() => !!n.col.required)() && _tmpl$2()),
|
|
72
|
+
return [memo(() => memo(() => !!n.col.required)() && _tmpl$2()), n.children];
|
|
71
73
|
} }))
|
|
72
74
|
}
|
|
73
75
|
};
|
|
@@ -9,10 +9,24 @@ import { defaultRangeExtractor } from "@tanstack/solid-virtual";
|
|
|
9
9
|
var $ML = Symbol();
|
|
10
10
|
const VirtualScrollPlugin = {
|
|
11
11
|
name: "virtual-scroll",
|
|
12
|
+
store: (e) => ({
|
|
13
|
+
scrollToCell(r, i, a) {
|
|
14
|
+
r = typeof r == "object" ? e.props.columns.indexOf(r) : r, i = typeof i == "object" ? e.props.data.indexOf(i) : i;
|
|
15
|
+
let o = e.virtualizerX, s = e.virtualizerY;
|
|
16
|
+
o.scrollToIndex(r, !0), s.scrollToIndex(i, !0);
|
|
17
|
+
},
|
|
18
|
+
scrollCellIfNeeded(r, i, a) {
|
|
19
|
+
r = typeof r == "object" ? e.props.columns.indexOf(r) : r, i = typeof i == "object" ? e.props.data.indexOf(i) : i;
|
|
20
|
+
let o = e.virtualizerX, s = e.virtualizerY, c = e.table.querySelector(`[x="${r}"][y="${i}"]`);
|
|
21
|
+
if (!c) return e.scrollToCell(r, i);
|
|
22
|
+
let l = c.getBoundingClientRect(), u = e.scroll_el.getBoundingClientRect();
|
|
23
|
+
(l.top < u.top || l.bottom > u.bottom) && s.scrollToIndex(i, !0), (l.left < u.left || l.right > u.right) && o.scrollToIndex(r, !0);
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
12
26
|
rewriteProps: {
|
|
13
27
|
virtual: ({ virtual: e }) => defaultsDeep(e, {
|
|
14
|
-
x: { overscan:
|
|
15
|
-
y: { overscan:
|
|
28
|
+
x: { overscan: 2 },
|
|
29
|
+
y: { overscan: 2 }
|
|
16
30
|
}),
|
|
17
31
|
Scroll: ({ Scroll: e }, { store: r }) => (r) => (r = combineProps({ class: "virtual" }, r), createComponent(e, r)),
|
|
18
32
|
Table: ({ Table: r }, { store: o }) => (d) => {
|