-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe-memed.ts
75 lines (63 loc) · 2.12 KB
/
be-memed.ts
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
74
75
import {BE, propDefaults, propInfo} from 'be-enhanced/BE.js';
import {BEConfig, EnhancementInfo} from 'be-enhanced/types';
import {XE} from 'xtal-element/XE.js';
import {Actions, AllProps, AP, PAP, ProPAP, POA} from './types';
import {register} from 'be-hive/register.js';
const templSym = Symbol.for('N+uiTE7d3E+p1Zan6c9+dw==');
let map: Map<string, DocumentFragment>;
if((<any>globalThis)[templSym] === undefined){
map = new Map<string, DocumentFragment>();
(<any>globalThis)[templSym] = map;
}
const templCntSym = Symbol.for('BbIEPgqUzkKtGgCvL0CEXg==');
if((<any>globalThis)[templCntSym] === undefined) (<any>globalThis)[templCntSym] = 0;
export function getContent(id: string){
return map.get(id);
}
export class BeMemed extends BE<AP, Actions> implements Actions{
static override get beConfig(){
return {
// parse: true,
// primaryProp: 'to'
} as BEConfig;
}
override async attach(enhancedElement: Element | DocumentFragment) {
let df : DocumentFragment | undefined;
if(enhancedElement instanceof HTMLTemplateElement){
df = enhancedElement.content
}else{
df = enhancedElement as DocumentFragment;
}
const templs = df.querySelectorAll('template');
for(const templ of templs){
const cnt = (<any>globalThis)[templCntSym] as number;
(<any>globalThis)[templCntSym] = cnt + 1;
let id = 'a' + cnt.toString(16);
templ.setAttribute('be-memed-id', id);
const clone = templ.content.cloneNode(true) as DocumentFragment;
this.attach(clone);
map.set(id, clone);
templ.innerHTML = '';
}
}
}
export interface BeMemed extends AllProps{}
const tagName = 'be-memed';
const ifWantsToBe = 'memed';
const upgrade = '*';
const xe = new XE<AP, Actions>({
config:{
tagName,
isEnh: true,
propDefaults: {
...propDefaults,
},
propInfo:{
...propInfo,
},
actions:{
}
},
superclass: BeMemed
});
register(ifWantsToBe, upgrade, tagName);