@eventcatalog/core 2.65.0 → 3.0.0-beta.0

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 (130) hide show
  1. package/README.md +1 -26
  2. package/dist/analytics/analytics.cjs +1 -1
  3. package/dist/analytics/analytics.js +2 -2
  4. package/dist/analytics/log-build.cjs +1 -1
  5. package/dist/analytics/log-build.js +3 -3
  6. package/dist/{chunk-NK6OYMRD.js → chunk-JB4YT5JY.js} +1 -1
  7. package/dist/{chunk-BMDTX5IN.js → chunk-TQ4HZREX.js} +1 -1
  8. package/dist/{chunk-IJRFYF4B.js → chunk-X4W4YC3U.js} +1 -1
  9. package/dist/constants.cjs +1 -1
  10. package/dist/constants.js +1 -1
  11. package/dist/eventcatalog.cjs +1 -21
  12. package/dist/eventcatalog.config.d.cts +10 -0
  13. package/dist/eventcatalog.config.d.ts +10 -0
  14. package/dist/eventcatalog.js +3 -20
  15. package/eventcatalog/src/components/CopyAsMarkdown.tsx +19 -1
  16. package/eventcatalog/src/components/FavoriteButton.tsx +54 -0
  17. package/eventcatalog/src/components/Grids/DomainGrid.tsx +386 -362
  18. package/eventcatalog/src/components/Grids/MessageGrid.tsx +166 -518
  19. package/eventcatalog/src/components/Header.astro +48 -23
  20. package/eventcatalog/src/components/Lists/VersionList.astro +2 -2
  21. package/eventcatalog/src/components/MDX/Design/Design.astro +4 -1
  22. package/eventcatalog/src/components/MDX/Flow/Flow.astro +2 -1
  23. package/eventcatalog/src/components/MDX/NodeGraph/NodeGraph.astro +3 -3
  24. package/eventcatalog/src/components/SchemaExplorer/SchemaDetailsPanel.tsx +8 -2
  25. package/eventcatalog/src/components/SchemaExplorer/SchemaPageViewer.tsx +37 -0
  26. package/eventcatalog/src/components/Search/Search.astro +48 -28
  27. package/eventcatalog/src/components/Search/SearchModal.tsx +393 -702
  28. package/eventcatalog/src/components/SideNav/NestedSideBar/SearchBar.tsx +298 -0
  29. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/container.ts +66 -0
  30. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/domain.ts +101 -0
  31. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/flow.ts +29 -0
  32. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/message.ts +84 -0
  33. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/service.ts +147 -0
  34. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/shared.ts +146 -0
  35. package/eventcatalog/src/components/SideNav/NestedSideBar/index.tsx +1073 -0
  36. package/eventcatalog/src/components/SideNav/NestedSideBar/sidebar-builder.ts +365 -0
  37. package/eventcatalog/src/components/SideNav/NestedSideBar/storage.ts +90 -0
  38. package/eventcatalog/src/components/SideNav/SideNav.astro +18 -28
  39. package/eventcatalog/src/content.config.ts +2 -0
  40. package/eventcatalog/src/enterprise/custom-documentation/pages/docs/custom/index.astro +10 -4
  41. package/eventcatalog/src/enterprise/eventcatalog-chat/pages/chat/index.astro +3 -3
  42. package/eventcatalog/src/layouts/DirectoryLayout.astro +2 -2
  43. package/eventcatalog/src/layouts/DiscoverLayout.astro +3 -3
  44. package/eventcatalog/src/layouts/VerticalSideBarLayout.astro +85 -63
  45. package/eventcatalog/src/layouts/VisualiserLayout.astro +3 -3
  46. package/eventcatalog/src/pages/_index.astro +530 -110
  47. package/eventcatalog/src/pages/architecture/[type]/[id]/[version]/_index.data.ts +64 -0
  48. package/eventcatalog/src/pages/architecture/[type]/[id]/[version]/index.astro +29 -0
  49. package/eventcatalog/src/pages/directory/[type]/_index.data.ts +4 -4
  50. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/_index.data.ts +1 -4
  51. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/changelog/_index.data.ts +3 -3
  52. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/changelog/index.astro +1 -5
  53. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/index.astro +362 -190
  54. package/eventcatalog/src/pages/docs/[type]/[id]/[version].md.ts +1 -1
  55. package/eventcatalog/src/pages/docs/[type]/[id]/index.astro +4 -4
  56. package/eventcatalog/src/pages/docs/[type]/[id]/language/_index.data.ts +1 -4
  57. package/eventcatalog/src/pages/docs/[type]/[id]/language/index.astro +3 -27
  58. package/eventcatalog/src/pages/docs/teams/[id]/_index.data.ts +2 -2
  59. package/eventcatalog/src/pages/docs/users/[id]/_index.data.ts +2 -2
  60. package/eventcatalog/src/pages/index.astro +14 -5
  61. package/eventcatalog/src/pages/nav-index.json.ts +30 -0
  62. package/eventcatalog/src/pages/schemas/[type]/[id]/[version]/_index.data.ts +77 -0
  63. package/eventcatalog/src/pages/schemas/[type]/[id]/[version]/index.astro +90 -0
  64. package/eventcatalog/src/pages/schemas/{index.astro → explorer/index.astro} +3 -3
  65. package/eventcatalog/src/pages/studio.astro +3 -3
  66. package/eventcatalog/src/pages/visualiser/[type]/[id]/[version]/_index.data.ts +4 -3
  67. package/eventcatalog/src/pages/visualiser/[type]/[id]/index.astro +2 -2
  68. package/eventcatalog/src/pages/visualiser/domains/[id]/[version]/entity-map/_index.data.ts +4 -3
  69. package/eventcatalog/src/stores/favorites-store.ts +83 -0
  70. package/eventcatalog/src/stores/sidebar-store.ts +8 -0
  71. package/eventcatalog/src/utils/collections/changelogs.ts +7 -4
  72. package/eventcatalog/src/utils/{channels.ts → collections/channels.ts} +81 -31
  73. package/eventcatalog/src/utils/collections/commands.ts +134 -0
  74. package/eventcatalog/src/utils/collections/containers.ts +44 -33
  75. package/eventcatalog/src/utils/collections/domains.ts +204 -62
  76. package/eventcatalog/src/utils/{entities.ts → collections/entities.ts} +44 -24
  77. package/eventcatalog/src/utils/collections/events.ts +136 -0
  78. package/eventcatalog/src/utils/collections/flows.ts +59 -25
  79. package/eventcatalog/src/utils/{messages.ts → collections/messages.ts} +13 -4
  80. package/eventcatalog/src/utils/{queries.ts → collections/queries.ts} +49 -28
  81. package/eventcatalog/src/utils/collections/services.ts +100 -68
  82. package/eventcatalog/src/utils/collections/teams.ts +94 -0
  83. package/eventcatalog/src/utils/collections/users.ts +122 -0
  84. package/eventcatalog/src/utils/collections/util.ts +57 -1
  85. package/eventcatalog/src/utils/feature.ts +3 -1
  86. package/eventcatalog/src/utils/{collections/file-diffs.ts → file-diffs.ts} +1 -1
  87. package/eventcatalog/src/utils/node-graphs/container-node-graph.ts +2 -0
  88. package/eventcatalog/src/utils/node-graphs/domain-entity-map.ts +16 -6
  89. package/eventcatalog/src/utils/node-graphs/domains-canvas.ts +14 -10
  90. package/eventcatalog/src/utils/node-graphs/domains-node-graph.ts +36 -64
  91. package/eventcatalog/src/utils/node-graphs/flows-node-graph.ts +23 -19
  92. package/eventcatalog/src/utils/node-graphs/message-node-graph.ts +36 -49
  93. package/eventcatalog/src/utils/node-graphs/services-node-graph.ts +22 -18
  94. package/eventcatalog/src/utils/page-loaders/page-data-loader.ts +4 -4
  95. package/eventcatalog/tailwind.config.mjs +14 -0
  96. package/eventcatalog/tsconfig.json +2 -1
  97. package/package.json +7 -4
  98. package/eventcatalog/public/logo_old.png +0 -0
  99. package/eventcatalog/src/components/DiscoverInsight.astro +0 -61
  100. package/eventcatalog/src/components/Grids/ServiceGrid.tsx +0 -534
  101. package/eventcatalog/src/components/Lists/CustomSideBarSectionList.astro +0 -55
  102. package/eventcatalog/src/components/Lists/ProtocolList.tsx +0 -74
  103. package/eventcatalog/src/components/Lists/RepositoryList.astro +0 -37
  104. package/eventcatalog/src/components/Lists/SpecificationsList.astro +0 -67
  105. package/eventcatalog/src/components/SideBars/ChannelSideBar.astro +0 -204
  106. package/eventcatalog/src/components/SideBars/ContainerSideBar.astro +0 -180
  107. package/eventcatalog/src/components/SideBars/DomainSideBar.astro +0 -273
  108. package/eventcatalog/src/components/SideBars/EntitySideBar.astro +0 -139
  109. package/eventcatalog/src/components/SideBars/FlowSideBar.astro +0 -128
  110. package/eventcatalog/src/components/SideBars/MessageSideBar.astro +0 -248
  111. package/eventcatalog/src/components/SideBars/ServiceSideBar.astro +0 -294
  112. package/eventcatalog/src/components/SideNav/ListViewSideBar/components/CollapsibleGroup.tsx +0 -46
  113. package/eventcatalog/src/components/SideNav/ListViewSideBar/components/MessageList.tsx +0 -78
  114. package/eventcatalog/src/components/SideNav/ListViewSideBar/components/SpecificationList.tsx +0 -83
  115. package/eventcatalog/src/components/SideNav/ListViewSideBar/index.tsx +0 -1250
  116. package/eventcatalog/src/components/SideNav/ListViewSideBar/types.ts +0 -91
  117. package/eventcatalog/src/components/SideNav/ListViewSideBar/utils.ts +0 -201
  118. package/eventcatalog/src/components/SideNav/TreeView/getTreeView.ts +0 -190
  119. package/eventcatalog/src/components/SideNav/TreeView/index.tsx +0 -94
  120. package/eventcatalog/src/components/TreeView/index.tsx +0 -328
  121. package/eventcatalog/src/components/TreeView/styles.module.css +0 -264
  122. package/eventcatalog/src/components/TreeView/useSlots.ts +0 -95
  123. package/eventcatalog/src/pages/architecture/[type]/index.astro +0 -14
  124. package/eventcatalog/src/pages/architecture/architecture.astro +0 -101
  125. package/eventcatalog/src/pages/architecture/docs/[type]/index.astro +0 -14
  126. package/eventcatalog/src/utils/commands.ts +0 -112
  127. package/eventcatalog/src/utils/events.ts +0 -108
  128. package/eventcatalog/src/utils/generators/index.ts +0 -10
  129. package/eventcatalog/src/utils/teams.ts +0 -72
  130. package/eventcatalog/src/utils/users.ts +0 -72
@@ -1,91 +0,0 @@
1
- export interface MessageItem {
2
- href: string;
3
- label: string;
4
- service: string;
5
- id: string;
6
- direction: 'sends' | 'receives';
7
- type: 'command' | 'query' | 'event';
8
- collection: string;
9
- data: {
10
- name: string;
11
- };
12
- }
13
-
14
- export interface EntityItem {
15
- href: string;
16
- label: string;
17
- id: string;
18
- name: string;
19
- }
20
-
21
- export interface ServiceItem {
22
- href: string;
23
- label: string;
24
- name: string;
25
- id: string;
26
- version: string;
27
- sidebar?: {
28
- badge?: string;
29
- color?: string;
30
- backgroundColor?: string;
31
- };
32
- draft: boolean | { title?: string; message: string };
33
- sends: MessageItem[];
34
- receives: MessageItem[];
35
- entities: EntityItem[];
36
- writesTo: MessageItem[];
37
- readsFrom: MessageItem[];
38
- specifications?: {
39
- type: string;
40
- path: string;
41
- name?: string;
42
- filename?: string;
43
- filenameWithoutExtension?: string;
44
- }[];
45
- }
46
-
47
- export interface DomainItem {
48
- href: string;
49
- label: string;
50
- id: string;
51
- name: string;
52
- services: any[];
53
- domains: any[];
54
- entities: EntityItem[];
55
- }
56
-
57
- export interface FlowItem {
58
- href: string;
59
- label: string;
60
- }
61
-
62
- export interface DesignItem {
63
- href: string;
64
- label: string;
65
- id: string;
66
- name: string;
67
- }
68
-
69
- export interface Resources {
70
- 'context-map'?: Array<{
71
- href: string;
72
- label: string;
73
- id: string;
74
- name: string;
75
- }>;
76
- domains?: DomainItem[];
77
- services?: ServiceItem[];
78
- flows?: FlowItem[];
79
- designs?: DesignItem[];
80
- messagesNotInService?: MessageItem[];
81
- commands?: MessageItem[];
82
- queries?: MessageItem[];
83
- events?: MessageItem[];
84
- containers?: MessageItem[];
85
- }
86
-
87
- export interface ListViewSideBarProps {
88
- resources: Resources;
89
- currentPath: string;
90
- showOrphanedMessages: boolean;
91
- }
@@ -1,201 +0,0 @@
1
- import { isCollectionVisibleInCatalog } from '@eventcatalog';
2
- import { buildUrl } from '@utils/url-builder';
3
- import { getChannels } from '@utils/channels';
4
- import { getDomains } from '@utils/collections/domains';
5
- import { getFlows } from '@utils/collections/flows';
6
- import { getServices, getSpecificationsForService } from '@utils/collections/services';
7
- import { getCommands } from '@utils/commands';
8
- import { getEvents } from '@utils/events';
9
- import { getQueries } from '@utils/queries';
10
- import { getDesigns } from '@utils/collections/designs';
11
- import { getContainers } from '@utils/collections/containers';
12
-
13
- const stripCollection = (collection: any) => {
14
- return collection.map((item: any) => ({
15
- data: {
16
- id: item.data.id,
17
- version: item.data.version,
18
- },
19
- }));
20
- };
21
-
22
- export async function getResourcesForNavigation({ currentPath }: { currentPath: string }) {
23
- const events = await getEvents({ getAllVersions: false });
24
- const commands = await getCommands({ getAllVersions: false });
25
- const queries = await getQueries({ getAllVersions: false });
26
- const services = await getServices({ getAllVersions: false });
27
- const domains = await getDomains({ getAllVersions: false });
28
- const channels = await getChannels({ getAllVersions: false });
29
- const flows = await getFlows({ getAllVersions: false });
30
- const containers = await getContainers({ getAllVersions: false });
31
- const designs = await getDesigns({ getAllVersions: false });
32
-
33
- const messages = [...events, ...commands, ...queries];
34
-
35
- // messages that are not in a service (sends or receives)
36
- const messagesNotInService = messages.filter(
37
- (message) =>
38
- !services.some(
39
- (service) =>
40
- service.data?.sends?.some((send: any) => send.data.id === message.data.id) ||
41
- service.data?.receives?.some((receive: any) => receive.data.id === message.data.id)
42
- )
43
- );
44
-
45
- const route = currentPath.includes('visualiser') ? 'visualiser' : 'docs';
46
-
47
- // Just the domains for now.
48
- const allDataAsSideNav = [...domains, ...services, ...flows, ...channels, ...containers].reduce((acc, item) => {
49
- const title = item.collection;
50
- const group = acc[title] || [];
51
-
52
- const isCollectionDomain = item.collection === 'domains';
53
- const isCollectionService = item.collection === 'services';
54
-
55
- const servicesCount = isCollectionDomain ? item.data.services?.length || 0 : 0;
56
- const sends = isCollectionService ? item.data.sends || null : null;
57
- const receives = isCollectionService ? item.data.receives || null : null;
58
- const entities = isCollectionDomain || isCollectionService ? item.data.entities || null : null;
59
-
60
- const writesTo = isCollectionService ? item.data.writesTo || null : null;
61
- const readsFrom = isCollectionService ? item.data.readsFrom || null : null;
62
-
63
- // Add href to the sends and receives
64
- const sendsWithHref = sends?.map((send: any) => ({
65
- id: send.data.id,
66
- data: {
67
- name: send.data.name,
68
- sidebar: send.data.sidebar,
69
- aggregateRoot: send?.data?.aggregateRoot,
70
- draft: send.data.draft,
71
- },
72
- collection: send.collection,
73
- href: buildUrl(`/${route}/${send.collection}/${send.data.id}/${send.data.version}`),
74
- }));
75
- const receivesWithHref = receives?.map((receive: any) => ({
76
- id: receive.data.id,
77
- data: {
78
- name: receive.data.name,
79
- sidebar: receive.data.sidebar,
80
- aggregateRoot: receive?.data?.aggregateRoot,
81
- draft: receive.data.draft,
82
- },
83
- collection: receive.collection,
84
- href: buildUrl(`/${route}/${receive.collection}/${receive.data.id}/${receive.data.version}`),
85
- }));
86
- const entitiesWithHref = entities?.map((entity: any) => ({
87
- id: entity.data.id,
88
- data: {
89
- name: entity.data.name,
90
- sidebar: entity.data.sidebar,
91
- aggregateRoot: entity?.data?.aggregateRoot,
92
- draft: entity.data.draft,
93
- },
94
- collection: entity.collection,
95
- href: buildUrl(`/${route}/${entity.collection}/${entity.data.id}/${entity.data.version}`),
96
- }));
97
-
98
- const writesToWithHref = writesTo?.map((writeTo: any) => ({
99
- id: writeTo.data.id,
100
- data: {
101
- name: writeTo.data.name,
102
- sidebar: {
103
- badge: writeTo.data.container_type || writeTo.collection,
104
- backgroundColor: 'bg-blue-100 text-blue-600',
105
- },
106
- },
107
- collection: writeTo.collection,
108
- href: buildUrl(`/${route}/${writeTo.collection}/${writeTo.data.id}/${writeTo.data.version}`),
109
- }));
110
-
111
- const readsFromWithHref = readsFrom?.map((readFrom: any) => ({
112
- id: readFrom.data.id,
113
- data: {
114
- name: readFrom.data.name,
115
- sidebar: {
116
- badge: readFrom.data.container_type || readFrom.collection,
117
- backgroundColor: 'bg-blue-100 text-indigo-600',
118
- },
119
- },
120
- collection: readFrom.collection,
121
- href: buildUrl(`/${route}/${readFrom.collection}/${readFrom.data.id}/${readFrom.data.version}`),
122
- }));
123
-
124
- // don't render items if we are in the visualiser and the item has visualiser set to false
125
- if (currentPath.includes('visualiser') && item.data.visualiser === false) {
126
- return acc;
127
- }
128
-
129
- const navigationItem = {
130
- label: item.data.name,
131
- version: item.data.version,
132
- // items: item.collection === 'users' ? [] : item.headings,
133
- visible: isCollectionVisibleInCatalog(item.collection),
134
- // @ts-ignore
135
- href: item.data.version
136
- ? // @ts-ignore
137
- buildUrl(`/${route}/${item.collection}/${item.data.id}/${item.data.version}`)
138
- : buildUrl(`/${route}/${item.collection}/${item.data.id}`),
139
- collection: item.collection,
140
- servicesCount,
141
- id: item.data.id,
142
- name: item.data.name,
143
- draft: item.data.draft,
144
- services: isCollectionDomain ? stripCollection(item.data.services) : null,
145
- domains: isCollectionDomain ? stripCollection(item.data.domains) : null,
146
- sends: sendsWithHref,
147
- receives: receivesWithHref,
148
- entities: entitiesWithHref,
149
- specifications: isCollectionService ? getSpecificationsForService(item) : null,
150
- writesTo: writesToWithHref,
151
- readsFrom: readsFromWithHref,
152
- sidebar: item.data?.sidebar,
153
- renderInVisualiser: item.data?.visualiser ?? true,
154
- };
155
-
156
- group.push(navigationItem);
157
-
158
- return {
159
- ...acc,
160
- [title]: group,
161
- };
162
- }, {} as any);
163
-
164
- // Add messagesNotInService
165
- const messagesNotInServiceAsSideNav = messagesNotInService.map((item) => ({
166
- label: item.data.name,
167
- version: item.data.version,
168
- id: item.data.id,
169
- name: item.data.name,
170
- draft: item.data.draft,
171
- href: buildUrl(`/${route}/${item.collection}/${item.data.id}/${item.data.version}`),
172
- collection: item.collection,
173
- }));
174
-
175
- const sideNav = {
176
- ...(currentPath.includes('visualiser')
177
- ? {
178
- 'context-map': [
179
- {
180
- label: 'Domain Integration Map',
181
- href: buildUrl('/visualiser/domain-integrations'),
182
- collection: 'domain-integrations',
183
- },
184
- ],
185
- }
186
- : {}),
187
- ...allDataAsSideNav,
188
- messagesNotInService: messagesNotInServiceAsSideNav,
189
- };
190
-
191
- // Add designs?
192
- if (designs.length > 0) {
193
- sideNav['designs'] = designs.map((design) => ({
194
- label: design.data.name,
195
- href: buildUrl(`/visualiser/designs/${design.data.id}`),
196
- collection: 'designs',
197
- }));
198
- }
199
-
200
- return sideNav;
201
- }
@@ -1,190 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import os from 'node:os';
4
- import gm from 'gray-matter';
5
- import { globSync } from 'glob';
6
- import type { CollectionKey } from 'astro:content';
7
- import { buildUrl } from '@utils/url-builder';
8
-
9
- export type TreeNode = {
10
- id: string;
11
- name: string;
12
- version: string;
13
- href?: string;
14
- type: CollectionKey | null;
15
- children: TreeNode[];
16
- };
17
-
18
- /**
19
- * Resource types that should be in the sidenav
20
- */
21
- const RESOURCE_TYPES = ['domains', 'entities', 'services', 'events', 'commands', 'queries', 'flows', 'channels', 'containers'];
22
- // const RESOURCE_TYPES = ['domains', 'services', 'events', 'commands', 'queries', 'flows', 'channels'];
23
-
24
- /**
25
- * Check if the path has a RESOURCE_TYPE on path
26
- */
27
- function canBeResource(dirPath: string) {
28
- const parts = dirPath.split(path.sep);
29
- for (let i = parts.length - 1; i >= 0; i--) {
30
- if (RESOURCE_TYPES.includes(parts[i])) return true;
31
- }
32
- return false;
33
- }
34
-
35
- function isNotVersioned(dirPath: string) {
36
- const parts = dirPath.split(path.sep);
37
- return parts.every((p) => p !== 'versioned');
38
- }
39
-
40
- function getResourceType(filePath: string): CollectionKey | null {
41
- const parts = filePath.split(path.sep);
42
- for (let i = parts.length - 1; i >= 0; i--) {
43
- if (RESOURCE_TYPES.includes(parts[i])) return parts[i] as CollectionKey;
44
- }
45
- return null;
46
- }
47
-
48
- function buildTreeOfDir(directory: string, parentNode: TreeNode, options: { ignore?: CollectionKey[] }) {
49
- let node: TreeNode | null = null;
50
-
51
- const resourceType = getResourceType(directory);
52
-
53
- const markdownFiles = globSync(path.join(directory, '/*.mdx'), { windowsPathsNoEscape: os.platform() === 'win32' });
54
- const isResourceIgnored = options?.ignore && resourceType && options.ignore.includes(resourceType);
55
-
56
- if (markdownFiles.length > 0 && !isResourceIgnored) {
57
- const resourceFilePath = markdownFiles.find((md) => md.endsWith('index.mdx'));
58
- if (resourceFilePath) {
59
- const resourceDef = gm.read(resourceFilePath);
60
- node = {
61
- id: resourceDef.data.id,
62
- name: resourceDef.data.name,
63
- type: resourceType,
64
- version: resourceDef.data.version,
65
- children: [],
66
- };
67
- parentNode.children.push(node);
68
- }
69
- }
70
-
71
- const directories = fs.readdirSync(directory).filter((name) => {
72
- const dirPath = path.join(directory, name);
73
- return fs.statSync(dirPath).isDirectory() && isNotVersioned(dirPath) && canBeResource(dirPath);
74
- });
75
- for (const dir of directories) {
76
- buildTreeOfDir(path.join(directory, dir), node || parentNode, options);
77
- }
78
- }
79
-
80
- function forEachTreeNodeOf(node: TreeNode, ...callbacks: Array<(node: TreeNode) => void>) {
81
- const next = node.children;
82
-
83
- callbacks.forEach((cb) => cb(node));
84
-
85
- // Go to next level
86
- next.forEach((n) => {
87
- forEachTreeNodeOf(n, ...callbacks);
88
- });
89
- }
90
-
91
- function addHrefToNode(basePathname: 'docs' | 'visualiser') {
92
- return (node: TreeNode) => {
93
- node.href = encodeURI(
94
- buildUrl(
95
- `/${basePathname}/${node.type}/${node.id}${node.type === 'teams' || node.type === 'users' ? '' : `/${node.version}`}`
96
- )
97
- );
98
- };
99
- }
100
-
101
- function orderChildrenByName(parentNode: TreeNode) {
102
- parentNode.children.sort((a, b) => a.name.localeCompare(b.name));
103
- }
104
-
105
- function groupChildrenByType(parentNode: TreeNode) {
106
- if (parentNode.children.length === 0) return; // Only group if there are children
107
-
108
- const acc: Record<string, TreeNode[]> = {};
109
-
110
- // Flows and messages are collapsed by default
111
-
112
- parentNode.children.forEach((n) => {
113
- if (n.type === null) return; // TODO: Just ignore or remove the type null???
114
- if (!(n.type in acc)) acc[n.type] = [];
115
- acc[n.type].push(n);
116
- });
117
-
118
- // Collapse everything except domains
119
- const AUTO_EXPANDED_TYPES = ['domains'];
120
-
121
- parentNode.children = Object.entries(acc)
122
- // Order label nodes by RESOURCE_TYPES
123
- .sort(([aType], [bType]) => RESOURCE_TYPES.indexOf(aType) - RESOURCE_TYPES.indexOf(bType))
124
- // Construct the label nodes
125
- .map(([type, nodes]) => {
126
- return {
127
- id: `${parentNode.id}/${type}`,
128
- name: type === 'containers' ? 'Data' : type,
129
- type: type as CollectionKey,
130
- version: '0',
131
- children: nodes,
132
- isExpanded: AUTO_EXPANDED_TYPES.includes(type),
133
- isLabel: true,
134
- };
135
- });
136
- }
137
-
138
- const treeViewCache = new Map<string, TreeNode>();
139
-
140
- export function getTreeView({ projectDir, currentPath }: { projectDir: string; currentPath: string }): TreeNode {
141
- const basePathname = currentPath.split('/').find((p) => p === 'docs' || p === 'visualiser') || 'docs';
142
-
143
- const cacheKey = `${projectDir}:${basePathname}`;
144
- if (treeViewCache.has(cacheKey)) return treeViewCache.get(cacheKey)!;
145
-
146
- const rootNode: TreeNode = {
147
- id: '/',
148
- name: 'root',
149
- type: null,
150
- version: '0',
151
- children: [],
152
- };
153
-
154
- buildTreeOfDir(projectDir, rootNode, {
155
- ignore: basePathname === 'visualiser' ? ['teams', 'users', 'channels'] : undefined,
156
- });
157
-
158
- // prettier-ignore
159
- forEachTreeNodeOf(
160
- rootNode,
161
- addHrefToNode(basePathname),
162
- orderChildrenByName,
163
- groupChildrenByType,
164
- );
165
-
166
- if (basePathname === 'visualiser') {
167
- rootNode.children.unshift({
168
- id: '/bounded-context-map',
169
- name: 'bounded context map',
170
- type: 'bounded-context-map' as any,
171
- version: '0',
172
- isLabel: true,
173
- children: [
174
- {
175
- id: '/domain-map',
176
- name: 'Domain map',
177
- href: buildUrl('/visualiser/context-map'),
178
- type: 'bounded-context-map' as any,
179
- version: '',
180
- children: [],
181
- },
182
- ],
183
- } as TreeNode);
184
- }
185
-
186
- // Store in cache before returning
187
- treeViewCache.set(cacheKey, rootNode);
188
-
189
- return rootNode;
190
- }
@@ -1,94 +0,0 @@
1
- import { gray } from 'tailwindcss/colors';
2
- import { TreeView } from '@components/TreeView';
3
- import { navigate } from 'astro:transitions/client';
4
- import type { TreeNode as RawTreeNode } from './getTreeView';
5
- import { getIconForCollection } from '@utils/collections/icons';
6
- import { useEffect, useState } from 'react';
7
-
8
- type TreeNode = RawTreeNode & { isLabel?: true; isDefaultExpanded?: boolean; isExpanded?: boolean };
9
-
10
- function isCurrentNode(node: TreeNode, currentPathname: string) {
11
- return currentPathname === node.href;
12
- }
13
-
14
- function TreeNode({ node }: { node: TreeNode }) {
15
- const Icon = getIconForCollection(node.type ?? '');
16
- const [isCurrent, setIsCurrent] = useState(document.location.pathname === node.href);
17
-
18
- useEffect(() => {
19
- const abortCtrl = new AbortController();
20
- // prettier-ignore
21
- document.addEventListener(
22
- 'astro:page-load',
23
- () => setIsCurrent(document.location.pathname === node.href),
24
- { signal: abortCtrl.signal },
25
- );
26
- return () => abortCtrl.abort();
27
- }, [document, node]);
28
-
29
- return (
30
- <TreeView.Item
31
- key={node.id}
32
- id={node.id}
33
- current={isCurrent}
34
- defaultExpanded={node?.isExpanded || node?.isDefaultExpanded}
35
- onSelect={node?.isLabel || !node?.href ? undefined : () => navigate(node.href!)}
36
- >
37
- {!node?.isLabel && (
38
- <TreeView.LeadingVisual>
39
- <Icon className="w-3 -ml-1" />
40
- </TreeView.LeadingVisual>
41
- )}
42
- <span
43
- className={node?.isLabel ? ' capitalize text-[13px] text-purple-900 font-extrabold' : 'font-light text-[14px] -ml-0.5'}
44
- >
45
- {node.name} {node.isLabel ? `(${node.children.length})` : ''}
46
- </span>
47
- {(node.children || []).length > 0 && (
48
- <TreeView.SubTree>
49
- {node.children!.map((childNode) => (
50
- <TreeNode key={childNode.id} node={childNode} />
51
- ))}
52
- </TreeView.SubTree>
53
- )}
54
- </TreeView.Item>
55
- );
56
- }
57
-
58
- export function SideNavTreeView({ tree }: { tree: TreeNode }) {
59
- function bubbleUpExpanded(parentNode: TreeNode) {
60
- if (isCurrentNode(parentNode, document.location.pathname)) return true;
61
- return (parentNode.isDefaultExpanded = parentNode.children.some(bubbleUpExpanded));
62
- }
63
- bubbleUpExpanded(tree);
64
-
65
- return (
66
- <nav id="resources-tree" className="px-2 py-2">
67
- <TreeView
68
- truncate={false}
69
- style={{
70
- // @ts-expect-error inline css var
71
- '--base-size-8': '0.5rem',
72
- '--base-size-12': '0.75rem',
73
- '--borderColor-muted': '#fff',
74
- '--borderRadius-medium': '0.375rem',
75
- '--borderWidth-thick': '0.125rem',
76
- '--borderWidth-thin': '0.0625rem',
77
- '--boxShadow-thick': 'inset 0 0 0 var(--borderWidth-thick)',
78
- '--control-transparent-bgColor-hover': '#656c7626',
79
- '--control-transparent-bgColor-selected': '#656c761a',
80
- // '--fgColor-accent': purple[700],
81
- '--fgColor-default': gray[600],
82
- '--fgColor-muted': gray[600],
83
- '--text-body-size-medium': '0.875rem',
84
- '--stack-gap-condensed': '0.5rem',
85
- '--treeViewItem-leadingVisual-iconColor-rest': 'var(--fgColor-muted)',
86
- }}
87
- >
88
- {tree.children.map((n) => (
89
- <TreeNode key={n.id} node={n} />
90
- ))}
91
- </TreeView>
92
- </nav>
93
- );
94
- }