@dxos/react-ui-mosaic 0.3.3-main.76bfae3 → 0.3.3-main.8043a2f
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 +65 -88
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/mosaic/Container.d.ts +1 -6
- package/dist/types/src/mosaic/Container.d.ts.map +1 -1
- package/dist/types/src/mosaic/Mosaic.d.ts +1 -2
- package/dist/types/src/mosaic/Mosaic.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/index.d.ts +1 -0
- package/dist/types/src/mosaic/hooks/index.d.ts.map +1 -1
- package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts +3 -0
- package/dist/types/src/mosaic/hooks/useItemsWithOrigin.d.ts.map +1 -0
- package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts +1 -2
- package/dist/types/src/mosaic/hooks/useItemsWithPreview.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +0 -7
- package/dist/types/src/testing/generator.d.ts.map +1 -1
- package/dist/types/src/views/Tree/Graph.stories.d.ts +1 -1
- package/dist/types/src/views/Tree/Tree.d.ts +2 -3
- package/dist/types/src/views/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/views/Tree/Tree.stories.d.ts +1 -1
- package/dist/types/src/views/Tree/testing.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/mosaic/Container.tsx +0 -9
- package/src/mosaic/Mosaic.ts +0 -3
- package/src/mosaic/hooks/index.ts +1 -0
- package/src/mosaic/hooks/useItemsWithOrigin.ts +33 -0
- package/src/mosaic/hooks/useItemsWithPreview.ts +24 -55
- package/src/testing/generator.ts +2 -5
- package/src/views/Tree/Tree.tsx +11 -20
- package/src/views/Tree/testing.tsx +2 -21
package/src/views/Tree/Tree.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { forwardRef
|
|
5
|
+
import React, { forwardRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Card, Tree as TreeComponent, TreeItem as TreeItemComponent } from '@dxos/react-ui';
|
|
8
8
|
import { dropRing, mx } from '@dxos/react-ui-theme';
|
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
useContainer,
|
|
16
16
|
useMosaic,
|
|
17
17
|
Path,
|
|
18
|
-
|
|
19
|
-
type MosaicCompareDataItem,
|
|
18
|
+
useItemsWithOrigin,
|
|
20
19
|
} from '../../mosaic';
|
|
21
20
|
|
|
22
21
|
// TODO(burdon): Tree data model that provides a pure abstraction of the plugin Graph.
|
|
@@ -27,7 +26,6 @@ import {
|
|
|
27
26
|
export type TreeProps<TData extends MosaicDataItem = TreeData> = MosaicContainerProps<TData, number> & {
|
|
28
27
|
items?: TData[];
|
|
29
28
|
debug?: boolean;
|
|
30
|
-
compare?: MosaicCompareDataItem;
|
|
31
29
|
};
|
|
32
30
|
|
|
33
31
|
export type TreeData = {
|
|
@@ -37,7 +35,7 @@ export type TreeData = {
|
|
|
37
35
|
};
|
|
38
36
|
|
|
39
37
|
// TODO(burdon): Make generic (and forwardRef).
|
|
40
|
-
export const Tree = ({ id, Component = TreeItem, onOver, onDrop, items = [], debug
|
|
38
|
+
export const Tree = ({ id, Component = TreeItem, onOver, onDrop, items = [], debug }: TreeProps) => {
|
|
41
39
|
return (
|
|
42
40
|
<Mosaic.Container
|
|
43
41
|
{...{
|
|
@@ -46,7 +44,6 @@ export const Tree = ({ id, Component = TreeItem, onOver, onDrop, items = [], deb
|
|
|
46
44
|
Component,
|
|
47
45
|
onOver,
|
|
48
46
|
onDrop,
|
|
49
|
-
compare,
|
|
50
47
|
}}
|
|
51
48
|
>
|
|
52
49
|
<TreeRoot items={items} />
|
|
@@ -55,16 +52,13 @@ export const Tree = ({ id, Component = TreeItem, onOver, onDrop, items = [], deb
|
|
|
55
52
|
};
|
|
56
53
|
|
|
57
54
|
const TreeRoot = ({ items }: { items: TreeData[] }) => {
|
|
58
|
-
const { id, Component
|
|
59
|
-
const
|
|
60
|
-
return compare ? [...items].sort(compare) : items;
|
|
61
|
-
}, [items, compare]);
|
|
62
|
-
const itemsWithPreview = useItemsWithPreview({ items: sortedItems, path: id, strategy: 'layout-stable' });
|
|
55
|
+
const { id, Component } = useContainer();
|
|
56
|
+
const itemsWithOrigin = useItemsWithOrigin(id, items);
|
|
63
57
|
|
|
64
58
|
return (
|
|
65
59
|
<TreeComponent.Root classNames='flex flex-col'>
|
|
66
|
-
<Mosaic.SortableContext id={id} items={
|
|
67
|
-
{
|
|
60
|
+
<Mosaic.SortableContext id={id} items={itemsWithOrigin} direction='vertical'>
|
|
61
|
+
{itemsWithOrigin.map((item, index) => (
|
|
68
62
|
<TreeItemComponent.Root key={item.id} collapsible defaultOpen>
|
|
69
63
|
<Mosaic.SortableTile item={item} path={id} position={index} Component={Component!} />
|
|
70
64
|
</TreeItemComponent.Root>
|
|
@@ -104,16 +98,13 @@ const TreeItem: MosaicTileComponent<TreeData> = forwardRef(
|
|
|
104
98
|
|
|
105
99
|
const TreeBranch = ({ path, items }: { path: string; items: TreeData[] }) => {
|
|
106
100
|
const { operation, overItem } = useMosaic();
|
|
107
|
-
const { Component
|
|
108
|
-
const
|
|
109
|
-
return compare ? [...items].sort(compare) : items;
|
|
110
|
-
}, [items, compare]);
|
|
111
|
-
const itemsWithPreview = useItemsWithPreview({ items: sortedItems, path, strategy: 'layout-stable' });
|
|
101
|
+
const { Component } = useContainer();
|
|
102
|
+
const itemsWithOrigin = useItemsWithOrigin(path, items);
|
|
112
103
|
|
|
113
104
|
return (
|
|
114
105
|
<TreeItemComponent.Body className='pis-4'>
|
|
115
|
-
<Mosaic.SortableContext id={path} items={
|
|
116
|
-
{
|
|
106
|
+
<Mosaic.SortableContext id={path} items={itemsWithOrigin} direction='vertical'>
|
|
107
|
+
{itemsWithOrigin.map((child, index) => (
|
|
117
108
|
<TreeComponent.Branch key={child.id}>
|
|
118
109
|
<TreeItemComponent.Root collapsible defaultOpen>
|
|
119
110
|
<Mosaic.SortableTile
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { faker } from '@faker-js/faker';
|
|
6
6
|
import React, { useCallback, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { type Graph, GraphBuilder
|
|
8
|
+
import { type Graph, GraphBuilder } from '@dxos/app-graph';
|
|
9
9
|
import { buildGraph } from '@dxos/app-graph/testing';
|
|
10
10
|
import { arrayMove } from '@dxos/util';
|
|
11
11
|
|
|
@@ -104,18 +104,6 @@ export const createGraph = () => {
|
|
|
104
104
|
return buildGraph(new GraphBuilder().build(), 'tree', content);
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
const graphNodeCompare = (a: Node, b: Node) => {
|
|
108
|
-
if (a.properties.index && b.properties.index) {
|
|
109
|
-
if (a.properties.index < b.properties.index) {
|
|
110
|
-
return -1;
|
|
111
|
-
} else if (a.properties.index > b.properties.index) {
|
|
112
|
-
return 1;
|
|
113
|
-
}
|
|
114
|
-
return 0;
|
|
115
|
-
}
|
|
116
|
-
return 0;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
107
|
export const GraphTree = ({ id, graph = createGraph(), debug }: { id: string; graph?: Graph; debug: boolean }) => {
|
|
120
108
|
const handleDrop = ({ operation, active, over }: MosaicDropEvent<number>) => {
|
|
121
109
|
// Moving within the tree.
|
|
@@ -145,13 +133,6 @@ export const GraphTree = ({ id, graph = createGraph(), debug }: { id: string; gr
|
|
|
145
133
|
const handleOver = (): MosaicOperation => 'transfer';
|
|
146
134
|
|
|
147
135
|
return (
|
|
148
|
-
<Tree
|
|
149
|
-
id={id}
|
|
150
|
-
items={graph.root.children as TreeData[]}
|
|
151
|
-
onDrop={handleDrop}
|
|
152
|
-
onOver={handleOver}
|
|
153
|
-
debug={debug}
|
|
154
|
-
compare={graphNodeCompare}
|
|
155
|
-
/>
|
|
136
|
+
<Tree id={id} items={graph.root.children as TreeData[]} onDrop={handleDrop} onOver={handleOver} debug={debug} />
|
|
156
137
|
);
|
|
157
138
|
};
|