UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

41 lines 1.26 kB
import { pluginFactory } from '@atlaskit/editor-common/utils'; import { handleDocOrSelectionChanged } from './handlers'; import { pluginKey } from './plugin-key'; import reducer from './reducer'; const dest = pluginFactory(pluginKey, reducer, { mapping: (tr, pluginState) => { if (tr.docChanged) { let updatedTargetCell = {}; if (pluginState.targetCellPosition) { const { pos, deleted } = tr.mapping.mapResult(pluginState.targetCellPosition); updatedTargetCell = { targetCellPosition: deleted ? undefined : pos }; } let updatedTablePos = {}; if (pluginState.tablePos) { const { pos, deleted } = tr.mapping.mapResult(pluginState.tablePos, -1); updatedTablePos = { tablePos: deleted ? undefined : pos }; } return { ...pluginState, ...updatedTargetCell, ...updatedTablePos }; } return pluginState; }, onDocChanged: handleDocOrSelectionChanged, onSelectionChanged: handleDocOrSelectionChanged }); export const createPluginState = dest.createPluginState; export const createCommand = dest.createCommand; export const getPluginState = dest.getPluginState;