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