@contentful/field-editor-rich-text 6.6.7 → 6.6.8

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.
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "ButtonRedo", {
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_default(require("react"));
12
12
  const _f36icons = require("@contentful/f36-icons");
13
+ const _react1 = require("platejs/react");
13
14
  const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
14
15
  const _ToolbarButton = require("../../plugins/shared/ToolbarButton");
15
16
  function _interop_require_default(obj) {
@@ -18,7 +19,8 @@ function _interop_require_default(obj) {
18
19
  };
19
20
  }
20
21
  const ButtonRedo = ()=>{
21
- const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
22
+ const editor = (0, _ContentfulEditorProvider.useContentfulEditorRef)();
23
+ const isDisabled = (0, _react1.useEditorSelector)((editor)=>editor.history.redos.length === 0, []);
22
24
  const onClickHandler = ()=>{
23
25
  editor.redo('toolbar');
24
26
  };
@@ -27,7 +29,7 @@ const ButtonRedo = ()=>{
27
29
  testId: "redo-toolbar-button",
28
30
  onClick: onClickHandler,
29
31
  isActive: false,
30
- isDisabled: editor.history.redos.length === 0
32
+ isDisabled: isDisabled
31
33
  }, /*#__PURE__*/ _react.default.createElement(_f36icons.ArrowUUpRightIcon, {
32
34
  "aria-label": "Redo"
33
35
  }));
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "ButtonUndo", {
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_default(require("react"));
12
12
  const _f36icons = require("@contentful/f36-icons");
13
+ const _react1 = require("platejs/react");
13
14
  const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
14
15
  const _ToolbarButton = require("../../plugins/shared/ToolbarButton");
15
16
  function _interop_require_default(obj) {
@@ -18,7 +19,8 @@ function _interop_require_default(obj) {
18
19
  };
19
20
  }
20
21
  const ButtonUndo = ()=>{
21
- const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
22
+ const editor = (0, _ContentfulEditorProvider.useContentfulEditorRef)();
23
+ const isDisabled = (0, _react1.useEditorSelector)((editor)=>editor.history.undos.length === 0, []);
22
24
  const onClickHandler = ()=>{
23
25
  editor.undo('toolbar');
24
26
  };
@@ -27,7 +29,7 @@ const ButtonUndo = ()=>{
27
29
  testId: "undo-toolbar-button",
28
30
  onClick: onClickHandler,
29
31
  isActive: false,
30
- isDisabled: editor.history.undos.length === 0
32
+ isDisabled: isDisabled
31
33
  }, /*#__PURE__*/ _react.default.createElement(_f36icons.ArrowUUpLeftIcon, {
32
34
  "aria-label": "Undo"
33
35
  }));
@@ -14,7 +14,7 @@ const _f36icons = require("@contentful/f36-icons");
14
14
  const _f36tokens = /*#__PURE__*/ _interop_require_default(require("@contentful/f36-tokens"));
15
15
  const _richtexttypes = require("@contentful/rich-text-types");
16
16
  const _css = require("@emotion/css");
17
- const _ContentfulEditorProvider = require("../ContentfulEditorProvider");
17
+ const _react1 = require("platejs/react");
18
18
  const _editor = require("../helpers/editor");
19
19
  const _validations = require("../helpers/validations");
20
20
  const _queries = require("../internal/queries");
@@ -132,8 +132,7 @@ const dropdownMarks = [
132
132
  _richtexttypes.MARKS.STRIKETHROUGH
133
133
  ];
134
134
  const Dropdown = ({ sdk, isDisabled })=>{
135
- const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
136
- const isActive = editor && dropdownMarks.some((mark)=>(0, _queries.isMarkActive)(editor, mark));
135
+ const isActive = (0, _react1.useEditorSelector)((editor)=>dropdownMarks.some((mark)=>(0, _queries.isMarkActive)(editor, mark)), []);
137
136
  return /*#__PURE__*/ _react.createElement(_f36components.Menu, null, /*#__PURE__*/ _react.createElement(_f36components.Menu.Trigger, null, /*#__PURE__*/ _react.createElement("span", null, /*#__PURE__*/ _react.createElement(_f36components.IconButton, {
138
137
  size: "small",
139
138
  className: styles.toolbarBtn,
@@ -154,13 +153,12 @@ const Dropdown = ({ sdk, isDisabled })=>{
154
153
  };
155
154
  const Toolbar = ({ isDisabled })=>{
156
155
  const sdk = (0, _SdkProvider.useSdkContext)();
157
- const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
158
- const canInsertBlocks = !(0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.TABLE);
156
+ const canInsertBlocks = (0, _react1.useEditorSelector)((editor)=>!(0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.TABLE), []);
159
157
  const validationInfo = _react.useMemo(()=>getValidationInfo(sdk.field), [
160
158
  sdk.field
161
159
  ]);
162
- const isListSelected = (0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.UL_LIST) || (0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.OL_LIST);
163
- const isBlockquoteSelected = (0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.QUOTE);
160
+ const isListSelected = (0, _react1.useEditorSelector)((editor)=>(0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.UL_LIST) || (0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.OL_LIST), []);
161
+ const isBlockquoteSelected = (0, _react1.useEditorSelector)((editor)=>(0, _editor.isNodeTypeSelected)(editor, _richtexttypes.BLOCKS.QUOTE), []);
164
162
  const shouldDisableTables = isDisabled || !canInsertBlocks || isListSelected || isBlockquoteSelected;
165
163
  const boldItalicUnderlineAvailable = (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.BOLD) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.ITALIC) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.UNDERLINE);
166
164
  const dropdownItemsAvailable = dropdownMarks.some((mark)=>(0, _validations.isMarkEnabled)(sdk.field, mark));
@@ -161,7 +161,7 @@ const makeDoc = (n)=>node(_richtexttypes.BLOCKS.DOCUMENT, {}, Array.from({
161
161
  });
162
162
  }
163
163
  (0, _vitest.expect)(container.textContent).toContain(`Par${'x'.repeat(KEYSTROKES)}agraph 0`);
164
- (0, _vitest.expect)(commits / KEYSTROKES).toBeLessThanOrEqual(18);
164
+ (0, _vitest.expect)(commits / KEYSTROKES).toBeLessThanOrEqual(11);
165
165
  }, 120000);
166
166
  (0, _vitest.it)('normalizing does not resolve unregistered plugins', ()=>{
167
167
  const { editor } = (0, _testutils.createTestEditor)({});
@@ -30,7 +30,9 @@ const withCharCounter = (editor)=>{
30
30
  }, CHARACTER_COUNT_DEBOUNCE_TIME);
31
31
  editor.apply = (op)=>{
32
32
  apply(op);
33
- recount();
33
+ if (op.type !== 'set_selection') {
34
+ recount();
35
+ }
34
36
  };
35
37
  return editor;
36
38
  };
@@ -79,7 +79,6 @@ const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveL
79
79
  };
80
80
  const resolvedPopoverText = typeof popoverText === 'function' ? popoverText(closePopover) : popoverText;
81
81
  return /*#__PURE__*/ _react.createElement(_f36components.Popover, {
82
- renderOnlyWhenOpen: false,
83
82
  usePortal: true,
84
83
  autoFocus: false,
85
84
  isOpen: isOpen
@@ -12,6 +12,7 @@ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
12
  const _f36components = require("@contentful/f36-components");
13
13
  const _f36tokens = /*#__PURE__*/ _interop_require_default(require("@contentful/f36-tokens"));
14
14
  const _css = require("@emotion/css");
15
+ const _react1 = require("platejs/react");
15
16
  const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
16
17
  const _editor = require("../../../helpers/editor");
17
18
  const _queries = require("../../../internal/queries");
@@ -71,7 +72,8 @@ const styles = {
71
72
  };
72
73
  const createMarkToolbarButton = ({ mark, title, icon })=>{
73
74
  const Mark = ({ isDisabled })=>{
74
- const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
75
+ const editor = (0, _ContentfulEditorProvider.useContentfulEditorRef)();
76
+ const isActive = (0, _react1.useEditorSelector)((editor)=>(0, _queries.isMarkActive)(editor, mark), []);
75
77
  const handleClick = _react.useCallback(()=>{
76
78
  if (!editor?.selection) return;
77
79
  const isActive = (0, _queries.isMarkActive)(editor, mark);
@@ -89,7 +91,7 @@ const createMarkToolbarButton = ({ mark, title, icon })=>{
89
91
  onClick: handleClick,
90
92
  disabled: isDisabled,
91
93
  className: (0, _css.cx)({
92
- [styles.isActive]: (0, _queries.isMarkActive)(editor, mark)
94
+ [styles.isActive]: isActive
93
95
  }),
94
96
  testId: `${mark}-toolbar-button`
95
97
  }, title);
@@ -98,7 +100,7 @@ const createMarkToolbarButton = ({ mark, title, icon })=>{
98
100
  title: title,
99
101
  testId: `${mark}-toolbar-button`,
100
102
  onClick: handleClick,
101
- isActive: (0, _queries.isMarkActive)(editor, mark),
103
+ isActive: isActive,
102
104
  isDisabled: isDisabled
103
105
  }, icon);
104
106
  };
@@ -67,7 +67,7 @@ const withNormalizer = (editor)=>{
67
67
  editor.normalizeNode = (rawEntry)=>{
68
68
  const entry = rawEntry;
69
69
  const [node, path] = entry;
70
- const children = (0, _queries.getChildren)(entry);
70
+ let children;
71
71
  for (const rule of rules){
72
72
  if (!(0, _queries.matchNode)(node, path, rule.match)) {
73
73
  continue;
@@ -78,6 +78,7 @@ const withNormalizer = (editor)=>{
78
78
  }
79
79
  if ('validChildren' in rule) {
80
80
  const isValidChild = rule.validChildren;
81
+ children ?? (children = (0, _queries.getChildren)(entry));
81
82
  const invalidChildEntry = children.find((entry)=>!isValidChild(editor, entry));
82
83
  if (invalidChildEntry) {
83
84
  _transform(rule.transform, invalidChildEntry);
@@ -1,9 +1,11 @@
1
1
  import React from 'react';
2
2
  import { ArrowUUpRightIcon } from '@contentful/f36-icons';
3
- import { useContentfulEditor } from '../../ContentfulEditorProvider';
3
+ import { useEditorSelector } from 'platejs/react';
4
+ import { useContentfulEditorRef } from '../../ContentfulEditorProvider';
4
5
  import { ToolbarButton } from '../../plugins/shared/ToolbarButton';
5
6
  export const ButtonRedo = ()=>{
6
- const editor = useContentfulEditor();
7
+ const editor = useContentfulEditorRef();
8
+ const isDisabled = useEditorSelector((editor)=>editor.history.redos.length === 0, []);
7
9
  const onClickHandler = ()=>{
8
10
  editor.redo('toolbar');
9
11
  };
@@ -12,7 +14,7 @@ export const ButtonRedo = ()=>{
12
14
  testId: "redo-toolbar-button",
13
15
  onClick: onClickHandler,
14
16
  isActive: false,
15
- isDisabled: editor.history.redos.length === 0
17
+ isDisabled: isDisabled
16
18
  }, /*#__PURE__*/ React.createElement(ArrowUUpRightIcon, {
17
19
  "aria-label": "Redo"
18
20
  }));
@@ -1,9 +1,11 @@
1
1
  import React from 'react';
2
2
  import { ArrowUUpLeftIcon } from '@contentful/f36-icons';
3
- import { useContentfulEditor } from '../../ContentfulEditorProvider';
3
+ import { useEditorSelector } from 'platejs/react';
4
+ import { useContentfulEditorRef } from '../../ContentfulEditorProvider';
4
5
  import { ToolbarButton } from '../../plugins/shared/ToolbarButton';
5
6
  export const ButtonUndo = ()=>{
6
- const editor = useContentfulEditor();
7
+ const editor = useContentfulEditorRef();
8
+ const isDisabled = useEditorSelector((editor)=>editor.history.undos.length === 0, []);
7
9
  const onClickHandler = ()=>{
8
10
  editor.undo('toolbar');
9
11
  };
@@ -12,7 +14,7 @@ export const ButtonUndo = ()=>{
12
14
  testId: "undo-toolbar-button",
13
15
  onClick: onClickHandler,
14
16
  isActive: false,
15
- isDisabled: editor.history.undos.length === 0
17
+ isDisabled: isDisabled
16
18
  }, /*#__PURE__*/ React.createElement(ArrowUUpLeftIcon, {
17
19
  "aria-label": "Undo"
18
20
  }));
@@ -4,7 +4,7 @@ import { DotsThreeIcon } from '@contentful/f36-icons';
4
4
  import tokens from '@contentful/f36-tokens';
5
5
  import { BLOCKS, INLINES, MARKS } from '@contentful/rich-text-types';
6
6
  import { css } from '@emotion/css';
7
- import { useContentfulEditor } from '../ContentfulEditorProvider';
7
+ import { useEditorSelector } from 'platejs/react';
8
8
  import { isNodeTypeSelected } from '../helpers/editor';
9
9
  import { isMarkEnabled, isNodeTypeEnabled } from '../helpers/validations';
10
10
  import { isMarkActive } from '../internal/queries';
@@ -76,8 +76,7 @@ const dropdownMarks = [
76
76
  MARKS.STRIKETHROUGH
77
77
  ];
78
78
  const Dropdown = ({ sdk, isDisabled })=>{
79
- const editor = useContentfulEditor();
80
- const isActive = editor && dropdownMarks.some((mark)=>isMarkActive(editor, mark));
79
+ const isActive = useEditorSelector((editor)=>dropdownMarks.some((mark)=>isMarkActive(editor, mark)), []);
81
80
  return /*#__PURE__*/ React.createElement(Menu, null, /*#__PURE__*/ React.createElement(Menu.Trigger, null, /*#__PURE__*/ React.createElement("span", null, /*#__PURE__*/ React.createElement(IconButton, {
82
81
  size: "small",
83
82
  className: styles.toolbarBtn,
@@ -98,13 +97,12 @@ const Dropdown = ({ sdk, isDisabled })=>{
98
97
  };
99
98
  const Toolbar = ({ isDisabled })=>{
100
99
  const sdk = useSdkContext();
101
- const editor = useContentfulEditor();
102
- const canInsertBlocks = !isNodeTypeSelected(editor, BLOCKS.TABLE);
100
+ const canInsertBlocks = useEditorSelector((editor)=>!isNodeTypeSelected(editor, BLOCKS.TABLE), []);
103
101
  const validationInfo = React.useMemo(()=>getValidationInfo(sdk.field), [
104
102
  sdk.field
105
103
  ]);
106
- const isListSelected = isNodeTypeSelected(editor, BLOCKS.UL_LIST) || isNodeTypeSelected(editor, BLOCKS.OL_LIST);
107
- const isBlockquoteSelected = isNodeTypeSelected(editor, BLOCKS.QUOTE);
104
+ const isListSelected = useEditorSelector((editor)=>isNodeTypeSelected(editor, BLOCKS.UL_LIST) || isNodeTypeSelected(editor, BLOCKS.OL_LIST), []);
105
+ const isBlockquoteSelected = useEditorSelector((editor)=>isNodeTypeSelected(editor, BLOCKS.QUOTE), []);
108
106
  const shouldDisableTables = isDisabled || !canInsertBlocks || isListSelected || isBlockquoteSelected;
109
107
  const boldItalicUnderlineAvailable = isMarkEnabled(sdk.field, MARKS.BOLD) || isMarkEnabled(sdk.field, MARKS.ITALIC) || isMarkEnabled(sdk.field, MARKS.UNDERLINE);
110
108
  const dropdownItemsAvailable = dropdownMarks.some((mark)=>isMarkEnabled(sdk.field, mark));
@@ -116,7 +116,7 @@ describe('rich text performance', ()=>{
116
116
  });
117
117
  }
118
118
  expect(container.textContent).toContain(`Par${'x'.repeat(KEYSTROKES)}agraph 0`);
119
- expect(commits / KEYSTROKES).toBeLessThanOrEqual(18);
119
+ expect(commits / KEYSTROKES).toBeLessThanOrEqual(11);
120
120
  }, 120000);
121
121
  it('normalizing does not resolve unregistered plugins', ()=>{
122
122
  const { editor } = createTestEditor({});
@@ -15,7 +15,9 @@ export const withCharCounter = (editor)=>{
15
15
  }, CHARACTER_COUNT_DEBOUNCE_TIME);
16
16
  editor.apply = (op)=>{
17
17
  apply(op);
18
- recount();
18
+ if (op.type !== 'set_selection') {
19
+ recount();
20
+ }
19
21
  };
20
22
  return editor;
21
23
  };
@@ -28,7 +28,6 @@ export const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handle
28
28
  };
29
29
  const resolvedPopoverText = typeof popoverText === 'function' ? popoverText(closePopover) : popoverText;
30
30
  return /*#__PURE__*/ React.createElement(Popover, {
31
- renderOnlyWhenOpen: false,
32
31
  usePortal: true,
33
32
  autoFocus: false,
34
33
  isOpen: isOpen
@@ -2,7 +2,8 @@ import * as React from 'react';
2
2
  import { Menu } from '@contentful/f36-components';
3
3
  import tokens from '@contentful/f36-tokens';
4
4
  import { css, cx } from '@emotion/css';
5
- import { useContentfulEditor } from '../../../ContentfulEditorProvider';
5
+ import { useEditorSelector } from 'platejs/react';
6
+ import { useContentfulEditorRef } from '../../../ContentfulEditorProvider';
6
7
  import { focus } from '../../../helpers/editor';
7
8
  import { isMarkActive } from '../../../internal/queries';
8
9
  import { ToolbarButton } from '../../shared/ToolbarButton';
@@ -15,7 +16,8 @@ const styles = {
15
16
  };
16
17
  export const createMarkToolbarButton = ({ mark, title, icon })=>{
17
18
  const Mark = ({ isDisabled })=>{
18
- const editor = useContentfulEditor();
19
+ const editor = useContentfulEditorRef();
20
+ const isActive = useEditorSelector((editor)=>isMarkActive(editor, mark), []);
19
21
  const handleClick = React.useCallback(()=>{
20
22
  if (!editor?.selection) return;
21
23
  const isActive = isMarkActive(editor, mark);
@@ -33,7 +35,7 @@ export const createMarkToolbarButton = ({ mark, title, icon })=>{
33
35
  onClick: handleClick,
34
36
  disabled: isDisabled,
35
37
  className: cx({
36
- [styles.isActive]: isMarkActive(editor, mark)
38
+ [styles.isActive]: isActive
37
39
  }),
38
40
  testId: `${mark}-toolbar-button`
39
41
  }, title);
@@ -42,7 +44,7 @@ export const createMarkToolbarButton = ({ mark, title, icon })=>{
42
44
  title: title,
43
45
  testId: `${mark}-toolbar-button`,
44
46
  onClick: handleClick,
45
- isActive: isMarkActive(editor, mark),
47
+ isActive: isActive,
46
48
  isDisabled: isDisabled
47
49
  }, icon);
48
50
  };
@@ -52,7 +52,7 @@ export const withNormalizer = (editor)=>{
52
52
  editor.normalizeNode = (rawEntry)=>{
53
53
  const entry = rawEntry;
54
54
  const [node, path] = entry;
55
- const children = getChildren(entry);
55
+ let children;
56
56
  for (const rule of rules){
57
57
  if (!matchNode(node, path, rule.match)) {
58
58
  continue;
@@ -63,6 +63,7 @@ export const withNormalizer = (editor)=>{
63
63
  }
64
64
  if ('validChildren' in rule) {
65
65
  const isValidChild = rule.validChildren;
66
+ children ?? (children = getChildren(entry));
66
67
  const invalidChildEntry = children.find((entry)=>!isValidChild(editor, entry));
67
68
  if (invalidChildEntry) {
68
69
  _transform(rule.transform, invalidChildEntry);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "6.6.7",
3
+ "version": "6.6.8",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -96,5 +96,5 @@
96
96
  "prettier --write"
97
97
  ]
98
98
  },
99
- "gitHead": "8f907c41345eeffedf4ac0ee89559aca38bc4456"
99
+ "gitHead": "75707b1b41b0c46cbf0a5e9e3a80a8425b514a9e"
100
100
  }