@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
|
@@ -36,11 +36,28 @@ export type UseCodeWindowOptions = {
|
|
|
36
36
|
*/
|
|
37
37
|
collapsibleProbeSelector?: string;
|
|
38
38
|
};
|
|
39
|
-
export type UseCodeWindowResult<ToggleElement extends HTMLElement = HTMLElement> = {
|
|
39
|
+
export type UseCodeWindowResult<ToggleElement extends HTMLElement = HTMLElement, ScrollElement extends HTMLElement = HTMLElement> = {
|
|
40
40
|
/**
|
|
41
41
|
* Ref to attach to the collapsible container element.
|
|
42
42
|
*/
|
|
43
43
|
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional ref to attach to a scrollable ancestor that should be
|
|
46
|
+
* compensated instead of the page. Attach it when the code block is
|
|
47
|
+
* rendered as a fixed-height "window" (its own `overflow: auto` region)
|
|
48
|
+
* so the anchor stays put against the panel's own scroll rather than the
|
|
49
|
+
* page. When left unattached, the page is compensated — the right default
|
|
50
|
+
* for code that grows the document flow. Forwarded from `useScrollAnchor`.
|
|
51
|
+
*
|
|
52
|
+
* When attached, this element is also treated as the horizontal scroll
|
|
53
|
+
* owner: the scrollbar-gutter swap (`data-scrollbar-gutter`) and the
|
|
54
|
+
* collapse scroll-back run on it instead of the inner `<pre>`. Use this when
|
|
55
|
+
* the window owns both scroll axes so the horizontal scrollbar sits at the
|
|
56
|
+
* window's edge (in view) rather than at the bottom of the inner `<pre>`,
|
|
57
|
+
* which can extend past the window's height and scroll out of view. Your
|
|
58
|
+
* gutter CSS must then key off this element's attribute.
|
|
59
|
+
*/
|
|
60
|
+
scrollContainerRef: React.RefObject<ScrollElement | null>;
|
|
44
61
|
/**
|
|
45
62
|
* Ref to attach to the toggle element. Used as a fallback anchor
|
|
46
63
|
* when the primary anchor is offscreen on collapse.
|
|
@@ -84,4 +101,4 @@ export type UseCodeWindowResult<ToggleElement extends HTMLElement = HTMLElement>
|
|
|
84
101
|
* Anchor selection and the collapsible probe are configurable so it works
|
|
85
102
|
* with any highlighter that marks frames with data attributes.
|
|
86
103
|
*/
|
|
87
|
-
export declare function useCodeWindow<ToggleElement extends HTMLElement = HTMLElement>(options?: UseCodeWindowOptions): UseCodeWindowResult<ToggleElement>;
|
|
104
|
+
export declare function useCodeWindow<ToggleElement extends HTMLElement = HTMLElement, ScrollElement extends HTMLElement = HTMLElement>(options?: UseCodeWindowOptions): UseCodeWindowResult<ToggleElement, ScrollElement>;
|
|
@@ -53,33 +53,38 @@ function cancelScheduled(handle) {
|
|
|
53
53
|
* Smoothly slides the `<code>` element back to the left edge over `duration`
|
|
54
54
|
* ms using an ease-out cubic via the Web Animations API.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* `scrollEl` is whichever element owns the horizontal scroll — the inner
|
|
57
|
+
* `<pre>` by default, or an attached scroll container (see `scrollContainerRef`)
|
|
58
|
+
* when the code block is rendered inside a fixed-size window. `code` is this
|
|
59
|
+
* code window's own `<code>` (scoped to its container by the caller) so a shared
|
|
60
|
+
* scroll container holding several blocks animates the right one.
|
|
61
|
+
*
|
|
62
|
+
* Used during collapse instead of tweening `scrollEl.scrollLeft` because the
|
|
63
|
+
* scrollbar-gutter animation forces `overflow-x: hidden` on `scrollEl`, which
|
|
58
64
|
* snaps `scrollLeft` to 0 instantly. Animating a transform on the inner
|
|
59
65
|
* `code` element produces the same visual effect, isn't reset by the overflow
|
|
60
|
-
* change, and is naturally clipped by the
|
|
66
|
+
* change, and is naturally clipped by the scroll element's hidden overflow.
|
|
61
67
|
*
|
|
62
68
|
* Honors `prefers-reduced-motion` by snapping immediately.
|
|
63
69
|
*/
|
|
64
|
-
function smoothCollapseScrollLeft(
|
|
65
|
-
const startLeft =
|
|
70
|
+
function smoothCollapseScrollLeft(scrollEl, code, duration) {
|
|
71
|
+
const startLeft = scrollEl.scrollLeft;
|
|
66
72
|
if (startLeft <= 0) {
|
|
67
73
|
return null;
|
|
68
74
|
}
|
|
69
|
-
const code = pre.querySelector('code');
|
|
70
|
-
if (!code || typeof code.animate !== 'function') {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
75
|
|
|
74
76
|
// Cancel any leftover scroll-back animation from a previous toggle so we
|
|
75
77
|
// don't end up with two transforms competing on the same element.
|
|
76
|
-
scrollbackAnimations.get(
|
|
77
|
-
scrollbackAnimations.delete(
|
|
78
|
+
scrollbackAnimations.get(scrollEl)?.cancel();
|
|
79
|
+
scrollbackAnimations.delete(scrollEl);
|
|
78
80
|
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// Snap the actual scroll position back to the left edge now. When we can
|
|
82
|
+
// animate, the WAAPI transform below visually compensates by translating the
|
|
83
|
+
// element from `-startLeft` back to `0`; otherwise (no WAAPI, no `code`,
|
|
84
|
+
// reduced motion, or zero duration) this stands as an instant snap — still
|
|
85
|
+
// the correct collapsed end state.
|
|
86
|
+
scrollEl.scrollLeft = 0;
|
|
87
|
+
if (!code || typeof code.animate !== 'function' || prefersReducedMotion() || duration <= 0) {
|
|
83
88
|
return null;
|
|
84
89
|
}
|
|
85
90
|
const anim = code.animate([{
|
|
@@ -91,10 +96,10 @@ function smoothCollapseScrollLeft(pre, duration) {
|
|
|
91
96
|
easing: 'cubic-bezier(0, 0, 0.2, 1)',
|
|
92
97
|
fill: 'none'
|
|
93
98
|
});
|
|
94
|
-
scrollbackAnimations.set(
|
|
99
|
+
scrollbackAnimations.set(scrollEl, anim);
|
|
95
100
|
const onSettle = () => {
|
|
96
|
-
if (scrollbackAnimations.get(
|
|
97
|
-
scrollbackAnimations.delete(
|
|
101
|
+
if (scrollbackAnimations.get(scrollEl) === anim) {
|
|
102
|
+
scrollbackAnimations.delete(scrollEl);
|
|
98
103
|
}
|
|
99
104
|
};
|
|
100
105
|
anim.finished.then(onSettle, onSettle);
|
|
@@ -106,74 +111,84 @@ function isElementInViewport(element) {
|
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
/**
|
|
109
|
-
* Measures the horizontal scrollbar height of
|
|
114
|
+
* Measures the horizontal scrollbar height of the scroll element by
|
|
110
115
|
* temporarily forcing `overflow-x: scroll`.
|
|
111
116
|
*/
|
|
112
|
-
function measureScrollbarHeight(
|
|
113
|
-
const prevOverflow =
|
|
114
|
-
|
|
115
|
-
const scrollbarHeight =
|
|
116
|
-
|
|
117
|
+
function measureScrollbarHeight(scrollEl) {
|
|
118
|
+
const prevOverflow = scrollEl.style.overflowX;
|
|
119
|
+
scrollEl.style.overflowX = 'scroll';
|
|
120
|
+
const scrollbarHeight = scrollEl.offsetHeight - scrollEl.clientHeight;
|
|
121
|
+
scrollEl.style.overflowX = prevOverflow;
|
|
117
122
|
return scrollbarHeight;
|
|
118
123
|
}
|
|
119
|
-
function clearGutterState(
|
|
120
|
-
cancelScheduled(gutterCleanupTimers.get(
|
|
121
|
-
gutterCleanupTimers.delete(
|
|
122
|
-
const flipTimer = gutterFlipTimers.get(
|
|
124
|
+
function clearGutterState(scrollEl) {
|
|
125
|
+
cancelScheduled(gutterCleanupTimers.get(scrollEl));
|
|
126
|
+
gutterCleanupTimers.delete(scrollEl);
|
|
127
|
+
const flipTimer = gutterFlipTimers.get(scrollEl);
|
|
123
128
|
if (flipTimer !== undefined) {
|
|
124
129
|
clearTimeout(flipTimer);
|
|
125
|
-
gutterFlipTimers.delete(
|
|
130
|
+
gutterFlipTimers.delete(scrollEl);
|
|
126
131
|
}
|
|
127
|
-
|
|
132
|
+
scrollEl.removeAttribute(GUTTER_STATE_ATTRIBUTE);
|
|
128
133
|
}
|
|
129
|
-
function
|
|
130
|
-
scrollbackAnimations.get(
|
|
131
|
-
scrollbackAnimations.delete(
|
|
132
|
-
clearGutterState(
|
|
134
|
+
function cancelAllForScrollEl(scrollEl) {
|
|
135
|
+
scrollbackAnimations.get(scrollEl)?.cancel();
|
|
136
|
+
scrollbackAnimations.delete(scrollEl);
|
|
137
|
+
clearGutterState(scrollEl);
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
/**
|
|
136
141
|
* Drives a from→to transition on the `data-scrollbar-gutter` attribute of
|
|
137
|
-
*
|
|
138
|
-
* a real scrollbar and equivalent padding-bottom.
|
|
142
|
+
* the scroll element, which the consumer's CSS hooks into to animate the swap
|
|
143
|
+
* between a real scrollbar and equivalent padding-bottom.
|
|
144
|
+
*
|
|
145
|
+
* `scrollEl` is whichever element owns the horizontal scroll — the inner
|
|
146
|
+
* `<pre>` by default, or the attached `scrollContainerRef` when the code block
|
|
147
|
+
* is rendered inside a fixed-size window. `code` is this code window's own
|
|
148
|
+
* `<code>` (scoped to its container by the caller).
|
|
139
149
|
*
|
|
140
150
|
* Skips the animation when content doesn't overflow (no scrollbar exists)
|
|
141
151
|
* or when the browser uses overlay scrollbars (zero height).
|
|
142
152
|
*/
|
|
143
|
-
function animateScrollbarGutter(
|
|
144
|
-
const scrollbarHeight = measureScrollbarHeight(
|
|
153
|
+
function animateScrollbarGutter(scrollEl, code, from, to, durationMs) {
|
|
154
|
+
const scrollbarHeight = measureScrollbarHeight(scrollEl);
|
|
145
155
|
if (scrollbarHeight === 0) {
|
|
146
156
|
return; // Overlay scrollbars, nothing to do
|
|
147
157
|
}
|
|
148
158
|
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// scrollWidth
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
// Decide from this code window's own `<code>`, not from `scrollEl` — the
|
|
160
|
+
// scroll owner may be a shared container wrapping other content. `code`'s
|
|
161
|
+
// `scrollWidth` reflects hidden frames (via `min-width: fit-content`), so it
|
|
162
|
+
// predicts the post-expand width and still reflects the wide source during
|
|
163
|
+
// collapse; compare it against the scroll owner's visible width.
|
|
164
|
+
//
|
|
165
|
+
// Exception: a collapse-to-empty block (`data-focused-lines="0"`) shows
|
|
166
|
+
// nothing while collapsed, so its `scrollWidth` can't predict the post-expand
|
|
167
|
+
// width that way. On expand, run the swap anyway so `overflow-x` stays hidden
|
|
168
|
+
// through the reveal instead of flashing a scrollbar; if the expanded source
|
|
169
|
+
// turns out to fit, the swap simply ends without one. On collapse the current
|
|
170
|
+
// width is real, so the normal skip still applies.
|
|
171
|
+
const widthUnknownOnExpand = from === 'expand-from' && code?.getAttribute('data-focused-lines') === '0';
|
|
172
|
+
if (!code || !widthUnknownOnExpand && code.scrollWidth <= scrollEl.clientWidth) {
|
|
158
173
|
return;
|
|
159
174
|
}
|
|
160
|
-
clearGutterState(
|
|
161
|
-
|
|
175
|
+
clearGutterState(scrollEl);
|
|
176
|
+
scrollEl.setAttribute(GUTTER_STATE_ATTRIBUTE, from);
|
|
162
177
|
|
|
163
178
|
// Move into the transition state on the next macrotask. Tracked so the
|
|
164
179
|
// flip can be cancelled if the component unmounts before it fires.
|
|
165
180
|
const flipTimer = setTimeout(() => {
|
|
166
|
-
gutterFlipTimers.delete(
|
|
167
|
-
|
|
181
|
+
gutterFlipTimers.delete(scrollEl);
|
|
182
|
+
scrollEl.setAttribute(GUTTER_STATE_ATTRIBUTE, to);
|
|
168
183
|
}, 0);
|
|
169
|
-
gutterFlipTimers.set(
|
|
184
|
+
gutterFlipTimers.set(scrollEl, flipTimer);
|
|
170
185
|
|
|
171
186
|
// Schedule cleanup on the animation timeline so DevTools throttling
|
|
172
187
|
// scales it together with the CSS transition.
|
|
173
|
-
const cleanup = scheduleOnAnimationTimeline(
|
|
174
|
-
clearGutterState(
|
|
188
|
+
const cleanup = scheduleOnAnimationTimeline(scrollEl, durationMs + 30, () => {
|
|
189
|
+
clearGutterState(scrollEl);
|
|
175
190
|
});
|
|
176
|
-
gutterCleanupTimers.set(
|
|
191
|
+
gutterCleanupTimers.set(scrollEl, cleanup);
|
|
177
192
|
}
|
|
178
193
|
const DEFAULT_ANCHOR_SELECTOR = '[data-frame-type="highlighted"], [data-frame-type="focus"]';
|
|
179
194
|
const DEFAULT_COLLAPSIBLE_SELECTOR = '[data-collapsible]';
|
|
@@ -218,17 +233,18 @@ export function useCodeWindow(options = {}) {
|
|
|
218
233
|
collapsibleProbeSelector = DEFAULT_COLLAPSIBLE_SELECTOR
|
|
219
234
|
} = options;
|
|
220
235
|
const toggleRef = React.useRef(null);
|
|
221
|
-
const
|
|
236
|
+
const lastScrollElRef = React.useRef(null);
|
|
222
237
|
const {
|
|
223
238
|
containerRef,
|
|
239
|
+
scrollContainerRef,
|
|
224
240
|
anchorScroll: rawAnchorScroll
|
|
225
241
|
} = useScrollAnchor();
|
|
226
242
|
React.useEffect(() => {
|
|
227
243
|
return () => {
|
|
228
|
-
const
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
244
|
+
const scrollEl = lastScrollElRef.current;
|
|
245
|
+
if (scrollEl) {
|
|
246
|
+
cancelAllForScrollEl(scrollEl);
|
|
247
|
+
lastScrollElRef.current = null;
|
|
232
248
|
}
|
|
233
249
|
};
|
|
234
250
|
}, []);
|
|
@@ -246,34 +262,45 @@ export function useCodeWindow(options = {}) {
|
|
|
246
262
|
if (!anchor) {
|
|
247
263
|
return;
|
|
248
264
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
265
|
+
|
|
266
|
+
// The element whose horizontal scrollbar we smooth: the attached scroll
|
|
267
|
+
// container when one is provided (the code block lives inside a
|
|
268
|
+
// fixed-size window that owns both scroll axes), otherwise the inner
|
|
269
|
+
// `<pre>`, which scrolls horizontally on its own.
|
|
270
|
+
const scrollEl = scrollContainerRef.current ?? container.querySelector('pre');
|
|
271
|
+
// Scope content lookups to *this* code window's `container`, never to
|
|
272
|
+
// `scrollEl`: an attached scroll container may wrap several code blocks or
|
|
273
|
+
// unrelated content, so `scrollEl.querySelector('code')` could match the
|
|
274
|
+
// wrong block. The overflow decision and scroll-back both use this code.
|
|
275
|
+
const code = container.querySelector('code');
|
|
276
|
+
if (scrollEl) {
|
|
277
|
+
lastScrollElRef.current = scrollEl;
|
|
252
278
|
if (direction === 'collapse') {
|
|
253
279
|
// Smoothly return horizontal scroll to the left edge. We animate
|
|
254
280
|
// via a transform on the inner `code` element rather than
|
|
255
|
-
// tweening `
|
|
281
|
+
// tweening `scrollEl.scrollLeft`, because the gutter animation below
|
|
256
282
|
// sets `overflow-x: hidden` which would snap `scrollLeft` to 0
|
|
257
283
|
// instantly. Both animations start in the same frame: the
|
|
258
284
|
// scroll-back resets `scrollLeft` to 0 up front, so the gutter
|
|
259
285
|
// swap's `overflow-x` change has nothing left to snap.
|
|
260
|
-
smoothCollapseScrollLeft(
|
|
261
|
-
animateScrollbarGutter(
|
|
286
|
+
smoothCollapseScrollLeft(scrollEl, code, scrollBackDuration);
|
|
287
|
+
animateScrollbarGutter(scrollEl, code, 'collapse-from', 'collapse-to', collapseDuration);
|
|
262
288
|
}
|
|
263
289
|
if (direction === 'expand') {
|
|
264
290
|
// Cancel any in-flight collapse scroll-back so its leftover
|
|
265
291
|
// transform can't drift the code horizontally during expand.
|
|
266
|
-
scrollbackAnimations.get(
|
|
267
|
-
scrollbackAnimations.delete(
|
|
268
|
-
if (collapsibleProbeSelector &&
|
|
269
|
-
animateScrollbarGutter(
|
|
292
|
+
scrollbackAnimations.get(scrollEl)?.cancel();
|
|
293
|
+
scrollbackAnimations.delete(scrollEl);
|
|
294
|
+
if (collapsibleProbeSelector && container.querySelector(collapsibleProbeSelector)) {
|
|
295
|
+
animateScrollbarGutter(scrollEl, code, 'expand-from', 'expand-to', expandDuration);
|
|
270
296
|
}
|
|
271
297
|
}
|
|
272
298
|
}
|
|
273
299
|
rawAnchorScroll(anchor, direction === 'collapse' ? collapseDuration : expandDuration);
|
|
274
|
-
}, [containerRef, rawAnchorScroll, anchorSelector, collapsibleProbeSelector, collapseDuration, expandDuration, scrollBackDuration]);
|
|
300
|
+
}, [containerRef, scrollContainerRef, rawAnchorScroll, anchorSelector, collapsibleProbeSelector, collapseDuration, expandDuration, scrollBackDuration]);
|
|
275
301
|
return {
|
|
276
302
|
containerRef,
|
|
303
|
+
scrollContainerRef,
|
|
277
304
|
toggleRef,
|
|
278
305
|
anchorScroll
|
|
279
306
|
};
|