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

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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.4.12](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.11...@contentful/field-editor-rich-text@3.4.12) (2023-03-10)
7
+
8
+ **Note:** Version bump only for package @contentful/field-editor-rich-text
9
+
10
+ ## [3.4.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.10...@contentful/field-editor-rich-text@3.4.11) (2023-03-09)
11
+
12
+ ### Bug Fixes
13
+
14
+ - **rich-text:** pasting hyperlinks with blocks ([#1364](https://github.com/contentful/field-editors/issues/1364)) ([32bfe1d](https://github.com/contentful/field-editors/commit/32bfe1dfaf6d976c69690a99b69b5beff570eba6))
15
+
6
16
  ## [3.4.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.9...@contentful/field-editor-rich-text@3.4.10) (2023-03-09)
7
17
 
8
18
  ### Bug Fixes
@@ -6096,6 +6096,62 @@ var createParagraphPlugin = function createParagraphPlugin() {
6096
6096
  return plateParagraph.createParagraphPlugin(config);
6097
6097
  };
6098
6098
 
6099
+ var wrapSpaceAround = function wrapSpaceAround(el) {
6100
+ var spacer = new Text(' ');
6101
+ var parent = el.parentNode;
6102
+
6103
+ if (!parent) {
6104
+ return;
6105
+ }
6106
+
6107
+ if (el.previousSibling) {
6108
+ parent.insertBefore(spacer, el);
6109
+ }
6110
+
6111
+ if (el.nextSibling) {
6112
+ parent.insertBefore(spacer, el.nextSibling);
6113
+ }
6114
+ };
6115
+
6116
+ var unwrap = function unwrap(el) {
6117
+ // add a spacer to avoid the content being cramped together with
6118
+ // the element siblings after it's unwrapped. It may not always
6119
+ // be desired but it should be easy to adjust by the end user.
6120
+ wrapSpaceAround(el);
6121
+ el.replaceWith.apply(el, Array.from(el.childNodes));
6122
+ };
6123
+ /**
6124
+ * In HTML it's a valid structure to have a block element inside a link
6125
+ *
6126
+ * e.g: <a href="..."><h1> My link </h1><h2>is fancy</h2></a>
6127
+ *
6128
+ * However, that's not supported in Slate. There are generally two ways to
6129
+ * handle this:
6130
+ *
6131
+ * a) Unwrap inner blocks while preserving the content.
6132
+ * e.g. <a href="...">My link is fancy</a>
6133
+ *
6134
+ * b) Break the link into multiple elements with having each block
6135
+ * element as a wrapper for an anchor with the same URL
6136
+ * e.g. <h1><a href="...">My link</a></h1>
6137
+ * and <h2><a href="...">is fancy</a></h2>
6138
+ *
6139
+ * We take approach (a) in here.
6140
+ */
6141
+
6142
+
6143
+ var sanitizeAnchors = function sanitizeAnchors(doc) {
6144
+ var unsupportedTagSelector = "a :not(" + [// Bold
6145
+ 'b', 'strong', // Code
6146
+ 'code', 'pre', // Italic
6147
+ 'em', 'i', // Super/subscript
6148
+ 'sub', 'sup', // Underline
6149
+ 'u', // Other
6150
+ 'span'].join(',') + ")";
6151
+ doc.querySelectorAll(unsupportedTagSelector).forEach(unwrap);
6152
+ return doc;
6153
+ };
6154
+
6099
6155
  /**
6100
6156
  * Remove empty spreadsheets columns/rows for performance reasons.
6101
6157
  */
@@ -6187,7 +6243,7 @@ var stripMetaTags = function stripMetaTags(doc) {
6187
6243
  }; // Attention: Order is important
6188
6244
 
6189
6245
 
6190
- var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags];
6246
+ var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags, sanitizeAnchors];
6191
6247
  var sanitizeHTML = function sanitizeHTML(html) {
6192
6248
  // Parse the HTML string and pipe it through our transformers
6193
6249
  var doc = transformers.reduce(function (value, cb) {