@dxos/react-ui-list 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d

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 (28) hide show
  1. package/dist/lib/browser/index.mjs +23 -9
  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 +23 -9
  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/Accordion/Accordion.stories.d.ts +0 -3
  8. package/dist/types/src/components/Accordion/Accordion.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/Tree/Tree.d.ts +2 -2
  10. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  11. package/dist/types/src/components/Tree/Tree.stories.d.ts +1 -1
  12. package/dist/types/src/components/Tree/TreeContext.d.ts +1 -1
  13. package/dist/types/src/components/Tree/TreeContext.d.ts.map +1 -1
  14. package/dist/types/src/components/Tree/TreeItem.d.ts +6 -0
  15. package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
  16. package/dist/types/src/components/Tree/TreeItemHeading.d.ts +1 -1
  17. package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
  18. package/dist/types/src/components/Tree/testing.d.ts.map +1 -1
  19. package/dist/types/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +16 -16
  21. package/src/components/Accordion/Accordion.stories.tsx +4 -7
  22. package/src/components/List/List.stories.tsx +3 -3
  23. package/src/components/List/testing.ts +2 -2
  24. package/src/components/Tree/Tree.tsx +10 -1
  25. package/src/components/Tree/TreeContext.tsx +1 -1
  26. package/src/components/Tree/TreeItem.tsx +12 -8
  27. package/src/components/Tree/TreeItemHeading.tsx +5 -3
  28. package/src/components/Tree/testing.ts +3 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-list",
3
- "version": "0.8.4-main.5ad4a44",
3
+ "version": "0.8.4-main.66e292d",
4
4
  "description": "A list component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -30,33 +30,33 @@
30
30
  "@preact/signals-core": "^1.12.1",
31
31
  "@radix-ui/react-accordion": "1.2.3",
32
32
  "@radix-ui/react-context": "1.1.1",
33
- "@dxos/debug": "0.8.4-main.5ad4a44",
34
- "@dxos/echo": "0.8.4-main.5ad4a44",
35
- "@dxos/invariant": "0.8.4-main.5ad4a44",
36
- "@dxos/log": "0.8.4-main.5ad4a44",
37
- "@dxos/live-object": "0.8.4-main.5ad4a44",
38
- "@dxos/react-ui": "0.8.4-main.5ad4a44",
39
- "@dxos/react-ui-text-tooltip": "0.8.4-main.5ad4a44",
40
- "@dxos/react-ui-theme": "0.8.4-main.5ad4a44",
41
- "@dxos/util": "0.8.4-main.5ad4a44",
42
- "@dxos/react-ui-types": "0.8.4-main.5ad4a44"
33
+ "@dxos/invariant": "0.8.4-main.66e292d",
34
+ "@dxos/live-object": "0.8.4-main.66e292d",
35
+ "@dxos/react-ui": "0.8.4-main.66e292d",
36
+ "@dxos/react-ui-text-tooltip": "0.8.4-main.66e292d",
37
+ "@dxos/log": "0.8.4-main.66e292d",
38
+ "@dxos/debug": "0.8.4-main.66e292d",
39
+ "@dxos/react-ui-theme": "0.8.4-main.66e292d",
40
+ "@dxos/react-ui-types": "0.8.4-main.66e292d",
41
+ "@dxos/util": "0.8.4-main.66e292d",
42
+ "@dxos/echo": "0.8.4-main.66e292d"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/react": "~19.2.2",
46
- "@types/react-dom": "~19.2.1",
46
+ "@types/react-dom": "~19.2.2",
47
47
  "effect": "3.18.3",
48
48
  "react": "~19.2.0",
49
49
  "react-dom": "~19.2.0",
50
50
  "vite": "7.1.9",
51
- "@dxos/random": "0.8.4-main.5ad4a44",
52
- "@dxos/storybook-utils": "0.8.4-main.5ad4a44"
51
+ "@dxos/storybook-utils": "0.8.4-main.66e292d",
52
+ "@dxos/random": "0.8.4-main.66e292d"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "effect": "^3.13.3",
56
56
  "react": "^19.0.0",
57
57
  "react-dom": "^19.0.0",
58
- "@dxos/react-ui-theme": "0.8.4-main.5ad4a44",
59
- "@dxos/react-ui": "0.8.4-main.5ad4a44"
58
+ "@dxos/react-ui-theme": "0.8.4-main.66e292d",
59
+ "@dxos/react-ui": "0.8.4-main.66e292d"
60
60
  },
61
61
  "publishConfig": {
62
62
  "access": "public"
@@ -6,7 +6,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import React from 'react';
7
7
 
8
8
  import { faker } from '@dxos/random';
9
- import { withTheme } from '@dxos/react-ui/testing';
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
10
 
11
11
  import { Accordion } from './Accordion';
12
12
 
@@ -22,9 +22,9 @@ const items: TestItem[] = Array.from({ length: 10 }, (_, i) => ({
22
22
 
23
23
  const DefaultStory = () => {
24
24
  return (
25
- <Accordion.Root<TestItem> items={items} classNames='w-[40rem]'>
25
+ <Accordion.Root<TestItem> items={items} classNames='is-[40rem]'>
26
26
  {({ items }) => (
27
- <div className='flex flex-col w-full border-y border-separator divide-y divide-separator'>
27
+ <div className='flex flex-col is-full border-y border-separator divide-y divide-separator'>
28
28
  {items.map((item) => (
29
29
  <Accordion.Item key={item.id} item={item} classNames='border-x border-separator'>
30
30
  <Accordion.ItemHeader>{item.name}</Accordion.ItemHeader>
@@ -42,10 +42,7 @@ const DefaultStory = () => {
42
42
  const meta = {
43
43
  title: 'ui/react-ui-list/Accordion',
44
44
  render: DefaultStory,
45
- decorators: [withTheme],
46
- parameters: {
47
- layout: 'column',
48
- },
45
+ decorators: [withTheme, withLayout({ container: 'column' })],
49
46
  } satisfies Meta<typeof Accordion>;
50
47
 
51
48
  export default meta;
@@ -33,13 +33,13 @@ const DefaultStory = ({ items = [], ...props }: ListRootProps<TestItemType>) =>
33
33
  <List.Root<TestItemType> dragPreview items={items} getId={(item) => item.id} onMove={handleMove} {...props}>
34
34
  {({ items }) => (
35
35
  <>
36
- <div className='flex flex-col w-full'>
36
+ <div className='flex flex-col is-full'>
37
37
  <div role='none' className={grid}>
38
38
  <div />
39
39
  <div className='flex items-center text-sm'>Items</div>
40
40
  </div>
41
41
 
42
- <div role='list' className='w-full h-full overflow-auto'>
42
+ <div role='list' className='is-full bs-full overflow-auto'>
43
43
  {items?.map((item) => (
44
44
  <List.Item<TestItemType> key={item.id} item={item} classNames={mx(grid, ghostHover)}>
45
45
  <List.ItemDragHandle />
@@ -73,7 +73,7 @@ const SimpleStory = ({ items = [], ...props }: ListRootProps<TestItemType>) => {
73
73
  return (
74
74
  <List.Root<TestItemType> dragPreview items={items} {...props}>
75
75
  {({ items }) => (
76
- <div role='list' className='w-full h-full overflow-auto'>
76
+ <div role='list' className='is-full bs-full overflow-auto'>
77
77
  {items?.map((item) => (
78
78
  <List.Item<TestItemType> key={item.id} item={item} classNames={mx(grid, ghostHover)}>
79
79
  <List.ItemDragHandle />
@@ -4,11 +4,11 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { ObjectId } from '@dxos/echo/internal';
7
+ import { Obj } from '@dxos/echo';
8
8
  import { faker } from '@dxos/random';
9
9
 
10
10
  export const TestItemSchema = Schema.Struct({
11
- id: ObjectId,
11
+ id: Obj.ID,
12
12
  name: Schema.String,
13
13
  });
14
14
 
@@ -18,7 +18,14 @@ export type TreeProps<T extends HasId = any, O = any> = {
18
18
  Partial<Pick<TreegridRootProps, 'gridTemplateColumns' | 'classNames'>> &
19
19
  Pick<
20
20
  TreeItemProps<T>,
21
- 'draggable' | 'renderColumns' | 'canDrop' | 'canSelect' | 'onOpenChange' | 'onSelect' | 'levelOffset'
21
+ | 'draggable'
22
+ | 'renderColumns'
23
+ | 'blockInstruction'
24
+ | 'canDrop'
25
+ | 'canSelect'
26
+ | 'onOpenChange'
27
+ | 'onSelect'
28
+ | 'levelOffset'
22
29
  >;
23
30
 
24
31
  export const Tree = <T extends HasId = any, O = any>({
@@ -34,6 +41,7 @@ export const Tree = <T extends HasId = any, O = any>({
34
41
  classNames,
35
42
  levelOffset,
36
43
  renderColumns,
44
+ blockInstruction,
37
45
  canDrop,
38
46
  canSelect,
39
47
  onOpenChange,
@@ -63,6 +71,7 @@ export const Tree = <T extends HasId = any, O = any>({
63
71
  levelOffset={levelOffset}
64
72
  draggable={draggable}
65
73
  renderColumns={renderColumns}
74
+ blockInstruction={blockInstruction}
66
75
  canDrop={canDrop}
67
76
  canSelect={canSelect}
68
77
  onOpenChange={onOpenChange}
@@ -14,7 +14,7 @@ export type TreeItemDataProps = {
14
14
  className?: string;
15
15
  headingClassName?: string;
16
16
  icon?: string;
17
- iconClassName?: string;
17
+ iconHue?: string;
18
18
  disabled?: boolean;
19
19
  testId?: string;
20
20
  };
@@ -58,6 +58,7 @@ export type TreeItemProps<T extends HasId = any> = {
58
58
  last: boolean;
59
59
  draggable?: boolean;
60
60
  renderColumns?: ColumnRenderer<T>;
61
+ blockInstruction?: (params: { instruction: Instruction; source: TreeData; target: TreeData }) => boolean;
61
62
  canDrop?: (params: { source: TreeData; target: TreeData }) => boolean;
62
63
  canSelect?: (params: { item: T; path: string[] }) => boolean;
63
64
  onOpenChange?: (params: { item: T; path: string[]; open: boolean }) => void;
@@ -71,6 +72,7 @@ const RawTreeItem = <T extends HasId = any>({
71
72
  last,
72
73
  draggable: _draggable,
73
74
  renderColumns: Columns,
75
+ blockInstruction,
74
76
  canDrop,
75
77
  canSelect,
76
78
  onOpenChange,
@@ -86,10 +88,7 @@ const RawTreeItem = <T extends HasId = any>({
86
88
 
87
89
  const { useItems, getProps, isOpen, isCurrent } = useTree();
88
90
  const items = useItems(item);
89
- const { id, parentOf, label, className, headingClassName, icon, iconClassName, disabled, testId } = getProps(
90
- item,
91
- _path,
92
- );
91
+ const { id, parentOf, label, className, headingClassName, icon, iconHue, disabled, testId } = getProps(item, _path);
93
92
  const path = useMemo(() => [..._path, id], [_path, id]);
94
93
  const open = isOpen(path, item);
95
94
  const current = isCurrent(path, item);
@@ -152,7 +151,11 @@ const RawTreeItem = <T extends HasId = any>({
152
151
  },
153
152
  getIsSticky: () => true,
154
153
  onDrag: ({ self, source }) => {
155
- const instruction = extractInstruction(self.data);
154
+ const desired = extractInstruction(self.data);
155
+ const block =
156
+ desired && blockInstruction?.({ instruction: desired, source: source.data as TreeData, target: data });
157
+ const instruction: Instruction | null =
158
+ block && desired.type !== 'instruction-blocked' ? { type: 'instruction-blocked', desired } : desired;
156
159
 
157
160
  if (source.data.id !== id) {
158
161
  if (instruction?.type === 'make-child' && isBranch && !open && !cancelExpandRef.current) {
@@ -183,7 +186,7 @@ const RawTreeItem = <T extends HasId = any>({
183
186
  },
184
187
  }),
185
188
  );
186
- }, [_draggable, item, id, mode, path, open, canDrop]);
189
+ }, [_draggable, item, id, mode, path, open, blockInstruction, canDrop]);
187
190
 
188
191
  // Cancel expand on unmount.
189
192
  useEffect(() => () => cancelExpand(), [cancelExpand]);
@@ -239,7 +242,7 @@ const RawTreeItem = <T extends HasId = any>({
239
242
  ghostFocusWithin,
240
243
  className,
241
244
  ]}
242
- data-itemid={id}
245
+ data-object-id={id}
243
246
  data-testid={testId}
244
247
  // NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
245
248
  // without alerting the user (except for in the correct link element). See also:
@@ -264,7 +267,7 @@ const RawTreeItem = <T extends HasId = any>({
264
267
  label={label}
265
268
  className={headingClassName}
266
269
  icon={icon}
267
- iconClassName={iconClassName}
270
+ iconHue={iconHue}
268
271
  onSelect={handleSelect}
269
272
  ref={buttonRef}
270
273
  />
@@ -282,6 +285,7 @@ const RawTreeItem = <T extends HasId = any>({
282
285
  last={index === items.length - 1}
283
286
  draggable={_draggable}
284
287
  renderColumns={Columns}
288
+ blockInstruction={blockInstruction}
285
289
  canDrop={canDrop}
286
290
  canSelect={canSelect}
287
291
  onOpenChange={onOpenChange}
@@ -6,6 +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
10
 
10
11
  // TODO(wittjosiah): Consider whether there should be a separate disabled prop which was visually distinct
11
12
  // rather than just making the item unselectable.
@@ -13,7 +14,7 @@ export type TreeItemHeadingProps = {
13
14
  label: Label;
14
15
  className?: string;
15
16
  icon?: string;
16
- iconClassName?: string;
17
+ iconHue?: string;
17
18
  disabled?: boolean;
18
19
  current?: boolean;
19
20
  onSelect?: (option: boolean) => void;
@@ -21,8 +22,9 @@ export type TreeItemHeadingProps = {
21
22
 
22
23
  export const TreeItemHeading = memo(
23
24
  forwardRef<HTMLButtonElement, TreeItemHeadingProps>(
24
- ({ label, className, icon, iconClassName, disabled, current, onSelect }, forwardedRef) => {
25
+ ({ label, className, icon, iconHue, disabled, current, onSelect }, forwardedRef) => {
25
26
  const { t } = useTranslation();
27
+ const styles = iconHue ? getStyles(iconHue) : undefined;
26
28
 
27
29
  const handleSelect = useCallback(
28
30
  (event: MouseEvent) => {
@@ -65,7 +67,7 @@ export const TreeItemHeading = memo(
65
67
  onKeyDown={handleButtonKeydown}
66
68
  {...(current && { 'aria-current': 'location' })}
67
69
  >
68
- {icon && <Icon icon={icon ?? 'ph--placeholder--regular'} size={5} classNames={['mlb-1', iconClassName]} />}
70
+ {icon && <Icon icon={icon ?? 'ph--placeholder--regular'} size={5} classNames={['mlb-1', styles?.icon]} />}
69
71
  <span className='flex-1 is-0 truncate text-start text-sm font-normal' data-tooltip>
70
72
  {toLocalizedString(label, t)}
71
73
  </span>
@@ -5,7 +5,8 @@
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
+ import { type HasId } from '@dxos/echo/internal';
9
10
  import { log } from '@dxos/log';
10
11
  import { faker } from '@dxos/random';
11
12
 
@@ -18,7 +19,7 @@ export type TestItem = HasId & {
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))),