@simon_he/vue-tui 0.0.8 → 1.0.0-rc.0
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/README.md +130 -27
- package/dist/TSelect-BmSkar0D.js +8697 -0
- package/dist/ansi-palette-Bv5Vqr4k.js +1499 -0
- package/dist/ansi-styles.d.ts +200 -0
- package/dist/cli/headless-renderer.d.ts +29 -0
- package/dist/cli/input.d.ts +49 -0
- package/dist/cli/node-file-writers.d.ts +12 -0
- package/dist/cli/node-module.d.ts +2 -0
- package/dist/cli/parse-kitty.d.ts +2 -0
- package/dist/cli/parse-mouse.d.ts +2 -0
- package/dist/cli/parse-utils.d.ts +14 -0
- package/dist/cli/parse-xterm.d.ts +2 -0
- package/dist/cli/path-provider-types.d.ts +1 -0
- package/dist/cli/path-provider.d.ts +4 -0
- package/dist/cli/path-suggest-core.d.ts +1 -0
- package/dist/cli/path-suggest.d.ts +15 -0
- package/dist/cli/recording.d.ts +4 -0
- package/dist/cli/stdin-buffer.d.ts +33 -0
- package/dist/cli.cjs +10664 -0
- package/dist/cli.d.cts +22 -0
- package/dist/cli.d.ts +22 -0
- package/dist/cli.js +9521 -0
- package/dist/core/ansi/capability.d.ts +20 -0
- package/dist/core/ansi/colors.d.ts +41 -0
- package/dist/core/ansi/sgr.d.ts +7 -0
- package/dist/core/ansi/theme.d.ts +6 -0
- package/dist/core/ansi-palette.d.ts +14 -0
- package/dist/core/buffer/buffer.d.ts +54 -0
- package/dist/core/buffer/width.d.ts +4 -0
- package/dist/core/debug-logger.d.ts +18 -0
- package/dist/core/hyperlink.d.ts +9 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/path-provider-types.d.ts +24 -0
- package/dist/core/path-suggest.d.ts +35 -0
- package/dist/core/render-plane.d.ts +3 -0
- package/dist/core/terminal/create-terminal.d.ts +7 -0
- package/dist/core/terminal/emitter.d.ts +7 -0
- package/dist/core/types.d.ts +107 -0
- package/dist/core.cjs +3072 -0
- package/dist/core.d.cts +14 -0
- package/dist/core.d.ts +14 -0
- package/dist/core.js +422 -0
- package/dist/create-terminal-app.d.ts +34 -0
- package/dist/dom-renderer-CDVQIcIL.js +1172 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/manager/cli-event-manager.d.ts +22 -0
- package/dist/events/manager/event-manager.d.ts +30 -0
- package/dist/events/manager/selection-suppression.d.ts +3 -0
- package/dist/events/manager/types.d.ts +108 -0
- package/dist/events/recording.d.ts +44 -0
- package/dist/experimental.cjs +1777 -1244
- package/dist/experimental.d.cts +39 -0
- package/dist/experimental.d.ts +39 -825
- package/dist/experimental.js +492 -343
- package/dist/frame-perf-C-w8mjJL.js +98 -0
- package/dist/hyperlink-B5PD7a3Q.js +331 -0
- package/dist/index.cjs +13133 -19960
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -1528
- package/dist/index.js +13 -20026
- package/dist/markdown.cjs +8728 -7359
- package/dist/markdown.d.cts +10 -0
- package/dist/markdown.d.ts +10 -112
- package/dist/markdown.js +169 -101
- package/dist/observability/cli-latency-node.d.ts +3 -0
- package/dist/observability/cli-latency-types.d.ts +41 -0
- package/dist/observability/cli-latency.d.ts +3 -0
- package/dist/observability/frame-perf-store.d.ts +13 -0
- package/dist/observability/frame-perf.d.ts +40 -0
- package/dist/observability/trace.d.ts +40 -0
- package/dist/observability/tui-profiler.d.ts +33 -0
- package/dist/observability.cjs +99 -0
- package/dist/observability.d.cts +6 -0
- package/dist/observability.d.ts +6 -0
- package/dist/observability.js +3 -0
- package/dist/path-DDiSCXrQ.js +99 -0
- package/dist/path-suggest-0Q2BDsuj.js +274 -0
- package/dist/path-suggest-Dk9TRLh5.js +3 -0
- package/dist/{path-suggest-DmrmeueH.js → path-suggest-bvR9SY6Q.js} +86 -18
- package/dist/renderer/capabilities.d.ts +13 -0
- package/dist/renderer/cli/index.d.ts +2 -0
- package/dist/renderer/cli/stdout-metrics.d.ts +18 -0
- package/dist/renderer/cli/stdout-renderer.d.ts +48 -0
- package/dist/renderer/dom/dom-renderer.d.ts +157 -0
- package/dist/renderer/dom/index.d.ts +2 -0
- package/dist/renderer/index.d.ts +2 -0
- package/dist/renderer-dom.cjs +1511 -0
- package/dist/renderer-dom.d.cts +4 -0
- package/dist/renderer-dom.d.ts +4 -0
- package/dist/renderer-dom.js +6 -0
- package/dist/runtime/index.d.ts +36 -0
- package/dist/runtime/osc52.d.ts +9 -0
- package/dist/runtime-DtrcQidD.js +1197 -0
- package/dist/runtime.cjs +1697 -0
- package/dist/runtime.d.cts +9 -0
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.js +4 -0
- package/dist/selection/terminal-selection.d.ts +122 -0
- package/dist/sgr-DMK2AvuT.js +304 -0
- package/dist/style-cache-i0ZABZRq.js +178 -0
- package/dist/terminal-selection-BCOh9jsL.js +329 -0
- package/dist/utils/env.d.ts +3 -0
- package/dist/utils/newlines.d.ts +1 -0
- package/dist/utils/path.d.ts +7 -0
- package/dist/utils/url-safety.d.ts +2 -0
- package/dist/vue/components/TAnchor.d.ts +108 -0
- package/dist/vue/components/TBox.d.ts +144 -0
- package/dist/vue/components/TDebugOverlay.d.ts +43 -0
- package/dist/vue/components/TDialog.d.ts +256 -0
- package/dist/vue/components/TFlow.d.ts +85 -0
- package/dist/vue/components/TInput.d.ts +554 -0
- package/dist/vue/components/TInputBox.d.ts +158 -0
- package/dist/vue/components/TJsonEditor.d.ts +165 -0
- package/dist/vue/components/TList.d.ts +119 -0
- package/dist/vue/components/TLogLinksPanel.d.ts +238 -0
- package/dist/vue/components/TLogMinimap.d.ts +263 -0
- package/dist/vue/components/TLogScrollbar.d.ts +236 -0
- package/dist/vue/components/TLogSearchBar.d.ts +267 -0
- package/dist/vue/components/TLogSearchPager.d.ts +162 -0
- package/dist/vue/components/TLogSearchResults.d.ts +200 -0
- package/dist/vue/components/TLogView.d.ts +502 -0
- package/dist/vue/components/TLogVirtualLinksPanel.d.ts +141 -0
- package/dist/vue/components/TLogVirtualSearchResults.d.ts +146 -0
- package/dist/vue/components/TMarkdownText.d.ts +134 -0
- package/dist/vue/components/TMultilineModal.d.ts +62 -0
- package/dist/vue/components/TPathPicker.d.ts +213 -0
- package/dist/vue/components/TRenderLayer.d.ts +16 -0
- package/dist/vue/components/TRenderPlane.d.ts +17 -0
- package/dist/vue/components/TSelect.d.ts +215 -0
- package/dist/vue/components/TText.d.ts +116 -0
- package/dist/vue/components/TTransition.d.ts +83 -0
- package/dist/vue/components/TView.d.ts +127 -0
- package/dist/vue/components/TVirtualList.d.ts +182 -0
- package/dist/vue/components/TVirtualMarkdown.d.ts +168 -0
- package/dist/vue/components/TerminalProvider.d.ts +195 -0
- package/dist/vue/components/input/host.d.ts +17 -0
- package/dist/vue/components/input/plugins/hostPlugin.d.ts +7 -0
- package/dist/vue/components/input/plugins/hostPlugin.node.d.ts +15 -0
- package/dist/vue/components/input/plugins/mentionUtils.d.ts +17 -0
- package/dist/vue/components/input/plugins/nodeMentionPathProvider.d.ts +2 -0
- package/dist/vue/components/input/plugins/promptMentionPlugin.d.ts +8 -0
- package/dist/vue/components/input/plugins/promptMentionState.d.ts +98 -0
- package/dist/vue/components/input/plugins/restrictText.d.ts +27 -0
- package/dist/vue/components/input/plugins/types.d.ts +90 -0
- package/dist/vue/components/input/utils/inlineText.d.ts +57 -0
- package/dist/vue/components/input/utils/inlineTextTokens.d.ts +34 -0
- package/dist/vue/components/input/utils/primitives.d.ts +3 -0
- package/dist/vue/components/input/utils/wordNavigation.d.ts +6 -0
- package/dist/vue/components/list/list-geometry.d.ts +16 -0
- package/dist/vue/components/list/list-paint.d.ts +1 -0
- package/dist/vue/components/list/scroll-state.d.ts +25 -0
- package/dist/vue/components/list/selection-state.d.ts +6 -0
- package/dist/vue/components/terminal-provider/copy-toast.d.ts +6 -0
- package/dist/vue/components/terminal-provider/portals.d.ts +17 -0
- package/dist/vue/components/terminal-provider/scheduler.d.ts +29 -0
- package/dist/vue/components/terminal-provider/selection-config.d.ts +15 -0
- package/dist/vue/components/terminal-provider/utils.d.ts +5 -0
- package/dist/vue/composables/use-layout.d.ts +2 -0
- package/dist/vue/composables/use-render-node.d.ts +19 -0
- package/dist/vue/composables/use-render-stack.d.ts +3 -0
- package/dist/vue/composables/use-runtime.d.ts +5 -0
- package/dist/vue/composables/use-terminal-node.d.ts +14 -0
- package/dist/vue/composables/use-terminal.d.ts +2 -0
- package/dist/vue/composables/use-visibility.d.ts +12 -0
- package/dist/vue/context.d.ts +153 -0
- package/dist/vue/index.d.ts +39 -0
- package/dist/vue/injection-key.d.ts +2 -0
- package/dist/vue/log/append-only-log-store.d.ts +2 -0
- package/dist/vue/log/tlog-keymap.d.ts +28 -0
- package/dist/vue/log/tlog-plugins.d.ts +144 -0
- package/dist/vue/log/tlog-session.d.ts +81 -0
- package/dist/vue/log/tlog-theme.d.ts +68 -0
- package/dist/vue/log/types.d.ts +43 -0
- package/dist/vue/log/use-tlog-link-controller.d.ts +31 -0
- package/dist/vue/log/use-tlog-retained-index.d.ts +26 -0
- package/dist/vue/log/use-tlog-search-controller.d.ts +51 -0
- package/dist/vue/log/use-tlog-search-results-page.d.ts +31 -0
- package/dist/vue/log/use-tlog-virtual-search-results.d.ts +22 -0
- package/dist/vue/markdown/ast.d.ts +3 -0
- package/dist/vue/markdown/block-source.d.ts +22 -0
- package/dist/vue/markdown/document.d.ts +18 -0
- package/dist/vue/markdown/layout.d.ts +16 -0
- package/dist/vue/markdown/parser.d.ts +11 -0
- package/dist/vue/markdown/render.d.ts +10 -0
- package/dist/vue/markdown/theme.d.ts +186 -0
- package/dist/vue/markdown/types.d.ts +47 -0
- package/dist/vue/render/context.d.ts +3 -0
- package/dist/vue/render/render-manager.d.ts +94 -0
- package/dist/vue/router/RouterView.d.ts +25 -0
- package/dist/vue/router/composables.d.ts +4 -0
- package/dist/vue/router/context.d.ts +4 -0
- package/dist/vue/router/router.d.ts +7 -0
- package/dist/vue/router/types.d.ts +29 -0
- package/dist/vue/scheduler/frame-mailbox.d.ts +55 -0
- package/dist/vue/scheduler/frame-scheduler.d.ts +51 -0
- package/dist/vue/utils/frame-task.d.ts +6 -0
- package/dist/vue/utils/rect.d.ts +4 -0
- package/dist/vue/utils/style-cache.d.ts +3 -0
- package/dist/vue/utils/text.d.ts +26 -0
- package/dist/vue/utils/wheel-scroll.d.ts +18 -0
- package/dist/vue.cjs +18882 -0
- package/dist/vue.d.cts +3 -0
- package/dist/vue.d.ts +3 -0
- package/dist/vue.js +3066 -0
- package/dist/{wheel-scroll-CiNsasLf.js → wheel-scroll-B-WlFuNB.js} +361 -367
- package/package.json +165 -35
- package/dist/path-suggest-BeV6n7m-.js +0 -3
- package/dist/sgr-Tko2EQ0U.js +0 -484
- package/dist/theme-Bsm65g8k.d.ts +0 -32
- package/dist/types-ClIV2h1o.d.ts +0 -103
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { TMarkdownText } from "./vue/components/TMarkdownText.js";
|
|
2
|
+
export { TVirtualMarkdown } from "./vue/components/TVirtualMarkdown.js";
|
|
3
|
+
export { createMarkdownBlockSource } from "./vue/markdown/block-source.js";
|
|
4
|
+
export { buildMarkdownBlocks, buildMarkdownVisualRows } from "./vue/markdown/document.js";
|
|
5
|
+
export { layoutMarkdownBlocks } from "./vue/markdown/layout.js";
|
|
6
|
+
export { createTuiMarkdownParser, isSafeMarkdownLink } from "./vue/markdown/parser.js";
|
|
7
|
+
export type { TuiMarkdownBlockSource, TuiMarkdownBlockSourceOptions, TuiMarkdownBlockSourceSnapshot, } from "./vue/markdown/block-source.js";
|
|
8
|
+
export type { TuiMarkdownBlock, TuiMarkdownInlineSegment, TuiMarkdownNode, TuiMarkdownVisualRow, TuiMarkdownVisualSegment, } from "./vue/markdown/types.js";
|
|
9
|
+
export type { TuiMarkdownParseConfig, TuiMarkdownParser } from "./vue/markdown/parser.js";
|
|
10
|
+
export type { TuiMarkdownTheme, TuiMarkdownThemeOverrides } from "./vue/markdown/theme.js";
|
package/dist/markdown.d.ts
CHANGED
|
@@ -1,112 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/vue/markdown/parser.d.ts
|
|
14
|
-
interface TuiMarkdownParseConfig {
|
|
15
|
-
streaming?: boolean;
|
|
16
|
-
customHtmlTags?: readonly string[];
|
|
17
|
-
}
|
|
18
|
-
interface TuiMarkdownParser {
|
|
19
|
-
parse: (content: string, final: boolean) => ParsedNode[];
|
|
20
|
-
}
|
|
21
|
-
declare function isSafeMarkdownLink(url: string): boolean;
|
|
22
|
-
declare function createTuiMarkdownParser(config?: TuiMarkdownParseConfig): TuiMarkdownParser;
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/vue/markdown/types.d.ts
|
|
26
|
-
type TuiMarkdownInlineSegment = Readonly<{
|
|
27
|
-
text: string;
|
|
28
|
-
style?: Style;
|
|
29
|
-
hardBreak?: boolean;
|
|
30
|
-
}>;
|
|
31
|
-
type TuiMarkdownBlock = Readonly<{
|
|
32
|
-
type: "inline";
|
|
33
|
-
key: string;
|
|
34
|
-
segments: readonly TuiMarkdownInlineSegment[];
|
|
35
|
-
prefixSegments?: readonly TuiMarkdownInlineSegment[];
|
|
36
|
-
continuationPrefixSegments?: readonly TuiMarkdownInlineSegment[];
|
|
37
|
-
}> | Readonly<{
|
|
38
|
-
type: "code_block";
|
|
39
|
-
key: string;
|
|
40
|
-
lines: readonly string[];
|
|
41
|
-
style?: Style;
|
|
42
|
-
prefixSegments?: readonly TuiMarkdownInlineSegment[];
|
|
43
|
-
continuationPrefixSegments?: readonly TuiMarkdownInlineSegment[];
|
|
44
|
-
}> | Readonly<{
|
|
45
|
-
type: "thematic_break";
|
|
46
|
-
key: string;
|
|
47
|
-
char?: string;
|
|
48
|
-
style?: Style;
|
|
49
|
-
prefixSegments?: readonly TuiMarkdownInlineSegment[];
|
|
50
|
-
}> | Readonly<{
|
|
51
|
-
type: "blank";
|
|
52
|
-
key: string;
|
|
53
|
-
}>;
|
|
54
|
-
type TuiMarkdownVisualSegment = Readonly<{
|
|
55
|
-
text: string;
|
|
56
|
-
style?: Style;
|
|
57
|
-
cells: number;
|
|
58
|
-
}>;
|
|
59
|
-
type TuiMarkdownVisualRow = Readonly<{
|
|
60
|
-
key: string;
|
|
61
|
-
blockKey: string;
|
|
62
|
-
rowInBlock: number;
|
|
63
|
-
plainText: string;
|
|
64
|
-
segments: readonly TuiMarkdownVisualSegment[];
|
|
65
|
-
}>;
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/vue/markdown/block-source.d.ts
|
|
69
|
-
type TuiMarkdownBlockSourceSnapshot = Readonly<{
|
|
70
|
-
version: number;
|
|
71
|
-
blocks: readonly TuiMarkdownBlock[];
|
|
72
|
-
}>;
|
|
73
|
-
type TuiMarkdownBlockSource = Readonly<{
|
|
74
|
-
version: number;
|
|
75
|
-
blocks: readonly TuiMarkdownBlock[];
|
|
76
|
-
appendDelta: (text: string) => void;
|
|
77
|
-
replaceTailBlock: (text: string) => void;
|
|
78
|
-
finalizeBlock: () => void;
|
|
79
|
-
clear: () => void;
|
|
80
|
-
snapshot: () => TuiMarkdownBlockSourceSnapshot;
|
|
81
|
-
}>;
|
|
82
|
-
type TuiMarkdownBlockSourceOptions = Readonly<{
|
|
83
|
-
parser?: TuiMarkdownParser;
|
|
84
|
-
customHtmlTags?: readonly string[];
|
|
85
|
-
theme?: TuiMarkdownThemeOverrides;
|
|
86
|
-
}>;
|
|
87
|
-
declare function createMarkdownBlockSource(options?: TuiMarkdownBlockSourceOptions): TuiMarkdownBlockSource;
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/vue/markdown/document.d.ts
|
|
91
|
-
/**
|
|
92
|
-
* This helper always builds visual rows from the full source string. Components
|
|
93
|
-
* that need streaming reuse can call buildMarkdownBlocks and cache block layout.
|
|
94
|
-
*/
|
|
95
|
-
declare function buildMarkdownBlocks(content: string, parser: TuiMarkdownParser, options?: Readonly<{
|
|
96
|
-
final?: boolean;
|
|
97
|
-
theme?: TuiMarkdownThemeOverrides;
|
|
98
|
-
}>): Readonly<{
|
|
99
|
-
nodes: readonly ParsedNode[];
|
|
100
|
-
blocks: readonly TuiMarkdownBlock[];
|
|
101
|
-
}>;
|
|
102
|
-
declare function buildMarkdownVisualRows(content: string, width: number, parser: TuiMarkdownParser, options?: Readonly<{
|
|
103
|
-
final?: boolean;
|
|
104
|
-
theme?: TuiMarkdownThemeOverrides;
|
|
105
|
-
}>): readonly TuiMarkdownVisualRow[];
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/vue/markdown/layout.d.ts
|
|
109
|
-
declare function layoutMarkdownBlocks(blocks: readonly TuiMarkdownBlock[], width: number): readonly TuiMarkdownVisualRow[];
|
|
110
|
-
|
|
111
|
-
//#endregion
|
|
112
|
-
export { TMarkdownText, TVirtualMarkdown, TuiMarkdownBlock, TuiMarkdownBlockSource, TuiMarkdownBlockSourceOptions, TuiMarkdownBlockSourceSnapshot, TuiMarkdownInlineSegment, TuiMarkdownParseConfig, TuiMarkdownParser, TuiMarkdownTheme, TuiMarkdownThemeOverrides, TuiMarkdownVisualRow, TuiMarkdownVisualSegment, buildMarkdownBlocks, buildMarkdownVisualRows, createMarkdownBlockSource, createTuiMarkdownParser, isSafeMarkdownLink, layoutMarkdownBlocks };
|
|
1
|
+
export { TMarkdownText } from "./vue/components/TMarkdownText.js";
|
|
2
|
+
export { TVirtualMarkdown } from "./vue/components/TVirtualMarkdown.js";
|
|
3
|
+
export { createMarkdownBlockSource } from "./vue/markdown/block-source.js";
|
|
4
|
+
export { buildMarkdownBlocks, buildMarkdownVisualRows } from "./vue/markdown/document.js";
|
|
5
|
+
export { layoutMarkdownBlocks } from "./vue/markdown/layout.js";
|
|
6
|
+
export { createTuiMarkdownParser, isSafeMarkdownLink } from "./vue/markdown/parser.js";
|
|
7
|
+
export type { TuiMarkdownBlockSource, TuiMarkdownBlockSourceOptions, TuiMarkdownBlockSourceSnapshot, } from "./vue/markdown/block-source.js";
|
|
8
|
+
export type { TuiMarkdownBlock, TuiMarkdownInlineSegment, TuiMarkdownNode, TuiMarkdownVisualRow, TuiMarkdownVisualSegment, } from "./vue/markdown/types.js";
|
|
9
|
+
export type { TuiMarkdownParseConfig, TuiMarkdownParser } from "./vue/markdown/parser.js";
|
|
10
|
+
export type { TuiMarkdownTheme, TuiMarkdownThemeOverrides } from "./vue/markdown/theme.js";
|
package/dist/markdown.js
CHANGED
|
@@ -1,70 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sanitizeDomHref } from "./hyperlink-B5PD7a3Q.js";
|
|
2
|
+
import { terminalSelectionRowSpans, terminalSelectionVisibleRowSpans } from "./terminal-selection-BCOh9jsL.js";
|
|
3
|
+
import { EventZIndexContextKey, applyWheelScroll, createWheelScrollState, forEachTextCellSegment, intersectRect, normalizeCellRect, repeatChar, resetWheelScrollState, sanitizeInlineText, sanitizeTextBlock, sliceByCellsRange, spaces, textCellWidth, translateRect, useLayout, useRenderNode, useTerminal, useTerminalNode, useVisibility } from "./wheel-scroll-B-WlFuNB.js";
|
|
2
4
|
import { computed, defineComponent, getCurrentInstance, h, inject, markRaw, onBeforeUnmount, ref, shallowRef, watch, watchEffect } from "vue";
|
|
3
5
|
import { getMarkdown, parseMarkdownToStructure } from "stream-markdown-parser";
|
|
4
6
|
|
|
5
7
|
//#region src/vue/markdown/parser.ts
|
|
6
|
-
const RELATIVE_LINK_PREFIXES = [
|
|
7
|
-
"#",
|
|
8
|
-
"/",
|
|
9
|
-
"./",
|
|
10
|
-
"../"
|
|
11
|
-
];
|
|
12
|
-
const SAFE_PROTOCOLS = new Set([
|
|
13
|
-
"http:",
|
|
14
|
-
"https:",
|
|
15
|
-
"mailto:"
|
|
16
|
-
]);
|
|
17
8
|
const markdownInstanceCache = new Map();
|
|
18
9
|
const MAX_MARKDOWN_INSTANCE_CACHE = 32;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (const ch of value) {
|
|
22
|
-
const code = ch.codePointAt(0);
|
|
23
|
-
if (code >= 0 && code <= 31 || code >= 127 && code <= 159) return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
10
|
+
function sanitizeMarkdownLink(url) {
|
|
11
|
+
return sanitizeDomHref(url, { allowRelative: true });
|
|
26
12
|
}
|
|
27
13
|
function isSafeMarkdownLink(url) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const value = raw.toLowerCase();
|
|
33
|
-
if (value.startsWith("javascript:")) return false;
|
|
34
|
-
if (value.startsWith("data:")) return false;
|
|
35
|
-
if (RELATIVE_LINK_PREFIXES.some((prefix) => raw.startsWith(prefix))) return true;
|
|
36
|
-
if (!SCHEME_RE.test(raw)) return true;
|
|
37
|
-
try {
|
|
38
|
-
const parsed = new URL(raw);
|
|
39
|
-
return SAFE_PROTOCOLS.has(parsed.protocol);
|
|
40
|
-
} catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
14
|
+
return sanitizeMarkdownLink(url) != null;
|
|
15
|
+
}
|
|
16
|
+
function normalizeCustomHtmlTags(config) {
|
|
17
|
+
return Array.from(new Set(config?.customHtmlTags?.filter(Boolean) ?? [])).sort();
|
|
43
18
|
}
|
|
44
|
-
function markdownInstanceCacheKey(
|
|
45
|
-
|
|
46
|
-
return JSON.stringify({ customHtmlTags: [...(config === null || config === void 0 || (_config$customHtmlTag = config.customHtmlTags) === null || _config$customHtmlTag === void 0 ? void 0 : _config$customHtmlTag.filter(Boolean)) ?? []].sort() });
|
|
19
|
+
function markdownInstanceCacheKey(customHtmlTags) {
|
|
20
|
+
return JSON.stringify({ customHtmlTags });
|
|
47
21
|
}
|
|
48
|
-
function getCachedMarkdownInstance(
|
|
49
|
-
|
|
50
|
-
const cacheKey = markdownInstanceCacheKey(config);
|
|
22
|
+
function getCachedMarkdownInstance(customHtmlTags) {
|
|
23
|
+
const cacheKey = markdownInstanceCacheKey(customHtmlTags);
|
|
51
24
|
const cached = markdownInstanceCache.get(cacheKey);
|
|
52
|
-
if (cached)
|
|
53
|
-
|
|
25
|
+
if (cached) {
|
|
26
|
+
markdownInstanceCache.delete(cacheKey);
|
|
27
|
+
markdownInstanceCache.set(cacheKey, cached);
|
|
28
|
+
return cached;
|
|
29
|
+
}
|
|
54
30
|
const created = getMarkdown(`vue-tui-markdown:${cacheKey}`, { customHtmlTags });
|
|
55
|
-
if (markdownInstanceCache.size >= MAX_MARKDOWN_INSTANCE_CACHE) markdownInstanceCache.clear();
|
|
56
31
|
markdownInstanceCache.set(cacheKey, created);
|
|
32
|
+
while (markdownInstanceCache.size > MAX_MARKDOWN_INSTANCE_CACHE) {
|
|
33
|
+
const oldest = markdownInstanceCache.keys().next().value;
|
|
34
|
+
if (oldest == null) break;
|
|
35
|
+
markdownInstanceCache.delete(oldest);
|
|
36
|
+
}
|
|
57
37
|
return created;
|
|
58
38
|
}
|
|
59
39
|
function createTuiMarkdownParser(config) {
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const md = getCachedMarkdownInstance(config);
|
|
40
|
+
const customHtmlTags = normalizeCustomHtmlTags(config);
|
|
41
|
+
const md = getCachedMarkdownInstance(customHtmlTags);
|
|
63
42
|
function parse(content, final) {
|
|
64
43
|
return parseMarkdownToStructure(content, md, {
|
|
65
44
|
final,
|
|
66
45
|
customHtmlTags,
|
|
67
|
-
requireClosingStrong: final || !
|
|
46
|
+
requireClosingStrong: final || !config?.streaming,
|
|
68
47
|
validateLink: isSafeMarkdownLink
|
|
69
48
|
});
|
|
70
49
|
}
|
|
@@ -87,11 +66,10 @@ function mergeStyle$1(base, overlay) {
|
|
|
87
66
|
};
|
|
88
67
|
}
|
|
89
68
|
function trimBlockArray(blocks) {
|
|
90
|
-
var _blocks$start, _blocks;
|
|
91
69
|
let start = 0;
|
|
92
70
|
let end = blocks.length;
|
|
93
|
-
while (start < end &&
|
|
94
|
-
while (end > start &&
|
|
71
|
+
while (start < end && blocks[start]?.type === "blank") start++;
|
|
72
|
+
while (end > start && blocks[end - 1]?.type === "blank") end--;
|
|
95
73
|
return blocks.slice(start, end);
|
|
96
74
|
}
|
|
97
75
|
function nodeChildren(node) {
|
|
@@ -104,6 +82,14 @@ function stringProp(node, key) {
|
|
|
104
82
|
function booleanProp(node, key) {
|
|
105
83
|
return node[key] === true;
|
|
106
84
|
}
|
|
85
|
+
function numberProp(node, key) {
|
|
86
|
+
const value = node[key];
|
|
87
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
88
|
+
}
|
|
89
|
+
function nodeItems(node) {
|
|
90
|
+
const value = node.items;
|
|
91
|
+
return Array.isArray(value) ? value : [];
|
|
92
|
+
}
|
|
107
93
|
function pushTextSegments(out, text, style) {
|
|
108
94
|
if (!text) return;
|
|
109
95
|
const normalized = sanitizeTextBlock(text);
|
|
@@ -165,7 +151,7 @@ function inlineNodeSegments(nodes, theme, inheritedStyle) {
|
|
|
165
151
|
break;
|
|
166
152
|
case "link": {
|
|
167
153
|
const href = stringProp(node, "href");
|
|
168
|
-
const safeHref = href
|
|
154
|
+
const safeHref = href ? sanitizeMarkdownLink(href) : null;
|
|
169
155
|
const linkStyle = safeHref ? mergeStyle$1(inheritedStyle, {
|
|
170
156
|
...theme.link,
|
|
171
157
|
href: safeHref
|
|
@@ -191,7 +177,7 @@ function inlineNodeSegments(nodes, theme, inheritedStyle) {
|
|
|
191
177
|
case "reference":
|
|
192
178
|
case "footnote_reference":
|
|
193
179
|
case "footnote_anchor":
|
|
194
|
-
pushTextSegments(out, node
|
|
180
|
+
pushTextSegments(out, stringProp(node, "raw"), inheritedStyle);
|
|
195
181
|
break;
|
|
196
182
|
case "html_inline":
|
|
197
183
|
pushTextSegments(out, stringProp(node, "content"), mergeStyle$1(inheritedStyle, theme.html));
|
|
@@ -204,7 +190,7 @@ function inlineNodeSegments(nodes, theme, inheritedStyle) {
|
|
|
204
190
|
out.push(...inlineNodeSegments(nodeChildren(node), theme, inheritedStyle));
|
|
205
191
|
break;
|
|
206
192
|
}
|
|
207
|
-
pushTextSegments(out, node
|
|
193
|
+
pushTextSegments(out, stringProp(node, "raw"), inheritedStyle);
|
|
208
194
|
break;
|
|
209
195
|
}
|
|
210
196
|
return out;
|
|
@@ -219,17 +205,17 @@ function inlineBlock(key, segments, context) {
|
|
|
219
205
|
};
|
|
220
206
|
}
|
|
221
207
|
function blockFromParagraph(node, key, context, theme) {
|
|
222
|
-
return inlineBlock(key, inlineNodeSegments(node
|
|
208
|
+
return inlineBlock(key, inlineNodeSegments(nodeChildren(node), theme), context);
|
|
223
209
|
}
|
|
224
210
|
function blockFromHeading(node, key, context, theme) {
|
|
225
|
-
const level = Math.min(6, Math.max(1, Math.floor(node
|
|
226
|
-
return inlineBlock(key, inlineNodeSegments(node
|
|
211
|
+
const level = Math.min(6, Math.max(1, Math.floor(numberProp(node, "level") ?? 1)));
|
|
212
|
+
return inlineBlock(key, inlineNodeSegments(nodeChildren(node), theme, theme.heading[level - 1]), context);
|
|
227
213
|
}
|
|
228
214
|
function blockFromCodeBlock(node, key, context, theme) {
|
|
229
215
|
return {
|
|
230
216
|
type: "code_block",
|
|
231
217
|
key,
|
|
232
|
-
lines: sanitizeCodeBlockText(node
|
|
218
|
+
lines: sanitizeCodeBlockText(stringProp(node, "code")).split("\n"),
|
|
233
219
|
style: theme.codeBlock,
|
|
234
220
|
prefixSegments: context.prefixSegments,
|
|
235
221
|
continuationPrefixSegments: context.continuationPrefixSegments
|
|
@@ -238,18 +224,17 @@ function blockFromCodeBlock(node, key, context, theme) {
|
|
|
238
224
|
function blockFromHtmlBlock(node, key, context, theme) {
|
|
239
225
|
return inlineBlock(key, inlineNodeSegments([{
|
|
240
226
|
type: "html_block",
|
|
241
|
-
raw: node
|
|
242
|
-
content: node
|
|
227
|
+
raw: stringProp(node, "raw"),
|
|
228
|
+
content: stringProp(node, "content")
|
|
243
229
|
}], theme), context);
|
|
244
230
|
}
|
|
245
231
|
function childSequenceToBlocks(nodes, context, theme, keyPrefix) {
|
|
246
232
|
const out = [];
|
|
247
233
|
let appended = false;
|
|
248
234
|
for (let i = 0; i < nodes.length; i++) {
|
|
249
|
-
var _out, _childBlocks$;
|
|
250
235
|
const childBlocks = trimBlockArray(nodeToBlocks(nodes[i], context, theme, `${keyPrefix}-${i}`));
|
|
251
236
|
if (!childBlocks.length) continue;
|
|
252
|
-
if (appended &&
|
|
237
|
+
if (appended && out[out.length - 1]?.type !== "blank" && childBlocks[0]?.type !== "blank") out.push({
|
|
253
238
|
type: "blank",
|
|
254
239
|
key: `${keyPrefix}-${i}-gap`
|
|
255
240
|
});
|
|
@@ -274,12 +259,12 @@ function listItemBlocks(item, index, ordered, start, context, theme, keyPrefix)
|
|
|
274
259
|
prefixSegments: [...context.continuationPrefixSegments, indentSegment],
|
|
275
260
|
continuationPrefixSegments: [...context.continuationPrefixSegments, indentSegment]
|
|
276
261
|
};
|
|
277
|
-
|
|
262
|
+
const children = nodeChildren(item);
|
|
263
|
+
if (!children.length) return [inlineBlock(`${keyPrefix}-empty`, [], firstContext)];
|
|
278
264
|
const out = [];
|
|
279
265
|
let usedLead = false;
|
|
280
|
-
for (let i = 0; i <
|
|
281
|
-
|
|
282
|
-
const child = item.children[i];
|
|
266
|
+
for (let i = 0; i < children.length; i++) {
|
|
267
|
+
const child = children[i];
|
|
283
268
|
const useLeadContext = !usedLead && (child.type === "paragraph" || child.type === "heading" || child.type === "code_block");
|
|
284
269
|
if (!usedLead && !useLeadContext) {
|
|
285
270
|
out.push(inlineBlock(`${keyPrefix}-marker`, [], firstContext));
|
|
@@ -287,8 +272,8 @@ function listItemBlocks(item, index, ordered, start, context, theme, keyPrefix)
|
|
|
287
272
|
}
|
|
288
273
|
const childBlocks = trimBlockArray(nodeToBlocks(child, useLeadContext && !usedLead ? firstContext : nestedContext, theme, `${keyPrefix}-${i}`));
|
|
289
274
|
if (!childBlocks.length) continue;
|
|
290
|
-
const startsNestedList = child.type === "list" && out.length > 0 &&
|
|
291
|
-
if (out.length &&
|
|
275
|
+
const startsNestedList = child.type === "list" && out.length > 0 && out[out.length - 1]?.type === "inline" && childBlocks[0]?.type === "inline";
|
|
276
|
+
if (out.length && out[out.length - 1]?.type !== "blank" && childBlocks[0]?.type !== "blank" && !startsNestedList) out.push({
|
|
292
277
|
type: "blank",
|
|
293
278
|
key: `${keyPrefix}-${i}-gap`
|
|
294
279
|
});
|
|
@@ -300,7 +285,8 @@ function listItemBlocks(item, index, ordered, start, context, theme, keyPrefix)
|
|
|
300
285
|
}
|
|
301
286
|
function listBlocks(node, context, theme, keyPrefix) {
|
|
302
287
|
const out = [];
|
|
303
|
-
|
|
288
|
+
const items = nodeItems(node);
|
|
289
|
+
for (let i = 0; i < items.length; i++) out.push(...listItemBlocks(items[i], i, booleanProp(node, "ordered"), numberProp(node, "start") ?? 1, context, theme, `${keyPrefix}-${i}`));
|
|
304
290
|
return out;
|
|
305
291
|
}
|
|
306
292
|
function nodeToBlocks(node, context, theme, keyPrefix) {
|
|
@@ -621,13 +607,13 @@ function layoutMarkdownBlocksCached(blocks, width, previous) {
|
|
|
621
607
|
};
|
|
622
608
|
const rows = [];
|
|
623
609
|
const entries = new Map();
|
|
624
|
-
const previousEntries =
|
|
610
|
+
const previousEntries = previous?.width === normalizedWidth ? previous.entries : void 0;
|
|
625
611
|
for (let index = 0; index < blocks.length; index++) {
|
|
626
612
|
const block = blocks[index];
|
|
627
613
|
const cacheKey = `${index}\u0000${block.key}`;
|
|
628
614
|
const signature = blockLayoutSignature(block);
|
|
629
|
-
const cached = previousEntries
|
|
630
|
-
const blockRows =
|
|
615
|
+
const cached = previousEntries?.get(cacheKey);
|
|
616
|
+
const blockRows = cached?.signature === signature ? cached.rows : layoutMarkdownBlock(block, normalizedWidth);
|
|
631
617
|
if (blockRows.length) {
|
|
632
618
|
rows.push(...blockRows);
|
|
633
619
|
entries.set(cacheKey, {
|
|
@@ -725,10 +711,7 @@ function markdownThemeSignature(overrides) {
|
|
|
725
711
|
}
|
|
726
712
|
function resolveTuiMarkdownTheme(overrides) {
|
|
727
713
|
if (!overrides) return DEFAULT_TUI_MARKDOWN_THEME;
|
|
728
|
-
const heading = DEFAULT_TUI_MARKDOWN_THEME.heading.map((style, index) =>
|
|
729
|
-
var _overrides$heading;
|
|
730
|
-
return mergeFrozenStyle(style, (_overrides$heading = overrides.heading) === null || _overrides$heading === void 0 ? void 0 : _overrides$heading[index]);
|
|
731
|
-
});
|
|
714
|
+
const heading = DEFAULT_TUI_MARKDOWN_THEME.heading.map((style, index) => mergeFrozenStyle(style, overrides.heading?.[index]));
|
|
732
715
|
return Object.freeze({
|
|
733
716
|
heading: Object.freeze(heading),
|
|
734
717
|
strong: mergeFrozenStyle(DEFAULT_TUI_MARKDOWN_THEME.strong, overrides.strong),
|
|
@@ -751,9 +734,9 @@ function resolveTuiMarkdownTheme(overrides) {
|
|
|
751
734
|
* that need streaming reuse can call buildMarkdownBlocks and cache block layout.
|
|
752
735
|
*/
|
|
753
736
|
function buildMarkdownBlocks(content, parser, options) {
|
|
754
|
-
const theme = resolveTuiMarkdownTheme(options
|
|
737
|
+
const theme = resolveTuiMarkdownTheme(options?.theme);
|
|
755
738
|
try {
|
|
756
|
-
const nodes = parser.parse(content,
|
|
739
|
+
const nodes = parser.parse(content, options?.final ?? true);
|
|
757
740
|
const blocks = markdownAstToBlocks(nodes, theme);
|
|
758
741
|
return {
|
|
759
742
|
nodes,
|
|
@@ -972,7 +955,7 @@ const TMarkdownText = defineComponent({
|
|
|
972
955
|
return;
|
|
973
956
|
}
|
|
974
957
|
scheduler.queueFrameTask({
|
|
975
|
-
id: `TMarkdownText:${
|
|
958
|
+
id: `TMarkdownText:${instance?.uid ?? "unknown"}:markdown`,
|
|
976
959
|
reason: props.streaming ? "stream" : "data",
|
|
977
960
|
priority: props.streaming ? "low" : "normal",
|
|
978
961
|
sync: false,
|
|
@@ -1053,7 +1036,7 @@ const TMarkdownText = defineComponent({
|
|
|
1053
1036
|
clear: props.clear
|
|
1054
1037
|
});
|
|
1055
1038
|
};
|
|
1056
|
-
if (dirtyRows
|
|
1039
|
+
if (dirtyRows?.length) {
|
|
1057
1040
|
for (const y of dirtyRows) paintRow(y);
|
|
1058
1041
|
return;
|
|
1059
1042
|
}
|
|
@@ -1183,7 +1166,7 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1183
1166
|
],
|
|
1184
1167
|
setup(props, { emit }) {
|
|
1185
1168
|
const instance = getCurrentInstance();
|
|
1186
|
-
const { terminal, defaultStyle, events, scheduler } = useTerminal();
|
|
1169
|
+
const { terminal, defaultStyle, events, scheduler, selection } = useTerminal();
|
|
1187
1170
|
const layout = useLayout();
|
|
1188
1171
|
const { visible, rootProps } = useVisibility();
|
|
1189
1172
|
const parentEventZ = inject(EventZIndexContextKey, computed(() => 0));
|
|
@@ -1191,6 +1174,7 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1191
1174
|
const internalScrollTop = ref(0);
|
|
1192
1175
|
const documentVersion = ref(0);
|
|
1193
1176
|
const rows = shallowRef(markRaw([]));
|
|
1177
|
+
let pendingSelectionScrollFocusRemap = false;
|
|
1194
1178
|
const wheelState = createWheelScrollState();
|
|
1195
1179
|
let builtOnce = false;
|
|
1196
1180
|
let rebuildVersion = 0;
|
|
@@ -1221,7 +1205,10 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1221
1205
|
const nextScrollTop = internalScrollTop.value;
|
|
1222
1206
|
const nextVisibleRows = visibleRowSignatures(nextRows, nextScrollTop);
|
|
1223
1207
|
const visibleChanged = prevVisibleRows.length !== nextVisibleRows.length || prevVisibleRows.some((row, index) => row !== nextVisibleRows[index]);
|
|
1224
|
-
if (!builtOnce || prevScrollTop !== nextScrollTop || visibleChanged)
|
|
1208
|
+
if (!builtOnce || prevScrollTop !== nextScrollTop || visibleChanged) {
|
|
1209
|
+
documentVersion.value++;
|
|
1210
|
+
selection.refresh();
|
|
1211
|
+
}
|
|
1225
1212
|
}
|
|
1226
1213
|
function scheduleRebuild() {
|
|
1227
1214
|
const currentVersion = ++rebuildVersion;
|
|
@@ -1231,7 +1218,7 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1231
1218
|
return;
|
|
1232
1219
|
}
|
|
1233
1220
|
scheduler.queueFrameTask({
|
|
1234
|
-
id: `TVirtualMarkdown:${
|
|
1221
|
+
id: `TVirtualMarkdown:${instance?.uid ?? "unknown"}:markdown`,
|
|
1235
1222
|
reason: props.streaming ? "stream" : "data",
|
|
1236
1223
|
priority: props.streaming ? "low" : "normal",
|
|
1237
1224
|
sync: false,
|
|
@@ -1287,16 +1274,29 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1287
1274
|
return out;
|
|
1288
1275
|
}
|
|
1289
1276
|
function hasControlledScrollTop() {
|
|
1290
|
-
return Object.prototype.hasOwnProperty.call(
|
|
1277
|
+
return Object.prototype.hasOwnProperty.call(instance?.vnode.props ?? {}, "scrollTop");
|
|
1291
1278
|
}
|
|
1292
|
-
function
|
|
1293
|
-
const
|
|
1294
|
-
|
|
1295
|
-
internalScrollTop.value
|
|
1296
|
-
if (
|
|
1279
|
+
function applyControlledScrollTop(next, remapSelectionFocus = false) {
|
|
1280
|
+
const desired = Math.floor(Number(next) || 0);
|
|
1281
|
+
const clamped = clamp(desired, 0, maxScrollTop());
|
|
1282
|
+
const changed = internalScrollTop.value !== clamped;
|
|
1283
|
+
if (changed) internalScrollTop.value = clamped;
|
|
1284
|
+
if (desired !== clamped) {
|
|
1285
|
+
emit("update:scrollTop", clamped);
|
|
1286
|
+
emit("scroll", clamped);
|
|
1287
|
+
}
|
|
1288
|
+
if (changed || remapSelectionFocus) selection.refresh(remapSelectionFocus ? { remapFocus: true } : void 0);
|
|
1289
|
+
}
|
|
1290
|
+
function setScrollTop(next, emitChange = true, refreshOptions) {
|
|
1291
|
+
const desired = Math.floor(Number(next) || 0);
|
|
1292
|
+
const clamped = clamp(desired, 0, maxScrollTop());
|
|
1293
|
+
const changed = internalScrollTop.value !== clamped;
|
|
1294
|
+
if (changed) internalScrollTop.value = clamped;
|
|
1295
|
+
if (emitChange && (changed || refreshOptions?.emitClampEvenIfUnchanged && desired !== clamped)) {
|
|
1297
1296
|
emit("update:scrollTop", clamped);
|
|
1298
1297
|
emit("scroll", clamped);
|
|
1299
1298
|
}
|
|
1299
|
+
if (changed || refreshOptions?.remapSelectionFocus) selection.refresh(refreshOptions?.remapSelectionFocus ? { remapFocus: true } : void 0);
|
|
1300
1300
|
}
|
|
1301
1301
|
function reconcileScrollTop() {
|
|
1302
1302
|
const desired = hasControlledScrollTop() ? Math.floor(Number(props.scrollTop) || 0) : internalScrollTop.value;
|
|
@@ -1307,16 +1307,13 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1307
1307
|
emit("update:scrollTop", clamped);
|
|
1308
1308
|
emit("scroll", clamped);
|
|
1309
1309
|
}
|
|
1310
|
+
selection.refresh();
|
|
1310
1311
|
}
|
|
1311
1312
|
watch(() => props.scrollTop, () => {
|
|
1312
1313
|
if (!hasControlledScrollTop()) return;
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
if (desired !== clamped) {
|
|
1317
|
-
emit("update:scrollTop", clamped);
|
|
1318
|
-
emit("scroll", clamped);
|
|
1319
|
-
}
|
|
1314
|
+
const remap = pendingSelectionScrollFocusRemap;
|
|
1315
|
+
pendingSelectionScrollFocusRemap = false;
|
|
1316
|
+
applyControlledScrollTop(props.scrollTop, remap);
|
|
1320
1317
|
});
|
|
1321
1318
|
watch([
|
|
1322
1319
|
() => props.content,
|
|
@@ -1345,6 +1342,65 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1345
1342
|
], () => {
|
|
1346
1343
|
reconcileScrollTop();
|
|
1347
1344
|
}, { immediate: true });
|
|
1345
|
+
function scrollSelectionBy(delta) {
|
|
1346
|
+
const n = Math.trunc(Number(delta));
|
|
1347
|
+
if (!Number.isFinite(n) || n === 0) return false;
|
|
1348
|
+
if (hasControlledScrollTop()) {
|
|
1349
|
+
const nextTop = clamp(internalScrollTop.value + n, 0, maxScrollTop());
|
|
1350
|
+
if (nextTop === internalScrollTop.value) return false;
|
|
1351
|
+
if (pendingSelectionScrollFocusRemap) return false;
|
|
1352
|
+
pendingSelectionScrollFocusRemap = true;
|
|
1353
|
+
emit("update:scrollTop", nextTop);
|
|
1354
|
+
emit("scroll", nextTop);
|
|
1355
|
+
return true;
|
|
1356
|
+
}
|
|
1357
|
+
const before = internalScrollTop.value;
|
|
1358
|
+
setScrollTop(before + n, true, { remapSelectionFocus: true });
|
|
1359
|
+
return internalScrollTop.value !== before;
|
|
1360
|
+
}
|
|
1361
|
+
function selectionPointForCell(point) {
|
|
1362
|
+
const r = normalizedRect();
|
|
1363
|
+
if (point.x < r.x || point.y < r.y || point.x >= r.x + r.w || point.y >= r.y + r.h) return null;
|
|
1364
|
+
const { x: clipX, y: clipY } = clipOffsets();
|
|
1365
|
+
const visualY = internalScrollTop.value + clipY + (point.y - r.y);
|
|
1366
|
+
if (visualY < 0 || visualY >= rows.value.length) return null;
|
|
1367
|
+
return {
|
|
1368
|
+
x: clamp(clipX + (point.x - r.x), 0, Math.max(0, props.w - 1)),
|
|
1369
|
+
y: visualY
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
function canHandleSelectionRange(range) {
|
|
1373
|
+
return Boolean(selectionPointForCell(range.anchor) && selectionPointForCell(range.focus));
|
|
1374
|
+
}
|
|
1375
|
+
function textForSelectionRange(range) {
|
|
1376
|
+
const cols = Math.max(1, Math.floor(props.w));
|
|
1377
|
+
return terminalSelectionRowSpans(range, cols, rows.value.length).map((span) => {
|
|
1378
|
+
const text = sliceByCellsRange(rows.value[span.y]?.plainText ?? "", span.x0, span.x1);
|
|
1379
|
+
return span.x1 >= cols ? text.trimEnd() : text;
|
|
1380
|
+
}).join("\n");
|
|
1381
|
+
}
|
|
1382
|
+
function visibleSpansForSelectionRange(providerRange, _screenRange) {
|
|
1383
|
+
const r = normalizedRect();
|
|
1384
|
+
const { x: clipX, y: clipY } = clipOffsets();
|
|
1385
|
+
const cols = Math.max(1, Math.floor(props.w));
|
|
1386
|
+
const top = internalScrollTop.value + clipY;
|
|
1387
|
+
const bottom = top + r.h;
|
|
1388
|
+
const providerSpans = terminalSelectionVisibleRowSpans(providerRange, cols, rows.value.length, top, bottom);
|
|
1389
|
+
const result = [];
|
|
1390
|
+
for (const span of providerSpans) {
|
|
1391
|
+
const screenY = r.y + (span.y - top);
|
|
1392
|
+
const screenX0 = r.x + span.x0 - clipX;
|
|
1393
|
+
const screenX1 = r.x + span.x1 - clipX;
|
|
1394
|
+
const x0 = Math.max(r.x, screenX0);
|
|
1395
|
+
const x1 = Math.min(r.x + r.w, screenX1);
|
|
1396
|
+
if (screenY >= r.y && screenY < r.y + r.h && x1 > x0) result.push({
|
|
1397
|
+
y: screenY,
|
|
1398
|
+
x0,
|
|
1399
|
+
x1
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
return result;
|
|
1403
|
+
}
|
|
1348
1404
|
function onKeydown(event) {
|
|
1349
1405
|
emit("keydown", event);
|
|
1350
1406
|
const page = Math.max(1, normalizedRect().h);
|
|
@@ -1378,22 +1434,34 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1378
1434
|
setScrollTop(maxScrollTop());
|
|
1379
1435
|
}
|
|
1380
1436
|
}
|
|
1437
|
+
const selectionTextProvider = {
|
|
1438
|
+
id: `TVirtualMarkdown:${instance?.uid ?? "unknown"}:selection-text`,
|
|
1439
|
+
get rect() {
|
|
1440
|
+
return normalizedRect();
|
|
1441
|
+
},
|
|
1442
|
+
canHandle: canHandleSelectionRange,
|
|
1443
|
+
pointForCell: selectionPointForCell,
|
|
1444
|
+
getText: textForSelectionRange,
|
|
1445
|
+
getVisibleSpans: visibleSpansForSelectionRange
|
|
1446
|
+
};
|
|
1447
|
+
const unregisterSelectionTextProvider = selection.registerTextProvider(selectionTextProvider);
|
|
1448
|
+
onBeforeUnmount(unregisterSelectionTextProvider);
|
|
1381
1449
|
const eventNode = useTerminalNode(() => ({
|
|
1382
1450
|
rect: normalizedRect(),
|
|
1383
1451
|
zIndex: eventZ.value,
|
|
1384
1452
|
visible: visible.value,
|
|
1385
1453
|
focusable: true,
|
|
1386
1454
|
selectable: props.selectable,
|
|
1455
|
+
selectionScrollBy: scrollSelectionBy,
|
|
1387
1456
|
handlers: {
|
|
1388
1457
|
click: (_event) => {},
|
|
1389
1458
|
wheel: (event) => {
|
|
1390
|
-
var _event$preventDefault;
|
|
1391
1459
|
const { deltaY, mode } = getWheelScrollInput(event);
|
|
1392
1460
|
if (!deltaY) return;
|
|
1393
1461
|
const now = typeof event.time === "number" ? event.time : typeof event.timeStamp === "number" ? event.timeStamp : Date.now();
|
|
1394
1462
|
const { nextTop, dir } = applyWheelScroll(wheelState, deltaY, internalScrollTop.value, maxScrollTop(), now, mode, { disableAcceleration: mode === "pixel" });
|
|
1395
1463
|
if (!dir || nextTop === internalScrollTop.value) return;
|
|
1396
|
-
|
|
1464
|
+
event.preventDefault?.();
|
|
1397
1465
|
setScrollTop(nextTop);
|
|
1398
1466
|
},
|
|
1399
1467
|
focus: () => {
|
|
@@ -1453,7 +1521,7 @@ const TVirtualMarkdown = defineComponent({
|
|
|
1453
1521
|
clear: true
|
|
1454
1522
|
});
|
|
1455
1523
|
};
|
|
1456
|
-
if (dirtyRows
|
|
1524
|
+
if (dirtyRows?.length) {
|
|
1457
1525
|
for (const y of dirtyRows) paintRow(y);
|
|
1458
1526
|
return;
|
|
1459
1527
|
}
|
|
@@ -1513,11 +1581,11 @@ function mergeGroups(groups) {
|
|
|
1513
1581
|
return out;
|
|
1514
1582
|
}
|
|
1515
1583
|
function createMarkdownBlockSource(options) {
|
|
1516
|
-
const parser =
|
|
1584
|
+
const parser = options?.parser ?? createTuiMarkdownParser({
|
|
1517
1585
|
streaming: true,
|
|
1518
|
-
customHtmlTags: options
|
|
1586
|
+
customHtmlTags: options?.customHtmlTags
|
|
1519
1587
|
});
|
|
1520
|
-
const theme = options
|
|
1588
|
+
const theme = options?.theme;
|
|
1521
1589
|
const finalizedGroups = [];
|
|
1522
1590
|
let tailText = "";
|
|
1523
1591
|
let nextGroupIndex = 0;
|