@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.
Files changed (217) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +3 -11
  3. package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
  4. package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
  5. package/esm/CodeControllerContext/index.d.ts +1 -0
  6. package/esm/CodeControllerContext/index.js +1 -0
  7. package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
  8. package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
  9. package/esm/CodeExternalsContext/index.d.ts +1 -0
  10. package/esm/CodeExternalsContext/index.js +1 -0
  11. package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
  12. package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
  13. package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
  14. package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
  15. package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
  16. package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
  17. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
  18. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
  19. package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
  20. package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
  21. package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
  22. package/esm/CodeHighlighter/applyTransform.js +75 -0
  23. package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
  24. package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
  25. package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
  26. package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
  27. package/esm/CodeHighlighter/errors.d.ts +141 -0
  28. package/esm/CodeHighlighter/errors.js +441 -0
  29. package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
  30. package/esm/CodeHighlighter/examineVariant.js +73 -0
  31. package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
  32. package/esm/CodeHighlighter/hasAllVariants.js +63 -0
  33. package/esm/CodeHighlighter/index.d.ts +1 -0
  34. package/esm/CodeHighlighter/index.js +1 -0
  35. package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
  36. package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
  37. package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
  38. package/esm/CodeHighlighter/loadVariant.js +1044 -0
  39. package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
  40. package/esm/CodeHighlighter/maybeInitialData.js +192 -0
  41. package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
  42. package/esm/CodeHighlighter/mergeMetadata.js +165 -0
  43. package/esm/CodeHighlighter/parseCode.d.ts +6 -0
  44. package/esm/CodeHighlighter/parseCode.js +134 -0
  45. package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
  46. package/esm/CodeHighlighter/parseControlledCode.js +87 -0
  47. package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
  48. package/esm/CodeHighlighter/pathUtils.js +258 -0
  49. package/esm/CodeHighlighter/transformCode.d.ts +21 -0
  50. package/esm/CodeHighlighter/transformCode.js +251 -0
  51. package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
  52. package/esm/CodeHighlighter/transformParsedSource.js +60 -0
  53. package/esm/CodeHighlighter/transformSource.d.ts +2 -0
  54. package/esm/CodeHighlighter/transformSource.js +103 -0
  55. package/esm/CodeHighlighter/types.d.ts +276 -0
  56. package/esm/CodeHighlighter/types.js +1 -0
  57. package/esm/CodeProvider/CodeContext.d.ts +31 -0
  58. package/esm/CodeProvider/CodeContext.js +12 -0
  59. package/esm/CodeProvider/CodeProvider.d.ts +13 -0
  60. package/esm/CodeProvider/CodeProvider.js +83 -0
  61. package/esm/CodeProvider/index.d.ts +1 -0
  62. package/esm/CodeProvider/index.js +1 -0
  63. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
  64. package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
  65. package/esm/abstractCreateDemo/index.d.ts +1 -0
  66. package/esm/abstractCreateDemo/index.js +1 -0
  67. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
  68. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
  69. package/esm/abstractCreateDemoClient/index.d.ts +1 -0
  70. package/esm/abstractCreateDemoClient/index.js +1 -0
  71. package/esm/createDemoData/createDemoData.d.ts +44 -0
  72. package/esm/createDemoData/createDemoData.js +74 -0
  73. package/esm/createDemoData/index.d.ts +1 -0
  74. package/esm/createDemoData/index.js +1 -0
  75. package/esm/createDemoData/types.d.ts +25 -0
  76. package/esm/createDemoData/types.js +1 -0
  77. package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
  78. package/esm/pipeline/hastUtils/hastUtils.js +67 -0
  79. package/esm/pipeline/hastUtils/index.d.ts +1 -0
  80. package/esm/pipeline/hastUtils/index.js +1 -0
  81. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
  82. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
  83. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
  84. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
  85. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
  86. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
  87. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
  88. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
  89. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
  90. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
  91. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
  92. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
  93. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
  94. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
  95. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
  96. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
  97. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
  98. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
  99. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
  100. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
  101. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
  102. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
  103. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
  104. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
  105. package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
  106. package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
  107. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
  108. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
  109. package/esm/pipeline/loadServerSource/index.d.ts +1 -0
  110. package/esm/pipeline/loadServerSource/index.js +1 -0
  111. package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
  112. package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
  113. package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
  114. package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
  115. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
  116. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
  117. package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
  118. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
  119. package/esm/pipeline/loaderUtils/index.d.ts +7 -0
  120. package/esm/pipeline/loaderUtils/index.js +7 -0
  121. package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
  122. package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
  123. package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
  124. package/esm/pipeline/loaderUtils/parseImports.js +306 -0
  125. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
  126. package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
  127. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
  128. package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
  129. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
  130. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
  131. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
  132. package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
  133. package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
  134. package/esm/pipeline/parseSource/addLineGutters.js +181 -0
  135. package/esm/pipeline/parseSource/grammars.d.ts +2 -0
  136. package/esm/pipeline/parseSource/grammars.js +27 -0
  137. package/esm/pipeline/parseSource/index.d.ts +1 -0
  138. package/esm/pipeline/parseSource/index.js +1 -0
  139. package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
  140. package/esm/pipeline/parseSource/parseSource.js +51 -0
  141. package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
  142. package/esm/pipeline/transformHtmlCode/index.js +4 -0
  143. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
  144. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
  145. package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
  146. package/esm/pipeline/transformMarkdownCode/index.js +4 -0
  147. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
  148. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
  149. package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
  150. package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
  151. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
  152. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
  153. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
  154. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
  155. package/esm/useCode/Pre.d.ts +15 -0
  156. package/esm/useCode/Pre.js +164 -0
  157. package/esm/useCode/index.d.ts +1 -0
  158. package/esm/useCode/index.js +1 -0
  159. package/esm/useCode/useCode.d.ts +41 -0
  160. package/esm/useCode/useCode.js +128 -0
  161. package/esm/useCode/useCodeUtils.d.ts +44 -0
  162. package/esm/useCode/useCodeUtils.js +245 -0
  163. package/esm/useCode/useCopyFunctionality.d.ts +18 -0
  164. package/esm/useCode/useCopyFunctionality.js +28 -0
  165. package/esm/useCode/useFileNavigation.d.ts +41 -0
  166. package/esm/useCode/useFileNavigation.js +453 -0
  167. package/esm/useCode/useSourceEditing.d.ts +21 -0
  168. package/esm/useCode/useSourceEditing.js +32 -0
  169. package/esm/useCode/useTransformManagement.d.ts +30 -0
  170. package/esm/useCode/useTransformManagement.js +72 -0
  171. package/esm/useCode/useUIState.d.ts +16 -0
  172. package/esm/useCode/useUIState.js +21 -0
  173. package/esm/useCode/useVariantSelection.d.ts +23 -0
  174. package/esm/useCode/useVariantSelection.js +75 -0
  175. package/esm/useCopier/index.d.ts +1 -1
  176. package/esm/useCopier/index.js +5 -5
  177. package/esm/useDemo/createCodeSandbox.d.ts +15 -0
  178. package/esm/useDemo/createCodeSandbox.js +42 -0
  179. package/esm/useDemo/createStackBlitz.d.ts +22 -0
  180. package/esm/useDemo/createStackBlitz.js +38 -0
  181. package/esm/useDemo/exportVariant.d.ts +184 -0
  182. package/esm/useDemo/exportVariant.js +422 -0
  183. package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
  184. package/esm/useDemo/exportVariantAsCra.js +57 -0
  185. package/esm/useDemo/flattenVariant.d.ts +19 -0
  186. package/esm/useDemo/flattenVariant.js +49 -0
  187. package/esm/useDemo/index.d.ts +6 -51
  188. package/esm/useDemo/index.js +6 -104
  189. package/esm/useDemo/useDemo.d.ts +81 -0
  190. package/esm/useDemo/useDemo.js +193 -0
  191. package/esm/useErrors/ErrorsContext.d.ts +6 -0
  192. package/esm/useErrors/ErrorsContext.js +8 -0
  193. package/esm/useErrors/index.d.ts +1 -0
  194. package/esm/useErrors/index.js +1 -0
  195. package/esm/useErrors/useErrors.d.ts +5 -0
  196. package/esm/useErrors/useErrors.js +7 -0
  197. package/esm/useLocalStorageState/index.d.ts +2 -0
  198. package/esm/useLocalStorageState/index.js +2 -0
  199. package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
  200. package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
  201. package/esm/usePreference/PreferencesProvider.d.ts +6 -0
  202. package/esm/usePreference/PreferencesProvider.js +8 -0
  203. package/esm/usePreference/index.d.ts +2 -0
  204. package/esm/usePreference/index.js +2 -0
  205. package/esm/usePreference/usePreference.d.ts +2 -0
  206. package/esm/usePreference/usePreference.js +25 -0
  207. package/esm/useUrlHashState/index.d.ts +1 -0
  208. package/esm/useUrlHashState/index.js +1 -0
  209. package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
  210. package/esm/useUrlHashState/useUrlHashState.js +68 -0
  211. package/esm/withDocsInfra/index.d.ts +1 -0
  212. package/esm/withDocsInfra/index.js +1 -0
  213. package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
  214. package/esm/withDocsInfra/withDocsInfra.js +147 -0
  215. package/package.json +178 -11
  216. package/esm/useCopier/index.d.ts.map +0 -1
  217. package/esm/useDemo/index.d.ts.map +0 -1
@@ -0,0 +1,72 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import * as React from 'react';
3
+ import { getAvailableTransforms, createTransformedFiles } from "./useCodeUtils.js";
4
+ import { usePreference } from "../usePreference/index.js";
5
+ /**
6
+ * Hook for managing code transforms and their application
7
+ * Uses the useLocalStorage hook for local storage persistence of transform preferences
8
+ */
9
+ export function useTransformManagement(_ref) {
10
+ var context = _ref.context,
11
+ effectiveCode = _ref.effectiveCode,
12
+ selectedVariantKey = _ref.selectedVariantKey,
13
+ selectedVariant = _ref.selectedVariant,
14
+ initialTransform = _ref.initialTransform,
15
+ shouldHighlight = _ref.shouldHighlight;
16
+ // Transform state - get available transforms from context or from the effective code data
17
+ var availableTransforms = React.useMemo(function () {
18
+ // First try to get from context
19
+ if (context != null && context.availableTransforms && context.availableTransforms.length > 0) {
20
+ return context.availableTransforms;
21
+ }
22
+
23
+ // Otherwise, get from the effective code data using the utility function
24
+ return getAvailableTransforms(effectiveCode, selectedVariantKey);
25
+ }, [context == null ? void 0 : context.availableTransforms, effectiveCode, selectedVariantKey]);
26
+
27
+ // Use localStorage hook for transform persistence - this is our single source of truth
28
+ var _usePreference = usePreference('transform', availableTransforms.length === 1 ? availableTransforms[0] : availableTransforms, function () {
29
+ // Don't use initialTransform as the fallback - localStorage should always take precedence
30
+ // We'll handle the initial transform separately below
31
+ return null;
32
+ }),
33
+ _usePreference2 = _slicedToArray(_usePreference, 2),
34
+ storedValue = _usePreference2[0],
35
+ setStoredValue = _usePreference2[1];
36
+
37
+ // Handle validation manually - empty string means "no transform selected"
38
+ var selectedTransform = React.useMemo(function () {
39
+ // If we have a stored value (including empty string), use it
40
+ if (storedValue !== null) {
41
+ if (storedValue === '') {
42
+ return null;
43
+ }
44
+ // Validate the stored value
45
+ if (!availableTransforms.includes(storedValue)) {
46
+ return null;
47
+ }
48
+ return storedValue;
49
+ }
50
+
51
+ // If no stored value and we have an initial transform, use it (but don't store it yet)
52
+ if (initialTransform && availableTransforms.includes(initialTransform)) {
53
+ return initialTransform;
54
+ }
55
+ return null;
56
+ }, [storedValue, availableTransforms, initialTransform]);
57
+ var setSelectedTransformAsUser = React.useCallback(function (value) {
58
+ var valueToStore = value === null ? '' : value;
59
+ setStoredValue(valueToStore);
60
+ }, [setStoredValue]);
61
+
62
+ // Memoize all transformed files based on selectedTransform
63
+ var transformedFiles = React.useMemo(function () {
64
+ return createTransformedFiles(selectedVariant, selectedTransform, shouldHighlight);
65
+ }, [selectedVariant, selectedTransform, shouldHighlight]);
66
+ return {
67
+ availableTransforms: availableTransforms,
68
+ selectedTransform: selectedTransform,
69
+ transformedFiles: transformedFiles,
70
+ selectTransform: setSelectedTransformAsUser
71
+ };
72
+ }
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ interface UseUIStateProps {
3
+ defaultOpen?: boolean;
4
+ }
5
+ export interface UseUIStateResult {
6
+ expanded: boolean;
7
+ expand: () => void;
8
+ setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
9
+ }
10
+ /**
11
+ * Hook for managing UI state like expansion and focus
12
+ */
13
+ export declare function useUIState({
14
+ defaultOpen
15
+ }: UseUIStateProps): UseUIStateResult;
16
+ export {};
@@ -0,0 +1,21 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import * as React from 'react';
3
+ /**
4
+ * Hook for managing UI state like expansion and focus
5
+ */
6
+ export function useUIState(_ref) {
7
+ var _ref$defaultOpen = _ref.defaultOpen,
8
+ defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen;
9
+ var _React$useState = React.useState(defaultOpen),
10
+ _React$useState2 = _slicedToArray(_React$useState, 2),
11
+ expanded = _React$useState2[0],
12
+ setExpanded = _React$useState2[1];
13
+ var expand = React.useCallback(function () {
14
+ return setExpanded(true);
15
+ }, []);
16
+ return {
17
+ expanded: expanded,
18
+ expand: expand,
19
+ setExpanded: setExpanded
20
+ };
21
+ }
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ import type { Code, VariantCode } from "../CodeHighlighter/types.js";
3
+ interface UseVariantSelectionProps {
4
+ effectiveCode: Code;
5
+ initialVariant?: string;
6
+ variantType?: string;
7
+ }
8
+ export interface UseVariantSelectionResult {
9
+ variantKeys: string[];
10
+ selectedVariantKey: string;
11
+ selectedVariant: VariantCode | null;
12
+ selectVariant: React.Dispatch<React.SetStateAction<string>>;
13
+ }
14
+ /**
15
+ * Hook for managing variant selection and providing variant-related data
16
+ * Uses the useLocalStorage hook for local storage persistence of variant preferences
17
+ */
18
+ export declare function useVariantSelection({
19
+ effectiveCode,
20
+ initialVariant,
21
+ variantType
22
+ }: UseVariantSelectionProps): UseVariantSelectionResult;
23
+ export {};
@@ -0,0 +1,75 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import * as React from 'react';
4
+ import { usePreference } from "../usePreference/index.js";
5
+ /**
6
+ * Hook for managing variant selection and providing variant-related data
7
+ * Uses the useLocalStorage hook for local storage persistence of variant preferences
8
+ */
9
+ export function useVariantSelection(_ref) {
10
+ var effectiveCode = _ref.effectiveCode,
11
+ initialVariant = _ref.initialVariant,
12
+ variantType = _ref.variantType;
13
+ // Get variant keys from effective code
14
+ var variantKeys = React.useMemo(function () {
15
+ return Object.keys(effectiveCode).filter(function (key) {
16
+ var variant = effectiveCode[key];
17
+ return variant && _typeof(variant) === 'object' && 'source' in variant;
18
+ });
19
+ }, [effectiveCode]);
20
+
21
+ // Use localStorage hook for variant persistence - this is our single source of truth
22
+ var _usePreference = usePreference('variant', variantType || variantKeys, function () {
23
+ // Don't use initialVariant as the fallback - localStorage should take precedence
24
+ // We'll handle the initial variant separately in the selectedVariantKey logic
25
+ return null;
26
+ }),
27
+ _usePreference2 = _slicedToArray(_usePreference, 2),
28
+ storedValue = _usePreference2[0],
29
+ setStoredValue = _usePreference2[1];
30
+
31
+ // Handle validation manually - localStorage should take precedence over initialVariant
32
+ var selectedVariantKey = React.useMemo(function () {
33
+ // First priority: use stored value if it exists and is valid
34
+ if (storedValue && variantKeys.includes(storedValue)) {
35
+ return storedValue;
36
+ }
37
+
38
+ // Second priority: use initial variant if provided and valid (only when no localStorage value)
39
+ if (initialVariant && variantKeys.includes(initialVariant)) {
40
+ return initialVariant;
41
+ }
42
+
43
+ // Final fallback: use first available variant
44
+ return variantKeys[0] || '';
45
+ }, [storedValue, variantKeys, initialVariant]);
46
+ var setSelectedVariantKey = React.useCallback(function (value) {
47
+ setStoredValue(value);
48
+ }, [setStoredValue]);
49
+ var setSelectedVariantKeyAsUser = React.useCallback(function (value) {
50
+ var resolvedValue = typeof value === 'function' ? value(selectedVariantKey) : value;
51
+ setStoredValue(resolvedValue);
52
+ }, [setStoredValue, selectedVariantKey]);
53
+ var selectedVariant = React.useMemo(function () {
54
+ var variant = effectiveCode[selectedVariantKey];
55
+ if (variant && _typeof(variant) === 'object' && 'source' in variant) {
56
+ return variant;
57
+ }
58
+ return null;
59
+ }, [effectiveCode, selectedVariantKey]);
60
+
61
+ // Safety check: if selectedVariant doesn't exist, fall back to first variant
62
+ React.useEffect(function () {
63
+ if (!selectedVariant && variantKeys.length > 0) {
64
+ // Don't mark this as a user selection - it's just a fallback
65
+ // Use setValue instead of setValueAsUserSelection to avoid localStorage save
66
+ setSelectedVariantKey(variantKeys[0]);
67
+ }
68
+ }, [selectedVariant, variantKeys, setSelectedVariantKey]);
69
+ return {
70
+ variantKeys: variantKeys,
71
+ selectedVariantKey: selectedVariantKey,
72
+ selectedVariant: selectedVariant,
73
+ selectVariant: setSelectedVariantKeyAsUser
74
+ };
75
+ }
@@ -10,6 +10,6 @@ export type UseCopierOpts = {
10
10
  };
11
11
  export declare function useCopier(contents: (() => string | undefined) | string, opts?: UseCopierOpts): {
12
12
  copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
13
- disabled: boolean;
13
+ recentlySuccessful: boolean;
14
14
  };
15
15
  export {};
@@ -13,8 +13,8 @@ export function useCopier(contents, opts) {
13
13
  var copyTimeoutRef = React.useRef(undefined);
14
14
  var _React$useState = React.useState(false),
15
15
  _React$useState2 = _slicedToArray(_React$useState, 2),
16
- disabled = _React$useState2[0],
17
- setDisabled = _React$useState2[1];
16
+ recentlySuccessful = _React$useState2[0],
17
+ setRecentlySuccessful = _React$useState2[1];
18
18
  var copy = React.useCallback(/*#__PURE__*/function () {
19
19
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(event) {
20
20
  var content, _t;
@@ -22,7 +22,7 @@ export function useCopier(contents, opts) {
22
22
  while (1) switch (_context.p = _context.n) {
23
23
  case 0:
24
24
  clearTimeout(copyTimeoutRef.current);
25
- setDisabled(true);
25
+ setRecentlySuccessful(false);
26
26
  _context.p = 1;
27
27
  content = typeof contents === 'function' ? contents() : contents;
28
28
  if (!content) {
@@ -43,7 +43,7 @@ export function useCopier(contents, opts) {
43
43
  onClick == null || onClick(event);
44
44
  copyTimeoutRef.current = setTimeout(function () {
45
45
  clearTimeout(copyTimeoutRef.current);
46
- setDisabled(false);
46
+ setRecentlySuccessful(false);
47
47
  }, timeout);
48
48
  case 5:
49
49
  return _context.a(2);
@@ -56,6 +56,6 @@ export function useCopier(contents, opts) {
56
56
  }(), [contents, timeout, onCopied, onError, onClick]);
57
57
  return {
58
58
  copy: copy,
59
- disabled: disabled
59
+ recentlySuccessful: recentlySuccessful
60
60
  };
61
61
  }
@@ -0,0 +1,15 @@
1
+ import type { FlattenedFiles } from "./flattenVariant.js";
2
+ /**
3
+ * Utility function for creating CodeSandbox demos
4
+ * Returns the configuration that can be used with openWithForm
5
+ */
6
+ export declare function createCodeSandbox({
7
+ flattenedFiles,
8
+ rootFile
9
+ }: {
10
+ flattenedFiles: FlattenedFiles;
11
+ rootFile: string;
12
+ }): {
13
+ url: string;
14
+ formData: Record<string, string>;
15
+ };
@@ -0,0 +1,42 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import LZString from 'lz-string';
3
+ /**
4
+ * Compress object for CodeSandbox API
5
+ */
6
+ function compress(object) {
7
+ return LZString.compressToBase64(JSON.stringify(object)).replace(/\+/g, '-') // Convert '+' to '-'
8
+ .replace(/\//g, '_') // Convert '/' to '_'
9
+ .replace(/=+$/, ''); // Remove ending '='
10
+ }
11
+
12
+ /**
13
+ * Utility function for creating CodeSandbox demos
14
+ * Returns the configuration that can be used with openWithForm
15
+ */
16
+ export function createCodeSandbox(_ref) {
17
+ var flattenedFiles = _ref.flattenedFiles,
18
+ rootFile = _ref.rootFile;
19
+ // Convert flattened files to string format
20
+ var files = {};
21
+ Object.entries(flattenedFiles).forEach(function (_ref2) {
22
+ var _ref3 = _slicedToArray(_ref2, 2),
23
+ filePath = _ref3[0],
24
+ fileData = _ref3[1];
25
+ files[filePath] = {
26
+ content: fileData.source
27
+ };
28
+ });
29
+ var parameters = compress({
30
+ files: files
31
+ });
32
+
33
+ // ref: https://codesandbox.io/docs/learn/browser-sandboxes/cli-api#supported-parameters
34
+ var formData = {
35
+ parameters: parameters,
36
+ query: "file=".concat(rootFile)
37
+ };
38
+ return {
39
+ url: 'https://codesandbox.io/api/v1/sandboxes/define',
40
+ formData: formData
41
+ };
42
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Utility function for creating StackBlitz demos
3
+ * Returns the configuration that can be used with openWithForm
4
+ */
5
+ import type { FlattenedFiles } from "./flattenVariant.js";
6
+ /**
7
+ * Create StackBlitz configuration for use with openWithForm
8
+ */
9
+ export declare function createStackBlitz({
10
+ title,
11
+ description,
12
+ flattenedFiles,
13
+ rootFile
14
+ }: {
15
+ title: string;
16
+ description: string;
17
+ flattenedFiles: FlattenedFiles;
18
+ rootFile: string;
19
+ }): {
20
+ url: string;
21
+ formData: Record<string, string>;
22
+ };
@@ -0,0 +1,38 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ /**
3
+ * Utility function for creating StackBlitz demos
4
+ * Returns the configuration that can be used with openWithForm
5
+ */
6
+
7
+ /**
8
+ * Create StackBlitz configuration for use with openWithForm
9
+ */
10
+ export function createStackBlitz(_ref) {
11
+ var title = _ref.title,
12
+ description = _ref.description,
13
+ flattenedFiles = _ref.flattenedFiles,
14
+ rootFile = _ref.rootFile;
15
+ // Convert flattened files to string format
16
+ var files = {};
17
+ Object.entries(flattenedFiles).forEach(function (_ref2) {
18
+ var _ref3 = _slicedToArray(_ref2, 2),
19
+ filePath = _ref3[0],
20
+ fileData = _ref3[1];
21
+ files[filePath] = fileData.source;
22
+ });
23
+ var formData = {
24
+ 'project[template]': 'node',
25
+ 'project[title]': title,
26
+ 'project[description]': "# ".concat(title, "\n").concat(description)
27
+ };
28
+ Object.entries(files).forEach(function (_ref4) {
29
+ var _ref5 = _slicedToArray(_ref4, 2),
30
+ key = _ref5[0],
31
+ value = _ref5[1];
32
+ formData["project[files][".concat(key, "]")] = value;
33
+ });
34
+ return {
35
+ url: "https://stackblitz.com/run?file=".concat(rootFile),
36
+ formData: formData
37
+ };
38
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Export variant functionality to add extra files like package.json, tsconfig, etc.
3
+ * Users can pass configuration options that vary the output here.
4
+ */
5
+ import type { VariantCode, VariantExtraFiles } from "../CodeHighlighter/types.js";
6
+ /**
7
+ * Extract filename from URL or return undefined if not available
8
+ */
9
+ export declare function getFilenameFromVariant(variantCode: VariantCode): string | undefined;
10
+ /**
11
+ * Generate a unique entrypoint filename that doesn't conflict with existing files
12
+ */
13
+ export declare function generateEntrypointFilename(existingFiles: VariantExtraFiles, sourceFilename: string | undefined, useTypescript: boolean, pathPrefix?: string): string;
14
+ /**
15
+ * Generate the relative import path from entrypoint to source file
16
+ */
17
+ export declare function getRelativeImportPath(sourceFilename: string | undefined): string;
18
+ /**
19
+ * Default HTML template function for Vite-based demos
20
+ */
21
+ export declare function defaultHtmlTemplate({
22
+ language,
23
+ title,
24
+ description,
25
+ head,
26
+ entrypoint
27
+ }: {
28
+ language: string;
29
+ title: string;
30
+ description: string;
31
+ head?: string;
32
+ entrypoint?: string;
33
+ }): string;
34
+ export interface ExportConfig {
35
+ /** The title for the demo (used in HTML title and package.json name) */
36
+ title?: string;
37
+ /** Optional prefix to add before the title */
38
+ titlePrefix?: string;
39
+ /** Optional suffix to add after the title */
40
+ titleSuffix?: string;
41
+ /** Description for package.json */
42
+ description?: string;
43
+ /** Optional prefix to add before the description */
44
+ descriptionPrefix?: string;
45
+ /** Optional suffix to add after the description */
46
+ descriptionSuffix?: string;
47
+ /** The variant name/identifier for this specific code variant */
48
+ variantName?: string;
49
+ /**
50
+ * Language for the HTML document (default is 'en')
51
+ */
52
+ language?: string;
53
+ /**
54
+ * Prefix for output file paths (e.g., 'public/' for CRA, '' for Vite)
55
+ * @example
56
+ * htmlPrefix: 'public/' // outputs index.html to correct depth + public/index.html
57
+ */
58
+ htmlPrefix?: string;
59
+ /**
60
+ * Prefix for asset files (e.g., 'assets/' for CRA)
61
+ */
62
+ assetPrefix?: string;
63
+ /**
64
+ * Prefix for code files (e.g., 'src/' for Vite)
65
+ */
66
+ sourcePrefix?: string;
67
+ /**
68
+ * Custom HTML template function
69
+ * @example
70
+ * htmlTemplate: ({ language, title, description, head, entrypoint, variant, variantName }) =>
71
+ * `<!doctype html><html><head><title>${title}</title>${head || ''}</head><body><div id="root"></div><script src="${entrypoint}"></script></body></html>`
72
+ */
73
+ htmlTemplate?: (params: {
74
+ language: string;
75
+ title: string;
76
+ description: string;
77
+ head?: string;
78
+ entrypoint?: string;
79
+ variant?: VariantCode;
80
+ variantName?: string;
81
+ }) => string;
82
+ /**
83
+ * Custom head template function for generating additional head content
84
+ * @example
85
+ * headTemplate: ({ sourcePrefix, assetPrefix, variant, variantName }) =>
86
+ * `<link rel="stylesheet" href="${assetPrefix}/styles.css" />\n<meta name="theme-color" content="#000000" />`
87
+ */
88
+ headTemplate?: (params: {
89
+ sourcePrefix: string;
90
+ assetPrefix: string;
91
+ variant?: VariantCode;
92
+ variantName?: string;
93
+ }) => string;
94
+ /** Custom React root index template function */
95
+ rootIndexTemplate?: (params: {
96
+ importString: string;
97
+ useTypescript: boolean;
98
+ }) => string;
99
+ /** Extra package.json dependencies to add */
100
+ dependencies?: Record<string, string>;
101
+ /** Extra package.json devDependencies to add */
102
+ devDependencies?: Record<string, string>;
103
+ /** Extra package.json scripts to add */
104
+ scripts?: Record<string, string>;
105
+ /** Package type: 'module' for ESM, 'commonjs' for CJS, undefined to omit */
106
+ packageType?: 'module' | 'commonjs';
107
+ /** Custom package.json fields to merge */
108
+ packageJsonFields?: Record<string, any>;
109
+ /** Extra tsconfig.json options to merge */
110
+ tsconfigOptions?: Record<string, any>;
111
+ /** Vite configuration options */
112
+ viteConfig?: Record<string, any>;
113
+ /** Whether to include TypeScript configuration files */
114
+ useTypescript?: boolean;
115
+ /** Custom metadata files to add */
116
+ extraMetadataFiles?: Record<string, {
117
+ source: string;
118
+ }>;
119
+ /**
120
+ * Whether the framework handles entrypoint and HTML generation (e.g., CRA with webpack)
121
+ * When true, skips generating index.html and entrypoint files
122
+ */
123
+ frameworkHandlesEntrypoint?: boolean;
124
+ /**
125
+ * Whether to skip adding the JavaScript link in the HTML
126
+ */
127
+ htmlSkipJsLink?: boolean;
128
+ /** Framework-specific files that override default files (index.html, entrypoint, etc.) */
129
+ frameworkFiles?: {
130
+ variant?: VariantCode;
131
+ globals?: VariantExtraFiles;
132
+ };
133
+ /**
134
+ * Custom export function to use instead of the default exportVariant or exportVariantAsCra
135
+ * @example
136
+ * exportFunction: (variantCode, config) => ({ exported: customProcessedCode, rootFile: 'custom-entry.js' })
137
+ */
138
+ exportFunction?: (variantCode: VariantCode, config: ExportConfig) => {
139
+ exported: VariantCode;
140
+ rootFile: string;
141
+ };
142
+ /**
143
+ * Transform function that runs at the very start of the export process
144
+ * Can modify the variant code and metadata before any other processing happens
145
+ * @example
146
+ * transformVariant: (variant, globals, variantName) => ({
147
+ * variant: { ...variant, source: modifiedSource },
148
+ * globals: { ...globals, extraFiles: { ...globals.extraFiles, 'theme.css': { source: '.new {}', metadata: true } } }
149
+ * })
150
+ */
151
+ transformVariant?: (variant: VariantCode, variantName?: string, globals?: VariantExtraFiles) => {
152
+ variant?: VariantCode;
153
+ globals?: VariantExtraFiles;
154
+ } | undefined;
155
+ /**
156
+ * Version overrides for core packages (react, react-dom, @types/react, @types/react-dom)
157
+ * @example
158
+ * versions: {
159
+ * '@types/react': '^19',
160
+ * '@types/react-dom': '^19',
161
+ * react: '^19',
162
+ * 'react-dom': '^19',
163
+ * }
164
+ */
165
+ versions?: Record<string, string>;
166
+ /**
167
+ * Custom dependency resolution function
168
+ * @example
169
+ * resolveDependencies: (packageName, envVars) => {
170
+ * if (packageName === '@mui/material') {
171
+ * return { '@mui/material': 'latest', '@emotion/react': 'latest' };
172
+ * }
173
+ * return { [packageName]: 'latest' };
174
+ * }
175
+ */
176
+ resolveDependencies?: (packageName: string, envVars?: Record<string, string>) => Record<string, string>;
177
+ }
178
+ /**
179
+ * Export a variant as a standalone project with metadata files properly scoped
180
+ */
181
+ export declare function exportVariant(variantCode: VariantCode, config?: ExportConfig): {
182
+ exported: VariantCode;
183
+ rootFile: string;
184
+ };