@atlaskit/editor-plugin-block-menu 2.0.0 → 3.0.0

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 (41) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/blockMenuPlugin.js +0 -12
  3. package/dist/cjs/pm-plugins/main.js +3 -13
  4. package/dist/cjs/ui/block-menu-components.js +3 -3
  5. package/dist/cjs/ui/copy-link.js +6 -2
  6. package/dist/cjs/ui/copy-section.js +21 -0
  7. package/dist/cjs/ui/format-menu-section.js +8 -5
  8. package/dist/cjs/ui/utils/checkIsFormatMenuHidden.js +36 -0
  9. package/dist/cjs/ui/utils/isNestedNode.js +4 -3
  10. package/dist/es2019/blockMenuPlugin.js +1 -13
  11. package/dist/es2019/pm-plugins/main.js +3 -13
  12. package/dist/es2019/ui/block-menu-components.js +4 -6
  13. package/dist/es2019/ui/copy-link.js +6 -2
  14. package/dist/es2019/ui/copy-section.js +14 -0
  15. package/dist/es2019/ui/format-menu-section.js +6 -4
  16. package/dist/es2019/ui/utils/checkIsFormatMenuHidden.js +30 -0
  17. package/dist/es2019/ui/utils/isNestedNode.js +4 -3
  18. package/dist/esm/blockMenuPlugin.js +1 -13
  19. package/dist/esm/pm-plugins/main.js +3 -12
  20. package/dist/esm/ui/block-menu-components.js +3 -3
  21. package/dist/esm/ui/copy-link.js +6 -2
  22. package/dist/esm/ui/copy-section.js +13 -0
  23. package/dist/esm/ui/format-menu-section.js +6 -4
  24. package/dist/esm/ui/utils/checkIsFormatMenuHidden.js +30 -0
  25. package/dist/esm/ui/utils/isNestedNode.js +4 -3
  26. package/dist/types/blockMenuPluginType.d.ts +0 -3
  27. package/dist/types/pm-plugins/main.d.ts +1 -3
  28. package/dist/types/ui/copy-section.d.ts +7 -0
  29. package/dist/types/ui/utils/checkIsFormatMenuHidden.d.ts +3 -0
  30. package/dist/types/ui/utils/isNestedNode.d.ts +1 -1
  31. package/dist/types-ts4.5/blockMenuPluginType.d.ts +0 -3
  32. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -3
  33. package/dist/types-ts4.5/ui/copy-section.d.ts +7 -0
  34. package/dist/types-ts4.5/ui/utils/checkIsFormatMenuHidden.d.ts +3 -0
  35. package/dist/types-ts4.5/ui/utils/isNestedNode.d.ts +1 -1
  36. package/package.json +2 -2
  37. package/dist/cjs/pm-plugins/getIsFormatMenuHidden.js +0 -40
  38. package/dist/es2019/pm-plugins/getIsFormatMenuHidden.js +0 -34
  39. package/dist/esm/pm-plugins/getIsFormatMenuHidden.js +0 -34
  40. package/dist/types/pm-plugins/getIsFormatMenuHidden.d.ts +0 -2
  41. package/dist/types-ts4.5/pm-plugins/getIsFormatMenuHidden.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`bdad0e9db564d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/bdad0e9db564d) -
8
+ [ux] ED-29214 Clean up isFormatMenuHidden shared state and add logic for blockquote selections
9
+
3
10
  ## 2.0.0
4
11
 
5
12
  ### Patch Changes
@@ -40,18 +40,6 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
40
40
  return (0, _formatNode2.formatNode)(targetType);
41
41
  }
42
42
  },
43
- getSharedState: function getSharedState(editorState) {
44
- if (!editorState) {
45
- return;
46
- }
47
- var pluginState = _main.blockMenuPluginKey.getState(editorState);
48
- if (!pluginState) {
49
- return;
50
- }
51
- return {
52
- isFormatMenuHidden: pluginState === null || pluginState === void 0 ? void 0 : pluginState.isFormatMenuHidden
53
- };
54
- },
55
43
  contentComponent: function contentComponent(_ref2) {
56
44
  var editorView = _ref2.editorView,
57
45
  popupsMountPoint = _ref2.popupsMountPoint,
@@ -1,16 +1,11 @@
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.createPlugin = exports.blockMenuPluginKey = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
8
  var _state = require("@atlaskit/editor-prosemirror/state");
11
- var _getIsFormatMenuHidden = require("./getIsFormatMenuHidden");
12
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
9
  var blockMenuPluginKey = exports.blockMenuPluginKey = new _state.PluginKey('blockMenuPlugin');
15
10
 
16
11
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -20,19 +15,14 @@ var createPlugin = exports.createPlugin = function createPlugin() {
20
15
  key: blockMenuPluginKey,
21
16
  state: {
22
17
  init: function init() {
23
- return {
24
- isFormatMenuHidden: false
25
- };
18
+ return {};
26
19
  },
27
20
  apply: function apply(tr, currentPluginState) {
28
21
  var meta = tr.getMeta(blockMenuPluginKey);
29
22
  if (meta) {
30
- return _objectSpread(_objectSpread({}, currentPluginState), meta);
23
+ return meta;
31
24
  }
32
- var isFormatMenuHidden = (0, _getIsFormatMenuHidden.getIsFormatMenuHidden)(tr);
33
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
34
- isFormatMenuHidden: isFormatMenuHidden
35
- });
25
+ return currentPluginState;
36
26
  }
37
27
  }
38
28
  });
@@ -13,6 +13,7 @@ var _changes = _interopRequireDefault(require("@atlaskit/icon/core/changes"));
13
13
  var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
14
14
  var _copyBlock = _interopRequireDefault(require("./copy-block"));
15
15
  var _copyLink = require("./copy-link");
16
+ var _copySection = require("./copy-section");
16
17
  var _deleteButton = require("./delete-button");
17
18
  var _formatMenuSection = require("./format-menu-section");
18
19
  var _moveDown = require("./move-down");
@@ -106,10 +107,9 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
106
107
  key: _blockMenu.COPY_MENU_SECTION.key,
107
108
  rank: _blockMenu.BLOCK_MENU_SECTION_RANK[_blockMenu.COPY_MENU_SECTION.key],
108
109
  component: function component(_ref5) {
109
- var _api$blockMenu$shared;
110
110
  var children = _ref5.children;
111
- return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
112
- hasSeparator: !(api !== null && api !== void 0 && (_api$blockMenu$shared = api.blockMenu.sharedState.currentState()) !== null && _api$blockMenu$shared !== void 0 && _api$blockMenu$shared.isFormatMenuHidden)
111
+ return /*#__PURE__*/_react.default.createElement(_copySection.CopySection, {
112
+ api: api
113
113
  }, children);
114
114
  }
115
115
  }, {
@@ -35,9 +35,13 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
35
35
  return (0, _copyLink.copyLink)(config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockQueryParam, api);
36
36
  }, [config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockQueryParam, api]);
37
37
  var checkIsNestedNode = (0, _react.useCallback)(function () {
38
- var _api$selection;
38
+ var _api$selection, _api$blockControls2;
39
39
  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;
40
- return (0, _isNestedNode.isNestedNode)(selection);
40
+ var menuTriggerBy = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
41
+ if (!selection || !menuTriggerBy) {
42
+ return false;
43
+ }
44
+ return (0, _isNestedNode.isNestedNode)(selection, menuTriggerBy);
41
45
  }, [api]);
42
46
 
43
47
  // Hide copy link when `platform_editor_adf_with_localid` feature flag is off or when the node is nested
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CopySection = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
10
+ var _checkIsFormatMenuHidden = require("./utils/checkIsFormatMenuHidden");
11
+ 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); }
12
+ var CopySection = exports.CopySection = function CopySection(_ref) {
13
+ var api = _ref.api,
14
+ children = _ref.children;
15
+ var isFormatMenuHidden = (0, _react.useCallback)(function () {
16
+ return (0, _checkIsFormatMenuHidden.checkIsFormatMenuHidden)(api);
17
+ }, [api]);
18
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
19
+ hasSeparator: !isFormatMenuHidden()
20
+ }, children);
21
+ };
@@ -1,18 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.FormatMenuSection = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
8
+ var _react = _interopRequireWildcard(require("react"));
10
9
  var _editorToolbar = require("@atlaskit/editor-toolbar");
10
+ var _checkIsFormatMenuHidden = require("./utils/checkIsFormatMenuHidden");
11
+ 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); }
11
12
  var FormatMenuSection = exports.FormatMenuSection = function FormatMenuSection(_ref) {
12
13
  var children = _ref.children,
13
14
  api = _ref.api;
14
- var isFormatMenuHidden = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockMenu.isFormatMenuHidden');
15
- if (isFormatMenuHidden) {
15
+ var isFormatMenuHidden = (0, _react.useCallback)(function () {
16
+ return (0, _checkIsFormatMenuHidden.checkIsFormatMenuHidden)(api);
17
+ }, [api]);
18
+ if (isFormatMenuHidden()) {
16
19
  return null;
17
20
  }
18
21
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, null, children);
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.checkIsFormatMenuHidden = void 0;
7
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
8
+ var _isNestedNode = require("./isNestedNode");
9
+ var getIsFormatMenuHidden = function getIsFormatMenuHidden(selection, schema, menuTriggerBy) {
10
+ var nodes = schema.nodes;
11
+ if (!nodes) {
12
+ return false;
13
+ }
14
+ var content;
15
+ var selectedNode = (0, _utils.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
16
+ if (selectedNode) {
17
+ content = selectedNode.node;
18
+ } else {
19
+ var listTypeOrBlockQuoteNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
20
+ if (listTypeOrBlockQuoteNode) {
21
+ content = listTypeOrBlockQuoteNode.node;
22
+ }
23
+ }
24
+ var isNested = (0, _isNestedNode.isNestedNode)(selection, menuTriggerBy);
25
+ return !content || isNested;
26
+ };
27
+ var checkIsFormatMenuHidden = exports.checkIsFormatMenuHidden = function checkIsFormatMenuHidden(api) {
28
+ var _api$selection, _api$core$sharedState, _api$blockControls;
29
+ 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;
30
+ var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
31
+ var menuTriggerBy = 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.menuTriggerBy;
32
+ if (!selection || !schema || !menuTriggerBy) {
33
+ return false;
34
+ }
35
+ return getIsFormatMenuHidden(selection, schema, menuTriggerBy);
36
+ };
@@ -18,7 +18,7 @@ var _editorTables = require("@atlaskit/editor-tables");
18
18
  * @param selection - The current ProseMirror selection
19
19
  * @returns true if nested, false if top-level
20
20
  */
21
- var isNestedNode = exports.isNestedNode = function isNestedNode(selection) {
21
+ var isNestedNode = exports.isNestedNode = function isNestedNode(selection, menuTriggerBy) {
22
22
  if (!selection) {
23
23
  return false;
24
24
  }
@@ -34,7 +34,7 @@ var isNestedNode = exports.isNestedNode = function isNestedNode(selection) {
34
34
  }
35
35
 
36
36
  // Depth 4+: Always nested
37
- if (depth > 3) {
37
+ if (depth > 4) {
38
38
  return true;
39
39
  }
40
40
 
@@ -49,9 +49,10 @@ var isNestedNode = exports.isNestedNode = function isNestedNode(selection) {
49
49
  return true;
50
50
  }
51
51
  var parentType = parentNode.type.name;
52
+ var isTriggeredByBlockquote = menuTriggerBy.includes('blockquote');
52
53
 
53
54
  // Special cases where content is still top-level
54
- if (parentType === 'listItem' && depth === 3 || parentType === 'blockquote' && depth === 2 || parentType === 'taskList' && depth === 2) {
55
+ if (parentType === 'listItem' && depth === 3 || parentType === 'blockquote' && depth === 2 && isTriggeredByBlockquote || parentType === 'taskList' && depth === 2 || parentType === 'listItem' && depth === 4 && isTriggeredByBlockquote) {
55
56
  return false;
56
57
  }
57
58
 
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { createBlockMenuRegistry } from './editor-actions';
3
3
  import { formatNode } from './editor-commands/formatNode';
4
- import { blockMenuPluginKey, createPlugin } from './pm-plugins/main';
4
+ import { createPlugin } from './pm-plugins/main';
5
5
  import BlockMenu from './ui/block-menu';
6
6
  import { getBlockMenuComponents } from './ui/block-menu-components';
7
7
  export const blockMenuPlugin = ({
@@ -34,18 +34,6 @@ export const blockMenuPlugin = ({
34
34
  return formatNode(targetType);
35
35
  }
36
36
  },
37
- getSharedState: editorState => {
38
- if (!editorState) {
39
- return;
40
- }
41
- const pluginState = blockMenuPluginKey.getState(editorState);
42
- if (!pluginState) {
43
- return;
44
- }
45
- return {
46
- isFormatMenuHidden: pluginState === null || pluginState === void 0 ? void 0 : pluginState.isFormatMenuHidden
47
- };
48
- },
49
37
  contentComponent({
50
38
  editorView,
51
39
  popupsMountPoint,
@@ -1,6 +1,5 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { getIsFormatMenuHidden } from './getIsFormatMenuHidden';
4
3
  export const blockMenuPluginKey = new PluginKey('blockMenuPlugin');
5
4
 
6
5
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -10,23 +9,14 @@ export const createPlugin = () => {
10
9
  key: blockMenuPluginKey,
11
10
  state: {
12
11
  init() {
13
- return {
14
- isFormatMenuHidden: false
15
- };
12
+ return {};
16
13
  },
17
14
  apply: (tr, currentPluginState) => {
18
15
  const meta = tr.getMeta(blockMenuPluginKey);
19
16
  if (meta) {
20
- return {
21
- ...currentPluginState,
22
- ...meta
23
- };
17
+ return meta;
24
18
  }
25
- const isFormatMenuHidden = getIsFormatMenuHidden(tr);
26
- return {
27
- ...currentPluginState,
28
- isFormatMenuHidden
29
- };
19
+ return currentPluginState;
30
20
  }
31
21
  }
32
22
  });
@@ -5,6 +5,7 @@ import ChangesIcon from '@atlaskit/icon/core/changes';
5
5
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
6
6
  import CopyBlockMenuItem from './copy-block';
7
7
  import { CopyLinkDropdownItem } from './copy-link';
8
+ import { CopySection } from './copy-section';
8
9
  import { DeleteDropdownItem } from './delete-button';
9
10
  import { FormatMenuSection } from './format-menu-section';
10
11
  import { MoveDownDropdownItem } from './move-down';
@@ -97,12 +98,9 @@ export const getBlockMenuComponents = ({
97
98
  rank: BLOCK_MENU_SECTION_RANK[COPY_MENU_SECTION.key],
98
99
  component: ({
99
100
  children
100
- }) => {
101
- var _api$blockMenu$shared;
102
- return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
103
- hasSeparator: !(api !== null && api !== void 0 && (_api$blockMenu$shared = api.blockMenu.sharedState.currentState()) !== null && _api$blockMenu$shared !== void 0 && _api$blockMenu$shared.isFormatMenuHidden)
104
- }, children);
105
- }
101
+ }) => /*#__PURE__*/React.createElement(CopySection, {
102
+ api: api
103
+ }, children)
106
104
  }, {
107
105
  type: 'block-menu-item',
108
106
  key: COPY_BLOCK_MENU_ITEM.key,
@@ -29,9 +29,13 @@ const CopyLinkDropdownItemContent = ({
29
29
  return copyLink(config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockQueryParam, api);
30
30
  }, [config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockQueryParam, api]);
31
31
  const checkIsNestedNode = useCallback(() => {
32
- var _api$selection, _api$selection$shared, _api$selection$shared2;
32
+ var _api$selection, _api$selection$shared, _api$selection$shared2, _api$blockControls2, _api$blockControls2$s, _api$blockControls2$s2;
33
33
  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) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
34
- return isNestedNode(selection);
34
+ const menuTriggerBy = api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$s = _api$blockControls2.sharedState) === null || _api$blockControls2$s === void 0 ? void 0 : (_api$blockControls2$s2 = _api$blockControls2$s.currentState()) === null || _api$blockControls2$s2 === void 0 ? void 0 : _api$blockControls2$s2.menuTriggerBy;
35
+ if (!selection || !menuTriggerBy) {
36
+ return false;
37
+ }
38
+ return isNestedNode(selection, menuTriggerBy);
35
39
  }, [api]);
36
40
 
37
41
  // Hide copy link when `platform_editor_adf_with_localid` feature flag is off or when the node is nested
@@ -0,0 +1,14 @@
1
+ import React, { useCallback } from 'react';
2
+ import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
+ import { checkIsFormatMenuHidden } from './utils/checkIsFormatMenuHidden';
4
+ export const CopySection = ({
5
+ api,
6
+ children
7
+ }) => {
8
+ const isFormatMenuHidden = useCallback(() => {
9
+ return checkIsFormatMenuHidden(api);
10
+ }, [api]);
11
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
12
+ hasSeparator: !isFormatMenuHidden()
13
+ }, children);
14
+ };
@@ -1,12 +1,14 @@
1
- import React from 'react';
2
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
1
+ import React, { useCallback } from 'react';
3
2
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
+ import { checkIsFormatMenuHidden } from './utils/checkIsFormatMenuHidden';
4
4
  export const FormatMenuSection = ({
5
5
  children,
6
6
  api
7
7
  }) => {
8
- const isFormatMenuHidden = useSharedPluginStateSelector(api, 'blockMenu.isFormatMenuHidden');
9
- if (isFormatMenuHidden) {
8
+ const isFormatMenuHidden = useCallback(() => {
9
+ return checkIsFormatMenuHidden(api);
10
+ }, [api]);
11
+ if (isFormatMenuHidden()) {
10
12
  return null;
11
13
  }
12
14
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
@@ -0,0 +1,30 @@
1
+ import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+ import { isNestedNode } from './isNestedNode';
3
+ const getIsFormatMenuHidden = (selection, schema, menuTriggerBy) => {
4
+ const nodes = schema.nodes;
5
+ if (!nodes) {
6
+ return false;
7
+ }
8
+ let content;
9
+ const selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
10
+ if (selectedNode) {
11
+ content = selectedNode.node;
12
+ } else {
13
+ const listTypeOrBlockQuoteNode = findParentNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
14
+ if (listTypeOrBlockQuoteNode) {
15
+ content = listTypeOrBlockQuoteNode.node;
16
+ }
17
+ }
18
+ const isNested = isNestedNode(selection, menuTriggerBy);
19
+ return !content || isNested;
20
+ };
21
+ export const checkIsFormatMenuHidden = api => {
22
+ var _api$selection, _api$selection$shared, _api$selection$shared2, _api$core$sharedState, _api$blockControls, _api$blockControls$sh;
23
+ 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) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
24
+ const schema = api === null || api === void 0 ? void 0 : (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
25
+ const menuTriggerBy = 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.menuTriggerBy;
26
+ if (!selection || !schema || !menuTriggerBy) {
27
+ return false;
28
+ }
29
+ return getIsFormatMenuHidden(selection, schema, menuTriggerBy);
30
+ };
@@ -13,7 +13,7 @@ import { CellSelection } from '@atlaskit/editor-tables';
13
13
  * @param selection - The current ProseMirror selection
14
14
  * @returns true if nested, false if top-level
15
15
  */
16
- export const isNestedNode = selection => {
16
+ export const isNestedNode = (selection, menuTriggerBy) => {
17
17
  if (!selection) {
18
18
  return false;
19
19
  }
@@ -31,7 +31,7 @@ export const isNestedNode = selection => {
31
31
  }
32
32
 
33
33
  // Depth 4+: Always nested
34
- if (depth > 3) {
34
+ if (depth > 4) {
35
35
  return true;
36
36
  }
37
37
 
@@ -46,9 +46,10 @@ export const isNestedNode = selection => {
46
46
  return true;
47
47
  }
48
48
  const parentType = parentNode.type.name;
49
+ const isTriggeredByBlockquote = menuTriggerBy.includes('blockquote');
49
50
 
50
51
  // Special cases where content is still top-level
51
- if (parentType === 'listItem' && depth === 3 || parentType === 'blockquote' && depth === 2 || parentType === 'taskList' && depth === 2) {
52
+ if (parentType === 'listItem' && depth === 3 || parentType === 'blockquote' && depth === 2 && isTriggeredByBlockquote || parentType === 'taskList' && depth === 2 || parentType === 'listItem' && depth === 4 && isTriggeredByBlockquote) {
52
53
  return false;
53
54
  }
54
55
 
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { createBlockMenuRegistry } from './editor-actions';
3
3
  import { formatNode as _formatNode } from './editor-commands/formatNode';
4
- import { blockMenuPluginKey, createPlugin } from './pm-plugins/main';
4
+ import { createPlugin } from './pm-plugins/main';
5
5
  import BlockMenu from './ui/block-menu';
6
6
  import { getBlockMenuComponents } from './ui/block-menu-components';
7
7
  export var blockMenuPlugin = function blockMenuPlugin(_ref) {
@@ -33,18 +33,6 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
33
33
  return _formatNode(targetType);
34
34
  }
35
35
  },
36
- getSharedState: function getSharedState(editorState) {
37
- if (!editorState) {
38
- return;
39
- }
40
- var pluginState = blockMenuPluginKey.getState(editorState);
41
- if (!pluginState) {
42
- return;
43
- }
44
- return {
45
- isFormatMenuHidden: pluginState === null || pluginState === void 0 ? void 0 : pluginState.isFormatMenuHidden
46
- };
47
- },
48
36
  contentComponent: function contentComponent(_ref2) {
49
37
  var editorView = _ref2.editorView,
50
38
  popupsMountPoint = _ref2.popupsMountPoint,
@@ -1,9 +1,5 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
- import { getIsFormatMenuHidden } from './getIsFormatMenuHidden';
7
3
  export var blockMenuPluginKey = new PluginKey('blockMenuPlugin');
8
4
 
9
5
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -13,19 +9,14 @@ export var createPlugin = function createPlugin() {
13
9
  key: blockMenuPluginKey,
14
10
  state: {
15
11
  init: function init() {
16
- return {
17
- isFormatMenuHidden: false
18
- };
12
+ return {};
19
13
  },
20
14
  apply: function apply(tr, currentPluginState) {
21
15
  var meta = tr.getMeta(blockMenuPluginKey);
22
16
  if (meta) {
23
- return _objectSpread(_objectSpread({}, currentPluginState), meta);
17
+ return meta;
24
18
  }
25
- var isFormatMenuHidden = getIsFormatMenuHidden(tr);
26
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
27
- isFormatMenuHidden: isFormatMenuHidden
28
- });
19
+ return currentPluginState;
29
20
  }
30
21
  }
31
22
  });
@@ -6,6 +6,7 @@ import ChangesIcon from '@atlaskit/icon/core/changes';
6
6
  import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
7
7
  import CopyBlockMenuItem from './copy-block';
8
8
  import { CopyLinkDropdownItem } from './copy-link';
9
+ import { CopySection } from './copy-section';
9
10
  import { DeleteDropdownItem } from './delete-button';
10
11
  import { FormatMenuSection } from './format-menu-section';
11
12
  import { MoveDownDropdownItem } from './move-down';
@@ -99,10 +100,9 @@ export var getBlockMenuComponents = function getBlockMenuComponents(_ref4) {
99
100
  key: COPY_MENU_SECTION.key,
100
101
  rank: BLOCK_MENU_SECTION_RANK[COPY_MENU_SECTION.key],
101
102
  component: function component(_ref5) {
102
- var _api$blockMenu$shared;
103
103
  var children = _ref5.children;
104
- return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
105
- hasSeparator: !(api !== null && api !== void 0 && (_api$blockMenu$shared = api.blockMenu.sharedState.currentState()) !== null && _api$blockMenu$shared !== void 0 && _api$blockMenu$shared.isFormatMenuHidden)
104
+ return /*#__PURE__*/React.createElement(CopySection, {
105
+ api: api
106
106
  }, children);
107
107
  }
108
108
  }, {
@@ -26,9 +26,13 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
26
26
  return copyLink(config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockQueryParam, api);
27
27
  }, [config === null || config === void 0 ? void 0 : config.getLinkPath, config === null || config === void 0 ? void 0 : config.blockQueryParam, api]);
28
28
  var checkIsNestedNode = useCallback(function () {
29
- var _api$selection;
29
+ var _api$selection, _api$blockControls2;
30
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
- return isNestedNode(selection);
31
+ var menuTriggerBy = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
32
+ if (!selection || !menuTriggerBy) {
33
+ return false;
34
+ }
35
+ return isNestedNode(selection, menuTriggerBy);
32
36
  }, [api]);
33
37
 
34
38
  // Hide copy link when `platform_editor_adf_with_localid` feature flag is off or when the node is nested
@@ -0,0 +1,13 @@
1
+ import React, { useCallback } from 'react';
2
+ import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
+ import { checkIsFormatMenuHidden } from './utils/checkIsFormatMenuHidden';
4
+ export var CopySection = function CopySection(_ref) {
5
+ var api = _ref.api,
6
+ children = _ref.children;
7
+ var isFormatMenuHidden = useCallback(function () {
8
+ return checkIsFormatMenuHidden(api);
9
+ }, [api]);
10
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
11
+ hasSeparator: !isFormatMenuHidden()
12
+ }, children);
13
+ };
@@ -1,11 +1,13 @@
1
- import React from 'react';
2
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
1
+ import React, { useCallback } from 'react';
3
2
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
+ import { checkIsFormatMenuHidden } from './utils/checkIsFormatMenuHidden';
4
4
  export var FormatMenuSection = function FormatMenuSection(_ref) {
5
5
  var children = _ref.children,
6
6
  api = _ref.api;
7
- var isFormatMenuHidden = useSharedPluginStateSelector(api, 'blockMenu.isFormatMenuHidden');
8
- if (isFormatMenuHidden) {
7
+ var isFormatMenuHidden = useCallback(function () {
8
+ return checkIsFormatMenuHidden(api);
9
+ }, [api]);
10
+ if (isFormatMenuHidden()) {
9
11
  return null;
10
12
  }
11
13
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);
@@ -0,0 +1,30 @@
1
+ import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+ import { isNestedNode } from './isNestedNode';
3
+ var getIsFormatMenuHidden = function getIsFormatMenuHidden(selection, schema, menuTriggerBy) {
4
+ var nodes = schema.nodes;
5
+ if (!nodes) {
6
+ return false;
7
+ }
8
+ var content;
9
+ var selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
10
+ if (selectedNode) {
11
+ content = selectedNode.node;
12
+ } else {
13
+ var listTypeOrBlockQuoteNode = findParentNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
14
+ if (listTypeOrBlockQuoteNode) {
15
+ content = listTypeOrBlockQuoteNode.node;
16
+ }
17
+ }
18
+ var isNested = isNestedNode(selection, menuTriggerBy);
19
+ return !content || isNested;
20
+ };
21
+ export var checkIsFormatMenuHidden = function checkIsFormatMenuHidden(api) {
22
+ var _api$selection, _api$core$sharedState, _api$blockControls;
23
+ 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;
24
+ var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
25
+ var menuTriggerBy = 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.menuTriggerBy;
26
+ if (!selection || !schema || !menuTriggerBy) {
27
+ return false;
28
+ }
29
+ return getIsFormatMenuHidden(selection, schema, menuTriggerBy);
30
+ };
@@ -13,7 +13,7 @@ import { CellSelection } from '@atlaskit/editor-tables';
13
13
  * @param selection - The current ProseMirror selection
14
14
  * @returns true if nested, false if top-level
15
15
  */
16
- export var isNestedNode = function isNestedNode(selection) {
16
+ export var isNestedNode = function isNestedNode(selection, menuTriggerBy) {
17
17
  if (!selection) {
18
18
  return false;
19
19
  }
@@ -29,7 +29,7 @@ export var isNestedNode = function isNestedNode(selection) {
29
29
  }
30
30
 
31
31
  // Depth 4+: Always nested
32
- if (depth > 3) {
32
+ if (depth > 4) {
33
33
  return true;
34
34
  }
35
35
 
@@ -44,9 +44,10 @@ export var isNestedNode = function isNestedNode(selection) {
44
44
  return true;
45
45
  }
46
46
  var parentType = parentNode.type.name;
47
+ var isTriggeredByBlockquote = menuTriggerBy.includes('blockquote');
47
48
 
48
49
  // Special cases where content is still top-level
49
- if (parentType === 'listItem' && depth === 3 || parentType === 'blockquote' && depth === 2 || parentType === 'taskList' && depth === 2) {
50
+ if (parentType === 'listItem' && depth === 3 || parentType === 'blockquote' && depth === 2 && isTriggeredByBlockquote || parentType === 'taskList' && depth === 2 || parentType === 'listItem' && depth === 4 && isTriggeredByBlockquote) {
50
51
  return false;
51
52
  }
52
53
 
@@ -19,9 +19,6 @@ export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
19
19
  OptionalPlugin<DecorationsPlugin>
20
20
  ];
21
21
  pluginConfiguration?: BlockMenuPluginOptions;
22
- sharedState: {
23
- isFormatMenuHidden?: boolean;
24
- } | undefined;
25
22
  }>;
26
23
  export type BlockMenuPluginOptions = {
27
24
  /**
@@ -1,8 +1,6 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const blockMenuPluginKey: PluginKey<any>;
4
- type BlockMenuPluginState = {
5
- isFormatMenuHidden: boolean;
6
- };
4
+ type BlockMenuPluginState = {};
7
5
  export declare const createPlugin: () => SafePlugin<BlockMenuPluginState>;
8
6
  export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockMenuPlugin } from '../blockMenuPluginType';
4
+ export declare const CopySection: ({ api, children, }: {
5
+ api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
6
+ children: React.ReactNode;
7
+ }) => React.JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockMenuPlugin } from '../../blockMenuPluginType';
3
+ export declare const checkIsFormatMenuHidden: (api: ExtractInjectionAPI<BlockMenuPlugin> | undefined) => boolean;
@@ -11,4 +11,4 @@ import { type Selection } from '@atlaskit/editor-prosemirror/state';
11
11
  * @param selection - The current ProseMirror selection
12
12
  * @returns true if nested, false if top-level
13
13
  */
14
- export declare const isNestedNode: (selection: Selection | undefined) => boolean;
14
+ export declare const isNestedNode: (selection: Selection | undefined, menuTriggerBy: string) => boolean;
@@ -19,9 +19,6 @@ export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
19
19
  OptionalPlugin<DecorationsPlugin>
20
20
  ];
21
21
  pluginConfiguration?: BlockMenuPluginOptions;
22
- sharedState: {
23
- isFormatMenuHidden?: boolean;
24
- } | undefined;
25
22
  }>;
26
23
  export type BlockMenuPluginOptions = {
27
24
  /**
@@ -1,8 +1,6 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const blockMenuPluginKey: PluginKey<any>;
4
- type BlockMenuPluginState = {
5
- isFormatMenuHidden: boolean;
6
- };
4
+ type BlockMenuPluginState = {};
7
5
  export declare const createPlugin: () => SafePlugin<BlockMenuPluginState>;
8
6
  export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockMenuPlugin } from '../blockMenuPluginType';
4
+ export declare const CopySection: ({ api, children, }: {
5
+ api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
6
+ children: React.ReactNode;
7
+ }) => React.JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockMenuPlugin } from '../../blockMenuPluginType';
3
+ export declare const checkIsFormatMenuHidden: (api: ExtractInjectionAPI<BlockMenuPlugin> | undefined) => boolean;
@@ -11,4 +11,4 @@ import { type Selection } from '@atlaskit/editor-prosemirror/state';
11
11
  * @param selection - The current ProseMirror selection
12
12
  * @returns true if nested, false if top-level
13
13
  */
14
- export declare const isNestedNode: (selection: Selection | undefined) => boolean;
14
+ export declare const isNestedNode: (selection: Selection | undefined, menuTriggerBy: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -46,7 +46,7 @@
46
46
  "@babel/runtime": "^7.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@atlaskit/editor-common": "^109.0.0",
49
+ "@atlaskit/editor-common": "^109.1.0",
50
50
  "react": "^18.2.0",
51
51
  "react-intl-next": "npm:react-intl@^5.18.1"
52
52
  },
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getIsFormatMenuHidden = void 0;
7
- var _utils = require("@atlaskit/editor-prosemirror/utils");
8
- var TOP_LEVEL_NODE_DEPTHS = {
9
- LIST_TYPE: 2,
10
- PARAGRAPH_OR_HEADING: 1,
11
- BLOCKQUOTE: 1,
12
- BLOCK: 0
13
- };
14
- var getIsFormatMenuHidden = exports.getIsFormatMenuHidden = function getIsFormatMenuHidden(tr) {
15
- var selection = tr.selection;
16
- var nodes = tr.doc.type.schema.nodes;
17
- if (selection.from === selection.to || selection.empty || !nodes) {
18
- return false;
19
- }
20
- var content;
21
- var isTopLevelNode = false;
22
- var selectedNode = (0, _utils.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
23
- if (selectedNode) {
24
- content = selectedNode.node;
25
- isTopLevelNode = selectedNode.depth === TOP_LEVEL_NODE_DEPTHS.BLOCK;
26
- } else {
27
- var listTypeOrBlockQuoteNode = (0, _utils.findParentNodeOfType)([nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
28
- if (listTypeOrBlockQuoteNode) {
29
- content = listTypeOrBlockQuoteNode.node;
30
- isTopLevelNode = listTypeOrBlockQuoteNode.node.type === nodes.blockquote ? listTypeOrBlockQuoteNode.depth === TOP_LEVEL_NODE_DEPTHS.BLOCKQUOTE : listTypeOrBlockQuoteNode.depth === TOP_LEVEL_NODE_DEPTHS.LIST_TYPE;
31
- } else {
32
- var paragraphOrHeadingNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading])(selection);
33
- if (paragraphOrHeadingNode) {
34
- content = paragraphOrHeadingNode.node;
35
- isTopLevelNode = paragraphOrHeadingNode.depth === TOP_LEVEL_NODE_DEPTHS.PARAGRAPH_OR_HEADING;
36
- }
37
- }
38
- }
39
- return !content || !isTopLevelNode;
40
- };
@@ -1,34 +0,0 @@
1
- import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
- const TOP_LEVEL_NODE_DEPTHS = {
3
- LIST_TYPE: 2,
4
- PARAGRAPH_OR_HEADING: 1,
5
- BLOCKQUOTE: 1,
6
- BLOCK: 0
7
- };
8
- export const getIsFormatMenuHidden = tr => {
9
- const selection = tr.selection;
10
- const nodes = tr.doc.type.schema.nodes;
11
- if (selection.from === selection.to || selection.empty || !nodes) {
12
- return false;
13
- }
14
- let content;
15
- let isTopLevelNode = false;
16
- const selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
17
- if (selectedNode) {
18
- content = selectedNode.node;
19
- isTopLevelNode = selectedNode.depth === TOP_LEVEL_NODE_DEPTHS.BLOCK;
20
- } else {
21
- const listTypeOrBlockQuoteNode = findParentNodeOfType([nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
22
- if (listTypeOrBlockQuoteNode) {
23
- content = listTypeOrBlockQuoteNode.node;
24
- isTopLevelNode = listTypeOrBlockQuoteNode.node.type === nodes.blockquote ? listTypeOrBlockQuoteNode.depth === TOP_LEVEL_NODE_DEPTHS.BLOCKQUOTE : listTypeOrBlockQuoteNode.depth === TOP_LEVEL_NODE_DEPTHS.LIST_TYPE;
25
- } else {
26
- const paragraphOrHeadingNode = findParentNodeOfType([nodes.paragraph, nodes.heading])(selection);
27
- if (paragraphOrHeadingNode) {
28
- content = paragraphOrHeadingNode.node;
29
- isTopLevelNode = paragraphOrHeadingNode.depth === TOP_LEVEL_NODE_DEPTHS.PARAGRAPH_OR_HEADING;
30
- }
31
- }
32
- }
33
- return !content || !isTopLevelNode;
34
- };
@@ -1,34 +0,0 @@
1
- import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
- var TOP_LEVEL_NODE_DEPTHS = {
3
- LIST_TYPE: 2,
4
- PARAGRAPH_OR_HEADING: 1,
5
- BLOCKQUOTE: 1,
6
- BLOCK: 0
7
- };
8
- export var getIsFormatMenuHidden = function getIsFormatMenuHidden(tr) {
9
- var selection = tr.selection;
10
- var nodes = tr.doc.type.schema.nodes;
11
- if (selection.from === selection.to || selection.empty || !nodes) {
12
- return false;
13
- }
14
- var content;
15
- var isTopLevelNode = false;
16
- var selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection])(selection);
17
- if (selectedNode) {
18
- content = selectedNode.node;
19
- isTopLevelNode = selectedNode.depth === TOP_LEVEL_NODE_DEPTHS.BLOCK;
20
- } else {
21
- var listTypeOrBlockQuoteNode = findParentNodeOfType([nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
22
- if (listTypeOrBlockQuoteNode) {
23
- content = listTypeOrBlockQuoteNode.node;
24
- isTopLevelNode = listTypeOrBlockQuoteNode.node.type === nodes.blockquote ? listTypeOrBlockQuoteNode.depth === TOP_LEVEL_NODE_DEPTHS.BLOCKQUOTE : listTypeOrBlockQuoteNode.depth === TOP_LEVEL_NODE_DEPTHS.LIST_TYPE;
25
- } else {
26
- var paragraphOrHeadingNode = findParentNodeOfType([nodes.paragraph, nodes.heading])(selection);
27
- if (paragraphOrHeadingNode) {
28
- content = paragraphOrHeadingNode.node;
29
- isTopLevelNode = paragraphOrHeadingNode.depth === TOP_LEVEL_NODE_DEPTHS.PARAGRAPH_OR_HEADING;
30
- }
31
- }
32
- }
33
- return !content || !isTopLevelNode;
34
- };
@@ -1,2 +0,0 @@
1
- import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
2
- export declare const getIsFormatMenuHidden: (tr: ReadonlyTransaction) => boolean;
@@ -1,2 +0,0 @@
1
- import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
2
- export declare const getIsFormatMenuHidden: (tr: ReadonlyTransaction) => boolean;