@vaadin/field-base 23.3.3 → 24.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 (55) hide show
  1. package/index.d.ts +0 -3
  2. package/index.js +0 -3
  3. package/package.json +3 -3
  4. package/src/checked-mixin.d.ts +2 -2
  5. package/src/checked-mixin.js +2 -2
  6. package/src/error-controller.d.ts +3 -8
  7. package/src/error-controller.js +53 -65
  8. package/src/field-aria-controller.d.ts +1 -1
  9. package/src/field-aria-controller.js +11 -11
  10. package/src/field-mixin.d.ts +1 -1
  11. package/src/field-mixin.js +24 -28
  12. package/src/helper-controller.d.ts +3 -5
  13. package/src/helper-controller.js +47 -147
  14. package/src/input-constraints-mixin.d.ts +2 -2
  15. package/src/input-constraints-mixin.js +2 -2
  16. package/src/input-control-mixin.d.ts +3 -3
  17. package/src/input-control-mixin.js +4 -4
  18. package/src/input-controller.d.ts +1 -1
  19. package/src/input-controller.js +5 -8
  20. package/src/input-field-mixin.d.ts +3 -3
  21. package/src/input-field-mixin.js +10 -10
  22. package/src/input-mixin.d.ts +1 -1
  23. package/src/input-mixin.js +17 -11
  24. package/src/label-controller.d.ts +3 -8
  25. package/src/label-controller.js +45 -149
  26. package/src/label-mixin.d.ts +1 -1
  27. package/src/label-mixin.js +13 -8
  28. package/src/labelled-input-controller.d.ts +1 -1
  29. package/src/labelled-input-controller.js +2 -2
  30. package/src/pattern-mixin.d.ts +3 -11
  31. package/src/pattern-mixin.js +2 -50
  32. package/src/slot-styles-mixin.d.ts +1 -1
  33. package/src/slot-styles-mixin.js +1 -1
  34. package/src/styles/clear-button-styles.d.ts +1 -1
  35. package/src/styles/clear-button-styles.js +1 -1
  36. package/src/styles/field-shared-styles.d.ts +1 -1
  37. package/src/styles/field-shared-styles.js +1 -1
  38. package/src/styles/input-field-container-styles.d.ts +1 -1
  39. package/src/styles/input-field-container-styles.js +1 -1
  40. package/src/styles/input-field-shared-styles.d.ts +1 -1
  41. package/src/styles/input-field-shared-styles.js +1 -1
  42. package/src/text-area-controller.d.ts +1 -1
  43. package/src/text-area-controller.js +5 -8
  44. package/src/validate-mixin.d.ts +1 -1
  45. package/src/validate-mixin.js +1 -1
  46. package/src/virtual-keyboard-controller.d.ts +1 -1
  47. package/src/virtual-keyboard-controller.js +1 -1
  48. package/src/delegate-focus-mixin.d.ts +0 -48
  49. package/src/delegate-focus-mixin.js +0 -228
  50. package/src/delegate-state-mixin.d.ts +0 -20
  51. package/src/delegate-state-mixin.js +0 -125
  52. package/src/shadow-focus-mixin.d.ts +0 -23
  53. package/src/shadow-focus-mixin.js +0 -97
  54. package/src/slot-target-controller.d.ts +0 -31
  55. package/src/slot-target-controller.js +0 -123
@@ -1,228 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 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 { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
8
- import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js';
9
-
10
- /**
11
- * A mixin to forward focus to an element in the light DOM.
12
- *
13
- * @polymerMixin
14
- * @mixes FocusMixin
15
- * @mixes TabindexMixin
16
- */
17
- export const DelegateFocusMixin = dedupingMixin(
18
- (superclass) =>
19
- class DelegateFocusMixinClass extends FocusMixin(TabindexMixin(superclass)) {
20
- static get properties() {
21
- return {
22
- /**
23
- * Specify that this control should have input focus when the page loads.
24
- */
25
- autofocus: {
26
- type: Boolean,
27
- },
28
-
29
- /**
30
- * A reference to the focusable element controlled by the mixin.
31
- * It can be an input, textarea, button or any element with tabindex > -1.
32
- *
33
- * Any component implementing this mixin is expected to provide it
34
- * by using `this._setFocusElement(input)` Polymer API.
35
- *
36
- * Toggling `tabindex` attribute on the host element propagates its value to `focusElement`.
37
- *
38
- * @protected
39
- * @type {!HTMLElement}
40
- */
41
- focusElement: {
42
- type: Object,
43
- readOnly: true,
44
- observer: '_focusElementChanged',
45
- },
46
-
47
- /**
48
- * Override the property from `TabIndexMixin`
49
- * to ensure the `tabindex` attribute of the focus element
50
- * will be restored to `0` after re-enabling the element.
51
- *
52
- * @protected
53
- * @override
54
- */
55
- _lastTabIndex: {
56
- value: 0,
57
- },
58
- };
59
- }
60
-
61
- constructor() {
62
- super();
63
-
64
- this._boundOnBlur = this._onBlur.bind(this);
65
- this._boundOnFocus = this._onFocus.bind(this);
66
- }
67
-
68
- /** @protected */
69
- ready() {
70
- super.ready();
71
-
72
- if (this.autofocus && !this.disabled) {
73
- requestAnimationFrame(() => {
74
- this.focus();
75
- this.setAttribute('focus-ring', '');
76
- });
77
- }
78
- }
79
-
80
- /**
81
- * @protected
82
- * @override
83
- */
84
- focus() {
85
- if (!this.focusElement || this.disabled) {
86
- return;
87
- }
88
-
89
- this.focusElement.focus();
90
- this._setFocused(true);
91
- }
92
-
93
- /**
94
- * @protected
95
- * @override
96
- */
97
- blur() {
98
- if (!this.focusElement) {
99
- return;
100
- }
101
- this.focusElement.blur();
102
- this._setFocused(false);
103
- }
104
-
105
- /**
106
- * @protected
107
- * @override
108
- */
109
- click() {
110
- if (this.focusElement && !this.disabled) {
111
- this.focusElement.click();
112
- }
113
- }
114
-
115
- /** @protected */
116
- _focusElementChanged(element, oldElement) {
117
- if (element) {
118
- element.disabled = this.disabled;
119
- this._addFocusListeners(element);
120
- this.__forwardTabIndex(this.tabindex);
121
- } else if (oldElement) {
122
- this._removeFocusListeners(oldElement);
123
- }
124
- }
125
-
126
- /**
127
- * @param {HTMLElement} element
128
- * @protected
129
- */
130
- _addFocusListeners(element) {
131
- element.addEventListener('blur', this._boundOnBlur);
132
- element.addEventListener('focus', this._boundOnFocus);
133
- }
134
-
135
- /**
136
- * @param {HTMLElement} element
137
- * @protected
138
- */
139
- _removeFocusListeners(element) {
140
- element.removeEventListener('blur', this._boundOnBlur);
141
- element.removeEventListener('focus', this._boundOnFocus);
142
- }
143
-
144
- /**
145
- * Focus event does not bubble, so we dispatch it manually
146
- * on the host element to support adding focus listeners
147
- * when the focusable element is placed in light DOM.
148
- * @param {FocusEvent} event
149
- * @protected
150
- */
151
- _onFocus(event) {
152
- event.stopPropagation();
153
- this.dispatchEvent(new Event('focus'));
154
- }
155
-
156
- /**
157
- * Blur event does not bubble, so we dispatch it manually
158
- * on the host element to support adding blur listeners
159
- * when the focusable element is placed in light DOM.
160
- * @param {FocusEvent} event
161
- * @protected
162
- */
163
- _onBlur(event) {
164
- event.stopPropagation();
165
- this.dispatchEvent(new Event('blur'));
166
- }
167
-
168
- /**
169
- * @param {Event} event
170
- * @return {boolean}
171
- * @protected
172
- * @override
173
- */
174
- _shouldSetFocus(event) {
175
- return event.target === this.focusElement;
176
- }
177
-
178
- /**
179
- * @param {boolean} disabled
180
- * @param {boolean} oldDisabled
181
- * @protected
182
- * @override
183
- */
184
- _disabledChanged(disabled, oldDisabled) {
185
- super._disabledChanged(disabled, oldDisabled);
186
-
187
- if (this.focusElement) {
188
- this.focusElement.disabled = disabled;
189
- }
190
-
191
- if (disabled) {
192
- this.blur();
193
- }
194
- }
195
-
196
- /**
197
- * Override an observer from `TabindexMixin`.
198
- * Do not call super to remove tabindex attribute
199
- * from the host after it has been forwarded.
200
- * @param {string} tabindex
201
- * @protected
202
- * @override
203
- */
204
- _tabindexChanged(tabindex) {
205
- this.__forwardTabIndex(tabindex);
206
- }
207
-
208
- /** @private */
209
- __forwardTabIndex(tabindex) {
210
- if (tabindex !== undefined && this.focusElement) {
211
- this.focusElement.tabIndex = tabindex;
212
-
213
- // Preserve tabindex="-1" on the host element
214
- if (tabindex !== -1) {
215
- this.tabindex = undefined;
216
- }
217
- }
218
-
219
- if (this.disabled && tabindex) {
220
- // If tabindex attribute was changed while component was disabled
221
- if (tabindex !== -1) {
222
- this._lastTabIndex = tabindex;
223
- }
224
- this.tabindex = undefined;
225
- }
226
- }
227
- },
228
- );
@@ -1,20 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
-
8
- /**
9
- * A mixin to delegate properties and attributes to a target element.
10
- */
11
- export declare function DelegateStateMixin<T extends Constructor<HTMLElement>>(
12
- base: T,
13
- ): Constructor<DelegateStateMixinClass> & T;
14
-
15
- export declare class DelegateStateMixinClass {
16
- /**
17
- * A target element to which attributes and properties are delegated.
18
- */
19
- stateTarget: HTMLElement | null;
20
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 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
- /**
9
- * A mixin to delegate properties and attributes to a target element.
10
- *
11
- * @polymerMixin
12
- */
13
- export const DelegateStateMixin = dedupingMixin(
14
- (superclass) =>
15
- class DelegateStateMixinClass extends superclass {
16
- static get properties() {
17
- return {
18
- /**
19
- * A target element to which attributes and properties are delegated.
20
- * @protected
21
- */
22
- stateTarget: {
23
- type: Object,
24
- observer: '_stateTargetChanged',
25
- },
26
- };
27
- }
28
-
29
- /**
30
- * An array of the host attributes to delegate to the target element.
31
- */
32
- static get delegateAttrs() {
33
- return [];
34
- }
35
-
36
- /**
37
- * An array of the host properties to delegate to the target element.
38
- */
39
- static get delegateProps() {
40
- return [];
41
- }
42
-
43
- /** @protected */
44
- ready() {
45
- super.ready();
46
-
47
- this._createDelegateAttrsObserver();
48
- this._createDelegatePropsObserver();
49
- }
50
-
51
- /** @protected */
52
- _stateTargetChanged(target) {
53
- if (target) {
54
- this._ensureAttrsDelegated();
55
- this._ensurePropsDelegated();
56
- }
57
- }
58
-
59
- /** @protected */
60
- _createDelegateAttrsObserver() {
61
- this._createMethodObserver(`_delegateAttrsChanged(${this.constructor.delegateAttrs.join(', ')})`);
62
- }
63
-
64
- /** @protected */
65
- _createDelegatePropsObserver() {
66
- this._createMethodObserver(`_delegatePropsChanged(${this.constructor.delegateProps.join(', ')})`);
67
- }
68
-
69
- /** @protected */
70
- _ensureAttrsDelegated() {
71
- this.constructor.delegateAttrs.forEach((name) => {
72
- this._delegateAttribute(name, this[name]);
73
- });
74
- }
75
-
76
- /** @protected */
77
- _ensurePropsDelegated() {
78
- this.constructor.delegateProps.forEach((name) => {
79
- this._delegateProperty(name, this[name]);
80
- });
81
- }
82
-
83
- /** @protected */
84
- _delegateAttrsChanged(...values) {
85
- this.constructor.delegateAttrs.forEach((name, index) => {
86
- this._delegateAttribute(name, values[index]);
87
- });
88
- }
89
-
90
- /** @protected */
91
- _delegatePropsChanged(...values) {
92
- this.constructor.delegateProps.forEach((name, index) => {
93
- this._delegateProperty(name, values[index]);
94
- });
95
- }
96
-
97
- /** @protected */
98
- _delegateAttribute(name, value) {
99
- if (!this.stateTarget) {
100
- return;
101
- }
102
-
103
- if (name === 'invalid') {
104
- this._delegateAttribute('aria-invalid', value ? 'true' : false);
105
- }
106
-
107
- if (typeof value === 'boolean') {
108
- this.stateTarget.toggleAttribute(name, value);
109
- } else if (value) {
110
- this.stateTarget.setAttribute(name, value);
111
- } else {
112
- this.stateTarget.removeAttribute(name);
113
- }
114
- }
115
-
116
- /** @protected */
117
- _delegateProperty(name, value) {
118
- if (!this.stateTarget) {
119
- return;
120
- }
121
-
122
- this.stateTarget[name] = value;
123
- }
124
- },
125
- );
@@ -1,23 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
- import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
10
- import type { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
11
- import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
-
13
- /**
14
- * A mixin to forward focus to an element in the shadow DOM.
15
- */
16
- export declare function ShadowFocusMixin<T extends Constructor<HTMLElement>>(
17
- base: T,
18
- ): Constructor<DelegateFocusMixinClass> &
19
- Constructor<DisabledMixinClass> &
20
- Constructor<FocusMixinClass> &
21
- Constructor<KeyboardMixinClass> &
22
- Constructor<TabindexMixinClass> &
23
- T;
@@ -1,97 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
7
- import { DelegateFocusMixin } from './delegate-focus-mixin.js';
8
-
9
- /**
10
- * A mixin to forward focus to an element in the shadow DOM.
11
- *
12
- * @polymerMixin
13
- * @mixes DelegateFocusMixin
14
- * @mixes KeyboardMixin
15
- */
16
- export const ShadowFocusMixin = (superClass) =>
17
- class ShadowFocusMixinClass extends DelegateFocusMixin(KeyboardMixin(superClass)) {
18
- static get properties() {
19
- return {
20
- /**
21
- * Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
22
- *
23
- * @override
24
- * @protected
25
- */
26
- tabindex: {
27
- type: Number,
28
- value: 0,
29
- },
30
- };
31
- }
32
-
33
- /**
34
- * Override an event listener from `KeyboardMixin`
35
- * to prevent focusing the host element on Shift Tab.
36
- * @param {KeyboardEvent} event
37
- * @protected
38
- * @override
39
- */
40
- _onKeyDown(event) {
41
- super._onKeyDown(event);
42
-
43
- // When focus moves with Shift + Tab, skip focusing the host element
44
- // by focusing it before the default browser focus handling runs
45
- if (!event.defaultPrevented && event.keyCode === 9 && event.shiftKey) {
46
- HTMLElement.prototype.focus.apply(this);
47
- }
48
- }
49
-
50
- /**
51
- * Override method inherited from `FocusMixin`
52
- * to support focusElement in Shadow DOM.
53
- * @param {Event} event
54
- * @return {boolean}
55
- * @protected
56
- * @override
57
- */
58
- _shouldSetFocus(event) {
59
- if (!this.disabled && this.focusElement) {
60
- const path = event.composedPath();
61
-
62
- // When focus moves to the host element itself, then delegate it to the focusElement
63
- // This should only move focus when using keyboard navigation, for clicks we don't want to interfere,
64
- // for example when the user tries to select some text
65
- if (path[0] === this && this._keyboardActive) {
66
- this.focusElement.focus();
67
- }
68
- if (path[0] === this || path.includes(this.focusElement)) {
69
- return true;
70
- }
71
- }
72
-
73
- return false;
74
- }
75
-
76
- /**
77
- * Override an observer from `TabindexMixin`.
78
- * Do not call super to remove tabindex attribute
79
- * from host when disabled by setting undefined.
80
- * @param {string} tabindex
81
- * @protected
82
- * @override
83
- */
84
- _tabindexChanged(tabindex) {
85
- if (tabindex !== undefined) {
86
- this.focusElement.tabIndex = tabindex;
87
- }
88
-
89
- if (this.disabled && tabindex) {
90
- // If tabindex attribute was changed while component was disabled
91
- if (tabindex !== -1) {
92
- this._lastTabIndex = tabindex;
93
- }
94
- this.tabindex = undefined;
95
- }
96
- }
97
- };
@@ -1,31 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { ReactiveController } from 'lit';
7
-
8
- export class SlotTargetController implements ReactiveController {
9
- /**
10
- * The source `<slot>` element to copy nodes from.
11
- */
12
- protected sourceSlot: HTMLSlotElement;
13
-
14
- /**
15
- * Function used to get a reference to slot target.
16
- */
17
- protected targetFactory: () => HTMLElement;
18
-
19
- /**
20
- * Function called after copying nodes to target.
21
- */
22
- protected copyCallback?: (nodes: HTMLElement[]) => void;
23
-
24
- constructor(
25
- sourceSlot: HTMLSlotElement,
26
- targetFactory: () => HTMLElement,
27
- copyCallback?: (nodes: HTMLElement[]) => void,
28
- );
29
-
30
- hostConnected(): void;
31
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * A controller to copy the content from a source slot to a target element.
9
- */
10
- export class SlotTargetController {
11
- constructor(sourceSlot, targetFactory, callback) {
12
- /**
13
- * The source `<slot>` element to copy nodes from.
14
- */
15
- this.sourceSlot = sourceSlot;
16
-
17
- /**
18
- * Function used to get a reference to slot target.
19
- */
20
- this.targetFactory = targetFactory;
21
-
22
- /**
23
- * Function called after copying nodes to target.
24
- */
25
- this.copyCallback = callback;
26
-
27
- if (sourceSlot) {
28
- sourceSlot.addEventListener('slotchange', () => {
29
- // Copy in progress, ignore this event.
30
- if (this.__copying) {
31
- this.__copying = false;
32
- } else {
33
- this.__checkAndCopyNodesToSlotTarget();
34
- }
35
- });
36
- }
37
- }
38
-
39
- hostConnected() {
40
- this.__sourceSlotObserver = new MutationObserver(() => this.__checkAndCopyNodesToSlotTarget());
41
-
42
- // Ensure the content is up to date when host is connected
43
- // to handle e.g. mutating text content while disconnected.
44
- // Note, `hostConnected()` is called twice if the controller
45
- // is initialized in `ready()` when using `ControllerMixin`.
46
- if (!this.__copying) {
47
- this.__checkAndCopyNodesToSlotTarget();
48
- }
49
- }
50
-
51
- /**
52
- * Copies every node from the source slot to the target element
53
- * once the source slot' content is changed.
54
- *
55
- * @private
56
- */
57
- __checkAndCopyNodesToSlotTarget() {
58
- this.__sourceSlotObserver.disconnect();
59
-
60
- // Ensure slot target element is up to date.
61
- const slotTarget = this.targetFactory();
62
-
63
- if (!slotTarget) {
64
- return;
65
- }
66
-
67
- // Remove any existing clones from the slot target
68
- if (this.__slotTargetClones) {
69
- this.__slotTargetClones.forEach((node) => {
70
- if (node.parentElement === slotTarget) {
71
- slotTarget.removeChild(node);
72
- }
73
- });
74
- delete this.__slotTargetClones;
75
- }
76
-
77
- // Exclude whitespace text nodes
78
- const nodes = this.sourceSlot
79
- .assignedNodes({ flatten: true })
80
- .filter((node) => !(node.nodeType === Node.TEXT_NODE && node.textContent.trim() === ''));
81
-
82
- if (nodes.length > 0) {
83
- slotTarget.innerHTML = '';
84
-
85
- // Ignore next slotchange
86
- this.__copying = true;
87
-
88
- this.__copyNodesToSlotTarget(nodes, slotTarget);
89
- }
90
- }
91
-
92
- /**
93
- * Copies the nodes to the target element.
94
- *
95
- * @param {!Array<!Node>} nodes
96
- * @param {HTMLElement} slotTarget
97
- * @private
98
- */
99
- __copyNodesToSlotTarget(nodes, slotTarget) {
100
- this.__slotTargetClones = this.__slotTargetClones || [];
101
-
102
- nodes.forEach((node) => {
103
- // Clone the nodes and append the clones to the target
104
- const clone = node.cloneNode(true);
105
- this.__slotTargetClones.push(clone);
106
-
107
- slotTarget.appendChild(clone);
108
-
109
- // Observe all changes to the source node to have the clones updated
110
- this.__sourceSlotObserver.observe(node, {
111
- attributes: true,
112
- childList: true,
113
- subtree: true,
114
- characterData: true,
115
- });
116
- });
117
-
118
- // Run callback e.g. to show a deprecation warning
119
- if (typeof this.copyCallback === 'function') {
120
- this.copyCallback(nodes);
121
- }
122
- }
123
- }