@contentful/field-editor-rich-text 3.4.10 → 3.4.11

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.
@@ -11,11 +11,11 @@ import { createDeserializeDocxPlugin } from '@udecode/plate-serializer-docx';
11
11
  import { createSoftBreakPlugin as createSoftBreakPlugin$1, createExitBreakPlugin as createExitBreakPlugin$1 } from '@udecode/plate-break';
12
12
  import { createResetNodePlugin as createResetNodePlugin$1, onKeyDownResetNode, SIMULATE_BACKSPACE } from '@udecode/plate-reset-node';
13
13
  import { usePopper } from 'react-popper';
14
- import { ScreenReaderOnly, Popover, SectionHeading, Stack, Flex, AssetCard, EntryCard, Menu, Icon, InlineEntryCard, MenuItem, Text as Text$1, Button, Tooltip, ModalContent, Form, FormControl, TextInput, Select, FormLabel, TextLink, ModalControls, IconButton } from '@contentful/f36-components';
14
+ import { ScreenReaderOnly, Popover, SectionHeading, Stack, Flex, AssetCard, EntryCard, Menu, Icon, InlineEntryCard, MenuItem, Text as Text$2, Button, Tooltip, ModalContent, Form, FormControl, TextInput, Select, FormLabel, TextLink, ModalControls, IconButton } from '@contentful/f36-components';
15
15
  import { Portal } from '@contentful/f36-utils';
16
16
  import constate from 'constate';
17
17
  import isHotkey from 'is-hotkey';
18
- import { Path, Range, Text, Node, Element, Point } from 'slate';
18
+ import { Path, Range, Text as Text$1, Node, Element, Point } from 'slate';
19
19
  import find from 'lodash-es/find';
20
20
  import flow from 'lodash-es/flow';
21
21
  import get from 'lodash-es/get';
@@ -552,7 +552,7 @@ var someNode = function someNode(editor, options) {
552
552
  };
553
553
  var getChildren = function getChildren(entry) {
554
554
  // Node.children crashes when given a text node
555
- if (Text.isText(entry[0])) {
555
+ if (Text$1.isText(entry[0])) {
556
556
  return [];
557
557
  }
558
558
 
@@ -3196,7 +3196,7 @@ function FetchingWrappedInlineEntryCard(props) {
3196
3196
  className: styles$3.scheduledIcon,
3197
3197
  variant: "muted",
3198
3198
  testId: "scheduled-icon"
3199
- })), /*#__PURE__*/React__default.createElement(Text$1, null, title));
3199
+ })), /*#__PURE__*/React__default.createElement(Text$2, null, title));
3200
3200
  }
3201
3201
 
3202
3202
  function createInlineEntryNode$1(id) {
@@ -6089,6 +6089,62 @@ var createParagraphPlugin = function createParagraphPlugin() {
6089
6089
  return createParagraphPlugin$1(config);
6090
6090
  };
6091
6091
 
6092
+ var wrapSpaceAround = function wrapSpaceAround(el) {
6093
+ var spacer = new Text(' ');
6094
+ var parent = el.parentNode;
6095
+
6096
+ if (!parent) {
6097
+ return;
6098
+ }
6099
+
6100
+ if (el.previousSibling) {
6101
+ parent.insertBefore(spacer, el);
6102
+ }
6103
+
6104
+ if (el.nextSibling) {
6105
+ parent.insertBefore(spacer, el.nextSibling);
6106
+ }
6107
+ };
6108
+
6109
+ var unwrap = function unwrap(el) {
6110
+ // add a spacer to avoid the content being cramped together with
6111
+ // the element siblings after it's unwrapped. It may not always
6112
+ // be desired but it should be easy to adjust by the end user.
6113
+ wrapSpaceAround(el);
6114
+ el.replaceWith.apply(el, Array.from(el.childNodes));
6115
+ };
6116
+ /**
6117
+ * In HTML it's a valid structure to have a block element inside a link
6118
+ *
6119
+ * e.g: <a href="..."><h1> My link </h1><h2>is fancy</h2></a>
6120
+ *
6121
+ * However, that's not supported in Slate. There are generally two ways to
6122
+ * handle this:
6123
+ *
6124
+ * a) Unwrap inner blocks while preserving the content.
6125
+ * e.g. <a href="...">My link is fancy</a>
6126
+ *
6127
+ * b) Break the link into multiple elements with having each block
6128
+ * element as a wrapper for an anchor with the same URL
6129
+ * e.g. <h1><a href="...">My link</a></h1>
6130
+ * and <h2><a href="...">is fancy</a></h2>
6131
+ *
6132
+ * We take approach (a) in here.
6133
+ */
6134
+
6135
+
6136
+ var sanitizeAnchors = function sanitizeAnchors(doc) {
6137
+ var unsupportedTagSelector = "a :not(" + [// Bold
6138
+ 'b', 'strong', // Code
6139
+ 'code', 'pre', // Italic
6140
+ 'em', 'i', // Super/subscript
6141
+ 'sub', 'sup', // Underline
6142
+ 'u', // Other
6143
+ 'span'].join(',') + ")";
6144
+ doc.querySelectorAll(unsupportedTagSelector).forEach(unwrap);
6145
+ return doc;
6146
+ };
6147
+
6092
6148
  /**
6093
6149
  * Remove empty spreadsheets columns/rows for performance reasons.
6094
6150
  */
@@ -6180,7 +6236,7 @@ var stripMetaTags = function stripMetaTags(doc) {
6180
6236
  }; // Attention: Order is important
6181
6237
 
6182
6238
 
6183
- var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags];
6239
+ var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags, sanitizeAnchors];
6184
6240
  var sanitizeHTML = function sanitizeHTML(html) {
6185
6241
  // Parse the HTML string and pipe it through our transformers
6186
6242
  var doc = transformers.reduce(function (value, cb) {