From 0902debd4476f33de17e693586c582d9867bf5e9 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Fri, 27 Sep 2024 12:25:10 +0200 Subject: [PATCH] Fix: Improved form success detection --- private/js/cms.editor.js | 4 ++-- .../js/tiptap_plugins/cms.balloon-toolbar.js | 18 +++++++++++------- private/js/tiptap_plugins/cms.plugin.js | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/private/js/cms.editor.js b/private/js/cms.editor.js index 7db093f..6ca78fb 100644 --- a/private/js/cms.editor.js +++ b/private/js/cms.editor.js @@ -366,7 +366,7 @@ class CMSEditor { // Fallback solution is to reload the page as djagocms-text-ckeditor used to do. const dom = document.createElement('html'); dom.innerHTML = body; - const success_element = dom.querySelectorAll('.messagelist > .success').length > 0; + const success_element = dom.querySelectorAll('div.messagelist > div.success').length > 0; if (!success_element) { el.dataset.changed = 'true'; // Collect messages @@ -485,7 +485,7 @@ class CMSEditor { } // - let saveSuccess = !!form.querySelector('.messagelist :not(.error)'); + let saveSuccess = !!form.querySelector('.messagelist :not(.error,.success)'); if (!saveSuccess) { saveSuccess = !!form.querySelector('.dashboard #content-main') && diff --git a/private/js/tiptap_plugins/cms.balloon-toolbar.js b/private/js/tiptap_plugins/cms.balloon-toolbar.js index f807eac..4af295d 100644 --- a/private/js/tiptap_plugins/cms.balloon-toolbar.js +++ b/private/js/tiptap_plugins/cms.balloon-toolbar.js @@ -116,14 +116,18 @@ export default class CmsBalloonToolbar { } depth -= 1; } - depth = 1; // TODO: Decide which works better: First level, or highest level with block node - this._updateToolbarIcon(resolvedPos.node(depth)); - const startPos = resolvedPos.start(depth); - this.toolbar.dataset.block = startPos; - const pos = this.editor.view.coordsAtPos(startPos); - const ref = this.editor.options.el.getBoundingClientRect(); + if (depth > 0) { + this._updateToolbarIcon(resolvedPos.node(depth)); + const startPos = resolvedPos.start(depth); + this.toolbar.dataset.block = startPos; + const pos = this.editor.view.coordsAtPos(startPos); + const ref = this.editor.options.el.getBoundingClientRect(); - this.toolbar.style.insetBlockStart = `${pos.top - ref.top}px`; + this.toolbar.style.insetBlockStart = `${pos.top - ref.top}px`; + this.toolbar.style.display = 'block'; + } else { + this.toolbar.style.display = 'none'; + } // TODO: Set the size of the balloon according to the fontsize // this.toolbar.style.setProperty('--size', this.editor.view. ...) } diff --git a/private/js/tiptap_plugins/cms.plugin.js b/private/js/tiptap_plugins/cms.plugin.js index 110bcb0..f280926 100644 --- a/private/js/tiptap_plugins/cms.plugin.js +++ b/private/js/tiptap_plugins/cms.plugin.js @@ -163,6 +163,7 @@ const cmsPluginNodes = { // Node types need to match return false; } + attrs['data-node'] = this.name; // return attributes and content return { HTMLAttributes: attrs,