mount-observer 0.1.12 → 0.1.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/DefineCustomElementHandler.js +99 -99
- package/ElementMountExtension.js +183 -8
- package/ElementMountExtension.ts +218 -11
- package/EnhanceMountedElementHandler.js +96 -96
- package/Events.js +27 -18
- package/Events.ts +18 -6
- package/EvtRt.js +16 -14
- package/EvtRt.ts +18 -15
- package/MountObserver.js +207 -71
- package/MountObserver.ts +234 -85
- package/README.md +1782 -251
- package/RegistryMountCoordinator.js +125 -0
- package/RegistryMountCoordinator.ts +181 -0
- package/connectionMonitor.js +1 -1
- package/connectionMonitor.ts +1 -1
- package/{getRootRegistryContainer.js → getRegistryRoot.js} +1 -1
- package/{getRootRegistryContainer.ts → getRegistryRoot.ts} +1 -1
- package/index.js +15 -10
- package/index.ts +15 -10
- package/mediaQuery.js +1 -1
- package/mediaQuery.ts +1 -1
- package/observedRootHas.js +87 -87
- package/package.json +67 -61
- package/playwright.config.ts +1 -0
- package/rootSizeObserver.js +1 -1
- package/rootSizeObserver.ts +1 -1
- package/upShadowSearch.js +67 -0
- package/upShadowSearch.ts +65 -0
- package/DefineCustomElementHandler.ts +0 -117
- package/EnhanceMountedElementHandler.ts +0 -111
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { EvtRt } from './EvtRt.js';
|
|
2
|
-
//import { buildCSSQuery } from 'assign-gingerly/buildCSSQuery.js';
|
|
3
|
-
import 'assign-gingerly/object-extension.js';
|
|
4
|
-
/**
|
|
5
|
-
* Handler for automatically enhancing mounted elements using assign-gingerly.
|
|
6
|
-
* Searches the first imported module for an export with a "spawn" property
|
|
7
|
-
* and uses element.enh.get() to spawn the enhancement.
|
|
8
|
-
*/
|
|
9
|
-
export class EnhanceMountedElementHandler extends EvtRt {
|
|
10
|
-
async mount(mountedElement, MountConfig, context) {
|
|
11
|
-
this.abort();
|
|
12
|
-
// Check if modules are specified
|
|
13
|
-
if (!context.modules || context.modules.length === 0) {
|
|
14
|
-
throw new Error('Must specify an ES Module with import property');
|
|
15
|
-
}
|
|
16
|
-
const module = context.modules[0];
|
|
17
|
-
// Find registry item (object with spawn property)
|
|
18
|
-
const registryItem = await this._findRegistryItem(module, mountedElement);
|
|
19
|
-
if (!registryItem) {
|
|
20
|
-
throw new Error('No registry item found in module. Expected an export with a "spawn" property.');
|
|
21
|
-
}
|
|
22
|
-
// Validate spawn is a constructor
|
|
23
|
-
if (typeof registryItem.spawn !== 'function') {
|
|
24
|
-
throw new Error('Registry item "spawn" property must be a constructor function');
|
|
25
|
-
}
|
|
26
|
-
// Spawn the enhancement
|
|
27
|
-
this.#spawnEnhancement(mountedElement, registryItem, context);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Spawn the enhancement using element.enh.get().
|
|
31
|
-
* Polyfills customElementRegistry if needed for browsers without scoped registry support.
|
|
32
|
-
*/
|
|
33
|
-
#spawnEnhancement(element, registryItem, context) {
|
|
34
|
-
// Polyfill element.customElementRegistry if it doesn't exist (for browsers without scoped registries)
|
|
35
|
-
if (!element.customElementRegistry) {
|
|
36
|
-
Object.defineProperty(element, 'customElementRegistry', {
|
|
37
|
-
value: customElements,
|
|
38
|
-
writable: true,
|
|
39
|
-
enumerable: false,
|
|
40
|
-
configurable: true
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// Use element.enh.get() to spawn the enhancement
|
|
44
|
-
const enh = element.enh;
|
|
45
|
-
if (!enh || typeof enh.get !== 'function') {
|
|
46
|
-
throw new Error('Element does not have enh.get() method. Make sure assign-gingerly/object-extension.js is loaded.');
|
|
47
|
-
}
|
|
48
|
-
enh.get(registryItem, context);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Find a registry item in the module exports.
|
|
52
|
-
* A registry item is an object with a "spawn" property.
|
|
53
|
-
* @param module - The imported module
|
|
54
|
-
* @returns The registry item or null if not found
|
|
55
|
-
*/
|
|
56
|
-
async _findRegistryItem(module, el) {
|
|
57
|
-
// Check default export first
|
|
58
|
-
if (module.default && await this._isRegistryItem(module.default, el)) {
|
|
59
|
-
return module.default;
|
|
60
|
-
}
|
|
61
|
-
// Search all exports for a registry item
|
|
62
|
-
const exports = Object.values(module);
|
|
63
|
-
const registryItems = [];
|
|
64
|
-
for (const e of exports) {
|
|
65
|
-
const isRegistryItem = await this._isRegistryItem(e, el);
|
|
66
|
-
if (isRegistryItem)
|
|
67
|
-
registryItems.push(e);
|
|
68
|
-
}
|
|
69
|
-
if (registryItems.length === 0) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
if (registryItems.length > 1) {
|
|
73
|
-
throw new Error('More than one registry item found in module. Expected exactly one export with a "spawn" property.');
|
|
74
|
-
}
|
|
75
|
-
return registryItems[0];
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Check if an export is a registry item (has a spawn property).
|
|
79
|
-
* @param exp - The export to check
|
|
80
|
-
* @returns True if the export is a registry item
|
|
81
|
-
*/
|
|
82
|
-
async _isRegistryItem(exp, mountedElement) {
|
|
83
|
-
let test = exp !== null
|
|
84
|
-
&& typeof exp === 'object'
|
|
85
|
-
&& 'spawn' in exp
|
|
86
|
-
&& typeof exp.spawn === 'function';
|
|
87
|
-
if (!test)
|
|
88
|
-
return false;
|
|
89
|
-
const emc = exp;
|
|
90
|
-
if (emc.withAttrs !== undefined) {
|
|
91
|
-
const cssQuery = (await import('assign-gingerly/buildCSSQuery.js')).buildCSSQuery(emc);
|
|
92
|
-
return mountedElement.matches(cssQuery);
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
1
|
+
import { EvtRt } from './EvtRt.js';
|
|
2
|
+
//import { buildCSSQuery } from 'assign-gingerly/buildCSSQuery.js';
|
|
3
|
+
import 'assign-gingerly/object-extension.js';
|
|
4
|
+
/**
|
|
5
|
+
* Handler for automatically enhancing mounted elements using assign-gingerly.
|
|
6
|
+
* Searches the first imported module for an export with a "spawn" property
|
|
7
|
+
* and uses element.enh.get() to spawn the enhancement.
|
|
8
|
+
*/
|
|
9
|
+
export class EnhanceMountedElementHandler extends EvtRt {
|
|
10
|
+
async mount(mountedElement, MountConfig, context) {
|
|
11
|
+
this.abort();
|
|
12
|
+
// Check if modules are specified
|
|
13
|
+
if (!context.modules || context.modules.length === 0) {
|
|
14
|
+
throw new Error('Must specify an ES Module with import property');
|
|
15
|
+
}
|
|
16
|
+
const module = context.modules[0];
|
|
17
|
+
// Find registry item (object with spawn property)
|
|
18
|
+
const registryItem = await this._findRegistryItem(module, mountedElement);
|
|
19
|
+
if (!registryItem) {
|
|
20
|
+
throw new Error('No registry item found in module. Expected an export with a "spawn" property.');
|
|
21
|
+
}
|
|
22
|
+
// Validate spawn is a constructor
|
|
23
|
+
if (typeof registryItem.spawn !== 'function') {
|
|
24
|
+
throw new Error('Registry item "spawn" property must be a constructor function');
|
|
25
|
+
}
|
|
26
|
+
// Spawn the enhancement
|
|
27
|
+
this.#spawnEnhancement(mountedElement, registryItem, context);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Spawn the enhancement using element.enh.get().
|
|
31
|
+
* Polyfills customElementRegistry if needed for browsers without scoped registry support.
|
|
32
|
+
*/
|
|
33
|
+
#spawnEnhancement(element, registryItem, context) {
|
|
34
|
+
// Polyfill element.customElementRegistry if it doesn't exist (for browsers without scoped registries)
|
|
35
|
+
if (!element.customElementRegistry) {
|
|
36
|
+
Object.defineProperty(element, 'customElementRegistry', {
|
|
37
|
+
value: customElements,
|
|
38
|
+
writable: true,
|
|
39
|
+
enumerable: false,
|
|
40
|
+
configurable: true
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Use element.enh.get() to spawn the enhancement
|
|
44
|
+
const enh = element.enh;
|
|
45
|
+
if (!enh || typeof enh.get !== 'function') {
|
|
46
|
+
throw new Error('Element does not have enh.get() method. Make sure assign-gingerly/object-extension.js is loaded.');
|
|
47
|
+
}
|
|
48
|
+
enh.get(registryItem, context);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Find a registry item in the module exports.
|
|
52
|
+
* A registry item is an object with a "spawn" property.
|
|
53
|
+
* @param module - The imported module
|
|
54
|
+
* @returns The registry item or null if not found
|
|
55
|
+
*/
|
|
56
|
+
async _findRegistryItem(module, el) {
|
|
57
|
+
// Check default export first
|
|
58
|
+
if (module.default && await this._isRegistryItem(module.default, el)) {
|
|
59
|
+
return module.default;
|
|
60
|
+
}
|
|
61
|
+
// Search all exports for a registry item
|
|
62
|
+
const exports = Object.values(module);
|
|
63
|
+
const registryItems = [];
|
|
64
|
+
for (const e of exports) {
|
|
65
|
+
const isRegistryItem = await this._isRegistryItem(e, el);
|
|
66
|
+
if (isRegistryItem)
|
|
67
|
+
registryItems.push(e);
|
|
68
|
+
}
|
|
69
|
+
if (registryItems.length === 0) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (registryItems.length > 1) {
|
|
73
|
+
throw new Error('More than one registry item found in module. Expected exactly one export with a "spawn" property.');
|
|
74
|
+
}
|
|
75
|
+
return registryItems[0];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if an export is a registry item (has a spawn property).
|
|
79
|
+
* @param exp - The export to check
|
|
80
|
+
* @returns True if the export is a registry item
|
|
81
|
+
*/
|
|
82
|
+
async _isRegistryItem(exp, mountedElement) {
|
|
83
|
+
let test = exp !== null
|
|
84
|
+
&& typeof exp === 'object'
|
|
85
|
+
&& 'spawn' in exp
|
|
86
|
+
&& typeof exp.spawn === 'function';
|
|
87
|
+
if (!test)
|
|
88
|
+
return false;
|
|
89
|
+
const emc = exp;
|
|
90
|
+
if (emc.withAttrs !== undefined) {
|
|
91
|
+
const cssQuery = (await import('assign-gingerly/buildCSSQuery.js')).buildCSSQuery(emc);
|
|
92
|
+
return mountedElement.matches(cssQuery);
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/Events.js
CHANGED
|
@@ -5,65 +5,74 @@ export const dismountEventName = 'dismount';
|
|
|
5
5
|
export const disconnectEventName = 'disconnect';
|
|
6
6
|
export const mediamatchEventName = 'mediamatch';
|
|
7
7
|
export const mediaunmatchEventName = 'mediaunmatch';
|
|
8
|
+
export const resolvedEventName = 'resolved';
|
|
8
9
|
export class MountEvent extends Event {
|
|
9
10
|
mountedElement;
|
|
10
11
|
modules;
|
|
11
|
-
|
|
12
|
+
mountConfig;
|
|
12
13
|
mountContext;
|
|
13
14
|
static eventName = mountEventName;
|
|
14
|
-
constructor(mountedElement, modules,
|
|
15
|
+
constructor(mountedElement, modules, mountConfig, mountContext) {
|
|
15
16
|
super(MountEvent.eventName);
|
|
16
17
|
this.mountedElement = mountedElement;
|
|
17
18
|
this.modules = modules;
|
|
18
|
-
this.
|
|
19
|
+
this.mountConfig = mountConfig;
|
|
19
20
|
this.mountContext = mountContext;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
export class DismountEvent extends Event {
|
|
23
24
|
mountedElement;
|
|
24
25
|
reason;
|
|
25
|
-
|
|
26
|
+
mountConfig;
|
|
26
27
|
static eventName = dismountEventName;
|
|
27
|
-
constructor(mountedElement, reason,
|
|
28
|
+
constructor(mountedElement, reason, mountConfig) {
|
|
28
29
|
super(DismountEvent.eventName);
|
|
29
30
|
this.mountedElement = mountedElement;
|
|
30
31
|
this.reason = reason;
|
|
31
|
-
this.
|
|
32
|
+
this.mountConfig = mountConfig;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
export class DisconnectEvent extends Event {
|
|
35
36
|
mountedElement;
|
|
36
|
-
|
|
37
|
+
mountConfig;
|
|
37
38
|
static eventName = disconnectEventName;
|
|
38
|
-
constructor(mountedElement,
|
|
39
|
+
constructor(mountedElement, mountConfig) {
|
|
39
40
|
super(DisconnectEvent.eventName);
|
|
40
41
|
this.mountedElement = mountedElement;
|
|
41
|
-
this.
|
|
42
|
+
this.mountConfig = mountConfig;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
export class LoadEvent extends Event {
|
|
45
46
|
modules;
|
|
46
|
-
|
|
47
|
+
mountConfig;
|
|
47
48
|
static eventName = loadEventName;
|
|
48
|
-
constructor(modules,
|
|
49
|
+
constructor(modules, mountConfig) {
|
|
49
50
|
super(LoadEvent.eventName);
|
|
50
51
|
this.modules = modules;
|
|
51
|
-
this.
|
|
52
|
+
this.mountConfig = mountConfig;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
export class MediaMatchEvent extends Event {
|
|
55
|
-
|
|
56
|
+
mountConfig;
|
|
56
57
|
static eventName = mediamatchEventName;
|
|
57
|
-
constructor(
|
|
58
|
+
constructor(mountConfig) {
|
|
58
59
|
super(MediaMatchEvent.eventName);
|
|
59
|
-
this.
|
|
60
|
+
this.mountConfig = mountConfig;
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
export class MediaUnmatchEvent extends Event {
|
|
63
|
-
|
|
64
|
+
mountConfig;
|
|
64
65
|
static eventName = mediaunmatchEventName;
|
|
65
|
-
constructor(
|
|
66
|
+
constructor(mountConfig) {
|
|
66
67
|
super(MediaUnmatchEvent.eventName);
|
|
67
|
-
this.
|
|
68
|
+
this.mountConfig = mountConfig;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class ResolvedEvent extends Event {
|
|
72
|
+
static eventName = resolvedEventName;
|
|
73
|
+
export;
|
|
74
|
+
constructor(exportValue) {
|
|
75
|
+
super(ResolvedEvent.eventName);
|
|
76
|
+
this.export = exportValue;
|
|
68
77
|
}
|
|
69
78
|
}
|
package/Events.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const dismountEventName = 'dismount';
|
|
|
8
8
|
export const disconnectEventName = 'disconnect';
|
|
9
9
|
export const mediamatchEventName = 'mediamatch';
|
|
10
10
|
export const mediaunmatchEventName = 'mediaunmatch';
|
|
11
|
+
export const resolvedEventName = 'resolved';
|
|
11
12
|
|
|
12
13
|
export class MountEvent extends Event implements IMountEvent {
|
|
13
14
|
static eventName: typeof mountEventName = mountEventName;
|
|
@@ -15,7 +16,7 @@ export class MountEvent extends Event implements IMountEvent {
|
|
|
15
16
|
constructor(
|
|
16
17
|
public mountedElement: Element,
|
|
17
18
|
public modules: any[],
|
|
18
|
-
public
|
|
19
|
+
public mountConfig: MountConfig,
|
|
19
20
|
public mountContext: MountContext
|
|
20
21
|
) {
|
|
21
22
|
super(MountEvent.eventName);
|
|
@@ -25,7 +26,7 @@ export class MountEvent extends Event implements IMountEvent {
|
|
|
25
26
|
export class DismountEvent extends Event implements IDismountEvent {
|
|
26
27
|
static eventName: typeof dismountEventName = dismountEventName;
|
|
27
28
|
|
|
28
|
-
constructor(public mountedElement: Element, public reason: DismountReason, public
|
|
29
|
+
constructor(public mountedElement: Element, public reason: DismountReason, public mountConfig: MountConfig) {
|
|
29
30
|
super(DismountEvent.eventName);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -33,7 +34,7 @@ export class DismountEvent extends Event implements IDismountEvent {
|
|
|
33
34
|
export class DisconnectEvent extends Event {
|
|
34
35
|
static eventName: typeof disconnectEventName = disconnectEventName;
|
|
35
36
|
|
|
36
|
-
constructor(public mountedElement: Element, public
|
|
37
|
+
constructor(public mountedElement: Element, public mountConfig: MountConfig) {
|
|
37
38
|
super(DisconnectEvent.eventName);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -41,7 +42,7 @@ export class DisconnectEvent extends Event {
|
|
|
41
42
|
export class LoadEvent extends Event {
|
|
42
43
|
static eventName: typeof loadEventName = loadEventName;
|
|
43
44
|
|
|
44
|
-
constructor(public modules: any[], public
|
|
45
|
+
constructor(public modules: any[], public mountConfig: MountConfig) {
|
|
45
46
|
super(LoadEvent.eventName);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -49,7 +50,7 @@ export class LoadEvent extends Event {
|
|
|
49
50
|
export class MediaMatchEvent extends Event {
|
|
50
51
|
static eventName: typeof mediamatchEventName = mediamatchEventName;
|
|
51
52
|
|
|
52
|
-
constructor(public
|
|
53
|
+
constructor(public mountConfig: MountConfig) {
|
|
53
54
|
super(MediaMatchEvent.eventName);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -57,7 +58,18 @@ export class MediaMatchEvent extends Event {
|
|
|
57
58
|
export class MediaUnmatchEvent extends Event {
|
|
58
59
|
static eventName: typeof mediaunmatchEventName = mediaunmatchEventName;
|
|
59
60
|
|
|
60
|
-
constructor(public
|
|
61
|
+
constructor(public mountConfig: MountConfig) {
|
|
61
62
|
super(MediaUnmatchEvent.eventName);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
export class ResolvedEvent extends Event {
|
|
67
|
+
static eventName: typeof resolvedEventName = resolvedEventName;
|
|
68
|
+
|
|
69
|
+
export: any;
|
|
70
|
+
|
|
71
|
+
constructor(exportValue: any) {
|
|
72
|
+
super(ResolvedEvent.eventName);
|
|
73
|
+
this.export = exportValue;
|
|
74
|
+
}
|
|
75
|
+
}
|
package/EvtRt.js
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
import { DismountEvent, MountEvent, DisconnectEvent, dismountEventName, disconnectEventName, mountEventName } from './Events.js';
|
|
2
|
+
import { MountObserver } from './MountObserver.js';
|
|
2
3
|
export class EvtRt {
|
|
3
4
|
#ac;
|
|
4
5
|
constructor(mountedElement, ctx) {
|
|
5
|
-
const { observer,
|
|
6
|
+
const { observer, mountConfig } = ctx;
|
|
6
7
|
this.#ac = new AbortController();
|
|
7
8
|
const et = observer.getNotifier(mountedElement);
|
|
8
9
|
et.addEventListener(mountEventName, this, { signal: this.#ac.signal });
|
|
9
10
|
et.addEventListener(disconnectEventName, this, { signal: this.#ac.signal });
|
|
10
11
|
et.addEventListener(dismountEventName, this, { signal: this.#ac.signal });
|
|
11
|
-
this.mount(mountedElement,
|
|
12
|
+
this.mount(mountedElement, mountConfig, ctx);
|
|
12
13
|
}
|
|
13
14
|
abort() {
|
|
14
15
|
this.#ac.abort();
|
|
15
16
|
}
|
|
16
|
-
mount(mountedElement,
|
|
17
|
-
console.log({ mountedElement,
|
|
17
|
+
mount(mountedElement, mountConfig, context) {
|
|
18
|
+
console.log({ mountedElement, mountConfig, context });
|
|
18
19
|
}
|
|
19
|
-
disconnect(mountedElement,
|
|
20
|
-
console.log({ mountedElement,
|
|
20
|
+
disconnect(mountedElement, mountConfig) {
|
|
21
|
+
console.log({ mountedElement, mountConfig });
|
|
21
22
|
}
|
|
22
|
-
dismount(mountedElement,
|
|
23
|
-
console.log({ mountedElement,
|
|
23
|
+
dismount(mountedElement, mountConfig) {
|
|
24
|
+
console.log({ mountedElement, mountConfig });
|
|
24
25
|
}
|
|
25
26
|
handleEvent(evt) {
|
|
26
27
|
if (evt instanceof MountEvent) {
|
|
27
|
-
const { mountedElement, mountContext,
|
|
28
|
-
this.mount(mountedElement,
|
|
28
|
+
const { mountedElement, mountContext, mountConfig } = evt;
|
|
29
|
+
this.mount(mountedElement, mountConfig, mountContext);
|
|
29
30
|
}
|
|
30
31
|
else if (evt instanceof DismountEvent) {
|
|
31
|
-
const { mountedElement,
|
|
32
|
-
this.dismount(mountedElement,
|
|
32
|
+
const { mountedElement, mountConfig } = evt;
|
|
33
|
+
this.dismount(mountedElement, mountConfig);
|
|
33
34
|
}
|
|
34
35
|
else if (evt instanceof DisconnectEvent) {
|
|
35
|
-
const { mountedElement,
|
|
36
|
-
this.disconnect(mountedElement,
|
|
36
|
+
const { mountedElement, mountConfig } = evt;
|
|
37
|
+
this.disconnect(mountedElement, mountConfig);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
MountObserver.define('builtIns.logToConsole', EvtRt);
|
package/EvtRt.ts
CHANGED
|
@@ -4,19 +4,20 @@ import {
|
|
|
4
4
|
DismountEvent, MountEvent, DisconnectEvent,
|
|
5
5
|
dismountEventName, disconnectEventName, mountEventName
|
|
6
6
|
} from './Events.js';
|
|
7
|
+
import { MountObserver } from './MountObserver.js';
|
|
7
8
|
export class EvtRt implements EventListenerObject{
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
#ac: AbortController;
|
|
11
12
|
|
|
12
13
|
constructor(mountedElement: Element, ctx: MountContext ){
|
|
13
|
-
const {observer,
|
|
14
|
+
const {observer, mountConfig} = ctx;
|
|
14
15
|
this.#ac = new AbortController();
|
|
15
16
|
const et = observer.getNotifier(mountedElement);
|
|
16
17
|
et.addEventListener(mountEventName, this, {signal: this.#ac.signal});
|
|
17
18
|
et.addEventListener(disconnectEventName, this, {signal: this.#ac.signal});
|
|
18
19
|
et.addEventListener(dismountEventName, this, {signal: this.#ac.signal});
|
|
19
|
-
this.mount(mountedElement,
|
|
20
|
+
this.mount(mountedElement, mountConfig, ctx);
|
|
20
21
|
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -24,28 +25,30 @@ export class EvtRt implements EventListenerObject{
|
|
|
24
25
|
this.#ac.abort();
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
mount(mountedElement: Element,
|
|
28
|
-
console.log({mountedElement,
|
|
28
|
+
mount(mountedElement: Element, mountConfig: MountConfig, context: MountContext){
|
|
29
|
+
console.log({mountedElement, mountConfig, context});
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
disconnect(mountedElement: Element,
|
|
32
|
-
console.log({mountedElement,
|
|
32
|
+
disconnect(mountedElement: Element, mountConfig: MountConfig){
|
|
33
|
+
console.log({mountedElement, mountConfig});
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
dismount(mountedElement: Element,
|
|
36
|
-
console.log({mountedElement,
|
|
36
|
+
dismount(mountedElement: Element, mountConfig: MountConfig){
|
|
37
|
+
console.log({mountedElement, mountConfig});
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
handleEvent(evt: Event): void {
|
|
40
41
|
if(evt instanceof MountEvent){
|
|
41
|
-
const {mountedElement, mountContext,
|
|
42
|
-
this.mount(mountedElement,
|
|
42
|
+
const {mountedElement, mountContext, mountConfig} = evt;
|
|
43
|
+
this.mount(mountedElement, mountConfig, mountContext);
|
|
43
44
|
}else if(evt instanceof DismountEvent){
|
|
44
|
-
const {mountedElement,
|
|
45
|
-
this.dismount(mountedElement,
|
|
45
|
+
const {mountedElement, mountConfig} = evt;
|
|
46
|
+
this.dismount(mountedElement, mountConfig);
|
|
46
47
|
}else if(evt instanceof DisconnectEvent){
|
|
47
|
-
const {mountedElement,
|
|
48
|
-
this.disconnect(mountedElement,
|
|
48
|
+
const {mountedElement, mountConfig} = evt;
|
|
49
|
+
this.disconnect(mountedElement, mountConfig);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
MountObserver.define('builtIns.logToConsole', EvtRt);
|