UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).

41 lines (33 loc) 982 B
import isString from '../util/isString' import filter from '../util/filter' import map from '../util/map' import TreeIndex from '../util/TreeIndex' import DocumentIndex from './DocumentIndex' export default class ContainerAnnotationIndex extends DocumentIndex { constructor () { super() this.byId = new TreeIndex() } select (node) { return node.isContainerAnnotation() } clear () { this.byId.clear() } get (containerPath, type) { let annotations = map(this.byId.get(String(containerPath))) if (isString(type)) { annotations = filter(annotations, DocumentIndex.filterByType) } return annotations } create (anno) { this.byId.set([String(anno.containerPath), anno.id], anno) } delete (anno) { this.byId.delete([String(anno.containerPath), anno.id]) } update(node, path, newValue, oldValue) { // eslint-disable-line // TODO should we support moving a container anno from one container to another? } }