@mui/internal-docs-infra 0.1.1-alpha.9 → 0.1.1-canary.1
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/README.md +1 -3
- package/esm/package.json +1 -0
- package/esm/useCopier/index.d.ts +15 -0
- package/esm/useCopier/index.d.ts.map +1 -0
- package/esm/useCopier/index.js +62 -0
- package/esm/useDemo/index.d.ts +51 -0
- package/esm/useDemo/index.d.ts.map +1 -0
- package/esm/useDemo/index.js +104 -0
- package/package.json +31 -32
- package/useCopier/index.d.ts +1 -1
- package/useCopier/index.js +23 -15
- package/useDemo/index.d.ts +51 -6
- package/useDemo/index.js +112 -6
- package/CodeControllerContext/CodeControllerContext.d.ts +0 -22
- package/CodeControllerContext/CodeControllerContext.d.ts.map +0 -1
- package/CodeControllerContext/CodeControllerContext.js +0 -14
- package/CodeControllerContext/index.d.ts +0 -1
- package/CodeControllerContext/index.d.ts.map +0 -1
- package/CodeControllerContext/index.js +0 -1
- package/CodeExternalsContext/CodeExternalsContext.d.ts +0 -8
- package/CodeExternalsContext/CodeExternalsContext.d.ts.map +0 -1
- package/CodeExternalsContext/CodeExternalsContext.js +0 -7
- package/CodeExternalsContext/index.d.ts +0 -1
- package/CodeExternalsContext/index.d.ts.map +0 -1
- package/CodeExternalsContext/index.js +0 -1
- package/CodeHighlighter/CodeHighlighter.d.ts +0 -2
- package/CodeHighlighter/CodeHighlighter.d.ts.map +0 -1
- package/CodeHighlighter/CodeHighlighter.js +0 -470
- package/CodeHighlighter/CodeHighlighterClient.d.ts +0 -2
- package/CodeHighlighter/CodeHighlighterClient.d.ts.map +0 -1
- package/CodeHighlighter/CodeHighlighterClient.js +0 -837
- package/CodeHighlighter/CodeHighlighterContext.d.ts +0 -16
- package/CodeHighlighter/CodeHighlighterContext.d.ts.map +0 -1
- package/CodeHighlighter/CodeHighlighterContext.js +0 -14
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +0 -7
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts.map +0 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.js +0 -13
- package/CodeHighlighter/applyTransform.d.ts +0 -19
- package/CodeHighlighter/applyTransform.d.ts.map +0 -1
- package/CodeHighlighter/applyTransform.js +0 -75
- package/CodeHighlighter/codeToFallbackProps.d.ts +0 -2
- package/CodeHighlighter/codeToFallbackProps.d.ts.map +0 -1
- package/CodeHighlighter/codeToFallbackProps.js +0 -73
- package/CodeHighlighter/errors.d.ts +0 -0
- package/CodeHighlighter/errors.d.ts.map +0 -1
- package/CodeHighlighter/errors.js +0 -1
- package/CodeHighlighter/hasAllVariants.d.ts +0 -2
- package/CodeHighlighter/hasAllVariants.d.ts.map +0 -1
- package/CodeHighlighter/hasAllVariants.js +0 -31
- package/CodeHighlighter/index.d.ts +0 -4
- package/CodeHighlighter/index.d.ts.map +0 -1
- package/CodeHighlighter/index.js +0 -4
- package/CodeHighlighter/loadFallbackCode.d.ts +0 -10
- package/CodeHighlighter/loadFallbackCode.d.ts.map +0 -1
- package/CodeHighlighter/loadFallbackCode.js +0 -632
- package/CodeHighlighter/loadVariant.d.ts +0 -12
- package/CodeHighlighter/loadVariant.d.ts.map +0 -1
- package/CodeHighlighter/loadVariant.js +0 -1083
- package/CodeHighlighter/maybeInitialData.d.ts +0 -10
- package/CodeHighlighter/maybeInitialData.d.ts.map +0 -1
- package/CodeHighlighter/maybeInitialData.js +0 -94
- package/CodeHighlighter/parseCode.d.ts +0 -6
- package/CodeHighlighter/parseCode.d.ts.map +0 -1
- package/CodeHighlighter/parseCode.js +0 -134
- package/CodeHighlighter/parseControlledCode.d.ts +0 -6
- package/CodeHighlighter/parseControlledCode.d.ts.map +0 -1
- package/CodeHighlighter/parseControlledCode.js +0 -87
- package/CodeHighlighter/transformCode.d.ts +0 -21
- package/CodeHighlighter/transformCode.d.ts.map +0 -1
- package/CodeHighlighter/transformCode.js +0 -263
- package/CodeHighlighter/transformParsedSource.d.ts +0 -3
- package/CodeHighlighter/transformParsedSource.d.ts.map +0 -1
- package/CodeHighlighter/transformParsedSource.js +0 -66
- package/CodeHighlighter/transformSource.d.ts +0 -2
- package/CodeHighlighter/transformSource.d.ts.map +0 -1
- package/CodeHighlighter/transformSource.js +0 -107
- package/CodeHighlighter/types.d.ts +0 -160
- package/CodeHighlighter/types.d.ts.map +0 -1
- package/CodeHighlighter/types.js +0 -1
- package/CodeProvider/CodeContext.d.ts +0 -12
- package/CodeProvider/CodeContext.d.ts.map +0 -1
- package/CodeProvider/CodeContext.js +0 -8
- package/CodeProvider/CodeProvider.d.ts +0 -13
- package/CodeProvider/CodeProvider.d.ts.map +0 -1
- package/CodeProvider/CodeProvider.js +0 -65
- package/CodeProvider/index.d.ts +0 -1
- package/CodeProvider/index.d.ts.map +0 -1
- package/CodeProvider/index.js +0 -1
- package/abstractCreateDemo/abstractCreateDemo.d.ts +0 -35
- package/abstractCreateDemo/abstractCreateDemo.d.ts.map +0 -1
- package/abstractCreateDemo/abstractCreateDemo.js +0 -91
- package/abstractCreateDemo/index.d.ts +0 -1
- package/abstractCreateDemo/index.d.ts.map +0 -1
- package/abstractCreateDemo/index.js +0 -1
- package/createDemoData/createDemoData.d.ts +0 -44
- package/createDemoData/createDemoData.d.ts.map +0 -1
- package/createDemoData/createDemoData.js +0 -75
- package/createDemoData/index.d.ts +0 -1
- package/createDemoData/index.d.ts.map +0 -1
- package/createDemoData/index.js +0 -1
- package/createDemoData/types.d.ts +0 -28
- package/createDemoData/types.d.ts.map +0 -1
- package/createDemoData/types.js +0 -1
- package/pipeline/hastUtils/hastUtils.d.ts +0 -11
- package/pipeline/hastUtils/hastUtils.d.ts.map +0 -1
- package/pipeline/hastUtils/hastUtils.js +0 -67
- package/pipeline/hastUtils/index.d.ts +0 -1
- package/pipeline/hastUtils/index.d.ts.map +0 -1
- package/pipeline/hastUtils/index.js +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/emitExternalsProvider.d.ts +0 -54
- package/pipeline/loadPrecomputedCodeHighlighter/emitExternalsProvider.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/emitExternalsProvider.js +0 -465
- package/pipeline/loadPrecomputedCodeHighlighter/generateExternalsProvider.d.ts +0 -15
- package/pipeline/loadPrecomputedCodeHighlighter/generateExternalsProvider.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/generateExternalsProvider.js +0 -253
- package/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +0 -2
- package/pipeline/loadPrecomputedCodeHighlighter/index.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/index.js +0 -4
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +0 -20
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +0 -224
- package/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +0 -31
- package/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +0 -433
- package/pipeline/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts +0 -19
- package/pipeline/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/parseFunctionParameters.js +0 -168
- package/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +0 -25
- package/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +0 -1
- package/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +0 -73
- package/pipeline/loadServerCodeMeta/index.d.ts +0 -1
- package/pipeline/loadServerCodeMeta/index.d.ts.map +0 -1
- package/pipeline/loadServerCodeMeta/index.js +0 -1
- package/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +0 -24
- package/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts.map +0 -1
- package/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +0 -92
- package/pipeline/loadServerSource/index.d.ts +0 -1
- package/pipeline/loadServerSource/index.d.ts.map +0 -1
- package/pipeline/loadServerSource/index.js +0 -1
- package/pipeline/loadServerSource/loadServerSource.d.ts +0 -25
- package/pipeline/loadServerSource/loadServerSource.d.ts.map +0 -1
- package/pipeline/loadServerSource/loadServerSource.js +0 -135
- package/pipeline/loaderUtils/externalsToPackages.d.ts +0 -1
- package/pipeline/loaderUtils/externalsToPackages.d.ts.map +0 -1
- package/pipeline/loaderUtils/externalsToPackages.js +0 -46
- package/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +0 -34
- package/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts.map +0 -1
- package/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +0 -161
- package/pipeline/loaderUtils/getFileNameFromUrl.d.ts +0 -11
- package/pipeline/loaderUtils/getFileNameFromUrl.d.ts.map +0 -1
- package/pipeline/loaderUtils/getFileNameFromUrl.js +0 -32
- package/pipeline/loaderUtils/index.d.ts +0 -7
- package/pipeline/loaderUtils/index.d.ts.map +0 -1
- package/pipeline/loaderUtils/index.js +0 -7
- package/pipeline/loaderUtils/mergeExternals.d.ts +0 -32
- package/pipeline/loaderUtils/mergeExternals.d.ts.map +0 -1
- package/pipeline/loaderUtils/mergeExternals.js +0 -72
- package/pipeline/loaderUtils/parseImports.d.ts +0 -20
- package/pipeline/loaderUtils/parseImports.d.ts.map +0 -1
- package/pipeline/loaderUtils/parseImports.js +0 -307
- package/pipeline/loaderUtils/processRelativeImports.d.ts +0 -19
- package/pipeline/loaderUtils/processRelativeImports.d.ts.map +0 -1
- package/pipeline/loaderUtils/processRelativeImports.js +0 -329
- package/pipeline/loaderUtils/resolveModulePath.d.ts +0 -87
- package/pipeline/loaderUtils/resolveModulePath.d.ts.map +0 -1
- package/pipeline/loaderUtils/resolveModulePath.js +0 -1449
- package/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +0 -47
- package/pipeline/loaderUtils/resolveModulePathWithFs.d.ts.map +0 -1
- package/pipeline/loaderUtils/resolveModulePathWithFs.js +0 -163
- package/pipeline/loaderUtils/rewriteImports.d.ts +0 -9
- package/pipeline/loaderUtils/rewriteImports.d.ts.map +0 -1
- package/pipeline/loaderUtils/rewriteImports.js +0 -35
- package/pipeline/parseSource/grammars.d.ts +0 -2
- package/pipeline/parseSource/grammars.d.ts.map +0 -1
- package/pipeline/parseSource/grammars.js +0 -27
- package/pipeline/parseSource/index.d.ts +0 -1
- package/pipeline/parseSource/index.d.ts.map +0 -1
- package/pipeline/parseSource/index.js +0 -1
- package/pipeline/parseSource/parseSource.d.ts +0 -3
- package/pipeline/parseSource/parseSource.d.ts.map +0 -1
- package/pipeline/parseSource/parseSource.js +0 -47
- package/pipeline/transformHtmlCode/index.d.ts +0 -2
- package/pipeline/transformHtmlCode/index.d.ts.map +0 -1
- package/pipeline/transformHtmlCode/index.js +0 -4
- package/pipeline/transformHtmlCode/transformHtmlCode.d.ts +0 -13
- package/pipeline/transformHtmlCode/transformHtmlCode.d.ts.map +0 -1
- package/pipeline/transformHtmlCode/transformHtmlCode.js +0 -303
- package/pipeline/transformMarkdownCode/index.d.ts +0 -2
- package/pipeline/transformMarkdownCode/index.d.ts.map +0 -1
- package/pipeline/transformMarkdownCode/index.js +0 -4
- package/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +0 -2
- package/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts.map +0 -1
- package/pipeline/transformMarkdownCode/transformMarkdownCode.js +0 -514
- package/pipeline/transformTypescriptToJavascript/index.d.ts +0 -1
- package/pipeline/transformTypescriptToJavascript/index.d.ts.map +0 -1
- package/pipeline/transformTypescriptToJavascript/index.js +0 -1
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +0 -13
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.ts.map +0 -1
- package/pipeline/transformTypescriptToJavascript/removeTypes.js +0 -134
- package/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +0 -3
- package/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts.map +0 -1
- package/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +0 -34
- package/useCode/index.d.ts +0 -1
- package/useCode/index.d.ts.map +0 -1
- package/useCode/index.js +0 -1
- package/useCode/useCode.d.ts +0 -39
- package/useCode/useCode.d.ts.map +0 -1
- package/useCode/useCode.js +0 -122
- package/useCode/useCodeUtils.d.ts +0 -45
- package/useCode/useCodeUtils.d.ts.map +0 -1
- package/useCode/useCodeUtils.js +0 -240
- package/useCode/useCopyFunctionality.d.ts +0 -17
- package/useCode/useCopyFunctionality.d.ts.map +0 -1
- package/useCode/useCopyFunctionality.js +0 -28
- package/useCode/useFileNavigation.d.ts +0 -48
- package/useCode/useFileNavigation.d.ts.map +0 -1
- package/useCode/useFileNavigation.js +0 -370
- package/useCode/useSourceEditing.d.ts +0 -19
- package/useCode/useSourceEditing.d.ts.map +0 -1
- package/useCode/useSourceEditing.js +0 -32
- package/useCode/useTransformManagement.d.ts +0 -28
- package/useCode/useTransformManagement.d.ts.map +0 -1
- package/useCode/useTransformManagement.js +0 -82
- package/useCode/useUIState.d.ts +0 -16
- package/useCode/useUIState.d.ts.map +0 -1
- package/useCode/useUIState.js +0 -21
- package/useCode/useVariantSelection.d.ts +0 -21
- package/useCode/useVariantSelection.d.ts.map +0 -1
- package/useCode/useVariantSelection.js +0 -84
- package/useCopier/index.d.ts.map +0 -1
- package/useDemo/createCodeSandbox.d.ts +0 -18
- package/useDemo/createCodeSandbox.d.ts.map +0 -1
- package/useDemo/createCodeSandbox.js +0 -48
- package/useDemo/createStackBlitz.d.ts +0 -22
- package/useDemo/createStackBlitz.d.ts.map +0 -1
- package/useDemo/createStackBlitz.js +0 -38
- package/useDemo/examineVariant.d.ts +0 -25
- package/useDemo/examineVariant.d.ts.map +0 -1
- package/useDemo/examineVariant.js +0 -134
- package/useDemo/exportVariant.d.ts +0 -110
- package/useDemo/exportVariant.d.ts.map +0 -1
- package/useDemo/exportVariant.js +0 -320
- package/useDemo/exportVariantAsCra.d.ts +0 -15
- package/useDemo/exportVariantAsCra.d.ts.map +0 -1
- package/useDemo/exportVariantAsCra.js +0 -56
- package/useDemo/flattenVariant.d.ts +0 -17
- package/useDemo/flattenVariant.d.ts.map +0 -1
- package/useDemo/flattenVariant.js +0 -206
- package/useDemo/index.d.ts.map +0 -1
- package/useDemo/useDemo.d.ts +0 -78
- package/useDemo/useDemo.d.ts.map +0 -1
- package/useDemo/useDemo.js +0 -174
- package/useLocalStorageState/index.d.ts +0 -2
- package/useLocalStorageState/index.d.ts.map +0 -1
- package/useLocalStorageState/index.js +0 -2
- package/useLocalStorageState/useLocalStorageState.d.ts +0 -14
- package/useLocalStorageState/useLocalStorageState.d.ts.map +0 -1
- package/useLocalStorageState/useLocalStorageState.js +0 -128
- package/useOnHydrate/index.d.ts +0 -1
- package/useOnHydrate/index.d.ts.map +0 -1
- package/useOnHydrate/index.js +0 -1
- package/useOnHydrate/useOnHydrate.d.ts +0 -1
- package/useOnHydrate/useOnHydrate.d.ts.map +0 -1
- package/useOnHydrate/useOnHydrate.js +0 -18
- package/useOnIdle/index.d.ts +0 -1
- package/useOnIdle/index.d.ts.map +0 -1
- package/useOnIdle/index.js +0 -1
- package/useOnIdle/useOnIdle.d.ts +0 -1
- package/useOnIdle/useOnIdle.d.ts.map +0 -1
- package/useOnIdle/useOnIdle.js +0 -39
- package/useUrlHashState/index.d.ts +0 -1
- package/useUrlHashState/index.d.ts.map +0 -1
- package/useUrlHashState/index.js +0 -1
- package/useUrlHashState/useUrlHashState.d.ts +0 -50
- package/useUrlHashState/useUrlHashState.d.ts.map +0 -1
- package/useUrlHashState/useUrlHashState.js +0 -113
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
/**
|
|
3
|
-
* Adds or replaces precompute data in createDemo function calls.
|
|
4
|
-
*
|
|
5
|
-
* This function handles multiple scenarios:
|
|
6
|
-
* 1. Replaces any existing 'precompute' property with actual data
|
|
7
|
-
* 2. Adds precompute property to existing options object when missing
|
|
8
|
-
* 3. Adds entire options object with precompute when no options exist
|
|
9
|
-
* 4. Optionally adds an ExternalsProvider property for external dependencies
|
|
10
|
-
*
|
|
11
|
-
* @param source - The source code string containing createDemo calls
|
|
12
|
-
* @param precomputeData - The data object to inject
|
|
13
|
-
* @param demoCallInfo - Information about the parsed demo call structure
|
|
14
|
-
* @param externalsProviderPath - Optional path to the generated externals provider file
|
|
15
|
-
* @returns The modified source code with precompute data injected
|
|
16
|
-
*/
|
|
17
|
-
export function replacePrecomputeValue(source, precomputeData, demoCallInfo, externalsProviderPath) {
|
|
18
|
-
// Convert the data to a properly formatted JSON string
|
|
19
|
-
var precomputeDataString = JSON.stringify(precomputeData, null, 2);
|
|
20
|
-
|
|
21
|
-
// If no demoCallInfo provided, return unchanged
|
|
22
|
-
if (!demoCallInfo) {
|
|
23
|
-
return source;
|
|
24
|
-
}
|
|
25
|
-
var callInfo = demoCallInfo;
|
|
26
|
-
var fullMatch = callInfo.fullMatch,
|
|
27
|
-
optionsObjectStr = callInfo.optionsObjectStr,
|
|
28
|
-
hasOptions = callInfo.hasOptions,
|
|
29
|
-
hasPrecompute = callInfo.hasPrecompute,
|
|
30
|
-
precomputeKeyStart = callInfo.precomputeKeyStart,
|
|
31
|
-
precomputeValueEnd = callInfo.precomputeValueEnd;
|
|
32
|
-
|
|
33
|
-
// Prepare externals provider import and property if needed
|
|
34
|
-
var modifiedSource = source;
|
|
35
|
-
var additionalProperties = '';
|
|
36
|
-
if (externalsProviderPath) {
|
|
37
|
-
// Add import statement at the top of the file
|
|
38
|
-
var importStatement = "import { CodeExternalsProvider } from '".concat(externalsProviderPath, "';\n");
|
|
39
|
-
modifiedSource = importStatement + modifiedSource;
|
|
40
|
-
|
|
41
|
-
// Prepare the CodeExternalsProvider property
|
|
42
|
-
additionalProperties = ", CodeExternalsProvider";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Case 1: Replace existing precompute property (from key start to value end)
|
|
46
|
-
if (hasPrecompute && precomputeKeyStart !== undefined && precomputeValueEnd !== undefined) {
|
|
47
|
-
// Replace the entire property from key start to value end
|
|
48
|
-
var beforeProperty = optionsObjectStr.substring(0, precomputeKeyStart);
|
|
49
|
-
var afterProperty = optionsObjectStr.substring(precomputeValueEnd);
|
|
50
|
-
var newOptionsStr = "".concat(beforeProperty, "precompute: ").concat(precomputeDataString).concat(additionalProperties).concat(afterProperty);
|
|
51
|
-
return modifiedSource.replace(optionsObjectStr, newOptionsStr);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Case 2: Add precompute to existing options object
|
|
55
|
-
if (hasOptions) {
|
|
56
|
-
var optionsMatch = optionsObjectStr.match(/^(\s*\{)([\s\S]*?)(\s*\}\s*)$/);
|
|
57
|
-
if (optionsMatch) {
|
|
58
|
-
var _optionsMatch = _slicedToArray(optionsMatch, 4),
|
|
59
|
-
openBrace = _optionsMatch[1],
|
|
60
|
-
content = _optionsMatch[2],
|
|
61
|
-
closeBrace = _optionsMatch[3];
|
|
62
|
-
var trimmedContent = content.trim();
|
|
63
|
-
var needsComma = trimmedContent !== '' && !trimmedContent.endsWith(',');
|
|
64
|
-
var newOptions = "".concat(openBrace).concat(content).concat(needsComma ? ',' : '', "\n precompute: ").concat(precomputeDataString).concat(additionalProperties).concat(closeBrace);
|
|
65
|
-
return modifiedSource.replace(optionsObjectStr, newOptions);
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
// Case 3: Add entire options object
|
|
69
|
-
var newCall = fullMatch.replace(/(\s*)\)$/, "$1, { precompute: ".concat(precomputeDataString).concat(additionalProperties, " })"));
|
|
70
|
-
return modifiedSource.replace(fullMatch, newCall);
|
|
71
|
-
}
|
|
72
|
-
return source;
|
|
73
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./loadServerCodeMeta.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loadServerCodeMeta/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./loadServerCodeMeta.js";
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { LoadCodeMeta } from "../../CodeHighlighter/types.js";
|
|
2
|
-
export interface CreateLoadCodeMetaOptions {}
|
|
3
|
-
/**
|
|
4
|
-
* Default loadServerCodeMeta function that resolves variant paths from demo files.
|
|
5
|
-
* This function is used to load code metadata for demos, specifically resolving paths for variants defined in the demo files.
|
|
6
|
-
* It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
|
|
7
|
-
* It returns a Code object mapping variant names to their resolved file URLs.
|
|
8
|
-
*/
|
|
9
|
-
export declare const loadServerCodeMeta: LoadCodeMeta;
|
|
10
|
-
/**
|
|
11
|
-
* Creates a loadCodeMeta function that resolves variant paths from demo files.
|
|
12
|
-
*
|
|
13
|
-
* This factory function creates a LoadCodeMeta implementation that:
|
|
14
|
-
* 1. Parses the demo file to find createDemo calls with variants
|
|
15
|
-
* 2. Resolves all variant entry point paths using resolveVariantPaths
|
|
16
|
-
* 3. Returns a Code object mapping variant names to their resolved file URLs
|
|
17
|
-
*
|
|
18
|
-
* The actual loading, parsing, and transformation of the variants is handled
|
|
19
|
-
* elsewhere by the CodeHighlighter component using loadVariant.
|
|
20
|
-
*
|
|
21
|
-
* @param options - Configuration options (currently unused)
|
|
22
|
-
* @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
|
|
23
|
-
*/
|
|
24
|
-
export declare function createLoadServerCodeMeta(_options?: CreateLoadCodeMetaOptions): LoadCodeMeta;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadServerCodeMeta.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loadServerCodeMeta/loadServerCodeMeta.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAQ,MAAM,6BAA6B,CAAC;AAKtE,MAAM,WAAW,yBAAyB;CAEzC;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,cAA6B,CAAC;AAE7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,yBAA8B,GAAG,YAAY,CAyC/F"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
-
import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
|
|
6
|
-
import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
|
|
7
|
-
import { getFileNameFromUrl } from "../loaderUtils/index.js";
|
|
8
|
-
/**
|
|
9
|
-
* Default loadServerCodeMeta function that resolves variant paths from demo files.
|
|
10
|
-
* This function is used to load code metadata for demos, specifically resolving paths for variants defined in the demo files.
|
|
11
|
-
* It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
|
|
12
|
-
* It returns a Code object mapping variant names to their resolved file URLs.
|
|
13
|
-
*/
|
|
14
|
-
export var loadServerCodeMeta = createLoadServerCodeMeta();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates a loadCodeMeta function that resolves variant paths from demo files.
|
|
18
|
-
*
|
|
19
|
-
* This factory function creates a LoadCodeMeta implementation that:
|
|
20
|
-
* 1. Parses the demo file to find createDemo calls with variants
|
|
21
|
-
* 2. Resolves all variant entry point paths using resolveVariantPaths
|
|
22
|
-
* 3. Returns a Code object mapping variant names to their resolved file URLs
|
|
23
|
-
*
|
|
24
|
-
* The actual loading, parsing, and transformation of the variants is handled
|
|
25
|
-
* elsewhere by the CodeHighlighter component using loadVariant.
|
|
26
|
-
*
|
|
27
|
-
* @param options - Configuration options (currently unused)
|
|
28
|
-
* @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
|
|
29
|
-
*/
|
|
30
|
-
export function createLoadServerCodeMeta() {
|
|
31
|
-
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
|
-
return /*#__PURE__*/function () {
|
|
33
|
-
var _loadCodeMeta = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
|
34
|
-
var filePath, source, demoCall, code, resolvedVariantMap;
|
|
35
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
|
-
while (1) switch (_context.prev = _context.next) {
|
|
37
|
-
case 0:
|
|
38
|
-
// Remove file:// prefix if present to get file path
|
|
39
|
-
filePath = url.replace('file://', ''); // Read the source file to find createDemo calls
|
|
40
|
-
_context.next = 3;
|
|
41
|
-
return readFile(filePath, 'utf-8');
|
|
42
|
-
case 3:
|
|
43
|
-
source = _context.sent;
|
|
44
|
-
_context.next = 6;
|
|
45
|
-
return parseCreateFactoryCall(source, filePath);
|
|
46
|
-
case 6:
|
|
47
|
-
demoCall = _context.sent;
|
|
48
|
-
if (!(!demoCall || !demoCall.variants)) {
|
|
49
|
-
_context.next = 9;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return _context.abrupt("return", {});
|
|
53
|
-
case 9:
|
|
54
|
-
code = {}; // Resolve all variant paths and get them as file URLs
|
|
55
|
-
_context.next = 12;
|
|
56
|
-
return resolveVariantPathsWithFs(demoCall.variants);
|
|
57
|
-
case 12:
|
|
58
|
-
resolvedVariantMap = _context.sent;
|
|
59
|
-
// Build Code object from the resolved variant map
|
|
60
|
-
Array.from(resolvedVariantMap.entries()).forEach(function (_ref) {
|
|
61
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
62
|
-
variantName = _ref2[0],
|
|
63
|
-
fileUrl = _ref2[1];
|
|
64
|
-
var namedExport = demoCall.namedExports[variantName];
|
|
65
|
-
code[variantName] = fileUrl;
|
|
66
|
-
if (namedExport) {
|
|
67
|
-
var _getFileNameFromUrl = getFileNameFromUrl(fileUrl),
|
|
68
|
-
fileName = _getFileNameFromUrl.fileName;
|
|
69
|
-
if (!fileName) {
|
|
70
|
-
throw new Error("Cannot determine fileName from URL \"".concat(fileUrl, "\" for variant \"").concat(variantName, "\". ") + "Please ensure the URL has a valid file extension.");
|
|
71
|
-
}
|
|
72
|
-
code[variantName] = {
|
|
73
|
-
url: fileUrl,
|
|
74
|
-
fileName: fileName,
|
|
75
|
-
namedExport: namedExport
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
// TODO: will this cause loadVariantMeta not to run? Maybe we should always run it
|
|
79
|
-
});
|
|
80
|
-
return _context.abrupt("return", code);
|
|
81
|
-
case 15:
|
|
82
|
-
case "end":
|
|
83
|
-
return _context.stop();
|
|
84
|
-
}
|
|
85
|
-
}, _callee);
|
|
86
|
-
}));
|
|
87
|
-
function loadCodeMeta(_x) {
|
|
88
|
-
return _loadCodeMeta.apply(this, arguments);
|
|
89
|
-
}
|
|
90
|
-
return loadCodeMeta;
|
|
91
|
-
}();
|
|
92
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./loadServerSource.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loadServerSource/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./loadServerSource.js";
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { LoadSource } from "../../CodeHighlighter/types.js";
|
|
2
|
-
import { type StoreAtMode } from "../loaderUtils/processRelativeImports.js";
|
|
3
|
-
interface LoadSourceOptions {
|
|
4
|
-
maxDepth?: number;
|
|
5
|
-
maxFiles?: number;
|
|
6
|
-
includeDependencies?: boolean;
|
|
7
|
-
storeAt?: StoreAtMode;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Default loadServerSource function that reads a file and extracts its dependencies.
|
|
11
|
-
* This function is used to load source files for demos, resolving their imports and dependencies.
|
|
12
|
-
* It reads the source file, resolves its imports, and returns the processed source along with any
|
|
13
|
-
* additional files and dependencies that were found.
|
|
14
|
-
*/
|
|
15
|
-
export declare const loadServerSource: LoadSource;
|
|
16
|
-
/**
|
|
17
|
-
* Creates a loadSource function that reads a file and extracts its dependencies.
|
|
18
|
-
*
|
|
19
|
-
* @param options.storeAt - Controls how imports are stored in extraFiles:
|
|
20
|
-
* - 'canonical': Full resolved path (e.g., '../Component/index.js')
|
|
21
|
-
* - 'import': Import path with file extension (e.g., '../Component.js')
|
|
22
|
-
* - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
|
|
23
|
-
*/
|
|
24
|
-
export declare function createLoadServerSource(options?: LoadSourceOptions): LoadSource;
|
|
25
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadServerSource.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loadServerSource/loadServerSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,6BAA6B,CAAC;AAGzE,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAGjG,UAAU,iBAAiB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAA2B,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CA8ElF"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
6
|
-
import { parseImports } from "../loaderUtils/index.js";
|
|
7
|
-
import { resolveImportResultWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
|
|
8
|
-
import { processRelativeImports } from "../loaderUtils/processRelativeImports.js";
|
|
9
|
-
import { isJavaScriptModule } from "../loaderUtils/resolveModulePath.js";
|
|
10
|
-
/**
|
|
11
|
-
* Default loadServerSource function that reads a file and extracts its dependencies.
|
|
12
|
-
* This function is used to load source files for demos, resolving their imports and dependencies.
|
|
13
|
-
* It reads the source file, resolves its imports, and returns the processed source along with any
|
|
14
|
-
* additional files and dependencies that were found.
|
|
15
|
-
*/
|
|
16
|
-
export var loadServerSource = createLoadServerSource();
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a loadSource function that reads a file and extracts its dependencies.
|
|
20
|
-
*
|
|
21
|
-
* @param options.storeAt - Controls how imports are stored in extraFiles:
|
|
22
|
-
* - 'canonical': Full resolved path (e.g., '../Component/index.js')
|
|
23
|
-
* - 'import': Import path with file extension (e.g., '../Component.js')
|
|
24
|
-
* - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
|
|
25
|
-
*/
|
|
26
|
-
export function createLoadServerSource() {
|
|
27
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
28
|
-
var _options$includeDepen = options.includeDependencies,
|
|
29
|
-
includeDependencies = _options$includeDepen === void 0 ? true : _options$includeDepen,
|
|
30
|
-
_options$storeAt = options.storeAt,
|
|
31
|
-
storeAt = _options$storeAt === void 0 ? 'flat' : _options$storeAt;
|
|
32
|
-
return /*#__PURE__*/function () {
|
|
33
|
-
var _loadSource = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
|
34
|
-
var filePath, source, isJavascriptModuleFile, _yield$parseImports, importResult, externals, transformedExternals, _i, _Object$entries, _Object$entries$_i, modulePath, externalImport, relativeImportsCompatible, _i2, _Object$entries2, _Object$entries2$_i, importPath, _Object$entries2$_i$, path, names, includeTypeDefs, resolvedPathsMap, _processRelativeImpor, processedSource, extraFiles, extraDependencies;
|
|
35
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
|
-
while (1) switch (_context.prev = _context.next) {
|
|
37
|
-
case 0:
|
|
38
|
-
// Remove file:// prefix if present
|
|
39
|
-
filePath = url.replace('file://', ''); // Read the file
|
|
40
|
-
_context.next = 3;
|
|
41
|
-
return readFile(filePath, 'utf8');
|
|
42
|
-
case 3:
|
|
43
|
-
source = _context.sent;
|
|
44
|
-
if (includeDependencies) {
|
|
45
|
-
_context.next = 6;
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
return _context.abrupt("return", {
|
|
49
|
-
source: source
|
|
50
|
-
});
|
|
51
|
-
case 6:
|
|
52
|
-
// Check if this is a static asset file (non-JS/TS modules)
|
|
53
|
-
isJavascriptModuleFile = isJavaScriptModule(filePath);
|
|
54
|
-
if (isJavascriptModuleFile) {
|
|
55
|
-
_context.next = 9;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
return _context.abrupt("return", {
|
|
59
|
-
source: source
|
|
60
|
-
});
|
|
61
|
-
case 9:
|
|
62
|
-
_context.next = 11;
|
|
63
|
-
return parseImports(source, filePath);
|
|
64
|
-
case 11:
|
|
65
|
-
_yield$parseImports = _context.sent;
|
|
66
|
-
importResult = _yield$parseImports.relative;
|
|
67
|
-
externals = _yield$parseImports.externals;
|
|
68
|
-
// Transform externals from parseImports format to simplified format
|
|
69
|
-
transformedExternals = {};
|
|
70
|
-
for (_i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
|
|
71
|
-
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), modulePath = _Object$entries$_i[0], externalImport = _Object$entries$_i[1];
|
|
72
|
-
transformedExternals[modulePath] = externalImport.names.map(function (importName) {
|
|
73
|
-
return {
|
|
74
|
-
name: importName.name,
|
|
75
|
-
type: importName.type,
|
|
76
|
-
isType: importName.isType
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
if (!(Object.keys(importResult).length === 0)) {
|
|
81
|
-
_context.next = 18;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
return _context.abrupt("return", {
|
|
85
|
-
source: source,
|
|
86
|
-
externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
|
|
87
|
-
});
|
|
88
|
-
case 18:
|
|
89
|
-
// Convert to format expected by resolveImportResultWithFs and processImports
|
|
90
|
-
relativeImportsCompatible = {};
|
|
91
|
-
for (_i2 = 0, _Object$entries2 = Object.entries(importResult); _i2 < _Object$entries2.length; _i2++) {
|
|
92
|
-
_Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), importPath = _Object$entries2$_i[0], _Object$entries2$_i$ = _Object$entries2$_i[1], path = _Object$entries2$_i$.path, names = _Object$entries2$_i$.names, includeTypeDefs = _Object$entries2$_i$.includeTypeDefs;
|
|
93
|
-
relativeImportsCompatible[importPath] = _objectSpread({
|
|
94
|
-
path: path,
|
|
95
|
-
names: names.map(function (_ref) {
|
|
96
|
-
var name = _ref.name,
|
|
97
|
-
alias = _ref.alias;
|
|
98
|
-
return alias || name;
|
|
99
|
-
})
|
|
100
|
-
}, includeTypeDefs && {
|
|
101
|
-
includeTypeDefs: includeTypeDefs
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Resolve import paths, handling JS/TS modules and static assets appropriately
|
|
106
|
-
_context.next = 22;
|
|
107
|
-
return resolveImportResultWithFs(relativeImportsCompatible);
|
|
108
|
-
case 22:
|
|
109
|
-
resolvedPathsMap = _context.sent;
|
|
110
|
-
// Process imports using the consolidated helper function
|
|
111
|
-
_processRelativeImpor = processRelativeImports(source, relativeImportsCompatible, resolvedPathsMap, storeAt), processedSource = _processRelativeImpor.processedSource, extraFiles = _processRelativeImpor.extraFiles; // Build dependencies list for recursive loading
|
|
112
|
-
extraDependencies = Object.values(importResult).map(function (_ref2) {
|
|
113
|
-
var path = _ref2.path;
|
|
114
|
-
return resolvedPathsMap.get(path);
|
|
115
|
-
}).filter(function (path) {
|
|
116
|
-
return path !== undefined;
|
|
117
|
-
});
|
|
118
|
-
return _context.abrupt("return", {
|
|
119
|
-
source: processedSource,
|
|
120
|
-
extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
|
|
121
|
-
extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined,
|
|
122
|
-
externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
|
|
123
|
-
});
|
|
124
|
-
case 26:
|
|
125
|
-
case "end":
|
|
126
|
-
return _context.stop();
|
|
127
|
-
}
|
|
128
|
-
}, _callee);
|
|
129
|
-
}));
|
|
130
|
-
function loadSource(_x) {
|
|
131
|
-
return _loadSource.apply(this, arguments);
|
|
132
|
-
}
|
|
133
|
-
return loadSource;
|
|
134
|
-
}();
|
|
135
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function externalsToPackages(externals: string[]): Record<string, true>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"externalsToPackages.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loaderUtils/externalsToPackages.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAiB7E"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export function externalsToPackages(externals) {
|
|
2
|
-
var packages = {};
|
|
3
|
-
externals.forEach(function (external) {
|
|
4
|
-
// Filter out path aliases that start with @/
|
|
5
|
-
if (external.startsWith('@/')) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Extract package name from import path
|
|
10
|
-
var packageName = extractPackageName(external);
|
|
11
|
-
if (packageName) {
|
|
12
|
-
packages[packageName] = true;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return packages;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extracts the package name from an import path.
|
|
20
|
-
* Examples:
|
|
21
|
-
* - 'react' -> 'react'
|
|
22
|
-
* - 'react-dom' -> 'react-dom'
|
|
23
|
-
* - '@mui/internal-docs-infra/CodeHighlighter' -> '@mui/internal-docs-infra'
|
|
24
|
-
* - '@mui/internal-docs-infra/parseSource' -> '@mui/internal-docs-infra'
|
|
25
|
-
* - 'lodash/get' -> 'lodash'
|
|
26
|
-
* - 'some-package/submodule/deep' -> 'some-package'
|
|
27
|
-
*/
|
|
28
|
-
function extractPackageName(importPath) {
|
|
29
|
-
if (!importPath) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Handle scoped packages (starting with @)
|
|
34
|
-
if (importPath.startsWith('@')) {
|
|
35
|
-
var _parts = importPath.split('/');
|
|
36
|
-
if (_parts.length >= 2) {
|
|
37
|
-
// Return @scope/package-name
|
|
38
|
-
return "".concat(_parts[0], "/").concat(_parts[1]);
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Handle regular packages
|
|
44
|
-
var parts = importPath.split('/');
|
|
45
|
-
return parts[0] || null;
|
|
46
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts and formats a name and slug from a URL path.
|
|
3
|
-
* This utility takes the last meaningful segment of a URL path and formats it
|
|
4
|
-
* into both a human-readable title and a URL-friendly slug.
|
|
5
|
-
*
|
|
6
|
-
* - Strips common file extensions (index.js, index.ts, index.tsx, etc.)
|
|
7
|
-
* - Converts kebab-case to Title Case for names
|
|
8
|
-
* - Ensures slugs are in kebab-case format
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Extracts and formats a name and slug from a URL path
|
|
12
|
-
* @param url - The URL to extract from (can be file:// URL or regular path)
|
|
13
|
-
* @returns Object containing the formatted name and slug
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* extractNameAndSlugFromUrl('file:///app/components/demos/advanced-keyboard/index.ts')
|
|
17
|
-
* // Returns: { name: 'Advanced Keyboard', slug: 'advanced-keyboard' }
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* extractNameAndSlugFromUrl('/src/components/button-group.tsx')
|
|
21
|
-
* // Returns: { name: 'Button Group', slug: 'button-group' }
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* extractNameAndSlugFromUrl('/src/components/customButton.tsx')
|
|
25
|
-
* // Returns: { name: 'Custom Button', slug: 'custom-button' }
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* extractNameAndSlugFromUrl('https://example.com/docs/getting-started/')
|
|
29
|
-
* // Returns: { name: 'Getting Started', slug: 'getting-started' }
|
|
30
|
-
*/
|
|
31
|
-
export declare function extractNameAndSlugFromUrl(url: string): {
|
|
32
|
-
name: string;
|
|
33
|
-
slug: string;
|
|
34
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractNameAndSlugFromUrl.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loaderUtils/extractNameAndSlugFromUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA4HH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAgBrF"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts and formats a name and slug from a URL path.
|
|
3
|
-
* This utility takes the last meaningful segment of a URL path and formats it
|
|
4
|
-
* into both a human-readable title and a URL-friendly slug.
|
|
5
|
-
*
|
|
6
|
-
* - Strips common file extensions (index.js, index.ts, index.tsx, etc.)
|
|
7
|
-
* - Converts kebab-case to Title Case for names
|
|
8
|
-
* - Ensures slugs are in kebab-case format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Converts a camelCase string to kebab-case
|
|
13
|
-
* @param camelCase - The camelCase string to convert
|
|
14
|
-
* @returns kebab-case string
|
|
15
|
-
*/
|
|
16
|
-
function camelToKebabCase(camelCase) {
|
|
17
|
-
return camelCase
|
|
18
|
-
// Insert hyphens before uppercase letters that follow lowercase letters or numbers
|
|
19
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
20
|
-
// Insert hyphens before numbers that follow letters
|
|
21
|
-
.replace(/([a-zA-Z])([0-9])/g, '$1-$2')
|
|
22
|
-
// Insert hyphens before letters that follow numbers
|
|
23
|
-
.replace(/([0-9])([a-zA-Z])/g, '$1-$2').toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Converts a camelCase string to Title Case with spaces
|
|
28
|
-
* @param camelCase - The camelCase string to convert
|
|
29
|
-
* @returns Title case string with spaces
|
|
30
|
-
*/
|
|
31
|
-
function camelToTitleCase(camelCase) {
|
|
32
|
-
return camelCase
|
|
33
|
-
// Insert spaces before uppercase letters that follow lowercase letters or numbers
|
|
34
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
35
|
-
// Insert spaces before numbers that follow letters
|
|
36
|
-
.replace(/([a-zA-Z])([0-9])/g, '$1 $2')
|
|
37
|
-
// Insert spaces before letters that follow numbers
|
|
38
|
-
.replace(/([0-9])([a-zA-Z])/g, '$1 $2')
|
|
39
|
-
// Capitalize the first letter
|
|
40
|
-
.replace(/^./, function (str) {
|
|
41
|
-
return str.toUpperCase();
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Converts a kebab-case string to Title Case
|
|
47
|
-
* @param kebabCase - The kebab-case string to convert
|
|
48
|
-
* @returns Title case string
|
|
49
|
-
*/
|
|
50
|
-
function kebabToTitleCase(kebabCase) {
|
|
51
|
-
return kebabCase.split(/[-_]/) // Split on both hyphens and underscores
|
|
52
|
-
.map(function (word) {
|
|
53
|
-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
54
|
-
}).join(' ');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Detects if a string is camelCase or PascalCase
|
|
59
|
-
* @param str - The string to check
|
|
60
|
-
* @returns true if the string is camelCase or PascalCase
|
|
61
|
-
*/
|
|
62
|
-
function isCamelCase(str) {
|
|
63
|
-
// Check if it matches the camelCase/PascalCase pattern:
|
|
64
|
-
// - Only contains letters and numbers
|
|
65
|
-
// - Has at least one transition from lowercase letter or number to uppercase letter
|
|
66
|
-
// - Doesn't contain hyphens, underscores, or spaces
|
|
67
|
-
return /^[a-zA-Z][a-zA-Z0-9]*$/.test(str) && /[a-z0-9][A-Z]/.test(str);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Converts a string to kebab-case
|
|
72
|
-
* @param str - The string to convert
|
|
73
|
-
* @returns kebab-case string
|
|
74
|
-
*/
|
|
75
|
-
function toKebabCase(str) {
|
|
76
|
-
return str.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Extracts the last meaningful segment from a URL path
|
|
81
|
-
* @param url - The URL to extract from
|
|
82
|
-
* @returns The last meaningful path segment
|
|
83
|
-
*/
|
|
84
|
-
function extractLastSegment(url) {
|
|
85
|
-
// Handle file: URLs by removing the protocol
|
|
86
|
-
var path = url;
|
|
87
|
-
if (url.startsWith('file:')) {
|
|
88
|
-
path = url.replace(/^file:\/\//, '');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Strip query parameters and hash fragments before processing
|
|
92
|
-
path = path.split('?')[0].split('#')[0];
|
|
93
|
-
|
|
94
|
-
// Split the path into segments and filter out empty ones
|
|
95
|
-
var segments = path.split('/').filter(Boolean);
|
|
96
|
-
if (segments.length === 0) {
|
|
97
|
-
throw new Error('Could not extract meaningful segment from URL');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Get the last segment
|
|
101
|
-
var lastSegment = segments[segments.length - 1];
|
|
102
|
-
|
|
103
|
-
// Handle index files - any file that starts with 'index.'
|
|
104
|
-
if (lastSegment.startsWith('index.')) {
|
|
105
|
-
// If it's an index file, use the parent directory name
|
|
106
|
-
if (segments.length < 2) {
|
|
107
|
-
throw new Error('Cannot extract name from index file without parent directory');
|
|
108
|
-
}
|
|
109
|
-
lastSegment = segments[segments.length - 2];
|
|
110
|
-
} else {
|
|
111
|
-
// Strip everything after the first dot from non-index files
|
|
112
|
-
// This handles all extensions: .js, .d.ts, .module.css, .config.dev.js, etc.
|
|
113
|
-
var firstDotIndex = lastSegment.indexOf('.');
|
|
114
|
-
if (firstDotIndex !== -1) {
|
|
115
|
-
lastSegment = lastSegment.substring(0, firstDotIndex);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (!lastSegment) {
|
|
119
|
-
throw new Error('Could not extract meaningful segment from URL');
|
|
120
|
-
}
|
|
121
|
-
return lastSegment;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Extracts and formats a name and slug from a URL path
|
|
126
|
-
* @param url - The URL to extract from (can be file:// URL or regular path)
|
|
127
|
-
* @returns Object containing the formatted name and slug
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* extractNameAndSlugFromUrl('file:///app/components/demos/advanced-keyboard/index.ts')
|
|
131
|
-
* // Returns: { name: 'Advanced Keyboard', slug: 'advanced-keyboard' }
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* extractNameAndSlugFromUrl('/src/components/button-group.tsx')
|
|
135
|
-
* // Returns: { name: 'Button Group', slug: 'button-group' }
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* extractNameAndSlugFromUrl('/src/components/customButton.tsx')
|
|
139
|
-
* // Returns: { name: 'Custom Button', slug: 'custom-button' }
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* extractNameAndSlugFromUrl('https://example.com/docs/getting-started/')
|
|
143
|
-
* // Returns: { name: 'Getting Started', slug: 'getting-started' }
|
|
144
|
-
*/
|
|
145
|
-
export function extractNameAndSlugFromUrl(url) {
|
|
146
|
-
var segment = extractLastSegment(url);
|
|
147
|
-
|
|
148
|
-
// Check if the segment is camelCase and handle it appropriately
|
|
149
|
-
if (isCamelCase(segment)) {
|
|
150
|
-
return {
|
|
151
|
-
name: camelToTitleCase(segment),
|
|
152
|
-
slug: camelToKebabCase(segment)
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// For kebab-case, snake_case, or other formats, use the existing logic
|
|
157
|
-
return {
|
|
158
|
-
name: kebabToTitleCase(segment),
|
|
159
|
-
slug: toKebabCase(segment)
|
|
160
|
-
};
|
|
161
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts the filename and extension from a URL or file path.
|
|
3
|
-
* This function is isomorphic and works in both Node.js and browser environments.
|
|
4
|
-
*
|
|
5
|
-
* @param url - The URL or file path to extract the filename from
|
|
6
|
-
* @returns An object containing the filename and extension
|
|
7
|
-
*/
|
|
8
|
-
export declare function getFileNameFromUrl(url: string): {
|
|
9
|
-
fileName: string;
|
|
10
|
-
extension: string;
|
|
11
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFileNameFromUrl.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loaderUtils/getFileNameFromUrl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAoBvF"}
|