modern-monaco 0.1.9 → 0.2.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/README.md +2 -4
- package/dist/{cache.js → cache.mjs} +1 -1
- package/dist/{core.js → core.mjs} +15 -38
- package/dist/{editor-core.js → editor-core.mjs} +108795 -88348
- package/dist/editor-worker-main.mjs +5 -0
- package/dist/{editor-worker.js → editor-worker.mjs} +5854 -4779
- package/dist/{index.js → index.mjs} +6 -6
- package/dist/lsp/css/{setup.js → setup.mjs} +19 -12
- package/dist/lsp/css/{worker.js → worker.mjs} +18 -23
- package/dist/lsp/html/{setup.js → setup.mjs} +19 -12
- package/dist/lsp/html/{worker.js → worker.mjs} +18 -23
- package/dist/lsp/json/{setup.js → setup.mjs} +19 -12
- package/dist/lsp/json/{worker.js → worker.mjs} +19 -24
- package/dist/lsp/{language-service.js → language-service.mjs} +7 -7
- package/dist/lsp/typescript/{setup.js → setup.mjs} +22 -15
- package/dist/lsp/typescript/{worker.js → worker.mjs} +22 -26
- package/dist/{shiki.js → shiki.mjs} +5 -2
- package/dist/ssr/{index.js → index.mjs} +4 -4
- package/dist/ssr/{workerd.js → workerd.mjs} +3 -3
- package/dist/{workspace.js → workspace.mjs} +16 -12
- package/package.json +18 -15
- package/types/index.d.ts +1 -1
- package/types/lsp.d.ts +2 -5
- package/types/monaco.d.ts +652 -278
- package/types/workspace.d.ts +5 -1
- /package/dist/lsp/typescript/{libs.js → libs.mjs} +0 -0
- /package/dist/{shiki-wasm.js → shiki-wasm.mjs} +0 -0
- /package/dist/{util.js → util.mjs} +0 -0
|
@@ -1466,14 +1466,15 @@ function getWellformedEdit(textEdit) {
|
|
|
1466
1466
|
|
|
1467
1467
|
// src/lsp/worker-base.ts
|
|
1468
1468
|
var WorkerBase = class {
|
|
1469
|
-
constructor(_ctx, _createLanguageDocument) {
|
|
1469
|
+
constructor(_ctx, _createData, _createLanguageDocument) {
|
|
1470
1470
|
this._ctx = _ctx;
|
|
1471
|
+
this._createData = _createData;
|
|
1471
1472
|
this._createLanguageDocument = _createLanguageDocument;
|
|
1472
1473
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1474
|
+
#documentCache = /* @__PURE__ */ new Map();
|
|
1475
|
+
#fs;
|
|
1475
1476
|
get hasFileSystemProvider() {
|
|
1476
|
-
return !!this.
|
|
1477
|
+
return !!this._createData.workspace;
|
|
1477
1478
|
}
|
|
1478
1479
|
get host() {
|
|
1479
1480
|
return this._ctx.host;
|
|
@@ -1506,17 +1507,17 @@ var WorkerBase = class {
|
|
|
1506
1507
|
if (!model) {
|
|
1507
1508
|
return null;
|
|
1508
1509
|
}
|
|
1509
|
-
const cached = this.
|
|
1510
|
+
const cached = this.#documentCache.get(uri);
|
|
1510
1511
|
if (cached && cached[0] === model.version) {
|
|
1511
1512
|
return cached[1];
|
|
1512
1513
|
}
|
|
1513
1514
|
const document2 = TextDocument2.create(uri, "-", model.version, model.getValue());
|
|
1514
|
-
this.
|
|
1515
|
+
this.#documentCache.set(uri, [model.version, document2, void 0]);
|
|
1515
1516
|
return document2;
|
|
1516
1517
|
}
|
|
1517
1518
|
getLanguageDocument(document2) {
|
|
1518
1519
|
const { uri, version } = document2;
|
|
1519
|
-
const cached = this.
|
|
1520
|
+
const cached = this.#documentCache.get(uri);
|
|
1520
1521
|
if (cached && cached[0] === version && cached[2]) {
|
|
1521
1522
|
return cached[2];
|
|
1522
1523
|
}
|
|
@@ -1524,14 +1525,13 @@ var WorkerBase = class {
|
|
|
1524
1525
|
throw new Error("createLanguageDocument is not provided");
|
|
1525
1526
|
}
|
|
1526
1527
|
const languageDocument = this._createLanguageDocument(document2);
|
|
1527
|
-
this.
|
|
1528
|
+
this.#documentCache.set(uri, [version, document2, languageDocument]);
|
|
1528
1529
|
return languageDocument;
|
|
1529
1530
|
}
|
|
1530
1531
|
readDir(uri, extensions) {
|
|
1531
1532
|
const entries = [];
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
for (const [path, type] of fsTree) {
|
|
1533
|
+
if (this.#fs) {
|
|
1534
|
+
for (const [path, type] of this.#fs) {
|
|
1535
1535
|
if (path.startsWith(uri)) {
|
|
1536
1536
|
const name = path.slice(uri.length);
|
|
1537
1537
|
if (!name.includes("/")) {
|
|
@@ -1567,30 +1567,25 @@ var WorkerBase = class {
|
|
|
1567
1567
|
resolveReference(ref, baseUrl) {
|
|
1568
1568
|
const url = new URL(ref, baseUrl);
|
|
1569
1569
|
const href = url.href;
|
|
1570
|
-
if (url.protocol === "file:" && this.
|
|
1571
|
-
|
|
1572
|
-
return void 0;
|
|
1573
|
-
}
|
|
1570
|
+
if (url.protocol === "file:" && url.pathname !== "/" && this.#fs && !this.#fs.has(href.endsWith("/") ? href.slice(0, -1) : href)) {
|
|
1571
|
+
return void 0;
|
|
1574
1572
|
}
|
|
1575
1573
|
return href;
|
|
1576
1574
|
}
|
|
1577
1575
|
// #region methods used by the host
|
|
1578
1576
|
async removeDocumentCache(uri) {
|
|
1579
|
-
this.
|
|
1580
|
-
}
|
|
1581
|
-
async syncFSEntries(entries) {
|
|
1582
|
-
this._fsEntries = new Map(entries);
|
|
1577
|
+
this.#documentCache.delete(uri);
|
|
1583
1578
|
}
|
|
1584
1579
|
async fsNotify(kind, path, type) {
|
|
1585
1580
|
const url = "file://" + path;
|
|
1586
|
-
const entries = this
|
|
1581
|
+
const entries = this.#fs ?? (this.#fs = /* @__PURE__ */ new Map());
|
|
1587
1582
|
if (kind === "create") {
|
|
1588
1583
|
if (type) {
|
|
1589
1584
|
entries.set(url, type);
|
|
1590
1585
|
}
|
|
1591
1586
|
} else if (kind === "remove") {
|
|
1592
1587
|
if (entries.get(url) === 1 /* File */) {
|
|
1593
|
-
this.
|
|
1588
|
+
this.#documentCache.delete(url);
|
|
1594
1589
|
}
|
|
1595
1590
|
entries.delete(url);
|
|
1596
1591
|
}
|
|
@@ -1599,17 +1594,17 @@ var WorkerBase = class {
|
|
|
1599
1594
|
};
|
|
1600
1595
|
|
|
1601
1596
|
// src/lsp/typescript/worker.ts
|
|
1602
|
-
import libs from "./libs.
|
|
1603
|
-
import { cache } from "../../cache.
|
|
1604
|
-
import { initializeWorker } from "../../editor-worker.
|
|
1597
|
+
import libs from "./libs.mjs";
|
|
1598
|
+
import { cache } from "../../cache.mjs";
|
|
1599
|
+
import { initializeWorker } from "../../editor-worker.mjs";
|
|
1605
1600
|
var TypeScriptWorker = class extends WorkerBase {
|
|
1606
1601
|
#compilerOptions;
|
|
1602
|
+
#languageService;
|
|
1607
1603
|
#formatOptions;
|
|
1608
1604
|
#importMap;
|
|
1609
1605
|
#importMapVersion;
|
|
1610
1606
|
#isBlankImportMap;
|
|
1611
1607
|
#types;
|
|
1612
|
-
#languageService = ts.createLanguageService(this);
|
|
1613
1608
|
#urlMappings = /* @__PURE__ */ new Map();
|
|
1614
1609
|
#typesMappings = /* @__PURE__ */ new Map();
|
|
1615
1610
|
#httpLibs = /* @__PURE__ */ new Map();
|
|
@@ -1622,8 +1617,9 @@ var TypeScriptWorker = class extends WorkerBase {
|
|
|
1622
1617
|
#fetchPromises = /* @__PURE__ */ new Map();
|
|
1623
1618
|
#httpDocumentCache = /* @__PURE__ */ new Map();
|
|
1624
1619
|
constructor(ctx, createData) {
|
|
1625
|
-
super(ctx);
|
|
1620
|
+
super(ctx, createData);
|
|
1626
1621
|
this.#compilerOptions = ts.convertCompilerOptionsFromJson(createData.compilerOptions, ".").options;
|
|
1622
|
+
this.#languageService = ts.createLanguageService(this);
|
|
1627
1623
|
this.#importMap = createData.importMap;
|
|
1628
1624
|
this.#importMapVersion = 0;
|
|
1629
1625
|
this.#isBlankImportMap = isBlankImportMap(createData.importMap);
|
|
@@ -7739,8 +7739,8 @@ var version = "1.24.10";
|
|
|
7739
7739
|
var version2 = "1.10.9";
|
|
7740
7740
|
|
|
7741
7741
|
// src/shiki.ts
|
|
7742
|
-
import { cache } from "./cache.
|
|
7743
|
-
import { isPlainObject } from "./util.
|
|
7742
|
+
import { cache } from "./cache.mjs";
|
|
7743
|
+
import { isPlainObject } from "./util.mjs";
|
|
7744
7744
|
|
|
7745
7745
|
// src/render.ts
|
|
7746
7746
|
var DEFAULT_WINDOWS_FONT_FAMILY = "Consolas, 'Courier New', monospace";
|
|
@@ -8071,6 +8071,9 @@ async function initShiki({
|
|
|
8071
8071
|
if (languages?.length) {
|
|
8072
8072
|
const set = /* @__PURE__ */ new Set();
|
|
8073
8073
|
languages.forEach((l) => {
|
|
8074
|
+
if (["plaintext", "text"].includes(l)) {
|
|
8075
|
+
return;
|
|
8076
|
+
}
|
|
8074
8077
|
if (typeof l === "string" || l instanceof URL) {
|
|
8075
8078
|
if (!set.has(l.toString())) {
|
|
8076
8079
|
const g = grammars.find((g2) => g2.name === l);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/ssr/index.ts
|
|
2
|
-
import { setDefaultWasmLoader } from "../shiki.
|
|
3
|
-
import { getWasmInstance } from "../shiki-wasm.
|
|
2
|
+
import { setDefaultWasmLoader } from "../shiki.mjs";
|
|
3
|
+
import { getWasmInstance } from "../shiki-wasm.mjs";
|
|
4
4
|
|
|
5
5
|
// src/ssr/ssr.ts
|
|
6
|
-
import { getLanguageIdFromPath, initShiki } from "../shiki.
|
|
7
|
-
import { render } from "../shiki.
|
|
6
|
+
import { getLanguageIdFromPath, initShiki } from "../shiki.mjs";
|
|
7
|
+
import { render } from "../shiki.mjs";
|
|
8
8
|
var ssrHighlighter;
|
|
9
9
|
async function renderToString(input, options) {
|
|
10
10
|
const { language, theme, shiki } = options ?? {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/ssr/workerd.ts
|
|
2
|
-
import { setDefaultWasmLoader } from "../shiki.
|
|
2
|
+
import { setDefaultWasmLoader } from "../shiki.mjs";
|
|
3
3
|
|
|
4
4
|
// src/ssr/ssr.ts
|
|
5
|
-
import { getLanguageIdFromPath, initShiki } from "../shiki.
|
|
6
|
-
import { render } from "../shiki.
|
|
5
|
+
import { getLanguageIdFromPath, initShiki } from "../shiki.mjs";
|
|
6
|
+
import { render } from "../shiki.mjs";
|
|
7
7
|
var ssrHighlighter;
|
|
8
8
|
async function renderToString(input, options) {
|
|
9
9
|
const { language, theme, shiki } = options ?? {};
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
promisifyIDBRequest,
|
|
12
12
|
supportLocalStorage,
|
|
13
13
|
toURL
|
|
14
|
-
} from "./util.
|
|
14
|
+
} from "./util.mjs";
|
|
15
15
|
var Workspace = class {
|
|
16
16
|
_monaco;
|
|
17
17
|
_history;
|
|
@@ -66,18 +66,18 @@ var Workspace = class {
|
|
|
66
66
|
}
|
|
67
67
|
async openTextDocument(uri, content) {
|
|
68
68
|
const monaco = await this._monaco.promise;
|
|
69
|
-
return this._openTextDocument(uri, monaco.editor.getEditors()[0]);
|
|
69
|
+
return this._openTextDocument(uri, monaco.editor.getEditors()[0], void 0, content);
|
|
70
70
|
}
|
|
71
71
|
// @internal
|
|
72
|
-
async _openTextDocument(uri, editor, selectionOrPosition) {
|
|
72
|
+
async _openTextDocument(uri, editor, selectionOrPosition, readonlyContent) {
|
|
73
73
|
const monaco = await this._monaco.promise;
|
|
74
74
|
const fs = this._fs;
|
|
75
75
|
const href = toURL(uri).href;
|
|
76
|
-
const content = await fs.readTextFile(href);
|
|
76
|
+
const content = readonlyContent ?? await fs.readTextFile(href);
|
|
77
77
|
const viewState = await this.viewState.get(href);
|
|
78
78
|
const modelUri = monaco.Uri.parse(href);
|
|
79
79
|
const model = monaco.editor.getModel(modelUri) ?? monaco.editor.createModel(content, void 0, modelUri);
|
|
80
|
-
if (!Reflect.has(model, "__OB__")) {
|
|
80
|
+
if (!Reflect.has(model, "__OB__") && typeof readonlyContent !== "string") {
|
|
81
81
|
const persist = createPersistTask(() => fs.writeFile(href, model.getValue(), { isModelContentChange: true }));
|
|
82
82
|
const disposable = model.onDidChangeContent(persist);
|
|
83
83
|
const unwatch = fs.watch(href, (kind, _, __, context) => {
|
|
@@ -99,7 +99,13 @@ var Workspace = class {
|
|
|
99
99
|
}
|
|
100
100
|
if (editor) {
|
|
101
101
|
editor.setModel(model);
|
|
102
|
-
editor.updateOptions({ readOnly:
|
|
102
|
+
editor.updateOptions({ readOnly: typeof readonlyContent === "string" });
|
|
103
|
+
if (typeof readonlyContent === "string") {
|
|
104
|
+
const disposable = editor.onDidChangeModel(() => {
|
|
105
|
+
model.dispose();
|
|
106
|
+
disposable.dispose();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
103
109
|
if (selectionOrPosition) {
|
|
104
110
|
if ("startLineNumber" in selectionOrPosition) {
|
|
105
111
|
editor.setSelection(selectionOrPosition);
|
|
@@ -149,14 +155,12 @@ var FS = class {
|
|
|
149
155
|
const transaction = (await this._db.open()).transaction(["fs-meta", "fs-blob"], readwrite ? "readwrite" : "readonly");
|
|
150
156
|
return [transaction.objectStore("fs-meta"), transaction.objectStore("fs-blob")];
|
|
151
157
|
}
|
|
152
|
-
|
|
153
|
-
* read the fs entries
|
|
154
|
-
* @internal
|
|
155
|
-
*/
|
|
156
|
-
async entries() {
|
|
158
|
+
async *walk() {
|
|
157
159
|
const metaStore = await this._getIdbObjectStore("fs-meta");
|
|
158
160
|
const entries = await promisifyIDBRequest(metaStore.getAll());
|
|
159
|
-
|
|
161
|
+
for (const entry of entries) {
|
|
162
|
+
yield [new URL(entry.url).pathname, entry.type];
|
|
163
|
+
}
|
|
160
164
|
}
|
|
161
165
|
async stat(name) {
|
|
162
166
|
const url = filenameToURL(name).href;
|
package/package.json
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-monaco",
|
|
3
3
|
"description": "A modern version of Monaco Editor",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
7
|
-
"module": "./dist/index.
|
|
6
|
+
"main": "./dist/index.mjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import": "./dist/index.
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
12
|
"types": "./types/index.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"./core": {
|
|
15
|
-
"import": "./dist/core.
|
|
15
|
+
"import": "./dist/core.mjs",
|
|
16
16
|
"types": "./types/core.d.ts"
|
|
17
17
|
},
|
|
18
18
|
"./workspace": {
|
|
19
|
-
"import": "./dist/workspace.
|
|
19
|
+
"import": "./dist/workspace.mjs",
|
|
20
20
|
"types": "./types/workspace.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"./ssr": {
|
|
23
|
-
"workerd": "./dist/ssr/workerd.
|
|
24
|
-
"import": "./dist/ssr/index.
|
|
23
|
+
"workerd": "./dist/ssr/workerd.mjs",
|
|
24
|
+
"import": "./dist/ssr/index.mjs",
|
|
25
25
|
"types": "./types/ssr.d.ts"
|
|
26
26
|
},
|
|
27
27
|
"./editor-core": {
|
|
28
|
-
"import": "./dist/editor-core.
|
|
28
|
+
"import": "./dist/editor-core.mjs",
|
|
29
29
|
"types": "./types/monaco.d.ts"
|
|
30
30
|
},
|
|
31
31
|
"./editor-worker": {
|
|
32
|
-
"import": "./dist/editor-worker.
|
|
32
|
+
"import": "./dist/editor-worker.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./editor-worker-main": {
|
|
35
|
+
"import": "./dist/editor-worker-main.mjs"
|
|
33
36
|
},
|
|
34
37
|
"./cache": {
|
|
35
|
-
"import": "./dist/cache.
|
|
38
|
+
"import": "./dist/cache.mjs"
|
|
36
39
|
},
|
|
37
40
|
"./shiki": {
|
|
38
|
-
"import": "./dist/shiki.
|
|
41
|
+
"import": "./dist/shiki.mjs"
|
|
39
42
|
},
|
|
40
43
|
"./util": {
|
|
41
|
-
"import": "./dist/util.
|
|
44
|
+
"import": "./dist/util.mjs"
|
|
42
45
|
},
|
|
43
46
|
"./lsp/*": {
|
|
44
|
-
"import": "./dist/lsp/*.
|
|
47
|
+
"import": "./dist/lsp/*.mjs"
|
|
45
48
|
}
|
|
46
49
|
},
|
|
47
50
|
"esm.sh": {
|
|
@@ -67,7 +70,7 @@
|
|
|
67
70
|
"@esm.sh/import-map": "0.1.1",
|
|
68
71
|
"@shikijs/core": "3.12.2",
|
|
69
72
|
"@shikijs/engine-oniguruma": "3.12.2",
|
|
70
|
-
"monaco-editor-core": "0.
|
|
73
|
+
"monaco-editor-core": "0.53.0",
|
|
71
74
|
"tm-grammars": "1.24.10",
|
|
72
75
|
"tm-themes": "1.10.9",
|
|
73
76
|
"typescript": "5.9.2",
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as monacoNS from "./monaco.d.ts";
|
|
2
2
|
import type { LSPConfig } from "./lsp.d.ts";
|
|
3
3
|
import type { TextmateGrammarName, TextmateThemeName } from "./textmate.d.ts";
|
|
4
|
-
import
|
|
4
|
+
import { ErrorNotFound, FileSystem, Workspace } from "./workspace";
|
|
5
5
|
|
|
6
6
|
type Awaitable<T> = T | Promise<T>;
|
|
7
7
|
type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
|
package/types/lsp.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface ITagData extends IData {
|
|
|
66
66
|
void?: boolean;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export interface
|
|
69
|
+
export interface LSPModule {
|
|
70
70
|
setup: (
|
|
71
71
|
monaco: typeof monacoNS,
|
|
72
72
|
languageId: string,
|
|
@@ -74,13 +74,12 @@ export interface LSP {
|
|
|
74
74
|
formattingOptions?: Record<string, unknown>,
|
|
75
75
|
workspace?: Workspace,
|
|
76
76
|
) => Promise<void>;
|
|
77
|
-
getWorkerUrl: () => URL;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
export interface LSPProvider {
|
|
81
80
|
aliases?: string[];
|
|
82
81
|
syntaxes?: any[];
|
|
83
|
-
import: () => Promise<
|
|
82
|
+
import: () => Promise<LSPModule>;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
export interface LSPConfig extends LSPLanguageConfig {
|
|
@@ -105,8 +104,6 @@ declare global {
|
|
|
105
104
|
compilerOptions?: ts.CompilerOptions;
|
|
106
105
|
/** The global import maps. */
|
|
107
106
|
importMap?: ImportMap;
|
|
108
|
-
/** The version of the typescript imported from esm.sh CDN. Default: ">= 5.5.0" */
|
|
109
|
-
tsVersion?: string;
|
|
110
107
|
};
|
|
111
108
|
}
|
|
112
109
|
}
|