55 type ButtonConfig ,
66 ButtonStyleType ,
77 type CommandButtonAction ,
8+ type CreateNoteButtonAction ,
89 type InputButtonAction ,
910 type JSButtonAction ,
1011 type OpenButtonAction ,
@@ -14,7 +15,7 @@ import {
1415} from 'packages/core/src/config/ButtonConfig' ;
1516import { MDLinkParser } from 'packages/core/src/parsers/MarkdownLinkParser' ;
1617import { Signal } from 'packages/core/src/utils/Signal' ;
17- import { getUUID , openURL } from 'packages/core/src/utils/Utils' ;
18+ import { expectType , getUUID , openURL } from 'packages/core/src/utils/Utils' ;
1819
1920export class ButtonActionRunner {
2021 plugin : IPlugin ;
@@ -81,7 +82,7 @@ export class ButtonActionRunner {
8182 return {
8283 type : ButtonActionType . TEMPLATER_CREATE_NOTE ,
8384 templateFile : '' ,
84- folderPath : '' ,
85+ folderPath : '/ ' ,
8586 fileName : '' ,
8687 openNote : true ,
8788 } satisfies TemplaterCreateNoteButtonAction ;
@@ -92,8 +93,17 @@ export class ButtonActionRunner {
9293 evaluate : false ,
9394 value : '' ,
9495 } satisfies UpdateMetadataButtonAction ;
96+ } else if ( type === ButtonActionType . CREATE_NOTE ) {
97+ return {
98+ type : ButtonActionType . CREATE_NOTE ,
99+ folderPath : '/' ,
100+ fileName : 'Untitled' ,
101+ openNote : true ,
102+ } satisfies CreateNoteButtonAction ;
95103 }
96104
105+ expectType < never > ( type ) ;
106+
97107 throw new Error ( `Unknown button action type: ${ type } ` ) ;
98108 }
99109
@@ -127,8 +137,13 @@ export class ButtonActionRunner {
127137 } else if ( action . type === ButtonActionType . UPDATE_METADATA ) {
128138 await this . runUpdateMetadataAction ( action , filePath ) ;
129139 return ;
140+ } else if ( action . type === ButtonActionType . CREATE_NOTE ) {
141+ await this . runCreateNoteAction ( action ) ;
142+ return ;
130143 }
131144
145+ expectType < never > ( action ) ;
146+
132147 throw new Error ( `Unknown button action type` ) ;
133148 }
134149
@@ -181,4 +196,8 @@ export class ButtonActionRunner {
181196 } ) ;
182197 subscription . unsubscribe ( ) ;
183198 }
199+
200+ async runCreateNoteAction ( action : CreateNoteButtonAction ) : Promise < void > {
201+ await this . plugin . internal . createFile ( action . folderPath ?? '' , action . fileName , 'md' , action . openNote ?? false ) ;
202+ }
184203}
0 commit comments