intable 0.0.30 → 0.0.32
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 +463 -463
- package/dist/__uno.css +1 -1
- package/dist/components/Filter.d.ts +3 -1
- package/dist/components/Filter.js +18 -18
- package/dist/components/Popover.d.ts +7 -4
- package/dist/components/Popover.js +32 -25
- package/dist/hooks/useControlled.d.ts +112 -0
- package/dist/hooks/useControlled.js +16 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +12 -8
- package/dist/plugins/AutoFillPlugin.js +61 -54
- package/dist/plugins/DiffPlugin.d.ts +2 -2
- package/dist/plugins/DiffPlugin.js +3 -4
- package/dist/plugins/FilterPlugin.d.ts +5 -1
- package/dist/plugins/FilterPlugin.js +89 -89
- package/dist/plugins/ResizePlugin.js +41 -36
- package/dist/plugins/SortPlugin.d.ts +5 -1
- package/dist/plugins/SortPlugin.js +47 -46
- 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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { usePointerDrag } from "../hooks/index.js";
|
|
2
|
+
import { useFloating } from "../components/Popover.js";
|
|
2
3
|
import { delegateEvents, effect, style, template, use } from "solid-js/web";
|
|
3
4
|
import { createMemo, createSignal } from "solid-js";
|
|
4
5
|
import { createScrollPosition } from "@solid-primitives/scroll";
|
|
5
|
-
|
|
6
|
+
import { offset } from "floating-ui-solid";
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template("<div>"), _tmpl$2 = /* @__PURE__ */ template("<div title=\"Drag to fill\"class=\"pointer-events-auto w-2.5 h-2.5 bg-[--c-primary] b-2px b-solid b-[--table-bg] cursor-crosshair\">");
|
|
6
8
|
function inferFill(e, t, n = 1) {
|
|
7
9
|
if (!e.length) return Array(t).fill(null);
|
|
8
10
|
let r = e.map((e) => typeof e == "number" ? e : Number(e));
|
|
@@ -20,7 +22,7 @@ function inferFill(e, t, n = 1) {
|
|
|
20
22
|
return Array.from({ length: t }, (t, n) => e[n % e.length]);
|
|
21
23
|
}
|
|
22
24
|
function applyFill(e, t, n, r, i) {
|
|
23
|
-
let { internal: a } = i, { data: o, columns: s } = i.props, c = r > 0 ? 1 : -1, l = Math.abs(r), u = /* @__PURE__ */ new Map(),
|
|
25
|
+
let { internal: a } = i, { data: o, columns: s } = i.props, c = r > 0 ? 1 : -1, l = Math.abs(r), u = /* @__PURE__ */ new Map(), d = (e) => (u.has(e) || u.set(e, { ...o[e] }), u.get(e)), f, m;
|
|
24
26
|
if (n === "v") {
|
|
25
27
|
let n = o.slice(t[0], t[1] + 1);
|
|
26
28
|
for (let r = e[0]; r <= e[1] && r < s.length; r++) {
|
|
@@ -29,10 +31,10 @@ function applyFill(e, t, n, r, i) {
|
|
|
29
31
|
let i = inferFill(n.map((t) => t[e.id]), l, c);
|
|
30
32
|
for (let n = 0; n < l; n++) {
|
|
31
33
|
let r = c === 1 ? t[1] + 1 + n : t[0] - l + n;
|
|
32
|
-
r >= 0 && r < o.length && (
|
|
34
|
+
r >= 0 && r < o.length && (d(r)[e.id] = i[n]);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
|
-
|
|
37
|
+
f = [e[0], c === 1 ? t[0] : Math.max(t[0] - l, 0)], m = [e[1], c === 1 ? Math.min(t[1] + l, o.length - 1) : t[1]];
|
|
36
38
|
} else {
|
|
37
39
|
for (let n = t[0]; n <= t[1] && n < o.length; n++) {
|
|
38
40
|
let t = s.slice(e[0], e[1] + 1).filter((e) => e && !e[a]).map((e) => o[n][e.id]), r = inferFill(t, l, c);
|
|
@@ -40,91 +42,96 @@ function applyFill(e, t, n, r, i) {
|
|
|
40
42
|
let i = c === 1 ? e[1] + 1 + t : e[0] - l + t;
|
|
41
43
|
if (i < 0 || i >= s.length) continue;
|
|
42
44
|
let o = s[i];
|
|
43
|
-
o && !o[a] && (
|
|
45
|
+
o && !o[a] && (d(n)[o.id] = r[t]);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
f = [c === 1 ? e[0] : Math.max(e[0] - l, 0), t[0]], m = [c === 1 ? Math.min(e[1] + l, s.length - 1) : e[1], t[1]];
|
|
47
49
|
}
|
|
48
50
|
return {
|
|
49
51
|
rowsMap: u,
|
|
50
|
-
newStart:
|
|
52
|
+
newStart: f,
|
|
51
53
|
newEnd: m
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
const AutoFillPlugin = {
|
|
55
57
|
name: "auto-fill",
|
|
56
|
-
layers: [(
|
|
57
|
-
let
|
|
58
|
-
let { start: e, end:
|
|
59
|
-
if (!e?.length || !
|
|
60
|
-
let r = [e[0],
|
|
58
|
+
layers: [(n) => {
|
|
59
|
+
let a = createScrollPosition(() => n.scroll_el), p = createMemo(() => {
|
|
60
|
+
let { start: e, end: t } = n.selected ?? {};
|
|
61
|
+
if (!e?.length || !t?.length) return null;
|
|
62
|
+
let r = [e[0], t[0]].sort((e, t) => e - t), i = [e[1], t[1]].sort((e, t) => e - t);
|
|
61
63
|
return Number.isFinite(r[1]) && Number.isFinite(i[1]) ? {
|
|
62
64
|
xs: r,
|
|
63
65
|
ys: i
|
|
64
66
|
} : null;
|
|
65
|
-
}),
|
|
66
|
-
let e =
|
|
67
|
+
}), h = createMemo(() => {
|
|
68
|
+
let e = n.thSizes ?? [], t = n.trSizes ?? [], r = e[0]?.height ?? 30, i = a.x, o = a.y, s = (t) => e.slice(0, t).reduce((e, t) => e + (t?.width ?? 0), 0) - i, c = (t) => s(t) + (e[t]?.width ?? 0), l = (e) => r + t.slice(0, e).reduce((e, t) => e + (t?.height ?? 28), 0) - o;
|
|
67
69
|
return {
|
|
68
70
|
colX: s,
|
|
69
71
|
colR: c,
|
|
70
72
|
rowY: l,
|
|
71
|
-
rowB: (e) => l(e) + (
|
|
73
|
+
rowB: (e) => l(e) + (t[e]?.height ?? 28)
|
|
72
74
|
};
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
}), g = createMemo(() => {
|
|
76
|
+
if (!p()) return;
|
|
77
|
+
let { xs: e, ys: t } = p();
|
|
78
|
+
if (n.props.columns[e[1]][n.internal] || n.props.data[t[1]][n.internal]) return;
|
|
79
|
+
let r = n.props.autoFill;
|
|
80
|
+
return r === !0 || r?.enable === !0;
|
|
81
|
+
}), [_, v] = createSignal(null), y = createMemo(() => {
|
|
82
|
+
let e = _(), t = p();
|
|
83
|
+
if (!e || !t || !e.delta) return "display:none;position:absolute";
|
|
84
|
+
let { xs: r, ys: i } = t, { colX: a, colR: o, rowY: s, rowB: c } = h(), l = e.delta > 0 ? 1 : -1, u = Math.abs(e.delta), d = n.props.data.length, f = n.props.columns.length, m, g, v, y;
|
|
85
|
+
e.axis === "v" ? (m = a(r[0]), v = o(r[1]), [g, y] = l > 0 ? [c(i[1]), c(Math.min(i[1] + u, d - 1))] : [s(Math.max(i[0] - u, 0)), s(i[0])]) : (g = s(i[0]), y = c(i[1]), [m, v] = l > 0 ? [o(r[1]), o(Math.min(r[1] + u, f - 1))] : [a(Math.max(r[0] - u, 0)), a(r[0])]);
|
|
86
|
+
let b = v - m, x = y - g;
|
|
87
|
+
return b <= 0 || x <= 0 ? "display:none;position:absolute" : `position:absolute;left:${m}px;top:${g}px;width:${b}px;height:${x}px;border:1.5px dashed var(--c-primary);background:rgba(99,102,241,0.08);pointer-events:none;z-index:3`;
|
|
88
|
+
}), [b, x] = createSignal(), S = (e, t, r, i) => {
|
|
89
|
+
let { rowsMap: a, newStart: o, newEnd: s } = applyFill(e, t, r, i, n);
|
|
90
|
+
a.size && (n.commands.rowsChange([...a.values()]), n.selected.start = o, n.selected.end = s);
|
|
91
|
+
};
|
|
92
|
+
useFloating({
|
|
93
|
+
reference: () => g() ? (n.ths[p()?.xs[1]], n.trs[p()?.ys[1]]?.querySelector(`[x="${p()?.xs[1]}"]`)) : null,
|
|
94
|
+
floating: b,
|
|
95
|
+
placement: "bottom-end",
|
|
96
|
+
middleware: [offset({
|
|
97
|
+
crossAxis: 5,
|
|
98
|
+
mainAxis: -5
|
|
99
|
+
})]
|
|
100
|
+
});
|
|
101
|
+
let C = (e) => {
|
|
93
102
|
e.stopPropagation();
|
|
94
|
-
let
|
|
95
|
-
if (!
|
|
96
|
-
let { xs: r, ys: i } =
|
|
103
|
+
let t = p();
|
|
104
|
+
if (!t) return;
|
|
105
|
+
let { xs: r, ys: i } = t, { data: a, columns: o } = n.props, s = r[0] > 0 ? r[0] - 1 : r[1] < o.length - 1 ? r[1] + 1 : -1, c = a.length - 1;
|
|
97
106
|
if (s >= 0) {
|
|
98
107
|
let e = o[s];
|
|
99
|
-
if (e && !e[
|
|
108
|
+
if (e && !e[n.internal]) for (let t = i[1] + 1; t < a.length; t++) {
|
|
100
109
|
let n = a[t][e.id];
|
|
101
110
|
if (n != null && n !== "") c = t;
|
|
102
111
|
else break;
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
|
-
|
|
114
|
+
S(r, i, "v", c - i[1]);
|
|
106
115
|
};
|
|
107
|
-
return usePointerDrag(
|
|
116
|
+
return usePointerDrag(b, { start(e, t, n) {
|
|
108
117
|
e.stopPropagation(), e.preventDefault();
|
|
109
|
-
let
|
|
110
|
-
if (!
|
|
111
|
-
let { xs:
|
|
112
|
-
|
|
113
|
-
Math.abs(
|
|
114
|
-
axis:
|
|
115
|
-
delta:
|
|
118
|
+
let r = p();
|
|
119
|
+
if (!r) return;
|
|
120
|
+
let { xs: i, ys: a } = r, o = 0, s = "v";
|
|
121
|
+
t((e, { ox: t, oy: n }) => {
|
|
122
|
+
Math.abs(n) >= Math.abs(t) ? (s = "v", o = e.composedPath().find((e) => e.tagName == "TD")?.getAttribute("y") - a[1]) : (s = "h", o = e.composedPath().find((e) => e.tagName == "TD")?.getAttribute("x") - i[1]), v(o ? {
|
|
123
|
+
axis: s,
|
|
124
|
+
delta: o
|
|
116
125
|
} : null);
|
|
117
|
-
}),
|
|
118
|
-
|
|
126
|
+
}), n(() => {
|
|
127
|
+
v(null), S(i, a, s, o);
|
|
119
128
|
});
|
|
120
129
|
} }), [(() => {
|
|
121
130
|
var e = _tmpl$();
|
|
122
|
-
return effect((t) => style(e,
|
|
131
|
+
return effect((t) => style(e, y(), t)), e;
|
|
123
132
|
})(), (() => {
|
|
124
133
|
var e = _tmpl$2();
|
|
125
|
-
e.$$dblclick = x;
|
|
126
|
-
var t = y;
|
|
127
|
-
return typeof t == "function" ? use(t, e) : y = e, effect((t) => style(e, h() + ";pointer-events:auto", t)), e;
|
|
134
|
+
return e.$$dblclick = C, use(x, e), e;
|
|
128
135
|
})()];
|
|
129
136
|
}]
|
|
130
137
|
};
|
|
@@ -10,7 +10,7 @@ declare module '../index' {
|
|
|
10
10
|
removed?: boolean;
|
|
11
11
|
/** @default true */
|
|
12
12
|
changed?: boolean;
|
|
13
|
-
onCommit?: (
|
|
13
|
+
onCommit?: (opt: {
|
|
14
14
|
added: any[];
|
|
15
15
|
removed: any[];
|
|
16
16
|
changed: any[];
|
|
@@ -22,7 +22,7 @@ declare module '../index' {
|
|
|
22
22
|
diffDataKeyed: () => any;
|
|
23
23
|
}
|
|
24
24
|
interface Commands {
|
|
25
|
-
diffCommit(
|
|
25
|
+
diffCommit(): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
export declare const DiffPlugin: Plugin;
|
|
@@ -11,14 +11,14 @@ const DiffPlugin = {
|
|
|
11
11
|
diffData: () => e.props.diff?.data ?? [],
|
|
12
12
|
diffDataKeyed: createLazyMemo(() => keyBy(e.diffData(), (o) => o[e.props.rowKey]))
|
|
13
13
|
}),
|
|
14
|
-
commands: (e) => ({ async diffCommit(
|
|
15
|
-
let { rowKey: s } = e.props || {}, c = [], l = [], u = [], d = keyBy(o, (e) => e[s]);
|
|
14
|
+
commands: (e) => ({ async diffCommit() {
|
|
15
|
+
let o = e.rawProps.data || [], { rowKey: s } = e.props || {}, c = [], l = [], u = [], d = keyBy(o, (e) => e[s]);
|
|
16
16
|
for (let l of o) {
|
|
17
17
|
let o = e.diffDataKeyed()[l[s]];
|
|
18
18
|
o ? isEqual(l, o) || u.push(l) : c.push(l);
|
|
19
19
|
}
|
|
20
20
|
for (let o of e.diffData()) !d[o[s]] && l.push(o);
|
|
21
|
-
await e.props.diff?.onCommit?.(
|
|
21
|
+
await e.props.diff?.onCommit?.({
|
|
22
22
|
added: c,
|
|
23
23
|
removed: l,
|
|
24
24
|
changed: u
|
|
@@ -26,7 +26,6 @@ const DiffPlugin = {
|
|
|
26
26
|
} }),
|
|
27
27
|
rewriteProps: {
|
|
28
28
|
diff: ({ diff: e }) => ({
|
|
29
|
-
enable: !1,
|
|
30
29
|
added: !0,
|
|
31
30
|
removed: !0,
|
|
32
31
|
changed: !0,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Plugin } from '..';
|
|
2
2
|
import type { AndOrNode } from '../components/AndOr';
|
|
3
|
+
import { useControlled } from '../hooks/useControlled';
|
|
3
4
|
declare module '../index' {
|
|
4
5
|
interface TableProps {
|
|
5
6
|
filter?: {
|
|
7
|
+
value?: AndOrNode[];
|
|
8
|
+
defaultValue?: AndOrNode[];
|
|
9
|
+
initialValue?: AndOrNode[];
|
|
6
10
|
onChange?: (value: AndOrNode[]) => void;
|
|
7
11
|
/** @default true */
|
|
8
12
|
autoMatch?: boolean;
|
|
@@ -12,7 +16,7 @@ declare module '../index' {
|
|
|
12
16
|
filterable?: boolean;
|
|
13
17
|
}
|
|
14
18
|
interface TableStore {
|
|
15
|
-
|
|
19
|
+
filter: ReturnType<typeof useControlled<Exclude<TableProps['filter'], undefined>>>;
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
export declare const FilterPlugin: Plugin;
|
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import { toArr } from "../utils.js";
|
|
1
|
+
import { findret, toArr } from "../utils.js";
|
|
2
|
+
import { useControlled } from "../hooks/useControlled.js";
|
|
2
3
|
import { normalizeType } from "../components/AndOrFields.js";
|
|
3
|
-
import { Filter } from "../components/Filter.js";
|
|
4
|
+
import { Filter, firstRule, isRuleNode } from "../components/Filter.js";
|
|
4
5
|
import { createComponent, memo, mergeProps } from "solid-js/web";
|
|
5
|
-
import { Show } from "solid-js";
|
|
6
|
+
import { Show, mergeProps as mergeProps$1 } from "solid-js";
|
|
7
|
+
import { keyBy } from "es-toolkit";
|
|
6
8
|
function isBlank(e) {
|
|
7
9
|
return e == null || String(e).trim() === "";
|
|
8
10
|
}
|
|
9
11
|
function toNum(e) {
|
|
10
|
-
let
|
|
11
|
-
return Number.isNaN(
|
|
12
|
+
let m = Number(e);
|
|
13
|
+
return Number.isNaN(m) ? null : m;
|
|
12
14
|
}
|
|
13
15
|
function toDateTs(e) {
|
|
14
16
|
if (isBlank(e)) return null;
|
|
15
|
-
let
|
|
16
|
-
return Number.isNaN(
|
|
17
|
+
let m = new Date(String(e)).getTime();
|
|
18
|
+
return Number.isNaN(m) ? null : m;
|
|
17
19
|
}
|
|
18
20
|
function toBool(e) {
|
|
19
21
|
if (typeof e == "boolean") return e;
|
|
20
22
|
if (typeof e == "number") return e !== 0;
|
|
21
|
-
let
|
|
23
|
+
let m = String(e ?? "").trim().toLowerCase();
|
|
22
24
|
return [
|
|
23
25
|
"1",
|
|
24
26
|
"true",
|
|
25
27
|
"yes",
|
|
26
28
|
"y",
|
|
27
29
|
"on"
|
|
28
|
-
].includes(
|
|
30
|
+
].includes(m) ? !0 : [
|
|
29
31
|
"0",
|
|
30
32
|
"false",
|
|
31
33
|
"no",
|
|
32
34
|
"n",
|
|
33
35
|
"off",
|
|
34
36
|
""
|
|
35
|
-
].includes(
|
|
37
|
+
].includes(m) ? !1 : !!e;
|
|
36
38
|
}
|
|
37
39
|
function toList(e) {
|
|
38
40
|
return Array.isArray(e) ? e : e == null || String(e).trim() === "" ? [] : String(e).split(",").map((e) => e.trim()).filter(Boolean);
|
|
@@ -40,11 +42,8 @@ function toList(e) {
|
|
|
40
42
|
function toPair(e) {
|
|
41
43
|
if (Array.isArray(e)) return [e[0], e[1]];
|
|
42
44
|
if (e == null || String(e).trim() === "") return [void 0, void 0];
|
|
43
|
-
let
|
|
44
|
-
return [
|
|
45
|
-
}
|
|
46
|
-
function isRuleNode(e) {
|
|
47
|
-
return "field" in e;
|
|
45
|
+
let m = String(e).split(",").map((e) => e.trim());
|
|
46
|
+
return [m[0], m[1]];
|
|
48
47
|
}
|
|
49
48
|
function hasActiveRule(e) {
|
|
50
49
|
return !!e.op;
|
|
@@ -52,108 +51,109 @@ function hasActiveRule(e) {
|
|
|
52
51
|
function hasActiveTree(e) {
|
|
53
52
|
return e ? isRuleNode(e) ? hasActiveRule(e) : (e.children ?? []).some(hasActiveTree) : !1;
|
|
54
53
|
}
|
|
55
|
-
function matchFilter(e,
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
if (
|
|
61
|
-
let
|
|
62
|
-
if (
|
|
63
|
-
let
|
|
64
|
-
if (
|
|
65
|
-
if (
|
|
66
|
-
if (
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
74
|
-
if (
|
|
75
|
-
if (
|
|
54
|
+
function matchFilter(e, m, h) {
|
|
55
|
+
let g = m.op;
|
|
56
|
+
if (g === "blank") return isBlank(e);
|
|
57
|
+
if (g === "noblank") return !isBlank(e);
|
|
58
|
+
if (g === "true") return toBool(e);
|
|
59
|
+
if (g === "false") return !toBool(e);
|
|
60
|
+
let _ = m.value;
|
|
61
|
+
if (h === "number") {
|
|
62
|
+
let m = toNum(e), h = toNum(_), v = toList(_).map(toNum).filter((e) => e != null), [y, b] = toPair(_), x = toNum(y), S = toNum(b);
|
|
63
|
+
if (m == null) return !1;
|
|
64
|
+
if (g === "eq") return m === h;
|
|
65
|
+
if (g === "ne") return m !== h;
|
|
66
|
+
if (g === "in") return v.includes(m);
|
|
67
|
+
if (g === "not_in") return !v.includes(m);
|
|
68
|
+
if (g === "between") return x != null && S != null && m >= Math.min(x, S) && m <= Math.max(x, S);
|
|
69
|
+
if (g === "not_between") return x != null && S != null && (m < Math.min(x, S) || m > Math.max(x, S));
|
|
70
|
+
if (h == null) return !1;
|
|
71
|
+
if (g === "lt") return m < h;
|
|
72
|
+
if (g === "gt") return m > h;
|
|
73
|
+
if (g === "lte") return m <= h;
|
|
74
|
+
if (g === "gte") return m >= h;
|
|
76
75
|
}
|
|
77
|
-
if (
|
|
78
|
-
let
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
84
|
-
if (
|
|
85
|
-
if (
|
|
86
|
-
if (
|
|
87
|
-
if (
|
|
88
|
-
if (
|
|
89
|
-
if (
|
|
90
|
-
if (
|
|
76
|
+
if (h === "date") {
|
|
77
|
+
let m = toDateTs(e), h = toDateTs(_), v = toList(_).map(toDateTs).filter((e) => e != null), [y, b] = toPair(_), x = toDateTs(y), S = toDateTs(b);
|
|
78
|
+
if (m == null) return !1;
|
|
79
|
+
if (g === "eq") return m === h;
|
|
80
|
+
if (g === "ne") return m !== h;
|
|
81
|
+
if (g === "in") return v.includes(m);
|
|
82
|
+
if (g === "not_in") return !v.includes(m);
|
|
83
|
+
if (g === "between") return x != null && S != null && m >= Math.min(x, S) && m <= Math.max(x, S);
|
|
84
|
+
if (g === "not_between") return x != null && S != null && (m < Math.min(x, S) || m > Math.max(x, S));
|
|
85
|
+
if (h == null) return !1;
|
|
86
|
+
if (g === "lt") return m < h;
|
|
87
|
+
if (g === "gt") return m > h;
|
|
88
|
+
if (g === "lte") return m <= h;
|
|
89
|
+
if (g === "gte") return m >= h;
|
|
91
90
|
}
|
|
92
|
-
let
|
|
93
|
-
return
|
|
91
|
+
let v = String(e ?? "").toLowerCase(), y = String(_ ?? "").toLowerCase(), b = toList(_).map((e) => String(e).toLowerCase()), [x, S] = toPair(_), C = String(x ?? "").toLowerCase(), w = String(S ?? "").toLowerCase();
|
|
92
|
+
return g === "eq" ? v === y : g === "ne" ? v !== y : g === "in" ? b.includes(v) : g === "not_in" ? !b.includes(v) : g === "between" ? C !== "" && w !== "" && v >= (C < w ? C : w) && v <= (C < w ? w : C) : g === "not_between" ? C !== "" && w !== "" && (v < (C < w ? C : w) || v > (C < w ? w : C)) : g === "startwith" ? v.startsWith(y) : g === "endwith" ? v.endsWith(y) : v.includes(y);
|
|
94
93
|
}
|
|
95
|
-
function evaluateFilterTree(e,
|
|
96
|
-
if (isRuleNode(
|
|
97
|
-
let
|
|
98
|
-
return
|
|
94
|
+
function evaluateFilterTree(e, m, h) {
|
|
95
|
+
if (isRuleNode(m)) return hasActiveRule(m) ? matchFilter(e[m.field], m, h(m)) : !0;
|
|
96
|
+
let g = (m.children ?? []).filter(hasActiveTree);
|
|
97
|
+
return g.length ? m.op === "or" ? g.some((m) => evaluateFilterTree(e, m, h)) : g.every((m) => evaluateFilterTree(e, m, h)) : !0;
|
|
99
98
|
}
|
|
100
|
-
function passesFilters(e,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
99
|
+
function passesFilters(e, m, h) {
|
|
100
|
+
let _ = keyBy(h, (e) => e.id);
|
|
101
|
+
return evaluateFilterTree(e, {
|
|
102
|
+
op: "and",
|
|
103
|
+
children: m
|
|
104
|
+
}, (e) => normalizeType(_[e.field]));
|
|
106
105
|
}
|
|
107
106
|
const FilterPlugin = {
|
|
108
107
|
name: "filter",
|
|
109
|
-
store: () => ({ filters: {} }),
|
|
110
108
|
rewriteProps: {
|
|
111
|
-
filter: ({ filter: e }) => ({
|
|
109
|
+
filter: ({ filter: e }, { store: m }) => (e = mergeProps$1({
|
|
112
110
|
autoMatch: !0,
|
|
111
|
+
initialValue: [],
|
|
113
112
|
...e
|
|
114
|
-
}),
|
|
115
|
-
newRow: ({ newRow:
|
|
116
|
-
let
|
|
117
|
-
return
|
|
118
|
-
if (
|
|
119
|
-
let
|
|
120
|
-
|
|
121
|
-
ne: `not ${
|
|
122
|
-
between: toArr(
|
|
113
|
+
}, e), m.filter ??= useControlled(e, m.owner), m.filter.$setOpt(e), m.filter),
|
|
114
|
+
newRow: ({ newRow: e }, { store: h }) => function(...g) {
|
|
115
|
+
let _ = e(...g), { filters: v, props: b } = h, { columns: x } = b;
|
|
116
|
+
return x.forEach((e) => {
|
|
117
|
+
if (e[h.internal] || !e.filterable) return;
|
|
118
|
+
let g = v[e.id];
|
|
119
|
+
g && isRuleNode(g) && (_[e.id] = {
|
|
120
|
+
ne: `not ${g.value}`,
|
|
121
|
+
between: toArr(g.value)[0],
|
|
123
122
|
not_between: NaN,
|
|
124
|
-
in: toArr(
|
|
123
|
+
in: toArr(g.value)[0],
|
|
125
124
|
not_in: "",
|
|
126
|
-
lt:
|
|
127
|
-
gt:
|
|
125
|
+
lt: g.value - 1,
|
|
126
|
+
gt: g.value + 1,
|
|
128
127
|
blank: "",
|
|
129
128
|
noblank: "default",
|
|
130
129
|
true: !0,
|
|
131
130
|
false: !1
|
|
132
|
-
}[
|
|
133
|
-
}),
|
|
131
|
+
}[g.op] ?? g.value);
|
|
132
|
+
}), _;
|
|
134
133
|
},
|
|
135
|
-
data: ({ data: e }, { store:
|
|
134
|
+
data: ({ data: e }, { store: m }) => {
|
|
136
135
|
if (!e) return e;
|
|
137
|
-
let {
|
|
138
|
-
return !
|
|
136
|
+
let { columns: h } = m.props, g = m.props.filter;
|
|
137
|
+
return !g.autoMatch || !g.value.some(hasActiveTree) ? e : e.filter((e) => passesFilters(e, g.value, h));
|
|
139
138
|
},
|
|
140
|
-
Th: ({ Th:
|
|
141
|
-
let
|
|
142
|
-
return createComponent(
|
|
143
|
-
return [memo(() =>
|
|
139
|
+
Th: ({ Th: m }, { store: h }) => (g) => {
|
|
140
|
+
let y = () => !!g.col.filterable && !g.col[h.internal];
|
|
141
|
+
return createComponent(m, mergeProps(g, { get children() {
|
|
142
|
+
return [memo(() => g.children), createComponent(Show, {
|
|
144
143
|
get when() {
|
|
145
|
-
return
|
|
144
|
+
return y();
|
|
146
145
|
},
|
|
147
146
|
get children() {
|
|
148
147
|
return createComponent(Filter, {
|
|
149
148
|
get col() {
|
|
150
|
-
return
|
|
149
|
+
return g.col;
|
|
151
150
|
},
|
|
152
151
|
get tree() {
|
|
153
|
-
return
|
|
152
|
+
return findret(h.props.filter.value, (e) => firstRule(e)?.field === g.col.id ? e : null);
|
|
154
153
|
},
|
|
155
154
|
setTree: (e) => {
|
|
156
|
-
|
|
155
|
+
let m = [...h.props.filter.value], _ = m.findIndex((e) => firstRule(e)?.field == g.col.id);
|
|
156
|
+
e ? _ > -1 ? m[_] = e : m.push(e) : _ > -1 && m.splice(_, 1), h.props.filter?.onChange?.(m);
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
}
|
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
import { usePointerDrag } from "../hooks/index.js";
|
|
2
2
|
import { unFn } from "../utils.js";
|
|
3
3
|
import { Ctx } from "../index.js";
|
|
4
|
-
import { className, createComponent, effect, memo, mergeProps, template, use } from "solid-js/web";
|
|
4
|
+
import { className, createComponent, delegateEvents, 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
7
|
import { clamp } from "es-toolkit";
|
|
8
8
|
import { createEventListener } from "@solid-primitives/event-listener";
|
|
9
9
|
import { defaultsDeep } from "es-toolkit/compat";
|
|
10
|
-
var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"),
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW = Symbol("row_size"), findParentEl = (e, m) => {
|
|
11
|
+
for (; e = e.parentElement;) if (m(e)) return e;
|
|
12
|
+
}, ColHandle = (m) => {
|
|
13
|
+
let { props: _, store: v } = useContext(Ctx), b;
|
|
14
|
+
return usePointerDrag(() => b, { start(e, h, g) {
|
|
13
15
|
e.stopPropagation();
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
let e =
|
|
17
|
-
|
|
18
|
-
...
|
|
19
|
-
width:
|
|
20
|
-
},
|
|
16
|
+
let y = m.x, { min: x, max: S } = _.resizable.col, C = findParentEl(b, (e) => e.tagName === "TH"), w = C.offsetWidth;
|
|
17
|
+
h((e, { ox: h }) => v[COL][m.x] = clamp(w + h, x, S)), g(() => {
|
|
18
|
+
let e = _.columns[y], m = [...v.rawProps.columns || []], h = m.findIndex((m) => m[v.ID] === e[v.ID]);
|
|
19
|
+
h > -1 && (m[h] = {
|
|
20
|
+
...m[h],
|
|
21
|
+
width: C.offsetWidth
|
|
22
|
+
}, _.onColumnsChange?.(m)), e.onWidthChange?.(C.offsetWidth);
|
|
21
23
|
});
|
|
22
24
|
} }), (() => {
|
|
23
|
-
var e = _tmpl$()
|
|
24
|
-
|
|
25
|
+
var e = _tmpl$();
|
|
26
|
+
e.$$click = (e) => e.stopPropagation();
|
|
27
|
+
var h = b;
|
|
28
|
+
return typeof h == "function" ? use(h, e) : b = e, effect(() => className(e, `in-cell__resize-handle absolute top-0 right-0 flex justify-center w-10px! ${m.x == _.columns.length - 1 ? "justify-end!" : "w-10px! translate-x-1/2"} after:w-1 cursor-w-resize z-1`)), e;
|
|
25
29
|
})();
|
|
26
|
-
}, RowHandle = (
|
|
27
|
-
let { props:
|
|
28
|
-
return usePointerDrag(() =>
|
|
30
|
+
}, RowHandle = (m) => {
|
|
31
|
+
let { props: _, store: v } = useContext(Ctx), b;
|
|
32
|
+
return usePointerDrag(() => b, { start(e, h, g) {
|
|
29
33
|
e.stopPropagation();
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
let e =
|
|
33
|
-
[...
|
|
34
|
+
let y = m.y, { min: x, max: S } = _.resizable.row, C = findParentEl(b, (e) => e.tagName === "TD").offsetHeight;
|
|
35
|
+
h((e, { oy: h }) => v[ROW][m.y] = clamp(C + h, x, S)), g(() => {
|
|
36
|
+
let e = _.data[y];
|
|
37
|
+
[...v.rawProps.data || []].findIndex((m) => m[v.ID] === e[v.ID]);
|
|
34
38
|
});
|
|
35
|
-
} }), createEventListener(() =>
|
|
36
|
-
var e = _tmpl$(),
|
|
37
|
-
return typeof
|
|
39
|
+
} }), createEventListener(() => b, "dblclick", () => m.data[COL] = void 0), (() => {
|
|
40
|
+
var e = _tmpl$(), h = b;
|
|
41
|
+
return typeof h == "function" ? use(h, e) : b = e, effect(() => className(e, `in-cell__resize-handle absolute bottom-0 left-0 flex flex-col justify-center h-1! ${m.y == _.data.length - 1 ? "justify-end!" : ""} after:h-1 cursor-s-resize z-2`)), e;
|
|
38
42
|
})();
|
|
39
43
|
};
|
|
40
44
|
const ResizePlugin = {
|
|
@@ -57,33 +61,34 @@ const ResizePlugin = {
|
|
|
57
61
|
max: 400
|
|
58
62
|
}
|
|
59
63
|
}),
|
|
60
|
-
columns: ({ columns: e }, { store:
|
|
64
|
+
columns: ({ columns: e }, { store: m }) => (e = e.map((e, h) => ({
|
|
61
65
|
...e,
|
|
62
|
-
[
|
|
66
|
+
[m.ID]: e[m.ID] ??= Symbol()
|
|
63
67
|
})), e = e.map((e) => e.resizable === void 0 ? {
|
|
64
68
|
...e,
|
|
65
|
-
resizable:
|
|
66
|
-
} : e), e = e.map((e,
|
|
69
|
+
resizable: m.props?.resizable?.col.enable
|
|
70
|
+
} : e), e = e.map((e, h) => m[COL][h] ? {
|
|
67
71
|
...e,
|
|
68
|
-
width:
|
|
69
|
-
} : e), untrack(() => batch(() => reconcile(e, { key:
|
|
70
|
-
Th: ({ Th: e }, { store:
|
|
72
|
+
width: m[COL][h]
|
|
73
|
+
} : e), untrack(() => batch(() => reconcile(e, { key: m.ID })(m.__resize__cols ??= [])))),
|
|
74
|
+
Th: ({ Th: e }, { store: m }) => (m) => createComponent(e, mergeProps(m, {
|
|
71
75
|
get class() {
|
|
72
|
-
return `relative ${
|
|
76
|
+
return `relative ${m.class}`;
|
|
73
77
|
},
|
|
74
78
|
get children() {
|
|
75
|
-
return [
|
|
79
|
+
return [m.children, memo(() => memo(() => !!m.col.resizable)() && createComponent(ColHandle, m))];
|
|
76
80
|
}
|
|
77
81
|
})),
|
|
78
|
-
Td: ({ Td: e }, { store:
|
|
82
|
+
Td: ({ Td: e }, { store: m }) => m.props?.resizable?.row.enable ? (h) => createComponent(e, mergeProps(h, {
|
|
79
83
|
get class() {
|
|
80
|
-
return `relative ${
|
|
84
|
+
return `relative ${h.class}`;
|
|
81
85
|
},
|
|
82
86
|
get children() {
|
|
83
|
-
return [
|
|
87
|
+
return [h.children, memo(() => memo(() => !!(h.x == 0 && m.props?.resizable?.row.enable))() && createComponent(RowHandle, h))];
|
|
84
88
|
}
|
|
85
89
|
})) : e,
|
|
86
|
-
cellStyle: ({ cellStyle: e }, { store:
|
|
90
|
+
cellStyle: ({ cellStyle: e }, { store: h }) => (g) => `${unFn(e, g)};` + (h[ROW][g.y] ? `height: ${h[ROW][g.y]}px` : "")
|
|
87
91
|
}
|
|
88
92
|
};
|
|
93
|
+
delegateEvents(["click"]);
|
|
89
94
|
export { ResizePlugin };
|