1 | import { Frame } from '../frame';
|
2 | import { isObject, isString } from '../../utils/types';
|
3 | export var DialogStrings;
|
4 | (function (DialogStrings) {
|
5 | DialogStrings.STRING = 'string';
|
6 | DialogStrings.PROMPT = 'Prompt';
|
7 | DialogStrings.CONFIRM = 'Confirm';
|
8 | DialogStrings.ALERT = 'Alert';
|
9 | DialogStrings.LOGIN = 'Login';
|
10 | DialogStrings.OK = 'OK';
|
11 | DialogStrings.CANCEL = 'Cancel';
|
12 | })(DialogStrings || (DialogStrings = {}));
|
13 |
|
14 |
|
15 |
|
16 | export var inputType;
|
17 | (function (inputType) {
|
18 | |
19 |
|
20 |
|
21 | inputType.text = 'text';
|
22 | |
23 |
|
24 |
|
25 | inputType.password = 'password';
|
26 | |
27 |
|
28 |
|
29 | inputType.email = 'email';
|
30 | |
31 |
|
32 |
|
33 | inputType.number = 'number';
|
34 | |
35 |
|
36 |
|
37 | inputType.decimal = 'decimal';
|
38 | |
39 |
|
40 |
|
41 | inputType.phone = 'phone';
|
42 | })(inputType || (inputType = {}));
|
43 |
|
44 |
|
45 |
|
46 | export var capitalizationType;
|
47 | (function (capitalizationType) {
|
48 | |
49 |
|
50 |
|
51 | capitalizationType.none = 'none';
|
52 | |
53 |
|
54 |
|
55 | capitalizationType.all = 'all';
|
56 | |
57 |
|
58 |
|
59 | capitalizationType.sentences = 'sentences';
|
60 | |
61 |
|
62 |
|
63 | capitalizationType.words = 'words';
|
64 | })(capitalizationType || (capitalizationType = {}));
|
65 | export function getCurrentPage() {
|
66 | const topmostFrame = Frame.topmost();
|
67 | if (topmostFrame) {
|
68 | return topmostFrame.currentPage;
|
69 | }
|
70 | return undefined;
|
71 | }
|
72 | function applySelectors(view, callback) {
|
73 | const currentPage = getCurrentPage();
|
74 | if (currentPage) {
|
75 | const styleScope = currentPage._styleScope;
|
76 | if (styleScope) {
|
77 | view.parent = currentPage;
|
78 | view._inheritStyleScope(styleScope);
|
79 | view.onLoaded();
|
80 | callback(view);
|
81 | view.onUnloaded();
|
82 | }
|
83 | }
|
84 | }
|
85 | let button;
|
86 | let label;
|
87 | let textField;
|
88 | export function getButtonColors() {
|
89 | if (!button) {
|
90 | const Button = require('../button').Button;
|
91 | button = new Button();
|
92 | if (__APPLE__) {
|
93 | button._setupUI({});
|
94 | }
|
95 | }
|
96 | let buttonColor;
|
97 | let buttonBackgroundColor;
|
98 | applySelectors(button, (btn) => {
|
99 | buttonColor = btn.color;
|
100 | buttonBackgroundColor = btn.backgroundColor;
|
101 | });
|
102 | return { color: buttonColor, backgroundColor: buttonBackgroundColor };
|
103 | }
|
104 | export function getLabelColor() {
|
105 | if (!label) {
|
106 | const Label = require('../label').Label;
|
107 | label = new Label();
|
108 | if (__APPLE__) {
|
109 | label._setupUI({});
|
110 | }
|
111 | }
|
112 | let labelColor;
|
113 | applySelectors(label, (lbl) => {
|
114 | labelColor = lbl.color;
|
115 | });
|
116 | return labelColor;
|
117 | }
|
118 | export function getTextFieldColor() {
|
119 | if (!textField) {
|
120 | const TextField = require('../text-field').TextField;
|
121 | textField = new TextField();
|
122 | if (__APPLE__) {
|
123 | textField._setupUI({});
|
124 | }
|
125 | }
|
126 | let textFieldColor;
|
127 | applySelectors(textField, (tf) => {
|
128 | textFieldColor = tf.color;
|
129 | });
|
130 | return textFieldColor;
|
131 | }
|
132 | export function isDialogOptions(arg) {
|
133 | return arg && (arg.message || arg.title);
|
134 | }
|
135 | export function parseLoginOptions(args) {
|
136 |
|
137 | if (args.length === 1 && isObject(args[0])) {
|
138 | return args[0];
|
139 | }
|
140 | const options = {
|
141 | title: DialogStrings.LOGIN,
|
142 | okButtonText: DialogStrings.OK,
|
143 | cancelButtonText: DialogStrings.CANCEL,
|
144 | };
|
145 | if (isString(args[0])) {
|
146 | options.message = args[0];
|
147 | }
|
148 | if (isString(args[1])) {
|
149 | options.userNameHint = args[1];
|
150 | }
|
151 | if (isString(args[2])) {
|
152 | options.passwordHint = args[2];
|
153 | }
|
154 | if (isString(args[3])) {
|
155 | options.userName = args[3];
|
156 | }
|
157 | if (isString(args[4])) {
|
158 | options.password = args[4];
|
159 | }
|
160 | return options;
|
161 | }
|
162 |
|
\ | No newline at end of file |