@dxos/react-ui-stack 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae

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