@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
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/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
1
|
/**
|
|
4
2
|
* createMarkdownNodes.ts - Helper functions for creating MD AST nodes
|
|
5
3
|
*
|
|
@@ -30,12 +28,10 @@ function normalizeChildren(children) {
|
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
// Convert to array if not already
|
|
33
|
-
|
|
31
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
34
32
|
|
|
35
33
|
// Convert strings to text nodes
|
|
36
|
-
return childArray.map(
|
|
37
|
-
return typeof child === 'string' ? text(child) : child;
|
|
38
|
-
});
|
|
34
|
+
return childArray.map(child => typeof child === 'string' ? text(child) : child);
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
/**
|
|
@@ -121,8 +117,7 @@ export function inlineCode(value) {
|
|
|
121
117
|
* @param excludeFormatting - If true, don't count formatting characters like backticks, brackets, etc.
|
|
122
118
|
* This allows "`false`" and "false" to both be treated as length 5.
|
|
123
119
|
*/
|
|
124
|
-
function getPhrasingContentLength(node) {
|
|
125
|
-
var excludeFormatting = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
120
|
+
function getPhrasingContentLength(node, excludeFormatting = false) {
|
|
126
121
|
switch (node.type) {
|
|
127
122
|
case 'text':
|
|
128
123
|
return node.value.length;
|
|
@@ -131,37 +126,27 @@ function getPhrasingContentLength(node) {
|
|
|
131
126
|
return node.value.length + (excludeFormatting ? 0 : 2);
|
|
132
127
|
case 'emphasis':
|
|
133
128
|
// Asterisks/underscores add chars, but exclude them if normalizing
|
|
134
|
-
return (node.children || []).reduce(
|
|
135
|
-
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
136
|
-
}, excludeFormatting ? 0 : 2 // *text* or _text_ adds 2 chars
|
|
129
|
+
return (node.children || []).reduce((sum, child) => sum + getPhrasingContentLength(child, excludeFormatting), excludeFormatting ? 0 : 2 // *text* or _text_ adds 2 chars
|
|
137
130
|
);
|
|
138
131
|
case 'strong':
|
|
139
132
|
// Double asterisks/underscores add chars, but exclude them if normalizing
|
|
140
|
-
return (node.children || []).reduce(
|
|
141
|
-
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
142
|
-
}, excludeFormatting ? 0 : 4 // **text** or __text__ adds 4 chars
|
|
133
|
+
return (node.children || []).reduce((sum, child) => sum + getPhrasingContentLength(child, excludeFormatting), excludeFormatting ? 0 : 4 // **text** or __text__ adds 4 chars
|
|
143
134
|
);
|
|
144
135
|
case 'delete':
|
|
145
136
|
// Tildes add chars, but exclude them if normalizing
|
|
146
|
-
return (node.children || []).reduce(
|
|
147
|
-
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
148
|
-
}, excludeFormatting ? 0 : 4 // ~~text~~ adds 4 chars
|
|
137
|
+
return (node.children || []).reduce((sum, child) => sum + getPhrasingContentLength(child, excludeFormatting), excludeFormatting ? 0 : 4 // ~~text~~ adds 4 chars
|
|
149
138
|
);
|
|
150
139
|
case 'link':
|
|
151
140
|
{
|
|
152
|
-
var _node$url;
|
|
153
141
|
// [text](url) format adds chars, but exclude them if normalizing
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}, 0);
|
|
157
|
-
return excludeFormatting ? childrenLength : childrenLength + 4 + (((_node$url = node.url) == null ? void 0 : _node$url.length) || 0); // [](url) adds 4 + url length
|
|
142
|
+
const childrenLength = (node.children || []).reduce((sum, child) => sum + getPhrasingContentLength(child, excludeFormatting), 0);
|
|
143
|
+
return excludeFormatting ? childrenLength : childrenLength + 4 + (node.url?.length || 0); // [](url) adds 4 + url length
|
|
158
144
|
}
|
|
159
145
|
case 'image':
|
|
160
146
|
{
|
|
161
|
-
var _node$url2;
|
|
162
147
|
//  format
|
|
163
|
-
|
|
164
|
-
return excludeFormatting ? altLength : altLength + 5 + (
|
|
148
|
+
const altLength = (node.alt || '').length;
|
|
149
|
+
return excludeFormatting ? altLength : altLength + 5 + (node.url?.length || 0); //  adds 5 + url length
|
|
165
150
|
}
|
|
166
151
|
case 'break':
|
|
167
152
|
return 0;
|
|
@@ -177,35 +162,33 @@ function getPhrasingContentLength(node) {
|
|
|
177
162
|
* @param excludeFormatting - If true, don't count formatting chars when calculating width
|
|
178
163
|
* @returns Table cell node
|
|
179
164
|
*/
|
|
180
|
-
function tableCell(content, widthIncrements) {
|
|
181
|
-
|
|
182
|
-
var children = normalizeChildren(content);
|
|
165
|
+
function tableCell(content, widthIncrements, excludeFormatting = true) {
|
|
166
|
+
const children = normalizeChildren(content);
|
|
183
167
|
if (widthIncrements) {
|
|
184
168
|
// Calculate total visual length of all content
|
|
185
|
-
|
|
186
|
-
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
187
|
-
}, 0);
|
|
169
|
+
const totalLength = children.reduce((sum, child) => sum + getPhrasingContentLength(child, excludeFormatting), 0);
|
|
188
170
|
|
|
189
171
|
// Calculate padding needed
|
|
190
|
-
|
|
172
|
+
const paddingNeeded = Math.ceil(totalLength / widthIncrements) * widthIncrements - totalLength;
|
|
191
173
|
|
|
192
174
|
// Add padding as trailing spaces to the last text node, or create a new text node
|
|
193
175
|
if (paddingNeeded > 0) {
|
|
194
|
-
|
|
176
|
+
const spaces = new Array(paddingNeeded).fill(' ').join('');
|
|
195
177
|
|
|
196
178
|
// Find the last text node and append spaces (reverse search)
|
|
197
|
-
|
|
198
|
-
for (
|
|
179
|
+
let lastTextIndex = -1;
|
|
180
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
199
181
|
if (children[i].type === 'text') {
|
|
200
182
|
lastTextIndex = i;
|
|
201
183
|
break;
|
|
202
184
|
}
|
|
203
185
|
}
|
|
204
186
|
if (lastTextIndex >= 0) {
|
|
205
|
-
|
|
206
|
-
children[lastTextIndex] =
|
|
207
|
-
|
|
208
|
-
|
|
187
|
+
const lastText = children[lastTextIndex];
|
|
188
|
+
children[lastTextIndex] = {
|
|
189
|
+
...lastText,
|
|
190
|
+
value: `${lastText.value}${spaces}`
|
|
191
|
+
};
|
|
209
192
|
} else {
|
|
210
193
|
// No text node found, add a new text node with just spaces
|
|
211
194
|
children.push(text(spaces));
|
|
@@ -214,7 +197,7 @@ function tableCell(content, widthIncrements) {
|
|
|
214
197
|
}
|
|
215
198
|
return {
|
|
216
199
|
type: 'tableCell',
|
|
217
|
-
children
|
|
200
|
+
children
|
|
218
201
|
};
|
|
219
202
|
}
|
|
220
203
|
|
|
@@ -226,9 +209,7 @@ function tableCell(content, widthIncrements) {
|
|
|
226
209
|
function tableRow(cells, widthIncrements) {
|
|
227
210
|
return {
|
|
228
211
|
type: 'tableRow',
|
|
229
|
-
children: cells.map(
|
|
230
|
-
return tableCell(cell, widthIncrements);
|
|
231
|
-
})
|
|
212
|
+
children: cells.map(cell => tableCell(cell, widthIncrements))
|
|
232
213
|
};
|
|
233
214
|
}
|
|
234
215
|
|
|
@@ -240,11 +221,9 @@ function tableRow(cells, widthIncrements) {
|
|
|
240
221
|
* @param {number} [widthIncrements] - Optional value to control the increments that tables expand for cleaner
|
|
241
222
|
* @returns {Object} A table node
|
|
242
223
|
*/
|
|
243
|
-
export function table(headers, rows) {
|
|
244
|
-
var alignment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
245
|
-
var widthIncrements = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 7;
|
|
224
|
+
export function table(headers, rows, alignment = null, widthIncrements = 7) {
|
|
246
225
|
// Convert alignment strings to AST format
|
|
247
|
-
|
|
226
|
+
const align = headers.map((_, index) => {
|
|
248
227
|
if (!alignment || !alignment[index]) {
|
|
249
228
|
return null;
|
|
250
229
|
}
|
|
@@ -259,18 +238,16 @@ export function table(headers, rows) {
|
|
|
259
238
|
});
|
|
260
239
|
|
|
261
240
|
// Create header row
|
|
262
|
-
|
|
241
|
+
const headerRow = tableRow(headers);
|
|
263
242
|
|
|
264
243
|
// Create data rows - rows is actually an array of arrays
|
|
265
|
-
|
|
266
|
-
return tableRow(row, widthIncrements);
|
|
267
|
-
});
|
|
244
|
+
const dataRows = rows.map(row => tableRow(row, widthIncrements));
|
|
268
245
|
|
|
269
246
|
// Return table node
|
|
270
247
|
return {
|
|
271
248
|
type: 'table',
|
|
272
|
-
align
|
|
273
|
-
children: [headerRow]
|
|
249
|
+
align,
|
|
250
|
+
children: [headerRow, ...dataRows]
|
|
274
251
|
};
|
|
275
252
|
}
|
|
276
253
|
|
|
@@ -298,8 +275,8 @@ export function comment(value, ref) {
|
|
|
298
275
|
export function link(url, children, title) {
|
|
299
276
|
return {
|
|
300
277
|
type: 'link',
|
|
301
|
-
url
|
|
302
|
-
title
|
|
278
|
+
url,
|
|
279
|
+
title,
|
|
303
280
|
children: normalizeChildren(children)
|
|
304
281
|
};
|
|
305
282
|
}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
6
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
-
var _excluded = ["descriptionMarkdown"];
|
|
8
1
|
import { markdownToMetadata, metadataToMarkdown } from "./metadataToMarkdown.js";
|
|
9
2
|
|
|
10
3
|
/**
|
|
@@ -48,162 +41,116 @@ import { markdownToMetadata, metadataToMarkdown } from "./metadataToMarkdown.js"
|
|
|
48
41
|
* // Result preserves Button, Checkbox order from existing markdown, adds Input at the end
|
|
49
42
|
* ```
|
|
50
43
|
*/
|
|
51
|
-
export function mergeMetadataMarkdown(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var options,
|
|
57
|
-
indexWrapperComponent,
|
|
58
|
-
path,
|
|
59
|
-
existingMetadata,
|
|
60
|
-
effectiveWrapper,
|
|
61
|
-
newPagesMap,
|
|
62
|
-
_iterator,
|
|
63
|
-
_step,
|
|
64
|
-
page,
|
|
65
|
-
pages,
|
|
66
|
-
addedPaths,
|
|
67
|
-
_iterator2,
|
|
68
|
-
_step2,
|
|
69
|
-
existingPage,
|
|
70
|
-
newPage,
|
|
71
|
-
descriptionMarkdown,
|
|
72
|
-
existingPageWithoutDescriptionMarkdown,
|
|
73
|
-
merged,
|
|
74
|
-
_iterator3,
|
|
75
|
-
_step3,
|
|
76
|
-
_newPage,
|
|
77
|
-
pageWithTag,
|
|
78
|
-
alphabeticalSortMarker,
|
|
79
|
-
requestsAlphabeticalSort,
|
|
80
|
-
mergedMetadata,
|
|
81
|
-
_args = arguments;
|
|
82
|
-
return _regenerator().w(function (_context) {
|
|
83
|
-
while (1) switch (_context.n) {
|
|
84
|
-
case 0:
|
|
85
|
-
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
86
|
-
indexWrapperComponent = options.indexWrapperComponent, path = options.path; // If no existing markdown, just convert the new metadata
|
|
87
|
-
// Use the provided wrapper unless it's null (which means remove)
|
|
88
|
-
if (existingMarkdown) {
|
|
89
|
-
_context.n = 1;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return _context.a(2, metadataToMarkdown(newMetadata, {
|
|
93
|
-
indexWrapperComponent: indexWrapperComponent === null ? undefined : indexWrapperComponent,
|
|
94
|
-
path: path
|
|
95
|
-
}));
|
|
96
|
-
case 1:
|
|
97
|
-
_context.n = 2;
|
|
98
|
-
return markdownToMetadata(existingMarkdown);
|
|
99
|
-
case 2:
|
|
100
|
-
existingMetadata = _context.v;
|
|
101
|
-
if (existingMetadata) {
|
|
102
|
-
_context.n = 3;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
return _context.a(2, metadataToMarkdown(newMetadata, {
|
|
106
|
-
indexWrapperComponent: indexWrapperComponent === null ? undefined : indexWrapperComponent,
|
|
107
|
-
path: path
|
|
108
|
-
}));
|
|
109
|
-
case 3:
|
|
110
|
-
if (indexWrapperComponent === undefined) {
|
|
111
|
-
effectiveWrapper = existingMetadata.indexWrapperComponent;
|
|
112
|
-
} else if (indexWrapperComponent === null) {
|
|
113
|
-
effectiveWrapper = undefined;
|
|
114
|
-
} else {
|
|
115
|
-
effectiveWrapper = indexWrapperComponent;
|
|
116
|
-
}
|
|
44
|
+
export async function mergeMetadataMarkdown(existingMarkdown, newMetadata, options = {}) {
|
|
45
|
+
const {
|
|
46
|
+
indexWrapperComponent,
|
|
47
|
+
path
|
|
48
|
+
} = options;
|
|
117
49
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
50
|
+
// If no existing markdown, just convert the new metadata
|
|
51
|
+
// Use the provided wrapper unless it's null (which means remove)
|
|
52
|
+
if (!existingMarkdown) {
|
|
53
|
+
return metadataToMarkdown(newMetadata, {
|
|
54
|
+
indexWrapperComponent: indexWrapperComponent === null ? undefined : indexWrapperComponent,
|
|
55
|
+
path
|
|
56
|
+
});
|
|
57
|
+
}
|
|
126
58
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
_iterator.e(err);
|
|
130
|
-
} finally {
|
|
131
|
-
_iterator.f();
|
|
132
|
-
}
|
|
133
|
-
pages = [];
|
|
134
|
-
addedPaths = new Set(); // First, add all pages that exist in the existing markdown, in their original order
|
|
135
|
-
_iterator2 = _createForOfIteratorHelper(existingMetadata.pages);
|
|
136
|
-
try {
|
|
137
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
138
|
-
existingPage = _step2.value;
|
|
139
|
-
newPage = newPagesMap.get(existingPage.path);
|
|
140
|
-
if (newPage) {
|
|
141
|
-
// Page exists in both - merge the metadata, preferring new values
|
|
142
|
-
// Only exclude descriptionMarkdown if newPage provides a new description
|
|
143
|
-
descriptionMarkdown = existingPage.descriptionMarkdown, existingPageWithoutDescriptionMarkdown = _objectWithoutPropertiesLoose(existingPage, _excluded);
|
|
144
|
-
merged = _extends(_extends(_extends({}, newPage.description ? existingPageWithoutDescriptionMarkdown : existingPage), newPage), {}, {
|
|
145
|
-
// Preserve tags from existing (user-managed, program should never delete tags)
|
|
146
|
-
tags: existingPage.tags,
|
|
147
|
-
// Preserve skipDetailSection from existing (user-managed for external links)
|
|
148
|
-
skipDetailSection: existingPage.skipDetailSection,
|
|
149
|
-
// Preserve sections from existing if new doesn't have them
|
|
150
|
-
sections: newPage.sections || existingPage.sections
|
|
151
|
-
});
|
|
152
|
-
pages.push(merged);
|
|
153
|
-
addedPaths.add(newPage.path);
|
|
154
|
-
}
|
|
155
|
-
// If page doesn't exist in new metadata, it's been removed - don't include it
|
|
156
|
-
}
|
|
59
|
+
// Parse the existing markdown to get the current order
|
|
60
|
+
const existingMetadata = await markdownToMetadata(existingMarkdown);
|
|
157
61
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
try {
|
|
166
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
167
|
-
_newPage = _step3.value;
|
|
168
|
-
if (!addedPaths.has(_newPage.path)) {
|
|
169
|
-
// This is a new page - automatically add the [New] tag
|
|
170
|
-
pageWithTag = _extends(_extends({}, _newPage), {}, {
|
|
171
|
-
tags: _newPage.tags ? [].concat(_toConsumableArray(_newPage.tags), ['New']) : ['New']
|
|
172
|
-
});
|
|
173
|
-
pages.push(pageWithTag);
|
|
174
|
-
addedPaths.add(_newPage.path);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
62
|
+
// If parsing failed, just use the new metadata
|
|
63
|
+
if (!existingMetadata) {
|
|
64
|
+
return metadataToMarkdown(newMetadata, {
|
|
65
|
+
indexWrapperComponent: indexWrapperComponent === null ? undefined : indexWrapperComponent,
|
|
66
|
+
path
|
|
67
|
+
});
|
|
68
|
+
}
|
|
177
69
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return titleA.localeCompare(titleB);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
70
|
+
// Determine effective wrapper component:
|
|
71
|
+
// - undefined: preserve existing
|
|
72
|
+
// - null: explicitly remove
|
|
73
|
+
// - string: use provided value
|
|
74
|
+
let effectiveWrapper;
|
|
75
|
+
if (indexWrapperComponent === undefined) {
|
|
76
|
+
effectiveWrapper = existingMetadata.indexWrapperComponent;
|
|
77
|
+
} else if (indexWrapperComponent === null) {
|
|
78
|
+
effectiveWrapper = undefined;
|
|
79
|
+
} else {
|
|
80
|
+
effectiveWrapper = indexWrapperComponent;
|
|
81
|
+
}
|
|
193
82
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
83
|
+
// Create a map of new pages by path for quick lookup
|
|
84
|
+
const newPagesMap = new Map();
|
|
85
|
+
for (const page of newMetadata.pages) {
|
|
86
|
+
newPagesMap.set(page.path, page);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Build the merged pages array, preserving order from existing markdown
|
|
90
|
+
let pages = [];
|
|
91
|
+
const addedPaths = new Set();
|
|
92
|
+
|
|
93
|
+
// First, add all pages that exist in the existing markdown, in their original order
|
|
94
|
+
for (const existingPage of existingMetadata.pages) {
|
|
95
|
+
const newPage = newPagesMap.get(existingPage.path);
|
|
96
|
+
if (newPage) {
|
|
97
|
+
// Page exists in both - merge the metadata, preferring new values
|
|
98
|
+
// Only exclude descriptionMarkdown if newPage provides a new description
|
|
99
|
+
const {
|
|
100
|
+
descriptionMarkdown,
|
|
101
|
+
...existingPageWithoutDescriptionMarkdown
|
|
102
|
+
} = existingPage;
|
|
103
|
+
const merged = {
|
|
104
|
+
...(newPage.description ? existingPageWithoutDescriptionMarkdown : existingPage),
|
|
105
|
+
...newPage,
|
|
106
|
+
// Preserve tags from existing (user-managed, program should never delete tags)
|
|
107
|
+
tags: existingPage.tags,
|
|
108
|
+
// Preserve skipDetailSection from existing (user-managed for external links)
|
|
109
|
+
skipDetailSection: existingPage.skipDetailSection,
|
|
110
|
+
// Preserve sections from existing if new doesn't have them
|
|
111
|
+
sections: newPage.sections || existingPage.sections
|
|
112
|
+
};
|
|
113
|
+
pages.push(merged);
|
|
114
|
+
addedPaths.add(newPage.path);
|
|
115
|
+
}
|
|
116
|
+
// If page doesn't exist in new metadata, it's been removed - don't include it
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Then, add any new pages that weren't in the existing markdown
|
|
120
|
+
for (const newPage of newMetadata.pages) {
|
|
121
|
+
if (!addedPaths.has(newPage.path)) {
|
|
122
|
+
// This is a new page - automatically add the [New] tag
|
|
123
|
+
const pageWithTag = {
|
|
124
|
+
...newPage,
|
|
125
|
+
tags: newPage.tags ? [...newPage.tags, 'New'] : ['New']
|
|
126
|
+
};
|
|
127
|
+
pages.push(pageWithTag);
|
|
128
|
+
addedPaths.add(newPage.path);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// If alphabetical sorting is requested, sort pages alphabetically by title
|
|
133
|
+
const alphabeticalSortMarker = "[//]: # 'This file is autogenerated, but the following list can be modified. Automatically sorted alphabetically.'";
|
|
134
|
+
const requestsAlphabeticalSort = existingMarkdown.includes(alphabeticalSortMarker);
|
|
135
|
+
if (requestsAlphabeticalSort) {
|
|
136
|
+
pages = pages.sort((a, b) => {
|
|
137
|
+
const titleA = a.title || a.slug;
|
|
138
|
+
const titleB = b.title || b.slug;
|
|
139
|
+
return titleA.localeCompare(titleB);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Create the final metadata with merged pages
|
|
144
|
+
const mergedMetadata = {
|
|
145
|
+
title: newMetadata.title,
|
|
146
|
+
// Always use the new title
|
|
147
|
+
pages
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Preserve the alphabetical sorting marker if it was present
|
|
151
|
+
return metadataToMarkdown(mergedMetadata, {
|
|
152
|
+
editableMarker: requestsAlphabeticalSort ? alphabeticalSortMarker : undefined,
|
|
153
|
+
indexWrapperComponent: effectiveWrapper,
|
|
154
|
+
path
|
|
155
|
+
});
|
|
209
156
|
}
|