-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
561 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { BE, propDefaults, propInfo } from 'be-enhanced/BE.js'; | ||
import { XE } from 'xtal-element/XE.js'; | ||
import { register } from 'be-hive/register.js'; | ||
export class BeDerived extends BE { | ||
static get beConfig() { | ||
return { | ||
parse: true, | ||
primaryProp: 'camelConfig', | ||
primaryPropReq: true, | ||
parseAndCamelize: true, | ||
camelizeOptions: { | ||
doSets: true, | ||
simpleSets: ['Affect', 'Survey', 'Target'] | ||
} | ||
}; | ||
} | ||
async camelToCanonical(self) { | ||
const { camelConfig, enhancedElement } = self; | ||
let { affect, target, survey, Derive, itemize } = camelConfig; | ||
affect = affect || 'previousElementSibling'; | ||
survey = survey || affect; | ||
const canonicalConfig = { | ||
affect, | ||
itemize: !!itemize, | ||
survey, | ||
target, | ||
}; | ||
if (Derive !== undefined) { | ||
const { toCanonical } = await import('./derive.js'); | ||
canonicalConfig.deriveRules = await toCanonical(Derive); //await derive(Derive, realmToSurvey, derivedVals); | ||
} | ||
if (enhancedElement instanceof HTMLTemplateElement) { | ||
const { toCanonical } = await import('./xslt.js'); | ||
canonicalConfig.xsltProcessor = toCanonical(enhancedElement); | ||
} | ||
return { canonicalConfig }; | ||
} | ||
async onCanonical(self) { | ||
const { enhancedElement, canonicalConfig } = self; | ||
const { survey, affect, itemize, target, deriveRules, xsltProcessor } = canonicalConfig; | ||
const { findRealm } = await import('trans-render/lib/findRealm.js'); | ||
const realmToSurvey = await findRealm(enhancedElement, survey); | ||
if (!(realmToSurvey instanceof Element)) | ||
throw 'bD.404'; | ||
let affected = await findRealm(enhancedElement, affect); | ||
let split; | ||
if (target !== undefined) { | ||
const { beSplit } = await import('be-enhanced/cpu.js'); | ||
split = await beSplit(target); | ||
} | ||
const derivedVals = {}; | ||
if (itemize) { | ||
const { itemize: doItemize } = await import('./itemize.js'); | ||
doItemize(realmToSurvey, derivedVals); | ||
} | ||
if (deriveRules !== undefined) { | ||
const { derive } = await import('./derive.js'); | ||
derive(deriveRules, realmToSurvey, derivedVals); | ||
} | ||
if (enhancedElement instanceof HTMLTemplateElement) { | ||
if (xsltProcessor !== undefined) { | ||
const { xslt } = await import('./xslt.js'); | ||
xslt(xsltProcessor, realmToSurvey, derivedVals); | ||
} | ||
} | ||
else if (enhancedElement instanceof HTMLScriptElement && enhancedElement.noModule) { | ||
const { script } = await import('./script.js'); | ||
await script(enhancedElement, realmToSurvey, derivedVals); | ||
} | ||
if (split !== undefined) { | ||
const { setProp } = await import('trans-render/lib/setProp.js'); | ||
await setProp(affected, split.path, derivedVals); | ||
} | ||
else { | ||
Object.assign(affected, derivedVals); | ||
} | ||
return { | ||
resolved: true | ||
}; | ||
} | ||
} | ||
const tagName = 'be-derived'; | ||
const ifWantsToBe = 'derived'; | ||
const upgrade = '*'; | ||
const xe = new XE({ | ||
config: { | ||
tagName, | ||
propDefaults: { | ||
...propDefaults, | ||
}, | ||
propInfo: { | ||
...propInfo | ||
}, | ||
actions: { | ||
camelToCanonical: { | ||
ifAllOf: ['camelConfig'], | ||
ifNoneOf: ['canonicalConfig'] | ||
}, | ||
onCanonical: { | ||
ifAllOf: ['canonicalConfig'] | ||
} | ||
} | ||
}, | ||
superclass: BeDerived | ||
}); | ||
register(ifWantsToBe, upgrade, tagName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import {BE, propDefaults, propInfo} from 'be-enhanced/BE.js'; | ||
import {BEConfig, BeSplitOutput} from 'be-enhanced/types'; | ||
import {XE} from 'xtal-element/XE.js'; | ||
import {Actions, AllProps, AP, PAP, ProPAP, ProPOA, POA, CamelConfig, CanonicalConfig} from './types'; | ||
import {register} from 'be-hive/register.js'; | ||
|
||
export class BeDerived extends BE<AP, Actions, HTMLTemplateElement | HTMLScriptElement> implements Actions{ | ||
static override get beConfig(){ | ||
return { | ||
parse: true, | ||
primaryProp: 'camelConfig', | ||
primaryPropReq: true, | ||
parseAndCamelize: true, | ||
camelizeOptions: { | ||
doSets: true, | ||
simpleSets: ['Affect', 'Survey', 'Target'] | ||
} | ||
} as BEConfig<CamelConfig> | ||
} | ||
|
||
async camelToCanonical(self: this): ProPAP { | ||
const {camelConfig, enhancedElement} = self; | ||
let {affect, target, survey, Derive, itemize} = camelConfig!; | ||
affect = affect || 'previousElementSibling'; | ||
survey = survey || affect; | ||
const canonicalConfig: CanonicalConfig = { | ||
affect, | ||
itemize: !!itemize, | ||
survey, | ||
target, | ||
|
||
}; | ||
|
||
|
||
if(Derive !== undefined){ | ||
const {toCanonical} = await import('./derive.js'); | ||
canonicalConfig.deriveRules = await toCanonical(Derive); //await derive(Derive, realmToSurvey, derivedVals); | ||
} | ||
|
||
if(enhancedElement instanceof HTMLTemplateElement){ | ||
const {toCanonical} = await import('./xslt.js'); | ||
canonicalConfig.xsltProcessor = toCanonical(enhancedElement); | ||
} | ||
|
||
return {canonicalConfig}; | ||
} | ||
|
||
async onCanonical(self: this): ProPAP { | ||
const {enhancedElement, canonicalConfig} = self; | ||
const {survey, affect, itemize, target, deriveRules, xsltProcessor} = canonicalConfig!; | ||
const {findRealm} = await import('trans-render/lib/findRealm.js'); | ||
const realmToSurvey = await findRealm(enhancedElement, survey); | ||
if(!(realmToSurvey instanceof Element)) throw 'bD.404'; | ||
let affected = await findRealm(enhancedElement, affect); | ||
let split: BeSplitOutput | undefined; | ||
|
||
if(target !== undefined){ | ||
const {beSplit} = await import('be-enhanced/cpu.js'); | ||
split = await beSplit(target); | ||
|
||
} | ||
const derivedVals = {} as any; | ||
if(itemize){ | ||
const {itemize: doItemize} = await import('./itemize.js'); | ||
doItemize(realmToSurvey, derivedVals); | ||
} | ||
if(deriveRules !== undefined){ | ||
const {derive} = await import('./derive.js'); | ||
derive(deriveRules, realmToSurvey, derivedVals); | ||
} | ||
if(enhancedElement instanceof HTMLTemplateElement){ | ||
if(xsltProcessor !== undefined){ | ||
const {xslt} = await import('./xslt.js'); | ||
xslt(xsltProcessor, realmToSurvey, derivedVals); | ||
} | ||
}else if(enhancedElement instanceof HTMLScriptElement && enhancedElement.noModule){ | ||
const {script} = await import('./script.js'); | ||
await script(enhancedElement, realmToSurvey, derivedVals); | ||
} | ||
if(split !== undefined){ | ||
const {setProp} = await import('trans-render/lib/setProp.js'); | ||
await setProp(affected, split.path, derivedVals); | ||
|
||
}else{ | ||
Object.assign(affected as any, derivedVals); | ||
} | ||
return { | ||
resolved: true | ||
} as PAP; | ||
} | ||
} | ||
|
||
export interface BeDerived extends AllProps{} | ||
|
||
const tagName = 'be-derived'; | ||
const ifWantsToBe = 'derived'; | ||
const upgrade = '*'; | ||
|
||
const xe = new XE<AP, Actions>({ | ||
config: { | ||
tagName, | ||
propDefaults: { | ||
...propDefaults, | ||
}, | ||
propInfo:{ | ||
...propInfo | ||
}, | ||
actions: { | ||
camelToCanonical:{ | ||
ifAllOf: ['camelConfig'], | ||
ifNoneOf: ['canonicalConfig'] | ||
}, | ||
onCanonical: { | ||
ifAllOf: ['canonicalConfig'] | ||
} | ||
} | ||
}, | ||
superclass: BeDerived | ||
}); | ||
|
||
register(ifWantsToBe, upgrade, tagName); |
Submodule be-enhanced
added at
fb39c0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div> | ||
<button>30</button> | ||
<time datetime="2018-07-07T20:00:00">20:00</time> | ||
<span itemprop="greeting">Hello</span> | ||
<ul> | ||
<li><data value="21053">Cherry Tomato</data></li> | ||
<li><data value="21054">Beef Tomato</data></li> | ||
<li><data value="21055">Snack Tomato</data></li> | ||
</ul> | ||
</div> | ||
<template be-derived=' | ||
Affect previous element sibling. //This is set by default. | ||
Target beScoped:scope. //Not set by default. | ||
Survey previous element sibling. //This is set by default. | ||
Derive count as number from button. | ||
Derive day of event as date from datetime attribute. | ||
Itemize. | ||
'> | ||
<obj-ml > | ||
<xsl:for-each select="div/ul/li"> | ||
<li-ml itemprop="product" product-id-n="{data/@value}" description="{data/text()}"></li-ml> | ||
</xsl:for-each> | ||
</obj-ml> | ||
</template> | ||
<script type=importmap> | ||
{ | ||
"imports": { | ||
"be-enhanced/": "../node_modules/be-enhanced/", | ||
"be-exportable/": "../node_modules/be-exportable/", | ||
"be-hive/": "../node_modules/be-hive/", | ||
"be-scoped/": "../node_modules/be-scoped/", | ||
"obj-ml/": "../node_modules/obj-ml/", | ||
"trans-render/": "../node_modules/trans-render/" | ||
} | ||
} | ||
</script> | ||
<script type=module> | ||
import '../be-derived.js'; | ||
import 'be-scoped/be-scoped.js'; | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.