1- import { z } from 'zod' ;
2- import { oneOf , schemaForType } from '../utils/ZodUtils' ;
3-
41export enum ButtonStyleType {
52 DEFAULT = 'default' ,
63 PRIMARY = 'primary' ,
@@ -22,61 +19,26 @@ export interface CommandButtonAction {
2219 command : string ;
2320}
2421
25- export const CommandButtonActionValidator = schemaForType < CommandButtonAction > ( ) (
26- z . object ( {
27- type : z . literal ( ButtonActionType . COMMAND ) ,
28- command : z . string ( ) ,
29- } ) ,
30- ) ;
31-
3222export interface JSButtonAction {
3323 type : ButtonActionType . JS ;
3424 file : string ;
3525}
3626
37- export const JSButtonActionValidator = schemaForType < JSButtonAction > ( ) (
38- z . object ( {
39- type : z . literal ( ButtonActionType . JS ) ,
40- file : z . string ( ) ,
41- } ) ,
42- ) ;
43-
4427export interface OpenButtonAction {
4528 type : ButtonActionType . OPEN ;
4629 link : string ;
4730}
4831
49- export const OpenButtonActionValidator = schemaForType < OpenButtonAction > ( ) (
50- z . object ( {
51- type : z . literal ( ButtonActionType . OPEN ) ,
52- link : z . string ( ) ,
53- } ) ,
54- ) ;
55-
5632export interface InputButtonAction {
5733 type : ButtonActionType . INPUT ;
5834 str : string ;
5935}
6036
61- export const InputButtonActionValidator = schemaForType < InputButtonAction > ( ) (
62- z . object ( {
63- type : z . literal ( ButtonActionType . INPUT ) ,
64- str : z . string ( ) ,
65- } ) ,
66- ) ;
67-
6837export interface SleepButtonAction {
6938 type : ButtonActionType . SLEEP ;
7039 ms : number ;
7140}
7241
73- export const SleepButtonActionValidator = schemaForType < SleepButtonAction > ( ) (
74- z . object ( {
75- type : z . literal ( ButtonActionType . SLEEP ) ,
76- ms : z . number ( ) ,
77- } ) ,
78- ) ;
79-
8042export interface TemplaterCreateNoteButtonAction {
8143 type : ButtonActionType . TEMPLATER_CREATE_NOTE ;
8244 templateFile : string ;
@@ -85,16 +47,6 @@ export interface TemplaterCreateNoteButtonAction {
8547 openNote ?: boolean ;
8648}
8749
88- export const TemplaterCreateNoteButtonActionValidator = schemaForType < TemplaterCreateNoteButtonAction > ( ) (
89- z . object ( {
90- type : z . literal ( ButtonActionType . TEMPLATER_CREATE_NOTE ) ,
91- templateFile : z . string ( ) ,
92- folderPath : z . string ( ) . optional ( ) ,
93- fileName : z . string ( ) . optional ( ) ,
94- openNote : z . boolean ( ) . optional ( ) ,
95- } ) ,
96- ) ;
97-
9850export type ButtonAction =
9951 | CommandButtonAction
10052 | JSButtonAction
@@ -103,38 +55,13 @@ export type ButtonAction =
10355 | SleepButtonAction
10456 | TemplaterCreateNoteButtonAction ;
10557
106- export const ButtonActionValidator = schemaForType < ButtonAction > ( ) (
107- z . union ( [
108- CommandButtonActionValidator ,
109- JSButtonActionValidator ,
110- OpenButtonActionValidator ,
111- InputButtonActionValidator ,
112- SleepButtonActionValidator ,
113- TemplaterCreateNoteButtonActionValidator ,
114- ] ) ,
115- ) ;
116-
11758export interface ButtonConfig {
11859 label : string ;
11960 style : ButtonStyleType ;
61+ class ?: string ;
62+ tooltip ?: string ;
12063 id ?: string ;
12164 hidden ?: boolean ;
12265 action ?: ButtonAction ;
12366 actions ?: ButtonAction [ ] ;
12467}
125-
126- type Tuple < T > = [ T , ...T [ ] ] ;
127- export const ButtonStyleValidator = z . enum ( Object . values ( ButtonStyleType ) as Tuple < ButtonStyleType > ) ;
128-
129- export const ButtonConfigValidator = schemaForType < ButtonConfig > ( ) (
130- z
131- . object ( {
132- label : z . string ( ) ,
133- style : ButtonStyleValidator ,
134- id : z . string ( ) . optional ( ) ,
135- hidden : z . boolean ( ) . optional ( ) ,
136- action : ButtonActionValidator . optional ( ) ,
137- actions : ButtonActionValidator . array ( ) . optional ( ) ,
138- } )
139- . superRefine ( oneOf ( 'action' , 'actions' ) ) ,
140- ) ;
0 commit comments