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 +1 -1
- package/slotkin/beKindred.js +16 -9
- package/slotkin/beKindred.ts +24 -10
package/package.json
CHANGED
package/slotkin/beKindred.js
CHANGED
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
}
|
package/slotkin/beKindred.ts
CHANGED
|
@@ -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(
|
|
5
|
+
export function beKindred(
|
|
6
|
+
fragment: DocumentFragment | Element,
|
|
7
|
+
el: Element,
|
|
8
|
+
//beVigilant: boolean = false
|
|
9
|
+
){
|
|
5
10
|
const qry = toQuery(el);
|
|
6
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
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
|
}
|