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