widgets: better not_editable widget flag implementation

This commit is contained in:
jean-emmanuel 2026-08-09 10:30:11 +02:00
parent 7981b6fdd6
commit 8c22384ddb
13 changed files with 32 additions and 46 deletions

View file

@ -35,7 +35,7 @@ var handleClick = function(event) {
if (!targetWidget) return
while (targetWidget._not_editable && targetWidget.parent) {
while (targetWidget.meta.not_editable && targetWidget.parent) {
targetWidget = targetWidget.parent
}

View file

@ -109,7 +109,8 @@ function updateWidget(widget, options={}) {
variables: widget.variables,
hash: widget.hash,
children: children,
index: index
index: index,
meta: widget.meta
})
newWidget.container.parentNode.replaceChild(newWidget.container, widget.container)

View file

@ -401,7 +401,7 @@ class Editor {
} else if (e.key === 'ArrowRight') {
if (curWidget.children[0] && !curWidget.children[0]._not_editable) {
if (curWidget.children[0] && !curWidget.children[0].meta.not_editable) {
toSelect = curWidget.children[0]
}

View file

@ -45,7 +45,8 @@ var Parser = class Parser {
index,
hash,
locals,
variables
variables,
meta
} = options
var props = data
@ -89,7 +90,8 @@ var Parser = class Parser {
children,
hash,
locals,
variables
variables,
meta
})
widgetManager.addWidget(widget)

View file

@ -59,14 +59,13 @@ class UiConsole extends UiSidePanel {
console._clear()
}
this.widget = new Widget({props: {id: 'CONSOLE'}, parent: widgetManager})
this.widget = new Widget({props: {id: 'CONSOLE'}, parent: widgetManager, meta: {not_editable: true}})
this.script = new Script({
widget: this.widget,
property: '',
code: 'var navigator; return eval(input_code)',
context: {input_code: ''}
})
this.widget._not_editable = true
this.widget.hash = 'CONSOLE'
this.input.addEventListener('keydown', (event)=>{

View file

@ -219,7 +219,8 @@ class Button extends Widget {
ignoreDefaults: true,
},
parentNode: this.widget,
parent: this
parent: this,
meta: {...this.meta}
})
this.decoupledValue.on('value-changed', (e)=>{
this.container.classList.toggle('on', this.decoupledValue.value)

View file

@ -189,6 +189,7 @@ class Widget extends EventEmitter {
this.hash = options.hash || 'W' + nanoid(9)
this.children = []
this.reCreateOptions = options.reCreateOptions
this.meta = options.meta || {}
this.removed = false
this.mounted = false
this.visible = true
@ -1140,7 +1141,7 @@ class Widget extends EventEmitter {
id = this.getProp('id') || this.props.id,
widget = this // used for edit link in console
while (widget._not_editable && widget.parent !== widgetManager) {
while (widget.meta.not_editable && widget.parent !== widgetManager) {
// ignore non editable
widget = widget.parent
}

View file

@ -116,15 +116,6 @@ class Clone extends Container() {
// see common/widget.js @ updateProps()
widgetManager.on('prop-src-changed', onPropChanged, {context: this})
this.on('widget-created', (e)=>{
if (e.widget !== this) {
e.widget.container.classList.add('not-editable')
e.widget._not_editable = true
}
})
}
getCloneTarget() {
@ -180,7 +171,11 @@ class Clone extends Container() {
parser.parse({
data: data,
parentNode: this.widget,
parent: this
parent: this,
meta: {
not_editable: true,
clone: true
}
})
this.updateContainer(!init)

View file

@ -56,15 +56,6 @@ class Fragment extends Container() {
this.fragmentClass = []
this.container.classList.add('empty')
this.on('widget-created', (e)=>{
if (e.widget !== this) {
e.widget.container.classList.add('not-editable')
e.widget._not_editable = true
}
})
sessionManager.on('fragment-updated', (e)=>{
var {path} = e
if (path === this.getProp('file') || path === this.getProp('fallback')) {
@ -123,7 +114,8 @@ class Fragment extends Container() {
parser.parse({
data: data,
parentNode: this.widget,
parent: this
parent: this,
meta: {not_editable: true}
})
this.updateContainer(!init)

View file

@ -135,12 +135,11 @@ class Keyboard extends Panel {
var key = parser.parse({
data: data,
parentNode: this.widget,
parent: this
parent: this,
meta: {not_editable: true}
})
key._index = i - start
key.container.classList.add('not-editable')
key._not_editable = true
key.container.classList.add('key')
if (pattern[i % 12] == 'w') {

View file

@ -82,12 +82,11 @@ class Matrix extends Panel {
var widget = parser.parse({
data: data,
parentNode: this.widget,
parent: this
parent: this,
meta: {not_editable: true}
})
widget._index = i
widget.container.classList.add('not-editable')
widget._not_editable = true
this.value[i] = widget.getValue()
@ -161,12 +160,11 @@ class Matrix extends Panel {
var widget = parser.parse({
data: data,
parentNode: this.widget,
parent: this
parent: this,
meta: {not_editable: true}
})
widget._index = i
widget.container.classList.add('not-editable')
widget._not_editable = true
}
@ -209,9 +207,6 @@ class Matrix extends Panel {
Object.assign(this.children[i].props, data)
this.children[i].updateProps(Object.keys(data), this, options)
// this.children[i] might have been recreated
this.children[i].container.classList.add('not-editable')
this.children[i]._not_editable = true
}

View file

@ -156,7 +156,8 @@ class Panel extends Container() {
parentNode: this.widget,
parent: this,
tab: true,
index: i
index: i,
meta: {...this.meta}
})
}
}
@ -198,7 +199,8 @@ class Panel extends Container() {
data: this.getProp('widgets')[i],
parentNode: this.widget,
parent: this,
index: i
index: i,
meta: {...this.meta}
})
}
}

View file

@ -178,10 +178,9 @@ class PatchBay extends Container(Canvas) {
label: k
},
parentNode: DOM.get(this.widget, '.inputs')[0],
parent: this
parent: this,
meta: {not_editable: true}
})
w.container.classList.add('not-editable')
w._not_editable = true
this.inputsWidgets.push(w)
this.inputNodes.push(w.container)
this.value[k] = []