UNPKG

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