@mui/internal-docs-infra 0.1.1-canary.9 → 0.2.0-alpha.2

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,31 @@
1
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import { removeTypes } from "./removeTypes.js";
4
+ export var transformTypescriptToJavascript = /*#__PURE__*/function () {
5
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(source, fileName) {
6
+ var transformed, transformedFileName;
7
+ return _regenerator().w(function (_context) {
8
+ while (1) switch (_context.n) {
9
+ case 0:
10
+ _context.n = 1;
11
+ return removeTypes(source, fileName);
12
+ case 1:
13
+ transformed = _context.v;
14
+ transformedFileName = fileName.replace(/\.ts$/, '.js').replace(/\.tsx$/, '.jsx');
15
+ return _context.a(2, {
16
+ js: {
17
+ source: transformed,
18
+ fileName: transformedFileName
19
+ }
20
+ });
21
+ }
22
+ }, _callee);
23
+ }));
24
+ return function transformTypescriptToJavascript(_x, _x2) {
25
+ return _ref.apply(this, arguments);
26
+ };
27
+ }();
28
+ export var TypescriptToJavascriptTransformer = {
29
+ extensions: ['ts', 'tsx'],
30
+ transformer: transformTypescriptToJavascript
31
+ };
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import type { VariantSource } from "../CodeHighlighter/types.js";
3
+ export declare function Pre({
4
+ children,
5
+ className,
6
+ ref,
7
+ shouldHighlight,
8
+ hydrateMargin
9
+ }: {
10
+ children: VariantSource;
11
+ className?: string;
12
+ ref?: React.Ref<HTMLPreElement>;
13
+ shouldHighlight?: boolean;
14
+ hydrateMargin?: string;
15
+ }): React.ReactNode;
@@ -0,0 +1,164 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import * as React from 'react';
7
+ import { toText } from 'hast-util-to-text';
8
+ import { hastToJsx } from "../pipeline/hastUtils/index.js";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ export function Pre(_ref) {
11
+ var children = _ref.children,
12
+ className = _ref.className,
13
+ ref = _ref.ref,
14
+ shouldHighlight = _ref.shouldHighlight,
15
+ _ref$hydrateMargin = _ref.hydrateMargin,
16
+ hydrateMargin = _ref$hydrateMargin === void 0 ? '200px 0px 200px 0px' : _ref$hydrateMargin;
17
+ var hast = React.useMemo(function () {
18
+ if (typeof children === 'string') {
19
+ return null;
20
+ }
21
+ if ('hastJson' in children) {
22
+ return JSON.parse(children.hastJson);
23
+ }
24
+ return children;
25
+ }, [children]);
26
+ var _React$useState = React.useState(_defineProperty({}, 0, true)),
27
+ _React$useState2 = _slicedToArray(_React$useState, 2),
28
+ visibleFrames = _React$useState2[0],
29
+ setVisibleFrames = _React$useState2[1];
30
+ var observer = React.useRef(null);
31
+ var bindIntersectionObserver = React.useCallback(function (root) {
32
+ if (!root) {
33
+ if (observer.current) {
34
+ observer.current.disconnect();
35
+ }
36
+ observer.current = null;
37
+ return;
38
+ }
39
+ observer.current = new IntersectionObserver(function (entries) {
40
+ return setVisibleFrames(function (prev) {
41
+ var visible = [];
42
+ var invisible = [];
43
+ entries.forEach(function (entry) {
44
+ if (entry.isIntersecting) {
45
+ visible.push(Number(entry.target.getAttribute('data-frame')));
46
+ } else {
47
+ invisible.push(Number(entry.target.getAttribute('data-frame')));
48
+ }
49
+ });
50
+
51
+ // avoid mutating the object if nothing changed
52
+ var frames;
53
+ visible.forEach(function (frame) {
54
+ if (prev[frame] !== true) {
55
+ if (!frames) {
56
+ frames = _extends({}, prev);
57
+ }
58
+ frames[frame] = true;
59
+ }
60
+ });
61
+ invisible.forEach(function (frame) {
62
+ if (prev[frame]) {
63
+ if (!frames) {
64
+ frames = _extends({}, prev);
65
+ }
66
+ delete frames[frame];
67
+ }
68
+ });
69
+ return frames || prev;
70
+ });
71
+ }, {
72
+ rootMargin: hydrateMargin
73
+ });
74
+ root.childNodes.forEach(function (node) {
75
+ if (node.nodeType === Node.ELEMENT_NODE) {
76
+ var _observer$current;
77
+ var element = node;
78
+ (_observer$current = observer.current) == null || _observer$current.observe(element);
79
+ }
80
+ });
81
+ if (ref) {
82
+ if (typeof ref === 'function') {
83
+ ref(root);
84
+ } else {
85
+ ref.current = root;
86
+ }
87
+ }
88
+ }, [ref, hydrateMargin]);
89
+ var observeFrame = React.useCallback(function (node) {
90
+ if (observer.current && node) {
91
+ observer.current.observe(node);
92
+ }
93
+ }, []);
94
+ var hastChildrenCache = React.useMemo(function () {
95
+ return hast == null ? void 0 : hast.children.map(function () {
96
+ return null;
97
+ });
98
+ }, [hast]);
99
+ var textChildrenCache = React.useMemo(function () {
100
+ return hast == null ? void 0 : hast.children.map(function () {
101
+ return null;
102
+ });
103
+ }, [hast]);
104
+ var renderCode = React.useCallback(function (index, hastChildren, renderHast, text) {
105
+ if (renderHast) {
106
+ var _cached = hastChildrenCache == null ? void 0 : hastChildrenCache[index];
107
+ if (_cached) {
108
+ return _cached;
109
+ }
110
+ var jsx = hastToJsx({
111
+ type: 'root',
112
+ children: hastChildren
113
+ });
114
+ if (hastChildrenCache) {
115
+ hastChildrenCache[index] = jsx;
116
+ }
117
+ return jsx;
118
+ }
119
+ if (text !== undefined) {
120
+ return text;
121
+ }
122
+ var cached = textChildrenCache == null ? void 0 : textChildrenCache[index];
123
+ if (cached) {
124
+ return cached;
125
+ }
126
+ var txt = toText({
127
+ type: 'root',
128
+ children: hastChildren
129
+ }, {
130
+ whitespace: 'pre'
131
+ });
132
+ if (textChildrenCache) {
133
+ textChildrenCache[index] = txt;
134
+ }
135
+ return txt;
136
+ }, [hastChildrenCache, textChildrenCache]);
137
+ var frames = React.useMemo(function () {
138
+ return hast == null ? void 0 : hast.children.map(function (child, index) {
139
+ if (child.type !== 'element') {
140
+ return null;
141
+ }
142
+ if (child.properties.className === 'frame') {
143
+ var _child$properties, _child$properties2;
144
+ var isVisible = Boolean(visibleFrames[index]);
145
+ return /*#__PURE__*/_jsx("span", {
146
+ className: "frame",
147
+ "data-frame": index,
148
+ ref: observeFrame,
149
+ children: renderCode(index, child.children, shouldHighlight && isVisible, (_child$properties = child.properties) != null && _child$properties.dataAsString ? String((_child$properties2 = child.properties) == null ? void 0 : _child$properties2.dataAsString) : undefined)
150
+ }, index);
151
+ }
152
+ return /*#__PURE__*/_jsx(React.Fragment, {
153
+ children: shouldHighlight ? hastToJsx(child) : toText(child, {
154
+ whitespace: 'pre'
155
+ })
156
+ }, index);
157
+ });
158
+ }, [hast, renderCode, observeFrame, shouldHighlight, visibleFrames]);
159
+ return /*#__PURE__*/_jsx("pre", {
160
+ ref: bindIntersectionObserver,
161
+ className: className,
162
+ children: typeof children === 'string' ? children : frames
163
+ });
164
+ }
@@ -0,0 +1 @@
1
+ export * from "./useCode.js";
@@ -0,0 +1 @@
1
+ export * from "./useCode.js";
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ import type { ContentProps } from "../CodeHighlighter/types.js";
3
+ import { UseCopierOpts } from "../useCopier/index.js";
4
+ export type UseCodeOpts = {
5
+ preClassName?: string;
6
+ preRef?: React.Ref<HTMLPreElement>;
7
+ defaultOpen?: boolean;
8
+ copy?: UseCopierOpts;
9
+ githubUrlPrefix?: string;
10
+ initialVariant?: string;
11
+ initialTransform?: string;
12
+ };
13
+ type UserProps<T extends {} = {}> = T & {
14
+ name?: string;
15
+ slug?: string;
16
+ };
17
+ export interface UseCodeResult<T extends {} = {}> {
18
+ variants: string[];
19
+ selectedVariant: string;
20
+ selectVariant: React.Dispatch<React.SetStateAction<string>>;
21
+ files: Array<{
22
+ name: string;
23
+ slug?: string;
24
+ component: React.ReactNode;
25
+ }>;
26
+ selectedFile: React.ReactNode;
27
+ selectedFileLines: number;
28
+ selectedFileName: string | undefined;
29
+ selectFileName: (fileName: string) => void;
30
+ expanded: boolean;
31
+ expand: () => void;
32
+ setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
33
+ copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
34
+ availableTransforms: string[];
35
+ selectedTransform: string | null | undefined;
36
+ selectTransform: (transformName: string | null) => void;
37
+ setSource?: (source: string) => void;
38
+ userProps: UserProps<T>;
39
+ }
40
+ export declare function useCode<T extends {} = {}>(contentProps: ContentProps<T>, opts?: UseCodeOpts): UseCodeResult<T>;
41
+ export {};
@@ -0,0 +1,128 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ var _excluded = ["name", "slug", "code", "components", "url"];
4
+ import * as React from 'react';
5
+ import { useCodeHighlighterContextOptional } from "../CodeHighlighter/CodeHighlighterContext.js";
6
+ import { extractNameAndSlugFromUrl } from "../pipeline/loaderUtils/index.js";
7
+ import { useVariantSelection } from "./useVariantSelection.js";
8
+ import { useTransformManagement } from "./useTransformManagement.js";
9
+ import { useFileNavigation } from "./useFileNavigation.js";
10
+ import { useUIState } from "./useUIState.js";
11
+ import { useCopyFunctionality } from "./useCopyFunctionality.js";
12
+ import { useSourceEditing } from "./useSourceEditing.js";
13
+ export function useCode(contentProps, opts) {
14
+ var _ref = opts || {},
15
+ copyOpts = _ref.copy,
16
+ _ref$defaultOpen = _ref.defaultOpen,
17
+ defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
18
+ initialVariant = _ref.initialVariant,
19
+ initialTransform = _ref.initialTransform,
20
+ preClassName = _ref.preClassName,
21
+ preRef = _ref.preRef;
22
+
23
+ // Safely try to get context values - will be undefined if not in context
24
+ var context = useCodeHighlighterContextOptional();
25
+
26
+ // Get the effective code - context overrides contentProps if available
27
+ var effectiveCode = React.useMemo(function () {
28
+ return (context == null ? void 0 : context.code) || contentProps.code || {};
29
+ }, [context == null ? void 0 : context.code, contentProps.code]);
30
+ var shouldHighlight = !(context != null && context.deferHighlight);
31
+
32
+ // Memoize userProps with auto-generated name and slug if missing
33
+ var userProps = React.useMemo(function () {
34
+ // Extract only the user-defined properties (T) from contentProps
35
+ var contentName = contentProps.name,
36
+ contentSlug = contentProps.slug,
37
+ code = contentProps.code,
38
+ components = contentProps.components,
39
+ contentUrl = contentProps.url,
40
+ userDefinedProps = _objectWithoutPropertiesLoose(contentProps, _excluded);
41
+ // Get URL from context first, then fall back to contentProps
42
+ var effectiveUrl = (context == null ? void 0 : context.url) || contentUrl;
43
+ var name = contentName;
44
+ var slug = contentSlug;
45
+ // Generate name and slug from URL if they're missing and we have a URL
46
+ if ((!name || !slug) && effectiveUrl) {
47
+ try {
48
+ var generated = extractNameAndSlugFromUrl(effectiveUrl);
49
+ name = name || generated.name;
50
+ slug = slug || generated.slug;
51
+ } catch (_unused) {
52
+ // If URL parsing fails, keep the original values (which might be undefined)
53
+ }
54
+ }
55
+ return _extends(_extends({}, userDefinedProps), {}, {
56
+ name: name,
57
+ slug: slug
58
+ });
59
+ }, [contentProps, context == null ? void 0 : context.url]);
60
+
61
+ // Sub-hook: UI State Management
62
+ var uiState = useUIState({
63
+ defaultOpen: defaultOpen
64
+ });
65
+
66
+ // Sub-hook: Variant Selection
67
+ var variantSelection = useVariantSelection({
68
+ effectiveCode: effectiveCode,
69
+ initialVariant: initialVariant,
70
+ variantType: contentProps.variantType
71
+ });
72
+
73
+ // Sub-hook: Transform Management
74
+ var transformManagement = useTransformManagement({
75
+ context: context,
76
+ effectiveCode: effectiveCode,
77
+ selectedVariantKey: variantSelection.selectedVariantKey,
78
+ selectedVariant: variantSelection.selectedVariant,
79
+ initialTransform: initialTransform,
80
+ shouldHighlight: shouldHighlight
81
+ });
82
+
83
+ // Sub-hook: File Navigation
84
+ var fileNavigation = useFileNavigation({
85
+ selectedVariant: variantSelection.selectedVariant,
86
+ transformedFiles: transformManagement.transformedFiles,
87
+ mainSlug: userProps.slug,
88
+ selectedVariantKey: variantSelection.selectedVariantKey,
89
+ variantKeys: variantSelection.variantKeys,
90
+ initialVariant: initialVariant,
91
+ shouldHighlight: shouldHighlight,
92
+ preClassName: preClassName,
93
+ preRef: preRef
94
+ });
95
+
96
+ // Sub-hook: Copy Functionality
97
+ var copyFunctionality = useCopyFunctionality({
98
+ selectedFile: fileNavigation.selectedFile,
99
+ copyOpts: copyOpts
100
+ });
101
+
102
+ // Sub-hook: Source Editing
103
+ var sourceEditing = useSourceEditing({
104
+ context: context,
105
+ selectedVariantKey: variantSelection.selectedVariantKey,
106
+ effectiveCode: effectiveCode,
107
+ selectedVariant: variantSelection.selectedVariant
108
+ });
109
+ return {
110
+ variants: variantSelection.variantKeys,
111
+ selectedVariant: variantSelection.selectedVariantKey,
112
+ selectVariant: variantSelection.selectVariant,
113
+ files: fileNavigation.files,
114
+ selectedFile: fileNavigation.selectedFileComponent,
115
+ selectedFileLines: fileNavigation.selectedFileLines,
116
+ selectedFileName: fileNavigation.selectedFileName,
117
+ selectFileName: fileNavigation.selectFileName,
118
+ expanded: uiState.expanded,
119
+ expand: uiState.expand,
120
+ setExpanded: uiState.setExpanded,
121
+ copy: copyFunctionality.copy,
122
+ availableTransforms: transformManagement.availableTransforms,
123
+ selectedTransform: transformManagement.selectedTransform,
124
+ selectTransform: transformManagement.selectTransform,
125
+ setSource: sourceEditing.setSource,
126
+ userProps: userProps
127
+ };
128
+ }
@@ -0,0 +1,44 @@
1
+ import type { VariantSource, VariantCode, Code, Transforms } from "../CodeHighlighter/types.js";
2
+ interface TransformedFile {
3
+ name: string;
4
+ originalName: string;
5
+ source: VariantSource;
6
+ component: React.ReactNode;
7
+ }
8
+ export interface TransformedFiles {
9
+ files: TransformedFile[];
10
+ filenameMap: {
11
+ [originalName: string]: string;
12
+ };
13
+ }
14
+ /**
15
+ * Pure function to get available transforms from effective code data.
16
+ * Only includes transforms that have actual deltas (file changes), not just filename changes.
17
+ *
18
+ * @param effectiveCode - The effective code object containing all variants
19
+ * @param selectedVariantKey - The currently selected variant key
20
+ * @returns Array of available transform keys that have deltas
21
+ */
22
+ export declare function getAvailableTransforms(effectiveCode: Code, selectedVariantKey: string): string[];
23
+ /**
24
+ * Pure helper function to apply transform to a source file.
25
+ *
26
+ * @param source - The source code to transform
27
+ * @param fileName - The filename for the source
28
+ * @param transforms - Available transforms for this source
29
+ * @param selectedTransform - The transform to apply
30
+ * @returns Object with transformed source and name
31
+ */
32
+ export declare function applyTransformToSource(source: VariantSource, fileName: string, transforms: Transforms | undefined, selectedTransform: string): {
33
+ transformedSource: VariantSource;
34
+ transformedName: string;
35
+ };
36
+ /**
37
+ * Pure function to create transformed files from a variant and selected transform.
38
+ *
39
+ * @param selectedVariant - The currently selected variant
40
+ * @param selectedTransform - The transform to apply
41
+ * @returns Object with transformed files and filename mapping, or undefined if no transform
42
+ */
43
+ export declare function createTransformedFiles(selectedVariant: VariantCode | null, selectedTransform: string | null, shouldHighlight: boolean): TransformedFiles | undefined;
44
+ export {};
@@ -0,0 +1,245 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import { stringOrHastToJsx } from "../pipeline/hastUtils/index.js";
4
+ import { applyTransform } from "../CodeHighlighter/applyTransform.js";
5
+ /**
6
+ * Pure function to get available transforms from effective code data.
7
+ * Only includes transforms that have actual deltas (file changes), not just filename changes.
8
+ *
9
+ * @param effectiveCode - The effective code object containing all variants
10
+ * @param selectedVariantKey - The currently selected variant key
11
+ * @returns Array of available transform keys that have deltas
12
+ */
13
+ export function getAvailableTransforms(effectiveCode, selectedVariantKey) {
14
+ var transforms = new Set();
15
+ if (effectiveCode && selectedVariantKey) {
16
+ var variantCode = effectiveCode[selectedVariantKey];
17
+ if (variantCode && _typeof(variantCode) === 'object') {
18
+ // Check main variant transforms
19
+ if ('transforms' in variantCode && variantCode.transforms) {
20
+ Object.keys(variantCode.transforms).forEach(function (transformKey) {
21
+ var transformData = variantCode.transforms[transformKey];
22
+ // Only include transforms that have actual deltas (file changes)
23
+ // Check if delta exists and is not empty
24
+ if (transformData && _typeof(transformData) === 'object' && 'delta' in transformData) {
25
+ var delta = transformData.delta;
26
+ // Check if delta has meaningful content (not just an empty object)
27
+ var hasContent = delta && _typeof(delta) === 'object' && Object.keys(delta).length > 0;
28
+ if (hasContent) {
29
+ transforms.add(transformKey);
30
+ }
31
+ }
32
+ });
33
+ }
34
+
35
+ // Check extraFiles for transforms with deltas
36
+ if ('extraFiles' in variantCode && variantCode.extraFiles) {
37
+ Object.values(variantCode.extraFiles).forEach(function (fileData) {
38
+ if (fileData && _typeof(fileData) === 'object' && 'transforms' in fileData && fileData.transforms) {
39
+ Object.keys(fileData.transforms).forEach(function (transformKey) {
40
+ var transformData = fileData.transforms[transformKey];
41
+ // Only include transforms that have actual deltas (file changes)
42
+ // Check if delta exists and is not empty
43
+ if (transformData && _typeof(transformData) === 'object' && 'delta' in transformData) {
44
+ var delta = transformData.delta;
45
+ // Check if delta has meaningful content (not just an empty object)
46
+ var hasContent = delta && _typeof(delta) === 'object' && Object.keys(delta).length > 0;
47
+ if (hasContent) {
48
+ transforms.add(transformKey);
49
+ }
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
55
+ }
56
+ }
57
+ return Array.from(transforms);
58
+ }
59
+
60
+ /**
61
+ * Pure helper function to apply transform to a source file.
62
+ *
63
+ * @param source - The source code to transform
64
+ * @param fileName - The filename for the source
65
+ * @param transforms - Available transforms for this source
66
+ * @param selectedTransform - The transform to apply
67
+ * @returns Object with transformed source and name
68
+ */
69
+ export function applyTransformToSource(source, fileName, transforms, selectedTransform) {
70
+ if (!(transforms != null && transforms[selectedTransform])) {
71
+ return {
72
+ transformedSource: source,
73
+ transformedName: fileName
74
+ };
75
+ }
76
+ try {
77
+ // Get transform data
78
+ var transformData = transforms[selectedTransform];
79
+ if (!transformData || _typeof(transformData) !== 'object' || !('delta' in transformData)) {
80
+ return {
81
+ transformedSource: source,
82
+ transformedName: fileName
83
+ };
84
+ }
85
+
86
+ // Check if delta has meaningful content
87
+ var delta = transformData.delta;
88
+ var hasContent = delta && _typeof(delta) === 'object' && Object.keys(delta).length > 0;
89
+ if (!hasContent) {
90
+ return {
91
+ transformedSource: source,
92
+ transformedName: fileName
93
+ };
94
+ }
95
+
96
+ // Apply transform
97
+ var result = applyTransform(source, transforms, selectedTransform);
98
+ var transformedName = transformData.fileName || fileName;
99
+ return {
100
+ transformedSource: result,
101
+ transformedName: transformedName
102
+ };
103
+ } catch (error) {
104
+ console.error("Transform failed for ".concat(fileName, ":"), error);
105
+ return {
106
+ transformedSource: source,
107
+ transformedName: fileName
108
+ };
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Pure function to create transformed files from a variant and selected transform.
114
+ *
115
+ * @param selectedVariant - The currently selected variant
116
+ * @param selectedTransform - The transform to apply
117
+ * @returns Object with transformed files and filename mapping, or undefined if no transform
118
+ */
119
+ export function createTransformedFiles(selectedVariant, selectedTransform, shouldHighlight) {
120
+ var _variantTransforms$se;
121
+ // Only create transformed files when there's actually a transform selected
122
+ if (!selectedVariant || !selectedTransform) {
123
+ return undefined;
124
+ }
125
+ var files = [];
126
+ var filenameMap = {};
127
+
128
+ // First, check if any file has a meaningful transform delta for the selected transform
129
+ var variantTransforms = 'transforms' in selectedVariant ? selectedVariant.transforms : undefined;
130
+ var hasAnyMeaningfulTransform = false;
131
+
132
+ // Check main file for meaningful transform
133
+ if (selectedVariant.fileName && variantTransforms != null && (_variantTransforms$se = variantTransforms[selectedTransform]) != null && _variantTransforms$se.delta) {
134
+ var delta = variantTransforms[selectedTransform].delta;
135
+ if (delta && Object.keys(delta).length > 0) {
136
+ hasAnyMeaningfulTransform = true;
137
+ }
138
+ }
139
+
140
+ // Check extraFiles for meaningful transforms
141
+ if (!hasAnyMeaningfulTransform && selectedVariant.extraFiles) {
142
+ Object.values(selectedVariant.extraFiles).forEach(function (fileData) {
143
+ if (fileData && _typeof(fileData) === 'object' && 'transforms' in fileData) {
144
+ var _fileData$transforms;
145
+ var transformData = (_fileData$transforms = fileData.transforms) == null ? void 0 : _fileData$transforms[selectedTransform];
146
+ if (transformData != null && transformData.delta && Object.keys(transformData.delta).length > 0) {
147
+ hasAnyMeaningfulTransform = true;
148
+ }
149
+ }
150
+ });
151
+ }
152
+
153
+ // If no file has a meaningful transform, return empty result
154
+ if (!hasAnyMeaningfulTransform) {
155
+ return {
156
+ files: [],
157
+ filenameMap: {}
158
+ };
159
+ }
160
+
161
+ // Process main file if we have a fileName and source
162
+ if (selectedVariant.fileName && selectedVariant.source) {
163
+ var _applyTransformToSour = applyTransformToSource(selectedVariant.source, selectedVariant.fileName, variantTransforms, selectedTransform),
164
+ mainSource = _applyTransformToSour.transformedSource,
165
+ mainName = _applyTransformToSour.transformedName;
166
+ var fileName = selectedVariant.fileName;
167
+ filenameMap[fileName] = mainName;
168
+ files.push({
169
+ name: mainName,
170
+ originalName: fileName,
171
+ source: mainSource,
172
+ component: stringOrHastToJsx(mainSource, shouldHighlight)
173
+ });
174
+ }
175
+
176
+ // Process extra files
177
+ if (selectedVariant.extraFiles) {
178
+ Object.entries(selectedVariant.extraFiles).forEach(function (_ref) {
179
+ var _transforms;
180
+ var _ref2 = _slicedToArray(_ref, 2),
181
+ extraFileName = _ref2[0],
182
+ fileData = _ref2[1];
183
+ var source;
184
+ var transforms;
185
+
186
+ // Handle different extraFile structures
187
+ if (typeof fileData === 'string') {
188
+ source = fileData;
189
+ transforms = undefined; // Don't inherit variant transforms for simple string files
190
+ } else if (fileData && _typeof(fileData) === 'object' && 'source' in fileData) {
191
+ source = fileData.source;
192
+ transforms = fileData.transforms; // Only use explicit transforms for this file
193
+ } else {
194
+ return; // Skip invalid entries
195
+ }
196
+
197
+ // Skip if source is undefined
198
+ if (!source) {
199
+ return;
200
+ }
201
+
202
+ // Apply transforms if available, otherwise use original source
203
+ var transformedSource = source;
204
+ var transformedName = extraFileName;
205
+ if ((_transforms = transforms) != null && _transforms[selectedTransform]) {
206
+ try {
207
+ var transformData = transforms[selectedTransform];
208
+ if (transformData && _typeof(transformData) === 'object' && 'delta' in transformData) {
209
+ // Only apply transform if there's a meaningful delta
210
+ var hasTransformDelta = transformData.delta && Object.keys(transformData.delta).length > 0;
211
+ if (hasTransformDelta) {
212
+ transformedSource = applyTransform(source, transforms, selectedTransform);
213
+ transformedName = transformData.fileName || extraFileName;
214
+ }
215
+ }
216
+ } catch (error) {
217
+ console.error("Transform failed for ".concat(extraFileName, ":"), error);
218
+ // Continue with original source if transform fails
219
+ }
220
+ }
221
+
222
+ // Only update filenameMap and add to files if this doesn't conflict with existing files
223
+ // If a file already exists with the target name, skip this transformation to preserve original files
224
+ var existingFile = files.find(function (f) {
225
+ return f.name === transformedName;
226
+ });
227
+ if (!existingFile) {
228
+ filenameMap[extraFileName] = transformedName;
229
+ files.push({
230
+ name: transformedName,
231
+ originalName: extraFileName,
232
+ source: transformedSource,
233
+ component: stringOrHastToJsx(transformedSource, shouldHighlight)
234
+ });
235
+ } else {
236
+ // If there's a conflict, skip this file with a warning
237
+ console.warn("Transform conflict: ".concat(extraFileName, " would transform to ").concat(transformedName, " but that name is already taken. Skipping this file."));
238
+ }
239
+ });
240
+ }
241
+ return {
242
+ files: files,
243
+ filenameMap: filenameMap
244
+ };
245
+ }