be-hive 0.0.267 → 0.1.0
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.js +3 -169
- package/be-hive.ts +3 -188
- package/package.json +3 -29
- package/LICENSE +0 -21
- package/README.md +0 -150
- package/Registry.js +0 -11
- package/Registry.ts +0 -15
- package/aggEvt.js +0 -27
- package/aggEvt.ts +0 -35
- package/e.js +0 -33
- package/e.ts +0 -35
- package/prsObj.js +0 -85
- package/prsObj.ts +0 -86
- package/w.js +0 -59
- package/w.ts +0 -61
- package/whenResolved.js +0 -8
- package/whenResolved.ts +0 -7
package/be-hive.js
CHANGED
|
@@ -1,170 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
import 'be-enhanced/beEnhanced.js';
|
|
4
|
-
import { Enhancers } from 'be-enhanced/beEnhanced.js';
|
|
5
|
-
import { assignGingerly } from 'trans-render/lib/assignGingerly.js';
|
|
6
|
-
export const defaultObsAttrs = {
|
|
7
|
-
hasRootIn: [
|
|
8
|
-
{
|
|
9
|
-
start: '',
|
|
10
|
-
context: 'BuiltIn'
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
start: 'enh',
|
|
14
|
-
context: 'Both'
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
start: 'data-enh',
|
|
18
|
-
context: 'Both'
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
base: '',
|
|
22
|
-
preBaseDelimiter: '-',
|
|
23
|
-
preBranchDelimiter: '-',
|
|
24
|
-
preLeafDelimiter: '--',
|
|
25
|
-
enhancedElementMatches: '*',
|
|
26
|
-
enhancedElementInstanceOf: [Element]
|
|
27
|
-
};
|
|
28
|
-
export const registeredHandlers = new Map();
|
|
29
|
-
//export const scopedHandlers = new Map<EMC, ScopedCustomHandlerCluster>();
|
|
30
|
-
export function seed(emc) {
|
|
31
|
-
if (emc.handlerKey === undefined)
|
|
32
|
-
emc.handlerKey = emc.enhPropKey;
|
|
33
|
-
emc.top = emc;
|
|
34
|
-
const { handlerKey } = emc;
|
|
35
|
-
if (!registeredHandlers.has(emc)) {
|
|
36
|
-
registeredHandlers.set(emc, new Map());
|
|
37
|
-
}
|
|
38
|
-
const cluster = registeredHandlers.get(emc);
|
|
39
|
-
if (!cluster?.has(handlerKey)) {
|
|
40
|
-
cluster.set(handlerKey, new Map());
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
Enhancers.define(emc);
|
|
44
|
-
}
|
|
45
|
-
catch (e) { }
|
|
46
|
-
const mose = document.createElement('script');
|
|
47
|
-
const id = `be-hive.${emc.base}`;
|
|
48
|
-
mose.id = emc.id = id;
|
|
49
|
-
mose.synConfig = emc;
|
|
50
|
-
return mose;
|
|
51
|
-
}
|
|
52
|
-
export class BeHive extends Synthesizer {
|
|
53
|
-
activate(mose) {
|
|
54
|
-
if (!this.checkIfAllowed(mose))
|
|
55
|
-
return;
|
|
56
|
-
const { synConfig } = mose;
|
|
57
|
-
const mergeWithDefaults = { ...defaultObsAttrs, ...synConfig };
|
|
58
|
-
//TODO allow for programmatic adjustments in load event
|
|
59
|
-
//this.dispatchEvent(new RegistryEventImpl(mergeWithDefaults));
|
|
60
|
-
const { base, block, branches, enhancedElementInstanceOf, enhancedElementMatches, hostInstanceOf, hostMatches, leaves, preBaseDelimiter, preBranchDelimiter, importEnh, preLeafDelimiter, hasRootIn, map, osotas, mapLocalNameTo, ws, mapEnhKeyTo, mapEmcTo } = mergeWithDefaults;
|
|
61
|
-
const mi = {
|
|
62
|
-
on: enhancedElementMatches,
|
|
63
|
-
whereInstanceOf: enhancedElementInstanceOf,
|
|
64
|
-
whereAttr: {
|
|
65
|
-
hasRootIn,
|
|
66
|
-
hasBase: [preBaseDelimiter, base],
|
|
67
|
-
},
|
|
68
|
-
observedAttrsWhenMounted: osotas,
|
|
69
|
-
assigner: assignGingerly,
|
|
70
|
-
};
|
|
71
|
-
if (branches !== undefined) {
|
|
72
|
-
mi.whereAttr.hasBranchIn = [preBaseDelimiter, branches];
|
|
73
|
-
}
|
|
74
|
-
if (leaves !== undefined) {
|
|
75
|
-
throw 'NI';
|
|
76
|
-
}
|
|
77
|
-
mose.init = mi;
|
|
78
|
-
super.activate(mose);
|
|
79
|
-
const mo = mose.observer;
|
|
80
|
-
mo.addEventListener('mount', async (e) => {
|
|
81
|
-
//TODO: doing this logic asynchronously after pulling in the existing prop
|
|
82
|
-
//could result in loss of information
|
|
83
|
-
const observedAttrs = await mo.observedAttrs();
|
|
84
|
-
const { mountedElement } = e;
|
|
85
|
-
const { beEnhanced } = mountedElement;
|
|
86
|
-
const enhancementConstructor = await importEnh();
|
|
87
|
-
if (enhancementConstructor === undefined)
|
|
88
|
-
throw 404;
|
|
89
|
-
const { enhPropKey, base } = mergeWithDefaults;
|
|
90
|
-
if (base !== undefined) {
|
|
91
|
-
//TODO: check for data- and enh- and data-enh-
|
|
92
|
-
const deferBase = `defer-${base}`;
|
|
93
|
-
if (mountedElement.hasAttribute(deferBase)) {
|
|
94
|
-
const { wfac } = await import('trans-render/lib/wfac.js');
|
|
95
|
-
await wfac(mountedElement, deferBase, (mr, el, attrs) => {
|
|
96
|
-
return !el.hasAttribute(deferBase);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const initialPropValues = beEnhanced[enhPropKey] || {};
|
|
101
|
-
if (initialPropValues instanceof enhancementConstructor)
|
|
102
|
-
return;
|
|
103
|
-
const enhancementInstance = new enhancementConstructor();
|
|
104
|
-
beEnhanced[enhPropKey] = enhancementInstance;
|
|
105
|
-
const initialAttrInfo = mo.readAttrs(mountedElement);
|
|
106
|
-
if (map !== undefined) {
|
|
107
|
-
for (const attr of initialAttrInfo) {
|
|
108
|
-
if (attr.isSOfTAttr)
|
|
109
|
-
continue;
|
|
110
|
-
const leafIdx = 0;
|
|
111
|
-
const { parts, newValue } = attr;
|
|
112
|
-
if (newValue === null)
|
|
113
|
-
continue;
|
|
114
|
-
const { branchIdx } = parts;
|
|
115
|
-
const key = `${branchIdx}.${leafIdx}`;
|
|
116
|
-
const prop = map[key];
|
|
117
|
-
if (prop === undefined)
|
|
118
|
-
continue;
|
|
119
|
-
switch (typeof prop) {
|
|
120
|
-
case 'string':
|
|
121
|
-
if (initialPropValues[prop] !== undefined)
|
|
122
|
-
continue;
|
|
123
|
-
initialPropValues[prop] = newValue;
|
|
124
|
-
break;
|
|
125
|
-
case 'object':
|
|
126
|
-
const { prsObj } = await import('./prsObj.js');
|
|
127
|
-
await prsObj(prop, newValue, initialPropValues, attr);
|
|
128
|
-
break;
|
|
129
|
-
default:
|
|
130
|
-
throw 'NI';
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (osotas !== undefined) {
|
|
135
|
-
for (const attr of initialAttrInfo) {
|
|
136
|
-
if (!attr.isSOfTAttr)
|
|
137
|
-
continue;
|
|
138
|
-
const { mapsTo, newValue } = attr;
|
|
139
|
-
initialPropValues[mapsTo] = newValue;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (mapLocalNameTo !== undefined) {
|
|
143
|
-
initialPropValues[mapLocalNameTo] = mountedElement.localName;
|
|
144
|
-
}
|
|
145
|
-
if (mapEnhKeyTo !== undefined) {
|
|
146
|
-
initialPropValues[mapEnhKeyTo] = enhPropKey;
|
|
147
|
-
}
|
|
148
|
-
if (mapEmcTo !== undefined) {
|
|
149
|
-
initialPropValues[mapEmcTo] = mergeWithDefaults;
|
|
150
|
-
}
|
|
151
|
-
initialPropValues.customHandlers = registeredHandlers.get(synConfig.top)?.get(enhPropKey);
|
|
152
|
-
let filteredWs;
|
|
153
|
-
if (ws !== undefined) {
|
|
154
|
-
(await import('./e.js')).e(mergeWithDefaults, mountedElement, ws, initialPropValues);
|
|
155
|
-
}
|
|
156
|
-
//initialPropValues.scopedCustomHandlers = scopedHandlers.get(synConfig.top)?.get(enhPropKey);
|
|
157
|
-
await enhancementInstance.attach(mountedElement, {
|
|
158
|
-
initialAttrInfo,
|
|
159
|
-
initialPropValues,
|
|
160
|
-
mountCnfg: mergeWithDefaults,
|
|
161
|
-
synConfig,
|
|
162
|
-
observedAttrs,
|
|
163
|
-
ws: filteredWs
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (customElements.get('be-hive') === undefined) {
|
|
169
|
-
customElements.define('be-hive', BeHive);
|
|
1
|
+
import { MOSE } from 'mount-observer-script-element/MOSE.js';
|
|
2
|
+
export class BeHive extends MOSE(HTMLElement) {
|
|
170
3
|
}
|
|
4
|
+
customElements.define('be-hive', BeHive);
|
package/be-hive.ts
CHANGED
|
@@ -1,192 +1,7 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
6
|
-
AttrMapPoint, CustomHandlerCluster, EMC, EventListenerOrFn,
|
|
7
|
-
HandlerKey,
|
|
8
|
-
IW,
|
|
9
|
-
} from './ts-refs/trans-render/be/types';
|
|
10
|
-
import { MountEvent } from 'mount-observer/MountObserver';
|
|
11
|
-
import 'be-enhanced/beEnhanced.js';
|
|
12
|
-
import { BeEnhanced, Enhancers } from 'be-enhanced/beEnhanced.js';
|
|
13
|
-
import {assignGingerly} from 'trans-render/lib/assignGingerly.js';
|
|
1
|
+
import {MOSE} from 'mount-observer-script-element/MOSE.js';
|
|
14
2
|
|
|
15
|
-
export
|
|
16
|
-
hasRootIn: [
|
|
17
|
-
{
|
|
18
|
-
start: '',
|
|
19
|
-
context: 'BuiltIn'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
start: 'enh',
|
|
23
|
-
context: 'Both'
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
start: 'data-enh',
|
|
27
|
-
context: 'Both'
|
|
28
|
-
},
|
|
3
|
+
export class BeHive extends MOSE(HTMLElement){
|
|
29
4
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
],
|
|
33
|
-
base: '',
|
|
34
|
-
preBaseDelimiter: '-',
|
|
35
|
-
preBranchDelimiter: '-',
|
|
36
|
-
preLeafDelimiter: '--',
|
|
37
|
-
enhancedElementMatches: '*',
|
|
38
|
-
enhancedElementInstanceOf: [Element]
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export const registeredHandlers = new Map<EMC, CustomHandlerCluster>();
|
|
44
|
-
|
|
45
|
-
//export const scopedHandlers = new Map<EMC, ScopedCustomHandlerCluster>();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export function seed(emc: EMC){
|
|
49
|
-
if(emc.handlerKey === undefined) emc.handlerKey = emc.enhPropKey;
|
|
50
|
-
emc.top = emc;
|
|
51
|
-
const {handlerKey} = emc;
|
|
52
|
-
if(!registeredHandlers.has(emc)) {
|
|
53
|
-
registeredHandlers.set(emc, new Map());
|
|
54
|
-
}
|
|
55
|
-
const cluster = registeredHandlers.get(emc);
|
|
56
|
-
if(!cluster?.has(handlerKey)){
|
|
57
|
-
cluster!.set(handlerKey, new Map());
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
try{
|
|
62
|
-
Enhancers.define(emc);
|
|
63
|
-
}catch(e){}
|
|
64
|
-
|
|
65
|
-
const mose = document.createElement('script') as MOSE<EMC>;
|
|
66
|
-
const id = `be-hive.${emc.base}`;
|
|
67
|
-
mose.id = emc.id = id;
|
|
68
|
-
mose.synConfig = emc;
|
|
69
|
-
return mose;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export class BeHive extends Synthesizer {
|
|
73
|
-
override activate(mose: MOSE<any>) {
|
|
74
|
-
if(!this.checkIfAllowed(mose)) return;
|
|
75
|
-
const {synConfig} = mose as MOSEAddedProps<any>;
|
|
76
|
-
const mergeWithDefaults = {...defaultObsAttrs, ...synConfig} as EMC;
|
|
77
|
-
//TODO allow for programmatic adjustments in load event
|
|
78
|
-
//this.dispatchEvent(new RegistryEventImpl(mergeWithDefaults));
|
|
79
|
-
const {
|
|
80
|
-
base, block, branches, enhancedElementInstanceOf,
|
|
81
|
-
enhancedElementMatches, hostInstanceOf, hostMatches,
|
|
82
|
-
leaves, preBaseDelimiter, preBranchDelimiter, importEnh,
|
|
83
|
-
preLeafDelimiter, hasRootIn, map, osotas,
|
|
84
|
-
mapLocalNameTo, ws, mapEnhKeyTo, mapEmcTo
|
|
85
|
-
|
|
86
|
-
} = mergeWithDefaults;
|
|
87
|
-
const mi: MountInit = {
|
|
88
|
-
on: enhancedElementMatches,
|
|
89
|
-
whereInstanceOf: enhancedElementInstanceOf,
|
|
90
|
-
whereAttr: {
|
|
91
|
-
hasRootIn,
|
|
92
|
-
hasBase: [preBaseDelimiter!, base!],
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
observedAttrsWhenMounted: osotas,
|
|
96
|
-
assigner: assignGingerly,
|
|
97
|
-
};
|
|
98
|
-
if(branches !== undefined){
|
|
99
|
-
mi.whereAttr!.hasBranchIn = [preBaseDelimiter!, branches];
|
|
100
|
-
}
|
|
101
|
-
if(leaves !== undefined){
|
|
102
|
-
throw 'NI';
|
|
103
|
-
}
|
|
104
|
-
mose.init = mi;
|
|
105
|
-
super.activate(mose);
|
|
106
|
-
const mo = mose.observer;
|
|
107
|
-
(mo as any as AddMountEventListener).addEventListener('mount', async e => {
|
|
108
|
-
//TODO: doing this logic asynchronously after pulling in the existing prop
|
|
109
|
-
//could result in loss of information
|
|
110
|
-
const observedAttrs = await mo.observedAttrs();
|
|
111
|
-
const {mountedElement} = (e as MountEvent);
|
|
112
|
-
const {beEnhanced} : {beEnhanced: BeEnhanced} = (<any>mountedElement);
|
|
113
|
-
const enhancementConstructor = await importEnh!();
|
|
114
|
-
if(enhancementConstructor === undefined) throw 404;
|
|
115
|
-
const {enhPropKey, base} = mergeWithDefaults;
|
|
116
|
-
if(base !== undefined){
|
|
117
|
-
//TODO: check for data- and enh- and data-enh-
|
|
118
|
-
const deferBase = `defer-${base}`;
|
|
119
|
-
if(mountedElement.hasAttribute(deferBase)){
|
|
120
|
-
const {wfac} = await import('trans-render/lib/wfac.js');
|
|
121
|
-
await wfac(mountedElement, deferBase, (mr, el, attrs) => {
|
|
122
|
-
return !el.hasAttribute(deferBase);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const initialPropValues = (<any>beEnhanced)[enhPropKey!] || {};
|
|
127
|
-
if(initialPropValues instanceof enhancementConstructor) return;
|
|
128
|
-
const enhancementInstance = new enhancementConstructor();
|
|
129
|
-
(<any>beEnhanced)[enhPropKey!] = enhancementInstance;
|
|
130
|
-
const initialAttrInfo = mo.readAttrs(mountedElement);
|
|
131
|
-
if(map !== undefined){
|
|
132
|
-
for(const attr of initialAttrInfo){
|
|
133
|
-
if(attr.isSOfTAttr) continue;
|
|
134
|
-
const leafIdx = 0;
|
|
135
|
-
const {parts, newValue} = attr;
|
|
136
|
-
if(newValue === null) continue;
|
|
137
|
-
const {branchIdx} = parts!;
|
|
138
|
-
const key = `${branchIdx}.${leafIdx}`;
|
|
139
|
-
const prop = (<any>map)[key] as AttrMapPoint;
|
|
140
|
-
if(prop === undefined) continue;
|
|
141
|
-
switch(typeof prop){
|
|
142
|
-
case 'string':
|
|
143
|
-
if(initialPropValues[prop] !== undefined) continue;
|
|
144
|
-
initialPropValues[prop] = newValue;
|
|
145
|
-
break;
|
|
146
|
-
case 'object':
|
|
147
|
-
const {prsObj} = await import ('./prsObj.js');
|
|
148
|
-
await prsObj(prop, newValue, initialPropValues, attr);
|
|
149
|
-
break;
|
|
150
|
-
default:
|
|
151
|
-
throw 'NI';
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if(osotas !== undefined){
|
|
157
|
-
for(const attr of initialAttrInfo){
|
|
158
|
-
if(!attr.isSOfTAttr) continue;
|
|
159
|
-
const {mapsTo, newValue} = attr;
|
|
160
|
-
initialPropValues[mapsTo!] = newValue;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if(mapLocalNameTo !== undefined){
|
|
164
|
-
initialPropValues[mapLocalNameTo] = mountedElement.localName;
|
|
165
|
-
}
|
|
166
|
-
if(mapEnhKeyTo !== undefined){
|
|
167
|
-
initialPropValues[mapEnhKeyTo] = enhPropKey;
|
|
168
|
-
}
|
|
169
|
-
if(mapEmcTo !== undefined){
|
|
170
|
-
initialPropValues[mapEmcTo] = mergeWithDefaults;
|
|
171
|
-
}
|
|
172
|
-
initialPropValues.customHandlers = registeredHandlers.get(synConfig.top)?.get(enhPropKey);
|
|
173
|
-
let filteredWs: Array<IW> | undefined;
|
|
174
|
-
if(ws !== undefined){
|
|
175
|
-
(await import('./e.js')).e(mergeWithDefaults, mountedElement, ws, initialPropValues);
|
|
176
|
-
}
|
|
177
|
-
//initialPropValues.scopedCustomHandlers = scopedHandlers.get(synConfig.top)?.get(enhPropKey);
|
|
178
|
-
await enhancementInstance.attach(mountedElement, {
|
|
179
|
-
initialAttrInfo,
|
|
180
|
-
initialPropValues,
|
|
181
|
-
mountCnfg: mergeWithDefaults,
|
|
182
|
-
synConfig,
|
|
183
|
-
observedAttrs,
|
|
184
|
-
ws: filteredWs
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
5
|
}
|
|
189
6
|
|
|
190
|
-
|
|
191
|
-
customElements.define('be-hive', BeHive);
|
|
192
|
-
}
|
|
7
|
+
customElements.define('be-hive', BeHive);
|
package/package.json
CHANGED
|
@@ -1,43 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "be-hive",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
7
7
|
"custom-element",
|
|
8
8
|
"custom-elements"
|
|
9
9
|
],
|
|
10
|
-
"description": "Specify that ShadowDOM should inherit be-hiviors from the
|
|
10
|
+
"description": "Specify that ShadowDOM should inherit be-hiviors from the Custom Element Registry Scope",
|
|
11
11
|
"main": "be-hive.js",
|
|
12
12
|
"module": "be-hive.js",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"default": "./be-hive.js",
|
|
16
16
|
"types": "./be-hive.ts"
|
|
17
|
-
},
|
|
18
|
-
"./aggEvt.js": {
|
|
19
|
-
"default": "./aggEvt.js",
|
|
20
|
-
"types": "./aggEvt.ts"
|
|
21
|
-
},
|
|
22
|
-
"./be-hive.js": {
|
|
23
|
-
"default": "./be-hive.js",
|
|
24
|
-
"types": "./be-hive.ts"
|
|
25
|
-
},
|
|
26
|
-
"./prsObj.js": {
|
|
27
|
-
"default": "./prsObj.js",
|
|
28
|
-
"types": "./prsObj.ts"
|
|
29
|
-
},
|
|
30
|
-
"./Registry.js": {
|
|
31
|
-
"default": "./Registry.js",
|
|
32
|
-
"types": "./Registry.ts"
|
|
33
|
-
},
|
|
34
|
-
"./w.js": {
|
|
35
|
-
"default": "./w.js",
|
|
36
|
-
"types": "./w.ts"
|
|
37
|
-
},
|
|
38
|
-
"./whenResolved.js": {
|
|
39
|
-
"default": "./whenResolved.js",
|
|
40
|
-
"types": "./whenResolved.ts"
|
|
41
17
|
}
|
|
42
18
|
},
|
|
43
19
|
"files": [
|
|
@@ -48,9 +24,7 @@
|
|
|
48
24
|
"update": "ncu -u && npm install"
|
|
49
25
|
},
|
|
50
26
|
"dependencies": {
|
|
51
|
-
"
|
|
52
|
-
"mount-observer": "0.0.105",
|
|
53
|
-
"trans-render": "0.0.960"
|
|
27
|
+
"mount-observer-script-element": "0.0.2"
|
|
54
28
|
},
|
|
55
29
|
"repository": {
|
|
56
30
|
"type": "git",
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Bruce B. Anderson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# be-hive [WIP]
|
|
2
|
-
|
|
3
|
-
[](https://www.webcomponents.org/element/bahrus/be-hive)
|
|
4
|
-
[](https://bundlephobia.com/result?p=be-hive)
|
|
5
|
-
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/npm/be-hive?compression=gzip">
|
|
6
|
-
[](http://badge.fury.io/js/be-hive)
|
|
7
|
-
|
|
8
|
-
## Inheriting behiviors
|
|
9
|
-
|
|
10
|
-
[be-hive](https://www.youtube.com/watch?v=SQoOwosJWns) lets it [snow in August](https://www.youtube.com/watch?v=m3dmnOtqrV0).
|
|
11
|
-
|
|
12
|
-
be-hive allows us to manage and coordinate the [family, or HTML frimework](https://github.com/bahrus/may-it-be) of [be-enhanced](https://github.com/bahrus/be-enhanced) custom enhancements.
|
|
13
|
-
|
|
14
|
-
Without be-hive, the developer is burdened with plopping an instance of each enhancement inside each shadow DOM realm.
|
|
15
|
-
|
|
16
|
-
With the help of the be-hive component, the developer only has to plop a single instance of be-hive inside the Shadow DOM realm, like so:
|
|
17
|
-
|
|
18
|
-
```html
|
|
19
|
-
<be-hive></be-hive>
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
This signals that the Shadow DOM realm is opting-in, and allowing element behiviors, and will inherit all the behiviors from the parent Shadow DOM realm, by default.
|
|
23
|
-
|
|
24
|
-
But the child Shadow DOM realm can develop a personality of its own by:
|
|
25
|
-
|
|
26
|
-
1. Adding additional behiviors by adding specific be-enhanced based enhancement instructions inside the be-hive instance tag.
|
|
27
|
-
2. Avoiding naming conflicts by overriding the attribute associated with the inherited behivior.
|
|
28
|
-
3. Preventing inheriting unwanted behiviors from affecting the child Shadow DOM realm.
|
|
29
|
-
4. Start over. Only decorator elements manually added inside the Shadow DOM (preferably inside the be-hive tag, for inheritance to work within)
|
|
30
|
-
|
|
31
|
-
## Syntax for customizations of inherited behiviors [WIP]
|
|
32
|
-
|
|
33
|
-
```html
|
|
34
|
-
<be-hive passthrough></be-hive>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
allows behiviors to flow though the ShadowDOM realm to child ShadowDOM realms, but skips over the one in question.
|
|
38
|
-
|
|
39
|
-
```html
|
|
40
|
-
<be-hive include=... exclude=...>
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
allows for blocking or specifying which behiviors to enable within the ShadowDOM realm, while allowing them to flow through to the child ShadowDOM realms, unaffected.
|
|
44
|
-
|
|
45
|
-
```html
|
|
46
|
-
<be-hive overrides='{
|
|
47
|
-
"be-sharing":{
|
|
48
|
-
"becomes": "be-familial"
|
|
49
|
-
},
|
|
50
|
-
"be-gracious": {
|
|
51
|
-
"becomes": "be-respectful"
|
|
52
|
-
},
|
|
53
|
-
"be-disobedient-without-facing-the-consequences": {
|
|
54
|
-
"block": "true"
|
|
55
|
-
}
|
|
56
|
-
}'></be-hive>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
## Be like Sirius Black
|
|
62
|
-
|
|
63
|
-
If the inherited behiviors are all just too odious to inherit, there's an option to start again:
|
|
64
|
-
|
|
65
|
-
```html
|
|
66
|
-
<be-hive be-severed>
|
|
67
|
-
</be-hive>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Adding back a personality trait [TODO]
|
|
71
|
-
|
|
72
|
-
If one Shadow DOM blocks an inherited behivior, child Shadow DOMs can bring it back within their (and descendent) shadow DOM realms thusly:
|
|
73
|
-
|
|
74
|
-
```html
|
|
75
|
-
<be-hive overrides='{
|
|
76
|
-
"be-disobedient-without-facing-the-consequences": {
|
|
77
|
-
"unblock": "true"
|
|
78
|
-
}
|
|
79
|
-
}'></be-hive>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
## The "Emcee" script files
|
|
84
|
-
|
|
85
|
-
To make the ceremony of establishing DOM enhancements go as smoothly as possible, *be-hive* rests on a key object structure that should accompany each enhancement -- the "EMC" object.
|
|
86
|
-
|
|
87
|
-
EMC stands for "Enhancement Mount Configuration".
|
|
88
|
-
|
|
89
|
-
These objects are small, and most of it can be turned into a JSON import:
|
|
90
|
-
|
|
91
|
-
For example:
|
|
92
|
-
|
|
93
|
-
```TypeScript
|
|
94
|
-
export const emc: EMC = {
|
|
95
|
-
base: 'be-based',
|
|
96
|
-
map: {
|
|
97
|
-
'0.0': 'base'
|
|
98
|
-
},
|
|
99
|
-
enhPropKey: 'beBased',
|
|
100
|
-
importEnh: async () => {
|
|
101
|
-
const {BeBased} = await import('./behance.js');
|
|
102
|
-
return BeBased;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
This provides a kind of "entrance ticket" that can then be used to enhance an element programmatically:
|
|
108
|
-
|
|
109
|
-
```TypeScript
|
|
110
|
-
const beBasedEnhancement = await oDivElement.beEnhanced.whenResolved(emc);
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
It also contains all the needed information for how to parse the the behavior/enhancement attributes, into an object that can be passed in to the behavior/enhancement during template instantiation.
|
|
114
|
-
|
|
115
|
-
To see a more complex example along those lines, see [be-switched](https://github.com/bahrus/be-switched/blob/baseline/behivior.ts).
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Potentially, an alternative EMC definition can be used inside different Shadow DOM roots in order to avoid clashes between two libraries that use the same names.
|
|
120
|
-
|
|
121
|
-
So we can synchronously load these small files (or a bundle of such small files), which would block being able to do template instantiation on a first load. but at least the files are as small (and as parsable) as possible.
|
|
122
|
-
|
|
123
|
-
The thinking is we can take a template filled with lots of inline behavior/enhancement attributes, where that template is going to be cloned repeatedly. In order to avoid excessive string parsing, we can analyze the template:
|
|
124
|
-
|
|
125
|
-
If the EMC's "cache" setting is set to true, then it will look at the initial attribute settings, and see if it matches something that is already in the cache, and if so, do a (structural clone?) of the object without re-parsing. Maybe this should only be done if the root fragment isn't connected?
|
|
126
|
-
|
|
127
|
-
## Behivior aspects [WIP]
|
|
128
|
-
|
|
129
|
-
There may be some cases, especially for enhancements with many equally important parameters where a developer may prefer to break up the settings into separate attributes. [Here's an example](https://github.com/bahrus/be-intl) where I can definitely see the appeal. So instead of:
|
|
130
|
-
|
|
131
|
-
```html
|
|
132
|
-
<time lang="ar-EG" datetime=2011-11-18T14:54:39.929Z be-intl='{ "weekday": "long", "year": "numeric", "month": "long", "day": "numeric" }'></time>
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
we can write:
|
|
136
|
-
|
|
137
|
-
```html
|
|
138
|
-
<time lang="ar-EG"
|
|
139
|
-
datetime=2011-11-18T14:54:39.929Z
|
|
140
|
-
be-intl-weekday=long be-intl-year=numeric be-intl-month=long
|
|
141
|
-
be-intl-day=numeric>
|
|
142
|
-
</time>
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
This is especially useful in environments where the consumer of the behivior prefers to use attributes, rather than properties, for updating a property of the behivior.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
package/Registry.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { registeredHandlers } from './be-hive.js';
|
|
2
|
-
export class Registry {
|
|
3
|
-
static register(emc, handlerName, handler) {
|
|
4
|
-
const cluster = registeredHandlers.get(emc);
|
|
5
|
-
const customHandlers = cluster.get(emc.handlerKey);
|
|
6
|
-
if (customHandlers.has(handlerName)) {
|
|
7
|
-
console.warn(`Overriding ${handlerName}`);
|
|
8
|
-
}
|
|
9
|
-
customHandlers.set(handlerName, handler);
|
|
10
|
-
}
|
|
11
|
-
}
|
package/Registry.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {EMC, EventListenerOrFn, OnOptions} from './ts-refs/trans-render/be/types';
|
|
2
|
-
import {registeredHandlers} from './be-hive.js';
|
|
3
|
-
import { CSSQuery } from './ts-refs/trans-render/types';
|
|
4
|
-
|
|
5
|
-
export class Registry{
|
|
6
|
-
static register(emc: EMC, handlerName: string, handler: EventListenerOrFn){
|
|
7
|
-
const cluster = registeredHandlers.get(emc)!;
|
|
8
|
-
const customHandlers = cluster.get(emc.handlerKey!)!;
|
|
9
|
-
if(customHandlers.has(handlerName)){
|
|
10
|
-
console.warn(`Overriding ${handlerName}`);
|
|
11
|
-
}
|
|
12
|
-
customHandlers.set(handlerName, handler);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|
package/aggEvt.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const rguid = 'XM5dz7tqZkeFCtytNXHPzw';
|
|
2
|
-
export class AggEvent extends Event {
|
|
3
|
-
r = rguid;
|
|
4
|
-
args;
|
|
5
|
-
f;
|
|
6
|
-
target;
|
|
7
|
-
constructor(type, args, f, target) {
|
|
8
|
-
super(type);
|
|
9
|
-
this.args = args;
|
|
10
|
-
this.f = f;
|
|
11
|
-
this.target = target;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export const aggs = {
|
|
15
|
-
'+': (e) => e.r = e.args.reduce((acc, arg) => acc + arg),
|
|
16
|
-
'*': (e) => e.r = e.args.reduce((acc, arg) => acc * arg),
|
|
17
|
-
max: (e) => e.r = Math.max(...e.args),
|
|
18
|
-
min: (e) => e.r = Math.min(...e.args),
|
|
19
|
-
nearlyEq: (e) => e.r = Math.max(...e.args) - Math.min(...e.args) < Number(e.target.dataset.maxDiff),
|
|
20
|
-
//eq: (e: AggEvent) => e.r = Math.max(...(e.args as Array<number>)) === Math.min(...(e.args as Array<number>)),
|
|
21
|
-
eq: (e) => e.r = e.args?.length === 0 ? true : e.args.find(x => e.args[0] !== x) === undefined,
|
|
22
|
-
'||': (e) => e.r = e.args.reduce((acc, arg) => acc || arg),
|
|
23
|
-
'||!': (e) => e.r = e.args.reduce((acc, arg) => acc || !arg),
|
|
24
|
-
'&&': (e) => e.r = e.args.reduce((acc, arg) => acc && arg),
|
|
25
|
-
'&&!': (e) => e.r = e.args.reduce((acc, arg) => acc && !arg),
|
|
26
|
-
'{}': (e) => e.r = e.f,
|
|
27
|
-
};
|
package/aggEvt.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { EventListenerOrFn } from "./ts-refs/trans-render/be/types";
|
|
2
|
-
import {aggKeys} from './ts-refs/be-hive/types';
|
|
3
|
-
|
|
4
|
-
export const rguid = 'XM5dz7tqZkeFCtytNXHPzw';
|
|
5
|
-
export abstract class AggEvent extends Event {
|
|
6
|
-
r: any = rguid;
|
|
7
|
-
args: Array<any>;
|
|
8
|
-
f: {[key: string]: any};
|
|
9
|
-
target: EventTarget;
|
|
10
|
-
|
|
11
|
-
constructor(type: string, args: Array<any>, f: {[key: string]: any}, target: EventTarget){
|
|
12
|
-
super(type);
|
|
13
|
-
this.args = args;
|
|
14
|
-
this.f = f;
|
|
15
|
-
this.target = target;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const aggs: {[key: aggKeys & string]: (e: AggEvent) => void} = {
|
|
20
|
-
'+': (e: AggEvent) => e.r = e.args.reduce((acc, arg) => acc + arg),
|
|
21
|
-
'*': (e: AggEvent) => e.r = e.args.reduce((acc, arg) => acc * arg),
|
|
22
|
-
max: (e: AggEvent) => e.r = Math.max(...(e.args as Array<number>)),
|
|
23
|
-
min: (e: AggEvent) => e.r = Math.min(...(e.args as Array<number>)),
|
|
24
|
-
nearlyEq: (e: AggEvent) => e.r = Math.max(...(e.args as Array<number>)) - Math.min(...(e.args as Array<number>)) < Number((e.target as HTMLElement).dataset.maxDiff),
|
|
25
|
-
//eq: (e: AggEvent) => e.r = Math.max(...(e.args as Array<number>)) === Math.min(...(e.args as Array<number>)),
|
|
26
|
-
eq: (e: AggEvent) => e.r = e.args?.length === 0 ? true : e.args.find(x => e.args[0] !== x) === undefined,
|
|
27
|
-
'||': (e: AggEvent) => e.r = e.args.reduce((acc, arg) => acc || arg),
|
|
28
|
-
'||!': (e: AggEvent) => e.r = e.args.reduce((acc, arg) => acc || !arg),
|
|
29
|
-
'&&': (e: AggEvent) => e.r = e.args.reduce((acc, arg) => acc && arg),
|
|
30
|
-
'&&!': (e: AggEvent) => e.r = e.args.reduce((acc, arg) => acc && !arg),
|
|
31
|
-
'{}': (e: AggEvent) => e.r = e.f,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
package/e.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* syndicate custom event handlers
|
|
3
|
-
* @param emc
|
|
4
|
-
* @param matchingElement
|
|
5
|
-
* @param ws
|
|
6
|
-
* @param initialPropVals
|
|
7
|
-
* @param ac
|
|
8
|
-
*/
|
|
9
|
-
export function e(emc, matchingElement, ws, initialPropVals, ac) {
|
|
10
|
-
const matchingWs = [];
|
|
11
|
-
const { mapWSTo, primaryProp } = emc;
|
|
12
|
-
for (const w of ws) {
|
|
13
|
-
if (!matchingElement.matches(w.q))
|
|
14
|
-
continue;
|
|
15
|
-
matchingWs.push(w);
|
|
16
|
-
const { listeners, props, primaryVal } = w;
|
|
17
|
-
for (const key in listeners) {
|
|
18
|
-
let listener = listeners[key];
|
|
19
|
-
if (listener.toString().substring(0, 5) === 'class') {
|
|
20
|
-
listener = new listener();
|
|
21
|
-
}
|
|
22
|
-
matchingElement.addEventListener(key, listener, { signal: ac?.signal });
|
|
23
|
-
}
|
|
24
|
-
Object.assign(initialPropVals, props);
|
|
25
|
-
if (primaryProp !== undefined && primaryVal !== undefined) {
|
|
26
|
-
//TODO: check if object and use object.assign?
|
|
27
|
-
initialPropVals[primaryProp] = primaryVal;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (mapWSTo !== undefined) {
|
|
31
|
-
initialPropVals[mapWSTo] = matchingWs;
|
|
32
|
-
}
|
|
33
|
-
}
|
package/e.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { EMC, EventListenerClass, EventListenerOrFn, IW } from "./ts-refs/trans-render/be/types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* syndicate custom event handlers
|
|
5
|
-
* @param emc
|
|
6
|
-
* @param matchingElement
|
|
7
|
-
* @param ws
|
|
8
|
-
* @param initialPropVals
|
|
9
|
-
* @param ac
|
|
10
|
-
*/
|
|
11
|
-
export function e(emc: EMC, matchingElement: Element, ws: Array<IW>, initialPropVals: any, ac?: AbortController){
|
|
12
|
-
const matchingWs = [];
|
|
13
|
-
const {mapWSTo, primaryProp} = emc;
|
|
14
|
-
for(const w of ws){
|
|
15
|
-
if(!matchingElement.matches(w.q)) continue;
|
|
16
|
-
matchingWs.push(w);
|
|
17
|
-
const {listeners, props, primaryVal} = w;
|
|
18
|
-
for(const key in listeners){
|
|
19
|
-
let listener = listeners[key] as any;
|
|
20
|
-
if(listener.toString().substring(0, 5) === 'class'){
|
|
21
|
-
listener = new (<EventListenerClass>listener)() as any as EventListenerOrFn;
|
|
22
|
-
}
|
|
23
|
-
matchingElement.addEventListener(key, listener, {signal: ac?.signal});
|
|
24
|
-
}
|
|
25
|
-
Object.assign(initialPropVals, props);
|
|
26
|
-
if(primaryProp !== undefined && primaryVal !== undefined){
|
|
27
|
-
//TODO: check if object and use object.assign?
|
|
28
|
-
initialPropVals[primaryProp] = primaryVal;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if(mapWSTo !== undefined){
|
|
33
|
-
initialPropVals[mapWSTo] = matchingWs;
|
|
34
|
-
}
|
|
35
|
-
}
|
package/prsObj.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export async function prsObj(prop, newValue, initialPropValues, attr) {
|
|
2
|
-
const { instanceOf, mapsTo, valIfFalsy } = prop;
|
|
3
|
-
let valToSet = newValue;
|
|
4
|
-
if (valIfFalsy !== undefined && !newValue && mapsTo) {
|
|
5
|
-
if (mapsTo === '.') {
|
|
6
|
-
if (typeof valIfFalsy === 'object') {
|
|
7
|
-
Object.assign(initialPropValues, valIfFalsy);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
throw 'NI';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
initialPropValues[mapsTo] = valIfFalsy;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
switch (instanceOf) {
|
|
19
|
-
case 'Object':
|
|
20
|
-
if (!newValue)
|
|
21
|
-
return;
|
|
22
|
-
try {
|
|
23
|
-
valToSet = JSON.parse(newValue);
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
throw { err: 400, attr, newValue };
|
|
27
|
-
}
|
|
28
|
-
if (mapsTo === undefined)
|
|
29
|
-
throw 400;
|
|
30
|
-
if (mapsTo === '.') {
|
|
31
|
-
Object.assign(initialPropValues, valToSet);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
initialPropValues[mapsTo] = valToSet;
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
case 'String':
|
|
38
|
-
initialPropValues[mapsTo] = valToSet;
|
|
39
|
-
break;
|
|
40
|
-
case 'Boolean':
|
|
41
|
-
initialPropValues[mapsTo] = valToSet !== null;
|
|
42
|
-
break;
|
|
43
|
-
case 'Number':
|
|
44
|
-
initialPropValues[mapsTo] = Number(valToSet);
|
|
45
|
-
break;
|
|
46
|
-
case 'DSSArray':
|
|
47
|
-
case 'Object$tring':
|
|
48
|
-
case 'Object$entences':
|
|
49
|
-
const { strValMapsTo, objValMapsTo, arrValMapsTo } = prop;
|
|
50
|
-
let parsedObj;
|
|
51
|
-
switch (instanceOf) {
|
|
52
|
-
case 'Object$tring':
|
|
53
|
-
const { Object$tring } = await import('trans-render/Object$tring.js');
|
|
54
|
-
parsedObj = new Object$tring(newValue);
|
|
55
|
-
break;
|
|
56
|
-
case 'Object$entences':
|
|
57
|
-
const { Object$entences } = await import('trans-render/Object$entences.js');
|
|
58
|
-
parsedObj = new Object$entences(newValue, prop);
|
|
59
|
-
break;
|
|
60
|
-
case 'DSSArray':
|
|
61
|
-
const { DSSArray } = await import('trans-render/DSSArray.js');
|
|
62
|
-
parsedObj = new DSSArray(newValue);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
await parsedObj.parse();
|
|
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
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
initialPropValues[objValMapsTo] = parsedObj.objVal;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else if (parsedObj.arrVal && arrValMapsTo !== undefined) {
|
|
78
|
-
initialPropValues[arrValMapsTo] = parsedObj.arrVal;
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
throw 'NI';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
package/prsObj.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
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
|
-
if(!newValue) return;
|
|
24
|
-
try{
|
|
25
|
-
|
|
26
|
-
valToSet = JSON.parse(newValue);
|
|
27
|
-
}catch(e){
|
|
28
|
-
throw {err: 400, attr, newValue};
|
|
29
|
-
}
|
|
30
|
-
if(mapsTo === undefined) throw 400;
|
|
31
|
-
if(mapsTo === '.'){
|
|
32
|
-
Object.assign(initialPropValues, valToSet);
|
|
33
|
-
}else{
|
|
34
|
-
initialPropValues[mapsTo] = valToSet;
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
case 'String':
|
|
38
|
-
initialPropValues[mapsTo!] = valToSet;
|
|
39
|
-
break;
|
|
40
|
-
case 'Boolean':
|
|
41
|
-
initialPropValues[mapsTo!] = valToSet !== null;
|
|
42
|
-
break;
|
|
43
|
-
case 'Number':
|
|
44
|
-
initialPropValues[mapsTo!] = Number(valToSet);
|
|
45
|
-
break;
|
|
46
|
-
case 'DSSArray':
|
|
47
|
-
case 'Object$tring':
|
|
48
|
-
case 'Object$entences':
|
|
49
|
-
const {strValMapsTo, objValMapsTo, arrValMapsTo} = prop;
|
|
50
|
-
let parsedObj : IObject$tring | undefined;
|
|
51
|
-
switch(instanceOf){
|
|
52
|
-
case 'Object$tring':
|
|
53
|
-
const {Object$tring} = await import('trans-render/Object$tring.js');
|
|
54
|
-
parsedObj = new Object$tring(newValue);
|
|
55
|
-
break;
|
|
56
|
-
case 'Object$entences':
|
|
57
|
-
const {Object$entences} = await import('trans-render/Object$entences.js');
|
|
58
|
-
parsedObj = new Object$entences(newValue, prop);
|
|
59
|
-
break;
|
|
60
|
-
case 'DSSArray':
|
|
61
|
-
const {DSSArray} = await import('trans-render/DSSArray.js');
|
|
62
|
-
parsedObj = new DSSArray(newValue);
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
await parsedObj.parse();
|
|
67
|
-
|
|
68
|
-
if(parsedObj.strVal && strValMapsTo !== undefined){
|
|
69
|
-
initialPropValues[strValMapsTo] = parsedObj.strVal;
|
|
70
|
-
}
|
|
71
|
-
if(parsedObj.objVal && objValMapsTo !== undefined){
|
|
72
|
-
if(objValMapsTo === '.'){
|
|
73
|
-
Object.assign(initialPropValues, parsedObj.objVal);
|
|
74
|
-
}else{
|
|
75
|
-
initialPropValues[objValMapsTo] = parsedObj.objVal;
|
|
76
|
-
}
|
|
77
|
-
}else if(parsedObj.arrVal && arrValMapsTo !== undefined){
|
|
78
|
-
initialPropValues[arrValMapsTo] = parsedObj.arrVal;
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
throw 'NI';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}
|
package/w.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export function w(q, ws, callback) {
|
|
2
|
-
const returnObj = new W(q, callback);
|
|
3
|
-
ws.push(returnObj);
|
|
4
|
-
return returnObj;
|
|
5
|
-
}
|
|
6
|
-
export class W {
|
|
7
|
-
q;
|
|
8
|
-
w;
|
|
9
|
-
constructor(q, w) {
|
|
10
|
-
this.q = q;
|
|
11
|
-
this.w = w;
|
|
12
|
-
}
|
|
13
|
-
#listeners = {};
|
|
14
|
-
get listeners() {
|
|
15
|
-
return this.#listeners;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* add events
|
|
19
|
-
* @param eventsToAdd
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
a(eventsToAdd) {
|
|
23
|
-
this.#listeners = { ...this.#listeners, ...eventsToAdd };
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
#primaryVal;
|
|
27
|
-
get primaryVal() {
|
|
28
|
-
return this.#primaryVal;
|
|
29
|
-
}
|
|
30
|
-
p(val) {
|
|
31
|
-
this.#primaryVal = val;
|
|
32
|
-
}
|
|
33
|
-
#props = {};
|
|
34
|
-
get props() {
|
|
35
|
-
return this.#props;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* set props
|
|
39
|
-
* @param props
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
s(props) {
|
|
43
|
-
this.#props = { ...this.#props, ...props };
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
#refs = {};
|
|
47
|
-
get refs() {
|
|
48
|
-
return this.#refs;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* register refs
|
|
52
|
-
* @param refs
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
r(refs) {
|
|
56
|
-
this.#refs = { ...this.#refs, ...refs };
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
}
|
package/w.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { EventListenerOrFn, OnOptions, IW, MappedListeners } from './ts-refs/trans-render/be/types';
|
|
2
|
-
import { CSSQuery } from './ts-refs/trans-render/types';
|
|
3
|
-
export function w(q: CSSQuery, ws: Array<IW>, callback: (q: CSSQuery) => W){
|
|
4
|
-
const returnObj = new W(q, callback);
|
|
5
|
-
ws.push(returnObj);
|
|
6
|
-
return returnObj;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class W<T = EventTarget> implements IW<T>{
|
|
10
|
-
constructor(public q: CSSQuery, public w: (q: CSSQuery) => W){}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#listeners: MappedListeners = {};
|
|
15
|
-
get listeners(){
|
|
16
|
-
return this.#listeners;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* add events
|
|
20
|
-
* @param eventsToAdd
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
a(eventsToAdd: {[key: string]: EventListenerOrFn}){
|
|
24
|
-
this.#listeners = {...this.#listeners, ...eventsToAdd};
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
#primaryVal: any
|
|
28
|
-
get primaryVal(){
|
|
29
|
-
return this.#primaryVal
|
|
30
|
-
}
|
|
31
|
-
p(val: any){
|
|
32
|
-
this.#primaryVal = val;
|
|
33
|
-
}
|
|
34
|
-
#props: Partial<T> = {};
|
|
35
|
-
get props(){
|
|
36
|
-
return this.#props;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* set props
|
|
40
|
-
* @param props
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
s(props: Partial<T>){
|
|
44
|
-
this.#props = {...this.#props, ...props};
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
#refs: {[key: string]: any} = {};
|
|
48
|
-
get refs(){
|
|
49
|
-
return this.#refs;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* register refs
|
|
53
|
-
* @param refs
|
|
54
|
-
* @returns
|
|
55
|
-
*/
|
|
56
|
-
r(refs: {[key: string]: any}){
|
|
57
|
-
this.#refs = {...this.#refs, ...refs};
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
package/whenResolved.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export async function whenResolved(enhancedElement, base) {
|
|
2
|
-
const rn = enhancedElement.getRootNode();
|
|
3
|
-
const mose = rn.getElementById(`be-hive.${base}`);
|
|
4
|
-
if (mose === null)
|
|
5
|
-
throw 404;
|
|
6
|
-
const emc = mose.synConfig;
|
|
7
|
-
return await enhancedElement.beEnhanced.whenResolved(emc);
|
|
8
|
-
}
|
package/whenResolved.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export async function whenResolved(enhancedElement: Element, base: string){
|
|
2
|
-
const rn = enhancedElement.getRootNode() as DocumentFragment;
|
|
3
|
-
const mose = rn.getElementById(`be-hive.${base}`);
|
|
4
|
-
if(mose === null) throw 404;
|
|
5
|
-
const emc = (<any>mose).synConfig;
|
|
6
|
-
return await (<any>enhancedElement).beEnhanced.whenResolved(emc);
|
|
7
|
-
}
|