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.
@@ -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
- _documentCache = /* @__PURE__ */ new Map();
1474
- _fsEntries;
1474
+ #documentCache = /* @__PURE__ */ new Map();
1475
+ #fs;
1475
1476
  get hasFileSystemProvider() {
1476
- return !!this._fsEntries;
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._documentCache.get(uri);
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._documentCache.set(uri, [model.version, document2, void 0]);
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._documentCache.get(uri);
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._documentCache.set(uri, [version, document2, languageDocument]);
1528
+ this.#documentCache.set(uri, [version, document2, languageDocument]);
1528
1529
  return languageDocument;
1529
1530
  }
1530
1531
  readDir(uri, extensions) {
1531
1532
  const entries = [];
1532
- const fsTree = this._fsEntries;
1533
- if (fsTree) {
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._fsEntries) {
1571
- if (!this._fsEntries.has(href)) {
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._documentCache.delete(uri);
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._fsEntries ?? (this._fsEntries = /* @__PURE__ */ new Map());
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._documentCache.delete(url);
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.js";
1603
- import { cache } from "../../cache.js";
1604
- import { initializeWorker } from "../../editor-worker.js";
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.js";
7743
- import { isPlainObject } from "./util.js";
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.js";
3
- import { getWasmInstance } from "../shiki-wasm.js";
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.js";
7
- import { render } from "../shiki.js";
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.js";
2
+ import { setDefaultWasmLoader } from "../shiki.mjs";
3
3
 
4
4
  // src/ssr/ssr.ts
5
- import { getLanguageIdFromPath, initShiki } from "../shiki.js";
6
- import { render } from "../shiki.js";
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.js";
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: false });
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
- return entries.map(({ url, type }) => [url, type]);
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.9",
4
+ "version": "0.2.1",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
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.js",
11
+ "import": "./dist/index.mjs",
12
12
  "types": "./types/index.d.ts"
13
13
  },
14
14
  "./core": {
15
- "import": "./dist/core.js",
15
+ "import": "./dist/core.mjs",
16
16
  "types": "./types/core.d.ts"
17
17
  },
18
18
  "./workspace": {
19
- "import": "./dist/workspace.js",
19
+ "import": "./dist/workspace.mjs",
20
20
  "types": "./types/workspace.d.ts"
21
21
  },
22
22
  "./ssr": {
23
- "workerd": "./dist/ssr/workerd.js",
24
- "import": "./dist/ssr/index.js",
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.js",
28
+ "import": "./dist/editor-core.mjs",
29
29
  "types": "./types/monaco.d.ts"
30
30
  },
31
31
  "./editor-worker": {
32
- "import": "./dist/editor-worker.js"
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.js"
38
+ "import": "./dist/cache.mjs"
36
39
  },
37
40
  "./shiki": {
38
- "import": "./dist/shiki.js"
41
+ "import": "./dist/shiki.mjs"
39
42
  },
40
43
  "./util": {
41
- "import": "./dist/util.js"
44
+ "import": "./dist/util.mjs"
42
45
  },
43
46
  "./lsp/*": {
44
- "import": "./dist/lsp/*.js"
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.52.2",
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 type { ErrorNotFound, FileSystem, Workspace } from "./workspace.d.ts";
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 LSP {
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<LSP>;
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
  }