be-hive 0.0.102 → 0.0.104

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 CHANGED
@@ -111,6 +111,10 @@ export class BeHive extends HTMLElement {
111
111
  beEnhanced.attachAttr(namespacedName, localName);
112
112
  });
113
113
  }
114
+ async beatify(content) {
115
+ const { beatify } = await import('./beatify.js');
116
+ return await beatify(content, this);
117
+ }
114
118
  register(parentInstance) {
115
119
  const parentInstanceLocalName = parentInstance.localName;
116
120
  if (this.querySelector(parentInstanceLocalName) !== null)
package/beatify.js ADDED
@@ -0,0 +1,57 @@
1
+ export function beatify(content, beHive, options) {
2
+ const clone = content.cloneNode(true);
3
+ options = options || {
4
+ cleanMicrodata: true //TODO
5
+ };
6
+ const { registeredBehaviors } = beHive;
7
+ const map = new Map();
8
+ for (const key in registeredBehaviors) {
9
+ const registeredBehavior = registeredBehaviors[key];
10
+ const { ifWantsToBe } = registeredBehavior;
11
+ const qry = `[be-${ifWantsToBe}]`; //TODO: include enh-by- and data-enh-by
12
+ const enhancedElements = Array.from(clone.querySelectorAll(qry));
13
+ for (const el of enhancedElements) {
14
+ if (!map.has(el)) {
15
+ map.set(el, new Map());
16
+ }
17
+ const attr = `be-${ifWantsToBe}`;
18
+ const attrVal = el.getAttribute(attr);
19
+ const elMap = map.get(el);
20
+ elMap.set(ifWantsToBe, attrVal);
21
+ el.removeAttribute(attr);
22
+ }
23
+ }
24
+ for (const [el, m] of map) {
25
+ let be = '{';
26
+ for (const [key, val] of m) {
27
+ if (val.startsWith('{')) {
28
+ be += `"${key}": ${val}`;
29
+ }
30
+ else {
31
+ be += `"${key}": "${val}"`;
32
+ }
33
+ }
34
+ be += '}';
35
+ el.setAttribute('be', be);
36
+ }
37
+ return clone;
38
+ // const decoratorElements = Array.from(beHive.children) as any;
39
+ // for(const decorEl of decoratorElements){
40
+ // const ifWantsToBe = (decorEl as any as Element).getAttribute('if-wants-to-be');
41
+ // if(ifWantsToBe === undefined) continue;
42
+ // const isAttr = 'is-' + ifWantsToBe;
43
+ // const beAttr = 'be-' + ifWantsToBe;
44
+ // const qry = `[${isAttr}]`;
45
+ // const converted = Array.from(content.querySelectorAll(qry));
46
+ // if((content as Element).matches !== undefined && (content as Element).matches(qry)) converted.push(content as Element);
47
+ // for(const el of converted){
48
+ // const attr = el.getAttribute(isAttr)!;
49
+ // el.removeAttribute(isAttr);
50
+ // el.setAttribute(beAttr, attr);
51
+ // }
52
+ // }
53
+ }
54
+ export function beBeatified(element) {
55
+ const beHive = element.getRootNode().querySelector('be-hive');
56
+ beatify(element, beHive);
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "be-hive",
3
- "version": "0.0.102",
3
+ "version": "0.0.104",
4
4
  "keywords": [
5
5
  "web-components",
6
6
  "web-component",
@@ -26,7 +26,7 @@
26
26
  "serve": "node node_modules/may-it-serve/serve.js"
27
27
  },
28
28
  "dependencies": {
29
- "be-enhanced": "0.0.27"
29
+ "be-enhanced": "0.0.29"
30
30
  },
31
31
  "devDependencies": {
32
32
  "may-it-serve": "0.0.5"
package/types.d.ts CHANGED
@@ -20,6 +20,10 @@ export interface BeHiveProps{
20
20
 
21
21
  }
22
22
 
23
+ export interface BeatifyOptions{
24
+ cleanMicrodata?: boolean,
25
+ }
26
+
23
27
  export interface BeHiveActions{
24
28
  intro(self: this): void;
25
29
  //onOverrides(self: this): void;