@atlaskit/editor-plugin-status
Version:
Status plugin for @atlaskit/editor-core
66 lines • 2.83 kB
JavaScript
import React 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 } from '@atlaskit/editor-common/messages';
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
import LozengeIcon from '@atlaskit/icon-lab/core/lozenge';
import { pluginKey } from '../pm-plugins/plugin-key';
import { createStatusNode } from '../utils/createStatusNode';
var StatusBlockMenuItem = function StatusBlockMenuItem(_ref) {
var api = _ref.api,
isSuggested = _ref.isSuggested;
var _useIntl = useIntl(),
formatMessage = _useIntl.formatMessage;
var handleClick = function handleClick() {
api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
var _api$blockMenu, _api$analytics;
var tr = _ref2.tr;
var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformInlineNode({
buildInlineNode: function buildInlineNode(source) {
return createStatusNode(tr.doc.type.schema, {
text: source.textContent.trim()
});
},
isSuggested: isSuggested,
targetTypeName: 'status'
});
var nextTr = command === null || command === void 0 ? void 0 : command({
tr: tr
});
if (!(nextTr !== null && nextTr !== void 0 && nextTr.docChanged)) {
return null;
}
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
action: ACTION.INSERTED,
actionSubject: ACTION_SUBJECT.DOCUMENT,
actionSubjectId: ACTION_SUBJECT_ID.STATUS,
attributes: {
inputMethod: INPUT_METHOD.BLOCK_MENU
},
eventType: EVENT_TYPE.TRACK
})(nextTr);
return nextTr.setMeta(pluginKey, {
focusStatusInput: true,
isNew: true,
showStatusPickerAt: nextTr.selection.from
});
});
};
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
onClick: handleClick,
elemBefore: /*#__PURE__*/React.createElement(LozengeIcon, {
label: "",
size: "small"
})
}, formatMessage(toolbarInsertBlockMessages.status));
};
export var createStatusBlockMenuItem = function createStatusBlockMenuItem(api) {
return function () {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
isSuggested = _ref3.isSuggested;
return /*#__PURE__*/React.createElement(StatusBlockMenuItem, {
api: api,
isSuggested: isSuggested
});
};
};