@ckeditor/ckeditor5-word-count 41.3.0 → 41.4.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +4 -0
- package/dist/index.js +204 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/es-co.d.ts +8 -0
- package/dist/translations/es-co.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/hy.d.ts +8 -0
- package/dist/translations/hy.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/augmentation.d.ts +23 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/utils.d.ts +18 -0
- package/dist/types/wordcount.d.ts +139 -0
- package/dist/types/wordcountconfig.d.ts +96 -0
- package/package.json +3 -2
- package/src/index.d.ts +1 -1
@@ -0,0 +1,5 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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 default {"zh-cn":{"dictionary":{"Words: %0":"单词数:%0","Characters: %0":"字符数:%0"},getPluralForm(n){return 0;}}}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
import type { Translations } from 'ckeditor5';
|
7
|
+
declare const translations: Translations;
|
8
|
+
export default translations;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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 default {"zh":{"dictionary":{"Words: %0":"字數: %0","Characters: %0":"字元數: %0"},getPluralForm(n){return 0;}}}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
8
|
+
*/
|
9
|
+
import type { WordCount, WordCountConfig } from './index.js';
|
10
|
+
declare module '@ckeditor/ckeditor5-core' {
|
11
|
+
interface EditorConfig {
|
12
|
+
/**
|
13
|
+
* The configuration of the word count feature.
|
14
|
+
* It is introduced by the {@link module:word-count/wordcount~WordCount} feature.
|
15
|
+
*
|
16
|
+
* Read more in {@link module:word-count/wordcountconfig~WordCountConfig}.
|
17
|
+
*/
|
18
|
+
wordCount?: WordCountConfig;
|
19
|
+
}
|
20
|
+
interface PluginsMap {
|
21
|
+
[WordCount.pluginName]: WordCount;
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* @module word-count
|
11
|
+
*/
|
12
|
+
export { default as WordCount, type WordCountUpdateEvent } from './wordcount.js';
|
13
|
+
export type { WordCountConfig } from './wordcountconfig.js';
|
14
|
+
import './augmentation.js';
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* @module word-count/utils
|
11
|
+
*/
|
12
|
+
import type { Item } from 'ckeditor5/src/engine.js';
|
13
|
+
/**
|
14
|
+
* Returns a plain text representation of an element and its children.
|
15
|
+
*
|
16
|
+
* @returns Plain text representing the model's data.
|
17
|
+
*/
|
18
|
+
export declare function modelElementToPlainText(item: Item): string;
|
@@ -0,0 +1,139 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
8
|
+
*/
|
9
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
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
|
+
* The number of characters in the editor.
|
43
|
+
*
|
44
|
+
* @observable
|
45
|
+
* @readonly
|
46
|
+
*/
|
47
|
+
characters: number;
|
48
|
+
/**
|
49
|
+
* The number of words in the editor.
|
50
|
+
*
|
51
|
+
* @observable
|
52
|
+
* @readonly
|
53
|
+
*/
|
54
|
+
words: number;
|
55
|
+
/**
|
56
|
+
* The label used to display the words value in the {@link #wordCountContainer output container}.
|
57
|
+
*
|
58
|
+
* @observable
|
59
|
+
* @private
|
60
|
+
* @readonly
|
61
|
+
*/
|
62
|
+
_wordsLabel: string | undefined;
|
63
|
+
/**
|
64
|
+
* The label used to display the characters value in the {@link #wordCountContainer output container}.
|
65
|
+
*
|
66
|
+
* @observable
|
67
|
+
* @private
|
68
|
+
* @readonly
|
69
|
+
*/
|
70
|
+
_charactersLabel: string | undefined;
|
71
|
+
/**
|
72
|
+
* The configuration of this plugin.
|
73
|
+
*/
|
74
|
+
private _config;
|
75
|
+
/**
|
76
|
+
* The reference to a {@link module:ui/view~View view object} that contains the self-updating HTML container.
|
77
|
+
*/
|
78
|
+
private _outputView;
|
79
|
+
/**
|
80
|
+
* A regular expression used to recognize words in the editor's content.
|
81
|
+
*/
|
82
|
+
private readonly _wordsMatchRegExp;
|
83
|
+
/**
|
84
|
+
* @inheritDoc
|
85
|
+
*/
|
86
|
+
constructor(editor: Editor);
|
87
|
+
/**
|
88
|
+
* @inheritDoc
|
89
|
+
*/
|
90
|
+
static get pluginName(): "WordCount";
|
91
|
+
/**
|
92
|
+
* @inheritDoc
|
93
|
+
*/
|
94
|
+
init(): void;
|
95
|
+
/**
|
96
|
+
* @inheritDoc
|
97
|
+
*/
|
98
|
+
destroy(): void;
|
99
|
+
/**
|
100
|
+
* Creates a self-updating HTML element. Repeated executions return the same element.
|
101
|
+
* The returned element has the following HTML structure:
|
102
|
+
*
|
103
|
+
* ```html
|
104
|
+
* <div class="ck ck-word-count">
|
105
|
+
* <div class="ck-word-count__words">Words: 4</div>
|
106
|
+
* <div class="ck-word-count__characters">Characters: 28</div>
|
107
|
+
* </div>
|
108
|
+
* ```
|
109
|
+
*/
|
110
|
+
get wordCountContainer(): HTMLElement;
|
111
|
+
private _getText;
|
112
|
+
/**
|
113
|
+
* Determines the number of characters in the current editor's model.
|
114
|
+
*/
|
115
|
+
private _getCharacters;
|
116
|
+
/**
|
117
|
+
* Determines the number of words in the current editor's model.
|
118
|
+
*/
|
119
|
+
private _getWords;
|
120
|
+
/**
|
121
|
+
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
|
122
|
+
* It also fires the {@link #event:update}.
|
123
|
+
*
|
124
|
+
* @fires update
|
125
|
+
*/
|
126
|
+
private _refreshStats;
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* An event fired after {@link ~WordCount#words} and {@link ~WordCount#characters} are updated.
|
130
|
+
*
|
131
|
+
* @eventName ~WordCount#update
|
132
|
+
*/
|
133
|
+
export type WordCountUpdateEvent = {
|
134
|
+
name: 'update';
|
135
|
+
args: [{
|
136
|
+
words: number;
|
137
|
+
characters: number;
|
138
|
+
}];
|
139
|
+
};
|
@@ -0,0 +1,96 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* @module word-count/wordcountconfig
|
11
|
+
*/
|
12
|
+
/**
|
13
|
+
* The configuration of the word count feature.
|
14
|
+
*
|
15
|
+
* ```ts
|
16
|
+
* ClassicEditor
|
17
|
+
* .create( {
|
18
|
+
* wordCount: ... // Word count feature configuration.
|
19
|
+
* } )
|
20
|
+
* .then( ... )
|
21
|
+
* .catch( ... );
|
22
|
+
* ```
|
23
|
+
*
|
24
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
25
|
+
*/
|
26
|
+
export interface WordCountConfig {
|
27
|
+
/**
|
28
|
+
* This option allows for hiding the word counter. The element obtained through
|
29
|
+
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
|
30
|
+
* the characters part. Word counter is displayed by default when this configuration option is not defined.
|
31
|
+
*
|
32
|
+
* ```ts
|
33
|
+
* const wordCountConfig = {
|
34
|
+
* displayWords: false
|
35
|
+
* };
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* The configuration above will result in the following container:
|
39
|
+
*
|
40
|
+
* ```html
|
41
|
+
* <div class="ck ck-word-count">
|
42
|
+
* <div class="ck-word-count__characters">Characters: 28</div>
|
43
|
+
* </div>
|
44
|
+
* ```
|
45
|
+
*/
|
46
|
+
displayWords?: boolean;
|
47
|
+
/**
|
48
|
+
* This option allows for hiding the character counter. The element obtained through
|
49
|
+
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
|
50
|
+
* the words part. Character counter is displayed by default when this configuration option is not defined.
|
51
|
+
*
|
52
|
+
* ```ts
|
53
|
+
* const wordCountConfig = {
|
54
|
+
* displayCharacters: false
|
55
|
+
* };
|
56
|
+
* ```
|
57
|
+
*
|
58
|
+
* The configuration above will result in the following container:
|
59
|
+
*
|
60
|
+
* ```html
|
61
|
+
* <div class="ck ck-word-count">
|
62
|
+
* <div class="ck-word-count__words">Words: 4</div>
|
63
|
+
* </div>
|
64
|
+
* ```
|
65
|
+
*/
|
66
|
+
displayCharacters?: boolean;
|
67
|
+
/**
|
68
|
+
* This configuration takes a function that is executed whenever the word count plugin updates its values.
|
69
|
+
* This function is called with one argument, which is an object with the `words` and `characters` keys containing
|
70
|
+
* the number of detected words and characters in the document.
|
71
|
+
*
|
72
|
+
* ```ts
|
73
|
+
* const wordCountConfig = {
|
74
|
+
* onUpdate: function( stats ) {
|
75
|
+
* doSthWithWordNumber( stats.words );
|
76
|
+
* doSthWithCharacterNumber( stats.characters );
|
77
|
+
* }
|
78
|
+
* };
|
79
|
+
* ```
|
80
|
+
*/
|
81
|
+
onUpdate?: (data: {
|
82
|
+
words: number;
|
83
|
+
characters: number;
|
84
|
+
}) => void;
|
85
|
+
/**
|
86
|
+
* Allows for providing the HTML element that the
|
87
|
+
* {@link module:word-count/wordcount~WordCount#wordCountContainer word count container} will be appended to automatically.
|
88
|
+
*
|
89
|
+
* ```ts
|
90
|
+
* const wordCountConfig = {
|
91
|
+
* container: document.getElementById( 'container-for-word-count' );
|
92
|
+
* };
|
93
|
+
* ```
|
94
|
+
*/
|
95
|
+
container?: HTMLElement;
|
96
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-word-count",
|
3
|
-
"version": "41.
|
3
|
+
"version": "41.4.0-alpha.0",
|
4
4
|
"description": "Word and character count feature for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"main": "src/index.js",
|
15
15
|
"dependencies": {
|
16
16
|
"lodash-es": "4.17.21",
|
17
|
-
"ckeditor5": "41.
|
17
|
+
"ckeditor5": "41.4.0-alpha.0"
|
18
18
|
},
|
19
19
|
"author": "CKSource (http://cksource.com/)",
|
20
20
|
"license": "GPL-2.0-or-later",
|
@@ -26,6 +26,7 @@
|
|
26
26
|
"directory": "packages/ckeditor5-word-count"
|
27
27
|
},
|
28
28
|
"files": [
|
29
|
+
"dist",
|
29
30
|
"lang",
|
30
31
|
"src/**/*.js",
|
31
32
|
"src/**/*.d.ts",
|
package/src/index.d.ts
CHANGED