@mui/internal-docs-infra 0.1.1-alpha.1 → 0.1.1-alpha.10
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/CodeControllerContext/CodeControllerContext.d.ts +1 -1
- package/CodeControllerContext/CodeControllerContext.d.ts.map +1 -1
- package/CodeControllerContext/index.d.ts.map +1 -1
- package/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
- package/CodeExternalsContext/CodeExternalsContext.d.ts.map +1 -0
- package/CodeExternalsContext/CodeExternalsContext.js +7 -0
- package/CodeExternalsContext/index.d.ts +1 -0
- package/CodeExternalsContext/index.d.ts.map +1 -0
- package/CodeExternalsContext/index.js +1 -0
- package/CodeHighlighter/CodeHighlighter.d.ts +1 -1
- package/CodeHighlighter/CodeHighlighter.d.ts.map +1 -1
- package/CodeHighlighter/CodeHighlighter.js +235 -86
- package/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -1
- package/CodeHighlighter/CodeHighlighterClient.js +500 -62
- package/CodeHighlighter/CodeHighlighterContext.d.ts +2 -0
- package/CodeHighlighter/CodeHighlighterContext.d.ts.map +1 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts.map +1 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.js +3 -1
- package/CodeHighlighter/applyTransform.d.ts.map +1 -1
- package/CodeHighlighter/codeToFallbackProps.d.ts +2 -2
- package/CodeHighlighter/codeToFallbackProps.d.ts.map +1 -1
- package/CodeHighlighter/codeToFallbackProps.js +8 -5
- package/CodeHighlighter/errors.d.ts.map +1 -1
- package/CodeHighlighter/hasAllVariants.d.ts.map +1 -1
- package/CodeHighlighter/index.d.ts.map +1 -1
- package/CodeHighlighter/loadFallbackCode.d.ts +3 -2
- package/CodeHighlighter/loadFallbackCode.d.ts.map +1 -1
- package/CodeHighlighter/loadFallbackCode.js +325 -161
- package/CodeHighlighter/loadVariant.d.ts +3 -2
- package/CodeHighlighter/loadVariant.d.ts.map +1 -1
- package/CodeHighlighter/loadVariant.js +604 -229
- package/CodeHighlighter/maybeInitialData.d.ts +1 -1
- package/CodeHighlighter/maybeInitialData.d.ts.map +1 -1
- package/CodeHighlighter/parseCode.d.ts.map +1 -1
- package/CodeHighlighter/parseCode.js +14 -2
- package/CodeHighlighter/parseControlledCode.d.ts.map +1 -1
- package/CodeHighlighter/parseControlledCode.js +12 -1
- package/CodeHighlighter/transformCode.d.ts +1 -0
- package/CodeHighlighter/transformCode.d.ts.map +1 -1
- package/CodeHighlighter/transformCode.js +43 -3
- package/CodeHighlighter/transformParsedSource.d.ts.map +1 -1
- package/CodeHighlighter/transformSource.d.ts.map +1 -1
- package/CodeHighlighter/types.d.ts +39 -17
- package/CodeHighlighter/types.d.ts.map +1 -1
- package/CodeProvider/CodeContext.d.ts.map +1 -1
- package/CodeProvider/CodeProvider.d.ts.map +1 -1
- package/CodeProvider/CodeProvider.js +21 -6
- package/CodeProvider/index.d.ts +1 -2
- package/CodeProvider/index.d.ts.map +1 -1
- package/CodeProvider/index.js +1 -2
- package/abstractCreateDemo/abstractCreateDemo.d.ts +35 -0
- package/abstractCreateDemo/abstractCreateDemo.d.ts.map +1 -0
- package/abstractCreateDemo/abstractCreateDemo.js +91 -0
- package/abstractCreateDemo/index.d.ts +1 -0
- package/abstractCreateDemo/index.d.ts.map +1 -0
- package/abstractCreateDemo/index.js +1 -0
- package/createDemoData/createDemoData.d.ts +44 -0
- package/createDemoData/createDemoData.d.ts.map +1 -0
- package/createDemoData/createDemoData.js +75 -0
- package/createDemoData/index.d.ts +1 -0
- package/createDemoData/index.d.ts.map +1 -0
- package/createDemoData/index.js +1 -0
- package/createDemoData/types.d.ts +28 -0
- package/createDemoData/types.d.ts.map +1 -0
- package/createDemoData/types.js +1 -0
- package/package.json +15 -9
- package/pipeline/hastUtils/hastUtils.d.ts.map +1 -0
- package/{hast/hast.js → pipeline/hastUtils/hastUtils.js} +2 -1
- package/pipeline/hastUtils/index.d.ts +1 -0
- package/pipeline/hastUtils/index.d.ts.map +1 -0
- package/pipeline/hastUtils/index.js +1 -0
- package/pipeline/loadPrecomputedCodeHighlighter/emitExternalsProvider.d.ts +54 -0
- package/pipeline/loadPrecomputedCodeHighlighter/emitExternalsProvider.d.ts.map +1 -0
- package/pipeline/loadPrecomputedCodeHighlighter/emitExternalsProvider.js +465 -0
- package/pipeline/loadPrecomputedCodeHighlighter/generateExternalsProvider.d.ts +15 -0
- package/pipeline/loadPrecomputedCodeHighlighter/generateExternalsProvider.d.ts.map +1 -0
- package/pipeline/loadPrecomputedCodeHighlighter/generateExternalsProvider.js +253 -0
- package/pipeline/loadPrecomputedCodeHighlighter/index.d.ts.map +1 -0
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +20 -0
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +1 -0
- package/{loadPrecomputedCodeHighlighter → pipeline/loadPrecomputedCodeHighlighter}/loadPrecomputedCodeHighlighter.js +105 -75
- package/{loadPrecomputedCodeHighlighter → pipeline/loadPrecomputedCodeHighlighter}/parseCreateFactoryCall.d.ts +12 -1
- package/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +1 -0
- package/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +433 -0
- package/{loadPrecomputedCodeHighlighter → pipeline/loadPrecomputedCodeHighlighter}/parseFunctionParameters.d.ts +5 -1
- package/pipeline/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +1 -0
- package/{loadPrecomputedCodeHighlighter → pipeline/loadPrecomputedCodeHighlighter}/parseFunctionParameters.js +1 -1
- package/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +25 -0
- package/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +1 -0
- package/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
- package/pipeline/loadServerCodeMeta/index.d.ts +1 -0
- package/pipeline/loadServerCodeMeta/index.d.ts.map +1 -0
- package/pipeline/loadServerCodeMeta/index.js +1 -0
- package/{loadServerCodeMeta/serverLoadCodeMeta.d.ts → pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts} +4 -4
- package/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts.map +1 -0
- package/{loadServerCodeMeta/serverLoadCodeMeta.js → pipeline/loadServerCodeMeta/loadServerCodeMeta.js} +18 -3
- package/pipeline/loadServerSource/index.d.ts +1 -0
- package/pipeline/loadServerSource/index.d.ts.map +1 -0
- package/pipeline/loadServerSource/index.js +1 -0
- package/{loadServerSource/serverLoadSource.d.ts → pipeline/loadServerSource/loadServerSource.d.ts} +5 -5
- package/pipeline/loadServerSource/loadServerSource.d.ts.map +1 -0
- package/pipeline/loadServerSource/loadServerSource.js +135 -0
- package/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
- package/pipeline/loaderUtils/externalsToPackages.d.ts.map +1 -0
- package/pipeline/loaderUtils/externalsToPackages.js +46 -0
- package/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
- package/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts.map +1 -0
- package/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
- package/pipeline/loaderUtils/getFileNameFromUrl.d.ts.map +1 -0
- package/pipeline/loaderUtils/index.d.ts +7 -0
- package/pipeline/loaderUtils/index.d.ts.map +1 -0
- package/pipeline/loaderUtils/index.js +7 -0
- package/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
- package/pipeline/loaderUtils/mergeExternals.d.ts.map +1 -0
- package/pipeline/loaderUtils/mergeExternals.js +72 -0
- package/pipeline/loaderUtils/parseImports.d.ts +20 -0
- package/pipeline/loaderUtils/parseImports.d.ts.map +1 -0
- package/pipeline/loaderUtils/parseImports.js +307 -0
- package/{loaderUtils/processImports.d.ts → pipeline/loaderUtils/processRelativeImports.d.ts} +2 -2
- package/pipeline/loaderUtils/processRelativeImports.d.ts.map +1 -0
- package/pipeline/loaderUtils/processRelativeImports.js +329 -0
- package/{loaderUtils → pipeline/loaderUtils}/resolveModulePath.d.ts +19 -6
- package/pipeline/loaderUtils/resolveModulePath.d.ts.map +1 -0
- package/pipeline/loaderUtils/resolveModulePath.js +1449 -0
- package/{loaderUtils → pipeline/loaderUtils}/resolveModulePathWithFs.d.ts +6 -3
- package/pipeline/loaderUtils/resolveModulePathWithFs.d.ts.map +1 -0
- package/{loaderUtils → pipeline/loaderUtils}/resolveModulePathWithFs.js +8 -4
- package/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
- package/pipeline/loaderUtils/rewriteImports.d.ts.map +1 -0
- package/pipeline/loaderUtils/rewriteImports.js +35 -0
- package/pipeline/parseSource/grammars.d.ts.map +1 -0
- package/pipeline/parseSource/index.d.ts.map +1 -0
- package/pipeline/parseSource/parseSource.d.ts +3 -0
- package/pipeline/parseSource/parseSource.d.ts.map +1 -0
- package/{parseSource → pipeline/parseSource}/parseSource.js +15 -5
- package/pipeline/transformHtmlCode/index.d.ts +2 -0
- package/pipeline/transformHtmlCode/index.d.ts.map +1 -0
- package/pipeline/transformHtmlCode/index.js +4 -0
- package/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
- package/pipeline/transformHtmlCode/transformHtmlCode.d.ts.map +1 -0
- package/pipeline/transformHtmlCode/transformHtmlCode.js +303 -0
- package/pipeline/transformMarkdownCode/index.d.ts +2 -0
- package/pipeline/transformMarkdownCode/index.d.ts.map +1 -0
- package/pipeline/transformMarkdownCode/index.js +4 -0
- package/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
- package/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts.map +1 -0
- package/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
- package/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
- package/pipeline/transformTypescriptToJavascript/index.d.ts.map +1 -0
- package/pipeline/transformTypescriptToJavascript/index.js +1 -0
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.ts.map +1 -0
- package/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
- package/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts.map +1 -0
- package/{transformTsToJs/transformTsToJs.js → pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js} +4 -4
- package/useCode/index.d.ts.map +1 -1
- package/useCode/useCode.d.ts +13 -11
- package/useCode/useCode.d.ts.map +1 -1
- package/useCode/useCode.js +93 -364
- package/useCode/useCodeUtils.d.ts +45 -0
- package/useCode/useCodeUtils.d.ts.map +1 -0
- package/useCode/useCodeUtils.js +240 -0
- package/useCode/useCopyFunctionality.d.ts +17 -0
- package/useCode/useCopyFunctionality.d.ts.map +1 -0
- package/useCode/useCopyFunctionality.js +28 -0
- package/useCode/useFileNavigation.d.ts +48 -0
- package/useCode/useFileNavigation.d.ts.map +1 -0
- package/useCode/useFileNavigation.js +370 -0
- package/useCode/useSourceEditing.d.ts +19 -0
- package/useCode/useSourceEditing.d.ts.map +1 -0
- package/useCode/useSourceEditing.js +32 -0
- package/useCode/useTransformManagement.d.ts +28 -0
- package/useCode/useTransformManagement.d.ts.map +1 -0
- package/useCode/useTransformManagement.js +82 -0
- package/useCode/useUIState.d.ts +16 -0
- package/useCode/useUIState.d.ts.map +1 -0
- package/useCode/useUIState.js +21 -0
- package/useCode/useVariantSelection.d.ts +21 -0
- package/useCode/useVariantSelection.d.ts.map +1 -0
- package/useCode/useVariantSelection.js +84 -0
- package/useCopier/index.d.ts +1 -1
- package/useCopier/index.d.ts.map +1 -1
- package/useCopier/index.js +5 -5
- package/useDemo/createCodeSandbox.d.ts +18 -0
- package/useDemo/createCodeSandbox.d.ts.map +1 -0
- package/useDemo/createCodeSandbox.js +48 -0
- package/useDemo/createStackBlitz.d.ts +22 -0
- package/useDemo/createStackBlitz.d.ts.map +1 -0
- package/useDemo/createStackBlitz.js +38 -0
- package/useDemo/examineVariant.d.ts +25 -0
- package/useDemo/examineVariant.d.ts.map +1 -0
- package/useDemo/examineVariant.js +134 -0
- package/useDemo/exportVariant.d.ts +110 -0
- package/useDemo/exportVariant.d.ts.map +1 -0
- package/useDemo/exportVariant.js +320 -0
- package/useDemo/exportVariantAsCra.d.ts +15 -0
- package/useDemo/exportVariantAsCra.d.ts.map +1 -0
- package/useDemo/exportVariantAsCra.js +56 -0
- package/useDemo/flattenVariant.d.ts +17 -0
- package/useDemo/flattenVariant.d.ts.map +1 -0
- package/useDemo/flattenVariant.js +206 -0
- package/useDemo/index.d.ts +6 -39
- package/useDemo/index.d.ts.map +1 -1
- package/useDemo/index.js +6 -17
- package/useDemo/useDemo.d.ts +78 -0
- package/useDemo/useDemo.d.ts.map +1 -0
- package/useDemo/useDemo.js +174 -0
- package/useLocalStorageState/index.d.ts +2 -0
- package/useLocalStorageState/index.d.ts.map +1 -0
- package/useLocalStorageState/index.js +2 -0
- package/useLocalStorageState/useLocalStorageState.d.ts +14 -0
- package/useLocalStorageState/useLocalStorageState.d.ts.map +1 -0
- package/useLocalStorageState/useLocalStorageState.js +128 -0
- package/useOnHydrate/index.d.ts.map +1 -1
- package/useOnHydrate/useOnHydrate.d.ts.map +1 -1
- package/useOnIdle/index.d.ts.map +1 -1
- package/useOnIdle/useOnIdle.d.ts.map +1 -1
- package/useUrlHashState/index.d.ts +1 -0
- package/useUrlHashState/index.d.ts.map +1 -0
- package/useUrlHashState/index.js +1 -0
- package/useUrlHashState/useUrlHashState.d.ts +50 -0
- package/useUrlHashState/useUrlHashState.d.ts.map +1 -0
- package/useUrlHashState/useUrlHashState.js +113 -0
- package/hast/hast.d.ts.map +0 -1
- package/hast/index.d.ts +0 -1
- package/hast/index.d.ts.map +0 -1
- package/hast/index.js +0 -1
- package/loadPrecomputedCodeHighlighter/index.d.ts.map +0 -1
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +0 -57
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +0 -1
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +0 -1
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +0 -243
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +0 -1
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +0 -27
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +0 -1
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +0 -37
- package/loadServerCodeMeta/index.d.ts +0 -1
- package/loadServerCodeMeta/index.d.ts.map +0 -1
- package/loadServerCodeMeta/index.js +0 -1
- package/loadServerCodeMeta/serverLoadCodeMeta.d.ts.map +0 -1
- package/loadServerSource/index.d.ts +0 -1
- package/loadServerSource/index.d.ts.map +0 -1
- package/loadServerSource/index.js +0 -1
- package/loadServerSource/serverLoadSource.d.ts.map +0 -1
- package/loadServerSource/serverLoadSource.js +0 -100
- package/loaderUtils/getFileNameFromUrl.d.ts.map +0 -1
- package/loaderUtils/index.d.ts +0 -5
- package/loaderUtils/index.d.ts.map +0 -1
- package/loaderUtils/index.js +0 -5
- package/loaderUtils/processImports.d.ts.map +0 -1
- package/loaderUtils/processImports.js +0 -82
- package/loaderUtils/resolveImports.d.ts +0 -4
- package/loaderUtils/resolveImports.d.ts.map +0 -1
- package/loaderUtils/resolveImports.js +0 -71
- package/loaderUtils/resolveModulePath.d.ts.map +0 -1
- package/loaderUtils/resolveModulePath.js +0 -862
- package/loaderUtils/resolveModulePathWithFs.d.ts.map +0 -1
- package/loaderUtils/rewriteImports.d.ts +0 -9
- package/loaderUtils/rewriteImports.d.ts.map +0 -1
- package/loaderUtils/rewriteImports.js +0 -57
- package/parseSource/grammars.d.ts.map +0 -1
- package/parseSource/index.d.ts.map +0 -1
- package/parseSource/parseSource.d.ts +0 -3
- package/parseSource/parseSource.d.ts.map +0 -1
- package/transformRelativeMarkdownPaths/index.d.ts +0 -2
- package/transformRelativeMarkdownPaths/index.d.ts.map +0 -1
- package/transformRelativeMarkdownPaths/index.js +0 -4
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts +0 -12
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts.map +0 -1
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.js +0 -30
- package/transformTsToJs/index.d.ts +0 -1
- package/transformTsToJs/index.d.ts.map +0 -1
- package/transformTsToJs/index.js +0 -1
- package/transformTsToJs/removeTypes.d.ts.map +0 -1
- package/transformTsToJs/transformTsToJs.d.ts +0 -3
- package/transformTsToJs/transformTsToJs.d.ts.map +0 -1
- /package/{hast/hast.d.ts → pipeline/hastUtils/hastUtils.d.ts} +0 -0
- /package/{loadPrecomputedCodeHighlighter → pipeline/loadPrecomputedCodeHighlighter}/index.d.ts +0 -0
- /package/{loadPrecomputedCodeHighlighter → pipeline/loadPrecomputedCodeHighlighter}/index.js +0 -0
- /package/{loaderUtils → pipeline/loaderUtils}/getFileNameFromUrl.d.ts +0 -0
- /package/{loaderUtils → pipeline/loaderUtils}/getFileNameFromUrl.js +0 -0
- /package/{parseSource → pipeline/parseSource}/grammars.d.ts +0 -0
- /package/{parseSource → pipeline/parseSource}/grammars.js +0 -0
- /package/{parseSource → pipeline/parseSource}/index.d.ts +0 -0
- /package/{parseSource → pipeline/parseSource}/index.js +0 -0
- /package/{transformTsToJs → pipeline/transformTypescriptToJavascript}/removeTypes.d.ts +0 -0
- /package/{transformTsToJs → pipeline/transformTypescriptToJavascript}/removeTypes.js +0 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
/**
|
|
4
|
+
* Export variant functionality to add extra files like package.json, tsconfig, etc.
|
|
5
|
+
* Users can pass configuration options that vary the output here.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { externalsToPackages } from "../pipeline/loaderUtils/index.js";
|
|
9
|
+
import { getFileNameFromUrl } from "../pipeline/loaderUtils/getFileNameFromUrl.js";
|
|
10
|
+
import { createPathContext } from "./examineVariant.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Extract filename from URL or return undefined if not available
|
|
14
|
+
*/
|
|
15
|
+
export function getFilenameFromVariant(variantCode) {
|
|
16
|
+
if (variantCode.fileName) {
|
|
17
|
+
return variantCode.fileName;
|
|
18
|
+
}
|
|
19
|
+
if (variantCode.url) {
|
|
20
|
+
var _getFileNameFromUrl = getFileNameFromUrl(variantCode.url),
|
|
21
|
+
fileName = _getFileNameFromUrl.fileName;
|
|
22
|
+
return fileName || undefined;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generate a unique entrypoint filename that doesn't conflict with existing files
|
|
29
|
+
*/
|
|
30
|
+
export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript) {
|
|
31
|
+
var pathPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
32
|
+
var ext = useTypescript ? 'tsx' : 'jsx';
|
|
33
|
+
var candidates = ["".concat(pathPrefix, "index.").concat(ext), "".concat(pathPrefix, "entrypoint.").concat(ext), "".concat(pathPrefix, "main.").concat(ext)];
|
|
34
|
+
|
|
35
|
+
// If we have a source filename, also try variations
|
|
36
|
+
if (sourceFilename) {
|
|
37
|
+
var baseName = sourceFilename.replace(/\.[^.]*$/, '');
|
|
38
|
+
candidates.push("".concat(pathPrefix).concat(baseName, "-entry.").concat(ext));
|
|
39
|
+
}
|
|
40
|
+
for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
|
|
41
|
+
var candidate = _candidates[_i];
|
|
42
|
+
if (candidate !== "".concat(pathPrefix).concat(sourceFilename) && !existingFiles[candidate]) {
|
|
43
|
+
return candidate;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Generate with hash if all candidates are taken
|
|
48
|
+
var hash = Math.random().toString(36).substring(2, 8);
|
|
49
|
+
return "".concat(pathPrefix, "entrypoint-").concat(hash, ".").concat(ext);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generate the relative import path from entrypoint to source file
|
|
54
|
+
*/
|
|
55
|
+
export function getRelativeImportPath(sourceFilename) {
|
|
56
|
+
if (!sourceFilename) {
|
|
57
|
+
return './App'; // Default fallback
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Remove extension for import
|
|
61
|
+
var baseName = sourceFilename.replace(/\.[^.]*$/, '');
|
|
62
|
+
return "./".concat(baseName);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Default HTML template function for Vite-based demos
|
|
67
|
+
*/
|
|
68
|
+
export function defaultHtmlTemplate(_ref) {
|
|
69
|
+
var language = _ref.language,
|
|
70
|
+
title = _ref.title,
|
|
71
|
+
description = _ref.description,
|
|
72
|
+
head = _ref.head,
|
|
73
|
+
entrypoint = _ref.entrypoint;
|
|
74
|
+
return "<!doctype html>\n<html lang=\"".concat(language, "\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>").concat(title, "</title>\n <meta name=\"description\" content=\"").concat(description, "\" />").concat(head ? "\n ".concat(head) : '', "\n </head>\n <body>\n <div id=\"root\"></div>").concat(entrypoint ? "\n <script type=\"module\" src=\"".concat(entrypoint, "\"></script>") : '', "\n </body>\n</html>");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Export a VariantCode with additional configuration files
|
|
78
|
+
* Returns an object with the exported VariantCode and rootPath path
|
|
79
|
+
*/
|
|
80
|
+
export function exportVariant(variantCode) {
|
|
81
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
82
|
+
var _config$title = config.title,
|
|
83
|
+
title = _config$title === void 0 ? 'Demo' : _config$title,
|
|
84
|
+
_config$description = config.description,
|
|
85
|
+
description = _config$description === void 0 ? 'Demo created with Vite' : _config$description,
|
|
86
|
+
_config$htmlPrefix = config.htmlPrefix,
|
|
87
|
+
htmlPrefix = _config$htmlPrefix === void 0 ? '' : _config$htmlPrefix,
|
|
88
|
+
_config$frameworkHand = config.frameworkHandlesEntrypoint,
|
|
89
|
+
frameworkHandlesEntrypoint = _config$frameworkHand === void 0 ? false : _config$frameworkHand,
|
|
90
|
+
htmlTemplate = config.htmlTemplate,
|
|
91
|
+
headTemplate = config.headTemplate,
|
|
92
|
+
rootIndexTemplate = config.rootIndexTemplate,
|
|
93
|
+
_config$dependencies = config.dependencies,
|
|
94
|
+
dependencies = _config$dependencies === void 0 ? {} : _config$dependencies,
|
|
95
|
+
_config$devDependenci = config.devDependencies,
|
|
96
|
+
devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
|
|
97
|
+
_config$scripts = config.scripts,
|
|
98
|
+
scripts = _config$scripts === void 0 ? {} : _config$scripts,
|
|
99
|
+
packageType = config.packageType,
|
|
100
|
+
_config$packageJsonFi = config.packageJsonFields,
|
|
101
|
+
packageJsonFields = _config$packageJsonFi === void 0 ? {} : _config$packageJsonFi,
|
|
102
|
+
_config$tsconfigOptio = config.tsconfigOptions,
|
|
103
|
+
tsconfigOptions = _config$tsconfigOptio === void 0 ? {} : _config$tsconfigOptio,
|
|
104
|
+
_config$useTypescript = config.useTypescript,
|
|
105
|
+
useTypescript = _config$useTypescript === void 0 ? false : _config$useTypescript,
|
|
106
|
+
_config$extraMetadata = config.extraMetadataFiles,
|
|
107
|
+
extraMetadataFiles = _config$extraMetadata === void 0 ? {} : _config$extraMetadata,
|
|
108
|
+
_config$frameworkFile = config.frameworkFiles,
|
|
109
|
+
frameworkFiles = _config$frameworkFile === void 0 ? {} : _config$frameworkFile;
|
|
110
|
+
|
|
111
|
+
// If packageType is explicitly provided (even as undefined), use that value
|
|
112
|
+
var finalPackageType;
|
|
113
|
+
if ('packageType' in config) {
|
|
114
|
+
finalPackageType = packageType;
|
|
115
|
+
} else {
|
|
116
|
+
finalPackageType = !Object.keys(frameworkFiles).length ? 'module' : undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Get existing extraFiles and source filename
|
|
120
|
+
var existingExtraFiles = variantCode.extraFiles || {};
|
|
121
|
+
var sourceFilename = getFilenameFromVariant(variantCode);
|
|
122
|
+
|
|
123
|
+
// Get path context to calculate proper URLs
|
|
124
|
+
var pathContext = createPathContext(variantCode);
|
|
125
|
+
|
|
126
|
+
// Calculate the correct prefix for metadata files based on path depth
|
|
127
|
+
var metadataPrefix = '../'.repeat(pathContext.maxBackNavigation + 1);
|
|
128
|
+
|
|
129
|
+
// Generate unique entrypoint filename
|
|
130
|
+
var entrypointFilename = generateEntrypointFilename(existingExtraFiles, sourceFilename, useTypescript);
|
|
131
|
+
|
|
132
|
+
// Calculate the entrypoint URL relative to the root
|
|
133
|
+
var entrypoint = "/src/".concat(pathContext.pathInwardFromRoot).concat(entrypointFilename);
|
|
134
|
+
|
|
135
|
+
// Get relative import path for the main component
|
|
136
|
+
var rootFile = "src/".concat(pathContext.pathInwardFromRoot).concat(sourceFilename);
|
|
137
|
+
var importPath = getRelativeImportPath(sourceFilename);
|
|
138
|
+
var importString = variantCode.namedExport ? "import { ".concat(variantCode.namedExport, " as App } from '").concat(importPath, "';") : "import App from '".concat(importPath, "';");
|
|
139
|
+
|
|
140
|
+
// Create new extraFiles object
|
|
141
|
+
var newExtraFiles = _objectSpread({}, existingExtraFiles);
|
|
142
|
+
|
|
143
|
+
// Add framework-specific files (if any)
|
|
144
|
+
for (var _i2 = 0, _Object$entries = Object.entries(frameworkFiles); _i2 < _Object$entries.length; _i2++) {
|
|
145
|
+
var _fileData$metadata;
|
|
146
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
|
147
|
+
fileName = _Object$entries$_i[0],
|
|
148
|
+
fileData = _Object$entries$_i[1];
|
|
149
|
+
newExtraFiles[fileName] = {
|
|
150
|
+
source: fileData.source,
|
|
151
|
+
metadata: (_fileData$metadata = fileData.metadata) != null ? _fileData$metadata : true
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Check if we're using a framework (has framework files)
|
|
156
|
+
var isFramework = frameworkFiles && Object.keys(frameworkFiles).length > 0;
|
|
157
|
+
var externalPackages = externalsToPackages(variantCode.externals || []);
|
|
158
|
+
var variantDeps = Object.keys(externalPackages).reduce(function (acc, pkg) {
|
|
159
|
+
acc[pkg] = 'latest';
|
|
160
|
+
return acc;
|
|
161
|
+
}, {});
|
|
162
|
+
|
|
163
|
+
// Generate package.json (always)
|
|
164
|
+
var packageJson = _objectSpread(_objectSpread({
|
|
165
|
+
"private": true,
|
|
166
|
+
name: title.toLowerCase().replace(/[^a-z0-9]/g, '-'),
|
|
167
|
+
version: '0.0.0',
|
|
168
|
+
description: description
|
|
169
|
+
}, finalPackageType && {
|
|
170
|
+
type: finalPackageType
|
|
171
|
+
}), {}, {
|
|
172
|
+
// Add type if specified
|
|
173
|
+
scripts: _objectSpread(_objectSpread({}, !isFramework && {
|
|
174
|
+
dev: 'vite',
|
|
175
|
+
build: 'vite build',
|
|
176
|
+
preview: 'vite preview'
|
|
177
|
+
}), scripts),
|
|
178
|
+
dependencies: _objectSpread(_objectSpread({
|
|
179
|
+
react: 'latest',
|
|
180
|
+
'react-dom': 'latest'
|
|
181
|
+
}, variantDeps), dependencies),
|
|
182
|
+
devDependencies: _objectSpread(_objectSpread(_objectSpread({}, !isFramework && {
|
|
183
|
+
'@vitejs/plugin-react': 'latest',
|
|
184
|
+
vite: 'latest'
|
|
185
|
+
}), useTypescript && {
|
|
186
|
+
typescript: 'latest',
|
|
187
|
+
'@types/react': 'latest',
|
|
188
|
+
'@types/react-dom': 'latest'
|
|
189
|
+
}), devDependencies)
|
|
190
|
+
}, packageJsonFields);
|
|
191
|
+
newExtraFiles["".concat(metadataPrefix, "package.json")] = {
|
|
192
|
+
source: JSON.stringify(packageJson, null, 2),
|
|
193
|
+
metadata: true
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Generate entrypoint and HTML files unless framework handles them
|
|
197
|
+
if (!frameworkHandlesEntrypoint) {
|
|
198
|
+
// Add index.html (with configurable prefix for different frameworks)
|
|
199
|
+
var headContent = headTemplate ? headTemplate({
|
|
200
|
+
sourcePrefix: '/src',
|
|
201
|
+
assetPrefix: ''
|
|
202
|
+
}) : undefined;
|
|
203
|
+
var htmlContent = htmlTemplate ? htmlTemplate({
|
|
204
|
+
language: 'en',
|
|
205
|
+
title: title,
|
|
206
|
+
description: description,
|
|
207
|
+
head: headContent,
|
|
208
|
+
entrypoint: entrypoint
|
|
209
|
+
}) : defaultHtmlTemplate({
|
|
210
|
+
language: 'en',
|
|
211
|
+
title: title,
|
|
212
|
+
description: description,
|
|
213
|
+
head: headContent,
|
|
214
|
+
entrypoint: entrypoint
|
|
215
|
+
});
|
|
216
|
+
var htmlFilePath = htmlPrefix ? "".concat(metadataPrefix).concat(htmlPrefix, "index.html") : "".concat(metadataPrefix, "index.html");
|
|
217
|
+
newExtraFiles[htmlFilePath] = {
|
|
218
|
+
source: htmlContent,
|
|
219
|
+
metadata: true
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// Create entrypoint file that imports the main component
|
|
223
|
+
var defaultEntrypointContent = "import * as React from 'react';\nimport * as ReactDOM from 'react-dom/client';\n".concat(importString, "\n\nReactDOM.createRoot(document.getElementById('root')").concat(useTypescript ? '!' : '', ").render(\n <React.StrictMode>\n <App />\n </React.StrictMode>\n);");
|
|
224
|
+
var entrypointContent = rootIndexTemplate ? rootIndexTemplate({
|
|
225
|
+
importString: importString,
|
|
226
|
+
useTypescript: useTypescript
|
|
227
|
+
}) : defaultEntrypointContent;
|
|
228
|
+
newExtraFiles[entrypointFilename] = {
|
|
229
|
+
source: entrypointContent,
|
|
230
|
+
metadata: false
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Add Vite config file only if no framework files (Vite-specific)
|
|
235
|
+
if (!isFramework) {
|
|
236
|
+
var viteConfigContent = "import { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\nimport { externalsToPackages } from '../loaderUtils/externalsToPackages';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [react()],\n define: { 'process.env': {} },\n});";
|
|
237
|
+
newExtraFiles["".concat(metadataPrefix, "vite.config.").concat(useTypescript ? 'ts' : 'js')] = {
|
|
238
|
+
source: viteConfigContent,
|
|
239
|
+
metadata: true
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Add TypeScript configuration if requested (up one directory, metadata: true)
|
|
244
|
+
if (useTypescript) {
|
|
245
|
+
// Check if frameworkFiles already includes a tsconfig
|
|
246
|
+
var hasFrameworkTsConfig = frameworkFiles && Object.keys(frameworkFiles).some(function (fileName) {
|
|
247
|
+
return fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json');
|
|
248
|
+
});
|
|
249
|
+
if (!hasFrameworkTsConfig) {
|
|
250
|
+
// Main tsconfig.json (default Vite config)
|
|
251
|
+
var defaultTsConfig = _objectSpread({
|
|
252
|
+
compilerOptions: _objectSpread({
|
|
253
|
+
target: 'ES2020',
|
|
254
|
+
useDefineForClassFields: true,
|
|
255
|
+
lib: ['ES2020', 'DOM', 'DOM.Iterable'],
|
|
256
|
+
module: 'ESNext',
|
|
257
|
+
skipLibCheck: true,
|
|
258
|
+
moduleResolution: 'bundler',
|
|
259
|
+
allowImportingTsExtensions: true,
|
|
260
|
+
resolveJsonModule: true,
|
|
261
|
+
isolatedModules: true,
|
|
262
|
+
noEmit: true,
|
|
263
|
+
jsx: 'react-jsx',
|
|
264
|
+
strict: true,
|
|
265
|
+
noUnusedLocals: true,
|
|
266
|
+
noUnusedParameters: true,
|
|
267
|
+
noFallthroughCasesInSwitch: true
|
|
268
|
+
}, tsconfigOptions),
|
|
269
|
+
include: ['src']
|
|
270
|
+
}, !isFramework && {
|
|
271
|
+
references: [{
|
|
272
|
+
path: './tsconfig.node.json'
|
|
273
|
+
}]
|
|
274
|
+
});
|
|
275
|
+
newExtraFiles["".concat(metadataPrefix, "tsconfig.json")] = {
|
|
276
|
+
source: JSON.stringify(defaultTsConfig, null, 2),
|
|
277
|
+
metadata: true
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Only add tsconfig.node.json for Vite (not for framework files)
|
|
282
|
+
if (!isFramework) {
|
|
283
|
+
// Node tsconfig for Vite config
|
|
284
|
+
var nodeTsConfig = {
|
|
285
|
+
compilerOptions: {
|
|
286
|
+
composite: true,
|
|
287
|
+
skipLibCheck: true,
|
|
288
|
+
module: 'ESNext',
|
|
289
|
+
moduleResolution: 'bundler',
|
|
290
|
+
allowSyntheticDefaultImports: true
|
|
291
|
+
},
|
|
292
|
+
include: ['vite.config.ts']
|
|
293
|
+
};
|
|
294
|
+
newExtraFiles["".concat(metadataPrefix, "tsconfig.node.json")] = {
|
|
295
|
+
source: JSON.stringify(nodeTsConfig, null, 2),
|
|
296
|
+
metadata: true
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Add custom metadata files (respect metadata flag)
|
|
302
|
+
for (var _i3 = 0, _Object$entries2 = Object.entries(extraMetadataFiles); _i3 < _Object$entries2.length; _i3++) {
|
|
303
|
+
var _fileData$metadata2;
|
|
304
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i3], 2),
|
|
305
|
+
_fileName = _Object$entries2$_i[0],
|
|
306
|
+
_fileData = _Object$entries2$_i[1];
|
|
307
|
+
newExtraFiles["".concat(metadataPrefix).concat(_fileName)] = {
|
|
308
|
+
source: _fileData.source,
|
|
309
|
+
metadata: (_fileData$metadata2 = _fileData.metadata) != null ? _fileData$metadata2 : true
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Return new VariantCode with updated extraFiles
|
|
314
|
+
return {
|
|
315
|
+
exported: _objectSpread(_objectSpread({}, variantCode), {}, {
|
|
316
|
+
extraFiles: newExtraFiles
|
|
317
|
+
}),
|
|
318
|
+
rootFile: rootFile
|
|
319
|
+
};
|
|
320
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export VariantCode as Create React App template using exportVariant
|
|
3
|
+
* This is a general-purpose wrapper that creates CRA-compatible templates
|
|
4
|
+
* without library-specific dependencies
|
|
5
|
+
*/
|
|
6
|
+
import type { VariantCode } from "../CodeHighlighter/types.js";
|
|
7
|
+
import { type ExportConfig } from "./exportVariant.js";
|
|
8
|
+
/**
|
|
9
|
+
* Export a VariantCode as a Create React App template
|
|
10
|
+
* Returns an object with the exported VariantCode and entrypoint path
|
|
11
|
+
*/
|
|
12
|
+
export declare function exportVariantAsCra(variantCode: VariantCode, config?: ExportConfig): {
|
|
13
|
+
exported: VariantCode;
|
|
14
|
+
rootFile: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exportVariantAsCra.d.ts","sourceRoot":"","sources":["../../src/useDemo/exportVariantAsCra.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,YAAiB,GACxB;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAsC7C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["title", "description", "scripts", "devDependencies"];
|
|
4
|
+
/**
|
|
5
|
+
* Export VariantCode as Create React App template using exportVariant
|
|
6
|
+
* This is a general-purpose wrapper that creates CRA-compatible templates
|
|
7
|
+
* without library-specific dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { exportVariant } from "./exportVariant.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Export a VariantCode as a Create React App template
|
|
14
|
+
* Returns an object with the exported VariantCode and entrypoint path
|
|
15
|
+
*/
|
|
16
|
+
export function exportVariantAsCra(variantCode) {
|
|
17
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
|
+
var _config$title = config.title,
|
|
19
|
+
title = _config$title === void 0 ? 'Demo' : _config$title,
|
|
20
|
+
_config$description = config.description,
|
|
21
|
+
description = _config$description === void 0 ? 'Demo created with Create React App' : _config$description,
|
|
22
|
+
_config$scripts = config.scripts,
|
|
23
|
+
scripts = _config$scripts === void 0 ? {} : _config$scripts,
|
|
24
|
+
_config$devDependenci = config.devDependencies,
|
|
25
|
+
devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
|
|
26
|
+
otherConfig = _objectWithoutProperties(config, _excluded);
|
|
27
|
+
|
|
28
|
+
// Default CRA scripts
|
|
29
|
+
var craScripts = _objectSpread({
|
|
30
|
+
start: 'react-scripts start',
|
|
31
|
+
build: 'react-scripts build',
|
|
32
|
+
test: 'react-scripts test',
|
|
33
|
+
eject: 'react-scripts eject'
|
|
34
|
+
}, scripts);
|
|
35
|
+
|
|
36
|
+
// CRA only needs react-scripts, other deps are handled by exportVariant
|
|
37
|
+
var craDevDependencies = _objectSpread({
|
|
38
|
+
'react-scripts': 'latest'
|
|
39
|
+
}, devDependencies);
|
|
40
|
+
|
|
41
|
+
// Create export configuration for CRA
|
|
42
|
+
var exportConfig = _objectSpread({
|
|
43
|
+
title: title,
|
|
44
|
+
description: description,
|
|
45
|
+
htmlPrefix: 'public/',
|
|
46
|
+
packageType: undefined,
|
|
47
|
+
// CRA should not have 'type: module'
|
|
48
|
+
frameworkFiles: {},
|
|
49
|
+
// Prevent Vite-specific files from being generated
|
|
50
|
+
devDependencies: craDevDependencies,
|
|
51
|
+
scripts: craScripts
|
|
52
|
+
}, otherConfig);
|
|
53
|
+
|
|
54
|
+
// Use exportVariant to generate the final result
|
|
55
|
+
return exportVariant(variantCode, exportConfig);
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flatten variant utility to convert a VariantCode into a flat files list
|
|
3
|
+
* Handles relative path resolution and metadata file scoping
|
|
4
|
+
*/
|
|
5
|
+
import type { VariantCode } from "../CodeHighlighter/types.js";
|
|
6
|
+
export interface FlatFile {
|
|
7
|
+
source: string;
|
|
8
|
+
metadata?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface FlattenedFiles {
|
|
11
|
+
[filePath: string]: FlatFile;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Flatten a VariantCode into a flat files structure
|
|
15
|
+
* Resolves relative paths and handles metadata file scoping
|
|
16
|
+
*/
|
|
17
|
+
export declare function flattenVariant(variant: VariantCode): FlattenedFiles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenVariant.d.ts","sourceRoot":"","sources":["../../src/useDemo/flattenVariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAK3E,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC9B;AAiLD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CA+BnE"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
|
+
/**
|
|
5
|
+
* Flatten variant utility to convert a VariantCode into a flat files list
|
|
6
|
+
* Handles relative path resolution and metadata file scoping
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { stringOrHastToString } from "../pipeline/hastUtils/index.js";
|
|
10
|
+
import { getFileNameFromUrl } from "../pipeline/loaderUtils/getFileNameFromUrl.js";
|
|
11
|
+
import { createPathContext } from "./examineVariant.js";
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a relative path from a base URL to get the target directory structure
|
|
14
|
+
*/
|
|
15
|
+
function resolveRelativePath(baseUrl, relativePath) {
|
|
16
|
+
var url = new URL(baseUrl);
|
|
17
|
+
var pathSegments = url.pathname.split('/').filter(Boolean);
|
|
18
|
+
pathSegments.pop(); // Remove filename to get directory
|
|
19
|
+
|
|
20
|
+
var relativeSegments = relativePath.split('/');
|
|
21
|
+
var _iterator = _createForOfIteratorHelper(relativeSegments),
|
|
22
|
+
_step;
|
|
23
|
+
try {
|
|
24
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
25
|
+
var segment = _step.value;
|
|
26
|
+
if (segment === '..') {
|
|
27
|
+
pathSegments.pop();
|
|
28
|
+
} else if (segment !== '.' && segment !== '') {
|
|
29
|
+
pathSegments.push(segment);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
} catch (err) {
|
|
33
|
+
_iterator.e(err);
|
|
34
|
+
} finally {
|
|
35
|
+
_iterator.f();
|
|
36
|
+
}
|
|
37
|
+
return pathSegments.join('/');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Process the main file and determine its final path
|
|
42
|
+
*/
|
|
43
|
+
function processMainFile(variant, context) {
|
|
44
|
+
var effectiveFileName = variant.fileName;
|
|
45
|
+
|
|
46
|
+
// If fileName is missing but we have a URL, derive it from the URL
|
|
47
|
+
if (!effectiveFileName && context.hasUrl) {
|
|
48
|
+
var _getFileNameFromUrl = getFileNameFromUrl(context.actualUrl),
|
|
49
|
+
fileName = _getFileNameFromUrl.fileName;
|
|
50
|
+
effectiveFileName = fileName;
|
|
51
|
+
}
|
|
52
|
+
if (!effectiveFileName || variant.source === undefined) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
var mainFilePath;
|
|
56
|
+
if (context.hasUrl && context.maxBackNavigation > 0) {
|
|
57
|
+
// URL with back navigation - calculate relative path from root level
|
|
58
|
+
// TypeScript knows context.actualUrl is defined when context.hasUrl is true
|
|
59
|
+
var urlObj = new URL(context.actualUrl);
|
|
60
|
+
var fullPath = urlObj.pathname.substring(1); // Remove leading slash
|
|
61
|
+
var relativePath = context.rootLevel ? fullPath.substring(context.rootLevel.length) : fullPath;
|
|
62
|
+
mainFilePath = relativePath.replace(/\/[^/]+$/, "/".concat(effectiveFileName));
|
|
63
|
+
} else if (context.hasUrl && variant.extraFiles && Object.keys(variant.extraFiles).length > 0) {
|
|
64
|
+
// URL with extra files but no back navigation
|
|
65
|
+
if (context.hasMetadata) {
|
|
66
|
+
// For metadata cases, preserve the full directory structure
|
|
67
|
+
mainFilePath = context.urlDirectory.length > 0 ? "".concat(context.urlDirectory.join('/'), "/").concat(effectiveFileName) : effectiveFileName;
|
|
68
|
+
} else {
|
|
69
|
+
// Check if all extra files are current directory references
|
|
70
|
+
var allCurrentDir = Object.keys(variant.extraFiles).every(function (path) {
|
|
71
|
+
return path.startsWith('./') || !path.startsWith('../') && !path.startsWith('.');
|
|
72
|
+
});
|
|
73
|
+
if (allCurrentDir) {
|
|
74
|
+
// For current directory references without metadata, flatten to root
|
|
75
|
+
mainFilePath = effectiveFileName;
|
|
76
|
+
} else {
|
|
77
|
+
// Use just the immediate parent directory
|
|
78
|
+
var lastSegment = context.urlDirectory[context.urlDirectory.length - 1];
|
|
79
|
+
mainFilePath = lastSegment ? "".concat(lastSegment, "/").concat(effectiveFileName) : effectiveFileName;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
// Simple case - just use the filename
|
|
84
|
+
mainFilePath = effectiveFileName;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Add src/ prefix if we have metadata
|
|
88
|
+
if (context.hasMetadata) {
|
|
89
|
+
// When there are metadata files, simplify the main file path
|
|
90
|
+
if (context.hasUrl && !context.maxBackNavigation) {
|
|
91
|
+
// No back navigation - just use the filename
|
|
92
|
+
mainFilePath = effectiveFileName;
|
|
93
|
+
}
|
|
94
|
+
mainFilePath = "src/".concat(mainFilePath);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
path: mainFilePath,
|
|
98
|
+
hasDirectory: mainFilePath.includes('/')
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Process metadata files to determine their final paths
|
|
104
|
+
*/
|
|
105
|
+
function processMetadataFile(relativePath) {
|
|
106
|
+
// Extract everything after the back navigation, preserving directory structure
|
|
107
|
+
return relativePath.replace(/^(\.\.\/)+/, '');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Process extra file paths to determine their final paths
|
|
112
|
+
*/
|
|
113
|
+
function processExtraFilePath(relativePath, context, mainFile) {
|
|
114
|
+
if (relativePath.startsWith('./')) {
|
|
115
|
+
// Current directory reference - just remove the ./
|
|
116
|
+
return relativePath.substring(2);
|
|
117
|
+
}
|
|
118
|
+
if (relativePath.startsWith('../')) {
|
|
119
|
+
// Back navigation - resolve relative to URL or create synthetic paths
|
|
120
|
+
if (context.hasUrl) {
|
|
121
|
+
// TypeScript knows context.actualUrl is defined when context.hasUrl is true
|
|
122
|
+
var resolved = resolveRelativePath(context.actualUrl, relativePath);
|
|
123
|
+
if (context.rootLevel) {
|
|
124
|
+
var rootLevelClean = context.rootLevel.replace(/\/$/, '');
|
|
125
|
+
if (resolved.startsWith("".concat(rootLevelClean, "/"))) {
|
|
126
|
+
return resolved.substring(rootLevelClean.length + 1);
|
|
127
|
+
}
|
|
128
|
+
if (resolved === rootLevelClean) {
|
|
129
|
+
return relativePath.split('/').pop() || relativePath;
|
|
130
|
+
}
|
|
131
|
+
return resolved;
|
|
132
|
+
}
|
|
133
|
+
return resolved;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Fallback: if somehow we don't have a URL (shouldn't happen anymore with synthetic URLs)
|
|
137
|
+
return relativePath.split('/').pop() || relativePath;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Regular relative path (like 'dir/utils.ts')
|
|
141
|
+
if (context.hasUrl && !context.hasMetadata && mainFile != null && mainFile.hasDirectory) {
|
|
142
|
+
// Place relative to main file's directory if it has one
|
|
143
|
+
var lastSegment = context.urlDirectory[context.urlDirectory.length - 1];
|
|
144
|
+
return lastSegment ? "".concat(lastSegment, "/").concat(relativePath) : relativePath;
|
|
145
|
+
}
|
|
146
|
+
return relativePath;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Process an extra file to determine its final path
|
|
151
|
+
*/
|
|
152
|
+
function processExtraFile(relativePath, file, context, mainFile) {
|
|
153
|
+
var finalPath;
|
|
154
|
+
if (file.metadata) {
|
|
155
|
+
finalPath = processMetadataFile(relativePath);
|
|
156
|
+
} else {
|
|
157
|
+
finalPath = processExtraFilePath(relativePath, context, mainFile);
|
|
158
|
+
|
|
159
|
+
// Add src/ prefix if we have metadata (all paths are relative to main file)
|
|
160
|
+
if (context.hasMetadata) {
|
|
161
|
+
finalPath = "src/".concat(finalPath);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return finalPath;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Flatten a VariantCode into a flat files structure
|
|
169
|
+
* Resolves relative paths and handles metadata file scoping
|
|
170
|
+
*/
|
|
171
|
+
export function flattenVariant(variant) {
|
|
172
|
+
var result = {};
|
|
173
|
+
var context = createPathContext(variant);
|
|
174
|
+
|
|
175
|
+
// Process main file
|
|
176
|
+
var mainFile = processMainFile(variant, context);
|
|
177
|
+
if (mainFile && variant.source !== undefined) {
|
|
178
|
+
result[mainFile.path] = {
|
|
179
|
+
source: stringOrHastToString(variant.source)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Process extra files
|
|
184
|
+
if (variant.extraFiles) {
|
|
185
|
+
for (var _i = 0, _Object$entries = Object.entries(variant.extraFiles); _i < _Object$entries.length; _i++) {
|
|
186
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
187
|
+
relativePath = _Object$entries$_i[0],
|
|
188
|
+
fileContent = _Object$entries$_i[1];
|
|
189
|
+
var file = typeof fileContent === 'string' ? {
|
|
190
|
+
source: fileContent
|
|
191
|
+
} : fileContent;
|
|
192
|
+
|
|
193
|
+
// Skip files with no source content
|
|
194
|
+
if (!file.source && file.source !== '') {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
var finalPath = processExtraFile(relativePath, file, context, mainFile);
|
|
198
|
+
result[finalPath] = _objectSpread({
|
|
199
|
+
source: stringOrHastToString(file.source || '')
|
|
200
|
+
}, file.metadata && {
|
|
201
|
+
metadata: file.metadata
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
package/useDemo/index.d.ts
CHANGED
|
@@ -1,39 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
githubUrlPrefix?: string;
|
|
8
|
-
codeSandboxUrlPrefix?: string;
|
|
9
|
-
stackBlitzPrefix?: string;
|
|
10
|
-
initialVariant?: string;
|
|
11
|
-
initialTransform?: string;
|
|
12
|
-
};
|
|
13
|
-
export declare function useDemo(contentProps: ContentProps, opts?: UseDemoOpts): {
|
|
14
|
-
name: string | undefined;
|
|
15
|
-
slug: string | undefined;
|
|
16
|
-
description: string | undefined;
|
|
17
|
-
component: React.ReactNode;
|
|
18
|
-
ref: React.RefObject<HTMLDivElement | null>;
|
|
19
|
-
variants: string[];
|
|
20
|
-
selectedVariant: string;
|
|
21
|
-
selectVariant: React.Dispatch<React.SetStateAction<string>>;
|
|
22
|
-
files: Array<{
|
|
23
|
-
name: string;
|
|
24
|
-
component: React.ReactNode;
|
|
25
|
-
}>;
|
|
26
|
-
selectedFile: React.ReactNode;
|
|
27
|
-
selectedFileName: string;
|
|
28
|
-
selectFileName: React.Dispatch<React.SetStateAction<string>>;
|
|
29
|
-
expanded: boolean;
|
|
30
|
-
expand: () => void;
|
|
31
|
-
setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|
|
32
|
-
resetFocus: () => void;
|
|
33
|
-
copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
|
|
34
|
-
copyDisabled: boolean;
|
|
35
|
-
availableTransforms: string[];
|
|
36
|
-
selectedTransform: string | null | undefined;
|
|
37
|
-
selectTransform: (transformName: string | null) => void;
|
|
38
|
-
};
|
|
39
|
-
export {};
|
|
1
|
+
export * from "./useDemo.js";
|
|
2
|
+
export * from "./createStackBlitz.js";
|
|
3
|
+
export * from "./createCodeSandbox.js";
|
|
4
|
+
export * from "./flattenVariant.js";
|
|
5
|
+
export * from "./exportVariant.js";
|
|
6
|
+
export * from "./exportVariantAsCra.js";
|
package/useDemo/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useDemo/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|