OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
moved ckeditor code as requested by @oliverguenther
Jonas Jabari0481ed3aee04
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.tsindex 5ddd211c826..5857b0b8e30 100644--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts@@ -26,7 +26,7 @@// See COPYRIGHT and LICENSE files for more details.//++-import { ChangeDetectionStrategy, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';+import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, OnInit, ViewChild } from '@angular/core';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';@@ -72,6 +72,15 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl@Input() public showAttachments = true;+ // Output save requests (ctrl+enter and cmd+enter)+ @Output() saveRequested = new EventEmitter<string>();++ // Output keyup events+ @Output() editorKeyup = new EventEmitter<void>();++ // Output blur events+ @Output() editorBlur = new EventEmitter<void>();+// Which template to includepublic element:HTMLElement;@@ -159,6 +168,7 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl}public async saveForm(evt?:SubmitEvent):Promise<void> {+ this.saveRequested.emit(); // Provide a hook for the parent component to do something before the form is submittedthis.inFlight = true;this.syncToTextarea();@@ -180,6 +190,8 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl});}++public setup(editor:ICKEditorInstance) {// Have a hacky way to access the editor from outside of angular.// This is e.g. employed to set the text from outside to reuse the same editor for different languages.diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.htmlindex 771c286e38f..fa8ffc51dc5 100644--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html@@ -5,6 +5,8 @@(initializeDone)="setup($event)"(contentChanged)="markEdited()"(saveRequested)="saveForm()"+ (editorKeyup)="editorKeyup.emit()"+ (editorBlur)="editorBlur.emit()"></op-ckeditor></div>diff --git a/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.tsindex d3e3ba883b0..e1716d82a2a 100644--- a/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts+++ b/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts@@ -71,6 +71,12 @@ export class OpCkeditorComponent extends UntilDestroyedMixin implements OnInit,// Output save requests (ctrl+enter and cmd+enter)@Output() saveRequested = new EventEmitter<string>();+ // Output key up events+ @Output() editorKeyup = new EventEmitter<string>();++ // Output blur events+ @Output() editorBlur = new EventEmitter<string>();+// View container of the replacement used to initialize CKEditor5@ViewChild('opCkeditorReplacementContainer', { static: true }) opCkeditorReplacementContainer:ElementRef;@@ -235,6 +241,12 @@ export class OpCkeditorComponent extends UntilDestroyedMixin implements OnInit,// Capture CTRL+ENTER commandsthis.interceptModifiedEnterKeystrokes(editor);+ // Capture and emit key up events+ this.interceptKeyup(editor);++ // Capture and emit blur events+ this.interceptBlur(editor);+// Emit global dragend events for other drop zones to react.// This is needed, as CKEditor does not bubble any drag eventsconst model = watchdog.editor.model;@@ -257,13 +269,44 @@ export class OpCkeditorComponent extends UntilDestroyedMixin implements OnInit,if ((data.ctrlKey || data.metaKey) && data.keyCode === KeyCodes.ENTER) {debugLog('Sending save request from CKEditor.');this.saveRequested.emit();- // evt.stop();+ evt.stop();}},{ priority: 'highest' },);}+ private interceptKeyup(editor:ICKEditorInstance) {+ editor.listenTo(+ editor.editing.view.document,+ 'keyup',+ (event) => {+ this.editorKeyup.emit();+ event.stop();+ },+ { priority: 'highest' },+ );+ }++ private interceptBlur(editor:ICKEditorInstance) {+ editor.listenTo(+ editor.editing.view.document,+ 'change:isFocused',+ () => {+ // without the timeout `isFocused` is still true even if the editor was blurred+ // current limitation:+ // clicking on empty toolbar space and the somewhere else on the page does not trigger the blur anymore+ setTimeout(() => {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ if (!editor.ui.focusTracker.isFocused) {+ this.editorBlur.emit();+ }+ }, 0);+ },+ { priority: 'highest' },+ );+ }+/*** Disable the manual mode, kill the codeMirror instance and switch back to CKEditor*/diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.tsindex cafa4dc7bb3..e2176862308 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts@@ -3,7 +3,6 @@ import { Controller } from '@hotwired/stimulus';import {ICKEditorInstance,} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';-import { KeyCodes } from 'core-app/shared/helpers/keyCodes.enum';interface CustomEventWithIdParam extends Event {params:{@@ -42,6 +41,10 @@ export default class IndexController extends Controller {private handleVisibilityChangeBound:EventListener;private rescueEditorContentBound:EventListener;+ private onSubmitBound:EventListener;+ private adjustMarginBound:EventListener;+ private hideEditorBound:EventListener;+connect() {this.setLocalStorageKey();this.setLastUpdateTimestamp();@@ -64,9 +67,9 @@ export default class IndexController extends Controller {}private setupEventListeners() {- this.handleWorkPackageUpdateBound = this.handleWorkPackageUpdate.bind(this);- this.handleVisibilityChangeBound = this.handleVisibilityChange.bind(this);- this.rescueEditorContentBound = this.rescueEditorContent.bind(this);+ this.handleWorkPackageUpdateBound = () => { void this.handleWorkPackageUpdate(); };+ this.handleVisibilityChangeBound = () => { void this.handleVisibilityChange(); };+ this.rescueEditorContentBound = () => { void this.rescueEditorContent(); };document.addEventListener('work-package-updated', this.handleWorkPackageUpdateBound);document.addEventListener('visibilitychange', this.handleVisibilityChangeBound);@@ -101,7 +104,7 @@ export default class IndexController extends Controller {return window.setInterval(() => this.updateActivitiesList(), this.pollingIntervalInMsValue);}- handleWorkPackageUpdate(_event:Event):void {+ handleWorkPackageUpdate(_event?:Event):void {setTimeout(() => this.updateActivitiesList(), 2000);}@@ -186,8 +189,12 @@ export default class IndexController extends Controller {window.location.hash = `#activity-${activityId}`;}+ private getCkEditorElement():HTMLElement | null {+ return this.element.querySelector('opce-ckeditor-augmented-textarea');+ }+private getCkEditorInstance():ICKEditorInstance | null {- const AngularCkEditorElement = this.element.querySelector('opce-ckeditor-augmented-textarea');+ const AngularCkEditorElement = this.getCkEditorElement();return AngularCkEditorElement ? jQuery(AngularCkEditorElement).data('editor') as ICKEditorInstance : null;}@@ -211,59 +218,25 @@ export default class IndexController extends Controller {}private addEventListenersToCkEditorInstance() {- const editor = this.getCkEditorInstance();- if (editor) {- this.addKeydownListener(editor);- this.addKeyupListener(editor);- this.addBlurListener(editor);+ this.onSubmitBound = () => { void this.onSubmit(); };+ this.adjustMarginBound = () => { void this.adjustJournalContainerMargin(); };+ this.hideEditorBound = () => { void this.hideEditorIfEmpty(); };++ const editorElement = this.getCkEditorElement();+ if (editorElement) {+ editorElement.addEventListener('saveRequested', this.onSubmitBound);+ editorElement.addEventListener('editorKeyup', this.adjustMarginBound);+ editorElement.addEventListener('editorBlur', this.hideEditorBound);}}- private addKeydownListener(editor:ICKEditorInstance) {- editor.listenTo(- editor.editing.view.document,- 'keydown',- (event, data) => {- // taken from op-ck-editor.component.ts- // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison- if ((data.ctrlKey || data.metaKey) && data.keyCode === KeyCodes.ENTER) {- void this.onSubmit();- event.stop();- }- },- { priority: 'highest' },- );- }-- private addKeyupListener(editor:ICKEditorInstance) {- editor.listenTo(- editor.editing.view.document,- 'keyup',- (event) => {- this.adjustJournalContainerMargin();- event.stop();- },- { priority: 'highest' },- );- }-- private addBlurListener(editor:ICKEditorInstance) {- editor.listenTo(- editor.editing.view.document,- 'change:isFocused',- () => {- // without the timeout `isFocused` is still true even if the editor was blurred- // current limitation:- // clicking on empty toolbar space and the somewhere else on the page does not trigger the blur anymore- setTimeout(() => {- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- if (!editor.ui.focusTracker.isFocused) {- this.hideEditorIfEmpty();- }- }, 0);- },- { priority: 'highest' },- );+ private removeEventListenersFromCkEditorInstance() {+ const editorElement = this.getCkEditorElement();+ if (editorElement) {+ editorElement.removeEventListener('saveRequested', this.onSubmitBound);+ editorElement.removeEventListener('editorKeyup', this.adjustMarginBound);+ editorElement.removeEventListener('editorBlur', this.hideEditorBound);+ }}private adjustJournalContainerMargin() {@@ -367,7 +340,10 @@ export default class IndexController extends Controller {hideEditorIfEmpty() {const ckEditorInstance = this.getCkEditorInstance();+if (ckEditorInstance && ckEditorInstance.getData({ trim: false }).length === 0) {+ this.clearEditor(); // remove potentially empty lines+ this.removeEventListenersFromCkEditorInstance();this.buttonRowTarget.classList.remove('d-none');this.formRowTarget.classList.add('d-none');