be-hive 0.0.50 → 0.0.53
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/README.md +47 -19
- package/be-hive.js +39 -29
- package/be-hive.ts +43 -28
- package/package.json +7 -5
- package/types.d.ts +4 -1
package/README.md
CHANGED
|
@@ -2,21 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/bahrus/be-hive/actions/workflows/CI.yml)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://bundlephobia.com/result?p=be-hive)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/npm/be-hive?compression=gzip">
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<a href="https://nodei.co/npm/be-hive/"><img src="https://nodei.co/npm/be-hive.png"></a>
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Inheriting behiviors
|
|
12
|
+
|
|
13
|
+
[be-hive](https://www.youtube.com/watch?v=SQoOwosJWns) let's it [snow in August](https://www.youtube.com/watch?v=m3dmnOtqrV0).
|
|
14
|
+
|
|
15
|
+
be-hive allows us to manage and coordinate the [family, or HTML frimework](https://github.com/bahrus/may-it-be) of [be-decorated](https://github.com/bahrus/be-decorated) element behiviors / decorators.
|
|
16
|
+
|
|
17
|
+
Without be-hive, the developer is burdened with plopping an instance of each decorator inside each shadow DOM realm.
|
|
18
|
+
|
|
19
|
+
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:
|
|
12
20
|
|
|
13
21
|
```html
|
|
14
22
|
<be-hive></be-hive>
|
|
15
23
|
```
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
But the child Shadow DOM realm can develop a personality of its own by:
|
|
28
|
+
|
|
29
|
+
1. Adding additional behiviors by adding specific be-decorated elements inside the be-hive instance tag.
|
|
30
|
+
2. Avoiding naming conflicts by overriding the attribute associated with the inherited behivior.
|
|
31
|
+
3. Preventing inheriting unwanted behiviors from affecting the child Shadow DOM realm.
|
|
32
|
+
4. Start over. Only decorator elements manually added inside the Shadow DOM (preferably inside the be-hive tag, for inheritance to work within)
|
|
33
|
+
|
|
34
|
+
## Syntax for customizations of inherited behiviors:
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<be-hive overrides='{
|
|
38
|
+
"be-sharing":{
|
|
39
|
+
"ifWantsToBe": "familial"
|
|
40
|
+
},
|
|
41
|
+
"be-gracious": {
|
|
42
|
+
"ifWantsToBe": "respectful"
|
|
43
|
+
},
|
|
44
|
+
"be-disobedient-without-facing-the-consequences": {
|
|
45
|
+
"block": "true"
|
|
46
|
+
}
|
|
47
|
+
}'></be-hive>
|
|
48
|
+
```
|
|
18
49
|
|
|
19
|
-
##
|
|
50
|
+
## Be like Sirius Black
|
|
51
|
+
|
|
52
|
+
If the inherited behiviors are all just too odious to inherit, there's an option to start again:
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<be-hive be-severed>
|
|
56
|
+
</be-hive>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## API
|
|
20
61
|
|
|
21
62
|
|
|
22
63
|
be-hiviors are registered via function:
|
|
@@ -31,16 +72,3 @@ in be-hive/register.js
|
|
|
31
72
|
be-hive then determines which be-hiviors to inherit.
|
|
32
73
|
|
|
33
74
|
|
|
34
|
-
However, be-hive supports an optional "overrides" attribute/property that allows overriding the parent inheritance.
|
|
35
|
-
|
|
36
|
-
To uses be-hiviors in this way, we need to include one instance of be-hive in our ShadowDOM-based web component.
|
|
37
|
-
|
|
38
|
-
```html
|
|
39
|
-
<be-hive overrides='{
|
|
40
|
-
"be-sharing":{
|
|
41
|
-
"ifWantsToBe": "familial"
|
|
42
|
-
}
|
|
43
|
-
}'></be-hive>
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
[TODO] Expline this coherently.
|
package/be-hive.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CE } from 'trans-render/lib/CE.js';
|
|
2
2
|
export class BeHiveCore extends HTMLElement {
|
|
3
3
|
registeredBehaviors = {};
|
|
4
|
-
intro({}) {
|
|
4
|
+
intro({ beSevered }) {
|
|
5
|
+
if (beSevered)
|
|
6
|
+
return;
|
|
5
7
|
const rn = this.getRootNode();
|
|
6
8
|
const host = rn.host;
|
|
7
9
|
if (!host)
|
|
@@ -18,48 +20,56 @@ export class BeHiveCore extends HTMLElement {
|
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
register(instance) {
|
|
27
|
-
const localName = instance.localName;
|
|
28
|
-
if (this.overrides[instance.localName] !== undefined)
|
|
23
|
+
register(parentInstance) {
|
|
24
|
+
const parentInstanceLocalName = parentInstance.localName;
|
|
25
|
+
if (this.querySelector(parentInstanceLocalName) !== null)
|
|
29
26
|
return;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const override = this.overrides[parentInstanceLocalName];
|
|
28
|
+
let newInstanceTagName = parentInstanceLocalName;
|
|
29
|
+
let newIfWantsToBe = parentInstance.ifWantsToBe;
|
|
30
|
+
if (override !== undefined) {
|
|
31
|
+
const { ifWantsToBe, block } = override;
|
|
32
|
+
if (block)
|
|
33
|
+
return;
|
|
34
|
+
if (ifWantsToBe !== null) {
|
|
35
|
+
newIfWantsToBe = ifWantsToBe;
|
|
36
|
+
newInstanceTagName = 'be-' + ifWantsToBe;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const newBehaviorEl = document.createElement(parentInstanceLocalName);
|
|
40
|
+
newBehaviorEl.setAttribute('if-wants-to-be', newIfWantsToBe);
|
|
41
|
+
newBehaviorEl.setAttribute('upgrade', parentInstance.upgrade);
|
|
36
42
|
this.appendChild(newBehaviorEl);
|
|
37
|
-
|
|
43
|
+
const newRegisteredBehavior = {
|
|
44
|
+
...parentInstance,
|
|
45
|
+
ifWantsToBe: newIfWantsToBe,
|
|
46
|
+
};
|
|
47
|
+
this.registeredBehaviors[parentInstanceLocalName] = newRegisteredBehavior;
|
|
48
|
+
this.latestBehavior = newRegisteredBehavior;
|
|
38
49
|
return newBehaviorEl;
|
|
39
50
|
}
|
|
51
|
+
onLatestBehavior({ latestBehavior }) {
|
|
52
|
+
this.dispatchEvent(new CustomEvent('latest-behavior-changed', {
|
|
53
|
+
detail: {
|
|
54
|
+
value: latestBehavior,
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
40
58
|
}
|
|
41
59
|
const tagName = 'be-hive';
|
|
42
|
-
const
|
|
60
|
+
const ce = new CE({
|
|
43
61
|
config: {
|
|
44
62
|
tagName,
|
|
45
63
|
propDefaults: {
|
|
46
64
|
overrides: {},
|
|
47
65
|
isC: true,
|
|
48
|
-
|
|
49
|
-
propInfo: {
|
|
50
|
-
latestBehavior: {
|
|
51
|
-
notify: {
|
|
52
|
-
dispatch: true,
|
|
53
|
-
}
|
|
54
|
-
}
|
|
66
|
+
beSevered: false,
|
|
55
67
|
},
|
|
56
68
|
actions: {
|
|
57
69
|
intro: {
|
|
58
70
|
ifAllOf: ['isC'],
|
|
59
71
|
},
|
|
60
|
-
|
|
61
|
-
ifAllOf: ['overrides']
|
|
62
|
-
}
|
|
72
|
+
onLatestBehavior: 'latestBehavior'
|
|
63
73
|
},
|
|
64
74
|
style: {
|
|
65
75
|
display: 'none',
|
|
@@ -67,4 +77,4 @@ const xe = new XE({
|
|
|
67
77
|
},
|
|
68
78
|
superclass: BeHiveCore
|
|
69
79
|
});
|
|
70
|
-
export const BeHive =
|
|
80
|
+
export const BeHive = ce.classDef;
|
package/be-hive.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {CE} from 'trans-render/lib/CE.js';
|
|
2
2
|
import {BeHiveProps, BeHiveActions, BehaviorKeys} from './types';
|
|
3
3
|
|
|
4
4
|
export class BeHiveCore extends HTMLElement implements BeHiveActions{
|
|
5
5
|
registeredBehaviors: {[key: string]: BehaviorKeys} = {};
|
|
6
6
|
|
|
7
|
-
intro({}: this){
|
|
7
|
+
intro({beSevered}: this){
|
|
8
|
+
if(beSevered) return;
|
|
8
9
|
const rn = this.getRootNode();
|
|
9
10
|
const host = (<any>rn).host;
|
|
10
11
|
if(!host) return;
|
|
@@ -21,51 +22,65 @@ export class BeHiveCore extends HTMLElement implements BeHiveActions{
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
onOverrides({overrides}: this){
|
|
25
|
-
for(const key in overrides){
|
|
26
|
-
this.register(overrides[key]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if(this.querySelector(
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
|
|
27
|
+
register(parentInstance: BehaviorKeys){
|
|
28
|
+
const parentInstanceLocalName = parentInstance.localName;
|
|
29
|
+
if(this.querySelector(parentInstanceLocalName) !== null) return;
|
|
30
|
+
const override = this.overrides[parentInstanceLocalName];
|
|
31
|
+
let newInstanceTagName = parentInstanceLocalName;
|
|
32
|
+
let newIfWantsToBe = parentInstance.ifWantsToBe;
|
|
33
|
+
if(override !== undefined){
|
|
34
|
+
const {ifWantsToBe, block} = override;
|
|
35
|
+
if(block) return;
|
|
36
|
+
if(ifWantsToBe !== null){
|
|
37
|
+
newIfWantsToBe = ifWantsToBe;
|
|
38
|
+
newInstanceTagName = 'be-' + ifWantsToBe;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const newBehaviorEl = document.createElement(parentInstanceLocalName);
|
|
43
|
+
newBehaviorEl.setAttribute('if-wants-to-be', newIfWantsToBe);
|
|
44
|
+
newBehaviorEl.setAttribute('upgrade', parentInstance.upgrade);
|
|
38
45
|
this.appendChild(newBehaviorEl);
|
|
39
|
-
|
|
46
|
+
const newRegisteredBehavior: BehaviorKeys = {
|
|
47
|
+
...parentInstance,
|
|
48
|
+
ifWantsToBe: newIfWantsToBe,
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
this.registeredBehaviors[parentInstanceLocalName] = newRegisteredBehavior;
|
|
53
|
+
this.latestBehavior = newRegisteredBehavior;
|
|
40
54
|
return newBehaviorEl;
|
|
41
55
|
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
onLatestBehavior({latestBehavior}: this): void {
|
|
59
|
+
this.dispatchEvent(new CustomEvent('latest-behavior-changed', {
|
|
60
|
+
detail:{
|
|
61
|
+
value: latestBehavior,
|
|
62
|
+
}
|
|
63
|
+
}))
|
|
64
|
+
}
|
|
42
65
|
}
|
|
43
66
|
|
|
44
67
|
export interface BeHiveCore extends BeHiveProps{}
|
|
45
68
|
|
|
46
69
|
const tagName = 'be-hive';
|
|
47
70
|
|
|
48
|
-
const
|
|
71
|
+
const ce = new CE<BeHiveProps, BeHiveActions>({
|
|
49
72
|
config:{
|
|
50
73
|
tagName,
|
|
51
74
|
propDefaults:{
|
|
52
75
|
overrides: {},
|
|
53
76
|
isC: true,
|
|
54
|
-
|
|
55
|
-
propInfo:{
|
|
56
|
-
latestBehavior: {
|
|
57
|
-
notify:{
|
|
58
|
-
dispatch: true,
|
|
59
|
-
}
|
|
60
|
-
}
|
|
77
|
+
beSevered: false,
|
|
61
78
|
},
|
|
62
79
|
actions:{
|
|
63
80
|
intro:{
|
|
64
81
|
ifAllOf:['isC'],
|
|
65
82
|
},
|
|
66
|
-
|
|
67
|
-
ifAllOf:['overrides']
|
|
68
|
-
}
|
|
83
|
+
onLatestBehavior: 'latestBehavior'
|
|
69
84
|
},
|
|
70
85
|
style:{
|
|
71
86
|
display: 'none',
|
|
@@ -74,6 +89,6 @@ const xe = new XE<BeHiveProps, BeHiveActions>({
|
|
|
74
89
|
superclass: BeHiveCore
|
|
75
90
|
});
|
|
76
91
|
|
|
77
|
-
export const BeHive =
|
|
92
|
+
export const BeHive = ce.classDef!;
|
|
78
93
|
|
|
79
94
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "be-hive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"web-components",
|
|
6
6
|
"web-component",
|
|
@@ -27,15 +27,17 @@
|
|
|
27
27
|
"doc": "custom-elements-manifest analyze"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
30
|
+
"trans-render": "0.0.562"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@playwright/test": "1.
|
|
33
|
+
"@playwright/test": "1.25.0",
|
|
34
34
|
"@skypack/package-check": "0.2.2",
|
|
35
35
|
"may-it-serve": "0.0.2",
|
|
36
36
|
"@custom-elements-manifest/analyzer": "0.6.4",
|
|
37
|
-
"xtal-editor": "0.0.
|
|
38
|
-
"xtal-shell": "0.0.27"
|
|
37
|
+
"xtal-editor": "0.0.177",
|
|
38
|
+
"xtal-shell": "0.0.27",
|
|
39
|
+
"be-exportable": "0.0.23",
|
|
40
|
+
"be-functional": "0.0.8"
|
|
39
41
|
},
|
|
40
42
|
"repository": {
|
|
41
43
|
"type": "git",
|
package/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface BehaviorKeys {
|
|
|
4
4
|
ifWantsToBe: string,
|
|
5
5
|
upgrade: string,
|
|
6
6
|
localName: string,
|
|
7
|
+
block?: boolean,
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
|
|
@@ -12,10 +13,12 @@ export interface BeHiveProps{
|
|
|
12
13
|
isC: boolean;
|
|
13
14
|
registeredBehaviors: {[key: string]: BehaviorKeys};
|
|
14
15
|
latestBehavior: BehaviorKeys;
|
|
16
|
+
beSevered: boolean
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export interface BeHiveActions{
|
|
18
20
|
intro(self: this): void;
|
|
19
|
-
onOverrides(self: this): void;
|
|
21
|
+
//onOverrides(self: this): void;
|
|
22
|
+
onLatestBehavior(self: this): void;
|
|
20
23
|
register(instance: BehaviorKeys): Element | undefined;
|
|
21
24
|
}
|