From ccd0805f6d066f7794779e5e9b96ffafed423eb9 Mon Sep 17 00:00:00 2001 From: mgsy Date: Thu, 19 Sep 2024 13:37:11 +0200 Subject: [PATCH] Switch the ckeditor5-maximum-length plugin from UMD build to JS. --- CHANGELOG.md | 11 +++ .../components/CKEditorInput/Configurator.js | 4 +- .../vendor/ckeditor5-maximum-length/index.js | 72 +++++++++++++++++++ .../ckeditor5-maximum-length/index.umd.js | 12 ---- .../ckeditor5-maximum-length/index.umd.js.map | 1 - package.json | 2 +- 6 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 admin/src/vendor/ckeditor5-maximum-length/index.js delete mode 100644 admin/src/vendor/ckeditor5-maximum-length/index.umd.js delete mode 100644 admin/src/vendor/ckeditor5-maximum-length/index.umd.js.map diff --git a/CHANGELOG.md b/CHANGELOG.md index 167a21e..0150cb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 1.0.1 (September 19, 2024) + +### Release highlights + +This is a patch release that resolves an issue that resulted in the Strapi app building process failure. + +Check out the highlights of the original v1.0.0 release. + +### Bug fixes +* Switch the `ckeditor5-maximum-length` plugin from UMD build to JS. + ## 1.0.0 (September 19, 2024) We are happy to announce the release of CKEditor 5 Official Integration v1.0.0. diff --git a/admin/src/components/CKEditorInput/Configurator.js b/admin/src/components/CKEditorInput/Configurator.js index 01dd475..462e652 100644 --- a/admin/src/components/CKEditorInput/Configurator.js +++ b/admin/src/components/CKEditorInput/Configurator.js @@ -1,6 +1,6 @@ import { StrapiMediaLib } from "./plugins/StrapiMediaLib"; -import "../../vendor/ckeditor5-maximum-length/index.umd"; +import MaximumLength from "../../vendor/ckeditor5-maximum-length/index"; import "../../vendor/ckeditor5-maximum-length/index-editor.css"; const { @@ -54,8 +54,6 @@ const { Highlight } = window.CKEDITOR; -const { MaximumLength } = window.MaximumLength; - const CKEDITOR_BASE_CONFIG_FOR_PRESETS = { light: { plugins: [ diff --git a/admin/src/vendor/ckeditor5-maximum-length/index.js b/admin/src/vendor/ckeditor5-maximum-length/index.js new file mode 100644 index 0000000..285de33 --- /dev/null +++ b/admin/src/vendor/ckeditor5-maximum-length/index.js @@ -0,0 +1,72 @@ +const { Plugin } = window.CKEDITOR; + + +export default class MaximumLength extends Plugin { + static get pluginName() { + return 'MaximumLength'; + } + + static get requires() { + return [ 'WordCount' ]; + } + + init() { + const editor = this.editor; + const wordCount = editor.plugins.get( 'WordCount' ); + const characterLimit = editor.config.get( 'maximumLength.characters' ); + let hasMarker = false; + + editor.model.document.registerPostFixer( writer => { + const currentCharacterCount = wordCount.characters; + const excessRange = this._calculateExcessRange( characterLimit, currentCharacterCount ); + + if ( excessRange ) { + if ( !hasMarker ) { + writer.addMarker( 'maximumLengthExcess', { range: excessRange, usingOperation: false } ); + hasMarker = true; + } else { + writer.updateMarker( 'maximumLengthExcess', { range: excessRange, usingOperation: false } ); + } + } else if ( hasMarker ) { + writer.removeMarker( 'maximumLengthExcess' ); + hasMarker = false; + } + } ); + + editor.conversion.for( 'editingDowncast' ).markerToHighlight( { + model: 'maximumLengthExcess', + view: { + classes: 'ck-maximum-length-excess' + } + } ); + } + + _calculateExcessRange( characterLimit, currentCharacterCount ) { + if ( characterLimit > currentCharacterCount ) { + return null; + } + + const editor = this.editor; + const contentRange = editor.model.createRangeIn( editor.model.document.getRoot() ); + const walker = contentRange.getWalker( { singleCharacters: true, direction: 'backward' } ); + + let characterNumber = currentCharacterCount; + let endPosition, startPosition; + + for ( const value of walker ) { + if ( value.type == 'text' ) { + if ( !endPosition ) { + endPosition = value.previousPosition; + } + + characterNumber--; + + if ( characterNumber < characterLimit ) { + startPosition = value.previousPosition; + + return editor.model.createRange( startPosition, endPosition ); + } + } + } + } +} diff --git a/admin/src/vendor/ckeditor5-maximum-length/index.umd.js b/admin/src/vendor/ckeditor5-maximum-length/index.umd.js deleted file mode 100644 index 885fc13..0000000 --- a/admin/src/vendor/ckeditor5-maximum-length/index.umd.js +++ /dev/null @@ -1,12 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('ckeditor5')) : - typeof define === 'function' && define.amd ? define(['exports', 'ckeditor5'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MaximumLength = {}, global.CKEDITOR)); -})(this, (function (exports, ckeditor5) { 'use strict'; - - class t extends ckeditor5.Plugin{static get pluginName(){return "MaximumLength"}static get requires(){return ["WordCount"]}init(){const e=this.editor,t=e.plugins.get("WordCount"),r=e.config.get("maximumLength.characters");let i=!1;e.model.document.registerPostFixer((e=>{const s=t.characters,n=this._calculateExcessRange(r,s);n?i?e.updateMarker("maximumLengthExcess",{range:n,usingOperation:!1}):(e.addMarker("maximumLengthExcess",{range:n,usingOperation:!1}),i=!0):i&&(e.removeMarker("maximumLengthExcess"),i=!1);})),e.conversion.for("editingDowncast").markerToHighlight({model:"maximumLengthExcess",view:{classes:"ck-maximum-length-excess"}});}_calculateExcessRange(e,t){if(e>t)return null;const r=this.editor,i=r.model.createRangeIn(r.model.document.getRoot()).getWalker({singleCharacters:!0,direction:"backward"});let s,n,a=t;for(const t of i)if("text"==t.type&&(s||(s=t.previousPosition),a--,a{const s=t.characters,n=this._calculateExcessRange(r,s);n?i?e.updateMarker(\"maximumLengthExcess\",{range:n,usingOperation:!1}):(e.addMarker(\"maximumLengthExcess\",{range:n,usingOperation:!1}),i=!0):i&&(e.removeMarker(\"maximumLengthExcess\"),i=!1)})),e.conversion.for(\"editingDowncast\").markerToHighlight({model:\"maximumLengthExcess\",view:{classes:\"ck-maximum-length-excess\"}})}_calculateExcessRange(e,t){if(e>t)return null;const r=this.editor,i=r.model.createRangeIn(r.model.document.getRoot()).getWalker({singleCharacters:!0,direction:\"backward\"});let s,n,a=t;for(const t of i)if(\"text\"==t.type&&(s||(s=t.previousPosition),a--,a