mount-observer 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/package.json +3 -3
- package/refid/ism.js +21 -18
- package/refid/ism.ts +21 -17
- package/ts-refs/be-parsing/types.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.109",
|
|
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.
|
|
9
|
-
"spa-ssi": "0.0.
|
|
8
|
+
"@playwright/test": "1.56.1",
|
|
9
|
+
"spa-ssi": "0.0.25"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
package/refid/ism.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { upShadowSearch } from '../upShadowSearch.js';
|
|
2
2
|
import { stdVal } from './stdVal.js';
|
|
3
|
-
Object.defineProperty(HTMLElement.prototype, '
|
|
3
|
+
Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
4
4
|
get() {
|
|
5
5
|
const el = this;
|
|
6
|
+
if (!el.hasAttribute('itemscope'))
|
|
7
|
+
return;
|
|
6
8
|
return parse(el);
|
|
7
9
|
}
|
|
8
10
|
});
|
|
9
|
-
const
|
|
10
|
-
export function parse(el, obj = {}) {
|
|
11
|
+
const parsedItempropMaps = new WeakMap();
|
|
12
|
+
export function parse(el, obj = {}, scopedLists = {}) {
|
|
11
13
|
const itemprop = el.getAttribute('itemprop');
|
|
12
14
|
if (itemprop) {
|
|
13
15
|
obj[itemprop] = stdVal(el); //TODO full logic
|
|
@@ -18,10 +20,10 @@ export function parse(el, obj = {}) {
|
|
|
18
20
|
const jsonEl = upShadowSearch(el, itempropmap);
|
|
19
21
|
if (!jsonEl)
|
|
20
22
|
throw 500;
|
|
21
|
-
if (!
|
|
22
|
-
|
|
23
|
+
if (!parsedItempropMaps.has(jsonEl)) {
|
|
24
|
+
parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
|
|
23
25
|
}
|
|
24
|
-
const parsed = /** @type {ItemPropMap} */ (
|
|
26
|
+
const parsed = /** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
|
|
25
27
|
for (const key in parsed) {
|
|
26
28
|
const attr = el.getAttribute(key);
|
|
27
29
|
if (attr === null)
|
|
@@ -50,23 +52,24 @@ export function parse(el, obj = {}) {
|
|
|
50
52
|
}
|
|
51
53
|
//el.ish = obj;
|
|
52
54
|
const children = Array.from(el.children);
|
|
53
|
-
const isItemScoped = el.hasAttribute('itemscope');
|
|
54
|
-
let
|
|
55
|
-
if (isItemScoped) {
|
|
56
|
-
itemscopeMap = {};
|
|
57
|
-
}
|
|
55
|
+
//const isItemScoped = el.hasAttribute('itemscope');
|
|
56
|
+
let itemscopeMapToPass = scopedLists;
|
|
58
57
|
for (const child of children) {
|
|
59
58
|
if (!(child instanceof HTMLElement))
|
|
60
59
|
continue;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const childHasItemScopeAttr = child.hasAttribute('itemscope');
|
|
61
|
+
const objToPass = childHasItemScopeAttr ? {} : obj;
|
|
62
|
+
if (childHasItemScopeAttr) {
|
|
63
|
+
itemscopeMapToPass = {};
|
|
64
|
+
}
|
|
65
|
+
parse(child, objToPass, itemscopeMapToPass);
|
|
66
|
+
const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
64
67
|
if (isItemScopeAndChildHasBothItempropAndItemscope) {
|
|
65
68
|
const itemprops = child.getAttribute('itemprop').split(" ").filter(x => x);
|
|
66
69
|
for (const itemprop of itemprops) {
|
|
67
|
-
if (!
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
if (!scopedLists[itemprop])
|
|
71
|
+
scopedLists[itemprop] = [];
|
|
72
|
+
scopedLists[itemprop].push(objToPass);
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -75,6 +78,6 @@ export function parse(el, obj = {}) {
|
|
|
75
78
|
// }
|
|
76
79
|
return {
|
|
77
80
|
obj,
|
|
78
|
-
|
|
81
|
+
scopedLists
|
|
79
82
|
};
|
|
80
83
|
}
|
package/refid/ism.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import {upShadowSearch} from '../upShadowSearch.js';
|
|
2
2
|
import {stdVal} from './stdVal.js';
|
|
3
3
|
|
|
4
|
-
Object.defineProperty(HTMLElement.prototype, '
|
|
4
|
+
Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
5
5
|
get(){
|
|
6
6
|
const el = this as HTMLElement;
|
|
7
|
+
if(!el.hasAttribute('itemscope')) return;
|
|
7
8
|
return parse(el);
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
type ScopedLists = {[key: string] : any[]}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
const parsedItempropMaps = new WeakMap<HTMLScriptElement, any>();
|
|
15
|
+
|
|
16
|
+
export function parse(el: HTMLElement, obj: any = {}, scopedLists: ScopedLists = {}){
|
|
14
17
|
const itemprop = el.getAttribute('itemprop');
|
|
15
18
|
if(itemprop){
|
|
16
19
|
obj[itemprop] = stdVal(el); //TODO full logic
|
|
@@ -20,10 +23,10 @@ export function parse(el: HTMLElement, obj: any = {}){
|
|
|
20
23
|
//const el = document.getElementById(itempropmap);
|
|
21
24
|
const jsonEl = upShadowSearch(el, itempropmap)
|
|
22
25
|
if(!jsonEl) throw 500;
|
|
23
|
-
if(!
|
|
24
|
-
|
|
26
|
+
if(!parsedItempropMaps.has(jsonEl)){
|
|
27
|
+
parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
|
|
25
28
|
}
|
|
26
|
-
const parsed =/** @type {ItemPropMap} */ (
|
|
29
|
+
const parsed =/** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
|
|
27
30
|
for(const key in parsed){
|
|
28
31
|
const attr = el.getAttribute(key);
|
|
29
32
|
if(attr === null) continue;
|
|
@@ -54,21 +57,22 @@ export function parse(el: HTMLElement, obj: any = {}){
|
|
|
54
57
|
}
|
|
55
58
|
//el.ish = obj;
|
|
56
59
|
const children = Array.from(el.children);
|
|
57
|
-
const isItemScoped = el.hasAttribute('itemscope');
|
|
58
|
-
let
|
|
59
|
-
if(isItemScoped){
|
|
60
|
-
itemscopeMap = {};
|
|
61
|
-
}
|
|
60
|
+
//const isItemScoped = el.hasAttribute('itemscope');
|
|
61
|
+
let itemscopeMapToPass = scopedLists;
|
|
62
62
|
for(const child of children){
|
|
63
63
|
if(!(child instanceof HTMLElement)) continue;
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const childHasItemScopeAttr = child.hasAttribute('itemscope')
|
|
65
|
+
const objToPass = childHasItemScopeAttr ? {} : obj;
|
|
66
|
+
if(childHasItemScopeAttr) {
|
|
67
|
+
itemscopeMapToPass = {};
|
|
68
|
+
}
|
|
69
|
+
parse(child, objToPass, itemscopeMapToPass);
|
|
70
|
+
const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
67
71
|
if(isItemScopeAndChildHasBothItempropAndItemscope){
|
|
68
72
|
const itemprops = child.getAttribute('itemprop')!.split(" ").filter(x => x);
|
|
69
73
|
for(const itemprop of itemprops){
|
|
70
|
-
if(!
|
|
71
|
-
|
|
74
|
+
if(!scopedLists![itemprop]) scopedLists![itemprop] = [];
|
|
75
|
+
scopedLists![itemprop].push(objToPass);
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
}
|
|
@@ -77,6 +81,6 @@ export function parse(el: HTMLElement, obj: any = {}){
|
|
|
77
81
|
// }
|
|
78
82
|
return {
|
|
79
83
|
obj,
|
|
80
|
-
|
|
84
|
+
scopedLists
|
|
81
85
|
};
|
|
82
86
|
}
|