@contentful/field-editor-rich-text 2.0.0-next.30 → 2.0.0-next.33
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 +483 -472
- 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 +485 -474
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/plugins/Table/tableTracking.d.ts +4 -0
- package/dist/plugins/Tracking/createTrackingPlugin.d.ts +1 -0
- package/package.json +3 -3
- package/dist/plugins/Table/addTableTrackingEvents.d.ts +0 -2
|
@@ -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
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
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
|
-
|
|
5967
|
-
|
|
5769
|
+
if (!tableItem) {
|
|
5770
|
+
return false;
|
|
5771
|
+
}
|
|
5968
5772
|
|
|
5969
|
-
var
|
|
5970
|
-
var editor = useContentfulEditor();
|
|
5971
|
-
var isDisabled = Slate.useReadOnly();
|
|
5773
|
+
var firstRow = plateCore.getChildren(tableItem)[0];
|
|
5972
5774
|
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5775
|
+
if (!firstRow) {
|
|
5776
|
+
return false;
|
|
5777
|
+
}
|
|
5976
5778
|
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
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
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
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
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
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, {
|
|
@@ -6112,18 +6018,20 @@ var Table = function Table(props) {
|
|
|
6112
6018
|
*/
|
|
6113
6019
|
|
|
6114
6020
|
var trimUnnecessaryTableWrapper = function trimUnnecessaryTableWrapper(node) {
|
|
6021
|
+
var _node$children, _row$children;
|
|
6022
|
+
|
|
6115
6023
|
if (!slate.Element.isElement(node)) {
|
|
6116
6024
|
return [node];
|
|
6117
6025
|
} // must be a table with a single row
|
|
6118
6026
|
|
|
6119
6027
|
|
|
6120
|
-
if (node.type !== Contentful.BLOCKS.TABLE || node.children.length !== 1) {
|
|
6028
|
+
if (node.type !== Contentful.BLOCKS.TABLE || ((_node$children = node.children) == null ? void 0 : _node$children.length) !== 1) {
|
|
6121
6029
|
return [node];
|
|
6122
6030
|
}
|
|
6123
6031
|
|
|
6124
6032
|
var row = node.children[0]; // the row must contain a single cell
|
|
6125
6033
|
|
|
6126
|
-
if (row.children.length !== 1) {
|
|
6034
|
+
if ((row == null ? void 0 : (_row$children = row.children) == null ? void 0 : _row$children.length) !== 1) {
|
|
6127
6035
|
return [node];
|
|
6128
6036
|
}
|
|
6129
6037
|
|
|
@@ -6165,57 +6073,347 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
|
6165
6073
|
// This fixes `Cannot resolve a Slate point from DOM point: [object HTMLDivElement]` when typing while the cursor is before table
|
|
6166
6074
|
var windowSelection = window.getSelection();
|
|
6167
6075
|
|
|
6168
|
-
if (windowSelection) {
|
|
6169
|
-
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;
|
|
6170
6380
|
|
|
6171
|
-
|
|
6172
|
-
|
|
6381
|
+
editor.insertData = function (data) {
|
|
6382
|
+
var html = data.getData('text/html');
|
|
6173
6383
|
|
|
6174
|
-
|
|
6384
|
+
if (html) {
|
|
6385
|
+
var markupBefore = editor.children;
|
|
6386
|
+
insertData(data);
|
|
6387
|
+
var markupAfter = editor.children;
|
|
6388
|
+
setTimeout(function () {
|
|
6389
|
+
if (hasTables(markupBefore)) return;
|
|
6175
6390
|
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
}
|
|
6182
|
-
});
|
|
6183
|
-
if (!above) return;
|
|
6184
|
-
var tablePath = above[1];
|
|
6185
|
-
insertEmptyParagraph(editor, {
|
|
6186
|
-
at: tablePath,
|
|
6187
|
-
select: true
|
|
6391
|
+
if (hasTables(markupAfter)) {
|
|
6392
|
+
editor.tracking.onViewportAction('paste', {
|
|
6393
|
+
tablePasted: true,
|
|
6394
|
+
source: getPastingSource(data),
|
|
6395
|
+
hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
|
|
6188
6396
|
});
|
|
6189
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];
|
|
6190
6407
|
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
return;
|
|
6194
|
-
}
|
|
6195
|
-
} // Pressing Tab on the last cell creates a new row
|
|
6196
|
-
// Otherwise, jumping between cells is handled in the defaultKeyDownTable
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
if (event.key === 'Tab' && !event.shiftKey) {
|
|
6200
|
-
event.preventDefault();
|
|
6201
|
-
var res = plateTable.getTableCellEntry(editor, {});
|
|
6202
|
-
|
|
6203
|
-
if (res) {
|
|
6204
|
-
var tableElement = res.tableElement,
|
|
6205
|
-
tableRow = res.tableRow,
|
|
6206
|
-
tableCell = res.tableCell;
|
|
6207
|
-
var isLastCell = plateCore.isLastChild(tableRow, tableCell[1]);
|
|
6208
|
-
var isLastRow = plateCore.isLastChild(tableElement, tableRow[1]);
|
|
6209
|
-
|
|
6210
|
-
if (isLastRow && isLastCell) {
|
|
6211
|
-
addRowBelow(editor); // skip default handler
|
|
6408
|
+
if (slate.Element.isElement(node)) {
|
|
6409
|
+
var _editor$tracking;
|
|
6212
6410
|
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
}
|
|
6411
|
+
(_editor$tracking = editor.tracking) == null ? void 0 : _editor$tracking.onViewportAction('invalidTablePaste', {
|
|
6412
|
+
nodeType: node.type
|
|
6413
|
+
});
|
|
6216
6414
|
}
|
|
6217
6415
|
|
|
6218
|
-
|
|
6416
|
+
return transformer(editor, childEntry);
|
|
6219
6417
|
};
|
|
6220
6418
|
};
|
|
6221
6419
|
|
|
@@ -6292,14 +6490,14 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
6292
6490
|
component: HeaderCell,
|
|
6293
6491
|
normalizer: [{
|
|
6294
6492
|
validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.TABLE_HEADER_CELL],
|
|
6295
|
-
transform: transformParagraphs
|
|
6493
|
+
transform: withInvalidCellChildrenTracking(transformParagraphs)
|
|
6296
6494
|
}]
|
|
6297
6495
|
}, _overrideByKey[plateTable.ELEMENT_TD] = {
|
|
6298
6496
|
type: Contentful.BLOCKS.TABLE_CELL,
|
|
6299
6497
|
component: Cell,
|
|
6300
6498
|
normalizer: [{
|
|
6301
6499
|
validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.TABLE_CELL],
|
|
6302
|
-
transform: transformParagraphs
|
|
6500
|
+
transform: withInvalidCellChildrenTracking(transformParagraphs)
|
|
6303
6501
|
}]
|
|
6304
6502
|
}, _overrideByKey)
|
|
6305
6503
|
});
|
|
@@ -6447,193 +6645,6 @@ function deleteFirstEmptyParagraph(unit, editor, deleteFunction) {
|
|
|
6447
6645
|
}
|
|
6448
6646
|
}
|
|
6449
6647
|
|
|
6450
|
-
var _extends2, _extends4, _inlines;
|
|
6451
|
-
var inlines = /*#__PURE__*/Object.values(Contentful.INLINES).map(function (type) {
|
|
6452
|
-
return {
|
|
6453
|
-
type: type
|
|
6454
|
-
};
|
|
6455
|
-
});
|
|
6456
|
-
var schema = {
|
|
6457
|
-
document: {
|
|
6458
|
-
nodes: [{
|
|
6459
|
-
types: /*#__PURE__*/Contentful.TOP_LEVEL_BLOCKS.map(function (type) {
|
|
6460
|
-
return {
|
|
6461
|
-
type: type
|
|
6462
|
-
};
|
|
6463
|
-
})
|
|
6464
|
-
}]
|
|
6465
|
-
},
|
|
6466
|
-
blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[Contentful.BLOCKS.PARAGRAPH] = {
|
|
6467
|
-
nodes: [{
|
|
6468
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6469
|
-
object: 'text'
|
|
6470
|
-
}])
|
|
6471
|
-
}]
|
|
6472
|
-
}, _extends2[Contentful.BLOCKS.HEADING_1] = {
|
|
6473
|
-
nodes: [{
|
|
6474
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6475
|
-
object: 'text'
|
|
6476
|
-
}])
|
|
6477
|
-
}]
|
|
6478
|
-
}, _extends2[Contentful.BLOCKS.HEADING_2] = {
|
|
6479
|
-
nodes: [{
|
|
6480
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6481
|
-
object: 'text'
|
|
6482
|
-
}])
|
|
6483
|
-
}]
|
|
6484
|
-
}, _extends2[Contentful.BLOCKS.HEADING_3] = {
|
|
6485
|
-
nodes: [{
|
|
6486
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6487
|
-
object: 'text'
|
|
6488
|
-
}])
|
|
6489
|
-
}]
|
|
6490
|
-
}, _extends2[Contentful.BLOCKS.HEADING_4] = {
|
|
6491
|
-
nodes: [{
|
|
6492
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6493
|
-
object: 'text'
|
|
6494
|
-
}])
|
|
6495
|
-
}]
|
|
6496
|
-
}, _extends2[Contentful.BLOCKS.HEADING_5] = {
|
|
6497
|
-
nodes: [{
|
|
6498
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6499
|
-
object: 'text'
|
|
6500
|
-
}])
|
|
6501
|
-
}]
|
|
6502
|
-
}, _extends2[Contentful.BLOCKS.HEADING_6] = {
|
|
6503
|
-
nodes: [{
|
|
6504
|
-
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6505
|
-
object: 'text'
|
|
6506
|
-
}])
|
|
6507
|
-
}]
|
|
6508
|
-
}, _extends2), /*#__PURE__*/Contentful.VOID_BLOCKS.reduce(function (blocks, nodeType) {
|
|
6509
|
-
var _extends3;
|
|
6510
|
-
|
|
6511
|
-
return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
|
|
6512
|
-
isVoid: true
|
|
6513
|
-
}, _extends3));
|
|
6514
|
-
}, {}), (_extends4 = {}, _extends4[Contentful.BLOCKS.QUOTE] = {
|
|
6515
|
-
nodes: [{
|
|
6516
|
-
match: [/*#__PURE__*/Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE].map(function (type) {
|
|
6517
|
-
return {
|
|
6518
|
-
type: type
|
|
6519
|
-
};
|
|
6520
|
-
})],
|
|
6521
|
-
min: 1
|
|
6522
|
-
}],
|
|
6523
|
-
normalize: function normalize(editor, error) {
|
|
6524
|
-
if (error.code === 'child_type_invalid') {
|
|
6525
|
-
return editor.unwrapBlockByKey(error.node.key, Contentful.BLOCKS.QUOTE);
|
|
6526
|
-
}
|
|
6527
|
-
}
|
|
6528
|
-
}, _extends4)),
|
|
6529
|
-
inlines: (_inlines = {}, _inlines[Contentful.INLINES.HYPERLINK] = {
|
|
6530
|
-
nodes: [{
|
|
6531
|
-
match: [{
|
|
6532
|
-
object: 'text'
|
|
6533
|
-
}]
|
|
6534
|
-
}]
|
|
6535
|
-
}, _inlines[Contentful.INLINES.ENTRY_HYPERLINK] = {
|
|
6536
|
-
nodes: [{
|
|
6537
|
-
match: [{
|
|
6538
|
-
object: 'text'
|
|
6539
|
-
}]
|
|
6540
|
-
}]
|
|
6541
|
-
}, _inlines[Contentful.INLINES.ASSET_HYPERLINK] = {
|
|
6542
|
-
nodes: [{
|
|
6543
|
-
match: [{
|
|
6544
|
-
object: 'text'
|
|
6545
|
-
}]
|
|
6546
|
-
}]
|
|
6547
|
-
}, _inlines[Contentful.INLINES.EMBEDDED_ENTRY] = {
|
|
6548
|
-
isVoid: true
|
|
6549
|
-
}, _inlines)
|
|
6550
|
-
};
|
|
6551
|
-
|
|
6552
|
-
function getCharacterCount(editor) {
|
|
6553
|
-
var document = contentfulSlateJSAdapter.toContentfulDocument({
|
|
6554
|
-
document: editor.children,
|
|
6555
|
-
schema: schema
|
|
6556
|
-
});
|
|
6557
|
-
return richTextPlainTextRenderer.documentToPlainTextString(document).length;
|
|
6558
|
-
}
|
|
6559
|
-
|
|
6560
|
-
var actionOrigin = {
|
|
6561
|
-
TOOLBAR: 'toolbar-icon',
|
|
6562
|
-
SHORTCUT: 'shortcut',
|
|
6563
|
-
VIEWPORT: 'viewport-interaction',
|
|
6564
|
-
COMMAND_PALETTE: 'command-palette'
|
|
6565
|
-
};
|
|
6566
|
-
var createTrackingPlugin = function createTrackingPlugin(onAction) {
|
|
6567
|
-
var trackingActions = {
|
|
6568
|
-
onViewportAction: function onViewportAction(actionName, data) {
|
|
6569
|
-
if (data === void 0) {
|
|
6570
|
-
data = {};
|
|
6571
|
-
}
|
|
6572
|
-
|
|
6573
|
-
return onAction(actionName, _extends({
|
|
6574
|
-
origin: actionOrigin.VIEWPORT
|
|
6575
|
-
}, data));
|
|
6576
|
-
},
|
|
6577
|
-
onShortcutAction: function onShortcutAction(actionName, data) {
|
|
6578
|
-
if (data === void 0) {
|
|
6579
|
-
data = {};
|
|
6580
|
-
}
|
|
6581
|
-
|
|
6582
|
-
return onAction(actionName, _extends({
|
|
6583
|
-
origin: actionOrigin.SHORTCUT
|
|
6584
|
-
}, data));
|
|
6585
|
-
},
|
|
6586
|
-
onToolbarAction: function onToolbarAction(actionName, data) {
|
|
6587
|
-
if (data === void 0) {
|
|
6588
|
-
data = {};
|
|
6589
|
-
}
|
|
6590
|
-
|
|
6591
|
-
return onAction(actionName, _extends({
|
|
6592
|
-
origin: actionOrigin.TOOLBAR
|
|
6593
|
-
}, data));
|
|
6594
|
-
},
|
|
6595
|
-
onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
|
|
6596
|
-
if (data === void 0) {
|
|
6597
|
-
data = {};
|
|
6598
|
-
}
|
|
6599
|
-
|
|
6600
|
-
return onAction(actionName, _extends({
|
|
6601
|
-
origin: actionOrigin.COMMAND_PALETTE
|
|
6602
|
-
}, data));
|
|
6603
|
-
}
|
|
6604
|
-
};
|
|
6605
|
-
return {
|
|
6606
|
-
key: 'TrackingPlugin',
|
|
6607
|
-
withOverrides: function withOverrides(editor) {
|
|
6608
|
-
var insertData = editor.insertData;
|
|
6609
|
-
editor.tracking = trackingActions;
|
|
6610
|
-
|
|
6611
|
-
editor.insertData = function (data) {
|
|
6612
|
-
var isCopyAndPaste = data.types.length !== 0;
|
|
6613
|
-
|
|
6614
|
-
if (isCopyAndPaste) {
|
|
6615
|
-
var _window$getSelection;
|
|
6616
|
-
|
|
6617
|
-
var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
|
|
6618
|
-
var characterCountBefore = getCharacterCount(editor);
|
|
6619
|
-
setTimeout(function () {
|
|
6620
|
-
var characterCountAfter = getCharacterCount(editor);
|
|
6621
|
-
trackingActions.onShortcutAction('paste', {
|
|
6622
|
-
characterCountAfter: characterCountAfter,
|
|
6623
|
-
characterCountBefore: characterCountBefore,
|
|
6624
|
-
characterCountSelection: characterCountSelection
|
|
6625
|
-
});
|
|
6626
|
-
});
|
|
6627
|
-
}
|
|
6628
|
-
|
|
6629
|
-
insertData(data);
|
|
6630
|
-
};
|
|
6631
|
-
|
|
6632
|
-
return editor;
|
|
6633
|
-
}
|
|
6634
|
-
};
|
|
6635
|
-
};
|
|
6636
|
-
|
|
6637
6648
|
var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
|
|
6638
6649
|
return plateTrailingBlock.createTrailingBlockPlugin({
|
|
6639
6650
|
options: {
|