UNPKG

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

Version:

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

71 lines • 2.96 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { toggleBulletList as toggleBulletListKeymap, formatShortcut } from '@atlaskit/editor-common/keymaps'; import { messages as listMessages } from '@atlaskit/editor-common/messages/list'; import { getInputMethodFromParentKeys } from '@atlaskit/editor-common/toolbar'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/useSharedPluginStateWithSelector'; import { ListBulletedIcon } from '@atlaskit/editor-toolbar/list-bulleted-icon'; import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar/toolbar-dropdown-item'; import { ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar/toolbar-keyboard-shortcut-hint'; export const useBulletedListInfo = ({ api, parents }) => { const { formatMessage } = useIntl(); const bulletMessage = formatMessage(listMessages.bulletedList); const { bulletListActive, bulletListDisabled, taskListActive } = useSharedPluginStateWithSelector(api, ['list', 'taskDecision'], 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 }; }); const isDisabled = bulletListDisabled && !taskListActive; const onClick = () => { var _api$taskDecision; api === null || api === void 0 ? void 0 : api.core.actions.execute(taskListActive ? api === null || api === void 0 ? 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))); }; const shortcut = formatShortcut(toggleBulletListKeymap); return { bulletMessage, onClick, isDisabled, isSelected: bulletListActive, shortcut }; }; export const BulletedListMenuItem = ({ api, parents }) => { const { bulletMessage, onClick, isDisabled, isSelected, shortcut } = useBulletedListInfo({ api, parents }); 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); };