@atlaskit/editor-plugin-block-menu 5.1.8 → 5.1.9

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-block-menu
2
2
 
3
+ ## 5.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`fdcaf17b021af`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fdcaf17b021af) -
8
+ Editor-2676: keep block menu open when move up down clicked
9
+ - Updated dependencies
10
+
3
11
  ## 5.1.8
4
12
 
5
13
  ### Patch Changes
@@ -8,7 +8,10 @@ exports.useBlockMenu = exports.BlockMenuProvider = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
10
  var BlockMenuContext = /*#__PURE__*/(0, _react.createContext)({
11
- onDropdownOpenChanged: function onDropdownOpenChanged() {}
11
+ onDropdownOpenChanged: function onDropdownOpenChanged() {},
12
+ moveFocusTo: function moveFocusTo() {},
13
+ moveDownRef: /*#__PURE__*/_react.default.createRef(),
14
+ moveUpRef: /*#__PURE__*/_react.default.createRef()
12
15
  });
13
16
  var useBlockMenu = exports.useBlockMenu = function useBlockMenu() {
14
17
  var context = (0, _react.useContext)(BlockMenuContext);
@@ -20,6 +23,8 @@ var useBlockMenu = exports.useBlockMenu = function useBlockMenu() {
20
23
  var BlockMenuProvider = exports.BlockMenuProvider = function BlockMenuProvider(_ref) {
21
24
  var children = _ref.children,
22
25
  api = _ref.api;
26
+ var moveUpRef = (0, _react.useRef)(null);
27
+ var moveDownRef = (0, _react.useRef)(null);
23
28
  var onDropdownOpenChanged = (0, _react.useCallback)(function (isOpen) {
24
29
  if (!isOpen) {
25
30
  // On Dropdown closed, return focus to editor
@@ -32,9 +37,21 @@ var BlockMenuProvider = exports.BlockMenuProvider = function BlockMenuProvider(_
32
37
  }, 1);
33
38
  }
34
39
  }, [api]);
40
+ var moveFocusTo = (0, _react.useCallback)(function (direction) {
41
+ if (direction === 'moveUp') {
42
+ var _moveUpRef$current;
43
+ (_moveUpRef$current = moveUpRef.current) === null || _moveUpRef$current === void 0 || _moveUpRef$current.focus();
44
+ } else if (direction === 'moveDown') {
45
+ var _moveDownRef$current;
46
+ (_moveDownRef$current = moveDownRef.current) === null || _moveDownRef$current === void 0 || _moveDownRef$current.focus();
47
+ }
48
+ }, []);
35
49
  return /*#__PURE__*/_react.default.createElement(BlockMenuContext.Provider, {
36
50
  value: {
37
- onDropdownOpenChanged: onDropdownOpenChanged
51
+ onDropdownOpenChanged: onDropdownOpenChanged,
52
+ moveFocusTo: moveFocusTo,
53
+ moveDownRef: moveDownRef,
54
+ moveUpRef: moveUpRef
38
55
  }
39
56
  }, children);
40
57
  };
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.MoveDownDropdownItem = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
+ var _react = _interopRequireWildcard(require("react"));
9
10
  var _reactIntlNext = require("react-intl-next");
10
11
  var _analytics = require("@atlaskit/editor-common/analytics");
11
12
  var _hooks = require("@atlaskit/editor-common/hooks");
@@ -13,11 +14,16 @@ var _messages = require("@atlaskit/editor-common/messages");
13
14
  var _types = require("@atlaskit/editor-common/types");
14
15
  var _editorToolbar = require("@atlaskit/editor-toolbar");
15
16
  var _arrowDown = _interopRequireDefault(require("@atlaskit/icon/core/arrow-down"));
17
+ var _blockMenuProvider = require("./block-menu-provider");
16
18
  var _consts = require("./consts");
19
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
20
  var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
18
21
  var api = _ref.api;
19
22
  var _useIntl = (0, _reactIntlNext.useIntl)(),
20
23
  formatMessage = _useIntl.formatMessage;
24
+ var _useBlockMenu = (0, _blockMenuProvider.useBlockMenu)(),
25
+ moveFocusTo = _useBlockMenu.moveFocusTo,
26
+ moveDownRef = _useBlockMenu.moveDownRef;
21
27
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (_ref2) {
22
28
  var _blockControlsState$b;
23
29
  var blockControlsState = _ref2.blockControlsState;
@@ -26,9 +32,18 @@ var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
26
32
  };
27
33
  }),
28
34
  canMoveDown = _useSharedPluginState.canMoveDown;
35
+ (0, _react.useEffect)(function () {
36
+ var moveDownElement = moveDownRef.current;
37
+ if (!moveDownElement) {
38
+ return;
39
+ }
40
+ if (!canMoveDown && moveDownElement === document.activeElement) {
41
+ moveFocusTo('moveUp');
42
+ }
43
+ }, [canMoveDown, moveFocusTo, moveDownRef]);
29
44
  var handleClick = function handleClick() {
30
45
  api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
31
- var _api$analytics, _api$blockControls, _api$blockControls2;
46
+ var _api$analytics, _api$blockControls;
32
47
  var tr = _ref3.tr;
33
48
  var payload = {
34
49
  action: _analytics.ACTION.CLICKED,
@@ -42,15 +57,11 @@ var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
42
57
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 || _api$blockControls.moveNodeWithBlockMenu(_types.DIRECTION.DOWN)({
43
58
  tr: tr
44
59
  });
45
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 || _api$blockControls2.toggleBlockMenu({
46
- closeMenu: true
47
- })({
48
- tr: tr
49
- });
50
60
  return tr;
51
61
  });
52
62
  };
53
63
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
64
+ triggerRef: moveDownRef,
54
65
  onClick: handleClick,
55
66
  elemBefore: /*#__PURE__*/_react.default.createElement(_arrowDown.default, {
56
67
  label: ""
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.MoveUpDropdownItem = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
+ var _react = _interopRequireWildcard(require("react"));
9
10
  var _reactIntlNext = require("react-intl-next");
10
11
  var _analytics = require("@atlaskit/editor-common/analytics");
11
12
  var _hooks = require("@atlaskit/editor-common/hooks");
@@ -13,11 +14,16 @@ var _messages = require("@atlaskit/editor-common/messages");
13
14
  var _types = require("@atlaskit/editor-common/types");
14
15
  var _editorToolbar = require("@atlaskit/editor-toolbar");
15
16
  var _arrowUp = _interopRequireDefault(require("@atlaskit/icon/core/arrow-up"));
17
+ var _blockMenuProvider = require("./block-menu-provider");
16
18
  var _consts = require("./consts");
19
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
20
  var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
18
21
  var api = _ref.api;
19
22
  var _useIntl = (0, _reactIntlNext.useIntl)(),
20
23
  formatMessage = _useIntl.formatMessage;
24
+ var _useBlockMenu = (0, _blockMenuProvider.useBlockMenu)(),
25
+ moveFocusTo = _useBlockMenu.moveFocusTo,
26
+ moveUpRef = _useBlockMenu.moveUpRef;
21
27
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (_ref2) {
22
28
  var _blockControlsState$b;
23
29
  var blockControlsState = _ref2.blockControlsState;
@@ -26,9 +32,18 @@ var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
26
32
  };
27
33
  }),
28
34
  canMoveUp = _useSharedPluginState.canMoveUp;
35
+ (0, _react.useEffect)(function () {
36
+ var moveUpElement = moveUpRef.current;
37
+ if (!moveUpElement) {
38
+ return;
39
+ }
40
+ if (!canMoveUp && moveUpElement === document.activeElement) {
41
+ moveFocusTo('moveDown');
42
+ }
43
+ }, [canMoveUp, moveFocusTo, moveUpRef]);
29
44
  var handleClick = function handleClick() {
30
45
  api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
31
- var _api$analytics, _api$blockControls, _api$blockControls2;
46
+ var _api$analytics, _api$blockControls;
32
47
  var tr = _ref3.tr;
33
48
  var payload = {
34
49
  action: _analytics.ACTION.CLICKED,
@@ -42,15 +57,11 @@ var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
42
57
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 || _api$blockControls.moveNodeWithBlockMenu(_types.DIRECTION.UP)({
43
58
  tr: tr
44
59
  });
45
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 || _api$blockControls2.toggleBlockMenu({
46
- closeMenu: true
47
- })({
48
- tr: tr
49
- });
50
60
  return tr;
51
61
  });
52
62
  };
53
63
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
64
+ triggerRef: moveUpRef,
54
65
  onClick: handleClick,
55
66
  elemBefore: /*#__PURE__*/_react.default.createElement(_arrowUp.default, {
56
67
  label: ""
@@ -1,6 +1,9 @@
1
- import React, { useCallback, createContext, useContext } from 'react';
1
+ import React, { useCallback, createContext, useContext, useRef } from 'react';
2
2
  const BlockMenuContext = /*#__PURE__*/createContext({
3
- onDropdownOpenChanged: () => {}
3
+ onDropdownOpenChanged: () => {},
4
+ moveFocusTo: () => {},
5
+ moveDownRef: /*#__PURE__*/React.createRef(),
6
+ moveUpRef: /*#__PURE__*/React.createRef()
4
7
  });
5
8
  export const useBlockMenu = () => {
6
9
  const context = useContext(BlockMenuContext);
@@ -13,6 +16,8 @@ export const BlockMenuProvider = ({
13
16
  children,
14
17
  api
15
18
  }) => {
19
+ const moveUpRef = useRef(null);
20
+ const moveDownRef = useRef(null);
16
21
  const onDropdownOpenChanged = useCallback(isOpen => {
17
22
  if (!isOpen) {
18
23
  // On Dropdown closed, return focus to editor
@@ -23,9 +28,21 @@ export const BlockMenuProvider = ({
23
28
  }), 1);
24
29
  }
25
30
  }, [api]);
31
+ const moveFocusTo = useCallback(direction => {
32
+ if (direction === 'moveUp') {
33
+ var _moveUpRef$current;
34
+ (_moveUpRef$current = moveUpRef.current) === null || _moveUpRef$current === void 0 ? void 0 : _moveUpRef$current.focus();
35
+ } else if (direction === 'moveDown') {
36
+ var _moveDownRef$current;
37
+ (_moveDownRef$current = moveDownRef.current) === null || _moveDownRef$current === void 0 ? void 0 : _moveDownRef$current.focus();
38
+ }
39
+ }, []);
26
40
  return /*#__PURE__*/React.createElement(BlockMenuContext.Provider, {
27
41
  value: {
28
- onDropdownOpenChanged
42
+ onDropdownOpenChanged,
43
+ moveFocusTo,
44
+ moveDownRef,
45
+ moveUpRef
29
46
  }
30
47
  }, children);
31
48
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { useIntl, injectIntl } from 'react-intl-next';
3
3
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
@@ -6,6 +6,7 @@ import { blockMenuMessages as messages } from '@atlaskit/editor-common/messages'
6
6
  import { DIRECTION } from '@atlaskit/editor-common/types';
7
7
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
8
  import ArrowDownIcon from '@atlaskit/icon/core/arrow-down';
9
+ import { useBlockMenu } from './block-menu-provider';
9
10
  import { BLOCK_MENU_ITEM_NAME } from './consts';
10
11
  const MoveDownDropdownItemContent = ({
11
12
  api
@@ -13,6 +14,10 @@ const MoveDownDropdownItemContent = ({
13
14
  const {
14
15
  formatMessage
15
16
  } = useIntl();
17
+ const {
18
+ moveFocusTo,
19
+ moveDownRef
20
+ } = useBlockMenu();
16
21
  const {
17
22
  canMoveDown
18
23
  } = useSharedPluginStateWithSelector(api, ['blockControls'], ({
@@ -23,11 +28,20 @@ const MoveDownDropdownItemContent = ({
23
28
  canMoveDown: blockControlsState === null || blockControlsState === void 0 ? void 0 : (_blockControlsState$b = blockControlsState.blockMenuOptions) === null || _blockControlsState$b === void 0 ? void 0 : _blockControlsState$b.canMoveDown
24
29
  };
25
30
  });
31
+ useEffect(() => {
32
+ const moveDownElement = moveDownRef.current;
33
+ if (!moveDownElement) {
34
+ return;
35
+ }
36
+ if (!canMoveDown && moveDownElement === document.activeElement) {
37
+ moveFocusTo('moveUp');
38
+ }
39
+ }, [canMoveDown, moveFocusTo, moveDownRef]);
26
40
  const handleClick = () => {
27
41
  api === null || api === void 0 ? void 0 : api.core.actions.execute(({
28
42
  tr
29
43
  }) => {
30
- var _api$analytics, _api$analytics$action, _api$blockControls, _api$blockControls$co, _api$blockControls2, _api$blockControls2$c;
44
+ var _api$analytics, _api$analytics$action, _api$blockControls, _api$blockControls$co;
31
45
  const payload = {
32
46
  action: ACTION.CLICKED,
33
47
  actionSubject: ACTION_SUBJECT.BLOCK_MENU_ITEM,
@@ -40,15 +54,11 @@ const MoveDownDropdownItemContent = ({
40
54
  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.moveNodeWithBlockMenu(DIRECTION.DOWN)({
41
55
  tr
42
56
  });
43
- 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.toggleBlockMenu({
44
- closeMenu: true
45
- })({
46
- tr
47
- });
48
57
  return tr;
49
58
  });
50
59
  };
51
60
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
61
+ triggerRef: moveDownRef,
52
62
  onClick: handleClick,
53
63
  elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
54
64
  label: ""
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { useIntl, injectIntl } from 'react-intl-next';
3
3
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
@@ -6,6 +6,7 @@ import { blockMenuMessages as messages } from '@atlaskit/editor-common/messages'
6
6
  import { DIRECTION } from '@atlaskit/editor-common/types';
7
7
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
8
  import ArrowUpIcon from '@atlaskit/icon/core/arrow-up';
9
+ import { useBlockMenu } from './block-menu-provider';
9
10
  import { BLOCK_MENU_ITEM_NAME } from './consts';
10
11
  const MoveUpDropdownItemContent = ({
11
12
  api
@@ -13,6 +14,10 @@ const MoveUpDropdownItemContent = ({
13
14
  const {
14
15
  formatMessage
15
16
  } = useIntl();
17
+ const {
18
+ moveFocusTo,
19
+ moveUpRef
20
+ } = useBlockMenu();
16
21
  const {
17
22
  canMoveUp
18
23
  } = useSharedPluginStateWithSelector(api, ['blockControls'], ({
@@ -23,11 +28,20 @@ const MoveUpDropdownItemContent = ({
23
28
  canMoveUp: blockControlsState === null || blockControlsState === void 0 ? void 0 : (_blockControlsState$b = blockControlsState.blockMenuOptions) === null || _blockControlsState$b === void 0 ? void 0 : _blockControlsState$b.canMoveUp
24
29
  };
25
30
  });
31
+ useEffect(() => {
32
+ const moveUpElement = moveUpRef.current;
33
+ if (!moveUpElement) {
34
+ return;
35
+ }
36
+ if (!canMoveUp && moveUpElement === document.activeElement) {
37
+ moveFocusTo('moveDown');
38
+ }
39
+ }, [canMoveUp, moveFocusTo, moveUpRef]);
26
40
  const handleClick = () => {
27
41
  api === null || api === void 0 ? void 0 : api.core.actions.execute(({
28
42
  tr
29
43
  }) => {
30
- var _api$analytics, _api$analytics$action, _api$blockControls, _api$blockControls$co, _api$blockControls2, _api$blockControls2$c;
44
+ var _api$analytics, _api$analytics$action, _api$blockControls, _api$blockControls$co;
31
45
  const payload = {
32
46
  action: ACTION.CLICKED,
33
47
  actionSubject: ACTION_SUBJECT.BLOCK_MENU_ITEM,
@@ -40,15 +54,11 @@ const MoveUpDropdownItemContent = ({
40
54
  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.moveNodeWithBlockMenu(DIRECTION.UP)({
41
55
  tr
42
56
  });
43
- 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.toggleBlockMenu({
44
- closeMenu: true
45
- })({
46
- tr
47
- });
48
57
  return tr;
49
58
  });
50
59
  };
51
60
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
61
+ triggerRef: moveUpRef,
52
62
  onClick: handleClick,
53
63
  elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
54
64
  label: ""
@@ -1,6 +1,9 @@
1
- import React, { useCallback, createContext, useContext } from 'react';
1
+ import React, { useCallback, createContext, useContext, useRef } from 'react';
2
2
  var BlockMenuContext = /*#__PURE__*/createContext({
3
- onDropdownOpenChanged: function onDropdownOpenChanged() {}
3
+ onDropdownOpenChanged: function onDropdownOpenChanged() {},
4
+ moveFocusTo: function moveFocusTo() {},
5
+ moveDownRef: /*#__PURE__*/React.createRef(),
6
+ moveUpRef: /*#__PURE__*/React.createRef()
4
7
  });
5
8
  export var useBlockMenu = function useBlockMenu() {
6
9
  var context = useContext(BlockMenuContext);
@@ -12,6 +15,8 @@ export var useBlockMenu = function useBlockMenu() {
12
15
  export var BlockMenuProvider = function BlockMenuProvider(_ref) {
13
16
  var children = _ref.children,
14
17
  api = _ref.api;
18
+ var moveUpRef = useRef(null);
19
+ var moveDownRef = useRef(null);
15
20
  var onDropdownOpenChanged = useCallback(function (isOpen) {
16
21
  if (!isOpen) {
17
22
  // On Dropdown closed, return focus to editor
@@ -24,9 +29,21 @@ export var BlockMenuProvider = function BlockMenuProvider(_ref) {
24
29
  }, 1);
25
30
  }
26
31
  }, [api]);
32
+ var moveFocusTo = useCallback(function (direction) {
33
+ if (direction === 'moveUp') {
34
+ var _moveUpRef$current;
35
+ (_moveUpRef$current = moveUpRef.current) === null || _moveUpRef$current === void 0 || _moveUpRef$current.focus();
36
+ } else if (direction === 'moveDown') {
37
+ var _moveDownRef$current;
38
+ (_moveDownRef$current = moveDownRef.current) === null || _moveDownRef$current === void 0 || _moveDownRef$current.focus();
39
+ }
40
+ }, []);
27
41
  return /*#__PURE__*/React.createElement(BlockMenuContext.Provider, {
28
42
  value: {
29
- onDropdownOpenChanged: onDropdownOpenChanged
43
+ onDropdownOpenChanged: onDropdownOpenChanged,
44
+ moveFocusTo: moveFocusTo,
45
+ moveDownRef: moveDownRef,
46
+ moveUpRef: moveUpRef
30
47
  }
31
48
  }, children);
32
49
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { useIntl, injectIntl } from 'react-intl-next';
3
3
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
@@ -6,11 +6,15 @@ import { blockMenuMessages as messages } from '@atlaskit/editor-common/messages'
6
6
  import { DIRECTION } from '@atlaskit/editor-common/types';
7
7
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
8
  import ArrowDownIcon from '@atlaskit/icon/core/arrow-down';
9
+ import { useBlockMenu } from './block-menu-provider';
9
10
  import { BLOCK_MENU_ITEM_NAME } from './consts';
10
11
  var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
11
12
  var api = _ref.api;
12
13
  var _useIntl = useIntl(),
13
14
  formatMessage = _useIntl.formatMessage;
15
+ var _useBlockMenu = useBlockMenu(),
16
+ moveFocusTo = _useBlockMenu.moveFocusTo,
17
+ moveDownRef = _useBlockMenu.moveDownRef;
14
18
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (_ref2) {
15
19
  var _blockControlsState$b;
16
20
  var blockControlsState = _ref2.blockControlsState;
@@ -19,9 +23,18 @@ var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
19
23
  };
20
24
  }),
21
25
  canMoveDown = _useSharedPluginState.canMoveDown;
26
+ useEffect(function () {
27
+ var moveDownElement = moveDownRef.current;
28
+ if (!moveDownElement) {
29
+ return;
30
+ }
31
+ if (!canMoveDown && moveDownElement === document.activeElement) {
32
+ moveFocusTo('moveUp');
33
+ }
34
+ }, [canMoveDown, moveFocusTo, moveDownRef]);
22
35
  var handleClick = function handleClick() {
23
36
  api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
24
- var _api$analytics, _api$blockControls, _api$blockControls2;
37
+ var _api$analytics, _api$blockControls;
25
38
  var tr = _ref3.tr;
26
39
  var payload = {
27
40
  action: ACTION.CLICKED,
@@ -35,15 +48,11 @@ var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
35
48
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 || _api$blockControls.moveNodeWithBlockMenu(DIRECTION.DOWN)({
36
49
  tr: tr
37
50
  });
38
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 || _api$blockControls2.toggleBlockMenu({
39
- closeMenu: true
40
- })({
41
- tr: tr
42
- });
43
51
  return tr;
44
52
  });
45
53
  };
46
54
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
55
+ triggerRef: moveDownRef,
47
56
  onClick: handleClick,
48
57
  elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
49
58
  label: ""
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { useIntl, injectIntl } from 'react-intl-next';
3
3
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
@@ -6,11 +6,15 @@ import { blockMenuMessages as messages } from '@atlaskit/editor-common/messages'
6
6
  import { DIRECTION } from '@atlaskit/editor-common/types';
7
7
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
8
  import ArrowUpIcon from '@atlaskit/icon/core/arrow-up';
9
+ import { useBlockMenu } from './block-menu-provider';
9
10
  import { BLOCK_MENU_ITEM_NAME } from './consts';
10
11
  var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
11
12
  var api = _ref.api;
12
13
  var _useIntl = useIntl(),
13
14
  formatMessage = _useIntl.formatMessage;
15
+ var _useBlockMenu = useBlockMenu(),
16
+ moveFocusTo = _useBlockMenu.moveFocusTo,
17
+ moveUpRef = _useBlockMenu.moveUpRef;
14
18
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (_ref2) {
15
19
  var _blockControlsState$b;
16
20
  var blockControlsState = _ref2.blockControlsState;
@@ -19,9 +23,18 @@ var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
19
23
  };
20
24
  }),
21
25
  canMoveUp = _useSharedPluginState.canMoveUp;
26
+ useEffect(function () {
27
+ var moveUpElement = moveUpRef.current;
28
+ if (!moveUpElement) {
29
+ return;
30
+ }
31
+ if (!canMoveUp && moveUpElement === document.activeElement) {
32
+ moveFocusTo('moveDown');
33
+ }
34
+ }, [canMoveUp, moveFocusTo, moveUpRef]);
22
35
  var handleClick = function handleClick() {
23
36
  api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
24
- var _api$analytics, _api$blockControls, _api$blockControls2;
37
+ var _api$analytics, _api$blockControls;
25
38
  var tr = _ref3.tr;
26
39
  var payload = {
27
40
  action: ACTION.CLICKED,
@@ -35,15 +48,11 @@ var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
35
48
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 || _api$blockControls.moveNodeWithBlockMenu(DIRECTION.UP)({
36
49
  tr: tr
37
50
  });
38
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 || _api$blockControls2.toggleBlockMenu({
39
- closeMenu: true
40
- })({
41
- tr: tr
42
- });
43
51
  return tr;
44
52
  });
45
53
  };
46
54
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
55
+ triggerRef: moveUpRef,
47
56
  onClick: handleClick,
48
57
  elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
49
58
  label: ""
@@ -1,11 +1,19 @@
1
1
  import React from 'react';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { BlockMenuPlugin } from '../blockMenuPluginType';
4
+ export type Direction = 'moveUp' | 'moveDown';
4
5
  type BlockMenuProviderProps = {
5
6
  api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
6
7
  children: React.ReactNode;
7
8
  };
8
9
  export type BlockMenuContextType = {
10
+ moveDownRef: React.MutableRefObject<HTMLButtonElement | null>;
11
+ /**
12
+ * Function to move focus between move up and move down items.
13
+ * Used when one item is disabled and focused.
14
+ */
15
+ moveFocusTo: (direction: Direction) => void;
16
+ moveUpRef: React.MutableRefObject<HTMLButtonElement | null>;
9
17
  /**
10
18
  * Callback for when the dropdown is open/closed. Receives an object with `isOpen` state.
11
19
  *
@@ -1,11 +1,19 @@
1
1
  import React from 'react';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { BlockMenuPlugin } from '../blockMenuPluginType';
4
+ export type Direction = 'moveUp' | 'moveDown';
4
5
  type BlockMenuProviderProps = {
5
6
  api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
6
7
  children: React.ReactNode;
7
8
  };
8
9
  export type BlockMenuContextType = {
10
+ moveDownRef: React.MutableRefObject<HTMLButtonElement | null>;
11
+ /**
12
+ * Function to move focus between move up and move down items.
13
+ * Used when one item is disabled and focused.
14
+ */
15
+ moveFocusTo: (direction: Direction) => void;
16
+ moveUpRef: React.MutableRefObject<HTMLButtonElement | null>;
9
17
  /**
10
18
  * Callback for when the dropdown is open/closed. Receives an object with `isOpen` state.
11
19
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "5.1.8",
3
+ "version": "5.1.9",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,7 +44,7 @@
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^16.4.0",
47
- "@atlaskit/tmp-editor-statsig": "^14.8.0",
47
+ "@atlaskit/tmp-editor-statsig": "^14.9.0",
48
48
  "@atlaskit/tokens": "^8.4.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },