MCPcopy Create free account
hub / github.com/PaulleDemon/PyUIBuilder / getWidgetFromTarget

Function getWidgetFromTarget

src/canvas/canvas.js:204–229  ·  view source on GitHub ↗

* returns the widget that contains the target * @param {HTMLElement} target * @returns {Widget}

(target)

Source from the content-addressed store, hash-verified

202 * @returns {Widget}
203 */
204 getWidgetFromTarget(target) {
205 // TODO: improve search, currently O(n), but can be improved via this.widgets or something
206
207 let innerWidget = null
208 for (let [key, ref] of Object.entries(this.widgetRefs.current)) {
209
210 if (ref.current === target) {
211 innerWidget = ref.current
212 break
213 }
214
215 // console.log("refs: ", ref)
216 // TODO: remove the ref.current? if there are bugs it would become hard to debug
217 if (ref.current?.getElement().contains(target)) {
218
219 if (!innerWidget) {
220 innerWidget = ref.current
221 } else if (innerWidget.getElement().contains(ref.current.getElement())) {
222 // If the current widget is deeper than the existing innermost widget, update innerWidget
223 innerWidget = ref.current
224 }
225 }
226 }
227
228 return innerWidget
229 }
230
231 keyDownEvent(event) {
232

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected