UNPKG

@atlaskit/editor-plugin-synced-block

Version:

SyncedBlock plugin for @atlaskit/editor-core

42 lines 2.04 kB
import React, { useCallback } from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { blockTypeMessages } from '@atlaskit/editor-common/messages'; import { IconSyncBlock } from '@atlaskit/editor-common/assets'; import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item'; import { createSyncedBlock } from '../../editor-commands'; export var SyncedBlockQuickInsertMenuItem = function SyncedBlockQuickInsertMenuItem(_ref) { var api = _ref.api, syncBlockStore = _ref.syncBlockStore; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['editorDisabled'], function (states) { var _states$editorDisable; return { editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled }; }), editorDisabled = _useSharedPluginState.editorDisabled; var onSelect = useCallback(function (_ref2) { var _api$analytics; var editorView = _ref2.editorView, insert = _ref2.insert, source = _ref2.source; return createSyncedBlock({ tr: editorView.state.tr, syncBlockStore: syncBlockStore, typeAheadInsert: insert, fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent, inputMethod: source !== null && source !== void 0 ? source : INPUT_METHOD.QUICK_INSERT }); }, [api, syncBlockStore]); return /*#__PURE__*/React.createElement(QuickInsertMenuItem, { iconBefore: /*#__PURE__*/React.createElement(IconSyncBlock, { label: "" }), isDisabled: editorDisabled, onSelect: onSelect, title: formatMessage(blockTypeMessages.syncedBlockQuickInsertTitle) }); };