@atlaskit/editor-plugin-paste 0.2.1 → 0.2.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,12 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#64216](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/64216) [`582a3eef15ae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/582a3eef15ae) - ED-20824 Fix copy paste issues with multi-level list inside blockquote
8
+ - Updated dependencies
9
+
3
10
  ## 0.2.1
4
11
 
5
12
  ### Patch Changes
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.insertSliceForLists = insertSliceForLists;
7
7
  exports.insertSliceForListsInsideBlockquote = insertSliceForListsInsideBlockquote;
8
8
  var _utils = require("@atlaskit/editor-common/utils");
9
+ var _model = require("@atlaskit/editor-prosemirror/model");
9
10
  var _state = require("@atlaskit/editor-prosemirror/state");
10
11
  var _transform = require("@atlaskit/editor-prosemirror/transform");
11
12
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
@@ -66,7 +67,9 @@ function insertSliceForLists(_ref) {
66
67
  function insertSliceForListsInsideBlockquote(_ref3) {
67
68
  var tr = _ref3.tr,
68
69
  slice = _ref3.slice;
69
- (0, _utils2.safeInsert)(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
70
+ //insert blockquote explicitly and set the selection in blockquote since replaceSelection will only insert the list
71
+ var schema = tr.doc.type.schema;
72
+ tr.replaceSelection(new _model.Slice(_model.Fragment.from(schema.nodes.blockquote.createAndFill()), 0, 0));
70
73
  // ProseMirror doesn't give a proper way to tell us where something was inserted.
71
74
  // However, we can know "how" it inserted something.
72
75
  //
@@ -85,4 +88,5 @@ function insertSliceForListsInsideBlockquote(_ref3) {
85
88
  if (nextSelection) {
86
89
  tr.setSelection(nextSelection);
87
90
  }
91
+ tr.replaceSelection(slice);
88
92
  }
@@ -154,7 +154,7 @@ function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChangedTr) {
154
154
  }
155
155
  function handlePasteNonNestableBlockNodesIntoList(slice) {
156
156
  return function (state, dispatch) {
157
- var _tr$doc$nodeAt, _sliceContent$firstCh, _findParentNodeOfType;
157
+ var _tr$doc$nodeAt, _slice$content$firstC2, _sliceContent$firstCh, _findParentNodeOfType;
158
158
  var tr = state.tr;
159
159
  var selection = tr.selection;
160
160
  var $from = selection.$from,
@@ -229,7 +229,12 @@ function handlePasteNonNestableBlockNodesIntoList(slice) {
229
229
  }
230
230
 
231
231
  // handle the insertion of the slice
232
- if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
232
+ if (((_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.type.name) === 'blockquote' && (0, _utils2.contains)(slice.content.firstChild, state.schema.nodes.listItem)) {
233
+ (0, _edgeCases.insertSliceForListsInsideBlockquote)({
234
+ tr: tr,
235
+ slice: slice
236
+ });
237
+ } else if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
233
238
  tr.replaceWith(from, replaceTo, sliceContent).scrollIntoView();
234
239
  } else {
235
240
  // When the selection is not at the end of a list item
@@ -331,10 +331,11 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
331
331
  if (isRichText && isInsideBlockQuote(state)) {
332
332
  //If pasting inside blockquote
333
333
  //Skip the blockquote node and keep remaining nodes as they are
334
+ //prevent doing this if there is list inside blockquote as the list is pasted incorrectly inside blockquote due to wrong openStart and openEnd
334
335
  var blockquote = schema.nodes.blockquote;
335
336
  var children = [];
336
337
  (0, _utils.mapChildren)(slice.content, function (node) {
337
- if (node.type === blockquote) {
338
+ if (node.type === blockquote && !(0, _utils2.contains)(node, state.schema.nodes.listItem)) {
338
339
  for (var i = 0; i < node.childCount; i++) {
339
340
  children.push(node.child(i));
340
341
  }
@@ -1,7 +1,8 @@
1
1
  import { isListNode } from '@atlaskit/editor-common/utils';
2
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
2
3
  import { Selection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
- import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
5
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
6
  import { isCursorSelectionAtTextStartOrEnd, isEmptyNode, isSelectionInsidePanel } from '../util';
6
7
  import { insertSliceAtNodeEdge, insertSliceInsideOfPanelNodeSelected, insertSliceIntoEmptyNode, insertSliceIntoRangeSelectionInsideList } from './lists';
7
8
  export function insertSliceForLists({
@@ -65,7 +66,11 @@ export function insertSliceForListsInsideBlockquote({
65
66
  tr,
66
67
  slice
67
68
  }) {
68
- safeInsert(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
69
+ //insert blockquote explicitly and set the selection in blockquote since replaceSelection will only insert the list
70
+ const {
71
+ schema
72
+ } = tr.doc.type;
73
+ tr.replaceSelection(new Slice(Fragment.from(schema.nodes.blockquote.createAndFill()), 0, 0));
69
74
  // ProseMirror doesn't give a proper way to tell us where something was inserted.
70
75
  // However, we can know "how" it inserted something.
71
76
  //
@@ -84,4 +89,5 @@ export function insertSliceForListsInsideBlockquote({
84
89
  if (nextSelection) {
85
90
  tr.setSelection(nextSelection);
86
91
  }
92
+ tr.replaceSelection(slice);
87
93
  }
@@ -7,7 +7,7 @@ import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isL
7
7
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
8
8
  import { Fragment, Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
9
9
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
10
- import { canInsert, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
10
+ import { canInsert, contains, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
11
11
  import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
12
12
  // TODO: ED-20519 Needs Macro extraction
13
13
 
@@ -130,7 +130,7 @@ export function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChange
130
130
  }
131
131
  export function handlePasteNonNestableBlockNodesIntoList(slice) {
132
132
  return (state, dispatch) => {
133
- var _tr$doc$nodeAt, _sliceContent$firstCh, _findParentNodeOfType;
133
+ var _tr$doc$nodeAt, _slice$content$firstC2, _sliceContent$firstCh, _findParentNodeOfType;
134
134
  const {
135
135
  tr
136
136
  } = state;
@@ -212,7 +212,12 @@ export function handlePasteNonNestableBlockNodesIntoList(slice) {
212
212
  }
213
213
 
214
214
  // handle the insertion of the slice
215
- if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
215
+ if (((_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.type.name) === 'blockquote' && contains(slice.content.firstChild, state.schema.nodes.listItem)) {
216
+ insertSliceForListsInsideBlockquote({
217
+ tr,
218
+ slice
219
+ });
220
+ } else if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
216
221
  tr.replaceWith(from, replaceTo, sliceContent).scrollIntoView();
217
222
  } else {
218
223
  // When the selection is not at the end of a list item
@@ -9,7 +9,7 @@ import { transformSingleLineCodeBlockToCodeMark, transformSliceNestedExpandToExp
9
9
  import { containsAnyAnnotations, extractSliceFromStep, linkifyContent, mapChildren, measureRender } from '@atlaskit/editor-common/utils';
10
10
  import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
11
11
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
12
- import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
12
+ import { contains, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
13
13
  import { handlePaste as handlePasteTable } from '@atlaskit/editor-tables/utils';
14
14
  import { PastePluginActionTypes } from '../actions';
15
15
  import { splitParagraphs, upgradeTextToLists } from '../commands';
@@ -300,12 +300,13 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
300
300
  if (isRichText && isInsideBlockQuote(state)) {
301
301
  //If pasting inside blockquote
302
302
  //Skip the blockquote node and keep remaining nodes as they are
303
+ //prevent doing this if there is list inside blockquote as the list is pasted incorrectly inside blockquote due to wrong openStart and openEnd
303
304
  const {
304
305
  blockquote
305
306
  } = schema.nodes;
306
307
  const children = [];
307
308
  mapChildren(slice.content, node => {
308
- if (node.type === blockquote) {
309
+ if (node.type === blockquote && !contains(node, state.schema.nodes.listItem)) {
309
310
  for (let i = 0; i < node.childCount; i++) {
310
311
  children.push(node.child(i));
311
312
  }
@@ -1,7 +1,8 @@
1
1
  import { isListNode } from '@atlaskit/editor-common/utils';
2
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
2
3
  import { Selection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
- import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
5
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
6
  import { isCursorSelectionAtTextStartOrEnd, isEmptyNode, isSelectionInsidePanel } from '../util';
6
7
  import { insertSliceAtNodeEdge, insertSliceInsideOfPanelNodeSelected, insertSliceIntoEmptyNode, insertSliceIntoRangeSelectionInsideList } from './lists';
7
8
  export function insertSliceForLists(_ref) {
@@ -59,7 +60,9 @@ export function insertSliceForLists(_ref) {
59
60
  export function insertSliceForListsInsideBlockquote(_ref3) {
60
61
  var tr = _ref3.tr,
61
62
  slice = _ref3.slice;
62
- safeInsert(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
63
+ //insert blockquote explicitly and set the selection in blockquote since replaceSelection will only insert the list
64
+ var schema = tr.doc.type.schema;
65
+ tr.replaceSelection(new Slice(Fragment.from(schema.nodes.blockquote.createAndFill()), 0, 0));
63
66
  // ProseMirror doesn't give a proper way to tell us where something was inserted.
64
67
  // However, we can know "how" it inserted something.
65
68
  //
@@ -78,4 +81,5 @@ export function insertSliceForListsInsideBlockquote(_ref3) {
78
81
  if (nextSelection) {
79
82
  tr.setSelection(nextSelection);
80
83
  }
84
+ tr.replaceSelection(slice);
81
85
  }
@@ -15,7 +15,7 @@ import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isL
15
15
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
16
16
  import { Fragment, Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
17
17
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
18
- import { canInsert, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
18
+ import { canInsert, contains, findParentNodeOfType, findParentNodeOfTypeClosestToPos, hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
19
19
  import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
20
20
  // TODO: ED-20519 Needs Macro extraction
21
21
 
@@ -133,7 +133,7 @@ export function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChange
133
133
  }
134
134
  export function handlePasteNonNestableBlockNodesIntoList(slice) {
135
135
  return function (state, dispatch) {
136
- var _tr$doc$nodeAt, _sliceContent$firstCh, _findParentNodeOfType;
136
+ var _tr$doc$nodeAt, _slice$content$firstC2, _sliceContent$firstCh, _findParentNodeOfType;
137
137
  var tr = state.tr;
138
138
  var selection = tr.selection;
139
139
  var $from = selection.$from,
@@ -208,7 +208,12 @@ export function handlePasteNonNestableBlockNodesIntoList(slice) {
208
208
  }
209
209
 
210
210
  // handle the insertion of the slice
211
- if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
211
+ if (((_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.type.name) === 'blockquote' && contains(slice.content.firstChild, state.schema.nodes.listItem)) {
212
+ insertSliceForListsInsideBlockquote({
213
+ tr: tr,
214
+ slice: slice
215
+ });
216
+ } else if (sliceContainsNodeThatPastesAsPlainText || nodeAfterInsertPositionIsListItem || sliceContent.childCount > 1 && ((_sliceContent$firstCh = sliceContent.firstChild) === null || _sliceContent$firstCh === void 0 ? void 0 : _sliceContent$firstCh.type.name) !== 'paragraph') {
212
217
  tr.replaceWith(from, replaceTo, sliceContent).scrollIntoView();
213
218
  } else {
214
219
  // When the selection is not at the end of a list item
@@ -11,7 +11,7 @@ import { transformSingleLineCodeBlockToCodeMark, transformSliceNestedExpandToExp
11
11
  import { containsAnyAnnotations, extractSliceFromStep, linkifyContent, mapChildren, measureRender } from '@atlaskit/editor-common/utils';
12
12
  import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
13
13
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
14
- import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
14
+ import { contains, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
15
15
  import { handlePaste as handlePasteTable } from '@atlaskit/editor-tables/utils';
16
16
  import { PastePluginActionTypes } from '../actions';
17
17
  import { splitParagraphs, upgradeTextToLists } from '../commands';
@@ -318,10 +318,11 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
318
318
  if (isRichText && isInsideBlockQuote(state)) {
319
319
  //If pasting inside blockquote
320
320
  //Skip the blockquote node and keep remaining nodes as they are
321
+ //prevent doing this if there is list inside blockquote as the list is pasted incorrectly inside blockquote due to wrong openStart and openEnd
321
322
  var blockquote = schema.nodes.blockquote;
322
323
  var children = [];
323
324
  mapChildren(slice.content, function (node) {
324
- if (node.type === blockquote) {
325
+ if (node.type === blockquote && !contains(node, state.schema.nodes.listItem)) {
325
326
  for (var i = 0; i < node.childCount; i++) {
326
327
  children.push(node.child(i));
327
328
  }
@@ -1,11 +1,11 @@
1
- import type { Schema, Slice } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Slice as PMSlice, Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare function insertSliceForLists({ tr, slice, schema, }: {
4
4
  tr: Transaction;
5
- slice: Slice;
5
+ slice: PMSlice;
6
6
  schema: Schema;
7
7
  }): void | Transaction;
8
8
  export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
9
9
  tr: Transaction;
10
- slice: Slice;
10
+ slice: PMSlice;
11
11
  }): Transaction | undefined;
@@ -1,11 +1,11 @@
1
- import type { Schema, Slice } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Slice as PMSlice, Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare function insertSliceForLists({ tr, slice, schema, }: {
4
4
  tr: Transaction;
5
- slice: Slice;
5
+ slice: PMSlice;
6
6
  schema: Schema;
7
7
  }): void | Transaction;
8
8
  export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
9
9
  tr: Transaction;
10
- slice: Slice;
10
+ slice: PMSlice;
11
11
  }): Transaction | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,14 +32,14 @@
32
32
  ".": "./src/index.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@atlaskit/editor-common": "^76.30.0",
35
+ "@atlaskit/editor-common": "^76.33.0",
36
36
  "@atlaskit/editor-markdown-transformer": "^5.2.5",
37
37
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
38
38
  "@atlaskit/editor-plugin-annotation": "^0.1.0",
39
39
  "@atlaskit/editor-plugin-better-type-history": "^0.1.0",
40
- "@atlaskit/editor-plugin-card": "^0.14.0",
40
+ "@atlaskit/editor-plugin-card": "^0.15.0",
41
41
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
42
- "@atlaskit/editor-plugin-list": "^3.0.0",
42
+ "@atlaskit/editor-plugin-list": "^3.1.0",
43
43
  "@atlaskit/editor-plugin-media": "^0.9.0",
44
44
  "@atlaskit/editor-prosemirror": "1.1.0",
45
45
  "@atlaskit/editor-tables": "^2.3.0",
@@ -56,12 +56,14 @@
56
56
  "devDependencies": {
57
57
  "@af/visual-regression": "*",
58
58
  "@atlaskit/adf-schema": "^35.2.0",
59
+ "@atlaskit/editor-plugin-block-type": "^3.0.0",
59
60
  "@atlaskit/editor-plugin-history": "^0.1.0",
60
61
  "@atlaskit/editor-plugin-type-ahead": "^0.8.0",
61
62
  "@atlaskit/ssr": "*",
62
63
  "@atlaskit/visual-regression": "*",
63
64
  "@atlaskit/webdriver-runner": "*",
64
65
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
66
+ "@atlassian/feature-flags-test-utils": "^0.1.1",
65
67
  "@testing-library/react": "^12.1.5",
66
68
  "react-dom": "^16.8.0",
67
69
  "typescript": "~4.9.5",