jsbox-cview 1.6.5 → 1.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/components/alert/input-alert.d.ts +22 -0
- package/dist/components/alert/input-alert.js +1 -2
- package/dist/components/alert/login-alert.d.ts +21 -0
- package/dist/components/alert/login-alert.js +1 -2
- package/dist/components/alert/plain-alert.d.ts +15 -0
- package/dist/components/alert/plain-alert.js +1 -2
- package/dist/components/alert/uialert.d.ts +29 -0
- package/{components/base.ts → dist/components/base.d.ts} +9 -28
- package/dist/components/custom-navigation-bar.d.ts +117 -0
- package/dist/components/custom-navigation-bar.js +7 -1
- package/dist/components/dialogs/dialog-sheet.d.ts +46 -0
- package/dist/components/dialogs/dialog-sheet.js +3 -1
- package/dist/components/dialogs/form-dialog.d.ts +15 -0
- package/dist/components/dialogs/form-dialog.js +1 -2
- package/dist/components/dialogs/list-dialog.d.ts +23 -0
- package/dist/components/dialogs/list-dialog.js +2 -3
- package/dist/components/dialogs/text-dialog.d.ts +13 -0
- package/dist/components/dialogs/text-dialog.js +1 -2
- package/dist/components/dynamic-contextmenu-view.d.ts +40 -0
- package/dist/components/dynamic-contextmenu-view.js +5 -1
- package/dist/components/dynamic-itemsize-matrix.d.ts +79 -0
- package/dist/components/dynamic-itemsize-matrix.js +18 -15
- package/dist/components/dynamic-itemsize-section-matrix.d.ts +115 -0
- package/dist/components/dynamic-itemsize-section-matrix.js +293 -0
- package/dist/components/dynamic-preference-listview.d.ts +63 -0
- package/dist/components/dynamic-preference-listview.js +25 -16
- package/dist/components/dynamic-rowheight-list.d.ts +38 -0
- package/dist/components/dynamic-rowheight-list.js +10 -3
- package/dist/components/enhanced-imageview.d.ts +41 -0
- package/dist/components/enhanced-imageview.js +1 -1
- package/dist/components/flowlayout.d.ts +63 -0
- package/dist/components/flowlayout.js +10 -13
- package/dist/components/image-pager.d.ts +49 -0
- package/dist/components/image-pager.js +6 -1
- package/dist/components/oc-webview.d.ts +64 -0
- package/dist/components/oc-webview.js +13 -5
- package/dist/components/page-control.d.ts +45 -0
- package/dist/components/page-control.js +2 -13
- package/dist/components/pageviewer-titlebar.d.ts +48 -0
- package/dist/components/pageviewer-titlebar.js +7 -13
- package/dist/components/pageviewer.d.ts +41 -0
- package/dist/components/pageviewer.js +4 -1
- package/dist/components/refresh-button.d.ts +25 -0
- package/dist/components/refresh-button.js +3 -4
- package/dist/components/rotating-view.d.ts +45 -0
- package/dist/components/rotating-view.js +10 -2
- package/dist/components/searchbar.d.ts +118 -0
- package/dist/components/searchbar.js +8 -1
- package/dist/components/sheet.d.ts +42 -0
- package/dist/components/single-views.d.ts +289 -0
- package/dist/components/single-views.js +11 -4
- package/dist/components/spinners/loading-dual-ring.d.ts +18 -0
- package/dist/components/spinners/loading-wedges.d.ts +15 -0
- package/dist/components/spinners/spinner-androidstyle.d.ts +30 -0
- package/dist/components/spinners/spinner-androidstyle.js +7 -1
- package/dist/components/static-preference-listview.d.ts +389 -0
- package/dist/components/static-preference-listview.js +13 -10
- package/dist/components/symbol-button.d.ts +39 -0
- package/dist/components/symbol-button.js +8 -1
- package/dist/components/tabbar.d.ts +140 -0
- package/dist/components/tabbar.js +8 -1
- package/dist/controller/base-controller.d.ts +125 -0
- package/dist/controller/base-controller.js +11 -11
- package/dist/controller/controller-router.d.ts +48 -0
- package/dist/controller/pageviewer-controller.d.ts +38 -0
- package/dist/controller/pageviewer-controller.js +4 -1
- package/dist/controller/presented-page-controller.d.ts +41 -0
- package/dist/controller/presented-page-controller.js +7 -9
- package/dist/controller/splitview-controller.d.ts +90 -0
- package/dist/controller/splitview-controller.js +27 -11
- package/dist/controller/tabbar-controller.d.ts +49 -0
- package/dist/controller/tabbar-controller.js +12 -15
- package/{index.ts → dist/index.d.ts} +2 -0
- package/dist/index.js +2 -0
- package/dist/utils/colors.d.ts +7 -0
- package/dist/utils/cvid.d.ts +11 -0
- package/dist/utils/l10n.d.ts +1 -0
- package/dist/utils/l10n.js +1 -2
- package/dist/utils/path.d.ts +8 -0
- package/dist/utils/path.js +8 -9
- package/dist/utils/rect.d.ts +38 -0
- package/dist/utils/rect.js +8 -9
- package/dist/utils/uitools.d.ts +75 -0
- package/dist/utils/uitools.js +6 -6
- package/package.json +20 -5
- package/.prettierignore +0 -6
- package/.prettierrc +0 -3
- package/components/alert/input-alert.ts +0 -64
- package/components/alert/login-alert.ts +0 -66
- package/components/alert/plain-alert.ts +0 -39
- package/components/alert/uialert.ts +0 -107
- package/components/custom-navigation-bar.ts +0 -579
- package/components/dialogs/dialog-sheet.ts +0 -111
- package/components/dialogs/form-dialog.ts +0 -63
- package/components/dialogs/list-dialog.ts +0 -119
- package/components/dialogs/text-dialog.ts +0 -44
- package/components/dynamic-contextmenu-view.ts +0 -115
- package/components/dynamic-itemsize-matrix.ts +0 -206
- package/components/dynamic-preference-listview.ts +0 -684
- package/components/dynamic-rowheight-list.ts +0 -77
- package/components/enhanced-imageview.ts +0 -132
- package/components/flowlayout.ts +0 -248
- package/components/image-pager.ts +0 -180
- package/components/oc-webview.ts +0 -177
- package/components/page-control.ts +0 -93
- package/components/pageviewer-titlebar.ts +0 -166
- package/components/pageviewer.ts +0 -125
- package/components/refresh-button.ts +0 -83
- package/components/rotating-view.ts +0 -133
- package/components/searchbar.ts +0 -398
- package/components/sheet.ts +0 -104
- package/components/single-views.ts +0 -956
- package/components/spinners/loading-dual-ring.ts +0 -97
- package/components/spinners/loading-wedges.ts +0 -106
- package/components/spinners/spinner-androidstyle.ts +0 -269
- package/components/static-preference-listview.ts +0 -1282
- package/components/symbol-button.ts +0 -108
- package/components/tabbar.ts +0 -453
- package/controller/base-controller.ts +0 -214
- package/controller/controller-router.ts +0 -73
- package/controller/pageviewer-controller.ts +0 -93
- package/controller/presented-page-controller.ts +0 -76
- package/controller/splitview-controller.ts +0 -359
- package/controller/tabbar-controller.ts +0 -131
- package/dist/test/custom-navigation-bar.js +0 -40
- package/dist/test/dialog-sheet.js +0 -40
- package/dist/test/dynamic-contextmenu-view.js +0 -66
- package/dist/test/dynamic-itemsize-matrix.js +0 -74
- package/dist/test/dynamic-preference-listview.js +0 -150
- package/dist/test/flowlayout.js +0 -76
- package/dist/test/form-dialog.js +0 -51
- package/dist/test/oc-webview.js +0 -195
- package/dist/test/pageviewer-controller.js +0 -20
- package/dist/test/pageviewer-titlebar.js +0 -18
- package/dist/test/pageviewer.js +0 -32
- package/dist/test/refresh-button.js +0 -26
- package/dist/test/searchbar.js +0 -36
- package/dist/test/splitview-controller.js +0 -41
- package/dist/test/static-preference-listview.js +0 -143
- package/dist/test/tabbar-controller.js +0 -48
- package/test/custom-navigation-bar.ts +0 -40
- package/test/dialog-sheet.ts +0 -40
- package/test/dynamic-contextmenu-view.ts +0 -67
- package/test/dynamic-itemsize-matrix.ts +0 -74
- package/test/dynamic-preference-listview.ts +0 -151
- package/test/flowlayout.ts +0 -79
- package/test/form-dialog.ts +0 -48
- package/test/oc-webview.ts +0 -197
- package/test/pageviewer-controller.ts +0 -21
- package/test/pageviewer-titlebar.ts +0 -18
- package/test/pageviewer.ts +0 -31
- package/test/refresh-button.ts +0 -26
- package/test/searchbar.ts +0 -38
- package/test/splitview-controller.ts +0 -42
- package/test/static-preference-listview.ts +0 -142
- package/test/tabbar-controller.ts +0 -49
- package/tsconfig.json +0 -122
- package/utils/colors.ts +0 -17
- package/utils/cvid.ts +0 -32
- package/utils/l10n.ts +0 -42
- package/utils/path.ts +0 -97
- package/utils/rect.ts +0 -90
- package/utils/uitools.ts +0 -122
|
@@ -1,1282 +0,0 @@
|
|
|
1
|
-
import { Base } from "./base";
|
|
2
|
-
import { getTextWidth } from "../utils/uitools";
|
|
3
|
-
|
|
4
|
-
type PreferenceCellTypes =
|
|
5
|
-
| "string"
|
|
6
|
-
| "number"
|
|
7
|
-
| "integer"
|
|
8
|
-
| "stepper"
|
|
9
|
-
| "boolean"
|
|
10
|
-
| "slider"
|
|
11
|
-
| "list"
|
|
12
|
-
| "tab"
|
|
13
|
-
| "date"
|
|
14
|
-
| "info"
|
|
15
|
-
| "interactive-info"
|
|
16
|
-
| "link"
|
|
17
|
-
| "symbol-action"
|
|
18
|
-
| "action";
|
|
19
|
-
|
|
20
|
-
export interface PreferenceSection {
|
|
21
|
-
title: string;
|
|
22
|
-
rows: PrefsRow[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type PrefsRow =
|
|
26
|
-
| PrefsRowString
|
|
27
|
-
| PrefsRowNumber
|
|
28
|
-
| PrefsRowInteger
|
|
29
|
-
| PrefsRowStepper
|
|
30
|
-
| PrefsRowBoolean
|
|
31
|
-
| PrefsRowSlider
|
|
32
|
-
| PrefsRowList
|
|
33
|
-
| PrefsRowTab
|
|
34
|
-
| PrefsRowDate
|
|
35
|
-
| PrefsRowInfo
|
|
36
|
-
| PrefsRowInteractiveInfo
|
|
37
|
-
| PrefsRowLink
|
|
38
|
-
| PrefsRowSymbolAction
|
|
39
|
-
| PrefsRowAction;
|
|
40
|
-
|
|
41
|
-
interface PrefsRowBase {
|
|
42
|
-
type: PreferenceCellTypes;
|
|
43
|
-
key?: string;
|
|
44
|
-
title?: string;
|
|
45
|
-
titleColor?: UIColor;
|
|
46
|
-
changedEvent?: () => void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface PrefsRowString extends PrefsRowBase {
|
|
50
|
-
type: "string";
|
|
51
|
-
value?: string;
|
|
52
|
-
placeholder?: string;
|
|
53
|
-
textColor?: UIColor;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface PrefsRowNumber extends PrefsRowBase {
|
|
57
|
-
type: "number";
|
|
58
|
-
value?: number;
|
|
59
|
-
placeholder?: string;
|
|
60
|
-
textColor?: UIColor;
|
|
61
|
-
min?: number;
|
|
62
|
-
max?: number;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface PrefsRowInteger extends PrefsRowBase {
|
|
66
|
-
type: "integer";
|
|
67
|
-
value?: number;
|
|
68
|
-
placeholder?: string;
|
|
69
|
-
textColor?: UIColor;
|
|
70
|
-
min?: number;
|
|
71
|
-
max?: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface PrefsRowStepper extends PrefsRowBase {
|
|
75
|
-
type: "stepper";
|
|
76
|
-
value?: number;
|
|
77
|
-
min?: number;
|
|
78
|
-
max?: number;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface PrefsRowBoolean extends PrefsRowBase {
|
|
82
|
-
type: "boolean";
|
|
83
|
-
value?: boolean;
|
|
84
|
-
onColor?: UIColor;
|
|
85
|
-
thumbColor?: UIColor;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface PrefsRowSlider extends PrefsRowBase {
|
|
89
|
-
type: "slider";
|
|
90
|
-
value?: number;
|
|
91
|
-
min?: number;
|
|
92
|
-
max?: number;
|
|
93
|
-
decimal?: number;
|
|
94
|
-
minColor?: UIColor;
|
|
95
|
-
maxColor?: UIColor;
|
|
96
|
-
thumbColor?: UIColor;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface PrefsRowList extends PrefsRowBase {
|
|
100
|
-
type: "list";
|
|
101
|
-
value?: number;
|
|
102
|
-
items: string[];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface PrefsRowTab extends PrefsRowBase {
|
|
106
|
-
type: "tab";
|
|
107
|
-
value?: number;
|
|
108
|
-
items: string[];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface PrefsRowDate extends PrefsRowBase {
|
|
112
|
-
type: "date";
|
|
113
|
-
value?: Date;
|
|
114
|
-
min?: Date;
|
|
115
|
-
max?: Date;
|
|
116
|
-
mode?: number;
|
|
117
|
-
interval?: number;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface PrefsRowInfo extends PrefsRowBase {
|
|
121
|
-
type: "info";
|
|
122
|
-
value?: string;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface PrefsRowInteractiveInfo extends PrefsRowBase {
|
|
126
|
-
type: "interactive-info";
|
|
127
|
-
value?: string;
|
|
128
|
-
copyable?: boolean;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface PrefsRowLink extends PrefsRowBase {
|
|
132
|
-
type: "link";
|
|
133
|
-
value?: string;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface PrefsRowSymbolAction extends PrefsRowBase {
|
|
137
|
-
type: "symbol-action";
|
|
138
|
-
symbol?: string;
|
|
139
|
-
tintColor?: UIColor;
|
|
140
|
-
contentMode?: number;
|
|
141
|
-
symbolSize?: JBSize;
|
|
142
|
-
value?: () => void;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface PrefsRowAction extends PrefsRowBase {
|
|
146
|
-
type: "action";
|
|
147
|
-
value?: () => void;
|
|
148
|
-
destructive?: boolean;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const selectableTypes = [
|
|
152
|
-
"string",
|
|
153
|
-
"number",
|
|
154
|
-
"integer",
|
|
155
|
-
"stepper",
|
|
156
|
-
"list",
|
|
157
|
-
"date",
|
|
158
|
-
"interactive-info",
|
|
159
|
-
"link",
|
|
160
|
-
"symbol-action",
|
|
161
|
-
"action",
|
|
162
|
-
];
|
|
163
|
-
|
|
164
|
-
export const excludedTypes = ["info", "interactive-info", "link", "symbol-action", "action"];
|
|
165
|
-
|
|
166
|
-
type PreferenceValues = { [key: string]: any };
|
|
167
|
-
|
|
168
|
-
type AllCells =
|
|
169
|
-
| StringCell
|
|
170
|
-
| NumberCell
|
|
171
|
-
| IntegerCell
|
|
172
|
-
| StepperCell
|
|
173
|
-
| BooleanCell
|
|
174
|
-
| SliderCell
|
|
175
|
-
| ListCell
|
|
176
|
-
| TabCell
|
|
177
|
-
| DateCell
|
|
178
|
-
| InteractiveInfoCell
|
|
179
|
-
| InfoCell
|
|
180
|
-
| LinkCell
|
|
181
|
-
| SymbolActionCell
|
|
182
|
-
| ActionCell;
|
|
183
|
-
|
|
184
|
-
abstract class Cell extends Base<UIView, UiTypes.ViewOptions> {
|
|
185
|
-
abstract _type: string;
|
|
186
|
-
_key?: string;
|
|
187
|
-
_title?: string;
|
|
188
|
-
_value?: any;
|
|
189
|
-
_values: PreferenceValues;
|
|
190
|
-
_titleColor: UIColor;
|
|
191
|
-
_changedEvent?: () => void;
|
|
192
|
-
_defineView: () => UiTypes.ViewOptions;
|
|
193
|
-
constructor(
|
|
194
|
-
{
|
|
195
|
-
key,
|
|
196
|
-
title,
|
|
197
|
-
value,
|
|
198
|
-
titleColor = $color("primaryText"),
|
|
199
|
-
changedEvent,
|
|
200
|
-
}: {
|
|
201
|
-
key?: string;
|
|
202
|
-
title?: string;
|
|
203
|
-
value?: any;
|
|
204
|
-
titleColor?: UIColor;
|
|
205
|
-
changedEvent?: () => void;
|
|
206
|
-
},
|
|
207
|
-
values: PreferenceValues,
|
|
208
|
-
) {
|
|
209
|
-
super();
|
|
210
|
-
this._key = key;
|
|
211
|
-
this._title = title;
|
|
212
|
-
this._value = value;
|
|
213
|
-
this._titleColor = titleColor;
|
|
214
|
-
this._changedEvent = changedEvent;
|
|
215
|
-
this._values = values;
|
|
216
|
-
this._defineView = () => {
|
|
217
|
-
return {
|
|
218
|
-
type: "view",
|
|
219
|
-
props: {
|
|
220
|
-
selectable: selectableTypes.includes(this._type),
|
|
221
|
-
id: this.id,
|
|
222
|
-
},
|
|
223
|
-
layout: $layout.fill,
|
|
224
|
-
views: [this._defineTitleView(), this._defineValueView()],
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
set value(value) {
|
|
230
|
-
if (this._handleValue) value = this._handleValue(value);
|
|
231
|
-
if (this._key) this._values[this._key] = value;
|
|
232
|
-
this._value = value;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
get value() {
|
|
236
|
-
return this._value;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
get type() {
|
|
240
|
-
return this._type;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
get key() {
|
|
244
|
-
return this._key;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
abstract _handleValue(value: any): any;
|
|
248
|
-
|
|
249
|
-
abstract _defineValueView(): UiTypes.AllViewOptions;
|
|
250
|
-
|
|
251
|
-
_defineTitleView(): UiTypes.LabelOptions {
|
|
252
|
-
return {
|
|
253
|
-
type: "label",
|
|
254
|
-
props: {
|
|
255
|
-
id: "title",
|
|
256
|
-
text: this._title,
|
|
257
|
-
textColor: this._titleColor,
|
|
258
|
-
font: $font(17),
|
|
259
|
-
},
|
|
260
|
-
layout: (make, view) => {
|
|
261
|
-
make.centerY.equalTo(view.super);
|
|
262
|
-
make.width.equalTo(getTextWidth(this._title || ""));
|
|
263
|
-
make.left.inset(15);
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
abstract class BaseStringCell extends Cell {
|
|
270
|
-
abstract _type: string;
|
|
271
|
-
_placeholder?: string;
|
|
272
|
-
_textColor?: UIColor;
|
|
273
|
-
constructor(props: PrefsRowString | PrefsRowNumber | PrefsRowInteger, values: PreferenceValues) {
|
|
274
|
-
super(props, values);
|
|
275
|
-
const { placeholder, textColor } = props;
|
|
276
|
-
this._placeholder = placeholder;
|
|
277
|
-
this._textColor = textColor;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
_defineValueView(): UiTypes.AllViewOptions {
|
|
281
|
-
return {
|
|
282
|
-
type: "view",
|
|
283
|
-
props: {},
|
|
284
|
-
layout: (make, view) => {
|
|
285
|
-
make.top.bottom.inset(0);
|
|
286
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
287
|
-
make.right.inset(15);
|
|
288
|
-
},
|
|
289
|
-
views: [
|
|
290
|
-
{
|
|
291
|
-
type: "image",
|
|
292
|
-
props: {
|
|
293
|
-
symbol: "chevron.right",
|
|
294
|
-
tintColor: $color("lightGray", "darkGray"),
|
|
295
|
-
contentMode: 1,
|
|
296
|
-
},
|
|
297
|
-
layout: (make, view) => {
|
|
298
|
-
make.centerY.equalTo(view.super);
|
|
299
|
-
make.size.equalTo($size(17, 17));
|
|
300
|
-
make.right.inset(0);
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
type: "label",
|
|
305
|
-
props: {
|
|
306
|
-
id: "label",
|
|
307
|
-
text: this._handleText(this._value)?.toString(),
|
|
308
|
-
align: $align.right,
|
|
309
|
-
font: $font(17),
|
|
310
|
-
textColor: this._textColor,
|
|
311
|
-
bgcolor: $color("clear"),
|
|
312
|
-
userInteractionEnabled: false,
|
|
313
|
-
},
|
|
314
|
-
layout: (make, view) => {
|
|
315
|
-
make.centerY.equalTo(view.super);
|
|
316
|
-
make.left.inset(0);
|
|
317
|
-
make.right.equalTo(view.prev.left).inset(5);
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
_handleValue(text: string) {
|
|
325
|
-
const result = this._handleText(text);
|
|
326
|
-
const label = this.view.get("label") as UILabelView;
|
|
327
|
-
if (result === undefined) label.text = "";
|
|
328
|
-
else label.text = result.toString();
|
|
329
|
-
return result;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
abstract _handleText(text: string): string | number | undefined;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
class StringCell extends BaseStringCell {
|
|
336
|
-
readonly _type = "string";
|
|
337
|
-
constructor(props: PrefsRowString, values: PreferenceValues) {
|
|
338
|
-
super(props, values);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
_handleText(text: string) {
|
|
342
|
-
return text;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
class NumberCell extends BaseStringCell {
|
|
347
|
-
readonly _type = "number";
|
|
348
|
-
_min?: number;
|
|
349
|
-
_max?: number;
|
|
350
|
-
constructor(props: PrefsRowNumber, values: PreferenceValues) {
|
|
351
|
-
super(props, values);
|
|
352
|
-
const { min, max } = props;
|
|
353
|
-
this._min = min;
|
|
354
|
-
this._max = max;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
_handleText(text: string): number | undefined {
|
|
358
|
-
if (!text) return;
|
|
359
|
-
const result = parseFloat(text);
|
|
360
|
-
if (isNaN(result)) return;
|
|
361
|
-
if (this._min !== undefined && result < this._min) return;
|
|
362
|
-
if (this._max !== undefined && result > this._max) return;
|
|
363
|
-
return result;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
class IntegerCell extends BaseStringCell {
|
|
368
|
-
readonly _type = "integer";
|
|
369
|
-
_min: number;
|
|
370
|
-
_max?: number;
|
|
371
|
-
constructor(props: PrefsRowInteger, values: PreferenceValues) {
|
|
372
|
-
super(props, values);
|
|
373
|
-
const { min, max } = props;
|
|
374
|
-
this._min = min || 0;
|
|
375
|
-
this._max = max;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
_handleText(text: string): number | undefined {
|
|
379
|
-
if (!text) return;
|
|
380
|
-
const result = parseInt(text);
|
|
381
|
-
if (isNaN(result)) return;
|
|
382
|
-
if (this._min !== undefined && result < this._min) return;
|
|
383
|
-
if (this._max !== undefined && result > this._max) return;
|
|
384
|
-
return result;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
class StepperCell extends Cell {
|
|
389
|
-
readonly _type = "stepper";
|
|
390
|
-
_max?: number;
|
|
391
|
-
_min: number;
|
|
392
|
-
constructor(props: PrefsRowStepper, values: PreferenceValues) {
|
|
393
|
-
super(props, values);
|
|
394
|
-
const { max, min } = props;
|
|
395
|
-
this._max = max;
|
|
396
|
-
this._min = min || 0;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
_defineValueView(): UiTypes.ViewOptions {
|
|
400
|
-
return {
|
|
401
|
-
type: "view",
|
|
402
|
-
props: {},
|
|
403
|
-
views: [
|
|
404
|
-
{
|
|
405
|
-
type: "stepper",
|
|
406
|
-
props: {
|
|
407
|
-
id: "stepper",
|
|
408
|
-
value: this._value || this._min,
|
|
409
|
-
max: this._max,
|
|
410
|
-
min: this._min,
|
|
411
|
-
},
|
|
412
|
-
layout: (make, view) => {
|
|
413
|
-
make.centerY.equalTo(view.super);
|
|
414
|
-
make.right.inset(0);
|
|
415
|
-
},
|
|
416
|
-
events: {
|
|
417
|
-
changed: (sender) => {
|
|
418
|
-
this.value = sender.value;
|
|
419
|
-
if (this._changedEvent) this._changedEvent();
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
type: "label",
|
|
425
|
-
props: {
|
|
426
|
-
id: "label",
|
|
427
|
-
text: this._value || this._min,
|
|
428
|
-
align: $align.right,
|
|
429
|
-
},
|
|
430
|
-
layout: (make, view) => {
|
|
431
|
-
make.top.bottom.inset(0);
|
|
432
|
-
make.right.equalTo(view.prev.left).inset(10);
|
|
433
|
-
make.width.equalTo(30);
|
|
434
|
-
},
|
|
435
|
-
},
|
|
436
|
-
],
|
|
437
|
-
layout: (make, view) => {
|
|
438
|
-
make.top.bottom.inset(0);
|
|
439
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
440
|
-
make.right.inset(15);
|
|
441
|
-
},
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
_handleValue(num: number) {
|
|
446
|
-
if (isNaN(num)) num = this._min;
|
|
447
|
-
if (this._min !== undefined && num < this._min) num = this._min;
|
|
448
|
-
if (this._max !== undefined && num > this._max) num = this._max;
|
|
449
|
-
const label = this.view.get("label") as UILabelView;
|
|
450
|
-
label.text = num.toString();
|
|
451
|
-
const stepper = this.view.get("stepper") as UIStepperView;
|
|
452
|
-
stepper.value = num;
|
|
453
|
-
return num;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
class BooleanCell extends Cell {
|
|
458
|
-
readonly _type = "boolean";
|
|
459
|
-
_onColor: UIColor;
|
|
460
|
-
_thumbColor?: UIColor;
|
|
461
|
-
constructor(props: PrefsRowBoolean, values: PreferenceValues) {
|
|
462
|
-
super(props, values);
|
|
463
|
-
const { onColor = $color("#34C85A"), thumbColor } = props;
|
|
464
|
-
this._onColor = onColor;
|
|
465
|
-
this._thumbColor = thumbColor;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
_defineValueView(): UiTypes.SwitchOptions {
|
|
469
|
-
return {
|
|
470
|
-
type: "switch",
|
|
471
|
-
props: {
|
|
472
|
-
id: "switch",
|
|
473
|
-
on: this._value,
|
|
474
|
-
onColor: this._onColor,
|
|
475
|
-
thumbColor: this._thumbColor,
|
|
476
|
-
},
|
|
477
|
-
layout: (make, view) => {
|
|
478
|
-
make.size.equalTo($size(51, 31));
|
|
479
|
-
make.centerY.equalTo(view.super);
|
|
480
|
-
make.right.inset(15);
|
|
481
|
-
},
|
|
482
|
-
events: {
|
|
483
|
-
changed: (sender) => {
|
|
484
|
-
this.value = sender.on;
|
|
485
|
-
if (this._changedEvent) this._changedEvent();
|
|
486
|
-
},
|
|
487
|
-
},
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
_handleValue(bool: boolean) {
|
|
492
|
-
const switchView = this.view.get("switch") as UISwitchView;
|
|
493
|
-
switchView.on = bool;
|
|
494
|
-
return bool;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
class SliderCell extends Cell {
|
|
499
|
-
readonly _type = "slider";
|
|
500
|
-
_decimal: number;
|
|
501
|
-
_min: number;
|
|
502
|
-
_max: number;
|
|
503
|
-
_minColor: UIColor;
|
|
504
|
-
_maxColor?: UIColor;
|
|
505
|
-
_thumbColor?: UIColor;
|
|
506
|
-
constructor(props: PrefsRowSlider, values: PreferenceValues) {
|
|
507
|
-
super(props, values);
|
|
508
|
-
const { decimal = 1, min = 0, max = 1, minColor = $color("systemLink"), maxColor, thumbColor } = props;
|
|
509
|
-
this._decimal = decimal;
|
|
510
|
-
this._min = min;
|
|
511
|
-
this._max = max;
|
|
512
|
-
this._minColor = minColor;
|
|
513
|
-
this._maxColor = maxColor;
|
|
514
|
-
this._thumbColor = thumbColor;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
_defineValueView(): UiTypes.ViewOptions {
|
|
518
|
-
return {
|
|
519
|
-
type: "view",
|
|
520
|
-
props: {},
|
|
521
|
-
views: [
|
|
522
|
-
{
|
|
523
|
-
type: "label",
|
|
524
|
-
props: {
|
|
525
|
-
id: "label",
|
|
526
|
-
text: this._value.toFixed(this._decimal),
|
|
527
|
-
align: $align.center,
|
|
528
|
-
},
|
|
529
|
-
layout: (make, view) => {
|
|
530
|
-
make.top.right.bottom.inset(0);
|
|
531
|
-
make.width.equalTo(44);
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
{
|
|
535
|
-
type: "slider",
|
|
536
|
-
props: {
|
|
537
|
-
id: "slider",
|
|
538
|
-
value: this._value,
|
|
539
|
-
max: this._max,
|
|
540
|
-
min: this._min,
|
|
541
|
-
minColor: this._minColor,
|
|
542
|
-
maxColor: this._maxColor,
|
|
543
|
-
thumbColor: this._thumbColor,
|
|
544
|
-
continuous: true,
|
|
545
|
-
},
|
|
546
|
-
layout: (make, view) => {
|
|
547
|
-
make.top.left.bottom.inset(0);
|
|
548
|
-
make.right.equalTo(view.prev.left);
|
|
549
|
-
},
|
|
550
|
-
events: {
|
|
551
|
-
changed: (sender) => {
|
|
552
|
-
const adjustedValue = parseFloat(sender.value.toFixed(this._decimal));
|
|
553
|
-
const label = sender.prev as UILabelView;
|
|
554
|
-
label.text = adjustedValue.toString();
|
|
555
|
-
if (this._key) {
|
|
556
|
-
this._values[this._key] = adjustedValue;
|
|
557
|
-
this._value = adjustedValue;
|
|
558
|
-
}
|
|
559
|
-
},
|
|
560
|
-
touchesEnded: (sender) => {
|
|
561
|
-
const adjustedValue = parseFloat(sender.value.toFixed(this._decimal));
|
|
562
|
-
this.value = adjustedValue;
|
|
563
|
-
if (this._changedEvent) this._changedEvent();
|
|
564
|
-
},
|
|
565
|
-
},
|
|
566
|
-
},
|
|
567
|
-
],
|
|
568
|
-
layout: (make, view) => {
|
|
569
|
-
make.top.bottom.inset(0);
|
|
570
|
-
make.left.lessThanOrEqualTo(view.prev.right).inset(10).priority(999);
|
|
571
|
-
make.width.lessThanOrEqualTo(250);
|
|
572
|
-
make.right.inset(15);
|
|
573
|
-
},
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
_handleValue(num: number) {
|
|
578
|
-
if (isNaN(num)) num = this._min;
|
|
579
|
-
if (this._min !== undefined && num < this._min) num = this._min;
|
|
580
|
-
if (this._max !== undefined && num > this._max) num = this._max;
|
|
581
|
-
const adjustedValue = parseFloat(num.toFixed(this._decimal));
|
|
582
|
-
const label = this.view.get("label") as UILabelView;
|
|
583
|
-
label.text = adjustedValue.toString();
|
|
584
|
-
const slider = this.view.get("slider") as UISliderView;
|
|
585
|
-
slider.value = adjustedValue;
|
|
586
|
-
return adjustedValue;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
class ListCell extends Cell {
|
|
591
|
-
readonly _type = "list";
|
|
592
|
-
_items: string[];
|
|
593
|
-
constructor(props: PrefsRowList, values: PreferenceValues) {
|
|
594
|
-
super(props, values);
|
|
595
|
-
const { items } = props;
|
|
596
|
-
this._items = items;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
_defineValueView(): UiTypes.ViewOptions {
|
|
600
|
-
return {
|
|
601
|
-
type: "view",
|
|
602
|
-
props: {},
|
|
603
|
-
layout: (make, view) => {
|
|
604
|
-
make.top.bottom.inset(0);
|
|
605
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
606
|
-
make.right.inset(15);
|
|
607
|
-
},
|
|
608
|
-
views: [
|
|
609
|
-
{
|
|
610
|
-
type: "image",
|
|
611
|
-
props: {
|
|
612
|
-
symbol: "chevron.right",
|
|
613
|
-
tintColor: $color("lightGray", "darkGray"),
|
|
614
|
-
contentMode: 1,
|
|
615
|
-
},
|
|
616
|
-
layout: (make, view) => {
|
|
617
|
-
make.centerY.equalTo(view.super);
|
|
618
|
-
make.size.equalTo($size(17, 17));
|
|
619
|
-
make.right.inset(0);
|
|
620
|
-
},
|
|
621
|
-
},
|
|
622
|
-
{
|
|
623
|
-
type: "label",
|
|
624
|
-
props: {
|
|
625
|
-
id: "label",
|
|
626
|
-
text: this._items[this._value],
|
|
627
|
-
textColor: $color("secondaryText"),
|
|
628
|
-
align: $align.right,
|
|
629
|
-
},
|
|
630
|
-
layout: (make, view) => {
|
|
631
|
-
make.centerY.equalTo(view.super);
|
|
632
|
-
make.left.inset(0);
|
|
633
|
-
make.right.equalTo(view.prev.left).inset(5);
|
|
634
|
-
},
|
|
635
|
-
},
|
|
636
|
-
],
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
_handleValue(num: number) {
|
|
641
|
-
const label = this.view.get("label") as UILabelView;
|
|
642
|
-
label.text = this._items[num];
|
|
643
|
-
return num;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
class TabCell extends Cell {
|
|
648
|
-
readonly _type = "tab";
|
|
649
|
-
_items: string[];
|
|
650
|
-
constructor(props: PrefsRowTab, values: PreferenceValues) {
|
|
651
|
-
super(props, values);
|
|
652
|
-
const { items, value = -1 } = props;
|
|
653
|
-
this._items = items;
|
|
654
|
-
this._value = value;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
_defineValueView(): UiTypes.TabOptions {
|
|
658
|
-
return {
|
|
659
|
-
type: "tab",
|
|
660
|
-
props: {
|
|
661
|
-
id: "tab",
|
|
662
|
-
items: this._items,
|
|
663
|
-
index: this._value,
|
|
664
|
-
},
|
|
665
|
-
layout: (make, view) => {
|
|
666
|
-
make.centerY.equalTo(view.super);
|
|
667
|
-
make.height.equalTo(34);
|
|
668
|
-
make.left.lessThanOrEqualTo(view.prev.right).inset(10).priority(999);
|
|
669
|
-
make.width.lessThanOrEqualTo(250);
|
|
670
|
-
make.right.inset(15);
|
|
671
|
-
},
|
|
672
|
-
events: {
|
|
673
|
-
changed: (sender) => {
|
|
674
|
-
this.value = sender.index;
|
|
675
|
-
if (this._changedEvent) this._changedEvent();
|
|
676
|
-
},
|
|
677
|
-
},
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
_handleValue(num: number) {
|
|
682
|
-
const tab = this.view.get("tab") as UITabView;
|
|
683
|
-
tab.index = num;
|
|
684
|
-
return num;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
export function dateToString(mode: number, date?: Date) {
|
|
689
|
-
if (!date) return "";
|
|
690
|
-
const year = date.getFullYear();
|
|
691
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
692
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
693
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
694
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
695
|
-
if (mode === 0 || mode === 3) {
|
|
696
|
-
return `${hours}:${minutes}`;
|
|
697
|
-
} else if (mode === 1) {
|
|
698
|
-
return `${year}-${month}-${day}`;
|
|
699
|
-
} else {
|
|
700
|
-
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
class DateCell extends Cell {
|
|
705
|
-
readonly _type = "date";
|
|
706
|
-
_mode: number;
|
|
707
|
-
_interval?: number;
|
|
708
|
-
_min?: Date;
|
|
709
|
-
_max?: Date;
|
|
710
|
-
constructor(props: PrefsRowDate, values: PreferenceValues) {
|
|
711
|
-
super(props, values);
|
|
712
|
-
const { mode, min, max, interval } = props;
|
|
713
|
-
this._mode = mode || 2;
|
|
714
|
-
this._min = min;
|
|
715
|
-
this._max = max;
|
|
716
|
-
this._interval = interval;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
_defineValueView(): UiTypes.ViewOptions {
|
|
720
|
-
return {
|
|
721
|
-
type: "view",
|
|
722
|
-
props: {},
|
|
723
|
-
layout: (make, view) => {
|
|
724
|
-
make.top.bottom.inset(0);
|
|
725
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
726
|
-
make.right.inset(15);
|
|
727
|
-
},
|
|
728
|
-
views: [
|
|
729
|
-
{
|
|
730
|
-
type: "image",
|
|
731
|
-
props: {
|
|
732
|
-
symbol: "chevron.right",
|
|
733
|
-
tintColor: $color("lightGray", "darkGray"),
|
|
734
|
-
contentMode: 1,
|
|
735
|
-
},
|
|
736
|
-
layout: (make, view) => {
|
|
737
|
-
make.centerY.equalTo(view.super);
|
|
738
|
-
make.size.equalTo($size(17, 17));
|
|
739
|
-
make.right.inset(0);
|
|
740
|
-
},
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
type: "label",
|
|
744
|
-
props: {
|
|
745
|
-
id: "label",
|
|
746
|
-
text: dateToString(this._mode, this._value),
|
|
747
|
-
textColor: $color("secondaryText"),
|
|
748
|
-
align: $align.right,
|
|
749
|
-
},
|
|
750
|
-
layout: (make, view) => {
|
|
751
|
-
make.centerY.equalTo(view.super);
|
|
752
|
-
make.left.inset(0);
|
|
753
|
-
make.right.equalTo(view.prev.left).inset(5);
|
|
754
|
-
},
|
|
755
|
-
},
|
|
756
|
-
],
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
_handleValue(date: Date) {
|
|
761
|
-
const label = this.view.get("label") as UILabelView;
|
|
762
|
-
label.text = dateToString(this._mode, date);
|
|
763
|
-
return date;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
class InfoCell extends Cell {
|
|
768
|
-
readonly _type = "info";
|
|
769
|
-
constructor(props: PrefsRowInfo, values: PreferenceValues) {
|
|
770
|
-
super(props, values);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
_defineValueView(): UiTypes.LabelOptions {
|
|
774
|
-
return {
|
|
775
|
-
type: "label",
|
|
776
|
-
props: {
|
|
777
|
-
id: "label",
|
|
778
|
-
text: this._value,
|
|
779
|
-
textColor: $color("secondaryText"),
|
|
780
|
-
align: $align.right,
|
|
781
|
-
},
|
|
782
|
-
layout: (make, view) => {
|
|
783
|
-
make.top.bottom.inset(0);
|
|
784
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
785
|
-
make.right.inset(15);
|
|
786
|
-
},
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
_handleValue(text: string) {
|
|
791
|
-
const label = this.view.get("label") as UILabelView;
|
|
792
|
-
label.text = text;
|
|
793
|
-
return text;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
class InteractiveInfoCell extends Cell {
|
|
798
|
-
readonly _type = "interactive-info";
|
|
799
|
-
_copyable: boolean;
|
|
800
|
-
constructor(props: PrefsRowInteractiveInfo, values: PreferenceValues) {
|
|
801
|
-
super(props, values);
|
|
802
|
-
const { copyable = false } = props;
|
|
803
|
-
this._copyable = copyable;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
_defineValueView(): UiTypes.LabelOptions {
|
|
807
|
-
return {
|
|
808
|
-
type: "label",
|
|
809
|
-
props: {
|
|
810
|
-
id: "label",
|
|
811
|
-
text: this._value,
|
|
812
|
-
textColor: $color("secondaryText"),
|
|
813
|
-
align: $align.right,
|
|
814
|
-
},
|
|
815
|
-
layout: (make, view) => {
|
|
816
|
-
make.top.bottom.inset(0);
|
|
817
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
818
|
-
make.right.inset(15);
|
|
819
|
-
},
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
_handleValue(text: string) {
|
|
824
|
-
const label = this.view.get("label") as UILabelView;
|
|
825
|
-
label.text = text;
|
|
826
|
-
return text;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
class LinkCell extends Cell {
|
|
831
|
-
readonly _type = "link";
|
|
832
|
-
constructor(props: PrefsRowLink, values: PreferenceValues) {
|
|
833
|
-
super(props, values);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
_defineValueView(): UiTypes.LabelOptions {
|
|
837
|
-
return {
|
|
838
|
-
type: "label",
|
|
839
|
-
props: {
|
|
840
|
-
id: "label",
|
|
841
|
-
styledText: {
|
|
842
|
-
text: this._value,
|
|
843
|
-
font: $font(17),
|
|
844
|
-
styles: [
|
|
845
|
-
{
|
|
846
|
-
range: $range(0, this._value.length),
|
|
847
|
-
link: this._value,
|
|
848
|
-
},
|
|
849
|
-
],
|
|
850
|
-
},
|
|
851
|
-
align: $align.right,
|
|
852
|
-
},
|
|
853
|
-
layout: (make, view) => {
|
|
854
|
-
make.top.bottom.inset(0);
|
|
855
|
-
make.left.equalTo(view.prev.right).inset(10);
|
|
856
|
-
make.right.inset(15);
|
|
857
|
-
},
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
_handleValue(text: string) {
|
|
862
|
-
const label = this.view.get("label") as UILabelView;
|
|
863
|
-
label.styledText = {
|
|
864
|
-
text,
|
|
865
|
-
font: $font(17),
|
|
866
|
-
styles: [
|
|
867
|
-
{
|
|
868
|
-
range: $range(0, text.length),
|
|
869
|
-
link: text,
|
|
870
|
-
},
|
|
871
|
-
],
|
|
872
|
-
};
|
|
873
|
-
return text;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
class SymbolActionCell extends Cell {
|
|
878
|
-
readonly _type = "symbol-action";
|
|
879
|
-
_symbol: string;
|
|
880
|
-
_tintColor: UIColor;
|
|
881
|
-
_contentMode: number;
|
|
882
|
-
_symbolSize: JBSize;
|
|
883
|
-
constructor(props: PrefsRowSymbolAction, values: PreferenceValues) {
|
|
884
|
-
super(props, values);
|
|
885
|
-
this._symbol = props.symbol || "";
|
|
886
|
-
this._tintColor = props.tintColor ?? $color("primaryText");
|
|
887
|
-
this._contentMode = props.contentMode ?? 1;
|
|
888
|
-
this._symbolSize = props.symbolSize ?? $size(24, 24);
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
_defineValueView(): UiTypes.ImageOptions {
|
|
892
|
-
return {
|
|
893
|
-
type: "image",
|
|
894
|
-
props: {
|
|
895
|
-
id: "image",
|
|
896
|
-
symbol: this._symbol,
|
|
897
|
-
tintColor: this._tintColor,
|
|
898
|
-
contentMode: this._contentMode,
|
|
899
|
-
},
|
|
900
|
-
layout: (make, view) => {
|
|
901
|
-
make.centerY.equalTo(view.super);
|
|
902
|
-
make.size.equalTo(this._symbolSize);
|
|
903
|
-
make.right.inset(15);
|
|
904
|
-
},
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
_handleValue() {
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
class ActionCell extends Cell {
|
|
914
|
-
readonly _type = "action";
|
|
915
|
-
_destructive: boolean;
|
|
916
|
-
constructor(props: PrefsRowAction, values: PreferenceValues) {
|
|
917
|
-
super(props, values);
|
|
918
|
-
const { destructive = false } = props;
|
|
919
|
-
this._destructive = destructive;
|
|
920
|
-
this._values = values;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
_defineTitleView(): UiTypes.LabelOptions {
|
|
924
|
-
return {
|
|
925
|
-
type: "label",
|
|
926
|
-
props: {},
|
|
927
|
-
layout: (make) => make.width.equalTo(0),
|
|
928
|
-
};
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
_defineValueView(): UiTypes.LabelOptions {
|
|
932
|
-
return {
|
|
933
|
-
type: "label",
|
|
934
|
-
props: {
|
|
935
|
-
text: this._title,
|
|
936
|
-
textColor: this._destructive ? $color("red") : $color("systemLink"),
|
|
937
|
-
},
|
|
938
|
-
layout: (make, view) => {
|
|
939
|
-
make.top.bottom.inset(0);
|
|
940
|
-
make.left.equalTo(view.prev.left);
|
|
941
|
-
make.left.right.inset(15);
|
|
942
|
-
},
|
|
943
|
-
};
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
_handleValue() {
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
/**
|
|
952
|
-
* # cview PreferenceListView_static
|
|
953
|
-
*
|
|
954
|
-
* 便捷的设置列表实现. 其所有 cell 均为静态 cell,
|
|
955
|
-
* 可以同时使用 list 控件的 props(除了 template, data)和 events(除了 didSelect),
|
|
956
|
-
* 同时具有独特方法 set(key, value), 以及独特方法 changed
|
|
957
|
-
*
|
|
958
|
-
* sections 为 Array, 里面的 section 定义:
|
|
959
|
-
*
|
|
960
|
-
* - title?: string 标题.
|
|
961
|
-
* - rows: {type: string}[] 内容
|
|
962
|
-
*
|
|
963
|
-
* row定义:
|
|
964
|
-
*
|
|
965
|
-
* - 通用:
|
|
966
|
-
*
|
|
967
|
-
* - type: string 类型. 包括'string', 'number', 'integer', 'stepper',
|
|
968
|
-
* 'boolean', 'slider', 'list', 'tab', 'interactive-info', 'info',
|
|
969
|
-
* 'link', 'action'
|
|
970
|
-
* - key?: string 键. 如没有则不会返回其值.
|
|
971
|
-
* - title?: string 标题
|
|
972
|
-
* - value?: any 在下面专项里详解.
|
|
973
|
-
* - titleColor?: $color = $color("primaryText") 标题颜色
|
|
974
|
-
*
|
|
975
|
-
* - string:
|
|
976
|
-
*
|
|
977
|
-
* - value?: string
|
|
978
|
-
* - placeholder?: string
|
|
979
|
-
* - textColor?: $color = $color("primaryText")
|
|
980
|
-
*
|
|
981
|
-
* - number, integer:
|
|
982
|
-
*
|
|
983
|
-
* - value?: number
|
|
984
|
-
* - placeholder?: string
|
|
985
|
-
* - textColor?: $color = $color("primaryText")
|
|
986
|
-
* - min?: number 最小值
|
|
987
|
-
* - max?: number 最大值
|
|
988
|
-
*
|
|
989
|
-
* - stepper:
|
|
990
|
-
*
|
|
991
|
-
* - value?: number
|
|
992
|
-
* - placeholder?: string
|
|
993
|
-
* - min?: number 最小值
|
|
994
|
-
* - max?: number 最大值
|
|
995
|
-
*
|
|
996
|
-
* - boolean:
|
|
997
|
-
*
|
|
998
|
-
* - value?: boolean
|
|
999
|
-
* - onColor?: $color = $color("#34C85A")
|
|
1000
|
-
* - thumbColor
|
|
1001
|
-
*
|
|
1002
|
-
* - slider:
|
|
1003
|
-
*
|
|
1004
|
-
* - value?: number 即 slider.value
|
|
1005
|
-
* - decimal?: number = 1 精度
|
|
1006
|
-
* - min?: number
|
|
1007
|
-
* - max?: number
|
|
1008
|
-
* - minColor?: $color = $color("systemLink")
|
|
1009
|
-
* - maxColor?: $color
|
|
1010
|
-
* - thumbColor?: $color
|
|
1011
|
-
*
|
|
1012
|
-
* - list:
|
|
1013
|
-
*
|
|
1014
|
-
* - value?: number 即 index, -1 时为不选
|
|
1015
|
-
* - items?: string[]
|
|
1016
|
-
*
|
|
1017
|
-
* - tab:
|
|
1018
|
-
*
|
|
1019
|
-
* - value?: number 即 index, -1 时为不选
|
|
1020
|
-
* - items?: string[]
|
|
1021
|
-
*
|
|
1022
|
-
* - date:
|
|
1023
|
-
*
|
|
1024
|
-
* - value?: Date
|
|
1025
|
-
* - min?: Date
|
|
1026
|
-
* - max?: Date
|
|
1027
|
-
* - mode?: number = 2
|
|
1028
|
-
* - interval?: number
|
|
1029
|
-
*
|
|
1030
|
-
* - info:
|
|
1031
|
-
*
|
|
1032
|
-
* - value?: string
|
|
1033
|
-
*
|
|
1034
|
-
* - interactive-info:
|
|
1035
|
-
*
|
|
1036
|
-
* - value?: string
|
|
1037
|
-
* - copyable?: boolean = false
|
|
1038
|
-
*
|
|
1039
|
-
* - link:
|
|
1040
|
-
*
|
|
1041
|
-
* - value?: string url
|
|
1042
|
-
*
|
|
1043
|
-
* - symbol-action:
|
|
1044
|
-
*
|
|
1045
|
-
* - symbol?: string;
|
|
1046
|
-
* - tintColor?: UIColor;
|
|
1047
|
-
* - contentMode?: number;
|
|
1048
|
-
* - symbolSize?: JBSize;
|
|
1049
|
-
* - value?: function 点击后会执行的函数
|
|
1050
|
-
*
|
|
1051
|
-
* - action:
|
|
1052
|
-
*
|
|
1053
|
-
* - value?: function 点击后会执行的函数
|
|
1054
|
-
* - destructive?: boolean = false 是否为危险动作,若是则为红色
|
|
1055
|
-
*
|
|
1056
|
-
* Methods:
|
|
1057
|
-
*
|
|
1058
|
-
* - set(key, value) 设定 key 对应的 value
|
|
1059
|
-
* - cview.values 获取全部的 values
|
|
1060
|
-
*
|
|
1061
|
-
* Events:
|
|
1062
|
-
*
|
|
1063
|
-
* - changed: values => {}
|
|
1064
|
-
*/
|
|
1065
|
-
export class PreferenceListView extends Base<UIListView, UiTypes.ListOptions> {
|
|
1066
|
-
_defineView: () => UiTypes.ListOptions;
|
|
1067
|
-
_sections: PreferenceSection[];
|
|
1068
|
-
_props: Partial<UiTypes.ListProps>;
|
|
1069
|
-
_layout?: (make: MASConstraintMaker, view: UIListView) => void;
|
|
1070
|
-
_values: PreferenceValues;
|
|
1071
|
-
_cells: {
|
|
1072
|
-
title: string;
|
|
1073
|
-
rows: AllCells[];
|
|
1074
|
-
}[];
|
|
1075
|
-
|
|
1076
|
-
constructor({
|
|
1077
|
-
sections,
|
|
1078
|
-
props = {},
|
|
1079
|
-
layout,
|
|
1080
|
-
events = {},
|
|
1081
|
-
}: {
|
|
1082
|
-
sections: PreferenceSection[];
|
|
1083
|
-
props?: Partial<UiTypes.ListProps>;
|
|
1084
|
-
layout?: (make: MASConstraintMaker, view: UIListView) => void;
|
|
1085
|
-
events?: {
|
|
1086
|
-
changed?: (values: { [key: string]: any }) => void;
|
|
1087
|
-
};
|
|
1088
|
-
}) {
|
|
1089
|
-
super();
|
|
1090
|
-
this._sections = sections;
|
|
1091
|
-
this._values = {};
|
|
1092
|
-
sections.forEach((section) => {
|
|
1093
|
-
section.rows.forEach((row) => {
|
|
1094
|
-
if (row.key && !excludedTypes.includes(row.type)) {
|
|
1095
|
-
this._values[row.key] = row.value;
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
});
|
|
1099
|
-
this._props = props;
|
|
1100
|
-
this._layout = layout;
|
|
1101
|
-
this._cells = this._sections.map((section) => ({
|
|
1102
|
-
title: section.title,
|
|
1103
|
-
rows: section.rows.map((props) => {
|
|
1104
|
-
if (events.changed)
|
|
1105
|
-
props.changedEvent = () => {
|
|
1106
|
-
if (events.changed) events.changed(this.values);
|
|
1107
|
-
};
|
|
1108
|
-
return this._createCell(props);
|
|
1109
|
-
}),
|
|
1110
|
-
}));
|
|
1111
|
-
this._defineView = () => {
|
|
1112
|
-
return {
|
|
1113
|
-
type: "list",
|
|
1114
|
-
props: {
|
|
1115
|
-
style: 2,
|
|
1116
|
-
...this._props,
|
|
1117
|
-
id: this.id,
|
|
1118
|
-
data: this._cells.map((section) => ({
|
|
1119
|
-
title: section.title,
|
|
1120
|
-
rows: section.rows.map((cell) => cell.definition),
|
|
1121
|
-
})),
|
|
1122
|
-
},
|
|
1123
|
-
layout: this._layout,
|
|
1124
|
-
events: {
|
|
1125
|
-
didSelect: (sender, indexPath, data) => {
|
|
1126
|
-
const cell = this._cells[indexPath.section].rows[indexPath.row];
|
|
1127
|
-
switch (cell._type) {
|
|
1128
|
-
case "string": {
|
|
1129
|
-
$input.text({
|
|
1130
|
-
text: cell.value,
|
|
1131
|
-
type: $kbType.default,
|
|
1132
|
-
placeholder: cell._placeholder,
|
|
1133
|
-
handler: (text) => {
|
|
1134
|
-
cell.value = text;
|
|
1135
|
-
if (cell._changedEvent) cell._changedEvent();
|
|
1136
|
-
},
|
|
1137
|
-
});
|
|
1138
|
-
break;
|
|
1139
|
-
}
|
|
1140
|
-
case "number": {
|
|
1141
|
-
$input.text({
|
|
1142
|
-
text: cell.value,
|
|
1143
|
-
type: $kbType.decimal,
|
|
1144
|
-
placeholder: cell._placeholder,
|
|
1145
|
-
handler: (text) => {
|
|
1146
|
-
cell.value = parseFloat(text);
|
|
1147
|
-
if (cell._changedEvent) cell._changedEvent();
|
|
1148
|
-
},
|
|
1149
|
-
});
|
|
1150
|
-
break;
|
|
1151
|
-
}
|
|
1152
|
-
case "integer": {
|
|
1153
|
-
$input.text({
|
|
1154
|
-
text: cell.value,
|
|
1155
|
-
type: $kbType.number,
|
|
1156
|
-
placeholder: cell._placeholder,
|
|
1157
|
-
handler: (text) => {
|
|
1158
|
-
cell.value = parseInt(text);
|
|
1159
|
-
if (cell._changedEvent) cell._changedEvent();
|
|
1160
|
-
},
|
|
1161
|
-
});
|
|
1162
|
-
break;
|
|
1163
|
-
}
|
|
1164
|
-
case "list": {
|
|
1165
|
-
$ui.menu({
|
|
1166
|
-
items: cell._items,
|
|
1167
|
-
handler: (title, index) => {
|
|
1168
|
-
cell.value = index;
|
|
1169
|
-
if (cell._changedEvent) cell._changedEvent();
|
|
1170
|
-
},
|
|
1171
|
-
});
|
|
1172
|
-
break;
|
|
1173
|
-
}
|
|
1174
|
-
case "date": {
|
|
1175
|
-
const props: any = {};
|
|
1176
|
-
if (cell.value) props.date = cell.value;
|
|
1177
|
-
if (cell._min) props.min = cell._min;
|
|
1178
|
-
if (cell._max) props.max = cell._max;
|
|
1179
|
-
if (cell._mode) props.mode = cell._mode;
|
|
1180
|
-
if (cell._interval) props.interval = cell._interval;
|
|
1181
|
-
$picker.date({
|
|
1182
|
-
props: props,
|
|
1183
|
-
handler: (date: Date) => {
|
|
1184
|
-
cell.value = date;
|
|
1185
|
-
if (cell._changedEvent) cell._changedEvent();
|
|
1186
|
-
},
|
|
1187
|
-
});
|
|
1188
|
-
break;
|
|
1189
|
-
}
|
|
1190
|
-
case "interactive-info": {
|
|
1191
|
-
if (cell._copyable) {
|
|
1192
|
-
$ui.alert({
|
|
1193
|
-
title: cell._title,
|
|
1194
|
-
message: cell.value,
|
|
1195
|
-
actions: [
|
|
1196
|
-
{
|
|
1197
|
-
title: "取消",
|
|
1198
|
-
},
|
|
1199
|
-
{
|
|
1200
|
-
title: "复制",
|
|
1201
|
-
handler: () => {
|
|
1202
|
-
$clipboard.text = cell.value;
|
|
1203
|
-
},
|
|
1204
|
-
},
|
|
1205
|
-
],
|
|
1206
|
-
});
|
|
1207
|
-
} else {
|
|
1208
|
-
$ui.alert({
|
|
1209
|
-
title: cell._title,
|
|
1210
|
-
message: cell.value,
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
case "link": {
|
|
1216
|
-
$safari.open({ url: cell.value });
|
|
1217
|
-
break;
|
|
1218
|
-
}
|
|
1219
|
-
case "symbol-action": {
|
|
1220
|
-
if (cell.value) cell.value();
|
|
1221
|
-
break;
|
|
1222
|
-
}
|
|
1223
|
-
case "action": {
|
|
1224
|
-
if (cell.value) cell.value();
|
|
1225
|
-
break;
|
|
1226
|
-
}
|
|
1227
|
-
default:
|
|
1228
|
-
break;
|
|
1229
|
-
}
|
|
1230
|
-
},
|
|
1231
|
-
},
|
|
1232
|
-
};
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
private _createCell(props: PrefsRow) {
|
|
1237
|
-
switch (props.type) {
|
|
1238
|
-
case "string":
|
|
1239
|
-
return new StringCell(props, this._values);
|
|
1240
|
-
case "number":
|
|
1241
|
-
return new NumberCell(props, this._values);
|
|
1242
|
-
case "integer":
|
|
1243
|
-
return new IntegerCell(props, this._values);
|
|
1244
|
-
case "stepper":
|
|
1245
|
-
return new StepperCell(props, this._values);
|
|
1246
|
-
case "boolean":
|
|
1247
|
-
return new BooleanCell(props, this._values);
|
|
1248
|
-
case "slider":
|
|
1249
|
-
return new SliderCell(props, this._values);
|
|
1250
|
-
case "list":
|
|
1251
|
-
return new ListCell(props, this._values);
|
|
1252
|
-
case "tab":
|
|
1253
|
-
return new TabCell(props, this._values);
|
|
1254
|
-
case "date":
|
|
1255
|
-
return new DateCell(props, this._values);
|
|
1256
|
-
case "info":
|
|
1257
|
-
return new InfoCell(props, this._values);
|
|
1258
|
-
case "interactive-info":
|
|
1259
|
-
return new InteractiveInfoCell(props, this._values);
|
|
1260
|
-
case "link":
|
|
1261
|
-
return new LinkCell(props, this._values);
|
|
1262
|
-
case "symbol-action":
|
|
1263
|
-
return new SymbolActionCell(props, this._values);
|
|
1264
|
-
case "action":
|
|
1265
|
-
return new ActionCell(props, this._values);
|
|
1266
|
-
default:
|
|
1267
|
-
throw new Error("Invalid cell type");
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
get values() {
|
|
1272
|
-
return this._values;
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
set(key: string, value: any) {
|
|
1276
|
-
this._cells.forEach((section) => {
|
|
1277
|
-
section.rows.forEach((row) => {
|
|
1278
|
-
if (row.key === key) row.value = value;
|
|
1279
|
-
});
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
}
|