Skip to content

Commit

Permalink
Switch the ckeditor5-maximum-length plugin from UMD build to JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgsy committed Sep 19, 2024
1 parent 54dc994 commit ccd0805
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 17 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 1 addition & 3 deletions admin/src/components/CKEditorInput/Configurator.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -54,8 +54,6 @@ const {
Highlight
} = window.CKEDITOR;

const { MaximumLength } = window.MaximumLength;

const CKEDITOR_BASE_CONFIG_FOR_PRESETS = {
light: {
plugins: [
Expand Down
72 changes: 72 additions & 0 deletions admin/src/vendor/ckeditor5-maximum-length/index.js
Original file line number Diff line number Diff line change
@@ -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 );
}
}
}
}
}
12 changes: 0 additions & 12 deletions admin/src/vendor/ckeditor5-maximum-length/index.umd.js

This file was deleted.

1 change: 0 additions & 1 deletion admin/src/vendor/ckeditor5-maximum-length/index.umd.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ckeditor/strapi-plugin-ckeditor",
"version": "1.0.0",
"version": "1.0.1",
"description": "CKEditor 5 - Official Integration for Strapi",
"strapi": {
"name": "ckeditor",
Expand Down

0 comments on commit ccd0805

Please sign in to comment.