@dxos/react-ui-grid 0.8.3 → 0.8.4-main.03d5cd7b56
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 +145 -156
- 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 +4 -4
- package/dist/types/src/CellEditor/CellEditor.d.ts.map +1 -1
- package/dist/types/src/CellEditor/CellEditor.stories.d.ts +16 -0
- package/dist/types/src/CellEditor/CellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/CellEditor/GridCellEditor.d.ts +3 -3
- package/dist/types/src/CellEditor/GridCellEditor.d.ts.map +1 -1
- package/dist/types/src/Grid/Grid.d.ts +10 -10
- package/dist/types/src/Grid/Grid.d.ts.map +1 -1
- package/dist/types/src/Grid/Grid.stories.d.ts +12 -4
- package/dist/types/src/Grid/Grid.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -28
- package/src/CellEditor/CellEditor.stories.tsx +88 -0
- package/src/CellEditor/CellEditor.tsx +31 -17
- package/src/CellEditor/GridCellEditor.tsx +8 -5
- package/src/Grid/Grid.stories.tsx +72 -36
- package/src/Grid/Grid.tsx +17 -14
package/package.json
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-grid",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.03d5cd7b56",
|
|
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
|
".": {
|
|
17
|
+
"source": "./src/index.ts",
|
|
13
18
|
"types": "./dist/types/src/index.d.ts",
|
|
14
|
-
"browser": "./dist/lib/browser/index.mjs"
|
|
19
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
20
|
+
"node": "./dist/lib/browser/index.mjs"
|
|
15
21
|
}
|
|
16
22
|
},
|
|
17
23
|
"types": "dist/types/src/index.d.ts",
|
|
18
|
-
"typesVersions": {
|
|
19
|
-
"*": {}
|
|
20
|
-
},
|
|
21
24
|
"files": [
|
|
22
25
|
"dist",
|
|
23
26
|
"src"
|
|
24
27
|
],
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@codemirror/autocomplete": "^6.
|
|
27
|
-
"@codemirror/state": "^6.
|
|
28
|
-
"@codemirror/view": "^6.
|
|
29
|
-
"@lit/react": "^1.0.
|
|
30
|
-
"@preact-signals/safe-react": "^0.9.0",
|
|
29
|
+
"@codemirror/autocomplete": "^6.19.0",
|
|
30
|
+
"@codemirror/state": "^6.5.2",
|
|
31
|
+
"@codemirror/view": "^6.38.5",
|
|
32
|
+
"@lit/react": "^1.0.8",
|
|
31
33
|
"@radix-ui/react-context": "1.1.1",
|
|
32
34
|
"@radix-ui/react-popper": "1.2.2",
|
|
33
35
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
34
|
-
"@dxos/lit-grid": "0.8.
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
36
|
+
"@dxos/lit-grid": "0.8.4-main.03d5cd7b56",
|
|
37
|
+
"@dxos/react-ui-editor": "0.8.4-main.03d5cd7b56",
|
|
38
|
+
"@dxos/util": "0.8.4-main.03d5cd7b56",
|
|
39
|
+
"@dxos/ui-editor": "0.8.4-main.03d5cd7b56"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"@types/react": "~
|
|
40
|
-
"@types/react-dom": "~
|
|
41
|
-
"react": "~
|
|
42
|
-
"react-dom": "~
|
|
43
|
-
"vite": "
|
|
44
|
-
"@dxos/random": "0.8.
|
|
45
|
-
"@dxos/react-ui": "0.8.
|
|
46
|
-
"@dxos/react-ui-
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
42
|
+
"@types/react": "~19.2.7",
|
|
43
|
+
"@types/react-dom": "~19.2.3",
|
|
44
|
+
"react": "~19.2.3",
|
|
45
|
+
"react-dom": "~19.2.3",
|
|
46
|
+
"vite": "^8.0.10",
|
|
47
|
+
"@dxos/random": "0.8.4-main.03d5cd7b56",
|
|
48
|
+
"@dxos/react-ui": "0.8.4-main.03d5cd7b56",
|
|
49
|
+
"@dxos/react-ui-list": "0.8.4-main.03d5cd7b56",
|
|
50
|
+
"@dxos/storybook-utils": "0.8.4-main.03d5cd7b56",
|
|
51
|
+
"@dxos/react-ui-search": "0.8.4-main.03d5cd7b56",
|
|
52
|
+
"@dxos/ui-theme": "0.8.4-main.03d5cd7b56"
|
|
49
53
|
},
|
|
50
54
|
"peerDependencies": {
|
|
51
|
-
"react": "~
|
|
52
|
-
"react-dom": "~
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/react-ui
|
|
55
|
+
"react": "~19.2.3",
|
|
56
|
+
"react-dom": "~19.2.3",
|
|
57
|
+
"@dxos/ui-theme": "0.8.4-main.03d5cd7b56",
|
|
58
|
+
"@dxos/react-ui": "0.8.4-main.03d5cd7b56"
|
|
55
59
|
},
|
|
56
60
|
"publishConfig": {
|
|
57
61
|
"access": "public"
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
|
|
10
|
+
import { CellEditor, type CellEditorProps, type EditorKeyEvent, editorKeys } from './CellEditor';
|
|
11
|
+
|
|
12
|
+
const DefaultStory = (props: CellEditorProps) => {
|
|
13
|
+
const [value, setValue] = useState(props.value || 'Edit me');
|
|
14
|
+
const [lastAction, setLastAction] = useState<string>('');
|
|
15
|
+
|
|
16
|
+
const handleBlur = (newValue?: string) => {
|
|
17
|
+
if (newValue !== undefined) {
|
|
18
|
+
setValue(newValue);
|
|
19
|
+
setLastAction(`Blur: ${newValue}`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const handleKeyEvent = (newValue: string | undefined, event: EditorKeyEvent) => {
|
|
24
|
+
if (newValue !== undefined) {
|
|
25
|
+
setValue(newValue);
|
|
26
|
+
setLastAction(`Key: ${event.key}${event.shift ? ' + Shift' : ''}, Value: ${newValue}`);
|
|
27
|
+
} else {
|
|
28
|
+
setLastAction(`Key: ${event.key}${event.shift ? ' + Shift' : ''}, Cancelled`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Create an extension with editor keys
|
|
33
|
+
const extensions = props.extensions || [
|
|
34
|
+
editorKeys({
|
|
35
|
+
onClose: handleKeyEvent,
|
|
36
|
+
onNav: (value, event) => {
|
|
37
|
+
setLastAction(`Navigation: ${event.key}, Value: ${value}`);
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className='flex flex-col gap-4 p-4'>
|
|
44
|
+
<div className='text-sm'>
|
|
45
|
+
Current value: <span className='font-mono'>{value}</span>
|
|
46
|
+
</div>
|
|
47
|
+
<div className='text-sm'>
|
|
48
|
+
Last action: <span className='font-mono'>{lastAction}</span>
|
|
49
|
+
</div>
|
|
50
|
+
<div className='relative border border-separator h-[100px] w-[300px]'>
|
|
51
|
+
<CellEditor
|
|
52
|
+
value={value}
|
|
53
|
+
extensions={extensions}
|
|
54
|
+
autoFocus={props.autoFocus}
|
|
55
|
+
onBlur={handleBlur}
|
|
56
|
+
box={{
|
|
57
|
+
insetInlineStart: 10,
|
|
58
|
+
insetBlockStart: 10,
|
|
59
|
+
inlineSize: 280,
|
|
60
|
+
blockSize: 30,
|
|
61
|
+
}}
|
|
62
|
+
gridId='demo-grid'
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const meta = {
|
|
70
|
+
title: 'ui/react-ui-grid/CellEditor',
|
|
71
|
+
component: CellEditor,
|
|
72
|
+
render: DefaultStory,
|
|
73
|
+
decorators: [withTheme()],
|
|
74
|
+
parameters: {
|
|
75
|
+
layout: 'centered',
|
|
76
|
+
},
|
|
77
|
+
} satisfies Meta<typeof CellEditor>;
|
|
78
|
+
|
|
79
|
+
export default meta;
|
|
80
|
+
|
|
81
|
+
type Story = StoryObj<typeof meta>;
|
|
82
|
+
|
|
83
|
+
export const Default: Story = {
|
|
84
|
+
args: {
|
|
85
|
+
value: 'Edit me',
|
|
86
|
+
autoFocus: true,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -8,13 +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
|
-
type
|
|
13
|
+
type ThemeExtensionsOptions,
|
|
13
14
|
createBasicExtensions,
|
|
14
15
|
createThemeExtensions,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from '@dxos/
|
|
16
|
+
filterChars,
|
|
17
|
+
} from '@dxos/ui-editor';
|
|
18
|
+
import { mx } from '@dxos/ui-theme';
|
|
18
19
|
|
|
19
20
|
import { type GridEditBox } from '../Grid';
|
|
20
21
|
|
|
@@ -114,12 +115,14 @@ export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
|
|
|
114
115
|
|
|
115
116
|
export type CellEditorProps = {
|
|
116
117
|
value?: string;
|
|
117
|
-
|
|
118
|
+
extensions?: Extension;
|
|
118
119
|
box?: GridEditBox;
|
|
119
120
|
gridId?: string;
|
|
120
|
-
|
|
121
|
+
onBlur?: EditorBlurHandler;
|
|
122
|
+
} & Pick<UseTextEditorProps, 'autoFocus'> &
|
|
123
|
+
Pick<ThemeExtensionsOptions, 'slots'>;
|
|
121
124
|
|
|
122
|
-
export const CellEditor = ({ value,
|
|
125
|
+
export const CellEditor = ({ value, extensions, box, gridId, autoFocus, slots, onBlur }: CellEditorProps) => {
|
|
123
126
|
const { themeMode } = useThemeContext();
|
|
124
127
|
const { parentRef } = useTextEditor(() => {
|
|
125
128
|
return {
|
|
@@ -127,39 +130,50 @@ export const CellEditor = ({ value, extension, autoFocus, onBlur, box, gridId }:
|
|
|
127
130
|
initialValue: value,
|
|
128
131
|
selection: { anchor: value?.length ?? 0 },
|
|
129
132
|
extensions: [
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
extensions ?? [],
|
|
134
|
+
filterChars(/[\n\r]+/),
|
|
132
135
|
EditorView.focusChangeEffect.of((state, focusing) => {
|
|
133
136
|
if (!focusing) {
|
|
134
137
|
onBlur?.(state.doc.toString());
|
|
135
138
|
}
|
|
136
139
|
return null;
|
|
137
140
|
}),
|
|
138
|
-
createBasicExtensions({ lineWrapping:
|
|
141
|
+
createBasicExtensions({ lineWrapping: true }),
|
|
139
142
|
createThemeExtensions({
|
|
140
143
|
themeMode,
|
|
141
144
|
slots: {
|
|
142
145
|
editor: {
|
|
143
|
-
className:
|
|
146
|
+
className: mx(
|
|
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)',
|
|
148
|
+
slots?.editor?.className,
|
|
149
|
+
),
|
|
150
|
+
},
|
|
151
|
+
scroller: {
|
|
152
|
+
className: mx(
|
|
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,
|
|
155
|
+
),
|
|
144
156
|
},
|
|
145
157
|
content: {
|
|
146
|
-
className:
|
|
147
|
-
'!border !border-transparent !pli-[var(--dx-grid-cell-padding-inline)] !plb-[var(--dx-grid-cell-padding-block)]',
|
|
158
|
+
className: mx('break-normal!', slots?.content?.className),
|
|
148
159
|
},
|
|
149
160
|
},
|
|
150
161
|
}),
|
|
151
162
|
],
|
|
152
163
|
};
|
|
153
|
-
}, [
|
|
164
|
+
}, [extensions, autoFocus, value, onBlur, themeMode, slots]);
|
|
154
165
|
|
|
155
166
|
return (
|
|
156
167
|
<div
|
|
157
168
|
data-testid='grid.cell-editor'
|
|
158
169
|
ref={parentRef}
|
|
159
|
-
className='absolute z-[1]'
|
|
170
|
+
className='absolute z-[1] dx-grid__cell-editor'
|
|
160
171
|
style={{
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
insetInlineStart: box?.insetInlineStart ?? '0px',
|
|
173
|
+
insetBlockStart: box?.insetBlockStart ?? '0px',
|
|
174
|
+
minInlineSize: box?.inlineSize ?? '180px',
|
|
175
|
+
minBlockSize: box?.blockSize ?? '30px',
|
|
176
|
+
...{ '--dx-grid-cell-width': `${box?.inlineSize ?? 200}px` },
|
|
163
177
|
}}
|
|
164
178
|
{...(gridId && { 'data-grid': gridId })}
|
|
165
179
|
/>
|
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback } from 'react';
|
|
6
6
|
|
|
7
|
+
import { type DxGridCellIndex, type GridScopedProps, useGridContext } from '../Grid';
|
|
7
8
|
import { CellEditor, type CellEditorProps } from './CellEditor';
|
|
8
|
-
import { type GridScopedProps, useGridContext, type DxGridCellIndex } from '../Grid';
|
|
9
9
|
|
|
10
10
|
export type GridCellEditorProps = GridScopedProps<
|
|
11
|
-
Pick<CellEditorProps, '
|
|
11
|
+
Pick<CellEditorProps, 'extensions' | 'onBlur' | 'slots'> & {
|
|
12
|
+
getCellContent: (index: DxGridCellIndex) => string | undefined;
|
|
13
|
+
}
|
|
12
14
|
>;
|
|
13
15
|
|
|
14
|
-
export const GridCellEditor = ({
|
|
15
|
-
const { id, editing, setEditing, editBox } = useGridContext('
|
|
16
|
+
export const GridCellEditor = ({ extensions, getCellContent, onBlur, slots, __gridScope }: GridCellEditorProps) => {
|
|
17
|
+
const { id, editing, setEditing, editBox } = useGridContext('GridCellEditor', __gridScope);
|
|
16
18
|
|
|
17
19
|
const handleBlur = useCallback(
|
|
18
20
|
(value?: string) => {
|
|
@@ -28,8 +30,9 @@ export const GridCellEditor = ({ extension, getCellContent, onBlur, __gridScope
|
|
|
28
30
|
autoFocus
|
|
29
31
|
box={editBox}
|
|
30
32
|
onBlur={handleBlur}
|
|
31
|
-
|
|
33
|
+
extensions={extensions}
|
|
32
34
|
gridId={id}
|
|
35
|
+
slots={slots}
|
|
33
36
|
/>
|
|
34
37
|
) : null;
|
|
35
38
|
};
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type Meta, type StoryObj } from '@storybook/react';
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { type MouseEvent, type MutableRefObject, useCallback, useRef, useState } from 'react';
|
|
9
7
|
|
|
10
8
|
import { defaultRowSize } from '@dxos/lit-grid';
|
|
11
|
-
import {
|
|
9
|
+
import { type DxGridPlaneCells } from '@dxos/lit-grid';
|
|
10
|
+
import { random } from '@dxos/random';
|
|
12
11
|
import { DropdownMenu } from '@dxos/react-ui';
|
|
13
|
-
import {
|
|
14
|
-
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';
|
|
15
16
|
|
|
16
|
-
import { Grid, type
|
|
17
|
+
import { Grid, type GridContentProps, type GridEditing, type GridRootProps } from './Grid';
|
|
17
18
|
|
|
18
|
-
const storybookItems =
|
|
19
|
+
const storybookItems = random.helpers.uniqueArray(random.commerce.productName, 16);
|
|
19
20
|
|
|
20
21
|
type GridStoryProps = GridContentProps & Pick<GridRootProps, 'onEditingChange'>;
|
|
21
22
|
|
|
@@ -33,7 +34,7 @@ const GridStory = ({ initialCells, ...props }: GridStoryProps) => {
|
|
|
33
34
|
// Multiselect
|
|
34
35
|
const [popoverOpen, setPopoverOpen] = useState(false);
|
|
35
36
|
const [multiSelectValue, setInternalMultiselectValue] = useState('');
|
|
36
|
-
const setMultiselectValue = useCallback<NonNullable<
|
|
37
|
+
const setMultiselectValue = useCallback<NonNullable<ComboboxRootProps['onValueChange']>>((nextValue) => {
|
|
37
38
|
setInternalMultiselectValue(nextValue);
|
|
38
39
|
setCells((cells) => {
|
|
39
40
|
// TODO(burdon): How can we get the cell address to update?
|
|
@@ -64,7 +65,7 @@ const GridStory = ({ initialCells, ...props }: GridStoryProps) => {
|
|
|
64
65
|
}, []);
|
|
65
66
|
|
|
66
67
|
return (
|
|
67
|
-
<div
|
|
68
|
+
<div className='contents'>
|
|
68
69
|
<Grid.Root id='story' editing={editing} onEditingChange={handleEditingChange}>
|
|
69
70
|
{/* TODO(burdon): Why is this property not just "cells" or "values" */}
|
|
70
71
|
<Grid.Content {...props} initialCells={cells} onClick={handleClick} />
|
|
@@ -80,38 +81,52 @@ const GridStory = ({ initialCells, ...props }: GridStoryProps) => {
|
|
|
80
81
|
</DropdownMenu.Root>
|
|
81
82
|
|
|
82
83
|
{/* Multiselect */}
|
|
83
|
-
<
|
|
84
|
+
<Combobox.Root
|
|
84
85
|
open={popoverOpen}
|
|
85
86
|
onOpenChange={setPopoverOpen}
|
|
86
87
|
value={multiSelectValue}
|
|
87
88
|
onValueChange={setMultiselectValue}
|
|
88
89
|
>
|
|
89
|
-
<
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
<PopoverCombobox.List>
|
|
93
|
-
{storybookItems.map((value) => (
|
|
94
|
-
<PopoverCombobox.Item key={value}>{value}</PopoverCombobox.Item>
|
|
95
|
-
))}
|
|
96
|
-
</PopoverCombobox.List>
|
|
97
|
-
<PopoverCombobox.Arrow />
|
|
98
|
-
</PopoverCombobox.Content>
|
|
99
|
-
</PopoverCombobox.Root>
|
|
90
|
+
<Combobox.VirtualTrigger virtualRef={triggerRef} />
|
|
91
|
+
<ComboboxContentWithFiltering />
|
|
92
|
+
</Combobox.Root>
|
|
100
93
|
</div>
|
|
101
94
|
);
|
|
102
95
|
};
|
|
103
96
|
|
|
104
|
-
const
|
|
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
|
+
|
|
115
|
+
const meta = {
|
|
105
116
|
title: 'ui/react-ui-grid/Grid',
|
|
106
117
|
component: GridStory,
|
|
107
|
-
decorators: [withTheme],
|
|
108
|
-
parameters: {
|
|
109
|
-
|
|
118
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
119
|
+
parameters: {
|
|
120
|
+
layout: 'fullscreen',
|
|
121
|
+
},
|
|
122
|
+
} satisfies Meta<typeof GridStory>;
|
|
110
123
|
|
|
111
124
|
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,20 +2,19 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { createComponent, type EventName } from '@lit/react';
|
|
8
|
-
import { createContextScope, type Scope } from '@radix-ui/react-context';
|
|
5
|
+
import { type EventName, createComponent } from '@lit/react';
|
|
6
|
+
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
9
7
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
10
8
|
import React, {
|
|
11
9
|
type ComponentProps,
|
|
12
|
-
forwardRef,
|
|
13
10
|
type PropsWithChildren,
|
|
11
|
+
forwardRef,
|
|
14
12
|
useCallback,
|
|
15
13
|
useEffect,
|
|
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,
|
|
@@ -102,13 +104,13 @@ const GridRoot = ({
|
|
|
102
104
|
|
|
103
105
|
GridRoot.displayName = GRID_NAME;
|
|
104
106
|
|
|
107
|
+
const GRID_CONTENT_NAME = 'GridContent';
|
|
108
|
+
|
|
105
109
|
type GridContentProps = Omit<ComponentProps<typeof DxGrid>, 'onEdit'> & {
|
|
106
110
|
getCells?: NaturalDxGrid['getCells'];
|
|
107
111
|
activeRefs?: string;
|
|
108
112
|
};
|
|
109
113
|
|
|
110
|
-
const GRID_CONTENT_NAME = 'GridContent';
|
|
111
|
-
|
|
112
114
|
const GridContent = forwardRef<NaturalDxGrid, GridScopedProps<GridContentProps>>((props, forwardedRef) => {
|
|
113
115
|
const { id, editing, setEditBox, setEditing } = useGridContext(GRID_CONTENT_NAME, props.__gridScope);
|
|
114
116
|
const [dxGrid, setDxGridInternal] = useState<NaturalDxGrid | null>(null);
|
|
@@ -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
|
|
@@ -166,7 +168,7 @@ export const Grid = {
|
|
|
166
168
|
Content: GridContent,
|
|
167
169
|
};
|
|
168
170
|
|
|
169
|
-
export { GridRoot, GridContent,
|
|
171
|
+
export { GridRoot, GridContent, createGridScope, gridSeparatorInlineEnd, gridSeparatorBlockEnd, useGridContext };
|
|
170
172
|
|
|
171
173
|
export type { GridRootProps, GridContentProps, GridEditing, GridEditBox, GridScopedProps, DxGridElement };
|
|
172
174
|
|
|
@@ -178,6 +180,7 @@ export {
|
|
|
178
180
|
toPlaneCellIndex,
|
|
179
181
|
parseCellIndex,
|
|
180
182
|
cellQuery,
|
|
183
|
+
DxEditRequest,
|
|
181
184
|
} from '@dxos/lit-grid';
|
|
182
185
|
|
|
183
186
|
export type {
|