UNPKG

@atlaskit/editor-plugin-undo-redo

Version:

Undo redo plugin for @atlaskit/editor-core

44 lines 2.07 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { getAriaKeyshortcuts, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps'; import { undoRedoMessages } from '@atlaskit/editor-common/messages'; import { useEditorToolbar } from '@atlaskit/editor-common/toolbar'; import { ToolbarButton, ToolbarTooltip, UndoIcon } from '@atlaskit/editor-toolbar'; import { undoFromToolbarWithAnalytics } from '../../pm-plugins/commands'; import { forceFocus } from '../../pm-plugins/utils'; export var UndoButton = function UndoButton(_ref) { var api = _ref.api; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useEditorToolbar = useEditorToolbar(), editorView = _useEditorToolbar.editorView; var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['history'], function (states) { var _states$historyState; return { canUndo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canUndo }; }), canUndo = _useSharedPluginState.canUndo; var handleUndo = function handleUndo() { if (editorView) { var _api$analytics; forceFocus(editorView, api)(undoFromToolbarWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)); } }; return /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(undoRedoMessages.undo), keymap: undoKeymap }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(UndoIcon, { label: formatMessage(undoRedoMessages.undo), size: "small" }), onClick: handleUndo, isDisabled: !canUndo, ariaKeyshortcuts: getAriaKeyshortcuts(undoKeymap), testId: "ak-editor-toolbar-button-undo" })); };