@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.
Files changed (63) hide show
  1. package/dist/lib/browser/{chunk-U7MTKDFQ.mjs → chunk-PSVCPL4T.mjs} +1 -1
  2. package/dist/lib/browser/chunk-PSVCPL4T.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +595 -392
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/meta.mjs +1 -1
  7. package/dist/types/src/NavTreePlugin.d.ts.map +1 -1
  8. package/dist/types/src/components/CommandsDialog.d.ts.map +1 -1
  9. package/dist/types/src/components/HaloButton.stories.d.ts +5 -9
  10. package/dist/types/src/components/HaloButton.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/NavBarStart.d.ts.map +1 -1
  12. package/dist/types/src/components/NavTree.d.ts +20 -0
  13. package/dist/types/src/components/NavTree.d.ts.map +1 -0
  14. package/dist/types/src/components/NavTree.stories.d.ts +7 -0
  15. package/dist/types/src/components/NavTree.stories.d.ts.map +1 -0
  16. package/dist/types/src/components/NavTreeContainer.d.ts +8 -8
  17. package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
  18. package/dist/types/src/components/NavTreeItemAction.d.ts +23 -0
  19. package/dist/types/src/components/NavTreeItemAction.d.ts.map +1 -0
  20. package/dist/types/src/components/NavTreeItemAction.stories.d.ts +45 -0
  21. package/dist/types/src/components/NavTreeItemAction.stories.d.ts.map +1 -0
  22. package/dist/types/src/components/index.d.ts +1 -0
  23. package/dist/types/src/components/index.d.ts.map +1 -1
  24. package/dist/types/src/experimental/Tree.stories.d.ts +3 -7
  25. package/dist/types/src/experimental/Tree.stories.d.ts.map +1 -1
  26. package/dist/types/src/meta.d.ts.map +1 -1
  27. package/dist/types/src/stories/Graph.stories.d.ts +4 -12
  28. package/dist/types/src/stories/Graph.stories.d.ts.map +1 -1
  29. package/dist/types/src/testing/generator.d.ts +86 -0
  30. package/dist/types/src/testing/generator.d.ts.map +1 -0
  31. package/dist/types/src/testing/index.d.ts +3 -0
  32. package/dist/types/src/testing/index.d.ts.map +1 -0
  33. package/dist/types/src/testing/visitor.d.ts +18 -0
  34. package/dist/types/src/testing/visitor.d.ts.map +1 -0
  35. package/dist/types/src/translations.d.ts +5 -10
  36. package/dist/types/src/translations.d.ts.map +1 -1
  37. package/dist/types/src/types.d.ts +41 -0
  38. package/dist/types/src/types.d.ts.map +1 -0
  39. package/dist/types/src/util.d.ts +8 -9
  40. package/dist/types/src/util.d.ts.map +1 -1
  41. package/package.json +39 -34
  42. package/src/NavTreePlugin.tsx +89 -36
  43. package/src/components/CommandsDialog.tsx +2 -4
  44. package/src/components/HaloButton.stories.tsx +8 -6
  45. package/src/components/NavBarStart.tsx +2 -4
  46. package/src/components/NavTree.stories.tsx +104 -0
  47. package/src/components/NavTree.tsx +127 -0
  48. package/src/components/NavTreeContainer.tsx +132 -302
  49. package/src/components/NavTreeFooter.tsx +1 -1
  50. package/src/components/NavTreeItemAction.stories.tsx +57 -0
  51. package/src/components/NavTreeItemAction.tsx +367 -0
  52. package/src/components/index.ts +1 -0
  53. package/src/experimental/Tree.stories.tsx +11 -8
  54. package/src/experimental/Tree.tsx +2 -2
  55. package/src/meta.ts +3 -1
  56. package/src/stories/Graph.stories.tsx +111 -102
  57. package/src/testing/generator.ts +199 -0
  58. package/src/testing/index.ts +6 -0
  59. package/src/testing/visitor.ts +152 -0
  60. package/src/translations.ts +3 -3
  61. package/src/types.ts +50 -0
  62. package/src/util.ts +52 -63
  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
- NavTreeItemNodeProperties &
27
- Partial<{
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
- destinationRelatedNode.properties.onTransferStart
71
+ persistenceParent.properties.onTransferStart
77
72
  ? 'transfer'
78
- : destinationRelatedNode.properties.onCopy
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: NavTreeItemNode[], path?: string[]): NavTreeItemNode | undefined => {
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<NavTreeItemNode, 'actions' | 'groupedActions'>>;
127
+ type FlattenedActions = Required<Pick<NavTreeItem, 'actions' | 'groupedActions'>>;
133
128
 
134
- export const getActions = (graph: Graph, node: NavTreeItemGraphNode): FlattenedActions => {
129
+ export const getActions = (graph: Graph, node: Node): FlattenedActions => {
135
130
  return graph.actions(node).reduce(
136
131
  (acc: FlattenedActions, arg) => {
137
- acc.actions.push(arg as unknown as NavTreeItemActions[number]);
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 as unknown as NavTreeActionNode[];
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: Graph,
162
- node: NavTreeItemGraphNode,
163
- openItemIds: OpenItemIds,
164
- path: string[] = [],
165
- filter?: NodeFilter,
166
- ): Generator<NavTreeItem> {
167
- const l0Children = getChildren(graph, node, filter, path);
168
- const { actions: l0Actions, groupedActions: l0GroupedActions } = getActions(graph, node);
169
-
170
- const stack: NavTreeItem[] = [
171
- {
172
- id: node.id,
173
- node,
174
- path: [],
175
- parentOf: (l0Children ?? []).map(({ id }) => id),
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 ((nextItem.path?.length ?? 0) > 0) {
177
+ if (nextItem.path.length > 1) {
184
178
  yield nextItem;
185
179
  }
186
- const { id, node, path } = nextItem;
180
+ const { node, path } = nextItem;
187
181
  const children = getChildren(graph, node, filter, path);
188
- if (path?.length === 0 || (id ?? 'never') in openItemIds) {
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
- const childPath = path ? [...path, child.id] : [child.id];
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
- openItemIds: OpenItemIds,
216
- path: string[] = [],
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, openItemIds, path, filter));
208
+ return Array.from(navTreeItemVisitor({ graph, node: rootNode, open, getItem, path, filter }));
220
209
  };
221
210
 
222
- export const expandOpenGraphNodes = (graph: Graph, openItemIds: OpenItemIds) => {
211
+ export const expandOpenGraphNodes = (graph: Graph, open: string[]) => {
223
212
  return Promise.all(
224
- Object.keys(openItemIds)
225
- .map((openItemId) => {
226
- const node = graph.findNode(Path.last(openItemId));
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
- }