be-hive 0.0.93 → 0.0.95
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/package.json +5 -6
- package/.gitignore +0 -1
- package/IDMonitor.void +0 -32
- package/be-hive.ts +0 -175
- package/beatify.ts +0 -23
- package/getLocalName.ts +0 -28
- package/playwright.config.ts +0 -28
- package/register.ts +0 -15
- package/tsconfig.json +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "be-hive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.95",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
"./getLocalName.js": "./getLocalName.js"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
|
-
"
|
|
21
|
+
"*.js",
|
|
22
|
+
"types.d.ts"
|
|
22
23
|
],
|
|
23
24
|
"types": "types.d.ts",
|
|
24
25
|
"scripts": {
|
|
25
26
|
"serve": "node node_modules/may-it-serve/serve.js",
|
|
26
27
|
"test": "playwright test",
|
|
27
|
-
"package-check": "package-check",
|
|
28
|
-
"doc": "custom-elements-manifest analyze",
|
|
29
28
|
"safari": "npx playwright wk http://localhost:3030"
|
|
30
29
|
},
|
|
31
30
|
"dependencies": {
|
|
32
|
-
"be-enhanced": "0.0.
|
|
31
|
+
"be-enhanced": "0.0.20"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"@playwright/test": "1.
|
|
34
|
+
"@playwright/test": "1.34.0",
|
|
36
35
|
"may-it-serve": "0.0.5"
|
|
37
36
|
},
|
|
38
37
|
"repository": {
|
package/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/node_modules
|
package/IDMonitor.void
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {BeHive} from './be-hive.js';
|
|
2
|
-
import { IHasID } from './types.js';
|
|
3
|
-
export class IDMonitor{
|
|
4
|
-
#mut: MutationObserver;
|
|
5
|
-
constructor(public instance: BeHive){
|
|
6
|
-
const config: MutationObserverInit = { childList: true};
|
|
7
|
-
instance.querySelectorAll('*').forEach(element => {
|
|
8
|
-
const {id} = element;
|
|
9
|
-
if(id){
|
|
10
|
-
instance.define({element, meta: {}}, false);
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
this.#mut = new MutationObserver((mutationList: MutationRecord[]) => {
|
|
14
|
-
for(const mutation of mutationList){
|
|
15
|
-
const {addedNodes} = mutation;
|
|
16
|
-
if(addedNodes !== undefined){
|
|
17
|
-
for(const addedNode of addedNodes){
|
|
18
|
-
const element = addedNode as any as IHasID;
|
|
19
|
-
const {id} = element
|
|
20
|
-
if(id){
|
|
21
|
-
instance.define({element, meta: {}}, false);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
this.#mut.observe(instance, config);
|
|
28
|
-
}
|
|
29
|
-
dispose(){
|
|
30
|
-
this.#mut.disconnect();
|
|
31
|
-
}
|
|
32
|
-
}
|
package/be-hive.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {BeHiveProps, BeHiveActions, BehaviorKeys, IHasID, IDisposable} from './types';
|
|
2
|
-
import {BeEnhanced} from 'be-enhanced/beEnhanced.js';
|
|
3
|
-
import 'be-enhanced/beEnhanced.js';
|
|
4
|
-
export class BeHive extends HTMLElement{
|
|
5
|
-
|
|
6
|
-
constructor(){
|
|
7
|
-
super();
|
|
8
|
-
this.registeredBehaviors = {};
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
async connectedCallback(){
|
|
12
|
-
this.hidden = true;
|
|
13
|
-
const overridesAttr = this.getAttribute('overrides');
|
|
14
|
-
if(overridesAttr !== null){
|
|
15
|
-
this.overrides = JSON.parse(overridesAttr);
|
|
16
|
-
}else{
|
|
17
|
-
this.overrides = {};
|
|
18
|
-
}
|
|
19
|
-
this.#getInheritedBehaviors();
|
|
20
|
-
this.#addMutationObserver();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
disconnectedCallback(){
|
|
24
|
-
if(this.#mutationObserver !== undefined){
|
|
25
|
-
this.#mutationObserver.disconnect();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
#getInheritedBehaviors(){
|
|
31
|
-
const rn = this.getRootNode();
|
|
32
|
-
const host = (<any>rn).host;
|
|
33
|
-
if(!host) return;
|
|
34
|
-
const parentShadowRealm = host.getRootNode();
|
|
35
|
-
const parentBeHiveInstance = parentShadowRealm.querySelector('be-hive') as BeHiveProps & Element;
|
|
36
|
-
if(parentBeHiveInstance !== null){
|
|
37
|
-
const {registeredBehaviors} = parentBeHiveInstance;
|
|
38
|
-
for(const key in registeredBehaviors){
|
|
39
|
-
this.register(registeredBehaviors[key]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
parentBeHiveInstance.addEventListener('latest-behavior-changed', (e: Event) => {
|
|
43
|
-
this.register((<any>e).detail.value);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
#mutationObserver: MutationObserver | undefined;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
#addMutationObserver(){
|
|
54
|
-
const rn = this.getRootNode() as DocumentFragment;
|
|
55
|
-
const config = { attributes: true, childList: true, subtree: true } as MutationObserverInit;
|
|
56
|
-
const callback = (mutationList: MutationRecord[], observer: MutationObserver) => {
|
|
57
|
-
|
|
58
|
-
for (const mutation of mutationList) {
|
|
59
|
-
if (mutation.type === "childList") {
|
|
60
|
-
//console.log("A child node has been added or removed.");
|
|
61
|
-
for(const node of mutation.addedNodes){
|
|
62
|
-
this.#inspectNewNode(node);
|
|
63
|
-
}
|
|
64
|
-
for(const node of mutation.removedNodes){
|
|
65
|
-
const beEnhanced = (<any>node).beEnhanced;
|
|
66
|
-
if(beEnhanced === undefined) continue;
|
|
67
|
-
for(const key in beEnhanced){
|
|
68
|
-
const enhancement = beEnhanced[key];
|
|
69
|
-
const detach = enhancement['detach'];
|
|
70
|
-
if(typeof(detach) === 'function'){
|
|
71
|
-
detach(node);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} else if (mutation.type === "attributes") {
|
|
76
|
-
|
|
77
|
-
//console.log(`The ${mutation.attributeName} attribute was modified.`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Create an observer instance linked to the callback function
|
|
83
|
-
const observer = new MutationObserver(callback);
|
|
84
|
-
observer.observe(rn, config);
|
|
85
|
-
this.#mutationObserver = observer;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
#inspectNewNode(node: Node){
|
|
89
|
-
if(!(node instanceof Element)) return;
|
|
90
|
-
const {registeredBehaviors} = this;
|
|
91
|
-
for(const key in registeredBehaviors){
|
|
92
|
-
const registeredBehavior = registeredBehaviors[key];
|
|
93
|
-
const {upgrade} = registeredBehavior;
|
|
94
|
-
const attr = '[' + key + ']';
|
|
95
|
-
if(node.matches(upgrade) && node.matches(attr)){
|
|
96
|
-
const {beEnhanced} : {beEnhanced: BeEnhanced} = (<any>node);
|
|
97
|
-
//console.log("behive: attachAttr");
|
|
98
|
-
beEnhanced.attachAttr(key);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
#scanForSingleRegisteredBehavior(localName: string, behaviorKeys: BehaviorKeys){
|
|
105
|
-
const {ifWantsToBe, upgrade} = behaviorKeys;
|
|
106
|
-
const attr = `${upgrade}[${localName}]`;
|
|
107
|
-
const rn = this.getRootNode() as DocumentFragment;
|
|
108
|
-
rn.querySelectorAll(attr).forEach(el => {
|
|
109
|
-
const {beEnhanced} : {beEnhanced: BeEnhanced} = (<any>el);
|
|
110
|
-
//console.log("behive: attachAttr");
|
|
111
|
-
beEnhanced.attachAttr(localName);
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
register(parentInstance: BehaviorKeys){
|
|
116
|
-
const parentInstanceLocalName = parentInstance.localName;
|
|
117
|
-
if(this.querySelector(parentInstanceLocalName) !== null) return;
|
|
118
|
-
const override = this.overrides[parentInstanceLocalName];
|
|
119
|
-
let newInstanceTagName = parentInstanceLocalName;
|
|
120
|
-
let newIfWantsToBe = parentInstance.ifWantsToBe;
|
|
121
|
-
let newDisabled = parentInstance.disabled;
|
|
122
|
-
|
|
123
|
-
if(override !== undefined){
|
|
124
|
-
const {ifWantsToBe, block, unblock} = override;
|
|
125
|
-
if(block) {
|
|
126
|
-
newDisabled = true;
|
|
127
|
-
} else if(unblock){
|
|
128
|
-
newDisabled = false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if(ifWantsToBe){
|
|
132
|
-
newIfWantsToBe = ifWantsToBe;
|
|
133
|
-
newInstanceTagName = 'be-' + ifWantsToBe;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const beSevered = this.hasAttribute('be-severed');
|
|
137
|
-
if(beSevered) newDisabled = true;
|
|
138
|
-
const newBehaviorEl = document.createElement('template');
|
|
139
|
-
Object.assign(newBehaviorEl.dataset, {
|
|
140
|
-
localName: parentInstanceLocalName,
|
|
141
|
-
ifWantsToBe: newIfWantsToBe,
|
|
142
|
-
upgrade: parentInstance.upgrade,
|
|
143
|
-
});
|
|
144
|
-
//parentInstanceLocalName
|
|
145
|
-
// newBehaviorEl.setAttribute('if-wants-to-be', newIfWantsToBe);
|
|
146
|
-
// newBehaviorEl.setAttribute('upgrade', parentInstance.upgrade);
|
|
147
|
-
if(newDisabled) newBehaviorEl.setAttribute('disabled', '');
|
|
148
|
-
this.appendChild(newBehaviorEl);
|
|
149
|
-
const newRegisteredBehavior: BehaviorKeys = {
|
|
150
|
-
...parentInstance,
|
|
151
|
-
ifWantsToBe: newIfWantsToBe,
|
|
152
|
-
disabled: newDisabled,
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
this.registeredBehaviors[parentInstanceLocalName] = newRegisteredBehavior;
|
|
156
|
-
this.#scanForSingleRegisteredBehavior(parentInstanceLocalName, newRegisteredBehavior);
|
|
157
|
-
//console.log({newRegisteredBehavior});
|
|
158
|
-
this.dispatchEvent(new CustomEvent('latest-behavior-changed', {
|
|
159
|
-
detail:{
|
|
160
|
-
value: newRegisteredBehavior,
|
|
161
|
-
}
|
|
162
|
-
}));
|
|
163
|
-
//this.latestBehaviors = [...this.latestBehaviors, newRegisteredBehavior];
|
|
164
|
-
//this.#doSweepingScan();
|
|
165
|
-
return newBehaviorEl;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if(!customElements.get('be-hive')){
|
|
172
|
-
customElements.define('be-hive', BeHive);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export interface BeHive extends BeHiveProps{}
|
package/beatify.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function beatify(content: DocumentFragment | Element, beHive: Element){
|
|
2
|
-
const decoratorElements = Array.from(beHive.children) as any;
|
|
3
|
-
|
|
4
|
-
for(const decorEl of decoratorElements){
|
|
5
|
-
const ifWantsToBe = (decorEl as any as Element).getAttribute('if-wants-to-be');
|
|
6
|
-
if(ifWantsToBe === undefined) continue;
|
|
7
|
-
const isAttr = 'is-' + ifWantsToBe;
|
|
8
|
-
const beAttr = 'be-' + ifWantsToBe;
|
|
9
|
-
const qry = `[${isAttr}]`;
|
|
10
|
-
const converted = Array.from(content.querySelectorAll(qry));
|
|
11
|
-
if((content as Element).matches !== undefined && (content as Element).matches(qry)) converted.push(content as Element);
|
|
12
|
-
for(const el of converted){
|
|
13
|
-
const attr = el.getAttribute(isAttr)!;
|
|
14
|
-
el.removeAttribute(isAttr);
|
|
15
|
-
el.setAttribute(beAttr, attr);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function beBeatified(element: Element){
|
|
21
|
-
const beHive = (element.getRootNode() as ShadowRoot).querySelector('be-hive') as Element;
|
|
22
|
-
beatify(element, beHive);
|
|
23
|
-
}
|
package/getLocalName.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {LatestBehaviorEvent} from './types';
|
|
2
|
-
|
|
3
|
-
export function getLocalName(peerCitizen: Element, decoratorName: string): Promise<string>{
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const rn = peerCitizen.getRootNode() as Element;
|
|
6
|
-
const bh = rn.querySelector('be-hive');
|
|
7
|
-
if(bh === null) {
|
|
8
|
-
reject('404');
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const wc = bh.querySelector(decoratorName);
|
|
13
|
-
if(wc !== null){
|
|
14
|
-
resolve((<any>bh).ifWantsToBe);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const controller = new AbortController();
|
|
18
|
-
bh.addEventListener('latest-behavior-changed', e => {
|
|
19
|
-
const detail = (e as CustomEvent).detail as LatestBehaviorEvent;
|
|
20
|
-
const {localName, ifWantsToBe} = detail.value;
|
|
21
|
-
if(localName === decoratorName){
|
|
22
|
-
resolve(ifWantsToBe);
|
|
23
|
-
controller.abort();
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
}
|
package/playwright.config.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// playwright.config.ts
|
|
2
|
-
import { PlaywrightTestConfig, devices } from '@playwright/test';
|
|
3
|
-
const config: PlaywrightTestConfig = {
|
|
4
|
-
webServer: {
|
|
5
|
-
command: 'npm run serve',
|
|
6
|
-
url: 'http://localhost:3030/',
|
|
7
|
-
timeout: 120 * 1000,
|
|
8
|
-
reuseExistingServer: !process.env.CI,
|
|
9
|
-
},
|
|
10
|
-
use: {
|
|
11
|
-
baseURL: 'http://localhost:3030/',
|
|
12
|
-
},
|
|
13
|
-
projects: [
|
|
14
|
-
// {
|
|
15
|
-
// name: 'chromium',
|
|
16
|
-
// use: { ...devices['Desktop Chrome'] },
|
|
17
|
-
// },
|
|
18
|
-
// {
|
|
19
|
-
// name: 'firefox',
|
|
20
|
-
// use: { ...devices['Desktop Firefox'] },
|
|
21
|
-
// },
|
|
22
|
-
// {
|
|
23
|
-
// name: 'webkit',
|
|
24
|
-
// use: { ...devices['Desktop Safari'] },
|
|
25
|
-
// },
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
export default config;
|
package/register.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {BeHiveActions} from './types';
|
|
2
|
-
import('./be-hive.js');
|
|
3
|
-
export async function register(ifWantsToBe: string, upgrade: string, extTagName: string){
|
|
4
|
-
let beHive = document.querySelector('be-hive') as Element & BeHiveActions;
|
|
5
|
-
if(beHive===null){
|
|
6
|
-
beHive = document.body.appendChild(document.createElement('be-hive')) as any as Element & BeHiveActions;
|
|
7
|
-
}
|
|
8
|
-
await customElements.whenDefined('be-hive');
|
|
9
|
-
return beHive.register({
|
|
10
|
-
ifWantsToBe,
|
|
11
|
-
upgrade,
|
|
12
|
-
localName: extTagName,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"sourceMap": false,
|
|
6
|
-
"experimentalDecorators": false,
|
|
7
|
-
"newLine": "LF",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"watch": true
|
|
10
|
-
},
|
|
11
|
-
"files": [
|
|
12
|
-
"be-hive.ts",
|
|
13
|
-
"register.ts",
|
|
14
|
-
"beatify.ts",
|
|
15
|
-
"getLocalName.ts"
|
|
16
|
-
],
|
|
17
|
-
"exclude":[
|
|
18
|
-
"build",
|
|
19
|
-
"bower_components",
|
|
20
|
-
"node_modules"
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
}
|