mount-observer 0.0.70 → 0.0.71

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.70",
3
+ "version": "0.0.71",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
@@ -1,8 +1,8 @@
1
1
  import { toQuery } from './toQuery.js';
2
2
  import { splitRefs } from '../refid/splitRefs.js';
3
+ import { MountObserver } from '../MountObserver.js';
3
4
  export function beKindred(fragment, el) {
4
5
  const qry = toQuery(el);
5
- const matches = Array.from(fragment.querySelectorAll(qry));
6
6
  const elFragment = new DocumentFragment();
7
7
  const clone = el.cloneNode(true);
8
8
  for (const child of clone.childNodes) {
@@ -17,14 +17,21 @@ export function beKindred(fragment, el) {
17
17
  map[attr] = el.getAttribute(attr);
18
18
  }
19
19
  }
20
- for (const match of matches) {
21
- const fragmentClone = elFragment.cloneNode(true);
22
- match.replaceChildren(fragmentClone);
23
- if (map !== null) {
24
- for (const key in map) {
25
- const value = map[key];
26
- match.setAttribute(key, value);
20
+ const mo = new MountObserver({
21
+ on: qry,
22
+ do: {
23
+ mount: (matchingElement) => {
24
+ const fragmentClone = elFragment.cloneNode(true);
25
+ matchingElement.replaceChildren(fragmentClone);
26
+ if (map !== null) {
27
+ for (const key in map) {
28
+ const value = map[key];
29
+ matchingElement.setAttribute(key, value);
30
+ }
31
+ }
27
32
  }
28
33
  }
29
- }
34
+ });
35
+ mo.observe(fragment);
36
+ return mo;
30
37
  }
@@ -1,9 +1,14 @@
1
1
  import {toQuery} from './toQuery.js';
2
2
  import {splitRefs} from '../refid/splitRefs.js';
3
+ import {MountObserver} from '../MountObserver.js';
3
4
 
4
- export function beKindred(fragment: DocumentFragment | Element, el: Element){
5
+ export function beKindred(
6
+ fragment: DocumentFragment | Element,
7
+ el: Element,
8
+ //beVigilant: boolean = false
9
+ ){
5
10
  const qry = toQuery(el);
6
- const matches = Array.from(fragment.querySelectorAll(qry));
11
+
7
12
  const elFragment = new DocumentFragment();
8
13
  const clone = el.cloneNode(true);
9
14
  for(const child of clone.childNodes){
@@ -18,14 +23,23 @@ export function beKindred(fragment: DocumentFragment | Element, el: Element){
18
23
  map[attr] = el.getAttribute(attr)!;
19
24
  }
20
25
  }
21
- for(const match of matches){
22
- const fragmentClone = elFragment.cloneNode(true) as DocumentFragment;
23
- match.replaceChildren(fragmentClone);
24
- if(map !== null){
25
- for(const key in map){
26
- const value = map[key]!;
27
- match.setAttribute(key, value);
26
+
27
+ const mo = new MountObserver({
28
+ on: qry,
29
+ do: {
30
+ mount: (matchingElement) => {
31
+ const fragmentClone = elFragment.cloneNode(true) as DocumentFragment;
32
+ matchingElement.replaceChildren(fragmentClone);
33
+ if(map !== null){
34
+ for(const key in map){
35
+ const value = map[key]!;
36
+ matchingElement.setAttribute(key, value);
37
+ }
38
+ }
28
39
  }
29
40
  }
30
- }
41
+ });
42
+ mo.observe(fragment);
43
+ return mo;
44
+
31
45
  }