@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
package/esm/useCode/useCode.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["name", "slug", "code", "components", "url"];
|
|
4
1
|
import * as React from 'react';
|
|
5
2
|
import { useCodeHighlighterContextOptional } from "../CodeHighlighter/CodeHighlighterContext.js";
|
|
6
3
|
import { extractNameAndSlugFromUrl } from "../pipeline/loaderUtils/index.js";
|
|
@@ -11,111 +8,112 @@ import { useUIState } from "./useUIState.js";
|
|
|
11
8
|
import { useCopyFunctionality } from "./useCopyFunctionality.js";
|
|
12
9
|
import { useSourceEditing } from "./useSourceEditing.js";
|
|
13
10
|
export function useCode(contentProps, opts) {
|
|
14
|
-
|
|
15
|
-
copyOpts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_ref$saveHashVariantT = _ref.saveHashVariantToLocalStorage,
|
|
25
|
-
saveHashVariantToLocalStorage = _ref$saveHashVariantT === void 0 ? 'on-interaction' : _ref$saveHashVariantT;
|
|
11
|
+
const {
|
|
12
|
+
copy: copyOpts,
|
|
13
|
+
defaultOpen = false,
|
|
14
|
+
initialVariant,
|
|
15
|
+
initialTransform,
|
|
16
|
+
preClassName,
|
|
17
|
+
preRef,
|
|
18
|
+
fileHashMode = 'remove-hash',
|
|
19
|
+
saveHashVariantToLocalStorage = 'on-interaction'
|
|
20
|
+
} = opts || {};
|
|
26
21
|
|
|
27
22
|
// Safely try to get context values - will be undefined if not in context
|
|
28
|
-
|
|
23
|
+
const context = useCodeHighlighterContextOptional();
|
|
29
24
|
|
|
30
25
|
// Get the effective code - context overrides contentProps if available
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
}, [context
|
|
34
|
-
|
|
26
|
+
const effectiveCode = React.useMemo(() => {
|
|
27
|
+
return context?.code || contentProps.code || {};
|
|
28
|
+
}, [context?.code, contentProps.code]);
|
|
29
|
+
const shouldHighlight = !context?.deferHighlight;
|
|
35
30
|
|
|
36
31
|
// Memoize userProps with auto-generated name and slug if missing
|
|
37
|
-
|
|
32
|
+
const userProps = React.useMemo(() => {
|
|
38
33
|
// Extract only the user-defined properties (T) from contentProps
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
const {
|
|
35
|
+
name: contentName,
|
|
36
|
+
slug: contentSlug,
|
|
37
|
+
code,
|
|
38
|
+
components,
|
|
39
|
+
url: contentUrl,
|
|
40
|
+
...userDefinedProps
|
|
41
|
+
} = contentProps;
|
|
45
42
|
// Get URL from context first, then fall back to contentProps
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const effectiveUrl = context?.url || contentUrl;
|
|
44
|
+
let name = contentName;
|
|
45
|
+
let slug = contentSlug;
|
|
49
46
|
// Generate name and slug from URL if they're missing and we have a URL
|
|
50
47
|
if ((!name || !slug) && effectiveUrl) {
|
|
51
48
|
try {
|
|
52
|
-
|
|
49
|
+
const generated = extractNameAndSlugFromUrl(effectiveUrl);
|
|
53
50
|
name = name || generated.name;
|
|
54
51
|
slug = slug || generated.slug;
|
|
55
|
-
} catch
|
|
52
|
+
} catch {
|
|
56
53
|
// If URL parsing fails, keep the original values (which might be undefined)
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
return {
|
|
57
|
+
...userDefinedProps,
|
|
58
|
+
name,
|
|
59
|
+
slug
|
|
60
|
+
};
|
|
61
|
+
}, [contentProps, context?.url]);
|
|
64
62
|
|
|
65
63
|
// Sub-hook: UI State Management (needs slug to check for relevant hash)
|
|
66
|
-
|
|
67
|
-
defaultOpen
|
|
64
|
+
const uiState = useUIState({
|
|
65
|
+
defaultOpen,
|
|
68
66
|
mainSlug: userProps.slug
|
|
69
67
|
});
|
|
70
68
|
|
|
71
69
|
// Sub-hook: Variant Selection
|
|
72
|
-
|
|
73
|
-
effectiveCode
|
|
74
|
-
initialVariant
|
|
70
|
+
const variantSelection = useVariantSelection({
|
|
71
|
+
effectiveCode,
|
|
72
|
+
initialVariant,
|
|
75
73
|
variantType: contentProps.variantType,
|
|
76
74
|
mainSlug: userProps.slug,
|
|
77
|
-
saveHashVariantToLocalStorage
|
|
75
|
+
saveHashVariantToLocalStorage
|
|
78
76
|
});
|
|
79
77
|
|
|
80
78
|
// Sub-hook: Transform Management
|
|
81
|
-
|
|
82
|
-
context
|
|
83
|
-
effectiveCode
|
|
79
|
+
const transformManagement = useTransformManagement({
|
|
80
|
+
context,
|
|
81
|
+
effectiveCode,
|
|
84
82
|
selectedVariantKey: variantSelection.selectedVariantKey,
|
|
85
83
|
selectedVariant: variantSelection.selectedVariant,
|
|
86
|
-
initialTransform
|
|
87
|
-
shouldHighlight
|
|
84
|
+
initialTransform,
|
|
85
|
+
shouldHighlight
|
|
88
86
|
});
|
|
89
87
|
|
|
90
88
|
// Sub-hook: File Navigation
|
|
91
|
-
|
|
89
|
+
const fileNavigation = useFileNavigation({
|
|
92
90
|
selectedVariant: variantSelection.selectedVariant,
|
|
93
91
|
transformedFiles: transformManagement.transformedFiles,
|
|
94
92
|
mainSlug: userProps.slug,
|
|
95
93
|
selectedVariantKey: variantSelection.selectedVariantKey,
|
|
96
94
|
selectVariant: variantSelection.selectVariantProgrammatic,
|
|
97
95
|
variantKeys: variantSelection.variantKeys,
|
|
98
|
-
shouldHighlight
|
|
99
|
-
preClassName
|
|
100
|
-
preRef
|
|
101
|
-
effectiveCode
|
|
102
|
-
fileHashMode
|
|
103
|
-
saveHashVariantToLocalStorage
|
|
96
|
+
shouldHighlight,
|
|
97
|
+
preClassName,
|
|
98
|
+
preRef,
|
|
99
|
+
effectiveCode,
|
|
100
|
+
fileHashMode,
|
|
101
|
+
saveHashVariantToLocalStorage,
|
|
104
102
|
saveVariantToLocalStorage: variantSelection.saveVariantToLocalStorage,
|
|
105
103
|
hashVariant: variantSelection.hashVariant
|
|
106
104
|
});
|
|
107
105
|
|
|
108
106
|
// Sub-hook: Copy Functionality
|
|
109
|
-
|
|
107
|
+
const copyFunctionality = useCopyFunctionality({
|
|
110
108
|
selectedFile: fileNavigation.selectedFile,
|
|
111
|
-
copyOpts
|
|
109
|
+
copyOpts
|
|
112
110
|
});
|
|
113
111
|
|
|
114
112
|
// Sub-hook: Source Editing
|
|
115
|
-
|
|
116
|
-
context
|
|
113
|
+
const sourceEditing = useSourceEditing({
|
|
114
|
+
context,
|
|
117
115
|
selectedVariantKey: variantSelection.selectedVariantKey,
|
|
118
|
-
effectiveCode
|
|
116
|
+
effectiveCode,
|
|
119
117
|
selectedVariant: variantSelection.selectedVariant
|
|
120
118
|
});
|
|
121
119
|
return {
|
|
@@ -136,6 +134,6 @@ export function useCode(contentProps, opts) {
|
|
|
136
134
|
selectedTransform: transformManagement.selectedTransform,
|
|
137
135
|
selectTransform: transformManagement.selectTransform,
|
|
138
136
|
setSource: sourceEditing.setSource,
|
|
139
|
-
userProps
|
|
137
|
+
userProps
|
|
140
138
|
};
|
|
141
139
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
1
|
import { stringOrHastToJsx } from "../pipeline/hastUtils/index.js";
|
|
4
2
|
import { applyCodeTransform } from "../pipeline/loadCodeVariant/applyCodeTransform.js";
|
|
5
3
|
/**
|
|
@@ -11,20 +9,20 @@ import { applyCodeTransform } from "../pipeline/loadCodeVariant/applyCodeTransfo
|
|
|
11
9
|
* @returns Array of available transform keys that have deltas
|
|
12
10
|
*/
|
|
13
11
|
export function getAvailableTransforms(effectiveCode, selectedVariantKey) {
|
|
14
|
-
|
|
12
|
+
const transforms = new Set();
|
|
15
13
|
if (effectiveCode && selectedVariantKey) {
|
|
16
|
-
|
|
17
|
-
if (variantCode &&
|
|
14
|
+
const variantCode = effectiveCode[selectedVariantKey];
|
|
15
|
+
if (variantCode && typeof variantCode === 'object') {
|
|
18
16
|
// Check main variant transforms
|
|
19
17
|
if ('transforms' in variantCode && variantCode.transforms) {
|
|
20
|
-
Object.keys(variantCode.transforms).forEach(
|
|
21
|
-
|
|
18
|
+
Object.keys(variantCode.transforms).forEach(transformKey => {
|
|
19
|
+
const transformData = variantCode.transforms[transformKey];
|
|
22
20
|
// Only include transforms that have actual deltas (file changes)
|
|
23
21
|
// Check if delta exists and is not empty
|
|
24
|
-
if (transformData &&
|
|
25
|
-
|
|
22
|
+
if (transformData && typeof transformData === 'object' && 'delta' in transformData) {
|
|
23
|
+
const delta = transformData.delta;
|
|
26
24
|
// Check if delta has meaningful content (not just an empty object)
|
|
27
|
-
|
|
25
|
+
const hasContent = delta && typeof delta === 'object' && Object.keys(delta).length > 0;
|
|
28
26
|
if (hasContent) {
|
|
29
27
|
transforms.add(transformKey);
|
|
30
28
|
}
|
|
@@ -34,16 +32,16 @@ export function getAvailableTransforms(effectiveCode, selectedVariantKey) {
|
|
|
34
32
|
|
|
35
33
|
// Check extraFiles for transforms with deltas
|
|
36
34
|
if ('extraFiles' in variantCode && variantCode.extraFiles) {
|
|
37
|
-
Object.values(variantCode.extraFiles).forEach(
|
|
38
|
-
if (fileData &&
|
|
39
|
-
Object.keys(fileData.transforms).forEach(
|
|
40
|
-
|
|
35
|
+
Object.values(variantCode.extraFiles).forEach(fileData => {
|
|
36
|
+
if (fileData && typeof fileData === 'object' && 'transforms' in fileData && fileData.transforms) {
|
|
37
|
+
Object.keys(fileData.transforms).forEach(transformKey => {
|
|
38
|
+
const transformData = fileData.transforms[transformKey];
|
|
41
39
|
// Only include transforms that have actual deltas (file changes)
|
|
42
40
|
// Check if delta exists and is not empty
|
|
43
|
-
if (transformData &&
|
|
44
|
-
|
|
41
|
+
if (transformData && typeof transformData === 'object' && 'delta' in transformData) {
|
|
42
|
+
const delta = transformData.delta;
|
|
45
43
|
// Check if delta has meaningful content (not just an empty object)
|
|
46
|
-
|
|
44
|
+
const hasContent = delta && typeof delta === 'object' && Object.keys(delta).length > 0;
|
|
47
45
|
if (hasContent) {
|
|
48
46
|
transforms.add(transformKey);
|
|
49
47
|
}
|
|
@@ -67,7 +65,7 @@ export function getAvailableTransforms(effectiveCode, selectedVariantKey) {
|
|
|
67
65
|
* @returns Object with transformed source and name
|
|
68
66
|
*/
|
|
69
67
|
export function applyTransformToSource(source, fileName, transforms, selectedTransform) {
|
|
70
|
-
if (!
|
|
68
|
+
if (!transforms?.[selectedTransform]) {
|
|
71
69
|
return {
|
|
72
70
|
transformedSource: source,
|
|
73
71
|
transformedName: fileName
|
|
@@ -75,8 +73,8 @@ export function applyTransformToSource(source, fileName, transforms, selectedTra
|
|
|
75
73
|
}
|
|
76
74
|
try {
|
|
77
75
|
// Get transform data
|
|
78
|
-
|
|
79
|
-
if (!transformData ||
|
|
76
|
+
const transformData = transforms[selectedTransform];
|
|
77
|
+
if (!transformData || typeof transformData !== 'object' || !('delta' in transformData)) {
|
|
80
78
|
return {
|
|
81
79
|
transformedSource: source,
|
|
82
80
|
transformedName: fileName
|
|
@@ -84,8 +82,8 @@ export function applyTransformToSource(source, fileName, transforms, selectedTra
|
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
// Check if delta has meaningful content
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
const delta = transformData.delta;
|
|
86
|
+
const hasContent = delta && typeof delta === 'object' && Object.keys(delta).length > 0;
|
|
89
87
|
if (!hasContent) {
|
|
90
88
|
return {
|
|
91
89
|
transformedSource: source,
|
|
@@ -94,14 +92,14 @@ export function applyTransformToSource(source, fileName, transforms, selectedTra
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
// Apply transform
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
const result = applyCodeTransform(source, transforms, selectedTransform);
|
|
96
|
+
const transformedName = transformData.fileName || fileName;
|
|
99
97
|
return {
|
|
100
98
|
transformedSource: result,
|
|
101
|
-
transformedName
|
|
99
|
+
transformedName
|
|
102
100
|
};
|
|
103
101
|
} catch (error) {
|
|
104
|
-
console.error(
|
|
102
|
+
console.error(`Transform failed for ${fileName}:`, error);
|
|
105
103
|
return {
|
|
106
104
|
transformedSource: source,
|
|
107
105
|
transformedName: fileName
|
|
@@ -117,21 +115,20 @@ export function applyTransformToSource(source, fileName, transforms, selectedTra
|
|
|
117
115
|
* @returns Object with transformed files and filename mapping, or undefined if no transform
|
|
118
116
|
*/
|
|
119
117
|
export function createTransformedFiles(selectedVariant, selectedTransform, shouldHighlight) {
|
|
120
|
-
var _variantTransforms$se;
|
|
121
118
|
// Only create transformed files when there's actually a transform selected
|
|
122
119
|
if (!selectedVariant || !selectedTransform) {
|
|
123
120
|
return undefined;
|
|
124
121
|
}
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
const files = [];
|
|
123
|
+
const filenameMap = {};
|
|
127
124
|
|
|
128
125
|
// First, check if any file has a meaningful transform delta for the selected transform
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
const variantTransforms = 'transforms' in selectedVariant ? selectedVariant.transforms : undefined;
|
|
127
|
+
let hasAnyMeaningfulTransform = false;
|
|
131
128
|
|
|
132
129
|
// Check main file for meaningful transform
|
|
133
|
-
if (selectedVariant.fileName && variantTransforms
|
|
134
|
-
|
|
130
|
+
if (selectedVariant.fileName && variantTransforms?.[selectedTransform]?.delta) {
|
|
131
|
+
const delta = variantTransforms[selectedTransform].delta;
|
|
135
132
|
if (delta && Object.keys(delta).length > 0) {
|
|
136
133
|
hasAnyMeaningfulTransform = true;
|
|
137
134
|
}
|
|
@@ -139,11 +136,10 @@ export function createTransformedFiles(selectedVariant, selectedTransform, shoul
|
|
|
139
136
|
|
|
140
137
|
// Check extraFiles for meaningful transforms
|
|
141
138
|
if (!hasAnyMeaningfulTransform && selectedVariant.extraFiles) {
|
|
142
|
-
Object.values(selectedVariant.extraFiles).forEach(
|
|
143
|
-
if (fileData &&
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (transformData != null && transformData.delta && Object.keys(transformData.delta).length > 0) {
|
|
139
|
+
Object.values(selectedVariant.extraFiles).forEach(fileData => {
|
|
140
|
+
if (fileData && typeof fileData === 'object' && 'transforms' in fileData) {
|
|
141
|
+
const transformData = fileData.transforms?.[selectedTransform];
|
|
142
|
+
if (transformData?.delta && Object.keys(transformData.delta).length > 0) {
|
|
147
143
|
hasAnyMeaningfulTransform = true;
|
|
148
144
|
}
|
|
149
145
|
}
|
|
@@ -160,10 +156,11 @@ export function createTransformedFiles(selectedVariant, selectedTransform, shoul
|
|
|
160
156
|
|
|
161
157
|
// Process main file if we have a fileName and source
|
|
162
158
|
if (selectedVariant.fileName && selectedVariant.source) {
|
|
163
|
-
|
|
164
|
-
mainSource
|
|
165
|
-
mainName
|
|
166
|
-
|
|
159
|
+
const {
|
|
160
|
+
transformedSource: mainSource,
|
|
161
|
+
transformedName: mainName
|
|
162
|
+
} = applyTransformToSource(selectedVariant.source, selectedVariant.fileName, variantTransforms, selectedTransform);
|
|
163
|
+
const fileName = selectedVariant.fileName;
|
|
167
164
|
filenameMap[fileName] = mainName;
|
|
168
165
|
files.push({
|
|
169
166
|
name: mainName,
|
|
@@ -175,19 +172,15 @@ export function createTransformedFiles(selectedVariant, selectedTransform, shoul
|
|
|
175
172
|
|
|
176
173
|
// Process extra files
|
|
177
174
|
if (selectedVariant.extraFiles) {
|
|
178
|
-
Object.entries(selectedVariant.extraFiles).forEach(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
extraFileName = _ref2[0],
|
|
182
|
-
fileData = _ref2[1];
|
|
183
|
-
var source;
|
|
184
|
-
var transforms;
|
|
175
|
+
Object.entries(selectedVariant.extraFiles).forEach(([extraFileName, fileData]) => {
|
|
176
|
+
let source;
|
|
177
|
+
let transforms;
|
|
185
178
|
|
|
186
179
|
// Handle different extraFile structures
|
|
187
180
|
if (typeof fileData === 'string') {
|
|
188
181
|
source = fileData;
|
|
189
182
|
transforms = undefined; // Don't inherit variant transforms for simple string files
|
|
190
|
-
} else if (fileData &&
|
|
183
|
+
} else if (fileData && typeof fileData === 'object' && 'source' in fileData) {
|
|
191
184
|
source = fileData.source;
|
|
192
185
|
transforms = fileData.transforms; // Only use explicit transforms for this file
|
|
193
186
|
} else {
|
|
@@ -200,30 +193,28 @@ export function createTransformedFiles(selectedVariant, selectedTransform, shoul
|
|
|
200
193
|
}
|
|
201
194
|
|
|
202
195
|
// Apply transforms if available, otherwise use original source
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
196
|
+
let transformedSource = source;
|
|
197
|
+
let transformedName = extraFileName;
|
|
198
|
+
if (transforms?.[selectedTransform]) {
|
|
206
199
|
try {
|
|
207
|
-
|
|
208
|
-
if (transformData &&
|
|
200
|
+
const transformData = transforms[selectedTransform];
|
|
201
|
+
if (transformData && typeof transformData === 'object' && 'delta' in transformData) {
|
|
209
202
|
// Only apply transform if there's a meaningful delta
|
|
210
|
-
|
|
203
|
+
const hasTransformDelta = transformData.delta && Object.keys(transformData.delta).length > 0;
|
|
211
204
|
if (hasTransformDelta) {
|
|
212
205
|
transformedSource = applyCodeTransform(source, transforms, selectedTransform);
|
|
213
206
|
transformedName = transformData.fileName || extraFileName;
|
|
214
207
|
}
|
|
215
208
|
}
|
|
216
209
|
} catch (error) {
|
|
217
|
-
console.error(
|
|
210
|
+
console.error(`Transform failed for ${extraFileName}:`, error);
|
|
218
211
|
// Continue with original source if transform fails
|
|
219
212
|
}
|
|
220
213
|
}
|
|
221
214
|
|
|
222
215
|
// Only update filenameMap and add to files if this doesn't conflict with existing files
|
|
223
216
|
// If a file already exists with the target name, skip this transformation to preserve original files
|
|
224
|
-
|
|
225
|
-
return f.name === transformedName;
|
|
226
|
-
});
|
|
217
|
+
const existingFile = files.find(f => f.name === transformedName);
|
|
227
218
|
if (!existingFile) {
|
|
228
219
|
filenameMap[extraFileName] = transformedName;
|
|
229
220
|
files.push({
|
|
@@ -234,12 +225,12 @@ export function createTransformedFiles(selectedVariant, selectedTransform, shoul
|
|
|
234
225
|
});
|
|
235
226
|
} else {
|
|
236
227
|
// If there's a conflict, skip this file with a warning
|
|
237
|
-
console.warn(
|
|
228
|
+
console.warn(`Transform conflict: ${extraFileName} would transform to ${transformedName} but that name is already taken. Skipping this file.`);
|
|
238
229
|
}
|
|
239
230
|
});
|
|
240
231
|
}
|
|
241
232
|
return {
|
|
242
|
-
files
|
|
243
|
-
filenameMap
|
|
233
|
+
files,
|
|
234
|
+
filenameMap
|
|
244
235
|
};
|
|
245
236
|
}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { stringOrHastToString } from "../pipeline/hastUtils/index.js";
|
|
4
3
|
import { useCopier } from "../useCopier/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* Hook for managing copy-to-clipboard functionality
|
|
7
6
|
*/
|
|
8
|
-
export function useCopyFunctionality(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export function useCopyFunctionality({
|
|
8
|
+
selectedFile,
|
|
9
|
+
copyOpts
|
|
10
|
+
}) {
|
|
11
|
+
const sourceFileToText = React.useCallback(() => {
|
|
12
12
|
if (!selectedFile) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
15
|
if (typeof selectedFile === 'string') {
|
|
16
16
|
return selectedFile;
|
|
17
17
|
}
|
|
18
|
-
if (selectedFile &&
|
|
18
|
+
if (selectedFile && typeof selectedFile === 'object' && 'hastJson' in selectedFile) {
|
|
19
19
|
return selectedFile.hastJson;
|
|
20
20
|
}
|
|
21
21
|
return stringOrHastToString(selectedFile);
|
|
22
22
|
}, [selectedFile]);
|
|
23
|
-
|
|
24
|
-
copy
|
|
23
|
+
const {
|
|
24
|
+
copy
|
|
25
|
+
} = useCopier(sourceFileToText, copyOpts);
|
|
25
26
|
return {
|
|
26
|
-
copy
|
|
27
|
+
copy
|
|
27
28
|
};
|
|
28
29
|
}
|