Skip to content

Commit

Permalink
Support Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
salmenf committed Nov 18, 2024
1 parent bc5662f commit fcafc7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion @webwriter/core/view/editor/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`<sl-card id="add-local" class=${classMap({"package-card": true})} @click=${() => !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.).": ""}>
<sl-icon name="plus"></sl-icon>
<div>${importingName? prettifyPackageName(importingName): msg(" Create/import")}</div>
Expand Down
23 changes: 17 additions & 6 deletions @webwriter/core/view/editor/prosemirroreditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ export class ProsemirrorEditor extends LitElement implements IProsemirrorEditor

updateState = (...args: Parameters<typeof this.view.updateState>) => {
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}}))
}

Expand Down Expand Up @@ -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<string, any>) {
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
}
}
Expand Down

0 comments on commit fcafc7f

Please sign in to comment.