@dxos/react-ui-grid 0.8.4-main.c4373fc → 0.8.4-main.cb12b3f963
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 +138 -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 +2 -1
- package/dist/types/src/Grid/Grid.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -23
- package/src/CellEditor/CellEditor.stories.tsx +1 -1
- package/src/CellEditor/CellEditor.tsx +10 -11
- package/src/CellEditor/GridCellEditor.tsx +0 -1
- package/src/Grid/Grid.stories.tsx +65 -29
- package/src/Grid/Grid.tsx +10 -8
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-grid",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.cb12b3f963",
|
|
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",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
@@ -16,9 +20,6 @@
|
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"types": "dist/types/src/index.d.ts",
|
|
19
|
-
"typesVersions": {
|
|
20
|
-
"*": {}
|
|
21
|
-
},
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
24
25
|
"src"
|
|
@@ -28,31 +29,32 @@
|
|
|
28
29
|
"@codemirror/state": "^6.5.2",
|
|
29
30
|
"@codemirror/view": "^6.38.4",
|
|
30
31
|
"@lit/react": "^1.0.8",
|
|
31
|
-
"@preact-signals/safe-react": "^0.9.0",
|
|
32
32
|
"@radix-ui/react-context": "1.1.1",
|
|
33
33
|
"@radix-ui/react-popper": "1.2.2",
|
|
34
34
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
35
|
+
"@dxos/lit-grid": "0.8.4-main.cb12b3f963",
|
|
36
|
+
"@dxos/react-ui-editor": "0.8.4-main.cb12b3f963",
|
|
37
|
+
"@dxos/ui-editor": "0.8.4-main.cb12b3f963",
|
|
38
|
+
"@dxos/util": "0.8.4-main.cb12b3f963"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/react": "~19.2.
|
|
41
|
-
"@types/react-dom": "~19.2.
|
|
42
|
-
"react": "~19.2.
|
|
43
|
-
"react-dom": "~19.2.
|
|
44
|
-
"vite": "
|
|
45
|
-
"@dxos/random": "0.8.4-main.
|
|
46
|
-
"@dxos/react-ui
|
|
47
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
41
|
+
"@types/react": "~19.2.7",
|
|
42
|
+
"@types/react-dom": "~19.2.3",
|
|
43
|
+
"react": "~19.2.3",
|
|
44
|
+
"react-dom": "~19.2.3",
|
|
45
|
+
"vite": "^8.0.10",
|
|
46
|
+
"@dxos/random": "0.8.4-main.cb12b3f963",
|
|
47
|
+
"@dxos/react-ui": "0.8.4-main.cb12b3f963",
|
|
48
|
+
"@dxos/react-ui-list": "0.8.4-main.cb12b3f963",
|
|
49
|
+
"@dxos/storybook-utils": "0.8.4-main.cb12b3f963",
|
|
50
|
+
"@dxos/ui-theme": "0.8.4-main.cb12b3f963",
|
|
51
|
+
"@dxos/react-ui-search": "0.8.4-main.cb12b3f963"
|
|
50
52
|
},
|
|
51
53
|
"peerDependencies": {
|
|
52
|
-
"react": "
|
|
53
|
-
"react-dom": "
|
|
54
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
55
|
-
"@dxos/
|
|
54
|
+
"react": "~19.2.3",
|
|
55
|
+
"react-dom": "~19.2.3",
|
|
56
|
+
"@dxos/react-ui": "0.8.4-main.cb12b3f963",
|
|
57
|
+
"@dxos/ui-theme": "0.8.4-main.cb12b3f963"
|
|
56
58
|
},
|
|
57
59
|
"publishConfig": {
|
|
58
60
|
"access": "public"
|
|
@@ -8,15 +8,14 @@ import { EditorView, keymap } from '@codemirror/view';
|
|
|
8
8
|
import React, { type KeyboardEvent } from 'react';
|
|
9
9
|
|
|
10
10
|
import { useThemeContext } from '@dxos/react-ui';
|
|
11
|
+
import { type UseTextEditorProps, useTextEditor } from '@dxos/react-ui-editor';
|
|
11
12
|
import {
|
|
12
13
|
type ThemeExtensionsOptions,
|
|
13
|
-
type UseTextEditorProps,
|
|
14
14
|
createBasicExtensions,
|
|
15
15
|
createThemeExtensions,
|
|
16
16
|
filterChars,
|
|
17
|
-
|
|
18
|
-
} from '@dxos/
|
|
19
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
17
|
+
} from '@dxos/ui-editor';
|
|
18
|
+
import { mx } from '@dxos/ui-theme';
|
|
20
19
|
|
|
21
20
|
import { type GridEditBox } from '../Grid';
|
|
22
21
|
|
|
@@ -123,7 +122,7 @@ export type CellEditorProps = {
|
|
|
123
122
|
} & Pick<UseTextEditorProps, 'autoFocus'> &
|
|
124
123
|
Pick<ThemeExtensionsOptions, 'slots'>;
|
|
125
124
|
|
|
126
|
-
export const CellEditor = ({ value, extensions, box, gridId,
|
|
125
|
+
export const CellEditor = ({ value, extensions, box, gridId, autoFocus, slots, onBlur }: CellEditorProps) => {
|
|
127
126
|
const { themeMode } = useThemeContext();
|
|
128
127
|
const { parentRef } = useTextEditor(() => {
|
|
129
128
|
return {
|
|
@@ -145,18 +144,18 @@ export const CellEditor = ({ value, extensions, box, gridId, onBlur, autoFocus,
|
|
|
145
144
|
slots: {
|
|
146
145
|
editor: {
|
|
147
146
|
className: mx(
|
|
148
|
-
'
|
|
147
|
+
'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)',
|
|
149
148
|
slots?.editor?.className,
|
|
150
149
|
),
|
|
151
150
|
},
|
|
152
|
-
|
|
151
|
+
scroller: {
|
|
153
152
|
className: mx(
|
|
154
|
-
'
|
|
155
|
-
slots?.
|
|
153
|
+
'overflow-x-hidden! !py-[max(0,calc(var(--dx-grid-cell-editor-padding-block)-1px))] pe-0! !pl-(--dx-grid-cell-editor-padding-inline)',
|
|
154
|
+
slots?.scroller?.className,
|
|
156
155
|
),
|
|
157
156
|
},
|
|
158
157
|
content: {
|
|
159
|
-
className: mx('
|
|
158
|
+
className: mx('break-normal!', slots?.content?.className),
|
|
160
159
|
},
|
|
161
160
|
},
|
|
162
161
|
}),
|
|
@@ -174,7 +173,7 @@ export const CellEditor = ({ value, extensions, box, gridId, onBlur, autoFocus,
|
|
|
174
173
|
insetBlockStart: box?.insetBlockStart ?? '0px',
|
|
175
174
|
minInlineSize: box?.inlineSize ?? '180px',
|
|
176
175
|
minBlockSize: box?.blockSize ?? '30px',
|
|
177
|
-
...{ '--dx-
|
|
176
|
+
...{ '--dx-grid-cell-width': `${box?.inlineSize ?? 200}px` },
|
|
178
177
|
}}
|
|
179
178
|
{...(gridId && { 'data-grid': gridId })}
|
|
180
179
|
/>
|
|
@@ -6,14 +6,17 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React, { type MouseEvent, type MutableRefObject, useCallback, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { defaultRowSize } from '@dxos/lit-grid';
|
|
9
|
-
import {
|
|
9
|
+
import { type DxGridPlaneCells } from '@dxos/lit-grid';
|
|
10
|
+
import { random } from '@dxos/random';
|
|
10
11
|
import { DropdownMenu } from '@dxos/react-ui';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { toPlaneCellIndex } from '@dxos/react-ui-grid';
|
|
13
|
+
import { Combobox, type ComboboxRootProps } from '@dxos/react-ui-list';
|
|
14
|
+
import { useSearchListResults } from '@dxos/react-ui-search';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
16
|
|
|
14
17
|
import { Grid, type GridContentProps, type GridEditing, type GridRootProps } from './Grid';
|
|
15
18
|
|
|
16
|
-
const storybookItems =
|
|
19
|
+
const storybookItems = random.helpers.uniqueArray(random.commerce.productName, 16);
|
|
17
20
|
|
|
18
21
|
type GridStoryProps = GridContentProps & Pick<GridRootProps, 'onEditingChange'>;
|
|
19
22
|
|
|
@@ -31,7 +34,7 @@ const GridStory = ({ initialCells, ...props }: GridStoryProps) => {
|
|
|
31
34
|
// Multiselect
|
|
32
35
|
const [popoverOpen, setPopoverOpen] = useState(false);
|
|
33
36
|
const [multiSelectValue, setInternalMultiselectValue] = useState('');
|
|
34
|
-
const setMultiselectValue = useCallback<NonNullable<
|
|
37
|
+
const setMultiselectValue = useCallback<NonNullable<ComboboxRootProps['onValueChange']>>((nextValue) => {
|
|
35
38
|
setInternalMultiselectValue(nextValue);
|
|
36
39
|
setCells((cells) => {
|
|
37
40
|
// TODO(burdon): How can we get the cell address to update?
|
|
@@ -62,7 +65,7 @@ const GridStory = ({ initialCells, ...props }: GridStoryProps) => {
|
|
|
62
65
|
}, []);
|
|
63
66
|
|
|
64
67
|
return (
|
|
65
|
-
<div role='none' className='
|
|
68
|
+
<div role='none' className='contents'>
|
|
66
69
|
<Grid.Root id='story' editing={editing} onEditingChange={handleEditingChange}>
|
|
67
70
|
{/* TODO(burdon): Why is this property not just "cells" or "values" */}
|
|
68
71
|
<Grid.Content {...props} initialCells={cells} onClick={handleClick} />
|
|
@@ -78,31 +81,41 @@ const GridStory = ({ initialCells, ...props }: GridStoryProps) => {
|
|
|
78
81
|
</DropdownMenu.Root>
|
|
79
82
|
|
|
80
83
|
{/* Multiselect */}
|
|
81
|
-
<
|
|
84
|
+
<Combobox.Root
|
|
82
85
|
open={popoverOpen}
|
|
83
86
|
onOpenChange={setPopoverOpen}
|
|
84
87
|
value={multiSelectValue}
|
|
85
88
|
onValueChange={setMultiselectValue}
|
|
86
89
|
>
|
|
87
|
-
<
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
<PopoverCombobox.List>
|
|
91
|
-
{storybookItems.map((value) => (
|
|
92
|
-
<PopoverCombobox.Item key={value}>{value}</PopoverCombobox.Item>
|
|
93
|
-
))}
|
|
94
|
-
</PopoverCombobox.List>
|
|
95
|
-
<PopoverCombobox.Arrow />
|
|
96
|
-
</PopoverCombobox.Content>
|
|
97
|
-
</PopoverCombobox.Root>
|
|
90
|
+
<Combobox.VirtualTrigger virtualRef={triggerRef} />
|
|
91
|
+
<ComboboxContentWithFiltering />
|
|
92
|
+
</Combobox.Root>
|
|
98
93
|
</div>
|
|
99
94
|
);
|
|
100
95
|
};
|
|
101
96
|
|
|
97
|
+
const ComboboxContentWithFiltering = () => {
|
|
98
|
+
const { results, query, handleSearch } = useSearchListResults({
|
|
99
|
+
items: storybookItems,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<Combobox.Content>
|
|
104
|
+
<Combobox.Input placeholder='Search...' value={query} onValueChange={handleSearch} />
|
|
105
|
+
<Combobox.List>
|
|
106
|
+
{results.map((value) => (
|
|
107
|
+
<Combobox.Item key={value} value={value} label={value} />
|
|
108
|
+
))}
|
|
109
|
+
</Combobox.List>
|
|
110
|
+
<Combobox.Arrow />
|
|
111
|
+
</Combobox.Content>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
102
115
|
const meta = {
|
|
103
116
|
title: 'ui/react-ui-grid/Grid',
|
|
104
117
|
component: GridStory,
|
|
105
|
-
decorators: [withTheme],
|
|
118
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
106
119
|
parameters: {
|
|
107
120
|
layout: 'fullscreen',
|
|
108
121
|
},
|
|
@@ -112,6 +125,8 @@ export default meta;
|
|
|
112
125
|
|
|
113
126
|
type Story = StoryObj<typeof meta>;
|
|
114
127
|
|
|
128
|
+
export const Default: Story = {};
|
|
129
|
+
|
|
115
130
|
export const Basic: Story = {
|
|
116
131
|
args: {
|
|
117
132
|
id: 'story',
|
|
@@ -141,7 +156,7 @@ export const Basic: Story = {
|
|
|
141
156
|
'1,1': {
|
|
142
157
|
value: 'Demo decoration',
|
|
143
158
|
accessoryHtml: `
|
|
144
|
-
<button class="dx-button
|
|
159
|
+
<button class="dx-button w-6 px-0.5 min-h-0 absolute inset-y-1 right-1" data-story-action="menu">
|
|
145
160
|
<svg><use href="/icons.svg#ph--arrow-right--regular"/></svg>
|
|
146
161
|
</button>
|
|
147
162
|
`,
|
|
@@ -158,26 +173,47 @@ export const Basic: Story = {
|
|
|
158
173
|
},
|
|
159
174
|
};
|
|
160
175
|
|
|
161
|
-
|
|
162
|
-
|
|
176
|
+
const cellSize = 40;
|
|
177
|
+
|
|
178
|
+
// TODO(burdon): Calendar.
|
|
179
|
+
export const Calendar: Story = {
|
|
163
180
|
args: {
|
|
164
181
|
id: 'story',
|
|
165
|
-
limitColumns:
|
|
182
|
+
limitColumns: 7,
|
|
166
183
|
columnDefault: {
|
|
167
184
|
grid: {
|
|
168
|
-
size:
|
|
185
|
+
size: cellSize,
|
|
186
|
+
resizeable: false,
|
|
169
187
|
},
|
|
170
188
|
},
|
|
171
189
|
rowDefault: {
|
|
172
190
|
grid: {
|
|
173
|
-
size:
|
|
191
|
+
size: cellSize,
|
|
174
192
|
resizeable: false,
|
|
175
193
|
},
|
|
176
194
|
},
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
getCells: (range, plane) => {
|
|
196
|
+
const cells: DxGridPlaneCells = {};
|
|
197
|
+
if (plane === 'grid') {
|
|
198
|
+
for (let col = range.start.col; col <= range.end.col; col++) {
|
|
199
|
+
for (let row = range.start.row; row <= range.end.row; row++) {
|
|
200
|
+
// TODO(burdon): Formatting changes when cell is selected.
|
|
201
|
+
cells[toPlaneCellIndex({ col, row })] = {
|
|
202
|
+
readonly: true,
|
|
203
|
+
accessoryHtml: '<div class="flex h-full w-full justify-center items-center overflow-hidden">0</div>',
|
|
204
|
+
className: '',
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return cells;
|
|
181
210
|
},
|
|
182
211
|
},
|
|
212
|
+
render: (args) => (
|
|
213
|
+
<div className='h-full flex justify-center'>
|
|
214
|
+
<div className='h-full w-[288px] border-x border-separator'>
|
|
215
|
+
<GridStory {...args} />
|
|
216
|
+
</div>
|
|
217
|
+
</div>
|
|
218
|
+
),
|
|
183
219
|
};
|
package/src/Grid/Grid.tsx
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos/lit-grid/dx-grid.pcss';
|
|
6
|
-
|
|
7
5
|
import { type EventName, createComponent } from '@lit/react';
|
|
8
6
|
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
9
7
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
@@ -16,6 +14,7 @@ import React, {
|
|
|
16
14
|
useState,
|
|
17
15
|
} from 'react';
|
|
18
16
|
|
|
17
|
+
import '@dxos/lit-grid/dx-grid.pcss';
|
|
19
18
|
import { type DxAxisResize, type DxEditRequest, type DxGridCellsSelect, DxGrid as NaturalDxGrid } from '@dxos/lit-grid';
|
|
20
19
|
|
|
21
20
|
type DxGridElement = NaturalDxGrid;
|
|
@@ -63,20 +62,23 @@ const [createGridContext, createGridScope] = createContextScope(GRID_NAME, []);
|
|
|
63
62
|
const [GridProvider, useGridContext] = createGridContext<GridContextValue>(GRID_NAME);
|
|
64
63
|
|
|
65
64
|
type GridRootProps = PropsWithChildren<
|
|
66
|
-
{
|
|
65
|
+
{
|
|
66
|
+
id: string;
|
|
67
|
+
} & Partial<{
|
|
67
68
|
editing: GridEditing;
|
|
68
69
|
defaultEditing: GridEditing;
|
|
69
70
|
onEditingChange: (nextEditing: GridEditing) => void;
|
|
70
71
|
}>
|
|
71
72
|
>;
|
|
72
73
|
|
|
74
|
+
// TODO(burdon): Make headless.
|
|
73
75
|
const GridRoot = ({
|
|
76
|
+
__gridScope,
|
|
77
|
+
children,
|
|
74
78
|
id,
|
|
75
79
|
editing: propsEditing,
|
|
76
80
|
defaultEditing,
|
|
77
81
|
onEditingChange,
|
|
78
|
-
children,
|
|
79
|
-
__gridScope,
|
|
80
82
|
}: GridScopedProps<GridRootProps>) => {
|
|
81
83
|
const [editing = null, setEditing] = useControllableState({
|
|
82
84
|
prop: propsEditing,
|
|
@@ -150,12 +152,12 @@ GridContent.displayName = GRID_CONTENT_NAME;
|
|
|
150
152
|
// Fragments
|
|
151
153
|
//
|
|
152
154
|
|
|
153
|
-
// NOTE(Zan): These fragments add border to
|
|
155
|
+
// NOTE(Zan): These fragments add border to w-end and h-end of the grid using pseudo-elements.
|
|
154
156
|
// These are offset by 1px to avoid double borders in planks.
|
|
155
157
|
const gridSeparatorInlineEnd =
|
|
156
|
-
'[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-
|
|
158
|
+
'[&>.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';
|
|
157
159
|
const gridSeparatorBlockEnd =
|
|
158
|
-
'[&>.dx-grid]:relative [&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-
|
|
160
|
+
'[&>.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';
|
|
159
161
|
|
|
160
162
|
//
|
|
161
163
|
// Exports
|