@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
33 lines (32 loc) • 1.19 kB
JavaScript
import { AnalyticPluginTypes } from './actions';
import { createCommand, getPluginState } from './plugin-factory';
import { pluginKey } from './plugin-key';
import { getMovedPayload } from './utils/moved-event';
export const updateRowOrColumnMoved = (nextState, nextAction) => createCommand(state => {
const {
rowOrColumnMoved
} = getPluginState(state);
const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
return {
type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
data
};
}, tr => tr.setMeta('addToHistory', false));
// --- transforms, prefer these over commands to avoid an extra 'dispatch'
export const resetRowOrColumnMovedTransform = () => tr => {
const payload = {
type: AnalyticPluginTypes.RemoveRowOrColumnMovedAction
};
return tr.setMeta(pluginKey, payload);
};
export const updateRowOrColumnMovedTransform = (nextState, nextAction) => (state, tr) => {
const {
rowOrColumnMoved
} = getPluginState(state);
const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
const payload = {
type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
data
};
return tr.setMeta(pluginKey, payload);
};