@codingame/monaco-vscode-api 16.1.0-shadow-root.1 → 16.1.0
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 +26 -3
- package/css.js +20 -17
- package/package.json +8 -8
- package/services.js +7 -7
package/README.md
CHANGED
|
@@ -327,7 +327,7 @@ See the [VSCode Server](https://github.com/CodinGame/monaco-vscode-api/wiki/How-
|
|
|
327
327
|
|
|
328
328
|
The library supports shadow-dom.
|
|
329
329
|
|
|
330
|
-
⚠️ VSCode itself
|
|
330
|
+
⚠️ VSCode itself doesn't support shadow dom, and there are multiple parts that needed to be patched in order for it to work.
|
|
331
331
|
|
|
332
332
|
There are multiple benefits of using it:
|
|
333
333
|
- Your custom global style won't impact the VSCode workbench style (for instance if you did override the default [box-sizing](https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing))
|
|
@@ -338,21 +338,44 @@ There are multiple benefits of using it:
|
|
|
338
338
|
|
|
339
339
|
If the provided container element is a child of a shadow dom element, the styles will be injected in both the main page and the shadow root. That's it.
|
|
340
340
|
|
|
341
|
+
### ⚠️ Xterm notice ⚠️
|
|
342
|
+
|
|
343
|
+
The webgl renderer of xterm, which VSCode is using, doesn't support being used inside a shadom dom (see https://github.com/xtermjs/xterm.js/pull/5334).
|
|
344
|
+
Until it's fixed and deployed, either do not use the terminal service override, or apply the patch on your side (using [patch-package](https://www.npmjs.com/package/patch-package) for instance).
|
|
345
|
+
|
|
341
346
|
### Prerequisites
|
|
342
347
|
|
|
343
|
-
In order to be able to load the static css files in the shadow dom as well. Your bundler configuration needs to be adapted so that importing css files doesn't load their content in the page head, but instead just returns the file content as default. It can be achieved with most bundlers with some configurations.
|
|
348
|
+
In order to be able to load the static css files in the shadow dom as well. Your bundler configuration needs to be adapted so that importing css files doesn't load their content in the page head, but instead just returns the file content as default (either as a string or a `CSSStyleSheet`). It can be achieved with most bundlers with some configurations.
|
|
349
|
+
|
|
350
|
+
Note that the bundler should still resolve referenced assets in the css files, so you can't just use the `raw` loader, or the `assets/source` webpack module type.
|
|
344
351
|
|
|
345
352
|
#### Webpack
|
|
353
|
+
|
|
346
354
|
Add this rule in your configuration:
|
|
355
|
+
|
|
347
356
|
```typescript
|
|
348
357
|
{
|
|
349
358
|
test: /node_modules\/(@codingame\/monaco-vscode|vscode|monaco-editor).*\.css$/,
|
|
350
|
-
|
|
359
|
+
use: [
|
|
360
|
+
{
|
|
361
|
+
loader: 'css-loader',
|
|
362
|
+
options: {
|
|
363
|
+
esModule: false,
|
|
364
|
+
exportType: 'css-style-sheet', // or 'string', both are working
|
|
365
|
+
url: true,
|
|
366
|
+
import: true
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
]
|
|
351
370
|
}
|
|
352
371
|
```
|
|
353
372
|
|
|
373
|
+
You should also make sure that no other loader is interfering with it, by either use a `oneOf` or exclusing those files in the other css loaders.
|
|
374
|
+
|
|
354
375
|
#### Vite
|
|
376
|
+
|
|
355
377
|
Add this plugin in your configuration:
|
|
378
|
+
|
|
356
379
|
```typescript
|
|
357
380
|
{
|
|
358
381
|
name: 'load-vscode-css-as-string',
|
package/css.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const sheets = [];
|
|
4
4
|
function registerCss(module) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
sheet
|
|
5
|
+
const exportedValue = module.default;
|
|
6
|
+
let sheet = undefined;
|
|
7
|
+
if (typeof exportedValue === 'string') {
|
|
8
|
+
sheet = new CSSStyleSheet();
|
|
9
|
+
sheet.replaceSync(exportedValue);
|
|
10
|
+
}
|
|
11
|
+
else if (exportedValue instanceof CSSStyleSheet) {
|
|
12
|
+
sheet = exportedValue;
|
|
13
|
+
}
|
|
14
|
+
if (sheet != null) {
|
|
9
15
|
const fontFaces = Array.from(sheet.cssRules)
|
|
10
16
|
.filter((rule) => rule instanceof CSSFontFaceRule)
|
|
11
17
|
.map((r) => r.cssText);
|
|
12
18
|
if (fontFaces.length > 0) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
const fontFaceStyleSheet = new CSSStyleSheet();
|
|
20
|
+
for (const fontFace of fontFaces) {
|
|
21
|
+
fontFaceStyleSheet.insertRule(fontFace);
|
|
22
|
+
}
|
|
23
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, fontFaceStyleSheet];
|
|
17
24
|
}
|
|
18
|
-
|
|
25
|
+
sheets.push(sheet);
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
function getInjectElement(target) {
|
|
@@ -23,18 +30,14 @@ function getInjectElement(target) {
|
|
|
23
30
|
if (root instanceof ShadowRoot) {
|
|
24
31
|
return root;
|
|
25
32
|
}
|
|
26
|
-
return document
|
|
33
|
+
return document;
|
|
27
34
|
}
|
|
28
35
|
function injectCss(target) {
|
|
29
36
|
const root = getInjectElement(target);
|
|
30
|
-
if (root instanceof ShadowRoot &&
|
|
37
|
+
if (root instanceof ShadowRoot && sheets.length === 0) {
|
|
31
38
|
console.error("@codingame/monaco-vscode-api was loaded inside a shadow dom, but it's unable to load the css into it because the bundler configuration wasn't applied properly: imported css files should export their content as default");
|
|
32
39
|
}
|
|
33
|
-
|
|
34
|
-
const styleEl = document.createElement('style');
|
|
35
|
-
styleEl.appendChild(document.createTextNode(style));
|
|
36
|
-
root.appendChild(styleEl);
|
|
37
|
-
}
|
|
40
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, ...sheets];
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
export { injectCss, registerCss };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-api",
|
|
3
|
-
"version": "16.1.0
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "VSCode public API plugged on the monaco editor",
|
|
6
6
|
"keywords": [],
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"type": "module",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@c4312/eventsource-umd": "3.0.5",
|
|
19
|
-
"@codingame/monaco-vscode-base-service-override": "16.1.0
|
|
20
|
-
"@codingame/monaco-vscode-environment-service-override": "16.1.0
|
|
21
|
-
"@codingame/monaco-vscode-extensions-service-override": "16.1.0
|
|
22
|
-
"@codingame/monaco-vscode-files-service-override": "16.1.0
|
|
23
|
-
"@codingame/monaco-vscode-host-service-override": "16.1.0
|
|
24
|
-
"@codingame/monaco-vscode-layout-service-override": "16.1.0
|
|
25
|
-
"@codingame/monaco-vscode-quickaccess-service-override": "16.1.0
|
|
19
|
+
"@codingame/monaco-vscode-base-service-override": "16.1.0",
|
|
20
|
+
"@codingame/monaco-vscode-environment-service-override": "16.1.0",
|
|
21
|
+
"@codingame/monaco-vscode-extensions-service-override": "16.1.0",
|
|
22
|
+
"@codingame/monaco-vscode-files-service-override": "16.1.0",
|
|
23
|
+
"@codingame/monaco-vscode-host-service-override": "16.1.0",
|
|
24
|
+
"@codingame/monaco-vscode-layout-service-override": "16.1.0",
|
|
25
|
+
"@codingame/monaco-vscode-quickaccess-service-override": "16.1.0",
|
|
26
26
|
"marked": "14.0.0"
|
|
27
27
|
},
|
|
28
28
|
"main": "services.js",
|
package/services.js
CHANGED
|
@@ -92,7 +92,6 @@ import './vscode/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeybo
|
|
|
92
92
|
export { default as Severity } from './vscode/src/vs/base/common/severity.js';
|
|
93
93
|
export { StorageScope, StorageTarget } from './vscode/src/vs/platform/storage/common/storage.js';
|
|
94
94
|
import { StandaloneServices } from './vscode/src/vs/editor/standalone/browser/standaloneServices.js';
|
|
95
|
-
import { mixin } from './vscode/src/vs/base/common/objects.js';
|
|
96
95
|
import { IInstantiationService } from './vscode/src/vs/platform/instantiation/common/instantiation.js';
|
|
97
96
|
import { DisposableStore } from './vscode/src/vs/base/common/lifecycle.js';
|
|
98
97
|
import { registerWorkbenchContribution2 } from './vscode/src/vs/workbench/common/contributions.js';
|
|
@@ -181,16 +180,16 @@ export { IKeybindingService } from './vscode/src/vs/platform/keybinding/common/k
|
|
|
181
180
|
export { ISecretStorageService } from './vscode/src/vs/platform/secrets/common/secrets.service.js';
|
|
182
181
|
export { ConfigurationTarget } from './vscode/src/vs/platform/configuration/common/configuration.js';
|
|
183
182
|
|
|
184
|
-
if (window.monacoVscodeApiBuildId != null && window.monacoVscodeApiBuildId !== "1.99.3-
|
|
185
|
-
throw new Error(`Another version of monaco-vscode-api has already been loaded. Trying to load ${"1.99.3-
|
|
183
|
+
if (window.monacoVscodeApiBuildId != null && window.monacoVscodeApiBuildId !== "1.99.3-de370f37-1fc0-486b-a51c-37a009681fa0") {
|
|
184
|
+
throw new Error(`Another version of monaco-vscode-api has already been loaded. Trying to load ${"1.99.3-de370f37-1fc0-486b-a51c-37a009681fa0"}, ${window.monacoVscodeApiBuildId} is already loaded`);
|
|
186
185
|
}
|
|
187
|
-
window.monacoVscodeApiBuildId = "1.99.3-
|
|
186
|
+
window.monacoVscodeApiBuildId = "1.99.3-de370f37-1fc0-486b-a51c-37a009681fa0";
|
|
188
187
|
async function initialize(overrides, container = document.body, configuration = {}, env) {
|
|
189
188
|
checkServicesNotInitialized();
|
|
190
189
|
injectCss(container);
|
|
191
190
|
initialize$1(container, configuration, env);
|
|
192
191
|
const instantiationService = StandaloneServices.initialize({
|
|
193
|
-
[IProductService.toString()]:
|
|
192
|
+
[IProductService.toString()]: {
|
|
194
193
|
version: "1.99.3",
|
|
195
194
|
quality: 'stable',
|
|
196
195
|
commit: "17baf841131aa23349f217ca7c570c76ee87b957",
|
|
@@ -202,8 +201,9 @@ async function initialize(overrides, container = document.body, configuration =
|
|
|
202
201
|
reportIssueUrl: 'https://github.com/microsoft/vscode/issues/new',
|
|
203
202
|
licenseName: 'MIT',
|
|
204
203
|
licenseUrl: 'https://github.com/microsoft/vscode/blob/main/LICENSE.txt',
|
|
205
|
-
serverApplicationName: 'code-server-oss'
|
|
206
|
-
|
|
204
|
+
serverApplicationName: 'code-server-oss',
|
|
205
|
+
...(configuration.productConfiguration ?? {})
|
|
206
|
+
},
|
|
207
207
|
...getServiceOverride$6(),
|
|
208
208
|
...getServiceOverride$5(),
|
|
209
209
|
...getServiceOverride$4(),
|