@atlaskit/editor-plugin-block-menu 6.0.20 → 6.0.21

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,15 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 6.0.21
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b30d6077b3e91`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b30d6077b3e91) -
8
+ [ux] Suggested section should be hidden when total number to native transfroms is less than 7.
9
+ - [`265980d7959cf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/265980d7959cf) -
10
+ [ux] recursive node decoration and 'selected danger' classname
11
+ - Updated dependencies
12
+
3
13
  ## 6.0.20
4
14
 
5
15
  ### Patch Changes
@@ -69,6 +69,9 @@
69
69
  {
70
70
  "path": "../../../design-system/primitives/afm-jira/tsconfig.json"
71
71
  },
72
+ {
73
+ "path": "../../prosemirror-history/afm-jira/tsconfig.json"
74
+ },
72
75
  {
73
76
  "path": "../../tmp-editor-statsig/afm-jira/tsconfig.json"
74
77
  },
@@ -69,6 +69,9 @@
69
69
  {
70
70
  "path": "../../../design-system/primitives/afm-products/tsconfig.json"
71
71
  },
72
+ {
73
+ "path": "../../prosemirror-history/afm-products/tsconfig.json"
74
+ },
72
75
  {
73
76
  "path": "../../tmp-editor-statsig/afm-products/tsconfig.json"
74
77
  },
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.transformNode = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
7
  var _analytics = require("@atlaskit/editor-common/analytics");
10
8
  var _performanceMeasures = require("@atlaskit/editor-common/performance-measures");
11
9
  var _selection = require("@atlaskit/editor-common/selection");
@@ -33,10 +31,7 @@ var transformNode = exports.transformNode = function transformNode(api) {
33
31
  var isParentLayout = selectedParent.type === nodes.layoutColumn;
34
32
  var isNested = (0, _isNestedNode.isNestedNode)(preservedSelection, '') && !isParentLayout;
35
33
  var isList = (0, _utils.isListNode)(selectedParent);
36
- var sliceStart = isList ? $from.pos - 1 : $from.pos;
37
- var sliceEnd = isList ? $to.pos + 1 : $to.pos;
38
- var slice = tr.doc.slice(sliceStart, sliceEnd);
39
- var sourceNodes = (0, _toConsumableArray2.default)(slice.content.content);
34
+ var sourceNodes = (0, _selection.getSourceNodesFromSelectionRange)(tr, preservedSelection);
40
35
  var sourceNodeTypes = {};
41
36
  sourceNodes.forEach(function (node) {
42
37
  var typeName = node.type.name;
@@ -50,7 +45,8 @@ var transformNode = exports.transformNode = function transformNode(api) {
50
45
  targetAttrs: metadata === null || metadata === void 0 ? void 0 : metadata.targetAttrs,
51
46
  parentNode: selectedParent
52
47
  });
53
- var content = resultNodes.length > 0 ? resultNodes : slice.content;
48
+ var content = resultNodes.length > 0 ? resultNodes : sourceNodes;
49
+ var sliceStart = isList ? $from.pos - 1 : $from.pos;
54
50
  if (preservedSelection instanceof _state.NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
55
51
  var _api$blockControls2;
56
52
  // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
@@ -65,10 +61,12 @@ var transformNode = exports.transformNode = function transformNode(api) {
65
61
  // when we replace and insert content, we need to manually map the preserved selection
66
62
  // through the transaction, otherwise it will treat the selection as having been deleted
67
63
  // and stop preserving it
68
- var oldSize = slice.size;
69
- var newSize = Array.isArray(content) ? content.reduce(function (sum, node) {
64
+ var oldSize = sourceNodes.reduce(function (sum, node) {
65
+ return sum + node.nodeSize;
66
+ }, 0);
67
+ var newSize = content.reduce(function (sum, node) {
70
68
  return sum + node.nodeSize;
71
- }, 0) : content.size;
69
+ }, 0);
72
70
  api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.mapPreservedSelection(new _transform.Mapping([new _transform.StepMap([0, oldSize, newSize])]))({
73
71
  tr: tr
74
72
  });
@@ -9,6 +9,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _blockMenu = require("@atlaskit/editor-common/block-menu");
11
11
  var _editorToolbar = require("@atlaskit/editor-toolbar");
12
+ var _utils = require("./block-menu-renderer/utils");
12
13
  var _copyLink = require("./copy-link");
13
14
  var _copySection = require("./copy-section");
14
15
  var _deleteButton = require("./delete-button");
@@ -21,6 +22,20 @@ var _suggestedItemsMenuSection = require("./suggested-items-menu-section");
21
22
  var _suggestedMenuItems = require("./suggested-menu-items");
22
23
  var _createMenuItemsMap = require("./utils/createMenuItemsMap");
23
24
  var _getSuggestedItemsFromSelection = require("./utils/getSuggestedItemsFromSelection");
25
+ var MIN_NUMBER_OF_AVAILABLE_NATIVE_TRANSFORMS = 7;
26
+ var getTotalNumberOfAvailableNativeTransforms = function getTotalNumberOfAvailableNativeTransforms(blockMenuComponents) {
27
+ if (!blockMenuComponents) {
28
+ return 0;
29
+ }
30
+ var childrenMap = (0, _utils.buildChildrenMap)(blockMenuComponents);
31
+ var headingsKey = (0, _utils.getChildrenMapKey)(_blockMenu.TRANSFORM_HEADINGS_MENU_SECTION.key, 'block-menu-section');
32
+ var structureKey = (0, _utils.getChildrenMapKey)(_blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION.key, 'block-menu-section');
33
+ var headingsChildren = childrenMap.get(headingsKey) || [];
34
+ var structureChildren = childrenMap.get(structureKey) || [];
35
+ return [].concat((0, _toConsumableArray2.default)(headingsChildren), (0, _toConsumableArray2.default)(structureChildren)).filter(function (c) {
36
+ return (0, _utils.willComponentRender)(c, childrenMap);
37
+ }).length;
38
+ };
24
39
  var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
25
40
  return [{
26
41
  type: 'block-menu-item',
@@ -101,6 +116,9 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
101
116
  isHidden: function isHidden() {
102
117
  var _api$blockMenu, _api$selection, _api$blockControls;
103
118
  var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
119
+ if (getTotalNumberOfAvailableNativeTransforms(blockMenuComponents) < MIN_NUMBER_OF_AVAILABLE_NATIVE_TRANSFORMS) {
120
+ return true;
121
+ }
104
122
  var menuItemsMap = (0, _createMenuItemsMap.createMenuItemsMap)(blockMenuComponents);
105
123
  var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
106
124
  var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
@@ -18,11 +18,9 @@ var _text = _interopRequireDefault(require("@atlaskit/primitives/text"));
18
18
  var _consts = require("./consts");
19
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); }
20
20
  var DeleteDropdownItemContent = function DeleteDropdownItemContent(_ref) {
21
- var _api$core$sharedState;
22
21
  var api = _ref.api;
23
22
  var _useIntl = (0, _reactIntlNext.useIntl)(),
24
23
  formatMessage = _useIntl.formatMessage;
25
- var nodeTypes = Object.values((api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 || (_api$core$sharedState = _api$core$sharedState.schema) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.nodes) || {});
26
24
  var onClick = function onClick() {
27
25
  api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
28
26
  var _api$analytics, _api$blockControls, _api$blockControls2;
@@ -51,14 +49,13 @@ var DeleteDropdownItemContent = function DeleteDropdownItemContent(_ref) {
51
49
  var _api$decorations, _api$decorations$hove;
52
50
  var tr = _ref3.tr;
53
51
  api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 || (_api$decorations = _api$decorations.commands) === null || _api$decorations === void 0 || (_api$decorations$hove = _api$decorations.hoverDecoration) === null || _api$decorations$hove === void 0 || _api$decorations$hove.call(_api$decorations, {
54
- nodeType: nodeTypes,
55
52
  add: true
56
53
  })({
57
54
  tr: tr
58
55
  });
59
56
  return tr;
60
57
  });
61
- }, [api, nodeTypes]);
58
+ }, [api]);
62
59
  var onRemoveHoverDecoration = (0, _react.useCallback)(function () {
63
60
  api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
64
61
  var _api$decorations2, _api$decorations2$rem;
@@ -1,6 +1,6 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
3
- import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
3
+ import { expandSelectionToBlockRange, getSourceNodesFromSelectionRange } from '@atlaskit/editor-common/selection';
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
6
6
  import { isNestedNode } from '../ui/utils/isNestedNode';
@@ -27,10 +27,7 @@ export const transformNode = api => (targetType, metadata) => ({
27
27
  const isParentLayout = selectedParent.type === nodes.layoutColumn;
28
28
  const isNested = isNestedNode(preservedSelection, '') && !isParentLayout;
29
29
  const isList = isListNode(selectedParent);
30
- const sliceStart = isList ? $from.pos - 1 : $from.pos;
31
- const sliceEnd = isList ? $to.pos + 1 : $to.pos;
32
- const slice = tr.doc.slice(sliceStart, sliceEnd);
33
- const sourceNodes = [...slice.content.content];
30
+ const sourceNodes = getSourceNodesFromSelectionRange(tr, preservedSelection);
34
31
  const sourceNodeTypes = {};
35
32
  sourceNodes.forEach(node => {
36
33
  const typeName = node.type.name;
@@ -44,7 +41,8 @@ export const transformNode = api => (targetType, metadata) => ({
44
41
  targetAttrs: metadata === null || metadata === void 0 ? void 0 : metadata.targetAttrs,
45
42
  parentNode: selectedParent
46
43
  });
47
- const content = resultNodes.length > 0 ? resultNodes : slice.content;
44
+ const content = resultNodes.length > 0 ? resultNodes : sourceNodes;
45
+ const sliceStart = isList ? $from.pos - 1 : $from.pos;
48
46
  if (preservedSelection instanceof NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
49
47
  var _api$blockControls2;
50
48
  // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
@@ -59,8 +57,8 @@ export const transformNode = api => (targetType, metadata) => ({
59
57
  // when we replace and insert content, we need to manually map the preserved selection
60
58
  // through the transaction, otherwise it will treat the selection as having been deleted
61
59
  // and stop preserving it
62
- const oldSize = slice.size;
63
- const newSize = Array.isArray(content) ? content.reduce((sum, node) => sum + node.nodeSize, 0) : content.size;
60
+ const oldSize = sourceNodes.reduce((sum, node) => sum + node.nodeSize, 0);
61
+ const newSize = content.reduce((sum, node) => sum + node.nodeSize, 0);
64
62
  api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.mapPreservedSelection(new Mapping([new StepMap([0, oldSize, newSize])]))({
65
63
  tr
66
64
  });
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { BLOCK_ACTIONS_COPY_LINK_TO_BLOCK_MENU_ITEM, BLOCK_ACTIONS_MENU_SECTION, BLOCK_ACTIONS_MENU_SECTION_RANK, DELETE_MENU_SECTION, DELETE_MENU_SECTION_RANK, DELETE_MENU_ITEM, POSITION_MENU_SECTION, POSITION_MENU_SECTION_RANK, POSITION_MOVE_DOWN_MENU_ITEM, POSITION_MOVE_UP_MENU_ITEM, TRANSFORM_MENU_ITEM, TRANSFORM_MENU_ITEM_RANK, TRANSFORM_MENU_SECTION, TRANSFORM_MENU_SECTION_RANK, TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_SUGGESTED_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_HEADINGS_MENU_SECTION, MAIN_BLOCK_MENU_SECTION_RANK, TRANSFORM_SUGGESTED_MENU_SECTION_RANK, TRANSFORM_SUGGESTED_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
3
3
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
4
+ import { buildChildrenMap, getChildrenMapKey, willComponentRender } from './block-menu-renderer/utils';
4
5
  import { CopyLinkDropdownItem } from './copy-link';
5
6
  import { CopySection } from './copy-section';
6
7
  import { DeleteDropdownItem } from './delete-button';
@@ -13,6 +14,18 @@ import { SuggestedItemsMenuSection } from './suggested-items-menu-section';
13
14
  import { SuggestedMenuItems } from './suggested-menu-items';
14
15
  import { createMenuItemsMap } from './utils/createMenuItemsMap';
15
16
  import { getSuggestedItemsFromSelection } from './utils/getSuggestedItemsFromSelection';
17
+ const MIN_NUMBER_OF_AVAILABLE_NATIVE_TRANSFORMS = 7;
18
+ const getTotalNumberOfAvailableNativeTransforms = blockMenuComponents => {
19
+ if (!blockMenuComponents) {
20
+ return 0;
21
+ }
22
+ const childrenMap = buildChildrenMap(blockMenuComponents);
23
+ const headingsKey = getChildrenMapKey(TRANSFORM_HEADINGS_MENU_SECTION.key, 'block-menu-section');
24
+ const structureKey = getChildrenMapKey(TRANSFORM_STRUCTURE_MENU_SECTION.key, 'block-menu-section');
25
+ const headingsChildren = childrenMap.get(headingsKey) || [];
26
+ const structureChildren = childrenMap.get(structureKey) || [];
27
+ return [...headingsChildren, ...structureChildren].filter(c => willComponentRender(c, childrenMap)).length;
28
+ };
16
29
  const getMoveUpMoveDownMenuComponents = api => {
17
30
  return [{
18
31
  type: 'block-menu-item',
@@ -85,6 +98,9 @@ const getTurnIntoMenuComponents = api => {
85
98
  isHidden: () => {
86
99
  var _api$blockMenu, _api$selection, _api$selection$shared, _api$blockControls, _api$blockControls$sh;
87
100
  const blockMenuComponents = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
101
+ if (getTotalNumberOfAvailableNativeTransforms(blockMenuComponents) < MIN_NUMBER_OF_AVAILABLE_NATIVE_TRANSFORMS) {
102
+ return true;
103
+ }
88
104
  const menuItemsMap = createMenuItemsMap(blockMenuComponents);
89
105
  const selection = api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : (_api$selection$shared = _api$selection.sharedState.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection;
90
106
  const preservedSelection = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.preservedSelection;
@@ -11,11 +11,9 @@ import { BLOCK_MENU_ITEM_NAME } from './consts';
11
11
  const DeleteDropdownItemContent = ({
12
12
  api
13
13
  }) => {
14
- var _api$core$sharedState, _api$core$sharedState2;
15
14
  const {
16
15
  formatMessage
17
16
  } = useIntl();
18
- const nodeTypes = Object.values((api === null || api === void 0 ? void 0 : (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : (_api$core$sharedState2 = _api$core$sharedState.schema) === null || _api$core$sharedState2 === void 0 ? void 0 : _api$core$sharedState2.nodes) || {});
19
17
  const onClick = () => {
20
18
  api === null || api === void 0 ? void 0 : api.core.actions.execute(({
21
19
  tr
@@ -46,14 +44,13 @@ const DeleteDropdownItemContent = ({
46
44
  }) => {
47
45
  var _api$decorations, _api$decorations$comm, _api$decorations$comm2;
48
46
  api === null || api === void 0 ? void 0 : (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : (_api$decorations$comm = _api$decorations.commands) === null || _api$decorations$comm === void 0 ? void 0 : (_api$decorations$comm2 = _api$decorations$comm.hoverDecoration) === null || _api$decorations$comm2 === void 0 ? void 0 : _api$decorations$comm2.call(_api$decorations$comm, {
49
- nodeType: nodeTypes,
50
47
  add: true
51
48
  })({
52
49
  tr
53
50
  });
54
51
  return tr;
55
52
  });
56
- }, [api, nodeTypes]);
53
+ }, [api]);
57
54
  const onRemoveHoverDecoration = useCallback(() => {
58
55
  api === null || api === void 0 ? void 0 : api.core.actions.execute(({
59
56
  tr
@@ -1,7 +1,6 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
2
  import { startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
4
- import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
3
+ import { expandSelectionToBlockRange, getSourceNodesFromSelectionRange } from '@atlaskit/editor-common/selection';
5
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
5
  import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
7
6
  import { isNestedNode } from '../ui/utils/isNestedNode';
@@ -26,10 +25,7 @@ export var transformNode = function transformNode(api) {
26
25
  var isParentLayout = selectedParent.type === nodes.layoutColumn;
27
26
  var isNested = isNestedNode(preservedSelection, '') && !isParentLayout;
28
27
  var isList = isListNode(selectedParent);
29
- var sliceStart = isList ? $from.pos - 1 : $from.pos;
30
- var sliceEnd = isList ? $to.pos + 1 : $to.pos;
31
- var slice = tr.doc.slice(sliceStart, sliceEnd);
32
- var sourceNodes = _toConsumableArray(slice.content.content);
28
+ var sourceNodes = getSourceNodesFromSelectionRange(tr, preservedSelection);
33
29
  var sourceNodeTypes = {};
34
30
  sourceNodes.forEach(function (node) {
35
31
  var typeName = node.type.name;
@@ -43,7 +39,8 @@ export var transformNode = function transformNode(api) {
43
39
  targetAttrs: metadata === null || metadata === void 0 ? void 0 : metadata.targetAttrs,
44
40
  parentNode: selectedParent
45
41
  });
46
- var content = resultNodes.length > 0 ? resultNodes : slice.content;
42
+ var content = resultNodes.length > 0 ? resultNodes : sourceNodes;
43
+ var sliceStart = isList ? $from.pos - 1 : $from.pos;
47
44
  if (preservedSelection instanceof NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
48
45
  var _api$blockControls2;
49
46
  // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
@@ -58,10 +55,12 @@ export var transformNode = function transformNode(api) {
58
55
  // when we replace and insert content, we need to manually map the preserved selection
59
56
  // through the transaction, otherwise it will treat the selection as having been deleted
60
57
  // and stop preserving it
61
- var oldSize = slice.size;
62
- var newSize = Array.isArray(content) ? content.reduce(function (sum, node) {
58
+ var oldSize = sourceNodes.reduce(function (sum, node) {
59
+ return sum + node.nodeSize;
60
+ }, 0);
61
+ var newSize = content.reduce(function (sum, node) {
63
62
  return sum + node.nodeSize;
64
- }, 0) : content.size;
63
+ }, 0);
65
64
  api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.mapPreservedSelection(new Mapping([new StepMap([0, oldSize, newSize])]))({
66
65
  tr: tr
67
66
  });
@@ -2,6 +2,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import React from 'react';
3
3
  import { BLOCK_ACTIONS_COPY_LINK_TO_BLOCK_MENU_ITEM, BLOCK_ACTIONS_MENU_SECTION, BLOCK_ACTIONS_MENU_SECTION_RANK, DELETE_MENU_SECTION, DELETE_MENU_SECTION_RANK, DELETE_MENU_ITEM, POSITION_MENU_SECTION, POSITION_MENU_SECTION_RANK, POSITION_MOVE_DOWN_MENU_ITEM, POSITION_MOVE_UP_MENU_ITEM, TRANSFORM_MENU_ITEM, TRANSFORM_MENU_ITEM_RANK, TRANSFORM_MENU_SECTION, TRANSFORM_MENU_SECTION_RANK, TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_SUGGESTED_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_HEADINGS_MENU_SECTION, MAIN_BLOCK_MENU_SECTION_RANK, TRANSFORM_SUGGESTED_MENU_SECTION_RANK, TRANSFORM_SUGGESTED_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
4
4
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
5
+ import { buildChildrenMap, getChildrenMapKey, willComponentRender } from './block-menu-renderer/utils';
5
6
  import { CopyLinkDropdownItem } from './copy-link';
6
7
  import { CopySection } from './copy-section';
7
8
  import { DeleteDropdownItem } from './delete-button';
@@ -14,6 +15,20 @@ import { SuggestedItemsMenuSection } from './suggested-items-menu-section';
14
15
  import { SuggestedMenuItems } from './suggested-menu-items';
15
16
  import { createMenuItemsMap } from './utils/createMenuItemsMap';
16
17
  import { getSuggestedItemsFromSelection } from './utils/getSuggestedItemsFromSelection';
18
+ var MIN_NUMBER_OF_AVAILABLE_NATIVE_TRANSFORMS = 7;
19
+ var getTotalNumberOfAvailableNativeTransforms = function getTotalNumberOfAvailableNativeTransforms(blockMenuComponents) {
20
+ if (!blockMenuComponents) {
21
+ return 0;
22
+ }
23
+ var childrenMap = buildChildrenMap(blockMenuComponents);
24
+ var headingsKey = getChildrenMapKey(TRANSFORM_HEADINGS_MENU_SECTION.key, 'block-menu-section');
25
+ var structureKey = getChildrenMapKey(TRANSFORM_STRUCTURE_MENU_SECTION.key, 'block-menu-section');
26
+ var headingsChildren = childrenMap.get(headingsKey) || [];
27
+ var structureChildren = childrenMap.get(structureKey) || [];
28
+ return [].concat(_toConsumableArray(headingsChildren), _toConsumableArray(structureChildren)).filter(function (c) {
29
+ return willComponentRender(c, childrenMap);
30
+ }).length;
31
+ };
17
32
  var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
18
33
  return [{
19
34
  type: 'block-menu-item',
@@ -94,6 +109,9 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
94
109
  isHidden: function isHidden() {
95
110
  var _api$blockMenu, _api$selection, _api$blockControls;
96
111
  var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
112
+ if (getTotalNumberOfAvailableNativeTransforms(blockMenuComponents) < MIN_NUMBER_OF_AVAILABLE_NATIVE_TRANSFORMS) {
113
+ return true;
114
+ }
97
115
  var menuItemsMap = createMenuItemsMap(blockMenuComponents);
98
116
  var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
99
117
  var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
@@ -9,11 +9,9 @@ import { Box } from '@atlaskit/primitives/box';
9
9
  import Text from '@atlaskit/primitives/text';
10
10
  import { BLOCK_MENU_ITEM_NAME } from './consts';
11
11
  var DeleteDropdownItemContent = function DeleteDropdownItemContent(_ref) {
12
- var _api$core$sharedState;
13
12
  var api = _ref.api;
14
13
  var _useIntl = useIntl(),
15
14
  formatMessage = _useIntl.formatMessage;
16
- var nodeTypes = Object.values((api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 || (_api$core$sharedState = _api$core$sharedState.schema) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.nodes) || {});
17
15
  var onClick = function onClick() {
18
16
  api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
19
17
  var _api$analytics, _api$blockControls, _api$blockControls2;
@@ -42,14 +40,13 @@ var DeleteDropdownItemContent = function DeleteDropdownItemContent(_ref) {
42
40
  var _api$decorations, _api$decorations$hove;
43
41
  var tr = _ref3.tr;
44
42
  api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 || (_api$decorations = _api$decorations.commands) === null || _api$decorations === void 0 || (_api$decorations$hove = _api$decorations.hoverDecoration) === null || _api$decorations$hove === void 0 || _api$decorations$hove.call(_api$decorations, {
45
- nodeType: nodeTypes,
46
43
  add: true
47
44
  })({
48
45
  tr: tr
49
46
  });
50
47
  return tr;
51
48
  });
52
- }, [api, nodeTypes]);
49
+ }, [api]);
53
50
  var onRemoveHoverDecoration = useCallback(function () {
54
51
  api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
55
52
  var _api$decorations2, _api$decorations2$rem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "6.0.20",
3
+ "version": "6.0.21",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -46,8 +46,8 @@
46
46
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
47
47
  "@atlaskit/primitives": "^17.1.0",
48
48
  "@atlaskit/prosemirror-history": "^0.2.0",
49
- "@atlaskit/tmp-editor-statsig": "^16.24.0",
50
- "@atlaskit/tokens": "^10.0.0",
49
+ "@atlaskit/tmp-editor-statsig": "^16.27.0",
50
+ "@atlaskit/tokens": "^10.1.0",
51
51
  "@babel/runtime": "^7.0.0"
52
52
  },
53
53
  "peerDependencies": {
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../tsconfig",
3
- "compilerOptions": {
4
- "target": "es5",
5
- "paths": {}
6
- },
7
- "include": [
8
- "../src/**/*.ts",
9
- "../src/**/*.tsx"
10
- ],
11
- "exclude": [
12
- "../src/**/__tests__/*",
13
- "../src/**/*.test.*",
14
- "../src/**/test.*",
15
- "../src/**/examples.*"
16
- ]
17
- }