11<script lang =" ts" >
2- import { ButtonBuilderModal } from ' packages/core/src/modals/modalContents/ButtonBuilderModal.ts ' ;
2+ import { ButtonBuilderModal } from ' packages/core/src/modals/modalContents/ButtonBuilderModal' ;
33 import {
4+ ButtonAction ,
45 ButtonActionType ,
56 ButtonConfig ,
67 ButtonStyleType ,
910 } from ' packages/core/src/config/ButtonConfig' ;
1011 import SettingComponent from ' packages/core/src/utils/components/SettingComponent.svelte' ;
1112 import { onDestroy } from ' svelte' ;
12- import { getUUID } from ' packages/core/src/utils/Utils' ;
13+ import { DomHelpers } from ' packages/core/src/utils/Utils' ;
1314 import Button from ' packages/core/src/utils/components/Button.svelte' ;
1415 import Icon from ' packages/core/src/utils/components/Icon.svelte' ;
1516 import ModalButtonGroup from ' packages/core/src/utils/components/ModalButtonGroup.svelte' ;
1617 import Toggle from ' packages/core/src/utils/components/Toggle.svelte' ;
17- import { ButtonBase } from ' packages/core/src/fields/button/ButtonBase' ;
1818 import { IPlugin } from ' packages/core/src/IPlugin' ;
19+ import { ButtonField } from ' packages/core/src/fields/button/ButtonField' ;
20+ import { Command } from ' packages/core/src/api/InternalAPI' ;
1921
2022 export let plugin: IPlugin ;
2123 export let modal: ButtonBuilderModal ;
2224 export let buttonConfig: ButtonConfig ;
2325
2426 let buttonEl: HTMLElement ;
25- let buttonBase: ButtonBase ;
27+ let buttonBase: ButtonField ;
2628 let addActionType: ButtonActionType ;
2729
2830 $ : updatePreviewButton (buttonConfig , buttonEl );
3436 function updatePreviewButton(config : ButtonConfig , el : HTMLElement ) {
3537 buttonBase ?.unmount ();
3638 if (el ) {
37- el .empty ();
38- buttonBase = new ButtonBase (plugin , getUUID () , ' ' , plugin . internal . stringifyYaml ( config ) , true );
39+ DomHelpers .empty (el );
40+ buttonBase = new ButtonField (plugin , config , ' ' , false , true );
3941 buttonBase .mount (el );
4042 }
4143 }
4749 }
4850
4951 function removeAction(id : number ) {
50- buttonConfig .actions .splice (id , 1 );
52+ buttonConfig .actions ? .splice (id , 1 );
5153 buttonConfig .actions = buttonConfig .actions ;
5254 }
5355
54- function commandActionChangeCommand(action : CommandButtonAction ) {
56+ function commandActionChangeCommand(action : ButtonAction ) {
57+ if (action .type !== ButtonActionType .COMMAND ) {
58+ return ;
59+ }
60+
5561 plugin .internal .openCommandSelectModal ((command : Command ) => {
5662 action .command = command .id ;
5763 buttonConfig .actions = buttonConfig .actions ;
5864 });
5965 }
6066
61- function templaterCreateNoteActionChangeTemplateFile(action : TemplaterCreateNoteButtonAction ) {
67+ function templaterCreateNoteActionChangeTemplateFile(action : ButtonAction ) {
68+ if (action .type !== ButtonActionType .TEMPLATER_CREATE_NOTE ) {
69+ return ;
70+ }
71+
6272 plugin .internal .openFileSelectModal ((file : string ) => {
6373 action .templateFile = file ;
6474 buttonConfig .actions = buttonConfig .actions ;
6575 });
6676 }
6777
68- function templaterCreateNoteActionChangeFolderPath(action : TemplaterCreateNoteButtonAction ) {
78+ function templaterCreateNoteActionChangeFolderPath(action : ButtonAction ) {
79+ if (action .type !== ButtonActionType .TEMPLATER_CREATE_NOTE ) {
80+ return ;
81+ }
82+
6983 plugin .internal .openFolderSelectModal ((folder : string ) => {
7084 action .folderPath = folder ;
7185 buttonConfig .actions = buttonConfig .actions ;
@@ -139,18 +153,19 @@ Add action of type
139153 {/each }
140154</select >
141155
142- <Button variant ="primary" on:click ={() => addAction ()}>Add Action</Button >
156+ <Button variant ={ ButtonStyleType . PRIMARY } on:click ={() => addAction ()}>Add Action</Button >
143157
144- {#each buttonConfig .actions as action , i (i )}
158+ {#each buttonConfig .actions ?? [] as action , i (i )}
145159 <h5 >{getActionLabel (action .type )}</h5 >
146160
147161 {#if action .type === ButtonActionType .COMMAND }
148162 <SettingComponent
149163 name ="Command: {action .command || ' none' }"
150164 description =" The command to execute when this action runs."
151165 >
152- <Button variant ="primary" on:click ={() => commandActionChangeCommand (action )}>Change</Button >
153- <Button variant ="destructive" on:click ={() => removeAction (i )}>
166+ <Button variant ={ButtonStyleType .PRIMARY } on:click ={() => commandActionChangeCommand (action )}>Change</Button
167+ >
168+ <Button variant ={ButtonStyleType .DESTRUCTIVE } on:click ={() => removeAction (i )}>
154169 <Icon plugin ={modal .plugin } iconName =" x" ></Icon >
155170 </Button >
156171 </SettingComponent >
@@ -159,7 +174,7 @@ Add action of type
159174 {#if action .type === ButtonActionType .OPEN }
160175 <SettingComponent name =" Link" description =" The link to open." >
161176 <input type ="text" bind:value ={action .link } placeholder =" [[Some Note]] or https://www.example.com" />
162- <Button variant ="destructive" on:click ={() => removeAction (i )}>
177+ <Button variant ={ ButtonStyleType . DESTRUCTIVE } on:click ={() => removeAction (i )}>
163178 <Icon plugin ={modal .plugin } iconName =" x" ></Icon >
164179 </Button >
165180 </SettingComponent >
@@ -168,7 +183,7 @@ Add action of type
168183 {#if action .type === ButtonActionType .JS }
169184 <SettingComponent name =" JS File" description =" The JavaScript file to run." >
170185 <input type ="text" bind:value ={action .file } placeholder =" someJsFile.js" />
171- <Button variant ="destructive" on:click ={() => removeAction (i )}>
186+ <Button variant ={ ButtonStyleType . DESTRUCTIVE } on:click ={() => removeAction (i )}>
172187 <Icon plugin ={modal .plugin } iconName =" x" ></Icon >
173188 </Button >
174189 </SettingComponent >
@@ -177,7 +192,7 @@ Add action of type
177192 {#if action .type === ButtonActionType .INPUT }
178193 <SettingComponent name =" Text" description =" The text to input at the cursor." >
179194 <input type ="text" bind:value ={action .str } placeholder =" some text" />
180- <Button variant ="destructive" on:click ={() => removeAction (i )}>
195+ <Button variant ={ ButtonStyleType . DESTRUCTIVE } on:click ={() => removeAction (i )}>
181196 <Icon plugin ={modal .plugin } iconName =" x" ></Icon >
182197 </Button >
183198 </SettingComponent >
@@ -186,20 +201,22 @@ Add action of type
186201 {#if action .type === ButtonActionType .SLEEP }
187202 <SettingComponent name =" Sleep Time" description =" The time to sleep in milliseconds." >
188203 <input type ="number" bind:value ={action .ms } placeholder =" 100 ms" />
189- <Button variant ="destructive" on:click ={() => removeAction (i )}>
204+ <Button variant ={ ButtonStyleType . DESTRUCTIVE } on:click ={() => removeAction (i )}>
190205 <Icon plugin ={modal .plugin } iconName =" x" ></Icon >
191206 </Button >
192207 </SettingComponent >
193208 {/if }
194209
195210 {#if action .type === ButtonActionType .TEMPLATER_CREATE_NOTE }
196- <Button variant ="destructive" on:click ={() => removeAction (i )}>Remove Action</Button >
211+ <Button variant ={ ButtonStyleType . DESTRUCTIVE } on:click ={() => removeAction (i )}>Remove Action</Button >
197212
198213 <SettingComponent
199214 name ="Template File: {action .templateFile || ' none' }"
200215 description =" The template file to create a new note of."
201216 >
202- <Button variant ="primary" on:click ={() => templaterCreateNoteActionChangeTemplateFile (action )}
217+ <Button
218+ variant ={ButtonStyleType .PRIMARY }
219+ on:click ={() => templaterCreateNoteActionChangeTemplateFile (action )}
203220 >Change
204221 </Button >
205222 </SettingComponent >
@@ -208,7 +225,9 @@ Add action of type
208225 name ="Folder: {action .folderPath || ' none' }"
209226 description =" The folder to create a new note in."
210227 >
211- <Button variant ="primary" on:click ={() => templaterCreateNoteActionChangeFolderPath (action )}>Change</Button >
228+ <Button variant ={ButtonStyleType .PRIMARY } on:click ={() => templaterCreateNoteActionChangeFolderPath (action )}
229+ >Change</Button
230+ >
212231 </SettingComponent >
213232
214233 <SettingComponent name ="File Name: {action .fileName || ' default' }" description =" The file name of the new note." >
@@ -221,7 +240,7 @@ Add action of type
221240 {/if }
222241
223242 {#if action .type === ButtonActionType .UPDATE_METADATA }
224- <Button variant ="destructive" on:click ={() => removeAction (i )}>Remove Action</Button >
243+ <Button variant ={ ButtonStyleType . DESTRUCTIVE } on:click ={() => removeAction (i )}>Remove Action</Button >
225244
226245 <SettingComponent name =" Metadata Property" description =" The metadata property in form of a bind target." >
227246 <input type ="text" bind:value ={action .bindTarget } placeholder =" some value" />
@@ -242,6 +261,8 @@ Add action of type
242261<div bind:this ={buttonEl }></div >
243262
244263<ModalButtonGroup >
245- <Button variant ="primary" on:click ={() => modal .okay (buttonConfig )}>{modal .options .submitText }</Button >
246- <Button variant ="default" on:click ={() => modal .cancel ()}>Cancel</Button >
264+ <Button variant ={ButtonStyleType .PRIMARY } on:click ={() => modal .okay (buttonConfig )}
265+ >{modal .options .submitText }</Button
266+ >
267+ <Button variant ={ButtonStyleType .DEFAULT } on:click ={() => modal .cancel ()}>Cancel</Button >
247268</ModalButtonGroup >
0 commit comments