mount-observer 0.0.12 → 0.0.14

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
@@ -80,8 +80,9 @@ export class MountObserver extends EventTarget {
80
80
  target.remove();
81
81
  }
82
82
  }
83
- this.#birtualizeFragment(clone, level + 1);
84
- if (level === 0) {
83
+ await this.#birtualizeFragment(clone, level + 1);
84
+ const shadowRootModeOnLoad = el.getAttribute('shadowRootModeOnLoad');
85
+ if (shadowRootModeOnLoad === null && level === 0) {
85
86
  const slotMap = el.getAttribute('slotmap');
86
87
  let map = slotMap === null ? undefined : JSON.parse(slotMap);
87
88
  const slots = clone.querySelectorAll('[slot]');
@@ -119,7 +120,17 @@ export class MountObserver extends EventTarget {
119
120
  el.dispatchEvent(new LoadEvent(clone));
120
121
  //console.log('dispatched')
121
122
  }
122
- el.after(clone);
123
+ if (shadowRootModeOnLoad !== null) {
124
+ const parent = el.parentElement;
125
+ if (parent === null)
126
+ throw 404;
127
+ if (parent.shadowRoot === null)
128
+ parent.attachShadow({ mode: shadowRootModeOnLoad });
129
+ parent.shadowRoot?.append(clone);
130
+ }
131
+ else {
132
+ el.after(clone);
133
+ }
123
134
  if (level !== 0 || slots.length === 0)
124
135
  el.remove();
125
136
  }
package/README.md CHANGED
@@ -439,10 +439,12 @@ const observer = new MountObserver({
439
439
 
440
440
  So what this does is only check for the presence of an element with tag name "my-element", and it starts downloading the resource, even before the element has "mounted" based on other criteria.
441
441
 
442
- ## Birtual Inclusions
442
+ ## Intra document html imports
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
+ Also, this proposal is partly focused on better management of importing resources "from a distance", in particular via imports carried out via http. Is it such a stretch to look closely at scenarios where that distance happens to be shorter?
447
+
446
448
  The mount-observer is always on the lookout for a template tags with an href attribute starting with #:
447
449
 
448
450
  ```html
@@ -486,4 +488,48 @@ This is an example of a snippet of HTML that appears repeatedly.
486
488
  Some significant differences with genuine slot support as used with (ShadowDOM'd) custom elements
487
489
 
488
490
  1. There is no mechanism for updating the slots. That is something under investigation with this userland [custom enhancement](https://github.com/bahrus/be-inclusive), that could possibly lead to a future implementation request tied to template instantiation.
489
- 2. ShadowDOM's slots act on a "many to one" basis. Multiple light children with identical slot identifiers all get merged into a single (first?) matching slot within the Shadow DOM. These birtual inclusions, instead, follow the opposite approach -- a single element with a slot identifier can get cloned into multiple slot targets as it weaves itself into the templates as they get merged together.
491
+ 2. ShadowDOM's slots act on a "many to one" basis. Multiple light children with identical slot identifiers all get merged into a single (first?) matching slot within the Shadow DOM. These "birtual" (birth-only, virtual) inclusions, instead, follow the opposite approach -- a single element with a slot identifier can get cloned into multiple slot targets as it weaves itself into the templates as they get merged together.
492
+
493
+ ## Intra document html imports with Shadow DOM support
494
+
495
+ This proposal (and polyfill) also supports the option to utilize ShadowDOM / slot updates:
496
+
497
+ ```html
498
+ <template id=chorus>
499
+ <template href=#beautiful>
500
+ <span slot=subjectIs>
501
+ <slot name=subjectIs1></slot>
502
+ </span>
503
+ </template>
504
+
505
+ <div>No matter what they say</div>
506
+ <div prop-pronoun>Words
507
+ <slot name=verb1></slot> bring
508
+ <slot name=pronoun1></slot> down</div>
509
+ <div>Oh no</div>
510
+ <template href=#beautiful>
511
+ <span slot=subjectIs>
512
+ <slot name=subjectIs2></slot>
513
+ </span>
514
+ </template>
515
+ <div>In every single way</div>
516
+ <div>Yes words
517
+ <slot name=verb2></slot> bring
518
+ <slot name=pronoun2></slot> down
519
+ </div>
520
+ <div>Oh no</div>
521
+
522
+ <template href=#down></template>
523
+ </template>
524
+
525
+ <div class=chorus>
526
+ <template href=#chorus shadowRootModeOnLoad=open></template>
527
+ <span slot=verb1>can't</span>
528
+ <span slot=verb2>can't</span>
529
+ <span slot=pronoun1>me</span>
530
+ <span slot=pronoun2>me</span>
531
+ <span slot=subjectIs1>I am</span>
532
+ <span slot=subjectIs2>I am</span>
533
+ </div>
534
+ ```
535
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",