@dxos/react-ui-list 0.8.4-main.c85a9c8dae → 0.8.4-main.d05673bc65

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.
@@ -74,6 +74,7 @@ import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-d
74
74
  import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
75
75
  import { attachClosestEdge, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
76
76
  import { createContext as createContext4 } from "@radix-ui/react-context";
77
+ import { Slot } from "@radix-ui/react-slot";
77
78
  import React4, { useEffect as useEffect2, useRef, useState as useState2 } from "react";
78
79
  import { createPortal } from "react-dom";
79
80
  import { invariant } from "@dxos/invariant";
@@ -160,7 +161,8 @@ var stateStyles = {
160
161
  var defaultContext = {};
161
162
  var LIST_ITEM_NAME = "ListItem";
162
163
  var [ListItemProvider, useListItemContext] = createContext4(LIST_ITEM_NAME, defaultContext);
163
- var ListItem = ({ children, classNames, item, ...props }) => {
164
+ var ListItem = ({ children, classNames, item, asChild, selected, ...props }) => {
165
+ const Comp = asChild ? Slot : "div";
164
166
  const { isItem, readonly, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
165
167
  const ref = useRef(null);
166
168
  const dragHandleRef = useRef(null);
@@ -169,7 +171,7 @@ var ListItem = ({ children, classNames, item, ...props }) => {
169
171
  const element = ref.current;
170
172
  invariant(element, void 0, {
171
173
  F: __dxlog_file,
172
- L: 98,
174
+ L: 109,
173
175
  S: void 0,
174
176
  A: [
175
177
  "element",
@@ -278,40 +280,41 @@ var ListItem = ({ children, classNames, item, ...props }) => {
278
280
  return /* @__PURE__ */ React4.createElement(ListItemProvider, {
279
281
  item,
280
282
  dragHandleRef
281
- }, /* @__PURE__ */ React4.createElement("div", {
283
+ }, /* @__PURE__ */ React4.createElement(Comp, {
282
284
  ref,
283
285
  role: "listitem",
284
- className: mx3("flex relative", classNames, stateStyles[state.type]),
286
+ "aria-selected": selected,
287
+ className: mx3("relative dx-selected", classNames, stateStyles[state.type]),
285
288
  ...props
286
- }, children, state.type === "w-dragging-over" && state.closestEdge && /* @__PURE__ */ React4.createElement(NaturalListItem.DropIndicator, {
289
+ }, children), state.type === "w-dragging-over" && state.closestEdge && /* @__PURE__ */ React4.createElement(NaturalListItem.DropIndicator, {
287
290
  edge: state.closestEdge
288
- })));
291
+ }));
289
292
  };
290
- var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, icon = "ph--x--regular", label, ...props }) => {
291
- const { state } = useListContext("DELETE_BUTTON");
293
+ var ListItemIconButton = ({ autoHide = true, iconOnly = true, variant = "ghost", classNames, disabled, ...props }) => {
294
+ const { state } = useListContext("ITEM_BUTTON");
292
295
  const isDisabled = state.type !== "idle" || disabled;
293
- const { t } = useTranslation(osTranslations);
294
296
  return /* @__PURE__ */ React4.createElement(IconButton, {
295
- iconOnly: true,
296
- variant: "ghost",
297
297
  ...props,
298
- icon,
299
298
  disabled: isDisabled,
300
- label: label ?? t("delete label"),
299
+ iconOnly,
300
+ variant,
301
301
  classNames: [
302
302
  classNames,
303
303
  autoHide && disabled && "hidden"
304
304
  ]
305
305
  });
306
306
  };
307
- var ListItemButton = ({ autoHide = true, iconOnly = true, variant = "ghost", classNames, disabled, ...props }) => {
308
- const { state } = useListContext("ITEM_BUTTON");
307
+ var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, icon = "ph--x--regular", label, ...props }) => {
308
+ const { state } = useListContext("DELETE_BUTTON");
309
309
  const isDisabled = state.type !== "idle" || disabled;
310
+ const { t } = useTranslation(osTranslations);
310
311
  return /* @__PURE__ */ React4.createElement(IconButton, {
312
+ iconOnly: true,
313
+ variant: "ghost",
311
314
  ...props,
315
+ icon,
312
316
  disabled: isDisabled,
313
- iconOnly,
314
- variant,
317
+ label: label ?? t("delete label"),
315
318
  classNames: [
316
319
  classNames,
317
320
  autoHide && disabled && "hidden"
@@ -351,8 +354,8 @@ var List = {
351
354
  ItemDragPreview: ListItemDragPreview,
352
355
  ItemWrapper: ListItemWrapper,
353
356
  ItemDragHandle: ListItemDragHandle,
357
+ ItemIconButton: ListItemIconButton,
354
358
  ItemDeleteButton: ListItemDeleteButton,
355
- ItemButton: ListItemButton,
356
359
  ItemTitle: ListItemTitle
357
360
  };
358
361
 
@@ -494,7 +497,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
494
497
  pathProp,
495
498
  item.id
496
499
  ]);
497
- const { id, parentOf, label, className, headingClassName, icon, iconHue, disabled, testId } = useAtomValue(itemPropsAtom(path));
500
+ const { id, parentOf, draggable: itemDraggable, droppable: itemDroppable, label, className, headingClassName, icon, iconHue, disabled, testId } = useAtomValue(itemPropsAtom(path));
498
501
  const childIds = useAtomValue(childIdsAtom(item.id));
499
502
  const open = useAtomValue(itemOpenAtom(path));
500
503
  const current = useAtomValue(itemCurrentAtom(path));
@@ -516,111 +519,119 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
516
519
  cancelExpandRef.current = null;
517
520
  }
518
521
  }, []);
522
+ const isItemDraggable = draggableProp && itemDraggable !== false;
523
+ const isItemDroppable = itemDroppable !== false;
519
524
  useEffect3(() => {
520
525
  if (!draggableProp) {
521
526
  return;
522
527
  }
523
528
  invariant2(buttonRef.current, void 0, {
524
529
  F: __dxlog_file2,
525
- L: 135,
530
+ L: 148,
526
531
  S: void 0,
527
532
  A: [
528
533
  "buttonRef.current",
529
534
  ""
530
535
  ]
531
536
  });
532
- return combine2(
533
- draggable2({
534
- element: buttonRef.current,
535
- getInitialData: () => data,
536
- onDragStart: () => {
537
- setState("dragging");
538
- if (open) {
539
- openRef.current = true;
540
- onOpenChange?.({
541
- item,
542
- path,
543
- open: false
544
- });
545
- }
546
- },
547
- onDrop: () => {
548
- setState("idle");
549
- if (openRef.current) {
550
- onOpenChange?.({
551
- item,
552
- path,
553
- open: true
554
- });
555
- }
556
- }
557
- }),
558
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
559
- dropTargetForElements2({
560
- element: buttonRef.current,
561
- getData: ({ input, element }) => {
562
- return attachInstruction(data, {
563
- input,
564
- element,
565
- indentPerLevel: DEFAULT_INDENTATION,
566
- currentLevel: level,
567
- mode,
568
- block: isBranch ? [] : [
569
- "make-child"
570
- ]
571
- });
572
- },
573
- canDrop: ({ source }) => {
574
- const _canDrop = canDrop ?? (() => true);
575
- return source.element !== buttonRef.current && _canDrop({
576
- source: source.data,
577
- target: data
537
+ const makeDraggable = () => draggable2({
538
+ element: buttonRef.current,
539
+ getInitialData: () => data,
540
+ onDragStart: () => {
541
+ setState("dragging");
542
+ if (open) {
543
+ openRef.current = true;
544
+ onOpenChange?.({
545
+ item,
546
+ path,
547
+ open: false
578
548
  });
579
- },
580
- getIsSticky: () => true,
581
- onDrag: ({ self, source }) => {
582
- const desired = extractInstruction(self.data);
583
- const block = desired && blockInstruction?.({
584
- instruction: desired,
585
- source: source.data,
586
- target: data
549
+ }
550
+ },
551
+ onDrop: () => {
552
+ setState("idle");
553
+ if (openRef.current) {
554
+ onOpenChange?.({
555
+ item,
556
+ path,
557
+ open: true
587
558
  });
588
- const instruction2 = block && desired.type !== "instruction-blocked" ? {
589
- type: "instruction-blocked",
590
- desired
591
- } : desired;
592
- if (source.data.id !== id) {
593
- if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
594
- cancelExpandRef.current = setTimeout(() => {
595
- onOpenChange?.({
596
- item,
597
- path,
598
- open: true
599
- });
600
- }, 500);
601
- }
602
- if (instruction2?.type !== "make-child") {
603
- cancelExpand();
604
- }
605
- setInstruction(instruction2);
606
- } else if (instruction2?.type === "reparent") {
607
- setInstruction(instruction2);
608
- } else {
609
- setInstruction(null);
559
+ }
560
+ }
561
+ });
562
+ if (!isItemDroppable) {
563
+ return isItemDraggable ? makeDraggable() : void 0;
564
+ }
565
+ const dropTarget = dropTargetForElements2({
566
+ element: buttonRef.current,
567
+ getData: ({ input, element }) => {
568
+ return attachInstruction(data, {
569
+ input,
570
+ element,
571
+ indentPerLevel: DEFAULT_INDENTATION,
572
+ currentLevel: level,
573
+ mode,
574
+ block: isBranch ? [] : [
575
+ "make-child"
576
+ ]
577
+ });
578
+ },
579
+ canDrop: ({ source }) => {
580
+ const _canDrop = canDrop ?? (() => true);
581
+ return source.element !== buttonRef.current && _canDrop({
582
+ source: source.data,
583
+ target: data
584
+ });
585
+ },
586
+ getIsSticky: () => true,
587
+ onDrag: ({ self, source }) => {
588
+ const desired = extractInstruction(self.data);
589
+ const block = desired && blockInstruction?.({
590
+ instruction: desired,
591
+ source: source.data,
592
+ target: data
593
+ });
594
+ const instruction2 = block && desired.type !== "instruction-blocked" ? {
595
+ type: "instruction-blocked",
596
+ desired
597
+ } : desired;
598
+ if (source.data.id !== id) {
599
+ if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
600
+ cancelExpandRef.current = setTimeout(() => {
601
+ onOpenChange?.({
602
+ item,
603
+ path,
604
+ open: true
605
+ });
606
+ }, 500);
610
607
  }
611
- },
612
- onDragLeave: () => {
613
- cancelExpand();
614
- setInstruction(null);
615
- },
616
- onDrop: () => {
617
- cancelExpand();
608
+ if (instruction2?.type !== "make-child") {
609
+ cancelExpand();
610
+ }
611
+ setInstruction(instruction2);
612
+ } else if (instruction2?.type === "reparent") {
613
+ setInstruction(instruction2);
614
+ } else {
618
615
  setInstruction(null);
619
616
  }
620
- })
621
- );
617
+ },
618
+ onDragLeave: () => {
619
+ cancelExpand();
620
+ setInstruction(null);
621
+ },
622
+ onDrop: () => {
623
+ cancelExpand();
624
+ setInstruction(null);
625
+ }
626
+ });
627
+ if (!isItemDraggable) {
628
+ return dropTarget;
629
+ }
630
+ return combine2(makeDraggable(), dropTarget);
622
631
  }, [
623
632
  draggableProp,
633
+ isItemDraggable,
634
+ isItemDroppable,
624
635
  item,
625
636
  id,
626
637
  mode,