be-hive 0.0.201 → 0.0.203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/be-hive.ts +134 -0
- package/package.json +17 -12
- package/prsObj.ts +84 -0
- package/types.d.ts +0 -0
package/be-hive.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {Synthesizer} from 'mount-observer/Synthesizer.js';
|
|
2
|
+
import { AddMountEventListener, MountInit, MOSE, MOSEAddedProps} from './ts-refs/mount-observer/types';
|
|
3
|
+
export {EMC} from './ts-refs/trans-render/be/types';
|
|
4
|
+
export {MountObserver, MOSE} from 'mount-observer/MountObserver.js';
|
|
5
|
+
import {AttrMapPoint, EMC} from './ts-refs/trans-render/be/types';
|
|
6
|
+
import { MountEvent } from 'mount-observer/MountObserver';
|
|
7
|
+
import 'be-enhanced/beEnhanced.js';
|
|
8
|
+
import { BeEnhanced, Enhancers } from 'be-enhanced/beEnhanced.js';
|
|
9
|
+
|
|
10
|
+
export const defaultObsAttrs: Partial<EMC> = {
|
|
11
|
+
hasRootIn: [
|
|
12
|
+
{
|
|
13
|
+
start: '',
|
|
14
|
+
context: 'BuiltIn'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
start: 'enh',
|
|
18
|
+
context: 'Both'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
start: 'data-enh',
|
|
22
|
+
context: 'Both'
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
],
|
|
28
|
+
base: '',
|
|
29
|
+
preBaseDelimiter: '-',
|
|
30
|
+
preBranchDelimiter: '-',
|
|
31
|
+
preLeafDelimiter: '--',
|
|
32
|
+
enhancedElementMatches: '*',
|
|
33
|
+
enhancedElementInstanceOf: [Element]
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function seed(emc: EMC){
|
|
37
|
+
try{
|
|
38
|
+
Enhancers.define(emc);
|
|
39
|
+
}catch(e){}
|
|
40
|
+
|
|
41
|
+
const mose = document.createElement('script') as MOSE<EMC>;
|
|
42
|
+
const id = `be-hive.${emc.base}`;
|
|
43
|
+
mose.id = emc.id = id;
|
|
44
|
+
mose.synConfig = emc;
|
|
45
|
+
return mose;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class BeHive extends Synthesizer {
|
|
49
|
+
override activate(mose: MOSE<any>) {
|
|
50
|
+
if(!this.checkIfAllowed(mose)) return;
|
|
51
|
+
const {synConfig} = mose as MOSEAddedProps<any>;
|
|
52
|
+
const mergeWithDefaults = {...defaultObsAttrs, ...synConfig} as EMC;
|
|
53
|
+
//TODO allow for programmatic adjustments in load event
|
|
54
|
+
//this.dispatchEvent(new RegistryEventImpl(mergeWithDefaults));
|
|
55
|
+
const {
|
|
56
|
+
base, block, branches, enhancedElementInstanceOf,
|
|
57
|
+
enhancedElementMatches, hostInstanceOf, hostMatches,
|
|
58
|
+
leaves, preBaseDelimiter, preBranchDelimiter, importEnh,
|
|
59
|
+
preLeafDelimiter, hasRootIn, map, osotas
|
|
60
|
+
|
|
61
|
+
} = mergeWithDefaults;
|
|
62
|
+
const mi: MountInit = {
|
|
63
|
+
on: enhancedElementMatches,
|
|
64
|
+
whereInstanceOf: enhancedElementInstanceOf,
|
|
65
|
+
whereAttr: {
|
|
66
|
+
hasRootIn,
|
|
67
|
+
hasBase: [preBaseDelimiter!, base!],
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
observedAttrsWhenMounted: osotas,
|
|
71
|
+
};
|
|
72
|
+
if(branches !== undefined){
|
|
73
|
+
mi.whereAttr!.hasBranchIn = [preBaseDelimiter!, branches];
|
|
74
|
+
}
|
|
75
|
+
if(leaves !== undefined){
|
|
76
|
+
throw 'NI';
|
|
77
|
+
}
|
|
78
|
+
mose.init = mi;
|
|
79
|
+
super.activate(mose);
|
|
80
|
+
const mo = mose.observer;
|
|
81
|
+
(mo as any as AddMountEventListener).addEventListener('mount', async e => {
|
|
82
|
+
const {mountedElement} = (e as MountEvent);
|
|
83
|
+
const {beEnhanced} : {beEnhanced: BeEnhanced} = (<any>mountedElement);
|
|
84
|
+
const enhancementConstructor = await importEnh!();
|
|
85
|
+
const {enhPropKey} = mergeWithDefaults;
|
|
86
|
+
const initialPropValues = (<any>beEnhanced)[enhPropKey!] || {};
|
|
87
|
+
if(initialPropValues instanceof enhancementConstructor) return;
|
|
88
|
+
const enhancementInstance = new enhancementConstructor();
|
|
89
|
+
(<any>beEnhanced)[enhPropKey!] = enhancementInstance;
|
|
90
|
+
const initialAttrInfo = mo.readAttrs(mountedElement);
|
|
91
|
+
if(map !== undefined){
|
|
92
|
+
for(const attr of initialAttrInfo){
|
|
93
|
+
if(attr.isSOfTAttr) continue;
|
|
94
|
+
const leafIdx = 0;
|
|
95
|
+
const {parts, newValue} = attr;
|
|
96
|
+
if(newValue === null) continue;
|
|
97
|
+
const {branchIdx} = parts!;
|
|
98
|
+
const key = `${branchIdx}.${leafIdx}`;
|
|
99
|
+
const prop = (<any>map)[key] as AttrMapPoint;
|
|
100
|
+
if(prop === undefined) continue;
|
|
101
|
+
switch(typeof prop){
|
|
102
|
+
case 'string':
|
|
103
|
+
if(initialPropValues[prop] !== undefined) continue;
|
|
104
|
+
initialPropValues[prop] = newValue;
|
|
105
|
+
break;
|
|
106
|
+
case 'object':
|
|
107
|
+
const {prsObj} = await import ('./prsObj.js');
|
|
108
|
+
await prsObj(prop, newValue, initialPropValues, attr);
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
throw 'NI';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if(osotas !== undefined){
|
|
117
|
+
for(const attr of initialAttrInfo){
|
|
118
|
+
if(!attr.isSOfTAttr) continue;
|
|
119
|
+
const {mapsTo, newValue} = attr;
|
|
120
|
+
initialPropValues[mapsTo!] = newValue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
enhancementInstance.attach(mountedElement, {
|
|
124
|
+
initialAttrInfo,
|
|
125
|
+
initialPropValues,
|
|
126
|
+
mountCnfg: mergeWithDefaults
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if(customElements.get('be-hive') === undefined){
|
|
133
|
+
customElements.define('be-hive', BeHive);
|
|
134
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "be-hive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.203",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
@@ -11,26 +11,31 @@
|
|
|
11
11
|
"main": "be-hive.js",
|
|
12
12
|
"module": "be-hive.js",
|
|
13
13
|
"exports": {
|
|
14
|
-
".":
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"./
|
|
19
|
-
|
|
14
|
+
".": {
|
|
15
|
+
"default": "./be-hive.js",
|
|
16
|
+
"types": "./be-hive.ts"
|
|
17
|
+
},
|
|
18
|
+
"./be-hive.js": {
|
|
19
|
+
"default": "./be-hive.js",
|
|
20
|
+
"types": "./be-hive.ts"
|
|
21
|
+
},
|
|
22
|
+
"./prsObj.js": {
|
|
23
|
+
"default": "./prsObj.js",
|
|
24
|
+
"types": "./prsObj.ts"
|
|
25
|
+
}
|
|
20
26
|
},
|
|
21
27
|
"files": [
|
|
22
28
|
"*.js",
|
|
23
|
-
"
|
|
29
|
+
"*.ts"
|
|
24
30
|
],
|
|
25
|
-
"types": "types.d.ts",
|
|
26
31
|
"scripts": {
|
|
27
32
|
"serve": "node node_modules/may-it-serve/serve.js",
|
|
28
33
|
"update": "ncu -u && npm install"
|
|
29
34
|
},
|
|
30
35
|
"dependencies": {
|
|
31
|
-
"be-enhanced": "0.0.
|
|
32
|
-
"mount-observer": "0.0.
|
|
33
|
-
"trans-render": "0.0.
|
|
36
|
+
"be-enhanced": "0.0.134",
|
|
37
|
+
"mount-observer": "0.0.34",
|
|
38
|
+
"trans-render": "0.0.826"
|
|
34
39
|
},
|
|
35
40
|
"devDependencies": {
|
|
36
41
|
"may-it-serve": "0.0.8"
|
package/prsObj.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {AttrMapConfig} from './ts-refs/trans-render/be/types';
|
|
2
|
+
import { AttrChangeInfo } from './ts-refs/mount-observer/types';
|
|
3
|
+
import { IObject$tring } from './ts-refs/trans-render/types';
|
|
4
|
+
|
|
5
|
+
export async function prsObj(prop: AttrMapConfig, newValue: string, initialPropValues: any, attr: AttrChangeInfo){
|
|
6
|
+
const {instanceOf, mapsTo, valIfFalsy} = prop;
|
|
7
|
+
let valToSet = newValue;
|
|
8
|
+
if(valIfFalsy !== undefined && !newValue && mapsTo){
|
|
9
|
+
if(mapsTo === '.'){
|
|
10
|
+
if(typeof valIfFalsy === 'object'){
|
|
11
|
+
Object.assign(initialPropValues, valIfFalsy);
|
|
12
|
+
}else {
|
|
13
|
+
throw 'NI';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}else{
|
|
17
|
+
initialPropValues[mapsTo] = valIfFalsy;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}else{
|
|
21
|
+
switch(instanceOf){
|
|
22
|
+
case 'Object':
|
|
23
|
+
try{
|
|
24
|
+
valToSet = JSON.parse(newValue);
|
|
25
|
+
}catch(e){
|
|
26
|
+
throw {err: 400, attr, newValue};
|
|
27
|
+
}
|
|
28
|
+
if(mapsTo === undefined) throw 400;
|
|
29
|
+
if(mapsTo === '.'){
|
|
30
|
+
Object.assign(initialPropValues, valToSet);
|
|
31
|
+
}else{
|
|
32
|
+
initialPropValues[mapsTo] = valToSet;
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
case 'String':
|
|
36
|
+
initialPropValues[mapsTo!] = valToSet;
|
|
37
|
+
break;
|
|
38
|
+
case 'Boolean':
|
|
39
|
+
initialPropValues[mapsTo!] = valToSet !== null;
|
|
40
|
+
break;
|
|
41
|
+
case 'Number':
|
|
42
|
+
initialPropValues[mapsTo!] = Number(valToSet);
|
|
43
|
+
break;
|
|
44
|
+
case 'DSSArray':
|
|
45
|
+
case 'Object$tring':
|
|
46
|
+
case 'Object$entences':
|
|
47
|
+
const {strValMapsTo, objValMapsTo, arrValMapsTo} = prop;
|
|
48
|
+
let parsedObj : IObject$tring | undefined;
|
|
49
|
+
switch(instanceOf){
|
|
50
|
+
case 'Object$tring':
|
|
51
|
+
const {Object$tring} = await import('trans-render/Object$tring.js');
|
|
52
|
+
parsedObj = new Object$tring(newValue);
|
|
53
|
+
break;
|
|
54
|
+
case 'Object$entences':
|
|
55
|
+
const {Object$entences} = await import('trans-render/Object$entences.js');
|
|
56
|
+
parsedObj = new Object$entences(newValue, prop);
|
|
57
|
+
break;
|
|
58
|
+
case 'DSSArray':
|
|
59
|
+
const {DSSArray} = await import('trans-render/DSSArray.js');
|
|
60
|
+
parsedObj = new DSSArray(newValue);
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
await parsedObj.parse();
|
|
65
|
+
|
|
66
|
+
if(parsedObj.strVal && strValMapsTo !== undefined){
|
|
67
|
+
initialPropValues[strValMapsTo] = parsedObj.strVal;
|
|
68
|
+
}
|
|
69
|
+
if(parsedObj.objVal && objValMapsTo !== undefined){
|
|
70
|
+
if(objValMapsTo === '.'){
|
|
71
|
+
Object.assign(initialPropValues, parsedObj.objVal);
|
|
72
|
+
}else{
|
|
73
|
+
initialPropValues[objValMapsTo] = parsedObj.objVal;
|
|
74
|
+
}
|
|
75
|
+
}else if(parsedObj.arrVal && arrValMapsTo !== undefined){
|
|
76
|
+
initialPropValues[arrValMapsTo] = parsedObj.arrVal;
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
throw 'NI';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
package/types.d.ts
DELETED
|
File without changes
|