@dxos/react-ui-mosaic 0.8.4-main.bc674ce → 0.8.4-main.c85a9c8dae

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 (186) hide show
  1. package/dist/lib/browser/chunk-7S4PIFKU.mjs +953 -0
  2. package/dist/lib/browser/chunk-7S4PIFKU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +596 -70
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/playwright/index.mjs +138 -0
  7. package/dist/lib/browser/playwright/index.mjs.map +7 -0
  8. package/dist/lib/browser/testing/index.mjs +61 -232
  9. package/dist/lib/browser/testing/index.mjs.map +4 -4
  10. package/dist/lib/node-esm/chunk-MK6KU66S.mjs +955 -0
  11. package/dist/lib/node-esm/chunk-MK6KU66S.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +596 -70
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/playwright/index.mjs +140 -0
  16. package/dist/lib/node-esm/playwright/index.mjs.map +7 -0
  17. package/dist/lib/node-esm/testing/index.mjs +61 -232
  18. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  19. package/dist/types/src/components/Board/Board.d.ts +81 -0
  20. package/dist/types/src/components/Board/Board.d.ts.map +1 -0
  21. package/dist/types/src/components/{Mosaic/Mosaic.stories.d.ts → Board/Board.stories.d.ts} +15 -1
  22. package/dist/types/src/components/Board/Board.stories.d.ts.map +1 -0
  23. package/dist/types/src/components/Board/Column.d.ts +40 -0
  24. package/dist/types/src/components/Board/Column.d.ts.map +1 -0
  25. package/dist/types/src/components/Board/Item.d.ts +9 -0
  26. package/dist/types/src/components/Board/Item.d.ts.map +1 -0
  27. package/dist/types/src/components/Board/index.d.ts +2 -0
  28. package/dist/types/src/components/Board/index.d.ts.map +1 -0
  29. package/dist/types/src/components/Focus/Focus.d.ts +5 -4
  30. package/dist/types/src/components/Focus/Focus.d.ts.map +1 -1
  31. package/dist/types/src/components/Focus/index.d.ts +0 -1
  32. package/dist/types/src/components/Focus/index.d.ts.map +1 -1
  33. package/dist/types/src/components/Mosaic/Container.d.ts +42 -0
  34. package/dist/types/src/components/Mosaic/Container.d.ts.map +1 -0
  35. package/dist/types/src/components/Mosaic/Mosaic.d.ts +35 -118
  36. package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -1
  37. package/dist/types/src/components/Mosaic/Placeholder.d.ts +21 -0
  38. package/dist/types/src/components/Mosaic/Placeholder.d.ts.map +1 -0
  39. package/dist/types/src/components/Mosaic/Root.d.ts +36 -0
  40. package/dist/types/src/components/Mosaic/Root.d.ts.map +1 -0
  41. package/dist/types/src/components/Mosaic/Stack.d.ts +23 -0
  42. package/dist/types/src/components/Mosaic/Stack.d.ts.map +1 -0
  43. package/dist/types/src/components/{Stack → Mosaic}/Stack.stories.d.ts +2 -2
  44. package/dist/types/src/components/Mosaic/Stack.stories.d.ts.map +1 -0
  45. package/dist/types/src/components/Mosaic/Tile.d.ts +48 -0
  46. package/dist/types/src/components/Mosaic/Tile.d.ts.map +1 -0
  47. package/dist/types/src/components/Mosaic/styles.d.ts.map +1 -1
  48. package/dist/types/src/components/Mosaic/types.d.ts +9 -2
  49. package/dist/types/src/components/Mosaic/types.d.ts.map +1 -1
  50. package/dist/types/src/components/index.d.ts +1 -4
  51. package/dist/types/src/components/index.d.ts.map +1 -1
  52. package/dist/types/src/hooks/index.d.ts +1 -0
  53. package/dist/types/src/hooks/index.d.ts.map +1 -1
  54. package/dist/types/src/hooks/useDefaultColumnEventHandler.d.ts +15 -0
  55. package/dist/types/src/hooks/useDefaultColumnEventHandler.d.ts.map +1 -0
  56. package/dist/types/src/hooks/useEventHandlerAdapter.d.ts +1 -1
  57. package/dist/types/src/hooks/useEventHandlerAdapter.d.ts.map +1 -1
  58. package/dist/types/src/hooks/useVisibleItems.d.ts +2 -2
  59. package/dist/types/src/hooks/useVisibleItems.d.ts.map +1 -1
  60. package/dist/types/src/playwright/board-manager.d.ts +45 -0
  61. package/dist/types/src/playwright/board-manager.d.ts.map +1 -0
  62. package/dist/types/src/playwright/index.d.ts +9 -0
  63. package/dist/types/src/playwright/index.d.ts.map +1 -0
  64. package/dist/types/src/playwright/playwright.config.d.ts +3 -0
  65. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
  66. package/dist/types/src/playwright/smoke.spec.d.ts +2 -0
  67. package/dist/types/src/playwright/smoke.spec.d.ts.map +1 -0
  68. package/dist/types/src/testing/CardContainer.d.ts +5 -4
  69. package/dist/types/src/testing/CardContainer.d.ts.map +1 -1
  70. package/dist/types/src/testing/DefaultStackTile.d.ts +2 -2
  71. package/dist/types/src/testing/DefaultStackTile.d.ts.map +1 -1
  72. package/dist/types/src/testing/index.d.ts +1 -1
  73. package/dist/types/src/testing/index.d.ts.map +1 -1
  74. package/dist/types/src/testing/types.d.ts +21 -0
  75. package/dist/types/src/testing/types.d.ts.map +1 -0
  76. package/dist/types/src/translations.d.ts +5 -1
  77. package/dist/types/src/translations.d.ts.map +1 -1
  78. package/dist/types/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +43 -28
  80. package/src/components/Board/Board.stories.tsx +273 -0
  81. package/src/components/Board/Board.tsx +191 -0
  82. package/src/components/Board/Column.tsx +300 -0
  83. package/src/components/Board/Item.tsx +116 -0
  84. package/src/components/{Layout → Board}/index.ts +1 -1
  85. package/src/components/Focus/Focus.tsx +26 -17
  86. package/src/components/Focus/index.ts +0 -2
  87. package/src/components/Mosaic/Container.tsx +289 -0
  88. package/src/components/Mosaic/Mosaic.tsx +35 -913
  89. package/src/components/Mosaic/Placeholder.tsx +133 -0
  90. package/src/components/Mosaic/Root.tsx +292 -0
  91. package/src/components/{Stack → Mosaic}/Stack.stories.tsx +30 -26
  92. package/src/components/Mosaic/Stack.tsx +246 -0
  93. package/src/components/Mosaic/Tile.tsx +242 -0
  94. package/src/components/Mosaic/extension.ts +1 -1
  95. package/src/components/Mosaic/styles.ts +9 -8
  96. package/src/components/Mosaic/types.ts +15 -3
  97. package/src/components/index.ts +1 -4
  98. package/src/hooks/index.ts +1 -0
  99. package/src/hooks/useContainerDebug.tsx +4 -2
  100. package/src/hooks/useDefaultColumnEventHandler.ts +35 -0
  101. package/src/hooks/useEventHandlerAdapter.ts +15 -6
  102. package/src/hooks/useVisibleItems.ts +7 -2
  103. package/src/playwright/board-manager.ts +154 -0
  104. package/src/playwright/index.ts +13 -0
  105. package/src/playwright/playwright.config.ts +17 -0
  106. package/src/playwright/smoke.spec.ts +138 -0
  107. package/src/testing/CardContainer.tsx +30 -18
  108. package/src/testing/DefaultStackTile.tsx +27 -16
  109. package/src/testing/index.ts +1 -1
  110. package/src/testing/types.ts +38 -0
  111. package/src/translations.ts +5 -1
  112. package/dist/lib/browser/chunk-UMBPEG4F.mjs +0 -1637
  113. package/dist/lib/browser/chunk-UMBPEG4F.mjs.map +0 -7
  114. package/dist/lib/browser/index.css +0 -13
  115. package/dist/lib/browser/index.css.map +0 -7
  116. package/dist/lib/browser/testing/index.css +0 -13
  117. package/dist/lib/browser/testing/index.css.map +0 -7
  118. package/dist/lib/node-esm/chunk-X6GV7SMK.mjs +0 -1639
  119. package/dist/lib/node-esm/chunk-X6GV7SMK.mjs.map +0 -7
  120. package/dist/lib/node-esm/index.css +0 -13
  121. package/dist/lib/node-esm/index.css.map +0 -7
  122. package/dist/lib/node-esm/testing/index.css +0 -13
  123. package/dist/lib/node-esm/testing/index.css.map +0 -7
  124. package/dist/types/src/components/Card/Card.d.ts +0 -121
  125. package/dist/types/src/components/Card/Card.d.ts.map +0 -1
  126. package/dist/types/src/components/Card/Card.stories.d.ts +0 -21
  127. package/dist/types/src/components/Card/Card.stories.d.ts.map +0 -1
  128. package/dist/types/src/components/Card/CardDragPreview.d.ts +0 -6
  129. package/dist/types/src/components/Card/CardDragPreview.d.ts.map +0 -1
  130. package/dist/types/src/components/Card/index.d.ts +0 -4
  131. package/dist/types/src/components/Card/index.d.ts.map +0 -1
  132. package/dist/types/src/components/Card/styles.d.ts +0 -13
  133. package/dist/types/src/components/Card/styles.d.ts.map +0 -1
  134. package/dist/types/src/components/Focus/styles.d.ts +0 -6
  135. package/dist/types/src/components/Focus/styles.d.ts.map +0 -1
  136. package/dist/types/src/components/Image/Image.d.ts +0 -14
  137. package/dist/types/src/components/Image/Image.d.ts.map +0 -1
  138. package/dist/types/src/components/Image/Image.stories.d.ts +0 -33
  139. package/dist/types/src/components/Image/Image.stories.d.ts.map +0 -1
  140. package/dist/types/src/components/Image/index.d.ts +0 -2
  141. package/dist/types/src/components/Image/index.d.ts.map +0 -1
  142. package/dist/types/src/components/Layout/Layout.d.ts +0 -33
  143. package/dist/types/src/components/Layout/Layout.d.ts.map +0 -1
  144. package/dist/types/src/components/Layout/Layout.stories.d.ts +0 -10
  145. package/dist/types/src/components/Layout/Layout.stories.d.ts.map +0 -1
  146. package/dist/types/src/components/Layout/index.d.ts +0 -2
  147. package/dist/types/src/components/Layout/index.d.ts.map +0 -1
  148. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts.map +0 -1
  149. package/dist/types/src/components/Scrollable/Scrollable.d.ts +0 -24
  150. package/dist/types/src/components/Scrollable/Scrollable.d.ts.map +0 -1
  151. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts +0 -10
  152. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts.map +0 -1
  153. package/dist/types/src/components/Scrollable/index.d.ts +0 -2
  154. package/dist/types/src/components/Scrollable/index.d.ts.map +0 -1
  155. package/dist/types/src/components/Stack/Stack.d.ts +0 -22
  156. package/dist/types/src/components/Stack/Stack.d.ts.map +0 -1
  157. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +0 -1
  158. package/dist/types/src/components/Stack/index.d.ts +0 -2
  159. package/dist/types/src/components/Stack/index.d.ts.map +0 -1
  160. package/dist/types/src/testing/Board.d.ts +0 -45
  161. package/dist/types/src/testing/Board.d.ts.map +0 -1
  162. package/dist/types/src/testing/Slot.stories.d.ts +0 -14
  163. package/dist/types/src/testing/Slot.stories.d.ts.map +0 -1
  164. package/dist/types/src/testing/Virtualizer.stories.d.ts +0 -12
  165. package/dist/types/src/testing/Virtualizer.stories.d.ts.map +0 -1
  166. package/src/components/Card/Card.stories.tsx +0 -148
  167. package/src/components/Card/Card.tsx +0 -458
  168. package/src/components/Card/CardDragPreview.tsx +0 -23
  169. package/src/components/Card/index.ts +0 -8
  170. package/src/components/Card/styles.ts +0 -23
  171. package/src/components/Focus/styles.ts +0 -24
  172. package/src/components/Image/Image.stories.tsx +0 -86
  173. package/src/components/Image/Image.tsx +0 -223
  174. package/src/components/Image/index.ts +0 -5
  175. package/src/components/Layout/Layout.stories.tsx +0 -59
  176. package/src/components/Layout/Layout.tsx +0 -108
  177. package/src/components/Mosaic/Mosaic.stories.tsx +0 -113
  178. package/src/components/Scrollable/Scrollable.stories.tsx +0 -59
  179. package/src/components/Scrollable/Scrollable.tsx +0 -88
  180. package/src/components/Scrollable/index.ts +0 -5
  181. package/src/components/Scrollable/scrollable.css +0 -20
  182. package/src/components/Stack/Stack.tsx +0 -210
  183. package/src/components/Stack/index.ts +0 -5
  184. package/src/testing/Board.tsx +0 -278
  185. package/src/testing/Slot.stories.tsx +0 -101
  186. package/src/testing/Virtualizer.stories.tsx +0 -133
@@ -1,100 +1,626 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
  import {
3
- Card,
4
3
  Focus,
5
- Image,
6
4
  Mosaic,
7
- Stack,
8
- VirtualStack,
9
- dropHandler,
5
+ getSourceData,
10
6
  styles,
11
- styles2,
12
- styles3,
13
- useContainerContext,
14
- useContainerDebug,
15
- useEventHandlerAdapter,
16
7
  useFocus,
17
- useRootContext,
18
- useTileContext,
8
+ useMosaicContainerContext,
9
+ useMosaicRootContext,
10
+ useMosaicTileContext,
19
11
  useVisibleItems
20
- } from "./chunk-X6GV7SMK.mjs";
12
+ } from "./chunk-MK6KU66S.mjs";
21
13
 
22
- // src/components/Card/CardDragPreview.tsx
23
- import React from "react";
14
+ // src/components/Board/Board.tsx
15
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
16
+ import { createContext as createContext2 } from "@radix-ui/react-context";
17
+ import React4, { forwardRef as forwardRef4, useRef as useRef4, useState as useState2 } from "react";
18
+ import { ScrollArea as ScrollArea2 } from "@dxos/react-ui";
19
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
20
+ import { mx as mx3 } from "@dxos/ui-theme";
21
+
22
+ // src/hooks/useContainerDebug.tsx
23
+ import React, { forwardRef, useMemo, useRef } from "react";
24
+ import { createPortal } from "react-dom";
25
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
24
26
  import { mx } from "@dxos/ui-theme";
25
- var CardDragPreviewRoot = ({ children }) => {
26
- return /* @__PURE__ */ React.createElement("div", {
27
- className: "p-2"
28
- }, children);
27
+ var useContainerDebug = (debug) => {
28
+ const debugRef = useRef(null);
29
+ return useMemo(() => {
30
+ if (!debug) {
31
+ return [
32
+ () => null,
33
+ void 0
34
+ ];
35
+ }
36
+ return [
37
+ ({ classNames }) => /* @__PURE__ */ React.createElement("div", {
38
+ role: "none",
39
+ className: mx("overflow-hidden", classNames),
40
+ ref: debugRef
41
+ }),
42
+ () => debugRef.current && /* @__PURE__ */ createPortal(/* @__PURE__ */ React.createElement(ContainerInfo, null), debugRef.current)
43
+ ];
44
+ }, [
45
+ debug,
46
+ debugRef
47
+ ]);
29
48
  };
30
- var CardDragPreviewContent = ({ children }) => {
31
- return /* @__PURE__ */ React.createElement("div", {
32
- className: mx(styles.root, "ring-focusLine ring-neutralFocusIndicator")
33
- }, children);
49
+ var CONTAINER_INFO_NAME = "ContainerInfo";
50
+ var ContainerInfo = /* @__PURE__ */ forwardRef(({ classNames }, forwardedRef) => {
51
+ const { id, state, activeLocation, scrolling } = useMosaicContainerContext(CONTAINER_INFO_NAME);
52
+ const counter = useRef(0);
53
+ return /* @__PURE__ */ React.createElement(Json, {
54
+ data: {
55
+ id,
56
+ activeLocation,
57
+ scrolling,
58
+ state,
59
+ count: counter.current++
60
+ },
61
+ classNames: mx("text-xs", classNames),
62
+ ref: forwardedRef
63
+ });
64
+ });
65
+ ContainerInfo.displayName = CONTAINER_INFO_NAME;
66
+
67
+ // src/hooks/useEventHandlerAdapter.ts
68
+ import { useMemo as useMemo2 } from "react";
69
+ import { log } from "@dxos/log";
70
+ import { arrayMove } from "@dxos/util";
71
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/hooks/useEventHandlerAdapter.ts";
72
+ var useEventHandlerAdapter = ({ items, getId, get, make, onChange, ...props }) => {
73
+ return useMemo2(() => ({
74
+ ...props,
75
+ onTake: ({ source }, cb) => {
76
+ log.info("onTake", {
77
+ source
78
+ }, {
79
+ F: __dxlog_file,
80
+ L: 61,
81
+ S: void 0,
82
+ C: (f, a) => f(...a)
83
+ });
84
+ const mutate = (items2) => {
85
+ const from = items2.findIndex((item) => getId(item) === source.id);
86
+ if (from !== -1) {
87
+ items2.splice(from, 1);
88
+ }
89
+ };
90
+ if (onChange) {
91
+ onChange(mutate);
92
+ } else {
93
+ mutate(items);
94
+ }
95
+ void cb(source.data);
96
+ },
97
+ onDrop: ({ source, target }) => {
98
+ log.info("onDrop", {
99
+ source,
100
+ target
101
+ }, {
102
+ F: __dxlog_file,
103
+ L: 78,
104
+ S: void 0,
105
+ C: (f, a) => f(...a)
106
+ });
107
+ const mutate = (items2) => {
108
+ const to = target?.type === "tile" || target?.type === "placeholder" ? target.location : target?.type === "container" ? items2.length : -1;
109
+ const from = items2.findIndex((item) => getId(item) === source.id);
110
+ const insertIndex = typeof to === "number" && to >= 0 ? Math.floor(to) : -1;
111
+ if (insertIndex !== -1) {
112
+ if (from !== -1) {
113
+ arrayMove(items2, from, insertIndex);
114
+ } else {
115
+ items2.splice(insertIndex, 0, make(get(source.data)));
116
+ }
117
+ }
118
+ };
119
+ if (onChange) {
120
+ onChange(mutate);
121
+ } else {
122
+ mutate(items);
123
+ }
124
+ }
125
+ }), [
126
+ items,
127
+ onChange
128
+ ]);
34
129
  };
35
- var CardDragPreview = {
36
- Root: CardDragPreviewRoot,
37
- Content: CardDragPreviewContent
130
+
131
+ // src/hooks/useDefaultColumnEventHandler.ts
132
+ var useDefaultColumnEventHandler = (id, model, items) => useEventHandlerAdapter({
133
+ id,
134
+ items,
135
+ getId: model.getColumnId,
136
+ get: (data) => data,
137
+ make: (object) => object,
138
+ canDrop: ({ source }) => model.isColumn(source.data)
139
+ });
140
+
141
+ // src/components/Mosaic/extension.ts
142
+ import { StateEffect, StateField } from "@codemirror/state";
143
+ import { Decoration, EditorView, ViewPlugin, WidgetType } from "@codemirror/view";
144
+ var dropHandler = ({ onDrop = handleDrop } = {}) => {
145
+ const views = /* @__PURE__ */ new Set();
146
+ let state = null;
147
+ const reset = () => {
148
+ views.forEach((view) => view.dispatch({
149
+ effects: setDrop.of(null)
150
+ }));
151
+ state = null;
152
+ };
153
+ const extension = [
154
+ dropField,
155
+ ViewPlugin.fromClass(class {
156
+ _view;
157
+ constructor(_view) {
158
+ this._view = _view;
159
+ views.add(_view);
160
+ }
161
+ destroy() {
162
+ views.delete(this._view);
163
+ }
164
+ })
165
+ ];
166
+ return {
167
+ extension,
168
+ update: (position) => {
169
+ if (!position) {
170
+ reset();
171
+ return;
172
+ }
173
+ views.forEach((view) => {
174
+ const rect = view.dom.getBoundingClientRect();
175
+ if (position.x >= rect.left && position.x <= rect.right && position.y >= rect.top && position.y <= rect.bottom) {
176
+ let pos = view.posAtCoords(position);
177
+ if (pos !== null) {
178
+ const word = view.state.wordAt(pos);
179
+ if (word) {
180
+ const startDist = Math.abs(pos - word.from);
181
+ const endDist = Math.abs(pos - word.to);
182
+ pos = startDist < endDist ? word.from : word.to;
183
+ }
184
+ view.dispatch({
185
+ effects: setDrop.of(pos)
186
+ });
187
+ state = {
188
+ view,
189
+ pos
190
+ };
191
+ return;
192
+ }
193
+ }
194
+ view.dispatch({
195
+ effects: setDrop.of(null)
196
+ });
197
+ });
198
+ },
199
+ cancel: () => {
200
+ reset();
201
+ },
202
+ drop: ({ text, url }) => {
203
+ if (state) {
204
+ onDrop(state.view, state.pos, {
205
+ text,
206
+ url
207
+ });
208
+ }
209
+ reset();
210
+ }
211
+ };
38
212
  };
213
+ var handleDrop = (view, pos, event) => {
214
+ const line = view.state.doc.lineAt(pos);
215
+ if (line.text.trim() === "") {
216
+ view.dispatch({
217
+ changes: {
218
+ from: pos,
219
+ insert: `
220
+ ![${event.text}](${event.url})
221
+ `
222
+ },
223
+ effects: setDrop.of(null)
224
+ });
225
+ } else {
226
+ view.dispatch({
227
+ changes: {
228
+ from: pos,
229
+ insert: ` [${event.text}](${event.url})`
230
+ },
231
+ effects: setDrop.of(null)
232
+ });
233
+ }
234
+ };
235
+ var setDrop = StateEffect.define();
236
+ var dropField = StateField.define({
237
+ create: () => Decoration.none,
238
+ update: (decorations, tr) => {
239
+ for (const effect of tr.effects) {
240
+ if (effect.is(setDrop)) {
241
+ if (effect.value === null) {
242
+ return Decoration.none;
243
+ }
244
+ return Decoration.set([
245
+ Decoration.widget({
246
+ widget: new class extends WidgetType {
247
+ toDOM() {
248
+ const dom = document.createElement("span");
249
+ dom.className = "cm-drop-cursor";
250
+ dom.style.borderLeft = "2px solid var(--color-accent-surface)";
251
+ dom.style.display = "inline-block";
252
+ dom.style.height = "1em";
253
+ dom.style.verticalAlign = "middle";
254
+ return dom;
255
+ }
256
+ }(),
257
+ side: 0
258
+ }).range(effect.value)
259
+ ]);
260
+ }
261
+ }
262
+ return decorations.map(tr.changes);
263
+ },
264
+ provide: (field) => EditorView.decorations.from(field)
265
+ });
39
266
 
40
- // src/components/Layout/Layout.tsx
41
- import React2, { forwardRef, useMemo } from "react";
267
+ // src/components/Board/Column.tsx
268
+ import { useAtomValue } from "@effect-atom/atom-react";
269
+ import { createContext } from "@radix-ui/react-context";
270
+ import React3, { forwardRef as forwardRef3, useMemo as useMemo4, useRef as useRef3, useState } from "react";
271
+ import { Obj as Obj2, Ref } from "@dxos/echo";
272
+ import { useObject } from "@dxos/react-client/echo";
273
+ import { IconButton, ScrollArea, Toolbar as Toolbar2, useTranslation as useTranslation2 } from "@dxos/react-ui";
274
+ import { Menu as Menu2, createMenuAction as createMenuAction2 } from "@dxos/react-ui-menu";
42
275
  import { mx as mx2 } from "@dxos/ui-theme";
43
- var Main = /* @__PURE__ */ forwardRef(({ classNames, children, role, toolbar, statusbar }, forwardedRef) => {
44
- const style = useMemo(() => ({
45
- gridTemplateRows: [
46
- toolbar && "var(--toolbar-size)",
47
- "1fr",
48
- statusbar && "var(--statusbar-size)"
49
- ].filter(Boolean).join(" ")
50
- }), [
51
- toolbar,
52
- statusbar
276
+
277
+ // src/translations.ts
278
+ var translationKey = "@dxos/react-ui-mosaic";
279
+ var translations = [
280
+ {
281
+ "en-US": {
282
+ [translationKey]: {
283
+ "action menu label": "Actions",
284
+ "add item label": "Add item",
285
+ "delete menu label": "Delete"
286
+ }
287
+ }
288
+ }
289
+ ];
290
+
291
+ // src/components/Board/Item.tsx
292
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
293
+ import React2, { forwardRef as forwardRef2, useMemo as useMemo3, useRef as useRef2 } from "react";
294
+ import { Obj } from "@dxos/echo";
295
+ import { Card, Tag, Toolbar, useTranslation } from "@dxos/react-ui";
296
+ import { Menu, createMenuAction } from "@dxos/react-ui-menu";
297
+ import { getHashStyles } from "@dxos/ui-theme";
298
+ var BOARD_ITEM_NAME = "Board.Item";
299
+ var BoardItemInner = /* @__PURE__ */ forwardRef2(({ classNames, data, location, debug }, forwardedRef) => {
300
+ const { t } = useTranslation(translationKey);
301
+ const rootRef = useRef2(null);
302
+ const composedRef = useComposedRefs(rootRef, forwardedRef);
303
+ const dragHandleRef = useRef2(null);
304
+ const { model } = useBoard(BOARD_ITEM_NAME);
305
+ const column = useBoardColumn();
306
+ const items = useMemo3(() => column != null && model.onItemDelete ? [
307
+ createMenuAction("delete-item", () => model.onItemDelete?.(column, data), {
308
+ label: t("delete menu label"),
309
+ icon: "ph--trash--regular"
310
+ })
311
+ ] : [], [
312
+ column,
313
+ data,
314
+ model.onItemDelete,
315
+ t
53
316
  ]);
54
- return /* @__PURE__ */ React2.createElement("div", {
55
- ref: forwardedRef,
56
- role: role ?? "none",
57
- style,
58
- className: mx2("bs-full is-full grid grid-cols-[100%] overflow-hidden", toolbar && "[&>.dx-toolbar]:relative [&>.dx-toolbar]:border-be [&>.dx-toolbar]:border-subduedSeparator", classNames)
59
- }, children);
317
+ if (!data) {
318
+ return null;
319
+ }
320
+ const label = Obj.getLabel(data);
321
+ const description = Obj.getDescription(data);
322
+ return /* @__PURE__ */ React2.createElement(Mosaic.Tile, {
323
+ asChild: true,
324
+ dragHandle: dragHandleRef.current,
325
+ id: data.id,
326
+ data,
327
+ location,
328
+ debug
329
+ }, /* @__PURE__ */ React2.createElement(Focus.Group, {
330
+ asChild: true
331
+ }, /* @__PURE__ */ React2.createElement(Menu.Root, null, /* @__PURE__ */ React2.createElement(Card.Root, {
332
+ classNames,
333
+ "data-testid": "board-item",
334
+ onClick: () => rootRef.current?.focus(),
335
+ ref: composedRef
336
+ }, /* @__PURE__ */ React2.createElement(Card.Toolbar, null, /* @__PURE__ */ React2.createElement(Card.DragHandle, {
337
+ ref: dragHandleRef
338
+ }), /* @__PURE__ */ React2.createElement(Card.Title, null, label), /* @__PURE__ */ React2.createElement(Menu.Trigger, {
339
+ asChild: true,
340
+ disabled: !items?.length
341
+ }, /* @__PURE__ */ React2.createElement(Toolbar.IconButton, {
342
+ iconOnly: true,
343
+ variant: "ghost",
344
+ icon: "ph--dots-three-vertical--regular",
345
+ label: t("action menu label")
346
+ })), /* @__PURE__ */ React2.createElement(Menu.Content, {
347
+ items
348
+ })), /* @__PURE__ */ React2.createElement(Card.Row, {
349
+ icon: "ph--note--regular",
350
+ classNames: "text-description"
351
+ }, description), /* @__PURE__ */ React2.createElement(Card.Row, {
352
+ icon: "ph--tag--regular"
353
+ }, label && /* @__PURE__ */ React2.createElement("div", {
354
+ role: "none",
355
+ className: "shrink-0 flex gap-1 items-center text-xs"
356
+ }, /* @__PURE__ */ React2.createElement(Tag, {
357
+ palette: getHashStyles(label).hue
358
+ }, label)))))));
60
359
  });
61
- var Container = /* @__PURE__ */ forwardRef(({ classNames, children, role, scrollable }, forwardedRef) => {
62
- return /* @__PURE__ */ React2.createElement("div", {
63
- ref: forwardedRef,
64
- role: role ?? "none",
65
- className: mx2("grid bs-full", scrollable ? "overflow-y-auto" : "overflow-hidden", classNames)
66
- }, children);
360
+ BoardItemInner.displayName = BOARD_ITEM_NAME;
361
+ var BoardItem = BoardItemInner;
362
+
363
+ // src/components/Board/Column.tsx
364
+ var BOARD_COLUMN_CONTEXT_NAME = "Board.Column";
365
+ var [BoardColumnProvider, useBoardColumnContext] = createContext(BOARD_COLUMN_CONTEXT_NAME, null);
366
+ function useBoardColumn() {
367
+ const value = useBoardColumnContext(BOARD_COLUMN_CONTEXT_NAME);
368
+ return value?.column;
369
+ }
370
+ var BOARD_COLUMN_ROOT_NAME = "Board.Column.Root";
371
+ var BoardColumnRootInner = /* @__PURE__ */ forwardRef3(({ classNames, children, location, data, debug, dragHandleRef: dragHandleRefProp, ...rest }, forwardedRef) => {
372
+ const { model } = useBoard(BOARD_COLUMN_ROOT_NAME);
373
+ const internalRef = useRef3(null);
374
+ const dragHandleRef = dragHandleRefProp ?? internalRef;
375
+ return /* @__PURE__ */ React3.createElement(Mosaic.Tile, {
376
+ asChild: true,
377
+ location,
378
+ id: model.getColumnId(data),
379
+ data,
380
+ debug,
381
+ dragHandle: dragHandleRef.current
382
+ }, /* @__PURE__ */ React3.createElement(Focus.Group, {
383
+ ...rest,
384
+ "data-testid": "board-column",
385
+ classNames: mx2(
386
+ // NOTE: Reserves 2px for outer Focus.Group border.
387
+ "group/column h-full overflow-hidden w-[calc(100vw-2px)] md:w-card-default-width snap-center bg-deck-surface",
388
+ classNames
389
+ ),
390
+ ref: forwardedRef
391
+ }, /* @__PURE__ */ React3.createElement(BoardColumnProvider, {
392
+ column: data
393
+ }, children)));
394
+ });
395
+ BoardColumnRootInner.displayName = BOARD_COLUMN_ROOT_NAME;
396
+ var BoardColumnRoot = BoardColumnRootInner;
397
+ var BOARD_COLUMN_HEADER_NAME = "Board.Column.Header";
398
+ var BoardColumnHeader = /* @__PURE__ */ forwardRef3(({ classNames, label, dragHandleRef }, forwardedRef) => {
399
+ const { t } = useTranslation2(translationKey);
400
+ const { model } = useBoard(BOARD_COLUMN_HEADER_NAME);
401
+ const column = useBoardColumn();
402
+ const columnMenuItems = useMemo4(() => column != null && model.onColumnDelete ? [
403
+ createMenuAction2("delete-column", () => model.onColumnDelete?.(column), {
404
+ label: t("delete menu label"),
405
+ icon: "ph--trash--regular"
406
+ })
407
+ ] : [], [
408
+ column,
409
+ model.onColumnDelete,
410
+ t
411
+ ]);
412
+ return /* @__PURE__ */ React3.createElement(Menu2.Root, null, /* @__PURE__ */ React3.createElement(Toolbar2.Root, {
413
+ classNames: mx2("border-b border-separator", classNames),
414
+ "data-testid": "board-column-header",
415
+ ref: forwardedRef
416
+ }, /* @__PURE__ */ React3.createElement(Toolbar2.DragHandle, {
417
+ ref: dragHandleRef
418
+ }), /* @__PURE__ */ React3.createElement(Toolbar2.Text, null, label), /* @__PURE__ */ React3.createElement(Menu2.Trigger, {
419
+ asChild: true,
420
+ disabled: !columnMenuItems?.length
421
+ }, /* @__PURE__ */ React3.createElement(Toolbar2.IconButton, {
422
+ iconOnly: true,
423
+ variant: "ghost",
424
+ icon: "ph--dots-three-vertical--regular",
425
+ label: t("action menu label")
426
+ })), /* @__PURE__ */ React3.createElement(Menu2.Content, {
427
+ items: columnMenuItems
428
+ })));
67
429
  });
68
- var Flex = ({ children, classNames, role, column, grow }) => {
69
- return /* @__PURE__ */ React2.createElement("div", {
70
- role: role ?? "none",
71
- className: mx2("flex", column && "flex-col", grow && "flex-1 overflow-hidden", classNames)
430
+ BoardColumnHeader.displayName = BOARD_COLUMN_HEADER_NAME;
431
+ var BOARD_COLUMN_BODY_NAME = "Board.Column.Body";
432
+ var BoardColumnBody = ({ data, eventHandler, Tile = BoardItem, debug }) => {
433
+ const { model } = useBoard(BOARD_COLUMN_BODY_NAME);
434
+ const [viewport, setViewport] = useState(null);
435
+ const items = useAtomValue(model.items(data));
436
+ return /* @__PURE__ */ React3.createElement(Mosaic.Container, {
437
+ asChild: true,
438
+ withFocus: true,
439
+ orientation: "vertical",
440
+ autoScroll: viewport,
441
+ eventHandler,
442
+ debug
443
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Root, {
444
+ orientation: "vertical",
445
+ thin: true,
446
+ margin: true,
447
+ padding: true
448
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Viewport, {
449
+ classNames: "snap-y md:snap-none",
450
+ ref: setViewport
451
+ }, /* @__PURE__ */ React3.createElement(Mosaic.Stack, {
452
+ items,
453
+ getId: model.getItemId,
454
+ Tile
455
+ }))));
456
+ };
457
+ BoardColumnBody.displayName = BOARD_COLUMN_BODY_NAME;
458
+ var BOARD_COLUMN_FOOTER_NAME = "Board.Column.Footer";
459
+ var BoardColumnFooter = /* @__PURE__ */ forwardRef3(({ classNames, data, onAdd }, forwardedRef) => {
460
+ const { t } = useTranslation2(translationKey);
461
+ const { model } = useBoard(BOARD_COLUMN_FOOTER_NAME);
462
+ const handleAdd = onAdd ?? (model.onItemCreate && data ? () => void model.onItemCreate?.(data) : void 0);
463
+ return /* @__PURE__ */ React3.createElement(Toolbar2.Root, {
464
+ classNames: mx2("rounded-b-sm border-t border-separator", classNames),
465
+ ref: forwardedRef
466
+ }, handleAdd && /* @__PURE__ */ React3.createElement(IconButton, {
467
+ "data-testid": "board-column-add-item",
468
+ classNames: "group-hover/column:opacity-100 md:opacity-0 transition transition-opacity duration-500",
469
+ variant: "ghost",
470
+ icon: "ph--plus--regular",
471
+ iconOnly: true,
472
+ label: t("add item label"),
473
+ onClick: handleAdd
474
+ }));
475
+ });
476
+ BoardColumnFooter.displayName = BOARD_COLUMN_FOOTER_NAME;
477
+ var BOARD_DEFAULT_COLUMN_NAME = "Board.DefaultColumn";
478
+ var DefaultBoardColumn = /* @__PURE__ */ forwardRef3(({ classNames, location, data, debug, Tile = BoardItem }, forwardedRef) => {
479
+ const { model } = useBoard(BOARD_DEFAULT_COLUMN_NAME);
480
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
481
+ const dragHandleRef = useRef3(null);
482
+ const [column, updateColumn] = useObject(data);
483
+ const eventHandler = useEventHandlerAdapter({
484
+ id: model.getColumnId(data),
485
+ items: column?.items ?? [],
486
+ getId: (ref) => ref.target?.id ?? ref.dxn.toString(),
487
+ get: (refOrObj) => Ref.isRef(refOrObj) ? refOrObj.target : refOrObj,
488
+ make: (object) => Ref.make(object),
489
+ canDrop: ({ source }) => {
490
+ const item = Ref.isRef(source.data) ? source.data.target : source.data;
491
+ return item != null && Obj2.isObject(item) && model.isItem(item);
492
+ },
493
+ onChange: (mutator) => updateColumn((col) => mutator(col.items))
494
+ });
495
+ return /* @__PURE__ */ React3.createElement(BoardColumnRootInner, {
496
+ classNames: mx2("group/column grid", debug ? "grid-rows-[var(--dx-rail-action)_1fr_20rem]" : "grid-rows-[var(--dx-rail-action)_1fr_var(--dx-rail-action)]", classNames),
497
+ location,
498
+ data,
499
+ dragHandleRef,
500
+ ref: forwardedRef
501
+ }, /* @__PURE__ */ React3.createElement(BoardColumnHeader, {
502
+ label: Obj2.getLabel(data) ?? data.id,
503
+ dragHandleRef
504
+ }), /* @__PURE__ */ React3.createElement(BoardColumnBody, {
505
+ data,
506
+ eventHandler,
507
+ debug: debugHandler,
508
+ Tile
509
+ }), /* @__PURE__ */ React3.createElement("div", {
510
+ role: "none",
511
+ className: "flex flex-col col-span-full"
512
+ }, /* @__PURE__ */ React3.createElement(BoardColumnFooter, {
513
+ data
514
+ }), /* @__PURE__ */ React3.createElement(DebugInfo, null)));
515
+ });
516
+ DefaultBoardColumn.displayName = BOARD_DEFAULT_COLUMN_NAME;
517
+ var BoardColumn = {
518
+ Root: BoardColumnRoot,
519
+ Header: BoardColumnHeader,
520
+ Body: BoardColumnBody,
521
+ Footer: BoardColumnFooter
522
+ };
523
+
524
+ // src/components/Board/Board.tsx
525
+ var BOARD_NAME = "Board";
526
+ var [BoardContextProvider, useBoardContext] = createContext2(BOARD_NAME);
527
+ function useBoard(displayName) {
528
+ return useBoardContext(displayName ?? BOARD_NAME);
529
+ }
530
+ var BOARD_ROOT_NAME = "Board.Root";
531
+ var BoardRootInner = ({ model, children }) => {
532
+ return /* @__PURE__ */ React4.createElement(BoardContextProvider, {
533
+ model
72
534
  }, children);
73
535
  };
74
- var Layout = {
75
- Main,
76
- Container,
77
- Flex
536
+ BoardRootInner.displayName = BOARD_ROOT_NAME;
537
+ var BoardRoot = BoardRootInner;
538
+ var BOARD_CONTENT_NAME = "Board.Content";
539
+ var BoardContentInner = /* @__PURE__ */ forwardRef4(({ classNames, id: _id, debug, eventHandler, Tile = DefaultBoardColumn }, forwardedRef) => {
540
+ const { model } = useBoardContext(BOARD_CONTENT_NAME);
541
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
542
+ const [viewport, setViewport] = useState2(null);
543
+ const items = useAtomValue2(model.columns);
544
+ return /* @__PURE__ */ React4.createElement("div", {
545
+ ref: forwardedRef,
546
+ className: mx3("flex h-full w-full overflow-hidden", classNames)
547
+ }, /* @__PURE__ */ React4.createElement(Focus.Group, {
548
+ asChild: true,
549
+ orientation: "horizontal"
550
+ }, /* @__PURE__ */ React4.createElement(Mosaic.Container, {
551
+ asChild: true,
552
+ withFocus: true,
553
+ orientation: "horizontal",
554
+ autoScroll: viewport,
555
+ eventHandler,
556
+ debug: debugHandler
557
+ }, /* @__PURE__ */ React4.createElement(ScrollArea2.Root, {
558
+ orientation: "horizontal",
559
+ classNames: "md:pt-3",
560
+ margin: true,
561
+ padding: true
562
+ }, /* @__PURE__ */ React4.createElement(ScrollArea2.Viewport, {
563
+ classNames: "snap-mandatory snap-x md:snap-none",
564
+ ref: setViewport
565
+ }, /* @__PURE__ */ React4.createElement(Mosaic.Stack, {
566
+ items,
567
+ getId: model.getColumnId,
568
+ Tile,
569
+ debug
570
+ }))))), /* @__PURE__ */ React4.createElement(DebugInfo, null));
571
+ });
572
+ BoardContentInner.displayName = BOARD_CONTENT_NAME;
573
+ var BoardContent = BoardContentInner;
574
+ var BOARD_PLACEHOLDER_NAME = "Board.Placeholder";
575
+ var BoardPlaceholder = (props) => {
576
+ return /* @__PURE__ */ React4.createElement(Mosaic.Placeholder, {
577
+ ...props,
578
+ classNames: styles.placeholder.root
579
+ }, /* @__PURE__ */ React4.createElement("div", {
580
+ className: mx3("flex h-full border border-dashed border-separator rounded-xs", styles.placeholder.content)
581
+ }));
582
+ };
583
+ BoardPlaceholder.displayName = BOARD_PLACEHOLDER_NAME;
584
+ var BOARD_DEBUG_NAME = "Board.Debug";
585
+ var BoardDebug = /* @__PURE__ */ forwardRef4(({ classNames }, forwardedRef) => {
586
+ const { containers, dragging } = useMosaicRootContext(BOARD_DEBUG_NAME);
587
+ const counter = useRef4(0);
588
+ return /* @__PURE__ */ React4.createElement(Json2, {
589
+ data: {
590
+ containers,
591
+ dragging,
592
+ count: counter.current++
593
+ },
594
+ classNames: mx3("text-xs", classNames),
595
+ ref: forwardedRef
596
+ });
597
+ });
598
+ BoardDebug.displayName = BOARD_DEBUG_NAME;
599
+ var Board = {
600
+ Root: BoardRoot,
601
+ Content: BoardContent,
602
+ Column: BoardColumn,
603
+ Item: BoardItem,
604
+ Placeholder: BoardPlaceholder,
605
+ Debug: BoardDebug
78
606
  };
79
607
  export {
80
- Card,
81
- CardDragPreview,
608
+ Board,
609
+ BoardDebug,
82
610
  Focus,
83
- Image,
84
- Layout,
85
611
  Mosaic,
86
- Stack,
87
- VirtualStack,
88
- styles as cardStyles,
89
612
  dropHandler,
90
- styles2 as focusStyles,
91
- styles3 as mosaicStyles,
613
+ getSourceData,
614
+ styles as mosaicStyles,
615
+ useBoard,
616
+ useBoardColumn,
92
617
  useContainerDebug,
618
+ useDefaultColumnEventHandler,
93
619
  useEventHandlerAdapter,
94
620
  useFocus,
95
- useRootContext as useMosaic,
96
- useContainerContext as useMosaicContainer,
97
- useTileContext as useMosaicTile,
621
+ useMosaicRootContext as useMosaic,
622
+ useMosaicContainerContext as useMosaicContainer,
623
+ useMosaicTileContext as useMosaicTile,
98
624
  useVisibleItems
99
625
  };
100
626
  //# sourceMappingURL=index.mjs.map