@contentful/field-editor-rich-text 0.26.3-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 +48 -67
- 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 +49 -68
- package/dist/field-editor-rich-text.esm.js.map +1 -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 +4 -4
|
@@ -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
|
|
|
@@ -2530,11 +2514,10 @@ function AssetDropdownMenu(_ref) {
|
|
|
2530
2514
|
onRemove = _ref.onRemove,
|
|
2531
2515
|
isDisabled = _ref.isDisabled,
|
|
2532
2516
|
entityFile = _ref.entityFile;
|
|
2533
|
-
var fileName = entityFile
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
var
|
|
2537
|
-
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');
|
|
2538
2521
|
|
|
2539
2522
|
function downloadAsset() {
|
|
2540
2523
|
if (!entityFile) return;
|
|
@@ -4115,29 +4098,11 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
4115
4098
|
var editor = useContentfulEditor();
|
|
4116
4099
|
var sdk = useSdkContext();
|
|
4117
4100
|
|
|
4118
|
-
var handleClick =
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
case 0:
|
|
4124
|
-
event.preventDefault();
|
|
4125
|
-
onClose();
|
|
4126
|
-
_context.next = 4;
|
|
4127
|
-
return selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
|
|
4128
|
-
|
|
4129
|
-
case 4:
|
|
4130
|
-
case "end":
|
|
4131
|
-
return _context.stop();
|
|
4132
|
-
}
|
|
4133
|
-
}
|
|
4134
|
-
}, _callee);
|
|
4135
|
-
}));
|
|
4136
|
-
|
|
4137
|
-
return function handleClick(_x) {
|
|
4138
|
-
return _ref2.apply(this, arguments);
|
|
4139
|
-
};
|
|
4140
|
-
}();
|
|
4101
|
+
var handleClick = function handleClick(event) {
|
|
4102
|
+
event.preventDefault();
|
|
4103
|
+
onClose();
|
|
4104
|
+
selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
|
|
4105
|
+
};
|
|
4141
4106
|
|
|
4142
4107
|
var type = getEntityTypeFromNodeType(nodeType);
|
|
4143
4108
|
var baseClass = "rich-text__" + nodeType;
|
|
@@ -4755,12 +4720,18 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
|
|
|
4755
4720
|
}, children);
|
|
4756
4721
|
};
|
|
4757
4722
|
|
|
4723
|
+
var isHTMLElement = function isHTMLElement(node) {
|
|
4724
|
+
return node.nodeType === Node.ELEMENT_NODE;
|
|
4725
|
+
};
|
|
4758
4726
|
var removeChildNodes = function removeChildNodes(node, predicate) {
|
|
4727
|
+
if (predicate === void 0) {
|
|
4728
|
+
predicate = Boolean;
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4759
4731
|
return Array.from(node.childNodes).filter(predicate).forEach(function (table) {
|
|
4760
4732
|
return node.removeChild(table);
|
|
4761
4733
|
});
|
|
4762
4734
|
};
|
|
4763
|
-
|
|
4764
4735
|
var removeChildNodesUsingPredicate = function removeChildNodesUsingPredicate(predicate) {
|
|
4765
4736
|
return function (nodeList) {
|
|
4766
4737
|
var nodes = Array.from(nodeList);
|
|
@@ -4795,10 +4766,6 @@ var TAG_NAME_TABLE = 'TABLE';
|
|
|
4795
4766
|
var TAG_NAME_TABLE_CAPTION = 'CAPTION';
|
|
4796
4767
|
var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
|
|
4797
4768
|
|
|
4798
|
-
var isHTMLElement = function isHTMLElement(node) {
|
|
4799
|
-
return node.nodeType === Node.ELEMENT_NODE;
|
|
4800
|
-
};
|
|
4801
|
-
|
|
4802
4769
|
var isTableElement = function isTableElement(node) {
|
|
4803
4770
|
return isHTMLElement(node) && node.tagName === TAG_NAME_TABLE;
|
|
4804
4771
|
};
|
|
@@ -4847,12 +4814,40 @@ var sanitizeTables = function sanitizeTables(_ref) {
|
|
|
4847
4814
|
return [doc, editor];
|
|
4848
4815
|
};
|
|
4849
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
|
+
|
|
4850
4844
|
|
|
4851
4845
|
|
|
4852
4846
|
var sanitizers = {
|
|
4853
4847
|
__proto__: null,
|
|
4854
4848
|
removeComments: removeComments,
|
|
4855
|
-
sanitizeTables: sanitizeTables
|
|
4849
|
+
sanitizeTables: sanitizeTables,
|
|
4850
|
+
sanitizeEntityBlocks: sanitizeEntityBlocks
|
|
4856
4851
|
};
|
|
4857
4852
|
|
|
4858
4853
|
var MIME_TYPE_HTML = 'text/html'; // TODO: Upgrade tslib so we can just flow(...sanitizers);
|
|
@@ -4913,23 +4908,9 @@ function createParagraphPlugin() {
|
|
|
4913
4908
|
renderElement: getRenderElement(elementKeys),
|
|
4914
4909
|
pluginKeys: elementKeys,
|
|
4915
4910
|
onKeyDown: getToggleElementOnKeyDown(BLOCKS.PARAGRAPH),
|
|
4916
|
-
deserialize:
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
element: [_extends({
|
|
4920
|
-
type: BLOCKS.PARAGRAPH,
|
|
4921
|
-
deserialize: function deserialize(element) {
|
|
4922
|
-
var isParagraphText = element.nodeName === 'P';
|
|
4923
|
-
var isNotEmpty = element.textContent !== '';
|
|
4924
|
-
var isText = isParagraphText && isNotEmpty;
|
|
4925
|
-
if (!isText) return;
|
|
4926
|
-
return {
|
|
4927
|
-
type: BLOCKS.PARAGRAPH
|
|
4928
|
-
};
|
|
4929
|
-
}
|
|
4930
|
-
}, options.deserialize)]
|
|
4931
|
-
};
|
|
4932
|
-
}
|
|
4911
|
+
deserialize: deserializeElement(BLOCKS.PARAGRAPH, [{
|
|
4912
|
+
nodeNames: ['P']
|
|
4913
|
+
}])
|
|
4933
4914
|
};
|
|
4934
4915
|
}
|
|
4935
4916
|
var withParagraphOptions = (_withParagraphOptions = {}, _withParagraphOptions[ELEMENT_PARAGRAPH] = {
|