@toolbox-web/grid-react 0.0.2
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/README.md +402 -0
- package/index.d.ts +12 -0
- package/index.d.ts.map +1 -0
- package/index.js +541 -0
- package/lib/context-types.d.ts +48 -0
- package/lib/context-types.d.ts.map +1 -0
- package/lib/data-grid.d.ts +155 -0
- package/lib/data-grid.d.ts.map +1 -0
- package/lib/grid-column.d.ts +117 -0
- package/lib/grid-column.d.ts.map +1 -0
- package/lib/grid-detail-panel.d.ts +88 -0
- package/lib/grid-detail-panel.d.ts.map +1 -0
- package/lib/grid-tool-button.d.ts +31 -0
- package/lib/grid-tool-button.d.ts.map +1 -0
- package/lib/grid-tool-panel.d.ts +98 -0
- package/lib/grid-tool-panel.d.ts.map +1 -0
- package/lib/react-column-config.d.ts +71 -0
- package/lib/react-column-config.d.ts.map +1 -0
- package/lib/react-grid-adapter.d.ts +107 -0
- package/lib/react-grid-adapter.d.ts.map +1 -0
- package/lib/use-grid-event.d.ts +73 -0
- package/lib/use-grid-event.d.ts.map +1 -0
- package/lib/use-grid.d.ts +63 -0
- package/lib/use-grid.d.ts.map +1 -0
- package/package.json +50 -0
package/index.js
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
import { jsx as L } from "react/jsx-runtime";
|
|
2
|
+
import { DataGridElement as O } from "@toolbox-web/grid";
|
|
3
|
+
import { useRef as G, useCallback as C, forwardRef as _, useMemo as j, useEffect as R, useImperativeHandle as B, useState as M } from "react";
|
|
4
|
+
import { flushSync as b } from "react-dom";
|
|
5
|
+
import { createRoot as V } from "react-dom/client";
|
|
6
|
+
const F = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new Map();
|
|
7
|
+
function H(n) {
|
|
8
|
+
const t = n.querySelector("tbw-grid-detail");
|
|
9
|
+
if (t) {
|
|
10
|
+
const r = F.get(t);
|
|
11
|
+
if (r) return r;
|
|
12
|
+
}
|
|
13
|
+
const e = n.id || n.getAttribute("data-grid-id");
|
|
14
|
+
if (e)
|
|
15
|
+
return W.get(e);
|
|
16
|
+
}
|
|
17
|
+
function ce(n) {
|
|
18
|
+
const { children: t, showExpandColumn: e = !0, animation: r = "slide" } = n, i = G(null), o = C(
|
|
19
|
+
(d) => {
|
|
20
|
+
if (i.current = d, !d) return;
|
|
21
|
+
F.set(d, t);
|
|
22
|
+
const u = d.closest("tbw-grid");
|
|
23
|
+
if (u) {
|
|
24
|
+
const l = u.id || u.getAttribute("data-grid-id");
|
|
25
|
+
l && W.set(l, t);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
[t]
|
|
29
|
+
);
|
|
30
|
+
return /* @__PURE__ */ L(
|
|
31
|
+
"tbw-grid-detail",
|
|
32
|
+
{
|
|
33
|
+
ref: o,
|
|
34
|
+
showExpandColumn: e ? void 0 : "false",
|
|
35
|
+
animation: r === !1 ? "false" : r
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function $(n) {
|
|
40
|
+
const t = /* @__PURE__ */ new WeakMap();
|
|
41
|
+
return (e) => {
|
|
42
|
+
const r = e.cellEl;
|
|
43
|
+
if (r) {
|
|
44
|
+
const s = t.get(r);
|
|
45
|
+
if (s)
|
|
46
|
+
return b(() => {
|
|
47
|
+
s.root.render(n(e));
|
|
48
|
+
}), s.container;
|
|
49
|
+
}
|
|
50
|
+
const i = document.createElement("div");
|
|
51
|
+
i.className = "react-cell-renderer", i.style.display = "contents";
|
|
52
|
+
const o = V(i);
|
|
53
|
+
return b(() => {
|
|
54
|
+
o.render(n(e));
|
|
55
|
+
}), r && t.set(r, { root: o, container: i }), i;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function J(n) {
|
|
59
|
+
return (t) => {
|
|
60
|
+
const e = document.createElement("div");
|
|
61
|
+
e.className = "react-cell-editor", e.style.display = "contents";
|
|
62
|
+
const r = V(e);
|
|
63
|
+
return b(() => {
|
|
64
|
+
r.render(n(t));
|
|
65
|
+
}), e;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function K(n) {
|
|
69
|
+
if (!n) return;
|
|
70
|
+
if (!n.columns) return n;
|
|
71
|
+
const t = n.columns.map((e) => {
|
|
72
|
+
const { renderer: r, editor: i, ...o } = e, s = { ...o };
|
|
73
|
+
return r && (s.renderer = $(r)), i && (s.editor = J(i)), s;
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
...n,
|
|
77
|
+
columns: t
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const N = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new Map();
|
|
81
|
+
function Q(n) {
|
|
82
|
+
const t = N.get(n);
|
|
83
|
+
if (t) return t;
|
|
84
|
+
const e = n.id;
|
|
85
|
+
if (e)
|
|
86
|
+
return T.get(e);
|
|
87
|
+
}
|
|
88
|
+
function de(n) {
|
|
89
|
+
const { id: t, title: e, icon: r, tooltip: i, order: o = 100, children: s } = n, d = G(null), u = C(
|
|
90
|
+
(l) => {
|
|
91
|
+
d.current = l, l && (N.set(l, s), t && T.set(t, s));
|
|
92
|
+
},
|
|
93
|
+
[s, t]
|
|
94
|
+
);
|
|
95
|
+
return /* @__PURE__ */ L(
|
|
96
|
+
"tbw-grid-tool-panel",
|
|
97
|
+
{
|
|
98
|
+
ref: u,
|
|
99
|
+
id: t,
|
|
100
|
+
title: e,
|
|
101
|
+
icon: r,
|
|
102
|
+
tooltip: i,
|
|
103
|
+
order: o?.toString()
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const S = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new Map();
|
|
108
|
+
function U(n, t) {
|
|
109
|
+
const e = n.getAttribute("field"), r = S.get(n) ?? {};
|
|
110
|
+
if (r.renderer = t, S.set(n, r), e) {
|
|
111
|
+
const i = A.get(e) ?? {};
|
|
112
|
+
i.renderer = t, A.set(e, i);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function X(n, t) {
|
|
116
|
+
const e = n.getAttribute("field"), r = S.get(n) ?? {};
|
|
117
|
+
if (r.editor = t, S.set(n, r), e) {
|
|
118
|
+
const i = A.get(e) ?? {};
|
|
119
|
+
i.editor = t, A.set(e, i);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function Y(n) {
|
|
123
|
+
let t = S.get(n)?.renderer;
|
|
124
|
+
if (!t) {
|
|
125
|
+
const e = n.getAttribute("field");
|
|
126
|
+
e && (t = A.get(e)?.renderer);
|
|
127
|
+
}
|
|
128
|
+
return t;
|
|
129
|
+
}
|
|
130
|
+
function Z(n) {
|
|
131
|
+
let t = S.get(n)?.editor;
|
|
132
|
+
if (!t) {
|
|
133
|
+
const e = n.getAttribute("field");
|
|
134
|
+
e && (t = A.get(e)?.editor);
|
|
135
|
+
}
|
|
136
|
+
return t;
|
|
137
|
+
}
|
|
138
|
+
function ue() {
|
|
139
|
+
return Array.from(A.keys());
|
|
140
|
+
}
|
|
141
|
+
class ee {
|
|
142
|
+
mountedViews = [];
|
|
143
|
+
/**
|
|
144
|
+
* Determines if this adapter can handle the given element.
|
|
145
|
+
* Checks if a renderer or editor is registered for this element.
|
|
146
|
+
*/
|
|
147
|
+
canHandle(t) {
|
|
148
|
+
const e = t.getAttribute("field");
|
|
149
|
+
let r = S.get(t);
|
|
150
|
+
if (!r && e) {
|
|
151
|
+
const s = A.get(e);
|
|
152
|
+
s && (s.renderer || s.editor) && (r = s, S.set(t, r));
|
|
153
|
+
}
|
|
154
|
+
const i = r?.renderer !== void 0, o = r?.editor !== void 0;
|
|
155
|
+
return r !== void 0 && (i || o);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates a view renderer function that renders a React component
|
|
159
|
+
* and returns its container DOM element.
|
|
160
|
+
*
|
|
161
|
+
* Uses a cell cache to reuse React roots for performance - instead of
|
|
162
|
+
* creating new roots on each render, we reuse existing ones and just
|
|
163
|
+
* call root.render() with new data.
|
|
164
|
+
*
|
|
165
|
+
* Returns undefined if no renderer is registered for this element,
|
|
166
|
+
* allowing the grid to use its default rendering.
|
|
167
|
+
*/
|
|
168
|
+
createRenderer(t) {
|
|
169
|
+
const e = Y(t);
|
|
170
|
+
if (!e)
|
|
171
|
+
return;
|
|
172
|
+
const r = /* @__PURE__ */ new WeakMap();
|
|
173
|
+
return (i) => {
|
|
174
|
+
const o = i.cellEl;
|
|
175
|
+
if (o) {
|
|
176
|
+
const u = r.get(o);
|
|
177
|
+
if (u)
|
|
178
|
+
return b(() => {
|
|
179
|
+
u.root.render(e(i));
|
|
180
|
+
}), u.container;
|
|
181
|
+
const l = document.createElement("div");
|
|
182
|
+
l.className = "react-cell-renderer", l.style.display = "contents";
|
|
183
|
+
const w = V(l);
|
|
184
|
+
return b(() => {
|
|
185
|
+
w.render(e(i));
|
|
186
|
+
}), r.set(o, { root: w, container: l, lastRowIndex: i.rowIndex ?? -1 }), this.mountedViews.push({ root: w, container: l }), l;
|
|
187
|
+
}
|
|
188
|
+
const s = document.createElement("div");
|
|
189
|
+
s.className = "react-cell-renderer", s.style.display = "contents";
|
|
190
|
+
const d = V(s);
|
|
191
|
+
return b(() => {
|
|
192
|
+
d.render(e(i));
|
|
193
|
+
}), this.mountedViews.push({ root: d, container: s }), s;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Creates an editor spec that renders a React component
|
|
198
|
+
* with commit/cancel callbacks passed as props.
|
|
199
|
+
*/
|
|
200
|
+
createEditor(t) {
|
|
201
|
+
const e = Z(t);
|
|
202
|
+
return e ? (r) => {
|
|
203
|
+
const i = document.createElement("div");
|
|
204
|
+
i.className = "react-cell-editor", i.style.display = "contents";
|
|
205
|
+
const o = V(i);
|
|
206
|
+
return b(() => {
|
|
207
|
+
o.render(e(r));
|
|
208
|
+
}), this.mountedViews.push({ root: o, container: i }), i;
|
|
209
|
+
} : () => document.createElement("div");
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Creates a detail renderer function for MasterDetailPlugin.
|
|
213
|
+
* Renders React components for expandable detail rows.
|
|
214
|
+
*/
|
|
215
|
+
createDetailRenderer(t) {
|
|
216
|
+
const e = H(t);
|
|
217
|
+
if (e)
|
|
218
|
+
return (r, i) => {
|
|
219
|
+
const o = document.createElement("div");
|
|
220
|
+
o.className = "react-detail-panel";
|
|
221
|
+
const s = { row: r, rowIndex: i }, d = V(o);
|
|
222
|
+
return b(() => {
|
|
223
|
+
d.render(e(s));
|
|
224
|
+
}), this.mountedViews.push({ root: d, container: o }), o;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Framework adapter hook called by MasterDetailPlugin during attach().
|
|
229
|
+
* Parses the <tbw-grid-detail> element and returns a React-based renderer.
|
|
230
|
+
*/
|
|
231
|
+
parseDetailElement(t) {
|
|
232
|
+
const e = t.closest("tbw-grid");
|
|
233
|
+
if (e)
|
|
234
|
+
return this.createDetailRenderer(e);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Creates a tool panel renderer from a light DOM element.
|
|
238
|
+
* Renders React components into tool panel containers.
|
|
239
|
+
*/
|
|
240
|
+
createToolPanelRenderer(t) {
|
|
241
|
+
const e = Q(t);
|
|
242
|
+
if (!e)
|
|
243
|
+
return;
|
|
244
|
+
const r = t.closest("tbw-grid");
|
|
245
|
+
return (i) => {
|
|
246
|
+
const o = {
|
|
247
|
+
grid: r ?? i
|
|
248
|
+
}, s = V(i);
|
|
249
|
+
return b(() => {
|
|
250
|
+
s.render(e(o));
|
|
251
|
+
}), this.mountedViews.push({ root: s, container: i }), () => {
|
|
252
|
+
const d = this.mountedViews.findIndex((u) => u.container === i);
|
|
253
|
+
if (d !== -1) {
|
|
254
|
+
const { root: u } = this.mountedViews[d];
|
|
255
|
+
try {
|
|
256
|
+
u.unmount();
|
|
257
|
+
} catch {
|
|
258
|
+
}
|
|
259
|
+
this.mountedViews.splice(d, 1);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Clean up all mounted React roots.
|
|
266
|
+
* Call this when the grid is unmounted.
|
|
267
|
+
*/
|
|
268
|
+
destroy() {
|
|
269
|
+
this.mountedViews.forEach(({ root: t }) => {
|
|
270
|
+
try {
|
|
271
|
+
t.unmount();
|
|
272
|
+
} catch {
|
|
273
|
+
}
|
|
274
|
+
}), this.mountedViews = [];
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Unmount a specific container (called when cell is recycled).
|
|
278
|
+
*/
|
|
279
|
+
unmount(t) {
|
|
280
|
+
const e = this.mountedViews.findIndex((r) => r.container === t);
|
|
281
|
+
if (e !== -1) {
|
|
282
|
+
const { root: r } = this.mountedViews[e];
|
|
283
|
+
try {
|
|
284
|
+
r.unmount();
|
|
285
|
+
} catch {
|
|
286
|
+
}
|
|
287
|
+
this.mountedViews.splice(e, 1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
let P = !1, x = null;
|
|
292
|
+
function q() {
|
|
293
|
+
return P || (x = new ee(), O.registerAdapter(x), P = !0), x;
|
|
294
|
+
}
|
|
295
|
+
q();
|
|
296
|
+
function te(n, t, e) {
|
|
297
|
+
const r = n, i = r.getPlugin?.(t);
|
|
298
|
+
if (i && typeof i.refreshDetailRenderer == "function") {
|
|
299
|
+
i.refreshDetailRenderer();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const o = n.querySelector("tbw-grid-detail");
|
|
303
|
+
if (!o || !H(n)) return;
|
|
304
|
+
const d = e.createDetailRenderer(n);
|
|
305
|
+
if (!d) return;
|
|
306
|
+
const u = o.getAttribute("animation");
|
|
307
|
+
let l = "slide";
|
|
308
|
+
u === "false" ? l = !1 : u === "fade" && (l = "fade");
|
|
309
|
+
const w = o.getAttribute("showExpandColumn") !== "false", a = new t({
|
|
310
|
+
detailRenderer: d,
|
|
311
|
+
showExpandColumn: w,
|
|
312
|
+
animation: l
|
|
313
|
+
}), m = r.gridConfig || {}, E = m.plugins || [];
|
|
314
|
+
r.gridConfig = {
|
|
315
|
+
...m,
|
|
316
|
+
plugins: [...E, a]
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
const ae = _(function(t, e) {
|
|
320
|
+
const {
|
|
321
|
+
rows: r,
|
|
322
|
+
gridConfig: i,
|
|
323
|
+
columns: o,
|
|
324
|
+
fitMode: s,
|
|
325
|
+
editOn: d,
|
|
326
|
+
customStyles: u,
|
|
327
|
+
className: l,
|
|
328
|
+
style: w,
|
|
329
|
+
children: a,
|
|
330
|
+
onRowsChange: m,
|
|
331
|
+
onCellEdit: E,
|
|
332
|
+
onRowClick: v,
|
|
333
|
+
onColumnStateChange: D,
|
|
334
|
+
onSortChange: I
|
|
335
|
+
} = t, f = G(null), k = G(null), p = j(() => K(i), [i]);
|
|
336
|
+
return R(() => {
|
|
337
|
+
f.current && (f.current.rows = r);
|
|
338
|
+
}, [r]), R(() => {
|
|
339
|
+
f.current && p && (f.current.gridConfig = p);
|
|
340
|
+
}, [p]), R(() => {
|
|
341
|
+
f.current && o && (f.current.columns = o);
|
|
342
|
+
}, [o]), R(() => {
|
|
343
|
+
f.current && s !== void 0 && (f.current.fitMode = s);
|
|
344
|
+
}, [s]), R(() => {
|
|
345
|
+
f.current && d !== void 0 && (f.current.editOn = d);
|
|
346
|
+
}, [d]), R(() => {
|
|
347
|
+
const c = f.current;
|
|
348
|
+
if (!c) return;
|
|
349
|
+
const h = q();
|
|
350
|
+
c.__frameworkAdapter = h;
|
|
351
|
+
let g = !1;
|
|
352
|
+
const y = requestAnimationFrame(() => {
|
|
353
|
+
g || (typeof c.refreshColumns == "function" && c.refreshColumns(), import("@toolbox-web/grid/all").then(({ MasterDetailPlugin: z }) => {
|
|
354
|
+
g || te(c, z, h);
|
|
355
|
+
}).catch(() => {
|
|
356
|
+
}), typeof c.refreshShellHeader == "function" && c.refreshShellHeader());
|
|
357
|
+
});
|
|
358
|
+
return () => {
|
|
359
|
+
g = !0, cancelAnimationFrame(y);
|
|
360
|
+
};
|
|
361
|
+
}, []), R(() => {
|
|
362
|
+
if (!f.current || !u) return;
|
|
363
|
+
const c = f.current, h = "react-custom-styles";
|
|
364
|
+
let g = !0;
|
|
365
|
+
return c.ready?.().then(() => {
|
|
366
|
+
g && u && (c.registerStyles?.(h, u), k.current = h);
|
|
367
|
+
}), () => {
|
|
368
|
+
g = !1, k.current && (c.unregisterStyles?.(k.current), k.current = null);
|
|
369
|
+
};
|
|
370
|
+
}, [u]), R(() => {
|
|
371
|
+
const c = f.current;
|
|
372
|
+
if (!c) return;
|
|
373
|
+
const h = [];
|
|
374
|
+
if (m) {
|
|
375
|
+
const g = ((y) => m(y.detail.rows));
|
|
376
|
+
c.addEventListener("rows-change", g), h.push(["rows-change", g]);
|
|
377
|
+
}
|
|
378
|
+
if (E) {
|
|
379
|
+
const g = ((y) => E(y));
|
|
380
|
+
c.addEventListener("cell-edit", g), h.push(["cell-edit", g]);
|
|
381
|
+
}
|
|
382
|
+
if (v) {
|
|
383
|
+
const g = ((y) => v(y));
|
|
384
|
+
c.addEventListener("row-click", g), h.push(["row-click", g]);
|
|
385
|
+
}
|
|
386
|
+
if (D) {
|
|
387
|
+
const g = ((y) => D(y));
|
|
388
|
+
c.addEventListener("column-state-change", g), h.push(["column-state-change", g]);
|
|
389
|
+
}
|
|
390
|
+
if (I) {
|
|
391
|
+
const g = ((y) => I(y));
|
|
392
|
+
c.addEventListener("sort-change", g), h.push(["sort-change", g]);
|
|
393
|
+
}
|
|
394
|
+
return () => {
|
|
395
|
+
h.forEach(([g, y]) => {
|
|
396
|
+
c.removeEventListener(g, y);
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
}, [m, E, v, D, I]), B(
|
|
400
|
+
e,
|
|
401
|
+
() => ({
|
|
402
|
+
get element() {
|
|
403
|
+
return f.current;
|
|
404
|
+
},
|
|
405
|
+
async getConfig() {
|
|
406
|
+
return f.current?.getConfig?.() ?? {};
|
|
407
|
+
},
|
|
408
|
+
async ready() {
|
|
409
|
+
return f.current?.ready?.();
|
|
410
|
+
},
|
|
411
|
+
async forceLayout() {
|
|
412
|
+
return f.current?.forceLayout?.();
|
|
413
|
+
},
|
|
414
|
+
async toggleGroup(c) {
|
|
415
|
+
return f.current?.toggleGroup?.(c);
|
|
416
|
+
},
|
|
417
|
+
registerStyles(c, h) {
|
|
418
|
+
f.current?.registerStyles?.(c, h);
|
|
419
|
+
},
|
|
420
|
+
unregisterStyles(c) {
|
|
421
|
+
f.current?.unregisterStyles?.(c);
|
|
422
|
+
}
|
|
423
|
+
}),
|
|
424
|
+
[]
|
|
425
|
+
), /* @__PURE__ */ L(
|
|
426
|
+
"tbw-grid",
|
|
427
|
+
{
|
|
428
|
+
ref: (c) => {
|
|
429
|
+
if (f.current = c, c) {
|
|
430
|
+
const h = c;
|
|
431
|
+
i && (h.gridConfig = i), r && (h.rows = r), o && (h.columns = o);
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
class: l,
|
|
435
|
+
style: w,
|
|
436
|
+
children: a
|
|
437
|
+
}
|
|
438
|
+
);
|
|
439
|
+
});
|
|
440
|
+
function le(n) {
|
|
441
|
+
const {
|
|
442
|
+
field: t,
|
|
443
|
+
header: e,
|
|
444
|
+
type: r,
|
|
445
|
+
editable: i,
|
|
446
|
+
sortable: o,
|
|
447
|
+
resizable: s,
|
|
448
|
+
width: d,
|
|
449
|
+
minWidth: u,
|
|
450
|
+
hidden: l,
|
|
451
|
+
lockVisible: w,
|
|
452
|
+
children: a,
|
|
453
|
+
editor: m,
|
|
454
|
+
options: E,
|
|
455
|
+
multi: v,
|
|
456
|
+
format: D
|
|
457
|
+
} = n, I = G(null), f = C(
|
|
458
|
+
(c) => {
|
|
459
|
+
I.current = c, c && (a && U(c, a), m && X(c, m));
|
|
460
|
+
},
|
|
461
|
+
[a, m, t]
|
|
462
|
+
), k = typeof d == "number" ? `${d}px` : d, p = {
|
|
463
|
+
field: t,
|
|
464
|
+
ref: f
|
|
465
|
+
};
|
|
466
|
+
return e !== void 0 && (p.header = e), r !== void 0 && (p.type = r), i !== void 0 && (p.editable = i), o !== void 0 && (p.sortable = o), s !== void 0 && (p.resizable = s), k !== void 0 && (p.width = k), u !== void 0 && (p["min-width"] = u), l !== void 0 && (p.hidden = l), w !== void 0 && (p["lock-visible"] = w), v !== void 0 && (p.multi = v), D && (p["data-has-format"] = "true"), E && (p["data-has-options"] = "true"), /* @__PURE__ */ L("tbw-grid-column", { ...p });
|
|
467
|
+
}
|
|
468
|
+
function fe({ children: n }) {
|
|
469
|
+
return /* @__PURE__ */ L("tbw-grid-tool-buttons", { children: n });
|
|
470
|
+
}
|
|
471
|
+
function ge() {
|
|
472
|
+
const n = G(null), [t, e] = M(!1), [r, i] = M(null);
|
|
473
|
+
R(() => {
|
|
474
|
+
const a = n.current;
|
|
475
|
+
if (!a) return;
|
|
476
|
+
let m = !0;
|
|
477
|
+
return (async () => {
|
|
478
|
+
try {
|
|
479
|
+
if (await a.ready?.(), m) {
|
|
480
|
+
e(!0);
|
|
481
|
+
const v = await a.getConfig?.();
|
|
482
|
+
m && v && i(v);
|
|
483
|
+
}
|
|
484
|
+
} catch {
|
|
485
|
+
}
|
|
486
|
+
})(), () => {
|
|
487
|
+
m = !1;
|
|
488
|
+
};
|
|
489
|
+
}, []);
|
|
490
|
+
const o = C(async () => {
|
|
491
|
+
const a = n.current;
|
|
492
|
+
return a ? await a.getConfig?.() ?? null : null;
|
|
493
|
+
}, []), s = C(async () => {
|
|
494
|
+
const a = n.current;
|
|
495
|
+
a && await a.forceLayout?.();
|
|
496
|
+
}, []), d = C(async (a) => {
|
|
497
|
+
const m = n.current;
|
|
498
|
+
m && await m.toggleGroup?.(a);
|
|
499
|
+
}, []), u = C((a, m) => {
|
|
500
|
+
n.current?.registerStyles?.(a, m);
|
|
501
|
+
}, []), l = C((a) => {
|
|
502
|
+
n.current?.unregisterStyles?.(a);
|
|
503
|
+
}, []), w = C(() => r?.columns ? r.columns.filter((a) => !a.hidden) : [], [r]);
|
|
504
|
+
return {
|
|
505
|
+
ref: n,
|
|
506
|
+
isReady: t,
|
|
507
|
+
config: r,
|
|
508
|
+
getConfig: o,
|
|
509
|
+
forceLayout: s,
|
|
510
|
+
toggleGroup: d,
|
|
511
|
+
registerStyles: u,
|
|
512
|
+
unregisterStyles: l,
|
|
513
|
+
getVisibleColumns: w
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function me(n, t, e, r = []) {
|
|
517
|
+
const i = G(e);
|
|
518
|
+
R(() => {
|
|
519
|
+
i.current = e;
|
|
520
|
+
}, [e, ...r]), R(() => {
|
|
521
|
+
const o = n.current, s = o && "element" in o ? o.element : o;
|
|
522
|
+
if (!s) return;
|
|
523
|
+
const d = ((u) => {
|
|
524
|
+
i.current(u);
|
|
525
|
+
});
|
|
526
|
+
return s.addEventListener(t, d), () => {
|
|
527
|
+
s.removeEventListener(t, d);
|
|
528
|
+
};
|
|
529
|
+
}, [n, t]);
|
|
530
|
+
}
|
|
531
|
+
export {
|
|
532
|
+
ae as DataGrid,
|
|
533
|
+
le as GridColumn,
|
|
534
|
+
ce as GridDetailPanel,
|
|
535
|
+
fe as GridToolButtons,
|
|
536
|
+
de as GridToolPanel,
|
|
537
|
+
ee as ReactGridAdapter,
|
|
538
|
+
ue as getRegisteredFields,
|
|
539
|
+
ge as useGrid,
|
|
540
|
+
me as useGridEvent
|
|
541
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ColumnConfig } from '../../../../dist/libs/grid/index.d.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Context object passed to cell renderer components.
|
|
4
|
+
*/
|
|
5
|
+
export interface GridCellContext<TValue = unknown, TRow = unknown> {
|
|
6
|
+
/** The cell value for this column */
|
|
7
|
+
value: TValue;
|
|
8
|
+
/** The full row data object */
|
|
9
|
+
row: TRow;
|
|
10
|
+
/** The column configuration */
|
|
11
|
+
column: ColumnConfig<TRow>;
|
|
12
|
+
/** Field key */
|
|
13
|
+
field: keyof TRow & string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Context object passed to cell editor components.
|
|
17
|
+
*/
|
|
18
|
+
export interface GridEditorContext<TValue = unknown, TRow = unknown> {
|
|
19
|
+
/** The cell value for this column */
|
|
20
|
+
value: TValue;
|
|
21
|
+
/** The full row data object */
|
|
22
|
+
row: TRow;
|
|
23
|
+
/** The column configuration */
|
|
24
|
+
column: ColumnConfig<TRow>;
|
|
25
|
+
/** Field key */
|
|
26
|
+
field: keyof TRow & string;
|
|
27
|
+
/** Commit the new value and close editor */
|
|
28
|
+
commit: (newValue: TValue) => void;
|
|
29
|
+
/** Cancel editing without saving */
|
|
30
|
+
cancel: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Context object passed to detail panel components.
|
|
34
|
+
*/
|
|
35
|
+
export interface GridDetailContext<TRow = unknown> {
|
|
36
|
+
/** The row data object */
|
|
37
|
+
row: TRow;
|
|
38
|
+
/** Row index */
|
|
39
|
+
rowIndex: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Context object passed to tool panel components.
|
|
43
|
+
*/
|
|
44
|
+
export interface GridToolPanelContext {
|
|
45
|
+
/** Reference to the grid element */
|
|
46
|
+
grid: HTMLElement;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=context-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-types.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/lib/context-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,MAAM,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO;IAC/D,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,+BAA+B;IAC/B,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,gBAAgB;IAChB,KAAK,EAAE,MAAM,IAAI,GAAG,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO;IACjE,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,+BAA+B;IAC/B,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,gBAAgB;IAChB,KAAK,EAAE,MAAM,IAAI,GAAG,MAAM,CAAC;IAC3B,4CAA4C;IAC5C,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,oCAAoC;IACpC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,IAAI,GAAG,OAAO;IAC/C,0BAA0B;IAC1B,GAAG,EAAE,IAAI,CAAC;IACV,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,oCAAoC;IACpC,IAAI,EAAE,WAAW,CAAC;CACnB"}
|