@vaadin/field-base 22.0.0-alpha1 → 22.0.0-alpha10

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 (67) hide show
  1. package/index.d.ts +10 -9
  2. package/index.js +10 -9
  3. package/package.json +25 -19
  4. package/src/aria-label-controller.d.ts +11 -0
  5. package/src/aria-label-controller.js +58 -0
  6. package/src/checked-mixin.d.ts +26 -0
  7. package/src/checked-mixin.js +54 -0
  8. package/src/delegate-focus-mixin.d.ts +7 -4
  9. package/src/delegate-focus-mixin.js +154 -72
  10. package/src/delegate-state-mixin.d.ts +23 -0
  11. package/src/delegate-state-mixin.js +125 -0
  12. package/src/field-mixin.d.ts +39 -0
  13. package/src/field-mixin.js +317 -0
  14. package/src/input-constraints-mixin.d.ts +28 -0
  15. package/src/input-constraints-mixin.js +126 -0
  16. package/src/input-control-mixin.d.ts +52 -0
  17. package/src/input-control-mixin.js +170 -0
  18. package/src/input-controller.d.ts +11 -0
  19. package/src/input-controller.js +35 -0
  20. package/src/input-field-mixin.d.ts +2 -22
  21. package/src/input-field-mixin.js +117 -168
  22. package/src/input-mixin.d.ts +22 -6
  23. package/src/input-mixin.js +161 -51
  24. package/src/label-mixin.d.ts +2 -2
  25. package/src/label-mixin.js +74 -60
  26. package/src/pattern-mixin.d.ts +32 -0
  27. package/src/pattern-mixin.js +72 -0
  28. package/src/shadow-focus-mixin.d.ts +21 -0
  29. package/src/shadow-focus-mixin.js +87 -0
  30. package/src/slot-controller.d.ts +8 -0
  31. package/src/slot-controller.js +36 -0
  32. package/src/slot-label-mixin.d.ts +20 -0
  33. package/src/slot-label-mixin.js +38 -0
  34. package/src/slot-styles-mixin.d.ts +24 -0
  35. package/src/slot-styles-mixin.js +76 -0
  36. package/src/slot-target-mixin.d.ts +32 -0
  37. package/src/slot-target-mixin.js +110 -0
  38. package/src/styles/clear-button-styles.d.ts +8 -0
  39. package/src/styles/clear-button-styles.js +21 -0
  40. package/src/styles/field-shared-styles.d.ts +8 -0
  41. package/src/styles/field-shared-styles.js +29 -0
  42. package/src/styles/input-field-container-styles.d.ts +8 -0
  43. package/src/styles/input-field-container-styles.js +16 -0
  44. package/src/styles/input-field-shared-styles.d.ts +8 -0
  45. package/src/styles/input-field-shared-styles.js +10 -0
  46. package/src/text-area-controller.d.ts +11 -0
  47. package/src/text-area-controller.js +38 -0
  48. package/src/validate-mixin.d.ts +1 -9
  49. package/src/validate-mixin.js +43 -118
  50. package/src/clear-button-mixin.d.ts +0 -32
  51. package/src/clear-button-mixin.js +0 -87
  52. package/src/disabled-mixin.d.ts +0 -23
  53. package/src/disabled-mixin.js +0 -48
  54. package/src/field-aria-mixin.d.ts +0 -24
  55. package/src/field-aria-mixin.js +0 -61
  56. package/src/focus-mixin.d.ts +0 -33
  57. package/src/focus-mixin.js +0 -104
  58. package/src/helper-text-mixin.d.ts +0 -24
  59. package/src/helper-text-mixin.js +0 -109
  60. package/src/input-aria-mixin.d.ts +0 -20
  61. package/src/input-aria-mixin.js +0 -69
  62. package/src/input-props-mixin.d.ts +0 -40
  63. package/src/input-props-mixin.js +0 -106
  64. package/src/slot-mixin.d.ts +0 -23
  65. package/src/slot-mixin.js +0 -55
  66. package/src/text-field-mixin.d.ts +0 -47
  67. package/src/text-field-mixin.js +0 -125
@@ -1,106 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
- import { InputAriaMixin } from './input-aria-mixin.js';
8
- import { ValidateMixin } from './validate-mixin.js';
9
-
10
- const InputPropsMixinImplementation = (superclass) =>
11
- class InputPropsMixinClass extends ValidateMixin(InputAriaMixin(superclass)) {
12
- static get properties() {
13
- return {
14
- /**
15
- * The name of this field.
16
- */
17
- name: {
18
- type: String
19
- },
20
-
21
- /**
22
- * A hint to the user of what can be entered in the field.
23
- */
24
- placeholder: {
25
- type: String
26
- },
27
-
28
- /**
29
- * When present, it specifies that the field is read-only.
30
- */
31
- readonly: {
32
- type: Boolean,
33
- value: false,
34
- reflectToAttribute: true
35
- },
36
-
37
- /**
38
- * The text usually displayed in a tooltip popup when the mouse is over the field.
39
- */
40
- title: {
41
- type: String
42
- }
43
- };
44
- }
45
-
46
- static get hostProps() {
47
- return ['name', 'type', 'placeholder', 'readonly', 'required', 'invalid', 'title'];
48
- }
49
-
50
- /** @protected */
51
- connectedCallback() {
52
- super.connectedCallback();
53
-
54
- if (this._inputNode) {
55
- // Propagate initially defined properties to the slotted input
56
- this._propagateHostAttributes(this.constructor.hostProps.map((attr) => this[attr] || this.getAttribute(attr)));
57
- }
58
- }
59
-
60
- /** @protected */
61
- ready() {
62
- super.ready();
63
-
64
- // create observer dynamically to allow subclasses to override hostProps
65
- this._createMethodObserver(`_hostPropsChanged(${this.constructor.hostProps.join(', ')})`);
66
- }
67
-
68
- /** @private */
69
- _hostPropsChanged(...attributesValues) {
70
- this._propagateHostAttributes(attributesValues);
71
- }
72
-
73
- /** @private */
74
- _propagateHostAttributes(attributesValues) {
75
- const input = this._inputNode;
76
- const attributeNames = this.constructor.hostProps;
77
-
78
- attributeNames.forEach((attr, index) => {
79
- const value = attributesValues[index];
80
- if (attr === 'invalid') {
81
- this._setOrToggleAttribute(attr, value, input);
82
- this._setOrToggleAttribute('aria-invalid', value ? 'true' : false, input);
83
- } else {
84
- this._setOrToggleAttribute(attr, value, input);
85
- }
86
- });
87
- }
88
-
89
- /** @protected */
90
- _setOrToggleAttribute(name, value, node) {
91
- if (!name || !node) {
92
- return;
93
- }
94
-
95
- if (value) {
96
- node.setAttribute(name, typeof value === 'boolean' ? '' : value);
97
- } else {
98
- node.removeAttribute(name);
99
- }
100
- }
101
- };
102
-
103
- /**
104
- * A mixin to forward properties to the native <input> element.
105
- */
106
- export const InputPropsMixin = dedupingMixin(InputPropsMixinImplementation);
@@ -1,23 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * A mixin to provide content for named slots defined by component.
9
- */
10
- declare function SlotMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotMixinConstructor;
11
-
12
- interface SlotMixinConstructor {
13
- new (...args: any[]): SlotMixin;
14
- }
15
-
16
- interface SlotMixin {
17
- /**
18
- * List of named slots to initialize.
19
- */
20
- readonly slots: Record<string, () => HTMLElement>;
21
- }
22
-
23
- export { SlotMixinConstructor, SlotMixin };
package/src/slot-mixin.js DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
-
8
- const SlotMixinImplementation = (superclass) =>
9
- class SlotMixinClass extends superclass {
10
- /**
11
- * List of named slots to initialize.
12
- */
13
- get slots() {
14
- return {};
15
- }
16
-
17
- /** @protected */
18
- connectedCallback() {
19
- super.connectedCallback();
20
- this._connectSlotMixin();
21
- }
22
-
23
- /** @private */
24
- _connectSlotMixin() {
25
- if (this.__isConnectedSlotMixin) {
26
- return;
27
- }
28
-
29
- Object.keys(this.slots).forEach((slotName) => {
30
- // Ignore labels of nested components, if any
31
- const hasContent = this._getDirectSlotChild(slotName) !== undefined;
32
-
33
- if (!hasContent) {
34
- const slotFactory = this.slots[slotName];
35
- const slotContent = slotFactory();
36
- if (slotContent instanceof Element) {
37
- slotContent.setAttribute('slot', slotName);
38
- this.appendChild(slotContent);
39
- }
40
- }
41
- });
42
-
43
- this.__isConnectedSlotMixin = true;
44
- }
45
-
46
- /** @protected */
47
- _getDirectSlotChild(slotName) {
48
- return Array.from(this.children).find((el) => el.slot === slotName);
49
- }
50
- };
51
-
52
- /**
53
- * A mixin to provide content for named slots defined by component.
54
- */
55
- export const SlotMixin = dedupingMixin(SlotMixinImplementation);
@@ -1,47 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { InputFieldMixin } from './input-field-mixin.js';
7
-
8
- /**
9
- * A mixin to provide validation constraints for vaadin-text-field and related components.
10
- */
11
- declare function TextFieldMixin<T extends new (...args: any[]) => {}>(base: T): T & TextFieldMixinConstructor;
12
-
13
- interface TextFieldMixinConstructor {
14
- new (...args: any[]): TextFieldMixin;
15
- }
16
-
17
- interface TextFieldMixin extends InputFieldMixin {
18
- /**
19
- * Maximum number of characters (in Unicode code points) that the user can enter.
20
- */
21
- maxlength: number | null | undefined;
22
-
23
- /**
24
- * Minimum number of characters (in Unicode code points) that the user can enter.
25
- */
26
- minlength: number | null | undefined;
27
-
28
- /**
29
- * A regular expression that the value is checked against.
30
- * The pattern must match the entire value, not just some subset.
31
- */
32
- pattern: string | null | undefined;
33
-
34
- /**
35
- * When set to true, user is prevented from typing a value that
36
- * conflicts with the given `pattern`.
37
- * @attr {boolean} prevent-invalid-input
38
- */
39
- preventInvalidInput: boolean | null | undefined;
40
-
41
- /**
42
- * Returns true if the current input value satisfies all constraints (if any).
43
- */
44
- checkValidity(): boolean;
45
- }
46
-
47
- export { TextFieldMixin, TextFieldMixinConstructor };
@@ -1,125 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
7
- import { timeOut } from '@polymer/polymer/lib/utils/async.js';
8
- import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
9
- import { InputFieldMixin } from './input-field-mixin.js';
10
-
11
- const TextFieldMixinImplementation = (superclass) =>
12
- class TextFieldMixinClass extends InputFieldMixin(superclass) {
13
- static get properties() {
14
- return {
15
- /**
16
- * Maximum number of characters (in Unicode code points) that the user can enter.
17
- */
18
- maxlength: {
19
- type: Number
20
- },
21
-
22
- /**
23
- * Minimum number of characters (in Unicode code points) that the user can enter.
24
- */
25
- minlength: {
26
- type: Number
27
- },
28
-
29
- /**
30
- * A regular expression that the value is checked against.
31
- * The pattern must match the entire value, not just some subset.
32
- */
33
- pattern: {
34
- type: String
35
- },
36
-
37
- /**
38
- * When set to true, user is prevented from typing a value that
39
- * conflicts with the given `pattern`.
40
- * @attr {boolean} prevent-invalid-input
41
- */
42
- preventInvalidInput: {
43
- type: Boolean
44
- }
45
- };
46
- }
47
-
48
- static get hostProps() {
49
- return [...super.hostProps, 'pattern', 'maxlength', 'minlength'];
50
- }
51
-
52
- /** @protected */
53
- ready() {
54
- super.ready();
55
-
56
- this._createConstraintsObserver();
57
- }
58
-
59
- /** @protected */
60
- _createConstraintsObserver() {
61
- // This complex observer needs to be added dynamically instead of using `static get observers()`
62
- // to make it possible to tweak this behavior in classes that apply this mixin.
63
- // An example is `vaadin-email-field` where the pattern is set before defining the observer.
64
- this._createMethodObserver('_constraintsChanged(required, minlength, maxlength, pattern)');
65
- }
66
-
67
- /**
68
- * @param {boolean | undefined} required
69
- * @param {number | undefined} minlength
70
- * @param {number | undefined} maxlength
71
- * @param {string | undefined} maxlength
72
- * @protected
73
- */
74
- _constraintsChanged(required, minlength, maxlength, pattern) {
75
- // Prevent marking field as invalid when setting required state
76
- // or any other constraint before a user has entered the value.
77
- if (!this.invalid) {
78
- return;
79
- }
80
-
81
- if (!required && !minlength && !maxlength && !pattern) {
82
- this.invalid = false;
83
- } else {
84
- this.validate();
85
- }
86
- }
87
-
88
- /**
89
- * @param {Event} e
90
- * @protected
91
- */
92
- _onInput(e) {
93
- if (this.preventInvalidInput) {
94
- const input = this._inputNode;
95
- if (input && input.value.length > 0 && !this.checkValidity()) {
96
- input.value = this.value || '';
97
- // add input-prevented attribute for 200ms
98
- this.setAttribute('input-prevented', '');
99
- this._inputDebouncer = Debouncer.debounce(this._inputDebouncer, timeOut.after(200), () => {
100
- this.removeAttribute('input-prevented');
101
- });
102
- return;
103
- }
104
- }
105
-
106
- super._onInput(e);
107
- }
108
-
109
- /**
110
- * Returns true if the current input value satisfies all constraints (if any)
111
- * @return {boolean}
112
- */
113
- checkValidity() {
114
- if (this.required || this.pattern || this.maxlength || this.minlength) {
115
- return this._inputNode ? this._inputNode.checkValidity() : undefined;
116
- } else {
117
- return !this.invalid;
118
- }
119
- }
120
- };
121
-
122
- /**
123
- * A mixin to provide validation constraints for vaadin-text-field and related components.
124
- */
125
- export const TextFieldMixin = dedupingMixin(TextFieldMixinImplementation);