Fix CKEditor change detector being misled by insert carriage plugin

This commit is contained in:
Stephen Abello
2024-07-17 14:53:13 +02:00
parent 23651ae510
commit f239b658e6
5 changed files with 40 additions and 9 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +1,13 @@
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
import InsertCarriageReturnAfterBlock from "../insert-carriage-return-after-block/insert-carriage-return-after-block.plugin";
/**
* DetectChanges Plugin.
*
*/
export default class DetectChanges extends Plugin {
private readonly _processor;
constructor(editor: Editor);
init(): void;
static get pluginName(): string;
static get requires(): (typeof InsertCarriageReturnAfterBlock)[];
}

View File

@@ -212,7 +212,25 @@ class Editor extends ClassicEditor {
'tableProperties',
'|',
'toggleTableCaption'
]
],
tableProperties: {
// The default styles for tables in the editor.
// They should be synchronized with the content styles.
defaultProperties: {
borderStyle: 'dashed',
borderColor: 'hsl(90, 75%, 60%)',
borderWidth: '1px',
},
},
// The default styles for table cells in the editor.
// They should be synchronized with the content styles.
tableCellProperties: {
defaultProperties: {
borderStyle: 'dashed',
borderColor: 'hsl(90, 75%, 60%)',
borderWidth: '1px',
}
}
},
htmlSupport: {
allow: [

View File

@@ -1,12 +1,14 @@
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
import iTopDataProcessor from "./itop-data-processor";
import InsertCarriageReturnAfterBlock from "../insert-carriage-return-after-block/insert-carriage-return-after-block.plugin";
/**
* DetectChanges Plugin.
*
*/
export default class DetectChanges extends Plugin {
private readonly _processor: iTopDataProcessor | undefined;
constructor( editor: Editor ) {
super( editor );
const sInitialValue:string = editor.config.get('detectChanges.initialValue') as string;
@@ -17,15 +19,23 @@ export default class DetectChanges extends Plugin {
// Initialize our own data processor
const oProcessor = new iTopDataProcessor( editor.data.viewDocument, sInitialValue, editor.getData() ) as iTopDataProcessor;
editor.data.processor = oProcessor;
// Listen for the dataReady event only once
editor.model.document.once('change:data', () => {
oProcessor.setTransformedInitialValue( editor.getData());
});
this._processor = oProcessor;
}
init() {
const editor = this.editor;// Listen for the dataReady event only once
editor.model.document.once('change:data', () => {
if(this._processor ) {
this._processor.setTransformedInitialValue(editor.getData());
}
});
}
static get pluginName() {
return 'DetectChanges';
}
// Needed as InsertCarriageReturnAfterBlock will possibly change data on initialization if there's a block in the content, so we need to make sure it's loaded first
static get requires() {
return [ InsertCarriageReturnAfterBlock ];
}
}