@@ -23,14 +23,28 @@ export default class EditPanel {
2323 this . name = panelName
2424 this . field = field
2525
26- this . props = this . createProps ( )
26+ this . panelConfig = this . getPanelConfig ( this . data )
27+
28+ if ( panelName === 'options' ) {
29+ field . addSetCallback ( `^${ panelName } ` , ( ) => {
30+ this . data = field . get ( 'options' )
31+ const { config, ...panelConfig } = this . getPanelConfig ( this . data )
32+ const editPanel = document . getElementById ( this . panelConfig . id )
33+ editPanel . replaceWith ( dom . create ( panelConfig ) )
34+ } )
35+ }
36+ }
37+
38+ getPanelConfig ( data ) {
39+ this . props = this . createProps ( data )
2740 this . editButtons = this . createEditButtons ( )
28- this . panelConfig = {
41+ return {
42+ id : `${ this . field . id } -${ this . name } -panel` ,
2943 config : {
30- label : i18n . get ( `panel.label.${ panelName } ` ) ,
44+ label : i18n . get ( `panel.label.${ this . name } ` ) ,
3145 } ,
3246 attrs : {
33- className : `f-panel ${ panelName } -panel` ,
47+ className : `f-panel ${ this . name } -panel` ,
3448 } ,
3549 children : [ this . props , this . editButtons ] ,
3650 }
@@ -42,11 +56,11 @@ export default class EditPanel {
4256 * @param {Object } dataObj field config object
4357 * @return {Object } formeo DOM config object
4458 */
45- createProps ( ) {
46- this . editPanelItems = Array . from ( this . data ) . map ( ( data , index ) => {
59+ createProps ( data ) {
60+ this . editPanelItems = Array . from ( data ) . map ( ( dataVal , index ) => {
4761 const isArray = this . type === 'array'
48- const itemKey = [ this . name , isArray ? String ( index ) : data [ 0 ] ] . join ( '.' )
49- const itemData = isArray ? data : { [ data [ 0 ] ] : data [ 1 ] }
62+ const itemKey = [ this . name , isArray ? String ( index ) : dataVal [ 0 ] ] . join ( '.' )
63+ const itemData = isArray ? dataVal : { [ dataVal [ 0 ] ] : dataVal [ 1 ] }
5064
5165 return new EditPanelItem ( { key : itemKey , data : itemData , field : this . field } )
5266 } )
0 commit comments