@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
70 lines (68 loc) • 3.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createPlugin = void 0;
var _analytics = require("@atlaskit/editor-common/analytics");
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
var _misc = require("../commands/misc");
var _commands = require("./commands");
var _pluginFactory = require("./plugin-factory");
var _pluginKey = require("./plugin-key");
var _types = require("./types");
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent) {
return new _safePlugin.SafePlugin({
key: _pluginKey.pluginKey,
state: (0, _pluginFactory.createPluginState)(dispatch, _types.defaultState),
appendTransaction: function appendTransaction(transactions, oldState, newState) {
var tr = transactions.find(function (tr) {
var _tr$getMeta;
return (_tr$getMeta = tr.getMeta(_pluginKey.pluginKey)) === null || _tr$getMeta === void 0 || (_tr$getMeta = _tr$getMeta.data) === null || _tr$getMeta === void 0 || (_tr$getMeta = _tr$getMeta.currentActions) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.includes('pasted');
});
if (tr) {
var _tr$getMeta2;
var newTr = newState.tr;
dispatchAnalyticsEvent({
action: _analytics.TABLE_ACTION.ROW_OR_COLUMN_MOVED,
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
actionSubjectId: null,
eventType: _analytics.EVENT_TYPE.TRACK,
attributes: {
type: (_tr$getMeta2 = tr.getMeta(_pluginKey.pluginKey)) === null || _tr$getMeta2 === void 0 || (_tr$getMeta2 = _tr$getMeta2.data) === null || _tr$getMeta2 === void 0 ? void 0 : _tr$getMeta2.type
}
});
return (0, _commands.resetRowOrColumnMovedTransform)()(newTr);
}
return undefined;
},
props: {
handlePaste: function handlePaste(_ref, event, slice) {
var state = _ref.state,
dispatch = _ref.dispatch;
var schema = state.schema;
var type = (0, _misc.getTableElementMoveTypeBySlice)(slice, state);
// if the selection wasn't in the first cell of a row or column, don't count it
if (!type || !(0, _misc.isInsideFirstCellOfRowOrColumn)(state.selection, type)) {
return;
}
var count = (0, _misc.countCellsInSlice)(slice, schema, type);
(0, _commands.updateRowOrColumnMoved)({
numberOfCells: count,
type: type
}, 'pasted')(state, dispatch);
},
transformCopied: function transformCopied(slice, _ref2) {
var state = _ref2.state,
dispatch = _ref2.dispatch;
var schema = state.schema;
var type = (0, _misc.getTableSelectionType)(state.selection);
var count = (0, _misc.countCellsInSlice)(slice, schema, type);
(0, _commands.updateRowOrColumnMoved)({
numberOfCells: count,
type: type
}, 'copyOrCut')(state, dispatch);
return slice;
}
}
});
};