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

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 (190) hide show
  1. package/dist/lib/browser/chunk-UTD5AWW5.mjs +1009 -0
  2. package/dist/lib/browser/chunk-UTD5AWW5.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +604 -71
  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 +148 -0
  7. package/dist/lib/browser/playwright/index.mjs.map +7 -0
  8. package/dist/lib/browser/testing/index.mjs +69 -236
  9. package/dist/lib/browser/testing/index.mjs.map +4 -4
  10. package/dist/lib/node-esm/chunk-5K56GSJL.mjs +1011 -0
  11. package/dist/lib/node-esm/chunk-5K56GSJL.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +604 -71
  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 +150 -0
  16. package/dist/lib/node-esm/playwright/index.mjs.map +7 -0
  17. package/dist/lib/node-esm/testing/index.mjs +69 -236
  18. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  19. package/dist/types/src/components/Board/Board.d.ts +88 -0
  20. package/dist/types/src/components/Board/Board.d.ts.map +1 -0
  21. package/dist/types/src/components/Board/Board.stories.d.ts +41 -0
  22. package/dist/types/src/components/Board/Board.stories.d.ts.map +1 -0
  23. package/dist/types/src/components/Board/Column.d.ts +48 -0
  24. package/dist/types/src/components/Board/Column.d.ts.map +1 -0
  25. package/dist/types/src/components/Board/Item.d.ts +12 -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 +1 -24
  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 +49 -0
  34. package/dist/types/src/components/Mosaic/Container.d.ts.map +1 -0
  35. package/dist/types/src/components/Mosaic/Mosaic.d.ts +36 -126
  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/Mosaic/Stack.stories.d.ts +20 -0
  44. package/dist/types/src/components/Mosaic/Stack.stories.d.ts.map +1 -0
  45. package/dist/types/src/components/Mosaic/Tile.d.ts +57 -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/AUDIT.md +106 -0
  81. package/src/components/Board/Board.stories.tsx +273 -0
  82. package/src/components/Board/Board.tsx +191 -0
  83. package/src/components/Board/Column.tsx +302 -0
  84. package/src/components/Board/Item.tsx +116 -0
  85. package/src/components/{Layout → Board}/index.ts +1 -1
  86. package/src/components/Focus/Focus.tsx +2 -93
  87. package/src/components/Focus/index.ts +0 -2
  88. package/src/components/Mosaic/Container.tsx +318 -0
  89. package/src/components/Mosaic/Mosaic.tsx +35 -913
  90. package/src/components/Mosaic/Placeholder.tsx +133 -0
  91. package/src/components/Mosaic/Root.tsx +292 -0
  92. package/src/components/Mosaic/Stack.stories.tsx +176 -0
  93. package/src/components/Mosaic/Stack.tsx +321 -0
  94. package/src/components/Mosaic/Tile.tsx +247 -0
  95. package/src/components/Mosaic/extension.ts +1 -1
  96. package/src/components/Mosaic/styles.ts +9 -8
  97. package/src/components/Mosaic/types.ts +15 -3
  98. package/src/components/index.ts +1 -4
  99. package/src/hooks/index.ts +1 -0
  100. package/src/hooks/useContainerDebug.tsx +5 -3
  101. package/src/hooks/useDefaultColumnEventHandler.ts +35 -0
  102. package/src/hooks/useEventHandlerAdapter.ts +15 -6
  103. package/src/hooks/useVisibleItems.ts +7 -2
  104. package/src/playwright/board-manager.ts +159 -0
  105. package/src/playwright/index.ts +13 -0
  106. package/src/playwright/playwright.config.ts +17 -0
  107. package/src/playwright/smoke.spec.ts +143 -0
  108. package/src/testing/CardContainer.tsx +31 -19
  109. package/src/testing/DefaultStackTile.tsx +36 -22
  110. package/src/testing/index.ts +1 -1
  111. package/src/testing/types.ts +38 -0
  112. package/src/translations.ts +5 -1
  113. package/dist/lib/browser/chunk-UMBPEG4F.mjs +0 -1637
  114. package/dist/lib/browser/chunk-UMBPEG4F.mjs.map +0 -7
  115. package/dist/lib/browser/index.css +0 -13
  116. package/dist/lib/browser/index.css.map +0 -7
  117. package/dist/lib/browser/testing/index.css +0 -13
  118. package/dist/lib/browser/testing/index.css.map +0 -7
  119. package/dist/lib/node-esm/chunk-X6GV7SMK.mjs +0 -1639
  120. package/dist/lib/node-esm/chunk-X6GV7SMK.mjs.map +0 -7
  121. package/dist/lib/node-esm/index.css +0 -13
  122. package/dist/lib/node-esm/index.css.map +0 -7
  123. package/dist/lib/node-esm/testing/index.css +0 -13
  124. package/dist/lib/node-esm/testing/index.css.map +0 -7
  125. package/dist/types/src/components/Card/Card.d.ts +0 -121
  126. package/dist/types/src/components/Card/Card.d.ts.map +0 -1
  127. package/dist/types/src/components/Card/Card.stories.d.ts +0 -21
  128. package/dist/types/src/components/Card/Card.stories.d.ts.map +0 -1
  129. package/dist/types/src/components/Card/CardDragPreview.d.ts +0 -6
  130. package/dist/types/src/components/Card/CardDragPreview.d.ts.map +0 -1
  131. package/dist/types/src/components/Card/index.d.ts +0 -4
  132. package/dist/types/src/components/Card/index.d.ts.map +0 -1
  133. package/dist/types/src/components/Card/styles.d.ts +0 -13
  134. package/dist/types/src/components/Card/styles.d.ts.map +0 -1
  135. package/dist/types/src/components/Focus/styles.d.ts +0 -6
  136. package/dist/types/src/components/Focus/styles.d.ts.map +0 -1
  137. package/dist/types/src/components/Image/Image.d.ts +0 -14
  138. package/dist/types/src/components/Image/Image.d.ts.map +0 -1
  139. package/dist/types/src/components/Image/Image.stories.d.ts +0 -33
  140. package/dist/types/src/components/Image/Image.stories.d.ts.map +0 -1
  141. package/dist/types/src/components/Image/index.d.ts +0 -2
  142. package/dist/types/src/components/Image/index.d.ts.map +0 -1
  143. package/dist/types/src/components/Layout/Layout.d.ts +0 -33
  144. package/dist/types/src/components/Layout/Layout.d.ts.map +0 -1
  145. package/dist/types/src/components/Layout/Layout.stories.d.ts +0 -10
  146. package/dist/types/src/components/Layout/Layout.stories.d.ts.map +0 -1
  147. package/dist/types/src/components/Layout/index.d.ts +0 -2
  148. package/dist/types/src/components/Layout/index.d.ts.map +0 -1
  149. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts +0 -27
  150. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts.map +0 -1
  151. package/dist/types/src/components/Scrollable/Scrollable.d.ts +0 -24
  152. package/dist/types/src/components/Scrollable/Scrollable.d.ts.map +0 -1
  153. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts +0 -10
  154. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts.map +0 -1
  155. package/dist/types/src/components/Scrollable/index.d.ts +0 -2
  156. package/dist/types/src/components/Scrollable/index.d.ts.map +0 -1
  157. package/dist/types/src/components/Stack/Stack.d.ts +0 -22
  158. package/dist/types/src/components/Stack/Stack.d.ts.map +0 -1
  159. package/dist/types/src/components/Stack/Stack.stories.d.ts +0 -9
  160. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +0 -1
  161. package/dist/types/src/components/Stack/index.d.ts +0 -2
  162. package/dist/types/src/components/Stack/index.d.ts.map +0 -1
  163. package/dist/types/src/testing/Board.d.ts +0 -45
  164. package/dist/types/src/testing/Board.d.ts.map +0 -1
  165. package/dist/types/src/testing/Slot.stories.d.ts +0 -14
  166. package/dist/types/src/testing/Slot.stories.d.ts.map +0 -1
  167. package/dist/types/src/testing/Virtualizer.stories.d.ts +0 -12
  168. package/dist/types/src/testing/Virtualizer.stories.d.ts.map +0 -1
  169. package/src/components/Card/Card.stories.tsx +0 -148
  170. package/src/components/Card/Card.tsx +0 -458
  171. package/src/components/Card/CardDragPreview.tsx +0 -23
  172. package/src/components/Card/index.ts +0 -8
  173. package/src/components/Card/styles.ts +0 -23
  174. package/src/components/Focus/styles.ts +0 -24
  175. package/src/components/Image/Image.stories.tsx +0 -86
  176. package/src/components/Image/Image.tsx +0 -223
  177. package/src/components/Image/index.ts +0 -5
  178. package/src/components/Layout/Layout.stories.tsx +0 -59
  179. package/src/components/Layout/Layout.tsx +0 -108
  180. package/src/components/Mosaic/Mosaic.stories.tsx +0 -113
  181. package/src/components/Scrollable/Scrollable.stories.tsx +0 -59
  182. package/src/components/Scrollable/Scrollable.tsx +0 -88
  183. package/src/components/Scrollable/index.ts +0 -5
  184. package/src/components/Scrollable/scrollable.css +0 -20
  185. package/src/components/Stack/Stack.stories.tsx +0 -115
  186. package/src/components/Stack/Stack.tsx +0 -210
  187. package/src/components/Stack/index.ts +0 -5
  188. package/src/testing/Board.tsx +0 -278
  189. package/src/testing/Slot.stories.tsx +0 -101
  190. package/src/testing/Virtualizer.stories.tsx +0 -133
@@ -1,99 +1,632 @@
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-UTD5AWW5.mjs";
12
+
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 { composable as composable2, composableProps as composableProps2, mx as mx3 } from "@dxos/ui-theme";
20
20
 
21
- // src/components/Card/CardDragPreview.tsx
22
- import React from "react";
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.Data, {
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
+ ]);
128
+ };
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
+ };
33
211
  };
34
- var CardDragPreview = {
35
- Root: CardDragPreviewRoot,
36
- Content: CardDragPreviewContent
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
+ }
37
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";
41
- 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
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";
274
+ import { composable, composableProps, mx as mx2 } from "@dxos/ui-theme";
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(Menu.Root, null, /* @__PURE__ */ React2.createElement(Mosaic.Tile, {
322
+ ref: rootRef,
323
+ asChild: true,
324
+ dragHandle: dragHandleRef.current,
325
+ id: data.id,
326
+ data,
327
+ location,
328
+ debug
329
+ }, /* @__PURE__ */ React2.createElement(Focus.Item, {
330
+ asChild: true
331
+ }, /* @__PURE__ */ React2.createElement(Card.Root, {
332
+ classNames,
333
+ "data-testid": "board-item",
334
+ ref: composedRef,
335
+ onClick: (event) => event.currentTarget.focus()
336
+ }, /* @__PURE__ */ React2.createElement(Card.Toolbar, null, /* @__PURE__ */ React2.createElement(Card.DragHandle, {
337
+ ref: dragHandleRef,
338
+ testId: "mosaicBoard.cardDragHandle"
339
+ }), /* @__PURE__ */ React2.createElement(Card.Title, {
340
+ "data-testid": "mosaicBoard.cardTitle"
341
+ }, label), /* @__PURE__ */ React2.createElement(Menu.Trigger, {
342
+ asChild: true,
343
+ disabled: !items?.length
344
+ }, /* @__PURE__ */ React2.createElement(Toolbar.IconButton, {
345
+ iconOnly: true,
346
+ variant: "ghost",
347
+ icon: "ph--dots-three-vertical--regular",
348
+ label: t("action-menu.label")
349
+ })), /* @__PURE__ */ React2.createElement(Menu.Content, {
350
+ items
351
+ })), /* @__PURE__ */ React2.createElement(Card.Row, {
352
+ icon: "ph--note--regular",
353
+ classNames: "text-description"
354
+ }, /* @__PURE__ */ React2.createElement(Card.Text, null, description)), /* @__PURE__ */ React2.createElement(Card.Row, {
355
+ icon: "ph--tag--regular"
356
+ }, label && /* @__PURE__ */ React2.createElement("div", {
357
+ role: "none",
358
+ className: "shrink-0 flex gap-1 items-center text-xs"
359
+ }, /* @__PURE__ */ React2.createElement(Tag, {
360
+ palette: getHashStyles(label).hue
361
+ }, label)))))));
59
362
  });
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);
363
+ BoardItemInner.displayName = BOARD_ITEM_NAME;
364
+ var BoardItem = BoardItemInner;
365
+
366
+ // src/components/Board/Column.tsx
367
+ var BOARD_COLUMN_CONTEXT_NAME = "Board.Column";
368
+ var [BoardColumnProvider, useBoardColumnContext] = createContext(BOARD_COLUMN_CONTEXT_NAME, null);
369
+ function useBoardColumn() {
370
+ const value = useBoardColumnContext(BOARD_COLUMN_CONTEXT_NAME);
371
+ return value?.column;
372
+ }
373
+ var BOARD_COLUMN_ROOT_NAME = "Board.Column.Root";
374
+ var BoardColumnRootInner = composable(({ classNames, children, location, data, debug, dragHandleRef: dragHandleRefProp, ...rest }, forwardedRef) => {
375
+ const { model } = useBoard(BOARD_COLUMN_ROOT_NAME);
376
+ const internalRef = useRef3(null);
377
+ const dragHandleRef = dragHandleRefProp ?? internalRef;
378
+ return /* @__PURE__ */ React3.createElement(Mosaic.Tile, {
379
+ asChild: true,
380
+ location,
381
+ id: model.getColumnId(data),
382
+ data,
383
+ debug,
384
+ dragHandle: dragHandleRef.current
385
+ }, /* @__PURE__ */ React3.createElement(Focus.Group, {
386
+ ...rest,
387
+ "data-testid": "board-column",
388
+ border: true,
389
+ classNames: mx2("group/column", "h-full w-full md:w-card-default-width snap-center bg-deck-surface", "overflow-hidden", classNames),
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 = composable(({ label, dragHandleRef, ...props }, 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
+ ...composableProps(props),
414
+ "data-testid": "board-column-header",
415
+ ref: forwardedRef
416
+ }, /* @__PURE__ */ React3.createElement(Toolbar2.DragHandle, {
417
+ ref: dragHandleRef,
418
+ testId: "mosaicBoard.columnDragHandle"
419
+ }), /* @__PURE__ */ React3.createElement(Toolbar2.Text, {
420
+ "data-testid": "mosaicBoard.columnTitle"
421
+ }, label), /* @__PURE__ */ React3.createElement(Menu2.Trigger, {
422
+ asChild: true,
423
+ disabled: !columnMenuItems?.length
424
+ }, /* @__PURE__ */ React3.createElement(Toolbar2.IconButton, {
425
+ iconOnly: true,
426
+ variant: "ghost",
427
+ icon: "ph--dots-three-vertical--regular",
428
+ label: t("action-menu.label")
429
+ })), /* @__PURE__ */ React3.createElement(Menu2.Content, {
430
+ items: columnMenuItems
431
+ })));
66
432
  });
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)
433
+ BoardColumnHeader.displayName = BOARD_COLUMN_HEADER_NAME;
434
+ var BOARD_COLUMN_BODY_NAME = "Board.Column.Body";
435
+ var BoardColumnBody = composable(({ data, eventHandler, Tile = BoardItem, debug, ...props }, forwardedRef) => {
436
+ const { model } = useBoard(BOARD_COLUMN_BODY_NAME);
437
+ const [viewport, setViewport] = useState(null);
438
+ const items = useAtomValue(model.items(data));
439
+ return /* @__PURE__ */ React3.createElement(Mosaic.Container, {
440
+ ...composableProps(props),
441
+ asChild: true,
442
+ withFocus: true,
443
+ orientation: "vertical",
444
+ autoScroll: viewport,
445
+ eventHandler,
446
+ debug,
447
+ ref: forwardedRef
448
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Root, {
449
+ orientation: "vertical",
450
+ thin: true,
451
+ centered: true,
452
+ padding: true
453
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Viewport, {
454
+ classNames: "snap-y md:snap-none",
455
+ ref: setViewport
456
+ }, /* @__PURE__ */ React3.createElement(Mosaic.Stack, {
457
+ items,
458
+ getId: model.getItemId,
459
+ Tile
460
+ }))));
461
+ });
462
+ BoardColumnBody.displayName = BOARD_COLUMN_BODY_NAME;
463
+ var BOARD_COLUMN_FOOTER_NAME = "Board.Column.Footer";
464
+ var BoardColumnFooter = /* @__PURE__ */ forwardRef3(({ classNames, data, onAdd }, forwardedRef) => {
465
+ const { t } = useTranslation2(translationKey);
466
+ const { model } = useBoard(BOARD_COLUMN_FOOTER_NAME);
467
+ const handleAdd = onAdd ?? (model.onItemCreate && data ? () => void model.onItemCreate?.(data) : void 0);
468
+ return /* @__PURE__ */ React3.createElement(Toolbar2.Root, {
469
+ classNames: mx2("rounded-b-sm border-t border-separator", classNames),
470
+ ref: forwardedRef
471
+ }, handleAdd && /* @__PURE__ */ React3.createElement(IconButton, {
472
+ "data-testid": "board-column-add-item",
473
+ classNames: "group-hover/column:opacity-100 md:opacity-0 transition transition-opacity duration-500",
474
+ variant: "ghost",
475
+ icon: "ph--plus--regular",
476
+ iconOnly: true,
477
+ label: t("add-item.label"),
478
+ onClick: handleAdd
479
+ }));
480
+ });
481
+ BoardColumnFooter.displayName = BOARD_COLUMN_FOOTER_NAME;
482
+ var BOARD_DEFAULT_COLUMN_NAME = "Board.DefaultColumn";
483
+ var DefaultBoardColumn = /* @__PURE__ */ forwardRef3(({ classNames, location, data, debug, Tile = BoardItem }, forwardedRef) => {
484
+ const { model } = useBoard(BOARD_DEFAULT_COLUMN_NAME);
485
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
486
+ const dragHandleRef = useRef3(null);
487
+ const [column, updateColumn] = useObject(data);
488
+ const eventHandler = useEventHandlerAdapter({
489
+ id: model.getColumnId(data),
490
+ items: column?.items ?? [],
491
+ getId: (ref) => ref.target?.id ?? ref.dxn.toString(),
492
+ get: (refOrObj) => Ref.isRef(refOrObj) ? refOrObj.target : refOrObj,
493
+ make: (object) => Ref.make(object),
494
+ canDrop: ({ source }) => {
495
+ const item = Ref.isRef(source.data) ? source.data.target : source.data;
496
+ return item != null && Obj2.isObject(item) && model.isItem(item);
497
+ },
498
+ onChange: (mutator) => updateColumn((col) => mutator(col.items))
499
+ });
500
+ return /* @__PURE__ */ React3.createElement(BoardColumnRootInner, {
501
+ 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),
502
+ location,
503
+ data,
504
+ dragHandleRef,
505
+ ref: forwardedRef
506
+ }, /* @__PURE__ */ React3.createElement(BoardColumnHeader, {
507
+ label: Obj2.getLabel(data) ?? data.id,
508
+ dragHandleRef
509
+ }), /* @__PURE__ */ React3.createElement(BoardColumnBody, {
510
+ data,
511
+ eventHandler,
512
+ debug: debugHandler,
513
+ Tile
514
+ }), /* @__PURE__ */ React3.createElement("div", {
515
+ role: "none",
516
+ className: "flex flex-col col-span-full"
517
+ }, /* @__PURE__ */ React3.createElement(BoardColumnFooter, {
518
+ data
519
+ }), /* @__PURE__ */ React3.createElement(DebugInfo, null)));
520
+ });
521
+ DefaultBoardColumn.displayName = BOARD_DEFAULT_COLUMN_NAME;
522
+ var BoardColumn = {
523
+ Root: BoardColumnRoot,
524
+ Header: BoardColumnHeader,
525
+ Body: BoardColumnBody,
526
+ Footer: BoardColumnFooter
527
+ };
528
+
529
+ // src/components/Board/Board.tsx
530
+ var BOARD_NAME = "Board";
531
+ var [BoardContextProvider, useBoardContext] = createContext2(BOARD_NAME);
532
+ function useBoard(displayName) {
533
+ return useBoardContext(displayName ?? BOARD_NAME);
534
+ }
535
+ var BOARD_ROOT_NAME = "Board.Root";
536
+ var BoardRootInner = ({ model, children }) => {
537
+ return /* @__PURE__ */ React4.createElement(BoardContextProvider, {
538
+ model
71
539
  }, children);
72
540
  };
73
- var Layout = {
74
- Main,
75
- Container,
76
- Flex
541
+ BoardRootInner.displayName = BOARD_ROOT_NAME;
542
+ var BoardRoot = BoardRootInner;
543
+ var BOARD_CONTENT_NAME = "Board.Content";
544
+ var BoardContentInner = composable2(({ id: _id, debug, eventHandler, Tile = DefaultBoardColumn, ...props }, forwardedRef) => {
545
+ const { model } = useBoardContext(BOARD_CONTENT_NAME);
546
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
547
+ const [viewport, setViewport] = useState2(null);
548
+ const items = useAtomValue2(model.columns);
549
+ return /* @__PURE__ */ React4.createElement("div", {
550
+ ...composableProps2(props, {
551
+ classNames: "dx-container"
552
+ }),
553
+ ref: forwardedRef
554
+ }, /* @__PURE__ */ React4.createElement(Focus.Group, {
555
+ asChild: true,
556
+ orientation: "horizontal"
557
+ }, /* @__PURE__ */ React4.createElement(Mosaic.Container, {
558
+ asChild: true,
559
+ withFocus: true,
560
+ orientation: "horizontal",
561
+ autoScroll: viewport,
562
+ eventHandler,
563
+ debug: debugHandler
564
+ }, /* @__PURE__ */ React4.createElement(ScrollArea2.Root, {
565
+ orientation: "horizontal",
566
+ centered: true,
567
+ padding: true
568
+ }, /* @__PURE__ */ React4.createElement(ScrollArea2.Viewport, {
569
+ classNames: "snap-mandatory snap-x md:snap-none",
570
+ ref: setViewport
571
+ }, /* @__PURE__ */ React4.createElement(Mosaic.Stack, {
572
+ items,
573
+ getId: model.getColumnId,
574
+ Tile,
575
+ debug
576
+ }))))), /* @__PURE__ */ React4.createElement(DebugInfo, null));
577
+ });
578
+ BoardContentInner.displayName = BOARD_CONTENT_NAME;
579
+ var BoardContent = BoardContentInner;
580
+ var BOARD_PLACEHOLDER_NAME = "Board.Placeholder";
581
+ var BoardPlaceholder = (props) => {
582
+ return /* @__PURE__ */ React4.createElement(Mosaic.Placeholder, {
583
+ ...props,
584
+ classNames: styles.placeholder.root
585
+ }, /* @__PURE__ */ React4.createElement("div", {
586
+ className: mx3("flex h-full border border-dashed border-separator rounded-xs", styles.placeholder.content)
587
+ }));
588
+ };
589
+ BoardPlaceholder.displayName = BOARD_PLACEHOLDER_NAME;
590
+ var BOARD_DEBUG_NAME = "Board.Debug";
591
+ var BoardDebug = /* @__PURE__ */ forwardRef4(({ classNames }, forwardedRef) => {
592
+ const { containers, dragging } = useMosaicRootContext(BOARD_DEBUG_NAME);
593
+ const counter = useRef4(0);
594
+ return /* @__PURE__ */ React4.createElement(Json2.Data, {
595
+ data: {
596
+ containers,
597
+ dragging,
598
+ count: counter.current++
599
+ },
600
+ classNames: mx3("text-xs", classNames),
601
+ ref: forwardedRef
602
+ });
603
+ });
604
+ BoardDebug.displayName = BOARD_DEBUG_NAME;
605
+ var Board = {
606
+ Root: BoardRoot,
607
+ Content: BoardContent,
608
+ Column: BoardColumn,
609
+ Item: BoardItem,
610
+ Placeholder: BoardPlaceholder,
611
+ Debug: BoardDebug
77
612
  };
78
613
  export {
79
- Card,
80
- CardDragPreview,
614
+ Board,
615
+ BoardDebug,
81
616
  Focus,
82
- Image,
83
- Layout,
84
617
  Mosaic,
85
- Stack,
86
- VirtualStack,
87
- styles as cardStyles,
88
618
  dropHandler,
89
- styles2 as focusStyles,
90
- styles3 as mosaicStyles,
619
+ getSourceData,
620
+ styles as mosaicStyles,
621
+ useBoard,
622
+ useBoardColumn,
91
623
  useContainerDebug,
624
+ useDefaultColumnEventHandler,
92
625
  useEventHandlerAdapter,
93
626
  useFocus,
94
- useRootContext as useMosaic,
95
- useContainerContext as useMosaicContainer,
96
- useTileContext as useMosaicTile,
627
+ useMosaicRootContext as useMosaic,
628
+ useMosaicContainerContext as useMosaicContainer,
629
+ useMosaicTileContext as useMosaicTile,
97
630
  useVisibleItems
98
631
  };
99
632
  //# sourceMappingURL=index.mjs.map