diff --git a/djangocms_text/cms_plugins.py b/djangocms_text/cms_plugins.py index 543d5ca..16123a2 100644 --- a/djangocms_text/cms_plugins.py +++ b/djangocms_text/cms_plugins.py @@ -249,6 +249,7 @@ def get_editor_widget(self, request, plugins, plugin): action_token=action_token, revert_on_cancel=settings.TEXT_CHILDREN_ENABLED and rte_config.child_plugin_support, body_css_classes=self._get_body_css_classes_from_parent_plugins(plugin), + add_admin_css=True, ) else: widget = TextEditorWidget( diff --git a/djangocms_text/editors.py b/djangocms_text/editors.py index ae2f44a..b7fdffb 100644 --- a/djangocms_text/editors.py +++ b/djangocms_text/editors.py @@ -1,4 +1,5 @@ -from typing import Optional +from __future__ import annotations + from collections.abc import Iterable from django.conf import settings @@ -436,8 +437,9 @@ def __init__( self, name: str, config: str, - js: Iterable[str] = None, - css: dict = None, + js: Iterable[str] | None = None, + css: dict | None = None, + admin_css: dict | None = None, inline_editing: bool = False, child_plugin_support: bool = False, ): @@ -446,6 +448,7 @@ def __init__( self.config = config self.js = js or [] self.css = css or {} + self.admin_css = admin_css or () self.inline_editing = inline_editing self.child_plugin_support = child_plugin_support @@ -474,7 +477,7 @@ def register(editor: RTEConfig): configuration[editor.name] = editor -def get_editor_config(editor: Optional[str] = None) -> RTEConfig: +def get_editor_config(editor: str | None = None) -> RTEConfig: """ Returns the editor configuration. @@ -494,7 +497,7 @@ def get_editor_config(editor: Optional[str] = None) -> RTEConfig: return configuration[config_name] -def get_editor_base_config(editor: Optional[str] = None) -> dict: +def get_editor_base_config(editor: str | None = None) -> dict: """ Returns the base configuration for the editor. @@ -510,7 +513,8 @@ def get_editor_base_config(editor: Optional[str] = None) -> dict: name="tiptap", config="TIPTAP", js=("djangocms_text/bundles/bundle.tiptap.min.js",), - css={"all": ("djangocms_text/css/bundle.tiptap.min.css", "djangocms_text/css/tiptap.admin.css")}, + css={"all": ("djangocms_text/css/bundle.tiptap.min.css",)}, + admin_css=("djangocms_text/css/tiptap.admin.css",), inline_editing=True, child_plugin_support=True, ) diff --git a/djangocms_text/fields.py b/djangocms_text/fields.py index a7fa5df..b8fb995 100644 --- a/djangocms_text/fields.py +++ b/djangocms_text/fields.py @@ -65,7 +65,7 @@ def formfield(self, **kwargs): # override the admin widget if defaults["widget"] == admin_widgets.AdminTextareaWidget: # In the admin the URL endpoint is available - defaults["widget"] = TextEditorWidget(configuration=self.configuration) + defaults["widget"] = TextEditorWidget(configuration=self.configuration, add_admin_css=True) return super().formfield(**defaults) def clean(self, value, model_instance): diff --git a/djangocms_text/widgets.py b/djangocms_text/widgets.py index 4c18b38..1ff3fe2 100644 --- a/djangocms_text/widgets.py +++ b/djangocms_text/widgets.py @@ -88,13 +88,16 @@ class TextEditorWidget(forms.Textarea): @property def media(self): rte_config = get_editor_config() + rte_css = rte_config.css.get("all", ()) + if self.add_admin_css: + rte_css += rte_config.admin_css return forms.Media( css={ **rte_config.css, "all": ( "djangocms_text/css/cms.text.css", "djangocms_text/css/cms.normalize.css", - *rte_config.css.get("all", ()), + *rte_css, ), }, js=( @@ -120,6 +123,7 @@ def __init__( action_token: str = None, revert_on_cancel: bool = False, body_css_classes: str = "", + add_admin_css: bool = False, ): """ Create a widget for editing text + plugins. @@ -156,6 +160,7 @@ def __init__( self.action_token = action_token # specific self.revert_on_cancel = revert_on_cancel self.body_css_classes = body_css_classes if body_css_classes else self.configuration.get("bodyClass", "") + self.add_admin_css = add_admin_css def render_textarea(self, name, value, attrs=None, renderer=None): return super().render(name, value, attrs, renderer)