@vaadin/field-base 22.0.0-alpha6 → 22.0.0-alpha7

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 (63) hide show
  1. package/index.d.ts +6 -9
  2. package/index.js +6 -9
  3. package/package.json +22 -17
  4. package/src/aria-label-controller.d.ts +11 -0
  5. package/src/aria-label-controller.js +53 -0
  6. package/src/checked-mixin.js +37 -67
  7. package/src/delegate-focus-mixin.js +147 -131
  8. package/src/delegate-state-mixin.d.ts +1 -1
  9. package/src/delegate-state-mixin.js +100 -88
  10. package/src/field-mixin.d.ts +39 -0
  11. package/src/field-mixin.js +317 -0
  12. package/src/input-constraints-mixin.d.ts +4 -2
  13. package/src/input-constraints-mixin.js +105 -86
  14. package/src/input-control-mixin.d.ts +52 -0
  15. package/src/input-control-mixin.js +170 -0
  16. package/src/input-controller.d.ts +11 -0
  17. package/src/input-controller.js +35 -0
  18. package/src/input-field-mixin.d.ts +2 -16
  19. package/src/input-field-mixin.js +17 -89
  20. package/src/input-mixin.d.ts +1 -1
  21. package/src/input-mixin.js +156 -145
  22. package/src/label-mixin.d.ts +1 -1
  23. package/src/label-mixin.js +72 -59
  24. package/src/pattern-mixin.js +9 -9
  25. package/src/shadow-focus-mixin.d.ts +21 -0
  26. package/src/shadow-focus-mixin.js +87 -0
  27. package/src/slot-controller.d.ts +8 -0
  28. package/src/slot-controller.js +36 -0
  29. package/src/slot-label-mixin.d.ts +20 -0
  30. package/src/slot-label-mixin.js +38 -0
  31. package/src/slot-styles-mixin.js +38 -31
  32. package/src/slot-target-mixin.d.ts +8 -19
  33. package/src/slot-target-mixin.js +93 -73
  34. package/src/styles/clear-button-styles.d.ts +8 -0
  35. package/src/styles/clear-button-styles.js +21 -0
  36. package/src/styles/field-shared-styles.d.ts +8 -0
  37. package/src/styles/field-shared-styles.js +29 -0
  38. package/src/styles/input-field-container-styles.d.ts +8 -0
  39. package/src/styles/input-field-container-styles.js +16 -0
  40. package/src/styles/input-field-shared-styles.d.ts +8 -0
  41. package/src/styles/input-field-shared-styles.js +10 -0
  42. package/src/text-area-controller.d.ts +11 -0
  43. package/src/text-area-controller.js +38 -0
  44. package/src/validate-mixin.d.ts +1 -9
  45. package/src/validate-mixin.js +43 -120
  46. package/src/aria-label-mixin.d.ts +0 -20
  47. package/src/aria-label-mixin.js +0 -71
  48. package/src/char-length-mixin.d.ts +0 -30
  49. package/src/char-length-mixin.js +0 -42
  50. package/src/clear-button-mixin.d.ts +0 -28
  51. package/src/clear-button-mixin.js +0 -82
  52. package/src/delegate-input-state-mixin.d.ts +0 -43
  53. package/src/delegate-input-state-mixin.js +0 -63
  54. package/src/field-aria-mixin.d.ts +0 -24
  55. package/src/field-aria-mixin.js +0 -61
  56. package/src/helper-text-mixin.d.ts +0 -24
  57. package/src/helper-text-mixin.js +0 -144
  58. package/src/input-slot-mixin.d.ts +0 -26
  59. package/src/input-slot-mixin.js +0 -71
  60. package/src/text-area-slot-mixin.d.ts +0 -21
  61. package/src/text-area-slot-mixin.js +0 -56
  62. package/src/text-field-mixin.d.ts +0 -21
  63. package/src/text-field-mixin.js +0 -17
@@ -0,0 +1,20 @@
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 { LabelMixin } from './label-mixin.js';
7
+ import { SlotTargetMixin } from './slot-target-mixin.js';
8
+
9
+ /**
10
+ * A mixin to forward any content from the default slot to the label node.
11
+ */
12
+ declare function SlotLabelMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotLabelMixinConstructor;
13
+
14
+ interface SlotLabelMixinConstructor {
15
+ new (...args: any[]): SlotLabelMixin;
16
+ }
17
+
18
+ interface SlotLabelMixin extends SlotTargetMixin, LabelMixin {}
19
+
20
+ export { SlotLabelMixinConstructor, SlotLabelMixin };
@@ -0,0 +1,38 @@
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 { LabelMixin } from './label-mixin.js';
8
+ import { SlotTargetMixin } from './slot-target-mixin.js';
9
+
10
+ /**
11
+ * A mixin to forward any content from the default slot to the label node.
12
+ *
13
+ * @polymerMixin
14
+ * @mixes LabelMixin
15
+ * @mixes SlotTargetMixin
16
+ */
17
+ export const SlotLabelMixin = dedupingMixin(
18
+ (superclass) =>
19
+ class SlotLabelMixinClass extends SlotTargetMixin(LabelMixin(superclass)) {
20
+ /** @protected */
21
+ get _slotTarget() {
22
+ return this._labelNode;
23
+ }
24
+
25
+ /** @protected */
26
+ ready() {
27
+ super.ready();
28
+
29
+ if (this._labelNode) {
30
+ // The default slot's content is moved to the label node
31
+ // only after `LabelMixin` is initialized which means
32
+ // we should manually toggle the `has-label` attribute
33
+ // respecting the new label content.
34
+ this._toggleHasLabelAttribute();
35
+ }
36
+ }
37
+ }
38
+ );
@@ -1,3 +1,8 @@
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
+ */
1
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
2
7
 
3
8
  const stylesMap = new WeakMap();
@@ -31,39 +36,41 @@ function insertStyles(styles, root) {
31
36
  }
32
37
  }
33
38
 
34
- const SlotStylesMixinImplementation = (superclass) =>
35
- class SlotStylesMixinClass extends superclass {
36
- /**
37
- * List of styles to insert into root.
38
- * @protected
39
- */
40
- get slotStyles() {
41
- return {};
42
- }
39
+ /**
40
+ * Mixin to insert styles into the outer scope to handle slotted components.
41
+ * This is useful e.g. to hide native `<input type="number">` controls.
42
+ *
43
+ * @polymerMixin
44
+ */
45
+ export const SlotStylesMixin = dedupingMixin(
46
+ (superclass) =>
47
+ class SlotStylesMixinClass extends superclass {
48
+ /**
49
+ * List of styles to insert into root.
50
+ * @protected
51
+ */
52
+ get slotStyles() {
53
+ return {};
54
+ }
43
55
 
44
- /** @protected */
45
- connectedCallback() {
46
- super.connectedCallback();
56
+ /** @protected */
57
+ connectedCallback() {
58
+ super.connectedCallback();
47
59
 
48
- this.__applySlotStyles();
49
- }
60
+ this.__applySlotStyles();
61
+ }
50
62
 
51
- /** @private */
52
- __applySlotStyles() {
53
- const root = this.getRootNode();
54
- const rootStyles = getRootStyles(root);
63
+ /** @private */
64
+ __applySlotStyles() {
65
+ const root = this.getRootNode();
66
+ const rootStyles = getRootStyles(root);
55
67
 
56
- this.slotStyles.forEach((styles) => {
57
- if (!rootStyles.has(styles)) {
58
- insertStyles(styles, root);
59
- rootStyles.add(styles);
60
- }
61
- });
68
+ this.slotStyles.forEach((styles) => {
69
+ if (!rootStyles.has(styles)) {
70
+ insertStyles(styles, root);
71
+ rootStyles.add(styles);
72
+ }
73
+ });
74
+ }
62
75
  }
63
- };
64
-
65
- /**
66
- * Mixin to insert styles into the outer scope to handle slotted components.
67
- * This is useful e.g. to hide native `<input type="number">` controls.
68
- */
69
- export const SlotStylesMixin = dedupingMixin(SlotStylesMixinImplementation);
76
+ );
@@ -5,39 +5,28 @@
5
5
  */
6
6
 
7
7
  /**
8
- * A mixin to forward the content from a source slot to a target element.
8
+ * A mixin to copy the content from a source slot to a target element.
9
9
  */
10
- declare function SlotTargetMixinMixin<T extends new (...args: any[]) => {}>(
11
- base: T
12
- ): T & SlotTargetMixinMixinConstructor;
10
+ declare function SlotTargetMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotTargetMixinConstructor;
13
11
 
14
- interface SlotTargetMixinMixinConstructor {
15
- new (...args: any[]): SlotTargetMixinMixin;
12
+ interface SlotTargetMixinConstructor {
13
+ new (...args: any[]): SlotTargetMixin;
16
14
  }
17
15
 
18
- interface SlotTargetMixinMixin {
16
+ interface SlotTargetMixin {
19
17
  /**
20
- * A reference to the source slot from which the content is forwarded to the target element.
18
+ * A reference to the source slot from which the content is copied to the target element.
21
19
  *
22
20
  * @protected
23
21
  */
24
22
  _sourceSlot: HTMLSlotElement;
25
23
 
26
24
  /**
27
- * A reference to the target element to which the content is forwarded from the source slot.
25
+ * A reference to the target element to which the content is copied from the source slot.
28
26
  *
29
27
  * @protected
30
28
  */
31
29
  _slotTarget: HTMLElement;
32
-
33
- /**
34
- * A callback method that is called once the target element's content is changed.
35
- *
36
- * By default, it does nothing. Override the method to implement your own behavior.
37
- *
38
- * @protected
39
- */
40
- _onSlotTargetContentChange(): void;
41
30
  }
42
31
 
43
- export { SlotTargetMixinMixinConstructor, SlotTargetMixinMixin };
32
+ export { SlotTargetMixinConstructor, SlotTargetMixin };
@@ -1,90 +1,110 @@
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
+ */
1
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
2
7
 
3
- const SlotTargetMixinImplementation = (superclass) =>
4
- class SlotTargetMixinClass extends superclass {
5
- constructor() {
6
- super();
8
+ /**
9
+ * A mixin to copy the content from a source slot to a target element.
10
+ *
11
+ * @polymerMixin
12
+ */
13
+ export const SlotTargetMixin = dedupingMixin(
14
+ (superclass) =>
15
+ class SlotTargetMixinClass extends superclass {
16
+ /** @protected */
17
+ ready() {
18
+ super.ready();
7
19
 
8
- /**
9
- * @type {MutationObserver}
10
- * @private
11
- */
12
- this.__slotTargetObserver = new MutationObserver(() => {
13
- this._onSlotTargetContentChange();
14
- });
15
- }
20
+ if (this._sourceSlot) {
21
+ this.__sourceSlotObserver = new MutationObserver(() => this.__checkAndCopyNodesToSlotTarget());
16
22
 
17
- /** @protected */
18
- ready() {
19
- super.ready();
23
+ this.__checkAndCopyNodesToSlotTarget();
20
24
 
21
- if (this._slotTarget) {
22
- // Observe for changes in the target element.
23
- this.__slotTargetObserver.observe(this._slotTarget, {
24
- childList: true
25
- });
25
+ this._sourceSlot.addEventListener('slotchange', () => {
26
+ this.__checkAndCopyNodesToSlotTarget();
27
+ });
28
+ }
26
29
  }
27
30
 
28
- if (this._sourceSlot) {
29
- // Observe for changes in the source slot.
30
- this._sourceSlot.addEventListener('slotchange', () => {
31
- this.__onSourceSlotContentChange();
32
- });
31
+ /**
32
+ * A reference to the source slot from which the nodes are copied to the target element.
33
+ *
34
+ * @type {HTMLSlotElement | null}
35
+ * @protected
36
+ */
37
+ get _sourceSlot() {
38
+ console.warn(`Please implement the '_sourceSlot' property in <${this.localName}>`);
39
+ return null;
40
+ }
33
41
 
34
- this.__onSourceSlotContentChange();
42
+ /**
43
+ * A reference to the target element to which the nodes are copied from the source slot.
44
+ *
45
+ * @type {HTMLElement | null}
46
+ * @protected
47
+ */
48
+ get _slotTarget() {
49
+ console.warn(`Please implement the '_slotTarget' property in <${this.localName}>`);
50
+ return null;
35
51
  }
36
- }
37
52
 
38
- /**
39
- * A reference to the source slot from which the content is forwarded to the target element.
40
- *
41
- * @type {HTMLSlotElement | null}
42
- * @protected
43
- */
44
- get _sourceSlot() {
45
- console.warn(`Please implement the '_sourceSlot' property in <${this.localName}>`);
46
- return null;
47
- }
53
+ /**
54
+ * Copies every node from the source slot to the target element
55
+ * once the source slot' content is changed.
56
+ *
57
+ * @private
58
+ */
59
+ __checkAndCopyNodesToSlotTarget() {
60
+ this.__sourceSlotObserver.disconnect();
48
61
 
49
- /**
50
- * A reference to the target element to which the content is forwarded from the source slot.
51
- *
52
- * @type {HTMLElement | null}
53
- * @protected
54
- */
55
- get _slotTarget() {
56
- console.warn(`Please implement the '_slotTarget' property in <${this.localName}>`);
57
- return null;
58
- }
62
+ if (!this._slotTarget) {
63
+ return;
64
+ }
59
65
 
60
- /**
61
- * A callback method that is called once the target element's content is changed.
62
- *
63
- * By default, it does nothing. Override the method to implement your own behavior.
64
- *
65
- * @protected
66
- */
67
- _onSlotTargetContentChange() {}
66
+ // Remove any existing clones from the slot target
67
+ if (this.__slotTargetClones) {
68
+ this.__slotTargetClones.forEach((node) => {
69
+ if (node.parentElement === this._slotTarget) {
70
+ this._slotTarget.removeChild(node);
71
+ }
72
+ });
73
+ delete this.__slotTargetClones;
74
+ }
68
75
 
69
- /**
70
- * Forwards every node from the source slot to the target element
71
- * once the source slot' content is changed.
72
- *
73
- * @private
74
- */
75
- __onSourceSlotContentChange() {
76
- if (!this._slotTarget) {
77
- return;
76
+ // Exclude whitespace text nodes
77
+ const nodes = this._sourceSlot
78
+ .assignedNodes({ flatten: true })
79
+ .filter((node) => !(node.nodeType == Node.TEXT_NODE && node.textContent.trim() === ''));
80
+
81
+ if (nodes.length > 0) {
82
+ this._slotTarget.innerHTML = '';
83
+ this.__copyNodesToSlotTarget(nodes);
84
+ }
78
85
  }
79
86
 
80
- const nodes = this._sourceSlot.assignedNodes({ flatten: true });
81
- if (nodes.length > 0) {
82
- this._slotTarget.replaceChildren(...nodes);
87
+ /**
88
+ * Copies the nodes to the target element.
89
+ *
90
+ * @protected
91
+ * @param {!Array<!Node>} nodes
92
+ */
93
+ __copyNodesToSlotTarget(nodes) {
94
+ this.__slotTargetClones = this.__slotTargetClones || [];
95
+ nodes.forEach((node) => {
96
+ // Clone the nodes and append the clones to the target slot
97
+ const clone = node.cloneNode(true);
98
+ this.__slotTargetClones.push(clone);
99
+ this._slotTarget.appendChild(clone);
100
+ // Observe all changes to the source node to have the clones updated
101
+ this.__sourceSlotObserver.observe(node, {
102
+ attributes: true,
103
+ childList: true,
104
+ subtree: true,
105
+ characterData: true
106
+ });
107
+ });
83
108
  }
84
109
  }
85
- };
86
-
87
- /**
88
- * A mixin to forward the content from a source slot to a target element.
89
- */
90
- export const SlotTargetMixin = dedupingMixin(SlotTargetMixinImplementation);
110
+ );
@@ -0,0 +1,8 @@
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 { CSSResult } from 'lit';
7
+
8
+ export const clearButton: CSSResult;
@@ -0,0 +1,21 @@
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 { css } from 'lit';
7
+
8
+ export const clearButton = css`
9
+ [part='clear-button'] {
10
+ display: none;
11
+ cursor: default;
12
+ }
13
+
14
+ [part='clear-button']::before {
15
+ content: '✕';
16
+ }
17
+
18
+ :host([clear-button-visible][has-value]:not([disabled]):not([readonly])) [part='clear-button'] {
19
+ display: block;
20
+ }
21
+ `;
@@ -0,0 +1,8 @@
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 { CSSResult } from 'lit';
7
+
8
+ export const fieldShared: CSSResult;
@@ -0,0 +1,29 @@
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 { css } from 'lit';
7
+
8
+ export const fieldShared = css`
9
+ :host {
10
+ display: inline-flex;
11
+ outline: none;
12
+ }
13
+
14
+ :host::before {
15
+ content: '\\2003';
16
+ width: 0;
17
+ display: inline-block;
18
+ /* Size and position this element on the same vertical position as the input-field element
19
+ to make vertical align for the host element work as expected */
20
+ }
21
+
22
+ :host([hidden]) {
23
+ display: none !important;
24
+ }
25
+
26
+ :host(:not([has-label])) [part='label'] {
27
+ display: none;
28
+ }
29
+ `;
@@ -0,0 +1,8 @@
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 { CSSResult } from 'lit';
7
+
8
+ export const inputFieldContainer: CSSResult;
@@ -0,0 +1,16 @@
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 { css } from 'lit';
7
+
8
+ export const inputFieldContainer = css`
9
+ [class$='container'] {
10
+ display: flex;
11
+ flex-direction: column;
12
+ min-width: 100%;
13
+ max-width: 100%;
14
+ width: var(--vaadin-field-default-width, 12em);
15
+ }
16
+ `;
@@ -0,0 +1,8 @@
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 { CSSResult } from 'lit';
7
+
8
+ export const inputFieldShared: CSSResult;
@@ -0,0 +1,10 @@
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 { clearButton } from './clear-button-styles.js';
7
+ import { fieldShared } from './field-shared-styles.js';
8
+ import { inputFieldContainer } from './input-field-container-styles.js';
9
+
10
+ export const inputFieldShared = [fieldShared, inputFieldContainer, clearButton];
@@ -0,0 +1,11 @@
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 { SlotController } from './slot-controller.js';
7
+
8
+ /**
9
+ * A controller to create and initialize slotted `<textarea>` element.
10
+ */
11
+ export class TextAreaController implements SlotController {}
@@ -0,0 +1,38 @@
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 { SlotController } from './slot-controller.js';
7
+
8
+ /**
9
+ * A controller to create and initialize slotted `<textarea>` element.
10
+ */
11
+ export class TextAreaController extends SlotController {
12
+ constructor(host, callback) {
13
+ super(host, [
14
+ 'textarea',
15
+ () => document.createElement('textarea'),
16
+ (host, node) => {
17
+ const value = host.getAttribute('value');
18
+ if (value) {
19
+ node.value = value;
20
+ }
21
+
22
+ const name = host.getAttribute('name');
23
+ if (name) {
24
+ node.setAttribute('name', name);
25
+ }
26
+
27
+ // Ensure every instance has unique ID
28
+ const uniqueId = (TextAreaController._uniqueTextAreaId = 1 + TextAreaController._uniqueInputId || 0);
29
+ host._textareaId = `${host.localName}-${uniqueId}`;
30
+ node.id = host._textareaId;
31
+
32
+ if (typeof callback == 'function') {
33
+ callback(node);
34
+ }
35
+ }
36
+ ]);
37
+ }
38
+ }
@@ -3,7 +3,6 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotMixin } from '@vaadin/component-base/src/slot-mixin.js';
7
6
 
8
7
  /**
9
8
  * A mixin to provide required state and validation logic.
@@ -14,7 +13,7 @@ interface ValidateMixinConstructor {
14
13
  new (...args: any[]): ValidateMixin;
15
14
  }
16
15
 
17
- interface ValidateMixin extends SlotMixin {
16
+ interface ValidateMixin {
18
17
  /**
19
18
  * Set to true when the field is invalid.
20
19
  */
@@ -25,13 +24,6 @@ interface ValidateMixin extends SlotMixin {
25
24
  */
26
25
  required: boolean;
27
26
 
28
- /**
29
- * Error to show when the field is invalid.
30
- *
31
- * @attr {string} error-message
32
- */
33
- errorMessage: string;
34
-
35
27
  /**
36
28
  * Returns true if field is valid, and sets `invalid` based on the field validity.
37
29
  */