jsbox-cview 1.5.18 → 1.5.20

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.
@@ -1,19 +1,51 @@
1
+ import { Base } from "../base";
1
2
  import { PreferenceListView, PreferenceSection } from "../static-preference-listview";
2
3
  import { DialogSheet } from "./dialog-sheet";
3
4
 
5
+ class DialogSheetForm extends DialogSheet {
6
+ private _checkHandler: (values: { [key: string]: any }) => boolean;
7
+ constructor(sheetProps: {
8
+ title: string;
9
+ cview: Base<any, any>;
10
+ doneHandler?: () => void;
11
+ presentMode?: number;
12
+ bgcolor?: UIColor;
13
+ doneButtonHidden?: boolean;
14
+ }, checkHandler: (values: { [key: string]: any }) => boolean) {
15
+ super(sheetProps);
16
+ this._checkHandler = checkHandler;
17
+ }
18
+
19
+ done() {
20
+ this._done = true;
21
+ if (this.resolve && this._props.doneHandler) {
22
+ const values = this._props.doneHandler();
23
+ const success = this._checkHandler(values);
24
+ if (success) {
25
+ this.resolve(values);
26
+ this.dismiss();
27
+ }
28
+ }
29
+ }
30
+ }
31
+
4
32
  /**
5
33
  * 显示一个表单
6
34
  * @param sections 表单分组, 请参考`PreferenceListView`中的`PreferenceSection`
7
35
  * @param title 标题
8
36
  */
9
- export function formDialog({ sections, title }: { sections: PreferenceSection[]; title: string }): Promise<{ [key: string]: any }> {
37
+ export function formDialog({ sections, title, checkHandler }: {
38
+ sections: PreferenceSection[];
39
+ title: string;
40
+ checkHandler?: (values: { [key: string]: any }) => boolean;
41
+ }): Promise<{ [key: string]: any }> {
10
42
  const view = new PreferenceListView({ sections });
11
- const sheet = new DialogSheet({
43
+ const sheet = new DialogSheetForm({
12
44
  title,
13
45
  bgcolor: $color("insetGroupedBackground"),
14
46
  cview: view,
15
47
  doneHandler: () => view.values
16
- });
48
+ }, checkHandler || (() => true));
17
49
  return new Promise((resolve, reject) => {
18
50
  sheet.promisify(resolve, reject);
19
51
  sheet.present();
@@ -26,6 +26,7 @@ export class RefreshButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
26
26
  events?: UiTypes.BaseViewEvents<UIButtonView>;
27
27
  }) {
28
28
  super();
29
+ this._layout = layout;
29
30
  this._defineView = () => {
30
31
  return {
31
32
  type: "button",
@@ -35,7 +36,7 @@ export class RefreshButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
35
36
  enabled: props?.enabled ?? true,
36
37
  hidden: props?.hidden ?? false,
37
38
  },
38
- layout,
39
+ layout: this._layout,
39
40
  events,
40
41
  views: [
41
42
  {
@@ -3,19 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formDialog = void 0;
4
4
  const static_preference_listview_1 = require("../static-preference-listview");
5
5
  const dialog_sheet_1 = require("./dialog-sheet");
6
+ class DialogSheetForm extends dialog_sheet_1.DialogSheet {
7
+ constructor(sheetProps, checkHandler) {
8
+ super(sheetProps);
9
+ this._checkHandler = checkHandler;
10
+ }
11
+ done() {
12
+ this._done = true;
13
+ if (this.resolve && this._props.doneHandler) {
14
+ const values = this._props.doneHandler();
15
+ const success = this._checkHandler(values);
16
+ if (success) {
17
+ this.resolve(values);
18
+ this.dismiss();
19
+ }
20
+ }
21
+ }
22
+ }
6
23
  /**
7
24
  * 显示一个表单
8
25
  * @param sections 表单分组, 请参考`PreferenceListView`中的`PreferenceSection`
9
26
  * @param title 标题
10
27
  */
11
- function formDialog({ sections, title }) {
28
+ function formDialog({ sections, title, checkHandler }) {
12
29
  const view = new static_preference_listview_1.PreferenceListView({ sections });
13
- const sheet = new dialog_sheet_1.DialogSheet({
30
+ const sheet = new DialogSheetForm({
14
31
  title,
15
32
  bgcolor: $color("insetGroupedBackground"),
16
33
  cview: view,
17
34
  doneHandler: () => view.values
18
- });
35
+ }, checkHandler || (() => true));
19
36
  return new Promise((resolve, reject) => {
20
37
  sheet.promisify(resolve, reject);
21
38
  sheet.present();
@@ -15,6 +15,7 @@ class RefreshButton extends base_1.Base {
15
15
  constructor({ props, layout, events = {} }) {
16
16
  super();
17
17
  this._loading = false;
18
+ this._layout = layout;
18
19
  this._defineView = () => {
19
20
  var _a, _b, _c;
20
21
  return {
@@ -25,7 +26,7 @@ class RefreshButton extends base_1.Base {
25
26
  enabled: (_a = props === null || props === void 0 ? void 0 : props.enabled) !== null && _a !== void 0 ? _a : true,
26
27
  hidden: (_b = props === null || props === void 0 ? void 0 : props.hidden) !== null && _b !== void 0 ? _b : false,
27
28
  },
28
- layout,
29
+ layout: this._layout,
29
30
  events,
30
31
  views: [
31
32
  {
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const form_dialog_1 = require("../components/dialogs/form-dialog");
13
+ $ui.render({
14
+ views: [{
15
+ type: "button",
16
+ props: {
17
+ title: "Show Form Dialog"
18
+ },
19
+ layout: $layout.center,
20
+ events: {
21
+ tapped: () => __awaiter(void 0, void 0, void 0, function* () {
22
+ const values = yield (0, form_dialog_1.formDialog)({
23
+ sections: [
24
+ {
25
+ title: "Section 1",
26
+ rows: [
27
+ {
28
+ type: "boolean",
29
+ title: "Switch",
30
+ key: "switch",
31
+ value: true
32
+ },
33
+ {
34
+ type: "string",
35
+ title: "String",
36
+ key: "string",
37
+ value: "Hello, World!"
38
+ }
39
+ ]
40
+ }
41
+ ],
42
+ title: "Form Dialog",
43
+ checkHandler: values => {
44
+ console.log(values);
45
+ if (values.switch)
46
+ return true;
47
+ else
48
+ return false;
49
+ }
50
+ });
51
+ $ui.alert({
52
+ title: "Values",
53
+ message: JSON.stringify(values, null, 2)
54
+ });
55
+ })
56
+ }
57
+ }]
58
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsbox-cview",
3
- "version": "1.5.18",
3
+ "version": "1.5.20",
4
4
  "description": "为 JSBox 设计的微型框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,47 @@
1
+ import { formDialog } from "../components/dialogs/form-dialog";
2
+
3
+ $ui.render({
4
+ views: [{
5
+ type: "button",
6
+ props: {
7
+ title: "Show Form Dialog"
8
+ },
9
+ layout: $layout.center,
10
+ events: {
11
+ tapped: async () => {
12
+ const values = await formDialog({
13
+ sections: [
14
+ {
15
+ title: "Section 1",
16
+ rows: [
17
+ {
18
+ type: "boolean",
19
+ title: "Switch",
20
+ key: "switch",
21
+ value: true
22
+ },
23
+ {
24
+ type: "string",
25
+ title: "String",
26
+ key: "string",
27
+ value: "Hello, World!"
28
+ }
29
+ ]
30
+ }
31
+ ],
32
+ title: "Form Dialog",
33
+ checkHandler: values => {
34
+ console.log(values);
35
+ if (values.switch) return true;
36
+ else return false;
37
+ }
38
+ });
39
+ $ui.alert({
40
+ title: "Values",
41
+ message: JSON.stringify(values, null, 2)
42
+ });
43
+ }
44
+ }
45
+ }]
46
+ })
47
+