@atlaskit/editor-core 189.5.0 → 189.5.1

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,11 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 189.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#58597](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58597) [`205975214b9c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/205975214b9c) - ED-20961: Handle copy paste - list with blockquote
8
+
3
9
  ## 189.5.0
4
10
 
5
11
  ### Minor Changes
@@ -4,9 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.insertSliceForLists = insertSliceForLists;
7
+ exports.insertSliceForListsInsideBlockquote = insertSliceForListsInsideBlockquote;
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
7
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
8
10
  var _lists = require("./lists");
9
11
  var _utils2 = require("@atlaskit/editor-common/utils");
12
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
10
13
  var _util = require("../util");
11
14
  function insertSliceForLists(_ref) {
12
15
  var _slice$content$firstC;
@@ -59,4 +62,27 @@ function insertSliceForLists(_ref) {
59
62
  });
60
63
  }
61
64
  tr.replaceSelection(slice);
65
+ }
66
+ function insertSliceForListsInsideBlockquote(_ref3) {
67
+ var tr = _ref3.tr,
68
+ slice = _ref3.slice;
69
+ (0, _utils.safeInsert)(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
70
+ // ProseMirror doesn't give a proper way to tell us where something was inserted.
71
+ // However, we can know "how" it inserted something.
72
+ //
73
+ // So, instead of weird depth calculations, we can use the step produced by the transform.
74
+ // For instance:
75
+ // The `replaceStep.to and replaceStep.from`, tell us the real position
76
+ // where the content will be insert.
77
+ // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
78
+ var replaceStep = tr.steps[0];
79
+ if (!(replaceStep instanceof _transform.ReplaceStep)) {
80
+ return tr;
81
+ }
82
+ var nextPosition = tr.mapping.map(replaceStep.to);
83
+ // The findFrom will make search for both: TextSelection and NodeSelections.
84
+ var nextSelection = _state.Selection.findFrom(tr.doc.resolve(Math.min(nextPosition, tr.doc.content.size)), -1);
85
+ if (nextSelection) {
86
+ tr.setSelection(nextSelection);
87
+ }
62
88
  }
@@ -861,15 +861,24 @@ function handleRichText(slice, queueCardsFromChangedTr) {
861
861
  schema: schema
862
862
  });
863
863
  } else if (noNeedForSafeInsert) {
864
- var _slice$content$lastCh;
865
- tr.replaceSelection(slice);
866
- // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
867
- // need to make sure the cursor position is is right after the panel, expand, or decisionList
868
- // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
869
- var shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 || (_slice$content$lastCh = _slice$content$lastCh.type) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.name) || '');
870
- if ((0, _utils3.insideTableCell)(state) && shouldUpdateCursorPosAfterPaste) {
871
- var nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
872
- tr.setSelection(new _selection.GapCursorSelection(nextPos, _selection.Side.RIGHT));
864
+ var _firstChildOfSlice$ty2, _firstChildOfSlice$co;
865
+ if ((firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && (firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co === void 0 ? void 0 : _firstChildOfSlice$co.type.name) === ('bulletList' || 'orderedList')) {
866
+ // checks if parent node is a blockquote and child node is either a bulletlist or orderedlist
867
+ (0, _edgeCases.insertSliceForListsInsideBlockquote)({
868
+ tr: tr,
869
+ slice: slice
870
+ });
871
+ } else {
872
+ var _slice$content$lastCh;
873
+ tr.replaceSelection(slice);
874
+ // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
875
+ // need to make sure the cursor position is is right after the panel, expand, or decisionList
876
+ // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
877
+ var shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 || (_slice$content$lastCh = _slice$content$lastCh.type) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.name) || '');
878
+ if ((0, _utils3.insideTableCell)(state) && shouldUpdateCursorPosAfterPaste) {
879
+ var nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
880
+ tr.setSelection(new _selection.GapCursorSelection(nextPos, _selection.Side.RIGHT));
881
+ }
873
882
  }
874
883
  } else {
875
884
  // need to scan the slice if there's a block node or list items inside it
@@ -5,4 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "189.5.0";
8
+ var version = exports.version = "189.5.1";
@@ -1,6 +1,8 @@
1
- import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
1
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
2
3
  import { insertSliceIntoRangeSelectionInsideList, insertSliceInsideOfPanelNodeSelected, insertSliceAtNodeEdge, insertSliceIntoEmptyNode } from './lists';
3
4
  import { isListNode } from '@atlaskit/editor-common/utils';
5
+ import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
6
  import { isSelectionInsidePanel, isEmptyNode, isCursorSelectionAtTextStartOrEnd } from '../util';
5
7
  export function insertSliceForLists({
6
8
  tr,
@@ -58,4 +60,28 @@ export function insertSliceForLists({
58
60
  });
59
61
  }
60
62
  tr.replaceSelection(slice);
63
+ }
64
+ export function insertSliceForListsInsideBlockquote({
65
+ tr,
66
+ slice
67
+ }) {
68
+ safeInsert(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
69
+ // ProseMirror doesn't give a proper way to tell us where something was inserted.
70
+ // However, we can know "how" it inserted something.
71
+ //
72
+ // So, instead of weird depth calculations, we can use the step produced by the transform.
73
+ // For instance:
74
+ // The `replaceStep.to and replaceStep.from`, tell us the real position
75
+ // where the content will be insert.
76
+ // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
77
+ const replaceStep = tr.steps[0];
78
+ if (!(replaceStep instanceof ReplaceStep)) {
79
+ return tr;
80
+ }
81
+ const nextPosition = tr.mapping.map(replaceStep.to);
82
+ // The findFrom will make search for both: TextSelection and NodeSelections.
83
+ const nextSelection = Selection.findFrom(tr.doc.resolve(Math.min(nextPosition, tr.doc.content.size)), -1);
84
+ if (nextSelection) {
85
+ tr.setSelection(nextSelection);
86
+ }
61
87
  }
@@ -11,7 +11,7 @@ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
11
11
  // TODO: ED-20519 Needs Macro extraction
12
12
 
13
13
  import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType } from './util';
14
- import { insertSliceForLists } from './edge-cases';
14
+ import { insertSliceForLists, insertSliceForListsInsideBlockquote } from './edge-cases';
15
15
  import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
16
16
  import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
17
17
  import { anyMarkActive } from '@atlaskit/editor-common/mark';
@@ -843,15 +843,24 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
843
843
  schema
844
844
  });
845
845
  } else if (noNeedForSafeInsert) {
846
- var _slice$content$lastCh, _slice$content$lastCh2;
847
- tr.replaceSelection(slice);
848
- // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
849
- // need to make sure the cursor position is is right after the panel, expand, or decisionList
850
- // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
851
- const shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : (_slice$content$lastCh2 = _slice$content$lastCh.type) === null || _slice$content$lastCh2 === void 0 ? void 0 : _slice$content$lastCh2.name) || '');
852
- if (insideTableCell(state) && shouldUpdateCursorPosAfterPaste) {
853
- const nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
854
- tr.setSelection(new GapCursorSelection(nextPos, Side.RIGHT));
846
+ var _firstChildOfSlice$ty2, _firstChildOfSlice$co;
847
+ if ((firstChildOfSlice === null || firstChildOfSlice === void 0 ? void 0 : (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && (firstChildOfSlice === null || firstChildOfSlice === void 0 ? void 0 : (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co === void 0 ? void 0 : _firstChildOfSlice$co.type.name) === ('bulletList' || 'orderedList')) {
848
+ // checks if parent node is a blockquote and child node is either a bulletlist or orderedlist
849
+ insertSliceForListsInsideBlockquote({
850
+ tr,
851
+ slice
852
+ });
853
+ } else {
854
+ var _slice$content$lastCh, _slice$content$lastCh2;
855
+ tr.replaceSelection(slice);
856
+ // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
857
+ // need to make sure the cursor position is is right after the panel, expand, or decisionList
858
+ // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
859
+ const shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : (_slice$content$lastCh2 = _slice$content$lastCh.type) === null || _slice$content$lastCh2 === void 0 ? void 0 : _slice$content$lastCh2.name) || '');
860
+ if (insideTableCell(state) && shouldUpdateCursorPosAfterPaste) {
861
+ const nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
862
+ tr.setSelection(new GapCursorSelection(nextPos, Side.RIGHT));
863
+ }
855
864
  }
856
865
  } else {
857
866
  // need to scan the slice if there's a block node or list items inside it
@@ -1,2 +1,2 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "189.5.0";
2
+ export const version = "189.5.1";
@@ -1,6 +1,8 @@
1
- import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
1
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
2
3
  import { insertSliceIntoRangeSelectionInsideList, insertSliceInsideOfPanelNodeSelected, insertSliceAtNodeEdge, insertSliceIntoEmptyNode } from './lists';
3
4
  import { isListNode } from '@atlaskit/editor-common/utils';
5
+ import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
6
  import { isSelectionInsidePanel, isEmptyNode, isCursorSelectionAtTextStartOrEnd } from '../util';
5
7
  export function insertSliceForLists(_ref) {
6
8
  var _slice$content$firstC;
@@ -53,4 +55,27 @@ export function insertSliceForLists(_ref) {
53
55
  });
54
56
  }
55
57
  tr.replaceSelection(slice);
58
+ }
59
+ export function insertSliceForListsInsideBlockquote(_ref3) {
60
+ var tr = _ref3.tr,
61
+ slice = _ref3.slice;
62
+ safeInsert(slice.content, tr.selection.$to.pos)(tr).scrollIntoView();
63
+ // ProseMirror doesn't give a proper way to tell us where something was inserted.
64
+ // However, we can know "how" it inserted something.
65
+ //
66
+ // So, instead of weird depth calculations, we can use the step produced by the transform.
67
+ // For instance:
68
+ // The `replaceStep.to and replaceStep.from`, tell us the real position
69
+ // where the content will be insert.
70
+ // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
71
+ var replaceStep = tr.steps[0];
72
+ if (!(replaceStep instanceof ReplaceStep)) {
73
+ return tr;
74
+ }
75
+ var nextPosition = tr.mapping.map(replaceStep.to);
76
+ // The findFrom will make search for both: TextSelection and NodeSelections.
77
+ var nextSelection = Selection.findFrom(tr.doc.resolve(Math.min(nextPosition, tr.doc.content.size)), -1);
78
+ if (nextSelection) {
79
+ tr.setSelection(nextSelection);
80
+ }
56
81
  }
@@ -19,7 +19,7 @@ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
19
19
  // TODO: ED-20519 Needs Macro extraction
20
20
 
21
21
  import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType } from './util';
22
- import { insertSliceForLists } from './edge-cases';
22
+ import { insertSliceForLists, insertSliceForListsInsideBlockquote } from './edge-cases';
23
23
  import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
24
24
  import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
25
25
  import { anyMarkActive } from '@atlaskit/editor-common/mark';
@@ -840,15 +840,24 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
840
840
  schema: schema
841
841
  });
842
842
  } else if (noNeedForSafeInsert) {
843
- var _slice$content$lastCh;
844
- tr.replaceSelection(slice);
845
- // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
846
- // need to make sure the cursor position is is right after the panel, expand, or decisionList
847
- // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
848
- var shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 || (_slice$content$lastCh = _slice$content$lastCh.type) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.name) || '');
849
- if (insideTableCell(state) && shouldUpdateCursorPosAfterPaste) {
850
- var nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
851
- tr.setSelection(new GapCursorSelection(nextPos, Side.RIGHT));
843
+ var _firstChildOfSlice$ty2, _firstChildOfSlice$co;
844
+ if ((firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$ty2 = firstChildOfSlice.type) === null || _firstChildOfSlice$ty2 === void 0 ? void 0 : _firstChildOfSlice$ty2.name) === 'blockquote' && (firstChildOfSlice === null || firstChildOfSlice === void 0 || (_firstChildOfSlice$co = firstChildOfSlice.content.firstChild) === null || _firstChildOfSlice$co === void 0 ? void 0 : _firstChildOfSlice$co.type.name) === ('bulletList' || 'orderedList')) {
845
+ // checks if parent node is a blockquote and child node is either a bulletlist or orderedlist
846
+ insertSliceForListsInsideBlockquote({
847
+ tr: tr,
848
+ slice: slice
849
+ });
850
+ } else {
851
+ var _slice$content$lastCh;
852
+ tr.replaceSelection(slice);
853
+ // when cursor is inside a table cell, and slice.content.lastChild is a panel, expand, or decisionList
854
+ // need to make sure the cursor position is is right after the panel, expand, or decisionList
855
+ // still in the same table cell, see issue: https://product-fabric.atlassian.net/browse/ED-17862
856
+ var shouldUpdateCursorPosAfterPaste = ['panel', 'nestedExpand', 'decisionList', 'codeBlock'].includes(((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 || (_slice$content$lastCh = _slice$content$lastCh.type) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.name) || '');
857
+ if (insideTableCell(state) && shouldUpdateCursorPosAfterPaste) {
858
+ var nextPos = tr.doc.resolve(tr.mapping.map(selection.$from.pos));
859
+ tr.setSelection(new GapCursorSelection(nextPos, Side.RIGHT));
860
+ }
852
861
  }
853
862
  } else {
854
863
  // need to scan the slice if there's a block node or list items inside it
@@ -1,2 +1,2 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "189.5.0";
2
+ export var version = "189.5.1";
@@ -5,3 +5,7 @@ export declare function insertSliceForLists({ tr, slice, schema, }: {
5
5
  slice: Slice;
6
6
  schema: Schema;
7
7
  }): void | Transaction;
8
+ export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
9
+ tr: Transaction;
10
+ slice: Slice;
11
+ }): Transaction | undefined;
@@ -5,3 +5,7 @@ export declare function insertSliceForLists({ tr, slice, schema, }: {
5
5
  slice: Slice;
6
6
  schema: Schema;
7
7
  }): void | Transaction;
8
+ export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
9
+ tr: Transaction;
10
+ slice: Slice;
11
+ }): Transaction | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "189.5.0",
3
+ "version": "189.5.1",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"