@ckeditor/ckeditor5-word-count 39.0.1 → 40.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/build/translations/hy.js +1 -0
- package/build/word-count.js.map +1 -0
- package/lang/translations/ar.po +1 -0
- package/lang/translations/az.po +1 -0
- package/lang/translations/bg.po +1 -0
- package/lang/translations/bn.po +1 -0
- package/lang/translations/ca.po +1 -0
- package/lang/translations/cs.po +1 -0
- package/lang/translations/da.po +1 -0
- package/lang/translations/de-ch.po +1 -0
- package/lang/translations/de.po +1 -0
- package/lang/translations/el.po +1 -0
- package/lang/translations/en-au.po +1 -0
- package/lang/translations/en-gb.po +1 -0
- package/lang/translations/en.po +1 -0
- package/lang/translations/es-co.po +1 -0
- package/lang/translations/es.po +1 -0
- package/lang/translations/et.po +1 -0
- package/lang/translations/fa.po +1 -0
- package/lang/translations/fi.po +1 -0
- package/lang/translations/fr.po +1 -0
- package/lang/translations/gl.po +1 -0
- package/lang/translations/he.po +1 -0
- package/lang/translations/hi.po +1 -0
- package/lang/translations/hr.po +1 -0
- package/lang/translations/hu.po +1 -0
- package/lang/translations/hy.po +26 -0
- package/lang/translations/id.po +1 -0
- package/lang/translations/it.po +1 -0
- package/lang/translations/ja.po +1 -0
- package/lang/translations/ko.po +1 -0
- package/lang/translations/ku.po +1 -0
- package/lang/translations/lt.po +1 -0
- package/lang/translations/lv.po +1 -0
- package/lang/translations/ms.po +1 -0
- package/lang/translations/ne.po +1 -0
- package/lang/translations/nl.po +1 -0
- package/lang/translations/no.po +1 -0
- package/lang/translations/pl.po +1 -0
- package/lang/translations/pt-br.po +1 -0
- package/lang/translations/pt.po +1 -0
- package/lang/translations/ro.po +1 -0
- package/lang/translations/ru.po +1 -0
- package/lang/translations/sk.po +1 -0
- package/lang/translations/sq.po +1 -0
- package/lang/translations/sr-latn.po +1 -0
- package/lang/translations/sr.po +1 -0
- package/lang/translations/sv.po +1 -0
- package/lang/translations/th.po +1 -0
- package/lang/translations/tk.po +1 -0
- package/lang/translations/tr.po +1 -0
- package/lang/translations/ug.po +1 -0
- package/lang/translations/uk.po +1 -0
- package/lang/translations/ur.po +1 -0
- package/lang/translations/vi.po +1 -0
- package/lang/translations/zh-cn.po +1 -0
- package/lang/translations/zh.po +1 -0
- package/package.json +2 -6
- package/src/augmentation.d.ts +19 -19
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +10 -10
- package/src/index.js +9 -9
- package/src/utils.d.ts +14 -14
- package/src/utils.js +27 -27
- package/src/wordcount.d.ts +135 -135
- package/src/wordcount.js +211 -211
- package/src/wordcountconfig.d.ts +92 -92
- package/src/wordcountconfig.js +5 -5
package/src/wordcount.js
CHANGED
@@ -1,211 +1,211 @@
|
|
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 } from 'ckeditor5/src/core';
|
6
|
-
import { Template, View } from 'ckeditor5/src/ui';
|
7
|
-
import { env } from 'ckeditor5/src/utils';
|
8
|
-
import { modelElementToPlainText } from './utils';
|
9
|
-
import { throttle, isElement } from 'lodash-es';
|
10
|
-
/**
|
11
|
-
* The word count plugin.
|
12
|
-
*
|
13
|
-
* This plugin calculates all words and characters in all {@link module:engine/model/text~Text text nodes} available in the model.
|
14
|
-
* It also provides an HTML element that updates its state whenever the editor content is changed.
|
15
|
-
*
|
16
|
-
* The model's data is first converted to plain text using {@link module:word-count/utils~modelElementToPlainText}.
|
17
|
-
* The number of words and characters in your text are determined based on the created plain text. Please keep in mind
|
18
|
-
* that every block in the editor is separated with a newline character, which is included in the calculation.
|
19
|
-
*
|
20
|
-
* Here are some examples of how the word and character calculations are made:
|
21
|
-
*
|
22
|
-
* ```html
|
23
|
-
* <paragraph>foo</paragraph>
|
24
|
-
* <paragraph>bar</paragraph>
|
25
|
-
* // Words: 2, Characters: 7
|
26
|
-
*
|
27
|
-
* <paragraph><$text bold="true">foo</$text>bar</paragraph>
|
28
|
-
* // Words: 1, Characters: 6
|
29
|
-
*
|
30
|
-
* <paragraph>*&^%)</paragraph>
|
31
|
-
* // Words: 0, Characters: 5
|
32
|
-
*
|
33
|
-
* <paragraph>foo(bar)</paragraph>
|
34
|
-
* //Words: 1, Characters: 8
|
35
|
-
*
|
36
|
-
* <paragraph>12345</paragraph>
|
37
|
-
* // Words: 1, Characters: 5
|
38
|
-
* ```
|
39
|
-
*/
|
40
|
-
export default class WordCount extends Plugin {
|
41
|
-
/**
|
42
|
-
* @inheritDoc
|
43
|
-
*/
|
44
|
-
constructor(editor) {
|
45
|
-
super(editor);
|
46
|
-
this.set('characters', 0);
|
47
|
-
this.set('words', 0);
|
48
|
-
// Don't wait for the #update event to set the value of the properties but obtain it right away.
|
49
|
-
// This way, accessing the properties directly returns precise numbers, e.g. for validation, etc.
|
50
|
-
// If not accessed directly, the properties will be refreshed upon #update anyway.
|
51
|
-
Object.defineProperties(this, {
|
52
|
-
characters: {
|
53
|
-
get() {
|
54
|
-
return (this.characters = this._getCharacters(this._getText()));
|
55
|
-
}
|
56
|
-
},
|
57
|
-
words: {
|
58
|
-
get() {
|
59
|
-
return (this.words = this._getWords(this._getText()));
|
60
|
-
}
|
61
|
-
}
|
62
|
-
});
|
63
|
-
this.set('_wordsLabel', undefined);
|
64
|
-
this.set('_charactersLabel', undefined);
|
65
|
-
this._config = editor.config.get('wordCount') || {};
|
66
|
-
this._outputView = undefined;
|
67
|
-
this._wordsMatchRegExp = env.features.isRegExpUnicodePropertySupported ?
|
68
|
-
// Usage of regular expression literal cause error during build (ckeditor/ckeditor5-dev#534).
|
69
|
-
// Groups:
|
70
|
-
// {L} - Any kind of letter from any language.
|
71
|
-
// {N} - Any kind of numeric character in any script.
|
72
|
-
new RegExp('([\\p{L}\\p{N}]+\\S?)+', 'gu') :
|
73
|
-
/([a-zA-Z0-9À-ž]+\S?)+/gu;
|
74
|
-
}
|
75
|
-
/**
|
76
|
-
* @inheritDoc
|
77
|
-
*/
|
78
|
-
static get pluginName() {
|
79
|
-
return 'WordCount';
|
80
|
-
}
|
81
|
-
/**
|
82
|
-
* @inheritDoc
|
83
|
-
*/
|
84
|
-
init() {
|
85
|
-
const editor = this.editor;
|
86
|
-
editor.model.document.on('change:data', throttle(this._refreshStats.bind(this), 250));
|
87
|
-
if (typeof this._config.onUpdate == 'function') {
|
88
|
-
this.on('update', (evt, data) => {
|
89
|
-
this._config.onUpdate(data);
|
90
|
-
});
|
91
|
-
}
|
92
|
-
if (isElement(this._config.container)) {
|
93
|
-
this._config.container.appendChild(this.wordCountContainer);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
/**
|
97
|
-
* @inheritDoc
|
98
|
-
*/
|
99
|
-
destroy() {
|
100
|
-
if (this._outputView) {
|
101
|
-
this._outputView.element.remove();
|
102
|
-
this._outputView.destroy();
|
103
|
-
}
|
104
|
-
super.destroy();
|
105
|
-
}
|
106
|
-
/**
|
107
|
-
* Creates a self-updating HTML element. Repeated executions return the same element.
|
108
|
-
* The returned element has the following HTML structure:
|
109
|
-
*
|
110
|
-
* ```html
|
111
|
-
* <div class="ck ck-word-count">
|
112
|
-
* <div class="ck-word-count__words">Words: 4</div>
|
113
|
-
* <div class="ck-word-count__characters">Characters: 28</div>
|
114
|
-
* </div>
|
115
|
-
* ```
|
116
|
-
*/
|
117
|
-
get wordCountContainer() {
|
118
|
-
const editor = this.editor;
|
119
|
-
const t = editor.t;
|
120
|
-
const displayWords = editor.config.get('wordCount.displayWords');
|
121
|
-
const displayCharacters = editor.config.get('wordCount.displayCharacters');
|
122
|
-
const bind = Template.bind(this, this);
|
123
|
-
const children = [];
|
124
|
-
if (!this._outputView) {
|
125
|
-
this._outputView = new View();
|
126
|
-
if (displayWords || displayWords === undefined) {
|
127
|
-
this.bind('_wordsLabel').to(this, 'words', words => {
|
128
|
-
return t('Words: %0', words);
|
129
|
-
});
|
130
|
-
children.push({
|
131
|
-
tag: 'div',
|
132
|
-
children: [
|
133
|
-
{
|
134
|
-
text: [bind.to('_wordsLabel')]
|
135
|
-
}
|
136
|
-
],
|
137
|
-
attributes: {
|
138
|
-
class: 'ck-word-count__words'
|
139
|
-
}
|
140
|
-
});
|
141
|
-
}
|
142
|
-
if (displayCharacters || displayCharacters === undefined) {
|
143
|
-
this.bind('_charactersLabel').to(this, 'characters', words => {
|
144
|
-
return t('Characters: %0', words);
|
145
|
-
});
|
146
|
-
children.push({
|
147
|
-
tag: 'div',
|
148
|
-
children: [
|
149
|
-
{
|
150
|
-
text: [bind.to('_charactersLabel')]
|
151
|
-
}
|
152
|
-
],
|
153
|
-
attributes: {
|
154
|
-
class: 'ck-word-count__characters'
|
155
|
-
}
|
156
|
-
});
|
157
|
-
}
|
158
|
-
this._outputView.setTemplate({
|
159
|
-
tag: 'div',
|
160
|
-
attributes: {
|
161
|
-
class: [
|
162
|
-
'ck',
|
163
|
-
'ck-word-count'
|
164
|
-
]
|
165
|
-
},
|
166
|
-
children
|
167
|
-
});
|
168
|
-
this._outputView.render();
|
169
|
-
}
|
170
|
-
return this._outputView.element;
|
171
|
-
}
|
172
|
-
_getText() {
|
173
|
-
let txt = '';
|
174
|
-
for (const root of this.editor.model.document.getRoots()) {
|
175
|
-
if (txt !== '') {
|
176
|
-
// Add a delimiter, so words from each root are treated independently.
|
177
|
-
txt += '\n';
|
178
|
-
}
|
179
|
-
txt += modelElementToPlainText(root);
|
180
|
-
}
|
181
|
-
return txt;
|
182
|
-
}
|
183
|
-
/**
|
184
|
-
* Determines the number of characters in the current editor's model.
|
185
|
-
*/
|
186
|
-
_getCharacters(txt) {
|
187
|
-
return txt.replace(/\n/g, '').length;
|
188
|
-
}
|
189
|
-
/**
|
190
|
-
* Determines the number of words in the current editor's model.
|
191
|
-
*/
|
192
|
-
_getWords(txt) {
|
193
|
-
const detectedWords = txt.match(this._wordsMatchRegExp) || [];
|
194
|
-
return detectedWords.length;
|
195
|
-
}
|
196
|
-
/**
|
197
|
-
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
|
198
|
-
* It also fires the {@link #event:update}.
|
199
|
-
*
|
200
|
-
* @fires update
|
201
|
-
*/
|
202
|
-
_refreshStats() {
|
203
|
-
const txt = this._getText();
|
204
|
-
const words = this.words = this._getWords(txt);
|
205
|
-
const characters = this.characters = this._getCharacters(txt);
|
206
|
-
this.fire('update', {
|
207
|
-
words,
|
208
|
-
characters
|
209
|
-
});
|
210
|
-
}
|
211
|
-
}
|
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 } from 'ckeditor5/src/core';
|
6
|
+
import { Template, View } from 'ckeditor5/src/ui';
|
7
|
+
import { env } from 'ckeditor5/src/utils';
|
8
|
+
import { modelElementToPlainText } from './utils';
|
9
|
+
import { throttle, isElement } from 'lodash-es';
|
10
|
+
/**
|
11
|
+
* The word count plugin.
|
12
|
+
*
|
13
|
+
* This plugin calculates all words and characters in all {@link module:engine/model/text~Text text nodes} available in the model.
|
14
|
+
* It also provides an HTML element that updates its state whenever the editor content is changed.
|
15
|
+
*
|
16
|
+
* The model's data is first converted to plain text using {@link module:word-count/utils~modelElementToPlainText}.
|
17
|
+
* The number of words and characters in your text are determined based on the created plain text. Please keep in mind
|
18
|
+
* that every block in the editor is separated with a newline character, which is included in the calculation.
|
19
|
+
*
|
20
|
+
* Here are some examples of how the word and character calculations are made:
|
21
|
+
*
|
22
|
+
* ```html
|
23
|
+
* <paragraph>foo</paragraph>
|
24
|
+
* <paragraph>bar</paragraph>
|
25
|
+
* // Words: 2, Characters: 7
|
26
|
+
*
|
27
|
+
* <paragraph><$text bold="true">foo</$text>bar</paragraph>
|
28
|
+
* // Words: 1, Characters: 6
|
29
|
+
*
|
30
|
+
* <paragraph>*&^%)</paragraph>
|
31
|
+
* // Words: 0, Characters: 5
|
32
|
+
*
|
33
|
+
* <paragraph>foo(bar)</paragraph>
|
34
|
+
* //Words: 1, Characters: 8
|
35
|
+
*
|
36
|
+
* <paragraph>12345</paragraph>
|
37
|
+
* // Words: 1, Characters: 5
|
38
|
+
* ```
|
39
|
+
*/
|
40
|
+
export default class WordCount extends Plugin {
|
41
|
+
/**
|
42
|
+
* @inheritDoc
|
43
|
+
*/
|
44
|
+
constructor(editor) {
|
45
|
+
super(editor);
|
46
|
+
this.set('characters', 0);
|
47
|
+
this.set('words', 0);
|
48
|
+
// Don't wait for the #update event to set the value of the properties but obtain it right away.
|
49
|
+
// This way, accessing the properties directly returns precise numbers, e.g. for validation, etc.
|
50
|
+
// If not accessed directly, the properties will be refreshed upon #update anyway.
|
51
|
+
Object.defineProperties(this, {
|
52
|
+
characters: {
|
53
|
+
get() {
|
54
|
+
return (this.characters = this._getCharacters(this._getText()));
|
55
|
+
}
|
56
|
+
},
|
57
|
+
words: {
|
58
|
+
get() {
|
59
|
+
return (this.words = this._getWords(this._getText()));
|
60
|
+
}
|
61
|
+
}
|
62
|
+
});
|
63
|
+
this.set('_wordsLabel', undefined);
|
64
|
+
this.set('_charactersLabel', undefined);
|
65
|
+
this._config = editor.config.get('wordCount') || {};
|
66
|
+
this._outputView = undefined;
|
67
|
+
this._wordsMatchRegExp = env.features.isRegExpUnicodePropertySupported ?
|
68
|
+
// Usage of regular expression literal cause error during build (ckeditor/ckeditor5-dev#534).
|
69
|
+
// Groups:
|
70
|
+
// {L} - Any kind of letter from any language.
|
71
|
+
// {N} - Any kind of numeric character in any script.
|
72
|
+
new RegExp('([\\p{L}\\p{N}]+\\S?)+', 'gu') :
|
73
|
+
/([a-zA-Z0-9À-ž]+\S?)+/gu;
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* @inheritDoc
|
77
|
+
*/
|
78
|
+
static get pluginName() {
|
79
|
+
return 'WordCount';
|
80
|
+
}
|
81
|
+
/**
|
82
|
+
* @inheritDoc
|
83
|
+
*/
|
84
|
+
init() {
|
85
|
+
const editor = this.editor;
|
86
|
+
editor.model.document.on('change:data', throttle(this._refreshStats.bind(this), 250));
|
87
|
+
if (typeof this._config.onUpdate == 'function') {
|
88
|
+
this.on('update', (evt, data) => {
|
89
|
+
this._config.onUpdate(data);
|
90
|
+
});
|
91
|
+
}
|
92
|
+
if (isElement(this._config.container)) {
|
93
|
+
this._config.container.appendChild(this.wordCountContainer);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* @inheritDoc
|
98
|
+
*/
|
99
|
+
destroy() {
|
100
|
+
if (this._outputView) {
|
101
|
+
this._outputView.element.remove();
|
102
|
+
this._outputView.destroy();
|
103
|
+
}
|
104
|
+
super.destroy();
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
* Creates a self-updating HTML element. Repeated executions return the same element.
|
108
|
+
* The returned element has the following HTML structure:
|
109
|
+
*
|
110
|
+
* ```html
|
111
|
+
* <div class="ck ck-word-count">
|
112
|
+
* <div class="ck-word-count__words">Words: 4</div>
|
113
|
+
* <div class="ck-word-count__characters">Characters: 28</div>
|
114
|
+
* </div>
|
115
|
+
* ```
|
116
|
+
*/
|
117
|
+
get wordCountContainer() {
|
118
|
+
const editor = this.editor;
|
119
|
+
const t = editor.t;
|
120
|
+
const displayWords = editor.config.get('wordCount.displayWords');
|
121
|
+
const displayCharacters = editor.config.get('wordCount.displayCharacters');
|
122
|
+
const bind = Template.bind(this, this);
|
123
|
+
const children = [];
|
124
|
+
if (!this._outputView) {
|
125
|
+
this._outputView = new View();
|
126
|
+
if (displayWords || displayWords === undefined) {
|
127
|
+
this.bind('_wordsLabel').to(this, 'words', words => {
|
128
|
+
return t('Words: %0', words);
|
129
|
+
});
|
130
|
+
children.push({
|
131
|
+
tag: 'div',
|
132
|
+
children: [
|
133
|
+
{
|
134
|
+
text: [bind.to('_wordsLabel')]
|
135
|
+
}
|
136
|
+
],
|
137
|
+
attributes: {
|
138
|
+
class: 'ck-word-count__words'
|
139
|
+
}
|
140
|
+
});
|
141
|
+
}
|
142
|
+
if (displayCharacters || displayCharacters === undefined) {
|
143
|
+
this.bind('_charactersLabel').to(this, 'characters', words => {
|
144
|
+
return t('Characters: %0', words);
|
145
|
+
});
|
146
|
+
children.push({
|
147
|
+
tag: 'div',
|
148
|
+
children: [
|
149
|
+
{
|
150
|
+
text: [bind.to('_charactersLabel')]
|
151
|
+
}
|
152
|
+
],
|
153
|
+
attributes: {
|
154
|
+
class: 'ck-word-count__characters'
|
155
|
+
}
|
156
|
+
});
|
157
|
+
}
|
158
|
+
this._outputView.setTemplate({
|
159
|
+
tag: 'div',
|
160
|
+
attributes: {
|
161
|
+
class: [
|
162
|
+
'ck',
|
163
|
+
'ck-word-count'
|
164
|
+
]
|
165
|
+
},
|
166
|
+
children
|
167
|
+
});
|
168
|
+
this._outputView.render();
|
169
|
+
}
|
170
|
+
return this._outputView.element;
|
171
|
+
}
|
172
|
+
_getText() {
|
173
|
+
let txt = '';
|
174
|
+
for (const root of this.editor.model.document.getRoots()) {
|
175
|
+
if (txt !== '') {
|
176
|
+
// Add a delimiter, so words from each root are treated independently.
|
177
|
+
txt += '\n';
|
178
|
+
}
|
179
|
+
txt += modelElementToPlainText(root);
|
180
|
+
}
|
181
|
+
return txt;
|
182
|
+
}
|
183
|
+
/**
|
184
|
+
* Determines the number of characters in the current editor's model.
|
185
|
+
*/
|
186
|
+
_getCharacters(txt) {
|
187
|
+
return txt.replace(/\n/g, '').length;
|
188
|
+
}
|
189
|
+
/**
|
190
|
+
* Determines the number of words in the current editor's model.
|
191
|
+
*/
|
192
|
+
_getWords(txt) {
|
193
|
+
const detectedWords = txt.match(this._wordsMatchRegExp) || [];
|
194
|
+
return detectedWords.length;
|
195
|
+
}
|
196
|
+
/**
|
197
|
+
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
|
198
|
+
* It also fires the {@link #event:update}.
|
199
|
+
*
|
200
|
+
* @fires update
|
201
|
+
*/
|
202
|
+
_refreshStats() {
|
203
|
+
const txt = this._getText();
|
204
|
+
const words = this.words = this._getWords(txt);
|
205
|
+
const characters = this.characters = this._getCharacters(txt);
|
206
|
+
this.fire('update', {
|
207
|
+
words,
|
208
|
+
characters
|
209
|
+
});
|
210
|
+
}
|
211
|
+
}
|
package/src/wordcountconfig.d.ts
CHANGED
@@ -1,92 +1,92 @@
|
|
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/wordcountconfig
|
7
|
-
*/
|
8
|
-
/**
|
9
|
-
* The configuration of the word count feature.
|
10
|
-
*
|
11
|
-
* ```ts
|
12
|
-
* ClassicEditor
|
13
|
-
* .create( {
|
14
|
-
* wordCount: ... // Word count feature configuration.
|
15
|
-
* } )
|
16
|
-
* .then( ... )
|
17
|
-
* .catch( ... );
|
18
|
-
* ```
|
19
|
-
*
|
20
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
21
|
-
*/
|
22
|
-
export interface WordCountConfig {
|
23
|
-
/**
|
24
|
-
* This option allows for hiding the word counter. The element obtained through
|
25
|
-
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
|
26
|
-
* the characters part. Word counter is displayed by default when this configuration option is not defined.
|
27
|
-
*
|
28
|
-
* ```ts
|
29
|
-
* const wordCountConfig = {
|
30
|
-
* displayWords: false
|
31
|
-
* };
|
32
|
-
* ```
|
33
|
-
*
|
34
|
-
* The configuration above will result in the following container:
|
35
|
-
*
|
36
|
-
* ```html
|
37
|
-
* <div class="ck ck-word-count">
|
38
|
-
* <div class="ck-word-count__characters">Characters: 28</div>
|
39
|
-
* </div>
|
40
|
-
* ```
|
41
|
-
*/
|
42
|
-
displayWords?: boolean;
|
43
|
-
/**
|
44
|
-
* This option allows for hiding the character counter. The element obtained through
|
45
|
-
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
|
46
|
-
* the words part. Character counter is displayed by default when this configuration option is not defined.
|
47
|
-
*
|
48
|
-
* ```ts
|
49
|
-
* const wordCountConfig = {
|
50
|
-
* displayCharacters: false
|
51
|
-
* };
|
52
|
-
* ```
|
53
|
-
*
|
54
|
-
* The configuration above will result in the following container:
|
55
|
-
*
|
56
|
-
* ```html
|
57
|
-
* <div class="ck ck-word-count">
|
58
|
-
* <div class="ck-word-count__words">Words: 4</div>
|
59
|
-
* </div>
|
60
|
-
* ```
|
61
|
-
*/
|
62
|
-
displayCharacters?: boolean;
|
63
|
-
/**
|
64
|
-
* This configuration takes a function that is executed whenever the word count plugin updates its values.
|
65
|
-
* This function is called with one argument, which is an object with the `words` and `characters` keys containing
|
66
|
-
* the number of detected words and characters in the document.
|
67
|
-
*
|
68
|
-
* ```ts
|
69
|
-
* const wordCountConfig = {
|
70
|
-
* onUpdate: function( stats ) {
|
71
|
-
* doSthWithWordNumber( stats.words );
|
72
|
-
* doSthWithCharacterNumber( stats.characters );
|
73
|
-
* }
|
74
|
-
* };
|
75
|
-
* ```
|
76
|
-
*/
|
77
|
-
onUpdate?: (data: {
|
78
|
-
words: number;
|
79
|
-
characters: number;
|
80
|
-
}) => void;
|
81
|
-
/**
|
82
|
-
* Allows for providing the HTML element that the
|
83
|
-
* {@link module:word-count/wordcount~WordCount#wordCountContainer word count container} will be appended to automatically.
|
84
|
-
*
|
85
|
-
* ```ts
|
86
|
-
* const wordCountConfig = {
|
87
|
-
* container: document.getElementById( 'container-for-word-count' );
|
88
|
-
* };
|
89
|
-
* ```
|
90
|
-
*/
|
91
|
-
container?: HTMLElement;
|
92
|
-
}
|
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/wordcountconfig
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* The configuration of the word count feature.
|
10
|
+
*
|
11
|
+
* ```ts
|
12
|
+
* ClassicEditor
|
13
|
+
* .create( {
|
14
|
+
* wordCount: ... // Word count feature configuration.
|
15
|
+
* } )
|
16
|
+
* .then( ... )
|
17
|
+
* .catch( ... );
|
18
|
+
* ```
|
19
|
+
*
|
20
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
21
|
+
*/
|
22
|
+
export interface WordCountConfig {
|
23
|
+
/**
|
24
|
+
* This option allows for hiding the word counter. The element obtained through
|
25
|
+
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
|
26
|
+
* the characters part. Word counter is displayed by default when this configuration option is not defined.
|
27
|
+
*
|
28
|
+
* ```ts
|
29
|
+
* const wordCountConfig = {
|
30
|
+
* displayWords: false
|
31
|
+
* };
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
* The configuration above will result in the following container:
|
35
|
+
*
|
36
|
+
* ```html
|
37
|
+
* <div class="ck ck-word-count">
|
38
|
+
* <div class="ck-word-count__characters">Characters: 28</div>
|
39
|
+
* </div>
|
40
|
+
* ```
|
41
|
+
*/
|
42
|
+
displayWords?: boolean;
|
43
|
+
/**
|
44
|
+
* This option allows for hiding the character counter. The element obtained through
|
45
|
+
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
|
46
|
+
* the words part. Character counter is displayed by default when this configuration option is not defined.
|
47
|
+
*
|
48
|
+
* ```ts
|
49
|
+
* const wordCountConfig = {
|
50
|
+
* displayCharacters: false
|
51
|
+
* };
|
52
|
+
* ```
|
53
|
+
*
|
54
|
+
* The configuration above will result in the following container:
|
55
|
+
*
|
56
|
+
* ```html
|
57
|
+
* <div class="ck ck-word-count">
|
58
|
+
* <div class="ck-word-count__words">Words: 4</div>
|
59
|
+
* </div>
|
60
|
+
* ```
|
61
|
+
*/
|
62
|
+
displayCharacters?: boolean;
|
63
|
+
/**
|
64
|
+
* This configuration takes a function that is executed whenever the word count plugin updates its values.
|
65
|
+
* This function is called with one argument, which is an object with the `words` and `characters` keys containing
|
66
|
+
* the number of detected words and characters in the document.
|
67
|
+
*
|
68
|
+
* ```ts
|
69
|
+
* const wordCountConfig = {
|
70
|
+
* onUpdate: function( stats ) {
|
71
|
+
* doSthWithWordNumber( stats.words );
|
72
|
+
* doSthWithCharacterNumber( stats.characters );
|
73
|
+
* }
|
74
|
+
* };
|
75
|
+
* ```
|
76
|
+
*/
|
77
|
+
onUpdate?: (data: {
|
78
|
+
words: number;
|
79
|
+
characters: number;
|
80
|
+
}) => void;
|
81
|
+
/**
|
82
|
+
* Allows for providing the HTML element that the
|
83
|
+
* {@link module:word-count/wordcount~WordCount#wordCountContainer word count container} will be appended to automatically.
|
84
|
+
*
|
85
|
+
* ```ts
|
86
|
+
* const wordCountConfig = {
|
87
|
+
* container: document.getElementById( 'container-for-word-count' );
|
88
|
+
* };
|
89
|
+
* ```
|
90
|
+
*/
|
91
|
+
container?: HTMLElement;
|
92
|
+
}
|
package/src/wordcountconfig.js
CHANGED
@@ -1,5 +1,5 @@
|
|
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
|
-
export {};
|
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
|
+
export {};
|