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