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.
Files changed (164) hide show
  1. package/README.md +4 -0
  2. package/dist/components/alert/input-alert.d.ts +22 -0
  3. package/dist/components/alert/input-alert.js +1 -2
  4. package/dist/components/alert/login-alert.d.ts +21 -0
  5. package/dist/components/alert/login-alert.js +1 -2
  6. package/dist/components/alert/plain-alert.d.ts +15 -0
  7. package/dist/components/alert/plain-alert.js +1 -2
  8. package/dist/components/alert/uialert.d.ts +29 -0
  9. package/{components/base.ts → dist/components/base.d.ts} +9 -28
  10. package/dist/components/custom-navigation-bar.d.ts +117 -0
  11. package/dist/components/custom-navigation-bar.js +7 -1
  12. package/dist/components/dialogs/dialog-sheet.d.ts +46 -0
  13. package/dist/components/dialogs/dialog-sheet.js +3 -1
  14. package/dist/components/dialogs/form-dialog.d.ts +15 -0
  15. package/dist/components/dialogs/form-dialog.js +1 -2
  16. package/dist/components/dialogs/list-dialog.d.ts +23 -0
  17. package/dist/components/dialogs/list-dialog.js +2 -3
  18. package/dist/components/dialogs/text-dialog.d.ts +13 -0
  19. package/dist/components/dialogs/text-dialog.js +1 -2
  20. package/dist/components/dynamic-contextmenu-view.d.ts +40 -0
  21. package/dist/components/dynamic-contextmenu-view.js +5 -1
  22. package/dist/components/dynamic-itemsize-matrix.d.ts +79 -0
  23. package/dist/components/dynamic-itemsize-matrix.js +18 -15
  24. package/dist/components/dynamic-itemsize-section-matrix.d.ts +115 -0
  25. package/dist/components/dynamic-itemsize-section-matrix.js +293 -0
  26. package/dist/components/dynamic-preference-listview.d.ts +63 -0
  27. package/dist/components/dynamic-preference-listview.js +25 -16
  28. package/dist/components/dynamic-rowheight-list.d.ts +38 -0
  29. package/dist/components/dynamic-rowheight-list.js +10 -3
  30. package/dist/components/enhanced-imageview.d.ts +41 -0
  31. package/dist/components/enhanced-imageview.js +1 -1
  32. package/dist/components/flowlayout.d.ts +63 -0
  33. package/dist/components/flowlayout.js +10 -13
  34. package/dist/components/image-pager.d.ts +49 -0
  35. package/dist/components/image-pager.js +6 -1
  36. package/dist/components/oc-webview.d.ts +64 -0
  37. package/dist/components/oc-webview.js +13 -5
  38. package/dist/components/page-control.d.ts +45 -0
  39. package/dist/components/page-control.js +2 -13
  40. package/dist/components/pageviewer-titlebar.d.ts +48 -0
  41. package/dist/components/pageviewer-titlebar.js +7 -13
  42. package/dist/components/pageviewer.d.ts +41 -0
  43. package/dist/components/pageviewer.js +4 -1
  44. package/dist/components/refresh-button.d.ts +25 -0
  45. package/dist/components/refresh-button.js +3 -4
  46. package/dist/components/rotating-view.d.ts +45 -0
  47. package/dist/components/rotating-view.js +10 -2
  48. package/dist/components/searchbar.d.ts +118 -0
  49. package/dist/components/searchbar.js +8 -1
  50. package/dist/components/sheet.d.ts +42 -0
  51. package/dist/components/single-views.d.ts +289 -0
  52. package/dist/components/single-views.js +11 -4
  53. package/dist/components/spinners/loading-dual-ring.d.ts +18 -0
  54. package/dist/components/spinners/loading-wedges.d.ts +15 -0
  55. package/dist/components/spinners/spinner-androidstyle.d.ts +30 -0
  56. package/dist/components/spinners/spinner-androidstyle.js +7 -1
  57. package/dist/components/static-preference-listview.d.ts +389 -0
  58. package/dist/components/static-preference-listview.js +13 -10
  59. package/dist/components/symbol-button.d.ts +39 -0
  60. package/dist/components/symbol-button.js +8 -1
  61. package/dist/components/tabbar.d.ts +140 -0
  62. package/dist/components/tabbar.js +8 -1
  63. package/dist/controller/base-controller.d.ts +125 -0
  64. package/dist/controller/base-controller.js +11 -11
  65. package/dist/controller/controller-router.d.ts +48 -0
  66. package/dist/controller/pageviewer-controller.d.ts +38 -0
  67. package/dist/controller/pageviewer-controller.js +4 -1
  68. package/dist/controller/presented-page-controller.d.ts +41 -0
  69. package/dist/controller/presented-page-controller.js +7 -9
  70. package/dist/controller/splitview-controller.d.ts +90 -0
  71. package/dist/controller/splitview-controller.js +27 -11
  72. package/dist/controller/tabbar-controller.d.ts +49 -0
  73. package/dist/controller/tabbar-controller.js +12 -15
  74. package/{index.ts → dist/index.d.ts} +2 -0
  75. package/dist/index.js +2 -0
  76. package/dist/utils/colors.d.ts +7 -0
  77. package/dist/utils/cvid.d.ts +11 -0
  78. package/dist/utils/l10n.d.ts +1 -0
  79. package/dist/utils/l10n.js +1 -2
  80. package/dist/utils/path.d.ts +8 -0
  81. package/dist/utils/path.js +8 -9
  82. package/dist/utils/rect.d.ts +38 -0
  83. package/dist/utils/rect.js +8 -9
  84. package/dist/utils/uitools.d.ts +75 -0
  85. package/dist/utils/uitools.js +6 -6
  86. package/package.json +20 -5
  87. package/.prettierignore +0 -6
  88. package/.prettierrc +0 -3
  89. package/components/alert/input-alert.ts +0 -64
  90. package/components/alert/login-alert.ts +0 -66
  91. package/components/alert/plain-alert.ts +0 -39
  92. package/components/alert/uialert.ts +0 -107
  93. package/components/custom-navigation-bar.ts +0 -579
  94. package/components/dialogs/dialog-sheet.ts +0 -111
  95. package/components/dialogs/form-dialog.ts +0 -63
  96. package/components/dialogs/list-dialog.ts +0 -119
  97. package/components/dialogs/text-dialog.ts +0 -44
  98. package/components/dynamic-contextmenu-view.ts +0 -115
  99. package/components/dynamic-itemsize-matrix.ts +0 -206
  100. package/components/dynamic-preference-listview.ts +0 -684
  101. package/components/dynamic-rowheight-list.ts +0 -77
  102. package/components/enhanced-imageview.ts +0 -132
  103. package/components/flowlayout.ts +0 -248
  104. package/components/image-pager.ts +0 -180
  105. package/components/oc-webview.ts +0 -177
  106. package/components/page-control.ts +0 -93
  107. package/components/pageviewer-titlebar.ts +0 -166
  108. package/components/pageviewer.ts +0 -125
  109. package/components/refresh-button.ts +0 -83
  110. package/components/rotating-view.ts +0 -133
  111. package/components/searchbar.ts +0 -398
  112. package/components/sheet.ts +0 -104
  113. package/components/single-views.ts +0 -956
  114. package/components/spinners/loading-dual-ring.ts +0 -97
  115. package/components/spinners/loading-wedges.ts +0 -106
  116. package/components/spinners/spinner-androidstyle.ts +0 -269
  117. package/components/static-preference-listview.ts +0 -1282
  118. package/components/symbol-button.ts +0 -108
  119. package/components/tabbar.ts +0 -453
  120. package/controller/base-controller.ts +0 -214
  121. package/controller/controller-router.ts +0 -73
  122. package/controller/pageviewer-controller.ts +0 -93
  123. package/controller/presented-page-controller.ts +0 -76
  124. package/controller/splitview-controller.ts +0 -359
  125. package/controller/tabbar-controller.ts +0 -131
  126. package/dist/test/custom-navigation-bar.js +0 -40
  127. package/dist/test/dialog-sheet.js +0 -40
  128. package/dist/test/dynamic-contextmenu-view.js +0 -66
  129. package/dist/test/dynamic-itemsize-matrix.js +0 -74
  130. package/dist/test/dynamic-preference-listview.js +0 -150
  131. package/dist/test/flowlayout.js +0 -76
  132. package/dist/test/form-dialog.js +0 -51
  133. package/dist/test/oc-webview.js +0 -195
  134. package/dist/test/pageviewer-controller.js +0 -20
  135. package/dist/test/pageviewer-titlebar.js +0 -18
  136. package/dist/test/pageviewer.js +0 -32
  137. package/dist/test/refresh-button.js +0 -26
  138. package/dist/test/searchbar.js +0 -36
  139. package/dist/test/splitview-controller.js +0 -41
  140. package/dist/test/static-preference-listview.js +0 -143
  141. package/dist/test/tabbar-controller.js +0 -48
  142. package/test/custom-navigation-bar.ts +0 -40
  143. package/test/dialog-sheet.ts +0 -40
  144. package/test/dynamic-contextmenu-view.ts +0 -67
  145. package/test/dynamic-itemsize-matrix.ts +0 -74
  146. package/test/dynamic-preference-listview.ts +0 -151
  147. package/test/flowlayout.ts +0 -79
  148. package/test/form-dialog.ts +0 -48
  149. package/test/oc-webview.ts +0 -197
  150. package/test/pageviewer-controller.ts +0 -21
  151. package/test/pageviewer-titlebar.ts +0 -18
  152. package/test/pageviewer.ts +0 -31
  153. package/test/refresh-button.ts +0 -26
  154. package/test/searchbar.ts +0 -38
  155. package/test/splitview-controller.ts +0 -42
  156. package/test/static-preference-listview.ts +0 -142
  157. package/test/tabbar-controller.ts +0 -49
  158. package/tsconfig.json +0 -122
  159. package/utils/colors.ts +0 -17
  160. package/utils/cvid.ts +0 -32
  161. package/utils/l10n.ts +0 -42
  162. package/utils/path.ts +0 -97
  163. package/utils/rect.ts +0 -90
  164. package/utils/uitools.ts +0 -122
@@ -1,684 +0,0 @@
1
- import { Base } from "./base";
2
- import {
3
- PreferenceSection,
4
- PrefsRow,
5
- PrefsRowString,
6
- PrefsRowNumber,
7
- PrefsRowInteger,
8
- PrefsRowStepper,
9
- PrefsRowBoolean,
10
- PrefsRowSlider,
11
- PrefsRowList,
12
- PrefsRowTab,
13
- PrefsRowDate,
14
- PrefsRowInfo,
15
- PrefsRowInteractiveInfo,
16
- PrefsRowLink,
17
- PrefsRowSymbolAction,
18
- PrefsRowAction,
19
- selectableTypes,
20
- excludedTypes,
21
- dateToString,
22
- } from "./static-preference-listview";
23
-
24
- interface CunstomProps extends UiTypes.ListProps {
25
- stringLeftInset?: number;
26
- infoAndLinkLeftInset?: number;
27
- sliderWidth?: number;
28
- tabWidth?: number;
29
- symbolSizeForSymbolAction?: JBSize;
30
- }
31
-
32
- interface RequiredCunstomProps extends UiTypes.ListProps {
33
- stringLeftInset: number;
34
- infoAndLinkLeftInset: number;
35
- sliderWidth: number;
36
- tabWidth: number;
37
- symbolSizeForSymbolAction: JBSize;
38
- }
39
-
40
- /**
41
- * # cview PreferenceListView_dynamic
42
- *
43
- * 便捷的设置列表实现. 样式以及功能均以 PreferenceListView_static 为准.
44
- *
45
- * 优势在于:
46
- *
47
- * - 可以实现 sections 重新写入.
48
- *
49
- * 劣势在于:
50
- *
51
- * - 由于每个 cell 不能单独布局, 因此标题和内容的长度无法动态调整, 在两者都比较短的情况下没有问题, 长了布局可能会重叠.
52
- * - 不能真正实现 selectable 为 false, 分割线仍然会闪动
53
- *
54
- * 为了缓解上面的问题, 让修改布局无需调整源代码, 增加下列 props:
55
- *
56
- * - stringLeftInset?: number = 120 将同时作用于 string, number, integer, list, date
57
- * 但是由于后四者内容可控, 可视为只作用于 string
58
- * - infoAndLinkLeftInset?: number = 120 作用于 info, link
59
- * - sliderWidth?: number = 200 作用于 slider
60
- * - tabWidth?: number = 200 作用于 tab
61
- * - symbolSizeForSymbolAction?: size = $size(24, 24) 作用于symbol-action
62
- * 注意以上的修改是应用于 template, 而不是应用于单个 cell 的
63
- *
64
- * 独特方法:
65
- *
66
- * - cview.sections = sections 可以写入新的 sections
67
- */
68
- export class DynamicPreferenceListView extends Base<UIListView, UiTypes.ListOptions> {
69
- _defineView: () => UiTypes.ListOptions;
70
- private _sections: PreferenceSection[];
71
- private _props: RequiredCunstomProps;
72
- constructor({
73
- sections,
74
- props,
75
- layout,
76
- events = {},
77
- }: {
78
- sections: PreferenceSection[];
79
- props: CunstomProps;
80
- layout?: (make: MASConstraintMaker, view: UIListView) => void;
81
- events?: {
82
- changed?: (values: any) => void;
83
- };
84
- }) {
85
- super();
86
- this._sections = sections.map((n) => ({
87
- title: n.title,
88
- rows: n.rows.map((r) => ({ ...r })),
89
- }));
90
- this._props = {
91
- stringLeftInset: 120,
92
- infoAndLinkLeftInset: 120,
93
- sliderWidth: 200,
94
- tabWidth: 200,
95
- symbolSizeForSymbolAction: $size(24, 24),
96
- ...props,
97
- };
98
- this._layout = layout;
99
- this._defineView = () => {
100
- return {
101
- type: "list",
102
- props: {
103
- style: 2,
104
- ...this._props,
105
- id: this.id,
106
- template: {
107
- views: [
108
- {
109
- type: "view",
110
- props: {
111
- id: "bgview",
112
- bgcolor: $color("secondarySurface"),
113
- },
114
- layout: $layout.fill,
115
- },
116
- {
117
- type: "label",
118
- props: {
119
- id: "title",
120
- font: $font(17),
121
- },
122
- layout: (make, view) => {
123
- make.top.bottom.inset(0);
124
- make.left.right.inset(15);
125
- },
126
- },
127
- {
128
- type: "view",
129
- props: {},
130
- layout: (make, view) => {
131
- make.top.bottom.inset(0);
132
- make.left.right.inset(15);
133
- },
134
- views: [
135
- {
136
- type: "view",
137
- props: {
138
- id: "label_and_chevron",
139
- },
140
- layout: $layout.fill,
141
- views: [
142
- {
143
- type: "image",
144
- props: {
145
- symbol: "chevron.right",
146
- tintColor: $color("lightGray", "darkGray"),
147
- contentMode: 1,
148
- },
149
- layout: (make, view) => {
150
- make.centerY.equalTo(view.super);
151
- make.size.equalTo($size(17, 17));
152
- make.right.inset(0);
153
- },
154
- },
155
- {
156
- type: "label",
157
- props: {
158
- id: "label_before_chevron",
159
- align: $align.right,
160
- font: $font(17),
161
- },
162
- layout: (make, view) => {
163
- make.centerY.equalTo(view.super);
164
- make.left.inset(this._props.stringLeftInset - 15);
165
- make.right.equalTo(view.prev.left).inset(5);
166
- },
167
- },
168
- ],
169
- },
170
- {
171
- type: "view",
172
- props: {
173
- id: "number_and_stepper",
174
- },
175
- layout: $layout.fill,
176
- views: [
177
- {
178
- type: "stepper",
179
- props: {
180
- id: "stepper",
181
- },
182
- layout: (make, view) => {
183
- make.centerY.equalTo(view.super);
184
- make.right.inset(0);
185
- },
186
- events: {
187
- changed: (sender) => {
188
- const { section, row } = sender.info;
189
- this._sections[section].rows[row].value = sender.value;
190
- const label = sender.next as UILabelView;
191
- label.text = sender.value.toString();
192
- if (events.changed) events.changed(this.values);
193
- },
194
- },
195
- },
196
- {
197
- type: "label",
198
- props: {
199
- id: "label_stepper",
200
- align: $align.right,
201
- },
202
- layout: (make, view) => {
203
- make.top.bottom.inset(0);
204
- make.right.equalTo(view.prev.left).inset(10);
205
- make.width.equalTo(100);
206
- },
207
- },
208
- ],
209
- },
210
- {
211
- type: "view",
212
- props: {
213
- id: "slider_and_number",
214
- },
215
- layout: $layout.fill,
216
- views: [
217
- {
218
- type: "slider",
219
- props: {
220
- id: "slider",
221
- min: 0,
222
- max: 1,
223
- },
224
- layout: (make, view) => {
225
- make.centerY.equalTo(view.super);
226
- make.right.inset(40);
227
- make.width.equalTo(this._props.sliderWidth - 40);
228
- },
229
- events: {
230
- changed: (sender) => {
231
- const { section, row } = sender.info;
232
- const options = this._sections[section].rows[row] as PrefsRowSlider;
233
- const label = sender.next as UILabelView;
234
- label.text = this._handleSliderValue(
235
- sender.value * (options.max ?? 1),
236
- options.decimal,
237
- options.min,
238
- options.max,
239
- ).toString();
240
- },
241
- touchesEnded: (sender) => {
242
- const { section, row } = sender.info;
243
- const options = this._sections[section].rows[row] as PrefsRowSlider;
244
- this._sections[section].rows[row].value = this._handleSliderValue(
245
- sender.value * (options.max ?? 1),
246
- options.decimal,
247
- options.min,
248
- options.max,
249
- );
250
- if (events.changed) events.changed(this.values);
251
- },
252
- },
253
- },
254
- {
255
- type: "label",
256
- props: {
257
- id: "label_slider",
258
- align: $align.center,
259
- },
260
- layout: (make, view) => {
261
- make.top.bottom.inset(0);
262
- make.right.inset(0);
263
- make.width.equalTo(44);
264
- },
265
- },
266
- ],
267
- },
268
- {
269
- type: "switch",
270
- props: {
271
- id: "switch",
272
- },
273
- layout: (make, view) => {
274
- make.centerY.equalTo(view.super);
275
- make.right.inset(0);
276
- },
277
- events: {
278
- changed: (sender) => {
279
- const { section, row } = sender.info;
280
- this._sections[section].rows[row].value = sender.on;
281
- if (events.changed) events.changed(this.values);
282
- },
283
- },
284
- },
285
- {
286
- type: "tab",
287
- props: {
288
- id: "tab",
289
- },
290
- layout: (make, view) => {
291
- make.centerY.equalTo(view.super);
292
- make.height.equalTo(32);
293
- make.width.equalTo(this._props.tabWidth);
294
- make.right.inset(0);
295
- },
296
- events: {
297
- changed: (sender) => {
298
- const { section, row } = sender.info;
299
- this._sections[section].rows[row].value = sender.index;
300
- if (events.changed) events.changed(this.values);
301
- },
302
- },
303
- },
304
- {
305
- type: "label",
306
- props: {
307
- id: "label_info_link",
308
- align: $align.right,
309
- },
310
- layout: (make, view) => {
311
- make.top.bottom.inset(0);
312
- make.left.inset(this._props.infoAndLinkLeftInset);
313
- make.right.inset(0);
314
- },
315
- },
316
- {
317
- type: "image",
318
- props: {
319
- id: "symbol",
320
- },
321
- layout: (make, view) => {
322
- make.centerY.equalTo(view.super);
323
- make.size.equalTo(this._props.symbolSizeForSymbolAction);
324
- make.right.inset(0);
325
- },
326
- },
327
- ],
328
- },
329
- ],
330
- },
331
- data: this._map(this._sections),
332
- },
333
- layout: this._layout,
334
- events: {
335
- didSelect: (sender, indexPath, data) => {
336
- const row = this._sections[indexPath.section].rows[indexPath.row];
337
- if (!selectableTypes.includes(row.type)) return;
338
- switch (row.type) {
339
- case "string": {
340
- $input.text({
341
- text: row.value,
342
- type: $kbType.default,
343
- placeholder: row.placeholder,
344
- handler: (text) => {
345
- row.value = text;
346
- sender.data = this._map(this._sections);
347
- if (events.changed) events.changed(this.values);
348
- },
349
- });
350
- break;
351
- }
352
- case "number": {
353
- $input.text({
354
- text: row.value?.toString(),
355
- type: $kbType.decimal,
356
- placeholder: row.placeholder,
357
- handler: (text) => {
358
- let num = this._handleText(text, row.type);
359
- if (num === undefined) return;
360
- if (row.min !== undefined && num < row.min) num = row.min;
361
- if (row.max !== undefined && num > row.max) num = row.max;
362
- row.value = num;
363
- sender.data = this._map(this._sections);
364
- if (events.changed) events.changed(this.values);
365
- },
366
- });
367
- break;
368
- }
369
- case "integer": {
370
- $input.text({
371
- text: row.value?.toString(),
372
- type: $kbType.number,
373
- placeholder: row.placeholder,
374
- handler: (text) => {
375
- let num = this._handleText(text, row.type);
376
- if (num === undefined) return;
377
- if (row.min !== undefined && num < row.min) num = row.min;
378
- if (row.max !== undefined && num > row.max) num = row.max;
379
- row.value = num;
380
- sender.data = this._map(this._sections);
381
- if (events.changed) events.changed(this.values);
382
- },
383
- });
384
- break;
385
- }
386
- case "list": {
387
- $ui.menu({
388
- items: row.items,
389
- handler: (title, index) => {
390
- row.value = index;
391
- sender.data = this._map(this._sections);
392
- if (events.changed) events.changed(this.values);
393
- },
394
- });
395
- break;
396
- }
397
- case "date": {
398
- const props: any = {};
399
- if (row.value) props.date = row.value;
400
- if (row.min) props.min = row.min;
401
- if (row.max) props.max = row.max;
402
- if (row.mode) props.mode = row.mode;
403
- if (row.interval) props.interval = row.interval;
404
- $picker.date({
405
- props: props,
406
- handler: (date: Date) => {
407
- row.value = date;
408
- sender.data = this._map(this._sections);
409
- if (events.changed) events.changed(this.values);
410
- },
411
- });
412
- break;
413
- }
414
- case "interactive-info": {
415
- if (row.copyable) {
416
- $ui.alert({
417
- title: row.title,
418
- message: row.value,
419
- actions: [
420
- {
421
- title: "取消",
422
- },
423
- {
424
- title: "复制",
425
- handler: () => {
426
- $clipboard.text = row.value || "";
427
- },
428
- },
429
- ],
430
- });
431
- } else {
432
- $ui.alert({
433
- title: row.title,
434
- message: row.value,
435
- });
436
- }
437
- break;
438
- }
439
- case "link": {
440
- if (row.value) $safari.open({ url: row.value });
441
- break;
442
- }
443
- case "symbol-action": {
444
- if (row.value) row.value();
445
- break;
446
- }
447
- case "action": {
448
- if (row.value) row.value();
449
- break;
450
- }
451
- default:
452
- break;
453
- }
454
- },
455
- },
456
- };
457
- };
458
- }
459
-
460
- _handleText(text: string, type: string) {
461
- switch (type) {
462
- case "number": {
463
- const number = parseFloat(text);
464
- if (isNaN(number)) return;
465
- return number;
466
- }
467
- case "integer": {
468
- const number = parseInt(text);
469
- if (isNaN(number)) return;
470
- return number;
471
- }
472
- case "stepper": {
473
- const number = parseInt(text);
474
- if (isNaN(number)) return;
475
- return number;
476
- }
477
- default:
478
- throw new Error("Invalid type");
479
- }
480
- }
481
-
482
- _handleSliderValue(num?: number, decimal?: number, min?: number, max?: number): number {
483
- if (num === undefined) return min || 0;
484
- if (decimal === undefined) decimal = 1;
485
- if (isNaN(num)) num = min || 0;
486
- if (min !== undefined && num < min) num = min;
487
- if (max !== undefined && num > max) num = max;
488
- const adjustedValue = parseFloat(num.toFixed(decimal));
489
- return adjustedValue;
490
- }
491
-
492
- _map(sections: PreferenceSection[]) {
493
- function generateDefaultRow(options: PrefsRow): any {
494
- return {
495
- bgview: { hidden: selectableTypes.includes(options.type) },
496
- // bgview其实是用于调整selectable, 显示此视图就没有highlight效果
497
- title: {
498
- text: options.title,
499
- textColor: options.titleColor || $color("primaryText"),
500
- }, // 标题, 同时用于action
501
- label_and_chevron: { hidden: true },
502
- // 用于string, number, integer, list, date
503
- number_and_stepper: { hidden: true }, // 用于stepper
504
- slider_and_number: { hidden: true }, // 用于slider
505
- switch: { hidden: true }, // 用于boolean
506
- tab: { hidden: true }, // 用于tab
507
- label_info_link: { hidden: true }, // 用于info, link
508
- symbol: { hidden: true },
509
- };
510
- }
511
- return sections.map((section, sectionIndex) => ({
512
- title: section.title,
513
- rows: section.rows.map((n, rowIndex) => {
514
- const data = generateDefaultRow(n);
515
- switch (n.type) {
516
- case "string": {
517
- data.label_and_chevron.hidden = false;
518
- data.label_before_chevron = {
519
- textColor: n.textColor || $color("primaryText"),
520
- text: n.value === undefined ? "" : n.value,
521
- };
522
- break;
523
- }
524
- case "number": {
525
- data.label_and_chevron.hidden = false;
526
- data.label_before_chevron = {
527
- textColor: n.textColor || $color("primaryText"),
528
- text: n.value === undefined ? "" : n.value,
529
- };
530
- break;
531
- }
532
- case "integer": {
533
- data.label_and_chevron.hidden = false;
534
- data.label_before_chevron = {
535
- textColor: n.textColor || $color("primaryText"),
536
- text: n.value === undefined ? "" : n.value,
537
- };
538
- break;
539
- }
540
- case "stepper": {
541
- data.number_and_stepper.hidden = false;
542
- data.label_stepper = {
543
- textColor: $color("primaryText"),
544
- text: n.value === undefined ? "" : n.value,
545
- };
546
- data.stepper = {
547
- min: n.min,
548
- max: n.max,
549
- value: n.value,
550
- info: { section: sectionIndex, row: rowIndex, key: n.key },
551
- };
552
- break;
553
- }
554
- case "boolean": {
555
- data.switch = {
556
- hidden: false,
557
- on: n.value,
558
- onColor: n.onColor || $color("#34C85A"),
559
- thumbColor: n.thumbColor,
560
- info: { section: sectionIndex, row: rowIndex, key: n.key },
561
- };
562
- break;
563
- }
564
- case "slider": {
565
- data.slider_and_number.hidden = false;
566
- const adjustedValue = this._handleSliderValue(n.value, n.decimal, n.min, n.max);
567
- data.label_slider = {
568
- textColor: $color("primaryText"),
569
- text: adjustedValue,
570
- };
571
- data.slider = {
572
- value: adjustedValue / (n.max ?? 1),
573
- info: { section: sectionIndex, row: rowIndex, key: n.key },
574
- //min: n.min, // 不可用,否则会出现slider滑动结束变为0点的bug
575
- //max: n.max,
576
- minColor: n.minColor || $color("systemLink"),
577
- maxColor: n.maxColor,
578
- thumbColor: n.thumbColor,
579
- };
580
- break;
581
- }
582
- case "list": {
583
- data.label_and_chevron.hidden = false;
584
- data.label_before_chevron = {
585
- textColor: $color("secondaryText"),
586
- text: n.items[n.value || 0],
587
- };
588
- break;
589
- }
590
- case "tab": {
591
- data.tab = {
592
- hidden: false,
593
- items: n.items,
594
- index: n.value,
595
- info: { section: sectionIndex, row: rowIndex, key: n.key },
596
- };
597
- break;
598
- }
599
- case "date": {
600
- data.label_and_chevron.hidden = false;
601
- data.label_before_chevron = {
602
- hidden: false,
603
- textColor: $color("secondaryText"),
604
- text: dateToString(n.mode || 2, n.value),
605
- };
606
- break;
607
- }
608
- case "info": {
609
- data.label_info_link = {
610
- hidden: false,
611
- textColor: $color("secondaryText"),
612
- text: n.value,
613
- };
614
- break;
615
- }
616
- case "interactive-info": {
617
- data.label_info_link = {
618
- hidden: false,
619
- textColor: $color("secondaryText"),
620
- text: n.value,
621
- };
622
- break;
623
- }
624
- case "link": {
625
- data.label_info_link = {
626
- hidden: false,
627
- styledText: `[${n.value}]()`,
628
- };
629
- break;
630
- }
631
- case "symbol-action": {
632
- data.symbol = {
633
- hidden: n.symbol ? false : true,
634
- symbol: n.symbol,
635
- tintColor: n.tintColor ?? $color("primaryText"),
636
- contentMode: n.contentMode ?? 1,
637
- };
638
- break;
639
- }
640
- case "action": {
641
- data.title.textColor = n.destructive ? $color("red") : $color("systemLink");
642
- break;
643
- }
644
- default:
645
- break;
646
- }
647
- return data;
648
- }),
649
- }));
650
- }
651
-
652
- get sections() {
653
- return this._sections;
654
- }
655
-
656
- set sections(sections) {
657
- this._sections = sections.map((n) => ({
658
- title: n.title,
659
- rows: n.rows.map((r) => ({ ...r })),
660
- }));
661
- this.view.data = this._map(this._sections);
662
- }
663
-
664
- get values() {
665
- const values: { [key: string]: any } = {};
666
- this._sections.forEach((section) => {
667
- section.rows.forEach((row) => {
668
- if (row.key && !excludedTypes.includes(row.type)) {
669
- values[row.key] = row.value;
670
- }
671
- });
672
- });
673
- return values;
674
- }
675
-
676
- set(key: string, value: any) {
677
- this._sections.forEach((section) => {
678
- section.rows.forEach((row) => {
679
- if (row.key === key) row.value = value;
680
- });
681
- });
682
- this.view.data = this._map(this._sections);
683
- }
684
- }