@commercetools-uikit/rich-text-utils 15.0.2 → 15.1.2

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.
@@ -321,13 +321,17 @@ var mapper = {
321
321
  }
322
322
  };
323
323
 
324
+ var wrapWithParagraph = function wrapWithParagraph(textContent) {
325
+ return slateHyperscript.jsx('element', {
326
+ type: 'paragraph'
327
+ }, textContent);
328
+ };
329
+
324
330
  var wrapWithParagraphIfRootElement = function wrapWithParagraphIfRootElement(el, textContent) {
325
331
  var _el$parentNode;
326
332
 
327
333
  return ((_el$parentNode = el.parentNode) === null || _el$parentNode === void 0 ? void 0 : _el$parentNode.nodeName) === 'BODY' // root element, because body is eventually turned to React fragment
328
- ? slateHyperscript.jsx('element', {
329
- type: 'paragraph'
330
- }, textContent) : textContent;
334
+ ? wrapWithParagraph(textContent) : textContent;
331
335
  };
332
336
 
333
337
  var deserializeElement = function deserializeElement(el) {
@@ -400,7 +404,10 @@ var deserializeElement = function deserializeElement(el) {
400
404
  }, children));
401
405
  }
402
406
 
403
- return wrapWithParagraphIfRootElement(el, slateHyperscript.jsx('text', attrs, children));
407
+ return wrapWithParagraphIfRootElement(el, // children mapping to cover nested elements within text e.g. <span>Some <span>text</span></span>
408
+ _mapInstanceProperty__default["default"](children).call(children, function (child) {
409
+ return slate.Text.isText(child) ? slateHyperscript.jsx('text', attrs, child) : slateHyperscript.jsx('element', attrs, child);
410
+ }));
404
411
  }
405
412
  }
406
413
 
@@ -416,9 +423,12 @@ var deserializeElement = function deserializeElement(el) {
416
423
  return _mapInstanceProperty__default["default"](children).call(children, function (child) {
417
424
  return slateHyperscript.jsx('text', _attrs2, child);
418
425
  });
419
- }
426
+ } // each non-empty text node must be wrapped with a paragraph
420
427
 
421
- return children;
428
+
429
+ return _mapInstanceProperty__default["default"](children).call(children, function (child) {
430
+ return slate.Text.isText(child) && child.text ? wrapWithParagraph(child) : child;
431
+ });
422
432
  };
423
433
 
424
434
  var deserialize = function deserialize(html) {
@@ -3244,7 +3254,7 @@ RichTextEditorBody.defaultProps = defaultProps;
3244
3254
  var RichTextEditorBody$1 = RichTextEditorBody;
3245
3255
 
3246
3256
  // NOTE: This string will be replaced on build time with the package version.
3247
- var version = "15.0.2";
3257
+ var version = "15.1.2";
3248
3258
 
3249
3259
  exports.Element = Element;
3250
3260
  exports.HiddenInput = HiddenInput$1;
@@ -320,13 +320,17 @@ var mapper = {
320
320
  }
321
321
  };
322
322
 
323
+ var wrapWithParagraph = function wrapWithParagraph(textContent) {
324
+ return slateHyperscript.jsx('element', {
325
+ type: 'paragraph'
326
+ }, textContent);
327
+ };
328
+
323
329
  var wrapWithParagraphIfRootElement = function wrapWithParagraphIfRootElement(el, textContent) {
324
330
  var _el$parentNode;
325
331
 
326
332
  return ((_el$parentNode = el.parentNode) === null || _el$parentNode === void 0 ? void 0 : _el$parentNode.nodeName) === 'BODY' // root element, because body is eventually turned to React fragment
327
- ? slateHyperscript.jsx('element', {
328
- type: 'paragraph'
329
- }, textContent) : textContent;
333
+ ? wrapWithParagraph(textContent) : textContent;
330
334
  };
331
335
 
332
336
  var deserializeElement = function deserializeElement(el) {
@@ -399,7 +403,10 @@ var deserializeElement = function deserializeElement(el) {
399
403
  }, children));
400
404
  }
401
405
 
402
- return wrapWithParagraphIfRootElement(el, slateHyperscript.jsx('text', attrs, children));
406
+ return wrapWithParagraphIfRootElement(el, // children mapping to cover nested elements within text e.g. <span>Some <span>text</span></span>
407
+ _mapInstanceProperty__default["default"](children).call(children, function (child) {
408
+ return slate.Text.isText(child) ? slateHyperscript.jsx('text', attrs, child) : slateHyperscript.jsx('element', attrs, child);
409
+ }));
403
410
  }
404
411
  }
405
412
 
@@ -415,9 +422,12 @@ var deserializeElement = function deserializeElement(el) {
415
422
  return _mapInstanceProperty__default["default"](children).call(children, function (child) {
416
423
  return slateHyperscript.jsx('text', _attrs2, child);
417
424
  });
418
- }
425
+ } // each non-empty text node must be wrapped with a paragraph
419
426
 
420
- return children;
427
+
428
+ return _mapInstanceProperty__default["default"](children).call(children, function (child) {
429
+ return slate.Text.isText(child) && child.text ? wrapWithParagraph(child) : child;
430
+ });
421
431
  };
422
432
 
423
433
  var deserialize = function deserialize(html) {
@@ -3119,7 +3129,7 @@ RichTextEditorBody.defaultProps = defaultProps;
3119
3129
  var RichTextEditorBody$1 = RichTextEditorBody;
3120
3130
 
3121
3131
  // NOTE: This string will be replaced on build time with the package version.
3122
- var version = "15.0.2";
3132
+ var version = "15.1.2";
3123
3133
 
3124
3134
  exports.Element = Element;
3125
3135
  exports.HiddenInput = HiddenInput$1;
@@ -284,13 +284,17 @@ var mapper = {
284
284
  }
285
285
  };
286
286
 
287
+ var wrapWithParagraph = function wrapWithParagraph(textContent) {
288
+ return jsx('element', {
289
+ type: 'paragraph'
290
+ }, textContent);
291
+ };
292
+
287
293
  var wrapWithParagraphIfRootElement = function wrapWithParagraphIfRootElement(el, textContent) {
288
294
  var _el$parentNode;
289
295
 
290
296
  return ((_el$parentNode = el.parentNode) === null || _el$parentNode === void 0 ? void 0 : _el$parentNode.nodeName) === 'BODY' // root element, because body is eventually turned to React fragment
291
- ? jsx('element', {
292
- type: 'paragraph'
293
- }, textContent) : textContent;
297
+ ? wrapWithParagraph(textContent) : textContent;
294
298
  };
295
299
 
296
300
  var deserializeElement = function deserializeElement(el) {
@@ -363,7 +367,10 @@ var deserializeElement = function deserializeElement(el) {
363
367
  }, children));
364
368
  }
365
369
 
366
- return wrapWithParagraphIfRootElement(el, jsx('text', attrs, children));
370
+ return wrapWithParagraphIfRootElement(el, // children mapping to cover nested elements within text e.g. <span>Some <span>text</span></span>
371
+ _mapInstanceProperty(children).call(children, function (child) {
372
+ return Text.isText(child) ? jsx('text', attrs, child) : jsx('element', attrs, child);
373
+ }));
367
374
  }
368
375
  }
369
376
 
@@ -379,9 +386,12 @@ var deserializeElement = function deserializeElement(el) {
379
386
  return _mapInstanceProperty(children).call(children, function (child) {
380
387
  return jsx('text', _attrs2, child);
381
388
  });
382
- }
389
+ } // each non-empty text node must be wrapped with a paragraph
383
390
 
384
- return children;
391
+
392
+ return _mapInstanceProperty(children).call(children, function (child) {
393
+ return Text.isText(child) && child.text ? wrapWithParagraph(child) : child;
394
+ });
385
395
  };
386
396
 
387
397
  var deserialize = function deserialize(html) {
@@ -3207,6 +3217,6 @@ RichTextEditorBody.defaultProps = defaultProps;
3207
3217
  var RichTextEditorBody$1 = RichTextEditorBody;
3208
3218
 
3209
3219
  // NOTE: This string will be replaced on build time with the package version.
3210
- var version = "15.0.2";
3220
+ var version = "15.1.2";
3211
3221
 
3212
3222
  export { Element, HiddenInput$1 as HiddenInput, Leaf, RichTextEditorBody$1 as RichTextBody, focusEditor, html$1 as html, isBlockActive, isRichTextEmpty as isEmpty, isMarkActive, index as localized, resetEditor, toggleBlock, toggleMark, validSlateStateAdapter, version };
@@ -8,6 +8,6 @@ declare const toggleMark: (editor: Editor, format: Format) => void;
8
8
  declare const isBlockActive: (editor: TEditor, format: Format) => boolean;
9
9
  declare const toggleBlock: (editor: TEditor, format: Format) => void;
10
10
  declare const validSlateStateAdapter: (value: Deserialized | Deserialized[]) => Descendant[];
11
- declare const resetEditor: (editor: Editor, resetValue?: string | undefined) => void;
11
+ declare const resetEditor: (editor: Editor, resetValue?: string) => void;
12
12
  declare const focusEditor: (editor: Editor) => void;
13
13
  export { Element, Leaf, isMarkActive, isBlockActive, toggleMark, toggleBlock, validSlateStateAdapter, resetEditor, focusEditor, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/rich-text-utils",
3
3
  "description": "Utilities for working with rich-text components.",
4
- "version": "15.0.2",
4
+ "version": "15.1.2",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,15 +24,15 @@
24
24
  "dependencies": {
25
25
  "@babel/runtime": "^7.17.2",
26
26
  "@babel/runtime-corejs3": "^7.17.2",
27
- "@commercetools-uikit/design-system": "15.0.0",
28
- "@commercetools-uikit/icons": "15.0.0",
29
- "@commercetools-uikit/input-utils": "15.0.0",
30
- "@commercetools-uikit/spacings-inline": "15.0.0",
31
- "@commercetools-uikit/tooltip": "15.0.0",
32
- "@commercetools-uikit/utils": "15.0.0",
27
+ "@commercetools-uikit/design-system": "15.1.2",
28
+ "@commercetools-uikit/icons": "15.1.2",
29
+ "@commercetools-uikit/input-utils": "15.1.2",
30
+ "@commercetools-uikit/spacings-inline": "15.1.2",
31
+ "@commercetools-uikit/tooltip": "15.1.2",
32
+ "@commercetools-uikit/utils": "15.1.2",
33
33
  "@emotion/react": "^11.4.0",
34
34
  "@emotion/styled": "^11.3.0",
35
- "@types/escape-html": "1.0.1",
35
+ "@types/escape-html": "1.0.2",
36
36
  "downshift": "6.1.7",
37
37
  "escape-html": "1.0.3",
38
38
  "is-hotkey": "0.2.0",
@@ -40,7 +40,7 @@
40
40
  "prop-types": "15.8.1",
41
41
  "slate": "0.75.0",
42
42
  "slate-history": "0.66.0",
43
- "slate-hyperscript": "0.67.0",
43
+ "slate-hyperscript": "0.77.0",
44
44
  "slate-react": "0.75.0",
45
45
  "style-to-object": "0.3.0"
46
46
  },