contenido
Version:
Contenido is a library with a set of tools to help you create your own rich text editor on top of draft-js without thinking about how to handle things.
28 lines (22 loc) • 720 B
text/typescript
// Core
import { EditorState } from '../../core';
// Types
import type { Attributes, State, StateHandler } from '../../types';
type NewEntityData = Attributes | { [key: string]: any };
const updateAtomicData = (
state: State,
stateHandler: StateHandler,
entityKey: string,
newData: NewEntityData
) => {
const contentState = state.getCurrentContent();
const entity = contentState.getEntity(entityKey);
const newEntityData = { ...entity.getData(), ...newData };
const newContentState = contentState.mergeEntityData(
entityKey,
newEntityData
);
const updatedState = EditorState.push(state, newContentState, 'apply-entity');
stateHandler(updatedState);
};
export default updateAtomicData;