@vaadin/component-base 22.0.0-alpha9 → 22.0.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.
package/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # @vaadin/component-base
2
2
 
3
- A set of mixins used by Vaadin components.
3
+ A set of helpers and mixins used by Vaadin components.
4
+
5
+ ## Contributing
6
+
7
+ Read the [contributing guide](https://vaadin.com/docs/latest/guide/contributing/overview) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components.
4
8
 
5
9
  ## License
6
10
 
7
11
  Apache License 2.0
8
12
 
9
- Vaadin collects development time usage statistics to improve this product. For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
13
+ Vaadin collects usage statistics at development time to improve this product.
14
+ For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ActiveMixin } from './src/active-mixin.js';
2
+ export { ControllerMixin } from './src/controller-mixin.js';
2
3
  export { DirMixin } from './src/dir-mixin.js';
3
4
  export { DisabledMixin } from './src/disabled-mixin.js';
4
5
  export { ElementMixin } from './src/element-mixin.js';
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ActiveMixin } from './src/active-mixin.js';
2
+ export { ControllerMixin } from './src/controller-mixin.js';
2
3
  export { DirMixin } from './src/dir-mixin.js';
3
4
  export { DisabledMixin } from './src/disabled-mixin.js';
4
5
  export { ElementMixin } from './src/element-mixin.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/component-base",
3
- "version": "22.0.0-alpha9",
3
+ "version": "22.0.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -30,6 +30,7 @@
30
30
  "web-component"
31
31
  ],
32
32
  "dependencies": {
33
+ "@open-wc/dedupe-mixin": "^1.3.0",
33
34
  "@polymer/polymer": "^3.0.0",
34
35
  "@vaadin/vaadin-development-mode-detector": "^2.0.0",
35
36
  "@vaadin/vaadin-usage-statistics": "^2.1.0",
@@ -37,8 +38,8 @@
37
38
  },
38
39
  "devDependencies": {
39
40
  "@esm-bundle/chai": "^4.3.4",
40
- "@vaadin/testing-helpers": "^0.3.0",
41
+ "@vaadin/testing-helpers": "^0.3.2",
41
42
  "sinon": "^9.2.4"
42
43
  },
43
- "gitHead": "6e8c899dc65918f97e3c0acb2076122c4b2ef274"
44
+ "gitHead": "b668e9b1a975227fbe34beb70d1cd5b03dce2348"
44
45
  }
@@ -3,8 +3,9 @@
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 { DisabledMixin } from './disabled-mixin.js';
7
- import { KeyboardMixin } from './keyboard-mixin.js';
6
+ import { Constructor } from '@open-wc/dedupe-mixin';
7
+ import { DisabledMixinClass } from './disabled-mixin.js';
8
+ import { KeyboardMixinClass } from './keyboard-mixin.js';
8
9
 
9
10
  /**
10
11
  * A mixin to toggle the `active` attribute.
@@ -15,12 +16,26 @@ import { KeyboardMixin } from './keyboard-mixin.js';
15
16
  * The attribute is removed as soon as the element is deactivated
16
17
  * by the pointer or by releasing the activation key.
17
18
  */
18
- declare function ActiveMixin<T extends new (...args: any[]) => {}>(base: T): T & ActiveMixinConstructor;
19
+ export declare function ActiveMixin<T extends Constructor<HTMLElement>>(
20
+ base: T
21
+ ): T & Constructor<ActiveMixinClass> & Constructor<DisabledMixinClass> & Constructor<KeyboardMixinClass>;
19
22
 
20
- interface ActiveMixinConstructor {
21
- new (...args: any[]): ActiveMixin;
22
- }
23
+ export declare class ActiveMixinClass {
24
+ /**
25
+ * An array of activation keys.
26
+ *
27
+ * See possible values here:
28
+ * https://developer.mozilla.org/ru/docs/Web/API/KeyboardEvent/key/Key_Values
29
+ */
30
+ protected readonly _activeKeys: string[];
23
31
 
24
- interface ActiveMixin extends DisabledMixin, KeyboardMixin {}
32
+ /**
33
+ * Override to define if the component needs to be activated.
34
+ */
35
+ protected _shouldSetFocus(event: KeyboardEvent | MouseEvent): boolean;
25
36
 
26
- export { ActiveMixinConstructor, ActiveMixin };
37
+ /**
38
+ * Toggles the `active` attribute on the element.
39
+ */
40
+ protected _setActive(active: boolean): void;
41
+ }
@@ -0,0 +1,35 @@
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
+ const testUserAgent = (regexp) => regexp.test(navigator.userAgent);
8
+
9
+ const testPlatform = (regexp) => regexp.test(navigator.platform);
10
+
11
+ const testVendor = (regexp) => regexp.test(navigator.vendor);
12
+
13
+ export const isAndroid = testUserAgent(/Android/);
14
+
15
+ export const isChrome = testUserAgent(/Chrome/) && testVendor(/Google Inc/);
16
+
17
+ export const isFirefox = testUserAgent(/Firefox/);
18
+
19
+ // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
20
+ export const isIPad = testPlatform(/^iPad/) || (testPlatform(/^Mac/) && navigator.maxTouchPoints > 1);
21
+
22
+ export const isIPhone = testPlatform(/^iPhone/);
23
+
24
+ export const isIOS = isIPhone || isIPad;
25
+
26
+ export const isSafari = testUserAgent(/^((?!chrome|android).)*safari/i);
27
+
28
+ export const isTouch = (() => {
29
+ try {
30
+ document.createEvent('TouchEvent');
31
+ return true;
32
+ } catch (e) {
33
+ return false;
34
+ }
35
+ })();
@@ -0,0 +1,28 @@
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 { Constructor } from '@open-wc/dedupe-mixin';
7
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
8
+
9
+ /**
10
+ * A mixin for connecting controllers to the element.
11
+ */
12
+ export declare function ControllerMixin<T extends Constructor<HTMLElement>>(
13
+ superclass: T
14
+ ): T & Constructor<ControllerMixinClass>;
15
+
16
+ export declare class ControllerMixinClass
17
+ implements Pick<ReactiveControllerHost, 'addController' | 'removeController'>
18
+ {
19
+ /**
20
+ * Registers a controller to participate in the element update cycle.
21
+ */
22
+ addController(controller: ReactiveController): void;
23
+
24
+ /**
25
+ * Removes a controller from the element.
26
+ */
27
+ removeController(controller: ReactiveController): void;
28
+ }
@@ -0,0 +1,67 @@
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 for connecting controllers to the element.
10
+ *
11
+ * @polymerMixin
12
+ */
13
+ export const ControllerMixin = dedupingMixin(
14
+ (superClass) =>
15
+ class ControllerMixinClass extends superClass {
16
+ constructor() {
17
+ super();
18
+
19
+ /**
20
+ * @type {Set<import('lit').ReactiveController>}
21
+ */
22
+ this.__controllers = new Set();
23
+ }
24
+
25
+ /** @protected */
26
+ connectedCallback() {
27
+ super.connectedCallback();
28
+
29
+ this.__controllers.forEach((c) => {
30
+ c.hostConnected && c.hostConnected();
31
+ });
32
+ }
33
+
34
+ /** @protected */
35
+ disconnectedCallback() {
36
+ super.disconnectedCallback();
37
+
38
+ this.__controllers.forEach((c) => {
39
+ c.hostDisconnected && c.hostDisconnected();
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Registers a controller to participate in the element update cycle.
45
+ *
46
+ * @param {import('lit').ReactiveController} controller
47
+ * @protected
48
+ */
49
+ addController(controller) {
50
+ this.__controllers.add(controller);
51
+ // Call hostConnected if a controller is added after the element is attached.
52
+ if (this.$ !== undefined && this.isConnected && controller.hostConnected) {
53
+ controller.hostConnected();
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Removes a controller from the element.
59
+ *
60
+ * @param {import('lit').ReactiveController} controller
61
+ * @protected
62
+ */
63
+ removeController(controller) {
64
+ this.__controllers.delete(controller);
65
+ }
66
+ }
67
+ );
@@ -3,22 +3,15 @@
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 { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
8
  /**
8
9
  * A mixin to handle `dir` attribute based on the one set on the `<html>` element.
9
10
  */
10
- declare function DirMixin<T extends new (...args: any[]) => {}>(base: T): T & DirMixinConstructor;
11
+ export declare function DirMixin<T extends Constructor<HTMLElement>>(base: T): T & Constructor<DirMixinClass>;
11
12
 
12
- interface DirMixinConstructor {
13
- new (...args: any[]): DirMixin;
13
+ export declare class DirMixinClass {
14
+ protected __getNormalizedScrollLeft(element: Element | null): number;
14
15
 
15
- finalize(): void;
16
+ protected __setNormalizedScrollLeft(element: Element | null, scrollLeft: number): void;
16
17
  }
17
-
18
- interface DirMixin {
19
- __getNormalizedScrollLeft(element: Element | null): number;
20
-
21
- __setNormalizedScrollLeft(element: Element | null, scrollLeft: number): void;
22
- }
23
-
24
- export { DirMixin, DirMixinConstructor };
@@ -3,21 +3,18 @@
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 { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
8
  /**
8
9
  * A mixin to provide disabled property for field components.
9
10
  */
10
- declare function DisabledMixin<T extends new (...args: any[]) => {}>(base: T): T & DisabledMixinConstructor;
11
+ export declare function DisabledMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<DisabledMixinClass> & T;
11
12
 
12
- interface DisabledMixinConstructor {
13
- new (...args: any[]): DisabledMixin;
14
- }
15
-
16
- interface DisabledMixin {
13
+ export declare class DisabledMixinClass {
17
14
  /**
18
15
  * If true, the user cannot interact with this element.
19
16
  */
20
17
  disabled: boolean;
21
- }
22
18
 
23
- export { DisabledMixinConstructor, DisabledMixin };
19
+ protected _disabledChanged(disabled: boolean, oldDisabled: boolean): void;
20
+ }
@@ -3,20 +3,20 @@
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 { ReactiveControllerHost } from 'lit';
7
6
  import '../custom_typings/vaadin-usage-statistics.js';
8
7
  import '../custom_typings/vaadin.js';
9
- import { DirMixin, DirMixinConstructor } from './dir-mixin.js';
8
+ import { Constructor } from '@open-wc/dedupe-mixin';
9
+ import { DirMixinClass } from './dir-mixin.js';
10
10
 
11
- declare function ElementMixin<T extends new (...args: any[]) => {}>(
12
- base: T
13
- ): T & ElementMixinConstructor & DirMixinConstructor;
14
-
15
- interface ElementMixinConstructor {
16
- new (...args: any[]): ElementMixin;
17
- finalize(): void;
18
- }
11
+ /**
12
+ * A mixin providing common logic for Vaadin components.
13
+ */
14
+ export declare function ElementMixin<T extends Constructor<HTMLElement>>(
15
+ superclass: T
16
+ ): T & Constructor<DirMixinClass> & Constructor<ElementMixinClass>;
19
17
 
20
- interface ElementMixin extends Pick<ReactiveControllerHost, 'addController' | 'removeController'>, DirMixin {}
18
+ export declare class ElementMixinClass {
19
+ static version: string;
21
20
 
22
- export { ElementMixin, ElementMixinConstructor };
21
+ protected static finalize(): void;
22
+ }
@@ -32,7 +32,7 @@ const registered = new Set();
32
32
  export const ElementMixin = (superClass) =>
33
33
  class VaadinElementMixin extends DirMixin(superClass) {
34
34
  static get version() {
35
- return '22.0.0-alpha9';
35
+ return '22.0.0';
36
36
  }
37
37
 
38
38
  /** @protected */
@@ -58,50 +58,10 @@ export const ElementMixin = (superClass) =>
58
58
  constructor() {
59
59
  super();
60
60
 
61
- this.__controllers = new Set();
62
-
63
61
  if (document.doctype === null) {
64
62
  console.warn(
65
63
  'Vaadin components require the "standards mode" declaration. Please add <!DOCTYPE html> to the HTML document.'
66
64
  );
67
65
  }
68
66
  }
69
-
70
- /** @protected */
71
- connectedCallback() {
72
- super.connectedCallback();
73
-
74
- this.__controllers.forEach((c) => {
75
- c.hostConnected && c.hostConnected();
76
- });
77
- }
78
-
79
- /** @protected */
80
- disconnectedCallback() {
81
- super.disconnectedCallback();
82
-
83
- this.__controllers.forEach((c) => {
84
- c.hostDisconnected && c.hostDisconnected();
85
- });
86
- }
87
-
88
- /**
89
- * Registers a controller to participate in the element update cycle.
90
- * @protected
91
- */
92
- addController(controller) {
93
- this.__controllers.add(controller);
94
- // Call hostConnected if a controller is added after the element is attached.
95
- if (this.$ !== undefined && this.isConnected && controller.hostConnected) {
96
- controller.hostConnected();
97
- }
98
- }
99
-
100
- /**
101
- * Removes a controller from the element.
102
- * @protected
103
- */
104
- removeController(controller) {
105
- this.__controllers.delete(controller);
106
- }
107
67
  };
@@ -3,31 +3,28 @@
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 { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
8
  /**
8
9
  * A mixin to handle `focused` and `focus-ring` attributes based on focus.
9
10
  */
10
- declare function FocusMixin<T extends new (...args: any[]) => {}>(base: T): T & FocusMixinConstructor;
11
+ export declare function FocusMixin<T extends Constructor<HTMLElement>>(base: T): T & Constructor<FocusMixinClass>;
11
12
 
12
- interface FocusMixinConstructor {
13
- new (...args: any[]): FocusMixin;
14
- }
13
+ export declare class FocusMixinClass {
14
+ protected readonly _keyboardActive: boolean;
15
15
 
16
- interface FocusMixin {
17
16
  /**
18
17
  * Override to change how focused and focus-ring attributes are set.
19
18
  */
20
- _setFocused(focused: boolean): void;
19
+ protected _setFocused(focused: boolean): void;
21
20
 
22
21
  /**
23
22
  * Override to define if the field receives focus based on the event.
24
23
  */
25
- _shouldSetFocus(event: FocusEvent): boolean;
24
+ protected _shouldSetFocus(event: FocusEvent): boolean;
26
25
 
27
26
  /**
28
27
  * Override to define if the field loses focus based on the event.
29
28
  */
30
- _shouldRemoveFocus(event: FocusEvent): boolean;
29
+ protected _shouldRemoveFocus(event: FocusEvent): boolean;
31
30
  }
32
-
33
- export { FocusMixinConstructor, FocusMixin };
@@ -35,6 +35,14 @@ window.addEventListener(
35
35
  export const FocusMixin = dedupingMixin(
36
36
  (superclass) =>
37
37
  class FocusMixinClass extends superclass {
38
+ /**
39
+ * @protected
40
+ * @return {boolean}
41
+ */
42
+ get _keyboardActive() {
43
+ return keyboardActive;
44
+ }
45
+
38
46
  /** @protected */
39
47
  ready() {
40
48
  this.addEventListener('focusin', (e) => {
@@ -78,13 +86,13 @@ export const FocusMixin = dedupingMixin(
78
86
 
79
87
  // focus-ring is true when the element was focused from the keyboard.
80
88
  // Focus Ring [A11ycasts]: https://youtu.be/ilj2P5-5CjI
81
- this.toggleAttribute('focus-ring', focused && keyboardActive);
89
+ this.toggleAttribute('focus-ring', focused && this._keyboardActive);
82
90
  }
83
91
 
84
92
  /**
85
93
  * Override to define if the field receives focus based on the event.
86
94
  *
87
- * @param {FocusEvent} event
95
+ * @param {FocusEvent} _event
88
96
  * @return {boolean}
89
97
  * @protected
90
98
  */
@@ -95,7 +103,7 @@ export const FocusMixin = dedupingMixin(
95
103
  /**
96
104
  * Override to define if the field loses focus based on the event.
97
105
  *
98
- * @param {FocusEvent} event
106
+ * @param {FocusEvent} _event
99
107
  * @return {boolean}
100
108
  * @protected
101
109
  */