@atlaskit/editor-plugin-quick-insert
Version:
Quick insert plugin for @atlaskit/editor-core
42 lines • 3.02 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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 var getBlockControlQuickInsertComponents = function getBlockControlQuickInsertComponents(_ref) {
var api = _ref.api,
getEditorView = _ref.getEditorView,
openTypeAhead = _ref.openTypeAhead;
return [{
key: 'block-controls-quick-insert',
type: 'button',
parents: [_objectSpread(_objectSpread({}, BLOCK_CONTROLS_LEFT_GROUP), {}, {
rank: 100
})],
isHidden: function isHidden() {
var _api$editorViewMode;
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
surfaceContext = _ref2.surfaceContext;
var context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
return (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'view' || !(context !== null && context !== void 0 && context.activeNode) || context.targetNode.pos !== context.rootNode.pos || context.targetNode.pos !== context.activeNode.rootPos;
},
component: function component(_ref3) {
var _context$activeNode;
var surfaceContext = _ref3.surfaceContext;
var context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
var 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
});
}
}];
};