mount-observer 0.0.63 → 0.0.65

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 CHANGED
@@ -2,45 +2,51 @@ export { waitForEvent } from './waitForEvent.js';
2
2
  import { ObsAttr } from './ObsAttr.js';
3
3
  import { splitRefs } from './refid/splitRefs.js';
4
4
  import { getIsh } from './refid/getIsh.js';
5
- import { sym } from './refid/regIsh.js';
5
+ import { arr } from './refid/secretKeys.js';
6
6
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
7
7
  export class Newish {
8
8
  queue = [];
9
9
  isResolved = false;
10
10
  #ce;
11
11
  #ref;
12
- //#assigner: undefined | Assigner = undefined;
13
12
  #options;
13
+ #args;
14
14
  constructor(enhancedElement, target, itemscope, options) {
15
+ this.#args = [enhancedElement, target, itemscope];
15
16
  this.#options = options || { assigner: Object.assign };
16
17
  this.#ref = new WeakRef(enhancedElement);
17
- this.#do(enhancedElement, target, itemscope);
18
18
  }
19
- handleEvent(event) {
19
+ handleEvent() {
20
20
  const enhancedElement = this.#ref.deref();
21
21
  if (!enhancedElement)
22
22
  return;
23
23
  this.#attachItemrefs(enhancedElement);
24
24
  }
25
- async #do(enhancedElement, target, itemscope) {
25
+ async do() {
26
+ const [enhancedElement, target, itemscope] = this.#args;
27
+ this.#args = undefined;
26
28
  if (enhancedElement[attached] === true)
27
29
  return;
28
30
  enhancedElement[attached] = true;
29
- const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
30
- const initPropVals = enhancedElement['ish'];
31
- if (enhancedElement instanceof HTMLElement) {
32
- if (enhancedElement.dataset.ish) {
33
- const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
34
- this.queue.push(parsedHostProps);
35
- }
31
+ const options = this.#options;
32
+ const { initPropVals, ctr } = options;
33
+ let ce;
34
+ if (ctr === undefined) {
35
+ const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
36
+ const initPropVals = enhancedElement['ish'];
37
+ const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
38
+ const isInstance = initPropVals instanceof resolvedConstructor;
39
+ ce = isInstance ? initPropVals : new resolvedConstructor();
40
+ if (initPropVals !== undefined && !isInstance)
41
+ this.queue.push(initPropVals);
36
42
  }
37
- const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
38
- const isInstance = initPropVals instanceof resolvedConstructor;
39
- const ce = isInstance ? initPropVals : new resolvedConstructor();
40
- if (initPropVals !== undefined && !isInstance)
41
- this.queue.push(initPropVals);
42
- if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
43
- await ce['<mount>'](ce, enhancedElement, this.#options);
43
+ else {
44
+ ce = new ctr();
45
+ if (initPropVals !== undefined)
46
+ this.queue.push(initPropVals);
47
+ }
48
+ if ('tbd' in ce && typeof ce['tbd'] === 'function') {
49
+ await ce['tbd'](ce, enhancedElement, this.#options);
44
50
  }
45
51
  this.#ce = ce;
46
52
  const self = this;
@@ -57,12 +63,16 @@ export class Newish {
57
63
  enumerable: true,
58
64
  configurable: true,
59
65
  });
60
- this.#assignGingerly(true);
66
+ await this.#assignGingerly(true);
67
+ if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
68
+ await ce['<mount>'](ce, enhancedElement, this.#options);
69
+ }
61
70
  //attach any itemref references
62
71
  this.#attachItemrefs(enhancedElement);
63
72
  const et = ObsAttr(enhancedElement, 'itemref');
64
73
  et.addEventListener('attr-changed', this);
65
74
  this.isResolved = true;
75
+ return ce;
66
76
  }
67
77
  #alreadyAttached = new Set();
68
78
  #attachItemrefs(enhancedElement) {
@@ -94,12 +104,20 @@ export class Newish {
94
104
  if (ce === undefined) {
95
105
  throw 500;
96
106
  }
107
+ let foundArray = false;
108
+ const hasArrFilter = 'arr=>' in ce && typeof ce['arr=>'] === 'function';
109
+ const ref = this.#ref.deref();
97
110
  while (this.queue.length > 0) {
98
111
  const fi = this.queue.shift();
99
112
  //TODO: Provide support for a virtual slice of a very large list
100
113
  //TODO: Maybe should check if iterable rather than an array?
101
114
  if (Array.isArray(fi)) {
102
- ce[sym] = fi;
115
+ foundArray = true;
116
+ let filtered = fi;
117
+ if (hasArrFilter) {
118
+ filtered = await (ce['arr=>'])(ce, fi, ref, this.#options);
119
+ }
120
+ ce[arr] = filtered;
103
121
  actions.add('ishListAssigned');
104
122
  }
105
123
  else {
@@ -108,7 +126,13 @@ export class Newish {
108
126
  actions.add('ishAssigned');
109
127
  }
110
128
  }
111
- const ref = this.#ref.deref();
129
+ if (fromDo && !foundArray) {
130
+ const filtered = await (ce['arr=>'])(ce, undefined, ref, this.#options);
131
+ if (filtered !== undefined) {
132
+ ce[arr] = filtered;
133
+ actions.add('ishListAssigned');
134
+ }
135
+ }
112
136
  if (ref) {
113
137
  ref.dispatchEvent(new IshEvent(Array.from(actions)));
114
138
  }
package/Newish.ts CHANGED
@@ -1,60 +1,60 @@
1
- import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
1
+ import { BindishOptions, HasIsh, Ishcycle } from './ts-refs/mount-observer/types.js';
2
2
 
3
3
  export {waitForEvent} from './waitForEvent.js';
4
4
  import {ObsAttr} from './ObsAttr.js';
5
5
  import {splitRefs} from './refid/splitRefs.js';
6
6
  import {getIsh} from './refid/getIsh.js';
7
- import {sym} from './refid/regIsh.js';
7
+ import {arr} from './refid/secretKeys.js';
8
8
  export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
9
9
  export class Newish implements EventListenerObject {
10
10
  queue: Array<any> = [];
11
11
  isResolved = false;
12
- #ce: HTMLElement | undefined;
12
+ #ce: Ishcycle | undefined;
13
13
  #ref: WeakRef<Element>;
14
14
 
15
- //#assigner: undefined | Assigner = undefined;
16
15
  #options: BindishOptions;
17
-
18
- constructor(enhancedElement: Element,
16
+ #args: [enhancedElement: Element, target: Node, itemscope: string] | undefined;
17
+ constructor(
18
+ enhancedElement: Element,
19
19
  target: Node,
20
- itemscope: string, options?: BindishOptions){
20
+ itemscope: string,
21
+ options?: BindishOptions
22
+ ){
23
+ this.#args = [enhancedElement, target, itemscope];
21
24
  this.#options = options || {assigner: Object.assign};
22
25
  this.#ref = new WeakRef(enhancedElement);
23
- this.#do(enhancedElement, target, itemscope);
24
26
  }
25
- handleEvent(event: Event): void {
27
+ handleEvent(): void {
26
28
  const enhancedElement = this.#ref.deref();
27
29
  if(!enhancedElement) return;
28
30
  this.#attachItemrefs(enhancedElement);
29
31
  }
30
32
 
31
- async #do(
32
- enhancedElement: Element,
33
- target: Node,
34
- itemscope: string
35
- ){
33
+ async do(){
34
+ const [enhancedElement, target, itemscope] = this.#args!;
35
+ this.#args = undefined;
36
36
  if((<any>enhancedElement)[attached] === true) return;
37
37
  (<any>enhancedElement)[attached] = true;
38
- const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
39
-
40
- const initPropVals = (<any>enhancedElement)['ish'];
41
- if(enhancedElement instanceof HTMLElement){
42
- if(enhancedElement.dataset.ish){
43
- const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
44
- this.queue.push(parsedHostProps);
45
- }
38
+ const options = this.#options;
39
+ const {initPropVals, ctr} = options;
40
+ let ce: Ishcycle;
41
+ if(ctr === undefined){
42
+ const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
43
+
44
+ const initPropVals = (<any>enhancedElement)['ish'];
45
+
46
+ const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
47
+ const isInstance = initPropVals instanceof resolvedConstructor
48
+ ce = isInstance ? initPropVals : new resolvedConstructor() as Ishcycle;
49
+ if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
50
+ }else{
51
+ ce = new ctr();
52
+ if(initPropVals !== undefined) this.queue.push(initPropVals);
46
53
  }
47
-
48
-
49
- const resolvedConstructor = ctr.constructor.name === 'AsyncFunction' ? await ctr() : ctr;
50
- const isInstance = initPropVals instanceof resolvedConstructor
51
- const ce = isInstance ? initPropVals : new resolvedConstructor();
52
- if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
53
-
54
- if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
55
- await ce['<mount>'](ce, enhancedElement, this.#options)
54
+ if('tbd' in ce && typeof ce['tbd'] === 'function'){
55
+ await ce['tbd'](ce, enhancedElement, this.#options);
56
56
  }
57
-
57
+
58
58
  this.#ce = ce;
59
59
  const self = this;
60
60
  Object.defineProperty(enhancedElement, 'ish', {
@@ -69,12 +69,16 @@ export class Newish implements EventListenerObject {
69
69
  enumerable: true,
70
70
  configurable: true,
71
71
  });
72
- this.#assignGingerly(true);
72
+ await this.#assignGingerly(true);
73
+ if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
74
+ await ce['<mount>'](ce, enhancedElement as HasIsh & Element, this.#options)
75
+ }
73
76
  //attach any itemref references
74
77
  this.#attachItemrefs(enhancedElement);
75
78
  const et = ObsAttr(enhancedElement, 'itemref');
76
79
  et.addEventListener('attr-changed', this);
77
80
  this.isResolved = true;
81
+ return ce;
78
82
  }
79
83
 
80
84
 
@@ -110,12 +114,20 @@ export class Newish implements EventListenerObject {
110
114
  if(ce === undefined){
111
115
  throw 500;
112
116
  }
117
+ let foundArray = false;
118
+ const hasArrFilter = 'arr=>' in ce && typeof ce['arr=>'] === 'function';
119
+ const ref = this.#ref.deref();
113
120
  while(this.queue.length > 0 ){
114
121
  const fi = this.queue.shift();
115
122
  //TODO: Provide support for a virtual slice of a very large list
116
123
  //TODO: Maybe should check if iterable rather than an array?
117
124
  if(Array.isArray(fi)){
118
- (<any>ce)[sym] = fi;
125
+ foundArray = true;
126
+ let filtered = fi as any | undefined;
127
+ if(hasArrFilter){
128
+ filtered = await (ce['arr=>']!)(ce, fi, ref! as HasIsh & Element, this.#options);
129
+ }
130
+ (<any>ce)[arr] = filtered;
119
131
  actions.add('ishListAssigned');
120
132
  }else{
121
133
  const {assigner} = this.#options;
@@ -124,7 +136,14 @@ export class Newish implements EventListenerObject {
124
136
  }
125
137
 
126
138
  }
127
- const ref = this.#ref.deref();
139
+ if(fromDo && !foundArray){
140
+ const filtered = await (ce['arr=>']!)(ce, undefined, ref! as HasIsh & Element, this.#options);
141
+ if(filtered !== undefined){
142
+ (<any>ce)[arr] = filtered;
143
+ actions.add('ishListAssigned');
144
+ }
145
+ }
146
+
128
147
  if(ref){
129
148
  ref.dispatchEvent(new IshEvent(Array.from(actions)));
130
149
  }
package/bindish.js CHANGED
@@ -8,7 +8,8 @@ export async function bindishIt(scopes, target, options) {
8
8
  const itemscope = scope.getAttribute('itemscope');
9
9
  if (itemscope && !(scope.ish instanceof HTMLElement)) {
10
10
  const { Newish } = await import('./Newish.js');
11
- new Newish(scope, target, itemscope, options);
11
+ const newIsh = new Newish(scope, target, itemscope, options);
12
+ await newIsh.do();
12
13
  }
13
14
  }
14
15
  }
package/bindish.ts CHANGED
@@ -15,7 +15,8 @@ export async function bindishIt(scopes: Array<Element>, target: Node, options?:
15
15
  const itemscope = scope.getAttribute('itemscope');
16
16
  if(itemscope && !((<any>scope).ish instanceof HTMLElement)){
17
17
  const {Newish} = await import('./Newish.js');
18
- new Newish(scope, target, itemscope, options);
18
+ const newIsh = new Newish(scope, target, itemscope, options);
19
+ await newIsh.do()
19
20
  }
20
21
  }
21
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
package/refid/regIsh.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const guid = 'La8Cx9vHsUOd03WomqdnPw';
2
2
  export const sym = Symbol.for(guid);
3
+ import { arr } from './secretKeys.js';
3
4
  export function regIsh(scope, name, ctr) {
4
5
  let map = scope[sym];
5
6
  if (map === undefined) {
@@ -12,7 +13,7 @@ export function regIsh(scope, name, ctr) {
12
13
  map.set(name, ctr);
13
14
  ctr.prototype[Symbol.iterator] = function () {
14
15
  var index = -1;
15
- var data = this[sym];
16
+ var data = this[arr];
16
17
  return {
17
18
  next: function () {
18
19
  return {
package/refid/regIsh.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {IshCtr} from '../ts-refs/mount-observer/types';
2
2
  export const guid = 'La8Cx9vHsUOd03WomqdnPw'
3
3
  export const sym = Symbol.for(guid);
4
+ import {arr} from './secretKeys.js';
4
5
 
5
6
  export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr:IshCtr){
6
7
  let map = (<any>scope)[sym] as Map<string, IshCtr>;
@@ -14,7 +15,7 @@ export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr
14
15
  map.set(name, ctr);
15
16
  ctr.prototype[Symbol.iterator] = function() {
16
17
  var index = -1;
17
- var data = this[sym];
18
+ var data = this[arr];
18
19
 
19
20
  return {
20
21
  next: function() {
@@ -0,0 +1,5 @@
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');
@@ -0,0 +1,5 @@
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');
@@ -216,12 +216,20 @@ export interface BindishOptions{
216
216
  * to indicate that the initial
217
217
  */
218
218
  csr?: boolean,
219
+ ctr?: {new() : Ishcycle},
220
+ initPropVals?: any,
221
+ }
222
+
223
+ //TODO: move to mount observer
224
+ export interface HasIsh {
225
+ ish: any;
219
226
  }
220
227
 
221
228
  export interface Ishcycle{
222
- '<mount>'?(self: Ishcycle, el: Element, options: BindishOptions): Promise<void>;
229
+ '<mount>'?(self: Ishcycle, el: Element & HasIsh, options: BindishOptions): Promise<void>;
223
230
  //'</dismount>'?(self: IshFace, el: Element): Promise<void>;
224
- '<inScope>'?(self: Ishcycle, el: Element, options: BindishOptions): Promise<void>;
231
+ '<inScope>'?(self: Ishcycle, el: Element & HasIsh, options: BindishOptions): Promise<void>;
232
+ 'arr=>'?(self: Ishcycle, arr: any[] | undefined, el: Element & HasIsh, options: BindishOptions): Promise<void | any[]>;
225
233
  //'</outOfScope>'?(self: IshFace, el: Element): Promise<void>;
226
234
  }
227
235
 
@@ -184,10 +184,7 @@ export interface PIP<TProp = any, TElement = Element> extends EventListenerObjec
184
184
  readonly outEvtName: string;
185
185
  }
186
186
 
187
- //TODO: move to mount observer
188
- export interface HasIsh {
189
- ish: EventTarget;
190
- }
187
+
191
188
 
192
189
  export interface HasIshList {
193
190
  ishList: Array<any>;
@@ -190,6 +190,7 @@ export interface IshConfig<TProps = any, TActions = TProps, ETProps = TProps>{
190
190
  isSleepless?: boolean;
191
191
  xform?: XForm<TProps, TActions>;
192
192
  inScopeXForms?: {[key: CSSQuery]: XForm<TProps, TActions>};
193
+ ishListCountProp?: keyof TProps & string;
193
194
  }
194
195
  export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps> extends IshConfig<TProps, TActions, ETProps>{
195
196
  mainTemplate?: string | HTMLTemplateElement;