@atlaskit/editor-plugin-panel
Version:
Panel plugin for @atlaskit/editor-core.
48 lines • 1.87 kB
JavaScript
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { insertSelectedItem } from '@atlaskit/editor-common/insert';
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
import { pickPanelTypeForInsertion } from '@atlaskit/editor-common/utils/node-type-utils';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
export const createPanelAction = ({
state,
attributes,
api,
typeAheadInsert,
inputMethod = INPUT_METHOD.QUICK_INSERT
}) => {
var _tr;
const panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? pickPanelTypeForInsertion(state.selection.$from) : state.schema.nodes.panel;
let tr;
if (state.selection.empty) {
var _insertSelectedItem;
const node = panelNodeType.createAndFill({
...attributes
});
if (!node) {
return false;
}
tr = typeAheadInsert ? typeAheadInsert(node) : (_insertSelectedItem = insertSelectedItem(node)(state, state.tr, state.selection.head)) === null || _insertSelectedItem === void 0 ? void 0 : _insertSelectedItem.scrollIntoView();
} else {
tr = createWrapSelectionTransaction({
state,
type: panelNodeType,
nodeAttributes: {
...attributes
}
});
}
if (tr) {
var _api$analytics;
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
action: ACTION.INSERTED,
actionSubject: ACTION_SUBJECT.DOCUMENT,
actionSubjectId: ACTION_SUBJECT_ID.PANEL,
attributes: {
inputMethod,
panelType: attributes.panelType
},
eventType: EVENT_TYPE.TRACK
})(tr);
}
return (_tr = tr) !== null && _tr !== void 0 ? _tr : false;
};