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