Skip to content

Commit ccd0805

Browse files
committed
Switch the ckeditor5-maximum-length plugin from UMD build to JS.
1 parent 54dc994 commit ccd0805

File tree

6 files changed

+85
-17
lines changed

6 files changed

+85
-17
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 1.0.1 (September 19, 2024)
4+
5+
### Release highlights
6+
7+
This is a patch release that resolves an issue that resulted in the Strapi app building process failure.
8+
9+
Check out the highlights of the original v1.0.0 release.
10+
11+
### Bug fixes
12+
* Switch the `ckeditor5-maximum-length` plugin from UMD build to JS.
13+
314
## 1.0.0 (September 19, 2024)
415

516
We are happy to announce the release of CKEditor 5 Official Integration v1.0.0.

admin/src/components/CKEditorInput/Configurator.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StrapiMediaLib } from "./plugins/StrapiMediaLib";
22

3-
import "../../vendor/ckeditor5-maximum-length/index.umd";
3+
import MaximumLength from "../../vendor/ckeditor5-maximum-length/index";
44
import "../../vendor/ckeditor5-maximum-length/index-editor.css";
55

66
const {
@@ -54,8 +54,6 @@ const {
5454
Highlight
5555
} = window.CKEDITOR;
5656

57-
const { MaximumLength } = window.MaximumLength;
58-
5957
const CKEDITOR_BASE_CONFIG_FOR_PRESETS = {
6058
light: {
6159
plugins: [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const { Plugin } = window.CKEDITOR;
2+
3+
4+
export default class MaximumLength extends Plugin {
5+
static get pluginName() {
6+
return 'MaximumLength';
7+
}
8+
9+
static get requires() {
10+
return [ 'WordCount' ];
11+
}
12+
13+
init() {
14+
const editor = this.editor;
15+
const wordCount = editor.plugins.get( 'WordCount' );
16+
const characterLimit = editor.config.get( 'maximumLength.characters' );
17+
let hasMarker = false;
18+
19+
editor.model.document.registerPostFixer( writer => {
20+
const currentCharacterCount = wordCount.characters;
21+
const excessRange = this._calculateExcessRange( characterLimit, currentCharacterCount );
22+
23+
if ( excessRange ) {
24+
if ( !hasMarker ) {
25+
writer.addMarker( 'maximumLengthExcess', { range: excessRange, usingOperation: false } );
26+
hasMarker = true;
27+
} else {
28+
writer.updateMarker( 'maximumLengthExcess', { range: excessRange, usingOperation: false } );
29+
}
30+
} else if ( hasMarker ) {
31+
writer.removeMarker( 'maximumLengthExcess' );
32+
hasMarker = false;
33+
}
34+
} );
35+
36+
editor.conversion.for( 'editingDowncast' ).markerToHighlight( {
37+
model: 'maximumLengthExcess',
38+
view: {
39+
classes: 'ck-maximum-length-excess'
40+
}
41+
} );
42+
}
43+
44+
_calculateExcessRange( characterLimit, currentCharacterCount ) {
45+
if ( characterLimit > currentCharacterCount ) {
46+
return null;
47+
}
48+
49+
const editor = this.editor;
50+
const contentRange = editor.model.createRangeIn( editor.model.document.getRoot() );
51+
const walker = contentRange.getWalker( { singleCharacters: true, direction: 'backward' } );
52+
53+
let characterNumber = currentCharacterCount;
54+
let endPosition, startPosition;
55+
56+
for ( const value of walker ) {
57+
if ( value.type == 'text' ) {
58+
if ( !endPosition ) {
59+
endPosition = value.previousPosition;
60+
}
61+
62+
characterNumber--;
63+
64+
if ( characterNumber < characterLimit ) {
65+
startPosition = value.previousPosition;
66+
67+
return editor.model.createRange( startPosition, endPosition );
68+
}
69+
}
70+
}
71+
}
72+
}

admin/src/vendor/ckeditor5-maximum-length/index.umd.js

-12
This file was deleted.

admin/src/vendor/ckeditor5-maximum-length/index.umd.js.map

-1
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ckeditor/strapi-plugin-ckeditor",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "CKEditor 5 - Official Integration for Strapi",
55
"strapi": {
66
"name": "ckeditor",

0 commit comments

Comments
 (0)