1- import { type RefinementCtx , z } from 'zod' ;
2-
3- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4- function schemaForType < T > ( ) : < S extends z . ZodType < T , any , any > > ( arg : S ) => S {
5- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6- return function < S extends z . ZodType < T , any , any > > ( arg : S ) : S {
7- return arg ;
8- } ;
9- }
1+ import { z } from 'zod' ;
2+ import { oneOf , schemaForType } from '../utils/ZodHelpers' ;
103
114export enum ButtonStyleType {
125 DEFAULT = 'default' ,
@@ -19,6 +12,10 @@ export enum ButtonActionType {
1912 COMMAND = 'command' ,
2013 JS = 'js' ,
2114 OPEN = 'open' ,
15+ INPUT = 'input' ,
16+ SLEEP = 'sleep' ,
17+ TEMPLATER_CREATE_NOTE = 'templaterCreateNote' ,
18+ QUICK_SWITCHER = 'quickSwitcher' ,
2219}
2320
2421export interface CommandButtonAction {
@@ -35,13 +32,13 @@ export const CommandButtonActionValidator = schemaForType<CommandButtonAction>()
3532
3633export interface JSButtonAction {
3734 type : ButtonActionType . JS ;
38- jsFile : string ;
35+ file : string ;
3936}
4037
4138export const JSButtonActionValidator = schemaForType < JSButtonAction > ( ) (
4239 z . object ( {
4340 type : z . literal ( ButtonActionType . JS ) ,
44- jsFile : z . string ( ) ,
41+ file : z . string ( ) ,
4542 } ) ,
4643) ;
4744
@@ -57,10 +54,79 @@ export const OpenButtonActionValidator = schemaForType<OpenButtonAction>()(
5754 } ) ,
5855) ;
5956
60- export type ButtonAction = CommandButtonAction | JSButtonAction | OpenButtonAction ;
57+ export interface InputButtonAction {
58+ type : ButtonActionType . INPUT ;
59+ str : string ;
60+ }
61+
62+ export const InputButtonActionValidator = schemaForType < InputButtonAction > ( ) (
63+ z . object ( {
64+ type : z . literal ( ButtonActionType . INPUT ) ,
65+ str : z . string ( ) ,
66+ } ) ,
67+ ) ;
68+
69+ export interface SleepButtonAction {
70+ type : ButtonActionType . SLEEP ;
71+ ms : number ;
72+ }
73+
74+ export const SleepButtonActionValidator = schemaForType < SleepButtonAction > ( ) (
75+ z . object ( {
76+ type : z . literal ( ButtonActionType . SLEEP ) ,
77+ ms : z . number ( ) ,
78+ } ) ,
79+ ) ;
80+
81+ export interface TemplaterCreateNoteButtonAction {
82+ type : ButtonActionType . TEMPLATER_CREATE_NOTE ;
83+ templateFile : string ;
84+ folderPath ?: string ;
85+ fileName ?: string ;
86+ openNote ?: boolean ;
87+ }
88+
89+ export const TemplaterCreateNoteButtonActionValidator = schemaForType < TemplaterCreateNoteButtonAction > ( ) (
90+ z . object ( {
91+ type : z . literal ( ButtonActionType . TEMPLATER_CREATE_NOTE ) ,
92+ templateFile : z . string ( ) ,
93+ folderPath : z . string ( ) . optional ( ) ,
94+ fileName : z . string ( ) . optional ( ) ,
95+ openNote : z . boolean ( ) . optional ( ) ,
96+ } ) ,
97+ ) ;
98+
99+ export interface QuickSwitcherButtonAction {
100+ type : ButtonActionType . QUICK_SWITCHER ;
101+ filter : string ;
102+ }
103+
104+ export const QuickSwitcherButtonActionValidator = schemaForType < QuickSwitcherButtonAction > ( ) (
105+ z . object ( {
106+ type : z . literal ( ButtonActionType . QUICK_SWITCHER ) ,
107+ filter : z . string ( ) ,
108+ } ) ,
109+ ) ;
110+
111+ export type ButtonAction =
112+ | CommandButtonAction
113+ | JSButtonAction
114+ | OpenButtonAction
115+ | InputButtonAction
116+ | SleepButtonAction
117+ | TemplaterCreateNoteButtonAction
118+ | QuickSwitcherButtonAction ;
61119
62120export const ButtonActionValidator = schemaForType < ButtonAction > ( ) (
63- z . union ( [ CommandButtonActionValidator , JSButtonActionValidator , OpenButtonActionValidator ] ) ,
121+ z . union ( [
122+ CommandButtonActionValidator ,
123+ JSButtonActionValidator ,
124+ OpenButtonActionValidator ,
125+ InputButtonActionValidator ,
126+ SleepButtonActionValidator ,
127+ TemplaterCreateNoteButtonActionValidator ,
128+ QuickSwitcherButtonActionValidator ,
129+ ] ) ,
64130) ;
65131
66132export interface ButtonConfig {
@@ -75,25 +141,6 @@ export interface ButtonConfig {
75141type Tuple < T > = [ T , ...T [ ] ] ;
76142export const ButtonStyleValidator = z . enum ( Object . values ( ButtonStyleType ) as Tuple < ButtonStyleType > ) ;
77143
78- function oneOf <
79- A ,
80- K1 extends Extract < keyof A , string > ,
81- K2 extends Extract < keyof A , string > ,
82- R extends A &
83- ( ( Required < Pick < A , K1 > > & { [ P in K2 ] : undefined } ) | ( Required < Pick < A , K2 > > & { [ P in K1 ] : undefined } ) ) ,
84- > ( key1 : K1 , key2 : K2 ) : ( arg : A , ctx : RefinementCtx ) => arg is R {
85- return ( arg , ctx ) : arg is R => {
86- if ( ( arg [ key1 ] === undefined ) === ( arg [ key2 ] === undefined ) ) {
87- ctx . addIssue ( {
88- code : z . ZodIssueCode . custom ,
89- message : `Either ${ key1 } or ${ key2 } must be filled, but not both` ,
90- } ) ;
91- return false ;
92- }
93- return true ;
94- } ;
95- }
96-
97144export const ButtonConfigValidator = schemaForType < ButtonConfig > ( ) (
98145 z
99146 . object ( {
0 commit comments