@@ -32,16 +32,23 @@ <h1>JSON Visual Editor</h1>
3232
3333 < script type ="module ">
3434 const jsonEditor = document . getElementById ( 'json-editor' ) ;
35- console . log ( typeof mcAPI . getConfig ( 'launcher' ) )
3635 const jsonData = await mcAPI . getConfig ( 'launcher' ) || { } ;
37- console . log ( jsonData )
3836
3937 window . addEntry = function ( key = '' , value = '' ) {
4038 const entryDiv = document . createElement ( 'div' ) ;
4139 entryDiv . className = 'json-entry' ;
40+
41+ const inputType = typeof value === 'boolean' ? 'checkbox'
42+ : typeof value === 'number' ? 'number'
43+ : 'text' ;
44+
45+ const isCheckbox = inputType === 'checkbox' ;
46+ const valueAttr = isCheckbox ? '' : `value="${ value } "` ;
47+ const checkedAttr = isCheckbox && value ? 'checked' : '' ;
48+
4249 entryDiv . innerHTML = `
4350 <input type="text" placeholder="Key" value="${ key } " oninput="updateJson(this, 'key')">
44- <input type="text" placeholder="Value" value=" ${ value } " oninput="updateJson(this, 'value')">
51+ <input type="${ inputType } " ${ valueAttr } ${ checkedAttr } oninput="updateJson(this, 'value')">
4552 <button onclick="removeEntry(this)">Remove</button>
4653 ` ;
4754 jsonEditor . appendChild ( entryDiv ) ;
@@ -51,15 +58,27 @@ <h1>JSON Visual Editor</h1>
5158 const entryDiv = input . parentElement ;
5259 const keyInput = entryDiv . children [ 0 ] ;
5360 const valueInput = entryDiv . children [ 1 ] ;
61+
62+ const oldKey = keyInput . dataset . oldKey || keyInput . value ;
5463 const key = keyInput . value ;
55- const value = valueInput . value ;
5664
5765 if ( type === 'key' ) {
58- delete jsonData [ keyInput . dataset . oldKey ] ;
66+ if ( oldKey && oldKey !== key ) {
67+ delete jsonData [ oldKey ] ;
68+ }
5969 keyInput . dataset . oldKey = key ;
6070 }
6171
6272 if ( key ) {
73+ let value ;
74+ if ( valueInput . type === 'checkbox' ) {
75+ value = valueInput . checked ;
76+ } else if ( valueInput . type === 'number' ) {
77+ value = parseFloat ( valueInput . value ) ;
78+ } else {
79+ value = valueInput . value ;
80+ }
81+
6382 jsonData [ key ] = value ;
6483 }
6584 }
@@ -91,4 +110,3 @@ <h1>JSON Visual Editor</h1>
91110 </ script >
92111</ body >
93112</ html >
94-
0 commit comments