@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
56 lines • 2.74 kB
JavaScript
import commonMessages from '@atlaskit/editor-common/messages';
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
import DeleteIcon from '@atlaskit/icon/core/delete';
import { deleteExpand } from './commands';
import { findSelectedParentExpandNode } from './utils';
export var getToolbarConfig = function getToolbarConfig(api) {
return function (state, _ref) {
var _api$decorations$acti, _api$decorations, _api$analytics;
var formatMessage = _ref.formatMessage;
var _ref2 = (_api$decorations$acti = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
hoverDecoration = _ref2.hoverDecoration;
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
var selectedExpandNode = findSelectedParentExpandNode(state);
if (selectedExpandNode) {
var _state$schema$nodes = state.schema.nodes,
nestedExpand = _state$schema$nodes.nestedExpand,
expand = _state$schema$nodes.expand;
return {
title: 'Expand toolbar',
getDomRef: function getDomRef(view) {
return (
// Ignored via go/ees005
// eslint-disable-next-line @atlaskit/editor/no-as-casting
findDomRefAtPos(selectedExpandNode.pos, view.domAtPos.bind(view))
);
},
nodeType: [nestedExpand, expand],
offset: [0, 6],
items: [{
type: 'copy-button',
items: [{
state: state,
formatMessage: formatMessage,
nodeType: [nestedExpand, expand]
}]
}, {
type: 'separator'
}, {
id: 'editor.expand.delete',
type: 'button',
appearance: 'danger',
focusEditoronEnter: true,
icon: DeleteIcon,
onClick: deleteExpand(editorAnalyticsAPI),
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], true),
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], false),
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], true),
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration([nestedExpand, expand], false),
title: formatMessage(commonMessages.remove),
tabIndex: null
}]
};
}
return;
};
};