@dxos/react-ui-mosaic 0.7.5-main.e9bb01b → 0.8.4-main.03d5cd7b56

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