UNPKG

@atlaskit/editor-plugin-panel

Version:

Panel plugin for @atlaskit/editor-core.

50 lines 2.31 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { blockTypeMessages } from '@atlaskit/editor-common/messages'; import { pickPanelTypeForInsertion } from '@atlaskit/editor-common/utils/node-type-utils'; import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar'; import InformationCircleIcon from '@atlaskit/icon/core/information-circle'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; var NODE_NAME = 'panel'; var PanelBlockMenuItem = function PanelBlockMenuItem(_ref) { var api = _ref.api, isSuggested = _ref.isSuggested; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var handleClick = function handleClick(event) { var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE; var inputMethod = INPUT_METHOD.BLOCK_MENU; api === null || api === void 0 || api.core.actions.execute(function (_ref2) { var _api$blockMenu; var tr = _ref2.tr; var panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? pickPanelTypeForInsertion(tr.selection.$from) : tr.doc.type.schema.nodes.panel; var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(panelNodeType, { inputMethod: inputMethod, isSuggested: isSuggested, triggeredFrom: triggeredFrom, targetTypeName: NODE_NAME }); return command ? command({ tr: tr }) : null; }); }; return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { onClick: handleClick, elemBefore: /*#__PURE__*/React.createElement(InformationCircleIcon, { label: "", size: "small" }) }, formatMessage(blockTypeMessages.panel)); }; export var createPanelBlockMenuItem = function createPanelBlockMenuItem(api) { return function () { var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, isSuggested = _ref3.isSuggested; return /*#__PURE__*/React.createElement(PanelBlockMenuItem, { api: api, isSuggested: isSuggested }); }; };