modern-monaco 0.0.0-beta.5 → 0.1.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 +84 -56
- package/dist/core.js +5 -18
- package/dist/index.js +7 -7
- package/dist/shiki-wasm.js +1 -1
- package/dist/shiki.js +11 -7
- package/dist/ssr/index.js +1 -1
- package/dist/ssr/workerd.js +1 -1
- package/dist/workspace.js +65 -67
- package/package.json +4 -4
- package/types/index.d.ts +4 -4
- package/types/ssr.d.ts +1 -2
- package/types/workspace.d.ts +4 -2
package/dist/shiki.js
CHANGED
|
@@ -10,7 +10,7 @@ var define_TM_GRAMMARS_default = [{ name: "abap", scopeName: "source.abap" }, {
|
|
|
10
10
|
// <define:TM_THEMES>
|
|
11
11
|
var define_TM_THEMES_default = ["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"];
|
|
12
12
|
|
|
13
|
-
// node_modules/.pnpm/@shikijs+types@3.9.
|
|
13
|
+
// node_modules/.pnpm/@shikijs+types@3.9.2/node_modules/@shikijs/types/dist/index.mjs
|
|
14
14
|
var ShikiError = class extends Error {
|
|
15
15
|
constructor(message) {
|
|
16
16
|
super(message);
|
|
@@ -5405,7 +5405,7 @@ function all(parent) {
|
|
|
5405
5405
|
return results.join("");
|
|
5406
5406
|
}
|
|
5407
5407
|
|
|
5408
|
-
// node_modules/.pnpm/@shikijs+core@3.9.
|
|
5408
|
+
// node_modules/.pnpm/@shikijs+core@3.9.2/node_modules/@shikijs/core/dist/index.mjs
|
|
5409
5409
|
function resolveColorReplacements(theme, options) {
|
|
5410
5410
|
const replacements = typeof theme === "string" ? {} : { ...theme.colorReplacements };
|
|
5411
5411
|
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
@@ -5700,11 +5700,15 @@ function transformerDecorations() {
|
|
|
5700
5700
|
const line = converter.lines[p2.line];
|
|
5701
5701
|
if (line === void 0)
|
|
5702
5702
|
throw new ShikiError(`Invalid decoration position ${JSON.stringify(p2)}. Lines length: ${converter.lines.length}`);
|
|
5703
|
-
|
|
5703
|
+
let character = p2.character;
|
|
5704
|
+
if (character < 0)
|
|
5705
|
+
character = line.length + character;
|
|
5706
|
+
if (character < 0 || character > line.length)
|
|
5704
5707
|
throw new ShikiError(`Invalid decoration position ${JSON.stringify(p2)}. Line ${p2.line} length: ${line.length}`);
|
|
5705
5708
|
return {
|
|
5706
5709
|
...p2,
|
|
5707
|
-
|
|
5710
|
+
character,
|
|
5711
|
+
offset: converter.posToIndex(p2.line, character)
|
|
5708
5712
|
};
|
|
5709
5713
|
}
|
|
5710
5714
|
};
|
|
@@ -7263,7 +7267,7 @@ async function createHighlighterCore(options) {
|
|
|
7263
7267
|
};
|
|
7264
7268
|
}
|
|
7265
7269
|
|
|
7266
|
-
// node_modules/.pnpm/@shikijs+engine-oniguruma@3.9.
|
|
7270
|
+
// node_modules/.pnpm/@shikijs+engine-oniguruma@3.9.2/node_modules/@shikijs/engine-oniguruma/dist/index.mjs
|
|
7267
7271
|
var ShikiError3 = class extends Error {
|
|
7268
7272
|
constructor(message) {
|
|
7269
7273
|
super(message);
|
|
@@ -7707,8 +7711,8 @@ async function createOnigurumaEngine(options) {
|
|
|
7707
7711
|
};
|
|
7708
7712
|
}
|
|
7709
7713
|
|
|
7710
|
-
// node_modules/.pnpm/tm-grammars@1.24.
|
|
7711
|
-
var version = "1.24.
|
|
7714
|
+
// node_modules/.pnpm/tm-grammars@1.24.3/node_modules/tm-grammars/package.json
|
|
7715
|
+
var version = "1.24.3";
|
|
7712
7716
|
|
|
7713
7717
|
// node_modules/.pnpm/tm-themes@1.10.7/node_modules/tm-themes/package.json
|
|
7714
7718
|
var version2 = "1.10.7";
|
package/dist/ssr/index.js
CHANGED
|
@@ -31,7 +31,7 @@ async function renderToString(input, options) {
|
|
|
31
31
|
}
|
|
32
32
|
async function renderToWebComponent(input, options) {
|
|
33
33
|
const prerender = await renderToString(input, options);
|
|
34
|
-
return '<monaco-editor><script type="application/json" class="monaco-editor-options">' + JSON.stringify([input, options]) + '<\/script><div class="monaco-editor-prerender" style="width:100%;height:100%;">' + prerender + "</div></monaco-editor>";
|
|
34
|
+
return '<monaco-editor><script type="application/json" class="monaco-editor-options">' + JSON.stringify([input, options]).replaceAll("/", "\\/") + '<\/script><div class="monaco-editor-prerender" style="width:100%;height:100%;">' + prerender + "</div></monaco-editor>";
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// src/ssr/index.ts
|
package/dist/ssr/workerd.js
CHANGED
|
@@ -30,7 +30,7 @@ async function renderToString(input, options) {
|
|
|
30
30
|
}
|
|
31
31
|
async function renderToWebComponent(input, options) {
|
|
32
32
|
const prerender = await renderToString(input, options);
|
|
33
|
-
return '<monaco-editor><script type="application/json" class="monaco-editor-options">' + JSON.stringify([input, options]) + '<\/script><div class="monaco-editor-prerender" style="width:100%;height:100%;">' + prerender + "</div></monaco-editor>";
|
|
33
|
+
return '<monaco-editor><script type="application/json" class="monaco-editor-options">' + JSON.stringify([input, options]).replaceAll("/", "\\/") + '<\/script><div class="monaco-editor-prerender" style="width:100%;height:100%;">' + prerender + "</div></monaco-editor>";
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// src/ssr/workerd.ts
|
package/dist/workspace.js
CHANGED
|
@@ -19,64 +19,10 @@ var Workspace = class {
|
|
|
19
19
|
_viewState;
|
|
20
20
|
_entryFile;
|
|
21
21
|
constructor(options = {}) {
|
|
22
|
-
const { name = "default", browserHistory, initialFiles, entryFile } = options;
|
|
23
|
-
const db = new WorkspaceDatabase(
|
|
24
|
-
name,
|
|
25
|
-
{
|
|
26
|
-
name: "fs-meta",
|
|
27
|
-
keyPath: "url",
|
|
28
|
-
onCreate: async (store) => {
|
|
29
|
-
if (initialFiles) {
|
|
30
|
-
const promises = [];
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
const reg = { type: 1, version: 1, ctime: now, mtime: now, size: 0 };
|
|
33
|
-
const dir = { type: 2, version: 1, ctime: now, mtime: now, size: 0 };
|
|
34
|
-
for (const [name2, data] of Object.entries(initialFiles)) {
|
|
35
|
-
const { pathname, href: url } = filenameToURL(name2);
|
|
36
|
-
let parent = pathname.slice(0, pathname.lastIndexOf("/"));
|
|
37
|
-
while (parent) {
|
|
38
|
-
promises.push(
|
|
39
|
-
promisifyIDBRequest(
|
|
40
|
-
store.put({ url: toURL(parent).href, ...dir })
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
parent = parent.slice(0, parent.lastIndexOf("/"));
|
|
44
|
-
}
|
|
45
|
-
promises.push(
|
|
46
|
-
promisifyIDBRequest(
|
|
47
|
-
store.put({ url, ...reg, size: encode(data).byteLength })
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
await Promise.all(promises);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "fs-blob",
|
|
57
|
-
keyPath: "url",
|
|
58
|
-
onCreate: async (store) => {
|
|
59
|
-
if (initialFiles) {
|
|
60
|
-
const promises = [];
|
|
61
|
-
for (const [name2, data] of Object.entries(initialFiles)) {
|
|
62
|
-
promises.push(
|
|
63
|
-
promisifyIDBRequest(
|
|
64
|
-
store.put({ url: filenameToURL(name2).href, content: encode(data) })
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
await Promise.all(promises);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "viewstate",
|
|
74
|
-
keyPath: "url"
|
|
75
|
-
}
|
|
76
|
-
);
|
|
22
|
+
const { name = "default", browserHistory, initialFiles, entryFile, customFs } = options;
|
|
77
23
|
this._monaco = promiseWithResolvers();
|
|
78
|
-
this._fs = new FS(
|
|
79
|
-
this._viewState = new WorkspaceStateStorage(
|
|
24
|
+
this._fs = customFs ?? new FS("modern-monaco-workspace:" + name, initialFiles);
|
|
25
|
+
this._viewState = new WorkspaceStateStorage("modern-monaco-viewstate:" + name);
|
|
80
26
|
this._entryFile = entryFile;
|
|
81
27
|
if (browserHistory) {
|
|
82
28
|
if (!globalThis.history) {
|
|
@@ -170,10 +116,56 @@ var Workspace = class {
|
|
|
170
116
|
}
|
|
171
117
|
};
|
|
172
118
|
var FS = class {
|
|
173
|
-
constructor(_db) {
|
|
174
|
-
this._db = _db;
|
|
175
|
-
}
|
|
176
119
|
_watchers = /* @__PURE__ */ new Set();
|
|
120
|
+
_db;
|
|
121
|
+
constructor(scope, initialFiles) {
|
|
122
|
+
this._db = new WorkspaceDatabase(scope, {
|
|
123
|
+
name: "fs-meta",
|
|
124
|
+
keyPath: "url",
|
|
125
|
+
onCreate: async (store) => {
|
|
126
|
+
if (initialFiles) {
|
|
127
|
+
const promises = [];
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
const reg = { type: 1, version: 1, ctime: now, mtime: now, size: 0 };
|
|
130
|
+
const dir = { type: 2, version: 1, ctime: now, mtime: now, size: 0 };
|
|
131
|
+
for (const [name, data] of Object.entries(initialFiles)) {
|
|
132
|
+
const { pathname, href: url } = filenameToURL(name);
|
|
133
|
+
let parent = pathname.slice(0, pathname.lastIndexOf("/"));
|
|
134
|
+
while (parent) {
|
|
135
|
+
promises.push(
|
|
136
|
+
promisifyIDBRequest(
|
|
137
|
+
store.put({ url: toURL(parent).href, ...dir })
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
parent = parent.slice(0, parent.lastIndexOf("/"));
|
|
141
|
+
}
|
|
142
|
+
promises.push(
|
|
143
|
+
promisifyIDBRequest(
|
|
144
|
+
store.put({ url, ...reg, size: encode(data).byteLength })
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
await Promise.all(promises);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, {
|
|
152
|
+
name: "fs-blob",
|
|
153
|
+
keyPath: "url",
|
|
154
|
+
onCreate: async (store) => {
|
|
155
|
+
if (initialFiles) {
|
|
156
|
+
const promises = [];
|
|
157
|
+
for (const [name, data] of Object.entries(initialFiles)) {
|
|
158
|
+
promises.push(
|
|
159
|
+
promisifyIDBRequest(
|
|
160
|
+
store.put({ url: filenameToURL(name).href, content: encode(data) })
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
await Promise.all(promises);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
177
169
|
async _getIdbObjectStore(storeName, readwrite = false) {
|
|
178
170
|
const db = await this._db.open();
|
|
179
171
|
return db.transaction(storeName, readwrite ? "readwrite" : "readonly").objectStore(storeName);
|
|
@@ -459,8 +451,8 @@ var ErrorNotFound = class extends Error {
|
|
|
459
451
|
};
|
|
460
452
|
var WorkspaceDatabase = class {
|
|
461
453
|
_db;
|
|
462
|
-
constructor(
|
|
463
|
-
const open = () => openIDB(
|
|
454
|
+
constructor(name, ...stores) {
|
|
455
|
+
const open = () => openIDB(name, 1, ...stores).then((db) => {
|
|
464
456
|
db.onclose = () => {
|
|
465
457
|
this._db = open();
|
|
466
458
|
};
|
|
@@ -473,18 +465,24 @@ var WorkspaceDatabase = class {
|
|
|
473
465
|
}
|
|
474
466
|
};
|
|
475
467
|
var WorkspaceStateStorage = class {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
this
|
|
468
|
+
#db;
|
|
469
|
+
constructor(dbName) {
|
|
470
|
+
this.#db = new WorkspaceDatabase(
|
|
471
|
+
dbName,
|
|
472
|
+
{
|
|
473
|
+
name: "store",
|
|
474
|
+
keyPath: "url"
|
|
475
|
+
}
|
|
476
|
+
);
|
|
479
477
|
}
|
|
480
478
|
async get(uri) {
|
|
481
479
|
const url = toURL(uri).href;
|
|
482
|
-
const store = (await this.
|
|
480
|
+
const store = (await this.#db.open()).transaction("store", "readonly").objectStore("store");
|
|
483
481
|
return promisifyIDBRequest(store.get(url)).then((result) => result?.state);
|
|
484
482
|
}
|
|
485
483
|
async save(uri, state) {
|
|
486
484
|
const url = toURL(uri).href;
|
|
487
|
-
const store = (await this.
|
|
485
|
+
const store = (await this.#db.open()).transaction("store", "readwrite").objectStore("store");
|
|
488
486
|
await promisifyIDBRequest(store.put({ url, state }));
|
|
489
487
|
}
|
|
490
488
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-monaco",
|
|
3
3
|
"description": "A modern version of Monaco Editor",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"sideEffects": false,
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@esm.sh/import-map": "0.1.1",
|
|
68
|
-
"@shikijs/core": "3.9.
|
|
69
|
-
"@shikijs/engine-oniguruma": "3.9.
|
|
68
|
+
"@shikijs/core": "3.9.2",
|
|
69
|
+
"@shikijs/engine-oniguruma": "3.9.2",
|
|
70
70
|
"monaco-editor-core": "0.52.2",
|
|
71
|
-
"tm-grammars": "1.24.
|
|
71
|
+
"tm-grammars": "1.24.3",
|
|
72
72
|
"tm-themes": "1.10.7",
|
|
73
73
|
"typescript": "5.9.2",
|
|
74
74
|
"vscode-css-languageservice": "6.3.7",
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type 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, Workspace } from "./workspace.d.ts";
|
|
4
|
+
import type { ErrorNotFound, FileSystem, Workspace } from "./workspace.d.ts";
|
|
5
5
|
|
|
6
6
|
type Awaitable<T> = T | Promise<T>;
|
|
7
7
|
type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
|
|
@@ -60,11 +60,11 @@ export interface InitOptions extends ShikiInitOptions {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export function init(options?: InitOptions): Promise<typeof monacoNS>;
|
|
63
|
-
export function lazy(options?: InitOptions): void
|
|
64
|
-
export function hydrate(options?: InitOptions): void
|
|
63
|
+
export function lazy(options?: InitOptions): Promise<void>;
|
|
64
|
+
export function hydrate(options?: InitOptions): Promise<void>;
|
|
65
65
|
|
|
66
66
|
export const errors: {
|
|
67
67
|
NotFound: ErrorNotFound;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
export { Workspace };
|
|
70
|
+
export { Workspace, FileSystem };
|
package/types/ssr.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type monacoNS from "./monaco.d.ts";
|
|
2
2
|
import type { ShikiInitOptions } from "./index.d.ts";
|
|
3
3
|
|
|
4
|
-
export type RenderInput = string | { filename: string; code: string };
|
|
4
|
+
export type RenderInput = string | { filename: string; code: string; version?: number };
|
|
5
5
|
|
|
6
6
|
export interface RenderOptions extends monacoNS.editor.IStandaloneEditorConstructionOptions {
|
|
7
|
-
filename?: string;
|
|
8
7
|
fontDigitWidth?: number;
|
|
9
8
|
userAgent?: string;
|
|
10
9
|
shiki?: ShikiInitOptions;
|
package/types/workspace.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface WorkspaceInit {
|
|
|
14
14
|
server?: {
|
|
15
15
|
url: string | URL;
|
|
16
16
|
};
|
|
17
|
+
/** custom filesystem implementation to override the default IndexedDB filesystem */
|
|
18
|
+
customFs?: FileSystem;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export class Workspace {
|
|
@@ -62,13 +64,13 @@ export interface FileSystem {
|
|
|
62
64
|
readTextFile(filename: string): Promise<string>;
|
|
63
65
|
rename(oldName: string, newName: string, options?: { overwrite: boolean }): Promise<void>;
|
|
64
66
|
stat(filename: string): Promise<FileStat>;
|
|
65
|
-
writeFile(filename: string, content: string | Uint8Array): Promise<void>;
|
|
67
|
+
writeFile(filename: string, content: string | Uint8Array, context?: { isModelContentChange: boolean }): Promise<void>;
|
|
66
68
|
watch(filename: string, options: { recursive: boolean }, handle: FileSystemWatchHandle): () => void;
|
|
67
69
|
watch(filename: string, handle: FileSystemWatchHandle): () => void;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export interface FileSystemWatchHandle {
|
|
71
|
-
(kind: "create" | "modify" | "remove", filename: string, type?: number): void;
|
|
73
|
+
(kind: "create" | "modify" | "remove", filename: string, type?: number, context?: { isModelContentChange: boolean }): void;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
export class ErrorNotFound extends Error {}
|