@mui/internal-docs-infra 0.1.1-canary.9 → 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,276 @@
|
|
|
1
|
+
import type { Root, RootData } from 'hast';
|
|
2
|
+
import type { Delta } from 'jsondiffpatch';
|
|
3
|
+
export type Components = {
|
|
4
|
+
[key: string]: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
type CodeMeta = {
|
|
7
|
+
/** Name of the file (e.g., 'Button.tsx') */
|
|
8
|
+
fileName?: string;
|
|
9
|
+
/** Flattened path for the file */
|
|
10
|
+
path?: string;
|
|
11
|
+
};
|
|
12
|
+
export type Transforms = Record<string, {
|
|
13
|
+
delta: Delta;
|
|
14
|
+
fileName?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export interface ExternalImportItem {
|
|
17
|
+
name: string;
|
|
18
|
+
type: 'named' | 'default' | 'namespace';
|
|
19
|
+
isType?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type Externals = Record<string, ExternalImportItem[]>;
|
|
22
|
+
export interface HastRoot extends Root {
|
|
23
|
+
data?: RootData & {
|
|
24
|
+
totalLines?: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export type VariantSource = string | HastRoot | {
|
|
28
|
+
hastJson: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Additional files associated with a code variant.
|
|
32
|
+
* Can be either simple string content or objects with source and transformation options.
|
|
33
|
+
*/
|
|
34
|
+
export type VariantExtraFiles = {
|
|
35
|
+
[fileName: string]: string | {
|
|
36
|
+
/** Source content for this file */
|
|
37
|
+
source?: VariantSource;
|
|
38
|
+
/** Transformations that can be applied to this file */
|
|
39
|
+
transforms?: Transforms;
|
|
40
|
+
/** Skip generating source transformers for this file */
|
|
41
|
+
skipTransforms?: boolean;
|
|
42
|
+
/** Include metadata for this file */
|
|
43
|
+
metadata?: boolean;
|
|
44
|
+
/** File system path for this file */
|
|
45
|
+
path?: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Complete code variant definition with source, metadata, and configuration.
|
|
50
|
+
* Extends CodeMeta with all the information needed to display and process a code example.
|
|
51
|
+
*/
|
|
52
|
+
export type VariantCode = CodeMeta & {
|
|
53
|
+
/** Source URL where this variant originates */
|
|
54
|
+
url?: string;
|
|
55
|
+
/** Main source content for this variant */
|
|
56
|
+
source?: VariantSource;
|
|
57
|
+
/** Additional files associated with this variant */
|
|
58
|
+
extraFiles?: VariantExtraFiles;
|
|
59
|
+
/** Prefix for metadata keys, e.g. /src */
|
|
60
|
+
metadataPrefix?: string;
|
|
61
|
+
/** External module dependencies */
|
|
62
|
+
externals?: string[];
|
|
63
|
+
/** The name of the export for this variant's entrypoint */
|
|
64
|
+
namedExport?: string;
|
|
65
|
+
/** Order in which files should be displayed */
|
|
66
|
+
filesOrder?: string[];
|
|
67
|
+
/** Transformations that can be applied to the source */
|
|
68
|
+
transforms?: Transforms;
|
|
69
|
+
/** Whether all files in the variant are explicitly listed */
|
|
70
|
+
allFilesListed?: boolean;
|
|
71
|
+
/** Skip generating source transformers for this variant */
|
|
72
|
+
skipTransforms?: boolean;
|
|
73
|
+
};
|
|
74
|
+
export type Code = {
|
|
75
|
+
[key: string]: undefined | string | VariantCode;
|
|
76
|
+
};
|
|
77
|
+
export type ControlledVariantExtraFiles = {
|
|
78
|
+
[fileName: string]: {
|
|
79
|
+
source: string | null;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export type ControlledVariantCode = CodeMeta & {
|
|
83
|
+
url?: string;
|
|
84
|
+
source?: string | null;
|
|
85
|
+
extraFiles?: ControlledVariantExtraFiles;
|
|
86
|
+
filesOrder?: string[];
|
|
87
|
+
};
|
|
88
|
+
export type ControlledCode = {
|
|
89
|
+
[key: string]: undefined | null | ControlledVariantCode;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Base props passed to Content components for rendering code examples.
|
|
93
|
+
* These props provide the necessary data for displaying code, previews, and metadata.
|
|
94
|
+
*/
|
|
95
|
+
type BaseContentProps = CodeIdentityProps & Pick<CodeContentProps, 'code' | 'components' | 'variantType'>;
|
|
96
|
+
export type ContentProps<T extends {}> = BaseContentProps & T;
|
|
97
|
+
export type ContentLoadingVariant = {
|
|
98
|
+
fileNames?: string[];
|
|
99
|
+
source?: React.ReactNode;
|
|
100
|
+
extraSource?: {
|
|
101
|
+
[fileName: string]: React.ReactNode;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export type BaseContentLoadingProps = ContentLoadingVariant & CodeIdentityProps & {
|
|
105
|
+
extraVariants?: Record<string, ContentLoadingVariant>;
|
|
106
|
+
};
|
|
107
|
+
export type ContentLoadingProps<T extends {}> = BaseContentLoadingProps & T & {
|
|
108
|
+
component: React.ReactNode;
|
|
109
|
+
components?: Record<string, React.ReactNode>;
|
|
110
|
+
initialFilename?: string;
|
|
111
|
+
};
|
|
112
|
+
export type LoadCodeMeta = (url: string) => Promise<Code>;
|
|
113
|
+
export type LoadVariantMeta = (variantName: string, url: string) => Promise<VariantCode>;
|
|
114
|
+
export type LoadSource = (url: string) => Promise<{
|
|
115
|
+
source: string;
|
|
116
|
+
extraFiles?: VariantExtraFiles;
|
|
117
|
+
extraDependencies?: string[];
|
|
118
|
+
externals?: Externals;
|
|
119
|
+
}>;
|
|
120
|
+
export type TransformSource = (source: string, fileName: string) => Promise<Record<string, {
|
|
121
|
+
source: string;
|
|
122
|
+
fileName?: string;
|
|
123
|
+
}> | undefined>;
|
|
124
|
+
export type ParseSource = (source: string, fileName: string) => HastRoot;
|
|
125
|
+
export type SourceTransformer = {
|
|
126
|
+
extensions: string[];
|
|
127
|
+
transformer: TransformSource;
|
|
128
|
+
};
|
|
129
|
+
export type SourceTransformers = Array<SourceTransformer>;
|
|
130
|
+
/**
|
|
131
|
+
* Options for controlling file loading behavior
|
|
132
|
+
*/
|
|
133
|
+
export interface LoadFileOptions {
|
|
134
|
+
/** Disable applying source transformers */
|
|
135
|
+
disableTransforms?: boolean;
|
|
136
|
+
/** Disable parsing source strings to AST */
|
|
137
|
+
disableParsing?: boolean;
|
|
138
|
+
/** Maximum recursion depth for loading nested extra files */
|
|
139
|
+
maxDepth?: number;
|
|
140
|
+
/** Set of already loaded file URLs to prevent circular dependencies */
|
|
141
|
+
loadedFiles?: Set<string>;
|
|
142
|
+
/** Side effects code to inject into extraFiles */
|
|
143
|
+
globalsCode?: Array<VariantCode | string>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Options for the loadVariant function, extending LoadFileOptions with required function dependencies
|
|
147
|
+
*/
|
|
148
|
+
export interface LoadVariantOptions extends LoadFileOptions, Pick<CodeFunctionProps, 'sourceParser' | 'loadSource' | 'loadVariantMeta' | 'sourceTransformers'> {}
|
|
149
|
+
/**
|
|
150
|
+
* Options for loading fallback code with various configuration flags
|
|
151
|
+
*/
|
|
152
|
+
export interface LoadFallbackCodeOptions extends LoadFileOptions, CodeFunctionProps, Pick<CodeContentProps, 'variants'>, Pick<CodeLoadingProps, 'fallbackUsesExtraFiles' | 'fallbackUsesAllVariants'> {
|
|
153
|
+
/** Flag to indicate if syntax highlighting should be performed */
|
|
154
|
+
shouldHighlight?: boolean;
|
|
155
|
+
/** Specific filename to initially display */
|
|
156
|
+
initialFilename?: string;
|
|
157
|
+
/** Array of global code to include (overrides LoadFileOptions.globalsCode with different type) */
|
|
158
|
+
globalsCode?: Array<Code | string>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Basic identification and metadata props for code examples
|
|
162
|
+
*/
|
|
163
|
+
export interface CodeIdentityProps {
|
|
164
|
+
/** Display name for the code example, used for identification and titles */
|
|
165
|
+
name?: string;
|
|
166
|
+
/** URL-friendly identifier for deep linking and navigation */
|
|
167
|
+
slug?: string;
|
|
168
|
+
/** Source URL where the code content originates from */
|
|
169
|
+
url?: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Core code content and variant management props
|
|
173
|
+
*/
|
|
174
|
+
export interface CodeContentProps {
|
|
175
|
+
/** Static code content with variants and metadata */
|
|
176
|
+
code?: Code;
|
|
177
|
+
/** React components for live preview alongside code */
|
|
178
|
+
components?: Components;
|
|
179
|
+
/** What type of variants are available (e.g., a type `packageManager` when variants `npm` and `yarn` are available) */
|
|
180
|
+
variantType?: string;
|
|
181
|
+
/** Static variant names that should be fetched at runtime */
|
|
182
|
+
variants?: string[];
|
|
183
|
+
/** Currently selected variant name */
|
|
184
|
+
variant?: string;
|
|
185
|
+
/** Currently selected file name */
|
|
186
|
+
fileName?: string;
|
|
187
|
+
/** Default variant to show on first load */
|
|
188
|
+
initialVariant?: string;
|
|
189
|
+
/** Fallback variant when the requested variant is not available */
|
|
190
|
+
defaultVariant?: string;
|
|
191
|
+
/** Global static code snippets to inject, typically for styling or tooling */
|
|
192
|
+
globalsCode?: Array<Code | string>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Loading and processing configuration props
|
|
196
|
+
*/
|
|
197
|
+
export interface CodeLoadingProps {
|
|
198
|
+
/** Pre-computed code data from build-time optimization */
|
|
199
|
+
precompute?: Code;
|
|
200
|
+
/** Whether fallback content should include extra files */
|
|
201
|
+
fallbackUsesExtraFiles?: boolean;
|
|
202
|
+
/** Whether fallback content should include all variants */
|
|
203
|
+
fallbackUsesAllVariants?: boolean;
|
|
204
|
+
/** Enable controlled mode for external code state management */
|
|
205
|
+
controlled?: boolean;
|
|
206
|
+
/** Raw code string for simple use cases */
|
|
207
|
+
children?: string;
|
|
208
|
+
/**
|
|
209
|
+
* When to perform syntax highlighting and code processing
|
|
210
|
+
* @default 'stream'
|
|
211
|
+
*/
|
|
212
|
+
highlightAt?: 'init' | 'stream' | 'hydration' | 'idle';
|
|
213
|
+
/** Force client-side rendering even when server rendering is available */
|
|
214
|
+
forceClient?: boolean;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Function props for loading and transforming code
|
|
218
|
+
*/
|
|
219
|
+
export interface CodeFunctionProps {
|
|
220
|
+
/** Function to load code metadata from a URL */
|
|
221
|
+
loadCodeMeta?: LoadCodeMeta;
|
|
222
|
+
/** Function to load specific variant metadata */
|
|
223
|
+
loadVariantMeta?: LoadVariantMeta;
|
|
224
|
+
/** Function to load raw source code and dependencies */
|
|
225
|
+
loadSource?: LoadSource;
|
|
226
|
+
/** Array of source transformers for code processing (e.g., TypeScript to JavaScript) */
|
|
227
|
+
sourceTransformers?: SourceTransformers;
|
|
228
|
+
/** Promise resolving to a source parser for syntax highlighting */
|
|
229
|
+
sourceParser?: Promise<ParseSource>;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Component and rendering props
|
|
233
|
+
*/
|
|
234
|
+
export interface CodeRenderingProps<T extends {}> {
|
|
235
|
+
/** Component to render the code content and preview */
|
|
236
|
+
Content: React.ComponentType<ContentProps<T>>;
|
|
237
|
+
/** Additional props passed to the Content component */
|
|
238
|
+
contentProps?: T;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Client-specific rendering props
|
|
242
|
+
*/
|
|
243
|
+
export interface CodeClientRenderingProps {
|
|
244
|
+
/** The CodeContent component that renders the code display and syntax highlighting */
|
|
245
|
+
children: React.ReactNode;
|
|
246
|
+
/** Loading placeholder shown while code is being processed */
|
|
247
|
+
fallback?: React.ReactNode;
|
|
248
|
+
/** Skip showing fallback content entirely */
|
|
249
|
+
skipFallback?: boolean;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Base props containing essential properties shared across CodeHighlighter components and helper functions.
|
|
253
|
+
* This serves as the foundation for other CodeHighlighter-related interfaces.
|
|
254
|
+
*/
|
|
255
|
+
export interface CodeHighlighterBaseProps<T extends {}> extends CodeIdentityProps, CodeContentProps, CodeLoadingProps, CodeFunctionProps, CodeRenderingProps<T> {}
|
|
256
|
+
/**
|
|
257
|
+
* Props for the client-side CodeHighlighter component.
|
|
258
|
+
* Used when rendering happens in the browser with lazy loading and interactive features.
|
|
259
|
+
*/
|
|
260
|
+
export interface CodeHighlighterClientProps extends CodeIdentityProps, CodeContentProps, Omit<CodeLoadingProps, 'children'>, CodeClientRenderingProps {
|
|
261
|
+
/**
|
|
262
|
+
* When to perform syntax highlighting for performance optimization
|
|
263
|
+
* @default 'hydration'
|
|
264
|
+
*/
|
|
265
|
+
highlightAt?: 'init' | 'hydration' | 'idle';
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Main props for the CodeHighlighter component.
|
|
269
|
+
* Supports both build-time precomputation and runtime code loading with extensive customization options.
|
|
270
|
+
* Generic type T allows for custom props to be passed to Content and ContentLoading components.
|
|
271
|
+
*/
|
|
272
|
+
export interface CodeHighlighterProps<T extends {}> extends CodeHighlighterBaseProps<T> {
|
|
273
|
+
/** Component to show while code is being loaded or processed */
|
|
274
|
+
ContentLoading?: React.ComponentType<ContentLoadingProps<T>>;
|
|
275
|
+
}
|
|
276
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { LoadCodeMeta, LoadSource, LoadVariantMeta, ParseSource, SourceTransformers, Code, ControlledCode, LoadFallbackCodeOptions, LoadVariantOptions, Externals, VariantCode } from "../CodeHighlighter/types.js";
|
|
3
|
+
export type LoadFallbackCodeFn = (url: string, initialVariant: string, loaded: Code | undefined, options?: LoadFallbackCodeOptions) => Promise<{
|
|
4
|
+
code: Code;
|
|
5
|
+
processedGlobalsCode?: Array<Code>;
|
|
6
|
+
}>;
|
|
7
|
+
export type LoadVariantFn = (url: string | undefined, variantName: string, variant: VariantCode | string | undefined, options?: LoadVariantOptions) => Promise<{
|
|
8
|
+
code: VariantCode;
|
|
9
|
+
dependencies: string[];
|
|
10
|
+
externals: Externals;
|
|
11
|
+
}>;
|
|
12
|
+
export type ParseCodeFn = (code: Code, parseSource: ParseSource) => Code;
|
|
13
|
+
export type ParseControlledCodeFn = (controlledCode: ControlledCode, parseSource: ParseSource) => Code;
|
|
14
|
+
export type ApplyTransformsFn = (parsedCode: Code, parseSource: ParseSource) => Promise<Code>;
|
|
15
|
+
export type GetAvailableTransformsFn = (parsedCode: Code | undefined, variantName: string) => string[];
|
|
16
|
+
export interface CodeContext {
|
|
17
|
+
sourceParser?: Promise<ParseSource>;
|
|
18
|
+
parseSource?: ParseSource;
|
|
19
|
+
sourceTransformers?: SourceTransformers;
|
|
20
|
+
loadSource?: LoadSource;
|
|
21
|
+
loadVariantMeta?: LoadVariantMeta;
|
|
22
|
+
loadCodeMeta?: LoadCodeMeta;
|
|
23
|
+
loadFallbackCode?: LoadFallbackCodeFn;
|
|
24
|
+
loadVariant?: LoadVariantFn;
|
|
25
|
+
parseCode?: ParseCodeFn;
|
|
26
|
+
parseControlledCode?: ParseControlledCodeFn;
|
|
27
|
+
applyTransforms?: ApplyTransformsFn;
|
|
28
|
+
getAvailableTransforms?: GetAvailableTransformsFn;
|
|
29
|
+
}
|
|
30
|
+
export declare const CodeContext: React.Context<CodeContext>;
|
|
31
|
+
export declare const useCodeContext: () => CodeContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
// Type definitions for the heavy functions we're moving to context
|
|
6
|
+
|
|
7
|
+
export var CodeContext = /*#__PURE__*/React.createContext({});
|
|
8
|
+
if (process.env.NODE_ENV !== "production") CodeContext.displayName = "CodeContext";
|
|
9
|
+
export var useCodeContext = function useCodeContext() {
|
|
10
|
+
var context = React.useContext(CodeContext);
|
|
11
|
+
return context;
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { LoadCodeMeta, LoadSource, LoadVariantMeta } from "../CodeHighlighter/types.js";
|
|
3
|
+
export declare function CodeProvider({
|
|
4
|
+
children,
|
|
5
|
+
loadCodeMeta,
|
|
6
|
+
loadVariantMeta,
|
|
7
|
+
loadSource
|
|
8
|
+
}: {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
loadCodeMeta?: LoadCodeMeta;
|
|
11
|
+
loadVariantMeta?: LoadVariantMeta;
|
|
12
|
+
loadSource?: LoadSource;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { createStarryNight } from '@wooorm/starry-night';
|
|
6
|
+
import { CodeContext } from "./CodeContext.js";
|
|
7
|
+
import { extensionMap, grammars } from "../pipeline/parseSource/grammars.js";
|
|
8
|
+
import { starryNightGutter } from "../pipeline/parseSource/addLineGutters.js";
|
|
9
|
+
// Import the heavy functions
|
|
10
|
+
import { loadFallbackCode } from "../CodeHighlighter/loadFallbackCode.js";
|
|
11
|
+
import { loadVariant } from "../CodeHighlighter/loadVariant.js";
|
|
12
|
+
import { parseCode } from "../CodeHighlighter/parseCode.js";
|
|
13
|
+
import { parseControlledCode } from "../CodeHighlighter/parseControlledCode.js";
|
|
14
|
+
import { applyTransforms, getAvailableTransforms } from "../CodeHighlighter/transformCode.js";
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
export function CodeProvider(_ref) {
|
|
17
|
+
var children = _ref.children,
|
|
18
|
+
loadCodeMeta = _ref.loadCodeMeta,
|
|
19
|
+
loadVariantMeta = _ref.loadVariantMeta,
|
|
20
|
+
loadSource = _ref.loadSource;
|
|
21
|
+
var _React$useState = React.useState(undefined),
|
|
22
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
23
|
+
parseSource = _React$useState2[0],
|
|
24
|
+
setParseSource = _React$useState2[1];
|
|
25
|
+
var sourceParser = React.useMemo(function () {
|
|
26
|
+
// Only initialize Starry Night in the browser, not during SSR
|
|
27
|
+
if (typeof window === 'undefined') {
|
|
28
|
+
return Promise.resolve(function () {
|
|
29
|
+
throw new Error('parseSource not available during SSR');
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return createStarryNight(grammars).then(function (starryNight) {
|
|
33
|
+
var parseSourceFn = function parseSourceFn(source, fileName) {
|
|
34
|
+
var fileType = fileName.slice(fileName.lastIndexOf('.'));
|
|
35
|
+
if (!extensionMap[fileType]) {
|
|
36
|
+
// Return a basic HAST root node with the source text for unsupported file types
|
|
37
|
+
return {
|
|
38
|
+
type: 'root',
|
|
39
|
+
children: [{
|
|
40
|
+
type: 'text',
|
|
41
|
+
value: source
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var highlighted = starryNight.highlight(source, extensionMap[fileType]);
|
|
46
|
+
var sourceLines = source.split(/\r?\n|\r/);
|
|
47
|
+
starryNightGutter(highlighted, sourceLines); // mutates the tree to add line gutters
|
|
48
|
+
|
|
49
|
+
return highlighted;
|
|
50
|
+
};
|
|
51
|
+
return parseSourceFn;
|
|
52
|
+
});
|
|
53
|
+
}, []);
|
|
54
|
+
React.useEffect(function () {
|
|
55
|
+
// Update the sync version when available
|
|
56
|
+
sourceParser.then(function (parseSourceFn) {
|
|
57
|
+
return setParseSource(function () {
|
|
58
|
+
return parseSourceFn;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}, [sourceParser]);
|
|
62
|
+
var context = React.useMemo(function () {
|
|
63
|
+
return {
|
|
64
|
+
sourceParser: sourceParser,
|
|
65
|
+
parseSource: parseSource,
|
|
66
|
+
// Sync version when available
|
|
67
|
+
loadSource: loadSource,
|
|
68
|
+
loadVariantMeta: loadVariantMeta,
|
|
69
|
+
loadCodeMeta: loadCodeMeta,
|
|
70
|
+
// Provide the heavy functions
|
|
71
|
+
loadFallbackCode: loadFallbackCode,
|
|
72
|
+
loadVariant: loadVariant,
|
|
73
|
+
parseCode: parseCode,
|
|
74
|
+
parseControlledCode: parseControlledCode,
|
|
75
|
+
applyTransforms: applyTransforms,
|
|
76
|
+
getAvailableTransforms: getAvailableTransforms
|
|
77
|
+
};
|
|
78
|
+
}, [sourceParser, parseSource, loadSource, loadVariantMeta, loadCodeMeta]);
|
|
79
|
+
return /*#__PURE__*/_jsx(CodeContext.Provider, {
|
|
80
|
+
value: context,
|
|
81
|
+
children: children
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CodeProvider.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CodeProvider.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Code, CodeHighlighterProps, ContentLoadingProps, ContentProps, LoadCodeMeta, LoadSource, LoadVariantMeta, ParseSource } from "../CodeHighlighter/types.js";
|
|
3
|
+
import { DemoGlobalData } from "../createDemoData/types.js";
|
|
4
|
+
type CreateDemoMeta = {
|
|
5
|
+
name?: string;
|
|
6
|
+
slug?: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
variantType?: string;
|
|
9
|
+
skipPrecompute?: boolean;
|
|
10
|
+
highlightAt?: CodeHighlighterProps<{}>['highlightAt'];
|
|
11
|
+
precompute?: Code;
|
|
12
|
+
ClientProvider?: React.ComponentType<{
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
type AbstractCreateDemoOptions<T extends {}> = {
|
|
17
|
+
DemoContent: React.ComponentType<ContentProps<T>>;
|
|
18
|
+
DemoContentLoading?: React.ComponentType<ContentLoadingProps<T>>;
|
|
19
|
+
DemoTitle?: React.ComponentType<{
|
|
20
|
+
slug?: string;
|
|
21
|
+
children?: string;
|
|
22
|
+
}>;
|
|
23
|
+
controlled?: boolean;
|
|
24
|
+
demoGlobalData?: DemoGlobalData[];
|
|
25
|
+
variantTypes?: Record<string, string>;
|
|
26
|
+
highlightAt?: CodeHighlighterProps<{}>['highlightAt'];
|
|
27
|
+
fallbackUsesExtraFiles?: boolean;
|
|
28
|
+
fallbackUsesAllVariants?: boolean;
|
|
29
|
+
loadCodeMeta?: LoadCodeMeta;
|
|
30
|
+
loadVariantMeta?: LoadVariantMeta;
|
|
31
|
+
loadSource?: LoadSource;
|
|
32
|
+
sourceParser?: Promise<ParseSource>;
|
|
33
|
+
};
|
|
34
|
+
export declare function abstractCreateDemo<T extends {}>(options: AbstractCreateDemoOptions<T>, url: string, variants: {
|
|
35
|
+
[key: string]: React.ComponentType;
|
|
36
|
+
}, meta: CreateDemoMeta | undefined): React.ComponentType<T> & {
|
|
37
|
+
Title: React.ComponentType;
|
|
38
|
+
};
|
|
39
|
+
export declare function createDemoFactory<T extends {}>(options: AbstractCreateDemoOptions<T>): (url: string, component: React.ComponentType, meta?: CreateDemoMeta) => React.ComponentType<T> & {
|
|
40
|
+
Title: React.ComponentType;
|
|
41
|
+
};
|
|
42
|
+
export declare function createDemoWithVariantsFactory<T extends {}>(options: AbstractCreateDemoOptions<T>): (url: string, variants: Record<string, React.ComponentType>, meta?: CreateDemoMeta) => React.ComponentType<T> & {
|
|
43
|
+
Title: React.ComponentType;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CodeHighlighter } from "../CodeHighlighter/index.js";
|
|
4
|
+
import { createDemoDataWithVariants } from "../createDemoData/index.js";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export function abstractCreateDemo(options, url, variants, meta) {
|
|
7
|
+
var demoData = createDemoDataWithVariants(url, variants, meta);
|
|
8
|
+
var variantType = options.variantTypes && options.variantTypes[Object.keys(variants).sort().join(':')];
|
|
9
|
+
var globalCode = [];
|
|
10
|
+
if (options.demoGlobalData) {
|
|
11
|
+
options.demoGlobalData.forEach(function (data) {
|
|
12
|
+
globalCode.push(data.precompute || data.url);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function DemoComponent(props) {
|
|
16
|
+
var renderedComponents = Object.entries(demoData.components).reduce(function (acc, _ref) {
|
|
17
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
18
|
+
key = _ref2[0],
|
|
19
|
+
Component = _ref2[1];
|
|
20
|
+
acc[key] = /*#__PURE__*/React.createElement(Component);
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
var highlighter = /*#__PURE__*/_jsx(CodeHighlighter, {
|
|
24
|
+
url: demoData.url,
|
|
25
|
+
name: demoData.name,
|
|
26
|
+
slug: demoData.slug,
|
|
27
|
+
variantType: (meta == null ? void 0 : meta.variantType) || variantType,
|
|
28
|
+
precompute: demoData.precompute,
|
|
29
|
+
globalsCode: globalCode,
|
|
30
|
+
components: renderedComponents,
|
|
31
|
+
contentProps: props,
|
|
32
|
+
Content: options.DemoContent,
|
|
33
|
+
ContentLoading: options.DemoContentLoading,
|
|
34
|
+
loadCodeMeta: options.loadCodeMeta,
|
|
35
|
+
loadVariantMeta: options.loadVariantMeta,
|
|
36
|
+
loadSource: options.loadSource,
|
|
37
|
+
sourceParser: options.sourceParser,
|
|
38
|
+
highlightAt: (meta == null ? void 0 : meta.highlightAt) || options.highlightAt,
|
|
39
|
+
controlled: options.controlled,
|
|
40
|
+
fallbackUsesExtraFiles: options.fallbackUsesExtraFiles,
|
|
41
|
+
fallbackUsesAllVariants: options.fallbackUsesAllVariants
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Use client provider if available
|
|
45
|
+
var ClientProvider = meta == null ? void 0 : meta.ClientProvider;
|
|
46
|
+
if (ClientProvider) {
|
|
47
|
+
return /*#__PURE__*/_jsx(ClientProvider, {
|
|
48
|
+
children: highlighter
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return highlighter;
|
|
52
|
+
}
|
|
53
|
+
function Title() {
|
|
54
|
+
if (options.DemoTitle) {
|
|
55
|
+
return /*#__PURE__*/_jsx(options.DemoTitle, {
|
|
56
|
+
slug: demoData.slug,
|
|
57
|
+
children: demoData.name
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return /*#__PURE__*/_jsx("h3", {
|
|
61
|
+
id: demoData.slug,
|
|
62
|
+
children: demoData.name
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
DemoComponent.Title = Title;
|
|
66
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
67
|
+
DemoComponent.displayName = demoData.displayName;
|
|
68
|
+
DemoComponent.Title.displayName = "".concat(demoData.displayName, "Title");
|
|
69
|
+
}
|
|
70
|
+
return DemoComponent;
|
|
71
|
+
}
|
|
72
|
+
export function createDemoFactory(options) {
|
|
73
|
+
/**
|
|
74
|
+
* Creates a demo component for displaying code examples with syntax highlighting.
|
|
75
|
+
* @param url Depends on `import.meta.url` to determine the source file location.
|
|
76
|
+
* @param component The component to be rendered in the demo.
|
|
77
|
+
* @param meta Additional meta for the demo.
|
|
78
|
+
*/
|
|
79
|
+
var createDemo = function createDemo(url, component, meta) {
|
|
80
|
+
return abstractCreateDemo(options, url, {
|
|
81
|
+
Default: component
|
|
82
|
+
},
|
|
83
|
+
// precomputed code will use the 'Default' key
|
|
84
|
+
meta);
|
|
85
|
+
};
|
|
86
|
+
return createDemo;
|
|
87
|
+
}
|
|
88
|
+
export function createDemoWithVariantsFactory(options) {
|
|
89
|
+
/**
|
|
90
|
+
* Creates a demo component for displaying code examples with syntax highlighting.
|
|
91
|
+
* A variant is a different implementation style of the same component.
|
|
92
|
+
* @param url Depends on `import.meta.url` to determine the source file location.
|
|
93
|
+
* @param variants The variants of the component to be rendered in the demo.
|
|
94
|
+
* @param meta Additional meta for the demo.
|
|
95
|
+
*/
|
|
96
|
+
var createDemoWithVariants = function createDemoWithVariants(url, variants, meta) {
|
|
97
|
+
return abstractCreateDemo(options, url, variants, meta);
|
|
98
|
+
};
|
|
99
|
+
return createDemoWithVariants;
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractCreateDemo.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractCreateDemo.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Externals } from "../CodeHighlighter/types.js";
|
|
3
|
+
type CreateDemoClientMeta = {
|
|
4
|
+
name?: string;
|
|
5
|
+
slug?: string;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
variantType?: string;
|
|
8
|
+
skipPrecompute?: boolean;
|
|
9
|
+
precompute?: {
|
|
10
|
+
externals?: Externals;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
type AbstractCreateDemoClientOptions = {
|
|
16
|
+
live?: boolean;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Abstract factory function for creating demo client providers.
|
|
21
|
+
* This creates a provider component that supplies externals to child components.
|
|
22
|
+
*
|
|
23
|
+
* @param options Configuration options for the demo client factory
|
|
24
|
+
* @returns A function that creates demo client providers
|
|
25
|
+
*/
|
|
26
|
+
export declare function abstractCreateDemoClient(options: AbstractCreateDemoClientOptions, url: string, meta?: CreateDemoClientMeta): React.ComponentType<{
|
|
27
|
+
children: React.ReactNode;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function createDemoClientFactory(options: AbstractCreateDemoClientOptions): (url: string, meta?: CreateDemoClientMeta) => React.ComponentType<{
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
}>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CodeExternalsContext } from "../CodeExternalsContext/index.js";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract factory function for creating demo client providers.
|
|
6
|
+
* This creates a provider component that supplies externals to child components.
|
|
7
|
+
*
|
|
8
|
+
* @param options Configuration options for the demo client factory
|
|
9
|
+
* @returns A function that creates demo client providers
|
|
10
|
+
*/
|
|
11
|
+
export function abstractCreateDemoClient(options, url, meta) {
|
|
12
|
+
var _meta$precompute;
|
|
13
|
+
// Extract externals from precomputed data
|
|
14
|
+
var externals = (meta == null || (_meta$precompute = meta.precompute) == null ? void 0 : _meta$precompute.externals) || {};
|
|
15
|
+
var context = {
|
|
16
|
+
externals: externals
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Create a provider component that makes externals available to children
|
|
20
|
+
function ClientProvider(_ref) {
|
|
21
|
+
var children = _ref.children;
|
|
22
|
+
// In a real implementation, this would provide the externals via context
|
|
23
|
+
// For now, just render children - the externals are already injected as imports
|
|
24
|
+
return /*#__PURE__*/_jsx(CodeExternalsContext.Provider, {
|
|
25
|
+
value: context,
|
|
26
|
+
children: children
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
30
|
+
ClientProvider.displayName = "ClientProvider(".concat((meta == null ? void 0 : meta.name) || 'Demo', ")");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Attach metadata to the provider for debugging/inspection
|
|
34
|
+
ClientProvider.clientMeta = {
|
|
35
|
+
url: url,
|
|
36
|
+
options: options,
|
|
37
|
+
meta: meta,
|
|
38
|
+
externals: externals
|
|
39
|
+
};
|
|
40
|
+
return ClientProvider;
|
|
41
|
+
}
|
|
42
|
+
export function createDemoClientFactory(options) {
|
|
43
|
+
/**
|
|
44
|
+
* Creates a demo client provider for live editing with precomputed externals.
|
|
45
|
+
* @param url Depends on `import.meta.url` to determine the source file location.
|
|
46
|
+
* @param meta Additional meta and configuration for the demo client.
|
|
47
|
+
*/
|
|
48
|
+
var createDemoClient = function createDemoClient(url, meta) {
|
|
49
|
+
return abstractCreateDemoClient(options, url, meta);
|
|
50
|
+
};
|
|
51
|
+
return createDemoClient;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractCreateDemoClient.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractCreateDemoClient.js";
|