@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,102 +1,36 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// Strips TypeScript syntax (types, interfaces, enums, decorators, etc.) from
|
|
2
|
+
// source while preserving line numbers and JSX. Backed by `sucrase`, which is
|
|
3
|
+
// a single-pass, allocation-light alternative to `@babel/standalone`.
|
|
4
|
+
//
|
|
5
|
+
// Why sucrase
|
|
6
|
+
// -----------
|
|
7
|
+
// The previous `@babel/standalone` + `prettier/standalone` implementation
|
|
8
|
+
// pulled ~3 MB of parser/printer code into every Next.js worker and held
|
|
9
|
+
// large parser state across calls. In a production build with hundreds of
|
|
10
|
+
// demos that drove webpack workers past `--max-old-space-size` even at
|
|
11
|
+
// concurrency=1. Sucrase ships a focused TS/JSX stripper (~200 KB) that
|
|
12
|
+
// rewrites in place, so transform output reuses input layout and there is no
|
|
13
|
+
// AST cache to bleed memory across files.
|
|
14
|
+
|
|
15
|
+
import { transform } from 'sucrase';
|
|
3
16
|
|
|
4
|
-
import * as Babel from '@babel/standalone';
|
|
5
|
-
import { format } from 'prettier/standalone';
|
|
6
|
-
import pluginBabel from 'prettier/plugins/babel';
|
|
7
|
-
import pluginEstree from 'prettier/plugins/estree';
|
|
8
17
|
/**
|
|
9
|
-
* Strips TypeScript types and decorators from code (including
|
|
10
|
-
* preserving
|
|
18
|
+
* Strips TypeScript types and decorators from code (including JSX in TSX),
|
|
19
|
+
* preserving line numbers so source maps and diff tooling stay aligned.
|
|
11
20
|
*
|
|
12
21
|
* @param code - The source code string to transform.
|
|
13
22
|
* @param filename - The name of the file (e.g. "foo.ts" or "Foo.tsx").
|
|
14
|
-
* Determines whether TSX parsing is enabled.
|
|
15
|
-
* @
|
|
16
|
-
* or a Prettier options object to customize.
|
|
17
|
-
* @returns The transformed (and optionally formatted) code.
|
|
23
|
+
* Determines whether TSX/JSX parsing is enabled.
|
|
24
|
+
* @returns The transformed code with TypeScript syntax removed.
|
|
18
25
|
*/
|
|
19
|
-
export async function removeTypes(code, filename = 'file.ts'
|
|
20
|
-
// Babel collapses newlines all over the place, which messes with the formatting of almost any
|
|
21
|
-
// code you pass to it. To preserve the formatting, we go through and mark all the empty lines
|
|
22
|
-
// in the code string *before* transforming it. This allows us to go back through after the
|
|
23
|
-
// transformation re-insert the empty lines in the correct place relative to the new code that
|
|
24
|
-
// has been generated.
|
|
25
|
-
code = code.replace(/\n\n+/g, '/* ___NEWLINE___ */\n');
|
|
26
|
-
|
|
27
|
-
// When removing TS-specific constructs (e.g. interfaces), we want to make sure we also remove
|
|
28
|
-
// any comments that are associated with those constructs, since otherwise we'll be left with
|
|
29
|
-
// comments that refer to something that isn't actually there.
|
|
30
|
-
// Credit to https://github.com/cyco130/detype for figuring out this very useful pattern
|
|
31
|
-
const removeComments = {
|
|
32
|
-
enter(nodePath) {
|
|
33
|
-
if (!nodePath.node.leadingComments) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
for (let i = nodePath.node.leadingComments.length - 1; i >= 0; i -= 1) {
|
|
37
|
-
const comment = nodePath.node.leadingComments[i];
|
|
38
|
-
if (code.slice(comment.end).match(/^\s*\n\s*\n/) || comment.value.includes('___NEWLINE___')) {
|
|
39
|
-
// There is at least one empty line between the comment and the TypeScript specific construct
|
|
40
|
-
// We should keep this comment and those before it
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
comment.value = '___REMOVE_ME___';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
26
|
+
export async function removeTypes(code, filename = 'file.ts') {
|
|
47
27
|
const isTSX = /\.tsx$/i.test(filename);
|
|
48
|
-
const
|
|
49
|
-
filename,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
TSInterfaceDeclaration: removeComments,
|
|
55
|
-
TSDeclareFunction: removeComments,
|
|
56
|
-
TSDeclareMethod: removeComments,
|
|
57
|
-
TSImportType: removeComments,
|
|
58
|
-
TSModuleDeclaration: removeComments
|
|
59
|
-
}
|
|
60
|
-
}, ['transform-typescript', {
|
|
61
|
-
onlyRemoveTypeImports: true,
|
|
62
|
-
isTSX,
|
|
63
|
-
allExtensions: true
|
|
64
|
-
}], ['proposal-decorators', {
|
|
65
|
-
legacy: true
|
|
66
|
-
}]],
|
|
67
|
-
generatorOpts: {
|
|
68
|
-
retainLines: true,
|
|
69
|
-
shouldPrintComment: c => c !== '___REMOVE_ME___'
|
|
70
|
-
}
|
|
28
|
+
const result = transform(code, {
|
|
29
|
+
filePath: filename,
|
|
30
|
+
transforms: isTSX ? ['typescript', 'jsx'] : ['typescript'],
|
|
31
|
+
jsxRuntime: 'preserve',
|
|
32
|
+
preserveDynamicImport: true,
|
|
33
|
+
disableESTransforms: true
|
|
71
34
|
});
|
|
72
|
-
|
|
73
|
-
throw new Error('There was an issue with the Babel transform.');
|
|
74
|
-
}
|
|
75
|
-
const fixed = transformed.code.replace(/\/\* ___NEWLINE___ \*\//g, '\n');
|
|
76
|
-
|
|
77
|
-
// If the user has *explicitly* passed `false` here, it means they do not want us to run Prettier
|
|
78
|
-
// at all, so we bail here.
|
|
79
|
-
if (prettierConfig === false) {
|
|
80
|
-
return fixed;
|
|
81
|
-
}
|
|
82
|
-
const standardPrettierOptions = {
|
|
83
|
-
parser: 'babel',
|
|
84
|
-
singleQuote: true,
|
|
85
|
-
plugins: [pluginBabel, pluginEstree]
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// If `prettierConfig` is *explicitly* true (as opposed to truthy), it means the user has opted in
|
|
89
|
-
// to default behavior either explicitly or implicitly. Either way, we run basic Prettier on it.
|
|
90
|
-
if (prettierConfig === true) {
|
|
91
|
-
return format(fixed, standardPrettierOptions);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If we've made it here, the user has passed their own Prettier options so we merge it with ours
|
|
95
|
-
// and let theirs overwrite any of the default settings.
|
|
96
|
-
const mergedPrettierOptions = {
|
|
97
|
-
...standardPrettierOptions,
|
|
98
|
-
...prettierConfig,
|
|
99
|
-
plugins: standardPrettierOptions.plugins
|
|
100
|
-
};
|
|
101
|
-
return format(fixed, mergedPrettierOptions);
|
|
35
|
+
return result.code;
|
|
102
36
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { type Position } from "./useEditableUtils.mjs";
|
|
2
|
+
import type { EditingEngineLoader } from "./editingEngineCache.mjs";
|
|
3
|
+
type History = [Position, string];
|
|
4
|
+
export interface State {
|
|
5
|
+
disconnected: boolean;
|
|
6
|
+
onChange(text: string, position: Position, preParseResult?: unknown): void;
|
|
7
|
+
pendingContent: string | null;
|
|
8
|
+
queue: MutationRecord[];
|
|
9
|
+
history: History[];
|
|
10
|
+
historyAt: number;
|
|
11
|
+
/**
|
|
12
|
+
* The text most recently reported via `onChange` (i.e. last seen by the
|
|
13
|
+
* controlled host), independent of the undo stack. Lets the
|
|
14
|
+
* external-swap detector recover edits that the 500ms dedup kept out
|
|
15
|
+
* of `history`: when the host swaps the editable's content, anything
|
|
16
|
+
* the user typed since the last history checkpoint is still reachable
|
|
17
|
+
* here and gets pushed onto the stack just before the swap is
|
|
18
|
+
* recorded. Cleared on every undo/redo so we don't double-record after
|
|
19
|
+
* navigating the existing history.
|
|
20
|
+
*/
|
|
21
|
+
lastCommittedContent: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Set whenever the MutationObserver sees DOM changes between renders,
|
|
24
|
+
* cleared after the snapshot block consumes them. Lets the per-render
|
|
25
|
+
* layout effect skip the O(N) `toString` walk on idle re-renders
|
|
26
|
+
* (parent updates, async state syncs, variant switches that don't
|
|
27
|
+
* actually touch the editable's DOM). React's reconciliation of an
|
|
28
|
+
* unchanged highlighted subtree produces zero mutation records, so
|
|
29
|
+
* `domDirty` stays false and the snapshot is a no-op.
|
|
30
|
+
*/
|
|
31
|
+
domDirty: boolean;
|
|
32
|
+
position: Position | null;
|
|
33
|
+
/** setTimeout id used to debounce flushChanges() calls during key-repeat */
|
|
34
|
+
repeatFlushId: ReturnType<typeof setTimeout> | null;
|
|
35
|
+
/**
|
|
36
|
+
* AbortController for the in-flight `preParse` callback (if any). Reset
|
|
37
|
+
* on every new flush so a rapidly-typed sequence aborts stale parses
|
|
38
|
+
* before posting a fresh request.
|
|
39
|
+
*/
|
|
40
|
+
preParseAbort: AbortController | null;
|
|
41
|
+
/**
|
|
42
|
+
* Set when an arrow-key handler invokes `onBoundary` (which typically
|
|
43
|
+
* triggers a host re-render to expand a collapsed region). The native
|
|
44
|
+
* arrow-key default action moves the caret AFTER our keydown handler
|
|
45
|
+
* returns, but the host's re-render commits BEFORE the resulting
|
|
46
|
+
* `selectionchange` updates `state.position`. Without this flag, the
|
|
47
|
+
* unconditional restore effect would snap the caret back to the stale
|
|
48
|
+
* pre-arrow `state.position` on that intermediate render. The flag is
|
|
49
|
+
* cleared after one skipped restore.
|
|
50
|
+
*/
|
|
51
|
+
skipNextRestore: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface Options<TPreParseResult = unknown> {
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
indentation?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Minimum column the cursor is allowed to occupy on indented lines.
|
|
58
|
+
*
|
|
59
|
+
* When set, horizontal arrow navigation skips over the leading whitespace
|
|
60
|
+
* up to `minColumn` so the caret never lands inside a clipped/hidden
|
|
61
|
+
* indent region:
|
|
62
|
+
*
|
|
63
|
+
* - `ArrowLeft` at column `minColumn` (with that line's first `minColumn`
|
|
64
|
+
* characters all whitespace) jumps to the end of the previous line
|
|
65
|
+
* instead of stepping into the indent.
|
|
66
|
+
* - `ArrowRight` at the end of a line jumps to column `minColumn` of the
|
|
67
|
+
* next line (when the next line is indented at least that far) instead
|
|
68
|
+
* of landing at column 0.
|
|
69
|
+
*
|
|
70
|
+
* Useful when the editor is rendered in a horizontally-shifted view (for
|
|
71
|
+
* example a collapsed code block whose left padding is translated off
|
|
72
|
+
* screen) where columns below `minColumn` are not visible. Leave
|
|
73
|
+
* `undefined` for default arrow-key behavior.
|
|
74
|
+
*/
|
|
75
|
+
minColumn?: number;
|
|
76
|
+
/**
|
|
77
|
+
* First row of the visible region. When set, `ArrowUp` on this row and
|
|
78
|
+
* `ArrowLeft` at the start of this row are blocked (no caret movement)
|
|
79
|
+
* and `onBoundary` is invoked. Useful when content above the visible
|
|
80
|
+
* region is hidden and the host wants a chance to reveal it.
|
|
81
|
+
*/
|
|
82
|
+
minRow?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Last row of the visible region. When set, `ArrowDown` on this row and
|
|
85
|
+
* `ArrowRight` at the end of this row are blocked (no caret movement)
|
|
86
|
+
* and `onBoundary` is invoked.
|
|
87
|
+
*/
|
|
88
|
+
maxRow?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Called when the user attempts to navigate past `minRow`/`maxRow` via
|
|
91
|
+
* arrow keys. When `onBoundary` is provided, the navigation is allowed
|
|
92
|
+
* to proceed natively so the host can react (e.g. expand a collapsed
|
|
93
|
+
* code block) and the caret continues moving in the now-visible
|
|
94
|
+
* content. When `onBoundary` is omitted, the navigation is blocked
|
|
95
|
+
* (caret stays put).
|
|
96
|
+
*/
|
|
97
|
+
onBoundary?: () => void;
|
|
98
|
+
/**
|
|
99
|
+
* CSS selector identifying the elements that represent selectable
|
|
100
|
+
* "lines" inside the editable. When set, and only while the caret is
|
|
101
|
+
* actually inside an element matching the selector:
|
|
102
|
+
*
|
|
103
|
+
* - `ArrowLeft` at column 0 jumps synchronously to the end of the
|
|
104
|
+
* previous line.
|
|
105
|
+
* - `ArrowRight` at the end of a line jumps synchronously to the start
|
|
106
|
+
* of the next line.
|
|
107
|
+
*
|
|
108
|
+
* Useful when the editable contains intentionally-empty whitespace
|
|
109
|
+
* text nodes between block-level children (e.g. newline text nodes
|
|
110
|
+
* separating `.line` spans inside a `.frame`). Without this, the
|
|
111
|
+
* browser would place the caret in those gap nodes on horizontal
|
|
112
|
+
* navigation, making `ArrowLeft`/`ArrowRight` appear to no-op.
|
|
113
|
+
*
|
|
114
|
+
* Vertical navigation (`ArrowUp`/`ArrowDown`) is intentionally left to
|
|
115
|
+
* the browser so wrapped visual lines in `pre-wrap` layouts continue
|
|
116
|
+
* to behave natively. Gap nodes styled with `line-height: 0` are
|
|
117
|
+
* skipped by browsers vertically without intervention.
|
|
118
|
+
*
|
|
119
|
+
* The selector is matched against the caret's containing element via
|
|
120
|
+
* `Element.closest`, so non-`.line` render paths (e.g. plain-string
|
|
121
|
+
* editables) never trigger the wrap behavior.
|
|
122
|
+
*/
|
|
123
|
+
caretSelector?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Optional async pre-parse hook invoked before each `onChange` flush.
|
|
126
|
+
* When provided, the parser receives the post-edit `text` and caret
|
|
127
|
+
* `position` plus an `AbortSignal` that fires when a newer keystroke
|
|
128
|
+
* supersedes this flush. Its resolved value is forwarded as the third
|
|
129
|
+
* argument to `onChange`, allowing the host to cache an already-parsed
|
|
130
|
+
* HAST (or any other derived state) keyed off the same source string.
|
|
131
|
+
*
|
|
132
|
+
* If `preParse` is omitted, `onChange` runs synchronously inside the
|
|
133
|
+
* keyup / debounce handler as before. If it is provided, the React
|
|
134
|
+
* state sync is delayed until the returned promise settles. Structural
|
|
135
|
+
* edits that need a synchronous re-render (Enter, paste, cut, undo/redo,
|
|
136
|
+
* programmatic `edit.update`/`edit.insert`, `minColumn` blank-line
|
|
137
|
+
* collapse) bypass `preParse` and fire `onChange` immediately without
|
|
138
|
+
* a third argument.
|
|
139
|
+
*/
|
|
140
|
+
preParse?: (text: string, position: Position, signal: AbortSignal) => Promise<TPreParseResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Loads the editing engine module on demand. Supplied by `CodeProvider` via
|
|
143
|
+
* context (eager → bundled, resolves instantly; lazy → dynamic `import()`).
|
|
144
|
+
* When omitted, `useEditable` falls back to a built-in dynamic import so
|
|
145
|
+
* editing still works without a provider.
|
|
146
|
+
*/
|
|
147
|
+
engineLoader?: EditingEngineLoader;
|
|
148
|
+
/**
|
|
149
|
+
* Controls when the editing engine loads once the block is editable:
|
|
150
|
+
* `'eager'` (default) loads it immediately; `'interaction'` defers until the
|
|
151
|
+
* user hovers, focuses, or clicks the editable.
|
|
152
|
+
*/
|
|
153
|
+
activation?: 'eager' | 'interaction';
|
|
154
|
+
/**
|
|
155
|
+
* Called once when the block is first activated for editing — immediately in
|
|
156
|
+
* `'eager'` mode, or on first engagement (hover / focus / click) in
|
|
157
|
+
* `'interaction'` mode. Lets the host warm the rest of the live-editing
|
|
158
|
+
* dependencies (grammars, worker) at the right moment, especially when
|
|
159
|
+
* `'interaction'` has deferred them.
|
|
160
|
+
*/
|
|
161
|
+
onActivate?: () => void;
|
|
162
|
+
}
|
|
163
|
+
export interface Edit {
|
|
164
|
+
/** Replaces the entire content of the editable while adjusting the caret position. */
|
|
165
|
+
update(content: string): void;
|
|
166
|
+
/** Inserts new text at the caret position while deleting text in range of the offset (which accepts negative offsets). */
|
|
167
|
+
insert(append: string, offset?: number): void;
|
|
168
|
+
/** Positions the caret where specified */
|
|
169
|
+
move(pos: number | {
|
|
170
|
+
row: number;
|
|
171
|
+
column: number;
|
|
172
|
+
}): void;
|
|
173
|
+
/** Returns the current editor state, as usually received in onChange */
|
|
174
|
+
getState(): {
|
|
175
|
+
text: string;
|
|
176
|
+
position: Position;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export type Bounds = {
|
|
180
|
+
minColumn?: number;
|
|
181
|
+
minRow?: number;
|
|
182
|
+
maxRow?: number;
|
|
183
|
+
onBoundary?: () => void;
|
|
184
|
+
caretSelector?: string;
|
|
185
|
+
preParse?: (text: string, position: Position, signal: AbortSignal) => Promise<unknown>;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Everything {@link createEditableEngine} needs from its host hook. `useEditable`
|
|
189
|
+
* owns this state and these refs so they survive this module's lazy load; the
|
|
190
|
+
* engine only reads and mutates them, and they are shared by reference so the
|
|
191
|
+
* engine's handlers always observe live values.
|
|
192
|
+
*/
|
|
193
|
+
export interface EditableEngineContext {
|
|
194
|
+
elementRef: {
|
|
195
|
+
current: HTMLElement | undefined | null;
|
|
196
|
+
};
|
|
197
|
+
state: State;
|
|
198
|
+
observerRef: {
|
|
199
|
+
current: MutationObserver | null;
|
|
200
|
+
};
|
|
201
|
+
boundsRef: {
|
|
202
|
+
current: Bounds;
|
|
203
|
+
};
|
|
204
|
+
configRef: {
|
|
205
|
+
current: Options;
|
|
206
|
+
};
|
|
207
|
+
unblock: (value: never[]) => void;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The heavy editing runtime bound to a host element. `setup` applies
|
|
211
|
+
* `contentEditable` and binds the keyboard/paste/caret handlers; `observeAndRestore`
|
|
212
|
+
* runs the per-render MutationObserver + caret-restore pass. Each returns its cleanup.
|
|
213
|
+
*/
|
|
214
|
+
export interface EditableEngine {
|
|
215
|
+
edit: Edit;
|
|
216
|
+
observeAndRestore(): (() => void) | undefined;
|
|
217
|
+
setup(): (() => void) | undefined;
|
|
218
|
+
}
|
|
219
|
+
export type CreateEditableEngine = (ctx: EditableEngineContext) => EditableEngine;
|
|
220
|
+
/**
|
|
221
|
+
* Resolves the editing engine factory. `CodeProvider` supplies one via context
|
|
222
|
+
* (eager → bundled, resolves instantly; lazy → dynamic `import()`); `useEditable`
|
|
223
|
+
* also has a built-in fallback so editing works without a provider.
|
|
224
|
+
*/
|
|
225
|
+
export type EditableEngineLoader = () => Promise<CreateEditableEngine>;
|
|
226
|
+
/**
|
|
227
|
+
* Builds the editing engine for a host element. This module statically imports
|
|
228
|
+
* the heavy editing utilities (`useEditableUtils`, `cloneRangeWithInlineStyles`,
|
|
229
|
+
* `stripLeadingPerLine`) and `react-dom`, so the bundler emits it as a separate
|
|
230
|
+
* chunk that `useEditable` loads on demand — read-only code blocks never pull it in.
|
|
231
|
+
*/
|
|
232
|
+
export declare const createEditableEngine: CreateEditableEngine;
|
|
233
|
+
export {};
|