@dxos/react-ui-mosaic 0.7.5-main.e9bb01b → 0.8.4-main.1068cf700f

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