mount-observer 0.0.111 → 0.1.0
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/Events.js +28 -26
- package/Events.ts +34 -30
- package/MountObserver.js +235 -520
- package/MountObserver.ts +281 -542
- package/README.md +149 -56
- package/attrCoordinates.js +93 -0
- package/attrCoordinates.ts +122 -0
- package/constants.js +6 -0
- package/constants.ts +7 -0
- package/index.js +3 -0
- package/index.ts +19 -0
- package/loadImports.js +47 -0
- package/loadImports.ts +56 -0
- package/package.json +8 -115
- package/playwright.config.ts +0 -1
- package/types.d.ts +86 -0
- package/whereAttr.js +174 -0
- package/whereAttr.ts +221 -0
- package/LICENSE +0 -21
- package/Newish.js +0 -145
- package/Newish.ts +0 -169
- package/ObsAttr.js +0 -18
- package/ObsAttr.ts +0 -18
- package/RootMutObs.js +0 -49
- package/RootMutObs.ts +0 -58
- package/Synthesizer.js +0 -125
- package/Synthesizer.ts +0 -130
- package/bindish.js +0 -15
- package/bindish.ts +0 -22
- package/compose.js +0 -148
- package/compose.ts +0 -164
- package/doCleanup.js +0 -31
- package/doCleanup.ts +0 -34
- package/getWhereAttrSelector.js +0 -83
- package/getWhereAttrSelector.ts +0 -92
- package/preloadContent.js +0 -44
- package/preloadContent.ts +0 -47
- package/readAttrs.ts +0 -60
- package/refid/README.md +0 -259
- package/refid/arr.js +0 -4
- package/refid/arr.ts +0 -4
- package/refid/camelToKebab.js +0 -4
- package/refid/camelToKebab.ts +0 -4
- package/refid/genIds.js +0 -190
- package/refid/genIds.ts +0 -177
- package/refid/getAdjRefs.js +0 -38
- package/refid/getAdjRefs.ts +0 -38
- package/refid/getContext.js +0 -13
- package/refid/getContext.ts +0 -14
- package/refid/getCount.js +0 -8
- package/refid/getCount.ts +0 -8
- package/refid/getIsh.js +0 -35
- package/refid/getIsh.ts +0 -37
- package/refid/hostish.js +0 -18
- package/refid/hostish.ts +0 -20
- package/refid/ism.js +0 -78
- package/refid/ism.ts +0 -81
- package/refid/itemprops.js +0 -60
- package/refid/itemprops.ts +0 -67
- package/refid/joinMatching.js +0 -56
- package/refid/joinMatching.ts +0 -54
- package/refid/nudge.js +0 -23
- package/refid/nudge.ts +0 -23
- package/refid/regIsh.js +0 -27
- package/refid/regIsh.ts +0 -31
- package/refid/secretKeys.js +0 -5
- package/refid/secretKeys.ts +0 -5
- package/refid/splitRefs.js +0 -6
- package/refid/splitRefs.ts +0 -6
- package/refid/stdVal.js +0 -15
- package/refid/stdVal.ts +0 -15
- package/refid/via.js +0 -114
- package/refid/via.ts +0 -113
- package/slotkin/affine.js +0 -39
- package/slotkin/affine.ts +0 -46
- package/slotkin/beKindred.js +0 -45
- package/slotkin/beKindred.ts +0 -55
- package/slotkin/getBreadth.js +0 -19
- package/slotkin/getBreadth.ts +0 -21
- package/slotkin/getFrag.js +0 -22
- package/slotkin/getFrag.ts +0 -21
- package/slotkin/toQuery.js +0 -12
- package/slotkin/toQuery.ts +0 -13
- package/slotkin/wrap.js +0 -13
- package/slotkin/wrap.ts +0 -18
- package/ts-refs/LICENSE +0 -21
- package/ts-refs/README.md +0 -18
- package/ts-refs/be-a-beacon/types.d.ts +0 -22
- package/ts-refs/be-alit/types.d.ts +0 -1
- package/ts-refs/be-based/types.d.ts +0 -32
- package/ts-refs/be-bound/types.d.ts +0 -65
- package/ts-refs/be-buttoned-up/types.d.ts +0 -21
- package/ts-refs/be-calculating/types.d.ts +0 -57
- package/ts-refs/be-clonable/types.d.ts +0 -28
- package/ts-refs/be-committed/types.d.ts +0 -26
- package/ts-refs/be-consoling/types.d.ts +0 -25
- package/ts-refs/be-counted/types.d.ts +0 -88
- package/ts-refs/be-delible/types.d.ts +0 -26
- package/ts-refs/be-directive/types.d.ts +0 -43
- package/ts-refs/be-dispatching/types.d.ts +0 -41
- package/ts-refs/be-elevating/types.d.ts +0 -55
- package/ts-refs/be-enhanced/types.d.ts +0 -32
- package/ts-refs/be-enhancing/types.d.ts +0 -31
- package/ts-refs/be-evanescent/types.d.ts +0 -20
- package/ts-refs/be-eventing/types.d.ts +0 -27
- package/ts-refs/be-exportable/types.d.ts +0 -26
- package/ts-refs/be-fetching/types.d.ts +0 -73
- package/ts-refs/be-flashy/types.d.ts +0 -27
- package/ts-refs/be-formalizing/types.d.ts +0 -29
- package/ts-refs/be-formidable/types.d.ts +0 -64
- package/ts-refs/be-giddy/types.d.ts +0 -26
- package/ts-refs/be-gingerly/types.d.ts +0 -19
- package/ts-refs/be-gone/types.d.ts +0 -24
- package/ts-refs/be-hashing-out/types.d.ts +0 -22
- package/ts-refs/be-hive/types.d.ts +0 -18
- package/ts-refs/be-imbued/types.d.ts +0 -30
- package/ts-refs/be-included/types.d.ts +0 -20
- package/ts-refs/be-inclusive/types.d.ts +0 -30
- package/ts-refs/be-intersectional/types.d.ts +0 -37
- package/ts-refs/be-intl/types.d.ts +0 -28
- package/ts-refs/be-invoking/types.d.ts +0 -28
- package/ts-refs/be-joining/types.d.ts +0 -26
- package/ts-refs/be-kvetching/types.d.ts +0 -24
- package/ts-refs/be-lazy/types.d.ts +0 -29
- package/ts-refs/be-literate/types.d.ts +0 -29
- package/ts-refs/be-mediating/types.d.ts +0 -34
- package/ts-refs/be-methodical/types.d.ts +0 -20
- package/ts-refs/be-modding/types.d.ts +0 -18
- package/ts-refs/be-observant/types.d.ts +0 -27
- package/ts-refs/be-observing/types.d.ts +0 -84
- package/ts-refs/be-parsed/types.d.ts +0 -19
- package/ts-refs/be-parsing/types.d.ts +0 -37
- package/ts-refs/be-persistent/types.d.ts +0 -66
- package/ts-refs/be-propagating/types.d.ts +0 -26
- package/ts-refs/be-reformable/types.d.ts +0 -48
- package/ts-refs/be-render-neutral/types.d.ts +0 -31
- package/ts-refs/be-scoped/types.d.ts +0 -24
- package/ts-refs/be-sharing/types.d.ts +0 -17
- package/ts-refs/be-switched/types.d.ts +0 -155
- package/ts-refs/be-typed/types.d.ts +0 -36
- package/ts-refs/be-value-added/types.d.ts +0 -34
- package/ts-refs/be-valued/types.d.ts +0 -22
- package/ts-refs/be-written/types.d.ts +0 -59
- package/ts-refs/css-charts/types.d.ts +0 -38
- package/ts-refs/css-echarts/types.d.ts +0 -13
- package/ts-refs/data-props/types.d.ts +0 -27
- package/ts-refs/do-inc/types.d.ts +0 -28
- package/ts-refs/do-invoke/types.d.ts +0 -28
- package/ts-refs/do-toggle/types.d.ts +0 -27
- package/ts-refs/em-bower/types.d.ts +0 -18
- package/ts-refs/fetch-for/types.d.ts +0 -37
- package/ts-refs/folder-picker/types.d.ts +0 -43
- package/ts-refs/for-fetch/doc.d.ts +0 -98
- package/ts-refs/for-fetch/types.d.ts +0 -83
- package/ts-refs/mount-observer/types.d.ts +0 -248
- package/ts-refs/mt-si/types.d.ts +0 -21
- package/ts-refs/per-each/types.d.ts +0 -51
- package/ts-refs/soak-up/types.d.ts +0 -36
- package/ts-refs/trans-render/XV/types.d.ts +0 -69
- package/ts-refs/trans-render/asmr/types.d.ts +0 -138
- package/ts-refs/trans-render/be/types.d.ts +0 -190
- package/ts-refs/trans-render/dss/types.d.ts +0 -57
- package/ts-refs/trans-render/froop/types.d.ts +0 -416
- package/ts-refs/trans-render/funions/types.d.ts +0 -12
- package/ts-refs/trans-render/lib/mixins/types.d.ts +0 -42
- package/ts-refs/trans-render/lib/prs/types.d.ts +0 -40
- package/ts-refs/trans-render/lib/types.d.ts +0 -489
- package/ts-refs/trans-render/types.d.ts +0 -583
- package/ts-refs/wc-info/SimpleWCInfo.d.ts +0 -15
- package/ts-refs/when-resolved/types.d.ts +0 -30
- package/ts-refs/xp-as/types.d.ts +0 -20
- package/ts-refs/xtal-element/types.d.ts +0 -43
- package/ts-refs/xtal-frappe-chart/types.d.ts +0 -193
- package/upShadowSearch.js +0 -25
- package/upShadowSearch.ts +0 -23
- package/waitForEvent.js +0 -12
- package/waitForEvent.ts +0 -13
- package/waitForIsh.js +0 -21
- package/waitForIsh.ts +0 -20
package/refid/ism.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {upShadowSearch} from '../upShadowSearch.js';
|
|
2
|
-
import {stdVal} from './stdVal.js';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
5
|
-
get(){
|
|
6
|
-
const el = this as HTMLElement;
|
|
7
|
-
if(!el.hasAttribute('itemscope')) return;
|
|
8
|
-
return parse(el);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
type ScopedLists = {[key: string] : any[]}
|
|
13
|
-
|
|
14
|
-
const parsedItempropMaps = new WeakMap<HTMLScriptElement, any>();
|
|
15
|
-
|
|
16
|
-
export function parse(el: HTMLElement, scope: any = {}, scopedLists: ScopedLists = {}){
|
|
17
|
-
const itemprop = el.getAttribute('itemprop');
|
|
18
|
-
if(itemprop){
|
|
19
|
-
scope[itemprop] = stdVal(el); //TODO full logic
|
|
20
|
-
}
|
|
21
|
-
const itempropmap = el.getAttribute('itempropmap');
|
|
22
|
-
if(itempropmap){
|
|
23
|
-
//const el = document.getElementById(itempropmap);
|
|
24
|
-
const jsonEl = upShadowSearch(el, itempropmap)
|
|
25
|
-
if(!jsonEl) throw 500;
|
|
26
|
-
if(!parsedItempropMaps.has(jsonEl)){
|
|
27
|
-
parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
|
|
28
|
-
}
|
|
29
|
-
const parsed =/** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
|
|
30
|
-
for(const key in parsed){
|
|
31
|
-
const attr = el.getAttribute(key);
|
|
32
|
-
if(attr === null) continue;
|
|
33
|
-
const rhs = parsed[key];
|
|
34
|
-
switch(typeof rhs){
|
|
35
|
-
case 'string':
|
|
36
|
-
scope[rhs] = attr;
|
|
37
|
-
break;
|
|
38
|
-
case 'object':
|
|
39
|
-
const {instanceOf, mapsTo} = rhs;
|
|
40
|
-
switch(instanceOf){
|
|
41
|
-
case 'Number':
|
|
42
|
-
case Number:
|
|
43
|
-
scope[mapsTo] = Number(attr);
|
|
44
|
-
break;
|
|
45
|
-
case 'Object':
|
|
46
|
-
case Object:
|
|
47
|
-
case 'Boolean':
|
|
48
|
-
case Boolean:
|
|
49
|
-
scope[mapsTo] = JSON.parse(attr);
|
|
50
|
-
break;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
const children = Array.from(el.children);
|
|
59
|
-
let itemscopeMapToPass = scopedLists;
|
|
60
|
-
for(const child of children){
|
|
61
|
-
if(!(child instanceof HTMLElement)) continue;
|
|
62
|
-
const childHasItemScopeAttr = child.hasAttribute('itemscope')
|
|
63
|
-
const objToPass = childHasItemScopeAttr ? {} : scope;
|
|
64
|
-
if(childHasItemScopeAttr) {
|
|
65
|
-
itemscopeMapToPass = {};
|
|
66
|
-
}
|
|
67
|
-
parse(child, objToPass, itemscopeMapToPass);
|
|
68
|
-
const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
69
|
-
if(isItemScopeAndChildHasBothItempropAndItemscope){
|
|
70
|
-
const itemprops = child.getAttribute('itemprop')!.split(" ").filter(x => x);
|
|
71
|
-
for(const itemprop of itemprops){
|
|
72
|
-
if(!scopedLists![itemprop]) scopedLists![itemprop] = [];
|
|
73
|
-
scopedLists![itemprop].push(objToPass);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
scope,
|
|
79
|
-
scopedLists
|
|
80
|
-
};
|
|
81
|
-
}
|
package/refid/itemprops.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function getFirst(element, prop) {
|
|
3
|
-
for (const child of element.children) {
|
|
4
|
-
const itemprop = child.getAttribute('itemprop');
|
|
5
|
-
if (itemprop === prop) {
|
|
6
|
-
return child;
|
|
7
|
-
}
|
|
8
|
-
if (!child.hasAttribute('itemscope')) {
|
|
9
|
-
const found = getFirst(child, prop);
|
|
10
|
-
if (found)
|
|
11
|
-
return found;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
const proxies = new WeakMap();
|
|
17
|
-
const refLookup = new WeakMap();
|
|
18
|
-
Object.defineProperty(Element.prototype, 'itemprops', {
|
|
19
|
-
get() {
|
|
20
|
-
if (!proxies.has(this)) {
|
|
21
|
-
const handler = {
|
|
22
|
-
get(target, prop) {
|
|
23
|
-
let lookup;
|
|
24
|
-
if (refLookup.has(target)) {
|
|
25
|
-
lookup = refLookup.get(target);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
lookup = new Map();
|
|
29
|
-
refLookup.set(target, lookup);
|
|
30
|
-
}
|
|
31
|
-
if (lookup.has(prop)) {
|
|
32
|
-
return lookup.get(prop);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
const propManager = new ItempropManager(target, prop);
|
|
36
|
-
lookup.set(prop, propManager);
|
|
37
|
-
return propManager;
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
proxies.set(this, new Proxy(this, handler));
|
|
42
|
-
}
|
|
43
|
-
return proxies.get(this);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
class ItempropManager extends EventTarget {
|
|
47
|
-
#el;
|
|
48
|
-
#prop;
|
|
49
|
-
constructor(el, prop) {
|
|
50
|
-
super();
|
|
51
|
-
this.#el = new WeakRef(el);
|
|
52
|
-
this.#prop = prop;
|
|
53
|
-
}
|
|
54
|
-
get first() {
|
|
55
|
-
const el = this.#el.deref();
|
|
56
|
-
if (el === undefined)
|
|
57
|
-
return null;
|
|
58
|
-
return getFirst(el, this.#prop);
|
|
59
|
-
}
|
|
60
|
-
}
|
package/refid/itemprops.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
function getFirst(element: Element, prop: string): Element | null {
|
|
2
|
-
for(const child of element.children){
|
|
3
|
-
const itemprop = child.getAttribute('itemprop');
|
|
4
|
-
if(itemprop === prop){
|
|
5
|
-
return child;
|
|
6
|
-
}
|
|
7
|
-
if(!child.hasAttribute('itemscope')){
|
|
8
|
-
const found = getFirst(child, prop);
|
|
9
|
-
if(found) return found;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const proxies = new WeakMap<Element, ProxyConstructor>();
|
|
15
|
-
const refLookup = new WeakMap<Element, PropManagerLookup>();
|
|
16
|
-
Object.defineProperty(Element.prototype, 'itemprops', {
|
|
17
|
-
|
|
18
|
-
get(){
|
|
19
|
-
if(!proxies.has(this)){
|
|
20
|
-
const handler = {
|
|
21
|
-
get(target: Element, prop: string) {
|
|
22
|
-
let lookup: PropManagerLookup;
|
|
23
|
-
if(refLookup.has(target)){
|
|
24
|
-
lookup = refLookup.get(target)!;
|
|
25
|
-
}else{
|
|
26
|
-
lookup = new Map<Prop, ItempropManager>();
|
|
27
|
-
refLookup.set(target, lookup);
|
|
28
|
-
}
|
|
29
|
-
if(lookup.has(prop)){
|
|
30
|
-
return lookup.get(prop);
|
|
31
|
-
}else{
|
|
32
|
-
const propManager = new ItempropManager(target, prop as string);
|
|
33
|
-
lookup.set(prop, propManager);
|
|
34
|
-
return propManager;
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
proxies.set(this, new Proxy(this, handler));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return proxies.get(this);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
type Prop = string;
|
|
48
|
-
|
|
49
|
-
type PropManagerLookup = Map<Prop, ItempropManager>;
|
|
50
|
-
|
|
51
|
-
class ItempropManager extends EventTarget {
|
|
52
|
-
#el: WeakRef<Element>;
|
|
53
|
-
#prop: Prop;
|
|
54
|
-
constructor(el: Element, prop: Prop){
|
|
55
|
-
super();
|
|
56
|
-
this.#el = new WeakRef(el);
|
|
57
|
-
this.#prop = prop;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get first(){
|
|
61
|
-
const el = this.#el.deref();
|
|
62
|
-
if(el === undefined) return null;
|
|
63
|
-
return getFirst(el, this.#prop);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
package/refid/joinMatching.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { camelToKebab } from './camelToKebab.js';
|
|
2
|
-
const proxies = new WeakMap();
|
|
3
|
-
Object.defineProperty(Element.prototype, 'joinMatching', {
|
|
4
|
-
get() {
|
|
5
|
-
if (!proxies.has(this)) {
|
|
6
|
-
const handler = {
|
|
7
|
-
get(target, prop) {
|
|
8
|
-
const jm = new JoinMatching(target, prop);
|
|
9
|
-
return jm;
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
proxies.set(this, new Proxy(this, handler));
|
|
13
|
-
}
|
|
14
|
-
return proxies.get(this);
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
export class JoinMatching {
|
|
18
|
-
#proxy;
|
|
19
|
-
elRef;
|
|
20
|
-
attr;
|
|
21
|
-
constructor(el, prop) {
|
|
22
|
-
this.elRef = new WeakRef(el);
|
|
23
|
-
this.attr = camelToKebab(prop);
|
|
24
|
-
}
|
|
25
|
-
get fromClosest() {
|
|
26
|
-
const handler = {
|
|
27
|
-
get(self, closestQry) {
|
|
28
|
-
const { elRef, attr } = self;
|
|
29
|
-
const el = elRef.deref();
|
|
30
|
-
if (el === undefined)
|
|
31
|
-
return [];
|
|
32
|
-
const attrVal = el.getAttribute(attr);
|
|
33
|
-
const tryClosestQry = camelToKebab(closestQry);
|
|
34
|
-
let closest = el.closest(tryClosestQry);
|
|
35
|
-
if (closest === null)
|
|
36
|
-
closest = el.closest(closestQry);
|
|
37
|
-
if (closest === null)
|
|
38
|
-
throw 404;
|
|
39
|
-
return Array.from(closest.querySelectorAll(`[${attr}="${attrVal}"]`));
|
|
40
|
-
//console.log({self, closestQry, prop, el});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
return new Proxy(this, handler);
|
|
44
|
-
}
|
|
45
|
-
get fromParent() {
|
|
46
|
-
const { elRef, attr } = this;
|
|
47
|
-
const el = elRef.deref();
|
|
48
|
-
if (el === undefined)
|
|
49
|
-
return [];
|
|
50
|
-
const { parentElement } = el;
|
|
51
|
-
if (parentElement === null)
|
|
52
|
-
return [];
|
|
53
|
-
const attrVal = el.getAttribute(attr);
|
|
54
|
-
return Array.from(parentElement.querySelectorAll(`[${attr}="${attrVal}"]`));
|
|
55
|
-
}
|
|
56
|
-
}
|
package/refid/joinMatching.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {camelToKebab} from './camelToKebab.js';
|
|
2
|
-
const proxies = new WeakMap<Element, ProxyConstructor>();
|
|
3
|
-
Object.defineProperty(Element.prototype, 'joinMatching', {
|
|
4
|
-
get(){
|
|
5
|
-
if(!proxies.has(this)){
|
|
6
|
-
const handler = {
|
|
7
|
-
get(target: Element, prop: string) {
|
|
8
|
-
const jm = new JoinMatching(target, prop);
|
|
9
|
-
return jm;
|
|
10
|
-
},
|
|
11
|
-
}
|
|
12
|
-
proxies.set(this, new Proxy(this, handler));
|
|
13
|
-
}
|
|
14
|
-
return proxies.get(this);
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export class JoinMatching {
|
|
19
|
-
#proxy: ProxyConstructor | undefined;
|
|
20
|
-
elRef: WeakRef<Element>;
|
|
21
|
-
attr: string;
|
|
22
|
-
constructor(el: Element, prop: string){
|
|
23
|
-
this.elRef = new WeakRef(el);
|
|
24
|
-
this.attr = camelToKebab(prop);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get fromClosest(){
|
|
28
|
-
const handler = {
|
|
29
|
-
get(self: JoinMatching, closestQry: string){
|
|
30
|
-
const {elRef, attr} = self;
|
|
31
|
-
const el = elRef.deref();
|
|
32
|
-
if(el === undefined) return [];
|
|
33
|
-
const attrVal = el.getAttribute(attr);
|
|
34
|
-
const tryClosestQry = camelToKebab(closestQry);
|
|
35
|
-
let closest = el.closest(tryClosestQry);
|
|
36
|
-
if(closest === null) closest = el.closest(closestQry);
|
|
37
|
-
if(closest === null) throw 404;
|
|
38
|
-
return Array.from(closest.querySelectorAll(`[${attr}="${attrVal}"]`))
|
|
39
|
-
//console.log({self, closestQry, prop, el});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return new Proxy(this, handler);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get fromParent(){
|
|
46
|
-
const {elRef, attr} = this;
|
|
47
|
-
const el = elRef.deref();
|
|
48
|
-
if(el === undefined) return [];
|
|
49
|
-
const {parentElement} = el;
|
|
50
|
-
if(parentElement === null) return [];
|
|
51
|
-
const attrVal = el.getAttribute(attr);
|
|
52
|
-
return Array.from(parentElement.querySelectorAll(`[${attr}="${attrVal}"]`));
|
|
53
|
-
}
|
|
54
|
-
}
|
package/refid/nudge.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { arr } from './arr.js';
|
|
2
|
-
/**
|
|
3
|
-
* Decrement "disabled" counter, remove when reaches 0
|
|
4
|
-
* @param el
|
|
5
|
-
* Optional select the attribute or attributes to remove or decrement
|
|
6
|
-
* @param attr
|
|
7
|
-
*/
|
|
8
|
-
export function nudge(el, attr = 'disabled') {
|
|
9
|
-
const attrs = arr(attr);
|
|
10
|
-
for (const attr of attrs) {
|
|
11
|
-
const da = el.getAttribute(attr);
|
|
12
|
-
if (da !== null) {
|
|
13
|
-
if (da.length === 0 || da === "1") {
|
|
14
|
-
el.removeAttribute(attr);
|
|
15
|
-
if (attr === 'disabled')
|
|
16
|
-
el.disabled = false;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
el.setAttribute(attr, (parseInt(da) - 1).toString());
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
package/refid/nudge.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {arr} from './arr.js';
|
|
2
|
-
/**
|
|
3
|
-
* Decrement "disabled" counter, remove when reaches 0
|
|
4
|
-
* @param el
|
|
5
|
-
* Optional select the attribute or attributes to remove or decrement
|
|
6
|
-
* @param attr
|
|
7
|
-
*/
|
|
8
|
-
export function nudge(el: Element, attr: string | Array<string> = 'disabled') { //TODO: Share with be-observant
|
|
9
|
-
const attrs = arr(attr);
|
|
10
|
-
for(const attr of attrs){
|
|
11
|
-
const da = el.getAttribute(attr);
|
|
12
|
-
if (da !== null) {
|
|
13
|
-
if (da.length === 0 || da === "1") {
|
|
14
|
-
el.removeAttribute(attr);
|
|
15
|
-
if(attr === 'disabled') (<any>el).disabled = false;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
el.setAttribute(attr, (parseInt(da) - 1).toString());
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
package/refid/regIsh.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const guid = 'La8Cx9vHsUOd03WomqdnPw';
|
|
2
|
-
export const sym = Symbol.for(guid);
|
|
3
|
-
import { arr } from './secretKeys.js';
|
|
4
|
-
export function regIsh(scope, name, ctr) {
|
|
5
|
-
let map = scope[sym];
|
|
6
|
-
if (map === undefined) {
|
|
7
|
-
map = new Map();
|
|
8
|
-
scope[sym] = map;
|
|
9
|
-
}
|
|
10
|
-
if (map.has(name)) {
|
|
11
|
-
throw 403;
|
|
12
|
-
}
|
|
13
|
-
map.set(name, ctr);
|
|
14
|
-
ctr.prototype[Symbol.iterator] = function () {
|
|
15
|
-
var index = -1;
|
|
16
|
-
var data = this[arr];
|
|
17
|
-
return {
|
|
18
|
-
next: function () {
|
|
19
|
-
return {
|
|
20
|
-
value: data === undefined ? undefined : data[++index],
|
|
21
|
-
done: data === undefined || !(index in data)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
document.dispatchEvent(new Event(guid));
|
|
27
|
-
}
|
package/refid/regIsh.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {IshCtr} from '../ts-refs/mount-observer/types';
|
|
2
|
-
export const guid = 'La8Cx9vHsUOd03WomqdnPw'
|
|
3
|
-
export const sym = Symbol.for(guid);
|
|
4
|
-
import {arr} from './secretKeys.js';
|
|
5
|
-
|
|
6
|
-
export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr:IshCtr){
|
|
7
|
-
let map = (<any>scope)[sym] as Map<string, IshCtr>;
|
|
8
|
-
if(map === undefined){
|
|
9
|
-
map = new Map<string, IshCtr>();
|
|
10
|
-
(<any>scope)[sym] = map;
|
|
11
|
-
}
|
|
12
|
-
if(map.has(name)){
|
|
13
|
-
throw 403;
|
|
14
|
-
}
|
|
15
|
-
map.set(name, ctr);
|
|
16
|
-
ctr.prototype[Symbol.iterator] = function() {
|
|
17
|
-
var index = -1;
|
|
18
|
-
var data = this[arr];
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
next: function() {
|
|
22
|
-
return {
|
|
23
|
-
value: data === undefined ? undefined : data[++index],
|
|
24
|
-
done: data === undefined || !(index in data)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
document.dispatchEvent(new Event(guid));
|
|
31
|
-
}
|
package/refid/secretKeys.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
//using Symbol.for, which is easily hackaable, because if two different entry points
|
|
2
|
-
//come from different versions of mount-observer, things could get out of sync.
|
|
3
|
-
//Not an issue if this was built into the browser, but it is an issue for a custom a library.
|
|
4
|
-
//Do not make this file exportable, it is only for internal use.
|
|
5
|
-
export const arr = Symbol.for('MHtiI353KU+aKBDlz/jR+A');
|
package/refid/secretKeys.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
//using Symbol.for, which is easily hackaable, because if two different entry points
|
|
2
|
-
//come from different versions of mount-observer, things could get out of sync.
|
|
3
|
-
//Not an issue if this was built into the browser, but it is an issue for a custom a library.
|
|
4
|
-
//Do not make this file exportable, it is only for internal use.
|
|
5
|
-
export const arr = Symbol.for('MHtiI353KU+aKBDlz/jR+A');
|
package/refid/splitRefs.js
DELETED
package/refid/splitRefs.ts
DELETED
package/refid/stdVal.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function stdVal(el) {
|
|
2
|
-
const { localName } = el;
|
|
3
|
-
switch (localName) {
|
|
4
|
-
case 'form':
|
|
5
|
-
throw 'NI';
|
|
6
|
-
case 'input':
|
|
7
|
-
throw 'NI';
|
|
8
|
-
case 'a':
|
|
9
|
-
return el.href;
|
|
10
|
-
case 'data':
|
|
11
|
-
return JSON.parse(el.value);
|
|
12
|
-
default:
|
|
13
|
-
return el.textContent;
|
|
14
|
-
}
|
|
15
|
-
}
|
package/refid/stdVal.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function stdVal(el: Element){
|
|
2
|
-
const {localName} = el;
|
|
3
|
-
switch(localName){
|
|
4
|
-
case 'form':
|
|
5
|
-
throw 'NI';
|
|
6
|
-
case 'input':
|
|
7
|
-
throw 'NI';
|
|
8
|
-
case 'a':
|
|
9
|
-
return (el as HTMLAnchorElement).href;
|
|
10
|
-
case 'data':
|
|
11
|
-
return JSON.parse((el as HTMLDataElement).value);
|
|
12
|
-
default:
|
|
13
|
-
return el.textContent;
|
|
14
|
-
}
|
|
15
|
-
}
|
package/refid/via.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { splitRefs } from './splitRefs.js';
|
|
2
|
-
import { MountObserver } from '../MountObserver.js';
|
|
3
|
-
import { camelToKebab } from './camelToKebab.js';
|
|
4
|
-
const proxies = new WeakMap();
|
|
5
|
-
const refLookup = new WeakMap();
|
|
6
|
-
Object.defineProperty(Element.prototype, 'via', {
|
|
7
|
-
get() {
|
|
8
|
-
if (!proxies.has(this)) {
|
|
9
|
-
const handler = {
|
|
10
|
-
get(target, prop) {
|
|
11
|
-
let lookup;
|
|
12
|
-
if (refLookup.has(target)) {
|
|
13
|
-
lookup = refLookup.get(target);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
lookup = new Map();
|
|
17
|
-
refLookup.set(target, lookup);
|
|
18
|
-
}
|
|
19
|
-
if (lookup.has(prop)) {
|
|
20
|
-
return lookup.get(prop);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const refManager = new RefManager(target, prop);
|
|
24
|
-
lookup.set(prop, refManager);
|
|
25
|
-
return refManager;
|
|
26
|
-
}
|
|
27
|
-
//return Reflect.get(target, prop);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
proxies.set(this, new Proxy(this, handler));
|
|
31
|
-
}
|
|
32
|
-
return proxies.get(this);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
class RefManager extends EventTarget {
|
|
36
|
-
#el;
|
|
37
|
-
#children;
|
|
38
|
-
#attr;
|
|
39
|
-
#lastAttrVal = '';
|
|
40
|
-
//#parents: Array<WeakRef<Element>> | undefined;
|
|
41
|
-
constructor(el, prop) {
|
|
42
|
-
super();
|
|
43
|
-
this.#attr = camelToKebab(prop);
|
|
44
|
-
this.#el = new WeakRef(el);
|
|
45
|
-
}
|
|
46
|
-
get children() {
|
|
47
|
-
const el = this.#el.deref();
|
|
48
|
-
if (el === undefined)
|
|
49
|
-
return [];
|
|
50
|
-
const attr = el.getAttribute(this.#attr);
|
|
51
|
-
if (this.#children === undefined || attr !== this.#lastAttrVal) {
|
|
52
|
-
if (!attr)
|
|
53
|
-
return [];
|
|
54
|
-
this.#lastAttrVal = attr;
|
|
55
|
-
const refIds = splitRefs(attr);
|
|
56
|
-
const qry = refIds.map(id => `#${id}`).join(',');
|
|
57
|
-
const rn = el.getRootNode();
|
|
58
|
-
const refsArr = Array.from(rn.querySelectorAll(qry));
|
|
59
|
-
const refs = new Map();
|
|
60
|
-
for (const ref of refsArr) {
|
|
61
|
-
refs.set(ref.id, new WeakRef(ref));
|
|
62
|
-
}
|
|
63
|
-
this.#children = refs;
|
|
64
|
-
const mo = new MountObserver({
|
|
65
|
-
on: qry,
|
|
66
|
-
do: {
|
|
67
|
-
mount: (el) => {
|
|
68
|
-
const id = el.id;
|
|
69
|
-
if (id && !this.#children?.has(id)) {
|
|
70
|
-
this.#children?.set(id, new WeakRef(el));
|
|
71
|
-
this.dispatchEvent(new ChangeEvent([el], []));
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
dismount: (el) => {
|
|
75
|
-
const id = el.id;
|
|
76
|
-
if (id && this.#children?.has(id)) {
|
|
77
|
-
this.#children?.delete(id);
|
|
78
|
-
this.dispatchEvent(new ChangeEvent([], [el]));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
mo.observe(rn);
|
|
84
|
-
this.dispatchEvent(new ChangeEvent((refsArr), []));
|
|
85
|
-
}
|
|
86
|
-
return Array.from(this.#children?.values().map(ref => ref.deref()).filter(el => el !== undefined)) || [];
|
|
87
|
-
}
|
|
88
|
-
get parents() {
|
|
89
|
-
//for now, hold off on caching parents until a use case arises
|
|
90
|
-
//if(this.#parents === undefined){
|
|
91
|
-
const el = this.#el.deref();
|
|
92
|
-
if (el === undefined)
|
|
93
|
-
return [];
|
|
94
|
-
if (el.id === '')
|
|
95
|
-
return [];
|
|
96
|
-
const rn = el.getRootNode();
|
|
97
|
-
const qry = `[${this.#attr}~="${el.id}"]`;
|
|
98
|
-
const parents = Array.from(rn.querySelectorAll(qry));
|
|
99
|
-
//this.#parents = parents.map(parent => new WeakRef(parent));
|
|
100
|
-
return parents;
|
|
101
|
-
//}
|
|
102
|
-
//return this.#parents.map(ref => ref.deref()).filter(el => el !== undefined) || [];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
export class ChangeEvent extends Event {
|
|
106
|
-
addedChildren;
|
|
107
|
-
removedChildren;
|
|
108
|
-
static eventName = 'change';
|
|
109
|
-
constructor(addedChildren, removedChildren) {
|
|
110
|
-
super(ChangeEvent.eventName);
|
|
111
|
-
this.addedChildren = addedChildren;
|
|
112
|
-
this.removedChildren = removedChildren;
|
|
113
|
-
}
|
|
114
|
-
}
|