jsbox-cview 1.0.0 → 1.1.0

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 (47) hide show
  1. package/dist/components/alert/input-alert.js +39 -0
  2. package/dist/components/alert/login-alert.js +45 -0
  3. package/dist/components/alert/plain-alert.js +25 -0
  4. package/dist/components/alert/uialert.js +89 -0
  5. package/dist/components/artificial-flowlayout.js +258 -0
  6. package/dist/components/base.js +43 -0
  7. package/dist/components/custom-navigation-bar.js +519 -0
  8. package/dist/components/dialogs/dialog-sheet.js +67 -0
  9. package/dist/components/dialogs/form-dialog.js +24 -0
  10. package/dist/components/dialogs/list-dialog.js +87 -0
  11. package/dist/components/dialogs/text-dialog.js +31 -0
  12. package/dist/components/dynamic-itemsize-matrix.js +129 -0
  13. package/dist/components/dynamic-preference-listview.js +557 -0
  14. package/dist/components/dynamic-rowheight-list.js +44 -0
  15. package/dist/components/enhanced-imageview.js +114 -0
  16. package/dist/components/image-pager.js +157 -0
  17. package/dist/components/page-control.js +76 -0
  18. package/dist/components/pageviewer-titlebar.js +143 -0
  19. package/dist/components/pageviewer.js +96 -0
  20. package/dist/components/rotating-view.js +102 -0
  21. package/dist/components/searchbar.js +322 -0
  22. package/dist/components/sheet.js +82 -0
  23. package/dist/components/single-views.js +429 -0
  24. package/dist/components/spinners/loading-double-rings.js +104 -0
  25. package/dist/components/spinners/loading-dual-ring.js +82 -0
  26. package/dist/components/spinners/loading-wedges.js +104 -0
  27. package/dist/components/spinners/spinner-androidstyle.js +248 -0
  28. package/dist/components/static-preference-listview.js +798 -0
  29. package/dist/components/symbol-button.js +79 -0
  30. package/dist/components/tabbar.js +357 -0
  31. package/dist/controller/base-controller.js +178 -0
  32. package/dist/controller/controller-router.js +68 -0
  33. package/dist/controller/pageviewer-controller.js +63 -0
  34. package/dist/controller/presented-page-controller.js +48 -0
  35. package/dist/controller/splitview-controller.js +252 -0
  36. package/dist/controller/tabbar-controller.js +74 -0
  37. package/dist/index.js +58 -0
  38. package/dist/test.js +1 -0
  39. package/dist/utils/colors.js +15 -0
  40. package/dist/utils/cvid.js +28 -0
  41. package/dist/utils/l10n.js +44 -0
  42. package/dist/utils/path.js +107 -0
  43. package/dist/utils/rect.js +72 -0
  44. package/dist/utils/uitools.js +95 -0
  45. package/index.ts +42 -0
  46. package/package.json +4 -3
  47. package/tsconfig.json +5 -3
@@ -0,0 +1,519 @@
1
+ "use strict";
2
+ /**
3
+ * # CView Custom NavigationBar
4
+ *
5
+ * 仿制 navBar
6
+ *
7
+ * ## features:
8
+ *
9
+ * - 拥有隐藏、最小化、普通、扩展四种布局方式
10
+ * - 隐藏: 什么都不显示
11
+ * - 最小化: safeAreaHeight 为 25, 只显示 titleView, 若用 title, font 为\$font(14)
12
+ * - 普通: safeAreaHeight 为 50, 显示 titleView, leftBarButtonItems 或 popButton, rightBarButtonItems, 若用 title, font 为\$font("bold", 17)
13
+ * - 扩展: safeAreaHeight 为 100, 除上面的之外, 再显示一个 toolView
14
+ * - 自动适应全面屏和非全面屏
15
+ *
16
+ * ## Arguments
17
+ *
18
+ * props:
19
+ *
20
+ * - 读写 style: number 0, 1, 2, 3,指定布局
21
+ * - 读写 title: string 但必须使用此种方案才可以在生成后写入,自动创建 Label 作为 titleView
22
+ * - titleView: cview 自定义的 titleView
23
+ * - popButtonEnabled: boolean 返回上一级的按钮,若为 true,则 leftBarButtonItems 忽略
24
+ * - popButtonTitle: string 返回上一级的按钮标题
25
+ * - popToRootEnabled: boolean popButton 是否可以长按返回到顶级
26
+ * - leftBarButtonItems: cview[]
27
+ * | {symbol: string, handler: () => void, tintColor?: UIColor}[]
28
+ * | {title: string, handler: () => void, tintColor?: UIColor}[]
29
+ * | {image: UIImage, handler: () => void, tintColor?: UIColor}[]
30
+ * 如果用的是 cview,其布局将被重新指定,即不需要(也不能)指定布局。可以通过 cview.width 来指定应有的宽度,如果没有此属性,则宽度为 50
31
+ * 建议最多放两个
32
+ * - rightBarButtonItems 定义同上,建议最多放两个
33
+ * - toolView: cview 在 expanded 模式下才会显现的
34
+ * - tintColor: UIColor 这将作用于 title, popButton, 自动创建的 barButton
35
+ * - bgcolor: UIColor 如不设置,则自动使用 blur(style 10),如果设置则没有 blur 效果
36
+ *
37
+ * events:
38
+ *
39
+ * - hidden: cview => void hide()时执行
40
+ * - minimized: cview => void minimize()时执行
41
+ * - restored: cview => void restore()时执行
42
+ * - expanded: cview => void expand()时执行
43
+ * - popHandler: cview => void 返回上一级时执行,需要popButtonEnabled
44
+ * - popToRootHandler: cview => void 返回顶级时执行,需要popButtonEnabled和popToRootEnabled
45
+ * - titleTapped: cview => void 点击标题时执行,需要使用title
46
+ *
47
+ * methods:
48
+ *
49
+ * - hide() 隐藏布局
50
+ * - minimize() 最小化布局
51
+ * - restore() 普通布局
52
+ * - expand() 扩展布局
53
+ */
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.CustomNavigationBar = void 0;
56
+ const base_1 = require("./base");
57
+ const single_views_1 = require("./single-views");
58
+ const symbol_button_1 = require("./symbol-button");
59
+ const uitools_1 = require("../utils/uitools");
60
+ const navBarStyles = {
61
+ hidden: 0,
62
+ minimized: 1,
63
+ normal: 2,
64
+ expanded: 3
65
+ };
66
+ const navBarLayouts = [
67
+ (make, view) => {
68
+ make.left.right.top.inset(0);
69
+ make.height.equalTo(0);
70
+ },
71
+ (make, view) => {
72
+ make.left.right.top.inset(0);
73
+ make.bottom.equalTo(view.super.safeAreaTop).inset(-25);
74
+ },
75
+ (make, view) => {
76
+ make.left.right.top.inset(0);
77
+ make.bottom.equalTo(view.super.safeAreaTop).inset(-50);
78
+ },
79
+ (make, view) => {
80
+ make.left.right.top.inset(0);
81
+ make.bottom.equalTo(view.super.safeAreaTop).inset(-100);
82
+ }
83
+ ];
84
+ class CustomNavigationBar extends base_1.Base {
85
+ constructor({ props = {}, events = {} } = {}) {
86
+ super();
87
+ this._props = Object.assign({ leftBarButtonItems: [], rightBarButtonItems: [], style: navBarStyles.normal, tintColor: $color("primaryText") }, props);
88
+ this._events = events;
89
+ this.cviews = {};
90
+ this._defineView = () => {
91
+ /*
92
+ 设计思路
93
+ 一共5个子视图:
94
+ - contentView 下有3个子视图
95
+ - leftItemView popButton或者leftButtonItems
96
+ - rightItemView rightButtonItems
97
+ - titleView
98
+ - toolView
99
+ */
100
+ // leftItemView
101
+ let leftInset = 0;
102
+ if (this._props.popButtonEnabled) {
103
+ const titleWidth = this._props.popButtonTitle
104
+ ? (0, uitools_1.getTextWidth)(this._props.popButtonTitle)
105
+ : 0;
106
+ leftInset = titleWidth + 35;
107
+ const views = [];
108
+ const chevronOptions = {
109
+ type: "view",
110
+ props: {},
111
+ layout: (make) => {
112
+ make.left.top.bottom.inset(0);
113
+ make.width.equalTo(35);
114
+ },
115
+ views: [
116
+ {
117
+ type: "image",
118
+ props: {
119
+ symbol: "chevron.left",
120
+ contentMode: 1,
121
+ tintColor: this._props.tintColor
122
+ },
123
+ layout: (make) => make.edges.insets($insets(12.5, 10, 12.5, 0))
124
+ }
125
+ ]
126
+ };
127
+ views.push(chevronOptions);
128
+ if (this._props.popButtonTitle) {
129
+ const popButtonTitleOptions = {
130
+ type: "label",
131
+ props: {
132
+ align: $align.left,
133
+ text: this._props.popButtonTitle,
134
+ font: $font(17),
135
+ textColor: this._props.tintColor
136
+ },
137
+ layout: (make, view) => {
138
+ make.top.bottom.right.inset(0);
139
+ make.left.equalTo(view.prev.right);
140
+ }
141
+ };
142
+ views.push(popButtonTitleOptions);
143
+ }
144
+ this.cviews.leftItemView = new single_views_1.Button({
145
+ props: {
146
+ bgcolor: $color("clear"),
147
+ cornerRadius: 0
148
+ },
149
+ views,
150
+ layout: (make, view) => {
151
+ make.width.equalTo(leftInset);
152
+ make.left.top.bottom.inset(0);
153
+ },
154
+ events: {
155
+ tapped: sender => {
156
+ if (this._events.popHandler)
157
+ this._events.popHandler(this);
158
+ $ui.pop();
159
+ },
160
+ longPressed: this._props.popToRootEnabled
161
+ ? sender => {
162
+ if (this._events.popToRootHandler)
163
+ this._events.popToRootHandler(this);
164
+ $ui.popToRoot();
165
+ }
166
+ : undefined
167
+ }
168
+ });
169
+ }
170
+ else {
171
+ leftInset = this._calculateItemViewWidth(this._props.leftBarButtonItems);
172
+ this.cviews.leftItemView = new single_views_1.ContentView({
173
+ props: {
174
+ bgcolor: undefined
175
+ },
176
+ layout: (make, view) => {
177
+ make.width.equalTo(leftInset);
178
+ make.left.top.bottom.inset(0);
179
+ },
180
+ views: this._createCviewsOnItemView(this._props.leftBarButtonItems).map(n => n.definition)
181
+ });
182
+ }
183
+ // rightItemView
184
+ const rightInset = this._calculateItemViewWidth(this._props.rightBarButtonItems);
185
+ this.cviews.rightItemView = new single_views_1.ContentView({
186
+ props: {
187
+ bgcolor: undefined
188
+ },
189
+ layout: (make, view) => {
190
+ make.width.equalTo(rightInset);
191
+ make.right.top.bottom.inset(0);
192
+ },
193
+ views: this._createCviewsOnItemView(this._props.rightBarButtonItems).map(n => n.definition)
194
+ });
195
+ // titleView
196
+ const titleViewInset = Math.max(leftInset, rightInset);
197
+ if (this._props.title) {
198
+ this.cviews.titleViewWrapper = new single_views_1.Label({
199
+ props: {
200
+ text: this._props.title,
201
+ font: $font("bold", 17),
202
+ align: $align.center,
203
+ textColor: this._props.tintColor,
204
+ userInteractionEnabled: true
205
+ },
206
+ layout: (make, view) => {
207
+ make.left.right.inset(titleViewInset);
208
+ make.top.bottom.inset(0);
209
+ },
210
+ events: {
211
+ tapped: sender => {
212
+ if (this._events.titleTapped)
213
+ this._events.titleTapped(this);
214
+ }
215
+ }
216
+ });
217
+ }
218
+ else {
219
+ this.cviews.titleViewWrapper = new single_views_1.ContentView({
220
+ props: {
221
+ bgcolor: undefined
222
+ },
223
+ layout: (make, view) => {
224
+ make.left.right.inset(titleViewInset);
225
+ make.top.bottom.inset(0);
226
+ },
227
+ views: this._props.titleView && [this._props.titleView.definition]
228
+ });
229
+ }
230
+ // contentView
231
+ this.cviews.contentView = new single_views_1.ContentView({
232
+ props: {
233
+ bgcolor: undefined
234
+ },
235
+ layout: (make, view) => {
236
+ make.top.inset(0);
237
+ make.left.right.inset(5);
238
+ make.height.equalTo(50);
239
+ },
240
+ views: [
241
+ this.cviews.titleViewWrapper.definition,
242
+ this.cviews.leftItemView.definition,
243
+ this.cviews.rightItemView.definition
244
+ ]
245
+ });
246
+ // toolView
247
+ this.cviews.toolViewWrapper = new single_views_1.ContentView({
248
+ props: {
249
+ bgcolor: undefined
250
+ },
251
+ layout: (make, view) => {
252
+ make.left.right.bottom.equalTo(view.super);
253
+ make.top.equalTo(view.super).inset(50);
254
+ },
255
+ views: this._props.toolView && [this._props.toolView.definition]
256
+ });
257
+ return {
258
+ type: this._props.bgcolor ? "view" : "blur",
259
+ props: {
260
+ id: this.id,
261
+ style: this._props.bgcolor ? undefined : 10,
262
+ bgcolor: this._props.bgcolor
263
+ },
264
+ layout: navBarLayouts[this._props.style],
265
+ events: {
266
+ ready: () => (this.style = this.style)
267
+ },
268
+ views: [
269
+ {
270
+ type: "view",
271
+ props: {},
272
+ layout: $layout.fillSafeArea,
273
+ views: [
274
+ this.cviews.contentView.definition,
275
+ this.cviews.toolViewWrapper.definition
276
+ ]
277
+ },
278
+ {
279
+ type: "view",
280
+ props: {
281
+ bgcolor: $color("separatorColor")
282
+ },
283
+ layout: (make, view) => {
284
+ make.bottom.left.right.inset(0);
285
+ make.height.equalTo(0.5);
286
+ }
287
+ }
288
+ ]
289
+ };
290
+ };
291
+ }
292
+ _calculateItemViewWidth(items) {
293
+ if (!items || items.length === 0)
294
+ return 0;
295
+ let width = 0;
296
+ items.forEach(n => {
297
+ if (n.cview)
298
+ width += n.width || 50;
299
+ else if (n.title)
300
+ width += (0, uitools_1.getTextWidth)(n.title, { inset: 20 });
301
+ else
302
+ width += 50;
303
+ });
304
+ return width;
305
+ }
306
+ _createCviewsOnItemView(items) {
307
+ return items.map(n => {
308
+ if (n.cview) {
309
+ const width = n.width || 50;
310
+ n.cview._layout = (make, view) => {
311
+ make.top.bottom.inset(0);
312
+ make.width.equalTo(width);
313
+ make.left.equalTo((view.prev && view.prev.right) || 0);
314
+ };
315
+ return n.cview;
316
+ }
317
+ else if (n.title) {
318
+ const width = (0, uitools_1.getTextWidth)(n.title, { inset: 20 });
319
+ return new single_views_1.Button({
320
+ props: {
321
+ title: n.title,
322
+ bgcolor: $color("clear"),
323
+ titleColor: n.tintColor || this._props.tintColor,
324
+ cornerRadius: 0
325
+ },
326
+ layout: (make, view) => {
327
+ make.top.bottom.inset(0);
328
+ make.width.equalTo(width);
329
+ make.left.equalTo((view.prev && view.prev.right) || 0);
330
+ },
331
+ events: {
332
+ tapped: n.handler
333
+ }
334
+ });
335
+ }
336
+ else if (n.symbol || n.image) {
337
+ return new symbol_button_1.SymbolButton({
338
+ props: {
339
+ symbol: n.symbol,
340
+ image: n.image,
341
+ tintColor: n.tintColor || this._props.tintColor
342
+ },
343
+ layout: (make, view) => {
344
+ make.top.bottom.inset(0);
345
+ make.width.equalTo(50);
346
+ make.left.equalTo((view.prev && view.prev.right) || 0);
347
+ },
348
+ events: {
349
+ tapped: n.handler
350
+ }
351
+ });
352
+ }
353
+ else {
354
+ throw Error("Invalid BarButtonItem");
355
+ }
356
+ });
357
+ }
358
+ get title() {
359
+ return this._props.title || "";
360
+ }
361
+ set title(title) {
362
+ if (this._props.title === undefined)
363
+ return;
364
+ this._props.title = title;
365
+ if ("text" in this.cviews.titleViewWrapper.view)
366
+ this.cviews.titleViewWrapper.view.text = title;
367
+ }
368
+ hide(animated = true) {
369
+ this.view.hidden = false;
370
+ this.cviews.leftItemView.view.hidden = true;
371
+ this.cviews.rightItemView.view.hidden = true;
372
+ this.cviews.toolViewWrapper.view.hidden = true;
373
+ this.cviews.titleViewWrapper.view.hidden = true;
374
+ this.view.remakeLayout(navBarLayouts[navBarStyles.hidden]);
375
+ this.cviews.contentView.view.updateLayout(make => make.height.equalTo(0));
376
+ if (animated) {
377
+ $ui.animate({
378
+ duration: 0.3,
379
+ animation: () => {
380
+ this.view.relayout();
381
+ this.cviews.contentView.view.relayout();
382
+ },
383
+ completion: () => {
384
+ this.view.hidden = true;
385
+ if (this._events.hidden)
386
+ this._events.hidden(this);
387
+ }
388
+ });
389
+ }
390
+ else {
391
+ this.view.hidden = true;
392
+ if (this._events.hidden)
393
+ this._events.hidden(this);
394
+ }
395
+ }
396
+ minimize(animated = true) {
397
+ this.view.hidden = false;
398
+ this.cviews.leftItemView.view.hidden = true;
399
+ this.cviews.rightItemView.view.hidden = true;
400
+ this.cviews.toolViewWrapper.view.hidden = true;
401
+ this.cviews.titleViewWrapper.view.hidden = false;
402
+ this.view.remakeLayout(navBarLayouts[navBarStyles.minimized]);
403
+ this.cviews.contentView.view.updateLayout(make => make.height.equalTo(25));
404
+ if (animated) {
405
+ $ui.animate({
406
+ duration: 0.3,
407
+ animation: () => {
408
+ this.view.relayout();
409
+ this.cviews.contentView.view.relayout();
410
+ if (this._props.title && "font" in this.cviews.titleViewWrapper.view)
411
+ this.cviews.titleViewWrapper.view.font = $font("bold", 14);
412
+ },
413
+ completion: () => {
414
+ if (this._events.minimized)
415
+ this._events.minimized(this);
416
+ }
417
+ });
418
+ }
419
+ else {
420
+ if (this._props.title && "font" in this.cviews.titleViewWrapper.view)
421
+ this.cviews.titleViewWrapper.view.font = $font("bold", 14);
422
+ if (this._events.minimized)
423
+ this._events.minimized(this);
424
+ }
425
+ }
426
+ restore(animated = true) {
427
+ this.view.hidden = false;
428
+ this.cviews.titleViewWrapper.view.hidden = false;
429
+ //this.cviews.toolViewWrapper.view.hidden = true;
430
+ this.view.remakeLayout(navBarLayouts[navBarStyles.normal]);
431
+ this.cviews.contentView.view.updateLayout(make => make.height.equalTo(50));
432
+ if (animated) {
433
+ $ui.animate({
434
+ duration: 0.3,
435
+ animation: () => {
436
+ this.view.relayout();
437
+ this.cviews.contentView.view.relayout();
438
+ if (this._props.title && "font" in this.cviews.titleViewWrapper.view)
439
+ this.cviews.titleViewWrapper.view.font = $font("bold", 17);
440
+ },
441
+ completion: () => {
442
+ this.cviews.leftItemView.view.hidden = false;
443
+ this.cviews.rightItemView.view.hidden = false;
444
+ if (this._events.restored)
445
+ this._events.restored(this);
446
+ }
447
+ });
448
+ }
449
+ else {
450
+ this.cviews.leftItemView.view.hidden = false;
451
+ this.cviews.rightItemView.view.hidden = false;
452
+ if (this._props.title && "font" in this.cviews.titleViewWrapper.view)
453
+ this.cviews.titleViewWrapper.view.font = $font("bold", 17);
454
+ if (this._events.restored)
455
+ this._events.restored(this);
456
+ }
457
+ }
458
+ expand(animated = true) {
459
+ this.view.hidden = false;
460
+ this.cviews.toolViewWrapper.view.hidden = false;
461
+ this.cviews.titleViewWrapper.view.hidden = false;
462
+ this.view.remakeLayout(navBarLayouts[navBarStyles.expanded]);
463
+ this.cviews.contentView.view.updateLayout(make => make.height.equalTo(50));
464
+ if (animated) {
465
+ $ui.animate({
466
+ duration: 0.3,
467
+ animation: () => {
468
+ this.view.relayout();
469
+ this.cviews.contentView.view.relayout();
470
+ if (this._props.title && "font" in this.cviews.titleViewWrapper.view)
471
+ this.cviews.titleViewWrapper.view.font = $font("bold", 17);
472
+ },
473
+ completion: () => {
474
+ this.cviews.leftItemView.view.hidden = false;
475
+ this.cviews.rightItemView.view.hidden = false;
476
+ //this.cviews.toolViewWrapper.view.hidden = false;
477
+ if (this._events.expanded)
478
+ this._events.expanded(this);
479
+ }
480
+ });
481
+ }
482
+ else {
483
+ this.cviews.leftItemView.view.hidden = false;
484
+ this.cviews.rightItemView.view.hidden = false;
485
+ //this.cviews.toolViewWrapper.view.hidden = false;
486
+ if (this._props.title && "font" in this.cviews.titleViewWrapper.view)
487
+ this.cviews.titleViewWrapper.view.font = $font("bold", 17);
488
+ if (this._events.expanded)
489
+ this._events.expanded(this);
490
+ }
491
+ }
492
+ get style() {
493
+ return this._props.style;
494
+ }
495
+ set style(num) {
496
+ this._props.style = num;
497
+ switch (num) {
498
+ case 0: {
499
+ this.hide();
500
+ break;
501
+ }
502
+ case 1: {
503
+ this.minimize();
504
+ break;
505
+ }
506
+ case 2: {
507
+ this.restore();
508
+ break;
509
+ }
510
+ case 3: {
511
+ this.expand();
512
+ break;
513
+ }
514
+ default:
515
+ break;
516
+ }
517
+ }
518
+ }
519
+ exports.CustomNavigationBar = CustomNavigationBar;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * # cview DialogSheet
4
+ *
5
+ * dialog所需要的sheet
6
+ *
7
+ * ## 参数
8
+ * - `title` 标题
9
+ * - `cview` CView
10
+ * - `doneHandler` 完成时的回调
11
+ * - `presentMode` presentMode
12
+ * - `bgcolor` 背景颜色
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DialogSheet = void 0;
16
+ const sheet_1 = require("../sheet");
17
+ const custom_navigation_bar_1 = require("../custom-navigation-bar");
18
+ const l10n_1 = require("../../utils/l10n");
19
+ const single_views_1 = require("../single-views");
20
+ class DialogSheet extends sheet_1.Sheet {
21
+ constructor(props) {
22
+ super({
23
+ presentMode: props.presentMode || ($device.isIpad ? 2 : 1),
24
+ bgcolor: props.bgcolor
25
+ });
26
+ this._props = props;
27
+ this._done = false;
28
+ }
29
+ promisify(resolve, reject) {
30
+ this.resolve = resolve;
31
+ this.reject = reject;
32
+ }
33
+ present() {
34
+ this._dismissalHandler = () => {
35
+ if (!this._done && this.reject)
36
+ this.reject("cancel");
37
+ };
38
+ const _navbar = new custom_navigation_bar_1.CustomNavigationBar({
39
+ props: {
40
+ title: this._props.title,
41
+ leftBarButtonItems: [
42
+ { symbol: "xmark", handler: () => this.dismiss() }
43
+ ],
44
+ rightBarButtonItems: [
45
+ { title: (0, l10n_1.l10n)("DONE"), handler: () => this.done() }
46
+ ]
47
+ }
48
+ });
49
+ this._props.cview._layout = (make, view) => {
50
+ make.bottom.equalTo(view.super);
51
+ make.left.right.equalTo(view.super.safeArea);
52
+ make.top.equalTo(view.prev.bottom);
53
+ };
54
+ this._cview = new single_views_1.ContentView({
55
+ props: { bgcolor: $color("clear") },
56
+ views: [_navbar.definition, this._props.cview.definition]
57
+ });
58
+ super.present();
59
+ }
60
+ done() {
61
+ this._done = true;
62
+ if (this.resolve && this._props.doneHandler)
63
+ this.resolve(this._props.doneHandler());
64
+ this.dismiss();
65
+ }
66
+ }
67
+ exports.DialogSheet = DialogSheet;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * # CView Form Dialog
4
+ *
5
+ * 显示一个表单
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.formDialog = void 0;
9
+ const static_preference_listview_1 = require("../static-preference-listview");
10
+ const dialog_sheet_1 = require("./dialog-sheet");
11
+ function formDialog({ sections, title }) {
12
+ const view = new static_preference_listview_1.PreferenceListView({ sections });
13
+ const sheet = new dialog_sheet_1.DialogSheet({
14
+ title,
15
+ bgcolor: $color("insetGroupedBackground"),
16
+ cview: view,
17
+ doneHandler: () => view.values
18
+ });
19
+ return new Promise((resolve, reject) => {
20
+ sheet.promisify(resolve, reject);
21
+ sheet.present();
22
+ });
23
+ }
24
+ exports.formDialog = formDialog;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * # CView List Dialog
4
+ *
5
+ * 显示一个列表以供选择
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.listDialog = void 0;
9
+ const dialog_sheet_1 = require("./dialog-sheet");
10
+ const single_views_1 = require("../single-views");
11
+ function listDialog({ items, multiSelectEnabled, value, values = [], title }) {
12
+ if (value)
13
+ values = [value];
14
+ const listView = new single_views_1.List({
15
+ props: {
16
+ style: 2,
17
+ data: items.map((n, i) => {
18
+ return {
19
+ label: { text: n },
20
+ image: { hidden: !values.includes(i) }
21
+ };
22
+ }),
23
+ template: {
24
+ views: [
25
+ {
26
+ type: "label",
27
+ props: {
28
+ id: "label"
29
+ },
30
+ layout: (make, view) => {
31
+ make.top.bottom.inset(0);
32
+ make.left.inset(20);
33
+ make.right.inset(50);
34
+ }
35
+ },
36
+ {
37
+ type: "image",
38
+ props: {
39
+ id: "image",
40
+ symbol: "checkmark",
41
+ contentMode: 1,
42
+ tintColor: $color("systemLink")
43
+ },
44
+ layout: (make, view) => {
45
+ make.top.bottom.right.inset(10);
46
+ make.width.equalTo(30);
47
+ }
48
+ }
49
+ ]
50
+ }
51
+ },
52
+ events: {
53
+ didSelect: (sender, indexPath) => {
54
+ const data = sender.data;
55
+ if (multiSelectEnabled) {
56
+ data[indexPath.item].image.hidden = !data[indexPath.item].image
57
+ .hidden;
58
+ }
59
+ else {
60
+ data.forEach((n, i) => {
61
+ n.image.hidden = i !== indexPath.item;
62
+ });
63
+ }
64
+ sender.data = data;
65
+ }
66
+ }
67
+ });
68
+ const sheet = new dialog_sheet_1.DialogSheet({
69
+ title,
70
+ bgcolor: $color("insetGroupedBackground"),
71
+ cview: listView,
72
+ doneHandler: () => {
73
+ const filtered = listView.view.data
74
+ .map((n, i) => (n.image.hidden ? -1 : i))
75
+ .filter(n => n !== -1);
76
+ if (multiSelectEnabled)
77
+ return filtered;
78
+ else
79
+ return filtered[0];
80
+ }
81
+ });
82
+ return new Promise((resolve, reject) => {
83
+ sheet.promisify(resolve, reject);
84
+ sheet.present();
85
+ });
86
+ }
87
+ exports.listDialog = listDialog;