intable 0.0.22 → 0.0.24
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/AndOr.d.ts +35 -0
- package/dist/components/AndOr.js +188 -0
- package/dist/components/AndOrFields.d.ts +38 -0
- package/dist/components/AndOrFields.js +280 -0
- package/dist/components/Filter.d.ts +10 -0
- package/dist/components/Filter.js +97 -0
- package/dist/filter.js +6 -0
- package/dist/hooks/index.js +4 -1
- package/dist/hooks/useVirtualizer.js +55 -59
- package/dist/index.d.ts +4 -3
- package/dist/index.js +245 -232
- package/dist/plugins/CommandPlugin.js +19 -21
- package/dist/plugins/EditablePlugin.js +6 -10
- package/dist/plugins/FilterPlugin.d.ts +18 -0
- package/dist/plugins/FilterPlugin.js +123 -0
- package/dist/plugins/LoadMorePlugin.d.ts +24 -0
- package/dist/plugins/LoadMorePlugin.js +62 -0
- package/dist/plugins/MenuPlugin.js +4 -3
- package/dist/plugins/RenderPlugin/index.d.ts +1 -0
- package/dist/plugins/RenderPlugin/index.js +1 -1
- package/dist/plugins/ValidatorPlugin.js +36 -35
- package/dist/plugins/VirtualScrollPlugin.js +73 -75
- package/dist/style.css +2 -2
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +42 -31
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Popover } from "./Popover.js";
|
|
2
|
+
import { AndOrFields, RuleValueEditor, isValueFreeOp, newRule } from "./AndOrFields.js";
|
|
3
|
+
import filter_default from "../filter.js";
|
|
4
|
+
import { addEventListener, className, createComponent, delegateEvents, effect, insert, template, use } from "solid-js/web";
|
|
5
|
+
import { Show } from "solid-js";
|
|
6
|
+
import { isEqual } from "es-toolkit";
|
|
7
|
+
import { autoPlacement, offset } from "floating-ui-solid";
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template("<div class=\"mt-1 flex gap-1.5\"><button aria-label=筛选 title=筛选>"), _tmpl$2 = /* @__PURE__ */ template("<div class=\"filter-input min-w-24 op-60 select-none\">"), _tmpl$3 = /* @__PURE__ */ template("<div class=\"tt-menu p-4! z-2\">");
|
|
9
|
+
function isRuleNode(e) {
|
|
10
|
+
return e ? "field" in e : !1;
|
|
11
|
+
}
|
|
12
|
+
function firstRule(e) {
|
|
13
|
+
if (e) {
|
|
14
|
+
if (isRuleNode(e)) return e;
|
|
15
|
+
for (let _ of e.children ?? []) {
|
|
16
|
+
let e = firstRule(_);
|
|
17
|
+
if (e) return e;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const Filter = (y) => {
|
|
22
|
+
let b, x = () => y.tree, C = () => firstRule(x()), w = () => isValueFreeOp(C()?.op), T = (e) => {
|
|
23
|
+
if (isEqual({
|
|
24
|
+
...x(),
|
|
25
|
+
value: e
|
|
26
|
+
}, newRule(y.col))) {
|
|
27
|
+
y.setTree();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!x()) {
|
|
31
|
+
y.setTree(newRule(y.col, { value: e }));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let _ = firstRule(x());
|
|
35
|
+
_ && (_.value = e);
|
|
36
|
+
};
|
|
37
|
+
return (() => {
|
|
38
|
+
var v = _tmpl$(), S = v.firstChild;
|
|
39
|
+
v.$$click = (e) => e.stopPropagation(), addEventListener(v, "pointerdown", (e) => e.stopPropagation()), addEventListener(v, "keydown", (e) => e.stopPropagation()), insert(v, createComponent(Show, {
|
|
40
|
+
get when() {
|
|
41
|
+
return !w();
|
|
42
|
+
},
|
|
43
|
+
get fallback() {
|
|
44
|
+
return _tmpl$2();
|
|
45
|
+
},
|
|
46
|
+
get children() {
|
|
47
|
+
return createComponent(RuleValueEditor, {
|
|
48
|
+
get field() {
|
|
49
|
+
return y.col;
|
|
50
|
+
},
|
|
51
|
+
get op() {
|
|
52
|
+
return C()?.op;
|
|
53
|
+
},
|
|
54
|
+
class: "filter-input",
|
|
55
|
+
get value() {
|
|
56
|
+
return C()?.value ?? "";
|
|
57
|
+
},
|
|
58
|
+
get enum() {
|
|
59
|
+
return y.col.enum;
|
|
60
|
+
},
|
|
61
|
+
onChange: (e) => T(String(e ?? ""))
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}), S);
|
|
65
|
+
var E = b;
|
|
66
|
+
return typeof E == "function" ? use(E, S) : b = S, insert(S, createComponent(filter_default, { class: "size-3.5 op-75" })), insert(v, createComponent(Popover, {
|
|
67
|
+
trigger: "click",
|
|
68
|
+
strategy: "fixed",
|
|
69
|
+
placement: "bottom",
|
|
70
|
+
get middleware() {
|
|
71
|
+
return [offset({ mainAxis: 6 }), autoPlacement({
|
|
72
|
+
boundary: document.body,
|
|
73
|
+
alignment: "start"
|
|
74
|
+
})];
|
|
75
|
+
},
|
|
76
|
+
reference: b,
|
|
77
|
+
get floating() {
|
|
78
|
+
return (() => {
|
|
79
|
+
var e = _tmpl$3();
|
|
80
|
+
return insert(e, createComponent(AndOrFields, {
|
|
81
|
+
get fields() {
|
|
82
|
+
return [y.col];
|
|
83
|
+
},
|
|
84
|
+
get value() {
|
|
85
|
+
return x() ?? newRule(y.col);
|
|
86
|
+
},
|
|
87
|
+
onChange: (e) => y.setTree(isEqual(e, newRule(y.col)) ? void 0 : e),
|
|
88
|
+
newRule: () => newRule(y.col),
|
|
89
|
+
hideFields: !0
|
|
90
|
+
})), e;
|
|
91
|
+
})();
|
|
92
|
+
}
|
|
93
|
+
}), null), effect(() => className(S, `filter-input w-a! flex items-center justify-center ${x() && "bg-blue/20! c-blue b-#00000000!"}`)), v;
|
|
94
|
+
})();
|
|
95
|
+
};
|
|
96
|
+
delegateEvents(["click"]);
|
|
97
|
+
export { Filter };
|
package/dist/filter.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { spread, template } from "solid-js/web";
|
|
2
|
+
var _tmpl$ = /* @__PURE__ */ template("<svg viewBox=\"0 0 24 24\"width=1.2em height=1.2em><path fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=2 d=\"M22 3H2l8 9.46V19l4 2v-8.54z\">"), filter_default = (n = {}) => (() => {
|
|
3
|
+
var r = _tmpl$();
|
|
4
|
+
return spread(r, n, !0, !0), r;
|
|
5
|
+
})();
|
|
6
|
+
export { filter_default as default };
|
package/dist/hooks/index.js
CHANGED
|
@@ -111,7 +111,10 @@ function useMouseDown(h) {
|
|
|
111
111
|
}
|
|
112
112
|
function useClicked(h) {
|
|
113
113
|
let [B, V] = createSignal(!1), H = () => castArray(access(h));
|
|
114
|
-
return createEventListener(() => H().map((h) => h?.getRootNode()), "click", (h) =>
|
|
114
|
+
return createEventListener(() => H().map((h) => h?.getRootNode()), "click", (h) => {
|
|
115
|
+
let B = h.composedPath();
|
|
116
|
+
V(H().some((h) => B.includes(h)));
|
|
117
|
+
}), B;
|
|
115
118
|
}
|
|
116
119
|
function useMutation(h, B, V) {
|
|
117
120
|
let H = createSignal(V());
|
|
@@ -1,96 +1,92 @@
|
|
|
1
|
+
import { throttlePromise } from "../utils.js";
|
|
1
2
|
import { createComputed, createMemo, createSignal, mergeProps, untrack } from "solid-js";
|
|
2
3
|
import { createElementSize } from "@solid-primitives/resize-observer";
|
|
3
4
|
import { createScrollPosition } from "@solid-primitives/scroll";
|
|
4
|
-
import { uniqBy } from "es-toolkit";
|
|
5
|
+
import { keyBy, uniqBy } from "es-toolkit";
|
|
5
6
|
var FenwickTree = class e {
|
|
6
7
|
constructor(e) {
|
|
7
8
|
this.n = e, this.tree = new Float64Array(e + 1);
|
|
8
9
|
}
|
|
9
|
-
add(e,
|
|
10
|
-
for (e += 1; e <= this.n; e += e & -e) this.tree[e] +=
|
|
10
|
+
add(e, s) {
|
|
11
|
+
for (e += 1; e <= this.n; e += e & -e) this.tree[e] += s;
|
|
11
12
|
}
|
|
12
13
|
sum(e) {
|
|
13
|
-
let
|
|
14
|
-
for (e += 1; e > 0; e -= e & -e)
|
|
15
|
-
return
|
|
14
|
+
let s = 0;
|
|
15
|
+
for (e += 1; e > 0; e -= e & -e) s += this.tree[e];
|
|
16
|
+
return s;
|
|
16
17
|
}
|
|
17
18
|
total() {
|
|
18
19
|
return this.n > 0 ? this.sum(this.n - 1) : 0;
|
|
19
20
|
}
|
|
20
21
|
findByOffset(e) {
|
|
21
|
-
let
|
|
22
|
-
for (let
|
|
23
|
-
return Math.min(
|
|
22
|
+
let s = 0;
|
|
23
|
+
for (let c = 1 << Math.floor(Math.log2(this.n || 1)); c > 0; c >>= 1) s + c <= this.n && this.tree[s + c] <= e && (s += c, e -= this.tree[s]);
|
|
24
|
+
return Math.min(s, this.n - 1);
|
|
24
25
|
}
|
|
25
|
-
static build(
|
|
26
|
-
let
|
|
27
|
-
for (let e = 0; e <
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
|
|
26
|
+
static build(s) {
|
|
27
|
+
let c = s.length, l = new e(c);
|
|
28
|
+
for (let e = 0; e < c; e++) {
|
|
29
|
+
l.tree[e + 1] += s[e];
|
|
30
|
+
let u = e + 1 + (e + 1 & -(e + 1));
|
|
31
|
+
u <= c && (l.tree[u] += l.tree[e + 1]);
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
+
return l;
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
|
-
function useVirtualizer(
|
|
36
|
-
|
|
36
|
+
function useVirtualizer(d) {
|
|
37
|
+
d = mergeProps({
|
|
37
38
|
overscan: 0,
|
|
38
39
|
batch: 0,
|
|
39
40
|
enable: !0
|
|
40
|
-
},
|
|
41
|
-
let
|
|
41
|
+
}, d);
|
|
42
|
+
let f = createElementSize(d.getScrollElement), p = createScrollPosition(d.getScrollElement), m = createMemo(() => d.horizontal ? p.x : p.y), h = createMemo(() => d.horizontal ? f.width : f.height), g = [], _ = new FenwickTree(0), [v, y] = createSignal(void 0, { equals: !1 }), b = throttlePromise(queueMicrotask), x = () => b().then(y);
|
|
42
43
|
createComputed(() => {
|
|
43
|
-
let { count: e } =
|
|
44
|
+
let { count: e } = d;
|
|
44
45
|
untrack(() => {
|
|
45
|
-
if (e !==
|
|
46
|
-
if (e >
|
|
47
|
-
else
|
|
48
|
-
|
|
46
|
+
if (e !== g.length) {
|
|
47
|
+
if (e > g.length) for (let s = g.length; s < e; s++) g.push(d.estimateSize(s));
|
|
48
|
+
else g.length = e;
|
|
49
|
+
_ = FenwickTree.build(g.slice(0, e)), x();
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
});
|
|
52
|
-
let
|
|
53
|
+
let S = (e) => ({
|
|
53
54
|
index: e,
|
|
54
|
-
start:
|
|
55
|
-
end:
|
|
56
|
-
}),
|
|
57
|
-
|
|
58
|
-
let { batch:
|
|
59
|
-
return
|
|
60
|
-
}, 0),
|
|
61
|
-
|
|
62
|
-
let { batch:
|
|
63
|
-
return
|
|
64
|
-
}, 0),
|
|
65
|
-
if (
|
|
55
|
+
start: _.sum(e - 1),
|
|
56
|
+
end: _.sum(e)
|
|
57
|
+
}), C = createMemo((e) => {
|
|
58
|
+
v();
|
|
59
|
+
let { batch: s, overscan: c = 0 } = d, l = _.findByOffset(m()) - c;
|
|
60
|
+
return s && (l > e ? l = l <= e + s ? e : l > e + s * 2 ? l : e + s : l -= s), Math.max(l, 0);
|
|
61
|
+
}, 0), w = createMemo((e) => {
|
|
62
|
+
v();
|
|
63
|
+
let { batch: s, overscan: c = 0 } = d, l = _.findByOffset(m() + h()) + c;
|
|
64
|
+
return s && (l < e ? l = l >= e - s ? e : l < e - s * 2 ? l : e - s : l += s), Math.min(l, d.count - 1);
|
|
65
|
+
}, 0), T = createMemo(() => {
|
|
66
|
+
if (v(), !d.enable) return Array.from({ length: d.count }, (e, s) => S(s));
|
|
66
67
|
let e = [];
|
|
67
|
-
for (let
|
|
68
|
-
return
|
|
68
|
+
for (let s = C(); s <= w(); s++) e.push(S(s));
|
|
69
|
+
return d.extras && (e.push(...d.extras(C(), w())?.map((e) => S(e)) || []), e = uniqBy(e, (e) => e.index)), e;
|
|
69
70
|
});
|
|
70
71
|
return {
|
|
71
|
-
options:
|
|
72
|
-
startIdx:
|
|
73
|
-
endIdx:
|
|
74
|
-
getTotalSize: () => (
|
|
75
|
-
resizeItem: (e,
|
|
76
|
-
let
|
|
77
|
-
if (
|
|
78
|
-
if (e <
|
|
79
|
-
let e =
|
|
80
|
-
(
|
|
72
|
+
options: d,
|
|
73
|
+
startIdx: C,
|
|
74
|
+
endIdx: w,
|
|
75
|
+
getTotalSize: () => (v(), _.total()),
|
|
76
|
+
resizeItem: (e, s) => {
|
|
77
|
+
let c = g[e] ?? 0;
|
|
78
|
+
if (c !== s) {
|
|
79
|
+
if (e < C()) {
|
|
80
|
+
let e = d.getScrollElement();
|
|
81
|
+
(d.horizontal ? e.scrollLeft : e.scrollTop) !== 0 && (d.horizontal ? e.scrollLeft += s - c : e.scrollTop += s - c);
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
_.add(e, s - c), g[e] = s, x();
|
|
83
84
|
}
|
|
84
85
|
},
|
|
85
|
-
getVirtualItems:
|
|
86
|
+
getVirtualItems: T,
|
|
86
87
|
getVirtualItem: (() => {
|
|
87
|
-
let e = createMemo(() =>
|
|
88
|
-
|
|
89
|
-
let e = {};
|
|
90
|
-
for (let a of x()) e[a.index] = a;
|
|
91
|
-
return e;
|
|
92
|
-
});
|
|
93
|
-
return (a) => e()[a];
|
|
88
|
+
let e = createMemo(() => keyBy(T(), (e) => e.index));
|
|
89
|
+
return (s) => e()[s];
|
|
94
90
|
})()
|
|
95
91
|
};
|
|
96
92
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ type Requireds<T, K extends keyof T> = Pri<Omit<T, K> & Required<Pick<T, K>>>;
|
|
|
24
24
|
type Pri<T> = {
|
|
25
25
|
[K in keyof T]: T[K];
|
|
26
26
|
};
|
|
27
|
-
type TableProps2 = Requireds<TableProps, ('Table' | 'Thead' | 'Tbody' | 'Tr' | 'Th' | 'Td' | 'EachRows' | 'EachCells' | 'rowKey' | 'data' | 'columns' | 'newRow')>;
|
|
27
|
+
type TableProps2 = Requireds<TableProps, ('Scroll' | 'Table' | 'Thead' | 'Tbody' | 'Tr' | 'Th' | 'Td' | 'EachRows' | 'EachCells' | 'rowKey' | 'data' | 'columns' | 'newRow')>;
|
|
28
28
|
type Each<T = any> = (props: {
|
|
29
29
|
each: T[];
|
|
30
30
|
children: (e: () => T, i: () => number) => JSX.Element;
|
|
@@ -65,6 +65,7 @@ export interface TableProps {
|
|
|
65
65
|
rowKey?: any;
|
|
66
66
|
size?: string;
|
|
67
67
|
newRow?: (i: number) => any;
|
|
68
|
+
Scroll?: Component<any>;
|
|
68
69
|
Table?: Component<any>;
|
|
69
70
|
Thead?: Component<any>;
|
|
70
71
|
Tbody?: Component<any>;
|
|
@@ -78,6 +79,7 @@ export interface TableProps {
|
|
|
78
79
|
}>;
|
|
79
80
|
EachRows?: Each;
|
|
80
81
|
EachCells?: Each<TableColumn>;
|
|
82
|
+
Footer?: Component<any>;
|
|
81
83
|
cellClass?: ((props: Omit<TDProps, 'y' | 'data'> & {
|
|
82
84
|
y?: number;
|
|
83
85
|
data?: any;
|
|
@@ -116,7 +118,7 @@ export type TDProps = {
|
|
|
116
118
|
export type TD = Component<TDProps>;
|
|
117
119
|
type Obj = Record<string | symbol, any>;
|
|
118
120
|
export interface TableColumn extends Obj {
|
|
119
|
-
id
|
|
121
|
+
id: any;
|
|
120
122
|
name?: string;
|
|
121
123
|
width?: number;
|
|
122
124
|
fixed?: 'left' | 'right';
|
|
@@ -150,5 +152,4 @@ export interface TableStore extends Obj {
|
|
|
150
152
|
export declare const Intable: (props: TableProps) => JSX.Element;
|
|
151
153
|
export default Intable;
|
|
152
154
|
declare function BasePlugin(): Plugin$0;
|
|
153
|
-
export declare const ScrollPlugin: Plugin;
|
|
154
155
|
export declare const defaultsPlugins: (Plugin$0 | typeof BasePlugin)[];
|