@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
36 lines (35 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.replaceSelectedTable = void 0;
var _analytics = require("@atlaskit/editor-common/analytics");
var _model = require("@atlaskit/editor-prosemirror/model");
var _state = require("@atlaskit/editor-prosemirror/state");
var _utils = require("@atlaskit/editor-tables/utils");
var _analytics2 = require("../utils/analytics");
var replaceSelectedTable = exports.replaceSelectedTable = function replaceSelectedTable(state, content, inputMethod, editorAnalyticsAPI) {
if ((0, _utils.isTableSelected)(state.selection)) {
var table = (0, _utils.findTable)(state.selection);
if (table) {
var slice = typeof content === 'string' ? new _model.Slice(_model.Fragment.from(state.schema.text(content)), 0, 0) : content;
var tr = state.tr.replace(table.pos, table.pos + table.node.nodeSize, slice);
tr.setSelection(_state.TextSelection.create(tr.doc, table.pos + slice.size + 1));
var _getSelectedTableInfo = (0, _analytics2.getSelectedTableInfo)(state.selection),
totalRowCount = _getSelectedTableInfo.totalRowCount,
totalColumnCount = _getSelectedTableInfo.totalColumnCount;
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
action: _analytics.TABLE_ACTION.REPLACED,
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
attributes: {
totalColumnCount: totalColumnCount,
totalRowCount: totalRowCount,
inputMethod: inputMethod
},
eventType: _analytics.EVENT_TYPE.TRACK
})(tr);
return tr;
}
}
return state.tr;
};