@contentful/field-editor-rich-text 4.14.0 → 4.14.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.
@@ -8,20 +8,26 @@ Object.defineProperty(exports, "withCharCounter", {
8
8
  return withCharCounter;
9
9
  }
10
10
  });
11
- const _utils = require("./utils");
12
11
  const _pdebounce = /*#__PURE__*/ _interop_require_default(require("p-debounce"));
12
+ const _utils = require("./utils");
13
13
  function _interop_require_default(obj) {
14
14
  return obj && obj.__esModule ? obj : {
15
15
  default: obj
16
16
  };
17
17
  }
18
+ const CHARACTER_COUNT_DEBOUNCE_TIME = 300;
18
19
  const withCharCounter = (editor)=>{
19
20
  const { apply } = editor;
20
- let count = (0, _utils.getTextContent)(editor).length;
21
- editor.getCharacterCount = ()=>count;
21
+ let count;
22
+ editor.getCharacterCount = ()=>{
23
+ if (count === undefined) {
24
+ count = (0, _utils.getTextContent)(editor).length;
25
+ }
26
+ return count;
27
+ };
22
28
  const recount = (0, _pdebounce.default)(async ()=>{
23
29
  count = (0, _utils.getTextContent)(editor).length;
24
- }, 300);
30
+ }, CHARACTER_COUNT_DEBOUNCE_TIME);
25
31
  editor.apply = (op)=>{
26
32
  apply(op);
27
33
  recount();
@@ -1,12 +1,18 @@
1
- import { getTextContent } from './utils';
2
1
  import debounce from 'p-debounce';
2
+ import { getTextContent } from './utils';
3
+ const CHARACTER_COUNT_DEBOUNCE_TIME = 300;
3
4
  export const withCharCounter = (editor)=>{
4
5
  const { apply } = editor;
5
- let count = getTextContent(editor).length;
6
- editor.getCharacterCount = ()=>count;
6
+ let count;
7
+ editor.getCharacterCount = ()=>{
8
+ if (count === undefined) {
9
+ count = getTextContent(editor).length;
10
+ }
11
+ return count;
12
+ };
7
13
  const recount = debounce(async ()=>{
8
14
  count = getTextContent(editor).length;
9
- }, 300);
15
+ }, CHARACTER_COUNT_DEBOUNCE_TIME);
10
16
  editor.apply = (op)=>{
11
17
  apply(op);
12
18
  recount();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "4.14.0",
3
+ "version": "4.14.1",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "registry": "https://npm.pkg.github.com/"
91
91
  },
92
- "gitHead": "5e69589554e4e8e0870f08886848dc13434573ca"
92
+ "gitHead": "95b2a596fbc722c9b541b89f47639e267652740c"
93
93
  }