UNPKG

@atlaskit/editor-plugin-quick-insert

Version:

Quick insert plugin for @atlaskit/editor-core

39 lines • 1.58 kB
import React from 'react'; import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context'; import { BLOCK_CONTROLS_LEFT_GROUP } from '@atlaskit/editor-common/block-controls/surface-keys'; import { BlockControlQuickInsertButton } from './BlockControlQuickInsertButton'; export const getBlockControlQuickInsertComponents = ({ api, getEditorView, openTypeAhead }) => [{ key: 'block-controls-quick-insert', type: 'button', parents: [{ ...BLOCK_CONTROLS_LEFT_GROUP, rank: 100 }], isHidden: ({ surfaceContext } = {}) => { const context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT); return !(context !== null && context !== void 0 && context.activeNode) || context.targetNode.pos !== context.rootNode.pos || context.targetNode.pos !== context.activeNode.rootPos; }, component: ({ surfaceContext }) => { var _context$activeNode; const context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT); const view = getEditorView(); if (!context || !view) { return null; } return /*#__PURE__*/React.createElement(BlockControlQuickInsertButton, { api: api, openTypeAhead: openTypeAhead, reserveDragHandleSpace: ((_context$activeNode = context.activeNode) === null || _context$activeNode === void 0 ? void 0 : _context$activeNode.pos) !== context.rootNode.pos, start: context.targetNode.pos, view: view }); } }];