MCPcopy Create free account
hub / github.com/tree-sitter/tree-sitter-javascript / OverlayComponent

Class OverlayComponent

examples/text-editor-component.js:4211–4284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4209}
4210
4211class OverlayComponent {
4212 constructor (props) {
4213 this.props = props
4214 this.element = document.createElement('atom-overlay')
4215 if (this.props.className != null) this.element.classList.add(this.props.className)
4216 this.element.appendChild(this.props.element)
4217 this.element.style.position = 'fixed'
4218 this.element.style.zIndex = 4
4219 this.element.style.top = (this.props.pixelTop || 0) + 'px'
4220 this.element.style.left = (this.props.pixelLeft || 0) + 'px'
4221 this.currentContentRect = null
4222
4223 // Synchronous DOM updates in response to resize events might trigger a
4224 // "loop limit exceeded" error. We disconnect the observer before
4225 // potentially mutating the DOM, and then reconnect it on the next tick.
4226 // Note: ResizeObserver calls its callback when .observe is called
4227 this.resizeObserver = new ResizeObserver((entries) => {
4228 const {contentRect} = entries[0]
4229
4230 if (
4231 this.currentContentRect &&
4232 (this.currentContentRect.width !== contentRect.width ||
4233 this.currentContentRect.height !== contentRect.height)
4234 ) {
4235 this.resizeObserver.disconnect()
4236 this.props.didResize(this)
4237 process.nextTick(() => { this.resizeObserver.observe(this.props.element) })
4238 }
4239
4240 this.currentContentRect = contentRect
4241 })
4242 this.didAttach()
4243 this.props.overlayComponents.add(this)
4244 }
4245
4246 destroy () {
4247 this.props.overlayComponents.delete(this)
4248 this.didDetach()
4249 }
4250
4251 getNextUpdatePromise () {
4252 if (!this.nextUpdatePromise) {
4253 this.nextUpdatePromise = new Promise((resolve) => {
4254 this.resolveNextUpdatePromise = () => {
4255 this.nextUpdatePromise = null
4256 this.resolveNextUpdatePromise = null
4257 resolve()
4258 }
4259 })
4260 }
4261 return this.nextUpdatePromise
4262 }
4263
4264 update (newProps) {
4265 const oldProps = this.props
4266 this.props = Object.assign({}, oldProps, newProps)
4267 if (this.props.pixelTop != null) this.element.style.top = this.props.pixelTop + 'px'
4268 if (this.props.pixelLeft != null) this.element.style.left = this.props.pixelLeft + 'px'

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…