From 30070275c4dde0c2e1aae9e5c84f4865827e808b Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Mon, 7 Oct 2024 11:32:51 +0200 Subject: [PATCH] fix: Better django CMS 3 compatibility --- CHANGELOG.rst | 6 ++++++ djangocms_text/__init__.py | 2 +- private/js/cms.editor.js | 33 ++++++++++++++++----------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e0e51d37..c7c7a0d2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,12 @@ Changelog ========= +0.3.2 (07-10-2024) +================== + +* fix: Improve inline editing experience for django CMS v3 + + 0.3.1 (02-10-2024) ================== diff --git a/djangocms_text/__init__.py b/djangocms_text/__init__.py index 4b9070ff..5398a0d2 100644 --- a/djangocms_text/__init__.py +++ b/djangocms_text/__init__.py @@ -15,4 +15,4 @@ 9. Publish the release when ready 10. Github actions will publish the new package to pypi """ -__version__ = "0.3.1" +__version__ = "0.3.2" diff --git a/private/js/cms.editor.js b/private/js/cms.editor.js index 92bb37e8..aa05f629 100644 --- a/private/js/cms.editor.js +++ b/private/js/cms.editor.js @@ -30,7 +30,6 @@ class CMSEditor { if (this.CMS) { // Only needs to happen on the main window. - console.log("Refresh established"); this.CMS.$(window).on('cms-content-refresh', () => { if (document.querySelector('template.cms-plugin')) { // django CMS core does not wrap newly inserted inline editable fields @@ -153,8 +152,6 @@ class CMSEditor { // no plugins -> no inline editors return; } - console.log("Init inline editors"); - const plugins = this.CMS._plugins; this.observer = this.observer || new IntersectionObserver( (entries) => { entries.forEach((entry) => { @@ -172,7 +169,7 @@ class CMSEditor { generic_inline_fields = JSON.parse(generic_inline_fields.textContent || '{}'); } - plugins.forEach(function (plugin) { + this.CMS._plugins.forEach(function (plugin) { if (plugin[1].type === 'plugin' || plugin[1].type === 'generic') { // Either plugin or frontend editable element const url = plugin[1].urls.edit_plugin; @@ -256,10 +253,6 @@ class CMSEditor { wrapper = document.createElement('div'); wrapper.classList.add('cms-editor-inline-wrapper', 'wrapped'); wrapper = this._wrapAll(elements, wrapper); - wrapper.classList.add('cms-plugin', 'cms-plugin-' + id); - for (let child of wrapper.children) { - child.classList.remove('cms-plugin', 'cms-plugin-' + id); - } } wrapper.dataset.cmsEditUrl = url; return wrapper; @@ -450,10 +443,17 @@ class CMSEditor { return; } } - this.CMS.API.StructureBoard.handleEditPlugin(this.CMS.API.Helpers.dataBridge); if (this.CMS.settings.version < "4") { /* Reflect dirty flag in django CMS < 4 */ + try { + /* For some reason, in v3 this fails if the structure board is not open */ + this.CMS.API.StructureBoard.handleEditPlugin(this.CMS.API.Helpers.dataBridge); + } catch (e) { + console.error(e); + } this._loadToolbar(); + } else { + this.CMS.API.StructureBoard.handleEditPlugin(this.CMS.API.Helpers.dataBridge); } }) .catch(error => { @@ -467,6 +467,7 @@ class CMSEditor { }); } window.console.error(error.message); + window.console.log(error.stack); }); } } @@ -584,14 +585,12 @@ class CMSEditor { // CMS Editor: loadToolbar // Load the toolbar after saving for update _loadToolbar () { - if (this.CMS) { - const $ = this.CMS.$; - this.CMS.API.StructureBoard._loadToolbar() - .done((newToolbar) => { - this.CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar')); - }) - .fail(() => this.CMS.API.Helpers.reloadBrowser()); - } + const $ = this.CMS.$; + this.CMS.API.StructureBoard._loadToolbar() + .done((newToolbar) => { + this.CMS.API.Toolbar._refreshMarkup($(newToolbar).find('.cms-toolbar')); + }) + .fail(() => this.CMS.API.Helpers.reloadBrowser()); } _highlightTextplugin (pluginId) {