@contentful/field-editor-rich-text 0.24.1-next → 0.26.2-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.
@@ -27,6 +27,7 @@ var fieldEditorShared = require('@contentful/field-editor-shared');
27
27
  var moment = _interopDefault(require('moment'));
28
28
  var mimetype = _interopDefault(require('@contentful/mimetype'));
29
29
  var plateTable = require('@udecode/plate-table');
30
+ var richTextPlainTextRenderer = require('@contentful/rich-text-plain-text-renderer');
30
31
  var plateHtmlSerializer = require('@udecode/plate-html-serializer');
31
32
  var plateParagraph = require('@udecode/plate-paragraph');
32
33
  var plateBreak = require('@udecode/plate-break');
@@ -679,6 +680,7 @@ var VALIDATIONS = {
679
680
  ENABLED_MARKS: 'enabledMarks',
680
681
  ENABLED_NODE_TYPES: 'enabledNodeTypes'
681
682
  };
683
+ var DEFAULT_ENABLED_NODE_TYPES = [Contentful.BLOCKS.DOCUMENT, Contentful.BLOCKS.PARAGRAPH, 'text'];
682
684
 
683
685
  var getRichTextValidation = function getRichTextValidation(field, validationType) {
684
686
  return flow(function (v) {
@@ -689,13 +691,14 @@ var getRichTextValidation = function getRichTextValidation(field, validationType
689
691
  };
690
692
 
691
693
  var isFormattingOptionEnabled = function isFormattingOptionEnabled(field, validationType, nodeTypeOrMark) {
692
- var enabledFormattings = getRichTextValidation(field, validationType);
694
+ var enabledFormattings = getRichTextValidation(field, validationType); // TODO: In the future, validations will always be opt-in. In that case
695
+ // we don't need this step.
693
696
 
694
697
  if (enabledFormattings === undefined) {
695
698
  return true;
696
699
  }
697
700
 
698
- return enabledFormattings.includes(nodeTypeOrMark);
701
+ return DEFAULT_ENABLED_NODE_TYPES.concat(enabledFormattings).includes(nodeTypeOrMark);
699
702
  };
700
703
 
701
704
  var isNodeTypeEnabled = function isNodeTypeEnabled(field, nodeType) {
@@ -1135,6 +1138,11 @@ var withListOptions = (_withListOptions = {}, _withListOptions[plateList.ELEMENT
1135
1138
  type: Contentful.BLOCKS.OL_LIST,
1136
1139
  component: OL
1137
1140
  }, _withListOptions);
1141
+ var createListPlugin = function createListPlugin() {
1142
+ return plateList.createListPlugin({
1143
+ validLiChildrenTypes: Contentful.LIST_ITEM_BLOCKS
1144
+ });
1145
+ };
1138
1146
 
1139
1147
  var _withBoldOptions;
1140
1148
  function ToolbarBoldButton(props) {
@@ -2420,13 +2428,17 @@ function FetchingWrappedEntryCard(props) {
2420
2428
 
2421
2429
  var entry = entries[props.entryId];
2422
2430
  var contentType = React.useMemo(function () {
2431
+ if (!entry || entry === 'failed') {
2432
+ return undefined;
2433
+ }
2434
+
2423
2435
  return props.sdk.space.getCachedContentTypes().find(function (contentType) {
2424
- return contentType.sys.id === (entry == null ? void 0 : entry.sys.contentType.sys.id);
2436
+ return contentType.sys.id === entry.sys.contentType.sys.id;
2425
2437
  });
2426
2438
  }, [props.sdk, entry]);
2427
2439
  var defaultLocaleCode = props.sdk.locales["default"];
2428
2440
  React.useEffect(function () {
2429
- if (!entry) return;
2441
+ if (!entry || entry === 'failed') return;
2430
2442
  fieldEditorShared.entityHelpers.getEntryImage({
2431
2443
  entry: entry,
2432
2444
  contentType: contentType,
@@ -2558,13 +2570,15 @@ function AssetDropdownMenu(_ref) {
2558
2570
  }
2559
2571
 
2560
2572
  function FetchingWrappedAssetCard(props) {
2573
+ var _asset$fields;
2574
+
2561
2575
  var _useEntities = fieldEditorReference.useEntities(),
2562
2576
  getOrLoadAsset = _useEntities.getOrLoadAsset,
2563
2577
  assets = _useEntities.assets;
2564
2578
 
2565
2579
  var asset = assets[props.assetId];
2566
2580
  var defaultLocaleCode = props.sdk.locales["default"];
2567
- var entityFile = asset != null && asset.fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
2581
+ var entityFile = asset != null && (_asset$fields = asset.fields) != null && _asset$fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
2568
2582
  React.useEffect(function () {
2569
2583
  getOrLoadAsset(props.assetId);
2570
2584
  }, [props.assetId]); // eslint-disable-line
@@ -3634,6 +3648,15 @@ var TableActions = function TableActions() {
3634
3648
 
3635
3649
  var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
3636
3650
  var styles$g = (_styles$1 = {}, _styles$1[Contentful.BLOCKS.TABLE] = /*#__PURE__*/emotion.css(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 1.5em;\n border-collapse: collapse;\n border-radius: 5px;\n border-style: hidden;\n box-shadow: 0 0 0 1px ", ";\n width: 100%;\n table-layout: fixed;\n overflow: hidden;\n "])), tokens.gray400), _styles$1[Contentful.BLOCKS.TABLE_ROW] = /*#__PURE__*/emotion.css(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n &:hover td {\n background-color: transparent !important;\n }\n "])), tokens.gray400), _styles$1[Contentful.BLOCKS.TABLE_HEADER_CELL] = /*#__PURE__*/emotion.css(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: ", ";\n border: 1px solid ", ";\n padding: 10px 12px;\n font-weight: ", ";\n text-align: left;\n min-width: 48px;\n position: relative;\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray200, tokens.gray400, tokens.fontWeightMedium), _styles$1[Contentful.BLOCKS.TABLE_CELL] = /*#__PURE__*/emotion.css(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n padding: 10px 12px;\n min-width: 48px;\n position: relative;\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray400), _styles$1);
3651
+
3652
+ var slateNodeToText = function slateNodeToText(node) {
3653
+ var contentfulNode = contentfulSlatejsAdapter.toContentfulDocument({
3654
+ document: [node],
3655
+ schema: schema
3656
+ });
3657
+ return richTextPlainTextRenderer.documentToPlainTextString(contentfulNode);
3658
+ };
3659
+
3637
3660
  var Table = function Table(props) {
3638
3661
  return /*#__PURE__*/React.createElement("table", Object.assign({}, props.attributes, {
3639
3662
  className: styles$g[Contentful.BLOCKS.TABLE]
@@ -3691,10 +3714,20 @@ function addTableTrackingEvents(editor, _ref) {
3691
3714
  });
3692
3715
  }
3693
3716
  }, 1);
3717
+ } else {
3718
+ insertData(data);
3694
3719
  }
3695
3720
  };
3696
3721
  }
3697
3722
 
3723
+ var paragraph = function paragraph() {
3724
+ return {
3725
+ type: Contentful.BLOCKS.PARAGRAPH,
3726
+ data: {},
3727
+ children: []
3728
+ };
3729
+ };
3730
+
3698
3731
  function addTableNormalization(editor) {
3699
3732
  var normalizeNode = editor.normalizeNode;
3700
3733
 
@@ -3713,12 +3746,20 @@ function addTableNormalization(editor) {
3713
3746
  childPath = _step$value[1];
3714
3747
 
3715
3748
  if (slate.Text.isText(child)) {
3716
- var paragraph = {
3717
- type: Contentful.BLOCKS.PARAGRAPH,
3718
- data: {},
3719
- children: []
3720
- };
3721
- slate.Transforms.wrapNodes(editor, paragraph, {
3749
+ slate.Transforms.wrapNodes(editor, paragraph(), {
3750
+ at: childPath
3751
+ });
3752
+ } else if (!Contentful.CONTAINERS[node.type].includes(child.type)) {
3753
+ var paragraphWithTextFromNode = _extends({}, paragraph(), {
3754
+ children: [{
3755
+ text: slateNodeToText(child)
3756
+ }]
3757
+ });
3758
+
3759
+ slate.Transforms.removeNodes(editor, {
3760
+ at: childPath
3761
+ });
3762
+ slate.Transforms.insertNodes(editor, paragraphWithTextFromNode, {
3722
3763
  at: childPath
3723
3764
  });
3724
3765
  }
@@ -4269,7 +4310,7 @@ function FetchingWrappedInlineEntryCard(props) {
4269
4310
  }, [entries, props.entryId]);
4270
4311
  var allContentTypes = props.sdk.space.getCachedContentTypes();
4271
4312
  var contentType = React__default.useMemo(function () {
4272
- if (!entry || !allContentTypes) return undefined;
4313
+ if (!entry || entry === 'failed' || !allContentTypes) return undefined;
4273
4314
  return allContentTypes.find(function (contentType) {
4274
4315
  return contentType.sys.id === entry.sys.contentType.sys.id;
4275
4316
  });
@@ -4759,7 +4800,7 @@ var removeComments = function removeComments(_ref) {
4759
4800
 
4760
4801
  var TAG_NAME_TABLE = 'TABLE';
4761
4802
  var TAG_NAME_TABLE_CAPTION = 'CAPTION';
4762
- var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE, TAG_NAME_TABLE_CAPTION];
4803
+ var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
4763
4804
 
4764
4805
  var isHTMLElement = function isHTMLElement(node) {
4765
4806
  return node.nodeType === Node.ELEMENT_NODE;
@@ -4853,6 +4894,8 @@ function withPasteHandling(editor) {
4853
4894
  var sanitized = sanitizeHtml(html, editor);
4854
4895
  var newData = htmlToDataTransfer(sanitized);
4855
4896
  insertData(newData);
4897
+ } else {
4898
+ insertData(data);
4856
4899
  }
4857
4900
  };
4858
4901
  };
@@ -5049,7 +5092,7 @@ var getPlugins = function getPlugins(sdk, tracking) {
5049
5092
  plateCore.createReactPlugin(), plateCore.createHistoryPlugin(), // Behavior
5050
5093
  createPastePlugin(), // Global shortcuts
5051
5094
  createNewLinePlugin(), createInsertBeforeFirstVoidBlockPlugin(), // Block Elements
5052
- createParagraphPlugin(), plateList.createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
5095
+ createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
5053
5096
  createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
5054
5097
  createBoldPlugin(), createCodePlugin(), createItalicPlugin(), createUnderlinePlugin(), // Other
5055
5098
  createTrailingParagraphPlugin()];