From e58f74b01627266de6686648cf03a65101816ca3 Mon Sep 17 00:00:00 2001 From: bat Date: Tue, 2 May 2023 01:55:32 +0000 Subject: [PATCH 1/3] add codemirror editor --- components/file-group-page.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/components/file-group-page.js b/components/file-group-page.js index 4895c5d..bc325d1 100644 --- a/components/file-group-page.js +++ b/components/file-group-page.js @@ -175,7 +175,11 @@ export class FileGroupPage extends HTMLElement { async displayEdit() { const doc = await this.editorBuild.build() - const msg = ['srcdoc', doc] + const msg = [ + 'srcdoc', + doc, + {codeMirror: this.settings.codeMirror}, + ] this.editFrame.contentWindow.postMessage( msg, '*' ) @@ -203,7 +207,12 @@ export class FileGroupPage extends HTMLElement { if (Array.isArray(event.data)) { if (event.data[0] === 'ready') { this.editFrame.contentWindow.postMessage( - ['doc', this.body], '*' + [ + 'doc', + this.body, + {codeMirror: !!(this.settings.codeMirror)} + ], + '*' ) } else if (event.data[0] === 'html') { const html = event.data[1] @@ -213,6 +222,18 @@ export class FileGroupPage extends HTMLElement { this.body = doc } else if (['get', 'put'].includes(event.data[0])) { await this.handleRequestMessage('edit', event) + } else if (event.data[0] === 'load') { + if (event.data[1] === '/editor-lib-codemirror/codemirror-bundle.js') { + const url = event.data[1] + const resp = await fetch(url) + const text = await resp.text() + const port = event.ports[0] + port.postMessage({ + status: 200, + body: text, + }) + port.close() + } } } } From e7b3f4ee86c87cabf06d144b42ed1a0555c31abb Mon Sep 17 00:00:00 2001 From: bat Date: Tue, 2 May 2023 01:56:20 +0000 Subject: [PATCH 2/3] add codemirror editor --- sw.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sw.js b/sw.js index 272f9c0..28c8328 100644 --- a/sw.js +++ b/sw.js @@ -13,6 +13,8 @@ async function initCache() { '/editor/file-group.js', '/editor/file-view.js', '/editor/text-edit.js', + '/editor/code-edit.js', + '/editor/header.js', '/forms/button-group.js', '/index.html', '/loader/builder.js', @@ -22,7 +24,7 @@ async function initCache() { '/settings/network-settings.js', '/settings/connections.js', '/settings/connection-edit.js', - ]) //1 + ]) } self.addEventListener("install", event => { From f7495eb9e45b10aadcacd58f58e07b0279bc01fc Mon Sep 17 00:00:00 2001 From: bat Date: Tue, 2 May 2023 01:59:22 +0000 Subject: [PATCH 3/3] add bundle --- sw.js | 1 + 1 file changed, 1 insertion(+) diff --git a/sw.js b/sw.js index 28c8328..7175251 100644 --- a/sw.js +++ b/sw.js @@ -24,6 +24,7 @@ async function initCache() { '/settings/network-settings.js', '/settings/connections.js', '/settings/connection-edit.js', + '/editor-lib-codemirror/codemirror-bundle.js', ]) }