@dxos/react-ui-canvas 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731
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 +43 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +43 -5
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/CellGrid/CellGrid.d.ts +1 -1
- package/dist/types/src/components/CellGrid/CellGrid.d.ts.map +1 -1
- package/dist/types/src/components/CellGrid/input/pointer.d.ts +4 -0
- package/dist/types/src/components/CellGrid/input/pointer.d.ts.map +1 -1
- package/dist/types/src/components/CellGrid/state/types.d.ts +1 -1
- package/dist/types/src/components/CellGrid/state/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -14
- package/src/components/CellGrid/CellGrid.tsx +6 -2
- package/src/components/CellGrid/input/pointer.ts +29 -1
- package/src/components/CellGrid/state/types.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-canvas",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.d9fc60f731",
|
|
4
4
|
"description": "A canvas component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -31,30 +31,30 @@
|
|
|
31
31
|
"d3": "^7.9.0",
|
|
32
32
|
"react-resize-detector": "^11.0.1",
|
|
33
33
|
"transformation-matrix": "^2.16.1",
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/log": "0.8.4-main.
|
|
37
|
-
"@dxos/util": "0.8.4-main.
|
|
34
|
+
"@dxos/debug": "0.8.4-main.d9fc60f731",
|
|
35
|
+
"@dxos/invariant": "0.8.4-main.d9fc60f731",
|
|
36
|
+
"@dxos/log": "0.8.4-main.d9fc60f731",
|
|
37
|
+
"@dxos/util": "0.8.4-main.d9fc60f731"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/d3": "^7.4.3",
|
|
41
41
|
"@types/react": "~19.2.7",
|
|
42
42
|
"@types/react-dom": "~19.2.3",
|
|
43
|
-
"effect": "3.
|
|
43
|
+
"effect": "3.21.2",
|
|
44
44
|
"react": "~19.2.3",
|
|
45
45
|
"react-dom": "~19.2.3",
|
|
46
|
-
"vite": "^8.0.
|
|
47
|
-
"@dxos/random": "0.8.4-main.
|
|
48
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
49
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
50
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
46
|
+
"vite": "^8.0.14",
|
|
47
|
+
"@dxos/random": "0.8.4-main.d9fc60f731",
|
|
48
|
+
"@dxos/react-ui": "0.8.4-main.d9fc60f731",
|
|
49
|
+
"@dxos/storybook-utils": "0.8.4-main.d9fc60f731",
|
|
50
|
+
"@dxos/ui-theme": "0.8.4-main.d9fc60f731"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"effect": "3.
|
|
53
|
+
"effect": "3.21.2",
|
|
54
54
|
"react": "~19.2.3",
|
|
55
55
|
"react-dom": "~19.2.3",
|
|
56
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
57
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
56
|
+
"@dxos/react-ui": "0.8.4-main.d9fc60f731",
|
|
57
|
+
"@dxos/ui-theme": "0.8.4-main.d9fc60f731"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
|
@@ -67,6 +67,8 @@ export const CellGrid = <T,>({
|
|
|
67
67
|
classNames,
|
|
68
68
|
onCellToggle,
|
|
69
69
|
onSelectionCommit,
|
|
70
|
+
onDrawUpdate,
|
|
71
|
+
onDrawCommit,
|
|
70
72
|
}: CellGridProps<T>) => {
|
|
71
73
|
const registry = useContext(RegistryContext);
|
|
72
74
|
|
|
@@ -212,8 +214,8 @@ export const CellGrid = <T,>({
|
|
|
212
214
|
// across consumer re-renders — otherwise an in-progress drag is torn down when
|
|
213
215
|
// the parent's onCellToggle identity changes (e.g. after the very mutation we
|
|
214
216
|
// just triggered), and subsequent pointermove events see drag === null.
|
|
215
|
-
const callbacksRef = useRef<PointerHandlers>({ onCellToggle, onSelectionCommit });
|
|
216
|
-
callbacksRef.current = { onCellToggle, onSelectionCommit };
|
|
217
|
+
const callbacksRef = useRef<PointerHandlers>({ onCellToggle, onSelectionCommit, onDrawUpdate, onDrawCommit });
|
|
218
|
+
callbacksRef.current = { onCellToggle, onSelectionCommit, onDrawUpdate, onDrawCommit };
|
|
217
219
|
useEffect(() => {
|
|
218
220
|
const element = overlayInputRef.current;
|
|
219
221
|
if (!element) {
|
|
@@ -226,6 +228,8 @@ export const CellGrid = <T,>({
|
|
|
226
228
|
handlers: {
|
|
227
229
|
onCellToggle: (coord, mode) => callbacksRef.current.onCellToggle?.(coord, mode),
|
|
228
230
|
onSelectionCommit: (range) => callbacksRef.current.onSelectionCommit?.(range),
|
|
231
|
+
onDrawUpdate: (start, end) => callbacksRef.current.onDrawUpdate?.(start, end),
|
|
232
|
+
onDrawCommit: (start, end) => callbacksRef.current.onDrawCommit?.(start, end),
|
|
229
233
|
},
|
|
230
234
|
});
|
|
231
235
|
const detachWheel = attachWheelHandlers(element, { registry, atoms, headers });
|
|
@@ -19,10 +19,15 @@ export type ToggleMode = 'set' | 'unset' | 'toggle';
|
|
|
19
19
|
export type PointerHandlers = {
|
|
20
20
|
onCellToggle?: (coord: CellCoord, mode: ToggleMode) => void;
|
|
21
21
|
onSelectionCommit?: (range: SelectionRange) => void;
|
|
22
|
+
/** Called each time the draw cursor moves to a new cell (edit tool). */
|
|
23
|
+
onDrawUpdate?: (startCoord: CellCoord, endCoord: CellCoord) => void;
|
|
24
|
+
/** Called when the user releases after an edit-tool drag; caller commits the note. */
|
|
25
|
+
onDrawCommit?: (startCoord: CellCoord, endCoord: CellCoord) => void;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
type DragState =
|
|
25
29
|
| { kind: 'toggle'; mode: 'set' | 'unset'; touched: Set<string> }
|
|
30
|
+
| { kind: 'draw'; startCoord: CellCoord; endCoord: CellCoord }
|
|
26
31
|
| { kind: 'select'; origin: CellCoord }
|
|
27
32
|
| { kind: 'pan'; lastX: number; lastY: number };
|
|
28
33
|
|
|
@@ -94,6 +99,20 @@ export const attachPointerHandlers = <T>(
|
|
|
94
99
|
drag = { kind: 'toggle', mode, touched: new Set([key]) };
|
|
95
100
|
break;
|
|
96
101
|
}
|
|
102
|
+
case 'edit': {
|
|
103
|
+
// Start a draw gesture: track extent and fire preview/commit callbacks
|
|
104
|
+
// instead of toggling individual cells. Constrained to the starting row.
|
|
105
|
+
drag = { kind: 'draw', startCoord: coord, endCoord: coord };
|
|
106
|
+
handlers.onDrawUpdate?.(coord, coord);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'delete': {
|
|
110
|
+
// Always removes notes regardless of current cell state.
|
|
111
|
+
const key = cellKey(coord.col, coord.row);
|
|
112
|
+
handlers.onCellToggle?.(coord, 'unset');
|
|
113
|
+
drag = { kind: 'toggle', mode: 'unset', touched: new Set([key]) };
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
97
116
|
case 'select': {
|
|
98
117
|
drag = { kind: 'select', origin: coord };
|
|
99
118
|
registry.set(atoms.selection, {
|
|
@@ -135,6 +154,13 @@ export const attachPointerHandlers = <T>(
|
|
|
135
154
|
drag.touched.add(key);
|
|
136
155
|
handlers.onCellToggle?.(coord, drag.mode);
|
|
137
156
|
}
|
|
157
|
+
} else if (drag.kind === 'draw') {
|
|
158
|
+
// Constrain to the starting row so the note stays at the same pitch.
|
|
159
|
+
const constrainedCol = coord.col;
|
|
160
|
+
if (constrainedCol !== drag.endCoord.col) {
|
|
161
|
+
drag.endCoord = { col: constrainedCol, row: drag.startCoord.row };
|
|
162
|
+
handlers.onDrawUpdate?.(drag.startCoord, drag.endCoord);
|
|
163
|
+
}
|
|
138
164
|
} else if (drag.kind === 'select') {
|
|
139
165
|
registry.set(atoms.selection, {
|
|
140
166
|
range: { col0: drag.origin.col, row0: drag.origin.row, col1: coord.col, row1: coord.row },
|
|
@@ -152,7 +178,9 @@ export const attachPointerHandlers = <T>(
|
|
|
152
178
|
if (!drag) {
|
|
153
179
|
return;
|
|
154
180
|
}
|
|
155
|
-
if (drag.kind === '
|
|
181
|
+
if (drag.kind === 'draw') {
|
|
182
|
+
handlers.onDrawCommit?.(drag.startCoord, drag.endCoord);
|
|
183
|
+
} else if (drag.kind === 'select') {
|
|
156
184
|
const range = registry.get(atoms.selection).range;
|
|
157
185
|
if (range) {
|
|
158
186
|
handlers.onSelectionCommit?.(range);
|