@revolist/react-datagrid 4.32.0 → 4.32.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 +24 -0
- package/dist/index.d.ts +19 -0
- package/dist/react-datagrid.js +45 -1
- package/dist/react-datagrid.umd.cjs +43 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -547,3 +547,27 @@ MIT
|
|
|
547
547
|
|
|
548
548
|
See [component templates](./component-templates.md) for framework components in
|
|
549
549
|
cells, master details, Kanban cards and Gantt labels. Existing template APIs remain supported.
|
|
550
|
+
|
|
551
|
+
### Custom grid controls
|
|
552
|
+
|
|
553
|
+
`GridControlsProvider` supplies its ready grid to descendant components. `useGridControls()` returns the current grid or `null` while it is unavailable. Use an effect to subscribe to events and remove listeners when the grid changes.
|
|
554
|
+
|
|
555
|
+
```tsx
|
|
556
|
+
import {
|
|
557
|
+
GridControlsProvider,
|
|
558
|
+
RevoGrid,
|
|
559
|
+
useGridControls,
|
|
560
|
+
} from "@revolist/react-datagrid";
|
|
561
|
+
|
|
562
|
+
function MyControl() {
|
|
563
|
+
const grid = useGridControls();
|
|
564
|
+
return <button disabled={!grid}>My control</button>;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
<GridControlsProvider>
|
|
568
|
+
<MyControl />
|
|
569
|
+
<RevoGrid columns={columns} source={rows} />
|
|
570
|
+
</GridControlsProvider>;
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Use `GridControl` with a `GridControlMount` callback when mounting an imperative control. Each provider owns one grid, and nested providers are independent.
|
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,18 @@ import { ColumnRegular } from '@revolist/revogrid';
|
|
|
4
4
|
import { ColumnTemplateProp } from '@revolist/revogrid';
|
|
5
5
|
import { ComponentType } from 'react';
|
|
6
6
|
import { DataType } from '@revolist/revogrid';
|
|
7
|
+
import { DetailedReactHTMLElement } from 'react';
|
|
7
8
|
import { EditCell } from '@revolist/revogrid';
|
|
8
9
|
import { EditorBase } from '@revolist/revogrid';
|
|
9
10
|
import { EditorCtr } from '@revolist/revogrid';
|
|
10
11
|
import { ForwardRefExoticComponent } from 'react';
|
|
12
|
+
import { FunctionComponentElement } from 'react';
|
|
13
|
+
import { GridControlMount } from '@revolist/revogrid';
|
|
11
14
|
import { HTMLAttributes } from 'react';
|
|
12
15
|
import { HyperFunc } from '@revolist/revogrid';
|
|
13
16
|
import { JSX as JSX_2 } from '@revolist/revogrid';
|
|
17
|
+
import { ProviderProps } from 'react';
|
|
18
|
+
import { ReactNode } from 'react';
|
|
14
19
|
import { RefAttributes } from 'react';
|
|
15
20
|
import { Root } from 'react-dom/client';
|
|
16
21
|
import { VNode } from '@revolist/revogrid';
|
|
@@ -45,6 +50,17 @@ export declare type EditorType = {
|
|
|
45
50
|
close: (focusNext?: boolean) => void;
|
|
46
51
|
} & Partial<EditCell>;
|
|
47
52
|
|
|
53
|
+
/** Mount a custom control for the scoped grid. */
|
|
54
|
+
export declare function GridControl({ grid, mount, }: {
|
|
55
|
+
grid?: HTMLRevoGridElement | null;
|
|
56
|
+
mount: GridControlMount;
|
|
57
|
+
}): DetailedReactHTMLElement<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
58
|
+
|
|
59
|
+
/** Connect descendant controls to the single grid inside this provider. */
|
|
60
|
+
export declare function GridControlsProvider({ children }: {
|
|
61
|
+
children?: ReactNode;
|
|
62
|
+
}): FunctionComponentElement<ProviderProps<HTMLRevoGridElement | null>>;
|
|
63
|
+
|
|
48
64
|
export declare interface ReactElement extends HTMLElement {
|
|
49
65
|
_root?: Root;
|
|
50
66
|
}
|
|
@@ -74,6 +90,9 @@ export declare const Template: <C = ColumnDataSchemaModel<DataType<any, ColumnPr
|
|
|
74
90
|
key?: (context: C) => string | number;
|
|
75
91
|
}) => (h: HyperFunc<VNode>, p: C, addition?: any) => VNode;
|
|
76
92
|
|
|
93
|
+
/** Read the ready grid in the nearest provider, or null when unavailable. */
|
|
94
|
+
export declare function useGridControls(): HTMLRevoGridElement | null;
|
|
95
|
+
|
|
77
96
|
/** Bind the existing template factory for use on any content surface. */
|
|
78
97
|
export declare function useTemplates(): {
|
|
79
98
|
template<C>(component: ComponentType<any>, options?: Parameters<typeof Template<C>>[2]): (h: HyperFunc<VNode>, p: C, addition?: any) => VNode;
|
package/dist/react-datagrid.js
CHANGED
|
@@ -3,9 +3,10 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { defineCustomElements } from "@revolist/revogrid/loader";
|
|
5
5
|
export * from "@revolist/revogrid/loader";
|
|
6
|
+
import { mountGridControl, observeScopedGrid } from "@revolist/revogrid";
|
|
6
7
|
export * from "@revolist/revogrid";
|
|
7
8
|
import { createRoot } from "react-dom/client";
|
|
8
|
-
import React, { createElement, useMemo } from "react";
|
|
9
|
+
import React, { createElement, useMemo, useRef, useEffect, useState, useContext, createContext } from "react";
|
|
9
10
|
import { jsx } from "react/jsx-runtime";
|
|
10
11
|
const dashToPascalCase = (str) => str.toLowerCase().split("-").map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
|
|
11
12
|
const camelToDashCase = (str) => str.replace(/([A-Z])/g, (m) => `-${m[0].toLowerCase()}`);
|
|
@@ -265,11 +266,54 @@ function useTemplates() {
|
|
|
265
266
|
}
|
|
266
267
|
}), []);
|
|
267
268
|
}
|
|
269
|
+
const GridContext = createContext(null);
|
|
270
|
+
function useGridControls() {
|
|
271
|
+
return useContext(GridContext);
|
|
272
|
+
}
|
|
273
|
+
function GridControlsProvider({ children }) {
|
|
274
|
+
const [grid, setGrid] = useState(null);
|
|
275
|
+
const host = useRef(null);
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
if (host.current) {
|
|
278
|
+
return observeScopedGrid(host.current, setGrid);
|
|
279
|
+
}
|
|
280
|
+
}, []);
|
|
281
|
+
return createElement(
|
|
282
|
+
GridContext.Provider,
|
|
283
|
+
{ value: grid },
|
|
284
|
+
createElement(
|
|
285
|
+
"div",
|
|
286
|
+
{
|
|
287
|
+
ref: host,
|
|
288
|
+
"data-rv-grid-controls-scope": "",
|
|
289
|
+
style: { display: "contents" }
|
|
290
|
+
},
|
|
291
|
+
children
|
|
292
|
+
)
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
function GridControl({
|
|
296
|
+
grid,
|
|
297
|
+
mount
|
|
298
|
+
}) {
|
|
299
|
+
const scope = useGridControls();
|
|
300
|
+
const current = grid === void 0 ? scope : grid;
|
|
301
|
+
const host = useRef(null);
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
if (host.current && current) {
|
|
304
|
+
return mountGridControl(host.current, current, mount);
|
|
305
|
+
}
|
|
306
|
+
}, [current, mount]);
|
|
307
|
+
return createElement("div", { ref: host });
|
|
308
|
+
}
|
|
268
309
|
const RevoGrid = /* @__PURE__ */ createReactComponent("revo-grid", void 0, void 0, defineCustomElements);
|
|
269
310
|
export {
|
|
270
311
|
Editor,
|
|
271
312
|
EditorAdapter,
|
|
313
|
+
GridControl,
|
|
314
|
+
GridControlsProvider,
|
|
272
315
|
RevoGrid,
|
|
273
316
|
Template,
|
|
317
|
+
useGridControls,
|
|
274
318
|
useTemplates
|
|
275
319
|
};
|
|
@@ -263,11 +263,54 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
263
263
|
}
|
|
264
264
|
}), []);
|
|
265
265
|
}
|
|
266
|
+
const GridContext = React.createContext(null);
|
|
267
|
+
function useGridControls() {
|
|
268
|
+
return React.useContext(GridContext);
|
|
269
|
+
}
|
|
270
|
+
function GridControlsProvider({ children }) {
|
|
271
|
+
const [grid, setGrid] = React.useState(null);
|
|
272
|
+
const host = React.useRef(null);
|
|
273
|
+
React.useEffect(() => {
|
|
274
|
+
if (host.current) {
|
|
275
|
+
return revogrid.observeScopedGrid(host.current, setGrid);
|
|
276
|
+
}
|
|
277
|
+
}, []);
|
|
278
|
+
return React.createElement(
|
|
279
|
+
GridContext.Provider,
|
|
280
|
+
{ value: grid },
|
|
281
|
+
React.createElement(
|
|
282
|
+
"div",
|
|
283
|
+
{
|
|
284
|
+
ref: host,
|
|
285
|
+
"data-rv-grid-controls-scope": "",
|
|
286
|
+
style: { display: "contents" }
|
|
287
|
+
},
|
|
288
|
+
children
|
|
289
|
+
)
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
function GridControl({
|
|
293
|
+
grid,
|
|
294
|
+
mount
|
|
295
|
+
}) {
|
|
296
|
+
const scope = useGridControls();
|
|
297
|
+
const current = grid === void 0 ? scope : grid;
|
|
298
|
+
const host = React.useRef(null);
|
|
299
|
+
React.useEffect(() => {
|
|
300
|
+
if (host.current && current) {
|
|
301
|
+
return revogrid.mountGridControl(host.current, current, mount);
|
|
302
|
+
}
|
|
303
|
+
}, [current, mount]);
|
|
304
|
+
return React.createElement("div", { ref: host });
|
|
305
|
+
}
|
|
266
306
|
const RevoGrid = /* @__PURE__ */ createReactComponent("revo-grid", void 0, void 0, loader.defineCustomElements);
|
|
267
307
|
exports2.Editor = Editor;
|
|
268
308
|
exports2.EditorAdapter = EditorAdapter;
|
|
309
|
+
exports2.GridControl = GridControl;
|
|
310
|
+
exports2.GridControlsProvider = GridControlsProvider;
|
|
269
311
|
exports2.RevoGrid = RevoGrid;
|
|
270
312
|
exports2.Template = Template;
|
|
313
|
+
exports2.useGridControls = useGridControls;
|
|
271
314
|
exports2.useTemplates = useTemplates;
|
|
272
315
|
Object.keys(loader).forEach((k) => {
|
|
273
316
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports2, k)) Object.defineProperty(exports2, k, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revolist/react-datagrid",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "4.32.
|
|
4
|
+
"version": "4.32.2",
|
|
5
5
|
"description": "React DataGrid Spreadsheet component with native cell render support",
|
|
6
6
|
"main": "./dist/react-datagrid.umd.cjs",
|
|
7
7
|
"module": "./dist/react-datagrid.js",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"homepage": "https://github.com/revolist/revogrid#readme",
|
|
66
66
|
"license": "MIT",
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@revolist/revogrid": "4.32.
|
|
68
|
+
"@revolist/revogrid": "4.32.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@stencil/core": "^4.43.2",
|