@@ -7,6 +7,8 @@ const textConfig = {
7
7
height : '30px' ,
8
8
fields : [
9
9
{ id : 'id' , label : 'Text ID' , type : 'text' , placeholder : 'Enter ID' } ,
10
+ { id : 'height' , label : 'Height(px)' , type : 'number' } ,
11
+ { id : 'width' , label : 'Width(px)' , type : 'number' } ,
10
12
{ id : 'value' , label : 'Text Value' , type : 'text' , placeholder : 'Enter Value' } ,
11
13
{ id : 'color' , label : 'Text Color' , type : 'color' , value : '#000000' }
12
14
]
@@ -17,6 +19,8 @@ const checkboxConfig = {
17
19
height : '20px' ,
18
20
fields : [
19
21
{ id : 'id' , label : 'Check box ID' , type : 'text' , placeholder : 'Enter ID' } ,
22
+ { id : 'height' , label : 'Height(px)' , type : 'number' } ,
23
+ { id : 'width' , label : 'Width(px)' , type : 'number' } ,
20
24
]
21
25
} ;
22
26
const dropdownConfig = {
@@ -26,6 +30,8 @@ const dropdownConfig = {
26
30
fields : [
27
31
{ id : 'id' , label : 'Dropdown ID' , type : 'text' , placeholder : 'Enter ID' } ,
28
32
{ id : 'dropdownValues' , label : 'Dropdown Options' , type : 'text' , placeholder : 'Comma-separated values' } ,
33
+ { id : 'height' , label : 'Height(px)' , type : 'number' } ,
34
+ { id : 'width' , label : 'Width(px)' , type : 'number' } ,
29
35
{ id : 'font' , label : 'Font' , type : 'select' , options : [ 'Courier' , 'Helvetica' , 'TimesRoman' ] } ,
30
36
{ id : 'fontSize' , label : 'Font Size' , type : 'number' , value : '12' } ,
31
37
{ id : 'backgroundPalette' , label : 'Background Color' , type : 'color' , value : '#ffffff' } ,
@@ -39,6 +45,8 @@ const optionListConfig = {
39
45
fields : [
40
46
{ id : 'id' , label : 'Option List ID' , type : 'text' , placeholder : 'Enter ID' } ,
41
47
{ id : 'optionListValues' , label : 'Option List Values' , type : 'text' , placeholder : 'Comma-separated values' } ,
48
+ { id : 'height' , label : 'Height(px)' , type : 'number' } ,
49
+ { id : 'width' , label : 'Width(px)' , type : 'number' } ,
42
50
{ id : 'fontSize' , label : 'Font Size' , type : 'number' , value : '12' } ,
43
51
{ id : 'backgroundPalette' , label : 'Background Color' , type : 'color' , value : '#ffffff' } ,
44
52
{ id : 'textPalette' , label : 'Text Color' , type : 'color' , value : '#000000' }
@@ -51,6 +59,8 @@ const radioButtonConfig = {
51
59
height : '20px' ,
52
60
fields : [
53
61
{ id : 'id' , label : 'Radio ID' , type : 'text' , placeholder : 'Enter ID' } ,
62
+ { id : 'height' , label : 'Height(px)' , type : 'number' } ,
63
+ { id : 'width' , label : 'Width(px)' , type : 'number' } ,
54
64
]
55
65
} ;
56
66
const textBoxConfig = {
@@ -60,6 +70,8 @@ const textBoxConfig = {
60
70
fields : [
61
71
{ id : 'id' , label : 'Text Box ID' , type : 'text' , placeholder : 'Enter ID' } ,
62
72
{ id : 'value' , label : 'Placeholder' , type : 'text' , placeholder : '' } ,
73
+ { id : 'height' , label : 'Height(px)' , type : 'number' } ,
74
+ { id : 'width' , label : 'Width(px)' , type : 'number' } ,
63
75
{ id : 'fontSize' , label : 'Font Size' , type : 'number' , value : '12' } ,
64
76
{ id : 'backgroundPalette' , label : 'Background Color' , type : 'color' , value : '#ffffff' } ,
65
77
{ id : 'textPalette' , label : 'Text Color' , type : 'color' , value : '#000000' }
@@ -243,49 +255,65 @@ function validateUniqueId(id) {
243
255
return ! document . getElementById ( id ) ;
244
256
}
245
257
246
-
247
258
function attachDynamicListeners ( fields ) {
248
- fields . forEach ( field => {
249
- document . addEventListener ( "change" , function ( event ) {
250
- if ( event . target && event . target . id === field . id ) {
251
- if ( field . type === 'color' ) {
252
- document . getElementById ( `${ field . id } Label` ) . style . setProperty ( '--palette-color' , event . target . value ) ;
253
- }
254
- if ( window . latestId ) {
255
- const targetElement = document . getElementById ( window . latestId ) ;
256
- if ( field . type === 'color' ) {
257
- if ( field . id . toLowerCase ( ) . includes ( 'background' ) ) {
258
- targetElement . style . background = event . target . value ;
259
- targetElement . setAttribute ( 'backgroundColor' , event . target . value )
260
- } else {
261
- targetElement . style . color = event . target . value ;
262
- targetElement . setAttribute ( 'textColor' , event . target . value )
263
- }
264
- } else if ( field . id === 'fontSize' ) {
265
- targetElement . style . fontSize = event . target . value + "px" ;
266
- } else if ( field . id === 'font' ) {
267
- targetElement . style . fontFamily = event . target . value ;
268
- } else if ( field . id === 'value' ) {
269
- targetElement . value = event . target . value ;
270
- } else if ( field . id === 'id' ) {
271
- targetElement . id = event . target . value ;
272
- targetElement . name = event . target . value ;
273
- } else if ( field . id === 'dropdownValues' ) {
274
- while ( targetElement ?. firstChild ) {
275
- targetElement . removeChild ( targetElement . firstChild ) ;
276
- }
277
- const values = event . target . value . split ( ',' ) . map ( v => v . trim ( ) ) ;
278
- values . forEach ( value => {
279
- const option = document . createElement ( "option" ) ;
280
- option . value = value ;
281
- option . textContent = value ;
282
- targetElement . appendChild ( option ) ;
283
- } ) ;
284
- targetElement . setAttribute ( "data-value" , values )
259
+ document . addEventListener ( "change" , function ( event ) {
260
+ const target = event . target ;
261
+ const field = fields . find ( f => f . id === target . id ) ; // Match the field
262
+
263
+ if ( ! field ) return ; // Ignore irrelevant changes
264
+
265
+ if ( field . type === 'color' ) {
266
+ document . getElementById ( `${ field . id } Label` ) . style . setProperty ( '--palette-color' , target . value ) ;
267
+ }
268
+
269
+ if ( window . latestId ) {
270
+ const targetElement = document . getElementById ( window . latestId ) ;
271
+ if ( ! targetElement ) return ;
272
+
273
+ switch ( field . id ) {
274
+ case 'backgroundColor' :
275
+ targetElement . style . background = target . value ;
276
+ targetElement . setAttribute ( 'backgroundColor' , target . value ) ;
277
+ break ;
278
+ case 'textColor' :
279
+ targetElement . style . color = target . value ;
280
+ targetElement . setAttribute ( 'textColor' , target . value ) ;
281
+ break ;
282
+ case 'height' :
283
+ window . resize ( targetElement . parentElement . parentElement , document . getElementById ( 'width' ) . value , target . value , true , "height" ) ;
284
+ break ;
285
+ case 'width' :
286
+ window . resize ( targetElement . parentElement . parentElement , target . value , document . getElementById ( 'height' ) . value , true , "width" ) ;
287
+ break ;
288
+ case 'fontSize' :
289
+ targetElement . style . fontSize = target . value + "px" ;
290
+ break ;
291
+ case 'font' :
292
+ targetElement . style . fontFamily = target . value ;
293
+ break ;
294
+ case 'value' :
295
+ targetElement . value = target . value ;
296
+ break ;
297
+ case 'id' :
298
+ targetElement . name = target . value ;
299
+ targetElement . id = target . value ;
300
+ window . latestId = target . value ;
301
+ break ;
302
+ case 'dropdownValues' :
303
+ while ( targetElement . firstChild ) {
304
+ targetElement . removeChild ( targetElement . firstChild ) ;
285
305
}
286
- }
306
+ const values = target . value . split ( ',' ) . map ( v => v . trim ( ) ) ;
307
+ values . forEach ( value => {
308
+ const option = document . createElement ( "option" ) ;
309
+ option . value = value ;
310
+ option . textContent = value ;
311
+ targetElement . appendChild ( option ) ;
312
+ } ) ;
313
+ targetElement . setAttribute ( "data-value" , values ) ;
314
+ break ;
287
315
}
288
- } ) ;
316
+ }
289
317
} ) ;
290
318
}
291
319
@@ -392,7 +420,7 @@ document.addEventListener("DOMContentLoaded", function () {
392
420
Object . keys ( existingValues ) . forEach ( key => {
393
421
const input = document . getElementById ( key ) ;
394
422
if ( input ) {
395
- input . value = existingValues [ key ] ;
423
+ input . defaultValue = existingValues [ key ] ;
396
424
if ( input . type === "color" ) {
397
425
document . getElementById ( `${ input . id } Label` ) . style . setProperty ( '--palette-color' , existingValues [ key ] ) ;
398
426
}
0 commit comments