@contentful/field-editor-rich-text 2.0.0-next.40 → 2.0.0-next.41
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/dist/field-editor-rich-text.cjs.development.js +39 -2
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +39 -2
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/sanitizeIncomingSlateDoc.d.ts +6 -0
- package/dist/prepareDocument.d.ts +2 -2
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6473,6 +6473,42 @@ var disableCorePlugins = {
|
|
|
6473
6473
|
eventEditor: true
|
|
6474
6474
|
};
|
|
6475
6475
|
|
|
6476
|
+
var isTextElement = function isTextElement(node) {
|
|
6477
|
+
return 'text' in node;
|
|
6478
|
+
};
|
|
6479
|
+
/**
|
|
6480
|
+
* Ensures all nodes have a child leaf text element. This should be handled by
|
|
6481
|
+
* Slate but its behavior has proven to be buggy and unpredictable.
|
|
6482
|
+
*/
|
|
6483
|
+
|
|
6484
|
+
|
|
6485
|
+
function sanitizeIncomingSlateDoc(nodes) {
|
|
6486
|
+
if (nodes === void 0) {
|
|
6487
|
+
nodes = [];
|
|
6488
|
+
}
|
|
6489
|
+
|
|
6490
|
+
return nodes.map(function (node) {
|
|
6491
|
+
var _node$children;
|
|
6492
|
+
|
|
6493
|
+
if (isTextElement(node)) {
|
|
6494
|
+
return node;
|
|
6495
|
+
}
|
|
6496
|
+
|
|
6497
|
+
if (((_node$children = node.children) == null ? void 0 : _node$children.length) === 0) {
|
|
6498
|
+
return _extends({}, node, {
|
|
6499
|
+
children: [{
|
|
6500
|
+
text: '',
|
|
6501
|
+
data: {}
|
|
6502
|
+
}]
|
|
6503
|
+
});
|
|
6504
|
+
}
|
|
6505
|
+
|
|
6506
|
+
return _extends({}, node, {
|
|
6507
|
+
children: sanitizeIncomingSlateDoc(node.children)
|
|
6508
|
+
});
|
|
6509
|
+
});
|
|
6510
|
+
}
|
|
6511
|
+
|
|
6476
6512
|
/**
|
|
6477
6513
|
* For legacy reasons, a document may not have any content at all
|
|
6478
6514
|
* e.g:
|
|
@@ -6527,16 +6563,17 @@ var setEditorContent = function setEditorContent(editor, nodes) {
|
|
|
6527
6563
|
});
|
|
6528
6564
|
};
|
|
6529
6565
|
/**
|
|
6530
|
-
* Converts a
|
|
6566
|
+
* Converts a Contentful rich text document to the corresponding slate editor
|
|
6531
6567
|
* value
|
|
6532
6568
|
*/
|
|
6533
6569
|
|
|
6534
6570
|
var documentToEditorValue = function documentToEditorValue(doc) {
|
|
6535
|
-
|
|
6571
|
+
var slateDoc = toSlatejsDocument({
|
|
6536
6572
|
document: hasContent(doc) ? doc : EMPTY_DOCUMENT,
|
|
6537
6573
|
// TODO: get rid of schema, https://github.com/contentful/field-editors/pull/1065#discussion_r826723248
|
|
6538
6574
|
schema: schema
|
|
6539
6575
|
});
|
|
6576
|
+
return sanitizeIncomingSlateDoc(slateDoc);
|
|
6540
6577
|
};
|
|
6541
6578
|
var normalizeEditorValue = function normalizeEditorValue(value, options) {
|
|
6542
6579
|
var editor = createPlateEditor(options);
|