UNPKG

4.41 kBJavaScriptView Raw
1import { Frame } from '../frame';
2import { CSSUtils } from '../../css/system-classes';
3import { isObject, isString } from '../../utils/types';
4const CSS_CLASS = `${CSSUtils.CLASS_PREFIX}dialog-item`;
5export 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 * Defines the input type for prompt dialog.
17 */
18export var inputType;
19(function (inputType) {
20 /**
21 * Plain text input type.
22 */
23 inputType.text = 'text';
24 /**
25 * Password input type.
26 */
27 inputType.password = 'password';
28 /**
29 * Email input type.
30 */
31 inputType.email = 'email';
32 /**
33 * Number input type
34 */
35 inputType.number = 'number';
36 /**
37 * Decimal input type
38 */
39 inputType.decimal = 'decimal';
40 /**
41 * Phone input type
42 */
43 inputType.phone = 'phone';
44})(inputType || (inputType = {}));
45/**
46 * Defines the capitalization type for prompt dialog.
47 */
48export var capitalizationType;
49(function (capitalizationType) {
50 /**
51 * No automatic capitalization.
52 */
53 capitalizationType.none = 'none';
54 /**
55 * Capitalizes every character.
56 */
57 capitalizationType.all = 'all';
58 /**
59 * Capitalize the first word of each sentence.
60 */
61 capitalizationType.sentences = 'sentences';
62 /**
63 * Capitalize the first letter of every word.
64 */
65 capitalizationType.words = 'words';
66})(capitalizationType || (capitalizationType = {}));
67export function getCurrentPage() {
68 const topmostFrame = Frame.topmost();
69 if (topmostFrame) {
70 return topmostFrame.currentPage;
71 }
72 return undefined;
73}
74function 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}
87let button;
88let label;
89let textField;
90export 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}
107export 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}
122export 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}
137export function isDialogOptions(arg) {
138 return arg && (arg.message || arg.title);
139}
140export function parseLoginOptions(args) {
141 // Handle options object first
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//# sourceMappingURL=dialogs-common.js.map
\No newline at end of file