be-hive 0.0.79 → 0.0.81

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/IDMonitor.void ADDED
@@ -0,0 +1,32 @@
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/README.md CHANGED
@@ -70,6 +70,40 @@ If one Shadow DOM blocks an inherited behivior, child Shadow DOMs can bring it b
70
70
  }'></be-hive>
71
71
  ```
72
72
 
73
+ ## Scoped refs [WIP]
74
+
75
+ be-hive can also manage "scoped refs" --
76
+
77
+ 1. Placing a DOM element, such as a template, with an id inside the be-vive element "registers" it.
78
+ 2. Elements contained inside be-hive elements in higher up ShadowDOM realms can "cascade down".
79
+
80
+ ```html
81
+ <my-element>
82
+ #shadow
83
+ <be-hive>
84
+ <template id=open-menu>
85
+ ...
86
+ </template>
87
+ </be-hive>
88
+ <my-child-element>
89
+ <be-hive>
90
+ </be-hive>
91
+ </my-child-element>
92
+ </my-element>
93
+ ```
94
+
95
+ from within my-child-element:
96
+
97
+ ```JavaScript
98
+ const openMenuTempl = await this.querySelector('be-hive').whenDefined('open-menu');
99
+ ```
100
+
101
+ Can also programmatically register template:
102
+
103
+ ```JavaScript
104
+ this.querySelector('be-hive').define(templ);
105
+ ```
106
+
73
107
  ## API
74
108
 
75
109
 
@@ -83,6 +117,5 @@ in be-hive/register.js
83
117
 
84
118
 
85
119
  be-hive then determines which be-hiviors to inherit.
86
-
87
- [TODO] Provide a "registry" for be-hiviors to read common meta information. Create a property that is an ES6 proxy, transmits event on all prop changes?
120
+
88
121
 
package/be-hive.js CHANGED
@@ -1,9 +1,11 @@
1
1
  export class BeHive extends HTMLElement {
2
+ //#monitor?: IDisposable;
2
3
  constructor() {
3
4
  super();
4
- this.registeredBehaviors = {};
5
+ // this.registeredBehaviors = {};
6
+ // this.refs = {};
5
7
  }
6
- connectedCallback() {
8
+ async connectedCallback() {
7
9
  this.hidden = true;
8
10
  const overridesAttr = this.getAttribute('overrides');
9
11
  if (overridesAttr !== null) {
@@ -13,6 +15,13 @@ export class BeHive extends HTMLElement {
13
15
  this.overrides = {};
14
16
  }
15
17
  this.#getInheritedBehaviors();
18
+ // const {IDMonitor} = await import('./IDMonitor.js');
19
+ // this.#monitor = new IDMonitor(this);
20
+ }
21
+ disconnectedCallback() {
22
+ // if(this.#monitor !== undefined){
23
+ // this.#monitor.dispose();
24
+ // }
16
25
  }
17
26
  #getInheritedBehaviors() {
18
27
  const rn = this.getRootNode();
@@ -29,6 +38,12 @@ export class BeHive extends HTMLElement {
29
38
  parentBeHiveInstance.addEventListener('latest-behavior-changed', (e) => {
30
39
  this.register(e.detail.value);
31
40
  });
41
+ // for(const id in refs){
42
+ // this.define(refs[id], true);
43
+ // }
44
+ // parentBeHiveInstance.addEventListener('new-ref', (e: Event) => {
45
+ // this.define((<any>e).detail.value, true);
46
+ // });
32
47
  }
33
48
  }
34
49
  register(parentInstance) {
package/be-hive.ts CHANGED
@@ -1,11 +1,14 @@
1
- import {BeHiveProps, BeHiveActions, BehaviorKeys} from './types';
1
+ import {BeHiveProps, BeHiveActions, BehaviorKeys, IHasID, IDisposable} from './types';
2
2
  export class BeHive extends HTMLElement{
3
+
4
+ //#monitor?: IDisposable;
3
5
  constructor(){
4
6
  super();
5
- this.registeredBehaviors = {};
6
-
7
+ // this.registeredBehaviors = {};
8
+ // this.refs = {};
9
+
7
10
  }
8
- connectedCallback(){
11
+ async connectedCallback(){
9
12
  this.hidden = true;
10
13
  const overridesAttr = this.getAttribute('overrides');
11
14
  if(overridesAttr !== null){
@@ -13,8 +16,15 @@ export class BeHive extends HTMLElement{
13
16
  }else{
14
17
  this.overrides = {};
15
18
  }
16
-
17
19
  this.#getInheritedBehaviors();
20
+ // const {IDMonitor} = await import('./IDMonitor.js');
21
+ // this.#monitor = new IDMonitor(this);
22
+ }
23
+
24
+ disconnectedCallback(){
25
+ // if(this.#monitor !== undefined){
26
+ // this.#monitor.dispose();
27
+ // }
18
28
  }
19
29
 
20
30
  #getInheritedBehaviors(){
@@ -32,6 +42,15 @@ export class BeHive extends HTMLElement{
32
42
  parentBeHiveInstance.addEventListener('latest-behavior-changed', (e: Event) => {
33
43
  this.register((<any>e).detail.value);
34
44
  });
45
+
46
+ // for(const id in refs){
47
+ // this.define(refs[id], true);
48
+ // }
49
+
50
+ // parentBeHiveInstance.addEventListener('new-ref', (e: Event) => {
51
+ // this.define((<any>e).detail.value, true);
52
+ // });
53
+
35
54
  }
36
55
  }
37
56
 
@@ -79,7 +98,35 @@ export class BeHive extends HTMLElement{
79
98
  return newBehaviorEl;
80
99
  }
81
100
 
101
+ // define(ref: Ref, noReplace: boolean){
102
+ // if(noReplace){
103
+ // if(this.refs[ref.element.id] !== undefined) return;
104
+ // }
105
+ // this.refs[ref.element.id] = ref;
106
+ // this.dispatchEvent(new CustomEvent('new-ref', {
107
+ // detail:{
108
+ // value: ref,
109
+ // } as INewDefEvent,
110
+ // }));
111
+ // }
112
+
113
+ // get(id: string){
114
+ // return this.refs[id];
115
+ // }
82
116
 
117
+ // whenDefined(id: string): Promise<Ref>{
118
+ // return new Promise(resolve => {
119
+ // const ref = this.get(id);
120
+ // if(ref !== undefined){
121
+ // resolve(ref);
122
+ // return;
123
+ // }
124
+ // this.addEventListener('new-ref', e => {
125
+ // const ref = (<any>e).detail.value as Ref;
126
+ // if(ref.element.id === id) resolve(ref);
127
+ // }, {once: true});
128
+ // });
129
+ // }
83
130
  }
84
131
 
85
132
  if(!customElements.get('be-hive')){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "be-hive",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "keywords": [
5
5
  "web-components",
6
6
  "web-component",
@@ -28,13 +28,13 @@
28
28
  "doc": "custom-elements-manifest analyze"
29
29
  },
30
30
  "devDependencies": {
31
- "@playwright/test": "1.29.1",
31
+ "@playwright/test": "1.30.0",
32
32
  "@skypack/package-check": "0.2.2",
33
33
  "may-it-serve": "0.0.4",
34
34
  "@custom-elements-manifest/analyzer": "0.6.4",
35
35
  "xtal-shell": "0.0.27",
36
- "be-functional": "0.0.17",
37
- "be-exportable": "0.0.52"
36
+ "be-functional": "0.0.18",
37
+ "be-exportable": "0.0.62"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
package/types.d.ts CHANGED
@@ -15,7 +15,9 @@ export interface BeHiveProps{
15
15
  isC: boolean;
16
16
  registeredBehaviors: {[key: string]: BehaviorKeys};
17
17
  latestBehaviors: BehaviorKeys[];
18
- beSevered: boolean
18
+ //refs: {[key: string]: Ref};
19
+ beSevered: boolean;
20
+
19
21
  }
20
22
 
21
23
  export interface BeHiveActions{
@@ -27,4 +29,23 @@ export interface BeHiveActions{
27
29
 
28
30
  export interface LatestBehaviorEvent{
29
31
  value: BehaviorKeys;
30
- }
32
+ }
33
+
34
+ export interface IHasID{
35
+ id: string;
36
+ }
37
+
38
+ // export interface Ref<TElement = IHasID, Meta = any>{
39
+ // element: TElement,
40
+ // meta: Meta
41
+ // }
42
+
43
+ export interface IDisposable{
44
+ dispose(): void;
45
+ }
46
+
47
+ export type Disposable = {new(): IDisposable};
48
+
49
+ // export interface INewDefEvent{
50
+ // value: Ref
51
+ // }