@codingame/monaco-vscode-standalone-html-language-features 23.1.1 → 23.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/common/initialize.js +11 -0
- package/common/workers.d.ts +29 -0
- package/common/workers.js +70 -0
- package/language/common/lspLanguageFeatures.js +644 -0
- package/language/html/html.worker.js +8 -0
- package/language/html/htmlMode.js +141 -0
- package/language/html/htmlWorker.js +126 -0
- package/language/html/monaco.contribution.d.ts +162 -0
- package/{index.js → language/html/monaco.contribution.js} +21 -57
- package/language/html/workerManager.js +64 -0
- package/package.json +7 -4
- package/htmlMode.js +0 -2108
- package/worker.js +0 -16161
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { editor } from "@codingame/monaco-vscode-api/vscode/vs/editor/editor.api.js";
|
|
2
|
+
declare function createWebWorker<T extends object>(opts: IWebWorkerOptions): editor.MonacoWebWorker<T>;
|
|
3
|
+
interface IWebWorkerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The AMD moduleId to load.
|
|
6
|
+
* It should export a function `create` that should return the exported proxy.
|
|
7
|
+
*/
|
|
8
|
+
moduleId: string;
|
|
9
|
+
createWorker?: () => Worker;
|
|
10
|
+
/**
|
|
11
|
+
* The data to send over when calling create on the module.
|
|
12
|
+
*/
|
|
13
|
+
createData?: any;
|
|
14
|
+
/**
|
|
15
|
+
* A label to be used to identify the web worker for debugging purposes.
|
|
16
|
+
*/
|
|
17
|
+
label?: string;
|
|
18
|
+
/**
|
|
19
|
+
* An object that can be used by the web worker to make calls back to the main thread.
|
|
20
|
+
*/
|
|
21
|
+
host?: any;
|
|
22
|
+
/**
|
|
23
|
+
* Keep idle models.
|
|
24
|
+
* Defaults to false, which means that idle models will stop syncing after a while.
|
|
25
|
+
*/
|
|
26
|
+
keepIdleModels?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export { createWebWorker };
|
|
29
|
+
export type { IWebWorkerOptions };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
import { editor } from 'monaco-editor';
|
|
3
|
+
|
|
4
|
+
function createTrustedTypesPolicy(policyName, policyOptions) {
|
|
5
|
+
const monacoEnvironment = globalThis.MonacoEnvironment;
|
|
6
|
+
if (monacoEnvironment?.createTrustedTypesPolicy) {
|
|
7
|
+
try {
|
|
8
|
+
return monacoEnvironment.createTrustedTypesPolicy(policyName, policyOptions);
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err);
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
return globalThis.trustedTypes?.createPolicy(policyName, policyOptions);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error(err);
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let ttPolicy;
|
|
22
|
+
if (typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope" && globalThis.workerttPolicy !== void 0) {
|
|
23
|
+
ttPolicy = globalThis.workerttPolicy;
|
|
24
|
+
} else {
|
|
25
|
+
ttPolicy = createTrustedTypesPolicy("defaultWorkerFactory", {
|
|
26
|
+
createScriptURL: (value) => value
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function getWorker(descriptor) {
|
|
30
|
+
const label = descriptor.label;
|
|
31
|
+
const monacoEnvironment = globalThis.MonacoEnvironment;
|
|
32
|
+
if (monacoEnvironment) {
|
|
33
|
+
if (typeof monacoEnvironment.getWorker === "function") {
|
|
34
|
+
return monacoEnvironment.getWorker("workerMain.js", label);
|
|
35
|
+
}
|
|
36
|
+
if (typeof monacoEnvironment.getWorkerUrl === "function") {
|
|
37
|
+
const workerUrl = monacoEnvironment.getWorkerUrl("workerMain.js", label);
|
|
38
|
+
return new Worker(
|
|
39
|
+
ttPolicy ? ttPolicy.createScriptURL(workerUrl) : workerUrl,
|
|
40
|
+
{ name: label, type: "module" }
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (descriptor.createWorker) {
|
|
45
|
+
return descriptor.createWorker();
|
|
46
|
+
}
|
|
47
|
+
throw new Error(
|
|
48
|
+
`You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
function createWebWorker(opts) {
|
|
52
|
+
const worker = Promise.resolve(
|
|
53
|
+
getWorker({
|
|
54
|
+
label: opts.label ?? "monaco-editor-worker",
|
|
55
|
+
moduleId: opts.moduleId,
|
|
56
|
+
createWorker: opts.createWorker
|
|
57
|
+
})
|
|
58
|
+
).then((w) => {
|
|
59
|
+
w.postMessage("ignore");
|
|
60
|
+
w.postMessage(opts.createData);
|
|
61
|
+
return w;
|
|
62
|
+
});
|
|
63
|
+
return editor.createWebWorker({
|
|
64
|
+
worker,
|
|
65
|
+
host: opts.host,
|
|
66
|
+
keepIdleModels: opts.keepIdleModels
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { createWebWorker };
|