@dxos/react-ui-mosaic 0.10.0 → 0.11.0

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