mount-observer 0.0.53 → 0.0.54
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/Newish.js +27 -14
- package/Newish.ts +31 -14
- package/ObsAttr.js +18 -0
- package/ObsAttr.ts +18 -0
- package/package.json +5 -1
- package/ts-refs/be-scoped/types.d.ts +23 -0
- package/ts-refs/trans-render/be/types.d.ts +2 -0
- package/ts-refs/trans-render/froop/types.d.ts +2 -2
package/Newish.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
export { waitForEvent } from './waitForEvent.js';
|
|
2
|
+
import { ObsAttr } from './ObsAttr.js';
|
|
2
3
|
export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
|
|
3
4
|
export class Newish {
|
|
4
5
|
queue = [];
|
|
5
6
|
isResolved = false;
|
|
6
7
|
#ce;
|
|
8
|
+
#ref;
|
|
7
9
|
//#assigner: undefined | Assigner = undefined;
|
|
8
10
|
#options;
|
|
9
11
|
constructor(enhancedElement, itemscope, options) {
|
|
10
12
|
this.#options = options || { assigner: Object.assign };
|
|
13
|
+
this.#ref = new WeakRef(enhancedElement);
|
|
11
14
|
this.#do(enhancedElement, itemscope);
|
|
12
15
|
}
|
|
16
|
+
handleEvent(event) {
|
|
17
|
+
const enhancedElement = this.#ref.deref();
|
|
18
|
+
if (!enhancedElement)
|
|
19
|
+
return;
|
|
20
|
+
this.#attachItemrefs(enhancedElement);
|
|
21
|
+
}
|
|
13
22
|
async #do(enhancedElement, itemscope) {
|
|
14
23
|
if (enhancedElement[attached] === true)
|
|
15
24
|
return;
|
|
@@ -43,26 +52,30 @@ export class Newish {
|
|
|
43
52
|
});
|
|
44
53
|
this.#assignGingerly();
|
|
45
54
|
//attach any itemref references
|
|
55
|
+
this.#attachItemrefs(enhancedElement);
|
|
56
|
+
const et = ObsAttr(enhancedElement, 'itemref');
|
|
57
|
+
et.addEventListener('attr-changed', this);
|
|
58
|
+
this.isResolved = true;
|
|
59
|
+
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
60
|
+
}
|
|
61
|
+
#alreadyAttached = new Set();
|
|
62
|
+
#attachItemrefs(enhancedElement) {
|
|
63
|
+
//TODO: watch for already attached itemrefs to be removed and remove them from the set
|
|
64
|
+
// and call outOfScopeCallback on them
|
|
46
65
|
if (enhancedElement.hasAttribute('itemref')) {
|
|
47
66
|
const itemref = enhancedElement.getAttribute('itemref');
|
|
48
67
|
const itemrefList = itemref.split(' ');
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
const rn = enhancedElement.getRootNode();
|
|
69
|
+
for (const id of itemrefList) {
|
|
70
|
+
if (this.#alreadyAttached.has(id))
|
|
71
|
+
continue;
|
|
72
|
+
const itemrefElement = rn.getElementById(id);
|
|
73
|
+
if (itemrefElement) {
|
|
74
|
+
this.#ce.inScopeCallback(itemrefElement);
|
|
75
|
+
this.#alreadyAttached.add(id);
|
|
54
76
|
}
|
|
55
|
-
if (itemrefList.length === 0)
|
|
56
|
-
break;
|
|
57
|
-
nextSibling = nextSibling.nextElementSibling;
|
|
58
|
-
}
|
|
59
|
-
if (itemrefList.length > 0) {
|
|
60
|
-
//TODO add an observer queue for the id found elsewhere
|
|
61
|
-
throw 'NI';
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
|
-
this.isResolved = true;
|
|
65
|
-
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
66
79
|
}
|
|
67
80
|
async #assignGingerly() {
|
|
68
81
|
let ce = this.#ce;
|
package/Newish.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
|
|
2
2
|
|
|
3
3
|
export {waitForEvent} from './waitForEvent.js';
|
|
4
|
+
import {ObsAttr} from './ObsAttr.js';
|
|
4
5
|
export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
|
|
5
|
-
export class Newish{
|
|
6
|
+
export class Newish implements EventListenerObject {
|
|
6
7
|
queue: Array<any> = [];
|
|
7
8
|
isResolved = false;
|
|
8
9
|
#ce: HTMLElement | undefined;
|
|
10
|
+
#ref: WeakRef<Element>;
|
|
9
11
|
|
|
10
12
|
//#assigner: undefined | Assigner = undefined;
|
|
11
13
|
#options: BindishOptions;
|
|
12
14
|
|
|
13
15
|
constructor(enhancedElement: Element, itemscope: string, options?: BindishOptions){
|
|
14
16
|
this.#options = options || {assigner: Object.assign};
|
|
17
|
+
this.#ref = new WeakRef(enhancedElement);
|
|
15
18
|
this.#do(enhancedElement, itemscope);
|
|
16
19
|
}
|
|
20
|
+
handleEvent(event: Event): void {
|
|
21
|
+
const enhancedElement = this.#ref.deref();
|
|
22
|
+
if(!enhancedElement) return;
|
|
23
|
+
this.#attachItemrefs(enhancedElement);
|
|
24
|
+
}
|
|
17
25
|
|
|
18
26
|
async #do(enhancedElement: Element, itemscope: string){
|
|
19
27
|
if((<any>enhancedElement)[attached] === true) return;
|
|
@@ -46,25 +54,34 @@ export class Newish{
|
|
|
46
54
|
});
|
|
47
55
|
this.#assignGingerly();
|
|
48
56
|
//attach any itemref references
|
|
57
|
+
this.#attachItemrefs(enhancedElement);
|
|
58
|
+
const et = ObsAttr(enhancedElement, 'itemref');
|
|
59
|
+
et.addEventListener('attr-changed', this);
|
|
60
|
+
this.isResolved = true;
|
|
61
|
+
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#alreadyAttached = new Set<string>();
|
|
67
|
+
|
|
68
|
+
#attachItemrefs(enhancedElement: Element){
|
|
69
|
+
//TODO: watch for already attached itemrefs to be removed and remove them from the set
|
|
70
|
+
// and call outOfScopeCallback on them
|
|
49
71
|
if(enhancedElement.hasAttribute('itemref')){
|
|
50
72
|
const itemref = enhancedElement.getAttribute('itemref')!;
|
|
51
73
|
const itemrefList = itemref.split(' ');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if(
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
const rn = enhancedElement.getRootNode() as Document | ShadowRoot;
|
|
75
|
+
for(const id of itemrefList){
|
|
76
|
+
if(this.#alreadyAttached.has(id)) continue;
|
|
77
|
+
const itemrefElement = rn.getElementById(id);
|
|
78
|
+
if(itemrefElement){
|
|
79
|
+
(<any>this.#ce).inScopeCallback(itemrefElement);
|
|
80
|
+
this.#alreadyAttached.add(id);
|
|
57
81
|
}
|
|
58
|
-
if(itemrefList.length === 0) break;
|
|
59
|
-
nextSibling = nextSibling.nextElementSibling;
|
|
60
|
-
}
|
|
61
|
-
if(itemrefList.length > 0){
|
|
62
|
-
//TODO add an observer queue for the id found elsewhere
|
|
63
|
-
throw 'NI';
|
|
64
82
|
}
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
84
|
+
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
async #assignGingerly(){
|
package/ObsAttr.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function ObsAttr(element, attr) {
|
|
2
|
+
const eventTarget = new EventTarget();
|
|
3
|
+
const obs = new MutationObserver((mutations) => {
|
|
4
|
+
eventTarget.dispatchEvent(new Event('attr-changed'));
|
|
5
|
+
// for(const mutation of mutations){
|
|
6
|
+
// if(mutation.type === 'attributes' && mutation.attributeName === attr){
|
|
7
|
+
// obs.disconnect();
|
|
8
|
+
// eventTarget.dispatchEvent(new Event('obsAttr'));
|
|
9
|
+
// break;
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
12
|
+
});
|
|
13
|
+
obs.observe(element, {
|
|
14
|
+
attributes: true,
|
|
15
|
+
attributeFilter: [attr],
|
|
16
|
+
});
|
|
17
|
+
return eventTarget;
|
|
18
|
+
}
|
package/ObsAttr.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function ObsAttr(element: Element, attr: string): EventTarget{
|
|
2
|
+
const eventTarget = new EventTarget();
|
|
3
|
+
const obs = new MutationObserver((mutations) => {
|
|
4
|
+
eventTarget.dispatchEvent(new Event('attr-changed'));
|
|
5
|
+
// for(const mutation of mutations){
|
|
6
|
+
// if(mutation.type === 'attributes' && mutation.attributeName === attr){
|
|
7
|
+
// obs.disconnect();
|
|
8
|
+
// eventTarget.dispatchEvent(new Event('obsAttr'));
|
|
9
|
+
// break;
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
12
|
+
});
|
|
13
|
+
obs.observe(element, {
|
|
14
|
+
attributes: true,
|
|
15
|
+
attributeFilter: [attr],
|
|
16
|
+
});
|
|
17
|
+
return eventTarget;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"default": "./Newish.js",
|
|
22
22
|
"types": "./Newish.ts"
|
|
23
23
|
},
|
|
24
|
+
"./ObsAttr.js": {
|
|
25
|
+
"default": "./ObsAttr.js",
|
|
26
|
+
"types": "./ObsAttr.ts"
|
|
27
|
+
},
|
|
24
28
|
"./Synthesizer.js": {
|
|
25
29
|
"default": "./Synthesizer.js",
|
|
26
30
|
"types": "./Synthesizer.ts"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {IEnhancement, BEAllProps} from '../trans-render/be/types';
|
|
2
|
+
|
|
3
|
+
export interface EndUserProps extends IEnhancement{
|
|
4
|
+
names: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AllProps extends EndUserProps{
|
|
8
|
+
parsedNames: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type AP = AllProps;
|
|
12
|
+
|
|
13
|
+
export type PAP = Partial<AP>;
|
|
14
|
+
|
|
15
|
+
export type ProPAP = Promise<PAP>;
|
|
16
|
+
|
|
17
|
+
export type BAP = AP & BEAllProps;
|
|
18
|
+
|
|
19
|
+
export interface Actions{
|
|
20
|
+
parse(self: BAP): PAP;
|
|
21
|
+
hydrate(self: BAP): ProPAP;
|
|
22
|
+
retire(self: BAP): void;
|
|
23
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IMountObserver } from '../../mount-observer/types';
|
|
2
2
|
import { Scope} from '../lib/types';
|
|
3
3
|
import { WrapperConfig } from '../XV/types';
|
|
4
|
-
import {XForm} from '../types';
|
|
4
|
+
import {CSSQuery, XForm} from '../types';
|
|
5
5
|
|
|
6
6
|
export interface IEventConfig<MCProps = any, MCActions = MCProps, TAction = Action>{
|
|
7
7
|
on?: string,
|
|
@@ -189,7 +189,7 @@ export interface IshConfig<TProps = any, TActions = TProps, ETProps = TProps>{
|
|
|
189
189
|
|
|
190
190
|
isSleepless?: boolean;
|
|
191
191
|
xform?: XForm<TProps, TActions>;
|
|
192
|
-
inScopeXForms?:
|
|
192
|
+
inScopeXForms?: {[key: CSSQuery]: XForm<TProps, TActions>};
|
|
193
193
|
}
|
|
194
194
|
export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps> extends IshConfig<TProps, TActions, ETProps>{
|
|
195
195
|
mainTemplate?: string | HTMLTemplateElement;
|