@contentful/field-editor-rich-text 0.26.0-next → 0.26.4-next
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/ContentfulEditorProvider.d.ts +2 -2
- package/dist/field-editor-rich-text.cjs.development.js +56 -69
- 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 +57 -70
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/validations.d.ts +2 -1
- package/dist/plugins/Paste/sanitizers/helpers.d.ts +2 -0
- package/dist/plugins/Paste/sanitizers/index.d.ts +1 -0
- package/dist/plugins/Paste/sanitizers/sanitizeEntityBlocks.d.ts +6 -0
- package/package.json +12 -12
- package/CHANGELOG.md +0 -684
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React__default, {
|
|
1
|
+
import React__default, { createElement, useMemo, useState, useEffect, Fragment, useCallback } from 'react';
|
|
2
2
|
import noop from 'lodash-es/noop';
|
|
3
3
|
import { toContentfulDocument, toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
|
|
4
4
|
import { TOP_LEVEL_BLOCKS, BLOCKS, CONTAINERS, VOID_BLOCKS, INLINES, LIST_ITEM_BLOCKS, MARKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
@@ -544,25 +544,9 @@ function getContentfulEditorId(sdk) {
|
|
|
544
544
|
}
|
|
545
545
|
|
|
546
546
|
function useContentfulEditorHook(_ref) {
|
|
547
|
-
var _editor$selection;
|
|
548
|
-
|
|
549
547
|
var sdk = _ref.sdk;
|
|
550
548
|
var editorId = getContentfulEditorId(sdk);
|
|
551
549
|
var editor = useStoreEditorRef(editorId);
|
|
552
|
-
|
|
553
|
-
var _React$useState = useState((_editor$selection = editor == null ? void 0 : editor.selection) != null ? _editor$selection : null),
|
|
554
|
-
selection = _React$useState[0],
|
|
555
|
-
setSelection = _React$useState[1];
|
|
556
|
-
|
|
557
|
-
useEffect(function () {
|
|
558
|
-
if (!(editor != null && editor.selection)) return;
|
|
559
|
-
setSelection(editor.selection);
|
|
560
|
-
}, [editor == null ? void 0 : editor.selection]);
|
|
561
|
-
|
|
562
|
-
if (editor && !(editor != null && editor.selection) && selection) {
|
|
563
|
-
editor.selection = selection;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
550
|
return editor;
|
|
567
551
|
}
|
|
568
552
|
|
|
@@ -673,6 +657,7 @@ var VALIDATIONS = {
|
|
|
673
657
|
ENABLED_MARKS: 'enabledMarks',
|
|
674
658
|
ENABLED_NODE_TYPES: 'enabledNodeTypes'
|
|
675
659
|
};
|
|
660
|
+
var DEFAULT_ENABLED_NODE_TYPES = [BLOCKS.DOCUMENT, BLOCKS.PARAGRAPH, 'text'];
|
|
676
661
|
|
|
677
662
|
var getRichTextValidation = function getRichTextValidation(field, validationType) {
|
|
678
663
|
return flow(function (v) {
|
|
@@ -683,13 +668,14 @@ var getRichTextValidation = function getRichTextValidation(field, validationType
|
|
|
683
668
|
};
|
|
684
669
|
|
|
685
670
|
var isFormattingOptionEnabled = function isFormattingOptionEnabled(field, validationType, nodeTypeOrMark) {
|
|
686
|
-
var enabledFormattings = getRichTextValidation(field, validationType);
|
|
671
|
+
var enabledFormattings = getRichTextValidation(field, validationType); // TODO: In the future, validations will always be opt-in. In that case
|
|
672
|
+
// we don't need this step.
|
|
687
673
|
|
|
688
674
|
if (enabledFormattings === undefined) {
|
|
689
675
|
return true;
|
|
690
676
|
}
|
|
691
677
|
|
|
692
|
-
return enabledFormattings.includes(nodeTypeOrMark);
|
|
678
|
+
return DEFAULT_ENABLED_NODE_TYPES.concat(enabledFormattings).includes(nodeTypeOrMark);
|
|
693
679
|
};
|
|
694
680
|
|
|
695
681
|
var isNodeTypeEnabled = function isNodeTypeEnabled(field, nodeType) {
|
|
@@ -2528,11 +2514,10 @@ function AssetDropdownMenu(_ref) {
|
|
|
2528
2514
|
onRemove = _ref.onRemove,
|
|
2529
2515
|
isDisabled = _ref.isDisabled,
|
|
2530
2516
|
entityFile = _ref.entityFile;
|
|
2531
|
-
var fileName = entityFile
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
var
|
|
2535
|
-
image = details.image;
|
|
2517
|
+
var fileName = get(entityFile, 'fileName');
|
|
2518
|
+
var fileSize = get(entityFile, 'details.size');
|
|
2519
|
+
var image = get(entityFile, 'details.image');
|
|
2520
|
+
var mimeType = get(entityFile, 'contentType');
|
|
2536
2521
|
|
|
2537
2522
|
function downloadAsset() {
|
|
2538
2523
|
if (!entityFile) return;
|
|
@@ -3705,6 +3690,8 @@ function addTableTrackingEvents(editor, _ref) {
|
|
|
3705
3690
|
});
|
|
3706
3691
|
}
|
|
3707
3692
|
}, 1);
|
|
3693
|
+
} else {
|
|
3694
|
+
insertData(data);
|
|
3708
3695
|
}
|
|
3709
3696
|
};
|
|
3710
3697
|
}
|
|
@@ -4111,29 +4098,11 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
4111
4098
|
var editor = useContentfulEditor();
|
|
4112
4099
|
var sdk = useSdkContext();
|
|
4113
4100
|
|
|
4114
|
-
var handleClick =
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
case 0:
|
|
4120
|
-
event.preventDefault();
|
|
4121
|
-
onClose();
|
|
4122
|
-
_context.next = 4;
|
|
4123
|
-
return selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
|
|
4124
|
-
|
|
4125
|
-
case 4:
|
|
4126
|
-
case "end":
|
|
4127
|
-
return _context.stop();
|
|
4128
|
-
}
|
|
4129
|
-
}
|
|
4130
|
-
}, _callee);
|
|
4131
|
-
}));
|
|
4132
|
-
|
|
4133
|
-
return function handleClick(_x) {
|
|
4134
|
-
return _ref2.apply(this, arguments);
|
|
4135
|
-
};
|
|
4136
|
-
}();
|
|
4101
|
+
var handleClick = function handleClick(event) {
|
|
4102
|
+
event.preventDefault();
|
|
4103
|
+
onClose();
|
|
4104
|
+
selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
|
|
4105
|
+
};
|
|
4137
4106
|
|
|
4138
4107
|
var type = getEntityTypeFromNodeType(nodeType);
|
|
4139
4108
|
var baseClass = "rich-text__" + nodeType;
|
|
@@ -4751,12 +4720,18 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
|
|
|
4751
4720
|
}, children);
|
|
4752
4721
|
};
|
|
4753
4722
|
|
|
4723
|
+
var isHTMLElement = function isHTMLElement(node) {
|
|
4724
|
+
return node.nodeType === Node.ELEMENT_NODE;
|
|
4725
|
+
};
|
|
4754
4726
|
var removeChildNodes = function removeChildNodes(node, predicate) {
|
|
4727
|
+
if (predicate === void 0) {
|
|
4728
|
+
predicate = Boolean;
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4755
4731
|
return Array.from(node.childNodes).filter(predicate).forEach(function (table) {
|
|
4756
4732
|
return node.removeChild(table);
|
|
4757
4733
|
});
|
|
4758
4734
|
};
|
|
4759
|
-
|
|
4760
4735
|
var removeChildNodesUsingPredicate = function removeChildNodesUsingPredicate(predicate) {
|
|
4761
4736
|
return function (nodeList) {
|
|
4762
4737
|
var nodes = Array.from(nodeList);
|
|
@@ -4791,10 +4766,6 @@ var TAG_NAME_TABLE = 'TABLE';
|
|
|
4791
4766
|
var TAG_NAME_TABLE_CAPTION = 'CAPTION';
|
|
4792
4767
|
var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
|
|
4793
4768
|
|
|
4794
|
-
var isHTMLElement = function isHTMLElement(node) {
|
|
4795
|
-
return node.nodeType === Node.ELEMENT_NODE;
|
|
4796
|
-
};
|
|
4797
|
-
|
|
4798
4769
|
var isTableElement = function isTableElement(node) {
|
|
4799
4770
|
return isHTMLElement(node) && node.tagName === TAG_NAME_TABLE;
|
|
4800
4771
|
};
|
|
@@ -4843,12 +4814,40 @@ var sanitizeTables = function sanitizeTables(_ref) {
|
|
|
4843
4814
|
return [doc, editor];
|
|
4844
4815
|
};
|
|
4845
4816
|
|
|
4817
|
+
/**
|
|
4818
|
+
* Ensures the text selection from entity block elements is
|
|
4819
|
+
* not included in the paste buffer.
|
|
4820
|
+
*/
|
|
4821
|
+
|
|
4822
|
+
var sanitizeEntityBlocks = function sanitizeEntityBlocks(_ref) {
|
|
4823
|
+
var doc = _ref[0],
|
|
4824
|
+
editor = _ref[1];
|
|
4825
|
+
var nodes = Array.from(doc.childNodes);
|
|
4826
|
+
|
|
4827
|
+
while (nodes.length > 0) {
|
|
4828
|
+
var node = nodes.pop();
|
|
4829
|
+
|
|
4830
|
+
if (isHTMLElement(node) && node.getAttribute('data-entity-type')) {
|
|
4831
|
+
removeChildNodes(node);
|
|
4832
|
+
continue;
|
|
4833
|
+
}
|
|
4834
|
+
|
|
4835
|
+
for (var _i = 0, _Array$from = Array.from(node.childNodes); _i < _Array$from.length; _i++) {
|
|
4836
|
+
var childNode = _Array$from[_i];
|
|
4837
|
+
nodes.push(childNode);
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
|
|
4841
|
+
return [doc, editor];
|
|
4842
|
+
};
|
|
4843
|
+
|
|
4846
4844
|
|
|
4847
4845
|
|
|
4848
4846
|
var sanitizers = {
|
|
4849
4847
|
__proto__: null,
|
|
4850
4848
|
removeComments: removeComments,
|
|
4851
|
-
sanitizeTables: sanitizeTables
|
|
4849
|
+
sanitizeTables: sanitizeTables,
|
|
4850
|
+
sanitizeEntityBlocks: sanitizeEntityBlocks
|
|
4852
4851
|
};
|
|
4853
4852
|
|
|
4854
4853
|
var MIME_TYPE_HTML = 'text/html'; // TODO: Upgrade tslib so we can just flow(...sanitizers);
|
|
@@ -4883,6 +4882,8 @@ function withPasteHandling(editor) {
|
|
|
4883
4882
|
var sanitized = sanitizeHtml(html, editor);
|
|
4884
4883
|
var newData = htmlToDataTransfer(sanitized);
|
|
4885
4884
|
insertData(newData);
|
|
4885
|
+
} else {
|
|
4886
|
+
insertData(data);
|
|
4886
4887
|
}
|
|
4887
4888
|
};
|
|
4888
4889
|
};
|
|
@@ -4907,23 +4908,9 @@ function createParagraphPlugin() {
|
|
|
4907
4908
|
renderElement: getRenderElement(elementKeys),
|
|
4908
4909
|
pluginKeys: elementKeys,
|
|
4909
4910
|
onKeyDown: getToggleElementOnKeyDown(BLOCKS.PARAGRAPH),
|
|
4910
|
-
deserialize:
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
element: [_extends({
|
|
4914
|
-
type: BLOCKS.PARAGRAPH,
|
|
4915
|
-
deserialize: function deserialize(element) {
|
|
4916
|
-
var isParagraphText = element.nodeName === 'P';
|
|
4917
|
-
var isNotEmpty = element.textContent !== '';
|
|
4918
|
-
var isText = isParagraphText && isNotEmpty;
|
|
4919
|
-
if (!isText) return;
|
|
4920
|
-
return {
|
|
4921
|
-
type: BLOCKS.PARAGRAPH
|
|
4922
|
-
};
|
|
4923
|
-
}
|
|
4924
|
-
}, options.deserialize)]
|
|
4925
|
-
};
|
|
4926
|
-
}
|
|
4911
|
+
deserialize: deserializeElement(BLOCKS.PARAGRAPH, [{
|
|
4912
|
+
nodeNames: ['P']
|
|
4913
|
+
}])
|
|
4927
4914
|
};
|
|
4928
4915
|
}
|
|
4929
4916
|
var withParagraphOptions = (_withParagraphOptions = {}, _withParagraphOptions[ELEMENT_PARAGRAPH] = {
|