@dxos/react-ui-grid 0.8.4-main.e8ec1fe → 0.8.4-main.effb148878
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +149 -160
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/CellEditor/CellEditor.d.ts +3 -2
- package/dist/types/src/CellEditor/CellEditor.d.ts.map +1 -1
- package/dist/types/src/CellEditor/CellEditor.stories.d.ts +1 -1
- package/dist/types/src/CellEditor/CellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/CellEditor/GridCellEditor.d.ts.map +1 -1
- package/dist/types/src/Grid/Grid.d.ts +8 -8
- package/dist/types/src/Grid/Grid.d.ts.map +1 -1
- package/dist/types/src/Grid/Grid.stories.d.ts +4 -0
- package/dist/types/src/Grid/Grid.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -28
- package/src/CellEditor/CellEditor.stories.tsx +2 -2
- package/src/CellEditor/CellEditor.tsx +26 -16
- package/src/CellEditor/GridCellEditor.tsx +0 -1
- package/src/Grid/Grid.stories.tsx +53 -19
- package/src/Grid/Grid.tsx +10 -8
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
import { defaultColSize, defaultRowSize } from "@dxos/lit-grid";
|
|
3
3
|
|
|
4
4
|
// src/Grid/Grid.tsx
|
|
5
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
6
|
-
import "@dxos/lit-grid/dx-grid.pcss";
|
|
7
5
|
import { createComponent } from "@lit/react";
|
|
8
6
|
import { createContextScope } from "@radix-ui/react-context";
|
|
9
7
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
10
8
|
import React, { forwardRef, useCallback, useEffect, useState } from "react";
|
|
9
|
+
import "@dxos/lit-grid/dx-grid.pcss";
|
|
11
10
|
import { DxGrid as NaturalDxGrid } from "@dxos/lit-grid";
|
|
12
11
|
import { colToA1Notation, rowToA1Notation, closestCell, commentedClassName, toPlaneCellIndex, parseCellIndex, cellQuery, DxEditRequest } from "@dxos/lit-grid";
|
|
13
12
|
var DxGrid = createComponent({
|
|
@@ -29,96 +28,86 @@ var initialBox = {
|
|
|
29
28
|
var GRID_NAME = "Grid";
|
|
30
29
|
var [createGridContext, createGridScope] = createContextScope(GRID_NAME, []);
|
|
31
30
|
var [GridProvider, useGridContext] = createGridContext(GRID_NAME);
|
|
32
|
-
var GridRoot = ({ id, editing: propsEditing, defaultEditing, onEditingChange
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}, children));
|
|
54
|
-
} finally {
|
|
55
|
-
_effect.f();
|
|
56
|
-
}
|
|
31
|
+
var GridRoot = ({ __gridScope, children, id, editing: propsEditing, defaultEditing, onEditingChange }) => {
|
|
32
|
+
const [editing = null, setEditing] = useControllableState({
|
|
33
|
+
prop: propsEditing,
|
|
34
|
+
defaultProp: defaultEditing,
|
|
35
|
+
onChange: onEditingChange
|
|
36
|
+
});
|
|
37
|
+
const [editBox, setEditBox] = useState(initialBox);
|
|
38
|
+
return /* @__PURE__ */ React.createElement(GridProvider, {
|
|
39
|
+
id,
|
|
40
|
+
editing,
|
|
41
|
+
setEditing,
|
|
42
|
+
editBox,
|
|
43
|
+
setEditBox,
|
|
44
|
+
scope: __gridScope
|
|
45
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
46
|
+
className: "dx-grid-host",
|
|
47
|
+
style: {
|
|
48
|
+
display: "contents"
|
|
49
|
+
}
|
|
50
|
+
}, children));
|
|
57
51
|
};
|
|
58
52
|
GridRoot.displayName = GRID_NAME;
|
|
59
53
|
var GRID_CONTENT_NAME = "GridContent";
|
|
60
54
|
var GridContent = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} else {
|
|
71
|
-
forwardedRef.current = nextDxGrid;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}, [
|
|
75
|
-
forwardedRef,
|
|
76
|
-
dxGrid
|
|
77
|
-
]);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (dxGrid && props.getCells) {
|
|
80
|
-
dxGrid.getCells = props.getCells;
|
|
81
|
-
dxGrid.requestUpdate("initialCells");
|
|
55
|
+
const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);
|
|
56
|
+
const [dxGrid, setDxGridInternal] = useState(null);
|
|
57
|
+
const setDxGrid = useCallback((nextDxGrid) => {
|
|
58
|
+
setDxGridInternal(nextDxGrid);
|
|
59
|
+
if (forwardedRef) {
|
|
60
|
+
if (typeof forwardedRef === "function") {
|
|
61
|
+
forwardedRef?.(nextDxGrid);
|
|
62
|
+
} else {
|
|
63
|
+
forwardedRef.current = nextDxGrid;
|
|
82
64
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
65
|
+
}
|
|
66
|
+
}, [
|
|
67
|
+
forwardedRef,
|
|
68
|
+
dxGrid
|
|
69
|
+
]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (dxGrid && props.getCells) {
|
|
72
|
+
dxGrid.getCells = props.getCells;
|
|
73
|
+
dxGrid.requestUpdate("initialCells");
|
|
74
|
+
}
|
|
75
|
+
}, [
|
|
76
|
+
props.getCells,
|
|
77
|
+
dxGrid
|
|
78
|
+
]);
|
|
79
|
+
const handleEdit = useCallback((event) => {
|
|
80
|
+
setEditBox(event.cellBox);
|
|
81
|
+
setEditing({
|
|
82
|
+
index: event.cellIndex,
|
|
83
|
+
cellElement: event.cellElement,
|
|
84
|
+
initialContent: event.initialContent
|
|
101
85
|
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
}, []);
|
|
87
|
+
return /* @__PURE__ */ React.createElement(DxGrid, {
|
|
88
|
+
...props,
|
|
89
|
+
gridId: id,
|
|
90
|
+
mode: editing ? "edit" : "browse",
|
|
91
|
+
onEdit: handleEdit,
|
|
92
|
+
ref: setDxGrid
|
|
93
|
+
});
|
|
105
94
|
});
|
|
106
95
|
GridContent.displayName = GRID_CONTENT_NAME;
|
|
107
|
-
var gridSeparatorInlineEnd = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-
|
|
108
|
-
var gridSeparatorBlockEnd = "[&>.dx-grid]:relative [&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-
|
|
96
|
+
var gridSeparatorInlineEnd = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-y-0 [&>.dx-grid]:after:-right-px [&>.dx-grid]:after:w-px [&>.dx-grid]:after:bg-subdued-separator";
|
|
97
|
+
var gridSeparatorBlockEnd = "[&>.dx-grid]:relative [&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-x-0 [&>.dx-grid]:before:-bottom-px [&>.dx-grid]:before:h-px [&>.dx-grid]:before:bg-subdued-separator";
|
|
109
98
|
var Grid = {
|
|
110
99
|
Root: GridRoot,
|
|
111
100
|
Content: GridContent
|
|
112
101
|
};
|
|
113
102
|
|
|
114
103
|
// src/CellEditor/CellEditor.tsx
|
|
115
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
116
104
|
import { completionStatus } from "@codemirror/autocomplete";
|
|
117
105
|
import { EditorView, keymap } from "@codemirror/view";
|
|
118
106
|
import React2 from "react";
|
|
119
107
|
import { useThemeContext } from "@dxos/react-ui";
|
|
120
|
-
import {
|
|
121
|
-
import {
|
|
108
|
+
import { useTextEditor } from "@dxos/react-ui-editor";
|
|
109
|
+
import { createBasicExtensions, createThemeExtensions, filterChars } from "@dxos/ui-editor";
|
|
110
|
+
import { mx } from "@dxos/ui-theme";
|
|
122
111
|
var editorKeys = ({ onNav, onClose }) => {
|
|
123
112
|
return keymap.of([
|
|
124
113
|
{
|
|
@@ -220,100 +209,100 @@ var editorKeys = ({ onNav, onClose }) => {
|
|
|
220
209
|
}
|
|
221
210
|
]);
|
|
222
211
|
};
|
|
223
|
-
var CellEditor = ({ value, extensions, box, gridId,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const { parentRef } = useTextEditor(() => {
|
|
228
|
-
return {
|
|
229
|
-
autoFocus,
|
|
230
|
-
initialValue: value,
|
|
231
|
-
selection: {
|
|
232
|
-
anchor: value?.length ?? 0
|
|
233
|
-
},
|
|
234
|
-
extensions: [
|
|
235
|
-
extensions ?? [],
|
|
236
|
-
filterChars(/[\n\r]+/),
|
|
237
|
-
EditorView.focusChangeEffect.of((state, focusing) => {
|
|
238
|
-
if (!focusing) {
|
|
239
|
-
onBlur?.(state.doc.toString());
|
|
240
|
-
}
|
|
241
|
-
return null;
|
|
242
|
-
}),
|
|
243
|
-
createBasicExtensions({
|
|
244
|
-
lineWrapping: true
|
|
245
|
-
}),
|
|
246
|
-
createThemeExtensions({
|
|
247
|
-
themeMode,
|
|
248
|
-
slots: {
|
|
249
|
-
editor: {
|
|
250
|
-
className: mx("!min-is-full !is-min !max-is-[--dx-grid-cell-editor-max-inline-size] !min-bs-full !max-bs-[--dx-grid-cell-editor-max-block-size]", slots?.editor?.className)
|
|
251
|
-
},
|
|
252
|
-
scroll: {
|
|
253
|
-
className: mx("!overflow-x-hidden !plb-[max(0,calc(var(--dx-grid-cell-editor-padding-block)-1px))] !pie-0 !pis-[--dx-grid-cell-editor-padding-inline]", slots?.scroll?.className)
|
|
254
|
-
},
|
|
255
|
-
content: {
|
|
256
|
-
className: mx("!break-normal", slots?.content?.className)
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
]
|
|
261
|
-
};
|
|
262
|
-
}, [
|
|
263
|
-
extensions,
|
|
212
|
+
var CellEditor = ({ value, extensions, box, gridId, autoFocus, slots, onBlur }) => {
|
|
213
|
+
const { themeMode } = useThemeContext();
|
|
214
|
+
const { parentRef } = useTextEditor(() => {
|
|
215
|
+
return {
|
|
264
216
|
autoFocus,
|
|
265
|
-
value,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
slots
|
|
269
|
-
]);
|
|
270
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
271
|
-
"data-testid": "grid.cell-editor",
|
|
272
|
-
ref: parentRef,
|
|
273
|
-
className: "absolute z-[1] dx-grid__cell-editor",
|
|
274
|
-
style: {
|
|
275
|
-
insetInlineStart: box?.insetInlineStart ?? "0px",
|
|
276
|
-
insetBlockStart: box?.insetBlockStart ?? "0px",
|
|
277
|
-
minInlineSize: box?.inlineSize ?? "180px",
|
|
278
|
-
minBlockSize: box?.blockSize ?? "30px",
|
|
279
|
-
...{
|
|
280
|
-
"--dx-gridCellWidth": `${box?.inlineSize ?? 200}px`
|
|
281
|
-
}
|
|
217
|
+
initialValue: value,
|
|
218
|
+
selection: {
|
|
219
|
+
anchor: value?.length ?? 0
|
|
282
220
|
},
|
|
283
|
-
|
|
284
|
-
|
|
221
|
+
extensions: [
|
|
222
|
+
extensions ?? [],
|
|
223
|
+
filterChars(/[\n\r]+/),
|
|
224
|
+
// Observe the underlying blur DOM event rather than `EditorView.focusChangeEffect`. The
|
|
225
|
+
// focus-change facet fires asynchronously (CodeMirror schedules it on a 10ms setTimeout),
|
|
226
|
+
// which means in React strict mode the destroy → blur of the first EditorView runs the
|
|
227
|
+
// callback after the second view has mounted — committing stale data and closing the
|
|
228
|
+
// editor on the user's first keystroke. Deferring via `queueMicrotask` runs the check
|
|
229
|
+
// *after* `view.destroy()` finishes its synchronous body (which calls `dom.remove()`),
|
|
230
|
+
// so `view.dom.isConnected === false` reliably distinguishes a programmatic teardown
|
|
231
|
+
// from a real user blur. Pass `undefined` on teardown so downstream handlers can consume
|
|
232
|
+
// any pending suppress-next-blur flag without committing stale data.
|
|
233
|
+
EditorView.domEventObservers({
|
|
234
|
+
blur: (_event, view) => {
|
|
235
|
+
const doc = view.state.doc.toString();
|
|
236
|
+
queueMicrotask(() => {
|
|
237
|
+
onBlur?.(view.dom.isConnected ? doc : void 0);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}),
|
|
241
|
+
createBasicExtensions({
|
|
242
|
+
lineWrapping: true
|
|
243
|
+
}),
|
|
244
|
+
createThemeExtensions({
|
|
245
|
+
themeMode,
|
|
246
|
+
slots: {
|
|
247
|
+
editor: {
|
|
248
|
+
className: mx("min-w-full! w-min! !max-w-(--dx-grid-cell-editor-max-w-size) min-h-full! !max-h-(--dx-grid-cell-editor-max-h-size)", slots?.editor?.className)
|
|
249
|
+
},
|
|
250
|
+
scroller: {
|
|
251
|
+
className: mx("overflow-x-hidden! !py-[max(0,calc(var(--dx-grid-cell-editor-padding-block)-1px))] pe-0! !pl-(--dx-grid-cell-editor-padding-inline)", slots?.scroller?.className)
|
|
252
|
+
},
|
|
253
|
+
content: {
|
|
254
|
+
className: mx("break-normal!", slots?.content?.className)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
]
|
|
259
|
+
};
|
|
260
|
+
}, [
|
|
261
|
+
extensions,
|
|
262
|
+
autoFocus,
|
|
263
|
+
value,
|
|
264
|
+
onBlur,
|
|
265
|
+
themeMode,
|
|
266
|
+
slots
|
|
267
|
+
]);
|
|
268
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
269
|
+
"data-testid": "grid.cell-editor",
|
|
270
|
+
ref: parentRef,
|
|
271
|
+
className: "absolute z-[1] dx-grid__cell-editor",
|
|
272
|
+
style: {
|
|
273
|
+
insetInlineStart: box?.insetInlineStart ?? "0px",
|
|
274
|
+
insetBlockStart: box?.insetBlockStart ?? "0px",
|
|
275
|
+
minInlineSize: box?.inlineSize ?? "180px",
|
|
276
|
+
minBlockSize: box?.blockSize ?? "30px",
|
|
277
|
+
...{
|
|
278
|
+
"--dx-grid-cell-width": `${box?.inlineSize ?? 200}px`
|
|
285
279
|
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
280
|
+
},
|
|
281
|
+
...gridId && {
|
|
282
|
+
"data-grid": gridId
|
|
283
|
+
}
|
|
284
|
+
});
|
|
290
285
|
};
|
|
291
286
|
|
|
292
287
|
// src/CellEditor/GridCellEditor.tsx
|
|
293
|
-
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
294
288
|
import React3, { useCallback as useCallback2 } from "react";
|
|
295
289
|
var GridCellEditor = ({ extensions, getCellContent, onBlur, slots, __gridScope }) => {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
slots
|
|
313
|
-
}) : null;
|
|
314
|
-
} finally {
|
|
315
|
-
_effect.f();
|
|
316
|
-
}
|
|
290
|
+
const { id, editing, setEditing, editBox } = useGridContext("GridCellEditor", __gridScope);
|
|
291
|
+
const handleBlur = useCallback2((value) => {
|
|
292
|
+
setEditing(null);
|
|
293
|
+
onBlur?.(value);
|
|
294
|
+
}, [
|
|
295
|
+
onBlur
|
|
296
|
+
]);
|
|
297
|
+
return editing ? /* @__PURE__ */ React3.createElement(CellEditor, {
|
|
298
|
+
value: editing.initialContent ?? getCellContent(editing.index),
|
|
299
|
+
autoFocus: true,
|
|
300
|
+
box: editBox,
|
|
301
|
+
onBlur: handleBlur,
|
|
302
|
+
extensions,
|
|
303
|
+
gridId: id,
|
|
304
|
+
slots
|
|
305
|
+
}) : null;
|
|
317
306
|
};
|
|
318
307
|
export {
|
|
319
308
|
CellEditor,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/Grid/Grid.tsx", "../../../src/CellEditor/CellEditor.tsx", "../../../src/CellEditor/GridCellEditor.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport { defaultColSize, defaultRowSize } from '@dxos/lit-grid';\n\nexport * from './Grid';\nexport * from './CellEditor';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport '@dxos/lit-grid/dx-grid.pcss';\n\nimport { type EventName, createComponent } from '@lit/react';\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n type ComponentProps,\n type PropsWithChildren,\n forwardRef,\n useCallback,\n useEffect,\n useState,\n} from 'react';\n\nimport { type DxAxisResize, type DxEditRequest, type DxGridCellsSelect, DxGrid as NaturalDxGrid } from '@dxos/lit-grid';\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 = {\n index: DxEditRequest['cellIndex'];\n cellElement: DxEditRequest['cellElement'];\n initialContent: DxEditRequest['initialContent'];\n} | 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 <div className='dx-grid-host' style={{ display: 'contents' }}>\n {children}\n </div>\n </GridProvider>\n );\n};\n\nGridRoot.displayName = GRID_NAME;\n\nconst GRID_CONTENT_NAME = 'GridContent';\n\ntype GridContentProps = Omit<ComponentProps<typeof DxGrid>, 'onEdit'> & {\n getCells?: NaturalDxGrid['getCells'];\n activeRefs?: string;\n};\n\nconst GridContent = forwardRef<NaturalDxGrid, GridScopedProps<GridContentProps>>((props, forwardedRef) => {\n const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);\n const [dxGrid, setDxGridInternal] = useState<NaturalDxGrid | null>(null);\n\n // NOTE(thure): using `useState` instead of `useRef` works with refs provided by `@lit/react` and gives us\n // a reliable dependency for `useEffect` whereas `useLayoutEffect` does not guarantee the element will be defined.\n const setDxGrid = useCallback(\n (nextDxGrid: NaturalDxGrid | null) => {\n setDxGridInternal(nextDxGrid);\n if (forwardedRef) {\n if (typeof forwardedRef === 'function') {\n forwardedRef?.(nextDxGrid);\n } else {\n forwardedRef.current = nextDxGrid;\n }\n }\n },\n [forwardedRef, dxGrid],\n );\n\n useEffect(() => {\n if (dxGrid && props.getCells) {\n dxGrid.getCells = props.getCells;\n dxGrid.requestUpdate('initialCells');\n }\n }, [props.getCells, dxGrid]);\n\n const handleEdit = useCallback((event: DxEditRequest) => {\n setEditBox(event.cellBox);\n setEditing({ index: event.cellIndex, cellElement: event.cellElement, initialContent: event.initialContent });\n }, []);\n\n return <DxGrid {...props} gridId={id} mode={editing ? 'edit' : 'browse'} onEdit={handleEdit} ref={setDxGrid} />;\n});\n\nGridContent.displayName = GRID_CONTENT_NAME;\n\n//\n// Fragments\n//\n\n// NOTE(Zan): These fragments add border to inline-end and block-end of the grid using pseudo-elements.\n// These are offset by 1px to avoid double borders in planks.\nconst gridSeparatorInlineEnd =\n '[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-subduedSeparator';\nconst gridSeparatorBlockEnd =\n '[&>.dx-grid]:relative [&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-subduedSeparator';\n\n//\n// Exports\n//\n\nexport const Grid = {\n Root: GridRoot,\n Content: GridContent,\n};\n\nexport { GridRoot, GridContent, createGridScope, gridSeparatorInlineEnd, gridSeparatorBlockEnd, useGridContext };\n\nexport type { GridRootProps, GridContentProps, GridEditing, GridEditBox, GridScopedProps, DxGridElement };\n\nexport {\n colToA1Notation,\n rowToA1Notation,\n closestCell,\n commentedClassName,\n toPlaneCellIndex,\n parseCellIndex,\n cellQuery,\n DxEditRequest,\n} from '@dxos/lit-grid';\n\nexport type {\n DxGridRange,\n DxGridAxisMeta,\n DxAxisResize,\n DxGridCells,\n DxGridPlaneRange,\n DxGridPlaneCells,\n DxGridCellIndex,\n DxGridPlaneCellIndex,\n DxGridCellValue,\n DxGridPlane,\n DxGridPosition,\n DxGridPlanePosition,\n DxGridAxis,\n} from '@dxos/lit-grid';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { completionStatus } from '@codemirror/autocomplete';\nimport { type Extension } from '@codemirror/state';\nimport { EditorView, keymap } from '@codemirror/view';\nimport React, { type KeyboardEvent } from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport {\n type ThemeExtensionsOptions,\n type UseTextEditorProps,\n createBasicExtensions,\n createThemeExtensions,\n filterChars,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { type GridEditBox } from '../Grid';\n\nexport type EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & { shift?: boolean };\n\nexport type EditorKeyHandler = (value: string | undefined, event: EditorKeyEvent) => void;\nexport type EditorBlurHandler = (value: string | undefined) => void;\nexport type EditorKeyOrBlurHandler = (value: string | undefined, event?: EditorKeyEvent) => void;\n\nexport type EditorKeysProps = {\n onClose: EditorKeyHandler;\n onNav?: EditorKeyHandler;\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: 'Mod-ArrowLeft',\n run: (editor) => {\n const value = editor.state.doc.toString();\n onNav?.(value, { key: 'ArrowLeft' });\n return !!onNav;\n },\n },\n {\n key: 'Mod-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 if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Enter' });\n return true;\n }\n },\n shift: (editor) => {\n if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Enter', shift: true });\n return true;\n }\n },\n },\n {\n key: 'Tab',\n run: (editor) => {\n if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Tab' });\n return true;\n }\n },\n shift: (editor) => {\n if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Tab', shift: true });\n return true;\n }\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 extensions?: Extension;\n box?: GridEditBox;\n gridId?: string;\n onBlur?: EditorBlurHandler;\n} & Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<ThemeExtensionsOptions, 'slots'>;\n\nexport const CellEditor = ({ value, extensions, box, gridId, onBlur, autoFocus, slots }: 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 extensions ?? [],\n filterChars(/[\\n\\r]+/),\n EditorView.focusChangeEffect.of((state, focusing) => {\n if (!focusing) {\n onBlur?.(state.doc.toString());\n }\n return null;\n }),\n createBasicExtensions({ lineWrapping: true }),\n createThemeExtensions({\n themeMode,\n slots: {\n editor: {\n className: mx(\n '!min-is-full !is-min !max-is-[--dx-grid-cell-editor-max-inline-size] !min-bs-full !max-bs-[--dx-grid-cell-editor-max-block-size]',\n slots?.editor?.className,\n ),\n },\n scroll: {\n className: mx(\n '!overflow-x-hidden !plb-[max(0,calc(var(--dx-grid-cell-editor-padding-block)-1px))] !pie-0 !pis-[--dx-grid-cell-editor-padding-inline]',\n slots?.scroll?.className,\n ),\n },\n content: {\n className: mx('!break-normal', slots?.content?.className),\n },\n },\n }),\n ],\n };\n }, [extensions, autoFocus, value, onBlur, themeMode, slots]);\n\n return (\n <div\n data-testid='grid.cell-editor'\n ref={parentRef}\n className='absolute z-[1] dx-grid__cell-editor'\n style={{\n insetInlineStart: box?.insetInlineStart ?? '0px',\n insetBlockStart: box?.insetBlockStart ?? '0px',\n minInlineSize: box?.inlineSize ?? '180px',\n minBlockSize: box?.blockSize ?? '30px',\n ...{ '--dx-gridCellWidth': `${box?.inlineSize ?? 200}px` },\n }}\n {...(gridId && { 'data-grid': gridId })}\n />\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback } from 'react';\n\nimport { type DxGridCellIndex, type GridScopedProps, useGridContext } from '../Grid';\n\nimport { CellEditor, type CellEditorProps } from './CellEditor';\n\nexport type GridCellEditorProps = GridScopedProps<\n Pick<CellEditorProps, 'extensions' | 'onBlur' | 'slots'> & {\n getCellContent: (index: DxGridCellIndex) => string | undefined;\n }\n>;\n\nexport const GridCellEditor = ({ extensions, getCellContent, onBlur, slots, __gridScope }: GridCellEditorProps) => {\n const { id, editing, setEditing, editBox } = useGridContext('GridCellEditor', __gridScope);\n\n const handleBlur = useCallback(\n (value?: string) => {\n setEditing(null);\n onBlur?.(value);\n },\n [onBlur],\n );\n\n return editing ? (\n <CellEditor\n value={editing.initialContent ?? getCellContent(editing.index)}\n autoFocus\n box={editBox}\n onBlur={handleBlur}\n extensions={extensions}\n gridId={id}\n slots={slots}\n />\n ) : null;\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,gBAAgBC,sBAAsB
|
|
6
|
-
"names": ["defaultColSize", "defaultRowSize", "createComponent", "createContextScope", "useControllableState", "React", "forwardRef", "useCallback", "useEffect", "useState", "DxGrid", "NaturalDxGrid", "colToA1Notation", "rowToA1Notation", "closestCell", "commentedClassName", "toPlaneCellIndex", "parseCellIndex", "cellQuery", "DxEditRequest", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport { defaultColSize, defaultRowSize } from '@dxos/lit-grid';\n\nexport * from './Grid';\nexport * from './CellEditor';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type EventName, createComponent } from '@lit/react';\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n type ComponentProps,\n type PropsWithChildren,\n forwardRef,\n useCallback,\n useEffect,\n useState,\n} from 'react';\n\nimport '@dxos/lit-grid/dx-grid.pcss';\nimport { type DxAxisResize, type DxEditRequest, type DxGridCellsSelect, DxGrid as NaturalDxGrid } from '@dxos/lit-grid';\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 = {\n index: DxEditRequest['cellIndex'];\n cellElement: DxEditRequest['cellElement'];\n initialContent: DxEditRequest['initialContent'];\n} | 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 {\n id: string;\n } & Partial<{\n editing: GridEditing;\n defaultEditing: GridEditing;\n onEditingChange: (nextEditing: GridEditing) => void;\n }>\n>;\n\n// TODO(burdon): Make headless.\nconst GridRoot = ({\n __gridScope,\n children,\n id,\n editing: propsEditing,\n defaultEditing,\n onEditingChange,\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 <div className='dx-grid-host' style={{ display: 'contents' }}>\n {children}\n </div>\n </GridProvider>\n );\n};\n\nGridRoot.displayName = GRID_NAME;\n\nconst GRID_CONTENT_NAME = 'GridContent';\n\ntype GridContentProps = Omit<ComponentProps<typeof DxGrid>, 'onEdit'> & {\n getCells?: NaturalDxGrid['getCells'];\n activeRefs?: string;\n};\n\nconst GridContent = forwardRef<NaturalDxGrid, GridScopedProps<GridContentProps>>((props, forwardedRef) => {\n const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);\n const [dxGrid, setDxGridInternal] = useState<NaturalDxGrid | null>(null);\n\n // NOTE(thure): using `useState` instead of `useRef` works with refs provided by `@lit/react` and gives us\n // a reliable dependency for `useEffect` whereas `useLayoutEffect` does not guarantee the element will be defined.\n const setDxGrid = useCallback(\n (nextDxGrid: NaturalDxGrid | null) => {\n setDxGridInternal(nextDxGrid);\n if (forwardedRef) {\n if (typeof forwardedRef === 'function') {\n forwardedRef?.(nextDxGrid);\n } else {\n forwardedRef.current = nextDxGrid;\n }\n }\n },\n [forwardedRef, dxGrid],\n );\n\n useEffect(() => {\n if (dxGrid && props.getCells) {\n dxGrid.getCells = props.getCells;\n dxGrid.requestUpdate('initialCells');\n }\n }, [props.getCells, dxGrid]);\n\n const handleEdit = useCallback((event: DxEditRequest) => {\n setEditBox(event.cellBox);\n setEditing({ index: event.cellIndex, cellElement: event.cellElement, initialContent: event.initialContent });\n }, []);\n\n return <DxGrid {...props} gridId={id} mode={editing ? 'edit' : 'browse'} onEdit={handleEdit} ref={setDxGrid} />;\n});\n\nGridContent.displayName = GRID_CONTENT_NAME;\n\n//\n// Fragments\n//\n\n// NOTE(Zan): These fragments add border to w-end and h-end of the grid using pseudo-elements.\n// These are offset by 1px to avoid double borders in planks.\nconst gridSeparatorInlineEnd =\n '[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-y-0 [&>.dx-grid]:after:-right-px [&>.dx-grid]:after:w-px [&>.dx-grid]:after:bg-subdued-separator';\nconst gridSeparatorBlockEnd =\n '[&>.dx-grid]:relative [&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-x-0 [&>.dx-grid]:before:-bottom-px [&>.dx-grid]:before:h-px [&>.dx-grid]:before:bg-subdued-separator';\n\n//\n// Exports\n//\n\nexport const Grid = {\n Root: GridRoot,\n Content: GridContent,\n};\n\nexport { GridRoot, GridContent, createGridScope, gridSeparatorInlineEnd, gridSeparatorBlockEnd, useGridContext };\n\nexport type { GridRootProps, GridContentProps, GridEditing, GridEditBox, GridScopedProps, DxGridElement };\n\nexport {\n colToA1Notation,\n rowToA1Notation,\n closestCell,\n commentedClassName,\n toPlaneCellIndex,\n parseCellIndex,\n cellQuery,\n DxEditRequest,\n} from '@dxos/lit-grid';\n\nexport type {\n DxGridRange,\n DxGridAxisMeta,\n DxAxisResize,\n DxGridCells,\n DxGridPlaneRange,\n DxGridPlaneCells,\n DxGridCellIndex,\n DxGridPlaneCellIndex,\n DxGridCellValue,\n DxGridPlane,\n DxGridPosition,\n DxGridPlanePosition,\n DxGridAxis,\n} from '@dxos/lit-grid';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { completionStatus } from '@codemirror/autocomplete';\nimport { type Extension } from '@codemirror/state';\nimport { EditorView, keymap } from '@codemirror/view';\nimport React, { type KeyboardEvent } from 'react';\n\nimport { useThemeContext } from '@dxos/react-ui';\nimport { type UseTextEditorProps, useTextEditor } from '@dxos/react-ui-editor';\nimport {\n type ThemeExtensionsOptions,\n createBasicExtensions,\n createThemeExtensions,\n filterChars,\n} from '@dxos/ui-editor';\nimport { mx } from '@dxos/ui-theme';\n\nimport { type GridEditBox } from '../Grid';\n\nexport type EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & { shift?: boolean };\n\nexport type EditorKeyHandler = (value: string | undefined, event: EditorKeyEvent) => void;\nexport type EditorBlurHandler = (value: string | undefined) => void;\nexport type EditorKeyOrBlurHandler = (value: string | undefined, event?: EditorKeyEvent) => void;\n\nexport type EditorKeysProps = {\n onClose: EditorKeyHandler;\n onNav?: EditorKeyHandler;\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: 'Mod-ArrowLeft',\n run: (editor) => {\n const value = editor.state.doc.toString();\n onNav?.(value, { key: 'ArrowLeft' });\n return !!onNav;\n },\n },\n {\n key: 'Mod-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 if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Enter' });\n return true;\n }\n },\n shift: (editor) => {\n if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Enter', shift: true });\n return true;\n }\n },\n },\n {\n key: 'Tab',\n run: (editor) => {\n if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Tab' });\n return true;\n }\n },\n shift: (editor) => {\n if (completionStatus(editor.state)) {\n return false;\n } else {\n onClose(editor.state.doc.toString(), { key: 'Tab', shift: true });\n return true;\n }\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 extensions?: Extension;\n box?: GridEditBox;\n gridId?: string;\n onBlur?: EditorBlurHandler;\n} & Pick<UseTextEditorProps, 'autoFocus'> &\n Pick<ThemeExtensionsOptions, 'slots'>;\n\nexport const CellEditor = ({ value, extensions, box, gridId, autoFocus, slots, onBlur }: 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 extensions ?? [],\n filterChars(/[\\n\\r]+/),\n // Observe the underlying blur DOM event rather than `EditorView.focusChangeEffect`. The\n // focus-change facet fires asynchronously (CodeMirror schedules it on a 10ms setTimeout),\n // which means in React strict mode the destroy → blur of the first EditorView runs the\n // callback after the second view has mounted — committing stale data and closing the\n // editor on the user's first keystroke. Deferring via `queueMicrotask` runs the check\n // *after* `view.destroy()` finishes its synchronous body (which calls `dom.remove()`),\n // so `view.dom.isConnected === false` reliably distinguishes a programmatic teardown\n // from a real user blur. Pass `undefined` on teardown so downstream handlers can consume\n // any pending suppress-next-blur flag without committing stale data.\n EditorView.domEventObservers({\n blur: (_event, view) => {\n const doc = view.state.doc.toString();\n queueMicrotask(() => {\n onBlur?.(view.dom.isConnected ? doc : undefined);\n });\n },\n }),\n createBasicExtensions({ lineWrapping: true }),\n createThemeExtensions({\n themeMode,\n slots: {\n editor: {\n className: mx(\n 'min-w-full! w-min! !max-w-(--dx-grid-cell-editor-max-w-size) min-h-full! !max-h-(--dx-grid-cell-editor-max-h-size)',\n slots?.editor?.className,\n ),\n },\n scroller: {\n className: mx(\n 'overflow-x-hidden! !py-[max(0,calc(var(--dx-grid-cell-editor-padding-block)-1px))] pe-0! !pl-(--dx-grid-cell-editor-padding-inline)',\n slots?.scroller?.className,\n ),\n },\n content: {\n className: mx('break-normal!', slots?.content?.className),\n },\n },\n }),\n ],\n };\n }, [extensions, autoFocus, value, onBlur, themeMode, slots]);\n\n return (\n <div\n data-testid='grid.cell-editor'\n ref={parentRef}\n className='absolute z-[1] dx-grid__cell-editor'\n style={{\n insetInlineStart: box?.insetInlineStart ?? '0px',\n insetBlockStart: box?.insetBlockStart ?? '0px',\n minInlineSize: box?.inlineSize ?? '180px',\n minBlockSize: box?.blockSize ?? '30px',\n ...{ '--dx-grid-cell-width': `${box?.inlineSize ?? 200}px` },\n }}\n {...(gridId && { 'data-grid': gridId })}\n />\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback } from 'react';\n\nimport { type DxGridCellIndex, type GridScopedProps, useGridContext } from '../Grid';\nimport { CellEditor, type CellEditorProps } from './CellEditor';\n\nexport type GridCellEditorProps = GridScopedProps<\n Pick<CellEditorProps, 'extensions' | 'onBlur' | 'slots'> & {\n getCellContent: (index: DxGridCellIndex) => string | undefined;\n }\n>;\n\nexport const GridCellEditor = ({ extensions, getCellContent, onBlur, slots, __gridScope }: GridCellEditorProps) => {\n const { id, editing, setEditing, editBox } = useGridContext('GridCellEditor', __gridScope);\n\n const handleBlur = useCallback(\n (value?: string) => {\n setEditing(null);\n onBlur?.(value);\n },\n [onBlur],\n );\n\n return editing ? (\n <CellEditor\n value={editing.initialContent ?? getCellContent(editing.index)}\n autoFocus\n box={editBox}\n onBlur={handleBlur}\n extensions={extensions}\n gridId={id}\n slots={slots}\n />\n ) : null;\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,gBAAgBC,sBAAsB;;;ACA/C,SAAyBC,uBAAuB;AAChD,SAAqBC,0BAA0B;AAC/C,SAASC,4BAA4B;AACrC,OAAOC,SAGLC,YACAC,aACAC,WACAC,gBACK;AAEP,OAAO;AACP,SAAwEC,UAAUC,qBAAqB;AA6JvG,SACEC,iBACAC,iBACAC,aACAC,oBACAC,kBACAC,gBACAC,WACAC,qBACK;AAlKP,IAAMT,SAASR,gBAAgB;EAC7BkB,SAAS;EACTC,cAAcV;EACdW,OAAOjB;EACPkB,QAAQ;IACNC,cAAc;IACdC,QAAQ;IACRC,UAAU;EACZ;AACF,CAAA;AAIA,IAAMC,aAAa;EACjBC,kBAAkB;EAClBC,iBAAiB;EACjBC,YAAY;EACZC,WAAW;AACb;AAkBA,IAAMC,YAAY;AAElB,IAAM,CAACC,mBAAmBC,eAAAA,IAAmB/B,mBAAmB6B,WAAW,CAAA,CAAE;AAE7E,IAAM,CAACG,cAAcC,cAAAA,IAAkBH,kBAAoCD,SAAAA;AAa3E,IAAMK,WAAW,CAAC,EAChBC,aACAC,UACAC,IACAC,SAASC,cACTC,gBACAC,gBAAe,MACgB;AAC/B,QAAM,CAACH,UAAU,MAAMI,UAAAA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ACAC,KAAKV;IACLN,QAAQQ;IACRV;IACAmB,QAAQd;IACRF;OAEA;AACN;",
|
|
6
|
+
"names": ["defaultColSize", "defaultRowSize", "createComponent", "createContextScope", "useControllableState", "React", "forwardRef", "useCallback", "useEffect", "useState", "DxGrid", "NaturalDxGrid", "colToA1Notation", "rowToA1Notation", "closestCell", "commentedClassName", "toPlaneCellIndex", "parseCellIndex", "cellQuery", "DxEditRequest", "tagName", "elementClass", "react", "events", "onAxisResize", "onEdit", "onSelect", "initialBox", "insetInlineStart", "insetBlockStart", "inlineSize", "blockSize", "GRID_NAME", "createGridContext", "createGridScope", "GridProvider", "useGridContext", "GridRoot", "__gridScope", "children", "id", "editing", "propsEditing", "defaultEditing", "onEditingChange", "setEditing", "prop", "defaultProp", "onChange", "editBox", "setEditBox", "scope", "div", "className", "style", "display", "displayName", "GRID_CONTENT_NAME", "GridContent", "props", "forwardedRef", "dxGrid", "setDxGridInternal", "setDxGrid", "nextDxGrid", "current", "getCells", "requestUpdate", "handleEdit", "event", "cellBox", "index", "cellIndex", "cellElement", "initialContent", "gridId", "mode", "ref", "gridSeparatorInlineEnd", "gridSeparatorBlockEnd", "Grid", "Root", "Content", "completionStatus", "EditorView", "keymap", "React", "useThemeContext", "useTextEditor", "createBasicExtensions", "createThemeExtensions", "filterChars", "mx", "editorKeys", "onNav", "onClose", "of", "key", "run", "editor", "value", "state", "doc", "toString", "shift", "undefined", "CellEditor", "extensions", "box", "gridId", "autoFocus", "slots", "onBlur", "themeMode", "parentRef", "initialValue", "selection", "anchor", "length", "domEventObservers", "blur", "_event", "view", "queueMicrotask", "dom", "isConnected", "lineWrapping", "className", "scroller", "content", "div", "data-testid", "ref", "style", "insetInlineStart", "insetBlockStart", "minInlineSize", "inlineSize", "minBlockSize", "blockSize", "React", "useCallback", "GridCellEditor", "extensions", "getCellContent", "onBlur", "slots", "__gridScope", "id", "editing", "setEditing", "editBox", "useGridContext", "handleBlur", "useCallback", "value", "React", "CellEditor", "initialContent", "index", "autoFocus", "box", "gridId"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/Grid/Grid.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"src/Grid/Grid.tsx":{"bytes":16514,"imports":[{"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/dx-grid.pcss","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true}],"format":"esm"},"src/Grid/index.ts":{"bytes":368,"imports":[{"path":"src/Grid/Grid.tsx","kind":"import-statement","original":"./Grid"}],"format":"esm"},"src/CellEditor/CellEditor.tsx":{"bytes":20399,"imports":[{"path":"@codemirror/autocomplete","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":"@dxos/ui-editor","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/CellEditor/GridCellEditor.tsx":{"bytes":3399,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"src/Grid/index.ts","kind":"import-statement","original":"../Grid"},{"path":"src/CellEditor/CellEditor.tsx","kind":"import-statement","original":"./CellEditor"}],"format":"esm"},"src/CellEditor/index.ts":{"bytes":484,"imports":[{"path":"src/CellEditor/CellEditor.tsx","kind":"import-statement","original":"./CellEditor"},{"path":"src/CellEditor/GridCellEditor.tsx","kind":"import-statement","original":"./GridCellEditor"}],"format":"esm"},"src/index.ts":{"bytes":711,"imports":[{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"src/Grid/index.ts","kind":"import-statement","original":"./Grid"},{"path":"src/CellEditor/index.ts","kind":"import-statement","original":"./CellEditor"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":20877},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/lit-grid","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/dx-grid.pcss","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"@dxos/lit-grid","kind":"import-statement","external":true},{"path":"@codemirror/autocomplete","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":"@dxos/ui-editor","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["CellEditor","DxEditRequest","Grid","GridCellEditor","GridContent","GridRoot","cellQuery","closestCell","colToA1Notation","commentedClassName","createGridScope","defaultColSize","defaultRowSize","editorKeys","gridSeparatorBlockEnd","gridSeparatorInlineEnd","parseCellIndex","rowToA1Notation","toPlaneCellIndex","useGridContext"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":65},"src/Grid/Grid.tsx":{"bytesInOutput":3340},"src/CellEditor/CellEditor.tsx":{"bytesInOutput":5359},"src/CellEditor/GridCellEditor.tsx":{"bytesInOutput":615}},"bytes":9883}}}
|