-
Notifications
You must be signed in to change notification settings - Fork 0
/
be-linked.ts
175 lines (158 loc) · 5.95 KB
/
be-linked.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import {BE, propDefaults, propInfo} from 'be-enhanced/BE.js';
import {BEConfig, EnhancementInfo} from 'be-enhanced/types';
import {XE} from 'xtal-element/XE.js';
import {JSONValue} from 'trans-render/lib/types';
import {Actions, AllProps, AP, PAP, ProPAP, POA, CamelConfig, CanonicalConfig, Settings} from './types';
const cache = new Map<string, JSONValue>();
export class BeLinked extends BE<AP, Actions> implements Actions{
static override get beConfig(){
return {
parse: true,
primaryProp: 'camelConfig',
cache,
primaryPropReq: true,
parseAndCamelize: true,
camelizeOptions: {
booleans: ['Debug', 'Skip', 'Nudge']
},
} as BEConfig<CamelConfig>
}
async camelToCanonical(self: this): ProPAP {
const {camelConfig, enhancedElement, parsedFrom} = self;
if(parsedFrom !== undefined) {
const canonicalConfig = cachedCanonicals[parsedFrom];
if(canonicalConfig !== undefined){
return {
canonicalConfig
};
}
}
const {arr} = await import('be-enhanced/cpu.js');
const camelConfigArr = arr(camelConfig);
let mergedSettings: Settings | undefined;
const canonicalConfig: CanonicalConfig = {
links: [],
settings: mergedSettings,
};
const {links} = canonicalConfig;
for(const cc of camelConfigArr){
const {
Link, Negate, Clone, Refer, Assign, On, When,
links: cc_downlinks, Fire, settings, Observe,
Share, Toggle, Elevate,
} = cc;
if(Fire !== undefined){
const {camelToLisp} = await import('trans-render/lib/camelToLisp.js');
cc.fire = Fire.map(s => camelToLisp(s));
}
if(cc_downlinks !== undefined){
cc_downlinks.forEach(link => links.push(link))
}
if(Link || Negate || Clone || Refer !== undefined){
const {prsLink} = await import('./prsLink.js');
await prsLink(cc, links, self);
}
if(On !== undefined){
const {prsOn} = await import('./prsOn.js');
await prsOn(cc, links, self);
}
if(When !== undefined){
const {prsWhen} = await import('./prsWhen.js');
await prsWhen(cc, links, self);
}
if(Observe !== undefined){
const {prsObj} = await import('./prsObs.js');
await prsObj(cc, links, self);
}
if(Share !== undefined){
const {prsShare} = await import('./prsShare.js');
await prsShare(cc, links, self);
}
if(Toggle !== undefined){
const {prsToggle} = await import('./prsToggle.js');
await prsToggle(cc, links, self);
}
if(Assign !== undefined){
const {prsAssign} = await import('./prsAssign.js');
await prsAssign(cc, links);
}
if(Elevate !== undefined){
const {prsElevate} = await import('./prsElevate.js');
await prsElevate(cc, links);
}
if(settings !== undefined){
const {enh} = settings;
if(enh !== undefined){
if(mergedSettings === undefined) mergedSettings = {};
if(mergedSettings.enh === undefined) mergedSettings.enh = {};
Object.assign(mergedSettings.enh, enh);
}
}
}
canonicalConfig.settings = mergedSettings;
if(parsedFrom !== undefined){
cachedCanonicals[parsedFrom] = canonicalConfig;
}
return {
canonicalConfig
};
}
async onCanonical(self: this): ProPAP {
//console.log('start onCanonical', performance.now() );
const {canonicalConfig} = self;
const {links, settings} = canonicalConfig!;
if(links !== undefined){
const passableLinks = links.filter(link => link.observe === undefined && link.share === undefined);
if(passableLinks.length > 0){
const {pass} = await import('./pass.js');
for(const link of passableLinks){
pass(self, link); // avoid render blocking
}
}
const observableLinks = links.filter(link => link.observe !== undefined);
if(observableLinks.length > 0){
const {observe} = await import('./observe.js');
for(const observableLink of observableLinks){
await observe(self, observableLink);
}
}
const shareableLinks = links.filter(link => link.share !== undefined);
if(shareableLinks.length > 0){
const {share} = await import('./share.js');
for(const shareableLink of shareableLinks){
await share(self, shareableLink, false);
}
}
}
if(settings !== undefined){
const {doSettings} = await import('./doSettings.js');
doSettings(settings, this.enhancedElement);
}
return {
resolved: true
};
}
}
export interface BeLinked extends AllProps{}
const cachedCanonicals: {[key: string]: CanonicalConfig} = {};
export const tagName = 'be-linked';
const xe = new XE<AP, Actions>({
config: {
tagName,
isEnh: true,
propDefaults: {
//...propDefaults
},
propInfo: {
...propInfo,
propertyBag: {
parse: false,
}
},
actions: {
camelToCanonical: 'camelConfig',
onCanonical: 'canonicalConfig'
}
},
superclass: BeLinked
});