UNPKG

@atlaskit/editor-plugin-placeholder-text

Version:

placeholder text plugin for @atlaskit/editor-core

40 lines 1.49 kB
import React, { useCallback } from 'react'; import { useIntl } from 'react-intl'; import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item'; import TextIcon from '@atlaskit/icon/core/text'; import { pluginKey } from '../../pm-plugins/plugin-key'; export const PlaceholderTextQuickInsertMenuItem = ({ api }) => { const { formatMessage } = useIntl(); const onSelect = useCallback(({ editorView }) => { var _api$analytics; const tr = editorView.state.tr; tr.setMeta(pluginKey, { showInsertPanelAt: tr.selection.anchor }); api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({ action: ACTION.INSERTED, actionSubject: ACTION_SUBJECT.DOCUMENT, actionSubjectId: ACTION_SUBJECT_ID.PLACEHOLDER_TEXT, attributes: { inputMethod: INPUT_METHOD.QUICK_INSERT }, eventType: EVENT_TYPE.TRACK })(tr); return tr; }, [api]); return /*#__PURE__*/React.createElement(QuickInsertMenuItem, { iconBefore: /*#__PURE__*/React.createElement(TextIcon, { label: "" }), onSelect: onSelect, title: formatMessage(messages.placeholderText) }); };