@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5

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 (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,5 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
1
  import * as React from 'react';
4
2
  import kebabCase from 'kebab-case';
5
3
  import { useCode } from "../useCode/index.js";
@@ -29,7 +27,7 @@ import { flattenCodeVariant } from "../pipeline/loadCodeVariant/flattenCodeVaria
29
27
  * Helper to create HTML form element with hidden inputs
30
28
  */
31
29
  export function addHiddenInput(form, name, value) {
32
- var input = document.createElement('input');
30
+ const input = document.createElement('input');
33
31
  input.type = 'hidden';
34
32
  input.name = name;
35
33
  input.value = value;
@@ -40,21 +38,17 @@ export function addHiddenInput(form, name, value) {
40
38
  * Generic function to create and submit a form for opening online demo platforms
41
39
  * This function creates HTML elements and should be used in browser contexts
42
40
  */
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');
41
+ export function openWithForm({
42
+ url,
43
+ formData,
44
+ method = 'POST',
45
+ target = '_blank'
46
+ }) {
47
+ const form = document.createElement('form');
51
48
  form.method = method;
52
49
  form.target = target;
53
50
  form.action = url;
54
- Object.entries(formData).forEach(function (_ref2) {
55
- var _ref3 = _slicedToArray(_ref2, 2),
56
- name = _ref3[0],
57
- value = _ref3[1];
51
+ Object.entries(formData).forEach(([name, value]) => {
58
52
  addHiddenInput(form, name, value);
59
53
  });
60
54
  document.body.appendChild(form);
@@ -64,130 +58,132 @@ export function openWithForm(_ref) {
64
58
 
65
59
  // TODO: take initialVariant and initialTransforms as parameters
66
60
  export function useDemo(contentProps, opts) {
67
- var code = useCode(contentProps, opts);
61
+ const code = useCode(contentProps, opts);
68
62
 
69
63
  // 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;
64
+ const {
65
+ export: commonExportConfig = {},
66
+ exportStackBlitz: stackBlitzExportConfig = {},
67
+ exportCodeSandbox: codeSandboxExportConfig = {}
68
+ } = opts || {};
77
69
 
78
70
  // 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]);
71
+ const context = React.useContext(CodeHighlighterContext);
72
+ const slug = React.useMemo(() => contentProps.slug || (contentProps.name ? kebabCase(contentProps.name, false) : undefined), [contentProps.slug, contentProps.name]);
83
73
 
84
74
  // 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]);
75
+ const effectiveComponents = React.useMemo(() => {
76
+ return context?.components || contentProps.components || {};
77
+ }, [context?.components, contentProps.components]);
88
78
 
89
79
  // Get the component for the current variant
90
- var component = React.useMemo(function () {
80
+ const component = React.useMemo(() => {
91
81
  return effectiveComponents[code.selectedVariant] || null;
92
82
  }, [effectiveComponents, code.selectedVariant]);
93
83
 
94
84
  // 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();
85
+ const ref = React.useRef(null);
86
+ const resetFocus = React.useCallback(() => {
87
+ ref.current?.focus();
99
88
  }, []);
100
89
 
101
90
  // 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]);
91
+ const effectiveCode = React.useMemo(() => {
92
+ return context?.code || contentProps.code || {};
93
+ }, [context?.code, contentProps.code]);
105
94
 
106
95
  // Create StackBlitz demo callback
107
- var openStackBlitz = React.useCallback(function () {
96
+ const openStackBlitz = React.useCallback(() => {
108
97
  // Get the current variant code
109
- var variantCode = effectiveCode[code.selectedVariant];
98
+ const variantCode = effectiveCode[code.selectedVariant];
110
99
  if (!variantCode || typeof variantCode === 'string') {
111
100
  console.warn('No valid variant code available for StackBlitz demo');
112
101
  return;
113
102
  }
114
- var title = contentProps.name || 'Demo';
115
- var description = "".concat(title, " demo");
103
+ const title = contentProps.name || 'Demo';
104
+ const description = `${title} demo`;
116
105
 
117
106
  // Determine if we should use TypeScript based on whether 'js' transform is NOT applied
118
107
  // If 'js' transform is applied, it means we're showing the JS version of TS code
119
- var useTypescript = code.selectedTransform !== 'js';
108
+ const useTypescript = code.selectedTransform !== 'js';
120
109
 
121
110
  // Merge common export config with StackBlitz-specific config
122
- var mergedConfig = _extends(_extends(_extends({}, commonExportConfig), stackBlitzExportConfig), {}, {
111
+ const mergedConfig = {
112
+ ...commonExportConfig,
113
+ ...stackBlitzExportConfig,
123
114
  variantName: code.selectedVariant,
124
- title: title,
125
- description: description,
126
- useTypescript: useTypescript
127
- });
115
+ title,
116
+ description,
117
+ useTypescript
118
+ };
128
119
 
129
120
  // 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;
121
+ const exportFunction = mergedConfig.exportFunction || exportVariant;
122
+ const {
123
+ exported,
124
+ rootFile
125
+ } = exportFunction(variantCode, mergedConfig);
134
126
 
135
127
  // Flatten the variant to get a flat file structure
136
- var flattenedFiles = flattenCodeVariant(exported);
137
- var stackBlitzDemo = createStackBlitz({
138
- title: title,
139
- description: description,
140
- flattenedFiles: flattenedFiles,
141
- rootFile: rootFile
128
+ const flattenedFiles = flattenCodeVariant(exported);
129
+ const stackBlitzDemo = createStackBlitz({
130
+ title,
131
+ description,
132
+ flattenedFiles,
133
+ rootFile
142
134
  });
143
135
  openWithForm(stackBlitzDemo);
144
136
  }, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name, commonExportConfig, stackBlitzExportConfig]);
145
137
 
146
138
  // Create CodeSandbox demo callback
147
- var openCodeSandbox = React.useCallback(function () {
139
+ const openCodeSandbox = React.useCallback(() => {
148
140
  // Get the current variant code
149
- var variantCode = effectiveCode[code.selectedVariant];
141
+ const variantCode = effectiveCode[code.selectedVariant];
150
142
  if (!variantCode || typeof variantCode === 'string') {
151
143
  console.warn('No valid variant code available for CodeSandbox demo');
152
144
  return;
153
145
  }
154
- var title = contentProps.name || 'Demo';
155
- var description = "".concat(title, " demo");
146
+ const title = contentProps.name || 'Demo';
147
+ const description = `${title} demo`;
156
148
 
157
149
  // Determine if we should use TypeScript based on whether 'js' transform is NOT applied
158
150
  // If 'js' transform is applied, it means we're showing the JS version of TS code
159
- var useTypescript = code.selectedTransform !== 'js';
151
+ const useTypescript = code.selectedTransform !== 'js';
160
152
 
161
153
  // Merge common export config with CodeSandbox-specific config
162
- var mergedConfig = _extends(_extends(_extends({}, commonExportConfig), codeSandboxExportConfig), {}, {
154
+ const mergedConfig = {
155
+ ...commonExportConfig,
156
+ ...codeSandboxExportConfig,
163
157
  variantName: code.selectedVariant,
164
- title: title,
165
- description: description,
166
- useTypescript: useTypescript
167
- });
158
+ title,
159
+ description,
160
+ useTypescript
161
+ };
168
162
 
169
163
  // 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;
164
+ const exportFunction = mergedConfig.exportFunction || exportVariantAsCra;
165
+ const {
166
+ exported: craExport,
167
+ rootFile
168
+ } = exportFunction(variantCode, mergedConfig);
174
169
 
175
170
  // Flatten the variant to get a flat file structure
176
- var flattenedFiles = flattenCodeVariant(craExport);
177
- var codeSandboxDemo = createCodeSandbox({
178
- flattenedFiles: flattenedFiles,
179
- rootFile: rootFile
171
+ const flattenedFiles = flattenCodeVariant(craExport);
172
+ const codeSandboxDemo = createCodeSandbox({
173
+ flattenedFiles,
174
+ rootFile
180
175
  });
181
176
  openWithForm(codeSandboxDemo);
182
177
  }, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name, commonExportConfig, codeSandboxExportConfig]);
183
- return _extends(_extends({}, code), {}, {
178
+ return {
179
+ ...code,
184
180
  // Demo-specific additions
185
- component: component,
186
- ref: ref,
187
- resetFocus: resetFocus,
188
- openStackBlitz: openStackBlitz,
189
- openCodeSandbox: openCodeSandbox,
181
+ component,
182
+ ref,
183
+ resetFocus,
184
+ openStackBlitz,
185
+ openCodeSandbox,
190
186
  name: contentProps.name,
191
- slug: slug
192
- });
187
+ slug
188
+ };
193
189
  }
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- export var CodeErrorsContext = /*#__PURE__*/React.createContext(undefined);
4
+ export const CodeErrorsContext = /*#__PURE__*/React.createContext(undefined);
5
5
  if (process.env.NODE_ENV !== "production") CodeErrorsContext.displayName = "CodeErrorsContext";
6
6
  export function useErrorsContext() {
7
7
  return React.useContext(CodeErrorsContext);
@@ -1,11 +1,11 @@
1
1
  import { useErrorsContext } from "./ErrorsContext.js";
2
2
  export function useErrors(props) {
3
- var context = useErrorsContext();
3
+ const context = useErrorsContext();
4
4
 
5
5
  // Context errors take precedence over prop errors
6
6
  // This ensures client-side errors override server-side errors
7
- var errors = (context == null ? void 0 : context.errors) || (props == null ? void 0 : props.errors);
7
+ const errors = context?.errors || props?.errors;
8
8
  return {
9
- errors: errors
9
+ errors
10
10
  };
11
11
  }
@@ -1,6 +1,5 @@
1
1
  'use client';
2
2
 
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
3
  import * as React from 'react';
5
4
 
6
5
  /**
@@ -8,9 +7,9 @@ import * as React from 'react';
8
7
  */
9
8
 
10
9
  // storage events only work across tabs, we'll use an event emitter to announce within the current tab
11
- var currentTabChangeListeners = new Map();
10
+ const currentTabChangeListeners = new Map();
12
11
  function onCurrentTabStorageChange(key, handler) {
13
- var listeners = currentTabChangeListeners.get(key);
12
+ let listeners = currentTabChangeListeners.get(key);
14
13
  if (!listeners) {
15
14
  listeners = new Set();
16
15
  currentTabChangeListeners.set(key, listeners);
@@ -18,35 +17,33 @@ function onCurrentTabStorageChange(key, handler) {
18
17
  listeners.add(handler);
19
18
  }
20
19
  function offCurrentTabStorageChange(key, handler) {
21
- var listeners = currentTabChangeListeners.get(key);
20
+ const listeners = currentTabChangeListeners.get(key);
22
21
  if (!listeners) {
23
22
  return;
24
23
  }
25
- listeners["delete"](handler);
24
+ listeners.delete(handler);
26
25
  if (listeners.size === 0) {
27
- currentTabChangeListeners["delete"](key);
26
+ currentTabChangeListeners.delete(key);
28
27
  }
29
28
  }
30
29
  function emitCurrentTabStorageChange(key) {
31
- var listeners = currentTabChangeListeners.get(key);
30
+ const listeners = currentTabChangeListeners.get(key);
32
31
  if (listeners) {
33
- listeners.forEach(function (listener) {
34
- return listener();
35
- });
32
+ listeners.forEach(listener => listener());
36
33
  }
37
34
  }
38
35
  function subscribe(area, key, callback) {
39
36
  if (!key) {
40
- return function () {};
37
+ return () => {};
41
38
  }
42
- var storageHandler = function storageHandler(event) {
39
+ const storageHandler = event => {
43
40
  if (event.storageArea === area && event.key === key) {
44
41
  callback();
45
42
  }
46
43
  };
47
44
  window.addEventListener('storage', storageHandler);
48
45
  onCurrentTabStorageChange(key, callback);
49
- return function () {
46
+ return () => {
50
47
  window.removeEventListener('storage', storageHandler);
51
48
  offCurrentTabStorageChange(key, callback);
52
49
  };
@@ -57,7 +54,7 @@ function getSnapshot(area, key) {
57
54
  }
58
55
  try {
59
56
  return area.getItem(key);
60
- } catch (_unused) {
57
+ } catch {
61
58
  // ignore
62
59
  // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage
63
60
  return null;
@@ -73,14 +70,14 @@ function setValue(area, key, value) {
73
70
  } else {
74
71
  area.setItem(key, String(value));
75
72
  }
76
- } catch (_unused2) {
73
+ } catch {
77
74
  // ignore
78
75
  // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage
79
76
  return;
80
77
  }
81
78
  emitCurrentTabStorageChange(key);
82
79
  }
83
- var serverValue = [null, function () {}];
80
+ const serverValue = [null, () => {}];
84
81
  function useLocalStorageStateServer() {
85
82
  return serverValue;
86
83
  }
@@ -93,33 +90,20 @@ function useLocalStorageStateServer() {
93
90
  * Since the storage API isn't available in server-rendering environments, we
94
91
  * return null during SSR and hydration.
95
92
  */
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]);
93
+ function useLocalStorageStateBrowser(key, initializer = null) {
94
+ const [initialValue] = React.useState(initializer);
95
+ const area = window.localStorage;
96
+ const subscribeKey = React.useCallback(callback => subscribe(area, key, callback), [area, key]);
97
+ const getKeySnapshot = React.useCallback(() => getSnapshot(area, key) ?? initialValue, [area, initialValue, key]);
109
98
 
110
99
  // 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;
100
+ const getKeyServerSnapshot = () => null;
101
+ const storedValue = React.useSyncExternalStore(subscribeKey, getKeySnapshot, getKeyServerSnapshot);
102
+ const setStoredValue = React.useCallback(value => {
103
+ const valueToStore = value instanceof Function ? value(storedValue) : value;
117
104
  setValue(area, key, valueToStore);
118
105
  }, [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];
106
+ const [nonStoredValue, setNonStoredValue] = React.useState(initialValue);
123
107
  if (!key) {
124
108
  return [nonStoredValue, setNonStoredValue];
125
109
  }
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- export var PreferencesContext = /*#__PURE__*/React.createContext(undefined);
4
+ export const PreferencesContext = /*#__PURE__*/React.createContext(undefined);
5
5
  if (process.env.NODE_ENV !== "production") PreferencesContext.displayName = "PreferencesContext";
6
6
  export function usePreferences() {
7
7
  return React.useContext(PreferencesContext);
@@ -1,25 +1,23 @@
1
1
  'use client';
2
2
 
3
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
3
  import * as React from 'react';
5
4
  import useLocalStorageState from "../useLocalStorageState/index.js";
6
5
  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 () {
6
+ const variantPrefPrefix = '_docs_variant_pref';
7
+ const transformPref = '_docs_transform_pref';
8
+ export function usePreference(type, name, initializer = null) {
9
+ const key = React.useMemo(() => {
12
10
  if (!Array.isArray(name)) {
13
11
  return name;
14
12
  }
15
13
  if (name.length <= 1) {
16
14
  return null; // Don't use localStorage for single variants - no choice to remember
17
15
  }
18
- return _toConsumableArray(name).sort().join(':');
16
+ return [...name].sort().join(':');
19
17
  }, [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;
18
+ const preferences = usePreferences();
19
+ const defaultPrefix = type === 'variant' ? variantPrefPrefix : transformPref;
20
+ const prefix = preferences?.prefix ? `${preferences?.prefix}_${type}` : defaultPrefix;
21
+ const storageKey = key ? `${prefix}:${key}` : null;
24
22
  return useLocalStorageState(storageKey, initializer);
25
23
  }