CKEditor5 plugin shim to support deprecated Model in CKEditor 41.3.1

Submitted by charles on

Drupal 10.3 uses CKEditor 41.3.1, which changed Model to ViewModel

To support both Drupal 10.2 and 10.3, you can use this shim.

Make sure you have this in global.d.ts:


declare module 'ckeditor5/src/ui' {
  export * from '@ckeditor/ckeditor5-ui';
  // Older versions of CKEditor 5 expect the export to be named `Model` rather
  // than `ViewModel`. See https://github.com/ckeditor/ckeditor5/issues/15661
  export { ViewModel as Model } from '@ckeditor/ckeditor5-ui';
}

Then create a shims file wherever you like in your plugin js/src directory:

/**
 * @file Contains shims to avoid breaking older versions of CKEditor 5.
 */
import { ViewModel, Model } from 'ckeditor5/src/ui';
// Older versions of CKEditor 5 expect the export to be named `Model` rather
// than `ViewModel`. See https://github.com/ckeditor/ckeditor5/issues/15661
// This shim allows us to retain compatibility with Drupal 10.2 and earlier.
export const UiViewModel = typeof ViewModel !== 'undefined' ? ViewModel : Model;

Then in your Typescript files where you use it, import as follows:
 

import { UiViewModel as ViewModel } from './utils/symbolshims';

And change any new Model() calls to new ViewModel().

Thanks to the maintainers of the CKEditor5 icons module for the fix https://www.drupal.org/project/ckeditor5_icons/issues/3452570