@atlaskit/editor-plugin-block-menu 0.0.5 → 0.0.7

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-dev-agents/tsconfig.json +3 -0
  4. package/afm-jira/tsconfig.json +3 -0
  5. package/afm-passionfruit/tsconfig.json +3 -0
  6. package/afm-post-office/tsconfig.json +3 -0
  7. package/afm-rovo-extension/tsconfig.json +3 -0
  8. package/afm-townsquare/tsconfig.json +3 -0
  9. package/dist/cjs/blockMenuPlugin.js +1 -1
  10. package/dist/cjs/ui/block-menu-components.js +65 -37
  11. package/dist/cjs/ui/block-menu.js +25 -10
  12. package/dist/cjs/ui/copy-block.js +82 -0
  13. package/dist/cjs/ui/move-down.js +50 -0
  14. package/dist/cjs/ui/move-up.js +50 -0
  15. package/dist/es2019/blockMenuPlugin.js +1 -1
  16. package/dist/es2019/ui/block-menu-components.js +60 -36
  17. package/dist/es2019/ui/block-menu.js +27 -11
  18. package/dist/es2019/ui/copy-block.js +75 -0
  19. package/dist/es2019/ui/move-down.js +48 -0
  20. package/dist/es2019/ui/move-up.js +48 -0
  21. package/dist/esm/blockMenuPlugin.js +1 -1
  22. package/dist/esm/ui/block-menu-components.js +65 -37
  23. package/dist/esm/ui/block-menu.js +26 -11
  24. package/dist/esm/ui/copy-block.js +75 -0
  25. package/dist/esm/ui/move-down.js +43 -0
  26. package/dist/esm/ui/move-up.js +43 -0
  27. package/dist/types/blockMenuPluginType.d.ts +6 -1
  28. package/dist/types/ui/block-menu-components.d.ts +3 -1
  29. package/dist/types/ui/copy-block.d.ts +11 -0
  30. package/dist/types/ui/move-down.d.ts +11 -0
  31. package/dist/types/ui/move-up.d.ts +11 -0
  32. package/dist/types-ts4.5/blockMenuPluginType.d.ts +3 -1
  33. package/dist/types-ts4.5/ui/block-menu-components.d.ts +3 -1
  34. package/dist/types-ts4.5/ui/copy-block.d.ts +11 -0
  35. package/dist/types-ts4.5/ui/move-down.d.ts +11 -0
  36. package/dist/types-ts4.5/ui/move-up.d.ts +11 -0
  37. package/package.json +5 -4
  38. package/tsconfig.json +1 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 0.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`31fc6b9e10762`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/31fc6b9e10762) -
8
+ [ux] ED-28592 ED-28592:Add copy block menu item to block menu
9
+ - Updated dependencies
10
+
11
+ ## 0.0.6
12
+
13
+ ### Patch Changes
14
+
15
+ - [`353075175e7ff`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/353075175e7ff) -
16
+ [ux] ED-28584 Register move up and down options in block menu
17
+ - Updated dependencies
18
+
3
19
  ## 0.0.5
4
20
 
5
21
  ### Patch Changes
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-cc/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-cc/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-cc/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-dev-agents/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-dev-agents/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-dev-agents/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-jira/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-jira/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-jira/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-passionfruit/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-passionfruit/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-passionfruit/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-post-office/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-post-office/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-post-office/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-rovo-extension/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-rovo-extension/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-rovo-extension/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-shared-styles/afm-townsquare/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-tables/afm-townsquare/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-toolbar/afm-townsquare/tsconfig.json"
37
40
  },
@@ -13,7 +13,7 @@ var _blockMenuComponents = require("./ui/block-menu-components");
13
13
  var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
14
14
  var api = _ref.api;
15
15
  var registry = (0, _editorActions.createBlockMenuRegistry)();
16
- registry.register((0, _blockMenuComponents.getBlockMenuComponents)());
16
+ registry.register((0, _blockMenuComponents.getBlockMenuComponents)(api));
17
17
  return {
18
18
  name: 'blockMenu',
19
19
  pmPlugins: function pmPlugins() {
@@ -5,17 +5,52 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.getBlockMenuComponents = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _react = _interopRequireDefault(require("react"));
9
10
  var _editorToolbar = require("@atlaskit/editor-toolbar");
10
11
  var _jira = _interopRequireDefault(require("@atlaskit/icon-lab/core/jira"));
11
- var _arrowDown = _interopRequireDefault(require("@atlaskit/icon/core/arrow-down"));
12
- var _arrowUp = _interopRequireDefault(require("@atlaskit/icon/core/arrow-up"));
13
12
  var _changes = _interopRequireDefault(require("@atlaskit/icon/core/changes"));
14
13
  var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
15
14
  var _delete = _interopRequireDefault(require("@atlaskit/icon/core/delete"));
16
15
  var _listBulleted = _interopRequireDefault(require("@atlaskit/icon/core/list-bulleted"));
17
16
  var _task = _interopRequireDefault(require("@atlaskit/icon/core/task"));
18
- var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents() {
17
+ var _copyBlock = _interopRequireDefault(require("./copy-block"));
18
+ var _moveDown = require("./move-down");
19
+ var _moveUp = require("./move-up");
20
+ var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
21
+ var _api$blockControls;
22
+ if (!(api !== null && api !== void 0 && (_api$blockControls = api.blockControls) !== null && _api$blockControls !== void 0 && _api$blockControls.commands.moveNode)) {
23
+ return [];
24
+ }
25
+ return [{
26
+ type: 'block-menu-item',
27
+ key: 'block-menu-item-move-up',
28
+ parent: {
29
+ type: 'block-menu-section',
30
+ key: 'block-menu-section-move-up-down',
31
+ rank: 100
32
+ },
33
+ component: function component() {
34
+ return /*#__PURE__*/_react.default.createElement(_moveUp.MoveUpDropdownItem, {
35
+ api: api
36
+ });
37
+ }
38
+ }, {
39
+ type: 'block-menu-item',
40
+ key: 'block-menu-item-move-down',
41
+ parent: {
42
+ type: 'block-menu-section',
43
+ key: 'block-menu-section-move-up-down',
44
+ rank: 200
45
+ },
46
+ component: function component() {
47
+ return /*#__PURE__*/_react.default.createElement(_moveDown.MoveDownDropdownItem, {
48
+ api: api
49
+ });
50
+ }
51
+ }];
52
+ };
53
+ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(api) {
19
54
  return [{
20
55
  type: 'block-menu-section',
21
56
  key: 'block-menu-section-format',
@@ -26,7 +61,7 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
26
61
  }
27
62
  }, {
28
63
  type: 'block-menu-section',
29
- key: 'block-menu-section-move-up-down',
64
+ key: 'block-menu-section-copy',
30
65
  rank: 200,
31
66
  component: function component(_ref2) {
32
67
  var children = _ref2.children;
@@ -34,9 +69,22 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
34
69
  hasSeparator: true
35
70
  }, children);
36
71
  }
72
+ }, {
73
+ type: 'block-menu-item',
74
+ key: 'block-menu-copy-block',
75
+ parent: {
76
+ type: 'block-menu-section',
77
+ key: 'block-menu-section-copy',
78
+ rank: 200
79
+ },
80
+ component: function component() {
81
+ return /*#__PURE__*/_react.default.createElement(_copyBlock.default, {
82
+ api: api
83
+ });
84
+ }
37
85
  }, {
38
86
  type: 'block-menu-section',
39
- key: 'block-menu-section-delete',
87
+ key: 'block-menu-section-move-up-down',
40
88
  rank: 300,
41
89
  component: function component(_ref3) {
42
90
  var children = _ref3.children;
@@ -44,6 +92,16 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
44
92
  hasSeparator: true
45
93
  }, children);
46
94
  }
95
+ }, {
96
+ type: 'block-menu-section',
97
+ key: 'block-menu-section-delete',
98
+ rank: 400,
99
+ component: function component(_ref4) {
100
+ var children = _ref4.children;
101
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
102
+ hasSeparator: true
103
+ }, children);
104
+ }
47
105
  }, {
48
106
  type: 'block-menu-nested',
49
107
  key: 'nested-menu',
@@ -86,37 +144,7 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
86
144
  })
87
145
  }, "Create Jira work item");
88
146
  }
89
- }, {
90
- type: 'block-menu-item',
91
- key: 'block-menu-item-move-up',
92
- parent: {
93
- type: 'block-menu-section',
94
- key: 'block-menu-section-move-up-down',
95
- rank: 100
96
- },
97
- component: function component() {
98
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
99
- elemBefore: /*#__PURE__*/_react.default.createElement(_arrowUp.default, {
100
- label: ""
101
- })
102
- }, "Move up");
103
- }
104
- }, {
105
- type: 'block-menu-item',
106
- key: 'block-menu-item-move-down',
107
- parent: {
108
- type: 'block-menu-section',
109
- key: 'block-menu-section-move-up-down',
110
- rank: 200
111
- },
112
- component: function component() {
113
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
114
- elemBefore: /*#__PURE__*/_react.default.createElement(_arrowDown.default, {
115
- label: ""
116
- })
117
- }, "Move down");
118
- }
119
- }, {
147
+ }].concat((0, _toConsumableArray2.default)(getMoveUpMoveDownMenuComponents(api)), [{
120
148
  type: 'block-menu-item',
121
149
  key: 'block-menu-item-delete',
122
150
  parent: {
@@ -131,5 +159,5 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
131
159
  })
132
160
  }, "Delete");
133
161
  }
134
- }];
162
+ }]);
135
163
  };
@@ -12,6 +12,7 @@ var _react = _interopRequireWildcard(require("react"));
12
12
  var _reactIntlNext = require("react-intl-next");
13
13
  var _css = require("@atlaskit/css");
14
14
  var _hooks = require("@atlaskit/editor-common/hooks");
15
+ var _styles = require("@atlaskit/editor-common/styles");
15
16
  var _ui = require("@atlaskit/editor-common/ui");
16
17
  var _uiReact = require("@atlaskit/editor-common/ui-react");
17
18
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
@@ -22,9 +23,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
22
23
  var styles = {
23
24
  base: "_2rkoglpi _bfhk1bhr _16qs1cd0"
24
25
  };
25
- var DRAG_HANDLE_SELECTOR = '[data-editor-block-ctrl-drag-handle=true]';
26
- var DRAG_HANDLE_WIDTH = 12;
27
- var DRAG_HANDLE_PADDING = 5;
26
+ var DRAG_HANDLE_OFFSET_PADDING = 5;
28
27
  var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
29
28
  var BlockMenuContent = function BlockMenuContent(_ref) {
30
29
  var _api$blockMenu;
@@ -75,20 +74,36 @@ var BlockMenu = function BlockMenu(_ref2) {
75
74
  currentUserIntent = _useSharedPluginState.currentUserIntent;
76
75
  var hasFocus = (_editorView$hasFocus = editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) !== null && _editorView$hasFocus !== void 0 ? _editorView$hasFocus : false;
77
76
  var hasSelection = !!editorView && !editorView.state.selection.empty;
77
+ (0, _react.useEffect)(function () {
78
+ var _api$userIntent;
79
+ if (!isMenuOpen || !menuTriggerBy || !isSelectedViaDragHandle || !hasFocus || !hasSelection || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
80
+ return;
81
+ }
82
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent('blockMenuOpen'));
83
+ }, [api, isMenuOpen, menuTriggerBy, isSelectedViaDragHandle, hasFocus, hasSelection, currentUserIntent]);
78
84
  if (!isMenuOpen) {
79
85
  return null;
80
86
  }
81
87
  var closeMenu = function closeMenu() {
82
- var _api$blockControls;
83
- api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.toggleBlockMenu({
84
- closeMenu: true
85
- }));
88
+ api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
89
+ var _api$blockControls, _api$userIntent2;
90
+ var tr = _ref3.tr;
91
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.toggleBlockMenu({
92
+ closeMenu: true
93
+ })({
94
+ tr: tr
95
+ });
96
+ api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent(currentUserIntent === 'blockMenuOpen' ? 'default' : currentUserIntent || 'default')({
97
+ tr: tr
98
+ });
99
+ return tr;
100
+ });
86
101
  };
87
- if (!menuTriggerBy || !isSelectedViaDragHandle || !hasFocus || !hasSelection || currentUserIntent === 'dragging') {
102
+ if (!menuTriggerBy || !isSelectedViaDragHandle || !hasFocus || !hasSelection || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
88
103
  closeMenu();
89
104
  return null;
90
105
  }
91
- var targetHandleRef = (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
106
+ 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);
92
107
  if (targetHandleRef instanceof HTMLElement) {
93
108
  return /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
94
109
  alignX: 'left',
@@ -102,7 +117,7 @@ var BlockMenu = function BlockMenu(_ref2) {
102
117
  zIndex: _editorSharedStyles.akEditorFloatingOverlapPanelZIndex,
103
118
  forcePlacement: true,
104
119
  stick: true,
105
- offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_PADDING, 0]
120
+ offset: [_styles.DRAG_HANDLE_WIDTH + DRAG_HANDLE_OFFSET_PADDING, 0]
106
121
  }, /*#__PURE__*/_react.default.createElement(BlockMenuContent, {
107
122
  api: api
108
123
  }));
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _blockMenu = require("@atlaskit/editor-common/block-menu");
11
+ var _clipboard = require("@atlaskit/editor-common/clipboard");
12
+ var _copyButton = require("@atlaskit/editor-common/copy-button");
13
+ var _model = require("@atlaskit/editor-prosemirror/model");
14
+ var _state = require("@atlaskit/editor-prosemirror/state");
15
+ var _utils = require("@atlaskit/editor-tables/utils");
16
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
17
+ var _copy = _interopRequireDefault(require("@atlaskit/icon/core/copy"));
18
+ var toDOMFromFragment = function toDOMFromFragment(fragment, schema) {
19
+ return _model.DOMSerializer.fromSchema(schema).serializeFragment(fragment);
20
+ };
21
+ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
22
+ var api = _ref.api;
23
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
24
+ formatMessage = _useIntl.formatMessage;
25
+ var copyHandler = function copyHandler(event) {
26
+ var _api$selection;
27
+ // prevent click event from bubbling up to the ancestor elements
28
+ event.stopPropagation();
29
+ // get the current selection
30
+ var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
31
+ if (selection) {
32
+ var schema = selection.$from.doc.type.schema;
33
+ // for texts and inline nodes
34
+ if (selection instanceof _state.TextSelection) {
35
+ var _fragment;
36
+ var fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
37
+ if (!fragment) {
38
+ return;
39
+ }
40
+ // if text is inside of a layout column, the selection contains the layoutSection and layoutColumn for some reason
41
+ // But the layoutSection only contains the layoutColumn that the selected text is in, hence we can use the .firstChild
42
+ if ((_fragment = fragment) !== null && _fragment !== void 0 && _fragment.firstChild && fragment.firstChild.type.name === 'layoutSection') {
43
+ var layoutSectionNode = fragment.firstChild;
44
+ var layoutColumnNode = layoutSectionNode.firstChild;
45
+ var layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
46
+ fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || _model.Fragment.empty;
47
+ }
48
+ var domNode = toDOMFromFragment(fragment, schema);
49
+ var div = document.createElement('div');
50
+ div.appendChild(domNode);
51
+ (0, _clipboard.copyHTMLToClipboard)(div);
52
+ }
53
+
54
+ // for table
55
+ if ((0, _utils.isTableSelected)(selection)) {
56
+ var nodeType = schema.nodes.table;
57
+ var tableNode = selection.$anchorCell.node(-1);
58
+ if (!tableNode) {
59
+ return;
60
+ }
61
+ var _domNode = (0, _copyButton.toDOM)(tableNode, schema);
62
+ (0, _copyButton.copyDomNode)(_domNode, nodeType, selection);
63
+ }
64
+
65
+ // for other nodes
66
+ if (selection instanceof _state.NodeSelection) {
67
+ var _nodeType = selection.node.type;
68
+ var _domNode2 = (0, _copyButton.toDOM)(selection.node, schema);
69
+ (0, _copyButton.copyDomNode)(_domNode2, _nodeType, selection);
70
+ }
71
+ }
72
+ };
73
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
74
+ elemBefore: /*#__PURE__*/_react.default.createElement(_copy.default, {
75
+ label: ""
76
+ }),
77
+ onClick: function onClick(e) {
78
+ return copyHandler(e);
79
+ }
80
+ }, formatMessage(_blockMenu.messages.copyBlock));
81
+ };
82
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(CopyBlockMenuItem);
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MoveDownDropdownItem = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _types = require("@atlaskit/editor-common/types");
13
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
14
+ var _arrowDown = _interopRequireDefault(require("@atlaskit/icon/core/arrow-down"));
15
+ var MoveDownDropdownItemContent = function MoveDownDropdownItemContent(_ref) {
16
+ var api = _ref.api;
17
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
18
+ formatMessage = _useIntl.formatMessage;
19
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (_ref2) {
20
+ var _blockControlsState$b;
21
+ var blockControlsState = _ref2.blockControlsState;
22
+ return {
23
+ canMoveDown: blockControlsState === null || blockControlsState === void 0 || (_blockControlsState$b = blockControlsState.blockMenuOptions) === null || _blockControlsState$b === void 0 ? void 0 : _blockControlsState$b.canMoveDown
24
+ };
25
+ }),
26
+ canMoveDown = _useSharedPluginState.canMoveDown;
27
+ var handleClick = function handleClick() {
28
+ api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
29
+ var _api$blockControls, _api$blockControls2;
30
+ var tr = _ref3.tr;
31
+ 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)({
32
+ tr: tr
33
+ });
34
+ 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({
35
+ closeMenu: true
36
+ })({
37
+ tr: tr
38
+ });
39
+ return tr;
40
+ });
41
+ };
42
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
43
+ onClick: handleClick,
44
+ elemBefore: /*#__PURE__*/_react.default.createElement(_arrowDown.default, {
45
+ label: ""
46
+ }),
47
+ isDisabled: !canMoveDown
48
+ }, formatMessage(_messages.blockMenuMessages.moveDownBlock));
49
+ };
50
+ var MoveDownDropdownItem = exports.MoveDownDropdownItem = (0, _reactIntlNext.injectIntl)(MoveDownDropdownItemContent);
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MoveUpDropdownItem = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _types = require("@atlaskit/editor-common/types");
13
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
14
+ var _arrowUp = _interopRequireDefault(require("@atlaskit/icon/core/arrow-up"));
15
+ var MoveUpDropdownItemContent = function MoveUpDropdownItemContent(_ref) {
16
+ var api = _ref.api;
17
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
18
+ formatMessage = _useIntl.formatMessage;
19
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (_ref2) {
20
+ var _blockControlsState$b;
21
+ var blockControlsState = _ref2.blockControlsState;
22
+ return {
23
+ canMoveUp: blockControlsState === null || blockControlsState === void 0 || (_blockControlsState$b = blockControlsState.blockMenuOptions) === null || _blockControlsState$b === void 0 ? void 0 : _blockControlsState$b.canMoveUp
24
+ };
25
+ }),
26
+ canMoveUp = _useSharedPluginState.canMoveUp;
27
+ var handleClick = function handleClick() {
28
+ api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
29
+ var _api$blockControls, _api$blockControls2;
30
+ var tr = _ref3.tr;
31
+ 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)({
32
+ tr: tr
33
+ });
34
+ 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({
35
+ closeMenu: true
36
+ })({
37
+ tr: tr
38
+ });
39
+ return tr;
40
+ });
41
+ };
42
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
43
+ onClick: handleClick,
44
+ elemBefore: /*#__PURE__*/_react.default.createElement(_arrowUp.default, {
45
+ label: ""
46
+ }),
47
+ isDisabled: !canMoveUp
48
+ }, formatMessage(_messages.blockMenuMessages.moveUpBlock));
49
+ };
50
+ var MoveUpDropdownItem = exports.MoveUpDropdownItem = (0, _reactIntlNext.injectIntl)(MoveUpDropdownItemContent);
@@ -7,7 +7,7 @@ export const blockMenuPlugin = ({
7
7
  api
8
8
  }) => {
9
9
  const registry = createBlockMenuRegistry();
10
- registry.register(getBlockMenuComponents());
10
+ registry.register(getBlockMenuComponents(api));
11
11
  return {
12
12
  name: 'blockMenu',
13
13
  pmPlugins() {
@@ -1,14 +1,44 @@
1
1
  import React from 'react';
2
2
  import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
3
3
  import JiraIcon from '@atlaskit/icon-lab/core/jira';
4
- import ArrowDownIcon from '@atlaskit/icon/core/arrow-down';
5
- import ArrowUpIcon from '@atlaskit/icon/core/arrow-up';
6
4
  import ChangesIcon from '@atlaskit/icon/core/changes';
7
5
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
8
6
  import DeleteIcon from '@atlaskit/icon/core/delete';
9
7
  import ListBulletedIcon from '@atlaskit/icon/core/list-bulleted';
10
8
  import TaskIcon from '@atlaskit/icon/core/task';
11
- export const getBlockMenuComponents = () => {
9
+ import CopyBlockMenuItem from './copy-block';
10
+ import { MoveDownDropdownItem } from './move-down';
11
+ import { MoveUpDropdownItem } from './move-up';
12
+ const getMoveUpMoveDownMenuComponents = api => {
13
+ var _api$blockControls;
14
+ if (!(api !== null && api !== void 0 && (_api$blockControls = api.blockControls) !== null && _api$blockControls !== void 0 && _api$blockControls.commands.moveNode)) {
15
+ return [];
16
+ }
17
+ return [{
18
+ type: 'block-menu-item',
19
+ key: 'block-menu-item-move-up',
20
+ parent: {
21
+ type: 'block-menu-section',
22
+ key: 'block-menu-section-move-up-down',
23
+ rank: 100
24
+ },
25
+ component: () => /*#__PURE__*/React.createElement(MoveUpDropdownItem, {
26
+ api: api
27
+ })
28
+ }, {
29
+ type: 'block-menu-item',
30
+ key: 'block-menu-item-move-down',
31
+ parent: {
32
+ type: 'block-menu-section',
33
+ key: 'block-menu-section-move-up-down',
34
+ rank: 200
35
+ },
36
+ component: () => /*#__PURE__*/React.createElement(MoveDownDropdownItem, {
37
+ api: api
38
+ })
39
+ }];
40
+ };
41
+ export const getBlockMenuComponents = api => {
12
42
  return [{
13
43
  type: 'block-menu-section',
14
44
  key: 'block-menu-section-format',
@@ -20,7 +50,7 @@ export const getBlockMenuComponents = () => {
20
50
  }
21
51
  }, {
22
52
  type: 'block-menu-section',
23
- key: 'block-menu-section-move-up-down',
53
+ key: 'block-menu-section-copy',
24
54
  rank: 200,
25
55
  component: ({
26
56
  children
@@ -29,9 +59,22 @@ export const getBlockMenuComponents = () => {
29
59
  hasSeparator: true
30
60
  }, children);
31
61
  }
62
+ }, {
63
+ type: 'block-menu-item',
64
+ key: 'block-menu-copy-block',
65
+ parent: {
66
+ type: 'block-menu-section',
67
+ key: 'block-menu-section-copy',
68
+ rank: 200
69
+ },
70
+ component: () => {
71
+ return /*#__PURE__*/React.createElement(CopyBlockMenuItem, {
72
+ api: api
73
+ });
74
+ }
32
75
  }, {
33
76
  type: 'block-menu-section',
34
- key: 'block-menu-section-delete',
77
+ key: 'block-menu-section-move-up-down',
35
78
  rank: 300,
36
79
  component: ({
37
80
  children
@@ -40,6 +83,17 @@ export const getBlockMenuComponents = () => {
40
83
  hasSeparator: true
41
84
  }, children);
42
85
  }
86
+ }, {
87
+ type: 'block-menu-section',
88
+ key: 'block-menu-section-delete',
89
+ rank: 400,
90
+ component: ({
91
+ children
92
+ }) => {
93
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
94
+ hasSeparator: true
95
+ }, children);
96
+ }
43
97
  }, {
44
98
  type: 'block-menu-nested',
45
99
  key: 'nested-menu',
@@ -82,37 +136,7 @@ export const getBlockMenuComponents = () => {
82
136
  })
83
137
  }, "Create Jira work item");
84
138
  }
85
- }, {
86
- type: 'block-menu-item',
87
- key: 'block-menu-item-move-up',
88
- parent: {
89
- type: 'block-menu-section',
90
- key: 'block-menu-section-move-up-down',
91
- rank: 100
92
- },
93
- component: () => {
94
- return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
95
- elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
96
- label: ""
97
- })
98
- }, "Move up");
99
- }
100
- }, {
101
- type: 'block-menu-item',
102
- key: 'block-menu-item-move-down',
103
- parent: {
104
- type: 'block-menu-section',
105
- key: 'block-menu-section-move-up-down',
106
- rank: 200
107
- },
108
- component: () => {
109
- return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
110
- elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
111
- label: ""
112
- })
113
- }, "Move down");
114
- }
115
- }, {
139
+ }, ...getMoveUpMoveDownMenuComponents(api), {
116
140
  type: 'block-menu-item',
117
141
  key: 'block-menu-item-delete',
118
142
  parent: {