@blackbirdjs/component 0.1.1 → 0.1.3
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/component.js +33 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbirdjs/component",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Template-first fine-grained Web Component layer for BlackbirdJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
".": "./src/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@blackbirdjs/store": "^0.
|
|
11
|
+
"@blackbirdjs/store": "^0.2.0"
|
|
12
12
|
},
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"publishConfig": {
|
package/src/component.js
CHANGED
|
@@ -26,25 +26,47 @@ export class BlackbirdComponent extends HTMLElement {
|
|
|
26
26
|
this.localStore.set(cleanKey, newValue);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
connectedCallback() {
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
async connectedCallback() {
|
|
30
|
+
// Check if the developer provided an external template file path string
|
|
31
|
+
const path = this.constructor.templatePath;
|
|
32
|
+
|
|
33
|
+
if (path) {
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetch(path);
|
|
36
|
+
const htmlText = await response.text();
|
|
37
|
+
|
|
38
|
+
// Convert the fetched raw text string into browser-executable DOM elements
|
|
39
|
+
const parser = new DOMParser();
|
|
40
|
+
const doc = parser.parseFromString(htmlText, 'text/html');
|
|
41
|
+
|
|
42
|
+
// Append it cleanly inside the isolated Shadow DOM
|
|
43
|
+
this.shadowRoot.innerHTML = doc.body.innerHTML;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error(`[Blackbird] Failed to fetch external template at: ${path}`, err);
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
// Fall back to <template id="..."> matching rule if no path exists
|
|
50
|
+
if (!this.shadowRoot.innerHTML) {
|
|
51
|
+
const templateId = this.getAttribute('template');
|
|
52
|
+
const template = document.getElementById(templateId);
|
|
53
|
+
|
|
54
|
+
if (!template) {
|
|
55
|
+
console.error(`[Blackbird] Template with id "${templateId}" not found.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Changed contentEditable to template.content
|
|
60
|
+
const clone = template.content.cloneNode(true);
|
|
61
|
+
this.shadowRoot.appendChild(clone);
|
|
62
|
+
}
|
|
41
63
|
|
|
42
64
|
this._hydrateInitialAttributes();
|
|
43
65
|
this._compileDOM();
|
|
44
66
|
}
|
|
45
67
|
|
|
46
68
|
// Automatically clean up memory when the component leaves the screen
|
|
47
|
-
disconnectedCallback() {
|
|
69
|
+
async disconnectedCallback() {
|
|
48
70
|
this.#unsubscribers.forEach(unsubscribe => unsubscribe());
|
|
49
71
|
this.#unsubscribers = [];
|
|
50
72
|
}
|