@dxos/react-ui-stack 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef

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