@atlaskit/editor-plugin-paste 0.2.8 → 0.2.9

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,13 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 0.2.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#66826](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66826) [`5e9f6778a15a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5e9f6778a15a) - [ux] resolved a bug where the cursor mispalced after pasting the media into the panel
8
+ - [#67283](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/67283) [`4f10a52c6e39`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4f10a52c6e39) - ED-21613 handle incorrect cursor position - when task is copied into a list
9
+ - Updated dependencies
10
+
3
11
  ## 0.2.8
4
12
 
5
13
  ### Patch Changes
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.insertSliceForLists = insertSliceForLists;
7
7
  exports.insertSliceForListsInsideBlockquote = insertSliceForListsInsideBlockquote;
8
+ exports.updateSelectionAfterReplace = updateSelectionAfterReplace;
8
9
  var _utils = require("@atlaskit/editor-common/utils");
9
10
  var _model = require("@atlaskit/editor-prosemirror/model");
10
11
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -70,6 +71,13 @@ function insertSliceForListsInsideBlockquote(_ref3) {
70
71
  //insert blockquote explicitly and set the selection in blockquote since replaceSelection will only insert the list
71
72
  var schema = tr.doc.type.schema;
72
73
  tr.replaceSelection(new _model.Slice(_model.Fragment.from(schema.nodes.blockquote.createAndFill()), 0, 0));
74
+ updateSelectionAfterReplace({
75
+ tr: tr
76
+ });
77
+ tr.replaceSelection(slice);
78
+ }
79
+ function updateSelectionAfterReplace(_ref4) {
80
+ var tr = _ref4.tr;
73
81
  // ProseMirror doesn't give a proper way to tell us where something was inserted.
74
82
  // However, we can know "how" it inserted something.
75
83
  //
@@ -78,6 +86,7 @@ function insertSliceForListsInsideBlockquote(_ref3) {
78
86
  // The `replaceStep.to and replaceStep.from`, tell us the real position
79
87
  // where the content will be insert.
80
88
  // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
89
+
81
90
  var replaceStep = tr.steps[0];
82
91
  if (!(replaceStep instanceof _transform.ReplaceStep)) {
83
92
  return tr;
@@ -88,5 +97,4 @@ function insertSliceForListsInsideBlockquote(_ref3) {
88
97
  if (nextSelection) {
89
98
  tr.setSelection(nextSelection);
90
99
  }
91
- tr.replaceSelection(slice);
92
100
  }
@@ -143,6 +143,16 @@ function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChangedTr) {
143
143
  // Whole codeblock node has reverse slice depths.
144
144
  transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
145
145
  tr.replaceSelection(transformedSlice).scrollIntoView();
146
+ } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
147
+ var parentNode = (0, _utils2.findParentNodeOfType)(panel)(selection);
148
+ if (selectionIsPanel && parentNode && (0, _utils.isNodeEmpty)(parentNode.node)) {
149
+ tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
150
+ // Place the cursor at the the end of the insersertion
151
+ var endPos = tr.selection.from + transformedSlice.size;
152
+ tr.setSelection(new _state.TextSelection(tr.doc.resolve(endPos)));
153
+ } else {
154
+ tr.replaceSelection(transformedSlice).scrollIntoView();
155
+ }
146
156
  } else {
147
157
  // This maintains both the selection (destination) and the slice (paste content).
148
158
  (0, _utils2.safeInsert)(transformedSlice.content)(tr).scrollIntoView();
@@ -827,7 +837,7 @@ function flattenNestedListInSlice(slice) {
827
837
  }
828
838
  function handleRichText(slice, queueCardsFromChangedTr) {
829
839
  return function (state, dispatch) {
830
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
840
+ var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre, _slice$content$firstC3;
831
841
  var _state$schema$nodes3 = state.schema.nodes,
832
842
  codeBlock = _state$schema$nodes3.codeBlock,
833
843
  heading = _state$schema$nodes3.heading,
@@ -910,6 +920,11 @@ function handleRichText(slice, queueCardsFromChangedTr) {
910
920
  if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
911
921
  tr.setSelection(_state.TextSelection.near(tr.selection.$from, 1));
912
922
  }
923
+ if ((0, _utils.isInListItem)(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 || (_slice$content$firstC3 = _slice$content$firstC3.type) === null || _slice$content$firstC3 === void 0 ? void 0 : _slice$content$firstC3.name) || '')) {
924
+ (0, _edgeCases.updateSelectionAfterReplace)({
925
+ tr: tr
926
+ });
927
+ }
913
928
  tr.scrollIntoView();
914
929
 
915
930
  // queue link cards, ignoring any errors
@@ -71,6 +71,14 @@ export function insertSliceForListsInsideBlockquote({
71
71
  schema
72
72
  } = tr.doc.type;
73
73
  tr.replaceSelection(new Slice(Fragment.from(schema.nodes.blockquote.createAndFill()), 0, 0));
74
+ updateSelectionAfterReplace({
75
+ tr
76
+ });
77
+ tr.replaceSelection(slice);
78
+ }
79
+ export function updateSelectionAfterReplace({
80
+ tr
81
+ }) {
74
82
  // ProseMirror doesn't give a proper way to tell us where something was inserted.
75
83
  // However, we can know "how" it inserted something.
76
84
  //
@@ -79,6 +87,7 @@ export function insertSliceForListsInsideBlockquote({
79
87
  // The `replaceStep.to and replaceStep.from`, tell us the real position
80
88
  // where the content will be insert.
81
89
  // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
90
+
82
91
  const replaceStep = tr.steps[0];
83
92
  if (!(replaceStep instanceof ReplaceStep)) {
84
93
  return tr;
@@ -89,5 +98,4 @@ export function insertSliceForListsInsideBlockquote({
89
98
  if (nextSelection) {
90
99
  tr.setSelection(nextSelection);
91
100
  }
92
- tr.replaceSelection(slice);
93
101
  }
@@ -3,7 +3,7 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
3
  import { insideTable } from '@atlaskit/editor-common/core-utils';
4
4
  import { anyMarkActive } from '@atlaskit/editor-common/mark';
5
5
  import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
6
- import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isListItemNode, isListNode, isParagraph, isText, linkifyContent, mapSlice } from '@atlaskit/editor-common/utils';
6
+ import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isListItemNode, isListNode, isNodeEmpty, isParagraph, isText, linkifyContent, mapSlice } from '@atlaskit/editor-common/utils';
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';
@@ -12,7 +12,7 @@ import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
12
12
  // TODO: ED-20519 Needs Macro extraction
13
13
 
14
14
  import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
15
- import { insertSliceForLists, insertSliceForListsInsideBlockquote } from './edge-cases';
15
+ import { insertSliceForLists, insertSliceForListsInsideBlockquote, updateSelectionAfterReplace } from './edge-cases';
16
16
  import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
17
17
  import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType } from './util';
18
18
 
@@ -119,6 +119,16 @@ export function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChange
119
119
  // Whole codeblock node has reverse slice depths.
120
120
  transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
121
121
  tr.replaceSelection(transformedSlice).scrollIntoView();
122
+ } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
123
+ const parentNode = findParentNodeOfType(panel)(selection);
124
+ if (selectionIsPanel && parentNode && isNodeEmpty(parentNode.node)) {
125
+ tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
126
+ // Place the cursor at the the end of the insersertion
127
+ const endPos = tr.selection.from + transformedSlice.size;
128
+ tr.setSelection(new TextSelection(tr.doc.resolve(endPos)));
129
+ } else {
130
+ tr.replaceSelection(transformedSlice).scrollIntoView();
131
+ }
122
132
  } else {
123
133
  // This maintains both the selection (destination) and the slice (paste content).
124
134
  safeInsert(transformedSlice.content)(tr).scrollIntoView();
@@ -806,7 +816,7 @@ export function flattenNestedListInSlice(slice) {
806
816
  }
807
817
  export function handleRichText(slice, queueCardsFromChangedTr) {
808
818
  return (state, dispatch) => {
809
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
819
+ var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre, _slice$content$firstC3, _slice$content$firstC4;
810
820
  const {
811
821
  codeBlock,
812
822
  heading,
@@ -892,6 +902,11 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
892
902
  if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
893
903
  tr.setSelection(TextSelection.near(tr.selection.$from, 1));
894
904
  }
905
+ if (isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 ? void 0 : (_slice$content$firstC4 = _slice$content$firstC3.type) === null || _slice$content$firstC4 === void 0 ? void 0 : _slice$content$firstC4.name) || '')) {
906
+ updateSelectionAfterReplace({
907
+ tr
908
+ });
909
+ }
895
910
  tr.scrollIntoView();
896
911
 
897
912
  // queue link cards, ignoring any errors
@@ -63,6 +63,13 @@ export function insertSliceForListsInsideBlockquote(_ref3) {
63
63
  //insert blockquote explicitly and set the selection in blockquote since replaceSelection will only insert the list
64
64
  var schema = tr.doc.type.schema;
65
65
  tr.replaceSelection(new Slice(Fragment.from(schema.nodes.blockquote.createAndFill()), 0, 0));
66
+ updateSelectionAfterReplace({
67
+ tr: tr
68
+ });
69
+ tr.replaceSelection(slice);
70
+ }
71
+ export function updateSelectionAfterReplace(_ref4) {
72
+ var tr = _ref4.tr;
66
73
  // ProseMirror doesn't give a proper way to tell us where something was inserted.
67
74
  // However, we can know "how" it inserted something.
68
75
  //
@@ -71,6 +78,7 @@ export function insertSliceForListsInsideBlockquote(_ref3) {
71
78
  // The `replaceStep.to and replaceStep.from`, tell us the real position
72
79
  // where the content will be insert.
73
80
  // Then, we can use the `tr.mapping.map` to the updated position after the replace operation
81
+
74
82
  var replaceStep = tr.steps[0];
75
83
  if (!(replaceStep instanceof ReplaceStep)) {
76
84
  return tr;
@@ -81,5 +89,4 @@ export function insertSliceForListsInsideBlockquote(_ref3) {
81
89
  if (nextSelection) {
82
90
  tr.setSelection(nextSelection);
83
91
  }
84
- tr.replaceSelection(slice);
85
92
  }
@@ -11,7 +11,7 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
11
11
  import { insideTable } from '@atlaskit/editor-common/core-utils';
12
12
  import { anyMarkActive } from '@atlaskit/editor-common/mark';
13
13
  import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
14
- import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isListItemNode, isListNode, isParagraph, isText, linkifyContent, mapSlice } from '@atlaskit/editor-common/utils';
14
+ import { canLinkBeCreatedInRange, insideTableCell, isInListItem, isLinkMark, isListItemNode, isListNode, isNodeEmpty, isParagraph, isText, linkifyContent, mapSlice } from '@atlaskit/editor-common/utils';
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';
@@ -20,7 +20,7 @@ import { replaceSelectedTable } from '@atlaskit/editor-tables/utils';
20
20
  // TODO: ED-20519 Needs Macro extraction
21
21
 
22
22
  import { startTrackingPastedMacroPositions, stopTrackingPastedMacroPositions } from './commands';
23
- import { insertSliceForLists, insertSliceForListsInsideBlockquote } from './edge-cases';
23
+ import { insertSliceForLists, insertSliceForListsInsideBlockquote, updateSelectionAfterReplace } from './edge-cases';
24
24
  import { getPluginState as getPastePluginState } from './pm-plugins/plugin-factory';
25
25
  import { addReplaceSelectedTableAnalytics, applyTextMarksToSlice, hasOnlyNodesOfType } from './util';
26
26
 
@@ -122,6 +122,16 @@ export function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChange
122
122
  // Whole codeblock node has reverse slice depths.
123
123
  transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
124
124
  tr.replaceSelection(transformedSlice).scrollIntoView();
125
+ } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
126
+ var parentNode = findParentNodeOfType(panel)(selection);
127
+ if (selectionIsPanel && parentNode && isNodeEmpty(parentNode.node)) {
128
+ tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
129
+ // Place the cursor at the the end of the insersertion
130
+ var endPos = tr.selection.from + transformedSlice.size;
131
+ tr.setSelection(new TextSelection(tr.doc.resolve(endPos)));
132
+ } else {
133
+ tr.replaceSelection(transformedSlice).scrollIntoView();
134
+ }
125
135
  } else {
126
136
  // This maintains both the selection (destination) and the slice (paste content).
127
137
  safeInsert(transformedSlice.content)(tr).scrollIntoView();
@@ -806,7 +816,7 @@ export function flattenNestedListInSlice(slice) {
806
816
  }
807
817
  export function handleRichText(slice, queueCardsFromChangedTr) {
808
818
  return function (state, dispatch) {
809
- var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre;
819
+ var _slice$content, _slice$content2, _firstChildOfSlice$ty, _lastChildOfSlice$typ, _panelParentOverCurre, _slice$content$firstC3;
810
820
  var _state$schema$nodes3 = state.schema.nodes,
811
821
  codeBlock = _state$schema$nodes3.codeBlock,
812
822
  heading = _state$schema$nodes3.heading,
@@ -889,6 +899,11 @@ export function handleRichText(slice, queueCardsFromChangedTr) {
889
899
  if (tr.selection.empty && tr.selection.$from.parent.type === codeBlock) {
890
900
  tr.setSelection(TextSelection.near(tr.selection.$from, 1));
891
901
  }
902
+ if (isInListItem(state) && ['taskList', 'taskItem'].includes(((_slice$content$firstC3 = slice.content.firstChild) === null || _slice$content$firstC3 === void 0 || (_slice$content$firstC3 = _slice$content$firstC3.type) === null || _slice$content$firstC3 === void 0 ? void 0 : _slice$content$firstC3.name) || '')) {
903
+ updateSelectionAfterReplace({
904
+ tr: tr
905
+ });
906
+ }
892
907
  tr.scrollIntoView();
893
908
 
894
909
  // queue link cards, ignoring any errors
@@ -8,4 +8,7 @@ export declare function insertSliceForLists({ tr, slice, schema, }: {
8
8
  export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
9
9
  tr: Transaction;
10
10
  slice: PMSlice;
11
+ }): void;
12
+ export declare function updateSelectionAfterReplace({ tr }: {
13
+ tr: Transaction;
11
14
  }): Transaction | undefined;
@@ -8,4 +8,7 @@ export declare function insertSliceForLists({ tr, slice, schema, }: {
8
8
  export declare function insertSliceForListsInsideBlockquote({ tr, slice, }: {
9
9
  tr: Transaction;
10
10
  slice: PMSlice;
11
+ }): void;
12
+ export declare function updateSelectionAfterReplace({ tr }: {
13
+ tr: Transaction;
11
14
  }): Transaction | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -14,7 +14,7 @@
14
14
  "releaseModel": "continuous",
15
15
  "runReact18": false
16
16
  },
17
- "repository": "https://bitbucket.org/atlassian/atlassian-frontend",
17
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
18
18
  "main": "dist/cjs/index.js",
19
19
  "module": "dist/esm/index.js",
20
20
  "module:es2019": "dist/es2019/index.js",
@@ -33,7 +33,7 @@
33
33
  ".": "./src/index.ts"
34
34
  },
35
35
  "dependencies": {
36
- "@atlaskit/editor-common": "^76.39.0",
36
+ "@atlaskit/editor-common": "^76.41.0",
37
37
  "@atlaskit/editor-markdown-transformer": "^5.3.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
39
39
  "@atlaskit/editor-plugin-annotation": "^0.1.0",