@contentful/field-editor-rich-text 2.0.0-next.31 → 2.0.0-next.34

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.
@@ -5628,210 +5628,6 @@ function SlashCommandsPalette(_ref2) {
5628
5628
  }, /*#__PURE__*/React.createElement(f36Components.Card, null, /*#__PURE__*/React.createElement(f36Components.Text, null, "Slash commands are temporarily unavailable.")));
5629
5629
  }
5630
5630
 
5631
- function insertTableAndFocusFirstCell(editor) {
5632
- plateTable.insertTable(editor, {
5633
- header: true
5634
- });
5635
- replaceEmptyParagraphWithTable(editor);
5636
- }
5637
- function isTableActive(editor) {
5638
- var tableElements = [plateTable.ELEMENT_TABLE, plateTable.ELEMENT_TH, plateTable.ELEMENT_TR, plateTable.ELEMENT_TD];
5639
- return tableElements.some(function (el) {
5640
- return isBlockSelected(editor, el);
5641
- });
5642
- }
5643
- function isTableHeaderEnabled(editor) {
5644
- var tableItem = plateCore.getAbove(editor, {
5645
- match: {
5646
- type: Contentful.BLOCKS.TABLE
5647
- }
5648
- });
5649
-
5650
- if (!tableItem) {
5651
- return false;
5652
- }
5653
-
5654
- var firstRow = plateCore.getChildren(tableItem)[0];
5655
-
5656
- if (!firstRow) {
5657
- return false;
5658
- }
5659
-
5660
- return plateCore.getChildren(firstRow).every(function (_ref) {
5661
- var node = _ref[0];
5662
- return node.type === Contentful.BLOCKS.TABLE_HEADER_CELL;
5663
- });
5664
- }
5665
- function replaceEmptyParagraphWithTable(editor) {
5666
- var tablePath = getAncestorPathFromSelection(editor);
5667
- if (!tablePath || plateCore.isFirstChild(tablePath)) return;
5668
- var previousPath = slate.Path.previous(tablePath);
5669
- if (!previousPath) return;
5670
-
5671
- var _Editor$nodes = slate.Editor.nodes(editor, {
5672
- at: previousPath,
5673
- match: function match(node) {
5674
- return node.type === Contentful.BLOCKS.PARAGRAPH;
5675
- }
5676
- }),
5677
- nodes = _Editor$nodes[0];
5678
-
5679
- if (!nodes) return;
5680
- var previousNode = nodes[0];
5681
- var isPreviousNodeTextEmpty = plateCore.isAncestorEmpty(editor, previousNode);
5682
-
5683
- if (isPreviousNodeTextEmpty) {
5684
- // Switch table with previous empty paragraph
5685
- slate.Transforms.moveNodes(editor, {
5686
- at: tablePath,
5687
- to: previousPath
5688
- }); // Remove previous paragraph that now is under the table
5689
-
5690
- slate.Transforms.removeNodes(editor, {
5691
- at: tablePath
5692
- });
5693
- }
5694
- }
5695
- /**
5696
- * Returns the number of cells in a given row vs the table width
5697
- *
5698
- * Note: We should only get different table rows cell counts in between
5699
- * normalization cycles.
5700
- */
5701
-
5702
- var getNoOfMissingTableCellsInRow = function getNoOfMissingTableCellsInRow(editor, _ref2) {
5703
- var rowPath = _ref2[1];
5704
- var parent = plateCore.getParent(editor, rowPath); // This is ensured by normalization. The error is here just in case
5705
-
5706
- if (!parent) {
5707
- throw new Error('table rows must be wrapped in a table node');
5708
- }
5709
-
5710
- var tablePath = parent[1]; // The longest table row determines its width
5711
-
5712
- var tableWidth = Math.max.apply(Math, Array.from(slate.Node.children(editor, tablePath)).map(function (_ref3) {
5713
- var path = _ref3[1];
5714
- return Array.from(slate.Node.children(editor, path)).length;
5715
- }));
5716
- var rowWidth = Array.from(slate.Node.children(editor, rowPath)).length;
5717
- return tableWidth - rowWidth;
5718
- };
5719
- var createEmptyTableCells = function createEmptyTableCells(count) {
5720
- var emptyTableCell = {
5721
- type: Contentful.BLOCKS.TABLE_CELL,
5722
- data: {},
5723
- children: [{
5724
- type: Contentful.BLOCKS.PARAGRAPH,
5725
- data: {},
5726
- children: [{
5727
- text: ''
5728
- }]
5729
- }]
5730
- };
5731
- return new Array(count).fill(emptyTableCell);
5732
- };
5733
- var isNotEmpty = function isNotEmpty(editor, _ref4) {
5734
- var path = _ref4[1];
5735
- return Array.from(slate.Node.children(editor, path)).length !== 0;
5736
- };
5737
- var isTable = function isTable(node) {
5738
- return slate.Element.isElement(node) && node.type === Contentful.BLOCKS.TABLE;
5739
- };
5740
-
5741
- function hasTables(nodes) {
5742
- return nodes.some(function (_ref) {
5743
- var type = _ref.type;
5744
- return type === Contentful.BLOCKS.TABLE;
5745
- });
5746
- }
5747
-
5748
- var isTableHeaderCell = function isTableHeaderCell(_ref2) {
5749
- var type = _ref2.type;
5750
- return type === Contentful.BLOCKS.TABLE_HEADER_CELL;
5751
- };
5752
-
5753
- var isTableCellOrHeader = function isTableCellOrHeader(node) {
5754
- return slate.Element.isElement(node) && [Contentful.BLOCKS.TABLE_HEADER_CELL, Contentful.BLOCKS.TABLE_CELL].includes(node.type);
5755
- };
5756
-
5757
- function hasHeadersOutsideFirstRow(nodes) {
5758
- return nodes.filter(function (_ref3) {
5759
- var type = _ref3.type;
5760
- return type === Contentful.BLOCKS.TABLE;
5761
- }).flatMap(function (_ref4) {
5762
- var children = _ref4.children;
5763
- return children.slice(1);
5764
- }).some(function (_ref5) {
5765
- var children = _ref5.children;
5766
- return children.some(isTableHeaderCell);
5767
- });
5768
- }
5769
-
5770
- function trackInvalidTableCellChildren(editor, table) {
5771
- var cells = table.children.flatMap(function (row) {
5772
- var _row$children;
5773
-
5774
- return (_row$children = row.children) != null ? _row$children : [];
5775
- }).filter(isTableCellOrHeader); // get invalid direct children
5776
-
5777
- var invalidNodeTypes = cells.flatMap(function (cell) {
5778
- // Only paragraphs are allowed inside tables at the moment
5779
- return cell.children.filter(function (node) {
5780
- return slate.Element.isElement(node) && node.type !== Contentful.BLOCKS.PARAGRAPH;
5781
- }).map(function (node) {
5782
- return node.type;
5783
- });
5784
- });
5785
-
5786
- for (var _iterator = _createForOfIteratorHelperLoose(new Set(invalidNodeTypes)), _step; !(_step = _iterator()).done;) {
5787
- var _editor$tracking;
5788
-
5789
- var nodeType = _step.value;
5790
- (_editor$tracking = editor.tracking) == null ? void 0 : _editor$tracking.onViewportAction('invalidTablePaste', {
5791
- nodeType: nodeType
5792
- });
5793
- }
5794
- }
5795
-
5796
- function addTableTrackingEvents(editor) {
5797
- var insertData = editor.insertData;
5798
-
5799
- editor.insertData = function (data) {
5800
- var html = data.getData('text/html');
5801
-
5802
- if (html) {
5803
- var markupBefore = editor.children;
5804
- insertData(data);
5805
- var markupAfter = editor.children;
5806
- setTimeout(function () {
5807
- if (hasTables(markupBefore)) return;
5808
-
5809
- if (hasTables(markupAfter)) {
5810
- editor.tracking.onViewportAction('paste', {
5811
- tablePasted: true,
5812
- hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
5813
- });
5814
- }
5815
- }, 1);
5816
- } else {
5817
- insertData(data);
5818
- }
5819
- };
5820
-
5821
- var insertFragment = editor.insertFragment;
5822
-
5823
- editor.insertFragment = function (fragment) {
5824
- var tables = fragment.filter(isTable);
5825
-
5826
- for (var _iterator2 = _createForOfIteratorHelperLoose(tables), _step2; !(_step2 = _iterator2()).done;) {
5827
- var table = _step2.value;
5828
- trackInvalidTableCellChildren(editor, table);
5829
- }
5830
-
5831
- return insertFragment(fragment);
5832
- };
5833
- }
5834
-
5835
5631
  var addRow = function addRow(editor, getNextRowPath) {
5836
5632
  if (plateCore.someNode(editor, {
5837
5633
  match: {
@@ -5951,47 +5747,157 @@ var setHeader = function setHeader(editor, enable) {
5951
5747
  });
5952
5748
  };
5953
5749
 
5954
- var styles$i = {
5955
- topRight: /*#__PURE__*/emotion.css({
5956
- position: 'absolute',
5957
- top: '6px',
5958
- right: '5px'
5959
- })
5960
- };
5961
-
5962
- var getCurrentTableSize = function getCurrentTableSize(editor) {
5963
- var _getNodeEntryFromSele = getNodeEntryFromSelection(editor, Contentful.BLOCKS.TABLE),
5964
- table = _getNodeEntryFromSele[0];
5750
+ function insertTableAndFocusFirstCell(editor) {
5751
+ plateTable.insertTable(editor, {
5752
+ header: true
5753
+ });
5754
+ replaceEmptyParagraphWithTable(editor);
5755
+ }
5756
+ function isTableActive(editor) {
5757
+ var tableElements = [plateTable.ELEMENT_TABLE, plateTable.ELEMENT_TH, plateTable.ELEMENT_TR, plateTable.ELEMENT_TD];
5758
+ return tableElements.some(function (el) {
5759
+ return isBlockSelected(editor, el);
5760
+ });
5761
+ }
5762
+ function isTableHeaderEnabled(editor) {
5763
+ var tableItem = plateCore.getAbove(editor, {
5764
+ match: {
5765
+ type: Contentful.BLOCKS.TABLE
5766
+ }
5767
+ });
5965
5768
 
5966
- return table ? getTableSize(table) : null;
5967
- };
5769
+ if (!tableItem) {
5770
+ return false;
5771
+ }
5968
5772
 
5969
- var TableActions = function TableActions() {
5970
- var editor = useContentfulEditor();
5971
- var isDisabled = Slate.useReadOnly();
5773
+ var firstRow = plateCore.getChildren(tableItem)[0];
5972
5774
 
5973
- var _React$useState = React__default.useState(false),
5974
- isOpen = _React$useState[0],
5975
- setOpen = _React$useState[1];
5775
+ if (!firstRow) {
5776
+ return false;
5777
+ }
5976
5778
 
5977
- var _React$useState2 = React__default.useState(false),
5978
- isHeaderEnabled = _React$useState2[0],
5979
- setHeaderEnabled = _React$useState2[1];
5779
+ return plateCore.getChildren(firstRow).every(function (_ref) {
5780
+ var node = _ref[0];
5781
+ return node.type === Contentful.BLOCKS.TABLE_HEADER_CELL;
5782
+ });
5783
+ }
5784
+ function replaceEmptyParagraphWithTable(editor) {
5785
+ var tablePath = getAncestorPathFromSelection(editor);
5786
+ if (!tablePath || plateCore.isFirstChild(tablePath)) return;
5787
+ var previousPath = slate.Path.previous(tablePath);
5788
+ if (!previousPath) return;
5980
5789
 
5981
- var close = React__default.useCallback(function () {
5982
- setOpen(false);
5983
- }, []);
5984
- React__default.useEffect(function () {
5985
- setHeaderEnabled(Boolean(editor && isTableHeaderEnabled(editor)));
5986
- }, [editor]);
5987
- var canInsertRowAbove = React__default.useMemo(function () {
5988
- if (!editor) {
5989
- return false;
5790
+ var _Editor$nodes = slate.Editor.nodes(editor, {
5791
+ at: previousPath,
5792
+ match: function match(node) {
5793
+ return node.type === Contentful.BLOCKS.PARAGRAPH;
5990
5794
  }
5795
+ }),
5796
+ nodes = _Editor$nodes[0];
5991
5797
 
5992
- var headerCell = plateCore.getAbove(editor, {
5993
- match: {
5994
- type: Contentful.BLOCKS.TABLE_HEADER_CELL
5798
+ if (!nodes) return;
5799
+ var previousNode = nodes[0];
5800
+ var isPreviousNodeTextEmpty = plateCore.isAncestorEmpty(editor, previousNode);
5801
+
5802
+ if (isPreviousNodeTextEmpty) {
5803
+ // Switch table with previous empty paragraph
5804
+ slate.Transforms.moveNodes(editor, {
5805
+ at: tablePath,
5806
+ to: previousPath
5807
+ }); // Remove previous paragraph that now is under the table
5808
+
5809
+ slate.Transforms.removeNodes(editor, {
5810
+ at: tablePath
5811
+ });
5812
+ }
5813
+ }
5814
+ /**
5815
+ * Returns the number of cells in a given row vs the table width
5816
+ *
5817
+ * Note: We should only get different table rows cell counts in between
5818
+ * normalization cycles.
5819
+ */
5820
+
5821
+ var getNoOfMissingTableCellsInRow = function getNoOfMissingTableCellsInRow(editor, _ref2) {
5822
+ var rowPath = _ref2[1];
5823
+ var parent = plateCore.getParent(editor, rowPath); // This is ensured by normalization. The error is here just in case
5824
+
5825
+ if (!parent) {
5826
+ throw new Error('table rows must be wrapped in a table node');
5827
+ }
5828
+
5829
+ var tablePath = parent[1]; // The longest table row determines its width
5830
+
5831
+ var tableWidth = Math.max.apply(Math, Array.from(slate.Node.children(editor, tablePath)).map(function (_ref3) {
5832
+ var path = _ref3[1];
5833
+ return Array.from(slate.Node.children(editor, path)).length;
5834
+ }));
5835
+ var rowWidth = Array.from(slate.Node.children(editor, rowPath)).length;
5836
+ return tableWidth - rowWidth;
5837
+ };
5838
+ var createEmptyTableCells = function createEmptyTableCells(count) {
5839
+ var emptyTableCell = {
5840
+ type: Contentful.BLOCKS.TABLE_CELL,
5841
+ data: {},
5842
+ children: [{
5843
+ type: Contentful.BLOCKS.PARAGRAPH,
5844
+ data: {},
5845
+ children: [{
5846
+ text: ''
5847
+ }]
5848
+ }]
5849
+ };
5850
+ return new Array(count).fill(emptyTableCell);
5851
+ };
5852
+ var isNotEmpty = function isNotEmpty(editor, _ref4) {
5853
+ var path = _ref4[1];
5854
+ return Array.from(slate.Node.children(editor, path)).length !== 0;
5855
+ };
5856
+ var isTable = function isTable(node) {
5857
+ return slate.Element.isElement(node) && node.type === Contentful.BLOCKS.TABLE;
5858
+ };
5859
+
5860
+ var styles$i = {
5861
+ topRight: /*#__PURE__*/emotion.css({
5862
+ position: 'absolute',
5863
+ top: '6px',
5864
+ right: '5px'
5865
+ })
5866
+ };
5867
+
5868
+ var getCurrentTableSize = function getCurrentTableSize(editor) {
5869
+ var _getNodeEntryFromSele = getNodeEntryFromSelection(editor, Contentful.BLOCKS.TABLE),
5870
+ table = _getNodeEntryFromSele[0];
5871
+
5872
+ return table ? getTableSize(table) : null;
5873
+ };
5874
+
5875
+ var TableActions = function TableActions() {
5876
+ var editor = useContentfulEditor();
5877
+ var isDisabled = Slate.useReadOnly();
5878
+
5879
+ var _React$useState = React__default.useState(false),
5880
+ isOpen = _React$useState[0],
5881
+ setOpen = _React$useState[1];
5882
+
5883
+ var _React$useState2 = React__default.useState(false),
5884
+ isHeaderEnabled = _React$useState2[0],
5885
+ setHeaderEnabled = _React$useState2[1];
5886
+
5887
+ var close = React__default.useCallback(function () {
5888
+ setOpen(false);
5889
+ }, []);
5890
+ React__default.useEffect(function () {
5891
+ setHeaderEnabled(Boolean(editor && isTableHeaderEnabled(editor)));
5892
+ }, [editor]);
5893
+ var canInsertRowAbove = React__default.useMemo(function () {
5894
+ if (!editor) {
5895
+ return false;
5896
+ }
5897
+
5898
+ var headerCell = plateCore.getAbove(editor, {
5899
+ match: {
5900
+ type: Contentful.BLOCKS.TABLE_HEADER_CELL
5995
5901
  }
5996
5902
  });
5997
5903
  return !headerCell;
@@ -6074,7 +5980,7 @@ var Cell = function Cell(props) {
6074
5980
  };
6075
5981
 
6076
5982
  var _templateObject$8;
6077
- var style$4 = /*#__PURE__*/emotion.css(_templateObject$8 || (_templateObject$8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: ", ";\n border: 1px solid ", ";\n border-collapse: collapse;\n padding: 10px 12px;\n font-weight: ", ";\n text-align: left;\n min-width: 48px;\n position: relative;\n\n div:last-child {\n margin-bottom: 0;\n }\n"])), tokens.gray200, tokens.gray400, tokens.fontWeightNormal);
5983
+ var style$4 = /*#__PURE__*/emotion.css(_templateObject$8 || (_templateObject$8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-clip: padding-box;\n background-color: ", ";\n border: 1px solid ", ";\n border-collapse: collapse;\n padding: 10px 12px;\n font-weight: ", ";\n text-align: left;\n min-width: 48px;\n position: relative;\n\n div:last-child {\n margin-bottom: 0;\n }\n"])), tokens.gray200, tokens.gray400, tokens.fontWeightNormal);
6078
5984
  var HeaderCell = function HeaderCell(props) {
6079
5985
  var isSelected = Slate.useSelected();
6080
5986
  return /*#__PURE__*/React.createElement("th", Object.assign({}, props.attributes, props.element.data, {
@@ -6167,57 +6073,347 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
6167
6073
  // This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
6168
6074
  var windowSelection = window.getSelection();
6169
6075
 
6170
- if (windowSelection) {
6171
- var _windowSelection$anch, _windowSelection$anch2;
6076
+ if (windowSelection) {
6077
+ var _windowSelection$anch, _windowSelection$anch2;
6078
+
6079
+ // @ts-expect-error
6080
+ var blockType = (_windowSelection$anch = windowSelection.anchorNode.attributes) == null ? void 0 : (_windowSelection$anch2 = _windowSelection$anch['data-block-type']) == null ? void 0 : _windowSelection$anch2.value; // this attribute comes from `plugins/Table/components/Table.tsx`
6081
+
6082
+ var isBeforeTable = blockType === Contentful.BLOCKS.TABLE;
6083
+
6084
+ if (isBeforeTable) {
6085
+ if (event.key === 'Enter') {
6086
+ var above = plateCore.getAbove(editor, {
6087
+ match: {
6088
+ type: Contentful.BLOCKS.TABLE
6089
+ }
6090
+ });
6091
+ if (!above) return;
6092
+ var tablePath = above[1];
6093
+ insertEmptyParagraph(editor, {
6094
+ at: tablePath,
6095
+ select: true
6096
+ });
6097
+ }
6098
+
6099
+ event.preventDefault();
6100
+ event.stopPropagation();
6101
+ return;
6102
+ }
6103
+ } // Pressing Tab on the last cell creates a new row
6104
+ // Otherwise, jumping between cells is handled in the defaultKeyDownTable
6105
+
6106
+
6107
+ if (event.key === 'Tab' && !event.shiftKey) {
6108
+ event.preventDefault();
6109
+ var res = plateTable.getTableCellEntry(editor, {});
6110
+
6111
+ if (res) {
6112
+ var tableElement = res.tableElement,
6113
+ tableRow = res.tableRow,
6114
+ tableCell = res.tableCell;
6115
+ var isLastCell = plateCore.isLastChild(tableRow, tableCell[1]);
6116
+ var isLastRow = plateCore.isLastChild(tableElement, tableRow[1]);
6117
+
6118
+ if (isLastRow && isLastCell) {
6119
+ addRowBelow(editor); // skip default handler
6120
+
6121
+ return;
6122
+ }
6123
+ }
6124
+ }
6125
+
6126
+ defaultHandler(event);
6127
+ };
6128
+ };
6129
+
6130
+ var _extends2, _extends4, _inlines;
6131
+ var inlines = /*#__PURE__*/Object.values(Contentful.INLINES).map(function (type) {
6132
+ return {
6133
+ type: type
6134
+ };
6135
+ });
6136
+ var schema = {
6137
+ document: {
6138
+ nodes: [{
6139
+ types: /*#__PURE__*/Contentful.TOP_LEVEL_BLOCKS.map(function (type) {
6140
+ return {
6141
+ type: type
6142
+ };
6143
+ })
6144
+ }]
6145
+ },
6146
+ blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[Contentful.BLOCKS.PARAGRAPH] = {
6147
+ nodes: [{
6148
+ match: /*#__PURE__*/[].concat(inlines, [{
6149
+ object: 'text'
6150
+ }])
6151
+ }]
6152
+ }, _extends2[Contentful.BLOCKS.HEADING_1] = {
6153
+ nodes: [{
6154
+ match: /*#__PURE__*/[].concat(inlines, [{
6155
+ object: 'text'
6156
+ }])
6157
+ }]
6158
+ }, _extends2[Contentful.BLOCKS.HEADING_2] = {
6159
+ nodes: [{
6160
+ match: /*#__PURE__*/[].concat(inlines, [{
6161
+ object: 'text'
6162
+ }])
6163
+ }]
6164
+ }, _extends2[Contentful.BLOCKS.HEADING_3] = {
6165
+ nodes: [{
6166
+ match: /*#__PURE__*/[].concat(inlines, [{
6167
+ object: 'text'
6168
+ }])
6169
+ }]
6170
+ }, _extends2[Contentful.BLOCKS.HEADING_4] = {
6171
+ nodes: [{
6172
+ match: /*#__PURE__*/[].concat(inlines, [{
6173
+ object: 'text'
6174
+ }])
6175
+ }]
6176
+ }, _extends2[Contentful.BLOCKS.HEADING_5] = {
6177
+ nodes: [{
6178
+ match: /*#__PURE__*/[].concat(inlines, [{
6179
+ object: 'text'
6180
+ }])
6181
+ }]
6182
+ }, _extends2[Contentful.BLOCKS.HEADING_6] = {
6183
+ nodes: [{
6184
+ match: /*#__PURE__*/[].concat(inlines, [{
6185
+ object: 'text'
6186
+ }])
6187
+ }]
6188
+ }, _extends2), /*#__PURE__*/Contentful.VOID_BLOCKS.reduce(function (blocks, nodeType) {
6189
+ var _extends3;
6190
+
6191
+ return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
6192
+ isVoid: true
6193
+ }, _extends3));
6194
+ }, {}), (_extends4 = {}, _extends4[Contentful.BLOCKS.QUOTE] = {
6195
+ nodes: [{
6196
+ match: [/*#__PURE__*/Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE].map(function (type) {
6197
+ return {
6198
+ type: type
6199
+ };
6200
+ })],
6201
+ min: 1
6202
+ }],
6203
+ normalize: function normalize(editor, error) {
6204
+ if (error.code === 'child_type_invalid') {
6205
+ return editor.unwrapBlockByKey(error.node.key, Contentful.BLOCKS.QUOTE);
6206
+ }
6207
+ }
6208
+ }, _extends4)),
6209
+ inlines: (_inlines = {}, _inlines[Contentful.INLINES.HYPERLINK] = {
6210
+ nodes: [{
6211
+ match: [{
6212
+ object: 'text'
6213
+ }]
6214
+ }]
6215
+ }, _inlines[Contentful.INLINES.ENTRY_HYPERLINK] = {
6216
+ nodes: [{
6217
+ match: [{
6218
+ object: 'text'
6219
+ }]
6220
+ }]
6221
+ }, _inlines[Contentful.INLINES.ASSET_HYPERLINK] = {
6222
+ nodes: [{
6223
+ match: [{
6224
+ object: 'text'
6225
+ }]
6226
+ }]
6227
+ }, _inlines[Contentful.INLINES.EMBEDDED_ENTRY] = {
6228
+ isVoid: true
6229
+ }, _inlines)
6230
+ };
6231
+
6232
+ function getCharacterCount(editor) {
6233
+ var document = contentfulSlateJSAdapter.toContentfulDocument({
6234
+ document: editor.children,
6235
+ schema: schema
6236
+ });
6237
+ return richTextPlainTextRenderer.documentToPlainTextString(document).length;
6238
+ }
6239
+
6240
+ var actionOrigin = {
6241
+ TOOLBAR: 'toolbar-icon',
6242
+ SHORTCUT: 'shortcut',
6243
+ VIEWPORT: 'viewport-interaction',
6244
+ COMMAND_PALETTE: 'command-palette'
6245
+ };
6246
+ function getPastingSource(data) {
6247
+ var textHtml = data.getData('text/html');
6248
+ var doc = new DOMParser().parseFromString(textHtml, 'text/html');
6249
+
6250
+ if (doc.querySelector('[id*="docs-internal-guid"]')) {
6251
+ return 'Google Docs';
6252
+ }
6253
+
6254
+ if (doc.querySelector('google-sheets-html-origin') || doc.querySelector('[data-sheets-value]')) {
6255
+ return 'Google Spreadsheets';
6256
+ }
6257
+
6258
+ if (doc.querySelector('meta[content*="Microsoft Excel"]')) {
6259
+ return 'Microsoft Excel';
6260
+ }
6261
+
6262
+ if (doc.querySelector('meta[content*="Microsoft Word"]')) {
6263
+ return 'Microsoft Word';
6264
+ } // TODO: MS Word Online doesn't give us specific tags, we might need to have a closer look at its tracking result since we are using generic values to identify it
6265
+
6266
+
6267
+ if (doc.querySelector('[style*="Arial_MSFontService"]') && (doc.querySelector('.TextRun') || doc.querySelector('.OutlineElement'))) {
6268
+ return 'Microsoft Word Online';
6269
+ }
6270
+
6271
+ if (doc.querySelector('meta[content="Cocoa HTML Writer"]')) {
6272
+ return 'Apple Notes';
6273
+ }
6274
+
6275
+ if (doc.querySelector('[style*="Slack-Lato, Slack-Fractions"]')) {
6276
+ return 'Slack';
6277
+ }
6278
+
6279
+ return 'Unknown';
6280
+ }
6281
+ var createTrackingPlugin = function createTrackingPlugin(onAction) {
6282
+ var trackingActions = {
6283
+ onViewportAction: function onViewportAction(actionName, data) {
6284
+ if (data === void 0) {
6285
+ data = {};
6286
+ }
6287
+
6288
+ return onAction(actionName, _extends({
6289
+ origin: actionOrigin.VIEWPORT
6290
+ }, data));
6291
+ },
6292
+ onShortcutAction: function onShortcutAction(actionName, data) {
6293
+ if (data === void 0) {
6294
+ data = {};
6295
+ }
6296
+
6297
+ return onAction(actionName, _extends({
6298
+ origin: actionOrigin.SHORTCUT
6299
+ }, data));
6300
+ },
6301
+ onToolbarAction: function onToolbarAction(actionName, data) {
6302
+ if (data === void 0) {
6303
+ data = {};
6304
+ }
6305
+
6306
+ return onAction(actionName, _extends({
6307
+ origin: actionOrigin.TOOLBAR
6308
+ }, data));
6309
+ },
6310
+ onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
6311
+ if (data === void 0) {
6312
+ data = {};
6313
+ }
6314
+
6315
+ return onAction(actionName, _extends({
6316
+ origin: actionOrigin.COMMAND_PALETTE
6317
+ }, data));
6318
+ }
6319
+ };
6320
+ return {
6321
+ key: 'TrackingPlugin',
6322
+ withOverrides: function withOverrides(editor) {
6323
+ var insertData = editor.insertData;
6324
+ editor.tracking = trackingActions;
6325
+
6326
+ editor.insertData = function (data) {
6327
+ var isCopyAndPaste = data.types.length !== 0;
6328
+
6329
+ if (isCopyAndPaste) {
6330
+ var _window$getSelection;
6331
+
6332
+ var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
6333
+ var characterCountBefore = getCharacterCount(editor);
6334
+ setTimeout(function () {
6335
+ var characterCountAfter = getCharacterCount(editor);
6336
+ trackingActions.onShortcutAction('paste', {
6337
+ characterCountAfter: characterCountAfter,
6338
+ characterCountBefore: characterCountBefore,
6339
+ characterCountSelection: characterCountSelection,
6340
+ source: getPastingSource(data)
6341
+ });
6342
+ });
6343
+ }
6344
+
6345
+ insertData(data);
6346
+ };
6347
+
6348
+ return editor;
6349
+ }
6350
+ };
6351
+ };
6352
+
6353
+ function hasTables(nodes) {
6354
+ return nodes.some(function (_ref) {
6355
+ var type = _ref.type;
6356
+ return type === Contentful.BLOCKS.TABLE;
6357
+ });
6358
+ }
6359
+
6360
+ var isTableHeaderCell = function isTableHeaderCell(_ref2) {
6361
+ var type = _ref2.type;
6362
+ return type === Contentful.BLOCKS.TABLE_HEADER_CELL;
6363
+ };
6364
+
6365
+ function hasHeadersOutsideFirstRow(nodes) {
6366
+ return nodes.filter(function (_ref3) {
6367
+ var type = _ref3.type;
6368
+ return type === Contentful.BLOCKS.TABLE;
6369
+ }).flatMap(function (_ref4) {
6370
+ var children = _ref4.children;
6371
+ return children.slice(1);
6372
+ }).some(function (_ref5) {
6373
+ var children = _ref5.children;
6374
+ return children.some(isTableHeaderCell);
6375
+ });
6376
+ }
6377
+
6378
+ function addTableTrackingEvents(editor) {
6379
+ var insertData = editor.insertData;
6172
6380
 
6173
- // @ts-expect-error
6174
- var blockType = (_windowSelection$anch = windowSelection.anchorNode.attributes) == null ? void 0 : (_windowSelection$anch2 = _windowSelection$anch['data-block-type']) == null ? void 0 : _windowSelection$anch2.value; // this attribute comes from `plugins/Table/components/Table.tsx`
6381
+ editor.insertData = function (data) {
6382
+ var html = data.getData('text/html');
6175
6383
 
6176
- var isBeforeTable = blockType === Contentful.BLOCKS.TABLE;
6384
+ if (html) {
6385
+ var markupBefore = editor.children;
6386
+ insertData(data);
6387
+ var markupAfter = editor.children;
6388
+ setTimeout(function () {
6389
+ if (hasTables(markupBefore)) return;
6177
6390
 
6178
- if (isBeforeTable) {
6179
- if (event.key === 'Enter') {
6180
- var above = plateCore.getAbove(editor, {
6181
- match: {
6182
- type: Contentful.BLOCKS.TABLE
6183
- }
6184
- });
6185
- if (!above) return;
6186
- var tablePath = above[1];
6187
- insertEmptyParagraph(editor, {
6188
- at: tablePath,
6189
- select: true
6391
+ if (hasTables(markupAfter)) {
6392
+ editor.tracking.onViewportAction('paste', {
6393
+ tablePasted: true,
6394
+ source: getPastingSource(data),
6395
+ hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
6190
6396
  });
6191
6397
  }
6398
+ }, 1);
6399
+ } else {
6400
+ insertData(data);
6401
+ }
6402
+ };
6403
+ }
6404
+ var withInvalidCellChildrenTracking = function withInvalidCellChildrenTracking(transformer) {
6405
+ return function (editor, childEntry) {
6406
+ var node = childEntry[0];
6192
6407
 
6193
- event.preventDefault();
6194
- event.stopPropagation();
6195
- return;
6196
- }
6197
- } // Pressing Tab on the last cell creates a new row
6198
- // Otherwise, jumping between cells is handled in the defaultKeyDownTable
6199
-
6200
-
6201
- if (event.key === 'Tab' && !event.shiftKey) {
6202
- event.preventDefault();
6203
- var res = plateTable.getTableCellEntry(editor, {});
6204
-
6205
- if (res) {
6206
- var tableElement = res.tableElement,
6207
- tableRow = res.tableRow,
6208
- tableCell = res.tableCell;
6209
- var isLastCell = plateCore.isLastChild(tableRow, tableCell[1]);
6210
- var isLastRow = plateCore.isLastChild(tableElement, tableRow[1]);
6211
-
6212
- if (isLastRow && isLastCell) {
6213
- addRowBelow(editor); // skip default handler
6408
+ if (slate.Element.isElement(node)) {
6409
+ var _editor$tracking;
6214
6410
 
6215
- return;
6216
- }
6217
- }
6411
+ (_editor$tracking = editor.tracking) == null ? void 0 : _editor$tracking.onViewportAction('invalidTablePaste', {
6412
+ nodeType: node.type
6413
+ });
6218
6414
  }
6219
6415
 
6220
- defaultHandler(event);
6416
+ return transformer(editor, childEntry);
6221
6417
  };
6222
6418
  };
6223
6419
 
@@ -6294,14 +6490,14 @@ var createTablePlugin = function createTablePlugin() {
6294
6490
  component: HeaderCell,
6295
6491
  normalizer: [{
6296
6492
  validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.TABLE_HEADER_CELL],
6297
- transform: transformParagraphs
6493
+ transform: withInvalidCellChildrenTracking(transformParagraphs)
6298
6494
  }]
6299
6495
  }, _overrideByKey[plateTable.ELEMENT_TD] = {
6300
6496
  type: Contentful.BLOCKS.TABLE_CELL,
6301
6497
  component: Cell,
6302
6498
  normalizer: [{
6303
6499
  validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.TABLE_CELL],
6304
- transform: transformParagraphs
6500
+ transform: withInvalidCellChildrenTracking(transformParagraphs)
6305
6501
  }]
6306
6502
  }, _overrideByKey)
6307
6503
  });
@@ -6449,193 +6645,6 @@ function deleteFirstEmptyParagraph(unit, editor, deleteFunction) {
6449
6645
  }
6450
6646
  }
6451
6647
 
6452
- var _extends2, _extends4, _inlines;
6453
- var inlines = /*#__PURE__*/Object.values(Contentful.INLINES).map(function (type) {
6454
- return {
6455
- type: type
6456
- };
6457
- });
6458
- var schema = {
6459
- document: {
6460
- nodes: [{
6461
- types: /*#__PURE__*/Contentful.TOP_LEVEL_BLOCKS.map(function (type) {
6462
- return {
6463
- type: type
6464
- };
6465
- })
6466
- }]
6467
- },
6468
- blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[Contentful.BLOCKS.PARAGRAPH] = {
6469
- nodes: [{
6470
- match: /*#__PURE__*/[].concat(inlines, [{
6471
- object: 'text'
6472
- }])
6473
- }]
6474
- }, _extends2[Contentful.BLOCKS.HEADING_1] = {
6475
- nodes: [{
6476
- match: /*#__PURE__*/[].concat(inlines, [{
6477
- object: 'text'
6478
- }])
6479
- }]
6480
- }, _extends2[Contentful.BLOCKS.HEADING_2] = {
6481
- nodes: [{
6482
- match: /*#__PURE__*/[].concat(inlines, [{
6483
- object: 'text'
6484
- }])
6485
- }]
6486
- }, _extends2[Contentful.BLOCKS.HEADING_3] = {
6487
- nodes: [{
6488
- match: /*#__PURE__*/[].concat(inlines, [{
6489
- object: 'text'
6490
- }])
6491
- }]
6492
- }, _extends2[Contentful.BLOCKS.HEADING_4] = {
6493
- nodes: [{
6494
- match: /*#__PURE__*/[].concat(inlines, [{
6495
- object: 'text'
6496
- }])
6497
- }]
6498
- }, _extends2[Contentful.BLOCKS.HEADING_5] = {
6499
- nodes: [{
6500
- match: /*#__PURE__*/[].concat(inlines, [{
6501
- object: 'text'
6502
- }])
6503
- }]
6504
- }, _extends2[Contentful.BLOCKS.HEADING_6] = {
6505
- nodes: [{
6506
- match: /*#__PURE__*/[].concat(inlines, [{
6507
- object: 'text'
6508
- }])
6509
- }]
6510
- }, _extends2), /*#__PURE__*/Contentful.VOID_BLOCKS.reduce(function (blocks, nodeType) {
6511
- var _extends3;
6512
-
6513
- return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
6514
- isVoid: true
6515
- }, _extends3));
6516
- }, {}), (_extends4 = {}, _extends4[Contentful.BLOCKS.QUOTE] = {
6517
- nodes: [{
6518
- match: [/*#__PURE__*/Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE].map(function (type) {
6519
- return {
6520
- type: type
6521
- };
6522
- })],
6523
- min: 1
6524
- }],
6525
- normalize: function normalize(editor, error) {
6526
- if (error.code === 'child_type_invalid') {
6527
- return editor.unwrapBlockByKey(error.node.key, Contentful.BLOCKS.QUOTE);
6528
- }
6529
- }
6530
- }, _extends4)),
6531
- inlines: (_inlines = {}, _inlines[Contentful.INLINES.HYPERLINK] = {
6532
- nodes: [{
6533
- match: [{
6534
- object: 'text'
6535
- }]
6536
- }]
6537
- }, _inlines[Contentful.INLINES.ENTRY_HYPERLINK] = {
6538
- nodes: [{
6539
- match: [{
6540
- object: 'text'
6541
- }]
6542
- }]
6543
- }, _inlines[Contentful.INLINES.ASSET_HYPERLINK] = {
6544
- nodes: [{
6545
- match: [{
6546
- object: 'text'
6547
- }]
6548
- }]
6549
- }, _inlines[Contentful.INLINES.EMBEDDED_ENTRY] = {
6550
- isVoid: true
6551
- }, _inlines)
6552
- };
6553
-
6554
- function getCharacterCount(editor) {
6555
- var document = contentfulSlateJSAdapter.toContentfulDocument({
6556
- document: editor.children,
6557
- schema: schema
6558
- });
6559
- return richTextPlainTextRenderer.documentToPlainTextString(document).length;
6560
- }
6561
-
6562
- var actionOrigin = {
6563
- TOOLBAR: 'toolbar-icon',
6564
- SHORTCUT: 'shortcut',
6565
- VIEWPORT: 'viewport-interaction',
6566
- COMMAND_PALETTE: 'command-palette'
6567
- };
6568
- var createTrackingPlugin = function createTrackingPlugin(onAction) {
6569
- var trackingActions = {
6570
- onViewportAction: function onViewportAction(actionName, data) {
6571
- if (data === void 0) {
6572
- data = {};
6573
- }
6574
-
6575
- return onAction(actionName, _extends({
6576
- origin: actionOrigin.VIEWPORT
6577
- }, data));
6578
- },
6579
- onShortcutAction: function onShortcutAction(actionName, data) {
6580
- if (data === void 0) {
6581
- data = {};
6582
- }
6583
-
6584
- return onAction(actionName, _extends({
6585
- origin: actionOrigin.SHORTCUT
6586
- }, data));
6587
- },
6588
- onToolbarAction: function onToolbarAction(actionName, data) {
6589
- if (data === void 0) {
6590
- data = {};
6591
- }
6592
-
6593
- return onAction(actionName, _extends({
6594
- origin: actionOrigin.TOOLBAR
6595
- }, data));
6596
- },
6597
- onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
6598
- if (data === void 0) {
6599
- data = {};
6600
- }
6601
-
6602
- return onAction(actionName, _extends({
6603
- origin: actionOrigin.COMMAND_PALETTE
6604
- }, data));
6605
- }
6606
- };
6607
- return {
6608
- key: 'TrackingPlugin',
6609
- withOverrides: function withOverrides(editor) {
6610
- var insertData = editor.insertData;
6611
- editor.tracking = trackingActions;
6612
-
6613
- editor.insertData = function (data) {
6614
- var isCopyAndPaste = data.types.length !== 0;
6615
-
6616
- if (isCopyAndPaste) {
6617
- var _window$getSelection;
6618
-
6619
- var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
6620
- var characterCountBefore = getCharacterCount(editor);
6621
- setTimeout(function () {
6622
- var characterCountAfter = getCharacterCount(editor);
6623
- trackingActions.onShortcutAction('paste', {
6624
- characterCountAfter: characterCountAfter,
6625
- characterCountBefore: characterCountBefore,
6626
- characterCountSelection: characterCountSelection
6627
- });
6628
- });
6629
- }
6630
-
6631
- insertData(data);
6632
- };
6633
-
6634
- return editor;
6635
- }
6636
- };
6637
- };
6638
-
6639
6648
  var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
6640
6649
  return plateTrailingBlock.createTrailingBlockPlugin({
6641
6650
  options: {