mount-observer 0.0.9 → 0.0.11

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/MountObserver.js CHANGED
@@ -62,7 +62,7 @@ export class MountObserver extends EventTarget {
62
62
  if (!(templ instanceof HTMLTemplateElement))
63
63
  throw 404;
64
64
  const clone = templ.content.cloneNode(true);
65
- const slots = el.querySelectorAll(`[slot]`);
65
+ const slots = el.content.querySelectorAll(`[slot]`);
66
66
  for (const slot of slots) {
67
67
  const name = slot.getAttribute('slot');
68
68
  const targets = Array.from(clone.querySelectorAll(`slot[name="${name}"]`));
@@ -111,8 +111,9 @@ export class MountObserver extends EventTarget {
111
111
  el.dispatchEvent(new LoadEvent(clone));
112
112
  //console.log('dispatched')
113
113
  }
114
- el.before(clone);
115
- el.remove();
114
+ el.after(clone);
115
+ if (level !== 0 || slots.length === 0)
116
+ el.remove();
116
117
  }
117
118
  #templLookUp = new Map();
118
119
  #findByID(id, fragment) {
@@ -373,7 +374,7 @@ export class MountObserver extends EventTarget {
373
374
  }
374
375
  }
375
376
  const refCountErr = 'mount-observer ref count mismatch';
376
- const biQry = 'b-i[href^="#"]:not([disabled])';
377
+ const biQry = 'template[href^="#"]:not([hidden])';
377
378
  // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
378
379
  /**
379
380
  * The `mutation-event` event represents something that happened.
package/README.md CHANGED
@@ -11,7 +11,7 @@ Author: Bruce B. Anderson
11
11
 
12
12
  Issues / pr's / polyfill: [mount-observer](https://github.com/bahrus/mount-observer)
13
13
 
14
- Last Update: 2024-2-17
14
+ Last Update: 2024-2-18
15
15
 
16
16
  ## Benefits of this API
17
17
 
@@ -443,25 +443,29 @@ So what this does is only check for the presence of an element with tag name "my
443
443
 
444
444
  This proposal "sneaks in" one more feature, that perhaps should stand separately as its own proposal. Because the MountObserver api allows us to attach behaviors on the fly based on css matching, and because the MountObserver would provide developers the "first point of contact" for such functionality, the efficiency argument seemingly "screams out" for this feature.
445
445
 
446
- The mount-observer is always on the lookout for a special tag that takes the form:
446
+ The mount-observer is always on the lookout for a template tags with an href attribute starting with #:
447
+
448
+ ```html
449
+ <template href=#id-of-source-template></template>
450
+ ```
451
+
452
+ For example:
447
453
 
448
454
  ```html
449
455
  <div>Some prior stuff</div>
450
- <b-i href=#my-snippet-of-html>
456
+ <template href=#id-of-source-template>
451
457
  <div slot=slot1>hello</div>
452
458
  <div slot=slot2>goodbye<div>
453
- </b-i>
459
+ </template>
454
460
  <div>Some additional stuff</div>
455
461
  ```
456
462
 
457
- "b-i" stands for "birtual inclusion" where birtual is a made up word that is a portmanteau of birth and virtual.
458
-
459
- When it encounters such a thing, it searches "upwardly" through the chain of ShadowRoots for a template with id=my-kinda-sorta-custom-element (in this case), and caches them as it finds them.
463
+ When it encounters such a thing, it searches "upwardly" through the chain of ShadowRoots for a template with id=id-of-source-template (in this case), and caches them as it finds them.
460
464
 
461
- Let's say the template looks as follows:
465
+ Let's say the source template looks as follows:
462
466
 
463
467
  ```html
464
- <template id=my-snippet-of-html>
468
+ <template id=id-of-source-template>
465
469
  This is an example of a snippet of HTML that appears repeatedly.
466
470
  <slot name=slot1></slot>
467
471
  <slot name=slot2></slot>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",