mount-observer 0.0.107 → 0.0.108
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 +11 -8
- package/refid/ism.ts +12 -8
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.108",
|
|
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
11
|
const parsedItempropmaps = new WeakMap();
|
|
10
|
-
export function parse(el, obj = {}) {
|
|
12
|
+
export function parse(el, obj = {}, itemscopeMap = {}) {
|
|
11
13
|
const itemprop = el.getAttribute('itemprop');
|
|
12
14
|
if (itemprop) {
|
|
13
15
|
obj[itemprop] = stdVal(el); //TODO full logic
|
|
@@ -51,15 +53,16 @@ export function parse(el, obj = {}) {
|
|
|
51
53
|
//el.ish = obj;
|
|
52
54
|
const children = Array.from(el.children);
|
|
53
55
|
const isItemScoped = el.hasAttribute('itemscope');
|
|
54
|
-
let itemscopeMap;
|
|
55
|
-
if (isItemScoped) {
|
|
56
|
-
itemscopeMap = {};
|
|
57
|
-
}
|
|
56
|
+
let itemscopeMapToPass = itemscopeMap;
|
|
58
57
|
for (const child of children) {
|
|
59
58
|
if (!(child instanceof HTMLElement))
|
|
60
59
|
continue;
|
|
61
|
-
const
|
|
62
|
-
|
|
60
|
+
const childHasItemScopeAttr = child.hasAttribute('itemscope');
|
|
61
|
+
const objToPass = childHasItemScopeAttr ? {} : obj;
|
|
62
|
+
if (childHasItemScopeAttr) {
|
|
63
|
+
itemscopeMapToPass = {};
|
|
64
|
+
}
|
|
65
|
+
parse(child, objToPass, itemscopeMapToPass);
|
|
63
66
|
const isItemScopeAndChildHasBothItempropAndItemscope = itemscopeMap && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
64
67
|
if (isItemScopeAndChildHasBothItempropAndItemscope) {
|
|
65
68
|
const itemprops = child.getAttribute('itemprop').split(" ").filter(x => x);
|
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
|
|
|
12
|
+
type ItemscopeMap = {[key: string] : any[]}
|
|
13
|
+
|
|
11
14
|
const parsedItempropmaps = new WeakMap<HTMLScriptElement, any>();
|
|
12
15
|
|
|
13
|
-
export function parse(el: HTMLElement, obj: any = {}){
|
|
16
|
+
export function parse(el: HTMLElement, obj: any = {}, itemscopeMap: ItemscopeMap = {}){
|
|
14
17
|
const itemprop = el.getAttribute('itemprop');
|
|
15
18
|
if(itemprop){
|
|
16
19
|
obj[itemprop] = stdVal(el); //TODO full logic
|
|
@@ -55,14 +58,15 @@ export function parse(el: HTMLElement, obj: any = {}){
|
|
|
55
58
|
//el.ish = obj;
|
|
56
59
|
const children = Array.from(el.children);
|
|
57
60
|
const isItemScoped = el.hasAttribute('itemscope');
|
|
58
|
-
let
|
|
59
|
-
if(isItemScoped){
|
|
60
|
-
itemscopeMap = {};
|
|
61
|
-
}
|
|
61
|
+
let itemscopeMapToPass = itemscopeMap;
|
|
62
62
|
for(const child of children){
|
|
63
63
|
if(!(child instanceof HTMLElement)) continue;
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const childHasItemScopeAttr = child.hasAttribute('itemscope')
|
|
65
|
+
const objToPass = childHasItemScopeAttr ? {} : obj;
|
|
66
|
+
if(childHasItemScopeAttr) {
|
|
67
|
+
itemscopeMapToPass = {};
|
|
68
|
+
}
|
|
69
|
+
parse(child, objToPass, itemscopeMapToPass);
|
|
66
70
|
const isItemScopeAndChildHasBothItempropAndItemscope = itemscopeMap && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
67
71
|
if(isItemScopeAndChildHasBothItempropAndItemscope){
|
|
68
72
|
const itemprops = child.getAttribute('itemprop')!.split(" ").filter(x => x);
|