@@ -34,10 +34,12 @@ export default class AdvancedMap extends Setting {
3434 * @param {Map<any, any> } val
3535 */
3636 element ( val , update , {
37- container, data : { keyData , valueData , leftData , rightData } = { } , disabled, key, name, untilClose,
37+ container, data : mapData = { } , disabled, key, name, untilClose,
3838 } = { } ) {
3939 // TODO: validate that disabled propagates properly
4040 const data = [ ...val . entries ( ) ] ;
41+ const dataKey = getData ( mapData ) ;
42+ const dataValue = getData ( mapData , true ) ;
4143 let entries = data . length ;
4244 const add = ( lineValue , id ) => {
4345 function save ( remove ) {
@@ -47,7 +49,6 @@ export default class AdvancedMap extends Setting {
4749 }
4850 const line = $ ( '<div class="item">' ) ;
4951 const options = { container : $ ( '<div>' ) , name, disabled, remove : false , removeSetting ( ) { } , key : `${ key } .${ id } ` , child : true } ;
50- const dataKey = keyData || leftData ;
5152 const left = $ ( this . #keyType. element ( this . #keyValue( lineValue [ 0 ] , dataKey ) , ( newValue ) => {
5253 // TODO: validate this is how it's supposed to work
5354 const isInvalid = newValue !== lineValue [ 0 ] && data . some ( ( [ keyValue ] ) => keyValue === newValue ) ;
@@ -59,7 +60,6 @@ export default class AdvancedMap extends Setting {
5960 ...options ,
6061 data : dataKey ,
6162 } ) ) ;
62- const dataValue = valueData || rightData ;
6363 const right = $ ( this . #valueType. element ( this . #value( lineValue [ 1 ] , dataValue ) , ( newValue ) => {
6464 if ( newValue === lineValue [ 1 ] ) return ;
6565 lineValue [ 1 ] = newValue ;
@@ -88,8 +88,8 @@ export default class AdvancedMap extends Setting {
8888 data . forEach ( add ) ;
8989 return $ ( '<button class="btn btn-success glyphicon glyphicon-plus">' ) . on ( 'click' , ( ) => {
9090 const item = [
91- this . #keyType. default ( keyData ) ?? '' ,
92- this . #valueType. default ( valueData ) ?? '' ,
91+ this . #keyType. default ( dataKey ) ?? '' ,
92+ this . #valueType. default ( dataValue ) ?? '' ,
9393 ] ;
9494 data . push ( item ) ;
9595 add ( item , entries ) ;
@@ -136,3 +136,10 @@ export default class AdvancedMap extends Setting {
136136 return registered ;
137137 }
138138}
139+
140+ function getData ( { key, keyData, leftData, value, valueData, rightData } = { } , secondary = false ) {
141+ if ( secondary ) {
142+ return value || valueData || rightData ;
143+ }
144+ return key || keyData || leftData ;
145+ }
0 commit comments