@mui/internal-docs-infra 0.11.1-canary.9 → 0.11.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/ChunkProvider/ChunkContext.d.mts +10 -0
- package/ChunkProvider/ChunkContext.mjs +15 -0
- package/ChunkProvider/ChunkProvider.d.mts +14 -0
- package/ChunkProvider/ChunkProvider.mjs +38 -0
- package/ChunkProvider/PreloadContext.d.mts +14 -0
- package/ChunkProvider/PreloadContext.mjs +18 -0
- package/ChunkProvider/PreloadProvider.d.mts +13 -0
- package/ChunkProvider/PreloadProvider.mjs +33 -0
- package/ChunkProvider/index.d.mts +7 -0
- package/ChunkProvider/index.mjs +7 -0
- package/ChunkProvider/types.d.mts +23 -0
- package/ChunkProvider/types.mjs +1 -0
- package/ChunkProvider/usePreload.d.mts +8 -0
- package/ChunkProvider/usePreload.mjs +21 -0
- package/CodeControllerContext/CodeControllerContext.d.mts +11 -0
- package/CodeControllerContext/CodeControllerContext.mjs +2 -1
- package/CodeHighlighter/CodeHighlighter.d.mts +15 -1
- package/CodeHighlighter/CodeHighlighter.mjs +97 -319
- package/CodeHighlighter/CodeHighlighterChunk.d.mts +42 -0
- package/CodeHighlighter/CodeHighlighterChunk.mjs +77 -0
- package/CodeHighlighter/CodeHighlighterClient.mjs +597 -128
- package/CodeHighlighter/CodeHighlighterContext.d.mts +57 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.mts +14 -2
- package/CodeHighlighter/CodeHighlighterFallbackContext.mjs +1 -3
- package/CodeHighlighter/CodeInitialSourceLoader.d.mts +10 -0
- package/CodeHighlighter/CodeInitialSourceLoader.mjs +108 -0
- package/CodeHighlighter/CodeSourceLoader.d.mts +11 -0
- package/CodeHighlighter/CodeSourceLoader.mjs +128 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.d.mts +47 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.mjs +61 -0
- package/CodeHighlighter/buildStringFallback.d.mts +29 -0
- package/CodeHighlighter/buildStringFallback.mjs +42 -0
- package/CodeHighlighter/codeToFallbackProps.d.mts +31 -2
- package/CodeHighlighter/codeToFallbackProps.mjs +347 -42
- package/CodeHighlighter/createClientProps.d.mts +17 -0
- package/CodeHighlighter/createClientProps.mjs +78 -0
- package/CodeHighlighter/errors.d.mts +6 -0
- package/CodeHighlighter/errors.mjs +10 -0
- package/CodeHighlighter/fallbackCompression.d.mts +96 -0
- package/CodeHighlighter/fallbackCompression.mjs +253 -0
- package/CodeHighlighter/fallbackFormat.d.mts +137 -0
- package/CodeHighlighter/fallbackFormat.mjs +422 -0
- package/CodeHighlighter/index.d.mts +4 -1
- package/CodeHighlighter/index.mjs +3 -1
- package/CodeHighlighter/mergeComments.d.mts +38 -0
- package/CodeHighlighter/mergeComments.mjs +80 -0
- package/CodeHighlighter/prepareInitialSource.d.mts +42 -0
- package/CodeHighlighter/prepareInitialSource.mjs +292 -0
- package/CodeHighlighter/resolveFallbackCritical.d.mts +23 -0
- package/CodeHighlighter/resolveFallbackCritical.mjs +44 -0
- package/CodeHighlighter/types.d.mts +272 -8
- package/CodeHighlighter/useCodeFallback.d.mts +94 -0
- package/CodeHighlighter/useCodeFallback.mjs +204 -0
- package/CodeHighlighter/useGrammarsReady.d.mts +18 -0
- package/CodeHighlighter/useGrammarsReady.mjs +45 -0
- package/CodeHighlighter/useSpeculativeCodePreload.d.mts +26 -0
- package/CodeHighlighter/useSpeculativeCodePreload.mjs +40 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.d.mts +33 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.mjs +58 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.d.mts +23 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.mjs +31 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.d.mts +22 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.mjs +41 -0
- package/CodeProvider/CodeContext.d.mts +47 -12
- package/CodeProvider/CodeContext.mjs +7 -0
- package/CodeProvider/CodeProvider.d.mts +4 -2
- package/CodeProvider/CodeProvider.mjs +40 -102
- package/CodeProvider/CodeProviderLazy.d.mts +40 -0
- package/CodeProvider/CodeProviderLazy.mjs +96 -0
- package/CodeProvider/constants.d.mts +26 -0
- package/CodeProvider/constants.mjs +24 -0
- package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
- package/CodeProvider/createParseSourceWorkerClient.mjs +22 -2
- package/CodeProvider/index.d.mts +2 -1
- package/CodeProvider/index.mjs +9 -1
- package/CodeProvider/parseSourceWorker.mjs +33 -0
- package/CodeProvider/useCodeProviderValue.d.mts +54 -0
- package/CodeProvider/useCodeProviderValue.mjs +188 -0
- package/CoordinatedLazy/ChunkServerLoader.d.mts +25 -0
- package/CoordinatedLazy/ChunkServerLoader.mjs +97 -0
- package/CoordinatedLazy/CoordinatedContentContext.d.mts +15 -0
- package/CoordinatedLazy/CoordinatedContentContext.mjs +22 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.d.mts +11 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.mjs +13 -0
- package/CoordinatedLazy/CoordinatedGateContext.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedGateContext.mjs +19 -0
- package/CoordinatedLazy/CoordinatedLazy.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedLazy.mjs +86 -0
- package/CoordinatedLazy/CoordinatedLazyClient.d.mts +24 -0
- package/CoordinatedLazy/CoordinatedLazyClient.mjs +65 -0
- package/CoordinatedLazy/LazyContent.d.mts +26 -0
- package/CoordinatedLazy/LazyContent.mjs +80 -0
- package/CoordinatedLazy/LazyContentServer.d.mts +18 -0
- package/CoordinatedLazy/LazyContentServer.mjs +25 -0
- package/CoordinatedLazy/buildChunkRenderInputs.d.mts +8 -0
- package/CoordinatedLazy/buildChunkRenderInputs.mjs +35 -0
- package/CoordinatedLazy/createCoordinatedLazy.d.mts +32 -0
- package/CoordinatedLazy/createCoordinatedLazy.mjs +127 -0
- package/CoordinatedLazy/index.d.mts +14 -0
- package/CoordinatedLazy/index.mjs +18 -0
- package/CoordinatedLazy/resolveChunkRender.d.mts +26 -0
- package/CoordinatedLazy/resolveChunkRender.mjs +73 -0
- package/CoordinatedLazy/types.d.mts +408 -0
- package/CoordinatedLazy/types.mjs +1 -0
- package/CoordinatedLazy/useChunk.d.mts +30 -0
- package/CoordinatedLazy/useChunk.mjs +135 -0
- package/CoordinatedLazy/useCoordinatedFallback.d.mts +12 -0
- package/CoordinatedLazy/useCoordinatedFallback.mjs +40 -0
- package/CoordinatedLazy/useCoordinatedSwap.d.mts +16 -0
- package/CoordinatedLazy/useCoordinatedSwap.mjs +124 -0
- package/LICENSE +1 -1
- package/abstractCreateDemo/abstractCreateDemo.d.mts +54 -3
- package/abstractCreateDemo/abstractCreateDemo.mjs +47 -7
- package/abstractCreateDemo/resolveDemoFlag.d.mts +20 -0
- package/abstractCreateDemo/resolveDemoFlag.mjs +25 -0
- package/abstractCreateStream/abstractCreateStream.d.mts +18 -0
- package/abstractCreateStream/abstractCreateStream.mjs +45 -0
- package/abstractCreateStream/index.d.mts +2 -0
- package/abstractCreateStream/index.mjs +1 -0
- package/abstractCreateStream/types.d.mts +34 -0
- package/abstractCreateStream/types.mjs +1 -0
- package/abstractCreateTypes/TypeCode.mjs +12 -11
- package/abstractCreateTypes/typesToJsx.mjs +30 -9
- package/cli/ensureDemoClients.mjs +4 -148
- package/cli/ensureDemoPages.d.mts +45 -0
- package/cli/ensureDemoPages.mjs +99 -0
- package/cli/fileUtils/index.d.mts +11 -0
- package/cli/fileUtils/index.mjs +48 -0
- package/cli/findDemoIndexFiles.d.mts +15 -0
- package/cli/findDemoIndexFiles.mjs +121 -0
- package/cli/index.mjs +1 -1
- package/cli/loadNextConfig.d.mts +25 -0
- package/cli/loadNextConfig.mjs +60 -1
- package/cli/runBrowser.mjs +1 -1
- package/cli/runValidate.mjs +44 -1
- package/package.json +84 -4
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasis.mjs +30 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.d.mts +17 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.mjs +52 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.d.mts +18 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.mjs +24 -0
- package/pipeline/hastUtils/hast.d.mts +27 -0
- package/pipeline/hastUtils/hastCompression.d.mts +3 -1
- package/pipeline/hastUtils/hastCompression.mjs +9 -1
- package/pipeline/hastUtils/hastDecompress.mjs +10 -4
- package/pipeline/hastUtils/hastDictionary.mjs +9 -0
- package/pipeline/hastUtils/hastUtils.d.mts +4 -3
- package/pipeline/hastUtils/hastUtils.mjs +24 -12
- package/pipeline/hastUtils/index.d.mts +2 -1
- package/pipeline/hastUtils/index.mjs +2 -1
- package/pipeline/hastUtils/stripHighlightingSpans.d.mts +6 -2
- package/pipeline/hastUtils/stripHighlightingSpans.mjs +22 -10
- package/pipeline/lintJavascriptDemoFocus/lintJavascriptDemoFocus.mjs +10 -7
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.d.mts +31 -13
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +50 -55
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.d.mts +78 -0
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.mjs +405 -0
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.d.mts +5 -5
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs +36 -66
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.d.mts +23 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.mjs +92 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.d.mts +19 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.mjs +25 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.d.mts +17 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.mjs +26 -0
- package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +26 -2
- package/pipeline/loadIsomorphicCodeVariant/diffHast.mjs +563 -19
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.d.mts +49 -0
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.mjs +152 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.d.mts +51 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.mjs +161 -0
- package/pipeline/loadIsomorphicCodeVariant/flattenCodeVariant.mjs +6 -3
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.d.mts +12 -0
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.mjs +44 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.d.mts +16 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.mjs +74 -0
- package/pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs +17 -5
- package/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs +229 -15
- package/pipeline/loadIsomorphicCodeVariant/transformSource.d.mts +2 -2
- package/pipeline/loadIsomorphicCodeVariant/transformSource.mjs +56 -22
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.mts +18 -0
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.mjs +11 -7
- package/pipeline/loadServerTypes/hastTypeUtils.d.mts +2 -2
- package/pipeline/loadServerTypes/hastTypeUtils.mjs +4 -4
- package/pipeline/loadServerTypes/loadServerTypes.mjs +1 -1
- package/pipeline/loadServerTypesMeta/extractJSDocText.d.mts +14 -0
- package/pipeline/loadServerTypesMeta/extractJSDocText.mjs +60 -0
- package/pipeline/loadServerTypesMeta/processTypes.mjs +43 -46
- package/pipeline/loadServerTypesText/order.mjs +1 -1
- package/pipeline/loadServerTypesText/parseTypesMarkdown.mjs +3 -1
- package/pipeline/loaderUtils/index.d.mts +0 -1
- package/pipeline/loaderUtils/index.mjs +0 -1
- package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -1
- package/pipeline/loaderUtils/parseImportsAndComments.mjs +19 -9
- package/pipeline/loaderUtils/resolveModulePath.mjs +23 -1
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +12 -0
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +17 -13
- package/pipeline/parseSource/addLineGutters.mjs +45 -11
- package/pipeline/parseSource/calculateFrameRanges.d.mts +22 -0
- package/pipeline/parseSource/calculateFrameRanges.mjs +69 -25
- package/pipeline/parseSource/detectGrammarScopes.d.mts +13 -0
- package/pipeline/parseSource/detectGrammarScopes.mjs +35 -0
- package/pipeline/parseSource/extendSyntaxTokens.mjs +501 -43
- package/pipeline/parseSource/frameVisibility.d.mts +47 -0
- package/pipeline/parseSource/frameVisibility.mjs +114 -0
- package/pipeline/parseSource/grammarCache.d.mts +33 -0
- package/pipeline/parseSource/grammarCache.mjs +73 -0
- package/pipeline/parseSource/grammarLoaders.d.mts +14 -0
- package/pipeline/parseSource/grammarLoaders.mjs +24 -0
- package/pipeline/parseSource/grammarMaps.d.mts +21 -1
- package/pipeline/parseSource/grammarMaps.mjs +36 -0
- package/pipeline/parseSource/isFrameSpan.d.mts +19 -0
- package/pipeline/parseSource/isFrameSpan.mjs +24 -0
- package/pipeline/parseSource/parseSource.d.mts +41 -6
- package/pipeline/parseSource/parseSource.mjs +184 -36
- package/pipeline/parseSource/redistributeFrameFallbacks.d.mts +40 -0
- package/pipeline/parseSource/redistributeFrameFallbacks.mjs +138 -0
- package/pipeline/parseSource/restructureFrames.d.mts +5 -0
- package/pipeline/parseSource/restructureFrames.mjs +179 -16
- package/pipeline/syncPageIndex/metadataToMarkdown.mjs +6 -2
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.d.mts +26 -0
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +181 -114
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.d.mts +12 -0
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.mjs +52 -0
- package/pipeline/transformHtmlCodeInline/transformHtmlCodeInline.mjs +22 -1
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.mts +5 -8
- package/pipeline/transformTypescriptToJavascript/removeTypes.mjs +27 -93
- package/useCode/EditableEngine.d.mts +233 -0
- package/useCode/EditableEngine.mjs +1712 -0
- package/useCode/EditingEngine.d.mts +13 -0
- package/useCode/EditingEngine.mjs +14 -0
- package/useCode/Pre.browser.mjs +5 -1
- package/useCode/Pre.d.mts +127 -1
- package/useCode/Pre.mjs +417 -165
- package/useCode/SourceEditingEngine.d.mts +50 -0
- package/useCode/SourceEditingEngine.mjs +461 -0
- package/useCode/TransformEngine.d.mts +39 -0
- package/useCode/TransformEngine.mjs +208 -0
- package/useCode/editingEngineCache.d.mts +29 -0
- package/useCode/editingEngineCache.mjs +68 -0
- package/useCode/sourceLineCounts.d.mts +80 -0
- package/useCode/sourceLineCounts.mjs +284 -0
- package/useCode/subscribeToggleNudge.d.mts +3 -0
- package/useCode/subscribeToggleNudge.mjs +95 -0
- package/useCode/transformEngineCache.d.mts +21 -0
- package/useCode/transformEngineCache.mjs +60 -0
- package/useCode/useCode.d.mts +140 -1
- package/useCode/useCode.mjs +250 -19
- package/useCode/useCodeUtils.d.mts +131 -20
- package/useCode/useCodeUtils.mjs +267 -194
- package/useCode/useCopyFunctionality.d.mts +13 -1
- package/useCode/useCopyFunctionality.mjs +39 -9
- package/useCode/useEditable.browser.mjs +10 -2
- package/useCode/useEditable.d.mts +27 -106
- package/useCode/useEditable.integration.browser.d.mts +1 -0
- package/useCode/useEditable.integration.browser.mjs +870 -0
- package/useCode/useEditable.mjs +198 -1247
- package/useCode/useEditableUtils.d.mts +50 -1
- package/useCode/useEditableUtils.mjs +29 -0
- package/useCode/useFileNavigation.d.mts +91 -3
- package/useCode/useFileNavigation.mjs +201 -41
- package/useCode/useHighlightGate.d.mts +17 -0
- package/useCode/useHighlightGate.mjs +147 -0
- package/useCode/useSourceEditing.d.mts +8 -0
- package/useCode/useSourceEditing.mjs +158 -314
- package/useCode/useSourceEnhancing.d.mts +5 -1
- package/useCode/useSourceEnhancing.mjs +22 -36
- package/useCode/useTransformManagement.d.mts +93 -5
- package/useCode/useTransformManagement.mjs +496 -28
- package/useCode/useTransitionPhase.d.mts +24 -0
- package/useCode/useTransitionPhase.mjs +49 -0
- package/useCode/useUIState.d.mts +2 -2
- package/useCode/useUIState.mjs +8 -8
- package/useCode/useVariantSelection.d.mts +130 -6
- package/useCode/useVariantSelection.mjs +529 -93
- package/useCodeWindow/useCodeWindow.d.mts +19 -2
- package/useCodeWindow/useCodeWindow.mjs +98 -71
- package/useCoordinated/coordinatePreference.d.mts +439 -0
- package/useCoordinated/coordinatePreference.mjs +951 -0
- package/useCoordinated/coordinatePreference.testUtils.d.mts +21 -0
- package/useCoordinated/coordinatePreference.testUtils.mjs +69 -0
- package/useCoordinated/createSettleGate.d.mts +96 -0
- package/useCoordinated/createSettleGate.mjs +171 -0
- package/useCoordinated/index.d.mts +8 -0
- package/useCoordinated/index.mjs +8 -0
- package/useCoordinated/layoutShiftGate.d.mts +24 -0
- package/useCoordinated/layoutShiftGate.mjs +79 -0
- package/useCoordinated/pageSettleGate.d.mts +11 -0
- package/useCoordinated/pageSettleGate.mjs +13 -0
- package/useCoordinated/scheduleTasks.d.mts +23 -0
- package/useCoordinated/scheduleTasks.mjs +45 -0
- package/useCoordinated/useCoordinated.d.mts +193 -0
- package/useCoordinated/useCoordinated.mjs +469 -0
- package/useCoordinated/useCoordinatedLazy.d.mts +17 -0
- package/useCoordinated/useCoordinatedLazy.mjs +38 -0
- package/useCoordinated/useCoordinatedLocalStorage.d.mts +16 -0
- package/useCoordinated/useCoordinatedLocalStorage.mjs +22 -0
- package/useCoordinated/useCoordinatedPreference.d.mts +20 -0
- package/useCoordinated/useCoordinatedPreference.mjs +26 -0
- package/useCoordinated/useSettleGate.d.mts +11 -0
- package/useCoordinated/useSettleGate.mjs +34 -0
- package/useDemo/exportVariant.d.mts +12 -5
- package/useDemo/exportVariant.mjs +59 -5
- package/useDemo/useDemo.d.mts +5 -2
- package/useScrollAnchor/useScrollAnchor.mjs +28 -5
- package/useStream/index.d.mts +6 -0
- package/useStream/index.mjs +6 -0
- package/useStream/streamChunks.d.mts +23 -0
- package/useStream/streamChunks.mjs +85 -0
- package/useStream/types.d.mts +45 -0
- package/useStream/types.mjs +1 -0
- package/useStream/useStream.d.mts +57 -0
- package/useStream/useStream.mjs +119 -0
- package/useStream/useStreamController.d.mts +15 -0
- package/useStream/useStreamController.mjs +90 -0
- package/withDocsInfra/withDocsInfra.d.mts +19 -0
- package/withDocsInfra/withDocsInfra.mjs +13 -5
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.d.mts +0 -8
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.mjs +0 -16
package/useCode/useUIState.mjs
CHANGED
|
@@ -6,20 +6,20 @@ import { isHashRelevantToDemo } from "./useFileNavigation.mjs";
|
|
|
6
6
|
* Auto-expands if there's a relevant hash for this demo
|
|
7
7
|
*/
|
|
8
8
|
export function useUIState({
|
|
9
|
-
|
|
9
|
+
initialExpanded = false,
|
|
10
10
|
mainSlug
|
|
11
11
|
}) {
|
|
12
12
|
const [hash] = useUrlHashState();
|
|
13
13
|
const hasRelevantHash = isHashRelevantToDemo(hash, mainSlug);
|
|
14
|
-
const [expanded, setExpanded] = React.useState(
|
|
14
|
+
const [expanded, setExpanded] = React.useState(initialExpanded || hasRelevantHash);
|
|
15
15
|
const expand = React.useCallback(() => setExpanded(true), []);
|
|
16
16
|
|
|
17
|
-
// Auto-expand if hash becomes relevant
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
17
|
+
// Auto-expand if hash becomes relevant. This is a one-way OR-latch: it ratchets
|
|
18
|
+
// `expanded` to true but never collapses, so adjusting state during render is safe
|
|
19
|
+
// (the branch is skipped once `expanded` is true, avoiding an extra render).
|
|
20
|
+
if (hasRelevantHash && !expanded) {
|
|
21
|
+
setExpanded(true);
|
|
22
|
+
}
|
|
23
23
|
return {
|
|
24
24
|
expanded,
|
|
25
25
|
expand,
|
|
@@ -1,31 +1,155 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { Code, VariantCode } from "../CodeHighlighter/types.mjs";
|
|
3
|
+
import { type TransitionPhase } from "./useTransitionPhase.mjs";
|
|
3
4
|
interface UseVariantSelectionProps {
|
|
4
5
|
effectiveCode: Code;
|
|
5
6
|
initialVariant?: string;
|
|
6
7
|
variantType?: string;
|
|
7
8
|
mainSlug?: string;
|
|
8
9
|
saveHashVariantToLocalStorage?: 'on-load' | 'on-interaction' | 'never';
|
|
10
|
+
/**
|
|
11
|
+
* Mode passed to `variantHasLayoutShift` to classify variant swaps
|
|
12
|
+
* as layout-affecting (phase 1, coordinated) versus non-layout
|
|
13
|
+
* (phase 2). See `useCode`'s `variantLayoutShift` option for
|
|
14
|
+
* details. Defaults to `'selected'`.
|
|
15
|
+
*/
|
|
16
|
+
variantLayoutShift?: 'all' | 'selected' | 'focus';
|
|
17
|
+
/**
|
|
18
|
+
* Currently-selected file name. Required for the `'selected'` and
|
|
19
|
+
* `'focus'` `variantLayoutShift` modes; ignored by `'all'`.
|
|
20
|
+
*/
|
|
21
|
+
selectedFileName?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the surrounding code block is currently expanded.
|
|
24
|
+
* Consulted only by `variantLayoutShift: 'focus'`.
|
|
25
|
+
*/
|
|
26
|
+
expanded?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* When set to a positive number, the *swap* of the rendered tree to
|
|
29
|
+
* the newly-selected variant is delayed by this many milliseconds so
|
|
30
|
+
* consumers can run an exit animation on the outgoing tree before
|
|
31
|
+
* the incoming tree replaces it. `selectedVariantKey` always
|
|
32
|
+
* updates synchronously so UI controls (tabs, dropdowns) reflect
|
|
33
|
+
* the change immediately; the lag is only visible on the rendered
|
|
34
|
+
* `<Pre>` content, which stays on `committedVariantKey` until the
|
|
35
|
+
* delay elapses. While the swap is pending or just-committed,
|
|
36
|
+
* `variantSwappingPhase` is non-null and the rendered `<pre>` is
|
|
37
|
+
* annotated with `data-transforming` so CSS can react.
|
|
38
|
+
*/
|
|
39
|
+
variantSwapDelay?: number;
|
|
40
|
+
/**
|
|
41
|
+
* When `true`, holds the coordinator barrier open via the engine's
|
|
42
|
+
* `preload` slot until the highlighter pipeline (sync `parseCode`
|
|
43
|
+
* + async `computeHastDeltas`) has finished, so the incoming
|
|
44
|
+
* variant tree always paints with highlighting applied instead of
|
|
45
|
+
* snapping to it a frame later. Plumbed in from
|
|
46
|
+
* `CodeHighlighterContext.deferHighlight`; see `useHighlightGate`.
|
|
47
|
+
*/
|
|
48
|
+
deferHighlight?: boolean;
|
|
9
49
|
}
|
|
10
50
|
export interface UseVariantSelectionResult {
|
|
11
51
|
variantKeys: string[];
|
|
12
52
|
selectedVariantKey: string;
|
|
13
53
|
selectedVariant: VariantCode | null;
|
|
54
|
+
/**
|
|
55
|
+
* Engine-committed variant key. Lags `selectedVariantKey` by
|
|
56
|
+
* `variantSwapDelay` ms when a delay is configured and a swap is
|
|
57
|
+
* in flight, otherwise equal to `selectedVariantKey`. Consumers
|
|
58
|
+
* that render the variant's file tree should key off this value
|
|
59
|
+
* so the outgoing tree stays put while the pre-swap animation
|
|
60
|
+
* window plays out.
|
|
61
|
+
*/
|
|
62
|
+
committedVariantKey: string;
|
|
63
|
+
/**
|
|
64
|
+
* Variant resolved from `committedVariantKey`. See
|
|
65
|
+
* `committedVariantKey` for the lag semantics. `null` when the
|
|
66
|
+
* committed key doesn't resolve to a fully-loaded variant entry.
|
|
67
|
+
*/
|
|
68
|
+
committedVariant: VariantCode | null;
|
|
69
|
+
/**
|
|
70
|
+
* State of the in-flight variant-swap animation, or `null` when
|
|
71
|
+
* settled. Always `null` when `variantSwapDelay` is not set or is
|
|
72
|
+
* `0`. Mirrors `useTransformManagement`'s `transformingPhase`.
|
|
73
|
+
*
|
|
74
|
+
* Each swap progresses through up to four states, gated on
|
|
75
|
+
* `notifyVariantTransitionReady` calls from the rendered `<Pre>`:
|
|
76
|
+
*
|
|
77
|
+
* - `'collapsed'` pre-swap paused. Outgoing tree is rendered;
|
|
78
|
+
* the bridge `.collapse` placeholder is held at
|
|
79
|
+
* 0 height. Waiting for one paint cycle before
|
|
80
|
+
* releasing into the expand animation.
|
|
81
|
+
* - `'expanding'` pre-swap active. The bridge animates from 0
|
|
82
|
+
* up to the incoming variant's extra line
|
|
83
|
+
* count. Outgoing tree still rendered.
|
|
84
|
+
* - `'expanded'` post-swap paused. Incoming tree is now
|
|
85
|
+
* rendered; the bridge is held at the outgoing
|
|
86
|
+
* variant's extra height. Waiting for the new
|
|
87
|
+
* tree's HAST to paint before releasing.
|
|
88
|
+
* - `'collapsing'` post-swap active. The bridge animates from
|
|
89
|
+
* the outgoing variant's extra height back
|
|
90
|
+
* down to 0.
|
|
91
|
+
*/
|
|
92
|
+
variantSwappingPhase: TransitionPhase;
|
|
93
|
+
/**
|
|
94
|
+
* The "other" variant key participating in the in-flight swap:
|
|
95
|
+
* - During `'collapsed'` / `'expanding'`: the incoming variant
|
|
96
|
+
* (the user's intent target, equal to `selectedVariantKey`).
|
|
97
|
+
* - During `'expanded'` / `'collapsing'`: the outgoing variant
|
|
98
|
+
* we just transitioned away from, captured at the commit
|
|
99
|
+
* boundary.
|
|
100
|
+
* - `null` when no swap is in flight.
|
|
101
|
+
*
|
|
102
|
+
* Consumers use this to look up the partner variant's per-file
|
|
103
|
+
* line counts so `<Pre>` can append a bridge `.collapse`
|
|
104
|
+
* placeholder when the partner has more visible lines than the
|
|
105
|
+
* currently-rendered (committed) variant.
|
|
106
|
+
*/
|
|
107
|
+
swapPartnerVariantKey: string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Target of an in-flight variant swap that is still waiting on slow
|
|
110
|
+
* peers past the coordinator's grace window. `undefined` when no
|
|
111
|
+
* swap is pending. Only populated on the demo that originated the
|
|
112
|
+
* change; always `undefined` on peers and when no coordinator is
|
|
113
|
+
* configured.
|
|
114
|
+
*/
|
|
115
|
+
pendingVariantKey: string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* `true` while a stored-preference bootstrap swap is known to be
|
|
118
|
+
* in flight: a valid `storedValue` exists, differs from the
|
|
119
|
+
* currently-committed variant, and the engine has not yet
|
|
120
|
+
* committed past the initial mount value. Releases on the first
|
|
121
|
+
* commit (whether the bootstrap landed or a racing user click
|
|
122
|
+
* superseded it) so consumers can defer expensive work — most
|
|
123
|
+
* notably suppressing the outgoing initial variant's highlight
|
|
124
|
+
* render — without leaking suppression into normal interactive
|
|
125
|
+
* swaps.
|
|
126
|
+
*/
|
|
127
|
+
pendingBootstrap: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Callback the rendered `<Pre>` invokes (via its `onTransitionReady`
|
|
130
|
+
* prop) once it has painted the new tree at a paused phase value.
|
|
131
|
+
* Triggers the transition from `'collapsed' → 'expanding'` (pre-swap)
|
|
132
|
+
* or `'expanded' → 'collapsing'` (post-swap). Holding the active
|
|
133
|
+
* value off until the new tree has had a paint cycle prevents the
|
|
134
|
+
* keyframe / transition from running against raw-text spans that
|
|
135
|
+
* haven't yet been upgraded to highlighted HAST.
|
|
136
|
+
*/
|
|
137
|
+
notifyVariantTransitionReady: () => void;
|
|
14
138
|
selectVariant: React.Dispatch<React.SetStateAction<string | null>>;
|
|
15
139
|
selectVariantProgrammatic: React.Dispatch<React.SetStateAction<string>>;
|
|
16
140
|
saveVariantToLocalStorage: (variant: string) => void;
|
|
17
141
|
hashVariant: string | null;
|
|
18
142
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Hook for managing variant selection and providing variant-related data
|
|
21
|
-
* Priority: URL hash > localStorage > initialVariant > first variant
|
|
22
|
-
* When hash has a variant, it overrides localStorage and is saved to localStorage
|
|
23
|
-
*/
|
|
24
143
|
export declare function useVariantSelection({
|
|
25
144
|
effectiveCode,
|
|
26
145
|
initialVariant,
|
|
27
146
|
variantType,
|
|
28
147
|
mainSlug,
|
|
29
|
-
saveHashVariantToLocalStorage
|
|
148
|
+
saveHashVariantToLocalStorage,
|
|
149
|
+
variantLayoutShift,
|
|
150
|
+
selectedFileName,
|
|
151
|
+
expanded,
|
|
152
|
+
variantSwapDelay,
|
|
153
|
+
deferHighlight
|
|
30
154
|
}: UseVariantSelectionProps): UseVariantSelectionResult;
|
|
31
155
|
export {};
|