@ornery/web-components 4.0.0 → 4.0.1

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": "@ornery/web-components",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "WebComponents html loader and optional runtime mixins to enable creation of custom HTML elements using es6 template literal syntax in *.html files.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,22 +1,30 @@
1
1
  export default function setupConnect(nodeList, context) {
2
2
  nodeList.connect = function (root) {
3
- if (typeof HTMLElement !== "undefined") {
4
- if (!root && context instanceof HTMLElement) {
5
- root = context;
6
- if (
7
- root instanceof HTMLElement &&
8
- root.shadowRoot &&
9
- root.shadowRoot.mode === "open"
10
- ) {
11
- root = root.shadowRoot;
12
- } else {
13
- root = document.createElement("div");
14
- }
15
- root.innerHTML = "";
16
- nodeList.forEach((node) => root.appendChild(node));
17
- return root;
3
+ if (typeof HTMLElement === "undefined") {
4
+ return;
5
+ }
6
+
7
+ if (root) {
8
+ // Explicit root provided — clear and append nodes.
9
+ root.innerHTML = "";
10
+ nodeList.forEach((node) => root.appendChild(node));
11
+ return root;
12
+ }
13
+
14
+ // No root provided — derive from context.
15
+ if (context instanceof HTMLElement) {
16
+ if (
17
+ context.shadowRoot &&
18
+ context.shadowRoot.mode === "open"
19
+ ) {
20
+ root = context.shadowRoot;
21
+ } else {
22
+ root = document.createElement("div");
18
23
  }
24
+ root.innerHTML = "";
25
+ nodeList.forEach((node) => root.appendChild(node));
26
+ return root;
19
27
  }
20
28
  };
21
29
  return nodeList;
22
- };
30
+ }