@dxos/plugin-navtree 0.6.13 → 0.6.14-main.69511f5
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/{chunk-U7MTKDFQ.mjs → chunk-PSVCPL4T.mjs} +1 -1
- package/dist/lib/browser/chunk-PSVCPL4T.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +595 -392
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
- package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
- package/dist/types/src/components/HaloButton.stories.d.ts +5 -9
- package/dist/types/src/components/HaloButton.stories.d.ts.map +1 -1
- package/dist/types/src/components/NavBarStart.d.ts.map +1 -1
- package/dist/types/src/components/NavTree.d.ts +20 -0
- package/dist/types/src/components/NavTree.d.ts.map +1 -0
- package/dist/types/src/components/NavTree.stories.d.ts +7 -0
- package/dist/types/src/components/NavTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeContainer.d.ts +8 -8
- package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
- package/dist/types/src/components/NavTreeItemAction.d.ts +23 -0
- package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -0
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts +45 -0
- package/dist/types/src/components/NavTreeItemAction.stories.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/experimental/Tree.stories.d.ts +3 -7
- package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/stories/Graph.stories.d.ts +4 -12
- package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/testing/generator.d.ts +86 -0
- package/dist/types/src/testing/generator.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +3 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/visitor.d.ts +18 -0
- package/dist/types/src/testing/visitor.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +5 -10
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +41 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +8 -9
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +39 -34
- package/src/NavTreePlugin.tsx +89 -36
- package/src/components/CommandsDialog.tsx +2 -4
- package/src/components/HaloButton.stories.tsx +8 -6
- package/src/components/NavBarStart.tsx +2 -4
- package/src/components/NavTree.stories.tsx +104 -0
- package/src/components/NavTree.tsx +127 -0
- package/src/components/NavTreeContainer.tsx +132 -302
- package/src/components/NavTreeFooter.tsx +1 -1
- package/src/components/NavTreeItemAction.stories.tsx +57 -0
- package/src/components/NavTreeItemAction.tsx +367 -0
- package/src/components/index.ts +1 -0
- package/src/experimental/Tree.stories.tsx +11 -8
- package/src/experimental/Tree.tsx +2 -2
- package/src/meta.ts +3 -1
- package/src/stories/Graph.stories.tsx +111 -102
- package/src/testing/generator.ts +199 -0
- package/src/testing/index.ts +6 -0
- package/src/testing/visitor.ts +152 -0
- package/src/translations.ts +3 -3
- package/src/types.ts +50 -0
- package/src/util.ts +52 -63
- package/dist/lib/browser/chunk-U7MTKDFQ.mjs.map +0 -7
package/src/util.ts
CHANGED
|
@@ -12,19 +12,14 @@ import {
|
|
|
12
12
|
isAction,
|
|
13
13
|
} from '@dxos/app-graph';
|
|
14
14
|
import { Path } from '@dxos/react-ui-mosaic';
|
|
15
|
-
import {
|
|
16
|
-
type NavTreeActionNode,
|
|
17
|
-
type NavTreeItemActions,
|
|
18
|
-
type NavTreeItemNode,
|
|
19
|
-
type NavTreeItemNodeProperties,
|
|
20
|
-
type OpenItemIds,
|
|
21
|
-
} from '@dxos/react-ui-navtree';
|
|
22
15
|
import { type MaybePromise, nonNullable } from '@dxos/util';
|
|
23
16
|
|
|
17
|
+
import { type NodeProperties, type NavTreeItem } from './types';
|
|
18
|
+
|
|
24
19
|
export type NavTreeItemGraphNode = Node<
|
|
25
20
|
any,
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
Partial<
|
|
22
|
+
NodeProperties & {
|
|
28
23
|
persistenceClass: string;
|
|
29
24
|
persistenceKey: string;
|
|
30
25
|
acceptPersistenceClass: Set<string>;
|
|
@@ -33,9 +28,9 @@ export type NavTreeItemGraphNode = Node<
|
|
|
33
28
|
onCopy: (activeNode: NavTreeItemGraphNode, index?: number) => MaybePromise<void>;
|
|
34
29
|
onTransferStart: (activeNode: NavTreeItemGraphNode, index?: number) => MaybePromise<void>;
|
|
35
30
|
onTransferEnd: (activeNode: NavTreeItemGraphNode, destinationParent: NavTreeItemGraphNode) => MaybePromise<void>;
|
|
36
|
-
}
|
|
31
|
+
}
|
|
32
|
+
>
|
|
37
33
|
>;
|
|
38
|
-
export type NavTreeItem = NavTreeItemNode<NavTreeItemGraphNode>;
|
|
39
34
|
|
|
40
35
|
export const getParent = (
|
|
41
36
|
graph: Graph,
|
|
@@ -73,9 +68,9 @@ export const resolveMigrationOperation = (
|
|
|
73
68
|
const activeKey = activeNode.properties.persistenceKey;
|
|
74
69
|
if (activeKey && persistenceParent?.properties.acceptPersistenceKey) {
|
|
75
70
|
return persistenceParent.properties.acceptPersistenceKey.has(activeKey) &&
|
|
76
|
-
|
|
71
|
+
persistenceParent.properties.onTransferStart
|
|
77
72
|
? 'transfer'
|
|
78
|
-
:
|
|
73
|
+
: persistenceParent.properties.onCopy
|
|
79
74
|
? 'copy'
|
|
80
75
|
: 'reject';
|
|
81
76
|
} else {
|
|
@@ -103,7 +98,7 @@ export const sortActions = (actions: Action[]): Action[] =>
|
|
|
103
98
|
return 1;
|
|
104
99
|
});
|
|
105
100
|
|
|
106
|
-
export const getTreeItemNode = (treeItems:
|
|
101
|
+
export const getTreeItemNode = (treeItems: NavTreeItem[], path?: string[]): NavTreeItem | undefined => {
|
|
107
102
|
if (!path) {
|
|
108
103
|
return undefined;
|
|
109
104
|
}
|
|
@@ -117,7 +112,7 @@ export const getChildren = (
|
|
|
117
112
|
graph: Graph,
|
|
118
113
|
node: NavTreeItemGraphNode,
|
|
119
114
|
filter?: NodeFilter,
|
|
120
|
-
path: string[] = [],
|
|
115
|
+
path: readonly string[] = [],
|
|
121
116
|
): NavTreeItemGraphNode[] => {
|
|
122
117
|
return graph
|
|
123
118
|
.nodes(node, { relation: 'outbound', filter })
|
|
@@ -129,15 +124,19 @@ export const getChildren = (
|
|
|
129
124
|
.filter(nonNullable) as NavTreeItemGraphNode[];
|
|
130
125
|
};
|
|
131
126
|
|
|
132
|
-
type FlattenedActions = Required<Pick<
|
|
127
|
+
type FlattenedActions = Required<Pick<NavTreeItem, 'actions' | 'groupedActions'>>;
|
|
133
128
|
|
|
134
|
-
export const getActions = (graph: Graph, node:
|
|
129
|
+
export const getActions = (graph: Graph, node: Node): FlattenedActions => {
|
|
135
130
|
return graph.actions(node).reduce(
|
|
136
131
|
(acc: FlattenedActions, arg) => {
|
|
137
|
-
|
|
132
|
+
if (arg.properties.disposition === 'item') {
|
|
133
|
+
return acc;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
acc.actions.push(arg);
|
|
138
137
|
if (!isAction(arg)) {
|
|
139
138
|
const actionGroup = graph.actions(arg);
|
|
140
|
-
acc.groupedActions[arg.id] = actionGroup
|
|
139
|
+
acc.groupedActions[arg.id] = actionGroup;
|
|
141
140
|
}
|
|
142
141
|
return acc;
|
|
143
142
|
},
|
|
@@ -157,50 +156,39 @@ export const expandActions = (graph: Graph, node: Node) => {
|
|
|
157
156
|
return Promise.all([graph.expand(node, 'outbound', ACTION_TYPE), graph.expand(node, 'outbound', ACTION_GROUP_TYPE)]);
|
|
158
157
|
};
|
|
159
158
|
|
|
160
|
-
function* navTreeItemVisitor(
|
|
161
|
-
graph
|
|
162
|
-
node
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
actions: l0Actions,
|
|
177
|
-
groupedActions: l0GroupedActions,
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
|
|
159
|
+
function* navTreeItemVisitor({
|
|
160
|
+
graph,
|
|
161
|
+
node,
|
|
162
|
+
open,
|
|
163
|
+
getItem,
|
|
164
|
+
path = [],
|
|
165
|
+
filter,
|
|
166
|
+
}: {
|
|
167
|
+
graph: Graph;
|
|
168
|
+
node: NavTreeItemGraphNode;
|
|
169
|
+
open: string[];
|
|
170
|
+
getItem: (node: NavTreeItemGraphNode, parent: readonly string[], filter?: NodeFilter) => NavTreeItem;
|
|
171
|
+
path?: readonly string[];
|
|
172
|
+
filter?: NodeFilter;
|
|
173
|
+
}): Generator<NavTreeItem> {
|
|
174
|
+
const stack: NavTreeItem[] = [getItem(node, path, filter)];
|
|
181
175
|
while (stack.length > 0) {
|
|
182
176
|
const nextItem = stack.pop()!;
|
|
183
|
-
if (
|
|
177
|
+
if (nextItem.path.length > 1) {
|
|
184
178
|
yield nextItem;
|
|
185
179
|
}
|
|
186
|
-
const {
|
|
180
|
+
const { node, path } = nextItem;
|
|
187
181
|
const children = getChildren(graph, node, filter, path);
|
|
188
|
-
|
|
182
|
+
const actions = graph.actions(node);
|
|
183
|
+
if (path.length === 1 || open.includes(Path.create(...path))) {
|
|
184
|
+
for (let i = actions.length - 1; i >= 0; i--) {
|
|
185
|
+
if (actions[i].properties.disposition === 'item') {
|
|
186
|
+
stack.push(getItem(actions[i], path, filter));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
189
|
for (let i = children.length - 1; i >= 0; i--) {
|
|
190
190
|
const child = children[i] as NavTreeItemGraphNode;
|
|
191
|
-
|
|
192
|
-
const childChildren = getChildren(graph, child, filter, childPath);
|
|
193
|
-
const { actions: childActions, groupedActions: childGroupedActions } = getActions(graph, child);
|
|
194
|
-
stack.push({
|
|
195
|
-
id: Path.create(...childPath),
|
|
196
|
-
node: child,
|
|
197
|
-
path: childPath,
|
|
198
|
-
...((childChildren?.length ?? 0) > 0 && {
|
|
199
|
-
parentOf: childChildren!.map(({ id }) => Path.create(...childPath, id)),
|
|
200
|
-
}),
|
|
201
|
-
actions: childActions,
|
|
202
|
-
groupedActions: childGroupedActions,
|
|
203
|
-
});
|
|
191
|
+
stack.push(getItem(child, path, filter));
|
|
204
192
|
}
|
|
205
193
|
}
|
|
206
194
|
}
|
|
@@ -212,18 +200,19 @@ function* navTreeItemVisitor(
|
|
|
212
200
|
export const treeItemsFromRootNode = (
|
|
213
201
|
graph: Graph,
|
|
214
202
|
rootNode: NavTreeItemGraphNode,
|
|
215
|
-
|
|
216
|
-
|
|
203
|
+
open: string[],
|
|
204
|
+
getItem: (node: NavTreeItemGraphNode, parent: readonly string[]) => NavTreeItem,
|
|
205
|
+
path?: readonly string[],
|
|
217
206
|
filter?: NodeFilter,
|
|
218
207
|
): NavTreeItem[] => {
|
|
219
|
-
return Array.from(navTreeItemVisitor(graph, rootNode,
|
|
208
|
+
return Array.from(navTreeItemVisitor({ graph, node: rootNode, open, getItem, path, filter }));
|
|
220
209
|
};
|
|
221
210
|
|
|
222
|
-
export const expandOpenGraphNodes = (graph: Graph,
|
|
211
|
+
export const expandOpenGraphNodes = (graph: Graph, open: string[]) => {
|
|
223
212
|
return Promise.all(
|
|
224
|
-
|
|
225
|
-
.map((
|
|
226
|
-
const node = graph.findNode(Path.last(
|
|
213
|
+
open
|
|
214
|
+
.map((id) => {
|
|
215
|
+
const node = graph.findNode(Path.last(id));
|
|
227
216
|
return node && expandChildrenAndActions(graph, node as NavTreeItemGraphNode);
|
|
228
217
|
})
|
|
229
218
|
.filter(nonNullable),
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport const NAVTREE_PLUGIN = 'dxos.org/plugin/navtree';\n\n// TODO(wittjosiah): Factor out.\nexport const KEY_BINDING = 'KeyBinding';\n\nexport default {\n id: NAVTREE_PLUGIN,\n};\n"],
|
|
5
|
-
"mappings": ";AAIO,IAAMA,iBAAiB;AAGvB,IAAMC,cAAc;AAE3B,IAAA,eAAe;EACbC,IAAIF;AACN;",
|
|
6
|
-
"names": ["NAVTREE_PLUGIN", "KEY_BINDING", "id"]
|
|
7
|
-
}
|