be-hive 0.0.107 → 0.0.109

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/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 = el.getAttribute(attr).replaceAll('\n', '');
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/getLocalName.js CHANGED
@@ -1,24 +1,24 @@
1
- export function getLocalName(peerCitizen, decoratorName) {
2
- return new Promise((resolve, reject) => {
3
- const rn = peerCitizen.getRootNode();
4
- const bh = rn.querySelector('be-hive');
5
- if (bh === null) {
6
- reject('404');
7
- return;
8
- }
9
- const wc = bh.querySelector(decoratorName);
10
- if (wc !== null) {
11
- resolve(bh.ifWantsToBe);
12
- return;
13
- }
14
- const controller = new AbortController();
15
- bh.addEventListener('latest-behavior-changed', e => {
16
- const detail = e.detail;
17
- const { localName, ifWantsToBe } = detail.value;
18
- if (localName === decoratorName) {
19
- resolve(ifWantsToBe);
20
- controller.abort();
21
- }
22
- });
23
- });
24
- }
1
+ export function getLocalName(peerCitizen, decoratorName) {
2
+ return new Promise((resolve, reject) => {
3
+ const rn = peerCitizen.getRootNode();
4
+ const bh = rn.querySelector('be-hive');
5
+ if (bh === null) {
6
+ reject('404');
7
+ return;
8
+ }
9
+ const wc = bh.querySelector(decoratorName);
10
+ if (wc !== null) {
11
+ resolve(bh.ifWantsToBe);
12
+ return;
13
+ }
14
+ const controller = new AbortController();
15
+ bh.addEventListener('latest-behavior-changed', e => {
16
+ const detail = e.detail;
17
+ const { localName, ifWantsToBe } = detail.value;
18
+ if (localName === decoratorName) {
19
+ resolve(ifWantsToBe);
20
+ controller.abort();
21
+ }
22
+ });
23
+ });
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "be-hive",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
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.31"
29
+ "be-enhanced": "0.0.33"
30
30
  },
31
31
  "devDependencies": {
32
32
  "may-it-serve": "0.0.5"
package/types.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import {BeDecoratedProps} from 'be-decorated/types';
2
-
3
1
  export interface BehaviorKeys {
4
2
  ifWantsToBe: string,
5
3
  upgrade: string,