@atlaskit/editor-plugin-paste 1.12.5 → 1.12.6

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
+ ## 1.12.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`037ce68784704`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/037ce68784704) -
8
+ ED-25123 Update document moved to fire for all cases
9
+ - Updated dependencies
10
+
3
11
  ## 1.12.5
4
12
 
5
13
  ### Patch Changes
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _analytics = require("@atlaskit/editor-common/analytics");
10
8
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
9
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -14,8 +12,6 @@ var _pluginFactory = require("./plugin-factory");
14
12
  var _pluginKey = require("./plugin-key");
15
13
  var _types = require("./types");
16
14
  var _utils = require("./utils");
17
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
15
  // This plugin exists only in FullPage/FullWidth Editor and is used to register an event that tells us
20
16
  // that a user cut and than pasted a node. This order of actions could be considered an alternative
21
17
  // to new Drag and Drop functionality. The event (document moved) is not accurate, but should be enough to be
@@ -44,15 +40,9 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, editor
44
40
  if (!hasCutAction) {
45
41
  return;
46
42
  }
47
- var content = slice.content,
48
- size = slice.size;
43
+ var content = slice.content;
49
44
  var nodeName = (_content$firstChild = content.firstChild) === null || _content$firstChild === void 0 ? void 0 : _content$firstChild.type.name;
50
-
51
- // We should not account for pastes that go inside another node and create nested content as DnD can't do it when nested-dnd is disabled
52
- if ((!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !(0, _utils.isValidNodeName)(contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName, nodeName) || size !== (contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.size) || !(0, _utils.isCursorSelectionAndInsideTopLevelNode)(state.selection)) && (0, _experiments.editorExperiment)('nested-dnd', false)) {
53
- return;
54
- }
55
- if (!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !(0, _utils.isCursorSelectionAtTopLevel)(state.selection) && (0, _experiments.editorExperiment)('nested-dnd', true)) {
45
+ if (!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !(0, _utils.isCursorSelectionAtTopLevel)(state.selection)) {
56
46
  return;
57
47
  }
58
48
  var tr = state.tr;
@@ -61,12 +51,13 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, editor
61
51
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
62
52
  actionSubjectId: _analytics.ACTION_SUBJECT_ID.NODE,
63
53
  eventType: _analytics.EVENT_TYPE.TRACK,
64
- attributes: _objectSpread({
65
- nodeType: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName
66
- }, (0, _experiments.editorExperiment)('nested-dnd', true) && {
54
+ attributes: {
55
+ nodeType: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName,
67
56
  nodeDepth: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeDepth,
68
57
  destinationNodeDepth: (0, _utils.getParentNodeDepth)(state.selection)
69
- })
58
+
59
+ // keep nodeName from copied slice
60
+ }
70
61
  })(tr);
71
62
 
72
63
  // reset to default state
@@ -104,52 +95,23 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, editor
104
95
  resetState = true;
105
96
  }
106
97
  var selection = state.selection;
107
- // DnD can't drag part of text in a paragraph/heading. DnD will select the whole node with all the text inside.
108
- // So we are only interested in cut slices that contain the entire node, not just a part of it.
109
- if (!resetState && nodeName === 'paragraph' && !(0, _utils.isEntireTopLevelHeadingOrParagraphSelected)(selection, nodeName) && (0, _experiments.editorExperiment)('nested-dnd', false)) {
110
- resetState = true;
111
- }
112
- if (!resetState && nodeName === 'heading' && !(0, _utils.isEntireTopLevelHeadingOrParagraphSelected)(selection, nodeName) && (0, _experiments.editorExperiment)('nested-dnd', false)) {
113
- resetState = true;
114
- }
115
- if (!resetState && !(0, _utils.isEntireNestedParagraphOrHeadingSelected)(selection) && (0, _experiments.editorExperiment)('nested-dnd', true)) {
116
- resetState = true;
117
- }
118
-
119
- // DnD can't drag just one paragraph (when blockquote contains multiple paragraphs) or just a part of a paragraph in the blockquote.
120
- // DnD will select and drag the whole blockquote. So we need to register cut events that have the entire blockquote too.
121
- if (!resetState && nodeName === 'blockquote' && !(0, _utils.isEntireTopLevelBlockquoteSelected)(state) && (0, _experiments.editorExperiment)('nested-dnd', false)) {
98
+ if (!resetState && !(0, _utils.isEntireNestedParagraphOrHeadingSelected)(selection)) {
122
99
  resetState = true;
123
100
  }
124
101
  if (!resetState && (0, _utils.isInlineNode)(nodeName) && (0, _utils.isNestedInlineNode)(selection)) {
125
102
  resetState = true;
126
103
  }
127
- if (!resetState && nodeName === 'table' && (0, _utils.isNestedTable)(selection) && (0, _experiments.editorExperiment)('nested-dnd', false)) {
128
- resetState = true;
129
- }
130
- if (!resetState && (0, _utils.isNestedInTable)(state) && (0, _experiments.editorExperiment)('nested-dnd', true) && (0, _experiments.editorExperiment)('table-nested-dnd', false)) {
131
- resetState = true;
132
- }
133
- var isBlockNode = (0, _utils.isBlockNodeWithoutTable)(nodeName);
134
- if (!resetState && (0, _utils.isNodeSelection)(selection) && isBlockNode && selection.$anchor.node().type.name !== 'doc' && (0, _experiments.editorExperiment)('nested-dnd', false) // checks that the block node is not a topLevel node
135
- ) {
136
- resetState = true;
137
- }
138
-
139
- // Some blockNodes can have text inside of them cut, in that case TextSelection occurs, we don't need to track
140
- // these cut events.
141
- if (!resetState && (0, _utils.isTextSelection)(selection) && isBlockNode && (0, _experiments.editorExperiment)('nested-dnd', false)) {
104
+ if (!resetState && (0, _utils.isNestedInTable)(state) && (0, _experiments.editorExperiment)('table-nested-dnd', false)) {
142
105
  resetState = true;
143
106
  }
144
107
  if (resetState) {
145
108
  (0, _commands.resetContentMoved)()(state, dispatch);
146
109
  } else {
147
- (0, _commands.updateContentMoved)(_objectSpread({
110
+ (0, _commands.updateContentMoved)({
148
111
  size: size,
149
- nodeName: nodeName
150
- }, (0, _experiments.editorExperiment)('nested-dnd', true) && {
112
+ nodeName: nodeName,
151
113
  nodeDepth: (0, _utils.getParentNodeDepth)(selection)
152
- }), 'contentCut')(state, dispatch);
114
+ }, 'contentCut')(state, dispatch);
153
115
  }
154
116
  isCutEvent = false;
155
117
  return slice;
@@ -4,9 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isValidNodeName = exports.isTextSelection = exports.isNodeSelection = exports.isNestedTable = exports.isNestedInlineNode = exports.isNestedInTable = exports.isInlineNode = exports.isExcludedNode = exports.isEntireTopLevelHeadingOrParagraphSelected = exports.isEntireTopLevelBlockquoteSelected = exports.isEntireNestedParagraphOrHeadingSelected = exports.isCursorSelectionAtTopLevel = exports.isCursorSelectionAndInsideTopLevelNode = exports.isBlockNodeWithoutTable = exports.getParentNodeDepth = void 0;
7
+ exports.isNestedInlineNode = exports.isNestedInTable = exports.isInlineNode = exports.isExcludedNode = exports.isEntireNestedParagraphOrHeadingSelected = exports.isCursorSelectionAtTopLevel = exports.getParentNodeDepth = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _state = require("@atlaskit/editor-prosemirror/state");
10
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
11
10
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
12
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -14,15 +13,6 @@ var excludedNodes = ['caption', 'layoutColumn', 'listItem', 'tableHeader', 'tabl
14
13
  var isExcludedNode = exports.isExcludedNode = function isExcludedNode(nodeName) {
15
14
  return excludedNodes.includes(nodeName);
16
15
  };
17
- var isCursorSelectionAndInsideTopLevelNode = exports.isCursorSelectionAndInsideTopLevelNode = function isCursorSelectionAndInsideTopLevelNode(selection) {
18
- var $from = selection.$from,
19
- from = selection.from,
20
- to = selection.to;
21
- if (from !== to || $from.depth > 1) {
22
- return false;
23
- }
24
- return true;
25
- };
26
16
  var isCursorSelectionAtTopLevel = exports.isCursorSelectionAtTopLevel = function isCursorSelectionAtTopLevel(selection) {
27
17
  var from = selection.from,
28
18
  to = selection.to,
@@ -56,15 +46,6 @@ var isNestedInlineNode = exports.isNestedInlineNode = function isNestedInlineNod
56
46
  }
57
47
  return true;
58
48
  };
59
- var blockNodes = ['bodiedExtension', 'blockCard', 'codeBlock', 'embedCard', 'expand', 'extension', 'layoutSection', 'mediaGroup', 'mediaSingle', 'panel', 'rule'];
60
- var isBlockNodeWithoutTable = exports.isBlockNodeWithoutTable = function isBlockNodeWithoutTable(nodeName) {
61
- return blockNodes.includes(nodeName);
62
- };
63
- var parentNodes = ['expand', 'extension', 'bodiedExtension', 'layoutSection'];
64
- var isNestedTable = exports.isNestedTable = function isNestedTable(selection) {
65
- var parentNode = selection.$anchor.node(1);
66
- return parentNode && parentNodes.includes(parentNode.type.name);
67
- };
68
49
  var isNestedInTable = exports.isNestedInTable = function isNestedInTable(state) {
69
50
  var schema = state.schema,
70
51
  selection = state.selection;
@@ -87,72 +68,6 @@ var getParentNodeDepth = exports.getParentNodeDepth = function getParentNodeDept
87
68
  }
88
69
  return parentNode.node.type.name === 'heading' || parentNode.node.type.name === 'paragraph' ? parentNode.depth - 1 : parentNode.depth;
89
70
  };
90
- var getPastedNameOfInlineNode = function getPastedNameOfInlineNode(nodeName) {
91
- if (inlineNodes.includes(nodeName)) {
92
- return 'paragraph';
93
- }
94
- return nodeName;
95
- };
96
- var isValidNodeName = exports.isValidNodeName = function isValidNodeName(copiedNodeName, pastedNodeName) {
97
- if (copiedNodeName === pastedNodeName) {
98
- return true;
99
- }
100
- if (getPastedNameOfInlineNode(copiedNodeName) === pastedNodeName) {
101
- return true;
102
- }
103
- return false;
104
- };
105
- var isTextSelection = exports.isTextSelection = function isTextSelection(selection) {
106
- return selection instanceof _state.TextSelection && selection.from !== selection.to;
107
- };
108
- var isNodeSelection = exports.isNodeSelection = function isNodeSelection(selection) {
109
- return selection instanceof _state.NodeSelection;
110
- };
111
- var isEntireHeadingOrParagraphSelected = function isEntireHeadingOrParagraphSelected(selection, nodeName) {
112
- if (!isTextSelection(selection)) {
113
- return false;
114
- }
115
- var $from = selection.$from,
116
- $to = selection.$to;
117
- if (!($from.parent.type.name === nodeName)) {
118
- return false;
119
- }
120
- if ($from.parent === $to.parent) {
121
- var node = $from.parent;
122
- return $from.parentOffset === 0 && $to.parentOffset === node.content.size;
123
- }
124
- };
125
- var isEntireTopLevelHeadingOrParagraphSelected = exports.isEntireTopLevelHeadingOrParagraphSelected = function isEntireTopLevelHeadingOrParagraphSelected(selection, nodeName) {
126
- if (selection.$from.depth !== 1) {
127
- return false;
128
- }
129
- return isEntireHeadingOrParagraphSelected(selection, nodeName);
130
- };
131
- var isEntireTopLevelBlockquoteSelected = exports.isEntireTopLevelBlockquoteSelected = function isEntireTopLevelBlockquoteSelected(state) {
132
- var schema = state.schema,
133
- selection = state.selection;
134
- var blockquote = schema.nodes.blockquote;
135
- var blockquoteNode = (0, _utils.findParentNodeOfTypeClosestToPos)(selection.$from, blockquote);
136
- if (!blockquoteNode) {
137
- return false;
138
- }
139
-
140
- // checks if it is a top level blockquote
141
- var depth = blockquoteNode.depth;
142
- if (depth !== 1) {
143
- return false;
144
- }
145
- var from = selection.from,
146
- to = selection.to;
147
- var selectedNodesCount = 0;
148
- state.doc.nodesBetween(from, to, function (node, pos) {
149
- if (pos >= from && pos + node.nodeSize <= to) {
150
- selectedNodesCount++;
151
- return false;
152
- }
153
- });
154
- return selectedNodesCount === blockquoteNode.node.childCount;
155
- };
156
71
  var isEntireNestedParagraphOrHeadingSelected = exports.isEntireNestedParagraphOrHeadingSelected = function isEntireNestedParagraphOrHeadingSelected(selection) {
157
72
  var $from = selection.$from,
158
73
  $to = selection.$to;
@@ -5,7 +5,7 @@ import { resetContentMoved, resetContentMovedTransform, updateContentMoved } fro
5
5
  import { createPluginState, getPluginState } from './plugin-factory';
6
6
  import { pluginKey } from './plugin-key';
7
7
  import { defaultState } from './types';
8
- import { getParentNodeDepth, isBlockNodeWithoutTable, isCursorSelectionAndInsideTopLevelNode, isCursorSelectionAtTopLevel, isEntireNestedParagraphOrHeadingSelected, isEntireTopLevelBlockquoteSelected, isEntireTopLevelHeadingOrParagraphSelected, isExcludedNode, isInlineNode, isNestedInlineNode, isNestedInTable, isNestedTable, isNodeSelection, isTextSelection, isValidNodeName } from './utils';
8
+ import { getParentNodeDepth, isCursorSelectionAtTopLevel, isEntireNestedParagraphOrHeadingSelected, isExcludedNode, isInlineNode, isNestedInlineNode, isNestedInTable } from './utils';
9
9
 
10
10
  // This plugin exists only in FullPage/FullWidth Editor and is used to register an event that tells us
11
11
  // that a user cut and than pasted a node. This order of actions could be considered an alternative
@@ -38,16 +38,10 @@ export const createPlugin = (dispatch, editorAnalyticsAPI) => {
38
38
  return;
39
39
  }
40
40
  const {
41
- content,
42
- size
41
+ content
43
42
  } = slice;
44
43
  const nodeName = (_content$firstChild = content.firstChild) === null || _content$firstChild === void 0 ? void 0 : _content$firstChild.type.name;
45
-
46
- // We should not account for pastes that go inside another node and create nested content as DnD can't do it when nested-dnd is disabled
47
- if ((!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !isValidNodeName(contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName, nodeName) || size !== (contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.size) || !isCursorSelectionAndInsideTopLevelNode(state.selection)) && editorExperiment('nested-dnd', false)) {
48
- return;
49
- }
50
- if (!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !isCursorSelectionAtTopLevel(state.selection) && editorExperiment('nested-dnd', true)) {
44
+ if (!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !isCursorSelectionAtTopLevel(state.selection)) {
51
45
  return;
52
46
  }
53
47
  const {
@@ -60,10 +54,9 @@ export const createPlugin = (dispatch, editorAnalyticsAPI) => {
60
54
  eventType: EVENT_TYPE.TRACK,
61
55
  attributes: {
62
56
  nodeType: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName,
63
- ...(editorExperiment('nested-dnd', true) && {
64
- nodeDepth: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeDepth,
65
- destinationNodeDepth: getParentNodeDepth(state.selection)
66
- })
57
+ nodeDepth: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeDepth,
58
+ destinationNodeDepth: getParentNodeDepth(state.selection)
59
+
67
60
  // keep nodeName from copied slice
68
61
  }
69
62
  })(tr);
@@ -108,41 +101,13 @@ export const createPlugin = (dispatch, editorAnalyticsAPI) => {
108
101
  const {
109
102
  selection
110
103
  } = state;
111
- // DnD can't drag part of text in a paragraph/heading. DnD will select the whole node with all the text inside.
112
- // So we are only interested in cut slices that contain the entire node, not just a part of it.
113
- if (!resetState && nodeName === 'paragraph' && !isEntireTopLevelHeadingOrParagraphSelected(selection, nodeName) && editorExperiment('nested-dnd', false)) {
114
- resetState = true;
115
- }
116
- if (!resetState && nodeName === 'heading' && !isEntireTopLevelHeadingOrParagraphSelected(selection, nodeName) && editorExperiment('nested-dnd', false)) {
117
- resetState = true;
118
- }
119
- if (!resetState && !isEntireNestedParagraphOrHeadingSelected(selection) && editorExperiment('nested-dnd', true)) {
120
- resetState = true;
121
- }
122
-
123
- // DnD can't drag just one paragraph (when blockquote contains multiple paragraphs) or just a part of a paragraph in the blockquote.
124
- // DnD will select and drag the whole blockquote. So we need to register cut events that have the entire blockquote too.
125
- if (!resetState && nodeName === 'blockquote' && !isEntireTopLevelBlockquoteSelected(state) && editorExperiment('nested-dnd', false)) {
104
+ if (!resetState && !isEntireNestedParagraphOrHeadingSelected(selection)) {
126
105
  resetState = true;
127
106
  }
128
107
  if (!resetState && isInlineNode(nodeName) && isNestedInlineNode(selection)) {
129
108
  resetState = true;
130
109
  }
131
- if (!resetState && nodeName === 'table' && isNestedTable(selection) && editorExperiment('nested-dnd', false)) {
132
- resetState = true;
133
- }
134
- if (!resetState && isNestedInTable(state) && editorExperiment('nested-dnd', true) && editorExperiment('table-nested-dnd', false)) {
135
- resetState = true;
136
- }
137
- const isBlockNode = isBlockNodeWithoutTable(nodeName);
138
- if (!resetState && isNodeSelection(selection) && isBlockNode && selection.$anchor.node().type.name !== 'doc' && editorExperiment('nested-dnd', false) // checks that the block node is not a topLevel node
139
- ) {
140
- resetState = true;
141
- }
142
-
143
- // Some blockNodes can have text inside of them cut, in that case TextSelection occurs, we don't need to track
144
- // these cut events.
145
- if (!resetState && isTextSelection(selection) && isBlockNode && editorExperiment('nested-dnd', false)) {
110
+ if (!resetState && isNestedInTable(state) && editorExperiment('table-nested-dnd', false)) {
146
111
  resetState = true;
147
112
  }
148
113
  if (resetState) {
@@ -151,9 +116,7 @@ export const createPlugin = (dispatch, editorAnalyticsAPI) => {
151
116
  updateContentMoved({
152
117
  size: size,
153
118
  nodeName: nodeName,
154
- ...(editorExperiment('nested-dnd', true) && {
155
- nodeDepth: getParentNodeDepth(selection)
156
- })
119
+ nodeDepth: getParentNodeDepth(selection)
157
120
  }, 'contentCut')(state, dispatch);
158
121
  }
159
122
  isCutEvent = false;
@@ -1,20 +1,8 @@
1
- import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
1
  import { findParentNodeClosestToPos, findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
3
2
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
4
  const excludedNodes = ['caption', 'layoutColumn', 'listItem', 'tableHeader', 'tableCell', 'tableRow', 'text', 'placeholder', 'unsupportedBlock', 'unsupportedInline', 'hardBreak', 'confluenceUnsupportedBlock', 'confluenceUnsupportedInline', 'taskItem', 'decisionItem', ...(editorExperiment('nested-dnd', false) ? ['bulletList', 'orderedList', 'taskList', 'decisionList', 'nestedExpand', 'media'] : [])];
6
5
  export const isExcludedNode = nodeName => excludedNodes.includes(nodeName);
7
- export const isCursorSelectionAndInsideTopLevelNode = selection => {
8
- const {
9
- $from,
10
- from,
11
- to
12
- } = selection;
13
- if (from !== to || $from.depth > 1) {
14
- return false;
15
- }
16
- return true;
17
- };
18
6
  export const isCursorSelectionAtTopLevel = selection => {
19
7
  const {
20
8
  from,
@@ -50,15 +38,6 @@ export const isNestedInlineNode = selection => {
50
38
  }
51
39
  return true;
52
40
  };
53
- const blockNodes = ['bodiedExtension', 'blockCard', 'codeBlock', 'embedCard', 'expand', 'extension', 'layoutSection', 'mediaGroup', 'mediaSingle', 'panel', 'rule'];
54
- export const isBlockNodeWithoutTable = nodeName => {
55
- return blockNodes.includes(nodeName);
56
- };
57
- const parentNodes = ['expand', 'extension', 'bodiedExtension', 'layoutSection'];
58
- export const isNestedTable = selection => {
59
- const parentNode = selection.$anchor.node(1);
60
- return parentNode && parentNodes.includes(parentNode.type.name);
61
- };
62
41
  export const isNestedInTable = state => {
63
42
  const {
64
43
  schema,
@@ -83,82 +62,6 @@ export const getParentNodeDepth = selection => {
83
62
  }
84
63
  return parentNode.node.type.name === 'heading' || parentNode.node.type.name === 'paragraph' ? parentNode.depth - 1 : parentNode.depth;
85
64
  };
86
- const getPastedNameOfInlineNode = nodeName => {
87
- if (inlineNodes.includes(nodeName)) {
88
- return 'paragraph';
89
- }
90
- return nodeName;
91
- };
92
- export const isValidNodeName = (copiedNodeName, pastedNodeName) => {
93
- if (copiedNodeName === pastedNodeName) {
94
- return true;
95
- }
96
- if (getPastedNameOfInlineNode(copiedNodeName) === pastedNodeName) {
97
- return true;
98
- }
99
- return false;
100
- };
101
- export const isTextSelection = selection => {
102
- return selection instanceof TextSelection && selection.from !== selection.to;
103
- };
104
- export const isNodeSelection = selection => {
105
- return selection instanceof NodeSelection;
106
- };
107
- const isEntireHeadingOrParagraphSelected = (selection, nodeName) => {
108
- if (!isTextSelection(selection)) {
109
- return false;
110
- }
111
- const {
112
- $from,
113
- $to
114
- } = selection;
115
- if (!($from.parent.type.name === nodeName)) {
116
- return false;
117
- }
118
- if ($from.parent === $to.parent) {
119
- const node = $from.parent;
120
- return $from.parentOffset === 0 && $to.parentOffset === node.content.size;
121
- }
122
- };
123
- export const isEntireTopLevelHeadingOrParagraphSelected = (selection, nodeName) => {
124
- if (selection.$from.depth !== 1) {
125
- return false;
126
- }
127
- return isEntireHeadingOrParagraphSelected(selection, nodeName);
128
- };
129
- export const isEntireTopLevelBlockquoteSelected = state => {
130
- const {
131
- schema,
132
- selection
133
- } = state;
134
- const {
135
- blockquote
136
- } = schema.nodes;
137
- const blockquoteNode = findParentNodeOfTypeClosestToPos(selection.$from, blockquote);
138
- if (!blockquoteNode) {
139
- return false;
140
- }
141
-
142
- // checks if it is a top level blockquote
143
- const {
144
- depth
145
- } = blockquoteNode;
146
- if (depth !== 1) {
147
- return false;
148
- }
149
- const {
150
- from,
151
- to
152
- } = selection;
153
- let selectedNodesCount = 0;
154
- state.doc.nodesBetween(from, to, (node, pos) => {
155
- if (pos >= from && pos + node.nodeSize <= to) {
156
- selectedNodesCount++;
157
- return false;
158
- }
159
- });
160
- return selectedNodesCount === blockquoteNode.node.childCount;
161
- };
162
65
  export const isEntireNestedParagraphOrHeadingSelected = selection => {
163
66
  const {
164
67
  $from,
@@ -1,6 +1,3 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -8,7 +5,7 @@ import { resetContentMoved, resetContentMovedTransform, updateContentMoved } fro
8
5
  import { createPluginState, getPluginState } from './plugin-factory';
9
6
  import { pluginKey } from './plugin-key';
10
7
  import { defaultState } from './types';
11
- import { getParentNodeDepth, isBlockNodeWithoutTable, isCursorSelectionAndInsideTopLevelNode, isCursorSelectionAtTopLevel, isEntireNestedParagraphOrHeadingSelected, isEntireTopLevelBlockquoteSelected, isEntireTopLevelHeadingOrParagraphSelected, isExcludedNode, isInlineNode, isNestedInlineNode, isNestedInTable, isNestedTable, isNodeSelection, isTextSelection, isValidNodeName } from './utils';
8
+ import { getParentNodeDepth, isCursorSelectionAtTopLevel, isEntireNestedParagraphOrHeadingSelected, isExcludedNode, isInlineNode, isNestedInlineNode, isNestedInTable } from './utils';
12
9
 
13
10
  // This plugin exists only in FullPage/FullWidth Editor and is used to register an event that tells us
14
11
  // that a user cut and than pasted a node. This order of actions could be considered an alternative
@@ -38,15 +35,9 @@ export var createPlugin = function createPlugin(dispatch, editorAnalyticsAPI) {
38
35
  if (!hasCutAction) {
39
36
  return;
40
37
  }
41
- var content = slice.content,
42
- size = slice.size;
38
+ var content = slice.content;
43
39
  var nodeName = (_content$firstChild = content.firstChild) === null || _content$firstChild === void 0 ? void 0 : _content$firstChild.type.name;
44
-
45
- // We should not account for pastes that go inside another node and create nested content as DnD can't do it when nested-dnd is disabled
46
- if ((!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !isValidNodeName(contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName, nodeName) || size !== (contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.size) || !isCursorSelectionAndInsideTopLevelNode(state.selection)) && editorExperiment('nested-dnd', false)) {
47
- return;
48
- }
49
- if (!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !isCursorSelectionAtTopLevel(state.selection) && editorExperiment('nested-dnd', true)) {
40
+ if (!nodeName || !(contentMoved !== null && contentMoved !== void 0 && contentMoved.nodeName) || !isCursorSelectionAtTopLevel(state.selection)) {
50
41
  return;
51
42
  }
52
43
  var tr = state.tr;
@@ -55,12 +46,13 @@ export var createPlugin = function createPlugin(dispatch, editorAnalyticsAPI) {
55
46
  actionSubject: ACTION_SUBJECT.DOCUMENT,
56
47
  actionSubjectId: ACTION_SUBJECT_ID.NODE,
57
48
  eventType: EVENT_TYPE.TRACK,
58
- attributes: _objectSpread({
59
- nodeType: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName
60
- }, editorExperiment('nested-dnd', true) && {
49
+ attributes: {
50
+ nodeType: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeName,
61
51
  nodeDepth: contentMoved === null || contentMoved === void 0 ? void 0 : contentMoved.nodeDepth,
62
52
  destinationNodeDepth: getParentNodeDepth(state.selection)
63
- })
53
+
54
+ // keep nodeName from copied slice
55
+ }
64
56
  })(tr);
65
57
 
66
58
  // reset to default state
@@ -98,52 +90,23 @@ export var createPlugin = function createPlugin(dispatch, editorAnalyticsAPI) {
98
90
  resetState = true;
99
91
  }
100
92
  var selection = state.selection;
101
- // DnD can't drag part of text in a paragraph/heading. DnD will select the whole node with all the text inside.
102
- // So we are only interested in cut slices that contain the entire node, not just a part of it.
103
- if (!resetState && nodeName === 'paragraph' && !isEntireTopLevelHeadingOrParagraphSelected(selection, nodeName) && editorExperiment('nested-dnd', false)) {
104
- resetState = true;
105
- }
106
- if (!resetState && nodeName === 'heading' && !isEntireTopLevelHeadingOrParagraphSelected(selection, nodeName) && editorExperiment('nested-dnd', false)) {
107
- resetState = true;
108
- }
109
- if (!resetState && !isEntireNestedParagraphOrHeadingSelected(selection) && editorExperiment('nested-dnd', true)) {
110
- resetState = true;
111
- }
112
-
113
- // DnD can't drag just one paragraph (when blockquote contains multiple paragraphs) or just a part of a paragraph in the blockquote.
114
- // DnD will select and drag the whole blockquote. So we need to register cut events that have the entire blockquote too.
115
- if (!resetState && nodeName === 'blockquote' && !isEntireTopLevelBlockquoteSelected(state) && editorExperiment('nested-dnd', false)) {
93
+ if (!resetState && !isEntireNestedParagraphOrHeadingSelected(selection)) {
116
94
  resetState = true;
117
95
  }
118
96
  if (!resetState && isInlineNode(nodeName) && isNestedInlineNode(selection)) {
119
97
  resetState = true;
120
98
  }
121
- if (!resetState && nodeName === 'table' && isNestedTable(selection) && editorExperiment('nested-dnd', false)) {
122
- resetState = true;
123
- }
124
- if (!resetState && isNestedInTable(state) && editorExperiment('nested-dnd', true) && editorExperiment('table-nested-dnd', false)) {
125
- resetState = true;
126
- }
127
- var isBlockNode = isBlockNodeWithoutTable(nodeName);
128
- if (!resetState && isNodeSelection(selection) && isBlockNode && selection.$anchor.node().type.name !== 'doc' && editorExperiment('nested-dnd', false) // checks that the block node is not a topLevel node
129
- ) {
130
- resetState = true;
131
- }
132
-
133
- // Some blockNodes can have text inside of them cut, in that case TextSelection occurs, we don't need to track
134
- // these cut events.
135
- if (!resetState && isTextSelection(selection) && isBlockNode && editorExperiment('nested-dnd', false)) {
99
+ if (!resetState && isNestedInTable(state) && editorExperiment('table-nested-dnd', false)) {
136
100
  resetState = true;
137
101
  }
138
102
  if (resetState) {
139
103
  resetContentMoved()(state, dispatch);
140
104
  } else {
141
- updateContentMoved(_objectSpread({
105
+ updateContentMoved({
142
106
  size: size,
143
- nodeName: nodeName
144
- }, editorExperiment('nested-dnd', true) && {
107
+ nodeName: nodeName,
145
108
  nodeDepth: getParentNodeDepth(selection)
146
- }), 'contentCut')(state, dispatch);
109
+ }, 'contentCut')(state, dispatch);
147
110
  }
148
111
  isCutEvent = false;
149
112
  return slice;
@@ -1,5 +1,4 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
2
  import { findParentNodeClosestToPos, findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
4
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -7,15 +6,6 @@ var excludedNodes = ['caption', 'layoutColumn', 'listItem', 'tableHeader', 'tabl
7
6
  export var isExcludedNode = function isExcludedNode(nodeName) {
8
7
  return excludedNodes.includes(nodeName);
9
8
  };
10
- export var isCursorSelectionAndInsideTopLevelNode = function isCursorSelectionAndInsideTopLevelNode(selection) {
11
- var $from = selection.$from,
12
- from = selection.from,
13
- to = selection.to;
14
- if (from !== to || $from.depth > 1) {
15
- return false;
16
- }
17
- return true;
18
- };
19
9
  export var isCursorSelectionAtTopLevel = function isCursorSelectionAtTopLevel(selection) {
20
10
  var from = selection.from,
21
11
  to = selection.to,
@@ -49,15 +39,6 @@ export var isNestedInlineNode = function isNestedInlineNode(selection) {
49
39
  }
50
40
  return true;
51
41
  };
52
- var blockNodes = ['bodiedExtension', 'blockCard', 'codeBlock', 'embedCard', 'expand', 'extension', 'layoutSection', 'mediaGroup', 'mediaSingle', 'panel', 'rule'];
53
- export var isBlockNodeWithoutTable = function isBlockNodeWithoutTable(nodeName) {
54
- return blockNodes.includes(nodeName);
55
- };
56
- var parentNodes = ['expand', 'extension', 'bodiedExtension', 'layoutSection'];
57
- export var isNestedTable = function isNestedTable(selection) {
58
- var parentNode = selection.$anchor.node(1);
59
- return parentNode && parentNodes.includes(parentNode.type.name);
60
- };
61
42
  export var isNestedInTable = function isNestedInTable(state) {
62
43
  var schema = state.schema,
63
44
  selection = state.selection;
@@ -80,72 +61,6 @@ export var getParentNodeDepth = function getParentNodeDepth(selection) {
80
61
  }
81
62
  return parentNode.node.type.name === 'heading' || parentNode.node.type.name === 'paragraph' ? parentNode.depth - 1 : parentNode.depth;
82
63
  };
83
- var getPastedNameOfInlineNode = function getPastedNameOfInlineNode(nodeName) {
84
- if (inlineNodes.includes(nodeName)) {
85
- return 'paragraph';
86
- }
87
- return nodeName;
88
- };
89
- export var isValidNodeName = function isValidNodeName(copiedNodeName, pastedNodeName) {
90
- if (copiedNodeName === pastedNodeName) {
91
- return true;
92
- }
93
- if (getPastedNameOfInlineNode(copiedNodeName) === pastedNodeName) {
94
- return true;
95
- }
96
- return false;
97
- };
98
- export var isTextSelection = function isTextSelection(selection) {
99
- return selection instanceof TextSelection && selection.from !== selection.to;
100
- };
101
- export var isNodeSelection = function isNodeSelection(selection) {
102
- return selection instanceof NodeSelection;
103
- };
104
- var isEntireHeadingOrParagraphSelected = function isEntireHeadingOrParagraphSelected(selection, nodeName) {
105
- if (!isTextSelection(selection)) {
106
- return false;
107
- }
108
- var $from = selection.$from,
109
- $to = selection.$to;
110
- if (!($from.parent.type.name === nodeName)) {
111
- return false;
112
- }
113
- if ($from.parent === $to.parent) {
114
- var node = $from.parent;
115
- return $from.parentOffset === 0 && $to.parentOffset === node.content.size;
116
- }
117
- };
118
- export var isEntireTopLevelHeadingOrParagraphSelected = function isEntireTopLevelHeadingOrParagraphSelected(selection, nodeName) {
119
- if (selection.$from.depth !== 1) {
120
- return false;
121
- }
122
- return isEntireHeadingOrParagraphSelected(selection, nodeName);
123
- };
124
- export var isEntireTopLevelBlockquoteSelected = function isEntireTopLevelBlockquoteSelected(state) {
125
- var schema = state.schema,
126
- selection = state.selection;
127
- var blockquote = schema.nodes.blockquote;
128
- var blockquoteNode = findParentNodeOfTypeClosestToPos(selection.$from, blockquote);
129
- if (!blockquoteNode) {
130
- return false;
131
- }
132
-
133
- // checks if it is a top level blockquote
134
- var depth = blockquoteNode.depth;
135
- if (depth !== 1) {
136
- return false;
137
- }
138
- var from = selection.from,
139
- to = selection.to;
140
- var selectedNodesCount = 0;
141
- state.doc.nodesBetween(from, to, function (node, pos) {
142
- if (pos >= from && pos + node.nodeSize <= to) {
143
- selectedNodesCount++;
144
- return false;
145
- }
146
- });
147
- return selectedNodesCount === blockquoteNode.node.childCount;
148
- };
149
64
  export var isEntireNestedParagraphOrHeadingSelected = function isEntireNestedParagraphOrHeadingSelected(selection) {
150
65
  var $from = selection.$from,
151
66
  $to = selection.$to;
@@ -1,16 +1,8 @@
1
1
  import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const isExcludedNode: (nodeName: string) => boolean;
3
- export declare const isCursorSelectionAndInsideTopLevelNode: (selection: Selection) => boolean;
4
3
  export declare const isCursorSelectionAtTopLevel: (selection: Selection) => boolean;
5
4
  export declare const isInlineNode: (nodeName: string) => boolean;
6
5
  export declare const isNestedInlineNode: (selection: Selection) => boolean;
7
- export declare const isBlockNodeWithoutTable: (nodeName: string) => boolean;
8
- export declare const isNestedTable: (selection: Selection) => boolean;
9
6
  export declare const isNestedInTable: (state: EditorState) => boolean;
10
7
  export declare const getParentNodeDepth: (selection: Selection) => number;
11
- export declare const isValidNodeName: (copiedNodeName: string, pastedNodeName: string) => boolean;
12
- export declare const isTextSelection: (selection: Selection) => boolean;
13
- export declare const isNodeSelection: (selection: Selection) => boolean;
14
- export declare const isEntireTopLevelHeadingOrParagraphSelected: (selection: Selection, nodeName: 'paragraph' | 'heading') => boolean | undefined;
15
- export declare const isEntireTopLevelBlockquoteSelected: (state: EditorState) => boolean;
16
8
  export declare const isEntireNestedParagraphOrHeadingSelected: (selection: Selection) => boolean;
@@ -1,16 +1,8 @@
1
1
  import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const isExcludedNode: (nodeName: string) => boolean;
3
- export declare const isCursorSelectionAndInsideTopLevelNode: (selection: Selection) => boolean;
4
3
  export declare const isCursorSelectionAtTopLevel: (selection: Selection) => boolean;
5
4
  export declare const isInlineNode: (nodeName: string) => boolean;
6
5
  export declare const isNestedInlineNode: (selection: Selection) => boolean;
7
- export declare const isBlockNodeWithoutTable: (nodeName: string) => boolean;
8
- export declare const isNestedTable: (selection: Selection) => boolean;
9
6
  export declare const isNestedInTable: (state: EditorState) => boolean;
10
7
  export declare const getParentNodeDepth: (selection: Selection) => number;
11
- export declare const isValidNodeName: (copiedNodeName: string, pastedNodeName: string) => boolean;
12
- export declare const isTextSelection: (selection: Selection) => boolean;
13
- export declare const isNodeSelection: (selection: Selection) => boolean;
14
- export declare const isEntireTopLevelHeadingOrParagraphSelected: (selection: Selection, nodeName: 'paragraph' | 'heading') => boolean | undefined;
15
- export declare const isEntireTopLevelBlockquoteSelected: (state: EditorState) => boolean;
16
8
  export declare const isEntireNestedParagraphOrHeadingSelected: (selection: Selection) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste",
3
- "version": "1.12.5",
3
+ "version": "1.12.6",
4
4
  "description": "Paste plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,20 +31,20 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^91.0.0",
34
+ "@atlaskit/editor-common": "^91.1.0",
35
35
  "@atlaskit/editor-markdown-transformer": "^5.12.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
37
37
  "@atlaskit/editor-plugin-annotation": "^1.19.0",
38
38
  "@atlaskit/editor-plugin-better-type-history": "^1.8.0",
39
- "@atlaskit/editor-plugin-card": "^3.0.0",
39
+ "@atlaskit/editor-plugin-card": "^3.2.0",
40
40
  "@atlaskit/editor-plugin-feature-flags": "^1.2.0",
41
41
  "@atlaskit/editor-plugin-list": "^3.8.0",
42
- "@atlaskit/editor-plugin-media": "^1.32.0",
42
+ "@atlaskit/editor-plugin-media": "^1.33.0",
43
43
  "@atlaskit/editor-plugin-mentions": "^2.6.0",
44
44
  "@atlaskit/editor-prosemirror": "6.0.0",
45
45
  "@atlaskit/editor-tables": "^2.8.0",
46
46
  "@atlaskit/media-client": "^28.0.0",
47
- "@atlaskit/media-common": "^11.4.0",
47
+ "@atlaskit/media-common": "^11.5.0",
48
48
  "@atlaskit/platform-feature-flags": "^0.3.0",
49
49
  "@atlaskit/tmp-editor-statsig": "*",
50
50
  "@babel/runtime": "^7.0.0",