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.
@@ -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 useMemoState(fn: any): {};
39
+ export declare function createShallowState(state: any): any;
40
+ export declare function useMemoState(fn: any): any;
40
41
  export {};
@@ -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, L) {
13
- L = mergeProps({ preventDefault: !0 }, L), createPointerListeners({
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
- L.preventDefault && h.preventDefault();
18
- let [R, z] = [h.x, h.y], B, V;
19
- L.start?.(h, (h) => B = h, (h) => V = h), createRoot((L) => {
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 [L, V] = [h.x - R, h.y - z];
24
- B?.(h, {
25
- sx: R,
26
- sy: z,
27
- ox: L,
28
- oy: V
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
- V?.(h), L(), B = void 0, V = void 0;
32
+ W?.(h), B(), U = void 0, W = void 0;
33
33
  }
34
- }), createEventListenerMap(document, { drop: L });
34
+ }), createEventListenerMap(document, { drop: B });
35
35
  });
36
36
  }
37
37
  });
38
38
  }
39
- function model(h, L) {
40
- let [R, z] = L();
41
- createRenderEffect(() => h.value = R()), h.addEventListener("input", (h) => z(h.target.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, L) {
44
- return [() => h[L], (R) => h[L] = R];
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" || R() && !h, L = (h) => h ? "dark" : "light", R = () => window.matchMedia("(prefers-color-scheme: dark)").matches, z = makePersisted(createSignal(R()), {
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: L,
51
+ serialize: B,
52
52
  deserialize: h
53
53
  });
54
- return createEffect(() => document.documentElement.classList[z[0]() ? "add" : "remove"]("dark")), createEffect(() => window.dispatchEvent(new StorageEvent("storage", {
54
+ return createEffect(() => document.documentElement.classList[H[0]() ? "add" : "remove"]("dark")), createEffect(() => window.dispatchEvent(new StorageEvent("storage", {
55
55
  key: "color-schema",
56
- newValue: L(z[0]())
57
- }))), z;
56
+ newValue: B(H[0]())
57
+ }))), H;
58
58
  }
59
- function useMemoAsync(h, L) {
60
- let R = Symbol(), [B, V] = createSignal(L);
59
+ function useMemoAsync(h, B) {
60
+ let V = Symbol(), [U, W] = createSignal(B);
61
61
  return createComputed(async () => {
62
- let L = h(untrack(B)), z = L instanceof Promise ? await new Promise((h) => {
63
- L.then(h), onCleanup(() => h(R));
64
- }) : L;
65
- z == R || V(() => z);
66
- }), B;
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, L) {
69
- let R = createSignal(isFunction(h) ? void 0 : h), B = (h) => {
70
- let R = L?.before?.(h);
71
- return isPromise(R) ? R.then((L) => L === void 0 ? h : L) : R ?? h;
72
- }, V = useMemoAsync(() => B(R[0]()));
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 L = useMemoAsync(() => B(h()));
75
- createComputed(() => R[1](L()));
74
+ let B = useMemoAsync(() => U(h()));
75
+ createComputed(() => V[1](B()));
76
76
  }
77
- return [V, R[1]];
77
+ return [W, V[1]];
78
78
  }
79
79
  var $MEMO = Symbol();
80
- function toReactive(R) {
81
- let z = () => unFn(R), B = () => !0, V = (h) => ((h) => typeof h == "function" && $MEMO in h ? h() : h)(z()[h]);
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, R, B) => R == $PROXY || R == $RAW ? B : ((h) => typeof h == "function" && $MEMO in h ? h() : h)(z()[R]),
84
- set: B,
85
- defineProperty: (h, L, R) => Object.defineProperty(z(), L, R),
86
- deleteProperty: B,
87
- getPrototypeOf: () => Object.getPrototypeOf(z()),
88
- has: (h, R) => R == $PROXY || R in z(),
89
- ownKeys: (h) => Object.keys(z()),
90
- getOwnPropertyDescriptor: (h, L) => ({
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 V(L);
94
+ return W(B);
95
95
  },
96
- set: B
96
+ set: U
97
97
  })
98
98
  });
99
99
  }
100
100
  function useMemo(h) {
101
- let L = createMemo(h);
102
- return L[$MEMO] = 1, L;
101
+ let B = createMemo(h);
102
+ return B[$MEMO] = 1, B;
103
103
  }
104
104
  function useHover(h) {
105
- let [L, R] = createSignal(!1);
106
- return createEventListener(h, "pointerenter", () => R(!0)), createEventListener(h, "pointerleave", () => R(!1)), L;
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 [L, R] = createSignal(!1);
110
- return createEventListener(h, "pointerdown", () => R(!0)), createEventListener(document.body, "pointerup", () => R(!1)), L;
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 [L, R] = createSignal(!1), z = () => castArray(access(h));
114
- return createEventListener(() => z().map((h) => h?.getRootNode()), "click", (h) => R(z().some((L) => L?.contains(h.target)))), L;
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, L, R) {
117
- let z = createSignal(R());
118
- return createMutationObserver(h, L, (h) => z[1](R())), z[0];
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, L) {
121
- createEventListener(h, "keydown", createKeybindingsHandler({ ...mapValues(L, (h) => (L) => {
122
- L.preventDefault(), h(L);
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, L]) {
126
- let R = 1, z = createMutable({
125
+ function useHistory([h, B]) {
126
+ let V = 1, H = createMutable({
127
127
  index: -1,
128
128
  history: []
129
- }), B = () => (z.index = 0, z.history = [h()]), V = () => z.index > 0, H = () => z.index < z.history.length - 1;
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 (!R) return R = 1;
133
- H() && (z.history = z.history.slice(0, z.index + 1)), z.history[++z.index] = h;
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: () => V() && ((R = 0) || L(z.history[--z.index])),
137
- redo: () => H() && ((R = 0) || L(z.history[++z.index])),
138
- clear: B,
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 z.index;
140
+ return H.index;
141
141
  },
142
142
  get history() {
143
- return z.history;
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 L = createMutable({});
175
+ let B = createShallowState({});
149
176
  return createComputed(() => {
150
- let z = h();
177
+ let H = { ...h() };
151
178
  untrack(() => batch(() => {
152
- for (let h in L) h in z || delete L[h];
153
- Object.assign(L, z);
179
+ for (let h in B) h in H || delete B[h];
180
+ Object.assign(B, H);
154
181
  }));
155
- }), L;
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
@@ -138,6 +138,7 @@ export interface TableStore extends Obj {
138
138
  raw: symbol;
139
139
  props: TableProps2;
140
140
  rawProps: TableProps;
141
+ ID: string;
141
142
  plugins: Plugin[];
142
143
  }
143
144
  export declare const Intable: (props: TableProps) => JSX.Element;
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 = (K) => {
33
- K = mergeProps$1({ rowKey: "id" }, K);
34
- let q = getOwner(), J = createMutable({
32
+ }), Intable = (q) => {
33
+ q = mergeProps$1({ rowKey: "id" }, q);
34
+ let J = getOwner(), Y = createMutable({
35
35
  get rawProps() {
36
- return K;
36
+ return q;
37
37
  },
38
38
  get plugins() {
39
39
  return Z();
40
40
  }
41
- }), Y = memoize((W) => runWithOwner(q, () => unFn(W, J))), Z = createMemo(() => [
41
+ }), X = memoize((W) => runWithOwner(J, () => unFn(W, Y))), Z = createMemo(() => [
42
42
  ...defaultsPlugins,
43
- ...K.plugins || [],
43
+ ...q.plugins || [],
44
44
  RenderPlugin
45
- ].map(Y).sort((h, W) => (W.priority || 0) - (h.priority || 0)));
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(q, () => {
49
- W.forEach((h) => Object.assign(J, h.store?.(J)));
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
- J.props = toReactive(createMemo(() => Q()[Q().length - 1][0]() || K)), createComputed(mapArray(Z, (h, q) => {
54
- let Y = createMemo(() => Q()[q() - 1]?.[0]() || K), X = mergeProps$1(Y, toReactive(mapValues(h.rewriteProps || {}, (h) => useMemo(() => h(Y(), { store: J })))));
55
- Q()[q()][1](X);
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?.(J)));
57
+ createEffect(mapArray(Z, (h) => h.onMount?.(Y)));
58
58
  });
59
59
  let $ = createMutable({
60
- props: J.props,
61
- store: J
60
+ props: Y.props,
61
+ store: Y
62
62
  });
63
- return window.store = J, window.ctx = $, createComponent(Ctx.Provider, {
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: Symbol("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.raw]: h[W.raw] ?? h
340
- })), untrack(() => batch(() => reconcile(h, { key: W.raw })(W.__fit_col_width__cols ??= [])))) }
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: () => ({ selected: {
9
- start: [],
10
- end: []
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) => (o.cellSelectionRect ??= createMemo(() => {
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.id && l && (e += "row-range-highlight "), e;
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();
@@ -7,6 +7,7 @@ import { v4 } from "uuid";
7
7
  import { diffArrays } from "diff";
8
8
  var DEL = Symbol("del"), NEW = Symbol("new");
9
9
  const DiffPlugin = {
10
+ name: "diff",
10
11
  priority: Infinity,
11
12
  store: (e) => {
12
13
  let a = e.rawProps.data || [];
@@ -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 i = useSort(() => r.scroll_el, {
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) => [...i.drag.parentElement.children].filter((e) => !r.props?.columns[e.getAttribute("x")][r.internal]),
18
- dragend: o
19
- }), a = useSort(() => r.scroll_el, {
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) => [...a.over.children].filter((e) => !r.props.data[e.getAttribute("y")][r.internal]),
27
- dragend: s
27
+ children: (e) => [...s.over.children].filter((e) => !r.props.data[e.getAttribute("y")][r.internal]),
28
+ dragend: l
28
29
  });
29
- async function o() {
30
- if (i.drag == i.rel) return;
31
- let [e, t] = [r.props.columns, [...r.rawProps.columns || []]], n = ((e) => e[r.raw] ?? e)(e[i.drag.getAttribute("x")]), a = ((e) => e[r.raw] ?? e)(e[i.rel.getAttribute("x")]), o = t.indexOf(n), s = t.indexOf(a);
32
- if (o < 0 || s < 0) return;
33
- t[o].fixed = t[s].fixed, t.splice(s - (o > s ? 0 : 1) + (i.type == "before" ? 0 : 1), 0, t.splice(o, 1)[0]), r.props.onColumnsChange?.(t), await Promise.resolve();
34
- let c = r.props.columns.findIndex((e) => e == n || e[r.raw] == n);
35
- c < 0 || (r.selected.start[0] = r.selected.end[0] = c);
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 s() {
38
- if (a.drag == a.rel) return;
39
- let [e, t] = [r.props.data, [...r.rawProps.data || []]], n = ((e) => e[r.raw] ?? e)(e[a.drag.getAttribute("y")]), i = ((e) => e[r.raw] ?? e)(e[a.rel.getAttribute("y")]), o = t.indexOf(n), s = t.indexOf(i);
40
- if (o < 0 || s < 0) return;
41
- t.splice(s - (o > s ? 0 : 1) + (a.type == "before" ? 0 : 1), 0, t.splice(o, 1)[0]), r.props.onDataChange?.(t), await Promise.resolve();
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 n of e) n.children?.length ? flatLeaves(n.children, t) : t.push(n);
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, a) {
19
- for (let o of e) {
20
- let e = !!o.children?.length, d = leafCount(o), f = e ? 1 : t - a, p = e ? i[c] : o, m = r.get(p);
21
- if (m == null) {
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[a][m] = {
25
+ s[o][h] = {
26
26
  kind: "anchor",
27
- anchorCol: o,
28
- colspan: d,
29
- rowspan: f
27
+ anchorCol: d,
28
+ colspan: f,
29
+ rowspan: p
30
30
  };
31
- for (let e = 1; e < d; e++) s[a][m + e] = {
31
+ for (let e = 1; e < f; e++) s[o][h + e] = {
32
32
  kind: "colspan-hidden",
33
- anchorCol: o,
34
- colspan: d,
35
- rowspan: f
33
+ anchorCol: d,
34
+ colspan: f,
35
+ rowspan: p
36
36
  };
37
- for (let e = 1; e < f; e++) for (let t = 0; t < d; t++) s[a + e][m + t] = {
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[m + t],
39
+ anchorCol: n[h + t],
40
40
  colspan: 1,
41
41
  rowspan: 1
42
42
  };
43
- e ? l(o.children, a + 1) : c++;
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.raw] || i[t], t);
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(e) {
76
- for (let r of e) if (r.children?.length) {
77
- let e = leafCount(r), i = a[c];
78
- if (i) {
79
- let r = o.get(i);
80
- if (r != null) {
81
- let i = r + e - 1;
82
- r <= n && i >= t && s.push(r);
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(r.children);
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.raw] || n[e], e);
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.indexOf(e[v.raw] ?? e);
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 || []].indexOf(e[v.raw] ?? e);
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.raw]: e[p.raw] ?? e
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
- [p.raw]: e[p.raw] ?? e
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: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intable",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [