nbhi 0.6.7 → 0.6.9
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/README.md +10 -5
- package/javascript/attributes.js +5 -1
- package/javascript/index.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**HTML includes and reactive rendering, all without any build tools**
|
|
4
4
|
|
|
5
|
-
No-build HTML includes (NBHI) is a simple **
|
|
5
|
+
No-build HTML includes (NBHI) is a simple **4.3KB** library that allows you to include html files into other html files and turns them into [web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components). Lazy initialization of content (when entering the viewport) and a one line call to update/hydrate content and attributes in your html pages. No build tools required, no `package.json` needed.
|
|
6
6
|
|
|
7
7
|
# Why?
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ NBHI minimizes abstractions, just standard HTML, CSS and Javascript. Migrating f
|
|
|
15
15
|
# Benefits
|
|
16
16
|
|
|
17
17
|
- No-build web applications (you can still make it a dependency via npm install) 👍
|
|
18
|
-
- Lightweight: **~
|
|
18
|
+
- Lightweight: **~4.3KB** (minified and bundled) 👍
|
|
19
19
|
- No dependencies 👍
|
|
20
20
|
- Benefit from standard web component encapsulation 👍
|
|
21
21
|
- Lazy load page content, when about to enter the viewport 👍
|
|
@@ -67,7 +67,7 @@ index.html
|
|
|
67
67
|
<my-component>Overwritten text</my-component>
|
|
68
68
|
|
|
69
69
|
<script type="module">
|
|
70
|
-
import initialize from '/
|
|
70
|
+
import initialize from '/nbhi.js';
|
|
71
71
|
await initialize(); // await if external templates
|
|
72
72
|
</script>
|
|
73
73
|
</body>
|
|
@@ -86,7 +86,12 @@ index.html
|
|
|
86
86
|
<script>
|
|
87
87
|
// Runs for each instance, fires on the standard connectedCallback
|
|
88
88
|
// element is the web component instance
|
|
89
|
-
export default element => {
|
|
89
|
+
export default await (element, importer) => {
|
|
90
|
+
// Path needs to be from the root of your project
|
|
91
|
+
// Use the importer to load files, it will make the path absolute in order
|
|
92
|
+
// to load the file. As the script tag is cloned and injected it has no
|
|
93
|
+
// sense of where it lives so it needs absolute paths
|
|
94
|
+
const { x } = await importer('/file/toLoad.js');
|
|
90
95
|
...
|
|
91
96
|
}
|
|
92
97
|
</script>
|
|
@@ -108,7 +113,7 @@ index.html
|
|
|
108
113
|
<my-component>Overwrite</my-component>
|
|
109
114
|
|
|
110
115
|
<script type="module">
|
|
111
|
-
import initialize from '/
|
|
116
|
+
import initialize from '/nbhi.js';
|
|
112
117
|
initialize(); // No await needed for internal templates
|
|
113
118
|
</script>
|
|
114
119
|
</body>
|
package/javascript/attributes.js
CHANGED
|
@@ -99,7 +99,11 @@ function updateAttributes({ name, value, attributeMapping, root }) {
|
|
|
99
99
|
const { type, tagNames = [] } = attributeMapping[name] ?? [];
|
|
100
100
|
|
|
101
101
|
if (type === 'userDefined') {
|
|
102
|
-
|
|
102
|
+
if (root.hasAttribute && root.hasAttribute(name)) {
|
|
103
|
+
process(root);
|
|
104
|
+
} else {
|
|
105
|
+
process(root.querySelector(`[${ name }]`));
|
|
106
|
+
}
|
|
103
107
|
} else {
|
|
104
108
|
tagNames.forEach(tagName => {
|
|
105
109
|
root.querySelectorAll(tagName).forEach(process);
|
package/javascript/index.js
CHANGED
|
@@ -115,7 +115,10 @@ async function initialize({ prefix = 'db', source = '/components' } = {}) {
|
|
|
115
115
|
|
|
116
116
|
connectedCallback() {
|
|
117
117
|
if (typeof script === 'function') {
|
|
118
|
-
script(this
|
|
118
|
+
script(this, path => {
|
|
119
|
+
const baseUrl = new URL('./', import.meta.url).origin;
|
|
120
|
+
return import(`${ baseUrl }${ path }`);
|
|
121
|
+
});
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nbhi",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "No-Build HTML Includes (NBHI) is a simple library that allows you to include html files into other html files and turns them into [web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components). Lazy initialization of content (when entering the viewport) and a one line call to update/hydrate content in your html pages. No build tools required, no `package.json` needed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|