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).
94 lines (73 loc) • 1.67 kB
JavaScript
import Component from '../dom/Component'
export default class CustomSurface extends Component {
constructor (...args) {
super(...args)
this._name = this._getCustomResourceId()
this._surfaceId = this._createSurfaceId()
}
getChildContext () {
return {
surface: this,
parentSurfaceId: this.getId()
}
}
didMount () {
const surfaceManager = this._getSurfaceManager()
surfaceManager.registerSurface(this)
}
dispose () {
const surfaceManager = this._getSurfaceManager()
surfaceManager.unregisterSurface(this)
}
rerenderDOMSelection () {
// nothing by default
}
get name () {
return this._name
}
getId () {
return this._surfaceId
}
getSurfaceId () {
return this.getId()
}
getContainer () {
return undefined
}
getContainerId () {
return undefined
}
isContainerEditor () {
return false
}
isCustomEditor () {
return true
}
isDisabled () {
return Boolean(this.props.disabled)
}
selectFirst () {
// nothing by default
}
_focus () {
// nothing by default
}
_blur () {
// nothing by default
}
_createSurfaceId () {
const isolatedNodeComponent = this.context.isolatedNodeComponent
if (isolatedNodeComponent) {
const 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')
}
_getSurfaceManager () {
return this.context.surfaceManager
}
}