@contentful/field-editor-rich-text 2.0.0-next.1 → 2.0.0-next.2

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +410 -0
  2. package/dist/field-editor-rich-text.cjs.development.js +569 -317
  3. package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
  4. package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
  5. package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
  6. package/dist/field-editor-rich-text.esm.js +467 -215
  7. package/dist/field-editor-rich-text.esm.js.map +1 -1
  8. package/dist/helpers/deserializer.d.ts +1 -1
  9. package/dist/helpers/editor.d.ts +8 -3
  10. package/dist/helpers/normalizers.d.ts +15 -0
  11. package/dist/plugins/Bold/index.d.ts +1 -1
  12. package/dist/plugins/Code/index.d.ts +1 -1
  13. package/dist/plugins/DragAndDrop/index.d.ts +1 -1
  14. package/dist/plugins/EmbeddedEntityBlock/index.d.ts +1 -1
  15. package/dist/plugins/EmbeddedEntityInline/index.d.ts +1 -1
  16. package/dist/plugins/Heading/index.d.ts +1 -1
  17. package/dist/plugins/Hr/index.d.ts +1 -1
  18. package/dist/plugins/Hyperlink/HyperlinkModal.d.ts +1 -1
  19. package/dist/plugins/Hyperlink/index.d.ts +1 -1
  20. package/dist/plugins/InsertBeforeFirstVoidBlock/index.d.ts +1 -1
  21. package/dist/plugins/Italic/index.d.ts +1 -1
  22. package/dist/plugins/List/getListInsertFragment.d.ts +1 -1
  23. package/dist/plugins/List/index.d.ts +1 -1
  24. package/dist/plugins/NewLine/index.d.ts +1 -1
  25. package/dist/plugins/Paragraph/index.d.ts +1 -1
  26. package/dist/plugins/Paste/index.d.ts +1 -1
  27. package/dist/plugins/Paste/sanitizers/helpers.d.ts +1 -1
  28. package/dist/plugins/Quote/index.d.ts +1 -1
  29. package/dist/plugins/Table/actions/addColumn.d.ts +1 -2
  30. package/dist/plugins/Table/actions/addRow.d.ts +1 -1
  31. package/dist/plugins/Table/actions/setHeader.d.ts +1 -1
  32. package/dist/plugins/Table/helpers.d.ts +2 -1
  33. package/dist/plugins/Table/index.d.ts +168 -168
  34. package/dist/plugins/Table/normalizers.d.ts +2 -0
  35. package/dist/plugins/Text/index.d.ts +2 -0
  36. package/dist/plugins/TrailingParagraph/index.d.ts +1 -1
  37. package/dist/plugins/Underline/index.d.ts +1 -1
  38. package/dist/plugins/index.d.ts +180 -0
  39. package/dist/test-utils/createEditor.d.ts +7 -0
  40. package/dist/test-utils/index.d.ts +2 -0
  41. package/dist/test-utils/jsx.d.ts +28 -0
  42. package/dist/types.d.ts +1 -1
  43. package/package.json +5 -12
@@ -17,23 +17,14 @@ var f36Components = require('@contentful/f36-components');
17
17
  var Slate = require('slate-react');
18
18
  var f36Icons = require('@contentful/f36-icons');
19
19
  var slate = require('slate');
20
- var plateCore = require('@udecode/plate-core');
21
- var plateCommon = require('@udecode/plate-common');
20
+ var plate = require('@udecode/plate');
22
21
  var constate = _interopDefault(require('constate'));
23
22
  var find = _interopDefault(require('lodash/find'));
24
23
  var flow = _interopDefault(require('lodash/flow'));
25
24
  var get = _interopDefault(require('lodash/get'));
26
- var plateList = require('@udecode/plate-list');
27
- var richTextPlainTextRenderer = require('@contentful/rich-text-plain-text-renderer');
28
25
  var fieldEditorShared = require('@contentful/field-editor-shared');
29
26
  var mimetype = _interopDefault(require('@contentful/mimetype'));
30
- var plateTable = require('@udecode/plate-table');
31
- var plateAstSerializer = require('@udecode/plate-ast-serializer');
32
- var plateHtmlSerializer = require('@udecode/plate-html-serializer');
33
- var plateParagraph = require('@udecode/plate-paragraph');
34
- var plateBreak = require('@udecode/plate-break');
35
27
  var values = _interopDefault(require('lodash/values'));
36
- var plateTrailingBlock = require('@udecode/plate-trailing-block');
37
28
  var PropTypes = _interopDefault(require('prop-types'));
38
29
 
39
30
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -569,7 +560,7 @@ function unwrapFromRoot(editor) {
569
560
  var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
570
561
  var _editor$selection, _editor$selection2;
571
562
 
572
- return ((_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.offset) === plateCommon.getText(editor, (_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.path).length;
563
+ return ((_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.offset) === plate.getText(editor, (_editor$selection2 = editor.selection) == null ? void 0 : _editor$selection2.focus.path).length;
573
564
  };
574
565
  function currentSelectionStartsTableCell(editor) {
575
566
  var _editor$selection3;
@@ -578,7 +569,7 @@ function currentSelectionStartsTableCell(editor) {
578
569
  tableCellNode = _getNodeEntryFromSele2[0],
579
570
  path = _getNodeEntryFromSele2[1];
580
571
 
581
- return !!tableCellNode && (!plateCommon.getText(editor, path) || ((_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.offset) === 0);
572
+ return !!tableCellNode && (!plate.getText(editor, path) || ((_editor$selection3 = editor.selection) == null ? void 0 : _editor$selection3.focus.offset) === 0);
582
573
  }
583
574
  /**
584
575
  * This traversal strategy is unfortunately necessary because Slate doesn't
@@ -617,12 +608,39 @@ function currentSelectionPrecedesTableCell(editor) {
617
608
  var nextNode = getNextNode(editor);
618
609
  return !!nextNode && Contentful.TABLE_BLOCKS.includes(nextNode.type) && isAtEndOfTextSelection(editor);
619
610
  }
611
+ var replaceNode = function replaceNode(editor, path, replacement) {
612
+ slate.Transforms.removeNodes(editor, {
613
+ at: path
614
+ });
615
+ slate.Transforms.insertNodes(editor, replacement, {
616
+ at: path
617
+ });
618
+ };
619
+ /**
620
+ * It filters out all paragraphs and headings from a path and convert them into paragraphs.
621
+ */
622
+
623
+ function extractParagraphsAt(editor, path) {
624
+ var paragraphs = Array.from(slate.Editor.nodes(editor, {
625
+ at: path,
626
+ match: function match(node) {
627
+ return Contentful.TEXT_CONTAINERS.includes(node.type);
628
+ },
629
+ mode: 'all'
630
+ })).map(function (_ref2) {
631
+ var node = _ref2[0];
632
+ return _extends({}, node, {
633
+ type: Contentful.BLOCKS.PARAGRAPH
634
+ });
635
+ });
636
+ return paragraphs;
637
+ }
620
638
 
621
639
  function deserializeLeaf(type, rules) {
622
640
  return function (editor) {
623
- var pluginOptions = plateCore.getPlatePluginOptions(editor, type);
641
+ var pluginOptions = plate.getPlatePluginOptions(editor, type);
624
642
  return {
625
- leaf: plateCommon.getLeafDeserializer(_extends({
643
+ leaf: plate.getLeafDeserializer(_extends({
626
644
  type: type,
627
645
  rules: rules
628
646
  }, pluginOptions.deserialize))
@@ -631,9 +649,9 @@ function deserializeLeaf(type, rules) {
631
649
  }
632
650
  function deserializeElement(type, rules) {
633
651
  return function (editor) {
634
- var pluginOptions = plateCore.getPlatePluginOptions(editor, type);
652
+ var pluginOptions = plate.getPlatePluginOptions(editor, type);
635
653
  return {
636
- element: plateCommon.getElementDeserializer(_extends({
654
+ element: plate.getElementDeserializer(_extends({
637
655
  type: type,
638
656
  rules: rules
639
657
  }, pluginOptions.deserialize))
@@ -651,7 +669,7 @@ function getContentfulEditorId(sdk) {
651
669
  function useContentfulEditorHook(_ref) {
652
670
  var sdk = _ref.sdk;
653
671
  var editorId = getContentfulEditorId(sdk);
654
- var editor = plateCore.usePlateEditorRef(editorId);
672
+ var editor = plate.usePlateEditorRef(editorId);
655
673
  return editor;
656
674
  }
657
675
 
@@ -708,8 +726,8 @@ function ToolbarHrButton(props) {
708
726
  }],
709
727
  isVoid: true
710
728
  };
711
- var hasText = !!plateCommon.getText(editor, editor.selection.focus.path);
712
- hasText ? slate.Transforms.insertNodes(editor, hr) : plateCommon.setNodes(editor, hr); // Move focus to the next paragraph (added by TrailingParagraph plugin)
729
+ var hasText = !!plate.getText(editor, editor.selection.focus.path);
730
+ hasText ? slate.Transforms.insertNodes(editor, hr) : plate.setNodes(editor, hr); // Move focus to the next paragraph (added by TrailingParagraph plugin)
713
731
 
714
732
  moveToTheNextLine(editor);
715
733
  Slate.ReactEditor.focus(editor);
@@ -737,10 +755,10 @@ function Hr(props) {
737
755
  }
738
756
  function createHrPlugin() {
739
757
  return {
740
- renderElement: plateCore.getRenderElement(Contentful.BLOCKS.HR),
758
+ renderElement: plate.getRenderElement(Contentful.BLOCKS.HR),
741
759
  pluginKeys: Contentful.BLOCKS.HR,
742
760
  onKeyDown: withHrEvents,
743
- voidTypes: plateCore.getPlatePluginTypes(Contentful.BLOCKS.HR),
761
+ voidTypes: plate.getPlatePluginTypes(Contentful.BLOCKS.HR),
744
762
  deserialize: deserializeElement(Contentful.BLOCKS.HR, [{
745
763
  nodeNames: ['HR']
746
764
  }])
@@ -842,19 +860,19 @@ function withHeadingEvents(editor) {
842
860
  var cursorIsAtTheEnd = currentTextLength === currentOffset;
843
861
 
844
862
  if (cursorIsAtTheBeginning) {
845
- plateCommon.insertNodes(editor, paragraph, {
863
+ plate.insertNodes(editor, paragraph, {
846
864
  at: editor.selection
847
865
  });
848
866
  } else if (cursorIsAtTheEnd) {
849
- plateCommon.insertNodes(editor, paragraph);
867
+ plate.insertNodes(editor, paragraph);
850
868
  } else {
851
869
  // Otherwise the cursor is in the middle
852
870
  slate.Transforms.splitNodes(editor);
853
- plateCommon.setNodes(editor, paragraph);
871
+ plate.setNodes(editor, paragraph);
854
872
  }
855
873
  } else {
856
- plateCommon.setNodes(editor, paragraph);
857
- plateCommon.insertNodes(editor, heading);
874
+ plate.setNodes(editor, paragraph);
875
+ plate.insertNodes(editor, heading);
858
876
  }
859
877
  } // Toggle heading blocks when pressing cmd/ctrl+alt+1|2|3|4|5|6
860
878
 
@@ -878,7 +896,7 @@ function withHeadingEvents(editor) {
878
896
  unwrapFromRoot(editor);
879
897
  }
880
898
 
881
- plateCommon.toggleNodeType(editor, {
899
+ plate.toggleNodeType(editor, {
882
900
  activeType: headingKey,
883
901
  inactiveType: Contentful.BLOCKS.PARAGRAPH
884
902
  });
@@ -929,7 +947,7 @@ function ToolbarHeadingButton(props) {
929
947
  unwrapFromRoot(editor);
930
948
  }
931
949
 
932
- plateCommon.toggleNodeType(editor, {
950
+ plate.toggleNodeType(editor, {
933
951
  activeType: type,
934
952
  inactiveType: type
935
953
  }); // TODO: Figure out why focus only works with timeout here.
@@ -979,18 +997,18 @@ var H1 = /*#__PURE__*/createHeading('h1', Contentful.BLOCKS.HEADING_1);
979
997
  var H2 = /*#__PURE__*/createHeading('h2', Contentful.BLOCKS.HEADING_2);
980
998
  var H3 = /*#__PURE__*/createHeading('h3', Contentful.BLOCKS.HEADING_3);
981
999
  var H4 = /*#__PURE__*/createHeading('h4', Contentful.BLOCKS.HEADING_4);
982
- var H5 = /*#__PURE__*/createHeading('h1', Contentful.BLOCKS.HEADING_5);
983
- var H6 = /*#__PURE__*/createHeading('h1', Contentful.BLOCKS.HEADING_6);
1000
+ var H5 = /*#__PURE__*/createHeading('h5', Contentful.BLOCKS.HEADING_5);
1001
+ var H6 = /*#__PURE__*/createHeading('h6', Contentful.BLOCKS.HEADING_6);
984
1002
  function createHeadingPlugin() {
985
1003
  var headings = [Contentful.BLOCKS.HEADING_1, Contentful.BLOCKS.HEADING_2, Contentful.BLOCKS.HEADING_3, Contentful.BLOCKS.HEADING_4, Contentful.BLOCKS.HEADING_5, Contentful.BLOCKS.HEADING_6];
986
1004
  return {
987
- renderElement: plateCore.getRenderElement(headings),
1005
+ renderElement: plate.getRenderElement(headings),
988
1006
  pluginKeys: headings,
989
1007
  onKeyDown: withHeadingEvents,
990
1008
  deserialize: function deserialize(editor) {
991
1009
  return {
992
1010
  element: headings.map(function (headingType, index) {
993
- var options = plateCore.getPlatePluginOptions(editor, headingType);
1011
+ var options = plate.getPlatePluginOptions(editor, headingType);
994
1012
  return _extends({
995
1013
  type: headingType,
996
1014
  deserialize: function deserialize(element) {
@@ -1132,7 +1150,7 @@ function Quote(props) {
1132
1150
  function createQuotePlugin() {
1133
1151
  return {
1134
1152
  pluginKeys: Contentful.BLOCKS.QUOTE,
1135
- renderElement: plateCore.getRenderElement(Contentful.BLOCKS.QUOTE),
1153
+ renderElement: plate.getRenderElement(Contentful.BLOCKS.QUOTE),
1136
1154
  onKeyDown: withQuoteEvents,
1137
1155
  deserialize: deserializeElement(Contentful.BLOCKS.QUOTE, [{
1138
1156
  nodeNames: 'BLOCKQUOTE'
@@ -1148,20 +1166,11 @@ var withQuoteOptions = (_withQuoteOptions = {}, _withQuoteOptions[Contentful.BLO
1148
1166
  * A copy of Plate's list plugin with a few adjustments
1149
1167
  * to fix pasting text inside lists.
1150
1168
  */
1151
-
1152
- var slateNodesToText = function slateNodesToText(nodes) {
1153
- var contentfulNode = contentfulSlatejsAdapter.toContentfulDocument({
1154
- document: nodes,
1155
- schema: schema
1156
- });
1157
- return richTextPlainTextRenderer.documentToPlainTextString(contentfulNode);
1158
- };
1159
-
1160
1169
  var getListInsertFragment = function getListInsertFragment(editor) {
1161
1170
  var insertFragment = editor.insertFragment;
1162
- var li = plateCore.getPlatePluginOptions(editor, plateList.ELEMENT_LI);
1163
- var ul = plateCore.getPlatePluginOptions(editor, plateList.ELEMENT_UL);
1164
- var ol = plateCore.getPlatePluginOptions(editor, plateList.ELEMENT_OL);
1171
+ var li = plate.getPlatePluginOptions(editor, plate.ELEMENT_LI);
1172
+ var ul = plate.getPlatePluginOptions(editor, plate.ELEMENT_UL);
1173
+ var ol = plate.getPlatePluginOptions(editor, plate.ELEMENT_OL);
1165
1174
 
1166
1175
  var isListRoot = function isListRoot(node) {
1167
1176
  return [ul.type, ol.type].includes(node.type);
@@ -1198,7 +1207,7 @@ var getListInsertFragment = function getListInsertFragment(editor) {
1198
1207
  };
1199
1208
 
1200
1209
  return function (fragment) {
1201
- var liEntry = plateCommon.findNode(editor, {
1210
+ var liEntry = plate.findNode(editor, {
1202
1211
  match: {
1203
1212
  type: li.type
1204
1213
  },
@@ -1212,10 +1221,7 @@ var getListInsertFragment = function getListInsertFragment(editor) {
1212
1221
  var nodes = fragment.flatMap(function (node) {
1213
1222
  return trimList(node);
1214
1223
  });
1215
- var text = slateNodesToText(nodes);
1216
- return slate.Transforms.insertNodes(editor, [{
1217
- text: text
1218
- }], {
1224
+ return slate.Transforms.insertNodes(editor, nodes, {
1219
1225
  at: editor.selection || slate.Path.next(liPath),
1220
1226
  select: true
1221
1227
  });
@@ -1241,7 +1247,7 @@ function ToolbarListButton(props) {
1241
1247
  unwrapFromRoot(editor);
1242
1248
  }
1243
1249
 
1244
- plateList.toggleList(editor, {
1250
+ plate.toggleList(editor, {
1245
1251
  type: type
1246
1252
  });
1247
1253
  Slate.ReactEditor.focus(editor);
@@ -1275,21 +1281,103 @@ function createList(Tag, block) {
1275
1281
  var UL = /*#__PURE__*/createList('ul', Contentful.BLOCKS.UL_LIST);
1276
1282
  var OL = /*#__PURE__*/createList('ol', Contentful.BLOCKS.OL_LIST);
1277
1283
  var LI = /*#__PURE__*/createList('li', Contentful.BLOCKS.LIST_ITEM);
1278
- var withListOptions = (_withListOptions = {}, _withListOptions[plateList.ELEMENT_LIC] = {
1284
+ var withListOptions = (_withListOptions = {}, _withListOptions[plate.ELEMENT_LIC] = {
1279
1285
  type: Contentful.BLOCKS.PARAGRAPH
1280
- }, _withListOptions[plateList.ELEMENT_LI] = {
1286
+ }, _withListOptions[plate.ELEMENT_LI] = {
1281
1287
  type: Contentful.BLOCKS.LIST_ITEM,
1282
1288
  component: LI
1283
- }, _withListOptions[plateList.ELEMENT_UL] = {
1289
+ }, _withListOptions[plate.ELEMENT_UL] = {
1284
1290
  type: Contentful.BLOCKS.UL_LIST,
1285
1291
  component: UL
1286
- }, _withListOptions[plateList.ELEMENT_OL] = {
1292
+ }, _withListOptions[plate.ELEMENT_OL] = {
1287
1293
  type: Contentful.BLOCKS.OL_LIST,
1288
1294
  component: OL
1289
1295
  }, _withListOptions);
1290
1296
 
1297
+ var emptyNodeOfType = function emptyNodeOfType(type) {
1298
+ return {
1299
+ type: type,
1300
+ children: [],
1301
+ data: {}
1302
+ };
1303
+ };
1304
+
1305
+ var isList = function isList(node) {
1306
+ return [Contentful.BLOCKS.OL_LIST, Contentful.BLOCKS.UL_LIST].includes(node.type);
1307
+ };
1308
+
1309
+ var isListItem = function isListItem(node) {
1310
+ return node.type === Contentful.BLOCKS.LIST_ITEM;
1311
+ };
1312
+
1313
+ var hasListAsDirectParent = function hasListAsDirectParent(editor, path) {
1314
+ var _ref = plate.getParent(editor, path) || [],
1315
+ parentNode = _ref[0];
1316
+
1317
+ return isList(parentNode);
1318
+ };
1319
+
1320
+ var isValidInsideListItem = function isValidInsideListItem(node) {
1321
+ return slate.Text.isText(node) || Contentful.LIST_ITEM_BLOCKS.concat(Object.values(Contentful.INLINES)).includes(node.type);
1322
+ };
1323
+
1324
+ var replaceInvalidListItemWithText = function replaceInvalidListItemWithText(editor, path) {
1325
+ var textFromEntry = extractParagraphsAt(editor, path);
1326
+ replaceNode(editor, path, textFromEntry);
1327
+ };
1328
+ /**
1329
+ * Ensures each list item follows the list schema.
1330
+ * Returns true if the list needed to have been normalized.
1331
+ */
1332
+
1333
+
1334
+ var normalizeList = function normalizeList(editor, path) {
1335
+ for (var _iterator = _createForOfIteratorHelperLoose(slate.Node.children(editor, path)), _step; !(_step = _iterator()).done;) {
1336
+ var _step$value = _step.value,
1337
+ child = _step$value[0],
1338
+ childPath = _step$value[1];
1339
+
1340
+ if (slate.Element.isElement(child) && !isListItem(child)) {
1341
+ slate.Transforms.wrapNodes(editor, emptyNodeOfType(Contentful.BLOCKS.LIST_ITEM), {
1342
+ at: childPath
1343
+ });
1344
+ return true;
1345
+ }
1346
+ }
1347
+
1348
+ return false;
1349
+ };
1350
+
1351
+ var getNearestListAncestor = function getNearestListAncestor(editor, path) {
1352
+ return plate.getAbove(editor, {
1353
+ at: path,
1354
+ mode: 'lowest',
1355
+ match: isList
1356
+ }) || [];
1357
+ };
1358
+ /**
1359
+ * Places orphaned list items in a list. If there's a list somewhere
1360
+ * in the node's ancestors, defaults to that list type, else places
1361
+ * the list item in an unordered list.
1362
+ */
1363
+
1364
+
1365
+ var normalizeOrphanedListItem = function normalizeOrphanedListItem(editor, path) {
1366
+ var _getNearestListAncest = getNearestListAncestor(editor, path),
1367
+ parentList = _getNearestListAncest[0];
1368
+
1369
+ var parentListType = parentList == null ? void 0 : parentList.type;
1370
+ slate.Transforms.wrapNodes(editor, {
1371
+ type: parentListType || Contentful.BLOCKS.UL_LIST,
1372
+ children: [],
1373
+ data: {}
1374
+ }, {
1375
+ at: path
1376
+ });
1377
+ };
1378
+
1291
1379
  var withCustomList = function withCustomList(options) {
1292
- var withDefaultOverrides = plateList.withList(options);
1380
+ var withDefaultOverrides = plate.withList(options);
1293
1381
  return function (editor) {
1294
1382
  var insertFragment = editor.insertFragment;
1295
1383
  withDefaultOverrides(editor); // Reverts any overrides to insertFragment
@@ -1297,6 +1385,52 @@ var withCustomList = function withCustomList(options) {
1297
1385
  editor.insertFragment = insertFragment; // Use our custom getListInsertFragment
1298
1386
 
1299
1387
  editor.insertFragment = getListInsertFragment(editor);
1388
+ var normalizeNode = editor.normalizeNode;
1389
+
1390
+ editor.normalizeNode = function (entry) {
1391
+ var node = entry[0],
1392
+ path = entry[1];
1393
+
1394
+ if (isList(node)) {
1395
+ if (normalizeList(editor, path)) {
1396
+ return;
1397
+ }
1398
+ } else if (isListItem(node)) {
1399
+ if (!hasListAsDirectParent(editor, path)) {
1400
+ normalizeOrphanedListItem(editor, path);
1401
+ return;
1402
+ }
1403
+
1404
+ var listItemChildren = Array.from(slate.Node.children(editor, path)); // Handle list items with no paragraph/text
1405
+
1406
+ if (listItemChildren.length === 0) {
1407
+ slate.Transforms.insertNodes(editor, [{
1408
+ type: Contentful.BLOCKS.PARAGRAPH,
1409
+ data: {},
1410
+ children: [{
1411
+ text: ''
1412
+ }]
1413
+ }], {
1414
+ at: path.concat([0])
1415
+ });
1416
+ return;
1417
+ }
1418
+
1419
+ for (var _i = 0, _listItemChildren = listItemChildren; _i < _listItemChildren.length; _i++) {
1420
+ var _listItemChildren$_i = _listItemChildren[_i],
1421
+ child = _listItemChildren$_i[0],
1422
+ childPath = _listItemChildren$_i[1];
1423
+
1424
+ if (slate.Element.isElement(child) && !isValidInsideListItem(child)) {
1425
+ replaceInvalidListItemWithText(editor, childPath);
1426
+ return;
1427
+ }
1428
+ }
1429
+ }
1430
+
1431
+ normalizeNode(entry);
1432
+ };
1433
+
1300
1434
  return editor;
1301
1435
  };
1302
1436
  };
@@ -1305,7 +1439,7 @@ var createListPlugin = function createListPlugin() {
1305
1439
  var options = {
1306
1440
  validLiChildrenTypes: Contentful.LIST_ITEM_BLOCKS
1307
1441
  };
1308
- var plugin = plateList.createListPlugin(options);
1442
+ var plugin = plate.createListPlugin(options);
1309
1443
  plugin.withOverrides = withCustomList(options);
1310
1444
  return plugin;
1311
1445
  };
@@ -1316,7 +1450,7 @@ function ToolbarBoldButton(props) {
1316
1450
 
1317
1451
  function handleClick() {
1318
1452
  if (!(editor != null && editor.selection)) return;
1319
- plateCommon.toggleMark(editor, Contentful.MARKS.BOLD);
1453
+ plate.toggleMark(editor, Contentful.MARKS.BOLD);
1320
1454
  Slate.ReactEditor.focus(editor);
1321
1455
  }
1322
1456
 
@@ -1325,7 +1459,7 @@ function ToolbarBoldButton(props) {
1325
1459
  title: "Bold",
1326
1460
  testId: "bold-toolbar-button",
1327
1461
  onClick: handleClick,
1328
- isActive: plateCommon.isMarkActive(editor, Contentful.MARKS.BOLD),
1462
+ isActive: plate.isMarkActive(editor, Contentful.MARKS.BOLD),
1329
1463
  isDisabled: props.isDisabled
1330
1464
  }, /*#__PURE__*/React.createElement(f36Icons.FormatBoldIcon, null));
1331
1465
  }
@@ -1342,8 +1476,8 @@ function Bold(props) {
1342
1476
  function createBoldPlugin() {
1343
1477
  return {
1344
1478
  pluginKeys: Contentful.MARKS.BOLD,
1345
- renderLeaf: plateCore.getRenderLeaf(Contentful.MARKS.BOLD),
1346
- onKeyDown: plateCommon.getToggleMarkOnKeyDown(Contentful.MARKS.BOLD),
1479
+ renderLeaf: plate.getRenderLeaf(Contentful.MARKS.BOLD),
1480
+ onKeyDown: plate.getToggleMarkOnKeyDown(Contentful.MARKS.BOLD),
1347
1481
  deserialize: function deserialize() {
1348
1482
  return {
1349
1483
  leaf: [{
@@ -1374,7 +1508,7 @@ function ToolbarCodeButton(props) {
1374
1508
 
1375
1509
  function handleClick() {
1376
1510
  if (!(editor != null && editor.selection)) return;
1377
- plateCommon.toggleMark(editor, Contentful.MARKS.CODE);
1511
+ plate.toggleMark(editor, Contentful.MARKS.CODE);
1378
1512
  Slate.ReactEditor.focus(editor);
1379
1513
  }
1380
1514
 
@@ -1383,7 +1517,7 @@ function ToolbarCodeButton(props) {
1383
1517
  title: "Code",
1384
1518
  testId: "code-toolbar-button",
1385
1519
  onClick: handleClick,
1386
- isActive: plateCommon.isMarkActive(editor, Contentful.MARKS.CODE),
1520
+ isActive: plate.isMarkActive(editor, Contentful.MARKS.CODE),
1387
1521
  isDisabled: props.isDisabled
1388
1522
  }, /*#__PURE__*/React.createElement(f36Icons.CodeIcon, null));
1389
1523
  }
@@ -1408,8 +1542,8 @@ function createCodePlugin() {
1408
1542
  }];
1409
1543
  return {
1410
1544
  pluginKeys: Contentful.MARKS.CODE,
1411
- renderLeaf: plateCore.getRenderLeaf(Contentful.MARKS.CODE),
1412
- onKeyDown: plateCommon.getToggleMarkOnKeyDown(Contentful.MARKS.CODE),
1545
+ renderLeaf: plate.getRenderLeaf(Contentful.MARKS.CODE),
1546
+ onKeyDown: plate.getToggleMarkOnKeyDown(Contentful.MARKS.CODE),
1413
1547
  deserialize: deserializeLeaf(Contentful.MARKS.CODE, deserializeRule)
1414
1548
  };
1415
1549
  }
@@ -1425,7 +1559,7 @@ function ToolbarItalicButton(props) {
1425
1559
 
1426
1560
  function handleClick() {
1427
1561
  if (!(editor != null && editor.selection)) return;
1428
- plateCommon.toggleMark(editor, Contentful.MARKS.ITALIC);
1562
+ plate.toggleMark(editor, Contentful.MARKS.ITALIC);
1429
1563
  Slate.ReactEditor.focus(editor);
1430
1564
  }
1431
1565
 
@@ -1434,7 +1568,7 @@ function ToolbarItalicButton(props) {
1434
1568
  title: "Italic",
1435
1569
  testId: "italic-toolbar-button",
1436
1570
  onClick: handleClick,
1437
- isActive: plateCommon.isMarkActive(editor, Contentful.MARKS.ITALIC),
1571
+ isActive: plate.isMarkActive(editor, Contentful.MARKS.ITALIC),
1438
1572
  isDisabled: props.isDisabled
1439
1573
  }, /*#__PURE__*/React.createElement(f36Icons.FormatItalicIcon, null));
1440
1574
  }
@@ -1458,8 +1592,8 @@ function createItalicPlugin() {
1458
1592
  }];
1459
1593
  return {
1460
1594
  pluginKeys: Contentful.MARKS.ITALIC,
1461
- renderLeaf: plateCore.getRenderLeaf(Contentful.MARKS.ITALIC),
1462
- onKeyDown: plateCommon.getToggleMarkOnKeyDown(Contentful.MARKS.ITALIC),
1595
+ renderLeaf: plate.getRenderLeaf(Contentful.MARKS.ITALIC),
1596
+ onKeyDown: plate.getToggleMarkOnKeyDown(Contentful.MARKS.ITALIC),
1463
1597
  deserialize: deserializeLeaf(Contentful.MARKS.ITALIC, deserializeRules)
1464
1598
  };
1465
1599
  }
@@ -1475,7 +1609,7 @@ function ToolbarUnderlineButton(props) {
1475
1609
 
1476
1610
  function handleClick() {
1477
1611
  if (!(editor != null && editor.selection)) return;
1478
- plateCommon.toggleMark(editor, Contentful.MARKS.UNDERLINE);
1612
+ plate.toggleMark(editor, Contentful.MARKS.UNDERLINE);
1479
1613
  Slate.ReactEditor.focus(editor);
1480
1614
  }
1481
1615
 
@@ -1484,7 +1618,7 @@ function ToolbarUnderlineButton(props) {
1484
1618
  title: "Underline",
1485
1619
  testId: "underline-toolbar-button",
1486
1620
  onClick: handleClick,
1487
- isActive: plateCommon.isMarkActive(editor, Contentful.MARKS.UNDERLINE),
1621
+ isActive: plate.isMarkActive(editor, Contentful.MARKS.UNDERLINE),
1488
1622
  isDisabled: props.isDisabled
1489
1623
  }, /*#__PURE__*/React.createElement(f36Icons.FormatUnderlinedIcon, null));
1490
1624
  }
@@ -1501,8 +1635,8 @@ function createUnderlinePlugin() {
1501
1635
  }];
1502
1636
  return {
1503
1637
  pluginKeys: Contentful.MARKS.UNDERLINE,
1504
- renderLeaf: plateCore.getRenderLeaf(Contentful.MARKS.UNDERLINE),
1505
- onKeyDown: plateCommon.getToggleMarkOnKeyDown(Contentful.MARKS.UNDERLINE),
1638
+ renderLeaf: plate.getRenderLeaf(Contentful.MARKS.UNDERLINE),
1639
+ onKeyDown: plate.getToggleMarkOnKeyDown(Contentful.MARKS.UNDERLINE),
1506
1640
  deserialize: deserializeLeaf(Contentful.MARKS.UNDERLINE, deserializeRules)
1507
1641
  };
1508
1642
  }
@@ -2897,7 +3031,7 @@ function HyperlinkModal(props) {
2897
3031
 
2898
3032
  return /*#__PURE__*/React.createElement(fieldEditorReference.EntityProvider, {
2899
3033
  sdk: props.sdk
2900
- }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(f36Components.ModalContent, null, /*#__PURE__*/React.createElement(f36Components.Form, null, /*#__PURE__*/React.createElement(f36Components.FormControl, {
3034
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(f36Components.ModalContent, null, /*#__PURE__*/React.createElement(f36Components.Form, null, !props.linkType && /*#__PURE__*/React.createElement(f36Components.FormControl, {
2901
3035
  id: "link-text",
2902
3036
  isRequired: true
2903
3037
  }, /*#__PURE__*/React.createElement(f36Components.FormControl.Label, null, "Link text"), /*#__PURE__*/React.createElement(f36Components.TextInput, {
@@ -3096,14 +3230,14 @@ var styles$d = {
3096
3230
  };
3097
3231
  function createHyperlinkPlugin(sdk) {
3098
3232
  return {
3099
- renderElement: plateCore.getRenderElement(LINK_TYPES),
3233
+ renderElement: plate.getRenderElement(LINK_TYPES),
3100
3234
  pluginKeys: LINK_TYPES,
3101
- inlineTypes: plateCore.getPlatePluginTypes(LINK_TYPES),
3235
+ inlineTypes: plate.getPlatePluginTypes(LINK_TYPES),
3102
3236
  onKeyDown: buildHyperlinkEventHandler(sdk),
3103
3237
  deserialize: function deserialize(editor) {
3104
- var hyperlinkOptions = plateCore.getPlatePluginOptions(editor, Contentful.INLINES.HYPERLINK);
3105
- var entryHyperlinkOptions = plateCore.getPlatePluginOptions(editor, Contentful.INLINES.ENTRY_HYPERLINK);
3106
- var assetHyperlinkOptions = plateCore.getPlatePluginOptions(editor, Contentful.INLINES.ASSET_HYPERLINK);
3238
+ var hyperlinkOptions = plate.getPlatePluginOptions(editor, Contentful.INLINES.HYPERLINK);
3239
+ var entryHyperlinkOptions = plate.getPlatePluginOptions(editor, Contentful.INLINES.ENTRY_HYPERLINK);
3240
+ var assetHyperlinkOptions = plate.getPlatePluginOptions(editor, Contentful.INLINES.ASSET_HYPERLINK);
3107
3241
 
3108
3242
  var isAnchor = function isAnchor(element) {
3109
3243
  return element.nodeName === 'A' && !!element.getAttribute('href') && element.getAttribute('href') !== '#';
@@ -3389,19 +3523,20 @@ function moveToFirstCellFromSelectedTable(editor) {
3389
3523
  function insertTableAndFocusFirstCell(editor) {
3390
3524
  // FIXME: a table should only be allowed at root level. Currently this
3391
3525
  // code adds it at any level
3392
- plateTable.insertTable(editor, {
3526
+ plate.insertTable(editor, {
3393
3527
  header: true
3394
3528
  });
3395
3529
  moveToFirstCellFromSelectedTable(editor);
3530
+ replaceEmptyParagraphWithTable(editor);
3396
3531
  }
3397
3532
  function isTableActive(editor) {
3398
- var tableElements = [plateTable.ELEMENT_TABLE, plateTable.ELEMENT_TH, plateTable.ELEMENT_TR, plateTable.ELEMENT_TD];
3533
+ var tableElements = [plate.ELEMENT_TABLE, plate.ELEMENT_TH, plate.ELEMENT_TR, plate.ELEMENT_TD];
3399
3534
  return tableElements.some(function (el) {
3400
3535
  return isBlockSelected(editor, el);
3401
3536
  });
3402
3537
  }
3403
3538
  function isTableHeaderEnabled(editor) {
3404
- var tableItem = plateCommon.getAbove(editor, {
3539
+ var tableItem = plate.getAbove(editor, {
3405
3540
  match: {
3406
3541
  type: Contentful.BLOCKS.TABLE
3407
3542
  }
@@ -3411,17 +3546,47 @@ function isTableHeaderEnabled(editor) {
3411
3546
  return false;
3412
3547
  }
3413
3548
 
3414
- var firstRow = plateCommon.getChildren(tableItem)[0];
3549
+ var firstRow = plate.getChildren(tableItem)[0];
3415
3550
 
3416
3551
  if (!firstRow) {
3417
3552
  return false;
3418
3553
  }
3419
3554
 
3420
- return plateCommon.getChildren(firstRow).every(function (_ref) {
3555
+ return plate.getChildren(firstRow).every(function (_ref) {
3421
3556
  var node = _ref[0];
3422
3557
  return node.type === Contentful.BLOCKS.TABLE_HEADER_CELL;
3423
3558
  });
3424
3559
  }
3560
+ function replaceEmptyParagraphWithTable(editor) {
3561
+ var tablePath = getAncestorPathFromSelection(editor);
3562
+ if (!tablePath || plate.isFirstChild(tablePath)) return;
3563
+ var previousPath = slate.Path.previous(tablePath);
3564
+ if (!previousPath) return;
3565
+
3566
+ var _Editor$nodes = slate.Editor.nodes(editor, {
3567
+ at: previousPath,
3568
+ match: function match(node) {
3569
+ return node.type === Contentful.BLOCKS.PARAGRAPH;
3570
+ }
3571
+ }),
3572
+ nodes = _Editor$nodes[0];
3573
+
3574
+ if (!nodes) return;
3575
+ var previousNode = nodes[0];
3576
+ var isPreviousNodeTextEmpty = plate.isAncestorEmpty(editor, previousNode);
3577
+
3578
+ if (isPreviousNodeTextEmpty) {
3579
+ // Switch table with previous empty paragraph
3580
+ slate.Transforms.moveNodes(editor, {
3581
+ at: tablePath,
3582
+ to: previousPath
3583
+ }); // Remove previous paragraph that now is under the table
3584
+
3585
+ slate.Transforms.removeNodes(editor, {
3586
+ at: tablePath
3587
+ });
3588
+ }
3589
+ }
3425
3590
 
3426
3591
  function useTracking(_ref) {
3427
3592
  var onAction = _ref.onAction;
@@ -3447,14 +3612,14 @@ var _constate$2 = /*#__PURE__*/constate(useTracking),
3447
3612
  useTrackingContext = _constate$2[1];
3448
3613
 
3449
3614
  var addRow = function addRow(editor, getNextRowPath) {
3450
- if (plateCommon.someNode(editor, {
3615
+ if (plate.someNode(editor, {
3451
3616
  match: {
3452
- type: plateCore.getPlatePluginType(editor, plateTable.ELEMENT_TABLE)
3617
+ type: plate.getPlatePluginType(editor, plate.ELEMENT_TABLE)
3453
3618
  }
3454
3619
  })) {
3455
- var currentRowItem = plateCommon.getAbove(editor, {
3620
+ var currentRowItem = plate.getAbove(editor, {
3456
3621
  match: {
3457
- type: plateCore.getPlatePluginType(editor, plateTable.ELEMENT_TR)
3622
+ type: plate.getPlatePluginType(editor, plate.ELEMENT_TR)
3458
3623
  }
3459
3624
  });
3460
3625
 
@@ -3462,8 +3627,8 @@ var addRow = function addRow(editor, getNextRowPath) {
3462
3627
  var currentRowElem = currentRowItem[0],
3463
3628
  currentRowPath = currentRowItem[1];
3464
3629
  var nextRowPath = getNextRowPath(currentRowPath);
3465
- plateCommon.insertNodes(editor, // @ts-expect-error
3466
- plateTable.getEmptyRowNode(editor, {
3630
+ plate.insertNodes(editor, // @ts-expect-error
3631
+ plate.getEmptyRowNode(editor, {
3467
3632
  header: false,
3468
3633
  colCount: currentRowElem.children.length
3469
3634
  }), {
@@ -3492,19 +3657,19 @@ var addRowAbove = function addRowAbove(editor) {
3492
3657
  var addColumn = function addColumn(editor, _ref, getNextCellPath) {
3493
3658
  var header = _ref.header;
3494
3659
 
3495
- if (plateCommon.someNode(editor, {
3660
+ if (plate.someNode(editor, {
3496
3661
  match: {
3497
- type: plateCore.getPlatePluginType(editor, plateTable.ELEMENT_TABLE)
3662
+ type: plate.getPlatePluginType(editor, plate.ELEMENT_TABLE)
3498
3663
  }
3499
3664
  })) {
3500
- var currentCellItem = plateCommon.getAbove(editor, {
3665
+ var currentCellItem = plate.getAbove(editor, {
3501
3666
  match: {
3502
- type: [plateCore.getPlatePluginType(editor, plateTable.ELEMENT_TD), plateCore.getPlatePluginType(editor, plateTable.ELEMENT_TH)]
3667
+ type: [plate.getPlatePluginType(editor, plate.ELEMENT_TD), plate.getPlatePluginType(editor, plate.ELEMENT_TH)]
3503
3668
  }
3504
3669
  });
3505
- var currentTableItem = plateCommon.getAbove(editor, {
3670
+ var currentTableItem = plate.getAbove(editor, {
3506
3671
  match: {
3507
- type: plateCore.getPlatePluginType(editor, plateTable.ELEMENT_TABLE)
3672
+ type: plate.getPlatePluginType(editor, plate.ELEMENT_TABLE)
3508
3673
  }
3509
3674
  });
3510
3675
 
@@ -3514,8 +3679,8 @@ var addColumn = function addColumn(editor, _ref, getNextCellPath) {
3514
3679
  var replacePathPos = newCellPath.length - 2;
3515
3680
  currentTableItem[0].children.forEach(function (_, rowIdx) {
3516
3681
  newCellPath[replacePathPos] = rowIdx;
3517
- plateCommon.insertNodes(editor, // @ts-expect-error
3518
- plateTable.getEmptyCellNode(editor, {
3682
+ plate.insertNodes(editor, // @ts-expect-error
3683
+ plate.getEmptyCellNode(editor, {
3519
3684
  header: header && rowIdx === 0
3520
3685
  }), {
3521
3686
  at: newCellPath,
@@ -3539,7 +3704,7 @@ var addColumnLeft = function addColumnLeft(editor, options) {
3539
3704
  };
3540
3705
 
3541
3706
  var setHeader = function setHeader(editor, enable) {
3542
- var tableItem = plateCommon.getAbove(editor, {
3707
+ var tableItem = plate.getAbove(editor, {
3543
3708
  match: {
3544
3709
  type: Contentful.BLOCKS.TABLE
3545
3710
  }
@@ -3549,15 +3714,15 @@ var setHeader = function setHeader(editor, enable) {
3549
3714
  return;
3550
3715
  }
3551
3716
 
3552
- var firstRow = plateCommon.getChildren(tableItem)[0];
3717
+ var firstRow = plate.getChildren(tableItem)[0];
3553
3718
 
3554
3719
  if (!firstRow) {
3555
3720
  return;
3556
3721
  }
3557
3722
 
3558
- plateCommon.getChildren(firstRow).forEach(function (_ref) {
3723
+ plate.getChildren(firstRow).forEach(function (_ref) {
3559
3724
  var path = _ref[1];
3560
- plateCommon.setNodes(editor, {
3725
+ plate.setNodes(editor, {
3561
3726
  type: enable ? Contentful.BLOCKS.TABLE_HEADER_CELL : Contentful.BLOCKS.TABLE_CELL
3562
3727
  }, {
3563
3728
  at: path
@@ -3609,7 +3774,7 @@ var TableActions = function TableActions() {
3609
3774
  return false;
3610
3775
  }
3611
3776
 
3612
- var headerCell = plateCommon.getAbove(editor, {
3777
+ var headerCell = plate.getAbove(editor, {
3613
3778
  match: {
3614
3779
  type: Contentful.BLOCKS.TABLE_HEADER_CELL
3615
3780
  }
@@ -3669,25 +3834,125 @@ var TableActions = function TableActions() {
3669
3834
  }, "Add column right"), /*#__PURE__*/React__default.createElement(f36Components.Menu.Divider, null), /*#__PURE__*/React__default.createElement(f36Components.Menu.Item, {
3670
3835
  onClick: toggleHeader
3671
3836
  }, isHeaderEnabled ? 'Disable table header' : 'Enable table header'), /*#__PURE__*/React__default.createElement(f36Components.Menu.Divider, null), /*#__PURE__*/React__default.createElement(f36Components.Menu.Item, {
3672
- onClick: action(plateTable.deleteRow, 'remove', 'Row')
3837
+ onClick: action(plate.deleteRow, 'remove', 'Row')
3673
3838
  }, "Delete row"), /*#__PURE__*/React__default.createElement(f36Components.Menu.Item, {
3674
- onClick: action(plateTable.deleteColumn, 'remove', 'Column')
3839
+ onClick: action(plate.deleteColumn, 'remove', 'Column')
3675
3840
  }, "Delete column"), /*#__PURE__*/React__default.createElement(f36Components.Menu.Item, {
3676
- onClick: action(plateTable.deleteTable, 'remove', 'Table')
3841
+ onClick: action(plate.deleteTable, 'remove', 'Table')
3677
3842
  }, "Delete table")));
3678
3843
  };
3679
3844
 
3680
- var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
3681
- var styles$f = (_styles$1 = {}, _styles$1[Contentful.BLOCKS.TABLE] = /*#__PURE__*/emotion.css(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 1.5em;\n border-collapse: collapse;\n border-radius: 5px;\n border-style: hidden;\n box-shadow: 0 0 0 1px ", ";\n width: 100%;\n table-layout: fixed;\n overflow: hidden;\n "])), tokens.gray400), _styles$1[Contentful.BLOCKS.TABLE_ROW] = /*#__PURE__*/emotion.css(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n &:hover td {\n background-color: transparent !important;\n }\n "])), tokens.gray400), _styles$1[Contentful.BLOCKS.TABLE_HEADER_CELL] = /*#__PURE__*/emotion.css(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: ", ";\n border: 1px solid ", ";\n padding: 10px 12px;\n font-weight: ", ";\n text-align: left;\n min-width: 48px;\n position: relative;\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray200, tokens.gray400, tokens.fontWeightMedium), _styles$1[Contentful.BLOCKS.TABLE_CELL] = /*#__PURE__*/emotion.css(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n padding: 10px 12px;\n min-width: 48px;\n position: relative;\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray400), _styles$1);
3845
+ /**
3846
+ * Injects a custom element normalization handler.
3847
+ *
3848
+ * Handlers must explicity return "true" to indicate a pass.
3849
+ * A pass is when a handler didn't encounter any normalization
3850
+ * paths (i.e. all nodes were valid)
3851
+ *
3852
+ * Important read:
3853
+ * https://docs.slatejs.org/concepts/11-normalizing#multi-pass-normalizing
3854
+ */
3682
3855
 
3683
- var slateNodeToText = function slateNodeToText(node) {
3684
- var contentfulNode = contentfulSlatejsAdapter.toContentfulDocument({
3685
- document: [node],
3686
- schema: schema
3687
- });
3688
- return richTextPlainTextRenderer.documentToPlainTextString(contentfulNode);
3856
+ var withNormalizer = function withNormalizer(editor, handler) {
3857
+ var normalizeNode = editor.normalizeNode;
3858
+
3859
+ editor.normalizeNode = function (entry) {
3860
+ var node = entry[0];
3861
+ var passed = false;
3862
+
3863
+ if (slate.Element.isElement(node)) {
3864
+ passed = handler(editor, entry) === true;
3865
+ }
3866
+
3867
+ if (passed) {
3868
+ normalizeNode(entry);
3869
+ }
3870
+ };
3689
3871
  };
3690
3872
 
3873
+ var isTable = function isTable(node) {
3874
+ return node.type === Contentful.BLOCKS.TABLE;
3875
+ };
3876
+
3877
+ var isTableCell = function isTableCell(node) {
3878
+ return node.type === Contentful.BLOCKS.TABLE_CELL || node.type === Contentful.BLOCKS.TABLE_HEADER_CELL;
3879
+ };
3880
+ /**
3881
+ * Normalizes TABLE_CELL & TABLE_HEADER_CELL nodes
3882
+ */
3883
+
3884
+
3885
+ var normalizeTableCell = function normalizeTableCell(editor, entry) {
3886
+ var node = entry[0],
3887
+ path = entry[1];
3888
+
3889
+ if (!isTableCell(node)) {
3890
+ return true;
3891
+ }
3892
+
3893
+ for (var _iterator = _createForOfIteratorHelperLoose(slate.Node.children(editor, path)), _step; !(_step = _iterator()).done;) {
3894
+ var _step$value = _step.value,
3895
+ child = _step$value[0],
3896
+ childPath = _step$value[1];
3897
+
3898
+ if (!slate.Element.isElement(child)) {
3899
+ continue;
3900
+ }
3901
+
3902
+ var isValidTableCellItem = Contentful.CONTAINERS[node.type].includes(child.type);
3903
+
3904
+ if (!isValidTableCellItem) {
3905
+ var text = extractParagraphsAt(editor, childPath);
3906
+ replaceNode(editor, childPath, text);
3907
+ return;
3908
+ }
3909
+ }
3910
+
3911
+ return true;
3912
+ };
3913
+ /**
3914
+ * Normalizes TABLE nodes
3915
+ */
3916
+
3917
+
3918
+ var normalizeTable = function normalizeTable(editor, entry) {
3919
+ var node = entry[0],
3920
+ path = entry[1];
3921
+
3922
+ if (!isTable(node)) {
3923
+ return true;
3924
+ } // All direct children must be of type TABLE_ROW
3925
+
3926
+
3927
+ for (var _iterator2 = _createForOfIteratorHelperLoose(slate.Node.children(editor, path)), _step2; !(_step2 = _iterator2()).done;) {
3928
+ var _step2$value = _step2.value,
3929
+ child = _step2$value[0],
3930
+ childPath = _step2$value[1];
3931
+
3932
+ if (!slate.Element.isElement(child)) {
3933
+ continue;
3934
+ }
3935
+
3936
+ var isValidTableChild = Contentful.CONTAINERS[Contentful.BLOCKS.TABLE].includes(child.type);
3937
+
3938
+ if (!isValidTableChild) {
3939
+ slate.Transforms.removeNodes(editor, {
3940
+ at: childPath
3941
+ });
3942
+ return;
3943
+ }
3944
+ }
3945
+
3946
+ return true;
3947
+ };
3948
+
3949
+ var addTableNormalizers = function addTableNormalizers(editor) {
3950
+ withNormalizer(editor, normalizeTable);
3951
+ withNormalizer(editor, normalizeTableCell);
3952
+ };
3953
+
3954
+ var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
3955
+ var styles$f = (_styles$1 = {}, _styles$1[Contentful.BLOCKS.TABLE] = /*#__PURE__*/emotion.css(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 1.5em;\n border-collapse: collapse;\n border-radius: 5px;\n border-style: hidden;\n box-shadow: 0 0 0 1px ", ";\n width: 100%;\n table-layout: fixed;\n overflow: hidden;\n "])), tokens.gray400), _styles$1[Contentful.BLOCKS.TABLE_ROW] = /*#__PURE__*/emotion.css(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n\n &:hover td {\n background-color: transparent !important;\n }\n "])), tokens.gray400), _styles$1[Contentful.BLOCKS.TABLE_HEADER_CELL] = /*#__PURE__*/emotion.css(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: ", ";\n border: 1px solid ", ";\n padding: 10px 12px;\n font-weight: ", ";\n text-align: left;\n min-width: 48px;\n position: relative;\n\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray200, tokens.gray400, tokens.fontWeightMedium), _styles$1[Contentful.BLOCKS.TABLE_CELL] = /*#__PURE__*/emotion.css(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n padding: 10px 12px;\n min-width: 48px;\n position: relative;\n\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray400), _styles$1);
3691
3956
  var Table = function Table(props) {
3692
3957
  return /*#__PURE__*/React.createElement("table", Object.assign({}, props.attributes, {
3693
3958
  className: styles$f[Contentful.BLOCKS.TABLE]
@@ -3710,16 +3975,16 @@ var TD = function TD(props) {
3710
3975
  className: styles$f[Contentful.BLOCKS.TABLE_CELL]
3711
3976
  }), isSelected && /*#__PURE__*/React.createElement(TableActions, null), props.children);
3712
3977
  };
3713
- var withTableOptions = (_withTableOptions = {}, _withTableOptions[plateTable.ELEMENT_TABLE] = {
3978
+ var withTableOptions = (_withTableOptions = {}, _withTableOptions[plate.ELEMENT_TABLE] = {
3714
3979
  type: Contentful.BLOCKS.TABLE,
3715
3980
  component: Table
3716
- }, _withTableOptions[plateTable.ELEMENT_TR] = {
3981
+ }, _withTableOptions[plate.ELEMENT_TR] = {
3717
3982
  type: Contentful.BLOCKS.TABLE_ROW,
3718
3983
  component: TR
3719
- }, _withTableOptions[plateTable.ELEMENT_TH] = {
3984
+ }, _withTableOptions[plate.ELEMENT_TH] = {
3720
3985
  type: Contentful.BLOCKS.TABLE_HEADER_CELL,
3721
3986
  component: TH
3722
- }, _withTableOptions[plateTable.ELEMENT_TD] = {
3987
+ }, _withTableOptions[plate.ELEMENT_TD] = {
3723
3988
  type: Contentful.BLOCKS.TABLE_CELL,
3724
3989
  component: TD
3725
3990
  }, _withTableOptions);
@@ -3751,56 +4016,6 @@ function addTableTrackingEvents(editor, _ref) {
3751
4016
  };
3752
4017
  }
3753
4018
 
3754
- var paragraph = function paragraph() {
3755
- return {
3756
- type: Contentful.BLOCKS.PARAGRAPH,
3757
- data: {},
3758
- children: []
3759
- };
3760
- };
3761
-
3762
- function addTableNormalization(editor) {
3763
- var normalizeNode = editor.normalizeNode;
3764
-
3765
- editor.normalizeNode = function (entry) {
3766
- var node = entry[0],
3767
- path = entry[1]; // TODO: This should be enforced by sanitizeSlateDoc() but the internal
3768
- // editor value can be different.
3769
- // cf. https://github.com/ianstormtaylor/slate/issues/2206
3770
-
3771
- var cellTypes = [Contentful.BLOCKS.TABLE_CELL, Contentful.BLOCKS.TABLE_HEADER_CELL];
3772
-
3773
- if (slate.Element.isElement(node) && cellTypes.includes(node.type)) {
3774
- for (var _iterator = _createForOfIteratorHelperLoose(slate.Node.children(editor, path)), _step; !(_step = _iterator()).done;) {
3775
- var _step$value = _step.value,
3776
- child = _step$value[0],
3777
- childPath = _step$value[1];
3778
-
3779
- if (slate.Text.isText(child)) {
3780
- slate.Transforms.wrapNodes(editor, paragraph(), {
3781
- at: childPath
3782
- });
3783
- } else if (!Contentful.CONTAINERS[node.type].includes(child.type)) {
3784
- var paragraphWithTextFromNode = _extends({}, paragraph(), {
3785
- children: [{
3786
- text: slateNodeToText(child)
3787
- }]
3788
- });
3789
-
3790
- slate.Transforms.removeNodes(editor, {
3791
- at: childPath
3792
- });
3793
- slate.Transforms.insertNodes(editor, paragraphWithTextFromNode, {
3794
- at: childPath
3795
- });
3796
- }
3797
- }
3798
- }
3799
-
3800
- normalizeNode(entry);
3801
- };
3802
- }
3803
-
3804
4019
  function hasTables(nodes) {
3805
4020
  return nodes.some(function (_ref2) {
3806
4021
  var type = _ref2.type;
@@ -3826,11 +4041,9 @@ function hasHeadersOutsideFirstRow(nodes) {
3826
4041
  });
3827
4042
  }
3828
4043
 
3829
- function createWithTableEvents(tracking) {
4044
+ function createTableOnKeyDown() {
3830
4045
  return function withTableEvents(editor) {
3831
- addTableTrackingEvents(editor, tracking);
3832
- addTableNormalization(editor);
3833
- var handleKeyDownFromPlateUdecode = plateTable.getTableOnKeyDown()(editor);
4046
+ var handleKeyDownFromPlateUdecode = plate.getTableOnKeyDown()(editor);
3834
4047
  return function handleKeyDown(event) {
3835
4048
  if (event.key === 'Backspace' && currentSelectionStartsTableCell(editor) || event.key === 'Delete' && currentSelectionPrecedesTableCell(editor)) {
3836
4049
  // The default behavior here would be to delete the preceding or forthcoming
@@ -3847,9 +4060,11 @@ function createWithTableEvents(tracking) {
3847
4060
  }
3848
4061
 
3849
4062
  var createTablePlugin = function createTablePlugin(tracking) {
3850
- return _extends({}, plateTable.createTablePlugin(), {
3851
- onKeyDown: createWithTableEvents(tracking),
4063
+ return _extends({}, plate.createTablePlugin(), {
4064
+ onKeyDown: createTableOnKeyDown(),
3852
4065
  withOverrides: function withOverrides(editor) {
4066
+ addTableTrackingEvents(editor, tracking);
4067
+ addTableNormalizers(editor);
3853
4068
  var insertFragment = editor.insertFragment;
3854
4069
 
3855
4070
  editor.insertFragment = function (fragments) {
@@ -4149,7 +4364,7 @@ var createNode = function createNode(nodeType, entity) {
4149
4364
  function insertBlock(editor, nodeType, entity) {
4150
4365
  if (!(editor != null && editor.selection)) return;
4151
4366
  var linkedEntityBlock = createNode(nodeType, entity);
4152
- var hasText = editor.selection && !!plateCommon.getText(editor, editor.selection.focus.path);
4367
+ var hasText = editor.selection && !!plate.getText(editor, editor.selection.focus.path);
4153
4368
 
4154
4369
  if (hasText) {
4155
4370
  slate.Transforms.insertNodes(editor, linkedEntityBlock);
@@ -4224,14 +4439,14 @@ var _withEmbeddedEntryBlo, _withEmbeddedAssetBlo;
4224
4439
  var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType) {
4225
4440
  return function (sdk) {
4226
4441
  return {
4227
- renderElement: plateCore.getRenderElement(nodeType),
4442
+ renderElement: plate.getRenderElement(nodeType),
4228
4443
  pluginKeys: nodeType,
4229
4444
  onKeyDown: getWithEmbeddedEntityEvents(nodeType, sdk),
4230
- voidTypes: plateCore.getPlatePluginTypes(nodeType),
4445
+ voidTypes: plate.getPlatePluginTypes(nodeType),
4231
4446
  deserialize: function deserialize(editor) {
4232
4447
  var _entityTypes;
4233
4448
 
4234
- var options = plateCore.getPlatePluginOptions(editor, nodeType);
4449
+ var options = plate.getPlatePluginOptions(editor, nodeType);
4235
4450
  var entityTypes = (_entityTypes = {}, _entityTypes[Contentful.BLOCKS.EMBEDDED_ENTRY] = 'Entry', _entityTypes[Contentful.BLOCKS.EMBEDDED_ASSET] = 'Asset', _entityTypes);
4236
4451
  return {
4237
4452
  element: [_extends({
@@ -4302,16 +4517,15 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
4302
4517
  // TODO: Dry up copied code from HR
4303
4518
  return function handleEvent(event) {
4304
4519
  if (!editor) return;
4305
- var isEnter = event.keyCode === 13;
4306
4520
 
4307
4521
  var _getNodeEntryFromSele = getNodeEntryFromSelection(editor, nodeType),
4308
4522
  pathToSelectedElement = _getNodeEntryFromSele[1];
4309
4523
 
4310
4524
  if (pathToSelectedElement) {
4311
- if (isEnter) {
4312
- event.preventDefault();
4313
- moveToTheNextLine(editor);
4314
- } else if (event.key === 'Backspace') {
4525
+ var isDelete = event.key === 'Delete';
4526
+ var isBackspace = event.key === 'Backspace';
4527
+
4528
+ if (isDelete || isBackspace) {
4315
4529
  event.preventDefault();
4316
4530
  slate.Transforms.removeNodes(editor, {
4317
4531
  at: pathToSelectedElement
@@ -4603,13 +4817,13 @@ function ToolbarEmbeddedEntityInlineButton(props) {
4603
4817
  }
4604
4818
  function createEmbeddedEntityInlinePlugin(sdk) {
4605
4819
  return {
4606
- renderElement: plateCore.getRenderElement(Contentful.INLINES.EMBEDDED_ENTRY),
4820
+ renderElement: plate.getRenderElement(Contentful.INLINES.EMBEDDED_ENTRY),
4607
4821
  pluginKeys: Contentful.INLINES.EMBEDDED_ENTRY,
4608
- inlineTypes: plateCore.getPlatePluginTypes(Contentful.INLINES.EMBEDDED_ENTRY),
4609
- voidTypes: plateCore.getPlatePluginTypes(Contentful.INLINES.EMBEDDED_ENTRY),
4822
+ inlineTypes: plate.getPlatePluginTypes(Contentful.INLINES.EMBEDDED_ENTRY),
4823
+ voidTypes: plate.getPlatePluginTypes(Contentful.INLINES.EMBEDDED_ENTRY),
4610
4824
  onKeyDown: getWithEmbeddedEntryInlineEvents(sdk),
4611
4825
  deserialize: function deserialize(editor) {
4612
- var options = plateCore.getPlatePluginOptions(editor, Contentful.INLINES.EMBEDDED_ENTRY);
4826
+ var options = plate.getPlatePluginOptions(editor, Contentful.INLINES.EMBEDDED_ENTRY);
4613
4827
  return {
4614
4828
  element: [_extends({
4615
4829
  type: Contentful.INLINES.EMBEDDED_ENTRY,
@@ -4760,6 +4974,9 @@ var Toolbar = function Toolbar(_ref) {
4760
4974
  var validationInfo = React__default.useMemo(function () {
4761
4975
  return getValidationInfo(sdk.field);
4762
4976
  }, [sdk.field]);
4977
+ var isListSelected = isNodeTypeSelected(editor, Contentful.BLOCKS.UL_LIST) || isNodeTypeSelected(editor, Contentful.BLOCKS.OL_LIST);
4978
+ var isBlockquoteSelected = isNodeTypeSelected(editor, Contentful.BLOCKS.QUOTE);
4979
+ var shouldDisableTables = isDisabled || !canInsertBlocks || isListSelected || isBlockquoteSelected;
4763
4980
  return /*#__PURE__*/React__default.createElement(f36Components.Flex, {
4764
4981
  testId: "toolbar",
4765
4982
  className: styles$k.toolbar,
@@ -4791,7 +5008,7 @@ var Toolbar = function Toolbar(_ref) {
4791
5008
  }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.HR) && /*#__PURE__*/React__default.createElement(ToolbarHrButton, {
4792
5009
  isDisabled: isDisabled || !canInsertBlocks
4793
5010
  }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.TABLE) && /*#__PURE__*/React__default.createElement(ToolbarTableButton, {
4794
- isDisabled: isDisabled || !canInsertBlocks
5011
+ isDisabled: shouldDisableTables
4795
5012
  })), /*#__PURE__*/React__default.createElement("div", {
4796
5013
  className: styles$k.embedActionsWrapper
4797
5014
  }, /*#__PURE__*/React__default.createElement(EmbedEntityWidget, {
@@ -4830,6 +5047,99 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
4830
5047
  }, children);
4831
5048
  };
4832
5049
 
5050
+ var TEXT_PARENT_NODES = /*#__PURE__*/Contentful.VOID_BLOCKS.concat(values(Contentful.INLINES)).concat(Contentful.BLOCKS.PARAGRAPH, Contentful.BLOCKS.HEADING_1, Contentful.BLOCKS.HEADING_2, Contentful.BLOCKS.HEADING_3, Contentful.BLOCKS.HEADING_4, Contentful.BLOCKS.HEADING_5, Contentful.BLOCKS.HEADING_6);
5051
+
5052
+ var isTextElement = function isTextElement(node) {
5053
+ return 'text' in node;
5054
+ };
5055
+
5056
+ var wrapNode = function wrapNode(type, node) {
5057
+ return {
5058
+ type: type,
5059
+ data: {},
5060
+ children: [node]
5061
+ };
5062
+ };
5063
+
5064
+ function wrapOrphanedTextNode(parentNodeType, node) {
5065
+ var paragraph = wrapNode(Contentful.BLOCKS.PARAGRAPH, node);
5066
+
5067
+ switch (parentNodeType) {
5068
+ case Contentful.BLOCKS.OL_LIST:
5069
+ case Contentful.BLOCKS.UL_LIST:
5070
+ return wrapNode(Contentful.BLOCKS.LIST_ITEM, paragraph);
5071
+
5072
+ case Contentful.BLOCKS.TABLE_ROW:
5073
+ return wrapNode(Contentful.BLOCKS.TABLE_CELL, paragraph);
5074
+
5075
+ case Contentful.BLOCKS.TABLE:
5076
+ return wrapNode(Contentful.BLOCKS.TABLE_ROW, wrapNode(Contentful.BLOCKS.TABLE_CELL, paragraph));
5077
+
5078
+ default:
5079
+ return paragraph;
5080
+ }
5081
+ }
5082
+ /**
5083
+ * Ensures "orphaned" text node elements (those without a parent capable of
5084
+ * validly rendering a text child node) are wrapped with a suitable parent
5085
+ * element to prevent failures on the validation layer.
5086
+ *
5087
+ * It is commonplace for third party plugins (including udecode) to reconcile
5088
+ * deletion events by inserting such nodes into their schema. This
5089
+ * subprocedure is intended as a guard against such cases.
5090
+ */
5091
+
5092
+
5093
+ function sanitizeSlateDoc(nodes, parentNodeType) {
5094
+ if (nodes === void 0) {
5095
+ nodes = [];
5096
+ }
5097
+
5098
+ if (parentNodeType === void 0) {
5099
+ parentNodeType = Contentful.BLOCKS.DOCUMENT;
5100
+ }
5101
+
5102
+ return nodes.map(function (node) {
5103
+ if (isTextElement(node)) {
5104
+ return TEXT_PARENT_NODES.includes(parentNodeType) ? node : wrapOrphanedTextNode(parentNodeType, node);
5105
+ }
5106
+
5107
+ return _extends({}, node, {
5108
+ children: sanitizeSlateDoc(node.children, node.type)
5109
+ });
5110
+ });
5111
+ }
5112
+ /**
5113
+ * Ensures incoming void nodes have a child leaf text element.
5114
+ */
5115
+
5116
+ function sanitizeIncomingSlateDoc(nodes) {
5117
+ if (nodes === void 0) {
5118
+ nodes = [];
5119
+ }
5120
+
5121
+ return nodes.map(function (node) {
5122
+ var _node$children;
5123
+
5124
+ if (isTextElement(node)) {
5125
+ return node;
5126
+ }
5127
+
5128
+ if (node.isVoid && ((_node$children = node.children) == null ? void 0 : _node$children.length) === 0) {
5129
+ return _extends({}, node, {
5130
+ children: [{
5131
+ text: '',
5132
+ data: {}
5133
+ }]
5134
+ });
5135
+ }
5136
+
5137
+ return _extends({}, node, {
5138
+ children: sanitizeIncomingSlateDoc(node.children)
5139
+ });
5140
+ });
5141
+ }
5142
+
4833
5143
  var isHTMLElement = function isHTMLElement(node) {
4834
5144
  return node.nodeType === Node.ELEMENT_NODE;
4835
5145
  };
@@ -4980,28 +5290,25 @@ var htmlToDataTransfer = function htmlToDataTransfer(html) {
4980
5290
  return data;
4981
5291
  };
4982
5292
 
4983
- function withPasteHandling(editor) {
4984
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4985
- return function (_event) {
4986
- var insertData = editor.insertData;
5293
+ var createPastePlugin = function createPastePlugin() {
5294
+ return {
5295
+ withOverrides: function withOverrides(editor) {
5296
+ var insertData = editor.insertData;
4987
5297
 
4988
- editor.insertData = function (data) {
4989
- var html = data.getData(MIME_TYPE_HTML);
5298
+ editor.insertData = function (data) {
5299
+ var html = data.getData(MIME_TYPE_HTML);
4990
5300
 
4991
- if (html) {
4992
- var sanitized = sanitizeHtml(html, editor);
4993
- var newData = htmlToDataTransfer(sanitized);
4994
- insertData(newData);
4995
- } else {
4996
- insertData(data);
4997
- }
4998
- };
4999
- };
5000
- }
5301
+ if (html) {
5302
+ var sanitized = sanitizeHtml(html, editor);
5303
+ var newData = htmlToDataTransfer(sanitized);
5304
+ insertData(newData);
5305
+ } else {
5306
+ insertData(data);
5307
+ }
5308
+ };
5001
5309
 
5002
- var createPastePlugin = function createPastePlugin() {
5003
- return {
5004
- onKeyDown: withPasteHandling
5310
+ return editor;
5311
+ }
5005
5312
  };
5006
5313
  };
5007
5314
 
@@ -5024,14 +5331,14 @@ function isEmpty(element) {
5024
5331
  }
5025
5332
 
5026
5333
  function createParagraphPlugin() {
5027
- var elementKeys = [plateParagraph.ELEMENT_PARAGRAPH, Contentful.BLOCKS.PARAGRAPH];
5334
+ var elementKeys = [plate.ELEMENT_PARAGRAPH, Contentful.BLOCKS.PARAGRAPH];
5028
5335
  var deserializer = deserializeElement(Contentful.BLOCKS.PARAGRAPH, [{
5029
5336
  nodeNames: ['P', 'DIV']
5030
5337
  }]);
5031
5338
  return {
5032
- renderElement: plateCore.getRenderElement(elementKeys),
5339
+ renderElement: plate.getRenderElement(elementKeys),
5033
5340
  pluginKeys: elementKeys,
5034
- onKeyDown: plateCommon.getToggleElementOnKeyDown(Contentful.BLOCKS.PARAGRAPH),
5341
+ onKeyDown: plate.getToggleElementOnKeyDown(Contentful.BLOCKS.PARAGRAPH),
5035
5342
  deserialize: function deserialize(editor) {
5036
5343
  var _deserializer = deserializer(editor),
5037
5344
  element = _deserializer.element,
@@ -5081,7 +5388,7 @@ function createParagraphPlugin() {
5081
5388
  }
5082
5389
  };
5083
5390
  }
5084
- var withParagraphOptions = (_withParagraphOptions = {}, _withParagraphOptions[plateParagraph.ELEMENT_PARAGRAPH] = {
5391
+ var withParagraphOptions = (_withParagraphOptions = {}, _withParagraphOptions[plate.ELEMENT_PARAGRAPH] = {
5085
5392
  // We convert the default slate plugin `p` to Contentful `BLOCKS.PARAGRAPH`
5086
5393
  type: Contentful.BLOCKS.PARAGRAPH,
5087
5394
  component: Paragraph
@@ -5133,104 +5440,11 @@ function createInsertBeforeFirstVoidBlockPlugin() {
5133
5440
  }
5134
5441
  }]
5135
5442
  };
5136
- return plateBreak.createExitBreakPlugin(optionsExitBreakPlugin);
5137
- }
5138
-
5139
- var TEXT_PARENT_NODES = /*#__PURE__*/Contentful.VOID_BLOCKS.concat(values(Contentful.INLINES)).concat(Contentful.BLOCKS.PARAGRAPH, Contentful.BLOCKS.HEADING_1, Contentful.BLOCKS.HEADING_2, Contentful.BLOCKS.HEADING_3, Contentful.BLOCKS.HEADING_4, Contentful.BLOCKS.HEADING_5, Contentful.BLOCKS.HEADING_6);
5140
-
5141
- var isTextElement = function isTextElement(node) {
5142
- return 'text' in node;
5143
- };
5144
-
5145
- var wrapNode = function wrapNode(type, node) {
5146
- return {
5147
- type: type,
5148
- data: {},
5149
- children: [node]
5150
- };
5151
- };
5152
-
5153
- function wrapOrphanedTextNode(parentNodeType, node) {
5154
- var paragraph = wrapNode(Contentful.BLOCKS.PARAGRAPH, node);
5155
-
5156
- switch (parentNodeType) {
5157
- case Contentful.BLOCKS.OL_LIST:
5158
- case Contentful.BLOCKS.UL_LIST:
5159
- return wrapNode(Contentful.BLOCKS.LIST_ITEM, paragraph);
5160
-
5161
- case Contentful.BLOCKS.TABLE_ROW:
5162
- return wrapNode(Contentful.BLOCKS.TABLE_CELL, paragraph);
5163
-
5164
- case Contentful.BLOCKS.TABLE:
5165
- return wrapNode(Contentful.BLOCKS.TABLE_ROW, wrapNode(Contentful.BLOCKS.TABLE_CELL, paragraph));
5166
-
5167
- default:
5168
- return paragraph;
5169
- }
5170
- }
5171
- /**
5172
- * Ensures "orphaned" text node elements (those without a parent capable of
5173
- * validly rendering a text child node) are wrapped with a suitable parent
5174
- * element to prevent failures on the validation layer.
5175
- *
5176
- * It is commonplace for third party plugins (including udecode) to reconcile
5177
- * deletion events by inserting such nodes into their schema. This
5178
- * subprocedure is intended as a guard against such cases.
5179
- */
5180
-
5181
-
5182
- function sanitizeSlateDoc(nodes, parentNodeType) {
5183
- if (nodes === void 0) {
5184
- nodes = [];
5185
- }
5186
-
5187
- if (parentNodeType === void 0) {
5188
- parentNodeType = Contentful.BLOCKS.DOCUMENT;
5189
- }
5190
-
5191
- return nodes.map(function (node) {
5192
- if (isTextElement(node)) {
5193
- return TEXT_PARENT_NODES.includes(parentNodeType) ? node : wrapOrphanedTextNode(parentNodeType, node);
5194
- }
5195
-
5196
- return _extends({}, node, {
5197
- children: sanitizeSlateDoc(node.children, node.type)
5198
- });
5199
- });
5200
- }
5201
- /**
5202
- * Ensures incoming void nodes have a child leaf text element.
5203
- */
5204
-
5205
- function sanitizeIncomingSlateDoc(nodes) {
5206
- if (nodes === void 0) {
5207
- nodes = [];
5208
- }
5209
-
5210
- return nodes.map(function (node) {
5211
- var _node$children;
5212
-
5213
- if (isTextElement(node)) {
5214
- return node;
5215
- }
5216
-
5217
- if (node.isVoid && ((_node$children = node.children) == null ? void 0 : _node$children.length) === 0) {
5218
- return _extends({}, node, {
5219
- children: [{
5220
- text: '',
5221
- data: {}
5222
- }]
5223
- });
5224
- }
5225
-
5226
- return _extends({}, node, {
5227
- children: sanitizeIncomingSlateDoc(node.children)
5228
- });
5229
- });
5443
+ return plate.createExitBreakPlugin(optionsExitBreakPlugin);
5230
5444
  }
5231
5445
 
5232
5446
  var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
5233
- return plateTrailingBlock.createTrailingBlockPlugin({
5447
+ return plate.createTrailingBlockPlugin({
5234
5448
  type: Contentful.BLOCKS.PARAGRAPH,
5235
5449
  level: 0
5236
5450
  });
@@ -5240,7 +5454,7 @@ function createDragAndDropPlugin() {
5240
5454
  var _DND_BLOCKED_ELEMENTS;
5241
5455
 
5242
5456
  // Elements that don't allow other elements to be dragged into them and which callback should be used
5243
- var DND_BLOCKED_ELEMENTS = (_DND_BLOCKED_ELEMENTS = {}, _DND_BLOCKED_ELEMENTS[Contentful.BLOCKS.TABLE] = slate.Transforms.removeNodes, _DND_BLOCKED_ELEMENTS[Contentful.BLOCKS.QUOTE] = slate.Transforms.liftNodes, _DND_BLOCKED_ELEMENTS);
5457
+ var DND_BLOCKED_ELEMENTS = (_DND_BLOCKED_ELEMENTS = {}, _DND_BLOCKED_ELEMENTS[Contentful.BLOCKS.QUOTE] = slate.Transforms.liftNodes, _DND_BLOCKED_ELEMENTS);
5244
5458
  var DRAGGABLE_TYPES = [Contentful.BLOCKS.EMBEDDED_ENTRY, Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.INLINES.EMBEDDED_ENTRY];
5245
5459
  /**
5246
5460
  * HTML node names where dropping should be allowed
@@ -5290,7 +5504,7 @@ function createDragAndDropPlugin() {
5290
5504
  // If true, the next handlers will be skipped.
5291
5505
  onDrop: function onDrop(editor) {
5292
5506
  return function (event) {
5293
- var _Array$from = Array.from(plateCommon.getNodes(editor, {
5507
+ var _Array$from = Array.from(plate.getNodes(editor, {
5294
5508
  match: function match(node) {
5295
5509
  return slate.Editor.isBlock(editor, node) && DRAGGABLE_TYPES.includes(node.type);
5296
5510
  }
@@ -5323,26 +5537,64 @@ function getParents(el) {
5323
5537
  return parents;
5324
5538
  }
5325
5539
 
5326
- var _excluded$1 = ["sdk", "isInitiallyDisabled", "onAction"];
5540
+ function createTextPlugin() {
5541
+ return {
5542
+ withOverrides: function withOverrides(editor) {
5543
+ var deleteForward = editor.deleteForward; // When pressing delete instead of backspace
5544
+
5545
+ editor.deleteForward = function (unit) {
5546
+ var _editor$selection;
5547
+
5548
+ var _Editor$nodes = slate.Editor.nodes(editor, {
5549
+ at: (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path,
5550
+ match: function match(node) {
5551
+ return Contentful.TEXT_CONTAINERS.includes(node.type);
5552
+ }
5553
+ }),
5554
+ nodes = _Editor$nodes[0];
5555
+
5556
+ if (nodes) {
5557
+ var paragraphOrHeading = nodes[0],
5558
+ path = nodes[1];
5559
+ var isTextEmpty = plate.isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
5560
+
5561
+ var isRootLevel = path.length === 1;
5562
+
5563
+ if (isTextEmpty && isRootLevel) {
5564
+ slate.Transforms.removeNodes(editor, {
5565
+ at: path
5566
+ });
5567
+ } else {
5568
+ deleteForward(unit);
5569
+ }
5570
+ } else {
5571
+ deleteForward(unit);
5572
+ }
5573
+ };
5574
+
5575
+ return editor;
5576
+ }
5577
+ };
5578
+ }
5327
5579
 
5328
5580
  var getPlugins = function getPlugins(sdk, tracking) {
5329
5581
  var plugins = [// Core
5330
- plateCore.createReactPlugin(), plateCore.createHistoryPlugin(), // Behavior
5582
+ plate.createReactPlugin(), plate.createHistoryPlugin(), // Behavior
5331
5583
  createPastePlugin(), // Global shortcuts
5332
5584
  createNewLinePlugin(), createInsertBeforeFirstVoidBlockPlugin(), createDragAndDropPlugin(), // Block Elements
5333
5585
  createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
5334
5586
  createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
5335
5587
  createBoldPlugin(), createCodePlugin(), createItalicPlugin(), createUnderlinePlugin(), // Other
5336
- createTrailingParagraphPlugin()];
5337
- return plugins.concat([plateHtmlSerializer.createDeserializeHTMLPlugin({
5588
+ createTrailingParagraphPlugin(), createTextPlugin()];
5589
+ return plugins.concat([plate.createDeserializeHTMLPlugin({
5338
5590
  plugins: plugins
5339
- }), plateAstSerializer.createDeserializeAstPlugin({
5591
+ }), plate.createDeserializeAstPlugin({
5340
5592
  plugins: plugins
5341
5593
  })]);
5342
5594
  };
5595
+ var pluginOptions = /*#__PURE__*/_extends({}, withParagraphOptions, withListOptions, withHrOptions, withHeadingOptions, withQuoteOptions, withTableOptions, withEmbeddedEntryBlockOptions, withEmbeddedAssetBlockOptions, withHyperlinkOptions, withEmbeddedEntityInlineOptions, withBoldOptions, withCodeOptions, withItalicOptions, withUnderlineOptions);
5343
5596
 
5344
- var options = /*#__PURE__*/_extends({}, withParagraphOptions, withListOptions, withHrOptions, withHeadingOptions, withQuoteOptions, withTableOptions, withEmbeddedEntryBlockOptions, withEmbeddedAssetBlockOptions, withHyperlinkOptions, withEmbeddedEntityInlineOptions, withBoldOptions, withCodeOptions, withItalicOptions, withUnderlineOptions);
5345
-
5597
+ var _excluded$1 = ["sdk", "isInitiallyDisabled", "onAction"];
5346
5598
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5347
5599
  var tracking = useTrackingContext();
5348
5600
  var docFromAdapter = contentfulSlatejsAdapter.toSlatejsDocument({
@@ -5364,7 +5616,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5364
5616
  return /*#__PURE__*/React__default.createElement("div", {
5365
5617
  className: styles.root,
5366
5618
  "data-test-id": "rich-text-editor"
5367
- }, /*#__PURE__*/React__default.createElement(plateCore.Plate, {
5619
+ }, /*#__PURE__*/React__default.createElement(plate.Plate, {
5368
5620
  id: getContentfulEditorId(props.sdk),
5369
5621
  initialValue: value,
5370
5622
  plugins: plugins,
@@ -5382,7 +5634,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5382
5634
  props.onChange == null ? void 0 : props.onChange(contentfulDoc);
5383
5635
  },
5384
5636
  // @ts-expect-error
5385
- options: options
5637
+ options: pluginOptions
5386
5638
  }, !props.isToolbarHidden && /*#__PURE__*/React__default.createElement(StickyToolbarWrapper, {
5387
5639
  isDisabled: props.isDisabled
5388
5640
  }, /*#__PURE__*/React__default.createElement(Toolbar, {