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