@tiptap/extension-character-count 2.0.0-beta.21 → 2.0.0-beta.22
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/dist/packages/extension-character-count/src/character-count.d.ts +2 -2
- package/dist/tiptap-extension-character-count.cjs.js +5 -6
- package/dist/tiptap-extension-character-count.cjs.js.map +1 -1
- package/dist/tiptap-extension-character-count.esm.js +5 -6
- package/dist/tiptap-extension-character-count.esm.js.map +1 -1
- package/dist/tiptap-extension-character-count.umd.js +5 -6
- package/dist/tiptap-extension-character-count.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/character-count.ts +7 -7
|
@@ -14,14 +14,14 @@ export interface CharacterCountStorage {
|
|
|
14
14
|
/**
|
|
15
15
|
* Get the number of characters for the current document.
|
|
16
16
|
*/
|
|
17
|
-
characters
|
|
17
|
+
characters: (options?: {
|
|
18
18
|
node?: ProseMirrorNode;
|
|
19
19
|
mode?: 'textSize' | 'nodeSize';
|
|
20
20
|
}) => number;
|
|
21
21
|
/**
|
|
22
22
|
* Get the number of words for the current document.
|
|
23
23
|
*/
|
|
24
|
-
words
|
|
24
|
+
words: (options?: {
|
|
25
25
|
node?: ProseMirrorNode;
|
|
26
26
|
}) => number;
|
|
27
27
|
}
|
|
@@ -5296,8 +5296,8 @@ const CharacterCount = core.Extension.create({
|
|
|
5296
5296
|
},
|
|
5297
5297
|
addStorage() {
|
|
5298
5298
|
return {
|
|
5299
|
-
characters:
|
|
5300
|
-
words:
|
|
5299
|
+
characters: () => 0,
|
|
5300
|
+
words: () => 0,
|
|
5301
5301
|
};
|
|
5302
5302
|
},
|
|
5303
5303
|
onBeforeCreate() {
|
|
@@ -5324,14 +5324,13 @@ const CharacterCount = core.Extension.create({
|
|
|
5324
5324
|
new Plugin({
|
|
5325
5325
|
key: new PluginKey('characterCount'),
|
|
5326
5326
|
filterTransaction: (transaction, state) => {
|
|
5327
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5328
5327
|
const limit = this.options.limit;
|
|
5329
5328
|
// Nothing has changed or no limit is defined. Ignore it.
|
|
5330
5329
|
if (!transaction.docChanged || limit === 0) {
|
|
5331
5330
|
return true;
|
|
5332
5331
|
}
|
|
5333
|
-
const oldSize =
|
|
5334
|
-
const newSize =
|
|
5332
|
+
const oldSize = this.storage.characters({ node: state.doc });
|
|
5333
|
+
const newSize = this.storage.characters({ node: transaction.doc });
|
|
5335
5334
|
// Everything is in the limit. Good.
|
|
5336
5335
|
if (newSize <= limit) {
|
|
5337
5336
|
return true;
|
|
@@ -5361,7 +5360,7 @@ const CharacterCount = core.Extension.create({
|
|
|
5361
5360
|
// This happens e.g. when truncating within a complex node (e.g. table)
|
|
5362
5361
|
// and ProseMirror has to close this node again.
|
|
5363
5362
|
// If this is the case, we prevent the transaction completely.
|
|
5364
|
-
const updatedSize =
|
|
5363
|
+
const updatedSize = this.storage.characters({ node: transaction.doc });
|
|
5365
5364
|
if (updatedSize > limit) {
|
|
5366
5365
|
return false;
|
|
5367
5366
|
}
|