diff --git a/djangocms_text/apps.py b/djangocms_text/apps.py index de02c15c..a864d431 100644 --- a/djangocms_text/apps.py +++ b/djangocms_text/apps.py @@ -8,8 +8,8 @@ class TextConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" def ready(self): - register(check_ckeditor_settings) self.inline_models = discover_inline_editable_models() + register(check_ckeditor_settings) def discover_inline_editable_models(): @@ -19,23 +19,17 @@ def discover_inline_editable_models(): registered_inline_fields = ["HTMLFormField", "CharField"] inline_models = {} - blacklist_apps = [ - "auth", - "admin", - "sessions", - "contenttypes", - "sites", - "cms", - "djangocms_text", - "djangocms_alias", - ] + blacklist_apps = [] + for model, modeladmin in site._registry.items(): if model._meta.app_label in blacklist_apps: continue for field_name in getattr(modeladmin, "frontend_editable_fields", []): try: - form = modeladmin.get_form(request=None, fields=(field_name,)) # Worth a try + form = modeladmin.get_form( + request=None, fields=(field_name,) + ) # Worth a try except Exception: form = getattr(modeladmin, "form", None) if form: @@ -62,7 +56,6 @@ def discover_inline_editable_models(): return inline_models - def check_ckeditor_settings(app_configs, **kwargs): from django.conf import settings diff --git a/djangocms_text/cms_toolbars.py b/djangocms_text/cms_toolbars.py index 653b10a8..b67b8858 100644 --- a/djangocms_text/cms_toolbars.py +++ b/djangocms_text/cms_toolbars.py @@ -12,7 +12,7 @@ from cms.toolbar_pool import toolbar_pool from . import settings -from .utils import get_url_endpoint, get_render_plugin_url +from .utils import get_url_endpoint, get_render_plugin_url, get_cancel_url from .widgets import rte_config, TextEditorWidget @@ -43,12 +43,8 @@ def media(self): @cached_property def inline_editing(self): - inline_editing = self.request.session.get( - "inline_editing", True - ) # Activated by default - change = self.request.GET.get( - "inline_editing", None - ) # can be changed by query param + inline_editing = self.request.session.get("inline_editing", True) # Activated by default + change = self.request.GET.get("inline_editing", None) # can be changed by query param if change is not None: inline_editing = change == "1" self.request.session["inline_editing"] = inline_editing # store in session @@ -60,9 +56,9 @@ def populate(self): item.add_item( IconButton( name=_("Toggle inline editing mode for text plugins"), - url=self.get_full_path_with_param( - "inline_editing", int(not self.inline_editing) - ).replace("/structure/", "/edit/"), + url=self.get_full_path_with_param("inline_editing", int(not self.inline_editing)).replace( + "/structure/", "/edit/" + ), active=self.inline_editing, extra_classes=["cms-icon cms-icon-pencil"], ), @@ -72,15 +68,14 @@ def populate(self): widget = TextEditorWidget( url_endpoint=get_url_endpoint(), render_plugin_url=get_render_plugin_url(), + cancel_url=get_cancel_url(), ) item = TemplateItem( "cms/toolbar/config.html", extra_context={ "global_config": widget.get_global_settings(self.current_lang), "html_field_config": widget.get_editor_settings(self.current_lang), - "allowed_inlines": apps.get_app_config( - "djangocms_text" - ).inline_models, + "allowed_inlines": apps.get_app_config("djangocms_text").inline_models, }, side=self.toolbar.RIGHT, ) diff --git a/djangocms_text/utils.py b/djangocms_text/utils.py index 1e3177d9..323bab5e 100644 --- a/djangocms_text/utils.py +++ b/djangocms_text/utils.py @@ -180,3 +180,8 @@ def get_url_endpoint(): def get_render_plugin_url(): """Get the url for rendering a text-enabled plugin for the toolbar""" return admin_reverse("djangocms_text_textplugin_render_plugin") + + +def get_cancel_url(): + """Get the url for cancelling a plugin edit""" + return admin_reverse("djangocms_text_textplugin_revert_on_cancel") diff --git a/djangocms_text/widgets.py b/djangocms_text/widgets.py index f8646d5e..221ecb47 100644 --- a/djangocms_text/widgets.py +++ b/djangocms_text/widgets.py @@ -173,9 +173,9 @@ def get_global_settings(self, language): } return { + "add_plugin_url": admin_reverse(cms_placeholder_add_plugin), "url_endpoint": self.url_endpoint or get_url_endpoint(), "static_url": settings.STATIC_URL + "djangocms_text", - "add_plugin_url": admin_reverse(cms_placeholder_add_plugin), "lang": toolbar_setting, "lang_alt": { "toolbar": gettext("CMS Plugins"), diff --git a/private/js/ckeditor4_plugins/cmsplugins/plugin.js b/private/js/ckeditor4_plugins/cmsplugins/plugin.js index 2b158ad9..57d0a8d7 100644 --- a/private/js/ckeditor4_plugins/cmsplugins/plugin.js +++ b/private/js/ckeditor4_plugins/cmsplugins/plugin.js @@ -84,7 +84,6 @@ import CmsDialog from "../../cms.dialog"; this.unsaved_child_plugins = []; var settings = CMS_Editor.getSettings(editor.name); - console.log(settings); this.setupCancelCleanupCallback(settings); // don't do anything if there are no plugins defined diff --git a/private/js/cms.dialog.js b/private/js/cms.dialog.js index 0469681d..9e31ab2a 100644 --- a/private/js/cms.dialog.js +++ b/private/js/cms.dialog.js @@ -276,8 +276,6 @@ class CmsForm { if (options && options.x && options.y) { const el_pos = this.el.getBoundingClientRect(); if (options.x > window.innerWidth / 2) { - console.log("options.x", options.x); - console.log("el_pos.width", el_pos.width); this.dialog.classList.add("right"); this.dialog.style.right = ( el_pos.x + el_pos.width - options.x - 28) + 'px'; } else { diff --git a/private/js/cms.editor.js b/private/js/cms.editor.js index 0a8a214a..7db093f0 100644 --- a/private/js/cms.editor.js +++ b/private/js/cms.editor.js @@ -18,19 +18,7 @@ class CMSEditor { this._global_settings = {}; this._editor_settings = {}; - // Get the CMS object from the parent window - if (window.CMS !== undefined && window.CMS.config !== undefined) { - this.mainWindow = window; - this.CMS = window.CMS; - } else { - this.mainWindow = window.parent; - this.CMS = window.parent.CMS; - } - - if (this.CMS) { - // Only needs to happen on the main window. - this.CMS.$(window).on('cms-content-refresh', () => this._resetInlineEditors()); - } + document.addEventListener('DOMContentLoaded', () => this.initAll()); } // CMS Editor: init @@ -284,6 +272,20 @@ class CMSEditor { // CMS Editor: init_all initAll () { + // Get the CMS object from the parent window + if (window.CMS !== undefined && window.CMS.config !== undefined) { + this.mainWindow = window; + this.CMS = window.CMS; + } else { + this.mainWindow = window.parent; + this.CMS = window.parent.CMS; + } + + if (this.CMS) { + // Only needs to happen on the main window. + this.CMS.$(window).on('cms-content-refresh', () => this._resetInlineEditors()); + } + // Get global options from script element try { this._global_settings = JSON.parse(document.getElementById('cms-editor-cfg').textContent); @@ -615,11 +617,7 @@ class CMSEditor { } } -// Create global editor object -document.addEventListener('DOMContentLoaded', () => { - "use strict"; - window.CMS_Editor = new CMSEditor(); - window.CMS_Editor.initAll(); -}); +// Create global editor object +window.CMS_Editor = new CMSEditor(); diff --git a/private/js/cms.linkfield.js b/private/js/cms.linkfield.js index 081ea907..b2026cbb 100644 --- a/private/js/cms.linkfield.js +++ b/private/js/cms.linkfield.js @@ -6,12 +6,10 @@ import "../css/cms.linkfield.css"; class LinkField { constructor(element, options) { - console.log("LinkField constructor", element.id + '_select'); this.options = options; this.urlElement = element; this.form = element.closest("form"); this.selectElement = this.form.querySelector(`input[name="${this.urlElement.id + '_select'}"]`); - console.log(this.urlElement, this.selectElement); if (this.selectElement) { this.prepareField(); this.registerEvents(); @@ -108,7 +106,6 @@ class LinkField { handleSelection(event) { event.stopPropagation(); event.preventDefault(); - console.log("handleSelection", event.target.textContent, event.target.getAttribute('data-href')); this.inputElement.value = event.target.getAttribute('data-text') || event.target.textContent; this.inputElement.classList.add('cms-linkfield-selected'); this.urlElement.value = event.target.getAttribute('data-href'); @@ -118,7 +115,6 @@ class LinkField { } handleChange(event) { - console.log("handleChange", event.target); if (this.selectElement.value) { fetch(this.options.url + '?g=' + encodeURIComponent(this.selectElement.value)) .then(response => response.json()) diff --git a/private/js/cms.texteditor.js b/private/js/cms.texteditor.js index 858c5bfa..0d3bdb5b 100644 --- a/private/js/cms.texteditor.js +++ b/private/js/cms.texteditor.js @@ -61,10 +61,7 @@ class CmsTextEditor { _blur (e) { this.save(e.target, (el, response) => { - console.log("timer set"); - console.log(response); setTimeout(() => { - console.log(e.target); if (e.target.dataset.changed === 'true') { e.target.innerText = this.options.undo; e.target.dataset.changed = 'false'; diff --git a/private/js/cms.tiptap.js b/private/js/cms.tiptap.js index 866c990f..39354c22 100644 --- a/private/js/cms.tiptap.js +++ b/private/js/cms.tiptap.js @@ -15,7 +15,7 @@ import TableCell from '@tiptap/extension-table-cell' import TableHeader from '@tiptap/extension-table-header' import TableRow from '@tiptap/extension-table-row' import { TextAlign, TextAlignOptions } from '@tiptap/extension-text-align'; -import CmsPluginNode from './tiptap_plugins/cms.plugin'; +import { CmsPluginNode, CmsBlockPluginNode } from './tiptap_plugins/cms.plugin'; import TiptapToolbar from "./tiptap_plugins/cms.tiptap.toolbar"; import {StarterKit} from "@tiptap/starter-kit"; @@ -55,6 +55,7 @@ class CMSTipTapPlugin { }), Small, Var, Kbd, Samp, CmsPluginNode, + CmsBlockPluginNode, TextAlign.configure({ types: ['heading', 'paragraph'], }), diff --git a/private/js/tiptap_plugins/cms.balloon-toolbar.js b/private/js/tiptap_plugins/cms.balloon-toolbar.js index c952ec2f..f807eac4 100644 --- a/private/js/tiptap_plugins/cms.balloon-toolbar.js +++ b/private/js/tiptap_plugins/cms.balloon-toolbar.js @@ -125,7 +125,7 @@ export default class CmsBalloonToolbar { this.toolbar.style.insetBlockStart = `${pos.top - ref.top}px`; // TODO: Set the size of the balloon according to the fontsize - // this.toolbar.style.setProperty('--size', this.editor.view. ...) + // this.toolbar.style.setProperty('--size', this.editor.view. ...) } _getResolvedPos() { @@ -142,7 +142,6 @@ export default class CmsBalloonToolbar { if (type in this._node_icons) { this.toolbar.innerHTML = this._node_icons[type]; } else { - console.log(type); this.toolbar.innerHTML = this._menu_icon; } } diff --git a/private/js/tiptap_plugins/cms.plugin.js b/private/js/tiptap_plugins/cms.plugin.js index 8c927308..964e6596 100644 --- a/private/js/tiptap_plugins/cms.plugin.js +++ b/private/js/tiptap_plugins/cms.plugin.js @@ -1,11 +1,26 @@ /* eslint-env es6 */ -/* jshint esversion: 6 */ +/* jshint esversion: 9 */ /* global document, window, console */ import { Node } from '@tiptap/core'; import CmsDialog from "../cms.dialog.js"; import TiptapToolbar from "./cms.tiptap.toolbar"; +const blockTags = ((x) => x.toUpperCase().substring(1, x.length-1).split("><"))( + "