@mui/internal-docs-infra 0.1.1-canary.8 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +3 -11
- package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
- package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
- package/esm/CodeControllerContext/index.d.ts +1 -0
- package/esm/CodeControllerContext/index.js +1 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
- package/esm/CodeExternalsContext/index.d.ts +1 -0
- package/esm/CodeExternalsContext/index.js +1 -0
- package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
- package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
- package/esm/CodeHighlighter/applyTransform.js +75 -0
- package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
- package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
- package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
- package/esm/CodeHighlighter/errors.d.ts +141 -0
- package/esm/CodeHighlighter/errors.js +441 -0
- package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
- package/esm/CodeHighlighter/examineVariant.js +73 -0
- package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
- package/esm/CodeHighlighter/hasAllVariants.js +63 -0
- package/esm/CodeHighlighter/index.d.ts +1 -0
- package/esm/CodeHighlighter/index.js +1 -0
- package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
- package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
- package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
- package/esm/CodeHighlighter/loadVariant.js +1044 -0
- package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
- package/esm/CodeHighlighter/maybeInitialData.js +192 -0
- package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
- package/esm/CodeHighlighter/mergeMetadata.js +165 -0
- package/esm/CodeHighlighter/parseCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseCode.js +134 -0
- package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseControlledCode.js +87 -0
- package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
- package/esm/CodeHighlighter/pathUtils.js +258 -0
- package/esm/CodeHighlighter/transformCode.d.ts +21 -0
- package/esm/CodeHighlighter/transformCode.js +251 -0
- package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/esm/CodeHighlighter/transformParsedSource.js +60 -0
- package/esm/CodeHighlighter/transformSource.d.ts +2 -0
- package/esm/CodeHighlighter/transformSource.js +103 -0
- package/esm/CodeHighlighter/types.d.ts +276 -0
- package/esm/CodeHighlighter/types.js +1 -0
- package/esm/CodeProvider/CodeContext.d.ts +31 -0
- package/esm/CodeProvider/CodeContext.js +12 -0
- package/esm/CodeProvider/CodeProvider.d.ts +13 -0
- package/esm/CodeProvider/CodeProvider.js +83 -0
- package/esm/CodeProvider/index.d.ts +1 -0
- package/esm/CodeProvider/index.js +1 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
- package/esm/abstractCreateDemo/index.d.ts +1 -0
- package/esm/abstractCreateDemo/index.js +1 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
- package/esm/abstractCreateDemoClient/index.d.ts +1 -0
- package/esm/abstractCreateDemoClient/index.js +1 -0
- package/esm/createDemoData/createDemoData.d.ts +44 -0
- package/esm/createDemoData/createDemoData.js +74 -0
- package/esm/createDemoData/index.d.ts +1 -0
- package/esm/createDemoData/index.js +1 -0
- package/esm/createDemoData/types.d.ts +25 -0
- package/esm/createDemoData/types.js +1 -0
- package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
- package/esm/pipeline/hastUtils/hastUtils.js +67 -0
- package/esm/pipeline/hastUtils/index.d.ts +1 -0
- package/esm/pipeline/hastUtils/index.js +1 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
- package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
- package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
- package/esm/pipeline/loadServerSource/index.d.ts +1 -0
- package/esm/pipeline/loadServerSource/index.js +1 -0
- package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
- package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
- package/esm/pipeline/loaderUtils/index.d.ts +7 -0
- package/esm/pipeline/loaderUtils/index.js +7 -0
- package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
- package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
- package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/parseImports.js +306 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
- package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
- package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
- package/esm/pipeline/parseSource/addLineGutters.js +181 -0
- package/esm/pipeline/parseSource/grammars.d.ts +2 -0
- package/esm/pipeline/parseSource/grammars.js +27 -0
- package/esm/pipeline/parseSource/index.d.ts +1 -0
- package/esm/pipeline/parseSource/index.js +1 -0
- package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
- package/esm/pipeline/parseSource/parseSource.js +51 -0
- package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
- package/esm/pipeline/transformHtmlCode/index.js +4 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
- package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/index.js +4 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
- package/esm/useCode/Pre.d.ts +15 -0
- package/esm/useCode/Pre.js +164 -0
- package/esm/useCode/index.d.ts +1 -0
- package/esm/useCode/index.js +1 -0
- package/esm/useCode/useCode.d.ts +41 -0
- package/esm/useCode/useCode.js +128 -0
- package/esm/useCode/useCodeUtils.d.ts +44 -0
- package/esm/useCode/useCodeUtils.js +245 -0
- package/esm/useCode/useCopyFunctionality.d.ts +18 -0
- package/esm/useCode/useCopyFunctionality.js +28 -0
- package/esm/useCode/useFileNavigation.d.ts +41 -0
- package/esm/useCode/useFileNavigation.js +453 -0
- package/esm/useCode/useSourceEditing.d.ts +21 -0
- package/esm/useCode/useSourceEditing.js +32 -0
- package/esm/useCode/useTransformManagement.d.ts +30 -0
- package/esm/useCode/useTransformManagement.js +72 -0
- package/esm/useCode/useUIState.d.ts +16 -0
- package/esm/useCode/useUIState.js +21 -0
- package/esm/useCode/useVariantSelection.d.ts +23 -0
- package/esm/useCode/useVariantSelection.js +75 -0
- package/esm/useCopier/index.d.ts +1 -1
- package/esm/useCopier/index.js +5 -5
- package/esm/useDemo/createCodeSandbox.d.ts +15 -0
- package/esm/useDemo/createCodeSandbox.js +42 -0
- package/esm/useDemo/createStackBlitz.d.ts +22 -0
- package/esm/useDemo/createStackBlitz.js +38 -0
- package/esm/useDemo/exportVariant.d.ts +184 -0
- package/esm/useDemo/exportVariant.js +422 -0
- package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
- package/esm/useDemo/exportVariantAsCra.js +57 -0
- package/esm/useDemo/flattenVariant.d.ts +19 -0
- package/esm/useDemo/flattenVariant.js +49 -0
- package/esm/useDemo/index.d.ts +6 -51
- package/esm/useDemo/index.js +6 -104
- package/esm/useDemo/useDemo.d.ts +81 -0
- package/esm/useDemo/useDemo.js +193 -0
- package/esm/useErrors/ErrorsContext.d.ts +6 -0
- package/esm/useErrors/ErrorsContext.js +8 -0
- package/esm/useErrors/index.d.ts +1 -0
- package/esm/useErrors/index.js +1 -0
- package/esm/useErrors/useErrors.d.ts +5 -0
- package/esm/useErrors/useErrors.js +7 -0
- package/esm/useLocalStorageState/index.d.ts +2 -0
- package/esm/useLocalStorageState/index.js +2 -0
- package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
- package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
- package/esm/usePreference/PreferencesProvider.d.ts +6 -0
- package/esm/usePreference/PreferencesProvider.js +8 -0
- package/esm/usePreference/index.d.ts +2 -0
- package/esm/usePreference/index.js +2 -0
- package/esm/usePreference/usePreference.d.ts +2 -0
- package/esm/usePreference/usePreference.js +25 -0
- package/esm/useUrlHashState/index.d.ts +1 -0
- package/esm/useUrlHashState/index.js +1 -0
- package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
- package/esm/useUrlHashState/useUrlHashState.js +68 -0
- package/esm/withDocsInfra/index.d.ts +1 -0
- package/esm/withDocsInfra/index.js +1 -0
- package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
- package/esm/withDocsInfra/withDocsInfra.js +147 -0
- package/package.json +178 -11
- package/esm/useCopier/index.d.ts.map +0 -1
- package/esm/useDemo/index.d.ts.map +0 -1
package/esm/useDemo/index.js
CHANGED
|
@@ -1,104 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import kebabCase from 'kebab-case';
|
|
8
|
-
import { useCopier } from "../useCopier/index.js";
|
|
9
|
-
function toComponent(source) {
|
|
10
|
-
return toJsxRuntime(source, {
|
|
11
|
-
Fragment: Fragment,
|
|
12
|
-
jsx: jsx,
|
|
13
|
-
jsxs: jsxs
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
export function useDemo(demo, opts) {
|
|
17
|
-
var _ref = opts || {},
|
|
18
|
-
copyOpts = _ref.copy,
|
|
19
|
-
_ref$defaultOpen = _ref.defaultOpen,
|
|
20
|
-
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen;
|
|
21
|
-
var slug = React.useMemo(function () {
|
|
22
|
-
return demo.slug || (demo.name ? kebabCase(demo.name, false) : undefined);
|
|
23
|
-
}, [demo.slug, demo.name]);
|
|
24
|
-
var _React$useState = React.useState(defaultOpen),
|
|
25
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
26
|
-
expanded = _React$useState2[0],
|
|
27
|
-
setExpanded = _React$useState2[1];
|
|
28
|
-
var expand = React.useCallback(function () {
|
|
29
|
-
return setExpanded(true);
|
|
30
|
-
}, []);
|
|
31
|
-
var ref = React.useRef(null);
|
|
32
|
-
var resetFocus = React.useCallback(function () {
|
|
33
|
-
var _ref$current;
|
|
34
|
-
(_ref$current = ref.current) == null || _ref$current.focus();
|
|
35
|
-
}, []);
|
|
36
|
-
var variantKeys = React.useMemo(function () {
|
|
37
|
-
return Object.keys(demo.variants);
|
|
38
|
-
}, [demo.variants]);
|
|
39
|
-
var _React$useState3 = React.useState(variantKeys[0]),
|
|
40
|
-
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
41
|
-
selectedVariantKey = _React$useState4[0],
|
|
42
|
-
setSelectedVariantKey = _React$useState4[1];
|
|
43
|
-
var selectedVariant = demo.variants[selectedVariantKey];
|
|
44
|
-
var _React$useState5 = React.useState(selectedVariant.fileName),
|
|
45
|
-
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
46
|
-
selectedFileName = _React$useState6[0],
|
|
47
|
-
setSelectedFileName = _React$useState6[1];
|
|
48
|
-
var selectedFile = React.useMemo(function () {
|
|
49
|
-
var _selectedVariant$extr;
|
|
50
|
-
return selectedFileName === selectedVariant.fileName ? selectedVariant.source : (_selectedVariant$extr = selectedVariant.extraSource) == null ? void 0 : _selectedVariant$extr[selectedFileName];
|
|
51
|
-
}, [selectedFileName, selectedVariant]);
|
|
52
|
-
|
|
53
|
-
// if copying, convert the selected file's hast to text
|
|
54
|
-
var sourceFileToText = React.useCallback(function () {
|
|
55
|
-
return selectedFile && toText(selectedFile, {
|
|
56
|
-
whitespace: 'pre'
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
// TODO: allow passing the filename to copy
|
|
60
|
-
[selectedFile]);
|
|
61
|
-
var _useCopier = useCopier(sourceFileToText, copyOpts),
|
|
62
|
-
copy = _useCopier.copy,
|
|
63
|
-
copyDisabled = _useCopier.disabled;
|
|
64
|
-
|
|
65
|
-
// transform hast source to React components
|
|
66
|
-
var files = React.useMemo(function () {
|
|
67
|
-
var extraSource = selectedVariant.extraSource;
|
|
68
|
-
return [{
|
|
69
|
-
name: selectedVariant.fileName,
|
|
70
|
-
component: toComponent(selectedVariant.source)
|
|
71
|
-
}].concat(_toConsumableArray(extraSource ? Object.keys(extraSource).map(function (name) {
|
|
72
|
-
return {
|
|
73
|
-
name: name,
|
|
74
|
-
component: toComponent(extraSource[name])
|
|
75
|
-
};
|
|
76
|
-
}) : []));
|
|
77
|
-
}, [selectedVariant]);
|
|
78
|
-
var selectedFileComponent = React.useMemo(function () {
|
|
79
|
-
var matchedFile = files.find(function (file) {
|
|
80
|
-
return file.name === selectedFileName;
|
|
81
|
-
});
|
|
82
|
-
return matchedFile ? matchedFile.component : null;
|
|
83
|
-
}, [files, selectedFileName]);
|
|
84
|
-
return {
|
|
85
|
-
component: selectedVariant.component,
|
|
86
|
-
name: demo.name,
|
|
87
|
-
slug: slug,
|
|
88
|
-
description: demo.description,
|
|
89
|
-
ref: ref,
|
|
90
|
-
variants: variantKeys,
|
|
91
|
-
selectedVariant: selectedVariantKey,
|
|
92
|
-
selectVariant: setSelectedVariantKey,
|
|
93
|
-
files: files,
|
|
94
|
-
selectedFile: selectedFileComponent,
|
|
95
|
-
selectedFileName: selectedFileName,
|
|
96
|
-
selectFileName: setSelectedFileName,
|
|
97
|
-
expanded: expanded,
|
|
98
|
-
expand: expand,
|
|
99
|
-
setExpanded: setExpanded,
|
|
100
|
-
resetFocus: resetFocus,
|
|
101
|
-
copy: copy,
|
|
102
|
-
copyDisabled: copyDisabled
|
|
103
|
-
};
|
|
104
|
-
}
|
|
1
|
+
export * from "./useDemo.js";
|
|
2
|
+
export * from "./createStackBlitz.js";
|
|
3
|
+
export * from "./createCodeSandbox.js";
|
|
4
|
+
export * from "./flattenVariant.js";
|
|
5
|
+
export * from "./exportVariant.js";
|
|
6
|
+
export * from "./exportVariantAsCra.js";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { UseCodeOpts } from "../useCode/index.js";
|
|
3
|
+
import type { ContentProps } from "../CodeHighlighter/types.js";
|
|
4
|
+
import { type ExportConfig } from "./exportVariant.js";
|
|
5
|
+
/**
|
|
6
|
+
* Demo templates use the exportVariant/exportVariantAsCra with flattenVariant pattern:
|
|
7
|
+
*
|
|
8
|
+
* For StackBlitz:
|
|
9
|
+
* const { exported: exportedVariant, entrypoint } = exportVariant(variantCode);
|
|
10
|
+
* const flattenedFiles = flattenVariant(exportedVariant);
|
|
11
|
+
* createStackBlitzDemo({ title, description, flattenedFiles, useTypescript, initialFile: entrypoint })
|
|
12
|
+
*
|
|
13
|
+
* For CodeSandbox:
|
|
14
|
+
* const { exported: craExport, entrypoint } = exportVariantAsCra(variantCode, { title, description, useTypescript });
|
|
15
|
+
* const flattenedFiles = flattenVariant(craExport);
|
|
16
|
+
* createCodeSandboxDemo({ title, description, flattenedFiles, useTypescript, initialFile: entrypoint })
|
|
17
|
+
* createCodeSandboxDemo({ title, description, flattenedFiles, useTypescript })
|
|
18
|
+
*/
|
|
19
|
+
type UseDemoOpts = UseCodeOpts & {
|
|
20
|
+
codeSandboxUrlPrefix?: string;
|
|
21
|
+
stackBlitzPrefix?: string;
|
|
22
|
+
/** Common export configuration applied to both StackBlitz and CodeSandbox */
|
|
23
|
+
export?: ExportConfig;
|
|
24
|
+
/** StackBlitz-specific export configuration (merged with common export config) */
|
|
25
|
+
exportStackBlitz?: ExportConfig;
|
|
26
|
+
/** CodeSandbox-specific export configuration (merged with common export config) */
|
|
27
|
+
exportCodeSandbox?: ExportConfig;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Helper to create HTML form element with hidden inputs
|
|
31
|
+
*/
|
|
32
|
+
export declare function addHiddenInput(form: HTMLFormElement, name: string, value: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Generic function to create and submit a form for opening online demo platforms
|
|
35
|
+
* This function creates HTML elements and should be used in browser contexts
|
|
36
|
+
*/
|
|
37
|
+
export declare function openWithForm({
|
|
38
|
+
url,
|
|
39
|
+
formData,
|
|
40
|
+
method,
|
|
41
|
+
target
|
|
42
|
+
}: {
|
|
43
|
+
url: string;
|
|
44
|
+
formData: Record<string, string>;
|
|
45
|
+
method?: string;
|
|
46
|
+
target?: string;
|
|
47
|
+
}): void;
|
|
48
|
+
export declare function useDemo<T extends {} = {}>(contentProps: ContentProps<T>, opts?: UseDemoOpts): {
|
|
49
|
+
component: string | number | bigint | true | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | null;
|
|
50
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
51
|
+
resetFocus: () => void;
|
|
52
|
+
openStackBlitz: () => void;
|
|
53
|
+
openCodeSandbox: () => void;
|
|
54
|
+
name: string | undefined;
|
|
55
|
+
slug: string | undefined;
|
|
56
|
+
variants: string[];
|
|
57
|
+
selectedVariant: string;
|
|
58
|
+
selectVariant: React.Dispatch<React.SetStateAction<string>>;
|
|
59
|
+
files: Array<{
|
|
60
|
+
name: string;
|
|
61
|
+
slug?: string;
|
|
62
|
+
component: React.ReactNode;
|
|
63
|
+
}>;
|
|
64
|
+
selectedFile: React.ReactNode;
|
|
65
|
+
selectedFileLines: number;
|
|
66
|
+
selectedFileName: string | undefined;
|
|
67
|
+
selectFileName: (fileName: string) => void;
|
|
68
|
+
expanded: boolean;
|
|
69
|
+
expand: () => void;
|
|
70
|
+
setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|
|
71
|
+
copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
|
|
72
|
+
availableTransforms: string[];
|
|
73
|
+
selectedTransform: string | null | undefined;
|
|
74
|
+
selectTransform: (transformName: string | null) => void;
|
|
75
|
+
setSource?: (source: string) => void;
|
|
76
|
+
userProps: T & {
|
|
77
|
+
name?: string;
|
|
78
|
+
slug?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import kebabCase from 'kebab-case';
|
|
5
|
+
import { useCode } from "../useCode/index.js";
|
|
6
|
+
import { CodeHighlighterContext } from "../CodeHighlighter/CodeHighlighterContext.js";
|
|
7
|
+
import { createStackBlitz } from "./createStackBlitz.js";
|
|
8
|
+
import { createCodeSandbox } from "./createCodeSandbox.js";
|
|
9
|
+
import { exportVariant } from "./exportVariant.js";
|
|
10
|
+
import { exportVariantAsCra } from "./exportVariantAsCra.js";
|
|
11
|
+
import { flattenVariant } from "./flattenVariant.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Demo templates use the exportVariant/exportVariantAsCra with flattenVariant pattern:
|
|
15
|
+
*
|
|
16
|
+
* For StackBlitz:
|
|
17
|
+
* const { exported: exportedVariant, entrypoint } = exportVariant(variantCode);
|
|
18
|
+
* const flattenedFiles = flattenVariant(exportedVariant);
|
|
19
|
+
* createStackBlitzDemo({ title, description, flattenedFiles, useTypescript, initialFile: entrypoint })
|
|
20
|
+
*
|
|
21
|
+
* For CodeSandbox:
|
|
22
|
+
* const { exported: craExport, entrypoint } = exportVariantAsCra(variantCode, { title, description, useTypescript });
|
|
23
|
+
* const flattenedFiles = flattenVariant(craExport);
|
|
24
|
+
* createCodeSandboxDemo({ title, description, flattenedFiles, useTypescript, initialFile: entrypoint })
|
|
25
|
+
* createCodeSandboxDemo({ title, description, flattenedFiles, useTypescript })
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Helper to create HTML form element with hidden inputs
|
|
30
|
+
*/
|
|
31
|
+
export function addHiddenInput(form, name, value) {
|
|
32
|
+
var input = document.createElement('input');
|
|
33
|
+
input.type = 'hidden';
|
|
34
|
+
input.name = name;
|
|
35
|
+
input.value = value;
|
|
36
|
+
form.appendChild(input);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generic function to create and submit a form for opening online demo platforms
|
|
41
|
+
* This function creates HTML elements and should be used in browser contexts
|
|
42
|
+
*/
|
|
43
|
+
export function openWithForm(_ref) {
|
|
44
|
+
var url = _ref.url,
|
|
45
|
+
formData = _ref.formData,
|
|
46
|
+
_ref$method = _ref.method,
|
|
47
|
+
method = _ref$method === void 0 ? 'POST' : _ref$method,
|
|
48
|
+
_ref$target = _ref.target,
|
|
49
|
+
target = _ref$target === void 0 ? '_blank' : _ref$target;
|
|
50
|
+
var form = document.createElement('form');
|
|
51
|
+
form.method = method;
|
|
52
|
+
form.target = target;
|
|
53
|
+
form.action = url;
|
|
54
|
+
Object.entries(formData).forEach(function (_ref2) {
|
|
55
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
56
|
+
name = _ref3[0],
|
|
57
|
+
value = _ref3[1];
|
|
58
|
+
addHiddenInput(form, name, value);
|
|
59
|
+
});
|
|
60
|
+
document.body.appendChild(form);
|
|
61
|
+
form.submit();
|
|
62
|
+
document.body.removeChild(form);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// TODO: take initialVariant and initialTransforms as parameters
|
|
66
|
+
export function useDemo(contentProps, opts) {
|
|
67
|
+
var code = useCode(contentProps, opts);
|
|
68
|
+
|
|
69
|
+
// Extract export configuration options
|
|
70
|
+
var _ref4 = opts || {},
|
|
71
|
+
_ref4$export = _ref4["export"],
|
|
72
|
+
commonExportConfig = _ref4$export === void 0 ? {} : _ref4$export,
|
|
73
|
+
_ref4$exportStackBlit = _ref4.exportStackBlitz,
|
|
74
|
+
stackBlitzExportConfig = _ref4$exportStackBlit === void 0 ? {} : _ref4$exportStackBlit,
|
|
75
|
+
_ref4$exportCodeSandb = _ref4.exportCodeSandbox,
|
|
76
|
+
codeSandboxExportConfig = _ref4$exportCodeSandb === void 0 ? {} : _ref4$exportCodeSandb;
|
|
77
|
+
|
|
78
|
+
// Get context to access components if available (using React.useContext to avoid import conflicts)
|
|
79
|
+
var context = React.useContext(CodeHighlighterContext);
|
|
80
|
+
var slug = React.useMemo(function () {
|
|
81
|
+
return contentProps.slug || (contentProps.name ? kebabCase(contentProps.name, false) : undefined);
|
|
82
|
+
}, [contentProps.slug, contentProps.name]);
|
|
83
|
+
|
|
84
|
+
// Get the effective components object - context overrides contentProps
|
|
85
|
+
var effectiveComponents = React.useMemo(function () {
|
|
86
|
+
return (context == null ? void 0 : context.components) || contentProps.components || {};
|
|
87
|
+
}, [context == null ? void 0 : context.components, contentProps.components]);
|
|
88
|
+
|
|
89
|
+
// Get the component for the current variant
|
|
90
|
+
var component = React.useMemo(function () {
|
|
91
|
+
return effectiveComponents[code.selectedVariant] || null;
|
|
92
|
+
}, [effectiveComponents, code.selectedVariant]);
|
|
93
|
+
|
|
94
|
+
// Demo-specific ref and focus management
|
|
95
|
+
var ref = React.useRef(null);
|
|
96
|
+
var resetFocus = React.useCallback(function () {
|
|
97
|
+
var _ref$current;
|
|
98
|
+
(_ref$current = ref.current) == null || _ref$current.focus();
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
// Get the effective code - context overrides contentProps if available
|
|
102
|
+
var effectiveCode = React.useMemo(function () {
|
|
103
|
+
return (context == null ? void 0 : context.code) || contentProps.code || {};
|
|
104
|
+
}, [context == null ? void 0 : context.code, contentProps.code]);
|
|
105
|
+
|
|
106
|
+
// Create StackBlitz demo callback
|
|
107
|
+
var openStackBlitz = React.useCallback(function () {
|
|
108
|
+
// Get the current variant code
|
|
109
|
+
var variantCode = effectiveCode[code.selectedVariant];
|
|
110
|
+
if (!variantCode || typeof variantCode === 'string') {
|
|
111
|
+
console.warn('No valid variant code available for StackBlitz demo');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var title = contentProps.name || 'Demo';
|
|
115
|
+
var description = "".concat(title, " demo");
|
|
116
|
+
|
|
117
|
+
// Determine if we should use TypeScript based on whether 'js' transform is NOT applied
|
|
118
|
+
// If 'js' transform is applied, it means we're showing the JS version of TS code
|
|
119
|
+
var useTypescript = code.selectedTransform !== 'js';
|
|
120
|
+
|
|
121
|
+
// Merge common export config with StackBlitz-specific config
|
|
122
|
+
var mergedConfig = _extends(_extends(_extends({}, commonExportConfig), stackBlitzExportConfig), {}, {
|
|
123
|
+
variantName: code.selectedVariant,
|
|
124
|
+
title: title,
|
|
125
|
+
description: description,
|
|
126
|
+
useTypescript: useTypescript
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Use custom export function if provided, otherwise use default exportVariant
|
|
130
|
+
var exportFunction = mergedConfig.exportFunction || exportVariant;
|
|
131
|
+
var _exportFunction = exportFunction(variantCode, mergedConfig),
|
|
132
|
+
exported = _exportFunction.exported,
|
|
133
|
+
rootFile = _exportFunction.rootFile;
|
|
134
|
+
|
|
135
|
+
// Flatten the variant to get a flat file structure
|
|
136
|
+
var flattenedFiles = flattenVariant(exported);
|
|
137
|
+
var stackBlitzDemo = createStackBlitz({
|
|
138
|
+
title: title,
|
|
139
|
+
description: description,
|
|
140
|
+
flattenedFiles: flattenedFiles,
|
|
141
|
+
rootFile: rootFile
|
|
142
|
+
});
|
|
143
|
+
openWithForm(stackBlitzDemo);
|
|
144
|
+
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name, commonExportConfig, stackBlitzExportConfig]);
|
|
145
|
+
|
|
146
|
+
// Create CodeSandbox demo callback
|
|
147
|
+
var openCodeSandbox = React.useCallback(function () {
|
|
148
|
+
// Get the current variant code
|
|
149
|
+
var variantCode = effectiveCode[code.selectedVariant];
|
|
150
|
+
if (!variantCode || typeof variantCode === 'string') {
|
|
151
|
+
console.warn('No valid variant code available for CodeSandbox demo');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
var title = contentProps.name || 'Demo';
|
|
155
|
+
var description = "".concat(title, " demo");
|
|
156
|
+
|
|
157
|
+
// Determine if we should use TypeScript based on whether 'js' transform is NOT applied
|
|
158
|
+
// If 'js' transform is applied, it means we're showing the JS version of TS code
|
|
159
|
+
var useTypescript = code.selectedTransform !== 'js';
|
|
160
|
+
|
|
161
|
+
// Merge common export config with CodeSandbox-specific config
|
|
162
|
+
var mergedConfig = _extends(_extends(_extends({}, commonExportConfig), codeSandboxExportConfig), {}, {
|
|
163
|
+
variantName: code.selectedVariant,
|
|
164
|
+
title: title,
|
|
165
|
+
description: description,
|
|
166
|
+
useTypescript: useTypescript
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Use custom export function if provided, otherwise use default exportVariantAsCra
|
|
170
|
+
var exportFunction = mergedConfig.exportFunction || exportVariantAsCra;
|
|
171
|
+
var _exportFunction2 = exportFunction(variantCode, mergedConfig),
|
|
172
|
+
craExport = _exportFunction2.exported,
|
|
173
|
+
rootFile = _exportFunction2.rootFile;
|
|
174
|
+
|
|
175
|
+
// Flatten the variant to get a flat file structure
|
|
176
|
+
var flattenedFiles = flattenVariant(craExport);
|
|
177
|
+
var codeSandboxDemo = createCodeSandbox({
|
|
178
|
+
flattenedFiles: flattenedFiles,
|
|
179
|
+
rootFile: rootFile
|
|
180
|
+
});
|
|
181
|
+
openWithForm(codeSandboxDemo);
|
|
182
|
+
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name, commonExportConfig, codeSandboxExportConfig]);
|
|
183
|
+
return _extends(_extends({}, code), {}, {
|
|
184
|
+
// Demo-specific additions
|
|
185
|
+
component: component,
|
|
186
|
+
ref: ref,
|
|
187
|
+
resetFocus: resetFocus,
|
|
188
|
+
openStackBlitz: openStackBlitz,
|
|
189
|
+
openCodeSandbox: openCodeSandbox,
|
|
190
|
+
name: contentProps.name,
|
|
191
|
+
slug: slug
|
|
192
|
+
});
|
|
193
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export var CodeErrorsContext = /*#__PURE__*/React.createContext(undefined);
|
|
5
|
+
if (process.env.NODE_ENV !== "production") CodeErrorsContext.displayName = "CodeErrorsContext";
|
|
6
|
+
export function useErrorsContext() {
|
|
7
|
+
return React.useContext(CodeErrorsContext);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useErrors.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useErrors.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type Initializer = () => string | null;
|
|
3
|
+
type UseStorageStateHookResult = [string | null, React.Dispatch<React.SetStateAction<string | null>>];
|
|
4
|
+
/**
|
|
5
|
+
* Sync state to local storage so that it persists through a page refresh. Usage is
|
|
6
|
+
* similar to useState except we pass in a storage key so that we can default
|
|
7
|
+
* to that value on page load instead of the specified initial value.
|
|
8
|
+
*
|
|
9
|
+
* Since the storage API isn't available in server-rendering environments, we
|
|
10
|
+
* return null during SSR and hydration.
|
|
11
|
+
*/
|
|
12
|
+
declare function useLocalStorageStateBrowser(key: string | null, initializer?: string | null | Initializer): UseStorageStateHookResult;
|
|
13
|
+
declare const _default: typeof useLocalStorageStateBrowser;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Copied from https://github.com/mui/material-ui/blob/9dfc2b12f3fc5c41071da5e10b0088fb04045a26/packages/mui-utils/src/useLocalStorageState/useLocalStorageState.ts
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// storage events only work across tabs, we'll use an event emitter to announce within the current tab
|
|
11
|
+
var currentTabChangeListeners = new Map();
|
|
12
|
+
function onCurrentTabStorageChange(key, handler) {
|
|
13
|
+
var listeners = currentTabChangeListeners.get(key);
|
|
14
|
+
if (!listeners) {
|
|
15
|
+
listeners = new Set();
|
|
16
|
+
currentTabChangeListeners.set(key, listeners);
|
|
17
|
+
}
|
|
18
|
+
listeners.add(handler);
|
|
19
|
+
}
|
|
20
|
+
function offCurrentTabStorageChange(key, handler) {
|
|
21
|
+
var listeners = currentTabChangeListeners.get(key);
|
|
22
|
+
if (!listeners) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
listeners["delete"](handler);
|
|
26
|
+
if (listeners.size === 0) {
|
|
27
|
+
currentTabChangeListeners["delete"](key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function emitCurrentTabStorageChange(key) {
|
|
31
|
+
var listeners = currentTabChangeListeners.get(key);
|
|
32
|
+
if (listeners) {
|
|
33
|
+
listeners.forEach(function (listener) {
|
|
34
|
+
return listener();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function subscribe(area, key, callback) {
|
|
39
|
+
if (!key) {
|
|
40
|
+
return function () {};
|
|
41
|
+
}
|
|
42
|
+
var storageHandler = function storageHandler(event) {
|
|
43
|
+
if (event.storageArea === area && event.key === key) {
|
|
44
|
+
callback();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
window.addEventListener('storage', storageHandler);
|
|
48
|
+
onCurrentTabStorageChange(key, callback);
|
|
49
|
+
return function () {
|
|
50
|
+
window.removeEventListener('storage', storageHandler);
|
|
51
|
+
offCurrentTabStorageChange(key, callback);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getSnapshot(area, key) {
|
|
55
|
+
if (!key) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return area.getItem(key);
|
|
60
|
+
} catch (_unused) {
|
|
61
|
+
// ignore
|
|
62
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function setValue(area, key, value) {
|
|
67
|
+
if (!key) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
if (value === null) {
|
|
72
|
+
area.removeItem(key);
|
|
73
|
+
} else {
|
|
74
|
+
area.setItem(key, String(value));
|
|
75
|
+
}
|
|
76
|
+
} catch (_unused2) {
|
|
77
|
+
// ignore
|
|
78
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
emitCurrentTabStorageChange(key);
|
|
82
|
+
}
|
|
83
|
+
var serverValue = [null, function () {}];
|
|
84
|
+
function useLocalStorageStateServer() {
|
|
85
|
+
return serverValue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sync state to local storage so that it persists through a page refresh. Usage is
|
|
90
|
+
* similar to useState except we pass in a storage key so that we can default
|
|
91
|
+
* to that value on page load instead of the specified initial value.
|
|
92
|
+
*
|
|
93
|
+
* Since the storage API isn't available in server-rendering environments, we
|
|
94
|
+
* return null during SSR and hydration.
|
|
95
|
+
*/
|
|
96
|
+
function useLocalStorageStateBrowser(key) {
|
|
97
|
+
var initializer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
98
|
+
var _React$useState = React.useState(initializer),
|
|
99
|
+
_React$useState2 = _slicedToArray(_React$useState, 1),
|
|
100
|
+
initialValue = _React$useState2[0];
|
|
101
|
+
var area = window.localStorage;
|
|
102
|
+
var subscribeKey = React.useCallback(function (callback) {
|
|
103
|
+
return subscribe(area, key, callback);
|
|
104
|
+
}, [area, key]);
|
|
105
|
+
var getKeySnapshot = React.useCallback(function () {
|
|
106
|
+
var _getSnapshot;
|
|
107
|
+
return (_getSnapshot = getSnapshot(area, key)) != null ? _getSnapshot : initialValue;
|
|
108
|
+
}, [area, initialValue, key]);
|
|
109
|
+
|
|
110
|
+
// Start with null for the hydration, and then switch to the actual value.
|
|
111
|
+
var getKeyServerSnapshot = function getKeyServerSnapshot() {
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
var storedValue = React.useSyncExternalStore(subscribeKey, getKeySnapshot, getKeyServerSnapshot);
|
|
115
|
+
var setStoredValue = React.useCallback(function (value) {
|
|
116
|
+
var valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
117
|
+
setValue(area, key, valueToStore);
|
|
118
|
+
}, [area, key, storedValue]);
|
|
119
|
+
var _React$useState3 = React.useState(initialValue),
|
|
120
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
121
|
+
nonStoredValue = _React$useState4[0],
|
|
122
|
+
setNonStoredValue = _React$useState4[1];
|
|
123
|
+
if (!key) {
|
|
124
|
+
return [nonStoredValue, setNonStoredValue];
|
|
125
|
+
}
|
|
126
|
+
return [storedValue, setStoredValue];
|
|
127
|
+
}
|
|
128
|
+
export default typeof window === 'undefined' ? useLocalStorageStateServer : useLocalStorageStateBrowser;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export var PreferencesContext = /*#__PURE__*/React.createContext(undefined);
|
|
5
|
+
if (process.env.NODE_ENV !== "production") PreferencesContext.displayName = "PreferencesContext";
|
|
6
|
+
export function usePreferences() {
|
|
7
|
+
return React.useContext(PreferencesContext);
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import useLocalStorageState from "../useLocalStorageState/index.js";
|
|
6
|
+
import { usePreferences } from "./PreferencesProvider.js";
|
|
7
|
+
var variantPrefPrefix = '_docs_variant_pref';
|
|
8
|
+
var transformPref = '_docs_transform_pref';
|
|
9
|
+
export function usePreference(type, name) {
|
|
10
|
+
var initializer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
11
|
+
var key = React.useMemo(function () {
|
|
12
|
+
if (!Array.isArray(name)) {
|
|
13
|
+
return name;
|
|
14
|
+
}
|
|
15
|
+
if (name.length <= 1) {
|
|
16
|
+
return null; // Don't use localStorage for single variants - no choice to remember
|
|
17
|
+
}
|
|
18
|
+
return _toConsumableArray(name).sort().join(':');
|
|
19
|
+
}, [name]);
|
|
20
|
+
var preferences = usePreferences();
|
|
21
|
+
var defaultPrefix = type === 'variant' ? variantPrefPrefix : transformPref;
|
|
22
|
+
var prefix = preferences != null && preferences.prefix ? "".concat(preferences == null ? void 0 : preferences.prefix, "_").concat(type) : defaultPrefix;
|
|
23
|
+
var storageKey = key ? "".concat(prefix, ":").concat(key) : null;
|
|
24
|
+
return useLocalStorageState(storageKey, initializer);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useUrlHashState.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useUrlHashState.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for managing URL hash state with SSR support
|
|
3
|
+
* @returns A tuple of [hash, setHash] where hash is the current URL hash (without '#') and setHash updates it
|
|
4
|
+
*/
|
|
5
|
+
export declare function useUrlHashState(): [string | null, (value: string | null, replace?: boolean) => void];
|