@dxos/react-ui-list 0.7.5-main.2567c87 → 0.7.5-main.5ae2ba8

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.
Files changed (44) hide show
  1. package/dist/lib/browser/index.mjs +120 -92
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +117 -90
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +120 -92
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/List/List.d.ts +6 -6
  11. package/dist/types/src/components/List/List.d.ts.map +1 -1
  12. package/dist/types/src/components/List/ListItem.d.ts +10 -13
  13. package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
  14. package/dist/types/src/components/List/ListRoot.d.ts +4 -7
  15. package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
  16. package/dist/types/src/components/Tree/Tree.d.ts +4 -3
  17. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  18. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  19. package/dist/types/src/components/Tree/TreeItem.d.ts +3 -2
  20. package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
  21. package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
  22. package/dist/types/src/components/Tree/TreeItemToggle.d.ts +1 -0
  23. package/dist/types/src/components/Tree/TreeItemToggle.d.ts.map +1 -1
  24. package/dist/types/src/components/Tree/helpers.d.ts +1 -1
  25. package/dist/types/src/index.d.ts +1 -0
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/util/index.d.ts +2 -0
  28. package/dist/types/src/util/index.d.ts.map +1 -0
  29. package/dist/types/src/util/path.d.ts +14 -0
  30. package/dist/types/src/util/path.d.ts.map +1 -0
  31. package/dist/types/src/util/path.test.d.ts +2 -0
  32. package/dist/types/src/util/path.test.d.ts.map +1 -0
  33. package/package.json +20 -20
  34. package/src/components/List/ListItem.tsx +10 -4
  35. package/src/components/Tree/Tree.stories.tsx +1 -1
  36. package/src/components/Tree/Tree.tsx +9 -5
  37. package/src/components/Tree/TreeItem.tsx +13 -16
  38. package/src/components/Tree/TreeItemHeading.tsx +2 -3
  39. package/src/components/Tree/TreeItemToggle.tsx +3 -2
  40. package/src/components/Tree/helpers.ts +1 -1
  41. package/src/index.ts +1 -0
  42. package/src/util/index.ts +5 -0
  43. package/src/util/path.test.ts +24 -0
  44. package/src/util/path.ts +21 -0
@@ -3,11 +3,7 @@
3
3
  //
4
4
 
5
5
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
6
- import {
7
- draggable as pragmaticDraggable,
8
- dropTargetForElements,
9
- } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
10
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
6
+ import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
11
7
  import {
12
8
  attachInstruction,
13
9
  extractInstruction,
@@ -20,7 +16,6 @@ import { S } from '@dxos/echo-schema';
20
16
  import { invariant } from '@dxos/invariant';
21
17
  import { Treegrid, TreeItem as NaturalTreeItem } from '@dxos/react-ui';
22
18
  import {
23
- focusRing,
24
19
  ghostHover,
25
20
  hoverableControls,
26
21
  hoverableFocusedKeyboardControls,
@@ -31,7 +26,7 @@ import {
31
26
  import { useTree } from './TreeContext';
32
27
  import { TreeItemHeading } from './TreeItemHeading';
33
28
  import { TreeItemToggle } from './TreeItemToggle';
34
- import { DEFAULT_INDENTATION, paddingIndendation } from './helpers';
29
+ import { DEFAULT_INDENTATION, paddingIndentation } from './helpers';
35
30
 
36
31
  type TreeItemState = 'idle' | 'dragging' | 'preview' | 'parent-of-instruction';
37
32
 
@@ -51,6 +46,7 @@ export const isTreeData = (data: unknown): data is TreeData => S.is(TreeDataSche
51
46
  export type TreeItemProps<T = any> = {
52
47
  item: T;
53
48
  path: string[];
49
+ levelOffset?: number;
54
50
  last: boolean;
55
51
  draggable?: boolean;
56
52
  renderColumns?: FC<{
@@ -69,11 +65,12 @@ export const RawTreeItem = <T = any,>({
69
65
  item,
70
66
  path: _path,
71
67
  last,
72
- draggable,
68
+ draggable: _draggable,
73
69
  renderColumns: Columns,
74
70
  canDrop,
75
71
  onOpenChange,
76
72
  onSelect,
73
+ levelOffset = 2,
77
74
  }: TreeItemProps<T>) => {
78
75
  const { getItems, getProps, isOpen, isCurrent } = useTree();
79
76
  const items = getItems(item);
@@ -81,7 +78,7 @@ export const RawTreeItem = <T = any,>({
81
78
  const path = useMemo(() => [..._path, id], [_path, id]);
82
79
  const open = isOpen(path, item);
83
80
  const current = isCurrent(path, item);
84
- const level = path.length - 2;
81
+ const level = path.length - levelOffset;
85
82
  const isBranch = !!parentOf;
86
83
  const mode: ItemMode = last ? 'last-in-group' : open ? 'expanded' : 'standard';
87
84
  const data = useMemo(() => ({ id, path, item }) satisfies TreeData, [id, path, item]);
@@ -102,7 +99,7 @@ export const RawTreeItem = <T = any,>({
102
99
  }, []);
103
100
 
104
101
  useEffect(() => {
105
- if (!draggable) {
102
+ if (!_draggable) {
106
103
  return;
107
104
  }
108
105
 
@@ -110,7 +107,7 @@ export const RawTreeItem = <T = any,>({
110
107
 
111
108
  // https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about
112
109
  return combine(
113
- pragmaticDraggable({
110
+ draggable({
114
111
  element: buttonRef.current,
115
112
  getInitialData: () => data,
116
113
  onDragStart: () => {
@@ -127,6 +124,7 @@ export const RawTreeItem = <T = any,>({
127
124
  }
128
125
  },
129
126
  }),
127
+ // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
130
128
  dropTargetForElements({
131
129
  element: buttonRef.current,
132
130
  getData: ({ input, element }) => {
@@ -176,7 +174,7 @@ export const RawTreeItem = <T = any,>({
176
174
  },
177
175
  }),
178
176
  );
179
- }, [draggable, item, id, mode, path, open, canDrop]);
177
+ }, [_draggable, item, id, mode, path, open, canDrop]);
180
178
 
181
179
  // Cancel expand on unmount.
182
180
  useEffect(() => () => cancelExpand(), [cancelExpand]);
@@ -220,13 +218,12 @@ export const RawTreeItem = <T = any,>({
220
218
  aria-labelledby={`${id}__label`}
221
219
  parentOf={parentOf?.join(Treegrid.PARENT_OF_SEPARATOR)}
222
220
  classNames={mx(
223
- 'grid grid-cols-subgrid col-[tree-row] mt-[2px] aria-[current]:bg-input',
221
+ 'grid grid-cols-subgrid col-[tree-row] mbs-0.5 aria-[current]:bg-groupSurface',
224
222
  hoverableControls,
225
223
  hoverableFocusedKeyboardControls,
226
224
  hoverableFocusedWithinControls,
227
225
  hoverableDescriptionIcons,
228
226
  ghostHover,
229
- focusRing,
230
227
  className,
231
228
  )}
232
229
  data-itemid={id}
@@ -244,7 +241,7 @@ export const RawTreeItem = <T = any,>({
244
241
  <Treegrid.Cell
245
242
  indent
246
243
  classNames='relative grid grid-cols-subgrid col-[tree-row]'
247
- style={paddingIndendation(level)}
244
+ style={paddingIndentation(level)}
248
245
  >
249
246
  <div role='none' className='flex items-center'>
250
247
  <TreeItemToggle open={open} isBranch={isBranch} onToggle={handleOpenChange} />
@@ -269,7 +266,7 @@ export const RawTreeItem = <T = any,>({
269
266
  item={item}
270
267
  path={path}
271
268
  last={index === items.length - 1}
272
- draggable={draggable}
269
+ draggable={_draggable}
273
270
  renderColumns={Columns}
274
271
  canDrop={canDrop}
275
272
  onOpenChange={onOpenChange}
@@ -51,14 +51,13 @@ export const TreeItemHeading = memo(
51
51
  asChild
52
52
  ref={forwardedRef}
53
53
  >
54
- {/* TODO(wittjosiah): Class precedence. See #8149. */}
55
54
  <Button
56
55
  data-testid='treeItem.heading'
57
56
  variant='ghost'
58
57
  density='fine'
59
58
  classNames={mx(
60
- 'grow gap-2 !pis-0.5 hover:!bg-transparent dark:hover:!bg-transparent',
61
- 'disabled:!cursor-default disabled:!opacity-100',
59
+ 'grow gap-2 pis-0.5 hover:bg-transparent dark:hover:bg-transparent',
60
+ 'disabled:cursor-default disabled:opacity-100',
62
61
  className,
63
62
  )}
64
63
  disabled={disabled}
@@ -11,10 +11,11 @@ export type TreeItemToggleProps = {
11
11
  open?: boolean;
12
12
  isBranch?: boolean;
13
13
  onToggle?: () => void;
14
+ hidden?: boolean;
14
15
  };
15
16
 
16
17
  export const TreeItemToggle = memo(
17
- forwardRef<HTMLButtonElement, TreeItemToggleProps>(({ open, isBranch, onToggle }, forwardedRef) => {
18
+ forwardRef<HTMLButtonElement, TreeItemToggleProps>(({ open, isBranch, hidden, onToggle }, forwardedRef) => {
18
19
  return (
19
20
  <Button
20
21
  ref={forwardedRef}
@@ -22,7 +23,7 @@ export const TreeItemToggle = memo(
22
23
  aria-expanded={open}
23
24
  variant='ghost'
24
25
  density='fine'
25
- classNames={mx('is-6 !pli-1', !isBranch && 'invisible')}
26
+ classNames={mx('is-4 dx-focus-ring-inset pli-0', hidden ? 'hidden' : !isBranch && 'invisible')}
26
27
  onClick={onToggle}
27
28
  >
28
29
  <Icon
@@ -4,6 +4,6 @@
4
4
 
5
5
  export const DEFAULT_INDENTATION = 8;
6
6
 
7
- export const paddingIndendation = (level: number, indentation = DEFAULT_INDENTATION) => ({
7
+ export const paddingIndentation = (level: number, indentation = DEFAULT_INDENTATION) => ({
8
8
  paddingInlineStart: `${(level - 1) * indentation}px`,
9
9
  });
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './components';
6
+ export * from './util';
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './path';
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { describe, expect, test } from 'vitest';
6
+
7
+ import { Path } from './path';
8
+
9
+ describe('paths', () => {
10
+ test('create', () => {
11
+ const path = Path.create('a', 'b', 'c');
12
+ expect(Path.first(path)).to.eq('a');
13
+ expect(Path.last(path)).to.eq('c');
14
+
15
+ expect(Path.hasRoot(path, 'a')).to.be.true;
16
+ expect(Path.hasRoot(path, 'x')).to.be.false;
17
+
18
+ expect(Path.hasChild(Path.create('a', 'b'), path)).to.be.true;
19
+ expect(Path.hasChild(Path.create('a'), path)).to.be.false;
20
+
21
+ expect(Path.hasDescendent(Path.create('a', 'b'), path)).to.be.true;
22
+ expect(Path.hasDescendent(Path.create('a'), path)).to.be.true;
23
+ });
24
+ });
@@ -0,0 +1,21 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ const SEPARATOR = '~';
6
+
7
+ export const Path = {
8
+ create: (...args: string[]) => args.join(SEPARATOR),
9
+
10
+ parts: (path: string) => path.split(SEPARATOR),
11
+ length: (path: string) => path.split(SEPARATOR).length,
12
+ first: (path: string) => path.split(SEPARATOR)[0] ?? path,
13
+ last: (path: string) => path.split(SEPARATOR).at(-1) ?? path,
14
+ parent: (path: string) => path.split(SEPARATOR).slice(0, -1).join(SEPARATOR),
15
+
16
+ hasRoot: (path: string, id: string) => Path.first(path) === id,
17
+ hasChild: (path: string, compare: string) => Path.parent(compare) === path,
18
+ hasDescendent: (path: string, compare: string) => compare !== path && compare.startsWith(path),
19
+ siblings: (path: string, compare: string) => Path.parent(path) === Path.parent(compare),
20
+ onPath: (path: string, id: string) => Path.parts(path).includes(id),
21
+ };