Skip to content

Commit

Permalink
fix: mark characterCount storage method types as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kühn authored and Philipp Kühn committed Dec 10, 2021
1 parent 914c75b commit ed7f93a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/extension-character-count/src/character-count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export interface CharacterCountStorage {
/**
* Get the number of characters for the current document.
*/
characters?: (options?: {
characters: (options?: {
node?: ProseMirrorNode,
mode?: 'textSize' | 'nodeSize',
}) => number,

/**
* Get the number of words for the current document.
*/
words?: (options?: {
words: (options?: {
node?: ProseMirrorNode,
}) => number,
}
Expand All @@ -42,8 +42,8 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC

addStorage() {
return {
characters: undefined,
words: undefined,
characters: () => 0,
words: () => 0,
}
},

Expand Down Expand Up @@ -84,8 +84,8 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC
return true
}

const oldSize = this.storage.characters?.({ node: state.doc }) || 0
const newSize = this.storage.characters?.({ node: transaction.doc }) || 0
const oldSize = this.storage.characters({ node: state.doc })
const newSize = this.storage.characters({ node: transaction.doc })

// Everything is in the limit. Good.
if (newSize <= limit) {
Expand Down Expand Up @@ -123,7 +123,7 @@ export const CharacterCount = Extension.create<CharacterCountOptions, CharacterC
// This happens e.g. when truncating within a complex node (e.g. table)
// and ProseMirror has to close this node again.
// If this is the case, we prevent the transaction completely.
const updatedSize = this.storage.characters?.({ node: transaction.doc }) || 0
const updatedSize = this.storage.characters({ node: transaction.doc })

if (updatedSize > limit) {
return false
Expand Down

0 comments on commit ed7f93a

Please sign in to comment.