@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
|
@@ -6480,6 +6480,42 @@ var disableCorePlugins = {
|
|
|
6480
6480
|
eventEditor: true
|
|
6481
6481
|
};
|
|
6482
6482
|
|
|
6483
|
+
var isTextElement = function isTextElement(node) {
|
|
6484
|
+
return 'text' in node;
|
|
6485
|
+
};
|
|
6486
|
+
/**
|
|
6487
|
+
* Ensures all nodes have a child leaf text element. This should be handled by
|
|
6488
|
+
* Slate but its behavior has proven to be buggy and unpredictable.
|
|
6489
|
+
*/
|
|
6490
|
+
|
|
6491
|
+
|
|
6492
|
+
function sanitizeIncomingSlateDoc(nodes) {
|
|
6493
|
+
if (nodes === void 0) {
|
|
6494
|
+
nodes = [];
|
|
6495
|
+
}
|
|
6496
|
+
|
|
6497
|
+
return nodes.map(function (node) {
|
|
6498
|
+
var _node$children;
|
|
6499
|
+
|
|
6500
|
+
if (isTextElement(node)) {
|
|
6501
|
+
return node;
|
|
6502
|
+
}
|
|
6503
|
+
|
|
6504
|
+
if (((_node$children = node.children) == null ? void 0 : _node$children.length) === 0) {
|
|
6505
|
+
return _extends({}, node, {
|
|
6506
|
+
children: [{
|
|
6507
|
+
text: '',
|
|
6508
|
+
data: {}
|
|
6509
|
+
}]
|
|
6510
|
+
});
|
|
6511
|
+
}
|
|
6512
|
+
|
|
6513
|
+
return _extends({}, node, {
|
|
6514
|
+
children: sanitizeIncomingSlateDoc(node.children)
|
|
6515
|
+
});
|
|
6516
|
+
});
|
|
6517
|
+
}
|
|
6518
|
+
|
|
6483
6519
|
/**
|
|
6484
6520
|
* For legacy reasons, a document may not have any content at all
|
|
6485
6521
|
* e.g:
|
|
@@ -6534,16 +6570,17 @@ var setEditorContent = function setEditorContent(editor, nodes) {
|
|
|
6534
6570
|
});
|
|
6535
6571
|
};
|
|
6536
6572
|
/**
|
|
6537
|
-
* Converts a
|
|
6573
|
+
* Converts a Contentful rich text document to the corresponding slate editor
|
|
6538
6574
|
* value
|
|
6539
6575
|
*/
|
|
6540
6576
|
|
|
6541
6577
|
var documentToEditorValue = function documentToEditorValue(doc) {
|
|
6542
|
-
|
|
6578
|
+
var slateDoc = contentfulSlateJSAdapter.toSlatejsDocument({
|
|
6543
6579
|
document: hasContent(doc) ? doc : Contentful.EMPTY_DOCUMENT,
|
|
6544
6580
|
// TODO: get rid of schema, https://github.com/contentful/field-editors/pull/1065#discussion_r826723248
|
|
6545
6581
|
schema: schema
|
|
6546
6582
|
});
|
|
6583
|
+
return sanitizeIncomingSlateDoc(slateDoc);
|
|
6547
6584
|
};
|
|
6548
6585
|
var normalizeEditorValue = function normalizeEditorValue(value, options) {
|
|
6549
6586
|
var editor = plateCore.createPlateEditor(options);
|