@dxos/react-ui-list 0.8.2-main.f081794 → 0.8.2-main.fbd8ed0
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.
- package/dist/lib/browser/index.mjs +24 -29
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +24 -30
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +24 -29
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Accordion/AccordionItem.d.ts.map +1 -1
- package/dist/types/src/components/Accordion/AccordionRoot.d.ts.map +1 -1
- package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
- package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
- package/dist/types/src/components/List/testing.d.ts +10 -10
- package/dist/types/src/components/List/testing.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.d.ts +4 -3
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts +2 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeContext.d.ts +1 -1
- package/dist/types/src/components/Tree/TreeItem.d.ts +9 -9
- package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
- package/dist/types/src/components/Tree/helpers.d.ts.map +1 -1
- package/dist/types/src/components/Tree/testing.d.ts +8 -8
- package/dist/types/src/components/Tree/testing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/components/Accordion/Accordion.stories.tsx +2 -2
- package/src/components/List/List.stories.tsx +3 -3
- package/src/components/List/testing.ts +10 -8
- package/src/components/Tree/Tree.stories.tsx +3 -3
- package/src/components/Tree/Tree.tsx +11 -6
- package/src/components/Tree/TreeContext.tsx +1 -1
- package/src/components/Tree/TreeItem.tsx +22 -20
- package/src/components/Tree/testing.ts +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,eAAO,MAAM,cAAc;;;EAGzB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,cAAc,CAAC,CAAC;AAErE,eAAO,MAAM,QAAQ;;;;;EAEnB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE3D,eAAO,MAAM,UAAU,GAAI,UAAM,KAAG,QAQlC,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type HasId } from '@dxos/echo-schema';
|
|
2
3
|
import { type TreegridRootProps } from '@dxos/react-ui';
|
|
3
4
|
import { type TreeContextType } from './TreeContext';
|
|
4
5
|
import { type TreeItemProps } from './TreeItem';
|
|
5
|
-
export type TreeProps<T = any> = {
|
|
6
|
+
export type TreeProps<T extends HasId = any> = {
|
|
6
7
|
root?: T;
|
|
7
8
|
path?: string[];
|
|
8
9
|
id: string;
|
|
9
|
-
} & TreeContextType & Partial<Pick<TreegridRootProps, 'gridTemplateColumns' | 'classNames'>> & Pick<TreeItemProps<T>, 'draggable' | 'renderColumns' | 'canDrop' | 'onOpenChange' | 'onSelect' | 'levelOffset'>;
|
|
10
|
-
export declare const Tree: <T = any>({ root, path, id,
|
|
10
|
+
} & TreeContextType<T> & Partial<Pick<TreegridRootProps, 'gridTemplateColumns' | 'classNames'>> & Pick<TreeItemProps<T>, 'draggable' | 'renderColumns' | 'canDrop' | 'onOpenChange' | 'onSelect' | 'levelOffset'>;
|
|
11
|
+
export declare const Tree: <T extends HasId = any>({ root, path, id, useItems, getProps, isOpen, isCurrent, draggable, gridTemplateColumns, classNames, renderColumns, canDrop, onOpenChange, onSelect, levelOffset, }: TreeProps<T>) => React.JSX.Element;
|
|
11
12
|
//# sourceMappingURL=Tree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/Tree.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAY,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,KAAK,eAAe,EAAgB,MAAM,eAAe,CAAC;AACnE,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/Tree.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAY,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,KAAK,eAAe,EAAgB,MAAM,eAAe,CAAC;AACnE,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,KAAK,GAAG,GAAG,IAAI;IAC7C,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,GAAG,eAAe,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,qBAAqB,GAAG,YAAY,CAAC,CAAC,GACtE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,eAAe,GAAG,SAAS,GAAG,cAAc,GAAG,UAAU,GAAG,aAAa,CAAC,CAAC;AAElH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,KAAK,GAAG,GAAG,EAAE,qKAgBzC,SAAS,CAAC,CAAC,CAAC,sBAiCd,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import '@dxos-theme';
|
|
2
2
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
3
3
|
import { Tree } from './Tree';
|
|
4
|
-
|
|
4
|
+
import { type TestItem } from './testing';
|
|
5
|
+
declare const meta: Meta<typeof Tree<TestItem>>;
|
|
5
6
|
export default meta;
|
|
6
7
|
export declare const Default: {};
|
|
7
8
|
export declare const Draggable: StoryObj<typeof Tree>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/Tree.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAIrB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAQ5D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"Tree.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/Tree.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAIrB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAQ5D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAA2B,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAQnE,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,CAgFrC,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,eAAO,MAAM,OAAO,IAAK,CAAC;AAE1B,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,OAAO,IAAI,CAI3C,CAAC"}
|
|
@@ -10,7 +10,7 @@ export type PropsFromTreeItem = {
|
|
|
10
10
|
testId?: string;
|
|
11
11
|
};
|
|
12
12
|
export type TreeContextType<T = any> = {
|
|
13
|
-
|
|
13
|
+
useItems: (parent?: T) => T[];
|
|
14
14
|
getProps: (item: T, parent: string[]) => PropsFromTreeItem;
|
|
15
15
|
isOpen: (path: string[], item: T) => boolean;
|
|
16
16
|
isCurrent: (path: string[], item: T) => boolean;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { type FC } from 'react';
|
|
3
|
+
import { type HasId } from '@dxos/echo-schema';
|
|
4
|
+
export declare const TreeDataSchema: Schema.Struct<{
|
|
5
|
+
id: typeof Schema.String;
|
|
6
|
+
path: Schema.Array$<typeof Schema.String>;
|
|
7
|
+
item: typeof Schema.Any;
|
|
7
8
|
}>;
|
|
8
|
-
export type TreeData =
|
|
9
|
+
export type TreeData = Schema.Schema.Type<typeof TreeDataSchema>;
|
|
9
10
|
export declare const isTreeData: (data: unknown) => data is TreeData;
|
|
10
|
-
export type TreeItemProps<T = any> = {
|
|
11
|
+
export type TreeItemProps<T extends HasId = any> = {
|
|
11
12
|
item: T;
|
|
12
13
|
path: string[];
|
|
13
14
|
levelOffset?: number;
|
|
@@ -33,6 +34,5 @@ export type TreeItemProps<T = any> = {
|
|
|
33
34
|
option: boolean;
|
|
34
35
|
}) => void;
|
|
35
36
|
};
|
|
36
|
-
export declare const RawTreeItem: <T = any>({ item, path: _path, last, draggable: _draggable, renderColumns: Columns, canDrop, onOpenChange, onSelect, levelOffset, }: TreeItemProps<T>) => React.JSX.Element;
|
|
37
37
|
export declare const TreeItem: FC<TreeItemProps>;
|
|
38
38
|
//# sourceMappingURL=TreeItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeItem.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/TreeItem.tsx"],"names":[],"mappings":"AAYA,OAAO,
|
|
1
|
+
{"version":3,"file":"TreeItem.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/TreeItem.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAc,EAA2D,KAAK,EAAE,EAAsB,MAAM,OAAO,CAAC;AAEpH,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAqB/C,eAAO,MAAM,cAAc;;;;EAIzB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,cAAc,CAAC,CAAC;AAEjE,eAAO,MAAM,UAAU,GAAI,MAAM,OAAO,KAAG,IAAI,IAAI,QAA2C,CAAC;AAE/F,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,GAAG,GAAG,IAAI;IACjD,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,EAAE,CAAC;QACjB,IAAI,EAAE,CAAC,CAAC;QACR,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,IAAI,EAAE,OAAO,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC;QAClB,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;KACtC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,KAAK,OAAO,CAAC;IAC1D,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC5E,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;CAC7F,CAAC;AA+NF,eAAO,MAAM,QAAQ,EAAwB,EAAE,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/helpers.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/helpers.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,oBAAiC;;CAEjF,CAAC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
2
|
-
import {
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
import { type HasId } from '@dxos/echo-schema';
|
|
3
4
|
import { type TreeData } from './TreeItem';
|
|
4
|
-
export type TestItem = {
|
|
5
|
-
id: string;
|
|
5
|
+
export type TestItem = HasId & {
|
|
6
6
|
name: string;
|
|
7
7
|
icon?: string;
|
|
8
8
|
items: TestItem[];
|
|
9
9
|
};
|
|
10
|
-
export declare const TestItemSchema:
|
|
11
|
-
id:
|
|
12
|
-
name: typeof
|
|
13
|
-
icon:
|
|
14
|
-
items:
|
|
10
|
+
export declare const TestItemSchema: Schema.Struct<{
|
|
11
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
12
|
+
name: typeof Schema.String;
|
|
13
|
+
icon: Schema.optional<typeof Schema.String>;
|
|
14
|
+
items: Schema.mutable<Schema.Array$<Schema.suspend<TestItem, TestItem, never>>>;
|
|
15
15
|
}>;
|
|
16
16
|
export declare const createTree: (n?: number, d?: number) => TestItem;
|
|
17
17
|
export declare const updateState: ({ state, instruction, source, target, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,mBAAmB,CAAC;AAIzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;EAKzB,CAAC;AAEH,eAAO,MAAM,UAAU,GAAI,UAAK,EAAE,UAAK,KAAG,QAaxC,CAAC;AAmBH,eAAO,MAAM,WAAW,GAAI,yCAKzB;IACD,KAAK,EAAE,QAAQ,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,EAAE,QAAQ,CAAC;CAClB,SAgCA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"5.
|
|
1
|
+
{"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-list",
|
|
3
|
-
"version": "0.8.2-main.
|
|
3
|
+
"version": "0.8.2-main.fbd8ed0",
|
|
4
4
|
"description": "A list component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -28,36 +28,36 @@
|
|
|
28
28
|
"@preact/signals-core": "^1.6.0",
|
|
29
29
|
"@radix-ui/react-accordion": "1.2.3",
|
|
30
30
|
"@radix-ui/react-context": "1.1.1",
|
|
31
|
-
"@dxos/debug": "0.8.2-main.
|
|
32
|
-
"@dxos/echo-schema": "0.8.2-main.
|
|
33
|
-
"@dxos/invariant": "0.8.2-main.
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/react-ui-text-tooltip": "0.8.2-main.
|
|
38
|
-
"@dxos/react-ui-types": "0.8.2-main.
|
|
39
|
-
"@dxos/util": "0.8.2-main.
|
|
31
|
+
"@dxos/debug": "0.8.2-main.fbd8ed0",
|
|
32
|
+
"@dxos/echo-schema": "0.8.2-main.fbd8ed0",
|
|
33
|
+
"@dxos/invariant": "0.8.2-main.fbd8ed0",
|
|
34
|
+
"@dxos/live-object": "0.8.2-main.fbd8ed0",
|
|
35
|
+
"@dxos/log": "0.8.2-main.fbd8ed0",
|
|
36
|
+
"@dxos/react-ui-attention": "0.8.2-main.fbd8ed0",
|
|
37
|
+
"@dxos/react-ui-text-tooltip": "0.8.2-main.fbd8ed0",
|
|
38
|
+
"@dxos/react-ui-types": "0.8.2-main.fbd8ed0",
|
|
39
|
+
"@dxos/util": "0.8.2-main.fbd8ed0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@phosphor-icons/react": "^2.1.5",
|
|
43
43
|
"@types/react": "~18.2.0",
|
|
44
44
|
"@types/react-dom": "~18.2.0",
|
|
45
|
-
"effect": "3.
|
|
45
|
+
"effect": "3.14.21",
|
|
46
46
|
"react": "~18.2.0",
|
|
47
47
|
"react-dom": "~18.2.0",
|
|
48
48
|
"vite": "5.4.7",
|
|
49
|
-
"@dxos/random": "0.8.2-main.
|
|
50
|
-
"@dxos/react-ui": "0.8.2-main.
|
|
51
|
-
"@dxos/react-ui-theme": "0.8.2-main.
|
|
52
|
-
"@dxos/storybook-utils": "0.8.2-main.
|
|
49
|
+
"@dxos/random": "0.8.2-main.fbd8ed0",
|
|
50
|
+
"@dxos/react-ui": "0.8.2-main.fbd8ed0",
|
|
51
|
+
"@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
|
|
52
|
+
"@dxos/storybook-utils": "0.8.2-main.fbd8ed0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@phosphor-icons/react": "^2.1.5",
|
|
56
56
|
"effect": "3.13.3",
|
|
57
57
|
"react": "~18.2.0",
|
|
58
58
|
"react-dom": "~18.2.0",
|
|
59
|
-
"@dxos/react-ui": "0.8.2-main.
|
|
60
|
-
"@dxos/react-ui-theme": "0.8.2-main.
|
|
59
|
+
"@dxos/react-ui": "0.8.2-main.fbd8ed0",
|
|
60
|
+
"@dxos/react-ui-theme": "0.8.2-main.fbd8ed0"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
@@ -26,9 +26,9 @@ const DefaultStory = () => {
|
|
|
26
26
|
return (
|
|
27
27
|
<Accordion.Root<TestItem> items={items} classNames='w-[40rem]'>
|
|
28
28
|
{({ items }) => (
|
|
29
|
-
<div className='flex flex-col w-full border-y border-
|
|
29
|
+
<div className='flex flex-col w-full border-y border-separator divide-y divide-separator'>
|
|
30
30
|
{items.map((item) => (
|
|
31
|
-
<Accordion.Item key={item.id} item={item} classNames='border-x border-
|
|
31
|
+
<Accordion.Item key={item.id} item={item} classNames='border-x border-separator'>
|
|
32
32
|
<Accordion.ItemHeader>{item.name}</Accordion.ItemHeader>
|
|
33
33
|
<Accordion.ItemBody>
|
|
34
34
|
<p>{item.text}</p>
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
7
|
import { type Meta, type StoryObj } from '@storybook/react';
|
|
8
|
+
import { Schema } from 'effect';
|
|
8
9
|
import React from 'react';
|
|
9
10
|
|
|
10
|
-
import { S } from '@dxos/echo-schema';
|
|
11
11
|
import { live } from '@dxos/live-object';
|
|
12
12
|
import { ghostHover, mx } from '@dxos/react-ui-theme';
|
|
13
13
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
@@ -102,7 +102,7 @@ export const Default: StoryObj<ListRootProps<TestItemType>> = {
|
|
|
102
102
|
render: DefaultStory,
|
|
103
103
|
args: {
|
|
104
104
|
items: list.items,
|
|
105
|
-
isItem:
|
|
105
|
+
isItem: Schema.is(TestItemSchema),
|
|
106
106
|
},
|
|
107
107
|
};
|
|
108
108
|
|
|
@@ -110,6 +110,6 @@ export const Simple: StoryObj<ListRootProps<TestItemType>> = {
|
|
|
110
110
|
render: SimpleStory,
|
|
111
111
|
args: {
|
|
112
112
|
items: list.items,
|
|
113
|
-
isItem:
|
|
113
|
+
isItem: Schema.is(TestItemSchema),
|
|
114
114
|
},
|
|
115
115
|
};
|
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { ObjectId } from '@dxos/echo-schema';
|
|
6
8
|
import { faker } from '@dxos/random';
|
|
7
9
|
|
|
8
|
-
export const TestItemSchema =
|
|
9
|
-
id:
|
|
10
|
-
name:
|
|
10
|
+
export const TestItemSchema = Schema.Struct({
|
|
11
|
+
id: ObjectId,
|
|
12
|
+
name: Schema.String,
|
|
11
13
|
});
|
|
12
14
|
|
|
13
|
-
export type TestItemType =
|
|
15
|
+
export type TestItemType = Schema.Schema.Type<typeof TestItemSchema>;
|
|
14
16
|
|
|
15
|
-
export const TestList =
|
|
16
|
-
items:
|
|
17
|
+
export const TestList = Schema.Struct({
|
|
18
|
+
items: Schema.mutable(Schema.Array(TestItemSchema)),
|
|
17
19
|
});
|
|
18
20
|
|
|
19
|
-
export type TestList =
|
|
21
|
+
export type TestList = Schema.Schema.Type<typeof TestList>;
|
|
20
22
|
|
|
21
23
|
export const createList = (n = 10): TestList => ({
|
|
22
24
|
items: faker.helpers.multiple(
|
|
@@ -24,10 +24,10 @@ faker.seed(1234);
|
|
|
24
24
|
const tree = live<TestItem>(createTree());
|
|
25
25
|
const state = new Map<string, Live<{ open: boolean; current: boolean }>>();
|
|
26
26
|
|
|
27
|
-
const meta: Meta<typeof Tree
|
|
27
|
+
const meta: Meta<typeof Tree<TestItem>> = {
|
|
28
28
|
title: 'ui/react-ui-list/Tree',
|
|
29
29
|
component: Tree,
|
|
30
|
-
decorators: [withTheme, withLayout(
|
|
30
|
+
decorators: [withTheme, withLayout()],
|
|
31
31
|
render: (args) => {
|
|
32
32
|
useEffect(() => {
|
|
33
33
|
return monitorForElements({
|
|
@@ -57,7 +57,7 @@ const meta: Meta<typeof Tree> = {
|
|
|
57
57
|
},
|
|
58
58
|
args: {
|
|
59
59
|
id: tree.id,
|
|
60
|
-
|
|
60
|
+
useItems: (testItem?: TestItem) => {
|
|
61
61
|
return testItem?.items ?? tree.items;
|
|
62
62
|
},
|
|
63
63
|
getProps: (testItem: TestItem) => ({
|
|
@@ -4,20 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
+
import { type HasId } from '@dxos/echo-schema';
|
|
7
8
|
import { Treegrid, type TreegridRootProps } from '@dxos/react-ui';
|
|
8
9
|
|
|
9
10
|
import { type TreeContextType, TreeProvider } from './TreeContext';
|
|
10
11
|
import { TreeItem, type TreeItemProps } from './TreeItem';
|
|
11
12
|
|
|
12
|
-
export type TreeProps<T = any> = {
|
|
13
|
+
export type TreeProps<T extends HasId = any> = {
|
|
14
|
+
root?: T;
|
|
15
|
+
path?: string[];
|
|
16
|
+
id: string;
|
|
17
|
+
} & TreeContextType<T> &
|
|
13
18
|
Partial<Pick<TreegridRootProps, 'gridTemplateColumns' | 'classNames'>> &
|
|
14
19
|
Pick<TreeItemProps<T>, 'draggable' | 'renderColumns' | 'canDrop' | 'onOpenChange' | 'onSelect' | 'levelOffset'>;
|
|
15
20
|
|
|
16
|
-
export const Tree = <T = any
|
|
21
|
+
export const Tree = <T extends HasId = any>({
|
|
17
22
|
root,
|
|
18
23
|
path,
|
|
19
24
|
id,
|
|
20
|
-
|
|
25
|
+
useItems,
|
|
21
26
|
getProps,
|
|
22
27
|
isOpen,
|
|
23
28
|
isCurrent,
|
|
@@ -32,14 +37,14 @@ export const Tree = <T = any,>({
|
|
|
32
37
|
}: TreeProps<T>) => {
|
|
33
38
|
const context = useMemo(
|
|
34
39
|
() => ({
|
|
35
|
-
|
|
40
|
+
useItems,
|
|
36
41
|
getProps,
|
|
37
42
|
isOpen,
|
|
38
43
|
isCurrent,
|
|
39
44
|
}),
|
|
40
|
-
[
|
|
45
|
+
[useItems, getProps, isOpen, isCurrent],
|
|
41
46
|
);
|
|
42
|
-
const items =
|
|
47
|
+
const items = useItems(root);
|
|
43
48
|
const treePath = useMemo(() => (path ? [...path, id] : [id]), [id, path]);
|
|
44
49
|
|
|
45
50
|
return (
|
|
@@ -19,7 +19,7 @@ export type PropsFromTreeItem = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export type TreeContextType<T = any> = {
|
|
22
|
-
|
|
22
|
+
useItems: (parent?: T) => T[];
|
|
23
23
|
getProps: (item: T, parent: string[]) => PropsFromTreeItem;
|
|
24
24
|
isOpen: (path: string[], item: T) => boolean;
|
|
25
25
|
isCurrent: (path: string[], item: T) => boolean;
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
type Instruction,
|
|
11
11
|
type ItemMode,
|
|
12
12
|
} from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
13
|
+
import { Schema } from 'effect';
|
|
13
14
|
import React, { memo, useCallback, useEffect, useMemo, useRef, useState, type FC, type KeyboardEvent } from 'react';
|
|
14
15
|
|
|
15
|
-
import {
|
|
16
|
+
import { type HasId } from '@dxos/echo-schema';
|
|
16
17
|
import { invariant } from '@dxos/invariant';
|
|
17
18
|
import { Treegrid, TreeItem as NaturalTreeItem } from '@dxos/react-ui';
|
|
18
19
|
import {
|
|
@@ -33,17 +34,17 @@ type TreeItemState = 'idle' | 'dragging' | 'preview' | 'parent-of-instruction';
|
|
|
33
34
|
const hoverableDescriptionIcons =
|
|
34
35
|
'[--icons-color:inherit] hover-hover:[--icons-color:var(--description-text)] hover-hover:hover:[--icons-color:inherit] focus-within:[--icons-color:inherit]';
|
|
35
36
|
|
|
36
|
-
export const TreeDataSchema =
|
|
37
|
-
id:
|
|
38
|
-
path:
|
|
39
|
-
item:
|
|
37
|
+
export const TreeDataSchema = Schema.Struct({
|
|
38
|
+
id: Schema.String,
|
|
39
|
+
path: Schema.Array(Schema.String),
|
|
40
|
+
item: Schema.Any,
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
export type TreeData =
|
|
43
|
+
export type TreeData = Schema.Schema.Type<typeof TreeDataSchema>;
|
|
43
44
|
|
|
44
|
-
export const isTreeData = (data: unknown): data is TreeData =>
|
|
45
|
+
export const isTreeData = (data: unknown): data is TreeData => Schema.is(TreeDataSchema)(data);
|
|
45
46
|
|
|
46
|
-
export type TreeItemProps<T = any> = {
|
|
47
|
+
export type TreeItemProps<T extends HasId = any> = {
|
|
47
48
|
item: T;
|
|
48
49
|
path: string[];
|
|
49
50
|
levelOffset?: number;
|
|
@@ -61,7 +62,7 @@ export type TreeItemProps<T = any> = {
|
|
|
61
62
|
onSelect?: (params: { item: T; path: string[]; current: boolean; option: boolean }) => void;
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
const RawTreeItem = <T extends HasId = any>({
|
|
65
66
|
item,
|
|
66
67
|
path: _path,
|
|
67
68
|
last,
|
|
@@ -72,17 +73,6 @@ export const RawTreeItem = <T = any,>({
|
|
|
72
73
|
onSelect,
|
|
73
74
|
levelOffset = 2,
|
|
74
75
|
}: TreeItemProps<T>) => {
|
|
75
|
-
const { getItems, getProps, isOpen, isCurrent } = useTree();
|
|
76
|
-
const items = getItems(item);
|
|
77
|
-
const { id, label, parentOf, icon, disabled, className, headingClassName, testId } = getProps(item, _path);
|
|
78
|
-
const path = useMemo(() => [..._path, id], [_path, id]);
|
|
79
|
-
const open = isOpen(path, item);
|
|
80
|
-
const current = isCurrent(path, item);
|
|
81
|
-
const level = path.length - levelOffset;
|
|
82
|
-
const isBranch = !!parentOf;
|
|
83
|
-
const mode: ItemMode = last ? 'last-in-group' : open ? 'expanded' : 'standard';
|
|
84
|
-
const data = useMemo(() => ({ id, path, item }) satisfies TreeData, [id, path, item]);
|
|
85
|
-
|
|
86
76
|
const rowRef = useRef<HTMLDivElement | null>(null);
|
|
87
77
|
const buttonRef = useRef<HTMLButtonElement | null>(null);
|
|
88
78
|
const openRef = useRef(false);
|
|
@@ -91,6 +81,16 @@ export const RawTreeItem = <T = any,>({
|
|
|
91
81
|
const [instruction, setInstruction] = useState<Instruction | null>(null);
|
|
92
82
|
const [menuOpen, setMenuOpen] = useState(false);
|
|
93
83
|
|
|
84
|
+
const { useItems, getProps, isOpen, isCurrent } = useTree();
|
|
85
|
+
const items = useItems(item);
|
|
86
|
+
const { id, label, parentOf, icon, disabled, className, headingClassName, testId } = getProps(item, _path);
|
|
87
|
+
const path = useMemo(() => [..._path, id], [_path, id]);
|
|
88
|
+
const open = isOpen(path, item);
|
|
89
|
+
const current = isCurrent(path, item);
|
|
90
|
+
const level = path.length - levelOffset;
|
|
91
|
+
const isBranch = !!parentOf;
|
|
92
|
+
const mode: ItemMode = last ? 'last-in-group' : open ? 'expanded' : 'standard';
|
|
93
|
+
|
|
94
94
|
const cancelExpand = useCallback(() => {
|
|
95
95
|
if (cancelExpandRef.current) {
|
|
96
96
|
clearTimeout(cancelExpandRef.current);
|
|
@@ -105,6 +105,8 @@ export const RawTreeItem = <T = any,>({
|
|
|
105
105
|
|
|
106
106
|
invariant(buttonRef.current);
|
|
107
107
|
|
|
108
|
+
const data = { id, path, item } satisfies TreeData;
|
|
109
|
+
|
|
108
110
|
// https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about
|
|
109
111
|
return combine(
|
|
110
112
|
draggable({
|
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
|
|
6
|
+
import { Schema } from 'effect';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { type HasId, ObjectId } from '@dxos/echo-schema';
|
|
8
9
|
import { log } from '@dxos/log';
|
|
9
10
|
import { faker } from '@dxos/random';
|
|
10
11
|
|
|
11
12
|
import { type TreeData } from './TreeItem';
|
|
12
13
|
|
|
13
|
-
export type TestItem = {
|
|
14
|
-
id: string;
|
|
14
|
+
export type TestItem = HasId & {
|
|
15
15
|
name: string;
|
|
16
16
|
icon?: string;
|
|
17
17
|
items: TestItem[];
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const TestItemSchema =
|
|
21
|
-
id:
|
|
22
|
-
name:
|
|
23
|
-
icon:
|
|
24
|
-
items:
|
|
20
|
+
export const TestItemSchema = Schema.Struct({
|
|
21
|
+
id: ObjectId,
|
|
22
|
+
name: Schema.String,
|
|
23
|
+
icon: Schema.optional(Schema.String),
|
|
24
|
+
items: Schema.mutable(Schema.Array(Schema.suspend((): Schema.Schema<TestItem> => TestItemSchema))),
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
export const createTree = (n = 4, d = 4): TestItem => ({
|