be-hive 0.0.109 → 0.0.110

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.
Files changed (3) hide show
  1. package/be-hive.js +2 -1
  2. package/beatify.js +57 -57
  3. package/package.json +1 -1
package/be-hive.js CHANGED
@@ -64,7 +64,8 @@ export class BeHive extends HTMLElement {
64
64
  }
65
65
  }
66
66
  else if (mutation.type === "attributes") {
67
- //console.log(`The ${mutation.attributeName} attribute was modified.`);
67
+ const { target } = mutation;
68
+ this.#inspectNewNode(target);
68
69
  }
69
70
  }
70
71
  };
package/beatify.js CHANGED
@@ -1,57 +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 = btoa(el.getAttribute(attr).trim());
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
- }
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 = btoa(el.getAttribute(attr).trim());
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.109",
3
+ "version": "0.0.110",
4
4
  "keywords": [
5
5
  "web-components",
6
6
  "web-component",