@vaadin/field-base 22.0.0-alpha3 → 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 (77) hide show
  1. package/index.d.ts +9 -14
  2. package/index.js +9 -14
  3. package/package.json +24 -18
  4. package/src/aria-label-controller.d.ts +11 -0
  5. package/src/aria-label-controller.js +53 -0
  6. package/src/checked-mixin.d.ts +21 -0
  7. package/src/checked-mixin.js +54 -0
  8. package/src/delegate-focus-mixin.d.ts +2 -2
  9. package/src/delegate-focus-mixin.js +150 -133
  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 +2 -1
  15. package/src/input-constraints-mixin.js +105 -53
  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 -16
  21. package/src/input-field-mixin.js +20 -97
  22. package/src/input-mixin.d.ts +1 -1
  23. package/src/input-mixin.js +156 -145
  24. package/src/label-mixin.d.ts +2 -2
  25. package/src/label-mixin.js +73 -60
  26. package/src/pattern-mixin.d.ts +2 -2
  27. package/src/pattern-mixin.js +13 -13
  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/active-mixin.d.ts +0 -25
  51. package/src/active-mixin.js +0 -84
  52. package/src/aria-label-mixin.d.ts +0 -20
  53. package/src/aria-label-mixin.js +0 -71
  54. package/src/char-length-mixin.d.ts +0 -30
  55. package/src/char-length-mixin.js +0 -42
  56. package/src/clear-button-mixin.d.ts +0 -27
  57. package/src/clear-button-mixin.js +0 -80
  58. package/src/disabled-mixin.d.ts +0 -23
  59. package/src/disabled-mixin.js +0 -48
  60. package/src/field-aria-mixin.d.ts +0 -24
  61. package/src/field-aria-mixin.js +0 -61
  62. package/src/focus-mixin.d.ts +0 -33
  63. package/src/focus-mixin.js +0 -104
  64. package/src/forward-input-props-mixin.d.ts +0 -41
  65. package/src/forward-input-props-mixin.js +0 -110
  66. package/src/helper-text-mixin.d.ts +0 -24
  67. package/src/helper-text-mixin.js +0 -109
  68. package/src/input-slot-mixin.d.ts +0 -26
  69. package/src/input-slot-mixin.js +0 -71
  70. package/src/slot-mixin.d.ts +0 -23
  71. package/src/slot-mixin.js +0 -55
  72. package/src/tabindex-mixin.d.ts +0 -29
  73. package/src/tabindex-mixin.js +0 -78
  74. package/src/text-area-slot-mixin.d.ts +0 -21
  75. package/src/text-area-slot-mixin.js +0 -56
  76. package/src/text-field-mixin.d.ts +0 -21
  77. package/src/text-field-mixin.js +0 -17
@@ -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 { ReactiveController } from 'lit';
7
+
8
+ export class SlotController implements ReactiveController {}
@@ -0,0 +1,36 @@
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
+ export class SlotController {
7
+ constructor(host, [slotName, slotFactory, slotInitializer]) {
8
+ this.host = host;
9
+ this.slotName = slotName;
10
+ this.slotFactory = slotFactory;
11
+ this.slotInitializer = slotInitializer;
12
+ }
13
+
14
+ hostConnected() {
15
+ if (!this.__initialized) {
16
+ const { host, slotName, slotFactory } = this;
17
+
18
+ const slotted = host.querySelector(`[slot=${slotName}]`);
19
+
20
+ if (!slotted) {
21
+ const slotContent = slotFactory(host);
22
+ if (slotContent instanceof Element) {
23
+ slotContent.setAttribute('slot', slotName);
24
+ host.appendChild(slotContent);
25
+ this.__slotContent = slotContent;
26
+ }
27
+ } else {
28
+ this.__slotContent = slotted;
29
+ }
30
+
31
+ this.slotInitializer(host, this.__slotContent);
32
+
33
+ this.__initialized = true;
34
+ }
35
+ }
36
+ }
@@ -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
+ );
@@ -0,0 +1,24 @@
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
+ * Mixin to insert styles into the outer scope to handle slotted components.
9
+ * This is useful e.g. to hide native `<input type="number">` controls.
10
+ */
11
+ declare function SlotStylesMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotStylesMixinConstructor;
12
+
13
+ interface SlotStylesMixinConstructor {
14
+ new (...args: any[]): SlotStylesMixin;
15
+ }
16
+
17
+ interface SlotStylesMixin {
18
+ /**
19
+ * List of styles to insert into root.
20
+ */
21
+ readonly slotStyles: string[];
22
+ }
23
+
24
+ export { SlotStylesMixinConstructor, SlotStylesMixin };
@@ -0,0 +1,76 @@
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 stylesMap = new WeakMap();
9
+
10
+ /**
11
+ * Get all the styles inserted into root.
12
+ * @param {DocumentOrShadowRoot} root
13
+ * @return {Set<string>}
14
+ */
15
+ function getRootStyles(root) {
16
+ if (!stylesMap.has(root)) {
17
+ stylesMap.set(root, new Set());
18
+ }
19
+
20
+ return stylesMap.get(root);
21
+ }
22
+
23
+ /**
24
+ * Insert styles into the root.
25
+ * @param {string} styles
26
+ * @param {DocumentOrShadowRoot} root
27
+ */
28
+ function insertStyles(styles, root) {
29
+ const style = document.createElement('style');
30
+ style.textContent = styles;
31
+
32
+ if (root === document) {
33
+ document.head.appendChild(style);
34
+ } else {
35
+ root.insertBefore(style, root.firstChild);
36
+ }
37
+ }
38
+
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
+ }
55
+
56
+ /** @protected */
57
+ connectedCallback() {
58
+ super.connectedCallback();
59
+
60
+ this.__applySlotStyles();
61
+ }
62
+
63
+ /** @private */
64
+ __applySlotStyles() {
65
+ const root = this.getRootNode();
66
+ const rootStyles = getRootStyles(root);
67
+
68
+ this.slotStyles.forEach((styles) => {
69
+ if (!rootStyles.has(styles)) {
70
+ insertStyles(styles, root);
71
+ rootStyles.add(styles);
72
+ }
73
+ });
74
+ }
75
+ }
76
+ );
@@ -0,0 +1,32 @@
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 copy the content from a source slot to a target element.
9
+ */
10
+ declare function SlotTargetMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotTargetMixinConstructor;
11
+
12
+ interface SlotTargetMixinConstructor {
13
+ new (...args: any[]): SlotTargetMixin;
14
+ }
15
+
16
+ interface SlotTargetMixin {
17
+ /**
18
+ * A reference to the source slot from which the content is copied to the target element.
19
+ *
20
+ * @protected
21
+ */
22
+ _sourceSlot: HTMLSlotElement;
23
+
24
+ /**
25
+ * A reference to the target element to which the content is copied from the source slot.
26
+ *
27
+ * @protected
28
+ */
29
+ _slotTarget: HTMLElement;
30
+ }
31
+
32
+ export { SlotTargetMixinConstructor, SlotTargetMixin };
@@ -0,0 +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
+ */
6
+ import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
+
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();
19
+
20
+ if (this._sourceSlot) {
21
+ this.__sourceSlotObserver = new MutationObserver(() => this.__checkAndCopyNodesToSlotTarget());
22
+
23
+ this.__checkAndCopyNodesToSlotTarget();
24
+
25
+ this._sourceSlot.addEventListener('slotchange', () => {
26
+ this.__checkAndCopyNodesToSlotTarget();
27
+ });
28
+ }
29
+ }
30
+
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
+ }
41
+
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;
51
+ }
52
+
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();
61
+
62
+ if (!this._slotTarget) {
63
+ return;
64
+ }
65
+
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
+ }
75
+
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
+ }
85
+ }
86
+
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
+ });
108
+ }
109
+ }
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 './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
  */