@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.
@@ -1,8 +1,8 @@
1
- import * as React from 'react';
1
+ /// <reference types="react" />
2
2
  import { FieldExtensionSDK } from '@contentful/app-sdk';
3
3
  export declare function getContentfulEditorId(sdk: FieldExtensionSDK): string;
4
4
  interface useContentfulEditorHookProps {
5
5
  sdk: FieldExtensionSDK;
6
6
  }
7
- export declare const ContentfulEditorProvider: React.FC<useContentfulEditorHookProps>, useContentfulEditor: any;
7
+ export declare const ContentfulEditorProvider: import("react").FC<useContentfulEditorHookProps>, useContentfulEditor: any;
8
8
  export {};
@@ -551,25 +551,9 @@ function getContentfulEditorId(sdk) {
551
551
  }
552
552
 
553
553
  function useContentfulEditorHook(_ref) {
554
- var _editor$selection;
555
-
556
554
  var sdk = _ref.sdk;
557
555
  var editorId = getContentfulEditorId(sdk);
558
556
  var editor = plateCore.useStoreEditorRef(editorId);
559
-
560
- var _React$useState = React.useState((_editor$selection = editor == null ? void 0 : editor.selection) != null ? _editor$selection : null),
561
- selection = _React$useState[0],
562
- setSelection = _React$useState[1];
563
-
564
- React.useEffect(function () {
565
- if (!(editor != null && editor.selection)) return;
566
- setSelection(editor.selection);
567
- }, [editor == null ? void 0 : editor.selection]);
568
-
569
- if (editor && !(editor != null && editor.selection) && selection) {
570
- editor.selection = selection;
571
- }
572
-
573
557
  return editor;
574
558
  }
575
559
 
@@ -2537,11 +2521,10 @@ function AssetDropdownMenu(_ref) {
2537
2521
  onRemove = _ref.onRemove,
2538
2522
  isDisabled = _ref.isDisabled,
2539
2523
  entityFile = _ref.entityFile;
2540
- var fileName = entityFile.fileName,
2541
- mimeType = entityFile.contentType,
2542
- details = entityFile.details;
2543
- var fileSize = details.size,
2544
- image = details.image;
2524
+ var fileName = get(entityFile, 'fileName');
2525
+ var fileSize = get(entityFile, 'details.size');
2526
+ var image = get(entityFile, 'details.image');
2527
+ var mimeType = get(entityFile, 'contentType');
2545
2528
 
2546
2529
  function downloadAsset() {
2547
2530
  if (!entityFile) return;
@@ -4122,29 +4105,11 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
4122
4105
  var editor = useContentfulEditor();
4123
4106
  var sdk = useSdkContext();
4124
4107
 
4125
- var handleClick = /*#__PURE__*/function () {
4126
- var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
4127
- return runtime_1.wrap(function _callee$(_context) {
4128
- while (1) {
4129
- switch (_context.prev = _context.next) {
4130
- case 0:
4131
- event.preventDefault();
4132
- onClose();
4133
- _context.next = 4;
4134
- return selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
4135
-
4136
- case 4:
4137
- case "end":
4138
- return _context.stop();
4139
- }
4140
- }
4141
- }, _callee);
4142
- }));
4143
-
4144
- return function handleClick(_x) {
4145
- return _ref2.apply(this, arguments);
4146
- };
4147
- }();
4108
+ var handleClick = function handleClick(event) {
4109
+ event.preventDefault();
4110
+ onClose();
4111
+ selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
4112
+ };
4148
4113
 
4149
4114
  var type = getEntityTypeFromNodeType(nodeType);
4150
4115
  var baseClass = "rich-text__" + nodeType;
@@ -4762,12 +4727,18 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
4762
4727
  }, children);
4763
4728
  };
4764
4729
 
4730
+ var isHTMLElement = function isHTMLElement(node) {
4731
+ return node.nodeType === Node.ELEMENT_NODE;
4732
+ };
4765
4733
  var removeChildNodes = function removeChildNodes(node, predicate) {
4734
+ if (predicate === void 0) {
4735
+ predicate = Boolean;
4736
+ }
4737
+
4766
4738
  return Array.from(node.childNodes).filter(predicate).forEach(function (table) {
4767
4739
  return node.removeChild(table);
4768
4740
  });
4769
4741
  };
4770
-
4771
4742
  var removeChildNodesUsingPredicate = function removeChildNodesUsingPredicate(predicate) {
4772
4743
  return function (nodeList) {
4773
4744
  var nodes = Array.from(nodeList);
@@ -4802,10 +4773,6 @@ var TAG_NAME_TABLE = 'TABLE';
4802
4773
  var TAG_NAME_TABLE_CAPTION = 'CAPTION';
4803
4774
  var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
4804
4775
 
4805
- var isHTMLElement = function isHTMLElement(node) {
4806
- return node.nodeType === Node.ELEMENT_NODE;
4807
- };
4808
-
4809
4776
  var isTableElement = function isTableElement(node) {
4810
4777
  return isHTMLElement(node) && node.tagName === TAG_NAME_TABLE;
4811
4778
  };
@@ -4854,12 +4821,40 @@ var sanitizeTables = function sanitizeTables(_ref) {
4854
4821
  return [doc, editor];
4855
4822
  };
4856
4823
 
4824
+ /**
4825
+ * Ensures the text selection from entity block elements is
4826
+ * not included in the paste buffer.
4827
+ */
4828
+
4829
+ var sanitizeEntityBlocks = function sanitizeEntityBlocks(_ref) {
4830
+ var doc = _ref[0],
4831
+ editor = _ref[1];
4832
+ var nodes = Array.from(doc.childNodes);
4833
+
4834
+ while (nodes.length > 0) {
4835
+ var node = nodes.pop();
4836
+
4837
+ if (isHTMLElement(node) && node.getAttribute('data-entity-type')) {
4838
+ removeChildNodes(node);
4839
+ continue;
4840
+ }
4841
+
4842
+ for (var _i = 0, _Array$from = Array.from(node.childNodes); _i < _Array$from.length; _i++) {
4843
+ var childNode = _Array$from[_i];
4844
+ nodes.push(childNode);
4845
+ }
4846
+ }
4847
+
4848
+ return [doc, editor];
4849
+ };
4850
+
4857
4851
 
4858
4852
 
4859
4853
  var sanitizers = {
4860
4854
  __proto__: null,
4861
4855
  removeComments: removeComments,
4862
- sanitizeTables: sanitizeTables
4856
+ sanitizeTables: sanitizeTables,
4857
+ sanitizeEntityBlocks: sanitizeEntityBlocks
4863
4858
  };
4864
4859
 
4865
4860
  var MIME_TYPE_HTML = 'text/html'; // TODO: Upgrade tslib so we can just flow(...sanitizers);
@@ -4920,23 +4915,9 @@ function createParagraphPlugin() {
4920
4915
  renderElement: plateCore.getRenderElement(elementKeys),
4921
4916
  pluginKeys: elementKeys,
4922
4917
  onKeyDown: plateCommon.getToggleElementOnKeyDown(Contentful.BLOCKS.PARAGRAPH),
4923
- deserialize: function deserialize(editor) {
4924
- var options = plateCore.getPlatePluginOptions(editor, Contentful.BLOCKS.PARAGRAPH);
4925
- return {
4926
- element: [_extends({
4927
- type: Contentful.BLOCKS.PARAGRAPH,
4928
- deserialize: function deserialize(element) {
4929
- var isParagraphText = element.nodeName === 'P';
4930
- var isNotEmpty = element.textContent !== '';
4931
- var isText = isParagraphText && isNotEmpty;
4932
- if (!isText) return;
4933
- return {
4934
- type: Contentful.BLOCKS.PARAGRAPH
4935
- };
4936
- }
4937
- }, options.deserialize)]
4938
- };
4939
- }
4918
+ deserialize: deserializeElement(Contentful.BLOCKS.PARAGRAPH, [{
4919
+ nodeNames: ['P']
4920
+ }])
4940
4921
  };
4941
4922
  }
4942
4923
  var withParagraphOptions = (_withParagraphOptions = {}, _withParagraphOptions[plateParagraph.ELEMENT_PARAGRAPH] = {