@dxos/react-ui-stack 0.8.4-main.e8ec1fe → 0.8.4-main.ef1bc66f44

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 (104) hide show
  1. package/dist/lib/browser/index.mjs +920 -57
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +921 -57
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/{exemplars → components}/CardStack/CardStack.d.ts +18 -13
  8. package/dist/types/src/components/CardStack/CardStack.d.ts.map +1 -0
  9. package/dist/types/src/components/CardStack/CardStack.stories.d.ts.map +1 -0
  10. package/dist/types/src/{exemplars → components}/CardStack/CardStackDragPreview.d.ts +4 -1
  11. package/dist/types/src/components/CardStack/CardStackDragPreview.d.ts.map +1 -0
  12. package/dist/types/src/components/CardStack/index.d.ts.map +1 -0
  13. package/dist/types/src/components/Stack/Stack.d.ts +1 -1
  14. package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
  15. package/dist/types/src/components/StackContext.d.ts +1 -1
  16. package/dist/types/src/components/StackContext.d.ts.map +1 -1
  17. package/dist/types/src/components/StackItem/StackItem.d.ts +5 -9
  18. package/dist/types/src/components/StackItem/StackItem.d.ts.map +1 -1
  19. package/dist/types/src/components/StackItem/StackItem.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/StackItem/StackItemContent.d.ts +2 -45
  21. package/dist/types/src/components/StackItem/StackItemContent.d.ts.map +1 -1
  22. package/dist/types/src/components/StackItem/StackItemSigil.d.ts +2 -2
  23. package/dist/types/src/components/StackItem/StackItemSigil.d.ts.map +1 -1
  24. package/dist/types/src/components/deprecated/LayoutControls.d.ts +3 -0
  25. package/dist/types/src/components/deprecated/LayoutControls.d.ts.map +1 -1
  26. package/dist/types/src/components/index.d.ts +2 -2
  27. package/dist/types/src/components/index.d.ts.map +1 -1
  28. package/dist/types/src/components/{defs.d.ts → types.d.ts} +1 -1
  29. package/dist/types/src/components/types.d.ts.map +1 -0
  30. package/dist/types/src/hooks/useStackDropForElements.d.ts +7 -5
  31. package/dist/types/src/hooks/useStackDropForElements.d.ts.map +1 -1
  32. package/dist/types/src/index.d.ts +0 -1
  33. package/dist/types/src/index.d.ts.map +1 -1
  34. package/dist/types/src/translations.d.ts +2 -2
  35. package/dist/types/src/translations.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +40 -37
  38. package/src/{exemplars → components}/CardStack/CardStack.stories.tsx +10 -10
  39. package/src/{exemplars → components}/CardStack/CardStack.tsx +113 -57
  40. package/src/{exemplars → components}/CardStack/CardStackDragPreview.tsx +12 -9
  41. package/src/components/Stack/Stack.stories.tsx +2 -2
  42. package/src/components/Stack/Stack.tsx +5 -3
  43. package/src/components/StackContext.tsx +1 -1
  44. package/src/components/StackItem/StackItem.stories.tsx +5 -3
  45. package/src/components/StackItem/StackItem.tsx +24 -12
  46. package/src/components/StackItem/StackItemContent.tsx +19 -50
  47. package/src/components/StackItem/StackItemHeading.tsx +1 -1
  48. package/src/components/StackItem/StackItemSigil.tsx +3 -3
  49. package/src/components/deprecated/LayoutControls.tsx +3 -0
  50. package/src/components/index.ts +2 -2
  51. package/src/hooks/useStackDropForElements.ts +17 -10
  52. package/src/index.ts +0 -3
  53. package/src/playwright/playwright.config.ts +1 -1
  54. package/src/translations.ts +1 -1
  55. package/dist/lib/browser/chunk-3F2KBXLP.mjs +0 -1482
  56. package/dist/lib/browser/chunk-3F2KBXLP.mjs.map +0 -7
  57. package/dist/lib/browser/testing/index.mjs +0 -31
  58. package/dist/lib/browser/testing/index.mjs.map +0 -7
  59. package/dist/lib/node-esm/chunk-SYKFLQGK.mjs +0 -1484
  60. package/dist/lib/node-esm/chunk-SYKFLQGK.mjs.map +0 -7
  61. package/dist/lib/node-esm/testing/index.mjs +0 -32
  62. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  63. package/dist/types/src/components/Image/Image.d.ts +0 -14
  64. package/dist/types/src/components/Image/Image.d.ts.map +0 -1
  65. package/dist/types/src/components/Image/Image.stories.d.ts +0 -33
  66. package/dist/types/src/components/Image/Image.stories.d.ts.map +0 -1
  67. package/dist/types/src/components/Image/index.d.ts +0 -2
  68. package/dist/types/src/components/Image/index.d.ts.map +0 -1
  69. package/dist/types/src/components/defs.d.ts.map +0 -1
  70. package/dist/types/src/exemplars/Card/Card.d.ts +0 -69
  71. package/dist/types/src/exemplars/Card/Card.d.ts.map +0 -1
  72. package/dist/types/src/exemplars/Card/Card.stories.d.ts +0 -21
  73. package/dist/types/src/exemplars/Card/Card.stories.d.ts.map +0 -1
  74. package/dist/types/src/exemplars/Card/CardDragPreview.d.ts +0 -6
  75. package/dist/types/src/exemplars/Card/CardDragPreview.d.ts.map +0 -1
  76. package/dist/types/src/exemplars/Card/fragments.d.ts +0 -13
  77. package/dist/types/src/exemplars/Card/fragments.d.ts.map +0 -1
  78. package/dist/types/src/exemplars/Card/index.d.ts +0 -4
  79. package/dist/types/src/exemplars/Card/index.d.ts.map +0 -1
  80. package/dist/types/src/exemplars/CardStack/CardStack.d.ts.map +0 -1
  81. package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts.map +0 -1
  82. package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts.map +0 -1
  83. package/dist/types/src/exemplars/CardStack/index.d.ts.map +0 -1
  84. package/dist/types/src/exemplars/index.d.ts +0 -3
  85. package/dist/types/src/exemplars/index.d.ts.map +0 -1
  86. package/dist/types/src/testing/CardContainer.d.ts +0 -6
  87. package/dist/types/src/testing/CardContainer.d.ts.map +0 -1
  88. package/dist/types/src/testing/index.d.ts +0 -2
  89. package/dist/types/src/testing/index.d.ts.map +0 -1
  90. package/src/components/Image/Image.stories.tsx +0 -84
  91. package/src/components/Image/Image.tsx +0 -222
  92. package/src/components/Image/index.ts +0 -5
  93. package/src/exemplars/Card/Card.stories.tsx +0 -64
  94. package/src/exemplars/Card/Card.tsx +0 -210
  95. package/src/exemplars/Card/CardDragPreview.tsx +0 -22
  96. package/src/exemplars/Card/fragments.ts +0 -24
  97. package/src/exemplars/Card/index.ts +0 -7
  98. package/src/exemplars/index.ts +0 -6
  99. package/src/testing/CardContainer.tsx +0 -37
  100. package/src/testing/index.ts +0 -5
  101. /package/dist/types/src/{exemplars → components}/CardStack/CardStack.stories.d.ts +0 -0
  102. /package/dist/types/src/{exemplars → components}/CardStack/index.d.ts +0 -0
  103. /package/src/{exemplars → components}/CardStack/index.ts +0 -0
  104. /package/src/components/{defs.ts → types.ts} +0 -0
@@ -1,1482 +0,0 @@
1
- // src/components/Image/Image.tsx
2
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
3
- import React, { useCallback, useRef, useState } from "react";
4
- import { mx } from "@dxos/react-ui-theme";
5
- var cache = /* @__PURE__ */ new Map();
6
- var Image = ({ classNames, src, alt = "", crossOrigin = "anonymous", sampleSize = 64, contrast = 0.9 }) => {
7
- var _effect = _useSignals();
8
- try {
9
- const [crossOriginState, setCrossOriginState] = useState(crossOrigin);
10
- const [dominantColor, setDominantColor] = useState(void 0);
11
- const [imageLoaded, setImageLoaded] = useState(false);
12
- const canvasRef = useRef(null);
13
- const handleImageError = () => {
14
- setCrossOriginState(void 0);
15
- };
16
- const handleImageLoad = useCallback(({ target }) => {
17
- const rgb = cache.get(src);
18
- if (rgb) {
19
- setDominantColor(rgb);
20
- setImageLoaded(true);
21
- return;
22
- }
23
- const img = target;
24
- if (!canvasRef.current) {
25
- return;
26
- }
27
- try {
28
- const color = extractDominantColor(canvasRef.current, img, {
29
- sampleSize,
30
- contrast
31
- });
32
- if (color) {
33
- const rgb2 = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
34
- cache.set(src, rgb2);
35
- setDominantColor(rgb2);
36
- }
37
- } catch {
38
- setCrossOriginState(void 0);
39
- }
40
- setImageLoaded(true);
41
- }, [
42
- sampleSize,
43
- contrast,
44
- src
45
- ]);
46
- return /* @__PURE__ */ React.createElement("div", {
47
- className: mx(`relative flex is-full justify-center overflow-hidden transition-all duration-700`, classNames),
48
- style: {
49
- backgroundColor: dominantColor
50
- }
51
- }, /* @__PURE__ */ React.createElement("canvas", {
52
- ref: canvasRef,
53
- style: {
54
- display: "none"
55
- },
56
- "aria-hidden": "true"
57
- }), /* @__PURE__ */ React.createElement("div", {
58
- className: "absolute inset-0 pointer-events-none",
59
- style: {
60
- background: dominantColor ? `radial-gradient(circle at center, transparent 30%, ${dominantColor} 100%)` : void 0,
61
- transition: "opacity 0.7s ease-in-out",
62
- opacity: 0.5
63
- }
64
- }), /* @__PURE__ */ React.createElement("img", {
65
- src,
66
- alt,
67
- crossOrigin: crossOriginState,
68
- onError: handleImageError,
69
- onLoad: handleImageLoad,
70
- className: mx("z-10 object-contain transition-opacity duration-500", classNames),
71
- style: {
72
- opacity: imageLoaded ? 1 : 0
73
- }
74
- }));
75
- } finally {
76
- _effect.f();
77
- }
78
- };
79
- var extractDominantColor = (canvas, img, { sampleSize = 64, contrast = 0.95 }) => {
80
- const ctx = canvas.getContext("2d");
81
- if (!ctx) {
82
- return null;
83
- }
84
- canvas.width = sampleSize;
85
- canvas.height = sampleSize;
86
- ctx.drawImage(img, 0, 0, sampleSize, sampleSize);
87
- const imageData = ctx.getImageData(0, 0, sampleSize, sampleSize);
88
- const pixels = imageData.data;
89
- if (isTransparent(pixels, sampleSize)) {
90
- return null;
91
- }
92
- let r = 0;
93
- let g = 0;
94
- let b = 0;
95
- let totalWeight = 0;
96
- const cornerSize = Math.floor(sampleSize * 0.125);
97
- for (let y = 0; y < sampleSize; y++) {
98
- for (let x = 0; x < sampleSize; x++) {
99
- const isInTopLeft = x < cornerSize && y < cornerSize;
100
- const isInTopRight = x >= sampleSize - cornerSize && y < cornerSize;
101
- const isInBottomLeft = x < cornerSize && y >= sampleSize - cornerSize;
102
- const isInBottomRight = x >= sampleSize - cornerSize && y >= sampleSize - cornerSize;
103
- if (!isInTopLeft && !isInTopRight && !isInBottomLeft && !isInBottomRight) {
104
- continue;
105
- }
106
- const i = (y * sampleSize + x) * 4;
107
- const red = pixels[i];
108
- const green = pixels[i + 1];
109
- const blue = pixels[i + 2];
110
- const alpha = pixels[i + 3];
111
- if (alpha === 0) continue;
112
- const max = Math.max(red, green, blue);
113
- const min = Math.min(red, green, blue);
114
- const saturation = max === 0 ? 0 : (max - min) / max;
115
- const weight = 1 + saturation * 2;
116
- r += red * weight;
117
- g += green * weight;
118
- b += blue * weight;
119
- totalWeight += weight;
120
- }
121
- }
122
- if (totalWeight > 0) {
123
- r = Math.round(Math.round(r / totalWeight) * contrast);
124
- g = Math.round(Math.round(g / totalWeight) * contrast);
125
- b = Math.round(Math.round(b / totalWeight) * contrast);
126
- return [
127
- r,
128
- g,
129
- b
130
- ];
131
- }
132
- return null;
133
- };
134
- var isTransparent = (pixels, sampleSize, threshold = 0.5) => {
135
- let edgeTransparentPixels = 0;
136
- const edgePixels = sampleSize * 4 - 4;
137
- for (let x = 0; x < sampleSize; x++) {
138
- const topIndex = x * 4;
139
- if (pixels[topIndex + 3] === 0) edgeTransparentPixels++;
140
- const bottomIndex = ((sampleSize - 1) * sampleSize + x) * 4;
141
- if (pixels[bottomIndex + 3] === 0) edgeTransparentPixels++;
142
- }
143
- for (let y = 1; y < sampleSize - 1; y++) {
144
- const leftIndex = y * sampleSize * 4;
145
- if (pixels[leftIndex + 3] === 0) edgeTransparentPixels++;
146
- const rightIndex = (y * sampleSize + sampleSize - 1) * 4;
147
- if (pixels[rightIndex + 3] === 0) edgeTransparentPixels++;
148
- }
149
- return edgeTransparentPixels / edgePixels > threshold;
150
- };
151
-
152
- // src/components/StackContext.tsx
153
- import { createContext, useContext } from "react";
154
- var StackContext = /* @__PURE__ */ createContext({
155
- orientation: "vertical",
156
- rail: true,
157
- size: "intrinsic"
158
- });
159
- var useStack = () => useContext(StackContext);
160
- var idle = {
161
- type: "idle"
162
- };
163
- var StackItemContext = /* @__PURE__ */ createContext({
164
- selfDragHandleRef: () => {
165
- },
166
- size: "min-content",
167
- setSize: () => {
168
- },
169
- state: idle,
170
- setState: () => {
171
- }
172
- });
173
- var useStackItem = () => useContext(StackItemContext);
174
-
175
- // src/components/Stack/Stack.tsx
176
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
177
- import { composeRefs } from "@radix-ui/react-compose-refs";
178
- import React2, { Children, forwardRef, useCallback as useCallback2, useEffect, useMemo, useState as useState3 } from "react";
179
- import { ListItem, useId } from "@dxos/react-ui";
180
- import { mx as mx2 } from "@dxos/react-ui-theme";
181
-
182
- // src/hooks/useStackDropForElements.ts
183
- import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
184
- import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
185
- import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
186
- import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
187
- import { useLayoutEffect, useState as useState2 } from "react";
188
- var noop = () => {
189
- };
190
- var useStackDropForElements = ({ id, element, scrollElement = element, orientation, selfDroppable, onRearrange }) => {
191
- const [dropping, setDropping] = useState2(false);
192
- useLayoutEffect(() => {
193
- if (!element) {
194
- return;
195
- }
196
- const acceptSourceType = orientation === "horizontal" ? "column" : "card";
197
- return combine(selfDroppable ? dropTargetForElements({
198
- element,
199
- getData: ({ input, element: element2 }) => {
200
- return attachClosestEdge({
201
- id,
202
- type: orientation === "horizontal" ? "card" : "column"
203
- }, {
204
- input,
205
- element: element2,
206
- allowedEdges: [
207
- orientation === "horizontal" ? "left" : "top"
208
- ]
209
- });
210
- },
211
- onDragEnter: ({ source }) => {
212
- if (source.data.type === acceptSourceType) {
213
- setDropping(true);
214
- }
215
- },
216
- onDrag: ({ source }) => {
217
- if (source.data.type === acceptSourceType) {
218
- setDropping(true);
219
- }
220
- },
221
- onDragLeave: () => {
222
- return setDropping(false);
223
- },
224
- onDrop: ({ self, source }) => {
225
- setDropping(false);
226
- if (source.data.type === acceptSourceType && selfDroppable && onRearrange) {
227
- onRearrange(source.data, self.data, extractClosestEdge(self.data));
228
- }
229
- }
230
- }) : noop, scrollElement ? autoScrollForElements({
231
- element: scrollElement,
232
- getAllowedAxis: () => orientation
233
- }) : noop);
234
- }, [
235
- element,
236
- scrollElement,
237
- selfDroppable,
238
- orientation,
239
- id,
240
- onRearrange
241
- ]);
242
- return {
243
- dropping
244
- };
245
- };
246
-
247
- // src/components/Stack/Stack.tsx
248
- var railGridHorizontal = "grid-rows-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]";
249
- var railGridVertical = "grid-cols-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]";
250
- var railGridHorizontalContainFitContent = "grid-rows-[[rail-start]_var(--rail-size)_[content-start]_fit-content(calc(100%-var(--rail-size)*2+2px))_[content-end]]";
251
- var railGridVerticalContainFitContent = "grid-cols-[[rail-start]_var(--rail-size)_[content-start]_fit-content(calc(100%-var(--rail-size)*2+2px))_[content-end]]";
252
- var autoScrollRootAttributes = {
253
- "data-drag-autoscroll": "idle"
254
- };
255
- var PERPENDICULAR_FOCUS_THRESHHOLD = 128;
256
- var scrollIntoViewAndFocus = (el, orientation) => {
257
- el.scrollIntoView({
258
- behavior: "instant",
259
- [orientation === "vertical" ? "block" : "inline"]: "center"
260
- });
261
- return el.focus();
262
- };
263
- var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientation = "vertical", rail = true, size = "intrinsic", onRearrange, itemsCount = Children.count(children), getDropElement, separatorOnScroll, circularFocus, ...props }, forwardedRef) => {
264
- var _effect = _useSignals2();
265
- try {
266
- const stackId = useId("stack", props.id);
267
- const [stackElement, stackRef] = useState3(null);
268
- const [lastFocusedItem, setLastFocusedItem] = useState3();
269
- const composedItemRef = composeRefs(stackRef, forwardedRef);
270
- const styles = {
271
- [orientation === "horizontal" ? "gridTemplateColumns" : "gridTemplateRows"]: size === "split" ? `repeat(${itemsCount}, 1fr)` : `repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
272
- ...style
273
- };
274
- const selfDroppable = !!(itemsCount < 1 && onRearrange && props.id);
275
- const { dropping } = useStackDropForElements({
276
- id: props.id,
277
- element: getDropElement && stackElement ? getDropElement(stackElement) : stackElement,
278
- scrollElement: stackElement,
279
- selfDroppable,
280
- orientation,
281
- onRearrange
282
- });
283
- const handleScroll = useCallback2(() => {
284
- if (stackElement && Number.isFinite(separatorOnScroll)) {
285
- const scrollPosition = orientation === "horizontal" ? stackElement.scrollLeft : stackElement.scrollTop;
286
- const scrollSize = orientation === "horizontal" ? stackElement.scrollWidth : stackElement.scrollHeight;
287
- const clientSize = orientation === "horizontal" ? stackElement.clientWidth : stackElement.clientHeight;
288
- const separatorHost = stackElement.closest("[data-scroll-separator]");
289
- if (separatorHost) {
290
- separatorHost.setAttribute("data-scroll-separator", String(scrollPosition > separatorOnScroll));
291
- separatorHost.setAttribute("data-scroll-separator-end", String(scrollSize - (scrollPosition + clientSize) > separatorOnScroll));
292
- }
293
- }
294
- }, [
295
- stackElement,
296
- separatorOnScroll,
297
- orientation
298
- ]);
299
- const handleBlur = useCallback2((event) => {
300
- if (event.target) {
301
- const target = event.target;
302
- const closestStackItem = target.closest(`[data-dx-item-id]`);
303
- if (closestStackItem?.closest(`[data-dx-stack="${stackId}"]`)) {
304
- setLastFocusedItem(closestStackItem?.getAttribute("data-dx-item-id") ?? void 0);
305
- }
306
- }
307
- props.onBlur?.(event);
308
- }, [
309
- stackId,
310
- props.onBlur
311
- ]);
312
- const handleKeyDown = useCallback2((event) => {
313
- const target = event.target;
314
- if (event.key.startsWith("Arrow") && !target.closest(`input, textarea, [role="textbox"], [data-tabster*="mover"], [data-arrow-keys="all"], [data-arrow-keys~="${event.key.toLowerCase().slice(5)}"]`)) {
315
- const closestOwnedItem = target.closest(`[data-dx-stack-item="${stackId}"]`);
316
- const closestStack = target.closest("[data-dx-stack]");
317
- const closestStackItems = Array.from(closestStack?.querySelectorAll(`[data-dx-stack-item="${stackId}"]`) ?? []);
318
- const closestStackOrientation = closestStack?.getAttribute("aria-orientation");
319
- const ancestorStack = closestStack?.parentElement?.closest("[data-dx-stack]");
320
- if (closestOwnedItem && closestStack) {
321
- const ancestorOrientation = ancestorStack?.getAttribute("aria-orientation");
322
- const parallelDelta = (closestStackOrientation === "vertical" ? event.key === "ArrowUp" : event.key === "ArrowLeft") ? -1 : (closestStackOrientation === "vertical" ? event.key === "ArrowDown" : event.key === "ArrowRight") ? 1 : 0;
323
- const perpendicularDelta = (closestStackOrientation === "vertical" ? event.key === "ArrowLeft" : event.key === "ArrowUp") ? -1 : (closestStackOrientation === "vertical" ? event.key === "ArrowRight" : event.key === "ArrowDown") ? 1 : 0;
324
- if (parallelDelta !== 0) {
325
- const currentIndex = closestStackItems.indexOf(closestOwnedItem);
326
- const nextIndex = currentIndex + parallelDelta;
327
- let adjacentItem;
328
- if (circularFocus) {
329
- adjacentItem = closestStackItems[(nextIndex + closestStackItems.length) % closestStackItems.length];
330
- } else {
331
- if (nextIndex >= 0 && nextIndex < closestStackItems.length) {
332
- adjacentItem = closestStackItems[nextIndex];
333
- }
334
- }
335
- if (adjacentItem) {
336
- event.preventDefault();
337
- scrollIntoViewAndFocus(adjacentItem, closestStackOrientation);
338
- }
339
- }
340
- if (perpendicularDelta !== 0) {
341
- if (ancestorStack && ancestorOrientation !== closestStackOrientation) {
342
- const siblingStacks = Array.from(ancestorStack.querySelectorAll(`[data-dx-stack-item="${ancestorStack.getAttribute("data-dx-stack")}"] [data-dx-stack]`));
343
- const currentStackIndex = siblingStacks.indexOf(closestStack);
344
- const nextStackIndex = currentStackIndex + perpendicularDelta;
345
- let adjacentStack;
346
- if (ancestorStack.getAttribute("data-dx-stack-circular-focus") === "true") {
347
- adjacentStack = siblingStacks[(nextStackIndex + siblingStacks.length) % siblingStacks.length];
348
- } else {
349
- if (nextStackIndex >= 0 && nextStackIndex < siblingStacks.length) {
350
- adjacentStack = siblingStacks[nextStackIndex];
351
- }
352
- }
353
- const adjacentStackSelfItem = adjacentStack?.closest(`[data-dx-stack-item=${ancestorStack.getAttribute("data-dx-stack")}]`);
354
- const adjacentStackItems = adjacentStack ? Array.from(adjacentStack.querySelectorAll(`[data-dx-stack-item="${adjacentStack.getAttribute("data-dx-stack")}"]`)) : [];
355
- if (adjacentStack && adjacentStackItems.length > 0) {
356
- let closestItem = adjacentStackItems[0];
357
- const lastFocusedItem2 = adjacentStack.querySelector(`[data-dx-item-id="${adjacentStack.getAttribute("data-dx-last-focused-item") ?? "never"}"]`);
358
- if (lastFocusedItem2) {
359
- closestItem = lastFocusedItem2;
360
- } else {
361
- const ownedItemRect = closestOwnedItem.getBoundingClientRect();
362
- const targetPosition = closestStackOrientation === "vertical" ? ownedItemRect.top : ownedItemRect.left;
363
- let closestDistance = Infinity;
364
- for (const item of adjacentStackItems) {
365
- const itemRect = item.getBoundingClientRect();
366
- const itemPosition = closestStackOrientation === "vertical" ? itemRect.top : itemRect.left;
367
- const distance = Math.abs(itemPosition - targetPosition);
368
- if (distance < closestDistance) {
369
- closestDistance = distance;
370
- closestItem = item;
371
- }
372
- if (closestDistance <= PERPENDICULAR_FOCUS_THRESHHOLD) {
373
- break;
374
- }
375
- }
376
- }
377
- event.preventDefault();
378
- scrollIntoViewAndFocus(closestItem, closestStackOrientation);
379
- } else if (adjacentStackSelfItem) {
380
- event.preventDefault();
381
- scrollIntoViewAndFocus(adjacentStackSelfItem, ancestorOrientation);
382
- }
383
- } else if (closestOwnedItem) {
384
- const closestOwnedItemStack = closestOwnedItem.querySelector("[data-dx-stack]");
385
- const closestOwnedItemStackItems = closestOwnedItemStack ? Array.from(closestOwnedItemStack.querySelectorAll(`[data-dx-stack-item="${closestOwnedItemStack.getAttribute("data-dx-stack")}"]`)) : [];
386
- if (closestOwnedItemStackItems.length > 0) {
387
- event.preventDefault();
388
- scrollIntoViewAndFocus(closestOwnedItemStackItems[[
389
- "ArrowUp",
390
- "ArrowLeft"
391
- ].includes(event.key) ? closestOwnedItemStackItems.length - 1 : 0], closestOwnedItemStack?.getAttribute("aria-orientation"));
392
- }
393
- }
394
- }
395
- }
396
- }
397
- props.onKeyDown?.(event);
398
- }, [
399
- props.onKeyDown,
400
- stackId,
401
- circularFocus
402
- ]);
403
- const gridClasses = useMemo(() => {
404
- if (!rail) {
405
- return orientation === "horizontal" ? "grid-rows-1 pli-[--stack-gap]" : "grid-cols-1 plb-[--stack-gap]";
406
- }
407
- if (orientation === "horizontal") {
408
- return railGridHorizontal;
409
- } else {
410
- return railGridVertical;
411
- }
412
- }, [
413
- rail,
414
- orientation,
415
- size
416
- ]);
417
- useEffect(() => {
418
- if (!(stackElement && Number.isFinite(separatorOnScroll))) {
419
- return;
420
- }
421
- const observer = new MutationObserver(() => {
422
- handleScroll();
423
- });
424
- observer.observe(stackElement, {
425
- childList: true,
426
- subtree: true
427
- });
428
- return () => {
429
- observer.disconnect();
430
- };
431
- }, [
432
- stackElement,
433
- handleScroll
434
- ]);
435
- return /* @__PURE__ */ React2.createElement(StackContext.Provider, {
436
- value: {
437
- orientation,
438
- rail,
439
- size,
440
- onRearrange,
441
- stackId
442
- }
443
- }, /* @__PURE__ */ React2.createElement("div", {
444
- ...props,
445
- className: mx2("grid relative [--stack-gap:var(--dx-trimXs)]", gridClasses, size === "contain" && (orientation === "horizontal" ? "overflow-x-auto overscroll-x-contain min-bs-0 max-bs-full bs-full" : "overflow-y-auto min-is-0 max-is-full is-full"), classNames),
446
- onKeyDown: handleKeyDown,
447
- onBlur: handleBlur,
448
- "data-dx-stack": stackId,
449
- "data-dx-stack-circular-focus": circularFocus,
450
- "data-dx-last-focused-item": lastFocusedItem,
451
- "data-rail": rail,
452
- "aria-orientation": orientation,
453
- style: styles,
454
- ref: composedItemRef,
455
- ...Number.isFinite(separatorOnScroll) && {
456
- onScroll: handleScroll
457
- }
458
- }, children, selfDroppable && dropping && /* @__PURE__ */ React2.createElement(ListItem.DropIndicator, {
459
- lineInset: 8,
460
- terminalInset: -8,
461
- gap: -8,
462
- edge: orientation === "horizontal" ? "left" : "top"
463
- })));
464
- } finally {
465
- _effect.f();
466
- }
467
- });
468
-
469
- // src/translations.ts
470
- var translationKey = "react-ui-stack";
471
- var translations = [
472
- {
473
- "en-US": {
474
- [translationKey]: {
475
- "resize label": "Drag to resize",
476
- "drag handle label": "Drag to rearrange",
477
- "pin start label": "Pin to the left sidebar",
478
- "pin end label": "Pin to the right sidebar",
479
- "increment start label": "Move to the left",
480
- "increment end label": "Move to the right",
481
- "close label": "Close",
482
- "minify label": "Minify"
483
- }
484
- }
485
- }
486
- ];
487
-
488
- // src/components/StackItem/StackItem.tsx
489
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
490
- import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
491
- import { draggable, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
492
- import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
493
- import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
494
- import { attachClosestEdge as attachClosestEdge2, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
495
- import { useFocusableGroup } from "@fluentui/react-tabster";
496
- import { composeRefs as composeRefs2 } from "@radix-ui/react-compose-refs";
497
- import React9, { forwardRef as forwardRef5, useCallback as useCallback3, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useState as useState5 } from "react";
498
- import { createPortal } from "react-dom";
499
- import { ListItem as ListItem2 } from "@dxos/react-ui";
500
- import { resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
501
- import { mx as mx6 } from "@dxos/react-ui-theme";
502
-
503
- // src/components/StackItem/StackItemContent.tsx
504
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
505
- import React3, { forwardRef as forwardRef2, useMemo as useMemo2 } from "react";
506
- import { mx as mx3 } from "@dxos/react-ui-theme";
507
- var StackItemContent = /* @__PURE__ */ forwardRef2(({ children, toolbar, statusbar, layoutManaged, classNames, size = "intrinsic", scrollable, ...props }, forwardedRef) => {
508
- var _effect = _useSignals3();
509
- try {
510
- const { size: stackItemSize } = useStack();
511
- const { role } = useStackItem();
512
- const style = useMemo2(() => layoutManaged ? {} : {
513
- gridTemplateRows: [
514
- ...toolbar ? [
515
- role === "section" ? "calc(var(--toolbar-size) - 1px)" : "var(--toolbar-size)"
516
- ] : [],
517
- "1fr",
518
- ...statusbar ? [
519
- "var(--statusbar-size)"
520
- ] : []
521
- ].join(" ")
522
- }, [
523
- toolbar,
524
- statusbar,
525
- layoutManaged
526
- ]);
527
- return /* @__PURE__ */ React3.createElement("div", {
528
- role: "none",
529
- ...props,
530
- className: mx3("group grid grid-cols-[100%] density-coarse", size === "video" ? "aspect-video" : size === "square" && "aspect-square", stackItemSize === "contain" && "min-bs-0 overflow-hidden", scrollable ? "min-bs-0 overflow-y-auto scrollbar-thin contain-layout" : "overflow-hidden", role === "section" && toolbar && "[&_.dx-toolbar]:sticky [&_.dx-toolbar]:z-[1] [&_.dx-toolbar]:block-start-0 [&_.dx-toolbar]:-mbe-px [&_.dx-toolbar]:min-is-0", toolbar && "[&>.dx-toolbar]:relative [&>.dx-toolbar]:border-be [&>.dx-toolbar]:border-subduedSeparator", classNames),
531
- style,
532
- "data-popover-collision-boundary": true,
533
- ref: forwardedRef
534
- }, children);
535
- } finally {
536
- _effect.f();
537
- }
538
- });
539
-
540
- // src/components/StackItem/StackItemDragHandle.tsx
541
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
542
- import { Slot } from "@radix-ui/react-slot";
543
- import React4 from "react";
544
- var StackItemDragHandle = ({ asChild, children }) => {
545
- var _effect = _useSignals4();
546
- try {
547
- const { selfDragHandleRef } = useStackItem();
548
- const Root = asChild ? Slot : "div";
549
- return /* @__PURE__ */ React4.createElement(Root, {
550
- ref: selfDragHandleRef,
551
- role: "button"
552
- }, children);
553
- } finally {
554
- _effect.f();
555
- }
556
- };
557
-
558
- // src/components/StackItem/StackItemHeading.tsx
559
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
560
- import { Slot as Slot2 } from "@radix-ui/react-slot";
561
- import React5, { forwardRef as forwardRef3 } from "react";
562
- import { useAttention } from "@dxos/react-ui-attention";
563
- import { mx as mx4 } from "@dxos/react-ui-theme";
564
- var StackItemHeading = ({ children, classNames, asChild, separateOnScroll, ...props }) => {
565
- var _effect = _useSignals5();
566
- try {
567
- const { orientation } = useStack();
568
- const Root = asChild ? Slot2 : "div";
569
- return /* @__PURE__ */ React5.createElement(Root, {
570
- role: "heading",
571
- ...props,
572
- className: mx4("flex items-center !border-is-0 bg-headerSurface", separateOnScroll ? 'border-transparent [[data-scroll-separator="true"]_&]:border-subduedSeparator' : "border-subduedSeparator", orientation === "horizontal" ? "bs-[--rail-size]" : "is-[--rail-size] flex-col", orientation === "horizontal" ? "border-be" : "border-ie", classNames)
573
- }, children);
574
- } finally {
575
- _effect.f();
576
- }
577
- };
578
- var StackItemHeadingStickyContent = ({ children }) => {
579
- var _effect = _useSignals5();
580
- try {
581
- return /* @__PURE__ */ React5.createElement("div", {
582
- role: "none",
583
- className: "sticky block-start-0 bg-[--sticky-bg] p-1 is-full"
584
- }, children);
585
- } finally {
586
- _effect.f();
587
- }
588
- };
589
- var StackItemHeadingLabel = /* @__PURE__ */ forwardRef3(({ attendableId, related, classNames, ...props }, forwardedRef) => {
590
- var _effect = _useSignals5();
591
- try {
592
- const { hasAttention, isAncestor, isRelated } = useAttention(attendableId);
593
- return /* @__PURE__ */ React5.createElement("h1", {
594
- ...props,
595
- "data-attention": (related && isRelated || hasAttention || isAncestor).toString(),
596
- className: mx4("pli-1 min-is-0 is-0 grow truncate font-medium text-baseText data-[attention=true]:text-accentText self-center", classNames),
597
- ref: forwardedRef
598
- });
599
- } finally {
600
- _effect.f();
601
- }
602
- });
603
-
604
- // src/components/StackItem/StackItemResizeHandle.tsx
605
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
606
- import React6 from "react";
607
- import { ResizeHandle } from "@dxos/react-ui-dnd";
608
- var MIN_WIDTH = 20;
609
- var MIN_HEIGHT = 3;
610
- var StackItemResizeHandle = () => {
611
- var _effect = _useSignals6();
612
- try {
613
- const { orientation } = useStack();
614
- const { setSize, size } = useStackItem();
615
- return /* @__PURE__ */ React6.createElement(ResizeHandle, {
616
- side: orientation === "horizontal" ? "inline-end" : "block-end",
617
- fallbackSize: DEFAULT_EXTRINSIC_SIZE,
618
- minSize: orientation === "horizontal" ? MIN_WIDTH : MIN_HEIGHT,
619
- size,
620
- onSizeChange: setSize
621
- });
622
- } finally {
623
- _effect.f();
624
- }
625
- };
626
-
627
- // src/components/StackItem/StackItemSigil.tsx
628
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
629
- import React8, { Fragment, forwardRef as forwardRef4, useState as useState4 } from "react";
630
- import { keySymbols } from "@dxos/keyboard";
631
- import { Button, DropdownMenu, Icon, toLocalizedString, useTranslation } from "@dxos/react-ui";
632
- import { useAttention as useAttention2 } from "@dxos/react-ui-attention";
633
- import { descriptionText, mx as mx5 } from "@dxos/react-ui-theme";
634
- import { getHostPlatform } from "@dxos/util";
635
-
636
- // src/components/StackItem/MenuSignifier.tsx
637
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
638
- import React7 from "react";
639
- var MenuSignifierHorizontal = () => {
640
- var _effect = _useSignals7();
641
- try {
642
- return /* @__PURE__ */ React7.createElement("svg", {
643
- className: "absolute block-end-[7px]",
644
- width: 20,
645
- height: 2,
646
- viewBox: "0 0 20 2",
647
- stroke: "currentColor",
648
- opacity: 0.5
649
- }, /* @__PURE__ */ React7.createElement("line", {
650
- x1: 0.5,
651
- y1: 0.75,
652
- x2: 19,
653
- y2: 0.75,
654
- strokeWidth: 1.25,
655
- strokeLinecap: "round",
656
- strokeDasharray: "6 20",
657
- strokeDashoffset: "-6.5"
658
- }));
659
- } finally {
660
- _effect.f();
661
- }
662
- };
663
-
664
- // src/components/StackItem/StackItemSigil.tsx
665
- var StackItemSigilButton = /* @__PURE__ */ forwardRef4(({ attendableId, classNames, related, isMenu = true, children, ...props }, forwardedRef) => {
666
- var _effect = _useSignals8();
667
- try {
668
- const { hasAttention, isAncestor, isRelated } = useAttention2(attendableId);
669
- const variant = related && isRelated || hasAttention || isAncestor ? "primary" : "ghost";
670
- return /* @__PURE__ */ React8.createElement(Button, {
671
- ...props,
672
- variant,
673
- classNames: [
674
- "shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative app-no-drag",
675
- classNames
676
- ],
677
- ref: forwardedRef
678
- }, isMenu && /* @__PURE__ */ React8.createElement(MenuSignifierHorizontal, null), children);
679
- } finally {
680
- _effect.f();
681
- }
682
- });
683
- var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAction, triggerLabel, attendableId, icon, related, children }, forwardedRef) => {
684
- var _effect = _useSignals8();
685
- try {
686
- const { t } = useTranslation(translationKey);
687
- const [optionsMenuOpen, setOptionsMenuOpen] = useState4(false);
688
- const hasActions = actionGroups && actionGroups.length > 0;
689
- const button = /* @__PURE__ */ React8.createElement(StackItemSigilButton, {
690
- attendableId,
691
- related,
692
- isMenu: hasActions,
693
- // TODO(wittjosiah): Better disabling of interactive styles when no action are available.
694
- // Remove underscore icon when no actions are available?
695
- classNames: !hasActions && "cursor-default"
696
- }, /* @__PURE__ */ React8.createElement("span", {
697
- className: "sr-only"
698
- }, triggerLabel), /* @__PURE__ */ React8.createElement(Icon, {
699
- icon,
700
- size: 5
701
- }));
702
- if (!hasActions) {
703
- return button;
704
- }
705
- return /* @__PURE__ */ React8.createElement(DropdownMenu.Root, {
706
- open: optionsMenuOpen,
707
- onOpenChange: setOptionsMenuOpen
708
- }, /* @__PURE__ */ React8.createElement(DropdownMenu.Trigger, {
709
- asChild: true,
710
- ref: forwardedRef
711
- }, button), /* @__PURE__ */ React8.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React8.createElement(DropdownMenu.Content, {
712
- classNames: "z-[31]"
713
- }, /* @__PURE__ */ React8.createElement(DropdownMenu.Viewport, null, actionGroups?.map((actions, index) => {
714
- const separator = index > 0 ? /* @__PURE__ */ React8.createElement(DropdownMenu.Separator, null) : null;
715
- return /* @__PURE__ */ React8.createElement(Fragment, {
716
- key: index
717
- }, separator, actions.map((action) => {
718
- const shortcut = typeof action.properties.keyBinding === "string" ? action.properties.keyBinding : action.properties.keyBinding?.[getHostPlatform()];
719
- const menuItemType = action.properties.menuItemType;
720
- const Root = menuItemType === "toggle" ? DropdownMenu.CheckboxItem : DropdownMenu.Item;
721
- return /* @__PURE__ */ React8.createElement(Root, {
722
- key: action.id,
723
- onClick: (event) => {
724
- if (action.properties.disabled) {
725
- return;
726
- }
727
- event.stopPropagation();
728
- setOptionsMenuOpen(false);
729
- onAction?.(action);
730
- },
731
- classNames: "gap-2",
732
- disabled: action.properties.disabled,
733
- checked: menuItemType === "toggle" ? action.properties.isChecked : void 0,
734
- ...action.properties?.testId && {
735
- "data-testid": action.properties.testId
736
- }
737
- }, /* @__PURE__ */ React8.createElement(Icon, {
738
- icon: action.properties.icon ?? "ph--placeholder--regular",
739
- size: 4
740
- }), /* @__PURE__ */ React8.createElement("span", {
741
- className: "grow truncate"
742
- }, toLocalizedString(action.properties.label ?? "", t)), menuItemType === "toggle" && /* @__PURE__ */ React8.createElement(DropdownMenu.ItemIndicator, {
743
- asChild: true
744
- }, /* @__PURE__ */ React8.createElement(Icon, {
745
- icon: "ph--check--regular",
746
- size: 4
747
- })), shortcut && /* @__PURE__ */ React8.createElement("span", {
748
- className: mx5("shrink-0", descriptionText)
749
- }, keySymbols(shortcut).join("")));
750
- }));
751
- }), children), /* @__PURE__ */ React8.createElement(DropdownMenu.Arrow, null))));
752
- } finally {
753
- _effect.f();
754
- }
755
- });
756
-
757
- // src/components/StackItem/StackItem.tsx
758
- var DEFAULT_HORIZONTAL_SIZE = 48;
759
- var DEFAULT_VERTICAL_SIZE = "min-content";
760
- var DEFAULT_EXTRINSIC_SIZE = DEFAULT_HORIZONTAL_SIZE;
761
- var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, size: propsSize, onSizeChange, role, order, prevSiblingId, nextSiblingId, style, disableRearrange, focusIndicatorVariant = "over-all", ...props }, forwardedRef) => {
762
- var _effect = _useSignals9();
763
- try {
764
- const [itemElement, itemRef] = useState5(null);
765
- const [selfDragHandleElement, selfDragHandleRef] = useState5(null);
766
- const [closestEdge, setEdge] = useState5(null);
767
- const [sourceId, setSourceId] = useState5(null);
768
- const [dragState, setDragState] = useState5(idle);
769
- const { orientation, rail, onRearrange, size: stackSize, stackId } = useStack();
770
- const [size = orientation === "horizontal" ? DEFAULT_HORIZONTAL_SIZE : DEFAULT_VERTICAL_SIZE, setInternalSize] = useState5(propsSize);
771
- const Root = role ?? "div";
772
- const composedItemRef = composeRefs2(itemRef, forwardedRef);
773
- const setSize = useCallback3((nextSize, commit) => {
774
- setInternalSize(nextSize);
775
- if (commit) {
776
- onSizeChange?.(nextSize);
777
- }
778
- }, [
779
- onSizeChange
780
- ]);
781
- const type = orientation === "horizontal" ? "column" : "card";
782
- useLayoutEffect2(() => {
783
- if (!itemElement || !onRearrange || disableRearrange) {
784
- return;
785
- }
786
- return combine2(draggable({
787
- element: itemElement,
788
- ...selfDragHandleElement && {
789
- dragHandle: selfDragHandleElement
790
- },
791
- getInitialData: () => ({
792
- id: item.id,
793
- type
794
- }),
795
- onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
796
- document.body.setAttribute("data-drag-preview", "true");
797
- const offsetFn = preserveOffsetOnSource({
798
- element: source.element,
799
- input: location.current.input
800
- });
801
- const rect = source.element.getBoundingClientRect();
802
- setCustomNativeDragPreview({
803
- nativeSetDragImage,
804
- getOffset: ({ container }) => {
805
- return offsetFn({
806
- container
807
- });
808
- },
809
- render: ({ container }) => {
810
- container.style.width = rect.width + "px";
811
- setDragState({
812
- type: "preview",
813
- container,
814
- item
815
- });
816
- return () => {
817
- };
818
- }
819
- });
820
- },
821
- onDragStart: () => {
822
- document.body.removeAttribute("data-drag-preview");
823
- itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "active");
824
- setDragState({
825
- type: "is-dragging",
826
- item
827
- });
828
- },
829
- onDrop: () => {
830
- itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "idle");
831
- setDragState(idle);
832
- }
833
- }), dropTargetForElements2({
834
- element: itemElement,
835
- getData: ({ input, element }) => {
836
- return attachClosestEdge2({
837
- id: item.id,
838
- type
839
- }, {
840
- input,
841
- element,
842
- allowedEdges: orientation === "horizontal" ? [
843
- "left",
844
- "right"
845
- ] : [
846
- "top",
847
- "bottom"
848
- ]
849
- });
850
- },
851
- onDragEnter: ({ self, source }) => {
852
- if (source.data.type === self.data.type) {
853
- setEdge(extractClosestEdge2(self.data));
854
- setSourceId(source.data.id);
855
- }
856
- },
857
- onDrag: ({ self, source }) => {
858
- if (source.data.type === self.data.type) {
859
- setEdge(extractClosestEdge2(self.data));
860
- setSourceId(source.data.id);
861
- }
862
- },
863
- onDragLeave: () => {
864
- setEdge(null);
865
- setSourceId(null);
866
- },
867
- onDrop: ({ self, source }) => {
868
- setEdge(null);
869
- setSourceId(null);
870
- if (source.data.type === self.data.type) {
871
- onRearrange(source.data, self.data, extractClosestEdge2(self.data));
872
- }
873
- }
874
- }));
875
- }, [
876
- orientation,
877
- item,
878
- onRearrange,
879
- selfDragHandleElement,
880
- itemElement
881
- ]);
882
- const focusableGroupAttrs = useFocusableGroup({
883
- tabBehavior: "limited"
884
- });
885
- const shouldShowDropIndicator = () => {
886
- if (!closestEdge || !sourceId) {
887
- return false;
888
- }
889
- if (sourceId === item.id) {
890
- return false;
891
- }
892
- const isTrailingEdgeOfPrevSibling = prevSiblingId !== void 0 && sourceId === prevSiblingId && (orientation === "horizontal" && closestEdge === "left" || orientation === "vertical" && closestEdge === "top");
893
- if (isTrailingEdgeOfPrevSibling) {
894
- return false;
895
- }
896
- const isLeadingEdgeOfNextSibling = nextSiblingId !== void 0 && sourceId === nextSiblingId && (orientation === "horizontal" && closestEdge === "right" || orientation === "vertical" && closestEdge === "bottom");
897
- if (isLeadingEdgeOfNextSibling) {
898
- return false;
899
- }
900
- return true;
901
- };
902
- const stackItemContextValue = useMemo3(() => ({
903
- selfDragHandleRef,
904
- size,
905
- setSize,
906
- state: dragState,
907
- setState: setDragState,
908
- role
909
- }), [
910
- selfDragHandleRef,
911
- size,
912
- setSize,
913
- dragState,
914
- setDragState,
915
- role
916
- ]);
917
- return /* @__PURE__ */ React9.createElement(StackItemContext.Provider, {
918
- value: stackItemContextValue
919
- }, /* @__PURE__ */ React9.createElement(Root, {
920
- ...props,
921
- tabIndex: 0,
922
- ...focusableGroupAttrs,
923
- className: mx6("group/stack-item grid relative", focusIndicatorVariant === "over-all" ? "dx-focus-ring-inset-over-all" : focusIndicatorVariant === "over-all-always" ? "dx-focus-ring-inset-over-all-always" : orientation === "horizontal" ? focusIndicatorVariant === "group-always" ? "dx-focus-ring-group-x-always" : "dx-focus-ring-group-x" : focusIndicatorVariant === "group-always" ? "dx-focus-ring-group-y-always" : "dx-focus-ring-group-y", orientation === "horizontal" ? "grid-rows-subgrid" : "grid-cols-subgrid", rail && (orientation === "horizontal" ? "row-span-2" : "col-span-2"), role === "section" && orientation !== "horizontal" && "border-be border-subduedSeparator", classNames),
924
- "data-dx-stack-item": stackId,
925
- "data-dx-item-id": item.id,
926
- ...resizeAttributes,
927
- style: {
928
- ...stackSize !== "split" && sizeStyle(size, orientation),
929
- ...Number.isFinite(order) && {
930
- [orientation === "horizontal" ? "gridColumn" : "gridRow"]: `${order}`
931
- },
932
- ...style
933
- },
934
- ref: composedItemRef
935
- }, children, shouldShowDropIndicator() && closestEdge && /* @__PURE__ */ React9.createElement(ListItem2.DropIndicator, {
936
- lineInset: 8,
937
- terminalInset: -8,
938
- edge: closestEdge
939
- })));
940
- } finally {
941
- _effect.f();
942
- }
943
- });
944
- var StackItemDragPreview = ({ children }) => {
945
- const { state } = useStackItem();
946
- return state?.type === "preview" ? /* @__PURE__ */ createPortal(children({
947
- item: state.item
948
- }), state.container) : null;
949
- };
950
- var StackItem = {
951
- Root: StackItemRoot,
952
- Content: StackItemContent,
953
- Heading: StackItemHeading,
954
- HeadingLabel: StackItemHeadingLabel,
955
- HeadingStickyContent: StackItemHeadingStickyContent,
956
- ResizeHandle: StackItemResizeHandle,
957
- DragHandle: StackItemDragHandle,
958
- Sigil: StackItemSigil,
959
- SigilButton: StackItemSigilButton,
960
- DragPreview: StackItemDragPreview
961
- };
962
-
963
- // src/exemplars/Card/fragments.ts
964
- var cardRoot = "rounded overflow-hidden bg-cardSurface border border-separator dark:border-subduedSeparator dx-focus-ring-group-y-indicator relative min-bs-[--rail-item] group/card";
965
- var cardSpacing = "pli-cardSpacingInline mlb-cardSpacingBlock";
966
- var cardNoSpacing = "pli-0 mlb-0";
967
- var labelSpacing = "mbs-inputSpacingBlock mbe-labelSpacingBlock";
968
- var cardDialogContent = "p-0 bs-content min-bs-[8rem] max-bs-full md:max-is-[32rem] overflow-hidden";
969
- var cardDialogHeader = "pli-cardSpacingInline mbs-cardSpacingBlock flex justify-between";
970
- var cardDialogOverflow = "overflow-y-auto min-bs-0 flex-1";
971
- var cardDialogPaddedOverflow = `${cardDialogOverflow} plb-cardSpacingBlock`;
972
- var cardDialogSearchListRoot = "pli-cardSpacingInline pbs-cardSpacingBlock [&>input]:mbe-0 min-bs-0 flex-1 flex flex-col";
973
- var cardText = cardSpacing;
974
- var cardHeading = "text-lg font-medium line-clamp-2 grow";
975
- var cardChrome = "pli-[--dx-cardSpacingChrome] mlb-[--dx-cardSpacingChrome] [&_.dx-button]:text-start [&_.dx-button]:is-full [&_.dx-button]:pis-[calc(var(--dx-cardSpacingInline)-var(--dx-cardSpacingChrome))]";
976
-
977
- // src/exemplars/Card/Card.tsx
978
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
979
- import { Primitive } from "@radix-ui/react-primitive";
980
- import { Slot as Slot3 } from "@radix-ui/react-slot";
981
- import React10, { forwardRef as forwardRef6 } from "react";
982
- import { Icon as Icon2, IconButton, Toolbar, useTranslation as useTranslation2 } from "@dxos/react-ui";
983
- import { cardMinInlineSize, hoverableControls, mx as mx7 } from "@dxos/react-ui-theme";
984
- var cardDefaultInlineSize = cardMinInlineSize;
985
- var cardStackDefaultInlineSizeRem = cardDefaultInlineSize + 2.125;
986
- var CardStaticRoot = /* @__PURE__ */ forwardRef6(({ children, classNames, id, asChild, role = "group", ...props }, forwardedRef) => {
987
- var _effect = _useSignals10();
988
- try {
989
- const Root = asChild ? Slot3 : "div";
990
- const rootProps = asChild ? {
991
- classNames: [
992
- cardRoot,
993
- classNames
994
- ]
995
- } : {
996
- className: mx7(cardRoot, classNames),
997
- role
998
- };
999
- return /* @__PURE__ */ React10.createElement(Root, {
1000
- ...id && {
1001
- "data-object-id": id
1002
- },
1003
- ...props,
1004
- ...rootProps,
1005
- ref: forwardedRef
1006
- }, children);
1007
- } finally {
1008
- _effect.f();
1009
- }
1010
- });
1011
- var CardSurfaceRoot = ({ id, role = "never", children, classNames }) => {
1012
- var _effect = _useSignals10();
1013
- try {
1014
- if ([
1015
- "card--popover",
1016
- "card--intrinsic",
1017
- "card--extrinsic"
1018
- ].includes(role)) {
1019
- return /* @__PURE__ */ React10.createElement("div", {
1020
- ...id && {
1021
- "data-object-id": id
1022
- },
1023
- className: mx7(role === "card--popover" ? "popover-card-width" : [
1024
- "card--intrinsic",
1025
- "card--extrinsic"
1026
- ].includes(role) ? "contents" : "", classNames)
1027
- }, children);
1028
- } else {
1029
- return /* @__PURE__ */ React10.createElement(CardStaticRoot, {
1030
- id,
1031
- classNames: [
1032
- role === "card--transclusion" && "mlb-1",
1033
- role === "card--transclusion" && hoverableControls,
1034
- classNames
1035
- ]
1036
- }, children);
1037
- }
1038
- } finally {
1039
- _effect.f();
1040
- }
1041
- };
1042
- var CardHeading = /* @__PURE__ */ forwardRef6(({ children, classNames, asChild, role = "heading", ...props }, forwardedRef) => {
1043
- var _effect = _useSignals10();
1044
- try {
1045
- const Root = asChild ? Slot3 : "div";
1046
- const rootProps = asChild ? {
1047
- classNames: [
1048
- cardHeading,
1049
- cardText,
1050
- classNames
1051
- ]
1052
- } : {
1053
- className: mx7(cardHeading, cardText, classNames),
1054
- role
1055
- };
1056
- return /* @__PURE__ */ React10.createElement(Root, {
1057
- ...props,
1058
- ...rootProps,
1059
- ref: forwardedRef
1060
- }, children);
1061
- } finally {
1062
- _effect.f();
1063
- }
1064
- });
1065
- var CardToolbar = /* @__PURE__ */ forwardRef6(({ children, classNames, ...props }, forwardedRef) => {
1066
- var _effect = _useSignals10();
1067
- try {
1068
- return /* @__PURE__ */ React10.createElement(Toolbar.Root, {
1069
- ...props,
1070
- classNames: [
1071
- "bg-transparent density-coarse",
1072
- classNames
1073
- ],
1074
- ref: forwardedRef
1075
- }, children);
1076
- } finally {
1077
- _effect.f();
1078
- }
1079
- });
1080
- var CardToolbarIconButton = Toolbar.IconButton;
1081
- var CardToolbarSeparator = Toolbar.Separator;
1082
- var CardDragHandle = /* @__PURE__ */ forwardRef6(({ toolbarItem }, forwardedRef) => {
1083
- var _effect = _useSignals10();
1084
- try {
1085
- const { t } = useTranslation2(translationKey);
1086
- const Root = toolbarItem ? Toolbar.IconButton : IconButton;
1087
- return /* @__PURE__ */ React10.createElement(Root, {
1088
- iconOnly: true,
1089
- icon: "ph--dots-six-vertical--regular",
1090
- variant: "ghost",
1091
- label: t("drag handle label"),
1092
- classNames: "pli-2",
1093
- ref: forwardedRef
1094
- });
1095
- } finally {
1096
- _effect.f();
1097
- }
1098
- });
1099
- var CardDragPreview = StackItem.DragPreview;
1100
- var CardMenu = Primitive.div;
1101
- var CardPoster = (props) => {
1102
- var _effect = _useSignals10();
1103
- try {
1104
- const aspect = props.aspect === "auto" ? "aspect-auto" : "aspect-video";
1105
- if (props.image) {
1106
- return /* @__PURE__ */ React10.createElement(Image, {
1107
- classNames: [
1108
- `dx-card__poster is-full`,
1109
- aspect,
1110
- props.classNames
1111
- ],
1112
- src: props.image,
1113
- alt: props.alt
1114
- });
1115
- }
1116
- if (props.icon) {
1117
- return /* @__PURE__ */ React10.createElement("div", {
1118
- role: "image",
1119
- className: mx7(`dx-card__poster grid place-items-center bg-inputSurface text-subdued`, aspect, props.classNames),
1120
- "aria-label": props.alt
1121
- }, /* @__PURE__ */ React10.createElement(Icon2, {
1122
- icon: props.icon,
1123
- size: 10
1124
- }));
1125
- }
1126
- } finally {
1127
- _effect.f();
1128
- }
1129
- };
1130
- var CardChrome = /* @__PURE__ */ forwardRef6(({ children, classNames, asChild, role = "none", ...props }, forwardedRef) => {
1131
- var _effect = _useSignals10();
1132
- try {
1133
- const Root = asChild ? Slot3 : "div";
1134
- const rootProps = asChild ? {
1135
- classNames: [
1136
- cardChrome,
1137
- classNames
1138
- ]
1139
- } : {
1140
- className: mx7(cardChrome, classNames),
1141
- role
1142
- };
1143
- return /* @__PURE__ */ React10.createElement(Root, {
1144
- ...props,
1145
- ...rootProps,
1146
- ref: forwardedRef
1147
- }, children);
1148
- } finally {
1149
- _effect.f();
1150
- }
1151
- });
1152
- var CardText = /* @__PURE__ */ forwardRef6(({ children, classNames, asChild, role = "none", ...props }, forwardedRef) => {
1153
- var _effect = _useSignals10();
1154
- try {
1155
- const Root = asChild ? Slot3 : "div";
1156
- const rootProps = asChild ? {
1157
- classNames: [
1158
- cardText,
1159
- classNames
1160
- ]
1161
- } : {
1162
- className: mx7(cardText, classNames),
1163
- role
1164
- };
1165
- return /* @__PURE__ */ React10.createElement(Root, {
1166
- ...props,
1167
- ...rootProps,
1168
- ref: forwardedRef
1169
- }, children);
1170
- } finally {
1171
- _effect.f();
1172
- }
1173
- });
1174
- var Card = {
1175
- StaticRoot: CardStaticRoot,
1176
- SurfaceRoot: CardSurfaceRoot,
1177
- Heading: CardHeading,
1178
- Toolbar: CardToolbar,
1179
- ToolbarIconButton: CardToolbarIconButton,
1180
- ToolbarSeparator: CardToolbarSeparator,
1181
- DragHandle: CardDragHandle,
1182
- DragPreview: CardDragPreview,
1183
- Menu: CardMenu,
1184
- Poster: CardPoster,
1185
- Chrome: CardChrome,
1186
- Text: CardText
1187
- };
1188
-
1189
- // src/exemplars/Card/CardDragPreview.tsx
1190
- import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
1191
- import React11 from "react";
1192
- import { mx as mx8 } from "@dxos/react-ui-theme";
1193
- var CardDragPreviewRoot = ({ children }) => {
1194
- var _effect = _useSignals11();
1195
- try {
1196
- return /* @__PURE__ */ React11.createElement("div", {
1197
- className: "p-2"
1198
- }, children);
1199
- } finally {
1200
- _effect.f();
1201
- }
1202
- };
1203
- var CardDragPreviewContent = ({ children }) => {
1204
- var _effect = _useSignals11();
1205
- try {
1206
- return /* @__PURE__ */ React11.createElement("div", {
1207
- className: mx8(cardRoot, "ring-focusLine ring-neutralFocusIndicator")
1208
- }, children);
1209
- } finally {
1210
- _effect.f();
1211
- }
1212
- };
1213
- var CardDragPreview2 = {
1214
- Root: CardDragPreviewRoot,
1215
- Content: CardDragPreviewContent
1216
- };
1217
-
1218
- // src/exemplars/CardStack/CardStack.tsx
1219
- import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
1220
- import { Slot as Slot4 } from "@radix-ui/react-slot";
1221
- import React12, { forwardRef as forwardRef7 } from "react";
1222
- import { mx as mx9 } from "@dxos/react-ui-theme";
1223
- var CardStackStack = /* @__PURE__ */ forwardRef7(({ children, classNames, itemsCount = 0, ...props }, forwardedRef) => {
1224
- var _effect = _useSignals12();
1225
- try {
1226
- return /* @__PURE__ */ React12.createElement(Stack, {
1227
- orientation: "vertical",
1228
- size: "contain",
1229
- rail: false,
1230
- classNames: (
1231
- /* NOTE(thure): Do not let this element have zero intrinsic size, otherwise the drop indicator will not display. See #9035. */
1232
- [
1233
- "plb-1",
1234
- itemsCount > 0 && "plb-2",
1235
- classNames
1236
- ]
1237
- ),
1238
- itemsCount,
1239
- separatorOnScroll: 9,
1240
- "data-density": "fine",
1241
- ...props,
1242
- ref: forwardedRef
1243
- }, children);
1244
- } finally {
1245
- _effect.f();
1246
- }
1247
- });
1248
- var CardStackDragHandle = Card.DragHandle;
1249
- var cardStackHeading = "mli-2 order-first bg-transparent rounded-bs-md flex items-center";
1250
- var CardStackHeading = /* @__PURE__ */ forwardRef7(({ children, classNames, asChild, role = "heading", ...props }, forwardedRef) => {
1251
- var _effect = _useSignals12();
1252
- try {
1253
- const Root = asChild ? Slot4 : "div";
1254
- const rootProps = asChild ? {
1255
- classNames: [
1256
- cardStackHeading,
1257
- classNames
1258
- ]
1259
- } : {
1260
- className: mx9(cardStackHeading, classNames),
1261
- role
1262
- };
1263
- return /* @__PURE__ */ React12.createElement(Root, {
1264
- ...props,
1265
- ...rootProps,
1266
- ref: forwardedRef
1267
- }, children);
1268
- } finally {
1269
- _effect.f();
1270
- }
1271
- });
1272
- var cardStackFooter = 'plb-2 mli-2 border-bs border-transparent [[data-scroll-separator-end="true"]_&]:border-subduedSeparator';
1273
- var CardStackFooter = /* @__PURE__ */ forwardRef7(({ children, classNames, asChild, role = "none", ...props }, forwardedRef) => {
1274
- var _effect = _useSignals12();
1275
- try {
1276
- const Root = asChild ? Slot4 : "div";
1277
- const rootProps = asChild ? {
1278
- classNames: [
1279
- cardStackFooter,
1280
- classNames
1281
- ]
1282
- } : {
1283
- className: mx9(cardStackFooter, classNames),
1284
- role
1285
- };
1286
- return /* @__PURE__ */ React12.createElement(Root, {
1287
- ...props,
1288
- ...rootProps,
1289
- ref: forwardedRef
1290
- }, children);
1291
- } finally {
1292
- _effect.f();
1293
- }
1294
- });
1295
- var cardStackContent = "shrink min-bs-0 bg-baseSurface border border-separator rounded-md grid dx-focus-ring-group-x-indicator kanban-drop";
1296
- var CardStackContent = /* @__PURE__ */ forwardRef7(({ children, classNames, asChild, role = "none", footer = true, ...props }, forwardedRef) => {
1297
- var _effect = _useSignals12();
1298
- try {
1299
- const Root = asChild ? Slot4 : "div";
1300
- const baseClassNames = footer ? [
1301
- cardStackContent,
1302
- railGridHorizontalContainFitContent
1303
- ] : [
1304
- cardStackContent
1305
- ];
1306
- const rootProps = asChild ? {
1307
- classNames: [
1308
- ...baseClassNames,
1309
- classNames
1310
- ]
1311
- } : {
1312
- className: mx9(...baseClassNames, classNames),
1313
- role
1314
- };
1315
- return /* @__PURE__ */ React12.createElement(Root, {
1316
- ...props,
1317
- ...rootProps,
1318
- "data-scroll-separator": "false",
1319
- ref: forwardedRef
1320
- }, children);
1321
- } finally {
1322
- _effect.f();
1323
- }
1324
- });
1325
- var cardStackRoot = "flex flex-col pli-2 plb-2";
1326
- var CardStackRoot = /* @__PURE__ */ forwardRef7(({ children, classNames, asChild, role = "none", ...props }, forwardedRef) => {
1327
- var _effect = _useSignals12();
1328
- try {
1329
- const Root = asChild ? Slot4 : "div";
1330
- const rootProps = asChild ? {
1331
- classNames: [
1332
- cardStackRoot,
1333
- classNames
1334
- ]
1335
- } : {
1336
- className: mx9(cardStackRoot, classNames),
1337
- role
1338
- };
1339
- return /* @__PURE__ */ React12.createElement(Root, {
1340
- ...props,
1341
- ...rootProps,
1342
- ref: forwardedRef
1343
- }, children);
1344
- } finally {
1345
- _effect.f();
1346
- }
1347
- });
1348
- var cardStackItem = "contain-layout pli-2 plb-1 first-of-type:pbs-0 last-of-type:pbe-0";
1349
- var CardStackItem = /* @__PURE__ */ forwardRef7(({ children, classNames, asChild, role = "none", ...props }, forwardedRef) => {
1350
- var _effect = _useSignals12();
1351
- try {
1352
- const Root = asChild ? Slot4 : "div";
1353
- const rootProps = asChild ? {
1354
- classNames: [
1355
- cardStackItem,
1356
- classNames
1357
- ]
1358
- } : {
1359
- className: mx9(cardStackItem, classNames),
1360
- role
1361
- };
1362
- return /* @__PURE__ */ React12.createElement(Root, {
1363
- ...props,
1364
- ...rootProps,
1365
- ref: forwardedRef
1366
- }, children);
1367
- } finally {
1368
- _effect.f();
1369
- }
1370
- });
1371
- var CardStack = {
1372
- Root: CardStackRoot,
1373
- Content: CardStackContent,
1374
- Stack: CardStackStack,
1375
- Heading: CardStackHeading,
1376
- Footer: CardStackFooter,
1377
- DragHandle: CardStackDragHandle,
1378
- Item: CardStackItem
1379
- };
1380
-
1381
- // src/exemplars/CardStack/CardStackDragPreview.tsx
1382
- import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
1383
- import React13 from "react";
1384
- import { IconButton as IconButton2, useTranslation as useTranslation3 } from "@dxos/react-ui";
1385
- import { mx as mx10 } from "@dxos/react-ui-theme";
1386
- var CardStackDragPreviewRoot = ({ children }) => {
1387
- var _effect = _useSignals13();
1388
- try {
1389
- return /* @__PURE__ */ React13.createElement("div", {
1390
- className: "p-2"
1391
- }, /* @__PURE__ */ React13.createElement("div", {
1392
- className: "rounded-md max-bs-[calc(100dvh-1rem)] overflow-hidden bg-baseSurface border border-separator ring-focusLine ring-neutralFocusIndicator flex flex-col"
1393
- }, children));
1394
- } finally {
1395
- _effect.f();
1396
- }
1397
- };
1398
- var CardStackDragPreviewHeading = ({ children }) => {
1399
- var _effect = _useSignals13();
1400
- try {
1401
- const { t } = useTranslation3(translationKey);
1402
- return /* @__PURE__ */ React13.createElement("div", {
1403
- className: "flex items-center p-2"
1404
- }, /* @__PURE__ */ React13.createElement(IconButton2, {
1405
- iconOnly: true,
1406
- icon: "ph--dots-six-vertical--regular",
1407
- variant: "ghost",
1408
- label: t("column drag handle label"),
1409
- classNames: "pli-2"
1410
- }), children);
1411
- } finally {
1412
- _effect.f();
1413
- }
1414
- };
1415
- var CardStackDragPreviewContent = ({ children, itemsCount = 0 }) => {
1416
- var _effect = _useSignals13();
1417
- try {
1418
- return /* @__PURE__ */ React13.createElement("div", {
1419
- className: mx10("overflow-y-auto flex-1 pli-2 flex flex-col gap-2", "plb-1", itemsCount > 0 ? "plb-2" : "plb-1")
1420
- }, children);
1421
- } finally {
1422
- _effect.f();
1423
- }
1424
- };
1425
- var CardStackDragPreviewFooter = ({ children }) => {
1426
- var _effect = _useSignals13();
1427
- try {
1428
- return /* @__PURE__ */ React13.createElement("div", {
1429
- className: "p-2 border-t border-separator"
1430
- }, children);
1431
- } finally {
1432
- _effect.f();
1433
- }
1434
- };
1435
- var CardStackDragPreview = {
1436
- Root: CardStackDragPreviewRoot,
1437
- Heading: CardStackDragPreviewHeading,
1438
- Content: CardStackDragPreviewContent,
1439
- Footer: CardStackDragPreviewFooter
1440
- };
1441
-
1442
- export {
1443
- Image,
1444
- StackContext,
1445
- railGridHorizontal,
1446
- railGridVertical,
1447
- railGridHorizontalContainFitContent,
1448
- railGridVerticalContainFitContent,
1449
- autoScrollRootAttributes,
1450
- Stack,
1451
- translationKey,
1452
- translations,
1453
- DEFAULT_HORIZONTAL_SIZE,
1454
- DEFAULT_VERTICAL_SIZE,
1455
- DEFAULT_EXTRINSIC_SIZE,
1456
- StackItemDragPreview,
1457
- StackItem,
1458
- cardRoot,
1459
- cardSpacing,
1460
- cardNoSpacing,
1461
- labelSpacing,
1462
- cardDialogContent,
1463
- cardDialogHeader,
1464
- cardDialogOverflow,
1465
- cardDialogPaddedOverflow,
1466
- cardDialogSearchListRoot,
1467
- cardText,
1468
- cardHeading,
1469
- cardChrome,
1470
- cardDefaultInlineSize,
1471
- cardStackDefaultInlineSizeRem,
1472
- Card,
1473
- CardDragPreview2 as CardDragPreview,
1474
- cardStackHeading,
1475
- cardStackFooter,
1476
- cardStackContent,
1477
- cardStackRoot,
1478
- cardStackItem,
1479
- CardStack,
1480
- CardStackDragPreview
1481
- };
1482
- //# sourceMappingURL=chunk-3F2KBXLP.mjs.map