@mui/internal-docs-infra 0.1.1-canary.8 → 0.2.0-alpha.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/CHANGELOG.md +9 -0
- package/README.md +3 -11
- package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
- package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
- package/esm/CodeControllerContext/index.d.ts +1 -0
- package/esm/CodeControllerContext/index.js +1 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
- package/esm/CodeExternalsContext/index.d.ts +1 -0
- package/esm/CodeExternalsContext/index.js +1 -0
- package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
- package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
- package/esm/CodeHighlighter/applyTransform.js +75 -0
- package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
- package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
- package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
- package/esm/CodeHighlighter/errors.d.ts +141 -0
- package/esm/CodeHighlighter/errors.js +441 -0
- package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
- package/esm/CodeHighlighter/examineVariant.js +73 -0
- package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
- package/esm/CodeHighlighter/hasAllVariants.js +63 -0
- package/esm/CodeHighlighter/index.d.ts +1 -0
- package/esm/CodeHighlighter/index.js +1 -0
- package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
- package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
- package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
- package/esm/CodeHighlighter/loadVariant.js +1044 -0
- package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
- package/esm/CodeHighlighter/maybeInitialData.js +192 -0
- package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
- package/esm/CodeHighlighter/mergeMetadata.js +165 -0
- package/esm/CodeHighlighter/parseCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseCode.js +134 -0
- package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseControlledCode.js +87 -0
- package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
- package/esm/CodeHighlighter/pathUtils.js +258 -0
- package/esm/CodeHighlighter/transformCode.d.ts +21 -0
- package/esm/CodeHighlighter/transformCode.js +251 -0
- package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/esm/CodeHighlighter/transformParsedSource.js +60 -0
- package/esm/CodeHighlighter/transformSource.d.ts +2 -0
- package/esm/CodeHighlighter/transformSource.js +103 -0
- package/esm/CodeHighlighter/types.d.ts +276 -0
- package/esm/CodeHighlighter/types.js +1 -0
- package/esm/CodeProvider/CodeContext.d.ts +31 -0
- package/esm/CodeProvider/CodeContext.js +12 -0
- package/esm/CodeProvider/CodeProvider.d.ts +13 -0
- package/esm/CodeProvider/CodeProvider.js +83 -0
- package/esm/CodeProvider/index.d.ts +1 -0
- package/esm/CodeProvider/index.js +1 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
- package/esm/abstractCreateDemo/index.d.ts +1 -0
- package/esm/abstractCreateDemo/index.js +1 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
- package/esm/abstractCreateDemoClient/index.d.ts +1 -0
- package/esm/abstractCreateDemoClient/index.js +1 -0
- package/esm/createDemoData/createDemoData.d.ts +44 -0
- package/esm/createDemoData/createDemoData.js +74 -0
- package/esm/createDemoData/index.d.ts +1 -0
- package/esm/createDemoData/index.js +1 -0
- package/esm/createDemoData/types.d.ts +25 -0
- package/esm/createDemoData/types.js +1 -0
- package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
- package/esm/pipeline/hastUtils/hastUtils.js +67 -0
- package/esm/pipeline/hastUtils/index.d.ts +1 -0
- package/esm/pipeline/hastUtils/index.js +1 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
- package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
- package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
- package/esm/pipeline/loadServerSource/index.d.ts +1 -0
- package/esm/pipeline/loadServerSource/index.js +1 -0
- package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
- package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
- package/esm/pipeline/loaderUtils/index.d.ts +7 -0
- package/esm/pipeline/loaderUtils/index.js +7 -0
- package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
- package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
- package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/parseImports.js +306 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
- package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
- package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
- package/esm/pipeline/parseSource/addLineGutters.js +181 -0
- package/esm/pipeline/parseSource/grammars.d.ts +2 -0
- package/esm/pipeline/parseSource/grammars.js +27 -0
- package/esm/pipeline/parseSource/index.d.ts +1 -0
- package/esm/pipeline/parseSource/index.js +1 -0
- package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
- package/esm/pipeline/parseSource/parseSource.js +51 -0
- package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
- package/esm/pipeline/transformHtmlCode/index.js +4 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
- package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/index.js +4 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
- package/esm/useCode/Pre.d.ts +15 -0
- package/esm/useCode/Pre.js +164 -0
- package/esm/useCode/index.d.ts +1 -0
- package/esm/useCode/index.js +1 -0
- package/esm/useCode/useCode.d.ts +41 -0
- package/esm/useCode/useCode.js +128 -0
- package/esm/useCode/useCodeUtils.d.ts +44 -0
- package/esm/useCode/useCodeUtils.js +245 -0
- package/esm/useCode/useCopyFunctionality.d.ts +18 -0
- package/esm/useCode/useCopyFunctionality.js +28 -0
- package/esm/useCode/useFileNavigation.d.ts +41 -0
- package/esm/useCode/useFileNavigation.js +453 -0
- package/esm/useCode/useSourceEditing.d.ts +21 -0
- package/esm/useCode/useSourceEditing.js +32 -0
- package/esm/useCode/useTransformManagement.d.ts +30 -0
- package/esm/useCode/useTransformManagement.js +72 -0
- package/esm/useCode/useUIState.d.ts +16 -0
- package/esm/useCode/useUIState.js +21 -0
- package/esm/useCode/useVariantSelection.d.ts +23 -0
- package/esm/useCode/useVariantSelection.js +75 -0
- package/esm/useCopier/index.d.ts +1 -1
- package/esm/useCopier/index.js +5 -5
- package/esm/useDemo/createCodeSandbox.d.ts +15 -0
- package/esm/useDemo/createCodeSandbox.js +42 -0
- package/esm/useDemo/createStackBlitz.d.ts +22 -0
- package/esm/useDemo/createStackBlitz.js +38 -0
- package/esm/useDemo/exportVariant.d.ts +184 -0
- package/esm/useDemo/exportVariant.js +422 -0
- package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
- package/esm/useDemo/exportVariantAsCra.js +57 -0
- package/esm/useDemo/flattenVariant.d.ts +19 -0
- package/esm/useDemo/flattenVariant.js +49 -0
- package/esm/useDemo/index.d.ts +6 -51
- package/esm/useDemo/index.js +6 -104
- package/esm/useDemo/useDemo.d.ts +81 -0
- package/esm/useDemo/useDemo.js +193 -0
- package/esm/useErrors/ErrorsContext.d.ts +6 -0
- package/esm/useErrors/ErrorsContext.js +8 -0
- package/esm/useErrors/index.d.ts +1 -0
- package/esm/useErrors/index.js +1 -0
- package/esm/useErrors/useErrors.d.ts +5 -0
- package/esm/useErrors/useErrors.js +7 -0
- package/esm/useLocalStorageState/index.d.ts +2 -0
- package/esm/useLocalStorageState/index.js +2 -0
- package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
- package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
- package/esm/usePreference/PreferencesProvider.d.ts +6 -0
- package/esm/usePreference/PreferencesProvider.js +8 -0
- package/esm/usePreference/index.d.ts +2 -0
- package/esm/usePreference/index.js +2 -0
- package/esm/usePreference/usePreference.d.ts +2 -0
- package/esm/usePreference/usePreference.js +25 -0
- package/esm/useUrlHashState/index.d.ts +1 -0
- package/esm/useUrlHashState/index.js +1 -0
- package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
- package/esm/useUrlHashState/useUrlHashState.js +68 -0
- package/esm/withDocsInfra/index.d.ts +1 -0
- package/esm/withDocsInfra/index.js +1 -0
- package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
- package/esm/withDocsInfra/withDocsInfra.js +147 -0
- package/package.json +178 -11
- package/esm/useCopier/index.d.ts.map +0 -1
- package/esm/useDemo/index.d.ts.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UseCopierOpts } from "../useCopier/index.js";
|
|
3
|
+
import type { VariantSource } from "../CodeHighlighter/types.js";
|
|
4
|
+
interface UseCopyFunctionalityProps {
|
|
5
|
+
selectedFile: VariantSource | null;
|
|
6
|
+
copyOpts?: UseCopierOpts;
|
|
7
|
+
}
|
|
8
|
+
export interface UseCopyFunctionalityResult {
|
|
9
|
+
copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook for managing copy-to-clipboard functionality
|
|
13
|
+
*/
|
|
14
|
+
export declare function useCopyFunctionality({
|
|
15
|
+
selectedFile,
|
|
16
|
+
copyOpts
|
|
17
|
+
}: UseCopyFunctionalityProps): UseCopyFunctionalityResult;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { stringOrHastToString } from "../pipeline/hastUtils/index.js";
|
|
4
|
+
import { useCopier } from "../useCopier/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Hook for managing copy-to-clipboard functionality
|
|
7
|
+
*/
|
|
8
|
+
export function useCopyFunctionality(_ref) {
|
|
9
|
+
var selectedFile = _ref.selectedFile,
|
|
10
|
+
copyOpts = _ref.copyOpts;
|
|
11
|
+
var sourceFileToText = React.useCallback(function () {
|
|
12
|
+
if (!selectedFile) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (typeof selectedFile === 'string') {
|
|
16
|
+
return selectedFile;
|
|
17
|
+
}
|
|
18
|
+
if (selectedFile && _typeof(selectedFile) === 'object' && 'hastJson' in selectedFile) {
|
|
19
|
+
return selectedFile.hastJson;
|
|
20
|
+
}
|
|
21
|
+
return stringOrHastToString(selectedFile);
|
|
22
|
+
}, [selectedFile]);
|
|
23
|
+
var _useCopier = useCopier(sourceFileToText, copyOpts),
|
|
24
|
+
copy = _useCopier.copy;
|
|
25
|
+
return {
|
|
26
|
+
copy: copy
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { VariantCode, VariantSource } from "../CodeHighlighter/types.js";
|
|
3
|
+
import type { TransformedFiles } from "./useCodeUtils.js";
|
|
4
|
+
interface UseFileNavigationProps {
|
|
5
|
+
selectedVariant: VariantCode | null;
|
|
6
|
+
transformedFiles: TransformedFiles | undefined;
|
|
7
|
+
mainSlug?: string;
|
|
8
|
+
selectedVariantKey?: string;
|
|
9
|
+
variantKeys?: string[];
|
|
10
|
+
shouldHighlight: boolean;
|
|
11
|
+
initialVariant?: string;
|
|
12
|
+
preClassName?: string;
|
|
13
|
+
preRef?: React.Ref<HTMLPreElement>;
|
|
14
|
+
}
|
|
15
|
+
export interface UseFileNavigationResult {
|
|
16
|
+
selectedFileName: string | undefined;
|
|
17
|
+
selectedFile: VariantSource | null;
|
|
18
|
+
selectedFileComponent: React.ReactNode;
|
|
19
|
+
selectedFileLines: number;
|
|
20
|
+
files: Array<{
|
|
21
|
+
name: string;
|
|
22
|
+
slug?: string;
|
|
23
|
+
component: React.ReactNode;
|
|
24
|
+
}>;
|
|
25
|
+
selectFileName: (fileName: string) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Hook for managing file selection and navigation within a code variant
|
|
29
|
+
*/
|
|
30
|
+
export declare function useFileNavigation({
|
|
31
|
+
selectedVariant,
|
|
32
|
+
transformedFiles,
|
|
33
|
+
mainSlug,
|
|
34
|
+
selectedVariantKey,
|
|
35
|
+
variantKeys,
|
|
36
|
+
initialVariant,
|
|
37
|
+
shouldHighlight,
|
|
38
|
+
preClassName,
|
|
39
|
+
preRef
|
|
40
|
+
}: UseFileNavigationProps): UseFileNavigationResult;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useUrlHashState } from "../useUrlHashState/index.js";
|
|
6
|
+
import { countLines } from "../pipeline/parseSource/addLineGutters.js";
|
|
7
|
+
import { Pre } from "./Pre.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Converts a string to kebab-case
|
|
11
|
+
* @param str - The string to convert
|
|
12
|
+
* @returns kebab-case string
|
|
13
|
+
*/
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
function toKebabCase(str) {
|
|
16
|
+
return str
|
|
17
|
+
// Insert a dash before any uppercase letter that follows a lowercase letter or digit
|
|
18
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase().replace(/[^a-z0-9.]+/g, '-').replace(/^-+|-+$/g, '');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generates a file slug based on main slug, file name, and variant name
|
|
23
|
+
* @param mainSlug - The main component/demo slug
|
|
24
|
+
* @param fileName - The file name
|
|
25
|
+
* @param variantName - The variant name
|
|
26
|
+
* @param isInitialVariant - Whether this is the initial/default variant
|
|
27
|
+
* @returns Generated file slug
|
|
28
|
+
*/
|
|
29
|
+
function generateFileSlug(mainSlug, fileName, variantName, isInitialVariant) {
|
|
30
|
+
// Extract base name from filename (strip extension)
|
|
31
|
+
var lastDotIndex = fileName.lastIndexOf('.');
|
|
32
|
+
var baseName = lastDotIndex !== -1 ? fileName.substring(0, lastDotIndex) : fileName;
|
|
33
|
+
var extension = lastDotIndex !== -1 ? fileName.substring(lastDotIndex) : '';
|
|
34
|
+
|
|
35
|
+
// Convert to kebab-case
|
|
36
|
+
var kebabMainSlug = toKebabCase(mainSlug);
|
|
37
|
+
var kebabBaseName = toKebabCase(baseName);
|
|
38
|
+
var kebabVariantName = toKebabCase(variantName);
|
|
39
|
+
|
|
40
|
+
// Reconstruct filename with kebab-case base name but preserved extension
|
|
41
|
+
var kebabFileName = "".concat(kebabBaseName).concat(extension);
|
|
42
|
+
|
|
43
|
+
// Handle empty main slug case
|
|
44
|
+
if (!kebabMainSlug) {
|
|
45
|
+
return kebabFileName;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Format: mainSlug:fileName.ext (for initial variant) or mainSlug:variantName:fileName.ext
|
|
49
|
+
if (isInitialVariant) {
|
|
50
|
+
return "".concat(kebabMainSlug, ":").concat(kebabFileName);
|
|
51
|
+
}
|
|
52
|
+
return "".concat(kebabMainSlug, ":").concat(kebabVariantName, ":").concat(kebabFileName);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Hook for managing file selection and navigation within a code variant
|
|
56
|
+
*/
|
|
57
|
+
export function useFileNavigation(_ref) {
|
|
58
|
+
var selectedVariant = _ref.selectedVariant,
|
|
59
|
+
transformedFiles = _ref.transformedFiles,
|
|
60
|
+
_ref$mainSlug = _ref.mainSlug,
|
|
61
|
+
mainSlug = _ref$mainSlug === void 0 ? '' : _ref$mainSlug,
|
|
62
|
+
_ref$selectedVariantK = _ref.selectedVariantKey,
|
|
63
|
+
selectedVariantKey = _ref$selectedVariantK === void 0 ? '' : _ref$selectedVariantK,
|
|
64
|
+
_ref$variantKeys = _ref.variantKeys,
|
|
65
|
+
variantKeys = _ref$variantKeys === void 0 ? [] : _ref$variantKeys,
|
|
66
|
+
initialVariant = _ref.initialVariant,
|
|
67
|
+
shouldHighlight = _ref.shouldHighlight,
|
|
68
|
+
preClassName = _ref.preClassName,
|
|
69
|
+
preRef = _ref.preRef;
|
|
70
|
+
// Keep selectedFileName as untransformed filename for internal tracking
|
|
71
|
+
var _React$useState = React.useState(selectedVariant == null ? void 0 : selectedVariant.fileName),
|
|
72
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
73
|
+
selectedFileNameInternal = _React$useState2[0],
|
|
74
|
+
setSelectedFileNameInternal = _React$useState2[1];
|
|
75
|
+
|
|
76
|
+
// Track user interaction locally
|
|
77
|
+
var _React$useState3 = React.useState(false),
|
|
78
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
79
|
+
hasUserInteraction = _React$useState4[0],
|
|
80
|
+
setHasUserInteraction = _React$useState4[1];
|
|
81
|
+
|
|
82
|
+
// Helper to mark user interaction
|
|
83
|
+
var markUserInteraction = React.useCallback(function () {
|
|
84
|
+
setHasUserInteraction(true);
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
// Use the simplified URL hash hook
|
|
88
|
+
var _useUrlHashState = useUrlHashState(),
|
|
89
|
+
_useUrlHashState2 = _slicedToArray(_useUrlHashState, 2),
|
|
90
|
+
hash = _useUrlHashState2[0],
|
|
91
|
+
setHash = _useUrlHashState2[1];
|
|
92
|
+
|
|
93
|
+
// Helper function to check URL hash and switch to matching file
|
|
94
|
+
var checkUrlHashAndSelectFile = React.useCallback(function () {
|
|
95
|
+
if (!selectedVariant || !hash) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Check if hash matches any file slug
|
|
100
|
+
var matchingFileName;
|
|
101
|
+
|
|
102
|
+
// Determine if this is the initial variant
|
|
103
|
+
var isInitialVariant = initialVariant ? selectedVariantKey === initialVariant : variantKeys.length === 0 || selectedVariantKey === variantKeys[0];
|
|
104
|
+
|
|
105
|
+
// Check main file
|
|
106
|
+
if (selectedVariant.fileName) {
|
|
107
|
+
var mainFileSlug = generateFileSlug(mainSlug, selectedVariant.fileName, selectedVariantKey, isInitialVariant);
|
|
108
|
+
if (hash === mainFileSlug) {
|
|
109
|
+
matchingFileName = selectedVariant.fileName;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Check extra files
|
|
114
|
+
if (!matchingFileName && selectedVariant.extraFiles) {
|
|
115
|
+
for (var _i = 0, _Object$keys = Object.keys(selectedVariant.extraFiles); _i < _Object$keys.length; _i++) {
|
|
116
|
+
var fileName = _Object$keys[_i];
|
|
117
|
+
var fileSlug = generateFileSlug(mainSlug, fileName, selectedVariantKey, isInitialVariant);
|
|
118
|
+
if (hash === fileSlug) {
|
|
119
|
+
matchingFileName = fileName;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Check transformed files if available
|
|
126
|
+
if (!matchingFileName && transformedFiles) {
|
|
127
|
+
var _iterator = _createForOfIteratorHelper(transformedFiles.files),
|
|
128
|
+
_step;
|
|
129
|
+
try {
|
|
130
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
131
|
+
var file = _step.value;
|
|
132
|
+
var _fileSlug = generateFileSlug(mainSlug, file.originalName, selectedVariantKey, isInitialVariant);
|
|
133
|
+
if (hash === _fileSlug) {
|
|
134
|
+
matchingFileName = file.originalName;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch (err) {
|
|
139
|
+
_iterator.e(err);
|
|
140
|
+
} finally {
|
|
141
|
+
_iterator.f();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (matchingFileName) {
|
|
145
|
+
setSelectedFileNameInternal(matchingFileName);
|
|
146
|
+
markUserInteraction(); // Mark that user has made a selection via URL
|
|
147
|
+
}
|
|
148
|
+
}, [selectedVariant, hash, transformedFiles, mainSlug, selectedVariantKey, variantKeys, initialVariant, markUserInteraction]);
|
|
149
|
+
|
|
150
|
+
// On hydration/variant change, check URL hash and switch to matching file
|
|
151
|
+
React.useEffect(function () {
|
|
152
|
+
checkUrlHashAndSelectFile();
|
|
153
|
+
}, [checkUrlHashAndSelectFile]);
|
|
154
|
+
|
|
155
|
+
// Reset selectedFileName when variant changes
|
|
156
|
+
React.useEffect(function () {
|
|
157
|
+
if (selectedVariant && selectedFileNameInternal !== selectedVariant.fileName) {
|
|
158
|
+
// Only reset if current selectedFileName doesn't exist in the new variant
|
|
159
|
+
var hasFile = selectedVariant.fileName === selectedFileNameInternal || selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal];
|
|
160
|
+
if (!hasFile) {
|
|
161
|
+
setSelectedFileNameInternal(selectedVariant.fileName);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}, [selectedVariant, selectedFileNameInternal]);
|
|
165
|
+
|
|
166
|
+
// Update URL when variant changes (to reflect new slug for current file)
|
|
167
|
+
React.useEffect(function () {
|
|
168
|
+
if (!selectedVariant || typeof window === 'undefined' || !selectedFileNameInternal || !hasUserInteraction) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Determine if this is the initial variant
|
|
173
|
+
var isInitialVariant = initialVariant ? selectedVariantKey === initialVariant : variantKeys.length === 0 || selectedVariantKey === variantKeys[0];
|
|
174
|
+
|
|
175
|
+
// Generate the new slug for the currently selected file
|
|
176
|
+
var fileSlug = '';
|
|
177
|
+
if (transformedFiles) {
|
|
178
|
+
var file = transformedFiles.files.find(function (f) {
|
|
179
|
+
return f.originalName === selectedFileNameInternal;
|
|
180
|
+
});
|
|
181
|
+
if (file) {
|
|
182
|
+
fileSlug = generateFileSlug(mainSlug, file.originalName, selectedVariantKey, isInitialVariant);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
fileSlug = generateFileSlug(mainSlug, selectedFileNameInternal, selectedVariantKey, isInitialVariant);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Only update the URL hash if it's different from current hash
|
|
189
|
+
if (fileSlug && hash !== fileSlug) {
|
|
190
|
+
setHash(fileSlug); // Use the new URL hash hook
|
|
191
|
+
}
|
|
192
|
+
}, [selectedVariant, selectedFileNameInternal, transformedFiles, mainSlug, selectedVariantKey, variantKeys, initialVariant, hasUserInteraction, setHash, hash]);
|
|
193
|
+
|
|
194
|
+
// Compute the displayed filename (transformed if applicable)
|
|
195
|
+
var selectedFileName = React.useMemo(function () {
|
|
196
|
+
if (!selectedVariant) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// If selectedFileNameInternal is undefined, we're selecting the main file
|
|
201
|
+
var effectiveFileName = selectedFileNameInternal || selectedVariant.fileName;
|
|
202
|
+
if (!effectiveFileName) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// If we have transformed files, return the transformed name
|
|
207
|
+
if (transformedFiles) {
|
|
208
|
+
var file = transformedFiles.files.find(function (f) {
|
|
209
|
+
return f.originalName === effectiveFileName;
|
|
210
|
+
});
|
|
211
|
+
return file ? file.name : effectiveFileName;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Otherwise, return the original filename
|
|
215
|
+
return effectiveFileName;
|
|
216
|
+
}, [selectedVariant, selectedFileNameInternal, transformedFiles]);
|
|
217
|
+
var selectedFile = React.useMemo(function () {
|
|
218
|
+
if (!selectedVariant) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// If we have transformed files, use them
|
|
223
|
+
if (transformedFiles) {
|
|
224
|
+
var effectiveFileName = selectedFileNameInternal || selectedVariant.fileName;
|
|
225
|
+
var file = transformedFiles.files.find(function (f) {
|
|
226
|
+
return f.originalName === effectiveFileName;
|
|
227
|
+
});
|
|
228
|
+
return file ? file.source : null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Otherwise, use the original untransformed files
|
|
232
|
+
if (selectedFileNameInternal === selectedVariant.fileName || !selectedFileNameInternal) {
|
|
233
|
+
var _selectedVariant$sour;
|
|
234
|
+
return (_selectedVariant$sour = selectedVariant.source) != null ? _selectedVariant$sour : null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Look in extraFiles
|
|
238
|
+
if (selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal]) {
|
|
239
|
+
var extraFile = selectedVariant.extraFiles[selectedFileNameInternal];
|
|
240
|
+
if (typeof extraFile === 'string') {
|
|
241
|
+
return extraFile;
|
|
242
|
+
}
|
|
243
|
+
if (extraFile && _typeof(extraFile) === 'object' && 'source' in extraFile) {
|
|
244
|
+
var _extraFile$source;
|
|
245
|
+
return (_extraFile$source = extraFile.source) != null ? _extraFile$source : null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}, [selectedVariant, selectedFileNameInternal, transformedFiles]);
|
|
250
|
+
var selectedFileComponent = React.useMemo(function () {
|
|
251
|
+
if (!selectedVariant) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// If we have transformed files, use them
|
|
256
|
+
if (transformedFiles) {
|
|
257
|
+
var file = transformedFiles.files.find(function (f) {
|
|
258
|
+
return f.originalName === selectedFileNameInternal;
|
|
259
|
+
});
|
|
260
|
+
return file ? file.component : null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Otherwise, create component from original untransformed files
|
|
264
|
+
if (selectedFileNameInternal === selectedVariant.fileName || !selectedFileNameInternal) {
|
|
265
|
+
if (selectedVariant.source == null) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return /*#__PURE__*/_jsx(Pre, {
|
|
269
|
+
className: preClassName,
|
|
270
|
+
ref: preRef,
|
|
271
|
+
shouldHighlight: shouldHighlight,
|
|
272
|
+
children: selectedVariant.source
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Look in extraFiles
|
|
277
|
+
if (selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal]) {
|
|
278
|
+
var extraFile = selectedVariant.extraFiles[selectedFileNameInternal];
|
|
279
|
+
var source;
|
|
280
|
+
if (typeof extraFile === 'string') {
|
|
281
|
+
source = extraFile;
|
|
282
|
+
} else if (extraFile && _typeof(extraFile) === 'object' && 'source' in extraFile) {
|
|
283
|
+
source = extraFile.source;
|
|
284
|
+
} else {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
if (source == null) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return /*#__PURE__*/_jsx(Pre, {
|
|
291
|
+
className: preClassName,
|
|
292
|
+
ref: preRef,
|
|
293
|
+
shouldHighlight: shouldHighlight,
|
|
294
|
+
children: source
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}, [selectedVariant, selectedFileNameInternal, transformedFiles, shouldHighlight, preClassName, preRef]);
|
|
299
|
+
var selectedFileLines = React.useMemo(function () {
|
|
300
|
+
if (selectedFile == null) {
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// If it's a string, split by newlines and count
|
|
305
|
+
if (typeof selectedFile === 'string') {
|
|
306
|
+
return selectedFile.split('\n').length;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// If it's a hast object, count the children length
|
|
310
|
+
if (selectedFile && _typeof(selectedFile) === 'object') {
|
|
311
|
+
var hastSelectedFile;
|
|
312
|
+
if ('hastJson' in selectedFile) {
|
|
313
|
+
hastSelectedFile = JSON.parse(selectedFile.hastJson);
|
|
314
|
+
} else {
|
|
315
|
+
hastSelectedFile = selectedFile;
|
|
316
|
+
}
|
|
317
|
+
if (hastSelectedFile.data && 'totalLines' in hastSelectedFile.data) {
|
|
318
|
+
var totalLines = hastSelectedFile.data.totalLines;
|
|
319
|
+
// Check if totalLines is a valid number (not null, undefined, or NaN)
|
|
320
|
+
if (totalLines != null && !Number.isNaN(Number(totalLines))) {
|
|
321
|
+
var numLines = Number(totalLines);
|
|
322
|
+
if (numLines >= 0) {
|
|
323
|
+
return numLines;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// Fall through to children count if totalLines is invalid
|
|
327
|
+
}
|
|
328
|
+
if ('children' in hastSelectedFile) {
|
|
329
|
+
// Use countLines for more accurate line counting of HAST trees
|
|
330
|
+
return countLines(hastSelectedFile);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return 0;
|
|
334
|
+
}, [selectedFile]);
|
|
335
|
+
|
|
336
|
+
// Convert files for the return interface
|
|
337
|
+
var files = React.useMemo(function () {
|
|
338
|
+
if (!selectedVariant) {
|
|
339
|
+
return [];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Determine if this is the initial variant
|
|
343
|
+
var isInitialVariant = initialVariant ? selectedVariantKey === initialVariant : variantKeys.length === 0 || selectedVariantKey === variantKeys[0];
|
|
344
|
+
|
|
345
|
+
// If we have transformed files, use them
|
|
346
|
+
if (transformedFiles) {
|
|
347
|
+
return transformedFiles.files.map(function (f) {
|
|
348
|
+
return {
|
|
349
|
+
name: f.name,
|
|
350
|
+
slug: generateFileSlug(mainSlug, f.originalName, selectedVariantKey, isInitialVariant),
|
|
351
|
+
component: f.component
|
|
352
|
+
};
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Otherwise, create files from original untransformed data
|
|
357
|
+
var result = [];
|
|
358
|
+
|
|
359
|
+
// Only add main file if it has a fileName
|
|
360
|
+
if (selectedVariant.fileName && selectedVariant.source) {
|
|
361
|
+
result.push({
|
|
362
|
+
name: selectedVariant.fileName,
|
|
363
|
+
slug: generateFileSlug(mainSlug, selectedVariant.fileName, selectedVariantKey, isInitialVariant),
|
|
364
|
+
component: /*#__PURE__*/_jsx(Pre, {
|
|
365
|
+
className: preClassName,
|
|
366
|
+
ref: preRef,
|
|
367
|
+
shouldHighlight: shouldHighlight,
|
|
368
|
+
children: selectedVariant.source
|
|
369
|
+
})
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (selectedVariant.extraFiles) {
|
|
373
|
+
Object.entries(selectedVariant.extraFiles).forEach(function (_ref2) {
|
|
374
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
375
|
+
fileName = _ref3[0],
|
|
376
|
+
fileData = _ref3[1];
|
|
377
|
+
var source;
|
|
378
|
+
if (typeof fileData === 'string') {
|
|
379
|
+
source = fileData;
|
|
380
|
+
} else if (fileData && _typeof(fileData) === 'object' && 'source' in fileData) {
|
|
381
|
+
source = fileData.source;
|
|
382
|
+
} else {
|
|
383
|
+
return; // Skip invalid entries
|
|
384
|
+
}
|
|
385
|
+
if (!source) {
|
|
386
|
+
return; // Skip null/undefined sources
|
|
387
|
+
}
|
|
388
|
+
result.push({
|
|
389
|
+
name: fileName,
|
|
390
|
+
slug: generateFileSlug(mainSlug, fileName, selectedVariantKey, isInitialVariant),
|
|
391
|
+
component: /*#__PURE__*/_jsx(Pre, {
|
|
392
|
+
className: preClassName,
|
|
393
|
+
ref: preRef,
|
|
394
|
+
shouldHighlight: shouldHighlight,
|
|
395
|
+
children: source
|
|
396
|
+
})
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
return result;
|
|
401
|
+
}, [selectedVariant, transformedFiles, mainSlug, selectedVariantKey, variantKeys, initialVariant, shouldHighlight, preClassName, preRef]);
|
|
402
|
+
|
|
403
|
+
// Create a wrapper for selectFileName that handles transformed filenames and URL updates
|
|
404
|
+
var selectFileName = React.useCallback(function (fileName) {
|
|
405
|
+
if (!selectedVariant) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
var targetFileName = fileName;
|
|
409
|
+
var fileSlug = '';
|
|
410
|
+
|
|
411
|
+
// Determine if this is the initial variant
|
|
412
|
+
var isInitialVariant = initialVariant ? selectedVariantKey === initialVariant : variantKeys.length === 0 || selectedVariantKey === variantKeys[0];
|
|
413
|
+
|
|
414
|
+
// If we have transformed files, we need to reverse-lookup the original filename
|
|
415
|
+
if (transformedFiles) {
|
|
416
|
+
// Check if the fileName is a transformed name - if so, find the original
|
|
417
|
+
var fileByTransformedName = transformedFiles.files.find(function (f) {
|
|
418
|
+
return f.name === fileName;
|
|
419
|
+
});
|
|
420
|
+
if (fileByTransformedName) {
|
|
421
|
+
targetFileName = fileByTransformedName.originalName;
|
|
422
|
+
fileSlug = generateFileSlug(mainSlug, fileByTransformedName.originalName, selectedVariantKey, isInitialVariant);
|
|
423
|
+
} else {
|
|
424
|
+
// Check if the fileName is already an original name
|
|
425
|
+
var fileByOriginalName = transformedFiles.files.find(function (f) {
|
|
426
|
+
return f.originalName === fileName;
|
|
427
|
+
});
|
|
428
|
+
if (fileByOriginalName) {
|
|
429
|
+
targetFileName = fileName;
|
|
430
|
+
fileSlug = generateFileSlug(mainSlug, fileName, selectedVariantKey, isInitialVariant);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
} else {
|
|
434
|
+
// No transformed files, generate slug directly
|
|
435
|
+
fileSlug = generateFileSlug(mainSlug, fileName, selectedVariantKey, isInitialVariant);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Update the URL hash without adding to history (replaceState)
|
|
439
|
+
if (typeof window !== 'undefined' && fileSlug && hash !== fileSlug) {
|
|
440
|
+
setHash(fileSlug); // Use the new URL hash hook
|
|
441
|
+
}
|
|
442
|
+
markUserInteraction(); // Mark that user has made an explicit selection
|
|
443
|
+
setSelectedFileNameInternal(targetFileName);
|
|
444
|
+
}, [selectedVariant, transformedFiles, mainSlug, selectedVariantKey, variantKeys, initialVariant, setHash, markUserInteraction, hash]);
|
|
445
|
+
return {
|
|
446
|
+
selectedFileName: selectedFileName,
|
|
447
|
+
selectedFile: selectedFile,
|
|
448
|
+
selectedFileComponent: selectedFileComponent,
|
|
449
|
+
selectedFileLines: selectedFileLines,
|
|
450
|
+
files: files,
|
|
451
|
+
selectFileName: selectFileName
|
|
452
|
+
};
|
|
453
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Code, VariantCode } from "../CodeHighlighter/types.js";
|
|
2
|
+
import type { CodeHighlighterContextType } from "../CodeHighlighter/CodeHighlighterContext.js";
|
|
3
|
+
interface UseSourceEditingProps {
|
|
4
|
+
context?: CodeHighlighterContextType;
|
|
5
|
+
selectedVariantKey: string;
|
|
6
|
+
effectiveCode: Code;
|
|
7
|
+
selectedVariant: VariantCode | null;
|
|
8
|
+
}
|
|
9
|
+
export interface UseSourceEditingResult {
|
|
10
|
+
setSource?: (source: string) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook for managing source code editing functionality
|
|
14
|
+
*/
|
|
15
|
+
export declare function useSourceEditing({
|
|
16
|
+
context,
|
|
17
|
+
selectedVariantKey,
|
|
18
|
+
effectiveCode,
|
|
19
|
+
selectedVariant
|
|
20
|
+
}: UseSourceEditingProps): UseSourceEditingResult;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing source code editing functionality
|
|
5
|
+
*/
|
|
6
|
+
export function useSourceEditing(_ref) {
|
|
7
|
+
var context = _ref.context,
|
|
8
|
+
selectedVariantKey = _ref.selectedVariantKey,
|
|
9
|
+
effectiveCode = _ref.effectiveCode,
|
|
10
|
+
selectedVariant = _ref.selectedVariant;
|
|
11
|
+
var contextSetCode = context == null ? void 0 : context.setCode;
|
|
12
|
+
var setSource = React.useCallback(function (source) {
|
|
13
|
+
if (contextSetCode) {
|
|
14
|
+
contextSetCode(function (currentCode) {
|
|
15
|
+
var newCode = {};
|
|
16
|
+
if (!currentCode) {
|
|
17
|
+
newCode = _extends({}, effectiveCode); // TODO: ensure all source are strings
|
|
18
|
+
}
|
|
19
|
+
newCode[selectedVariantKey] = _extends(_extends({}, newCode[selectedVariantKey] || selectedVariant), {}, {
|
|
20
|
+
source: source,
|
|
21
|
+
extraFiles: {}
|
|
22
|
+
});
|
|
23
|
+
return newCode;
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
console.warn('setCode is not available in the current context. Ensure you are using CodeControllerContext.');
|
|
27
|
+
}
|
|
28
|
+
}, [contextSetCode, selectedVariantKey, effectiveCode, selectedVariant]);
|
|
29
|
+
return {
|
|
30
|
+
setSource: contextSetCode ? setSource : undefined
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Code, VariantCode } from "../CodeHighlighter/types.js";
|
|
2
|
+
import { createTransformedFiles } from "./useCodeUtils.js";
|
|
3
|
+
import { CodeHighlighterContextType } from "../CodeHighlighter/CodeHighlighterContext.js";
|
|
4
|
+
interface UseTransformManagementProps {
|
|
5
|
+
context?: CodeHighlighterContextType;
|
|
6
|
+
effectiveCode: Code;
|
|
7
|
+
selectedVariantKey: string;
|
|
8
|
+
selectedVariant: VariantCode | null;
|
|
9
|
+
initialTransform?: string;
|
|
10
|
+
shouldHighlight: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface UseTransformManagementResult {
|
|
13
|
+
availableTransforms: string[];
|
|
14
|
+
selectedTransform: string | null;
|
|
15
|
+
transformedFiles: ReturnType<typeof createTransformedFiles>;
|
|
16
|
+
selectTransform: (transformName: string | null) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hook for managing code transforms and their application
|
|
20
|
+
* Uses the useLocalStorage hook for local storage persistence of transform preferences
|
|
21
|
+
*/
|
|
22
|
+
export declare function useTransformManagement({
|
|
23
|
+
context,
|
|
24
|
+
effectiveCode,
|
|
25
|
+
selectedVariantKey,
|
|
26
|
+
selectedVariant,
|
|
27
|
+
initialTransform,
|
|
28
|
+
shouldHighlight
|
|
29
|
+
}: UseTransformManagementProps): UseTransformManagementResult;
|
|
30
|
+
export {};
|