@vaadin/component-base 24.1.0 → 24.2.0-alpha1
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 +3 -3
- package/src/dom-utils.d.ts +6 -0
- package/src/dom-utils.js +16 -0
- package/src/element-mixin.js +1 -1
- package/src/slot-controller.js +6 -2
- package/src/url-utils.d.ts +10 -0
- package/src/url-utils.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.2.0-alpha1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@esm-bundle/chai": "^4.3.4",
|
|
42
|
-
"@vaadin/testing-helpers": "^0.4.
|
|
42
|
+
"@vaadin/testing-helpers": "^0.4.2",
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0dbb118320203ab6c0c07450a3e718815367589f"
|
|
46
46
|
}
|
package/src/dom-utils.d.ts
CHANGED
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export function getAncestorRootNodes(node: Node): Node[];
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Traverses the given node and its parents, including those that are across
|
|
18
|
+
* the shadow root boundaries, until it finds a node that matches the selector.
|
|
19
|
+
*/
|
|
20
|
+
export function getClosestElement(selector: string, node: Node): Node | null;
|
|
21
|
+
|
|
16
22
|
/**
|
|
17
23
|
* Takes a string with values separated by space and returns a set the values
|
|
18
24
|
*/
|
package/src/dom-utils.js
CHANGED
|
@@ -40,6 +40,22 @@ export function getAncestorRootNodes(node) {
|
|
|
40
40
|
return result;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Traverses the given node and its parents, including those that are across
|
|
45
|
+
* the shadow root boundaries, until it finds a node that matches the selector.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} selector The CSS selector to match against
|
|
48
|
+
* @param {Node} node The starting node for the traversal
|
|
49
|
+
* @return {Node | null} The closest matching element, or null if no match is found
|
|
50
|
+
*/
|
|
51
|
+
export function getClosestElement(selector, node) {
|
|
52
|
+
if (!node) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return node.closest(selector) || getClosestElement(selector, node.getRootNode().host);
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
/**
|
|
44
60
|
* Takes a string with values separated by space and returns a set the values
|
|
45
61
|
*
|
package/src/element-mixin.js
CHANGED
package/src/slot-controller.js
CHANGED
|
@@ -81,8 +81,10 @@ export class SlotController extends EventTarget {
|
|
|
81
81
|
|
|
82
82
|
if (children.length === 0) {
|
|
83
83
|
const defaultNode = this.attachDefaultNode();
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
if (defaultNode) {
|
|
85
|
+
this.nodes = [defaultNode];
|
|
86
|
+
this.initNode(defaultNode);
|
|
87
|
+
}
|
|
86
88
|
} else {
|
|
87
89
|
this.nodes = children;
|
|
88
90
|
children.forEach((node) => {
|
|
@@ -205,6 +207,8 @@ export class SlotController extends EventTarget {
|
|
|
205
207
|
const newNodes = info.addedNodes.filter((node) => !isEmptyTextNode(node) && !current.includes(node));
|
|
206
208
|
|
|
207
209
|
if (info.removedNodes.length) {
|
|
210
|
+
this.nodes = current.filter((node) => !info.removedNodes.includes(node));
|
|
211
|
+
|
|
208
212
|
info.removedNodes.forEach((node) => {
|
|
209
213
|
this.teardownNode(node);
|
|
210
214
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Check if two paths match
|
|
9
|
+
*/
|
|
10
|
+
export declare function matchPaths(path1: string, path2: string): boolean;
|
package/src/url-utils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Check if two paths match
|
|
9
|
+
*
|
|
10
|
+
* @param {string} path1
|
|
11
|
+
* @param {string} path2
|
|
12
|
+
*/
|
|
13
|
+
export function matchPaths(path1, path2) {
|
|
14
|
+
const base = document.baseURI;
|
|
15
|
+
return new URL(path1, base).pathname === new URL(path2, base).pathname;
|
|
16
|
+
}
|