@@ -43,6 +43,8 @@ type ControlSpecBase = {
4343 desc ?: string ;
4444 save ?: SaveFn ;
4545 afterMount ?: ( root : HTMLElement ) => void | Promise < void > ;
46+ /** 省略时按控件 id 从 config 读取;嵌套 / 派生项需显式传入 */
47+ readConfig ?: ( ) => unknown ;
4648} ;
4749type SwitchSpec = ControlSpecBase ;
4850type NumberSpec = ControlSpecBase & {
@@ -250,7 +252,9 @@ class SettingGroupBuilder<TId extends string> {
250252 }
251253
252254 switch ( id : string , spec : SwitchSpec ) {
253- return this . registerFullItem ( id , spec , controlBoolean ( id ) ) ;
255+ return this . registerFullItem ( id , spec , controlBoolean ( id , {
256+ readConfig : spec . readConfig as ( ( ) => boolean ) | undefined ,
257+ } ) ) ;
254258 }
255259
256260 number ( id : string , spec : NumberSpec ) {
@@ -259,6 +263,7 @@ class SettingGroupBuilder<TId extends string> {
259263 max : spec . max ,
260264 step : spec . step ,
261265 unit : spec . unit ,
266+ readConfig : spec . readConfig as ( ( ) => number ) | undefined ,
262267 } ) ) ;
263268 }
264269
@@ -267,6 +272,7 @@ class SettingGroupBuilder<TId extends string> {
267272 min : spec . min ,
268273 max : spec . max ,
269274 step : spec . step ,
275+ readConfig : spec . readConfig as ( ( ) => number ) | undefined ,
270276 } ) ) ;
271277 }
272278
@@ -278,11 +284,16 @@ class SettingGroupBuilder<TId extends string> {
278284 }
279285
280286 text ( id : string , spec : TextSpec ) {
281- return this . registerFullItem ( id , spec , controlString ( id ) ) ;
287+ return this . registerFullItem ( id , spec , controlString ( id , {
288+ readConfig : spec . readConfig as ( ( ) => string ) | undefined ,
289+ } ) ) ;
282290 }
283291
284292 textBlock ( id : string , spec : TextBlockSpec ) {
285- return this . registerFullItem ( id , spec , controlTextBlock ( id , { mode : spec . mode } ) ) ;
293+ return this . registerFullItem ( id , spec , controlTextBlock ( id , {
294+ mode : spec . mode ,
295+ readConfig : spec . readConfig as ( ( ) => string ) | undefined ,
296+ } ) ) ;
286297 }
287298
288299 textPair ( spec : TextPairSpec ) {
0 commit comments