@atlaskit/editor-plugin-paste-options-toolbar 9.1.2 → 9.1.4

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,23 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 9.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`cdacbdec78ed6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cdacbdec78ed6) -
8
+ [EDITOR-5980] Fix sticky menu stopping before table when paste selection ends inside cell
9
+ - [`70e3625a8ae3f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/70e3625a8ae3f) -
10
+ [EDITOR-5880] updated prop name for consistency and used view.dom for stable editor reference
11
+ - Updated dependencies
12
+
13
+ ## 9.1.3
14
+
15
+ ### Patch Changes
16
+
17
+ - [`0fe3de6aa5e9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0fe3de6aa5e9c) -
18
+ [ux] EDITOR-5978 Add additional buttons and update thresholds for Editor AI paste actions. Only
19
+ show existing paste actions if pasting greater than 100 characters.
20
+
3
21
  ## 9.1.2
4
22
 
5
23
  ### Patch Changes
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.PasteActionsMenu = void 0;
9
+ exports.getVisualEndBottom = getVisualEndBottom;
9
10
  exports.onPositionCalculated = onPositionCalculated;
11
+ exports.resolveTableAfterPos = resolveTableAfterPos;
10
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
13
  var _react = _interopRequireWildcard(require("react"));
12
14
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -39,6 +41,34 @@ function getTargetElement(editorView, pos) {
39
41
  }
40
42
  }
41
43
 
44
+ /**
45
+ * Returns the position immediately after a table ancestor of `pos`, or
46
+ * `undefined` if not inside a table. Safe to cache per document version.
47
+ */
48
+ function resolveTableAfterPos(editorView, pos) {
49
+ var $pos = editorView.state.doc.resolve(pos);
50
+ for (var depth = $pos.depth; depth > 0; depth--) {
51
+ if ($pos.node(depth).type.name === 'table') {
52
+ return $pos.after(depth);
53
+ }
54
+ }
55
+ return undefined;
56
+ }
57
+
58
+ /**
59
+ * Returns the visual bottom of the pasted content. For positions inside a
60
+ * table, uses the pre-computed `tableAfterPos` to get the correct bottom edge.
61
+ */
62
+ function getVisualEndBottom(editorView, pasteEndPos, tableAfterPos) {
63
+ var endCoords = editorView.coordsAtPos(pasteEndPos);
64
+ var bottom = endCoords.bottom;
65
+ if (tableAfterPos !== undefined) {
66
+ var afterCoords = editorView.coordsAtPos(tableAfterPos);
67
+ bottom = Math.max(bottom, afterCoords.bottom);
68
+ }
69
+ return bottom;
70
+ }
71
+
42
72
  /**
43
73
  * Adjusts the vertical position of the paste menu to align with the top of the
44
74
  * pasted content using the exact coordinates at the paste start position,
@@ -56,10 +86,12 @@ function getTargetElement(editorView, pos) {
56
86
  * above the visible area.
57
87
  */
58
88
  function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElement, scrollableElement) {
89
+ // Pre-compute once per render to avoid doc.resolve() on every scroll frame.
90
+ var tableAfterPos = resolveTableAfterPos(editorView, pasteEndPos);
59
91
  return function (position) {
60
92
  var _position$top;
61
93
  var startCoords = editorView.coordsAtPos(pasteStartPos);
62
- var endCoords = editorView.coordsAtPos(pasteEndPos);
94
+ var endBottom = getVisualEndBottom(editorView, pasteEndPos, tableAfterPos);
63
95
  var targetRect = targetElement.getBoundingClientRect();
64
96
 
65
97
  // The Popup places the menu at the target's bottom edge by default.
@@ -73,7 +105,7 @@ function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElem
73
105
  // content is still visible.
74
106
  if (scrollableElement) {
75
107
  var scrollContainerTop = scrollableElement.getBoundingClientRect().top;
76
- if (startCoords.top < scrollContainerTop && endCoords.bottom > scrollContainerTop) {
108
+ if (startCoords.top < scrollContainerTop && endBottom > scrollContainerTop) {
77
109
  adjustedTop += scrollContainerTop - startCoords.top + _constants.PASTE_MENU_GAP_TOP;
78
110
  }
79
111
  }
@@ -99,6 +131,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
99
131
  lastContentPasted = _useSharedPluginState.lastContentPasted;
100
132
  var prevShowToolbarRef = (0, _react.useRef)(false);
101
133
  (0, _react.useEffect)(function () {
134
+ var _lastContentPasted$te, _lastContentPasted$te2;
102
135
  if (!lastContentPasted) {
103
136
  (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
104
137
  return;
@@ -116,7 +149,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
116
149
  for (var depth = $pos.depth; depth > 0; depth--) {
117
150
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
118
151
  }
119
- var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted);
152
+ var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
120
153
  (0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
121
154
  }, [lastContentPasted, editorView]);
122
155
  var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
@@ -176,8 +209,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
176
209
  // so the Popup attaches its built-in scroll listener, which calls
177
210
  // scheduledUpdatePosition (RAF-throttled) on each scroll event — triggering
178
211
  // onPositionCalculated with fresh viewport coordinates.
179
- var targetForScroll = isToolbarShown ? getTargetElement(editorView, pasteStartPos) : null;
180
- var overflowScrollParent = targetForScroll ? (0, _ui.findOverflowScrollParent)(targetForScroll) : false;
212
+ var overflowScrollParent = isToolbarShown ? (0, _ui.findOverflowScrollParent)(editorView.dom) : false;
181
213
  var effectiveScrollableElement = overflowScrollParent || scrollableElement;
182
214
  var pasteMenuComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
183
215
  var anyComponentVisible = (0, _hasVisibleButton.hasVisibleButton)(pasteMenuComponents);
@@ -26,6 +26,34 @@ function getTargetElement(editorView, pos) {
26
26
  }
27
27
  }
28
28
 
29
+ /**
30
+ * Returns the position immediately after a table ancestor of `pos`, or
31
+ * `undefined` if not inside a table. Safe to cache per document version.
32
+ */
33
+ export function resolveTableAfterPos(editorView, pos) {
34
+ const $pos = editorView.state.doc.resolve(pos);
35
+ for (let depth = $pos.depth; depth > 0; depth--) {
36
+ if ($pos.node(depth).type.name === 'table') {
37
+ return $pos.after(depth);
38
+ }
39
+ }
40
+ return undefined;
41
+ }
42
+
43
+ /**
44
+ * Returns the visual bottom of the pasted content. For positions inside a
45
+ * table, uses the pre-computed `tableAfterPos` to get the correct bottom edge.
46
+ */
47
+ export function getVisualEndBottom(editorView, pasteEndPos, tableAfterPos) {
48
+ const endCoords = editorView.coordsAtPos(pasteEndPos);
49
+ let bottom = endCoords.bottom;
50
+ if (tableAfterPos !== undefined) {
51
+ const afterCoords = editorView.coordsAtPos(tableAfterPos);
52
+ bottom = Math.max(bottom, afterCoords.bottom);
53
+ }
54
+ return bottom;
55
+ }
56
+
29
57
  /**
30
58
  * Adjusts the vertical position of the paste menu to align with the top of the
31
59
  * pasted content using the exact coordinates at the paste start position,
@@ -43,10 +71,12 @@ function getTargetElement(editorView, pos) {
43
71
  * above the visible area.
44
72
  */
45
73
  export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElement, scrollableElement) {
74
+ // Pre-compute once per render to avoid doc.resolve() on every scroll frame.
75
+ const tableAfterPos = resolveTableAfterPos(editorView, pasteEndPos);
46
76
  return position => {
47
77
  var _position$top;
48
78
  const startCoords = editorView.coordsAtPos(pasteStartPos);
49
- const endCoords = editorView.coordsAtPos(pasteEndPos);
79
+ const endBottom = getVisualEndBottom(editorView, pasteEndPos, tableAfterPos);
50
80
  const targetRect = targetElement.getBoundingClientRect();
51
81
 
52
82
  // The Popup places the menu at the target's bottom edge by default.
@@ -60,7 +90,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
60
90
  // content is still visible.
61
91
  if (scrollableElement) {
62
92
  const scrollContainerTop = scrollableElement.getBoundingClientRect().top;
63
- if (startCoords.top < scrollContainerTop && endCoords.bottom > scrollContainerTop) {
93
+ if (startCoords.top < scrollContainerTop && endBottom > scrollContainerTop) {
64
94
  adjustedTop += scrollContainerTop - startCoords.top + PASTE_MENU_GAP_TOP;
65
95
  }
66
96
  }
@@ -89,6 +119,7 @@ export const PasteActionsMenu = ({
89
119
  });
90
120
  const prevShowToolbarRef = useRef(false);
91
121
  useEffect(() => {
122
+ var _lastContentPasted$te, _lastContentPasted$te2;
92
123
  if (!lastContentPasted) {
93
124
  hideToolbar()(editorView.state, editorView.dispatch);
94
125
  return;
@@ -106,7 +137,7 @@ export const PasteActionsMenu = ({
106
137
  for (let depth = $pos.depth; depth > 0; depth--) {
107
138
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
108
139
  }
109
- const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
140
+ const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
110
141
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
111
142
  }, [lastContentPasted, editorView]);
112
143
  const {
@@ -167,8 +198,7 @@ export const PasteActionsMenu = ({
167
198
  // so the Popup attaches its built-in scroll listener, which calls
168
199
  // scheduledUpdatePosition (RAF-throttled) on each scroll event — triggering
169
200
  // onPositionCalculated with fresh viewport coordinates.
170
- const targetForScroll = isToolbarShown ? getTargetElement(editorView, pasteStartPos) : null;
171
- const overflowScrollParent = targetForScroll ? findOverflowScrollParent(targetForScroll) : false;
201
+ const overflowScrollParent = isToolbarShown ? findOverflowScrollParent(editorView.dom) : false;
172
202
  const effectiveScrollableElement = overflowScrollParent || scrollableElement;
173
203
  const pasteMenuComponents = (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
174
204
  const anyComponentVisible = hasVisibleButton(pasteMenuComponents);
@@ -29,6 +29,34 @@ function getTargetElement(editorView, pos) {
29
29
  }
30
30
  }
31
31
 
32
+ /**
33
+ * Returns the position immediately after a table ancestor of `pos`, or
34
+ * `undefined` if not inside a table. Safe to cache per document version.
35
+ */
36
+ export function resolveTableAfterPos(editorView, pos) {
37
+ var $pos = editorView.state.doc.resolve(pos);
38
+ for (var depth = $pos.depth; depth > 0; depth--) {
39
+ if ($pos.node(depth).type.name === 'table') {
40
+ return $pos.after(depth);
41
+ }
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ /**
47
+ * Returns the visual bottom of the pasted content. For positions inside a
48
+ * table, uses the pre-computed `tableAfterPos` to get the correct bottom edge.
49
+ */
50
+ export function getVisualEndBottom(editorView, pasteEndPos, tableAfterPos) {
51
+ var endCoords = editorView.coordsAtPos(pasteEndPos);
52
+ var bottom = endCoords.bottom;
53
+ if (tableAfterPos !== undefined) {
54
+ var afterCoords = editorView.coordsAtPos(tableAfterPos);
55
+ bottom = Math.max(bottom, afterCoords.bottom);
56
+ }
57
+ return bottom;
58
+ }
59
+
32
60
  /**
33
61
  * Adjusts the vertical position of the paste menu to align with the top of the
34
62
  * pasted content using the exact coordinates at the paste start position,
@@ -46,10 +74,12 @@ function getTargetElement(editorView, pos) {
46
74
  * above the visible area.
47
75
  */
48
76
  export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElement, scrollableElement) {
77
+ // Pre-compute once per render to avoid doc.resolve() on every scroll frame.
78
+ var tableAfterPos = resolveTableAfterPos(editorView, pasteEndPos);
49
79
  return function (position) {
50
80
  var _position$top;
51
81
  var startCoords = editorView.coordsAtPos(pasteStartPos);
52
- var endCoords = editorView.coordsAtPos(pasteEndPos);
82
+ var endBottom = getVisualEndBottom(editorView, pasteEndPos, tableAfterPos);
53
83
  var targetRect = targetElement.getBoundingClientRect();
54
84
 
55
85
  // The Popup places the menu at the target's bottom edge by default.
@@ -63,7 +93,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
63
93
  // content is still visible.
64
94
  if (scrollableElement) {
65
95
  var scrollContainerTop = scrollableElement.getBoundingClientRect().top;
66
- if (startCoords.top < scrollContainerTop && endCoords.bottom > scrollContainerTop) {
96
+ if (startCoords.top < scrollContainerTop && endBottom > scrollContainerTop) {
67
97
  adjustedTop += scrollContainerTop - startCoords.top + PASTE_MENU_GAP_TOP;
68
98
  }
69
99
  }
@@ -89,6 +119,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
89
119
  lastContentPasted = _useSharedPluginState.lastContentPasted;
90
120
  var prevShowToolbarRef = useRef(false);
91
121
  useEffect(function () {
122
+ var _lastContentPasted$te, _lastContentPasted$te2;
92
123
  if (!lastContentPasted) {
93
124
  hideToolbar()(editorView.state, editorView.dispatch);
94
125
  return;
@@ -106,7 +137,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
106
137
  for (var depth = $pos.depth; depth > 0; depth--) {
107
138
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
108
139
  }
109
- var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
140
+ var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
110
141
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
111
142
  }, [lastContentPasted, editorView]);
112
143
  var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
@@ -166,8 +197,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
166
197
  // so the Popup attaches its built-in scroll listener, which calls
167
198
  // scheduledUpdatePosition (RAF-throttled) on each scroll event — triggering
168
199
  // onPositionCalculated with fresh viewport coordinates.
169
- var targetForScroll = isToolbarShown ? getTargetElement(editorView, pasteStartPos) : null;
170
- var overflowScrollParent = targetForScroll ? findOverflowScrollParent(targetForScroll) : false;
200
+ var overflowScrollParent = isToolbarShown ? findOverflowScrollParent(editorView.dom) : false;
171
201
  var effectiveScrollableElement = overflowScrollParent || scrollableElement;
172
202
  var pasteMenuComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
173
203
  var anyComponentVisible = hasVisibleButton(pasteMenuComponents);
@@ -9,6 +9,16 @@ interface PasteActionsMenuProps {
9
9
  mountTo?: HTMLElement;
10
10
  scrollableElement?: HTMLElement;
11
11
  }
12
+ /**
13
+ * Returns the position immediately after a table ancestor of `pos`, or
14
+ * `undefined` if not inside a table. Safe to cache per document version.
15
+ */
16
+ export declare function resolveTableAfterPos(editorView: EditorView, pos: number): number | undefined;
17
+ /**
18
+ * Returns the visual bottom of the pasted content. For positions inside a
19
+ * table, uses the pre-computed `tableAfterPos` to get the correct bottom edge.
20
+ */
21
+ export declare function getVisualEndBottom(editorView: EditorView, pasteEndPos: number, tableAfterPos?: number): number;
12
22
  /**
13
23
  * Adjusts the vertical position of the paste menu to align with the top of the
14
24
  * pasted content using the exact coordinates at the paste start position,
@@ -9,6 +9,16 @@ interface PasteActionsMenuProps {
9
9
  mountTo?: HTMLElement;
10
10
  scrollableElement?: HTMLElement;
11
11
  }
12
+ /**
13
+ * Returns the position immediately after a table ancestor of `pos`, or
14
+ * `undefined` if not inside a table. Safe to cache per document version.
15
+ */
16
+ export declare function resolveTableAfterPos(editorView: EditorView, pos: number): number | undefined;
17
+ /**
18
+ * Returns the visual bottom of the pasted content. For positions inside a
19
+ * table, uses the pre-computed `tableAfterPos` to get the correct bottom edge.
20
+ */
21
+ export declare function getVisualEndBottom(editorView: EditorView, pasteEndPos: number, tableAfterPos?: number): number;
12
22
  /**
13
23
  * Adjusts the vertical position of the paste menu to align with the top of the
14
24
  * pasted content using the exact coordinates at the paste start position,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste-options-toolbar",
3
- "version": "9.1.2",
3
+ "version": "9.1.4",
4
4
  "description": "Paste options toolbar for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -48,7 +48,7 @@
48
48
  "react-intl-next": "npm:react-intl@^5.18.1"
49
49
  },
50
50
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^112.4.0",
51
+ "@atlaskit/editor-common": "^112.5.0",
52
52
  "react": "^18.2.0",
53
53
  "react-dom": "^18.2.0"
54
54
  },