1- import { App , TFile } from 'obsidian' ;
1+ import { App } from 'obsidian' ;
22import MetaBindPlugin from './main' ;
33import { InlineAPI } from './InlineAPI' ;
4- import { InputFieldMarkdownRenderChild , InputFieldMarkdownRenderChildType } from './InputFieldMarkdownRenderChild' ;
4+ import { InputFieldMarkdownRenderChild , RenderChildType } from './InputFieldMarkdownRenderChild' ;
55import { InputFieldArgumentType , InputFieldDeclaration , InputFieldDeclarationParser , InputFieldType } from './parsers/InputFieldDeclarationParser' ;
66import { MetaBindBindTargetError , MetaBindParsingError } from './utils/MetaBindErrors' ;
77import { isTruthy } from './utils/Utils' ;
@@ -18,51 +18,50 @@ export class API {
1818 this . parser = new InputFieldDeclarationParser ( ) ;
1919 }
2020
21- public createInlineAPI ( file : TFile , container ?: HTMLElement ) : InlineAPI {
22- return new InlineAPI ( this , file , container ) ;
21+ public createInlineAPI ( filePath : string , container ?: HTMLElement ) : InlineAPI {
22+ return new InlineAPI ( this , filePath , container ) ;
2323 }
2424
2525 public createInputField (
2626 declaration : InputFieldDeclaration ,
2727 templateName : string | undefined ,
28- renderType : InputFieldMarkdownRenderChildType ,
28+ renderChildType : RenderChildType ,
2929 filePath : string ,
3030 container : HTMLElement
3131 ) : InputFieldMarkdownRenderChild {
32+ if ( ! Object . values ( RenderChildType ) . contains ( renderChildType ) ) {
33+ throw new MetaBindParsingError ( `unknown render child type '${ renderChildType } '` ) ;
34+ }
3235 declaration = this . parser . parseDeclaration ( declaration , undefined , templateName ) ;
33- return new InputFieldMarkdownRenderChild ( container , renderType , declaration , this . plugin , filePath , crypto . randomUUID ( ) ) ;
36+ return new InputFieldMarkdownRenderChild ( container , renderChildType , declaration , this . plugin , filePath , crypto . randomUUID ( ) ) ;
3437 }
3538
36- public createInputFieldFromString (
37- fullDeclaration : string ,
38- renderType : InputFieldMarkdownRenderChildType ,
39- filePath : string ,
40- container : HTMLElement
41- ) : InputFieldMarkdownRenderChild {
39+ public createInputFieldFromString ( fullDeclaration : string , renderType : RenderChildType , filePath : string , container : HTMLElement ) : InputFieldMarkdownRenderChild {
4240 const declaration : InputFieldDeclaration = this . parser . parseString ( fullDeclaration ) ;
4341 return new InputFieldMarkdownRenderChild ( container , renderType , declaration , this . plugin , filePath , crypto . randomUUID ( ) ) ;
4442 }
4543
4644 public createDeclaration (
4745 inputFieldType : InputFieldType ,
48- inputFieldArguments ?: Record < InputFieldArgumentType , string > ,
49- bindTargetFile ?: string ,
50- bindTargetField ?: string
46+ inputFieldArguments ?: { type : InputFieldArgumentType ; value : string } [ ] ,
47+ bindTargetField ?: string ,
48+ bindTargetFile ?: string
5149 ) : InputFieldDeclaration {
5250 if ( bindTargetFile && ! bindTargetField ) {
5351 throw new MetaBindBindTargetError ( 'if a bind target file is specified, a bind target field must also be specified' ) ;
5452 }
5553
5654 if ( this . parser . getInputFieldType ( inputFieldType ) === InputFieldType . INVALID ) {
57- throw new MetaBindParsingError ( `input field type ${ inputFieldType } is invalid` ) ;
55+ throw new MetaBindParsingError ( `input field type ' ${ inputFieldType } ' is invalid` ) ;
5856 }
5957
6058 return {
6159 declaration : undefined ,
6260 fullDeclaration : undefined ,
6361 inputFieldType : inputFieldType ,
62+ argumentContainer : this . parser . parseArguments ( inputFieldType , inputFieldArguments ) ,
6463 isBound : isTruthy ( bindTargetField ) ,
65- bindTarget : bindTargetFile + '#' + bindTargetField ,
64+ bindTarget : bindTargetFile ? bindTargetFile + '#' + bindTargetField : bindTargetField ,
6665 error : undefined ,
6766 } as InputFieldDeclaration ;
6867 }
0 commit comments