@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/lang/translations/tk.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Turkmen (https://app.transifex.com/ckeditor/teams/11143/tk/)\n"
|
16
16
|
"Language: tk\n"
|
17
17
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/lang/translations/tr.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Turkish (https://app.transifex.com/ckeditor/teams/11143/tr/)\n"
|
16
16
|
"Language: tr\n"
|
17
17
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/lang/translations/ug.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Uyghur (https://app.transifex.com/ckeditor/teams/11143/ug/)\n"
|
16
16
|
"Language: ug\n"
|
17
17
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/lang/translations/uk.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Ukrainian (https://app.transifex.com/ckeditor/teams/11143/uk/)\n"
|
16
16
|
"Language: uk\n"
|
17
17
|
"Plural-Forms: nplurals=4; plural=(n % 1 == 0 && n % 10 == 1 && n % 100 != 11 ? 0 : n % 1 == 0 && n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14) ? 1 : n % 1 == 0 && (n % 10 ==0 || (n % 10 >=5 && n % 10 <=9) || (n % 100 >=11 && n % 100 <=14 )) ? 2: 3);\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/lang/translations/ur.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Urdu (https://app.transifex.com/ckeditor/teams/11143/ur/)\n"
|
16
16
|
"Language: ur\n"
|
17
17
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/lang/translations/vi.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Vietnamese (https://app.transifex.com/ckeditor/teams/11143/vi/)\n"
|
16
16
|
"Language: vi\n"
|
17
17
|
"Plural-Forms: nplurals=1; plural=0;\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Chinese (China) (https://app.transifex.com/ckeditor/teams/11143/zh_CN/)\n"
|
16
16
|
"Language: zh_CN\n"
|
17
17
|
"Plural-Forms: nplurals=1; plural=0;\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/lang/translations/zh.po
CHANGED
@@ -15,6 +15,7 @@ msgstr ""
|
|
15
15
|
"Language-Team: Chinese (Taiwan) (https://app.transifex.com/ckeditor/teams/11143/zh_TW/)\n"
|
16
16
|
"Language: zh_TW\n"
|
17
17
|
"Plural-Forms: nplurals=1; plural=0;\n"
|
18
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
19
|
|
19
20
|
msgctxt "Label showing the number of words in the editor content."
|
20
21
|
msgid "Words: %0"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-word-count",
|
3
|
-
"version": "
|
3
|
+
"version": "40.0.0",
|
4
4
|
"description": "Word and character count feature for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -13,11 +13,7 @@
|
|
13
13
|
"main": "src/index.js",
|
14
14
|
"dependencies": {
|
15
15
|
"lodash-es": "4.17.21",
|
16
|
-
"ckeditor5": "
|
17
|
-
},
|
18
|
-
"engines": {
|
19
|
-
"node": ">=16.0.0",
|
20
|
-
"npm": ">=5.7.1"
|
16
|
+
"ckeditor5": "40.0.0"
|
21
17
|
},
|
22
18
|
"author": "CKSource (http://cksource.com/)",
|
23
19
|
"license": "GPL-2.0-or-later",
|
package/src/augmentation.d.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
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 type { WordCount, WordCountConfig } from './index';
|
6
|
-
declare module '@ckeditor/ckeditor5-core' {
|
7
|
-
interface EditorConfig {
|
8
|
-
/**
|
9
|
-
* The configuration of the word count feature.
|
10
|
-
* It is introduced by the {@link module:word-count/wordcount~WordCount} feature.
|
11
|
-
*
|
12
|
-
* Read more in {@link module:word-count/wordcountconfig~WordCountConfig}.
|
13
|
-
*/
|
14
|
-
wordCount?: WordCountConfig;
|
15
|
-
}
|
16
|
-
interface PluginsMap {
|
17
|
-
[WordCount.pluginName]: WordCount;
|
18
|
-
}
|
19
|
-
}
|
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 type { WordCount, WordCountConfig } from './index';
|
6
|
+
declare module '@ckeditor/ckeditor5-core' {
|
7
|
+
interface EditorConfig {
|
8
|
+
/**
|
9
|
+
* The configuration of the word count feature.
|
10
|
+
* It is introduced by the {@link module:word-count/wordcount~WordCount} feature.
|
11
|
+
*
|
12
|
+
* Read more in {@link module:word-count/wordcountconfig~WordCountConfig}.
|
13
|
+
*/
|
14
|
+
wordCount?: WordCountConfig;
|
15
|
+
}
|
16
|
+
interface PluginsMap {
|
17
|
+
[WordCount.pluginName]: WordCount;
|
18
|
+
}
|
19
|
+
}
|
package/src/augmentation.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 {};
|
package/src/index.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
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';
|
9
|
-
export { WordCountConfig } from './wordcountconfig';
|
10
|
-
import './augmentation';
|
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';
|
9
|
+
export { WordCountConfig } from './wordcountconfig';
|
10
|
+
import './augmentation';
|
package/src/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
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 } from './wordcount';
|
9
|
-
import './augmentation';
|
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 } from './wordcount';
|
9
|
+
import './augmentation';
|
package/src/utils.d.ts
CHANGED
@@ -1,14 +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;
|
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;
|
package/src/utils.js
CHANGED
@@ -1,27 +1,27 @@
|
|
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
|
-
* Returns a plain text representation of an element and its children.
|
7
|
-
*
|
8
|
-
* @returns Plain text representing the model's data.
|
9
|
-
*/
|
10
|
-
export function modelElementToPlainText(item) {
|
11
|
-
if (item.is('$text') || item.is('$textProxy')) {
|
12
|
-
return item.data;
|
13
|
-
}
|
14
|
-
const element = item;
|
15
|
-
let text = '';
|
16
|
-
let prev = null;
|
17
|
-
for (const child of element.getChildren()) {
|
18
|
-
const childText = modelElementToPlainText(child);
|
19
|
-
// If last block was finish, start from new line.
|
20
|
-
if (prev && prev.is('element')) {
|
21
|
-
text += '\n';
|
22
|
-
}
|
23
|
-
text += childText;
|
24
|
-
prev = child;
|
25
|
-
}
|
26
|
-
return text;
|
27
|
-
}
|
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
|
+
* Returns a plain text representation of an element and its children.
|
7
|
+
*
|
8
|
+
* @returns Plain text representing the model's data.
|
9
|
+
*/
|
10
|
+
export function modelElementToPlainText(item) {
|
11
|
+
if (item.is('$text') || item.is('$textProxy')) {
|
12
|
+
return item.data;
|
13
|
+
}
|
14
|
+
const element = item;
|
15
|
+
let text = '';
|
16
|
+
let prev = null;
|
17
|
+
for (const child of element.getChildren()) {
|
18
|
+
const childText = modelElementToPlainText(child);
|
19
|
+
// If last block was finish, start from new line.
|
20
|
+
if (prev && prev.is('element')) {
|
21
|
+
text += '\n';
|
22
|
+
}
|
23
|
+
text += childText;
|
24
|
+
prev = child;
|
25
|
+
}
|
26
|
+
return text;
|
27
|
+
}
|
package/src/wordcount.d.ts
CHANGED
@@ -1,135 +1,135 @@
|
|
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
|
-
private _getText;
|
108
|
-
/**
|
109
|
-
* Determines the number of characters in the current editor's model.
|
110
|
-
*/
|
111
|
-
private _getCharacters;
|
112
|
-
/**
|
113
|
-
* Determines the number of words in the current editor's model.
|
114
|
-
*/
|
115
|
-
private _getWords;
|
116
|
-
/**
|
117
|
-
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
|
118
|
-
* It also fires the {@link #event:update}.
|
119
|
-
*
|
120
|
-
* @fires update
|
121
|
-
*/
|
122
|
-
private _refreshStats;
|
123
|
-
}
|
124
|
-
/**
|
125
|
-
* An event fired after {@link ~WordCount#words} and {@link ~WordCount#characters} are updated.
|
126
|
-
*
|
127
|
-
* @eventName ~WordCount#update
|
128
|
-
*/
|
129
|
-
export type WordCountUpdateEvent = {
|
130
|
-
name: 'update';
|
131
|
-
args: [{
|
132
|
-
words: number;
|
133
|
-
characters: number;
|
134
|
-
}];
|
135
|
-
};
|
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
|
+
private _getText;
|
108
|
+
/**
|
109
|
+
* Determines the number of characters in the current editor's model.
|
110
|
+
*/
|
111
|
+
private _getCharacters;
|
112
|
+
/**
|
113
|
+
* Determines the number of words in the current editor's model.
|
114
|
+
*/
|
115
|
+
private _getWords;
|
116
|
+
/**
|
117
|
+
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
|
118
|
+
* It also fires the {@link #event:update}.
|
119
|
+
*
|
120
|
+
* @fires update
|
121
|
+
*/
|
122
|
+
private _refreshStats;
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* An event fired after {@link ~WordCount#words} and {@link ~WordCount#characters} are updated.
|
126
|
+
*
|
127
|
+
* @eventName ~WordCount#update
|
128
|
+
*/
|
129
|
+
export type WordCountUpdateEvent = {
|
130
|
+
name: 'update';
|
131
|
+
args: [{
|
132
|
+
words: number;
|
133
|
+
characters: number;
|
134
|
+
}];
|
135
|
+
};
|