UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

42 lines 1.17 kB
import { pluginFactory } from '@atlaskit/editor-common/utils'; import { handleDocOrSelectionChanged } from './handlers'; import { pluginKey } from './plugin-key'; import reducer from './reducer'; export const { createPluginState, createCommand, getPluginState } = 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 });