@atlaskit/editor-plugin-block-type 10.3.3 → 10.3.5

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,21 @@
1
1
  # @atlaskit/editor-plugin-block-type
2
2
 
3
+ ## 10.3.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`9cb0ce7857313`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9cb0ce7857313) -
8
+ [ux] Fix contextual transform options for single node selections.
9
+ - Updated dependencies
10
+
11
+ ## 10.3.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [`b5d004bf834f8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b5d004bf834f8) -
16
+ [ux] Adds block menu action to check if 'Turn into' item should be rendered or not.
17
+ - Updated dependencies
18
+
3
19
  ## 10.3.3
4
20
 
5
21
  ### Patch Changes
@@ -9,8 +9,6 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _reactIntlNext = require("react-intl-next");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
11
  var _messages = require("@atlaskit/editor-common/messages");
12
- var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
12
  var _editorToolbar = require("@atlaskit/editor-toolbar");
15
13
  var _textHeadingFive = _interopRequireDefault(require("@atlaskit/icon-lab/core/text-heading-five"));
16
14
  var _textHeadingFour = _interopRequireDefault(require("@atlaskit/icon-lab/core/text-heading-four"));
@@ -18,50 +16,44 @@ var _textHeadingOne = _interopRequireDefault(require("@atlaskit/icon-lab/core/te
18
16
  var _textHeadingSix = _interopRequireDefault(require("@atlaskit/icon-lab/core/text-heading-six"));
19
17
  var _textHeadingThree = _interopRequireDefault(require("@atlaskit/icon-lab/core/text-heading-three"));
20
18
  var _textHeadingTwo = _interopRequireDefault(require("@atlaskit/icon-lab/core/text-heading-two"));
21
- var _consts = require("./consts");
22
19
  var headingIcons = [_textHeadingOne.default, _textHeadingTwo.default, _textHeadingThree.default, _textHeadingFour.default, _textHeadingFive.default, _textHeadingSix.default];
23
20
  var headingMessages = [_messages.blockTypeMessages.heading1, _messages.blockTypeMessages.heading2, _messages.blockTypeMessages.heading3, _messages.blockTypeMessages.heading4, _messages.blockTypeMessages.heading5, _messages.blockTypeMessages.heading6];
24
- var HeadingBlockTypes = [_consts.HEADING_1, _consts.HEADING_2, _consts.HEADING_3, _consts.HEADING_4, _consts.HEADING_5, _consts.HEADING_6];
21
+ var NODE_NAME = 'heading';
25
22
  var HeadingBlockMenuItem = function HeadingBlockMenuItem(_ref) {
23
+ var _api$blockMenu2;
26
24
  var level = _ref.level,
27
25
  api = _ref.api;
28
26
  var _useIntl = (0, _reactIntlNext.useIntl)(),
29
27
  formatMessage = _useIntl.formatMessage;
30
28
  var Icon = headingIcons[level - 1];
31
29
  var message = headingMessages[level - 1];
32
- var currentBlockType = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockType.currentBlockType');
33
- var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
34
- var isTextSelection = selection instanceof _state.TextSelection;
35
- var isHeading = isTextSelection && currentBlockType && HeadingBlockTypes.includes(currentBlockType);
36
- var currentHeadingLevel = isHeading ? currentBlockType.level : undefined;
37
- var isSelected = isHeading && currentHeadingLevel === level;
38
30
  var handleClick = function handleClick(event) {
39
- if (!selection) {
40
- return;
41
- }
42
- if (!isSelected) {
43
- var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? _analytics.INPUT_METHOD.KEYBOARD : _analytics.INPUT_METHOD.MOUSE;
44
- var inputMethod = _analytics.INPUT_METHOD.BLOCK_MENU;
45
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
46
- var _api$blockMenu;
47
- var tr = _ref2.tr;
48
- var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.heading, {
49
- inputMethod: inputMethod,
50
- triggeredFrom: triggeredFrom,
51
- targetTypeName: "heading".concat(level),
52
- targetAttrs: {
53
- level: level
54
- }
55
- });
56
- return command ? command({
57
- tr: tr
58
- }) : null;
31
+ var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? _analytics.INPUT_METHOD.KEYBOARD : _analytics.INPUT_METHOD.MOUSE;
32
+ var inputMethod = _analytics.INPUT_METHOD.BLOCK_MENU;
33
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
34
+ var _api$blockMenu;
35
+ var tr = _ref2.tr;
36
+ var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.heading, {
37
+ inputMethod: inputMethod,
38
+ triggeredFrom: triggeredFrom,
39
+ targetTypeName: "".concat(NODE_NAME).concat(level),
40
+ targetAttrs: {
41
+ level: level
42
+ }
59
43
  });
60
- }
44
+ return command ? command({
45
+ tr: tr
46
+ }) : null;
47
+ });
61
48
  };
49
+ var isTransfromToPanelDisabled = api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME, {
50
+ level: level
51
+ });
52
+ if (isTransfromToPanelDisabled) {
53
+ return null;
54
+ }
62
55
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
63
56
  onClick: handleClick,
64
- isSelected: isSelected,
65
57
  elemBefore: /*#__PURE__*/_react.default.createElement(Icon, {
66
58
  label: ""
67
59
  })
@@ -8,55 +8,37 @@ exports.createParagraphBlockMenuItem = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _reactIntlNext = require("react-intl-next");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
- var _hooks = require("@atlaskit/editor-common/hooks");
12
11
  var _messages = require("@atlaskit/editor-common/messages");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
12
  var _editorToolbar = require("@atlaskit/editor-toolbar");
15
13
  var _textParagraph = _interopRequireDefault(require("@atlaskit/icon-lab/core/text-paragraph"));
16
- var _consts = require("./consts");
14
+ var NODE_NAME = 'paragraph';
17
15
  var ParagraphBlockMenuItem = function ParagraphBlockMenuItem(_ref) {
16
+ var _api$blockMenu2;
18
17
  var api = _ref.api;
19
18
  var _useIntl = (0, _reactIntlNext.useIntl)(),
20
19
  formatMessage = _useIntl.formatMessage;
21
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockType', 'list', 'selection'], function (states) {
22
- var _states$blockTypeStat, _states$listState, _states$listState2, _states$selectionStat;
23
- return {
24
- currentBlockType: (_states$blockTypeStat = states.blockTypeState) === null || _states$blockTypeStat === void 0 ? void 0 : _states$blockTypeStat.currentBlockType,
25
- bulletListActive: (_states$listState = states.listState) === null || _states$listState === void 0 ? void 0 : _states$listState.bulletListActive,
26
- orderedListActive: (_states$listState2 = states.listState) === null || _states$listState2 === void 0 ? void 0 : _states$listState2.orderedListActive,
27
- selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
28
- };
29
- }),
30
- currentBlockType = _useSharedPluginState.currentBlockType,
31
- bulletListActive = _useSharedPluginState.bulletListActive,
32
- orderedListActive = _useSharedPluginState.orderedListActive,
33
- selection = _useSharedPluginState.selection;
34
- var isTextSelection = selection instanceof _state.TextSelection;
35
- var isParagraph = isTextSelection && currentBlockType && currentBlockType === _consts.NORMAL_TEXT && !bulletListActive && !orderedListActive;
36
20
  var handleClick = function handleClick(event) {
37
- if (!selection) {
38
- return;
39
- }
40
- if (!isParagraph) {
41
- var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? _analytics.INPUT_METHOD.KEYBOARD : _analytics.INPUT_METHOD.MOUSE;
42
- var inputMethod = _analytics.INPUT_METHOD.BLOCK_MENU;
43
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
44
- var _api$blockMenu;
45
- var tr = _ref2.tr;
46
- var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.paragraph, {
47
- inputMethod: inputMethod,
48
- triggeredFrom: triggeredFrom,
49
- targetTypeName: "paragraph"
50
- });
51
- return command ? command({
52
- tr: tr
53
- }) : null;
21
+ var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? _analytics.INPUT_METHOD.KEYBOARD : _analytics.INPUT_METHOD.MOUSE;
22
+ var inputMethod = _analytics.INPUT_METHOD.BLOCK_MENU;
23
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
24
+ var _api$blockMenu;
25
+ var tr = _ref2.tr;
26
+ var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.paragraph, {
27
+ inputMethod: inputMethod,
28
+ triggeredFrom: triggeredFrom,
29
+ targetTypeName: NODE_NAME
54
30
  });
55
- }
31
+ return command ? command({
32
+ tr: tr
33
+ }) : null;
34
+ });
56
35
  };
36
+ var isTransfromToPanelDisabled = api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME);
37
+ if (isTransfromToPanelDisabled) {
38
+ return null;
39
+ }
57
40
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
58
41
  onClick: handleClick,
59
- isSelected: isParagraph,
60
42
  elemBefore: /*#__PURE__*/_react.default.createElement(_textParagraph.default, {
61
43
  label: ""
62
44
  })
@@ -9,37 +9,36 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _reactIntlNext = require("react-intl-next");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
11
  var _messages = require("@atlaskit/editor-common/messages");
12
- var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
12
  var _editorToolbar = require("@atlaskit/editor-toolbar");
14
13
  var _quotationMark = _interopRequireDefault(require("@atlaskit/icon/core/quotation-mark"));
15
- var _consts = require("./consts");
14
+ var NODE_NAME = 'blockquote';
16
15
  var QuoteBlockMenuItem = function QuoteBlockMenuItem(_ref) {
16
+ var _api$blockMenu2;
17
17
  var api = _ref.api;
18
18
  var _useIntl = (0, _reactIntlNext.useIntl)(),
19
19
  formatMessage = _useIntl.formatMessage;
20
- var currentBlockType = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockType.currentBlockType');
21
- var isBlockQuote = currentBlockType && currentBlockType === _consts.BLOCK_QUOTE;
22
20
  var handleClick = function handleClick(event) {
23
- if (!isBlockQuote) {
24
- var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? _analytics.INPUT_METHOD.KEYBOARD : _analytics.INPUT_METHOD.MOUSE;
25
- var inputMethod = _analytics.INPUT_METHOD.BLOCK_MENU;
26
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
27
- var _api$blockMenu;
28
- var tr = _ref2.tr;
29
- var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.blockquote, {
30
- inputMethod: inputMethod,
31
- triggeredFrom: triggeredFrom,
32
- targetTypeName: "blockquote"
33
- });
34
- return command ? command({
35
- tr: tr
36
- }) : null;
21
+ var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? _analytics.INPUT_METHOD.KEYBOARD : _analytics.INPUT_METHOD.MOUSE;
22
+ var inputMethod = _analytics.INPUT_METHOD.BLOCK_MENU;
23
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
24
+ var _api$blockMenu;
25
+ var tr = _ref2.tr;
26
+ var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.blockquote, {
27
+ inputMethod: inputMethod,
28
+ triggeredFrom: triggeredFrom,
29
+ targetTypeName: NODE_NAME
37
30
  });
38
- }
31
+ return command ? command({
32
+ tr: tr
33
+ }) : null;
34
+ });
39
35
  };
36
+ var isTransfromToPanelDisabled = api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME);
37
+ if (isTransfromToPanelDisabled) {
38
+ return null;
39
+ }
40
40
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
41
41
  onClick: handleClick,
42
- isSelected: isBlockQuote,
43
42
  elemBefore: /*#__PURE__*/_react.default.createElement(_quotationMark.default, {
44
43
  label: ""
45
44
  })
@@ -2,8 +2,6 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
5
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
6
  import TextHeadingFiveIcon from '@atlaskit/icon-lab/core/text-heading-five';
9
7
  import TextHeadingFourIcon from '@atlaskit/icon-lab/core/text-heading-four';
@@ -11,53 +9,47 @@ import TextHeadingOneIcon from '@atlaskit/icon-lab/core/text-heading-one';
11
9
  import TextHeadingSixIcon from '@atlaskit/icon-lab/core/text-heading-six';
12
10
  import TextHeadingThreeIcon from '@atlaskit/icon-lab/core/text-heading-three';
13
11
  import TextHeadingTwoIcon from '@atlaskit/icon-lab/core/text-heading-two';
14
- import { HEADING_2, HEADING_5, HEADING_1, HEADING_3, HEADING_4, HEADING_6 } from './consts';
15
12
  const headingIcons = [TextHeadingOneIcon, TextHeadingTwoIcon, TextHeadingThreeIcon, TextHeadingFourIcon, TextHeadingFiveIcon, TextHeadingSixIcon];
16
13
  const headingMessages = [blockTypeMessages.heading1, blockTypeMessages.heading2, blockTypeMessages.heading3, blockTypeMessages.heading4, blockTypeMessages.heading5, blockTypeMessages.heading6];
17
- const HeadingBlockTypes = [HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6];
14
+ const NODE_NAME = 'heading';
18
15
  const HeadingBlockMenuItem = ({
19
16
  level,
20
17
  api
21
18
  }) => {
19
+ var _api$blockMenu2;
22
20
  const {
23
21
  formatMessage
24
22
  } = useIntl();
25
23
  const Icon = headingIcons[level - 1];
26
24
  const message = headingMessages[level - 1];
27
- const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
28
- const selection = useSharedPluginStateSelector(api, 'selection.selection');
29
- const isTextSelection = selection instanceof TextSelection;
30
- const isHeading = isTextSelection && currentBlockType && HeadingBlockTypes.includes(currentBlockType);
31
- const currentHeadingLevel = isHeading ? currentBlockType.level : undefined;
32
- const isSelected = isHeading && currentHeadingLevel === level;
33
25
  const handleClick = event => {
34
- if (!selection) {
35
- return;
36
- }
37
- if (!isSelected) {
38
- const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
39
- const inputMethod = INPUT_METHOD.BLOCK_MENU;
40
- api === null || api === void 0 ? void 0 : api.core.actions.execute(({
41
- tr
42
- }) => {
43
- var _api$blockMenu;
44
- const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.heading, {
45
- inputMethod,
46
- triggeredFrom,
47
- targetTypeName: `heading${level}`,
48
- targetAttrs: {
49
- level
50
- }
51
- });
52
- return command ? command({
53
- tr
54
- }) : null;
26
+ const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
27
+ const inputMethod = INPUT_METHOD.BLOCK_MENU;
28
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(({
29
+ tr
30
+ }) => {
31
+ var _api$blockMenu;
32
+ const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.heading, {
33
+ inputMethod,
34
+ triggeredFrom,
35
+ targetTypeName: `${NODE_NAME}${level}`,
36
+ targetAttrs: {
37
+ level
38
+ }
55
39
  });
56
- }
40
+ return command ? command({
41
+ tr
42
+ }) : null;
43
+ });
57
44
  };
45
+ const isTransfromToPanelDisabled = api === null || api === void 0 ? void 0 : (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME, {
46
+ level
47
+ });
48
+ if (isTransfromToPanelDisabled) {
49
+ return null;
50
+ }
58
51
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
59
52
  onClick: handleClick,
60
- isSelected: isSelected,
61
53
  elemBefore: /*#__PURE__*/React.createElement(Icon, {
62
54
  label: ""
63
55
  })
@@ -1,59 +1,40 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
4
  import { blockMenuMessages } from '@atlaskit/editor-common/messages';
6
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
5
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
6
  import TextParagraphIcon from '@atlaskit/icon-lab/core/text-paragraph';
9
- import { NORMAL_TEXT } from './consts';
7
+ const NODE_NAME = 'paragraph';
10
8
  const ParagraphBlockMenuItem = ({
11
9
  api
12
10
  }) => {
11
+ var _api$blockMenu2;
13
12
  const {
14
13
  formatMessage
15
14
  } = useIntl();
16
- const {
17
- currentBlockType,
18
- bulletListActive,
19
- orderedListActive,
20
- selection
21
- } = useSharedPluginStateWithSelector(api, ['blockType', 'list', 'selection'], states => {
22
- var _states$blockTypeStat, _states$listState, _states$listState2, _states$selectionStat;
23
- return {
24
- currentBlockType: (_states$blockTypeStat = states.blockTypeState) === null || _states$blockTypeStat === void 0 ? void 0 : _states$blockTypeStat.currentBlockType,
25
- bulletListActive: (_states$listState = states.listState) === null || _states$listState === void 0 ? void 0 : _states$listState.bulletListActive,
26
- orderedListActive: (_states$listState2 = states.listState) === null || _states$listState2 === void 0 ? void 0 : _states$listState2.orderedListActive,
27
- selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
28
- };
29
- });
30
- const isTextSelection = selection instanceof TextSelection;
31
- const isParagraph = isTextSelection && currentBlockType && currentBlockType === NORMAL_TEXT && !bulletListActive && !orderedListActive;
32
15
  const handleClick = event => {
33
- if (!selection) {
34
- return;
35
- }
36
- if (!isParagraph) {
37
- const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
38
- const inputMethod = INPUT_METHOD.BLOCK_MENU;
39
- api === null || api === void 0 ? void 0 : api.core.actions.execute(({
40
- tr
41
- }) => {
42
- var _api$blockMenu;
43
- const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.paragraph, {
44
- inputMethod,
45
- triggeredFrom,
46
- targetTypeName: `paragraph`
47
- });
48
- return command ? command({
49
- tr
50
- }) : null;
16
+ const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
17
+ const inputMethod = INPUT_METHOD.BLOCK_MENU;
18
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(({
19
+ tr
20
+ }) => {
21
+ var _api$blockMenu;
22
+ const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.paragraph, {
23
+ inputMethod,
24
+ triggeredFrom,
25
+ targetTypeName: NODE_NAME
51
26
  });
52
- }
27
+ return command ? command({
28
+ tr
29
+ }) : null;
30
+ });
53
31
  };
32
+ const isTransfromToPanelDisabled = api === null || api === void 0 ? void 0 : (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME);
33
+ if (isTransfromToPanelDisabled) {
34
+ return null;
35
+ }
54
36
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
55
37
  onClick: handleClick,
56
- isSelected: isParagraph,
57
38
  elemBefore: /*#__PURE__*/React.createElement(TextParagraphIcon, {
58
39
  label: ""
59
40
  })
@@ -2,40 +2,39 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
5
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
7
6
  import QuotationMarkIcon from '@atlaskit/icon/core/quotation-mark';
8
- import { BLOCK_QUOTE } from './consts';
7
+ const NODE_NAME = 'blockquote';
9
8
  const QuoteBlockMenuItem = ({
10
9
  api
11
10
  }) => {
11
+ var _api$blockMenu2;
12
12
  const {
13
13
  formatMessage
14
14
  } = useIntl();
15
- const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
16
- const isBlockQuote = currentBlockType && currentBlockType === BLOCK_QUOTE;
17
15
  const handleClick = event => {
18
- if (!isBlockQuote) {
19
- const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
20
- const inputMethod = INPUT_METHOD.BLOCK_MENU;
21
- api === null || api === void 0 ? void 0 : api.core.actions.execute(({
22
- tr
23
- }) => {
24
- var _api$blockMenu;
25
- const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.blockquote, {
26
- inputMethod,
27
- triggeredFrom,
28
- targetTypeName: `blockquote`
29
- });
30
- return command ? command({
31
- tr
32
- }) : null;
16
+ const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
17
+ const inputMethod = INPUT_METHOD.BLOCK_MENU;
18
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(({
19
+ tr
20
+ }) => {
21
+ var _api$blockMenu;
22
+ const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.blockquote, {
23
+ inputMethod,
24
+ triggeredFrom,
25
+ targetTypeName: NODE_NAME
33
26
  });
34
- }
27
+ return command ? command({
28
+ tr
29
+ }) : null;
30
+ });
35
31
  };
32
+ const isTransfromToPanelDisabled = api === null || api === void 0 ? void 0 : (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME);
33
+ if (isTransfromToPanelDisabled) {
34
+ return null;
35
+ }
36
36
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
37
37
  onClick: handleClick,
38
- isSelected: isBlockQuote,
39
38
  elemBefore: /*#__PURE__*/React.createElement(QuotationMarkIcon, {
40
39
  label: ""
41
40
  })
@@ -2,8 +2,6 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
5
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
6
  import TextHeadingFiveIcon from '@atlaskit/icon-lab/core/text-heading-five';
9
7
  import TextHeadingFourIcon from '@atlaskit/icon-lab/core/text-heading-four';
@@ -11,50 +9,44 @@ import TextHeadingOneIcon from '@atlaskit/icon-lab/core/text-heading-one';
11
9
  import TextHeadingSixIcon from '@atlaskit/icon-lab/core/text-heading-six';
12
10
  import TextHeadingThreeIcon from '@atlaskit/icon-lab/core/text-heading-three';
13
11
  import TextHeadingTwoIcon from '@atlaskit/icon-lab/core/text-heading-two';
14
- import { HEADING_2, HEADING_5, HEADING_1, HEADING_3, HEADING_4, HEADING_6 } from './consts';
15
12
  var headingIcons = [TextHeadingOneIcon, TextHeadingTwoIcon, TextHeadingThreeIcon, TextHeadingFourIcon, TextHeadingFiveIcon, TextHeadingSixIcon];
16
13
  var headingMessages = [blockTypeMessages.heading1, blockTypeMessages.heading2, blockTypeMessages.heading3, blockTypeMessages.heading4, blockTypeMessages.heading5, blockTypeMessages.heading6];
17
- var HeadingBlockTypes = [HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6];
14
+ var NODE_NAME = 'heading';
18
15
  var HeadingBlockMenuItem = function HeadingBlockMenuItem(_ref) {
16
+ var _api$blockMenu2;
19
17
  var level = _ref.level,
20
18
  api = _ref.api;
21
19
  var _useIntl = useIntl(),
22
20
  formatMessage = _useIntl.formatMessage;
23
21
  var Icon = headingIcons[level - 1];
24
22
  var message = headingMessages[level - 1];
25
- var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
26
- var selection = useSharedPluginStateSelector(api, 'selection.selection');
27
- var isTextSelection = selection instanceof TextSelection;
28
- var isHeading = isTextSelection && currentBlockType && HeadingBlockTypes.includes(currentBlockType);
29
- var currentHeadingLevel = isHeading ? currentBlockType.level : undefined;
30
- var isSelected = isHeading && currentHeadingLevel === level;
31
23
  var handleClick = function handleClick(event) {
32
- if (!selection) {
33
- return;
34
- }
35
- if (!isSelected) {
36
- var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
37
- var inputMethod = INPUT_METHOD.BLOCK_MENU;
38
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
39
- var _api$blockMenu;
40
- var tr = _ref2.tr;
41
- var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.heading, {
42
- inputMethod: inputMethod,
43
- triggeredFrom: triggeredFrom,
44
- targetTypeName: "heading".concat(level),
45
- targetAttrs: {
46
- level: level
47
- }
48
- });
49
- return command ? command({
50
- tr: tr
51
- }) : null;
24
+ var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
25
+ var inputMethod = INPUT_METHOD.BLOCK_MENU;
26
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
27
+ var _api$blockMenu;
28
+ var tr = _ref2.tr;
29
+ var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.heading, {
30
+ inputMethod: inputMethod,
31
+ triggeredFrom: triggeredFrom,
32
+ targetTypeName: "".concat(NODE_NAME).concat(level),
33
+ targetAttrs: {
34
+ level: level
35
+ }
52
36
  });
53
- }
37
+ return command ? command({
38
+ tr: tr
39
+ }) : null;
40
+ });
54
41
  };
42
+ var isTransfromToPanelDisabled = api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME, {
43
+ level: level
44
+ });
45
+ if (isTransfromToPanelDisabled) {
46
+ return null;
47
+ }
55
48
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
56
49
  onClick: handleClick,
57
- isSelected: isSelected,
58
50
  elemBefore: /*#__PURE__*/React.createElement(Icon, {
59
51
  label: ""
60
52
  })
@@ -1,55 +1,37 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
4
  import { blockMenuMessages } from '@atlaskit/editor-common/messages';
6
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
5
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
8
6
  import TextParagraphIcon from '@atlaskit/icon-lab/core/text-paragraph';
9
- import { NORMAL_TEXT } from './consts';
7
+ var NODE_NAME = 'paragraph';
10
8
  var ParagraphBlockMenuItem = function ParagraphBlockMenuItem(_ref) {
9
+ var _api$blockMenu2;
11
10
  var api = _ref.api;
12
11
  var _useIntl = useIntl(),
13
12
  formatMessage = _useIntl.formatMessage;
14
- var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockType', 'list', 'selection'], function (states) {
15
- var _states$blockTypeStat, _states$listState, _states$listState2, _states$selectionStat;
16
- return {
17
- currentBlockType: (_states$blockTypeStat = states.blockTypeState) === null || _states$blockTypeStat === void 0 ? void 0 : _states$blockTypeStat.currentBlockType,
18
- bulletListActive: (_states$listState = states.listState) === null || _states$listState === void 0 ? void 0 : _states$listState.bulletListActive,
19
- orderedListActive: (_states$listState2 = states.listState) === null || _states$listState2 === void 0 ? void 0 : _states$listState2.orderedListActive,
20
- selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
21
- };
22
- }),
23
- currentBlockType = _useSharedPluginState.currentBlockType,
24
- bulletListActive = _useSharedPluginState.bulletListActive,
25
- orderedListActive = _useSharedPluginState.orderedListActive,
26
- selection = _useSharedPluginState.selection;
27
- var isTextSelection = selection instanceof TextSelection;
28
- var isParagraph = isTextSelection && currentBlockType && currentBlockType === NORMAL_TEXT && !bulletListActive && !orderedListActive;
29
13
  var handleClick = function handleClick(event) {
30
- if (!selection) {
31
- return;
32
- }
33
- if (!isParagraph) {
34
- var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
35
- var inputMethod = INPUT_METHOD.BLOCK_MENU;
36
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
37
- var _api$blockMenu;
38
- var tr = _ref2.tr;
39
- var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.paragraph, {
40
- inputMethod: inputMethod,
41
- triggeredFrom: triggeredFrom,
42
- targetTypeName: "paragraph"
43
- });
44
- return command ? command({
45
- tr: tr
46
- }) : null;
14
+ var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
15
+ var inputMethod = INPUT_METHOD.BLOCK_MENU;
16
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
17
+ var _api$blockMenu;
18
+ var tr = _ref2.tr;
19
+ var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.paragraph, {
20
+ inputMethod: inputMethod,
21
+ triggeredFrom: triggeredFrom,
22
+ targetTypeName: NODE_NAME
47
23
  });
48
- }
24
+ return command ? command({
25
+ tr: tr
26
+ }) : null;
27
+ });
49
28
  };
29
+ var isTransfromToPanelDisabled = api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME);
30
+ if (isTransfromToPanelDisabled) {
31
+ return null;
32
+ }
50
33
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
51
34
  onClick: handleClick,
52
- isSelected: isParagraph,
53
35
  elemBefore: /*#__PURE__*/React.createElement(TextParagraphIcon, {
54
36
  label: ""
55
37
  })
@@ -2,37 +2,36 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
5
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
7
6
  import QuotationMarkIcon from '@atlaskit/icon/core/quotation-mark';
8
- import { BLOCK_QUOTE } from './consts';
7
+ var NODE_NAME = 'blockquote';
9
8
  var QuoteBlockMenuItem = function QuoteBlockMenuItem(_ref) {
9
+ var _api$blockMenu2;
10
10
  var api = _ref.api;
11
11
  var _useIntl = useIntl(),
12
12
  formatMessage = _useIntl.formatMessage;
13
- var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
14
- var isBlockQuote = currentBlockType && currentBlockType === BLOCK_QUOTE;
15
13
  var handleClick = function handleClick(event) {
16
- if (!isBlockQuote) {
17
- var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
18
- var inputMethod = INPUT_METHOD.BLOCK_MENU;
19
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
20
- var _api$blockMenu;
21
- var tr = _ref2.tr;
22
- var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.blockquote, {
23
- inputMethod: inputMethod,
24
- triggeredFrom: triggeredFrom,
25
- targetTypeName: "blockquote"
26
- });
27
- return command ? command({
28
- tr: tr
29
- }) : null;
14
+ var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
15
+ var inputMethod = INPUT_METHOD.BLOCK_MENU;
16
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
17
+ var _api$blockMenu;
18
+ var tr = _ref2.tr;
19
+ var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.blockquote, {
20
+ inputMethod: inputMethod,
21
+ triggeredFrom: triggeredFrom,
22
+ targetTypeName: NODE_NAME
30
23
  });
31
- }
24
+ return command ? command({
25
+ tr: tr
26
+ }) : null;
27
+ });
32
28
  };
29
+ var isTransfromToPanelDisabled = api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(NODE_NAME);
30
+ if (isTransfromToPanelDisabled) {
31
+ return null;
32
+ }
33
33
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
34
34
  onClick: handleClick,
35
- isSelected: isBlockQuote,
36
35
  elemBefore: /*#__PURE__*/React.createElement(QuotationMarkIcon, {
37
36
  label: ""
38
37
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-type",
3
- "version": "10.3.3",
3
+ "version": "10.3.5",
4
4
  "description": "BlockType plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,8 +36,8 @@
36
36
  "@atlaskit/editor-plugin-list": "^8.2.0",
37
37
  "@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
38
38
  "@atlaskit/editor-plugin-selection": "^6.1.0",
39
- "@atlaskit/editor-plugin-selection-toolbar": "^7.1.0",
40
- "@atlaskit/editor-plugin-toolbar": "^3.4.0",
39
+ "@atlaskit/editor-plugin-selection-toolbar": "^7.2.0",
40
+ "@atlaskit/editor-plugin-toolbar": "^3.5.0",
41
41
  "@atlaskit/editor-prosemirror": "^7.2.0",
42
42
  "@atlaskit/editor-shared-styles": "^3.10.0",
43
43
  "@atlaskit/editor-tables": "^2.9.0",
@@ -51,13 +51,13 @@
51
51
  "@atlaskit/prosemirror-history": "^0.2.0",
52
52
  "@atlaskit/prosemirror-input-rules": "^3.6.0",
53
53
  "@atlaskit/theme": "^21.0.0",
54
- "@atlaskit/tmp-editor-statsig": "^16.0.0",
54
+ "@atlaskit/tmp-editor-statsig": "^16.2.0",
55
55
  "@atlaskit/tokens": "^9.0.0",
56
56
  "@babel/runtime": "^7.0.0",
57
57
  "@emotion/react": "^11.7.1"
58
58
  },
59
59
  "peerDependencies": {
60
- "@atlaskit/editor-common": "^110.46.0",
60
+ "@atlaskit/editor-common": "^110.49.0",
61
61
  "react": "^18.2.0",
62
62
  "react-dom": "^18.2.0",
63
63
  "react-intl-next": "npm:react-intl@^5.18.1"