@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
55 lines • 2.53 kB
JavaScript
import commonMessages from '@atlaskit/editor-common/messages';
import DeleteIcon from '@atlaskit/icon/core/delete';
import { deleteExpand } from './commands';
import { getPluginState } from './pm-plugins/plugin-factory';
export const getToolbarConfig = api => (state, {
formatMessage
}) => {
var _api$decorations$acti, _api$decorations, _api$analytics, _getPluginState;
const {
hoverDecoration
} = (_api$decorations$acti = api === null || api === void 0 ? 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 : {};
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
// JST-1060364: We are observing this crashing the editor where the `expandPlugin` doesn't exist
// in the editor (resulting in `Cannot destructure property 'expandRef' of ...`).
// For now let's add a null check to ensure we don't crash while we investigate further.
const {
expandRef
} = (_getPluginState = getPluginState(state)) !== null && _getPluginState !== void 0 ? _getPluginState : {};
if (expandRef) {
const {
nestedExpand,
expand
} = state.schema.nodes;
return {
title: 'Expand toolbar',
getDomRef: () => expandRef,
nodeType: [nestedExpand, expand],
offset: [0, 6],
items: [{
type: 'copy-button',
items: [{
state,
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;
};