mount-observer 0.0.95 → 0.0.97
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 +5 -1
- package/refid/genIds.js +17 -0
- package/refid/genIds.ts +16 -0
- package/refid/getContext.js +13 -0
- package/refid/getContext.ts +14 -0
- package/refid/hostish.js +4 -3
- package/refid/hostish.ts +4 -3
- package/ts-refs/be-observant/types.d.ts +27 -0
- package/ts-refs/be-observing/types.d.ts +1 -1
- package/ts-refs/trans-render/dss/types.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.97",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
"default": "./refid/getAdjRefs.js",
|
|
58
58
|
"types": "./refid/getAdjRefs.ts"
|
|
59
59
|
},
|
|
60
|
+
"./refid/getContext.js": {
|
|
61
|
+
"default": "./refid/getContext.js",
|
|
62
|
+
"types": "./refid/getContext.ts"
|
|
63
|
+
},
|
|
60
64
|
"./refid/getCount.js": {
|
|
61
65
|
"default": "./refid/getCount.js",
|
|
62
66
|
"types": "./refid/getCount.ts"
|
package/refid/genIds.js
CHANGED
|
@@ -37,6 +37,23 @@ export function genIds(enhancedElement) {
|
|
|
37
37
|
hi.dataset.id = `{{${sideEffects}${localName}}}`;
|
|
38
38
|
hi.removeAttribute('#');
|
|
39
39
|
}
|
|
40
|
+
//now find all elements with attribute @
|
|
41
|
+
const names = Array.from(scopeFragment.querySelectorAll('[name]:not([name=""])[\\@]')).filter(x => inScope(scopeFragment, x));
|
|
42
|
+
for (const nameEl of names) {
|
|
43
|
+
if (!(nameEl instanceof HTMLElement))
|
|
44
|
+
continue;
|
|
45
|
+
const val = nameEl.getAttribute('name');
|
|
46
|
+
if (uniqueCheck.has(val))
|
|
47
|
+
throw 500;
|
|
48
|
+
uniqueCheck.add(val);
|
|
49
|
+
let sideEffects = '';
|
|
50
|
+
const nameValue = nameEl.getAttribute('@');
|
|
51
|
+
if (nameValue) {
|
|
52
|
+
sideEffects = `${nameValue} `;
|
|
53
|
+
}
|
|
54
|
+
nameEl.dataset.id = `{{${sideEffects}${val}}}`;
|
|
55
|
+
nameEl.removeAttribute('@');
|
|
56
|
+
}
|
|
40
57
|
const dataIds = Array.from(scopeFragment.querySelectorAll('[data-id^="{{"][data-id$="}}"]')).filter(x => inScope(scopeFragment, x));
|
|
41
58
|
const ids = [];
|
|
42
59
|
for (const di of dataIds) {
|
package/refid/genIds.ts
CHANGED
|
@@ -38,6 +38,22 @@ export function genIds(enhancedElement: Element){
|
|
|
38
38
|
hi.removeAttribute('#');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
//now find all elements with attribute @
|
|
42
|
+
const names = Array.from(scopeFragment.querySelectorAll('[name]:not([name=""])[\\@]')).filter(x => inScope(scopeFragment, x));
|
|
43
|
+
for(const nameEl of names){
|
|
44
|
+
if(!(nameEl instanceof HTMLElement)) continue;
|
|
45
|
+
const val = nameEl.getAttribute('name');
|
|
46
|
+
if(uniqueCheck.has(val)) throw 500;
|
|
47
|
+
uniqueCheck.add(val);
|
|
48
|
+
let sideEffects = '';
|
|
49
|
+
const nameValue = nameEl.getAttribute('@');
|
|
50
|
+
if(nameValue){
|
|
51
|
+
sideEffects = `${nameValue} `;
|
|
52
|
+
}
|
|
53
|
+
nameEl.dataset.id = `{{${sideEffects}${val}}}`;
|
|
54
|
+
nameEl.removeAttribute('@');
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
const dataIds = Array.from(scopeFragment.querySelectorAll('[data-id^="{{"][data-id$="}}"]')).filter(x => inScope(scopeFragment, x));
|
|
42
58
|
const ids: Array<string> = [];
|
|
43
59
|
for(const di of dataIds){
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import './hostish.js';
|
|
2
|
+
export function getContext(el, ctr) {
|
|
3
|
+
let hostish = el.hostish(false);
|
|
4
|
+
while (hostish && !(hostish instanceof ctr)) {
|
|
5
|
+
if ('hostish' in hostish) {
|
|
6
|
+
hostish = hostish.hostish();
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return hostish;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import './hostish.js';
|
|
2
|
+
|
|
3
|
+
export function getContext<T extends Object>(el: Element, ctr: {new(): T}){
|
|
4
|
+
let hostish = (<any>el).hostish(false);
|
|
5
|
+
while(hostish && !(hostish instanceof ctr)){
|
|
6
|
+
if('hostish' in hostish){
|
|
7
|
+
hostish = hostish.hostish();
|
|
8
|
+
}else{
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
return hostish;
|
|
14
|
+
}
|
package/refid/hostish.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Element.prototype.hostish = async function () {
|
|
3
|
-
const
|
|
4
|
-
|
|
2
|
+
Element.prototype.hostish = async function (checkSelf = true) {
|
|
3
|
+
const from = checkSelf ? this : this.hasAttribute('itemscope') ? this.parentElement : this;
|
|
4
|
+
const closest = from?.closest('[itemscope]');
|
|
5
|
+
if (closest === null || closest === undefined)
|
|
5
6
|
return this.getRootNode().host;
|
|
6
7
|
const { localName } = closest;
|
|
7
8
|
const itemScopeAttr = closest.getAttribute('itemscope');
|
package/refid/hostish.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
interface Element{
|
|
2
2
|
hostish(): Promise<any>
|
|
3
3
|
}
|
|
4
|
-
Element.prototype.hostish = async function(){
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
Element.prototype.hostish = async function(checkSelf = true){
|
|
5
|
+
const from = checkSelf ? this : this.hasAttribute('itemscope') ? this.parentElement : this;
|
|
6
|
+
const closest = from?.closest('[itemscope]') as HTMLElement;
|
|
7
|
+
if(closest === null || closest === undefined) return (<any>this.getRootNode()).host;
|
|
7
8
|
const {localName} = closest;
|
|
8
9
|
const itemScopeAttr = closest.getAttribute('itemscope');
|
|
9
10
|
if(itemScopeAttr){
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {BEAllProps, IEnhancement} from '../trans-render/be/types';
|
|
2
|
+
import { Specifier } from "../trans-render/dss/types";
|
|
3
|
+
|
|
4
|
+
export interface EndUserProps extends IEnhancement<HTMLElement>{
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface AllProps extends EndUserProps{
|
|
9
|
+
parsedStatements: Array<ObservantParameters>,
|
|
10
|
+
rawStatements?: Array<string>,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ObservantParameters{
|
|
14
|
+
remoteSpecifiers: Array<Specifier>,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type AP = AllProps;
|
|
18
|
+
|
|
19
|
+
export type PAP = Partial<AP>;
|
|
20
|
+
|
|
21
|
+
export type ProPAP = Promise<PAP>;
|
|
22
|
+
|
|
23
|
+
export type BAP = AP & BEAllProps<HTMLElement>;
|
|
24
|
+
|
|
25
|
+
export interface Actions{
|
|
26
|
+
hydrate(self: BAP) : ProPAP;
|
|
27
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BEAllProps,
|
|
1
|
+
import {BEAllProps, IEnhancement, IW} from '../trans-render/be/types';
|
|
2
2
|
import { Specifier } from "../trans-render/dss/types";
|
|
3
3
|
import {aggKeys, Handlers} from '../be-hive/types';
|
|
4
4
|
import { StringWithAutocompleteOptions } from '../trans-render/types';
|
|
@@ -23,7 +23,9 @@ export type ValExpression = `${PropPath | ConstVal | MindReadProp}${TypeQualifie
|
|
|
23
23
|
|
|
24
24
|
export type MindReadEvent = ``;
|
|
25
25
|
|
|
26
|
-
export type
|
|
26
|
+
export type EventSpecifier = `::${string}`;
|
|
27
|
+
|
|
28
|
+
export type EventPart = MindReadEvent | EventSpecifier;
|
|
27
29
|
|
|
28
30
|
export type DSS = `${Target}${ValExpression}${EventPart}`;
|
|
29
31
|
|