UNPKG

@atlaskit/editor-plugin-toolbar-lists-indentation

Version:

Toolbar lists and indentation plugin for @atlaskit/editor-core

64 lines 3.29 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { toggleBulletList as toggleBulletListKeymap, formatShortcut } from '@atlaskit/editor-common/keymaps'; import { listMessages } from '@atlaskit/editor-common/messages'; import { getInputMethodFromParentKeys } from '@atlaskit/editor-common/toolbar'; import { ListBulletedIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar'; export var useBulletedListInfo = function useBulletedListInfo(_ref) { var api = _ref.api, parents = _ref.parents; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var bulletMessage = formatMessage(listMessages.bulletedList); var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['list', 'taskDecision'], function (states) { var _states$listState, _states$listState2, _states$taskDecisionS; return { bulletListActive: (_states$listState = states.listState) === null || _states$listState === void 0 ? void 0 : _states$listState.bulletListActive, bulletListDisabled: (_states$listState2 = states.listState) === null || _states$listState2 === void 0 ? void 0 : _states$listState2.bulletListDisabled, taskListActive: (_states$taskDecisionS = states.taskDecisionState) === null || _states$taskDecisionS === void 0 ? void 0 : _states$taskDecisionS.isInsideTask }; }), bulletListActive = _useSharedPluginState.bulletListActive, bulletListDisabled = _useSharedPluginState.bulletListDisabled, taskListActive = _useSharedPluginState.taskListActive; var onClick = function onClick() { var _api$taskDecision; api === null || api === void 0 || api.core.actions.execute(taskListActive ? api === null || api === void 0 || (_api$taskDecision = api.taskDecision) === null || _api$taskDecision === void 0 ? void 0 : _api$taskDecision.commands.toggleTaskList('bulletList') : api === null || api === void 0 ? void 0 : api.list.commands.toggleBulletList(getInputMethodFromParentKeys(parents))); }; var isDisabled = bulletListDisabled && !taskListActive; var shortcut = formatShortcut(toggleBulletListKeymap); return { bulletMessage: bulletMessage, onClick: onClick, isDisabled: isDisabled, isSelected: bulletListActive, shortcut: shortcut }; }; export var BulletedListMenuItem = function BulletedListMenuItem(_ref2) { var api = _ref2.api, parents = _ref2.parents; var _useBulletedListInfo = useBulletedListInfo({ api: api, parents: parents }), bulletMessage = _useBulletedListInfo.bulletMessage, onClick = _useBulletedListInfo.onClick, isDisabled = _useBulletedListInfo.isDisabled, isSelected = _useBulletedListInfo.isSelected, shortcut = _useBulletedListInfo.shortcut; return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { elemBefore: /*#__PURE__*/React.createElement(ListBulletedIcon, { size: "small", label: "" }), elemAfter: shortcut ? /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, { shortcut: shortcut }) : undefined, isSelected: isSelected, isDisabled: isDisabled, onClick: onClick, ariaKeyshortcuts: shortcut }, bulletMessage); };