@toolbox-web/grid-react 0.2.0 → 0.3.1
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 +78 -12
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +273 -187
- package/lib/data-grid.d.ts.map +1 -1
- package/lib/grid-type-registry.d.ts +122 -0
- package/lib/grid-type-registry.d.ts.map +1 -0
- package/lib/react-grid-adapter.d.ts +45 -1
- package/lib/react-grid-adapter.d.ts.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ React adapter for `@toolbox-web/grid` data grid component. Provides components a
|
|
|
11
11
|
- ✅ **Full React integration** - Use JSX for cell renderers and editors
|
|
12
12
|
- ✅ **Declarative columns** - Define columns via props or `GridColumn` components
|
|
13
13
|
- ✅ **Render props** - Clean `children` syntax for custom cells
|
|
14
|
+
- ✅ **Type-level defaults** - App-wide renderers/editors via `GridTypeProvider`
|
|
14
15
|
- ✅ **Hooks API** - `useGrid` and `useGridEvent` for programmatic access
|
|
15
16
|
- ✅ **Ref forwarding** - Access grid instance via `DataGridRef`
|
|
16
17
|
- ✅ **Master-detail** - `GridDetailPanel` for expandable rows
|
|
@@ -352,6 +353,65 @@ function MyComponent() {
|
|
|
352
353
|
|
|
353
354
|
See [useGridEvent](#usegridevent) above.
|
|
354
355
|
|
|
356
|
+
## Type-Level Defaults
|
|
357
|
+
|
|
358
|
+
Define app-wide renderers and editors for custom column types using `GridTypeProvider`:
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
import { GridTypeProvider, DataGrid, type TypeDefaultsMap } from '@toolbox-web/grid-react';
|
|
362
|
+
import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';
|
|
363
|
+
|
|
364
|
+
// Define type defaults at app level
|
|
365
|
+
const typeDefaults: TypeDefaultsMap = {
|
|
366
|
+
country: {
|
|
367
|
+
renderer: (ctx) => <span>🌍 {ctx.value}</span>,
|
|
368
|
+
editor: (ctx) => (
|
|
369
|
+
<select defaultValue={ctx.value} onChange={(e) => ctx.commit(e.target.value)}>
|
|
370
|
+
<option value="USA">USA</option>
|
|
371
|
+
<option value="UK">UK</option>
|
|
372
|
+
<option value="Germany">Germany</option>
|
|
373
|
+
</select>
|
|
374
|
+
),
|
|
375
|
+
},
|
|
376
|
+
currency: {
|
|
377
|
+
renderer: (ctx) => <span>${ctx.value.toFixed(2)}</span>,
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// Wrap your app with the provider
|
|
382
|
+
function App() {
|
|
383
|
+
return (
|
|
384
|
+
<GridTypeProvider defaults={typeDefaults}>
|
|
385
|
+
<Dashboard />
|
|
386
|
+
</GridTypeProvider>
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// All grids with type: 'country' columns use these components
|
|
391
|
+
function Dashboard() {
|
|
392
|
+
return (
|
|
393
|
+
<DataGrid
|
|
394
|
+
rows={employees}
|
|
395
|
+
gridConfig={{
|
|
396
|
+
columns: [
|
|
397
|
+
{ field: 'name', header: 'Name' },
|
|
398
|
+
{ field: 'country', type: 'country', editable: true },
|
|
399
|
+
{ field: 'salary', type: 'currency' },
|
|
400
|
+
],
|
|
401
|
+
plugins: [new EditingPlugin()],
|
|
402
|
+
}}
|
|
403
|
+
/>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
**Hooks:**
|
|
409
|
+
|
|
410
|
+
| Hook | Description |
|
|
411
|
+
| ----------------------- | ---------------------------------- |
|
|
412
|
+
| `useGridTypeDefaults()` | Get all type defaults from context |
|
|
413
|
+
| `useTypeDefault(type)` | Get defaults for a specific type |
|
|
414
|
+
|
|
355
415
|
## Using Plugins
|
|
356
416
|
|
|
357
417
|
Import plugins individually for smaller bundles:
|
|
@@ -403,20 +463,23 @@ Inject custom CSS into the grid:
|
|
|
403
463
|
|
|
404
464
|
### Exported Components
|
|
405
465
|
|
|
406
|
-
| Component
|
|
407
|
-
|
|
|
408
|
-
| `DataGrid`
|
|
409
|
-
| `GridColumn`
|
|
410
|
-
| `GridDetailPanel`
|
|
411
|
-
| `GridToolPanel`
|
|
412
|
-
| `GridToolButtons`
|
|
466
|
+
| Component | Description |
|
|
467
|
+
| ------------------ | ------------------------------------ |
|
|
468
|
+
| `DataGrid` | Main grid component wrapper |
|
|
469
|
+
| `GridColumn` | Declarative column with render props |
|
|
470
|
+
| `GridDetailPanel` | Master-detail expandable panel |
|
|
471
|
+
| `GridToolPanel` | Custom sidebar panel |
|
|
472
|
+
| `GridToolButtons` | Toolbar button container |
|
|
473
|
+
| `GridTypeProvider` | App-level type defaults context |
|
|
413
474
|
|
|
414
475
|
### Exported Hooks
|
|
415
476
|
|
|
416
|
-
| Hook
|
|
417
|
-
|
|
|
418
|
-
| `useGrid`
|
|
419
|
-
| `useGridEvent`
|
|
477
|
+
| Hook | Description |
|
|
478
|
+
| ----------------------- | ----------------------------------------- |
|
|
479
|
+
| `useGrid` | Grid ref with ready state and methods |
|
|
480
|
+
| `useGridEvent` | Type-safe event subscription with cleanup |
|
|
481
|
+
| `useGridTypeDefaults()` | Get all type defaults from context |
|
|
482
|
+
| `useTypeDefault(type)` | Get defaults for a specific type |
|
|
420
483
|
|
|
421
484
|
### Exported Types
|
|
422
485
|
|
|
@@ -430,6 +493,10 @@ import type {
|
|
|
430
493
|
ToolPanelContext,
|
|
431
494
|
DataGridRef,
|
|
432
495
|
DataGridProps,
|
|
496
|
+
// Type-level defaults
|
|
497
|
+
ReactTypeDefault,
|
|
498
|
+
TypeDefaultsMap,
|
|
499
|
+
GridTypeProviderProps,
|
|
433
500
|
} from '@toolbox-web/grid-react';
|
|
434
501
|
```
|
|
435
502
|
|
|
@@ -441,7 +508,6 @@ import type {
|
|
|
441
508
|
| `columns` | `ColumnConfig[]` | Column definitions |
|
|
442
509
|
| `gridConfig` | `GridConfig` | Full configuration object |
|
|
443
510
|
| `fitMode` | `'stretch' \| 'fit-columns' \| 'auto-fit'` | Column sizing mode |
|
|
444
|
-
| `editOn` | `'click' \| 'dblclick' \| 'none'` | Edit trigger |
|
|
445
511
|
| `customStyles` | `string` | CSS to inject into grid |
|
|
446
512
|
| `onRowsChange` | `(rows: TRow[]) => void` | Rows changed callback |
|
|
447
513
|
| `onCellEdit` | `(event: CustomEvent) => void` | Cell edited callback |
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { GridColumn } from './lib/grid-column';
|
|
|
3
3
|
export { GridDetailPanel, type DetailPanelContext, type GridDetailPanelProps } from './lib/grid-detail-panel';
|
|
4
4
|
export { GridToolButtons, type GridToolButtonsProps } from './lib/grid-tool-button';
|
|
5
5
|
export { GridToolPanel, type GridToolPanelProps, type ToolPanelContext } from './lib/grid-tool-panel';
|
|
6
|
+
export { GridTypeProvider, useGridTypeDefaults, useTypeDefault, type GridTypeProviderProps, type ReactTypeDefault, type TypeDefaultsMap, } from './lib/grid-type-registry';
|
|
6
7
|
export type { ReactColumnConfig, ReactGridConfig } from './lib/react-column-config';
|
|
7
8
|
export { useGrid } from './lib/use-grid';
|
|
8
9
|
export { useGridEvent } from './lib/use-grid-event';
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../libs/grid-react/src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../libs/grid-react/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,YAAY,CAAC;AAGpB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC9G,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGtG,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAGpF,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAGjF,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGvH,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
|
package/index.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { DataGridElement as
|
|
3
|
-
import { useRef as
|
|
4
|
-
import { flushSync as
|
|
5
|
-
import { createRoot as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
1
|
+
import { jsx as T } from "react/jsx-runtime";
|
|
2
|
+
import { DataGridElement as _ } from "@toolbox-web/grid";
|
|
3
|
+
import { useRef as k, useCallback as D, createContext as j, useContext as F, forwardRef as $, useMemo as J, useEffect as v, useImperativeHandle as K, useState as N } from "react";
|
|
4
|
+
import { flushSync as R } from "react-dom";
|
|
5
|
+
import { createRoot as b } from "react-dom/client";
|
|
6
|
+
const H = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new Map();
|
|
7
|
+
function z(n) {
|
|
8
8
|
const t = n.querySelector("tbw-grid-detail");
|
|
9
9
|
if (t) {
|
|
10
|
-
const r =
|
|
10
|
+
const r = H.get(t);
|
|
11
11
|
if (r) return r;
|
|
12
12
|
}
|
|
13
13
|
const e = n.id || n.getAttribute("data-grid-id");
|
|
14
14
|
if (e)
|
|
15
|
-
return
|
|
15
|
+
return q.get(e);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const { children: t, showExpandColumn: e = !0, animation: r = "slide" } = n, i =
|
|
19
|
-
(
|
|
20
|
-
if (i.current =
|
|
21
|
-
|
|
22
|
-
const u =
|
|
17
|
+
function le(n) {
|
|
18
|
+
const { children: t, showExpandColumn: e = !0, animation: r = "slide" } = n, i = k(null), s = D(
|
|
19
|
+
(c) => {
|
|
20
|
+
if (i.current = c, !c) return;
|
|
21
|
+
H.set(c, t);
|
|
22
|
+
const u = c.closest("tbw-grid");
|
|
23
23
|
if (u) {
|
|
24
24
|
const l = u.id || u.getAttribute("data-grid-id");
|
|
25
|
-
l &&
|
|
25
|
+
l && q.set(l, t);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
[t]
|
|
29
29
|
);
|
|
30
|
-
return /* @__PURE__ */
|
|
30
|
+
return /* @__PURE__ */ T(
|
|
31
31
|
"tbw-grid-detail",
|
|
32
32
|
{
|
|
33
33
|
ref: s,
|
|
@@ -36,63 +36,71 @@ function se(n) {
|
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
const L = j(null), fe = ({ defaults: n, children: t }) => /* @__PURE__ */ T(L.Provider, { value: n, children: t });
|
|
40
|
+
function ge() {
|
|
41
|
+
return F(L);
|
|
42
|
+
}
|
|
43
|
+
function me(n) {
|
|
44
|
+
return F(L)?.[n];
|
|
45
|
+
}
|
|
46
|
+
const Q = L;
|
|
47
|
+
function U(n) {
|
|
40
48
|
const t = /* @__PURE__ */ new WeakMap();
|
|
41
49
|
return (e) => {
|
|
42
50
|
const r = e.cellEl;
|
|
43
51
|
if (r) {
|
|
44
52
|
const o = t.get(r);
|
|
45
53
|
if (o)
|
|
46
|
-
return
|
|
54
|
+
return R(() => {
|
|
47
55
|
o.root.render(n(e));
|
|
48
56
|
}), o.container;
|
|
49
57
|
}
|
|
50
58
|
const i = document.createElement("div");
|
|
51
59
|
i.className = "react-cell-renderer", i.style.display = "contents";
|
|
52
|
-
const s =
|
|
53
|
-
return
|
|
60
|
+
const s = b(i);
|
|
61
|
+
return R(() => {
|
|
54
62
|
s.render(n(e));
|
|
55
63
|
}), r && t.set(r, { root: s, container: i }), i;
|
|
56
64
|
};
|
|
57
65
|
}
|
|
58
|
-
function
|
|
66
|
+
function X(n) {
|
|
59
67
|
return (t) => {
|
|
60
68
|
const e = document.createElement("div");
|
|
61
69
|
e.className = "react-cell-editor", e.style.display = "contents";
|
|
62
|
-
const r =
|
|
63
|
-
return
|
|
70
|
+
const r = b(e);
|
|
71
|
+
return R(() => {
|
|
64
72
|
r.render(n(t));
|
|
65
73
|
}), e;
|
|
66
74
|
};
|
|
67
75
|
}
|
|
68
|
-
function
|
|
76
|
+
function Y(n) {
|
|
69
77
|
if (!n) return;
|
|
70
78
|
if (!n.columns) return n;
|
|
71
79
|
const t = n.columns.map((e) => {
|
|
72
80
|
const { renderer: r, editor: i, ...s } = e, o = { ...s };
|
|
73
|
-
return r && (o.renderer =
|
|
81
|
+
return r && (o.renderer = U(r)), i && (o.editor = X(i)), o;
|
|
74
82
|
});
|
|
75
83
|
return {
|
|
76
84
|
...n,
|
|
77
85
|
columns: t
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
|
-
const
|
|
81
|
-
function
|
|
82
|
-
const t =
|
|
88
|
+
const B = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new Map();
|
|
89
|
+
function Z(n) {
|
|
90
|
+
const t = B.get(n);
|
|
83
91
|
if (t) return t;
|
|
84
92
|
const e = n.id;
|
|
85
93
|
if (e)
|
|
86
|
-
return
|
|
94
|
+
return O.get(e);
|
|
87
95
|
}
|
|
88
|
-
function
|
|
89
|
-
const { id: t, title: e, icon: r, tooltip: i, order: s = 100, children: o } = n,
|
|
96
|
+
function pe(n) {
|
|
97
|
+
const { id: t, title: e, icon: r, tooltip: i, order: s = 100, children: o } = n, c = k(null), u = D(
|
|
90
98
|
(l) => {
|
|
91
|
-
|
|
99
|
+
c.current = l, l && (B.set(l, o), t && O.set(t, o));
|
|
92
100
|
},
|
|
93
101
|
[o, t]
|
|
94
102
|
);
|
|
95
|
-
return /* @__PURE__ */
|
|
103
|
+
return /* @__PURE__ */ T(
|
|
96
104
|
"tbw-grid-tool-panel",
|
|
97
105
|
{
|
|
98
106
|
ref: u,
|
|
@@ -104,52 +112,62 @@ function ce(n) {
|
|
|
104
112
|
}
|
|
105
113
|
);
|
|
106
114
|
}
|
|
107
|
-
const
|
|
108
|
-
function
|
|
109
|
-
const e = n.getAttribute("field"), r =
|
|
110
|
-
if (r.renderer = t,
|
|
111
|
-
const i =
|
|
112
|
-
i.renderer = t,
|
|
115
|
+
const A = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new Map();
|
|
116
|
+
function ee(n, t) {
|
|
117
|
+
const e = n.getAttribute("field"), r = A.get(n) ?? {};
|
|
118
|
+
if (r.renderer = t, A.set(n, r), e) {
|
|
119
|
+
const i = G.get(e) ?? {};
|
|
120
|
+
i.renderer = t, G.set(e, i);
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
|
-
function
|
|
116
|
-
const e = n.getAttribute("field"), r =
|
|
117
|
-
if (r.editor = t,
|
|
118
|
-
const i =
|
|
119
|
-
i.editor = t,
|
|
123
|
+
function te(n, t) {
|
|
124
|
+
const e = n.getAttribute("field"), r = A.get(n) ?? {};
|
|
125
|
+
if (r.editor = t, A.set(n, r), e) {
|
|
126
|
+
const i = G.get(e) ?? {};
|
|
127
|
+
i.editor = t, G.set(e, i);
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
|
-
function
|
|
123
|
-
let t =
|
|
130
|
+
function re(n) {
|
|
131
|
+
let t = A.get(n)?.renderer;
|
|
124
132
|
if (!t) {
|
|
125
133
|
const e = n.getAttribute("field");
|
|
126
|
-
e && (t =
|
|
134
|
+
e && (t = G.get(e)?.renderer);
|
|
127
135
|
}
|
|
128
136
|
return t;
|
|
129
137
|
}
|
|
130
|
-
function
|
|
131
|
-
let t =
|
|
138
|
+
function ne(n) {
|
|
139
|
+
let t = A.get(n)?.editor;
|
|
132
140
|
if (!t) {
|
|
133
141
|
const e = n.getAttribute("field");
|
|
134
|
-
e && (t =
|
|
142
|
+
e && (t = G.get(e)?.editor);
|
|
135
143
|
}
|
|
136
144
|
return t;
|
|
137
145
|
}
|
|
138
|
-
function
|
|
139
|
-
return Array.from(
|
|
146
|
+
function ye() {
|
|
147
|
+
return Array.from(G.keys());
|
|
140
148
|
}
|
|
141
|
-
class
|
|
149
|
+
class ie {
|
|
142
150
|
mountedViews = [];
|
|
151
|
+
typeDefaults = null;
|
|
152
|
+
/**
|
|
153
|
+
* Sets the type defaults map for this adapter.
|
|
154
|
+
* Called by DataGrid when it receives type defaults from context.
|
|
155
|
+
*
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
setTypeDefaults(t) {
|
|
159
|
+
this.typeDefaults = t;
|
|
160
|
+
}
|
|
143
161
|
/**
|
|
144
162
|
* Determines if this adapter can handle the given element.
|
|
145
163
|
* Checks if a renderer or editor is registered for this element.
|
|
146
164
|
*/
|
|
147
165
|
canHandle(t) {
|
|
148
166
|
const e = t.getAttribute("field");
|
|
149
|
-
let r =
|
|
167
|
+
let r = A.get(t);
|
|
150
168
|
if (!r && e) {
|
|
151
|
-
const o =
|
|
152
|
-
o && (o.renderer || o.editor) && (r = o,
|
|
169
|
+
const o = G.get(e);
|
|
170
|
+
o && (o.renderer || o.editor) && (r = o, A.set(t, r));
|
|
153
171
|
}
|
|
154
172
|
const i = r?.renderer !== void 0, s = r?.editor !== void 0;
|
|
155
173
|
return r !== void 0 && (i || s);
|
|
@@ -166,7 +184,7 @@ class Z {
|
|
|
166
184
|
* allowing the grid to use its default rendering.
|
|
167
185
|
*/
|
|
168
186
|
createRenderer(t) {
|
|
169
|
-
const e =
|
|
187
|
+
const e = re(t);
|
|
170
188
|
if (!e)
|
|
171
189
|
return;
|
|
172
190
|
const r = /* @__PURE__ */ new WeakMap();
|
|
@@ -175,22 +193,22 @@ class Z {
|
|
|
175
193
|
if (s) {
|
|
176
194
|
const u = r.get(s);
|
|
177
195
|
if (u)
|
|
178
|
-
return
|
|
196
|
+
return R(() => {
|
|
179
197
|
u.root.render(e(i));
|
|
180
198
|
}), u.container;
|
|
181
199
|
const l = document.createElement("div");
|
|
182
200
|
l.className = "react-cell-renderer", l.style.display = "contents";
|
|
183
|
-
const w =
|
|
184
|
-
return
|
|
201
|
+
const w = b(l);
|
|
202
|
+
return R(() => {
|
|
185
203
|
w.render(e(i));
|
|
186
204
|
}), r.set(s, { root: w, container: l, lastRowIndex: i.rowIndex ?? -1 }), this.mountedViews.push({ root: w, container: l }), l;
|
|
187
205
|
}
|
|
188
206
|
const o = document.createElement("div");
|
|
189
207
|
o.className = "react-cell-renderer", o.style.display = "contents";
|
|
190
|
-
const
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
}), this.mountedViews.push({ root:
|
|
208
|
+
const c = b(o);
|
|
209
|
+
return R(() => {
|
|
210
|
+
c.render(e(i));
|
|
211
|
+
}), this.mountedViews.push({ root: c, container: o }), o;
|
|
194
212
|
};
|
|
195
213
|
}
|
|
196
214
|
/**
|
|
@@ -198,12 +216,12 @@ class Z {
|
|
|
198
216
|
* with commit/cancel callbacks passed as props.
|
|
199
217
|
*/
|
|
200
218
|
createEditor(t) {
|
|
201
|
-
const e =
|
|
219
|
+
const e = ne(t);
|
|
202
220
|
return e ? (r) => {
|
|
203
221
|
const i = document.createElement("div");
|
|
204
222
|
i.className = "react-cell-editor", i.style.display = "contents";
|
|
205
|
-
const s =
|
|
206
|
-
return
|
|
223
|
+
const s = b(i);
|
|
224
|
+
return R(() => {
|
|
207
225
|
s.render(e(r));
|
|
208
226
|
}), this.mountedViews.push({ root: s, container: i }), i;
|
|
209
227
|
} : () => document.createElement("div");
|
|
@@ -213,15 +231,15 @@ class Z {
|
|
|
213
231
|
* Renders React components for expandable detail rows.
|
|
214
232
|
*/
|
|
215
233
|
createDetailRenderer(t) {
|
|
216
|
-
const e =
|
|
234
|
+
const e = z(t);
|
|
217
235
|
if (e)
|
|
218
236
|
return (r, i) => {
|
|
219
237
|
const s = document.createElement("div");
|
|
220
238
|
s.className = "react-detail-panel";
|
|
221
|
-
const o = { row: r, rowIndex: i },
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
}), this.mountedViews.push({ root:
|
|
239
|
+
const o = { row: r, rowIndex: i }, c = b(s);
|
|
240
|
+
return R(() => {
|
|
241
|
+
c.render(e(o));
|
|
242
|
+
}), this.mountedViews.push({ root: c, container: s }), s;
|
|
225
243
|
};
|
|
226
244
|
}
|
|
227
245
|
/**
|
|
@@ -238,29 +256,92 @@ class Z {
|
|
|
238
256
|
* Renders React components into tool panel containers.
|
|
239
257
|
*/
|
|
240
258
|
createToolPanelRenderer(t) {
|
|
241
|
-
const e =
|
|
259
|
+
const e = Z(t);
|
|
242
260
|
if (!e)
|
|
243
261
|
return;
|
|
244
262
|
const r = t.closest("tbw-grid");
|
|
245
263
|
return (i) => {
|
|
246
264
|
const s = {
|
|
247
265
|
grid: r ?? i
|
|
248
|
-
}, o =
|
|
249
|
-
return
|
|
266
|
+
}, o = b(i);
|
|
267
|
+
return R(() => {
|
|
250
268
|
o.render(e(s));
|
|
251
269
|
}), this.mountedViews.push({ root: o, container: i }), () => {
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
const { root: u } = this.mountedViews[
|
|
270
|
+
const c = this.mountedViews.findIndex((u) => u.container === i);
|
|
271
|
+
if (c !== -1) {
|
|
272
|
+
const { root: u } = this.mountedViews[c];
|
|
255
273
|
try {
|
|
256
274
|
u.unmount();
|
|
257
275
|
} catch {
|
|
258
276
|
}
|
|
259
|
-
this.mountedViews.splice(
|
|
277
|
+
this.mountedViews.splice(c, 1);
|
|
260
278
|
}
|
|
261
279
|
};
|
|
262
280
|
};
|
|
263
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Gets type-level defaults from the type defaults map.
|
|
284
|
+
*
|
|
285
|
+
* This enables application-wide type defaults configured via GridTypeProvider.
|
|
286
|
+
* The returned TypeDefault contains renderer/editor functions that render
|
|
287
|
+
* React components into the grid's cells.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* // App.tsx
|
|
292
|
+
* const typeDefaults = {
|
|
293
|
+
* country: {
|
|
294
|
+
* renderer: (ctx) => <CountryBadge code={ctx.value} />,
|
|
295
|
+
* editor: (ctx) => <CountrySelect value={ctx.value} onCommit={ctx.commit} />
|
|
296
|
+
* }
|
|
297
|
+
* };
|
|
298
|
+
*
|
|
299
|
+
* <GridTypeProvider defaults={typeDefaults}>
|
|
300
|
+
* <App />
|
|
301
|
+
* </GridTypeProvider>
|
|
302
|
+
*
|
|
303
|
+
* // Any grid with type: 'country' columns will use these components
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
getTypeDefault(t) {
|
|
307
|
+
if (!this.typeDefaults)
|
|
308
|
+
return;
|
|
309
|
+
const e = this.typeDefaults[t];
|
|
310
|
+
if (!e)
|
|
311
|
+
return;
|
|
312
|
+
const r = {
|
|
313
|
+
editorParams: e.editorParams
|
|
314
|
+
};
|
|
315
|
+
return e.renderer && (r.renderer = this.createTypeRenderer(e.renderer)), e.editor && (r.editor = this.createTypeEditor(e.editor)), r;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Creates a renderer function from a React render function for type defaults.
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
321
|
+
createTypeRenderer(t) {
|
|
322
|
+
return (e) => {
|
|
323
|
+
const r = document.createElement("span");
|
|
324
|
+
r.style.display = "contents";
|
|
325
|
+
const i = b(r);
|
|
326
|
+
return this.mountedViews.push({ root: i, container: r }), R(() => {
|
|
327
|
+
i.render(t(e));
|
|
328
|
+
}), r;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Creates an editor function from a React render function for type defaults.
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
createTypeEditor(t) {
|
|
336
|
+
return (e) => {
|
|
337
|
+
const r = document.createElement("span");
|
|
338
|
+
r.style.display = "contents";
|
|
339
|
+
const i = b(r);
|
|
340
|
+
return this.mountedViews.push({ root: i, container: r }), R(() => {
|
|
341
|
+
i.render(t(e));
|
|
342
|
+
}), r;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
264
345
|
/**
|
|
265
346
|
* Clean up all mounted React roots.
|
|
266
347
|
* Call this when the grid is unmounted.
|
|
@@ -288,114 +369,116 @@ class Z {
|
|
|
288
369
|
}
|
|
289
370
|
}
|
|
290
371
|
}
|
|
291
|
-
let
|
|
292
|
-
function
|
|
293
|
-
return
|
|
372
|
+
let W = !1, M = null;
|
|
373
|
+
function P() {
|
|
374
|
+
return W || (M = new ie(), _.registerAdapter(M), W = !0), M;
|
|
294
375
|
}
|
|
295
|
-
|
|
296
|
-
function
|
|
376
|
+
P();
|
|
377
|
+
function oe(n, t) {
|
|
297
378
|
const e = n, r = e.getPluginByName?.("masterDetail");
|
|
298
379
|
if (r && typeof r.refreshDetailRenderer == "function") {
|
|
299
380
|
r.refreshDetailRenderer();
|
|
300
381
|
return;
|
|
301
382
|
}
|
|
302
383
|
const i = n.querySelector("tbw-grid-detail");
|
|
303
|
-
!i || !
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
384
|
+
!i || !z(n) || import("@toolbox-web/grid/all").then(({ MasterDetailPlugin: o }) => {
|
|
385
|
+
const c = t.createDetailRenderer(n);
|
|
386
|
+
if (!c) return;
|
|
306
387
|
const u = i.getAttribute("animation");
|
|
307
388
|
let l = "slide";
|
|
308
389
|
u === "false" ? l = !1 : u === "fade" && (l = "fade");
|
|
309
390
|
const w = i.getAttribute("showExpandColumn") !== "false", a = new o({
|
|
310
|
-
detailRenderer:
|
|
391
|
+
detailRenderer: c,
|
|
311
392
|
showExpandColumn: w,
|
|
312
393
|
animation: l
|
|
313
|
-
}), m = e.gridConfig || {},
|
|
394
|
+
}), m = e.gridConfig || {}, S = m.plugins || [];
|
|
314
395
|
e.gridConfig = {
|
|
315
396
|
...m,
|
|
316
|
-
plugins: [...
|
|
397
|
+
plugins: [...S, a]
|
|
317
398
|
};
|
|
318
399
|
}).catch(() => {
|
|
319
400
|
});
|
|
320
401
|
}
|
|
321
|
-
const
|
|
402
|
+
const he = $(function(t, e) {
|
|
322
403
|
const {
|
|
323
404
|
rows: r,
|
|
324
405
|
gridConfig: i,
|
|
325
406
|
columns: s,
|
|
326
407
|
fitMode: o,
|
|
327
|
-
editOn:
|
|
408
|
+
editOn: c,
|
|
328
409
|
customStyles: u,
|
|
329
410
|
className: l,
|
|
330
411
|
style: w,
|
|
331
412
|
children: a,
|
|
332
413
|
onRowsChange: m,
|
|
333
|
-
onCellEdit:
|
|
334
|
-
onRowClick:
|
|
335
|
-
onColumnStateChange:
|
|
414
|
+
onCellEdit: S,
|
|
415
|
+
onRowClick: E,
|
|
416
|
+
onColumnStateChange: x,
|
|
336
417
|
onSortChange: I
|
|
337
|
-
} = t, f =
|
|
338
|
-
return
|
|
418
|
+
} = t, f = k(null), V = k(null), y = F(Q), C = J(() => Y(i), [i]);
|
|
419
|
+
return v(() => {
|
|
420
|
+
P().setTypeDefaults(y);
|
|
421
|
+
}, [y]), v(() => {
|
|
339
422
|
f.current && (f.current.rows = r);
|
|
340
|
-
}, [r]),
|
|
341
|
-
f.current &&
|
|
342
|
-
}, [
|
|
423
|
+
}, [r]), v(() => {
|
|
424
|
+
f.current && C && (f.current.gridConfig = C);
|
|
425
|
+
}, [C]), v(() => {
|
|
343
426
|
f.current && s && (f.current.columns = s);
|
|
344
|
-
}, [s]),
|
|
427
|
+
}, [s]), v(() => {
|
|
345
428
|
f.current && o !== void 0 && (f.current.fitMode = o);
|
|
346
|
-
}, [o]),
|
|
347
|
-
f.current &&
|
|
348
|
-
}, [
|
|
349
|
-
const
|
|
350
|
-
if (!
|
|
351
|
-
const p =
|
|
352
|
-
|
|
429
|
+
}, [o]), v(() => {
|
|
430
|
+
f.current && c !== void 0 && (f.current.editOn = c);
|
|
431
|
+
}, [c]), v(() => {
|
|
432
|
+
const d = f.current;
|
|
433
|
+
if (!d) return;
|
|
434
|
+
const p = P();
|
|
435
|
+
d.__frameworkAdapter = p, oe(d, p);
|
|
353
436
|
let g = !1;
|
|
354
|
-
const
|
|
355
|
-
g || (typeof
|
|
437
|
+
const h = requestAnimationFrame(() => {
|
|
438
|
+
g || (typeof d.refreshColumns == "function" && d.refreshColumns(), typeof d.refreshShellHeader == "function" && d.refreshShellHeader());
|
|
356
439
|
});
|
|
357
440
|
return () => {
|
|
358
|
-
g = !0, cancelAnimationFrame(
|
|
441
|
+
g = !0, cancelAnimationFrame(h);
|
|
359
442
|
};
|
|
360
|
-
}, []),
|
|
443
|
+
}, []), v(() => {
|
|
361
444
|
if (!f.current || !u) return;
|
|
362
|
-
const
|
|
445
|
+
const d = f.current, p = "react-custom-styles";
|
|
363
446
|
let g = !0;
|
|
364
|
-
return
|
|
365
|
-
g && u && (
|
|
447
|
+
return d.ready?.().then(() => {
|
|
448
|
+
g && u && (d.registerStyles?.(p, u), V.current = p);
|
|
366
449
|
}), () => {
|
|
367
|
-
g = !1,
|
|
450
|
+
g = !1, V.current && (d.unregisterStyles?.(V.current), V.current = null);
|
|
368
451
|
};
|
|
369
|
-
}, [u]),
|
|
370
|
-
const
|
|
371
|
-
if (!
|
|
452
|
+
}, [u]), v(() => {
|
|
453
|
+
const d = f.current;
|
|
454
|
+
if (!d) return;
|
|
372
455
|
const p = [];
|
|
373
456
|
if (m) {
|
|
374
|
-
const g = ((
|
|
375
|
-
|
|
457
|
+
const g = ((h) => m(h.detail.rows));
|
|
458
|
+
d.addEventListener("rows-change", g), p.push(["rows-change", g]);
|
|
376
459
|
}
|
|
377
|
-
if (
|
|
378
|
-
const g = ((
|
|
379
|
-
|
|
460
|
+
if (S) {
|
|
461
|
+
const g = ((h) => S(h));
|
|
462
|
+
d.addEventListener("cell-edit", g), p.push(["cell-edit", g]);
|
|
380
463
|
}
|
|
381
|
-
if (
|
|
382
|
-
const g = ((
|
|
383
|
-
|
|
464
|
+
if (E) {
|
|
465
|
+
const g = ((h) => E(h));
|
|
466
|
+
d.addEventListener("row-click", g), p.push(["row-click", g]);
|
|
384
467
|
}
|
|
385
|
-
if (
|
|
386
|
-
const g = ((
|
|
387
|
-
|
|
468
|
+
if (x) {
|
|
469
|
+
const g = ((h) => x(h));
|
|
470
|
+
d.addEventListener("column-state-change", g), p.push(["column-state-change", g]);
|
|
388
471
|
}
|
|
389
472
|
if (I) {
|
|
390
|
-
const g = ((
|
|
391
|
-
|
|
473
|
+
const g = ((h) => I(h));
|
|
474
|
+
d.addEventListener("sort-change", g), p.push(["sort-change", g]);
|
|
392
475
|
}
|
|
393
476
|
return () => {
|
|
394
|
-
p.forEach(([g,
|
|
395
|
-
|
|
477
|
+
p.forEach(([g, h]) => {
|
|
478
|
+
d.removeEventListener(g, h);
|
|
396
479
|
});
|
|
397
480
|
};
|
|
398
|
-
}, [m,
|
|
481
|
+
}, [m, S, E, x, I]), K(
|
|
399
482
|
e,
|
|
400
483
|
() => ({
|
|
401
484
|
get element() {
|
|
@@ -410,24 +493,24 @@ const ue = B(function(t, e) {
|
|
|
410
493
|
async forceLayout() {
|
|
411
494
|
return f.current?.forceLayout?.();
|
|
412
495
|
},
|
|
413
|
-
async toggleGroup(
|
|
414
|
-
return f.current?.toggleGroup?.(
|
|
496
|
+
async toggleGroup(d) {
|
|
497
|
+
return f.current?.toggleGroup?.(d);
|
|
415
498
|
},
|
|
416
|
-
registerStyles(
|
|
417
|
-
f.current?.registerStyles?.(
|
|
499
|
+
registerStyles(d, p) {
|
|
500
|
+
f.current?.registerStyles?.(d, p);
|
|
418
501
|
},
|
|
419
|
-
unregisterStyles(
|
|
420
|
-
f.current?.unregisterStyles?.(
|
|
502
|
+
unregisterStyles(d) {
|
|
503
|
+
f.current?.unregisterStyles?.(d);
|
|
421
504
|
}
|
|
422
505
|
}),
|
|
423
506
|
[]
|
|
424
|
-
), /* @__PURE__ */
|
|
507
|
+
), /* @__PURE__ */ T(
|
|
425
508
|
"tbw-grid",
|
|
426
509
|
{
|
|
427
|
-
ref: (
|
|
428
|
-
if (f.current =
|
|
429
|
-
const p =
|
|
430
|
-
|
|
510
|
+
ref: (d) => {
|
|
511
|
+
if (f.current = d, d) {
|
|
512
|
+
const p = d;
|
|
513
|
+
C && (p.gridConfig = C), r && (p.rows = r), s && (p.columns = s);
|
|
431
514
|
}
|
|
432
515
|
},
|
|
433
516
|
class: l,
|
|
@@ -436,7 +519,7 @@ const ue = B(function(t, e) {
|
|
|
436
519
|
}
|
|
437
520
|
);
|
|
438
521
|
});
|
|
439
|
-
function
|
|
522
|
+
function we(n) {
|
|
440
523
|
const {
|
|
441
524
|
field: t,
|
|
442
525
|
header: e,
|
|
@@ -444,32 +527,32 @@ function ae(n) {
|
|
|
444
527
|
editable: i,
|
|
445
528
|
sortable: s,
|
|
446
529
|
resizable: o,
|
|
447
|
-
width:
|
|
530
|
+
width: c,
|
|
448
531
|
minWidth: u,
|
|
449
532
|
hidden: l,
|
|
450
533
|
lockVisible: w,
|
|
451
534
|
children: a,
|
|
452
535
|
editor: m,
|
|
453
|
-
options:
|
|
454
|
-
multi:
|
|
455
|
-
format:
|
|
456
|
-
} = n, I =
|
|
457
|
-
(
|
|
458
|
-
I.current =
|
|
536
|
+
options: S,
|
|
537
|
+
multi: E,
|
|
538
|
+
format: x
|
|
539
|
+
} = n, I = k(null), f = D(
|
|
540
|
+
(C) => {
|
|
541
|
+
I.current = C, C && (a && ee(C, a), m && te(C, m));
|
|
459
542
|
},
|
|
460
543
|
[a, m, t]
|
|
461
|
-
),
|
|
544
|
+
), V = typeof c == "number" ? `${c}px` : c, y = {
|
|
462
545
|
field: t,
|
|
463
546
|
ref: f
|
|
464
547
|
};
|
|
465
|
-
return e !== void 0 && (
|
|
548
|
+
return e !== void 0 && (y.header = e), r !== void 0 && (y.type = r), i !== void 0 && (y.editable = i), s !== void 0 && (y.sortable = s), o !== void 0 && (y.resizable = o), V !== void 0 && (y.width = V), u !== void 0 && (y["min-width"] = u), l !== void 0 && (y.hidden = l), w !== void 0 && (y["lock-visible"] = w), E !== void 0 && (y.multi = E), x && (y["data-has-format"] = "true"), S && (y["data-has-options"] = "true"), /* @__PURE__ */ T("tbw-grid-column", { ...y });
|
|
466
549
|
}
|
|
467
|
-
function
|
|
468
|
-
return /* @__PURE__ */
|
|
550
|
+
function ve({ children: n }) {
|
|
551
|
+
return /* @__PURE__ */ T("tbw-grid-tool-buttons", { children: n });
|
|
469
552
|
}
|
|
470
|
-
function
|
|
471
|
-
const n =
|
|
472
|
-
|
|
553
|
+
function Re() {
|
|
554
|
+
const n = k(null), [t, e] = N(!1), [r, i] = N(null);
|
|
555
|
+
v(() => {
|
|
473
556
|
const a = n.current;
|
|
474
557
|
if (!a) return;
|
|
475
558
|
let m = !0;
|
|
@@ -477,8 +560,8 @@ function fe() {
|
|
|
477
560
|
try {
|
|
478
561
|
if (await a.ready?.(), m) {
|
|
479
562
|
e(!0);
|
|
480
|
-
const
|
|
481
|
-
m &&
|
|
563
|
+
const E = await a.getConfig?.();
|
|
564
|
+
m && E && i(E);
|
|
482
565
|
}
|
|
483
566
|
} catch {
|
|
484
567
|
}
|
|
@@ -486,55 +569,58 @@ function fe() {
|
|
|
486
569
|
m = !1;
|
|
487
570
|
};
|
|
488
571
|
}, []);
|
|
489
|
-
const s =
|
|
572
|
+
const s = D(async () => {
|
|
490
573
|
const a = n.current;
|
|
491
574
|
return a ? await a.getConfig?.() ?? null : null;
|
|
492
|
-
}, []), o =
|
|
575
|
+
}, []), o = D(async () => {
|
|
493
576
|
const a = n.current;
|
|
494
577
|
a && await a.forceLayout?.();
|
|
495
|
-
}, []),
|
|
578
|
+
}, []), c = D(async (a) => {
|
|
496
579
|
const m = n.current;
|
|
497
580
|
m && await m.toggleGroup?.(a);
|
|
498
|
-
}, []), u =
|
|
581
|
+
}, []), u = D((a, m) => {
|
|
499
582
|
n.current?.registerStyles?.(a, m);
|
|
500
|
-
}, []), l =
|
|
583
|
+
}, []), l = D((a) => {
|
|
501
584
|
n.current?.unregisterStyles?.(a);
|
|
502
|
-
}, []), w =
|
|
585
|
+
}, []), w = D(() => r?.columns ? r.columns.filter((a) => !a.hidden) : [], [r]);
|
|
503
586
|
return {
|
|
504
587
|
ref: n,
|
|
505
588
|
isReady: t,
|
|
506
589
|
config: r,
|
|
507
590
|
getConfig: s,
|
|
508
591
|
forceLayout: o,
|
|
509
|
-
toggleGroup:
|
|
592
|
+
toggleGroup: c,
|
|
510
593
|
registerStyles: u,
|
|
511
594
|
unregisterStyles: l,
|
|
512
595
|
getVisibleColumns: w
|
|
513
596
|
};
|
|
514
597
|
}
|
|
515
|
-
function
|
|
516
|
-
const i =
|
|
517
|
-
|
|
598
|
+
function Ce(n, t, e, r = []) {
|
|
599
|
+
const i = k(e);
|
|
600
|
+
v(() => {
|
|
518
601
|
i.current = e;
|
|
519
|
-
}, [e, ...r]),
|
|
602
|
+
}, [e, ...r]), v(() => {
|
|
520
603
|
const s = n.current, o = s && "element" in s ? s.element : s;
|
|
521
604
|
if (!o) return;
|
|
522
|
-
const
|
|
605
|
+
const c = ((u) => {
|
|
523
606
|
i.current(u);
|
|
524
607
|
});
|
|
525
|
-
return o.addEventListener(t,
|
|
526
|
-
o.removeEventListener(t,
|
|
608
|
+
return o.addEventListener(t, c), () => {
|
|
609
|
+
o.removeEventListener(t, c);
|
|
527
610
|
};
|
|
528
611
|
}, [n, t]);
|
|
529
612
|
}
|
|
530
613
|
export {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
614
|
+
he as DataGrid,
|
|
615
|
+
we as GridColumn,
|
|
616
|
+
le as GridDetailPanel,
|
|
617
|
+
ve as GridToolButtons,
|
|
618
|
+
pe as GridToolPanel,
|
|
619
|
+
fe as GridTypeProvider,
|
|
620
|
+
ie as ReactGridAdapter,
|
|
621
|
+
ye as getRegisteredFields,
|
|
622
|
+
Re as useGrid,
|
|
623
|
+
Ce as useGridEvent,
|
|
624
|
+
ge as useGridTypeDefaults,
|
|
625
|
+
me as useTypeDefault
|
|
540
626
|
};
|
package/lib/data-grid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-grid.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/lib/data-grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,
|
|
1
|
+
{"version":3,"file":"data-grid.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/lib/data-grid.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { CellRenderContext, ColumnEditorContext, TypeDefault } from '../../../../dist/libs/grid/index.d.ts';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* React-specific type default configuration.
|
|
5
|
+
* Uses React function components that receive the render context.
|
|
6
|
+
*/
|
|
7
|
+
export interface ReactTypeDefault<TRow = unknown, TValue = unknown> {
|
|
8
|
+
/** React component/function for rendering cells of this type */
|
|
9
|
+
renderer?: (ctx: CellRenderContext<TRow, TValue>) => ReactNode;
|
|
10
|
+
/** React component/function for editing cells of this type */
|
|
11
|
+
editor?: (ctx: ColumnEditorContext<TRow, TValue>) => ReactNode;
|
|
12
|
+
/** Default editorParams for this type */
|
|
13
|
+
editorParams?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type defaults registry - a map of type names to their defaults.
|
|
17
|
+
*/
|
|
18
|
+
export type TypeDefaultsMap = Record<string, ReactTypeDefault>;
|
|
19
|
+
/**
|
|
20
|
+
* Props for the GridTypeProvider component.
|
|
21
|
+
*/
|
|
22
|
+
export interface GridTypeProviderProps {
|
|
23
|
+
/**
|
|
24
|
+
* Type defaults to provide to all descendant grids.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const typeDefaults = {
|
|
29
|
+
* country: {
|
|
30
|
+
* renderer: (ctx) => <CountryBadge value={ctx.value} />,
|
|
31
|
+
* editor: (ctx) => <CountrySelect value={ctx.value} onCommit={ctx.commit} />
|
|
32
|
+
* },
|
|
33
|
+
* status: {
|
|
34
|
+
* renderer: (ctx) => <StatusBadge value={ctx.value} />
|
|
35
|
+
* }
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* <GridTypeProvider defaults={typeDefaults}>
|
|
39
|
+
* <App />
|
|
40
|
+
* </GridTypeProvider>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
defaults: TypeDefaultsMap;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Provides application-wide type defaults for all descendant grids.
|
|
48
|
+
*
|
|
49
|
+
* Wrap your application (or part of it) with this provider to make
|
|
50
|
+
* type-level renderers and editors available to all DataGrid components.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* // App.tsx or main.tsx
|
|
55
|
+
* import { GridTypeProvider, type TypeDefaultsMap } from '@toolbox-web/grid-react';
|
|
56
|
+
*
|
|
57
|
+
* const typeDefaults: TypeDefaultsMap = {
|
|
58
|
+
* country: {
|
|
59
|
+
* renderer: (ctx) => <CountryBadge code={ctx.value} />,
|
|
60
|
+
* editor: (ctx) => (
|
|
61
|
+
* <CountrySelect
|
|
62
|
+
* value={ctx.value}
|
|
63
|
+
* onSelect={(v) => ctx.commit(v)}
|
|
64
|
+
* />
|
|
65
|
+
* )
|
|
66
|
+
* },
|
|
67
|
+
* date: {
|
|
68
|
+
* renderer: (ctx) => formatDate(ctx.value),
|
|
69
|
+
* editor: (ctx) => <DatePicker value={ctx.value} onCommit={ctx.commit} />
|
|
70
|
+
* }
|
|
71
|
+
* };
|
|
72
|
+
*
|
|
73
|
+
* function App() {
|
|
74
|
+
* return (
|
|
75
|
+
* <GridTypeProvider defaults={typeDefaults}>
|
|
76
|
+
* <Dashboard />
|
|
77
|
+
* </GridTypeProvider>
|
|
78
|
+
* );
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* Any DataGrid with columns using `type: 'country'` will automatically
|
|
83
|
+
* use the registered renderer/editor.
|
|
84
|
+
*/
|
|
85
|
+
export declare const GridTypeProvider: FC<GridTypeProviderProps>;
|
|
86
|
+
/**
|
|
87
|
+
* Hook to access the type defaults from context.
|
|
88
|
+
*
|
|
89
|
+
* @returns The type defaults map, or null if not within a GridTypeProvider
|
|
90
|
+
*/
|
|
91
|
+
export declare function useGridTypeDefaults(): TypeDefaultsMap | null;
|
|
92
|
+
/**
|
|
93
|
+
* Hook to get type defaults for a specific type.
|
|
94
|
+
*
|
|
95
|
+
* @param type - The type name to look up
|
|
96
|
+
* @returns The type defaults, or undefined if not found
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```tsx
|
|
100
|
+
* function MyComponent() {
|
|
101
|
+
* const countryDefaults = useTypeDefault('country');
|
|
102
|
+
* // countryDefaults?.renderer, countryDefaults?.editor
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function useTypeDefault<TRow = unknown, TValue = unknown>(type: string): ReactTypeDefault<TRow, TValue> | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Creates a TypeDefault that the grid can use from a React type default.
|
|
109
|
+
*
|
|
110
|
+
* This converts React render functions into grid-compatible renderer/editor functions.
|
|
111
|
+
* Used internally by ReactGridAdapter.
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export declare function reactTypeDefaultToGridTypeDefault<TRow = unknown>(reactDefault: ReactTypeDefault<TRow>, renderReactNode: (node: ReactNode) => HTMLElement): TypeDefault<TRow>;
|
|
116
|
+
/**
|
|
117
|
+
* Internal context for passing the type defaults to the adapter.
|
|
118
|
+
* Used by DataGrid to communicate with ReactGridAdapter.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export declare const GridTypeContextInternal: import('react').Context<TypeDefaultsMap | null>;
|
|
122
|
+
//# sourceMappingURL=grid-type-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-type-registry.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/lib/grid-type-registry.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAA6B,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO;IAChE,gEAAgE;IAChE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,SAAS,CAAC;IAC/D,8DAA8D;IAC9D,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,SAAS,CAAC;IAC/D,yCAAyC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAO/D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CAEtD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,GAAG,IAAI,CAE5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EAC7D,IAAI,EAAE,MAAM,GACX,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,SAAS,CAG5C;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,GAAG,OAAO,EAC9D,YAAY,EAAE,gBAAgB,CAAC,IAAI,CAAC,EACpC,eAAe,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,WAAW,GAChD,WAAW,CAAC,IAAI,CAAC,CAsBnB;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,iDAAkB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CellRenderContext, ColumnEditorContext, ColumnEditorSpec, ColumnViewRenderer, FrameworkAdapter } from '../../../../dist/libs/grid/index.d.ts';
|
|
1
|
+
import { CellRenderContext, ColumnEditorContext, ColumnEditorSpec, ColumnViewRenderer, FrameworkAdapter, TypeDefault } from '../../../../dist/libs/grid/index.d.ts';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
+
import { TypeDefaultsMap } from './grid-type-registry';
|
|
3
4
|
/**
|
|
4
5
|
* Register a React cell renderer for a column element.
|
|
5
6
|
* Called by GridColumn when it has a children render prop.
|
|
@@ -57,6 +58,14 @@ export declare function getRegisteredFields(): string[];
|
|
|
57
58
|
*/
|
|
58
59
|
export declare class ReactGridAdapter implements FrameworkAdapter {
|
|
59
60
|
private mountedViews;
|
|
61
|
+
private typeDefaults;
|
|
62
|
+
/**
|
|
63
|
+
* Sets the type defaults map for this adapter.
|
|
64
|
+
* Called by DataGrid when it receives type defaults from context.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
setTypeDefaults(defaults: TypeDefaultsMap | null): void;
|
|
60
69
|
/**
|
|
61
70
|
* Determines if this adapter can handle the given element.
|
|
62
71
|
* Checks if a renderer or editor is registered for this element.
|
|
@@ -94,6 +103,41 @@ export declare class ReactGridAdapter implements FrameworkAdapter {
|
|
|
94
103
|
* Renders React components into tool panel containers.
|
|
95
104
|
*/
|
|
96
105
|
createToolPanelRenderer(element: HTMLElement): ((container: HTMLElement) => void | (() => void)) | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Gets type-level defaults from the type defaults map.
|
|
108
|
+
*
|
|
109
|
+
* This enables application-wide type defaults configured via GridTypeProvider.
|
|
110
|
+
* The returned TypeDefault contains renderer/editor functions that render
|
|
111
|
+
* React components into the grid's cells.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* // App.tsx
|
|
116
|
+
* const typeDefaults = {
|
|
117
|
+
* country: {
|
|
118
|
+
* renderer: (ctx) => <CountryBadge code={ctx.value} />,
|
|
119
|
+
* editor: (ctx) => <CountrySelect value={ctx.value} onCommit={ctx.commit} />
|
|
120
|
+
* }
|
|
121
|
+
* };
|
|
122
|
+
*
|
|
123
|
+
* <GridTypeProvider defaults={typeDefaults}>
|
|
124
|
+
* <App />
|
|
125
|
+
* </GridTypeProvider>
|
|
126
|
+
*
|
|
127
|
+
* // Any grid with type: 'country' columns will use these components
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
getTypeDefault(type: string): TypeDefault | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Creates a renderer function from a React render function for type defaults.
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
private createTypeRenderer;
|
|
136
|
+
/**
|
|
137
|
+
* Creates an editor function from a React render function for type defaults.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
private createTypeEditor;
|
|
97
141
|
/**
|
|
98
142
|
* Clean up all mounted React roots.
|
|
99
143
|
* Call this when the grid is unmounted.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-grid-adapter.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/lib/react-grid-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"react-grid-adapter.d.ts","sourceRoot":"","sources":["../../../../libs/grid-react/src/lib/react-grid-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAiB9E;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,SAAS,GAChE,IAAI,CAaN;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,CAAC,GAAG,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,SAAS,GAChE,IAAI,CAYN;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,GACnB,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,SAAS,CAAC,GAAG,SAAS,CAYvE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,WAAW,GACnB,CAAC,CAAC,GAAG,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,SAAS,CAAC,GAAG,SAAS,CAYzE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAE9C;AAoBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,gBAAiB,YAAW,gBAAgB;IACvD,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,YAAY,CAAgC;IAEpD;;;;;OAKG;IACH,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI;IAIvD;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO;IAoBxC;;;;;;;;;;OAUG;IACH,cAAc,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,WAAW,GAAG,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC;IA2DxG;;;OAGG;IACH,YAAY,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,WAAW,GAAG,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC;IA0BpG;;;OAGG;IACH,oBAAoB,CAAC,IAAI,GAAG,OAAO,EACjC,WAAW,EAAE,WAAW,GACvB,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,WAAW,CAAC,GAAG,SAAS;IAwB7D;;;OAGG;IACH,kBAAkB,CAAC,IAAI,GAAG,OAAO,EAC/B,aAAa,EAAE,OAAO,GACrB,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,GAAG,SAAS;IAOtE;;;OAGG;IACH,uBAAuB,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,CAAC,SAAS,EAAE,WAAW,KAAK,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,SAAS;IAqC5G;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IA2BrD;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAkBxB;;;OAGG;IACH,OAAO,IAAI,IAAI;IAWf;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;CAYtC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolbox-web/grid-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "React adapter for @toolbox-web/grid data grid component",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
7
|
-
"module": "./
|
|
8
|
-
"types": "./
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
"./package.json": "./package.json",
|
|
11
11
|
".": {
|
|
12
|
-
"types": "./
|
|
13
|
-
"import": "./
|
|
14
|
-
"default": "./
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"default": "./index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|