@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,100 +1,633 @@
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-5K56GSJL.mjs";
13
+
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 { composable as composable2, composableProps as composableProps2, mx as mx3 } from "@dxos/ui-theme";
21
21
 
22
- // src/components/Card/CardDragPreview.tsx
23
- import React from "react";
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.Data, {
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
+ ]);
129
+ };
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
+ };
34
212
  };
35
- var CardDragPreview = {
36
- Root: CardDragPreviewRoot,
37
- Content: CardDragPreviewContent
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
+ }
38
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";
42
- 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
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";
275
+ import { composable, composableProps, mx as mx2 } from "@dxos/ui-theme";
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(Menu.Root, null, /* @__PURE__ */ React2.createElement(Mosaic.Tile, {
323
+ ref: rootRef,
324
+ asChild: true,
325
+ dragHandle: dragHandleRef.current,
326
+ id: data.id,
327
+ data,
328
+ location,
329
+ debug
330
+ }, /* @__PURE__ */ React2.createElement(Focus.Item, {
331
+ asChild: true
332
+ }, /* @__PURE__ */ React2.createElement(Card.Root, {
333
+ classNames,
334
+ "data-testid": "board-item",
335
+ ref: composedRef,
336
+ onClick: (event) => event.currentTarget.focus()
337
+ }, /* @__PURE__ */ React2.createElement(Card.Toolbar, null, /* @__PURE__ */ React2.createElement(Card.DragHandle, {
338
+ ref: dragHandleRef,
339
+ testId: "mosaicBoard.cardDragHandle"
340
+ }), /* @__PURE__ */ React2.createElement(Card.Title, {
341
+ "data-testid": "mosaicBoard.cardTitle"
342
+ }, label), /* @__PURE__ */ React2.createElement(Menu.Trigger, {
343
+ asChild: true,
344
+ disabled: !items?.length
345
+ }, /* @__PURE__ */ React2.createElement(Toolbar.IconButton, {
346
+ iconOnly: true,
347
+ variant: "ghost",
348
+ icon: "ph--dots-three-vertical--regular",
349
+ label: t("action-menu.label")
350
+ })), /* @__PURE__ */ React2.createElement(Menu.Content, {
351
+ items
352
+ })), /* @__PURE__ */ React2.createElement(Card.Row, {
353
+ icon: "ph--note--regular",
354
+ classNames: "text-description"
355
+ }, /* @__PURE__ */ React2.createElement(Card.Text, null, description)), /* @__PURE__ */ React2.createElement(Card.Row, {
356
+ icon: "ph--tag--regular"
357
+ }, label && /* @__PURE__ */ React2.createElement("div", {
358
+ role: "none",
359
+ className: "shrink-0 flex gap-1 items-center text-xs"
360
+ }, /* @__PURE__ */ React2.createElement(Tag, {
361
+ palette: getHashStyles(label).hue
362
+ }, label)))))));
60
363
  });
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);
364
+ BoardItemInner.displayName = BOARD_ITEM_NAME;
365
+ var BoardItem = BoardItemInner;
366
+
367
+ // src/components/Board/Column.tsx
368
+ var BOARD_COLUMN_CONTEXT_NAME = "Board.Column";
369
+ var [BoardColumnProvider, useBoardColumnContext] = createContext(BOARD_COLUMN_CONTEXT_NAME, null);
370
+ function useBoardColumn() {
371
+ const value = useBoardColumnContext(BOARD_COLUMN_CONTEXT_NAME);
372
+ return value?.column;
373
+ }
374
+ var BOARD_COLUMN_ROOT_NAME = "Board.Column.Root";
375
+ var BoardColumnRootInner = composable(({ classNames, children, location, data, debug, dragHandleRef: dragHandleRefProp, ...rest }, forwardedRef) => {
376
+ const { model } = useBoard(BOARD_COLUMN_ROOT_NAME);
377
+ const internalRef = useRef3(null);
378
+ const dragHandleRef = dragHandleRefProp ?? internalRef;
379
+ return /* @__PURE__ */ React3.createElement(Mosaic.Tile, {
380
+ asChild: true,
381
+ location,
382
+ id: model.getColumnId(data),
383
+ data,
384
+ debug,
385
+ dragHandle: dragHandleRef.current
386
+ }, /* @__PURE__ */ React3.createElement(Focus.Group, {
387
+ ...rest,
388
+ "data-testid": "board-column",
389
+ border: true,
390
+ classNames: mx2("group/column", "h-full w-full md:w-card-default-width snap-center bg-deck-surface", "overflow-hidden", classNames),
391
+ ref: forwardedRef
392
+ }, /* @__PURE__ */ React3.createElement(BoardColumnProvider, {
393
+ column: data
394
+ }, children)));
395
+ });
396
+ BoardColumnRootInner.displayName = BOARD_COLUMN_ROOT_NAME;
397
+ var BoardColumnRoot = BoardColumnRootInner;
398
+ var BOARD_COLUMN_HEADER_NAME = "Board.Column.Header";
399
+ var BoardColumnHeader = composable(({ label, dragHandleRef, ...props }, forwardedRef) => {
400
+ const { t } = useTranslation2(translationKey);
401
+ const { model } = useBoard(BOARD_COLUMN_HEADER_NAME);
402
+ const column = useBoardColumn();
403
+ const columnMenuItems = useMemo4(() => column != null && model.onColumnDelete ? [
404
+ createMenuAction2("delete-column", () => model.onColumnDelete?.(column), {
405
+ label: t("delete-menu.label"),
406
+ icon: "ph--trash--regular"
407
+ })
408
+ ] : [], [
409
+ column,
410
+ model.onColumnDelete,
411
+ t
412
+ ]);
413
+ return /* @__PURE__ */ React3.createElement(Menu2.Root, null, /* @__PURE__ */ React3.createElement(Toolbar2.Root, {
414
+ ...composableProps(props),
415
+ "data-testid": "board-column-header",
416
+ ref: forwardedRef
417
+ }, /* @__PURE__ */ React3.createElement(Toolbar2.DragHandle, {
418
+ ref: dragHandleRef,
419
+ testId: "mosaicBoard.columnDragHandle"
420
+ }), /* @__PURE__ */ React3.createElement(Toolbar2.Text, {
421
+ "data-testid": "mosaicBoard.columnTitle"
422
+ }, label), /* @__PURE__ */ React3.createElement(Menu2.Trigger, {
423
+ asChild: true,
424
+ disabled: !columnMenuItems?.length
425
+ }, /* @__PURE__ */ React3.createElement(Toolbar2.IconButton, {
426
+ iconOnly: true,
427
+ variant: "ghost",
428
+ icon: "ph--dots-three-vertical--regular",
429
+ label: t("action-menu.label")
430
+ })), /* @__PURE__ */ React3.createElement(Menu2.Content, {
431
+ items: columnMenuItems
432
+ })));
67
433
  });
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)
434
+ BoardColumnHeader.displayName = BOARD_COLUMN_HEADER_NAME;
435
+ var BOARD_COLUMN_BODY_NAME = "Board.Column.Body";
436
+ var BoardColumnBody = composable(({ data, eventHandler, Tile = BoardItem, debug, ...props }, forwardedRef) => {
437
+ const { model } = useBoard(BOARD_COLUMN_BODY_NAME);
438
+ const [viewport, setViewport] = useState(null);
439
+ const items = useAtomValue(model.items(data));
440
+ return /* @__PURE__ */ React3.createElement(Mosaic.Container, {
441
+ ...composableProps(props),
442
+ asChild: true,
443
+ withFocus: true,
444
+ orientation: "vertical",
445
+ autoScroll: viewport,
446
+ eventHandler,
447
+ debug,
448
+ ref: forwardedRef
449
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Root, {
450
+ orientation: "vertical",
451
+ thin: true,
452
+ centered: true,
453
+ padding: true
454
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Viewport, {
455
+ classNames: "snap-y md:snap-none",
456
+ ref: setViewport
457
+ }, /* @__PURE__ */ React3.createElement(Mosaic.Stack, {
458
+ items,
459
+ getId: model.getItemId,
460
+ Tile
461
+ }))));
462
+ });
463
+ BoardColumnBody.displayName = BOARD_COLUMN_BODY_NAME;
464
+ var BOARD_COLUMN_FOOTER_NAME = "Board.Column.Footer";
465
+ var BoardColumnFooter = /* @__PURE__ */ forwardRef3(({ classNames, data, onAdd }, forwardedRef) => {
466
+ const { t } = useTranslation2(translationKey);
467
+ const { model } = useBoard(BOARD_COLUMN_FOOTER_NAME);
468
+ const handleAdd = onAdd ?? (model.onItemCreate && data ? () => void model.onItemCreate?.(data) : void 0);
469
+ return /* @__PURE__ */ React3.createElement(Toolbar2.Root, {
470
+ classNames: mx2("rounded-b-sm border-t border-separator", classNames),
471
+ ref: forwardedRef
472
+ }, handleAdd && /* @__PURE__ */ React3.createElement(IconButton, {
473
+ "data-testid": "board-column-add-item",
474
+ classNames: "group-hover/column:opacity-100 md:opacity-0 transition transition-opacity duration-500",
475
+ variant: "ghost",
476
+ icon: "ph--plus--regular",
477
+ iconOnly: true,
478
+ label: t("add-item.label"),
479
+ onClick: handleAdd
480
+ }));
481
+ });
482
+ BoardColumnFooter.displayName = BOARD_COLUMN_FOOTER_NAME;
483
+ var BOARD_DEFAULT_COLUMN_NAME = "Board.DefaultColumn";
484
+ var DefaultBoardColumn = /* @__PURE__ */ forwardRef3(({ classNames, location, data, debug, Tile = BoardItem }, forwardedRef) => {
485
+ const { model } = useBoard(BOARD_DEFAULT_COLUMN_NAME);
486
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
487
+ const dragHandleRef = useRef3(null);
488
+ const [column, updateColumn] = useObject(data);
489
+ const eventHandler = useEventHandlerAdapter({
490
+ id: model.getColumnId(data),
491
+ items: column?.items ?? [],
492
+ getId: (ref) => ref.target?.id ?? ref.dxn.toString(),
493
+ get: (refOrObj) => Ref.isRef(refOrObj) ? refOrObj.target : refOrObj,
494
+ make: (object) => Ref.make(object),
495
+ canDrop: ({ source }) => {
496
+ const item = Ref.isRef(source.data) ? source.data.target : source.data;
497
+ return item != null && Obj2.isObject(item) && model.isItem(item);
498
+ },
499
+ onChange: (mutator) => updateColumn((col) => mutator(col.items))
500
+ });
501
+ return /* @__PURE__ */ React3.createElement(BoardColumnRootInner, {
502
+ 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),
503
+ location,
504
+ data,
505
+ dragHandleRef,
506
+ ref: forwardedRef
507
+ }, /* @__PURE__ */ React3.createElement(BoardColumnHeader, {
508
+ label: Obj2.getLabel(data) ?? data.id,
509
+ dragHandleRef
510
+ }), /* @__PURE__ */ React3.createElement(BoardColumnBody, {
511
+ data,
512
+ eventHandler,
513
+ debug: debugHandler,
514
+ Tile
515
+ }), /* @__PURE__ */ React3.createElement("div", {
516
+ role: "none",
517
+ className: "flex flex-col col-span-full"
518
+ }, /* @__PURE__ */ React3.createElement(BoardColumnFooter, {
519
+ data
520
+ }), /* @__PURE__ */ React3.createElement(DebugInfo, null)));
521
+ });
522
+ DefaultBoardColumn.displayName = BOARD_DEFAULT_COLUMN_NAME;
523
+ var BoardColumn = {
524
+ Root: BoardColumnRoot,
525
+ Header: BoardColumnHeader,
526
+ Body: BoardColumnBody,
527
+ Footer: BoardColumnFooter
528
+ };
529
+
530
+ // src/components/Board/Board.tsx
531
+ var BOARD_NAME = "Board";
532
+ var [BoardContextProvider, useBoardContext] = createContext2(BOARD_NAME);
533
+ function useBoard(displayName) {
534
+ return useBoardContext(displayName ?? BOARD_NAME);
535
+ }
536
+ var BOARD_ROOT_NAME = "Board.Root";
537
+ var BoardRootInner = ({ model, children }) => {
538
+ return /* @__PURE__ */ React4.createElement(BoardContextProvider, {
539
+ model
72
540
  }, children);
73
541
  };
74
- var Layout = {
75
- Main,
76
- Container,
77
- Flex
542
+ BoardRootInner.displayName = BOARD_ROOT_NAME;
543
+ var BoardRoot = BoardRootInner;
544
+ var BOARD_CONTENT_NAME = "Board.Content";
545
+ var BoardContentInner = composable2(({ id: _id, debug, eventHandler, Tile = DefaultBoardColumn, ...props }, forwardedRef) => {
546
+ const { model } = useBoardContext(BOARD_CONTENT_NAME);
547
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
548
+ const [viewport, setViewport] = useState2(null);
549
+ const items = useAtomValue2(model.columns);
550
+ return /* @__PURE__ */ React4.createElement("div", {
551
+ ...composableProps2(props, {
552
+ classNames: "dx-container"
553
+ }),
554
+ ref: forwardedRef
555
+ }, /* @__PURE__ */ React4.createElement(Focus.Group, {
556
+ asChild: true,
557
+ orientation: "horizontal"
558
+ }, /* @__PURE__ */ React4.createElement(Mosaic.Container, {
559
+ asChild: true,
560
+ withFocus: true,
561
+ orientation: "horizontal",
562
+ autoScroll: viewport,
563
+ eventHandler,
564
+ debug: debugHandler
565
+ }, /* @__PURE__ */ React4.createElement(ScrollArea2.Root, {
566
+ orientation: "horizontal",
567
+ centered: true,
568
+ padding: true
569
+ }, /* @__PURE__ */ React4.createElement(ScrollArea2.Viewport, {
570
+ classNames: "snap-mandatory snap-x md:snap-none",
571
+ ref: setViewport
572
+ }, /* @__PURE__ */ React4.createElement(Mosaic.Stack, {
573
+ items,
574
+ getId: model.getColumnId,
575
+ Tile,
576
+ debug
577
+ }))))), /* @__PURE__ */ React4.createElement(DebugInfo, null));
578
+ });
579
+ BoardContentInner.displayName = BOARD_CONTENT_NAME;
580
+ var BoardContent = BoardContentInner;
581
+ var BOARD_PLACEHOLDER_NAME = "Board.Placeholder";
582
+ var BoardPlaceholder = (props) => {
583
+ return /* @__PURE__ */ React4.createElement(Mosaic.Placeholder, {
584
+ ...props,
585
+ classNames: styles.placeholder.root
586
+ }, /* @__PURE__ */ React4.createElement("div", {
587
+ className: mx3("flex h-full border border-dashed border-separator rounded-xs", styles.placeholder.content)
588
+ }));
589
+ };
590
+ BoardPlaceholder.displayName = BOARD_PLACEHOLDER_NAME;
591
+ var BOARD_DEBUG_NAME = "Board.Debug";
592
+ var BoardDebug = /* @__PURE__ */ forwardRef4(({ classNames }, forwardedRef) => {
593
+ const { containers, dragging } = useMosaicRootContext(BOARD_DEBUG_NAME);
594
+ const counter = useRef4(0);
595
+ return /* @__PURE__ */ React4.createElement(Json2.Data, {
596
+ data: {
597
+ containers,
598
+ dragging,
599
+ count: counter.current++
600
+ },
601
+ classNames: mx3("text-xs", classNames),
602
+ ref: forwardedRef
603
+ });
604
+ });
605
+ BoardDebug.displayName = BOARD_DEBUG_NAME;
606
+ var Board = {
607
+ Root: BoardRoot,
608
+ Content: BoardContent,
609
+ Column: BoardColumn,
610
+ Item: BoardItem,
611
+ Placeholder: BoardPlaceholder,
612
+ Debug: BoardDebug
78
613
  };
79
614
  export {
80
- Card,
81
- CardDragPreview,
615
+ Board,
616
+ BoardDebug,
82
617
  Focus,
83
- Image,
84
- Layout,
85
618
  Mosaic,
86
- Stack,
87
- VirtualStack,
88
- styles as cardStyles,
89
619
  dropHandler,
90
- styles2 as focusStyles,
91
- styles3 as mosaicStyles,
620
+ getSourceData,
621
+ styles as mosaicStyles,
622
+ useBoard,
623
+ useBoardColumn,
92
624
  useContainerDebug,
625
+ useDefaultColumnEventHandler,
93
626
  useEventHandlerAdapter,
94
627
  useFocus,
95
- useRootContext as useMosaic,
96
- useContainerContext as useMosaicContainer,
97
- useTileContext as useMosaicTile,
628
+ useMosaicRootContext as useMosaic,
629
+ useMosaicContainerContext as useMosaicContainer,
630
+ useMosaicTileContext as useMosaicTile,
98
631
  useVisibleItems
99
632
  };
100
633
  //# sourceMappingURL=index.mjs.map