@contentful/field-editor-rich-text 3.4.9 → 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
  */
@@ -6167,15 +6223,43 @@ var stripStyleTags = function stripStyleTags(doc) {
6167
6223
  });
6168
6224
  return doc;
6169
6225
  };
6226
+ /**
6227
+ * Remove all <meta /> tags
6228
+ */
6229
+
6230
+
6231
+ var stripMetaTags = function stripMetaTags(doc) {
6232
+ doc.querySelectorAll('meta').forEach(function (el) {
6233
+ return el.remove();
6234
+ });
6235
+ return doc;
6236
+ }; // Attention: Order is important
6237
+
6170
6238
 
6171
- var transformers = [stripStyleTags, sanitizeSheets];
6239
+ var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags, sanitizeAnchors];
6172
6240
  var sanitizeHTML = function sanitizeHTML(html) {
6173
6241
  // Parse the HTML string and pipe it through our transformers
6174
6242
  var doc = transformers.reduce(function (value, cb) {
6175
6243
  return cb(value);
6176
6244
  }, new DOMParser().parseFromString(html, 'text/html'));
6177
- return doc.body.innerHTML.replace(/>\s+</g, '><') // Remove whitespace between tags
6178
- .replace(/(.*)<div.*>(<table.*<\/table>)<\/div>(.*)/g, '$1$2$3'); // remove div containers from tables
6245
+ var previous;
6246
+
6247
+ do {
6248
+ // save previous first before doing modifications
6249
+ previous = doc.body.innerHTML; // Update the body with the cleaned up content
6250
+
6251
+ doc.body.innerHTML = doc.body.innerHTML // remove div container from tables
6252
+ // capture groups explained:
6253
+ // 1. and 3. every content/linebreaks before and after the div container
6254
+ // 2. the table inside the container, including content and linebreaks
6255
+ // The div container including attributes and possible linebreaks inside wil be removed
6256
+ .replace(/(.*\s)?<div.*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>(.*\s)?/g, '$1$2$3') // remove whitespaces between some tags, as this can lead to unwanted behaviour:
6257
+ // - table -> empty table cells
6258
+ // - list -> leading whitespaces
6259
+ .replace(/<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)(.*)>\s+</g, '<$1$2$3><');
6260
+ } while (doc.body.innerHTML !== previous);
6261
+
6262
+ return doc.body.innerHTML;
6179
6263
  };
6180
6264
 
6181
6265
  /**