mount-observer 0.0.57 → 0.0.59
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/Newish.js +13 -7
- package/Newish.ts +17 -7
- package/RootMutObs.js +0 -1
- package/RootMutObs.ts +0 -1
- package/bindish.js +2 -2
- package/bindish.ts +2 -2
- package/package.json +5 -1
- package/refid/getIsh.js +24 -0
- package/refid/getIsh.ts +25 -0
- package/refid/regIsh.js +12 -0
- package/refid/regIsh.ts +14 -0
- package/ts-refs/mount-observer/types.d.ts +9 -0
- package/ts-refs/per-each/types.d.ts +2 -1
- package/ts-refs/trans-render/froop/types.d.ts +4 -0
- package/ts-refs/trans-render/types.d.ts +26 -4
package/Newish.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { waitForEvent } from './waitForEvent.js';
|
|
2
2
|
import { ObsAttr } from './ObsAttr.js';
|
|
3
3
|
import { splitRefs } from './refid/splitRefs.js';
|
|
4
|
+
import { getIsh } from './refid/getIsh.js';
|
|
4
5
|
export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
|
|
5
6
|
export class Newish {
|
|
6
7
|
queue = [];
|
|
@@ -24,7 +25,7 @@ export class Newish {
|
|
|
24
25
|
if (enhancedElement[attached] === true)
|
|
25
26
|
return;
|
|
26
27
|
enhancedElement[attached] = true;
|
|
27
|
-
|
|
28
|
+
const ctr = getIsh(enhancedElement, itemscope);
|
|
28
29
|
const initPropVals = enhancedElement['ish'];
|
|
29
30
|
if (enhancedElement instanceof HTMLElement) {
|
|
30
31
|
if (enhancedElement.dataset.ish) {
|
|
@@ -32,11 +33,13 @@ export class Newish {
|
|
|
32
33
|
this.queue.push(parsedHostProps);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
|
|
37
|
+
const isInstance = initPropVals instanceof resolvedConstructor;
|
|
38
|
+
const ce = isInstance ? initPropVals : new resolvedConstructor();
|
|
39
|
+
if (initPropVals !== undefined && !isInstance)
|
|
36
40
|
this.queue.push(initPropVals);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await ce.attachedCallback(enhancedElement);
|
|
41
|
+
if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
|
|
42
|
+
await ce['<mount>'](ce, enhancedElement, this.#options);
|
|
40
43
|
}
|
|
41
44
|
this.#ce = ce;
|
|
42
45
|
const self = this;
|
|
@@ -45,6 +48,9 @@ export class Newish {
|
|
|
45
48
|
return self.#ce;
|
|
46
49
|
},
|
|
47
50
|
set(nv) {
|
|
51
|
+
if (self.#ce === nv)
|
|
52
|
+
return;
|
|
53
|
+
console.log({ nv });
|
|
48
54
|
self.queue.push(nv);
|
|
49
55
|
self.#assignGingerly();
|
|
50
56
|
},
|
|
@@ -63,7 +69,7 @@ export class Newish {
|
|
|
63
69
|
#attachItemrefs(enhancedElement) {
|
|
64
70
|
//TODO: watch for already attached itemrefs to be removed and remove them from the set
|
|
65
71
|
// and call outOfScopeCallback on them
|
|
66
|
-
if ('
|
|
72
|
+
if ('<inScope>' in this.#ce && enhancedElement.hasAttribute('itemref')) {
|
|
67
73
|
const itemref = enhancedElement.getAttribute('itemref');
|
|
68
74
|
const itemrefList = splitRefs(itemref); // itemref.split(' ').map((id) => id.trim()).filter((id) => id.length > 0);
|
|
69
75
|
if (itemrefList.length === 0)
|
|
@@ -74,7 +80,7 @@ export class Newish {
|
|
|
74
80
|
continue;
|
|
75
81
|
const itemrefElement = rn.getElementById(id);
|
|
76
82
|
if (itemrefElement) {
|
|
77
|
-
this.#ce
|
|
83
|
+
this.#ce['<inScope>'](this.#ce, itemrefElement, this.#options);
|
|
78
84
|
this.#alreadyAttached.add(id);
|
|
79
85
|
}
|
|
80
86
|
}
|
package/Newish.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
|
|
|
3
3
|
export {waitForEvent} from './waitForEvent.js';
|
|
4
4
|
import {ObsAttr} from './ObsAttr.js';
|
|
5
5
|
import {splitRefs} from './refid/splitRefs.js';
|
|
6
|
+
import {getIsh} from './refid/getIsh.js';
|
|
6
7
|
export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
|
|
7
8
|
export class Newish implements EventListenerObject {
|
|
8
9
|
queue: Array<any> = [];
|
|
@@ -27,7 +28,8 @@ export class Newish implements EventListenerObject {
|
|
|
27
28
|
async #do(enhancedElement: Element, itemscope: string){
|
|
28
29
|
if((<any>enhancedElement)[attached] === true) return;
|
|
29
30
|
(<any>enhancedElement)[attached] = true;
|
|
30
|
-
|
|
31
|
+
const ctr = getIsh(enhancedElement, itemscope)! as any;
|
|
32
|
+
|
|
31
33
|
const initPropVals = (<any>enhancedElement)['ish'];
|
|
32
34
|
if(enhancedElement instanceof HTMLElement){
|
|
33
35
|
if(enhancedElement.dataset.ish){
|
|
@@ -35,11 +37,17 @@ export class Newish implements EventListenerObject {
|
|
|
35
37
|
this.queue.push(parsedHostProps);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
|
|
43
|
+
const isInstance = initPropVals instanceof resolvedConstructor
|
|
44
|
+
const ce = isInstance ? initPropVals : new resolvedConstructor();
|
|
45
|
+
if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
|
|
46
|
+
|
|
47
|
+
if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
|
|
48
|
+
await ce['<mount>'](ce, enhancedElement, this.#options)
|
|
42
49
|
}
|
|
50
|
+
|
|
43
51
|
this.#ce = ce;
|
|
44
52
|
const self = this;
|
|
45
53
|
Object.defineProperty(enhancedElement, 'ish', {
|
|
@@ -47,6 +55,8 @@ export class Newish implements EventListenerObject {
|
|
|
47
55
|
return self.#ce;
|
|
48
56
|
},
|
|
49
57
|
set(nv: any){
|
|
58
|
+
if(self.#ce === nv) return;
|
|
59
|
+
console.log({nv});
|
|
50
60
|
self.queue.push(nv);
|
|
51
61
|
self.#assignGingerly();
|
|
52
62
|
},
|
|
@@ -69,7 +79,7 @@ export class Newish implements EventListenerObject {
|
|
|
69
79
|
#attachItemrefs(enhancedElement: Element){
|
|
70
80
|
//TODO: watch for already attached itemrefs to be removed and remove them from the set
|
|
71
81
|
// and call outOfScopeCallback on them
|
|
72
|
-
if('
|
|
82
|
+
if('<inScope>' in (<any>this.#ce) && enhancedElement.hasAttribute('itemref')){
|
|
73
83
|
const itemref = enhancedElement.getAttribute('itemref')!;
|
|
74
84
|
const itemrefList = splitRefs(itemref);// itemref.split(' ').map((id) => id.trim()).filter((id) => id.length > 0);
|
|
75
85
|
if(itemrefList.length === 0) return;
|
|
@@ -78,7 +88,7 @@ export class Newish implements EventListenerObject {
|
|
|
78
88
|
if(this.#alreadyAttached.has(id)) continue;
|
|
79
89
|
const itemrefElement = rn.getElementById(id);
|
|
80
90
|
if(itemrefElement){
|
|
81
|
-
(<any>this.#ce)
|
|
91
|
+
(<any>this.#ce)['<inScope>'](this.#ce, itemrefElement, this.#options);
|
|
82
92
|
this.#alreadyAttached.add(id);
|
|
83
93
|
}
|
|
84
94
|
}
|
package/RootMutObs.js
CHANGED
|
@@ -4,7 +4,6 @@ export class RootMutObs extends EventTarget {
|
|
|
4
4
|
constructor(rootNode, options) {
|
|
5
5
|
super();
|
|
6
6
|
this.#idleTimeout = options?.idleTimeout ?? 30;
|
|
7
|
-
console.log(this.#idleTimeout);
|
|
8
7
|
this.#mutationObserver = new MutationObserver(mutationRecords => {
|
|
9
8
|
this.dispatchEvent(new MutationEvent(mutationRecords));
|
|
10
9
|
this.#triggerIsIdle();
|
package/RootMutObs.ts
CHANGED
|
@@ -6,7 +6,6 @@ export class RootMutObs extends EventTarget{
|
|
|
6
6
|
constructor(rootNode: Node, options: MountInit ){
|
|
7
7
|
super();
|
|
8
8
|
this.#idleTimeout = options?.idleTimeout ?? 30;
|
|
9
|
-
console.log(this.#idleTimeout);
|
|
10
9
|
this.#mutationObserver = new MutationObserver(mutationRecords => {
|
|
11
10
|
this.dispatchEvent(new MutationEvent(mutationRecords));
|
|
12
11
|
this.#triggerIsIdle();
|
package/bindish.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const itemscopeQry = '[itemscope
|
|
1
|
+
export const itemscopeQry = '[itemscope]:not([itemscope=""])';
|
|
2
2
|
export async function bindish(fragment, options) {
|
|
3
3
|
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
4
4
|
await bindishIt(scopes, options);
|
|
@@ -6,7 +6,7 @@ export async function bindish(fragment, options) {
|
|
|
6
6
|
export async function bindishIt(scopes, options) {
|
|
7
7
|
for (const scope of scopes) {
|
|
8
8
|
const itemscope = scope.getAttribute('itemscope');
|
|
9
|
-
if (itemscope &&
|
|
9
|
+
if (itemscope && !(scope.ish instanceof HTMLElement)) {
|
|
10
10
|
const { Newish } = await import('./Newish.js');
|
|
11
11
|
new Newish(scope, itemscope, options);
|
|
12
12
|
}
|
package/bindish.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
|
|
2
2
|
|
|
3
|
-
export const itemscopeQry = '[itemscope
|
|
3
|
+
export const itemscopeQry = '[itemscope]:not([itemscope=""])';
|
|
4
4
|
export async function bindish(fragment: DocumentFragment, options?: BindishOptions){
|
|
5
5
|
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
6
6
|
await bindishIt(scopes, options);
|
|
@@ -9,7 +9,7 @@ export async function bindish(fragment: DocumentFragment, options?: BindishOptio
|
|
|
9
9
|
export async function bindishIt(scopes: Array<Element>, options?: BindishOptions){
|
|
10
10
|
for(const scope of scopes){
|
|
11
11
|
const itemscope = scope.getAttribute('itemscope');
|
|
12
|
-
if(itemscope &&
|
|
12
|
+
if(itemscope && !((<any>scope).ish instanceof HTMLElement)){
|
|
13
13
|
const {Newish} = await import('./Newish.js');
|
|
14
14
|
new Newish(scope, itemscope, options);
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.59",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -45,6 +45,10 @@
|
|
|
45
45
|
"default": "./waitForIsh.js",
|
|
46
46
|
"types": "./waitForIsh.ts"
|
|
47
47
|
},
|
|
48
|
+
"./refid/regIsh.js": {
|
|
49
|
+
"default": "./refid/regIsh.js",
|
|
50
|
+
"types": "./refid/regIsh.js"
|
|
51
|
+
},
|
|
48
52
|
"./refid/splitRefs.js": {
|
|
49
53
|
"default": "./refid/splitRefs.js",
|
|
50
54
|
"types": "./refid/splitRefs.ts"
|
package/refid/getIsh.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { sym } from './regIsh.js';
|
|
2
|
+
export function getIsh(scope, name) {
|
|
3
|
+
let test = scope;
|
|
4
|
+
while (true) {
|
|
5
|
+
const map = test[sym];
|
|
6
|
+
if (map !== undefined) {
|
|
7
|
+
if (map.has(name)) {
|
|
8
|
+
return map.get(name);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (test === document)
|
|
12
|
+
throw 404;
|
|
13
|
+
if (test instanceof ShadowRoot) {
|
|
14
|
+
test = test.host;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
let newTest = test.parentElement;
|
|
18
|
+
if (newTest) {
|
|
19
|
+
test = newTest;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
test = test.getRootNode();
|
|
23
|
+
}
|
|
24
|
+
}
|
package/refid/getIsh.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {sym} from './regIsh.js';
|
|
2
|
+
import {IshCtr} from '../ts-refs/mount-observer/types.js';
|
|
3
|
+
export function getIsh(scope: Element | ShadowRoot | Document, name: string){
|
|
4
|
+
let test = scope as any;
|
|
5
|
+
|
|
6
|
+
while(true){
|
|
7
|
+
const map = test[sym] as Map<string, IshCtr>;
|
|
8
|
+
if(map !== undefined){
|
|
9
|
+
if(map.has(name)){
|
|
10
|
+
return map.get(name);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if(test === document) throw 404;
|
|
14
|
+
if(test instanceof ShadowRoot){
|
|
15
|
+
test = test.host;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
let newTest = test.parentElement;
|
|
19
|
+
if(newTest){
|
|
20
|
+
test = newTest;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
test = test.getRootNode();
|
|
24
|
+
}
|
|
25
|
+
}
|
package/refid/regIsh.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const sym = Symbol.for('La8Cx9vHsUOd03WomqdnPw');
|
|
2
|
+
export function regIsh(scope, name, ctr) {
|
|
3
|
+
let map = scope[sym];
|
|
4
|
+
if (map === undefined) {
|
|
5
|
+
map = new Map();
|
|
6
|
+
scope[sym] = map;
|
|
7
|
+
}
|
|
8
|
+
if (map.has(name)) {
|
|
9
|
+
throw 403;
|
|
10
|
+
}
|
|
11
|
+
map.set(name, ctr);
|
|
12
|
+
}
|
package/refid/regIsh.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {IshCtr} from '../ts-refs/mount-observer/types';
|
|
2
|
+
export const sym = Symbol.for('La8Cx9vHsUOd03WomqdnPw');
|
|
3
|
+
|
|
4
|
+
export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr:IshCtr){
|
|
5
|
+
let map = (<any>scope)[sym] as Map<string, IshCtr>;
|
|
6
|
+
if(map === undefined){
|
|
7
|
+
map = new Map<string, IshCtr>();
|
|
8
|
+
(<any>scope)[sym] = map;
|
|
9
|
+
}
|
|
10
|
+
if(map.has(name)){
|
|
11
|
+
throw 403;
|
|
12
|
+
}
|
|
13
|
+
map.set(name, ctr);
|
|
14
|
+
}
|
|
@@ -218,6 +218,15 @@ export interface BindishOptions{
|
|
|
218
218
|
csr?: boolean,
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
export interface Ishcycle{
|
|
222
|
+
'<mount>'?(self: Ishcycle, el: Element, options: BindishOptions): Promise<void>;
|
|
223
|
+
//'</dismount>'?(self: IshFace, el: Element): Promise<void>;
|
|
224
|
+
'<inScope>'?(self: Ishcycle, el: Element, options: BindishOptions): Promise<void>;
|
|
225
|
+
//'</outOfScope>'?(self: IshFace, el: Element): Promise<void>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type IshCtr = ({new() : Ishcycle}) | (() => Promise<{new() : Ishcycle}>);
|
|
229
|
+
|
|
221
230
|
//#endregion
|
|
222
231
|
|
|
223
232
|
|
|
@@ -2,10 +2,11 @@ import {IEnhancement, BEAllProps} from '../trans-render/be/types';
|
|
|
2
2
|
import { HasIshList } from '../trans-render/dss/types';
|
|
3
3
|
|
|
4
4
|
export interface EndUserProps extends IEnhancement{
|
|
5
|
-
|
|
5
|
+
each: string;
|
|
6
6
|
mapIdxTo: string;
|
|
7
7
|
idxStart: number;
|
|
8
8
|
idleTimeout: number;
|
|
9
|
+
options: Partial<EndUserProps>;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export interface AllProps extends EndUserProps{
|
|
@@ -257,6 +257,8 @@ export interface LogicOp<Props = any>{
|
|
|
257
257
|
|
|
258
258
|
delay?: number,
|
|
259
259
|
|
|
260
|
+
do?: (x: Props) => (Promise<Partial<Props>> | Partial<Props>)
|
|
261
|
+
|
|
260
262
|
}
|
|
261
263
|
|
|
262
264
|
export interface SetLogicOps<Props = any>{
|
|
@@ -278,6 +280,8 @@ export interface SetLogicOps<Props = any>{
|
|
|
278
280
|
debug?: boolean,
|
|
279
281
|
|
|
280
282
|
delay?: number,
|
|
283
|
+
|
|
284
|
+
do?: (x: Props) => (Promise<Partial<Props>> | Partial<Props>),
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
export interface Action<MCProps = any, MCActions = MCProps> extends LogicOp<MCProps>{
|
|
@@ -53,7 +53,11 @@ export type DerivationCriteria<TProps, TMethods> = {
|
|
|
53
53
|
path: string,
|
|
54
54
|
from?: number,
|
|
55
55
|
//TODO
|
|
56
|
-
as?: ConvertOptions
|
|
56
|
+
as?: ConvertOptions,
|
|
57
|
+
//TODO - applicable to arrays
|
|
58
|
+
filter?: keyof TModhods & string | ((val: any) => boolean),
|
|
59
|
+
//TODO
|
|
60
|
+
map?: keyof TModhods & string | ((val: any) => any,
|
|
57
61
|
};
|
|
58
62
|
|
|
59
63
|
export interface TransformOptions{
|
|
@@ -144,6 +148,15 @@ export interface ConditionGate<TProps, TMethods, TElement = {}>{
|
|
|
144
148
|
|
|
145
149
|
}
|
|
146
150
|
|
|
151
|
+
export interface ScopingConfig<TProps=any, TMethods = TProps> {
|
|
152
|
+
name: string;
|
|
153
|
+
config?: IshConfig<TProps, TMethods>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type ScopeInstructions<TProps=any, TMethods=TProps> =
|
|
157
|
+
| ScopingConfig
|
|
158
|
+
;
|
|
159
|
+
|
|
147
160
|
export type WhereConditions =
|
|
148
161
|
| string //css matches
|
|
149
162
|
| {
|
|
@@ -183,6 +196,12 @@ export interface ForEach<TProps, TMethods, TElement = {}>{
|
|
|
183
196
|
outOfRangeProp?: string,
|
|
184
197
|
}
|
|
185
198
|
|
|
199
|
+
// export interface MapInstructions<TProps, TMethods, TElement = {}>{
|
|
200
|
+
// // itemCss: CSSQuery,
|
|
201
|
+
// // each: string | [string, IshConfig<TProps, TMethods, TElement>],
|
|
202
|
+
// // in: string | [string, IshConfig<TProps, TMethods, TElement>],
|
|
203
|
+
// }
|
|
204
|
+
|
|
186
205
|
export interface ForEachInterface{
|
|
187
206
|
init(): Promise<void>;
|
|
188
207
|
update(model: any[]): Promise<void>;
|
|
@@ -224,7 +243,7 @@ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
|
|
|
224
243
|
|
|
225
244
|
forEachBinding?: ForEach<any, any, any>
|
|
226
245
|
/**
|
|
227
|
-
* for each
|
|
246
|
+
* for each -- deprecated?
|
|
228
247
|
*/
|
|
229
248
|
f?: ForEach<any, any, any>,
|
|
230
249
|
|
|
@@ -244,6 +263,7 @@ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
|
|
|
244
263
|
*/
|
|
245
264
|
invoke?: string,
|
|
246
265
|
|
|
266
|
+
|
|
247
267
|
/**
|
|
248
268
|
* modify the model in a (mostly) declarative way
|
|
249
269
|
*/
|
|
@@ -303,7 +323,9 @@ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
|
|
|
303
323
|
*/
|
|
304
324
|
w?: WhereConditions,
|
|
305
325
|
|
|
306
|
-
y?: number | YieldSettings<TProps
|
|
326
|
+
y?: number | YieldSettings<TProps>,
|
|
327
|
+
|
|
328
|
+
$?: ScopeInstructions<TProps, TMethods>,
|
|
307
329
|
}
|
|
308
330
|
|
|
309
331
|
export interface YieldSettings<TProps>{
|
|
@@ -455,7 +477,7 @@ export interface TransRenderMethods{
|
|
|
455
477
|
skipInit: boolean,
|
|
456
478
|
}
|
|
457
479
|
|
|
458
|
-
import {OConfig} from './froop/types';
|
|
480
|
+
import {IshConfig, OConfig} from './froop/types';
|
|
459
481
|
export interface MntCfg<TProps = any, TActions = TProps, ETProps = TProps> extends OConfig<TProps, TActions, ETProps>{
|
|
460
482
|
mainTemplate: string | HTMLTemplateElement,
|
|
461
483
|
/**
|