nbhi 0.6.0 → 0.6.2

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 CHANGED
@@ -2,25 +2,27 @@
2
2
 
3
3
  **HTML includes and reactive rendering, all without any build tools**
4
4
 
5
- d--b is a simple **4KB** 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
+ No-build HTML includes (NBHI) is a simple **3.9KB** 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
 
9
- d--b is developed to create real-time data driven web sites. It has lower complexity than typical SPA applications but still offers more interactivy and flexibility than server side rendered web sites. _It works well with serverless application and a pub/sub data model_.
9
+ NBHI is developed to create real-time data driven web sites. It has lower complexity than typical SPA applications but still offers more interactivy and flexibility than server side rendered web sites. _It works well with serverless application and a pub/sub data model_.
10
10
 
11
- d--b is designed to be composable with other packages to build web sites. It takes the Lego approach, you select the packages for your needs, no lock-in into a single framework with a potential steep learning curve. d--b is build on standard browser supported technologies which means that you only need to read MDN as the source of knowledge.
11
+ NBHI is designed to be composable with other packages to build web sites. It takes the Lego approach, you select the packages for your needs, no lock-in into a single framework with a potential steep learning curve. NBHI is build on standard browser supported technologies which means that you only need to read MDN as the source of knowledge.
12
12
 
13
- d--b minimizes abstractions, just standard HTML, CSS and Javascript. Migrating from a SPA to d--b's multi page application (MPA) approach should mean you can do this one page at the time not having to migrate your whole system at once and pray that everything keeps working.
13
+ NBHI minimizes abstractions, just standard HTML, CSS and Javascript. Migrating from a SPA to NBHI's multi page application (MPA) approach should mean you can do this one page at the time not having to migrate your whole system at once and pray that everything keeps working.
14
14
 
15
15
  # Benefits
16
16
 
17
- - Buildless web applications (minification is still possible of course) 👍
18
- - Lightweight: **~4KB** 👍
17
+ - No-build web applications (you can still make it a dependency via npm install) 👍
18
+ - Lightweight: **~3.9KB** (minified and bundled) 👍
19
+ - No dependencies 👍
19
20
  - Benefit from standard web component encapsulation 👍
20
21
  - Lazy load page content, when about to enter the viewport 👍
21
22
  - Just standard web technologies, little abstractions 👍
22
- - Composable with other packages
23
- - Support for web component form fields out of the box 👍
23
+ - Simple single function to hydrate your html (including attributes) 👍
24
+ - Support for form validation for web component based html fields 👍
25
+ - Composable with other packages 👍
24
26
  - Multi Page Application (MPA) design
25
27
  - The standard method how the web communicates between server and client 👍
26
28
  - Normal native routing 👍
@@ -28,6 +30,23 @@ d--b minimizes abstractions, just standard HTML, CSS and Javascript. Migrating f
28
30
  - Each page loads what it needs and no more 👍
29
31
  - Fast initial draw 👍
30
32
 
33
+ # Install
34
+
35
+ For no-build solutions:
36
+
37
+ ```js
38
+ <script type="module">
39
+ import { initialize } from 'https://esm.run/nbhi@x.x.x';
40
+ await initialize();
41
+ </script>
42
+ ```
43
+
44
+ For build solutions
45
+
46
+ ```cli
47
+ npm install nbhi
48
+ ```
49
+
31
50
  # Examples
32
51
 
33
52
  Please look in the **examples.html** for working examples.
@@ -43,30 +62,34 @@ Templates let you build complex systems and reuse components accross multiple pa
43
62
  index.html
44
63
 
45
64
  ```html
46
-
47
65
  <html>
48
66
  <body>
49
67
  <my-component>Overwritten text</my-component>
50
68
 
51
69
  <script type="module">
52
- import initialize from '/d--b.js';
53
- await initialize(); // await if loading external templates
70
+ import initialize from '/NBHI.js';
71
+ await initialize(); // await if external templates
54
72
  </script>
55
73
  </body>
56
74
  </html>
57
-
58
75
  ```
59
76
 
60
- /components/my-component.html
77
+ /components/component.html
61
78
 
62
79
  ```html
63
-
64
80
  <div>
65
81
  <slot>Default text</slot>
66
82
  </div>
67
83
 
68
84
  <style>/* Scoped to the web component */</style>
69
85
 
86
+ <script>
87
+ // Runs for each instance, fires on the standard connectedCallback
88
+ // element is the web component instance
89
+ export default element => {
90
+ ...
91
+ }
92
+ </script>
70
93
  ```
71
94
 
72
95
  ### Internal templates
@@ -74,9 +97,9 @@ index.html
74
97
  index.html
75
98
 
76
99
  ```html
77
-
78
100
  <html>
79
101
  <body>
102
+ <!-- id becomes the name of your web component -->
80
103
  <template id="my-component">
81
104
  <slot>Default</slot>
82
105
  <style>/* Scoped to the web component */</style>
@@ -85,180 +108,199 @@ index.html
85
108
  <my-component>Overwrite</my-component>
86
109
 
87
110
  <script type="module">
88
- import initialize from '/d--b.js';
111
+ import initialize from '/NBHI.js';
89
112
  initialize(); // No await needed for internal templates
90
113
  </script>
91
114
  </body>
92
115
  </html>
93
-
94
116
  ```
95
117
 
96
- _Note: When you use an internal `<template>` you need to define an id, which will be the name of the tag._
97
-
98
118
  ## Options
99
119
 
100
120
  ```js
101
-
102
- /**
103
- * Options for initiating an instance
104
- * @param {string} [prefix=db]
105
- * @param {string} [source=/components]
106
- **/
107
-
108
- import initialize from 'd--b.js'
109
- initialize({
110
- // Prefix to use, ie <db-input> or <db-nav>
111
- prefix: 'db',
112
- // Where to find external web components, if string it will be a director
113
- // when using an object the key is the name (without prefix) of the component
114
- // and the value the path to the web-component
115
- directory: '/components',
116
- });
117
-
121
+ initialize({ prefix = 'my', directory = '/components' }); // Defaults
118
122
  ```
119
123
 
120
- ## Methods
121
-
122
- ### .setSlot(value, [slotName], [htmlSelector])
123
-
124
124
  ```js
125
- /**
126
- * Update data in a <slot> tag
127
- * @param {string} value - What you want to assign to a <slot>
128
- * @param {string} [slotName] - If not given value is assigned to default <slot>
129
- * @param {string} [htmlSelector] - Target a html tag in a complex <slot>
130
- **/
125
+ initialize({ prefix: 'x' }); // Components are now x-component
126
+ ```
131
127
 
132
- const element = document.querySelector('my-component');
128
+ ```js
129
+ initialize({ components: '/abc' }); // Fetches files in /abc/component.html
130
+ ```
133
131
 
134
- // To default slot
135
- element.setSlot('Some text');
132
+ ```js
133
+ // key = name of component (no prefix), value is path to file
134
+ initialize({ components: {
135
+ nav: '/shared/nav.html',
136
+ dropdown: '/components/dropdown.html'
137
+ } });
138
+ ```
136
139
 
137
- // To slot named title
138
- element.setSlot('Some text', 'title');
140
+ ## Update a single component (data and attributes)
139
141
 
140
- // To slot named title and withing the <em> tag
141
- element.setSlot('Some text', 'title', 'em');
142
+ ### Via HTML
142
143
 
144
+ ```html
145
+ <!-- Instance -->
146
+ <my-component checked data-id="1">
147
+ Text here will be assigned to the default slot
148
+ <span slot="title">Will be assigned to the named slot</span>
149
+ </my-component>
150
+
151
+ <!-- Component definition -->
152
+ <section data-id=""> <!-- Data and custom attributes need to be defined so NBHI can resolve them -->
153
+ <input type="checkbox"> <!-- NBHI automatically maps common attributes, checked will be placed on the input -->
154
+ <slot>Default text</slot>
155
+ <slot name="title">Default title</slot>
156
+ </section>
143
157
  ```
144
158
 
145
- ### .setChildren(data, [wrapperTag])
159
+ ### Via JS
146
160
 
147
161
  ```js
148
- /**
149
- * Updates one or more records in the child template
150
- * @param {object|object[]} data - The data to use
151
- **/
162
+ import { update } from 'nbhi';
152
163
 
153
- const element = document.querySelector('my-component');
154
-
155
- // Update a single child, with data-slot named "title"
156
- element.setChildren({ title: 'Some value' });
164
+ const updater = update('my-component');
157
165
 
166
+ updater('Text here will be assigned to the default slot');
167
+ updater({ title: 'Will be assigned to the named slot' });
168
+ updater({ $checked: true, `$data-id`: 1 }); // Atributes are prefixed with $
158
169
  ```
159
170
 
160
- _Note: Child templates always need to extend an existing tag, like `<tr>`, `<option>`, `<div>`, etc. This is because some parents like `<tbody>`, `<select>` will not render regular non extended web components._
171
+ ## Update a list (data and attributes)
161
172
 
162
- ### .onceVisible(callback)
173
+ ### Inline child
163
174
 
164
- ```js
165
- /**
166
- * Runs one time when the web component comes into view
167
- * @param {function} callback - Callback to run
168
- **/
169
- document.querySelector('my-component').onceVisible(element => {
170
- subscribeToData('someCollection', data => element.setChildren(data));
171
- });
175
+ /components/component.html
172
176
 
177
+ ```html
178
+ <div>
179
+ <h1><slot>Header</slot></h1>
180
+ <div child> <!-- NBHI uses child attribute to make clones from -->
181
+ <p data-slot="name"></p> <!-- use data-slot for inline children -->
182
+ </div>
183
+ </div>
173
184
  ```
174
185
 
175
- ### .checkValidity() (Only if the webcomponent includes a form element)
176
-
177
- ```js
178
- /**
179
- * Checks if the field is valid
180
- * @returns boolean
181
- **/
182
- document.querySelector('my-form-field').checkValidity();
186
+ index.html
183
187
 
188
+ ```html
189
+ <my-component>Header overwrite</my-component>
190
+
191
+ <script>
192
+ import { initialize, update } from 'nbhi';
193
+ await initialize();
194
+ update('my-component')([
195
+ { name: 'Record 1' },
196
+ { name: 'Record 2' },
197
+ ]);
198
+ </script>
184
199
  ```
185
200
 
186
- ### .validity (Only if the webcomponent includes a form element)
201
+ ### Child component
187
202
 
188
- ```js
189
- /**
190
- * Get the standard validity object
191
- * @returns ValidityState
192
- **/
193
- document.querySelector('my-form-field').validity;
203
+ /components/component.html
194
204
 
205
+ ```html
206
+ <div>
207
+ <h1><slot>Header</slot></h1>
208
+ <my-child child></my-child> <!-- NBHI uses child attribute to make clones from -->
209
+ </div>
195
210
  ```
196
211
 
197
- ### .validationMessage() (Only if the webcomponent includes a form element)
212
+ /components/child.html
198
213
 
199
- ```js
200
- /**
201
- * Gets the message for an invalid field, handy for bespoke themes
202
- * @returns string
203
- **/
204
- document.querySelector('my-form-field').validationMessage();
214
+ ```html
215
+ <div>
216
+ <p><slot></slot></p> <!-- use regular slot for nested components -->
217
+ </div>
218
+ ```
219
+
220
+ index.html
205
221
 
222
+ ```html
223
+ <my-component>Header overwrite</my-component>
224
+
225
+ <script>
226
+ import { initialize, update } from 'nbhi';
227
+ await initialize();
228
+ update('my-component')(['Record 1', 'Record 2']);
229
+ </script>
206
230
  ```
207
231
 
208
- ### Attributes
232
+ ### List data for `<table>, <ol>, <li> and <option>`
209
233
 
210
- It is possible to set attributes on a web component instance tag like `<my-component>` and they will automatically be assigned to the correct nodes in the underlying `<template>`. Any changes you make to the `<my-component>` attributes will automatically update the underlying component data.
234
+ These elements do not support web component children. So for these you can just define the following
211
235
 
212
236
  index.html
213
237
 
214
238
  ```html
239
+ <template id="my-table">
240
+ <table>
241
+ <thead>
242
+ <tr>
243
+ <th>Header</th>
244
+ </tr>
245
+ </thead>
246
+ <tbody> <!-- Required -->
247
+ <tr> <!-- No need for child attribute -->
248
+ <td data-slot="name"></td>
249
+ </tr>
250
+ </tbody>
251
+ </table>
252
+ </template>
253
+
254
+ index.html
215
255
 
216
- <my-email data-id="1" value="me@me.com" readonly>User Email</my-email>
256
+ <my-table></my-table>
217
257
 
258
+ <script>
259
+ import { initialize, update } from 'nbhi';
260
+ await initialize();
261
+ update('my-table')([
262
+ { name: 'Record 1' },
263
+ { name: 'Record 2' },
264
+ ]);
265
+ </script>
218
266
  ```
219
267
 
220
- my-component.html
268
+ Same logic for `<ol>`, `<ul>` and `<option>`
221
269
 
222
- ```html
223
- <!--
224
- Custom attributes like data-id need to be defined in the template, otherwise
225
- d--b does not know where to assign the value
226
- -->
227
- <label data-id="">
228
- <slot></slot>
229
- <!-- d--b knows to add value and read only to the input field --->
230
- <input type="email" placeholder="email">
231
- </div>
270
+ ## Lazy loading
271
+
272
+ ```js
273
+ import { onceVisible } form 'nbhi';
232
274
 
275
+ onceVisible('my-component', element => ...); // Will run once when it comes into view (200px before)
233
276
  ```
234
277
 
278
+ ## Validating a form field
279
+
235
280
  ```js
281
+ import { validate } form 'nbhi';
236
282
 
237
- // Calling from JS is also easier, you don't need to find the shadowRoot
238
- const element = document.querySelector('my-component')
239
- element.setAttribute('value', 'Some value');
240
- element.disabled = true;
283
+ const internals = validate('my-form-field'); // Returns elementInternals
241
284
 
285
+ // See MDN for details
286
+ internals.checkValidity();
287
+ internals.validity;
242
288
  ```
243
289
 
244
- _Note: If there are multiple elements that can have an attribute that has been defined on the component instance it will assign it to all instances. You can assign attributes to the `<template>` tag but only if it extends an existing tag_
245
-
246
- # FAQ
247
-
248
- ### How to pronounce d--b?
249
- However you like.
290
+ ## FAQ
250
291
 
251
292
  ### No build steps is nice, but I want to use TypeScript
293
+
252
294
  If you want to use TS you have a couple of options. You can either add a build step, nothing is stopping you, the library supports it. If you want to stay buildless but want to add some sort of type checking and hinting you can consider using JSDoc, it is [supported](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#author) in TS as well.
253
295
 
254
296
  ### Creating interactivity is verbose with native js DOM manipulation
255
- d--b is not designed to be a single solution for everything, if you want to make DOM manipulation for interactivity easier I would suggest using dedicated libraries for that. You can consider [Alpine.js](https://alpinejs.dev/) or [Umbrella.js](https://umbrellajs.com/) for example. d--b is designed with composibility in mind so you decide what to add.
256
297
 
257
- ### External npm packages require me the add build steps again
258
- You could load them from a CDN if you want to stay 100% buildless, otherwise you could just add a simple minifier and bundler. This will stay very lightweight but probably is more suitable for production environments.
298
+ NBHI is not designed to be a single solution for everything, if you want to make DOM manipulation for interactivity easier I would suggest using dedicated libraries for that. You can consider [Alpine.js](https://alpinejs.dev/) or [Umbrella.js](https://umbrellajs.com/) for example. NBHI is designed with composibility in mind so you decide what to add.
259
299
 
260
300
  ### Anybody using web component technology?
301
+
261
302
  Just check out the source code of github.com or youtube.com.
262
303
 
263
304
  ### We are a team of multiple developers, using a framework ensures we write similar code
264
- You are correct, when you choose a more opinionated framework it will most likely give more cohesive code overall when you work with multiple developers. However it also gives you lock-in. It is a trade-off that you have to make, depending on the team size and how agile your codebase needs to remain.
305
+
306
+ You are correct, when you choose a more opinionated framework it will most likely give more cohesive code overall when you work with multiple developers. However it also gives you lock-in. It is a trade-off that you have to make, depending on the team size and how agile your codebase needs to remain.
package/index.min.js CHANGED
@@ -1,3 +1,4 @@
1
1
  var I={boolean:{autofocus:["button","input","select","textarea"],autoplay:["audio","video"],checked:["input"],controls:["audio","video"],default:["track"],defer:["script"],disabled:["button","input","optgroup","option","select","textarea","fieldset"],formnovalidate:["button","input"],ismap:["img"],loop:["audio","video"],multiple:["input","select"],muted:["audio","video"],novalidate:["form"],open:["details","dialog"],playsinline:["video"],readonly:["input","textarea"],required:["input","select","textarea"],reversed:["ol"]},keyValue:{accept:["input"],autocomplete:["input","select","textarea"],cols:["textarea"],dirname:["input","textarea"],max:["input"],maxlength:["input","textarea"],min:["input"],minlength:["input","textarea"],name:["input","select","textarea"],pattern:["input"],placeholder:["input","textarea"],rows:["textarea"],size:["input","select"],step:["input"],type:["input"],value:["input","select"],width:["input"],wrap:["textarea"],htmlFor:["label"],for:["label"],href:["a"],target:["a"],src:["audio","img","input","video"],"aria-invalid":["input","textarea","select"]},excludedAttributes:["class","extends","id","part","data-slot","child"],excludedElements:["slot","template","style","script"]};function q(c){let{keyValue:n,excludedAttributes:i,excludedElements:f,boolean:b}=I,d={};return p(c),d;function p(r){let S=r.localName;r&&typeof S=="string"&&!f.includes(r.localName)&&(Object.entries(b).filter(([o])=>!i.includes(o)).filter(([,o])=>o.includes(S)).forEach(([o,a])=>d[o]={type:"boolean",tagNames:a}),Object.entries(n).filter(([o])=>!i.includes(o)).filter(([,o])=>o.includes(S)).forEach(([o,a])=>d[o]={type:"keyValue",tagNames:a}),r.hasAttributes()&&[...r.attributes].forEach(o=>{let a=o.name;i.includes(a)||(d[a]||(d[a]={type:"userDefined",tagNames:[]}),d[a].tagNames.includes(S)||d[a].tagNames.push(S))})),[...r.children].forEach(o=>p(o))}}function j({name:c,value:n,attributeMapping:i,root:f}){let{type:b,tagNames:d=[]}=i[c]??[];b==="userDefined"?p(f.querySelector(`[${c}]`)):d.forEach(r=>{f.querySelectorAll(r).forEach(p),r===f?.localName&&p(f)});function p(r){r&&(n==null||b==="boolean"&&n===!1?r.removeAttribute(c):(r.setAttribute(c,n),c==="value"&&(r.value=n)))}}var N=c=>{if(typeof c=="string"){let n=document.querySelector(c);if(!n)throw new Error(`No elements found for selector ${c}`);return n}return c};var k=c=>{let n=N(c),i=new WeakMap,f=new WeakMap,b=new Map,d=1,p;return r=>{if(S(r))throw new Error("Please convert date to string, ie. toISOString()");s(r)?v(r):o(r)?A(n,r):a(r)&&g(n,r);function S(t){return t?.getTime!==void 0}function o(t){return!s(t)&&!a(t)}function a(t){return!s(t)&&t!==null&&typeof t=="object"&&Object.keys(t).length}function s(t){return Array.isArray(t)}function g(t,u){Object.entries(u).forEach(([h,l])=>{if(h.startsWith("$")){let x=h.slice(1);if(t.shadowRoot)l===!1?t.removeAttribute(x):l===!0?t.setAttribute(x,""):t.setAttribute(x,l);else{f.has(t)||f.set(t,q(t));let C=f.get(t);j({name:x,value:l,attributeMapping:C,root:t})}}else A(t,l,h)})}function A(t,u,h){if(t.localName==="option")t.textContent=u;else if(t.localName==="tr"||t.localName==="li"||t.hasAttribute("child")&&!t.shadowRoot)if(t.hasAttribute("data-slot")&&t.dataset.slot===h)t.textContent=u;else{let l=t.querySelector(`[data-slot="${h}"]`);l&&(l.textContent=u)}else if(!h&&t.textContent!==u)t.textContent=u;else{let l=t.querySelector(`[slot="${h}"]`);l||(l=document.createElement("span"),l.setAttribute("slot",h),t.append(l)),l.textContent!==u&&(l.textContent=u)}}function v(t){let u=C();if(!p)throw new Error(`Cannot update ${c}, cannot find child element`);let h=new Map;t.forEach((e,y)=>{let M=x(e,y),w=b.get(M);w||(w=p.cloneNode(!0),u.append(w)),w.cachedData!==e&&(a(e)?g(w,e):A(w,e),w.cachedData=e),h.set(M,w)}),b.forEach((e,y)=>{h.has(y)||e.remove()});let l;h.forEach(e=>{e!==l?.nextSibling&&u.insertBefore(e,l?l.nextSibling:u.firstChild),l=e}),b=h;function x(e,y){return e&&typeof e=="object"?(i.has(e)||i.set(e,d++),i.get(e)):`p:${e}:${y}`}function C(){let e=$();if(e.localName==="table")return y("tbody","tr");if(e.localName==="ol")return y("ol","li");if(e.localName==="ul")return y("ul","li");if(e.localName==="select")return y("select","option");if(e.querySelector("[child]")){let m=w(e.querySelector("[child]")).parentElement;return M("[child]",m),m.localName==="slot"&&m.hasAttribute("name")&&(p.slot=m.getAttribute("name")),m.localName==="slot"?n:m}throw new Error(`Could not find a parent to assign children to, valid
2
2
  options are table, ul, ol, select or a structure with a child attribute`);function y(m,E){let O=w(m);return M(E,O),O}function M(m,E){p||(p=E.querySelector(m).cloneNode(!0),E.replaceChildren())}function w(m){if(m===e.localName)return e;let E=typeof m=="string"?e.querySelector(m):m;if(!E)throw console.log({topLevel:e,parentName:m}),new Error("Cannot find parent");return E}function $(){return n.tagName.includes("-")?[...n.shadowRoot.children].find(m=>m.localName!=="script"&&m.localName!=="style"):n}}}}};var T=c=>{let n=N(c);if(n.elementInternals){let r=function(){return p.tooShort?`The text needs to be at least ${b} characters long`:p.tooLong?`The text needs to be at most ${d} characters long`:i.validationMessage?i.validationMessage:"The value is invalid"},i=n.formElement,f=i.value,b=i.getAttribute("minlength"),d=i.getAttribute("maxlength"),p={valueMissing:i.validity.valueMissing,typeMismatch:i.validity.typeMismatch,patternMismatch:i.validity.patternMismatch,rangeUnderflow:i.validity.rangeUnderflow,rangeOverflow:i.validity.rangeOverflow,stepMismatch:i.validity.stepMismatch,badInput:i.validity.badInput,customError:i.validity.customError,tooShort:b?f.length<parseInt(b):!1,tooLong:d?f.length>parseInt(d):!1};return n.elementInternals.setFormValue(f),n.elementInternals.setValidity(p,r(),i),n.elementInternals}};var L=(c,n)=>{let i=new IntersectionObserver(f=>{f[0].isIntersecting&&(n(),i.disconnect())});i.observe(N(c))};async function Q({prefix:c="db",source:n="/components"}={}){let i=new Set,f=new Set;if(typeof n!="string"||!Object.keys(n).length)throw new Error("source option needs to be a string or an object");if(typeof c!="string"||c==="")throw new Error("prefix option needs to be a string of at least one character");let b=S();d(document.querySelector("body")),await p(document.querySelector("body"));function d(o,a){o.querySelectorAll("template").forEach(s=>{if(!s.id&&a&&(s.id=`${a}-child`),!s.id)throw console.log(s,a),new Error("<template> is missing a mandatory id field");d(s.content,s.id);let g=s.id;r({name:g,template:s})})}function p(o){let a=[...o.querySelectorAll(":not(:defined)")].filter(s=>{let g=s.localName;return s.nodeType===1&&g.includes("-")&&g.startsWith(c)}).map(async s=>{let g=s.localName;if(!f.has(g)){let h=function(l){let x=l.content.querySelector("script");return new Promise(async C=>{if(x){let e=new Blob([x.textContent],{type:"text/javascript"}),y=URL.createObjectURL(e);C((await import(y)).default),URL.revokeObjectURL(y)}else C({})})};f.add(g);let v=await A(g),t=document.createElement("template");t.content.append(...v.children);let u=await h(t);await p(t.content),d(t.content,g),r({name:g,template:t,script:u})}async function A(v){let t=v.split("-").slice(1).join("-"),u=typeof n=="string"?`${n}/${t}.html`:n[t],h=await fetch(u);if(!h.ok)throw new Error(`Could not find component @ ${u}`);let l=await h.text();return new DOMParser().parseFromString(l,"text/html").querySelector("body")}});return Promise.all(a)}function r({name:o,template:a,script:s}){if(i.has(o))return;i.add(o);let g=!!a.content.querySelector("input, select, textarea"),A=q(a.content);customElements.define(o,class extends HTMLElement{static observedAttributes=Object.keys(A);static formAssociated=g;#t=null;constructor(){super();let v=document.importNode(a.content,!0);this.#t=this.attachShadow({mode:"open"}),this.#t.adoptedStyleSheets=b,this.#t.appendChild(v),g&&(this.elementInternals=this.attachInternals(),this.formElement=this.#t.querySelector("input, select, textarea"))}connectedCallback(){typeof s=="function"&&s(this)}attributeChangedCallback(v,t,u){t!==u&&j({name:v,value:u,attributeMapping:A,root:this.#t})}})}function S(){return Array.from(document.styleSheets).filter(o=>o?.ownerNode?.dataset?.inherit==="true").map(o=>{let a=new CSSStyleSheet;try{let s=Array.from(o.cssRules).map(g=>g.cssText).join(`
3
3
  `);a.replaceSync(s)}catch(s){console.error("Permission denied for sheet:",o.href)}return a})}}export{Q as initialize,L as onceVisible,k as update,T as validate};
4
+ //# sourceMappingURL=index.min.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["javascript/attributes.js", "javascript/element.js", "javascript/update.js", "javascript/validate.js", "javascript/onceVisible.js", "javascript/index.js"],
4
+ "sourcesContent": ["export { getAttributeMapping, updateAttributes };\n\nconst mapping = {\n boolean: {\n autofocus: ['button', 'input', 'select', 'textarea'],\n autoplay: ['audio', 'video'],\n checked: ['input'],\n controls: ['audio', 'video'],\n default: ['track'],\n defer: ['script'],\n disabled: ['button', 'input', 'optgroup', 'option', 'select', 'textarea', 'fieldset'],\n formnovalidate: ['button', 'input'],\n ismap: ['img'],\n loop: ['audio', 'video'],\n multiple: ['input', 'select'],\n muted: ['audio', 'video'],\n novalidate: ['form'],\n open: ['details', 'dialog'],\n playsinline: ['video'],\n readonly: ['input', 'textarea'],\n required: ['input', 'select', 'textarea'],\n reversed: ['ol'],\n },\n keyValue: {\n accept: ['input'],\n autocomplete: ['input', 'select', 'textarea'],\n cols: ['textarea'],\n dirname: ['input', 'textarea'],\n max: ['input'],\n maxlength: ['input', 'textarea'],\n min: ['input'],\n minlength: ['input', 'textarea'],\n name: ['input', 'select', 'textarea'],\n pattern: ['input'],\n placeholder: ['input', 'textarea'],\n rows: ['textarea'],\n size: ['input', 'select'],\n step: ['input'],\n type: ['input'],\n value: ['input', 'select'],\n width: ['input'],\n wrap: ['textarea'],\n htmlFor: ['label'],\n for: ['label'],\n href: ['a'],\n target: ['a'],\n src: ['audio', 'img', 'input', 'video'],\n 'aria-invalid': ['input', 'textarea', 'select'],\n },\n excludedAttributes: ['class', 'extends', 'id', 'part', 'data-slot', 'child'],\n excludedElements: ['slot', 'template', 'style', 'script'],\n};\n\nfunction getAttributeMapping(element) {\n const { keyValue, excludedAttributes, excludedElements, boolean: binary } = mapping;\n const results = {};\n traverse(element);\n return results;\n\n function traverse(element) {\n const tagName = element.localName;\n if (\n element &&\n typeof tagName === 'string' &&\n !excludedElements.includes(element.localName)\n ) {\n Object\n .entries(binary)\n .filter(([key]) => !excludedAttributes.includes(key))\n .filter(([, tagNames]) => tagNames.includes(tagName))\n .forEach(([key, tagNames]) => results[key] = { type: 'boolean', tagNames });\n\n Object\n .entries(keyValue)\n .filter(([key]) => !excludedAttributes.includes(key))\n .filter(([, tagNames]) => tagNames.includes(tagName))\n .forEach(([key, tagNames]) => results[key] = { type: 'keyValue', tagNames });\n\n if (element.hasAttributes()) {\n [...element.attributes].forEach(attribute => {\n const name = attribute.name;\n if (!excludedAttributes.includes(name)) {\n if (!results[name]) {\n results[name] = { type: 'userDefined', tagNames: [] };\n }\n\n if (!results[name].tagNames.includes(tagName)) {\n results[name].tagNames.push(tagName);\n }\n }\n });\n }\n }\n [...element.children].forEach(child => traverse(child));\n }\n};\n\nfunction updateAttributes({ name, value, attributeMapping, root }) {\n const { type, tagNames = [] } = attributeMapping[name] ?? [];\n\n if (type === 'userDefined') {\n process(root.querySelector(`[${ name }]`));\n } else {\n tagNames.forEach(tagName => {\n root.querySelectorAll(tagName).forEach(process);\n if (tagName === root?.localName) {\n process(root);\n }\n });\n }\n\n function process(element) {\n if (element) {\n if (\n value === null ||\n value === undefined ||\n (type === 'boolean' && value === false)\n ) {\n element.removeAttribute(name);\n } else {\n element.setAttribute(name, value);\n // Triggers <select> to update the selected <option>\n if (name === 'value') {\n element.value = value;\n }\n }\n }\n }\n}", "export default selector => {\n if (typeof selector === 'string') {\n const instance = document.querySelector(selector);\n if (!instance) {\n throw new Error(`No elements found for selector ${ selector }`);\n }\n return instance;\n }\n\n return selector;\n};", "import { getAttributeMapping, updateAttributes } from './attributes.js';\nimport element from './element.js';\n\nexport default selector => {\n const instance = element(selector);\n const idCache = new WeakMap();\n const mappingCache = new WeakMap();\n let renderedChildren = new Map();\n let idCount = 1;\n let templateChild;\n\n return data => {\n if (isDate(data)) {\n throw new Error('Please convert date to string, ie. toISOString()');\n }\n\n if (isArray(data)) {\n updateList(data);\n } else {\n if (isPrimitive(data)) {\n updateText(instance, data);\n } else if (isObject(data)) {\n updateFromObject(instance, data);\n }\n }\n\n function isDate(input) {\n return input?.getTime !== undefined;\n }\n\n function isPrimitive(input) {\n return !isArray(input) && !isObject(input);\n }\n\n function isObject(input) {\n return !isArray(input) && input !== null && typeof input === 'object' && Object.keys(input).length;\n }\n\n function isArray(input) {\n return Array.isArray(input);\n }\n\n function updateFromObject(element, data) {\n Object.entries(data).forEach(([key, value]) => {\n if (key.startsWith('$')) {\n const name = key.slice(1);\n if (element.shadowRoot) {\n if (value === false) {\n element.removeAttribute(name);\n } else if (value === true) {\n element.setAttribute(name, '');\n } else {\n element.setAttribute(name, value);\n }\n } else {\n if (!mappingCache.has(element)) {\n mappingCache.set(element, getAttributeMapping(element));\n }\n const attributeMapping = mappingCache.get(element);\n updateAttributes({ name, value, attributeMapping, root: element });\n }\n } else {\n updateText(element, value, key);\n }\n });\n }\n\n function updateText(element, value, name) {\n if (element.localName === 'option') {\n element.textContent = value;\n } else if (\n element.localName === 'tr' ||\n element.localName === 'li' ||\n (element.hasAttribute('child') && !element.shadowRoot)) {\n if (element.hasAttribute('data-slot') && element.dataset.slot === name) {\n element.textContent = value;\n } else {\n const match = element.querySelector(`[data-slot=\"${ name }\"]`);\n if (match) {\n match.textContent = value;\n }\n }\n } else if (!name && element.textContent !== value) {\n element.textContent = value;\n } else {\n let slot = element.querySelector(`[slot=\"${ name }\"]`);\n if (!slot) {\n slot = document.createElement('span');\n slot.setAttribute('slot', name);\n element.append(slot);\n }\n\n if (slot.textContent !== value) {\n slot.textContent = value;\n }\n }\n }\n\n function updateList(records) {\n const parent = getParent();\n\n if (!templateChild) {\n throw new Error(`Cannot update ${ selector }, cannot find child element`);\n }\n\n const newChildren = new Map();\n\n records.forEach((record, index) => {\n const id = getId(record, index);\n let child = renderedChildren.get(id);\n\n if (!child) {\n child = templateChild.cloneNode(true);\n parent.append(child);\n }\n\n if (child.cachedData !== record) {\n if (isObject(record)) {\n updateFromObject(child, record);\n } else {\n updateText(child, record);\n }\n child.cachedData = record;\n }\n\n newChildren.set(id, child);\n });\n\n renderedChildren.forEach((child, id) => {\n if (!newChildren.has(id)) {\n child.remove();\n }\n });\n\n // Order children\n let lastChild;\n newChildren.forEach(child => {\n if (child !== lastChild?.nextSibling) {\n parent.insertBefore(child, lastChild ? lastChild.nextSibling : parent.firstChild);\n }\n lastChild = child;\n });\n\n renderedChildren = newChildren;\n\n function getId(record, index) {\n if (record && typeof record === 'object') {\n if (!idCache.has(record)) {\n idCache.set(record, idCount++);\n }\n return idCache.get(record);\n }\n return `p:${ record }:${ index }`;\n };\n\n function getParent() {\n const topLevel = getTopLevel();\n if (topLevel.localName === 'table') {\n return process('tbody', 'tr');\n } else if (topLevel.localName === 'ol') {\n return process('ol', 'li');\n } else if (topLevel.localName === 'ul') {\n return process('ul', 'li');\n } else if (topLevel.localName === 'select') {\n return process('select', 'option');\n } else if (topLevel.querySelector('[child]')) {\n const parent = getParent(topLevel.querySelector('[child]')).parentElement;\n setTemplateChild('[child]', parent);\n if (parent.localName === 'slot' && parent.hasAttribute('name')) {\n templateChild.slot = parent.getAttribute('name');\n }\n return parent.localName === 'slot' ? instance : parent;\n }\n\n throw new Error(`Could not find a parent to assign children to, valid\n options are table, ul, ol, select or a structure with a child attribute`);\n\n function process(parentName, childName) {\n const parent = getParent(parentName);\n setTemplateChild(childName, parent);\n return parent;\n }\n\n function setTemplateChild(childName, parent) {\n if (!templateChild) {\n templateChild = parent.querySelector(childName).cloneNode(true);\n parent.replaceChildren();\n }\n }\n\n function getParent(parentName) {\n if (parentName === topLevel.localName) {\n return topLevel;\n }\n const parent = typeof parentName === 'string'\n ? topLevel.querySelector(parentName) : parentName;\n if (!parent) {\n console.log({ topLevel, parentName });\n throw new Error('Cannot find parent');\n }\n return parent;\n }\n\n function getTopLevel() {\n if (instance.tagName.includes('-')) {\n return [...instance.shadowRoot.children].find(child => {\n return child.localName !== 'script' && child.localName !== 'style';\n });\n }\n return instance;\n }\n }\n }\n };\n};", "import element from './element.js';\n\n// Too long and too short is only set when the actual input is changed, so we do it here\nexport default selector => {\n const instance = element(selector);\n if (instance.elementInternals) {\n const element = instance.formElement;\n const value = element.value;\n const minlength = element.getAttribute('minlength');\n const maxlength = element.getAttribute('maxlength');\n const validity = {\n valueMissing: element.validity.valueMissing,\n typeMismatch: element.validity.typeMismatch,\n patternMismatch: element.validity.patternMismatch,\n rangeUnderflow: element.validity.rangeUnderflow,\n rangeOverflow: element.validity.rangeOverflow,\n stepMismatch: element.validity.stepMismatch,\n badInput: element.validity.badInput,\n customError: element.validity.customError,\n tooShort: minlength ? value.length < parseInt(minlength) : false,\n tooLong: maxlength ? value.length > parseInt(maxlength) : false,\n };\n instance.elementInternals.setFormValue(value);\n instance.elementInternals.setValidity(validity, message(), element);\n\n return instance.elementInternals;\n\n function message() {\n if (validity.tooShort) {\n return `The text needs to be at least ${ minlength } characters long`;\n } else if (validity.tooLong) {\n return `The text needs to be at most ${ maxlength } characters long`;\n } else if (element.validationMessage) {\n return element.validationMessage;\n }\n return 'The value is invalid';\n }\n }\n};", "import element from './element.js';\n\nexport default (selector, callback) => {\n const observer = new IntersectionObserver(entries => {\n if (entries[0].isIntersecting) {\n callback();\n observer.disconnect();\n }\n });\n observer.observe(element(selector));\n};", "import { getAttributeMapping, updateAttributes } from './attributes.js';\nimport update from './update.js';\nimport validate from './validate.js';\nimport onceVisible from './onceVisible.js';\n\nexport { initialize, update, validate, onceVisible };\n\nasync function initialize({ prefix = 'db', source = '/components' } = {}) {\n const registerCache = new Set();\n const fileCache = new Set();\n\n if (typeof source !== 'string' || !Object.keys(source).length) {\n throw new Error('source option needs to be a string or an object');\n }\n\n if (typeof prefix !== 'string' || prefix === '') {\n throw new Error('prefix option needs to be a string of at least one character');\n }\n\n const inheritedStylesheets = getInheritedStylesheets();\n inPage(document.querySelector('body'));\n await fromFile(document.querySelector('body'));\n\n function inPage(root, parentId) {\n root.querySelectorAll('template').forEach(template => {\n if (!template.id && parentId) {\n template.id = `${ parentId }-child`;\n }\n\n if (!template.id) {\n console.log(template, parentId);\n throw new Error('<template> is missing a mandatory id field');\n }\n\n inPage(template.content, template.id);\n const name = template.id;\n register({ name, template });\n });\n }\n\n function fromFile(root) {\n const promises = [...root.querySelectorAll(':not(:defined)')]\n .filter(element => {\n const tagName = element.localName;\n return element.nodeType === 1 && tagName.includes('-') && tagName.startsWith(prefix);\n })\n .map(async element => {\n const name = element.localName;\n if (!fileCache.has(name)) {\n fileCache.add(name);\n const html = await fetchFromFile(name);\n const template = document.createElement('template');\n template.content.append(...html.children);\n const script = await copyScript(template);\n await fromFile(template.content);\n inPage(template.content, name);\n register({ name, template, script });\n\n function copyScript(template) {\n const script = template.content.querySelector('script');\n return new Promise(async resolve => {\n if (script) {\n const blob = new Blob([script.textContent], { type: 'text/javascript' });\n const blobUrl = URL.createObjectURL(blob);\n resolve((await import(blobUrl)).default);\n URL.revokeObjectURL(blobUrl);\n } else {\n resolve({});\n }\n });\n }\n };\n\n async function fetchFromFile(name) {\n const fileName = name.split('-').slice(1).join('-');\n const relativePath = typeof source === 'string'\n ? `${ source }/${ fileName }.html` : source[fileName];\n const response = await fetch(relativePath);\n if (!response.ok) {\n throw new Error(`Could not find component @ ${ relativePath }`);\n }\n const templateAsString = await response.text();\n const document = new DOMParser().parseFromString(templateAsString, 'text/html');\n return document.querySelector('body');\n }\n });\n\n return Promise.all(promises);\n }\n\n function register({ name, template, script }) {\n if (registerCache.has(name)) {\n return;\n }\n\n registerCache.add(name);\n\n const isFormControl = !!template.content.querySelector('input, select, textarea');\n const attributeMapping = getAttributeMapping(template.content);\n\n customElements.define(name, class extends HTMLElement {\n static observedAttributes = Object.keys(attributeMapping);\n static formAssociated = isFormControl;\n #shadow = null;\n\n constructor() {\n super();\n\n const clone = document.importNode(template.content, true);\n this.#shadow = this.attachShadow({ mode: 'open' });\n this.#shadow.adoptedStyleSheets = inheritedStylesheets;\n this.#shadow.appendChild(clone);\n\n if (isFormControl) {\n this.elementInternals = this.attachInternals();\n this.formElement = this.#shadow.querySelector('input, select, textarea');\n }\n }\n\n connectedCallback() {\n if (typeof script === 'function') {\n script(this);\n }\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n if (oldValue !== newValue) {\n updateAttributes({ name, value: newValue, attributeMapping, root: this.#shadow });\n }\n }\n });\n };\n\n function getInheritedStylesheets() {\n return Array.from(document.styleSheets)\n .filter(sheet => sheet?.ownerNode?.dataset?.inherit === 'true')\n .map(sheet => {\n const newSheet = new CSSStyleSheet();\n try {\n const cssText = Array.from(sheet.cssRules).map(rule => rule.cssText).join('\\n');\n newSheet.replaceSync(cssText);\n } catch (error) {\n error;\n console.error('Permission denied for sheet:', sheet.href);\n }\n return newSheet;\n });\n }\n};\n"],
5
+ "mappings": "AAEA,IAAMA,EAAU,CACd,QAAS,CACP,UAAW,CAAC,SAAU,QAAS,SAAU,UAAU,EACnD,SAAU,CAAC,QAAS,OAAO,EAC3B,QAAS,CAAC,OAAO,EACjB,SAAU,CAAC,QAAS,OAAO,EAC3B,QAAS,CAAC,OAAO,EACjB,MAAO,CAAC,QAAQ,EAChB,SAAU,CAAC,SAAU,QAAS,WAAY,SAAU,SAAU,WAAY,UAAU,EACpF,eAAgB,CAAC,SAAU,OAAO,EAClC,MAAO,CAAC,KAAK,EACb,KAAM,CAAC,QAAS,OAAO,EACvB,SAAU,CAAC,QAAS,QAAQ,EAC5B,MAAO,CAAC,QAAS,OAAO,EACxB,WAAY,CAAC,MAAM,EACnB,KAAM,CAAC,UAAW,QAAQ,EAC1B,YAAa,CAAC,OAAO,EACrB,SAAU,CAAC,QAAS,UAAU,EAC9B,SAAU,CAAC,QAAS,SAAU,UAAU,EACxC,SAAU,CAAC,IAAI,CACjB,EACA,SAAU,CACR,OAAQ,CAAC,OAAO,EAChB,aAAc,CAAC,QAAS,SAAU,UAAU,EAC5C,KAAM,CAAC,UAAU,EACjB,QAAS,CAAC,QAAS,UAAU,EAC7B,IAAK,CAAC,OAAO,EACb,UAAW,CAAC,QAAS,UAAU,EAC/B,IAAK,CAAC,OAAO,EACb,UAAW,CAAC,QAAS,UAAU,EAC/B,KAAM,CAAC,QAAS,SAAU,UAAU,EACpC,QAAS,CAAC,OAAO,EACjB,YAAa,CAAC,QAAS,UAAU,EACjC,KAAM,CAAC,UAAU,EACjB,KAAM,CAAC,QAAS,QAAQ,EACxB,KAAM,CAAC,OAAO,EACd,KAAM,CAAC,OAAO,EACd,MAAO,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"binary", "results", "traverse", "tagName", "key", "tagNames", "attribute", "name", "child", "updateAttributes", "value", "attributeMapping", "root", "type", "process", "element_default", "selector", "instance", "update_default", "selector", "instance", "element_default", "idCache", "mappingCache", "renderedChildren", "idCount", "templateChild", "data", "isDate", "isArray", "updateList", "isPrimitive", "updateText", "isObject", "updateFromObject", "input", "element", "key", "value", "name", "getAttributeMapping", "attributeMapping", "updateAttributes", "match", "slot", "records", "parent", "getParent", "newChildren", "record", "index", "id", "getId", "child", "lastChild", "topLevel", "getTopLevel", "process", "setTemplateChild", "parentName", "childName", "validate_default", "selector", "instance", "element_default", "message", "validity", "minlength", "maxlength", "element", "value", "onceVisible_default", "selector", "callback", "observer", "entries", "element_default", "initialize", "prefix", "source", "registerCache", "fileCache", "inheritedStylesheets", "getInheritedStylesheets", "inPage", "fromFile", "root", "parentId", "template", "name", "register", "promises", "element", "tagName", "copyScript", "script", "resolve", "blob", "blobUrl", "html", "fetchFromFile", "fileName", "relativePath", "response", "templateAsString", "isFormControl", "attributeMapping", "getAttributeMapping", "#shadow", "clone", "oldValue", "newValue", "updateAttributes", "sheet", "newSheet", "cssText", "rule", "error"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nbhi",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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",
@@ -13,16 +13,17 @@
13
13
  "multi-page-application",
14
14
  "composable"
15
15
  ],
16
- "homepage": "https://github.com/royniels/d--b#readme",
16
+ "homepage": "https://github.com/royniels/nbhi#readme",
17
17
  "bugs": {
18
- "url": "https://github.com/royniels/d--b/issues"
18
+ "url": "https://github.com/royniels/nbhi/issues"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "git+https://github.com/royniels/d--b.git"
22
+ "url": "git+https://github.com/royniels/nbhi.git"
23
23
  },
24
24
  "files": [
25
- "./index.min.js"
25
+ "./index.min.js",
26
+ "./index.min.js.map"
26
27
  ],
27
28
  "exports": {
28
29
  ".": "./index.min.js"
@@ -32,6 +33,6 @@
32
33
  "type": "module",
33
34
  "scripts": {
34
35
  "test": "echo \"Error: no test specified\" && exit 1",
35
- "build": "npx esbuild ./javascript/index.js --minify --bundle --format=esm --outfile=index.min.js"
36
+ "build": "npx esbuild ./javascript/index.js --minify --bundle --format=esm --sourcemap --outfile=index.min.js"
36
37
  }
37
38
  }