stream-monaco 0.0.8 → 0.0.10
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/dist/index.cjs +43 -24
- package/dist/index.js +43 -24
- package/package.json +15 -17
package/dist/index.cjs
CHANGED
|
@@ -1998,6 +1998,12 @@ let languagesRegistered = false;
|
|
|
1998
1998
|
let currentThemes = [];
|
|
1999
1999
|
let currentLanguages = [];
|
|
2000
2000
|
let themeRegisterPromise = null;
|
|
2001
|
+
let registrationQueue = Promise.resolve();
|
|
2002
|
+
function enqueueRegistration(task) {
|
|
2003
|
+
const next = registrationQueue.then(task, task);
|
|
2004
|
+
registrationQueue = next.then(() => void 0, () => void 0);
|
|
2005
|
+
return next;
|
|
2006
|
+
}
|
|
2001
2007
|
function setThemeRegisterPromise(p) {
|
|
2002
2008
|
return themeRegisterPromise = p;
|
|
2003
2009
|
}
|
|
@@ -2074,27 +2080,29 @@ async function getOrCreateHighlighter(themes, languages$1) {
|
|
|
2074
2080
|
* standalone renderer to use the new theme without recreating everything.
|
|
2075
2081
|
*/
|
|
2076
2082
|
async function registerMonacoThemes(themes, languages$1) {
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
const
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2083
|
+
return enqueueRegistration(async () => {
|
|
2084
|
+
registerMonacoLanguages(languages$1);
|
|
2085
|
+
if (themesRegistered && arraysEqual(themes, currentThemes) && arraysEqual(languages$1, currentLanguages)) {
|
|
2086
|
+
const existing = highlighterCache.get(serializeThemes(themes));
|
|
2087
|
+
return existing ? existing.promise : Promise.resolve(null);
|
|
2088
|
+
}
|
|
2089
|
+
const p = (async () => {
|
|
2090
|
+
const highlighter = await getOrCreateHighlighter(themes, languages$1);
|
|
2091
|
+
(0, __shikijs_monaco.shikiToMonaco)(highlighter, monaco_shim_exports);
|
|
2092
|
+
themesRegistered = true;
|
|
2093
|
+
currentThemes = themes.slice();
|
|
2094
|
+
currentLanguages = languages$1.slice();
|
|
2095
|
+
return highlighter;
|
|
2096
|
+
})();
|
|
2097
|
+
setThemeRegisterPromise(p);
|
|
2098
|
+
try {
|
|
2099
|
+
const res = await p;
|
|
2100
|
+
return res;
|
|
2101
|
+
} catch (e) {
|
|
2102
|
+
setThemeRegisterPromise(null);
|
|
2103
|
+
throw e;
|
|
2104
|
+
}
|
|
2105
|
+
});
|
|
2098
2106
|
}
|
|
2099
2107
|
function registerMonacoLanguages(languages$1) {
|
|
2100
2108
|
if (languagesRegistered && arraysEqual(languages$1, currentLanguages)) return;
|
|
@@ -2287,6 +2295,12 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2287
2295
|
console.warn("onThemeChange callback threw an error:", err);
|
|
2288
2296
|
}
|
|
2289
2297
|
}
|
|
2298
|
+
async function ensureThemeRegistered(themeName) {
|
|
2299
|
+
const availableNames = themes.map((t) => typeof t === "string" ? t : t.name);
|
|
2300
|
+
const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
|
|
2301
|
+
const p = setThemeRegisterPromise(registerMonacoThemes(list, languages$1));
|
|
2302
|
+
if (p) await p;
|
|
2303
|
+
}
|
|
2290
2304
|
function hasVerticalScrollbar() {
|
|
2291
2305
|
if (!editorView) return false;
|
|
2292
2306
|
if (_hasScrollBar) return true;
|
|
@@ -2327,11 +2341,16 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2327
2341
|
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
2328
2342
|
if (ds) disposals.push(...ds);
|
|
2329
2343
|
}
|
|
2330
|
-
await setThemeRegisterPromise(registerMonacoThemes(themes, languages$1));
|
|
2331
2344
|
const initialThemeName = monacoOptions.theme ?? currentTheme.value;
|
|
2332
|
-
|
|
2345
|
+
await ensureThemeRegistered(initialThemeName);
|
|
2333
2346
|
editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs);
|
|
2334
2347
|
editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
|
|
2348
|
+
lastAppliedTheme = initialThemeName;
|
|
2349
|
+
if (pendingUpdate && editorMgr) {
|
|
2350
|
+
const { code: queuedCode, lang: queuedLang } = pendingUpdate;
|
|
2351
|
+
pendingUpdate = null;
|
|
2352
|
+
editorMgr.updateCode(queuedCode, queuedLang);
|
|
2353
|
+
}
|
|
2335
2354
|
if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
|
|
2336
2355
|
if (editorView) lastKnownCode = editorView.getValue();
|
|
2337
2356
|
return editorView;
|
|
@@ -2354,8 +2373,8 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2354
2373
|
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
2355
2374
|
if (ds) disposals.push(...ds);
|
|
2356
2375
|
}
|
|
2357
|
-
await setThemeRegisterPromise(registerMonacoThemes(themes, languages$1));
|
|
2358
2376
|
const initialThemeName = monacoOptions.theme ?? currentTheme.value;
|
|
2377
|
+
await ensureThemeRegistered(initialThemeName);
|
|
2359
2378
|
try {
|
|
2360
2379
|
monaco_shim_exports.editor.setTheme(initialThemeName);
|
|
2361
2380
|
lastAppliedTheme = initialThemeName;
|
package/dist/index.js
CHANGED
|
@@ -1970,6 +1970,12 @@ let languagesRegistered = false;
|
|
|
1970
1970
|
let currentThemes = [];
|
|
1971
1971
|
let currentLanguages = [];
|
|
1972
1972
|
let themeRegisterPromise = null;
|
|
1973
|
+
let registrationQueue = Promise.resolve();
|
|
1974
|
+
function enqueueRegistration(task) {
|
|
1975
|
+
const next = registrationQueue.then(task, task);
|
|
1976
|
+
registrationQueue = next.then(() => void 0, () => void 0);
|
|
1977
|
+
return next;
|
|
1978
|
+
}
|
|
1973
1979
|
function setThemeRegisterPromise(p) {
|
|
1974
1980
|
return themeRegisterPromise = p;
|
|
1975
1981
|
}
|
|
@@ -2046,27 +2052,29 @@ async function getOrCreateHighlighter(themes, languages$1) {
|
|
|
2046
2052
|
* standalone renderer to use the new theme without recreating everything.
|
|
2047
2053
|
*/
|
|
2048
2054
|
async function registerMonacoThemes(themes, languages$1) {
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
const
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2055
|
+
return enqueueRegistration(async () => {
|
|
2056
|
+
registerMonacoLanguages(languages$1);
|
|
2057
|
+
if (themesRegistered && arraysEqual(themes, currentThemes) && arraysEqual(languages$1, currentLanguages)) {
|
|
2058
|
+
const existing = highlighterCache.get(serializeThemes(themes));
|
|
2059
|
+
return existing ? existing.promise : Promise.resolve(null);
|
|
2060
|
+
}
|
|
2061
|
+
const p = (async () => {
|
|
2062
|
+
const highlighter = await getOrCreateHighlighter(themes, languages$1);
|
|
2063
|
+
shikiToMonaco(highlighter, monaco_shim_exports);
|
|
2064
|
+
themesRegistered = true;
|
|
2065
|
+
currentThemes = themes.slice();
|
|
2066
|
+
currentLanguages = languages$1.slice();
|
|
2067
|
+
return highlighter;
|
|
2068
|
+
})();
|
|
2069
|
+
setThemeRegisterPromise(p);
|
|
2070
|
+
try {
|
|
2071
|
+
const res = await p;
|
|
2072
|
+
return res;
|
|
2073
|
+
} catch (e) {
|
|
2074
|
+
setThemeRegisterPromise(null);
|
|
2075
|
+
throw e;
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2070
2078
|
}
|
|
2071
2079
|
function registerMonacoLanguages(languages$1) {
|
|
2072
2080
|
if (languagesRegistered && arraysEqual(languages$1, currentLanguages)) return;
|
|
@@ -2259,6 +2267,12 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2259
2267
|
console.warn("onThemeChange callback threw an error:", err);
|
|
2260
2268
|
}
|
|
2261
2269
|
}
|
|
2270
|
+
async function ensureThemeRegistered(themeName) {
|
|
2271
|
+
const availableNames = themes.map((t) => typeof t === "string" ? t : t.name);
|
|
2272
|
+
const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
|
|
2273
|
+
const p = setThemeRegisterPromise(registerMonacoThemes(list, languages$1));
|
|
2274
|
+
if (p) await p;
|
|
2275
|
+
}
|
|
2262
2276
|
function hasVerticalScrollbar() {
|
|
2263
2277
|
if (!editorView) return false;
|
|
2264
2278
|
if (_hasScrollBar) return true;
|
|
@@ -2299,11 +2313,16 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2299
2313
|
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
2300
2314
|
if (ds) disposals.push(...ds);
|
|
2301
2315
|
}
|
|
2302
|
-
await setThemeRegisterPromise(registerMonacoThemes(themes, languages$1));
|
|
2303
2316
|
const initialThemeName = monacoOptions.theme ?? currentTheme.value;
|
|
2304
|
-
|
|
2317
|
+
await ensureThemeRegistered(initialThemeName);
|
|
2305
2318
|
editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs);
|
|
2306
2319
|
editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
|
|
2320
|
+
lastAppliedTheme = initialThemeName;
|
|
2321
|
+
if (pendingUpdate && editorMgr) {
|
|
2322
|
+
const { code: queuedCode, lang: queuedLang } = pendingUpdate;
|
|
2323
|
+
pendingUpdate = null;
|
|
2324
|
+
editorMgr.updateCode(queuedCode, queuedLang);
|
|
2325
|
+
}
|
|
2307
2326
|
if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
|
|
2308
2327
|
if (editorView) lastKnownCode = editorView.getValue();
|
|
2309
2328
|
return editorView;
|
|
@@ -2326,8 +2345,8 @@ function useMonaco(monacoOptions = {}) {
|
|
|
2326
2345
|
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
2327
2346
|
if (ds) disposals.push(...ds);
|
|
2328
2347
|
}
|
|
2329
|
-
await setThemeRegisterPromise(registerMonacoThemes(themes, languages$1));
|
|
2330
2348
|
const initialThemeName = monacoOptions.theme ?? currentTheme.value;
|
|
2349
|
+
await ensureThemeRegistered(initialThemeName);
|
|
2331
2350
|
try {
|
|
2332
2351
|
monaco_shim_exports.editor.setTheme(initialThemeName);
|
|
2333
2352
|
lastAppliedTheme = initialThemeName;
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-monaco",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"packageManager": "pnpm@10.24.0",
|
|
4
|
+
"version": "0.0.10",
|
|
6
5
|
"description": "A framework-agnostic library for integrating Monaco Editor with Shiki highlighting, optimized for streaming updates.",
|
|
7
6
|
"author": "Simon He",
|
|
8
7
|
"license": "MIT",
|
|
@@ -54,20 +53,6 @@
|
|
|
54
53
|
"files": [
|
|
55
54
|
"dist"
|
|
56
55
|
],
|
|
57
|
-
"scripts": {
|
|
58
|
-
"build": "tsdown",
|
|
59
|
-
"dev": "npm run build -- --watch src",
|
|
60
|
-
"format": "prettier --write --cache .",
|
|
61
|
-
"lint": "eslint . --cache",
|
|
62
|
-
"lint:fix": "pnpm run lint --fix",
|
|
63
|
-
"prepublishOnly": "nr build",
|
|
64
|
-
"release": "bumpp && npm publish",
|
|
65
|
-
"start": "esno src/index.ts",
|
|
66
|
-
"bench": "node scripts/stream-benchmark.mjs",
|
|
67
|
-
"bench:playwright": "node scripts/playwright-bench.mjs",
|
|
68
|
-
"test": "vitest",
|
|
69
|
-
"typecheck": "tsc --noEmit"
|
|
70
|
-
},
|
|
71
56
|
"peerDependencies": {
|
|
72
57
|
"monaco-editor": "^0.52.2"
|
|
73
58
|
},
|
|
@@ -96,5 +81,18 @@
|
|
|
96
81
|
"prettier --write --cache --ignore-unknown"
|
|
97
82
|
],
|
|
98
83
|
"*.{vue,js,ts,jsx,tsx,md,json}": "eslint --fix"
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "tsdown",
|
|
87
|
+
"dev": "npm run build -- --watch src",
|
|
88
|
+
"format": "prettier --write --cache .",
|
|
89
|
+
"lint": "eslint . --cache",
|
|
90
|
+
"lint:fix": "pnpm run lint --fix",
|
|
91
|
+
"release": "bumpp && npm publish",
|
|
92
|
+
"start": "esno src/index.ts",
|
|
93
|
+
"bench": "node scripts/stream-benchmark.mjs",
|
|
94
|
+
"bench:playwright": "node scripts/playwright-bench.mjs",
|
|
95
|
+
"test": "vitest",
|
|
96
|
+
"typecheck": "tsc --noEmit"
|
|
99
97
|
}
|
|
100
|
-
}
|
|
98
|
+
}
|