@vaadin/component-base 23.2.0-beta2 → 23.2.0-beta3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/component-base",
3
- "version": "23.2.0-beta2",
3
+ "version": "23.2.0-beta3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,5 +42,5 @@
42
42
  "@vaadin/testing-helpers": "^0.3.2",
43
43
  "sinon": "^13.0.2"
44
44
  },
45
- "gitHead": "42864949ade7e573ac534a64ecdd97fab32a87fc"
45
+ "gitHead": "3389e7d2dd4c94c6354817d4dc8c8d2db48c7137"
46
46
  }
@@ -12,3 +12,14 @@
12
12
  * and involves both the light DOM and ancestor shadow DOM trees.
13
13
  */
14
14
  export function getAncestorRootNodes(node: Node): Node[];
15
+
16
+ /**
17
+ * Adds a value to an attribute containing space-delimited values.
18
+ */
19
+ export function addValueToAttribute(element: HTMLElement, attr: string, value: string): void;
20
+
21
+ /**
22
+ * Removes a value from an attribute containing space-delimited values.
23
+ * If the value is the last one, the whole attribute is removed.
24
+ */
25
+ export function removeValueFromAttribute(element: HTMLElement, attr: string, value: string): void;
package/src/dom-utils.js CHANGED
@@ -39,3 +39,54 @@ export function getAncestorRootNodes(node) {
39
39
 
40
40
  return result;
41
41
  }
42
+
43
+ /**
44
+ * @param {string} value
45
+ * @return {Set<string>}
46
+ */
47
+ function deserializeAttributeValue(value) {
48
+ if (!value) {
49
+ return new Set();
50
+ }
51
+
52
+ return new Set(value.split(' '));
53
+ }
54
+
55
+ /**
56
+ * @param {Set<string>} values
57
+ * @return {string}
58
+ */
59
+ function serializeAttributeValue(values) {
60
+ return [...values].join(' ');
61
+ }
62
+
63
+ /**
64
+ * Adds a value to an attribute containing space-delimited values.
65
+ *
66
+ * @param {HTMLElement} element
67
+ * @param {string} attr
68
+ * @param {string} value
69
+ */
70
+ export function addValueToAttribute(element, attr, value) {
71
+ const values = deserializeAttributeValue(element.getAttribute(attr));
72
+ values.add(value);
73
+ element.setAttribute(attr, serializeAttributeValue(values));
74
+ }
75
+
76
+ /**
77
+ * Removes a value from an attribute containing space-delimited values.
78
+ * If the value is the last one, the whole attribute is removed.
79
+ *
80
+ * @param {HTMLElement} element
81
+ * @param {string} attr
82
+ * @param {string} value
83
+ */
84
+ export function removeValueFromAttribute(element, attr, value) {
85
+ const values = deserializeAttributeValue(element.getAttribute(attr));
86
+ values.delete(value);
87
+ if (values.size === 0) {
88
+ element.removeAttribute(attr);
89
+ return;
90
+ }
91
+ element.setAttribute(attr, serializeAttributeValue(values));
92
+ }
@@ -39,7 +39,7 @@ const registered = new Set();
39
39
  export const ElementMixin = (superClass) =>
40
40
  class VaadinElementMixin extends DirMixin(superClass) {
41
41
  static get version() {
42
- return '23.2.0-beta2';
42
+ return '23.2.0-beta3';
43
43
  }
44
44
 
45
45
  /** @protected */
@@ -4,28 +4,7 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
-
8
- // We consider the keyboard to be active if the window has received a keydown
9
- // event since the last mousedown event.
10
- let keyboardActive = false;
11
-
12
- // Listen for top-level keydown and mousedown events.
13
- // Use capture phase so we detect events even if they're handled.
14
- window.addEventListener(
15
- 'keydown',
16
- () => {
17
- keyboardActive = true;
18
- },
19
- { capture: true },
20
- );
21
-
22
- window.addEventListener(
23
- 'mousedown',
24
- () => {
25
- keyboardActive = false;
26
- },
27
- { capture: true },
28
- );
7
+ import { isKeyboardActive } from './focus-utils.js';
29
8
 
30
9
  /**
31
10
  * A mixin to handle `focused` and `focus-ring` attributes based on focus.
@@ -40,7 +19,7 @@ export const FocusMixin = dedupingMixin(
40
19
  * @return {boolean}
41
20
  */
42
21
  get _keyboardActive() {
43
- return keyboardActive;
22
+ return isKeyboardActive();
44
23
  }
45
24
 
46
25
  /** @protected */
@@ -4,6 +4,12 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
7
+ /**
8
+ * Returns true if the window has received a keydown
9
+ * event since the last mousedown event.
10
+ */
11
+ export declare function isKeyboardActive(): boolean;
12
+
7
13
  /**
8
14
  * Returns true if the element is hidden, false otherwise.
9
15
  *
@@ -4,6 +4,38 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
7
+ // We consider the keyboard to be active if the window has received a keydown
8
+ // event since the last mousedown event.
9
+ let keyboardActive = false;
10
+
11
+ // Listen for top-level keydown and mousedown events.
12
+ // Use capture phase so we detect events even if they're handled.
13
+ window.addEventListener(
14
+ 'keydown',
15
+ () => {
16
+ keyboardActive = true;
17
+ },
18
+ { capture: true },
19
+ );
20
+
21
+ window.addEventListener(
22
+ 'mousedown',
23
+ () => {
24
+ keyboardActive = false;
25
+ },
26
+ { capture: true },
27
+ );
28
+
29
+ /**
30
+ * Returns true if the window has received a keydown
31
+ * event since the last mousedown event.
32
+ *
33
+ * @return {boolean}
34
+ */
35
+ export function isKeyboardActive() {
36
+ return keyboardActive;
37
+ }
38
+
7
39
  /**
8
40
  * Returns true if the element is hidden directly with `display: none` or `visibility: hidden`,
9
41
  * false otherwise.