@contentful/field-editor-rich-text 2.0.0-next.23 → 2.0.0-next.26
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/dist/field-editor-rich-text.cjs.development.js +114 -57
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +114 -57
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +1 -1
- package/dist/plugins/Hyperlink/HyperlinkModal.d.ts +2 -1
- package/dist/plugins/Table/helpers.d.ts +2 -1
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -410
|
@@ -420,10 +420,12 @@ function isBlockSelected(editor, type) {
|
|
|
420
420
|
function isRootLevel(path) {
|
|
421
421
|
return path.length === 1;
|
|
422
422
|
}
|
|
423
|
-
function getNodeEntryFromSelection(editor, nodeTypeOrTypes) {
|
|
424
|
-
|
|
423
|
+
function getNodeEntryFromSelection(editor, nodeTypeOrTypes, path) {
|
|
424
|
+
var _path, _editor$selection;
|
|
425
|
+
|
|
426
|
+
path = (_path = path) != null ? _path : (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path;
|
|
427
|
+
if (!path) return [];
|
|
425
428
|
var nodeTypes = Array.isArray(nodeTypeOrTypes) ? nodeTypeOrTypes : [nodeTypeOrTypes];
|
|
426
|
-
var path = editor.selection.focus.path;
|
|
427
429
|
|
|
428
430
|
for (var i = 0; i < path.length; i++) {
|
|
429
431
|
var nodeEntry = Editor.node(editor, path.slice(0, i + 1));
|
|
@@ -582,18 +584,18 @@ function getAncestorPathFromSelection(editor) {
|
|
|
582
584
|
});
|
|
583
585
|
}
|
|
584
586
|
var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
|
|
585
|
-
var _editor$
|
|
587
|
+
var _editor$selection2, _editor$selection3;
|
|
586
588
|
|
|
587
|
-
return ((_editor$
|
|
589
|
+
return ((_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.offset) === getText(editor, (_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.path).length;
|
|
588
590
|
};
|
|
589
591
|
function currentSelectionStartsTableCell(editor) {
|
|
590
|
-
var _editor$
|
|
592
|
+
var _editor$selection4;
|
|
591
593
|
|
|
592
594
|
var _getNodeEntryFromSele2 = getNodeEntryFromSelection(editor, [BLOCKS.TABLE_CELL, BLOCKS.TABLE_HEADER_CELL]),
|
|
593
595
|
tableCellNode = _getNodeEntryFromSele2[0],
|
|
594
596
|
path = _getNodeEntryFromSele2[1];
|
|
595
597
|
|
|
596
|
-
return !!tableCellNode && (!getText(editor, path) || ((_editor$
|
|
598
|
+
return !!tableCellNode && (!getText(editor, path) || ((_editor$selection4 = editor.selection) == null ? void 0 : _editor$selection4.focus.offset) === 0);
|
|
597
599
|
}
|
|
598
600
|
/**
|
|
599
601
|
* This traversal strategy is unfortunately necessary because Slate doesn't
|
|
@@ -1056,6 +1058,9 @@ function FetchingWrappedEntryCard(props) {
|
|
|
1056
1058
|
var styles$3 = {
|
|
1057
1059
|
root: /*#__PURE__*/css({
|
|
1058
1060
|
marginBottom: '1.25rem !important',
|
|
1061
|
+
display: 'block'
|
|
1062
|
+
}),
|
|
1063
|
+
container: /*#__PURE__*/css({
|
|
1059
1064
|
// The next 2 properties ensure Entity card won't be aligned above
|
|
1060
1065
|
// a list item marker (i.e. bullet)
|
|
1061
1066
|
display: 'inline-block',
|
|
@@ -1100,7 +1105,8 @@ function LinkedEntityBlock(props) {
|
|
|
1100
1105
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
1101
1106
|
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
1102
1107
|
contentEditable: HAS_BEFORE_INPUT_SUPPORT ? false : undefined,
|
|
1103
|
-
draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined
|
|
1108
|
+
draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined,
|
|
1109
|
+
className: styles$3.container
|
|
1104
1110
|
}, entityType === 'Entry' && /*#__PURE__*/React__default.createElement(FetchingWrappedEntryCard, {
|
|
1105
1111
|
sdk: sdk,
|
|
1106
1112
|
entryId: entityId,
|
|
@@ -3203,29 +3209,31 @@ function HyperlinkModal(props) {
|
|
|
3203
3209
|
testId: "confirm-cta"
|
|
3204
3210
|
}, props.linkType ? 'Update' : 'Insert'))));
|
|
3205
3211
|
}
|
|
3206
|
-
function addOrEditLink(_x, _x2, _x3) {
|
|
3212
|
+
function addOrEditLink(_x, _x2, _x3, _x4) {
|
|
3207
3213
|
return _addOrEditLink.apply(this, arguments);
|
|
3208
3214
|
}
|
|
3209
3215
|
|
|
3210
3216
|
function _addOrEditLink() {
|
|
3211
|
-
_addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction) {
|
|
3217
|
+
_addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction, targetPath) {
|
|
3212
3218
|
var _target$sys$linkType;
|
|
3213
3219
|
|
|
3214
|
-
var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path,
|
|
3220
|
+
var selectionBeforeBlur, linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionAfterFocus, currentLinkText, isEditing, data, text, url, type, target;
|
|
3215
3221
|
|
|
3216
3222
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
3217
3223
|
while (1) {
|
|
3218
3224
|
switch (_context3.prev = _context3.next) {
|
|
3219
3225
|
case 0:
|
|
3220
|
-
|
|
3221
|
-
|
|
3226
|
+
selectionBeforeBlur = editor.selection ? _extends({}, editor.selection) : undefined;
|
|
3227
|
+
|
|
3228
|
+
if (!(!targetPath && !selectionBeforeBlur)) {
|
|
3229
|
+
_context3.next = 3;
|
|
3222
3230
|
break;
|
|
3223
3231
|
}
|
|
3224
3232
|
|
|
3225
3233
|
return _context3.abrupt("return");
|
|
3226
3234
|
|
|
3227
|
-
case
|
|
3228
|
-
_getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
|
|
3235
|
+
case 3:
|
|
3236
|
+
_getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES, targetPath), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
|
|
3229
3237
|
|
|
3230
3238
|
if (node && path) {
|
|
3231
3239
|
linkType = node.type;
|
|
@@ -3234,11 +3242,11 @@ function _addOrEditLink() {
|
|
|
3234
3242
|
linkEntity = node.data.target;
|
|
3235
3243
|
}
|
|
3236
3244
|
|
|
3237
|
-
|
|
3238
|
-
currentLinkText = linkText || Editor.string(editor, editor.selection);
|
|
3245
|
+
selectionAfterFocus = targetPath != null ? targetPath : selectionBeforeBlur;
|
|
3246
|
+
currentLinkText = linkText || (editor.selection ? Editor.string(editor, editor.selection) : '');
|
|
3239
3247
|
isEditing = Boolean(node && path);
|
|
3240
3248
|
logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
|
|
3241
|
-
_context3.next =
|
|
3249
|
+
_context3.next = 11;
|
|
3242
3250
|
return ModalDialogLauncher.openDialog({
|
|
3243
3251
|
title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
|
|
3244
3252
|
width: 'large',
|
|
@@ -3257,20 +3265,21 @@ function _addOrEditLink() {
|
|
|
3257
3265
|
});
|
|
3258
3266
|
});
|
|
3259
3267
|
|
|
3260
|
-
case
|
|
3268
|
+
case 11:
|
|
3261
3269
|
data = _context3.sent;
|
|
3270
|
+
Transforms.select(editor, selectionAfterFocus);
|
|
3262
3271
|
|
|
3263
3272
|
if (data) {
|
|
3264
|
-
_context3.next =
|
|
3273
|
+
_context3.next = 17;
|
|
3265
3274
|
break;
|
|
3266
3275
|
}
|
|
3267
3276
|
|
|
3277
|
+
focus(editor);
|
|
3268
3278
|
logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
|
|
3269
3279
|
return _context3.abrupt("return");
|
|
3270
3280
|
|
|
3271
|
-
case
|
|
3281
|
+
case 17:
|
|
3272
3282
|
text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
|
|
3273
|
-
Transforms.select(editor, selectionBeforeBlur);
|
|
3274
3283
|
Editor.withoutNormalizing(editor, function () {
|
|
3275
3284
|
insertLink(editor, {
|
|
3276
3285
|
text: text,
|
|
@@ -3286,7 +3295,7 @@ function _addOrEditLink() {
|
|
|
3286
3295
|
});
|
|
3287
3296
|
focus(editor);
|
|
3288
3297
|
|
|
3289
|
-
case
|
|
3298
|
+
case 21:
|
|
3290
3299
|
case "end":
|
|
3291
3300
|
return _context3.stop();
|
|
3292
3301
|
}
|
|
@@ -3540,7 +3549,11 @@ function EntityHyperlink(props) {
|
|
|
3540
3549
|
event.preventDefault();
|
|
3541
3550
|
event.stopPropagation();
|
|
3542
3551
|
if (!editor) return;
|
|
3543
|
-
|
|
3552
|
+
var p = ReactEditor.toSlatePoint(editor, [event.target, 0], {
|
|
3553
|
+
exactMatch: false,
|
|
3554
|
+
suppressThrow: false
|
|
3555
|
+
});
|
|
3556
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
3544
3557
|
}
|
|
3545
3558
|
|
|
3546
3559
|
return /*#__PURE__*/createElement(Tooltip, {
|
|
@@ -3568,7 +3581,11 @@ function UrlHyperlink(props) {
|
|
|
3568
3581
|
event.preventDefault();
|
|
3569
3582
|
event.stopPropagation();
|
|
3570
3583
|
if (!editor) return;
|
|
3571
|
-
|
|
3584
|
+
var p = ReactEditor.toSlatePoint(editor, [event.target, 0], {
|
|
3585
|
+
exactMatch: false,
|
|
3586
|
+
suppressThrow: false
|
|
3587
|
+
});
|
|
3588
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
3572
3589
|
}
|
|
3573
3590
|
|
|
3574
3591
|
return /*#__PURE__*/createElement(Tooltip, {
|
|
@@ -3844,37 +3861,44 @@ var moveListItems = function moveListItems(editor, _temp) {
|
|
|
3844
3861
|
* Credit: Modified version of Plate's list plugin
|
|
3845
3862
|
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
3846
3863
|
*/
|
|
3847
|
-
|
|
3864
|
+
|
|
3865
|
+
function hasUnliftedListItems(editor, at) {
|
|
3866
|
+
return Editor.nodes(editor, {
|
|
3867
|
+
at: at,
|
|
3868
|
+
match: function match(node, path) {
|
|
3869
|
+
return Element.isElement(node) && node.type === BLOCKS.LIST_ITEM && path.length >= 2;
|
|
3870
|
+
}
|
|
3871
|
+
}).next().done;
|
|
3872
|
+
}
|
|
3873
|
+
|
|
3848
3874
|
var unwrapList = function unwrapList(editor, _temp) {
|
|
3849
3875
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
3850
3876
|
at = _ref.at;
|
|
3851
3877
|
|
|
3852
3878
|
Editor.withoutNormalizing(editor, function () {
|
|
3853
3879
|
do {
|
|
3854
|
-
|
|
3880
|
+
// lift list items to the root level
|
|
3881
|
+
Transforms.liftNodes(editor, {
|
|
3855
3882
|
at: at,
|
|
3856
|
-
match: {
|
|
3857
|
-
type
|
|
3883
|
+
match: function match(node) {
|
|
3884
|
+
return Element.isElement(node) && node.type === BLOCKS.LIST_ITEM;
|
|
3858
3885
|
},
|
|
3859
|
-
|
|
3886
|
+
mode: 'lowest'
|
|
3860
3887
|
});
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
split: true
|
|
3867
|
-
});
|
|
3868
|
-
} while (getAbove(editor, {
|
|
3888
|
+
} while (!hasUnliftedListItems(editor, at)); // finally unwrap all lifted items
|
|
3889
|
+
|
|
3890
|
+
|
|
3891
|
+
unwrapNodes(editor, {
|
|
3892
|
+
at: at,
|
|
3869
3893
|
match: {
|
|
3870
|
-
type:
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
})
|
|
3894
|
+
type: BLOCKS.LIST_ITEM
|
|
3895
|
+
},
|
|
3896
|
+
split: false
|
|
3897
|
+
});
|
|
3874
3898
|
});
|
|
3875
3899
|
};
|
|
3876
3900
|
|
|
3877
|
-
var listTypes
|
|
3901
|
+
var listTypes = [BLOCKS.UL_LIST, BLOCKS.OL_LIST];
|
|
3878
3902
|
var toggleList = function toggleList(editor, _ref) {
|
|
3879
3903
|
var type = _ref.type;
|
|
3880
3904
|
return Editor.withoutNormalizing(editor, function () {
|
|
@@ -3895,7 +3919,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3895
3919
|
}, {
|
|
3896
3920
|
at: editor.selection,
|
|
3897
3921
|
match: function match(n) {
|
|
3898
|
-
return listTypes
|
|
3922
|
+
return listTypes.includes(n.type);
|
|
3899
3923
|
},
|
|
3900
3924
|
mode: 'lowest'
|
|
3901
3925
|
});
|
|
@@ -3936,19 +3960,25 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3936
3960
|
|
|
3937
3961
|
var commonEntry = Node.common(editor, startPoint.path, endPoint.path);
|
|
3938
3962
|
|
|
3939
|
-
if (listTypes
|
|
3940
|
-
|
|
3963
|
+
if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === BLOCKS.LIST_ITEM) {
|
|
3964
|
+
var listType = commonEntry[0].type;
|
|
3965
|
+
|
|
3966
|
+
if (commonEntry[0].type === BLOCKS.LIST_ITEM) {
|
|
3967
|
+
listType = Editor.parent(editor, commonEntry[1])[0].type;
|
|
3968
|
+
}
|
|
3969
|
+
|
|
3970
|
+
if (listType !== type) {
|
|
3941
3971
|
var startList = findNode(editor, {
|
|
3942
3972
|
at: Range.start(editor.selection),
|
|
3943
3973
|
match: {
|
|
3944
|
-
type: listTypes
|
|
3974
|
+
type: listTypes
|
|
3945
3975
|
},
|
|
3946
3976
|
mode: 'lowest'
|
|
3947
3977
|
});
|
|
3948
3978
|
var endList = findNode(editor, {
|
|
3949
3979
|
at: Range.end(editor.selection),
|
|
3950
3980
|
match: {
|
|
3951
|
-
type: listTypes
|
|
3981
|
+
type: listTypes
|
|
3952
3982
|
},
|
|
3953
3983
|
mode: 'lowest'
|
|
3954
3984
|
});
|
|
@@ -3963,7 +3993,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3963
3993
|
}, {
|
|
3964
3994
|
at: editor.selection,
|
|
3965
3995
|
match: function match(n, path) {
|
|
3966
|
-
return listTypes
|
|
3996
|
+
return listTypes.includes(n.type) && path.length >= rangeLength;
|
|
3967
3997
|
},
|
|
3968
3998
|
mode: 'all'
|
|
3969
3999
|
});
|
|
@@ -3981,7 +4011,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
3981
4011
|
}).reverse();
|
|
3982
4012
|
|
|
3983
4013
|
_nodes.forEach(function (n) {
|
|
3984
|
-
if (listTypes
|
|
4014
|
+
if (listTypes.includes(n[0].type)) {
|
|
3985
4015
|
setNodes(editor, {
|
|
3986
4016
|
type: type
|
|
3987
4017
|
}, {
|
|
@@ -4132,7 +4162,25 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
|
|
|
4132
4162
|
});
|
|
4133
4163
|
};
|
|
4134
4164
|
var isListTypeActive = function isListTypeActive(editor, type) {
|
|
4135
|
-
|
|
4165
|
+
var selection = editor.selection;
|
|
4166
|
+
|
|
4167
|
+
if (!selection) {
|
|
4168
|
+
return false;
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
if (Range.isExpanded(selection)) {
|
|
4172
|
+
var _Range$edges = Range.edges(selection),
|
|
4173
|
+
start = _Range$edges[0],
|
|
4174
|
+
end = _Range$edges[1];
|
|
4175
|
+
|
|
4176
|
+
var node = Node.common(editor, start.path, end.path);
|
|
4177
|
+
|
|
4178
|
+
if (node[0].type === type) {
|
|
4179
|
+
return true;
|
|
4180
|
+
}
|
|
4181
|
+
} // Lists can be nested. Here, we take the list type at the lowest level
|
|
4182
|
+
|
|
4183
|
+
|
|
4136
4184
|
var listNode = getBlockAbove(editor, {
|
|
4137
4185
|
match: {
|
|
4138
4186
|
type: [BLOCKS.OL_LIST, BLOCKS.UL_LIST]
|
|
@@ -5179,9 +5227,9 @@ var sanitizeHTML = function sanitizeHTML(html) {
|
|
|
5179
5227
|
// Parse the HTML string and pipe it through our transformers
|
|
5180
5228
|
var doc = transformers.reduce(function (value, cb) {
|
|
5181
5229
|
return cb(value);
|
|
5182
|
-
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
5183
|
-
|
|
5184
|
-
|
|
5230
|
+
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
5231
|
+
return doc.body.innerHTML.replace(/>\s+</g, '><') // Remove whitespace between tags
|
|
5232
|
+
.replace(/(.*)<div.*>(<table.*<\/table>)<\/div>(.*)/g, '$1$2$3'); // remove div containers from tables
|
|
5185
5233
|
};
|
|
5186
5234
|
|
|
5187
5235
|
/**
|
|
@@ -5722,6 +5770,9 @@ var isNotEmpty = function isNotEmpty(editor, _ref4) {
|
|
|
5722
5770
|
var path = _ref4[1];
|
|
5723
5771
|
return Array.from(Node.children(editor, path)).length !== 0;
|
|
5724
5772
|
};
|
|
5773
|
+
var isTable = function isTable(node) {
|
|
5774
|
+
return Element.isElement(node) && node.type === BLOCKS.TABLE;
|
|
5775
|
+
};
|
|
5725
5776
|
|
|
5726
5777
|
var styles$i = {
|
|
5727
5778
|
topRight: /*#__PURE__*/css({
|
|
@@ -5899,13 +5950,19 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5899
5950
|
var insertFragment = editor.insertFragment;
|
|
5900
5951
|
|
|
5901
5952
|
editor.insertFragment = function (fragments) {
|
|
5953
|
+
var _editor$selection;
|
|
5954
|
+
|
|
5902
5955
|
// We need to make sure we have a new, empty and clean paragraph in order to paste tables as-is due to how Slate behaves
|
|
5903
5956
|
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
5904
|
-
var
|
|
5905
|
-
return fragment
|
|
5957
|
+
var isInsertingTable = fragments.some(function (fragment) {
|
|
5958
|
+
return isTable(fragment);
|
|
5906
5959
|
});
|
|
5960
|
+
var isTableFirstFragment = fragments.findIndex(function (fragment) {
|
|
5961
|
+
return isTable(fragment);
|
|
5962
|
+
}) === 0;
|
|
5963
|
+
var currentLineHasText = getText(editor, (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path) !== '';
|
|
5907
5964
|
|
|
5908
|
-
if (
|
|
5965
|
+
if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
|
|
5909
5966
|
insertEmptyParagraph(editor);
|
|
5910
5967
|
}
|
|
5911
5968
|
|