@dxos/plugin-navtree 0.8.2-main.2f9c567 → 0.8.2-main.30e4dbb

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 (116) hide show
  1. package/dist/lib/browser/{chunk-FBQKXPOR.mjs → chunk-ZULGSU3L.mjs} +239 -204
  2. package/dist/lib/browser/chunk-ZULGSU3L.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +2 -2
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/{keyboard-IQXHKUWM.mjs → keyboard-2KXRP22I.mjs} +2 -2
  6. package/dist/lib/browser/{keyboard-IQXHKUWM.mjs.map → keyboard-2KXRP22I.mjs.map} +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/{react-surface-FQEYRV4Q.mjs → react-surface-BVZN7664.mjs} +2 -2
  9. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  10. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  11. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  12. package/dist/types/src/capabilities/keyboard.d.ts.map +1 -1
  13. package/dist/types/src/capabilities/state.d.ts.map +1 -1
  14. package/dist/types/src/components/CommandsDialog/CommandsDialog.d.ts.map +1 -0
  15. package/dist/types/src/components/CommandsDialog/CommandsTrigger.d.ts.map +1 -0
  16. package/dist/types/src/components/CommandsDialog/index.d.ts +3 -0
  17. package/dist/types/src/components/CommandsDialog/index.d.ts.map +1 -0
  18. package/dist/types/src/components/NavTree/NavTree.d.ts +8 -0
  19. package/dist/types/src/components/NavTree/NavTree.d.ts.map +1 -0
  20. package/dist/types/src/components/NavTree/NavTree.stories.d.ts +8 -0
  21. package/dist/types/src/components/NavTree/NavTree.stories.d.ts.map +1 -0
  22. package/dist/types/src/components/NavTree/index.d.ts +2 -0
  23. package/dist/types/src/components/NavTree/index.d.ts.map +1 -0
  24. package/dist/types/src/components/NavTreeContainer.d.ts.map +1 -1
  25. package/dist/types/src/components/NavTreeContext.d.ts.map +1 -1
  26. package/dist/types/src/components/NavTreeDocumentTitle.d.ts.map +1 -1
  27. package/dist/types/src/components/{NavTreeItemAction.d.ts → NavTreeItem/NavTreeItemAction.d.ts} +2 -3
  28. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.d.ts.map +1 -0
  29. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts +8 -0
  30. package/dist/types/src/components/NavTreeItem/NavTreeItemAction.stories.d.ts.map +1 -0
  31. package/dist/types/src/components/{NavTreeItemColumns.d.ts → NavTreeItem/NavTreeItemColumns.d.ts} +1 -1
  32. package/dist/types/src/components/NavTreeItem/NavTreeItemColumns.d.ts.map +1 -0
  33. package/dist/types/src/components/NavTreeItem/index.d.ts +3 -0
  34. package/dist/types/src/components/NavTreeItem/index.d.ts.map +1 -0
  35. package/dist/types/src/components/Sidebar/L0Menu.d.ts +13 -0
  36. package/dist/types/src/components/Sidebar/L0Menu.d.ts.map +1 -0
  37. package/dist/types/src/components/Sidebar/L1Panel.d.ts +15 -0
  38. package/dist/types/src/components/Sidebar/L1Panel.d.ts.map +1 -0
  39. package/dist/types/src/components/Sidebar/index.d.ts +3 -0
  40. package/dist/types/src/components/Sidebar/index.d.ts.map +1 -0
  41. package/dist/types/src/components/{UserAccountAvatar.d.ts → UserAccountAvatar/UserAccountAvatar.d.ts} +1 -1
  42. package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.d.ts.map +1 -0
  43. package/dist/types/src/components/{UserAccountAvatar.stories.d.ts → UserAccountAvatar/UserAccountAvatar.stories.d.ts} +1 -2
  44. package/dist/types/src/components/UserAccountAvatar/UserAccountAvatar.stories.d.ts.map +1 -0
  45. package/dist/types/src/components/UserAccountAvatar/index.d.ts +2 -0
  46. package/dist/types/src/components/UserAccountAvatar/index.d.ts.map +1 -0
  47. package/dist/types/src/components/index.d.ts +0 -1
  48. package/dist/types/src/components/index.d.ts.map +1 -1
  49. package/dist/types/src/components/types.d.ts +14 -15
  50. package/dist/types/src/components/types.d.ts.map +1 -1
  51. package/dist/types/src/experimental/Tree.d.ts.map +1 -1
  52. package/dist/types/src/hooks.d.ts.map +1 -1
  53. package/dist/types/src/testing/app-graph-builder.d.ts +11 -0
  54. package/dist/types/src/testing/app-graph-builder.d.ts.map +1 -0
  55. package/dist/types/src/testing/generator.d.ts +1 -0
  56. package/dist/types/src/testing/generator.d.ts.map +1 -1
  57. package/dist/types/src/testing/index.d.ts +1 -0
  58. package/dist/types/src/testing/index.d.ts.map +1 -1
  59. package/dist/types/src/testing/update-state.d.ts.map +1 -1
  60. package/dist/types/src/translations.d.ts +1 -1
  61. package/dist/types/src/util.d.ts +1 -1
  62. package/dist/types/src/util.d.ts.map +1 -1
  63. package/dist/types/tsconfig.tsbuildinfo +1 -1
  64. package/package.json +32 -31
  65. package/src/capabilities/keyboard.ts +1 -1
  66. package/src/components/{CommandsDialog.tsx → CommandsDialog/CommandsDialog.tsx} +2 -2
  67. package/src/components/{CommandsTrigger.tsx → CommandsDialog/CommandsTrigger.tsx} +1 -1
  68. package/src/components/CommandsDialog/index.ts +6 -0
  69. package/src/components/NavTree/NavTree.stories.tsx +87 -0
  70. package/src/components/{NavTree.tsx → NavTree/NavTree.tsx} +24 -11
  71. package/src/components/NavTree/index.ts +5 -0
  72. package/src/components/NavTreeContainer.tsx +35 -16
  73. package/src/components/NavTreeContext.tsx +1 -1
  74. package/src/components/{NavTreeItemAction.stories.tsx → NavTreeItem/NavTreeItemAction.stories.tsx} +12 -6
  75. package/src/components/{NavTreeItemAction.tsx → NavTreeItem/NavTreeItemAction.tsx} +13 -14
  76. package/src/components/{NavTreeItemColumns.tsx → NavTreeItem/NavTreeItemColumns.tsx} +5 -5
  77. package/src/components/NavTreeItem/index.ts +6 -0
  78. package/src/components/{L0Menu.tsx → Sidebar/L0Menu.tsx} +182 -129
  79. package/src/components/{L1Panels.tsx → Sidebar/L1Panel.tsx} +29 -48
  80. package/src/components/Sidebar/index.ts +6 -0
  81. package/src/components/{UserAccountAvatar.stories.tsx → UserAccountAvatar/UserAccountAvatar.stories.tsx} +5 -5
  82. package/src/components/{UserAccountAvatar.tsx → UserAccountAvatar/UserAccountAvatar.tsx} +6 -6
  83. package/src/components/UserAccountAvatar/index.ts +5 -0
  84. package/src/components/index.ts +0 -1
  85. package/src/components/types.ts +13 -15
  86. package/src/testing/app-graph-builder.ts +158 -0
  87. package/src/testing/generator.ts +2 -1
  88. package/src/testing/index.ts +1 -0
  89. package/src/translations.ts +1 -1
  90. package/dist/lib/browser/chunk-FBQKXPOR.mjs.map +0 -7
  91. package/dist/types/src/components/CommandsDialog.d.ts.map +0 -1
  92. package/dist/types/src/components/CommandsTrigger.d.ts.map +0 -1
  93. package/dist/types/src/components/L0Menu.d.ts +0 -10
  94. package/dist/types/src/components/L0Menu.d.ts.map +0 -1
  95. package/dist/types/src/components/L1Panels.d.ts +0 -14
  96. package/dist/types/src/components/L1Panels.d.ts.map +0 -1
  97. package/dist/types/src/components/NavTree.d.ts +0 -5
  98. package/dist/types/src/components/NavTree.d.ts.map +0 -1
  99. package/dist/types/src/components/NavTree.stories.d.ts +0 -7
  100. package/dist/types/src/components/NavTree.stories.d.ts.map +0 -1
  101. package/dist/types/src/components/NavTreeItemAction.d.ts.map +0 -1
  102. package/dist/types/src/components/NavTreeItemAction.stories.d.ts +0 -41
  103. package/dist/types/src/components/NavTreeItemAction.stories.d.ts.map +0 -1
  104. package/dist/types/src/components/NavTreeItemColumns.d.ts.map +0 -1
  105. package/dist/types/src/components/UserAccountAvatar.d.ts.map +0 -1
  106. package/dist/types/src/components/UserAccountAvatar.stories.d.ts.map +0 -1
  107. package/dist/types/src/stories/Graph.stories.d.ts +0 -7
  108. package/dist/types/src/stories/Graph.stories.d.ts.map +0 -1
  109. package/dist/types/src/stories/StorybookNavTree.d.ts +0 -4
  110. package/dist/types/src/stories/StorybookNavTree.d.ts.map +0 -1
  111. package/src/components/NavTree.stories.tsx +0 -107
  112. package/src/stories/Graph.stories.tsx +0 -130
  113. package/src/stories/StorybookNavTree.tsx +0 -63
  114. /package/dist/lib/browser/{react-surface-FQEYRV4Q.mjs.map → react-surface-BVZN7664.mjs.map} +0 -0
  115. /package/dist/types/src/components/{CommandsDialog.d.ts → CommandsDialog/CommandsDialog.d.ts} +0 -0
  116. /package/dist/types/src/components/{CommandsTrigger.d.ts → CommandsDialog/CommandsTrigger.d.ts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"NavTreeItemAction.d.ts","sourceRoot":"","sources":["../../../../src/components/NavTreeItemAction.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,gBAAgB,EAAU,MAAM,OAAO,CAAC;AAE7D,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAMzD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,MAAM,0BAA0B,GAAG,gBAAgB,GAAG;IAC1D,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,mBAAmB,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAaF,eAAO,MAAM,6BAA6B,oDAMvC,0BAA0B,sBAsB5B,CAAC;AAEF,eAAO,MAAM,2BAA2B,4GAKrC,MAAM,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,sBA0BnF,CAAC;AAEF,eAAO,MAAM,iBAAiB,wDAAyD,0BAA0B,sBAiBhH,CAAC"}
@@ -1,41 +0,0 @@
1
- import '@dxos-theme';
2
- import { type NavTreeItemActionMenuProps } from './NavTreeItemAction';
3
- declare const _default: {
4
- title: string;
5
- component: ({ monolithic, menuActions, parent: node, ...props }: NavTreeItemActionMenuProps) => import("react").JSX.Element;
6
- decorators: import("@storybook/react").Decorator[];
7
- args: {
8
- icon: string;
9
- parent: {
10
- id: string;
11
- type: string;
12
- data: null;
13
- properties: {
14
- label: string;
15
- icon: string;
16
- };
17
- };
18
- menuActions: {
19
- id: string;
20
- type: string;
21
- data: () => void;
22
- properties: {
23
- label: string;
24
- icon: string;
25
- };
26
- }[];
27
- label: string;
28
- onAction: (action: Readonly<Omit<Readonly<{
29
- id: string;
30
- type: string;
31
- cacheable?: string[];
32
- properties: Readonly<Record<string, any>>;
33
- data: import("@dxos/app-graph").ActionData;
34
- }>, "properties"> & {
35
- properties: Readonly<Record<string, any>>;
36
- }>) => void;
37
- };
38
- };
39
- export default _default;
40
- export declare const Default: {};
41
- //# sourceMappingURL=NavTreeItemAction.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NavTreeItemAction.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/NavTreeItemAction.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAMrB,OAAO,EAAqB,KAAK,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BzF,wBAaE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"NavTreeItemColumns.d.ts","sourceRoot":"","sources":["../../../../src/components/NavTreeItemColumns.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAyB,MAAM,OAAO,CAAC;AAQ9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIvD,eAAO,MAAM,kBAAkB,4DAAiD,uBAAuB,uBAwDrG,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"UserAccountAvatar.d.ts","sourceRoot":"","sources":["../../../../src/components/UserAccountAvatar.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAU,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtE,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,sBAAsB,sBAiB9D,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"UserAccountAvatar.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/UserAccountAvatar.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAO,MAAM,OAAO,UAAW,GAAG,sBAEjC,CAAC;AAEF,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,iBAAiB,CAGxC,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1,7 +0,0 @@
1
- import '@dxos-theme';
2
- import { type Meta } from '@storybook/react';
3
- import { StorybookNavTree } from './StorybookNavTree';
4
- export declare const Default: {};
5
- declare const meta: Meta<typeof StorybookNavTree>;
6
- export default meta;
7
- //# sourceMappingURL=Graph.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Graph.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/Graph.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAKrB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAW7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAiCtD,eAAO,MAAM,OAAO,IAAK,CAAC;AAE1B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,gBAAgB,CAwEvC,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { type NavTreeContextValue, type NavTreeProps } from '../components';
3
- export declare const StorybookNavTree: ({ getActions, loadDescendents, renderItemEnd, popoverAnchorId, getItems, getProps, isCurrent, canDrop, onSelect, isOpen, onOpenChange, ...props }: NavTreeProps & NavTreeContextValue) => React.JSX.Element;
4
- //# sourceMappingURL=StorybookNavTree.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorybookNavTree.d.ts","sourceRoot":"","sources":["../../../../src/stories/StorybookNavTree.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,OAAO,EAA2B,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAGrG,eAAO,MAAM,gBAAgB,sJAa1B,YAAY,GAAG,mBAAmB,sBAwCpC,CAAC"}
@@ -1,107 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
8
- import { extractInstruction, type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
9
- import { type Meta } from '@storybook/react';
10
- import React, { useEffect } from 'react';
11
-
12
- import { isActionLike, type NodeArg } from '@dxos/app-graph';
13
- import { live, type Live } from '@dxos/live-object';
14
- import { faker } from '@dxos/random';
15
- import { isTreeData, type TreeData } from '@dxos/react-ui-list';
16
- import { Path } from '@dxos/react-ui-list';
17
- import { withLayout, withTheme } from '@dxos/storybook-utils';
18
-
19
- import { StorybookNavTree } from '../stories/StorybookNavTree';
20
- import { createTree, updateState } from '../testing';
21
-
22
- faker.seed(1234);
23
-
24
- const tree = live<NodeArg<any>>(createTree());
25
- const state = new Map<string, Live<{ open: boolean; current: boolean }>>();
26
-
27
- const meta: Meta<typeof StorybookNavTree> = {
28
- title: 'plugins/plugin-navtree/NavTree',
29
- component: StorybookNavTree,
30
- decorators: [withTheme, withLayout({ tooltips: true })],
31
- render: (args) => {
32
- useEffect(() => {
33
- return monitorForElements({
34
- canMonitor: ({ source }) => isTreeData(source),
35
- onDrop: ({ location, source }) => {
36
- // Didn't drop on anything.
37
- if (!location.current.dropTargets.length) {
38
- return;
39
- }
40
-
41
- const target = location.current.dropTargets[0];
42
- const instruction: Instruction | null = extractInstruction(target.data);
43
- if (instruction !== null) {
44
- updateState({
45
- state: tree,
46
- instruction,
47
- source: source.data as TreeData,
48
- target: target.data as TreeData,
49
- });
50
- }
51
- },
52
- });
53
- }, []);
54
-
55
- return <StorybookNavTree {...args} />;
56
- },
57
- args: {
58
- id: tree.id,
59
- getActions: (arg: NodeArg<any>) => ({
60
- actions: arg.nodes?.filter((node) => isActionLike(node)) ?? [],
61
- groupedActions: {},
62
- }),
63
- getItems: (testItem?: any) => {
64
- return testItem?.nodes ?? tree.nodes ?? [];
65
- },
66
- getProps: (testItem: NodeArg<any>) => ({
67
- id: testItem.id,
68
- label: testItem.properties?.label ?? testItem.id,
69
- icon: testItem.properties?.icon,
70
- ...((testItem.nodes?.length ?? 0) > 0 && {
71
- parentOf: testItem.nodes!.map(({ id }) => id),
72
- }),
73
- }),
74
- isOpen: (_path: string[]) => {
75
- const path = Path.create(..._path);
76
- const value = state.get(path) ?? live({ open: false, current: false });
77
- if (!state.has(path)) {
78
- state.set(path, value);
79
- }
80
-
81
- return value.open;
82
- },
83
- isCurrent: (_path: string[]) => {
84
- const path = Path.create(..._path);
85
- const value = state.get(path) ?? live({ open: false, current: false });
86
- if (!state.has(path)) {
87
- state.set(path, value);
88
- }
89
-
90
- return value.current;
91
- },
92
- onOpenChange: ({ path: _path, open }) => {
93
- const path = Path.create(..._path);
94
- const object = state.get(path);
95
- object!.open = open;
96
- },
97
- onSelect: ({ path: _path, current }) => {
98
- const path = Path.create(..._path);
99
- const object = state.get(path);
100
- object!.current = current;
101
- },
102
- },
103
- };
104
-
105
- export default meta;
106
-
107
- export const Default = {};
@@ -1,130 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
8
- import { extractInstruction, type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
9
- import { batch } from '@preact/signals-core';
10
- import { type Meta } from '@storybook/react';
11
- import React, { useEffect } from 'react';
12
-
13
- import { Graph, ROOT_ID, type Node } from '@dxos/app-graph';
14
- import { registerSignalsRuntime } from '@dxos/echo-signals/react';
15
- import { live, type Live } from '@dxos/live-object';
16
- import { faker } from '@dxos/random';
17
- import { isTreeData, type PropsFromTreeItem } from '@dxos/react-ui-list';
18
- import { Path } from '@dxos/react-ui-list';
19
- import { withLayout, withTheme } from '@dxos/storybook-utils';
20
-
21
- import { StorybookNavTree } from './StorybookNavTree';
22
- import { getActions, getChildren } from '../util';
23
-
24
- faker.seed(3);
25
- registerSignalsRuntime();
26
-
27
- const createGraph = () => {
28
- const graph = new Graph();
29
-
30
- batch(() => {
31
- (graph as any)._addNode({
32
- id: ROOT_ID,
33
- nodes: [...Array(2)].map((_, i) => ({
34
- id: faker.string.hexadecimal({ length: 4 }).slice(2).toUpperCase(),
35
- properties: { index: `a${i}`, label: faker.lorem.words(2), description: faker.lorem.sentence() },
36
- nodes: [...Array(2)].map((_, j) => ({
37
- id: faker.string.hexadecimal({ length: 4 }).slice(2).toUpperCase(),
38
- properties: { index: `a${j}`, label: faker.lorem.words(2), description: faker.lorem.sentence() },
39
- nodes: [...Array(2)].map((_, k) => ({
40
- id: faker.string.hexadecimal({ length: 4 }).slice(2).toUpperCase(),
41
- properties: { index: `a${k}`, label: faker.lorem.words(2), description: faker.lorem.sentence() },
42
- })),
43
- })),
44
- })),
45
- });
46
- });
47
-
48
- return graph;
49
- };
50
-
51
- const graph = createGraph();
52
- const state = new Map<string, Live<{ open: boolean; current: boolean }>>();
53
-
54
- export const Default = {};
55
-
56
- const meta: Meta<typeof StorybookNavTree> = {
57
- title: 'plugins/plugin-navtree/Graph',
58
- component: StorybookNavTree,
59
- decorators: [withTheme, withLayout({ tooltips: true })],
60
- render: (args) => {
61
- useEffect(() => {
62
- return monitorForElements({
63
- canMonitor: ({ source }) => isTreeData(source.data),
64
- onDrop: ({ location, source }) => {
65
- // Didn't drop on anything.
66
- if (!location.current.dropTargets.length) {
67
- return;
68
- }
69
-
70
- const target = location.current.dropTargets[0];
71
-
72
- const instruction: Instruction | null = extractInstruction(target.data);
73
- if (instruction !== null) {
74
- // TODO(wittjosiah): Implement drop logic.
75
- console.log('update', instruction);
76
- }
77
- },
78
- });
79
- }, []);
80
-
81
- return <StorybookNavTree {...args} />;
82
- },
83
- args: {
84
- root: graph.root,
85
- id: graph.root.id,
86
- getActions: (node: Node) => getActions(graph, node),
87
- getItems: (node?: Node) => graph.nodes(node ?? graph.root),
88
- getProps: (node: Node, path: string[]) => {
89
- const children = getChildren(graph, node, undefined, path);
90
- const parentOf =
91
- children.length > 0 ? children.map(({ id }) => id) : node.properties.role === 'branch' ? [] : undefined;
92
- return {
93
- id: node.id,
94
- label: node.properties.label ?? node.id,
95
- icon: node.properties.icon,
96
- parentOf,
97
- } satisfies PropsFromTreeItem;
98
- },
99
- isOpen: (_path: string[]) => {
100
- const path = Path.create(..._path);
101
- const value = state.get(path) ?? live({ open: false, current: false });
102
- if (!state.has(path)) {
103
- state.set(path, value);
104
- }
105
-
106
- return value.open;
107
- },
108
- isCurrent: (_path: string[]) => {
109
- const path = Path.create(..._path);
110
- const value = state.get(path) ?? live({ open: false, current: false });
111
- if (!state.has(path)) {
112
- state.set(path, value);
113
- }
114
-
115
- return value.current;
116
- },
117
- onOpenChange: ({ path: _path, open }) => {
118
- const path = Path.create(..._path);
119
- const object = state.get(path);
120
- object!.open = open;
121
- },
122
- onSelect: ({ path: _path, current }) => {
123
- const path = Path.create(..._path);
124
- const object = state.get(path);
125
- object!.current = current;
126
- },
127
- },
128
- };
129
-
130
- export default meta;
@@ -1,63 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import React, { useMemo, useState } from 'react';
6
-
7
- import { NavTree, NavTreeContext, type NavTreeContextValue, type NavTreeProps } from '../components';
8
- import { type NavTreeItemGraphNode } from '../types';
9
-
10
- export const StorybookNavTree = ({
11
- getActions,
12
- loadDescendents,
13
- renderItemEnd,
14
- popoverAnchorId,
15
- getItems,
16
- getProps,
17
- isCurrent,
18
- canDrop,
19
- onSelect,
20
- isOpen,
21
- onOpenChange,
22
- ...props
23
- }: NavTreeProps & NavTreeContextValue) => {
24
- const [tab, setTab] = useState('never');
25
-
26
- const contextValue = useMemo(
27
- () => ({
28
- tab,
29
- onTabChange: (node: NavTreeItemGraphNode) => setTab(node.id),
30
- getActions,
31
- loadDescendents,
32
- renderItemEnd,
33
- popoverAnchorId,
34
- getItems,
35
- getProps,
36
- isCurrent,
37
- isOpen,
38
- onOpenChange,
39
- canDrop,
40
- onSelect,
41
- }),
42
- [
43
- tab,
44
- setTab,
45
- getActions,
46
- loadDescendents,
47
- renderItemEnd,
48
- popoverAnchorId,
49
- getItems,
50
- getProps,
51
- isCurrent,
52
- isOpen,
53
- onOpenChange,
54
- canDrop,
55
- onSelect,
56
- ],
57
- );
58
- return (
59
- <NavTreeContext.Provider value={contextValue}>
60
- <NavTree {...props} />
61
- </NavTreeContext.Provider>
62
- );
63
- };