@dxos/react-ui-mosaic 0.8.4-main.ef1bc66f44 → 0.8.4-main.fcfe5033a5
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/chunk-33NNDFD6.mjs +1008 -0
- package/dist/lib/browser/chunk-33NNDFD6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +377 -206
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/playwright/index.mjs +148 -0
- package/dist/lib/browser/playwright/index.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +56 -33
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-Y4LG7O67.mjs +1010 -0
- package/dist/lib/node-esm/chunk-Y4LG7O67.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +377 -206
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/playwright/index.mjs +150 -0
- package/dist/lib/node-esm/playwright/index.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +56 -33
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Board/Board.d.ts +42 -27
- package/dist/types/src/components/Board/Board.d.ts.map +1 -1
- package/dist/types/src/components/Board/Board.stories.d.ts +10 -4
- package/dist/types/src/components/Board/Board.stories.d.ts.map +1 -1
- package/dist/types/src/components/Board/Column.d.ts +31 -20
- package/dist/types/src/components/Board/Column.d.ts.map +1 -1
- package/dist/types/src/components/Board/Item.d.ts +5 -2
- package/dist/types/src/components/Board/Item.d.ts.map +1 -1
- package/dist/types/src/components/Focus/Focus.d.ts +1 -25
- package/dist/types/src/components/Focus/Focus.d.ts.map +1 -1
- package/dist/types/src/components/Focus/index.d.ts +0 -1
- package/dist/types/src/components/Focus/index.d.ts.map +1 -1
- package/dist/types/src/components/Mosaic/Container.d.ts +45 -0
- package/dist/types/src/components/Mosaic/Container.d.ts.map +1 -0
- package/dist/types/src/components/Mosaic/Mosaic.d.ts +31 -120
- package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -1
- package/dist/types/src/components/Mosaic/Placeholder.d.ts +21 -0
- package/dist/types/src/components/Mosaic/Placeholder.d.ts.map +1 -0
- package/dist/types/src/components/Mosaic/Root.d.ts +35 -0
- package/dist/types/src/components/Mosaic/Root.d.ts.map +1 -0
- package/dist/types/src/components/Mosaic/Stack.d.ts +24 -0
- package/dist/types/src/components/Mosaic/Stack.d.ts.map +1 -0
- package/dist/types/src/components/Mosaic/Stack.stories.d.ts +20 -0
- package/dist/types/src/components/Mosaic/Stack.stories.d.ts.map +1 -0
- package/dist/types/src/components/Mosaic/Tile.d.ts +53 -0
- package/dist/types/src/components/Mosaic/Tile.d.ts.map +1 -0
- package/dist/types/src/components/Mosaic/types.d.ts +9 -0
- package/dist/types/src/components/Mosaic/types.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useDefaultColumnEventHandler.d.ts +15 -0
- package/dist/types/src/hooks/useDefaultColumnEventHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useEventHandlerAdapter.d.ts +1 -1
- package/dist/types/src/hooks/useEventHandlerAdapter.d.ts.map +1 -1
- package/dist/types/src/hooks/useVisibleItems.d.ts +2 -2
- package/dist/types/src/hooks/useVisibleItems.d.ts.map +1 -1
- package/dist/types/src/playwright/board-manager.d.ts +45 -0
- package/dist/types/src/playwright/board-manager.d.ts.map +1 -0
- package/dist/types/src/playwright/index.d.ts +9 -0
- package/dist/types/src/playwright/index.d.ts.map +1 -0
- package/dist/types/src/playwright/playwright.config.d.ts +3 -0
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
- package/dist/types/src/playwright/smoke.spec.d.ts +2 -0
- package/dist/types/src/playwright/smoke.spec.d.ts.map +1 -0
- package/dist/types/src/testing/CardContainer.d.ts +4 -3
- package/dist/types/src/testing/CardContainer.d.ts.map +1 -1
- package/dist/types/src/testing/DefaultStackTile.d.ts +2 -2
- package/dist/types/src/testing/DefaultStackTile.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -26
- package/src/AUDIT.md +106 -0
- package/src/components/Board/Board.stories.tsx +157 -43
- package/src/components/Board/Board.tsx +95 -71
- package/src/components/Board/Column.tsx +171 -123
- package/src/components/Board/Item.tsx +78 -43
- package/src/components/Focus/Focus.tsx +2 -91
- package/src/components/Focus/index.ts +0 -2
- package/src/components/Mosaic/Container.tsx +315 -0
- package/src/components/Mosaic/Mosaic.tsx +35 -914
- package/src/components/Mosaic/Placeholder.tsx +133 -0
- package/src/components/Mosaic/Root.tsx +286 -0
- package/src/components/Mosaic/Stack.stories.tsx +175 -0
- package/src/components/Mosaic/Stack.tsx +341 -0
- package/src/components/Mosaic/Tile.tsx +247 -0
- package/src/components/Mosaic/extension.ts +1 -1
- package/src/components/Mosaic/styles.ts +8 -8
- package/src/components/Mosaic/types.ts +16 -0
- package/src/components/index.ts +0 -3
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useContainerDebug.tsx +1 -1
- package/src/hooks/useDefaultColumnEventHandler.ts +34 -0
- package/src/hooks/useEventHandlerAdapter.ts +15 -6
- package/src/hooks/useVisibleItems.ts +7 -2
- package/src/playwright/board-manager.ts +159 -0
- package/src/playwright/index.ts +13 -0
- package/src/playwright/playwright.config.ts +17 -0
- package/src/playwright/smoke.spec.ts +143 -0
- package/src/testing/CardContainer.tsx +23 -16
- package/src/testing/DefaultStackTile.tsx +36 -22
- package/src/testing/types.ts +4 -4
- package/src/translations.ts +3 -2
- package/dist/lib/browser/chunk-Y6GU2CCU.mjs +0 -1478
- package/dist/lib/browser/chunk-Y6GU2CCU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KTLFCRVA.mjs +0 -1480
- package/dist/lib/node-esm/chunk-KTLFCRVA.mjs.map +0 -7
- package/dist/types/src/components/Card/Card.d.ts +0 -123
- package/dist/types/src/components/Card/Card.d.ts.map +0 -1
- package/dist/types/src/components/Card/Card.stories.d.ts +0 -21
- package/dist/types/src/components/Card/Card.stories.d.ts.map +0 -1
- package/dist/types/src/components/Card/CardDragPreview.d.ts +0 -6
- package/dist/types/src/components/Card/CardDragPreview.d.ts.map +0 -1
- package/dist/types/src/components/Card/index.d.ts +0 -4
- package/dist/types/src/components/Card/index.d.ts.map +0 -1
- package/dist/types/src/components/Card/styles.d.ts +0 -13
- package/dist/types/src/components/Card/styles.d.ts.map +0 -1
- package/dist/types/src/components/Focus/styles.d.ts +0 -6
- package/dist/types/src/components/Focus/styles.d.ts.map +0 -1
- package/dist/types/src/components/Image/Image.d.ts +0 -14
- package/dist/types/src/components/Image/Image.d.ts.map +0 -1
- package/dist/types/src/components/Image/Image.stories.d.ts +0 -33
- package/dist/types/src/components/Image/Image.stories.d.ts.map +0 -1
- package/dist/types/src/components/Image/index.d.ts +0 -2
- package/dist/types/src/components/Image/index.d.ts.map +0 -1
- package/dist/types/src/components/Stack/Stack.d.ts +0 -22
- package/dist/types/src/components/Stack/Stack.d.ts.map +0 -1
- package/dist/types/src/components/Stack/Stack.stories.d.ts +0 -9
- package/dist/types/src/components/Stack/Stack.stories.d.ts.map +0 -1
- package/dist/types/src/components/Stack/index.d.ts +0 -2
- package/dist/types/src/components/Stack/index.d.ts.map +0 -1
- package/dist/types/src/components/Stack/virtualizer.stories.d.ts +0 -12
- package/dist/types/src/components/Stack/virtualizer.stories.d.ts.map +0 -1
- package/src/components/Card/Card.stories.tsx +0 -148
- package/src/components/Card/Card.tsx +0 -458
- package/src/components/Card/CardDragPreview.tsx +0 -23
- package/src/components/Card/index.ts +0 -8
- package/src/components/Card/styles.ts +0 -23
- package/src/components/Focus/styles.ts +0 -21
- package/src/components/Image/Image.stories.tsx +0 -86
- package/src/components/Image/Image.tsx +0 -223
- package/src/components/Image/index.ts +0 -5
- package/src/components/Stack/Stack.stories.tsx +0 -119
- package/src/components/Stack/Stack.tsx +0 -219
- package/src/components/Stack/index.ts +0 -5
- package/src/components/Stack/virtualizer.stories.tsx +0 -143
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
// src/hooks/useVisibleItems.ts
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
var useVisibleItems = ({ id, items, dragging, getId }) => {
|
|
4
|
+
const visibleItems = useMemo(() => {
|
|
5
|
+
if (!items || !dragging || id !== dragging.containerId) {
|
|
6
|
+
return items ?? [];
|
|
7
|
+
}
|
|
8
|
+
const idx = items.findIndex((item) => getId(item) === dragging.id);
|
|
9
|
+
if (idx === -1) {
|
|
10
|
+
return items;
|
|
11
|
+
}
|
|
12
|
+
const visibleItems2 = items.slice();
|
|
13
|
+
visibleItems2.splice(idx, 1);
|
|
14
|
+
return visibleItems2;
|
|
15
|
+
}, [
|
|
16
|
+
id,
|
|
17
|
+
items,
|
|
18
|
+
dragging,
|
|
19
|
+
getId
|
|
20
|
+
]);
|
|
21
|
+
return visibleItems;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/components/Focus/Focus.tsx
|
|
25
|
+
import { Focus, useFocus } from "@dxos/react-ui";
|
|
26
|
+
|
|
27
|
+
// src/components/Mosaic/styles.ts
|
|
28
|
+
var styles = {
|
|
29
|
+
placeholder: {
|
|
30
|
+
root: [
|
|
31
|
+
"group opacity-0",
|
|
32
|
+
'group-data-[mosaic-debug="true"]:opacity-100',
|
|
33
|
+
'group-data-[mosaic-debug="true"]:bg-orange-500',
|
|
34
|
+
"data-[mosaic-placeholder-state=active]:opacity-100",
|
|
35
|
+
"data-[mosaic-placeholder-orientation=vertical]:snap-start",
|
|
36
|
+
"data-[mosaic-placeholder-orientation=vertical]:py-1",
|
|
37
|
+
"data-[mosaic-placeholder-orientation=vertical]:data-[mosaic-placeholder-state=active]:py-2.5",
|
|
38
|
+
"data-[mosaic-placeholder-orientation=horizontal]:px-1",
|
|
39
|
+
"data-[mosaic-placeholder-orientation=horizontal]:data-[mosaic-placeholder-state=active]:px-2.5"
|
|
40
|
+
],
|
|
41
|
+
content: [
|
|
42
|
+
"transition-all duration-0",
|
|
43
|
+
// TODO(burdon): Don't animate open if placeholder is the source.
|
|
44
|
+
// TODO(burdon): Flickers when start to drag since source is removed and then the placeholder shows up.
|
|
45
|
+
// - Use absolute positioning?
|
|
46
|
+
// 'group-data-[mosaic-placeholder-state=active]:duration-200',
|
|
47
|
+
"group-data-[mosaic-placeholder-orientation=vertical]:h-0",
|
|
48
|
+
"group-data-[mosaic-placeholder-orientation=vertical]:group-data-[mosaic-placeholder-state=active]:h-[var(--mosaic-placeholder-height)]",
|
|
49
|
+
"group-data-[mosaic-placeholder-orientation=horizontal]:w-0",
|
|
50
|
+
"group-data-[mosaic-placeholder-orientation=horizontal]:group-data-[mosaic-placeholder-state=active]:w-[var(--mosaic-placeholder-width)]"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/components/Mosaic/types.ts
|
|
56
|
+
var getSourceData = (source) => {
|
|
57
|
+
return source.data.type === "tile" ? source.data : null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/components/Mosaic/Root.tsx
|
|
61
|
+
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
62
|
+
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
63
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
64
|
+
import { createContext } from "@radix-ui/react-context";
|
|
65
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
66
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
67
|
+
import React, { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
68
|
+
import { log } from "@dxos/log";
|
|
69
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Root.tsx";
|
|
70
|
+
var [MosaicRootContextProvider, useMosaicRootContext] = createContext("MosaicRoot");
|
|
71
|
+
var MOSAIC_ROOT_NAME = "Mosaic.Root";
|
|
72
|
+
var MOSAIC_ROOT_DEBUG_ATTR = "mosaic-debug";
|
|
73
|
+
var MosaicRoot = /* @__PURE__ */ forwardRef(({ children, asChild, debug }, forwardedRef) => {
|
|
74
|
+
const rootRef = useRef(null);
|
|
75
|
+
const composedRef = useComposedRefs(rootRef, forwardedRef);
|
|
76
|
+
const Comp = asChild ? Slot : Primitive.div;
|
|
77
|
+
const [handlers, setHandlers] = useState({});
|
|
78
|
+
const [dragging, setDragging] = useState();
|
|
79
|
+
const getSourceHandler = useCallback((source) => {
|
|
80
|
+
const data = source.data;
|
|
81
|
+
return {
|
|
82
|
+
data,
|
|
83
|
+
handler: handlers[data.containerId]
|
|
84
|
+
};
|
|
85
|
+
}, [
|
|
86
|
+
handlers
|
|
87
|
+
]);
|
|
88
|
+
const getTargetHandler = useCallback((location) => {
|
|
89
|
+
for (const target of location.current.dropTargets) {
|
|
90
|
+
const data = target.data;
|
|
91
|
+
let containerId;
|
|
92
|
+
switch (data.type) {
|
|
93
|
+
case "tile":
|
|
94
|
+
case "placeholder":
|
|
95
|
+
containerId = data.containerId;
|
|
96
|
+
break;
|
|
97
|
+
case "container":
|
|
98
|
+
containerId = data.id;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const handler = handlers[containerId];
|
|
102
|
+
if (handler) {
|
|
103
|
+
return {
|
|
104
|
+
data,
|
|
105
|
+
handler
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {};
|
|
110
|
+
}, [
|
|
111
|
+
handlers
|
|
112
|
+
]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const handleChange = ({ source, location }) => {
|
|
115
|
+
const { data: sourceData } = getSourceHandler(source);
|
|
116
|
+
const { data: targetData, handler } = getTargetHandler(location);
|
|
117
|
+
setDragging((dragging2) => {
|
|
118
|
+
dragging2?.target?.handler?.onCancel?.();
|
|
119
|
+
return {
|
|
120
|
+
source: {
|
|
121
|
+
data: sourceData,
|
|
122
|
+
handler: handlers[sourceData.containerId],
|
|
123
|
+
// TODO(burdon): Check id matches.
|
|
124
|
+
container: location.initial.dropTargets.find((target) => target.data.type === "container")?.element
|
|
125
|
+
},
|
|
126
|
+
target: targetData && {
|
|
127
|
+
data: targetData,
|
|
128
|
+
handler
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const handleCancel = () => {
|
|
134
|
+
setDragging((dragging2) => {
|
|
135
|
+
requestAnimationFrame(() => {
|
|
136
|
+
dragging2?.target?.handler?.onCancel?.();
|
|
137
|
+
dragging2?.source?.container?.dispatchEvent(new CustomEvent("dnd:cancel", {
|
|
138
|
+
bubbles: true
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
141
|
+
return void 0;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
let noTargetTimeout;
|
|
145
|
+
return combine(monitorForElements({
|
|
146
|
+
/**
|
|
147
|
+
* Dragging started within any container.
|
|
148
|
+
*/
|
|
149
|
+
onDragStart: ({ source, location }) => {
|
|
150
|
+
log("Root.onDragStart", {
|
|
151
|
+
source: source.data,
|
|
152
|
+
location: location.current.dropTargets.map((target) => target.data)
|
|
153
|
+
}, {
|
|
154
|
+
F: __dxlog_file,
|
|
155
|
+
L: 144,
|
|
156
|
+
S: void 0,
|
|
157
|
+
C: (f, a) => f(...a)
|
|
158
|
+
});
|
|
159
|
+
handleChange({
|
|
160
|
+
source,
|
|
161
|
+
location
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Dragging entered a new container.
|
|
166
|
+
*/
|
|
167
|
+
onDropTargetChange: ({ source, location }) => {
|
|
168
|
+
clearTimeout(noTargetTimeout);
|
|
169
|
+
log("Root.onDropTargetChange", {
|
|
170
|
+
source: source.data,
|
|
171
|
+
location: location.current.dropTargets.map((target) => target.data)
|
|
172
|
+
}, {
|
|
173
|
+
F: __dxlog_file,
|
|
174
|
+
L: 157,
|
|
175
|
+
S: void 0,
|
|
176
|
+
C: (f, a) => f(...a)
|
|
177
|
+
});
|
|
178
|
+
if (location.current.dropTargets.length === 0) {
|
|
179
|
+
noTargetTimeout = setTimeout(() => setDragging(void 0), 1e3);
|
|
180
|
+
} else {
|
|
181
|
+
handleChange({
|
|
182
|
+
source,
|
|
183
|
+
location
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* Dragging within any container.
|
|
189
|
+
*/
|
|
190
|
+
onDrag: ({ source, location }) => {
|
|
191
|
+
const { data } = getSourceHandler(source);
|
|
192
|
+
const { handler } = getTargetHandler(location);
|
|
193
|
+
if (handler) {
|
|
194
|
+
const { clientX: x, clientY: y } = location.current.input;
|
|
195
|
+
handler.onDrag?.({
|
|
196
|
+
source: data,
|
|
197
|
+
position: {
|
|
198
|
+
x,
|
|
199
|
+
y
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
/**
|
|
205
|
+
* Dragging ended.
|
|
206
|
+
*/
|
|
207
|
+
onDrop: ({ source, location }) => {
|
|
208
|
+
log.info("Root.onDrop", {
|
|
209
|
+
source: source.data,
|
|
210
|
+
location: location.current.dropTargets.map((target) => target.data)
|
|
211
|
+
}, {
|
|
212
|
+
F: __dxlog_file,
|
|
213
|
+
L: 186,
|
|
214
|
+
S: void 0,
|
|
215
|
+
C: (f, a) => f(...a)
|
|
216
|
+
});
|
|
217
|
+
const { data: sourceData, handler: sourceHandler } = getSourceHandler(source);
|
|
218
|
+
if (!sourceHandler) {
|
|
219
|
+
log.warn("invalid source", {
|
|
220
|
+
source: sourceData,
|
|
221
|
+
handlers: Object.keys(handlers)
|
|
222
|
+
}, {
|
|
223
|
+
F: __dxlog_file,
|
|
224
|
+
L: 194,
|
|
225
|
+
S: void 0,
|
|
226
|
+
C: (f, a) => f(...a)
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
if (location.current.dropTargets.length === 0) {
|
|
232
|
+
log.info("cancelled", void 0, {
|
|
233
|
+
F: __dxlog_file,
|
|
234
|
+
L: 209,
|
|
235
|
+
S: void 0,
|
|
236
|
+
C: (f, a) => f(...a)
|
|
237
|
+
});
|
|
238
|
+
} else {
|
|
239
|
+
const { data: targetData, handler: targetHandler } = getTargetHandler(location);
|
|
240
|
+
if (!targetHandler) {
|
|
241
|
+
log.warn("invalid target", {
|
|
242
|
+
source: sourceData,
|
|
243
|
+
location,
|
|
244
|
+
handlers: Object.keys(handlers)
|
|
245
|
+
}, {
|
|
246
|
+
F: __dxlog_file,
|
|
247
|
+
L: 214,
|
|
248
|
+
S: void 0,
|
|
249
|
+
C: (f, a) => f(...a)
|
|
250
|
+
});
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (sourceHandler === targetHandler) {
|
|
254
|
+
targetHandler.onDrop?.({
|
|
255
|
+
source: sourceData,
|
|
256
|
+
target: targetData
|
|
257
|
+
});
|
|
258
|
+
} else {
|
|
259
|
+
if (!sourceHandler.onTake) {
|
|
260
|
+
log.warn("invalid source", {
|
|
261
|
+
source: sourceData
|
|
262
|
+
}, {
|
|
263
|
+
F: __dxlog_file,
|
|
264
|
+
L: 230,
|
|
265
|
+
S: void 0,
|
|
266
|
+
C: (f, a) => f(...a)
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
sourceHandler.onTake?.({
|
|
271
|
+
source: sourceData
|
|
272
|
+
}, async (object) => {
|
|
273
|
+
targetHandler.onDrop?.({
|
|
274
|
+
source: {
|
|
275
|
+
...sourceData,
|
|
276
|
+
data: object
|
|
277
|
+
},
|
|
278
|
+
target: targetData
|
|
279
|
+
});
|
|
280
|
+
return true;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} finally {
|
|
285
|
+
handleCancel();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}));
|
|
289
|
+
}, [
|
|
290
|
+
handlers,
|
|
291
|
+
getSourceHandler,
|
|
292
|
+
getTargetHandler
|
|
293
|
+
]);
|
|
294
|
+
return /* @__PURE__ */ React.createElement(MosaicRootContextProvider, {
|
|
295
|
+
containers: handlers,
|
|
296
|
+
addContainer: (container) => setHandlers((containers) => ({
|
|
297
|
+
...containers,
|
|
298
|
+
[container.id]: container
|
|
299
|
+
})),
|
|
300
|
+
removeContainer: (id) => setHandlers((containers) => {
|
|
301
|
+
delete containers[id];
|
|
302
|
+
return {
|
|
303
|
+
...containers
|
|
304
|
+
};
|
|
305
|
+
}),
|
|
306
|
+
dragging
|
|
307
|
+
}, /* @__PURE__ */ React.createElement(Comp, {
|
|
308
|
+
className: "contents group",
|
|
309
|
+
[`data-${MOSAIC_ROOT_DEBUG_ATTR}`]: debug,
|
|
310
|
+
ref: composedRef
|
|
311
|
+
}, children));
|
|
312
|
+
});
|
|
313
|
+
MosaicRoot.displayName = MOSAIC_ROOT_NAME;
|
|
314
|
+
|
|
315
|
+
// src/components/Mosaic/Container.tsx
|
|
316
|
+
import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
|
|
317
|
+
import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
318
|
+
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
319
|
+
import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
|
|
320
|
+
import { createContext as createContext2 } from "@radix-ui/react-context";
|
|
321
|
+
import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
|
|
322
|
+
import { Slot as Slot2 } from "@radix-ui/react-slot";
|
|
323
|
+
import { bind } from "bind-event-listener";
|
|
324
|
+
import React2, { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
325
|
+
import { composable, composableProps } from "@dxos/ui-theme";
|
|
326
|
+
import { isTruthy } from "@dxos/util";
|
|
327
|
+
var MOSAIC_CONTAINER_NAME = "Mosaic.Container";
|
|
328
|
+
var [MosaicContainerContextProvider, useMosaicContainerContext] = createContext2("MosaicContainer");
|
|
329
|
+
var MOSAIC_CONTAINER_STATE_ATTR = "mosaic-container-state";
|
|
330
|
+
var MOSAIC_CONTAINER_PLACEHOLDER_WIDTH = "--mosaic-placeholder-width";
|
|
331
|
+
var MOSAIC_CONTAINER_PLACEHOLDER_HEIGHT = "--mosaic-placeholder-height";
|
|
332
|
+
var counter = 0;
|
|
333
|
+
var MosaicContainer = composable(({ children, eventHandler: eventHandlerProp, orientation = "vertical", asChild, autoScroll: autoscrollElement, withFocus, currentId, onCurrentChange, debug, ...props }, forwardedRef) => {
|
|
334
|
+
const Comp = asChild ? Slot2 : Primitive2.div;
|
|
335
|
+
const rootRef = useRef2(null);
|
|
336
|
+
const composedRef = useComposedRefs2(rootRef, forwardedRef);
|
|
337
|
+
const eventHandler = useMemo2(() => eventHandlerProp ?? {
|
|
338
|
+
id: `mosaic-container-${counter++}`
|
|
339
|
+
}, [
|
|
340
|
+
eventHandlerProp
|
|
341
|
+
]);
|
|
342
|
+
const { dragging } = useMosaicRootContext(MOSAIC_CONTAINER_NAME);
|
|
343
|
+
const [state, setState] = useState2({
|
|
344
|
+
type: "idle"
|
|
345
|
+
});
|
|
346
|
+
const [activeLocation, setActiveLocation] = useState2();
|
|
347
|
+
const [scrolling, setScrolling] = useState2(false);
|
|
348
|
+
const setCurrentId = useCallback2((id) => onCurrentChange?.(id), [
|
|
349
|
+
onCurrentChange
|
|
350
|
+
]);
|
|
351
|
+
const scrollToRef = useRef2(void 0);
|
|
352
|
+
const registerScrollTo = useCallback2((fn) => {
|
|
353
|
+
scrollToRef.current = fn;
|
|
354
|
+
}, []);
|
|
355
|
+
useEffect2(() => {
|
|
356
|
+
if (currentId) {
|
|
357
|
+
scrollToRef.current?.(currentId);
|
|
358
|
+
}
|
|
359
|
+
}, [
|
|
360
|
+
currentId
|
|
361
|
+
]);
|
|
362
|
+
const { setFocus } = useFocus();
|
|
363
|
+
useEffect2(() => {
|
|
364
|
+
if (withFocus) {
|
|
365
|
+
setFocus?.(state.type === "active" ? "active" : void 0);
|
|
366
|
+
}
|
|
367
|
+
}, [
|
|
368
|
+
setFocus,
|
|
369
|
+
withFocus,
|
|
370
|
+
state
|
|
371
|
+
]);
|
|
372
|
+
const { addContainer, removeContainer } = useMosaicRootContext(eventHandler.id);
|
|
373
|
+
useEffect2(() => {
|
|
374
|
+
addContainer(eventHandler);
|
|
375
|
+
return () => removeContainer(eventHandler.id);
|
|
376
|
+
}, [
|
|
377
|
+
eventHandler
|
|
378
|
+
]);
|
|
379
|
+
const data = useMemo2(() => ({
|
|
380
|
+
type: "container",
|
|
381
|
+
id: eventHandler.id
|
|
382
|
+
}), [
|
|
383
|
+
eventHandler.id
|
|
384
|
+
]);
|
|
385
|
+
useEffect2(() => {
|
|
386
|
+
if (!rootRef.current) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
let timeout;
|
|
390
|
+
const handleScroll = () => {
|
|
391
|
+
setScrolling(true);
|
|
392
|
+
clearTimeout(timeout);
|
|
393
|
+
timeout = setTimeout(() => {
|
|
394
|
+
setScrolling(false);
|
|
395
|
+
}, 500);
|
|
396
|
+
};
|
|
397
|
+
return combine2(...[
|
|
398
|
+
/**
|
|
399
|
+
* Custom event for dragging cancellation.
|
|
400
|
+
*/
|
|
401
|
+
bind(rootRef.current, {
|
|
402
|
+
type: "dnd:cancel",
|
|
403
|
+
listener: () => {
|
|
404
|
+
setState({
|
|
405
|
+
type: "idle"
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}),
|
|
409
|
+
// Target.
|
|
410
|
+
dropTargetForElements({
|
|
411
|
+
element: rootRef.current,
|
|
412
|
+
getData: () => data,
|
|
413
|
+
/**
|
|
414
|
+
* Test if permitted to drop here.
|
|
415
|
+
* NOTE: Contained Tile and Placeholder elements do the same.
|
|
416
|
+
*/
|
|
417
|
+
canDrop: ({ source }) => {
|
|
418
|
+
const data2 = getSourceData(source);
|
|
419
|
+
return data2 && eventHandler.canDrop?.({
|
|
420
|
+
source: data2
|
|
421
|
+
}) || false;
|
|
422
|
+
},
|
|
423
|
+
// TODO(burdon): Provide semantic intent to onDrop.
|
|
424
|
+
// getDropEffect: () => {
|
|
425
|
+
// return 'move';
|
|
426
|
+
// },
|
|
427
|
+
/**
|
|
428
|
+
* Dragging started in this container.
|
|
429
|
+
*/
|
|
430
|
+
onDragStart: ({ source }) => {
|
|
431
|
+
const sourceData = source.data;
|
|
432
|
+
setState({
|
|
433
|
+
type: "active",
|
|
434
|
+
bounds: sourceData.bounds
|
|
435
|
+
});
|
|
436
|
+
},
|
|
437
|
+
/**
|
|
438
|
+
* Dragging entered this container.
|
|
439
|
+
*/
|
|
440
|
+
onDragEnter: ({ source }) => {
|
|
441
|
+
const sourceData = source.data;
|
|
442
|
+
setState({
|
|
443
|
+
type: "active",
|
|
444
|
+
bounds: sourceData.bounds
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* Dragging left this container.
|
|
449
|
+
* NOTE: If the container isn't full-height, then when the dragged item is temporarily removed the container will shrink,
|
|
450
|
+
* triggering `onDragLeave`, which then causes the item to be added and removed continually (flickering).
|
|
451
|
+
*/
|
|
452
|
+
onDragLeave: ({ source }) => {
|
|
453
|
+
const sourceData = source.data;
|
|
454
|
+
if (sourceData.containerId !== eventHandler.id) {
|
|
455
|
+
setState({
|
|
456
|
+
type: "idle"
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
/**
|
|
461
|
+
* Dropped in this container.
|
|
462
|
+
*/
|
|
463
|
+
onDrop: () => {
|
|
464
|
+
setState({
|
|
465
|
+
type: "idle"
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}),
|
|
469
|
+
// Autoscroll.
|
|
470
|
+
// NOTE: When used with Scrollable we get a spurious warning (in dev mode).
|
|
471
|
+
// "Auto scrolling has been attached to an element that appears not to be scrollable."
|
|
472
|
+
autoscrollElement && [
|
|
473
|
+
autoScrollForElements({
|
|
474
|
+
element: autoscrollElement,
|
|
475
|
+
// canScroll: ({ element: _ }) => {
|
|
476
|
+
// return true;
|
|
477
|
+
// },
|
|
478
|
+
getAllowedAxis: () => orientation,
|
|
479
|
+
getConfiguration: () => ({
|
|
480
|
+
maxScrollSpeed: "fast"
|
|
481
|
+
})
|
|
482
|
+
}),
|
|
483
|
+
bind(autoscrollElement, {
|
|
484
|
+
type: "scroll",
|
|
485
|
+
listener: handleScroll
|
|
486
|
+
}),
|
|
487
|
+
() => setScrolling(false)
|
|
488
|
+
]
|
|
489
|
+
].filter(isTruthy).flatMap((x) => x));
|
|
490
|
+
}, [
|
|
491
|
+
rootRef,
|
|
492
|
+
eventHandler,
|
|
493
|
+
data,
|
|
494
|
+
autoscrollElement
|
|
495
|
+
]);
|
|
496
|
+
return /* @__PURE__ */ React2.createElement(MosaicContainerContextProvider, {
|
|
497
|
+
id: eventHandler.id,
|
|
498
|
+
eventHandler,
|
|
499
|
+
orientation,
|
|
500
|
+
state,
|
|
501
|
+
dragging: state.type === "active" ? dragging : void 0,
|
|
502
|
+
scrolling,
|
|
503
|
+
activeLocation,
|
|
504
|
+
setActiveLocation,
|
|
505
|
+
currentId,
|
|
506
|
+
setCurrentId,
|
|
507
|
+
registerScrollTo
|
|
508
|
+
}, /* @__PURE__ */ React2.createElement(Comp, {
|
|
509
|
+
...composableProps(props, {
|
|
510
|
+
classNames: "h-full",
|
|
511
|
+
style: {
|
|
512
|
+
[MOSAIC_CONTAINER_PLACEHOLDER_WIDTH]: state.type === "active" && state.bounds ? `${state.bounds.width}px` : "0px",
|
|
513
|
+
[MOSAIC_CONTAINER_PLACEHOLDER_HEIGHT]: state.type === "active" && state.bounds ? `${state.bounds.height}px` : "0px"
|
|
514
|
+
}
|
|
515
|
+
}),
|
|
516
|
+
[`data-${MOSAIC_CONTAINER_STATE_ATTR}`]: state.type,
|
|
517
|
+
ref: composedRef
|
|
518
|
+
}, children), debug?.());
|
|
519
|
+
});
|
|
520
|
+
MosaicContainer.displayName = MOSAIC_CONTAINER_NAME;
|
|
521
|
+
|
|
522
|
+
// src/components/Mosaic/Tile.tsx
|
|
523
|
+
import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
524
|
+
import { combine as combine3 } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
525
|
+
import { draggable, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
526
|
+
import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
|
|
527
|
+
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
528
|
+
import { composeRefs } from "@radix-ui/react-compose-refs";
|
|
529
|
+
import { createContext as createContext3 } from "@radix-ui/react-context";
|
|
530
|
+
import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
|
|
531
|
+
import { Slot as Slot3 } from "@radix-ui/react-slot";
|
|
532
|
+
import React3, { useLayoutEffect, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
533
|
+
import { createPortal } from "react-dom";
|
|
534
|
+
import { composableProps as composableProps2, slottable } from "@dxos/ui-theme";
|
|
535
|
+
var MOSAIC_TILE_NAME = "Mosaic.Tile";
|
|
536
|
+
var [MosaicTileContextProvider, useMosaicTileContext] = createContext3("MosaicTile");
|
|
537
|
+
var MOSAIC_TILE_STATE_ATTR = "mosaic-tile-state";
|
|
538
|
+
var MosaicTile = slottable(({ children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, draggable: draggableProp, current: _current, debug: _, ...props }, forwardedRef) => {
|
|
539
|
+
const Comp = asChild ? Slot3 : Primitive3.div;
|
|
540
|
+
const rootRef = useRef3(null);
|
|
541
|
+
const composedRef = composeRefs(rootRef, forwardedRef);
|
|
542
|
+
const { id: containerId, eventHandler, orientation, scrolling, setActiveLocation } = useMosaicContainerContext(MOSAIC_TILE_NAME);
|
|
543
|
+
const [state, setState] = useState3({
|
|
544
|
+
type: "idle"
|
|
545
|
+
});
|
|
546
|
+
const allowedEdges = useMemo3(() => allowedEdgesProp || (orientation === "vertical" ? [
|
|
547
|
+
"top",
|
|
548
|
+
"bottom"
|
|
549
|
+
] : [
|
|
550
|
+
"left",
|
|
551
|
+
"right"
|
|
552
|
+
]), [
|
|
553
|
+
allowedEdgesProp,
|
|
554
|
+
orientation
|
|
555
|
+
]);
|
|
556
|
+
const data = useMemo3(() => ({
|
|
557
|
+
type: "tile",
|
|
558
|
+
id,
|
|
559
|
+
containerId,
|
|
560
|
+
data: dataProp,
|
|
561
|
+
location
|
|
562
|
+
}), [
|
|
563
|
+
containerId,
|
|
564
|
+
location,
|
|
565
|
+
dataProp
|
|
566
|
+
]);
|
|
567
|
+
useLayoutEffect(() => {
|
|
568
|
+
const root = rootRef.current;
|
|
569
|
+
if (!draggableProp || !root || !containerId || scrolling) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const handleChange = ({ self, source }) => {
|
|
573
|
+
if (source.data.id !== dataProp.id) {
|
|
574
|
+
const closestEdge = extractClosestEdge(self.data);
|
|
575
|
+
const location2 = data.location + (closestEdge === "top" || closestEdge === "left" ? -0.5 : 0.5);
|
|
576
|
+
setActiveLocation(location2);
|
|
577
|
+
setState({
|
|
578
|
+
type: "target",
|
|
579
|
+
closestEdge
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
return combine3(
|
|
584
|
+
// Source.
|
|
585
|
+
draggable({
|
|
586
|
+
element: root,
|
|
587
|
+
dragHandle: dragHandle && state.type !== "preview" ? dragHandle : void 0,
|
|
588
|
+
canDrag: () => true,
|
|
589
|
+
getInitialData: () => data,
|
|
590
|
+
onGenerateDragPreview: ({ location: location2, nativeSetDragImage }) => {
|
|
591
|
+
setCustomNativeDragPreview({
|
|
592
|
+
nativeSetDragImage,
|
|
593
|
+
getOffset: preserveOffsetOnSource({
|
|
594
|
+
element: root,
|
|
595
|
+
input: location2.current.input
|
|
596
|
+
}),
|
|
597
|
+
render: ({ container }) => {
|
|
598
|
+
data.bounds = root.getBoundingClientRect();
|
|
599
|
+
setState({
|
|
600
|
+
type: "preview",
|
|
601
|
+
container,
|
|
602
|
+
rect: root.getBoundingClientRect()
|
|
603
|
+
});
|
|
604
|
+
return () => setState({
|
|
605
|
+
type: "dragging"
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
},
|
|
610
|
+
onDragStart: () => {
|
|
611
|
+
setState({
|
|
612
|
+
type: "dragging"
|
|
613
|
+
});
|
|
614
|
+
},
|
|
615
|
+
onDrop: () => {
|
|
616
|
+
setState({
|
|
617
|
+
type: "idle"
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}),
|
|
621
|
+
// Target.
|
|
622
|
+
dropTargetForElements2({
|
|
623
|
+
element: root,
|
|
624
|
+
getData: ({ input, element }) => attachClosestEdge(data, {
|
|
625
|
+
input,
|
|
626
|
+
element,
|
|
627
|
+
allowedEdges
|
|
628
|
+
}),
|
|
629
|
+
canDrop: ({ source }) => {
|
|
630
|
+
const data2 = getSourceData(source);
|
|
631
|
+
return data2 && eventHandler.canDrop?.({
|
|
632
|
+
source: data2
|
|
633
|
+
}) || false;
|
|
634
|
+
},
|
|
635
|
+
onDragEnter: ({ self, source }) => {
|
|
636
|
+
handleChange({
|
|
637
|
+
self,
|
|
638
|
+
source
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
onDragLeave: () => {
|
|
642
|
+
setState({
|
|
643
|
+
type: "idle"
|
|
644
|
+
});
|
|
645
|
+
setActiveLocation(void 0);
|
|
646
|
+
},
|
|
647
|
+
onDrag: ({ self, source }) => {
|
|
648
|
+
handleChange({
|
|
649
|
+
self,
|
|
650
|
+
source
|
|
651
|
+
});
|
|
652
|
+
},
|
|
653
|
+
onDrop: () => {
|
|
654
|
+
setState({
|
|
655
|
+
type: "idle"
|
|
656
|
+
});
|
|
657
|
+
setActiveLocation(void 0);
|
|
658
|
+
}
|
|
659
|
+
})
|
|
660
|
+
);
|
|
661
|
+
}, [
|
|
662
|
+
rootRef,
|
|
663
|
+
forwardedRef,
|
|
664
|
+
containerId,
|
|
665
|
+
dragHandle,
|
|
666
|
+
eventHandler,
|
|
667
|
+
data,
|
|
668
|
+
scrolling,
|
|
669
|
+
allowedEdges,
|
|
670
|
+
setActiveLocation
|
|
671
|
+
]);
|
|
672
|
+
const { className, ...rest } = composableProps2(props, {
|
|
673
|
+
classNames: "relative outline-none"
|
|
674
|
+
});
|
|
675
|
+
return /* @__PURE__ */ React3.createElement(MosaicTileContextProvider, {
|
|
676
|
+
state
|
|
677
|
+
}, /* @__PURE__ */ React3.createElement(Comp, {
|
|
678
|
+
...rest,
|
|
679
|
+
"data-object-id": id,
|
|
680
|
+
[`data-${MOSAIC_TILE_STATE_ATTR}`]: state.type,
|
|
681
|
+
role: "listitem",
|
|
682
|
+
className,
|
|
683
|
+
ref: composedRef
|
|
684
|
+
}, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React3.createElement(Comp, {
|
|
685
|
+
// NOTE: Use to control appearance while dragging.
|
|
686
|
+
[`data-${MOSAIC_TILE_STATE_ATTR}`]: state.type,
|
|
687
|
+
className,
|
|
688
|
+
style: {
|
|
689
|
+
width: `${state.rect.width}px`,
|
|
690
|
+
height: `${state.rect.height}px`
|
|
691
|
+
}
|
|
692
|
+
}, children), state.container));
|
|
693
|
+
});
|
|
694
|
+
MosaicTile.displayName = MOSAIC_TILE_NAME;
|
|
695
|
+
|
|
696
|
+
// src/components/Mosaic/Placeholder.tsx
|
|
697
|
+
import { DropIndicator as NaturalDropIndicator } from "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box";
|
|
698
|
+
import { dropTargetForElements as dropTargetForElements3 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
699
|
+
import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
|
|
700
|
+
import { Slot as Slot4 } from "@radix-ui/react-slot";
|
|
701
|
+
import React4, { useLayoutEffect as useLayoutEffect2, useMemo as useMemo4, useRef as useRef4 } from "react";
|
|
702
|
+
import { mx } from "@dxos/ui-theme";
|
|
703
|
+
var MOSAIC_PLACEHOLDER_NAME = "Mosaic.Placeholder";
|
|
704
|
+
var MOSAIC_PLACEHOLDER_ORIENTATION_ATTR = "mosaic-placeholder-orientation";
|
|
705
|
+
var MOSAIC_PLACEHOLDER_STATE_ATTR = "mosaic-placeholder-state";
|
|
706
|
+
var MosaicPlaceholder = ({ classNames, children, asChild, orientation = "vertical", location }) => {
|
|
707
|
+
const rootRef = useRef4(null);
|
|
708
|
+
const Comp = asChild ? Slot4 : Primitive4.div;
|
|
709
|
+
const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useMosaicContainerContext(MOSAIC_PLACEHOLDER_NAME);
|
|
710
|
+
const data = useMemo4(() => ({
|
|
711
|
+
type: "placeholder",
|
|
712
|
+
containerId,
|
|
713
|
+
location
|
|
714
|
+
}), [
|
|
715
|
+
containerId,
|
|
716
|
+
location
|
|
717
|
+
]);
|
|
718
|
+
useLayoutEffect2(() => {
|
|
719
|
+
const root = rootRef.current;
|
|
720
|
+
if (!root || scrolling) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
return dropTargetForElements3({
|
|
724
|
+
element: root,
|
|
725
|
+
getData: () => data,
|
|
726
|
+
canDrop: ({ source }) => {
|
|
727
|
+
const data2 = getSourceData(source);
|
|
728
|
+
return data2 && eventHandler.canDrop?.({
|
|
729
|
+
source: data2
|
|
730
|
+
}) || false;
|
|
731
|
+
},
|
|
732
|
+
onDragEnter: () => {
|
|
733
|
+
setActiveLocation(data.location);
|
|
734
|
+
},
|
|
735
|
+
onDragLeave: () => {
|
|
736
|
+
setActiveLocation(void 0);
|
|
737
|
+
},
|
|
738
|
+
onDrop: () => {
|
|
739
|
+
setActiveLocation(void 0);
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
}, [
|
|
743
|
+
rootRef,
|
|
744
|
+
data,
|
|
745
|
+
scrolling,
|
|
746
|
+
setActiveLocation
|
|
747
|
+
]);
|
|
748
|
+
return /* @__PURE__ */ React4.createElement(Comp, {
|
|
749
|
+
[`data-${MOSAIC_PLACEHOLDER_ORIENTATION_ATTR}`]: orientation,
|
|
750
|
+
[`data-${MOSAIC_PLACEHOLDER_STATE_ATTR}`]: data.location === activeLocation ? "active" : "idle",
|
|
751
|
+
role: "none",
|
|
752
|
+
className: mx("relative", classNames),
|
|
753
|
+
ref: rootRef
|
|
754
|
+
}, children);
|
|
755
|
+
};
|
|
756
|
+
MosaicPlaceholder.displayName = MOSAIC_PLACEHOLDER_NAME;
|
|
757
|
+
var DROP_INDICATOR_NAME = "Mosaic.DropIndicator";
|
|
758
|
+
var MosaicDropIndicator = (props) => {
|
|
759
|
+
const { state } = useMosaicTileContext(DROP_INDICATOR_NAME);
|
|
760
|
+
return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React4.createElement(NaturalDropIndicator, {
|
|
761
|
+
...props,
|
|
762
|
+
edge: state.closestEdge
|
|
763
|
+
}) : null;
|
|
764
|
+
};
|
|
765
|
+
MosaicDropIndicator.displayName = DROP_INDICATOR_NAME;
|
|
766
|
+
|
|
767
|
+
// src/components/Mosaic/Stack.tsx
|
|
768
|
+
import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
|
|
769
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
770
|
+
import React5, { forwardRef as forwardRef2, Fragment, useCallback as useCallback3, useEffect as useEffect3, useRef as useRef5 } from "react";
|
|
771
|
+
import { invariant } from "@dxos/invariant";
|
|
772
|
+
import { composable as composable2, composableProps as composableProps3, mx as mx2 } from "@dxos/ui-theme";
|
|
773
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Stack.tsx";
|
|
774
|
+
var MOSAIC_STACK_NAME = "MosaicStack";
|
|
775
|
+
var MosaicStackInner = composable2(({ orientation: orientationProp = "vertical", getId, items, scrollIntoView = true, Tile, draggable: draggable2 = true, debug, ...props }, forwardedRef) => {
|
|
776
|
+
const { id, orientation = orientationProp, dragging, currentId, registerScrollTo } = useMosaicContainerContext(MOSAIC_STACK_NAME);
|
|
777
|
+
const visibleItems = useVisibleItems({
|
|
778
|
+
id,
|
|
779
|
+
items,
|
|
780
|
+
dragging: dragging?.source.data,
|
|
781
|
+
getId
|
|
782
|
+
});
|
|
783
|
+
invariant(orientation === "vertical" || orientation === "horizontal", `Invalid orientation: ${orientation}`, {
|
|
784
|
+
F: __dxlog_file2,
|
|
785
|
+
L: 91,
|
|
786
|
+
S: void 0,
|
|
787
|
+
A: [
|
|
788
|
+
"orientation === 'vertical' || orientation === 'horizontal'",
|
|
789
|
+
"`Invalid orientation: ${orientation}`"
|
|
790
|
+
]
|
|
791
|
+
});
|
|
792
|
+
const rootRef = useRef5(null);
|
|
793
|
+
const scrollToId = useCallback3((targetId) => {
|
|
794
|
+
if (!scrollIntoView) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const el = rootRef.current?.querySelector(`[data-object-id="${CSS.escape(targetId)}"]`);
|
|
798
|
+
el?.scrollIntoView({
|
|
799
|
+
block: "nearest",
|
|
800
|
+
behavior: "smooth"
|
|
801
|
+
});
|
|
802
|
+
}, [
|
|
803
|
+
scrollIntoView
|
|
804
|
+
]);
|
|
805
|
+
useEffect3(() => {
|
|
806
|
+
registerScrollTo(scrollToId);
|
|
807
|
+
return () => registerScrollTo(void 0);
|
|
808
|
+
}, [
|
|
809
|
+
registerScrollTo,
|
|
810
|
+
scrollToId
|
|
811
|
+
]);
|
|
812
|
+
const composedRef = useComposedRefs3(rootRef, forwardedRef);
|
|
813
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
814
|
+
...composableProps3(props, {
|
|
815
|
+
role: "list",
|
|
816
|
+
classNames: [
|
|
817
|
+
"flex",
|
|
818
|
+
orientation === "horizontal" && "h-full [&>*]:shrink-0",
|
|
819
|
+
orientation === "vertical" && "flex-col"
|
|
820
|
+
]
|
|
821
|
+
}),
|
|
822
|
+
ref: composedRef
|
|
823
|
+
}, draggable2 && /* @__PURE__ */ React5.createElement(InternalPlaceholder, {
|
|
824
|
+
orientation,
|
|
825
|
+
location: 0.5
|
|
826
|
+
}), visibleItems?.map((item, index) => /* @__PURE__ */ React5.createElement(Fragment, {
|
|
827
|
+
key: getId(item)
|
|
828
|
+
}, /* @__PURE__ */ React5.createElement(Tile, {
|
|
829
|
+
id: getId(item),
|
|
830
|
+
data: item,
|
|
831
|
+
location: index + 1,
|
|
832
|
+
draggable: draggable2,
|
|
833
|
+
current: getId(item) === currentId,
|
|
834
|
+
debug
|
|
835
|
+
}), draggable2 && /* @__PURE__ */ React5.createElement(InternalPlaceholder, {
|
|
836
|
+
orientation,
|
|
837
|
+
location: index + 1.5
|
|
838
|
+
}))));
|
|
839
|
+
});
|
|
840
|
+
MosaicStackInner.displayName = MOSAIC_STACK_NAME;
|
|
841
|
+
var MosaicStack = MosaicStackInner;
|
|
842
|
+
var MOSAIC_VIRTUAL_STACK_NAME = "MosaicVirtualStack";
|
|
843
|
+
var MosaicVirtualStackInner = /* @__PURE__ */ forwardRef2(({ orientation = "vertical", getId, items, scrollIntoView = true, Tile, estimateSize, getScrollElement, overscan = 8, gap, onChange, draggable: draggable2 = true, debug, ...props }, forwardedRef) => {
|
|
844
|
+
invariant(Tile, void 0, {
|
|
845
|
+
F: __dxlog_file2,
|
|
846
|
+
L: 180,
|
|
847
|
+
S: void 0,
|
|
848
|
+
A: [
|
|
849
|
+
"Tile",
|
|
850
|
+
""
|
|
851
|
+
]
|
|
852
|
+
});
|
|
853
|
+
const { id, dragging, currentId, registerScrollTo } = useMosaicContainerContext(MOSAIC_VIRTUAL_STACK_NAME);
|
|
854
|
+
const visibleItems = useVisibleItems({
|
|
855
|
+
id,
|
|
856
|
+
items,
|
|
857
|
+
dragging: dragging?.source.data,
|
|
858
|
+
getId
|
|
859
|
+
});
|
|
860
|
+
const wrappedEstimateSize = draggable2 ? (index) => index % 2 === 0 ? 0 : estimateSize(Math.floor(index / 2)) : estimateSize;
|
|
861
|
+
const virtualizer = useVirtualizer({
|
|
862
|
+
// NOTE: When draggable we double the number of items to allow for placeholders.
|
|
863
|
+
count: draggable2 ? visibleItems.length * 2 + 1 : visibleItems.length,
|
|
864
|
+
estimateSize: wrappedEstimateSize,
|
|
865
|
+
gap,
|
|
866
|
+
// Key measurements by stable item ID so the size cache survives scrolling;
|
|
867
|
+
// without this, measurements are indexed by position and are lost when items reorder.
|
|
868
|
+
getItemKey: draggable2 ? (index) => index % 2 === 0 ? `ph-${index}` : getId(visibleItems[Math.floor(index / 2)]) : (index) => getId(visibleItems[index]),
|
|
869
|
+
getScrollElement,
|
|
870
|
+
overscan,
|
|
871
|
+
onChange
|
|
872
|
+
});
|
|
873
|
+
const scrollToId = useCallback3((targetId) => {
|
|
874
|
+
const itemIndex = visibleItems.findIndex((item) => getId(item) === targetId);
|
|
875
|
+
if (itemIndex >= 0) {
|
|
876
|
+
if (!scrollIntoView) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
const virtualIndex = draggable2 ? itemIndex * 2 + 1 : itemIndex;
|
|
880
|
+
virtualizer.scrollToIndex(virtualIndex, {
|
|
881
|
+
align: "start",
|
|
882
|
+
behavior: "smooth"
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}, [
|
|
886
|
+
visibleItems,
|
|
887
|
+
getId,
|
|
888
|
+
draggable2,
|
|
889
|
+
virtualizer,
|
|
890
|
+
scrollIntoView
|
|
891
|
+
]);
|
|
892
|
+
useEffect3(() => {
|
|
893
|
+
registerScrollTo(scrollToId);
|
|
894
|
+
return () => registerScrollTo(void 0);
|
|
895
|
+
}, [
|
|
896
|
+
registerScrollTo,
|
|
897
|
+
scrollToId
|
|
898
|
+
]);
|
|
899
|
+
const virtualItems = virtualizer.getVirtualItems();
|
|
900
|
+
const getData = (index) => {
|
|
901
|
+
if (draggable2) {
|
|
902
|
+
if (index % 2 === 0) {
|
|
903
|
+
return {
|
|
904
|
+
location: Math.floor(index / 2) + 0.5
|
|
905
|
+
};
|
|
906
|
+
} else {
|
|
907
|
+
return {
|
|
908
|
+
data: visibleItems[Math.floor(index / 2)],
|
|
909
|
+
location: Math.floor(index / 2) + 1
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
} else {
|
|
913
|
+
return {
|
|
914
|
+
data: visibleItems[index],
|
|
915
|
+
location: index + 1
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
920
|
+
...composableProps3(props, {
|
|
921
|
+
role: "list",
|
|
922
|
+
classNames: [
|
|
923
|
+
// shrink-0 is required: this div sets an explicit height via inline style (getTotalSize).
|
|
924
|
+
// Without it, a parent flex container (e.g. ScrollArea.Viewport) would shrink this div
|
|
925
|
+
// to the viewport height, collapsing the scroll content and causing scrollbar drift.
|
|
926
|
+
"flex shrink-0",
|
|
927
|
+
orientation === "horizontal" && "h-full [&>*]:shrink-0",
|
|
928
|
+
orientation === "vertical" && "flex-col"
|
|
929
|
+
]
|
|
930
|
+
}),
|
|
931
|
+
style: {
|
|
932
|
+
position: "relative",
|
|
933
|
+
...orientation === "vertical" ? {
|
|
934
|
+
width: "100%",
|
|
935
|
+
height: virtualizer.getTotalSize()
|
|
936
|
+
} : {
|
|
937
|
+
width: virtualizer.getTotalSize(),
|
|
938
|
+
height: "100%"
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
ref: forwardedRef
|
|
942
|
+
}, virtualItems.map(({ key, index, start }) => {
|
|
943
|
+
const { data, location } = getData(index);
|
|
944
|
+
return /* @__PURE__ */ React5.createElement("div", {
|
|
945
|
+
key,
|
|
946
|
+
"data-index": index,
|
|
947
|
+
style: {
|
|
948
|
+
position: "absolute",
|
|
949
|
+
top: 0,
|
|
950
|
+
left: 0,
|
|
951
|
+
...orientation === "vertical" ? {
|
|
952
|
+
width: "100%",
|
|
953
|
+
transform: `translateY(${start}px)`
|
|
954
|
+
} : {
|
|
955
|
+
height: "100%",
|
|
956
|
+
transform: `translateX(${start}px)`
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
ref: virtualizer.measureElement
|
|
960
|
+
}, data ? /* @__PURE__ */ React5.createElement(Tile, {
|
|
961
|
+
id: getId(data),
|
|
962
|
+
data,
|
|
963
|
+
location,
|
|
964
|
+
draggable: draggable2,
|
|
965
|
+
current: getId(data) === currentId,
|
|
966
|
+
debug
|
|
967
|
+
}) : /* @__PURE__ */ React5.createElement(InternalPlaceholder, {
|
|
968
|
+
orientation,
|
|
969
|
+
location
|
|
970
|
+
}));
|
|
971
|
+
}));
|
|
972
|
+
});
|
|
973
|
+
MosaicVirtualStackInner.displayName = MOSAIC_VIRTUAL_STACK_NAME;
|
|
974
|
+
var MosaicVirtualStack = MosaicVirtualStackInner;
|
|
975
|
+
MosaicVirtualStack[/* @__PURE__ */ Symbol.for("dxos.composable")] = true;
|
|
976
|
+
var InternalPlaceholder = (props) => {
|
|
977
|
+
return /* @__PURE__ */ React5.createElement(MosaicPlaceholder, {
|
|
978
|
+
...props,
|
|
979
|
+
classNames: styles.placeholder.root
|
|
980
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
981
|
+
className: mx2("flex h-full bg-base-surface border border-dashed border-separator rounded-xs", styles.placeholder.content)
|
|
982
|
+
}));
|
|
983
|
+
};
|
|
984
|
+
InternalPlaceholder.displayName = "InternalPlaceholder";
|
|
985
|
+
|
|
986
|
+
// src/components/Mosaic/Mosaic.tsx
|
|
987
|
+
var Mosaic = {
|
|
988
|
+
Root: MosaicRoot,
|
|
989
|
+
Container: MosaicContainer,
|
|
990
|
+
Tile: MosaicTile,
|
|
991
|
+
Placeholder: MosaicPlaceholder,
|
|
992
|
+
DropIndicator: MosaicDropIndicator,
|
|
993
|
+
Stack: MosaicStack,
|
|
994
|
+
VirtualStack: MosaicVirtualStack
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
export {
|
|
998
|
+
useVisibleItems,
|
|
999
|
+
Focus,
|
|
1000
|
+
useFocus,
|
|
1001
|
+
styles,
|
|
1002
|
+
getSourceData,
|
|
1003
|
+
useMosaicRootContext,
|
|
1004
|
+
useMosaicContainerContext,
|
|
1005
|
+
useMosaicTileContext,
|
|
1006
|
+
Mosaic
|
|
1007
|
+
};
|
|
1008
|
+
//# sourceMappingURL=chunk-33NNDFD6.mjs.map
|