@ckeditor/ckeditor5-word-count 36.0.0 → 37.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,4 +2,4 @@
2
2
  /*!
3
3
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
4
4
  * For licensing, see LICENSE.md.
5
- */(()=>{var t={704:(t,e,r)=>{t.exports=r(79)("./src/core.js")},273:(t,e,r)=>{t.exports=r(79)("./src/ui.js")},209:(t,e,r)=>{t.exports=r(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function r(o){var n=e[o];if(void 0!==n)return n.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,r),i.exports}r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};(()=>{"use strict";r.r(o),r.d(o,{WordCount:()=>z});var t=r(704),e=r(273),n=r(209);function i(t){if(t.is("$text")||t.is("$textProxy"))return t.data;const e=t;let r="",o=null;for(const t of e.getChildren()){const e=i(t);o&&o.is("element")&&(r+="\n"),r+=e,o=t}return r}const s=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};const c="object"==typeof global&&global&&global.Object===Object&&global;var a="object"==typeof self&&self&&self.Object===Object&&self;const u=c||a||Function("return this")();const d=function(){return u.Date.now()};var l=/\s/;const f=function(t){for(var e=t.length;e--&&l.test(t.charAt(e)););return e};var h=/^\s+/;const p=function(t){return t?t.slice(0,f(t)+1).replace(h,""):t};const g=u.Symbol;var v=Object.prototype,b=v.hasOwnProperty,w=v.toString,y=g?g.toStringTag:void 0;const _=function(t){var e=b.call(t,y),r=t[y];try{t[y]=void 0;var o=!0}catch(t){}var n=w.call(t);return o&&(e?t[y]=r:delete t[y]),n};var m=Object.prototype.toString;const j=function(t){return m.call(t)};var O=g?g.toStringTag:void 0;const x=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":O&&O in Object(t)?_(t):j(t)};const C=function(t){return null!=t&&"object"==typeof t};const S=function(t){return"symbol"==typeof t||C(t)&&"[object Symbol]"==x(t)};var T=/^[-+]0x[0-9a-f]+$/i,E=/^0b[01]+$/i,W=/^0o[0-7]+$/i,N=parseInt;const P=function(t){if("number"==typeof t)return t;if(S(t))return NaN;if(s(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=s(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=p(t);var r=E.test(t);return r||W.test(t)?N(t.slice(2),r?2:8):T.test(t)?NaN:+t};var R=Math.max,V=Math.min;const L=function(t,e,r){var o,n,i,c,a,u,l=0,f=!1,h=!1,p=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function g(e){var r=o,i=n;return o=n=void 0,l=e,c=t.apply(i,r)}function v(t){return l=t,a=setTimeout(w,e),f?g(t):c}function b(t){var r=t-u;return void 0===u||r>=e||r<0||h&&t-l>=i}function w(){var t=d();if(b(t))return y(t);a=setTimeout(w,function(t){var r=e-(t-u);return h?V(r,i-(t-l)):r}(t))}function y(t){return a=void 0,p&&o?g(t):(o=n=void 0,c)}function _(){var t=d(),r=b(t);if(o=arguments,n=this,u=t,r){if(void 0===a)return v(u);if(h)return clearTimeout(a),a=setTimeout(w,e),g(u)}return void 0===a&&(a=setTimeout(w,e)),c}return e=P(e)||0,s(r)&&(f=!!r.leading,i=(h="maxWait"in r)?R(P(r.maxWait)||0,e):i,p="trailing"in r?!!r.trailing:p),_.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=u=n=a=void 0},_.flush=function(){return void 0===a?c:y(d())},_};const A=function(t,e,r){var o=!0,n=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return s(r)&&(o="leading"in r?!!r.leading:o,n="trailing"in r?!!r.trailing:n),L(t,e,{leading:o,maxWait:e,trailing:n})};const M=function(t,e){return function(r){return t(e(r))}}(Object.getPrototypeOf,Object);var I=Function.prototype,K=Object.prototype,$=I.toString,k=K.hasOwnProperty,U=$.call(Object);const D=function(t){if(!C(t)||"[object Object]"!=x(t))return!1;var e=M(t);if(null===e)return!0;var r=k.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&$.call(r)==U};const F=function(t){return C(t)&&1===t.nodeType&&!D(t)};class z extends t.Plugin{constructor(t){super(t),this.set("characters",0),this.set("words",0),Object.defineProperties(this,{characters:{get(){return this.characters=this._getCharacters()}},words:{get(){return this.words=this._getWords()}}}),this.set("_wordsLabel",void 0),this.set("_charactersLabel",void 0),this._config=t.config.get("wordCount")||{},this._outputView=void 0,this._wordsMatchRegExp=n.env.features.isRegExpUnicodePropertySupported?new RegExp("([\\p{L}\\p{N}]+\\S?)+","gu"):/([a-zA-Z0-9À-ž]+\S?)+/gu}static get pluginName(){return"WordCount"}init(){this.editor.model.document.on("change:data",A(this._refreshStats.bind(this),250)),"function"==typeof this._config.onUpdate&&this.on("update",((t,e)=>{this._config.onUpdate(e)})),F(this._config.container)&&this._config.container.appendChild(this.wordCountContainer)}destroy(){this._outputView&&(this._outputView.element.remove(),this._outputView.destroy()),super.destroy()}get wordCountContainer(){const t=this.editor,r=t.t,o=t.config.get("wordCount.displayWords"),n=t.config.get("wordCount.displayCharacters"),i=e.Template.bind(this,this),s=[];return this._outputView||(this._outputView=new e.View,(o||void 0===o)&&(this.bind("_wordsLabel").to(this,"words",(t=>r("Words: %0",t))),s.push({tag:"div",children:[{text:[i.to("_wordsLabel")]}],attributes:{class:"ck-word-count__words"}})),(n||void 0===n)&&(this.bind("_charactersLabel").to(this,"characters",(t=>r("Characters: %0",t))),s.push({tag:"div",children:[{text:[i.to("_charactersLabel")]}],attributes:{class:"ck-word-count__characters"}})),this._outputView.setTemplate({tag:"div",attributes:{class:["ck","ck-word-count"]},children:s}),this._outputView.render()),this._outputView.element}_getCharacters(){return i(this.editor.model.document.getRoot()).replace(/\n/g,"").length}_getWords(){return(i(this.editor.model.document.getRoot()).match(this._wordsMatchRegExp)||[]).length}_refreshStats(){const t=this.words=this._getWords(),e=this.characters=this._getCharacters();this.fire("update",{words:t,characters:e})}}})(),(window.CKEditor5=window.CKEditor5||{}).wordCount=o})();
5
+ */(()=>{var t={704:(t,e,r)=>{t.exports=r(79)("./src/core.js")},273:(t,e,r)=>{t.exports=r(79)("./src/ui.js")},209:(t,e,r)=>{t.exports=r(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function r(o){var n=e[o];if(void 0!==n)return n.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,r),i.exports}r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};(()=>{"use strict";r.r(o),r.d(o,{WordCount:()=>Q});var t=r(704),e=r(273),n=r(209);function i(t){if(t.is("$text")||t.is("$textProxy"))return t.data;const e=t;let r="",o=null;for(const t of e.getChildren()){const e=i(t);o&&o.is("element")&&(r+="\n"),r+=e,o=t}return r}const s=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};const c="object"==typeof global&&global&&global.Object===Object&&global;var a="object"==typeof self&&self&&self.Object===Object&&self;const u=c||a||Function("return this")();const d=function(){return u.Date.now()};var l=/\s/;const f=function(t){for(var e=t.length;e--&&l.test(t.charAt(e)););return e};var h=/^\s+/;const p=function(t){return t?t.slice(0,f(t)+1).replace(h,""):t};const g=u.Symbol;var v=Object.prototype,b=v.hasOwnProperty,w=v.toString,y=g?g.toStringTag:void 0;const _=function(t){var e=b.call(t,y),r=t[y];try{t[y]=void 0;var o=!0}catch(t){}var n=w.call(t);return o&&(e?t[y]=r:delete t[y]),n};var m=Object.prototype.toString;const j=function(t){return m.call(t)};var O="[object Null]",x="[object Undefined]",C=g?g.toStringTag:void 0;const S=function(t){return null==t?void 0===t?x:O:C&&C in Object(t)?_(t):j(t)};const T=function(t){return null!=t&&"object"==typeof t};var E="[object Symbol]";const W=function(t){return"symbol"==typeof t||T(t)&&S(t)==E};var P=NaN,R=/^[-+]0x[0-9a-f]+$/i,V=/^0b[01]+$/i,L=/^0o[0-7]+$/i,N=parseInt;const A=function(t){if("number"==typeof t)return t;if(W(t))return P;if(s(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=s(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=p(t);var r=V.test(t);return r||L.test(t)?N(t.slice(2),r?2:8):R.test(t)?P:+t};var M="Expected a function",I=Math.max,K=Math.min;const $=function(t,e,r){var o,n,i,c,a,u,l=0,f=!1,h=!1,p=!0;if("function"!=typeof t)throw new TypeError(M);function g(e){var r=o,i=n;return o=n=void 0,l=e,c=t.apply(i,r)}function v(t){var r=t-u;return void 0===u||r>=e||r<0||h&&t-l>=i}function b(){var t=d();if(v(t))return w(t);a=setTimeout(b,function(t){var r=e-(t-u);return h?K(r,i-(t-l)):r}(t))}function w(t){return a=void 0,p&&o?g(t):(o=n=void 0,c)}function y(){var t=d(),r=v(t);if(o=arguments,n=this,u=t,r){if(void 0===a)return function(t){return l=t,a=setTimeout(b,e),f?g(t):c}(u);if(h)return clearTimeout(a),a=setTimeout(b,e),g(u)}return void 0===a&&(a=setTimeout(b,e)),c}return e=A(e)||0,s(r)&&(f=!!r.leading,i=(h="maxWait"in r)?I(A(r.maxWait)||0,e):i,p="trailing"in r?!!r.trailing:p),y.cancel=function(){void 0!==a&&clearTimeout(a),l=0,o=u=n=a=void 0},y.flush=function(){return void 0===a?c:w(d())},y};var k="Expected a function";const U=function(t,e,r){var o=!0,n=!0;if("function"!=typeof t)throw new TypeError(k);return s(r)&&(o="leading"in r?!!r.leading:o,n="trailing"in r?!!r.trailing:n),$(t,e,{leading:o,maxWait:e,trailing:n})};const D=function(t,e){return function(r){return t(e(r))}}(Object.getPrototypeOf,Object);var F="[object Object]",z=Function.prototype,Z=Object.prototype,q=z.toString,B=Z.hasOwnProperty,G=q.call(Object);const H=function(t){if(!T(t)||S(t)!=F)return!1;var e=D(t);if(null===e)return!0;var r=B.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&q.call(r)==G};const J=function(t){return T(t)&&1===t.nodeType&&!H(t)};class Q extends t.Plugin{constructor(t){super(t),this.set("characters",0),this.set("words",0),Object.defineProperties(this,{characters:{get(){return this.characters=this._getCharacters()}},words:{get(){return this.words=this._getWords()}}}),this.set("_wordsLabel",void 0),this.set("_charactersLabel",void 0),this._config=t.config.get("wordCount")||{},this._outputView=void 0,this._wordsMatchRegExp=n.env.features.isRegExpUnicodePropertySupported?new RegExp("([\\p{L}\\p{N}]+\\S?)+","gu"):/([a-zA-Z0-9À-ž]+\S?)+/gu}static get pluginName(){return"WordCount"}init(){this.editor.model.document.on("change:data",U(this._refreshStats.bind(this),250)),"function"==typeof this._config.onUpdate&&this.on("update",((t,e)=>{this._config.onUpdate(e)})),J(this._config.container)&&this._config.container.appendChild(this.wordCountContainer)}destroy(){this._outputView&&(this._outputView.element.remove(),this._outputView.destroy()),super.destroy()}get wordCountContainer(){const t=this.editor,r=t.t,o=t.config.get("wordCount.displayWords"),n=t.config.get("wordCount.displayCharacters"),i=e.Template.bind(this,this),s=[];return this._outputView||(this._outputView=new e.View,(o||void 0===o)&&(this.bind("_wordsLabel").to(this,"words",(t=>r("Words: %0",t))),s.push({tag:"div",children:[{text:[i.to("_wordsLabel")]}],attributes:{class:"ck-word-count__words"}})),(n||void 0===n)&&(this.bind("_charactersLabel").to(this,"characters",(t=>r("Characters: %0",t))),s.push({tag:"div",children:[{text:[i.to("_charactersLabel")]}],attributes:{class:"ck-word-count__characters"}})),this._outputView.setTemplate({tag:"div",attributes:{class:["ck","ck-word-count"]},children:s}),this._outputView.render()),this._outputView.element}_getCharacters(){return i(this.editor.model.document.getRoot()).replace(/\n/g,"").length}_getWords(){return(i(this.editor.model.document.getRoot()).match(this._wordsMatchRegExp)||[]).length}_refreshStats(){const t=this.words=this._getWords(),e=this.characters=this._getCharacters();this.fire("update",{words:t,characters:e})}}})(),(window.CKEditor5=window.CKEditor5||{}).wordCount=o})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-word-count",
3
- "version": "36.0.0",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "Word and character count feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,23 +13,23 @@
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
15
  "lodash-es": "^4.17.15",
16
- "ckeditor5": "^36.0.0"
16
+ "ckeditor5": "^37.0.0-alpha.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@ckeditor/ckeditor5-basic-styles": "^36.0.0",
20
- "@ckeditor/ckeditor5-block-quote": "^36.0.0",
21
- "@ckeditor/ckeditor5-core": "^36.0.0",
22
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
23
- "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
24
- "@ckeditor/ckeditor5-engine": "^36.0.0",
25
- "@ckeditor/ckeditor5-enter": "^36.0.0",
26
- "@ckeditor/ckeditor5-image": "^36.0.0",
27
- "@ckeditor/ckeditor5-link": "^36.0.0",
28
- "@ckeditor/ckeditor5-list": "^36.0.0",
29
- "@ckeditor/ckeditor5-paragraph": "^36.0.0",
30
- "@ckeditor/ckeditor5-table": "^36.0.0",
31
- "@ckeditor/ckeditor5-theme-lark": "^36.0.0",
32
- "@ckeditor/ckeditor5-utils": "^36.0.0",
19
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.0",
20
+ "@ckeditor/ckeditor5-block-quote": "^37.0.0-alpha.0",
21
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
22
+ "@ckeditor/ckeditor5-dev-utils": "^34.0.0",
23
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
24
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0",
25
+ "@ckeditor/ckeditor5-enter": "^37.0.0-alpha.0",
26
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.0",
27
+ "@ckeditor/ckeditor5-link": "^37.0.0-alpha.0",
28
+ "@ckeditor/ckeditor5-list": "^37.0.0-alpha.0",
29
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
30
+ "@ckeditor/ckeditor5-table": "^37.0.0-alpha.0",
31
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.0",
32
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.0",
33
33
  "typescript": "^4.8.4",
34
34
  "webpack": "^5.58.1",
35
35
  "webpack-cli": "^4.9.0"
@@ -60,5 +60,6 @@
60
60
  "dll:build": "webpack",
61
61
  "build": "tsc -p ./tsconfig.release.json",
62
62
  "postversion": "npm run build"
63
- }
63
+ },
64
+ "types": "src/index.d.ts"
64
65
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module word-count
7
+ */
8
+ export { default as WordCount, type WordCountUpdateEvent } from './wordcount';
package/src/utils.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module word-count/utils
7
+ */
8
+ import type { Item } from 'ckeditor5/src/engine';
9
+ /**
10
+ * Returns a plain text representation of an element and its children.
11
+ *
12
+ * @returns Plain text representing the model's data.
13
+ */
14
+ export declare function modelElementToPlainText(item: Item): string;
@@ -0,0 +1,233 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
6
+ /**
7
+ * The word count plugin.
8
+ *
9
+ * This plugin calculates all words and characters in all {@link module:engine/model/text~Text text nodes} available in the model.
10
+ * It also provides an HTML element that updates its state whenever the editor content is changed.
11
+ *
12
+ * The model's data is first converted to plain text using {@link module:word-count/utils~modelElementToPlainText}.
13
+ * The number of words and characters in your text are determined based on the created plain text. Please keep in mind
14
+ * that every block in the editor is separated with a newline character, which is included in the calculation.
15
+ *
16
+ * Here are some examples of how the word and character calculations are made:
17
+ *
18
+ * ```html
19
+ * <paragraph>foo</paragraph>
20
+ * <paragraph>bar</paragraph>
21
+ * // Words: 2, Characters: 7
22
+ *
23
+ * <paragraph><$text bold="true">foo</$text>bar</paragraph>
24
+ * // Words: 1, Characters: 6
25
+ *
26
+ * <paragraph>*&^%)</paragraph>
27
+ * // Words: 0, Characters: 5
28
+ *
29
+ * <paragraph>foo(bar)</paragraph>
30
+ * //Words: 1, Characters: 8
31
+ *
32
+ * <paragraph>12345</paragraph>
33
+ * // Words: 1, Characters: 5
34
+ * ```
35
+ */
36
+ export default class WordCount extends Plugin {
37
+ /**
38
+ * The number of characters in the editor.
39
+ *
40
+ * @observable
41
+ * @readonly
42
+ */
43
+ characters: number;
44
+ /**
45
+ * The number of words in the editor.
46
+ *
47
+ * @observable
48
+ * @readonly
49
+ */
50
+ words: number;
51
+ /**
52
+ * The label used to display the words value in the {@link #wordCountContainer output container}.
53
+ *
54
+ * @observable
55
+ * @private
56
+ * @readonly
57
+ */
58
+ _wordsLabel: string | undefined;
59
+ /**
60
+ * The label used to display the characters value in the {@link #wordCountContainer output container}.
61
+ *
62
+ * @observable
63
+ * @private
64
+ * @readonly
65
+ */
66
+ _charactersLabel: string | undefined;
67
+ /**
68
+ * The configuration of this plugin.
69
+ */
70
+ private _config;
71
+ /**
72
+ * The reference to a {@link module:ui/view~View view object} that contains the self-updating HTML container.
73
+ */
74
+ private _outputView;
75
+ /**
76
+ * A regular expression used to recognize words in the editor's content.
77
+ */
78
+ private readonly _wordsMatchRegExp;
79
+ /**
80
+ * @inheritDoc
81
+ */
82
+ constructor(editor: Editor);
83
+ /**
84
+ * @inheritDoc
85
+ */
86
+ static get pluginName(): 'WordCount';
87
+ /**
88
+ * @inheritDoc
89
+ */
90
+ init(): void;
91
+ /**
92
+ * @inheritDoc
93
+ */
94
+ destroy(): void;
95
+ /**
96
+ * Creates a self-updating HTML element. Repeated executions return the same element.
97
+ * The returned element has the following HTML structure:
98
+ *
99
+ * ```html
100
+ * <div class="ck ck-word-count">
101
+ * <div class="ck-word-count__words">Words: 4</div>
102
+ * <div class="ck-word-count__characters">Characters: 28</div>
103
+ * </div>
104
+ * ```
105
+ */
106
+ get wordCountContainer(): HTMLElement;
107
+ /**
108
+ * Determines the number of characters in the current editor's model.
109
+ */
110
+ private _getCharacters;
111
+ /**
112
+ * Determines the number of words in the current editor's model.
113
+ */
114
+ private _getWords;
115
+ /**
116
+ * Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
117
+ * It also fires the {@link #event:update}.
118
+ *
119
+ * @fires update
120
+ */
121
+ private _refreshStats;
122
+ }
123
+ /**
124
+ * An event fired after {@link #words} and {@link #characters} are updated.
125
+ *
126
+ * @eventName update
127
+ */
128
+ export type WordCountUpdateEvent = {
129
+ name: 'update';
130
+ args: [{
131
+ words: number;
132
+ characters: number;
133
+ }];
134
+ };
135
+ /**
136
+ * The configuration of the word count feature.
137
+ *
138
+ * ```ts
139
+ * ClassicEditor
140
+ * .create( {
141
+ * wordCount: ... // Word count feature configuration.
142
+ * } )
143
+ * .then( ... )
144
+ * .catch( ... );
145
+ * ```
146
+ *
147
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
148
+ */
149
+ export interface WordCountConfig {
150
+ /**
151
+ * This option allows for hiding the word counter. The element obtained through
152
+ * {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
153
+ * the characters part. Word counter is displayed by default when this configuration option is not defined.
154
+ *
155
+ * ```ts
156
+ * const wordCountConfig = {
157
+ * displayWords: false
158
+ * };
159
+ * ```
160
+ *
161
+ * The configuration above will result in the following container:
162
+ *
163
+ * ```html
164
+ * <div class="ck ck-word-count">
165
+ * <div class="ck-word-count__characters">Characters: 28</div>
166
+ * </div>
167
+ * ```
168
+ */
169
+ displayWords?: boolean;
170
+ /**
171
+ * This option allows for hiding the character counter. The element obtained through
172
+ * {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
173
+ * the words part. Character counter is displayed by default when this configuration option is not defined.
174
+ *
175
+ * ```ts
176
+ * const wordCountConfig = {
177
+ * displayCharacters: false
178
+ * };
179
+ * ```
180
+ *
181
+ * The configuration above will result in the following container:
182
+ *
183
+ * ```html
184
+ * <div class="ck ck-word-count">
185
+ * <div class="ck-word-count__words">Words: 4</div>
186
+ * </div>
187
+ * ```
188
+ */
189
+ displayCharacters?: boolean;
190
+ /**
191
+ * This configuration takes a function that is executed whenever the word count plugin updates its values.
192
+ * This function is called with one argument, which is an object with the `words` and `characters` keys containing
193
+ * the number of detected words and characters in the document.
194
+ *
195
+ * ```ts
196
+ * const wordCountConfig = {
197
+ * onUpdate: function( stats ) {
198
+ * doSthWithWordNumber( stats.words );
199
+ * doSthWithCharacterNumber( stats.characters );
200
+ * }
201
+ * };
202
+ * ```
203
+ */
204
+ onUpdate?: (data: {
205
+ words: number;
206
+ characters: number;
207
+ }) => void;
208
+ /**
209
+ * Allows for providing the HTML element that the
210
+ * {@link module:word-count/wordcount~WordCount#wordCountContainer word count container} will be appended to automatically.
211
+ *
212
+ * ```ts
213
+ * const wordCountConfig = {
214
+ * container: document.getElementById( 'container-for-word-count' );
215
+ * };
216
+ * ```
217
+ */
218
+ container?: HTMLElement;
219
+ }
220
+ declare module '@ckeditor/ckeditor5-core' {
221
+ interface PluginsMap {
222
+ [WordCount.pluginName]: WordCount;
223
+ }
224
+ interface EditorConfig {
225
+ /**
226
+ * The configuration of the word count feature.
227
+ * It is introduced by the {@link module:word-count/wordcount~WordCount} feature.
228
+ *
229
+ * Read more in {@link module:word-count/wordcount~WordCountConfig}.
230
+ */
231
+ wordCount?: WordCountConfig;
232
+ }
233
+ }