@contentful/field-editor-rich-text 3.4.17 → 3.4.18

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,12 @@
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.18](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.17...@contentful/field-editor-rich-text@3.4.18) (2023-04-17)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **RTE:** copy-paste perf issues on larger documents ([#1394](https://github.com/contentful/field-editors/issues/1394)) ([af6f3b1](https://github.com/contentful/field-editors/commit/af6f3b14e9cc3f38ae1337f32f8c0480da616659))
11
+
6
12
  ## [3.4.17](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.16...@contentful/field-editor-rich-text@3.4.17) (2023-04-04)
7
13
 
8
14
  ### Bug Fixes
@@ -6244,6 +6244,16 @@ var stripMetaTags = function stripMetaTags(doc) {
6244
6244
 
6245
6245
 
6246
6246
  var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags, sanitizeAnchors];
6247
+
6248
+ function removeTableWrappers(table) {
6249
+ var parent = table.parentElement;
6250
+
6251
+ if (parent && parent.tagName === 'DIV' && parent.children.length === 1) {
6252
+ parent.replaceWith(table);
6253
+ removeTableWrappers(table);
6254
+ }
6255
+ }
6256
+
6247
6257
  var sanitizeHTML = function sanitizeHTML(html) {
6248
6258
  // Parse the HTML string and pipe it through our transformers
6249
6259
  var doc = transformers.reduce(function (value, cb) {
@@ -6260,17 +6270,7 @@ var sanitizeHTML = function sanitizeHTML(html) {
6260
6270
  }, // remove whitespaces before the ending block element tag
6261
6271
  function (innerHTML) {
6262
6272
  return innerHTML.replace(/\s*<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1');
6263
- }]; // Call this replacer only if there are tables inside, as it can have a larger performance impact
6264
-
6265
- if (doc.querySelector('table')) {
6266
- // remove div container from tables
6267
- // The div container including attributes and possible linebreaks inside wil be removed
6268
- replacers.unshift(function (innerHtml) {
6269
- var result = innerHtml.replace(/<div[^>]*>\s*(<table(?:.|\s)*<\/table>)\s*<\/div>/g, '$1');
6270
- return result;
6271
- });
6272
- }
6273
-
6273
+ }];
6274
6274
  var previous;
6275
6275
 
6276
6276
  do {
@@ -6279,8 +6279,12 @@ var sanitizeHTML = function sanitizeHTML(html) {
6279
6279
  doc.body.innerHTML = replacers.reduce(function (innerHTML, replacer) {
6280
6280
  return replacer(innerHTML);
6281
6281
  }, doc.body.innerHTML);
6282
- } while (doc.body.innerHTML !== previous);
6282
+ } while (doc.body.innerHTML !== previous); // Removing the div container wrappers from tables
6283
+ // The div container including attributes and possible linebreaks inside wil be removed
6284
+ // TODO: can be removed with plate >= 20
6285
+
6283
6286
 
6287
+ doc.querySelectorAll('table').forEach(removeTableWrappers);
6284
6288
  return doc.body.innerHTML;
6285
6289
  };
6286
6290