@atlaskit/editor-plugin-paste 4.1.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 4.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#193268](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193268)
8
+ [`4a345f374785e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4a345f374785e) -
9
+ [ux] ED-28208 Fix pasting table into selected table results in a nested table
10
+ - Updated dependencies
11
+
3
12
  ## 4.1.1
4
13
 
5
14
  ### Patch Changes
@@ -23,6 +23,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
23
23
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
24
24
  var _utils3 = require("@atlaskit/editor-tables/utils");
25
25
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
26
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
26
27
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
27
28
  var _actions = require("../editor-actions/actions");
28
29
  var _commands = require("../editor-commands/commands");
@@ -34,6 +35,9 @@ var _util = require("./util");
34
35
  var _handleVSCodeBlock = require("./util/edge-cases/handleVSCodeBlock");
35
36
  var _handlers = require("./util/handlers");
36
37
  var _tinyMCE = require("./util/tinyMCE");
38
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
39
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
40
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
37
41
  var isInsideBlockQuote = exports.isInsideBlockQuote = function isInsideBlockQuote(state) {
38
42
  var blockquote = state.schema.nodes.blockquote;
39
43
  return (0, _utils2.hasParentNodeOfType)(blockquote)(state.selection);
@@ -212,6 +216,25 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
212
216
  dispatchAnalyticsEvent(payload);
213
217
  }
214
218
  });
219
+ var getLastPastedSlice = function getLastPastedSlice(tr) {
220
+ var slice;
221
+ var _iterator = _createForOfIteratorHelper(tr.steps),
222
+ _step;
223
+ try {
224
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
225
+ var step = _step.value;
226
+ var stepSlice = (0, _utils.extractSliceFromStep)(step);
227
+ if (stepSlice) {
228
+ slice = stepSlice;
229
+ }
230
+ }
231
+ } catch (err) {
232
+ _iterator.e(err);
233
+ } finally {
234
+ _iterator.f();
235
+ }
236
+ return slice;
237
+ };
215
238
  // creating a custom dispatch because we want to add a meta whenever we do a paste.
216
239
  var dispatch = function dispatch(tr) {
217
240
  var _state$doc$resolve$no;
@@ -255,25 +278,50 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
255
278
  // we make sure to call paste options toolbar
256
279
  // only for a valid paste action
257
280
  if (isDocChanged) {
258
- var _input;
259
- var pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
260
- var pasteEndPos = tr.selection.to;
261
- var contentPasted = {
262
- pasteStartPos: pasteStartPos,
263
- pasteEndPos: pasteEndPos,
264
- text: text,
265
- isShiftPressed: Boolean(
266
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
267
- view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
268
- isPlainText: Boolean(isPlainText),
269
- pastedSlice: tr.doc.slice(pasteStartPos, pasteEndPos),
270
- pastedAt: Date.now(),
271
- pasteSource: (0, _util.getPasteSource)(event)
272
- };
273
- tr.setMeta(_pluginFactory.pluginKey, {
274
- type: _actions.PastePluginActionTypes.ON_PASTE,
275
- contentPasted: contentPasted
276
- });
281
+ if ((0, _expValEquals.expValEquals)('platform_editor_pasting_nested_table_fix', 'isEnabled', true)) {
282
+ var pastedSlice = getLastPastedSlice(tr);
283
+ if (pastedSlice) {
284
+ var _input;
285
+ var pasteStartPos = state.selection.from;
286
+ var pasteEndPos = tr.selection.to;
287
+ var contentPasted = {
288
+ pasteStartPos: pasteStartPos,
289
+ pasteEndPos: pasteEndPos,
290
+ text: text,
291
+ isShiftPressed: Boolean(
292
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
293
+ view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
294
+ isPlainText: Boolean(isPlainText),
295
+ pastedSlice: pastedSlice,
296
+ pastedAt: Date.now(),
297
+ pasteSource: (0, _util.getPasteSource)(event)
298
+ };
299
+ tr.setMeta(_pluginFactory.pluginKey, {
300
+ type: _actions.PastePluginActionTypes.ON_PASTE,
301
+ contentPasted: contentPasted
302
+ });
303
+ }
304
+ } else {
305
+ var _input2;
306
+ var _pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
307
+ var _pasteEndPos = tr.selection.to;
308
+ var _contentPasted = {
309
+ pasteStartPos: _pasteStartPos,
310
+ pasteEndPos: _pasteEndPos,
311
+ text: text,
312
+ isShiftPressed: Boolean(
313
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
314
+ view.shiftKey || ((_input2 = view.input) === null || _input2 === void 0 ? void 0 : _input2.shiftKey)),
315
+ isPlainText: Boolean(isPlainText),
316
+ pastedSlice: tr.doc.slice(_pasteStartPos, _pasteEndPos),
317
+ pastedAt: Date.now(),
318
+ pasteSource: (0, _util.getPasteSource)(event)
319
+ };
320
+ tr.setMeta(_pluginFactory.pluginKey, {
321
+ type: _actions.PastePluginActionTypes.ON_PASTE,
322
+ contentPasted: _contentPasted
323
+ });
324
+ }
277
325
  }
278
326
 
279
327
  // the handlePaste definition overrides the generic prosemirror behaviour which would previously
@@ -13,6 +13,7 @@ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
13
13
  import { contains, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
14
14
  import { handlePaste as handlePasteTable } from '@atlaskit/editor-tables/utils';
15
15
  import { fg } from '@atlaskit/platform-feature-flags';
16
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
16
17
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
17
18
  import { PastePluginActionTypes } from '../editor-actions/actions';
18
19
  import { splitParagraphs, upgradeTextToLists } from '../editor-commands/commands';
@@ -184,6 +185,16 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
184
185
  dispatchAnalyticsEvent(payload);
185
186
  }
186
187
  });
188
+ const getLastPastedSlice = tr => {
189
+ let slice;
190
+ for (const step of tr.steps) {
191
+ const stepSlice = extractSliceFromStep(step);
192
+ if (stepSlice) {
193
+ slice = stepSlice;
194
+ }
195
+ }
196
+ return slice;
197
+ };
187
198
  // creating a custom dispatch because we want to add a meta whenever we do a paste.
188
199
  const dispatch = tr => {
189
200
  var _state$doc$resolve$no;
@@ -229,25 +240,50 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
229
240
  // we make sure to call paste options toolbar
230
241
  // only for a valid paste action
231
242
  if (isDocChanged) {
232
- var _input;
233
- const pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
234
- const pasteEndPos = tr.selection.to;
235
- const contentPasted = {
236
- pasteStartPos,
237
- pasteEndPos,
238
- text,
239
- isShiftPressed: Boolean(
240
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
241
- view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
242
- isPlainText: Boolean(isPlainText),
243
- pastedSlice: tr.doc.slice(pasteStartPos, pasteEndPos),
244
- pastedAt: Date.now(),
245
- pasteSource: getPasteSource(event)
246
- };
247
- tr.setMeta(stateKey, {
248
- type: PastePluginActionTypes.ON_PASTE,
249
- contentPasted
250
- });
243
+ if (expValEquals('platform_editor_pasting_nested_table_fix', 'isEnabled', true)) {
244
+ const pastedSlice = getLastPastedSlice(tr);
245
+ if (pastedSlice) {
246
+ var _input;
247
+ const pasteStartPos = state.selection.from;
248
+ const pasteEndPos = tr.selection.to;
249
+ const contentPasted = {
250
+ pasteStartPos,
251
+ pasteEndPos,
252
+ text,
253
+ isShiftPressed: Boolean(
254
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
255
+ view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
256
+ isPlainText: Boolean(isPlainText),
257
+ pastedSlice,
258
+ pastedAt: Date.now(),
259
+ pasteSource: getPasteSource(event)
260
+ };
261
+ tr.setMeta(stateKey, {
262
+ type: PastePluginActionTypes.ON_PASTE,
263
+ contentPasted
264
+ });
265
+ }
266
+ } else {
267
+ var _input2;
268
+ const pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
269
+ const pasteEndPos = tr.selection.to;
270
+ const contentPasted = {
271
+ pasteStartPos,
272
+ pasteEndPos,
273
+ text,
274
+ isShiftPressed: Boolean(
275
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
+ view.shiftKey || ((_input2 = view.input) === null || _input2 === void 0 ? void 0 : _input2.shiftKey)),
277
+ isPlainText: Boolean(isPlainText),
278
+ pastedSlice: tr.doc.slice(pasteStartPos, pasteEndPos),
279
+ pastedAt: Date.now(),
280
+ pasteSource: getPasteSource(event)
281
+ };
282
+ tr.setMeta(stateKey, {
283
+ type: PastePluginActionTypes.ON_PASTE,
284
+ contentPasted
285
+ });
286
+ }
251
287
  }
252
288
 
253
289
  // the handlePaste definition overrides the generic prosemirror behaviour which would previously
@@ -1,5 +1,8 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
3
6
  import uuid from 'uuid';
4
7
  import { ACTION, INPUT_METHOD, PasteTypes } from '@atlaskit/editor-common/analytics';
5
8
  import { addLinkMetadata } from '@atlaskit/editor-common/card';
@@ -15,6 +18,7 @@ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
15
18
  import { contains, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
16
19
  import { handlePaste as handlePasteTable } from '@atlaskit/editor-tables/utils';
17
20
  import { fg } from '@atlaskit/platform-feature-flags';
21
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
18
22
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
19
23
  import { PastePluginActionTypes } from '../editor-actions/actions';
20
24
  import { splitParagraphs, upgradeTextToLists } from '../editor-commands/commands';
@@ -204,6 +208,25 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
204
208
  dispatchAnalyticsEvent(payload);
205
209
  }
206
210
  });
211
+ var getLastPastedSlice = function getLastPastedSlice(tr) {
212
+ var slice;
213
+ var _iterator = _createForOfIteratorHelper(tr.steps),
214
+ _step;
215
+ try {
216
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
217
+ var step = _step.value;
218
+ var stepSlice = extractSliceFromStep(step);
219
+ if (stepSlice) {
220
+ slice = stepSlice;
221
+ }
222
+ }
223
+ } catch (err) {
224
+ _iterator.e(err);
225
+ } finally {
226
+ _iterator.f();
227
+ }
228
+ return slice;
229
+ };
207
230
  // creating a custom dispatch because we want to add a meta whenever we do a paste.
208
231
  var dispatch = function dispatch(tr) {
209
232
  var _state$doc$resolve$no;
@@ -247,25 +270,50 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
247
270
  // we make sure to call paste options toolbar
248
271
  // only for a valid paste action
249
272
  if (isDocChanged) {
250
- var _input;
251
- var pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
252
- var pasteEndPos = tr.selection.to;
253
- var contentPasted = {
254
- pasteStartPos: pasteStartPos,
255
- pasteEndPos: pasteEndPos,
256
- text: text,
257
- isShiftPressed: Boolean(
258
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
259
- view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
260
- isPlainText: Boolean(isPlainText),
261
- pastedSlice: tr.doc.slice(pasteStartPos, pasteEndPos),
262
- pastedAt: Date.now(),
263
- pasteSource: getPasteSource(event)
264
- };
265
- tr.setMeta(stateKey, {
266
- type: PastePluginActionTypes.ON_PASTE,
267
- contentPasted: contentPasted
268
- });
273
+ if (expValEquals('platform_editor_pasting_nested_table_fix', 'isEnabled', true)) {
274
+ var pastedSlice = getLastPastedSlice(tr);
275
+ if (pastedSlice) {
276
+ var _input;
277
+ var pasteStartPos = state.selection.from;
278
+ var pasteEndPos = tr.selection.to;
279
+ var contentPasted = {
280
+ pasteStartPos: pasteStartPos,
281
+ pasteEndPos: pasteEndPos,
282
+ text: text,
283
+ isShiftPressed: Boolean(
284
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
285
+ view.shiftKey || ((_input = view.input) === null || _input === void 0 ? void 0 : _input.shiftKey)),
286
+ isPlainText: Boolean(isPlainText),
287
+ pastedSlice: pastedSlice,
288
+ pastedAt: Date.now(),
289
+ pasteSource: getPasteSource(event)
290
+ };
291
+ tr.setMeta(stateKey, {
292
+ type: PastePluginActionTypes.ON_PASTE,
293
+ contentPasted: contentPasted
294
+ });
295
+ }
296
+ } else {
297
+ var _input2;
298
+ var _pasteStartPos = Math.min(state.selection.anchor, state.selection.head);
299
+ var _pasteEndPos = tr.selection.to;
300
+ var _contentPasted = {
301
+ pasteStartPos: _pasteStartPos,
302
+ pasteEndPos: _pasteEndPos,
303
+ text: text,
304
+ isShiftPressed: Boolean(
305
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
+ view.shiftKey || ((_input2 = view.input) === null || _input2 === void 0 ? void 0 : _input2.shiftKey)),
307
+ isPlainText: Boolean(isPlainText),
308
+ pastedSlice: tr.doc.slice(_pasteStartPos, _pasteEndPos),
309
+ pastedAt: Date.now(),
310
+ pasteSource: getPasteSource(event)
311
+ };
312
+ tr.setMeta(stateKey, {
313
+ type: PastePluginActionTypes.ON_PASTE,
314
+ contentPasted: _contentPasted
315
+ });
316
+ }
269
317
  }
270
318
 
271
319
  // the handlePaste definition overrides the generic prosemirror behaviour which would previously
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -46,13 +46,13 @@
46
46
  "@atlaskit/media-client": "^35.2.0",
47
47
  "@atlaskit/media-common": "^12.3.0",
48
48
  "@atlaskit/platform-feature-flags": "^1.1.0",
49
- "@atlaskit/tmp-editor-statsig": "^9.17.0",
49
+ "@atlaskit/tmp-editor-statsig": "^9.18.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "lodash": "^4.17.21",
52
52
  "uuid": "^3.1.0"
53
53
  },
54
54
  "peerDependencies": {
55
- "@atlaskit/editor-common": "^107.12.0",
55
+ "@atlaskit/editor-common": "^107.14.0",
56
56
  "react": "^18.2.0",
57
57
  "react-dom": "^18.2.0"
58
58
  },