Skip to content

Commit

Permalink
fix: Ensure styles are loaded for text-enabled dialog (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun authored Aug 28, 2024
1 parent 091239e commit 6a76c81
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 190 deletions.
26 changes: 9 additions & 17 deletions djangocms_text/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
import operator
import re

from cms.utils import get_language_from_request
from django.apps import apps
from django.contrib.admin.utils import unquote
from django.core import signing
from django.core.exceptions import PermissionDenied, ValidationError
from django.db import transaction
from django.forms.fields import CharField
from django.http import (
Http404,
HttpResponse,
HttpResponseBadRequest,
HttpResponseForbidden,
HttpResponseRedirect, JsonResponse,
Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect, JsonResponse,
)
from django.shortcuts import get_object_or_404
from django.template import RequestContext
Expand All @@ -26,12 +21,16 @@
from django.views.decorators.http import require_POST

from cms.models import CMSPlugin, Page
from cms.utils import get_language_from_request

from .settings import TEXT_CHILDREN_ENABLED


try:
from cms.models import PageContent
except ImportError:
from cms.models import Title as PageContent

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.utils.placeholder import get_placeholder_conf
Expand All @@ -42,15 +41,8 @@
from .html import render_dynamic_attributes
from .models import Text
from .utils import (
OBJ_ADMIN_WITH_CONTENT_RE_PATTERN,
_plugin_tags_to_html,
cms_placeholder_add_plugin,
plugin_tags_to_admin_html,
plugin_tags_to_id_list,
plugin_tags_to_user_html,
plugin_to_tag,
random_comment_exempt,
replace_plugin_tags,
OBJ_ADMIN_WITH_CONTENT_RE_PATTERN, _plugin_tags_to_html, cms_placeholder_add_plugin, plugin_tags_to_admin_html,
plugin_tags_to_id_list, plugin_tags_to_user_html, plugin_to_tag, random_comment_exempt, replace_plugin_tags,
)
from .widgets import TextEditorWidget, rte_config

Expand Down Expand Up @@ -572,7 +564,7 @@ def get_child_plugin_candidates(cls, slot, page):
page=page,
)
# Filter out plugins that are not in the whitelist if given
if settings.TEXT_CHILDREN_WHITELIST:
if settings.TEXT_CHILDREN_WHITELIST is not None:
text_enabled_plugins = [
plugin
for plugin in text_enabled_plugins
Expand All @@ -597,7 +589,7 @@ def render_plugin_icon(self, plugin):

def get_plugins(self, obj=None):
plugin = getattr(self, "cms_plugin_instance", None) or obj
if not plugin:
if not plugin or not TEXT_CHILDREN_ENABLED:
return []
get_plugin = plugin_pool.get_plugin
child_plugin_types = self.get_child_classes(
Expand Down
4 changes: 2 additions & 2 deletions djangocms_text/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IconButton(Button):
class InlineEditingToolbar(CMSToolbar):
@property
def media(self):
if self.toolbar.edit_mode_active and self.inline_editing:
if self.toolbar.edit_mode_active:
return forms.Media(
css={
**rte_config.css,
Expand All @@ -33,7 +33,7 @@ def media(self):
js=(
static("djangocms_text/bundles/bundle.editor.min.js"),
*(static(js) for js in rte_config.js),
),
) if self.inline_editing else (),
)
return forms.Media()

Expand Down
1 change: 1 addition & 0 deletions djangocms_text/contrib/text_ckeditor4/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from djangocms_text.editors import RTEConfig


ckeditor4 = RTEConfig(
name="ckeditor4",
config="CKEDITOR",
Expand Down
1 change: 1 addition & 0 deletions djangocms_text/contrib/text_ckeditor5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from djangocms_text.editors import RTEConfig


ckeditor5 = RTEConfig(
name="ckeditor5",
config="CKEDITOR5",
Expand Down
9 changes: 3 additions & 6 deletions djangocms_text/editors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from typing import Iterable, Optional

from django.conf import settings


from django.utils.translation import gettext_lazy as _

from django.utils.functional import Promise
from django.utils.encoding import force_str
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.encoding import force_str
from django.utils.functional import Promise
from django.utils.translation import gettext_lazy as _


class LazyEncoder(DjangoJSONEncoder):
Expand Down
5 changes: 2 additions & 3 deletions djangocms_text/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from copy import deepcopy
from typing import Optional, Union

import nh3
from django.apps import apps
from lxml import etree

from django.db import models

import nh3
from lxml import etree
from lxml.etree import Element

from . import settings
Expand Down
7 changes: 1 addition & 6 deletions djangocms_text/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

from . import settings
from .html import clean_html, extract_images
from .utils import (
plugin_tags_to_db,
plugin_tags_to_id_list,
plugin_to_tag,
replace_plugin_tags,
)
from .utils import plugin_tags_to_db, plugin_tags_to_id_list, plugin_to_tag, replace_plugin_tags


try:
Expand Down
2 changes: 1 addition & 1 deletion djangocms_text/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@

TEXT_INLINE_EDITING = getattr(settings, "TEXT_INLINE_EDITING", False)
TEXT_CHILDREN_ENABLED = getattr(settings, "TEXT_CHILDREN_ENABLED", True)
TEXT_CHILDREN_WHITELIST = getattr(settings, "TEXT_CHILDREN_WHITELIST", [])
TEXT_CHILDREN_WHITELIST = getattr(settings, "TEXT_CHILDREN_WHITELIST", None)
TEXT_CHILDREN_BLACKLIST = getattr(settings, "TEXT_CHILDREN_BLACKLIST", [])
152 changes: 152 additions & 0 deletions djangocms_text/static/djangocms_text/css/cms.text.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,155 @@
display: none;
}
}


#cms-top dialog.cms-dialog {
padding: 0;
resize: both;
top: 50%;
left: 50%;
inset-inline-start: 50%;
inset-inline-end: unset;
transform: translate(calc(-50% + 250px), calc(-50% + 121px));
width: 32rem;
height: 24rem;
min-height: 16rem;
min-width: 16rem;
.cms-modal-foot {
margin-inline-end: 1rem;
.cms-modal-buttons {
padding-inline-end: 10px;
}
}
.cms-modal-body iframe {
width: 100%;
height: 100%;
border: none;
}
}

[dir="rtl"] dialog.cms-dialog {
inset-inline-start: unset;
inset-inline-end: 50%;
}

dialog.cms-form-dialog {
&::before {
position: absolute;
background: var(--dca-white);
border: 1px solid var(--dca-gray-light);
box-shadow: 0 0 10px rgba(var(--dca-shadow), .25);
height: 10px;
width: 10px;
left: 24px;
top: 8px;
transform: rotate(-135deg);
transform-origin: 0 0;
content: "";
}
&.right::before {
right: 24px;
left: auto;
}
&::after {
position: absolute;
background: var(--dca-white);
height: 10px;
left: 10px;
top: 0;
width: 40px;
content: "";
}
&.right::after {
right: 10px;
left: auto;
}
.dropback {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
cursor: unset; /* browser default */
}
z-index: 1001;
position: fixed;
margin: unset;
left: auto;
transform: translate(-50%, -50%);
min-width: 200px;
padding: 10px 15px;
background-color: var(--dca-white);
border: 1px solid var(--dca-gray-light);
border-radius: 5px;
box-shadow: 0 0 10px rgba(var(--dca-shadow), .25);
form {
display: flex;
flex-flow: row;
justify-content: space-between;
align-content: baseline;
align-items: center;
}
.cancel {
display: inline-flex;
color: #f00;
margin-left: 0.5em;
margin-right: 0.5em;
cursor: pointer;
}
.submit {
display: inline-flex;
color: #693;
cursor: pointer;
}
}


form.cms-form {
display: flex;
flex-flow: row;
justify-content: space-between;
align-content: baseline;
align-items: center;
text-align: start;
zoom: 1;
input, select {
min-width: 200px;
width: 100%;
margin-bottom: 3px;
font-size: 0.8rem;
min-height: 1rem;
line-height: unset;
height: unset;
padding: 3px 6px !important;
}
select { /* !important for djangocms-admin-style */
background: var(--dca-white) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="16" fill="%23808080" viewBox="0 0 16 16"><path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"/></svg>') no-repeat right center !important;
background-size: auto 1em !important;
appearance: none;
}
label {
font-size: 0.7rem;
padding-bottom: 4px;
}
hr {
margin: 0.3em -1em;
}
.cms-form-buttons {
display: inline-flex;
margin-inline-start: 1em;
.cancel {
color: #f00;
cursor: pointer;
zoom: 1.2;
}
.submit {
margin-left: 0.5em;
margin-right: 0.5em;
color: #693;
cursor: pointer;
zoom: 1.2;
}
}
}
5 changes: 3 additions & 2 deletions djangocms_text/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from cms.utils.urlutils import admin_reverse, static_with_version

from . import settings as text_settings
from .editors import DEFAULT_TOOLBAR_CMS, DEFAULT_TOOLBAR_HTMLField, LazyEncoder, get_editor_base_config
from .editors import get_editor_config
from .editors import (
DEFAULT_TOOLBAR_CMS, DEFAULT_TOOLBAR_HTMLField, LazyEncoder, get_editor_base_config, get_editor_config,
)
from .utils import cms_placeholder_add_plugin


Expand Down
Loading

0 comments on commit 6a76c81

Please sign in to comment.