-
Notifications
You must be signed in to change notification settings - Fork 0
/
be-inclusive.ts
96 lines (86 loc) · 3.07 KB
/
be-inclusive.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {BE, propDefaults, propInfo} from 'be-enhanced/BE.js';
import {BEConfig} 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';
import {LoadEvent} from 'mount-observer/MountObserver.js';
import {Transform} from 'trans-render/Transform.js';
export class BeInclusive<TProps, TMethods, TElement = {}> extends BE<AP, Actions, HTMLTemplateElement> implements Actions{
static override get beConfig(){
return {
parse: true,
primaryProp: 'of',
primaryPropReq: true,
isParsedProp: 'isParsed',
} as BEConfig
}
async onInitModel(self: this){
const {enhancedElement, initModel} = self;
const {content} = enhancedElement;
const slots = Array.from(content.querySelectorAll('[slot]'));
for(const slot of slots){
const initValFrom = slot.getAttribute('init-val-from');
const slotName = slot.slot;
let val: any;
if(initValFrom === null){
const {getSignalVal} = await import('be-linked/getSignalVal.js');
val = getSignalVal(slot);
console.log({val});
}else{
slot.removeAttribute('init-val-from');
if(initValFrom[0] === '.'){
const {getVal} = await import('trans-render/lib/getVal.js');
val = getVal({host: slot}, initValFrom);
}else{
val = (<any>slot)[initValFrom];
}
}
(<any>initModel)[slotName] = val;
}
return {
model: Object.assign({}, initModel),
}
}
async startWeaving(self: this){
const {of, model, xform, enhancedElement, slotMap} = self;
enhancedElement.addEventListener<'load'>('load', async e => {
const le = e as LoadEvent;
const {clone} = le;
const {children} = clone;
for(const child of children){
Transform<any, any, any>(child, model, xform!);
}
console.log({le});
}, {once: true});
enhancedElement.setAttribute('slotmap', JSON.stringify(slotMap));
enhancedElement.setAttribute('href', of);
return {
resolved: true,
}
}
}
export interface BeInclusive<TProps, TMethods, TElement = {}> extends AllProps<TProps, TMethods, TElement>{}
export const tagName = 'be-inclusive';
const xe = new XE<AP, Actions>({
config:{
tagName,
propDefaults:{
...propDefaults,
},
propInfo:{
...propInfo,
},
actions:{
// onOf:{
// ifAllOf:['of', 'isC']
// },
onInitModel:{
ifAllOf: ['isParsed', 'initModel']
},
startWeaving:{
ifAllOf: ['isParsed', 'model', 'slotMap', 'of', 'xform'],
}
}
},
superclass: BeInclusive
});