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