@openremote/or-mwc-components 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120000
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.
- package/README.md +32 -32
- package/build.gradle +19 -19
- package/custom-elements.json +4 -4
- package/lib/or-mwc-dialog.js +329 -76
- package/lib/or-mwc-drawer.js +114 -10
- package/lib/or-mwc-input.js +1760 -439
- package/lib/or-mwc-list.js +283 -71
- package/lib/or-mwc-menu.js +237 -45
- package/lib/or-mwc-snackbar.d.ts +1 -1
- package/lib/or-mwc-snackbar.js +141 -17
- package/lib/or-mwc-table.js +685 -245
- package/lib/or-mwc-tabs.js +173 -53
- package/lib/style.js +125 -121
- package/package.json +5 -5
- package/rspack.config.js +7 -7
- package/src/or-mwc-dialog.ts +374 -374
- package/src/or-mwc-drawer.ts +100 -100
- package/src/or-mwc-input.ts +1876 -1876
- package/src/or-mwc-list.ts +335 -335
- package/src/or-mwc-menu.ts +279 -279
- package/src/or-mwc-snackbar.ts +157 -157
- package/src/or-mwc-table.ts +712 -712
- package/src/or-mwc-tabs.ts +175 -175
- package/src/style.ts +125 -125
- package/tsconfig.json +15 -15
- package/tsconfig.tsbuildinfo +1 -1
package/lib/or-mwc-input.js
CHANGED
|
@@ -1,439 +1,1760 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import { css, html, LitElement, unsafeCSS } from "lit";
|
|
17
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
18
|
+
import { ref, createRef } from "lit/directives/ref.js";
|
|
19
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
20
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
21
|
+
import { when } from 'lit/directives/when.js';
|
|
22
|
+
import { until } from 'lit/directives/until.js';
|
|
23
|
+
import { MDCTextField } from "@material/textfield";
|
|
24
|
+
import { MDCRipple } from "@material/ripple";
|
|
25
|
+
import { MDCCheckbox } from "@material/checkbox";
|
|
26
|
+
import { MDCSwitch } from "@material/switch";
|
|
27
|
+
import { MDCSlider } from "@material/slider";
|
|
28
|
+
import { MDCSelect } from "@material/select";
|
|
29
|
+
import { MDCList } from "@material/list";
|
|
30
|
+
import { MDCFormField } from "@material/form-field";
|
|
31
|
+
import { MDCIconButtonToggle } from "@material/icon-button";
|
|
32
|
+
import { DefaultColor4, DefaultColor5, DefaultColor8, Util } from "@openremote/core";
|
|
33
|
+
import "@openremote/or-icon";
|
|
34
|
+
import { getItemTemplate, getListTemplate, ListType } from "./or-mwc-list";
|
|
35
|
+
import { i18next } from "@openremote/or-translate";
|
|
36
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
37
|
+
// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
|
|
38
|
+
const buttonStyle = require("@material/button/dist/mdc.button.css");
|
|
39
|
+
const buttonFabStyle = require("@material/fab/dist/mdc.fab.css");
|
|
40
|
+
const iconButtonStyle = require("@material/icon-button/dist/mdc.icon-button.css");
|
|
41
|
+
const textfieldStyle = require("@material/textfield/dist/mdc.textfield.css");
|
|
42
|
+
const rippleStyle = require("@material/ripple/dist/mdc.ripple.css");
|
|
43
|
+
const lineRippleStyle = require("@material/line-ripple/dist/mdc.line-ripple.css");
|
|
44
|
+
const floatingLabelStyle = require("@material/floating-label/dist/mdc.floating-label.css");
|
|
45
|
+
const formFieldStyle = require("@material/form-field/dist/mdc.form-field.css");
|
|
46
|
+
const checkboxStyle = require("@material/checkbox/dist/mdc.checkbox.css");
|
|
47
|
+
const radioStyle = require("@material/radio/dist/mdc.radio.css");
|
|
48
|
+
const switchStyle = require("@material/switch/dist/mdc.switch.css");
|
|
49
|
+
const selectStyle = require("@material/select/dist/mdc.select.css");
|
|
50
|
+
const listStyle = require("@material/list/dist/mdc.list.css");
|
|
51
|
+
const menuSurfaceStyle = require("@material/menu-surface/dist/mdc.menu-surface.css");
|
|
52
|
+
const menuStyle = require("@material/menu/dist/mdc.menu.css");
|
|
53
|
+
const sliderStyle = require("@material/slider/dist/mdc.slider.css");
|
|
54
|
+
export class OrInputChangedEvent extends CustomEvent {
|
|
55
|
+
constructor(value, previousValue, enterPressed) {
|
|
56
|
+
super(OrInputChangedEvent.NAME, {
|
|
57
|
+
detail: {
|
|
58
|
+
value: value,
|
|
59
|
+
previousValue: previousValue,
|
|
60
|
+
enterPressed: enterPressed
|
|
61
|
+
},
|
|
62
|
+
bubbles: true,
|
|
63
|
+
composed: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
OrInputChangedEvent.NAME = "or-mwc-input-changed";
|
|
68
|
+
export var InputType;
|
|
69
|
+
(function (InputType) {
|
|
70
|
+
InputType["BUTTON"] = "button";
|
|
71
|
+
InputType["BUTTON_TOGGLE"] = "button-toggle";
|
|
72
|
+
InputType["BUTTON_MOMENTARY"] = "button-momentary";
|
|
73
|
+
InputType["CHECKBOX"] = "checkbox";
|
|
74
|
+
InputType["CHECKBOX_LIST"] = "checkbox-list";
|
|
75
|
+
InputType["COLOUR"] = "color";
|
|
76
|
+
InputType["DATE"] = "date";
|
|
77
|
+
InputType["DATETIME"] = "datetime-local";
|
|
78
|
+
InputType["EMAIL"] = "email";
|
|
79
|
+
InputType["JSON"] = "json";
|
|
80
|
+
InputType["JSON_OBJECT"] = "json-object";
|
|
81
|
+
InputType["MONTH"] = "month";
|
|
82
|
+
InputType["NUMBER"] = "number";
|
|
83
|
+
InputType["BIG_INT"] = "big-int";
|
|
84
|
+
InputType["PASSWORD"] = "password";
|
|
85
|
+
InputType["RADIO"] = "radio";
|
|
86
|
+
InputType["SWITCH"] = "switch";
|
|
87
|
+
InputType["RANGE"] = "range";
|
|
88
|
+
InputType["TELEPHONE"] = "tel";
|
|
89
|
+
InputType["TEXT"] = "text";
|
|
90
|
+
InputType["TEXTAREA"] = "textarea";
|
|
91
|
+
InputType["TIME"] = "time";
|
|
92
|
+
InputType["URL"] = "url";
|
|
93
|
+
InputType["WEEK"] = "week";
|
|
94
|
+
InputType["SELECT"] = "select";
|
|
95
|
+
InputType["LIST"] = "list";
|
|
96
|
+
InputType["CRON"] = "cron";
|
|
97
|
+
InputType["DURATION"] = "duration";
|
|
98
|
+
InputType["DURATION_TIME"] = "duration-time";
|
|
99
|
+
InputType["DURATION_PERIOD"] = "duration-period";
|
|
100
|
+
})(InputType || (InputType = {}));
|
|
101
|
+
function inputTypeSupportsButton(inputType) {
|
|
102
|
+
return inputType === InputType.NUMBER
|
|
103
|
+
|| inputType === InputType.BIG_INT
|
|
104
|
+
|| inputType === InputType.TELEPHONE
|
|
105
|
+
|| inputType === InputType.TEXT
|
|
106
|
+
|| inputType === InputType.PASSWORD
|
|
107
|
+
|| inputType === InputType.DATE
|
|
108
|
+
|| inputType === InputType.DATETIME
|
|
109
|
+
|| inputType === InputType.EMAIL
|
|
110
|
+
|| inputType === InputType.JSON
|
|
111
|
+
|| inputType === InputType.JSON_OBJECT
|
|
112
|
+
|| inputType === InputType.MONTH
|
|
113
|
+
|| inputType === InputType.TEXTAREA
|
|
114
|
+
|| inputType === InputType.TIME
|
|
115
|
+
|| inputType === InputType.URL
|
|
116
|
+
|| inputType === InputType.WEEK;
|
|
117
|
+
}
|
|
118
|
+
function inputTypeSupportsHelperText(inputType) {
|
|
119
|
+
return inputTypeSupportsButton(inputType) || inputType === InputType.SELECT;
|
|
120
|
+
}
|
|
121
|
+
function inputTypeSupportsLabel(inputType) {
|
|
122
|
+
return inputTypeSupportsHelperText(inputType) || inputType === InputType.CHECKBOX || inputType === InputType.BUTTON_MOMENTARY;
|
|
123
|
+
}
|
|
124
|
+
export const getValueHolderInputTemplateProvider = (assetDescriptor, valueHolder, valueHolderDescriptor, valueDescriptor, valueChangeNotifier, options) => {
|
|
125
|
+
let inputType = options.inputType;
|
|
126
|
+
let step;
|
|
127
|
+
let pattern;
|
|
128
|
+
let min;
|
|
129
|
+
let max;
|
|
130
|
+
let multiple;
|
|
131
|
+
let required;
|
|
132
|
+
let selectOptions;
|
|
133
|
+
let valueConverter;
|
|
134
|
+
const styles = {};
|
|
135
|
+
const assetType = typeof assetDescriptor === "string" ? assetDescriptor : assetDescriptor.name;
|
|
136
|
+
const constraints = (valueHolder && (valueHolder.meta) || (valueDescriptor && valueDescriptor.meta) ? Util.getAttributeValueConstraints(valueHolder, valueHolderDescriptor, assetType) : Util.getMetaValueConstraints(valueHolder, valueHolderDescriptor, assetType)) || [];
|
|
137
|
+
const format = (valueHolder && (valueHolder.meta) || (valueDescriptor && valueDescriptor.meta) ? Util.getAttributeValueFormat(valueHolder, valueHolderDescriptor, assetType) : Util.getMetaValueFormat(valueHolder, valueHolderDescriptor, assetType));
|
|
138
|
+
// Determine input type
|
|
139
|
+
if (!inputType) {
|
|
140
|
+
switch (valueDescriptor.name) {
|
|
141
|
+
case "text" /* WellknownValueTypes.TEXT */:
|
|
142
|
+
case "email" /* WellknownValueTypes.EMAIL */:
|
|
143
|
+
case "UUID" /* WellknownValueTypes.UUID */:
|
|
144
|
+
case "assetID" /* WellknownValueTypes.ASSETID */:
|
|
145
|
+
case "hostOrIPAddress" /* WellknownValueTypes.HOSTORIPADDRESS */:
|
|
146
|
+
case "IPAddress" /* WellknownValueTypes.IPADDRESS */:
|
|
147
|
+
inputType = Util.getMetaValue("multiline" /* WellknownMetaItems.MULTILINE */, valueHolder, valueHolderDescriptor) === true ? InputType.TEXTAREA : InputType.TEXT;
|
|
148
|
+
break;
|
|
149
|
+
case "boolean" /* WellknownValueTypes.BOOLEAN */:
|
|
150
|
+
if (format && format.asNumber) {
|
|
151
|
+
inputType = InputType.NUMBER;
|
|
152
|
+
step = 1;
|
|
153
|
+
min = 0;
|
|
154
|
+
max = 1;
|
|
155
|
+
valueConverter = (v) => !!v;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
if (format && (format.asOnOff || format.asOpenClosed)) {
|
|
159
|
+
inputType = InputType.SWITCH;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
inputType = InputType.CHECKBOX;
|
|
163
|
+
}
|
|
164
|
+
if (format && format.asMomentary || (Util.getMetaValue("momentary" /* WellknownMetaItems.MOMENTARY */, valueHolder, valueHolderDescriptor) === true)) {
|
|
165
|
+
inputType = InputType.BUTTON_MOMENTARY;
|
|
166
|
+
}
|
|
167
|
+
break;
|
|
168
|
+
case "bigNumber" /* WellknownValueTypes.BIGNUMBER */:
|
|
169
|
+
case "number" /* WellknownValueTypes.NUMBER */:
|
|
170
|
+
case "positiveInteger" /* WellknownValueTypes.POSITIVEINTEGER */:
|
|
171
|
+
case "positiveNumber" /* WellknownValueTypes.POSITIVENUMBER */:
|
|
172
|
+
case "long" /* WellknownValueTypes.LONG */:
|
|
173
|
+
case "integer" /* WellknownValueTypes.INTEGER */:
|
|
174
|
+
case "byte" /* WellknownValueTypes.BYTE */:
|
|
175
|
+
case "integerByte" /* WellknownValueTypes.INTEGERBYTE */:
|
|
176
|
+
case "direction" /* WellknownValueTypes.DIRECTION */:
|
|
177
|
+
case "TCP_IPPortNumber" /* WellknownValueTypes.TCPIPPORTNUMBER */:
|
|
178
|
+
if (valueDescriptor.name === "byte" /* WellknownValueTypes.BYTE */ || valueDescriptor.name === "integerByte" /* WellknownValueTypes.INTEGERBYTE */) {
|
|
179
|
+
min = 0;
|
|
180
|
+
max = 255;
|
|
181
|
+
step = 1;
|
|
182
|
+
}
|
|
183
|
+
else if (valueDescriptor.name === "integer" /* WellknownValueTypes.INTEGER */ || valueDescriptor.name === "long" /* WellknownValueTypes.LONG */) {
|
|
184
|
+
step = 1;
|
|
185
|
+
}
|
|
186
|
+
if (format && format.asDate) {
|
|
187
|
+
inputType = InputType.DATETIME;
|
|
188
|
+
}
|
|
189
|
+
else if (format && format.asBoolean) {
|
|
190
|
+
inputType = InputType.CHECKBOX;
|
|
191
|
+
valueConverter = (v) => v ? 1 : 0;
|
|
192
|
+
}
|
|
193
|
+
else if (format && format.asSlider) {
|
|
194
|
+
inputType = InputType.RANGE;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
inputType = InputType.NUMBER;
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
case "bigInteger" /* WellknownValueTypes.BIGINTEGER */:
|
|
201
|
+
inputType = InputType.BIG_INT;
|
|
202
|
+
step = 1;
|
|
203
|
+
break;
|
|
204
|
+
case "colourRGB" /* WellknownValueTypes.COLOURRGB */:
|
|
205
|
+
inputType = InputType.COLOUR;
|
|
206
|
+
break;
|
|
207
|
+
case "dateAndTime" /* WellknownValueTypes.DATEANDTIME */:
|
|
208
|
+
case "timestamp" /* WellknownValueTypes.TIMESTAMP */:
|
|
209
|
+
case "timestampISO8601" /* WellknownValueTypes.TIMESTAMPISO8601 */:
|
|
210
|
+
inputType = InputType.DATETIME;
|
|
211
|
+
break;
|
|
212
|
+
case "CRONExpression" /* WellknownValueTypes.CRONEXPRESSION */:
|
|
213
|
+
inputType = InputType.CRON;
|
|
214
|
+
break;
|
|
215
|
+
case "timeDurationISO8601" /* WellknownValueTypes.TIMEDURATIONISO8601 */:
|
|
216
|
+
inputType = InputType.DURATION_TIME;
|
|
217
|
+
break;
|
|
218
|
+
case "periodDurationISO8601" /* WellknownValueTypes.PERIODDURATIONISO8601 */:
|
|
219
|
+
inputType = InputType.DURATION_PERIOD;
|
|
220
|
+
break;
|
|
221
|
+
case "timeAndPeriodDurationISO8601" /* WellknownValueTypes.TIMEANDPERIODDURATIONISO8601 */:
|
|
222
|
+
inputType = InputType.DURATION;
|
|
223
|
+
break;
|
|
224
|
+
case "JSONObject" /* WellknownValueTypes.JSONOBJECT */:
|
|
225
|
+
inputType = InputType.JSON_OBJECT;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
if (valueDescriptor.arrayDimensions && valueDescriptor.arrayDimensions > 0) {
|
|
229
|
+
inputType = InputType.JSON;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (!inputType) {
|
|
233
|
+
switch (valueDescriptor.jsonType) {
|
|
234
|
+
case "number":
|
|
235
|
+
case "bigint":
|
|
236
|
+
inputType = InputType.NUMBER;
|
|
237
|
+
break;
|
|
238
|
+
case "boolean":
|
|
239
|
+
inputType = InputType.CHECKBOX;
|
|
240
|
+
break;
|
|
241
|
+
case "string":
|
|
242
|
+
inputType = InputType.TEXT;
|
|
243
|
+
break;
|
|
244
|
+
case "date":
|
|
245
|
+
inputType = InputType.DATETIME;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (!inputType) {
|
|
250
|
+
inputType = InputType.JSON;
|
|
251
|
+
}
|
|
252
|
+
// Apply any constraints
|
|
253
|
+
const sizeConstraint = constraints && constraints.find(c => c.type === "size");
|
|
254
|
+
const patternConstraint = constraints && constraints.find(c => c.type === "pattern");
|
|
255
|
+
const minConstraint = constraints && constraints.find(c => c.type === "min");
|
|
256
|
+
const maxConstraint = constraints && constraints.find(c => c.type === "max");
|
|
257
|
+
const allowedValuesConstraint = constraints && constraints.find(c => c.type === "allowedValues");
|
|
258
|
+
const pastConstraint = constraints && constraints.find(c => c.type === "past");
|
|
259
|
+
const pastOrPresentConstraint = constraints && constraints.find(c => c.type === "pastOrPresent");
|
|
260
|
+
const futureConstraint = constraints && constraints.find(c => c.type === "future");
|
|
261
|
+
const futureOrPresentConstraint = constraints && constraints.find(c => c.type === "futureOrPresent");
|
|
262
|
+
const notEmptyConstraint = constraints && constraints.find(c => c.type === "notEmpty");
|
|
263
|
+
const notBlankConstraint = constraints && constraints.find(c => c.type === "notBlank");
|
|
264
|
+
const notNullConstraint = constraints && constraints.find(c => c.type === "notNull");
|
|
265
|
+
if (sizeConstraint) {
|
|
266
|
+
min = sizeConstraint.min;
|
|
267
|
+
max = sizeConstraint.max;
|
|
268
|
+
}
|
|
269
|
+
if (sizeConstraint) {
|
|
270
|
+
min = sizeConstraint.min;
|
|
271
|
+
max = sizeConstraint.max;
|
|
272
|
+
}
|
|
273
|
+
if (minConstraint) {
|
|
274
|
+
min = minConstraint.min;
|
|
275
|
+
}
|
|
276
|
+
if (maxConstraint) {
|
|
277
|
+
max = maxConstraint.max;
|
|
278
|
+
}
|
|
279
|
+
if (patternConstraint) {
|
|
280
|
+
pattern = patternConstraint.regexp;
|
|
281
|
+
}
|
|
282
|
+
if (notNullConstraint) {
|
|
283
|
+
required = true;
|
|
284
|
+
}
|
|
285
|
+
if (notBlankConstraint && !pattern) {
|
|
286
|
+
pattern = "\\S+";
|
|
287
|
+
}
|
|
288
|
+
else if (notEmptyConstraint && !pattern) {
|
|
289
|
+
pattern = ".+";
|
|
290
|
+
}
|
|
291
|
+
if (allowedValuesConstraint && allowedValuesConstraint.allowedValues) {
|
|
292
|
+
const allowedLabels = allowedValuesConstraint.allowedValueNames && allowedValuesConstraint.allowedValueNames.length === allowedValuesConstraint.allowedValues.length ? allowedValuesConstraint.allowedValueNames : undefined;
|
|
293
|
+
selectOptions = allowedValuesConstraint.allowedValues.map((v, i) => {
|
|
294
|
+
let label = allowedLabels ? allowedLabels[i] : "" + v;
|
|
295
|
+
label = Util.getAllowedValueLabel(label);
|
|
296
|
+
return [v, label || "" + v];
|
|
297
|
+
});
|
|
298
|
+
inputType = InputType.SELECT;
|
|
299
|
+
if (valueDescriptor.arrayDimensions && valueDescriptor.arrayDimensions > 0) {
|
|
300
|
+
multiple = true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (inputType === InputType.DATETIME) {
|
|
304
|
+
if (pastConstraint || pastOrPresentConstraint) {
|
|
305
|
+
min = undefined;
|
|
306
|
+
max = new Date();
|
|
307
|
+
}
|
|
308
|
+
else if (futureConstraint || futureOrPresentConstraint) {
|
|
309
|
+
min = new Date();
|
|
310
|
+
max = undefined;
|
|
311
|
+
}
|
|
312
|
+
// Refine the input type based on formatting
|
|
313
|
+
if (format) {
|
|
314
|
+
if (format.timeStyle && !format.dateStyle) {
|
|
315
|
+
inputType = InputType.TIME;
|
|
316
|
+
}
|
|
317
|
+
else if (format.dateStyle && !format.timeStyle) {
|
|
318
|
+
inputType = InputType.DATE;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (inputType === InputType.NUMBER && format && format.resolution) {
|
|
323
|
+
step = format.resolution;
|
|
324
|
+
}
|
|
325
|
+
if (inputType === InputType.COLOUR) {
|
|
326
|
+
styles.marginLeft = "24px";
|
|
327
|
+
}
|
|
328
|
+
const supportsHelperText = inputTypeSupportsHelperText(inputType);
|
|
329
|
+
const supportsLabel = inputTypeSupportsLabel(inputType);
|
|
330
|
+
const supportsSendButton = inputTypeSupportsButton(inputType);
|
|
331
|
+
const readonly = options.readonly;
|
|
332
|
+
required = required || options.required;
|
|
333
|
+
const comfortable = options.comfortable;
|
|
334
|
+
const resizeVertical = options.resizeVertical;
|
|
335
|
+
const inputRef = createRef();
|
|
336
|
+
const templateFunction = (value, focused, loading, sending, error, helperText) => {
|
|
337
|
+
const disabled = options.disabled || loading || sending;
|
|
338
|
+
const label = supportsLabel ? options.label : undefined;
|
|
339
|
+
return html `<or-mwc-input ${ref(inputRef)} id="input" style="${styleMap(styles)}" .type="${inputType}" .label="${label}" .value="${value}" .pattern="${pattern}"
|
|
340
|
+
.min="${min}" .max="${max}" .format="${format}" .focused="${focused}" .required="${required}" .multiple="${multiple}"
|
|
341
|
+
.options="${selectOptions}" .comfortable="${comfortable}" .readonly="${readonly}" .disabled="${disabled}" .step="${step}"
|
|
342
|
+
.helperText="${helperText}" .helperPersistent="${true}" .resizeVertical="${resizeVertical}"
|
|
343
|
+
.rounded="${options.rounded}"
|
|
344
|
+
.outlined="${options.outlined}"
|
|
345
|
+
@or-mwc-input-changed="${(e) => {
|
|
346
|
+
e.stopPropagation();
|
|
347
|
+
e.detail.value = valueConverter ? valueConverter(e.detail.value) : e.detail.value;
|
|
348
|
+
valueChangeNotifier(e.detail);
|
|
349
|
+
}}"></or-mwc-input>`;
|
|
350
|
+
};
|
|
351
|
+
return {
|
|
352
|
+
templateFunction: templateFunction,
|
|
353
|
+
supportsHelperText: supportsHelperText,
|
|
354
|
+
supportsSendButton: supportsSendButton,
|
|
355
|
+
supportsLabel: supportsLabel,
|
|
356
|
+
validator: () => {
|
|
357
|
+
if (!inputRef.value) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
return inputRef.value.checkValidity();
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
// language=CSS
|
|
365
|
+
const style = css `
|
|
366
|
+
|
|
367
|
+
:host {
|
|
368
|
+
display: inline-block;
|
|
369
|
+
--internal-or-mwc-input-color: var(--or-mwc-input-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
|
|
370
|
+
--internal-or-mwc-input-text-color: var(--or-mwc-input-text-color, var(--or-app-color8, ${unsafeCSS(DefaultColor8)}));
|
|
371
|
+
|
|
372
|
+
--mdc-theme-primary: var(--internal-or-mwc-input-color);
|
|
373
|
+
--mdc-theme-on-primary: var(--internal-or-mwc-input-text-color);
|
|
374
|
+
--mdc-theme-secondary: var(--internal-or-mwc-input-color);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
:host([hidden]) {
|
|
378
|
+
display: none;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
:host([type=select]) {
|
|
382
|
+
height: 56px;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#wrapper {
|
|
386
|
+
display: flex;
|
|
387
|
+
align-items: center;
|
|
388
|
+
min-height: 48px;
|
|
389
|
+
height: 100%;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
#wrapper > label {
|
|
393
|
+
white-space: nowrap;
|
|
394
|
+
margin-right: 20px;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
#component {
|
|
398
|
+
max-width: 100%;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.mdc-text-field {
|
|
402
|
+
flex: 1 1 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
.mdc-list {
|
|
406
|
+
flex: 1;
|
|
407
|
+
overflow: auto;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
.mdc-select__anchor {
|
|
411
|
+
max-width: 100%;
|
|
412
|
+
width: 100%;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.mdc-checkbox-list input {
|
|
416
|
+
display: none;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
.mdc-checkbox-list label {
|
|
420
|
+
display: block;
|
|
421
|
+
border-radius: 50%;
|
|
422
|
+
text-align: center;
|
|
423
|
+
width: 32px;
|
|
424
|
+
line-height: 32px;
|
|
425
|
+
height: 32px;
|
|
426
|
+
cursor: pointer;
|
|
427
|
+
background-color: var(--or-app-color2);
|
|
428
|
+
font-size: 13px;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
input::-webkit-calendar-picker-indicator {
|
|
432
|
+
margin: 0;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.mdc-checkbox-list .mdc-checkbox {
|
|
436
|
+
padding: 0;
|
|
437
|
+
height: 32px;
|
|
438
|
+
width: 32px;
|
|
439
|
+
}
|
|
440
|
+
.mdc-radio-container {
|
|
441
|
+
display: flex;
|
|
442
|
+
flex-direction: column;
|
|
443
|
+
}
|
|
444
|
+
.mdc-text-field.mdc-text-field--invalid:not(.mdc-text-field--disabled) + .mdc-text-field-helper-line .mdc-text-field-helper-text {
|
|
445
|
+
color: var(--mdc-theme-error, #b00020)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.mdc-checkbox-list input:checked + label {
|
|
449
|
+
color: var(--or-app-color2);
|
|
450
|
+
background-color: var(--mdc-theme-primary);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.mdc-button--rounded,
|
|
454
|
+
.or-mwc-input--rounded {
|
|
455
|
+
border-radius: 24px !important;
|
|
456
|
+
--mdc-shape-small: 32px;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
#select-searchable {
|
|
460
|
+
background-color: transparent;
|
|
461
|
+
border: 1px solid var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
|
|
462
|
+
margin: 8px;
|
|
463
|
+
width: calc(100% - 16px);
|
|
464
|
+
border-radius: 4px;
|
|
465
|
+
padding: 4px 16px;
|
|
466
|
+
flex: 0 0 auto;
|
|
467
|
+
align-items: center;
|
|
468
|
+
height: auto;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
.mdc-text-field__input::-webkit-calendar-picker-indicator {
|
|
472
|
+
display: block;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
::-webkit-clear-button {display: none;}
|
|
476
|
+
::-webkit-inner-spin-button { display: none; }
|
|
477
|
+
::-webkit-datetime-edit { padding: 0em; }
|
|
478
|
+
::-webkit-datetime-edit-text { padding: 0; }
|
|
479
|
+
|
|
480
|
+
.mdc-text-field--focused:not(.mdc-text-field--disabled) .mdc-floating-label {
|
|
481
|
+
color: var(--mdc-theme-primary);
|
|
482
|
+
}
|
|
483
|
+
.mdc-text-field--focused .mdc-text-field__input:required ~ .mdc-floating-label::after,
|
|
484
|
+
.mdc-text-field--focused .mdc-text-field__input:required ~ .mdc-notched-outline .mdc-floating-label::after {
|
|
485
|
+
color: var(--mdc-theme-primary);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
.mdc-text-field__input.resize-vertical {
|
|
489
|
+
resize: vertical;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
.mdc-text-field, .mdc-text-field-helper-line {
|
|
493
|
+
width: 100%;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.mdc-text-field.dense-comfortable, .mdc-select.dense-comfortable {
|
|
497
|
+
height: 48px;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
.mdc-text-field.dense-compact {
|
|
501
|
+
height: 36px;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
.mdc-select:not(.mdc-list) {
|
|
505
|
+
white-space: nowrap;
|
|
506
|
+
display: flex;
|
|
507
|
+
flex-direction: column;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
.mdc-select:not(.mdc-select--disabled).mdc-select--focused .mdc-floating-label {
|
|
511
|
+
color: var(--mdc-theme-primary);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
.mdc-select-helper-text {
|
|
515
|
+
white-space: normal;
|
|
516
|
+
color: rgba(0, 0, 0, 0.6);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.mdc-icon-button {
|
|
520
|
+
padding: 0;
|
|
521
|
+
color: var(--internal-or-mwc-input-color);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/* Give slider min width like select etc. */
|
|
525
|
+
.mdc-slider {
|
|
526
|
+
min-width: 200px;
|
|
527
|
+
flex: 1;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.mdc-switch {
|
|
531
|
+
margin: 0 24px;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.mdc-switch--full-width {
|
|
535
|
+
margin-left: auto;
|
|
536
|
+
}
|
|
537
|
+
.mdc-button--fullwidth {
|
|
538
|
+
width: 100%;
|
|
539
|
+
}
|
|
540
|
+
#field {
|
|
541
|
+
height: 100%;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.mdc-select__menu .mdc-list .mdc-list-item.mdc-list-item--selected or-icon {
|
|
545
|
+
--or-icon-fill: var(--or-app-color4);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
.mdc-menu__searchable {
|
|
549
|
+
overflow: hidden;
|
|
550
|
+
}
|
|
551
|
+
.mdc-menu__searchable.mdc-menu-surface--open {
|
|
552
|
+
display: flex;
|
|
553
|
+
flex-direction: column-reverse;
|
|
554
|
+
}
|
|
555
|
+
.mdc-menu__searchable.mdc-menu-surface--is-open-below {
|
|
556
|
+
flex-direction: column;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/* Prevent mouse events being fired from inside the or-icon shadowDOM */
|
|
560
|
+
.mdc-list-item__graphic > or-icon {
|
|
561
|
+
pointer-events: none;
|
|
562
|
+
}
|
|
563
|
+
`;
|
|
564
|
+
let OrMwcInput = class OrMwcInput extends LitElement {
|
|
565
|
+
constructor() {
|
|
566
|
+
super(...arguments);
|
|
567
|
+
this.readonly = false;
|
|
568
|
+
this.required = false;
|
|
569
|
+
this.checked = false;
|
|
570
|
+
this.indeterminate = false;
|
|
571
|
+
this.multiple = false;
|
|
572
|
+
this.searchLabel = "search";
|
|
573
|
+
this.compact = false;
|
|
574
|
+
this.comfortable = false;
|
|
575
|
+
/* BUTTON STYLES START */
|
|
576
|
+
this.raised = false;
|
|
577
|
+
this.action = false;
|
|
578
|
+
this.unElevated = false;
|
|
579
|
+
this.outlined = false;
|
|
580
|
+
this.rounded = false;
|
|
581
|
+
this.disableSliderNumberInput = false;
|
|
582
|
+
/* BUTTON STYLES END */
|
|
583
|
+
/* TEXT INPUT STYLES START */
|
|
584
|
+
this.fullWidth = false;
|
|
585
|
+
this.helperPersistent = false;
|
|
586
|
+
this.autoValidate = false;
|
|
587
|
+
this.charCounter = false;
|
|
588
|
+
this.disabled = false;
|
|
589
|
+
this.continuous = false;
|
|
590
|
+
this.resizeVertical = false;
|
|
591
|
+
/**
|
|
592
|
+
* Always censure text fields (like a password), and do not allow toggling
|
|
593
|
+
*/
|
|
594
|
+
this.censored = false;
|
|
595
|
+
/**
|
|
596
|
+
* Toggles visibility state of the password InputType (true = shown, false = hidden)
|
|
597
|
+
*/
|
|
598
|
+
this.advertised = false;
|
|
599
|
+
this._selectedIndex = -1;
|
|
600
|
+
this.isUiValid = true;
|
|
601
|
+
}
|
|
602
|
+
static get styles() {
|
|
603
|
+
return [
|
|
604
|
+
css `${unsafeCSS(iconButtonStyle)}`,
|
|
605
|
+
css `${unsafeCSS(buttonStyle)}`,
|
|
606
|
+
css `${unsafeCSS(buttonFabStyle)}`,
|
|
607
|
+
css `${unsafeCSS(textfieldStyle)}`,
|
|
608
|
+
css `${unsafeCSS(rippleStyle)}`,
|
|
609
|
+
css `${unsafeCSS(lineRippleStyle)}`,
|
|
610
|
+
css `${unsafeCSS(floatingLabelStyle)}`,
|
|
611
|
+
css `${unsafeCSS(formFieldStyle)}`,
|
|
612
|
+
css `${unsafeCSS(checkboxStyle)}`,
|
|
613
|
+
css `${unsafeCSS(radioStyle)}`,
|
|
614
|
+
css `${unsafeCSS(switchStyle)}`,
|
|
615
|
+
css `${unsafeCSS(selectStyle)}`,
|
|
616
|
+
css `${unsafeCSS(listStyle)}`,
|
|
617
|
+
css `${unsafeCSS(menuStyle)}`,
|
|
618
|
+
css `${unsafeCSS(menuSurfaceStyle)}`,
|
|
619
|
+
css `${unsafeCSS(sliderStyle)}`,
|
|
620
|
+
style
|
|
621
|
+
];
|
|
622
|
+
}
|
|
623
|
+
get nativeValue() {
|
|
624
|
+
if (this._mdcComponent) {
|
|
625
|
+
return this._mdcComponent.value;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
disconnectedCallback() {
|
|
629
|
+
var _a, _b;
|
|
630
|
+
super.disconnectedCallback();
|
|
631
|
+
if (this._mdcComponent) {
|
|
632
|
+
this._mdcComponent.destroy();
|
|
633
|
+
this._mdcComponent = undefined;
|
|
634
|
+
(_a = this._menuObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
635
|
+
}
|
|
636
|
+
if (this._mdcComponent2) {
|
|
637
|
+
this._mdcComponent2.destroy();
|
|
638
|
+
this._mdcComponent2 = undefined;
|
|
639
|
+
(_b = this._menuObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
shouldUpdate(_changedProperties) {
|
|
643
|
+
if (_changedProperties.has("indeterminate")) {
|
|
644
|
+
if (this._mdcComponent && this.type === InputType.CHECKBOX) {
|
|
645
|
+
this._mdcComponent.indeterminate = this.indeterminate;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (_changedProperties.has("disabled")) {
|
|
649
|
+
if (this._mdcComponent) {
|
|
650
|
+
this._mdcComponent.disabled = this.disabled;
|
|
651
|
+
}
|
|
652
|
+
if (this.type === InputType.RANGE && this._mdcComponent2) {
|
|
653
|
+
this._mdcComponent2.disabled = this.disabled;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (_changedProperties.has("readonly")) {
|
|
657
|
+
if (this._mdcComponent) {
|
|
658
|
+
this._mdcComponent.readonly = this.readonly;
|
|
659
|
+
}
|
|
660
|
+
if (this.type === InputType.RANGE && this._mdcComponent2) {
|
|
661
|
+
this._mdcComponent2.readonly = this.readonly;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (!this.type && this.value) {
|
|
665
|
+
if (this.value instanceof Date) {
|
|
666
|
+
this.type = InputType.DATETIME;
|
|
667
|
+
}
|
|
668
|
+
else if (typeof (this.value) === "boolean") {
|
|
669
|
+
this.type = InputType.CHECKBOX;
|
|
670
|
+
}
|
|
671
|
+
else if (typeof (this.value) === "number") {
|
|
672
|
+
this.type = InputType.NUMBER;
|
|
673
|
+
}
|
|
674
|
+
else if (typeof (this.value) === "string") {
|
|
675
|
+
this.type = InputType.TEXT;
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
this.type = InputType.JSON;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
focus() {
|
|
684
|
+
if (this.type === InputType.RANGE && this._mdcComponent2) {
|
|
685
|
+
this._mdcComponent2.focus();
|
|
686
|
+
}
|
|
687
|
+
else if (this._mdcComponent && typeof this._mdcComponent.focus === "function") {
|
|
688
|
+
this._mdcComponent.focus();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
render() {
|
|
692
|
+
var _a;
|
|
693
|
+
if (this.type) {
|
|
694
|
+
const showLabel = !this.fullWidth && this.label;
|
|
695
|
+
let outlined = !this.fullWidth && this.outlined;
|
|
696
|
+
let hasHelper = !!this.helperText;
|
|
697
|
+
const showValidationMessage = !this.isUiValid && (!!this.errorMessage || !!this.validationMessage);
|
|
698
|
+
const helperClasses = {
|
|
699
|
+
"mdc-text-field-helper-text--persistent": !showValidationMessage && this.helperPersistent,
|
|
700
|
+
"mdc-text-field-helper-text--validation-msg": showValidationMessage,
|
|
701
|
+
};
|
|
702
|
+
const hasValue = (this.value !== null && this.value !== undefined) || this.value === false;
|
|
703
|
+
let labelTemplate = showLabel ? html `<span class="mdc-floating-label ${hasValue ? "mdc-floating-label--float-above" : ""}" id="label">${this.label}</span>` : undefined;
|
|
704
|
+
switch (this.type) {
|
|
705
|
+
case InputType.RADIO:
|
|
706
|
+
const optsRadio = this.resolveOptions(this.options);
|
|
707
|
+
this._selectedIndex = -1;
|
|
708
|
+
return html `
|
|
709
|
+
<div class="mdc-radio-container">
|
|
710
|
+
${optsRadio ? optsRadio.map(([optValue, optDisplay], index) => {
|
|
711
|
+
if (this.value === optValue) {
|
|
712
|
+
this._selectedIndex = index;
|
|
713
|
+
}
|
|
714
|
+
return html `
|
|
715
|
+
<div id="field" class="mdc-form-field">
|
|
716
|
+
<div class="mdc-radio">
|
|
717
|
+
<input type="radio"
|
|
718
|
+
id="elem-${optValue}"
|
|
719
|
+
name="${ifDefined(this.name)}"
|
|
720
|
+
value="${optValue}"
|
|
721
|
+
?checked="${this.value && this.value.includes(optValue)}"
|
|
722
|
+
?required="${this.required}"
|
|
723
|
+
?disabled="${this.disabled || this.readonly}"
|
|
724
|
+
@change="${(e) => this.onValueChange(e.target, optValue)}"
|
|
725
|
+
class="mdc-radio__native-control"/>
|
|
726
|
+
<div class="mdc-radio__background">
|
|
727
|
+
<div class="mdc-radio__outer-circle"></div>
|
|
728
|
+
<div class="mdc-radio__inner-circle"></div>
|
|
729
|
+
</div>
|
|
730
|
+
<div class="mdc-radio__ripple"></div>
|
|
731
|
+
</div>
|
|
732
|
+
<label for="elem-${optValue}"><or-translate value="${optDisplay}"></or-translate></label>
|
|
733
|
+
</div>
|
|
734
|
+
|
|
735
|
+
`;
|
|
736
|
+
}) : ``}
|
|
737
|
+
</div>
|
|
738
|
+
`;
|
|
739
|
+
case InputType.SWITCH:
|
|
740
|
+
const classesSwitch = {
|
|
741
|
+
"mdc-switch--disabled": this.disabled || this.readonly,
|
|
742
|
+
"mdc-switch--full-width": this.fullWidth,
|
|
743
|
+
"mdc-switch--checked": this.value,
|
|
744
|
+
};
|
|
745
|
+
return html `
|
|
746
|
+
<span id="wrapper">
|
|
747
|
+
${this.label ? html `<label for="elem" class="${this.disabled ? "mdc-switch--disabled" : ""}">${this.label}</label>` : ``}
|
|
748
|
+
<div id="component" class="mdc-switch ${classMap(classesSwitch)}">
|
|
749
|
+
<div class="mdc-switch__track"></div>
|
|
750
|
+
<div class="mdc-switch__thumb-underlay">
|
|
751
|
+
<div class="mdc-switch__thumb">
|
|
752
|
+
<input type="checkbox" id="elem" class="mdc-switch__native-control"
|
|
753
|
+
?checked="${this.value}"
|
|
754
|
+
?required="${this.required}"
|
|
755
|
+
?disabled="${this.disabled || this.readonly}"
|
|
756
|
+
@change="${(e) => this.onValueChange(e.target, e.target.checked)}"
|
|
757
|
+
role="switch">
|
|
758
|
+
</div>
|
|
759
|
+
</div>
|
|
760
|
+
</div>
|
|
761
|
+
</span>
|
|
762
|
+
`;
|
|
763
|
+
case InputType.LIST:
|
|
764
|
+
const classesList = {
|
|
765
|
+
"mdc-select--outlined": outlined,
|
|
766
|
+
"mdc-select--disabled": this.disabled,
|
|
767
|
+
"mdc-select--required": this.required,
|
|
768
|
+
"mdc-select--dense": false, // this.dense,
|
|
769
|
+
"mdc-select--no-label": !this.label,
|
|
770
|
+
"mdc-select--with-leading-icon": !!this.icon
|
|
771
|
+
};
|
|
772
|
+
const optsList = this.resolveOptions(this.options);
|
|
773
|
+
this._selectedIndex = -1;
|
|
774
|
+
return html `
|
|
775
|
+
<div id="component" class="mdc-list mdc-select ${classMap(classesList)}" @MDCList:action="${(e) => this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(this.options[e.detail.index]) ? this.options[e.detail.index][0] : this.options[e.detail.index])}">
|
|
776
|
+
<ul class="mdc-list">
|
|
777
|
+
${optsList ? optsList.map(([optValue, optDisplay], index) => {
|
|
778
|
+
if (this.value === optValue) {
|
|
779
|
+
this._selectedIndex = index;
|
|
780
|
+
}
|
|
781
|
+
// todo: it's not actually putting the mdc-list-item--selected class on even when this.value === optValue...
|
|
782
|
+
return html `<li class="${classMap({ "mdc-list-item": true, "mdc-list-item--selected": this.value === optValue })}" role="option" data-value="${optValue}"><or-translate value="${optDisplay}"></or-translate></li>`;
|
|
783
|
+
}) : ``}
|
|
784
|
+
</ul>
|
|
785
|
+
</div>
|
|
786
|
+
`;
|
|
787
|
+
case InputType.SELECT:
|
|
788
|
+
const classes = {
|
|
789
|
+
"mdc-select--outlined": outlined,
|
|
790
|
+
"mdc-select--filled": !outlined,
|
|
791
|
+
"mdc-select--disabled": this.disabled || this.readonly,
|
|
792
|
+
"mdc-select--required": this.required,
|
|
793
|
+
"mdc-select--dense": false, // this.dense,
|
|
794
|
+
"dense-comfortable": this.comfortable,
|
|
795
|
+
"mdc-select--no-label": !this.label,
|
|
796
|
+
"mdc-select--with-leading-icon": !!this.icon,
|
|
797
|
+
"or-mwc-input--rounded": this.rounded
|
|
798
|
+
};
|
|
799
|
+
let opts;
|
|
800
|
+
if (this.searchProvider != undefined) {
|
|
801
|
+
opts = this.searchProvider(this.searchableValue);
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
opts = this.resolveOptions(this.options);
|
|
805
|
+
}
|
|
806
|
+
const itemClickHandler = (ev, item) => {
|
|
807
|
+
var _a;
|
|
808
|
+
const value = item.value;
|
|
809
|
+
if (this.multiple) {
|
|
810
|
+
ev.stopPropagation();
|
|
811
|
+
const inputValue = (_a = this._tempValue) !== null && _a !== void 0 ? _a : (Array.isArray(this.value) ? [...this.value] : this.value !== undefined ? [this.value] : []);
|
|
812
|
+
const index = inputValue.findIndex((v) => v === value);
|
|
813
|
+
if (index >= 0) {
|
|
814
|
+
inputValue.splice(index, 1);
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
inputValue.push(value);
|
|
818
|
+
}
|
|
819
|
+
const listItemEl = ev.composedPath()[0].closest("li"), iconEl = listItemEl.getElementsByTagName("or-icon")[0];
|
|
820
|
+
if (listItemEl) {
|
|
821
|
+
if (index >= 0) {
|
|
822
|
+
listItemEl.classList.remove("mdc-list-item--selected");
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
listItemEl.classList.add("mdc-list-item--selected");
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (iconEl) {
|
|
829
|
+
iconEl.icon = index >= 0 ? "checkbox-blank-outline" : "checkbox-marked";
|
|
830
|
+
}
|
|
831
|
+
this._tempValue = inputValue;
|
|
832
|
+
}
|
|
833
|
+
// A narrowed down list with search, or a different asynchronous approach does not always trigger @MDCSelect:change,
|
|
834
|
+
// so using itemClickHandler instead to let it trigger anyway.
|
|
835
|
+
else if (this.searchProvider != undefined || !Array.isArray(opts)) {
|
|
836
|
+
this.onValueChange(undefined, item.value);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
const menuCloseHandler = () => {
|
|
840
|
+
var _a;
|
|
841
|
+
const v = ((_a = this._tempValue) !== null && _a !== void 0 ? _a : this.value);
|
|
842
|
+
window.setTimeout(() => {
|
|
843
|
+
if (this._mdcComponent) {
|
|
844
|
+
// Hack to stop label moving down when there is a value set
|
|
845
|
+
this._mdcComponent.foundation.adapter.floatLabel(v && (!Array.isArray(v) || v.length > 0));
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
if (!this._tempValue) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const val = [...this._tempValue];
|
|
852
|
+
this._tempValue = undefined;
|
|
853
|
+
this.onValueChange(undefined, val);
|
|
854
|
+
};
|
|
855
|
+
const listTemplate = (options) => {
|
|
856
|
+
if (this.searchProvider != undefined && (!options || options.length == 0)) {
|
|
857
|
+
return html `<span class="mdc-text-field-helper-line" style="margin: 8px 8px 8px 0;">${i18next.t('noResults')}</span>`;
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
return getListTemplate(this.multiple ? ListType.MULTI_TICK : ListType.SELECT, html `${options === null || options === void 0 ? void 0 : options.map(([optValue, optDisplay], index) => {
|
|
861
|
+
return getItemTemplate({
|
|
862
|
+
text: optDisplay,
|
|
863
|
+
value: optValue
|
|
864
|
+
}, index, Array.isArray(this.value) ? this.value : this.value ? [this.value] : [], this.multiple ? ListType.MULTI_TICK : ListType.SELECT, false, itemClickHandler);
|
|
865
|
+
})}`, false, undefined);
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
return html `
|
|
869
|
+
<div id="component"
|
|
870
|
+
class="mdc-select ${classMap(classes)}"
|
|
871
|
+
@MDCSelect:change="${(e) => __awaiter(this, void 0, void 0, function* () {
|
|
872
|
+
const options = (Array.isArray(opts) ? opts : yield opts);
|
|
873
|
+
this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(options[e.detail.index]) ? options[e.detail.index][0] : options[e.detail.index]);
|
|
874
|
+
})}">
|
|
875
|
+
<div class="mdc-select__anchor" role="button"
|
|
876
|
+
aria-haspopup="listbox"
|
|
877
|
+
aria-expanded="false"
|
|
878
|
+
aria-disabled="${"" + (this.disabled || this.readonly)}"
|
|
879
|
+
aria-labelledby="label selected-text">
|
|
880
|
+
${!outlined ? html `<span class="mdc-select__ripple"></span>` : undefined}
|
|
881
|
+
${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}
|
|
882
|
+
<span class="mdc-select__selected-text-container">
|
|
883
|
+
<span id="selected-text" class="mdc-select__selected-text"></span>
|
|
884
|
+
</span>
|
|
885
|
+
<span class="mdc-select__dropdown-icon">
|
|
886
|
+
<svg
|
|
887
|
+
class="mdc-select__dropdown-icon-graphic"
|
|
888
|
+
viewBox="7 10 10 5">
|
|
889
|
+
<polygon
|
|
890
|
+
class="mdc-select__dropdown-icon-inactive"
|
|
891
|
+
stroke="none"
|
|
892
|
+
fill-rule="evenodd"
|
|
893
|
+
points="7 10 12 15 17 10">
|
|
894
|
+
</polygon>
|
|
895
|
+
<polygon
|
|
896
|
+
class="mdc-select__dropdown-icon-active"
|
|
897
|
+
stroke="none"
|
|
898
|
+
fill-rule="evenodd"
|
|
899
|
+
points="7 15 12 10 17 15">
|
|
900
|
+
</polygon>
|
|
901
|
+
</svg>
|
|
902
|
+
</span>
|
|
903
|
+
${!outlined ? html `<div class="mdc-line-ripple"></div>` : ``}
|
|
904
|
+
</div>
|
|
905
|
+
<div id="mdc-select-menu" class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fixed ${this.searchProvider != undefined ? 'mdc-menu__searchable' : undefined}" @MDCMenuSurface:closed="${menuCloseHandler}">
|
|
906
|
+
${when(this.searchProvider != undefined, () => html `
|
|
907
|
+
<label id="select-searchable" class="mdc-text-field mdc-text-field--filled">
|
|
908
|
+
<span class="mdc-floating-label" style="color: rgba(0, 0, 0, 0.6); text-transform: capitalize; visibility: ${this.searchableValue ? 'hidden' : 'visible'}" id="my-label-id">
|
|
909
|
+
<or-translate .value="${this.searchLabel}"></or-translate>
|
|
910
|
+
</span>
|
|
911
|
+
<input class="mdc-text-field__input" type="text"
|
|
912
|
+
@keyup="${(e) => this.searchableValue = e.target.value}"
|
|
913
|
+
/>
|
|
914
|
+
</label>
|
|
915
|
+
`)}
|
|
916
|
+
${when(Array.isArray(opts), () => {
|
|
917
|
+
return listTemplate(opts);
|
|
918
|
+
}, () => {
|
|
919
|
+
return until(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
920
|
+
resolve(listTemplate(yield opts));
|
|
921
|
+
})), html `<span class="mdc-text-field-helper-line" style="margin: 8px 8px 8px 0;">${i18next.t('loading')}</span>`);
|
|
922
|
+
})}
|
|
923
|
+
</div>
|
|
924
|
+
${hasHelper || showValidationMessage ? html `
|
|
925
|
+
<p id="component-helper-text" class="mdc-select-helper-text ${classMap(helperClasses)}" aria-hidden="true">
|
|
926
|
+
${showValidationMessage ? this.errorMessage || this.validationMessage : this.helperText}
|
|
927
|
+
</p>` : ``}
|
|
928
|
+
</div>
|
|
929
|
+
`;
|
|
930
|
+
case InputType.BUTTON_TOGGLE:
|
|
931
|
+
return html `
|
|
932
|
+
<button id="component" class="mdc-icon-button ${this.value ? "mdc-icon-button--on" : ""}"
|
|
933
|
+
?readonly="${this.readonly}"
|
|
934
|
+
?disabled="${this.disabled}"
|
|
935
|
+
@MDCIconButtonToggle:change="${(evt) => this.onValueChange(undefined, evt.detail.isOn)}">
|
|
936
|
+
${this.icon ? html `<or-icon class="mdc-icon-button__icon" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
|
|
937
|
+
${this.iconOn ? html `<or-icon class="mdc-icon-button__icon mdc-icon-button__icon--on" aria-hidden="true" icon="${this.iconOn}"></or-icon>` : ``}
|
|
938
|
+
</button>
|
|
939
|
+
`;
|
|
940
|
+
case InputType.BUTTON:
|
|
941
|
+
case InputType.BUTTON_MOMENTARY: {
|
|
942
|
+
const onMouseDown = (ev) => {
|
|
943
|
+
if (this.disabled) {
|
|
944
|
+
ev.stopPropagation();
|
|
945
|
+
}
|
|
946
|
+
if (isMomentary)
|
|
947
|
+
this.dispatchEvent(new OrInputChangedEvent(true, null));
|
|
948
|
+
};
|
|
949
|
+
const onMouseUp = (ev) => {
|
|
950
|
+
if (this.disabled) {
|
|
951
|
+
ev.stopPropagation();
|
|
952
|
+
}
|
|
953
|
+
if (isMomentary)
|
|
954
|
+
this.dispatchEvent(new OrInputChangedEvent(false, true));
|
|
955
|
+
};
|
|
956
|
+
const onClick = (ev) => {
|
|
957
|
+
if (this.disabled) {
|
|
958
|
+
ev.stopPropagation();
|
|
959
|
+
}
|
|
960
|
+
if (!isMomentary)
|
|
961
|
+
this.dispatchEvent(new OrInputChangedEvent(true, null));
|
|
962
|
+
};
|
|
963
|
+
const isMomentary = this.type === InputType.BUTTON_MOMENTARY;
|
|
964
|
+
const isIconButton = !this.action && !this.label;
|
|
965
|
+
// If no action, label or icons are given, show as a circle.
|
|
966
|
+
if (isIconButton && !this.iconTrailing && !this.icon) {
|
|
967
|
+
this.icon = "circle";
|
|
968
|
+
}
|
|
969
|
+
const classes = {
|
|
970
|
+
"mdc-icon-button": isIconButton,
|
|
971
|
+
"mdc-fab": !isIconButton && this.action,
|
|
972
|
+
"mdc-fab--extended": !isIconButton && this.action && !!this.label,
|
|
973
|
+
"mdc-fab--mini": !isIconButton && this.action && (this.compact || this.comfortable),
|
|
974
|
+
"mdc-button": !isIconButton && !this.action,
|
|
975
|
+
"mdc-button--raised": !isIconButton && !this.action && this.raised,
|
|
976
|
+
"mdc-button--unelevated": !isIconButton && !this.action && this.unElevated,
|
|
977
|
+
"mdc-button--outlined": !isIconButton && !this.action && (this.outlined || isMomentary),
|
|
978
|
+
"mdc-button--rounded": !isIconButton && !this.action && this.rounded,
|
|
979
|
+
"mdc-button--fullwidth": this.fullWidth,
|
|
980
|
+
};
|
|
981
|
+
return html `
|
|
982
|
+
<button id="component" class="${classMap(classes)}"
|
|
983
|
+
?readonly="${this.readonly}"
|
|
984
|
+
?disabled="${this.disabled}"
|
|
985
|
+
@click="${(ev) => onClick(ev)}"
|
|
986
|
+
@mousedown="${(ev) => onMouseDown(ev)}" @mouseup="${(ev) => onMouseUp(ev)}">
|
|
987
|
+
${!isIconButton ? html `<div class="mdc-button__ripple"></div>` : ``}
|
|
988
|
+
${this.icon ? html `<or-icon class="${isIconButton ? "" : this.action ? "mdc-fab__icon" : "mdc-button__icon"}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
|
|
989
|
+
${this.label ? html `<span class="${this.action ? "mdc-fab__label" : "mdc-button__label"}"><or-translate .value="${this.label}"></or-translate></span>` : ``}
|
|
990
|
+
${!isIconButton && this.iconTrailing ? html `<or-icon class="${this.action ? "mdc-fab__icon" : "mdc-button__icon"}" aria-hidden="true" icon="${this.iconTrailing}"></or-icon>` : ``}
|
|
991
|
+
</button>
|
|
992
|
+
`;
|
|
993
|
+
}
|
|
994
|
+
case InputType.CHECKBOX_LIST:
|
|
995
|
+
if (!Array.isArray(this.value)) {
|
|
996
|
+
if (this.value === null || this.value === undefined) {
|
|
997
|
+
this.value = [];
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
this.value = [this.value];
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
const optsCheckboxList = this.resolveOptions(this.options);
|
|
1004
|
+
this._selectedIndex = -1;
|
|
1005
|
+
return html `
|
|
1006
|
+
<div class="mdc-checkbox-list">
|
|
1007
|
+
${optsCheckboxList ? optsCheckboxList.map(([optValue, optDisplay], index) => {
|
|
1008
|
+
if (this.value === optValue) {
|
|
1009
|
+
this._selectedIndex = index;
|
|
1010
|
+
}
|
|
1011
|
+
return html `
|
|
1012
|
+
<div id="field" class="mdc-form-field">
|
|
1013
|
+
<div id="component" class="mdc-checkbox">
|
|
1014
|
+
<input type="checkbox"
|
|
1015
|
+
?checked="${this.value && this.value.includes(optValue)}"
|
|
1016
|
+
?required="${this.required}"
|
|
1017
|
+
name="${optValue}"
|
|
1018
|
+
?disabled="${this.disabled || this.readonly}"
|
|
1019
|
+
@change="${(e) => {
|
|
1020
|
+
let val = this.value;
|
|
1021
|
+
if (e.target.checked) {
|
|
1022
|
+
if (!val.includes(optValue)) {
|
|
1023
|
+
val = [optValue, ...val];
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
else {
|
|
1027
|
+
val = val.filter((v) => v !== optValue);
|
|
1028
|
+
}
|
|
1029
|
+
this.onValueChange(e.target, val);
|
|
1030
|
+
}}"
|
|
1031
|
+
class="mdc-checkbox__native-control" id="elem-${optValue}"/>
|
|
1032
|
+
|
|
1033
|
+
<label for="elem-${optValue}"><or-translate value="${optDisplay}"></or-translate></label>
|
|
1034
|
+
|
|
1035
|
+
</div>
|
|
1036
|
+
</div>
|
|
1037
|
+
|
|
1038
|
+
`;
|
|
1039
|
+
}) : ``}
|
|
1040
|
+
</div>
|
|
1041
|
+
`;
|
|
1042
|
+
case InputType.CHECKBOX:
|
|
1043
|
+
let classList = {
|
|
1044
|
+
"mdc-checkbox": true,
|
|
1045
|
+
"mdc-checkbox--disabled": this.disabled || this.readonly
|
|
1046
|
+
};
|
|
1047
|
+
return html `
|
|
1048
|
+
<div id="field" class="mdc-form-field">
|
|
1049
|
+
<div id="component" class="${classMap(classList)}">
|
|
1050
|
+
<input type="checkbox"
|
|
1051
|
+
id="elem"
|
|
1052
|
+
data-indeterminate="${this.indeterminate}"
|
|
1053
|
+
?checked="${this.value}"
|
|
1054
|
+
?required="${this.required}"
|
|
1055
|
+
?disabled="${this.disabled || this.readonly}"
|
|
1056
|
+
@change="${(e) => this.onValueChange(e.target, e.target.checked)}"
|
|
1057
|
+
class="mdc-checkbox__native-control" />
|
|
1058
|
+
<div class="mdc-checkbox__background">
|
|
1059
|
+
<svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
|
|
1060
|
+
<path class="mdc-checkbox__checkmark-path" fill="none" d="M1.73,12.91 8.1,19.28 22.79,4.59"></path>
|
|
1061
|
+
</svg>
|
|
1062
|
+
<div class="mdc-checkbox__mixedmark"></div>
|
|
1063
|
+
</div>
|
|
1064
|
+
<div class="mdc-checkbox__ripple"></div>
|
|
1065
|
+
</div>
|
|
1066
|
+
<label class="mdc-checkbox-circle" for="elem">${this.label}</label>
|
|
1067
|
+
</div>
|
|
1068
|
+
`;
|
|
1069
|
+
case InputType.COLOUR:
|
|
1070
|
+
return html `
|
|
1071
|
+
<div id="component" style="width: 100%; display: inline-flex; align-items: center; padding: 8px 0;">
|
|
1072
|
+
<input type="color" id="elem" style="border: none; height: 31px; width: 31px; padding: 1px 3px; min-height: 22px; min-width: 30px;cursor: pointer" value="${this.value}"
|
|
1073
|
+
?disabled="${this.disabled || this.readonly}"
|
|
1074
|
+
?required="${this.required}"
|
|
1075
|
+
@change="${(e) => this.onValueChange(e.target, e.target.value)}"
|
|
1076
|
+
/>
|
|
1077
|
+
<label style="margin-left: 10px; cursor: pointer" for="elem">${this.label}</label>
|
|
1078
|
+
</div>
|
|
1079
|
+
`;
|
|
1080
|
+
case InputType.NUMBER:
|
|
1081
|
+
case InputType.RANGE:
|
|
1082
|
+
case InputType.DATE:
|
|
1083
|
+
case InputType.DATETIME:
|
|
1084
|
+
case InputType.TIME:
|
|
1085
|
+
case InputType.MONTH:
|
|
1086
|
+
case InputType.WEEK:
|
|
1087
|
+
case InputType.EMAIL:
|
|
1088
|
+
case InputType.PASSWORD:
|
|
1089
|
+
case InputType.TELEPHONE:
|
|
1090
|
+
case InputType.URL:
|
|
1091
|
+
case InputType.TEXT:
|
|
1092
|
+
case InputType.TEXTAREA:
|
|
1093
|
+
case InputType.JSON:
|
|
1094
|
+
case InputType.JSON_OBJECT: {
|
|
1095
|
+
// The following HTML input types require the values as specially formatted strings
|
|
1096
|
+
let valMinMax = [this.value === undefined || this.value === null ? undefined : this.value, this.min, this.max];
|
|
1097
|
+
if (valMinMax.some((v) => typeof (v) !== "string")) {
|
|
1098
|
+
if (this.type === InputType.JSON || this.type === InputType.JSON_OBJECT) {
|
|
1099
|
+
if (valMinMax[0] !== undefined) {
|
|
1100
|
+
if (typeof valMinMax[0] !== "string" || valMinMax[0] === null) {
|
|
1101
|
+
try {
|
|
1102
|
+
valMinMax[0] = JSON.stringify(valMinMax[0], null, 2);
|
|
1103
|
+
}
|
|
1104
|
+
catch (e) {
|
|
1105
|
+
console.warn("Failed to parse JSON expression for input control");
|
|
1106
|
+
valMinMax[0] = "";
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
valMinMax[0] = "";
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
const format = this.format ? Object.assign({}, this.format) : {};
|
|
1116
|
+
switch (this.type) {
|
|
1117
|
+
case InputType.TIME:
|
|
1118
|
+
format.asDate = true;
|
|
1119
|
+
format.hour12 = false;
|
|
1120
|
+
format.timeStyle = this.step && this.step < 60 ? "medium" /* ValueFormatStyleRepresentation.MEDIUM */ : "short" /* ValueFormatStyleRepresentation.SHORT */;
|
|
1121
|
+
break;
|
|
1122
|
+
case InputType.DATE:
|
|
1123
|
+
format.asDate = true;
|
|
1124
|
+
format.momentJsFormat = "YYYY-MM-DD";
|
|
1125
|
+
break;
|
|
1126
|
+
case InputType.WEEK:
|
|
1127
|
+
format.asDate = true;
|
|
1128
|
+
format.momentJsFormat = "YYYY-[W]WW";
|
|
1129
|
+
break;
|
|
1130
|
+
case InputType.MONTH:
|
|
1131
|
+
format.asDate = true;
|
|
1132
|
+
format.momentJsFormat = "YYYY-MM";
|
|
1133
|
+
break;
|
|
1134
|
+
case InputType.DATETIME:
|
|
1135
|
+
format.asDate = true;
|
|
1136
|
+
format.momentJsFormat = "YYYY-MM-DDTHH:mm";
|
|
1137
|
+
break;
|
|
1138
|
+
case InputType.NUMBER:
|
|
1139
|
+
(_a = format.maximumFractionDigits) !== null && _a !== void 0 ? _a : (format.maximumFractionDigits = 20); // default according to Web documentation
|
|
1140
|
+
break;
|
|
1141
|
+
}
|
|
1142
|
+
// Numbers/dates must be in english locale without commas etc.
|
|
1143
|
+
format.useGrouping = false;
|
|
1144
|
+
valMinMax = valMinMax.map((val) => val !== undefined ? Util.getValueAsString(val, () => format, "en-GB") : undefined);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
let inputElem;
|
|
1148
|
+
let label = this.label;
|
|
1149
|
+
let type = this.type;
|
|
1150
|
+
let componentId = "component";
|
|
1151
|
+
if (this.type === InputType.RANGE) {
|
|
1152
|
+
// Change vars so number input can be included alongside the slider
|
|
1153
|
+
label = undefined;
|
|
1154
|
+
outlined = false;
|
|
1155
|
+
hasHelper = false;
|
|
1156
|
+
type = InputType.NUMBER;
|
|
1157
|
+
componentId = "number";
|
|
1158
|
+
}
|
|
1159
|
+
if (!(this.type === InputType.RANGE && this.disableSliderNumberInput)) {
|
|
1160
|
+
// Handle password toggling logic
|
|
1161
|
+
if (this.censored)
|
|
1162
|
+
type = InputType.PASSWORD;
|
|
1163
|
+
if (this.type === InputType.PASSWORD && this.advertised)
|
|
1164
|
+
type = InputType.TEXT;
|
|
1165
|
+
const classes = {
|
|
1166
|
+
"mdc-text-field": true,
|
|
1167
|
+
"mdc-text-field--invalid": !this.valid,
|
|
1168
|
+
"mdc-text-field--filled": !outlined,
|
|
1169
|
+
"mdc-text-field--outlined": outlined,
|
|
1170
|
+
"mdc-text-field--textarea": type === InputType.TEXTAREA || type === InputType.JSON || type === InputType.JSON_OBJECT,
|
|
1171
|
+
"mdc-text-field--disabled": this.disabled,
|
|
1172
|
+
"mdc-text-field--fullwidth": this.fullWidth && !outlined,
|
|
1173
|
+
"dense-comfortable": this.comfortable && !(type === InputType.TEXTAREA || type === InputType.JSON || type === InputType.JSON_OBJECT),
|
|
1174
|
+
"dense-compact": !this.comfortable && this.compact,
|
|
1175
|
+
"mdc-text-field--label-floating": hasValue,
|
|
1176
|
+
"mdc-text-field--no-label": !this.label,
|
|
1177
|
+
"mdc-text-field--with-leading-icon": !!this.icon,
|
|
1178
|
+
"mdc-text-field--with-trailing-icon": !!this.iconTrailing,
|
|
1179
|
+
"or-mwc-input--rounded": this.rounded
|
|
1180
|
+
};
|
|
1181
|
+
inputElem = type === InputType.TEXTAREA || type === InputType.JSON || type === InputType.JSON_OBJECT
|
|
1182
|
+
? html `
|
|
1183
|
+
<textarea id="elem" class="mdc-text-field__input ${this.resizeVertical ? "resize-vertical" : ""}" ?required="${this.required}"
|
|
1184
|
+
?readonly="${this.readonly}" ?disabled="${this.disabled}" minlength="${ifDefined(this.minLength)}"
|
|
1185
|
+
maxlength="${ifDefined(this.maxLength)}" rows="${this.rows ? this.rows : 5}"
|
|
1186
|
+
cols="${ifDefined(this.cols)}" aria-label="${ifDefined(label)}"
|
|
1187
|
+
aria-labelledby="${ifDefined(label ? "label" : undefined)}"
|
|
1188
|
+
@change="${(e) => this.onValueChange(e.target, e.target.value)}">${valMinMax[0] ? valMinMax[0] : ""}</textarea>`
|
|
1189
|
+
: html `
|
|
1190
|
+
<input type="${type}" id="elem" aria-labelledby="${ifDefined(label ? "label" : undefined)}"
|
|
1191
|
+
class="mdc-text-field__input" ?required="${this.required}" ?readonly="${this.readonly}"
|
|
1192
|
+
?disabled="${this.disabled}" min="${ifDefined(valMinMax[1])}" max="${ifDefined(valMinMax[2])}"
|
|
1193
|
+
step="${this.step ? this.step : "any"}" minlength="${ifDefined(this.minLength)}" pattern="${ifDefined(this.pattern)}"
|
|
1194
|
+
maxlength="${ifDefined(this.maxLength)}" placeholder="${ifDefined(this.placeHolder)}"
|
|
1195
|
+
.value="${valMinMax[0] !== null && valMinMax[0] !== undefined ? valMinMax[0] : ""}"
|
|
1196
|
+
@keydown="${(e) => {
|
|
1197
|
+
if ((e.code === "Enter" || e.code === "NumpadEnter")) {
|
|
1198
|
+
this.onValueChange(e.target, e.target.value, true);
|
|
1199
|
+
}
|
|
1200
|
+
}}"
|
|
1201
|
+
@blur="${(e) => { if (e.target.value === "")
|
|
1202
|
+
this.reportValidity(); }}"
|
|
1203
|
+
@change="${(e) => this.onValueChange(e.target, e.target.value)}" />`;
|
|
1204
|
+
inputElem = html `
|
|
1205
|
+
<label id="${componentId}" class="${classMap(classes)}">
|
|
1206
|
+
${this.icon ? html `<or-icon class="mdc-text-field__icon mdc-text-field__icon--leading" style="color: ${this.iconColor ? "#" + this.iconColor : "unset"}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
|
|
1207
|
+
${outlined ? `` : html `<span class="mdc-text-field__ripple"></span>`}
|
|
1208
|
+
${inputElem}
|
|
1209
|
+
${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}
|
|
1210
|
+
${outlined ? `` : html `<span class="mdc-line-ripple"></span>`}
|
|
1211
|
+
${this.type === InputType.PASSWORD && !this.censored ? html `<or-icon class="mdc-text-field__icon mdc-text-field__icon--trailing" aria-hidden="true" icon=${this.advertised ? 'eye' : 'eye-off'} style="pointer-events: auto;" @click=${() => this.advertised = !this.advertised}></or-icon>` : ``}
|
|
1212
|
+
${this.iconTrailing ? html `<or-icon class="mdc-text-field__icon mdc-text-field__icon--trailing" aria-hidden="true" icon="${this.iconTrailing}"></or-icon>` : ``}
|
|
1213
|
+
</label>
|
|
1214
|
+
${hasHelper || showValidationMessage ? html `
|
|
1215
|
+
<div class="mdc-text-field-helper-line">
|
|
1216
|
+
<div class="mdc-text-field-helper-text ${classMap(helperClasses)}">${showValidationMessage ? this.errorMessage || this.validationMessage : this.helperText}</div>
|
|
1217
|
+
${this.charCounter && !this.readonly ? html `<div class="mdc-text-field-character-counter"></div>` : ``}
|
|
1218
|
+
</div>
|
|
1219
|
+
` : ``}
|
|
1220
|
+
`;
|
|
1221
|
+
}
|
|
1222
|
+
if (this.type === InputType.RANGE) {
|
|
1223
|
+
const classes = {
|
|
1224
|
+
"mdc-slider": true,
|
|
1225
|
+
"mdc-slider--range": this.continuous,
|
|
1226
|
+
"mdc-slider--discreet": !this.continuous,
|
|
1227
|
+
"mdc-slider--disabled": this.disabled || this.readonly
|
|
1228
|
+
};
|
|
1229
|
+
inputElem = html `
|
|
1230
|
+
<span id="wrapper">
|
|
1231
|
+
${this.label ? html `<label for="component" class="${this.disabled ? "mdc-switch--disabled" : ""}">${this.label}</label>` : ``}
|
|
1232
|
+
<div id="component" class="${classMap(classes)}" @MDCSlider:change="${(ev) => this.onValueChange(undefined, ev.detail.value)}">
|
|
1233
|
+
<input id="elem" class="mdc-slider__input" type="range" min="${ifDefined(valMinMax[1])}" max="${ifDefined(valMinMax[2])}" value="${valMinMax[0] || valMinMax[1] || 0}" name="slider" step="${this.step || 1}" ?readonly="${this.readonly}" ?disabled="${this.disabled}" aria-label="${ifDefined(this.label)}" />
|
|
1234
|
+
<div class="mdc-slider__track">
|
|
1235
|
+
<div class="mdc-slider__track--inactive"></div>
|
|
1236
|
+
<div class="mdc-slider__track--active">
|
|
1237
|
+
<div class="mdc-slider__track--active_fill"></div>
|
|
1238
|
+
</div>
|
|
1239
|
+
</div>
|
|
1240
|
+
<div class="mdc-slider__thumb">
|
|
1241
|
+
${!this.continuous ? html `<div class="mdc-slider__value-indicator-container" aria-hidden="true">
|
|
1242
|
+
<div class="mdc-slider__value-indicator">
|
|
1243
|
+
<span class="mdc-slider__value-indicator-text">
|
|
1244
|
+
50
|
|
1245
|
+
</span>
|
|
1246
|
+
</div>
|
|
1247
|
+
</div>` : ``}
|
|
1248
|
+
<div class="mdc-slider__thumb-knob"></div>
|
|
1249
|
+
</div>
|
|
1250
|
+
</div>
|
|
1251
|
+
${inputElem ? html `<div style="min-width: 70px; width: 70px;">${inputElem}</div>` : ``}
|
|
1252
|
+
</span>
|
|
1253
|
+
`;
|
|
1254
|
+
}
|
|
1255
|
+
return inputElem;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return html `<span>INPUT TYPE NOT IMPLEMENTED</span>`;
|
|
1260
|
+
}
|
|
1261
|
+
_getFormat() {
|
|
1262
|
+
if (this.format) {
|
|
1263
|
+
return this.format;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
update(_changedProperties) {
|
|
1267
|
+
if (_changedProperties.has('autoValidate') && this._mdcComponent) {
|
|
1268
|
+
const comp = this._mdcComponent;
|
|
1269
|
+
if (comp.foundation && comp.foundation.setValidateOnValueChange) {
|
|
1270
|
+
comp.foundation.setValidateOnValueChange(this.autoValidate);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
super.update(_changedProperties);
|
|
1274
|
+
}
|
|
1275
|
+
firstUpdated(_changedProperties) {
|
|
1276
|
+
super.firstUpdated(_changedProperties);
|
|
1277
|
+
if (this.autoValidate) {
|
|
1278
|
+
this.reportValidity();
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
updated(_changedProperties) {
|
|
1282
|
+
var _a, _b;
|
|
1283
|
+
super.updated(_changedProperties);
|
|
1284
|
+
if (_changedProperties.has("type")) {
|
|
1285
|
+
const component = this.shadowRoot.getElementById("component");
|
|
1286
|
+
if (this._mdcComponent) {
|
|
1287
|
+
this._mdcComponent.destroy();
|
|
1288
|
+
this._mdcComponent = undefined;
|
|
1289
|
+
}
|
|
1290
|
+
if (this._mdcComponent2) {
|
|
1291
|
+
this._mdcComponent2.destroy();
|
|
1292
|
+
this._mdcComponent2 = undefined;
|
|
1293
|
+
}
|
|
1294
|
+
if (component && this.type) {
|
|
1295
|
+
switch (this.type) {
|
|
1296
|
+
case InputType.LIST:
|
|
1297
|
+
const mdcList = new MDCList(component);
|
|
1298
|
+
this._mdcComponent = mdcList;
|
|
1299
|
+
mdcList.selectedIndex = this._selectedIndex;
|
|
1300
|
+
break;
|
|
1301
|
+
case InputType.SELECT:
|
|
1302
|
+
const mdcSelect = new MDCSelect(component);
|
|
1303
|
+
this._mdcComponent = mdcSelect;
|
|
1304
|
+
const hasValue = (this.value !== null && this.value !== undefined);
|
|
1305
|
+
if (!hasValue) {
|
|
1306
|
+
mdcSelect.selectedIndex = -1; // Without this first option will be shown as selected
|
|
1307
|
+
}
|
|
1308
|
+
if (this.multiple) {
|
|
1309
|
+
// To make multiple select work then override the adapter getSelectedIndex
|
|
1310
|
+
this._mdcComponent.foundation.adapter.getSelectedIndex = () => {
|
|
1311
|
+
// Return first item index
|
|
1312
|
+
if (!Array.isArray(this.value) || this.value.length === 0) {
|
|
1313
|
+
return -1;
|
|
1314
|
+
}
|
|
1315
|
+
const firstSelected = this.value[0];
|
|
1316
|
+
const items = this._mdcComponent.foundation.adapter.getMenuItemValues();
|
|
1317
|
+
return items.indexOf(firstSelected);
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
mdcSelect.useDefaultValidation = !this.multiple;
|
|
1321
|
+
mdcSelect.valid = !this.required || (!this.multiple && mdcSelect.valid) || (this.multiple && Array.isArray(this.value) && this.value.length > 0);
|
|
1322
|
+
const selectedText = this.getSelectedTextValue();
|
|
1323
|
+
this._mdcComponent.foundation.adapter.setSelectedText(selectedText);
|
|
1324
|
+
this._mdcComponent.foundation.adapter.floatLabel(!!selectedText);
|
|
1325
|
+
// Set width of fixed select menu to match the component width
|
|
1326
|
+
// Using an observer to prevent forced reflow / DOM measurements; prevents blocking the thread
|
|
1327
|
+
if (!this._menuObserver) {
|
|
1328
|
+
this._menuObserver = new IntersectionObserver((entries, observer) => {
|
|
1329
|
+
var _a, _b;
|
|
1330
|
+
if (entries[0].target.style.minWidth != (((_a = entries[0].target.parentElement) === null || _a === void 0 ? void 0 : _a.clientWidth) + "px")) {
|
|
1331
|
+
entries[0].target.style.minWidth = ((_b = entries[0].target.parentElement) === null || _b === void 0 ? void 0 : _b.clientWidth) + "px";
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
this._menuObserver.observe(this.shadowRoot.getElementById("mdc-select-menu"));
|
|
1335
|
+
}
|
|
1336
|
+
// This overrides the standard mdc menu body click capture handler as it doesn't work with webcomponents
|
|
1337
|
+
const searchable = (this.searchProvider !== undefined);
|
|
1338
|
+
const multi = this.multiple;
|
|
1339
|
+
mdcSelect.menu.menuSurface_.foundation.handleBodyClick = function (evt) {
|
|
1340
|
+
const el = evt.composedPath()[0]; // Use composed path not evt target to work with webcomponents
|
|
1341
|
+
if (this.adapter.isElementInContainer(el)) {
|
|
1342
|
+
if (!searchable) {
|
|
1343
|
+
return; // Normal select menu closes automatically, so abort
|
|
1344
|
+
}
|
|
1345
|
+
// if searchable, we manually close the menu when clicking a list item.
|
|
1346
|
+
// However, if something else than a list item (for example the search field) is clicked, it should not close, so abort.
|
|
1347
|
+
else if (el instanceof Element && !el.className.includes('mdc-list-item')) {
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
else if (multi) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
mdcSelect.menu.menuSurface_.close();
|
|
1355
|
+
};
|
|
1356
|
+
break;
|
|
1357
|
+
case InputType.RADIO:
|
|
1358
|
+
case InputType.CHECKBOX_LIST:
|
|
1359
|
+
case InputType.COLOUR:
|
|
1360
|
+
break;
|
|
1361
|
+
case InputType.BUTTON:
|
|
1362
|
+
case InputType.BUTTON_MOMENTARY:
|
|
1363
|
+
const isIconButton = !this.action && !this.label;
|
|
1364
|
+
const ripple = new MDCRipple(component);
|
|
1365
|
+
if (isIconButton) {
|
|
1366
|
+
ripple.unbounded = true;
|
|
1367
|
+
}
|
|
1368
|
+
this._mdcComponent = ripple;
|
|
1369
|
+
break;
|
|
1370
|
+
case InputType.BUTTON_TOGGLE:
|
|
1371
|
+
this._mdcComponent = new MDCIconButtonToggle(component);
|
|
1372
|
+
break;
|
|
1373
|
+
case InputType.CHECKBOX:
|
|
1374
|
+
this._mdcComponent = new MDCCheckbox(component);
|
|
1375
|
+
const field = this.shadowRoot.getElementById("field");
|
|
1376
|
+
if (field) {
|
|
1377
|
+
const mdcField = new MDCFormField(field);
|
|
1378
|
+
mdcField.input = this._mdcComponent;
|
|
1379
|
+
this._mdcComponent2 = mdcField;
|
|
1380
|
+
}
|
|
1381
|
+
break;
|
|
1382
|
+
case InputType.SWITCH:
|
|
1383
|
+
this._mdcComponent = new MDCSwitch(component);
|
|
1384
|
+
break;
|
|
1385
|
+
case InputType.RANGE:
|
|
1386
|
+
this._mdcComponent = new MDCSlider(component);
|
|
1387
|
+
const numberComponent = this.shadowRoot.getElementById("number");
|
|
1388
|
+
if (numberComponent) {
|
|
1389
|
+
const numberField = new MDCTextField(numberComponent);
|
|
1390
|
+
numberField.useNativeValidation = false;
|
|
1391
|
+
this._mdcComponent2 = numberField;
|
|
1392
|
+
}
|
|
1393
|
+
break;
|
|
1394
|
+
default:
|
|
1395
|
+
const textField = new MDCTextField(component);
|
|
1396
|
+
textField.useNativeValidation = false;
|
|
1397
|
+
this._mdcComponent = textField;
|
|
1398
|
+
break;
|
|
1399
|
+
}
|
|
1400
|
+
if (this._mdcComponent && this.focused && typeof (this._mdcComponent.focus) === "function") {
|
|
1401
|
+
this._mdcComponent.focus();
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
else {
|
|
1406
|
+
// some components need to be kept in sync with the DOM
|
|
1407
|
+
if (this.type === InputType.SELECT && this._mdcComponent) {
|
|
1408
|
+
if (_changedProperties.has("options")) {
|
|
1409
|
+
this._mdcComponent.layoutOptions(); // has big impact on performance when the MDCSelect list is large.
|
|
1410
|
+
}
|
|
1411
|
+
this._mdcComponent.disabled = !!(this.disabled || this.readonly);
|
|
1412
|
+
this._mdcComponent.useDefaultValidation = !this.multiple;
|
|
1413
|
+
this._mdcComponent.valid = !this.required || (!this.multiple && this._mdcComponent.valid) || (this.multiple && Array.isArray(this.value) && this.value.length > 0);
|
|
1414
|
+
const selectedText = this.getSelectedTextValue();
|
|
1415
|
+
this._mdcComponent.foundation.adapter.setSelectedText(selectedText);
|
|
1416
|
+
this._mdcComponent.foundation.adapter.floatLabel(!!selectedText);
|
|
1417
|
+
}
|
|
1418
|
+
else if (this.type === InputType.RANGE && this._mdcComponent) {
|
|
1419
|
+
const slider = this._mdcComponent;
|
|
1420
|
+
slider.setDisabled(this.disabled || this.readonly);
|
|
1421
|
+
// slider.getDefaultFoundation(). getDefaultFoundation()..getMax() = this.min;
|
|
1422
|
+
// slider.max = this.max;
|
|
1423
|
+
slider.setValue(this.value);
|
|
1424
|
+
}
|
|
1425
|
+
else if (this.type === InputType.SWITCH && this._mdcComponent) {
|
|
1426
|
+
const swtch = this._mdcComponent;
|
|
1427
|
+
swtch.checked = this.value;
|
|
1428
|
+
}
|
|
1429
|
+
else if (this.type === InputType.CHECKBOX && this._mdcComponent) {
|
|
1430
|
+
const checkbox = this._mdcComponent;
|
|
1431
|
+
checkbox.checked = !!this.value;
|
|
1432
|
+
checkbox.disabled = !!(this.disabled || this.readonly);
|
|
1433
|
+
}
|
|
1434
|
+
if (this._mdcComponent) {
|
|
1435
|
+
this._mdcComponent.required = !!this.required;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
if (_changedProperties.has("label")) {
|
|
1439
|
+
(_b = (_a = this._mdcComponent) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.call(_a); // Adjusts the dimensions and positions for all sub-elements.
|
|
1440
|
+
}
|
|
1441
|
+
if (this.autoValidate) {
|
|
1442
|
+
this.reportValidity();
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
renderOutlined(labelTemplate) {
|
|
1446
|
+
return html `
|
|
1447
|
+
<span class="mdc-notched-outline">
|
|
1448
|
+
<span class="mdc-notched-outline__leading"></span>
|
|
1449
|
+
${labelTemplate ? html `
|
|
1450
|
+
<span class="mdc-notched-outline__notch">
|
|
1451
|
+
${labelTemplate}
|
|
1452
|
+
</span>
|
|
1453
|
+
` : ``}
|
|
1454
|
+
<span class="mdc-notched-outline__trailing"></span>
|
|
1455
|
+
</span>
|
|
1456
|
+
`;
|
|
1457
|
+
}
|
|
1458
|
+
setCustomValidity(msg) {
|
|
1459
|
+
this.errorMessage = msg;
|
|
1460
|
+
const elem = this.shadowRoot.getElementById("elem");
|
|
1461
|
+
if (elem && elem.setCustomValidity) {
|
|
1462
|
+
elem.setCustomValidity(msg !== null && msg !== void 0 ? msg : "");
|
|
1463
|
+
}
|
|
1464
|
+
this.reportValidity();
|
|
1465
|
+
}
|
|
1466
|
+
checkValidity() {
|
|
1467
|
+
const elem = this.shadowRoot.getElementById("elem");
|
|
1468
|
+
let valid = true;
|
|
1469
|
+
if (elem && elem.validity) {
|
|
1470
|
+
const nativeValidity = elem.validity;
|
|
1471
|
+
valid = nativeValidity.valid;
|
|
1472
|
+
}
|
|
1473
|
+
if (valid && (this.type === InputType.JSON || this.type === InputType.JSON_OBJECT)) {
|
|
1474
|
+
// JSON needs special validation - if no text value but this.value then parsing failed
|
|
1475
|
+
if (this.value !== undefined && this.value !== null && this._mdcComponent.value === "") {
|
|
1476
|
+
valid = false;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return valid;
|
|
1480
|
+
}
|
|
1481
|
+
reportValidity() {
|
|
1482
|
+
const isValid = this.checkValidity();
|
|
1483
|
+
this.isUiValid = isValid;
|
|
1484
|
+
if (this._mdcComponent) {
|
|
1485
|
+
this._mdcComponent.valid = isValid;
|
|
1486
|
+
}
|
|
1487
|
+
return isValid;
|
|
1488
|
+
}
|
|
1489
|
+
onValueChange(elem, newValue, enterPressed) {
|
|
1490
|
+
var _a, _b;
|
|
1491
|
+
let previousValue = this.value;
|
|
1492
|
+
let errorMsg;
|
|
1493
|
+
if (newValue === "undefined") {
|
|
1494
|
+
previousValue = null;
|
|
1495
|
+
newValue = undefined;
|
|
1496
|
+
}
|
|
1497
|
+
if (newValue === "null") {
|
|
1498
|
+
previousValue = undefined;
|
|
1499
|
+
newValue = null;
|
|
1500
|
+
}
|
|
1501
|
+
if (typeof (newValue) === "string") {
|
|
1502
|
+
switch (this.type) {
|
|
1503
|
+
case InputType.CHECKBOX:
|
|
1504
|
+
case InputType.SWITCH:
|
|
1505
|
+
newValue = newValue === "on";
|
|
1506
|
+
break;
|
|
1507
|
+
case InputType.JSON:
|
|
1508
|
+
case InputType.JSON_OBJECT:
|
|
1509
|
+
case InputType.NUMBER:
|
|
1510
|
+
case InputType.RANGE:
|
|
1511
|
+
if (newValue === "") {
|
|
1512
|
+
newValue = null;
|
|
1513
|
+
}
|
|
1514
|
+
else {
|
|
1515
|
+
try {
|
|
1516
|
+
newValue = JSON.parse(newValue);
|
|
1517
|
+
if (this.type === InputType.JSON_OBJECT && (typeof newValue !== 'object' || Array.isArray(newValue))) {
|
|
1518
|
+
newValue = this.value;
|
|
1519
|
+
errorMsg = i18next.t("validation.invalidJSON");
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
catch (e) {
|
|
1523
|
+
newValue = this.value;
|
|
1524
|
+
errorMsg = this.type === InputType.JSON || this.type == InputType.JSON_OBJECT ? i18next.t("validation.invalidJSON") : i18next.t("validation.invalidNumber");
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
break;
|
|
1528
|
+
case InputType.DATETIME:
|
|
1529
|
+
if (newValue === "") {
|
|
1530
|
+
newValue = null;
|
|
1531
|
+
}
|
|
1532
|
+
else {
|
|
1533
|
+
try {
|
|
1534
|
+
newValue = Date.parse(newValue);
|
|
1535
|
+
}
|
|
1536
|
+
catch (e) {
|
|
1537
|
+
newValue = this.value;
|
|
1538
|
+
errorMsg = i18next.t("validation.invalidDate");
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
this.value = newValue;
|
|
1545
|
+
this.setCustomValidity(errorMsg);
|
|
1546
|
+
this.reportValidity();
|
|
1547
|
+
if (this.type !== InputType.CHECKBOX_LIST && newValue !== previousValue) {
|
|
1548
|
+
if (this.type === InputType.RANGE) {
|
|
1549
|
+
this._mdcComponent.setValue(newValue);
|
|
1550
|
+
if (this._mdcComponent2) {
|
|
1551
|
+
this._mdcComponent2.value = newValue;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
this.dispatchEvent(new OrInputChangedEvent(this.value, previousValue, enterPressed));
|
|
1555
|
+
}
|
|
1556
|
+
// Reset search if value has been selected
|
|
1557
|
+
if (this.searchProvider != undefined && this.type === InputType.SELECT) {
|
|
1558
|
+
const searchableElement = (_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('select-searchable')) === null || _b === void 0 ? void 0 : _b.children[1];
|
|
1559
|
+
if (searchableElement) {
|
|
1560
|
+
this.searchableValue = undefined;
|
|
1561
|
+
searchableElement.value = "";
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
if (this.type === InputType.CHECKBOX_LIST && !Util.objectsEqual(newValue, previousValue, true)) {
|
|
1565
|
+
this.dispatchEvent(new OrInputChangedEvent(newValue, previousValue, enterPressed));
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
get valid() {
|
|
1569
|
+
const elem = this.shadowRoot.getElementById("elem");
|
|
1570
|
+
if (elem && elem.checkValidity) {
|
|
1571
|
+
return elem.checkValidity();
|
|
1572
|
+
}
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
get currentValue() {
|
|
1576
|
+
const elem = this.shadowRoot.getElementById("elem");
|
|
1577
|
+
if (elem && elem.value) {
|
|
1578
|
+
return elem.value;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
resolveOptions(options) {
|
|
1582
|
+
let resolved;
|
|
1583
|
+
if (options && options.length > 0) {
|
|
1584
|
+
resolved = options.map(opt => {
|
|
1585
|
+
if (Array.isArray(opt)) {
|
|
1586
|
+
return opt;
|
|
1587
|
+
}
|
|
1588
|
+
else {
|
|
1589
|
+
const optStr = "" + opt;
|
|
1590
|
+
return [opt, i18next.t(optStr, { defaultValue: Util.camelCaseToSentenceCase(optStr) })];
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
return resolved;
|
|
1595
|
+
}
|
|
1596
|
+
getSelectedTextValue(options) {
|
|
1597
|
+
const value = this.value;
|
|
1598
|
+
const values = Array.isArray(value) ? value : value != null ? [value] : undefined;
|
|
1599
|
+
if (!values) {
|
|
1600
|
+
return "";
|
|
1601
|
+
}
|
|
1602
|
+
const opts = options || this.resolveOptions(this.options);
|
|
1603
|
+
return !opts || !values ? "" : values.map(v => opts.find(([optValue, optDisplay], index) => v === optValue)).map((opt) => opt ? opt[1] : "").join(", ");
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
__decorate([
|
|
1607
|
+
property({ type: Boolean })
|
|
1608
|
+
], OrMwcInput.prototype, "focused", void 0);
|
|
1609
|
+
__decorate([
|
|
1610
|
+
property()
|
|
1611
|
+
], OrMwcInput.prototype, "value", void 0);
|
|
1612
|
+
__decorate([
|
|
1613
|
+
property({ type: String })
|
|
1614
|
+
], OrMwcInput.prototype, "type", void 0);
|
|
1615
|
+
__decorate([
|
|
1616
|
+
property({ type: String })
|
|
1617
|
+
], OrMwcInput.prototype, "name", void 0);
|
|
1618
|
+
__decorate([
|
|
1619
|
+
property({ type: Boolean })
|
|
1620
|
+
], OrMwcInput.prototype, "readonly", void 0);
|
|
1621
|
+
__decorate([
|
|
1622
|
+
property({ type: Boolean })
|
|
1623
|
+
], OrMwcInput.prototype, "required", void 0);
|
|
1624
|
+
__decorate([
|
|
1625
|
+
property()
|
|
1626
|
+
], OrMwcInput.prototype, "max", void 0);
|
|
1627
|
+
__decorate([
|
|
1628
|
+
property()
|
|
1629
|
+
], OrMwcInput.prototype, "min", void 0);
|
|
1630
|
+
__decorate([
|
|
1631
|
+
property({ type: Number })
|
|
1632
|
+
], OrMwcInput.prototype, "step", void 0);
|
|
1633
|
+
__decorate([
|
|
1634
|
+
property({ type: Boolean })
|
|
1635
|
+
], OrMwcInput.prototype, "checked", void 0);
|
|
1636
|
+
__decorate([
|
|
1637
|
+
property({ type: Boolean })
|
|
1638
|
+
], OrMwcInput.prototype, "indeterminate", void 0);
|
|
1639
|
+
__decorate([
|
|
1640
|
+
property({ type: Number })
|
|
1641
|
+
], OrMwcInput.prototype, "maxLength", void 0);
|
|
1642
|
+
__decorate([
|
|
1643
|
+
property({ type: Number })
|
|
1644
|
+
], OrMwcInput.prototype, "minLength", void 0);
|
|
1645
|
+
__decorate([
|
|
1646
|
+
property({ type: Number })
|
|
1647
|
+
], OrMwcInput.prototype, "rows", void 0);
|
|
1648
|
+
__decorate([
|
|
1649
|
+
property({ type: Number })
|
|
1650
|
+
], OrMwcInput.prototype, "cols", void 0);
|
|
1651
|
+
__decorate([
|
|
1652
|
+
property({ type: Boolean })
|
|
1653
|
+
], OrMwcInput.prototype, "multiple", void 0);
|
|
1654
|
+
__decorate([
|
|
1655
|
+
property({ type: String, attribute: true, reflect: false })
|
|
1656
|
+
], OrMwcInput.prototype, "pattern", void 0);
|
|
1657
|
+
__decorate([
|
|
1658
|
+
property({ type: String })
|
|
1659
|
+
], OrMwcInput.prototype, "placeHolder", void 0);
|
|
1660
|
+
__decorate([
|
|
1661
|
+
property({ type: Array })
|
|
1662
|
+
], OrMwcInput.prototype, "options", void 0);
|
|
1663
|
+
__decorate([
|
|
1664
|
+
property({ type: Boolean })
|
|
1665
|
+
], OrMwcInput.prototype, "autoSelect", void 0);
|
|
1666
|
+
__decorate([
|
|
1667
|
+
property({ type: Object })
|
|
1668
|
+
], OrMwcInput.prototype, "searchProvider", void 0);
|
|
1669
|
+
__decorate([
|
|
1670
|
+
property({ type: String })
|
|
1671
|
+
], OrMwcInput.prototype, "searchLabel", void 0);
|
|
1672
|
+
__decorate([
|
|
1673
|
+
property({ type: String })
|
|
1674
|
+
], OrMwcInput.prototype, "icon", void 0);
|
|
1675
|
+
__decorate([
|
|
1676
|
+
property({ type: String })
|
|
1677
|
+
], OrMwcInput.prototype, "iconColor", void 0);
|
|
1678
|
+
__decorate([
|
|
1679
|
+
property({ type: String })
|
|
1680
|
+
], OrMwcInput.prototype, "iconOn", void 0);
|
|
1681
|
+
__decorate([
|
|
1682
|
+
property({ type: String })
|
|
1683
|
+
], OrMwcInput.prototype, "iconTrailing", void 0);
|
|
1684
|
+
__decorate([
|
|
1685
|
+
property({ type: Boolean })
|
|
1686
|
+
], OrMwcInput.prototype, "compact", void 0);
|
|
1687
|
+
__decorate([
|
|
1688
|
+
property({ type: Boolean })
|
|
1689
|
+
], OrMwcInput.prototype, "comfortable", void 0);
|
|
1690
|
+
__decorate([
|
|
1691
|
+
property({ type: Boolean })
|
|
1692
|
+
], OrMwcInput.prototype, "raised", void 0);
|
|
1693
|
+
__decorate([
|
|
1694
|
+
property({ type: Boolean })
|
|
1695
|
+
], OrMwcInput.prototype, "action", void 0);
|
|
1696
|
+
__decorate([
|
|
1697
|
+
property({ type: Boolean })
|
|
1698
|
+
], OrMwcInput.prototype, "unElevated", void 0);
|
|
1699
|
+
__decorate([
|
|
1700
|
+
property({ type: Boolean })
|
|
1701
|
+
], OrMwcInput.prototype, "outlined", void 0);
|
|
1702
|
+
__decorate([
|
|
1703
|
+
property({ type: Boolean })
|
|
1704
|
+
], OrMwcInput.prototype, "rounded", void 0);
|
|
1705
|
+
__decorate([
|
|
1706
|
+
property({ type: Object })
|
|
1707
|
+
], OrMwcInput.prototype, "format", void 0);
|
|
1708
|
+
__decorate([
|
|
1709
|
+
property({ type: Boolean })
|
|
1710
|
+
], OrMwcInput.prototype, "disableSliderNumberInput", void 0);
|
|
1711
|
+
__decorate([
|
|
1712
|
+
property({ type: Boolean })
|
|
1713
|
+
], OrMwcInput.prototype, "fullWidth", void 0);
|
|
1714
|
+
__decorate([
|
|
1715
|
+
property({ type: String })
|
|
1716
|
+
], OrMwcInput.prototype, "helperText", void 0);
|
|
1717
|
+
__decorate([
|
|
1718
|
+
property({ type: Boolean })
|
|
1719
|
+
], OrMwcInput.prototype, "helperPersistent", void 0);
|
|
1720
|
+
__decorate([
|
|
1721
|
+
property({ type: String, attribute: true })
|
|
1722
|
+
], OrMwcInput.prototype, "validationMessage", void 0);
|
|
1723
|
+
__decorate([
|
|
1724
|
+
property({ type: Boolean })
|
|
1725
|
+
], OrMwcInput.prototype, "autoValidate", void 0);
|
|
1726
|
+
__decorate([
|
|
1727
|
+
property({ type: Boolean })
|
|
1728
|
+
], OrMwcInput.prototype, "charCounter", void 0);
|
|
1729
|
+
__decorate([
|
|
1730
|
+
property({ type: String })
|
|
1731
|
+
], OrMwcInput.prototype, "label", void 0);
|
|
1732
|
+
__decorate([
|
|
1733
|
+
property({ type: Boolean })
|
|
1734
|
+
], OrMwcInput.prototype, "disabled", void 0);
|
|
1735
|
+
__decorate([
|
|
1736
|
+
property({ type: Boolean })
|
|
1737
|
+
], OrMwcInput.prototype, "continuous", void 0);
|
|
1738
|
+
__decorate([
|
|
1739
|
+
property({ type: Boolean })
|
|
1740
|
+
], OrMwcInput.prototype, "resizeVertical", void 0);
|
|
1741
|
+
__decorate([
|
|
1742
|
+
property({ type: Boolean })
|
|
1743
|
+
], OrMwcInput.prototype, "censored", void 0);
|
|
1744
|
+
__decorate([
|
|
1745
|
+
property({ type: Boolean, reflect: true })
|
|
1746
|
+
], OrMwcInput.prototype, "advertised", void 0);
|
|
1747
|
+
__decorate([
|
|
1748
|
+
state()
|
|
1749
|
+
], OrMwcInput.prototype, "isUiValid", void 0);
|
|
1750
|
+
__decorate([
|
|
1751
|
+
state()
|
|
1752
|
+
], OrMwcInput.prototype, "searchableValue", void 0);
|
|
1753
|
+
__decorate([
|
|
1754
|
+
state()
|
|
1755
|
+
], OrMwcInput.prototype, "errorMessage", void 0);
|
|
1756
|
+
OrMwcInput = __decorate([
|
|
1757
|
+
customElement("or-mwc-input")
|
|
1758
|
+
], OrMwcInput);
|
|
1759
|
+
export { OrMwcInput };
|
|
1760
|
+
//# sourceMappingURL=or-mwc-input.js.map
|