mount-observer 0.1.15 → 0.1.17

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.
@@ -71,6 +71,9 @@ Object.defineProperty(Node.prototype, 'mount', {
71
71
  if (!(this instanceof Element)) {
72
72
  throw new Error('mount() can only be called on Element, ShadowRoot, or Document');
73
73
  }
74
+ if (this instanceof HTMLScriptElement) {
75
+ options.mose = new WeakRef(this);
76
+ }
74
77
  const scope = options.scope ?? 'registry'; // NEW DEFAULT
75
78
  let thingToObserve;
76
79
  if (scope === 'registry') {
@@ -84,7 +87,7 @@ Object.defineProperty(Node.prototype, 'mount', {
84
87
  const registry = this.customElementRegistry;
85
88
  // Register with coordinator if registry exists
86
89
  if (registry) {
87
- await getOrInsertObserverEntry(registry, config, thingToObserve);
90
+ await getOrInsertObserverEntry(registry, config, thingToObserve, options);
88
91
  }
89
92
  else {
90
93
  // No registry, just create a standalone observer
@@ -146,7 +149,7 @@ Object.defineProperty(Element.prototype, 'mountScope', {
146
149
  const configs = registry.mountConfigRegistry.items;
147
150
  // For each config, ensure an observer exists for this registry root
148
151
  for (const config of configs) {
149
- await getOrInsertObserverEntry(registry, config, registryRoot);
152
+ await getOrInsertObserverEntry(registry, config, registryRoot, {});
150
153
  }
151
154
  },
152
155
  writable: true,
@@ -95,6 +95,7 @@ Object.defineProperty(Node.prototype, 'mount', {
95
95
  config: MountConfig,
96
96
  options: MountObserverOptions = {}
97
97
  ): Promise<T> {
98
+
98
99
  // For ShadowRoot and Document, observe directly
99
100
  if (this instanceof ShadowRoot || this instanceof Document) {
100
101
  const mo = new MountObserver(config, options);
@@ -106,6 +107,10 @@ Object.defineProperty(Node.prototype, 'mount', {
106
107
  if (!(this instanceof Element)) {
107
108
  throw new Error('mount() can only be called on Element, ShadowRoot, or Document');
108
109
  }
110
+
111
+ if(this instanceof HTMLScriptElement) {
112
+ options.mose = new WeakRef(this);
113
+ }
109
114
 
110
115
  const scope = options.scope ?? 'registry'; // NEW DEFAULT
111
116
  let thingToObserve: Node;
@@ -123,7 +128,7 @@ Object.defineProperty(Node.prototype, 'mount', {
123
128
 
124
129
  // Register with coordinator if registry exists
125
130
  if (registry) {
126
- await getOrInsertObserverEntry(registry, config, thingToObserve);
131
+ await getOrInsertObserverEntry(registry, config, thingToObserve, options);
127
132
  } else {
128
133
  // No registry, just create a standalone observer
129
134
  const mo = new MountObserver(config, options);
@@ -185,7 +190,7 @@ Object.defineProperty(Element.prototype, 'mountScope', {
185
190
 
186
191
  // For each config, ensure an observer exists for this registry root
187
192
  for (const config of configs) {
188
- await getOrInsertObserverEntry(registry, config, registryRoot);
193
+ await getOrInsertObserverEntry(registry, config, registryRoot, {});
189
194
  }
190
195
  },
191
196
  writable: true,
package/MountObserver.js CHANGED
@@ -13,6 +13,9 @@ export class MountObserver extends EventTarget {
13
13
  }
14
14
  #init;
15
15
  #options;
16
+ get options() {
17
+ return { ...this.#options };
18
+ }
16
19
  #abortController;
17
20
  #modules = [];
18
21
  #configFromPromise;
package/MountObserver.ts CHANGED
@@ -37,6 +37,9 @@ export class MountObserver<TKeys extends string = string> extends EventTarget im
37
37
 
38
38
  #init: MountConfig;
39
39
  #options: MountObserverOptions;
40
+ get options(): MountObserverOptions {
41
+ return { ...this.#options };
42
+ }
40
43
  #abortController: AbortController;
41
44
  #modules: any[] = [];
42
45
  #configFromPromise: Promise<void> | undefined;
@@ -55,10 +55,10 @@ if (typeof WeakMap.prototype.getOrInsertComputed !== 'function') {
55
55
  * Helper to create an observer entry asynchronously.
56
56
  * Separated to handle async operations cleanly.
57
57
  */
58
- async function createObserverEntry(config, registryRoot) {
58
+ async function createObserverEntry(config, registryRoot, options) {
59
59
  // Dynamically import to avoid circular dependency
60
60
  const { MountObserver: MountObserverClass } = await import('./MountObserver.js');
61
- const observer = new MountObserverClass(config);
61
+ const observer = new MountObserverClass(config, options);
62
62
  await observer.observe(registryRoot);
63
63
  return {
64
64
  config,
@@ -76,7 +76,7 @@ async function createObserverEntry(config, registryRoot) {
76
76
  *
77
77
  * @returns The ObserverEntry for the requested combination
78
78
  */
79
- export async function getOrInsertObserverEntry(registry, config, registryRoot) {
79
+ export async function getOrInsertObserverEntry(registry, config, registryRoot, options) {
80
80
  // Add config to the registry's config list (if not already there)
81
81
  registry.mountConfigRegistry.push(config);
82
82
  // Get or create the nested map structure
@@ -85,7 +85,7 @@ export async function getOrInsertObserverEntry(registry, config, registryRoot) {
85
85
  // Get or create the observer for this specific registry root
86
86
  let observerEntry = nodeToObserverMap.get(registryRoot);
87
87
  if (!observerEntry) {
88
- observerEntry = await createObserverEntry(config, registryRoot);
88
+ observerEntry = await createObserverEntry(config, registryRoot, options);
89
89
  nodeToObserverMap.set(registryRoot, observerEntry);
90
90
  }
91
91
  // Track this registry root in the scopes set
@@ -116,7 +116,7 @@ export async function getOrInsertObserverEntry(registry, config, registryRoot) {
116
116
  const confObserverMap = mountConfigMap.getOrInsertComputed(conf, () => new WeakMap());
117
117
  let existingEntry = confObserverMap.get(regRoot);
118
118
  if (!existingEntry) {
119
- existingEntry = await createObserverEntry(conf, regRoot);
119
+ existingEntry = await createObserverEntry(conf, regRoot, options);
120
120
  confObserverMap.set(regRoot, existingEntry);
121
121
  }
122
122
  }
@@ -4,7 +4,7 @@
4
4
  * where all scopes with the same registry share mount observers.
5
5
  */
6
6
 
7
- import type { MountConfig, WeakDual } from './types/mount-observer/types.js';
7
+ import type { MountConfig, MountObserverOptions, WeakDual } from './types/mount-observer/types.js';
8
8
  import type { MountObserver } from './MountObserver.js';
9
9
 
10
10
  /**
@@ -98,11 +98,12 @@ if (typeof WeakMap.prototype.getOrInsertComputed !== 'function') {
98
98
  */
99
99
  async function createObserverEntry(
100
100
  config: MountConfig,
101
- registryRoot: Node
101
+ registryRoot: Node,
102
+ options: MountObserverOptions
102
103
  ): Promise<ObserverEntry> {
103
104
  // Dynamically import to avoid circular dependency
104
105
  const { MountObserver: MountObserverClass } = await import('./MountObserver.js');
105
- const observer = new MountObserverClass(config);
106
+ const observer = new MountObserverClass(config, options);
106
107
  await observer.observe(registryRoot);
107
108
  return {
108
109
  config,
@@ -124,7 +125,8 @@ async function createObserverEntry(
124
125
  export async function getOrInsertObserverEntry(
125
126
  registry: CustomElementRegistry,
126
127
  config: MountConfig,
127
- registryRoot: Node
128
+ registryRoot: Node,
129
+ options: MountObserverOptions
128
130
  ): Promise<ObserverEntry> {
129
131
  // Add config to the registry's config list (if not already there)
130
132
  (registry as any).mountConfigRegistry.push(config);
@@ -136,7 +138,7 @@ export async function getOrInsertObserverEntry(
136
138
  // Get or create the observer for this specific registry root
137
139
  let observerEntry = nodeToObserverMap.get(registryRoot);
138
140
  if (!observerEntry) {
139
- observerEntry = await createObserverEntry(config, registryRoot);
141
+ observerEntry = await createObserverEntry(config, registryRoot, options);
140
142
  nodeToObserverMap.set(registryRoot, observerEntry);
141
143
  }
142
144
 
@@ -171,7 +173,7 @@ export async function getOrInsertObserverEntry(
171
173
  const confObserverMap = mountConfigMap.getOrInsertComputed(conf, () => new WeakMap());
172
174
  let existingEntry = confObserverMap.get(regRoot);
173
175
  if (!existingEntry) {
174
- existingEntry = await createObserverEntry(conf, regRoot);
176
+ existingEntry = await createObserverEntry(conf, regRoot, options);
175
177
  confObserverMap.set(regRoot, existingEntry);
176
178
  }
177
179
  }
@@ -23,6 +23,16 @@ export class EnhanceMountedElementHandler extends EvtRt {
23
23
  if (typeof registryItem.spawn !== 'function') {
24
24
  throw new Error('Registry item "spawn" property must be a constructor function');
25
25
  }
26
+ const tbd = context?.observer?.options?.mose;
27
+ if (tbd) {
28
+ const se = tbd.deref();
29
+ const { parentElement } = se;
30
+ const { enhKey } = registryItem;
31
+ if (!se.id && enhKey) {
32
+ se.id = `${parentElement?.localName}.${enhKey}`;
33
+ }
34
+ }
35
+ console.log({ tbd });
26
36
  // Spawn the enhancement
27
37
  this.#spawnEnhancement(mountedElement, registryItem, context);
28
38
  }
@@ -30,6 +30,16 @@ export class EnhanceMountedElementHandler extends EvtRt {
30
30
  if (typeof registryItem.spawn !== 'function') {
31
31
  throw new Error('Registry item "spawn" property must be a constructor function');
32
32
  }
33
+ const tbd = context?.observer?.options?.mose;
34
+ if(tbd){
35
+ const se = tbd.deref() as HTMLScriptElement;
36
+ const {parentElement} = se;
37
+ const {enhKey} = registryItem;
38
+ if(!se.id && enhKey){
39
+ se.id = `${parentElement?.localName}.${ enhKey}`;
40
+ }
41
+ }
42
+ console.log({ tbd });
33
43
 
34
44
  // Spawn the enhancement
35
45
  this.#spawnEnhancement(mountedElement, registryItem, context);
@@ -34,4 +34,5 @@ export class GenerateIdsHandler extends EvtRt {
34
34
  }
35
35
  // Register built-in handler
36
36
  import { MountObserver } from '../MountObserver.js';
37
- MountObserver.define('builtIns.generateIds', GenerateIdsHandler);
37
+ export const genIds = 'builtIns.generateIds';
38
+ MountObserver.define(genIds, GenerateIdsHandler);
@@ -42,4 +42,5 @@ export class GenerateIdsHandler extends EvtRt {
42
42
  // Register built-in handler
43
43
  import { MountObserver } from '../MountObserver.js';
44
44
 
45
- MountObserver.define('builtIns.generateIds', GenerateIdsHandler);
45
+ export const genIds = 'builtIns.generateIds';
46
+ MountObserver.define(genIds, GenerateIdsHandler);
@@ -390,4 +390,5 @@ export class HTMLIncludeHandler extends EvtRt {
390
390
  }
391
391
  // Register the handler
392
392
  import { MountObserver } from '../MountObserver.js';
393
- MountObserver.define('builtIns.HTMLInclude', HTMLIncludeHandler);
393
+ export const include = 'builtIns.HTMLInclude';
394
+ MountObserver.define(include, HTMLIncludeHandler);
@@ -450,4 +450,6 @@ export class HTMLIncludeHandler extends EvtRt {
450
450
  // Register the handler
451
451
  import { MountObserver } from '../MountObserver.js';
452
452
 
453
- MountObserver.define('builtIns.HTMLInclude', HTMLIncludeHandler);
453
+ export const include = 'builtIns.HTMLInclude';
454
+
455
+ MountObserver.define(include, HTMLIncludeHandler);
@@ -74,4 +74,5 @@ function hoistTemplate(templ) {
74
74
  }
75
75
  // Register the handler
76
76
  import { MountObserver } from '../MountObserver.js';
77
- MountObserver.define('builtIns.hoistTemplate', HoistTemplateHandler);
77
+ export const hoist = 'builtIns.hoistTemplate';
78
+ MountObserver.define(hoist, HoistTemplateHandler);
@@ -86,4 +86,6 @@ function hoistTemplate(templ: HTMLTemplateElement): void {
86
86
  // Register the handler
87
87
  import { MountObserver } from '../MountObserver.js';
88
88
 
89
- MountObserver.define('builtIns.hoistTemplate', HoistTemplateHandler);
89
+ export const hoist = 'builtIns.hoistTemplate';
90
+
91
+ MountObserver.define(hoist, HoistTemplateHandler);
@@ -25,9 +25,9 @@ export class MountObserverScriptHandler extends EvtRt {
25
25
  const srcAttr = scriptElement.getAttribute('src');
26
26
  if (srcAttr) {
27
27
  // External JSON mode: import from src
28
- const resolvedUrl = new URL(srcAttr, document.baseURI).href;
28
+ //const resolvedUrl = new URL(srcAttr, document.baseURI).href;
29
29
  try {
30
- const module = await import(resolvedUrl, { with: { type: 'json' } });
30
+ const module = await import(srcAttr, { with: { type: 'json' } });
31
31
  config = module.default;
32
32
  }
33
33
  catch (error) {
@@ -75,4 +75,5 @@ export class MountObserverScriptHandler extends EvtRt {
75
75
  }
76
76
  // Register built-in handler
77
77
  import { MountObserver } from '../MountObserver.js';
78
- MountObserver.define('builtIns.mountObserverScript', MountObserverScriptHandler);
78
+ export const mos = 'builtIns.mountObserverScript';
79
+ MountObserver.define(mos, MountObserverScriptHandler);
@@ -31,10 +31,10 @@ export class MountObserverScriptHandler extends EvtRt {
31
31
 
32
32
  if (srcAttr) {
33
33
  // External JSON mode: import from src
34
- const resolvedUrl = new URL(srcAttr, document.baseURI).href;
34
+ //const resolvedUrl = new URL(srcAttr, document.baseURI).href;
35
35
 
36
36
  try {
37
- const module = await import(resolvedUrl, { with: { type: 'json' } } as any);
37
+ const module = await import(srcAttr, { with: { type: 'json' } } as any);
38
38
  config = module.default;
39
39
  } catch (error) {
40
40
  throw new Error(`Failed to import JSON from '${srcAttr}': ${error instanceof Error ? error.message : String(error)}`);
@@ -86,4 +86,7 @@ export class MountObserverScriptHandler extends EvtRt {
86
86
  // Register built-in handler
87
87
  import { MountObserver } from '../MountObserver.js';
88
88
 
89
- MountObserver.define('builtIns.mountObserverScript', MountObserverScriptHandler);
89
+ export const mos = 'builtIns.mountObserverScript';
90
+
91
+ MountObserver.define(mos, MountObserverScriptHandler);
92
+
@@ -80,4 +80,5 @@ export class ScriptExportHandler extends EvtRt {
80
80
  }
81
81
  // Register built-in handler
82
82
  import { MountObserver } from '../MountObserver.js';
83
- MountObserver.define('builtIns.scriptExport', ScriptExportHandler);
83
+ export const scriptExport = 'builtIns.scriptExport';
84
+ MountObserver.define(scriptExport, ScriptExportHandler);
@@ -94,4 +94,6 @@ export class ScriptExportHandler extends EvtRt {
94
94
  // Register built-in handler
95
95
  import { MountObserver } from '../MountObserver.js';
96
96
 
97
- MountObserver.define('builtIns.scriptExport', ScriptExportHandler);
97
+ export const scriptExport = 'builtIns.scriptExport';
98
+
99
+ MountObserver.define(scriptExport, ScriptExportHandler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
@@ -294,6 +294,7 @@ export type MountScope =
294
294
  export interface MountObserverOptions {
295
295
  disconnectedSignal?: AbortSignal;
296
296
  scope?: MountScope;
297
+ mose?: WeakRef<HTMLScriptElement>;
297
298
  }
298
299
 
299
300
  export interface WeakDual<T extends Object>{
@@ -312,6 +313,7 @@ export interface IMountObserver extends EventTarget {
312
313
  disconnectedSignal: AbortSignal;
313
314
  assignGingerly(config: Record<string, any> | undefined): Promise<void>;
314
315
  getNotifier(element: Element): EventTarget;
316
+ readonly options: MountObserverOptions;
315
317
  }
316
318
 
317
319
  export interface IMountEvent extends Event {
@@ -1,96 +0,0 @@
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,110 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ResolvedEvent = exports.MediaUnmatchEvent = exports.MediaMatchEvent = exports.LoadEvent = exports.DisconnectEvent = exports.DismountEvent = exports.MountEvent = exports.resolvedEventName = exports.mediaunmatchEventName = exports.mediamatchEventName = exports.disconnectEventName = exports.dismountEventName = exports.mountEventName = exports.loadEventName = void 0;
19
- // Event name constants
20
- exports.loadEventName = 'load';
21
- exports.mountEventName = 'mount';
22
- exports.dismountEventName = 'dismount';
23
- exports.disconnectEventName = 'disconnect';
24
- exports.mediamatchEventName = 'mediamatch';
25
- exports.mediaunmatchEventName = 'mediaunmatch';
26
- exports.resolvedEventName = 'resolved';
27
- var MountEvent = /** @class */ (function (_super) {
28
- __extends(MountEvent, _super);
29
- function MountEvent(mountedElement, modules, mountConfig, mountContext) {
30
- var _this = _super.call(this, MountEvent.eventName) || this;
31
- _this.mountedElement = mountedElement;
32
- _this.modules = modules;
33
- _this.mountConfig = mountConfig;
34
- _this.mountContext = mountContext;
35
- return _this;
36
- }
37
- MountEvent.eventName = exports.mountEventName;
38
- return MountEvent;
39
- }(Event));
40
- exports.MountEvent = MountEvent;
41
- var DismountEvent = /** @class */ (function (_super) {
42
- __extends(DismountEvent, _super);
43
- function DismountEvent(mountedElement, reason, mountConfig) {
44
- var _this = _super.call(this, DismountEvent.eventName) || this;
45
- _this.mountedElement = mountedElement;
46
- _this.reason = reason;
47
- _this.mountConfig = mountConfig;
48
- return _this;
49
- }
50
- DismountEvent.eventName = exports.dismountEventName;
51
- return DismountEvent;
52
- }(Event));
53
- exports.DismountEvent = DismountEvent;
54
- var DisconnectEvent = /** @class */ (function (_super) {
55
- __extends(DisconnectEvent, _super);
56
- function DisconnectEvent(mountedElement, mountConfig) {
57
- var _this = _super.call(this, DisconnectEvent.eventName) || this;
58
- _this.mountedElement = mountedElement;
59
- _this.mountConfig = mountConfig;
60
- return _this;
61
- }
62
- DisconnectEvent.eventName = exports.disconnectEventName;
63
- return DisconnectEvent;
64
- }(Event));
65
- exports.DisconnectEvent = DisconnectEvent;
66
- var LoadEvent = /** @class */ (function (_super) {
67
- __extends(LoadEvent, _super);
68
- function LoadEvent(modules, mountConfig) {
69
- var _this = _super.call(this, LoadEvent.eventName) || this;
70
- _this.modules = modules;
71
- _this.mountConfig = mountConfig;
72
- return _this;
73
- }
74
- LoadEvent.eventName = exports.loadEventName;
75
- return LoadEvent;
76
- }(Event));
77
- exports.LoadEvent = LoadEvent;
78
- var MediaMatchEvent = /** @class */ (function (_super) {
79
- __extends(MediaMatchEvent, _super);
80
- function MediaMatchEvent(mountConfig) {
81
- var _this = _super.call(this, MediaMatchEvent.eventName) || this;
82
- _this.mountConfig = mountConfig;
83
- return _this;
84
- }
85
- MediaMatchEvent.eventName = exports.mediamatchEventName;
86
- return MediaMatchEvent;
87
- }(Event));
88
- exports.MediaMatchEvent = MediaMatchEvent;
89
- var MediaUnmatchEvent = /** @class */ (function (_super) {
90
- __extends(MediaUnmatchEvent, _super);
91
- function MediaUnmatchEvent(mountConfig) {
92
- var _this = _super.call(this, MediaUnmatchEvent.eventName) || this;
93
- _this.mountConfig = mountConfig;
94
- return _this;
95
- }
96
- MediaUnmatchEvent.eventName = exports.mediaunmatchEventName;
97
- return MediaUnmatchEvent;
98
- }(Event));
99
- exports.MediaUnmatchEvent = MediaUnmatchEvent;
100
- var ResolvedEvent = /** @class */ (function (_super) {
101
- __extends(ResolvedEvent, _super);
102
- function ResolvedEvent(exportValue) {
103
- var _this = _super.call(this, ResolvedEvent.eventName) || this;
104
- _this.export = exportValue;
105
- return _this;
106
- }
107
- ResolvedEvent.eventName = exports.resolvedEventName;
108
- return ResolvedEvent;
109
- }(Event));
110
- exports.ResolvedEvent = ResolvedEvent;
package/handlers/EvtRt.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _EvtRt_ac;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.EvtRt = void 0;
16
- var Events_js_1 = require("./Events.js");
17
- var MountObserver_js_1 = require("./MountObserver.js");
18
- var EvtRt = /** @class */ (function () {
19
- function EvtRt(mountedElement, ctx) {
20
- _EvtRt_ac.set(this, void 0);
21
- var observer = ctx.observer, mountConfig = ctx.mountConfig;
22
- __classPrivateFieldSet(this, _EvtRt_ac, new AbortController(), "f");
23
- var et = observer.getNotifier(mountedElement);
24
- et.addEventListener(Events_js_1.mountEventName, this, { signal: __classPrivateFieldGet(this, _EvtRt_ac, "f").signal });
25
- et.addEventListener(Events_js_1.disconnectEventName, this, { signal: __classPrivateFieldGet(this, _EvtRt_ac, "f").signal });
26
- et.addEventListener(Events_js_1.dismountEventName, this, { signal: __classPrivateFieldGet(this, _EvtRt_ac, "f").signal });
27
- this.mount(mountedElement, mountConfig, ctx);
28
- }
29
- EvtRt.prototype.abort = function () {
30
- __classPrivateFieldGet(this, _EvtRt_ac, "f").abort();
31
- };
32
- EvtRt.prototype.mount = function (mountedElement, mountConfig, context) {
33
- console.log({ mountedElement: mountedElement, mountConfig: mountConfig, context: context });
34
- };
35
- EvtRt.prototype.disconnect = function (mountedElement, mountConfig) {
36
- console.log({ mountedElement: mountedElement, mountConfig: mountConfig });
37
- };
38
- EvtRt.prototype.dismount = function (mountedElement, mountConfig) {
39
- console.log({ mountedElement: mountedElement, mountConfig: mountConfig });
40
- };
41
- EvtRt.prototype.handleEvent = function (evt) {
42
- if (evt instanceof Events_js_1.MountEvent) {
43
- var mountedElement = evt.mountedElement, mountContext = evt.mountContext, mountConfig = evt.mountConfig;
44
- this.mount(mountedElement, mountConfig, mountContext);
45
- }
46
- else if (evt instanceof Events_js_1.DismountEvent) {
47
- var mountedElement = evt.mountedElement, mountConfig = evt.mountConfig;
48
- this.dismount(mountedElement, mountConfig);
49
- }
50
- else if (evt instanceof Events_js_1.DisconnectEvent) {
51
- var mountedElement = evt.mountedElement, mountConfig = evt.mountConfig;
52
- this.disconnect(mountedElement, mountConfig);
53
- }
54
- };
55
- return EvtRt;
56
- }());
57
- exports.EvtRt = EvtRt;
58
- _EvtRt_ac = new WeakMap();
59
- MountObserver_js_1.MountObserver.define('builtIns.logToConsole', EvtRt);