@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type Code, type ControlledCode, type HastRoot } from "./types.mjs";
|
|
2
|
+
import { type Code, type ControlledCode, type Fallbacks, type HastRoot } from "./types.mjs";
|
|
3
3
|
import { type Selection } from "../CodeControllerContext/index.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* One cached pre-parsed file. Stored per-fileName: each new write replaces
|
|
@@ -21,6 +21,62 @@ export interface CodeHighlighterContextType {
|
|
|
21
21
|
availableTransforms?: string[];
|
|
22
22
|
url?: string;
|
|
23
23
|
deferHighlight?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
/**
|
|
26
|
+
* Compact fallback data for the active variant, keyed by fileName.
|
|
27
|
+
* Used by `Pre` to both render the fallback and derive text dictionaries
|
|
28
|
+
* for decompressing `hastCompressed` payloads.
|
|
29
|
+
*/
|
|
30
|
+
fallbacks?: Fallbacks;
|
|
31
|
+
/**
|
|
32
|
+
* Render-side readiness gate. `true` once the highlight trigger
|
|
33
|
+
* (`init` / `hydration` / `idle` / `visible`) has fired *and* the
|
|
34
|
+
* sync `parseCode` pass has resolved, so consumers like `<Pre>`
|
|
35
|
+
* can render the published `code` as highlighted HAST. While
|
|
36
|
+
* `false` they should render the un-highlighted fallback (plain
|
|
37
|
+
* text) — the published `code` may still contain precomputed HAST
|
|
38
|
+
* left over from SSR, so without this gate non-`init` demos would
|
|
39
|
+
* render highlighted spans on the first paint and defeat the
|
|
40
|
+
* deferred-highlighting trigger.
|
|
41
|
+
*
|
|
42
|
+
* Distinct from `deferHighlight`, which is the narrower
|
|
43
|
+
* "highlight pass is actively in flight" signal consumed by
|
|
44
|
+
* barrier gates (e.g. `useTransformManagement.awaitHighlight`)
|
|
45
|
+
* that must not block when no work is queued.
|
|
46
|
+
*/
|
|
47
|
+
highlightReady?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Echo of the `highlightAfter` prop on the surrounding
|
|
50
|
+
* `CodeHighlighter` / `CodeHighlighterClient`. Consumers such as
|
|
51
|
+
* `useCode` use this to skip transient highlighting-suppression
|
|
52
|
+
* gates that only matter when highlighting is asynchronous — in
|
|
53
|
+
* `'init'` mode the precomputed HAST already carries the highlight
|
|
54
|
+
* spans, so those gates would just cause a visible flash of
|
|
55
|
+
* unhighlighted content during variant swaps.
|
|
56
|
+
*/
|
|
57
|
+
highlightAfter?: 'init' | 'hydration' | 'idle';
|
|
58
|
+
/**
|
|
59
|
+
* Echo of the `editActivation` prop on the surrounding `CodeHighlighter` /
|
|
60
|
+
* `CodeHighlighterClient`. `useCode` reads it from here and threads it down to
|
|
61
|
+
* `useEditable` (which defers the `contentEditable` attach when
|
|
62
|
+
* `'interaction'`), so the editing-activation strategy can be configured at
|
|
63
|
+
* the `CodeHighlighter` / demo level rather than inside the content subtree.
|
|
64
|
+
*/
|
|
65
|
+
editActivation?: 'eager' | 'interaction';
|
|
66
|
+
/**
|
|
67
|
+
* Callback `useCode` threads down to `useEditable`'s `onActivate`, fired once
|
|
68
|
+
* when the block first engages for editing. `CodeHighlighterClient` supplies it
|
|
69
|
+
* to flip its per-block `activated` state (warming the live-editing engine,
|
|
70
|
+
* grammars, and worker) and to notify the `CodeControllerContext`.
|
|
71
|
+
*/
|
|
72
|
+
onEditingActivated?: () => void;
|
|
73
|
+
/**
|
|
74
|
+
* Re-runs the full variant loader on the client and swaps in fresh data,
|
|
75
|
+
* keeping the current highlighted output visible until the new tree lands
|
|
76
|
+
* (stale-while-revalidate). Invalidates the pre-parsed HAST cache. A no-op for
|
|
77
|
+
* a block with no `url` to re-fetch from. Surfaced through `useCode`/`useDemo`.
|
|
78
|
+
*/
|
|
79
|
+
refresh?: () => void;
|
|
24
80
|
/**
|
|
25
81
|
* Per-file pre-parsed HAST cache. Populated by `useSourceEditing` when the
|
|
26
82
|
* editable supplies a worker-parsed result alongside a source change, and
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export interface CodeHighlighterFallbackContext
|
|
2
|
+
import type { Fallbacks, ContentLoadingVariant } from "./types.mjs";
|
|
3
|
+
export interface CodeHighlighterFallbackContext {
|
|
4
4
|
extraVariants?: Record<string, ContentLoadingVariant>;
|
|
5
|
+
/**
|
|
6
|
+
* Callback used by `useCodeFallback` to hoist fallback data
|
|
7
|
+
* back to `CodeHighlighterClient` so it can derive text dictionaries
|
|
8
|
+
* for decompressing `hastCompressed` payloads.
|
|
9
|
+
*/
|
|
10
|
+
setFallbackHasts?: (variantName: string, hasts: Fallbacks) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Callback invoked by `useCodeFallback` in an effect to signal that
|
|
13
|
+
* the hook was used. Allows the parent to detect when a ContentLoading
|
|
14
|
+
* component forgets to call the hook.
|
|
15
|
+
*/
|
|
16
|
+
onHookCalled?: () => void;
|
|
5
17
|
}
|
|
6
18
|
export declare const CodeHighlighterFallbackContext: React.Context<CodeHighlighterFallbackContext | undefined>;
|
|
7
19
|
export declare function useCodeHighlighterFallbackContext(): CodeHighlighterFallbackContext;
|
|
@@ -9,6 +9,4 @@ export function useCodeHighlighterFallbackContext() {
|
|
|
9
9
|
throw new Error('CodeHighlighterFallbackContext is missing. `useCodeHighlighterFallbackContext` must be used within a `CodeHighlighter` component.');
|
|
10
10
|
}
|
|
11
11
|
return context;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// TODO: rename to ContentMinimal
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { CodeHighlighterChunkContentProps } from "./CodeHighlighterChunk.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The chunk's **server initial loader**: load just the initial source (a quick
|
|
5
|
+
* fallback paint) via `loadCodeFallback`, prepare the loading fallback + compressed
|
|
6
|
+
* residual from it, then **re-enter the chunk** with the initial in hand
|
|
7
|
+
* (`skipInitialLoad`, so it routes to the full server loader or the client - never
|
|
8
|
+
* back here). Dynamically imported by `CodeHighlighterChunk`.
|
|
9
|
+
*/
|
|
10
|
+
export default function CodeInitialSourceLoader(props: CodeHighlighterChunkContentProps): Promise<React.ReactElement>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CodeHighlighterChunk } from "./CodeHighlighterChunk.mjs";
|
|
3
|
+
import { buildCodeHighlighterChunkProps } from "./buildCodeHighlighterChunkProps.mjs";
|
|
4
|
+
import { prepareInitialSource } from "./prepareInitialSource.mjs";
|
|
5
|
+
// Statically imported because this whole module is dynamically imported by
|
|
6
|
+
// `CodeHighlighterChunk` (`() => import('./CodeInitialSourceLoader')`) only when
|
|
7
|
+
// the render decision routes to the initial loader - so `loadCodeFallback` already
|
|
8
|
+
// lives in this lazy chunk and never reaches the precomputed-content path.
|
|
9
|
+
import { loadCodeFallback } from "../pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs";
|
|
10
|
+
import * as Errors from "./errors.mjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The chunk's **server initial loader**: load just the initial source (a quick
|
|
14
|
+
* fallback paint) via `loadCodeFallback`, prepare the loading fallback + compressed
|
|
15
|
+
* residual from it, then **re-enter the chunk** with the initial in hand
|
|
16
|
+
* (`skipInitialLoad`, so it routes to the full server loader or the client - never
|
|
17
|
+
* back here). Dynamically imported by `CodeHighlighterChunk`.
|
|
18
|
+
*/
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
export default async function CodeInitialSourceLoader(props) {
|
|
21
|
+
const {
|
|
22
|
+
data,
|
|
23
|
+
loading,
|
|
24
|
+
...userProps
|
|
25
|
+
} = props;
|
|
26
|
+
const {
|
|
27
|
+
url,
|
|
28
|
+
initialVariant,
|
|
29
|
+
highlightAfter,
|
|
30
|
+
ContentLoading
|
|
31
|
+
} = userProps;
|
|
32
|
+
if (!url) {
|
|
33
|
+
throw new Errors.ErrorCodeHighlighterServerMissingUrl();
|
|
34
|
+
}
|
|
35
|
+
if (!initialVariant) {
|
|
36
|
+
throw new Errors.ErrorCodeHighlighterServerMissingVariant('initial');
|
|
37
|
+
}
|
|
38
|
+
let output = 'hastCompressed';
|
|
39
|
+
if (userProps.deferParsing === 'json') {
|
|
40
|
+
output = 'hastJson';
|
|
41
|
+
} else if (userProps.deferParsing === 'none') {
|
|
42
|
+
output = 'hast';
|
|
43
|
+
}
|
|
44
|
+
const {
|
|
45
|
+
code,
|
|
46
|
+
initialFilename,
|
|
47
|
+
initialSource,
|
|
48
|
+
initialExtraFiles,
|
|
49
|
+
processedGlobalsCode
|
|
50
|
+
} = await loadCodeFallback(url, initialVariant, data ?? userProps.code, {
|
|
51
|
+
shouldHighlight: highlightAfter === 'init',
|
|
52
|
+
fallbackUsesExtraFiles: userProps.fallbackUsesExtraFiles,
|
|
53
|
+
fallbackUsesAllVariants: userProps.fallbackUsesAllVariants,
|
|
54
|
+
sourceParser: userProps.sourceParser,
|
|
55
|
+
loadSource: userProps.loadSource,
|
|
56
|
+
loadVariantMeta: userProps.loadVariantMeta,
|
|
57
|
+
loadCodeMeta: userProps.loadCodeMeta,
|
|
58
|
+
sourceEnhancers: userProps.sourceEnhancers,
|
|
59
|
+
initialFilename: userProps.fileName,
|
|
60
|
+
variants: userProps.variants,
|
|
61
|
+
globalsCode: userProps.globalsCode,
|
|
62
|
+
output,
|
|
63
|
+
urlPrefix: userProps.urlPrefix
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Prepare the loading fallback + compressed residual from the loaded initial.
|
|
67
|
+
const {
|
|
68
|
+
fallback,
|
|
69
|
+
residualFallbacks,
|
|
70
|
+
codeForClient
|
|
71
|
+
} = prepareInitialSource({
|
|
72
|
+
...userProps,
|
|
73
|
+
code,
|
|
74
|
+
initialVariant,
|
|
75
|
+
initialFilename,
|
|
76
|
+
initialSource,
|
|
77
|
+
initialExtraFiles,
|
|
78
|
+
ContentLoading: ContentLoading
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Re-enter the chunk with the initial in hand. `skipInitialLoad` prevents routing
|
|
82
|
+
// back here; the recomputed decision loads the full content on the server (when
|
|
83
|
+
// loader functions exist) or hands off to the client.
|
|
84
|
+
const {
|
|
85
|
+
controlled,
|
|
86
|
+
isInitial,
|
|
87
|
+
forceClient
|
|
88
|
+
} = buildCodeHighlighterChunkProps({
|
|
89
|
+
...userProps,
|
|
90
|
+
code: codeForClient
|
|
91
|
+
});
|
|
92
|
+
return /*#__PURE__*/_jsx(CodeHighlighterChunk, {
|
|
93
|
+
preloaded: codeForClient,
|
|
94
|
+
controlled: controlled,
|
|
95
|
+
isInitial: isInitial,
|
|
96
|
+
forceClient: forceClient,
|
|
97
|
+
skipInitialLoad: true,
|
|
98
|
+
awaitServerLoad: highlightAfter !== 'stream',
|
|
99
|
+
userProps: {
|
|
100
|
+
...userProps,
|
|
101
|
+
code: codeForClient,
|
|
102
|
+
fallback,
|
|
103
|
+
residualFallbacks,
|
|
104
|
+
processedGlobalsCode,
|
|
105
|
+
initialVariant
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { CodeHighlighterChunkContentProps } from "./CodeHighlighterChunk.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The chunk's full **server loader**: load every variant (highlighting them via the
|
|
5
|
+
* heavy `loadIsomorphicCodeVariant` pipeline), then render the `'use client'`
|
|
6
|
+
* `CodeHighlighterClient` with the loaded `Code`. Dynamically imported by
|
|
7
|
+
* `CodeHighlighterChunk`, so it (and the pipeline) only reach the bundle when the
|
|
8
|
+
* decision actually routes here. The prepared loading `fallback`/`residualFallbacks`
|
|
9
|
+
* ride through the user props.
|
|
10
|
+
*/
|
|
11
|
+
export default function CodeSourceLoader(props: CodeHighlighterChunkContentProps): Promise<React.ReactElement>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createClientProps } from "./createClientProps.mjs";
|
|
3
|
+
import { CodeHighlighterClient } from "./CodeHighlighterClient.mjs";
|
|
4
|
+
// `loadIsomorphicCodeVariant` is the heavy load/parse/transform pipeline. It is
|
|
5
|
+
// imported statically here because this whole module is dynamically imported by
|
|
6
|
+
// `CodeHighlighterChunk` (`() => import('./CodeSourceLoader')`) only when the
|
|
7
|
+
// render decision routes to the server loader - so it already lives in this lazy
|
|
8
|
+
// chunk and never reaches the path that renders precomputed content.
|
|
9
|
+
import { loadIsomorphicCodeVariant } from "../pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs";
|
|
10
|
+
import * as Errors from "./errors.mjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The chunk's full **server loader**: load every variant (highlighting them via the
|
|
14
|
+
* heavy `loadIsomorphicCodeVariant` pipeline), then render the `'use client'`
|
|
15
|
+
* `CodeHighlighterClient` with the loaded `Code`. Dynamically imported by
|
|
16
|
+
* `CodeHighlighterChunk`, so it (and the pipeline) only reach the bundle when the
|
|
17
|
+
* decision actually routes here. The prepared loading `fallback`/`residualFallbacks`
|
|
18
|
+
* ride through the user props.
|
|
19
|
+
*/
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
export default async function CodeSourceLoader(props) {
|
|
22
|
+
const {
|
|
23
|
+
data,
|
|
24
|
+
loading,
|
|
25
|
+
...userProps
|
|
26
|
+
} = props;
|
|
27
|
+
|
|
28
|
+
// Start with the loaded code from the chunk's data (precompute/wire code), or
|
|
29
|
+
// load it via `loadCodeMeta` when nothing was provided.
|
|
30
|
+
let loadedCode = data ?? userProps.code ?? userProps.precompute;
|
|
31
|
+
if (!loadedCode) {
|
|
32
|
+
if (!userProps.loadCodeMeta) {
|
|
33
|
+
throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMeta();
|
|
34
|
+
}
|
|
35
|
+
if (!userProps.url) {
|
|
36
|
+
throw new Errors.ErrorCodeHighlighterServerMissingUrlForLoadCodeMeta();
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
loadedCode = await userProps.loadCodeMeta(userProps.url);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Errors.ErrorCodeHighlighterServerLoadCodeFailure(userProps.url, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// TODO: if props.variant is provided, we should only load that variant
|
|
46
|
+
|
|
47
|
+
// Process globalsCode: use already processed version if available, otherwise
|
|
48
|
+
// convert string URLs to Code objects.
|
|
49
|
+
let processedGlobalsCode = userProps.processedGlobalsCode;
|
|
50
|
+
if (!processedGlobalsCode && userProps.globalsCode && userProps.globalsCode.length > 0) {
|
|
51
|
+
const hasStringUrls = userProps.globalsCode.some(item => typeof item === 'string');
|
|
52
|
+
if (hasStringUrls && !userProps.loadCodeMeta) {
|
|
53
|
+
throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMetaForGlobals();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Load all string URLs in parallel, keep Code objects as-is
|
|
57
|
+
const globalsPromises = userProps.globalsCode.map(async globalItem => {
|
|
58
|
+
if (typeof globalItem === 'string') {
|
|
59
|
+
try {
|
|
60
|
+
return await userProps.loadCodeMeta(globalItem);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new Errors.ErrorCodeHighlighterServerLoadGlobalsFailure(globalItem, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return globalItem;
|
|
66
|
+
});
|
|
67
|
+
processedGlobalsCode = await Promise.all(globalsPromises);
|
|
68
|
+
}
|
|
69
|
+
const variantNames = Object.keys(userProps.components || loadedCode || {});
|
|
70
|
+
const variantCodes = await Promise.all(variantNames.map(variantName => {
|
|
71
|
+
const variantCode = loadedCode[variantName];
|
|
72
|
+
const variantUrl = typeof variantCode === 'object' && variantCode?.url ? variantCode.url : userProps.url;
|
|
73
|
+
|
|
74
|
+
// Convert processedGlobalsCode to VariantCode | string for this specific variant
|
|
75
|
+
let resolvedGlobalsCode;
|
|
76
|
+
if (processedGlobalsCode && processedGlobalsCode.length > 0) {
|
|
77
|
+
resolvedGlobalsCode = [];
|
|
78
|
+
for (const codeObj of processedGlobalsCode) {
|
|
79
|
+
const targetVariant = codeObj[variantName];
|
|
80
|
+
if (targetVariant) {
|
|
81
|
+
resolvedGlobalsCode.push(targetVariant);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let output = 'hastCompressed';
|
|
86
|
+
if (userProps.deferParsing === 'json') {
|
|
87
|
+
output = 'hastJson';
|
|
88
|
+
} else if (userProps.deferParsing === 'none') {
|
|
89
|
+
output = 'hast';
|
|
90
|
+
}
|
|
91
|
+
return loadIsomorphicCodeVariant(variantUrl, variantName, variantCode, {
|
|
92
|
+
sourceParser: userProps.sourceParser,
|
|
93
|
+
loadSource: userProps.loadSource,
|
|
94
|
+
loadVariantMeta: userProps.loadVariantMeta,
|
|
95
|
+
sourceTransformers: userProps.sourceTransformers,
|
|
96
|
+
sourceEnhancers: userProps.sourceEnhancers,
|
|
97
|
+
globalsCode: resolvedGlobalsCode,
|
|
98
|
+
output,
|
|
99
|
+
urlPrefix: userProps.urlPrefix
|
|
100
|
+
}).then(variant => ({
|
|
101
|
+
name: variantName,
|
|
102
|
+
variant
|
|
103
|
+
})).catch(error => ({
|
|
104
|
+
error
|
|
105
|
+
}));
|
|
106
|
+
}));
|
|
107
|
+
const processedCode = {};
|
|
108
|
+
const errors = [];
|
|
109
|
+
for (const item of variantCodes) {
|
|
110
|
+
if ('error' in item) {
|
|
111
|
+
console.error(new Errors.ErrorCodeHighlighterServerLoadVariantFailure(userProps.url, item.error));
|
|
112
|
+
errors.push(item.error);
|
|
113
|
+
} else {
|
|
114
|
+
processedCode[item.name] = item.variant.code;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (errors.length > 0) {
|
|
118
|
+
throw new Errors.ErrorCodeHighlighterServerLoadVariantsFailure(userProps.url, errors);
|
|
119
|
+
}
|
|
120
|
+
const clientProps = createClientProps({
|
|
121
|
+
...userProps,
|
|
122
|
+
code: processedCode,
|
|
123
|
+
processedGlobalsCode
|
|
124
|
+
});
|
|
125
|
+
return /*#__PURE__*/_jsx(CodeHighlighterClient, {
|
|
126
|
+
...clientProps
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Code, CodeHighlighterProps } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The render-decision inputs for the chunk that drives `CodeHighlighter`,
|
|
4
|
+
* computed from its props. These feed the generic chunk decision
|
|
5
|
+
* (`resolveChunkRender` via `buildChunkRenderInputs`):
|
|
6
|
+
*
|
|
7
|
+
* - `preloaded` is the `Code` (build/precomputed input).
|
|
8
|
+
* - `controlled` forces the `content` mode (render the client directly).
|
|
9
|
+
* - `isInitial` reports that an initial paint is already in hand.
|
|
10
|
+
* - `forceClient` opts out of the server `Loader`/`InitialLoader`.
|
|
11
|
+
*/
|
|
12
|
+
export interface CodeHighlighterChunkProps {
|
|
13
|
+
/** The `Code` passed as the chunk's `preloaded` value. */
|
|
14
|
+
preloaded?: Code;
|
|
15
|
+
/**
|
|
16
|
+
* Every variant is already highlighted (or `CodeHighlighter` is in controlled
|
|
17
|
+
* editing mode) - render the client content directly, no loading.
|
|
18
|
+
*/
|
|
19
|
+
controlled: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* A partial code with an initial paint already in hand (enough to render the
|
|
22
|
+
* loading fallback now). Routes to loading the full content behind it, or, with
|
|
23
|
+
* no server loading, to the client.
|
|
24
|
+
*/
|
|
25
|
+
isInitial: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* No server loading is available for this render (no loading functions, or the
|
|
28
|
+
* caller forced the client), so the decision routes to a client/content branch.
|
|
29
|
+
*/
|
|
30
|
+
forceClient: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** The `CodeHighlighter` props this decision reads. */
|
|
33
|
+
type BuildCodeHighlighterChunkPropsInput<T extends {}> = Pick<CodeHighlighterProps<T>, 'code' | 'precompute' | 'components' | 'variants' | 'variant' | 'initialVariant' | 'defaultVariant' | 'controlled' | 'forceClient' | 'highlightAfter' | 'fallbackUsesExtraFiles' | 'fallbackUsesAllVariants' | 'loadCodeMeta' | 'loadVariantMeta' | 'loadSource' | 'sourceParser' | 'sourceTransformers' | 'url' | 'fileName'>;
|
|
34
|
+
/**
|
|
35
|
+
* Map `CodeHighlighter`'s props onto the generic chunk render-decision inputs.
|
|
36
|
+
* This replaces the bespoke `renderCodeHighlighter`/`renderWithInitialSource`
|
|
37
|
+
* branching: the returned values drive `resolveChunkRender`, which picks between
|
|
38
|
+
* rendering the client directly, loading the full content on the server, fetching
|
|
39
|
+
* an initial on the server, or letting the client drive - the same five outcomes
|
|
40
|
+
* `CodeHighlighter` chose by hand.
|
|
41
|
+
*
|
|
42
|
+
* Pure and synchronous (mirrors `maybeCodeInitialData`), so the same inputs decide
|
|
43
|
+
* identically on the server and the client's first render. Expects `code` already
|
|
44
|
+
* normalized (e.g. a string child folded into a `Default` variant).
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildCodeHighlighterChunkProps<T extends {} = {}>(props: BuildCodeHighlighterChunkPropsInput<T>): CodeHighlighterChunkProps;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { hasAllVariants } from "../pipeline/loadIsomorphicCodeVariant/hasAllCodeVariants.mjs";
|
|
2
|
+
import { maybeCodeInitialData } from "../pipeline/loadIsomorphicCodeVariant/maybeCodeInitialData.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The render-decision inputs for the chunk that drives `CodeHighlighter`,
|
|
6
|
+
* computed from its props. These feed the generic chunk decision
|
|
7
|
+
* (`resolveChunkRender` via `buildChunkRenderInputs`):
|
|
8
|
+
*
|
|
9
|
+
* - `preloaded` is the `Code` (build/precomputed input).
|
|
10
|
+
* - `controlled` forces the `content` mode (render the client directly).
|
|
11
|
+
* - `isInitial` reports that an initial paint is already in hand.
|
|
12
|
+
* - `forceClient` opts out of the server `Loader`/`InitialLoader`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The `CodeHighlighter` props this decision reads. */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Map `CodeHighlighter`'s props onto the generic chunk render-decision inputs.
|
|
19
|
+
* This replaces the bespoke `renderCodeHighlighter`/`renderWithInitialSource`
|
|
20
|
+
* branching: the returned values drive `resolveChunkRender`, which picks between
|
|
21
|
+
* rendering the client directly, loading the full content on the server, fetching
|
|
22
|
+
* an initial on the server, or letting the client drive - the same five outcomes
|
|
23
|
+
* `CodeHighlighter` chose by hand.
|
|
24
|
+
*
|
|
25
|
+
* Pure and synchronous (mirrors `maybeCodeInitialData`), so the same inputs decide
|
|
26
|
+
* identically on the server and the client's first render. Expects `code` already
|
|
27
|
+
* normalized (e.g. a string child folded into a `Default` variant).
|
|
28
|
+
*/
|
|
29
|
+
export function buildCodeHighlighterChunkProps(props) {
|
|
30
|
+
const code = props.code || props.precompute;
|
|
31
|
+
const variants = props.variants || Object.keys(props.components || code || {});
|
|
32
|
+
const initialKey = props.initialVariant || props.variant || props.defaultVariant || variants[0];
|
|
33
|
+
|
|
34
|
+
// Every variant already highlighted (or controlled editing) -> render the
|
|
35
|
+
// client directly with no loading.
|
|
36
|
+
const allVariantsLoaded = Boolean(code && hasAllVariants(variants, code, true));
|
|
37
|
+
const controlled = Boolean(props.controlled) || allVariantsLoaded;
|
|
38
|
+
|
|
39
|
+
// No loading functions (or the caller forced the client) -> the server cannot
|
|
40
|
+
// load, so route to a client/content branch.
|
|
41
|
+
const hasAnyLoaderFunction = Boolean(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
|
|
42
|
+
const forceClient = Boolean(props.forceClient) || !hasAnyLoaderFunction;
|
|
43
|
+
|
|
44
|
+
// An initial paint is in hand when, short of being fully loaded,
|
|
45
|
+
// `maybeCodeInitialData` validates enough to render the loading fallback now.
|
|
46
|
+
// Mirrors the server arguments `CodeHighlighter` passed it (no explicit
|
|
47
|
+
// `fileName`; highlight required only for `highlightAfter: 'init'`).
|
|
48
|
+
let isInitial = false;
|
|
49
|
+
if (!controlled) {
|
|
50
|
+
const {
|
|
51
|
+
initialData
|
|
52
|
+
} = maybeCodeInitialData(variants, initialKey, code, undefined, props.highlightAfter === 'init', props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants);
|
|
53
|
+
isInitial = Boolean(initialData);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
preloaded: code,
|
|
57
|
+
controlled,
|
|
58
|
+
isInitial,
|
|
59
|
+
forceClient
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SourceComments, SourceEnhancers } from "./types.mjs";
|
|
2
|
+
import { type FallbackNode } from "./fallbackFormat.mjs";
|
|
3
|
+
export interface StringFallbackResult {
|
|
4
|
+
/** Compact, windowed fallback frames (text only — `.line` spans stripped). */
|
|
5
|
+
fallback: FallbackNode[];
|
|
6
|
+
/** Total source lines. */
|
|
7
|
+
totalLines: number;
|
|
8
|
+
/** Lines visible in the collapsed window (the sum of visible frame sizes). */
|
|
9
|
+
focusedLines: number;
|
|
10
|
+
/** Whether the enhanced frame structure has hidden content to expand into. */
|
|
11
|
+
collapsible: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Derive a *windowed* fallback for a plain-string source by running the same
|
|
15
|
+
* `sourceEnhancers` the live render uses over a cheap line-guttered HAST
|
|
16
|
+
* (`parsePlainText` — gutters, no syntax highlighting). The inline-string
|
|
17
|
+
* fallback path otherwise wraps the whole source in one un-windowed focus frame,
|
|
18
|
+
* so an oversized / `@focus` / `@highlight` block paints its full text before
|
|
19
|
+
* hydration then snaps to the collapsed window. Running the enhancers here makes
|
|
20
|
+
* the loading frames match the live render, and the resulting `root.data` carries
|
|
21
|
+
* the `totalLines` / `focusedLines` the compact fallback can't preserve.
|
|
22
|
+
*
|
|
23
|
+
* Synchronous by design — it runs at server fallback-prep time inside the
|
|
24
|
+
* (sync) `prepareInitialSource`. An enhancer that returns a promise is skipped
|
|
25
|
+
* (returns `undefined`) so the caller falls back to the naive single-frame wrap
|
|
26
|
+
* rather than blocking; the built-in `enhanceCodeEmphasis` is synchronous, so
|
|
27
|
+
* the common case windows.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildStringFallback(source: string, comments: SourceComments | undefined, fileName: string, sourceEnhancers: SourceEnhancers): StringFallbackResult | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { buildRootFallback } from "./fallbackFormat.mjs";
|
|
2
|
+
import { parsePlainText } from "../pipeline/parseSource/index.mjs";
|
|
3
|
+
function isPromiseLike(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && typeof value.then === 'function';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Derive a *windowed* fallback for a plain-string source by running the same
|
|
9
|
+
* `sourceEnhancers` the live render uses over a cheap line-guttered HAST
|
|
10
|
+
* (`parsePlainText` — gutters, no syntax highlighting). The inline-string
|
|
11
|
+
* fallback path otherwise wraps the whole source in one un-windowed focus frame,
|
|
12
|
+
* so an oversized / `@focus` / `@highlight` block paints its full text before
|
|
13
|
+
* hydration then snaps to the collapsed window. Running the enhancers here makes
|
|
14
|
+
* the loading frames match the live render, and the resulting `root.data` carries
|
|
15
|
+
* the `totalLines` / `focusedLines` the compact fallback can't preserve.
|
|
16
|
+
*
|
|
17
|
+
* Synchronous by design — it runs at server fallback-prep time inside the
|
|
18
|
+
* (sync) `prepareInitialSource`. An enhancer that returns a promise is skipped
|
|
19
|
+
* (returns `undefined`) so the caller falls back to the naive single-frame wrap
|
|
20
|
+
* rather than blocking; the built-in `enhanceCodeEmphasis` is synchronous, so
|
|
21
|
+
* the common case windows.
|
|
22
|
+
*/
|
|
23
|
+
export function buildStringFallback(source, comments, fileName, sourceEnhancers) {
|
|
24
|
+
let root = parsePlainText(source);
|
|
25
|
+
for (const enhancer of sourceEnhancers) {
|
|
26
|
+
const result = enhancer(root, comments, fileName);
|
|
27
|
+
if (isPromiseLike(result)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
root = result;
|
|
31
|
+
}
|
|
32
|
+
const data = root.data;
|
|
33
|
+
const totalLines = data?.totalLines ?? 0;
|
|
34
|
+
const focusedLines = data?.focusedLines ?? totalLines;
|
|
35
|
+
const collapsible = data?.collapsible === true;
|
|
36
|
+
return {
|
|
37
|
+
fallback: buildRootFallback(root),
|
|
38
|
+
totalLines,
|
|
39
|
+
focusedLines,
|
|
40
|
+
collapsible
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { BaseContentLoadingProps, Code, Fallbacks } from "./types.mjs";
|
|
2
|
+
import { type SourceLineCounts } from "../useCode/sourceLineCounts.mjs";
|
|
3
|
+
/** Per-variant → per-file line metadata threaded for the fallback. */
|
|
4
|
+
export type LineCountsByVariant = Record<string, Record<string, SourceLineCounts>>;
|
|
5
|
+
export declare function codeToFallbackProps(variant: string, code?: Code, _fileName?: string, _needsAllFiles?: boolean, needsAllVariants?: boolean, allFallbackHasts?: Record<string, Fallbacks>, allLineCounts?: LineCountsByVariant): BaseContentLoadingProps;
|
|
6
|
+
/**
|
|
7
|
+
* Read a variant's per-file fallbacks straight off its `VariantCode` `fallback`
|
|
8
|
+
* fields (main + extra files), returning a `Fallbacks` map keyed by file name.
|
|
9
|
+
*
|
|
10
|
+
* The fallback crosses the server→client boundary exactly once: either on the
|
|
11
|
+
* `VariantCode` (no `ContentLoading`) or — after `stripFallbackHastsFromCode`
|
|
12
|
+
* moves it — on the `ContentLoading` props. This reads the former location, so
|
|
13
|
+
* the client can resolve the DEFLATE dictionary for `hastCompressed` without a
|
|
14
|
+
* hoist when there's no `ContentLoading`. Returns `undefined` when the variant
|
|
15
|
+
* carries no fallback (a string variant, a live-HAST source, or one whose
|
|
16
|
+
* fallbacks were stripped for a `ContentLoading` component) — in which case the
|
|
17
|
+
* hoisted copy is used instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare function deriveFallbacksFromCode(code: Code | undefined, variantName: string): Fallbacks | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Strip `fallback` entries from a `Code` object and return the
|
|
22
|
+
* stripped Code alongside the extracted fallbacks grouped by variant → fileName.
|
|
23
|
+
*
|
|
24
|
+
* Used on the server to separate the fallback data from the Code
|
|
25
|
+
* so Code is sent to CodeHighlighterClient without fallbacks, and
|
|
26
|
+
* the data is passed to ContentLoading as source/extraSource props.
|
|
27
|
+
*/
|
|
28
|
+
export declare function stripFallbackHastsFromCode(code: Code | undefined, variantName: string, fallbackUsesExtraFiles?: boolean, fallbackUsesAllVariants?: boolean): {
|
|
29
|
+
strippedCode: Code;
|
|
30
|
+
allFallbackHasts: Record<string, Fallbacks>;
|
|
31
|
+
};
|