@mui/internal-docs-infra 0.11.1-canary.8 → 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 +85 -5
- 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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Document-level subscriber registry for `<details>` toggle events. Each
|
|
2
|
+
// `<Pre>` would otherwise install its own capture-phase listener; on docs
|
|
3
|
+
// pages with many code blocks that's N listeners all firing on every
|
|
4
|
+
// toggle anywhere in the document. A single shared listener fans out to
|
|
5
|
+
// the relevant subscribers instead.
|
|
6
|
+
//
|
|
7
|
+
// Subscribers register their `<pre>` element so the dispatcher can do a
|
|
8
|
+
// single `target.contains(pre)` ancestry check per subscriber and skip
|
|
9
|
+
// the nudge entirely for unrelated toggles — no JS-side work runs in
|
|
10
|
+
// `<Pre>` instances whose subtree the toggle didn't touch.
|
|
11
|
+
//
|
|
12
|
+
// The value is a Set rather than a single function so the registry
|
|
13
|
+
// tolerates the (unlikely but possible) case where two `<Pre>` instances
|
|
14
|
+
// transiently share the same DOM node — e.g. a fast unmount/remount
|
|
15
|
+
// where the next mount's setup runs before the prior mount's cleanup.
|
|
16
|
+
// Without the set the second subscribe would silently overwrite the
|
|
17
|
+
// first nudge and a single unsubscribe would orphan the other instance.
|
|
18
|
+
|
|
19
|
+
const toggleSubscribers = new Map();
|
|
20
|
+
let toggleListenerAttached = false;
|
|
21
|
+
let sharedToggleListener = null;
|
|
22
|
+
|
|
23
|
+
// Reconcile the document-level capture listener with the current
|
|
24
|
+
// subscriber set. Idempotent: callable from any code path (including
|
|
25
|
+
// test teardowns that want to defensively assert no leaked listener)
|
|
26
|
+
// without risk of leaving the document in a half-attached state.
|
|
27
|
+
function syncToggleListener() {
|
|
28
|
+
if (typeof document === 'undefined') {
|
|
29
|
+
if (toggleSubscribers.size === 0) {
|
|
30
|
+
sharedToggleListener = null;
|
|
31
|
+
toggleListenerAttached = false;
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (toggleSubscribers.size === 0) {
|
|
36
|
+
if (toggleListenerAttached && sharedToggleListener) {
|
|
37
|
+
document.removeEventListener('toggle', sharedToggleListener, true);
|
|
38
|
+
}
|
|
39
|
+
sharedToggleListener = null;
|
|
40
|
+
toggleListenerAttached = false;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!toggleListenerAttached || !sharedToggleListener) {
|
|
44
|
+
sharedToggleListener = event => {
|
|
45
|
+
const target = event.target;
|
|
46
|
+
if (!(target instanceof Node)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Snapshot before iterating: a nudge may synchronously trigger an
|
|
50
|
+
// unmount that mutates `toggleSubscribers` mid-dispatch. Iterating
|
|
51
|
+
// a snapshot keeps dispatch order independent of subscriber
|
|
52
|
+
// mutations and matches the snapshot pattern used by
|
|
53
|
+
// `sweepDetachedFrames` / `nudgeFrameObserver`.
|
|
54
|
+
Array.from(toggleSubscribers).forEach(([preNode, nudges]) => {
|
|
55
|
+
// Centralized ancestry filter: only nudge subscribers whose `<pre>`
|
|
56
|
+
// is a descendant of the toggled element. Done here (rather than
|
|
57
|
+
// in each subscriber) so unrelated toggles short-circuit before
|
|
58
|
+
// any subscriber-side work runs.
|
|
59
|
+
if (!target.contains(preNode)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
Array.from(nudges).forEach(nudge => nudge());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener('toggle', sharedToggleListener, true);
|
|
66
|
+
toggleListenerAttached = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function subscribeToggleNudge(preNode, nudge) {
|
|
70
|
+
// Defensive SSR no-op: there is no `document` to attach a listener to,
|
|
71
|
+
// and module state in Node persists across requests — leaking a
|
|
72
|
+
// subscriber here would also leak the closure it captures. `useEffect`
|
|
73
|
+
// already won't run on the server, but make the contract explicit so
|
|
74
|
+
// any future non-effect caller can't strand entries in the registry.
|
|
75
|
+
if (typeof document === 'undefined') {
|
|
76
|
+
return () => {};
|
|
77
|
+
}
|
|
78
|
+
let nudges = toggleSubscribers.get(preNode);
|
|
79
|
+
if (!nudges) {
|
|
80
|
+
nudges = new Set();
|
|
81
|
+
toggleSubscribers.set(preNode, nudges);
|
|
82
|
+
}
|
|
83
|
+
nudges.add(nudge);
|
|
84
|
+
syncToggleListener();
|
|
85
|
+
return () => {
|
|
86
|
+
const existing = toggleSubscribers.get(preNode);
|
|
87
|
+
if (existing) {
|
|
88
|
+
existing.delete(nudge);
|
|
89
|
+
if (existing.size === 0) {
|
|
90
|
+
toggleSubscribers.delete(preNode);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
syncToggleListener();
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CreateTransformedFiles } from "./TransformEngine.mjs";
|
|
2
|
+
import type { TransformEngineLoader } from "../CodeProvider/CodeContext.mjs";
|
|
3
|
+
/** Built-in loader, used when no provider supplies a `transformEngineLoader`. */
|
|
4
|
+
export declare const defaultTransformEngineLoader: TransformEngineLoader;
|
|
5
|
+
/** Synchronously reads the cached applier, or `undefined` if not yet resolved. */
|
|
6
|
+
export declare function peekTransformEngine(): CreateTransformedFiles | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the applier (from the warm cache, else via the loader) and caches it.
|
|
9
|
+
* Returns the cached value synchronously when warm. Rejects if the load fails;
|
|
10
|
+
* callers decide whether to surface or swallow that.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadTransformEngine(loader?: TransformEngineLoader): CreateTransformedFiles | Promise<CreateTransformedFiles>;
|
|
13
|
+
/**
|
|
14
|
+
* Eagerly resolves and caches the applier so the next transform swap (and the
|
|
15
|
+
* first transform-bearing block's first render) build synchronously instead of
|
|
16
|
+
* flashing un-transformed files. Fire-and-forget — fails open. Pass the provider's
|
|
17
|
+
* `transformEngineLoader` to share its page-wide deduplication.
|
|
18
|
+
*/
|
|
19
|
+
export declare function preloadTransformEngine(loader?: TransformEngineLoader): Promise<void>;
|
|
20
|
+
/** Clears the cache so the next resolve loads from scratch. For tests. */
|
|
21
|
+
export declare function resetTransformEngineCache(): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Set DEBUG=true to log transform-engine load failures (e.g. a chunk-load error
|
|
2
|
+
// after a rotated deploy, or offline). Off by default — a failed load fails open
|
|
3
|
+
// (transforms simply don't apply) per convention 9.3.
|
|
4
|
+
const DEBUG = false;
|
|
5
|
+
|
|
6
|
+
// Module-level cache of the resolved transform applier (`createTransformedFiles`,
|
|
7
|
+
// which pulls the `jsondiffpatch` chunk). Kept in this *light* module — which only
|
|
8
|
+
// reaches the heavy chunk through the dynamic `import()` below — so it can be
|
|
9
|
+
// primed by `CodeHighlighter`'s speculative preload (in the client chunk) AND read
|
|
10
|
+
// by `useTransformManagement` (in the content chunk) without either statically
|
|
11
|
+
// pulling the other in. The first transform-bearing block resolves it once; every
|
|
12
|
+
// block after reads it synchronously, so the swap-commit build stays synchronous.
|
|
13
|
+
let cached;
|
|
14
|
+
|
|
15
|
+
/** Built-in loader, used when no provider supplies a `transformEngineLoader`. */
|
|
16
|
+
export const defaultTransformEngineLoader = () => import("./TransformEngine.mjs").then(mod => mod.createTransformedFiles);
|
|
17
|
+
|
|
18
|
+
/** Synchronously reads the cached applier, or `undefined` if not yet resolved. */
|
|
19
|
+
export function peekTransformEngine() {
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the applier (from the warm cache, else via the loader) and caches it.
|
|
25
|
+
* Returns the cached value synchronously when warm. Rejects if the load fails;
|
|
26
|
+
* callers decide whether to surface or swallow that.
|
|
27
|
+
*/
|
|
28
|
+
export function loadTransformEngine(loader) {
|
|
29
|
+
if (cached) {
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
return (loader ?? defaultTransformEngineLoader)().then(create => {
|
|
33
|
+
cached = create;
|
|
34
|
+
return create;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Eagerly resolves and caches the applier so the next transform swap (and the
|
|
40
|
+
* first transform-bearing block's first render) build synchronously instead of
|
|
41
|
+
* flashing un-transformed files. Fire-and-forget — fails open. Pass the provider's
|
|
42
|
+
* `transformEngineLoader` to share its page-wide deduplication.
|
|
43
|
+
*/
|
|
44
|
+
export async function preloadTransformEngine(loader) {
|
|
45
|
+
if (cached) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
await loadTransformEngine(loader);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (DEBUG) {
|
|
52
|
+
console.error('[docs-infra] transform engine failed to preload', error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Clears the cache so the next resolve loads from scratch. For tests. */
|
|
58
|
+
export function resetTransformEngineCache() {
|
|
59
|
+
cached = undefined;
|
|
60
|
+
}
|
package/useCode/useCode.d.mts
CHANGED
|
@@ -3,7 +3,6 @@ import type { ContentProps, SourceEnhancers } from "../CodeHighlighter/types.mjs
|
|
|
3
3
|
import { type UseCopierOpts } from "../useCopier/index.mjs";
|
|
4
4
|
export type UseCodeOpts = {
|
|
5
5
|
preClassName?: string;
|
|
6
|
-
defaultOpen?: boolean;
|
|
7
6
|
copy?: UseCopierOpts;
|
|
8
7
|
githubUrlPrefix?: string;
|
|
9
8
|
initialVariant?: string;
|
|
@@ -31,6 +30,116 @@ export type UseCodeOpts = {
|
|
|
31
30
|
* Disables editing of the code block even when a CodeControllerContext is present.
|
|
32
31
|
*/
|
|
33
32
|
disabled?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Called when the code block is asked to expand its collapsed window — most
|
|
35
|
+
* importantly from the editor itself, when the caret navigates past the
|
|
36
|
+
* visible region (e.g. `ArrowUp` at the top of a collapsed block). Fires
|
|
37
|
+
* synchronously, *before* the expansion re-renders, so a host can capture the
|
|
38
|
+
* still-collapsed layout and engage a scroll anchor (e.g. `useCodeWindow`'s
|
|
39
|
+
* `anchorScroll('expand')`) — matching the timing of a click on the expand
|
|
40
|
+
* toggle. Without this, keyboard-driven expansion would jump the viewport
|
|
41
|
+
* instead of smoothly anchoring it.
|
|
42
|
+
*/
|
|
43
|
+
onExpand?: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Delay in milliseconds between a transform change and the actual swap
|
|
46
|
+
* of the rendered file tree to the new transform. `selectedTransform`
|
|
47
|
+
* still updates synchronously so UI controls reflect the change
|
|
48
|
+
* immediately — whether triggered by a user click in this demo or
|
|
49
|
+
* received as an external broadcast from a peer demo. While the swap
|
|
50
|
+
* is pending the rendered `<pre>` element receives a `data-transforming`
|
|
51
|
+
* attribute so consumer CSS can run an exit animation — most notably
|
|
52
|
+
* expanding `.collapse` placeholders back to their original height —
|
|
53
|
+
* before the new tree replaces them. When omitted or `0`, the new
|
|
54
|
+
* transform commits synchronously (default behavior).
|
|
55
|
+
*/
|
|
56
|
+
transformDelay?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Delay in milliseconds between a variant change and the actual
|
|
59
|
+
* swap of the rendered file tree to the new variant. `selectedVariant`
|
|
60
|
+
* still updates synchronously so UI controls (tabs, dropdowns)
|
|
61
|
+
* reflect the change immediately — whether triggered by a user
|
|
62
|
+
* click in this demo or received as an external broadcast from a
|
|
63
|
+
* peer demo. While the swap is pending the rendered `<pre>` element
|
|
64
|
+
* receives a `data-transforming` attribute, and `<Pre>` appends a
|
|
65
|
+
* bridge `<span class="collapse">` to the shorter of the two
|
|
66
|
+
* variants' rendered tree so consumer CSS can animate between the
|
|
67
|
+
* two heights before the swap commits. When omitted or `0`, the
|
|
68
|
+
* new variant commits synchronously (default behavior).
|
|
69
|
+
*/
|
|
70
|
+
variantSwapDelay?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Controls which transforms are treated as layout-affecting (phase 1,
|
|
73
|
+
* coordinated barrier) versus non-layout (phase 2, deferred). All
|
|
74
|
+
* options consult the precomputed `hasCollapse` /
|
|
75
|
+
* `hasCollapseInFocus` flags on each transform manifest entry — no
|
|
76
|
+
* tree walking happens at runtime.
|
|
77
|
+
*
|
|
78
|
+
* - `'all'` — Phase 1 if *any* file (main or `extraFiles`) in the
|
|
79
|
+
* selected variant has `hasCollapse: true`. Most conservative;
|
|
80
|
+
* matches the historical pre-`transformLayoutShift` behavior.
|
|
81
|
+
* - `'selected'` (default) — Phase 1 only when the currently
|
|
82
|
+
* rendered file's transform has `hasCollapse: true`. Avoids
|
|
83
|
+
* coordinating swaps that wouldn't visibly shift the rendered
|
|
84
|
+
* pre.
|
|
85
|
+
* - `'focus'` — Like `'selected'`, but while the surrounding code
|
|
86
|
+
* block is *collapsed* (un-expanded), use `hasCollapseInFocus`
|
|
87
|
+
* instead of `hasCollapse`. A `.collapse` placeholder outside
|
|
88
|
+
* the initially-visible region (the lines covered by
|
|
89
|
+
* `data-frame-type` ∈ `'highlighted' | 'focus' | 'padding-top' |
|
|
90
|
+
* 'padding-bottom'`) won't trigger the coordinated barrier
|
|
91
|
+
* because the user can't see the resulting layout shift. Falls
|
|
92
|
+
* back to `'selected'`-style behavior when expanded.
|
|
93
|
+
*/
|
|
94
|
+
transformLayoutShift?: 'all' | 'selected' | 'focus';
|
|
95
|
+
/**
|
|
96
|
+
* When `true`, throws synchronously during render if any transform
|
|
97
|
+
* on any variant has `hasCollapseInFocus: true` — i.e. its
|
|
98
|
+
* `.collapse` placeholder lands inside the focus region that is
|
|
99
|
+
* visible while the surrounding code block is un-expanded. The
|
|
100
|
+
* thrown error names the offending variant/file/transform so the
|
|
101
|
+
* demo author can narrow the `@focus` (or `@padding`) markers, or
|
|
102
|
+
* shrink the transform's edit range, until the placeholder lands
|
|
103
|
+
* outside the initially-visible window. Pair with
|
|
104
|
+
* `transformLayoutShift: 'focus'` to guarantee no coordinated
|
|
105
|
+
* barrier swaps fire while the block is collapsed.
|
|
106
|
+
*/
|
|
107
|
+
strictCollapseInFocus?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Controls which variant swaps are treated as layout-affecting
|
|
110
|
+
* (phase 1, coordinated barrier) versus non-layout (phase 2,
|
|
111
|
+
* deferred). The check consults `totalLines` / `focusedLines`
|
|
112
|
+
* metadata precomputed by the pipeline — no tree walking happens
|
|
113
|
+
* at runtime.
|
|
114
|
+
*
|
|
115
|
+
* - `'all'` — Phase 1 when the sum of `totalLines` across every
|
|
116
|
+
* file (main + `extraFiles`) differs between the from-variant
|
|
117
|
+
* and the to-variant. Useful when the rendering surface shows
|
|
118
|
+
* all files simultaneously.
|
|
119
|
+
* - `'selected'` (default) — Phase 1 when the currently selected
|
|
120
|
+
* file's `totalLines` differs between the two variants (or
|
|
121
|
+
* the file is missing from one side). Avoids coordinating
|
|
122
|
+
* swaps that wouldn't visibly shift the rendered pre.
|
|
123
|
+
* - `'focus'` — Like `'selected'`, but while the surrounding
|
|
124
|
+
* code block is *collapsed* (un-expanded), compare
|
|
125
|
+
* `focusedLines` (the size of the visible window when
|
|
126
|
+
* collapsed) instead of `totalLines`. Recommended for demos
|
|
127
|
+
* that use `@focus` / `@padding` markers to collapse to a
|
|
128
|
+
* specific region.
|
|
129
|
+
*/
|
|
130
|
+
variantLayoutShift?: 'all' | 'selected' | 'focus';
|
|
131
|
+
/**
|
|
132
|
+
* When `true`, throws synchronously during render if any two
|
|
133
|
+
* variants declare a file with the same name but a different
|
|
134
|
+
* `focusedLines` count. Pair with `variantLayoutShift: 'focus'`
|
|
135
|
+
* to guarantee no coordinated barrier swaps fire while the block
|
|
136
|
+
* is collapsed: when every shared file's focused window matches
|
|
137
|
+
* across variants, switching variants can never shift the
|
|
138
|
+
* collapsed pre's height. The thrown error names the offending
|
|
139
|
+
* variants / file so the demo author can align the
|
|
140
|
+
* `@focus` / `@padding` markers.
|
|
141
|
+
*/
|
|
142
|
+
strictMatchingVariantFocusedLines?: boolean;
|
|
34
143
|
};
|
|
35
144
|
type UserProps<T extends {} = {}> = T & {
|
|
36
145
|
name?: string;
|
|
@@ -54,6 +163,13 @@ export interface UseCodeResult<T extends {} = {}> {
|
|
|
54
163
|
* the variant has no `url` or the URL cannot be resolved.
|
|
55
164
|
*/
|
|
56
165
|
selectedFileUrl: string | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Slug for the currently selected file. Always derived from the canonical
|
|
168
|
+
* (original) file name — transforms are a view preference and do not
|
|
169
|
+
* produce separate slugs. Useful for building permalinks (e.g. `#${slug}`)
|
|
170
|
+
* that survive transform changes.
|
|
171
|
+
*/
|
|
172
|
+
selectedFileSlug: string | undefined;
|
|
57
173
|
selectFileName: (fileName: string) => void;
|
|
58
174
|
allFilesSlugs: Array<{
|
|
59
175
|
fileName: string;
|
|
@@ -72,6 +188,21 @@ export interface UseCodeResult<T extends {} = {}> {
|
|
|
72
188
|
availableTransforms: string[];
|
|
73
189
|
selectedTransform: string | null | undefined;
|
|
74
190
|
selectTransform: (transformName: string | null) => void;
|
|
191
|
+
/**
|
|
192
|
+
* Target of an in-flight transform swap that is still waiting on
|
|
193
|
+
* slow peers to catch up. `undefined` when no swap is pending or
|
|
194
|
+
* shortly after one commits. Otherwise mirrors the shape of
|
|
195
|
+
* `selectedTransform`: `null` for a pending swap back to the
|
|
196
|
+
* un-transformed original, or the transform name for a pending
|
|
197
|
+
* swap to that transform. Consumers can check
|
|
198
|
+
* `pendingTransform !== undefined` to render a generic loading
|
|
199
|
+
* indicator, or read the value to render something like
|
|
200
|
+
* `` `Switching to ${pendingTransform ?? 'original'}…` ``. Only
|
|
201
|
+
* populated on the demo that originated the change — peer demos
|
|
202
|
+
* receiving the broadcast keep this `undefined` so the indicator
|
|
203
|
+
* stays anchored to the demo the user interacted with.
|
|
204
|
+
*/
|
|
205
|
+
pendingTransform: string | null | undefined;
|
|
75
206
|
/**
|
|
76
207
|
* Replace the source of the currently selected file (or `fileName` when
|
|
77
208
|
* provided) in the controlled code. Internal hooks may pass additional
|
|
@@ -87,6 +218,14 @@ export interface UseCodeResult<T extends {} = {}> {
|
|
|
87
218
|
* is in scope and editing is not disabled.
|
|
88
219
|
*/
|
|
89
220
|
reset?: () => void;
|
|
221
|
+
/**
|
|
222
|
+
* Re-fetches the block's data on the client by re-running the full variant
|
|
223
|
+
* loader, then swaps in the fresh result while keeping the current highlighted
|
|
224
|
+
* output visible until the new tree lands (stale-while-revalidate). Invalidates
|
|
225
|
+
* the pre-parsed HAST cache. `undefined` (or a no-op) for a block with no `url`
|
|
226
|
+
* to re-fetch from, or with no `CodeProvider` in scope.
|
|
227
|
+
*/
|
|
228
|
+
refresh?: () => void;
|
|
90
229
|
userProps: UserProps<T>;
|
|
91
230
|
}
|
|
92
231
|
export declare function useCode<T extends {} = {}>(contentProps: ContentProps<T>, opts?: UseCodeOpts): UseCodeResult<T>;
|