@everymatrix/general-input 1.10.2 → 1.15.0

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.
Files changed (96) hide show
  1. package/dist/cjs/checkbox-group-input_10.cjs.entry.js +35539 -0
  2. package/dist/cjs/general-input.cjs.entry.js +34 -13
  3. package/dist/cjs/general-input.cjs.js +2 -2
  4. package/dist/cjs/{index-64a5cb7f.js → index-132a0774.js} +119 -6
  5. package/dist/cjs/loader.cjs.js +2 -2
  6. package/dist/cjs/locale.utils-7665b010.js +71 -0
  7. package/dist/cjs/toggle-checkbox-input.cjs.entry.js +85 -0
  8. package/dist/cjs/tooltipIcon-092a795f.js +5 -0
  9. package/dist/collection/collection-manifest.json +3 -1
  10. package/dist/collection/components/checkbox-group-input/checkbox-group-input.css +62 -0
  11. package/dist/collection/components/checkbox-group-input/checkbox-group-input.js +366 -0
  12. package/dist/collection/components/checkbox-input/checkbox-input.css +47 -1
  13. package/dist/collection/components/checkbox-input/checkbox-input.js +143 -16
  14. package/dist/collection/components/date-input/date-input.css +64 -30
  15. package/dist/collection/components/date-input/date-input.js +194 -13
  16. package/dist/collection/components/email-input/email-input.css +63 -28
  17. package/dist/collection/components/email-input/email-input.js +197 -21
  18. package/dist/collection/components/general-input/general-input.js +163 -21
  19. package/dist/collection/components/number-input/number-input.css +65 -30
  20. package/dist/collection/components/number-input/number-input.js +174 -19
  21. package/dist/collection/components/password-input/password-input.css +120 -29
  22. package/dist/collection/components/password-input/password-input.js +341 -25
  23. package/dist/collection/components/radio-input/radio-input.css +22 -1
  24. package/dist/collection/components/radio-input/radio-input.js +89 -10
  25. package/dist/collection/components/select-input/select-input.css +75 -22
  26. package/dist/collection/components/select-input/select-input.js +180 -37
  27. package/dist/collection/components/tel-input/tel-input.css +91 -33
  28. package/dist/collection/components/tel-input/tel-input.js +202 -24
  29. package/dist/collection/components/text-input/text-input.css +63 -28
  30. package/dist/collection/components/text-input/text-input.js +208 -39
  31. package/dist/collection/components/toggle-checkbox-input/toggle-checkbox-input.css +76 -0
  32. package/dist/collection/components/toggle-checkbox-input/toggle-checkbox-input.js +324 -0
  33. package/dist/collection/utils/locale.utils.js +52 -13
  34. package/dist/collection/utils/tooltipIcon.svg +5 -0
  35. package/dist/components/active-mixin.js +975 -0
  36. package/dist/components/checkbox-group-input.d.ts +11 -0
  37. package/dist/components/checkbox-group-input.js +6 -0
  38. package/dist/components/checkbox-group-input2.js +1125 -0
  39. package/dist/components/checkbox-input2.js +62 -12
  40. package/dist/components/date-input2.js +10247 -15
  41. package/dist/components/email-input2.js +98 -21
  42. package/dist/components/field-mixin.js +12712 -0
  43. package/dist/components/general-input.js +1 -118
  44. package/dist/components/general-input2.js +331 -0
  45. package/dist/components/input-field-shared-styles.js +1114 -0
  46. package/dist/components/number-input2.js +92 -16
  47. package/dist/components/password-input2.js +924 -24
  48. package/dist/components/pattern-mixin.js +85 -0
  49. package/dist/components/radio-input2.js +45 -11
  50. package/dist/components/select-input2.js +87 -27
  51. package/dist/components/tel-input2.js +122 -22
  52. package/dist/components/text-input2.js +120 -34
  53. package/dist/components/toggle-checkbox-input.d.ts +11 -0
  54. package/dist/components/toggle-checkbox-input.js +6 -0
  55. package/dist/components/tooltipIcon.js +70 -0
  56. package/dist/components/vaadin-button.js +461 -0
  57. package/dist/components/vaadin-combo-box.js +4329 -0
  58. package/dist/components/virtual-keyboard-controller.js +2658 -0
  59. package/dist/esm/checkbox-group-input_10.entry.js +35526 -0
  60. package/dist/esm/general-input.entry.js +34 -13
  61. package/dist/esm/general-input.js +2 -2
  62. package/dist/esm/{index-df80f936.js → index-db76d5b5.js} +118 -7
  63. package/dist/esm/loader.js +2 -2
  64. package/dist/esm/locale.utils-95ea2605.js +68 -0
  65. package/dist/esm/toggle-checkbox-input.entry.js +81 -0
  66. package/dist/esm/tooltipIcon-99c1c7b7.js +3 -0
  67. package/dist/general-input/general-input.esm.js +1 -1
  68. package/dist/general-input/p-0966f523.entry.js +3581 -0
  69. package/dist/general-input/p-916a1319.entry.js +1 -0
  70. package/dist/general-input/p-b408093e.js +1 -0
  71. package/dist/general-input/p-c2d4d6ac.entry.js +1 -0
  72. package/dist/general-input/p-f4f4ccda.js +1 -0
  73. package/dist/general-input/p-f6132f1d.js +1 -0
  74. package/dist/types/components/checkbox-group-input/checkbox-group-input.d.ts +74 -0
  75. package/dist/types/components/checkbox-input/checkbox-input.d.ts +28 -2
  76. package/dist/types/components/date-input/date-input.d.ts +43 -1
  77. package/dist/types/components/email-input/email-input.d.ts +37 -3
  78. package/dist/types/components/general-input/general-input.d.ts +30 -0
  79. package/dist/types/components/number-input/number-input.d.ts +34 -3
  80. package/dist/types/components/password-input/password-input.d.ts +56 -7
  81. package/dist/types/components/radio-input/radio-input.d.ts +17 -1
  82. package/dist/types/components/select-input/select-input.d.ts +36 -3
  83. package/dist/types/components/tel-input/tel-input.d.ts +40 -5
  84. package/dist/types/components/text-input/text-input.d.ts +84 -0
  85. package/dist/types/components/toggle-checkbox-input/toggle-checkbox-input.d.ts +67 -0
  86. package/dist/types/components.d.ts +568 -9
  87. package/dist/types/utils/locale.utils.d.ts +9 -0
  88. package/dist/types/utils/types.d.ts +41 -9
  89. package/package.json +8 -1
  90. package/dist/cjs/checkbox-input_9.cjs.entry.js +0 -623
  91. package/dist/components/locale.utils.js +0 -29
  92. package/dist/esm/checkbox-input_9.entry.js +0 -611
  93. package/dist/general-input/p-1703fce3.entry.js +0 -1
  94. package/dist/general-input/p-d9f7fa2e.js +0 -1
  95. package/dist/general-input/p-dea0a4ac.entry.js +0 -1
  96. /package/dist/types/Users/{user/workspace/everymatrix → adrian.pripon/Documents/Work}/widgets-stencil/packages/general-input/.stencil/packages/general-input/stencil.config.d.ts +0 -0
@@ -0,0 +1,1114 @@
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
+
3
+ registerStyles(
4
+ 'vaadin-input-container',
5
+ i`
6
+ :host {
7
+ border-radius: var(--lumo-border-radius-m);
8
+ background-color: var(--lumo-contrast-10pct);
9
+ padding: 0 calc(0.375em + var(--lumo-border-radius-m) / 4 - 1px);
10
+ font-weight: 500;
11
+ line-height: 1;
12
+ position: relative;
13
+ cursor: text;
14
+ box-sizing: border-box;
15
+ }
16
+
17
+ /* Used for hover and activation effects */
18
+ :host::after {
19
+ content: '';
20
+ position: absolute;
21
+ top: 0;
22
+ right: 0;
23
+ bottom: 0;
24
+ left: 0;
25
+ border-radius: inherit;
26
+ pointer-events: none;
27
+ background-color: var(--lumo-contrast-50pct);
28
+ opacity: 0;
29
+ transition: transform 0.15s, opacity 0.2s;
30
+ transform-origin: 100% 0;
31
+ }
32
+
33
+ ::slotted(:not([slot$='fix'])) {
34
+ cursor: inherit;
35
+ min-height: var(--lumo-text-field-size, var(--lumo-size-m));
36
+ padding: 0 0.25em;
37
+ --_lumo-text-field-overflow-mask-image: linear-gradient(to left, transparent, #000 1.25em);
38
+ -webkit-mask-image: var(--_lumo-text-field-overflow-mask-image);
39
+ mask-image: var(--_lumo-text-field-overflow-mask-image);
40
+ }
41
+
42
+ /* Read-only */
43
+ :host([readonly]) {
44
+ color: var(--lumo-secondary-text-color);
45
+ background-color: transparent;
46
+ cursor: default;
47
+ }
48
+
49
+ :host([readonly])::after {
50
+ background-color: transparent;
51
+ opacity: 1;
52
+ border: 1px dashed var(--lumo-contrast-30pct);
53
+ }
54
+
55
+ /* Disabled */
56
+ :host([disabled]) {
57
+ background-color: var(--lumo-contrast-5pct);
58
+ }
59
+
60
+ :host([disabled]) ::slotted(*) {
61
+ color: var(--lumo-disabled-text-color);
62
+ -webkit-text-fill-color: var(--lumo-disabled-text-color);
63
+ }
64
+
65
+ /* Invalid */
66
+ :host([invalid]) {
67
+ background-color: var(--lumo-error-color-10pct);
68
+ }
69
+
70
+ :host([invalid])::after {
71
+ background-color: var(--lumo-error-color-50pct);
72
+ }
73
+
74
+ /* Slotted icons */
75
+ ::slotted(iron-icon),
76
+ ::slotted(vaadin-icon) {
77
+ color: var(--lumo-contrast-60pct);
78
+ width: var(--lumo-icon-size-m);
79
+ height: var(--lumo-icon-size-m);
80
+ }
81
+
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:']),
84
+ ::slotted(vaadin-icon[icon^='vaadin:']) {
85
+ padding: 0.25em;
86
+ box-sizing: border-box !important;
87
+ }
88
+
89
+ /* Text align */
90
+ :host([dir='rtl']) ::slotted(:not([slot$='fix'])) {
91
+ --_lumo-text-field-overflow-mask-image: linear-gradient(to right, transparent, #000 1.25em);
92
+ }
93
+
94
+ @-moz-document url-prefix() {
95
+ :host([dir='rtl']) ::slotted(:not([slot$='fix'])) {
96
+ mask-image: var(--_lumo-text-field-overflow-mask-image);
97
+ }
98
+ }
99
+
100
+ :host([theme~='align-left']) ::slotted(:not([slot$='fix'])) {
101
+ text-align: start;
102
+ --_lumo-text-field-overflow-mask-image: none;
103
+ }
104
+
105
+ :host([theme~='align-center']) ::slotted(:not([slot$='fix'])) {
106
+ text-align: center;
107
+ --_lumo-text-field-overflow-mask-image: none;
108
+ }
109
+
110
+ :host([theme~='align-right']) ::slotted(:not([slot$='fix'])) {
111
+ text-align: end;
112
+ --_lumo-text-field-overflow-mask-image: none;
113
+ }
114
+
115
+ @-moz-document url-prefix() {
116
+ /* Firefox is smart enough to align overflowing text to right */
117
+ :host([theme~='align-right']) ::slotted(:not([slot$='fix'])) {
118
+ --_lumo-text-field-overflow-mask-image: linear-gradient(to right, transparent 0.25em, #000 1.5em);
119
+ }
120
+ }
121
+
122
+ @-moz-document url-prefix() {
123
+ /* Firefox is smart enough to align overflowing text to right */
124
+ :host([theme~='align-left']) ::slotted(:not([slot$='fix'])) {
125
+ --_lumo-text-field-overflow-mask-image: linear-gradient(to left, transparent 0.25em, #000 1.5em);
126
+ }
127
+ }
128
+
129
+ /* RTL specific styles */
130
+ :host([dir='rtl'])::after {
131
+ transform-origin: 0% 0;
132
+ }
133
+
134
+ :host([theme~='align-left'][dir='rtl']) ::slotted(:not([slot$='fix'])) {
135
+ --_lumo-text-field-overflow-mask-image: none;
136
+ }
137
+
138
+ :host([theme~='align-center'][dir='rtl']) ::slotted(:not([slot$='fix'])) {
139
+ --_lumo-text-field-overflow-mask-image: none;
140
+ }
141
+
142
+ :host([theme~='align-right'][dir='rtl']) ::slotted(:not([slot$='fix'])) {
143
+ --_lumo-text-field-overflow-mask-image: none;
144
+ }
145
+
146
+ @-moz-document url-prefix() {
147
+ /* Firefox is smart enough to align overflowing text to right */
148
+ :host([theme~='align-right'][dir='rtl']) ::slotted(:not([slot$='fix'])) {
149
+ --_lumo-text-field-overflow-mask-image: linear-gradient(to right, transparent 0.25em, #000 1.5em);
150
+ }
151
+ }
152
+
153
+ @-moz-document url-prefix() {
154
+ /* Firefox is smart enough to align overflowing text to right */
155
+ :host([theme~='align-left'][dir='rtl']) ::slotted(:not([slot$='fix'])) {
156
+ --_lumo-text-field-overflow-mask-image: linear-gradient(to left, transparent 0.25em, #000 1.5em);
157
+ }
158
+ }
159
+ `,
160
+ { moduleId: 'lumo-input-container' },
161
+ );
162
+
163
+ /**
164
+ * @license
165
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
166
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
167
+ */
168
+
169
+ class InputContainer extends ThemableMixin(DirMixin(PolymerElement)) {
170
+ static get is() {
171
+ return 'vaadin-input-container';
172
+ }
173
+
174
+ static get template() {
175
+ return html`
176
+ <style>
177
+ :host {
178
+ display: flex;
179
+ align-items: center;
180
+ flex: 0 1 auto;
181
+ }
182
+
183
+ :host([hidden]) {
184
+ display: none !important;
185
+ }
186
+
187
+ /* Reset the native input styles */
188
+ ::slotted(input) {
189
+ -webkit-appearance: none;
190
+ -moz-appearance: none;
191
+ flex: auto;
192
+ white-space: nowrap;
193
+ overflow: hidden;
194
+ width: 100%;
195
+ height: 100%;
196
+ outline: none;
197
+ margin: 0;
198
+ padding: 0;
199
+ border: 0;
200
+ border-radius: 0;
201
+ min-width: 0;
202
+ font: inherit;
203
+ line-height: normal;
204
+ color: inherit;
205
+ background-color: transparent;
206
+ /* Disable default invalid style in Firefox */
207
+ box-shadow: none;
208
+ }
209
+
210
+ ::slotted(*) {
211
+ flex: none;
212
+ }
213
+
214
+ ::slotted(:is(input, textarea))::placeholder {
215
+ /* Use ::slotted(input:placeholder-shown) in themes to style the placeholder. */
216
+ /* because ::slotted(...)::placeholder does not work in Safari. */
217
+ font: inherit;
218
+ color: inherit;
219
+ /* Override default opacity in Firefox */
220
+ opacity: 1;
221
+ }
222
+ </style>
223
+ <slot name="prefix"></slot>
224
+ <slot></slot>
225
+ <slot name="suffix"></slot>
226
+ `;
227
+ }
228
+
229
+ static get properties() {
230
+ return {
231
+ /**
232
+ * If true, the user cannot interact with this element.
233
+ */
234
+ disabled: {
235
+ type: Boolean,
236
+ reflectToAttribute: true,
237
+ },
238
+
239
+ /**
240
+ * Set to true to make this element read-only.
241
+ */
242
+ readonly: {
243
+ type: Boolean,
244
+ reflectToAttribute: true,
245
+ },
246
+
247
+ /**
248
+ * Set to true when the element is invalid.
249
+ */
250
+ invalid: {
251
+ type: Boolean,
252
+ reflectToAttribute: true,
253
+ },
254
+ };
255
+ }
256
+
257
+ /** @protected */
258
+ ready() {
259
+ super.ready();
260
+
261
+ this.addEventListener('pointerdown', (event) => {
262
+ if (event.target === this) {
263
+ // Prevent direct clicks to the input container from blurring the input
264
+ event.preventDefault();
265
+ }
266
+ });
267
+
268
+ this.addEventListener('click', (event) => {
269
+ if (event.target === this) {
270
+ // The vaadin-input-container element was directly clicked,
271
+ // focus any focusable child element from the default slot
272
+ this.shadowRoot
273
+ .querySelector('slot:not([name])')
274
+ .assignedNodes({ flatten: true })
275
+ .forEach((node) => node.focus && node.focus());
276
+ }
277
+ });
278
+ }
279
+ }
280
+
281
+ customElements.define(InputContainer.is, InputContainer);
282
+
283
+ /**
284
+ * @license
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.
322
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
323
+ */
324
+
325
+ const fieldButton = i`
326
+ [part$='button'] {
327
+ flex: none;
328
+ width: 1em;
329
+ height: 1em;
330
+ line-height: 1;
331
+ font-size: var(--lumo-icon-size-m);
332
+ text-align: center;
333
+ color: var(--lumo-contrast-60pct);
334
+ transition: 0.2s color;
335
+ cursor: var(--lumo-clickable-cursor);
336
+ }
337
+
338
+ [part$='button']:hover {
339
+ color: var(--lumo-contrast-90pct);
340
+ }
341
+
342
+ :host([disabled]) [part$='button'],
343
+ :host([readonly]) [part$='button'] {
344
+ color: var(--lumo-contrast-20pct);
345
+ cursor: default;
346
+ }
347
+
348
+ [part$='button']::before {
349
+ font-family: 'lumo-icons';
350
+ display: block;
351
+ }
352
+ `;
353
+ registerStyles('', fieldButton, { moduleId: 'lumo-field-button' });
354
+
355
+ /**
356
+ * @license
357
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
358
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
359
+ */
360
+
361
+ const inputField = i`
362
+ :host {
363
+ --lumo-text-field-size: var(--lumo-size-m);
364
+ color: var(--lumo-body-text-color);
365
+ font-size: var(--lumo-font-size-m);
366
+ font-family: var(--lumo-font-family);
367
+ -webkit-font-smoothing: antialiased;
368
+ -moz-osx-font-smoothing: grayscale;
369
+ -webkit-tap-highlight-color: transparent;
370
+ padding: var(--lumo-space-xs) 0;
371
+ }
372
+
373
+ :host::before {
374
+ height: var(--lumo-text-field-size);
375
+ box-sizing: border-box;
376
+ display: inline-flex;
377
+ align-items: center;
378
+ }
379
+
380
+ :host([focused]:not([readonly])) [part='label'] {
381
+ color: var(--lumo-primary-text-color);
382
+ }
383
+
384
+ :host([focused]) [part='input-field'] ::slotted(:is(input, textarea)) {
385
+ -webkit-mask-image: none;
386
+ mask-image: none;
387
+ }
388
+
389
+ ::slotted(:is(input, textarea):placeholder-shown) {
390
+ color: var(--lumo-secondary-text-color);
391
+ }
392
+
393
+ /* Hover */
394
+ :host(:hover:not([readonly]):not([focused])) [part='label'] {
395
+ color: var(--lumo-body-text-color);
396
+ }
397
+
398
+ :host(:hover:not([readonly]):not([focused])) [part='input-field']::after {
399
+ opacity: 0.1;
400
+ }
401
+
402
+ /* Touch device adjustment */
403
+ @media (pointer: coarse) {
404
+ :host(:hover:not([readonly]):not([focused])) [part='label'] {
405
+ color: var(--lumo-secondary-text-color);
406
+ }
407
+
408
+ :host(:hover:not([readonly]):not([focused])) [part='input-field']::after {
409
+ opacity: 0;
410
+ }
411
+
412
+ :host(:active:not([readonly]):not([focused])) [part='input-field']::after {
413
+ opacity: 0.2;
414
+ }
415
+ }
416
+
417
+ /* Trigger when not focusing using the keyboard */
418
+ :host([focused]:not([focus-ring]):not([readonly])) [part='input-field']::after {
419
+ transform: scaleX(0);
420
+ transition-duration: 0.15s, 1s;
421
+ }
422
+
423
+ /* Focus-ring */
424
+ :host([focus-ring]) [part='input-field'] {
425
+ box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
426
+ }
427
+
428
+ /* Read-only and disabled */
429
+ :host(:is([readonly], [disabled])) ::slotted(:is(input, textarea):placeholder-shown) {
430
+ opacity: 0;
431
+ }
432
+
433
+ /* Disabled style */
434
+ :host([disabled]) {
435
+ pointer-events: none;
436
+ }
437
+
438
+ :host([disabled]) [part='label'],
439
+ :host([disabled]) [part='input-field'] ::slotted(*) {
440
+ color: var(--lumo-disabled-text-color);
441
+ -webkit-text-fill-color: var(--lumo-disabled-text-color);
442
+ }
443
+
444
+ /* Invalid style */
445
+ :host([invalid][focus-ring]) [part='input-field'] {
446
+ box-shadow: 0 0 0 2px var(--lumo-error-color-50pct);
447
+ }
448
+
449
+ :host([input-prevented]) [part='input-field'] {
450
+ animation: shake 0.15s infinite;
451
+ }
452
+
453
+ @keyframes shake {
454
+ 25% {
455
+ transform: translateX(4px);
456
+ }
457
+ 75% {
458
+ transform: translateX(-4px);
459
+ }
460
+ }
461
+
462
+ /* Small theme */
463
+ :host([theme~='small']) {
464
+ font-size: var(--lumo-font-size-s);
465
+ --lumo-text-field-size: var(--lumo-size-s);
466
+ }
467
+
468
+ :host([theme~='small']) [part='label'] {
469
+ font-size: var(--lumo-font-size-xs);
470
+ }
471
+
472
+ :host([theme~='small']) [part='error-message'] {
473
+ font-size: var(--lumo-font-size-xxs);
474
+ }
475
+
476
+ /* Slotted content */
477
+ [part='input-field'] ::slotted(:not(iron-icon):not(vaadin-icon):not(input):not(textarea)) {
478
+ color: var(--lumo-secondary-text-color);
479
+ font-weight: 400;
480
+ }
481
+
482
+ [part='clear-button']::before {
483
+ content: var(--lumo-icons-cross);
484
+ }
485
+ `;
486
+
487
+ const inputFieldShared$1 = [requiredField, fieldButton, helper, inputField];
488
+
489
+ registerStyles('', inputFieldShared$1, {
490
+ moduleId: 'lumo-input-field-shared-styles',
491
+ });
492
+
493
+ /**
494
+ * @license
495
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
496
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
497
+ */
498
+
499
+ /**
500
+ * A mixin to combine multiple input validation constraints.
501
+ *
502
+ * @polymerMixin
503
+ * @mixes DelegateStateMixin
504
+ * @mixes InputMixin
505
+ * @mixes ValidateMixin
506
+ */
507
+ const InputConstraintsMixin = dedupingMixin(
508
+ (superclass) =>
509
+ class InputConstraintsMixinClass extends DelegateStateMixin(ValidateMixin(InputMixin(superclass))) {
510
+ /**
511
+ * An array of attributes which participate in the input validation.
512
+ * Changing these attributes will cause the input to re-validate.
513
+ *
514
+ * IMPORTANT: The attributes should be properly delegated to the input element
515
+ * from the host using `delegateAttrs` getter (see `DelegateStateMixin`).
516
+ * The `required` attribute is already delegated.
517
+ */
518
+ static get constraints() {
519
+ return ['required'];
520
+ }
521
+
522
+ static get delegateAttrs() {
523
+ return [...super.delegateAttrs, 'required'];
524
+ }
525
+
526
+ /** @protected */
527
+ ready() {
528
+ super.ready();
529
+
530
+ this._createConstraintsObserver();
531
+ }
532
+
533
+ /**
534
+ * Returns true if the current input value satisfies all constraints (if any).
535
+ * @return {boolean}
536
+ */
537
+ checkValidity() {
538
+ if (this.inputElement && this._hasValidConstraints(this.constructor.constraints.map((c) => this[c]))) {
539
+ return this.inputElement.checkValidity();
540
+ }
541
+ return !this.invalid;
542
+ }
543
+
544
+ /**
545
+ * Returns true if some of the provided set of constraints are valid.
546
+ * @param {Array} constraints
547
+ * @return {boolean}
548
+ * @protected
549
+ */
550
+ _hasValidConstraints(constraints) {
551
+ return constraints.some((c) => this.__isValidConstraint(c));
552
+ }
553
+
554
+ /**
555
+ * Override this method to customize setting up constraints observer.
556
+ * @protected
557
+ */
558
+ _createConstraintsObserver() {
559
+ // This complex observer needs to be added dynamically instead of using `static get observers()`
560
+ // to make it possible to tweak this behavior in classes that apply this mixin.
561
+ this._createMethodObserver(`_constraintsChanged(stateTarget, ${this.constructor.constraints.join(', ')})`);
562
+ }
563
+
564
+ /**
565
+ * Override this method to implement custom validation constraints.
566
+ * @param {HTMLElement | undefined} stateTarget
567
+ * @param {unknown[]} constraints
568
+ * @protected
569
+ */
570
+ _constraintsChanged(stateTarget, ...constraints) {
571
+ // The input element's validity cannot be determined until
572
+ // all the necessary constraint attributes aren't set on it.
573
+ if (!stateTarget) {
574
+ return;
575
+ }
576
+
577
+ const hasConstraints = this._hasValidConstraints(constraints);
578
+ const isLastConstraintRemoved = this.__previousHasConstraints && !hasConstraints;
579
+
580
+ if ((this._hasValue || this.invalid) && hasConstraints) {
581
+ this.validate();
582
+ } else if (isLastConstraintRemoved) {
583
+ this._setInvalid(false);
584
+ }
585
+
586
+ this.__previousHasConstraints = hasConstraints;
587
+ }
588
+
589
+ /**
590
+ * Override an event listener inherited from `InputMixin`
591
+ * to capture native `change` event and make sure that
592
+ * a new one is dispatched after validation runs.
593
+ * @param {Event} event
594
+ * @protected
595
+ * @override
596
+ */
597
+ _onChange(event) {
598
+ event.stopPropagation();
599
+
600
+ this.validate();
601
+
602
+ this.dispatchEvent(
603
+ new CustomEvent('change', {
604
+ detail: {
605
+ sourceEvent: event,
606
+ },
607
+ bubbles: event.bubbles,
608
+ cancelable: event.cancelable,
609
+ }),
610
+ );
611
+ }
612
+
613
+ /** @private */
614
+ __isValidConstraint(constraint) {
615
+ // 0 is valid for `minlength` and `maxlength`
616
+ return Boolean(constraint) || constraint === 0;
617
+ }
618
+ },
619
+ );
620
+
621
+ /**
622
+ * @license
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.
700
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
701
+ */
702
+
703
+ /**
704
+ * A mixin to provide shared logic for the editable form input controls.
705
+ *
706
+ * @polymerMixin
707
+ * @mixes DelegateFocusMixin
708
+ * @mixes FieldMixin
709
+ * @mixes InputConstraintsMixin
710
+ * @mixes KeyboardMixin
711
+ * @mixes SlotStylesMixin
712
+ */
713
+ const InputControlMixin = (superclass) =>
714
+ class InputControlMixinClass extends SlotStylesMixin(
715
+ DelegateFocusMixin(InputConstraintsMixin(FieldMixin(KeyboardMixin(superclass)))),
716
+ ) {
717
+ static get properties() {
718
+ return {
719
+ /**
720
+ * A pattern matched against individual characters the user inputs.
721
+ *
722
+ * When set, the field will prevent:
723
+ * - `keydown` events if the entered key doesn't match `/^allowedCharPattern$/`
724
+ * - `paste` events if the pasted text doesn't match `/^allowedCharPattern*$/`
725
+ * - `drop` events if the dropped text doesn't match `/^allowedCharPattern*$/`
726
+ *
727
+ * For example, to allow entering only numbers and minus signs, use:
728
+ * `allowedCharPattern = "[\\d-]"`
729
+ * @attr {string} allowed-char-pattern
730
+ */
731
+ allowedCharPattern: {
732
+ type: String,
733
+ observer: '_allowedCharPatternChanged',
734
+ },
735
+
736
+ /**
737
+ * If true, the input text gets fully selected when the field is focused using click or touch / tap.
738
+ */
739
+ autoselect: {
740
+ type: Boolean,
741
+ value: false,
742
+ },
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
+
754
+ /**
755
+ * The name of this field.
756
+ */
757
+ name: {
758
+ type: String,
759
+ reflectToAttribute: true,
760
+ },
761
+
762
+ /**
763
+ * A hint to the user of what can be entered in the field.
764
+ */
765
+ placeholder: {
766
+ type: String,
767
+ reflectToAttribute: true,
768
+ },
769
+
770
+ /**
771
+ * When present, it specifies that the field is read-only.
772
+ */
773
+ readonly: {
774
+ type: Boolean,
775
+ value: false,
776
+ reflectToAttribute: true,
777
+ },
778
+
779
+ /**
780
+ * The text usually displayed in a tooltip popup when the mouse is over the field.
781
+ */
782
+ title: {
783
+ type: String,
784
+ reflectToAttribute: true,
785
+ },
786
+ };
787
+ }
788
+
789
+ static get delegateAttrs() {
790
+ return [...super.delegateAttrs, 'name', 'type', 'placeholder', 'readonly', 'invalid', 'title'];
791
+ }
792
+
793
+ constructor() {
794
+ super();
795
+
796
+ this._boundOnPaste = this._onPaste.bind(this);
797
+ this._boundOnDrop = this._onDrop.bind(this);
798
+ this._boundOnBeforeInput = this._onBeforeInput.bind(this);
799
+ }
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
+
812
+ /** @protected */
813
+ get slotStyles() {
814
+ // Needed for Safari, where ::slotted(...)::placeholder does not work
815
+ return [
816
+ `
817
+ :is(input[slot='input'], textarea[slot='textarea'])::placeholder {
818
+ font: inherit;
819
+ color: inherit;
820
+ }
821
+ `,
822
+ ];
823
+ }
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
+
855
+ /**
856
+ * Override an event listener from `DelegateFocusMixin`.
857
+ * @param {FocusEvent} event
858
+ * @protected
859
+ * @override
860
+ */
861
+ _onFocus(event) {
862
+ super._onFocus(event);
863
+
864
+ if (this.autoselect && this.inputElement) {
865
+ this.inputElement.select();
866
+ }
867
+ }
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
+
886
+ /**
887
+ * Override an event listener inherited from `InputMixin`
888
+ * to capture native `change` event and make sure that
889
+ * a new one is dispatched after validation runs.
890
+ * @param {Event} event
891
+ * @protected
892
+ * @override
893
+ */
894
+ _onChange(event) {
895
+ event.stopPropagation();
896
+
897
+ this.validate();
898
+
899
+ this.dispatchEvent(
900
+ new CustomEvent('change', {
901
+ detail: {
902
+ sourceEvent: event,
903
+ },
904
+ bubbles: event.bubbles,
905
+ cancelable: event.cancelable,
906
+ }),
907
+ );
908
+ }
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
+
917
+ /**
918
+ * Override a method from `InputMixin`.
919
+ * @param {!HTMLElement} input
920
+ * @protected
921
+ * @override
922
+ */
923
+ _addInputListeners(input) {
924
+ super._addInputListeners(input);
925
+
926
+ input.addEventListener('paste', this._boundOnPaste);
927
+ input.addEventListener('drop', this._boundOnDrop);
928
+ input.addEventListener('beforeinput', this._boundOnBeforeInput);
929
+ }
930
+
931
+ /**
932
+ * Override a method from `InputMixin`.
933
+ * @param {!HTMLElement} input
934
+ * @protected
935
+ * @override
936
+ */
937
+ _removeInputListeners(input) {
938
+ super._removeInputListeners(input);
939
+
940
+ input.removeEventListener('paste', this._boundOnPaste);
941
+ input.removeEventListener('drop', this._boundOnDrop);
942
+ input.removeEventListener('beforeinput', this._boundOnBeforeInput);
943
+ }
944
+
945
+ /**
946
+ * Override an event listener from `KeyboardMixin`.
947
+ * @param {!KeyboardEvent} event
948
+ * @protected
949
+ * @override
950
+ */
951
+ _onKeyDown(event) {
952
+ super._onKeyDown(event);
953
+
954
+ if (this.allowedCharPattern && !this.__shouldAcceptKey(event)) {
955
+ event.preventDefault();
956
+ this._markInputPrevented();
957
+ }
958
+ }
959
+
960
+ /** @protected */
961
+ _markInputPrevented() {
962
+ // Add input-prevented attribute for 200ms
963
+ this.setAttribute('input-prevented', '');
964
+ this._preventInputDebouncer = Debouncer.debounce(this._preventInputDebouncer, timeOut.after(200), () => {
965
+ this.removeAttribute('input-prevented');
966
+ });
967
+ }
968
+
969
+ /** @private */
970
+ __shouldAcceptKey(event) {
971
+ return (
972
+ event.metaKey ||
973
+ event.ctrlKey ||
974
+ !event.key || // Allow typing anything if event.key is not supported
975
+ event.key.length !== 1 || // Allow "Backspace", "ArrowLeft" etc.
976
+ this.__allowedCharRegExp.test(event.key)
977
+ );
978
+ }
979
+
980
+ /** @private */
981
+ _onPaste(e) {
982
+ if (this.allowedCharPattern) {
983
+ const pastedText = e.clipboardData.getData('text');
984
+ if (!this.__allowedTextRegExp.test(pastedText)) {
985
+ e.preventDefault();
986
+ this._markInputPrevented();
987
+ }
988
+ }
989
+ }
990
+
991
+ /** @private */
992
+ _onDrop(e) {
993
+ if (this.allowedCharPattern) {
994
+ const draggedText = e.dataTransfer.getData('text');
995
+ if (!this.__allowedTextRegExp.test(draggedText)) {
996
+ e.preventDefault();
997
+ this._markInputPrevented();
998
+ }
999
+ }
1000
+ }
1001
+
1002
+ /** @private */
1003
+ _onBeforeInput(e) {
1004
+ // The `beforeinput` event covers all the cases for `allowedCharPattern`: keyboard, pasting and dropping,
1005
+ // but it is still experimental technology so we can't rely on it. It's used here just as an additional check,
1006
+ // because it seems to be the only way to detect and prevent specific keys on mobile devices.
1007
+ // See https://github.com/vaadin/vaadin-text-field/issues/429
1008
+ if (this.allowedCharPattern && e.data && !this.__allowedTextRegExp.test(e.data)) {
1009
+ e.preventDefault();
1010
+ this._markInputPrevented();
1011
+ }
1012
+ }
1013
+
1014
+ /** @private */
1015
+ _allowedCharPatternChanged(charPattern) {
1016
+ if (charPattern) {
1017
+ try {
1018
+ this.__allowedCharRegExp = new RegExp(`^${charPattern}$`);
1019
+ this.__allowedTextRegExp = new RegExp(`^${charPattern}*$`);
1020
+ } catch (e) {
1021
+ console.error(e);
1022
+ }
1023
+ }
1024
+ }
1025
+
1026
+ /**
1027
+ * Fired when the user commits a value change.
1028
+ *
1029
+ * @event change
1030
+ */
1031
+
1032
+ /**
1033
+ * Fired when the value is changed by the user: on every typing keystroke,
1034
+ * and the value is cleared using the clear button.
1035
+ *
1036
+ * @event input
1037
+ */
1038
+ };
1039
+
1040
+ /**
1041
+ * @license
1042
+ * Copyright (c) 2021 - 2022 Vaadin Ltd..
1043
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1044
+ */
1045
+
1046
+ const clearButton = i`
1047
+ [part='clear-button'] {
1048
+ display: none;
1049
+ cursor: default;
1050
+ }
1051
+
1052
+ [part='clear-button']::before {
1053
+ content: '✕';
1054
+ }
1055
+
1056
+ :host([clear-button-visible][has-value]:not([disabled]):not([readonly])) [part='clear-button'] {
1057
+ display: block;
1058
+ }
1059
+ `;
1060
+
1061
+ /**
1062
+ * @license
1063
+ * Copyright (c) 2021 - 2022 Vaadin Ltd..
1064
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1065
+ */
1066
+
1067
+ const fieldShared = i`
1068
+ :host {
1069
+ display: inline-flex;
1070
+ outline: none;
1071
+ }
1072
+
1073
+ :host::before {
1074
+ content: '\\2003';
1075
+ width: 0;
1076
+ display: inline-block;
1077
+ /* Size and position this element on the same vertical position as the input-field element
1078
+ to make vertical align for the host element work as expected */
1079
+ }
1080
+
1081
+ :host([hidden]) {
1082
+ display: none !important;
1083
+ }
1084
+
1085
+ :host(:not([has-label])) [part='label'] {
1086
+ display: none;
1087
+ }
1088
+ `;
1089
+
1090
+ /**
1091
+ * @license
1092
+ * Copyright (c) 2021 - 2022 Vaadin Ltd..
1093
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1094
+ */
1095
+
1096
+ const inputFieldContainer = i`
1097
+ [class$='container'] {
1098
+ display: flex;
1099
+ flex-direction: column;
1100
+ min-width: 100%;
1101
+ max-width: 100%;
1102
+ width: var(--vaadin-field-default-width, 12em);
1103
+ }
1104
+ `;
1105
+
1106
+ /**
1107
+ * @license
1108
+ * Copyright (c) 2021 - 2022 Vaadin Ltd..
1109
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1110
+ */
1111
+
1112
+ const inputFieldShared = [fieldShared, inputFieldContainer, clearButton];
1113
+
1114
+ export { InputConstraintsMixin as I, isFirefox as a, isIOS as b, InputControlMixin as c, inputFieldShared as d, isSafari as e, isTouch as f, inputFieldShared$1 as i };