mount-observer 0.0.108 → 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.
- package/package.json +2 -2
- package/refid/ism.js +17 -22
- package/refid/ism.ts +17 -22
- package/ts-refs/be-parsing/types.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.110",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"@playwright/test": "1.
|
|
8
|
+
"@playwright/test": "1.57.0",
|
|
9
9
|
"spa-ssi": "0.0.25"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
package/refid/ism.js
CHANGED
|
@@ -8,11 +8,11 @@ Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
|
8
8
|
return parse(el);
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
export function parse(el,
|
|
11
|
+
const parsedItempropMaps = new WeakMap();
|
|
12
|
+
export function parse(el, scope = {}, scopedLists = {}) {
|
|
13
13
|
const itemprop = el.getAttribute('itemprop');
|
|
14
14
|
if (itemprop) {
|
|
15
|
-
|
|
15
|
+
scope[itemprop] = stdVal(el); //TODO full logic
|
|
16
16
|
}
|
|
17
17
|
const itempropmap = el.getAttribute('itempropmap');
|
|
18
18
|
if (itempropmap) {
|
|
@@ -20,10 +20,10 @@ export function parse(el, obj = {}, itemscopeMap = {}) {
|
|
|
20
20
|
const jsonEl = upShadowSearch(el, itempropmap);
|
|
21
21
|
if (!jsonEl)
|
|
22
22
|
throw 500;
|
|
23
|
-
if (!
|
|
24
|
-
|
|
23
|
+
if (!parsedItempropMaps.has(jsonEl)) {
|
|
24
|
+
parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
|
|
25
25
|
}
|
|
26
|
-
const parsed = /** @type {ItemPropMap} */ (
|
|
26
|
+
const parsed = /** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
|
|
27
27
|
for (const key in parsed) {
|
|
28
28
|
const attr = el.getAttribute(key);
|
|
29
29
|
if (attr === null)
|
|
@@ -31,53 +31,48 @@ export function parse(el, obj = {}, itemscopeMap = {}) {
|
|
|
31
31
|
const rhs = parsed[key];
|
|
32
32
|
switch (typeof rhs) {
|
|
33
33
|
case 'string':
|
|
34
|
-
|
|
34
|
+
scope[rhs] = attr;
|
|
35
35
|
break;
|
|
36
36
|
case 'object':
|
|
37
37
|
const { instanceOf, mapsTo } = rhs;
|
|
38
38
|
switch (instanceOf) {
|
|
39
39
|
case 'Number':
|
|
40
40
|
case Number:
|
|
41
|
-
|
|
41
|
+
scope[mapsTo] = Number(attr);
|
|
42
42
|
break;
|
|
43
43
|
case 'Object':
|
|
44
44
|
case Object:
|
|
45
45
|
case 'Boolean':
|
|
46
46
|
case Boolean:
|
|
47
|
-
|
|
47
|
+
scope[mapsTo] = JSON.parse(attr);
|
|
48
48
|
break;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
//el.ish = obj;
|
|
54
53
|
const children = Array.from(el.children);
|
|
55
|
-
|
|
56
|
-
let itemscopeMapToPass = itemscopeMap;
|
|
54
|
+
let itemscopeMapToPass = scopedLists;
|
|
57
55
|
for (const child of children) {
|
|
58
56
|
if (!(child instanceof HTMLElement))
|
|
59
57
|
continue;
|
|
60
58
|
const childHasItemScopeAttr = child.hasAttribute('itemscope');
|
|
61
|
-
const objToPass = childHasItemScopeAttr ? {} :
|
|
59
|
+
const objToPass = childHasItemScopeAttr ? {} : scope;
|
|
62
60
|
if (childHasItemScopeAttr) {
|
|
63
61
|
itemscopeMapToPass = {};
|
|
64
62
|
}
|
|
65
63
|
parse(child, objToPass, itemscopeMapToPass);
|
|
66
|
-
const isItemScopeAndChildHasBothItempropAndItemscope =
|
|
64
|
+
const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
67
65
|
if (isItemScopeAndChildHasBothItempropAndItemscope) {
|
|
68
66
|
const itemprops = child.getAttribute('itemprop').split(" ").filter(x => x);
|
|
69
67
|
for (const itemprop of itemprops) {
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
if (!scopedLists[itemprop])
|
|
69
|
+
scopedLists[itemprop] = [];
|
|
70
|
+
scopedLists[itemprop].push(objToPass);
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
|
-
// if(itemscopeMap){
|
|
77
|
-
// el.ism = itemscopeMap;
|
|
78
|
-
// }
|
|
79
74
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
scope,
|
|
76
|
+
scopedLists
|
|
82
77
|
};
|
|
83
78
|
}
|
package/refid/ism.ts
CHANGED
|
@@ -9,44 +9,44 @@ Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
type
|
|
12
|
+
type ScopedLists = {[key: string] : any[]}
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const parsedItempropMaps = new WeakMap<HTMLScriptElement, any>();
|
|
15
15
|
|
|
16
|
-
export function parse(el: HTMLElement,
|
|
16
|
+
export function parse(el: HTMLElement, scope: any = {}, scopedLists: ScopedLists = {}){
|
|
17
17
|
const itemprop = el.getAttribute('itemprop');
|
|
18
18
|
if(itemprop){
|
|
19
|
-
|
|
19
|
+
scope[itemprop] = stdVal(el); //TODO full logic
|
|
20
20
|
}
|
|
21
21
|
const itempropmap = el.getAttribute('itempropmap');
|
|
22
22
|
if(itempropmap){
|
|
23
23
|
//const el = document.getElementById(itempropmap);
|
|
24
24
|
const jsonEl = upShadowSearch(el, itempropmap)
|
|
25
25
|
if(!jsonEl) throw 500;
|
|
26
|
-
if(!
|
|
27
|
-
|
|
26
|
+
if(!parsedItempropMaps.has(jsonEl)){
|
|
27
|
+
parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
|
|
28
28
|
}
|
|
29
|
-
const parsed =/** @type {ItemPropMap} */ (
|
|
29
|
+
const parsed =/** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
|
|
30
30
|
for(const key in parsed){
|
|
31
31
|
const attr = el.getAttribute(key);
|
|
32
32
|
if(attr === null) continue;
|
|
33
33
|
const rhs = parsed[key];
|
|
34
34
|
switch(typeof rhs){
|
|
35
35
|
case 'string':
|
|
36
|
-
|
|
36
|
+
scope[rhs] = attr;
|
|
37
37
|
break;
|
|
38
38
|
case 'object':
|
|
39
39
|
const {instanceOf, mapsTo} = rhs;
|
|
40
40
|
switch(instanceOf){
|
|
41
41
|
case 'Number':
|
|
42
42
|
case Number:
|
|
43
|
-
|
|
43
|
+
scope[mapsTo] = Number(attr);
|
|
44
44
|
break;
|
|
45
45
|
case 'Object':
|
|
46
46
|
case Object:
|
|
47
47
|
case 'Boolean':
|
|
48
48
|
case Boolean:
|
|
49
|
-
|
|
49
|
+
scope[mapsTo] = JSON.parse(attr);
|
|
50
50
|
break;
|
|
51
51
|
|
|
52
52
|
|
|
@@ -55,32 +55,27 @@ export function parse(el: HTMLElement, obj: any = {}, itemscopeMap: ItemscopeMap
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
}
|
|
58
|
-
//el.ish = obj;
|
|
59
58
|
const children = Array.from(el.children);
|
|
60
|
-
|
|
61
|
-
let itemscopeMapToPass = itemscopeMap;
|
|
59
|
+
let itemscopeMapToPass = scopedLists;
|
|
62
60
|
for(const child of children){
|
|
63
61
|
if(!(child instanceof HTMLElement)) continue;
|
|
64
62
|
const childHasItemScopeAttr = child.hasAttribute('itemscope')
|
|
65
|
-
const objToPass = childHasItemScopeAttr ? {} :
|
|
63
|
+
const objToPass = childHasItemScopeAttr ? {} : scope;
|
|
66
64
|
if(childHasItemScopeAttr) {
|
|
67
65
|
itemscopeMapToPass = {};
|
|
68
66
|
}
|
|
69
67
|
parse(child, objToPass, itemscopeMapToPass);
|
|
70
|
-
const isItemScopeAndChildHasBothItempropAndItemscope =
|
|
68
|
+
const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
71
69
|
if(isItemScopeAndChildHasBothItempropAndItemscope){
|
|
72
70
|
const itemprops = child.getAttribute('itemprop')!.split(" ").filter(x => x);
|
|
73
71
|
for(const itemprop of itemprops){
|
|
74
|
-
if(!
|
|
75
|
-
|
|
72
|
+
if(!scopedLists![itemprop]) scopedLists![itemprop] = [];
|
|
73
|
+
scopedLists![itemprop].push(objToPass);
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
|
-
// if(itemscopeMap){
|
|
80
|
-
// el.ism = itemscopeMap;
|
|
81
|
-
// }
|
|
82
77
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
scope,
|
|
79
|
+
scopedLists
|
|
85
80
|
};
|
|
86
81
|
}
|