mount-observer 0.0.82 → 0.0.84
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 +2 -2
- package/MountObserver.ts +2 -2
- package/README.md +3 -15
- package/package.json +2 -3
- package/preloadContent.js +40 -39
- package/preloadContent.ts +40 -37
- package/ts-refs/be-enhancing/types.d.ts +31 -0
- package/ts-refs/be-switched/types.d.ts +3 -1
- package/ts-refs/trans-render/types.d.ts +6 -1
package/MountObserver.js
CHANGED
|
@@ -64,7 +64,7 @@ export class MountObserver extends EventTarget {
|
|
|
64
64
|
const bis = fragment.querySelectorAll(`${inclTemplQry}`);
|
|
65
65
|
for (const bi of bis) {
|
|
66
66
|
if (bi.getAttribute('rel') === 'preload') {
|
|
67
|
-
(await import('./preloadContent.js')).preloadContent(bi
|
|
67
|
+
(await import('./preloadContent.js')).preloadContent(bi);
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
70
|
await this.#compose(bi, level);
|
|
@@ -486,7 +486,7 @@ export class MountObserver extends EventTarget {
|
|
|
486
486
|
for (const elToMount of elsToMount) {
|
|
487
487
|
if (elToMount.matches(inclTemplQry)) {
|
|
488
488
|
if (elToMount instanceof HTMLTemplateElement && elToMount.getAttribute('rel') === 'preload') {
|
|
489
|
-
(await import('./preloadContent.js')).preloadContent(elToMount
|
|
489
|
+
(await import('./preloadContent.js')).preloadContent(elToMount /*, this.#mountInit.withTargetShadowRoot*/);
|
|
490
490
|
}
|
|
491
491
|
else {
|
|
492
492
|
await this.#compose(elToMount, 0);
|
package/MountObserver.ts
CHANGED
|
@@ -77,7 +77,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
77
77
|
const bis = fragment.querySelectorAll(`${inclTemplQry}`) as NodeListOf<HTMLTemplateElement>;
|
|
78
78
|
for(const bi of bis){
|
|
79
79
|
if(bi.getAttribute('rel') === 'preload'){
|
|
80
|
-
(await import('./preloadContent.js')).preloadContent(bi
|
|
80
|
+
(await import('./preloadContent.js')).preloadContent(bi);
|
|
81
81
|
}else{
|
|
82
82
|
await this.#compose(bi, level);
|
|
83
83
|
}
|
|
@@ -515,7 +515,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
515
515
|
for(const elToMount of elsToMount){
|
|
516
516
|
if(elToMount.matches(inclTemplQry)){
|
|
517
517
|
if(elToMount instanceof HTMLTemplateElement && elToMount.getAttribute('rel') === 'preload'){
|
|
518
|
-
(await import('./preloadContent.js')).preloadContent(elToMount
|
|
518
|
+
(await import('./preloadContent.js')).preloadContent(elToMount/*, this.#mountInit.withTargetShadowRoot*/);
|
|
519
519
|
}else{
|
|
520
520
|
await this.#compose(elToMount as HTMLTemplateElement, 0);
|
|
521
521
|
}
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Author: Bruce B. Anderson (with valuable feedback from @doeixd )
|
|
|
11
11
|
|
|
12
12
|
Issues / pr's / polyfill: [mount-observer](https://github.com/bahrus/mount-observer)
|
|
13
13
|
|
|
14
|
-
Last Update: Aug
|
|
14
|
+
Last Update: Aug 7, 2025
|
|
15
15
|
|
|
16
16
|
## Benefits of this API
|
|
17
17
|
|
|
@@ -929,7 +929,7 @@ The discussion there leads to an open question whether a processing instruction
|
|
|
929
929
|
|
|
930
930
|
The [add src attribute to template to load a template from file](https://github.com/whatwg/html/issues/10571) and an interesting proposal that is [coming from](https://github.com/htmlcomponents/declarative-shadow-imports/blob/main/examples/02-explainer-proposal/02-html.html) the Edge team [seem quite compatible](https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/ShadowDOM/explainer.md#proposal-inline-declarative-css-module-scripts) with this idea.
|
|
931
931
|
|
|
932
|
-
## Applying DRY to templates
|
|
932
|
+
## Applying DRY to templates
|
|
933
933
|
|
|
934
934
|
Recall that with the previous examples, there was an implicit value of the rel attribute:
|
|
935
935
|
|
|
@@ -1160,11 +1160,7 @@ Again, because of the mount-observer being the "first point of contact" with the
|
|
|
1160
1160
|
console.log({e});
|
|
1161
1161
|
//{addedChildren, removedChildren}
|
|
1162
1162
|
});
|
|
1163
|
-
|
|
1164
|
-
const mo = new MountObserver({ //TODO
|
|
1165
|
-
via: 'itemref.children',
|
|
1166
|
-
});
|
|
1167
|
-
mo.observe('#section');
|
|
1163
|
+
|
|
1168
1164
|
</script>
|
|
1169
1165
|
```
|
|
1170
1166
|
|
|
@@ -1183,9 +1179,6 @@ Again, because of the mount-observer being the "first point of contact" with the
|
|
|
1183
1179
|
console.log(mySpan.via.ariaLabelledby.children);
|
|
1184
1180
|
//[span#tac, span#tac2]
|
|
1185
1181
|
|
|
1186
|
-
console.log(tac2.via.ariaLabelledby.parents);
|
|
1187
|
-
//[span#mySpan]
|
|
1188
|
-
|
|
1189
1182
|
|
|
1190
1183
|
mySpan.via.ariaLabelledby.addEventListener('change', e => {
|
|
1191
1184
|
console.log({e});
|
|
@@ -1215,11 +1208,6 @@ Again, because of the mount-observer being the "first point of contact" with the
|
|
|
1215
1208
|
</tbody>
|
|
1216
1209
|
</table>
|
|
1217
1210
|
<script>
|
|
1218
|
-
console.log(myTbody.group.dataParentName.by.group1);
|
|
1219
|
-
// [tr.myTR1, tr.myTR2]
|
|
1220
|
-
myTbody.group.dataParentName.by.group1.addEventListener('change', e => {
|
|
1221
|
-
{addedMember, removedMember}
|
|
1222
|
-
});
|
|
1223
1211
|
|
|
1224
1212
|
console.log(myTR1.joinMatching.dataParentName.fromClosest.tbody);
|
|
1225
1213
|
// [tr#myTR1, tr#myTR2]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.84",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"default": "./refid/getAdjRefs.js",
|
|
62
62
|
"types": "./refid/getAdjRefs.ts"
|
|
63
63
|
},
|
|
64
|
-
"./refid/joinMatching.js":{
|
|
64
|
+
"./refid/joinMatching.js": {
|
|
65
65
|
"default": "./refid/joinMatching.js",
|
|
66
66
|
"types": "./refid/joinMatching.ts"
|
|
67
67
|
},
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"default": "./refid/via.js",
|
|
78
78
|
"types": "./refid/via.ts"
|
|
79
79
|
},
|
|
80
|
-
|
|
81
80
|
"./refid/splitRefs.js": {
|
|
82
81
|
"default": "./refid/splitRefs.js",
|
|
83
82
|
"types": "./refid/splitRefs.ts"
|
package/preloadContent.js
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
+
import { upShadowSearch } from './upShadowSearch.js';
|
|
1
2
|
const remoteTemplElSym = Symbol.for('du3y+tfsAUGFHMG/iHZiMQ');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw 'NI'; //not implemented
|
|
3
|
+
Object.defineProperty(HTMLTemplateElement.prototype, 'remoteContent', {
|
|
4
|
+
get() {
|
|
5
|
+
const templ = this;
|
|
6
|
+
const src = templ.getAttribute('src');
|
|
7
|
+
if (src === null) {
|
|
8
|
+
const head = document.head;
|
|
9
|
+
if (window[remoteTemplElSym] === undefined) {
|
|
10
|
+
window[remoteTemplElSym] = 0;
|
|
11
|
+
}
|
|
12
|
+
const id = templ.id || window[remoteTemplElSym]++;
|
|
13
|
+
const sourceTempl = document.createElement('template');
|
|
14
|
+
sourceTempl.id = '' + id;
|
|
15
|
+
sourceTempl.content.appendChild(templ.content);
|
|
16
|
+
head.append(sourceTempl);
|
|
17
|
+
templ.innerHTML = '';
|
|
18
|
+
templ.setAttribute('src', `#${id}`);
|
|
19
|
+
templ.setAttribute('rel', 'preload');
|
|
20
|
+
templ[remoteTemplElSym] = new WeakRef(sourceTempl);
|
|
21
|
+
return sourceTempl.content;
|
|
22
|
+
}
|
|
23
|
+
{
|
|
24
|
+
const test = templ[remoteTemplElSym]?.deref();
|
|
25
|
+
if (test !== undefined)
|
|
26
|
+
return test;
|
|
27
|
+
if (templ.getAttribute('rel') !== 'preload')
|
|
28
|
+
throw 'NI';
|
|
29
|
+
const isIntraDoc = src[0] === '#';
|
|
30
|
+
if (!isIntraDoc)
|
|
31
|
+
throw 'NI';
|
|
32
|
+
const id = src.substring(1);
|
|
33
|
+
const remoteTempl = upShadowSearch(templ, id);
|
|
34
|
+
if (!(remoteTempl instanceof HTMLTemplateElement))
|
|
35
|
+
throw 404; //not found
|
|
36
|
+
templ[remoteTemplElSym] = new WeakRef(remoteTempl);
|
|
37
|
+
//templ.dispatchEvent(new Event('load'));
|
|
38
|
+
}
|
|
41
39
|
}
|
|
40
|
+
});
|
|
41
|
+
export function preloadContent(templ) {
|
|
42
|
+
const content = templ.remoteContent;
|
|
42
43
|
}
|
package/preloadContent.ts
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
import {TemplateWithRemoteContent} from './ts-refs/mount-observer/types.js';
|
|
2
|
+
import {upShadowSearch} from './upShadowSearch.js';
|
|
2
3
|
const remoteTemplElSym = Symbol.for('du3y+tfsAUGFHMG/iHZiMQ');
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
Object.defineProperty(HTMLTemplateElement.prototype, 'remoteContent', {
|
|
6
|
+
get(){
|
|
7
|
+
const templ = this as HTMLTemplateElement;
|
|
8
|
+
const src = templ.getAttribute('src');
|
|
9
|
+
if(src === null){
|
|
10
|
+
const head = document.head;
|
|
11
|
+
if((<any>window)[remoteTemplElSym] === undefined ){
|
|
12
|
+
(<any>window)[remoteTemplElSym] = 0;
|
|
13
|
+
}
|
|
14
|
+
const id = templ.id || (<any>window)[remoteTemplElSym]++;
|
|
15
|
+
const sourceTempl = document.createElement('template');
|
|
16
|
+
sourceTempl.id = '' + id;
|
|
17
|
+
sourceTempl.content.appendChild(templ.content);
|
|
18
|
+
head.append(sourceTempl);
|
|
19
|
+
templ.innerHTML = '';
|
|
20
|
+
templ.setAttribute('src', `#${id}`);
|
|
21
|
+
templ.setAttribute('rel', 'preload');
|
|
22
|
+
(<any>templ)[remoteTemplElSym] = new WeakRef(sourceTempl);
|
|
23
|
+
return sourceTempl.content;
|
|
24
|
+
}
|
|
25
|
+
{
|
|
26
|
+
const test = (<any>templ)[remoteTemplElSym]?.deref();
|
|
27
|
+
if(test !== undefined) return test;
|
|
28
|
+
if(templ.getAttribute('rel') !== 'preload') throw 'NI';
|
|
29
|
+
const isIntraDoc = src[0] === '#';
|
|
30
|
+
if(!isIntraDoc) throw 'NI';
|
|
31
|
+
const id = src.substring(1);
|
|
32
|
+
const remoteTempl = upShadowSearch(templ, id);
|
|
33
|
+
if(!(remoteTempl instanceof HTMLTemplateElement)) throw 404; //not found
|
|
34
|
+
(<any>templ)[remoteTemplElSym] = new WeakRef(remoteTempl);
|
|
35
|
+
//templ.dispatchEvent(new Event('load'));
|
|
36
|
+
}
|
|
28
37
|
|
|
29
|
-
});
|
|
30
|
-
}else{
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if(isIntraDoc){
|
|
34
|
-
const id = src.substring(1);
|
|
35
|
-
const {upShadowSearch} = await import('./upShadowSearch.js');
|
|
36
|
-
const remoteTempl = upShadowSearch(templ, id) || upShadowSearch((target || document) as Element, id);
|
|
37
|
-
if(!(remoteTempl instanceof HTMLTemplateElement)) throw 404; //not found
|
|
38
|
-
templWithRemoteContent[remoteTemplElSym] = new WeakRef(remoteTempl);
|
|
39
|
-
templWithRemoteContent.dispatchEvent(new Event('load'));
|
|
40
|
-
}else{
|
|
41
|
-
throw 'NI'; //not implemented
|
|
42
38
|
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export function preloadContent(
|
|
42
|
+
templ: HTMLTemplateElement,
|
|
43
|
+
) {
|
|
44
|
+
const content = (<any>templ).remoteContent;
|
|
45
|
+
|
|
43
46
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {IEnhancement, BEAllProps} from '../trans-render/be/types';
|
|
2
|
+
import { Specifier } from "../trans-render/dss/types";
|
|
3
|
+
|
|
4
|
+
export interface EndUserProps extends IEnhancement{
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AllProps extends EndUserProps{
|
|
8
|
+
parsedStatements: Array<ResolvingParameters>,
|
|
9
|
+
rawStatements?: Array<string>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type AP = AllProps;
|
|
13
|
+
|
|
14
|
+
export type PAP = Partial<AP>;
|
|
15
|
+
|
|
16
|
+
export type ProPAP = Promise<PAP>;
|
|
17
|
+
|
|
18
|
+
export type BAP = AP & BEAllProps;
|
|
19
|
+
|
|
20
|
+
export interface Actions{
|
|
21
|
+
hydrate(self: BAP): ProPAP;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ResolvingParameters{
|
|
25
|
+
remoteSpecifierString: string;
|
|
26
|
+
remoteSpecifier: Specifier;
|
|
27
|
+
enhancementBase: string;
|
|
28
|
+
localSpecifierString: string;
|
|
29
|
+
localSpecifier: Specifier;
|
|
30
|
+
remotePropertyPath: string;
|
|
31
|
+
}
|
|
@@ -28,10 +28,11 @@ export interface EndUserProps extends IEnhancement<HTMLTemplateElement>{
|
|
|
28
28
|
beOosoom?: string;
|
|
29
29
|
js?: string;
|
|
30
30
|
transitional: boolean;
|
|
31
|
+
idRefAttr: string;
|
|
31
32
|
/**
|
|
32
33
|
* Use comments rather a DOM element to wrap multiple elements
|
|
33
34
|
*/
|
|
34
|
-
cmtWrap?: boolean;
|
|
35
|
+
//cmtWrap?: boolean;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export interface AllProps extends EndUserProps{
|
|
@@ -49,6 +50,7 @@ export interface AllProps extends EndUserProps{
|
|
|
49
50
|
rawStatements?: Array<string>,
|
|
50
51
|
notProcessedJS?: boolean,
|
|
51
52
|
emc: EMC<any, AllProps>,
|
|
53
|
+
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
export type SwitchStatement = string;
|
|
@@ -313,6 +313,11 @@ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
|
|
|
313
313
|
*/
|
|
314
314
|
ss?: string,
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* two way bind the listed props to data- attributes
|
|
318
|
+
*/
|
|
319
|
+
data?: Array<keyof TProp & string>
|
|
320
|
+
|
|
316
321
|
/**
|
|
317
322
|
* negate to
|
|
318
323
|
*/
|
|
@@ -395,7 +400,7 @@ export type UnitOfWorkRHS<TProps, TMethods, TElement = {}> =
|
|
|
395
400
|
| XForm<any, any, any> & Info //unclear if this is necessary
|
|
396
401
|
;
|
|
397
402
|
|
|
398
|
-
export type RHS<TProps, TMethods, TElements = Element> = UnitOfWorkRHS<TProps, TMethods, TElements> | Array<UnitOfWork<TProps, TMethods, TElements>>;
|
|
403
|
+
export type RHS<TProps = any, TMethods = TProps, TElements = Element> = UnitOfWorkRHS<TProps, TMethods, TElements> | Array<UnitOfWork<TProps, TMethods, TElements>>;
|
|
399
404
|
|
|
400
405
|
export interface AttrMap{
|
|
401
406
|
type: PropAttrQueryType,
|