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

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.
@@ -2772,21 +2772,24 @@ function watchCurrentSlide(navigator) {
2772
2772
  };
2773
2773
  };
2774
2774
 
2775
- var off = navigator.onSlideInNavigation(function (info) {
2775
+ var off = navigator.onSlideInNavigation(function (_ref) {
2776
+ var oldSlideLevel = _ref.oldSlideLevel,
2777
+ newSlideLevel = _ref.newSlideLevel;
2778
+
2776
2779
  if (initialSlideLevel === undefined) {
2777
- initialSlideLevel = info.oldSlideLevel;
2780
+ initialSlideLevel = oldSlideLevel;
2778
2781
  }
2779
2782
 
2780
- lastSlideLevel = info.newSlideLevel;
2783
+ lastSlideLevel = newSlideLevel;
2781
2784
 
2782
- if (info.newSlideLevel < initialSlideLevel) {
2785
+ if (newSlideLevel < initialSlideLevel) {
2783
2786
  wasSlideClosed = true;
2784
2787
  off(); // No more point in watching, slide got closed.
2785
2788
 
2786
2789
  onActiveCallbacks.clear();
2787
2790
  }
2788
2791
 
2789
- if (status().isActive) {
2792
+ if (status().isActive && newSlideLevel !== oldSlideLevel) {
2790
2793
  onActiveCallbacks.forEach(function (cb) {
2791
2794
  return cb();
2792
2795
  });
@@ -3237,7 +3240,11 @@ function EmbeddedEntityInline(props) {
3237
3240
 
3238
3241
  function handleEditClick() {
3239
3242
  return sdk.navigator.openEntry(entryId, {
3240
- slideIn: true
3243
+ slideIn: {
3244
+ waitForClose: true
3245
+ }
3246
+ }).then(function () {
3247
+ editor && focus(editor);
3241
3248
  });
3242
3249
  }
3243
3250
 
@@ -3276,7 +3283,7 @@ function selectEntityAndInsert$1(_x, _x2, _x3) {
3276
3283
 
3277
3284
  function _selectEntityAndInsert$1() {
3278
3285
  _selectEntityAndInsert$1 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(editor, sdk, logAction) {
3279
- var config, selection, entry, inlineEntryNode;
3286
+ var config, rteSlide, entry;
3280
3287
  return runtime_1.wrap(function _callee2$(_context2) {
3281
3288
  while (1) {
3282
3289
  switch (_context2.prev = _context2.next) {
@@ -3287,39 +3294,30 @@ function _selectEntityAndInsert$1() {
3287
3294
  config = _extends({}, newEntitySelectorConfigFromRichTextField(sdk.field, INLINES.EMBEDDED_ENTRY), {
3288
3295
  withCreate: true
3289
3296
  });
3290
- selection = editor.selection;
3297
+ rteSlide = watchCurrentSlide(sdk.navigator);
3291
3298
  _context2.next = 5;
3292
3299
  return sdk.dialogs.selectSingleEntry(config);
3293
3300
 
3294
3301
  case 5:
3295
3302
  entry = _context2.sent;
3296
- focus(editor); // Dialog steals focus from editor, return it.
3297
3303
 
3298
- if (entry) {
3299
- _context2.next = 10;
3300
- break;
3304
+ if (!entry) {
3305
+ logAction('cancelCreateEmbedDialog', {
3306
+ nodeType: INLINES.EMBEDDED_ENTRY
3307
+ });
3308
+ } else {
3309
+ insertNodes(editor, createInlineEntryNode$1(entry.sys.id));
3310
+ logAction('insert', {
3311
+ nodeType: INLINES.EMBEDDED_ENTRY
3312
+ });
3301
3313
  }
3302
3314
 
3303
- logAction('cancelCreateEmbedDialog', {
3304
- nodeType: INLINES.EMBEDDED_ENTRY
3315
+ rteSlide.onActive(function () {
3316
+ rteSlide.unwatch();
3317
+ focus(editor);
3305
3318
  });
3306
- return _context2.abrupt("return");
3307
3319
 
3308
- case 10:
3309
- inlineEntryNode = createInlineEntryNode$1(entry.sys.id);
3310
- logAction('insert', {
3311
- nodeType: INLINES.EMBEDDED_ENTRY
3312
- }); // Got to wait until focus is really back on the editor or setSelection() won't work.
3313
-
3314
- return _context2.abrupt("return", new Promise(function (resolve) {
3315
- setTimeout(function () {
3316
- setSelection(editor, selection);
3317
- insertNodes(editor, inlineEntryNode);
3318
- resolve();
3319
- }, 0);
3320
- }));
3321
-
3322
- case 13:
3320
+ case 8:
3323
3321
  case "end":
3324
3322
  return _context2.stop();
3325
3323
  }
@@ -6169,15 +6167,43 @@ var stripStyleTags = function stripStyleTags(doc) {
6169
6167
  });
6170
6168
  return doc;
6171
6169
  };
6170
+ /**
6171
+ * Remove all <meta /> tags
6172
+ */
6173
+
6174
+
6175
+ var stripMetaTags = function stripMetaTags(doc) {
6176
+ doc.querySelectorAll('meta').forEach(function (el) {
6177
+ return el.remove();
6178
+ });
6179
+ return doc;
6180
+ }; // Attention: Order is important
6181
+
6172
6182
 
6173
- var transformers = [stripStyleTags, sanitizeSheets];
6183
+ var transformers = [stripStyleTags, sanitizeSheets, stripMetaTags];
6174
6184
  var sanitizeHTML = function sanitizeHTML(html) {
6175
6185
  // Parse the HTML string and pipe it through our transformers
6176
6186
  var doc = transformers.reduce(function (value, cb) {
6177
6187
  return cb(value);
6178
6188
  }, new DOMParser().parseFromString(html, 'text/html'));
6179
- return doc.body.innerHTML.replace(/>\s+</g, '><') // Remove whitespace between tags
6180
- .replace(/(.*)<div.*>(<table.*<\/table>)<\/div>(.*)/g, '$1$2$3'); // remove div containers from tables
6189
+ var previous;
6190
+
6191
+ do {
6192
+ // save previous first before doing modifications
6193
+ previous = doc.body.innerHTML; // Update the body with the cleaned up content
6194
+
6195
+ doc.body.innerHTML = doc.body.innerHTML // remove div container from tables
6196
+ // capture groups explained:
6197
+ // 1. and 3. every content/linebreaks before and after the div container
6198
+ // 2. the table inside the container, including content and linebreaks
6199
+ // The div container including attributes and possible linebreaks inside wil be removed
6200
+ .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:
6201
+ // - table -> empty table cells
6202
+ // - list -> leading whitespaces
6203
+ .replace(/<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)(.*)>\s+</g, '<$1$2$3><');
6204
+ } while (doc.body.innerHTML !== previous);
6205
+
6206
+ return doc.body.innerHTML;
6181
6207
  };
6182
6208
 
6183
6209
  /**