@vaadin/component-base 23.1.0-rc2 → 23.1.0-rc3
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 +2 -2
- package/src/dom-utils.d.ts +14 -0
- package/src/dom-utils.js +41 -0
- package/src/element-mixin.js +1 -1
- package/src/keyboard-mixin.d.ts +14 -1
- package/src/keyboard-mixin.js +36 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "23.1.0-
|
|
3
|
+
"version": "23.1.0-rc3",
|
|
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": "
|
|
45
|
+
"gitHead": "49c312fbe0228adb559296d45655bbfd4eac6235"
|
|
46
46
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* Returns an array of ancestor root nodes for the given node.
|
|
9
|
+
*
|
|
10
|
+
* A root node is either a document node or a document fragment node (Shadow Root).
|
|
11
|
+
* The array is collected by a bottom-up DOM traversing that starts with the given node
|
|
12
|
+
* and involves both the light DOM and ancestor shadow DOM trees.
|
|
13
|
+
*/
|
|
14
|
+
export function getAncestorRootNodes(node: Node): Node[];
|
package/src/dom-utils.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
* Returns an array of ancestor root nodes for the given node.
|
|
9
|
+
*
|
|
10
|
+
* A root node is either a document node or a document fragment node (Shadow Root).
|
|
11
|
+
* The array is collected by a bottom-up DOM traversing that starts with the given node
|
|
12
|
+
* and involves both the light DOM and ancestor shadow DOM trees.
|
|
13
|
+
*
|
|
14
|
+
* @param {Node} node
|
|
15
|
+
* @return {Node[]}
|
|
16
|
+
*/
|
|
17
|
+
export function getAncestorRootNodes(node) {
|
|
18
|
+
const result = [];
|
|
19
|
+
|
|
20
|
+
while (node) {
|
|
21
|
+
if (node.nodeType === Node.DOCUMENT_NODE) {
|
|
22
|
+
result.push(node);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
27
|
+
result.push(node);
|
|
28
|
+
node = node.host;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (node.assignedSlot) {
|
|
33
|
+
node = node.assignedSlot;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
node = node.parentNode;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result;
|
|
41
|
+
}
|
package/src/element-mixin.js
CHANGED
package/src/keyboard-mixin.d.ts
CHANGED
|
@@ -14,7 +14,20 @@ export declare function KeyboardMixin<T extends Constructor<HTMLElement>>(base:
|
|
|
14
14
|
|
|
15
15
|
export declare class KeyboardMixinClass {
|
|
16
16
|
/**
|
|
17
|
-
* A handler for the
|
|
17
|
+
* A handler for the "Enter" key. By default, it does nothing.
|
|
18
|
+
* Override the method to implement your own behavior.
|
|
19
|
+
*/
|
|
20
|
+
protected _onEnter(event: KeyboardEvent): void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A handler for the "Escape" key. By default, it does nothing.
|
|
24
|
+
* Override the method to implement your own behavior.
|
|
25
|
+
*/
|
|
26
|
+
protected _onEscape(event: KeyboardEvent): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A handler for the `keydown` event. By default, it calls
|
|
30
|
+
* separate methods for handling "Enter" and "Escape" keys.
|
|
18
31
|
* Override the method to implement your own behavior.
|
|
19
32
|
*/
|
|
20
33
|
protected _onKeyDown(event: KeyboardEvent): void;
|
package/src/keyboard-mixin.js
CHANGED
|
@@ -29,14 +29,24 @@ export const KeyboardMixin = dedupingMixin(
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* A handler for the `keydown` event. By default, it
|
|
32
|
+
* A handler for the `keydown` event. By default, it calls
|
|
33
|
+
* separate methods for handling "Enter" and "Escape" keys.
|
|
33
34
|
* Override the method to implement your own behavior.
|
|
34
35
|
*
|
|
35
|
-
* @param {KeyboardEvent}
|
|
36
|
+
* @param {KeyboardEvent} event
|
|
36
37
|
* @protected
|
|
37
38
|
*/
|
|
38
|
-
_onKeyDown(
|
|
39
|
-
|
|
39
|
+
_onKeyDown(event) {
|
|
40
|
+
switch (event.key) {
|
|
41
|
+
case 'Enter':
|
|
42
|
+
this._onEnter(event);
|
|
43
|
+
break;
|
|
44
|
+
case 'Escape':
|
|
45
|
+
this._onEscape(event);
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
/**
|
|
@@ -49,5 +59,27 @@ export const KeyboardMixin = dedupingMixin(
|
|
|
49
59
|
_onKeyUp(_event) {
|
|
50
60
|
// To be implemented.
|
|
51
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A handler for the "Enter" key. By default, it does nothing.
|
|
65
|
+
* Override the method to implement your own behavior.
|
|
66
|
+
*
|
|
67
|
+
* @param {KeyboardEvent} _event
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
_onEnter(_event) {
|
|
71
|
+
// To be implemented.
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A handler for the "Escape" key. By default, it does nothing.
|
|
76
|
+
* Override the method to implement your own behavior.
|
|
77
|
+
*
|
|
78
|
+
* @param {KeyboardEvent} _event
|
|
79
|
+
* @protected
|
|
80
|
+
*/
|
|
81
|
+
_onEscape(_event) {
|
|
82
|
+
// To be implemented.
|
|
83
|
+
}
|
|
52
84
|
},
|
|
53
85
|
);
|