@everymatrix/general-input 1.28.7 → 1.28.8
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/dist/cjs/checkbox-group-input_10.cjs.entry.js +12517 -13047
- package/dist/components/active-mixin.js +6 -6
- package/dist/components/checkbox-group-input2.js +307 -260
- package/dist/components/date-input2.js +2206 -3449
- package/dist/components/field-mixin.js +2512 -2226
- package/dist/components/input-field-shared-styles.js +211 -308
- package/dist/components/password-input2.js +72 -119
- package/dist/components/pattern-mixin.js +85 -0
- package/dist/components/vaadin-button.js +73 -102
- package/dist/components/vaadin-combo-box.js +808 -991
- package/dist/components/virtual-keyboard-controller.js +1768 -1111
- package/dist/esm/checkbox-group-input_10.entry.js +12517 -13047
- package/dist/general-input/general-input.esm.js +1 -1
- package/dist/general-input/p-6958a2a8.entry.js +3581 -0
- package/package.json +1 -1
- package/dist/general-input/p-765941e7.entry.js +0 -3646
- /package/dist/types/Users/{adrian.pripon/Documents/Work → sebastian.strulea/Documents/work}/widgets-stencil/packages/general-input/.stencil/packages/general-input/stencil.config.d.ts +0 -0
|
@@ -1,42 +1,27 @@
|
|
|
1
|
-
import { r as registerStyles, i,
|
|
1
|
+
import { r as registerStyles, i, T as ThemableMixin, A as DirMixin, P as PolymerElement, h as html, j as requiredField, k as helper, d as dedupingMixin, D as DelegateStateMixin, V as ValidateMixin, I as InputMixin, c as DelegateFocusMixin, F as FieldMixin, K as KeyboardMixin, y as Debouncer, z as timeOut } from './field-mixin.js';
|
|
2
2
|
|
|
3
3
|
registerStyles(
|
|
4
4
|
'vaadin-input-container',
|
|
5
5
|
i`
|
|
6
6
|
:host {
|
|
7
|
+
border-radius: var(--lumo-border-radius-m);
|
|
7
8
|
background-color: var(--lumo-contrast-10pct);
|
|
8
|
-
padding: 0 calc(0.375em + var(--
|
|
9
|
+
padding: 0 calc(0.375em + var(--lumo-border-radius-m) / 4 - 1px);
|
|
9
10
|
font-weight: 500;
|
|
10
11
|
line-height: 1;
|
|
11
12
|
position: relative;
|
|
12
13
|
cursor: text;
|
|
13
14
|
box-sizing: border-box;
|
|
14
|
-
border-radius:
|
|
15
|
-
/* See https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius#syntax */
|
|
16
|
-
var(--vaadin-input-field-top-start-radius, var(--_input-container-radius))
|
|
17
|
-
var(--vaadin-input-field-top-end-radius, var(--_input-container-radius))
|
|
18
|
-
var(--vaadin-input-field-bottom-end-radius, var(--_input-container-radius))
|
|
19
|
-
var(--vaadin-input-field-bottom-start-radius, var(--_input-container-radius));
|
|
20
|
-
/* Fallback */
|
|
21
|
-
--_input-container-radius: var(--vaadin-input-field-border-radius, var(--lumo-border-radius-m));
|
|
22
|
-
/* Default field border color */
|
|
23
|
-
--_input-border-color: var(--vaadin-input-field-border-color, var(--lumo-contrast-50pct));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
:host([dir='rtl']) {
|
|
27
|
-
border-radius:
|
|
28
|
-
/* Don't use logical props, see https://github.com/vaadin/vaadin-time-picker/issues/145 */
|
|
29
|
-
var(--vaadin-input-field-top-end-radius, var(--_input-container-radius))
|
|
30
|
-
var(--vaadin-input-field-top-start-radius, var(--_input-container-radius))
|
|
31
|
-
var(--vaadin-input-field-bottom-start-radius, var(--_input-container-radius))
|
|
32
|
-
var(--vaadin-input-field-bottom-end-radius, var(--_input-container-radius));
|
|
33
15
|
}
|
|
34
16
|
|
|
35
17
|
/* Used for hover and activation effects */
|
|
36
18
|
:host::after {
|
|
37
19
|
content: '';
|
|
38
20
|
position: absolute;
|
|
39
|
-
|
|
21
|
+
top: 0;
|
|
22
|
+
right: 0;
|
|
23
|
+
bottom: 0;
|
|
24
|
+
left: 0;
|
|
40
25
|
border-radius: inherit;
|
|
41
26
|
pointer-events: none;
|
|
42
27
|
background-color: var(--lumo-contrast-50pct);
|
|
@@ -87,6 +72,7 @@ registerStyles(
|
|
|
87
72
|
}
|
|
88
73
|
|
|
89
74
|
/* Slotted icons */
|
|
75
|
+
::slotted(iron-icon),
|
|
90
76
|
::slotted(vaadin-icon) {
|
|
91
77
|
color: var(--lumo-contrast-60pct);
|
|
92
78
|
width: var(--lumo-icon-size-m);
|
|
@@ -94,6 +80,7 @@ registerStyles(
|
|
|
94
80
|
}
|
|
95
81
|
|
|
96
82
|
/* Vaadin icons are based on a 16x16 grid (unlike Lumo and Material icons with 24x24), so they look too big by default */
|
|
83
|
+
::slotted(iron-icon[icon^='vaadin:']),
|
|
97
84
|
::slotted(vaadin-icon[icon^='vaadin:']) {
|
|
98
85
|
padding: 0.25em;
|
|
99
86
|
box-sizing: border-box !important;
|
|
@@ -175,16 +162,10 @@ registerStyles(
|
|
|
175
162
|
|
|
176
163
|
/**
|
|
177
164
|
* @license
|
|
178
|
-
* Copyright (c) 2021 -
|
|
165
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
179
166
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
180
167
|
*/
|
|
181
168
|
|
|
182
|
-
/**
|
|
183
|
-
* @customElement
|
|
184
|
-
* @extends HTMLElement
|
|
185
|
-
* @mixes ThemableMixin
|
|
186
|
-
* @mixes DirMixin
|
|
187
|
-
*/
|
|
188
169
|
class InputContainer extends ThemableMixin(DirMixin(PolymerElement)) {
|
|
189
170
|
static get is() {
|
|
190
171
|
return 'vaadin-input-container';
|
|
@@ -197,25 +178,6 @@ class InputContainer extends ThemableMixin(DirMixin(PolymerElement)) {
|
|
|
197
178
|
display: flex;
|
|
198
179
|
align-items: center;
|
|
199
180
|
flex: 0 1 auto;
|
|
200
|
-
border-radius:
|
|
201
|
-
/* See https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius */
|
|
202
|
-
var(--vaadin-input-field-top-start-radius, var(--__border-radius))
|
|
203
|
-
var(--vaadin-input-field-top-end-radius, var(--__border-radius))
|
|
204
|
-
var(--vaadin-input-field-bottom-end-radius, var(--__border-radius))
|
|
205
|
-
var(--vaadin-input-field-bottom-start-radius, var(--__border-radius));
|
|
206
|
-
--_border-radius: var(--vaadin-input-field-border-radius, 0px);
|
|
207
|
-
--_input-border-width: var(--vaadin-input-field-border-width, 0);
|
|
208
|
-
--_input-border-color: var(--vaadin-input-field-border-color, transparent);
|
|
209
|
-
box-shadow: inset 0 0 0 var(--_input-border-width, 0) var(--_input-border-color);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
:host([dir='rtl']) {
|
|
213
|
-
border-radius:
|
|
214
|
-
/* Don't use logical props, see https://github.com/vaadin/vaadin-time-picker/issues/145 */
|
|
215
|
-
var(--vaadin-input-field-top-end-radius, var(--_border-radius))
|
|
216
|
-
var(--vaadin-input-field-top-start-radius, var(--_border-radius))
|
|
217
|
-
var(--vaadin-input-field-bottom-start-radius, var(--_border-radius))
|
|
218
|
-
var(--vaadin-input-field-bottom-end-radius, var(--_border-radius));
|
|
219
181
|
}
|
|
220
182
|
|
|
221
183
|
:host([hidden]) {
|
|
@@ -316,11 +278,47 @@ class InputContainer extends ThemableMixin(DirMixin(PolymerElement)) {
|
|
|
316
278
|
}
|
|
317
279
|
}
|
|
318
280
|
|
|
319
|
-
|
|
281
|
+
customElements.define(InputContainer.is, InputContainer);
|
|
320
282
|
|
|
321
283
|
/**
|
|
322
284
|
* @license
|
|
323
|
-
* Copyright (c)
|
|
285
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
286
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
const testUserAgent = (regexp) => regexp.test(navigator.userAgent);
|
|
290
|
+
|
|
291
|
+
const testPlatform = (regexp) => regexp.test(navigator.platform);
|
|
292
|
+
|
|
293
|
+
const testVendor = (regexp) => regexp.test(navigator.vendor);
|
|
294
|
+
|
|
295
|
+
testUserAgent(/Android/);
|
|
296
|
+
|
|
297
|
+
testUserAgent(/Chrome/) && testVendor(/Google Inc/);
|
|
298
|
+
|
|
299
|
+
const isFirefox = testUserAgent(/Firefox/);
|
|
300
|
+
|
|
301
|
+
// IPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
|
|
302
|
+
const isIPad = testPlatform(/^iPad/) || (testPlatform(/^Mac/) && navigator.maxTouchPoints > 1);
|
|
303
|
+
|
|
304
|
+
const isIPhone = testPlatform(/^iPhone/);
|
|
305
|
+
|
|
306
|
+
const isIOS = isIPhone || isIPad;
|
|
307
|
+
|
|
308
|
+
const isSafari = testUserAgent(/^((?!chrome|android).)*safari/i);
|
|
309
|
+
|
|
310
|
+
const isTouch = (() => {
|
|
311
|
+
try {
|
|
312
|
+
document.createEvent('TouchEvent');
|
|
313
|
+
return true;
|
|
314
|
+
} catch (e) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
})();
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @license
|
|
321
|
+
* Copyright (c) 2017 - 2022 Vaadin Ltd.
|
|
324
322
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
325
323
|
*/
|
|
326
324
|
|
|
@@ -356,7 +354,7 @@ registerStyles('', fieldButton, { moduleId: 'lumo-field-button' });
|
|
|
356
354
|
|
|
357
355
|
/**
|
|
358
356
|
* @license
|
|
359
|
-
* Copyright (c) 2017 -
|
|
357
|
+
* Copyright (c) 2017 - 2022 Vaadin Ltd.
|
|
360
358
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
361
359
|
*/
|
|
362
360
|
|
|
@@ -432,15 +430,9 @@ const inputField = i`
|
|
|
432
430
|
opacity: 0;
|
|
433
431
|
}
|
|
434
432
|
|
|
435
|
-
/* Read-only style */
|
|
436
|
-
:host([readonly]) {
|
|
437
|
-
--vaadin-input-field-border-color: transparent;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
433
|
/* Disabled style */
|
|
441
434
|
:host([disabled]) {
|
|
442
435
|
pointer-events: none;
|
|
443
|
-
--vaadin-input-field-border-color: var(--lumo-contrast-20pct);
|
|
444
436
|
}
|
|
445
437
|
|
|
446
438
|
:host([disabled]) [part='label'],
|
|
@@ -450,10 +442,6 @@ const inputField = i`
|
|
|
450
442
|
}
|
|
451
443
|
|
|
452
444
|
/* Invalid style */
|
|
453
|
-
:host([invalid]) {
|
|
454
|
-
--vaadin-input-field-border-color: var(--lumo-error-color);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
445
|
:host([invalid][focus-ring]) [part='input-field'] {
|
|
458
446
|
box-shadow: 0 0 0 2px var(--lumo-error-color-50pct);
|
|
459
447
|
}
|
|
@@ -486,7 +474,7 @@ const inputField = i`
|
|
|
486
474
|
}
|
|
487
475
|
|
|
488
476
|
/* Slotted content */
|
|
489
|
-
[part='input-field'] ::slotted(:not(vaadin-icon):not(input):not(textarea)) {
|
|
477
|
+
[part='input-field'] ::slotted(:not(iron-icon):not(vaadin-icon):not(input):not(textarea)) {
|
|
490
478
|
color: var(--lumo-secondary-text-color);
|
|
491
479
|
font-weight: 400;
|
|
492
480
|
}
|
|
@@ -504,229 +492,7 @@ registerStyles('', inputFieldShared$1, {
|
|
|
504
492
|
|
|
505
493
|
/**
|
|
506
494
|
* @license
|
|
507
|
-
* Copyright (c) 2021 -
|
|
508
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
509
|
-
*/
|
|
510
|
-
|
|
511
|
-
const testUserAgent = (regexp) => regexp.test(navigator.userAgent);
|
|
512
|
-
|
|
513
|
-
const testPlatform = (regexp) => regexp.test(navigator.platform);
|
|
514
|
-
|
|
515
|
-
const testVendor = (regexp) => regexp.test(navigator.vendor);
|
|
516
|
-
|
|
517
|
-
testUserAgent(/Android/u);
|
|
518
|
-
|
|
519
|
-
testUserAgent(/Chrome/u) && testVendor(/Google Inc/u);
|
|
520
|
-
|
|
521
|
-
const isFirefox = testUserAgent(/Firefox/u);
|
|
522
|
-
|
|
523
|
-
// IPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
|
|
524
|
-
const isIPad = testPlatform(/^iPad/u) || (testPlatform(/^Mac/u) && navigator.maxTouchPoints > 1);
|
|
525
|
-
|
|
526
|
-
const isIPhone = testPlatform(/^iPhone/u);
|
|
527
|
-
|
|
528
|
-
const isIOS = isIPhone || isIPad;
|
|
529
|
-
|
|
530
|
-
const isSafari = testUserAgent(/^((?!chrome|android).)*safari/iu);
|
|
531
|
-
|
|
532
|
-
const isTouch = (() => {
|
|
533
|
-
try {
|
|
534
|
-
document.createEvent('TouchEvent');
|
|
535
|
-
return true;
|
|
536
|
-
} catch (e) {
|
|
537
|
-
return false;
|
|
538
|
-
}
|
|
539
|
-
})();
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* @license
|
|
543
|
-
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
544
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
545
|
-
*/
|
|
546
|
-
|
|
547
|
-
const stylesMap = new WeakMap();
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Get all the styles inserted into root.
|
|
551
|
-
* @param {DocumentOrShadowRoot} root
|
|
552
|
-
* @return {Set<string>}
|
|
553
|
-
*/
|
|
554
|
-
function getRootStyles(root) {
|
|
555
|
-
if (!stylesMap.has(root)) {
|
|
556
|
-
stylesMap.set(root, new Set());
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
return stylesMap.get(root);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Insert styles into the root.
|
|
564
|
-
* @param {string} styles
|
|
565
|
-
* @param {DocumentOrShadowRoot} root
|
|
566
|
-
*/
|
|
567
|
-
function insertStyles(styles, root) {
|
|
568
|
-
const style = document.createElement('style');
|
|
569
|
-
style.textContent = styles;
|
|
570
|
-
|
|
571
|
-
if (root === document) {
|
|
572
|
-
document.head.appendChild(style);
|
|
573
|
-
} else {
|
|
574
|
-
root.insertBefore(style, root.firstChild);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Mixin to insert styles into the outer scope to handle slotted components.
|
|
580
|
-
* This is useful e.g. to hide native `<input type="number">` controls.
|
|
581
|
-
*
|
|
582
|
-
* @polymerMixin
|
|
583
|
-
*/
|
|
584
|
-
const SlotStylesMixin = dedupingMixin(
|
|
585
|
-
(superclass) =>
|
|
586
|
-
class SlotStylesMixinClass extends superclass {
|
|
587
|
-
/**
|
|
588
|
-
* List of styles to insert into root.
|
|
589
|
-
* @protected
|
|
590
|
-
*/
|
|
591
|
-
get slotStyles() {
|
|
592
|
-
return {};
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/** @protected */
|
|
596
|
-
connectedCallback() {
|
|
597
|
-
super.connectedCallback();
|
|
598
|
-
|
|
599
|
-
this.__applySlotStyles();
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
/** @private */
|
|
603
|
-
__applySlotStyles() {
|
|
604
|
-
const root = this.getRootNode();
|
|
605
|
-
const rootStyles = getRootStyles(root);
|
|
606
|
-
|
|
607
|
-
this.slotStyles.forEach((styles) => {
|
|
608
|
-
if (!rootStyles.has(styles)) {
|
|
609
|
-
insertStyles(styles, root);
|
|
610
|
-
rootStyles.add(styles);
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
},
|
|
615
|
-
);
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* @license
|
|
619
|
-
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
620
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
621
|
-
*/
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* A mixin that manages the clear button.
|
|
625
|
-
*
|
|
626
|
-
* @polymerMixin
|
|
627
|
-
* @mixes InputMixin
|
|
628
|
-
* @mixes KeyboardMixin
|
|
629
|
-
*/
|
|
630
|
-
const ClearButtonMixin = (superclass) =>
|
|
631
|
-
class ClearButtonMixinClass extends InputMixin(KeyboardMixin(superclass)) {
|
|
632
|
-
static get properties() {
|
|
633
|
-
return {
|
|
634
|
-
/**
|
|
635
|
-
* Set to true to display the clear icon which clears the input.
|
|
636
|
-
*
|
|
637
|
-
* It is up to the component to choose where to place the clear icon:
|
|
638
|
-
* in the Shadow DOM or in the light DOM. In any way, a reference to
|
|
639
|
-
* the clear icon element should be provided via the `clearElement` getter.
|
|
640
|
-
*
|
|
641
|
-
* @attr {boolean} clear-button-visible
|
|
642
|
-
*/
|
|
643
|
-
clearButtonVisible: {
|
|
644
|
-
type: Boolean,
|
|
645
|
-
reflectToAttribute: true,
|
|
646
|
-
value: false,
|
|
647
|
-
},
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* Any element extending this mixin is required to implement this getter.
|
|
653
|
-
* It returns the reference to the clear button element.
|
|
654
|
-
*
|
|
655
|
-
* @protected
|
|
656
|
-
* @return {Element | null | undefined}
|
|
657
|
-
*/
|
|
658
|
-
get clearElement() {
|
|
659
|
-
console.warn(`Please implement the 'clearElement' property in <${this.localName}>`);
|
|
660
|
-
return null;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/** @protected */
|
|
664
|
-
ready() {
|
|
665
|
-
super.ready();
|
|
666
|
-
|
|
667
|
-
if (this.clearElement) {
|
|
668
|
-
this.clearElement.addEventListener('mousedown', (event) => this._onClearButtonMouseDown(event));
|
|
669
|
-
this.clearElement.addEventListener('click', (event) => this._onClearButtonClick(event));
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* @param {Event} event
|
|
675
|
-
* @protected
|
|
676
|
-
*/
|
|
677
|
-
_onClearButtonClick(event) {
|
|
678
|
-
event.preventDefault();
|
|
679
|
-
this._onClearAction();
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
/**
|
|
683
|
-
* @param {MouseEvent} event
|
|
684
|
-
* @protected
|
|
685
|
-
*/
|
|
686
|
-
_onClearButtonMouseDown(event) {
|
|
687
|
-
event.preventDefault();
|
|
688
|
-
if (!isTouch) {
|
|
689
|
-
this.inputElement.focus();
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Override an event listener inherited from `KeydownMixin` to clear on Esc.
|
|
695
|
-
* Components that extend this mixin can prevent this behavior by overriding
|
|
696
|
-
* this method without calling `super._onEscape` to provide custom logic.
|
|
697
|
-
*
|
|
698
|
-
* @param {KeyboardEvent} event
|
|
699
|
-
* @protected
|
|
700
|
-
* @override
|
|
701
|
-
*/
|
|
702
|
-
_onEscape(event) {
|
|
703
|
-
super._onEscape(event);
|
|
704
|
-
|
|
705
|
-
if (this.clearButtonVisible && !!this.value) {
|
|
706
|
-
event.stopPropagation();
|
|
707
|
-
this._onClearAction();
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Clears the value and dispatches `input` and `change` events
|
|
713
|
-
* on the input element. This method should be called
|
|
714
|
-
* when the clear action originates from the user.
|
|
715
|
-
*
|
|
716
|
-
* @protected
|
|
717
|
-
*/
|
|
718
|
-
_onClearAction() {
|
|
719
|
-
this.clear();
|
|
720
|
-
// Note, according to the HTML spec, the native change event isn't composed
|
|
721
|
-
// while the input event is composed.
|
|
722
|
-
this.inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
723
|
-
this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* @license
|
|
729
|
-
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
495
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
730
496
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
731
497
|
*/
|
|
732
498
|
|
|
@@ -854,7 +620,83 @@ const InputConstraintsMixin = dedupingMixin(
|
|
|
854
620
|
|
|
855
621
|
/**
|
|
856
622
|
* @license
|
|
857
|
-
* Copyright (c) 2021 -
|
|
623
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
624
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
625
|
+
*/
|
|
626
|
+
|
|
627
|
+
const stylesMap = new WeakMap();
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Get all the styles inserted into root.
|
|
631
|
+
* @param {DocumentOrShadowRoot} root
|
|
632
|
+
* @return {Set<string>}
|
|
633
|
+
*/
|
|
634
|
+
function getRootStyles(root) {
|
|
635
|
+
if (!stylesMap.has(root)) {
|
|
636
|
+
stylesMap.set(root, new Set());
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return stylesMap.get(root);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Insert styles into the root.
|
|
644
|
+
* @param {string} styles
|
|
645
|
+
* @param {DocumentOrShadowRoot} root
|
|
646
|
+
*/
|
|
647
|
+
function insertStyles(styles, root) {
|
|
648
|
+
const style = document.createElement('style');
|
|
649
|
+
style.textContent = styles;
|
|
650
|
+
|
|
651
|
+
if (root === document) {
|
|
652
|
+
document.head.appendChild(style);
|
|
653
|
+
} else {
|
|
654
|
+
root.insertBefore(style, root.firstChild);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Mixin to insert styles into the outer scope to handle slotted components.
|
|
660
|
+
* This is useful e.g. to hide native `<input type="number">` controls.
|
|
661
|
+
*
|
|
662
|
+
* @polymerMixin
|
|
663
|
+
*/
|
|
664
|
+
const SlotStylesMixin = dedupingMixin(
|
|
665
|
+
(superclass) =>
|
|
666
|
+
class SlotStylesMixinClass extends superclass {
|
|
667
|
+
/**
|
|
668
|
+
* List of styles to insert into root.
|
|
669
|
+
* @protected
|
|
670
|
+
*/
|
|
671
|
+
get slotStyles() {
|
|
672
|
+
return {};
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** @protected */
|
|
676
|
+
connectedCallback() {
|
|
677
|
+
super.connectedCallback();
|
|
678
|
+
|
|
679
|
+
this.__applySlotStyles();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/** @private */
|
|
683
|
+
__applySlotStyles() {
|
|
684
|
+
const root = this.getRootNode();
|
|
685
|
+
const rootStyles = getRootStyles(root);
|
|
686
|
+
|
|
687
|
+
this.slotStyles.forEach((styles) => {
|
|
688
|
+
if (!rootStyles.has(styles)) {
|
|
689
|
+
insertStyles(styles, root);
|
|
690
|
+
rootStyles.add(styles);
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* @license
|
|
699
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
858
700
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
859
701
|
*/
|
|
860
702
|
|
|
@@ -866,12 +708,11 @@ const InputConstraintsMixin = dedupingMixin(
|
|
|
866
708
|
* @mixes FieldMixin
|
|
867
709
|
* @mixes InputConstraintsMixin
|
|
868
710
|
* @mixes KeyboardMixin
|
|
869
|
-
* @mixes ClearButtonMixin
|
|
870
711
|
* @mixes SlotStylesMixin
|
|
871
712
|
*/
|
|
872
713
|
const InputControlMixin = (superclass) =>
|
|
873
714
|
class InputControlMixinClass extends SlotStylesMixin(
|
|
874
|
-
DelegateFocusMixin(InputConstraintsMixin(FieldMixin(
|
|
715
|
+
DelegateFocusMixin(InputConstraintsMixin(FieldMixin(KeyboardMixin(superclass)))),
|
|
875
716
|
) {
|
|
876
717
|
static get properties() {
|
|
877
718
|
return {
|
|
@@ -900,6 +741,16 @@ const InputControlMixin = (superclass) =>
|
|
|
900
741
|
value: false,
|
|
901
742
|
},
|
|
902
743
|
|
|
744
|
+
/**
|
|
745
|
+
* Set to true to display the clear icon which clears the input.
|
|
746
|
+
* @attr {boolean} clear-button-visible
|
|
747
|
+
*/
|
|
748
|
+
clearButtonVisible: {
|
|
749
|
+
type: Boolean,
|
|
750
|
+
reflectToAttribute: true,
|
|
751
|
+
value: false,
|
|
752
|
+
},
|
|
753
|
+
|
|
903
754
|
/**
|
|
904
755
|
* The name of this field.
|
|
905
756
|
*/
|
|
@@ -947,6 +798,17 @@ const InputControlMixin = (superclass) =>
|
|
|
947
798
|
this._boundOnBeforeInput = this._onBeforeInput.bind(this);
|
|
948
799
|
}
|
|
949
800
|
|
|
801
|
+
/**
|
|
802
|
+
* Any element extending this mixin is required to implement this getter.
|
|
803
|
+
* It returns the reference to the clear button element.
|
|
804
|
+
* @protected
|
|
805
|
+
* @return {Element | null | undefined}
|
|
806
|
+
*/
|
|
807
|
+
get clearElement() {
|
|
808
|
+
console.warn(`Please implement the 'clearElement' property in <${this.localName}>`);
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
|
|
950
812
|
/** @protected */
|
|
951
813
|
get slotStyles() {
|
|
952
814
|
// Needed for Safari, where ::slotted(...)::placeholder does not work
|
|
@@ -960,6 +822,36 @@ const InputControlMixin = (superclass) =>
|
|
|
960
822
|
];
|
|
961
823
|
}
|
|
962
824
|
|
|
825
|
+
/** @protected */
|
|
826
|
+
ready() {
|
|
827
|
+
super.ready();
|
|
828
|
+
|
|
829
|
+
if (this.clearElement) {
|
|
830
|
+
this.clearElement.addEventListener('click', (e) => this._onClearButtonClick(e));
|
|
831
|
+
this.clearElement.addEventListener('mousedown', (e) => this._onClearButtonMouseDown(e));
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* @param {Event} event
|
|
837
|
+
* @protected
|
|
838
|
+
*/
|
|
839
|
+
_onClearButtonClick(event) {
|
|
840
|
+
event.preventDefault();
|
|
841
|
+
this.__clear();
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* @param {Event} event
|
|
846
|
+
* @protected
|
|
847
|
+
*/
|
|
848
|
+
_onClearButtonMouseDown(event) {
|
|
849
|
+
event.preventDefault();
|
|
850
|
+
if (!isTouch) {
|
|
851
|
+
this.inputElement.focus();
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
963
855
|
/**
|
|
964
856
|
* Override an event listener from `DelegateFocusMixin`.
|
|
965
857
|
* @param {FocusEvent} event
|
|
@@ -974,6 +866,23 @@ const InputControlMixin = (superclass) =>
|
|
|
974
866
|
}
|
|
975
867
|
}
|
|
976
868
|
|
|
869
|
+
/**
|
|
870
|
+
* Override an event listener inherited from `KeydownMixin` to clear on Esc.
|
|
871
|
+
* Components that extend this mixin can prevent this behavior by overriding
|
|
872
|
+
* this method without calling `super._onEscape` to provide custom logic.
|
|
873
|
+
* @param {KeyboardEvent} event
|
|
874
|
+
* @protected
|
|
875
|
+
* @override
|
|
876
|
+
*/
|
|
877
|
+
_onEscape(event) {
|
|
878
|
+
super._onEscape(event);
|
|
879
|
+
|
|
880
|
+
if (this.clearButtonVisible && !!this.value) {
|
|
881
|
+
event.stopPropagation();
|
|
882
|
+
this.__clear();
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
977
886
|
/**
|
|
978
887
|
* Override an event listener inherited from `InputMixin`
|
|
979
888
|
* to capture native `change` event and make sure that
|
|
@@ -998,6 +907,13 @@ const InputControlMixin = (superclass) =>
|
|
|
998
907
|
);
|
|
999
908
|
}
|
|
1000
909
|
|
|
910
|
+
/** @private */
|
|
911
|
+
__clear() {
|
|
912
|
+
this.clear();
|
|
913
|
+
this.inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
914
|
+
this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
|
|
915
|
+
}
|
|
916
|
+
|
|
1001
917
|
/**
|
|
1002
918
|
* Override a method from `InputMixin`.
|
|
1003
919
|
* @param {!HTMLElement} input
|
|
@@ -1099,8 +1015,8 @@ const InputControlMixin = (superclass) =>
|
|
|
1099
1015
|
_allowedCharPatternChanged(charPattern) {
|
|
1100
1016
|
if (charPattern) {
|
|
1101
1017
|
try {
|
|
1102
|
-
this.__allowedCharRegExp = new RegExp(`^${charPattern}
|
|
1103
|
-
this.__allowedTextRegExp = new RegExp(`^${charPattern}
|
|
1018
|
+
this.__allowedCharRegExp = new RegExp(`^${charPattern}$`);
|
|
1019
|
+
this.__allowedTextRegExp = new RegExp(`^${charPattern}*$`);
|
|
1104
1020
|
} catch (e) {
|
|
1105
1021
|
console.error(e);
|
|
1106
1022
|
}
|
|
@@ -1123,7 +1039,7 @@ const InputControlMixin = (superclass) =>
|
|
|
1123
1039
|
|
|
1124
1040
|
/**
|
|
1125
1041
|
* @license
|
|
1126
|
-
* Copyright (c) 2021 -
|
|
1042
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd..
|
|
1127
1043
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
1128
1044
|
*/
|
|
1129
1045
|
|
|
@@ -1134,7 +1050,7 @@ const clearButton = i`
|
|
|
1134
1050
|
}
|
|
1135
1051
|
|
|
1136
1052
|
[part='clear-button']::before {
|
|
1137
|
-
content: '
|
|
1053
|
+
content: '✕';
|
|
1138
1054
|
}
|
|
1139
1055
|
|
|
1140
1056
|
:host([clear-button-visible][has-value]:not([disabled]):not([readonly])) [part='clear-button'] {
|
|
@@ -1144,7 +1060,7 @@ const clearButton = i`
|
|
|
1144
1060
|
|
|
1145
1061
|
/**
|
|
1146
1062
|
* @license
|
|
1147
|
-
* Copyright (c) 2021 -
|
|
1063
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd..
|
|
1148
1064
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
1149
1065
|
*/
|
|
1150
1066
|
|
|
@@ -1169,24 +1085,11 @@ const fieldShared = i`
|
|
|
1169
1085
|
:host(:not([has-label])) [part='label'] {
|
|
1170
1086
|
display: none;
|
|
1171
1087
|
}
|
|
1172
|
-
|
|
1173
|
-
@media (forced-colors: active) {
|
|
1174
|
-
:host(:not([readonly])) [part='input-field'] {
|
|
1175
|
-
outline: 1px solid;
|
|
1176
|
-
outline-offset: -1px;
|
|
1177
|
-
}
|
|
1178
|
-
:host([focused]) [part='input-field'] {
|
|
1179
|
-
outline-width: 2px;
|
|
1180
|
-
}
|
|
1181
|
-
:host([disabled]) [part='input-field'] {
|
|
1182
|
-
outline-color: GrayText;
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
1088
|
`;
|
|
1186
1089
|
|
|
1187
1090
|
/**
|
|
1188
1091
|
* @license
|
|
1189
|
-
* Copyright (c) 2021 -
|
|
1092
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd..
|
|
1190
1093
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
1191
1094
|
*/
|
|
1192
1095
|
|
|
@@ -1202,7 +1105,7 @@ const inputFieldContainer = i`
|
|
|
1202
1105
|
|
|
1203
1106
|
/**
|
|
1204
1107
|
* @license
|
|
1205
|
-
* Copyright (c) 2021 -
|
|
1108
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd..
|
|
1206
1109
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
1207
1110
|
*/
|
|
1208
1111
|
|