@tiptap/extension-character-count 2.0.0-beta.21 → 2.0.0-beta.25

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-character-count",
3
3
  "description": "font family extension for tiptap",
4
- "version": "2.0.0-beta.21",
4
+ "version": "2.0.0-beta.25",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -24,10 +24,14 @@
24
24
  "@tiptap/core": "^2.0.0-beta.1",
25
25
  "@tiptap/extension-text-style": "^2.0.0-beta.1"
26
26
  },
27
+ "dependencies": {
28
+ "prosemirror-model": "^1.16.1",
29
+ "prosemirror-state": "^1.3.4"
30
+ },
27
31
  "repository": {
28
32
  "type": "git",
29
33
  "url": "https://github.com/ueberdosis/tiptap",
30
34
  "directory": "packages/extension-character-count"
31
35
  },
32
- "gitHead": "914c75b3056cdbfc74c1ae585a36c5d13655595d"
36
+ "gitHead": "4b128e17be3e057ac9e1a4a38565d2b91aabe4ea"
33
37
  }
@@ -6,7 +6,7 @@ export interface CharacterCountOptions {
6
6
  /**
7
7
  * The maximum number of characters that should be allowed. Defaults to `0`.
8
8
  */
9
- limit: number,
9
+ limit: number | null | undefined,
10
10
  /**
11
11
  * The mode by which the size is calculated. Defaults to 'textSize'.
12
12
  */
@@ -17,7 +17,7 @@ export interface CharacterCountStorage {
17
17
  /**
18
18
  * Get the number of characters for the current document.
19
19
  */
20
- characters?: (options?: {
20
+ characters: (options?: {
21
21
  node?: ProseMirrorNode,
22
22
  mode?: 'textSize' | 'nodeSize',
23
23
  }) => number,
@@ -25,7 +25,7 @@ export interface CharacterCountStorage {
25
25
  /**
26
26
  * Get the number of words for the current document.
27
27
  */
28
- words?: (options?: {
28
+ words: (options?: {
29
29
  node?: ProseMirrorNode,
30
30
  }) => number,
31
31
  }
@@ -35,15 +35,15 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC
35
35
 
36
36
  addOptions() {
37
37
  return {
38
- limit: 0,
38
+ limit: null,
39
39
  mode: 'textSize',
40
40
  }
41
41
  },
42
42
 
43
43
  addStorage() {
44
44
  return {
45
- characters: undefined,
46
- words: undefined,
45
+ characters: () => 0,
46
+ words: () => 0,
47
47
  }
48
48
  },
49
49
 
@@ -80,12 +80,12 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC
80
80
  const limit = this.options.limit
81
81
 
82
82
  // Nothing has changed or no limit is defined. Ignore it.
83
- if (!transaction.docChanged || limit === 0) {
83
+ if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {
84
84
  return true
85
85
  }
86
86
 
87
- const oldSize = this.storage.characters?.({ node: state.doc }) || 0
88
- const newSize = this.storage.characters?.({ node: transaction.doc }) || 0
87
+ const oldSize = this.storage.characters({ node: state.doc })
88
+ const newSize = this.storage.characters({ node: transaction.doc })
89
89
 
90
90
  // Everything is in the limit. Good.
91
91
  if (newSize <= limit) {
@@ -123,7 +123,7 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC
123
123
  // This happens e.g. when truncating within a complex node (e.g. table)
124
124
  // and ProseMirror has to close this node again.
125
125
  // If this is the case, we prevent the transaction completely.
126
- const updatedSize = this.storage.characters?.({ node: transaction.doc }) || 0
126
+ const updatedSize = this.storage.characters({ node: transaction.doc })
127
127
 
128
128
  if (updatedSize > limit) {
129
129
  return false