@atlaskit/editor-plugin-paste 0.2.16 → 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,11 @@
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
+
3
9
  ## 0.2.16
4
10
 
5
11
  ### Patch Changes
@@ -140,30 +140,37 @@ 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 {
162
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
+ }
163
170
  // This maintains both the selection (destination) and the slice (paste content).
164
171
  (0, _utils2.safeInsert)(transformedSlice.content)(tr).scrollIntoView();
165
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') {
166
- tr.setSelection(_state.TextSelection.near(tr.doc.resolve(selection.$from.pos + transformedSlice.content.size)));
173
+ tr.setSelection(_state.TextSelection.near(tr.doc.resolve(tr.selection.$from.pos + transformedSlice.content.size)));
167
174
  } else {
168
175
  // safeInsert doesn't set correct cursor position
169
176
  // it moves the cursor to beginning of the node
@@ -115,30 +115,37 @@ 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 {
137
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
+ }
138
145
  // This maintains both the selection (destination) and the slice (paste content).
139
146
  safeInsert(transformedSlice.content)(tr).scrollIntoView();
140
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') {
141
- tr.setSelection(TextSelection.near(tr.doc.resolve(selection.$from.pos + transformedSlice.content.size)));
148
+ tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.$from.pos + transformedSlice.content.size)));
142
149
  } else {
143
150
  // safeInsert doesn't set correct cursor position
144
151
  // it moves the cursor to beginning of the node
@@ -118,30 +118,37 @@ 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 {
140
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
+ }
141
148
  // This maintains both the selection (destination) and the slice (paste content).
142
149
  safeInsert(transformedSlice.content)(tr).scrollIntoView();
143
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') {
144
- tr.setSelection(TextSelection.near(tr.doc.resolve(selection.$from.pos + transformedSlice.content.size)));
151
+ tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.$from.pos + transformedSlice.content.size)));
145
152
  } else {
146
153
  // safeInsert doesn't set correct cursor position
147
154
  // it moves the cursor to beginning of the node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "0.2.16",
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",