@atlaskit/editor-core 190.1.25 → 190.1.26

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/afm-cc/tsconfig.json +0 -12
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/presets/default.js +2 -3
  5. package/dist/cjs/version-wrapper.js +1 -1
  6. package/dist/es2019/plugins/index.js +0 -1
  7. package/dist/es2019/presets/default.js +1 -1
  8. package/dist/es2019/version-wrapper.js +1 -1
  9. package/dist/esm/plugins/index.js +0 -1
  10. package/dist/esm/presets/default.js +1 -1
  11. package/dist/esm/version-wrapper.js +1 -1
  12. package/dist/types/plugins/index.d.ts +0 -1
  13. package/dist/types/presets/default.d.ts +1 -1
  14. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  15. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  16. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  17. package/dist/types-ts4.5/presets/default.d.ts +1 -1
  18. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  19. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  20. package/package.json +5 -7
  21. package/dist/cjs/plugins/paste/actions.js +0 -12
  22. package/dist/cjs/plugins/paste/commands.js +0 -255
  23. package/dist/cjs/plugins/paste/edge-cases/index.js +0 -88
  24. package/dist/cjs/plugins/paste/edge-cases/lists.js +0 -107
  25. package/dist/cjs/plugins/paste/handlers.js +0 -935
  26. package/dist/cjs/plugins/paste/index.js +0 -14
  27. package/dist/cjs/plugins/paste/plugin.js +0 -43
  28. package/dist/cjs/plugins/paste/plugins/media.js +0 -207
  29. package/dist/cjs/plugins/paste/pm-plugins/analytics.js +0 -376
  30. package/dist/cjs/plugins/paste/pm-plugins/clipboard-text-serializer.js +0 -43
  31. package/dist/cjs/plugins/paste/pm-plugins/main.js +0 -482
  32. package/dist/cjs/plugins/paste/pm-plugins/plugin-factory.js +0 -42
  33. package/dist/cjs/plugins/paste/reducer.js +0 -41
  34. package/dist/cjs/plugins/paste/types.js +0 -5
  35. package/dist/cjs/plugins/paste/util/index.js +0 -214
  36. package/dist/cjs/plugins/paste/util/tinyMCE.js +0 -183
  37. package/dist/es2019/plugins/paste/actions.js +0 -6
  38. package/dist/es2019/plugins/paste/commands.js +0 -235
  39. package/dist/es2019/plugins/paste/edge-cases/index.js +0 -87
  40. package/dist/es2019/plugins/paste/edge-cases/lists.js +0 -113
  41. package/dist/es2019/plugins/paste/handlers.js +0 -915
  42. package/dist/es2019/plugins/paste/index.js +0 -3
  43. package/dist/es2019/plugins/paste/plugin.js +0 -38
  44. package/dist/es2019/plugins/paste/plugins/media.js +0 -204
  45. package/dist/es2019/plugins/paste/pm-plugins/analytics.js +0 -332
  46. package/dist/es2019/plugins/paste/pm-plugins/clipboard-text-serializer.js +0 -37
  47. package/dist/es2019/plugins/paste/pm-plugins/main.js +0 -451
  48. package/dist/es2019/plugins/paste/pm-plugins/plugin-factory.js +0 -30
  49. package/dist/es2019/plugins/paste/reducer.js +0 -32
  50. package/dist/es2019/plugins/paste/types.js +0 -1
  51. package/dist/es2019/plugins/paste/util/index.js +0 -209
  52. package/dist/es2019/plugins/paste/util/tinyMCE.js +0 -168
  53. package/dist/esm/plugins/paste/actions.js +0 -6
  54. package/dist/esm/plugins/paste/commands.js +0 -248
  55. package/dist/esm/plugins/paste/edge-cases/index.js +0 -81
  56. package/dist/esm/plugins/paste/edge-cases/lists.js +0 -98
  57. package/dist/esm/plugins/paste/handlers.js +0 -914
  58. package/dist/esm/plugins/paste/index.js +0 -3
  59. package/dist/esm/plugins/paste/plugin.js +0 -37
  60. package/dist/esm/plugins/paste/plugins/media.js +0 -199
  61. package/dist/esm/plugins/paste/pm-plugins/analytics.js +0 -364
  62. package/dist/esm/plugins/paste/pm-plugins/clipboard-text-serializer.js +0 -37
  63. package/dist/esm/plugins/paste/pm-plugins/main.js +0 -469
  64. package/dist/esm/plugins/paste/pm-plugins/plugin-factory.js +0 -36
  65. package/dist/esm/plugins/paste/reducer.js +0 -34
  66. package/dist/esm/plugins/paste/types.js +0 -1
  67. package/dist/esm/plugins/paste/util/index.js +0 -194
  68. package/dist/esm/plugins/paste/util/tinyMCE.js +0 -176
  69. package/dist/types/plugins/paste/actions.d.ts +0 -21
  70. package/dist/types/plugins/paste/commands.d.ts +0 -30
  71. package/dist/types/plugins/paste/edge-cases/index.d.ts +0 -11
  72. package/dist/types/plugins/paste/edge-cases/lists.d.ts +0 -18
  73. package/dist/types/plugins/paste/handlers.d.ts +0 -55
  74. package/dist/types/plugins/paste/index.d.ts +0 -4
  75. package/dist/types/plugins/paste/plugin.d.ts +0 -2
  76. package/dist/types/plugins/paste/plugins/media.d.ts +0 -23
  77. package/dist/types/plugins/paste/pm-plugins/analytics.d.ts +0 -44
  78. package/dist/types/plugins/paste/pm-plugins/clipboard-text-serializer.d.ts +0 -13
  79. package/dist/types/plugins/paste/pm-plugins/main.d.ts +0 -12
  80. package/dist/types/plugins/paste/pm-plugins/plugin-factory.d.ts +0 -3
  81. package/dist/types/plugins/paste/reducer.d.ts +0 -3
  82. package/dist/types/plugins/paste/types.d.ts +0 -1
  83. package/dist/types/plugins/paste/util/index.d.ts +0 -21
  84. package/dist/types/plugins/paste/util/tinyMCE.d.ts +0 -32
  85. package/dist/types-ts4.5/plugins/paste/actions.d.ts +0 -21
  86. package/dist/types-ts4.5/plugins/paste/commands.d.ts +0 -30
  87. package/dist/types-ts4.5/plugins/paste/edge-cases/index.d.ts +0 -11
  88. package/dist/types-ts4.5/plugins/paste/edge-cases/lists.d.ts +0 -18
  89. package/dist/types-ts4.5/plugins/paste/handlers.d.ts +0 -55
  90. package/dist/types-ts4.5/plugins/paste/index.d.ts +0 -4
  91. package/dist/types-ts4.5/plugins/paste/plugin.d.ts +0 -2
  92. package/dist/types-ts4.5/plugins/paste/plugins/media.d.ts +0 -23
  93. package/dist/types-ts4.5/plugins/paste/pm-plugins/analytics.d.ts +0 -44
  94. package/dist/types-ts4.5/plugins/paste/pm-plugins/clipboard-text-serializer.d.ts +0 -13
  95. package/dist/types-ts4.5/plugins/paste/pm-plugins/main.d.ts +0 -12
  96. package/dist/types-ts4.5/plugins/paste/pm-plugins/plugin-factory.d.ts +0 -3
  97. package/dist/types-ts4.5/plugins/paste/reducer.d.ts +0 -3
  98. package/dist/types-ts4.5/plugins/paste/types.d.ts +0 -1
  99. package/dist/types-ts4.5/plugins/paste/util/index.d.ts +0 -21
  100. package/dist/types-ts4.5/plugins/paste/util/tinyMCE.d.ts +0 -32
@@ -1,935 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.doesSelectionWhichStartsOrEndsInListContainEntireList = void 0;
8
- exports.flattenNestedListInSlice = flattenNestedListInSlice;
9
- exports.handleCodeBlock = handleCodeBlock;
10
- exports.handleExpandPasteInTable = handleExpandPasteInTable;
11
- exports.handleMacroAutoConvert = handleMacroAutoConvert;
12
- exports.handleMarkdown = handleMarkdown;
13
- exports.handleMediaSingle = handleMediaSingle;
14
- exports.handleMention = handleMention;
15
- exports.handleParagraphBlockMarks = handleParagraphBlockMarks;
16
- exports.handlePasteAsPlainText = handlePasteAsPlainText;
17
- exports.handlePasteIntoCaption = handlePasteIntoCaption;
18
- exports.handlePasteIntoTaskOrDecisionOrPanel = handlePasteIntoTaskOrDecisionOrPanel;
19
- exports.handlePasteLinkOnSelectedText = handlePasteLinkOnSelectedText;
20
- exports.handlePasteNonNestableBlockNodesIntoList = handlePasteNonNestableBlockNodesIntoList;
21
- exports.handlePastePanelOrDecisionContentIntoList = handlePastePanelOrDecisionContentIntoList;
22
- exports.handlePastePreservingMarks = handlePastePreservingMarks;
23
- exports.handleRichText = handleRichText;
24
- exports.handleSelectedTable = void 0;
25
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
26
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
27
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
28
- var _history = require("@atlaskit/editor-prosemirror/history");
29
- var _model = require("@atlaskit/editor-prosemirror/model");
30
- var _state = require("@atlaskit/editor-prosemirror/state");
31
- var _utils = require("@atlaskit/editor-prosemirror/utils");
32
- var _v = _interopRequireDefault(require("uuid/v4"));
33
- var _utils2 = require("@atlaskit/editor-tables/utils");
34
- var _utils3 = require("@atlaskit/editor-common/utils");
35
- var _coreUtils = require("@atlaskit/editor-common/core-utils");
36
- var _analytics = require("@atlaskit/editor-common/analytics");
37
- var _selection = require("@atlaskit/editor-common/selection");
38
- var _util = require("./util");
39
- var _edgeCases = require("./edge-cases");
40
- var _commands = require("./commands");
41
- var _pluginFactory = require("./pm-plugins/plugin-factory");
42
- var _mark = require("@atlaskit/editor-common/mark");
43
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
44
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
45
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
46
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
47
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // TODO: ED-20519 Needs Macro extraction
48
- /** Helper type for single arg function */
49
-
50
- /**
51
- * Compose 1 to n functions.
52
- * @param func first function
53
- * @param funcs additional functions
54
- */
55
- function compose(func) {
56
- for (var _len = arguments.length, funcs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
57
- funcs[_key - 1] = arguments[_key];
58
- }
59
- var allFuncs = [func].concat(funcs);
60
- return function composed(raw) {
61
- return allFuncs.reduceRight(function (memo, func) {
62
- return func(memo);
63
- }, raw);
64
- };
65
- }
66
-
67
- // remove text attribute from mention for copy/paste (GDPR)
68
- function handleMention(slice, schema) {
69
- return (0, _utils3.mapSlice)(slice, function (node) {
70
- if (node.type.name === schema.nodes.mention.name) {
71
- var mention = node.attrs;
72
- var newMention = _objectSpread(_objectSpread({}, mention), {}, {
73
- text: ''
74
- });
75
- return schema.nodes.mention.create(newMention, node.content, node.marks);
76
- }
77
- return node;
78
- });
79
- }
80
- function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChangedTr) {
81
- return function (state, dispatch) {
82
- var _slice$content$firstC, _transformedSlice$con;
83
- var schema = state.schema,
84
- selection = state.tr.selection;
85
- var codeMark = schema.marks.code,
86
- _schema$nodes = schema.nodes,
87
- decisionItem = _schema$nodes.decisionItem,
88
- emoji = _schema$nodes.emoji,
89
- hardBreak = _schema$nodes.hardBreak,
90
- mention = _schema$nodes.mention,
91
- paragraph = _schema$nodes.paragraph,
92
- taskItem = _schema$nodes.taskItem,
93
- text = _schema$nodes.text,
94
- panel = _schema$nodes.panel,
95
- bulletList = _schema$nodes.bulletList,
96
- orderedList = _schema$nodes.orderedList,
97
- taskList = _schema$nodes.taskList,
98
- listItem = _schema$nodes.listItem,
99
- expand = _schema$nodes.expand,
100
- heading = _schema$nodes.heading;
101
- var selectionIsValidNode = state.selection instanceof _state.NodeSelection && ['decisionList', 'decisionItem', 'taskList', 'taskItem'].includes(state.selection.node.type.name);
102
- var selectionHasValidParentNode = (0, _utils.hasParentNodeOfType)([decisionItem, taskItem, panel])(state.selection);
103
- var selectionIsPanel = (0, _utils.hasParentNodeOfType)([panel])(state.selection);
104
-
105
- // Some types of content should be handled by the default handler, not this function.
106
- // Check through slice content to see if it contains an invalid node.
107
- var sliceIsInvalid = false;
108
- slice.content.nodesBetween(0, slice.content.size, function (node) {
109
- if (node.type === bulletList || node.type === orderedList || node.type === expand || node.type === heading || node.type === listItem) {
110
- sliceIsInvalid = true;
111
- }
112
- if (selectionIsPanel && node.type === taskList) {
113
- sliceIsInvalid = true;
114
- }
115
- });
116
-
117
- // If the selection is a panel,
118
- // and the slice's first node is a paragraph
119
- // and it is not from a depth that would indicate it being from inside from another node (e.g. text from a decision)
120
- // then we can rely on the default behaviour.
121
- var sliceIsAPanelReceivingLowDepthText = selectionIsPanel && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === paragraph && slice.openEnd < 2;
122
- if (sliceIsInvalid || sliceIsAPanelReceivingLowDepthText || !selectionIsValidNode && !selectionHasValidParentNode) {
123
- return false;
124
- }
125
- var filters = [(0, _utils3.linkifyContent)(schema)];
126
- var selectionMarks = selection.$head.marks();
127
- if (selection instanceof _state.TextSelection && Array.isArray(selectionMarks) && selectionMarks.length > 0 && (0, _util.hasOnlyNodesOfType)(paragraph, text, emoji, mention, hardBreak)(slice) && (!codeMark.isInSet(selectionMarks) || (0, _mark.anyMarkActive)(state, codeMark)) // check if there is a code mark anywhere in the selection
128
- ) {
129
- filters.push((0, _util.applyTextMarksToSlice)(schema, selection.$head.marks()));
130
- }
131
- var transformedSlice = compose.apply(null, filters)(slice);
132
- var tr = (0, _history.closeHistory)(state.tr);
133
- var transformedSliceIsValidNode = transformedSlice.content.firstChild.type.inlineContent || ['decisionList', 'decisionItem', 'taskList', 'taskItem', 'panel'].includes(transformedSlice.content.firstChild.type.name) && !(0, _utils3.isInListItem)(state);
134
- // If the slice or the selection are valid nodes to handle,
135
- // and the slice is not a whole node (i.e. openStart is 1 and openEnd is 0)
136
- // or the slice's first node is a paragraph,
137
- // then we can replace the selection with our slice.
138
- if ((transformedSliceIsValidNode || selectionIsValidNode) && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
139
- // Whole codeblock node has reverse slice depths.
140
- transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
141
- tr.replaceSelection(transformedSlice).scrollIntoView();
142
- } else {
143
- // This maintains both the selection (destination) and the slice (paste content).
144
- (0, _utils.safeInsert)(transformedSlice.content)(tr).scrollIntoView();
145
- }
146
- queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 || queueCardsFromChangedTr(state, tr, _analytics.INPUT_METHOD.CLIPBOARD);
147
- if (dispatch) {
148
- dispatch(tr);
149
- }
150
- return true;
151
- };
152
- }
153
- function handlePasteNonNestableBlockNodesIntoList(slice) {
154
- return function (state, dispatch) {
155
- var _tr$doc$nodeAt, _sliceContent$firstCh, _findParentNodeOfType;
156
- var tr = state.tr;
157
- var selection = tr.selection;
158
- var $from = selection.$from,
159
- $to = selection.$to,
160
- from = selection.from,
161
- to = selection.to;
162
- var _state$schema$nodes = state.schema.nodes,
163
- orderedList = _state$schema$nodes.orderedList,
164
- bulletList = _state$schema$nodes.bulletList,
165
- listItem = _state$schema$nodes.listItem;
166
-
167
- // Selected nodes
168
- var selectionParentListItemNode = (0, _utils.findParentNodeOfType)(listItem)(selection);
169
- var selectionParentListNodeWithPos = (0, _utils.findParentNodeOfType)([bulletList, orderedList])(selection);
170
- var selectionParentListNode = selectionParentListNodeWithPos === null || selectionParentListNodeWithPos === void 0 ? void 0 : selectionParentListNodeWithPos.node;
171
-
172
- // Slice info
173
- var sliceContent = slice.content;
174
- var sliceIsListItems = (0, _utils3.isListNode)(sliceContent.firstChild) && (0, _utils3.isListNode)(sliceContent.lastChild);
175
-
176
- // Find case of slices that can be inserted into a list item
177
- // (eg. paragraphs, list items, code blocks, media single)
178
- // These scenarios already get handled elsewhere and don't need to split the list
179
- var sliceContainsBlockNodesOtherThanThoseAllowedInListItem = false;
180
- slice.content.forEach(function (child) {
181
- var _listItem$spec$conten;
182
- if (!listItem || child.isBlock && !((_listItem$spec$conten = listItem.spec.content) !== null && _listItem$spec$conten !== void 0 && _listItem$spec$conten.includes(child.type.name))) {
183
- sliceContainsBlockNodesOtherThanThoseAllowedInListItem = true;
184
- }
185
- });
186
- if (!selectionParentListItemNode || !sliceContent || (0, _utils.canInsert)($from, sliceContent) ||
187
- // eg. inline nodes that can be inserted in a list item
188
- !sliceContainsBlockNodesOtherThanThoseAllowedInListItem || sliceIsListItems || !selectionParentListNodeWithPos) {
189
- return false;
190
- }
191
-
192
- // Offsets
193
- var listWrappingOffset = $to.depth - selectionParentListNodeWithPos.depth + 1; // difference in depth between to position and list node
194
- var listItemWrappingOffset = $to.depth - selectionParentListNodeWithPos.depth; // difference in depth between to position and list item node
195
-
196
- // Anything to do with nested lists should safeInsert and not be handled here
197
- var grandParentListNode = (0, _utils.findParentNodeOfTypeClosestToPos)(tr.doc.resolve(selectionParentListNodeWithPos.pos), [bulletList, orderedList]);
198
- var selectionIsInNestedList = !!grandParentListNode;
199
- var selectedListItemHasNestedList = false;
200
- selectionParentListItemNode.node.content.forEach(function (child) {
201
- if ((0, _utils3.isListNode)(child)) {
202
- selectedListItemHasNestedList = true;
203
- }
204
- });
205
- if (selectedListItemHasNestedList || selectionIsInNestedList) {
206
- return false;
207
- }
208
-
209
- // Node after the insert position
210
- var nodeAfterInsertPositionIsListItem = ((_tr$doc$nodeAt = tr.doc.nodeAt(to + listItemWrappingOffset)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.type.name) === 'listItem';
211
-
212
- // Get the next list items position (used later to find the split out ordered list)
213
- var indexOfNextListItem = $to.indexAfter($to.depth - listItemWrappingOffset);
214
- var positionOfNextListItem = tr.doc.resolve(selectionParentListNodeWithPos.pos + 1).posAtIndex(indexOfNextListItem);
215
-
216
- // These nodes paste as plain text by default so need to be handled differently
217
- var sliceContainsNodeThatPastesAsPlainText = sliceContent.firstChild && ['taskItem', 'taskList', 'heading', 'blockquote'].includes(sliceContent.firstChild.type.name);
218
-
219
- // Work out position to replace up to
220
- var replaceTo;
221
- if (sliceContainsNodeThatPastesAsPlainText && nodeAfterInsertPositionIsListItem) {
222
- replaceTo = to + listItemWrappingOffset;
223
- } else if (sliceContainsNodeThatPastesAsPlainText || !nodeAfterInsertPositionIsListItem) {
224
- replaceTo = to;
225
- } else {
226
- replaceTo = to + listWrappingOffset;
227
- }
228
-
229
- // handle the insertion of the slice
230
- if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
231
- tr.replaceWith(from, replaceTo, sliceContent).scrollIntoView();
232
- } else {
233
- // When the selection is not at the end of a list item
234
- // eg. middle of list item, start of list item
235
- tr.replaceSelection(slice).scrollIntoView();
236
- }
237
-
238
- // Find the ordered list node after the pasted content so we can set it's order
239
- var mappedPositionOfNextListItem = tr.mapping.map(positionOfNextListItem);
240
- if (mappedPositionOfNextListItem > tr.doc.nodeSize) {
241
- return false;
242
- }
243
- var nodeAfterPastedContentResolvedPos = (0, _utils.findParentNodeOfTypeClosestToPos)(tr.doc.resolve(mappedPositionOfNextListItem), [orderedList]);
244
-
245
- // Work out the new split out lists 'order' (the number it starts from)
246
- var originalParentOrderedListNodeOrder = selectionParentListNode === null || selectionParentListNode === void 0 ? void 0 : selectionParentListNode.attrs.order;
247
- var numOfListItemsInOriginalList = (_findParentNodeOfType = (0, _utils.findParentNodeOfTypeClosestToPos)(tr.doc.resolve(from - 1), [orderedList])) === null || _findParentNodeOfType === void 0 ? void 0 : _findParentNodeOfType.node.childCount;
248
-
249
- // Set the new split out lists order attribute
250
- if (typeof originalParentOrderedListNodeOrder === 'number' && numOfListItemsInOriginalList && nodeAfterPastedContentResolvedPos) {
251
- tr.setNodeMarkup(nodeAfterPastedContentResolvedPos.pos, orderedList, _objectSpread(_objectSpread({}, nodeAfterPastedContentResolvedPos.node.attrs), {}, {
252
- order: originalParentOrderedListNodeOrder + numOfListItemsInOriginalList
253
- }));
254
- }
255
-
256
- // dispatch transaction
257
- if (tr.docChanged) {
258
- if (dispatch) {
259
- dispatch(tr);
260
- }
261
- return true;
262
- }
263
- return false;
264
- };
265
- }
266
- var doesSelectionWhichStartsOrEndsInListContainEntireList = exports.doesSelectionWhichStartsOrEndsInListContainEntireList = function doesSelectionWhichStartsOrEndsInListContainEntireList(selection, findRootParentListNode) {
267
- var $from = selection.$from,
268
- $to = selection.$to,
269
- from = selection.from,
270
- to = selection.to;
271
- var selectionParentListItemNodeResolvedPos = findRootParentListNode ? findRootParentListNode($from) || findRootParentListNode($to) : null;
272
- var selectionParentListNode = selectionParentListItemNodeResolvedPos === null || selectionParentListItemNodeResolvedPos === void 0 ? void 0 : selectionParentListItemNodeResolvedPos.parent;
273
- if (!selectionParentListItemNodeResolvedPos || !selectionParentListNode) {
274
- return false;
275
- }
276
- var startOfEntireList = $from.pos < $to.pos ? selectionParentListItemNodeResolvedPos.pos + $from.depth - 1 : selectionParentListItemNodeResolvedPos.pos + $to.depth - 1;
277
- var endOfEntireList = $from.pos < $to.pos ? selectionParentListItemNodeResolvedPos.pos + selectionParentListNode.nodeSize - $to.depth - 1 : selectionParentListItemNodeResolvedPos.pos + selectionParentListNode.nodeSize - $from.depth - 1;
278
- if (!startOfEntireList || !endOfEntireList) {
279
- return false;
280
- }
281
- if (from < to) {
282
- return startOfEntireList >= $from.pos && endOfEntireList <= $to.pos;
283
- } else if (from > to) {
284
- return startOfEntireList >= $to.pos && endOfEntireList <= $from.pos;
285
- } else {
286
- return false;
287
- }
288
- };
289
- function handlePastePanelOrDecisionContentIntoList(slice, findRootParentListNode) {
290
- return function (state, dispatch) {
291
- var schema = state.schema,
292
- tr = state.tr;
293
- var selection = tr.selection;
294
- // Check this pasting action is related to copy content from panel node into a selected the list node
295
- var blockNode = slice.content.firstChild;
296
- var isSliceWholeNode = slice.openStart === 0 && slice.openEnd === 0;
297
- var selectionParentListItemNode = selection.$to.node(selection.$to.depth - 1);
298
- var sliceIsWholeNodeButShouldNotReplaceSelection = isSliceWholeNode && !doesSelectionWhichStartsOrEndsInListContainEntireList(selection, findRootParentListNode);
299
- if (!selectionParentListItemNode || (selectionParentListItemNode === null || selectionParentListItemNode === void 0 ? void 0 : selectionParentListItemNode.type) !== schema.nodes.listItem || !blockNode || !['panel', 'decisionList'].includes(blockNode === null || blockNode === void 0 ? void 0 : blockNode.type.name) || slice.content.childCount > 1 || (blockNode === null || blockNode === void 0 ? void 0 : blockNode.content.firstChild) === undefined || sliceIsWholeNodeButShouldNotReplaceSelection) {
300
- return false;
301
- }
302
-
303
- // Paste the panel node contents extracted instead of pasting the entire panel node
304
- tr.replaceSelection(slice).scrollIntoView();
305
- if (dispatch) {
306
- dispatch(tr);
307
- }
308
- return true;
309
- };
310
- }
311
-
312
- // If we paste a link onto some selected text, apply the link as a mark
313
- function handlePasteLinkOnSelectedText(slice) {
314
- return function (state, dispatch) {
315
- var schema = state.schema,
316
- selection = state.selection,
317
- _state$selection = state.selection,
318
- from = _state$selection.from,
319
- to = _state$selection.to,
320
- tr = state.tr;
321
- var linkMark;
322
-
323
- // check if we have a link on the clipboard
324
- if (slice.content.childCount === 1 && (0, _utils3.isParagraph)(slice.content.child(0), schema)) {
325
- var paragraph = slice.content.child(0);
326
- if (paragraph.content.childCount === 1 && (0, _utils3.isText)(paragraph.content.child(0), schema)) {
327
- var text = paragraph.content.child(0);
328
-
329
- // If pasteType is plain text, then
330
- // @atlaskit/editor-markdown-transformer in getMarkdownSlice decode
331
- // url before setting text property of text node.
332
- // However href of marks will be without decoding.
333
- // So, if there is character (e.g space) in url eligible escaping then
334
- // mark.attrs.href will not be equal to text.text.
335
- // That's why decoding mark.attrs.href before comparing.
336
- // However, if pasteType is richText, that means url in text.text
337
- // and href in marks, both won't be decoded.
338
- linkMark = text.marks.find(function (mark) {
339
- return (0, _utils3.isLinkMark)(mark, schema) && (mark.attrs.href === text.text || decodeURI(mark.attrs.href) === text.text);
340
- });
341
- }
342
- }
343
-
344
- // if we have a link, apply it to the selected text if we have any and it's allowed
345
- if (linkMark && selection instanceof _state.TextSelection && !selection.empty && (0, _utils3.canLinkBeCreatedInRange)(from, to)(state)) {
346
- tr.addMark(from, to, linkMark);
347
- if (dispatch) {
348
- dispatch(tr);
349
- }
350
- return true;
351
- }
352
- return false;
353
- };
354
- }
355
- function handlePasteAsPlainText(slice, _event, editorAnalyticsAPI) {
356
- return function (state, dispatch, view) {
357
- var _input;
358
- if (!view) {
359
- return false;
360
- }
361
-
362
- // prosemirror-bump-fix
363
- // Yes, this is wrong by default. But, we need to keep the private PAI usage to unblock the prosemirror bump
364
- // So, this code will make sure we are checking for both version (current and the newest prosemirror-view version
365
- var isShiftKeyPressed = view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey);
366
- // In case of SHIFT+CMD+V ("Paste and Match Style") we don't want to run the usual
367
- // fuzzy matching of content. ProseMirror already handles this scenario and will
368
- // provide us with slice containing paragraphs with plain text, which we decorate
369
- // with "stored marks".
370
- // @see prosemirror-view/src/clipboard.js:parseFromClipboard()).
371
- // @see prosemirror-view/src/input.js:doPaste().
372
- if (isShiftKeyPressed) {
373
- var tr = (0, _history.closeHistory)(state.tr);
374
- var _tr = tr,
375
- selection = _tr.selection;
376
-
377
- // <- using the same internal flag that prosemirror-view is using
378
-
379
- // if user has selected table we need custom logic to replace the table
380
- tr = (0, _utils2.replaceSelectedTable)(state, slice);
381
-
382
- // add analytics after replacing selected table
383
- tr = (0, _util.addReplaceSelectedTableAnalytics)(state, tr, editorAnalyticsAPI);
384
-
385
- // otherwise just replace the selection
386
- if (!tr.docChanged) {
387
- tr.replaceSelection(slice);
388
- }
389
- (state.storedMarks || []).forEach(function (mark) {
390
- tr.addMark(selection.from, selection.from + slice.size, mark);
391
- });
392
- tr.scrollIntoView();
393
- if (dispatch) {
394
- dispatch(tr);
395
- }
396
- return true;
397
- }
398
- return false;
399
- };
400
- }
401
- function handlePastePreservingMarks(slice, queueCardsFromChangedTr) {
402
- return function (state, dispatch) {
403
- var schema = state.schema,
404
- selection = state.tr.selection;
405
- var _schema$marks = schema.marks,
406
- codeMark = _schema$marks.code,
407
- annotationMark = _schema$marks.annotation,
408
- _schema$nodes2 = schema.nodes,
409
- bulletList = _schema$nodes2.bulletList,
410
- emoji = _schema$nodes2.emoji,
411
- hardBreak = _schema$nodes2.hardBreak,
412
- heading = _schema$nodes2.heading,
413
- listItem = _schema$nodes2.listItem,
414
- mention = _schema$nodes2.mention,
415
- orderedList = _schema$nodes2.orderedList,
416
- text = _schema$nodes2.text;
417
- if (!(selection instanceof _state.TextSelection)) {
418
- return false;
419
- }
420
- var selectionMarks = selection.$head.marks();
421
- if (selectionMarks.length === 0) {
422
- return false;
423
- }
424
-
425
- // special case for codeMark: will preserve mark only if codeMark is currently active
426
- // won't preserve mark if cursor is on the edge on the mark (namely inactive)
427
- var hasActiveCodeMark = codeMark && codeMark.isInSet(selectionMarks) && (0, _mark.anyMarkActive)(state, codeMark);
428
- var hasAnnotationMark = annotationMark && annotationMark.isInSet(selectionMarks);
429
- var selectionIsHeading = (0, _utils.hasParentNodeOfType)([heading])(state.selection);
430
-
431
- // if the pasted data is one of the node types below
432
- // we apply current selection marks to the pasted slice
433
- if ((0, _util.hasOnlyNodesOfType)(bulletList, hardBreak, heading, listItem, text, emoji, mention, orderedList)(slice) || selectionIsHeading || hasActiveCodeMark || hasAnnotationMark) {
434
- var transformedSlice = (0, _util.applyTextMarksToSlice)(schema, selectionMarks)(slice);
435
- var tr = (0, _history.closeHistory)(state.tr).replaceSelection(transformedSlice).setStoredMarks(selectionMarks).scrollIntoView();
436
- queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 || queueCardsFromChangedTr(state, tr, _analytics.INPUT_METHOD.CLIPBOARD);
437
- if (dispatch) {
438
- dispatch(tr);
439
- }
440
- return true;
441
- }
442
- return false;
443
- };
444
- }
445
- function getSmartLinkAdf(_x, _x2, _x3) {
446
- return _getSmartLinkAdf.apply(this, arguments);
447
- }
448
- function _getSmartLinkAdf() {
449
- _getSmartLinkAdf = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(text, type, cardOptions) {
450
- var provider;
451
- return _regenerator.default.wrap(function _callee$(_context) {
452
- while (1) switch (_context.prev = _context.next) {
453
- case 0:
454
- if (cardOptions.provider) {
455
- _context.next = 2;
456
- break;
457
- }
458
- throw Error('No card provider found');
459
- case 2:
460
- _context.next = 4;
461
- return cardOptions.provider;
462
- case 4:
463
- provider = _context.sent;
464
- _context.next = 7;
465
- return provider.resolve(text, type);
466
- case 7:
467
- return _context.abrupt("return", _context.sent);
468
- case 8:
469
- case "end":
470
- return _context.stop();
471
- }
472
- }, _callee);
473
- }));
474
- return _getSmartLinkAdf.apply(this, arguments);
475
- }
476
- function insertAutoMacro(slice, macro, view, from, to) {
477
- if (view) {
478
- // insert the text or linkified/md-converted clipboard data
479
- var selection = view.state.tr.selection;
480
- var tr;
481
- var before;
482
- if (typeof from === 'number' && typeof to === 'number') {
483
- tr = view.state.tr.replaceRange(from, to, slice);
484
- before = tr.mapping.map(from, -1);
485
- } else {
486
- tr = view.state.tr.replaceSelection(slice);
487
- before = tr.mapping.map(selection.from, -1);
488
- }
489
- view.dispatch(tr);
490
-
491
- // replace the text with the macro as a separate transaction
492
- // so the autoconversion generates 2 undo steps
493
- view.dispatch((0, _history.closeHistory)(view.state.tr).replaceRangeWith(before, before + slice.size, macro).scrollIntoView());
494
- return true;
495
- }
496
- return false;
497
- }
498
- function handleMacroAutoConvert(text, slice, queueCardsFromChangedTr, runMacroAutoConvert, cardsOptions, extensionAutoConverter) {
499
- return function (state, dispatch, view) {
500
- var macro = null;
501
-
502
- // try to use auto convert from extension provider first
503
- if (extensionAutoConverter) {
504
- var extension = extensionAutoConverter(text);
505
- if (extension) {
506
- macro = _model.Node.fromJSON(state.schema, extension);
507
- }
508
- }
509
-
510
- // then try from macro provider (which will be removed some time in the future)
511
- if (!macro) {
512
- var _runMacroAutoConvert;
513
- macro = (_runMacroAutoConvert = runMacroAutoConvert === null || runMacroAutoConvert === void 0 ? void 0 : runMacroAutoConvert(state, text)) !== null && _runMacroAutoConvert !== void 0 ? _runMacroAutoConvert : null;
514
- }
515
- if (macro) {
516
- /**
517
- * if FF enabled, run through smart links and check for result
518
- */
519
- if (cardsOptions && cardsOptions.resolveBeforeMacros && cardsOptions.resolveBeforeMacros.length) {
520
- var _startTrackingPastedM;
521
- if (cardsOptions.resolveBeforeMacros.indexOf(macro.attrs.extensionKey) < 0) {
522
- return insertAutoMacro(slice, macro, view);
523
- }
524
- if (!view) {
525
- throw new Error('View is missing');
526
- }
527
- var trackingId = (0, _v.default)();
528
- var trackingFrom = "handleMacroAutoConvert-from-".concat(trackingId);
529
- var trackingTo = "handleMacroAutoConvert-to-".concat(trackingId);
530
- (0, _commands.startTrackingPastedMacroPositions)((_startTrackingPastedM = {}, (0, _defineProperty2.default)(_startTrackingPastedM, trackingFrom, state.selection.from), (0, _defineProperty2.default)(_startTrackingPastedM, trackingTo, state.selection.to), _startTrackingPastedM))(state, dispatch);
531
- getSmartLinkAdf(text, 'inline', cardsOptions).then(function () {
532
- // we use view.state rather than state because state becomes a stale
533
- // state reference after getSmartLinkAdf's async work
534
- var _getPastePluginState = (0, _pluginFactory.getPluginState)(view.state),
535
- pastedMacroPositions = _getPastePluginState.pastedMacroPositions;
536
- if (dispatch) {
537
- handleMarkdown(slice, queueCardsFromChangedTr, pastedMacroPositions[trackingFrom], pastedMacroPositions[trackingTo])(view.state, dispatch);
538
- }
539
- }).catch(function () {
540
- var _getPastePluginState2 = (0, _pluginFactory.getPluginState)(view.state),
541
- pastedMacroPositions = _getPastePluginState2.pastedMacroPositions;
542
- insertAutoMacro(slice, macro, view, pastedMacroPositions[trackingFrom], pastedMacroPositions[trackingTo]);
543
- }).finally(function () {
544
- (0, _commands.stopTrackingPastedMacroPositions)([trackingFrom, trackingTo])(view.state, dispatch);
545
- });
546
- return true;
547
- }
548
- return insertAutoMacro(slice, macro, view);
549
- }
550
- return !!macro;
551
- };
552
- }
553
- function handleCodeBlock(text) {
554
- return function (state, dispatch) {
555
- var codeBlock = state.schema.nodes.codeBlock;
556
- if (text && (0, _utils.hasParentNodeOfType)(codeBlock)(state.selection)) {
557
- var tr = (0, _history.closeHistory)(state.tr);
558
- tr.scrollIntoView();
559
- if (dispatch) {
560
- dispatch(tr.insertText(text));
561
- }
562
- return true;
563
- }
564
- return false;
565
- };
566
- }
567
- function isOnlyMedia(state, slice) {
568
- var media = state.schema.nodes.media;
569
- return slice.content.childCount === 1 && slice.content.firstChild.type === media;
570
- }
571
- function isOnlyMediaSingle(state, slice) {
572
- var mediaSingle = state.schema.nodes.mediaSingle;
573
- return mediaSingle && slice.content.childCount === 1 && slice.content.firstChild.type === mediaSingle;
574
- }
575
- function handleMediaSingle(inputMethod, insertMediaAsMediaSingle) {
576
- return function (slice) {
577
- return function (state, dispatch, view) {
578
- if (view) {
579
- if (isOnlyMedia(state, slice)) {
580
- var _insertMediaAsMediaSi;
581
- return (_insertMediaAsMediaSi = insertMediaAsMediaSingle === null || insertMediaAsMediaSingle === void 0 ? void 0 : insertMediaAsMediaSingle(view, slice.content.firstChild, inputMethod)) !== null && _insertMediaAsMediaSi !== void 0 ? _insertMediaAsMediaSi : false;
582
- }
583
- if ((0, _coreUtils.insideTable)(state) && isOnlyMediaSingle(state, slice)) {
584
- var tr = state.tr.replaceSelection(slice);
585
- var nextPos = tr.doc.resolve(tr.mapping.map(state.selection.$from.pos));
586
- if (dispatch) {
587
- dispatch(tr.setSelection(new _selection.GapCursorSelection(nextPos, _selection.Side.RIGHT)));
588
- }
589
- return true;
590
- }
591
- }
592
- return false;
593
- };
594
- };
595
- }
596
- var checkExpand = function checkExpand(slice) {
597
- var hasExpand = false;
598
- slice.content.forEach(function (node) {
599
- if (node.type.name === 'expand') {
600
- hasExpand = true;
601
- }
602
- });
603
- return hasExpand;
604
- };
605
- function handleExpandPasteInTable(slice) {
606
- return function (state, dispatch) {
607
- // Do not handle expand if it's not being pasted into a table
608
- // OR if it's nested within another node when being pasted into a table
609
- if (!(0, _coreUtils.insideTable)(state) || !checkExpand(slice)) {
610
- return false;
611
- }
612
- var _state$schema$nodes2 = state.schema.nodes,
613
- expand = _state$schema$nodes2.expand,
614
- nestedExpand = _state$schema$nodes2.nestedExpand;
615
- var tr = state.tr;
616
- var hasExpand = false;
617
- var newSlice = (0, _utils3.mapSlice)(slice, function (maybeNode) {
618
- if (maybeNode.type === expand) {
619
- hasExpand = true;
620
- try {
621
- return nestedExpand.createChecked(maybeNode.attrs, maybeNode.content, maybeNode.marks);
622
- } catch (e) {
623
- tr = (0, _utils.safeInsert)(maybeNode, tr.selection.$to.pos)(tr);
624
- return _model.Fragment.empty;
625
- }
626
- }
627
- return maybeNode;
628
- });
629
- if (hasExpand && dispatch) {
630
- // If the slice is a subset, we can let PM replace the selection
631
- // it will insert as text where it can't place the node.
632
- // Otherwise we use safeInsert to insert below instead of
633
- // replacing/splitting the current node.
634
- if (slice.openStart > 1 && slice.openEnd > 1) {
635
- dispatch(tr.replaceSelection(newSlice));
636
- } else {
637
- dispatch((0, _utils.safeInsert)(newSlice.content)(tr));
638
- }
639
- return true;
640
- }
641
- return false;
642
- };
643
- }
644
- function handleMarkdown(markdownSlice, queueCardsFromChangedTr, from, to) {
645
- return function (state, dispatch) {
646
- var tr = (0, _history.closeHistory)(state.tr);
647
- var pastesFrom = typeof from === 'number' ? from : tr.selection.from;
648
- if (typeof from === 'number' && typeof to === 'number') {
649
- tr.replaceRange(from, to, markdownSlice);
650
- } else {
651
- tr.replaceSelection(markdownSlice);
652
- }
653
- var textPosition = tr.doc.resolve(Math.min(pastesFrom + markdownSlice.size, tr.doc.content.size));
654
- tr.setSelection(_state.TextSelection.near(textPosition, -1));
655
- queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 || queueCardsFromChangedTr(state, tr, _analytics.INPUT_METHOD.CLIPBOARD);
656
- if (dispatch) {
657
- dispatch(tr.scrollIntoView());
658
- }
659
- return true;
660
- };
661
- }
662
- function removePrecedingBackTick(tr) {
663
- var _tr$selection = tr.selection,
664
- nodeBefore = _tr$selection.$from.nodeBefore,
665
- from = _tr$selection.from;
666
- if (nodeBefore && nodeBefore.isText && nodeBefore.text.endsWith('`')) {
667
- tr.delete(from - 1, from);
668
- }
669
- }
670
- function hasInlineCode(state, slice) {
671
- return slice.content.firstChild && slice.content.firstChild.marks.some(function (m) {
672
- return m.type === state.schema.marks.code;
673
- });
674
- }
675
- function rollupLeafListItems(list, leafListItems) {
676
- list.content.forEach(function (child) {
677
- if ((0, _utils3.isListNode)(child) || (0, _utils3.isListItemNode)(child) && (0, _utils3.isListNode)(child.firstChild)) {
678
- rollupLeafListItems(child, leafListItems);
679
- } else {
680
- leafListItems.push(child);
681
- }
682
- });
683
- }
684
- function shouldFlattenList(state, slice) {
685
- var node = slice.content.firstChild;
686
- return node && (0, _coreUtils.insideTable)(state) && (0, _utils3.isListNode)(node) && slice.openStart > slice.openEnd;
687
- }
688
- function sliceHasTopLevelMarks(slice) {
689
- var hasTopLevelMarks = false;
690
- slice.content.descendants(function (node) {
691
- if (node.marks.length > 0) {
692
- hasTopLevelMarks = true;
693
- }
694
- return false;
695
- });
696
- return hasTopLevelMarks;
697
- }
698
- function getTopLevelMarkTypesInSlice(slice) {
699
- var markTypes = new Set();
700
- slice.content.descendants(function (node) {
701
- node.marks.map(function (mark) {
702
- return mark.type;
703
- }).forEach(function (markType) {
704
- return markTypes.add(markType);
705
- });
706
- return false;
707
- });
708
- return markTypes;
709
- }
710
- function handleParagraphBlockMarks(state, slice) {
711
- if (slice.content.size === 0) {
712
- return slice;
713
- }
714
- var schema = state.schema,
715
- $from = state.selection.$from;
716
-
717
- // If no paragraph in the slice contains marks, there's no need for special handling
718
- // Note: this doesn't check for marks applied to lower level nodes such as text
719
- if (!sliceHasTopLevelMarks(slice)) {
720
- return slice;
721
- }
722
-
723
- // If pasting a single paragraph into pre-existing content, match destination formatting
724
- var destinationHasContent = $from.parent.textContent.length > 0;
725
- if (slice.content.childCount === 1 && destinationHasContent) {
726
- return slice;
727
- }
728
-
729
- // Check the parent of (paragraph -> text) because block marks are assigned to a wrapper
730
- // element around the paragraph node
731
- var grandparent = $from.node(Math.max(0, $from.depth - 1));
732
- var markTypesInSlice = getTopLevelMarkTypesInSlice(slice);
733
- var forbiddenMarkTypes = [];
734
- var _iterator = _createForOfIteratorHelper(markTypesInSlice),
735
- _step;
736
- try {
737
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
738
- var markType = _step.value;
739
- if (!grandparent.type.allowsMarkType(markType)) {
740
- forbiddenMarkTypes.push(markType);
741
- }
742
- }
743
- } catch (err) {
744
- _iterator.e(err);
745
- } finally {
746
- _iterator.f();
747
- }
748
- if (forbiddenMarkTypes.length === 0) {
749
- // In a slice containing one or more paragraphs at the document level (not wrapped in
750
- // another node), the first paragraph will only have its text content captured and pasted
751
- // since openStart is 1. We decrement the open depth of the slice so it retains any block
752
- // marks applied to it. We only care about the depth at the start of the selection so
753
- // there's no need to change openEnd - the rest of the slice gets pasted correctly.
754
- var openStart = Math.max(0, slice.openStart - 1);
755
- return new _model.Slice(slice.content, openStart, slice.openEnd);
756
- }
757
-
758
- // If the paragraph contains marks forbidden by the parent node (e.g. alignment/indentation),
759
- // drop those marks from the slice
760
- return (0, _utils3.mapSlice)(slice, function (node) {
761
- if (node.type === schema.nodes.paragraph) {
762
- return schema.nodes.paragraph.createChecked(undefined, node.content, node.marks.filter(function (mark) {
763
- return !forbiddenMarkTypes.includes(mark.type);
764
- }));
765
- }
766
- return node;
767
- });
768
- }
769
-
770
- /**
771
- * ED-6300: When a nested list is pasted in a table cell and the slice has openStart > openEnd,
772
- * it splits the table. As a workaround, we flatten the list to even openStart and openEnd.
773
- *
774
- * Note: this only happens if the first child is a list
775
- *
776
- * Example: copying "one" and "two"
777
- * - zero
778
- * - one
779
- * - two
780
- *
781
- * Before:
782
- * ul
783
- * ┗━ li
784
- * ┗━ ul
785
- * ┗━ li
786
- * ┗━ p -> "one"
787
- * ┗━ li
788
- * ┗━ p -> "two"
789
- *
790
- * After:
791
- * ul
792
- * ┗━ li
793
- * ┗━ p -> "one"
794
- * ┗━ li
795
- * ┗━p -> "two"
796
- */
797
- function flattenNestedListInSlice(slice) {
798
- if (!slice.content.firstChild) {
799
- return slice;
800
- }
801
- var listToFlatten = slice.content.firstChild;
802
- var leafListItems = [];
803
- rollupLeafListItems(listToFlatten, leafListItems);
804
- var contentWithFlattenedList = slice.content.replaceChild(0, listToFlatten.type.createChecked(listToFlatten.attrs, leafListItems));
805
- return new _model.Slice(contentWithFlattenedList, slice.openEnd, slice.openEnd);
806
- }
807
- function handleRichText(slice, queueCardsFromChangedTr) {
808
- return function (state, dispatch) {
809
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
810
- var _state$schema$nodes3 = state.schema.nodes,
811
- codeBlock = _state$schema$nodes3.codeBlock,
812
- heading = _state$schema$nodes3.heading,
813
- paragraph = _state$schema$nodes3.paragraph,
814
- panel = _state$schema$nodes3.panel;
815
- var selection = state.selection,
816
- schema = state.schema;
817
- var firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild;
818
- var lastChildOfSlice = (_slice$content2 = slice.content) === null || _slice$content2 === void 0 ? void 0 : _slice$content2.lastChild;
819
-
820
- // In case user is pasting inline code,
821
- // any backtick ` immediately preceding it should be removed.
822
- var tr = state.tr;
823
- if (hasInlineCode(state, slice)) {
824
- removePrecedingBackTick(tr);
825
- }
826
- if (shouldFlattenList(state, slice)) {
827
- slice = flattenNestedListInSlice(slice);
828
- }
829
- (0, _history.closeHistory)(tr);
830
- var isFirstChildListNode = (0, _utils3.isListNode)(firstChildOfSlice);
831
- var isLastChildListNode = (0, _utils3.isListNode)(lastChildOfSlice);
832
- var isSliceContentListNodes = isFirstChildListNode || isLastChildListNode;
833
- var isFirstChildTaskListNode = (firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$ty = firstChildOfSlice.type) === null || _firstChildOfSlice$ty === void 0 ? void 0 : _firstChildOfSlice$ty.name) === 'taskList';
834
- var isLastChildTaskListNode = (lastChildOfSlice === null || lastChildOfSlice === void 0 || (_lastChildOfSlice$typ = lastChildOfSlice.type) === null || _lastChildOfSlice$typ === void 0 ? void 0 : _lastChildOfSlice$typ.name) === 'taskList';
835
- var isSliceContentTaskListNodes = isFirstChildTaskListNode || isLastChildTaskListNode;
836
-
837
- // We want to use safeInsert to insert invalid content, as it inserts at the closest non schema violating position
838
- // rather than spliting the selection parent node in half (which is what replaceSelection does)
839
- // Exception is paragraph and heading nodes, these should be split, provided their parent supports the pasted content
840
- var textNodes = [heading, paragraph];
841
- var selectionParent = selection.$to.node(selection.$to.depth - 1);
842
- var noNeedForSafeInsert = selection.$to.node().type.validContent(slice.content) || textNodes.includes(selection.$to.node().type) && selectionParent.type.validContent(slice.content);
843
- var panelParentOverCurrentSelection = (0, _utils.findParentNodeOfType)(panel)(tr.selection);
844
- var isTargetPanelEmpty = panelParentOverCurrentSelection && ((_panelParentOverCurre = panelParentOverCurrentSelection.node) === null || _panelParentOverCurre === void 0 ? void 0 : _panelParentOverCurre.content.size) === 2;
845
- if (!isSliceContentTaskListNodes && (isSliceContentListNodes || isTargetPanelEmpty)) {
846
- (0, _edgeCases.insertSliceForLists)({
847
- tr: tr,
848
- slice: slice,
849
- schema: schema
850
- });
851
- } else if (noNeedForSafeInsert) {
852
- var _firstChildOfSlice$ty2, _firstChildOfSlice$co, _firstChildOfSlice$co2;
853
- if ((firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && firstChildOfSlice !== null && firstChildOfSlice !== void 0 && (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) !== null && _firstChildOfSlice$co !== void 0 && _firstChildOfSlice$co.type.name && ['bulletList', 'orderedList'].includes(firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$co2 = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co2 === void 0 ? void 0 : _firstChildOfSlice$co2.type.name)) {
854
- // checks if parent node is a blockquote and child node is either a bulletlist or orderedlist
855
- (0, _edgeCases.insertSliceForListsInsideBlockquote)({
856
- tr: tr,
857
- slice: slice
858
- });
859
- } else {
860
- var _slice$content$lastCh;
861
- tr.replaceSelection(slice);
862
- // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
863
- // need to make sure the cursor position is is right after the panel, expand, or decisionList
864
- // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
865
- var shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 || (_slice$content$lastCh = _slice$content$lastCh.type) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.name) || '');
866
- if ((0, _utils3.insideTableCell)(state) && shouldUpdateCursorPosAfterPaste) {
867
- var nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
868
- tr.setSelection(new _selection.GapCursorSelection(nextPos, _selection.Side.RIGHT));
869
- }
870
- }
871
- } else {
872
- // need to scan the slice if there's a block node or list items inside it
873
- var sliceHasList = false;
874
- slice.content.nodesBetween(0, slice.content.size, function (node, start) {
875
- if (node.type === state.schema.nodes.listItem) {
876
- sliceHasList = true;
877
- return false;
878
- }
879
- });
880
- if ((0, _utils3.insideTableCell)(state) && (0, _utils3.isInListItem)(state) && (0, _utils.canInsert)(selection.$from, slice.content) && (0, _utils.canInsert)(selection.$to, slice.content) || sliceHasList) {
881
- tr.replaceSelection(slice);
882
- } else {
883
- // need safeInsert rather than replaceSelection, so that nodes aren't split in half
884
- // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
885
- tr = (0, _utils.safeInsert)(slice.content, tr.selection.$to.pos)(tr);
886
- }
887
- }
888
- tr.setStoredMarks([]);
889
- if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
890
- tr.setSelection(_state.TextSelection.near(tr.selection.$from, 1));
891
- }
892
- tr.scrollIntoView();
893
-
894
- // queue link cards, ignoring any errors
895
- queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 || queueCardsFromChangedTr(state, tr, _analytics.INPUT_METHOD.CLIPBOARD);
896
- if (dispatch) {
897
- dispatch(tr);
898
- }
899
- return true;
900
- };
901
- }
902
- function handlePasteIntoCaption(slice) {
903
- return function (state, dispatch) {
904
- var caption = state.schema.nodes.caption;
905
- var tr = state.tr;
906
- if ((0, _utils.hasParentNodeOfType)(caption)(state.selection)) {
907
- // We let PM replace the selection and it will insert as text where it can't place the node
908
- // This is totally fine as caption is just a simple block that only contains inline contents
909
- // And it is more in line with WYSIWYG expectations
910
- tr.replaceSelection(slice).scrollIntoView();
911
- if (dispatch) {
912
- dispatch(tr);
913
- }
914
- return true;
915
- }
916
- return false;
917
- };
918
- }
919
- var handleSelectedTable = exports.handleSelectedTable = function handleSelectedTable(editorAnalyticsAPI) {
920
- return function (slice) {
921
- return function (state, dispatch) {
922
- var tr = (0, _utils2.replaceSelectedTable)(state, slice);
923
-
924
- // add analytics after replacing selected table
925
- tr = (0, _util.addReplaceSelectedTableAnalytics)(state, tr, editorAnalyticsAPI);
926
- if (tr.docChanged) {
927
- if (dispatch) {
928
- dispatch(tr);
929
- }
930
- return true;
931
- }
932
- return false;
933
- };
934
- };
935
- };