stream-monaco 0.0.14 → 0.0.16
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 +41 -0
- package/README.zh-CN.md +33 -1
- package/dist/index.base-BaAqAXUs.d.ts +288 -0
- package/dist/index.base-D0jPJkA_.d.cts +289 -0
- package/dist/index.cjs +13 -2776
- package/dist/index.d.cts +1 -275
- package/dist/index.d.ts +1 -274
- package/dist/index.js +6 -2741
- package/dist/index.legacy.cjs +34 -0
- package/dist/index.legacy.d.cts +6 -0
- package/dist/index.legacy.d.ts +6 -0
- package/dist/index.legacy.js +27 -0
- package/dist/preloadMonacoWorkers.shared-C62vOlc9.js +2791 -0
- package/dist/preloadMonacoWorkers.shared-gUKedCzF.cjs +2878 -0
- package/legacy.cjs +1 -0
- package/legacy.d.cts +1 -0
- package/legacy.d.ts +1 -0
- package/legacy.js +1 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -80,6 +80,13 @@ The `useMonaco()` function returns an object with the following methods:
|
|
|
80
80
|
- **`setUpdateThrottleMs(ms)`** - Change update throttle at runtime
|
|
81
81
|
- **`getUpdateThrottleMs()`** - Get current throttle value
|
|
82
82
|
|
|
83
|
+
#### Diff streaming highlight tip
|
|
84
|
+
|
|
85
|
+
Monaco's diff computation is async and cancels/restarts when models change. If you stream updates too frequently (e.g. per token / every frame), the diff may only finish once streaming stops, so the difference highlights appear "at the end".
|
|
86
|
+
|
|
87
|
+
- Set `diffUpdateThrottleMs` (default: 50) to let the diff worker complete intermediate computations during streaming.
|
|
88
|
+
- Set it to `0` to restore pure RAF batching (most responsive, but may delay diff highlights under heavy streaming).
|
|
89
|
+
|
|
83
90
|
### Install
|
|
84
91
|
|
|
85
92
|
```bash
|
|
@@ -477,6 +484,40 @@ cleanupEditor()
|
|
|
477
484
|
- Theme not applied: ensure theme name is included in `themes`.
|
|
478
485
|
- Language highlighting missing: ensure the language is included and supported by Shiki.
|
|
479
486
|
|
|
487
|
+
#### Vue CLI 4 (Webpack 4)
|
|
488
|
+
|
|
489
|
+
Webpack 4 cannot parse `import.meta.url`. Use the `stream-monaco/legacy` entry (no `import.meta`) and configure Monaco workers in your app.
|
|
490
|
+
|
|
491
|
+
Recommended: use `monaco-editor-webpack-plugin`.
|
|
492
|
+
|
|
493
|
+
```bash
|
|
494
|
+
pnpm add -D monaco-editor-webpack-plugin
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
`vue.config.js`:
|
|
498
|
+
|
|
499
|
+
```js
|
|
500
|
+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
|
|
501
|
+
|
|
502
|
+
module.exports = {
|
|
503
|
+
configureWebpack: {
|
|
504
|
+
plugins: [
|
|
505
|
+
new MonacoWebpackPlugin({
|
|
506
|
+
languages: ['json', 'css', 'html', 'typescript'],
|
|
507
|
+
}),
|
|
508
|
+
],
|
|
509
|
+
},
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
And call once early (e.g. `main.ts`):
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
import { preloadMonacoWorkers } from 'stream-monaco/legacy'
|
|
517
|
+
|
|
518
|
+
preloadMonacoWorkers()
|
|
519
|
+
```
|
|
520
|
+
|
|
480
521
|
### Development
|
|
481
522
|
|
|
482
523
|
```bash
|
package/README.zh-CN.md
CHANGED
|
@@ -718,7 +718,39 @@ onUnmounted(() => {
|
|
|
718
718
|
|
|
719
719
|
#### 1. 打包后编辑器无法显示
|
|
720
720
|
|
|
721
|
-
确保正确配置了 Monaco Editor 的 Web Workers
|
|
721
|
+
确保正确配置了 Monaco Editor 的 Web Workers。
|
|
722
|
+
|
|
723
|
+
**Vue CLI 4(Webpack 4)注意:** Webpack 4 无法解析 `import.meta.url`。请改用 `stream-monaco/legacy` 入口(不包含 `import.meta`),并在项目侧配置 Monaco workers。
|
|
724
|
+
|
|
725
|
+
推荐使用 `monaco-editor-webpack-plugin` 来处理 Monaco workers:
|
|
726
|
+
|
|
727
|
+
```bash
|
|
728
|
+
pnpm add -D monaco-editor-webpack-plugin
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
`vue.config.js`:
|
|
732
|
+
|
|
733
|
+
```js
|
|
734
|
+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
|
|
735
|
+
|
|
736
|
+
module.exports = {
|
|
737
|
+
configureWebpack: {
|
|
738
|
+
plugins: [
|
|
739
|
+
new MonacoWebpackPlugin({
|
|
740
|
+
languages: ['json', 'css', 'html', 'typescript'],
|
|
741
|
+
}),
|
|
742
|
+
],
|
|
743
|
+
},
|
|
744
|
+
}
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
并尽早调用一次(例如 `main.ts`):
|
|
748
|
+
|
|
749
|
+
```ts
|
|
750
|
+
import { preloadMonacoWorkers } from 'stream-monaco/legacy'
|
|
751
|
+
|
|
752
|
+
preloadMonacoWorkers()
|
|
753
|
+
```
|
|
722
754
|
|
|
723
755
|
#### 2. Diff 编辑器流式更新时内容区空白
|
|
724
756
|
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { __export, __reExport } from "./chunk-CHLpw0oG.js";
|
|
2
|
+
import * as monaco_editor0 from "monaco-editor";
|
|
3
|
+
import * as monaco$1 from "monaco-editor";
|
|
4
|
+
import * as _monaco from "monaco-editor";
|
|
5
|
+
import { Highlighter, SpecialTheme, ThemeInput } from "shiki";
|
|
6
|
+
|
|
7
|
+
//#region src/type.d.ts
|
|
8
|
+
type ShikiHighlighter = Highlighter | any;
|
|
9
|
+
type MonacoEditorInstance = monaco$1.editor.IStandaloneCodeEditor;
|
|
10
|
+
type MonacoDiffEditorInstance = monaco$1.editor.IStandaloneDiffEditor;
|
|
11
|
+
type MonacoTheme = 'andromeeda' | 'aurora-x' | 'ayu-dark' | 'catppuccin-frappe' | 'catppuccin-latte' | 'catppuccin-macchiato' | 'catppuccin-mocha' | 'dark-plus' | 'dracula' | 'dracula-soft' | 'everforest-dark' | 'everforest-light' | 'github-dark' | 'github-dark-default' | 'github-dark-dimmed' | 'github-dark-high-contrast' | 'github-light' | 'github-light-default' | 'github-light-high-contrast' | 'gruvbox-dark-hard' | 'gruvbox-dark-medium' | 'gruvbox-dark-soft' | 'gruvbox-light-hard' | 'gruvbox-light-medium' | 'gruvbox-light-soft' | 'houston' | 'kanagawa-dragon' | 'kanagawa-lotus' | 'kanagawa-wave' | 'laserwave' | 'light-plus' | 'material-theme' | 'material-theme-darker' | 'material-theme-lighter' | 'material-theme-ocean' | 'material-theme-palenight' | 'min-dark' | 'min-light' | 'monokai' | 'night-owl' | 'nord' | 'one-dark-pro' | 'one-light' | 'plastic' | 'poimandres' | 'red' | 'rose-pine' | 'rose-pine-dawn' | 'rose-pine-moon' | 'slack-dark' | 'slack-ochin' | 'snazzy-light' | 'solarized-dark' | 'solarized-light' | 'synthwave-84' | 'tokyo-night' | 'vesper' | 'vitesse-black' | 'vitesse-dark' | 'vitesse-light' | ThemeInput | string | SpecialTheme;
|
|
12
|
+
type MonacoLanguage = 'abap' | 'actionscript-3' | 'ada' | 'angular-html' | 'angular-ts' | 'apache' | 'apex' | 'apl' | 'applescript' | 'ara' | 'asciidoc' | 'asm' | 'astro' | 'awk' | 'ballerina' | 'bat' | 'beancount' | 'berry' | 'bibtex' | 'bicep' | 'blade' | 'bsl' | 'c' | 'cadence' | 'cairo' | 'clarity' | 'clojure' | 'cmake' | 'cobol' | 'codeowners' | 'codeql' | 'coffee' | 'common-lisp' | 'coq' | 'cpp' | 'crystal' | 'csharp' | 'css' | 'csv' | 'cue' | 'cypher' | 'd' | 'dart' | 'dax' | 'desktop' | 'diff' | 'docker' | 'dotenv' | 'dream-maker' | 'edge' | 'elixir' | 'elm' | 'emacs-lisp' | 'erb' | 'erlang' | 'fennel' | 'fish' | 'fluent' | 'fortran-fixed-form' | 'fortran-free-form' | 'fsharp' | 'gdresource' | 'gdscript' | 'gdshader' | 'genie' | 'gherkin' | 'git-commit' | 'git-rebase' | 'gleam' | 'glimmer-js' | 'glimmer-ts' | 'glsl' | 'gnuplot' | 'go' | 'graphql' | 'groovy' | 'hack' | 'haml' | 'handlebars' | 'haskell' | 'haxe' | 'hcl' | 'hjson' | 'hlsl' | 'html' | 'html-derivative' | 'http' | 'hxml' | 'hy' | 'imba' | 'ini' | 'java' | 'javascript' | 'jinja' | 'jison' | 'json' | 'json5' | 'jsonc' | 'jsonl' | 'jsonnet' | 'jssm' | 'jsx' | 'julia' | 'kotlin' | 'kusto' | 'latex' | 'lean' | 'less' | 'liquid' | 'llvm' | 'log' | 'logo' | 'lua' | 'luau' | 'make' | 'markdown' | 'marko' | 'matlab' | 'mdc' | 'mdx' | 'mermaid' | 'mipsasm' | 'mojo' | 'move' | 'narrat' | 'nextflow' | 'nginx' | 'nim' | 'nix' | 'nushell' | 'objective-c' | 'objective-cpp' | 'ocaml' | 'pascal' | 'perl' | 'php' | 'plsql' | 'po' | 'polar' | 'postcss' | 'powerquery' | 'powershell' | 'prisma' | 'prolog' | 'proto' | 'pug' | 'puppet' | 'purescript' | 'python' | 'qml' | 'qmldir' | 'qss' | 'r' | 'racket' | 'raku' | 'razor' | 'reg' | 'regexp' | 'rel' | 'riscv' | 'rst' | 'ruby' | 'rust' | 'sas' | 'sass' | 'scala' | 'scheme' | 'scss' | 'sdbl' | 'shaderlab' | 'shellscript' | 'shellsession' | 'smalltalk' | 'solidity' | 'soy' | 'sparql' | 'splunk' | 'sql' | 'ssh-config' | 'stata' | 'stylus' | 'svelte' | 'swift' | 'system-verilog' | 'systemd' | 'talonscript' | 'tasl' | 'tcl' | 'templ' | 'terraform' | 'tex' | 'toml' | 'ts-tags' | 'tsv' | 'tsx' | 'turtle' | 'twig' | 'typescript' | 'typespec' | 'typst' | 'v' | 'vala' | 'vb' | 'verilog' | 'vhdl' | 'viml' | 'vue' | 'vue-html' | 'vyper' | 'wasm' | 'wenyan' | 'wgsl' | 'wikitext' | 'wit' | 'wolfram' | 'xml' | 'xsl' | 'yaml' | 'zenscript' | 'zig' | string;
|
|
13
|
+
interface MonacoOptions extends monaco$1.editor.IStandaloneEditorConstructionOptions {
|
|
14
|
+
MAX_HEIGHT?: number | string;
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
themes?: MonacoTheme[];
|
|
17
|
+
languages?: MonacoLanguage[];
|
|
18
|
+
theme?: string;
|
|
19
|
+
isCleanOnBeforeCreate?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 控制更新时的自动滚动行为:当为 true 时,如果当前接近底部则在新增内容后自动滚动到底部;
|
|
22
|
+
* 当为 false 时,将完全禁用自动滚动。
|
|
23
|
+
* 默认 true。
|
|
24
|
+
*/
|
|
25
|
+
autoScrollOnUpdate?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 编辑器创建时是否默认启用自动滚动。用户一旦滚离底部将自动暂停,回到底部附近再恢复。
|
|
28
|
+
* 默认 true(保持原有行为)。
|
|
29
|
+
*/
|
|
30
|
+
autoScrollInitial?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 触发“接近底部”的绝对像素阈值。如果设置,将与 autoScrollThresholdLines 共同取最大值。
|
|
33
|
+
* 默认 32。
|
|
34
|
+
*/
|
|
35
|
+
autoScrollThresholdPx?: number;
|
|
36
|
+
/**
|
|
37
|
+
* 触发“接近底部”的相对行数阈值(以当前行高计算)。如果设置,将与 autoScrollThresholdPx 共同取最大值。
|
|
38
|
+
* 默认 2 行。
|
|
39
|
+
*/
|
|
40
|
+
autoScrollThresholdLines?: number;
|
|
41
|
+
/**
|
|
42
|
+
* 是否启用 Diff 编辑器 modified 侧的自动滚动逻辑。
|
|
43
|
+
* 当为 false 时,updateDiff/appendModified 等不会触发自动滚动。
|
|
44
|
+
* 默认 true(与单编辑器体验保持一致)。
|
|
45
|
+
*/
|
|
46
|
+
diffAutoScroll?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Debounce time (ms) to coalesce multiple reveal requests into a single
|
|
49
|
+
* reveal. Useful for streaming/append scenarios. Default: 75
|
|
50
|
+
*/
|
|
51
|
+
revealDebounceMs?: number;
|
|
52
|
+
/**
|
|
53
|
+
* How to reveal target line when auto-scrolling.
|
|
54
|
+
* - 'bottom' : revealLine (closest to bottom)
|
|
55
|
+
* - 'centerIfOutside' : revealLineInCenterIfOutsideViewport (default)
|
|
56
|
+
* - 'center' : revealLineInCenter
|
|
57
|
+
*/
|
|
58
|
+
revealStrategy?: 'bottom' | 'centerIfOutside' | 'center';
|
|
59
|
+
/**
|
|
60
|
+
* If set to a positive number (ms), append/streaming scenarios will delay a final
|
|
61
|
+
* "scroll to bottom" until this idle time has passed since the last append. Useful
|
|
62
|
+
* to batch many small appends and then perform one final jump to bottom. Default: undefined (disabled).
|
|
63
|
+
*/
|
|
64
|
+
revealBatchOnIdleMs?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Time window (ms) used to throttle `updateCode` calls in addition to RAF batching.
|
|
67
|
+
* - 0 means only RAF-based coalescing (no extra time throttling).
|
|
68
|
+
* - Default (library): 50
|
|
69
|
+
*/
|
|
70
|
+
updateThrottleMs?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Time window (ms) used to throttle diff streaming updates in addition to RAF batching.
|
|
73
|
+
* This affects `appendOriginal`/`appendModified` and the fast-path append branches of `updateDiff`.
|
|
74
|
+
*
|
|
75
|
+
* Why: Monaco's diff computation is async and cancels/restarts when models change.
|
|
76
|
+
* If you apply edits every frame (or per token), the diff may only finish once
|
|
77
|
+
* streaming stops, so the highlights appear "at the end".
|
|
78
|
+
*
|
|
79
|
+
* - 0 means only RAF-based coalescing (more responsive, but can starve diff computation).
|
|
80
|
+
* - Default (library): 50
|
|
81
|
+
*/
|
|
82
|
+
diffUpdateThrottleMs?: number;
|
|
83
|
+
/**
|
|
84
|
+
* When attempting the "minimal edit" algorithm, if prev.length + next.length
|
|
85
|
+
* exceeds this number the library will fall back to full `setValue` to avoid
|
|
86
|
+
* expensive diff computation on very large documents.
|
|
87
|
+
*/
|
|
88
|
+
minimalEditMaxChars?: number;
|
|
89
|
+
/**
|
|
90
|
+
* When the relative change ratio (|new-prev|/maxLen) exceeds this value the
|
|
91
|
+
* library will fall back to full `setValue` instead of attempting minimal edit.
|
|
92
|
+
*/
|
|
93
|
+
minimalEditMaxChangeRatio?: number;
|
|
94
|
+
onBeforeCreate?: (monaco: typeof monaco_editor0) => monaco$1.IDisposable[];
|
|
95
|
+
/**
|
|
96
|
+
* Optional callback that is invoked after a theme change has been applied.
|
|
97
|
+
* This callback will be awaited when possible so callers can track completion
|
|
98
|
+
* of theme application. It receives the name of the applied theme.
|
|
99
|
+
*/
|
|
100
|
+
onThemeChange?: (theme: MonacoTheme) => void | Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
declare enum RevealStrategy {
|
|
103
|
+
Bottom = "bottom",
|
|
104
|
+
CenterIfOutside = "centerIfOutside",
|
|
105
|
+
Center = "center",
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/code.detect.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* @module detect
|
|
111
|
+
* (Language detector)
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Supported language identifiers
|
|
115
|
+
*/
|
|
116
|
+
type CodeLanguage = 'bash' | 'html' | 'http' | 'js' | 'ts' | 'py' | 'sql' | 'pl' | 'lua' | 'make' | 'uri' | 'css' | 'diff' | 'md' | 'docker' | 'xml' | 'c' | 'rs' | 'go' | 'java' | 'asm' | 'json' | 'yaml' | 'toml' | 'mermaid' | 'plain';
|
|
117
|
+
/**
|
|
118
|
+
* Language detection feature with pattern and score
|
|
119
|
+
*/
|
|
120
|
+
type LanguageFeature = [RegExp, number];
|
|
121
|
+
/**
|
|
122
|
+
* Language definition with identifier and detection features
|
|
123
|
+
*/
|
|
124
|
+
type LanguageDefinition = [CodeLanguage, ...LanguageFeature[]];
|
|
125
|
+
/**
|
|
126
|
+
* Language detection definitions
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Try to find the language the given code belongs to
|
|
131
|
+
*
|
|
132
|
+
* @param {string} code The code to analyze
|
|
133
|
+
* @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
|
|
134
|
+
* @returns {CodeLanguage} The detected language of the code
|
|
135
|
+
*/
|
|
136
|
+
declare function detectLanguage(code: string, additionalLanguages?: LanguageDefinition[]): CodeLanguage;
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/constant.d.ts
|
|
139
|
+
declare const defaultRevealDebounceMs = 75;
|
|
140
|
+
declare namespace monaco_shim_d_exports {
|
|
141
|
+
export { monaco as default };
|
|
142
|
+
}
|
|
143
|
+
import * as import_monaco_editor from "monaco-editor";
|
|
144
|
+
__reExport(monaco_shim_d_exports, import_monaco_editor);
|
|
145
|
+
declare const monaco: typeof _monaco;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/utils/registerMonacoThemes.d.ts
|
|
148
|
+
/**
|
|
149
|
+
* Clear all cached shiki highlighters.
|
|
150
|
+
*
|
|
151
|
+
* Useful for long-running apps that dynamically create many theme combinations,
|
|
152
|
+
* or in tests to ensure a clean state. Call this when you know the highlighters
|
|
153
|
+
* are no longer needed (for example on app shutdown) to free memory.
|
|
154
|
+
*/
|
|
155
|
+
declare function clearHighlighterCache(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Return number of entries currently in the highlighter cache.
|
|
158
|
+
* Helpful for tests and debugging.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
declare function getOrCreateHighlighter(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter>;
|
|
162
|
+
/**
|
|
163
|
+
* Update the theme used by the shiki highlighter for a given themes+languages
|
|
164
|
+
* combination. Useful when Monaco themes are already registered (so switching
|
|
165
|
+
* Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
|
|
166
|
+
* standalone renderer to use the new theme without recreating everything.
|
|
167
|
+
*/
|
|
168
|
+
declare function registerMonacoThemes(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter | null>;
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/index.base.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* useMonaco 组合式函数
|
|
173
|
+
*
|
|
174
|
+
* 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
|
|
175
|
+
* 支持主题自动切换、语言高亮、代码更新等功能。
|
|
176
|
+
*
|
|
177
|
+
* @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
|
|
178
|
+
* @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
|
|
179
|
+
* @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
|
|
180
|
+
* @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
|
|
181
|
+
* @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
|
|
182
|
+
* @param {string} [monacoOptions.theme] - 初始主题名称
|
|
183
|
+
* @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
|
|
184
|
+
* @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
|
|
185
|
+
*
|
|
186
|
+
* @returns {{
|
|
187
|
+
* createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
|
|
188
|
+
* createDiffEditor: (
|
|
189
|
+
* container: HTMLElement,
|
|
190
|
+
* originalCode: string,
|
|
191
|
+
* modifiedCode: string,
|
|
192
|
+
* language: string,
|
|
193
|
+
* ) => Promise<monaco.editor.IStandaloneDiffEditor>,
|
|
194
|
+
* cleanupEditor: () => void,
|
|
195
|
+
* updateCode: (newCode: string, codeLanguage: string) => void,
|
|
196
|
+
* appendCode: (appendText: string, codeLanguage?: string) => void,
|
|
197
|
+
* updateDiff: (
|
|
198
|
+
* originalCode: string,
|
|
199
|
+
* modifiedCode: string,
|
|
200
|
+
* codeLanguage?: string,
|
|
201
|
+
* ) => void,
|
|
202
|
+
* updateOriginal: (newCode: string, codeLanguage?: string) => void,
|
|
203
|
+
* updateModified: (newCode: string, codeLanguage?: string) => void,
|
|
204
|
+
* appendOriginal: (appendText: string, codeLanguage?: string) => void,
|
|
205
|
+
* appendModified: (appendText: string, codeLanguage?: string) => void,
|
|
206
|
+
* setTheme: (theme: MonacoTheme) => Promise<void>,
|
|
207
|
+
* setLanguage: (language: MonacoLanguage) => void,
|
|
208
|
+
* getCurrentTheme: () => string,
|
|
209
|
+
* getEditor: () => typeof monaco.editor,
|
|
210
|
+
* getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
|
|
211
|
+
* getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
|
|
212
|
+
* getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
|
|
213
|
+
* getCode: () => string | { original: string, modified: string } | null,
|
|
214
|
+
* }} 返回对象包含以下方法和属性:
|
|
215
|
+
*
|
|
216
|
+
* @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
|
|
217
|
+
* @property {Function} cleanupEditor - 销毁编辑器并清理容器
|
|
218
|
+
* @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
|
|
219
|
+
* @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
|
|
220
|
+
* @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
|
|
221
|
+
* @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
|
|
222
|
+
* @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
|
|
223
|
+
* @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
|
|
224
|
+
* @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
|
|
225
|
+
* @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
|
|
226
|
+
* @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
|
|
227
|
+
* @property {Function} setLanguage - 切换编辑器语言
|
|
228
|
+
* @property {Function} getCurrentTheme - 获取当前主题名称
|
|
229
|
+
* @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
|
|
230
|
+
* @property {Function} getEditorView - 获取当前编辑器实例
|
|
231
|
+
* @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
|
|
232
|
+
* @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
|
|
233
|
+
* @property {Function} getCode - 获取当前编辑器或 Diff 编辑器中的代码内容
|
|
234
|
+
*
|
|
235
|
+
* @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* import { useMonaco } from 'stream-monaco'
|
|
240
|
+
*
|
|
241
|
+
* const { createEditor, updateCode, setTheme } = useMonaco({
|
|
242
|
+
* themes: ['vitesse-dark', 'vitesse-light'],
|
|
243
|
+
* languages: ['javascript', 'typescript'],
|
|
244
|
+
* readOnly: false
|
|
245
|
+
* })
|
|
246
|
+
*
|
|
247
|
+
* // 创建编辑器
|
|
248
|
+
* const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
|
|
249
|
+
*
|
|
250
|
+
* // 更新代码
|
|
251
|
+
* updateCode('console.log("world")', 'javascript')
|
|
252
|
+
*
|
|
253
|
+
* // 切换主题
|
|
254
|
+
* setTheme('vitesse-light')
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function useMonaco(monacoOptions?: MonacoOptions): {
|
|
258
|
+
createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneCodeEditor>;
|
|
259
|
+
createDiffEditor: (container: HTMLElement, originalCode: string, modifiedCode: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneDiffEditor>;
|
|
260
|
+
cleanupEditor: () => void;
|
|
261
|
+
safeClean(): void;
|
|
262
|
+
updateCode: (newCode: string, codeLanguage: string) => void;
|
|
263
|
+
appendCode: (appendText: string, codeLanguage?: string) => void;
|
|
264
|
+
updateDiff: (originalCode: string, modifiedCode: string, codeLanguage?: string) => void;
|
|
265
|
+
updateOriginal: (newCode: string, codeLanguage?: string) => void;
|
|
266
|
+
updateModified: (newCode: string, codeLanguage?: string) => void;
|
|
267
|
+
appendOriginal: (appendText: string, codeLanguage?: string) => void;
|
|
268
|
+
appendModified: (appendText: string, codeLanguage?: string) => void;
|
|
269
|
+
setTheme: (theme: MonacoTheme, force?: boolean) => Promise<void>;
|
|
270
|
+
setLanguage(language: MonacoLanguage): void;
|
|
271
|
+
getCurrentTheme(): string;
|
|
272
|
+
getEditor(): typeof monaco_shim_d_exports.editor;
|
|
273
|
+
getEditorView(): monaco_shim_d_exports.editor.IStandaloneCodeEditor | null;
|
|
274
|
+
getDiffEditorView(): monaco_shim_d_exports.editor.IStandaloneDiffEditor | null;
|
|
275
|
+
getDiffModels(): {
|
|
276
|
+
original: monaco_shim_d_exports.editor.ITextModel | null;
|
|
277
|
+
modified: monaco_shim_d_exports.editor.ITextModel | null;
|
|
278
|
+
};
|
|
279
|
+
getMonacoInstance(): typeof monaco_shim_d_exports;
|
|
280
|
+
setUpdateThrottleMs: (ms: number) => void;
|
|
281
|
+
getUpdateThrottleMs: () => number;
|
|
282
|
+
getCode(): string | {
|
|
283
|
+
original: string;
|
|
284
|
+
modified: string;
|
|
285
|
+
} | null;
|
|
286
|
+
};
|
|
287
|
+
//#endregion
|
|
288
|
+
export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, registerMonacoThemes, useMonaco };
|