@contentful/field-editor-rich-text 6.5.1-canary.0 → 6.6.0
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/README.md +5 -6
- package/dist/cjs/RichTextEditor.js +48 -8
- package/dist/cjs/SyncEditorChanges.js +7 -28
- package/dist/cjs/Toolbar/_tests_/toolbar.test.js +13 -7
- package/dist/cjs/helpers/__tests__/extractNodes.test.js +2 -2
- package/dist/cjs/internal/__tests__/linkEditing.test.js +63 -0
- package/dist/cjs/internal/__tests__/pasteMarks.test.js +54 -0
- package/dist/cjs/internal/__tests__/pluginAdapter.test.js +201 -0
- package/dist/cjs/internal/__tests__/transforms.test.js +2 -2
- package/dist/cjs/internal/breaks.js +121 -0
- package/dist/cjs/internal/constants.js +2 -2
- package/dist/cjs/internal/hooks.js +4 -57
- package/dist/cjs/internal/list.js +96 -0
- package/dist/cjs/internal/misc.js +9 -14
- package/dist/cjs/internal/plate.js +460 -0
- package/dist/cjs/internal/pluginAdapter.js +168 -0
- package/dist/cjs/internal/pluginFactories.js +77 -0
- package/dist/cjs/internal/queries.js +48 -48
- package/dist/cjs/internal/table.js +141 -0
- package/dist/cjs/internal/transforms.js +26 -25
- package/dist/cjs/plugins/Break/createExitBreakPlugin.js +3 -3
- package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +2 -2
- package/dist/cjs/plugins/Break/createResetNodePlugin.js +3 -3
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.js +3 -3
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +2 -2
- package/dist/cjs/plugins/CommandPalette/useCommands.js +2 -2
- package/dist/cjs/plugins/CommandPalette/utils/insertBlock.test.js +3 -3
- package/dist/cjs/plugins/DeserializeDocx/cleanHtmlEmptyElements.js +2 -2
- package/dist/cjs/plugins/DeserializeDocx/createDeserializeDocxPlugin.js +20 -19
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +3 -3
- package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +3 -3
- package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +3 -3
- package/dist/cjs/plugins/EmbeddedResourceInline/LinkedResourceInline.js +3 -3
- package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +5 -5
- package/dist/cjs/plugins/Hr/index.js +3 -3
- package/dist/cjs/plugins/Hyperlink/utils.js +2 -2
- package/dist/cjs/plugins/List/createListPlugin.js +11 -8
- package/dist/cjs/plugins/List/insertListBreak.js +12 -12
- package/dist/cjs/plugins/List/insertListFragment.js +2 -2
- package/dist/cjs/plugins/List/onKeyDownList.js +1 -1
- package/dist/cjs/plugins/List/transforms/moveListItemDown.js +2 -2
- package/dist/cjs/plugins/List/transforms/moveListItems.js +5 -5
- package/dist/cjs/plugins/List/transforms/toggleList.js +3 -3
- package/dist/cjs/plugins/List/withList.js +4 -4
- package/dist/cjs/plugins/Marks/Bold.js +2 -2
- package/dist/cjs/plugins/Marks/Code.js +2 -2
- package/dist/cjs/plugins/Marks/Italic.js +2 -2
- package/dist/cjs/plugins/Marks/Strikethrough.js +2 -11
- package/dist/cjs/plugins/Marks/Subscript.js +2 -11
- package/dist/cjs/plugins/Marks/Superscript.js +2 -11
- package/dist/cjs/plugins/Marks/Underline.js +2 -2
- package/dist/cjs/plugins/Normalizer/withNormalizer.js +6 -3
- package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +5 -5
- package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +2 -2
- package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +2 -2
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +11 -0
- package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +5 -5
- package/dist/cjs/plugins/Quote/shouldResetQuote.js +2 -2
- package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +21 -8
- package/dist/cjs/plugins/Table/__tests__/helpers.test.js +1 -1
- package/dist/cjs/plugins/Table/actions/addColumn.js +2 -2
- package/dist/cjs/plugins/Table/actions/addRow.js +4 -3
- package/dist/cjs/plugins/Table/components/Cell.js +2 -2
- package/dist/cjs/plugins/Table/components/HeaderCell.js +2 -2
- package/dist/cjs/plugins/Table/components/Table.js +2 -2
- package/dist/cjs/plugins/Table/components/TableActions.js +4 -4
- package/dist/cjs/plugins/Table/createTablePlugin.js +13 -12
- package/dist/cjs/plugins/Table/helpers.js +7 -7
- package/dist/cjs/plugins/Table/onKeyDownTable.js +16 -15
- package/dist/cjs/plugins/Table/withInsertFragmentTableOverride.js +6 -6
- package/dist/cjs/plugins/Text/createTextPlugin.js +9 -4
- package/dist/cjs/plugins/TrailingParagraph/index.js +23 -7
- package/dist/cjs/plugins/Voids/createVoidsPlugin.js +28 -0
- package/dist/cjs/plugins/index.js +3 -14
- package/dist/cjs/plugins/shared/__tests__/EmbeddedBlockUtil.test.js +3 -3
- package/dist/cjs/test-utils/jsx.js +2 -3
- package/dist/cjs/test-utils/mockPlugin.js +2 -2
- package/dist/cjs/test-utils/setEmptyDataAttribute.js +2 -2
- package/dist/esm/RichTextEditor.js +47 -7
- package/dist/esm/SyncEditorChanges.js +8 -29
- package/dist/esm/Toolbar/_tests_/toolbar.test.js +10 -4
- package/dist/esm/helpers/__tests__/extractNodes.test.js +2 -2
- package/dist/esm/internal/__tests__/linkEditing.test.js +59 -0
- package/dist/esm/internal/__tests__/pasteMarks.test.js +50 -0
- package/dist/esm/internal/__tests__/pluginAdapter.test.js +197 -0
- package/dist/esm/internal/__tests__/transforms.test.js +2 -2
- package/dist/esm/internal/breaks.js +83 -0
- package/dist/esm/internal/constants.js +1 -1
- package/dist/esm/internal/hooks.js +4 -12
- package/dist/esm/internal/list.js +49 -0
- package/dist/esm/internal/misc.js +4 -7
- package/dist/esm/internal/plate.js +140 -0
- package/dist/esm/internal/pluginAdapter.js +144 -0
- package/dist/esm/internal/pluginFactories.js +32 -0
- package/dist/esm/internal/queries.js +2 -2
- package/dist/esm/internal/table.js +43 -0
- package/dist/esm/internal/transforms.js +3 -2
- package/dist/esm/plugins/Break/createExitBreakPlugin.js +2 -2
- package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +2 -2
- package/dist/esm/plugins/Break/createResetNodePlugin.js +2 -2
- package/dist/esm/plugins/Break/createSoftBreakPlugin.js +2 -2
- package/dist/esm/plugins/Break/createSoftBreakPlugin.test.js +2 -2
- package/dist/esm/plugins/CommandPalette/useCommands.js +2 -2
- package/dist/esm/plugins/CommandPalette/utils/insertBlock.test.js +3 -3
- package/dist/esm/plugins/DeserializeDocx/cleanHtmlEmptyElements.js +1 -1
- package/dist/esm/plugins/DeserializeDocx/createDeserializeDocxPlugin.js +3 -2
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +1 -1
- package/dist/esm/plugins/EmbeddedEntityInline/LinkedEntityInline.js +1 -1
- package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +1 -1
- package/dist/esm/plugins/EmbeddedResourceInline/LinkedResourceInline.js +1 -1
- package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +5 -5
- package/dist/esm/plugins/Hr/index.js +3 -3
- package/dist/esm/plugins/Hyperlink/utils.js +1 -1
- package/dist/esm/plugins/List/createListPlugin.js +6 -3
- package/dist/esm/plugins/List/insertListBreak.js +3 -3
- package/dist/esm/plugins/List/insertListFragment.js +1 -1
- package/dist/esm/plugins/List/onKeyDownList.js +1 -1
- package/dist/esm/plugins/List/transforms/moveListItemDown.js +1 -1
- package/dist/esm/plugins/List/transforms/moveListItems.js +1 -1
- package/dist/esm/plugins/List/transforms/toggleList.js +2 -2
- package/dist/esm/plugins/List/withList.js +1 -1
- package/dist/esm/plugins/Marks/Bold.js +1 -1
- package/dist/esm/plugins/Marks/Code.js +1 -1
- package/dist/esm/plugins/Marks/Italic.js +1 -1
- package/dist/esm/plugins/Marks/Strikethrough.js +1 -10
- package/dist/esm/plugins/Marks/Subscript.js +1 -10
- package/dist/esm/plugins/Marks/Superscript.js +1 -10
- package/dist/esm/plugins/Marks/Underline.js +1 -1
- package/dist/esm/plugins/Normalizer/withNormalizer.js +6 -3
- package/dist/esm/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +5 -5
- package/dist/esm/plugins/Paragraph/createParagraphPlugin.js +1 -1
- package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +1 -1
- package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +11 -0
- package/dist/esm/plugins/Quote/__test__/createQuotePlugin.test.js +5 -5
- package/dist/esm/plugins/Quote/shouldResetQuote.js +1 -1
- package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +21 -8
- package/dist/esm/plugins/Table/__tests__/helpers.test.js +1 -1
- package/dist/esm/plugins/Table/actions/addColumn.js +1 -1
- package/dist/esm/plugins/Table/actions/addRow.js +3 -2
- package/dist/esm/plugins/Table/components/Cell.js +1 -1
- package/dist/esm/plugins/Table/components/HeaderCell.js +1 -1
- package/dist/esm/plugins/Table/components/Table.js +2 -2
- package/dist/esm/plugins/Table/components/TableActions.js +1 -1
- package/dist/esm/plugins/Table/createTablePlugin.js +2 -1
- package/dist/esm/plugins/Table/helpers.js +1 -1
- package/dist/esm/plugins/Table/onKeyDownTable.js +14 -13
- package/dist/esm/plugins/Table/withInsertFragmentTableOverride.js +2 -2
- package/dist/esm/plugins/Text/createTextPlugin.js +9 -4
- package/dist/esm/plugins/TrailingParagraph/index.js +23 -7
- package/dist/esm/plugins/Voids/createVoidsPlugin.js +29 -1
- package/dist/esm/plugins/index.js +0 -3
- package/dist/esm/plugins/shared/__tests__/EmbeddedBlockUtil.test.js +3 -3
- package/dist/esm/test-utils/jsx.js +1 -1
- package/dist/esm/test-utils/mockPlugin.js +1 -1
- package/dist/esm/test-utils/setEmptyDataAttribute.js +1 -1
- package/dist/types/ContentfulEditorProvider.d.ts +16 -1
- package/dist/types/SyncEditorChanges.d.ts +3 -12
- package/dist/types/internal/__tests__/linkEditing.test.d.ts +1 -0
- package/dist/types/internal/__tests__/pasteMarks.test.d.ts +1 -0
- package/dist/types/internal/__tests__/pluginAdapter.test.d.ts +1 -0
- package/dist/types/internal/breaks.d.ts +13 -0
- package/dist/types/internal/hooks.d.ts +18 -34
- package/dist/types/internal/list.d.ts +14 -0
- package/dist/types/internal/misc.d.ts +6 -33
- package/dist/types/internal/plate.d.ts +126 -0
- package/dist/types/internal/pluginAdapter.d.ts +14 -0
- package/dist/types/internal/pluginFactories.d.ts +12 -0
- package/dist/types/internal/queries.d.ts +15 -16
- package/dist/types/internal/table.d.ts +15 -0
- package/dist/types/internal/transforms.d.ts +7 -7
- package/dist/types/internal/types/editor.d.ts +9 -10
- package/dist/types/internal/types/plugins.d.ts +72 -7
- package/dist/types/plugins/Break/index.d.ts +2 -2
- package/dist/types/plugins/Heading/components/Heading.d.ts +1 -1
- package/dist/types/plugins/Hr/index.d.ts +1 -1
- package/dist/types/plugins/Hyperlink/components/useHyperlinkCommon.d.ts +1 -1
- package/dist/types/plugins/List/components/List.d.ts +1 -1
- package/dist/types/plugins/List/components/ListItem.d.ts +1 -1
- package/dist/types/plugins/List/onKeyDownList.d.ts +1 -5
- package/dist/types/plugins/Table/components/Row.d.ts +1 -1
- package/dist/types/plugins/Table/components/Table.d.ts +1 -1
- package/dist/types/plugins/index.d.ts +0 -2
- package/dist/types/plugins/shared/EmbeddedBlockUtil.d.ts +1 -1
- package/dist/types/plugins/shared/EmbeddedInlineUtil.d.ts +1 -1
- package/dist/types/test-utils/jsx.d.ts +5 -14
- package/package.json +14 -19
package/README.md
CHANGED
|
@@ -12,16 +12,15 @@ import { RichTextEditor } from '@contentful/field-editor-rich-text';
|
|
|
12
12
|
|
|
13
13
|
## ⚠️ Important: Package Configuration
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
This is a temporary workaround until we have upgraded the underlying rich text packages.
|
|
15
|
+
Plate 53.3.14 pins `slate-react` to 0.126.4. To use the latest Slate React version tested by this package (0.127.1), update existing overrides in your application as shown below. Package-manager overrides in this repository are not inherited by applications that install the published package.
|
|
17
16
|
|
|
18
17
|
**For npm:**
|
|
19
18
|
|
|
20
19
|
```json
|
|
21
20
|
{
|
|
22
21
|
"overrides": {
|
|
23
|
-
"slate": "0.
|
|
24
|
-
"slate-react": "0.
|
|
22
|
+
"slate": "0.126.2",
|
|
23
|
+
"slate-react": "0.127.1"
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
```
|
|
@@ -31,8 +30,8 @@ This is a temporary workaround until we have upgraded the underlying rich text p
|
|
|
31
30
|
```json
|
|
32
31
|
{
|
|
33
32
|
"resolutions": {
|
|
34
|
-
"slate": "0.
|
|
35
|
-
"slate-react": "0.
|
|
33
|
+
"slate": "0.126.2",
|
|
34
|
+
"slate-react": "0.127.1"
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
```
|
|
@@ -21,14 +21,16 @@ const _fieldeditorreference = require("@contentful/field-editor-reference");
|
|
|
21
21
|
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
22
22
|
const _richtexttypes = /*#__PURE__*/ _interop_require_wildcard(require("@contentful/rich-text-types"));
|
|
23
23
|
const _css = require("@emotion/css");
|
|
24
|
-
const _platecommon = require("@udecode/plate-common");
|
|
25
24
|
const _fastdeepequal = /*#__PURE__*/ _interop_require_default(require("fast-deep-equal"));
|
|
26
25
|
const _noop = /*#__PURE__*/ _interop_require_default(require("lodash/noop"));
|
|
27
26
|
const _usedeepcompare = require("use-deep-compare");
|
|
28
27
|
const _CharConstraints = require("./CharConstraints");
|
|
29
28
|
const _ContentfulEditorProvider = require("./ContentfulEditorProvider");
|
|
30
29
|
const _editoroverrides = require("./editor-overrides");
|
|
30
|
+
const _callbacks = require("./helpers/callbacks");
|
|
31
31
|
const _toSlateDoc = require("./helpers/toSlateDoc");
|
|
32
|
+
const _plate = require("./internal/plate");
|
|
33
|
+
const _pluginAdapter = require("./internal/pluginAdapter");
|
|
32
34
|
const _plugins = require("./plugins");
|
|
33
35
|
const _RichTextEditorstyles = require("./RichTextEditor.styles");
|
|
34
36
|
const _SdkProvider = require("./SdkProvider");
|
|
@@ -95,6 +97,41 @@ const ConnectedRichTextEditor = /*#__PURE__*/ _react.memo(function ConnectedRich
|
|
|
95
97
|
}, [
|
|
96
98
|
props.value
|
|
97
99
|
]);
|
|
100
|
+
const editorOptions = _react.useRef({
|
|
101
|
+
plugins,
|
|
102
|
+
value: initialValue
|
|
103
|
+
});
|
|
104
|
+
editorOptions.current = {
|
|
105
|
+
plugins,
|
|
106
|
+
value: initialValue
|
|
107
|
+
};
|
|
108
|
+
const editor = _react.useMemo(()=>(0, _pluginAdapter.createPlateEditor)({
|
|
109
|
+
id,
|
|
110
|
+
...editorOptions.current
|
|
111
|
+
}), [
|
|
112
|
+
id
|
|
113
|
+
]);
|
|
114
|
+
const handleValueChange = _react.useMemo(()=>(0, _callbacks.createOnChangeCallback)(props.onChange), [
|
|
115
|
+
props.onChange
|
|
116
|
+
]);
|
|
117
|
+
const lastValue = _react.useMemo(()=>({
|
|
118
|
+
current: editor.children
|
|
119
|
+
}), [
|
|
120
|
+
editor
|
|
121
|
+
]);
|
|
122
|
+
const acceptExternalValue = _react.useCallback(()=>{
|
|
123
|
+
handleValueChange.cancel();
|
|
124
|
+
lastValue.current = editor.children;
|
|
125
|
+
}, [
|
|
126
|
+
editor,
|
|
127
|
+
handleValueChange,
|
|
128
|
+
lastValue
|
|
129
|
+
]);
|
|
130
|
+
_react.useEffect(()=>()=>{
|
|
131
|
+
handleValueChange.flush();
|
|
132
|
+
}, [
|
|
133
|
+
handleValueChange
|
|
134
|
+
]);
|
|
98
135
|
const direction = sdk.locales.direction[sdk.field.locale] ?? 'ltr';
|
|
99
136
|
const classNames = (0, _css.cx)(_RichTextEditorstyles.styles.editor, props.minHeight !== undefined ? (0, _css.css)({
|
|
100
137
|
minHeight: props.minHeight
|
|
@@ -111,11 +148,14 @@ const ConnectedRichTextEditor = /*#__PURE__*/ _react.memo(function ConnectedRich
|
|
|
111
148
|
}, /*#__PURE__*/ _react.createElement("div", {
|
|
112
149
|
className: _RichTextEditorstyles.styles.root,
|
|
113
150
|
"data-test-id": "rich-text-editor"
|
|
114
|
-
}, /*#__PURE__*/ _react.createElement(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
151
|
+
}, /*#__PURE__*/ _react.createElement(_plate.Plate, {
|
|
152
|
+
editor: editor,
|
|
153
|
+
readOnly: props.isDisabled,
|
|
154
|
+
onValueChange: ({ value })=>{
|
|
155
|
+
if ((0, _fastdeepequal.default)(lastValue.current, value)) return;
|
|
156
|
+
lastValue.current = value;
|
|
157
|
+
handleValueChange(value);
|
|
158
|
+
}
|
|
119
159
|
}, !props.isToolbarHidden && /*#__PURE__*/ _react.createElement(_StickyToolbarWrapper.default, {
|
|
120
160
|
isDisabled: props.isDisabled,
|
|
121
161
|
offset: props.stickyToolbarOffset
|
|
@@ -123,8 +163,8 @@ const ConnectedRichTextEditor = /*#__PURE__*/ _react.memo(function ConnectedRich
|
|
|
123
163
|
isDisabled: props.isDisabled
|
|
124
164
|
})), /*#__PURE__*/ _react.createElement(_SyncEditorChanges.SyncEditorChanges, {
|
|
125
165
|
incomingValue: initialValue,
|
|
126
|
-
|
|
127
|
-
}), /*#__PURE__*/ _react.createElement(
|
|
166
|
+
onValueApplied: acceptExternalValue
|
|
167
|
+
}), /*#__PURE__*/ _react.createElement(_plate.PlateContent, {
|
|
128
168
|
id: id,
|
|
129
169
|
className: classNames,
|
|
130
170
|
readOnly: props.isDisabled,
|
|
@@ -9,9 +9,7 @@ Object.defineProperty(exports, "SyncEditorChanges", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
-
const _platecommon = require("@udecode/plate-common");
|
|
13
12
|
const _fastdeepequal = /*#__PURE__*/ _interop_require_default(require("fast-deep-equal"));
|
|
14
|
-
const _callbacks = require("./helpers/callbacks");
|
|
15
13
|
const _hooks = require("./internal/hooks");
|
|
16
14
|
const _transforms = require("./internal/transforms");
|
|
17
15
|
function _interop_require_default(obj) {
|
|
@@ -60,8 +58,8 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
60
58
|
}
|
|
61
59
|
return newObj;
|
|
62
60
|
}
|
|
63
|
-
const useAcceptIncomingChanges = (incomingValue)=>{
|
|
64
|
-
const editor = (0, _hooks.
|
|
61
|
+
const useAcceptIncomingChanges = (incomingValue, onValueApplied)=>{
|
|
62
|
+
const editor = (0, _hooks.usePlateEditorRef)();
|
|
65
63
|
const lastIncomingValue = _react.useRef(incomingValue);
|
|
66
64
|
_react.useEffect(()=>{
|
|
67
65
|
if ((0, _fastdeepequal.default)(lastIncomingValue.current, incomingValue)) {
|
|
@@ -69,33 +67,14 @@ const useAcceptIncomingChanges = (incomingValue)=>{
|
|
|
69
67
|
}
|
|
70
68
|
lastIncomingValue.current = incomingValue;
|
|
71
69
|
(0, _transforms.setEditorValue)(editor, incomingValue);
|
|
70
|
+
onValueApplied();
|
|
72
71
|
}, [
|
|
73
72
|
editor,
|
|
74
|
-
incomingValue
|
|
73
|
+
incomingValue,
|
|
74
|
+
onValueApplied
|
|
75
75
|
]);
|
|
76
76
|
};
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const setEditorOnChange = (0, _platecommon.usePlateActions)().onChange();
|
|
80
|
-
_react.useEffect(()=>{
|
|
81
|
-
const cb = (0, _callbacks.createOnChangeCallback)(onChange);
|
|
82
|
-
setEditorOnChange((document)=>{
|
|
83
|
-
const operations = editor?.operations.filter((op)=>{
|
|
84
|
-
return op.type !== 'set_selection';
|
|
85
|
-
});
|
|
86
|
-
if (operations.length === 0) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
cb(document);
|
|
90
|
-
});
|
|
91
|
-
}, [
|
|
92
|
-
editor,
|
|
93
|
-
onChange,
|
|
94
|
-
setEditorOnChange
|
|
95
|
-
]);
|
|
96
|
-
};
|
|
97
|
-
const SyncEditorChanges = ({ incomingValue, onChange })=>{
|
|
98
|
-
useAcceptIncomingChanges(incomingValue);
|
|
99
|
-
useOnValueChanged(onChange);
|
|
77
|
+
const SyncEditorChanges = ({ incomingValue, onValueApplied })=>{
|
|
78
|
+
useAcceptIncomingChanges(incomingValue, onValueApplied);
|
|
100
79
|
return null;
|
|
101
80
|
};
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
7
7
|
const _react1 = require("@testing-library/react");
|
|
8
|
-
const _platecommon = require("@udecode/plate-common");
|
|
9
8
|
const _vitest = require("vitest");
|
|
10
9
|
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
10
|
+
const _plate = require("../../internal/plate");
|
|
11
11
|
const _SdkProvider = require("../../SdkProvider");
|
|
12
12
|
const _index = /*#__PURE__*/ _interop_require_default(require("../index"));
|
|
13
13
|
function _interop_require_default(obj) {
|
|
@@ -92,8 +92,10 @@ const mockSdk = (marks)=>{
|
|
|
92
92
|
(0, _vitest.test)('everything on the toolbar should be disabled', async ()=>{
|
|
93
93
|
const sdk = mockSdk();
|
|
94
94
|
const id = (0, _ContentfulEditorProvider.getContentfulEditorId)(sdk);
|
|
95
|
-
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(
|
|
96
|
-
|
|
95
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_plate.Plate, {
|
|
96
|
+
editor: (0, _plate.createPlateEditor)({
|
|
97
|
+
id
|
|
98
|
+
})
|
|
97
99
|
}, /*#__PURE__*/ _react.createElement(_SdkProvider.SdkProvider, {
|
|
98
100
|
sdk: sdk
|
|
99
101
|
}, /*#__PURE__*/ _react.createElement(_ContentfulEditorProvider.ContentfulEditorIdProvider, {
|
|
@@ -126,8 +128,10 @@ const mockSdk = (marks)=>{
|
|
|
126
128
|
_richtexttypes.MARKS.SUPERSCRIPT
|
|
127
129
|
]);
|
|
128
130
|
const id = (0, _ContentfulEditorProvider.getContentfulEditorId)(sdk);
|
|
129
|
-
const { queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(
|
|
130
|
-
|
|
131
|
+
const { queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_plate.Plate, {
|
|
132
|
+
editor: (0, _plate.createPlateEditor)({
|
|
133
|
+
id
|
|
134
|
+
})
|
|
131
135
|
}, /*#__PURE__*/ _react.createElement(_SdkProvider.SdkProvider, {
|
|
132
136
|
sdk: sdk
|
|
133
137
|
}, /*#__PURE__*/ _react.createElement(_ContentfulEditorProvider.ContentfulEditorIdProvider, {
|
|
@@ -144,8 +148,10 @@ const mockSdk = (marks)=>{
|
|
|
144
148
|
_richtexttypes.MARKS.CODE
|
|
145
149
|
]);
|
|
146
150
|
const id = (0, _ContentfulEditorProvider.getContentfulEditorId)(sdk);
|
|
147
|
-
const { queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(
|
|
148
|
-
|
|
151
|
+
const { queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_plate.Plate, {
|
|
152
|
+
editor: (0, _plate.createPlateEditor)({
|
|
153
|
+
id
|
|
154
|
+
})
|
|
149
155
|
}, /*#__PURE__*/ _react.createElement(_SdkProvider.SdkProvider, {
|
|
150
156
|
sdk: sdk
|
|
151
157
|
}, /*#__PURE__*/ _react.createElement(_ContentfulEditorProvider.ContentfulEditorIdProvider, {
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
6
|
-
const
|
|
6
|
+
const _testutils = require("@platejs/test-utils");
|
|
7
7
|
const _vitest = require("vitest");
|
|
8
8
|
const _extractNodes = require("../extractNodes");
|
|
9
|
-
const createEditor = (children)=>(0,
|
|
9
|
+
const createEditor = (children)=>(0, _testutils.jsx)('editor', {}, children);
|
|
10
10
|
const buildParagraph = (children = [])=>({
|
|
11
11
|
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
12
12
|
data: {},
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
6
|
+
const _vitest = require("vitest");
|
|
7
|
+
const _editor = require("../../helpers/editor");
|
|
8
|
+
const _createTestEditor = require("../../test-utils/createTestEditor");
|
|
9
|
+
(0, _vitest.it)('converts selected text into a hyperlink', ()=>{
|
|
10
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
11
|
+
editor.children = [
|
|
12
|
+
{
|
|
13
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
14
|
+
children: [
|
|
15
|
+
{
|
|
16
|
+
text: 'My cool website'
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
editor.tf.select({
|
|
22
|
+
anchor: {
|
|
23
|
+
path: [
|
|
24
|
+
0,
|
|
25
|
+
0
|
|
26
|
+
],
|
|
27
|
+
offset: 0
|
|
28
|
+
},
|
|
29
|
+
focus: {
|
|
30
|
+
path: [
|
|
31
|
+
0,
|
|
32
|
+
0
|
|
33
|
+
],
|
|
34
|
+
offset: 15
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
editor.tf.withoutNormalizing(()=>{
|
|
38
|
+
(0, _editor.wrapLink)(editor, {
|
|
39
|
+
text: 'My cool website',
|
|
40
|
+
url: 'https://example.com',
|
|
41
|
+
type: _richtexttypes.INLINES.HYPERLINK
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
(0, _vitest.expect)(editor.children[0].children).toEqual([
|
|
45
|
+
{
|
|
46
|
+
text: ''
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: _richtexttypes.INLINES.HYPERLINK,
|
|
50
|
+
data: {
|
|
51
|
+
uri: 'https://example.com'
|
|
52
|
+
},
|
|
53
|
+
children: [
|
|
54
|
+
{
|
|
55
|
+
text: 'My cool website'
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
text: ''
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
6
|
+
const _vitest = require("vitest");
|
|
7
|
+
const _sanitizeHTML = require("../../plugins/PasteHTML/utils/sanitizeHTML");
|
|
8
|
+
const _createTestEditor = require("../../test-utils/createTestEditor");
|
|
9
|
+
(0, _vitest.it)('preserves superscript and subscript styles copied from Google Docs', ()=>{
|
|
10
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
11
|
+
const html = '<span style="vertical-align:super">Hello</span><span style="vertical-align:sub">World</span>';
|
|
12
|
+
(0, _vitest.expect)(editor.api.html.deserialize({
|
|
13
|
+
element: (0, _sanitizeHTML.sanitizeHTML)(html)
|
|
14
|
+
})).toEqual([
|
|
15
|
+
{
|
|
16
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
17
|
+
children: [
|
|
18
|
+
{
|
|
19
|
+
text: 'Hello',
|
|
20
|
+
superscript: true
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
text: 'World',
|
|
24
|
+
subscript: true
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
(0, _vitest.it)('preserves strikethrough styles and the trailing pasted newline', ()=>{
|
|
31
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
32
|
+
const html = '<p><span style="text-decoration:line-through">Hello world</span></p><br class="Apple-interchange-newline">';
|
|
33
|
+
(0, _vitest.expect)(editor.api.html.deserialize({
|
|
34
|
+
element: (0, _sanitizeHTML.sanitizeHTML)(html)
|
|
35
|
+
})).toEqual([
|
|
36
|
+
{
|
|
37
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
38
|
+
children: [
|
|
39
|
+
{
|
|
40
|
+
text: 'Hello world',
|
|
41
|
+
strikethrough: true
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
47
|
+
children: [
|
|
48
|
+
{
|
|
49
|
+
text: '\n'
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
6
|
+
const _platejs = require("platejs");
|
|
7
|
+
const _vitest = require("vitest");
|
|
8
|
+
const _Paragraph = require("../../plugins/Paragraph/Paragraph");
|
|
9
|
+
const _sanitizeHTML = require("../../plugins/PasteHTML/utils/sanitizeHTML");
|
|
10
|
+
const _Cell = require("../../plugins/Table/components/Cell");
|
|
11
|
+
const _Table = require("../../plugins/Table/components/Table");
|
|
12
|
+
const _createTestEditor = require("../../test-utils/createTestEditor");
|
|
13
|
+
(0, _vitest.it)('preserves Contentful renderers for native Plate plugins', ()=>{
|
|
14
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
15
|
+
(0, _vitest.expect)(editor.getPlugin({
|
|
16
|
+
key: _platejs.KEYS.p
|
|
17
|
+
}).render.node).toBe(_Paragraph.Paragraph);
|
|
18
|
+
(0, _vitest.expect)(editor.getPlugin({
|
|
19
|
+
key: _platejs.KEYS.table
|
|
20
|
+
}).render.node).toBe(_Table.Table);
|
|
21
|
+
(0, _vitest.expect)(editor.getPlugin({
|
|
22
|
+
key: _platejs.KEYS.td
|
|
23
|
+
}).render.node).toBe(_Cell.Cell);
|
|
24
|
+
_vitest.expect.soft((0, _platejs.getPluginByType)(editor, _richtexttypes.BLOCKS.PARAGRAPH)?.render.node).toBe(_Paragraph.Paragraph);
|
|
25
|
+
_vitest.expect.soft((0, _platejs.getPluginByType)(editor, _richtexttypes.BLOCKS.TABLE)?.render.node).toBe(_Table.Table);
|
|
26
|
+
_vitest.expect.soft((0, _platejs.getPluginByType)(editor, _richtexttypes.BLOCKS.TABLE_CELL)?.render.node).toBe(_Cell.Cell);
|
|
27
|
+
});
|
|
28
|
+
(0, _vitest.it)('splits a paragraph when inserting a fragment of void blocks', ()=>{
|
|
29
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
30
|
+
editor.children = [
|
|
31
|
+
{
|
|
32
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
33
|
+
children: [
|
|
34
|
+
{
|
|
35
|
+
text: 'some text.'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
editor.tf.select({
|
|
41
|
+
path: [
|
|
42
|
+
0,
|
|
43
|
+
0
|
|
44
|
+
],
|
|
45
|
+
offset: 4
|
|
46
|
+
});
|
|
47
|
+
editor.insertFragment([
|
|
48
|
+
{
|
|
49
|
+
type: _richtexttypes.BLOCKS.HR,
|
|
50
|
+
isVoid: true,
|
|
51
|
+
children: [
|
|
52
|
+
{
|
|
53
|
+
text: ''
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
(0, _vitest.expect)(editor.children.map((node)=>node.type)).toEqual([
|
|
59
|
+
_richtexttypes.BLOCKS.PARAGRAPH,
|
|
60
|
+
_richtexttypes.BLOCKS.HR,
|
|
61
|
+
_richtexttypes.BLOCKS.PARAGRAPH
|
|
62
|
+
]);
|
|
63
|
+
(0, _vitest.expect)(editor.api.string([
|
|
64
|
+
0
|
|
65
|
+
])).toBe('some');
|
|
66
|
+
(0, _vitest.expect)(editor.api.string([
|
|
67
|
+
2
|
|
68
|
+
])).toBe(' text.');
|
|
69
|
+
});
|
|
70
|
+
(0, _vitest.it)('replaces an empty paragraph when pasting a void block', ()=>{
|
|
71
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
72
|
+
editor.tf.select({
|
|
73
|
+
path: [
|
|
74
|
+
0,
|
|
75
|
+
0
|
|
76
|
+
],
|
|
77
|
+
offset: 0
|
|
78
|
+
});
|
|
79
|
+
editor.insertFragment([
|
|
80
|
+
{
|
|
81
|
+
type: _richtexttypes.BLOCKS.HR,
|
|
82
|
+
isVoid: true,
|
|
83
|
+
children: [
|
|
84
|
+
{
|
|
85
|
+
text: ''
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
(0, _vitest.expect)(editor.children.map((node)=>node.type)).toEqual([
|
|
91
|
+
_richtexttypes.BLOCKS.HR,
|
|
92
|
+
_richtexttypes.BLOCKS.PARAGRAPH
|
|
93
|
+
]);
|
|
94
|
+
});
|
|
95
|
+
(0, _vitest.it)('preserves nodes and marks from HTML copied by the previous editor', ()=>{
|
|
96
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
97
|
+
const html = '<div data-slate-node="element"><strong data-slate-leaf="true"><span data-slate-string="true">bold</span></strong></div>';
|
|
98
|
+
(0, _vitest.expect)(editor.api.html.deserialize({
|
|
99
|
+
element: (0, _sanitizeHTML.sanitizeHTML)(html)
|
|
100
|
+
})).toEqual([
|
|
101
|
+
{
|
|
102
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
103
|
+
children: [
|
|
104
|
+
{
|
|
105
|
+
text: 'bold',
|
|
106
|
+
bold: true
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
(0, _vitest.it)('does not register task lists unsupported by the Contentful schema', ()=>{
|
|
113
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
114
|
+
(0, _vitest.expect)(editor.plugins[_platejs.KEYS.taskList]).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
(0, _vitest.it)('uses Contentful keyboard handlers without registering native shortcuts', ()=>{
|
|
117
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
118
|
+
(0, _vitest.expect)(Object.values(editor.meta.shortcuts).filter(Boolean)).toEqual([]);
|
|
119
|
+
});
|
|
120
|
+
(0, _vitest.it)('handles Enter on a selected embedded block', ()=>{
|
|
121
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
122
|
+
const embedded = {
|
|
123
|
+
type: _richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
124
|
+
isVoid: true,
|
|
125
|
+
children: [
|
|
126
|
+
{
|
|
127
|
+
text: ''
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
editor.children = [
|
|
132
|
+
embedded,
|
|
133
|
+
{
|
|
134
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
135
|
+
children: [
|
|
136
|
+
{
|
|
137
|
+
text: ''
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
editor.tf.select({
|
|
143
|
+
path: [
|
|
144
|
+
0,
|
|
145
|
+
0
|
|
146
|
+
],
|
|
147
|
+
offset: 0
|
|
148
|
+
});
|
|
149
|
+
(0, _vitest.expect)(editor.isVoid(embedded)).toBe(true);
|
|
150
|
+
(0, _vitest.expect)(editor.api.isVoid(embedded)).toBe(true);
|
|
151
|
+
(0, _vitest.expect)(editor.api.block()?.[0]).toBe(embedded);
|
|
152
|
+
const plugin = editor.contentfulPlugins.find((plugin)=>plugin.key === 'exitBreak');
|
|
153
|
+
plugin.handlers.onKeyDown(editor, plugin)({
|
|
154
|
+
key: 'Enter',
|
|
155
|
+
which: 13,
|
|
156
|
+
preventDefault: _vitest.vi.fn()
|
|
157
|
+
});
|
|
158
|
+
(0, _vitest.expect)(editor.children.map((node)=>node.type)).toEqual([
|
|
159
|
+
_richtexttypes.BLOCKS.PARAGRAPH,
|
|
160
|
+
_richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
161
|
+
_richtexttypes.BLOCKS.PARAGRAPH
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
(0, _vitest.it)('unwraps an empty quote on Backspace', ()=>{
|
|
165
|
+
const { editor } = (0, _createTestEditor.createTestEditor)({});
|
|
166
|
+
const paragraph = ()=>({
|
|
167
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
168
|
+
children: [
|
|
169
|
+
{
|
|
170
|
+
text: ''
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
editor.children = [
|
|
175
|
+
{
|
|
176
|
+
type: _richtexttypes.BLOCKS.QUOTE,
|
|
177
|
+
children: [
|
|
178
|
+
paragraph()
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
paragraph()
|
|
182
|
+
];
|
|
183
|
+
editor.tf.select({
|
|
184
|
+
path: [
|
|
185
|
+
0,
|
|
186
|
+
0,
|
|
187
|
+
0
|
|
188
|
+
],
|
|
189
|
+
offset: 0
|
|
190
|
+
});
|
|
191
|
+
const plugin = editor.contentfulPlugins.find((plugin)=>plugin.key === 'resetNode');
|
|
192
|
+
plugin.handlers.onKeyDown(editor, plugin)({
|
|
193
|
+
key: 'Backspace',
|
|
194
|
+
which: 8,
|
|
195
|
+
preventDefault: _vitest.vi.fn()
|
|
196
|
+
});
|
|
197
|
+
(0, _vitest.expect)(editor.children.map((node)=>node.type)).toEqual([
|
|
198
|
+
_richtexttypes.BLOCKS.PARAGRAPH,
|
|
199
|
+
_richtexttypes.BLOCKS.PARAGRAPH
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const
|
|
5
|
+
const _testutils = require("@platejs/test-utils");
|
|
6
6
|
const _vitest = require("vitest");
|
|
7
7
|
const _transforms = require("../transforms");
|
|
8
8
|
const paragraph = (text)=>({
|
|
@@ -15,7 +15,7 @@ const paragraph = (text)=>({
|
|
|
15
15
|
}
|
|
16
16
|
]
|
|
17
17
|
});
|
|
18
|
-
const createEditor = (children)=>(0,
|
|
18
|
+
const createEditor = (children)=>(0, _testutils.jsx)('editor', {}, children);
|
|
19
19
|
(0, _vitest.describe)('setEditorValue', ()=>{
|
|
20
20
|
(0, _vitest.it)('preserves cursor position when incoming value has the same structure', ()=>{
|
|
21
21
|
const initial = [
|