@tiptap/extension-character-count
Advanced tools
Comparing version 2.10.2 to 2.10.3
@@ -41,5 +41,27 @@ import { Extension } from '@tiptap/core'; | ||
addProseMirrorPlugins() { | ||
let initialEvaluationDone = false; | ||
return [ | ||
new Plugin({ | ||
key: new PluginKey('characterCount'), | ||
appendTransaction: (transactions, oldState, newState) => { | ||
if (initialEvaluationDone) { | ||
return; | ||
} | ||
const limit = this.options.limit; | ||
if (limit === null || limit === undefined || limit === 0) { | ||
initialEvaluationDone = true; | ||
return; | ||
} | ||
const initialContentSize = this.storage.characters({ node: newState.doc }); | ||
if (initialContentSize > limit) { | ||
const over = initialContentSize - limit; | ||
const from = 0; | ||
const to = over; | ||
console.warn(`[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`); | ||
const tr = newState.tr.deleteRange(from, to); | ||
initialEvaluationDone = true; | ||
return tr; | ||
} | ||
initialEvaluationDone = true; | ||
}, | ||
filterTransaction: (transaction, state) => { | ||
@@ -46,0 +68,0 @@ const limit = this.options.limit; |
@@ -44,5 +44,27 @@ (function (global, factory) { | ||
addProseMirrorPlugins() { | ||
let initialEvaluationDone = false; | ||
return [ | ||
new state.Plugin({ | ||
key: new state.PluginKey('characterCount'), | ||
appendTransaction: (transactions, oldState, newState) => { | ||
if (initialEvaluationDone) { | ||
return; | ||
} | ||
const limit = this.options.limit; | ||
if (limit === null || limit === undefined || limit === 0) { | ||
initialEvaluationDone = true; | ||
return; | ||
} | ||
const initialContentSize = this.storage.characters({ node: newState.doc }); | ||
if (initialContentSize > limit) { | ||
const over = initialContentSize - limit; | ||
const from = 0; | ||
const to = over; | ||
console.warn(`[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`); | ||
const tr = newState.tr.deleteRange(from, to); | ||
initialEvaluationDone = true; | ||
return tr; | ||
} | ||
initialEvaluationDone = true; | ||
}, | ||
filterTransaction: (transaction, state) => { | ||
@@ -49,0 +71,0 @@ const limit = this.options.limit; |
{ | ||
"name": "@tiptap/extension-character-count", | ||
"description": "font family extension for tiptap", | ||
"version": "2.10.2", | ||
"version": "2.10.3", | ||
"homepage": "https://tiptap.dev", | ||
@@ -32,4 +32,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@tiptap/core": "^2.10.2", | ||
"@tiptap/pm": "^2.10.2" | ||
"@tiptap/core": "^2.10.3", | ||
"@tiptap/pm": "^2.10.3" | ||
}, | ||
@@ -36,0 +36,0 @@ "peerDependencies": { |
@@ -96,5 +96,35 @@ import { Extension } from '@tiptap/core' | ||
addProseMirrorPlugins() { | ||
let initialEvaluationDone = false | ||
return [ | ||
new Plugin({ | ||
key: new PluginKey('characterCount'), | ||
appendTransaction: (transactions, oldState, newState) => { | ||
if (initialEvaluationDone) { | ||
return | ||
} | ||
const limit = this.options.limit | ||
if (limit === null || limit === undefined || limit === 0) { | ||
initialEvaluationDone = true | ||
return | ||
} | ||
const initialContentSize = this.storage.characters({ node: newState.doc }) | ||
if (initialContentSize > limit) { | ||
const over = initialContentSize - limit | ||
const from = 0 | ||
const to = over | ||
console.warn(`[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`) | ||
const tr = newState.tr.deleteRange(from, to) | ||
initialEvaluationDone = true | ||
return tr | ||
} | ||
initialEvaluationDone = true | ||
}, | ||
filterTransaction: (transaction, state) => { | ||
@@ -101,0 +131,0 @@ const limit = this.options.limit |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58459
562