@mintlify/validation 0.1.638 → 0.1.640
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/editor-navigation/conversion/common.d.ts +29 -0
- package/dist/editor-navigation/conversion/common.js +95 -0
- package/dist/editor-navigation/conversion/docsjson-to-tree.d.ts +3 -0
- package/dist/editor-navigation/conversion/docsjson-to-tree.js +419 -0
- package/dist/editor-navigation/conversion/index.d.ts +3 -0
- package/dist/editor-navigation/conversion/index.js +3 -0
- package/dist/editor-navigation/conversion/tree-to-docsjson.d.ts +3 -0
- package/dist/editor-navigation/conversion/tree-to-docsjson.js +264 -0
- package/dist/editor-navigation/index.d.ts +4 -0
- package/dist/editor-navigation/index.js +4 -0
- package/dist/editor-navigation/schema.d.ts +2 -0
- package/dist/editor-navigation/schema.js +13 -0
- package/dist/editor-navigation/types.d.ts +130 -0
- package/dist/editor-navigation/types.js +11 -0
- package/dist/editor-navigation/utils.d.ts +5 -0
- package/dist/editor-navigation/utils.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mint-config/schemas/v2/properties/reusable/href.js +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { GroupConfig, TabConfig, AnchorConfig, LanguageConfig, VersionConfig, DropdownConfig, ProductConfig, MenuItemConfig } from '../../mint-config/schemas/v2/properties/index.js';
|
|
2
|
+
import type { NavigationTree, NavigationNode, NavigationNodeType } from '../types.js';
|
|
3
|
+
export type IdGenerator = () => string;
|
|
4
|
+
export type ParentInfo = {
|
|
5
|
+
id: string | 0;
|
|
6
|
+
order: number;
|
|
7
|
+
};
|
|
8
|
+
export type TreeNodeMap = Map<string | 0, NavigationNode[]>;
|
|
9
|
+
export declare const createIdGenerator: () => IdGenerator;
|
|
10
|
+
export declare function isProductConfig(value: unknown): value is ProductConfig;
|
|
11
|
+
export declare function isLanguageConfig(value: unknown): value is LanguageConfig;
|
|
12
|
+
export declare function isVersionConfig(value: unknown): value is VersionConfig;
|
|
13
|
+
export declare function isTabConfig(value: unknown): value is TabConfig;
|
|
14
|
+
export declare function isMenuItemConfig(value: unknown): value is MenuItemConfig;
|
|
15
|
+
export declare function isDropdownConfig(value: unknown): value is DropdownConfig;
|
|
16
|
+
export declare function isAnchorConfig(value: unknown): value is AnchorConfig;
|
|
17
|
+
export declare function isGroupConfig(value: unknown): value is GroupConfig;
|
|
18
|
+
export declare function buildChildrenMap(tree: NavigationTree): TreeNodeMap;
|
|
19
|
+
export declare function mapNodesOfType<TNode extends NavigationNode, TConfig>(nodes: NavigationNode[], type: NavigationNodeType, childrenMap: TreeNodeMap, mapper: (node: TNode, childrenMap: TreeNodeMap) => TConfig): TConfig[];
|
|
20
|
+
export declare function assignIfPresent<K extends string>(target: Partial<Record<K, unknown>>, source: Partial<Record<K, unknown>>, keys: readonly K[]): void;
|
|
21
|
+
export declare const COMMON_DIVISION_NODE_DATA_FIELDS: readonly ["hidden", "href", "asyncapi", "openapi", "global"];
|
|
22
|
+
export declare const TAB_NODE_DATA_FIELDS: readonly ["icon", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
23
|
+
export declare const ANCHOR_NODE_DATA_FIELDS: readonly ["icon", "color", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
24
|
+
export declare const LANGUAGE_NODE_DATA_FIELDS: readonly ["default", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
25
|
+
export declare const VERSION_NODE_DATA_FIELDS: readonly ["default", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
26
|
+
export declare const DROPDOWN_NODE_DATA_FIELDS: readonly ["icon", "color", "description", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
27
|
+
export declare const PRODUCT_NODE_DATA_FIELDS: readonly ["name", "icon", "color", "description", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
28
|
+
export declare const MENU_ITEM_NODE_DATA_FIELDS: readonly ["icon", "description", "hidden", "href", "asyncapi", "openapi", "global"];
|
|
29
|
+
export declare const GROUP_NODE_DATA_FIELDS: readonly ["icon", "hidden", "tag", "expanded", "public", "root", "asyncapi", "openapi"];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { generateNodeId } from '../utils.js';
|
|
2
|
+
export const createIdGenerator = () => {
|
|
3
|
+
let counter = 0;
|
|
4
|
+
return () => generateNodeId(counter++);
|
|
5
|
+
};
|
|
6
|
+
export function isProductConfig(value) {
|
|
7
|
+
return typeof value === 'object' && value !== null && 'product' in value;
|
|
8
|
+
}
|
|
9
|
+
export function isLanguageConfig(value) {
|
|
10
|
+
return typeof value === 'object' && value !== null && 'language' in value;
|
|
11
|
+
}
|
|
12
|
+
export function isVersionConfig(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null && 'version' in value;
|
|
14
|
+
}
|
|
15
|
+
export function isTabConfig(value) {
|
|
16
|
+
return typeof value === 'object' && value !== null && 'tab' in value;
|
|
17
|
+
}
|
|
18
|
+
export function isMenuItemConfig(value) {
|
|
19
|
+
return typeof value === 'object' && value !== null && 'item' in value;
|
|
20
|
+
}
|
|
21
|
+
export function isDropdownConfig(value) {
|
|
22
|
+
return typeof value === 'object' && value !== null && 'dropdown' in value;
|
|
23
|
+
}
|
|
24
|
+
export function isAnchorConfig(value) {
|
|
25
|
+
return typeof value === 'object' && value !== null && 'anchor' in value;
|
|
26
|
+
}
|
|
27
|
+
export function isGroupConfig(value) {
|
|
28
|
+
return typeof value === 'object' && value !== null && 'group' in value;
|
|
29
|
+
}
|
|
30
|
+
export function buildChildrenMap(tree) {
|
|
31
|
+
const childrenMap = new Map();
|
|
32
|
+
tree.forEach((node) => {
|
|
33
|
+
const children = childrenMap.get(node.parent) || [];
|
|
34
|
+
children.push(node);
|
|
35
|
+
childrenMap.set(node.parent, children);
|
|
36
|
+
});
|
|
37
|
+
childrenMap.forEach((children) => {
|
|
38
|
+
children.sort((a, b) => a.order - b.order);
|
|
39
|
+
});
|
|
40
|
+
return childrenMap;
|
|
41
|
+
}
|
|
42
|
+
export function mapNodesOfType(nodes, type, childrenMap, mapper) {
|
|
43
|
+
return nodes.filter((n) => n.type === type).map((node) => mapper(node, childrenMap));
|
|
44
|
+
}
|
|
45
|
+
export function assignIfPresent(target, source, keys) {
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
const value = source[key];
|
|
48
|
+
if (value !== undefined) {
|
|
49
|
+
target[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export const COMMON_DIVISION_NODE_DATA_FIELDS = [
|
|
54
|
+
'hidden',
|
|
55
|
+
'href',
|
|
56
|
+
'asyncapi',
|
|
57
|
+
'openapi',
|
|
58
|
+
'global',
|
|
59
|
+
];
|
|
60
|
+
export const TAB_NODE_DATA_FIELDS = ['icon', ...COMMON_DIVISION_NODE_DATA_FIELDS];
|
|
61
|
+
export const ANCHOR_NODE_DATA_FIELDS = [
|
|
62
|
+
'icon',
|
|
63
|
+
'color',
|
|
64
|
+
...COMMON_DIVISION_NODE_DATA_FIELDS,
|
|
65
|
+
];
|
|
66
|
+
export const LANGUAGE_NODE_DATA_FIELDS = ['default', ...COMMON_DIVISION_NODE_DATA_FIELDS];
|
|
67
|
+
export const VERSION_NODE_DATA_FIELDS = ['default', ...COMMON_DIVISION_NODE_DATA_FIELDS];
|
|
68
|
+
export const DROPDOWN_NODE_DATA_FIELDS = [
|
|
69
|
+
'icon',
|
|
70
|
+
'color',
|
|
71
|
+
'description',
|
|
72
|
+
...COMMON_DIVISION_NODE_DATA_FIELDS,
|
|
73
|
+
];
|
|
74
|
+
export const PRODUCT_NODE_DATA_FIELDS = [
|
|
75
|
+
'name',
|
|
76
|
+
'icon',
|
|
77
|
+
'color',
|
|
78
|
+
'description',
|
|
79
|
+
...COMMON_DIVISION_NODE_DATA_FIELDS,
|
|
80
|
+
];
|
|
81
|
+
export const MENU_ITEM_NODE_DATA_FIELDS = [
|
|
82
|
+
'icon',
|
|
83
|
+
'description',
|
|
84
|
+
...COMMON_DIVISION_NODE_DATA_FIELDS,
|
|
85
|
+
];
|
|
86
|
+
export const GROUP_NODE_DATA_FIELDS = [
|
|
87
|
+
'icon',
|
|
88
|
+
'hidden',
|
|
89
|
+
'tag',
|
|
90
|
+
'expanded',
|
|
91
|
+
'public',
|
|
92
|
+
'root',
|
|
93
|
+
'asyncapi',
|
|
94
|
+
'openapi',
|
|
95
|
+
];
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import traverse from 'neotraverse';
|
|
2
|
+
import { isGlobalNode } from '../schema.js';
|
|
3
|
+
import { createIdGenerator, isProductConfig, isLanguageConfig, isVersionConfig, isTabConfig, isMenuItemConfig, isDropdownConfig, isAnchorConfig, isGroupConfig, } from './common.js';
|
|
4
|
+
function pickDefined(obj) {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const key in obj) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
8
|
+
const value = obj[key];
|
|
9
|
+
if (value !== undefined && value !== null) {
|
|
10
|
+
result[key] = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
const NODE_FACTORIES = {
|
|
17
|
+
products: ({ value, parent, generateId, getNextOrder }) => {
|
|
18
|
+
if (!isProductConfig(value))
|
|
19
|
+
return null;
|
|
20
|
+
const nodeId = generateId();
|
|
21
|
+
const productNode = {
|
|
22
|
+
id: nodeId,
|
|
23
|
+
parent: parent.id,
|
|
24
|
+
order: getNextOrder(parent.id),
|
|
25
|
+
text: value.name || value.product,
|
|
26
|
+
type: 'product',
|
|
27
|
+
isHidden: value.hidden === true,
|
|
28
|
+
data: Object.assign({ product: value.product }, pickDefined({
|
|
29
|
+
name: value.name,
|
|
30
|
+
icon: value.icon,
|
|
31
|
+
color: value.color,
|
|
32
|
+
description: value.description,
|
|
33
|
+
hidden: value.hidden,
|
|
34
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
35
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
36
|
+
})),
|
|
37
|
+
};
|
|
38
|
+
return productNode;
|
|
39
|
+
},
|
|
40
|
+
languages: ({ value, parent, generateId, getNextOrder }) => {
|
|
41
|
+
if (!isLanguageConfig(value))
|
|
42
|
+
return null;
|
|
43
|
+
const nodeId = generateId();
|
|
44
|
+
const langNode = {
|
|
45
|
+
id: nodeId,
|
|
46
|
+
parent: parent.id,
|
|
47
|
+
order: getNextOrder(parent.id),
|
|
48
|
+
text: value.language,
|
|
49
|
+
type: 'language',
|
|
50
|
+
isHidden: value.hidden === true,
|
|
51
|
+
data: Object.assign({ language: value.language }, pickDefined({
|
|
52
|
+
default: value.default,
|
|
53
|
+
hidden: value.hidden,
|
|
54
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
55
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
56
|
+
})),
|
|
57
|
+
};
|
|
58
|
+
return langNode;
|
|
59
|
+
},
|
|
60
|
+
versions: ({ value, parent, generateId, getNextOrder }) => {
|
|
61
|
+
if (!isVersionConfig(value))
|
|
62
|
+
return null;
|
|
63
|
+
const nodeId = generateId();
|
|
64
|
+
const verNode = {
|
|
65
|
+
id: nodeId,
|
|
66
|
+
parent: parent.id,
|
|
67
|
+
order: getNextOrder(parent.id),
|
|
68
|
+
text: value.version,
|
|
69
|
+
type: 'version',
|
|
70
|
+
isHidden: value.hidden === true,
|
|
71
|
+
data: Object.assign({ version: value.version }, pickDefined({
|
|
72
|
+
default: value.default,
|
|
73
|
+
hidden: value.hidden,
|
|
74
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
75
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
76
|
+
})),
|
|
77
|
+
};
|
|
78
|
+
return verNode;
|
|
79
|
+
},
|
|
80
|
+
tabs: ({ value, parent, generateId, getNextOrder }) => {
|
|
81
|
+
if (!isTabConfig(value))
|
|
82
|
+
return null;
|
|
83
|
+
const nodeId = generateId();
|
|
84
|
+
const tabNode = {
|
|
85
|
+
id: nodeId,
|
|
86
|
+
parent: parent.id,
|
|
87
|
+
order: getNextOrder(parent.id),
|
|
88
|
+
text: value.tab,
|
|
89
|
+
type: 'tab',
|
|
90
|
+
isHidden: value.hidden === true,
|
|
91
|
+
data: Object.assign({ tab: value.tab }, pickDefined({
|
|
92
|
+
icon: value.icon,
|
|
93
|
+
hidden: value.hidden,
|
|
94
|
+
href: 'href' in value ? value.href : undefined,
|
|
95
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
96
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
return tabNode;
|
|
100
|
+
},
|
|
101
|
+
dropdowns: ({ value, parent, generateId, getNextOrder }) => {
|
|
102
|
+
if (!isDropdownConfig(value))
|
|
103
|
+
return null;
|
|
104
|
+
const nodeId = generateId();
|
|
105
|
+
const dropdownNode = {
|
|
106
|
+
id: nodeId,
|
|
107
|
+
parent: parent.id,
|
|
108
|
+
order: getNextOrder(parent.id),
|
|
109
|
+
text: value.dropdown,
|
|
110
|
+
type: 'dropdown',
|
|
111
|
+
isHidden: value.hidden === true,
|
|
112
|
+
data: Object.assign({ dropdown: value.dropdown }, pickDefined({
|
|
113
|
+
icon: value.icon,
|
|
114
|
+
color: value.color,
|
|
115
|
+
description: value.description,
|
|
116
|
+
hidden: value.hidden,
|
|
117
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
118
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
119
|
+
})),
|
|
120
|
+
};
|
|
121
|
+
return dropdownNode;
|
|
122
|
+
},
|
|
123
|
+
anchors: ({ value, parent, generateId, getNextOrder }) => {
|
|
124
|
+
if (!isAnchorConfig(value))
|
|
125
|
+
return null;
|
|
126
|
+
const nodeId = generateId();
|
|
127
|
+
const anchorNode = {
|
|
128
|
+
id: nodeId,
|
|
129
|
+
parent: parent.id,
|
|
130
|
+
order: getNextOrder(parent.id),
|
|
131
|
+
text: value.anchor,
|
|
132
|
+
type: 'anchor',
|
|
133
|
+
isHidden: value.hidden === true,
|
|
134
|
+
data: Object.assign({ anchor: value.anchor }, pickDefined({
|
|
135
|
+
icon: value.icon,
|
|
136
|
+
color: value.color,
|
|
137
|
+
hidden: value.hidden,
|
|
138
|
+
href: 'href' in value ? value.href : undefined,
|
|
139
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
140
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
141
|
+
})),
|
|
142
|
+
};
|
|
143
|
+
return anchorNode;
|
|
144
|
+
},
|
|
145
|
+
menu: ({ value, parent, generateId, getNextOrder }) => {
|
|
146
|
+
if (!isMenuItemConfig(value))
|
|
147
|
+
return null;
|
|
148
|
+
const nodeId = generateId();
|
|
149
|
+
const menuItemNode = {
|
|
150
|
+
id: nodeId,
|
|
151
|
+
parent: parent.id,
|
|
152
|
+
order: getNextOrder(parent.id),
|
|
153
|
+
text: value.item,
|
|
154
|
+
type: 'item',
|
|
155
|
+
isHidden: value.hidden === true,
|
|
156
|
+
data: Object.assign({ item: value.item }, pickDefined({
|
|
157
|
+
icon: value.icon,
|
|
158
|
+
description: value.description,
|
|
159
|
+
hidden: value.hidden,
|
|
160
|
+
href: 'href' in value ? value.href : undefined,
|
|
161
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
162
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
163
|
+
})),
|
|
164
|
+
};
|
|
165
|
+
return menuItemNode;
|
|
166
|
+
},
|
|
167
|
+
groups: ({ value, parent, generateId, getNextOrder }) => {
|
|
168
|
+
if (!isGroupConfig(value))
|
|
169
|
+
return null;
|
|
170
|
+
const nodeId = generateId();
|
|
171
|
+
const groupNode = {
|
|
172
|
+
id: nodeId,
|
|
173
|
+
parent: parent.id,
|
|
174
|
+
order: getNextOrder(parent.id),
|
|
175
|
+
text: value.group,
|
|
176
|
+
type: 'group',
|
|
177
|
+
isHidden: value.hidden === true,
|
|
178
|
+
data: Object.assign({ group: value.group }, pickDefined({
|
|
179
|
+
icon: value.icon,
|
|
180
|
+
hidden: value.hidden,
|
|
181
|
+
tag: value.tag,
|
|
182
|
+
expanded: value.expanded,
|
|
183
|
+
public: value.public,
|
|
184
|
+
root: value.root,
|
|
185
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
186
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
187
|
+
})),
|
|
188
|
+
};
|
|
189
|
+
return groupNode;
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
const GLOBAL_NODE_FACTORIES = {
|
|
193
|
+
languages: ({ value, parent, generateId, getNextOrder }) => {
|
|
194
|
+
if (!isLanguageConfig(value))
|
|
195
|
+
return null;
|
|
196
|
+
return {
|
|
197
|
+
id: generateId(),
|
|
198
|
+
parent: parent.id,
|
|
199
|
+
order: getNextOrder(parent.id),
|
|
200
|
+
text: value.language,
|
|
201
|
+
type: 'language',
|
|
202
|
+
isHidden: value.hidden === true,
|
|
203
|
+
data: Object.assign({ language: value.language, isGlobal: true }, pickDefined({
|
|
204
|
+
default: value.default,
|
|
205
|
+
hidden: value.hidden,
|
|
206
|
+
href: 'href' in value ? value.href : undefined,
|
|
207
|
+
})),
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
versions: ({ value, parent, generateId, getNextOrder }) => {
|
|
211
|
+
if (!isVersionConfig(value))
|
|
212
|
+
return null;
|
|
213
|
+
return {
|
|
214
|
+
id: generateId(),
|
|
215
|
+
parent: parent.id,
|
|
216
|
+
order: getNextOrder(parent.id),
|
|
217
|
+
text: value.version,
|
|
218
|
+
type: 'version',
|
|
219
|
+
isHidden: value.hidden === true,
|
|
220
|
+
data: Object.assign({ version: value.version, isGlobal: true }, pickDefined({
|
|
221
|
+
default: value.default,
|
|
222
|
+
hidden: value.hidden,
|
|
223
|
+
href: 'href' in value ? value.href : undefined,
|
|
224
|
+
})),
|
|
225
|
+
};
|
|
226
|
+
},
|
|
227
|
+
tabs: ({ value, parent, generateId, getNextOrder }) => {
|
|
228
|
+
if (!isTabConfig(value))
|
|
229
|
+
return null;
|
|
230
|
+
return {
|
|
231
|
+
id: generateId(),
|
|
232
|
+
parent: parent.id,
|
|
233
|
+
order: getNextOrder(parent.id),
|
|
234
|
+
text: value.tab,
|
|
235
|
+
type: 'tab',
|
|
236
|
+
isHidden: value.hidden === true,
|
|
237
|
+
data: Object.assign({ tab: value.tab, isGlobal: true }, pickDefined({
|
|
238
|
+
icon: value.icon,
|
|
239
|
+
hidden: value.hidden,
|
|
240
|
+
href: 'href' in value ? value.href : undefined,
|
|
241
|
+
})),
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
dropdowns: ({ value, parent, generateId, getNextOrder }) => {
|
|
245
|
+
if (!isDropdownConfig(value))
|
|
246
|
+
return null;
|
|
247
|
+
return {
|
|
248
|
+
id: generateId(),
|
|
249
|
+
parent: parent.id,
|
|
250
|
+
order: getNextOrder(parent.id),
|
|
251
|
+
text: value.dropdown,
|
|
252
|
+
type: 'dropdown',
|
|
253
|
+
isHidden: value.hidden === true,
|
|
254
|
+
data: Object.assign({ dropdown: value.dropdown, isGlobal: true }, pickDefined({
|
|
255
|
+
icon: value.icon,
|
|
256
|
+
color: value.color,
|
|
257
|
+
description: value.description,
|
|
258
|
+
hidden: value.hidden,
|
|
259
|
+
href: 'href' in value ? value.href : undefined,
|
|
260
|
+
})),
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
anchors: ({ value, parent, generateId, getNextOrder }) => {
|
|
264
|
+
if (!isAnchorConfig(value))
|
|
265
|
+
return null;
|
|
266
|
+
return {
|
|
267
|
+
id: generateId(),
|
|
268
|
+
parent: parent.id,
|
|
269
|
+
order: getNextOrder(parent.id),
|
|
270
|
+
text: value.anchor,
|
|
271
|
+
type: 'anchor',
|
|
272
|
+
isHidden: value.hidden === true,
|
|
273
|
+
data: Object.assign({ anchor: value.anchor, isGlobal: true }, pickDefined({
|
|
274
|
+
icon: value.icon,
|
|
275
|
+
color: value.color,
|
|
276
|
+
hidden: value.hidden,
|
|
277
|
+
href: 'href' in value ? value.href : undefined,
|
|
278
|
+
})),
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
products: ({ value, parent, generateId, getNextOrder }) => {
|
|
282
|
+
if (!isProductConfig(value))
|
|
283
|
+
return null;
|
|
284
|
+
return {
|
|
285
|
+
id: generateId(),
|
|
286
|
+
parent: parent.id,
|
|
287
|
+
order: getNextOrder(parent.id),
|
|
288
|
+
text: value.name || value.product,
|
|
289
|
+
type: 'product',
|
|
290
|
+
isHidden: value.hidden === true,
|
|
291
|
+
data: Object.assign({ product: value.product, isGlobal: true }, pickDefined({
|
|
292
|
+
name: value.name,
|
|
293
|
+
icon: value.icon,
|
|
294
|
+
color: value.color,
|
|
295
|
+
description: value.description,
|
|
296
|
+
hidden: value.hidden,
|
|
297
|
+
href: 'href' in value ? value.href : undefined,
|
|
298
|
+
})),
|
|
299
|
+
};
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
export function docsConfigToNavigationTree(navigation) {
|
|
303
|
+
const nodes = [];
|
|
304
|
+
const generateId = createIdGenerator();
|
|
305
|
+
const parentStack = [{ id: 0, order: 0 }];
|
|
306
|
+
const orderByParent = new Map();
|
|
307
|
+
const getNextOrder = (parentId) => {
|
|
308
|
+
var _a;
|
|
309
|
+
const current = (_a = orderByParent.get(parentId)) !== null && _a !== void 0 ? _a : 0;
|
|
310
|
+
orderByParent.set(parentId, current + 1);
|
|
311
|
+
return current;
|
|
312
|
+
};
|
|
313
|
+
const getCurrentParent = () => {
|
|
314
|
+
var _a;
|
|
315
|
+
return (_a = parentStack[parentStack.length - 1]) !== null && _a !== void 0 ? _a : { id: 0, order: 0 };
|
|
316
|
+
};
|
|
317
|
+
traverse(navigation).forEach(function (value) {
|
|
318
|
+
var _a, _b, _c;
|
|
319
|
+
const parentKey = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.key;
|
|
320
|
+
const grandparentKey = (_c = (_b = this.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.key;
|
|
321
|
+
const currentParent = getCurrentParent();
|
|
322
|
+
if (!parentKey || typeof parentKey !== 'string')
|
|
323
|
+
return;
|
|
324
|
+
if (grandparentKey === 'global' && typeof parentKey === 'string') {
|
|
325
|
+
const globalFactory = GLOBAL_NODE_FACTORIES[parentKey];
|
|
326
|
+
if (globalFactory) {
|
|
327
|
+
const node = globalFactory({
|
|
328
|
+
value,
|
|
329
|
+
parent: currentParent,
|
|
330
|
+
generateId,
|
|
331
|
+
getNextOrder,
|
|
332
|
+
});
|
|
333
|
+
if (node) {
|
|
334
|
+
nodes.push(node);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (parentKey === 'pages') {
|
|
340
|
+
if (typeof value === 'string') {
|
|
341
|
+
const nodeId = generateId();
|
|
342
|
+
const text = value.split('/').pop() || value;
|
|
343
|
+
const node = {
|
|
344
|
+
id: nodeId,
|
|
345
|
+
parent: currentParent.id,
|
|
346
|
+
order: getNextOrder(currentParent.id),
|
|
347
|
+
text,
|
|
348
|
+
type: 'page',
|
|
349
|
+
data: { title: text, href: value },
|
|
350
|
+
};
|
|
351
|
+
nodes.push(node);
|
|
352
|
+
}
|
|
353
|
+
else if (isGroupConfig(value)) {
|
|
354
|
+
const nodeId = generateId();
|
|
355
|
+
const groupNode = {
|
|
356
|
+
id: nodeId,
|
|
357
|
+
parent: currentParent.id,
|
|
358
|
+
order: getNextOrder(currentParent.id),
|
|
359
|
+
text: value.group,
|
|
360
|
+
type: 'group',
|
|
361
|
+
isHidden: value.hidden === true,
|
|
362
|
+
data: Object.assign({ group: value.group, fromPages: true }, pickDefined({
|
|
363
|
+
icon: value.icon,
|
|
364
|
+
hidden: value.hidden,
|
|
365
|
+
tag: value.tag,
|
|
366
|
+
expanded: value.expanded,
|
|
367
|
+
public: value.public,
|
|
368
|
+
root: value.root,
|
|
369
|
+
openapi: 'openapi' in value ? value.openapi : undefined,
|
|
370
|
+
asyncapi: 'asyncapi' in value ? value.asyncapi : undefined,
|
|
371
|
+
})),
|
|
372
|
+
};
|
|
373
|
+
nodes.push(groupNode);
|
|
374
|
+
parentStack.push({ id: nodeId, order: 0 });
|
|
375
|
+
this.after(() => parentStack.pop());
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const factory = NODE_FACTORIES[parentKey];
|
|
380
|
+
if (!factory)
|
|
381
|
+
return;
|
|
382
|
+
const node = factory({
|
|
383
|
+
value,
|
|
384
|
+
parent: currentParent,
|
|
385
|
+
generateId,
|
|
386
|
+
getNextOrder,
|
|
387
|
+
});
|
|
388
|
+
if (!node)
|
|
389
|
+
return;
|
|
390
|
+
nodes.push(node);
|
|
391
|
+
parentStack.push({ id: node.id, order: 0 });
|
|
392
|
+
this.after(() => parentStack.pop());
|
|
393
|
+
});
|
|
394
|
+
reorderGlobalNodesFirst(nodes);
|
|
395
|
+
return nodes;
|
|
396
|
+
}
|
|
397
|
+
function reorderGlobalNodesFirst(nodes) {
|
|
398
|
+
var _a;
|
|
399
|
+
const nodesByParent = new Map();
|
|
400
|
+
for (const node of nodes) {
|
|
401
|
+
const siblings = (_a = nodesByParent.get(node.parent)) !== null && _a !== void 0 ? _a : [];
|
|
402
|
+
siblings.push(node);
|
|
403
|
+
nodesByParent.set(node.parent, siblings);
|
|
404
|
+
}
|
|
405
|
+
for (const siblings of nodesByParent.values()) {
|
|
406
|
+
siblings.sort((a, b) => {
|
|
407
|
+
const aIsGlobal = isGlobalNode(a);
|
|
408
|
+
const bIsGlobal = isGlobalNode(b);
|
|
409
|
+
if (aIsGlobal && !bIsGlobal)
|
|
410
|
+
return -1;
|
|
411
|
+
if (!aIsGlobal && bIsGlobal)
|
|
412
|
+
return 1;
|
|
413
|
+
return a.order - b.order;
|
|
414
|
+
});
|
|
415
|
+
siblings.forEach((node, index) => {
|
|
416
|
+
node.order = index;
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|