@atlaskit/editor-plugin-paste 0.2.15 → 0.2.17

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,18 @@
1
1
  # @atlaskit/editor-plugin-paste
2
2
 
3
+ ## 0.2.17
4
+
5
+ ### Patch Changes
6
+
7
+ - [#70164](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70164) [`a6438ad5ed9d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a6438ad5ed9d) - ED-21974 Pasting node into panel should replace the selected text
8
+
9
+ ## 0.2.16
10
+
11
+ ### Patch Changes
12
+
13
+ - [#69736](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/69736) [`febb7827b916`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/febb7827b916) - ED-21619 Set correct cursor position on pasting a rule inside panel
14
+ - Updated dependencies
15
+
3
16
  ## 0.2.15
4
17
 
5
18
  ### Patch Changes
@@ -140,36 +140,43 @@ function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChangedTr) {
140
140
  // and the slice is not a whole node (i.e. openStart is 1 and openEnd is 0)
141
141
  // or the slice's first node is a paragraph,
142
142
  // then we can replace the selection with our slice.
143
- var pastingDecisionIntoExtendedPanel = selectionIsPanel && transformedSlice.content.firstChild.type.name === 'decisionList' && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.allow-extended-panel');
144
- if ((transformedSliceIsValidNode || selectionIsValidNode) && !pastingDecisionIntoExtendedPanel && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
143
+ var pastingIntoExtendedPanel = selectionIsPanel && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.allow-extended-panel') && panel.validContent(transformedSlice.content);
144
+ if ((transformedSliceIsValidNode || selectionIsValidNode) && !pastingIntoExtendedPanel && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
145
145
  // Whole codeblock node has reverse slice depths.
146
146
  transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
147
147
  tr.replaceSelection(transformedSlice).scrollIntoView();
148
- } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
149
- var parentNode = (0, _utils2.findParentNodeOfType)(panel)(selection);
150
- if (selectionIsPanel && parentNode && (0, _utils.isNodeEmpty)(parentNode.node)) {
151
- tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
152
- // Place the cursor at the the end of the insersertion
153
- var endPos = tr.selection.from + transformedSlice.size;
154
- tr.setSelection(new _state.TextSelection(tr.doc.resolve(endPos)));
155
- } else {
156
- tr.replaceSelection(transformedSlice).scrollIntoView();
157
- }
158
148
  } else {
159
- if (pastingDecisionIntoExtendedPanel && selectionIsValidNode) {
160
- tr.replaceSelection(transformedSlice).scrollIntoView();
149
+ var isWholeContentSelected = selection.$from.pos === selection.$from.start() && selection.$to.end() === selection.$to.pos;
150
+ if (pastingIntoExtendedPanel && selection.$from.pos !== selection.$to.pos && !isWholeContentSelected) {
151
+ // Do a replaceSelection if the entire panel content isn't selected
152
+ //tr.replaceSelection(transformedSlice).scrollIntoView();
153
+ tr.replaceSelection(new _model.Slice(transformedSlice.content, 0, transformedSlice.openEnd)).scrollIntoView();
154
+ } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
155
+ var parentNode = (0, _utils2.findParentNodeOfType)(panel)(selection);
156
+ if (selectionIsPanel && parentNode && (0, _utils.isNodeEmpty)(parentNode.node)) {
157
+ tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
158
+ // Place the cursor at the the end of the insersertion
159
+ var endPos = tr.selection.from + transformedSlice.size;
160
+ tr.setSelection(new _state.TextSelection(tr.doc.resolve(endPos)));
161
+ } else {
162
+ tr.replaceSelection(transformedSlice).scrollIntoView();
163
+ }
161
164
  } else {
165
+ var _transformedSlice$con2;
166
+ if (pastingIntoExtendedPanel && isWholeContentSelected) {
167
+ // if the entire panel content is selected, doing a replaceSelection removes the panel as well. Hence we do delete followed by safeInsert
168
+ tr.delete(selection.$from.pos, selection.$to.pos);
169
+ }
162
170
  // This maintains both the selection (destination) and the slice (paste content).
163
171
  (0, _utils2.safeInsert)(transformedSlice.content)(tr).scrollIntoView();
164
- //safeInsert doesn't set correct cursor position inside codeBlock or decision
165
- //it moves the cursor to beginning of the node
166
- //we manually shift the cursor to end of the codeblock
167
- var currentPosition = tr.selection.$from;
168
- var currentNode = currentPosition.parent;
169
- if (['codeBlock', 'decisionItem'].includes(currentNode.type.name)) {
170
- var endPosOfNode = currentPosition.end();
171
- var endResolvedPosition = tr.doc.resolve(endPosOfNode);
172
- tr.setSelection(new _state.TextSelection(endResolvedPosition, endResolvedPosition));
172
+ if (((_transformedSlice$con2 = transformedSlice.content.lastChild) === null || _transformedSlice$con2 === void 0 || (_transformedSlice$con2 = _transformedSlice$con2.type) === null || _transformedSlice$con2 === void 0 ? void 0 : _transformedSlice$con2.name) === 'rule') {
173
+ tr.setSelection(_state.TextSelection.near(tr.doc.resolve(tr.selection.$from.pos + transformedSlice.content.size)));
174
+ } else {
175
+ // safeInsert doesn't set correct cursor position
176
+ // it moves the cursor to beginning of the node
177
+ // we manually shift the cursor to end of the node
178
+ var nextPos = tr.doc.resolve(tr.selection.$from.end());
179
+ tr.setSelection(new _state.TextSelection(nextPos));
173
180
  }
174
181
  }
175
182
  }
@@ -115,36 +115,43 @@ export function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChange
115
115
  // and the slice is not a whole node (i.e. openStart is 1 and openEnd is 0)
116
116
  // or the slice's first node is a paragraph,
117
117
  // then we can replace the selection with our slice.
118
- const pastingDecisionIntoExtendedPanel = selectionIsPanel && transformedSlice.content.firstChild.type.name === 'decisionList' && getBooleanFF('platform.editor.allow-extended-panel');
119
- if ((transformedSliceIsValidNode || selectionIsValidNode) && !pastingDecisionIntoExtendedPanel && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
118
+ const pastingIntoExtendedPanel = selectionIsPanel && getBooleanFF('platform.editor.allow-extended-panel') && panel.validContent(transformedSlice.content);
119
+ if ((transformedSliceIsValidNode || selectionIsValidNode) && !pastingIntoExtendedPanel && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
120
120
  // Whole codeblock node has reverse slice depths.
121
121
  transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
122
122
  tr.replaceSelection(transformedSlice).scrollIntoView();
123
- } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
124
- const parentNode = findParentNodeOfType(panel)(selection);
125
- if (selectionIsPanel && parentNode && isNodeEmpty(parentNode.node)) {
126
- tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
127
- // Place the cursor at the the end of the insersertion
128
- const endPos = tr.selection.from + transformedSlice.size;
129
- tr.setSelection(new TextSelection(tr.doc.resolve(endPos)));
130
- } else {
131
- tr.replaceSelection(transformedSlice).scrollIntoView();
132
- }
133
123
  } else {
134
- if (pastingDecisionIntoExtendedPanel && selectionIsValidNode) {
135
- tr.replaceSelection(transformedSlice).scrollIntoView();
124
+ const isWholeContentSelected = selection.$from.pos === selection.$from.start() && selection.$to.end() === selection.$to.pos;
125
+ if (pastingIntoExtendedPanel && selection.$from.pos !== selection.$to.pos && !isWholeContentSelected) {
126
+ // Do a replaceSelection if the entire panel content isn't selected
127
+ //tr.replaceSelection(transformedSlice).scrollIntoView();
128
+ tr.replaceSelection(new Slice(transformedSlice.content, 0, transformedSlice.openEnd)).scrollIntoView();
129
+ } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
130
+ const parentNode = findParentNodeOfType(panel)(selection);
131
+ if (selectionIsPanel && parentNode && isNodeEmpty(parentNode.node)) {
132
+ tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
133
+ // Place the cursor at the the end of the insersertion
134
+ const endPos = tr.selection.from + transformedSlice.size;
135
+ tr.setSelection(new TextSelection(tr.doc.resolve(endPos)));
136
+ } else {
137
+ tr.replaceSelection(transformedSlice).scrollIntoView();
138
+ }
136
139
  } else {
140
+ var _transformedSlice$con2, _transformedSlice$con3;
141
+ if (pastingIntoExtendedPanel && isWholeContentSelected) {
142
+ // if the entire panel content is selected, doing a replaceSelection removes the panel as well. Hence we do delete followed by safeInsert
143
+ tr.delete(selection.$from.pos, selection.$to.pos);
144
+ }
137
145
  // This maintains both the selection (destination) and the slice (paste content).
138
146
  safeInsert(transformedSlice.content)(tr).scrollIntoView();
139
- //safeInsert doesn't set correct cursor position inside codeBlock or decision
140
- //it moves the cursor to beginning of the node
141
- //we manually shift the cursor to end of the codeblock
142
- const currentPosition = tr.selection.$from;
143
- const currentNode = currentPosition.parent;
144
- if (['codeBlock', 'decisionItem'].includes(currentNode.type.name)) {
145
- const endPosOfNode = currentPosition.end();
146
- const endResolvedPosition = tr.doc.resolve(endPosOfNode);
147
- tr.setSelection(new TextSelection(endResolvedPosition, endResolvedPosition));
147
+ if (((_transformedSlice$con2 = transformedSlice.content.lastChild) === null || _transformedSlice$con2 === void 0 ? void 0 : (_transformedSlice$con3 = _transformedSlice$con2.type) === null || _transformedSlice$con3 === void 0 ? void 0 : _transformedSlice$con3.name) === 'rule') {
148
+ tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.$from.pos + transformedSlice.content.size)));
149
+ } else {
150
+ // safeInsert doesn't set correct cursor position
151
+ // it moves the cursor to beginning of the node
152
+ // we manually shift the cursor to end of the node
153
+ const nextPos = tr.doc.resolve(tr.selection.$from.end());
154
+ tr.setSelection(new TextSelection(nextPos));
148
155
  }
149
156
  }
150
157
  }
@@ -118,36 +118,43 @@ export function handlePasteIntoTaskOrDecisionOrPanel(slice, queueCardsFromChange
118
118
  // and the slice is not a whole node (i.e. openStart is 1 and openEnd is 0)
119
119
  // or the slice's first node is a paragraph,
120
120
  // then we can replace the selection with our slice.
121
- var pastingDecisionIntoExtendedPanel = selectionIsPanel && transformedSlice.content.firstChild.type.name === 'decisionList' && getBooleanFF('platform.editor.allow-extended-panel');
122
- if ((transformedSliceIsValidNode || selectionIsValidNode) && !pastingDecisionIntoExtendedPanel && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
121
+ var pastingIntoExtendedPanel = selectionIsPanel && getBooleanFF('platform.editor.allow-extended-panel') && panel.validContent(transformedSlice.content);
122
+ if ((transformedSliceIsValidNode || selectionIsValidNode) && !pastingIntoExtendedPanel && !(transformedSlice.openStart === 1 && transformedSlice.openEnd === 0 ||
123
123
  // Whole codeblock node has reverse slice depths.
124
124
  transformedSlice.openStart === 0 && transformedSlice.openEnd === 1) || ((_transformedSlice$con = transformedSlice.content.firstChild) === null || _transformedSlice$con === void 0 ? void 0 : _transformedSlice$con.type) === paragraph) {
125
125
  tr.replaceSelection(transformedSlice).scrollIntoView();
126
- } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
127
- var parentNode = findParentNodeOfType(panel)(selection);
128
- if (selectionIsPanel && parentNode && isNodeEmpty(parentNode.node)) {
129
- tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
130
- // Place the cursor at the the end of the insersertion
131
- var endPos = tr.selection.from + transformedSlice.size;
132
- tr.setSelection(new TextSelection(tr.doc.resolve(endPos)));
133
- } else {
134
- tr.replaceSelection(transformedSlice).scrollIntoView();
135
- }
136
126
  } else {
137
- if (pastingDecisionIntoExtendedPanel && selectionIsValidNode) {
138
- tr.replaceSelection(transformedSlice).scrollIntoView();
127
+ var isWholeContentSelected = selection.$from.pos === selection.$from.start() && selection.$to.end() === selection.$to.pos;
128
+ if (pastingIntoExtendedPanel && selection.$from.pos !== selection.$to.pos && !isWholeContentSelected) {
129
+ // Do a replaceSelection if the entire panel content isn't selected
130
+ //tr.replaceSelection(transformedSlice).scrollIntoView();
131
+ tr.replaceSelection(new Slice(transformedSlice.content, 0, transformedSlice.openEnd)).scrollIntoView();
132
+ } else if (['mediaSingle'].includes(transformedSlice.content.firstChild.type.name) && selectionIsPanel) {
133
+ var parentNode = findParentNodeOfType(panel)(selection);
134
+ if (selectionIsPanel && parentNode && isNodeEmpty(parentNode.node)) {
135
+ tr.insert(selection.$from.pos, transformedSlice.content).scrollIntoView();
136
+ // Place the cursor at the the end of the insersertion
137
+ var endPos = tr.selection.from + transformedSlice.size;
138
+ tr.setSelection(new TextSelection(tr.doc.resolve(endPos)));
139
+ } else {
140
+ tr.replaceSelection(transformedSlice).scrollIntoView();
141
+ }
139
142
  } else {
143
+ var _transformedSlice$con2;
144
+ if (pastingIntoExtendedPanel && isWholeContentSelected) {
145
+ // if the entire panel content is selected, doing a replaceSelection removes the panel as well. Hence we do delete followed by safeInsert
146
+ tr.delete(selection.$from.pos, selection.$to.pos);
147
+ }
140
148
  // This maintains both the selection (destination) and the slice (paste content).
141
149
  safeInsert(transformedSlice.content)(tr).scrollIntoView();
142
- //safeInsert doesn't set correct cursor position inside codeBlock or decision
143
- //it moves the cursor to beginning of the node
144
- //we manually shift the cursor to end of the codeblock
145
- var currentPosition = tr.selection.$from;
146
- var currentNode = currentPosition.parent;
147
- if (['codeBlock', 'decisionItem'].includes(currentNode.type.name)) {
148
- var endPosOfNode = currentPosition.end();
149
- var endResolvedPosition = tr.doc.resolve(endPosOfNode);
150
- tr.setSelection(new TextSelection(endResolvedPosition, endResolvedPosition));
150
+ if (((_transformedSlice$con2 = transformedSlice.content.lastChild) === null || _transformedSlice$con2 === void 0 || (_transformedSlice$con2 = _transformedSlice$con2.type) === null || _transformedSlice$con2 === void 0 ? void 0 : _transformedSlice$con2.name) === 'rule') {
151
+ tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.$from.pos + transformedSlice.content.size)));
152
+ } else {
153
+ // safeInsert doesn't set correct cursor position
154
+ // it moves the cursor to beginning of the node
155
+ // we manually shift the cursor to end of the node
156
+ var nextPos = tr.doc.resolve(tr.selection.$from.end());
157
+ tr.setSelection(new TextSelection(nextPos));
151
158
  }
152
159
  }
153
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  "@atlaskit/editor-common": "^77.1.0",
37
37
  "@atlaskit/editor-markdown-transformer": "^5.3.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
39
- "@atlaskit/editor-plugin-annotation": "^0.2.0",
39
+ "@atlaskit/editor-plugin-annotation": "^0.3.0",
40
40
  "@atlaskit/editor-plugin-better-type-history": "^0.1.0",
41
41
  "@atlaskit/editor-plugin-card": "^0.16.0",
42
42
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",