@@ -4,8 +4,8 @@ import type { PreferenceState } from "./state";
44
55export type Dispatcher = ( action : Action ) => void ;
66
7- export type PreferenceRouteInfo = {
8- route : string ;
7+ export type PreferenceRouteInfo < T extends string = string > = {
8+ route : T ;
99 name : string ;
1010 icon ?: string ;
1111} ;
@@ -33,3 +33,72 @@ export type Subset<K> = {
3333 ? Subset < K [ attr ] > | null | undefined
3434 : K [ attr ] ;
3535} ;
36+
37+ type TPropertyBase < T > = {
38+ default : T ;
39+ /**
40+ * plain text description. if markdownDescription is defined, this can still be used as a fallback.
41+ */
42+ description : string ;
43+ /**
44+ * markdown description. if this is defined, description will be ignored. if markdown is invalid or failed to parse, this will be ignored.
45+ */
46+ markdownDescription ?: string ;
47+
48+ tags ?: string [ ] ;
49+ } ;
50+
51+ export type TBooleanProperty = TPropertyBase < boolean > & {
52+ type : "boolean" ;
53+ } ;
54+
55+ export type TStringProperty = TPropertyBase < string > & {
56+ type : "string" ;
57+ /**
58+ * ignored when `enum` is defined
59+ */
60+ pattern ?: string ;
61+ /**
62+ * ignored when `enum` is defined
63+ */
64+ minLength ?: number ;
65+ /**
66+ * ignored when `enum` is defined
67+ */
68+ maxLength ?: number ;
69+ /**
70+ * if this is defined, the property will be treated as an enum.
71+ */
72+ enum ?: string [ ] ;
73+ enumDescriptions ?: string [ ] ;
74+ markdownEnumDescriptions ?: string [ ] ;
75+ } ;
76+
77+ export type TNumberProperty = TPropertyBase < number > & {
78+ type : "number" ;
79+ maximum ?: number ;
80+ minimum ?: number ;
81+ } ;
82+
83+ /**
84+ * Property Type.
85+ * inspired from VSCode's API
86+ * object and array types are not supported
87+ * object - example: `editor.tokenColorCustomizations`
88+ * array - example: `files.exclude`
89+ */
90+ export type TProperty = TBooleanProperty | TNumberProperty | TStringProperty ;
91+
92+ export type TPropertyValueType = string | number | boolean ;
93+
94+ /**
95+ * Preference Type.
96+ * this defines the single preference item, which can hold multiple properties.
97+ */
98+ export type Preference = {
99+ identifier : string ;
100+ title : string ;
101+ properties : {
102+ [ key : string ] : TProperty ;
103+ } ;
104+ } ;
0 commit comments