@revolist/react-datagrid 4.29.0 → 4.29.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 +5 -0
- package/component-templates.md +22 -0
- package/dist/index.d.ts +14 -1
- package/dist/react-datagrid.js +17 -8
- package/dist/react-datagrid.umd.cjs +15 -6
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Framework content templates
|
|
2
|
+
|
|
3
|
+
`useTemplates()` is a thin wrapper around the existing framework `Template` factory. It returns ordinary template callbacks for cells, master rows, Kanban cards, and Gantt labels. There is no outlet or separate mounting protocol.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { useTemplates } from '@revolist/react-datagrid';
|
|
7
|
+
import type { CellTemplateProp } from '@revolist/revogrid';
|
|
8
|
+
|
|
9
|
+
const templates = useTemplates();
|
|
10
|
+
const content = templates.template<CellTemplateProp>(MyCell, {
|
|
11
|
+
props: context => ({ item: context.model }),
|
|
12
|
+
key: context => context.model.id,
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Without `props`, the component receives a `context` prop/input. The optional `key` selects record identity when hosts are reused. Supply a stable key for cells whose records may reorder. Mapped props are recomputed when the product invokes the callback, and omitted props are cleared.
|
|
17
|
+
|
|
18
|
+
Use the returned callback directly as `column.cellTemplate`, `masterRow.template`, `customization.cardContent`, or `gantt.visuals.taskBarContent`. Product progress, resize, dependency, selection and drag controls remain outside the custom content. The legacy Gantt content hook takes precedence. Exports retain the default product representation.
|
|
19
|
+
|
|
20
|
+
React templates use the existing per-host roots. Pass app state and callbacks explicitly through mapped props; surrounding React Context does not cross those roots. Keep template definitions stable with useMemo.
|
|
21
|
+
|
|
22
|
+
Templates use the existing renderer’s ref cleanup and product caching behavior; `useTemplates` adds no lifecycle management. Existing `Template` and editor signatures remain available; their default cell prop shape is unchanged.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ColumnDataSchemaModel } from '@revolist/revogrid';
|
|
2
|
+
import { ColumnProp } from '@revolist/revogrid';
|
|
3
|
+
import { ColumnRegular } from '@revolist/revogrid';
|
|
2
4
|
import { ColumnTemplateProp } from '@revolist/revogrid';
|
|
3
5
|
import { ComponentType } from 'react';
|
|
6
|
+
import { DataType } from '@revolist/revogrid';
|
|
4
7
|
import { EditCell } from '@revolist/revogrid';
|
|
5
8
|
import { EditorBase } from '@revolist/revogrid';
|
|
6
9
|
import { EditorCtr } from '@revolist/revogrid';
|
|
@@ -46,6 +49,8 @@ export declare interface ReactElement extends HTMLElement {
|
|
|
46
49
|
_root?: Root;
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
export declare type ReactTemplateOwner = ReturnType<typeof useTemplates>;
|
|
53
|
+
|
|
49
54
|
export declare interface RenderedComponent<T> {
|
|
50
55
|
update: (newProps: T) => void;
|
|
51
56
|
destroy: () => void;
|
|
@@ -64,7 +69,15 @@ declare interface StyleReactProps {
|
|
|
64
69
|
/**
|
|
65
70
|
* Render React component in Grid column template.
|
|
66
71
|
*/
|
|
67
|
-
export declare const Template:
|
|
72
|
+
export declare const Template: <C = ColumnDataSchemaModel<DataType<any, ColumnProp>, ColumnRegular<ColumnProp, DataType<any, ColumnProp>>, ColumnProp> | ColumnTemplateProp<ColumnProp>>(ReactComponent: ComponentType<ColumnDataSchemaModel | ColumnTemplateProp>, customProps?: any, options?: {
|
|
73
|
+
props?: (context: C) => Record<string, any>;
|
|
74
|
+
key?: (context: C) => string | number;
|
|
75
|
+
}) => (h: HyperFunc<VNode>, p: C, addition?: any) => VNode;
|
|
76
|
+
|
|
77
|
+
/** Bind the existing template factory for use on any content surface. */
|
|
78
|
+
export declare function useTemplates(): {
|
|
79
|
+
template<C>(component: ComponentType<any>, options?: Parameters<typeof Template<C>>[2]): (h: HyperFunc<VNode>, p: C, addition?: any) => VNode;
|
|
80
|
+
};
|
|
68
81
|
|
|
69
82
|
|
|
70
83
|
export * from "@revolist/revogrid";
|
package/dist/react-datagrid.js
CHANGED
|
@@ -5,7 +5,7 @@ import { defineCustomElements } from "@revolist/revogrid/loader";
|
|
|
5
5
|
export * from "@revolist/revogrid/loader";
|
|
6
6
|
export * from "@revolist/revogrid";
|
|
7
7
|
import { createRoot } from "react-dom/client";
|
|
8
|
-
import React, { createElement } from "react";
|
|
8
|
+
import React, { createElement, useMemo } from "react";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
10
|
const dashToPascalCase = (str) => str.toLowerCase().split("-").map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
|
|
11
11
|
const camelToDashCase = (str) => str.replace(/([A-Z])/g, (m) => `-${m[0].toLowerCase()}`);
|
|
@@ -188,17 +188,17 @@ function TemplateConstructor(el, ReactComponent, initialProps, key) {
|
|
|
188
188
|
};
|
|
189
189
|
return { update, destroy };
|
|
190
190
|
}
|
|
191
|
-
const Template = (ReactComponent, customProps) => {
|
|
191
|
+
const Template = (ReactComponent, customProps, options) => {
|
|
192
192
|
return (h, p, addition) => {
|
|
193
|
-
|
|
194
|
-
props
|
|
195
|
-
const key = `${p.prop}-${p.rowIndex || 0}
|
|
193
|
+
var _a;
|
|
194
|
+
const props = (options == null ? void 0 : options.props) ? options.props(p) : { ...customProps, ...p, addition };
|
|
195
|
+
const key = String(((_a = options == null ? void 0 : options.key) == null ? void 0 : _a.call(options, p)) ?? `${p.prop}-${p.rowIndex || 0}`);
|
|
196
196
|
let lastEl = null;
|
|
197
197
|
return h("span", {
|
|
198
198
|
ref: (el) => {
|
|
199
|
-
var
|
|
199
|
+
var _a2;
|
|
200
200
|
if (!el) {
|
|
201
|
-
(
|
|
201
|
+
(_a2 = lastEl == null ? void 0 : lastEl.destroy) == null ? void 0 : _a2.call(lastEl);
|
|
202
202
|
} else {
|
|
203
203
|
lastEl = TemplateConstructor(el, ReactComponent, props, key);
|
|
204
204
|
}
|
|
@@ -257,10 +257,19 @@ const Editor = (EditorComponent) => {
|
|
|
257
257
|
return new EditorAdapter(EditorComponent, column, save, close);
|
|
258
258
|
};
|
|
259
259
|
};
|
|
260
|
+
function useTemplates() {
|
|
261
|
+
return useMemo(() => ({
|
|
262
|
+
template(component, options) {
|
|
263
|
+
const adapted = { ...options, props: (options == null ? void 0 : options.props) ?? ((context) => ({ context })) };
|
|
264
|
+
return Template(component, void 0, adapted);
|
|
265
|
+
}
|
|
266
|
+
}), []);
|
|
267
|
+
}
|
|
260
268
|
const RevoGrid = /* @__PURE__ */ createReactComponent("revo-grid", void 0, void 0, defineCustomElements);
|
|
261
269
|
export {
|
|
262
270
|
Editor,
|
|
263
271
|
EditorAdapter,
|
|
264
272
|
RevoGrid,
|
|
265
|
-
Template
|
|
273
|
+
Template,
|
|
274
|
+
useTemplates
|
|
266
275
|
};
|
|
@@ -186,17 +186,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
186
186
|
};
|
|
187
187
|
return { update, destroy };
|
|
188
188
|
}
|
|
189
|
-
const Template = (ReactComponent, customProps) => {
|
|
189
|
+
const Template = (ReactComponent, customProps, options) => {
|
|
190
190
|
return (h, p, addition) => {
|
|
191
|
-
|
|
192
|
-
props
|
|
193
|
-
const key = `${p.prop}-${p.rowIndex || 0}
|
|
191
|
+
var _a;
|
|
192
|
+
const props = (options == null ? void 0 : options.props) ? options.props(p) : { ...customProps, ...p, addition };
|
|
193
|
+
const key = String(((_a = options == null ? void 0 : options.key) == null ? void 0 : _a.call(options, p)) ?? `${p.prop}-${p.rowIndex || 0}`);
|
|
194
194
|
let lastEl = null;
|
|
195
195
|
return h("span", {
|
|
196
196
|
ref: (el) => {
|
|
197
|
-
var
|
|
197
|
+
var _a2;
|
|
198
198
|
if (!el) {
|
|
199
|
-
(
|
|
199
|
+
(_a2 = lastEl == null ? void 0 : lastEl.destroy) == null ? void 0 : _a2.call(lastEl);
|
|
200
200
|
} else {
|
|
201
201
|
lastEl = TemplateConstructor(el, ReactComponent, props, key);
|
|
202
202
|
}
|
|
@@ -255,11 +255,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
255
255
|
return new EditorAdapter(EditorComponent, column, save, close);
|
|
256
256
|
};
|
|
257
257
|
};
|
|
258
|
+
function useTemplates() {
|
|
259
|
+
return React.useMemo(() => ({
|
|
260
|
+
template(component, options) {
|
|
261
|
+
const adapted = { ...options, props: (options == null ? void 0 : options.props) ?? ((context) => ({ context })) };
|
|
262
|
+
return Template(component, void 0, adapted);
|
|
263
|
+
}
|
|
264
|
+
}), []);
|
|
265
|
+
}
|
|
258
266
|
const RevoGrid = /* @__PURE__ */ createReactComponent("revo-grid", void 0, void 0, loader.defineCustomElements);
|
|
259
267
|
exports2.Editor = Editor;
|
|
260
268
|
exports2.EditorAdapter = EditorAdapter;
|
|
261
269
|
exports2.RevoGrid = RevoGrid;
|
|
262
270
|
exports2.Template = Template;
|
|
271
|
+
exports2.useTemplates = useTemplates;
|
|
263
272
|
Object.keys(loader).forEach((k) => {
|
|
264
273
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports2, k)) Object.defineProperty(exports2, k, {
|
|
265
274
|
enumerable: true,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revolist/react-datagrid",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "4.29.
|
|
4
|
+
"version": "4.29.1",
|
|
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",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"files": [
|
|
18
|
-
"dist/"
|
|
18
|
+
"dist/",
|
|
19
|
+
"component-templates.md"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"dev": "vite",
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
"homepage": "https://github.com/revolist/revogrid#readme",
|
|
65
66
|
"license": "MIT",
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"@revolist/revogrid": "4.29.
|
|
68
|
+
"@revolist/revogrid": "4.29.1"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@stencil/core": "^4.43.2",
|