@dxos/react-ui-mosaic 0.7.5-main.ff8607b → 0.8.4-main.69d29f4

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 (282) hide show
  1. package/README.md +2 -44
  2. package/dist/lib/browser/chunk-4VDZJ3HV.mjs +1639 -0
  3. package/dist/lib/browser/chunk-4VDZJ3HV.mjs.map +7 -0
  4. package/dist/lib/browser/index.css +13 -0
  5. package/dist/lib/browser/index.css.map +7 -0
  6. package/dist/lib/browser/index.mjs +85 -689
  7. package/dist/lib/browser/index.mjs.map +4 -4
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/testing/index.css +13 -0
  10. package/dist/lib/browser/testing/index.css.map +7 -0
  11. package/dist/lib/browser/testing/index.mjs +306 -0
  12. package/dist/lib/browser/testing/index.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-KONKDEUD.mjs +1641 -0
  14. package/dist/lib/node-esm/chunk-KONKDEUD.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.css +13 -0
  16. package/dist/lib/node-esm/index.css.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +85 -690
  18. package/dist/lib/node-esm/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.css +13 -0
  21. package/dist/lib/node-esm/testing/index.css.map +7 -0
  22. package/dist/lib/node-esm/testing/index.mjs +307 -0
  23. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  24. package/dist/types/src/components/Card/Card.d.ts +120 -0
  25. package/dist/types/src/components/Card/Card.d.ts.map +1 -0
  26. package/dist/types/src/components/Card/Card.stories.d.ts +21 -0
  27. package/dist/types/src/components/Card/Card.stories.d.ts.map +1 -0
  28. package/dist/types/src/components/Card/CardDragPreview.d.ts +6 -0
  29. package/dist/types/src/components/Card/CardDragPreview.d.ts.map +1 -0
  30. package/dist/types/src/components/Card/index.d.ts +4 -0
  31. package/dist/types/src/components/Card/index.d.ts.map +1 -0
  32. package/dist/types/src/components/Card/styles.d.ts +13 -0
  33. package/dist/types/src/components/Card/styles.d.ts.map +1 -0
  34. package/dist/types/src/components/Focus/Focus.d.ts +25 -0
  35. package/dist/types/src/components/Focus/Focus.d.ts.map +1 -0
  36. package/dist/types/src/components/Focus/index.d.ts +3 -0
  37. package/dist/types/src/components/Focus/index.d.ts.map +1 -0
  38. package/dist/types/src/components/Focus/styles.d.ts +6 -0
  39. package/dist/types/src/components/Focus/styles.d.ts.map +1 -0
  40. package/dist/types/src/components/Image/Image.d.ts +14 -0
  41. package/dist/types/src/components/Image/Image.d.ts.map +1 -0
  42. package/dist/types/src/components/Image/Image.stories.d.ts +33 -0
  43. package/dist/types/src/components/Image/Image.stories.d.ts.map +1 -0
  44. package/dist/types/src/components/Image/index.d.ts +2 -0
  45. package/dist/types/src/components/Image/index.d.ts.map +1 -0
  46. package/dist/types/src/components/Layout/Layout.d.ts +33 -0
  47. package/dist/types/src/components/Layout/Layout.d.ts.map +1 -0
  48. package/dist/types/src/components/Layout/Layout.stories.d.ts +10 -0
  49. package/dist/types/src/components/Layout/Layout.stories.d.ts.map +1 -0
  50. package/dist/types/src/components/Layout/index.d.ts +2 -0
  51. package/dist/types/src/components/Layout/index.d.ts.map +1 -0
  52. package/dist/types/src/components/Mosaic/Mosaic.d.ts +141 -0
  53. package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -0
  54. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts +27 -0
  55. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts.map +1 -0
  56. package/dist/types/src/components/Mosaic/extension.d.ts +20 -0
  57. package/dist/types/src/components/Mosaic/extension.d.ts.map +1 -0
  58. package/dist/types/src/components/Mosaic/index.d.ts +5 -0
  59. package/dist/types/src/components/Mosaic/index.d.ts.map +1 -0
  60. package/dist/types/src/components/Mosaic/styles.d.ts +7 -0
  61. package/dist/types/src/components/Mosaic/styles.d.ts.map +1 -0
  62. package/dist/types/src/components/Mosaic/types.d.ts +79 -0
  63. package/dist/types/src/components/Mosaic/types.d.ts.map +1 -0
  64. package/dist/types/src/components/Scrollable/Scrollable.d.ts +17 -0
  65. package/dist/types/src/components/Scrollable/Scrollable.d.ts.map +1 -0
  66. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts +8 -0
  67. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts.map +1 -0
  68. package/dist/types/src/components/Scrollable/index.d.ts +2 -0
  69. package/dist/types/src/components/Scrollable/index.d.ts.map +1 -0
  70. package/dist/types/src/components/Stack/Stack.d.ts +24 -0
  71. package/dist/types/src/components/Stack/Stack.d.ts.map +1 -0
  72. package/dist/types/src/components/Stack/Stack.stories.d.ts +9 -0
  73. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -0
  74. package/dist/types/src/components/Stack/index.d.ts.map +1 -0
  75. package/dist/types/src/components/index.d.ts +7 -0
  76. package/dist/types/src/components/index.d.ts.map +1 -0
  77. package/dist/types/src/hooks/index.d.ts +4 -0
  78. package/dist/types/src/hooks/index.d.ts.map +1 -0
  79. package/dist/types/src/hooks/useContainerDebug.d.ts +9 -0
  80. package/dist/types/src/hooks/useContainerDebug.d.ts.map +1 -0
  81. package/dist/types/src/hooks/useEventHandlerAdapter.d.ts +32 -0
  82. package/dist/types/src/hooks/useEventHandlerAdapter.d.ts.map +1 -0
  83. package/dist/types/src/hooks/useVisibleItems.d.ts +16 -0
  84. package/dist/types/src/hooks/useVisibleItems.d.ts.map +1 -0
  85. package/dist/types/src/index.d.ts +2 -1
  86. package/dist/types/src/index.d.ts.map +1 -1
  87. package/dist/types/src/testing/Board.d.ts +45 -0
  88. package/dist/types/src/testing/Board.d.ts.map +1 -0
  89. package/dist/types/src/testing/CardContainer.d.ts +17 -0
  90. package/dist/types/src/testing/CardContainer.d.ts.map +1 -0
  91. package/dist/types/src/testing/DefaultStackTile.d.ts +4 -0
  92. package/dist/types/src/testing/DefaultStackTile.d.ts.map +1 -0
  93. package/dist/types/src/testing/Slot.stories.d.ts +14 -0
  94. package/dist/types/src/testing/Slot.stories.d.ts.map +1 -0
  95. package/dist/types/src/testing/Virtualizer.stories.d.ts +12 -0
  96. package/dist/types/src/testing/Virtualizer.stories.d.ts.map +1 -0
  97. package/dist/types/src/testing/decorator.d.ts +3 -0
  98. package/dist/types/src/testing/decorator.d.ts.map +1 -0
  99. package/dist/types/src/testing/index.d.ts +4 -2
  100. package/dist/types/src/testing/index.d.ts.map +1 -1
  101. package/dist/types/src/translations.d.ts +7 -0
  102. package/dist/types/src/translations.d.ts.map +1 -0
  103. package/dist/types/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +63 -40
  105. package/src/components/Card/Card.stories.tsx +148 -0
  106. package/src/components/Card/Card.tsx +435 -0
  107. package/src/components/Card/CardDragPreview.tsx +23 -0
  108. package/src/components/Card/index.ts +8 -0
  109. package/src/components/Card/styles.ts +23 -0
  110. package/src/components/Focus/Focus.tsx +95 -0
  111. package/src/components/Focus/index.ts +7 -0
  112. package/src/components/Focus/styles.ts +24 -0
  113. package/src/components/Image/Image.stories.tsx +86 -0
  114. package/src/components/Image/Image.tsx +223 -0
  115. package/src/components/Image/index.ts +5 -0
  116. package/src/components/Layout/Layout.stories.tsx +59 -0
  117. package/src/components/Layout/Layout.tsx +108 -0
  118. package/src/components/Layout/index.ts +5 -0
  119. package/src/components/Mosaic/Mosaic.stories.tsx +113 -0
  120. package/src/components/Mosaic/Mosaic.tsx +930 -0
  121. package/src/components/Mosaic/extension.ts +141 -0
  122. package/src/components/Mosaic/index.ts +10 -0
  123. package/src/components/Mosaic/styles.ts +31 -0
  124. package/src/components/Mosaic/types.ts +82 -0
  125. package/src/components/Scrollable/Scrollable.stories.tsx +33 -0
  126. package/src/components/Scrollable/Scrollable.tsx +99 -0
  127. package/src/components/Scrollable/index.ts +5 -0
  128. package/src/components/Scrollable/scrollable.css +20 -0
  129. package/src/components/Stack/Stack.stories.tsx +115 -0
  130. package/src/components/Stack/Stack.tsx +210 -0
  131. package/src/{views → components}/Stack/index.ts +1 -1
  132. package/src/components/index.ts +10 -0
  133. package/src/hooks/index.ts +7 -0
  134. package/src/hooks/useContainerDebug.tsx +46 -0
  135. package/src/hooks/useEventHandlerAdapter.ts +99 -0
  136. package/src/hooks/useVisibleItems.ts +43 -0
  137. package/src/index.ts +3 -2
  138. package/src/testing/Board.tsx +278 -0
  139. package/src/testing/CardContainer.tsx +88 -0
  140. package/src/testing/DefaultStackTile.tsx +38 -0
  141. package/src/testing/Slot.stories.tsx +101 -0
  142. package/src/testing/Virtualizer.stories.tsx +133 -0
  143. package/src/testing/decorator.tsx +16 -0
  144. package/src/testing/index.ts +5 -3
  145. package/src/translations.ts +15 -0
  146. package/dist/lib/node/index.cjs +0 -705
  147. package/dist/lib/node/index.cjs.map +0 -7
  148. package/dist/lib/node/meta.json +0 -1
  149. package/dist/types/src/mosaic/Container.d.ts +0 -94
  150. package/dist/types/src/mosaic/Container.d.ts.map +0 -1
  151. package/dist/types/src/mosaic/Debug.d.ts +0 -9
  152. package/dist/types/src/mosaic/Debug.d.ts.map +0 -1
  153. package/dist/types/src/mosaic/DefaultComponent.d.ts +0 -4
  154. package/dist/types/src/mosaic/DefaultComponent.d.ts.map +0 -1
  155. package/dist/types/src/mosaic/DragOverlay.d.ts +0 -11
  156. package/dist/types/src/mosaic/DragOverlay.d.ts.map +0 -1
  157. package/dist/types/src/mosaic/Mosaic.d.ts +0 -34
  158. package/dist/types/src/mosaic/Mosaic.d.ts.map +0 -1
  159. package/dist/types/src/mosaic/Root.d.ts +0 -28
  160. package/dist/types/src/mosaic/Root.d.ts.map +0 -1
  161. package/dist/types/src/mosaic/SortableContext.d.ts +0 -14
  162. package/dist/types/src/mosaic/SortableContext.d.ts.map +0 -1
  163. package/dist/types/src/mosaic/Tile.d.ts +0 -74
  164. package/dist/types/src/mosaic/Tile.d.ts.map +0 -1
  165. package/dist/types/src/mosaic/hooks/index.d.ts +0 -5
  166. package/dist/types/src/mosaic/hooks/index.d.ts.map +0 -1
  167. package/dist/types/src/mosaic/hooks/useContainer.d.ts +0 -4
  168. package/dist/types/src/mosaic/hooks/useContainer.d.ts.map +0 -1
  169. package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts +0 -3
  170. package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts.map +0 -1
  171. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts +0 -10
  172. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +0 -1
  173. package/dist/types/src/mosaic/hooks/useMosaic.d.ts +0 -2
  174. package/dist/types/src/mosaic/hooks/useMosaic.d.ts.map +0 -1
  175. package/dist/types/src/mosaic/index.d.ts +0 -5
  176. package/dist/types/src/mosaic/index.d.ts.map +0 -1
  177. package/dist/types/src/mosaic/types.d.ts +0 -10
  178. package/dist/types/src/mosaic/types.d.ts.map +0 -1
  179. package/dist/types/src/mosaic/util/data.d.ts +0 -3
  180. package/dist/types/src/mosaic/util/data.d.ts.map +0 -1
  181. package/dist/types/src/mosaic/util/index.d.ts +0 -5
  182. package/dist/types/src/mosaic/util/index.d.ts.map +0 -1
  183. package/dist/types/src/mosaic/util/path.d.ts +0 -14
  184. package/dist/types/src/mosaic/util/path.d.ts.map +0 -1
  185. package/dist/types/src/mosaic/util/path.test.d.ts +0 -2
  186. package/dist/types/src/mosaic/util/path.test.d.ts.map +0 -1
  187. package/dist/types/src/mosaic/util/props.d.ts +0 -4
  188. package/dist/types/src/mosaic/util/props.d.ts.map +0 -1
  189. package/dist/types/src/mosaic/util/styles.d.ts +0 -3
  190. package/dist/types/src/mosaic/util/styles.d.ts.map +0 -1
  191. package/dist/types/src/testing/Cards.d.ts +0 -10
  192. package/dist/types/src/testing/Cards.d.ts.map +0 -1
  193. package/dist/types/src/testing/generator.d.ts +0 -35
  194. package/dist/types/src/testing/generator.d.ts.map +0 -1
  195. package/dist/types/src/views/Demo/Demo.stories.d.ts +0 -14
  196. package/dist/types/src/views/Demo/Demo.stories.d.ts.map +0 -1
  197. package/dist/types/src/views/Demo/Echo.stories.d.ts +0 -8
  198. package/dist/types/src/views/Demo/Echo.stories.d.ts.map +0 -1
  199. package/dist/types/src/views/Grid/Grid.d.ts +0 -31
  200. package/dist/types/src/views/Grid/Grid.d.ts.map +0 -1
  201. package/dist/types/src/views/Grid/Grid.stories.d.ts +0 -14
  202. package/dist/types/src/views/Grid/Grid.stories.d.ts.map +0 -1
  203. package/dist/types/src/views/Grid/index.d.ts +0 -3
  204. package/dist/types/src/views/Grid/index.d.ts.map +0 -1
  205. package/dist/types/src/views/Grid/layout.d.ts +0 -27
  206. package/dist/types/src/views/Grid/layout.d.ts.map +0 -1
  207. package/dist/types/src/views/Grid/testing.d.ts +0 -11
  208. package/dist/types/src/views/Grid/testing.d.ts.map +0 -1
  209. package/dist/types/src/views/Kanban/Kanban.d.ts +0 -12
  210. package/dist/types/src/views/Kanban/Kanban.d.ts.map +0 -1
  211. package/dist/types/src/views/Kanban/Kanban.stories.d.ts +0 -29
  212. package/dist/types/src/views/Kanban/Kanban.stories.d.ts.map +0 -1
  213. package/dist/types/src/views/Kanban/index.d.ts +0 -2
  214. package/dist/types/src/views/Kanban/index.d.ts.map +0 -1
  215. package/dist/types/src/views/Kanban/testing.d.ts +0 -12
  216. package/dist/types/src/views/Kanban/testing.d.ts.map +0 -1
  217. package/dist/types/src/views/Stack/Columns.stories.d.ts +0 -34
  218. package/dist/types/src/views/Stack/Columns.stories.d.ts.map +0 -1
  219. package/dist/types/src/views/Stack/Stack.d.ts +0 -10
  220. package/dist/types/src/views/Stack/Stack.d.ts.map +0 -1
  221. package/dist/types/src/views/Stack/Stack.stories.d.ts +0 -40
  222. package/dist/types/src/views/Stack/Stack.stories.d.ts.map +0 -1
  223. package/dist/types/src/views/Stack/index.d.ts.map +0 -1
  224. package/dist/types/src/views/Stack/testing.d.ts +0 -10
  225. package/dist/types/src/views/Stack/testing.d.ts.map +0 -1
  226. package/dist/types/src/views/Tree/Graph.stories.d.ts +0 -11
  227. package/dist/types/src/views/Tree/Graph.stories.d.ts.map +0 -1
  228. package/dist/types/src/views/Tree/Tree.d.ts +0 -13
  229. package/dist/types/src/views/Tree/Tree.d.ts.map +0 -1
  230. package/dist/types/src/views/Tree/Tree.stories.d.ts +0 -42
  231. package/dist/types/src/views/Tree/Tree.stories.d.ts.map +0 -1
  232. package/dist/types/src/views/Tree/index.d.ts +0 -2
  233. package/dist/types/src/views/Tree/index.d.ts.map +0 -1
  234. package/dist/types/src/views/Tree/testing.d.ts +0 -11
  235. package/dist/types/src/views/Tree/testing.d.ts.map +0 -1
  236. package/dist/types/src/views/index.d.ts +0 -5
  237. package/dist/types/src/views/index.d.ts.map +0 -1
  238. package/src/mosaic/Container.tsx +0 -190
  239. package/src/mosaic/Debug.tsx +0 -24
  240. package/src/mosaic/DefaultComponent.tsx +0 -26
  241. package/src/mosaic/DragOverlay.tsx +0 -150
  242. package/src/mosaic/Mosaic.ts +0 -100
  243. package/src/mosaic/Root.tsx +0 -320
  244. package/src/mosaic/SortableContext.tsx +0 -61
  245. package/src/mosaic/Tile.tsx +0 -207
  246. package/src/mosaic/hooks/index.ts +0 -8
  247. package/src/mosaic/hooks/useContainer.ts +0 -13
  248. package/src/mosaic/hooks/useItemsWithOrigin.ts +0 -33
  249. package/src/mosaic/hooks/useItemsWithPreview.ts +0 -69
  250. package/src/mosaic/hooks/useMosaic.ts +0 -11
  251. package/src/mosaic/index.ts +0 -9
  252. package/src/mosaic/types.ts +0 -15
  253. package/src/mosaic/util/data.ts +0 -19
  254. package/src/mosaic/util/index.ts +0 -8
  255. package/src/mosaic/util/path.test.ts +0 -24
  256. package/src/mosaic/util/path.ts +0 -21
  257. package/src/mosaic/util/props.ts +0 -14
  258. package/src/mosaic/util/styles.ts +0 -10
  259. package/src/testing/Cards.tsx +0 -88
  260. package/src/testing/generator.ts +0 -131
  261. package/src/views/Demo/Demo.stories.tsx +0 -81
  262. package/src/views/Demo/Echo.stories.tsx +0 -75
  263. package/src/views/Grid/Grid.stories.tsx +0 -51
  264. package/src/views/Grid/Grid.tsx +0 -265
  265. package/src/views/Grid/index.ts +0 -7
  266. package/src/views/Grid/layout.ts +0 -42
  267. package/src/views/Grid/testing.tsx +0 -92
  268. package/src/views/Kanban/Kanban.stories.tsx +0 -51
  269. package/src/views/Kanban/Kanban.tsx +0 -139
  270. package/src/views/Kanban/index.ts +0 -5
  271. package/src/views/Kanban/testing.tsx +0 -234
  272. package/src/views/Stack/Columns.stories.tsx +0 -63
  273. package/src/views/Stack/Stack.stories.tsx +0 -65
  274. package/src/views/Stack/Stack.tsx +0 -58
  275. package/src/views/Stack/testing.tsx +0 -77
  276. package/src/views/Tree/Graph.stories.tsx +0 -37
  277. package/src/views/Tree/Tree.stories.tsx +0 -95
  278. package/src/views/Tree/Tree.tsx +0 -126
  279. package/src/views/Tree/index.ts +0 -5
  280. package/src/views/Tree/testing.tsx +0 -142
  281. package/src/views/index.ts +0 -8
  282. /package/dist/types/src/{views → components}/Stack/index.d.ts +0 -0
@@ -0,0 +1,1641 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/components/Card/styles.ts
4
+ var styles = {
5
+ root: "group/card relative min-bs-[--rail-item] overflow-hidden is-full card-min-width __card-max-width",
6
+ border: "bg-cardSurface border border-separator dark:border-subduedSeparator rounded-sm dx-focus-ring-group-y-indicator",
7
+ /**
8
+ * Row grid.
9
+ * NOTE: Rows should provide their own line padding (since they may need to encapsulate buttons, etc.)
10
+ */
11
+ grid_3: "grid grid-cols-[var(--rail-item)_minmax(0,1fr)_var(--rail-item)] gap-x-1",
12
+ grid_2: "grid grid-cols-[var(--rail-item)_minmax(0,1fr)] gap-x-1",
13
+ // TODO(burdon): Address density.
14
+ grid_3_coarse: "grid grid-cols-[var(--l0-avatar-size)_minmax(0,1fr)_var(--rail-item)] gap-x-1",
15
+ poster: "max-bs-[200px]"
16
+ };
17
+
18
+ // src/components/Image/Image.tsx
19
+ import React, { useCallback, useRef, useState } from "react";
20
+ import { mx } from "@dxos/ui-theme";
21
+ var cache = /* @__PURE__ */ new Map();
22
+ var Image = ({ classNames, src, alt = "", crossOrigin = "anonymous", sampleSize = 64, contrast = 0.9 }) => {
23
+ const [crossOriginState, setCrossOriginState] = useState(crossOrigin);
24
+ const [dominantColor, setDominantColor] = useState(void 0);
25
+ const [imageLoaded, setImageLoaded] = useState(false);
26
+ const canvasRef = useRef(null);
27
+ const handleImageError = () => {
28
+ setCrossOriginState(void 0);
29
+ };
30
+ const handleImageLoad = useCallback(({ target }) => {
31
+ const rgb = cache.get(src);
32
+ if (rgb) {
33
+ setDominantColor(rgb);
34
+ setImageLoaded(true);
35
+ return;
36
+ }
37
+ const img = target;
38
+ if (!canvasRef.current) {
39
+ return;
40
+ }
41
+ try {
42
+ const color = extractDominantColor(canvasRef.current, img, {
43
+ sampleSize,
44
+ contrast
45
+ });
46
+ if (color) {
47
+ const rgb2 = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
48
+ cache.set(src, rgb2);
49
+ setDominantColor(rgb2);
50
+ }
51
+ } catch {
52
+ setCrossOriginState(void 0);
53
+ }
54
+ setImageLoaded(true);
55
+ }, [
56
+ sampleSize,
57
+ contrast,
58
+ src
59
+ ]);
60
+ return /* @__PURE__ */ React.createElement("div", {
61
+ className: mx(`relative flex is-full justify-center overflow-hidden transition-all duration-700`, classNames),
62
+ style: {
63
+ backgroundColor: dominantColor
64
+ }
65
+ }, /* @__PURE__ */ React.createElement("canvas", {
66
+ ref: canvasRef,
67
+ style: {
68
+ display: "none"
69
+ },
70
+ "aria-hidden": "true"
71
+ }), /* @__PURE__ */ React.createElement("div", {
72
+ className: "absolute inset-0 pointer-events-none",
73
+ style: {
74
+ background: dominantColor ? `radial-gradient(circle at center, transparent 30%, ${dominantColor} 100%)` : void 0,
75
+ transition: "opacity 0.7s ease-in-out",
76
+ opacity: 0.5
77
+ }
78
+ }), /* @__PURE__ */ React.createElement("img", {
79
+ src,
80
+ alt,
81
+ crossOrigin: crossOriginState,
82
+ onError: handleImageError,
83
+ onLoad: handleImageLoad,
84
+ className: mx("z-10 object-contain transition-opacity duration-500", classNames),
85
+ style: {
86
+ opacity: imageLoaded ? 1 : 0
87
+ }
88
+ }));
89
+ };
90
+ var extractDominantColor = (canvas, img, { sampleSize = 64, contrast = 0.95 }) => {
91
+ const ctx = canvas.getContext("2d");
92
+ if (!ctx) {
93
+ return null;
94
+ }
95
+ canvas.width = sampleSize;
96
+ canvas.height = sampleSize;
97
+ ctx.drawImage(img, 0, 0, sampleSize, sampleSize);
98
+ const imageData = ctx.getImageData(0, 0, sampleSize, sampleSize);
99
+ const pixels = imageData.data;
100
+ if (isTransparent(pixels, sampleSize)) {
101
+ return null;
102
+ }
103
+ let r = 0;
104
+ let g = 0;
105
+ let b = 0;
106
+ let totalWeight = 0;
107
+ const cornerSize = Math.floor(sampleSize * 0.125);
108
+ for (let y = 0; y < sampleSize; y++) {
109
+ for (let x = 0; x < sampleSize; x++) {
110
+ const isInTopLeft = x < cornerSize && y < cornerSize;
111
+ const isInTopRight = x >= sampleSize - cornerSize && y < cornerSize;
112
+ const isInBottomLeft = x < cornerSize && y >= sampleSize - cornerSize;
113
+ const isInBottomRight = x >= sampleSize - cornerSize && y >= sampleSize - cornerSize;
114
+ if (!isInTopLeft && !isInTopRight && !isInBottomLeft && !isInBottomRight) {
115
+ continue;
116
+ }
117
+ const i = (y * sampleSize + x) * 4;
118
+ const red = pixels[i];
119
+ const green = pixels[i + 1];
120
+ const blue = pixels[i + 2];
121
+ const alpha = pixels[i + 3];
122
+ if (alpha === 0) continue;
123
+ const max = Math.max(red, green, blue);
124
+ const min = Math.min(red, green, blue);
125
+ const saturation = max === 0 ? 0 : (max - min) / max;
126
+ const weight = 1 + saturation * 2;
127
+ r += red * weight;
128
+ g += green * weight;
129
+ b += blue * weight;
130
+ totalWeight += weight;
131
+ }
132
+ }
133
+ if (totalWeight > 0) {
134
+ r = Math.round(Math.round(r / totalWeight) * contrast);
135
+ g = Math.round(Math.round(g / totalWeight) * contrast);
136
+ b = Math.round(Math.round(b / totalWeight) * contrast);
137
+ return [
138
+ r,
139
+ g,
140
+ b
141
+ ];
142
+ }
143
+ return null;
144
+ };
145
+ var isTransparent = (pixels, sampleSize, threshold = 0.5) => {
146
+ let edgeTransparentPixels = 0;
147
+ const edgePixels = sampleSize * 4 - 4;
148
+ for (let x = 0; x < sampleSize; x++) {
149
+ const topIndex = x * 4;
150
+ if (pixels[topIndex + 3] === 0) edgeTransparentPixels++;
151
+ const bottomIndex = ((sampleSize - 1) * sampleSize + x) * 4;
152
+ if (pixels[bottomIndex + 3] === 0) edgeTransparentPixels++;
153
+ }
154
+ for (let y = 1; y < sampleSize - 1; y++) {
155
+ const leftIndex = y * sampleSize * 4;
156
+ if (pixels[leftIndex + 3] === 0) edgeTransparentPixels++;
157
+ const rightIndex = (y * sampleSize + sampleSize - 1) * 4;
158
+ if (pixels[rightIndex + 3] === 0) edgeTransparentPixels++;
159
+ }
160
+ return edgeTransparentPixels / edgePixels > threshold;
161
+ };
162
+
163
+ // src/components/Card/Card.tsx
164
+ import { Slot } from "@radix-ui/react-slot";
165
+ import React2, { createContext, forwardRef, useContext } from "react";
166
+ import { Button, DropdownMenu, Icon, Toolbar, useTranslation } from "@dxos/react-ui";
167
+ import { mx as mx2 } from "@dxos/ui-theme";
168
+
169
+ // src/translations.ts
170
+ var translationKey = "@dxos/react-ui-mosaic";
171
+ var translations = [
172
+ {
173
+ "en-US": {
174
+ [translationKey]: {}
175
+ }
176
+ }
177
+ ];
178
+
179
+ // src/components/Card/Card.tsx
180
+ var CardContext = /* @__PURE__ */ createContext({});
181
+ var CardRoot = /* @__PURE__ */ forwardRef(({ children, classNames, className, id, asChild, role = "group", border = true, fullWidth, ...props }, forwardedRef) => {
182
+ const Root2 = asChild ? Slot : "div";
183
+ return /* @__PURE__ */ React2.createElement(Root2, {
184
+ ...id && {
185
+ "data-object-id": id
186
+ },
187
+ ...props,
188
+ role,
189
+ className: mx2(styles.root, border && styles.border, fullWidth && "!max-is-none", className, classNames),
190
+ ref: forwardedRef
191
+ }, children);
192
+ });
193
+ var CardToolbar = /* @__PURE__ */ forwardRef(({ children, classNames, density = "fine", ...props }, forwardedRef) => {
194
+ return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
195
+ ...props,
196
+ classNames: [
197
+ "density-fine bg-transparent",
198
+ density === "fine" ? styles.grid_3 : styles.grid_3_coarse,
199
+ classNames
200
+ ],
201
+ ref: forwardedRef
202
+ }, children);
203
+ });
204
+ var CardToolbarIconButton = Toolbar.IconButton;
205
+ var CardToolbarSeparator = Toolbar.Separator;
206
+ var CardDragHandle = /* @__PURE__ */ forwardRef((_, forwardedRef) => {
207
+ const { t } = useTranslation(translationKey);
208
+ return /* @__PURE__ */ React2.createElement(Toolbar.IconButton, {
209
+ "data-testid": "card-drag-handle",
210
+ noTooltip: true,
211
+ iconOnly: true,
212
+ icon: "ph--dots-six-vertical--regular",
213
+ variant: "ghost",
214
+ label: t("drag handle label"),
215
+ classNames: "cursor-pointer",
216
+ size: 5,
217
+ disabled: !forwardedRef,
218
+ ref: forwardedRef
219
+ });
220
+ });
221
+ var CardClose = /* @__PURE__ */ forwardRef(({ onClick }, forwardedRef) => {
222
+ const { t } = useTranslation(translationKey);
223
+ return /* @__PURE__ */ React2.createElement(Toolbar.IconButton, {
224
+ iconOnly: true,
225
+ icon: "ph--x--regular",
226
+ variant: "ghost",
227
+ label: t("card close label"),
228
+ classNames: "cursor-pointer",
229
+ size: 5,
230
+ onClick,
231
+ ref: forwardedRef
232
+ });
233
+ });
234
+ var CardMenu = ({ context, items }) => {
235
+ const { t } = useTranslation(translationKey);
236
+ const { menuItems } = useContext(CardContext) ?? {};
237
+ const combinedItems = [
238
+ ...items ?? [],
239
+ ...menuItems ?? []
240
+ ];
241
+ return /* @__PURE__ */ React2.createElement(DropdownMenu.Root, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
242
+ disabled: !combinedItems.length,
243
+ asChild: true
244
+ }, /* @__PURE__ */ React2.createElement(Card.ToolbarIconButton, {
245
+ iconOnly: true,
246
+ variant: "ghost",
247
+ icon: "ph--dots-three-vertical--regular",
248
+ label: t("action menu label")
249
+ })), (combinedItems?.length ?? 0) > 0 && /* @__PURE__ */ React2.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Viewport, null, combinedItems?.map(({ label, onClick: onSelect }, i) => /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
250
+ key: i,
251
+ onSelect: () => onSelect(context)
252
+ }, label))), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null))));
253
+ };
254
+ var CardTitle = /* @__PURE__ */ forwardRef(({ children, classNames, className, asChild, role = "heading", ...props }, forwardedRef) => {
255
+ const Root2 = asChild ? Slot : "div";
256
+ return /* @__PURE__ */ React2.createElement(Root2, {
257
+ ...props,
258
+ role,
259
+ className: mx2("grow truncate", classNames, className),
260
+ ref: forwardedRef
261
+ }, children);
262
+ });
263
+ var CardContent = /* @__PURE__ */ forwardRef(({ children, ...props }, forwardedRef) => {
264
+ return /* @__PURE__ */ React2.createElement("div", {
265
+ role: "none",
266
+ className: "contents [&>:last-child]:pbe-1",
267
+ ...props,
268
+ ref: forwardedRef
269
+ }, children);
270
+ });
271
+ var CardRow = /* @__PURE__ */ forwardRef(({ children, classNames, className, role = "none", icon, ...props }, forwardedRef) => {
272
+ return /* @__PURE__ */ React2.createElement("div", {
273
+ ...props,
274
+ role,
275
+ className: mx2(styles.grid_2, "pli-1", classNames, className),
276
+ ref: forwardedRef
277
+ }, icon && /* @__PURE__ */ React2.createElement(CardIcon, {
278
+ classNames: "text-subdued",
279
+ icon
280
+ }) || /* @__PURE__ */ React2.createElement("div", null), children);
281
+ });
282
+ var CardHeading = /* @__PURE__ */ forwardRef(({ children, classNames, className, asChild, role = "heading", variant = "default", ...props }, forwardedRef) => {
283
+ const Root2 = asChild ? Slot : "div";
284
+ const variantClassNames = {
285
+ default: "plb-1",
286
+ subtitle: "plb-2 text-xs text-description font-medium uppercase"
287
+ };
288
+ return /* @__PURE__ */ React2.createElement(Root2, {
289
+ ...props,
290
+ role,
291
+ className: mx2(variantClassNames[variant], classNames, className),
292
+ ref: forwardedRef
293
+ }, children);
294
+ });
295
+ var CardText = /* @__PURE__ */ forwardRef(({ children, classNames, className, asChild, role = "none", truncate, variant = "default", ...props }, forwardedRef) => {
296
+ const Root2 = asChild ? Slot : "div";
297
+ const variantClassNames = {
298
+ default: {
299
+ root: "plb-1"
300
+ },
301
+ description: {
302
+ root: "plb-1.5",
303
+ span: "text-sm text-description line-clamp-3"
304
+ }
305
+ };
306
+ return /* @__PURE__ */ React2.createElement(Root2, {
307
+ ...props,
308
+ role,
309
+ className: mx2("flex overflow-hidden", variantClassNames[variant].root, classNames, className),
310
+ ref: forwardedRef
311
+ }, /* @__PURE__ */ React2.createElement("span", {
312
+ className: mx2(variantClassNames[variant].span, truncate && "truncate")
313
+ }, children));
314
+ });
315
+ var CardPoster = (props) => {
316
+ const aspect = props.aspect === "auto" ? "aspect-auto" : "aspect-video";
317
+ if (props.image) {
318
+ return /* @__PURE__ */ React2.createElement("div", {
319
+ role: "none",
320
+ className: "mbe-1"
321
+ }, /* @__PURE__ */ React2.createElement(Image, {
322
+ classNames: [
323
+ styles.poster,
324
+ aspect,
325
+ props.classNames
326
+ ],
327
+ src: props.image,
328
+ alt: props.alt
329
+ }));
330
+ }
331
+ if (props.icon) {
332
+ return /* @__PURE__ */ React2.createElement("div", {
333
+ role: "image",
334
+ className: mx2("grid place-items-center bg-inputSurface text-subdued", styles.poster, aspect, props.classNames),
335
+ "aria-label": props.alt
336
+ }, /* @__PURE__ */ React2.createElement(Icon, {
337
+ icon: props.icon,
338
+ size: 10
339
+ }));
340
+ }
341
+ };
342
+ var CardAction = ({ icon, actionIcon = "ph--arrow-right--regular", label, onClick }) => {
343
+ return /* @__PURE__ */ React2.createElement("div", {
344
+ role: "none",
345
+ className: "is-full pli-1"
346
+ }, /* @__PURE__ */ React2.createElement(Button, {
347
+ variant: "ghost",
348
+ classNames: mx2(styles.grid_3, "!p-0 is-full text-start overflow-hidden"),
349
+ onClick
350
+ }, icon ? /* @__PURE__ */ React2.createElement(CardIcon, {
351
+ classNames: "text-subdued",
352
+ icon
353
+ }) : /* @__PURE__ */ React2.createElement("div", null), /* @__PURE__ */ React2.createElement("span", {
354
+ className: mx2("min-is-0 flex-1 truncate", !actionIcon && "col-span-2")
355
+ }, label), actionIcon && /* @__PURE__ */ React2.createElement(CardIcon, {
356
+ icon: actionIcon
357
+ })));
358
+ };
359
+ var CardLink = ({ label, href }) => {
360
+ return /* @__PURE__ */ React2.createElement("div", {
361
+ role: "none",
362
+ className: "is-full pli-1"
363
+ }, /* @__PURE__ */ React2.createElement("a", {
364
+ className: mx2(styles.grid_3, "group !p-0 dx-button dx-focus-ring !min-bs-1"),
365
+ "data-variant": "ghost",
366
+ href,
367
+ target: "_blank",
368
+ rel: "noreferrer"
369
+ }, /* @__PURE__ */ React2.createElement(CardIcon, {
370
+ classNames: "text-subdued",
371
+ icon: "ph--link--regular"
372
+ }), /* @__PURE__ */ React2.createElement("span", {
373
+ className: mx2("min-is-0 flex-1 truncate")
374
+ }, label), /* @__PURE__ */ React2.createElement(CardIcon, {
375
+ classNames: "invisible group-hover:visible",
376
+ icon: "ph--arrow-square-out--regular"
377
+ })));
378
+ };
379
+ var CardIcon = ({ toolbar, ...props }) => {
380
+ return /* @__PURE__ */ React2.createElement("div", {
381
+ role: "none",
382
+ className: "grid bs-[var(--rail-item)] is-[var(--rail-item)] place-items-center"
383
+ }, /* @__PURE__ */ React2.createElement(Icon, {
384
+ ...props,
385
+ size: toolbar ? 5 : 4
386
+ }));
387
+ };
388
+ var Card = {
389
+ Context: CardContext,
390
+ Root: CardRoot,
391
+ // Toolbar
392
+ Toolbar: CardToolbar,
393
+ ToolbarIconButton: CardToolbarIconButton,
394
+ ToolbarSeparator: CardToolbarSeparator,
395
+ DragHandle: CardDragHandle,
396
+ Title: CardTitle,
397
+ Close: CardClose,
398
+ Menu: CardMenu,
399
+ Icon: CardIcon,
400
+ // Content
401
+ Content: CardContent,
402
+ Row: CardRow,
403
+ Heading: CardHeading,
404
+ Text: CardText,
405
+ Poster: CardPoster,
406
+ Action: CardAction,
407
+ Link: CardLink
408
+ };
409
+
410
+ // src/components/Focus/styles.ts
411
+ var styles2 = {
412
+ container: {
413
+ // TODO(burdon): Handle selection (aria-current?)
414
+ // TODO(burdon): Use ring instead of border?
415
+ root: [
416
+ "outline-none border border-separator rounded-sm",
417
+ // Focus (e.g., via tabster).
418
+ // TODO(burdon): Why is ! required?
419
+ "focus:!border-accentSurface",
420
+ // Active (e.g., drop target).
421
+ "data-[focus-state=active]:border-neutralFocusIndicator",
422
+ // Error
423
+ // TODO(burdon): Error token.
424
+ "data-[focus-state=error]:border-rose-500"
425
+ ]
426
+ }
427
+ };
428
+
429
+ // src/components/Focus/Focus.tsx
430
+ import { useArrowNavigationGroup, useFocusableGroup, useMergedTabsterAttributes_unstable } from "@fluentui/react-tabster";
431
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
432
+ import { Primitive } from "@radix-ui/react-primitive";
433
+ import { Slot as Slot2 } from "@radix-ui/react-slot";
434
+ import React3, { createContext as createContext2, forwardRef as forwardRef2, useContext as useContext2, useRef as useRef2, useState as useState2 } from "react";
435
+ import { mx as mx3 } from "@dxos/ui-theme";
436
+ var FOCUS_STATE_ATTR = "focus-state";
437
+ var FocusContext = /* @__PURE__ */ createContext2({});
438
+ var useFocus = () => useContext2(FocusContext);
439
+ var Group = /* @__PURE__ */ forwardRef2(({ classNames, className, children, asChild, axis = "vertical", ...props }, forwardedRef) => {
440
+ const rootRef = useRef2(null);
441
+ const composedRef = useComposedRefs(rootRef, forwardedRef);
442
+ const Root2 = asChild ? Slot2 : Primitive.div;
443
+ const focusableGroupAttrs = useFocusableGroup({
444
+ tabBehavior: "limited-trap-focus"
445
+ });
446
+ const arrowNavigationAttrs = useArrowNavigationGroup({
447
+ axis,
448
+ memorizeCurrent: true
449
+ });
450
+ const tabsterAttrs = useMergedTabsterAttributes_unstable(focusableGroupAttrs, arrowNavigationAttrs);
451
+ const [state, setState] = useState2();
452
+ return /* @__PURE__ */ React3.createElement(FocusContext.Provider, {
453
+ value: {
454
+ setFocus: setState
455
+ }
456
+ }, /* @__PURE__ */ React3.createElement(Root2, {
457
+ tabIndex: 0,
458
+ className: mx3(styles2.container.root, className, classNames),
459
+ ...tabsterAttrs,
460
+ ...state && {
461
+ [`data-${FOCUS_STATE_ATTR}`]: state
462
+ },
463
+ ...props,
464
+ ref: composedRef
465
+ }, children));
466
+ });
467
+ var Focus = {
468
+ Group
469
+ };
470
+
471
+ // src/components/Mosaic/styles.ts
472
+ var styles3 = {
473
+ placeholder: {
474
+ root: [
475
+ "group opacity-0",
476
+ 'group-data-[mosaic-debug="true"]:opacity-100',
477
+ 'group-data-[mosaic-debug="true"]:bg-orange-500',
478
+ "data-[mosaic-placeholder-state=active]:opacity-100",
479
+ "data-[mosaic-placeholder-axis=vertical]:plb-1",
480
+ "data-[mosaic-placeholder-axis=vertical]:data-[mosaic-placeholder-state=active]:plb-2.5",
481
+ "data-[mosaic-placeholder-axis=horizontal]:pli-1",
482
+ "data-[mosaic-placeholder-axis=horizontal]:data-[mosaic-placeholder-state=active]:pli-2.5"
483
+ ],
484
+ content: [
485
+ "transition-all duration-0",
486
+ // TODO(burdon): Don't animate open if placeholder is the source.
487
+ // TODO(burdon): Flickers when start to drag since source is removed and then the placeholder shows up.
488
+ // - Use absolute positioning?
489
+ // 'group-data-[mosaic-placeholder-state=active]:duration-200',
490
+ "group-data-[mosaic-placeholder-axis=vertical]:bs-0",
491
+ "group-data-[mosaic-placeholder-axis=horizontal]:is-0",
492
+ "group-data-[mosaic-placeholder-axis=vertical]:group-data-[mosaic-placeholder-state=active]:bs-[var(--mosaic-placeholder-height)]",
493
+ "group-data-[mosaic-placeholder-axis=horizontal]:group-data-[mosaic-placeholder-state=active]:is-[var(--mosaic-placeholder-width)]"
494
+ ]
495
+ }
496
+ };
497
+
498
+ // src/components/Mosaic/extension.ts
499
+ import { StateEffect, StateField } from "@codemirror/state";
500
+ import { Decoration, EditorView, ViewPlugin, WidgetType } from "@codemirror/view";
501
+ var dropHandler = ({ onDrop = handleDrop } = {}) => {
502
+ const views = /* @__PURE__ */ new Set();
503
+ let state = null;
504
+ const reset = () => {
505
+ views.forEach((view) => view.dispatch({
506
+ effects: setDrop.of(null)
507
+ }));
508
+ state = null;
509
+ };
510
+ const extension = [
511
+ dropField,
512
+ ViewPlugin.fromClass(class {
513
+ _view;
514
+ constructor(_view) {
515
+ this._view = _view;
516
+ views.add(_view);
517
+ }
518
+ destroy() {
519
+ views.delete(this._view);
520
+ }
521
+ })
522
+ ];
523
+ return {
524
+ extension,
525
+ update: (position) => {
526
+ if (!position) {
527
+ reset();
528
+ return;
529
+ }
530
+ views.forEach((view) => {
531
+ const rect = view.dom.getBoundingClientRect();
532
+ if (position.x >= rect.left && position.x <= rect.right && position.y >= rect.top && position.y <= rect.bottom) {
533
+ let pos = view.posAtCoords(position);
534
+ if (pos !== null) {
535
+ const word = view.state.wordAt(pos);
536
+ if (word) {
537
+ const startDist = Math.abs(pos - word.from);
538
+ const endDist = Math.abs(pos - word.to);
539
+ pos = startDist < endDist ? word.from : word.to;
540
+ }
541
+ view.dispatch({
542
+ effects: setDrop.of(pos)
543
+ });
544
+ state = {
545
+ view,
546
+ pos
547
+ };
548
+ return;
549
+ }
550
+ }
551
+ view.dispatch({
552
+ effects: setDrop.of(null)
553
+ });
554
+ });
555
+ },
556
+ cancel: () => {
557
+ reset();
558
+ },
559
+ drop: ({ text, url }) => {
560
+ if (state) {
561
+ onDrop(state.view, state.pos, {
562
+ text,
563
+ url
564
+ });
565
+ }
566
+ reset();
567
+ }
568
+ };
569
+ };
570
+ var handleDrop = (view, pos, event) => {
571
+ const line = view.state.doc.lineAt(pos);
572
+ if (line.text.trim() === "") {
573
+ view.dispatch({
574
+ changes: {
575
+ from: pos,
576
+ insert: `
577
+ ![${event.text}](${event.url})
578
+ `
579
+ },
580
+ effects: setDrop.of(null)
581
+ });
582
+ } else {
583
+ view.dispatch({
584
+ changes: {
585
+ from: pos,
586
+ insert: ` [${event.text}](${event.url})`
587
+ },
588
+ effects: setDrop.of(null)
589
+ });
590
+ }
591
+ };
592
+ var setDrop = StateEffect.define();
593
+ var dropField = StateField.define({
594
+ create: () => Decoration.none,
595
+ update: (decorations, tr) => {
596
+ for (const effect of tr.effects) {
597
+ if (effect.is(setDrop)) {
598
+ if (effect.value === null) {
599
+ return Decoration.none;
600
+ }
601
+ return Decoration.set([
602
+ Decoration.widget({
603
+ widget: new class extends WidgetType {
604
+ toDOM() {
605
+ const dom = document.createElement("span");
606
+ dom.className = "cm-drop-cursor";
607
+ dom.style.borderLeft = "2px solid var(--dx-accentSurface)";
608
+ dom.style.display = "inline-block";
609
+ dom.style.height = "1em";
610
+ dom.style.verticalAlign = "middle";
611
+ return dom;
612
+ }
613
+ }(),
614
+ side: 0
615
+ }).range(effect.value)
616
+ ]);
617
+ }
618
+ }
619
+ return decorations.map(tr.changes);
620
+ },
621
+ provide: (field) => EditorView.decorations.from(field)
622
+ });
623
+
624
+ // src/hooks/useContainerDebug.tsx
625
+ import React7, { forwardRef as forwardRef6, useMemo as useMemo5, useRef as useRef5 } from "react";
626
+ import { createPortal as createPortal2 } from "react-dom";
627
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
628
+ import { mx as mx7 } from "@dxos/ui-theme";
629
+
630
+ // src/components/Mosaic/Mosaic.tsx
631
+ import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
632
+ import { draggable, dropTargetForElements, monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
633
+ import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
634
+ import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
635
+ import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
636
+ import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
637
+ import { DropIndicator as NativeDropIndicator } from "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box";
638
+ import { composeRefs, useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
639
+ import { createContext as createContext3 } from "@radix-ui/react-context";
640
+ import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
641
+ import { Slot as Slot3 } from "@radix-ui/react-slot";
642
+ import { bind } from "bind-event-listener";
643
+ import React6, { forwardRef as forwardRef5, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo4, useRef as useRef4, useState as useState3 } from "react";
644
+ import { createPortal } from "react-dom";
645
+ import { log as log2 } from "@dxos/log";
646
+ import { mx as mx6 } from "@dxos/ui-theme";
647
+ import { isTruthy } from "@dxos/util";
648
+
649
+ // src/components/Scrollable/Scrollable.tsx
650
+ import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
651
+ import React4, { forwardRef as forwardRef3, useEffect, useMemo, useRef as useRef3 } from "react";
652
+ import { mx as mx4 } from "@dxos/ui-theme";
653
+ import "overlayscrollbars/styles/overlayscrollbars.css";
654
+ var defaultOptions = {
655
+ scrollbars: {
656
+ autoHide: "leave",
657
+ autoHideDelay: 1e3,
658
+ autoHideSuspend: true
659
+ }
660
+ };
661
+ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", padding, options: optionsProp = defaultOptions, onScroll, viewportRef, ...props }, forwardedRef) => {
662
+ const osRef = useRef3(null);
663
+ const options = useMemo(() => {
664
+ const options2 = {
665
+ ...optionsProp
666
+ };
667
+ if (axis) {
668
+ options2.overflow = {
669
+ x: axis === "horizontal" ? "scroll" : "hidden",
670
+ y: axis === "vertical" ? "scroll" : "hidden"
671
+ };
672
+ }
673
+ return options2;
674
+ }, [
675
+ axis,
676
+ optionsProp
677
+ ]);
678
+ useEffect(() => {
679
+ const hostElement = osRef.current?.getElement();
680
+ if (forwardedRef) {
681
+ if (typeof forwardedRef === "function") {
682
+ forwardedRef(hostElement ?? null);
683
+ } else {
684
+ forwardedRef.current = hostElement ?? null;
685
+ }
686
+ }
687
+ });
688
+ useEffect(() => {
689
+ const instance = osRef.current?.osInstance();
690
+ if (viewportRef) {
691
+ viewportRef.current = instance?.elements().viewport ?? null;
692
+ }
693
+ }, [
694
+ osRef,
695
+ viewportRef
696
+ ]);
697
+ const events = useMemo(() => {
698
+ if (!onScroll) {
699
+ return null;
700
+ }
701
+ return {
702
+ scroll: (_, event) => {
703
+ onScroll(event);
704
+ }
705
+ };
706
+ }, [
707
+ onScroll
708
+ ]);
709
+ return /* @__PURE__ */ React4.createElement(OverlayScrollbarsComponent, {
710
+ ...props,
711
+ className: mx4(padding && axis === "vertical" ? "pli-3" : "pbe-3", classNames),
712
+ options,
713
+ events,
714
+ ref: osRef
715
+ });
716
+ });
717
+
718
+ // src/components/Stack/Stack.tsx
719
+ import { useVirtualizer } from "@tanstack/react-virtual";
720
+ import React5, { Fragment, forwardRef as forwardRef4 } from "react";
721
+ import { invariant } from "@dxos/invariant";
722
+ import { mx as mx5 } from "@dxos/ui-theme";
723
+
724
+ // src/hooks/useEventHandlerAdapter.ts
725
+ import { useMemo as useMemo2 } from "react";
726
+ import { log } from "@dxos/log";
727
+ import { arrayMove } from "@dxos/util";
728
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/hooks/useEventHandlerAdapter.ts";
729
+ var useEventHandlerAdapter = ({ items, getId, get, make, onChange, ...props }) => {
730
+ return useMemo2(() => ({
731
+ ...props,
732
+ onTake: ({ source }, cb) => {
733
+ log.info("onTake", {
734
+ source
735
+ }, {
736
+ F: __dxlog_file,
737
+ L: 58,
738
+ S: void 0,
739
+ C: (f, a) => f(...a)
740
+ });
741
+ const mutate = (items2) => {
742
+ const from = items2.findIndex((item) => getId(item) === source.id);
743
+ if (from !== -1) {
744
+ items2.splice(from, 1);
745
+ }
746
+ };
747
+ if (onChange) {
748
+ onChange(mutate);
749
+ } else {
750
+ mutate(items);
751
+ }
752
+ void cb(source.data);
753
+ },
754
+ onDrop: ({ source, target }) => {
755
+ const to = target?.type === "tile" || target?.type === "placeholder" ? target.location : -1;
756
+ log.info("onDrop", {
757
+ source,
758
+ target,
759
+ to
760
+ }, {
761
+ F: __dxlog_file,
762
+ L: 76,
763
+ S: void 0,
764
+ C: (f, a) => f(...a)
765
+ });
766
+ const mutate = (items2) => {
767
+ const from = items2.findIndex((item) => getId(item) === source.id);
768
+ if (to !== -1) {
769
+ if (from !== -1) {
770
+ arrayMove(items2, from, to);
771
+ } else {
772
+ items2.splice(to, 0, make(get(source.data)));
773
+ }
774
+ }
775
+ };
776
+ if (onChange) {
777
+ onChange(mutate);
778
+ } else {
779
+ mutate(items);
780
+ }
781
+ }
782
+ }), [
783
+ items,
784
+ onChange
785
+ ]);
786
+ };
787
+
788
+ // src/hooks/useVisibleItems.ts
789
+ import { useMemo as useMemo3 } from "react";
790
+ var useVisibleItems = ({ id, items, dragging, getId }) => {
791
+ const visibleItems = useMemo3(() => {
792
+ if (!items || !dragging || id !== dragging.containerId) {
793
+ return items ?? [];
794
+ }
795
+ const idx = items.findIndex((item) => getId(item) === dragging.id);
796
+ if (idx === -1) {
797
+ return items;
798
+ }
799
+ const visibleItems2 = items.slice();
800
+ visibleItems2.splice(idx, 1);
801
+ return visibleItems2;
802
+ }, [
803
+ id,
804
+ items,
805
+ dragging,
806
+ getId
807
+ ]);
808
+ return visibleItems;
809
+ };
810
+
811
+ // src/components/Stack/Stack.tsx
812
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
813
+ var StackInner = /* @__PURE__ */ forwardRef4(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
814
+ invariant(Tile2, void 0, {
815
+ F: __dxlog_file2,
816
+ L: 44,
817
+ S: void 0,
818
+ A: [
819
+ "Tile",
820
+ ""
821
+ ]
822
+ });
823
+ const { id, dragging } = useContainerContext(StackInner.displayName);
824
+ const visibleItems = useVisibleItems({
825
+ id,
826
+ items,
827
+ dragging: dragging?.source.data,
828
+ getId
829
+ });
830
+ return /* @__PURE__ */ React5.createElement("div", {
831
+ ...props,
832
+ role,
833
+ className: mx5("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
834
+ ref: forwardedRef
835
+ }, /* @__PURE__ */ React5.createElement(Placeholder, {
836
+ axis,
837
+ location: 0.5
838
+ }), visibleItems?.map((item, index) => /* @__PURE__ */ React5.createElement(Fragment, {
839
+ key: getId(item)
840
+ }, /* @__PURE__ */ React5.createElement(Tile2, {
841
+ id: getId(item),
842
+ data: item,
843
+ location: index + 1,
844
+ draggable: draggable2,
845
+ debug
846
+ }), /* @__PURE__ */ React5.createElement(Placeholder, {
847
+ axis,
848
+ location: index + 1.5
849
+ }))));
850
+ });
851
+ StackInner.displayName = "Stack";
852
+ var Stack = StackInner;
853
+ var VirtualStackInner = /* @__PURE__ */ forwardRef4(({ className, classNames, role = "list", axis = "vertical", items, getId, Tile: Tile2, estimateSize, getScrollElement, overscan = 8, onChange, debug, ...props }, forwardedRef) => {
854
+ invariant(Tile2, void 0, {
855
+ F: __dxlog_file2,
856
+ L: 106,
857
+ S: void 0,
858
+ A: [
859
+ "Tile",
860
+ ""
861
+ ]
862
+ });
863
+ const { id, dragging } = useContainerContext(VirtualStackInner.displayName);
864
+ const visibleItems = useVisibleItems({
865
+ id,
866
+ items,
867
+ dragging: dragging?.source.data,
868
+ getId
869
+ });
870
+ const virtualizer = useVirtualizer({
871
+ count: visibleItems.length * 2 + 1,
872
+ estimateSize,
873
+ getScrollElement,
874
+ overscan,
875
+ onChange
876
+ });
877
+ const virtualItems = virtualizer.getVirtualItems();
878
+ return /* @__PURE__ */ React5.createElement("div", {
879
+ ...props,
880
+ role,
881
+ className: mx5("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
882
+ style: {
883
+ position: "relative",
884
+ ...axis === "vertical" ? {
885
+ width: "100%",
886
+ height: virtualizer.getTotalSize()
887
+ } : {
888
+ width: virtualizer.getTotalSize(),
889
+ height: "100%"
890
+ }
891
+ },
892
+ ref: forwardedRef
893
+ }, virtualItems.map((virtualItem) => {
894
+ const data = visibleItems[Math.floor(virtualItem.index / 2)];
895
+ return /* @__PURE__ */ React5.createElement("div", {
896
+ key: virtualItem.key,
897
+ "data-index": virtualItem.index,
898
+ style: {
899
+ position: "absolute",
900
+ top: 0,
901
+ left: 0,
902
+ ...axis === "vertical" ? {
903
+ width: "100%",
904
+ transform: `translateY(${virtualItem.start}px)`
905
+ } : {
906
+ height: "100%",
907
+ transform: `translateX(${virtualItem.start}px)`
908
+ }
909
+ },
910
+ ref: virtualizer.measureElement
911
+ }, virtualItem.index % 2 === 0 ? /* @__PURE__ */ React5.createElement(Placeholder, {
912
+ axis,
913
+ location: Math.floor(virtualItem.index / 2) + 0.5
914
+ }) : /* @__PURE__ */ React5.createElement(Tile2, {
915
+ id: getId(data),
916
+ data,
917
+ location: Math.floor(virtualItem.index / 2) + 1,
918
+ debug
919
+ }));
920
+ }));
921
+ });
922
+ VirtualStackInner.displayName = "VirtualStackInner";
923
+ var VirtualStack = VirtualStackInner;
924
+ var Placeholder = (props) => {
925
+ return /* @__PURE__ */ React5.createElement(Mosaic.Placeholder, {
926
+ ...props,
927
+ classNames: styles3.placeholder.root
928
+ }, /* @__PURE__ */ React5.createElement("div", {
929
+ className: mx5("flex bs-full bg-baseSurface border border-dashed border-separator rounded-sm", styles3.placeholder.content)
930
+ }));
931
+ };
932
+ Placeholder.displayName = "Placeholder";
933
+
934
+ // src/components/Mosaic/Mosaic.tsx
935
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Mosaic.tsx";
936
+ var getSourceData = (source) => {
937
+ return source.data.type === "tile" ? source.data : null;
938
+ };
939
+ var [RootContextProvider, useRootContext] = createContext3("MosaicRoot");
940
+ var ROOT_DEBUG_ATTR = "mosaic-debug";
941
+ var Root = /* @__PURE__ */ forwardRef5(({ classNames, children, asChild, debug }, forwardedRef) => {
942
+ const rootRef = useRef4(null);
943
+ const composedRef = useComposedRefs2(rootRef, forwardedRef);
944
+ const Root2 = asChild ? Slot3 : Primitive2.div;
945
+ const [handlers, setHandlers] = useState3({});
946
+ const [dragging, setDragging] = useState3();
947
+ const getSourceHandler = useCallback2((source) => {
948
+ const data = source.data;
949
+ return {
950
+ data,
951
+ handler: handlers[data.containerId]
952
+ };
953
+ }, [
954
+ handlers
955
+ ]);
956
+ const getTargetHandler = useCallback2((location) => {
957
+ for (const target of location.current.dropTargets) {
958
+ const data = target.data;
959
+ let containerId;
960
+ switch (data.type) {
961
+ case "tile":
962
+ case "placeholder":
963
+ containerId = data.containerId;
964
+ break;
965
+ case "container":
966
+ containerId = data.id;
967
+ break;
968
+ }
969
+ const handler = handlers[containerId];
970
+ if (handler) {
971
+ return {
972
+ data,
973
+ handler
974
+ };
975
+ }
976
+ }
977
+ return {};
978
+ }, [
979
+ handlers
980
+ ]);
981
+ useEffect2(() => {
982
+ const handleChange = ({ source, location }) => {
983
+ const { data: sourceData } = getSourceHandler(source);
984
+ const { data: targetData, handler } = getTargetHandler(location);
985
+ setDragging((dragging2) => {
986
+ dragging2?.target?.handler?.onCancel?.();
987
+ return {
988
+ source: {
989
+ data: sourceData,
990
+ handler: handlers[sourceData.containerId],
991
+ // TOOD(burdon): Check id matches.
992
+ container: location.initial.dropTargets.find((target) => target.data.type === "container")?.element
993
+ },
994
+ target: targetData && {
995
+ data: targetData,
996
+ handler
997
+ }
998
+ };
999
+ });
1000
+ };
1001
+ const handleCancel = () => {
1002
+ setDragging((dragging2) => {
1003
+ requestAnimationFrame(() => {
1004
+ dragging2?.target?.handler?.onCancel?.();
1005
+ dragging2?.source?.container?.dispatchEvent(new CustomEvent("dnd:cancel", {
1006
+ bubbles: true
1007
+ }));
1008
+ });
1009
+ return void 0;
1010
+ });
1011
+ };
1012
+ let noTargetTimeout;
1013
+ return combine(monitorForElements({
1014
+ /**
1015
+ * Dragging started within any container.
1016
+ */
1017
+ onDragStart: ({ source, location }) => {
1018
+ log2("Root.onDragStart", {
1019
+ source: source.data,
1020
+ location: location.current.dropTargets.map((target) => target.data)
1021
+ }, {
1022
+ F: __dxlog_file3,
1023
+ L: 215,
1024
+ S: void 0,
1025
+ C: (f, a) => f(...a)
1026
+ });
1027
+ handleChange({
1028
+ source,
1029
+ location
1030
+ });
1031
+ },
1032
+ /**
1033
+ * Dragging entered a new container.
1034
+ */
1035
+ onDropTargetChange: ({ source, location }) => {
1036
+ clearTimeout(noTargetTimeout);
1037
+ log2("Root.onDropTargetChange", {
1038
+ source: source.data,
1039
+ location: location.current.dropTargets.map((target) => target.data)
1040
+ }, {
1041
+ F: __dxlog_file3,
1042
+ L: 228,
1043
+ S: void 0,
1044
+ C: (f, a) => f(...a)
1045
+ });
1046
+ if (location.current.dropTargets.length === 0) {
1047
+ noTargetTimeout = setTimeout(() => setDragging(void 0), 1e3);
1048
+ } else {
1049
+ handleChange({
1050
+ source,
1051
+ location
1052
+ });
1053
+ }
1054
+ },
1055
+ /**
1056
+ * Dragging within any container.
1057
+ */
1058
+ onDrag: ({ source, location }) => {
1059
+ const { data } = getSourceHandler(source);
1060
+ const { handler } = getTargetHandler(location);
1061
+ if (handler) {
1062
+ const { clientX: x, clientY: y } = location.current.input;
1063
+ handler.onDrag?.({
1064
+ source: data,
1065
+ position: {
1066
+ x,
1067
+ y
1068
+ }
1069
+ });
1070
+ }
1071
+ },
1072
+ /**
1073
+ * Dragging ended.
1074
+ */
1075
+ onDrop: ({ source, location }) => {
1076
+ log2.info("Root.onDrop", {
1077
+ source: source.data,
1078
+ location: location.current.dropTargets.map((target) => target.data)
1079
+ }, {
1080
+ F: __dxlog_file3,
1081
+ L: 257,
1082
+ S: void 0,
1083
+ C: (f, a) => f(...a)
1084
+ });
1085
+ const { data: sourceData, handler: sourceHandler } = getSourceHandler(source);
1086
+ if (!sourceHandler) {
1087
+ log2.warn("invalid source", {
1088
+ source: sourceData,
1089
+ handlers: Object.keys(handlers)
1090
+ }, {
1091
+ F: __dxlog_file3,
1092
+ L: 265,
1093
+ S: void 0,
1094
+ C: (f, a) => f(...a)
1095
+ });
1096
+ return;
1097
+ }
1098
+ try {
1099
+ if (location.current.dropTargets.length === 0) {
1100
+ log2.info("cancelled", void 0, {
1101
+ F: __dxlog_file3,
1102
+ L: 280,
1103
+ S: void 0,
1104
+ C: (f, a) => f(...a)
1105
+ });
1106
+ } else {
1107
+ const { data: targetData, handler: targetHandler } = getTargetHandler(location);
1108
+ if (!targetHandler) {
1109
+ log2.warn("invalid target", {
1110
+ source: sourceData,
1111
+ location,
1112
+ handlers: Object.keys(handlers)
1113
+ }, {
1114
+ F: __dxlog_file3,
1115
+ L: 285,
1116
+ S: void 0,
1117
+ C: (f, a) => f(...a)
1118
+ });
1119
+ return;
1120
+ }
1121
+ if (sourceHandler === targetHandler) {
1122
+ targetHandler.onDrop?.({
1123
+ source: sourceData,
1124
+ target: targetData
1125
+ });
1126
+ } else {
1127
+ if (!sourceHandler.onTake) {
1128
+ log2.warn("invalid source", {
1129
+ source: sourceData
1130
+ }, {
1131
+ F: __dxlog_file3,
1132
+ L: 301,
1133
+ S: void 0,
1134
+ C: (f, a) => f(...a)
1135
+ });
1136
+ return;
1137
+ }
1138
+ sourceHandler.onTake?.({
1139
+ source: sourceData
1140
+ }, async (object) => {
1141
+ targetHandler.onDrop?.({
1142
+ // TODO(burdon): Change source!!!
1143
+ source: {
1144
+ ...sourceData,
1145
+ data: object
1146
+ },
1147
+ target: targetData
1148
+ });
1149
+ return true;
1150
+ });
1151
+ }
1152
+ }
1153
+ } finally {
1154
+ handleCancel();
1155
+ }
1156
+ }
1157
+ }));
1158
+ }, [
1159
+ handlers,
1160
+ getSourceHandler,
1161
+ getTargetHandler
1162
+ ]);
1163
+ return /* @__PURE__ */ React6.createElement(RootContextProvider, {
1164
+ containers: handlers,
1165
+ addContainer: (container) => setHandlers((containers) => ({
1166
+ ...containers,
1167
+ [container.id]: container
1168
+ })),
1169
+ removeContainer: (id) => setHandlers((containers) => {
1170
+ delete containers[id];
1171
+ return {
1172
+ ...containers
1173
+ };
1174
+ }),
1175
+ dragging
1176
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1177
+ className: mx6("group overflow-hidden", classNames),
1178
+ [`data-${ROOT_DEBUG_ATTR}`]: debug,
1179
+ ref: composedRef
1180
+ }, children));
1181
+ });
1182
+ var [ContainerContextProvider, useContainerContext] = createContext3("MosaicContainer");
1183
+ var CONTAINER_STATE_ATTR = "mosaic-container-state";
1184
+ var CONTAINER_PLACEHOLDER_WIDTH = "--mosaic-placeholder-width";
1185
+ var CONTAINER_PLACEHOLDER_HEIGHT = "--mosaic-placeholder-height";
1186
+ var counter = 0;
1187
+ var Container = /* @__PURE__ */ forwardRef5(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
1188
+ const rootRef = useRef4(null);
1189
+ const composedRef = useComposedRefs2(rootRef, forwardedRef);
1190
+ const Root2 = asChild ? Slot3 : Primitive2.div;
1191
+ const eventHandler = useMemo4(() => eventHandlerProp ?? {
1192
+ id: `mosaic-container-${counter++}`
1193
+ }, [
1194
+ eventHandlerProp
1195
+ ]);
1196
+ const { dragging } = useRootContext(Container.displayName);
1197
+ const [state, setState] = useState3({
1198
+ type: "idle"
1199
+ });
1200
+ const [activeLocation, setActiveLocation] = useState3();
1201
+ const [scrolling, setScrolling] = useState3(false);
1202
+ const { setFocus } = useFocus();
1203
+ useEffect2(() => {
1204
+ if (withFocus) {
1205
+ setFocus?.(state.type === "active" ? "active" : void 0);
1206
+ }
1207
+ }, [
1208
+ setFocus,
1209
+ withFocus,
1210
+ state
1211
+ ]);
1212
+ const { addContainer, removeContainer } = useRootContext(eventHandler.id);
1213
+ useEffect2(() => {
1214
+ addContainer(eventHandler);
1215
+ return () => removeContainer(eventHandler.id);
1216
+ }, [
1217
+ eventHandler
1218
+ ]);
1219
+ const data = useMemo4(() => ({
1220
+ type: "container",
1221
+ id: eventHandler.id
1222
+ }), [
1223
+ eventHandler.id
1224
+ ]);
1225
+ useEffect2(() => {
1226
+ if (!rootRef.current) {
1227
+ return;
1228
+ }
1229
+ let timeout;
1230
+ const handleScroll = () => {
1231
+ setScrolling(true);
1232
+ clearTimeout(timeout);
1233
+ timeout = setTimeout(() => {
1234
+ setScrolling(false);
1235
+ }, 500);
1236
+ };
1237
+ return combine(...[
1238
+ // Autoscroll.
1239
+ // TODO(burdon): Autoscroll doesn't work well horizontally.
1240
+ autoscrollElement && [
1241
+ autoScrollForElements({
1242
+ element: autoscrollElement,
1243
+ canScroll: ({ element: _ }) => {
1244
+ return true;
1245
+ },
1246
+ getAllowedAxis: () => axis,
1247
+ getConfiguration: () => ({
1248
+ maxScrollSpeed: "fast"
1249
+ })
1250
+ }),
1251
+ bind(autoscrollElement, {
1252
+ type: "scroll",
1253
+ listener: handleScroll
1254
+ }),
1255
+ () => setScrolling(false)
1256
+ ],
1257
+ // Target.
1258
+ dropTargetForElements({
1259
+ element: rootRef.current,
1260
+ getData: () => data,
1261
+ /**
1262
+ * Test if permitted to drop here.
1263
+ * NOTE: Contained Tile and Placeholder elements do the same.
1264
+ */
1265
+ canDrop: ({ source }) => {
1266
+ const data2 = getSourceData(source);
1267
+ return data2 && eventHandler.canDrop?.({
1268
+ source: data2
1269
+ }) || false;
1270
+ },
1271
+ // TODO(burdon): Provide semantic intent to onDrop.
1272
+ // getDropEffect: () => {
1273
+ // return 'move';
1274
+ // },
1275
+ /**
1276
+ * Dragging started in this container.
1277
+ */
1278
+ onDragStart: ({ source }) => {
1279
+ const sourceData = source.data;
1280
+ setState({
1281
+ type: "active",
1282
+ bounds: sourceData.bounds
1283
+ });
1284
+ },
1285
+ /**
1286
+ * Dragging entered this container.
1287
+ */
1288
+ onDragEnter: ({ source }) => {
1289
+ const sourceData = source.data;
1290
+ setState({
1291
+ type: "active",
1292
+ bounds: sourceData.bounds
1293
+ });
1294
+ },
1295
+ /**
1296
+ * Dragging left this container.
1297
+ * NOTE: If the container isn't full-height, then when the dragged item is temporarily removed the container will shrink,
1298
+ * triggering `onDragLeave`, which then causes the item to be added and removed continually (flickering).
1299
+ */
1300
+ onDragLeave: ({ source }) => {
1301
+ const sourceData = source.data;
1302
+ if (sourceData.containerId !== eventHandler.id) {
1303
+ setState({
1304
+ type: "idle"
1305
+ });
1306
+ }
1307
+ },
1308
+ /**
1309
+ * Dropped in this container.
1310
+ */
1311
+ onDrop: () => {
1312
+ setState({
1313
+ type: "idle"
1314
+ });
1315
+ }
1316
+ }),
1317
+ /**
1318
+ * Custom event for dragging cancellation.
1319
+ */
1320
+ bind(rootRef.current, {
1321
+ type: "dnd:cancel",
1322
+ listener: () => {
1323
+ setState({
1324
+ type: "idle"
1325
+ });
1326
+ }
1327
+ })
1328
+ ].filter(isTruthy).flatMap((x) => x));
1329
+ }, [
1330
+ rootRef,
1331
+ eventHandler,
1332
+ data,
1333
+ autoscrollElement
1334
+ ]);
1335
+ return /* @__PURE__ */ React6.createElement(ContainerContextProvider, {
1336
+ id: eventHandler.id,
1337
+ eventHandler,
1338
+ axis,
1339
+ state,
1340
+ dragging: state.type === "active" ? dragging : void 0,
1341
+ scrolling,
1342
+ activeLocation,
1343
+ setActiveLocation
1344
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1345
+ className: mx6("bs-full", className, classNames),
1346
+ style: {
1347
+ [CONTAINER_PLACEHOLDER_WIDTH]: state.type === "active" && state.bounds ? `${state.bounds.width}px` : "0px",
1348
+ [CONTAINER_PLACEHOLDER_HEIGHT]: state.type === "active" && state.bounds ? `${state.bounds.height}px` : "0px"
1349
+ },
1350
+ ...props,
1351
+ [`data-${CONTAINER_STATE_ATTR}`]: state.type,
1352
+ ref: composedRef
1353
+ }, children), debug?.());
1354
+ });
1355
+ Container.displayName = "MosaicContainer";
1356
+ var [TileContextProvider, useTileContext] = createContext3("MosaicTile");
1357
+ var TILE_STATE_ATTR = "mosaic-tile-state";
1358
+ var Tile = /* @__PURE__ */ forwardRef5(({ className, classNames, children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, debug: _ }, forwardedRef) => {
1359
+ const rootRef = useRef4(null);
1360
+ const composedRef = composeRefs(rootRef, forwardedRef);
1361
+ const Root2 = asChild ? Slot3 : Primitive2.div;
1362
+ const { id: containerId, eventHandler, axis, scrolling, setActiveLocation } = useContainerContext(Tile.displayName);
1363
+ const [state, setState] = useState3({
1364
+ type: "idle"
1365
+ });
1366
+ const allowedEdges = useMemo4(() => allowedEdgesProp || (axis === "vertical" ? [
1367
+ "top",
1368
+ "bottom"
1369
+ ] : [
1370
+ "left",
1371
+ "right"
1372
+ ]), [
1373
+ allowedEdgesProp,
1374
+ axis
1375
+ ]);
1376
+ const data = useMemo4(() => ({
1377
+ type: "tile",
1378
+ id,
1379
+ containerId,
1380
+ data: dataProp,
1381
+ location
1382
+ }), [
1383
+ containerId,
1384
+ location,
1385
+ dataProp
1386
+ ]);
1387
+ useLayoutEffect(() => {
1388
+ const root = rootRef.current;
1389
+ if (!root || !containerId || scrolling) {
1390
+ return;
1391
+ }
1392
+ const handleChange = ({ self, source }) => {
1393
+ if (source.data.id !== dataProp.id) {
1394
+ const closestEdge = extractClosestEdge(self.data);
1395
+ const location2 = data.location + (closestEdge === "top" || closestEdge === "left" ? -0.5 : 0.5);
1396
+ setActiveLocation(location2);
1397
+ setState({
1398
+ type: "target",
1399
+ closestEdge
1400
+ });
1401
+ }
1402
+ };
1403
+ return combine(
1404
+ // Source.
1405
+ draggable({
1406
+ element: root,
1407
+ dragHandle: dragHandle && state.type !== "preview" ? dragHandle : void 0,
1408
+ canDrag: () => true,
1409
+ getInitialData: () => data,
1410
+ onGenerateDragPreview: ({ location: location2, nativeSetDragImage }) => {
1411
+ setCustomNativeDragPreview({
1412
+ nativeSetDragImage,
1413
+ getOffset: preserveOffsetOnSource({
1414
+ element: root,
1415
+ input: location2.current.input
1416
+ }),
1417
+ render: ({ container }) => {
1418
+ data.bounds = root.getBoundingClientRect();
1419
+ setState({
1420
+ type: "preview",
1421
+ container,
1422
+ rect: root.getBoundingClientRect()
1423
+ });
1424
+ return () => setState({
1425
+ type: "dragging"
1426
+ });
1427
+ }
1428
+ });
1429
+ },
1430
+ onDragStart: () => {
1431
+ setState({
1432
+ type: "dragging"
1433
+ });
1434
+ },
1435
+ onDrop: () => {
1436
+ setState({
1437
+ type: "idle"
1438
+ });
1439
+ }
1440
+ }),
1441
+ // Target.
1442
+ dropTargetForElements({
1443
+ element: root,
1444
+ getData: ({ input, element }) => attachClosestEdge(data, {
1445
+ input,
1446
+ element,
1447
+ allowedEdges
1448
+ }),
1449
+ canDrop: ({ source }) => {
1450
+ const data2 = getSourceData(source);
1451
+ return data2 && eventHandler.canDrop?.({
1452
+ source: data2
1453
+ }) || false;
1454
+ },
1455
+ onDragEnter: ({ self, source }) => {
1456
+ handleChange({
1457
+ self,
1458
+ source
1459
+ });
1460
+ },
1461
+ onDragLeave: () => {
1462
+ setState({
1463
+ type: "idle"
1464
+ });
1465
+ setActiveLocation(void 0);
1466
+ },
1467
+ onDrag: ({ self, source }) => {
1468
+ handleChange({
1469
+ self,
1470
+ source
1471
+ });
1472
+ },
1473
+ onDrop: () => {
1474
+ setState({
1475
+ type: "idle"
1476
+ });
1477
+ setActiveLocation(void 0);
1478
+ }
1479
+ })
1480
+ );
1481
+ }, [
1482
+ rootRef,
1483
+ dragHandle,
1484
+ eventHandler,
1485
+ data,
1486
+ scrolling,
1487
+ allowedEdges,
1488
+ setActiveLocation
1489
+ ]);
1490
+ return /* @__PURE__ */ React6.createElement(TileContextProvider, {
1491
+ state
1492
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1493
+ [`data-${TILE_STATE_ATTR}`]: state.type,
1494
+ role: "listitem",
1495
+ className: mx6("relative", className, classNames),
1496
+ ref: composedRef
1497
+ }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(Root2, {
1498
+ // NOTE: Use to control appearance while dragging.
1499
+ [`data-${TILE_STATE_ATTR}`]: state.type,
1500
+ // TODO(burdon): Configure drop animation.
1501
+ className: mx6("relative", className, classNames),
1502
+ style: {
1503
+ width: `${state.rect.width}px`,
1504
+ height: `${state.rect.height}px`
1505
+ }
1506
+ }, children), state.container));
1507
+ });
1508
+ Tile.displayName = "MosaicTile";
1509
+ var PLACEHOLDER_AXIS_ATTR = "mosaic-placeholder-axis";
1510
+ var PLACEHOLDER_STATE_ATTR = "mosaic-placeholder-state";
1511
+ var Placeholder2 = ({ classNames, children, asChild, axis = "vertical", location }) => {
1512
+ const rootRef = useRef4(null);
1513
+ const Root2 = asChild ? Slot3 : Primitive2.div;
1514
+ const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder2.displayName);
1515
+ const data = useMemo4(() => ({
1516
+ type: "placeholder",
1517
+ containerId,
1518
+ location
1519
+ }), [
1520
+ containerId,
1521
+ location
1522
+ ]);
1523
+ useLayoutEffect(() => {
1524
+ const root = rootRef.current;
1525
+ if (!root || scrolling) {
1526
+ return;
1527
+ }
1528
+ return dropTargetForElements({
1529
+ element: root,
1530
+ getData: () => data,
1531
+ canDrop: ({ source }) => {
1532
+ const data2 = getSourceData(source);
1533
+ return data2 && eventHandler.canDrop?.({
1534
+ source: data2
1535
+ }) || false;
1536
+ },
1537
+ onDragEnter: () => {
1538
+ setActiveLocation(data.location);
1539
+ },
1540
+ onDragLeave: () => {
1541
+ setActiveLocation(void 0);
1542
+ },
1543
+ onDrop: () => {
1544
+ setActiveLocation(void 0);
1545
+ }
1546
+ });
1547
+ }, [
1548
+ rootRef,
1549
+ data,
1550
+ scrolling,
1551
+ setActiveLocation
1552
+ ]);
1553
+ return /* @__PURE__ */ React6.createElement(Root2, {
1554
+ [`data-${PLACEHOLDER_AXIS_ATTR}`]: axis,
1555
+ [`data-${PLACEHOLDER_STATE_ATTR}`]: data.location === activeLocation ? "active" : "idle",
1556
+ role: "none",
1557
+ className: mx6("relative", classNames),
1558
+ ref: rootRef
1559
+ }, children);
1560
+ };
1561
+ Placeholder2.displayName = "MosaicPlaceholder";
1562
+ var DropIndicator = (props) => {
1563
+ const { state } = useTileContext(DropIndicator.displayName);
1564
+ return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React6.createElement(NativeDropIndicator, {
1565
+ ...props,
1566
+ edge: state.closestEdge
1567
+ }) : null;
1568
+ };
1569
+ DropIndicator.displayName = "MosaicDropIndicator";
1570
+ var Mosaic = {
1571
+ Root,
1572
+ Container,
1573
+ Tile,
1574
+ Placeholder: Placeholder2,
1575
+ DropIndicator,
1576
+ // TODO(burdon): Move out of Mosaic namespace?
1577
+ Viewport: Scrollable,
1578
+ Stack,
1579
+ VirtualStack
1580
+ };
1581
+
1582
+ // src/hooks/useContainerDebug.tsx
1583
+ var useContainerDebug = (debug) => {
1584
+ const debugRef = useRef5(null);
1585
+ return useMemo5(() => {
1586
+ if (!debug) {
1587
+ return [
1588
+ () => null,
1589
+ void 0
1590
+ ];
1591
+ }
1592
+ return [
1593
+ ({ classNames }) => /* @__PURE__ */ React7.createElement("div", {
1594
+ role: "none",
1595
+ className: mx7("overflow-hidden", classNames),
1596
+ ref: debugRef
1597
+ }),
1598
+ () => debugRef.current && /* @__PURE__ */ createPortal2(/* @__PURE__ */ React7.createElement(ContainerInfo, null), debugRef.current)
1599
+ ];
1600
+ }, [
1601
+ debug,
1602
+ debugRef
1603
+ ]);
1604
+ };
1605
+ var ContainerInfo = /* @__PURE__ */ forwardRef6(({ classNames }, forwardedRef) => {
1606
+ const { id, state, activeLocation, scrolling } = useContainerContext(ContainerInfo.displayName);
1607
+ const counter2 = useRef5(0);
1608
+ return /* @__PURE__ */ React7.createElement(Json, {
1609
+ data: {
1610
+ id,
1611
+ activeLocation,
1612
+ scrolling,
1613
+ state,
1614
+ count: counter2.current++
1615
+ },
1616
+ classNames: mx7("text-xs", classNames),
1617
+ ref: forwardedRef
1618
+ });
1619
+ });
1620
+ ContainerInfo.displayName = "ContainerInfo";
1621
+
1622
+ export {
1623
+ styles,
1624
+ Image,
1625
+ Card,
1626
+ styles2,
1627
+ useFocus,
1628
+ Focus,
1629
+ styles3,
1630
+ dropHandler,
1631
+ useContainerDebug,
1632
+ useEventHandlerAdapter,
1633
+ useVisibleItems,
1634
+ Stack,
1635
+ VirtualStack,
1636
+ useRootContext,
1637
+ useContainerContext,
1638
+ useTileContext,
1639
+ Mosaic
1640
+ };
1641
+ //# sourceMappingURL=chunk-KONKDEUD.mjs.map