Skip to content

Commit

Permalink
Regenerate da-y-wrapper and fix the preview window updates (#214)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Chris Peyer <[email protected]>
  • Loading branch information
bosschaert and chrischrischris authored Sep 24, 2024
1 parent a345439 commit 8def111
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
16 changes: 11 additions & 5 deletions blocks/edit/prose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function getSchema() {
return new Schema({ nodes, marks: addCustomMarks(marks) });
}

let pollerSetUp = false;
let sendUpdates = false;
let hasChanged = 0;
function dispatchTransaction(transaction) {
Expand All @@ -116,11 +117,12 @@ function setPreviewBody(daPreview, proseEl) {
daPreview.body = body;
}

function pollForUpdates() {
const daContent = document.querySelector('da-content');
const daPreview = daContent.shadowRoot.querySelector('da-preview');
if (!window.view) return;
const proseEl = window.view.root.querySelector('.ProseMirror');
export function pollForUpdates(doc = document, win = window) {
if (pollerSetUp) return;
const daContent = doc.querySelector('da-content');
const daPreview = daContent?.shadowRoot.querySelector('da-preview');
if (!win.view) return;
const proseEl = win.view.root.querySelector('.ProseMirror');
if (!daPreview) return;

setInterval(() => {
Expand All @@ -133,6 +135,7 @@ function pollForUpdates() {
sendUpdates = false;
}
}, 500);
pollerSetUp = true;
}

function handleAwarenessUpdates(wsProvider, daTitle, win) {
Expand Down Expand Up @@ -299,6 +302,9 @@ export default function initProse({ editor, path }) {
},
});

// Call pollForUpdates() to make sure it gets called even if the callback was made earlier
pollForUpdates();

document.execCommand('enableObjectResizing', false, 'false');
document.execCommand('enableInlineTableEditing', false, 'false');

Expand Down
Loading

0 comments on commit 8def111

Please sign in to comment.