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 systems.
72 lines (55 loc) • 1.36 kB
JavaScript
import Component from './Component'
export default class CustomSurface extends Component {
constructor(...args) {
super(...args)
this._name = this._getCustomResourceId()
this._surfaceId = this._createSurfaceId()
}
didMount() {
const surfaceManager = this.context.editorSession.surfaceManager
surfaceManager.registerSurface(this)
}
dispose() {
const surfaceManager = this.context.editorSession.surfaceManager
surfaceManager.unregisterSurface(this)
}
rerenderDOMSelection() {
// nothing by default
}
get name() {
return this._name
}
getId() {
return this._surfaceId
}
getContainer() {
return undefined
}
getContainerId() {
return undefined
}
isContainerEditor() {
return false
}
isCustomEditor() {
return true
}
isDisabled() {
return Boolean(this.props.disabled)
}
_focus() {
// nothing by default
}
_createSurfaceId() {
let isolatedNodeComponent = this.context.isolatedNodeComponent
if (isolatedNodeComponent) {
let parentSurface = isolatedNodeComponent.context.surface
return parentSurface.id + '/' + isolatedNodeComponent.props.node.id + '/' + this._name
} else {
return this._name
}
}
_getCustomResourceId() {
throw new Error('This method needs to be implemented by a CustomSurface')
}
}