@dxos/react-ui-stack 0.8.4-main.d05673bc65 → 0.8.4-main.dfabb4ec29
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.
- package/dist/lib/browser/index.mjs +129 -174
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +23 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +129 -174
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +25 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/Stack/Stack.d.ts +2 -7
- package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
- package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
- package/dist/types/src/components/StackContext.d.ts +1 -1
- package/dist/types/src/components/StackContext.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItem.d.ts +4 -4
- package/dist/types/src/components/StackItem/StackItem.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItem.stories.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemContent.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemDragHandle.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemHeading.d.ts +1 -1
- package/dist/types/src/components/StackItem/StackItemHeading.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts.map +1 -1
- package/dist/types/src/hooks/useStackDropForElements.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/playwright/stack-manager.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +8 -8
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -35
- package/src/components/Stack/Stack.stories.tsx +7 -9
- package/src/components/Stack/Stack.tsx +193 -206
- package/src/components/StackContext.tsx +1 -1
- package/src/components/StackItem/StackItem.stories.tsx +2 -2
- package/src/components/StackItem/StackItem.tsx +13 -15
- package/src/components/StackItem/StackItemContent.tsx +0 -1
- package/src/components/StackItem/StackItemHeading.tsx +3 -7
- package/src/components/StackItem/StackItemResizeHandle.tsx +0 -1
- package/src/components/StackItem/StackItemSigil.tsx +2 -2
- package/src/hooks/useStackDropForElements.ts +2 -2
- package/src/index.ts +0 -1
- package/src/translations.ts +8 -8
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/components/Stack/Stack.tsx
|
|
2
2
|
import { composeRefs } from "@radix-ui/react-compose-refs";
|
|
3
|
-
import React, { Children, forwardRef, useCallback, useEffect,
|
|
3
|
+
import React, { Children, forwardRef, useCallback, useEffect, useState as useState2 } from "react";
|
|
4
4
|
import { ListItem, useId } from "@dxos/react-ui";
|
|
5
5
|
import { mx } from "@dxos/ui-theme";
|
|
6
6
|
|
|
7
7
|
// src/hooks/useStackDropForElements.ts
|
|
8
|
-
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
9
|
-
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
10
8
|
import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
|
|
11
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
12
|
import { useLayoutEffect, useState } from "react";
|
|
13
13
|
var noop = () => {
|
|
14
14
|
};
|
|
@@ -95,11 +95,6 @@ var useStackItem = () => useContext(StackItemContext);
|
|
|
95
95
|
// src/components/Stack/Stack.tsx
|
|
96
96
|
var railGridHorizontal = "grid-rows-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]";
|
|
97
97
|
var railGridVertical = "grid-cols-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]";
|
|
98
|
-
var railGridHorizontalContainFitContent = "grid-rows-[[rail-start]_var(--dx-rail-size)_[content-start]_fit-content(calc(100%-var(--dx-rail-size)*2+2px))_[content-end]]";
|
|
99
|
-
var railGridVerticalContainFitContent = "grid-cols-[[rail-start]_var(--dx-rail-size)_[content-start]_fit-content(calc(100%-var(--dx-rail-size)*2+2px))_[content-end]]";
|
|
100
|
-
var autoScrollRootAttributes = {
|
|
101
|
-
"data-drag-autoscroll": "idle"
|
|
102
|
-
};
|
|
103
98
|
var PERPENDICULAR_FOCUS_THRESHHOLD = 128;
|
|
104
99
|
var scrollIntoViewAndFocus = (el, orientation) => {
|
|
105
100
|
el.scrollIntoView({
|
|
@@ -108,18 +103,14 @@ var scrollIntoViewAndFocus = (el, orientation) => {
|
|
|
108
103
|
});
|
|
109
104
|
return el.focus();
|
|
110
105
|
};
|
|
111
|
-
var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientation = "vertical", rail = true, size = "intrinsic",
|
|
112
|
-
const stackId = useId("stack",
|
|
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);
|
|
113
108
|
const [stackElement, stackRef] = useState2(null);
|
|
114
109
|
const [lastFocusedItem, setLastFocusedItem] = useState2();
|
|
115
110
|
const composedItemRef = composeRefs(stackRef, forwardedRef);
|
|
116
|
-
const
|
|
117
|
-
[orientation === "horizontal" ? "gridTemplateColumns" : "gridTemplateRows"]: size === "split" ? `repeat(${itemsCount}, 1fr)` : `repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
|
|
118
|
-
...style
|
|
119
|
-
};
|
|
120
|
-
const selfDroppable = !!(itemsCount < 1 && onRearrange && props.id);
|
|
111
|
+
const selfDroppable = !!(itemsCount < 1 && onRearrange && id);
|
|
121
112
|
const { dropping } = useStackDropForElements({
|
|
122
|
-
id
|
|
113
|
+
id,
|
|
123
114
|
element: getDropElement && stackElement ? getDropElement(stackElement) : stackElement,
|
|
124
115
|
scrollElement: stackElement,
|
|
125
116
|
selfDroppable,
|
|
@@ -150,116 +141,12 @@ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientati
|
|
|
150
141
|
setLastFocusedItem(closestStackItem?.getAttribute("data-dx-item-id") ?? void 0);
|
|
151
142
|
}
|
|
152
143
|
}
|
|
153
|
-
|
|
154
|
-
}, [
|
|
155
|
-
stackId,
|
|
156
|
-
props.onBlur
|
|
157
|
-
]);
|
|
158
|
-
const handleKeyDown = useCallback((event) => {
|
|
159
|
-
const target = event.target;
|
|
160
|
-
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)}"]`)) {
|
|
161
|
-
const closestOwnedItem = target.closest(`[data-dx-stack-item="${stackId}"]`);
|
|
162
|
-
const closestStack = target.closest("[data-dx-stack]");
|
|
163
|
-
const closestStackItems = Array.from(closestStack?.querySelectorAll(`[data-dx-stack-item="${stackId}"]`) ?? []);
|
|
164
|
-
const closestStackOrientation = closestStack?.getAttribute("aria-orientation");
|
|
165
|
-
const ancestorStack = closestStack?.parentElement?.closest("[data-dx-stack]");
|
|
166
|
-
if (closestOwnedItem && closestStack) {
|
|
167
|
-
const ancestorOrientation = ancestorStack?.getAttribute("aria-orientation");
|
|
168
|
-
const parallelDelta = (closestStackOrientation === "vertical" ? event.key === "ArrowUp" : event.key === "ArrowLeft") ? -1 : (closestStackOrientation === "vertical" ? event.key === "ArrowDown" : event.key === "ArrowRight") ? 1 : 0;
|
|
169
|
-
const perpendicularDelta = (closestStackOrientation === "vertical" ? event.key === "ArrowLeft" : event.key === "ArrowUp") ? -1 : (closestStackOrientation === "vertical" ? event.key === "ArrowRight" : event.key === "ArrowDown") ? 1 : 0;
|
|
170
|
-
if (parallelDelta !== 0) {
|
|
171
|
-
const currentIndex = closestStackItems.indexOf(closestOwnedItem);
|
|
172
|
-
const nextIndex = currentIndex + parallelDelta;
|
|
173
|
-
let adjacentItem;
|
|
174
|
-
if (circularFocus) {
|
|
175
|
-
adjacentItem = closestStackItems[(nextIndex + closestStackItems.length) % closestStackItems.length];
|
|
176
|
-
} else {
|
|
177
|
-
if (nextIndex >= 0 && nextIndex < closestStackItems.length) {
|
|
178
|
-
adjacentItem = closestStackItems[nextIndex];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (adjacentItem) {
|
|
182
|
-
event.preventDefault();
|
|
183
|
-
scrollIntoViewAndFocus(adjacentItem, closestStackOrientation);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (perpendicularDelta !== 0) {
|
|
187
|
-
if (ancestorStack && ancestorOrientation !== closestStackOrientation) {
|
|
188
|
-
const siblingStacks = Array.from(ancestorStack.querySelectorAll(`[data-dx-stack-item="${ancestorStack.getAttribute("data-dx-stack")}"] [data-dx-stack]`));
|
|
189
|
-
const currentStackIndex = siblingStacks.indexOf(closestStack);
|
|
190
|
-
const nextStackIndex = currentStackIndex + perpendicularDelta;
|
|
191
|
-
let adjacentStack;
|
|
192
|
-
if (ancestorStack.getAttribute("data-dx-stack-circular-focus") === "true") {
|
|
193
|
-
adjacentStack = siblingStacks[(nextStackIndex + siblingStacks.length) % siblingStacks.length];
|
|
194
|
-
} else {
|
|
195
|
-
if (nextStackIndex >= 0 && nextStackIndex < siblingStacks.length) {
|
|
196
|
-
adjacentStack = siblingStacks[nextStackIndex];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const adjacentStackSelfItem = adjacentStack?.closest(`[data-dx-stack-item=${ancestorStack.getAttribute("data-dx-stack")}]`);
|
|
200
|
-
const adjacentStackItems = adjacentStack ? Array.from(adjacentStack.querySelectorAll(`[data-dx-stack-item="${adjacentStack.getAttribute("data-dx-stack")}"]`)) : [];
|
|
201
|
-
if (adjacentStack && adjacentStackItems.length > 0) {
|
|
202
|
-
let closestItem = adjacentStackItems[0];
|
|
203
|
-
const lastFocusedItem2 = adjacentStack.querySelector(`[data-dx-item-id="${adjacentStack.getAttribute("data-dx-last-focused-item") ?? "never"}"]`);
|
|
204
|
-
if (lastFocusedItem2) {
|
|
205
|
-
closestItem = lastFocusedItem2;
|
|
206
|
-
} else {
|
|
207
|
-
const ownedItemRect = closestOwnedItem.getBoundingClientRect();
|
|
208
|
-
const targetPosition = closestStackOrientation === "vertical" ? ownedItemRect.top : ownedItemRect.left;
|
|
209
|
-
let closestDistance = Infinity;
|
|
210
|
-
for (const item of adjacentStackItems) {
|
|
211
|
-
const itemRect = item.getBoundingClientRect();
|
|
212
|
-
const itemPosition = closestStackOrientation === "vertical" ? itemRect.top : itemRect.left;
|
|
213
|
-
const distance = Math.abs(itemPosition - targetPosition);
|
|
214
|
-
if (distance < closestDistance) {
|
|
215
|
-
closestDistance = distance;
|
|
216
|
-
closestItem = item;
|
|
217
|
-
}
|
|
218
|
-
if (closestDistance <= PERPENDICULAR_FOCUS_THRESHHOLD) {
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
event.preventDefault();
|
|
224
|
-
scrollIntoViewAndFocus(closestItem, closestStackOrientation);
|
|
225
|
-
} else if (adjacentStackSelfItem) {
|
|
226
|
-
event.preventDefault();
|
|
227
|
-
scrollIntoViewAndFocus(adjacentStackSelfItem, ancestorOrientation);
|
|
228
|
-
}
|
|
229
|
-
} else if (closestOwnedItem) {
|
|
230
|
-
const closestOwnedItemStack = closestOwnedItem.querySelector("[data-dx-stack]");
|
|
231
|
-
const closestOwnedItemStackItems = closestOwnedItemStack ? Array.from(closestOwnedItemStack.querySelectorAll(`[data-dx-stack-item="${closestOwnedItemStack.getAttribute("data-dx-stack")}"]`)) : [];
|
|
232
|
-
if (closestOwnedItemStackItems.length > 0) {
|
|
233
|
-
event.preventDefault();
|
|
234
|
-
scrollIntoViewAndFocus(closestOwnedItemStackItems[[
|
|
235
|
-
"ArrowUp",
|
|
236
|
-
"ArrowLeft"
|
|
237
|
-
].includes(event.key) ? closestOwnedItemStackItems.length - 1 : 0], closestOwnedItemStack?.getAttribute("aria-orientation"));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
props.onKeyDown?.(event);
|
|
144
|
+
onBlur?.(event);
|
|
244
145
|
}, [
|
|
245
|
-
props.onKeyDown,
|
|
246
146
|
stackId,
|
|
247
|
-
|
|
248
|
-
]);
|
|
249
|
-
const gridClasses = useMemo(() => {
|
|
250
|
-
if (!rail) {
|
|
251
|
-
return orientation === "horizontal" ? "grid-rows-1 px-(--stack-gap)" : "grid-cols-1 py-(--stack-gap)";
|
|
252
|
-
}
|
|
253
|
-
if (orientation === "horizontal") {
|
|
254
|
-
return railGridHorizontal;
|
|
255
|
-
} else {
|
|
256
|
-
return railGridVertical;
|
|
257
|
-
}
|
|
258
|
-
}, [
|
|
259
|
-
rail,
|
|
260
|
-
orientation,
|
|
261
|
-
size
|
|
147
|
+
onBlur
|
|
262
148
|
]);
|
|
149
|
+
const handleKeyDown = useKeyDown(stackId, circularFocus, onKeyDown);
|
|
263
150
|
useEffect(() => {
|
|
264
151
|
if (!(stackElement && Number.isFinite(separatorOnScroll))) {
|
|
265
152
|
return;
|
|
@@ -280,27 +167,30 @@ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientati
|
|
|
280
167
|
]);
|
|
281
168
|
return /* @__PURE__ */ React.createElement(StackContext.Provider, {
|
|
282
169
|
value: {
|
|
170
|
+
stackId,
|
|
283
171
|
orientation,
|
|
284
172
|
rail,
|
|
285
173
|
size,
|
|
286
|
-
onRearrange
|
|
287
|
-
stackId
|
|
174
|
+
onRearrange
|
|
288
175
|
}
|
|
289
176
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
290
177
|
...props,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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,
|
|
294
187
|
"data-dx-stack": stackId,
|
|
295
188
|
"data-dx-stack-circular-focus": circularFocus,
|
|
296
189
|
"data-dx-last-focused-item": lastFocusedItem,
|
|
297
190
|
"data-rail": rail,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
ref: composedItemRef
|
|
301
|
-
...Number.isFinite(separatorOnScroll) && {
|
|
302
|
-
onScroll: handleScroll
|
|
303
|
-
}
|
|
191
|
+
onBlur: handleBlur,
|
|
192
|
+
onKeyDown: handleKeyDown,
|
|
193
|
+
ref: composedItemRef
|
|
304
194
|
}, children, selfDroppable && dropping && /* @__PURE__ */ React.createElement(ListItem.DropIndicator, {
|
|
305
195
|
lineInset: 8,
|
|
306
196
|
terminalInset: -8,
|
|
@@ -308,28 +198,119 @@ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientati
|
|
|
308
198
|
edge: orientation === "horizontal" ? "left" : "top"
|
|
309
199
|
})));
|
|
310
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
|
+
]);
|
|
311
292
|
|
|
312
293
|
// src/components/StackItem/StackItem.tsx
|
|
294
|
+
import { attachClosestEdge as attachClosestEdge2, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
313
295
|
import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
314
296
|
import { draggable, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
315
297
|
import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
|
|
316
298
|
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
317
|
-
import { attachClosestEdge as attachClosestEdge2, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
318
299
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
319
300
|
import { composeRefs as composeRefs2 } from "@radix-ui/react-compose-refs";
|
|
320
|
-
import React8, { forwardRef as forwardRef5, useCallback as useCallback2, useLayoutEffect as useLayoutEffect2, useMemo as
|
|
301
|
+
import React8, { forwardRef as forwardRef5, useCallback as useCallback2, useLayoutEffect as useLayoutEffect2, useMemo as useMemo2, useState as useState4 } from "react";
|
|
321
302
|
import { createPortal } from "react-dom";
|
|
322
303
|
import { ListItem as ListItem2 } from "@dxos/react-ui";
|
|
323
304
|
import { resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
|
|
324
305
|
import { mx as mx5 } from "@dxos/ui-theme";
|
|
325
306
|
|
|
326
307
|
// src/components/StackItem/StackItemContent.tsx
|
|
327
|
-
import React2, { forwardRef as forwardRef2, useMemo
|
|
308
|
+
import React2, { forwardRef as forwardRef2, useMemo } from "react";
|
|
328
309
|
import { mx as mx2 } from "@dxos/ui-theme";
|
|
329
310
|
var StackItemContent = /* @__PURE__ */ forwardRef2(({ classNames, children, toolbar, statusbar, ...props }, forwardedRef) => {
|
|
330
311
|
const { size: stackItemSize } = useStack();
|
|
331
312
|
const { role } = useStackItem();
|
|
332
|
-
const style =
|
|
313
|
+
const style = useMemo(() => ({
|
|
333
314
|
gridTemplateRows: [
|
|
334
315
|
toolbar && role === "section" ? "calc(var(--dx-toolbar-size) - 1px)" : "var(--dx-toolbar-size)",
|
|
335
316
|
"1fr",
|
|
@@ -341,7 +322,6 @@ var StackItemContent = /* @__PURE__ */ forwardRef2(({ classNames, children, tool
|
|
|
341
322
|
]);
|
|
342
323
|
return /* @__PURE__ */ React2.createElement("div", {
|
|
343
324
|
...props,
|
|
344
|
-
role: "none",
|
|
345
325
|
style,
|
|
346
326
|
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),
|
|
347
327
|
"data-popover-collision-boundary": true,
|
|
@@ -369,18 +349,17 @@ import { Slot as Slot2 } from "@radix-ui/react-slot";
|
|
|
369
349
|
import React4, { forwardRef as forwardRef3 } from "react";
|
|
370
350
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
371
351
|
import { mx as mx3 } from "@dxos/ui-theme";
|
|
372
|
-
var StackItemHeading = ({ children, classNames, asChild, separateOnScroll, ...props }) => {
|
|
352
|
+
var StackItemHeading = ({ children, classNames, asChild, separateOnScroll, role, ...props }) => {
|
|
373
353
|
const { orientation } = useStack();
|
|
374
354
|
const Comp = asChild ? Slot2 : Primitive2.div;
|
|
375
355
|
return /* @__PURE__ */ React4.createElement(Comp, {
|
|
376
|
-
role: "heading",
|
|
377
356
|
...props,
|
|
357
|
+
role: role ?? "heading",
|
|
378
358
|
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)
|
|
379
359
|
}, children);
|
|
380
360
|
};
|
|
381
361
|
var StackItemHeadingStickyContent = ({ children }) => {
|
|
382
362
|
return /* @__PURE__ */ React4.createElement("div", {
|
|
383
|
-
role: "none",
|
|
384
363
|
className: "sticky top-0 bg-(--sticky-bg) p-1 w-full"
|
|
385
364
|
}, children);
|
|
386
365
|
};
|
|
@@ -418,25 +397,7 @@ import { Button, DropdownMenu, Icon, toLocalizedString, useTranslation } from "@
|
|
|
418
397
|
import { useAttention as useAttention2 } from "@dxos/react-ui-attention";
|
|
419
398
|
import { mx as mx4 } from "@dxos/ui-theme";
|
|
420
399
|
import { getHostPlatform } from "@dxos/util";
|
|
421
|
-
|
|
422
|
-
// src/translations.ts
|
|
423
|
-
var translationKey = "@dxos/react-ui-stack";
|
|
424
|
-
var translations = [
|
|
425
|
-
{
|
|
426
|
-
"en-US": {
|
|
427
|
-
[translationKey]: {
|
|
428
|
-
"resize label": "Drag to resize",
|
|
429
|
-
"drag handle label": "Drag to rearrange",
|
|
430
|
-
"pin start label": "Pin to the left sidebar",
|
|
431
|
-
"pin end label": "Pin to the right sidebar",
|
|
432
|
-
"increment start label": "Move to the left",
|
|
433
|
-
"increment end label": "Move to the right",
|
|
434
|
-
"close label": "Close",
|
|
435
|
-
"minify label": "Minify"
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
];
|
|
400
|
+
import { translationKey } from "#translations";
|
|
440
401
|
|
|
441
402
|
// src/components/StackItem/MenuSignifier.tsx
|
|
442
403
|
import React6 from "react";
|
|
@@ -486,8 +447,7 @@ var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAct
|
|
|
486
447
|
}, /* @__PURE__ */ React7.createElement("span", {
|
|
487
448
|
className: "sr-only"
|
|
488
449
|
}, triggerLabel), /* @__PURE__ */ React7.createElement(Icon, {
|
|
489
|
-
icon
|
|
490
|
-
size: 5
|
|
450
|
+
icon
|
|
491
451
|
}));
|
|
492
452
|
if (!hasActions) {
|
|
493
453
|
return button;
|
|
@@ -542,10 +502,10 @@ var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAct
|
|
|
542
502
|
});
|
|
543
503
|
|
|
544
504
|
// src/components/StackItem/StackItem.tsx
|
|
545
|
-
var DEFAULT_HORIZONTAL_SIZE = 48;
|
|
546
505
|
var DEFAULT_VERTICAL_SIZE = "min-content";
|
|
506
|
+
var DEFAULT_HORIZONTAL_SIZE = 50;
|
|
547
507
|
var DEFAULT_EXTRINSIC_SIZE = DEFAULT_HORIZONTAL_SIZE;
|
|
548
|
-
var StackItemRoot = /* @__PURE__ */ forwardRef5(({
|
|
508
|
+
var StackItemRoot = /* @__PURE__ */ forwardRef5(({ classNames, children, style, role, item, order, prevSiblingId, nextSiblingId, size: sizeProp, onSizeChange, disableRearrange, focusIndicatorVariant = "over-all", ...props }, forwardedRef) => {
|
|
549
509
|
const [itemElement, itemRef] = useState4(null);
|
|
550
510
|
const composedItemRef = composeRefs2(itemRef, forwardedRef);
|
|
551
511
|
const [selfDragHandleElement, selfDragHandleRef] = useState4(null);
|
|
@@ -553,7 +513,7 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
|
|
|
553
513
|
const [sourceId, setSourceId] = useState4(null);
|
|
554
514
|
const [dragState, setDragState] = useState4(idle);
|
|
555
515
|
const { orientation, rail, onRearrange, size: stackSize, stackId } = useStack();
|
|
556
|
-
const [size = orientation === "horizontal" ? DEFAULT_HORIZONTAL_SIZE : DEFAULT_VERTICAL_SIZE, setInternalSize] = useState4(
|
|
516
|
+
const [size = orientation === "horizontal" ? DEFAULT_HORIZONTAL_SIZE : DEFAULT_VERTICAL_SIZE, setInternalSize] = useState4(sizeProp);
|
|
557
517
|
const Root = role ?? "div";
|
|
558
518
|
const setSize = useCallback2((nextSize, commit) => {
|
|
559
519
|
setInternalSize(nextSize);
|
|
@@ -607,7 +567,7 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
|
|
|
607
567
|
document.body.removeAttribute("data-drag-preview");
|
|
608
568
|
itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "active");
|
|
609
569
|
setDragState({
|
|
610
|
-
type: "
|
|
570
|
+
type: "is-dragging",
|
|
611
571
|
item
|
|
612
572
|
});
|
|
613
573
|
},
|
|
@@ -684,7 +644,7 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
|
|
|
684
644
|
}
|
|
685
645
|
return true;
|
|
686
646
|
};
|
|
687
|
-
const stackItemContextValue =
|
|
647
|
+
const stackItemContextValue = useMemo2(() => ({
|
|
688
648
|
selfDragHandleRef,
|
|
689
649
|
size,
|
|
690
650
|
setSize,
|
|
@@ -748,12 +708,7 @@ export {
|
|
|
748
708
|
Stack,
|
|
749
709
|
StackContext,
|
|
750
710
|
StackItem,
|
|
751
|
-
autoScrollRootAttributes,
|
|
752
711
|
railGridHorizontal,
|
|
753
|
-
|
|
754
|
-
railGridVertical,
|
|
755
|
-
railGridVerticalContainFitContent,
|
|
756
|
-
translationKey,
|
|
757
|
-
translations
|
|
712
|
+
railGridVertical
|
|
758
713
|
};
|
|
759
714
|
//# sourceMappingURL=index.mjs.map
|