@dxos/react-ui-grid 0.6.13-main.ed424a1 → 0.6.13
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 +6 -248
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/Grid.d.ts +8 -0
- package/dist/types/src/Grid.d.ts.map +1 -0
- package/dist/types/src/Grid.stories.d.ts +43 -0
- package/dist/types/src/Grid.stories.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +9 -15
- package/src/Grid.stories.tsx +42 -0
- package/src/Grid.tsx +26 -0
- package/src/index.ts +0 -1
- package/dist/types/src/CellEditor/CellEditor.d.ts +0 -34
- package/dist/types/src/CellEditor/CellEditor.d.ts.map +0 -1
- package/dist/types/src/CellEditor/GridCellEditor.d.ts +0 -7
- package/dist/types/src/CellEditor/GridCellEditor.d.ts.map +0 -1
- package/dist/types/src/CellEditor/index.d.ts +0 -3
- package/dist/types/src/CellEditor/index.d.ts.map +0 -1
- package/dist/types/src/Grid/Grid.d.ts +0 -55
- package/dist/types/src/Grid/Grid.d.ts.map +0 -1
- package/dist/types/src/Grid/Grid.stories.d.ts +0 -60
- package/dist/types/src/Grid/Grid.stories.d.ts.map +0 -1
- package/dist/types/src/Grid/index.d.ts +0 -2
- package/dist/types/src/Grid/index.d.ts.map +0 -1
- package/src/CellEditor/CellEditor.tsx +0 -165
- package/src/CellEditor/GridCellEditor.tsx +0 -28
- package/src/CellEditor/index.ts +0 -6
- package/src/Grid/Grid.stories.tsx +0 -95
- package/src/Grid/Grid.tsx +0 -150
- package/src/Grid/index.ts +0 -5
|
@@ -1,262 +1,20 @@
|
|
|
1
|
-
// packages/ui/react-ui-grid/src/Grid
|
|
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
|
|
5
|
-
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
6
|
-
import React, { forwardRef, useCallback, useLayoutEffect, useState } from "react";
|
|
4
|
+
import React from "react";
|
|
7
5
|
import { DxGrid as NaturalDxGrid } from "@dxos/lit-grid";
|
|
8
|
-
import { useForwardedRef } from "@dxos/react-ui";
|
|
9
|
-
import { colToA1Notation, rowToA1Notation, closestCell } from "@dxos/lit-grid";
|
|
10
6
|
var DxGrid = createComponent({
|
|
11
7
|
tagName: "dx-grid",
|
|
12
8
|
elementClass: NaturalDxGrid,
|
|
13
9
|
react: React,
|
|
14
10
|
events: {
|
|
15
|
-
onAxisResize: "dx-axis-resize"
|
|
16
|
-
onEdit: "dx-edit-request",
|
|
17
|
-
onSelect: "dx-grid-cells-select"
|
|
11
|
+
onAxisResize: "dx-axis-resize"
|
|
18
12
|
}
|
|
19
13
|
});
|
|
20
|
-
var
|
|
21
|
-
|
|
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;
|
|
14
|
+
var Grid = (props) => {
|
|
15
|
+
return /* @__PURE__ */ React.createElement(DxGrid, props);
|
|
248
16
|
};
|
|
249
17
|
export {
|
|
250
|
-
|
|
251
|
-
Grid,
|
|
252
|
-
GridCellEditor,
|
|
253
|
-
GridContent,
|
|
254
|
-
GridRoot,
|
|
255
|
-
closestCell,
|
|
256
|
-
colToA1Notation,
|
|
257
|
-
createGridScope,
|
|
258
|
-
editorKeys,
|
|
259
|
-
rowToA1Notation,
|
|
260
|
-
useGridContext
|
|
18
|
+
Grid
|
|
261
19
|
};
|
|
262
20
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Grid
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["createComponent", "
|
|
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, type DxGridProps } from '@dxos/lit-grid';\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 },\n});\n\nexport type GridProps = DxGridProps & {\n onAxisResize: (event: DxAxisResize) => void;\n};\n\nexport const Grid = (props: GridProps) => {\n return <DxGrid {...props} />;\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO;AAEP,SAASA,uBAAuC;AAChD,OAAOC,WAAW;AAElB,SAA4BC,UAAUC,qBAAuC;AAE7E,IAAMC,SAASC,gBAAgB;EAC7BC,SAAS;EACTC,cAAcC;EACdC,OAAOC;EACPC,QAAQ;IACNC,cAAc;EAChB;AACF,CAAA;AAMO,IAAMC,OAAO,CAACC,UAAAA;AACnB,SAAO,sBAAA,cAACV,QAAWU,KAAAA;AACrB;",
|
|
6
|
+
"names": ["createComponent", "React", "DxGrid", "NaturalDxGrid", "DxGrid", "createComponent", "tagName", "elementClass", "NaturalDxGrid", "react", "React", "events", "onAxisResize", "Grid", "props"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/react-ui-grid/src/Grid
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-grid/src/Grid.tsx":{"bytes":2180,"imports":[{"path":"@dxos/lit-grid/dx-grid.pcss","kind":"import-statement","external":true},{"path":"@lit/react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","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":1186},"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":"react","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true}],"exports":["Grid"],"entryPoint":"packages/ui/react-ui-grid/src/index.ts","inputs":{"packages/ui/react-ui-grid/src/Grid.tsx":{"bytesInOutput":412},"packages/ui/react-ui-grid/src/index.ts":{"bytesInOutput":0}},"bytes":508}}}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-grid",
|
|
3
|
-
"version": "0.6.13
|
|
3
|
+
"version": "0.6.13",
|
|
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,29 +21,23 @@
|
|
|
21
21
|
"src"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@codemirror/state": "^6.4.1",
|
|
25
|
-
"@codemirror/view": "^6.34.1",
|
|
26
24
|
"@lit/react": "^1.0.5",
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/react-ui": "0.6.13-main.ed424a1",
|
|
32
|
-
"@dxos/react-ui-editor": "0.6.13-main.ed424a1",
|
|
33
|
-
"@dxos/util": "0.6.13-main.ed424a1",
|
|
34
|
-
"@dxos/react-ui-theme": "0.6.13-main.ed424a1"
|
|
25
|
+
"@dxos/lit-grid": "0.6.13",
|
|
26
|
+
"@dxos/react-ui": "0.6.13",
|
|
27
|
+
"@dxos/util": "0.6.13",
|
|
28
|
+
"@dxos/react-ui-theme": "0.6.13"
|
|
35
29
|
},
|
|
36
30
|
"devDependencies": {
|
|
37
31
|
"@types/react": "~18.2.0",
|
|
38
32
|
"@types/react-dom": "~18.2.0",
|
|
39
33
|
"react": "~18.2.0",
|
|
40
34
|
"react-dom": "~18.2.0",
|
|
41
|
-
"vite": "5.4
|
|
42
|
-
"@dxos/storybook-utils": "0.6.13
|
|
35
|
+
"vite": "^5.3.4",
|
|
36
|
+
"@dxos/storybook-utils": "0.6.13"
|
|
43
37
|
},
|
|
44
38
|
"peerDependencies": {
|
|
45
|
-
"react": "
|
|
46
|
-
"react-dom": "
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"react-dom": "^18.0.0"
|
|
47
41
|
},
|
|
48
42
|
"publishConfig": {
|
|
49
43
|
"access": "public"
|
|
@@ -0,0 +1,42 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/CellEditor/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
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, DxGridCellIndex, DxGridCellValue, DxGridPlane, DxGridPosition, } from '@dxos/lit-grid';
|
|
55
|
-
//# sourceMappingURL=Grid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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,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,eAAe,EACf,eAAe,EACf,WAAW,EACX,cAAc,GACf,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Grid/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC"}
|
|
@@ -1,165 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
};
|
package/src/CellEditor/index.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
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
|
-
};
|
package/src/Grid/Grid.tsx
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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
|
-
DxGridCellIndex,
|
|
147
|
-
DxGridCellValue,
|
|
148
|
-
DxGridPlane,
|
|
149
|
-
DxGridPosition,
|
|
150
|
-
} from '@dxos/lit-grid';
|