scopes: fix some issues in clone and adapt scrollbar

This commit is contained in:
jean-emmanuel 2026-08-13 18:03:57 +02:00
parent 08b837ff98
commit 83456acbff
2 changed files with 39 additions and 17 deletions

View file

@ -71,10 +71,10 @@ class Clone extends Container() {
this.getCloneTarget()
// global listener to catch cloneTarget's creation if no target is locked
widgetManager.on('widget-created', (e)=>{
if (this.cloneTarget) return
// if in a non-scoped context we don't watch for a closer target once we have one
if (!this.scopes.length && this.cloneTarget) return
var {id, widget} = e
@ -114,13 +114,13 @@ class Clone extends Container() {
// attempt to acquire a cloneTarget if 'widget-created' event has not been caught
// (the target might have been created before the clone itself)
var scopes = this.prefixId || [''],
var scopes = this.scopes.length ? this.scopes : [''],
target = null,
rank = 0
for (var scope of scopes) {
var widgets = widgetManager.getWidgetById(this.getProp('widgetId'), scope)
.filter(el=>this.isValidCloneTarget(el))
.filter(w=>this.isValidCloneTarget(w))
target = widgets[0]
if (!target) continue

View file

@ -43,6 +43,7 @@ export default class Scrollbar extends StaticProperties(Fader, {
super(options)
this.scrollTarget = null
this.targetRank = null
this.thumbSize = 1
if (!this.getProp('horizontal')) {
@ -50,29 +51,48 @@ export default class Scrollbar extends StaticProperties(Fader, {
this.rangeVals[1] = 0
}
this.getScrollTarget()
widgetManager.on('widget-created', (e)=>{
if (this.scrollTarget) return
// if in a non-scoped context we don't watch for a closer target once we have one
if (!this.scopes.length && this.scrollTarget) return
var {id, widget} = e
if (id === this.getProp('widgetId') && widget.getProp('scroll')) {
this.unbindTarget()
this.bindTarget(widget)
if (id.includes(this.getProp('widgetId')) && widget.getProp('scroll')) {
this.getScrollTarget()
}
}, {context: this})
var widgets = widgetManager.getWidgetById(this.getProp('widgetId'))
for (var widget of widgets) {
if (widget.getProp('scroll')) {
this.unbindTarget()
this.bindTarget(widget)
break
}
}
}
getScrollTarget() {
var scopes = this.scopes.length ? this.scopes : [''],
target = null,
rank = 0
for (var scope of scopes) {
var widgets = widgetManager.getWidgetById(this.getProp('widgetId'), scope)
.filter(w=w.getProp('scroll'))
target = widgets[0]
if (!target) continue
if (target && (rank < this.targetRank || this.targetRank == null)) {
this.unbindTarget()
this.bindTarget(target, rank)
return
}
rank++
}
}
draginitHandle(e) {
@ -134,13 +154,15 @@ export default class Scrollbar extends StaticProperties(Fader, {
this.scrollTarget.off(undefined, undefined, this)
this.scrollTarget = null
this.targetRank = null
}
bindTarget(target) {
bindTarget(target, rank) {
if (!target) return
this.scrollTarget = target
this.targetRank = rank
this.scrollTarget.on('widget-removed', (e)=>{
if (this.scrollTarget === e.widget) {