@mintlify/validation 0.1.638 → 0.1.639
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/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { isGlobalNode } from '../schema.js';
|
|
2
|
+
import { buildChildrenMap, mapNodesOfType, assignIfPresent, TAB_NODE_DATA_FIELDS, ANCHOR_NODE_DATA_FIELDS, LANGUAGE_NODE_DATA_FIELDS, VERSION_NODE_DATA_FIELDS, DROPDOWN_NODE_DATA_FIELDS, PRODUCT_NODE_DATA_FIELDS, GROUP_NODE_DATA_FIELDS, MENU_ITEM_NODE_DATA_FIELDS, } from './common.js';
|
|
3
|
+
function nodesToPages(nodes, childrenMap) {
|
|
4
|
+
return nodes.map((node) => {
|
|
5
|
+
if (node.type === 'group') {
|
|
6
|
+
const groupChildren = childrenMap.get(node.id) || [];
|
|
7
|
+
const baseConfig = { group: node.data.group };
|
|
8
|
+
assignIfPresent(baseConfig, node.data, GROUP_NODE_DATA_FIELDS);
|
|
9
|
+
if ((node.data.openapi !== undefined || node.data.asyncapi !== undefined) &&
|
|
10
|
+
!groupChildren.length) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- groups default `pages` to an empty array, so we can cast with pages being undefined
|
|
12
|
+
return Object.assign(Object.assign({}, baseConfig), { group: node.data.group });
|
|
13
|
+
}
|
|
14
|
+
return Object.assign(Object.assign({}, baseConfig), { group: node.data.group, pages: nodesToPages(groupChildren, childrenMap) });
|
|
15
|
+
}
|
|
16
|
+
if (node.type === 'page') {
|
|
17
|
+
return node.data.href;
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function nodesToGroups(nodes, childrenMap) {
|
|
23
|
+
return mapNodesOfType(nodes, 'group', childrenMap, (node, map) => {
|
|
24
|
+
const groupChildren = map.get(node.id) || [];
|
|
25
|
+
const baseConfig = { group: node.data.group };
|
|
26
|
+
assignIfPresent(baseConfig, node.data, GROUP_NODE_DATA_FIELDS);
|
|
27
|
+
if ((node.data.openapi !== undefined || node.data.asyncapi !== undefined) &&
|
|
28
|
+
!groupChildren.length) {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- groups default `pages` to an empty array, so we can cast with pages being undefined
|
|
30
|
+
return Object.assign(Object.assign({}, baseConfig), { group: node.data.group });
|
|
31
|
+
}
|
|
32
|
+
return Object.assign(Object.assign({}, baseConfig), { group: node.data.group, pages: nodesToPages(groupChildren, map) });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function getGlobalChildren(childrenMap, nodeId) {
|
|
36
|
+
const children = childrenMap.get(nodeId) || [];
|
|
37
|
+
return children.filter(isGlobalNode);
|
|
38
|
+
}
|
|
39
|
+
function getRegularChildren(childrenMap, nodeId) {
|
|
40
|
+
const children = childrenMap.get(nodeId) || [];
|
|
41
|
+
return children.filter((child) => !isGlobalNode(child));
|
|
42
|
+
}
|
|
43
|
+
function nodesToGlobalConfig(globalChildren) {
|
|
44
|
+
if (globalChildren.length === 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
const globalConfig = {};
|
|
47
|
+
const languages = globalChildren.filter((n) => n.type === 'language');
|
|
48
|
+
const versions = globalChildren.filter((n) => n.type === 'version');
|
|
49
|
+
const tabs = globalChildren.filter((n) => n.type === 'tab');
|
|
50
|
+
const dropdowns = globalChildren.filter((n) => n.type === 'dropdown');
|
|
51
|
+
const anchors = globalChildren.filter((n) => n.type === 'anchor');
|
|
52
|
+
const products = globalChildren.filter((n) => n.type === 'product');
|
|
53
|
+
if (languages.length > 0) {
|
|
54
|
+
globalConfig.languages = languages.map((node) => (Object.assign(Object.assign(Object.assign({ language: node.data.language }, (node.data.hidden !== undefined && { hidden: node.data.hidden })), (node.data.default !== undefined && { default: node.data.default })), { href: node.data.href || '' })));
|
|
55
|
+
}
|
|
56
|
+
if (versions.length > 0) {
|
|
57
|
+
globalConfig.versions = versions.map((node) => (Object.assign(Object.assign(Object.assign({ version: node.data.version }, (node.data.hidden !== undefined && { hidden: node.data.hidden })), (node.data.default !== undefined && { default: node.data.default })), { href: node.data.href || '' })));
|
|
58
|
+
}
|
|
59
|
+
if (tabs.length > 0) {
|
|
60
|
+
globalConfig.tabs = tabs.map((node) => (Object.assign(Object.assign(Object.assign({ tab: node.data.tab }, (node.data.icon !== undefined && { icon: node.data.icon })), (node.data.hidden !== undefined && { hidden: node.data.hidden })), { href: node.data.href || '' })));
|
|
61
|
+
}
|
|
62
|
+
if (dropdowns.length > 0) {
|
|
63
|
+
globalConfig.dropdowns = dropdowns.map((node) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ dropdown: node.data.dropdown }, (node.data.icon !== undefined && { icon: node.data.icon })), (node.data.color !== undefined && { color: node.data.color })), (node.data.description !== undefined && { description: node.data.description })), (node.data.hidden !== undefined && { hidden: node.data.hidden })), { href: node.data.href || '' })));
|
|
64
|
+
}
|
|
65
|
+
if (anchors.length > 0) {
|
|
66
|
+
globalConfig.anchors = anchors.map((node) => (Object.assign(Object.assign(Object.assign(Object.assign({ anchor: node.data.anchor }, (node.data.icon !== undefined && { icon: node.data.icon })), (node.data.color !== undefined && { color: node.data.color })), (node.data.hidden !== undefined && { hidden: node.data.hidden })), { href: node.data.href || '' })));
|
|
67
|
+
}
|
|
68
|
+
if (products.length > 0) {
|
|
69
|
+
globalConfig.products = products.map((node) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ product: node.data.product }, (node.data.name !== undefined && { name: node.data.name })), (node.data.icon !== undefined && { icon: node.data.icon })), (node.data.color !== undefined && { color: node.data.color })), (node.data.description !== undefined && { description: node.data.description })), (node.data.hidden !== undefined && { hidden: node.data.hidden })), { href: node.data.href || '' })));
|
|
70
|
+
}
|
|
71
|
+
return Object.keys(globalConfig).length > 0 ? globalConfig : undefined;
|
|
72
|
+
}
|
|
73
|
+
function buildChildNavigation(node, childrenMap) {
|
|
74
|
+
const regularChildren = getRegularChildren(childrenMap, node.id);
|
|
75
|
+
if (regularChildren.length === 0) {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
const firstChild = regularChildren[0];
|
|
79
|
+
if (!firstChild) {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
const childType = firstChild.type;
|
|
83
|
+
const children = regularChildren;
|
|
84
|
+
switch (childType) {
|
|
85
|
+
case 'product':
|
|
86
|
+
return { products: nodesToProducts(children, childrenMap) };
|
|
87
|
+
case 'language':
|
|
88
|
+
return { languages: nodesToLanguages(children, childrenMap) };
|
|
89
|
+
case 'version':
|
|
90
|
+
return { versions: nodesToVersions(children, childrenMap) };
|
|
91
|
+
case 'tab':
|
|
92
|
+
return { tabs: nodesToTabs(children, childrenMap) };
|
|
93
|
+
case 'dropdown':
|
|
94
|
+
return { dropdowns: nodesToDropdowns(children, childrenMap) };
|
|
95
|
+
case 'anchor':
|
|
96
|
+
return { anchors: nodesToAnchors(children, childrenMap) };
|
|
97
|
+
case 'item':
|
|
98
|
+
return { menu: nodesToMenuItems(children, childrenMap) };
|
|
99
|
+
case 'group':
|
|
100
|
+
if (firstChild.data.fromPages) {
|
|
101
|
+
return { pages: nodesToPages(children, childrenMap) };
|
|
102
|
+
}
|
|
103
|
+
const hasPageSibling = children.some((child) => child.type === 'page');
|
|
104
|
+
if (hasPageSibling) {
|
|
105
|
+
return { pages: nodesToPages(children, childrenMap) };
|
|
106
|
+
}
|
|
107
|
+
return { groups: nodesToGroups(children, childrenMap) };
|
|
108
|
+
case 'page':
|
|
109
|
+
return { pages: nodesToPages(children, childrenMap) };
|
|
110
|
+
default:
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function nodesToTabs(nodes, childrenMap) {
|
|
115
|
+
return mapNodesOfType(nodes, 'tab', childrenMap, (node, map) => {
|
|
116
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
117
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
118
|
+
const baseConfig = { tab: node.data.tab };
|
|
119
|
+
assignIfPresent(baseConfig, node.data, TAB_NODE_DATA_FIELDS);
|
|
120
|
+
if (node.data.href && !node.data.isGlobal) {
|
|
121
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { tab: node.data.tab, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
122
|
+
}
|
|
123
|
+
const childNav = buildChildNavigation(node, map);
|
|
124
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { tab: node.data.tab }), (globalConfig && { global: globalConfig })), childNav);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function nodesToAnchors(nodes, childrenMap) {
|
|
128
|
+
return mapNodesOfType(nodes, 'anchor', childrenMap, (node, map) => {
|
|
129
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
130
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
131
|
+
const baseConfig = { anchor: node.data.anchor };
|
|
132
|
+
assignIfPresent(baseConfig, node.data, ANCHOR_NODE_DATA_FIELDS);
|
|
133
|
+
if (node.data.href && !node.data.isGlobal) {
|
|
134
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { anchor: node.data.anchor, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
135
|
+
}
|
|
136
|
+
const childNav = buildChildNavigation(node, map);
|
|
137
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { anchor: node.data.anchor }), (globalConfig && { global: globalConfig })), childNav);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function nodesToLanguages(nodes, childrenMap) {
|
|
141
|
+
return mapNodesOfType(nodes, 'language', childrenMap, (node, map) => {
|
|
142
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
143
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
144
|
+
const baseConfig = Object.assign({ language: node.data.language }, (node.data.default !== undefined && { default: node.data.default }));
|
|
145
|
+
assignIfPresent(baseConfig, node.data, LANGUAGE_NODE_DATA_FIELDS);
|
|
146
|
+
if (node.data.href && !node.data.isGlobal) {
|
|
147
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { language: node.data.language, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
148
|
+
}
|
|
149
|
+
const childNav = buildChildNavigation(node, map);
|
|
150
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { language: node.data.language }), (globalConfig && { global: globalConfig })), childNav);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function nodesToVersions(nodes, childrenMap) {
|
|
154
|
+
return mapNodesOfType(nodes, 'version', childrenMap, (node, map) => {
|
|
155
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
156
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
157
|
+
const baseConfig = Object.assign({ version: node.data.version }, (node.data.default !== undefined && { default: node.data.default }));
|
|
158
|
+
assignIfPresent(baseConfig, node.data, VERSION_NODE_DATA_FIELDS);
|
|
159
|
+
if (node.data.href && !node.data.isGlobal) {
|
|
160
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { version: node.data.version, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
161
|
+
}
|
|
162
|
+
const childNav = buildChildNavigation(node, map);
|
|
163
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { version: node.data.version }), (globalConfig && { global: globalConfig })), childNav);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function nodesToDropdowns(nodes, childrenMap) {
|
|
167
|
+
return mapNodesOfType(nodes, 'dropdown', childrenMap, (node, map) => {
|
|
168
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
169
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
170
|
+
const baseConfig = { dropdown: node.data.dropdown };
|
|
171
|
+
assignIfPresent(baseConfig, node.data, DROPDOWN_NODE_DATA_FIELDS);
|
|
172
|
+
if (node.data.href && !node.data.isGlobal) {
|
|
173
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { dropdown: node.data.dropdown, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
174
|
+
}
|
|
175
|
+
const childNav = buildChildNavigation(node, map);
|
|
176
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { dropdown: node.data.dropdown }), (globalConfig && { global: globalConfig })), childNav);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function nodesToProducts(nodes, childrenMap) {
|
|
180
|
+
return mapNodesOfType(nodes, 'product', childrenMap, (node, map) => {
|
|
181
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
182
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
183
|
+
const baseConfig = { product: node.data.product };
|
|
184
|
+
assignIfPresent(baseConfig, node.data, PRODUCT_NODE_DATA_FIELDS);
|
|
185
|
+
if (node.data.href && !node.data.isGlobal) {
|
|
186
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { product: node.data.product, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
187
|
+
}
|
|
188
|
+
const childNav = buildChildNavigation(node, map);
|
|
189
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { product: node.data.product }), (globalConfig && { global: globalConfig })), childNav);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function nodesToMenuItems(nodes, childrenMap) {
|
|
193
|
+
return mapNodesOfType(nodes, 'item', childrenMap, (node, map) => {
|
|
194
|
+
const globalChildren = getGlobalChildren(map, node.id);
|
|
195
|
+
const globalConfig = nodesToGlobalConfig(globalChildren);
|
|
196
|
+
const baseConfig = { item: node.data.item };
|
|
197
|
+
assignIfPresent(baseConfig, node.data, MENU_ITEM_NODE_DATA_FIELDS);
|
|
198
|
+
if (node.data.href) {
|
|
199
|
+
return Object.assign(Object.assign(Object.assign({}, baseConfig), { item: node.data.item, href: node.data.href }), (globalConfig && { global: globalConfig }));
|
|
200
|
+
}
|
|
201
|
+
const childNav = buildChildNavigation(node, map);
|
|
202
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseConfig), { item: node.data.item }), (globalConfig && { global: globalConfig })), childNav);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
export function navigationTreeToDocsConfig(tree) {
|
|
206
|
+
const childrenMap = buildChildrenMap(tree);
|
|
207
|
+
const rootGlobalChildren = getGlobalChildren(childrenMap, 0);
|
|
208
|
+
const rootRegularChildren = getRegularChildren(childrenMap, 0);
|
|
209
|
+
const globalConfig = nodesToGlobalConfig(rootGlobalChildren);
|
|
210
|
+
if (rootRegularChildren.length === 0) {
|
|
211
|
+
if (globalConfig) {
|
|
212
|
+
return { global: globalConfig, groups: [] };
|
|
213
|
+
}
|
|
214
|
+
return { groups: [] };
|
|
215
|
+
}
|
|
216
|
+
const firstChild = rootRegularChildren[0];
|
|
217
|
+
if (!firstChild) {
|
|
218
|
+
if (globalConfig) {
|
|
219
|
+
return { global: globalConfig, groups: [] };
|
|
220
|
+
}
|
|
221
|
+
return { groups: [] };
|
|
222
|
+
}
|
|
223
|
+
const rootType = firstChild.type;
|
|
224
|
+
let result;
|
|
225
|
+
switch (rootType) {
|
|
226
|
+
case 'product':
|
|
227
|
+
result = { products: nodesToProducts(rootRegularChildren, childrenMap) };
|
|
228
|
+
break;
|
|
229
|
+
case 'language':
|
|
230
|
+
result = { languages: nodesToLanguages(rootRegularChildren, childrenMap) };
|
|
231
|
+
break;
|
|
232
|
+
case 'version':
|
|
233
|
+
result = { versions: nodesToVersions(rootRegularChildren, childrenMap) };
|
|
234
|
+
break;
|
|
235
|
+
case 'tab':
|
|
236
|
+
result = { tabs: nodesToTabs(rootRegularChildren, childrenMap) };
|
|
237
|
+
break;
|
|
238
|
+
case 'dropdown':
|
|
239
|
+
result = { dropdowns: nodesToDropdowns(rootRegularChildren, childrenMap) };
|
|
240
|
+
break;
|
|
241
|
+
case 'anchor':
|
|
242
|
+
result = { anchors: nodesToAnchors(rootRegularChildren, childrenMap) };
|
|
243
|
+
break;
|
|
244
|
+
case 'group': {
|
|
245
|
+
const hasPageSibling = rootRegularChildren.some((child) => child.type === 'page');
|
|
246
|
+
if (hasPageSibling) {
|
|
247
|
+
result = { pages: nodesToPages(rootRegularChildren, childrenMap) };
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
result = { groups: nodesToGroups(rootRegularChildren, childrenMap) };
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case 'page':
|
|
255
|
+
result = { pages: nodesToPages(rootRegularChildren, childrenMap) };
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
result = { groups: [] };
|
|
259
|
+
}
|
|
260
|
+
if (globalConfig) {
|
|
261
|
+
return Object.assign({ global: globalConfig }, result);
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { IconType } from '@mintlify/models';
|
|
2
|
+
import { DecoratedPageConfig, BaseDropdownSchema, BaseLanguageSchema, BaseProductSchema, BaseTabSchema, BaseVersionSchema, BaseGroupSchema, BaseAnchorSchema, MenuItemConfig, AsyncApiConfig, OpenApiConfig, IconConfig } from '../mint-config/schemas/v2/properties/index.js';
|
|
3
|
+
export declare const DIVISION_TYPES: readonly ["tab", "dropdown", "anchor", "language", "product", "version", "item"];
|
|
4
|
+
export declare const CONTENT_TYPES: readonly ["page", "group"];
|
|
5
|
+
export type DivisionType = (typeof DIVISION_TYPES)[number];
|
|
6
|
+
export type ContentType = (typeof CONTENT_TYPES)[number];
|
|
7
|
+
export type NavigationNodeType = DivisionType | ContentType;
|
|
8
|
+
export declare const ROOT_NODE: "root";
|
|
9
|
+
export type ROOT_NODE_TYPE = typeof ROOT_NODE;
|
|
10
|
+
export type ParentNodeType = NavigationNodeType | ROOT_NODE_TYPE;
|
|
11
|
+
export interface BaseNavigationNode<TData> {
|
|
12
|
+
id: string;
|
|
13
|
+
parent: string | 0;
|
|
14
|
+
order: number;
|
|
15
|
+
text: string;
|
|
16
|
+
type: NavigationNodeType;
|
|
17
|
+
isHidden?: boolean;
|
|
18
|
+
data: TData;
|
|
19
|
+
}
|
|
20
|
+
export interface APISchema {
|
|
21
|
+
asyncapi?: AsyncApiConfig;
|
|
22
|
+
openapi?: OpenApiConfig;
|
|
23
|
+
}
|
|
24
|
+
export type HrefSchema = {
|
|
25
|
+
href?: string;
|
|
26
|
+
};
|
|
27
|
+
export type GlobalSchema = {
|
|
28
|
+
isGlobal?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export interface DropdownNode extends BaseNavigationNode<BaseDropdownSchema & APISchema & HrefSchema & GlobalSchema> {
|
|
31
|
+
type: 'dropdown';
|
|
32
|
+
}
|
|
33
|
+
export interface VersionNode extends BaseNavigationNode<BaseVersionSchema & APISchema & HrefSchema & GlobalSchema> {
|
|
34
|
+
type: 'version';
|
|
35
|
+
}
|
|
36
|
+
export interface LanguageNode extends BaseNavigationNode<BaseLanguageSchema & APISchema & HrefSchema & GlobalSchema> {
|
|
37
|
+
type: 'language';
|
|
38
|
+
}
|
|
39
|
+
export interface TabNode extends BaseNavigationNode<BaseTabSchema & APISchema & HrefSchema & GlobalSchema> {
|
|
40
|
+
type: 'tab';
|
|
41
|
+
}
|
|
42
|
+
export interface ProductNode extends BaseNavigationNode<BaseProductSchema & APISchema & HrefSchema & GlobalSchema> {
|
|
43
|
+
type: 'product';
|
|
44
|
+
}
|
|
45
|
+
export interface AnchorNode extends BaseNavigationNode<BaseAnchorSchema & APISchema & HrefSchema & GlobalSchema> {
|
|
46
|
+
type: 'anchor';
|
|
47
|
+
}
|
|
48
|
+
export interface MenuItemNode extends BaseNavigationNode<MenuItemConfig & APISchema & HrefSchema> {
|
|
49
|
+
type: 'item';
|
|
50
|
+
}
|
|
51
|
+
export interface GroupNode extends BaseNavigationNode<BaseGroupSchema & APISchema & {
|
|
52
|
+
fromPages?: boolean;
|
|
53
|
+
}> {
|
|
54
|
+
type: 'group';
|
|
55
|
+
}
|
|
56
|
+
export interface PageNode extends BaseNavigationNode<DecoratedPageConfig & {
|
|
57
|
+
ogImageUrl?: string;
|
|
58
|
+
}> {
|
|
59
|
+
type: 'page';
|
|
60
|
+
}
|
|
61
|
+
export type DivisionNode = DropdownNode | VersionNode | LanguageNode | TabNode | ProductNode | AnchorNode | MenuItemNode;
|
|
62
|
+
export type NavigationNode = DivisionNode | GroupNode | PageNode;
|
|
63
|
+
export type NavigationTree = NavigationNode[];
|
|
64
|
+
export type NodeDataUpdates = {
|
|
65
|
+
title?: DecoratedPageConfig['title'];
|
|
66
|
+
description?: DecoratedPageConfig['description'];
|
|
67
|
+
sidebarTitle?: DecoratedPageConfig['sidebarTitle'];
|
|
68
|
+
ogImageUrl?: string;
|
|
69
|
+
tag?: DecoratedPageConfig['tag'];
|
|
70
|
+
url?: DecoratedPageConfig['url'];
|
|
71
|
+
keywords?: string[];
|
|
72
|
+
mode?: DecoratedPageConfig['mode'];
|
|
73
|
+
icon?: IconConfig;
|
|
74
|
+
iconType?: IconType;
|
|
75
|
+
tab?: BaseTabSchema['tab'];
|
|
76
|
+
anchor?: BaseAnchorSchema['anchor'];
|
|
77
|
+
group?: BaseGroupSchema['group'];
|
|
78
|
+
product?: BaseProductSchema['product'];
|
|
79
|
+
version?: BaseVersionSchema['version'];
|
|
80
|
+
dropdown?: BaseDropdownSchema['dropdown'];
|
|
81
|
+
item?: MenuItemConfig['item'];
|
|
82
|
+
language?: BaseLanguageSchema['language'];
|
|
83
|
+
hidden?: boolean;
|
|
84
|
+
public?: BaseGroupSchema['public'];
|
|
85
|
+
expanded?: BaseGroupSchema['expanded'];
|
|
86
|
+
default?: BaseVersionSchema['default'];
|
|
87
|
+
color?: BaseDropdownSchema['color'];
|
|
88
|
+
href?: string;
|
|
89
|
+
openapi?: OpenApiConfig;
|
|
90
|
+
asyncapi?: AsyncApiConfig;
|
|
91
|
+
};
|
|
92
|
+
export type NodeActions = {
|
|
93
|
+
canHide: boolean;
|
|
94
|
+
canDuplicate: boolean;
|
|
95
|
+
};
|
|
96
|
+
export type NodeConfig = {
|
|
97
|
+
isExpandable: boolean;
|
|
98
|
+
showRoundedLineForParent: NavigationNodeType[];
|
|
99
|
+
actions: NodeActions;
|
|
100
|
+
};
|
|
101
|
+
export type PartialNodeConfig = {
|
|
102
|
+
isExpandable?: boolean;
|
|
103
|
+
showRoundedLineForParent?: NavigationNodeType[];
|
|
104
|
+
actions?: Partial<NodeActions>;
|
|
105
|
+
};
|
|
106
|
+
export type FlatNodeData = {
|
|
107
|
+
type: 'node';
|
|
108
|
+
node: NavigationNode;
|
|
109
|
+
depth: number;
|
|
110
|
+
parentType: NavigationNodeType | null;
|
|
111
|
+
lowerSiblingCounts: number[];
|
|
112
|
+
treeIndex: number;
|
|
113
|
+
parentTypes: (NavigationNodeType | null)[];
|
|
114
|
+
parentIds: (string | 0)[];
|
|
115
|
+
hasChildGroups: boolean;
|
|
116
|
+
hasVisibleChildren: boolean;
|
|
117
|
+
isLastSibling: boolean;
|
|
118
|
+
};
|
|
119
|
+
export type FlatNodeAddNew = {
|
|
120
|
+
type: 'add-new';
|
|
121
|
+
parentId: string;
|
|
122
|
+
depth: number;
|
|
123
|
+
lowerSiblingCounts: number[];
|
|
124
|
+
parentTypes: (NavigationNodeType | null)[];
|
|
125
|
+
parentIds: (string | 0)[];
|
|
126
|
+
};
|
|
127
|
+
export type FlatNodeRootAddNew = {
|
|
128
|
+
type: 'root-add-new';
|
|
129
|
+
};
|
|
130
|
+
export type FlatNode = FlatNodeData | FlatNodeAddNew | FlatNodeRootAddNew;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NavigationNodeType, DivisionType, DivisionNode, ContentType, NavigationNode } from './types.js';
|
|
2
|
+
export declare const isDivisionType: (type: NavigationNodeType) => type is DivisionType;
|
|
3
|
+
export declare const isDivisionNode: (node: NavigationNode) => node is DivisionNode;
|
|
4
|
+
export declare const isContentType: (type: NavigationNodeType) => type is ContentType;
|
|
5
|
+
export declare const generateNodeId: (counter?: number) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DIVISION_TYPES, CONTENT_TYPES, } from './types.js';
|
|
2
|
+
export const isDivisionType = (type) => DIVISION_TYPES.some((t) => t === type);
|
|
3
|
+
export const isDivisionNode = (node) => isDivisionType(node.type);
|
|
4
|
+
export const isContentType = (type) => CONTENT_TYPES.some((t) => t === type);
|
|
5
|
+
export const generateNodeId = (counter) => {
|
|
6
|
+
const counterPart = counter ? `-${counter}` : '';
|
|
7
|
+
return `nav-${Date.now()}${counterPart}-${Math.random().toString(36).substr(2, 9)}`;
|
|
8
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED