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