@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
31 lines • 906 B
JavaScript
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
export const pluginKey = new PluginKey('tableSizeSelectorPlugin');
export const createPlugin = dispatch => {
return new SafePlugin({
key: pluginKey,
state: {
init: () => ({
isSelectorOpen: false
}),
apply: (tr, currentPluginState) => {
const meta = tr.getMeta(pluginKey);
if (meta) {
const keys = Object.keys(meta);
const changed = keys.some(key => {
return currentPluginState[key] !== meta[key];
});
if (changed) {
const newState = {
...currentPluginState,
...meta
};
dispatch(pluginKey, newState);
return newState;
}
}
return currentPluginState;
}
}
});
};