@dxos/react-ui-stack 0.7.5-main.9d2a38b → 0.7.5-main.ff8607b

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.
@@ -1,5 +1,7 @@
1
1
  // packages/ui/react-ui-stack/src/components/Stack.tsx
2
+ import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
2
3
  import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
4
+ import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
3
5
  import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
4
6
  import { useArrowNavigationGroup } from "@fluentui/react-tabster";
5
7
  import { composeRefs } from "@radix-ui/react-compose-refs";
@@ -27,6 +29,9 @@ var useStackItem = () => useContext(StackItemContext);
27
29
  // packages/ui/react-ui-stack/src/components/Stack.tsx
28
30
  var railGridHorizontal = "grid-rows-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]";
29
31
  var railGridVertical = "grid-cols-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]";
32
+ var autoScrollRootAttributes = {
33
+ "data-drag-autoscroll": "idle"
34
+ };
30
35
  var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientation = "vertical", rail = true, size = "intrinsic", onRearrange, itemsCount = Children.count(children), ...props }, forwardedRef) => {
31
36
  const [stackElement, stackRef] = useState(null);
32
37
  const composedItemRef = composeRefs(stackRef, forwardedRef);
@@ -44,7 +49,7 @@ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientati
44
49
  return;
45
50
  }
46
51
  const acceptSourceType = orientation === "horizontal" ? "column" : "card";
47
- return dropTargetForElements({
52
+ return combine(dropTargetForElements({
48
53
  element: stackElement,
49
54
  getData: ({ input, element }) => {
50
55
  return attachClosestEdge({
@@ -75,10 +80,14 @@ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientati
75
80
  onRearrange(source.data, self.data, extractClosestEdge(self.data));
76
81
  }
77
82
  }
78
- });
83
+ }), autoScrollForElements({
84
+ element: stackElement,
85
+ getAllowedAxis: () => orientation
86
+ }));
79
87
  }, [
80
88
  stackElement,
81
- selfDroppable
89
+ selfDroppable,
90
+ orientation
82
91
  ]);
83
92
  return /* @__PURE__ */ React.createElement(StackContext.Provider, {
84
93
  value: {
@@ -90,20 +99,24 @@ var Stack = /* @__PURE__ */ forwardRef(({ children, classNames, style, orientati
90
99
  }, /* @__PURE__ */ React.createElement("div", {
91
100
  ...props,
92
101
  ...arrowNavigationGroup,
93
- className: mx("grid relative", rail ? orientation === "horizontal" ? railGridHorizontal : railGridVertical : orientation === "horizontal" ? "grid-rows-1" : "grid-cols-1", size === "contain" && (orientation === "horizontal" ? "overflow-x-auto min-bs-0 bs-full max-bs-full" : "overflow-y-auto min-is-0 is-full max-is-full"), classNames),
102
+ className: mx("grid relative", rail ? orientation === "horizontal" ? railGridHorizontal : railGridVertical : orientation === "horizontal" ? "grid-rows-1 pli-1" : "grid-cols-1 plb-1", size === "contain" && (orientation === "horizontal" ? "overflow-x-auto min-bs-0 bs-full max-bs-full" : "overflow-y-auto min-is-0 is-full max-is-full"), classNames),
103
+ "data-rail": rail,
94
104
  "aria-orientation": orientation,
95
105
  style: styles,
96
106
  ref: composedItemRef
97
107
  }, children, selfDroppable && dropping && /* @__PURE__ */ React.createElement(ListItem.DropIndicator, {
108
+ lineInset: 8,
109
+ terminalInset: -8,
110
+ gap: -8,
98
111
  edge: orientation === "horizontal" ? "left" : "top"
99
112
  })));
100
113
  });
101
114
 
102
115
  // packages/ui/react-ui-stack/src/components/StackItem.tsx
103
- import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
116
+ import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
104
117
  import { draggable as draggable2, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
105
- import { disableNativeDragPreview as disableNativeDragPreview2 } from "@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview";
106
- import { preventUnhandled as preventUnhandled2 } from "@atlaskit/pragmatic-drag-and-drop/prevent-unhandled";
118
+ import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source";
119
+ import { scrollJustEnoughIntoView } from "@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view";
107
120
  import { attachClosestEdge as attachClosestEdge2, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
108
121
  import { useFocusableGroup as useFocusableGroup2 } from "@fluentui/react-tabster";
109
122
  import { composeRefs as composeRefs2 } from "@radix-ui/react-compose-refs";
@@ -162,7 +175,7 @@ var StackItemHeading = ({ children, classNames, ...props }) => {
162
175
  ...props,
163
176
  tabIndex: 0,
164
177
  ...focusableGroupAttrs,
165
- className: mx3("flex items-center ch-focus-ring-inset-over-all relative !border-is-0", orientation === "horizontal" ? "bs-[--rail-size]" : "is-[--rail-size] flex-col", classNames)
178
+ className: mx3("flex items-center dx-focus-ring-inset-over-all relative !border-is-0", orientation === "horizontal" ? "bs-[--rail-size]" : "is-[--rail-size] flex-col", classNames)
166
179
  }, children);
167
180
  };
168
181
  var StackItemHeadingLabel = /* @__PURE__ */ forwardRef3(({ attendableId, related, classNames, ...props }, forwardedRef) => {
@@ -182,7 +195,8 @@ import { preventUnhandled } from "@atlaskit/pragmatic-drag-and-drop/prevent-unha
182
195
  import React5, { useLayoutEffect as useLayoutEffect2, useRef } from "react";
183
196
  import { mx as mx4 } from "@dxos/react-ui-theme";
184
197
  var REM = parseFloat(getComputedStyle(document.documentElement).fontSize);
185
- var MIN_SIZE = 20;
198
+ var MIN_WIDTH = 20;
199
+ var MIN_HEIGHT = 3;
186
200
  var measureStackItem = (element) => {
187
201
  const stackItemElement = element.closest("[data-dx-stack-item]");
188
202
  return stackItemElement?.getBoundingClientRect() ?? {
@@ -191,7 +205,7 @@ var measureStackItem = (element) => {
191
205
  };
192
206
  };
193
207
  var getNextSize = (startSize, location, client) => {
194
- return Math.max(MIN_SIZE, startSize + (location.current.input[client] - location.initial.input[client]) / REM);
208
+ return Math.max(client === "clientX" ? MIN_WIDTH : MIN_HEIGHT, startSize + (location.current.input[client] - location.initial.input[client]) / REM);
195
209
  };
196
210
  var StackItemResizeHandle = () => {
197
211
  const { orientation } = useStack();
@@ -232,18 +246,20 @@ var StackItemResizeHandle = () => {
232
246
  }, []);
233
247
  return /* @__PURE__ */ React5.createElement("button", {
234
248
  ref: buttonRef,
235
- className: mx4(orientation === "horizontal" ? "cursor-col-resize" : "cursor-row-resize", "group absolute is-3 bs-full inline-end-[-1px] !border-lb-0", "before:transition-opacity before:duration-100 before:ease-in-out before:opacity-0 hover:before:opacity-100 focus-visible:before:opacity-100 active:before:opacity-100", "before:absolute before:block before:inset-block-0 before:inline-end-0 before:is-1 before:bg-accentFocusIndicator")
249
+ className: mx4("group absolute", orientation === "horizontal" ? "cursor-col-resize is-3 bs-full inline-end-[-1px] !border-lb-0 before:inset-block-0 before:inline-end-0 before:is-1" : "cursor-row-resize bs-3 is-full block-end-[-1px] !border-li-0 before:inset-inline-0 before:block-end-0 before:bs-1", "before:transition-opacity before:duration-100 before:ease-in-out before:opacity-0 hover:before:opacity-100 focus-visible:before:opacity-100 active:before:opacity-100", "before:absolute before:block before:bg-accentFocusIndicator")
236
250
  }, /* @__PURE__ */ React5.createElement("div", {
237
251
  role: "none",
238
- className: "absolute block-start-0 inline-end-[1px] bs-[--rail-size] flex items-center group-hover:opacity-0 group-focus-visible:opacity-0 group-active:opacity-0"
239
- }, /* @__PURE__ */ React5.createElement(DragHandleSignifier, null)));
252
+ className: mx4("absolute flex items-center group-hover:opacity-0 group-focus-visible:opacity-0 group-active:opacity-0", orientation === "horizontal" ? "block-start-0 inline-end-px bs-[--rail-size]" : "inline-start-0 block-end-px is-[--rail-size] flex justify-center")
253
+ }, /* @__PURE__ */ React5.createElement(DragHandleSignifier, {
254
+ orientation
255
+ })));
240
256
  };
241
- var DragHandleSignifier = () => {
257
+ var DragHandleSignifier = ({ orientation }) => {
242
258
  return /* @__PURE__ */ React5.createElement("svg", {
243
259
  xmlns: "http://www.w3.org/2000/svg",
244
260
  viewBox: "0 0 256 256",
245
261
  fill: "currentColor",
246
- className: "shrink-0 bs-[1em] is-[1em] text-unAccent"
262
+ className: mx4("shrink-0 bs-[1em] is-[1em] text-unAccent", orientation === "vertical" && "rotate-90")
247
263
  }, /* @__PURE__ */ React5.createElement("path", {
248
264
  d: "M256,64c-8.8,0-16-7.2-16-16s7.2-16,16-16v32Z"
249
265
  }), /* @__PURE__ */ React5.createElement("path", {
@@ -258,7 +274,7 @@ var DragHandleSignifier = () => {
258
274
  // packages/ui/react-ui-stack/src/components/StackItemSigil.tsx
259
275
  import React7, { Fragment, forwardRef as forwardRef4, useRef as useRef2, useState as useState2 } from "react";
260
276
  import { keySymbols } from "@dxos/keyboard";
261
- import { Button, DropdownMenu, Icon, toLocalizedString, Tooltip, useTranslation } from "@dxos/react-ui";
277
+ import { Button, DropdownMenu, Icon, toLocalizedString, useTranslation } from "@dxos/react-ui";
262
278
  import { useAttention as useAttention2 } from "@dxos/react-ui-attention";
263
279
  import { descriptionText, mx as mx5 } from "@dxos/react-ui-theme";
264
280
  import { getHostPlatform } from "@dxos/util";
@@ -309,7 +325,7 @@ var StackItemSigilButton = /* @__PURE__ */ forwardRef4(({ attendableId, classNam
309
325
  ...props,
310
326
  variant,
311
327
  classNames: [
312
- "shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative",
328
+ "shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative app-no-drag",
313
329
  classNames
314
330
  ],
315
331
  ref: forwardedRef
@@ -319,18 +335,23 @@ var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAct
319
335
  const { t } = useTranslation(translationKey);
320
336
  const suppressNextTooltip = useRef2(false);
321
337
  const [optionsMenuOpen, setOptionsMenuOpen] = useState2(false);
322
- const [triggerTooltipOpen, setTriggerTooltipOpen] = useState2(false);
323
- return /* @__PURE__ */ React7.createElement(Tooltip.Root, {
324
- open: triggerTooltipOpen,
325
- onOpenChange: (nextOpen) => {
326
- if (suppressNextTooltip.current) {
327
- setTriggerTooltipOpen(false);
328
- suppressNextTooltip.current = false;
329
- } else {
330
- setTriggerTooltipOpen(nextOpen);
331
- }
332
- }
333
- }, /* @__PURE__ */ React7.createElement(DropdownMenu.Root, {
338
+ const hasActions = actionGroups && actionGroups.length > 0;
339
+ const button = /* @__PURE__ */ React7.createElement(StackItemSigilButton, {
340
+ attendableId,
341
+ related,
342
+ // TODO(wittjosiah): Better disabling of interactive styles when no action are available.
343
+ // Remove underscore icon when no actions are available?
344
+ classNames: !hasActions && "cursor-default"
345
+ }, /* @__PURE__ */ React7.createElement("span", {
346
+ className: "sr-only"
347
+ }, triggerLabel), /* @__PURE__ */ React7.createElement(Icon, {
348
+ icon,
349
+ size: 5
350
+ }));
351
+ if (!hasActions) {
352
+ return button;
353
+ }
354
+ return /* @__PURE__ */ React7.createElement(DropdownMenu.Root, {
334
355
  open: optionsMenuOpen,
335
356
  onOpenChange: (nextOpen) => {
336
357
  if (!nextOpen) {
@@ -338,20 +359,10 @@ var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAct
338
359
  }
339
360
  return setOptionsMenuOpen(nextOpen);
340
361
  }
341
- }, /* @__PURE__ */ React7.createElement(Tooltip.Trigger, {
342
- asChild: true
343
362
  }, /* @__PURE__ */ React7.createElement(DropdownMenu.Trigger, {
344
363
  asChild: true,
345
364
  ref: forwardedRef
346
- }, /* @__PURE__ */ React7.createElement(StackItemSigilButton, {
347
- attendableId,
348
- related
349
- }, /* @__PURE__ */ React7.createElement("span", {
350
- className: "sr-only"
351
- }, triggerLabel), /* @__PURE__ */ React7.createElement(Icon, {
352
- icon,
353
- size: 5
354
- })))), /* @__PURE__ */ React7.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React7.createElement(DropdownMenu.Content, {
365
+ }, button), /* @__PURE__ */ React7.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React7.createElement(DropdownMenu.Content, {
355
366
  classNames: "z-[31]"
356
367
  }, /* @__PURE__ */ React7.createElement(DropdownMenu.Viewport, null, actionGroups?.map((actions, index) => {
357
368
  const separator = index > 0 ? /* @__PURE__ */ React7.createElement(DropdownMenu.Separator, null) : null;
@@ -392,16 +403,14 @@ var StackItemSigil = /* @__PURE__ */ forwardRef4(({ actions: actionGroups, onAct
392
403
  className: mx5("shrink-0", descriptionText)
393
404
  }, keySymbols(shortcut).join("")));
394
405
  }));
395
- }), children), /* @__PURE__ */ React7.createElement(DropdownMenu.Arrow, null)))), /* @__PURE__ */ React7.createElement(Tooltip.Portal, null, /* @__PURE__ */ React7.createElement(Tooltip.Content, {
396
- side: "bottom"
397
- }, triggerLabel, /* @__PURE__ */ React7.createElement(Tooltip.Arrow, null))));
406
+ }), children), /* @__PURE__ */ React7.createElement(DropdownMenu.Arrow, null))));
398
407
  });
399
408
 
400
409
  // packages/ui/react-ui-stack/src/components/StackItem.tsx
401
410
  var DEFAULT_HORIZONTAL_SIZE = 44;
402
411
  var DEFAULT_VERTICAL_SIZE = "min-content";
403
412
  var DEFAULT_EXTRINSIC_SIZE = DEFAULT_HORIZONTAL_SIZE;
404
- var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, size: propsSize, onSizeChange, role, order, style, ...props }, forwardedRef) => {
413
+ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, size: propsSize, onSizeChange, role, order, style, disableRearrange, focusIndicatorVariant = "over-all", ...props }, forwardedRef) => {
405
414
  const [itemElement, itemRef] = useState3(null);
406
415
  const [selfDragHandleElement, selfDragHandleRef] = useState3(null);
407
416
  const [closestEdge, setEdge] = useState3(null);
@@ -419,10 +428,10 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
419
428
  ]);
420
429
  const type = orientation === "horizontal" ? "column" : "card";
421
430
  useLayoutEffect3(() => {
422
- if (!itemElement || !onRearrange) {
431
+ if (!itemElement || !onRearrange || disableRearrange) {
423
432
  return;
424
433
  }
425
- return combine(draggable2({
434
+ return combine2(draggable2({
426
435
  element: itemElement,
427
436
  ...selfDragHandleElement && {
428
437
  dragHandle: selfDragHandleElement
@@ -431,12 +440,25 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
431
440
  id: item.id,
432
441
  type
433
442
  }),
434
- // TODO(thure): tabster focus honeypots are causing the preview to render with the wrong dimensions; what do?
435
- onGenerateDragPreview: ({ nativeSetDragImage }) => {
436
- disableNativeDragPreview2({
437
- nativeSetDragImage
443
+ onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
444
+ document.body.setAttribute("data-drag-preview", "true");
445
+ scrollJustEnoughIntoView({
446
+ element: source.element
438
447
  });
439
- preventUnhandled2.start();
448
+ const { x, y } = preserveOffsetOnSource({
449
+ element: source.element,
450
+ input: location.current.input
451
+ })({
452
+ container: source.element.offsetParent ?? document.body
453
+ });
454
+ nativeSetDragImage?.(source.element, x, y);
455
+ },
456
+ onDragStart: () => {
457
+ document.body.removeAttribute("data-drag-preview");
458
+ itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "active");
459
+ },
460
+ onDrop: () => {
461
+ itemElement?.closest("[data-drag-autoscroll]")?.setAttribute("data-drag-autoscroll", "idle");
440
462
  }
441
463
  }), dropTargetForElements2({
442
464
  element: itemElement,
@@ -494,7 +516,7 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
494
516
  ...props,
495
517
  tabIndex: 0,
496
518
  ...focusGroupAttrs,
497
- className: mx6("group/stack-item grid relative ch-focus-ring-inset-over-all", size === "min-content" && (orientation === "horizontal" ? "is-min" : "bs-min"), orientation === "horizontal" ? "grid-rows-subgrid" : "grid-cols-subgrid", rail && (orientation === "horizontal" ? "row-span-2" : "col-span-2"), classNames),
519
+ className: mx6("group/stack-item grid relative", focusIndicatorVariant === "over-all" ? "dx-focus-ring-inset-over-all" : orientation === "horizontal" ? "dx-focus-ring-group-x" : "dx-focus-ring-group-y", size === "min-content" && (orientation === "horizontal" ? "is-min" : "bs-min"), orientation === "horizontal" ? "grid-rows-subgrid" : "grid-cols-subgrid", rail && (orientation === "horizontal" ? "row-span-2" : "col-span-2"), classNames),
498
520
  "data-dx-stack-item": true,
499
521
  style: {
500
522
  ...size !== "min-content" && {
@@ -507,6 +529,8 @@ var StackItemRoot = /* @__PURE__ */ forwardRef5(({ item, children, classNames, s
507
529
  },
508
530
  ref: composedItemRef
509
531
  }, children, closestEdge && /* @__PURE__ */ React8.createElement(ListItem2.DropIndicator, {
532
+ lineInset: 8,
533
+ terminalInset: -8,
510
534
  edge: closestEdge
511
535
  })));
512
536
  });
@@ -523,9 +547,9 @@ var StackItem = {
523
547
 
524
548
  // packages/ui/react-ui-stack/src/components/LayoutControls.tsx
525
549
  import React9, { forwardRef as forwardRef6 } from "react";
526
- import { Button as Button2, ButtonGroup, Icon as Icon2, Tooltip as Tooltip2, useTranslation as useTranslation2 } from "@dxos/react-ui";
550
+ import { Button as Button2, ButtonGroup, Icon as Icon2, Tooltip, useTranslation as useTranslation2 } from "@dxos/react-ui";
527
551
  var LayoutControl = ({ icon, label, ...props }) => {
528
- return /* @__PURE__ */ React9.createElement(Tooltip2.Root, null, /* @__PURE__ */ React9.createElement(Tooltip2.Trigger, {
552
+ return /* @__PURE__ */ React9.createElement(Tooltip.Root, null, /* @__PURE__ */ React9.createElement(Tooltip.Trigger, {
529
553
  asChild: true
530
554
  }, /* @__PURE__ */ React9.createElement(Button2, {
531
555
  variant: "ghost",
@@ -534,7 +558,7 @@ var LayoutControl = ({ icon, label, ...props }) => {
534
558
  className: "sr-only"
535
559
  }, label), /* @__PURE__ */ React9.createElement(Icon2, {
536
560
  icon
537
- }))), /* @__PURE__ */ React9.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React9.createElement(Tooltip2.Content, {
561
+ }))), /* @__PURE__ */ React9.createElement(Tooltip.Portal, null, /* @__PURE__ */ React9.createElement(Tooltip.Content, {
538
562
  side: "bottom"
539
563
  }, label)));
540
564
  };
@@ -595,6 +619,7 @@ export {
595
619
  StackContext,
596
620
  StackItem,
597
621
  StackItemContext,
622
+ autoScrollRootAttributes,
598
623
  railGridHorizontal,
599
624
  railGridVertical,
600
625
  translations_default as translations,