Skip to content

Commit

Permalink
feat: Add text-enabled support by rte
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Sep 29, 2024
1 parent 6b95de9 commit c76c951
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 38 deletions.
7 changes: 4 additions & 3 deletions djangocms_text/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_editor_widget(self, request, plugins, plugin):
render_plugin_url=render_plugin_url,
cancel_url=cancel_url,
action_token=action_token,
revert_on_cancel=settings.TEXT_CHILDREN_ENABLED,
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),
)
else:
Expand Down Expand Up @@ -353,7 +353,7 @@ def add_view(self, request, form_url="", extra_context=None):
# CMS >= 3.4 compatibility
self.cms_plugin_instance = self._get_plugin_or_404(request.GET["plugin"])

if not settings.TEXT_CHILDREN_ENABLED or getattr(
if not settings.TEXT_CHILDREN_ENABLED or not rte_config.child_plugin_support or getattr(
self, "cms_plugin_instance", None
):
# This can happen if the user did not properly cancel the plugin
Expand Down Expand Up @@ -601,7 +601,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 or not TEXT_CHILDREN_ENABLED:
if not plugin or not TEXT_CHILDREN_ENABLED or not rte_config.child_plugin_support:
return []
get_plugin = plugin_pool.get_plugin
child_plugin_types = self.get_child_classes(
Expand Down Expand Up @@ -653,6 +653,7 @@ def get_render_template(self, context, instance, placeholder):
def inline_editing_active(request):
return (
settings.TEXT_INLINE_EDITING
and rte_config.inline_editing
and hasattr(request, "toolbar")
and request.toolbar.edit_mode_active
and request.session.get("inline_editing", True)
Expand Down
2 changes: 1 addition & 1 deletion djangocms_text/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ def get_full_path_with_param(self, key, value):
return urlunparse(url)


if settings.TEXT_INLINE_EDITING: # Only register if explicitly required from settings
if settings.TEXT_INLINE_EDITING and rte_config.inline_editing: # Only register if explicitly required from settings
toolbar_pool.register(InlineEditingToolbar)
6 changes: 4 additions & 2 deletions djangocms_text/contrib/text_ckeditor4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
config="CKEDITOR",
js=(
"djangocms_text/vendor/ckeditor4/ckeditor.js",
"djangocms_text/bundles/bundle.ckeditor5.min.js",
"djangocms_text/bundles/bundle.ckeditor4.min.js",
),
css={"all": ("djangocms_text/css/cms.ckeditor5.css",)},
css={"all": ("djangocms_text/css/cms.ckeditor4.css",)},
inline_editing=True,
child_plugin_support=True,
)
73 changes: 41 additions & 32 deletions djangocms_text/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,36 @@ def default(self, obj):
"editLabel": _("Edit CMS Plugin"),
"addLabel": _("Add CMS Plugin"),
"icon": '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" '
'class="bi bi-puzzle" viewBox="0 0 16 16"><path d="M3.112 3.645A1.5 1.5 0 0 1 4.605 '
'2H7a.5.5 0 0 1 .5.5v.382c0 .696-.497 1.182-.872 1.469a.5.5 0 0 0-.115.118l-.012.025L6.5 '
'4.5v.003l.003.01q.005.015.036.053a.9.9 0 0 0 .27.194C7.09 4.9 7.51 5 8 5c.492 0 '
'.912-.1 1.19-.24a.9.9 0 0 0 .271-.194.2.2 0 0 0 .039-.063v-.009l-.012-.025a.5.5 0 0 '
'0-.115-.118c-.375-.287-.872-.773-.872-1.469V2.5A.5.5 0 0 1 9 2h2.395a1.5 1.5 0 0 1 '
'1.493 1.645L12.645 6.5h.237c.195 0 .42-.147.675-.48.21-.274.528-.52.943-.52.568 0 '
'.947.447 1.154.862C15.877 6.807 16 7.387 16 8s-.123 1.193-.346 '
'1.638c-.207.415-.586.862-1.154.862-.415 0-.733-.246-.943-.52-.255-.333-.48-.48-.675-.48h-.237l.243 '
'2.855A1.5 1.5 0 0 1 11.395 14H9a.5.5 0 0 1-.5-.5v-.382c0-.696.497-1.182.872-1.469a.5.5 0 0 0 '
'.115-.118l.012-.025.001-.006v-.003a.2.2 0 0 0-.039-.064.9.9 0 0 0-.27-.193C8.91 11.1 8.49 11 '
'8 11s-.912.1-1.19.24a.9.9 0 0 0-.271.194.2.2 0 0 '
'0-.039.063v.003l.001.006.012.025c.016.027.05.068.115.118.375.287.872.773.872 1.469v.382a.5.5 '
'0 0 1-.5.5H4.605a1.5 1.5 0 0 1-1.493-1.645L3.356 9.5h-.238c-.195 0-.42.147-.675.48-.21.274'
'-.528.52-.943.52-.568 0-.947-.447-1.154-.862C.123 9.193 0 8.613 0 8s.123-1.193.346-1.638C.553 '
'5.947.932 5.5 1.5 5.5c.415 0 .733.246.943.52.255.333.48.48.675.48h.238zM4.605 3a.5.5 0 0 '
'0-.498.55l.001.007.29 3.4A.5.5 0 0 1 3.9 7.5h-.782c-.696 0-1.182-.497-1.469-.872a.5.5 0 0 '
'0-.118-.115l-.025-.012L1.5 6.5h-.003a.2.2 0 0 0-.064.039.9.9 0 0 0-.193.27C1.1 7.09 1 7.51 1 '
'8s.1.912.24 1.19c.07.14.14.225.194.271a.2.2 0 0 0 .063.039H1.5l.006-.001.025-.012a.5.5 0 0 0 '
'.118-.115c.287-.375.773-.872 1.469-.872H3.9a.5.5 0 0 1 .498.542l-.29 3.408a.5.5 0 0 0 '
'.497.55h1.878c-.048-.166-.195-.352-.463-.557-.274-.21-.52-.528-.52-.943 '
'0-.568.447-.947.862-1.154C6.807 10.123 7.387 10 8 10s1.193.123 1.638.346c.415.207.862.586.862 '
'1.154 0 .415-.246.733-.52.943-.268.205-.415.39-.463.557h1.878a.5.5 0 0 0 '
'.498-.55l-.001-.007-.29-3.4A.5.5 0 0 1 12.1 8.5h.782c.696 0 1.182.497 '
'1.469.872.05.065.091.099.118.115l.025.012.006.001h.003a.2.2 0 0 0 .064-.039.9.9 0 0 0 '
'.193-.27c.14-.28.24-.7.24-1.191s-.1-.912-.24-1.19a.9.9 0 0 0-.194-.271.2.2 0 0 '
'0-.063-.039H14.5l-.006.001-.025.012a.5.5 0 0 0-.118.115c-.287.375-.773.872-1.469.872H12.1a.5.5 0 0 '
'1-.498-.543l.29-3.407a.5.5 0 0 0-.497-.55H9.517c.048.166.195.352.463.557.274.21.52.528.52.943 0 '
'.568-.447.947-.862 1.154C9.193 5.877 8.613 6 8 6s-1.193-.123-1.638-.346C5.947 5.447 5.5 5.068 5.5 '
'4.5c0-.415.246-.733.52-.943.268-.205.415-.39.463-.557z"/></svg>',
}
'class="bi bi-puzzle" viewBox="0 0 16 16"><path d="M3.112 3.645A1.5 1.5 0 0 1 4.605 '
"2H7a.5.5 0 0 1 .5.5v.382c0 .696-.497 1.182-.872 1.469a.5.5 0 0 0-.115.118l-.012.025L6.5 "
"4.5v.003l.003.01q.005.015.036.053a.9.9 0 0 0 .27.194C7.09 4.9 7.51 5 8 5c.492 0 "
".912-.1 1.19-.24a.9.9 0 0 0 .271-.194.2.2 0 0 0 .039-.063v-.009l-.012-.025a.5.5 0 0 "
"0-.115-.118c-.375-.287-.872-.773-.872-1.469V2.5A.5.5 0 0 1 9 2h2.395a1.5 1.5 0 0 1 "
"1.493 1.645L12.645 6.5h.237c.195 0 .42-.147.675-.48.21-.274.528-.52.943-.52.568 0 "
".947.447 1.154.862C15.877 6.807 16 7.387 16 8s-.123 1.193-.346 "
"1.638c-.207.415-.586.862-1.154.862-.415 0-.733-.246-.943-.52-.255-.333-.48-.48-.675-.48h-.237l.243 "
"2.855A1.5 1.5 0 0 1 11.395 14H9a.5.5 0 0 1-.5-.5v-.382c0-.696.497-1.182.872-1.469a.5.5 0 0 0 "
".115-.118l.012-.025.001-.006v-.003a.2.2 0 0 0-.039-.064.9.9 0 0 0-.27-.193C8.91 11.1 8.49 11 "
"8 11s-.912.1-1.19.24a.9.9 0 0 0-.271.194.2.2 0 0 "
"0-.039.063v.003l.001.006.012.025c.016.027.05.068.115.118.375.287.872.773.872 1.469v.382a.5.5 "
"0 0 1-.5.5H4.605a1.5 1.5 0 0 1-1.493-1.645L3.356 9.5h-.238c-.195 0-.42.147-.675.48-.21.274"
"-.528.52-.943.52-.568 0-.947-.447-1.154-.862C.123 9.193 0 8.613 0 8s.123-1.193.346-1.638C.553 "
"5.947.932 5.5 1.5 5.5c.415 0 .733.246.943.52.255.333.48.48.675.48h.238zM4.605 3a.5.5 0 0 "
"0-.498.55l.001.007.29 3.4A.5.5 0 0 1 3.9 7.5h-.782c-.696 0-1.182-.497-1.469-.872a.5.5 0 0 "
"0-.118-.115l-.025-.012L1.5 6.5h-.003a.2.2 0 0 0-.064.039.9.9 0 0 0-.193.27C1.1 7.09 1 7.51 1 "
"8s.1.912.24 1.19c.07.14.14.225.194.271a.2.2 0 0 0 .063.039H1.5l.006-.001.025-.012a.5.5 0 0 0 "
".118-.115c.287-.375.773-.872 1.469-.872H3.9a.5.5 0 0 1 .498.542l-.29 3.408a.5.5 0 0 0 "
".497.55h1.878c-.048-.166-.195-.352-.463-.557-.274-.21-.52-.528-.52-.943 "
"0-.568.447-.947.862-1.154C6.807 10.123 7.387 10 8 10s1.193.123 1.638.346c.415.207.862.586.862 "
"1.154 0 .415-.246.733-.52.943-.268.205-.415.39-.463.557h1.878a.5.5 0 0 0 "
".498-.55l-.001-.007-.29-3.4A.5.5 0 0 1 12.1 8.5h.782c.696 0 1.182.497 "
"1.469.872.05.065.091.099.118.115l.025.012.006.001h.003a.2.2 0 0 0 .064-.039.9.9 0 0 0 "
".193-.27c.14-.28.24-.7.24-1.191s-.1-.912-.24-1.19a.9.9 0 0 0-.194-.271.2.2 0 0 "
"0-.063-.039H14.5l-.006.001-.025.012a.5.5 0 0 0-.118.115c-.287.375-.773.872-1.469.872H12.1a.5.5 0 0 "
"1-.498-.543l.29-3.407a.5.5 0 0 0-.497-.55H9.517c.048.166.195.352.463.557.274.21.52.528.52.943 0 "
".568-.447.947-.862 1.154C9.193 5.877 8.613 6 8 6s-1.193-.123-1.638-.346C5.947 5.447 5.5 5.068 5.5 "
'4.5c0-.415.246-.733.52-.943.268-.205.415-.39.463-.557z"/></svg>',
},
}

DEFAULT_TOOLBAR_CMS = [
Expand Down Expand Up @@ -382,13 +382,21 @@ class RTEConfig:
"""

def __init__(
self, name: str, config: str, js: Iterable[str] = None, css: dict = None
self,
name: str,
config: str,
js: Iterable[str] = None,
css: dict = None,
inline_editing: bool = False,
child_plugin_support: bool = False,
):
""" """
self.name = name
self.config = config
self.js = js or []
self.css = css or {}
self.inline_editing = inline_editing
self.child_plugin_support = child_plugin_support

def process_base_config(self, base_config: dict) -> dict:
"""
Expand Down Expand Up @@ -452,6 +460,7 @@ def get_editor_base_config(editor: Optional[str] = None) -> dict:
config="TIPTAP",
js=("djangocms_text/bundles/bundle.tiptap.min.js",),
css={"all": ("djangocms_text/css/bundle.tiptap.min.css",)},
inline_editing=True,
child_plugin_support=True,
)
)

0 comments on commit c76c951

Please sign in to comment.