@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
62 lines (61 loc) • 3.16 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getToolbarConfig = void 0;
var _messages = _interopRequireDefault(require("@atlaskit/editor-common/messages"));
var _delete = _interopRequireDefault(require("@atlaskit/icon/core/delete"));
var _commands = require("./commands");
var _pluginFactory = require("./pm-plugins/plugin-factory");
var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(api) {
return function (state, _ref) {
var _api$decorations$acti, _api$decorations, _api$analytics, _getPluginState;
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;
// 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.
var _ref3 = (_getPluginState = (0, _pluginFactory.getPluginState)(state)) !== null && _getPluginState !== void 0 ? _getPluginState : {},
expandRef = _ref3.expandRef;
if (expandRef) {
var _state$schema$nodes = state.schema.nodes,
nestedExpand = _state$schema$nodes.nestedExpand,
expand = _state$schema$nodes.expand;
return {
title: 'Expand toolbar',
getDomRef: function getDomRef() {
return expandRef;
},
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: _delete.default,
onClick: (0, _commands.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(_messages.default.remove),
tabIndex: null
}]
};
}
return;
};
};