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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/README.md +2 -44
  2. package/dist/lib/browser/chunk-RUQB4JIG.mjs +964 -0
  3. package/dist/lib/browser/chunk-RUQB4JIG.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +654 -661
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/playwright/index.mjs +231 -0
  8. package/dist/lib/browser/playwright/index.mjs.map +7 -0
  9. package/dist/lib/browser/testing/index.mjs +138 -0
  10. package/dist/lib/browser/testing/index.mjs.map +7 -0
  11. package/dist/lib/browser/translations.mjs +18 -0
  12. package/dist/lib/browser/translations.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-MYDCPSNY.mjs +966 -0
  14. package/dist/lib/node-esm/chunk-MYDCPSNY.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +654 -662
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/playwright/index.mjs +233 -0
  19. package/dist/lib/node-esm/playwright/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/testing/index.mjs +139 -0
  21. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  22. package/dist/lib/node-esm/translations.mjs +20 -0
  23. package/dist/lib/node-esm/translations.mjs.map +7 -0
  24. package/dist/types/src/components/Board/Board.d.ts +88 -0
  25. package/dist/types/src/components/Board/Board.d.ts.map +1 -0
  26. package/dist/types/src/components/Board/Board.stories.d.ts +41 -0
  27. package/dist/types/src/components/Board/Board.stories.d.ts.map +1 -0
  28. package/dist/types/src/components/Board/Column.d.ts +40 -0
  29. package/dist/types/src/components/Board/Column.d.ts.map +1 -0
  30. package/dist/types/src/components/Board/Item.d.ts +12 -0
  31. package/dist/types/src/components/Board/Item.d.ts.map +1 -0
  32. package/dist/types/src/components/Board/index.d.ts +2 -0
  33. package/dist/types/src/components/Board/index.d.ts.map +1 -0
  34. package/dist/types/src/components/Focus/Focus.d.ts +2 -0
  35. package/dist/types/src/components/Focus/Focus.d.ts.map +1 -0
  36. package/dist/types/src/components/Focus/index.d.ts +2 -0
  37. package/dist/types/src/components/Focus/index.d.ts.map +1 -0
  38. package/dist/types/src/components/Mosaic/Container.d.ts +45 -0
  39. package/dist/types/src/components/Mosaic/Container.d.ts.map +1 -0
  40. package/dist/types/src/components/Mosaic/Mosaic.d.ts +50 -0
  41. package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -0
  42. package/dist/types/src/components/Mosaic/Placeholder.d.ts +21 -0
  43. package/dist/types/src/components/Mosaic/Placeholder.d.ts.map +1 -0
  44. package/dist/types/src/components/Mosaic/Root.d.ts +35 -0
  45. package/dist/types/src/components/Mosaic/Root.d.ts.map +1 -0
  46. package/dist/types/src/components/Mosaic/Stack.d.ts +29 -0
  47. package/dist/types/src/components/Mosaic/Stack.d.ts.map +1 -0
  48. package/dist/types/src/components/Mosaic/Stack.stories.d.ts +20 -0
  49. package/dist/types/src/components/Mosaic/Stack.stories.d.ts.map +1 -0
  50. package/dist/types/src/components/Mosaic/Tile.d.ts +53 -0
  51. package/dist/types/src/components/Mosaic/Tile.d.ts.map +1 -0
  52. package/dist/types/src/components/Mosaic/extension.d.ts +20 -0
  53. package/dist/types/src/components/Mosaic/extension.d.ts.map +1 -0
  54. package/dist/types/src/components/Mosaic/index.d.ts +5 -0
  55. package/dist/types/src/components/Mosaic/index.d.ts.map +1 -0
  56. package/dist/types/src/components/Mosaic/styles.d.ts +7 -0
  57. package/dist/types/src/components/Mosaic/styles.d.ts.map +1 -0
  58. package/dist/types/src/components/Mosaic/types.d.ts +86 -0
  59. package/dist/types/src/components/Mosaic/types.d.ts.map +1 -0
  60. package/dist/types/src/components/SearchStack/SearchStack.d.ts +20 -0
  61. package/dist/types/src/components/SearchStack/SearchStack.d.ts.map +1 -0
  62. package/dist/types/src/components/SearchStack/SearchStack.stories.d.ts +10 -0
  63. package/dist/types/src/components/SearchStack/SearchStack.stories.d.ts.map +1 -0
  64. package/dist/types/src/components/SearchStack/index.d.ts +2 -0
  65. package/dist/types/src/components/SearchStack/index.d.ts.map +1 -0
  66. package/dist/types/src/components/index.d.ts +5 -0
  67. package/dist/types/src/components/index.d.ts.map +1 -0
  68. package/dist/types/src/hooks/index.d.ts +5 -0
  69. package/dist/types/src/hooks/index.d.ts.map +1 -0
  70. package/dist/types/src/hooks/useContainerDebug.d.ts +9 -0
  71. package/dist/types/src/hooks/useContainerDebug.d.ts.map +1 -0
  72. package/dist/types/src/hooks/useDefaultColumnEventHandler.d.ts +15 -0
  73. package/dist/types/src/hooks/useDefaultColumnEventHandler.d.ts.map +1 -0
  74. package/dist/types/src/hooks/useEventHandlerAdapter.d.ts +32 -0
  75. package/dist/types/src/hooks/useEventHandlerAdapter.d.ts.map +1 -0
  76. package/dist/types/src/hooks/useVisibleItems.d.ts +16 -0
  77. package/dist/types/src/hooks/useVisibleItems.d.ts.map +1 -0
  78. package/dist/types/src/index.d.ts +2 -1
  79. package/dist/types/src/index.d.ts.map +1 -1
  80. package/dist/types/src/playwright/board-manager.d.ts +55 -0
  81. package/dist/types/src/playwright/board-manager.d.ts.map +1 -0
  82. package/dist/types/src/playwright/index.d.ts +9 -0
  83. package/dist/types/src/playwright/index.d.ts.map +1 -0
  84. package/dist/types/src/playwright/playwright.config.d.ts +3 -0
  85. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
  86. package/dist/types/src/playwright/smoke.spec.d.ts +2 -0
  87. package/dist/types/src/playwright/smoke.spec.d.ts.map +1 -0
  88. package/dist/types/src/testing/CardContainer.d.ts +18 -0
  89. package/dist/types/src/testing/CardContainer.d.ts.map +1 -0
  90. package/dist/types/src/testing/DefaultStackTile.d.ts +4 -0
  91. package/dist/types/src/testing/DefaultStackTile.d.ts.map +1 -0
  92. package/dist/types/src/testing/decorator.d.ts +3 -0
  93. package/dist/types/src/testing/decorator.d.ts.map +1 -0
  94. package/dist/types/src/testing/index.d.ts +4 -2
  95. package/dist/types/src/testing/index.d.ts.map +1 -1
  96. package/dist/types/src/testing/types.d.ts +21 -0
  97. package/dist/types/src/testing/types.d.ts.map +1 -0
  98. package/dist/types/src/translations.d.ts +11 -0
  99. package/dist/types/src/translations.d.ts.map +1 -0
  100. package/dist/types/tsconfig.tsbuildinfo +1 -1
  101. package/package.json +84 -43
  102. package/src/AUDIT.md +106 -0
  103. package/src/components/Board/Board.stories.tsx +274 -0
  104. package/src/components/Board/Board.tsx +190 -0
  105. package/src/components/Board/Column.tsx +304 -0
  106. package/src/components/Board/Item.tsx +119 -0
  107. package/src/components/Board/index.ts +5 -0
  108. package/src/components/Focus/Focus.tsx +6 -0
  109. package/src/components/Focus/index.ts +5 -0
  110. package/src/components/Mosaic/Container.tsx +315 -0
  111. package/src/components/Mosaic/Mosaic.tsx +51 -0
  112. package/src/components/Mosaic/Placeholder.tsx +139 -0
  113. package/src/components/Mosaic/Root.tsx +286 -0
  114. package/src/components/Mosaic/Stack.stories.tsx +175 -0
  115. package/src/components/Mosaic/Stack.tsx +341 -0
  116. package/src/components/Mosaic/Tile.tsx +252 -0
  117. package/src/components/Mosaic/extension.ts +141 -0
  118. package/src/components/Mosaic/index.ts +10 -0
  119. package/src/components/Mosaic/styles.ts +32 -0
  120. package/src/components/Mosaic/types.ts +94 -0
  121. package/src/components/SearchStack/SearchStack.stories.tsx +47 -0
  122. package/src/components/SearchStack/SearchStack.tsx +135 -0
  123. package/src/components/SearchStack/index.ts +5 -0
  124. package/src/components/index.ts +8 -0
  125. package/src/hooks/index.ts +8 -0
  126. package/src/hooks/useContainerDebug.tsx +48 -0
  127. package/src/hooks/useDefaultColumnEventHandler.ts +34 -0
  128. package/src/hooks/useEventHandlerAdapter.ts +108 -0
  129. package/src/hooks/useVisibleItems.ts +48 -0
  130. package/src/index.ts +3 -2
  131. package/src/playwright/board-manager.ts +287 -0
  132. package/src/playwright/index.ts +13 -0
  133. package/src/playwright/playwright.config.ts +17 -0
  134. package/src/playwright/smoke.spec.ts +143 -0
  135. package/src/testing/CardContainer.tsx +97 -0
  136. package/src/testing/DefaultStackTile.tsx +58 -0
  137. package/src/testing/decorator.tsx +16 -0
  138. package/src/testing/index.ts +5 -3
  139. package/src/testing/types.ts +38 -0
  140. package/src/translations.ts +19 -0
  141. package/dist/lib/node/index.cjs +0 -705
  142. package/dist/lib/node/index.cjs.map +0 -7
  143. package/dist/lib/node/meta.json +0 -1
  144. package/dist/types/src/mosaic/Container.d.ts +0 -94
  145. package/dist/types/src/mosaic/Container.d.ts.map +0 -1
  146. package/dist/types/src/mosaic/Debug.d.ts +0 -9
  147. package/dist/types/src/mosaic/Debug.d.ts.map +0 -1
  148. package/dist/types/src/mosaic/DefaultComponent.d.ts +0 -4
  149. package/dist/types/src/mosaic/DefaultComponent.d.ts.map +0 -1
  150. package/dist/types/src/mosaic/DragOverlay.d.ts +0 -11
  151. package/dist/types/src/mosaic/DragOverlay.d.ts.map +0 -1
  152. package/dist/types/src/mosaic/Mosaic.d.ts +0 -34
  153. package/dist/types/src/mosaic/Mosaic.d.ts.map +0 -1
  154. package/dist/types/src/mosaic/Root.d.ts +0 -28
  155. package/dist/types/src/mosaic/Root.d.ts.map +0 -1
  156. package/dist/types/src/mosaic/SortableContext.d.ts +0 -14
  157. package/dist/types/src/mosaic/SortableContext.d.ts.map +0 -1
  158. package/dist/types/src/mosaic/Tile.d.ts +0 -74
  159. package/dist/types/src/mosaic/Tile.d.ts.map +0 -1
  160. package/dist/types/src/mosaic/hooks/index.d.ts +0 -5
  161. package/dist/types/src/mosaic/hooks/index.d.ts.map +0 -1
  162. package/dist/types/src/mosaic/hooks/useContainer.d.ts +0 -4
  163. package/dist/types/src/mosaic/hooks/useContainer.d.ts.map +0 -1
  164. package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts +0 -3
  165. package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts.map +0 -1
  166. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts +0 -10
  167. package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +0 -1
  168. package/dist/types/src/mosaic/hooks/useMosaic.d.ts +0 -2
  169. package/dist/types/src/mosaic/hooks/useMosaic.d.ts.map +0 -1
  170. package/dist/types/src/mosaic/index.d.ts +0 -5
  171. package/dist/types/src/mosaic/index.d.ts.map +0 -1
  172. package/dist/types/src/mosaic/types.d.ts +0 -10
  173. package/dist/types/src/mosaic/types.d.ts.map +0 -1
  174. package/dist/types/src/mosaic/util/data.d.ts +0 -3
  175. package/dist/types/src/mosaic/util/data.d.ts.map +0 -1
  176. package/dist/types/src/mosaic/util/index.d.ts +0 -5
  177. package/dist/types/src/mosaic/util/index.d.ts.map +0 -1
  178. package/dist/types/src/mosaic/util/path.d.ts +0 -14
  179. package/dist/types/src/mosaic/util/path.d.ts.map +0 -1
  180. package/dist/types/src/mosaic/util/path.test.d.ts +0 -2
  181. package/dist/types/src/mosaic/util/path.test.d.ts.map +0 -1
  182. package/dist/types/src/mosaic/util/props.d.ts +0 -4
  183. package/dist/types/src/mosaic/util/props.d.ts.map +0 -1
  184. package/dist/types/src/mosaic/util/styles.d.ts +0 -3
  185. package/dist/types/src/mosaic/util/styles.d.ts.map +0 -1
  186. package/dist/types/src/testing/Cards.d.ts +0 -10
  187. package/dist/types/src/testing/Cards.d.ts.map +0 -1
  188. package/dist/types/src/testing/generator.d.ts +0 -35
  189. package/dist/types/src/testing/generator.d.ts.map +0 -1
  190. package/dist/types/src/views/Demo/Demo.stories.d.ts +0 -14
  191. package/dist/types/src/views/Demo/Demo.stories.d.ts.map +0 -1
  192. package/dist/types/src/views/Demo/Echo.stories.d.ts +0 -8
  193. package/dist/types/src/views/Demo/Echo.stories.d.ts.map +0 -1
  194. package/dist/types/src/views/Grid/Grid.d.ts +0 -31
  195. package/dist/types/src/views/Grid/Grid.d.ts.map +0 -1
  196. package/dist/types/src/views/Grid/Grid.stories.d.ts +0 -14
  197. package/dist/types/src/views/Grid/Grid.stories.d.ts.map +0 -1
  198. package/dist/types/src/views/Grid/index.d.ts +0 -3
  199. package/dist/types/src/views/Grid/index.d.ts.map +0 -1
  200. package/dist/types/src/views/Grid/layout.d.ts +0 -27
  201. package/dist/types/src/views/Grid/layout.d.ts.map +0 -1
  202. package/dist/types/src/views/Grid/testing.d.ts +0 -11
  203. package/dist/types/src/views/Grid/testing.d.ts.map +0 -1
  204. package/dist/types/src/views/Kanban/Kanban.d.ts +0 -12
  205. package/dist/types/src/views/Kanban/Kanban.d.ts.map +0 -1
  206. package/dist/types/src/views/Kanban/Kanban.stories.d.ts +0 -29
  207. package/dist/types/src/views/Kanban/Kanban.stories.d.ts.map +0 -1
  208. package/dist/types/src/views/Kanban/index.d.ts +0 -2
  209. package/dist/types/src/views/Kanban/index.d.ts.map +0 -1
  210. package/dist/types/src/views/Kanban/testing.d.ts +0 -12
  211. package/dist/types/src/views/Kanban/testing.d.ts.map +0 -1
  212. package/dist/types/src/views/Stack/Columns.stories.d.ts +0 -34
  213. package/dist/types/src/views/Stack/Columns.stories.d.ts.map +0 -1
  214. package/dist/types/src/views/Stack/Stack.d.ts +0 -10
  215. package/dist/types/src/views/Stack/Stack.d.ts.map +0 -1
  216. package/dist/types/src/views/Stack/Stack.stories.d.ts +0 -40
  217. package/dist/types/src/views/Stack/Stack.stories.d.ts.map +0 -1
  218. package/dist/types/src/views/Stack/index.d.ts +0 -2
  219. package/dist/types/src/views/Stack/index.d.ts.map +0 -1
  220. package/dist/types/src/views/Stack/testing.d.ts +0 -10
  221. package/dist/types/src/views/Stack/testing.d.ts.map +0 -1
  222. package/dist/types/src/views/Tree/Graph.stories.d.ts +0 -11
  223. package/dist/types/src/views/Tree/Graph.stories.d.ts.map +0 -1
  224. package/dist/types/src/views/Tree/Tree.d.ts +0 -13
  225. package/dist/types/src/views/Tree/Tree.d.ts.map +0 -1
  226. package/dist/types/src/views/Tree/Tree.stories.d.ts +0 -42
  227. package/dist/types/src/views/Tree/Tree.stories.d.ts.map +0 -1
  228. package/dist/types/src/views/Tree/index.d.ts +0 -2
  229. package/dist/types/src/views/Tree/index.d.ts.map +0 -1
  230. package/dist/types/src/views/Tree/testing.d.ts +0 -11
  231. package/dist/types/src/views/Tree/testing.d.ts.map +0 -1
  232. package/dist/types/src/views/index.d.ts +0 -5
  233. package/dist/types/src/views/index.d.ts.map +0 -1
  234. package/src/mosaic/Container.tsx +0 -190
  235. package/src/mosaic/Debug.tsx +0 -24
  236. package/src/mosaic/DefaultComponent.tsx +0 -26
  237. package/src/mosaic/DragOverlay.tsx +0 -150
  238. package/src/mosaic/Mosaic.ts +0 -100
  239. package/src/mosaic/Root.tsx +0 -320
  240. package/src/mosaic/SortableContext.tsx +0 -61
  241. package/src/mosaic/Tile.tsx +0 -207
  242. package/src/mosaic/hooks/index.ts +0 -8
  243. package/src/mosaic/hooks/useContainer.ts +0 -13
  244. package/src/mosaic/hooks/useItemsWithOrigin.ts +0 -33
  245. package/src/mosaic/hooks/useItemsWithPreview.ts +0 -69
  246. package/src/mosaic/hooks/useMosaic.ts +0 -11
  247. package/src/mosaic/index.ts +0 -9
  248. package/src/mosaic/types.ts +0 -15
  249. package/src/mosaic/util/data.ts +0 -19
  250. package/src/mosaic/util/index.ts +0 -8
  251. package/src/mosaic/util/path.test.ts +0 -24
  252. package/src/mosaic/util/path.ts +0 -21
  253. package/src/mosaic/util/props.ts +0 -14
  254. package/src/mosaic/util/styles.ts +0 -10
  255. package/src/testing/Cards.tsx +0 -88
  256. package/src/testing/generator.ts +0 -131
  257. package/src/views/Demo/Demo.stories.tsx +0 -81
  258. package/src/views/Demo/Echo.stories.tsx +0 -75
  259. package/src/views/Grid/Grid.stories.tsx +0 -51
  260. package/src/views/Grid/Grid.tsx +0 -265
  261. package/src/views/Grid/index.ts +0 -7
  262. package/src/views/Grid/layout.ts +0 -42
  263. package/src/views/Grid/testing.tsx +0 -92
  264. package/src/views/Kanban/Kanban.stories.tsx +0 -51
  265. package/src/views/Kanban/Kanban.tsx +0 -139
  266. package/src/views/Kanban/index.ts +0 -5
  267. package/src/views/Kanban/testing.tsx +0 -234
  268. package/src/views/Stack/Columns.stories.tsx +0 -63
  269. package/src/views/Stack/Stack.stories.tsx +0 -65
  270. package/src/views/Stack/Stack.tsx +0 -58
  271. package/src/views/Stack/index.ts +0 -5
  272. package/src/views/Stack/testing.tsx +0 -77
  273. package/src/views/Tree/Graph.stories.tsx +0 -37
  274. package/src/views/Tree/Tree.stories.tsx +0 -95
  275. package/src/views/Tree/Tree.tsx +0 -126
  276. package/src/views/Tree/index.ts +0 -5
  277. package/src/views/Tree/testing.tsx +0 -142
  278. package/src/views/index.ts +0 -8
@@ -1,265 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { useDroppable } from '@dnd-kit/core';
6
- import { PlusCircle } from '@phosphor-icons/react';
7
- import defaultsDeep from 'lodash.defaultsdeep';
8
- import React, { type FC, useState, useMemo, useEffect } from 'react';
9
- import { useResizeDetector } from 'react-resize-detector';
10
-
11
- import { Button, useMediaQuery } from '@dxos/react-ui';
12
- import { getSize, mx } from '@dxos/react-ui-theme';
13
-
14
- import {
15
- calculateCellWidth,
16
- createMatrix,
17
- getBounds,
18
- getDimension,
19
- getPanelBounds,
20
- type Dimension,
21
- type Position,
22
- type Size,
23
- } from './layout';
24
- import {
25
- type MosaicContainerProps,
26
- type MosaicDataItem,
27
- type MosaicTileAction,
28
- Mosaic,
29
- Path,
30
- useMosaic,
31
- } from '../../mosaic';
32
-
33
- //
34
- // Selection
35
- //
36
-
37
- // TODO(burdon): Factor out as mosaic standard.
38
- type ControlledSelection = {
39
- selected?: string;
40
- onSelect?: (id: string) => void;
41
- };
42
-
43
- //
44
- // Context.
45
- //
46
-
47
- type GridOptions = {
48
- size: Size;
49
- cellBounds: Dimension;
50
- spacing?: number;
51
- };
52
-
53
- const defaultGridOptions: GridOptions = {
54
- size: { x: 8, y: 8 },
55
- cellBounds: { width: 272, height: 272 },
56
- spacing: 6,
57
- };
58
-
59
- //
60
- // Container.
61
- //
62
-
63
- export type GridLayout = { [id: string]: Position };
64
-
65
- export type GridProps<TData extends MosaicDataItem = MosaicDataItem> = Omit<
66
- MosaicContainerProps<TData, Position>,
67
- 'onSelect'
68
- > &
69
- ControlledSelection & {
70
- items?: TData[];
71
- layout?: GridLayout;
72
- options?: Partial<GridOptions>;
73
- margin?: boolean;
74
- square?: boolean;
75
- debug?: boolean;
76
- onCreate?: (position: Position) => void;
77
- onAction?: (action: MosaicTileAction) => void; // TODO(burdon): Standardize across mosaics?
78
- };
79
-
80
- /**
81
- * Grid content.
82
- */
83
- // TODO(burdon): Make generic (and forwardRef).
84
- export const Grid = ({
85
- id,
86
- items = [],
87
- layout = {},
88
- options: opts,
89
- margin,
90
- square = true,
91
- debug,
92
- selected: controlledSelected,
93
- Component = Mosaic.DefaultComponent,
94
- classNames,
95
- onDrop,
96
- onOver,
97
- onSelect,
98
- onCreate,
99
- onAction,
100
- }: GridProps) => {
101
- const { ref: containerRef, width, height } = useResizeDetector({ refreshRate: 200 });
102
- const options = defaultsDeep({}, opts, defaultGridOptions);
103
- const { matrix, bounds, cellBounds } = useMemo(() => {
104
- // Change default cell bounds to screen width if mobile.
105
- const cellWidth = calculateCellWidth(options.cellBounds.width, width ?? 0);
106
- const cellBounds = {
107
- width: cellWidth,
108
- height: square ? cellWidth : options.cellBounds.height,
109
- };
110
-
111
- return {
112
- matrix: createMatrix(options.size, ({ x, y }) => ({ x, y })),
113
- bounds: getPanelBounds(options.size, cellBounds, options.spacing),
114
- cellBounds,
115
- };
116
- }, [options, width]);
117
-
118
- // No margin if mobile.
119
- const [isNotMobile] = useMediaQuery('md');
120
- const marginSize = margin && !isNotMobile ? Math.max(cellBounds.width, cellBounds.height) : 0;
121
-
122
- const [selected, setSelected] = useState(controlledSelected);
123
- useEffect(() => {
124
- setSelected(controlledSelected);
125
- if (controlledSelected) {
126
- scrollToCenter(controlledSelected);
127
- }
128
- }, [controlledSelected]);
129
-
130
- const scrollToCenter = (id: string) => {
131
- const item = items.find((item) => item.id === id);
132
- if (item && width && height) {
133
- const pos = getBounds(layout[item.id], cellBounds);
134
- const top = pos.top + marginSize - (height - cellBounds.height) / 2;
135
- const left = pos.left + marginSize - (width - cellBounds.width) / 2;
136
- containerRef.current!.scrollTo({ top, left, behavior: 'smooth' });
137
- }
138
- };
139
-
140
- // TODO(burdon): Focus ring/navigation.
141
- // TODO(burdon): Set center point on container (via translation?) Scale container to zoom.
142
- const handleSelect = (id: string) => {
143
- setSelected(id);
144
- scrollToCenter(id);
145
- onSelect?.(id);
146
- };
147
-
148
- useEffect(() => {
149
- if (selected) {
150
- scrollToCenter(selected);
151
- }
152
- }, [selected, width, height]);
153
-
154
- return (
155
- <Mosaic.Container
156
- {...{
157
- id,
158
- Component,
159
- getOverlayProps: () => ({ grow: true }),
160
- getOverlayStyle: () => ({ display: 'flex', ...getDimension(cellBounds, options.spacing) }),
161
- onDrop,
162
- onOver,
163
- }}
164
- >
165
- <div className={mx('flex grow overflow-auto', classNames)}>
166
- {/* TODO(burdon): Tailwind classes aren't currently processed by labs. */}
167
- <div ref={containerRef} className={mx('grow overflow-auto snap-x md:snap-none snap-mandatory')}>
168
- <div className='group block relative' style={{ ...bounds, margin: marginSize }}>
169
- {matrix && (
170
- <div style={{ padding: options.spacing }}>
171
- <div className='relative'>
172
- {matrix.map((row) =>
173
- row.map(({ x, y }) => (
174
- <GridCell
175
- key={`${x}-${y}`}
176
- path={id}
177
- position={{ x, y }}
178
- bounds={getBounds({ x, y }, cellBounds)}
179
- padding={options.spacing}
180
- onCreate={onCreate}
181
- />
182
- )),
183
- )}
184
- </div>
185
- </div>
186
- )}
187
-
188
- <div>
189
- {items.map((item) => {
190
- const position = layout[item.id] ?? { x: 0, y: 0 };
191
- return (
192
- <Mosaic.DraggableTile
193
- key={item.id}
194
- item={item}
195
- path={id}
196
- position={position}
197
- Component={Component}
198
- draggableStyle={{
199
- position: 'absolute',
200
- ...getBounds(position, cellBounds, options.spacing),
201
- }}
202
- onSelect={() => handleSelect(item.id)}
203
- onAction={onAction}
204
- // debug={debug}
205
- />
206
- );
207
- })}
208
- </div>
209
- </div>
210
-
211
- {debug && <Mosaic.Debug data={{ items: items?.length }} position='bottom-right' />}
212
- </div>
213
- </div>
214
- </Mosaic.Container>
215
- );
216
- };
217
-
218
- /**
219
- * Grid cell.
220
- */
221
- const GridCell: FC<{
222
- path: string;
223
- position: Position;
224
- bounds: Dimension;
225
- padding?: number;
226
- onCreate?: (position: Position) => void;
227
- }> = ({ path, position, bounds, padding, onCreate }) => {
228
- const { overItem } = useMosaic();
229
- const isOverContainer = path === overItem?.path;
230
- const { setNodeRef, isOver } = useDroppable({
231
- id: Path.create(path, 'cell', `${position.x}-${position.y}`),
232
- data: { path, position },
233
- });
234
-
235
- return (
236
- <div
237
- ref={setNodeRef}
238
- style={{ ...bounds, padding }}
239
- className='absolute flex justify-center items-center grow select-none cursor-pointer'
240
- >
241
- <div
242
- className={mx(
243
- 'group/cell flex group-hover:flex w-full h-full items-center justify-center',
244
- 'box-border border-dashed border-4 border-neutral-75 dark:border-neutral-850 rounded-lg',
245
- 'transition ease-in-out duration-300',
246
- isOver && 'flex bg-neutral-75 dark:bg-neutral-850 border-neutral-200 dark:border-neutral-800',
247
- )}
248
- >
249
- <div
250
- className={mx(
251
- 'opacity-10 transition ease-in-out duration-300 group-hover/cell:opacity-100',
252
- isOverContainer && 'hidden',
253
- )}
254
- >
255
- {onCreate && (
256
- // TODO(burdon): Style button.
257
- <Button variant='ghost' onClick={() => onCreate(position)}>
258
- <PlusCircle className={getSize(8)} />
259
- </Button>
260
- )}
261
- </div>
262
- </div>
263
- </div>
264
- );
265
- };
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './layout';
6
-
7
- export * from './Grid';
@@ -1,42 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export type Size = { x: number; y: number };
6
- export type Position = { x: number; y: number };
7
- export type Dimension = { width: number; height: number };
8
- export type Bounds = { left: number; top: number; width: number; height: number };
9
-
10
- export const createMatrix = <TValue>(size: Size, value: (position: Position) => TValue): TValue[][] => {
11
- const matrix: TValue[][] = [];
12
- for (let x = 0; x < size.x; x++) {
13
- matrix.push(Array.from({ length: size.y }, (_, y) => value({ x, y })));
14
- }
15
-
16
- return matrix;
17
- };
18
-
19
- export const getDimension = ({ width, height }: Dimension, spacing = 0): Dimension => ({
20
- width: width - spacing * 2,
21
- height: height - spacing * 2,
22
- });
23
-
24
- export const getBounds = ({ x, y }: Position, { width, height }: Dimension, spacing = 0): Bounds => ({
25
- left: x * width + spacing * 2,
26
- top: y * height + spacing * 2,
27
- width: width - spacing * 2,
28
- height: height - spacing * 2,
29
- });
30
-
31
- export const getPanelBounds = ({ x, y }: Position, { width, height }: Dimension, spacing = 0): Dimension => ({
32
- width: x * width + spacing * 2,
33
- height: y * height + spacing * 2,
34
- });
35
-
36
- export const calculateCellWidth = (
37
- defaultWidth: number,
38
- screenWidth: number,
39
- options: { min: number; max: number } = { min: 260, max: 400 },
40
- ) => {
41
- return screenWidth > options.min && screenWidth < options.max ? screenWidth : defaultWidth;
42
- };
@@ -1,92 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { useState } from 'react';
6
-
7
- import { faker } from '@dxos/random';
8
-
9
- import { Grid, type GridLayout, type GridProps } from './Grid';
10
- import { type Position } from './layout';
11
- import { type MosaicDataItem, type MosaicDropEvent } from '../../mosaic';
12
- import { ComplexCard, TestObjectGenerator } from '../../testing';
13
-
14
- export type DemoGridProps = GridProps & {
15
- initialItems?: MosaicDataItem[]; // TODO(burdon): Remove or convert to controlled.
16
- initialLayout?: GridLayout; // TODO(burdon): Remove or convert to controlled.
17
- types?: string[];
18
- debug?: boolean;
19
- };
20
-
21
- export const DemoGrid = ({
22
- id = 'grid',
23
- options = { size: { x: 8, y: 8 } },
24
- Component = ComplexCard,
25
- initialItems,
26
- initialLayout,
27
- types,
28
- debug,
29
- classNames,
30
- }: DemoGridProps) => {
31
- const [selected, setSelected] = useState<string>();
32
- const [items, setItems] = useState<MosaicDataItem[]>(
33
- initialItems ??
34
- (() => {
35
- const generator = new TestObjectGenerator({ types });
36
- return generator.createObjects({ length: 12 });
37
- }),
38
- );
39
- const [layout, setLayout] = useState<GridLayout>(
40
- initialLayout ??
41
- (() =>
42
- items.reduce<GridLayout>((map, item, i) => {
43
- map[item.id] = {
44
- x: faker.number.int({ min: 0, max: (options.size?.x ?? 1) - 1 }),
45
- y: faker.number.int({ min: 0, max: (options.size?.y ?? 1) - 1 }),
46
- };
47
- return map;
48
- }, {})),
49
- );
50
-
51
- const handleDrop = ({ active, over }: MosaicDropEvent<Position>) => {
52
- if (over.path !== id) {
53
- setItems((items) => items.filter((item) => item.id !== active.item.id));
54
- } else {
55
- setItems((items) => {
56
- if (items.findIndex((item) => item.id === active.item.id) === -1) {
57
- return [active.item, ...items];
58
- } else {
59
- return items;
60
- }
61
- });
62
- setLayout((layout) => ({ ...layout, [active.item.id]: over.position! }));
63
- }
64
- };
65
-
66
- const handleCreate = (position: Position) => {
67
- setItems((items) => {
68
- const item = new TestObjectGenerator({ types }).createObject();
69
- setTimeout(() => {
70
- setSelected(item.id);
71
- });
72
- setLayout((layout) => ({ ...layout, [item.id]: position }));
73
- return [item, ...items];
74
- });
75
- };
76
-
77
- return (
78
- <Grid
79
- id={id}
80
- items={items}
81
- layout={layout}
82
- options={options}
83
- Component={Component}
84
- classNames={classNames}
85
- debug={debug}
86
- selected={selected}
87
- onSelect={setSelected}
88
- onDrop={handleDrop}
89
- onCreate={handleCreate}
90
- />
91
- );
92
- };
@@ -1,51 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import React from 'react';
8
-
9
- import { faker } from '@dxos/random';
10
- import { withLayout, withTheme } from '@dxos/storybook-utils';
11
-
12
- import { Kanban } from './Kanban';
13
- import { DemoKanban, type DemoKanbanProps } from './testing';
14
- import { Mosaic } from '../../mosaic';
15
- import { ComplexCard, SimpleCard } from '../../testing';
16
-
17
- faker.seed(3);
18
-
19
- export default {
20
- title: 'ui/react-ui-mosaic/Kanban',
21
- component: Kanban,
22
- render: (args: DemoKanbanProps) => {
23
- return (
24
- <Mosaic.Root debug={args.debug}>
25
- <Mosaic.DragOverlay />
26
- <DemoKanban {...args} />
27
- </Mosaic.Root>
28
- );
29
- },
30
- decorators: [withTheme, withLayout({ fullscreen: true })],
31
- parameters: {
32
- layout: 'fullscreen',
33
- },
34
- };
35
-
36
- export const Default = {
37
- args: {
38
- Component: SimpleCard,
39
- count: 3,
40
- debug: true,
41
- },
42
- };
43
-
44
- export const Complex = {
45
- args: {
46
- Component: ComplexCard,
47
- types: ['document', 'image'],
48
- count: 4,
49
- debug: true,
50
- },
51
- };
@@ -1,139 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { forwardRef, useMemo } from 'react';
6
-
7
- import { Card } from '@dxos/react-ui-card';
8
- import { groupSurface, mx } from '@dxos/react-ui-theme';
9
-
10
- import {
11
- Mosaic,
12
- type MosaicContainerProps,
13
- type MosaicDataItem,
14
- type MosaicTileComponent,
15
- Path,
16
- useItemsWithPreview,
17
- useContainer,
18
- } from '../../mosaic';
19
-
20
- // Example:
21
- // https://master--5fc05e08a4a65d0021ae0bf2.chromatic.com/?path=/story/presets-sortable-multiple-containers--basic-setup
22
-
23
- export type KanbanColumn<TData extends MosaicDataItem = MosaicDataItem> = MosaicDataItem & {
24
- title: string;
25
- items: TData[];
26
- };
27
-
28
- export type KanbanProps<TData extends MosaicDataItem = MosaicDataItem> = MosaicContainerProps<TData, number> & {
29
- columns: KanbanColumn<TData>[];
30
- debug?: boolean;
31
- };
32
-
33
- export const Kanban = ({
34
- id,
35
- columns,
36
- Component: TileComponent = Mosaic.DefaultComponent,
37
- debug,
38
- onDrop,
39
- }: KanbanProps) => {
40
- const Component = useMemo(() => OverlayComponent(id, TileComponent), [id, TileComponent]);
41
-
42
- return (
43
- <Mosaic.Container
44
- {...{
45
- id,
46
- debug,
47
- Component,
48
- // Restrict columns to x-axis.
49
- modifier: ({ path, item }, { transform }) =>
50
- path === Path.create(id, item.id) ? { ...transform, y: 0 } : transform,
51
- // Restrict to objects from other columns.
52
- // TODO(burdon): Consider objects from other containers.
53
- // TODO(wittjosiah): Allow override.
54
- onOver: ({ active, over }) => (Path.length(active.path) >= Path.length(over.path) ? 'transfer' : 'reject'),
55
- onDrop,
56
- }}
57
- >
58
- <div className='grow flex overflow-y-hidden overflow-x-auto'>
59
- <div className='flex'>
60
- <Mosaic.SortableContext items={columns} direction='horizontal'>
61
- {columns.map((column, index) => (
62
- <Mosaic.SortableTile
63
- key={column.id}
64
- item={column}
65
- path={id}
66
- position={index}
67
- Component={Component}
68
- debug={debug}
69
- />
70
- ))}
71
- </Mosaic.SortableContext>
72
- </div>
73
- </div>
74
- </Mosaic.Container>
75
- );
76
- };
77
-
78
- const OverlayComponent = (id: string, Component: MosaicTileComponent<any>): MosaicTileComponent<any> =>
79
- forwardRef((props, ref) => {
80
- const isColumn = Path.hasRoot(props.path, id) && Path.length(props.path) === 2;
81
- if (isColumn && props.active === 'overlay') {
82
- return (
83
- // Needs to not override the main kanban path.
84
- <Mosaic.Container {...{ id: `${id}-active`, Component }}>
85
- <KanbanColumnComponent {...props} ref={ref} />
86
- </Mosaic.Container>
87
- );
88
- }
89
-
90
- return isColumn ? <KanbanColumnComponent {...props} ref={ref} /> : <Component {...props} ref={ref} />;
91
- });
92
-
93
- const KanbanColumnComponent: MosaicTileComponent<KanbanColumn> = forwardRef(
94
- ({ path, item, active, draggableStyle, draggableProps, debug }, forwardRef) => {
95
- const { id, title, items } = item;
96
- const { Component } = useContainer();
97
- const itemsWithPreview = useItemsWithPreview({ path, items });
98
-
99
- return (
100
- <div role='none' className='grow flex flex-col' ref={forwardRef}>
101
- <div
102
- className={mx(
103
- groupSurface,
104
- 'grow flex flex-col w-[300px] snap-center overflow-hidden m-1',
105
- active === 'rearrange' && 'opacity-0',
106
- )}
107
- style={draggableStyle}
108
- >
109
- <Card.Root classNames='shrink-0 bg-cyan-200'>
110
- <Card.Header>
111
- <Card.DragHandle {...draggableProps} />
112
- <Card.Title title={title} />
113
- <Card.Menu />
114
- </Card.Header>
115
- </Card.Root>
116
-
117
- <div className={mx('flex flex-col grow overflow-y-scroll')}>
118
- <div className='flex flex-col my-1'>
119
- <Mosaic.SortableContext id={path} items={itemsWithPreview} direction='vertical'>
120
- {itemsWithPreview.map((item, index) => (
121
- <Mosaic.SortableTile
122
- key={item.id}
123
- item={item}
124
- path={path}
125
- position={index}
126
- Component={Component!}
127
- classNames='m-1'
128
- // debug={debug}
129
- />
130
- ))}
131
- </Mosaic.SortableContext>
132
- </div>
133
- </div>
134
- {debug && <Mosaic.Debug data={{ path, id, items: itemsWithPreview.length }} />}
135
- </div>
136
- </div>
137
- );
138
- },
139
- );
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './Kanban';