@dxos/react-ui-grid 0.6.12 → 0.6.13-main.09887cd
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 +248 -6
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/CellEditor/CellEditor.d.ts +34 -0
- package/dist/types/src/CellEditor/CellEditor.d.ts.map +1 -0
- package/dist/types/src/CellEditor/GridCellEditor.d.ts +7 -0
- package/dist/types/src/CellEditor/GridCellEditor.d.ts.map +1 -0
- package/dist/types/src/CellEditor/index.d.ts +3 -0
- package/dist/types/src/CellEditor/index.d.ts.map +1 -0
- package/dist/types/src/Grid/Grid.d.ts +55 -0
- package/dist/types/src/Grid/Grid.d.ts.map +1 -0
- package/dist/types/src/Grid/Grid.stories.d.ts +60 -0
- package/dist/types/src/Grid/Grid.stories.d.ts.map +1 -0
- package/dist/types/src/Grid/index.d.ts +2 -0
- package/dist/types/src/Grid/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +15 -9
- package/src/CellEditor/CellEditor.tsx +165 -0
- package/src/CellEditor/GridCellEditor.tsx +28 -0
- package/src/CellEditor/index.ts +6 -0
- package/src/Grid/Grid.stories.tsx +95 -0
- package/src/Grid/Grid.tsx +148 -0
- package/src/Grid/index.ts +5 -0
- package/src/index.ts +1 -0
- package/dist/types/src/Grid.d.ts +0 -8
- package/dist/types/src/Grid.d.ts.map +0 -1
- package/dist/types/src/Grid.stories.d.ts +0 -43
- package/dist/types/src/Grid.stories.d.ts.map +0 -1
- package/src/Grid.stories.tsx +0 -42
- package/src/Grid.tsx +0 -26
|
@@ -1,20 +1,262 @@
|
|
|
1
|
-
// packages/ui/react-ui-grid/src/Grid.tsx
|
|
1
|
+
// packages/ui/react-ui-grid/src/Grid/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";
|
|
9
|
+
import { colToA1Notation, rowToA1Notation, closestCell } from "@dxos/lit-grid";
|
|
6
10
|
var DxGrid = createComponent({
|
|
7
11
|
tagName: "dx-grid",
|
|
8
12
|
elementClass: NaturalDxGrid,
|
|
9
13
|
react: React,
|
|
10
14
|
events: {
|
|
11
|
-
onAxisResize: "dx-axis-resize"
|
|
15
|
+
onAxisResize: "dx-axis-resize",
|
|
16
|
+
onEdit: "dx-edit-request",
|
|
17
|
+
onSelect: "dx-grid-cells-select"
|
|
12
18
|
}
|
|
13
19
|
});
|
|
14
|
-
var
|
|
15
|
-
|
|
20
|
+
var initialBox = {
|
|
21
|
+
insetInlineStart: 0,
|
|
22
|
+
insetBlockStart: 0,
|
|
23
|
+
inlineSize: 0,
|
|
24
|
+
blockSize: 0
|
|
25
|
+
};
|
|
26
|
+
var GRID_NAME = "Grid";
|
|
27
|
+
var [createGridContext, createGridScope] = createContextScope(GRID_NAME, []);
|
|
28
|
+
var [GridProvider, useGridContext] = createGridContext(GRID_NAME);
|
|
29
|
+
var GridRoot = ({ id, editing: propsEditing, defaultEditing, onEditingChange, children, __gridScope }) => {
|
|
30
|
+
const [editing = null, setEditing] = useControllableState({
|
|
31
|
+
prop: propsEditing,
|
|
32
|
+
defaultProp: defaultEditing,
|
|
33
|
+
onChange: onEditingChange
|
|
34
|
+
});
|
|
35
|
+
const [editBox, setEditBox] = useState(initialBox);
|
|
36
|
+
return /* @__PURE__ */ React.createElement(GridProvider, {
|
|
37
|
+
id,
|
|
38
|
+
editing,
|
|
39
|
+
setEditing,
|
|
40
|
+
editBox,
|
|
41
|
+
setEditBox,
|
|
42
|
+
scope: __gridScope
|
|
43
|
+
}, children);
|
|
44
|
+
};
|
|
45
|
+
GridRoot.displayName = GRID_NAME;
|
|
46
|
+
var GRID_CONTENT_NAME = "GridContent";
|
|
47
|
+
var GridContent = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
48
|
+
const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);
|
|
49
|
+
const dxGrid = useForwardedRef(forwardedRef);
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
if (dxGrid.current && props.getCells) {
|
|
52
|
+
dxGrid.current.getCells = props.getCells;
|
|
53
|
+
dxGrid.current.requestUpdate("initialCells");
|
|
54
|
+
}
|
|
55
|
+
}, [
|
|
56
|
+
props.getCells
|
|
57
|
+
]);
|
|
58
|
+
const handleEdit = useCallback((event) => {
|
|
59
|
+
setEditBox(event.cellBox);
|
|
60
|
+
setEditing({
|
|
61
|
+
index: event.cellIndex,
|
|
62
|
+
initialContent: event.initialContent
|
|
63
|
+
});
|
|
64
|
+
}, []);
|
|
65
|
+
return /* @__PURE__ */ React.createElement(DxGrid, {
|
|
66
|
+
...props,
|
|
67
|
+
gridId: id,
|
|
68
|
+
mode: editing ? "edit" : "browse",
|
|
69
|
+
onEdit: handleEdit,
|
|
70
|
+
ref: dxGrid
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
GridContent.displayName = GRID_CONTENT_NAME;
|
|
74
|
+
var Grid = {
|
|
75
|
+
Root: GridRoot,
|
|
76
|
+
Content: GridContent
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// packages/ui/react-ui-grid/src/CellEditor/CellEditor.tsx
|
|
80
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
81
|
+
import React2 from "react";
|
|
82
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
83
|
+
import { createBasicExtensions, createThemeExtensions, preventNewline, useTextEditor } from "@dxos/react-ui-editor";
|
|
84
|
+
var editorKeys = ({ onNav, onClose }) => {
|
|
85
|
+
return keymap.of([
|
|
86
|
+
{
|
|
87
|
+
key: "ArrowUp",
|
|
88
|
+
run: (editor) => {
|
|
89
|
+
const value = editor.state.doc.toString();
|
|
90
|
+
onNav?.(value, {
|
|
91
|
+
key: "ArrowUp"
|
|
92
|
+
});
|
|
93
|
+
return !!onNav;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "ArrowDown",
|
|
98
|
+
run: (editor) => {
|
|
99
|
+
const value = editor.state.doc.toString();
|
|
100
|
+
onNav?.(value, {
|
|
101
|
+
key: "ArrowDown"
|
|
102
|
+
});
|
|
103
|
+
return !!onNav;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: "ArrowLeft",
|
|
108
|
+
run: (editor) => {
|
|
109
|
+
const value = editor.state.doc.toString();
|
|
110
|
+
onNav?.(value, {
|
|
111
|
+
key: "ArrowLeft"
|
|
112
|
+
});
|
|
113
|
+
return !!onNav;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
key: "ArrowRight",
|
|
118
|
+
run: (editor) => {
|
|
119
|
+
const value = editor.state.doc.toString();
|
|
120
|
+
onNav?.(value, {
|
|
121
|
+
key: "ArrowRight"
|
|
122
|
+
});
|
|
123
|
+
return !!onNav;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
key: "Enter",
|
|
128
|
+
run: (editor) => {
|
|
129
|
+
onClose(editor.state.doc.toString(), {
|
|
130
|
+
key: "Enter"
|
|
131
|
+
});
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
shift: (editor) => {
|
|
135
|
+
onClose(editor.state.doc.toString(), {
|
|
136
|
+
key: "Enter",
|
|
137
|
+
shift: true
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
key: "Tab",
|
|
144
|
+
run: (editor) => {
|
|
145
|
+
onClose(editor.state.doc.toString(), {
|
|
146
|
+
key: "Tab"
|
|
147
|
+
});
|
|
148
|
+
return true;
|
|
149
|
+
},
|
|
150
|
+
shift: (editor) => {
|
|
151
|
+
onClose(editor.state.doc.toString(), {
|
|
152
|
+
key: "Tab",
|
|
153
|
+
shift: true
|
|
154
|
+
});
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
key: "Escape",
|
|
160
|
+
run: () => {
|
|
161
|
+
onClose(void 0, {
|
|
162
|
+
key: "Escape"
|
|
163
|
+
});
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
]);
|
|
168
|
+
};
|
|
169
|
+
var editorVariants = {
|
|
170
|
+
// TODO(thure): remove when legacy is no longer used.
|
|
171
|
+
legacy: {
|
|
172
|
+
root: "flex w-full",
|
|
173
|
+
editor: "flex w-full [&>.cm-scroller]:scrollbar-none",
|
|
174
|
+
content: "!px-2 !py-1"
|
|
175
|
+
},
|
|
176
|
+
grid: {
|
|
177
|
+
root: "absolute z-[1]",
|
|
178
|
+
editor: "[&>.cm-scroller]:scrollbar-none tabular-nums",
|
|
179
|
+
content: "!border !border-transparent !p-0.5"
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var CellEditor = ({ value, extension, autoFocus, onBlur, variant = "legacy", box, gridId }) => {
|
|
183
|
+
const { themeMode } = useThemeContext();
|
|
184
|
+
const { parentRef } = useTextEditor(() => {
|
|
185
|
+
return {
|
|
186
|
+
autoFocus,
|
|
187
|
+
initialValue: value,
|
|
188
|
+
selection: {
|
|
189
|
+
anchor: value?.length ?? 0
|
|
190
|
+
},
|
|
191
|
+
extensions: [
|
|
192
|
+
extension ?? [],
|
|
193
|
+
preventNewline,
|
|
194
|
+
EditorView.focusChangeEffect.of((_, focusing) => {
|
|
195
|
+
if (!focusing) {
|
|
196
|
+
onBlur?.({
|
|
197
|
+
type: "blur"
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}),
|
|
202
|
+
createBasicExtensions({
|
|
203
|
+
lineWrapping: false
|
|
204
|
+
}),
|
|
205
|
+
createThemeExtensions({
|
|
206
|
+
themeMode,
|
|
207
|
+
slots: {
|
|
208
|
+
editor: {
|
|
209
|
+
className: editorVariants[variant].editor
|
|
210
|
+
},
|
|
211
|
+
content: {
|
|
212
|
+
className: editorVariants[variant].content
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
]
|
|
217
|
+
};
|
|
218
|
+
}, [
|
|
219
|
+
extension,
|
|
220
|
+
autoFocus,
|
|
221
|
+
value,
|
|
222
|
+
variant,
|
|
223
|
+
onBlur
|
|
224
|
+
]);
|
|
225
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
226
|
+
ref: parentRef,
|
|
227
|
+
className: editorVariants[variant].root,
|
|
228
|
+
style: box,
|
|
229
|
+
...gridId && {
|
|
230
|
+
"data-grid": gridId
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// packages/ui/react-ui-grid/src/CellEditor/GridCellEditor.tsx
|
|
236
|
+
import React3 from "react";
|
|
237
|
+
var GridCellEditor = ({ extension, getCellContent, __gridScope }) => {
|
|
238
|
+
const { id, editing, setEditing, editBox } = useGridContext("GridSheetCellEditor", __gridScope);
|
|
239
|
+
return editing ? /* @__PURE__ */ React3.createElement(CellEditor, {
|
|
240
|
+
variant: "grid",
|
|
241
|
+
value: editing.initialContent ?? getCellContent(editing.index),
|
|
242
|
+
autoFocus: true,
|
|
243
|
+
box: editBox,
|
|
244
|
+
onBlur: () => setEditing(null),
|
|
245
|
+
extension,
|
|
246
|
+
gridId: id
|
|
247
|
+
}) : null;
|
|
16
248
|
};
|
|
17
249
|
export {
|
|
18
|
-
|
|
250
|
+
CellEditor,
|
|
251
|
+
Grid,
|
|
252
|
+
GridCellEditor,
|
|
253
|
+
GridContent,
|
|
254
|
+
GridRoot,
|
|
255
|
+
closestCell,
|
|
256
|
+
colToA1Notation,
|
|
257
|
+
createGridScope,
|
|
258
|
+
editorKeys,
|
|
259
|
+
rowToA1Notation,
|
|
260
|
+
useGridContext
|
|
19
261
|
};
|
|
20
262
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 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", "
|
|
3
|
+
"sources": ["../../../src/Grid/Grid.tsx", "../../../src/CellEditor/CellEditor.tsx", "../../../src/CellEditor/GridCellEditor.tsx"],
|
|
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 { colToA1Notation, rowToA1Notation, closestCell } from '@dxos/lit-grid';\n\nexport type {\n DxGridRange,\n DxGridAxisMeta,\n DxAxisResize,\n DxGridCells,\n DxGridPlaneRange,\n DxGridPlaneCells,\n DxGridPlane,\n DxGridPosition,\n} from '@dxos/lit-grid';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport { EditorView, keymap } from '@codemirror/view';\nimport React, { type DOMAttributes, type KeyboardEvent } from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n type UseTextEditorProps,\n createBasicExtensions,\n createThemeExtensions,\n preventNewline,\n useTextEditor,\n} from '@dxos/react-ui-editor';\n\nimport { type GridEditBox } from '../Grid';\n\ntype EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & { shift?: boolean };\n\nexport type EditorKeysProps = {\n onClose: (value: string | undefined, event: EditorKeyEvent) => void;\n onNav?: (value: string | undefined, event: EditorKeyEvent) => void;\n};\n\n// TODO(Zan): Should each consumer be responsible for defining these?\nexport const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {\n return keymap.of([\n {\n key: 'ArrowUp',\n run: (editor) => {\n const value = editor.state.doc.toString();\n onNav?.(value, { key: 'ArrowUp' });\n return !!onNav;\n },\n },\n {\n key: 'ArrowDown',\n run: (editor) => {\n const value = editor.state.doc.toString();\n onNav?.(value, { key: 'ArrowDown' });\n return !!onNav;\n },\n },\n {\n key: 'ArrowLeft',\n run: (editor) => {\n const value = editor.state.doc.toString();\n onNav?.(value, { key: 'ArrowLeft' });\n return !!onNav;\n },\n },\n {\n key: 'ArrowRight',\n run: (editor) => {\n const value = editor.state.doc.toString();\n onNav?.(value, { key: 'ArrowRight' });\n return !!onNav;\n },\n },\n {\n key: 'Enter',\n run: (editor) => {\n onClose(editor.state.doc.toString(), { key: 'Enter' });\n return true;\n },\n shift: (editor) => {\n onClose(editor.state.doc.toString(), { key: 'Enter', shift: true });\n return true;\n },\n },\n {\n key: 'Tab',\n run: (editor) => {\n onClose(editor.state.doc.toString(), { key: 'Tab' });\n return true;\n },\n shift: (editor) => {\n onClose(editor.state.doc.toString(), { key: 'Tab', shift: true });\n return true;\n },\n },\n {\n key: 'Escape',\n run: () => {\n onClose(undefined, { key: 'Escape' });\n return true;\n },\n },\n ]);\n};\n\nexport type CellEditorProps = {\n value?: string;\n extension?: Extension;\n variant?: keyof typeof editorVariants;\n box?: GridEditBox;\n gridId?: string;\n} & Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<DOMAttributes<HTMLInputElement>, 'onBlur' | 'onKeyDown'>;\n\nconst editorVariants = {\n // TODO(thure): remove when legacy is no longer used.\n legacy: {\n root: 'flex w-full',\n editor: 'flex w-full [&>.cm-scroller]:scrollbar-none',\n content: '!px-2 !py-1',\n },\n grid: {\n root: 'absolute z-[1]',\n editor: '[&>.cm-scroller]:scrollbar-none tabular-nums',\n content: '!border !border-transparent !p-0.5',\n },\n};\n\nexport const CellEditor = ({\n value,\n extension,\n autoFocus,\n onBlur,\n variant = 'legacy',\n box,\n gridId,\n}: CellEditorProps) => {\n const { themeMode } = useThemeContext();\n const { parentRef } = useTextEditor(() => {\n return {\n autoFocus,\n initialValue: value,\n selection: { anchor: value?.length ?? 0 },\n extensions: [\n extension ?? [],\n preventNewline,\n EditorView.focusChangeEffect.of((_, focusing) => {\n if (!focusing) {\n onBlur?.({ type: 'blur' } as any);\n }\n return null;\n }),\n createBasicExtensions({ lineWrapping: false }),\n createThemeExtensions({\n themeMode,\n slots: {\n editor: {\n className: editorVariants[variant].editor,\n },\n content: {\n className: editorVariants[variant].content,\n },\n },\n }),\n ],\n };\n }, [extension, autoFocus, value, variant, onBlur]);\n\n return (\n <div\n ref={parentRef}\n className={editorVariants[variant].root}\n style={box}\n {...(gridId && { 'data-grid': gridId })}\n />\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { CellEditor, type CellEditorProps } from './CellEditor';\nimport { type GridScopedProps, useGridContext } from '../Grid';\n\nexport const GridCellEditor = ({\n extension,\n getCellContent,\n __gridScope,\n}: GridScopedProps<Pick<CellEditorProps, 'extension'> & { getCellContent: (index: string) => string | undefined }>) => {\n const { id, editing, setEditing, editBox } = useGridContext('GridSheetCellEditor', __gridScope);\n\n return editing ? (\n <CellEditor\n variant='grid'\n value={editing.initialContent ?? getCellContent(editing.index)}\n autoFocus\n box={editBox}\n onBlur={() => setEditing(null)}\n extension={extension}\n gridId={id}\n />\n ) : null;\n};\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;AAqHhC,SAASC,iBAAiBC,iBAAiBC,mBAAmB;AAjH9D,IAAMC,SAASC,gBAAgB;EAC7BC,SAAS;EACTC,cAAcC;EACdC,OAAOC;EACPC,QAAQ;IACNC,cAAc;IACdC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F,CAAA;;IAEJ;EACF,GAAG;IAACG;IAAWC;IAAWb;IAAOe;IAASD;GAAO;AAEjD,SACE,gBAAAwB,OAAA,cAACC,OAAAA;IACCC,KAAKpB;IACLiB,WAAW/B,eAAeS,OAAAA,EAASP;IACnCiC,OAAOzB;IACN,GAAIC,UAAU;MAAE,aAAaA;IAAO;;AAG3C;;;AChKA,OAAOyB,YAAW;AAKX,IAAMC,iBAAiB,CAAC,EAC7BC,WACAC,gBACAC,YAAW,MACqG;AAChH,QAAM,EAAEC,IAAIC,SAASC,YAAYC,QAAO,IAAKC,eAAe,uBAAuBL,WAAAA;AAEnF,SAAOE,UACL,gBAAAI,OAAA,cAACC,YAAAA;IACCC,SAAQ;IACRC,OAAOP,QAAQQ,kBAAkBX,eAAeG,QAAQS,KAAK;IAC7DC,WAAAA;IACAC,KAAKT;IACLU,QAAQ,MAAMX,WAAW,IAAA;IACzBL;IACAiB,QAAQd;OAER;AACN;",
|
|
6
|
+
"names": ["createComponent", "createContextScope", "useControllableState", "React", "forwardRef", "useCallback", "useLayoutEffect", "useState", "DxGrid", "NaturalDxGrid", "useForwardedRef", "colToA1Notation", "rowToA1Notation", "closestCell", "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", "EditorView", "keymap", "React", "useThemeContext", "createBasicExtensions", "createThemeExtensions", "preventNewline", "useTextEditor", "editorKeys", "onNav", "onClose", "keymap", "of", "key", "run", "editor", "value", "state", "doc", "toString", "shift", "undefined", "editorVariants", "legacy", "root", "content", "grid", "CellEditor", "extension", "autoFocus", "onBlur", "variant", "box", "gridId", "themeMode", "useThemeContext", "parentRef", "useTextEditor", "initialValue", "selection", "anchor", "length", "extensions", "preventNewline", "EditorView", "focusChangeEffect", "_", "focusing", "type", "createBasicExtensions", "lineWrapping", "createThemeExtensions", "slots", "className", "React", "div", "ref", "style", "React", "GridCellEditor", "extension", "getCellContent", "__gridScope", "id", "editing", "setEditing", "editBox", "useGridContext", "React", "CellEditor", "variant", "value", "initialContent", "index", "autoFocus", "box", "onBlur", "gridId"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/react-ui-grid/src/Grid.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-grid/src/Grid/Grid.tsx":{"bytes":12334,"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},{"path":"@dxos/lit-grid","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-grid/src/Grid/index.ts":{"bytes":494,"imports":[{"path":"packages/ui/react-ui-grid/src/Grid/Grid.tsx","kind":"import-statement","original":"./Grid"}],"format":"esm"},"packages/ui/react-ui-grid/src/CellEditor/CellEditor.tsx":{"bytes":14862,"imports":[{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-grid/src/CellEditor/GridCellEditor.tsx":{"bytes":2887,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"packages/ui/react-ui-grid/src/CellEditor/CellEditor.tsx","kind":"import-statement","original":"./CellEditor"},{"path":"packages/ui/react-ui-grid/src/Grid/index.ts","kind":"import-statement","original":"../Grid"}],"format":"esm"},"packages/ui/react-ui-grid/src/CellEditor/index.ts":{"bytes":620,"imports":[{"path":"packages/ui/react-ui-grid/src/CellEditor/CellEditor.tsx","kind":"import-statement","original":"./CellEditor"},{"path":"packages/ui/react-ui-grid/src/CellEditor/GridCellEditor.tsx","kind":"import-statement","original":"./GridCellEditor"}],"format":"esm"},"packages/ui/react-ui-grid/src/index.ts":{"bytes":583,"imports":[{"path":"packages/ui/react-ui-grid/src/Grid/index.ts","kind":"import-statement","original":"./Grid"},{"path":"packages/ui/react-ui-grid/src/CellEditor/index.ts","kind":"import-statement","original":"./CellEditor"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-grid/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15666},"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},{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["CellEditor","Grid","GridCellEditor","GridContent","GridRoot","closestCell","colToA1Notation","createGridScope","editorKeys","rowToA1Notation","useGridContext"],"entryPoint":"packages/ui/react-ui-grid/src/index.ts","inputs":{"packages/ui/react-ui-grid/src/Grid/Grid.tsx":{"bytesInOutput":2440},"packages/ui/react-ui-grid/src/Grid/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-grid/src/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-grid/src/CellEditor/CellEditor.tsx":{"bytesInOutput":3537},"packages/ui/react-ui-grid/src/CellEditor/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-grid/src/CellEditor/GridCellEditor.tsx":{"bytesInOutput":478}},"bytes":6843}}}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Extension } from '@codemirror/state';
|
|
2
|
+
import React, { type DOMAttributes, type KeyboardEvent } from 'react';
|
|
3
|
+
import { type UseTextEditorProps } from '@dxos/react-ui-editor';
|
|
4
|
+
import { type GridEditBox } from '../Grid';
|
|
5
|
+
type EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & {
|
|
6
|
+
shift?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type EditorKeysProps = {
|
|
9
|
+
onClose: (value: string | undefined, event: EditorKeyEvent) => void;
|
|
10
|
+
onNav?: (value: string | undefined, event: EditorKeyEvent) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const editorKeys: ({ onNav, onClose }: EditorKeysProps) => Extension;
|
|
13
|
+
export type CellEditorProps = {
|
|
14
|
+
value?: string;
|
|
15
|
+
extension?: Extension;
|
|
16
|
+
variant?: keyof typeof editorVariants;
|
|
17
|
+
box?: GridEditBox;
|
|
18
|
+
gridId?: string;
|
|
19
|
+
} & Pick<UseTextEditorProps, 'autoFocus'> & Pick<DOMAttributes<HTMLInputElement>, 'onBlur' | 'onKeyDown'>;
|
|
20
|
+
declare const editorVariants: {
|
|
21
|
+
legacy: {
|
|
22
|
+
root: string;
|
|
23
|
+
editor: string;
|
|
24
|
+
content: string;
|
|
25
|
+
};
|
|
26
|
+
grid: {
|
|
27
|
+
root: string;
|
|
28
|
+
editor: string;
|
|
29
|
+
content: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare const CellEditor: ({ value, extension, autoFocus, onBlur, variant, box, gridId, }: CellEditorProps) => React.JSX.Element;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=CellEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CellEditor.d.ts","sourceRoot":"","sources":["../../../../src/CellEditor/CellEditor.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtE,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACpE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CACpE,CAAC;AAGF,eAAO,MAAM,UAAU,uBAAwB,eAAe,KAAG,SAgEhE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,OAAO,cAAc,CAAC;IACtC,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,GACvC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC,CAAC;AAEhE,QAAA,MAAM,cAAc;;;;;;;;;;;CAYnB,CAAC;AAEF,eAAO,MAAM,UAAU,mEAQpB,eAAe,sBAwCjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type CellEditorProps } from './CellEditor';
|
|
3
|
+
import { type GridScopedProps } from '../Grid';
|
|
4
|
+
export declare const GridCellEditor: ({ extension, getCellContent, __gridScope, }: GridScopedProps<Pick<CellEditorProps, "extension"> & {
|
|
5
|
+
getCellContent: (index: string) => string | undefined;
|
|
6
|
+
}>) => React.JSX.Element | null;
|
|
7
|
+
//# sourceMappingURL=GridCellEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GridCellEditor.d.ts","sourceRoot":"","sources":["../../../../src/CellEditor/GridCellEditor.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,cAAc,gDAIxB,eAAe,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG;IAAE,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,6BAcjH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/CellEditor/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import '@dxos/lit-grid/dx-grid.pcss';
|
|
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;
|
|
23
|
+
};
|
|
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 { colToA1Notation, rowToA1Notation, closestCell } from '@dxos/lit-grid';
|
|
54
|
+
export type { DxGridRange, DxGridAxisMeta, DxAxisResize, DxGridCells, DxGridPlaneRange, DxGridPlaneCells, DxGridPlane, DxGridPosition, } from '@dxos/lit-grid';
|
|
55
|
+
//# sourceMappingURL=Grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../../../src/Grid/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,OA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,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,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE/E,YAAY,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import '@dxos-theme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { type GridContentProps, type GridRootProps } from './Grid';
|
|
4
|
+
type StoryGridProps = GridContentProps & Pick<GridRootProps, 'onEditingChange'>;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
title: string;
|
|
7
|
+
component: ({ onEditingChange, ...props }: StoryGridProps) => React.JSX.Element;
|
|
8
|
+
decorators: import("@storybook/react/*").Decorator[];
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
export declare const Basic: {
|
|
15
|
+
args: {
|
|
16
|
+
id: string;
|
|
17
|
+
initialCells: {
|
|
18
|
+
grid: {
|
|
19
|
+
'1,1': {
|
|
20
|
+
accessoryHtml: string;
|
|
21
|
+
value: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
columnDefault: {
|
|
26
|
+
grid: {
|
|
27
|
+
size: number;
|
|
28
|
+
resizeable: true;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
rowDefault: {
|
|
32
|
+
grid: {
|
|
33
|
+
size: number;
|
|
34
|
+
resizeable: true;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
columns: {
|
|
38
|
+
grid: {
|
|
39
|
+
0: {
|
|
40
|
+
size: number;
|
|
41
|
+
};
|
|
42
|
+
1: {
|
|
43
|
+
size: number;
|
|
44
|
+
};
|
|
45
|
+
2: {
|
|
46
|
+
size: number;
|
|
47
|
+
};
|
|
48
|
+
3: {
|
|
49
|
+
size: number;
|
|
50
|
+
};
|
|
51
|
+
4: {
|
|
52
|
+
size: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
onAxisResize: (event: import("packages/ui/lit-grid/dist/src/types").DxAxisResize) => void;
|
|
57
|
+
onEditingChange: (event: import("./Grid").GridEditing) => void;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=Grid.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Grid.stories.d.ts","sourceRoot":"","sources":["../../../../src/Grid/Grid.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAGrB,OAAO,KAAyD,MAAM,OAAO,CAAC;AAK9E,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;;;;;;AA+BhE,wBAKE;AAEF,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Grid/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,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.13-main.09887cd",
|
|
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",
|
|
@@ -21,23 +21,29 @@
|
|
|
21
21
|
"src"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@codemirror/state": "^6.4.1",
|
|
25
|
+
"@codemirror/view": "^6.34.1",
|
|
24
26
|
"@lit/react": "^1.0.5",
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@dxos/
|
|
27
|
+
"@radix-ui/react-context": "^1.0.0",
|
|
28
|
+
"@radix-ui/react-popper": "^1.1.2",
|
|
29
|
+
"@radix-ui/react-use-controllable-state": "^1.0.0",
|
|
30
|
+
"@dxos/react-ui-editor": "0.6.13-main.09887cd",
|
|
31
|
+
"@dxos/react-ui": "0.6.13-main.09887cd",
|
|
32
|
+
"@dxos/react-ui-theme": "0.6.13-main.09887cd",
|
|
33
|
+
"@dxos/util": "0.6.13-main.09887cd",
|
|
34
|
+
"@dxos/lit-grid": "0.6.13-main.09887cd"
|
|
29
35
|
},
|
|
30
36
|
"devDependencies": {
|
|
31
37
|
"@types/react": "~18.2.0",
|
|
32
38
|
"@types/react-dom": "~18.2.0",
|
|
33
39
|
"react": "~18.2.0",
|
|
34
40
|
"react-dom": "~18.2.0",
|
|
35
|
-
"vite": "
|
|
36
|
-
"@dxos/storybook-utils": "0.6.
|
|
41
|
+
"vite": "5.4.7",
|
|
42
|
+
"@dxos/storybook-utils": "0.6.13-main.09887cd"
|
|
37
43
|
},
|
|
38
44
|
"peerDependencies": {
|
|
39
|
-
"react": "
|
|
40
|
-
"react-dom": "
|
|
45
|
+
"react": "~18.2.0",
|
|
46
|
+
"react-dom": "~18.2.0"
|
|
41
47
|
},
|
|
42
48
|
"publishConfig": {
|
|
43
49
|
"access": "public"
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Extension } from '@codemirror/state';
|
|
6
|
+
import { EditorView, keymap } from '@codemirror/view';
|
|
7
|
+
import React, { type DOMAttributes, type KeyboardEvent } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useThemeContext } from '@dxos/react-ui';
|
|
10
|
+
import {
|
|
11
|
+
type UseTextEditorProps,
|
|
12
|
+
createBasicExtensions,
|
|
13
|
+
createThemeExtensions,
|
|
14
|
+
preventNewline,
|
|
15
|
+
useTextEditor,
|
|
16
|
+
} from '@dxos/react-ui-editor';
|
|
17
|
+
|
|
18
|
+
import { type GridEditBox } from '../Grid';
|
|
19
|
+
|
|
20
|
+
type EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & { shift?: boolean };
|
|
21
|
+
|
|
22
|
+
export type EditorKeysProps = {
|
|
23
|
+
onClose: (value: string | undefined, event: EditorKeyEvent) => void;
|
|
24
|
+
onNav?: (value: string | undefined, event: EditorKeyEvent) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// TODO(Zan): Should each consumer be responsible for defining these?
|
|
28
|
+
export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
|
|
29
|
+
return keymap.of([
|
|
30
|
+
{
|
|
31
|
+
key: 'ArrowUp',
|
|
32
|
+
run: (editor) => {
|
|
33
|
+
const value = editor.state.doc.toString();
|
|
34
|
+
onNav?.(value, { key: 'ArrowUp' });
|
|
35
|
+
return !!onNav;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: 'ArrowDown',
|
|
40
|
+
run: (editor) => {
|
|
41
|
+
const value = editor.state.doc.toString();
|
|
42
|
+
onNav?.(value, { key: 'ArrowDown' });
|
|
43
|
+
return !!onNav;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: 'ArrowLeft',
|
|
48
|
+
run: (editor) => {
|
|
49
|
+
const value = editor.state.doc.toString();
|
|
50
|
+
onNav?.(value, { key: 'ArrowLeft' });
|
|
51
|
+
return !!onNav;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: 'ArrowRight',
|
|
56
|
+
run: (editor) => {
|
|
57
|
+
const value = editor.state.doc.toString();
|
|
58
|
+
onNav?.(value, { key: 'ArrowRight' });
|
|
59
|
+
return !!onNav;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: 'Enter',
|
|
64
|
+
run: (editor) => {
|
|
65
|
+
onClose(editor.state.doc.toString(), { key: 'Enter' });
|
|
66
|
+
return true;
|
|
67
|
+
},
|
|
68
|
+
shift: (editor) => {
|
|
69
|
+
onClose(editor.state.doc.toString(), { key: 'Enter', shift: true });
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: 'Tab',
|
|
75
|
+
run: (editor) => {
|
|
76
|
+
onClose(editor.state.doc.toString(), { key: 'Tab' });
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
shift: (editor) => {
|
|
80
|
+
onClose(editor.state.doc.toString(), { key: 'Tab', shift: true });
|
|
81
|
+
return true;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: 'Escape',
|
|
86
|
+
run: () => {
|
|
87
|
+
onClose(undefined, { key: 'Escape' });
|
|
88
|
+
return true;
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type CellEditorProps = {
|
|
95
|
+
value?: string;
|
|
96
|
+
extension?: Extension;
|
|
97
|
+
variant?: keyof typeof editorVariants;
|
|
98
|
+
box?: GridEditBox;
|
|
99
|
+
gridId?: string;
|
|
100
|
+
} & Pick<UseTextEditorProps, 'autoFocus'> &
|
|
101
|
+
Pick<DOMAttributes<HTMLInputElement>, 'onBlur' | 'onKeyDown'>;
|
|
102
|
+
|
|
103
|
+
const editorVariants = {
|
|
104
|
+
// TODO(thure): remove when legacy is no longer used.
|
|
105
|
+
legacy: {
|
|
106
|
+
root: 'flex w-full',
|
|
107
|
+
editor: 'flex w-full [&>.cm-scroller]:scrollbar-none',
|
|
108
|
+
content: '!px-2 !py-1',
|
|
109
|
+
},
|
|
110
|
+
grid: {
|
|
111
|
+
root: 'absolute z-[1]',
|
|
112
|
+
editor: '[&>.cm-scroller]:scrollbar-none tabular-nums',
|
|
113
|
+
content: '!border !border-transparent !p-0.5',
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const CellEditor = ({
|
|
118
|
+
value,
|
|
119
|
+
extension,
|
|
120
|
+
autoFocus,
|
|
121
|
+
onBlur,
|
|
122
|
+
variant = 'legacy',
|
|
123
|
+
box,
|
|
124
|
+
gridId,
|
|
125
|
+
}: CellEditorProps) => {
|
|
126
|
+
const { themeMode } = useThemeContext();
|
|
127
|
+
const { parentRef } = useTextEditor(() => {
|
|
128
|
+
return {
|
|
129
|
+
autoFocus,
|
|
130
|
+
initialValue: value,
|
|
131
|
+
selection: { anchor: value?.length ?? 0 },
|
|
132
|
+
extensions: [
|
|
133
|
+
extension ?? [],
|
|
134
|
+
preventNewline,
|
|
135
|
+
EditorView.focusChangeEffect.of((_, focusing) => {
|
|
136
|
+
if (!focusing) {
|
|
137
|
+
onBlur?.({ type: 'blur' } as any);
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}),
|
|
141
|
+
createBasicExtensions({ lineWrapping: false }),
|
|
142
|
+
createThemeExtensions({
|
|
143
|
+
themeMode,
|
|
144
|
+
slots: {
|
|
145
|
+
editor: {
|
|
146
|
+
className: editorVariants[variant].editor,
|
|
147
|
+
},
|
|
148
|
+
content: {
|
|
149
|
+
className: editorVariants[variant].content,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
}, [extension, autoFocus, value, variant, onBlur]);
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div
|
|
159
|
+
ref={parentRef}
|
|
160
|
+
className={editorVariants[variant].root}
|
|
161
|
+
style={box}
|
|
162
|
+
{...(gridId && { 'data-grid': gridId })}
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { CellEditor, type CellEditorProps } from './CellEditor';
|
|
8
|
+
import { type GridScopedProps, useGridContext } from '../Grid';
|
|
9
|
+
|
|
10
|
+
export const GridCellEditor = ({
|
|
11
|
+
extension,
|
|
12
|
+
getCellContent,
|
|
13
|
+
__gridScope,
|
|
14
|
+
}: GridScopedProps<Pick<CellEditorProps, 'extension'> & { getCellContent: (index: string) => string | undefined }>) => {
|
|
15
|
+
const { id, editing, setEditing, editBox } = useGridContext('GridSheetCellEditor', __gridScope);
|
|
16
|
+
|
|
17
|
+
return editing ? (
|
|
18
|
+
<CellEditor
|
|
19
|
+
variant='grid'
|
|
20
|
+
value={editing.initialContent ?? getCellContent(editing.index)}
|
|
21
|
+
autoFocus
|
|
22
|
+
box={editBox}
|
|
23
|
+
onBlur={() => setEditing(null)}
|
|
24
|
+
extension={extension}
|
|
25
|
+
gridId={id}
|
|
26
|
+
/>
|
|
27
|
+
) : null;
|
|
28
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import * as ModalPrimitive from '@radix-ui/react-popper';
|
|
8
|
+
import React, { type MouseEvent, useCallback, useRef, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { DropdownMenu, useThemeContext } from '@dxos/react-ui';
|
|
11
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
12
|
+
|
|
13
|
+
import { Grid, type GridContentProps, type GridRootProps } from './Grid';
|
|
14
|
+
|
|
15
|
+
type StoryGridProps = GridContentProps & Pick<GridRootProps, 'onEditingChange'>;
|
|
16
|
+
|
|
17
|
+
const StoryGrid = ({ onEditingChange, ...props }: StoryGridProps) => {
|
|
18
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
19
|
+
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
20
|
+
const { tx } = useThemeContext();
|
|
21
|
+
|
|
22
|
+
const handleClick = useCallback((event: MouseEvent) => {
|
|
23
|
+
const closestAction = (event.target as HTMLElement).closest('button[data-story-action]');
|
|
24
|
+
if (closestAction) {
|
|
25
|
+
triggerRef.current = closestAction as HTMLDivElement;
|
|
26
|
+
setMenuOpen(true);
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ModalPrimitive.Root>
|
|
32
|
+
<Grid.Root id='story' onEditingChange={onEditingChange}>
|
|
33
|
+
<Grid.Content {...props} onClick={handleClick} />
|
|
34
|
+
</Grid.Root>
|
|
35
|
+
<ModalPrimitive.Anchor virtualRef={triggerRef} />
|
|
36
|
+
<DropdownMenu.Root open={menuOpen} onOpenChange={setMenuOpen}>
|
|
37
|
+
<DropdownMenu.Content classNames='contents'>
|
|
38
|
+
<ModalPrimitive.Content className={tx('menu.content', 'menu__content', {})}>
|
|
39
|
+
<DropdownMenu.Item onClick={() => console.log('[Click on dropdown menu item]')}>Hello</DropdownMenu.Item>
|
|
40
|
+
<ModalPrimitive.Arrow className={tx('menu.arrow', 'menu__arrow', {})} />
|
|
41
|
+
</ModalPrimitive.Content>
|
|
42
|
+
</DropdownMenu.Content>
|
|
43
|
+
</DropdownMenu.Root>
|
|
44
|
+
</ModalPrimitive.Root>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
title: 'react-ui-grid/Grid',
|
|
50
|
+
component: StoryGrid,
|
|
51
|
+
decorators: [withTheme],
|
|
52
|
+
parameters: { layout: 'fullscreen' },
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const Basic = {
|
|
56
|
+
args: {
|
|
57
|
+
id: 'story',
|
|
58
|
+
initialCells: {
|
|
59
|
+
grid: {
|
|
60
|
+
'1,1': {
|
|
61
|
+
accessoryHtml:
|
|
62
|
+
'<button class="ch-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 inline-end-1" data-story-action="menu"><svg><use href="/icons.svg#ph--arrow-right--regular"/></svg></button>',
|
|
63
|
+
value: 'Weekly sales report',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
columnDefault: {
|
|
68
|
+
grid: {
|
|
69
|
+
size: 180,
|
|
70
|
+
resizeable: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
rowDefault: {
|
|
74
|
+
grid: {
|
|
75
|
+
size: 32,
|
|
76
|
+
resizeable: true,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
columns: {
|
|
80
|
+
grid: {
|
|
81
|
+
0: { size: 200 },
|
|
82
|
+
1: { size: 210 },
|
|
83
|
+
2: { size: 230 },
|
|
84
|
+
3: { size: 250 },
|
|
85
|
+
4: { size: 270 },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
onAxisResize: (event) => {
|
|
89
|
+
console.log('[axis resize]', event);
|
|
90
|
+
},
|
|
91
|
+
onEditingChange: (event) => {
|
|
92
|
+
console.log('[edit]', event);
|
|
93
|
+
},
|
|
94
|
+
} satisfies StoryGridProps,
|
|
95
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos/lit-grid/dx-grid.pcss';
|
|
6
|
+
|
|
7
|
+
import { createComponent, type EventName } from '@lit/react';
|
|
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';
|
|
21
|
+
|
|
22
|
+
type DxGridElement = NaturalDxGrid;
|
|
23
|
+
|
|
24
|
+
const DxGrid = createComponent({
|
|
25
|
+
tagName: 'dx-grid',
|
|
26
|
+
elementClass: NaturalDxGrid,
|
|
27
|
+
react: React,
|
|
28
|
+
events: {
|
|
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>,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
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;
|
|
52
|
+
};
|
|
53
|
+
|
|
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']>;
|
|
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 { colToA1Notation, rowToA1Notation, closestCell } from '@dxos/lit-grid';
|
|
138
|
+
|
|
139
|
+
export type {
|
|
140
|
+
DxGridRange,
|
|
141
|
+
DxGridAxisMeta,
|
|
142
|
+
DxAxisResize,
|
|
143
|
+
DxGridCells,
|
|
144
|
+
DxGridPlaneRange,
|
|
145
|
+
DxGridPlaneCells,
|
|
146
|
+
DxGridPlane,
|
|
147
|
+
DxGridPosition,
|
|
148
|
+
} from '@dxos/lit-grid';
|
package/src/index.ts
CHANGED
package/dist/types/src/Grid.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import '@dxos/lit-grid/dx-grid.pcss';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { type DxAxisResize, type DxGridProps } from '@dxos/lit-grid';
|
|
4
|
-
export type GridProps = DxGridProps & {
|
|
5
|
-
onAxisResize: (event: DxAxisResize) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare const Grid: (props: GridProps) => React.JSX.Element;
|
|
8
|
-
//# sourceMappingURL=Grid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.d.ts","sourceRoot":"","sources":["../../../src/Grid.tsx"],"names":[],"mappings":"AAGA,OAAO,6BAA6B,CAAC;AAGrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,KAAK,YAAY,EAA2B,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAW9F,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IACpC,YAAY,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,IAAI,UAAW,SAAS,sBAEpC,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { type GridProps } from './Grid';
|
|
2
|
-
declare const _default: {
|
|
3
|
-
title: string;
|
|
4
|
-
component: (props: GridProps) => import("react").JSX.Element;
|
|
5
|
-
decorators: import("@storybook/react/*").Decorator[];
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|
|
8
|
-
export declare const Basic: {
|
|
9
|
-
args: {
|
|
10
|
-
cells: {
|
|
11
|
-
'1,1': {
|
|
12
|
-
value: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
columnDefault: {
|
|
16
|
-
size: number;
|
|
17
|
-
resizeable: true;
|
|
18
|
-
};
|
|
19
|
-
rowDefault: {
|
|
20
|
-
size: number;
|
|
21
|
-
resizeable: true;
|
|
22
|
-
};
|
|
23
|
-
columns: {
|
|
24
|
-
0: {
|
|
25
|
-
size: number;
|
|
26
|
-
};
|
|
27
|
-
1: {
|
|
28
|
-
size: number;
|
|
29
|
-
};
|
|
30
|
-
2: {
|
|
31
|
-
size: number;
|
|
32
|
-
};
|
|
33
|
-
3: {
|
|
34
|
-
size: number;
|
|
35
|
-
};
|
|
36
|
-
4: {
|
|
37
|
-
size: number;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
onAxisResize: (event: import("packages/ui/lit-grid/dist/types/src").DxAxisResize) => void;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=Grid.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.stories.d.ts","sourceRoot":"","sources":["../../../src/Grid.stories.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;;;;;;AAE9C,wBAIE;AAEF,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BjB,CAAC"}
|
package/src/Grid.stories.tsx
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
6
|
-
|
|
7
|
-
import { Grid, type GridProps } from './Grid';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
title: 'react-ui-grid/Grid',
|
|
11
|
-
component: Grid,
|
|
12
|
-
decorators: [withTheme],
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const Basic = {
|
|
16
|
-
args: {
|
|
17
|
-
cells: {
|
|
18
|
-
'1,1': {
|
|
19
|
-
// end: '8,1',
|
|
20
|
-
value: 'Weekly sales report',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
columnDefault: {
|
|
24
|
-
size: 180,
|
|
25
|
-
resizeable: true,
|
|
26
|
-
},
|
|
27
|
-
rowDefault: {
|
|
28
|
-
size: 32,
|
|
29
|
-
resizeable: true,
|
|
30
|
-
},
|
|
31
|
-
columns: {
|
|
32
|
-
0: { size: 200 },
|
|
33
|
-
1: { size: 210 },
|
|
34
|
-
2: { size: 230 },
|
|
35
|
-
3: { size: 250 },
|
|
36
|
-
4: { size: 270 },
|
|
37
|
-
},
|
|
38
|
-
onAxisResize: (event) => {
|
|
39
|
-
console.log('[axis resize]', event);
|
|
40
|
-
},
|
|
41
|
-
} satisfies GridProps,
|
|
42
|
-
};
|
package/src/Grid.tsx
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
import '@dxos/lit-grid/dx-grid.pcss';
|
|
5
|
-
|
|
6
|
-
import { createComponent, type EventName } from '@lit/react';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
|
|
9
|
-
import { type DxAxisResize, DxGrid as NaturalDxGrid, type DxGridProps } from '@dxos/lit-grid';
|
|
10
|
-
|
|
11
|
-
const DxGrid = createComponent({
|
|
12
|
-
tagName: 'dx-grid',
|
|
13
|
-
elementClass: NaturalDxGrid,
|
|
14
|
-
react: React,
|
|
15
|
-
events: {
|
|
16
|
-
onAxisResize: 'dx-axis-resize' as EventName<DxAxisResize>,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export type GridProps = DxGridProps & {
|
|
21
|
-
onAxisResize: (event: DxAxisResize) => void;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const Grid = (props: GridProps) => {
|
|
25
|
-
return <DxGrid {...props} />;
|
|
26
|
-
};
|