@dxos/react-ui-list 0.7.4 → 0.7.5-main.9d26e3a

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.
@@ -6,56 +6,18 @@ import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-d
6
6
  import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
7
7
  import { attachClosestEdge, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
8
8
  import { createContext as createContext2 } from "@radix-ui/react-context";
9
- import React3, { forwardRef, useEffect as useEffect2, useRef, useState as useState2 } from "react";
9
+ import React2, { forwardRef, useEffect as useEffect2, useRef, useState as useState2 } from "react";
10
10
  import { createPortal } from "react-dom";
11
11
  import { invariant } from "@dxos/invariant";
12
- import { Icon } from "@dxos/react-ui";
13
- import { mx as mx2 } from "@dxos/react-ui-theme";
14
-
15
- // packages/ui/react-ui-list/src/components/List/DropIndicator.tsx
16
- import React from "react";
12
+ import { Icon, ListItem as NaturalListItem } from "@dxos/react-ui";
17
13
  import { mx } from "@dxos/react-ui-theme";
18
- var edgeToOrientationMap = {
19
- top: "horizontal",
20
- bottom: "horizontal",
21
- left: "vertical",
22
- right: "vertical"
23
- };
24
- var orientationStyles = {
25
- horizontal: "h-[--line-thickness] left-[--terminal-radius] right-0 before:left-[--negative-terminal-size]",
26
- vertical: "w-[--line-thickness] top-[--terminal-radius] bottom-0 before:top-[--negative-terminal-size]"
27
- };
28
- var edgeStyles = {
29
- top: "top-[--line-offset] before:top-[--offset-terminal]",
30
- right: "right-[--line-offset] before:right-[--offset-terminal]",
31
- bottom: "bottom-[--line-offset] before:bottom-[--offset-terminal]",
32
- left: "left-[--line-offset] before:left-[--offset-terminal]"
33
- };
34
- var strokeSize = 2;
35
- var terminalSize = 8;
36
- var offsetToAlignTerminalWithLine = (strokeSize - terminalSize) / 2;
37
- var DropIndicator = ({ edge, gap = 0 }) => {
38
- const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize}px))`;
39
- const orientation = edgeToOrientationMap[edge];
40
- return /* @__PURE__ */ React.createElement("div", {
41
- style: {
42
- "--line-thickness": `${strokeSize}px`,
43
- "--line-offset": `${lineOffset}`,
44
- "--terminal-size": `${terminalSize}px`,
45
- "--terminal-radius": `${terminalSize / 2}px`,
46
- "--negative-terminal-size": `-${terminalSize}px`,
47
- "--offset-terminal": `${offsetToAlignTerminalWithLine}px`
48
- },
49
- className: mx("absolute z-10 pointer-events-none bg-blue-700", "before:content-[''] before:w-[--terminal-size] before:h-[--terminal-size] box-border before:absolute", "before:border-[length:--line-thickness] before:border-solid before:border-blue-700 before:rounded-full", orientationStyles[orientation], edgeStyles[edge])
50
- });
51
- };
52
14
 
53
15
  // packages/ui/react-ui-list/src/components/List/ListRoot.tsx
54
16
  import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
55
17
  import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
56
18
  import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index";
57
19
  import { createContext } from "@radix-ui/react-context";
58
- import React2, { useCallback, useEffect, useState } from "react";
20
+ import React, { useCallback, useEffect, useState } from "react";
59
21
  var LIST_NAME = "List";
60
22
  var [ListProvider, useListContext] = createContext(LIST_NAME);
61
23
  var defaultGetId = (item) => item?.id;
@@ -108,7 +70,7 @@ var ListRoot = ({ classNames, children, items, isItem, getId = defaultGetId, onM
108
70
  isEqual,
109
71
  onMove
110
72
  ]);
111
- return /* @__PURE__ */ React2.createElement(ListProvider, {
73
+ return /* @__PURE__ */ React.createElement(ListProvider, {
112
74
  isItem,
113
75
  state,
114
76
  setState,
@@ -139,7 +101,7 @@ var ListItem = ({ children, classNames, item }) => {
139
101
  const element = ref.current;
140
102
  invariant(element, void 0, {
141
103
  F: __dxlog_file,
142
- L: 91,
104
+ L: 90,
143
105
  S: void 0,
144
106
  A: [
145
107
  "element",
@@ -176,6 +138,8 @@ var ListItem = ({ children, classNames, item }) => {
176
138
  container,
177
139
  item
178
140
  });
141
+ return () => {
142
+ };
179
143
  }
180
144
  });
181
145
  } : void 0,
@@ -242,25 +206,25 @@ var ListItem = ({ children, classNames, item }) => {
242
206
  }, [
243
207
  item
244
208
  ]);
245
- return /* @__PURE__ */ React3.createElement(ListItemProvider, {
209
+ return /* @__PURE__ */ React2.createElement(ListItemProvider, {
246
210
  item,
247
211
  dragHandleRef
248
- }, /* @__PURE__ */ React3.createElement("div", {
212
+ }, /* @__PURE__ */ React2.createElement("div", {
249
213
  className: "relative"
250
- }, /* @__PURE__ */ React3.createElement("div", {
214
+ }, /* @__PURE__ */ React2.createElement("div", {
251
215
  ref,
252
216
  role: "listitem",
253
- className: mx2("flex overflow-hidden", classNames, stateStyles[state.type])
254
- }, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ React3.createElement(DropIndicator, {
217
+ className: mx("flex overflow-hidden", classNames, stateStyles[state.type])
218
+ }, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ React2.createElement(NaturalListItem.DropIndicator, {
255
219
  edge: state.closestEdge
256
220
  })));
257
221
  };
258
222
  var IconButton = /* @__PURE__ */ forwardRef(({ classNames, icon, ...props }, forwardedRef) => {
259
- return /* @__PURE__ */ React3.createElement("button", {
223
+ return /* @__PURE__ */ React2.createElement("button", {
260
224
  ref: forwardedRef,
261
- className: mx2("flex items-center justify-center", classNames),
225
+ className: mx("flex items-center justify-center", classNames),
262
226
  ...props
263
- }, /* @__PURE__ */ React3.createElement(Icon, {
227
+ }, /* @__PURE__ */ React2.createElement(Icon, {
264
228
  icon,
265
229
  classNames: "cursor-pointer",
266
230
  size: 4
@@ -269,7 +233,7 @@ var IconButton = /* @__PURE__ */ forwardRef(({ classNames, icon, ...props }, for
269
233
  var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, ...props }) => {
270
234
  const { state } = useListContext("DELETE_BUTTON");
271
235
  const isDisabled = state.type !== "idle" || disabled;
272
- return /* @__PURE__ */ React3.createElement(IconButton, {
236
+ return /* @__PURE__ */ React2.createElement(IconButton, {
273
237
  icon: "ph--x--regular",
274
238
  disabled: isDisabled,
275
239
  classNames: [
@@ -281,7 +245,7 @@ var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, ...props })
281
245
  };
282
246
  var ListItemDragHandle = () => {
283
247
  const { dragHandleRef } = useListItemContext("DRAG_HANDLE");
284
- return /* @__PURE__ */ React3.createElement(IconButton, {
248
+ return /* @__PURE__ */ React2.createElement(IconButton, {
285
249
  ref: dragHandleRef,
286
250
  icon: "ph--dots-six-vertical--regular"
287
251
  });
@@ -292,11 +256,11 @@ var ListItemDragPreview = ({ children }) => {
292
256
  item: state.item
293
257
  }), state.container) : null;
294
258
  };
295
- var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */ React3.createElement("div", {
296
- className: mx2("flex is-full gap-2", classNames)
259
+ var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */ React2.createElement("div", {
260
+ className: mx("flex is-full gap-2", classNames)
297
261
  }, children);
298
- var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */ React3.createElement("div", {
299
- className: mx2("flex grow items-center truncate", classNames),
262
+ var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */ React2.createElement("div", {
263
+ className: mx("flex grow items-center truncate", classNames),
300
264
  ...props
301
265
  }, children);
302
266
 
@@ -313,7 +277,7 @@ var List = {
313
277
  };
314
278
 
315
279
  // packages/ui/react-ui-list/src/components/Tree/Tree.tsx
316
- import React8, { useMemo as useMemo2 } from "react";
280
+ import React6, { useMemo as useMemo2 } from "react";
317
281
  import { Treegrid as Treegrid2 } from "@dxos/react-ui";
318
282
 
319
283
  // packages/ui/react-ui-list/src/components/Tree/TreeContext.tsx
@@ -327,63 +291,17 @@ var TreeProvider = TreeContext.Provider;
327
291
  import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
328
292
  import { draggable as pragmaticDraggable, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
329
293
  import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
330
- import React7, { memo as memo3, useCallback as useCallback3, useEffect as useEffect3, useMemo, useRef as useRef2, useState as useState3 } from "react";
294
+ import React5, { memo as memo3, useCallback as useCallback3, useEffect as useEffect3, useMemo, useRef as useRef2, useState as useState3 } from "react";
331
295
  import { S } from "@dxos/echo-schema";
332
296
  import { invariant as invariant2 } from "@dxos/invariant";
333
- import { Treegrid } from "@dxos/react-ui";
334
- import { focusRing, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as mx6 } from "@dxos/react-ui-theme";
335
-
336
- // packages/ui/react-ui-list/src/components/Tree/DropIndicator.tsx
337
- import React4 from "react";
338
- import { mx as mx3 } from "@dxos/react-ui-theme";
339
- var edgeToOrientationMap2 = {
340
- "reorder-above": "sibling",
341
- "reorder-below": "sibling",
342
- "make-child": "child",
343
- reparent: "child"
344
- };
345
- var orientationStyles2 = {
346
- // TODO(wittjosiah): Stop using left/right here.
347
- sibling: "bs-[--line-thickness] left-[--horizontal-indent] right-0 bg-accentSurface before:left-[--negative-terminal-size]",
348
- child: "is-full block-start-0 block-end-0 border-[length:--line-thickness] before:invisible"
349
- };
350
- var instructionStyles = {
351
- "reorder-above": "block-start-[--line-offset] before:block-start-[--offset-terminal]",
352
- "reorder-below": "block-end-[--line-offset] before:block-end-[--offset-terminal]",
353
- "make-child": "border-accentSurface",
354
- // TODO(wittjosiah): This is not occurring in the current implementation.
355
- reparent: ""
356
- };
357
- var strokeSize2 = 2;
358
- var terminalSize2 = 8;
359
- var offsetToAlignTerminalWithLine2 = (strokeSize2 - terminalSize2) / 2;
360
- var DropIndicator2 = ({ instruction, gap = 0 }) => {
361
- const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize2}px))`;
362
- const isBlocked = instruction.type === "instruction-blocked";
363
- const desiredInstruction = isBlocked ? instruction.desired : instruction;
364
- const orientation = edgeToOrientationMap2[desiredInstruction.type];
365
- if (isBlocked) {
366
- return null;
367
- }
368
- return /* @__PURE__ */ React4.createElement("div", {
369
- style: {
370
- "--line-thickness": `${strokeSize2}px`,
371
- "--line-offset": `${lineOffset}`,
372
- "--terminal-size": `${terminalSize2}px`,
373
- "--terminal-radius": `${terminalSize2 / 2}px`,
374
- "--negative-terminal-size": `-${terminalSize2}px`,
375
- "--offset-terminal": `${offsetToAlignTerminalWithLine2}px`,
376
- "--horizontal-indent": `${desiredInstruction.currentLevel * desiredInstruction.indentPerLevel + 4}px`
377
- },
378
- className: mx3("absolute z-10 pointer-events-none", "before:is-[--terminal-size] before:bs-[--terminal-size] box-border before:absolute", "before:border-[length:--line-thickness] before:border-solid before:border-accentSurface before:rounded-full", orientationStyles2[orientation], instructionStyles[desiredInstruction.type])
379
- });
380
- };
297
+ import { Treegrid, TreeItem as NaturalTreeItem } from "@dxos/react-ui";
298
+ import { focusRing, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as mx4 } from "@dxos/react-ui-theme";
381
299
 
382
300
  // packages/ui/react-ui-list/src/components/Tree/TreeItemHeading.tsx
383
- import React5, { forwardRef as forwardRef2, memo, useCallback as useCallback2 } from "react";
301
+ import React3, { forwardRef as forwardRef2, memo, useCallback as useCallback2 } from "react";
384
302
  import { Button, Icon as Icon2, toLocalizedString, useTranslation } from "@dxos/react-ui";
385
303
  import { TextTooltip } from "@dxos/react-ui-text-tooltip";
386
- import { mx as mx4 } from "@dxos/react-ui-theme";
304
+ import { mx as mx2 } from "@dxos/react-ui-theme";
387
305
  var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef2(({ label, icon, className, disabled, current, onSelect }, forwardedRef) => {
388
306
  const { t } = useTranslation();
389
307
  const handleSelect = useCallback2((event) => {
@@ -400,51 +318,51 @@ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef2(({ label,
400
318
  }, [
401
319
  onSelect
402
320
  ]);
403
- return /* @__PURE__ */ React5.createElement(TextTooltip, {
321
+ return /* @__PURE__ */ React3.createElement(TextTooltip, {
404
322
  text: toLocalizedString(label, t),
405
323
  side: "bottom",
406
324
  truncateQuery: "span[data-tooltip]",
407
325
  onlyWhenTruncating: true,
408
326
  asChild: true,
409
327
  ref: forwardedRef
410
- }, /* @__PURE__ */ React5.createElement(Button, {
328
+ }, /* @__PURE__ */ React3.createElement(Button, {
411
329
  "data-testid": "treeItem.heading",
412
330
  variant: "ghost",
413
331
  density: "fine",
414
- classNames: mx4("grow gap-2 !pis-0.5 hover:!bg-transparent dark:hover:!bg-transparent", "disabled:!cursor-default disabled:!opacity-100", className),
332
+ classNames: mx2("grow gap-2 !pis-0.5 hover:!bg-transparent dark:hover:!bg-transparent", "disabled:!cursor-default disabled:!opacity-100", className),
415
333
  disabled,
416
334
  onClick: handleSelect,
417
335
  onKeyDown: handleButtonKeydown,
418
336
  ...current && {
419
337
  "aria-current": "location"
420
338
  }
421
- }, icon && /* @__PURE__ */ React5.createElement(Icon2, {
339
+ }, icon && /* @__PURE__ */ React3.createElement(Icon2, {
422
340
  icon: icon ?? "ph--placeholder--regular",
423
341
  size: 4,
424
342
  classNames: "is-[1em] bs-[1em] mlb-1"
425
- }), /* @__PURE__ */ React5.createElement("span", {
343
+ }), /* @__PURE__ */ React3.createElement("span", {
426
344
  className: "flex-1 is-0 truncate text-start text-sm font-normal",
427
345
  "data-tooltip": true
428
346
  }, toLocalizedString(label, t))));
429
347
  }));
430
348
 
431
349
  // packages/ui/react-ui-list/src/components/Tree/TreeItemToggle.tsx
432
- import React6, { forwardRef as forwardRef3, memo as memo2 } from "react";
350
+ import React4, { forwardRef as forwardRef3, memo as memo2 } from "react";
433
351
  import { Button as Button2, Icon as Icon3 } from "@dxos/react-ui";
434
- import { mx as mx5 } from "@dxos/react-ui-theme";
352
+ import { mx as mx3 } from "@dxos/react-ui-theme";
435
353
  var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef3(({ open, isBranch, onToggle }, forwardedRef) => {
436
- return /* @__PURE__ */ React6.createElement(Button2, {
354
+ return /* @__PURE__ */ React4.createElement(Button2, {
437
355
  ref: forwardedRef,
438
356
  "data-testid": "treeItem.toggle",
439
357
  "aria-expanded": open,
440
358
  variant: "ghost",
441
359
  density: "fine",
442
- classNames: mx5("is-6 !pli-1", !isBranch && "invisible"),
360
+ classNames: mx3("is-6 !pli-1", !isBranch && "invisible"),
443
361
  onClick: onToggle
444
- }, /* @__PURE__ */ React6.createElement(Icon3, {
362
+ }, /* @__PURE__ */ React4.createElement(Icon3, {
445
363
  icon: "ph--caret-right--regular",
446
364
  size: 3,
447
- classNames: mx5("transition duration-200", open && "rotate-90")
365
+ classNames: mx3("transition duration-200", open && "rotate-90")
448
366
  }));
449
367
  }));
450
368
 
@@ -507,7 +425,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
507
425
  }
508
426
  invariant2(buttonRef.current, void 0, {
509
427
  F: __dxlog_file2,
510
- L: 104,
428
+ L: 109,
511
429
  S: void 0,
512
430
  A: [
513
431
  "buttonRef.current",
@@ -642,13 +560,13 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
642
560
  handleOpenChange,
643
561
  handleSelect
644
562
  ]);
645
- return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Treegrid.Row, {
563
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(Treegrid.Row, {
646
564
  ref: rowRef,
647
565
  key: id,
648
566
  id,
649
567
  "aria-labelledby": `${id}__label`,
650
568
  parentOf: parentOf?.join(Treegrid.PARENT_OF_SEPARATOR),
651
- classNames: mx6("grid grid-cols-subgrid col-[tree-row] mt-[2px] aria-[current]:bg-input", hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableDescriptionIcons, ghostHover, focusRing, className),
569
+ classNames: mx4("grid grid-cols-subgrid col-[tree-row] mt-[2px] aria-[current]:bg-input", hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableDescriptionIcons, ghostHover, focusRing, className),
652
570
  "data-itemid": id,
653
571
  "data-testid": testId,
654
572
  // NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
@@ -660,18 +578,18 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
660
578
  event.preventDefault();
661
579
  setMenuOpen(true);
662
580
  }
663
- }, /* @__PURE__ */ React7.createElement(Treegrid.Cell, {
581
+ }, /* @__PURE__ */ React5.createElement(Treegrid.Cell, {
664
582
  indent: true,
665
583
  classNames: "relative grid grid-cols-subgrid col-[tree-row]",
666
584
  style: paddingIndendation(level)
667
- }, /* @__PURE__ */ React7.createElement("div", {
585
+ }, /* @__PURE__ */ React5.createElement("div", {
668
586
  role: "none",
669
587
  className: "flex items-center"
670
- }, /* @__PURE__ */ React7.createElement(TreeItemToggle, {
588
+ }, /* @__PURE__ */ React5.createElement(TreeItemToggle, {
671
589
  open,
672
590
  isBranch,
673
591
  onToggle: handleOpenChange
674
- }), /* @__PURE__ */ React7.createElement(TreeItemHeading, {
592
+ }), /* @__PURE__ */ React5.createElement(TreeItemHeading, {
675
593
  ref: buttonRef,
676
594
  label,
677
595
  icon,
@@ -679,15 +597,16 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
679
597
  disabled,
680
598
  current,
681
599
  onSelect: handleSelect
682
- })), Columns && /* @__PURE__ */ React7.createElement(Columns, {
600
+ })), Columns && /* @__PURE__ */ React5.createElement(Columns, {
683
601
  item,
684
602
  path,
603
+ open,
685
604
  menuOpen,
686
605
  setMenuOpen
687
- }), instruction && /* @__PURE__ */ React7.createElement(DropIndicator2, {
606
+ }), instruction && /* @__PURE__ */ React5.createElement(NaturalTreeItem.DropIndicator, {
688
607
  instruction,
689
608
  gap: 2
690
- }))), open && items.map((item2, index) => /* @__PURE__ */ React7.createElement(TreeItem, {
609
+ }))), open && items.map((item2, index) => /* @__PURE__ */ React5.createElement(TreeItem, {
691
610
  key: item2.id,
692
611
  item: item2,
693
612
  path,
@@ -720,12 +639,12 @@ var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable: draggable2 =
720
639
  ], [
721
640
  id
722
641
  ]);
723
- return /* @__PURE__ */ React8.createElement(Treegrid2.Root, {
642
+ return /* @__PURE__ */ React6.createElement(Treegrid2.Root, {
724
643
  gridTemplateColumns,
725
644
  classNames
726
- }, /* @__PURE__ */ React8.createElement(TreeProvider, {
645
+ }, /* @__PURE__ */ React6.createElement(TreeProvider, {
727
646
  value: context
728
- }, items.map((item, index) => /* @__PURE__ */ React8.createElement(TreeItem, {
647
+ }, items.map((item, index) => /* @__PURE__ */ React6.createElement(TreeItem, {
729
648
  key: item.id,
730
649
  item,
731
650
  last: index === items.length - 1,