@ckeditor/ckeditor5-word-count 36.0.1 → 37.0.0-alpha.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-word-count",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.1",
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.1"
16
+ "ckeditor5": "^37.0.0-alpha.1"
17
17
  },
18
18
  "devDependencies": {
19
- "@ckeditor/ckeditor5-basic-styles": "^36.0.1",
20
- "@ckeditor/ckeditor5-block-quote": "^36.0.1",
21
- "@ckeditor/ckeditor5-core": "^36.0.1",
22
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
23
- "@ckeditor/ckeditor5-editor-classic": "^36.0.1",
24
- "@ckeditor/ckeditor5-engine": "^36.0.1",
25
- "@ckeditor/ckeditor5-enter": "^36.0.1",
26
- "@ckeditor/ckeditor5-image": "^36.0.1",
27
- "@ckeditor/ckeditor5-link": "^36.0.1",
28
- "@ckeditor/ckeditor5-list": "^36.0.1",
29
- "@ckeditor/ckeditor5-paragraph": "^36.0.1",
30
- "@ckeditor/ckeditor5-table": "^36.0.1",
31
- "@ckeditor/ckeditor5-theme-lark": "^36.0.1",
32
- "@ckeditor/ckeditor5-utils": "^36.0.1",
19
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.1",
20
+ "@ckeditor/ckeditor5-block-quote": "^37.0.0-alpha.1",
21
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.1",
22
+ "@ckeditor/ckeditor5-dev-utils": "^35.0.0",
23
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.1",
24
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.1",
25
+ "@ckeditor/ckeditor5-enter": "^37.0.0-alpha.1",
26
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.1",
27
+ "@ckeditor/ckeditor5-link": "^37.0.0-alpha.1",
28
+ "@ckeditor/ckeditor5-list": "^37.0.0-alpha.1",
29
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.1",
30
+ "@ckeditor/ckeditor5-table": "^37.0.0-alpha.1",
31
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.1",
32
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.1",
33
33
  "typescript": "^4.8.4",
34
34
  "webpack": "^5.58.1",
35
35
  "webpack-cli": "^4.9.0"
@@ -58,7 +58,8 @@
58
58
  ],
59
59
  "scripts": {
60
60
  "dll:build": "webpack",
61
- "build": "tsc -p ./tsconfig.release.json",
61
+ "build": "tsc -p ./tsconfig.json",
62
62
  "postversion": "npm run build"
63
- }
63
+ },
64
+ "types": "src/index.d.ts"
64
65
  }
@@ -0,0 +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
+ }
@@ -0,0 +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 {};
package/src/index.d.ts ADDED
@@ -0,0 +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';
package/src/index.js CHANGED
@@ -6,3 +6,4 @@
6
6
  * @module word-count
7
7
  */
8
8
  export { default as WordCount } from './wordcount';
9
+ import './augmentation';
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,134 @@
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 ~WordCount#words} and {@link ~WordCount#characters} are updated.
125
+ *
126
+ * @eventName ~WordCount#update
127
+ */
128
+ export type WordCountUpdateEvent = {
129
+ name: 'update';
130
+ args: [{
131
+ words: number;
132
+ characters: number;
133
+ }];
134
+ };
@@ -0,0 +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
+ }
@@ -0,0 +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 {};