@toolbox-web/grid-react 0.18.4 → 0.18.5

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/index.js CHANGED
@@ -1,37 +1,37 @@
1
- import { jsx as E, Fragment as Re } from "react/jsx-runtime";
2
- import { DataGridElement as ve } from "@toolbox-web/grid";
3
- import { createContext as pe, useContext as z, useRef as P, useCallback as h, useEffect as w, forwardRef as Ce, useMemo as G, useImperativeHandle as be, Children as Ee, isValidElement as Se, useState as de } from "react";
4
- import { flushSync as R } from "react-dom";
5
- import { createRoot as C } from "react-dom/client";
6
- import { createPluginsFromFeatures as Pe } from "@toolbox-web/grid/features/registry";
7
- import { G as xe } from "./chunks/grid-element-context-BU3WvNtM.js";
8
- function De(n) {
1
+ import { jsx as E, Fragment as ie, jsxs as Se } from "react/jsx-runtime";
2
+ import { DataGridElement as ke } from "@toolbox-web/grid";
3
+ import { createContext as ve, useContext as z, useRef as b, useCallback as C, useEffect as R, forwardRef as Ce, useReducer as xe, useImperativeHandle as Re, useMemo as x, useLayoutEffect as Ge, Children as De, isValidElement as Ae, useState as fe } from "react";
4
+ import { a as w, r as _, s as ge } from "./chunks/portal-bridge-B0mjqzak.js";
5
+ import { createPortal as Te, flushSync as pe } from "react-dom";
6
+ import { createPluginsFromFeatures as Ne } from "@toolbox-web/grid/features/registry";
7
+ import { G as Ke } from "./chunks/grid-element-context-BU3WvNtM.js";
8
+ function Ie(n) {
9
9
  return n.charAt(0).toUpperCase() + n.slice(1);
10
10
  }
11
- function ue(n) {
12
- return n.toLowerCase() === "id" ? "ID" : n.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").split(" ").filter(Boolean).map(De).join(" ");
11
+ function me(n) {
12
+ return n.toLowerCase() === "id" ? "ID" : n.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").split(" ").filter(Boolean).map(Ie).join(" ");
13
13
  }
14
- const Ge = /* @__PURE__ */ new Set(["string", "number", "boolean", "date", "datetime", "currency"]);
15
- function Ae(n) {
16
- const t = n.lastIndexOf(":");
17
- if (t > 0) {
18
- const e = n.slice(t + 1).toLowerCase();
19
- if (Ge.has(e)) {
20
- const r = n.slice(0, t);
14
+ const Le = /* @__PURE__ */ new Set(["string", "number", "boolean", "date", "datetime", "currency"]);
15
+ function Fe(n) {
16
+ const e = n.lastIndexOf(":");
17
+ if (e > 0) {
18
+ const t = n.slice(e + 1).toLowerCase();
19
+ if (Le.has(t)) {
20
+ const r = n.slice(0, e);
21
21
  return {
22
22
  field: r,
23
- header: ue(r),
24
- type: e
23
+ header: me(r),
24
+ type: t
25
25
  };
26
26
  }
27
27
  }
28
28
  return {
29
29
  field: n,
30
- header: ue(n)
30
+ header: me(n)
31
31
  };
32
32
  }
33
- function Ie(n) {
34
- return n.map((t) => typeof t == "string" ? Ae(t) : t);
33
+ function Me(n) {
34
+ return n.map((e) => typeof e == "string" ? Fe(e) : e);
35
35
  }
36
36
  const U = {
37
37
  onCellClick: "cell-click",
@@ -59,265 +59,285 @@ const U = {
59
59
  onExportComplete: "export-complete",
60
60
  onPrintStart: "print-start",
61
61
  onPrintComplete: "print-complete"
62
- }, oe = pe(null), Ve = ({ icons: n, children: t }) => /* @__PURE__ */ E(oe.Provider, { value: n, children: t });
63
- function at() {
64
- return z(oe);
62
+ }, se = ve(null), qe = ({ icons: n, children: e }) => /* @__PURE__ */ E(se.Provider, { value: n, children: e });
63
+ function yt() {
64
+ return z(se);
65
65
  }
66
- const Ne = oe, Z = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new Map();
67
- function me(n) {
68
- const t = n.querySelector("tbw-grid-responsive-card");
69
- if (t) {
70
- const r = Z.get(t);
66
+ const He = se, Q = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new Map();
67
+ function we(n) {
68
+ const e = n.querySelector("tbw-grid-responsive-card");
69
+ if (e) {
70
+ const r = Q.get(e);
71
71
  if (r) return r;
72
72
  }
73
- const e = n.id || n.getAttribute("data-grid-id");
74
- if (e)
75
- return Q.get(e);
73
+ const t = n.id || n.getAttribute("data-grid-id");
74
+ if (t)
75
+ return X.get(t);
76
76
  }
77
- function Le(n) {
78
- const { children: t, cardRowHeight: e = "auto" } = n, r = P(null), o = h(
79
- (l) => {
80
- if (r.current = l, !l) return;
81
- Z.set(l, t);
82
- const i = l.closest("tbw-grid");
77
+ function Oe(n) {
78
+ const { children: e, cardRowHeight: t = "auto" } = n, r = b(null), o = C(
79
+ (c) => {
80
+ if (r.current = c, !c) return;
81
+ Q.set(c, e);
82
+ const i = c.closest("tbw-grid");
83
83
  if (i) {
84
- const f = i.id || i.getAttribute("data-grid-id");
85
- f && Q.set(f, t);
84
+ const g = i.id || i.getAttribute("data-grid-id");
85
+ g && X.set(g, e);
86
86
  }
87
87
  },
88
- [t]
88
+ [e]
89
89
  );
90
- w(() => () => {
91
- const l = r.current;
92
- if (l) {
93
- Z.delete(l);
94
- const i = l.closest("tbw-grid");
90
+ R(() => () => {
91
+ const c = r.current;
92
+ if (c) {
93
+ Q.delete(c);
94
+ const i = c.closest("tbw-grid");
95
95
  if (i) {
96
- const f = i.id || i.getAttribute("data-grid-id");
97
- f && Q.delete(f);
96
+ const g = i.id || i.getAttribute("data-grid-id");
97
+ g && X.delete(g);
98
98
  }
99
99
  }
100
100
  }, []);
101
- const a = e === "auto" ? "auto" : String(e);
102
- return /* @__PURE__ */ E("tbw-grid-responsive-card", { ref: o, cardRowHeight: a });
101
+ const s = t === "auto" ? "auto" : String(t);
102
+ return /* @__PURE__ */ E("tbw-grid-responsive-card", { ref: o, cardRowHeight: s });
103
103
  }
104
- Le.displayName = "GridResponsiveCard";
105
- const $ = pe(null), Te = ({ defaults: n, children: t }) => /* @__PURE__ */ E($.Provider, { value: n, children: t });
106
- function lt() {
104
+ Oe.displayName = "GridResponsiveCard";
105
+ const $ = ve(null), je = ({ defaults: n, children: e }) => /* @__PURE__ */ E($.Provider, { value: n, children: e });
106
+ function ht() {
107
107
  return z($);
108
108
  }
109
- function dt(n) {
109
+ function vt(n) {
110
110
  return z($)?.[n];
111
111
  }
112
- const ke = $, K = /* @__PURE__ */ Symbol("reactProcessed"), I = [];
113
- function Fe(n) {
114
- for (let t = I.length - 1; t >= 0; t--) {
115
- const e = I[t];
116
- if (n.contains(e.container) && e.container.classList.contains("react-cell-editor")) {
117
- try {
118
- e.root.unmount();
119
- } catch {
112
+ const Be = $, _e = Ce(function(e, t) {
113
+ const r = b(/* @__PURE__ */ new Map()), [, o] = xe((m) => m + 1, 0), s = b(!1), c = b(0), i = () => {
114
+ s.current || (s.current = !0, queueMicrotask(() => {
115
+ s.current = !1, pe(o), g();
116
+ }));
117
+ }, g = () => {
118
+ c.current || (c.current = requestAnimationFrame(() => {
119
+ c.current = 0;
120
+ let m = !1;
121
+ for (const [v, P] of r.current)
122
+ P.container.isConnected || (r.current.delete(v), m = !0);
123
+ m && pe(o);
124
+ }));
125
+ };
126
+ Re(
127
+ t,
128
+ () => ({
129
+ renderPortal(m, v, P) {
130
+ r.current.set(m, { container: v, element: P }), i();
131
+ },
132
+ removePortal(m) {
133
+ r.current.delete(m) && i();
134
+ },
135
+ clear() {
136
+ r.current.size > 0 && (r.current.clear(), c.current && (cancelAnimationFrame(c.current), c.current = 0), i());
120
137
  }
121
- I.splice(t, 1);
122
- }
138
+ }),
139
+ // forceRender is stable (useReducer dispatch), refs are stable
140
+ // eslint-disable-next-line react-hooks/exhaustive-deps
141
+ []
142
+ );
143
+ const f = [];
144
+ for (const [m, { container: v, element: P }] of r.current)
145
+ f.push(Te(P, v, m));
146
+ return /* @__PURE__ */ E(ie, { children: f });
147
+ }), Y = /* @__PURE__ */ Symbol("reactProcessed"), D = [];
148
+ function ze(n) {
149
+ for (let e = D.length - 1; e >= 0; e--) {
150
+ const t = D[e];
151
+ n.contains(t.container) && t.container.classList.contains("react-cell-editor") && (_(t.key), D.splice(e, 1));
123
152
  }
124
153
  }
125
- function Me(n) {
126
- const t = /* @__PURE__ */ new WeakMap();
127
- return (e) => {
128
- const r = e.cellEl;
154
+ function $e(n) {
155
+ const e = /* @__PURE__ */ new WeakMap();
156
+ return (t) => {
157
+ const r = t.cellEl;
129
158
  if (r) {
130
- const l = t.get(r);
131
- if (l)
132
- return R(() => {
133
- l.root.render(n(e));
134
- }), l.container;
159
+ const c = e.get(r);
160
+ if (c)
161
+ return w(c.container, n(t), c.portalKey), c.container;
135
162
  }
136
163
  const o = document.createElement("div");
137
164
  o.className = "react-cell-renderer", o.style.display = "contents";
138
- const a = C(o);
139
- return R(() => {
140
- a.render(n(e));
141
- }), r && t.set(r, { root: a, container: o }), I.push({ root: a, container: o }), o;
165
+ const s = w(o, n(t));
166
+ return r && e.set(r, { portalKey: s, container: o }), D.push({ key: s, container: o }), o;
142
167
  };
143
168
  }
144
- function He(n) {
145
- return (t) => {
146
- const e = document.createElement("div");
147
- e.className = "react-cell-editor", e.style.display = "contents";
148
- const r = C(e);
149
- return R(() => {
150
- r.render(n(t));
151
- }), I.push({ root: r, container: e }), e;
169
+ function Ve(n) {
170
+ return (e) => {
171
+ const t = document.createElement("div");
172
+ t.className = "react-cell-editor", t.style.display = "contents";
173
+ const r = w(t, n(e));
174
+ return D.push({ key: r, container: t }), t;
152
175
  };
153
176
  }
154
- function Oe(n) {
155
- return (t) => {
156
- const e = document.createElement("div");
157
- e.className = "react-header-renderer", e.style.display = "contents";
158
- const r = C(e);
159
- return R(() => {
160
- r.render(n(t));
161
- }), I.push({ root: r, container: e }), e;
177
+ function We(n) {
178
+ return (e) => {
179
+ const t = document.createElement("div");
180
+ t.className = "react-header-renderer", t.style.display = "contents";
181
+ const r = w(t, n(e));
182
+ return D.push({ key: r, container: t }), t;
162
183
  };
163
184
  }
164
- function qe(n) {
165
- return (t) => {
166
- const e = document.createElement("div");
167
- e.className = "react-header-label-renderer", e.style.display = "contents";
168
- const r = C(e);
169
- return R(() => {
170
- r.render(n(t));
171
- }), I.push({ root: r, container: e }), e;
185
+ function Je(n) {
186
+ return (e) => {
187
+ const t = document.createElement("div");
188
+ t.className = "react-header-label-renderer", t.style.display = "contents";
189
+ const r = w(t, n(e));
190
+ return D.push({ key: r, container: t }), t;
172
191
  };
173
192
  }
174
- function Be(n) {
175
- return (t) => {
176
- const e = n(t);
177
- if (e instanceof HTMLElement || typeof e == "string")
178
- return e;
193
+ function Ue(n) {
194
+ return (e) => {
195
+ const t = n(e);
196
+ if (t instanceof HTMLElement || typeof t == "string")
197
+ return t;
179
198
  const r = document.createElement("div");
180
199
  r.className = "react-loading-renderer", r.style.display = "contents";
181
- const o = C(r);
182
- return R(() => {
183
- o.render(e);
184
- }), I.push({ root: o, container: r }), r;
200
+ const o = w(r, t);
201
+ return D.push({ key: o, container: r }), r;
185
202
  };
186
203
  }
187
- function ye(n) {
204
+ function Pe(n) {
188
205
  if (!n) return;
189
- if (n[K]) return n;
206
+ if (n[Y]) return n;
190
207
  if (n.loadingRenderer && typeof n.loadingRenderer == "function") {
191
208
  const r = n.loadingRenderer;
192
209
  n = {
193
210
  ...n,
194
- loadingRenderer: Be(r)
211
+ loadingRenderer: Ue(r)
195
212
  };
196
213
  }
197
214
  if (!n.columns) {
198
215
  const r = n;
199
- return r[K] = !0, r;
216
+ return r[Y] = !0, r;
200
217
  }
201
- const t = n.columns.map((r) => {
202
- const { renderer: o, editor: a, headerRenderer: l, headerLabelRenderer: i, ...f } = r, g = { ...f };
203
- return o && (g.renderer = Me(o)), a && (g.editor = He(a)), l && (g.headerRenderer = Oe(l)), i && (g.headerLabelRenderer = qe(i)), g;
204
- }), e = {
218
+ const e = n.columns.map((r) => {
219
+ const { renderer: o, editor: s, headerRenderer: c, headerLabelRenderer: i, ...g } = r, f = { ...g };
220
+ return o && (f.renderer = $e(o)), s && (f.editor = Ve(s)), c && (f.headerRenderer = We(c)), i && (f.headerLabelRenderer = Je(i)), f;
221
+ }), t = {
205
222
  ...n,
206
- columns: t
223
+ columns: e
207
224
  };
208
- return e[K] = !0, e;
225
+ return t[Y] = !0, t;
209
226
  }
210
- const X = /* @__PURE__ */ new WeakMap(), ee = /* @__PURE__ */ new Map();
211
- function je(n) {
212
- const t = n.querySelector("tbw-grid-detail");
213
- if (t) {
214
- const r = X.get(t);
227
+ const ee = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new Map();
228
+ function Ye(n) {
229
+ const e = n.querySelector("tbw-grid-detail");
230
+ if (e) {
231
+ const r = ee.get(e);
215
232
  if (r) return r;
216
233
  }
217
- const e = n.id || n.getAttribute("data-grid-id");
218
- if (e)
219
- return ee.get(e);
234
+ const t = n.id || n.getAttribute("data-grid-id");
235
+ if (t)
236
+ return te.get(t);
220
237
  }
221
- function _e(n) {
222
- const { children: t, showExpandColumn: e = !0, animation: r = "slide" } = n, o = P(null), a = h(
238
+ function Ze(n) {
239
+ const { children: e, showExpandColumn: t = !0, animation: r = "slide" } = n, o = b(null), s = C(
223
240
  (i) => {
224
241
  if (o.current = i, !i) return;
225
- X.set(i, t);
226
- const f = i.closest("tbw-grid");
227
- if (f) {
228
- const g = f.id || f.getAttribute("data-grid-id");
229
- g && ee.set(g, t);
242
+ ee.set(i, e);
243
+ const g = i.closest("tbw-grid");
244
+ if (g) {
245
+ const f = g.id || g.getAttribute("data-grid-id");
246
+ f && te.set(f, e);
230
247
  }
231
248
  },
232
- [t]
249
+ [e]
233
250
  );
234
- return w(() => () => {
251
+ return R(() => () => {
235
252
  const i = o.current;
236
253
  if (i) {
237
- X.delete(i);
238
- const f = i.closest("tbw-grid");
239
- if (f) {
240
- const v = f.id || f.getAttribute("data-grid-id");
241
- v && ee.delete(v);
254
+ ee.delete(i);
255
+ const g = i.closest("tbw-grid");
256
+ if (g) {
257
+ const m = g.id || g.getAttribute("data-grid-id");
258
+ m && te.delete(m);
242
259
  }
243
- const g = i.parentNode;
244
- g && g.contains(i);
260
+ const f = i.parentNode;
261
+ f && f.contains(i);
245
262
  }
246
263
  }, []), /* @__PURE__ */ E(
247
264
  "tbw-grid-detail",
248
265
  {
249
- ref: a,
250
- showExpandColumn: e ? void 0 : "false",
266
+ ref: s,
267
+ showExpandColumn: t ? void 0 : "false",
251
268
  animation: r === !1 ? "false" : r
252
269
  }
253
270
  );
254
271
  }
255
- _e.displayName = "GridDetailPanel";
256
- const te = /* @__PURE__ */ new WeakMap(), re = /* @__PURE__ */ new Map();
257
- function ze(n) {
258
- const t = te.get(n);
259
- if (t) return t;
260
- const e = n.id;
261
- if (e)
262
- return re.get(e);
272
+ Ze.displayName = "GridDetailPanel";
273
+ const re = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new Map();
274
+ function Qe(n) {
275
+ const e = re.get(n);
276
+ if (e) return e;
277
+ const t = n.id;
278
+ if (t)
279
+ return ne.get(t);
263
280
  }
264
- function ut(n) {
265
- const { id: t, title: e, icon: r, tooltip: o, order: a = 100, children: l } = n, i = P(null), f = h(
266
- (g) => {
267
- i.current = g, g && (te.set(g, l), t && re.set(t, l));
281
+ function Ct(n) {
282
+ const { id: e, title: t, icon: r, tooltip: o, order: s = 100, children: c } = n, i = b(null), g = C(
283
+ (f) => {
284
+ i.current = f, f && (re.set(f, c), e && ne.set(e, c));
268
285
  },
269
- [l, t]
286
+ [c, e]
270
287
  );
271
- return w(() => () => {
272
- const g = i.current;
273
- g && (te.delete(g), t && re.delete(t));
274
- }, [t]), /* @__PURE__ */ E(
288
+ return R(() => () => {
289
+ const f = i.current;
290
+ f && (re.delete(f), e && ne.delete(e));
291
+ }, [e]), /* @__PURE__ */ E(
275
292
  "tbw-grid-tool-panel",
276
293
  {
277
- ref: f,
278
- id: t,
279
- title: e,
294
+ ref: g,
295
+ id: e,
296
+ title: t,
280
297
  icon: r,
281
298
  tooltip: o,
282
- order: a?.toString()
299
+ order: s?.toString()
283
300
  }
284
301
  );
285
302
  }
286
- const V = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new Map();
287
- function $e(n, t) {
288
- const e = n.getAttribute("field"), r = V.get(n) ?? {};
289
- if (r.renderer = t, V.set(n, r), e) {
290
- const o = N.get(e) ?? {};
291
- o.renderer = t, N.set(e, o);
303
+ const A = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new Map();
304
+ function Xe(n, e) {
305
+ const t = n.getAttribute("field"), r = A.get(n) ?? {};
306
+ if (r.renderer = e, A.set(n, r), t) {
307
+ const o = T.get(t) ?? {};
308
+ o.renderer = e, T.set(t, o);
292
309
  }
293
310
  }
294
- function We(n, t) {
295
- const e = n.getAttribute("field"), r = V.get(n) ?? {};
296
- if (r.editor = t, V.set(n, r), e) {
297
- const o = N.get(e) ?? {};
298
- o.editor = t, N.set(e, o);
311
+ function et(n, e) {
312
+ const t = n.getAttribute("field"), r = A.get(n) ?? {};
313
+ if (r.editor = e, A.set(n, r), t) {
314
+ const o = T.get(t) ?? {};
315
+ o.editor = e, T.set(t, o);
299
316
  }
300
317
  }
301
- function Je(n) {
302
- let t = V.get(n)?.renderer;
303
- if (!t) {
304
- const e = n.getAttribute("field");
305
- e && (t = N.get(e)?.renderer);
318
+ function tt(n) {
319
+ let e = A.get(n)?.renderer;
320
+ if (!e) {
321
+ const t = n.getAttribute("field");
322
+ t && (e = T.get(t)?.renderer);
306
323
  }
307
- return t;
324
+ return e;
308
325
  }
309
- function Ue(n) {
310
- let t = V.get(n)?.editor;
311
- if (!t) {
312
- const e = n.getAttribute("field");
313
- e && (t = N.get(e)?.editor);
326
+ function rt(n) {
327
+ let e = A.get(n)?.editor;
328
+ if (!e) {
329
+ const t = n.getAttribute("field");
330
+ t && (e = T.get(t)?.editor);
314
331
  }
315
- return t;
332
+ return e;
316
333
  }
317
- class he {
318
- mountedViews = [];
319
- /** Editor-specific views tracked separately for per-cell cleanup via releaseCell. */
320
- editorViews = [];
334
+ class be {
335
+ /** Portal keys for all managed portals (for cleanup on destroy). */
336
+ allPortalKeys = /* @__PURE__ */ new Set();
337
+ /** Portal keys for editor-specific portals (for per-cell cleanup via releaseCell). */
338
+ editorPortalKeys = /* @__PURE__ */ new Set();
339
+ /** Maps portal keys to their containers (for container-based lookups in releaseCell/unmount). */
340
+ keyToContainer = /* @__PURE__ */ new Map();
321
341
  typeDefaults = null;
322
342
  /**
323
343
  * Sets the type defaults map for this adapter.
@@ -325,151 +345,157 @@ class he {
325
345
  *
326
346
  * @internal
327
347
  */
328
- setTypeDefaults(t) {
329
- this.typeDefaults = t;
348
+ setTypeDefaults(e) {
349
+ this.typeDefaults = e;
330
350
  }
331
351
  /**
332
352
  * FrameworkAdapter.processConfig implementation.
333
353
  * Called automatically by the grid's `set gridConfig` setter.
334
354
  * Converts React renderer/editor functions to DOM-returning functions.
335
355
  */
336
- processConfig(t) {
337
- return ye(t) ?? t;
356
+ processConfig(e) {
357
+ return Pe(e) ?? e;
338
358
  }
339
359
  /**
340
360
  * Determines if this adapter can handle the given element.
341
361
  * Checks if a renderer or editor is registered for this element.
342
362
  */
343
- canHandle(t) {
344
- const e = t.getAttribute("field");
345
- let r = V.get(t);
346
- if (!r && e) {
347
- const l = N.get(e);
348
- l && (l.renderer || l.editor) && (r = l, V.set(t, r));
363
+ canHandle(e) {
364
+ const t = e.getAttribute("field");
365
+ let r = A.get(e);
366
+ if (!r && t) {
367
+ const c = T.get(t);
368
+ c && (c.renderer || c.editor) && (r = c, A.set(e, r));
349
369
  }
350
- const o = r?.renderer !== void 0, a = r?.editor !== void 0;
351
- return r !== void 0 && (o || a);
370
+ const o = r?.renderer !== void 0, s = r?.editor !== void 0;
371
+ return r !== void 0 && (o || s);
352
372
  }
353
373
  /**
354
374
  * Creates a view renderer function that renders a React component
355
375
  * and returns its container DOM element.
356
376
  *
357
- * Uses a cell cache to reuse React roots for performance - instead of
358
- * creating new roots on each render, we reuse existing ones and just
359
- * call root.render() with new data.
377
+ * Uses a cell cache to reuse portals for performance - instead of
378
+ * creating new portals on each render, we reuse existing ones and
379
+ * update their content.
360
380
  *
361
381
  * Returns undefined if no renderer is registered for this element,
362
382
  * allowing the grid to use its default rendering.
363
383
  */
364
- createRenderer(t) {
365
- const e = Je(t);
366
- if (!e)
384
+ createRenderer(e) {
385
+ const t = tt(e);
386
+ if (!t)
367
387
  return;
368
- const r = /* @__PURE__ */ new WeakMap();
369
- return (o) => {
370
- const a = o.cellEl;
371
- if (a) {
372
- const f = r.get(a);
388
+ const r = e.closest("tbw-grid"), o = /* @__PURE__ */ new WeakMap();
389
+ return (s) => {
390
+ const c = s.cellEl;
391
+ if (c) {
392
+ const f = o.get(c);
373
393
  if (f)
374
- return R(() => {
375
- f.root.render(e(o));
376
- }), f.container;
377
- const g = document.createElement("div");
378
- g.className = "react-cell-renderer", g.style.display = "contents";
379
- const v = C(g);
380
- return R(() => {
381
- v.render(e(o));
382
- }), r.set(a, { root: v, container: g, lastRowIndex: o.rowIndex ?? -1 }), this.mountedViews.push({ root: v, container: g }), g;
394
+ return w(f.container, t(s), f.portalKey), f.container;
395
+ const m = document.createElement("div");
396
+ m.className = "react-cell-renderer", m.style.display = "contents";
397
+ const v = w(
398
+ m,
399
+ t(s),
400
+ void 0,
401
+ r ?? void 0
402
+ );
403
+ return o.set(c, { portalKey: v, container: m }), this.trackPortal(v, m, !1), m;
383
404
  }
384
- const l = document.createElement("div");
385
- l.className = "react-cell-renderer", l.style.display = "contents";
386
- const i = C(l);
387
- return R(() => {
388
- i.render(e(o));
389
- }), this.mountedViews.push({ root: i, container: l }), l;
405
+ const i = document.createElement("div");
406
+ i.className = "react-cell-renderer", i.style.display = "contents";
407
+ const g = w(
408
+ i,
409
+ t(s),
410
+ void 0,
411
+ r ?? void 0
412
+ );
413
+ return this.trackPortal(g, i, !1), i;
390
414
  };
391
415
  }
392
416
  /**
393
417
  * Creates an editor spec that renders a React component
394
418
  * with commit/cancel callbacks passed as props.
395
419
  */
396
- createEditor(t) {
397
- const e = Ue(t);
398
- return e ? (r) => {
399
- const o = document.createElement("div");
400
- o.className = "react-cell-editor", o.style.display = "contents";
401
- const a = C(o);
402
- return R(() => {
403
- a.render(e(r));
404
- }), this.editorViews.push({ root: a, container: o }), o;
405
- } : () => document.createElement("div");
420
+ createEditor(e) {
421
+ const t = rt(e);
422
+ if (!t)
423
+ return () => document.createElement("div");
424
+ const r = e.closest("tbw-grid") ?? void 0;
425
+ return (o) => {
426
+ const s = document.createElement("div");
427
+ s.className = "react-cell-editor", s.style.display = "contents";
428
+ const c = w(
429
+ s,
430
+ t(o),
431
+ void 0,
432
+ r
433
+ );
434
+ return this.trackPortal(c, s, !0), s;
435
+ };
406
436
  }
407
437
  /**
408
438
  * Creates a detail renderer function for MasterDetailPlugin.
409
439
  * Renders React components for expandable detail rows.
410
440
  */
411
- createDetailRenderer(t) {
412
- const e = je(t);
413
- if (e)
441
+ createDetailRenderer(e) {
442
+ const t = Ye(e);
443
+ if (t)
414
444
  return (r, o) => {
415
- const a = document.createElement("div");
416
- a.className = "react-detail-panel";
417
- const l = { row: r, rowIndex: o }, i = C(a);
418
- return R(() => {
419
- i.render(e(l));
420
- }), this.mountedViews.push({ root: i, container: a }), a;
445
+ const s = document.createElement("div");
446
+ s.className = "react-detail-panel";
447
+ const i = w(
448
+ s,
449
+ t({ row: r, rowIndex: o }),
450
+ void 0,
451
+ e
452
+ );
453
+ return this.trackPortal(i, s, !1), s;
421
454
  };
422
455
  }
423
456
  /**
424
457
  * Framework adapter hook called by MasterDetailPlugin during attach().
425
458
  * Parses the <tbw-grid-detail> element and returns a React-based renderer.
426
459
  */
427
- parseDetailElement(t) {
428
- const e = t.closest("tbw-grid");
429
- if (e)
430
- return this.createDetailRenderer(e);
460
+ parseDetailElement(e) {
461
+ const t = e.closest("tbw-grid");
462
+ if (t)
463
+ return this.createDetailRenderer(t);
431
464
  }
432
465
  /**
433
466
  * Creates a responsive card renderer function for ResponsivePlugin.
434
467
  * Renders React components for card layout in responsive mode.
435
468
  */
436
- createResponsiveCardRenderer(t) {
437
- const e = me(t);
438
- if (e)
469
+ createResponsiveCardRenderer(e) {
470
+ const t = we(e);
471
+ if (t)
439
472
  return (r, o) => {
440
- const a = document.createElement("div");
441
- a.className = "react-responsive-card";
442
- const l = { row: r, index: o }, i = C(a);
443
- return R(() => {
444
- i.render(e(l));
445
- }), this.mountedViews.push({ root: i, container: a }), a;
473
+ const s = document.createElement("div");
474
+ s.className = "react-responsive-card";
475
+ const i = w(
476
+ s,
477
+ t({ row: r, index: o }),
478
+ void 0,
479
+ e
480
+ );
481
+ return this.trackPortal(i, s, !1), s;
446
482
  };
447
483
  }
448
484
  /**
449
485
  * Creates a tool panel renderer from a light DOM element.
450
486
  * Renders React components into tool panel containers.
451
487
  */
452
- createToolPanelRenderer(t) {
453
- const e = ze(t);
454
- if (!e)
488
+ createToolPanelRenderer(e) {
489
+ const t = Qe(e);
490
+ if (!t)
455
491
  return;
456
- const r = t.closest("tbw-grid");
492
+ const r = e.closest("tbw-grid");
457
493
  return (o) => {
458
- const a = {
494
+ const c = w(o, t({
459
495
  grid: r ?? o
460
- }, l = C(o);
461
- return R(() => {
462
- l.render(e(a));
463
- }), this.mountedViews.push({ root: l, container: o }), () => {
464
- const i = this.mountedViews.findIndex((f) => f.container === o);
465
- if (i !== -1) {
466
- const { root: f } = this.mountedViews[i];
467
- try {
468
- f.unmount();
469
- } catch {
470
- }
471
- this.mountedViews.splice(i, 1);
472
- }
496
+ }), void 0, r ?? void 0);
497
+ return this.trackPortal(c, o, !1), () => {
498
+ _(c), this.untrackPortal(c);
473
499
  };
474
500
  };
475
501
  }
@@ -497,192 +523,178 @@ class he {
497
523
  * // Any grid with type: 'country' columns will use these components
498
524
  * ```
499
525
  */
500
- getTypeDefault(t) {
526
+ getTypeDefault(e, t) {
501
527
  if (!this.typeDefaults)
502
528
  return;
503
- const e = this.typeDefaults[t];
504
- if (!e)
529
+ const r = this.typeDefaults[e];
530
+ if (!r)
505
531
  return;
506
- const r = {
507
- editorParams: e.editorParams
532
+ const o = {
533
+ editorParams: r.editorParams
508
534
  };
509
- return e.renderer && (r.renderer = this.createTypeRenderer(e.renderer)), e.editor && (r.editor = this.createTypeEditor(e.editor)), e.filterPanelRenderer && (r.filterPanelRenderer = this.createFilterPanelRenderer(e.filterPanelRenderer)), r;
535
+ return r.renderer && (o.renderer = this.createTypeRenderer(r.renderer, t)), r.editor && (o.editor = this.createTypeEditor(r.editor, t)), r.filterPanelRenderer && (o.filterPanelRenderer = this.createFilterPanelRenderer(r.filterPanelRenderer, t)), o;
510
536
  }
511
537
  /**
512
538
  * Creates a renderer function from a React render function for type defaults.
513
539
  * @internal
514
540
  */
515
- createTypeRenderer(t) {
516
- return (e) => {
517
- const r = document.createElement("span");
518
- r.style.display = "contents";
519
- const o = C(r);
520
- return this.mountedViews.push({ root: o, container: r }), R(() => {
521
- o.render(t(e));
522
- }), r;
541
+ createTypeRenderer(e, t) {
542
+ return (r) => {
543
+ const o = document.createElement("span");
544
+ o.style.display = "contents";
545
+ const s = r.cellEl?.closest("tbw-grid") ?? t, c = w(o, e(r), void 0, s);
546
+ return this.trackPortal(c, o, !1), o;
523
547
  };
524
548
  }
525
549
  /**
526
550
  * Creates an editor function from a React render function for type defaults.
527
551
  * @internal
528
552
  */
529
- createTypeEditor(t) {
530
- return (e) => {
531
- const r = document.createElement("span");
532
- r.style.display = "contents";
533
- const o = C(r);
534
- return this.editorViews.push({ root: o, container: r }), R(() => {
535
- o.render(t(e));
536
- }), r;
553
+ createTypeEditor(e, t) {
554
+ return (r) => {
555
+ const o = document.createElement("span");
556
+ o.style.display = "contents";
557
+ const s = w(o, e(r), void 0, t);
558
+ return this.trackPortal(s, o, !0), o;
537
559
  };
538
560
  }
539
561
  /**
540
562
  * Creates a filter panel renderer that mounts React content into the filter panel container.
541
563
  * @internal
542
564
  */
543
- createFilterPanelRenderer(t) {
544
- return (e, r) => {
545
- const o = document.createElement("div");
546
- o.style.display = "contents";
547
- const a = C(o);
548
- this.mountedViews.push({ root: a, container: o }), R(() => {
549
- a.render(t(r));
550
- }), e.appendChild(o);
565
+ createFilterPanelRenderer(e, t) {
566
+ return (r, o) => {
567
+ const s = document.createElement("div");
568
+ s.style.display = "contents";
569
+ const c = r.closest("tbw-grid") ?? t, i = w(s, e(o), void 0, c);
570
+ this.trackPortal(i, s, !1), r.appendChild(s);
551
571
  };
552
572
  }
573
+ // #region Portal tracking helpers
574
+ /** Register a portal key for lifecycle tracking. */
575
+ trackPortal(e, t, r) {
576
+ this.allPortalKeys.add(e), this.keyToContainer.set(e, t), r && this.editorPortalKeys.add(e);
577
+ }
578
+ /** Unregister a portal key from all tracking sets. */
579
+ untrackPortal(e) {
580
+ this.allPortalKeys.delete(e), this.editorPortalKeys.delete(e), this.keyToContainer.delete(e);
581
+ }
582
+ // #endregion
553
583
  /**
554
- * Clean up all mounted React roots.
584
+ * Clean up all mounted portals.
555
585
  * Call this when the grid is unmounted.
556
586
  */
557
587
  destroy() {
558
- this.mountedViews.forEach(({ root: t }) => {
559
- try {
560
- t.unmount();
561
- } catch {
562
- }
563
- }), this.mountedViews = [], this.editorViews.forEach(({ root: t }) => {
564
- try {
565
- t.unmount();
566
- } catch {
567
- }
568
- }), this.editorViews = [], N.clear();
588
+ for (const e of this.allPortalKeys)
589
+ _(e);
590
+ this.allPortalKeys.clear(), this.editorPortalKeys.clear(), this.keyToContainer.clear(), T.clear();
569
591
  }
570
592
  /**
571
593
  * Called when a cell's content is about to be wiped.
572
- * Destroys editor React roots whose container is inside the cell.
594
+ * Destroys editor portals whose container is inside the cell.
573
595
  * Also cleans up config-based editor roots (from processGridConfig/wrapReactEditor)
574
- * that bypass the adapter's tracking arrays.
596
+ * that bypass the adapter's tracking.
575
597
  */
576
- releaseCell(t) {
577
- for (let e = this.editorViews.length - 1; e >= 0; e--) {
578
- const { root: r, container: o } = this.editorViews[e];
579
- if (t.contains(o)) {
580
- try {
581
- r.unmount();
582
- } catch {
583
- }
584
- this.editorViews.splice(e, 1);
585
- }
598
+ releaseCell(e) {
599
+ for (const t of this.editorPortalKeys) {
600
+ const r = this.keyToContainer.get(t);
601
+ r && e.contains(r) && (_(t), this.untrackPortal(t));
586
602
  }
587
- Fe(t);
603
+ ze(e);
588
604
  }
589
605
  /**
590
606
  * Unmount a specific container (called when cell is recycled).
591
607
  */
592
- unmount(t) {
593
- const e = this.mountedViews.findIndex((r) => r.container === t);
594
- if (e !== -1) {
595
- const { root: r } = this.mountedViews[e];
596
- try {
597
- r.unmount();
598
- } catch {
608
+ unmount(e) {
609
+ for (const [t, r] of this.keyToContainer)
610
+ if (r === e) {
611
+ _(t), this.untrackPortal(t);
612
+ return;
599
613
  }
600
- this.mountedViews.splice(e, 1);
601
- }
602
614
  }
603
615
  }
604
- const ft = he, Ke = {
616
+ const Rt = be, nt = {
605
617
  undoRedo: ["editing"],
606
618
  clipboard: ["selection"]
607
619
  };
608
- function Ye(n) {
609
- const t = new Set(n);
610
- for (const e of n) {
611
- const r = Ke[e];
620
+ function ot(n) {
621
+ const e = new Set(n);
622
+ for (const t of n) {
623
+ const r = nt[t];
612
624
  if (r)
613
625
  for (const o of r)
614
- t.has(o) || console.warn(
615
- `[DataGrid] Feature "${e}" requires "${o}" to be enabled. Add the "${o}" prop to your DataGrid.`
626
+ e.has(o) || console.warn(
627
+ `[DataGrid] Feature "${t}" requires "${o}" to be enabled. Add the "${o}" prop to your DataGrid.`
616
628
  );
617
629
  }
618
630
  }
619
- function Ze(n) {
620
- const t = [];
621
- for (const [e, r] of Object.entries(n))
622
- r === void 0 || r === !1 || t.push(e);
623
- return Ye(t), Pe(n);
631
+ function it(n) {
632
+ const e = [];
633
+ for (const [t, r] of Object.entries(n))
634
+ r === void 0 || r === !1 || e.push(t);
635
+ return ot(e), Ne(n);
624
636
  }
625
- let fe = !1, Y = null;
626
- function ne() {
627
- return fe || (Y = new he(), ve.registerAdapter(Y), fe = !0), Y;
637
+ let ye = !1, Z = null;
638
+ function oe() {
639
+ return ye || (Z = new be(), ke.registerAdapter(Z), ye = !0), Z;
628
640
  }
629
- ne();
630
- function Qe(n) {
631
- const e = n.getPluginByName?.("masterDetail");
632
- e && typeof e.refreshDetailRenderer == "function" && e.refreshDetailRenderer();
641
+ oe();
642
+ function st(n) {
643
+ const t = n.getPluginByName?.("masterDetail");
644
+ t && typeof t.refreshDetailRenderer == "function" && t.refreshDetailRenderer();
633
645
  }
634
- function Xe(n, t) {
635
- const e = n;
636
- if (!n.querySelector("tbw-grid-responsive-card") || !me(n)) return;
637
- const a = e.getPluginByName?.("responsive");
638
- if (a && typeof a.setCardRenderer == "function") {
639
- const l = t.createResponsiveCardRenderer(n);
640
- l && a.setCardRenderer(l);
646
+ function ct(n, e) {
647
+ const t = n;
648
+ if (!n.querySelector("tbw-grid-responsive-card") || !we(n)) return;
649
+ const s = t.getPluginByName?.("responsive");
650
+ if (s && typeof s.setCardRenderer == "function") {
651
+ const c = e.createResponsiveCardRenderer(n);
652
+ c && s.setCardRenderer(c);
641
653
  }
642
654
  }
643
- function et(n) {
644
- const t = {};
645
- return Ee.forEach(n, (e) => {
646
- if (Se(e)) {
647
- if (e.type && e.type.displayName === "GridDetailPanel") {
648
- const r = e.props;
649
- t.masterDetail = {
655
+ function at(n) {
656
+ const e = {};
657
+ return De.forEach(n, (t) => {
658
+ if (Ae(t)) {
659
+ if (t.type && t.type.displayName === "GridDetailPanel") {
660
+ const r = t.props;
661
+ e.masterDetail = {
650
662
  // Use props from the child component for configuration
651
663
  showExpandColumn: r.showExpandColumn ?? !0,
652
664
  animation: r.animation ?? "slide"
653
665
  // detailRenderer will be wired up by refreshMasterDetailRenderer after mount
654
666
  };
655
667
  }
656
- e.type && e.type.displayName === "GridResponsiveCard" && (t.responsive = !0);
668
+ t.type && t.type.displayName === "GridResponsiveCard" && (e.responsive = !0);
657
669
  }
658
- }), t;
670
+ }), e;
659
671
  }
660
- const gt = Ce(function(t, e) {
672
+ const wt = Ce(function(e, t) {
661
673
  const {
662
674
  // Core props
663
675
  rows: r,
664
676
  gridConfig: o,
665
- columns: a,
666
- columnDefaults: l,
677
+ columns: s,
678
+ columnDefaults: c,
667
679
  fitMode: i,
668
- sortable: f,
669
- filterable: g,
670
- selectable: v,
671
- loading: x,
672
- editOn: D,
673
- customStyles: A,
674
- className: k,
675
- style: M,
676
- children: L,
680
+ sortable: g,
681
+ filterable: f,
682
+ selectable: m,
683
+ loading: v,
684
+ editOn: P,
685
+ customStyles: G,
686
+ className: I,
687
+ style: F,
688
+ children: N,
677
689
  // Plugin props
678
- plugins: S,
690
+ plugins: k,
679
691
  // SSR mode
680
- ssr: T,
692
+ ssr: K,
681
693
  // Legacy event handlers
682
- onRowsChange: y,
694
+ onRowsChange: h,
683
695
  // Feature props and event props are in ...rest
684
696
  ...d
685
- } = t, s = P(null), p = P(null), b = z(ke), H = z(Ne), F = [
697
+ } = e, l = b(null), p = b(null), S = z(Be), M = z(He), L = [
686
698
  "selection",
687
699
  "editing",
688
700
  "filtering",
@@ -712,215 +724,225 @@ const gt = Ce(function(t, e) {
712
724
  "pivot",
713
725
  "serverSide",
714
726
  "tooltip"
715
- ], we = G(() => F.map((c) => {
716
- const u = d[c];
717
- return u !== void 0 ? `${c}:${JSON.stringify(u)}` : "";
718
- }).filter(Boolean).join("|"), [d]), ie = G(() => {
719
- const c = {};
720
- for (const u of F)
721
- u in d && d[u] !== void 0 && (c[u] = d[u]);
722
- return c;
723
- }, [we]), se = G(() => et(L), [L]), ce = G(() => ({ ...se, ...ie }), [ie, se]), W = G(() => S || T ? [] : Ze(ce), [ce, S, T]), O = G(() => {
724
- if (S) {
725
- const c = new Set(S.map((m) => m.name)), u = W.filter((m) => !c.has(m.name));
726
- return [...S, ...u];
727
+ ], Ee = x(() => L.map((a) => {
728
+ const u = d[a];
729
+ return u !== void 0 ? `${a}:${JSON.stringify(u)}` : "";
730
+ }).filter(Boolean).join("|"), [d]), ce = x(() => {
731
+ const a = {};
732
+ for (const u of L)
733
+ u in d && d[u] !== void 0 && (a[u] = d[u]);
734
+ return a;
735
+ }, [Ee]), ae = x(() => at(N), [N]), le = x(() => ({ ...ae, ...ce }), [ce, ae]), V = x(() => k || K ? [] : it(le), [le, k, K]), q = x(() => {
736
+ if (k) {
737
+ const a = new Set(k.map((y) => y.name)), u = V.filter((y) => !a.has(y.name));
738
+ return [...k, ...u];
727
739
  }
728
- return W;
729
- }, [S, W]), q = G(() => {
730
- if (!a) return a;
731
- const c = Ie(a);
732
- return l ? c.map((u) => ({
733
- ...l,
740
+ return V;
741
+ }, [k, V]), H = x(() => {
742
+ if (!s) return s;
743
+ const a = Me(s);
744
+ return c ? a.map((u) => ({
745
+ ...c,
734
746
  ...u
735
747
  // Individual column props override defaults
736
- })) : c;
737
- }, [a, l]), B = G(() => {
738
- const c = ye(o), u = {};
739
- if (f !== void 0 && (u.sortable = f), g !== void 0 && (u.filterable = g), v !== void 0 && (u.selectable = v), H) {
740
- const m = c?.icons || o?.icons || {};
741
- u.icons = { ...H, ...m };
748
+ })) : a;
749
+ }, [s, c]), O = x(() => {
750
+ const a = Pe(o), u = {};
751
+ if (g !== void 0 && (u.sortable = g), f !== void 0 && (u.filterable = f), m !== void 0 && (u.selectable = m), M) {
752
+ const y = a?.icons || o?.icons || {};
753
+ u.icons = { ...M, ...y };
742
754
  }
743
- if (O.length > 0 && c) {
744
- const m = c.plugins || [], j = new Set(m.map((_) => _.name)), J = O.filter((_) => !j.has(_.name));
755
+ if (q.length > 0 && a) {
756
+ const y = a.plugins || [], j = new Set(y.map((B) => B.name)), J = q.filter((B) => !j.has(B.name));
745
757
  return {
746
- ...c,
758
+ ...a,
747
759
  ...u,
748
- plugins: [...m, ...J]
760
+ plugins: [...y, ...J]
749
761
  };
750
762
  }
751
- return O.length > 0 && !c ? { ...u, plugins: O } : Object.keys(u).length > 0 ? { ...c, ...u } : c;
752
- }, [o, O, f, g, v, H]);
753
- w(() => {
754
- ne().setTypeDefaults(b);
755
- }, [b]), w(() => {
756
- s.current && (s.current.rows = r);
757
- }, [r]), w(() => {
758
- s.current && B && (s.current.gridConfig = B);
759
- }, [B]), w(() => {
760
- s.current && q && (s.current.columns = q);
761
- }, [q]), w(() => {
762
- s.current && i !== void 0 && (s.current.fitMode = i);
763
- }, [i]), w(() => {
764
- s.current && D !== void 0 && (s.current.editOn = D);
765
- }, [D]), w(() => {
766
- s.current && x !== void 0 && (s.current.loading = x);
767
- }, [x]), w(() => {
768
- const c = s.current;
769
- if (!c) return;
770
- const u = ne();
771
- c.__frameworkAdapter = u, Qe(c), Xe(c, u);
772
- let m = !1;
763
+ return q.length > 0 && !a ? { ...u, plugins: q } : Object.keys(u).length > 0 ? { ...a, ...u } : a;
764
+ }, [o, q, g, f, m, M]);
765
+ R(() => {
766
+ oe().setTypeDefaults(S);
767
+ }, [S]), R(() => {
768
+ l.current && (l.current.rows = r);
769
+ }, [r]), R(() => {
770
+ l.current && O && (l.current.gridConfig = O);
771
+ }, [O]), R(() => {
772
+ l.current && H && (l.current.columns = H);
773
+ }, [H]), R(() => {
774
+ l.current && i !== void 0 && (l.current.fitMode = i);
775
+ }, [i]), R(() => {
776
+ l.current && P !== void 0 && (l.current.editOn = P);
777
+ }, [P]), R(() => {
778
+ l.current && v !== void 0 && (l.current.loading = v);
779
+ }, [v]), R(() => {
780
+ const a = l.current;
781
+ if (!a) return;
782
+ const u = oe();
783
+ a.__frameworkAdapter = u, st(a), ct(a, u);
784
+ let y = !1;
773
785
  const j = requestAnimationFrame(() => {
774
- m || (typeof c.refreshColumns == "function" && c.refreshColumns(), typeof c.refreshShellHeader == "function" && c.refreshShellHeader());
786
+ y || (typeof a.refreshColumns == "function" && a.refreshColumns(), typeof a.refreshShellHeader == "function" && a.refreshShellHeader());
775
787
  });
776
788
  return () => {
777
- m = !0, cancelAnimationFrame(j);
789
+ y = !0, cancelAnimationFrame(j);
778
790
  };
779
- }, []), w(() => {
780
- if (!s.current || !A) return;
781
- const c = s.current, u = "react-custom-styles";
782
- let m = !0;
783
- return c.ready?.().then(() => {
784
- m && A && (c.registerStyles?.(u, A), p.current = u);
791
+ }, []), R(() => {
792
+ if (!l.current || !G) return;
793
+ const a = l.current, u = "react-custom-styles";
794
+ let y = !0;
795
+ return a.ready?.().then(() => {
796
+ y && G && (a.registerStyles?.(u, G), p.current = u);
785
797
  }), () => {
786
- m = !1, p.current && (c.unregisterStyles?.(p.current), p.current = null);
798
+ y = !1, p.current && (a.unregisterStyles?.(p.current), p.current = null);
787
799
  };
788
- }, [A]), w(() => {
789
- const c = s.current;
790
- if (!c) return;
800
+ }, [G]), R(() => {
801
+ const a = l.current;
802
+ if (!a) return;
791
803
  const u = [];
792
- return y && u.push(c.on("rows-change", (m) => y(m.rows))), () => {
793
- u.forEach((m) => m());
804
+ return h && u.push(a.on("rows-change", (y) => h(y.rows))), () => {
805
+ u.forEach((y) => y());
794
806
  };
795
- }, [y]);
796
- const ae = G(() => Object.keys(U).filter((c) => typeof d[c] == "function").sort().join("|"), [d]), le = P({});
797
- for (const c of Object.keys(U))
798
- le.current[c] = d[c];
799
- return w(() => {
800
- const c = s.current;
801
- if (!c) return;
807
+ }, [h]);
808
+ const de = x(() => Object.keys(U).filter((a) => typeof d[a] == "function").sort().join("|"), [d]), ue = b({});
809
+ for (const a of Object.keys(U))
810
+ ue.current[a] = d[a];
811
+ R(() => {
812
+ const a = l.current;
813
+ if (!a) return;
802
814
  const u = [];
803
- for (const [m, j] of Object.entries(U))
804
- ae.includes(m) && u.push(
805
- c.on(j, (J, _) => {
806
- le.current[m]?.(J, _);
815
+ for (const [y, j] of Object.entries(U))
816
+ de.includes(y) && u.push(
817
+ a.on(j, (J, B) => {
818
+ ue.current[y]?.(J, B);
807
819
  })
808
820
  );
809
821
  return () => {
810
- u.forEach((m) => m());
822
+ u.forEach((y) => y());
811
823
  };
812
- }, [ae]), be(
813
- e,
824
+ }, [de]), Re(
825
+ t,
814
826
  () => ({
815
827
  get element() {
816
- return s.current;
828
+ return l.current;
817
829
  },
818
830
  async getConfig() {
819
- return s.current?.getConfig?.() ?? {};
831
+ return l.current?.getConfig?.() ?? {};
820
832
  },
821
833
  async ready() {
822
- return s.current?.ready?.();
834
+ return l.current?.ready?.();
823
835
  },
824
836
  async forceLayout() {
825
- return s.current?.forceLayout?.();
837
+ return l.current?.forceLayout?.();
826
838
  },
827
- async toggleGroup(c) {
828
- return s.current?.toggleGroup?.(c);
839
+ async toggleGroup(a) {
840
+ return l.current?.toggleGroup?.(a);
829
841
  },
830
- registerStyles(c, u) {
831
- s.current?.registerStyles?.(c, u);
842
+ registerStyles(a, u) {
843
+ l.current?.registerStyles?.(a, u);
832
844
  },
833
- unregisterStyles(c) {
834
- s.current?.unregisterStyles?.(c);
845
+ unregisterStyles(a) {
846
+ l.current?.unregisterStyles?.(a);
835
847
  },
836
- setRowLoading(c, u) {
837
- s.current?.setRowLoading?.(c, u);
848
+ setRowLoading(a, u) {
849
+ l.current?.setRowLoading?.(a, u);
838
850
  },
839
- setCellLoading(c, u, m) {
840
- s.current?.setCellLoading?.(c, u, m);
851
+ setCellLoading(a, u, y) {
852
+ l.current?.setCellLoading?.(a, u, y);
841
853
  },
842
- isRowLoading(c) {
843
- return s.current?.isRowLoading?.(c) ?? !1;
854
+ isRowLoading(a) {
855
+ return l.current?.isRowLoading?.(a) ?? !1;
844
856
  },
845
- isCellLoading(c, u) {
846
- return s.current?.isCellLoading?.(c, u) ?? !1;
857
+ isCellLoading(a, u) {
858
+ return l.current?.isCellLoading?.(a, u) ?? !1;
847
859
  },
848
860
  clearAllLoading() {
849
- s.current?.clearAllLoading?.();
861
+ l.current?.clearAllLoading?.();
850
862
  }
851
863
  }),
852
864
  []
853
- ), /* @__PURE__ */ E(
854
- "tbw-grid",
855
- {
856
- ref: (c) => {
857
- if (s.current = c, c) {
858
- const u = c;
859
- B && (u.gridConfig = B), r && (u.rows = r), q && (u.columns = q);
860
- }
861
- },
862
- class: k,
863
- style: M,
864
- children: /* @__PURE__ */ E(xe.Provider, { value: s, children: L })
865
- }
866
865
  );
866
+ const W = b(null);
867
+ return Ge(() => {
868
+ const a = l.current;
869
+ return a && W.current && ge(a, W.current), () => {
870
+ a && ge(a, null);
871
+ };
872
+ }, []), /* @__PURE__ */ Se(ie, { children: [
873
+ /* @__PURE__ */ E(_e, { ref: W }),
874
+ /* @__PURE__ */ E(
875
+ "tbw-grid",
876
+ {
877
+ ref: (a) => {
878
+ if (l.current = a, a) {
879
+ const u = a;
880
+ O && (u.gridConfig = O), r && (u.rows = r), H && (u.columns = H);
881
+ }
882
+ },
883
+ class: I,
884
+ style: F,
885
+ children: /* @__PURE__ */ E(Ke.Provider, { value: l, children: N })
886
+ }
887
+ )
888
+ ] });
867
889
  });
868
- function pt(n) {
890
+ function Pt(n) {
869
891
  const {
870
- field: t,
871
- header: e,
892
+ field: e,
893
+ header: t,
872
894
  type: r,
873
895
  editable: o,
874
- sortable: a,
875
- resizable: l,
896
+ sortable: s,
897
+ resizable: c,
876
898
  width: i,
877
- minWidth: f,
878
- hidden: g,
879
- lockVisible: v,
880
- children: x,
881
- editor: D,
882
- options: A,
883
- multi: k,
884
- format: M
885
- } = n, L = P(null), S = h(
899
+ minWidth: g,
900
+ hidden: f,
901
+ lockVisible: m,
902
+ children: v,
903
+ editor: P,
904
+ options: G,
905
+ multi: I,
906
+ format: F
907
+ } = n, N = b(null), k = C(
886
908
  (d) => {
887
- L.current = d, d && (x && $e(d, x), D && We(d, D));
909
+ N.current = d, d && (v && Xe(d, v), P && et(d, P));
888
910
  },
889
- [x, D, t]
890
- ), T = typeof i == "number" ? `${i}px` : i, y = {
891
- field: t,
892
- ref: S
911
+ [v, P, e]
912
+ ), K = typeof i == "number" ? `${i}px` : i, h = {
913
+ field: e,
914
+ ref: k
893
915
  };
894
- return e !== void 0 && (y.header = e), r !== void 0 && (y.type = r), o !== void 0 && (y.editable = o), a !== void 0 && (y.sortable = a), l !== void 0 && (y.resizable = l), T !== void 0 && (y.width = T), f !== void 0 && (y["min-width"] = f), g !== void 0 && (y.hidden = g), v !== void 0 && (y["lock-visible"] = v), k !== void 0 && (y.multi = k), M && (y["data-has-format"] = "true"), A && (y["data-has-options"] = "true"), /* @__PURE__ */ E("tbw-grid-column", { ...y });
916
+ return t !== void 0 && (h.header = t), r !== void 0 && (h.type = r), o !== void 0 && (h.editable = o), s !== void 0 && (h.sortable = s), c !== void 0 && (h.resizable = c), K !== void 0 && (h.width = K), g !== void 0 && (h["min-width"] = g), f !== void 0 && (h.hidden = f), m !== void 0 && (h["lock-visible"] = m), I !== void 0 && (h.multi = I), F && (h["data-has-format"] = "true"), G && (h["data-has-options"] = "true"), /* @__PURE__ */ E("tbw-grid-column", { ...h });
895
917
  }
896
- function mt({ children: n }) {
918
+ function bt({ children: n }) {
897
919
  return /* @__PURE__ */ E("tbw-grid-tool-buttons", { children: n });
898
920
  }
899
- const yt = ({ icons: n, defaults: t, children: e }) => {
900
- let r = e;
901
- return t && (r = /* @__PURE__ */ E(Te, { defaults: t, children: r })), n && (r = /* @__PURE__ */ E(Ve, { icons: n, children: r })), /* @__PURE__ */ E(Re, { children: r });
921
+ const Et = ({ icons: n, defaults: e, children: t }) => {
922
+ let r = t;
923
+ return e && (r = /* @__PURE__ */ E(je, { defaults: e, children: r })), n && (r = /* @__PURE__ */ E(qe, { icons: n, children: r })), /* @__PURE__ */ E(ie, { children: r });
902
924
  };
903
- function ht(n) {
904
- const t = P(null), [e, r] = de(!1), [o, a] = de(null), l = P(null), i = h(() => n ? (l.current ??= document.querySelector(n), l.current) : t.current?.element ?? null, [n]);
905
- w(() => {
925
+ function St(n) {
926
+ const e = b(null), [t, r] = fe(!1), [o, s] = fe(null), c = b(null), i = C(() => n ? (c.current ??= document.querySelector(n), c.current) : e.current?.element ?? null, [n]);
927
+ R(() => {
906
928
  let d = !0;
907
929
  return (async () => {
908
930
  try {
909
931
  if (n) {
910
932
  const p = document.querySelector(n);
911
933
  if (!p) return;
912
- if (l.current = p, await p.ready?.(), d) {
934
+ if (c.current = p, await p.ready?.(), d) {
913
935
  r(!0);
914
- const b = await p.getConfig?.();
915
- d && b && a(b);
936
+ const S = await p.getConfig?.();
937
+ d && S && s(S);
916
938
  }
917
939
  } else {
918
- const p = t.current;
940
+ const p = e.current;
919
941
  if (!p) return;
920
942
  if (await p.ready?.(), d) {
921
943
  r(!0);
922
- const b = await p.getConfig?.();
923
- d && b && a(b);
944
+ const S = await p.getConfig?.();
945
+ d && S && s(S);
924
946
  }
925
947
  }
926
948
  } catch {
@@ -929,73 +951,73 @@ function ht(n) {
929
951
  d = !1;
930
952
  };
931
953
  }, [n]);
932
- const f = h(async () => {
954
+ const g = C(async () => {
933
955
  const d = i();
934
956
  if (d)
935
957
  return await d.getConfig?.() ?? null;
936
- const s = t.current;
937
- return s ? await s.getConfig?.() ?? null : null;
938
- }, [i]), g = h(async () => {
958
+ const l = e.current;
959
+ return l ? await l.getConfig?.() ?? null : null;
960
+ }, [i]), f = C(async () => {
939
961
  const d = i();
940
962
  if (d) {
941
963
  await d.forceLayout?.();
942
964
  return;
943
965
  }
944
- const s = t.current;
945
- s && await s.forceLayout?.();
946
- }, [i]), v = h(
966
+ const l = e.current;
967
+ l && await l.forceLayout?.();
968
+ }, [i]), m = C(
947
969
  async (d) => {
948
- const s = i();
949
- if (s) {
950
- await s.toggleGroup?.(d);
970
+ const l = i();
971
+ if (l) {
972
+ await l.toggleGroup?.(d);
951
973
  return;
952
974
  }
953
- const p = t.current;
975
+ const p = e.current;
954
976
  p && await p.toggleGroup?.(d);
955
977
  },
956
978
  [i]
957
- ), x = h(
958
- (d, s) => {
979
+ ), v = C(
980
+ (d, l) => {
959
981
  const p = i();
960
982
  if (p) {
961
- p.registerStyles?.(d, s);
983
+ p.registerStyles?.(d, l);
962
984
  return;
963
985
  }
964
- t.current?.registerStyles?.(d, s);
986
+ e.current?.registerStyles?.(d, l);
965
987
  },
966
988
  [i]
967
- ), D = h(
989
+ ), P = C(
968
990
  (d) => {
969
- const s = i();
970
- if (s) {
971
- s.unregisterStyles?.(d);
991
+ const l = i();
992
+ if (l) {
993
+ l.unregisterStyles?.(d);
972
994
  return;
973
995
  }
974
- t.current?.unregisterStyles?.(d);
996
+ e.current?.unregisterStyles?.(d);
975
997
  },
976
998
  [i]
977
- ), A = h(() => o?.columns ? o.columns.filter((d) => !d.hidden) : [], [o]), k = h(() => {
978
- const d = i(), s = d?.getPluginByName?.("selection");
979
- if (!s) {
999
+ ), G = C(() => o?.columns ? o.columns.filter((d) => !d.hidden) : [], [o]), I = C(() => {
1000
+ const d = i(), l = d?.getPluginByName?.("selection");
1001
+ if (!l) {
980
1002
  console.warn("[useGrid] selectAll requires SelectionPlugin");
981
1003
  return;
982
1004
  }
983
- if (s.config?.mode === "row") {
984
- const p = d?.rows ?? [], b = new Set(p.map((H, F) => F));
985
- s.selected = b, s.requestAfterRender?.();
1005
+ if (l.config?.mode === "row") {
1006
+ const p = d?.rows ?? [], S = new Set(p.map((M, L) => L));
1007
+ l.selected = S, l.requestAfterRender?.();
986
1008
  }
987
- }, [i]), M = h(() => {
988
- const s = i()?.getPluginByName?.("selection");
989
- s && s.clearSelection?.();
990
- }, [i]), L = h(() => {
991
- const s = i()?.getPluginByName?.("selection");
992
- return s ? new Set(s.selected ?? []) : /* @__PURE__ */ new Set();
993
- }, [i]), S = h(() => {
994
- const d = i(), s = d?.getPluginByName?.("selection");
995
- if (!s) return [];
996
- const p = d?.rows ?? [], b = s.selected ?? /* @__PURE__ */ new Set();
997
- return p.filter((H, F) => b.has(F));
998
- }, [i]), T = h(
1009
+ }, [i]), F = C(() => {
1010
+ const l = i()?.getPluginByName?.("selection");
1011
+ l && l.clearSelection?.();
1012
+ }, [i]), N = C(() => {
1013
+ const l = i()?.getPluginByName?.("selection");
1014
+ return l ? new Set(l.selected ?? []) : /* @__PURE__ */ new Set();
1015
+ }, [i]), k = C(() => {
1016
+ const d = i(), l = d?.getPluginByName?.("selection");
1017
+ if (!l) return [];
1018
+ const p = d?.rows ?? [], S = l.selected ?? /* @__PURE__ */ new Set();
1019
+ return p.filter((M, L) => S.has(L));
1020
+ }, [i]), K = C(
999
1021
  (d) => {
1000
1022
  const p = i()?.getPluginByName?.("export");
1001
1023
  if (!p) {
@@ -1005,7 +1027,7 @@ function ht(n) {
1005
1027
  p.exportCsv?.({ filename: d ?? "export.csv" });
1006
1028
  },
1007
1029
  [i]
1008
- ), y = h(
1030
+ ), h = C(
1009
1031
  (d) => {
1010
1032
  const p = i()?.getPluginByName?.("export");
1011
1033
  if (!p) {
@@ -1017,62 +1039,62 @@ function ht(n) {
1017
1039
  [i]
1018
1040
  );
1019
1041
  return {
1020
- ref: t,
1042
+ ref: e,
1021
1043
  element: i(),
1022
- isReady: e,
1044
+ isReady: t,
1023
1045
  config: o,
1024
- getConfig: f,
1025
- forceLayout: g,
1026
- toggleGroup: v,
1027
- registerStyles: x,
1028
- unregisterStyles: D,
1029
- getVisibleColumns: A,
1046
+ getConfig: g,
1047
+ forceLayout: f,
1048
+ toggleGroup: m,
1049
+ registerStyles: v,
1050
+ unregisterStyles: P,
1051
+ getVisibleColumns: G,
1030
1052
  // Selection methods
1031
- selectAll: k,
1032
- clearSelection: M,
1033
- getSelectedIndices: L,
1034
- getSelectedRows: S,
1053
+ selectAll: I,
1054
+ clearSelection: F,
1055
+ getSelectedIndices: N,
1056
+ getSelectedRows: k,
1035
1057
  // Export methods
1036
- exportToCsv: T,
1037
- exportToJson: y
1058
+ exportToCsv: K,
1059
+ exportToJson: h
1038
1060
  };
1039
1061
  }
1040
- let ge = !1;
1041
- function wt(n, t, e, r = []) {
1042
- !ge && typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname.includes(".local")) && (ge = !0, console.warn(
1062
+ let he = !1;
1063
+ function kt(n, e, t, r = []) {
1064
+ !he && typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname.includes(".local")) && (he = !0, console.warn(
1043
1065
  `[useGridEvent] Deprecated: Use event props directly on DataGrid instead.
1044
1066
  Example: <DataGrid onSelectionChange={(e) => ...} />
1045
1067
  See migration guide: https://toolbox-web.dev/grid-react/migration`
1046
1068
  ));
1047
- const o = P(e);
1048
- w(() => {
1049
- o.current = e;
1050
- }, [e, ...r]), w(() => {
1051
- const a = n.current, l = a && "element" in a ? a.element : a;
1052
- if (!l) return;
1053
- const i = ((f) => {
1054
- o.current(f);
1069
+ const o = b(t);
1070
+ R(() => {
1071
+ o.current = t;
1072
+ }, [t, ...r]), R(() => {
1073
+ const s = n.current, c = s && "element" in s ? s.element : s;
1074
+ if (!c) return;
1075
+ const i = ((g) => {
1076
+ o.current(g);
1055
1077
  });
1056
- return l.addEventListener(t, i), () => {
1057
- l.removeEventListener(t, i);
1078
+ return c.addEventListener(e, i), () => {
1079
+ c.removeEventListener(e, i);
1058
1080
  };
1059
- }, [n, t]);
1081
+ }, [n, e]);
1060
1082
  }
1061
1083
  export {
1062
- gt as DataGrid,
1063
- he as GridAdapter,
1064
- pt as GridColumn,
1065
- _e as GridDetailPanel,
1066
- Ve as GridIconProvider,
1067
- yt as GridProvider,
1068
- Le as GridResponsiveCard,
1069
- mt as GridToolButtons,
1070
- ut as GridToolPanel,
1071
- Te as GridTypeProvider,
1072
- ft as ReactGridAdapter,
1073
- ht as useGrid,
1074
- wt as useGridEvent,
1075
- at as useGridIcons,
1076
- lt as useGridTypeDefaults,
1077
- dt as useTypeDefault
1084
+ wt as DataGrid,
1085
+ be as GridAdapter,
1086
+ Pt as GridColumn,
1087
+ Ze as GridDetailPanel,
1088
+ qe as GridIconProvider,
1089
+ Et as GridProvider,
1090
+ Oe as GridResponsiveCard,
1091
+ bt as GridToolButtons,
1092
+ Ct as GridToolPanel,
1093
+ je as GridTypeProvider,
1094
+ Rt as ReactGridAdapter,
1095
+ St as useGrid,
1096
+ kt as useGridEvent,
1097
+ yt as useGridIcons,
1098
+ ht as useGridTypeDefaults,
1099
+ vt as useTypeDefault
1078
1100
  };