UNPKG

@atlaskit/editor-plugin-synced-block

Version:

SyncedBlock plugin for @atlaskit/editor-core

46 lines 1.8 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 const SyncedBlockQuickInsertMenuItem = ({ api, syncBlockStore }) => { const { formatMessage } = useIntl(); const { editorDisabled } = useSharedPluginStateWithSelector(api, ['editorDisabled'], states => { var _states$editorDisable; return { editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled }; }); const onSelect = useCallback(({ editorView, insert, source }) => { var _api$analytics; return createSyncedBlock({ tr: editorView.state.tr, syncBlockStore, typeAheadInsert: insert, fireAnalyticsEvent: api === null || api === void 0 ? 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) }); };