Skip to content

Commit

Permalink
Merge branch 'baseline' of https://github.com/bahrus/be-calculating i…
Browse files Browse the repository at this point in the history
…nto baseline
  • Loading branch information
bahrus committed Dec 15, 2024
1 parent 2dafe5e commit c9b68ca
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ The nomodule attribute is important -- it tells the browser to ignore the expres

This is an example of how those of us who want to do the right thing by our users, and use HTML and progressive enhancement, are grateful for the browser vendors or accidentally(?) leaving us some leftover scraps in their pursuit of flashy new toys. Thanks, browser vendors!!! (Sorry for "eventing").

By "CSP Safe," I mean that the browser will provide a warning when it doesn't find a matching csp hash value, so that with enough patience, or with a good build engine, http headers or a meta tag such as what we see below can put the browser at ease:
By "CSP Safe," I mean that with minimal standard protections in place, the browser will provide a blocking error when it doesn't find a matching csp hash value, and provide what that hash value needs to be, so that with enough patience, or with a good build engine, http headers or a meta tag such as what we see below can put the browser at ease:

```html
<meta http-equiv="Content-Security-Policy"
Expand All @@ -209,7 +209,7 @@ By "CSP Safe," I mean that the browser will provide a warning when it doesn't fi
">
```

Each calculated expression should only result in one hash code, regardless of how many times the JS expression is repeated through the application.
Each calculated expression should only result in one hash code, regardless of how many times the JS expression is repeated throughout the application.

## CSP safe inline handler [TODO]

Expand Down
37 changes: 28 additions & 9 deletions be-calculating.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ let cnt = 0;
*/
class BeCalculating extends BE {
/**
* @type {BEConfig<BAP, Actions & IEnhancement, any>}
* @type {BEConfig<BAP, Actions & IEnhancement>}
*/
static config = {
propDefaults: {
eventArg: 'input',

notYetParsedJS: true,
},
propInfo:{
...propInfo,
Expand All @@ -44,6 +44,7 @@ class BeCalculating extends BE {
isOutputEl: {},
checkedRegistry: {},
customHandlers: {},
js: {},
},
compacts: {
when_enhElLocalName_changes_invoke_categorizeEl: 0,
Expand All @@ -64,7 +65,11 @@ class BeCalculating extends BE {
ifAllOf: ['defaultEventType', 'remSpecifierLen']
},
hydrate: {
ifAllOf: ['checkedRegistry', 'propToAO']
ifAllOf: ['checkedRegistry', 'propToAO'],
ifNotAllOf: ['js', 'notYetParsedJS']
},
parseJS: {
ifAllOf: ['js', 'notYetParsedJS'],
}
}
}
Expand Down Expand Up @@ -101,6 +106,20 @@ class BeCalculating extends BE {
forArgs: Array.from(/** @type {HTMLOutputElement} */(enhancedElement).htmlFor)
}
}
/**
*
* @param {BAP} self
* @returns
*/
async parseJS(self){
const {enhKey, enhancedElement, js} = self;
const handler = (await import('trans-render/lib/activate.js')).activate(js);
if(this.#ac === undefined) this.#ac = new AbortController();
enhancedElement.addEventListener(enhKey, handler, {signal: this.#ac.signal});
return /** @type {PAP} */({
notYetParsedJS: false,
});
}

/**
*
Expand Down Expand Up @@ -217,7 +236,7 @@ class BeCalculating extends BE {
#so;
async handleEvent() {
const self = /** @type {BAP} */(/** @type {any} */ (this));
const {enhancedElement, propToAO, handlerObj, isOutputEl} = self;
const {enhancedElement, propToAO, handlerObj, isOutputEl, enhKey} = self;
//console.log({enhancedElement, propToAO, handlerObj});
const obj = {};
const args = [];
Expand All @@ -227,7 +246,7 @@ class BeCalculating extends BE {
args.push(val);
obj[prop] = val;
}
const event = new CalcEvent(args, obj, enhancedElement);
const event = new CalcEvent(enhKey, args, obj, enhancedElement);
if(handlerObj !== undefined){
if('handleEvent' in handlerObj){
/** @type {EventListenerObject} */ (handlerObj).handleEvent(event);
Expand Down Expand Up @@ -275,16 +294,16 @@ await BeCalculating.bootUp();
export {BeCalculating};

export class CalcEvent extends AggEvent {
static eventName = 'be-calculating';
//static eventName = 'be-calculating';

/**
*
* @param {string} eventName
* @param {Array<any>} args
* @param {{[key: string]: any}} f
* @param {Element} target
*/
constructor(args, f, target){
super(CalcEvent.eventName, args, f, target);
constructor(eventName, args, f, target){
super(eventName, args, f, target);
}
}

Expand Down
1 change: 1 addition & 0 deletions emc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const emc = {
base: 'be-calculating',
branches: ['', 'for', 'on', 'js'],
enhPropKey: 'beCalculating',
mapEnhKeyTo: 'enhKey',
map: {
'0.0': {
instanceOf: 'String',
Expand Down
56 changes: 9 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"be-enhanced": "0.0.160",
"be-hive": "0.0.240",
"be-hive": "0.0.241",
"mount-observer": "0.0.39",
"trans-render": "0.0.870"
},
Expand Down
2 changes: 1 addition & 1 deletion ts-refs
Submodule ts-refs updated from 3efab6 to 8d58cc

0 comments on commit c9b68ca

Please sign in to comment.