@contentful/field-editor-rich-text 2.0.0-next.22 → 2.0.0-next.25
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 +81 -33
- 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 +81 -33
- 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
|
@@ -427,10 +427,12 @@ function isBlockSelected(editor, type) {
|
|
|
427
427
|
function isRootLevel(path) {
|
|
428
428
|
return path.length === 1;
|
|
429
429
|
}
|
|
430
|
-
function getNodeEntryFromSelection(editor, nodeTypeOrTypes) {
|
|
431
|
-
|
|
430
|
+
function getNodeEntryFromSelection(editor, nodeTypeOrTypes, path) {
|
|
431
|
+
var _path, _editor$selection;
|
|
432
|
+
|
|
433
|
+
path = (_path = path) != null ? _path : (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path;
|
|
434
|
+
if (!path) return [];
|
|
432
435
|
var nodeTypes = Array.isArray(nodeTypeOrTypes) ? nodeTypeOrTypes : [nodeTypeOrTypes];
|
|
433
|
-
var path = editor.selection.focus.path;
|
|
434
436
|
|
|
435
437
|
for (var i = 0; i < path.length; i++) {
|
|
436
438
|
var nodeEntry = slate.Editor.node(editor, path.slice(0, i + 1));
|
|
@@ -589,18 +591,18 @@ function getAncestorPathFromSelection(editor) {
|
|
|
589
591
|
});
|
|
590
592
|
}
|
|
591
593
|
var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
|
|
592
|
-
var _editor$
|
|
594
|
+
var _editor$selection2, _editor$selection3;
|
|
593
595
|
|
|
594
|
-
return ((_editor$
|
|
596
|
+
return ((_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.offset) === plateCore.getText(editor, (_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.path).length;
|
|
595
597
|
};
|
|
596
598
|
function currentSelectionStartsTableCell(editor) {
|
|
597
|
-
var _editor$
|
|
599
|
+
var _editor$selection4;
|
|
598
600
|
|
|
599
601
|
var _getNodeEntryFromSele2 = getNodeEntryFromSelection(editor, [Contentful.BLOCKS.TABLE_CELL, Contentful.BLOCKS.TABLE_HEADER_CELL]),
|
|
600
602
|
tableCellNode = _getNodeEntryFromSele2[0],
|
|
601
603
|
path = _getNodeEntryFromSele2[1];
|
|
602
604
|
|
|
603
|
-
return !!tableCellNode && (!plateCore.getText(editor, path) || ((_editor$
|
|
605
|
+
return !!tableCellNode && (!plateCore.getText(editor, path) || ((_editor$selection4 = editor.selection) == null ? void 0 : _editor$selection4.focus.offset) === 0);
|
|
604
606
|
}
|
|
605
607
|
/**
|
|
606
608
|
* This traversal strategy is unfortunately necessary because Slate doesn't
|
|
@@ -1062,7 +1064,14 @@ function FetchingWrappedEntryCard(props) {
|
|
|
1062
1064
|
|
|
1063
1065
|
var styles$3 = {
|
|
1064
1066
|
root: /*#__PURE__*/emotion.css({
|
|
1065
|
-
marginBottom: '1.25rem !important'
|
|
1067
|
+
marginBottom: '1.25rem !important',
|
|
1068
|
+
display: 'block'
|
|
1069
|
+
}),
|
|
1070
|
+
container: /*#__PURE__*/emotion.css({
|
|
1071
|
+
// The next 2 properties ensure Entity card won't be aligned above
|
|
1072
|
+
// a list item marker (i.e. bullet)
|
|
1073
|
+
display: 'inline-block',
|
|
1074
|
+
verticalAlign: 'text-top'
|
|
1066
1075
|
})
|
|
1067
1076
|
};
|
|
1068
1077
|
function LinkedEntityBlock(props) {
|
|
@@ -1103,7 +1112,8 @@ function LinkedEntityBlock(props) {
|
|
|
1103
1112
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
1104
1113
|
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
1105
1114
|
contentEditable: HAS_BEFORE_INPUT_SUPPORT ? false : undefined,
|
|
1106
|
-
draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined
|
|
1115
|
+
draggable: HAS_BEFORE_INPUT_SUPPORT ? true : undefined,
|
|
1116
|
+
className: styles$3.container
|
|
1107
1117
|
}, entityType === 'Entry' && /*#__PURE__*/React__default.createElement(FetchingWrappedEntryCard, {
|
|
1108
1118
|
sdk: sdk,
|
|
1109
1119
|
entryId: entityId,
|
|
@@ -3206,29 +3216,31 @@ function HyperlinkModal(props) {
|
|
|
3206
3216
|
testId: "confirm-cta"
|
|
3207
3217
|
}, props.linkType ? 'Update' : 'Insert'))));
|
|
3208
3218
|
}
|
|
3209
|
-
function addOrEditLink(_x, _x2, _x3) {
|
|
3219
|
+
function addOrEditLink(_x, _x2, _x3, _x4) {
|
|
3210
3220
|
return _addOrEditLink.apply(this, arguments);
|
|
3211
3221
|
}
|
|
3212
3222
|
|
|
3213
3223
|
function _addOrEditLink() {
|
|
3214
|
-
_addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction) {
|
|
3224
|
+
_addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction, targetPath) {
|
|
3215
3225
|
var _target$sys$linkType;
|
|
3216
3226
|
|
|
3217
|
-
var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path,
|
|
3227
|
+
var selectionBeforeBlur, linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionAfterFocus, currentLinkText, isEditing, data, text, url, type, target;
|
|
3218
3228
|
|
|
3219
3229
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
3220
3230
|
while (1) {
|
|
3221
3231
|
switch (_context3.prev = _context3.next) {
|
|
3222
3232
|
case 0:
|
|
3223
|
-
|
|
3224
|
-
|
|
3233
|
+
selectionBeforeBlur = editor.selection ? _extends({}, editor.selection) : undefined;
|
|
3234
|
+
|
|
3235
|
+
if (!(!targetPath && !selectionBeforeBlur)) {
|
|
3236
|
+
_context3.next = 3;
|
|
3225
3237
|
break;
|
|
3226
3238
|
}
|
|
3227
3239
|
|
|
3228
3240
|
return _context3.abrupt("return");
|
|
3229
3241
|
|
|
3230
|
-
case
|
|
3231
|
-
_getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
|
|
3242
|
+
case 3:
|
|
3243
|
+
_getNodeEntryFromSele = getNodeEntryFromSelection(editor, LINK_TYPES, targetPath), node = _getNodeEntryFromSele[0], path = _getNodeEntryFromSele[1];
|
|
3232
3244
|
|
|
3233
3245
|
if (node && path) {
|
|
3234
3246
|
linkType = node.type;
|
|
@@ -3237,11 +3249,11 @@ function _addOrEditLink() {
|
|
|
3237
3249
|
linkEntity = node.data.target;
|
|
3238
3250
|
}
|
|
3239
3251
|
|
|
3240
|
-
|
|
3241
|
-
currentLinkText = linkText || slate.Editor.string(editor, editor.selection);
|
|
3252
|
+
selectionAfterFocus = targetPath != null ? targetPath : selectionBeforeBlur;
|
|
3253
|
+
currentLinkText = linkText || (editor.selection ? slate.Editor.string(editor, editor.selection) : '');
|
|
3242
3254
|
isEditing = Boolean(node && path);
|
|
3243
3255
|
logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
|
|
3244
|
-
_context3.next =
|
|
3256
|
+
_context3.next = 11;
|
|
3245
3257
|
return fieldEditorShared.ModalDialogLauncher.openDialog({
|
|
3246
3258
|
title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
|
|
3247
3259
|
width: 'large',
|
|
@@ -3260,20 +3272,21 @@ function _addOrEditLink() {
|
|
|
3260
3272
|
});
|
|
3261
3273
|
});
|
|
3262
3274
|
|
|
3263
|
-
case
|
|
3275
|
+
case 11:
|
|
3264
3276
|
data = _context3.sent;
|
|
3277
|
+
slate.Transforms.select(editor, selectionAfterFocus);
|
|
3265
3278
|
|
|
3266
3279
|
if (data) {
|
|
3267
|
-
_context3.next =
|
|
3280
|
+
_context3.next = 17;
|
|
3268
3281
|
break;
|
|
3269
3282
|
}
|
|
3270
3283
|
|
|
3284
|
+
focus(editor);
|
|
3271
3285
|
logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
|
|
3272
3286
|
return _context3.abrupt("return");
|
|
3273
3287
|
|
|
3274
|
-
case
|
|
3288
|
+
case 17:
|
|
3275
3289
|
text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
|
|
3276
|
-
slate.Transforms.select(editor, selectionBeforeBlur);
|
|
3277
3290
|
slate.Editor.withoutNormalizing(editor, function () {
|
|
3278
3291
|
insertLink(editor, {
|
|
3279
3292
|
text: text,
|
|
@@ -3289,7 +3302,7 @@ function _addOrEditLink() {
|
|
|
3289
3302
|
});
|
|
3290
3303
|
focus(editor);
|
|
3291
3304
|
|
|
3292
|
-
case
|
|
3305
|
+
case 21:
|
|
3293
3306
|
case "end":
|
|
3294
3307
|
return _context3.stop();
|
|
3295
3308
|
}
|
|
@@ -3543,7 +3556,11 @@ function EntityHyperlink(props) {
|
|
|
3543
3556
|
event.preventDefault();
|
|
3544
3557
|
event.stopPropagation();
|
|
3545
3558
|
if (!editor) return;
|
|
3546
|
-
|
|
3559
|
+
var p = Slate.ReactEditor.toSlatePoint(editor, [event.target, 0], {
|
|
3560
|
+
exactMatch: false,
|
|
3561
|
+
suppressThrow: false
|
|
3562
|
+
});
|
|
3563
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
3547
3564
|
}
|
|
3548
3565
|
|
|
3549
3566
|
return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
|
|
@@ -3571,7 +3588,11 @@ function UrlHyperlink(props) {
|
|
|
3571
3588
|
event.preventDefault();
|
|
3572
3589
|
event.stopPropagation();
|
|
3573
3590
|
if (!editor) return;
|
|
3574
|
-
|
|
3591
|
+
var p = Slate.ReactEditor.toSlatePoint(editor, [event.target, 0], {
|
|
3592
|
+
exactMatch: false,
|
|
3593
|
+
suppressThrow: false
|
|
3594
|
+
});
|
|
3595
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
3575
3596
|
}
|
|
3576
3597
|
|
|
3577
3598
|
return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
|
|
@@ -4135,7 +4156,25 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
|
|
|
4135
4156
|
});
|
|
4136
4157
|
};
|
|
4137
4158
|
var isListTypeActive = function isListTypeActive(editor, type) {
|
|
4138
|
-
|
|
4159
|
+
var selection = editor.selection;
|
|
4160
|
+
|
|
4161
|
+
if (!selection) {
|
|
4162
|
+
return false;
|
|
4163
|
+
}
|
|
4164
|
+
|
|
4165
|
+
if (slate.Range.isExpanded(selection)) {
|
|
4166
|
+
var _Range$edges = slate.Range.edges(selection),
|
|
4167
|
+
start = _Range$edges[0],
|
|
4168
|
+
end = _Range$edges[1];
|
|
4169
|
+
|
|
4170
|
+
var node = slate.Node.common(editor, start.path, end.path);
|
|
4171
|
+
|
|
4172
|
+
if (node[0].type === type) {
|
|
4173
|
+
return true;
|
|
4174
|
+
}
|
|
4175
|
+
} // Lists can be nested. Here, we take the list type at the lowest level
|
|
4176
|
+
|
|
4177
|
+
|
|
4139
4178
|
var listNode = plateCore.getBlockAbove(editor, {
|
|
4140
4179
|
match: {
|
|
4141
4180
|
type: [Contentful.BLOCKS.OL_LIST, Contentful.BLOCKS.UL_LIST]
|
|
@@ -5182,9 +5221,9 @@ var sanitizeHTML = function sanitizeHTML(html) {
|
|
|
5182
5221
|
// Parse the HTML string and pipe it through our transformers
|
|
5183
5222
|
var doc = transformers.reduce(function (value, cb) {
|
|
5184
5223
|
return cb(value);
|
|
5185
|
-
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
5186
|
-
|
|
5187
|
-
|
|
5224
|
+
}, new DOMParser().parseFromString(html, 'text/html'));
|
|
5225
|
+
return doc.body.innerHTML.replace(/>\s+</g, '><') // Remove whitespace between tags
|
|
5226
|
+
.replace(/(.*)<div.*>(<table.*<\/table>)<\/div>(.*)/g, '$1$2$3'); // remove div containers from tables
|
|
5188
5227
|
};
|
|
5189
5228
|
|
|
5190
5229
|
/**
|
|
@@ -5725,6 +5764,9 @@ var isNotEmpty = function isNotEmpty(editor, _ref4) {
|
|
|
5725
5764
|
var path = _ref4[1];
|
|
5726
5765
|
return Array.from(slate.Node.children(editor, path)).length !== 0;
|
|
5727
5766
|
};
|
|
5767
|
+
var isTable = function isTable(node) {
|
|
5768
|
+
return slate.Element.isElement(node) && node.type === Contentful.BLOCKS.TABLE;
|
|
5769
|
+
};
|
|
5728
5770
|
|
|
5729
5771
|
var styles$i = {
|
|
5730
5772
|
topRight: /*#__PURE__*/emotion.css({
|
|
@@ -5902,13 +5944,19 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5902
5944
|
var insertFragment = editor.insertFragment;
|
|
5903
5945
|
|
|
5904
5946
|
editor.insertFragment = function (fragments) {
|
|
5947
|
+
var _editor$selection;
|
|
5948
|
+
|
|
5905
5949
|
// 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
|
|
5906
5950
|
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
5907
|
-
var
|
|
5908
|
-
return fragment
|
|
5951
|
+
var isInsertingTable = fragments.some(function (fragment) {
|
|
5952
|
+
return isTable(fragment);
|
|
5909
5953
|
});
|
|
5954
|
+
var isTableFirstFragment = fragments.findIndex(function (fragment) {
|
|
5955
|
+
return isTable(fragment);
|
|
5956
|
+
}) === 0;
|
|
5957
|
+
var currentLineHasText = plateCore.getText(editor, (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path) !== '';
|
|
5910
5958
|
|
|
5911
|
-
if (
|
|
5959
|
+
if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
|
|
5912
5960
|
insertEmptyParagraph(editor);
|
|
5913
5961
|
}
|
|
5914
5962
|
|