mount-observer 0.1.26 → 0.1.28
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/handlers/EMCParserScript.ts +132 -0
- package/handlers/EMCScript.js +65 -5
- package/handlers/EMCScript.ts +72 -5
- package/package.json +2 -2
- package/types/assign-gingerly/types.d.ts +56 -5
- package/types/be-a-beacon/types.d.ts +15 -1
- package/types/be-buttoned-up/types.d.ts +19 -0
- package/types/be-clonable/types.d.ts +36 -0
- package/types/be-committed/types.d.ts +2 -6
- package/types/be-delible/types.d.ts +25 -0
- package/types/be-render-neutral/types.d.ts +29 -0
- package/types/be-typed/types.d.ts +31 -0
- package/types/roundabout/types.d.ts +43 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { EvtRt } from '../EvtRt.js';
|
|
2
|
+
import { MountConfig, MountContext } from '../types/mount-observer/types.js';
|
|
3
|
+
import { getParserRegistry } from 'assign-gingerly/parserRegistry.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Handler for EMC Parser Script Elements.
|
|
7
|
+
* Processes script[type="emc-parser"] elements to load and register parser modules
|
|
8
|
+
* in the containing synthesizer element's scoped parser registry.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* <script type="emc-parser" src="./my-parser.js" parser-name="myParser"></script>
|
|
12
|
+
*
|
|
13
|
+
* The parser module should export a parser function as the default export:
|
|
14
|
+
* export default function myParser(v: string | null): any { ... }
|
|
15
|
+
*/
|
|
16
|
+
export class EMCParserScriptHandler extends EvtRt {
|
|
17
|
+
// Static properties define default MountConfig constraints
|
|
18
|
+
static matching = 'script[type="emc-parser"]';
|
|
19
|
+
static whereInstanceOf = HTMLScriptElement;
|
|
20
|
+
|
|
21
|
+
async mount(mountedElement: Element, mountConfig: MountConfig, context: MountContext): Promise<void> {
|
|
22
|
+
this.abort(); // Clean up event listeners (one-time operation)
|
|
23
|
+
|
|
24
|
+
const scriptElement = mountedElement as HTMLScriptElement;
|
|
25
|
+
|
|
26
|
+
// Read required attributes
|
|
27
|
+
const src = scriptElement.getAttribute('src');
|
|
28
|
+
const parserName = scriptElement.getAttribute('parser-name');
|
|
29
|
+
|
|
30
|
+
// Validate required attributes
|
|
31
|
+
if (!src) {
|
|
32
|
+
const errorMsg = 'EMCParserScript: missing src attribute';
|
|
33
|
+
console.error(errorMsg, scriptElement);
|
|
34
|
+
scriptElement.setAttribute('data-parser-error', 'missing src attribute');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!parserName) {
|
|
39
|
+
const errorMsg = 'EMCParserScript: missing parser-name attribute';
|
|
40
|
+
console.error(errorMsg, scriptElement);
|
|
41
|
+
scriptElement.setAttribute('data-parser-error', 'missing parser-name attribute');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Find containing synthesizer element
|
|
46
|
+
const synthesizerElement = this.findContainingSynthesizer(scriptElement);
|
|
47
|
+
if (!synthesizerElement) {
|
|
48
|
+
const errorMsg = 'EMCParserScript: no containing synthesizer element found';
|
|
49
|
+
console.error(errorMsg, scriptElement);
|
|
50
|
+
scriptElement.setAttribute('data-parser-error', 'no containing synthesizer element');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
// Dynamic import the parser module
|
|
56
|
+
const module = await import(src);
|
|
57
|
+
|
|
58
|
+
// Get parser function from default export
|
|
59
|
+
const parser = module.default;
|
|
60
|
+
|
|
61
|
+
// Validate parser is a function
|
|
62
|
+
if (typeof parser !== 'function') {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Parser module "${src}" must export a function as default export. ` +
|
|
65
|
+
`Received: ${typeof parser}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Get scoped registry and register parser
|
|
70
|
+
const registry = getParserRegistry(synthesizerElement);
|
|
71
|
+
registry.register(parserName, parser);
|
|
72
|
+
|
|
73
|
+
// Dispatch parser-registered event
|
|
74
|
+
scriptElement.dispatchEvent(new CustomEvent('parser-registered', {
|
|
75
|
+
detail: { parserName },
|
|
76
|
+
bubbles: true
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
console.log(`Registered parser "${parserName}" from ${src}`);
|
|
80
|
+
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
83
|
+
console.error(`Failed to load parser "${parserName}" from "${src}":`, errorMessage);
|
|
84
|
+
scriptElement.setAttribute('data-parser-error', errorMessage);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Find the nearest ancestor synthesizer element.
|
|
90
|
+
* Traverses up through shadow root boundaries.
|
|
91
|
+
* Looks for elements with data-synthesizer attribute, be-hive tag, or __isSynthesizer property.
|
|
92
|
+
*/
|
|
93
|
+
private findContainingSynthesizer(element: Element): Element | undefined {
|
|
94
|
+
let current: Node | null = element;
|
|
95
|
+
|
|
96
|
+
while (current) {
|
|
97
|
+
if (current instanceof Element) {
|
|
98
|
+
// Check for synthesizer marker or known synthesizer tag names
|
|
99
|
+
if (current.hasAttribute('data-synthesizer') ||
|
|
100
|
+
current.localName === 'be-hive' ||
|
|
101
|
+
(current as any).__isSynthesizer === true) {
|
|
102
|
+
return current;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Try parent element
|
|
107
|
+
if (current.parentElement) {
|
|
108
|
+
current = current.parentElement;
|
|
109
|
+
}
|
|
110
|
+
// Try shadow root host
|
|
111
|
+
else if (current instanceof ShadowRoot) {
|
|
112
|
+
current = (current as ShadowRoot).host;
|
|
113
|
+
}
|
|
114
|
+
// Try parent node (for document fragments)
|
|
115
|
+
else if (current.parentNode) {
|
|
116
|
+
current = current.parentNode;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Register built-in handler
|
|
128
|
+
import { MountObserver } from '../MountObserver.js';
|
|
129
|
+
|
|
130
|
+
export const emcParser = 'builtIns.emcParserScript';
|
|
131
|
+
|
|
132
|
+
MountObserver.define(emcParser, EMCParserScriptHandler);
|
package/handlers/EMCScript.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EvtRt } from '../EvtRt.js';
|
|
2
2
|
import '../ElementMountExtension.js';
|
|
3
3
|
import 'assign-gingerly/object-extension.js';
|
|
4
|
+
import { getParserRegistry } from 'assign-gingerly/parserRegistry.js';
|
|
4
5
|
/**
|
|
5
6
|
* Handler for EMC (Element Mount Configuration) Script Elements.
|
|
6
7
|
* Processes script[type="emc"] elements to declaratively configure element enhancements.
|
|
@@ -18,6 +19,29 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
18
19
|
async mount(mountedElement, MountConfig, context) {
|
|
19
20
|
this.abort(); // Clean up event listeners (one-time operation)
|
|
20
21
|
const scriptElement = mountedElement;
|
|
22
|
+
// Find containing synthesizer element early (needed for parser waiting)
|
|
23
|
+
const synthesizerElement = this.findContainingSynthesizer(scriptElement);
|
|
24
|
+
// Check for parser waiting before processing EMC config
|
|
25
|
+
const waitForParsers = scriptElement.getAttribute('wait-for-parsers');
|
|
26
|
+
if (waitForParsers && synthesizerElement) {
|
|
27
|
+
const parserNames = waitForParsers.trim().split(/\s+/).filter(name => name.length > 0);
|
|
28
|
+
if (parserNames.length > 0) {
|
|
29
|
+
// Read timeout attribute (default: 60000ms = 1 minute)
|
|
30
|
+
const timeoutAttr = scriptElement.getAttribute('data-parser-timeout');
|
|
31
|
+
const timeout = timeoutAttr ? parseInt(timeoutAttr, 10) : 60000;
|
|
32
|
+
try {
|
|
33
|
+
// Get scoped registry and wait for parsers
|
|
34
|
+
const registry = getParserRegistry(synthesizerElement);
|
|
35
|
+
await registry.waitFor(parserNames, timeout);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
39
|
+
console.error(`Parser waiting failed for EMC script:`, errorMessage, scriptElement);
|
|
40
|
+
scriptElement.setAttribute('data-emc-error', errorMessage);
|
|
41
|
+
return; // Stop processing on timeout/error
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
21
45
|
let emcConfig = scriptElement.export;
|
|
22
46
|
if (!emcConfig) {
|
|
23
47
|
// Check if script has src attribute
|
|
@@ -68,14 +92,14 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
68
92
|
scriptElement.id = `${scriptElement.parentElement.localName}.${enhKey}`;
|
|
69
93
|
}
|
|
70
94
|
// Construct MountConfig from EMC config and mount it
|
|
71
|
-
const mountConfig = await this.buildMountConfig(emcConfig);
|
|
95
|
+
const mountConfig = await this.buildMountConfig(emcConfig, synthesizerElement);
|
|
72
96
|
await scriptElement.mount(mountConfig);
|
|
73
97
|
}
|
|
74
98
|
/**
|
|
75
99
|
* Build a MountConfig from an EMC config.
|
|
76
100
|
* Combines the matching selector with withAttrs if present.
|
|
77
101
|
*/
|
|
78
|
-
async buildMountConfig(emcConfig) {
|
|
102
|
+
async buildMountConfig(emcConfig, synthesizerElement) {
|
|
79
103
|
const { enhConfig, ...mountConfigBase } = emcConfig;
|
|
80
104
|
let matching = mountConfigBase.matching || '';
|
|
81
105
|
// If withAttrs is defined, use buildCSSQuery to combine with matching
|
|
@@ -96,7 +120,7 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
96
120
|
...mountConfigBase,
|
|
97
121
|
matching,
|
|
98
122
|
do: (mountedElement) => {
|
|
99
|
-
return this.handleMount(mountedElement, emcConfig);
|
|
123
|
+
return this.handleMount(mountedElement, emcConfig, synthesizerElement);
|
|
100
124
|
}
|
|
101
125
|
};
|
|
102
126
|
return mountConfig;
|
|
@@ -104,7 +128,7 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
104
128
|
/**
|
|
105
129
|
* Handle when an element mounts that matches the EMC config.
|
|
106
130
|
*/
|
|
107
|
-
async handleMount(mountedElement, emcConfig) {
|
|
131
|
+
async handleMount(mountedElement, emcConfig, synthesizerElement) {
|
|
108
132
|
const enhKey = emcConfig.enhConfig.enhKey;
|
|
109
133
|
// Step 1: Check if element already has this enhancement
|
|
110
134
|
const enh = mountedElement.enh;
|
|
@@ -128,7 +152,9 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
128
152
|
if (!enh) {
|
|
129
153
|
throw new Error('Element does not have enh property. Make sure ElementMountExtension is loaded.');
|
|
130
154
|
}
|
|
131
|
-
|
|
155
|
+
// Pass synthesizerElement through SpawnContext if available
|
|
156
|
+
const spawnContext = synthesizerElement ? { synthesizerElement } : undefined;
|
|
157
|
+
await enh.get(enhancementConfig, spawnContext);
|
|
132
158
|
}
|
|
133
159
|
/**
|
|
134
160
|
* Register an enhancement in the enhancement registry.
|
|
@@ -165,6 +191,40 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
165
191
|
enhancementRegistry.push(enhancementConfig);
|
|
166
192
|
return enhancementConfig;
|
|
167
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Find the nearest ancestor synthesizer element.
|
|
196
|
+
* Traverses up through shadow root boundaries.
|
|
197
|
+
* Looks for elements with data-synthesizer attribute, be-hive tag, or __isSynthesizer property.
|
|
198
|
+
*/
|
|
199
|
+
findContainingSynthesizer(element) {
|
|
200
|
+
let current = element;
|
|
201
|
+
while (current) {
|
|
202
|
+
if (current instanceof Element) {
|
|
203
|
+
// Check for synthesizer marker or known synthesizer tag names
|
|
204
|
+
if (current.hasAttribute('data-synthesizer') ||
|
|
205
|
+
current.localName === 'be-hive' ||
|
|
206
|
+
current.__isSynthesizer === true) {
|
|
207
|
+
return current;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Try parent element
|
|
211
|
+
if (current.parentElement) {
|
|
212
|
+
current = current.parentElement;
|
|
213
|
+
}
|
|
214
|
+
// Try shadow root host
|
|
215
|
+
else if (current instanceof ShadowRoot) {
|
|
216
|
+
current = current.host;
|
|
217
|
+
}
|
|
218
|
+
// Try parent node (for document fragments)
|
|
219
|
+
else if (current.parentNode) {
|
|
220
|
+
current = current.parentNode;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
168
228
|
}
|
|
169
229
|
// Register built-in handler
|
|
170
230
|
import { MountObserver } from '../MountObserver.js';
|
package/handlers/EMCScript.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { EvtRt } from '../EvtRt.js';
|
|
|
2
2
|
import { EMC, MountConfig, MountContext } from '../types/mount-observer/types.js';
|
|
3
3
|
import '../ElementMountExtension.js';
|
|
4
4
|
import 'assign-gingerly/object-extension.js';
|
|
5
|
+
import { getParserRegistry } from 'assign-gingerly/parserRegistry.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Handler for EMC (Element Mount Configuration) Script Elements.
|
|
@@ -23,6 +24,32 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
23
24
|
|
|
24
25
|
const scriptElement = mountedElement as HTMLScriptElement;
|
|
25
26
|
|
|
27
|
+
// Find containing synthesizer element early (needed for parser waiting)
|
|
28
|
+
const synthesizerElement = this.findContainingSynthesizer(scriptElement);
|
|
29
|
+
|
|
30
|
+
// Check for parser waiting before processing EMC config
|
|
31
|
+
const waitForParsers = scriptElement.getAttribute('wait-for-parsers');
|
|
32
|
+
if (waitForParsers && synthesizerElement) {
|
|
33
|
+
const parserNames = waitForParsers.trim().split(/\s+/).filter(name => name.length > 0);
|
|
34
|
+
|
|
35
|
+
if (parserNames.length > 0) {
|
|
36
|
+
// Read timeout attribute (default: 60000ms = 1 minute)
|
|
37
|
+
const timeoutAttr = scriptElement.getAttribute('data-parser-timeout');
|
|
38
|
+
const timeout = timeoutAttr ? parseInt(timeoutAttr, 10) : 60000;
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
// Get scoped registry and wait for parsers
|
|
42
|
+
const registry = getParserRegistry(synthesizerElement);
|
|
43
|
+
await registry.waitFor(parserNames, timeout);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
46
|
+
console.error(`Parser waiting failed for EMC script:`, errorMessage, scriptElement);
|
|
47
|
+
scriptElement.setAttribute('data-emc-error', errorMessage);
|
|
48
|
+
return; // Stop processing on timeout/error
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
26
53
|
let emcConfig = (scriptElement as any).export;
|
|
27
54
|
if (!emcConfig) {
|
|
28
55
|
// Check if script has src attribute
|
|
@@ -80,7 +107,7 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
80
107
|
}
|
|
81
108
|
|
|
82
109
|
// Construct MountConfig from EMC config and mount it
|
|
83
|
-
const mountConfig = await this.buildMountConfig(emcConfig);
|
|
110
|
+
const mountConfig = await this.buildMountConfig(emcConfig, synthesizerElement);
|
|
84
111
|
await scriptElement.mount(mountConfig);
|
|
85
112
|
}
|
|
86
113
|
|
|
@@ -88,7 +115,7 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
88
115
|
* Build a MountConfig from an EMC config.
|
|
89
116
|
* Combines the matching selector with withAttrs if present.
|
|
90
117
|
*/
|
|
91
|
-
private async buildMountConfig(emcConfig: EMC): Promise<MountConfig> {
|
|
118
|
+
private async buildMountConfig(emcConfig: EMC, synthesizerElement?: Element): Promise<MountConfig> {
|
|
92
119
|
const { enhConfig, ...mountConfigBase } = emcConfig;
|
|
93
120
|
|
|
94
121
|
let matching = mountConfigBase.matching || '';
|
|
@@ -112,7 +139,7 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
112
139
|
...mountConfigBase,
|
|
113
140
|
matching,
|
|
114
141
|
do: (mountedElement: Element) => {
|
|
115
|
-
return this.handleMount(mountedElement, emcConfig);
|
|
142
|
+
return this.handleMount(mountedElement, emcConfig, synthesizerElement);
|
|
116
143
|
}
|
|
117
144
|
};
|
|
118
145
|
|
|
@@ -122,7 +149,7 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
122
149
|
/**
|
|
123
150
|
* Handle when an element mounts that matches the EMC config.
|
|
124
151
|
*/
|
|
125
|
-
private async handleMount(mountedElement: Element, emcConfig: EMC): Promise<void> {
|
|
152
|
+
private async handleMount(mountedElement: Element, emcConfig: EMC, synthesizerElement?: Element): Promise<void> {
|
|
126
153
|
const enhKey = emcConfig.enhConfig.enhKey;
|
|
127
154
|
|
|
128
155
|
// Step 1: Check if element already has this enhancement
|
|
@@ -153,7 +180,9 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
153
180
|
throw new Error('Element does not have enh property. Make sure ElementMountExtension is loaded.');
|
|
154
181
|
}
|
|
155
182
|
|
|
156
|
-
|
|
183
|
+
// Pass synthesizerElement through SpawnContext if available
|
|
184
|
+
const spawnContext = synthesizerElement ? { synthesizerElement } : undefined;
|
|
185
|
+
await enh.get(enhancementConfig, spawnContext);
|
|
157
186
|
}
|
|
158
187
|
|
|
159
188
|
/**
|
|
@@ -198,6 +227,44 @@ export class EMCScriptHandler extends EvtRt {
|
|
|
198
227
|
|
|
199
228
|
return enhancementConfig;
|
|
200
229
|
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Find the nearest ancestor synthesizer element.
|
|
233
|
+
* Traverses up through shadow root boundaries.
|
|
234
|
+
* Looks for elements with data-synthesizer attribute, be-hive tag, or __isSynthesizer property.
|
|
235
|
+
*/
|
|
236
|
+
private findContainingSynthesizer(element: Element): Element | undefined {
|
|
237
|
+
let current: Node | null = element;
|
|
238
|
+
|
|
239
|
+
while (current) {
|
|
240
|
+
if (current instanceof Element) {
|
|
241
|
+
// Check for synthesizer marker or known synthesizer tag names
|
|
242
|
+
if (current.hasAttribute('data-synthesizer') ||
|
|
243
|
+
current.localName === 'be-hive' ||
|
|
244
|
+
(current as any).__isSynthesizer === true) {
|
|
245
|
+
return current;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Try parent element
|
|
250
|
+
if (current.parentElement) {
|
|
251
|
+
current = current.parentElement;
|
|
252
|
+
}
|
|
253
|
+
// Try shadow root host
|
|
254
|
+
else if (current instanceof ShadowRoot) {
|
|
255
|
+
current = (current as ShadowRoot).host;
|
|
256
|
+
}
|
|
257
|
+
// Try parent node (for document fragments)
|
|
258
|
+
else if (current.parentNode) {
|
|
259
|
+
current = current.parentNode;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
201
268
|
}
|
|
202
269
|
|
|
203
270
|
// Register built-in handler
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"assign-gingerly": "0.0.
|
|
8
|
+
"assign-gingerly": "0.0.27",
|
|
9
9
|
"id-generation": "0.0.4"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
@@ -74,6 +74,44 @@ export type pathString = `?.${string}`;
|
|
|
74
74
|
export type CustomElementName = string;
|
|
75
75
|
export type CustomElementConstructorStaticMethodName = string;
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Context passed to parser functions
|
|
79
|
+
* Provides access to configuration and spawn context for advanced parsing scenarios
|
|
80
|
+
*/
|
|
81
|
+
export interface ParserContext<T = any> {
|
|
82
|
+
/**
|
|
83
|
+
* The attribute configuration that matched this attribute
|
|
84
|
+
* Useful for parsers that need to access additional config properties
|
|
85
|
+
*/
|
|
86
|
+
attrConfig: AttrConfig<T>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The spawn context containing enhancement config and synthesizer element
|
|
90
|
+
* Useful for parsers that need access to the enhancement or synthesizer context
|
|
91
|
+
*/
|
|
92
|
+
spawnContext?: SpawnContext<T>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The element being enhanced
|
|
96
|
+
* Useful for parsers that need to read other attributes or element properties
|
|
97
|
+
*/
|
|
98
|
+
element: Element;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The attribute name that was matched (resolved from template)
|
|
102
|
+
* Useful for parsers that handle multiple attributes
|
|
103
|
+
*/
|
|
104
|
+
attrName: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Parser function signature
|
|
109
|
+
* Can accept just the attribute value (simple form) or value + context (advanced form)
|
|
110
|
+
*/
|
|
111
|
+
export type ParserFunction<T = any> =
|
|
112
|
+
| ((attrValue: string | null) => any)
|
|
113
|
+
| ((attrValue: string | null, context?: ParserContext<T>) => any);
|
|
114
|
+
|
|
77
115
|
export interface AttrConfig<T = any> {
|
|
78
116
|
/**
|
|
79
117
|
* Type of the property value (JSON-serializable string format)
|
|
@@ -100,13 +138,19 @@ export interface AttrConfig<T = any> {
|
|
|
100
138
|
/**
|
|
101
139
|
* Parser to transform attribute string value
|
|
102
140
|
* - Function: Inline parser function (not JSON serializable)
|
|
103
|
-
*
|
|
104
|
-
*
|
|
141
|
+
* - Simple form: (attrValue: string | null) => any
|
|
142
|
+
* - Advanced form: (attrValue: string | null, context: ParserContext) => any
|
|
143
|
+
* - String: Named parser reference (JSON serializable) - looks up in scoped registry (if available) then global parser registry (e.g., 'timestamp', 'csv')
|
|
144
|
+
*
|
|
145
|
+
* Parser functions can optionally accept a second parameter (ParserContext) which provides:
|
|
146
|
+
* - attrConfig: The full AttrConfig object for this attribute
|
|
147
|
+
* - spawnContext: The SpawnContext with enhancement config and synthesizer element
|
|
148
|
+
* - element: The element being enhanced
|
|
149
|
+
* - attrName: The resolved attribute name
|
|
105
150
|
*/
|
|
106
151
|
parser?:
|
|
107
|
-
|
|
|
108
|
-
| string
|
|
109
|
-
| [CustomElementName, CustomElementConstructorStaticMethodName]
|
|
152
|
+
| ParserFunction<T>
|
|
153
|
+
| string
|
|
110
154
|
;
|
|
111
155
|
|
|
112
156
|
/**
|
|
@@ -156,6 +200,12 @@ export type AttrPatterns<T = any> = {
|
|
|
156
200
|
export interface SpawnContext<T = any, TMountContext = any> {
|
|
157
201
|
config: EnhancementConfig<T>;
|
|
158
202
|
mountCtx?: TMountContext;
|
|
203
|
+
/**
|
|
204
|
+
* Reference to the synthesizer element (be-hive, htmx-container, alpine-scope, etc.)
|
|
205
|
+
* that contains the EMC script defining this enhancement.
|
|
206
|
+
* Used for scoped parser registry access during attribute parsing.
|
|
207
|
+
*/
|
|
208
|
+
synthesizerElement?: Element;
|
|
159
209
|
}
|
|
160
210
|
|
|
161
211
|
/**
|
|
@@ -169,6 +219,7 @@ export type IEnhancementRegistryItem<T = any> = EnhancementConfig<T>;
|
|
|
169
219
|
export interface IAssignGingerlyOptions {
|
|
170
220
|
registry?: typeof EnhancementRegistry | EnhancementRegistry;
|
|
171
221
|
bypassChecks?: boolean;
|
|
222
|
+
withMethods?: string[] | Set<string>;
|
|
172
223
|
}
|
|
173
224
|
|
|
174
225
|
/**
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface EndUserProps {
|
|
2
2
|
eventName: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface AllProps extends EndUserProps {
|
|
6
|
+
enhancedElement: Element;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type AP = AllProps;
|
|
10
|
+
|
|
11
|
+
export type PAP = Partial<AP>;
|
|
12
|
+
|
|
13
|
+
export type ProPAP = Promise<PAP>;
|
|
14
|
+
|
|
15
|
+
export interface Actions {
|
|
16
|
+
hydrate(self: AP): PAP;
|
|
3
17
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface EndUserProps{
|
|
2
|
+
closeOnSelect: boolean;
|
|
3
|
+
eventName: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface AllProps extends EndUserProps {
|
|
7
|
+
enhancedElement: Element;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type AP = AllProps;
|
|
11
|
+
|
|
12
|
+
export type PAP = Partial<AP>;
|
|
13
|
+
|
|
14
|
+
export type ProPAP = Promise<PAP>;
|
|
15
|
+
|
|
16
|
+
export interface Actions{
|
|
17
|
+
init(self: AllProps, enhancedElement: Element, initVals: PAP): void;
|
|
18
|
+
hydrate(self: AP): PAP | void
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface EndUserProps{
|
|
2
|
+
triggerInsertPosition: InsertPosition;
|
|
3
|
+
cloneInsertPosition: InsertPosition;
|
|
4
|
+
buttonContent: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AllProps extends EndUserProps{
|
|
8
|
+
enhancedElement: Element;
|
|
9
|
+
byob?: boolean;
|
|
10
|
+
trigger: HTMLButtonElement;
|
|
11
|
+
resolved: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type AP = AllProps;
|
|
15
|
+
|
|
16
|
+
export type PAP = Partial<AP>;
|
|
17
|
+
|
|
18
|
+
export type ProPAP = Promise<PAP>;
|
|
19
|
+
|
|
20
|
+
export interface CustomData {
|
|
21
|
+
triggerSettings: {
|
|
22
|
+
type: string;
|
|
23
|
+
'?.classList?.add': string;
|
|
24
|
+
ariaLabel: string;
|
|
25
|
+
title: string;
|
|
26
|
+
},
|
|
27
|
+
withMethods: string[]
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Actions{
|
|
32
|
+
addCloneBtn(self: AP): ProPAP;
|
|
33
|
+
setBtnContent(self: AP): void;
|
|
34
|
+
beCloned(self: AP): void;
|
|
35
|
+
init(self: AP, enhancedElement: Element, initVals: PAP): Promise<void>
|
|
36
|
+
}
|
|
@@ -15,12 +15,8 @@ export type PAP = Partial<AP>;
|
|
|
15
15
|
|
|
16
16
|
export type ProPAP = Promise<PAP>;
|
|
17
17
|
|
|
18
|
-
export type BAP = AllProps // & BEAllProps & RoundaboutReady;
|
|
19
|
-
|
|
20
18
|
export interface Actions{
|
|
21
19
|
|
|
22
|
-
hydrate(self:
|
|
23
|
-
init(self:
|
|
24
|
-
// findTarget(self: this): Promise<void>;
|
|
25
|
-
// handleCommit(self: this, e: KeyboardEvent): Promise<void>;
|
|
20
|
+
hydrate(self: AP): ProPAP;
|
|
21
|
+
init(self: AP, enhancedElement: Element, initVals: PAP): Promise<void>
|
|
26
22
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface EndUserProps{
|
|
2
|
+
triggerInsertPosition: InsertPosition;
|
|
3
|
+
buttonContent: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface AllProps extends EndUserProps{
|
|
7
|
+
enhancedElement: Element;
|
|
8
|
+
byob?: boolean,
|
|
9
|
+
trigger: HTMLButtonElement;
|
|
10
|
+
resolved: boolean,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type AP = AllProps;
|
|
14
|
+
|
|
15
|
+
export type PAP = Partial<AP>;
|
|
16
|
+
|
|
17
|
+
export type ProPAP = Promise<PAP>;
|
|
18
|
+
|
|
19
|
+
export interface Actions{
|
|
20
|
+
|
|
21
|
+
addDeleteBtn(self: AP): ProPAP ;
|
|
22
|
+
setBtnContent(self: AP): void;
|
|
23
|
+
beDeleted(self: AP): void;
|
|
24
|
+
init(self: AP & Actions, enhancedElement: Element, initVals: PAP): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface RenderingHTMLScriptElement extends HTMLScriptElement{
|
|
2
|
+
renderer: (vm: any, html: any) => any,
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface EndUserProps{
|
|
6
|
+
vm: any,
|
|
7
|
+
with: Array<string>,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type Renderer = (vm: any, html: any) => any;
|
|
11
|
+
|
|
12
|
+
export interface AllProps extends EndUserProps{
|
|
13
|
+
enhancedElement: Element;
|
|
14
|
+
renderer: Renderer,
|
|
15
|
+
absorbingObject: any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type PAP = Partial<AllProps>;
|
|
19
|
+
|
|
20
|
+
export type AP = AllProps;
|
|
21
|
+
|
|
22
|
+
export type ProPAP = Promise<PAP>;
|
|
23
|
+
|
|
24
|
+
export interface Actions {
|
|
25
|
+
getRenderer(self: AP): PAP;
|
|
26
|
+
doRender(self: AP): void;
|
|
27
|
+
observe(self: AP): ProPAP;
|
|
28
|
+
absorb(self: AP, e?: Event): ProPAP;
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface EndUserProps {
|
|
2
|
+
triggerInsertPosition: InsertPosition;
|
|
3
|
+
labelTextContainer: string;
|
|
4
|
+
buttonContent: string;
|
|
5
|
+
nudge?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface AllProps extends EndUserProps{
|
|
9
|
+
enhancedElement: Element;
|
|
10
|
+
byob?: boolean;
|
|
11
|
+
trigger: WeakRef<HTMLButtonElement>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type AP = AllProps;
|
|
15
|
+
|
|
16
|
+
export type PAP = Partial<AP>;
|
|
17
|
+
|
|
18
|
+
export type ProPAP = Promise<PAP>;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export interface Actions{
|
|
23
|
+
addTypeBtn(self: AP): ProPAP;
|
|
24
|
+
setBtnContent(self: AP): void;
|
|
25
|
+
openDialog(self: AP): Promise<void>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ITyper{
|
|
29
|
+
showDialog(): void;
|
|
30
|
+
dispose(): void;
|
|
31
|
+
}
|
|
@@ -71,13 +71,34 @@ export interface Positraction<TProps = any, TActions = TProps> extends LogicOp<T
|
|
|
71
71
|
assignTo?: Array<null | (keyof TProps & string)>
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export interface RAConfig<TProps = unknown, TActions = TProps, ETProps = TProps> {
|
|
74
|
+
export interface RAConfig<TProps = unknown, TActions = TProps, ETProps = TProps, TCustomData = unknown> {
|
|
75
75
|
actions?: Actions<TProps,TActions>,
|
|
76
76
|
compacts?: Compacts<TProps, TActions>,
|
|
77
77
|
//onsets?: Onsets<TProps, TActions>,
|
|
78
78
|
handlers?: Handlers<ETProps, TActions>,
|
|
79
79
|
hitch?: Hitches<TProps, TActions>,
|
|
80
80
|
positractions?: Positractions<TProps>,
|
|
81
|
+
/**
|
|
82
|
+
* Configure automatic WeakRef wrapping for properties
|
|
83
|
+
*
|
|
84
|
+
* Properties listed here will automatically wrap values in WeakRef when set,
|
|
85
|
+
* and automatically deref when accessed. This prevents memory leaks for
|
|
86
|
+
* DOM elements and other objects that should be garbage collected.
|
|
87
|
+
*
|
|
88
|
+
* Options:
|
|
89
|
+
* - Array of property names: ['trigger', 'enhancedElement']
|
|
90
|
+
* - Object with configuration: { properties: ['trigger'], logIfCollected: 'warn' }
|
|
91
|
+
*
|
|
92
|
+
* When a WeakRef'd value is garbage collected, the getter returns undefined.
|
|
93
|
+
* Use logIfCollected to get notified when this happens.
|
|
94
|
+
*/
|
|
95
|
+
weakRef?: WeakRefConfig<TProps>,
|
|
96
|
+
|
|
97
|
+
defaultPropVals?: Partial<{[key in keyof TProps & string]: unknown}>,
|
|
98
|
+
|
|
99
|
+
customData?: TCustomData,
|
|
100
|
+
|
|
101
|
+
initialPropVals?: Partial<{[key in keyof TProps & string]: unknown}>,
|
|
81
102
|
}
|
|
82
103
|
|
|
83
104
|
export interface RoundaboutOptions<TProps = unknown, TActions = TProps, ETProps = TProps> extends RAConfig<TProps, TActions, ETProps> {
|
|
@@ -107,6 +128,27 @@ export interface RoundaboutOptions<TProps = unknown, TActions = TProps, ETProps
|
|
|
107
128
|
* - Diamond dependencies (A→B, A→C, B→D, C→D)
|
|
108
129
|
*/
|
|
109
130
|
internalRouting?: boolean,
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Configuration for automatic WeakRef wrapping
|
|
137
|
+
*/
|
|
138
|
+
export interface WeakRefConfig<TProps = any> {
|
|
139
|
+
/**
|
|
140
|
+
* Properties to automatically wrap in WeakRef
|
|
141
|
+
*/
|
|
142
|
+
properties: Array<keyof TProps & string>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Logging behavior when deref returns null/undefined
|
|
146
|
+
* - 'error': console.error (default)
|
|
147
|
+
* - 'warn': console.warn
|
|
148
|
+
* - 'silent': no logging
|
|
149
|
+
* - function: custom logging function
|
|
150
|
+
*/
|
|
151
|
+
logIfCollected?: 'error' | 'warn' | 'silent' | ((propName: string) => void);
|
|
110
152
|
}
|
|
111
153
|
|
|
112
154
|
export interface RoundaboutReady{
|