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