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

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