@atlaskit/editor-plugin-block-menu 10.0.0 → 10.1.1

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,22 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 10.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 10.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`06e26bd93de31`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/06e26bd93de31) -
14
+ [ux] Close the block menu when its positioning containers resize.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 10.0.0
4
21
 
5
22
  ### Patch Changes
@@ -22,6 +22,7 @@ var _ui = require("@atlaskit/editor-common/ui");
22
22
  var _uiMenu = require("@atlaskit/editor-common/ui-menu");
23
23
  var _uiReact = require("@atlaskit/editor-common/ui-react");
24
24
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
25
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
25
26
  var _compiled = require("@atlaskit/primitives/compiled");
26
27
  var _prosemirrorHistory = require("@atlaskit/prosemirror-history");
27
28
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
@@ -79,10 +80,48 @@ var isSelectionWithinCodeBlock = function isSelectionWithinCodeBlock(state) {
79
80
  $to = _state$selection.$to;
80
81
  return $from.sameParent($to) && $from.parent.type === state.schema.nodes.codeBlock;
81
82
  };
82
- var BlockMenuContent = function BlockMenuContent(_ref2) {
83
+ var useCloseBlockMenuOnResize = function useCloseBlockMenuOnResize(_ref2) {
84
+ var isEnabled = _ref2.isEnabled,
85
+ mountTo = _ref2.mountTo,
86
+ boundariesElement = _ref2.boundariesElement,
87
+ scrollableElement = _ref2.scrollableElement,
88
+ closeMenu = _ref2.closeMenu;
89
+ (0, _react.useEffect)(function () {
90
+ if (!isEnabled || typeof ResizeObserver === 'undefined') {
91
+ return;
92
+ }
93
+ var observedElements = Array.from(new Set([mountTo, boundariesElement, scrollableElement].filter(function (element) {
94
+ return Boolean(element);
95
+ })));
96
+ if (observedElements.length === 0) {
97
+ return;
98
+ }
99
+ var pendingInitialResizeElements = new Set(observedElements);
100
+ var resizeObserver = new ResizeObserver(function (entries) {
101
+ var hasResizeAfterInitialObservation = entries.some(function (_ref3) {
102
+ var target = _ref3.target;
103
+ if (target instanceof HTMLElement && pendingInitialResizeElements.has(target)) {
104
+ pendingInitialResizeElements.delete(target);
105
+ return false;
106
+ }
107
+ return true;
108
+ });
109
+ if (hasResizeAfterInitialObservation) {
110
+ closeMenu();
111
+ }
112
+ });
113
+ observedElements.forEach(function (element) {
114
+ return resizeObserver.observe(element);
115
+ });
116
+ return function () {
117
+ resizeObserver.disconnect();
118
+ };
119
+ }, [boundariesElement, closeMenu, isEnabled, mountTo, scrollableElement]);
120
+ };
121
+ var BlockMenuContent = function BlockMenuContent(_ref4) {
83
122
  var _api$blockMenu;
84
- var api = _ref2.api,
85
- setRef = _ref2.setRef;
123
+ var api = _ref4.api,
124
+ setRef = _ref4.setRef;
86
125
  var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
87
126
  var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
88
127
  var ref = function ref(el) {
@@ -116,13 +155,13 @@ var BlockMenuContent = function BlockMenuContent(_ref2) {
116
155
  allRegisteredComponents: blockMenuComponents || []
117
156
  })));
118
157
  };
119
- var BlockMenu = function BlockMenu(_ref3) {
120
- var _editorView$dom, _ref4, _api$analytics2;
121
- var editorView = _ref3.editorView,
122
- api = _ref3.api,
123
- mountTo = _ref3.mountTo,
124
- boundariesElement = _ref3.boundariesElement,
125
- scrollableElement = _ref3.scrollableElement;
158
+ var BlockMenu = function BlockMenu(_ref5) {
159
+ var _editorView$dom, _ref7, _api$analytics2;
160
+ var editorView = _ref5.editorView,
161
+ api = _ref5.api,
162
+ mountTo = _ref5.mountTo,
163
+ boundariesElement = _ref5.boundariesElement,
164
+ scrollableElement = _ref5.scrollableElement;
126
165
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls', 'userIntent'], function (states) {
127
166
  var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$userIntentSta, _states$blockControls4;
128
167
  return {
@@ -141,6 +180,30 @@ var BlockMenu = function BlockMenu(_ref3) {
141
180
  var _useBlockMenu = (0, _blockMenuProvider.useBlockMenu)(),
142
181
  onDropdownOpenChanged = _useBlockMenu.onDropdownOpenChanged;
143
182
  var targetHandleRef = editorView === null || editorView === void 0 || (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(_styles.DRAG_HANDLE_SELECTOR);
183
+ var shouldCloseBlockMenuOnResize = (0, _platformFeatureFlags.fg)('platform_editor_block_menu_jira_patch_4');
184
+ var closeMenu = _react.default.useCallback(function () {
185
+ api === null || api === void 0 || api.core.actions.execute(function (_ref6) {
186
+ var _api$blockControls, _api$userIntent2;
187
+ var tr = _ref6.tr;
188
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.toggleBlockMenu({
189
+ closeMenu: true
190
+ })({
191
+ tr: tr
192
+ });
193
+ onDropdownOpenChanged(false);
194
+ api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
195
+ tr: tr
196
+ });
197
+ return tr;
198
+ });
199
+ }, [api, currentUserIntent, onDropdownOpenChanged]);
200
+ useCloseBlockMenuOnResize({
201
+ isEnabled: Boolean(isMenuOpen && shouldCloseBlockMenuOnResize),
202
+ mountTo: mountTo,
203
+ boundariesElement: boundariesElement,
204
+ scrollableElement: scrollableElement,
205
+ closeMenu: closeMenu
206
+ });
144
207
  var prevIsMenuOpenRef = (0, _react.useRef)(false);
145
208
  var popupRef = (0, _react.useRef)(undefined);
146
209
  var _React$useState = _react.default.useState(0),
@@ -155,13 +218,13 @@ var BlockMenu = function BlockMenu(_ref3) {
155
218
  }
156
219
  setMenuHeight(((_popupRef$current = popupRef.current) === null || _popupRef$current === void 0 ? void 0 : _popupRef$current.clientHeight) || FALLBACK_MENU_HEIGHT);
157
220
  }, [isMenuOpen]);
158
- var hasFocus = (_ref4 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) ||
221
+ var hasFocus = (_ref7 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) ||
159
222
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage
160
223
  document.activeElement === targetHandleRef || popupRef.current && (
161
224
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage
162
225
  popupRef.current.contains(document.activeElement) ||
163
226
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage
164
- popupRef.current === document.activeElement)) !== null && _ref4 !== void 0 ? _ref4 : false;
227
+ popupRef.current === document.activeElement)) !== null && _ref7 !== void 0 ? _ref7 : false;
165
228
  var selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
166
229
 
167
230
  // Use conditional hook based on feature flag
@@ -178,7 +241,7 @@ var BlockMenu = function BlockMenu(_ref3) {
178
241
  return null;
179
242
  }
180
243
  var handleKeyDown = function handleKeyDown(event) {
181
- var _api$core, _api$blockControls;
244
+ var _api$core, _api$blockControls2;
182
245
  // When the editor view has focus, the keydown will be handled by the
183
246
  // selection preservation plugin – exit early to avoid double handling
184
247
  // Also exit if selection is within a code block to avoid double handling when code block got focus when the node after it is deleted
@@ -201,7 +264,7 @@ var BlockMenu = function BlockMenu(_ref3) {
201
264
  } else if (isRedo) {
202
265
  (0, _prosemirrorHistory.redo)(editorView.state, editorView.dispatch);
203
266
  }
204
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.handleKeyDownWithPreservedSelection(event));
267
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.handleKeyDownWithPreservedSelection(event));
205
268
  };
206
269
  var handleClickOutside = function handleClickOutside(e) {
207
270
  // check if the clicked element was another drag handle, if so don't close the menu
@@ -210,22 +273,6 @@ var BlockMenu = function BlockMenu(_ref3) {
210
273
  }
211
274
  closeMenu();
212
275
  };
213
- var closeMenu = function closeMenu() {
214
- api === null || api === void 0 || api.core.actions.execute(function (_ref5) {
215
- var _api$blockControls2, _api$userIntent2;
216
- var tr = _ref5.tr;
217
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.toggleBlockMenu({
218
- closeMenu: true
219
- })({
220
- tr: tr
221
- });
222
- onDropdownOpenChanged(false);
223
- api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
224
- tr: tr
225
- });
226
- return tr;
227
- });
228
- };
229
276
  if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
230
277
  closeMenu();
231
278
  return null;
@@ -13,6 +13,7 @@ import { Popup } from '@atlaskit/editor-common/ui';
13
13
  import { ArrowKeyNavigationProvider, ArrowKeyNavigationType } from '@atlaskit/editor-common/ui-menu';
14
14
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
15
15
  import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
16
+ import { fg } from '@atlaskit/platform-feature-flags';
16
17
  import { Box } from '@atlaskit/primitives/compiled';
17
18
  import { redo, undo } from '@atlaskit/prosemirror-history';
18
19
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
@@ -71,6 +72,42 @@ const isSelectionWithinCodeBlock = state => {
71
72
  } = state.selection;
72
73
  return $from.sameParent($to) && $from.parent.type === state.schema.nodes.codeBlock;
73
74
  };
75
+ const useCloseBlockMenuOnResize = ({
76
+ isEnabled,
77
+ mountTo,
78
+ boundariesElement,
79
+ scrollableElement,
80
+ closeMenu
81
+ }) => {
82
+ useEffect(() => {
83
+ if (!isEnabled || typeof ResizeObserver === 'undefined') {
84
+ return;
85
+ }
86
+ const observedElements = Array.from(new Set([mountTo, boundariesElement, scrollableElement].filter(element => Boolean(element))));
87
+ if (observedElements.length === 0) {
88
+ return;
89
+ }
90
+ const pendingInitialResizeElements = new Set(observedElements);
91
+ const resizeObserver = new ResizeObserver(entries => {
92
+ const hasResizeAfterInitialObservation = entries.some(({
93
+ target
94
+ }) => {
95
+ if (target instanceof HTMLElement && pendingInitialResizeElements.has(target)) {
96
+ pendingInitialResizeElements.delete(target);
97
+ return false;
98
+ }
99
+ return true;
100
+ });
101
+ if (hasResizeAfterInitialObservation) {
102
+ closeMenu();
103
+ }
104
+ });
105
+ observedElements.forEach(element => resizeObserver.observe(element));
106
+ return () => {
107
+ resizeObserver.disconnect();
108
+ };
109
+ }, [boundariesElement, closeMenu, isEnabled, mountTo, scrollableElement]);
110
+ };
74
111
  const BlockMenuContent = ({
75
112
  api,
76
113
  setRef
@@ -135,6 +172,31 @@ const BlockMenu = ({
135
172
  onDropdownOpenChanged
136
173
  } = useBlockMenu();
137
174
  const targetHandleRef = editorView === null || editorView === void 0 ? void 0 : (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
175
+ const shouldCloseBlockMenuOnResize = fg('platform_editor_block_menu_jira_patch_4');
176
+ const closeMenu = React.useCallback(() => {
177
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(({
178
+ tr
179
+ }) => {
180
+ var _api$blockControls, _api$userIntent2;
181
+ api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.toggleBlockMenu({
182
+ closeMenu: true
183
+ })({
184
+ tr
185
+ });
186
+ onDropdownOpenChanged(false);
187
+ api === null || api === void 0 ? void 0 : (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
188
+ tr
189
+ });
190
+ return tr;
191
+ });
192
+ }, [api, currentUserIntent, onDropdownOpenChanged]);
193
+ useCloseBlockMenuOnResize({
194
+ isEnabled: Boolean(isMenuOpen && shouldCloseBlockMenuOnResize),
195
+ mountTo,
196
+ boundariesElement,
197
+ scrollableElement,
198
+ closeMenu
199
+ });
138
200
  const prevIsMenuOpenRef = useRef(false);
139
201
  const popupRef = useRef(undefined);
140
202
  const [menuHeight, setMenuHeight] = React.useState(0);
@@ -169,7 +231,7 @@ const BlockMenu = ({
169
231
  return null;
170
232
  }
171
233
  const handleKeyDown = event => {
172
- var _api$core, _api$blockControls, _api$blockControls$co;
234
+ var _api$core, _api$blockControls2, _api$blockControls2$c;
173
235
  // When the editor view has focus, the keydown will be handled by the
174
236
  // selection preservation plugin – exit early to avoid double handling
175
237
  // Also exit if selection is within a code block to avoid double handling when code block got focus when the node after it is deleted
@@ -192,7 +254,7 @@ const BlockMenu = ({
192
254
  } else if (isRedo) {
193
255
  redo(editorView.state, editorView.dispatch);
194
256
  }
195
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$co = _api$blockControls.commands) === null || _api$blockControls$co === void 0 ? void 0 : _api$blockControls$co.handleKeyDownWithPreservedSelection(event));
257
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$c = _api$blockControls2.commands) === null || _api$blockControls2$c === void 0 ? void 0 : _api$blockControls2$c.handleKeyDownWithPreservedSelection(event));
196
258
  };
197
259
  const handleClickOutside = e => {
198
260
  // check if the clicked element was another drag handle, if so don't close the menu
@@ -201,23 +263,6 @@ const BlockMenu = ({
201
263
  }
202
264
  closeMenu();
203
265
  };
204
- const closeMenu = () => {
205
- api === null || api === void 0 ? void 0 : api.core.actions.execute(({
206
- tr
207
- }) => {
208
- var _api$blockControls2, _api$userIntent2;
209
- api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.toggleBlockMenu({
210
- closeMenu: true
211
- })({
212
- tr
213
- });
214
- onDropdownOpenChanged(false);
215
- api === null || api === void 0 ? void 0 : (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
216
- tr
217
- });
218
- return tr;
219
- });
220
- };
221
266
  if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
222
267
  closeMenu();
223
268
  return null;
@@ -14,6 +14,7 @@ import { Popup } from '@atlaskit/editor-common/ui';
14
14
  import { ArrowKeyNavigationProvider, ArrowKeyNavigationType } from '@atlaskit/editor-common/ui-menu';
15
15
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
16
16
  import { akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
17
+ import { fg } from '@atlaskit/platform-feature-flags';
17
18
  import { Box } from '@atlaskit/primitives/compiled';
18
19
  import { redo, undo } from '@atlaskit/prosemirror-history';
19
20
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
@@ -70,10 +71,48 @@ var isSelectionWithinCodeBlock = function isSelectionWithinCodeBlock(state) {
70
71
  $to = _state$selection.$to;
71
72
  return $from.sameParent($to) && $from.parent.type === state.schema.nodes.codeBlock;
72
73
  };
73
- var BlockMenuContent = function BlockMenuContent(_ref2) {
74
+ var useCloseBlockMenuOnResize = function useCloseBlockMenuOnResize(_ref2) {
75
+ var isEnabled = _ref2.isEnabled,
76
+ mountTo = _ref2.mountTo,
77
+ boundariesElement = _ref2.boundariesElement,
78
+ scrollableElement = _ref2.scrollableElement,
79
+ closeMenu = _ref2.closeMenu;
80
+ useEffect(function () {
81
+ if (!isEnabled || typeof ResizeObserver === 'undefined') {
82
+ return;
83
+ }
84
+ var observedElements = Array.from(new Set([mountTo, boundariesElement, scrollableElement].filter(function (element) {
85
+ return Boolean(element);
86
+ })));
87
+ if (observedElements.length === 0) {
88
+ return;
89
+ }
90
+ var pendingInitialResizeElements = new Set(observedElements);
91
+ var resizeObserver = new ResizeObserver(function (entries) {
92
+ var hasResizeAfterInitialObservation = entries.some(function (_ref3) {
93
+ var target = _ref3.target;
94
+ if (target instanceof HTMLElement && pendingInitialResizeElements.has(target)) {
95
+ pendingInitialResizeElements.delete(target);
96
+ return false;
97
+ }
98
+ return true;
99
+ });
100
+ if (hasResizeAfterInitialObservation) {
101
+ closeMenu();
102
+ }
103
+ });
104
+ observedElements.forEach(function (element) {
105
+ return resizeObserver.observe(element);
106
+ });
107
+ return function () {
108
+ resizeObserver.disconnect();
109
+ };
110
+ }, [boundariesElement, closeMenu, isEnabled, mountTo, scrollableElement]);
111
+ };
112
+ var BlockMenuContent = function BlockMenuContent(_ref4) {
74
113
  var _api$blockMenu;
75
- var api = _ref2.api,
76
- setRef = _ref2.setRef;
114
+ var api = _ref4.api,
115
+ setRef = _ref4.setRef;
77
116
  var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
78
117
  var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
79
118
  var ref = function ref(el) {
@@ -107,13 +146,13 @@ var BlockMenuContent = function BlockMenuContent(_ref2) {
107
146
  allRegisteredComponents: blockMenuComponents || []
108
147
  })));
109
148
  };
110
- var BlockMenu = function BlockMenu(_ref3) {
111
- var _editorView$dom, _ref4, _api$analytics2;
112
- var editorView = _ref3.editorView,
113
- api = _ref3.api,
114
- mountTo = _ref3.mountTo,
115
- boundariesElement = _ref3.boundariesElement,
116
- scrollableElement = _ref3.scrollableElement;
149
+ var BlockMenu = function BlockMenu(_ref5) {
150
+ var _editorView$dom, _ref7, _api$analytics2;
151
+ var editorView = _ref5.editorView,
152
+ api = _ref5.api,
153
+ mountTo = _ref5.mountTo,
154
+ boundariesElement = _ref5.boundariesElement,
155
+ scrollableElement = _ref5.scrollableElement;
117
156
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls', 'userIntent'], function (states) {
118
157
  var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$userIntentSta, _states$blockControls4;
119
158
  return {
@@ -132,6 +171,30 @@ var BlockMenu = function BlockMenu(_ref3) {
132
171
  var _useBlockMenu = useBlockMenu(),
133
172
  onDropdownOpenChanged = _useBlockMenu.onDropdownOpenChanged;
134
173
  var targetHandleRef = editorView === null || editorView === void 0 || (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
174
+ var shouldCloseBlockMenuOnResize = fg('platform_editor_block_menu_jira_patch_4');
175
+ var closeMenu = React.useCallback(function () {
176
+ api === null || api === void 0 || api.core.actions.execute(function (_ref6) {
177
+ var _api$blockControls, _api$userIntent2;
178
+ var tr = _ref6.tr;
179
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.toggleBlockMenu({
180
+ closeMenu: true
181
+ })({
182
+ tr: tr
183
+ });
184
+ onDropdownOpenChanged(false);
185
+ api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
186
+ tr: tr
187
+ });
188
+ return tr;
189
+ });
190
+ }, [api, currentUserIntent, onDropdownOpenChanged]);
191
+ useCloseBlockMenuOnResize({
192
+ isEnabled: Boolean(isMenuOpen && shouldCloseBlockMenuOnResize),
193
+ mountTo: mountTo,
194
+ boundariesElement: boundariesElement,
195
+ scrollableElement: scrollableElement,
196
+ closeMenu: closeMenu
197
+ });
135
198
  var prevIsMenuOpenRef = useRef(false);
136
199
  var popupRef = useRef(undefined);
137
200
  var _React$useState = React.useState(0),
@@ -146,13 +209,13 @@ var BlockMenu = function BlockMenu(_ref3) {
146
209
  }
147
210
  setMenuHeight(((_popupRef$current = popupRef.current) === null || _popupRef$current === void 0 ? void 0 : _popupRef$current.clientHeight) || FALLBACK_MENU_HEIGHT);
148
211
  }, [isMenuOpen]);
149
- var hasFocus = (_ref4 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) ||
212
+ var hasFocus = (_ref7 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) ||
150
213
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage
151
214
  document.activeElement === targetHandleRef || popupRef.current && (
152
215
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage
153
216
  popupRef.current.contains(document.activeElement) ||
154
217
  // eslint-disable-next-line @atlaskit/platform/no-direct-document-usage
155
- popupRef.current === document.activeElement)) !== null && _ref4 !== void 0 ? _ref4 : false;
218
+ popupRef.current === document.activeElement)) !== null && _ref7 !== void 0 ? _ref7 : false;
156
219
  var selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
157
220
 
158
221
  // Use conditional hook based on feature flag
@@ -169,7 +232,7 @@ var BlockMenu = function BlockMenu(_ref3) {
169
232
  return null;
170
233
  }
171
234
  var handleKeyDown = function handleKeyDown(event) {
172
- var _api$core, _api$blockControls;
235
+ var _api$core, _api$blockControls2;
173
236
  // When the editor view has focus, the keydown will be handled by the
174
237
  // selection preservation plugin – exit early to avoid double handling
175
238
  // Also exit if selection is within a code block to avoid double handling when code block got focus when the node after it is deleted
@@ -192,7 +255,7 @@ var BlockMenu = function BlockMenu(_ref3) {
192
255
  } else if (isRedo) {
193
256
  redo(editorView.state, editorView.dispatch);
194
257
  }
195
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.handleKeyDownWithPreservedSelection(event));
258
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.handleKeyDownWithPreservedSelection(event));
196
259
  };
197
260
  var handleClickOutside = function handleClickOutside(e) {
198
261
  // check if the clicked element was another drag handle, if so don't close the menu
@@ -201,22 +264,6 @@ var BlockMenu = function BlockMenu(_ref3) {
201
264
  }
202
265
  closeMenu();
203
266
  };
204
- var closeMenu = function closeMenu() {
205
- api === null || api === void 0 || api.core.actions.execute(function (_ref5) {
206
- var _api$blockControls2, _api$userIntent2;
207
- var tr = _ref5.tr;
208
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.toggleBlockMenu({
209
- closeMenu: true
210
- })({
211
- tr: tr
212
- });
213
- onDropdownOpenChanged(false);
214
- api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
215
- tr: tr
216
- });
217
- return tr;
218
- });
219
- };
220
267
  if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
221
268
  closeMenu();
222
269
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "10.0.0",
3
+ "version": "10.1.1",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,19 +38,19 @@
38
38
  "@atlaskit/editor-prosemirror": "^7.3.0",
39
39
  "@atlaskit/editor-shared-styles": "^3.11.0",
40
40
  "@atlaskit/editor-tables": "^2.10.0",
41
- "@atlaskit/editor-toolbar": "^1.9.0",
41
+ "@atlaskit/editor-toolbar": "^1.10.0",
42
42
  "@atlaskit/flag": "^17.12.0",
43
- "@atlaskit/icon": "^35.3.0",
43
+ "@atlaskit/icon": "^35.4.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/primitives": "^19.0.0",
46
46
  "@atlaskit/prosemirror-history": "^0.2.0",
47
- "@atlaskit/tmp-editor-statsig": "^88.0.0",
47
+ "@atlaskit/tmp-editor-statsig": "^89.0.0",
48
48
  "@atlaskit/tokens": "^13.1.0",
49
49
  "@babel/runtime": "^7.0.0",
50
50
  "bind-event-listener": "^3.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@atlaskit/editor-common": "^115.0.0",
53
+ "@atlaskit/editor-common": "^115.2.0",
54
54
  "react": "^18.2.0",
55
55
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
56
56
  },
@@ -100,6 +100,9 @@
100
100
  "platform_editor_block_menu_jira_patch_3": {
101
101
  "type": "boolean"
102
102
  },
103
+ "platform_editor_block_menu_jira_patch_4": {
104
+ "type": "boolean"
105
+ },
103
106
  "cc_blocks_changeboarding": {
104
107
  "type": "boolean"
105
108
  },