intable 0.0.9 → 0.0.11
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/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +108 -81
- package/dist/index.d.ts +1 -0
- package/dist/index.js +21 -20
- package/dist/plugins/CellSelectionPlugin.js +15 -12
- package/dist/plugins/DiffPlugin.js +1 -0
- package/dist/plugins/DragPlugin.js +26 -18
- package/dist/plugins/HeaderGroup.js +31 -31
- package/dist/plugins/ResizePlugin.js +6 -8
- package/dist/plugins/RowGroupPlugin.js +1 -0
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -36,5 +36,6 @@ export declare function useHistory([val, setVal]: [any, any]): {
|
|
|
36
36
|
readonly index: number;
|
|
37
37
|
readonly history: any[];
|
|
38
38
|
};
|
|
39
|
-
export declare function
|
|
39
|
+
export declare function createShallowState(state: any): any;
|
|
40
|
+
export declare function useMemoState(fn: any): any;
|
|
40
41
|
export {};
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { unFn } from "../utils.js";
|
|
2
|
-
import { $PROXY, batch, createComputed, createEffect, createMemo, createRenderEffect, createRoot, createSignal, mergeProps, on, onCleanup, untrack } from "solid-js";
|
|
2
|
+
import { $PROXY, batch, createComputed, createEffect, createMemo, createRenderEffect, createRoot, createSignal, getOwner, mergeProps, on, onCleanup, runWithOwner, untrack } from "solid-js";
|
|
3
3
|
import { $RAW, createMutable } from "solid-js/store";
|
|
4
4
|
import { isFunction, isPromise, mapValues } from "es-toolkit";
|
|
5
5
|
import { createEventListener, createEventListenerMap } from "@solid-primitives/event-listener";
|
|
@@ -9,149 +9,176 @@ import { makePersisted, storageSync } from "@solid-primitives/storage";
|
|
|
9
9
|
import { createMutationObserver } from "@solid-primitives/mutation-observer";
|
|
10
10
|
import { castArray } from "es-toolkit/compat";
|
|
11
11
|
import { createKeybindingsHandler } from "tinykeys";
|
|
12
|
-
function usePointerDrag(h,
|
|
13
|
-
|
|
12
|
+
function usePointerDrag(h, B) {
|
|
13
|
+
B = mergeProps({ preventDefault: !0 }, B), createPointerListeners({
|
|
14
14
|
target: h,
|
|
15
15
|
passive: !1,
|
|
16
16
|
onDown(h) {
|
|
17
|
-
|
|
18
|
-
let [
|
|
19
|
-
|
|
17
|
+
B.preventDefault && h.preventDefault();
|
|
18
|
+
let [V, H] = [h.x, h.y], U, W;
|
|
19
|
+
B.start?.(h, (h) => U = h, (h) => W = h), createRoot((B) => {
|
|
20
20
|
createPointerListeners({
|
|
21
21
|
target: document,
|
|
22
22
|
onMove(h) {
|
|
23
|
-
let [
|
|
24
|
-
|
|
25
|
-
sx:
|
|
26
|
-
sy:
|
|
27
|
-
ox:
|
|
28
|
-
oy:
|
|
23
|
+
let [B, W] = [h.x - V, h.y - H];
|
|
24
|
+
U?.(h, {
|
|
25
|
+
sx: V,
|
|
26
|
+
sy: H,
|
|
27
|
+
ox: B,
|
|
28
|
+
oy: W
|
|
29
29
|
});
|
|
30
30
|
},
|
|
31
31
|
onUp() {
|
|
32
|
-
|
|
32
|
+
W?.(h), B(), U = void 0, W = void 0;
|
|
33
33
|
}
|
|
34
|
-
}), createEventListenerMap(document, { drop:
|
|
34
|
+
}), createEventListenerMap(document, { drop: B });
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
function model(h,
|
|
40
|
-
let [
|
|
41
|
-
createRenderEffect(() => h.value =
|
|
39
|
+
function model(h, B) {
|
|
40
|
+
let [V, H] = B();
|
|
41
|
+
createRenderEffect(() => h.value = V()), h.addEventListener("input", (h) => H(h.target.value));
|
|
42
42
|
}
|
|
43
|
-
function toSignle(h,
|
|
44
|
-
return [() => h[
|
|
43
|
+
function toSignle(h, B) {
|
|
44
|
+
return [() => h[B], (V) => h[B] = V];
|
|
45
45
|
}
|
|
46
46
|
function useDark() {
|
|
47
|
-
let h = (h) => h == "dark" ||
|
|
47
|
+
let h = (h) => h == "dark" || V() && !h, B = (h) => h ? "dark" : "light", V = () => window.matchMedia("(prefers-color-scheme: dark)").matches, H = makePersisted(createSignal(V()), {
|
|
48
48
|
name: "color-schema",
|
|
49
49
|
storage: localStorage,
|
|
50
50
|
sync: storageSync,
|
|
51
|
-
serialize:
|
|
51
|
+
serialize: B,
|
|
52
52
|
deserialize: h
|
|
53
53
|
});
|
|
54
|
-
return createEffect(() => document.documentElement.classList[
|
|
54
|
+
return createEffect(() => document.documentElement.classList[H[0]() ? "add" : "remove"]("dark")), createEffect(() => window.dispatchEvent(new StorageEvent("storage", {
|
|
55
55
|
key: "color-schema",
|
|
56
|
-
newValue:
|
|
57
|
-
}))),
|
|
56
|
+
newValue: B(H[0]())
|
|
57
|
+
}))), H;
|
|
58
58
|
}
|
|
59
|
-
function useMemoAsync(h,
|
|
60
|
-
let
|
|
59
|
+
function useMemoAsync(h, B) {
|
|
60
|
+
let V = Symbol(), [U, W] = createSignal(B);
|
|
61
61
|
return createComputed(async () => {
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
}) :
|
|
65
|
-
|
|
66
|
-
}),
|
|
62
|
+
let B = h(untrack(U)), H = B instanceof Promise ? await new Promise((h) => {
|
|
63
|
+
B.then(h), onCleanup(() => h(V));
|
|
64
|
+
}) : B;
|
|
65
|
+
H == V || W(() => H);
|
|
66
|
+
}), U;
|
|
67
67
|
}
|
|
68
|
-
function useSignle2(h,
|
|
69
|
-
let
|
|
70
|
-
let
|
|
71
|
-
return isPromise(
|
|
72
|
-
},
|
|
68
|
+
function useSignle2(h, B) {
|
|
69
|
+
let V = createSignal(isFunction(h) ? void 0 : h), U = (h) => {
|
|
70
|
+
let V = B?.before?.(h);
|
|
71
|
+
return isPromise(V) ? V.then((B) => B === void 0 ? h : B) : V ?? h;
|
|
72
|
+
}, W = useMemoAsync(() => U(V[0]()));
|
|
73
73
|
if (isFunction(h)) {
|
|
74
|
-
let
|
|
75
|
-
createComputed(() =>
|
|
74
|
+
let B = useMemoAsync(() => U(h()));
|
|
75
|
+
createComputed(() => V[1](B()));
|
|
76
76
|
}
|
|
77
|
-
return [
|
|
77
|
+
return [W, V[1]];
|
|
78
78
|
}
|
|
79
79
|
var $MEMO = Symbol();
|
|
80
|
-
function toReactive(
|
|
81
|
-
let
|
|
80
|
+
function toReactive(V) {
|
|
81
|
+
let H = () => unFn(V), U = () => !0, W = (h) => ((h) => typeof h == "function" && $MEMO in h ? h() : h)(H()[h]);
|
|
82
82
|
return new Proxy(Object.create(null), {
|
|
83
|
-
get: (h,
|
|
84
|
-
set:
|
|
85
|
-
defineProperty: (h,
|
|
86
|
-
deleteProperty:
|
|
87
|
-
getPrototypeOf: () => Object.getPrototypeOf(
|
|
88
|
-
has: (h,
|
|
89
|
-
ownKeys: (h) => Object.keys(
|
|
90
|
-
getOwnPropertyDescriptor: (h,
|
|
83
|
+
get: (h, V, U) => V == $PROXY || V == $RAW ? U : ((h) => typeof h == "function" && $MEMO in h ? h() : h)(H()[V]),
|
|
84
|
+
set: U,
|
|
85
|
+
defineProperty: (h, B, V) => Object.defineProperty(H(), B, V),
|
|
86
|
+
deleteProperty: U,
|
|
87
|
+
getPrototypeOf: () => Object.getPrototypeOf(H()),
|
|
88
|
+
has: (h, V) => V == $PROXY || V in H(),
|
|
89
|
+
ownKeys: (h) => Object.keys(H()),
|
|
90
|
+
getOwnPropertyDescriptor: (h, B) => ({
|
|
91
91
|
enumerable: !0,
|
|
92
92
|
configurable: !0,
|
|
93
93
|
get() {
|
|
94
|
-
return
|
|
94
|
+
return W(B);
|
|
95
95
|
},
|
|
96
|
-
set:
|
|
96
|
+
set: U
|
|
97
97
|
})
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
function useMemo(h) {
|
|
101
|
-
let
|
|
102
|
-
return
|
|
101
|
+
let B = createMemo(h);
|
|
102
|
+
return B[$MEMO] = 1, B;
|
|
103
103
|
}
|
|
104
104
|
function useHover(h) {
|
|
105
|
-
let [
|
|
106
|
-
return createEventListener(h, "pointerenter", () =>
|
|
105
|
+
let [B, V] = createSignal(!1);
|
|
106
|
+
return createEventListener(h, "pointerenter", () => V(!0)), createEventListener(h, "pointerleave", () => V(!1)), B;
|
|
107
107
|
}
|
|
108
108
|
function useMouseDown(h) {
|
|
109
|
-
let [
|
|
110
|
-
return createEventListener(h, "pointerdown", () =>
|
|
109
|
+
let [B, V] = createSignal(!1);
|
|
110
|
+
return createEventListener(h, "pointerdown", () => V(!0)), createEventListener(document.body, "pointerup", () => V(!1)), B;
|
|
111
111
|
}
|
|
112
112
|
function useClicked(h) {
|
|
113
|
-
let [
|
|
114
|
-
return createEventListener(() =>
|
|
113
|
+
let [B, V] = createSignal(!1), H = () => castArray(access(h));
|
|
114
|
+
return createEventListener(() => H().map((h) => h?.getRootNode()), "click", (h) => V(H().some((B) => B?.contains(h.target)))), B;
|
|
115
115
|
}
|
|
116
|
-
function useMutation(h,
|
|
117
|
-
let
|
|
118
|
-
return createMutationObserver(h,
|
|
116
|
+
function useMutation(h, B, V) {
|
|
117
|
+
let H = createSignal(V());
|
|
118
|
+
return createMutationObserver(h, B, (h) => H[1](V())), H[0];
|
|
119
119
|
}
|
|
120
|
-
function useTinykeys(h,
|
|
121
|
-
createEventListener(h, "keydown", createKeybindingsHandler({ ...mapValues(
|
|
122
|
-
|
|
120
|
+
function useTinykeys(h, B) {
|
|
121
|
+
createEventListener(h, "keydown", createKeybindingsHandler({ ...mapValues(B, (h) => (B) => {
|
|
122
|
+
B.preventDefault(), h(B);
|
|
123
123
|
}) }));
|
|
124
124
|
}
|
|
125
|
-
function useHistory([h,
|
|
126
|
-
let
|
|
125
|
+
function useHistory([h, B]) {
|
|
126
|
+
let V = 1, H = createMutable({
|
|
127
127
|
index: -1,
|
|
128
128
|
history: []
|
|
129
|
-
}),
|
|
129
|
+
}), U = () => (H.index = 0, H.history = [h()]), W = () => H.index > 0, G = () => H.index < H.history.length - 1;
|
|
130
130
|
return createRenderEffect(on(h, (h) => {
|
|
131
131
|
if (h != null) {
|
|
132
|
-
if (!
|
|
133
|
-
|
|
132
|
+
if (!V) return V = 1;
|
|
133
|
+
G() && (H.history = H.history.slice(0, H.index + 1)), H.history[++H.index] = h;
|
|
134
134
|
}
|
|
135
135
|
})), {
|
|
136
|
-
undo: () =>
|
|
137
|
-
redo: () =>
|
|
138
|
-
clear:
|
|
136
|
+
undo: () => W() && ((V = 0) || B(H.history[--H.index])),
|
|
137
|
+
redo: () => G() && ((V = 0) || B(H.history[++H.index])),
|
|
138
|
+
clear: U,
|
|
139
139
|
get index() {
|
|
140
|
-
return
|
|
140
|
+
return H.index;
|
|
141
141
|
},
|
|
142
142
|
get history() {
|
|
143
|
-
return
|
|
143
|
+
return H.history;
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
+
function createShallowState(h) {
|
|
148
|
+
let V = getOwner(), H = {}, U = (h, B) => H[h] ??= runWithOwner(V, () => createSignal(B));
|
|
149
|
+
for (let B in h) U(B, h[B]);
|
|
150
|
+
return new Proxy(h, {
|
|
151
|
+
get(h, V, H) {
|
|
152
|
+
return V == $PROXY ? H : U(V)[0]();
|
|
153
|
+
},
|
|
154
|
+
set(h, B, V, H) {
|
|
155
|
+
return h[B] = V, U(B, V)[1](() => V), !0;
|
|
156
|
+
},
|
|
157
|
+
deleteProperty(h, B) {
|
|
158
|
+
return U(B)[1](void 0), delete h[B], delete H[B], !0;
|
|
159
|
+
},
|
|
160
|
+
has: (h, V) => V == $PROXY || V in H,
|
|
161
|
+
ownKeys: (h) => Reflect.ownKeys(H),
|
|
162
|
+
getOwnPropertyDescriptor: (h, B) => ({
|
|
163
|
+
enumerable: !0,
|
|
164
|
+
configurable: !0,
|
|
165
|
+
get() {
|
|
166
|
+
return U(B)[0]();
|
|
167
|
+
},
|
|
168
|
+
set(h) {
|
|
169
|
+
U(B)[1](h);
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
}
|
|
147
174
|
function useMemoState(h) {
|
|
148
|
-
let
|
|
175
|
+
let B = createShallowState({});
|
|
149
176
|
return createComputed(() => {
|
|
150
|
-
let
|
|
177
|
+
let H = { ...h() };
|
|
151
178
|
untrack(() => batch(() => {
|
|
152
|
-
for (let h in
|
|
153
|
-
Object.assign(
|
|
179
|
+
for (let h in B) h in H || delete B[h];
|
|
180
|
+
Object.assign(B, H);
|
|
154
181
|
}));
|
|
155
|
-
}),
|
|
182
|
+
}), B;
|
|
156
183
|
}
|
|
157
|
-
export { model, toReactive, toSignle, useClicked, useDark, useHistory, useHover, useMemo, useMemoAsync, useMemoState, useMouseDown, useMutation, usePointerDrag, useSignle2, useTinykeys };
|
|
184
|
+
export { createShallowState, model, toReactive, toSignle, useClicked, useDark, useHistory, useHover, useMemo, useMemoAsync, useMemoState, useMouseDown, useMutation, usePointerDrag, useSignle2, useTinykeys };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { unFn } from "./utils.js";
|
|
2
|
-
import { toReactive, useMemo } from "./hooks/index.js";
|
|
2
|
+
import { toReactive, useMemo, useMemoState } from "./hooks/index.js";
|
|
3
3
|
import './style.css';;/* empty css */
|
|
4
4
|
/* empty css */
|
|
5
5
|
import { CellSelectionPlugin } from "./plugins/CellSelectionPlugin.js";
|
|
@@ -29,38 +29,38 @@ var _tmpl$ = /* @__PURE__ */ template("<table>"), _tmpl$2 = /* @__PURE__ */ temp
|
|
|
29
29
|
const Ctx = createContext({
|
|
30
30
|
props: {},
|
|
31
31
|
store: {}
|
|
32
|
-
}), Intable = (
|
|
33
|
-
|
|
34
|
-
let
|
|
32
|
+
}), Intable = (q) => {
|
|
33
|
+
q = mergeProps$1({ rowKey: "id" }, q);
|
|
34
|
+
let J = getOwner(), Y = createMutable({
|
|
35
35
|
get rawProps() {
|
|
36
|
-
return
|
|
36
|
+
return q;
|
|
37
37
|
},
|
|
38
38
|
get plugins() {
|
|
39
39
|
return Z();
|
|
40
40
|
}
|
|
41
|
-
}),
|
|
41
|
+
}), X = memoize((W) => runWithOwner(J, () => unFn(W, Y))), Z = createMemo(() => [
|
|
42
42
|
...defaultsPlugins,
|
|
43
|
-
...
|
|
43
|
+
...q.plugins || [],
|
|
44
44
|
RenderPlugin
|
|
45
|
-
].map(
|
|
45
|
+
].map(X).sort((h, W) => (W.priority || 0) - (h.priority || 0)));
|
|
46
46
|
createComputed((h) => {
|
|
47
47
|
let W = difference(Z(), h);
|
|
48
|
-
return runWithOwner(
|
|
49
|
-
W.forEach((h) => Object.assign(
|
|
48
|
+
return runWithOwner(J, () => {
|
|
49
|
+
W.forEach((h) => Object.assign(Y, h.store?.(Y)));
|
|
50
50
|
}), Z();
|
|
51
51
|
}, []);
|
|
52
52
|
let Q = mapArray(Z, () => createSignal());
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
Q()[
|
|
53
|
+
Y.props = useMemoState(() => Q()[Q().length - 1][0]() || q), createComputed(mapArray(Z, (h, K) => {
|
|
54
|
+
let J = createMemo(() => Q()[K() - 1]?.[0]() || q), X = mergeProps$1(J, toReactive(mapValues(h.rewriteProps || {}, (h) => useMemo(() => h(J(), { store: Y })))));
|
|
55
|
+
Q()[K()][1](X);
|
|
56
56
|
})), onMount(() => {
|
|
57
|
-
createEffect(mapArray(Z, (h) => h.onMount?.(
|
|
57
|
+
createEffect(mapArray(Z, (h) => h.onMount?.(Y)));
|
|
58
58
|
});
|
|
59
59
|
let $ = createMutable({
|
|
60
|
-
props:
|
|
61
|
-
store:
|
|
60
|
+
props: Y.props,
|
|
61
|
+
store: Y
|
|
62
62
|
});
|
|
63
|
-
return window.store =
|
|
63
|
+
return window.store = Y, window.ctx = $, createComponent(Ctx.Provider, {
|
|
64
64
|
value: $,
|
|
65
65
|
get children() {
|
|
66
66
|
return createComponent($.props.Table, { get children() {
|
|
@@ -185,7 +185,8 @@ function BasePlugin() {
|
|
|
185
185
|
trs: [],
|
|
186
186
|
trSizes: [],
|
|
187
187
|
internal: Symbol("internal"),
|
|
188
|
-
raw:
|
|
188
|
+
raw: "__raw",
|
|
189
|
+
ID: "__ID"
|
|
189
190
|
};
|
|
190
191
|
},
|
|
191
192
|
rewriteProps: {
|
|
@@ -336,8 +337,8 @@ var IndexPlugin = {
|
|
|
336
337
|
rewriteProps: { columns: ({ columns: h }, { store: W }) => (h = h.map((h, K) => ({
|
|
337
338
|
...h,
|
|
338
339
|
...G?.[K],
|
|
339
|
-
[W.
|
|
340
|
-
})), untrack(() => batch(() => reconcile(h, { key: W.
|
|
340
|
+
[W.ID]: h[W.ID] ??= Symbol()
|
|
341
|
+
})), untrack(() => batch(() => reconcile(h, { key: W.ID })(W.__fit_col_width__cols ??= [])))) }
|
|
341
342
|
};
|
|
342
343
|
};
|
|
343
344
|
const ScrollPlugin = {
|
|
@@ -5,22 +5,25 @@ import { combineProps } from "@solid-primitives/props";
|
|
|
5
5
|
var _tmpl$ = /* @__PURE__ */ template("<div class=area>"), inrange = (e, i, a) => e <= a && e >= i;
|
|
6
6
|
const CellSelectionPlugin = {
|
|
7
7
|
name: "cell-selection",
|
|
8
|
-
store: () => ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
store: (e) => ({
|
|
9
|
+
selected: {
|
|
10
|
+
start: [],
|
|
11
|
+
end: []
|
|
12
|
+
},
|
|
13
|
+
cellSelectionRect: () => {
|
|
14
|
+
let { start: i, end: a } = e.selected, o = [i[0], a[0]].sort((e, i) => e - i), s = [i[1], a[1]].sort((e, i) => e - i);
|
|
15
|
+
return {
|
|
16
|
+
xs: o,
|
|
17
|
+
ys: s
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}),
|
|
12
21
|
commands: (e) => ({ getAreaRows() {
|
|
13
22
|
let { start: i, end: a } = e.selected, [o, s] = [i[1], a[1]].sort((e, i) => e - i);
|
|
14
23
|
return e.props.data.slice(o, s + 1);
|
|
15
24
|
} }),
|
|
16
25
|
rewriteProps: {
|
|
17
|
-
Table: ({ Table: a }, { store: o }) => (s) => (
|
|
18
|
-
let { start: e, end: i } = o.selected, a = [e[0], i[0]].sort((e, i) => e - i), s = [e[1], i[1]].sort((e, i) => e - i);
|
|
19
|
-
return {
|
|
20
|
-
xs: a,
|
|
21
|
-
ys: s
|
|
22
|
-
};
|
|
23
|
-
}), usePointerDrag(() => o.table, {
|
|
26
|
+
Table: ({ Table: a }, { store: o }) => (s) => (usePointerDrag(() => o.table, {
|
|
24
27
|
preventDefault: !1,
|
|
25
28
|
start(e, i, a) {
|
|
26
29
|
batch(() => {
|
|
@@ -73,7 +76,7 @@ const CellSelectionPlugin = {
|
|
|
73
76
|
Td: ({ Td: e }, { store: s }) => (c) => {
|
|
74
77
|
let u = createMemo(() => {
|
|
75
78
|
let e = "", { xs: i, ys: a } = s.cellSelectionRect(), o = inrange(c.x, i[0], i[1]), l = inrange(c.y, a[0], a[1]);
|
|
76
|
-
return o && l && (e += "range-selected ", c.x == i[0] && (e += "range-selected-l "), c.x == i[1] && (e += "range-selected-r "), c.y == a[0] && (e += "range-selected-t "), c.y == a[1] && (e += "range-selected-b ")), c.col.id == s.$index
|
|
79
|
+
return o && l && (e += "range-selected ", c.x == i[0] && (e += "range-selected-l "), c.x == i[1] && (e += "range-selected-r "), c.y == a[0] && (e += "range-selected-t "), c.y == a[1] && (e += "range-selected-b ")), c.col.id == s.$index?.id && l && (e += "row-range-highlight "), e;
|
|
77
80
|
}), d = combineProps(c, {
|
|
78
81
|
get class() {
|
|
79
82
|
return u();
|
|
@@ -2,46 +2,54 @@ import { useSort } from "../hooks/useSort.js";
|
|
|
2
2
|
import { delay } from "es-toolkit";
|
|
3
3
|
import { isMatch } from "es-toolkit/compat";
|
|
4
4
|
const DragPlugin = {
|
|
5
|
+
name: "drag",
|
|
5
6
|
rewriteProps: {
|
|
6
7
|
colDrag: ({ colDrag: e = !1 }) => e,
|
|
7
8
|
rowDrag: ({ rowDrag: e = !1 }) => e
|
|
8
9
|
},
|
|
9
10
|
onMount(r) {
|
|
10
|
-
let
|
|
11
|
+
let o = useSort(() => r.scroll_el, {
|
|
11
12
|
get enable() {
|
|
12
13
|
return r.props?.colDrag;
|
|
13
14
|
},
|
|
14
15
|
guideLine: { class: "col__guide-line" },
|
|
15
16
|
draggable: (e) => ((i, a) => e.tagName == "TH" && isMatch(r.selected, { start: [i, 0] }) && !r.props?.columns[i][r.internal] && r.thead.contains(e) && delay(300).then(() => !0))(+e.getAttribute("x"), +e.getAttribute("y")),
|
|
16
17
|
dragover: (e) => e.tagName == "THEAD",
|
|
17
|
-
children: (e) => [...
|
|
18
|
-
dragend:
|
|
19
|
-
}),
|
|
18
|
+
children: (e) => [...o.drag.parentElement.children].filter((e) => !r.props?.columns[e.getAttribute("x")][r.internal]),
|
|
19
|
+
dragend: c
|
|
20
|
+
}), s = useSort(() => r.scroll_el, {
|
|
20
21
|
get enable() {
|
|
21
22
|
return r.props?.rowDrag;
|
|
22
23
|
},
|
|
23
24
|
guideLine: { class: "row__guide-line" },
|
|
24
25
|
draggable: (e) => ((i, a) => e.tagName == "TD" && isMatch(r.selected, { start: [0, a] }) && i == 0 && !r.props?.data[a][r.internal] && r.tbody.contains(e) && delay(300).then(() => !0))(+e.getAttribute("x"), +e.getAttribute("y")),
|
|
25
26
|
dragover: (e) => e.tagName == "TBODY",
|
|
26
|
-
children: (e) => [...
|
|
27
|
-
dragend:
|
|
27
|
+
children: (e) => [...s.over.children].filter((e) => !r.props.data[e.getAttribute("y")][r.internal]),
|
|
28
|
+
dragend: l
|
|
28
29
|
});
|
|
29
|
-
async function
|
|
30
|
-
if (
|
|
31
|
-
let [e, t] = [r.props.columns, [...r.rawProps.columns || []]], n = (
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
async function c() {
|
|
31
|
+
if (o.drag == o.rel) return;
|
|
32
|
+
let [e, t] = [r.props.columns, [...r.rawProps.columns || []]], n = getRawCol(r, e[o.drag.getAttribute("x")]), s = getRawCol(r, e[o.rel.getAttribute("x")]);
|
|
33
|
+
if (!n || !s) return;
|
|
34
|
+
let c = t.indexOf(n), l = t.indexOf(s);
|
|
35
|
+
t[c].fixed = t[l].fixed, t.splice(l - (c > l ? 0 : 1) + (o.type == "before" ? 0 : 1), 0, t.splice(c, 1)[0]), r.props.onColumnsChange?.(t), await Promise.resolve();
|
|
36
|
+
let u = r.props.columns.findIndex((e) => colEq(r, e, n));
|
|
37
|
+
u < 0 || (r.selected.start[0] = r.selected.end[0] = u);
|
|
36
38
|
}
|
|
37
|
-
async function
|
|
38
|
-
if (
|
|
39
|
-
let [e, t] = [r.props.data, [...r.rawProps.data || []]], n = ((e) => e[r.raw] ?? e)(e[
|
|
40
|
-
if (
|
|
41
|
-
t.splice(
|
|
39
|
+
async function l() {
|
|
40
|
+
if (s.drag == s.rel) return;
|
|
41
|
+
let [e, t] = [r.props.data, [...r.rawProps.data || []]], n = ((e) => e[r.raw] ?? e)(e[s.drag.getAttribute("y")]), i = ((e) => e[r.raw] ?? e)(e[s.rel.getAttribute("y")]), a = t.indexOf(n), o = t.indexOf(i);
|
|
42
|
+
if (a < 0 || o < 0) return;
|
|
43
|
+
t.splice(o - (a > o ? 0 : 1) + (s.type == "before" ? 0 : 1), 0, t.splice(a, 1)[0]), r.props.onDataChange?.(t), await Promise.resolve();
|
|
42
44
|
let c = r.props.data.findIndex((e) => e == n || e[r.raw] == n);
|
|
43
45
|
c < 0 || (r.selected.start[1] = r.selected.end[1] = c);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
};
|
|
49
|
+
function getRawCol(e, t) {
|
|
50
|
+
return e.rawProps.columns?.find((n) => colEq(e, n, t));
|
|
51
|
+
}
|
|
52
|
+
function colEq({ ID: e }, t, n) {
|
|
53
|
+
return t == n || t.id && n.id && t.id === n.id || t[e] && n[e] && t[e] === n[e];
|
|
54
|
+
}
|
|
47
55
|
export { DragPlugin };
|
|
@@ -9,38 +9,38 @@ function maxDepth(e) {
|
|
|
9
9
|
for (let n of e) n.children?.length && (t = Math.max(t, maxDepth(n.children)));
|
|
10
10
|
return t + 1;
|
|
11
11
|
}
|
|
12
|
-
function flatLeaves(e, t = []) {
|
|
13
|
-
for (let
|
|
12
|
+
function flatLeaves(e, t = [], n) {
|
|
13
|
+
for (let r of e) r[n.ID] ??= Symbol(), r.children?.length ? flatLeaves(r.children, t, n) : t.push(r);
|
|
14
14
|
return t;
|
|
15
15
|
}
|
|
16
16
|
function buildFlatGrid(e, t, n, r, i, a) {
|
|
17
17
|
let o = n.length, s = Array.from({ length: t }, () => Array(o).fill(null)), c = 0;
|
|
18
|
-
function l(e,
|
|
19
|
-
for (let
|
|
20
|
-
let e = !!
|
|
21
|
-
if (
|
|
18
|
+
function l(e, o) {
|
|
19
|
+
for (let d of e) {
|
|
20
|
+
let e = !!d.children?.length, f = leafCount(d), p = e ? 1 : t - o, m = e ? i[c] : d, h = r.get(m[a.ID]);
|
|
21
|
+
if (h == null) {
|
|
22
22
|
e || c++;
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
25
|
-
s[
|
|
25
|
+
s[o][h] = {
|
|
26
26
|
kind: "anchor",
|
|
27
|
-
anchorCol:
|
|
28
|
-
colspan:
|
|
29
|
-
rowspan:
|
|
27
|
+
anchorCol: d,
|
|
28
|
+
colspan: f,
|
|
29
|
+
rowspan: p
|
|
30
30
|
};
|
|
31
|
-
for (let e = 1; e <
|
|
31
|
+
for (let e = 1; e < f; e++) s[o][h + e] = {
|
|
32
32
|
kind: "colspan-hidden",
|
|
33
|
-
anchorCol:
|
|
34
|
-
colspan:
|
|
35
|
-
rowspan:
|
|
33
|
+
anchorCol: d,
|
|
34
|
+
colspan: f,
|
|
35
|
+
rowspan: p
|
|
36
36
|
};
|
|
37
|
-
for (let e = 1; e <
|
|
37
|
+
for (let e = 1; e < p; e++) for (let t = 0; t < f; t++) s[o + e][h + t] = {
|
|
38
38
|
kind: "rowspan-hidden",
|
|
39
|
-
anchorCol: n[
|
|
39
|
+
anchorCol: n[h + t],
|
|
40
40
|
colspan: 1,
|
|
41
41
|
rowspan: 1
|
|
42
42
|
};
|
|
43
|
-
e ? l(
|
|
43
|
+
e ? l(d.children, o + 1) : c++;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
c = 0, l(e, 0);
|
|
@@ -69,32 +69,32 @@ const HeaderGroupPlugin = {
|
|
|
69
69
|
store: (e) => ({ _headerGroupAnchors(t, n) {
|
|
70
70
|
let r = e.rawProps.columns || [];
|
|
71
71
|
if (!r.some((e) => e.children?.length) || maxDepth(r) <= 1) return [];
|
|
72
|
-
let i = e.props.columns || [], a = flatLeaves(r), o = /* @__PURE__ */ new Map();
|
|
73
|
-
for (let t = 0; t < i.length; t++) o.set(i[t][e.
|
|
72
|
+
let i = e.props.columns || [], a = flatLeaves(r, [], e), o = /* @__PURE__ */ new Map();
|
|
73
|
+
for (let t = 0; t < i.length; t++) o.set(i[t][e.ID], t);
|
|
74
74
|
let s = [], c = 0;
|
|
75
|
-
function l(
|
|
76
|
-
for (let
|
|
77
|
-
let
|
|
78
|
-
if (
|
|
79
|
-
let
|
|
80
|
-
if (
|
|
81
|
-
let
|
|
82
|
-
|
|
75
|
+
function l(r) {
|
|
76
|
+
for (let i of r) if (i.children?.length) {
|
|
77
|
+
let r = leafCount(i), d = a[c];
|
|
78
|
+
if (d) {
|
|
79
|
+
let i = o.get(d[e.ID]);
|
|
80
|
+
if (i != null) {
|
|
81
|
+
let e = i + r - 1;
|
|
82
|
+
i <= n && e >= t && s.push(i);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
l(
|
|
85
|
+
l(i.children);
|
|
86
86
|
} else c++;
|
|
87
87
|
}
|
|
88
88
|
return l(r), s;
|
|
89
89
|
} }),
|
|
90
90
|
rewriteProps: {
|
|
91
|
-
columns: ({ columns: e }) => flatLeaves(e),
|
|
91
|
+
columns: ({ columns: e }, { store: t }) => flatLeaves(e, [], t),
|
|
92
92
|
Thead: ({ Thead: u }, { store: m }) => (h) => {
|
|
93
93
|
let { props: g } = useContext(Ctx), _ = createMemo(() => {
|
|
94
94
|
let e = m.rawProps.columns || [], t = maxDepth(e);
|
|
95
95
|
if (t <= 1) return null;
|
|
96
|
-
let n = g.columns || [], r = flatLeaves(e), i = /* @__PURE__ */ new Map();
|
|
97
|
-
for (let e = 0; e < n.length; e++) i.set(n[e][m.
|
|
96
|
+
let n = g.columns || [], r = flatLeaves(e, [], m), i = /* @__PURE__ */ new Map();
|
|
97
|
+
for (let e = 0; e < n.length; e++) i.set(n[e][m.ID], e);
|
|
98
98
|
return {
|
|
99
99
|
grid: buildFlatGrid(e, t, n, i, r, m),
|
|
100
100
|
depth: t
|
|
@@ -14,7 +14,7 @@ var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW =
|
|
|
14
14
|
p.stopPropagation();
|
|
15
15
|
let _ = e.x, { min: b, max: x } = g.resizable.col, S = y.parentElement, C = S.offsetWidth;
|
|
16
16
|
m((p, { ox: m }) => v[COL][e.x] = clamp(C + m, b, x)), h(() => {
|
|
17
|
-
let e = g.columns[_], p = [...v.rawProps.columns || []], m = p.
|
|
17
|
+
let e = g.columns[_], p = [...v.rawProps.columns || []], m = p.findIndex((p) => p[v.ID] === e[v.ID]);
|
|
18
18
|
m > -1 && (p[m] = {
|
|
19
19
|
...p[m],
|
|
20
20
|
width: S.offsetWidth
|
|
@@ -31,7 +31,7 @@ var _tmpl$ = /* @__PURE__ */ template("<div>"), COL = Symbol("col_size"), ROW =
|
|
|
31
31
|
let _ = e.y, { min: b, max: x } = g.resizable.row, S = y.parentElement.offsetHeight;
|
|
32
32
|
m((p, { oy: m }) => v[ROW][e.y] = clamp(S + m, b, x)), h(() => {
|
|
33
33
|
let e = g.data[_];
|
|
34
|
-
[...v.rawProps.data || []].
|
|
34
|
+
[...v.rawProps.data || []].findIndex((p) => p[v.ID] === e[v.ID]);
|
|
35
35
|
});
|
|
36
36
|
} }), createEventListener(() => y, "dblclick", () => e.data[COL] = void 0), (() => {
|
|
37
37
|
var p = _tmpl$(), m = y;
|
|
@@ -60,16 +60,14 @@ const ResizePlugin = {
|
|
|
60
60
|
}),
|
|
61
61
|
columns: ({ columns: e }, { store: p }) => (e = e.map((e, m) => ({
|
|
62
62
|
...e,
|
|
63
|
-
[p.
|
|
63
|
+
[p.ID]: e[p.ID] ??= Symbol()
|
|
64
64
|
})), e = e.map((e) => e.resizable === void 0 ? {
|
|
65
65
|
...e,
|
|
66
|
-
resizable: p.props?.resizable?.col.enable
|
|
67
|
-
[p.raw]: e[p.raw] ?? e
|
|
66
|
+
resizable: p.props?.resizable?.col.enable
|
|
68
67
|
} : e), e = e.map((e, m) => p[COL][m] ? {
|
|
69
68
|
...e,
|
|
70
|
-
width: p[COL][m]
|
|
71
|
-
|
|
72
|
-
} : e), untrack(() => batch(() => reconcile(e, { key: p.raw })(p.__resize__cols ??= [])))),
|
|
69
|
+
width: p[COL][m]
|
|
70
|
+
} : e), untrack(() => batch(() => reconcile(e, { key: p.ID })(p.__resize__cols ??= [])))),
|
|
73
71
|
Th: ({ Th: e }, { store: p }) => (p) => (p = combineProps({ class: "relative" }, p), createComponent(e, mergeProps(p, { get children() {
|
|
74
72
|
return [memo(() => p.children), memo(() => memo(() => !!p.col.resizable)() && createComponent(ColHandle, p))];
|
|
75
73
|
} }))),
|
|
@@ -6,6 +6,7 @@ import { groupBy, zipObject } from "es-toolkit";
|
|
|
6
6
|
import { findLast } from "es-toolkit/compat";
|
|
7
7
|
var _tmpl$ = /* @__PURE__ */ template("<div class=\"flex items-center\">"), pathKey = (e) => e.join("\0");
|
|
8
8
|
const RowGroupPlugin = {
|
|
9
|
+
name: "row-group",
|
|
9
10
|
priority: -Infinity,
|
|
10
11
|
store: (e) => ({ rowGroup: {
|
|
11
12
|
expandKeys: {},
|