From 6f2932ca5bfa8f1d726a8fd3de20a6264d46ff4e Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Tue, 17 Dec 2024 00:49:37 +0100 Subject: [PATCH] Add dynamic link fields --- djangocms_text_ckeditor5/__init__.py | 9 +- .../css/cms.ckeditor5.css | 0 .../css/cms.linkfield.css | 62 +++ .../js/ckeditor5_plugins/cms-link/index.js | 5 +- .../cms-link/src/autocomplete.js | 162 ------- .../cms-link/src/cms.linkfield.js | 188 ++++++++ .../ckeditor5_plugins/cms-link/src/cmsLink.js | 290 ++--------- .../cms-link/src/linksuggestionediting.js | 456 ++++++++---------- private/js/cms.ckeditor5.js | 15 +- webpack.config.js | 2 +- 10 files changed, 512 insertions(+), 677 deletions(-) rename djangocms_text_ckeditor5/static/{djangocms_text => djangocms_text_ckeditor5}/css/cms.ckeditor5.css (100%) create mode 100644 djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.linkfield.css delete mode 100644 private/js/ckeditor5_plugins/cms-link/src/autocomplete.js create mode 100644 private/js/ckeditor5_plugins/cms-link/src/cms.linkfield.js diff --git a/djangocms_text_ckeditor5/__init__.py b/djangocms_text_ckeditor5/__init__.py index ad6de06..59d76c4 100644 --- a/djangocms_text_ckeditor5/__init__.py +++ b/djangocms_text_ckeditor5/__init__.py @@ -7,7 +7,12 @@ ckeditor5 = RTEConfig( name="ckeditor5", config="CKEDITOR5", - js=("djangocms_text/bundles/bundle.ckeditor5.min.js",), - css={"all": ("djangocms_text/css/cms.ckeditor5.css",)}, + js=("djangocms_text_ckeditor5/bundles/bundle.ckeditor5.min.js",), + css={ + "all": ( + "djangocms_text_ckeditor5/css/cms.ckeditor5.css", + "djangocms_text_ckeditor5/css/cms.linkfield.css", + ) + }, inline_editing=True, ) diff --git a/djangocms_text_ckeditor5/static/djangocms_text/css/cms.ckeditor5.css b/djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.ckeditor5.css similarity index 100% rename from djangocms_text_ckeditor5/static/djangocms_text/css/cms.ckeditor5.css rename to djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.ckeditor5.css diff --git a/djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.linkfield.css b/djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.linkfield.css new file mode 100644 index 0000000..d875a67 --- /dev/null +++ b/djangocms_text_ckeditor5/static/djangocms_text_ckeditor5/css/cms.linkfield.css @@ -0,0 +1,62 @@ +.ck.ck-balloon-panel { + .cms-linkfield-wrapper { + font-size: 0.8rem; + position: relative; + input[type="text"] { + padding-inline-end: 3em; + background: var(--dca-white) url('data:image/svg+xml;utf8,') no-repeat inline-end center; + background-size: auto 1em; + } + .cms-linkfield-selected { + font-weight: bold; + } + .cms-linkfield-dropdown:not(:empty), .cms-linkfield-dropdown:active { + /* Hide dropdown when empty */ + visibility: visible; + } + .cms-linkfield-dropdown { + z-index: 1; + visibility: hidden; + position: absolute; + max-block-size: 400px; + overflow: auto; + inset-inline-start: 0; + inset-block-start: 100%; + border: 1px solid var(--dca-gray-lighter); + background: var(--dca-white); + inline-size: 120%; + resize: both; + border-end-start-radius: 4px; + border-end-end-radius: 4px; + box-shadow: 0 1.5px 1.5px rgba(var(--dca-shadow),.4); + .cms-linkfield-error { + color: red; + font-size: 0.8rem; + } + div { + padding: 0.3rem 6px; + white-space: nowrap; + font-weight: normal; + border-block-end: 1px solid var(--dca-gray-lighter); + &:last-child { + border-bottom: none; + } + &.cms-linkfield-parent { + font-weight: bold; + background: var(--dca-gray-lightest); + } + &.cms-linkfield-message { + font-style: italic; + color: var(--dca-gray); + } + &.cms-linkfield-option { + cursor: pointer; + } + &.cms-linkfield-option:hover { + background: var(--dca-primary); + color: var(--dca-white); + } + } + } + } +} diff --git a/private/js/ckeditor5_plugins/cms-link/index.js b/private/js/ckeditor5_plugins/cms-link/index.js index 47fbdbe..cfe56e5 100644 --- a/private/js/ckeditor5_plugins/cms-link/index.js +++ b/private/js/ckeditor5_plugins/cms-link/index.js @@ -2,6 +2,7 @@ /* jshint esversion: 6 */ // index.js -import CMSLinkPlugin from './src/cmsLinkPlugin'; +import CmsLink from './src/cmsLink'; +import LinkSuggestionsEditing from './src/linksuggestionediting'; -export default CMSLinkPlugin; +export { CmsLink, LinkSuggestionsEditing }; diff --git a/private/js/ckeditor5_plugins/cms-link/src/autocomplete.js b/private/js/ckeditor5_plugins/cms-link/src/autocomplete.js deleted file mode 100644 index a3a5007..0000000 --- a/private/js/ckeditor5_plugins/cms-link/src/autocomplete.js +++ /dev/null @@ -1,162 +0,0 @@ -const $ = jQuery; - -/** - * Override jQuery UI _renderItem function to output HTML by default. - * - * This uses function() syntax as required by jQuery UI. - * - * @param {object} ul - * The