@@ -125,50 +125,43 @@ watch(
125
125
}
126
126
}
127
127
)
128
-
129
- // Set up event listeners only after the widget is mounted and visible
130
- const setupDOMEventListeners = () => {
131
- if (! isDOMWidget (widget ) || ! widgetState .visible ) return
132
-
133
- if (widget .element .blur ) {
134
- useEventListener (document , ' mousedown' , (event ) => {
135
- if (! widget .element .contains (event .target as HTMLElement )) {
136
- widget .element .blur ()
137
- }
138
- })
128
+ useEventListener (document , ' mousedown' , (event ) => {
129
+ if (! isDOMWidget (widget ) || ! widgetState .visible || ! widget .element .blur ) {
130
+ return
131
+ }
132
+ if (! widget .element .contains (event .target as HTMLElement )) {
133
+ widget .element .blur ()
139
134
}
135
+ })
140
136
141
- for (const evt of widget .options .selectOn ?? [' focus' , ' click' ]) {
142
- useEventListener (widget .element , evt , () => {
137
+ onMounted (() => {
138
+ if (! isDOMWidget (widget )) {
139
+ return
140
+ }
141
+ useEventListener (
142
+ widget .element ,
143
+ widget .options .selectOn ?? [' focus' , ' click' ],
144
+ () => {
143
145
const lgCanvas = canvasStore .canvas
144
146
lgCanvas ?.selectNode (widget .node )
145
147
lgCanvas ?.bringToFront (widget .node )
146
- })
147
- }
148
- }
149
-
150
- // Set up event listeners when widget becomes visible
151
- watch (
152
- () => widgetState .visible ,
153
- (visible ) => {
154
- if (visible ) {
155
- setupDOMEventListeners ()
156
148
}
157
- },
158
- { immediate: true }
159
- )
149
+ )
150
+ })
160
151
161
152
const inputSpec = widget .node .constructor .nodeData
162
153
const tooltip = inputSpec ?.inputs ?.[widget .name ]?.tooltip
163
154
164
155
// Mount DOM element when widget is or becomes visible
165
156
const mountElementIfVisible = () => {
166
- if (widgetState .visible && isDOMWidget (widget ) && widgetElement .value ) {
167
- // Only append if not already a child
168
- if (! widgetElement .value .contains (widget .element )) {
169
- widgetElement .value .appendChild (widget .element )
170
- }
157
+ if (! (widgetState .visible && isDOMWidget (widget ) && widgetElement .value )) {
158
+ return
159
+ }
160
+ // Only append if not already a child
161
+ if (widgetElement .value .contains (widget .element )) {
162
+ return
171
163
}
164
+ widgetElement .value .appendChild (widget .element )
172
165
}
173
166
174
167
// Check on mount - but only after next tick to ensure visibility is calculated
0 commit comments