mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 05:28:44 +02:00
N°5298 -When opening CKEditor4 data with CKEditor5, if no change has been made return initial data instead of transformed data
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
||||
import iTopDataProcessor from "./itop-data-processor";
|
||||
|
||||
/**
|
||||
* DetectChanges Plugin.
|
||||
*
|
||||
*/
|
||||
export default class DetectChanges extends Plugin {
|
||||
|
||||
constructor( editor: Editor ) {
|
||||
super( editor );
|
||||
const sInitialValue:string = editor.config.get('detectChanges.initialValue') as string;
|
||||
// TODO 3.2.0: How to use CombodoJSConsole here ?
|
||||
console.debug('DetectChanges initial value', sInitialValue);
|
||||
// If the initial value is not set or empty, we don't need to do anything
|
||||
if( !sInitialValue || sInitialValue === '') {
|
||||
return;
|
||||
}
|
||||
// Initialize our own data processor
|
||||
editor.data.processor= new iTopDataProcessor( editor.data.viewDocument, sInitialValue, editor.getData() ) as iTopDataProcessor;
|
||||
// Listen for the dataReady event only once
|
||||
editor.model.document.once('change:data', () => {
|
||||
// Ignore linter as processor can be any kind of DataProcessor but we're sure that we have an iTopDataProcessor
|
||||
// @ts-ignore
|
||||
editor.data.processor.setTransformedInitialValue( editor.getData());
|
||||
});
|
||||
}
|
||||
init() {
|
||||
|
||||
}
|
||||
static get pluginName() {
|
||||
return 'DetectChanges';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user