From fcafc7ff0892072ddc05dbeb94b0c1227b74dde0 Mon Sep 17 00:00:00 2001 From: Frederic Salmen <4583669+salmenf@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:19:26 +0100 Subject: [PATCH] Support Firefox --- @webwriter/core/view/editor/palette.ts | 2 +- .../core/view/editor/prosemirroreditor.ts | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/@webwriter/core/view/editor/palette.ts b/@webwriter/core/view/editor/palette.ts index 9b0bf74..b60d794 100644 --- a/@webwriter/core/view/editor/palette.ts +++ b/@webwriter/core/view/editor/palette.ts @@ -963,7 +963,7 @@ export class Palette extends LitElement { AddLocalPackageButton() { const importingName = this.app.store.packages.importingName - const disabled = !this.app.store.accounts.getClient("file", "file")?.fileSystemSupported + const disabled = !this.app.store.accounts.getClient("file", "file")?.showOpenFilePickerSupported return html` !disabled && (this.packageFormMode = "create")} ?inert=${!!importingName} ?data-disabled=${disabled} title=${disabled? "This is a feature for developers. It only works in Chromium-based browsers with the File System Access API enabled (Chrome, Edge, etc.).": ""}>
${importingName? prettifyPackageName(importingName): msg(" Create/import")}
diff --git a/@webwriter/core/view/editor/prosemirroreditor.ts b/@webwriter/core/view/editor/prosemirroreditor.ts index 5b62ac6..fd50e2c 100644 --- a/@webwriter/core/view/editor/prosemirroreditor.ts +++ b/@webwriter/core/view/editor/prosemirroreditor.ts @@ -209,6 +209,13 @@ export class ProsemirrorEditor extends LitElement implements IProsemirrorEditor updateState = (...args: Parameters) => { this?.view.updateState(...args) + // Fix for Firefox + if(!this.view?.dom?.querySelector(":not(br)")) { + (this.view as any).domObserver.stop(); + const p = this.document.createElement("p"); + this.body.appendChild(p); + (this.view as any).domObserver.start() + } this.dispatchEvent(new CustomEvent("update", {composed: true, bubbles: true, detail: {editorState: this.view.state}})) } @@ -278,25 +285,29 @@ export class ProsemirrorEditor extends LitElement implements IProsemirrorEditor if(this.url) { return this.initializePreviewFrame() } - await this.initializeIFrame() this.view?.destroy() - this.view = new EditorView({mount: this.body}, this.directProps) + await this.initializeIFrame() // Fix for Firefox - if(!this.view?.dom?.querySelector(":not(br)")) { - const p = this.view.dom.ownerDocument.createElement("p") - this.view.dom.appendChild(p) + if(!this.body.querySelector(":not(br)")) { + const p = this.document.createElement("p") + this.body.appendChild(p) } + this.view = new EditorView({mount: this.body}, this.directProps) this.focus() this.renderHead() } async updated(previous: Map) { + if(!this.head) { + return + } if(!this.url) { try { this.view?.setProps(this.directProps) } catch(err: any) { - if(err.message !== "Cannot read properties of null (reading 'focusNode')") { + const ignoreMessages = ["Cannot read properties of null (reading 'focusNode')", "c is null"] + if(!ignoreMessages.includes(err?.message)) { throw err } }