This repository was archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui-model.ts
103 lines (87 loc) · 2.41 KB
/
gui-model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* The main gui controls that should be used.
*/
export type ControlType =
'group' | 'input' | 'dropdown' | 'yesno';
/**
* The javascript data types used.
*/
export type DataType =
'string' | 'number' | 'integer' | 'boolean';
/**
* Special subtypes for strings; superset of json schema string formats.
*/
export type StringSubDataType =
'text'
| 'password'
| 'date'
| 'time'
| 'date-time'
| 'uri'
| 'email'
| 'hostname'
| 'ipv4'
| 'ipv6'
| 'regex'
| 'uuid'
| 'json-pointer'
| 'relative-json-pointer'
;
export type IntegerSubType =
'port-number'
| 'miliseconds'
| 'seconds'
| 'minutes'
| 'hours'
| 'days'
;
export type SubDataType = StringSubDataType | IntegerSubType | 'none';
/**
* Common interface for all gui elements.
*/
export interface GuiElementBase {
readonly name: string;
readonly controlType: ControlType;
readonly label: string;
readonly tooltip: string;
/**
* A string representing a path to the property in json data file conforming to the plugin schema,
* where each path component is seperated by a dot. Same as string representation of
* Lodash.get method or mariocasciaro's object-path (https://github.com/mariocasciaro/object-path).
* This string is unique for all elements in a model and may thus be used as a key if needed.
*/
readonly dataObjectPath: string;
readonly required: boolean;
readonly comment?: string;
}
/**
* Base interface for all types of gui input elements that are not containers for other elements.
*/
export interface FieldBase extends GuiElementBase {
readonly kind: 'field';
readonly type: DataType;
readonly subType: SubDataType;
};
export interface TypedField<T> extends FieldBase {
readonly defaultValue: T | null;
readonly values?: ReadonlyArray<T | null>;
}
/**
* A containers for other gui elements.
*/
export interface Group extends GuiElementBase {
readonly kind: 'group';
readonly elements: ReadonlyArray<GuiElement>;
}
export interface TranslationError {
readonly schemaPath: string;
readonly errorText: string;
};
/**
* Represents a full gui model. Essentially a group but with an extra errors field.
*/
export interface GuiModel extends Group {
readonly errors: ReadonlyArray<TranslationError>;
}
export type Field = TypedField<string> | TypedField<number> | TypedField<boolean>;
export type GuiElement = Group | Field;