@atlaskit/editor-core 190.1.25 → 190.1.27

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 +14 -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 +6 -12
  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,469 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
4
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import uuid from 'uuid';
6
- import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
7
- import { addLinkMetadata } from '@atlaskit/editor-common/card';
8
- import { containsAnyAnnotations, extractSliceFromStep, linkifyContent, mapChildren, measureRender } from '@atlaskit/editor-common/utils';
9
- import { handlePaste as handlePasteTable } from '@atlaskit/editor-tables/utils';
10
- import { getExtensionAutoConvertersFromProvider } from '@atlaskit/editor-common/extensions';
11
- import { ACTION, INPUT_METHOD, PasteTypes } from '@atlaskit/editor-common/analytics';
12
- import { md, isPastedFile as isPastedFileFromEvent } from '@atlaskit/editor-common/paste';
13
- import { transformSliceForMedia, transformSliceToCorrectMediaWrapper, transformSliceToMediaSingleWithNewExperience, unwrapNestedMediaElements } from '../plugins/media';
14
- import { escapeLinks, htmlContainsSingleFile, isPastedFromWord, isPastedFromExcel, htmlHasInvalidLinkTags, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline, getPasteSource } from '../util';
15
- import { transformSliceNestedExpandToExpand, transformSliceToJoinAdjacentCodeBlocks, transformSingleLineCodeBlockToCodeMark, transformSliceToDecisionList } from '@atlaskit/editor-common/transforms';
16
- import { handleMacroAutoConvert, handleMention, handleParagraphBlockMarks } from '../handlers';
17
- import { createPasteMeasurePayload, getContentNodeTypes, handlePasteAsPlainTextWithAnalytics, handlePasteIntoTaskAndDecisionWithAnalytics, handleCodeBlockWithAnalytics, handleMediaSingleWithAnalytics, handlePastePreservingMarksWithAnalytics, handleMarkdownWithAnalytics, handleRichTextWithAnalytics, handleExpandWithAnalytics, handleSelectedTableWithAnalytics, handlePasteLinkOnSelectedTextWithAnalytics, sendPasteAnalyticsEvent, handlePasteIntoCaptionWithAnalytics, handlePastePanelOrDecisionIntoListWithAnalytics, handlePasteNonNestableBlockNodesIntoListWithAnalytics } from './analytics';
18
- import { insideTable } from '@atlaskit/editor-common/core-utils';
19
- import { upgradeTextToLists, splitParagraphs } from '../commands';
20
- import { clipboardTextSerializer } from './clipboard-text-serializer';
21
- import { htmlHasIncompleteTable, tryRebuildCompleteTableHtml, isPastedFromTinyMCEConfluence } from '../util/tinyMCE';
22
- import { pluginKey as stateKey, createPluginState } from './plugin-factory';
23
- export { pluginKey as stateKey } from './plugin-factory';
24
- import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
25
- import { PastePluginActionTypes } from '../actions';
26
- export var isInsideBlockQuote = function isInsideBlockQuote(state) {
27
- var blockquote = state.schema.nodes.blockquote;
28
- return hasParentNodeOfType(blockquote)(state.selection);
29
- };
30
- var PASTE = 'Editor Paste Plugin Paste Duration';
31
- export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pluginInjectionApi, cardOptions, sanitizePrivateContent, providerFactory) {
32
- var _pluginInjectionApi$a;
33
- var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
34
- var atlassianMarkDownParser = new MarkdownTransformer(schema, md);
35
- function getMarkdownSlice(text, openStart, openEnd) {
36
- var textInput = escapeBackslashExceptCodeblock(text);
37
- var doc = atlassianMarkDownParser.parse(escapeLinks(textInput));
38
- if (doc && doc.content) {
39
- return new Slice(doc.content, openStart, openEnd);
40
- }
41
- return;
42
- }
43
- function escapeBackslashExceptCodeblock(textInput) {
44
- var codeToken = '```';
45
- if (!textInput.includes(codeToken)) {
46
- return textInput.replace(/\\/g, '\\\\');
47
- }
48
- var isInsideCodeblock = false;
49
- var textSplitByNewLine = textInput.split('\n');
50
- // In the splitted array, we traverse through every line and check if it will be parsed as a codeblock.
51
- textSplitByNewLine = textSplitByNewLine.map(function (text) {
52
- if (text === codeToken) {
53
- isInsideCodeblock = !isInsideCodeblock;
54
- } else if (text.startsWith(codeToken) && isInsideCodeblock === false) {
55
- // if there is some text after the ``` mark , it gets counted as language attribute only at the start of codeblock
56
- isInsideCodeblock = true;
57
- }
58
- if (!isInsideCodeblock) {
59
- // only escape text which is not inside a codeblock
60
- text = text.replace(/\\/g, '\\\\');
61
- }
62
- return text;
63
- });
64
- textInput = textSplitByNewLine.join('\n');
65
- return textInput;
66
- }
67
- var extensionAutoConverter;
68
- function setExtensionAutoConverter(_x, _x2) {
69
- return _setExtensionAutoConverter.apply(this, arguments);
70
- }
71
- function _setExtensionAutoConverter() {
72
- _setExtensionAutoConverter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(name, extensionProviderPromise) {
73
- return _regeneratorRuntime.wrap(function _callee$(_context) {
74
- while (1) switch (_context.prev = _context.next) {
75
- case 0:
76
- if (!(name !== 'extensionProvider' || !extensionProviderPromise)) {
77
- _context.next = 2;
78
- break;
79
- }
80
- return _context.abrupt("return");
81
- case 2:
82
- _context.prev = 2;
83
- _context.next = 5;
84
- return getExtensionAutoConvertersFromProvider(extensionProviderPromise);
85
- case 5:
86
- extensionAutoConverter = _context.sent;
87
- _context.next = 11;
88
- break;
89
- case 8:
90
- _context.prev = 8;
91
- _context.t0 = _context["catch"](2);
92
- // eslint-disable-next-line no-console
93
- console.error(_context.t0);
94
- case 11:
95
- case "end":
96
- return _context.stop();
97
- }
98
- }, _callee, null, [[2, 8]]);
99
- }));
100
- return _setExtensionAutoConverter.apply(this, arguments);
101
- }
102
- if (providerFactory) {
103
- providerFactory.subscribe('extensionProvider', setExtensionAutoConverter);
104
- }
105
- var mostRecentPasteEvent;
106
- var pastedFromBitBucket = false;
107
- return new SafePlugin({
108
- key: stateKey,
109
- state: createPluginState(dispatch, {
110
- pastedMacroPositions: {},
111
- lastContentPasted: null
112
- }),
113
- props: {
114
- // For serialising to plain text
115
- clipboardTextSerializer: clipboardTextSerializer,
116
- handleDOMEvents: {
117
- paste: function paste(view, event) {
118
- mostRecentPasteEvent = event;
119
- return false;
120
- }
121
- },
122
- handlePaste: function handlePaste(view, rawEvent, slice) {
123
- var _text, _pluginInjectionApi$a2, _analyticsPlugin$perf, _schema$nodes, _schema$nodes2, _schema$nodes3, _pluginInjectionApi$m;
124
- var event = rawEvent;
125
- if (!event.clipboardData) {
126
- return false;
127
- }
128
- var text = event.clipboardData.getData('text/plain');
129
- var html = event.clipboardData.getData('text/html');
130
- var uriList = event.clipboardData.getData('text/uri-list');
131
- // Links copied from iOS Safari share button only have the text/uri-list data type
132
- // ProseMirror don't do anything with this type so we want to make our own open slice
133
- // with url as text content so link is pasted inline
134
- if (uriList && !text && !html) {
135
- text = uriList;
136
- slice = new Slice(Fragment.from(schema.text(text)), 1, 1);
137
- }
138
- if ((_text = text) !== null && _text !== void 0 && _text.includes('\r')) {
139
- text = text.replace(/\r/g, '');
140
- }
141
- var isPastedFile = isPastedFileFromEvent(event);
142
- var isPlainText = text && !html;
143
- var isRichText = !!html;
144
-
145
- // Bail if copied content has files
146
- if (isPastedFile) {
147
- if (!html) {
148
- /**
149
- * Microsoft Office, Number, Pages, etc. adds an image to clipboard
150
- * with other mime-types so we don't let the event reach media.
151
- * The detection ration here is that if the payload has both `html` and
152
- * `files`, then it could be one of above or an image copied from web.
153
- * Here, we don't have html, so we return true to allow default event behaviour
154
- */
155
- return true;
156
- }
157
-
158
- /**
159
- * We want to return false for external copied image to allow
160
- * it to be uploaded by the client.
161
- */
162
- if (htmlContainsSingleFile(html)) {
163
- return true;
164
- }
165
- event.stopImmediatePropagation();
166
- }
167
- var state = view.state;
168
- var analyticsPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 || (_pluginInjectionApi$a2 = _pluginInjectionApi$a2.sharedState) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.currentState();
169
- var pasteTrackingEnabled = analyticsPlugin === null || analyticsPlugin === void 0 || (_analyticsPlugin$perf = analyticsPlugin.performanceTracking) === null || _analyticsPlugin$perf === void 0 || (_analyticsPlugin$perf = _analyticsPlugin$perf.pasteTracking) === null || _analyticsPlugin$perf === void 0 ? void 0 : _analyticsPlugin$perf.enabled;
170
- if (pasteTrackingEnabled) {
171
- var content = getContentNodeTypes(slice.content);
172
- var pasteId = uuid();
173
- var measureName = "".concat(PASTE, "_").concat(pasteId);
174
- measureRender(measureName, function (_ref) {
175
- var duration = _ref.duration,
176
- distortedDuration = _ref.distortedDuration;
177
- var payload = createPasteMeasurePayload({
178
- view: view,
179
- duration: duration,
180
- content: content,
181
- distortedDuration: distortedDuration
182
- });
183
- if (payload) {
184
- dispatchAnalyticsEvent(payload);
185
- }
186
- });
187
- }
188
- // creating a custom dispatch because we want to add a meta whenever we do a paste.
189
- var dispatch = function dispatch(tr) {
190
- var _state$doc$resolve$no, _input;
191
- // https://product-fabric.atlassian.net/browse/ED-12633
192
- // don't add closeHistory call if we're pasting a text inside placeholder text as we want the whole action
193
- // to be atomic
194
- var placeholder = state.schema.nodes.placeholder;
195
- var isPastingTextInsidePlaceholderText = ((_state$doc$resolve$no = state.doc.resolve(state.selection.$anchor.pos).nodeAfter) === null || _state$doc$resolve$no === void 0 ? void 0 : _state$doc$resolve$no.type) === placeholder;
196
-
197
- // Don't add closeHistory if we're pasting over layout columns, as we will appendTransaction
198
- // to cleanup the layout's structure and we want to keep the paste and re-structuring as
199
- // one event.
200
- var isPastingOverLayoutColumns = hasParentNodeOfType(state.schema.nodes.layoutColumn)(state.selection);
201
-
202
- // don't add closeHistory call if we're pasting a table, as some tables may involve additional
203
- // appendedTransactions to repair them (if they're partial or incomplete) and we don't want
204
- // to split those repairing transactions in prosemirror-history when they're being added to the
205
- // "done" stack
206
- var isPastingTable = tr.steps.some(function (step) {
207
- var _slice$content;
208
- var slice = extractSliceFromStep(step);
209
- var tableExists = false;
210
- slice === null || slice === void 0 || (_slice$content = slice.content) === null || _slice$content === void 0 || _slice$content.forEach(function (node) {
211
- if (node.type === state.schema.nodes.table) {
212
- tableExists = true;
213
- }
214
- });
215
- return tableExists;
216
- });
217
- if (!isPastingTextInsidePlaceholderText && !isPastingTable && !isPastingOverLayoutColumns && pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.betterTypeHistory) {
218
- var _pluginInjectionApi$b;
219
- tr = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$b = pluginInjectionApi.betterTypeHistory) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.flagPasteEvent(tr);
220
- }
221
- addLinkMetadata(view.state.selection, tr, {
222
- action: isPlainText ? ACTION.PASTED_AS_PLAIN : ACTION.PASTED,
223
- inputMethod: INPUT_METHOD.CLIPBOARD
224
- });
225
- var pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
226
- var pasteEndPos = tr.selection.to;
227
- var contentPasted = {
228
- pasteStartPos: pasteStartPos,
229
- pasteEndPos: pasteEndPos,
230
- text: text,
231
- isShiftPressed: Boolean(view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
232
- isPlainText: Boolean(isPlainText),
233
- pastedSlice: tr.doc.slice(pasteStartPos, pasteEndPos),
234
- pastedAt: Date.now(),
235
- pasteSource: getPasteSource(event)
236
- };
237
- tr.setMeta(stateKey, {
238
- type: PastePluginActionTypes.ON_PASTE,
239
- contentPasted: contentPasted
240
- });
241
- view.dispatch(tr);
242
- };
243
- slice = handleParagraphBlockMarks(state, slice);
244
- var plainTextPasteSlice = linkifyContent(state.schema)(slice);
245
- if (handlePasteAsPlainTextWithAnalytics(editorAnalyticsAPI)(view, event, plainTextPasteSlice)(state, dispatch, view)) {
246
- return true;
247
- }
248
-
249
- // transform slices based on destination
250
- slice = transformSliceForMedia(slice, schema)(state.selection);
251
- var markdownSlice;
252
- if (isPlainText) {
253
- var _markdownSlice;
254
- markdownSlice = getMarkdownSlice(text, slice.openStart, slice.openEnd);
255
-
256
- // https://product-fabric.atlassian.net/browse/ED-15134
257
- // Lists are not allowed within Blockquotes at this time. Attempting to
258
- // paste a markdown list ie. ">- foo" will yeild a markdownSlice of size 0.
259
- // Rather then blocking the paste action with no UI feedback, this will instead
260
- // force a "paste as plain text" action by clearing the markdownSlice.
261
- markdownSlice = !((_markdownSlice = markdownSlice) !== null && _markdownSlice !== void 0 && _markdownSlice.size) ? undefined : markdownSlice;
262
- if (markdownSlice) {
263
- var _pluginInjectionApi$c, _pluginInjectionApi$e;
264
- // linkify text prior to converting to macro
265
- if (handlePasteLinkOnSelectedTextWithAnalytics(editorAnalyticsAPI)(view, event, markdownSlice, PasteTypes.markdown)(state, dispatch)) {
266
- return true;
267
- }
268
-
269
- // run macro autoconvert prior to other conversions
270
- if (handleMacroAutoConvert(text, markdownSlice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.card) === null || _pluginInjectionApi$c === void 0 || (_pluginInjectionApi$c = _pluginInjectionApi$c.actions) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.queueCardsFromChangedTr, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.extension) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.actions) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.runMacroAutoConvert, cardOptions, extensionAutoConverter)(state, dispatch, view)) {
271
- // TODO: handleMacroAutoConvert dispatch twice, so we can't use the helper
272
- sendPasteAnalyticsEvent(editorAnalyticsAPI)(view, event, markdownSlice, {
273
- type: PasteTypes.markdown
274
- });
275
- return true;
276
- }
277
- }
278
- }
279
- slice = transformUnsupportedBlockCardToInline(slice, state, cardOptions);
280
-
281
- // Handles edge case so that when copying text from the top level of the document
282
- // it can be pasted into nodes like panels/actions/decisions without removing them.
283
- // Overriding openStart to be 1 when only pasting a paragraph makes the preferred
284
- // depth favour the text, rather than the paragraph node.
285
- // https://github.com/ProseMirror/prosemirror-transform/blob/master/src/replace.js#:~:text=Transform.prototype.-,replaceRange,-%3D%20function(from%2C%20to
286
- var selectionDepth = state.selection.$head.depth;
287
- var selectionParentNode = state.selection.$head.node(selectionDepth - 1);
288
- var selectionParentType = selectionParentNode === null || selectionParentNode === void 0 ? void 0 : selectionParentNode.type;
289
- var edgeCaseNodeTypes = [(_schema$nodes = schema.nodes) === null || _schema$nodes === void 0 ? void 0 : _schema$nodes.panel, (_schema$nodes2 = schema.nodes) === null || _schema$nodes2 === void 0 ? void 0 : _schema$nodes2.taskList, (_schema$nodes3 = schema.nodes) === null || _schema$nodes3 === void 0 ? void 0 : _schema$nodes3.decisionList];
290
- if (slice.openStart === 0 && slice.openEnd !== 1 && selectionParentNode && edgeCaseNodeTypes.includes(selectionParentType)) {
291
- // @ts-ignore - [unblock prosemirror bump] assigning to readonly prop
292
- slice.openStart = 1;
293
- }
294
- if (handlePasteIntoTaskAndDecisionWithAnalytics(view, event, slice, isPlainText ? PasteTypes.plain : PasteTypes.richText, pluginInjectionApi)(state, dispatch)) {
295
- return true;
296
- }
297
-
298
- // If we're in a code block, append the text contents of clipboard inside it
299
- if (handleCodeBlockWithAnalytics(editorAnalyticsAPI)(view, event, slice, text)(state, dispatch)) {
300
- return true;
301
- }
302
- if (handleMediaSingleWithAnalytics(editorAnalyticsAPI)(view, event, slice, isPastedFile ? PasteTypes.binary : PasteTypes.richText, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$m = pluginInjectionApi.media) === null || _pluginInjectionApi$m === void 0 ? void 0 : _pluginInjectionApi$m.actions.insertMediaAsMediaSingle)(state, dispatch, view)) {
303
- return true;
304
- }
305
- if (handleSelectedTableWithAnalytics(editorAnalyticsAPI)(view, event, slice)(state, dispatch)) {
306
- return true;
307
- }
308
-
309
- // If the clipboard only contains plain text, attempt to parse it as Markdown
310
- if (isPlainText && markdownSlice) {
311
- if (handlePastePreservingMarksWithAnalytics(view, event, markdownSlice, PasteTypes.markdown, pluginInjectionApi)(state, dispatch)) {
312
- return true;
313
- }
314
- return handleMarkdownWithAnalytics(view, event, markdownSlice, pluginInjectionApi)(state, dispatch);
315
- }
316
- if (isRichText && isInsideBlockQuote(state)) {
317
- //If pasting inside blockquote
318
- //Skip the blockquote node and keep remaining nodes as they are
319
- var blockquote = schema.nodes.blockquote;
320
- var children = [];
321
- mapChildren(slice.content, function (node) {
322
- if (node.type === blockquote) {
323
- for (var i = 0; i < node.childCount; i++) {
324
- children.push(node.child(i));
325
- }
326
- } else {
327
- children.push(node);
328
- }
329
- });
330
- slice = new Slice(Fragment.fromArray(children), slice.openStart, slice.openEnd);
331
- }
332
-
333
- // finally, handle rich-text copy-paste
334
- if (isRichText) {
335
- var _pluginInjectionApi$c2, _pluginInjectionApi$e2, _pluginInjectionApi$l;
336
- // linkify the text where possible
337
- slice = linkifyContent(state.schema)(slice);
338
- if (handlePasteLinkOnSelectedTextWithAnalytics(editorAnalyticsAPI)(view, event, slice, PasteTypes.richText)(state, dispatch)) {
339
- return true;
340
- }
341
-
342
- // run macro autoconvert prior to other conversions
343
- if (handleMacroAutoConvert(text, slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.card) === null || _pluginInjectionApi$c2 === void 0 || (_pluginInjectionApi$c2 = _pluginInjectionApi$c2.actions) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.queueCardsFromChangedTr, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e2 = pluginInjectionApi.extension) === null || _pluginInjectionApi$e2 === void 0 || (_pluginInjectionApi$e2 = _pluginInjectionApi$e2.actions) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.runMacroAutoConvert, cardOptions, extensionAutoConverter)(state, dispatch, view)) {
344
- // TODO: handleMacroAutoConvert dispatch twice, so we can't use the helper
345
- sendPasteAnalyticsEvent(editorAnalyticsAPI)(view, event, slice, {
346
- type: PasteTypes.richText
347
- });
348
- return true;
349
- }
350
-
351
- // get editor-tables to handle pasting tables if it can
352
- // otherwise, just the replace the selection with the content
353
- if (handlePasteTable(view, null, slice)) {
354
- sendPasteAnalyticsEvent(editorAnalyticsAPI)(view, event, slice, {
355
- type: PasteTypes.richText
356
- });
357
- return true;
358
- }
359
-
360
- // remove annotation marks from the pasted data if they are not present in the document
361
- // for the cases when they are pasted from external pages
362
- if (slice.content.size && containsAnyAnnotations(slice, state)) {
363
- var _pluginInjectionApi$a3;
364
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a3 = pluginInjectionApi.annotation) === null || _pluginInjectionApi$a3 === void 0 || _pluginInjectionApi$a3.actions.stripNonExistingAnnotations(slice, state);
365
- }
366
-
367
- // ED-4732
368
- if (handlePastePreservingMarksWithAnalytics(view, event, slice, PasteTypes.richText, pluginInjectionApi)(state, dispatch)) {
369
- return true;
370
- }
371
-
372
- // Check that we are pasting in a location that does not accept
373
- // breakout marks, if so we strip the mark and paste. Note that
374
- // breakout marks are only valid in the root document.
375
- if (selectionParentType !== state.schema.nodes.doc) {
376
- var sliceCopy = Slice.fromJSON(state.schema, slice.toJSON() || {});
377
- sliceCopy.content.descendants(function (node) {
378
- // @ts-ignore - [unblock prosemirror bump] assigning to readonly prop
379
- node.marks = node.marks.filter(function (mark) {
380
- return mark.type.name !== 'breakout';
381
- });
382
- // as breakout marks should only be on top level nodes,
383
- // we don't traverse the entire document
384
- return false;
385
- });
386
- slice = sliceCopy;
387
- }
388
- if (handleExpandWithAnalytics(editorAnalyticsAPI)(view, event, slice)(state, dispatch)) {
389
- return true;
390
- }
391
- if (!insideTable(state)) {
392
- slice = transformSliceNestedExpandToExpand(slice, state.schema);
393
- }
394
-
395
- // Create a custom handler to avoid handling with handleRichText method
396
- // As SafeInsert is used inside handleRichText which caused some bad UX like this:
397
- // https://product-fabric.atlassian.net/browse/MEX-1520
398
- if (handlePasteIntoCaptionWithAnalytics(editorAnalyticsAPI)(view, event, slice, PasteTypes.richText)(state, dispatch)) {
399
- return true;
400
- }
401
- if (handlePastePanelOrDecisionIntoListWithAnalytics(editorAnalyticsAPI)(view, event, slice, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$l = pluginInjectionApi.list) === null || _pluginInjectionApi$l === void 0 ? void 0 : _pluginInjectionApi$l.actions.findRootParentListNode)(state, dispatch)) {
402
- return true;
403
- }
404
- if (handlePasteNonNestableBlockNodesIntoListWithAnalytics(editorAnalyticsAPI)(view, event, slice)(state, dispatch)) {
405
- return true;
406
- }
407
- return handleRichTextWithAnalytics(view, event, slice, pluginInjectionApi)(state, dispatch);
408
- }
409
- return false;
410
- },
411
- transformPasted: function transformPasted(slice) {
412
- if (sanitizePrivateContent) {
413
- slice = handleMention(slice, schema);
414
- }
415
-
416
- /* Bitbucket copies diffs as multiple adjacent code blocks
417
- * so we merge ALL adjacent code blocks to support paste here */
418
- if (pastedFromBitBucket) {
419
- slice = transformSliceToJoinAdjacentCodeBlocks(slice);
420
- }
421
- slice = transformSingleLineCodeBlockToCodeMark(slice, schema);
422
- slice = transformSliceToCorrectMediaWrapper(slice, schema);
423
- slice = transformSliceToMediaSingleWithNewExperience(slice, schema);
424
- slice = transformSliceToDecisionList(slice, schema);
425
-
426
- // splitting linebreaks into paragraphs must happen before upgrading text to lists
427
- slice = splitParagraphs(slice, schema);
428
- slice = upgradeTextToLists(slice, schema);
429
- if (slice.content.childCount && slice.content.lastChild.type === schema.nodes.codeBlock) {
430
- slice = new Slice(slice.content, 0, 0);
431
- }
432
- return slice;
433
- },
434
- transformPastedHTML: function transformPastedHTML(html) {
435
- // Fix for issue ED-4438
436
- // text from google docs should not be pasted as inline code
437
- if (html.indexOf('id="docs-internal-guid-') >= 0) {
438
- html = html.replace(/white-space:pre/g, '');
439
- html = html.replace(/white-space:pre-wrap/g, '');
440
- }
441
-
442
- // Partial fix for ED-7331: During a copy/paste from the legacy tinyMCE
443
- // confluence editor, if we encounter an incomplete table (e.g. table elements
444
- // not wrapped in <table>), we try to rebuild a complete, valid table if possible.
445
- if (mostRecentPasteEvent && isPastedFromTinyMCEConfluence(mostRecentPasteEvent, html) && htmlHasIncompleteTable(html)) {
446
- var completeTableHtml = tryRebuildCompleteTableHtml(html);
447
- if (completeTableHtml) {
448
- html = completeTableHtml;
449
- }
450
- }
451
- if (!isPastedFromWord(html) && !isPastedFromExcel(html) && html.indexOf('<img ') >= 0) {
452
- html = unwrapNestedMediaElements(html);
453
- }
454
-
455
- // https://product-fabric.atlassian.net/browse/ED-11714
456
- // Checking for edge case when copying a list item containing links from Notion
457
- // The html from this case is invalid with duplicate nested links
458
- if (htmlHasInvalidLinkTags(html)) {
459
- html = removeDuplicateInvalidLinks(html);
460
- }
461
-
462
- // Fix for ED-13568: Code blocks being copied/pasted when next to each other get merged
463
- pastedFromBitBucket = html.indexOf('data-qa="code-line"') >= 0;
464
- mostRecentPasteEvent = null;
465
- return html;
466
- }
467
- }
468
- });
469
- }
@@ -1,36 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- 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; }
4
- 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) { _defineProperty(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; }
5
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
- import { pluginFactory } from '@atlaskit/editor-common/utils';
7
- import { reducer } from '../reducer';
8
- export var pluginKey = new PluginKey('pastePlugin');
9
- var _pluginFactory = pluginFactory(pluginKey, reducer, {
10
- mapping: function mapping(tr, pluginState) {
11
- if (tr.docChanged) {
12
- var atLeastOnePositionChanged = false;
13
- var positionsMappedThroughChanges = Object.entries(pluginState.pastedMacroPositions).reduce(function (acc, _ref) {
14
- var _ref2 = _slicedToArray(_ref, 2),
15
- key = _ref2[0],
16
- position = _ref2[1];
17
- var mappedPosition = tr.mapping.map(position);
18
- if (position !== mappedPosition) {
19
- atLeastOnePositionChanged = true;
20
- }
21
- acc[key] = tr.mapping.map(position);
22
- return acc;
23
- }, {});
24
- if (atLeastOnePositionChanged) {
25
- return _objectSpread(_objectSpread({}, pluginState), {}, {
26
- pastedMacroPositions: positionsMappedThroughChanges
27
- });
28
- }
29
- }
30
- return pluginState;
31
- }
32
- }),
33
- createPluginState = _pluginFactory.createPluginState,
34
- createCommand = _pluginFactory.createCommand,
35
- getPluginState = _pluginFactory.getPluginState;
36
- export { createPluginState, createCommand, getPluginState };
@@ -1,34 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- 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; }
4
- 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) { _defineProperty(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; }
5
- import { PastePluginActionTypes as ActionTypes } from './actions';
6
- export var reducer = function reducer(state, action) {
7
- switch (action.type) {
8
- case ActionTypes.START_TRACKING_PASTED_MACRO_POSITIONS:
9
- {
10
- return _objectSpread(_objectSpread({}, state), {}, {
11
- pastedMacroPositions: _objectSpread(_objectSpread({}, state.pastedMacroPositions), action.pastedMacroPositions)
12
- });
13
- }
14
- case ActionTypes.STOP_TRACKING_PASTED_MACRO_POSITIONS:
15
- {
16
- var filteredMacroPositions = Object.fromEntries(Object.entries(state.pastedMacroPositions).filter(function (_ref) {
17
- var _ref2 = _slicedToArray(_ref, 1),
18
- key = _ref2[0];
19
- return !action.pastedMacroPositionKeys.includes(key);
20
- }));
21
- return _objectSpread(_objectSpread({}, state), {}, {
22
- pastedMacroPositions: filteredMacroPositions
23
- });
24
- }
25
- case ActionTypes.ON_PASTE:
26
- {
27
- return _objectSpread(_objectSpread({}, state), {}, {
28
- lastContentPasted: action.contentPasted
29
- });
30
- }
31
- default:
32
- return state;
33
- }
34
- };
@@ -1 +0,0 @@
1
- export {};