@dxos/react-ui-grid 0.6.11 → 0.6.12-main.5a87ad5
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/dist/lib/browser/index.mjs +69 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/Grid.d.ts +51 -5
- package/dist/types/src/Grid.d.ts.map +1 -1
- package/dist/types/src/Grid.stories.d.ts +11 -3
- package/dist/types/src/Grid.stories.d.ts.map +1 -1
- package/package.json +11 -9
- package/src/Grid.stories.tsx +23 -4
- package/src/Grid.tsx +117 -6
|
@@ -1,20 +1,84 @@
|
|
|
1
1
|
// packages/ui/react-ui-grid/src/Grid.tsx
|
|
2
2
|
import "@dxos/lit-grid/dx-grid.pcss";
|
|
3
3
|
import { createComponent } from "@lit/react";
|
|
4
|
-
import
|
|
4
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
5
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
6
|
+
import React, { forwardRef, useCallback, useLayoutEffect, useState } from "react";
|
|
5
7
|
import { DxGrid as NaturalDxGrid } from "@dxos/lit-grid";
|
|
8
|
+
import { useForwardedRef } from "@dxos/react-ui";
|
|
6
9
|
var DxGrid = createComponent({
|
|
7
10
|
tagName: "dx-grid",
|
|
8
11
|
elementClass: NaturalDxGrid,
|
|
9
12
|
react: React,
|
|
10
13
|
events: {
|
|
11
|
-
onAxisResize: "dx-axis-resize"
|
|
14
|
+
onAxisResize: "dx-axis-resize",
|
|
15
|
+
onEdit: "dx-edit-request",
|
|
16
|
+
onSelect: "dx-grid-cells-select"
|
|
12
17
|
}
|
|
13
18
|
});
|
|
14
|
-
var
|
|
15
|
-
|
|
19
|
+
var initialBox = {
|
|
20
|
+
insetInlineStart: 0,
|
|
21
|
+
insetBlockStart: 0,
|
|
22
|
+
inlineSize: 0,
|
|
23
|
+
blockSize: 0
|
|
24
|
+
};
|
|
25
|
+
var GRID_NAME = "Grid";
|
|
26
|
+
var [createGridContext, createGridScope] = createContextScope(GRID_NAME, []);
|
|
27
|
+
var [GridProvider, useGridContext] = createGridContext(GRID_NAME);
|
|
28
|
+
var GridRoot = ({ id, editing: propsEditing, defaultEditing, onEditingChange, children, __gridScope }) => {
|
|
29
|
+
const [editing = null, setEditing] = useControllableState({
|
|
30
|
+
prop: propsEditing,
|
|
31
|
+
defaultProp: defaultEditing,
|
|
32
|
+
onChange: onEditingChange
|
|
33
|
+
});
|
|
34
|
+
const [editBox, setEditBox] = useState(initialBox);
|
|
35
|
+
return /* @__PURE__ */ React.createElement(GridProvider, {
|
|
36
|
+
id,
|
|
37
|
+
editing,
|
|
38
|
+
setEditing,
|
|
39
|
+
editBox,
|
|
40
|
+
setEditBox,
|
|
41
|
+
scope: __gridScope
|
|
42
|
+
}, children);
|
|
43
|
+
};
|
|
44
|
+
GridRoot.displayName = GRID_NAME;
|
|
45
|
+
var GRID_CONTENT_NAME = "GridContent";
|
|
46
|
+
var GridContent = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
47
|
+
const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);
|
|
48
|
+
const dxGrid = useForwardedRef(forwardedRef);
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
if (dxGrid.current && props.getCells) {
|
|
51
|
+
dxGrid.current.getCells = props.getCells;
|
|
52
|
+
dxGrid.current.requestUpdate("initialCells");
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
props.getCells
|
|
56
|
+
]);
|
|
57
|
+
const handleEdit = useCallback((event) => {
|
|
58
|
+
setEditBox(event.cellBox);
|
|
59
|
+
setEditing({
|
|
60
|
+
index: event.cellIndex,
|
|
61
|
+
initialContent: event.initialContent
|
|
62
|
+
});
|
|
63
|
+
}, []);
|
|
64
|
+
return /* @__PURE__ */ React.createElement(DxGrid, {
|
|
65
|
+
...props,
|
|
66
|
+
gridId: id,
|
|
67
|
+
mode: editing ? "edit" : "browse",
|
|
68
|
+
onEdit: handleEdit,
|
|
69
|
+
ref: dxGrid
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
GridContent.displayName = GRID_CONTENT_NAME;
|
|
73
|
+
var Grid = {
|
|
74
|
+
Root: GridRoot,
|
|
75
|
+
Content: GridContent
|
|
16
76
|
};
|
|
17
77
|
export {
|
|
18
|
-
Grid
|
|
78
|
+
Grid,
|
|
79
|
+
GridContent,
|
|
80
|
+
GridRoot,
|
|
81
|
+
createGridScope,
|
|
82
|
+
useGridContext
|
|
19
83
|
};
|
|
20
84
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Grid.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\nimport '@dxos/lit-grid/dx-grid.pcss';\n\nimport { createComponent, type EventName } from '@lit/react';\nimport React from 'react';\n\nimport { type DxAxisResize, DxGrid as NaturalDxGrid
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["createComponent", "React", "DxGrid", "NaturalDxGrid", "DxGrid", "createComponent", "tagName", "elementClass", "NaturalDxGrid", "react", "React", "events", "onAxisResize", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport '@dxos/lit-grid/dx-grid.pcss';\n\nimport { createComponent, type EventName } from '@lit/react';\nimport { createContextScope, type Scope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n type ComponentProps,\n forwardRef,\n type PropsWithChildren,\n useCallback,\n useLayoutEffect,\n useState,\n} from 'react';\n\nimport { type DxAxisResize, type DxEditRequest, type DxGridCellsSelect, DxGrid as NaturalDxGrid } from '@dxos/lit-grid';\nimport { useForwardedRef } from '@dxos/react-ui';\n\ntype DxGridElement = NaturalDxGrid;\n\nconst DxGrid = createComponent({\n tagName: 'dx-grid',\n elementClass: NaturalDxGrid,\n react: React,\n events: {\n onAxisResize: 'dx-axis-resize' as EventName<DxAxisResize>,\n onEdit: 'dx-edit-request' as EventName<DxEditRequest>,\n onSelect: 'dx-grid-cells-select' as EventName<DxGridCellsSelect>,\n },\n});\n\ntype GridEditBox = DxEditRequest['cellBox'];\n\nconst initialBox = {\n insetInlineStart: 0,\n insetBlockStart: 0,\n inlineSize: 0,\n blockSize: 0,\n} satisfies GridEditBox;\n\ntype GridEditing = { index: DxEditRequest['cellIndex']; initialContent: DxEditRequest['initialContent'] } | null;\n\ntype GridContextValue = {\n id: string;\n editing: GridEditing;\n setEditing: (nextEditing: GridEditing) => void;\n editBox: GridEditBox;\n setEditBox: (nextEditBox: GridEditBox) => void;\n};\n\ntype GridScopedProps<P> = P & { __gridScope?: Scope };\n\nconst GRID_NAME = 'Grid';\n\nconst [createGridContext, createGridScope] = createContextScope(GRID_NAME, []);\n\nconst [GridProvider, useGridContext] = createGridContext<GridContextValue>(GRID_NAME);\n\ntype GridRootProps = PropsWithChildren<\n { id: string } & Partial<{\n editing: GridEditing;\n defaultEditing: GridEditing;\n onEditingChange: (nextEditing: GridEditing) => void;\n }>\n>;\n\nconst GridRoot = ({\n id,\n editing: propsEditing,\n defaultEditing,\n onEditingChange,\n children,\n __gridScope,\n}: GridScopedProps<GridRootProps>) => {\n const [editing = null, setEditing] = useControllableState({\n prop: propsEditing,\n defaultProp: defaultEditing,\n onChange: onEditingChange,\n });\n const [editBox, setEditBox] = useState<GridEditBox>(initialBox);\n return (\n <GridProvider\n id={id}\n editing={editing}\n setEditing={setEditing}\n editBox={editBox}\n setEditBox={setEditBox}\n scope={__gridScope}\n >\n {children}\n </GridProvider>\n );\n};\n\nGridRoot.displayName = GRID_NAME;\n\ntype GridContentProps = Omit<ComponentProps<typeof DxGrid>, 'onEdit'> & {\n getCells?: NonNullable<NaturalDxGrid['getCells']>;\n};\n\nconst GRID_CONTENT_NAME = 'GridContent';\n\nconst GridContent = forwardRef<NaturalDxGrid, GridScopedProps<GridContentProps>>((props, forwardedRef) => {\n const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);\n const dxGrid = useForwardedRef(forwardedRef);\n\n // Needed instead of `useEffect` to ensure the DxGrid ref is defined.\n useLayoutEffect(() => {\n if (dxGrid.current && props.getCells) {\n dxGrid.current.getCells = props.getCells;\n dxGrid.current.requestUpdate('initialCells');\n }\n }, [props.getCells]);\n\n const handleEdit = useCallback((event: DxEditRequest) => {\n setEditBox(event.cellBox);\n setEditing({ index: event.cellIndex, initialContent: event.initialContent });\n }, []);\n\n return <DxGrid {...props} gridId={id} mode={editing ? 'edit' : 'browse'} onEdit={handleEdit} ref={dxGrid} />;\n});\n\nGridContent.displayName = GRID_CONTENT_NAME;\n\nexport const Grid = {\n Root: GridRoot,\n Content: GridContent,\n};\n\nexport { GridRoot, GridContent, useGridContext, createGridScope };\n\nexport type { GridRootProps, GridContentProps, GridEditing, GridEditBox, GridScopedProps, DxGridElement };\n\nexport type { DxGridRange, DxGridAxisMeta, DxGridCells } from '@dxos/lit-grid';\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO;AAEP,SAASA,uBAAuC;AAChD,SAASC,0BAAsC;AAC/C,SAASC,4BAA4B;AACrC,OAAOC,SAELC,YAEAC,aACAC,iBACAC,gBACK;AAEP,SAAwEC,UAAUC,qBAAqB;AACvG,SAASC,uBAAuB;AAIhC,IAAMC,SAASC,gBAAgB;EAC7BC,SAAS;EACTC,cAAcC;EACdC,OAAOC;EACPC,QAAQ;IACNC,cAAc;IACdC,QAAQ;IACRC,UAAU;EACZ;AACF,CAAA;AAIA,IAAMC,aAAa;EACjBC,kBAAkB;EAClBC,iBAAiB;EACjBC,YAAY;EACZC,WAAW;AACb;AAcA,IAAMC,YAAY;AAElB,IAAM,CAACC,mBAAmBC,eAAAA,IAAmBC,mBAAmBH,WAAW,CAAA,CAAE;AAE7E,IAAM,CAACI,cAAcC,cAAAA,IAAkBJ,kBAAoCD,SAAAA;AAU3E,IAAMM,WAAW,CAAC,EAChBC,IACAC,SAASC,cACTC,gBACAC,iBACAC,UACAC,YAAW,MACoB;AAC/B,QAAM,CAACL,UAAU,MAAMM,UAAAA,IAAcC,qBAAqB;IACxDC,MAAMP;IACNQ,aAAaP;IACbQ,UAAUP;EACZ,CAAA;AACA,QAAM,CAACQ,SAASC,UAAAA,IAAcC,SAAsB1B,UAAAA;AACpD,SACE,sBAAA,cAACS,cAAAA;IACCG;IACAC;IACAM;IACAK;IACAC;IACAE,OAAOT;KAEND,QAAAA;AAGP;AAEAN,SAASiB,cAAcvB;AAMvB,IAAMwB,oBAAoB;AAE1B,IAAMC,cAAcC,2BAA6D,CAACC,OAAOC,iBAAAA;AACvF,QAAM,EAAErB,IAAIC,SAASY,YAAYN,WAAU,IAAKT,eAAemB,mBAAmBG,MAAMd,WAAW;AACnG,QAAMgB,SAASC,gBAAgBF,YAAAA;AAG/BG,kBAAgB,MAAA;AACd,QAAIF,OAAOG,WAAWL,MAAMM,UAAU;AACpCJ,aAAOG,QAAQC,WAAWN,MAAMM;AAChCJ,aAAOG,QAAQE,cAAc,cAAA;IAC/B;EACF,GAAG;IAACP,MAAMM;GAAS;AAEnB,QAAME,aAAaC,YAAY,CAACC,UAAAA;AAC9BjB,eAAWiB,MAAMC,OAAO;AACxBxB,eAAW;MAAEyB,OAAOF,MAAMG;MAAWC,gBAAgBJ,MAAMI;IAAe,CAAA;EAC5E,GAAG,CAAA,CAAE;AAEL,SAAO,sBAAA,cAACzD,QAAAA;IAAQ,GAAG2C;IAAOe,QAAQnC;IAAIoC,MAAMnC,UAAU,SAAS;IAAUf,QAAQ0C;IAAYS,KAAKf;;AACpG,CAAA;AAEAJ,YAAYF,cAAcC;AAEnB,IAAMqB,OAAO;EAClBC,MAAMxC;EACNyC,SAAStB;AACX;",
|
|
6
|
+
"names": ["createComponent", "createContextScope", "useControllableState", "React", "forwardRef", "useCallback", "useLayoutEffect", "useState", "DxGrid", "NaturalDxGrid", "useForwardedRef", "DxGrid", "createComponent", "tagName", "elementClass", "NaturalDxGrid", "react", "React", "events", "onAxisResize", "onEdit", "onSelect", "initialBox", "insetInlineStart", "insetBlockStart", "inlineSize", "blockSize", "GRID_NAME", "createGridContext", "createGridScope", "createContextScope", "GridProvider", "useGridContext", "GridRoot", "id", "editing", "propsEditing", "defaultEditing", "onEditingChange", "children", "__gridScope", "setEditing", "useControllableState", "prop", "defaultProp", "onChange", "editBox", "setEditBox", "useState", "scope", "displayName", "GRID_CONTENT_NAME", "GridContent", "forwardRef", "props", "forwardedRef", "dxGrid", "useForwardedRef", "useLayoutEffect", "current", "getCells", "requestUpdate", "handleEdit", "useCallback", "event", "cellBox", "index", "cellIndex", "initialContent", "gridId", "mode", "ref", "Grid", "Root", "Content"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/react-ui-grid/src/Grid.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-grid/src/Grid.tsx":{"bytes":11861,"imports":[{"path":"@dxos/lit-grid/dx-grid.pcss","kind":"import-statement","external":true},{"path":"@lit/react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-grid/src/index.ts":{"bytes":489,"imports":[{"path":"packages/ui/react-ui-grid/src/Grid.tsx","kind":"import-statement","original":"./Grid"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-grid/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6653},"packages/ui/react-ui-grid/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/lit-grid/dx-grid.pcss","kind":"import-statement","external":true},{"path":"@lit/react","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["Grid","GridContent","GridRoot","createGridScope","useGridContext"],"entryPoint":"packages/ui/react-ui-grid/src/index.ts","inputs":{"packages/ui/react-ui-grid/src/Grid.tsx":{"bytesInOutput":2360},"packages/ui/react-ui-grid/src/index.ts":{"bytesInOutput":0}},"bytes":2520}}}
|
package/dist/types/src/Grid.d.ts
CHANGED
|
@@ -1,8 +1,54 @@
|
|
|
1
1
|
import '@dxos/lit-grid/dx-grid.pcss';
|
|
2
|
-
import
|
|
3
|
-
import { type
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { type EventName } from '@lit/react';
|
|
3
|
+
import { type Scope } from '@radix-ui/react-context';
|
|
4
|
+
import React, { type ComponentProps, type PropsWithChildren } from 'react';
|
|
5
|
+
import { type DxAxisResize, type DxEditRequest, type DxGridCellsSelect, DxGrid as NaturalDxGrid } from '@dxos/lit-grid';
|
|
6
|
+
type DxGridElement = NaturalDxGrid;
|
|
7
|
+
declare const DxGrid: import("@lit/react").ReactWebComponent<NaturalDxGrid, {
|
|
8
|
+
onAxisResize: EventName<DxAxisResize>;
|
|
9
|
+
onEdit: EventName<DxEditRequest>;
|
|
10
|
+
onSelect: EventName<DxGridCellsSelect>;
|
|
11
|
+
}>;
|
|
12
|
+
type GridEditBox = DxEditRequest['cellBox'];
|
|
13
|
+
type GridEditing = {
|
|
14
|
+
index: DxEditRequest['cellIndex'];
|
|
15
|
+
initialContent: DxEditRequest['initialContent'];
|
|
16
|
+
} | null;
|
|
17
|
+
type GridContextValue = {
|
|
18
|
+
id: string;
|
|
19
|
+
editing: GridEditing;
|
|
20
|
+
setEditing: (nextEditing: GridEditing) => void;
|
|
21
|
+
editBox: GridEditBox;
|
|
22
|
+
setEditBox: (nextEditBox: GridEditBox) => void;
|
|
6
23
|
};
|
|
7
|
-
|
|
24
|
+
type GridScopedProps<P> = P & {
|
|
25
|
+
__gridScope?: Scope;
|
|
26
|
+
};
|
|
27
|
+
declare const createGridScope: import("@radix-ui/react-context").CreateScope;
|
|
28
|
+
declare const useGridContext: (consumerName: string, scope: Scope<GridContextValue | undefined>) => GridContextValue;
|
|
29
|
+
type GridRootProps = PropsWithChildren<{
|
|
30
|
+
id: string;
|
|
31
|
+
} & Partial<{
|
|
32
|
+
editing: GridEditing;
|
|
33
|
+
defaultEditing: GridEditing;
|
|
34
|
+
onEditingChange: (nextEditing: GridEditing) => void;
|
|
35
|
+
}>>;
|
|
36
|
+
declare const GridRoot: {
|
|
37
|
+
({ id, editing: propsEditing, defaultEditing, onEditingChange, children, __gridScope, }: GridScopedProps<GridRootProps>): React.JSX.Element;
|
|
38
|
+
displayName: string;
|
|
39
|
+
};
|
|
40
|
+
type GridContentProps = Omit<ComponentProps<typeof DxGrid>, 'onEdit'> & {
|
|
41
|
+
getCells?: NonNullable<NaturalDxGrid['getCells']>;
|
|
42
|
+
};
|
|
43
|
+
declare const GridContent: React.ForwardRefExoticComponent<Omit<GridScopedProps<GridContentProps>, "ref"> & React.RefAttributes<NaturalDxGrid>>;
|
|
44
|
+
export declare const Grid: {
|
|
45
|
+
Root: {
|
|
46
|
+
({ id, editing: propsEditing, defaultEditing, onEditingChange, children, __gridScope, }: GridScopedProps<GridRootProps>): React.JSX.Element;
|
|
47
|
+
displayName: string;
|
|
48
|
+
};
|
|
49
|
+
Content: React.ForwardRefExoticComponent<Omit<GridScopedProps<GridContentProps>, "ref"> & React.RefAttributes<NaturalDxGrid>>;
|
|
50
|
+
};
|
|
51
|
+
export { GridRoot, GridContent, useGridContext, createGridScope };
|
|
52
|
+
export type { GridRootProps, GridContentProps, GridEditing, GridEditBox, GridScopedProps, DxGridElement };
|
|
53
|
+
export type { DxGridRange, DxGridAxisMeta, DxGridCells } from '@dxos/lit-grid';
|
|
8
54
|
//# sourceMappingURL=Grid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../../src/Grid.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../../src/Grid.tsx"],"names":[],"mappings":"AAIA,OAAO,6BAA6B,CAAC;AAErC,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,KAAK,EAAE,EACZ,KAAK,cAAc,EAEnB,KAAK,iBAAiB,EAIvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGxH,KAAK,aAAa,GAAG,aAAa,CAAC;AAEnC,QAAA,MAAM,MAAM;kBAK0B,SAAS,CAAC,YAAY,CAAC;YAC5B,SAAS,CAAC,aAAa,CAAC;cACjB,SAAS,CAAC,iBAAiB,CAAC;EAElE,CAAC;AAEH,KAAK,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAS5C,KAAK,WAAW,GAAG;IAAE,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAAC,cAAc,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;CAAE,GAAG,IAAI,CAAC;AAEjH,KAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;IAC/C,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAItD,QAAA,MAA0B,eAAe,+CAAqC,CAAC;AAE/E,QAAA,MAAqB,cAAc,wFAAkD,CAAC;AAEtF,KAAK,aAAa,GAAG,iBAAiB,CACpC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,eAAe,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;CACrD,CAAC,CACH,CAAC;AAEF,QAAA,MAAM,QAAQ;6FAOX,eAAe,CAAC,aAAa,CAAC;;CAmBhC,CAAC;AAIF,KAAK,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG;IACtE,QAAQ,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;CACnD,CAAC;AAIF,QAAA,MAAM,WAAW,sHAkBf,CAAC;AAIH,eAAO,MAAM,IAAI;;iGAnDd,eAAe,CAAC,aAAa,CAAC;;;;CAsDhC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC;AAElE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC;AAE1G,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@dxos-theme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { type GridContentProps, type GridRootProps } from './Grid';
|
|
4
|
+
type StoryGridProps = GridContentProps & Pick<GridRootProps, 'onEditingChange'>;
|
|
2
5
|
declare const _default: {
|
|
3
6
|
title: string;
|
|
4
|
-
component: (props:
|
|
7
|
+
component: ({ onEditingChange, ...props }: StoryGridProps) => React.JSX.Element;
|
|
5
8
|
decorators: import("@storybook/react/*").Decorator[];
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: string;
|
|
11
|
+
};
|
|
6
12
|
};
|
|
7
13
|
export default _default;
|
|
8
14
|
export declare const Basic: {
|
|
9
15
|
args: {
|
|
10
|
-
|
|
16
|
+
id: string;
|
|
17
|
+
initialCells: {
|
|
11
18
|
'1,1': {
|
|
12
19
|
value: string;
|
|
13
20
|
};
|
|
@@ -38,6 +45,7 @@ export declare const Basic: {
|
|
|
38
45
|
};
|
|
39
46
|
};
|
|
40
47
|
onAxisResize: (event: import("packages/ui/lit-grid/dist/types/src").DxAxisResize) => void;
|
|
48
|
+
onEditingChange: (event: import("./Grid").GridEditing) => void;
|
|
41
49
|
};
|
|
42
50
|
};
|
|
43
51
|
//# sourceMappingURL=Grid.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.stories.d.ts","sourceRoot":"","sources":["../../../src/Grid.stories.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Grid.stories.d.ts","sourceRoot":"","sources":["../../../src/Grid.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAQ,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEzE,KAAK,cAAc,GAAG,gBAAgB,GAAG,IAAI,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;;;+CAE9B,cAAc;;;;;;AAQhE,wBAKE;AAEF,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-grid",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12-main.5a87ad5",
|
|
4
4
|
"description": "React component which manages a `dx-grid` Lit web component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -22,22 +22,24 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@lit/react": "^1.0.5",
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@dxos/
|
|
28
|
-
"@dxos/
|
|
25
|
+
"@radix-ui/react-context": "^1.0.0",
|
|
26
|
+
"@radix-ui/react-use-controllable-state": "^1.0.0",
|
|
27
|
+
"@dxos/lit-grid": "0.6.12-main.5a87ad5",
|
|
28
|
+
"@dxos/react-ui": "0.6.12-main.5a87ad5",
|
|
29
|
+
"@dxos/react-ui-theme": "0.6.12-main.5a87ad5",
|
|
30
|
+
"@dxos/util": "0.6.12-main.5a87ad5"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
33
|
"@types/react": "~18.2.0",
|
|
32
34
|
"@types/react-dom": "~18.2.0",
|
|
33
35
|
"react": "~18.2.0",
|
|
34
36
|
"react-dom": "~18.2.0",
|
|
35
|
-
"vite": "
|
|
36
|
-
"@dxos/storybook-utils": "0.6.
|
|
37
|
+
"vite": "5.4.7",
|
|
38
|
+
"@dxos/storybook-utils": "0.6.12-main.5a87ad5"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
|
-
"react": "
|
|
40
|
-
"react-dom": "
|
|
41
|
+
"react": "~18.2.0",
|
|
42
|
+
"react-dom": "~18.2.0"
|
|
41
43
|
},
|
|
42
44
|
"publishConfig": {
|
|
43
45
|
"access": "public"
|
package/src/Grid.stories.tsx
CHANGED
|
@@ -2,19 +2,35 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
5
9
|
import { withTheme } from '@dxos/storybook-utils';
|
|
6
10
|
|
|
7
|
-
import { Grid, type
|
|
11
|
+
import { Grid, type GridContentProps, type GridRootProps } from './Grid';
|
|
12
|
+
|
|
13
|
+
type StoryGridProps = GridContentProps & Pick<GridRootProps, 'onEditingChange'>;
|
|
14
|
+
|
|
15
|
+
const StoryGrid = ({ onEditingChange, ...props }: StoryGridProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<Grid.Root id='story' onEditingChange={onEditingChange}>
|
|
18
|
+
<Grid.Content {...props} />
|
|
19
|
+
</Grid.Root>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
8
22
|
|
|
9
23
|
export default {
|
|
10
24
|
title: 'react-ui-grid/Grid',
|
|
11
|
-
component:
|
|
25
|
+
component: StoryGrid,
|
|
12
26
|
decorators: [withTheme],
|
|
27
|
+
parameters: { layout: 'fullscreen' },
|
|
13
28
|
};
|
|
14
29
|
|
|
15
30
|
export const Basic = {
|
|
16
31
|
args: {
|
|
17
|
-
|
|
32
|
+
id: 'story',
|
|
33
|
+
initialCells: {
|
|
18
34
|
'1,1': {
|
|
19
35
|
// end: '8,1',
|
|
20
36
|
value: 'Weekly sales report',
|
|
@@ -38,5 +54,8 @@ export const Basic = {
|
|
|
38
54
|
onAxisResize: (event) => {
|
|
39
55
|
console.log('[axis resize]', event);
|
|
40
56
|
},
|
|
41
|
-
|
|
57
|
+
onEditingChange: (event) => {
|
|
58
|
+
console.log('[edit]', event);
|
|
59
|
+
},
|
|
60
|
+
} satisfies StoryGridProps,
|
|
42
61
|
};
|
package/src/Grid.tsx
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
|
+
|
|
4
5
|
import '@dxos/lit-grid/dx-grid.pcss';
|
|
5
6
|
|
|
6
7
|
import { createComponent, type EventName } from '@lit/react';
|
|
7
|
-
import
|
|
8
|
+
import { createContextScope, type Scope } from '@radix-ui/react-context';
|
|
9
|
+
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
10
|
+
import React, {
|
|
11
|
+
type ComponentProps,
|
|
12
|
+
forwardRef,
|
|
13
|
+
type PropsWithChildren,
|
|
14
|
+
useCallback,
|
|
15
|
+
useLayoutEffect,
|
|
16
|
+
useState,
|
|
17
|
+
} from 'react';
|
|
18
|
+
|
|
19
|
+
import { type DxAxisResize, type DxEditRequest, type DxGridCellsSelect, DxGrid as NaturalDxGrid } from '@dxos/lit-grid';
|
|
20
|
+
import { useForwardedRef } from '@dxos/react-ui';
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
type DxGridElement = NaturalDxGrid;
|
|
10
23
|
|
|
11
24
|
const DxGrid = createComponent({
|
|
12
25
|
tagName: 'dx-grid',
|
|
@@ -14,13 +27,111 @@ const DxGrid = createComponent({
|
|
|
14
27
|
react: React,
|
|
15
28
|
events: {
|
|
16
29
|
onAxisResize: 'dx-axis-resize' as EventName<DxAxisResize>,
|
|
30
|
+
onEdit: 'dx-edit-request' as EventName<DxEditRequest>,
|
|
31
|
+
onSelect: 'dx-grid-cells-select' as EventName<DxGridCellsSelect>,
|
|
17
32
|
},
|
|
18
33
|
});
|
|
19
34
|
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
type GridEditBox = DxEditRequest['cellBox'];
|
|
36
|
+
|
|
37
|
+
const initialBox = {
|
|
38
|
+
insetInlineStart: 0,
|
|
39
|
+
insetBlockStart: 0,
|
|
40
|
+
inlineSize: 0,
|
|
41
|
+
blockSize: 0,
|
|
42
|
+
} satisfies GridEditBox;
|
|
43
|
+
|
|
44
|
+
type GridEditing = { index: DxEditRequest['cellIndex']; initialContent: DxEditRequest['initialContent'] } | null;
|
|
45
|
+
|
|
46
|
+
type GridContextValue = {
|
|
47
|
+
id: string;
|
|
48
|
+
editing: GridEditing;
|
|
49
|
+
setEditing: (nextEditing: GridEditing) => void;
|
|
50
|
+
editBox: GridEditBox;
|
|
51
|
+
setEditBox: (nextEditBox: GridEditBox) => void;
|
|
22
52
|
};
|
|
23
53
|
|
|
24
|
-
|
|
25
|
-
|
|
54
|
+
type GridScopedProps<P> = P & { __gridScope?: Scope };
|
|
55
|
+
|
|
56
|
+
const GRID_NAME = 'Grid';
|
|
57
|
+
|
|
58
|
+
const [createGridContext, createGridScope] = createContextScope(GRID_NAME, []);
|
|
59
|
+
|
|
60
|
+
const [GridProvider, useGridContext] = createGridContext<GridContextValue>(GRID_NAME);
|
|
61
|
+
|
|
62
|
+
type GridRootProps = PropsWithChildren<
|
|
63
|
+
{ id: string } & Partial<{
|
|
64
|
+
editing: GridEditing;
|
|
65
|
+
defaultEditing: GridEditing;
|
|
66
|
+
onEditingChange: (nextEditing: GridEditing) => void;
|
|
67
|
+
}>
|
|
68
|
+
>;
|
|
69
|
+
|
|
70
|
+
const GridRoot = ({
|
|
71
|
+
id,
|
|
72
|
+
editing: propsEditing,
|
|
73
|
+
defaultEditing,
|
|
74
|
+
onEditingChange,
|
|
75
|
+
children,
|
|
76
|
+
__gridScope,
|
|
77
|
+
}: GridScopedProps<GridRootProps>) => {
|
|
78
|
+
const [editing = null, setEditing] = useControllableState({
|
|
79
|
+
prop: propsEditing,
|
|
80
|
+
defaultProp: defaultEditing,
|
|
81
|
+
onChange: onEditingChange,
|
|
82
|
+
});
|
|
83
|
+
const [editBox, setEditBox] = useState<GridEditBox>(initialBox);
|
|
84
|
+
return (
|
|
85
|
+
<GridProvider
|
|
86
|
+
id={id}
|
|
87
|
+
editing={editing}
|
|
88
|
+
setEditing={setEditing}
|
|
89
|
+
editBox={editBox}
|
|
90
|
+
setEditBox={setEditBox}
|
|
91
|
+
scope={__gridScope}
|
|
92
|
+
>
|
|
93
|
+
{children}
|
|
94
|
+
</GridProvider>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
GridRoot.displayName = GRID_NAME;
|
|
99
|
+
|
|
100
|
+
type GridContentProps = Omit<ComponentProps<typeof DxGrid>, 'onEdit'> & {
|
|
101
|
+
getCells?: NonNullable<NaturalDxGrid['getCells']>;
|
|
26
102
|
};
|
|
103
|
+
|
|
104
|
+
const GRID_CONTENT_NAME = 'GridContent';
|
|
105
|
+
|
|
106
|
+
const GridContent = forwardRef<NaturalDxGrid, GridScopedProps<GridContentProps>>((props, forwardedRef) => {
|
|
107
|
+
const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);
|
|
108
|
+
const dxGrid = useForwardedRef(forwardedRef);
|
|
109
|
+
|
|
110
|
+
// Needed instead of `useEffect` to ensure the DxGrid ref is defined.
|
|
111
|
+
useLayoutEffect(() => {
|
|
112
|
+
if (dxGrid.current && props.getCells) {
|
|
113
|
+
dxGrid.current.getCells = props.getCells;
|
|
114
|
+
dxGrid.current.requestUpdate('initialCells');
|
|
115
|
+
}
|
|
116
|
+
}, [props.getCells]);
|
|
117
|
+
|
|
118
|
+
const handleEdit = useCallback((event: DxEditRequest) => {
|
|
119
|
+
setEditBox(event.cellBox);
|
|
120
|
+
setEditing({ index: event.cellIndex, initialContent: event.initialContent });
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
return <DxGrid {...props} gridId={id} mode={editing ? 'edit' : 'browse'} onEdit={handleEdit} ref={dxGrid} />;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
GridContent.displayName = GRID_CONTENT_NAME;
|
|
127
|
+
|
|
128
|
+
export const Grid = {
|
|
129
|
+
Root: GridRoot,
|
|
130
|
+
Content: GridContent,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export { GridRoot, GridContent, useGridContext, createGridScope };
|
|
134
|
+
|
|
135
|
+
export type { GridRootProps, GridContentProps, GridEditing, GridEditBox, GridScopedProps, DxGridElement };
|
|
136
|
+
|
|
137
|
+
export type { DxGridRange, DxGridAxisMeta, DxGridCells } from '@dxos/lit-grid';
|