@dxos/react-ui-list 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (37) hide show
  1. package/dist/lib/browser/index.mjs +637 -712
  2. package/dist/lib/browser/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +637 -712
  5. package/dist/lib/node-esm/index.mjs.map +3 -3
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/List/List.d.ts +2 -2
  8. package/dist/types/src/components/List/List.d.ts.map +1 -1
  9. package/dist/types/src/components/List/List.stories.d.ts +2 -2
  10. package/dist/types/src/components/List/List.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/List/ListRoot.d.ts +2 -2
  12. package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
  13. package/dist/types/src/components/Tree/Tree.d.ts +7 -4
  14. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  15. package/dist/types/src/components/Tree/Tree.stories.d.ts +9 -28
  16. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  17. package/dist/types/src/components/Tree/TreeContext.d.ts +4 -2
  18. package/dist/types/src/components/Tree/TreeContext.d.ts.map +1 -1
  19. package/dist/types/src/components/Tree/TreeItem.d.ts +12 -3
  20. package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
  21. package/dist/types/src/components/Tree/testing.d.ts +2 -2
  22. package/dist/types/src/components/Tree/testing.d.ts.map +1 -1
  23. package/dist/types/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +29 -27
  25. package/src/components/Accordion/Accordion.stories.tsx +3 -3
  26. package/src/components/Accordion/AccordionItem.tsx +2 -2
  27. package/src/components/Accordion/AccordionRoot.tsx +1 -1
  28. package/src/components/List/List.stories.tsx +29 -17
  29. package/src/components/List/ListItem.tsx +3 -3
  30. package/src/components/List/ListRoot.tsx +2 -2
  31. package/src/components/List/testing.ts +2 -2
  32. package/src/components/Tree/Tree.stories.tsx +74 -60
  33. package/src/components/Tree/Tree.tsx +17 -9
  34. package/src/components/Tree/TreeContext.tsx +4 -2
  35. package/src/components/Tree/TreeItem.tsx +17 -11
  36. package/src/components/Tree/TreeItemHeading.tsx +1 -1
  37. package/src/components/Tree/testing.ts +4 -3
@@ -13,7 +13,6 @@ import {
13
13
  import * as Schema from 'effect/Schema';
14
14
  import React, { type FC, type KeyboardEvent, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
15
15
 
16
- import { type HasId } from '@dxos/echo/internal';
17
16
  import { invariant } from '@dxos/invariant';
18
17
  import { TreeItem as NaturalTreeItem, Treegrid } from '@dxos/react-ui';
19
18
  import {
@@ -22,7 +21,7 @@ import {
22
21
  hoverableControls,
23
22
  hoverableFocusedKeyboardControls,
24
23
  hoverableFocusedWithinControls,
25
- } from '@dxos/react-ui-theme';
24
+ } from '@dxos/ui-theme';
26
25
 
27
26
  import { DEFAULT_INDENTATION, paddingIndentation } from './helpers';
28
27
  import { useTree } from './TreeContext';
@@ -43,7 +42,7 @@ export const TreeDataSchema = Schema.Struct({
43
42
  export type TreeData = Schema.Schema.Type<typeof TreeDataSchema>;
44
43
  export const isTreeData = (data: unknown): data is TreeData => Schema.is(TreeDataSchema)(data);
45
44
 
46
- export type ColumnRenderer<T extends HasId = any> = FC<{
45
+ export type ColumnRenderer<T extends { id: string } = any> = FC<{
47
46
  item: T;
48
47
  path: string[];
49
48
  open: boolean;
@@ -51,26 +50,28 @@ export type ColumnRenderer<T extends HasId = any> = FC<{
51
50
  setMenuOpen: (open: boolean) => void;
52
51
  }>;
53
52
 
54
- export type TreeItemProps<T extends HasId = any> = {
53
+ export type TreeItemProps<T extends { id: string } = any> = {
55
54
  item: T;
56
55
  path: string[];
57
56
  levelOffset?: number;
58
57
  last: boolean;
59
58
  draggable?: boolean;
60
59
  renderColumns?: ColumnRenderer<T>;
60
+ blockInstruction?: (params: { instruction: Instruction; source: TreeData; target: TreeData }) => boolean;
61
61
  canDrop?: (params: { source: TreeData; target: TreeData }) => boolean;
62
62
  canSelect?: (params: { item: T; path: string[] }) => boolean;
63
63
  onOpenChange?: (params: { item: T; path: string[]; open: boolean }) => void;
64
64
  onSelect?: (params: { item: T; path: string[]; current: boolean; option: boolean }) => void;
65
65
  };
66
66
 
67
- const RawTreeItem = <T extends HasId = any>({
67
+ const RawTreeItem = <T extends { id: string } = any>({
68
68
  item,
69
69
  path: _path,
70
70
  levelOffset = 2,
71
71
  last,
72
72
  draggable: _draggable,
73
73
  renderColumns: Columns,
74
+ blockInstruction,
74
75
  canDrop,
75
76
  canSelect,
76
77
  onOpenChange,
@@ -84,12 +85,12 @@ const RawTreeItem = <T extends HasId = any>({
84
85
  const [instruction, setInstruction] = useState<Instruction | null>(null);
85
86
  const [menuOpen, setMenuOpen] = useState(false);
86
87
 
87
- const { useItems, getProps, isOpen, isCurrent } = useTree();
88
+ const { useItems, getProps, useIsOpen, useIsCurrent } = useTree();
88
89
  const items = useItems(item);
89
90
  const { id, parentOf, label, className, headingClassName, icon, iconHue, disabled, testId } = getProps(item, _path);
90
91
  const path = useMemo(() => [..._path, id], [_path, id]);
91
- const open = isOpen(path, item);
92
- const current = isCurrent(path, item);
92
+ const open = useIsOpen(path, item);
93
+ const current = useIsCurrent(path, item);
93
94
  const level = path.length - levelOffset;
94
95
  const isBranch = !!parentOf;
95
96
  const mode: ItemMode = last ? 'last-in-group' : open ? 'expanded' : 'standard';
@@ -149,7 +150,11 @@ const RawTreeItem = <T extends HasId = any>({
149
150
  },
150
151
  getIsSticky: () => true,
151
152
  onDrag: ({ self, source }) => {
152
- const instruction = extractInstruction(self.data);
153
+ const desired = extractInstruction(self.data);
154
+ const block =
155
+ desired && blockInstruction?.({ instruction: desired, source: source.data as TreeData, target: data });
156
+ const instruction: Instruction | null =
157
+ block && desired.type !== 'instruction-blocked' ? { type: 'instruction-blocked', desired } : desired;
153
158
 
154
159
  if (source.data.id !== id) {
155
160
  if (instruction?.type === 'make-child' && isBranch && !open && !cancelExpandRef.current) {
@@ -180,7 +185,7 @@ const RawTreeItem = <T extends HasId = any>({
180
185
  },
181
186
  }),
182
187
  );
183
- }, [_draggable, item, id, mode, path, open, canDrop]);
188
+ }, [_draggable, item, id, mode, path, open, blockInstruction, canDrop]);
184
189
 
185
190
  // Cancel expand on unmount.
186
191
  useEffect(() => () => cancelExpand(), [cancelExpand]);
@@ -236,7 +241,7 @@ const RawTreeItem = <T extends HasId = any>({
236
241
  ghostFocusWithin,
237
242
  className,
238
243
  ]}
239
- data-itemid={id}
244
+ data-object-id={id}
240
245
  data-testid={testId}
241
246
  // NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
242
247
  // without alerting the user (except for in the correct link element). See also:
@@ -279,6 +284,7 @@ const RawTreeItem = <T extends HasId = any>({
279
284
  last={index === items.length - 1}
280
285
  draggable={_draggable}
281
286
  renderColumns={Columns}
287
+ blockInstruction={blockInstruction}
282
288
  canDrop={canDrop}
283
289
  canSelect={canSelect}
284
290
  onOpenChange={onOpenChange}
@@ -6,7 +6,7 @@ import React, { type KeyboardEvent, type MouseEvent, forwardRef, memo, useCallba
6
6
 
7
7
  import { Button, Icon, type Label, toLocalizedString, useTranslation } from '@dxos/react-ui';
8
8
  import { TextTooltip } from '@dxos/react-ui-text-tooltip';
9
- import { getStyles } from '@dxos/react-ui-theme';
9
+ import { getStyles } from '@dxos/ui-theme';
10
10
 
11
11
  // TODO(wittjosiah): Consider whether there should be a separate disabled prop which was visually distinct
12
12
  // rather than just making the item unselectable.
@@ -5,20 +5,21 @@
5
5
  import { type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
6
6
  import * as Schema from 'effect/Schema';
7
7
 
8
- import { type HasId, ObjectId } from '@dxos/echo/internal';
8
+ import { Obj } from '@dxos/echo';
9
9
  import { log } from '@dxos/log';
10
10
  import { faker } from '@dxos/random';
11
11
 
12
12
  import { type TreeData } from './TreeItem';
13
13
 
14
- export type TestItem = HasId & {
14
+ export type TestItem = {
15
+ id: string;
15
16
  name: string;
16
17
  icon?: string;
17
18
  items: TestItem[];
18
19
  };
19
20
 
20
21
  export const TestItemSchema = Schema.Struct({
21
- id: ObjectId,
22
+ id: Obj.ID,
22
23
  name: Schema.String,
23
24
  icon: Schema.optional(Schema.String),
24
25
  items: Schema.mutable(Schema.Array(Schema.suspend((): Schema.Schema<TestItem> => TestItemSchema))),