-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe-committed.js
73 lines (67 loc) · 1.9 KB
/
be-committed.js
1
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// @ts-check
import { BE } from 'be-enhanced/BE.js';
import { propInfo, resolved, rejected } from 'be-enhanced/cc.js';
/** @import {BEConfig, IEnhancement, BEAllProps} from './ts-refs/be-enhanced/types.d.ts' */
/** @import {Actions, PAP, AP, BAP, ObservingParameters} from './ts-refs/be-committed/types' */
/**
* @implements {Actions}
* @implements {EventListenerObject}
*/
class BeCommitted extends BE {
/**
* @type {BEConfig<BAP, Actions & IEnhancement, any>}
*/
static config = {
propDefaults:{
on: 'keyup'
},
propInfo:{
...propInfo,
to: {},
nudges: {},
},
compacts:{
when_on_changes_invoke_hydrate: 0,
},
positractions: [
resolved, rejected
]
}
/**
* @type {WeakRef<HTMLElement> | undefined}
*/
#clickableElementRef;
/**
*
* @param {BAP} self
*/
async hydrate(self){
const {enhancedElement, on, to, nudges} = self;
const {parse} = await import('trans-render/dss/parse.js');
const specifier = await parse(to);
const {find} = await import('trans-render/dss/find.js');
const remoteEl = await find(enhancedElement, specifier);
if(!(remoteEl instanceof HTMLElement)) throw 404;
this.#clickableElementRef = new WeakRef(remoteEl);
enhancedElement.addEventListener(on, this);
if(nudges){
self.nudge();
}
return /** @type {PAP} */({
resolved: true
});
}
/**
*
* @param {KeyboardEvent} e
*/
handleEvent(e){
if(e.key !== 'Enter') return;
const clickableElementRef = this.#clickableElementRef?.deref();
if(clickableElementRef === undefined) throw 404;
e.preventDefault();
clickableElementRef.click();
}
}
await BeCommitted.bootUp();
export {BeCommitted}