@contentful/field-editor-rich-text 2.0.0-next.31 → 2.0.0-next.32
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/field-editor-rich-text.cjs.development.js +225 -209
- 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 +227 -211
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/plugins/Table/tableTracking.d.ts +4 -0
- package/dist/prepareDocument.d.ts +1 -1
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -410
- package/dist/plugins/Table/addTableTrackingEvents.d.ts +0 -2
|
@@ -2,7 +2,7 @@ import React__default, { createContext, useContext, useMemo, createElement, useE
|
|
|
2
2
|
import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, EntityProvider, getScheduleTooltipContent } from '@contentful/field-editor-reference';
|
|
3
3
|
import { entityHelpers, shortenStorageUnit, isValidImage, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
|
|
4
4
|
import { BLOCKS, INLINES, TEXT_CONTAINERS, HEADINGS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
5
|
-
import { usePlateEditorRef, usePlateEditorState, getNodes, toggleNodeType, getText, getAbove, setNodes, isAncestorEmpty, match, getLastChildPath, wrapNodes, getPluginType, unwrapNodes, isCollapsed, isRangeAcrossBlocks, ELEMENT_DEFAULT, findNode, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, deleteFragment, isMarkActive, toggleMark, someHtmlElement, KEY_DESERIALIZE_HTML, hasSingleChild, isLastChild, getChildren as getChildren$1,
|
|
5
|
+
import { usePlateEditorRef, usePlateEditorState, getNodes, toggleNodeType, getText, getAbove, setNodes, isAncestorEmpty, match, getLastChildPath, wrapNodes, getPluginType, unwrapNodes, isCollapsed, isRangeAcrossBlocks, ELEMENT_DEFAULT, findNode, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, deleteFragment, isMarkActive, toggleMark, someHtmlElement, KEY_DESERIALIZE_HTML, hasSingleChild, isLastChild, someNode, getChildren as getChildren$1, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, getPlateSelectors, getPlateActions, Plate } from '@udecode/plate-core';
|
|
6
6
|
import { css, cx } from 'emotion';
|
|
7
7
|
import deepEquals from 'fast-deep-equal';
|
|
8
8
|
import noop from 'lodash-es/noop';
|
|
@@ -26,7 +26,7 @@ import { createBoldPlugin as createBoldPlugin$1, createCodePlugin as createCodeP
|
|
|
26
26
|
import isPlainObject from 'is-plain-obj';
|
|
27
27
|
import { createParagraphPlugin as createParagraphPlugin$1 } from '@udecode/plate-paragraph';
|
|
28
28
|
import { createSelectOnBackspacePlugin as createSelectOnBackspacePlugin$1 } from '@udecode/plate-select';
|
|
29
|
-
import { ELEMENT_TABLE,
|
|
29
|
+
import { ELEMENT_TABLE, ELEMENT_TR, getEmptyRowNode, ELEMENT_TD, ELEMENT_TH, getEmptyCellNode, insertTable, deleteRow, deleteColumn, deleteTable, onKeyDownTable as onKeyDownTable$1, getTableCellEntry, createTablePlugin as createTablePlugin$1, withTable } from '@udecode/plate-table';
|
|
30
30
|
import { toContentfulDocument, toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
|
|
31
31
|
import { documentToPlainTextString } from '@contentful/rich-text-plain-text-renderer';
|
|
32
32
|
import { createTrailingBlockPlugin } from '@udecode/plate-trailing-block';
|
|
@@ -5621,210 +5621,6 @@ function SlashCommandsPalette(_ref2) {
|
|
|
5621
5621
|
}, /*#__PURE__*/createElement(Card, null, /*#__PURE__*/createElement(Text$1, null, "Slash commands are temporarily unavailable.")));
|
|
5622
5622
|
}
|
|
5623
5623
|
|
|
5624
|
-
function insertTableAndFocusFirstCell(editor) {
|
|
5625
|
-
insertTable(editor, {
|
|
5626
|
-
header: true
|
|
5627
|
-
});
|
|
5628
|
-
replaceEmptyParagraphWithTable(editor);
|
|
5629
|
-
}
|
|
5630
|
-
function isTableActive(editor) {
|
|
5631
|
-
var tableElements = [ELEMENT_TABLE, ELEMENT_TH, ELEMENT_TR, ELEMENT_TD];
|
|
5632
|
-
return tableElements.some(function (el) {
|
|
5633
|
-
return isBlockSelected(editor, el);
|
|
5634
|
-
});
|
|
5635
|
-
}
|
|
5636
|
-
function isTableHeaderEnabled(editor) {
|
|
5637
|
-
var tableItem = getAbove(editor, {
|
|
5638
|
-
match: {
|
|
5639
|
-
type: BLOCKS.TABLE
|
|
5640
|
-
}
|
|
5641
|
-
});
|
|
5642
|
-
|
|
5643
|
-
if (!tableItem) {
|
|
5644
|
-
return false;
|
|
5645
|
-
}
|
|
5646
|
-
|
|
5647
|
-
var firstRow = getChildren$1(tableItem)[0];
|
|
5648
|
-
|
|
5649
|
-
if (!firstRow) {
|
|
5650
|
-
return false;
|
|
5651
|
-
}
|
|
5652
|
-
|
|
5653
|
-
return getChildren$1(firstRow).every(function (_ref) {
|
|
5654
|
-
var node = _ref[0];
|
|
5655
|
-
return node.type === BLOCKS.TABLE_HEADER_CELL;
|
|
5656
|
-
});
|
|
5657
|
-
}
|
|
5658
|
-
function replaceEmptyParagraphWithTable(editor) {
|
|
5659
|
-
var tablePath = getAncestorPathFromSelection(editor);
|
|
5660
|
-
if (!tablePath || isFirstChild(tablePath)) return;
|
|
5661
|
-
var previousPath = Path.previous(tablePath);
|
|
5662
|
-
if (!previousPath) return;
|
|
5663
|
-
|
|
5664
|
-
var _Editor$nodes = Editor.nodes(editor, {
|
|
5665
|
-
at: previousPath,
|
|
5666
|
-
match: function match(node) {
|
|
5667
|
-
return node.type === BLOCKS.PARAGRAPH;
|
|
5668
|
-
}
|
|
5669
|
-
}),
|
|
5670
|
-
nodes = _Editor$nodes[0];
|
|
5671
|
-
|
|
5672
|
-
if (!nodes) return;
|
|
5673
|
-
var previousNode = nodes[0];
|
|
5674
|
-
var isPreviousNodeTextEmpty = isAncestorEmpty(editor, previousNode);
|
|
5675
|
-
|
|
5676
|
-
if (isPreviousNodeTextEmpty) {
|
|
5677
|
-
// Switch table with previous empty paragraph
|
|
5678
|
-
Transforms.moveNodes(editor, {
|
|
5679
|
-
at: tablePath,
|
|
5680
|
-
to: previousPath
|
|
5681
|
-
}); // Remove previous paragraph that now is under the table
|
|
5682
|
-
|
|
5683
|
-
Transforms.removeNodes(editor, {
|
|
5684
|
-
at: tablePath
|
|
5685
|
-
});
|
|
5686
|
-
}
|
|
5687
|
-
}
|
|
5688
|
-
/**
|
|
5689
|
-
* Returns the number of cells in a given row vs the table width
|
|
5690
|
-
*
|
|
5691
|
-
* Note: We should only get different table rows cell counts in between
|
|
5692
|
-
* normalization cycles.
|
|
5693
|
-
*/
|
|
5694
|
-
|
|
5695
|
-
var getNoOfMissingTableCellsInRow = function getNoOfMissingTableCellsInRow(editor, _ref2) {
|
|
5696
|
-
var rowPath = _ref2[1];
|
|
5697
|
-
var parent = getParent(editor, rowPath); // This is ensured by normalization. The error is here just in case
|
|
5698
|
-
|
|
5699
|
-
if (!parent) {
|
|
5700
|
-
throw new Error('table rows must be wrapped in a table node');
|
|
5701
|
-
}
|
|
5702
|
-
|
|
5703
|
-
var tablePath = parent[1]; // The longest table row determines its width
|
|
5704
|
-
|
|
5705
|
-
var tableWidth = Math.max.apply(Math, Array.from(Node.children(editor, tablePath)).map(function (_ref3) {
|
|
5706
|
-
var path = _ref3[1];
|
|
5707
|
-
return Array.from(Node.children(editor, path)).length;
|
|
5708
|
-
}));
|
|
5709
|
-
var rowWidth = Array.from(Node.children(editor, rowPath)).length;
|
|
5710
|
-
return tableWidth - rowWidth;
|
|
5711
|
-
};
|
|
5712
|
-
var createEmptyTableCells = function createEmptyTableCells(count) {
|
|
5713
|
-
var emptyTableCell = {
|
|
5714
|
-
type: BLOCKS.TABLE_CELL,
|
|
5715
|
-
data: {},
|
|
5716
|
-
children: [{
|
|
5717
|
-
type: BLOCKS.PARAGRAPH,
|
|
5718
|
-
data: {},
|
|
5719
|
-
children: [{
|
|
5720
|
-
text: ''
|
|
5721
|
-
}]
|
|
5722
|
-
}]
|
|
5723
|
-
};
|
|
5724
|
-
return new Array(count).fill(emptyTableCell);
|
|
5725
|
-
};
|
|
5726
|
-
var isNotEmpty = function isNotEmpty(editor, _ref4) {
|
|
5727
|
-
var path = _ref4[1];
|
|
5728
|
-
return Array.from(Node.children(editor, path)).length !== 0;
|
|
5729
|
-
};
|
|
5730
|
-
var isTable = function isTable(node) {
|
|
5731
|
-
return Element.isElement(node) && node.type === BLOCKS.TABLE;
|
|
5732
|
-
};
|
|
5733
|
-
|
|
5734
|
-
function hasTables(nodes) {
|
|
5735
|
-
return nodes.some(function (_ref) {
|
|
5736
|
-
var type = _ref.type;
|
|
5737
|
-
return type === BLOCKS.TABLE;
|
|
5738
|
-
});
|
|
5739
|
-
}
|
|
5740
|
-
|
|
5741
|
-
var isTableHeaderCell = function isTableHeaderCell(_ref2) {
|
|
5742
|
-
var type = _ref2.type;
|
|
5743
|
-
return type === BLOCKS.TABLE_HEADER_CELL;
|
|
5744
|
-
};
|
|
5745
|
-
|
|
5746
|
-
var isTableCellOrHeader = function isTableCellOrHeader(node) {
|
|
5747
|
-
return Element.isElement(node) && [BLOCKS.TABLE_HEADER_CELL, BLOCKS.TABLE_CELL].includes(node.type);
|
|
5748
|
-
};
|
|
5749
|
-
|
|
5750
|
-
function hasHeadersOutsideFirstRow(nodes) {
|
|
5751
|
-
return nodes.filter(function (_ref3) {
|
|
5752
|
-
var type = _ref3.type;
|
|
5753
|
-
return type === BLOCKS.TABLE;
|
|
5754
|
-
}).flatMap(function (_ref4) {
|
|
5755
|
-
var children = _ref4.children;
|
|
5756
|
-
return children.slice(1);
|
|
5757
|
-
}).some(function (_ref5) {
|
|
5758
|
-
var children = _ref5.children;
|
|
5759
|
-
return children.some(isTableHeaderCell);
|
|
5760
|
-
});
|
|
5761
|
-
}
|
|
5762
|
-
|
|
5763
|
-
function trackInvalidTableCellChildren(editor, table) {
|
|
5764
|
-
var cells = table.children.flatMap(function (row) {
|
|
5765
|
-
var _row$children;
|
|
5766
|
-
|
|
5767
|
-
return (_row$children = row.children) != null ? _row$children : [];
|
|
5768
|
-
}).filter(isTableCellOrHeader); // get invalid direct children
|
|
5769
|
-
|
|
5770
|
-
var invalidNodeTypes = cells.flatMap(function (cell) {
|
|
5771
|
-
// Only paragraphs are allowed inside tables at the moment
|
|
5772
|
-
return cell.children.filter(function (node) {
|
|
5773
|
-
return Element.isElement(node) && node.type !== BLOCKS.PARAGRAPH;
|
|
5774
|
-
}).map(function (node) {
|
|
5775
|
-
return node.type;
|
|
5776
|
-
});
|
|
5777
|
-
});
|
|
5778
|
-
|
|
5779
|
-
for (var _iterator = _createForOfIteratorHelperLoose(new Set(invalidNodeTypes)), _step; !(_step = _iterator()).done;) {
|
|
5780
|
-
var _editor$tracking;
|
|
5781
|
-
|
|
5782
|
-
var nodeType = _step.value;
|
|
5783
|
-
(_editor$tracking = editor.tracking) == null ? void 0 : _editor$tracking.onViewportAction('invalidTablePaste', {
|
|
5784
|
-
nodeType: nodeType
|
|
5785
|
-
});
|
|
5786
|
-
}
|
|
5787
|
-
}
|
|
5788
|
-
|
|
5789
|
-
function addTableTrackingEvents(editor) {
|
|
5790
|
-
var insertData = editor.insertData;
|
|
5791
|
-
|
|
5792
|
-
editor.insertData = function (data) {
|
|
5793
|
-
var html = data.getData('text/html');
|
|
5794
|
-
|
|
5795
|
-
if (html) {
|
|
5796
|
-
var markupBefore = editor.children;
|
|
5797
|
-
insertData(data);
|
|
5798
|
-
var markupAfter = editor.children;
|
|
5799
|
-
setTimeout(function () {
|
|
5800
|
-
if (hasTables(markupBefore)) return;
|
|
5801
|
-
|
|
5802
|
-
if (hasTables(markupAfter)) {
|
|
5803
|
-
editor.tracking.onViewportAction('paste', {
|
|
5804
|
-
tablePasted: true,
|
|
5805
|
-
hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
|
|
5806
|
-
});
|
|
5807
|
-
}
|
|
5808
|
-
}, 1);
|
|
5809
|
-
} else {
|
|
5810
|
-
insertData(data);
|
|
5811
|
-
}
|
|
5812
|
-
};
|
|
5813
|
-
|
|
5814
|
-
var insertFragment = editor.insertFragment;
|
|
5815
|
-
|
|
5816
|
-
editor.insertFragment = function (fragment) {
|
|
5817
|
-
var tables = fragment.filter(isTable);
|
|
5818
|
-
|
|
5819
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(tables), _step2; !(_step2 = _iterator2()).done;) {
|
|
5820
|
-
var table = _step2.value;
|
|
5821
|
-
trackInvalidTableCellChildren(editor, table);
|
|
5822
|
-
}
|
|
5823
|
-
|
|
5824
|
-
return insertFragment(fragment);
|
|
5825
|
-
};
|
|
5826
|
-
}
|
|
5827
|
-
|
|
5828
5624
|
var addRow = function addRow(editor, getNextRowPath) {
|
|
5829
5625
|
if (someNode(editor, {
|
|
5830
5626
|
match: {
|
|
@@ -5944,6 +5740,116 @@ var setHeader = function setHeader(editor, enable) {
|
|
|
5944
5740
|
});
|
|
5945
5741
|
};
|
|
5946
5742
|
|
|
5743
|
+
function insertTableAndFocusFirstCell(editor) {
|
|
5744
|
+
insertTable(editor, {
|
|
5745
|
+
header: true
|
|
5746
|
+
});
|
|
5747
|
+
replaceEmptyParagraphWithTable(editor);
|
|
5748
|
+
}
|
|
5749
|
+
function isTableActive(editor) {
|
|
5750
|
+
var tableElements = [ELEMENT_TABLE, ELEMENT_TH, ELEMENT_TR, ELEMENT_TD];
|
|
5751
|
+
return tableElements.some(function (el) {
|
|
5752
|
+
return isBlockSelected(editor, el);
|
|
5753
|
+
});
|
|
5754
|
+
}
|
|
5755
|
+
function isTableHeaderEnabled(editor) {
|
|
5756
|
+
var tableItem = getAbove(editor, {
|
|
5757
|
+
match: {
|
|
5758
|
+
type: BLOCKS.TABLE
|
|
5759
|
+
}
|
|
5760
|
+
});
|
|
5761
|
+
|
|
5762
|
+
if (!tableItem) {
|
|
5763
|
+
return false;
|
|
5764
|
+
}
|
|
5765
|
+
|
|
5766
|
+
var firstRow = getChildren$1(tableItem)[0];
|
|
5767
|
+
|
|
5768
|
+
if (!firstRow) {
|
|
5769
|
+
return false;
|
|
5770
|
+
}
|
|
5771
|
+
|
|
5772
|
+
return getChildren$1(firstRow).every(function (_ref) {
|
|
5773
|
+
var node = _ref[0];
|
|
5774
|
+
return node.type === BLOCKS.TABLE_HEADER_CELL;
|
|
5775
|
+
});
|
|
5776
|
+
}
|
|
5777
|
+
function replaceEmptyParagraphWithTable(editor) {
|
|
5778
|
+
var tablePath = getAncestorPathFromSelection(editor);
|
|
5779
|
+
if (!tablePath || isFirstChild(tablePath)) return;
|
|
5780
|
+
var previousPath = Path.previous(tablePath);
|
|
5781
|
+
if (!previousPath) return;
|
|
5782
|
+
|
|
5783
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
5784
|
+
at: previousPath,
|
|
5785
|
+
match: function match(node) {
|
|
5786
|
+
return node.type === BLOCKS.PARAGRAPH;
|
|
5787
|
+
}
|
|
5788
|
+
}),
|
|
5789
|
+
nodes = _Editor$nodes[0];
|
|
5790
|
+
|
|
5791
|
+
if (!nodes) return;
|
|
5792
|
+
var previousNode = nodes[0];
|
|
5793
|
+
var isPreviousNodeTextEmpty = isAncestorEmpty(editor, previousNode);
|
|
5794
|
+
|
|
5795
|
+
if (isPreviousNodeTextEmpty) {
|
|
5796
|
+
// Switch table with previous empty paragraph
|
|
5797
|
+
Transforms.moveNodes(editor, {
|
|
5798
|
+
at: tablePath,
|
|
5799
|
+
to: previousPath
|
|
5800
|
+
}); // Remove previous paragraph that now is under the table
|
|
5801
|
+
|
|
5802
|
+
Transforms.removeNodes(editor, {
|
|
5803
|
+
at: tablePath
|
|
5804
|
+
});
|
|
5805
|
+
}
|
|
5806
|
+
}
|
|
5807
|
+
/**
|
|
5808
|
+
* Returns the number of cells in a given row vs the table width
|
|
5809
|
+
*
|
|
5810
|
+
* Note: We should only get different table rows cell counts in between
|
|
5811
|
+
* normalization cycles.
|
|
5812
|
+
*/
|
|
5813
|
+
|
|
5814
|
+
var getNoOfMissingTableCellsInRow = function getNoOfMissingTableCellsInRow(editor, _ref2) {
|
|
5815
|
+
var rowPath = _ref2[1];
|
|
5816
|
+
var parent = getParent(editor, rowPath); // This is ensured by normalization. The error is here just in case
|
|
5817
|
+
|
|
5818
|
+
if (!parent) {
|
|
5819
|
+
throw new Error('table rows must be wrapped in a table node');
|
|
5820
|
+
}
|
|
5821
|
+
|
|
5822
|
+
var tablePath = parent[1]; // The longest table row determines its width
|
|
5823
|
+
|
|
5824
|
+
var tableWidth = Math.max.apply(Math, Array.from(Node.children(editor, tablePath)).map(function (_ref3) {
|
|
5825
|
+
var path = _ref3[1];
|
|
5826
|
+
return Array.from(Node.children(editor, path)).length;
|
|
5827
|
+
}));
|
|
5828
|
+
var rowWidth = Array.from(Node.children(editor, rowPath)).length;
|
|
5829
|
+
return tableWidth - rowWidth;
|
|
5830
|
+
};
|
|
5831
|
+
var createEmptyTableCells = function createEmptyTableCells(count) {
|
|
5832
|
+
var emptyTableCell = {
|
|
5833
|
+
type: BLOCKS.TABLE_CELL,
|
|
5834
|
+
data: {},
|
|
5835
|
+
children: [{
|
|
5836
|
+
type: BLOCKS.PARAGRAPH,
|
|
5837
|
+
data: {},
|
|
5838
|
+
children: [{
|
|
5839
|
+
text: ''
|
|
5840
|
+
}]
|
|
5841
|
+
}]
|
|
5842
|
+
};
|
|
5843
|
+
return new Array(count).fill(emptyTableCell);
|
|
5844
|
+
};
|
|
5845
|
+
var isNotEmpty = function isNotEmpty(editor, _ref4) {
|
|
5846
|
+
var path = _ref4[1];
|
|
5847
|
+
return Array.from(Node.children(editor, path)).length !== 0;
|
|
5848
|
+
};
|
|
5849
|
+
var isTable = function isTable(node) {
|
|
5850
|
+
return Element.isElement(node) && node.type === BLOCKS.TABLE;
|
|
5851
|
+
};
|
|
5852
|
+
|
|
5947
5853
|
var styles$i = {
|
|
5948
5854
|
topRight: /*#__PURE__*/css({
|
|
5949
5855
|
position: 'absolute',
|
|
@@ -6067,7 +5973,7 @@ var Cell = function Cell(props) {
|
|
|
6067
5973
|
};
|
|
6068
5974
|
|
|
6069
5975
|
var _templateObject$8;
|
|
6070
|
-
var style$4 = /*#__PURE__*/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);
|
|
5976
|
+
var style$4 = /*#__PURE__*/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);
|
|
6071
5977
|
var HeaderCell = function HeaderCell(props) {
|
|
6072
5978
|
var isSelected = useSelected();
|
|
6073
5979
|
return /*#__PURE__*/createElement("th", Object.assign({}, props.attributes, props.element.data, {
|
|
@@ -6214,6 +6120,72 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
|
6214
6120
|
};
|
|
6215
6121
|
};
|
|
6216
6122
|
|
|
6123
|
+
function hasTables(nodes) {
|
|
6124
|
+
return nodes.some(function (_ref) {
|
|
6125
|
+
var type = _ref.type;
|
|
6126
|
+
return type === BLOCKS.TABLE;
|
|
6127
|
+
});
|
|
6128
|
+
}
|
|
6129
|
+
|
|
6130
|
+
var isTableHeaderCell = function isTableHeaderCell(_ref2) {
|
|
6131
|
+
var type = _ref2.type;
|
|
6132
|
+
return type === BLOCKS.TABLE_HEADER_CELL;
|
|
6133
|
+
};
|
|
6134
|
+
|
|
6135
|
+
function hasHeadersOutsideFirstRow(nodes) {
|
|
6136
|
+
return nodes.filter(function (_ref3) {
|
|
6137
|
+
var type = _ref3.type;
|
|
6138
|
+
return type === BLOCKS.TABLE;
|
|
6139
|
+
}).flatMap(function (_ref4) {
|
|
6140
|
+
var children = _ref4.children;
|
|
6141
|
+
return children.slice(1);
|
|
6142
|
+
}).some(function (_ref5) {
|
|
6143
|
+
var children = _ref5.children;
|
|
6144
|
+
return children.some(isTableHeaderCell);
|
|
6145
|
+
});
|
|
6146
|
+
}
|
|
6147
|
+
|
|
6148
|
+
function addTableTrackingEvents(editor) {
|
|
6149
|
+
var insertData = editor.insertData;
|
|
6150
|
+
|
|
6151
|
+
editor.insertData = function (data) {
|
|
6152
|
+
var html = data.getData('text/html');
|
|
6153
|
+
|
|
6154
|
+
if (html) {
|
|
6155
|
+
var markupBefore = editor.children;
|
|
6156
|
+
insertData(data);
|
|
6157
|
+
var markupAfter = editor.children;
|
|
6158
|
+
setTimeout(function () {
|
|
6159
|
+
if (hasTables(markupBefore)) return;
|
|
6160
|
+
|
|
6161
|
+
if (hasTables(markupAfter)) {
|
|
6162
|
+
editor.tracking.onViewportAction('paste', {
|
|
6163
|
+
tablePasted: true,
|
|
6164
|
+
hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
|
|
6165
|
+
});
|
|
6166
|
+
}
|
|
6167
|
+
}, 1);
|
|
6168
|
+
} else {
|
|
6169
|
+
insertData(data);
|
|
6170
|
+
}
|
|
6171
|
+
};
|
|
6172
|
+
}
|
|
6173
|
+
var withInvalidCellChildrenTracking = function withInvalidCellChildrenTracking(transformer) {
|
|
6174
|
+
return function (editor, childEntry) {
|
|
6175
|
+
var node = childEntry[0];
|
|
6176
|
+
|
|
6177
|
+
if (Element.isElement(node)) {
|
|
6178
|
+
var _editor$tracking;
|
|
6179
|
+
|
|
6180
|
+
(_editor$tracking = editor.tracking) == null ? void 0 : _editor$tracking.onViewportAction('invalidTablePaste', {
|
|
6181
|
+
nodeType: node.type
|
|
6182
|
+
});
|
|
6183
|
+
}
|
|
6184
|
+
|
|
6185
|
+
return transformer(editor, childEntry);
|
|
6186
|
+
};
|
|
6187
|
+
};
|
|
6188
|
+
|
|
6217
6189
|
var createTablePlugin = function createTablePlugin() {
|
|
6218
6190
|
var _overrideByKey;
|
|
6219
6191
|
|
|
@@ -6287,14 +6259,14 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
6287
6259
|
component: HeaderCell,
|
|
6288
6260
|
normalizer: [{
|
|
6289
6261
|
validChildren: CONTAINERS[BLOCKS.TABLE_HEADER_CELL],
|
|
6290
|
-
transform: transformParagraphs
|
|
6262
|
+
transform: withInvalidCellChildrenTracking(transformParagraphs)
|
|
6291
6263
|
}]
|
|
6292
6264
|
}, _overrideByKey[ELEMENT_TD] = {
|
|
6293
6265
|
type: BLOCKS.TABLE_CELL,
|
|
6294
6266
|
component: Cell,
|
|
6295
6267
|
normalizer: [{
|
|
6296
6268
|
validChildren: CONTAINERS[BLOCKS.TABLE_CELL],
|
|
6297
|
-
transform: transformParagraphs
|
|
6269
|
+
transform: withInvalidCellChildrenTracking(transformParagraphs)
|
|
6298
6270
|
}]
|
|
6299
6271
|
}, _overrideByKey)
|
|
6300
6272
|
});
|
|
@@ -6558,6 +6530,43 @@ var actionOrigin = {
|
|
|
6558
6530
|
VIEWPORT: 'viewport-interaction',
|
|
6559
6531
|
COMMAND_PALETTE: 'command-palette'
|
|
6560
6532
|
};
|
|
6533
|
+
|
|
6534
|
+
function getPastingSource(data) {
|
|
6535
|
+
var textHtml = data.getData('text/html');
|
|
6536
|
+
var doc = new DOMParser().parseFromString(textHtml, 'text/html');
|
|
6537
|
+
|
|
6538
|
+
if (doc.querySelector('[id*="docs-internal-guid"]')) {
|
|
6539
|
+
return 'Google Docs';
|
|
6540
|
+
}
|
|
6541
|
+
|
|
6542
|
+
if (doc.querySelector('google-sheets-html-origin') || doc.querySelector('[data-sheets-value]')) {
|
|
6543
|
+
return 'Google Spreadsheets';
|
|
6544
|
+
}
|
|
6545
|
+
|
|
6546
|
+
if (doc.querySelector('meta[content*="Microsoft Excel"]')) {
|
|
6547
|
+
return 'Microsoft Excel';
|
|
6548
|
+
}
|
|
6549
|
+
|
|
6550
|
+
if (doc.querySelector('meta[content*="Microsoft Word"]')) {
|
|
6551
|
+
return 'Microsoft Word';
|
|
6552
|
+
} // 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
|
|
6553
|
+
|
|
6554
|
+
|
|
6555
|
+
if (doc.querySelector('[style*="Arial_MSFontService"]') && (doc.querySelector('.TextRun') || doc.querySelector('.OutlineElement'))) {
|
|
6556
|
+
return 'Microsoft Word Online';
|
|
6557
|
+
}
|
|
6558
|
+
|
|
6559
|
+
if (doc.querySelector('meta[content="Cocoa HTML Writer"]')) {
|
|
6560
|
+
return 'Apple Notes';
|
|
6561
|
+
}
|
|
6562
|
+
|
|
6563
|
+
if (doc.querySelector('[style*="Slack-Lato, Slack-Fractions"]')) {
|
|
6564
|
+
return 'Slack';
|
|
6565
|
+
}
|
|
6566
|
+
|
|
6567
|
+
return '';
|
|
6568
|
+
}
|
|
6569
|
+
|
|
6561
6570
|
var createTrackingPlugin = function createTrackingPlugin(onAction) {
|
|
6562
6571
|
var trackingActions = {
|
|
6563
6572
|
onViewportAction: function onViewportAction(actionName, data) {
|
|
@@ -6613,11 +6622,18 @@ var createTrackingPlugin = function createTrackingPlugin(onAction) {
|
|
|
6613
6622
|
var characterCountBefore = getCharacterCount(editor);
|
|
6614
6623
|
setTimeout(function () {
|
|
6615
6624
|
var characterCountAfter = getCharacterCount(editor);
|
|
6616
|
-
|
|
6625
|
+
var payload = {
|
|
6617
6626
|
characterCountAfter: characterCountAfter,
|
|
6618
6627
|
characterCountBefore: characterCountBefore,
|
|
6619
6628
|
characterCountSelection: characterCountSelection
|
|
6620
|
-
}
|
|
6629
|
+
};
|
|
6630
|
+
var source = getPastingSource(data);
|
|
6631
|
+
|
|
6632
|
+
if (source) {
|
|
6633
|
+
payload.source = source;
|
|
6634
|
+
}
|
|
6635
|
+
|
|
6636
|
+
trackingActions.onShortcutAction('paste', payload);
|
|
6621
6637
|
});
|
|
6622
6638
|
}
|
|
6623
6639
|
|