@contentful/field-editor-rich-text 0.24.1-next → 0.25.0-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,7 +1,7 @@
1
1
  import React__default, { useState, useEffect, createElement, useMemo, Fragment, useCallback } from 'react';
2
2
  import noop from 'lodash-es/noop';
3
- import { toSlatejsDocument, toContentfulDocument } from '@contentful/contentful-slatejs-adapter';
4
- import { TOP_LEVEL_BLOCKS, BLOCKS, CONTAINERS, VOID_BLOCKS, INLINES, MARKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
3
+ import { toContentfulDocument, toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
4
+ import { TOP_LEVEL_BLOCKS, BLOCKS, CONTAINERS, VOID_BLOCKS, INLINES, LIST_ITEM_BLOCKS, MARKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
5
5
  import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, EntityProvider } from '@contentful/field-editor-reference';
6
6
  import { css, cx } from 'emotion';
7
7
  import tokens from '@contentful/forma-36-tokens';
@@ -15,11 +15,12 @@ import constate from 'constate';
15
15
  import find from 'lodash-es/find';
16
16
  import flow from 'lodash-es/flow';
17
17
  import get from 'lodash-es/get';
18
- import { ELEMENT_LIC, ELEMENT_LI, ELEMENT_UL, ELEMENT_OL, toggleList, createListPlugin } from '@udecode/plate-list';
18
+ import { ELEMENT_LIC, ELEMENT_LI, ELEMENT_UL, ELEMENT_OL, createListPlugin as createListPlugin$1, toggleList } from '@udecode/plate-list';
19
19
  import { entityHelpers, isValidImage, shortenStorageUnit, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
20
20
  import moment from 'moment';
21
21
  import mimetype from '@contentful/mimetype';
22
22
  import { ELEMENT_TABLE, ELEMENT_TH, ELEMENT_TR, ELEMENT_TD, insertTable, getEmptyRowNode, getEmptyCellNode, deleteRow, deleteColumn, deleteTable, createTablePlugin as createTablePlugin$1, getTableOnKeyDown } from '@udecode/plate-table';
23
+ import { documentToPlainTextString } from '@contentful/rich-text-plain-text-renderer';
23
24
  import { createDeserializeHTMLPlugin } from '@udecode/plate-html-serializer';
24
25
  import { ELEMENT_PARAGRAPH } from '@udecode/plate-paragraph';
25
26
  import { createExitBreakPlugin } from '@udecode/plate-break';
@@ -1128,6 +1129,11 @@ var withListOptions = (_withListOptions = {}, _withListOptions[ELEMENT_LIC] = {
1128
1129
  type: BLOCKS.OL_LIST,
1129
1130
  component: OL
1130
1131
  }, _withListOptions);
1132
+ var createListPlugin = function createListPlugin() {
1133
+ return createListPlugin$1({
1134
+ validLiChildrenTypes: LIST_ITEM_BLOCKS
1135
+ });
1136
+ };
1131
1137
 
1132
1138
  var _withBoldOptions;
1133
1139
  function ToolbarBoldButton(props) {
@@ -3627,6 +3633,15 @@ var TableActions = function TableActions() {
3627
3633
 
3628
3634
  var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
3629
3635
  var styles$g = (_styles$1 = {}, _styles$1[BLOCKS.TABLE] = /*#__PURE__*/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[BLOCKS.TABLE_ROW] = /*#__PURE__*/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[BLOCKS.TABLE_HEADER_CELL] = /*#__PURE__*/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[BLOCKS.TABLE_CELL] = /*#__PURE__*/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);
3636
+
3637
+ var slateNodeToText = function slateNodeToText(node) {
3638
+ var contentfulNode = toContentfulDocument({
3639
+ document: [node],
3640
+ schema: schema
3641
+ });
3642
+ return documentToPlainTextString(contentfulNode);
3643
+ };
3644
+
3630
3645
  var Table = function Table(props) {
3631
3646
  return /*#__PURE__*/createElement("table", Object.assign({}, props.attributes, {
3632
3647
  className: styles$g[BLOCKS.TABLE]
@@ -3688,6 +3703,14 @@ function addTableTrackingEvents(editor, _ref) {
3688
3703
  };
3689
3704
  }
3690
3705
 
3706
+ var paragraph = function paragraph() {
3707
+ return {
3708
+ type: BLOCKS.PARAGRAPH,
3709
+ data: {},
3710
+ children: []
3711
+ };
3712
+ };
3713
+
3691
3714
  function addTableNormalization(editor) {
3692
3715
  var normalizeNode = editor.normalizeNode;
3693
3716
 
@@ -3706,12 +3729,20 @@ function addTableNormalization(editor) {
3706
3729
  childPath = _step$value[1];
3707
3730
 
3708
3731
  if (Text.isText(child)) {
3709
- var paragraph = {
3710
- type: BLOCKS.PARAGRAPH,
3711
- data: {},
3712
- children: []
3713
- };
3714
- Transforms.wrapNodes(editor, paragraph, {
3732
+ Transforms.wrapNodes(editor, paragraph(), {
3733
+ at: childPath
3734
+ });
3735
+ } else if (!CONTAINERS[node.type].includes(child.type)) {
3736
+ var paragraphWithTextFromNode = _extends({}, paragraph(), {
3737
+ children: [{
3738
+ text: slateNodeToText(child)
3739
+ }]
3740
+ });
3741
+
3742
+ Transforms.removeNodes(editor, {
3743
+ at: childPath
3744
+ });
3745
+ Transforms.insertNodes(editor, paragraphWithTextFromNode, {
3715
3746
  at: childPath
3716
3747
  });
3717
3748
  }
@@ -4752,7 +4783,7 @@ var removeComments = function removeComments(_ref) {
4752
4783
 
4753
4784
  var TAG_NAME_TABLE = 'TABLE';
4754
4785
  var TAG_NAME_TABLE_CAPTION = 'CAPTION';
4755
- var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE, TAG_NAME_TABLE_CAPTION];
4786
+ var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
4756
4787
 
4757
4788
  var isHTMLElement = function isHTMLElement(node) {
4758
4789
  return node.nodeType === Node.ELEMENT_NODE;