Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allows an admin_css: tuple in RTEConfig for a list of CSS files only to be loaded into the admin for the editor #49

Merged
merged 5 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions djangocms_text/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion djangocms_text/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ def __init__(
config: str,
js: Iterable[str] = None,
css: dict = None,
admin_css: dict = None,
fsbraun marked this conversation as resolved.
Show resolved Hide resolved
inline_editing: bool = False,
child_plugin_support: bool = False,
):
Expand All @@ -446,6 +447,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

Expand Down Expand Up @@ -510,7 +512,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,
)
Expand Down
2 changes: 1 addition & 1 deletion djangocms_text/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion djangocms_text/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading