From a6eb28175a6a996f58d94414e7f1c6a4bc67c622 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 17 Feb 2025 14:13:07 +0100 Subject: [PATCH] Revert backend to original state and load commentEditor vue app anytime CommentType form field is used --- .../Resources/views/Activity/new.html.twig | 10 ------ .../public/chill/scss/comment-editor.scss | 11 +++++-- .../public/module/ckeditor5/index.ts | 30 ++++++++++++------ .../public/vuejs/CommentEditor/App.vue | 7 ++--- .../CommentEditor/component/CommentEditor.vue | 5 +-- .../public/vuejs/CommentEditor/index.js | 31 ------------------- .../Resources/views/Form/fields.html.twig | 8 +++-- 7 files changed, 40 insertions(+), 62 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig index 52c3da56d..8590d79b9 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig @@ -84,16 +84,6 @@ {{ form_row(form.comment) }} {% endif %} -
- -
-
- -
- -
-
- {%- if form.privateComment is defined -%} {{ form_row(form.privateComment) }} {% endif %} diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/comment-editor.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/comment-editor.scss index e30326e48..f0411baff 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/comment-editor.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/comment-editor.scss @@ -3,12 +3,20 @@ } .toggle-button { + background-color: white; + font-size: .8rem; + text-decoration: none; position: absolute; bottom: -10px; - left: 10px; + left: 20px; padding: 2px 6px; cursor: pointer; z-index: 10; + transition: left 0.1s ease-in-out; +} + +.rich-editor-active .toggle-button { + bottom: 0; } .editor-wrapper textarea { @@ -20,7 +28,6 @@ position: relative; display: flex; flex-direction: column; - width: 100%; } .editor-wrapper { diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/ckeditor5/index.ts b/src/Bundle/ChillMainBundle/Resources/public/module/ckeditor5/index.ts index 9b849c8f7..6d0597b78 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/ckeditor5/index.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/module/ckeditor5/index.ts @@ -1,13 +1,23 @@ -import config from "./editor_config"; -import {ClassicEditor} from "ckeditor5"; +import App from "../../vuejs/CommentEditor/App.vue" +import { createApp, reactive } from "vue"; const ckeditorFields: NodeListOf = - document.querySelectorAll("textarea[ckeditor]"); -ckeditorFields.forEach((field: HTMLTextAreaElement): void => { - ClassicEditor.create(field, config) - .catch((error) => { - console.error(error.stack); - throw error; - }); + document.querySelectorAll(".vue-comment-editor"); + +const globalState = reactive({ + isSimple: localStorage.getItem('editorMode') === 'simple' +}); +window.addEventListener('storage', () => { + globalState.isSimple = localStorage.getItem('editorMode') === 'simple'; +}); + +ckeditorFields.forEach((field: HTMLTextAreaElement): void => { + console.log('field', field) + const app = createApp({ + template: `` + }); + + app.provide('globalState', globalState) + .component("app", App) + .mount(field); }); -//Fields.push.apply(Fields, document.querySelectorAll('.cf-fields textarea')); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue index 4a42427d8..34eec1a0f 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue @@ -14,18 +14,15 @@ export default defineComponent({ name: "App", components: { CommentEditor }, setup() { + console.log('im loaded') const globalState = inject('globalState'); - const fieldName = inject('fieldName') const toggleEditorMode = () => { globalState.isSimple = !globalState.isSimple; localStorage.setItem('editorMode', globalState.isSimple ? 'simple' : 'rich'); }; const handleChange = (newContent) => { - const hiddenField = document.querySelector(`input[name="${fieldName}"]`); - if (hiddenField) { - hiddenField.value = newContent || ''; - } + console.log(newContent) }; return { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue index 427883eb4..893fa0a23 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue @@ -1,5 +1,5 @@ @@ -38,6 +38,7 @@ export default defineComponent({ isSimple: Boolean, }, setup(props, { emit }) { + console.log("im loaded too") const { isSimple } = toRefs(props); const content = ref(""); const classicEditor = ClassicEditor; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js deleted file mode 100644 index f543a27fb..000000000 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js +++ /dev/null @@ -1,31 +0,0 @@ -import { createApp, reactive } from "vue"; -import App from "./App.vue"; -import {_createI18n} from "ChillMainAssets/vuejs/_js/i18n"; -import { appMessages } from "ChillMainAssets/vuejs/CommentEditor/i18n"; - -const i18n = _createI18n(appMessages); - -// Global reactive state to handle editorMode -const globalState = reactive({ - isSimple: localStorage.getItem('editorMode') === 'simple' -}); - -// Watch for changes to `localStorage` and update the state -window.addEventListener('storage', () => { - globalState.isSimple = localStorage.getItem('editorMode') === 'simple'; -}); - -const commentWidgets = document.querySelectorAll('[id^="comment-widget"]'); -commentWidgets.forEach((commentContainer) => { - const app = createApp({ - template: `` - }); - - const fieldName = commentContainer.dataset.fieldname; - - app.use(i18n) - .provide('globalState', globalState) - .provide( 'fieldName', fieldName) - .component("app", App) - .mount(commentContainer); -}); diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 15794b9f7..30230005e 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -214,7 +214,9 @@ {% block private_comment_widget %} {% for entry in form %} - {{ form_widget(entry) }} +
+ {{ form_widget(entry, { attr: { ckeditor: 'true' } }) }} +
{% endfor %} {% endblock %} @@ -224,7 +226,9 @@ {% block comment_widget %} {% for entry in form %} - {{ form_widget(entry) }} +
+ {{ form_widget(entry, { attr: { ckeditor: 'true' } }) }} +
{% endfor %} {% endblock comment_widget %}