@@ -14,7 +14,6 @@ import { EMBED_MAX_DEPTH, EmbedMDRC } from './renderChildren/EmbedMDRC';
1414import { getUUID } from './utils/Utils' ;
1515import { ObsidianAPIAdapter } from './api/internalApi/ObsidianAPIAdapter' ;
1616import { RenderChildType } from './config/FieldConfigs' ;
17- import { ButtonMDRC } from './renderChildren/ButtonMDRC' ;
1817import { ButtonBuilderModal } from './fields/button/ButtonBuilderModal' ;
1918import { InlineMDRCType , InlineMDRCUtils } from './utils/InlineMDRCUtils' ;
2019import { registerCm5HLModes } from './cm6/Cm5_Modes' ;
@@ -57,7 +56,6 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
5756
5857 // settings
5958 await this . loadSettings ( ) ;
60- await this . saveSettings ( ) ;
6159 this . addSettingTab ( new MetaBindSettingTab ( this . app , this ) ) ;
6260
6361 // check dependencies
@@ -184,8 +182,7 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
184182 }
185183
186184 this . registerMarkdownCodeBlockProcessor ( 'meta-bind-button' , ( source , el , ctx ) => {
187- const button = new ButtonMDRC ( el , source , this , ctx . sourcePath , getUUID ( ) ) ;
188- ctx . addChild ( button ) ;
185+ this . api . createButtonFromString ( source , ctx . sourcePath , el , ctx ) ;
189186 } ) ;
190187 }
191188
@@ -218,15 +215,15 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
218215 id : 'open-button-builder' ,
219216 name : 'Open Button Builder' ,
220217 callback : ( ) => {
221- new ButtonBuilderModal (
222- this ,
223- config => {
218+ new ButtonBuilderModal ( {
219+ plugin : this ,
220+ onOkay : ( config ) : void => {
224221 void window . navigator . clipboard . writeText (
225222 `\`\`\`meta-bind-button\n${ stringifyYaml ( config ) } \n\`\`\`` ,
226223 ) ;
227224 } ,
228- 'Copy to Clipboard' ,
229- ) . open ( ) ;
225+ submitText : 'Copy to Clipboard' ,
226+ } ) . open ( ) ;
230227 } ,
231228 } ) ;
232229 }
@@ -248,11 +245,18 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
248245 }
249246
250247 loadTemplates ( ) : void {
251- const templateParseErrorCollection = this . api . inputFieldParser . parseTemplates (
248+ const inputFieldTemplateParseErrorCollection = this . api . inputFieldParser . parseTemplates (
252249 this . settings . inputFieldTemplates ,
253250 ) ;
254- if ( templateParseErrorCollection . hasErrors ( ) ) {
255- console . warn ( 'meta-bind | failed to parse templates' , templateParseErrorCollection ) ;
251+ if ( inputFieldTemplateParseErrorCollection . hasErrors ( ) ) {
252+ console . warn ( 'meta-bind | failed to parse input field templates' , inputFieldTemplateParseErrorCollection ) ;
253+ }
254+
255+ const buttonTemplateParseErrorCollection = this . api . buttonManager . setButtonTemplates (
256+ this . settings . buttonTemplates ,
257+ ) ;
258+ if ( buttonTemplateParseErrorCollection . hasErrors ( ) ) {
259+ console . warn ( 'meta-bind | failed to parse button templates' , buttonTemplateParseErrorCollection ) ;
256260 }
257261 }
258262
@@ -270,11 +274,9 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
270274 async loadSettings ( ) : Promise < void > {
271275 console . log ( `meta-bind | Main >> settings load` ) ;
272276
273- let loadedSettings = ( await this . loadData ( ) ) as MetaBindPluginSettings ;
277+ const loadedSettings = ( await this . loadData ( ) ) as MetaBindPluginSettings ;
274278
275- loadedSettings = this . applyTemplatesMigration ( Object . assign ( { } , DEFAULT_SETTINGS , loadedSettings ) ) ;
276-
277- this . settings = loadedSettings ;
279+ this . settings = Object . assign ( { } , DEFAULT_SETTINGS , loadedSettings ) ;
278280
279281 await this . saveSettings ( ) ;
280282 }
@@ -289,11 +291,6 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
289291 await this . saveData ( this . settings ) ;
290292 }
291293
292- // TODO: move to internal API
293- applyTemplatesMigration ( oldSettings : MetaBindPluginSettings ) : MetaBindPluginSettings {
294- return oldSettings ;
295- }
296-
297294 // TODO: move to internal API
298295 async activateView ( viewType : string ) : Promise < void > {
299296 const { workspace } = this . app ;
0 commit comments