@dxos/react-ui-stack 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33

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 (109) hide show
  1. package/dist/lib/browser/index.mjs +706 -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/translations.mjs +23 -0
  5. package/dist/lib/browser/translations.mjs.map +7 -0
  6. package/dist/lib/node-esm/index.mjs +707 -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/translations.mjs +25 -0
  10. package/dist/lib/node-esm/translations.mjs.map +7 -0
  11. package/dist/types/src/components/Stack/Stack.d.ts +13 -10
  12. package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
  13. package/dist/types/src/components/Stack/Stack.stories.d.ts +12 -3
  14. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/StackContext.d.ts +2 -1
  16. package/dist/types/src/components/StackContext.d.ts.map +1 -1
  17. package/dist/types/src/components/StackItem/MenuSignifier.d.ts.map +1 -1
  18. package/dist/types/src/components/StackItem/StackItem.d.ts +12 -15
  19. package/dist/types/src/components/StackItem/StackItem.d.ts.map +1 -1
  20. package/dist/types/src/components/StackItem/StackItem.stories.d.ts +13 -5
  21. package/dist/types/src/components/StackItem/StackItem.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/StackItem/StackItemContent.d.ts +4 -37
  23. package/dist/types/src/components/StackItem/StackItemContent.d.ts.map +1 -1
  24. package/dist/types/src/components/StackItem/StackItemDragHandle.d.ts.map +1 -1
  25. package/dist/types/src/components/StackItem/StackItemHeading.d.ts +1 -1
  26. package/dist/types/src/components/StackItem/StackItemHeading.d.ts.map +1 -1
  27. package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts +1 -1
  28. package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts.map +1 -1
  29. package/dist/types/src/components/StackItem/StackItemSigil.d.ts +2 -2
  30. package/dist/types/src/components/StackItem/StackItemSigil.d.ts.map +1 -1
  31. package/dist/types/src/components/index.d.ts +1 -1
  32. package/dist/types/src/components/index.d.ts.map +1 -1
  33. package/dist/types/src/components/{defs.d.ts → types.d.ts} +1 -1
  34. package/dist/types/src/components/types.d.ts.map +1 -0
  35. package/dist/types/src/hooks/useStackDropForElements.d.ts +8 -6
  36. package/dist/types/src/hooks/useStackDropForElements.d.ts.map +1 -1
  37. package/dist/types/src/index.d.ts +0 -2
  38. package/dist/types/src/index.d.ts.map +1 -1
  39. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  40. package/dist/types/src/playwright/stack-manager.d.ts.map +1 -1
  41. package/dist/types/src/translations.d.ts +10 -10
  42. package/dist/types/src/translations.d.ts.map +1 -1
  43. package/dist/types/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +49 -47
  45. package/src/components/Stack/Stack.stories.tsx +13 -17
  46. package/src/components/Stack/Stack.tsx +238 -52
  47. package/src/components/StackContext.tsx +2 -1
  48. package/src/components/StackItem/MenuSignifier.tsx +2 -9
  49. package/src/components/StackItem/StackItem.stories.tsx +21 -17
  50. package/src/components/StackItem/StackItem.tsx +51 -34
  51. package/src/components/StackItem/StackItemContent.tsx +24 -44
  52. package/src/components/StackItem/StackItemDragHandle.tsx +4 -3
  53. package/src/components/StackItem/StackItemHeading.tsx +14 -17
  54. package/src/components/StackItem/StackItemResizeHandle.tsx +1 -2
  55. package/src/components/StackItem/StackItemSigil.tsx +10 -7
  56. package/src/components/index.ts +2 -1
  57. package/src/hooks/useStackDropForElements.ts +60 -46
  58. package/src/index.ts +0 -4
  59. package/src/playwright/playwright.config.ts +1 -1
  60. package/src/translations.ts +9 -9
  61. package/dist/lib/browser/chunk-WOG2GQRG.mjs +0 -1200
  62. package/dist/lib/browser/chunk-WOG2GQRG.mjs.map +0 -7
  63. package/dist/lib/browser/testing/index.mjs +0 -31
  64. package/dist/lib/browser/testing/index.mjs.map +0 -7
  65. package/dist/lib/node-esm/chunk-PO2QGNXW.mjs +0 -1202
  66. package/dist/lib/node-esm/chunk-PO2QGNXW.mjs.map +0 -7
  67. package/dist/lib/node-esm/testing/index.mjs +0 -32
  68. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  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 -58
  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 -13
  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 -40
  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 -9
  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/deprecated/LayoutControls.tsx +0 -109
  97. package/src/exemplars/Card/Card.stories.tsx +0 -78
  98. package/src/exemplars/Card/Card.tsx +0 -187
  99. package/src/exemplars/Card/CardDragPreview.tsx +0 -22
  100. package/src/exemplars/Card/fragments.ts +0 -24
  101. package/src/exemplars/Card/index.ts +0 -7
  102. package/src/exemplars/CardStack/CardStack.stories.tsx +0 -173
  103. package/src/exemplars/CardStack/CardStack.tsx +0 -136
  104. package/src/exemplars/CardStack/CardStackDragPreview.tsx +0 -61
  105. package/src/exemplars/CardStack/index.ts +0 -6
  106. package/src/exemplars/index.ts +0 -6
  107. package/src/testing/CardContainer.tsx +0 -37
  108. package/src/testing/index.ts +0 -5
  109. /package/src/components/{defs.ts → types.ts} +0 -0
@@ -1,75 +1,716 @@
1
- import {
2
- Card,
3
- CardDragPreview,
4
- CardStack,
5
- CardStackDragPreview,
6
- DEFAULT_EXTRINSIC_SIZE,
7
- DEFAULT_HORIZONTAL_SIZE,
8
- DEFAULT_VERTICAL_SIZE,
9
- Stack,
10
- StackContext,
11
- StackItem,
12
- StackItemDragPreview,
13
- autoScrollRootAttributes,
14
- cardChrome,
15
- cardDialogContent,
16
- cardDialogHeader,
17
- cardDialogOverflow,
18
- cardDialogPaddedOverflow,
19
- cardDialogSearchListRoot,
20
- cardHeading,
21
- cardNoSpacing,
22
- cardRoot,
23
- cardSpacing,
24
- cardStackContent,
25
- cardStackFooter,
26
- cardStackHeading,
27
- cardStackItem,
28
- cardStackRoot,
29
- cardText,
30
- labelSpacing,
31
- railGridHorizontal,
32
- railGridHorizontalContainFitContent,
33
- railGridVertical,
34
- railGridVerticalContainFitContent,
35
- translationKey,
36
- translations
37
- } from "./chunk-WOG2GQRG.mjs";
1
+ // src/components/Stack/Stack.tsx
2
+ import { composeRefs } from "@radix-ui/react-compose-refs";
3
+ import React, { Children, forwardRef, useCallback, useEffect, useState as useState2 } from "react";
4
+ import { ListItem, useId } from "@dxos/react-ui";
5
+ import { mx } from "@dxos/ui-theme";
6
+
7
+ // src/hooks/useStackDropForElements.ts
8
+ import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
9
+ import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
10
+ import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
11
+ import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
12
+ import { useLayoutEffect, useState } from "react";
13
+ var noop = () => {
14
+ };
15
+ var useStackDropForElements = ({ id, element, scrollElement = element, orientation, selfDroppable, onRearrange }) => {
16
+ const [dropping, setDropping] = useState(false);
17
+ useLayoutEffect(() => {
18
+ if (!element) {
19
+ return;
20
+ }
21
+ const acceptSourceType = orientation === "horizontal" ? "column" : "card";
22
+ return combine(selfDroppable ? dropTargetForElements({
23
+ element,
24
+ getData: ({ input, element: element2 }) => {
25
+ return attachClosestEdge({
26
+ id,
27
+ type: orientation === "horizontal" ? "card" : "column"
28
+ }, {
29
+ input,
30
+ element: element2,
31
+ allowedEdges: [
32
+ orientation === "horizontal" ? "left" : "top"
33
+ ]
34
+ });
35
+ },
36
+ onDragEnter: ({ source }) => {
37
+ if (source.data.type === acceptSourceType) {
38
+ setDropping(true);
39
+ }
40
+ },
41
+ onDrag: ({ source }) => {
42
+ if (source.data.type === acceptSourceType) {
43
+ setDropping(true);
44
+ }
45
+ },
46
+ onDragLeave: () => {
47
+ return setDropping(false);
48
+ },
49
+ onDrop: ({ self, source }) => {
50
+ setDropping(false);
51
+ if (source.data.type === acceptSourceType && selfDroppable && onRearrange) {
52
+ onRearrange(source.data, self.data, extractClosestEdge(self.data));
53
+ }
54
+ }
55
+ }) : noop, scrollElement ? autoScrollForElements({
56
+ element: scrollElement,
57
+ getAllowedAxis: () => orientation
58
+ }) : noop);
59
+ }, [
60
+ id,
61
+ element,
62
+ scrollElement,
63
+ selfDroppable,
64
+ orientation,
65
+ onRearrange
66
+ ]);
67
+ return {
68
+ dropping
69
+ };
70
+ };
71
+
72
+ // src/components/StackContext.tsx
73
+ import { createContext, useContext } from "react";
74
+ var StackContext = /* @__PURE__ */ createContext({
75
+ orientation: "vertical",
76
+ rail: true,
77
+ size: "intrinsic"
78
+ });
79
+ var useStack = () => useContext(StackContext);
80
+ var idle = {
81
+ type: "idle"
82
+ };
83
+ var StackItemContext = /* @__PURE__ */ createContext({
84
+ selfDragHandleRef: () => {
85
+ },
86
+ size: "min-content",
87
+ setSize: () => {
88
+ },
89
+ state: idle,
90
+ setState: () => {
91
+ }
92
+ });
93
+ var useStackItem = () => useContext(StackItemContext);
94
+
95
+ // src/components/Stack/Stack.tsx
96
+ var railGridHorizontal = "grid-rows-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]";
97
+ var railGridVertical = "grid-cols-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]";
98
+ var PERPENDICULAR_FOCUS_THRESHHOLD = 128;
99
+ var scrollIntoViewAndFocus = (el, orientation) => {
100
+ el.scrollIntoView({
101
+ behavior: "instant",
102
+ [orientation === "vertical" ? "block" : "inline"]: "center"
103
+ });
104
+ return el.focus();
105
+ };
106
+ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, id, style, orientation = "vertical", rail = true, size = "intrinsic", itemsCount = Children.count(children), circularFocus, separatorOnScroll, getDropElement, onBlur, onKeyDown, onRearrange, ...props }, forwardedRef) => {
107
+ const stackId = useId("stack", id);
108
+ const [stackElement, stackRef] = useState2(null);
109
+ const [lastFocusedItem, setLastFocusedItem] = useState2();
110
+ const composedItemRef = composeRefs(stackRef, forwardedRef);
111
+ const selfDroppable = !!(itemsCount < 1 && onRearrange && id);
112
+ const { dropping } = useStackDropForElements({
113
+ id,
114
+ element: getDropElement && stackElement ? getDropElement(stackElement) : stackElement,
115
+ scrollElement: stackElement,
116
+ selfDroppable,
117
+ orientation,
118
+ onRearrange
119
+ });
120
+ const handleScroll = useCallback(() => {
121
+ if (stackElement && Number.isFinite(separatorOnScroll)) {
122
+ const scrollPosition = orientation === "horizontal" ? stackElement.scrollLeft : stackElement.scrollTop;
123
+ const scrollSize = orientation === "horizontal" ? stackElement.scrollWidth : stackElement.scrollHeight;
124
+ const clientSize = orientation === "horizontal" ? stackElement.clientWidth : stackElement.clientHeight;
125
+ const separatorHost = stackElement.closest("[data-scroll-separator]");
126
+ if (separatorHost) {
127
+ separatorHost.setAttribute("data-scroll-separator", String(scrollPosition > separatorOnScroll));
128
+ separatorHost.setAttribute("data-scroll-separator-end", String(scrollSize - (scrollPosition + clientSize) > separatorOnScroll));
129
+ }
130
+ }
131
+ }, [
132
+ stackElement,
133
+ separatorOnScroll,
134
+ orientation
135
+ ]);
136
+ const handleBlur = useCallback((event) => {
137
+ if (event.target) {
138
+ const target = event.target;
139
+ const closestStackItem = target.closest(`[data-dx-item-id]`);
140
+ if (closestStackItem?.closest(`[data-dx-stack="${stackId}"]`)) {
141
+ setLastFocusedItem(closestStackItem?.getAttribute("data-dx-item-id") ?? void 0);
142
+ }
143
+ }
144
+ onBlur?.(event);
145
+ }, [
146
+ stackId,
147
+ onBlur
148
+ ]);
149
+ const handleKeyDown = useKeyDown(stackId, circularFocus, onKeyDown);
150
+ useEffect(() => {
151
+ if (!(stackElement && Number.isFinite(separatorOnScroll))) {
152
+ return;
153
+ }
154
+ const observer = new MutationObserver(() => {
155
+ handleScroll();
156
+ });
157
+ observer.observe(stackElement, {
158
+ childList: true,
159
+ subtree: true
160
+ });
161
+ return () => {
162
+ observer.disconnect();
163
+ };
164
+ }, [
165
+ stackElement,
166
+ handleScroll
167
+ ]);
168
+ return /* @__PURE__ */ React.createElement(StackContext.Provider, {
169
+ value: {
170
+ stackId,
171
+ orientation,
172
+ rail,
173
+ size,
174
+ onRearrange
175
+ }
176
+ }, /* @__PURE__ */ React.createElement("div", {
177
+ ...props,
178
+ ...Number.isFinite(separatorOnScroll) && {
179
+ onScroll: handleScroll
180
+ },
181
+ className: mx("relative grid [--stack-gap:var(--spacing-trim-xs)]", size === "contain" && (orientation === "horizontal" ? "overflow-x-auto overscroll-x-contain min-h-0 max-h-full h-full" : "overflow-y-auto min-w-0 max-w-full w-full"), rail ? orientation === "horizontal" ? railGridHorizontal : railGridVertical : orientation === "horizontal" ? "grid-rows-1 px-(--stack-gap)" : "grid-cols-1 py-(--stack-gap)", classNames),
182
+ style: {
183
+ [orientation === "horizontal" ? "gridTemplateColumns" : "gridTemplateRows"]: size === "split" ? `repeat(${itemsCount}, 1fr)` : `repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
184
+ ...style
185
+ },
186
+ "aria-orientation": orientation,
187
+ "data-dx-stack": stackId,
188
+ "data-dx-stack-circular-focus": circularFocus,
189
+ "data-dx-last-focused-item": lastFocusedItem,
190
+ "data-rail": rail,
191
+ onBlur: handleBlur,
192
+ onKeyDown: handleKeyDown,
193
+ ref: composedItemRef
194
+ }, children, selfDroppable && dropping && /* @__PURE__ */ React.createElement(ListItem.DropIndicator, {
195
+ lineInset: 8,
196
+ terminalInset: -8,
197
+ gap: -8,
198
+ edge: orientation === "horizontal" ? "left" : "top"
199
+ })));
200
+ });
201
+ var useKeyDown = (stackId, circularFocus, onKeyDown) => useCallback((event) => {
202
+ const target = event.target;
203
+ 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)}"]`)) {
204
+ const closestOwnedItem = target.closest(`[data-dx-stack-item="${stackId}"]`);
205
+ const closestStack = target.closest("[data-dx-stack]");
206
+ const closestStackItems = Array.from(closestStack?.querySelectorAll(`[data-dx-stack-item="${stackId}"]`) ?? []);
207
+ const closestStackOrientation = closestStack?.getAttribute("aria-orientation");
208
+ const ancestorStack = closestStack?.parentElement?.closest("[data-dx-stack]");
209
+ if (closestOwnedItem && closestStack) {
210
+ const ancestorOrientation = ancestorStack?.getAttribute("aria-orientation");
211
+ const parallelDelta = (closestStackOrientation === "vertical" ? event.key === "ArrowUp" : event.key === "ArrowLeft") ? -1 : (closestStackOrientation === "vertical" ? event.key === "ArrowDown" : event.key === "ArrowRight") ? 1 : 0;
212
+ const perpendicularDelta = (closestStackOrientation === "vertical" ? event.key === "ArrowLeft" : event.key === "ArrowUp") ? -1 : (closestStackOrientation === "vertical" ? event.key === "ArrowRight" : event.key === "ArrowDown") ? 1 : 0;
213
+ if (parallelDelta !== 0) {
214
+ const currentIndex = closestStackItems.indexOf(closestOwnedItem);
215
+ const nextIndex = currentIndex + parallelDelta;
216
+ let adjacentItem;
217
+ if (circularFocus) {
218
+ adjacentItem = closestStackItems[(nextIndex + closestStackItems.length) % closestStackItems.length];
219
+ } else {
220
+ if (nextIndex >= 0 && nextIndex < closestStackItems.length) {
221
+ adjacentItem = closestStackItems[nextIndex];
222
+ }
223
+ }
224
+ if (adjacentItem) {
225
+ event.preventDefault();
226
+ scrollIntoViewAndFocus(adjacentItem, closestStackOrientation);
227
+ }
228
+ }
229
+ if (perpendicularDelta !== 0) {
230
+ if (ancestorStack && ancestorOrientation !== closestStackOrientation) {
231
+ const siblingStacks = Array.from(ancestorStack.querySelectorAll(`[data-dx-stack-item="${ancestorStack.getAttribute("data-dx-stack")}"] [data-dx-stack]`));
232
+ const currentStackIndex = siblingStacks.indexOf(closestStack);
233
+ const nextStackIndex = currentStackIndex + perpendicularDelta;
234
+ let adjacentStack;
235
+ if (ancestorStack.getAttribute("data-dx-stack-circular-focus") === "true") {
236
+ adjacentStack = siblingStacks[(nextStackIndex + siblingStacks.length) % siblingStacks.length];
237
+ } else {
238
+ if (nextStackIndex >= 0 && nextStackIndex < siblingStacks.length) {
239
+ adjacentStack = siblingStacks[nextStackIndex];
240
+ }
241
+ }
242
+ const adjacentStackSelfItem = adjacentStack?.closest(`[data-dx-stack-item=${ancestorStack.getAttribute("data-dx-stack")}]`);
243
+ const adjacentStackItems = adjacentStack ? Array.from(adjacentStack.querySelectorAll(`[data-dx-stack-item="${adjacentStack.getAttribute("data-dx-stack")}"]`)) : [];
244
+ if (adjacentStack && adjacentStackItems.length > 0) {
245
+ let closestItem = adjacentStackItems[0];
246
+ const lastFocusedItem = adjacentStack.querySelector(`[data-dx-item-id="${adjacentStack.getAttribute("data-dx-last-focused-item") ?? "never"}"]`);
247
+ if (lastFocusedItem) {
248
+ closestItem = lastFocusedItem;
249
+ } else {
250
+ const ownedItemRect = closestOwnedItem.getBoundingClientRect();
251
+ const targetPosition = closestStackOrientation === "vertical" ? ownedItemRect.top : ownedItemRect.left;
252
+ let closestDistance = Infinity;
253
+ for (const item of adjacentStackItems) {
254
+ const itemRect = item.getBoundingClientRect();
255
+ const itemPosition = closestStackOrientation === "vertical" ? itemRect.top : itemRect.left;
256
+ const distance = Math.abs(itemPosition - targetPosition);
257
+ if (distance < closestDistance) {
258
+ closestDistance = distance;
259
+ closestItem = item;
260
+ }
261
+ if (closestDistance <= PERPENDICULAR_FOCUS_THRESHHOLD) {
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ event.preventDefault();
267
+ scrollIntoViewAndFocus(closestItem, closestStackOrientation);
268
+ } else if (adjacentStackSelfItem) {
269
+ event.preventDefault();
270
+ scrollIntoViewAndFocus(adjacentStackSelfItem, ancestorOrientation);
271
+ }
272
+ } else if (closestOwnedItem) {
273
+ const closestOwnedItemStack = closestOwnedItem.querySelector("[data-dx-stack]");
274
+ const closestOwnedItemStackItems = closestOwnedItemStack ? Array.from(closestOwnedItemStack.querySelectorAll(`[data-dx-stack-item="${closestOwnedItemStack.getAttribute("data-dx-stack")}"]`)) : [];
275
+ if (closestOwnedItemStackItems.length > 0) {
276
+ event.preventDefault();
277
+ scrollIntoViewAndFocus(closestOwnedItemStackItems[[
278
+ "ArrowUp",
279
+ "ArrowLeft"
280
+ ].includes(event.key) ? closestOwnedItemStackItems.length - 1 : 0], closestOwnedItemStack?.getAttribute("aria-orientation"));
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+ onKeyDown?.(event);
287
+ }, [
288
+ onKeyDown,
289
+ stackId,
290
+ circularFocus
291
+ ]);
292
+
293
+ // src/components/StackItem/StackItem.tsx
294
+ import { attachClosestEdge as attachClosestEdge2, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
295
+ import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
296
+ import { draggable, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
297
+ import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
298
+ import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
299
+ import { useFocusableGroup } from "@fluentui/react-tabster";
300
+ import { composeRefs as composeRefs2 } from "@radix-ui/react-compose-refs";
301
+ import React8, { forwardRef as forwardRef5, useCallback as useCallback2, useLayoutEffect as useLayoutEffect2, useMemo as useMemo2, useState as useState4 } from "react";
302
+ import { createPortal } from "react-dom";
303
+ import { ListItem as ListItem2 } from "@dxos/react-ui";
304
+ import { resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
305
+ import { mx as mx5 } from "@dxos/ui-theme";
306
+
307
+ // src/components/StackItem/StackItemContent.tsx
308
+ import React2, { forwardRef as forwardRef2, useMemo } from "react";
309
+ import { mx as mx2 } from "@dxos/ui-theme";
310
+ var StackItemContent = /* @__PURE__ */ forwardRef2(({ classNames, children, toolbar, statusbar, ...props }, forwardedRef) => {
311
+ const { size: stackItemSize } = useStack();
312
+ const { role } = useStackItem();
313
+ const style = useMemo(() => ({
314
+ gridTemplateRows: [
315
+ toolbar && role === "section" ? "calc(var(--dx-toolbar-size) - 1px)" : "var(--dx-toolbar-size)",
316
+ "1fr",
317
+ statusbar && "var(--dx-statusbar-size)"
318
+ ].filter(Boolean).join(" ")
319
+ }), [
320
+ toolbar,
321
+ statusbar
322
+ ]);
323
+ return /* @__PURE__ */ React2.createElement("div", {
324
+ ...props,
325
+ role: "none",
326
+ style,
327
+ className: mx2("group grid grid-cols-[100%] dx-density-coarse", stackItemSize === "contain" && "min-h-0 overflow-hidden", toolbar && role === "section" && "[&_.dx-toolbar]:sticky [&_.dx-toolbar]:z-[1] [&_.dx-toolbar]:top-0 [&_.dx-toolbar]:-mb-px [&_.dx-toolbar]:min-w-0", toolbar && "[&>.dx-toolbar]:relative [&>.dx-toolbar]:border-b [&>.dx-toolbar]:border-subdued-separator", classNames),
328
+ "data-popover-collision-boundary": true,
329
+ ref: forwardedRef
330
+ }, children);
331
+ });
332
+ StackItemContent.displayName = "StackItemContent";
333
+
334
+ // src/components/StackItem/StackItemDragHandle.tsx
335
+ import { Primitive } from "@radix-ui/react-primitive";
336
+ import { Slot } from "@radix-ui/react-slot";
337
+ import React3 from "react";
338
+ var StackItemDragHandle = ({ asChild, children }) => {
339
+ const { selfDragHandleRef } = useStackItem();
340
+ const Comp = asChild ? Slot : Primitive.div;
341
+ return /* @__PURE__ */ React3.createElement(Comp, {
342
+ ref: selfDragHandleRef,
343
+ role: "button"
344
+ }, children);
345
+ };
346
+
347
+ // src/components/StackItem/StackItemHeading.tsx
348
+ import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
349
+ import { Slot as Slot2 } from "@radix-ui/react-slot";
350
+ import React4, { forwardRef as forwardRef3 } from "react";
351
+ import { useAttention } from "@dxos/react-ui-attention";
352
+ import { mx as mx3 } from "@dxos/ui-theme";
353
+ var StackItemHeading = ({ children, classNames, asChild, separateOnScroll, role, ...props }) => {
354
+ const { orientation } = useStack();
355
+ const Comp = asChild ? Slot2 : Primitive2.div;
356
+ return /* @__PURE__ */ React4.createElement(Comp, {
357
+ ...props,
358
+ role: role ?? "heading",
359
+ className: mx3("flex items-center border-x-0! bg-header-surface", separateOnScroll ? 'border-transparent [[data-scroll-separator="true"]_&]:border-subdued-separator' : "border-subdued-separator", orientation === "horizontal" ? "h-(--dx-rail-size)" : "w-(--dx-rail-size) flex-col", orientation === "horizontal" ? "border-b" : "border-e", classNames)
360
+ }, children);
361
+ };
362
+ var StackItemHeadingStickyContent = ({ children }) => {
363
+ return /* @__PURE__ */ React4.createElement("div", {
364
+ role: "none",
365
+ className: "sticky top-0 bg-(--sticky-bg) p-1 w-full"
366
+ }, children);
367
+ };
368
+ var StackItemHeadingLabel = /* @__PURE__ */ forwardRef3(({ attendableId, related, classNames, ...props }, forwardedRef) => {
369
+ const { hasAttention, isAncestor, isRelated } = useAttention(attendableId);
370
+ return /* @__PURE__ */ React4.createElement("h1", {
371
+ ...props,
372
+ "data-attention": (related && isRelated || hasAttention || isAncestor).toString(),
373
+ className: mx3("px-1 min-w-0 w-0 grow truncate font-medium text-base-surface-text data-[attention=true]:text-accent-text self-center", classNames),
374
+ ref: forwardedRef
375
+ });
376
+ });
377
+
378
+ // src/components/StackItem/StackItemResizeHandle.tsx
379
+ import React5 from "react";
380
+ import { ResizeHandle } from "@dxos/react-ui-dnd";
381
+ var MIN_WIDTH = 20;
382
+ var MIN_HEIGHT = 3;
383
+ var StackItemResizeHandle = (_) => {
384
+ const { orientation } = useStack();
385
+ const { setSize, size } = useStackItem();
386
+ return /* @__PURE__ */ React5.createElement(ResizeHandle, {
387
+ side: orientation === "horizontal" ? "inline-end" : "block-end",
388
+ fallbackSize: DEFAULT_EXTRINSIC_SIZE,
389
+ minSize: orientation === "horizontal" ? MIN_WIDTH : MIN_HEIGHT,
390
+ size,
391
+ onSizeChange: setSize
392
+ });
393
+ };
394
+
395
+ // src/components/StackItem/StackItemSigil.tsx
396
+ import React7, { Fragment, forwardRef as forwardRef4, useState as useState3 } from "react";
397
+ import { keySymbols } from "@dxos/keyboard";
398
+ import { Button, DropdownMenu, Icon, toLocalizedString, useTranslation } from "@dxos/react-ui";
399
+ import { useAttention as useAttention2 } from "@dxos/react-ui-attention";
400
+ import { mx as mx4 } from "@dxos/ui-theme";
401
+ import { getHostPlatform } from "@dxos/util";
402
+ import { translationKey } from "#translations";
403
+
404
+ // src/components/StackItem/MenuSignifier.tsx
405
+ import React6 from "react";
406
+ var MenuSignifierHorizontal = () => /* @__PURE__ */ React6.createElement("svg", {
407
+ className: "absolute bottom-[7px]",
408
+ width: 20,
409
+ height: 2,
410
+ viewBox: "0 0 20 2",
411
+ stroke: "currentColor",
412
+ opacity: 0.5
413
+ }, /* @__PURE__ */ React6.createElement("line", {
414
+ x1: 0.5,
415
+ y1: 0.75,
416
+ x2: 19,
417
+ y2: 0.75,
418
+ strokeWidth: 1.25,
419
+ strokeLinecap: "round",
420
+ strokeDasharray: "6 20",
421
+ strokeDashoffset: "-6.5"
422
+ }));
423
+
424
+ // src/components/StackItem/StackItemSigil.tsx
425
+ var StackItemSigilButton = /* @__PURE__ */ forwardRef4(({ attendableId, classNames, related, isMenu = true, children, ...props }, forwardedRef) => {
426
+ const { hasAttention, isAncestor, isRelated } = useAttention2(attendableId);
427
+ const variant = related && isRelated || hasAttention || isAncestor ? "primary" : "ghost";
428
+ return /* @__PURE__ */ React7.createElement(Button, {
429
+ ...props,
430
+ variant,
431
+ classNames: [
432
+ "shrink-0 px-0 min-h-0 w-(--dx-rail-action) h-(--dx-rail-action) relative dx-app-no-drag",
433
+ classNames
434
+ ],
435
+ ref: forwardedRef
436
+ }, isMenu && /* @__PURE__ */ React7.createElement(MenuSignifierHorizontal, null), children);
437
+ });
438
+ var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAction, triggerLabel, attendableId, icon, related, children }, forwardedRef) => {
439
+ const { t } = useTranslation(translationKey);
440
+ const [optionsMenuOpen, setOptionsMenuOpen] = useState3(false);
441
+ const hasActions = actionGroups && actionGroups.length > 0;
442
+ const button = /* @__PURE__ */ React7.createElement(StackItemSigilButton, {
443
+ attendableId,
444
+ related,
445
+ isMenu: hasActions,
446
+ // TODO(wittjosiah): Better disabling of interactive styles when no action are available.
447
+ // Remove underscore icon when no actions are available?
448
+ classNames: !hasActions && "cursor-default"
449
+ }, /* @__PURE__ */ React7.createElement("span", {
450
+ className: "sr-only"
451
+ }, triggerLabel), /* @__PURE__ */ React7.createElement(Icon, {
452
+ icon
453
+ }));
454
+ if (!hasActions) {
455
+ return button;
456
+ }
457
+ return /* @__PURE__ */ React7.createElement(DropdownMenu.Root, {
458
+ open: optionsMenuOpen,
459
+ onOpenChange: setOptionsMenuOpen
460
+ }, /* @__PURE__ */ React7.createElement(DropdownMenu.Trigger, {
461
+ asChild: true,
462
+ ref: forwardedRef
463
+ }, button), /* @__PURE__ */ React7.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React7.createElement(DropdownMenu.Content, {
464
+ classNames: "z-[31]"
465
+ }, /* @__PURE__ */ React7.createElement(DropdownMenu.Viewport, null, actionGroups?.map((actions, index) => {
466
+ const separator = index > 0 ? /* @__PURE__ */ React7.createElement(DropdownMenu.Separator, null) : null;
467
+ return /* @__PURE__ */ React7.createElement(Fragment, {
468
+ key: index
469
+ }, separator, actions.map((action) => {
470
+ const shortcut = typeof action.properties.keyBinding === "string" ? action.properties.keyBinding : action.properties.keyBinding?.[getHostPlatform()];
471
+ const menuItemType = action.properties.menuItemType;
472
+ const Root = menuItemType === "toggle" ? DropdownMenu.CheckboxItem : DropdownMenu.Item;
473
+ return /* @__PURE__ */ React7.createElement(Root, {
474
+ key: action.id,
475
+ onClick: (event) => {
476
+ if (action.properties.disabled) {
477
+ return;
478
+ }
479
+ event.stopPropagation();
480
+ setOptionsMenuOpen(false);
481
+ onAction?.(action);
482
+ },
483
+ classNames: "gap-2",
484
+ disabled: action.properties.disabled,
485
+ checked: menuItemType === "toggle" ? action.properties.isChecked : void 0,
486
+ ...action.properties?.testId && {
487
+ "data-testid": action.properties.testId
488
+ }
489
+ }, /* @__PURE__ */ React7.createElement(Icon, {
490
+ icon: action.properties.icon ?? "ph--placeholder--regular",
491
+ size: 4
492
+ }), /* @__PURE__ */ React7.createElement("span", {
493
+ className: "grow truncate"
494
+ }, toLocalizedString(action.properties.label ?? "", t)), menuItemType === "toggle" && /* @__PURE__ */ React7.createElement(DropdownMenu.ItemIndicator, {
495
+ asChild: true
496
+ }, /* @__PURE__ */ React7.createElement(Icon, {
497
+ icon: "ph--check--regular",
498
+ size: 4
499
+ })), shortcut && /* @__PURE__ */ React7.createElement("span", {
500
+ className: mx4("shrink-0", "text-description")
501
+ }, keySymbols(shortcut).join("")));
502
+ }));
503
+ }), children), /* @__PURE__ */ React7.createElement(DropdownMenu.Arrow, null))));
504
+ });
505
+
506
+ // src/components/StackItem/StackItem.tsx
507
+ var DEFAULT_VERTICAL_SIZE = "min-content";
508
+ var DEFAULT_HORIZONTAL_SIZE = 50;
509
+ var DEFAULT_EXTRINSIC_SIZE = DEFAULT_HORIZONTAL_SIZE;
510
+ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ classNames, children, style, role, item, order, prevSiblingId, nextSiblingId, size: sizeProp, onSizeChange, disableRearrange, focusIndicatorVariant = "over-all", ...props }, forwardedRef) => {
511
+ const [itemElement, itemRef] = useState4(null);
512
+ const composedItemRef = composeRefs2(itemRef, forwardedRef);
513
+ const [selfDragHandleElement, selfDragHandleRef] = useState4(null);
514
+ const [closestEdge, setEdge] = useState4(null);
515
+ const [sourceId, setSourceId] = useState4(null);
516
+ const [dragState, setDragState] = useState4(idle);
517
+ const { orientation, rail, onRearrange, size: stackSize, stackId } = useStack();
518
+ const [size = orientation === "horizontal" ? DEFAULT_HORIZONTAL_SIZE : DEFAULT_VERTICAL_SIZE, setInternalSize] = useState4(sizeProp);
519
+ const Root = role ?? "div";
520
+ const setSize = useCallback2((nextSize, commit) => {
521
+ setInternalSize(nextSize);
522
+ if (commit) {
523
+ onSizeChange?.(nextSize);
524
+ }
525
+ }, [
526
+ onSizeChange
527
+ ]);
528
+ const type = orientation === "horizontal" ? "column" : "card";
529
+ useLayoutEffect2(() => {
530
+ if (!itemElement || !onRearrange || disableRearrange) {
531
+ return;
532
+ }
533
+ return combine2(draggable({
534
+ element: itemElement,
535
+ ...selfDragHandleElement && {
536
+ dragHandle: selfDragHandleElement
537
+ },
538
+ getInitialData: () => ({
539
+ id: item.id,
540
+ type
541
+ }),
542
+ onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
543
+ document.body.setAttribute("data-drag-preview", "true");
544
+ const offsetFn = preserveOffsetOnSource({
545
+ element: source.element,
546
+ input: location.current.input
547
+ });
548
+ const rect = source.element.getBoundingClientRect();
549
+ setCustomNativeDragPreview({
550
+ nativeSetDragImage,
551
+ getOffset: ({ container }) => {
552
+ return offsetFn({
553
+ container
554
+ });
555
+ },
556
+ render: ({ container }) => {
557
+ container.style.width = rect.width + "px";
558
+ setDragState({
559
+ type: "preview",
560
+ container,
561
+ item
562
+ });
563
+ return () => {
564
+ };
565
+ }
566
+ });
567
+ },
568
+ onDragStart: () => {
569
+ document.body.removeAttribute("data-drag-preview");
570
+ itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "active");
571
+ setDragState({
572
+ type: "is-dragging",
573
+ item
574
+ });
575
+ },
576
+ onDrop: () => {
577
+ itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "idle");
578
+ setDragState(idle);
579
+ }
580
+ }), dropTargetForElements2({
581
+ element: itemElement,
582
+ getData: ({ input, element }) => {
583
+ return attachClosestEdge2({
584
+ id: item.id,
585
+ type
586
+ }, {
587
+ input,
588
+ element,
589
+ allowedEdges: orientation === "horizontal" ? [
590
+ "left",
591
+ "right"
592
+ ] : [
593
+ "top",
594
+ "bottom"
595
+ ]
596
+ });
597
+ },
598
+ onDragEnter: ({ self, source }) => {
599
+ if (source.data.type === self.data.type) {
600
+ setEdge(extractClosestEdge2(self.data));
601
+ setSourceId(source.data.id);
602
+ }
603
+ },
604
+ onDrag: ({ self, source }) => {
605
+ if (source.data.type === self.data.type) {
606
+ setEdge(extractClosestEdge2(self.data));
607
+ setSourceId(source.data.id);
608
+ }
609
+ },
610
+ onDragLeave: () => {
611
+ setEdge(null);
612
+ setSourceId(null);
613
+ },
614
+ onDrop: ({ self, source }) => {
615
+ setEdge(null);
616
+ setSourceId(null);
617
+ if (source.data.type === self.data.type) {
618
+ onRearrange(source.data, self.data, extractClosestEdge2(self.data));
619
+ }
620
+ }
621
+ }));
622
+ }, [
623
+ orientation,
624
+ item,
625
+ onRearrange,
626
+ selfDragHandleElement,
627
+ itemElement
628
+ ]);
629
+ const focusableGroupAttrs = useFocusableGroup({
630
+ tabBehavior: "limited"
631
+ });
632
+ const shouldShowDropIndicator = () => {
633
+ if (!closestEdge || !sourceId) {
634
+ return false;
635
+ }
636
+ if (sourceId === item.id) {
637
+ return false;
638
+ }
639
+ const isTrailingEdgeOfPrevSibling = prevSiblingId !== void 0 && sourceId === prevSiblingId && (orientation === "horizontal" && closestEdge === "left" || orientation === "vertical" && closestEdge === "top");
640
+ if (isTrailingEdgeOfPrevSibling) {
641
+ return false;
642
+ }
643
+ const isLeadingEdgeOfNextSibling = nextSiblingId !== void 0 && sourceId === nextSiblingId && (orientation === "horizontal" && closestEdge === "right" || orientation === "vertical" && closestEdge === "bottom");
644
+ if (isLeadingEdgeOfNextSibling) {
645
+ return false;
646
+ }
647
+ return true;
648
+ };
649
+ const stackItemContextValue = useMemo2(() => ({
650
+ selfDragHandleRef,
651
+ size,
652
+ setSize,
653
+ state: dragState,
654
+ setState: setDragState,
655
+ role
656
+ }), [
657
+ selfDragHandleRef,
658
+ size,
659
+ setSize,
660
+ dragState,
661
+ setDragState,
662
+ role
663
+ ]);
664
+ return /* @__PURE__ */ React8.createElement(StackItemContext.Provider, {
665
+ value: stackItemContextValue
666
+ }, /* @__PURE__ */ React8.createElement(Root, {
667
+ ...props,
668
+ tabIndex: 0,
669
+ ...focusableGroupAttrs,
670
+ className: mx5("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-b border-subdued-separator", classNames),
671
+ "data-dx-stack-item": stackId,
672
+ "data-dx-item-id": item.id,
673
+ ...resizeAttributes,
674
+ style: {
675
+ ...stackSize !== "split" && sizeStyle(size, orientation),
676
+ ...Number.isFinite(order) && {
677
+ [orientation === "horizontal" ? "gridColumn" : "gridRow"]: `${order}`
678
+ },
679
+ ...style
680
+ },
681
+ ref: composedItemRef
682
+ }, children, shouldShowDropIndicator() && closestEdge && /* @__PURE__ */ React8.createElement(ListItem2.DropIndicator, {
683
+ lineInset: 8,
684
+ terminalInset: -8,
685
+ edge: closestEdge
686
+ })));
687
+ });
688
+ var StackItemDragPreview = ({ children }) => {
689
+ const { state } = useStackItem();
690
+ return state?.type === "preview" ? /* @__PURE__ */ createPortal(children({
691
+ item: state.item
692
+ }), state.container) : null;
693
+ };
694
+ var StackItem = {
695
+ Root: StackItemRoot,
696
+ Content: StackItemContent,
697
+ DragHandle: StackItemDragHandle,
698
+ DragPreview: StackItemDragPreview,
699
+ Heading: StackItemHeading,
700
+ HeadingLabel: StackItemHeadingLabel,
701
+ HeadingStickyContent: StackItemHeadingStickyContent,
702
+ ResizeHandle: StackItemResizeHandle,
703
+ Sigil: StackItemSigil,
704
+ SigilButton: StackItemSigilButton
705
+ };
38
706
  export {
39
- Card,
40
- CardDragPreview,
41
- CardStack,
42
- CardStackDragPreview,
43
707
  DEFAULT_EXTRINSIC_SIZE,
44
708
  DEFAULT_HORIZONTAL_SIZE,
45
709
  DEFAULT_VERTICAL_SIZE,
46
710
  Stack,
47
711
  StackContext,
48
712
  StackItem,
49
- StackItemDragPreview,
50
- autoScrollRootAttributes,
51
- cardChrome,
52
- cardDialogContent,
53
- cardDialogHeader,
54
- cardDialogOverflow,
55
- cardDialogPaddedOverflow,
56
- cardDialogSearchListRoot,
57
- cardHeading,
58
- cardNoSpacing,
59
- cardRoot,
60
- cardSpacing,
61
- cardStackContent,
62
- cardStackFooter,
63
- cardStackHeading,
64
- cardStackItem,
65
- cardStackRoot,
66
- cardText,
67
- labelSpacing,
68
713
  railGridHorizontal,
69
- railGridHorizontalContainFitContent,
70
- railGridVertical,
71
- railGridVerticalContainFitContent,
72
- translationKey,
73
- translations
714
+ railGridVertical
74
715
  };
75
716
  //# sourceMappingURL=index.mjs.map