Skip to content

Commit 029007d

Browse files
Fix Imagine Monaco editor interactions inside Console wrapper (#2488)
Co-authored-by: Torsten Dittmann <torsten.dittmann@googlemail.com>
1 parent 335c6d4 commit 029007d

3 files changed

Lines changed: 98 additions & 42 deletions

File tree

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
name: Dockerize Profiles
22

33
on:
4-
push:
5-
branches: [feat-profiles]
6-
pull_request:
7-
types: [opened, synchronize, reopened]
8-
branches: [feat-profiles]
9-
workflow_dispatch:
4+
push:
5+
branches: [feat-profiles]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
branches: [feat-profiles]
9+
workflow_dispatch:
1010

1111
jobs:
12-
dockerize-profiles:
13-
runs-on: ubuntu-latest
14-
15-
steps:
16-
- name: Checkout the repo
17-
uses: actions/checkout@v2
18-
- name: Set up QEMU
19-
uses: docker/setup-qemu-action@v2
20-
- name: Set up Docker Buildx
21-
uses: docker/setup-buildx-action@v2
22-
- name: Log in to Docker Hub
23-
uses: docker/login-action@v3
24-
with:
25-
username: ${{ vars.DOCKERHUB_USERNAME }}
26-
password: ${{ secrets.DOCKERHUB_TOKEN }}
12+
dockerize-profiles:
13+
runs-on: ubuntu-latest
2714

28-
- name: Extract metadata (tags, labels) for Docker
29-
id: meta
30-
uses: docker/metadata-action@v5
31-
with:
32-
images: appwrite/console-profiles
33-
tags: |
34-
type=ref,event=branch,prefix=branch-
35-
type=ref,event=pr
36-
type=sha,prefix=sha-
37-
type=raw,value=gh-${{ github.run_id}}
38-
flavor: |
39-
latest=false
15+
steps:
16+
- name: Checkout the repo
17+
uses: actions/checkout@v2
18+
- name: Set up QEMU
19+
uses: docker/setup-qemu-action@v2
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
- name: Log in to Docker Hub
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ vars.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_TOKEN }}
4027

41-
- name: Build and push Docker image
42-
id: push
43-
uses: docker/build-push-action@v6
44-
with:
45-
context: .
46-
push: true
47-
platforms: linux/amd64,linux/arm64
48-
tags: ${{ steps.meta.outputs.tags }}
49-
labels: ${{ steps.meta.outputs.labels }}
28+
- name: Extract metadata (tags, labels) for Docker
29+
id: meta
30+
uses: docker/metadata-action@v5
31+
with:
32+
images: appwrite/console-profiles
33+
tags: |
34+
type=ref,event=branch,prefix=branch-
35+
type=ref,event=pr
36+
type=sha,prefix=sha-
37+
type=raw,value=gh-${{ github.run_id}}
38+
flavor: |
39+
latest=false
40+
41+
- name: Build and push Docker image
42+
id: push
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: .
46+
push: true
47+
platforms: linux/amd64,linux/arm64
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const MONACO_STYLE_ATTRIBUTE = 'data-appwrite-studio-monaco-style';
2+
3+
let monacoStyleObserver: MutationObserver | null = null;
4+
5+
function findMonacoEditorCssLink(): HTMLLinkElement | null {
6+
if (typeof document === 'undefined') {
7+
return null;
8+
}
9+
10+
const link = document.head?.querySelector<HTMLLinkElement>(
11+
'link[rel="stylesheet"][href*="monaco-editor"][href*="editor.main.css"]'
12+
);
13+
14+
return link ?? null;
15+
}
16+
17+
function syncMonacoStyles(shadow: ShadowRoot) {
18+
if (typeof document === 'undefined') {
19+
return;
20+
}
21+
22+
// Check if already synced
23+
if (shadow.querySelector(`[${MONACO_STYLE_ATTRIBUTE}]`)) {
24+
return;
25+
}
26+
27+
const link = findMonacoEditorCssLink();
28+
if (!link) {
29+
return;
30+
}
31+
32+
const clone = link.cloneNode(true) as HTMLLinkElement;
33+
clone.setAttribute(MONACO_STYLE_ATTRIBUTE, 'true');
34+
shadow.appendChild(clone);
35+
}
36+
37+
export function ensureMonacoStyles(shadow: ShadowRoot) {
38+
syncMonacoStyles(shadow);
39+
40+
if (
41+
monacoStyleObserver ||
42+
typeof MutationObserver === 'undefined' ||
43+
typeof document === 'undefined'
44+
) {
45+
return;
46+
}
47+
48+
monacoStyleObserver = new MutationObserver(() => {
49+
syncMonacoStyles(shadow);
50+
});
51+
52+
monacoStyleObserver.observe(document.head, { childList: true });
53+
}

src/lib/studio/studio-widget.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { app } from '$lib/stores/app';
33
import { get } from 'svelte/store';
44
import { goto } from '$app/navigation';
55
import { resolve } from '$app/paths';
6+
import { ensureMonacoStyles } from './monaco-style-manager';
67
import DEV_CSS_URL from '@imagine.dev/web-components/imagine-web-components.css?url';
78

89
const COMPONENT_SELECTOR = 'imagine-web-components-wrapper[data-appwrite-studio]';
@@ -83,6 +84,7 @@ function injectStyles(node: HTMLElement, attempt = 0) {
8384
}
8485

8586
if (shadow.querySelector<HTMLLinkElement>(`link[${STYLE_ATTRIBUTE}]`)) {
87+
ensureMonacoStyles(shadow);
8688
return;
8789
}
8890

@@ -91,6 +93,7 @@ function injectStyles(node: HTMLElement, attempt = 0) {
9193
link.href = DEV_OVERRIDE_WEB_COMPONENTS ? DEV_CSS_URL : CDN_CSS_URL;
9294
link.setAttribute(STYLE_ATTRIBUTE, 'true');
9395
shadow.prepend(link);
96+
ensureMonacoStyles(shadow);
9497
})
9598
.catch(() => {
9699
/* no-op */

0 commit comments

Comments
 (0)