mount-observer 0.0.46 → 0.0.48

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/MountObserver.js CHANGED
@@ -57,6 +57,7 @@ export class MountObserver extends EventTarget {
57
57
  this.#calculatedSelector = calculatedSelector;
58
58
  return this.#calculatedSelector;
59
59
  }
60
+ //This method is called publicly from outside mount-observer -- keep it public
60
61
  async composeFragment(fragment, level) {
61
62
  const bis = fragment.querySelectorAll(`${inclTemplQry},${itemscopeQry}`);
62
63
  for (const bi of bis) {
@@ -418,9 +419,11 @@ export class MountObserver extends EventTarget {
418
419
  if (elToMount.matches(inclTemplQry)) {
419
420
  await this.#compose(elToMount, 0);
420
421
  }
421
- if (elToMount.matches(itemscopeQry)) {
422
+ }
423
+ for (const el of els) {
424
+ if (el.matches(itemscopeQry)) {
422
425
  const { Newish } = await import('./Newish.js');
423
- new Newish(elToMount, elToMount.getAttribute('itemscope'), assigner);
426
+ new Newish(el, el.getAttribute('itemscope'), assigner);
424
427
  }
425
428
  }
426
429
  this.#mount(elsToMount, initializing);
@@ -433,7 +436,7 @@ export class MountObserver extends EventTarget {
433
436
  }
434
437
  const refCountErr = 'mount-observer ref count mismatch';
435
438
  export const inclTemplQry = 'template[src^="#"]:not([hidden])';
436
- export const itemscopeQry = '[itemscope~="-"]';
439
+ export const itemscopeQry = '[itemscope*="-"]';
437
440
  // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
438
441
  /**
439
442
  * The `mutation-event` event represents something that happened.
package/MountObserver.ts CHANGED
@@ -68,6 +68,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
68
68
  return this.#calculatedSelector;
69
69
  }
70
70
 
71
+ //This method is called publicly from outside mount-observer -- keep it public
71
72
  async composeFragment(fragment: DocumentFragment, level: number){
72
73
  const bis = fragment.querySelectorAll(`${inclTemplQry},${itemscopeQry}`) as NodeListOf<HTMLTemplateElement>;
73
74
  for(const bi of bis){
@@ -433,9 +434,12 @@ export class MountObserver extends EventTarget implements IMountObserver{
433
434
  if(elToMount.matches(inclTemplQry)){
434
435
  await this.#compose(elToMount as HTMLTemplateElement, 0)
435
436
  }
436
- if(elToMount.matches(itemscopeQry)){
437
+
438
+ }
439
+ for(const el of els){
440
+ if(el.matches(itemscopeQry)){
437
441
  const {Newish} = await import('./Newish.js');
438
- new Newish(elToMount, elToMount.getAttribute('itemscope')!, assigner);
442
+ new Newish(el, el.getAttribute('itemscope')!, assigner);
439
443
  }
440
444
  }
441
445
  this.#mount(elsToMount, initializing);
@@ -453,7 +457,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
453
457
 
454
458
  const refCountErr = 'mount-observer ref count mismatch';
455
459
  export const inclTemplQry = 'template[src^="#"]:not([hidden])';
456
- export const itemscopeQry = '[itemscope~="-"]';
460
+ export const itemscopeQry = '[itemscope*="-"]';
457
461
  export interface MountObserver extends IMountObserver{}
458
462
 
459
463
  // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
package/Newish.js CHANGED
@@ -1,11 +1,10 @@
1
1
  export { waitForEvent } from './waitForEvent.js';
2
- export class Newish extends EventTarget {
2
+ export class Newish {
3
3
  queue = [];
4
4
  isResolved = false;
5
5
  #ce;
6
6
  #assigner = undefined;
7
7
  constructor(enhancedElement, itemscope, assigner) {
8
- super();
9
8
  this.#assigner = assigner;
10
9
  this.#do(enhancedElement, itemscope);
11
10
  }
@@ -42,8 +41,27 @@ export class Newish extends EventTarget {
42
41
  });
43
42
  this.#assignGingerly();
44
43
  }
44
+ //attach any itemref references
45
+ if (enhancedElement.hasAttribute('itemref')) {
46
+ const itemref = enhancedElement.getAttribute('itemref');
47
+ const itemrefList = itemref.split(' ');
48
+ let nextSibling = enhancedElement.nextElementSibling;
49
+ while (nextSibling) {
50
+ if (itemrefList.includes(nextSibling.id)) {
51
+ this.#ce.inScopeCallback(nextSibling);
52
+ itemrefList.splice(itemrefList.indexOf(nextSibling.id), 1);
53
+ }
54
+ if (itemrefList.length === 0)
55
+ break;
56
+ nextSibling = nextSibling.nextElementSibling;
57
+ }
58
+ if (itemrefList.length > 0) {
59
+ //TODO add an observer queue for the id found elsewhere
60
+ throw 'NI';
61
+ }
62
+ }
45
63
  this.isResolved = true;
46
- this.dispatchEvent(new Event('resolved'));
64
+ enhancedElement.dispatchEvent(new Event('ishAttached'));
47
65
  }
48
66
  async #assignGingerly() {
49
67
  let ce = this.#ce;
package/Newish.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export {waitForEvent} from './waitForEvent.js';
2
- export class Newish extends EventTarget{
2
+ export class Newish{
3
3
  queue: Array<any> = [];
4
4
  isResolved = false;
5
5
  #ce: HTMLElement | undefined;
@@ -7,7 +7,6 @@ export class Newish extends EventTarget{
7
7
  #assigner: undefined | ((target: any, source: any) => Promise<void>) = undefined;
8
8
 
9
9
  constructor(enhancedElement: Element, itemscope: string, assigner?: (target: any, source: any) => Promise<void>){
10
- super();
11
10
  this.#assigner = assigner;
12
11
  this.#do(enhancedElement, itemscope);
13
12
  }
@@ -44,9 +43,26 @@ export class Newish extends EventTarget{
44
43
  });
45
44
  this.#assignGingerly();
46
45
  }
47
-
46
+ //attach any itemref references
47
+ if(enhancedElement.hasAttribute('itemref')){
48
+ const itemref = enhancedElement.getAttribute('itemref')!;
49
+ const itemrefList = itemref.split(' ');
50
+ let nextSibling = enhancedElement.nextElementSibling;
51
+ while(nextSibling){
52
+ if(itemrefList.includes(nextSibling.id)){
53
+ (<any>this.#ce).inScopeCallback(nextSibling);
54
+ itemrefList.splice(itemrefList.indexOf(nextSibling.id), 1);
55
+ }
56
+ if(itemrefList.length === 0) break;
57
+ nextSibling = nextSibling.nextElementSibling;
58
+ }
59
+ if(itemrefList.length > 0){
60
+ //TODO add an observer queue for the id found elsewhere
61
+ throw 'NI';
62
+ }
63
+ }
48
64
  this.isResolved = true;
49
- this.dispatchEvent(new Event('resolved'));
65
+ enhancedElement.dispatchEvent(new Event('ishAttached'));
50
66
  }
51
67
 
52
68
  async #assignGingerly(){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
@@ -32,6 +32,10 @@
32
32
  "./waitForEvent.js": {
33
33
  "default": "./waitForEvent.js",
34
34
  "types": "./waitForEvent.ts"
35
+ },
36
+ "./waitForIsh.js": {
37
+ "default": "./waitForIsh.js",
38
+ "types": "./waitForIsh.ts"
35
39
  }
36
40
  },
37
41
  "files": [
@@ -0,0 +1,24 @@
1
+ import {IEnhancement, BEAllProps} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps extends IEnhancement{
4
+ statement: string;
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps{
8
+ listProp: string;
9
+ itemProp: string;
10
+ }
11
+
12
+ export type AP = AllProps;
13
+
14
+ export type PAP = Partial<AP>;
15
+
16
+ export type ProPAP = Promise<PAP>;
17
+
18
+ export type BAP = AP & BEAllProps;
19
+
20
+ export interface Actions{
21
+ parse(self: BAP): PAP;
22
+ hydrate(self: BAP): ProPAP;
23
+ }
24
+
@@ -170,10 +170,9 @@ export interface WCConfig<TProps = any, TActions = TProps, TPropInfo = PropInfo,
170
170
 
171
171
  }
172
172
 
173
- export type PropLookup<TProps = any> = Partial<{[key in keyof TProps]: PropInfo}>;
174
-
175
- export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps>{
176
-
173
+ export type PropLookup<TProps = any, TActions = any> = Partial<{[key in keyof TProps]: PropInfo<TProps, TActions>}>;
174
+ export type IshPropLookup<TProps = any, TActions = any> = Partial<{[key in keyof TProps]: IshPropInfo<TProps, TActions>}>;
175
+ export interface IshConfig<TProps = any, TActions = TProps, ETProps = TProps>{
177
176
  propDefaults?: Partial<{[key in keyof TProps]: TProps[key]}>;
178
177
  propInfo?: Partial<{[key in keyof TProps]: PropInfo}>;
179
178
  wrappers?: Partial<{[key in keyof TProps]: WrapperConfig<TProps>}>;
@@ -186,8 +185,13 @@ export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps>{
186
185
  hitch?: Hitches<TProps, TActions>;
187
186
  handlers?: Handlers<ETProps, TActions>;
188
187
  positractions?: Positractions<TProps, TActions>;
189
- mainTemplate?: string | HTMLTemplateElement;
188
+
190
189
  isSleepless?: boolean;
190
+ xform?: XForm<TProps, TActions>;
191
+ inScopeXForms?: Array<XForm<TProps, TActions>>;
192
+ }
193
+ export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps> extends IshConfig<TProps, TActions, ETProps>{
194
+ mainTemplate?: string | HTMLTemplateElement;
191
195
  }
192
196
 
193
197
  export type Positractions<TProps = any, TActions = TProps> =
@@ -287,14 +291,26 @@ export interface IActionProcessor{
287
291
  }
288
292
 
289
293
  type PropInfoTypes = "String" | "Number" | "Boolean" | "Object" | "RegExp";
290
- export interface PropInfo{
294
+
295
+ export interface IshPropInfo<TProps = any, TActions = any>{
291
296
  type?: PropInfoTypes;
292
297
  dry?: boolean;
293
- parse?: boolean;
294
298
  ro?: boolean;
299
+ propName?: string;
300
+ /**
301
+ * Allow for discarding what is passed in favor of a modified value such as a formatted value
302
+ * or filtered list
303
+ */
304
+ adjuster?:
305
+ |keyof TActions & string
306
+ |((nv: any) => any)
307
+ }
308
+
309
+ export interface PropInfo<TProps=any, TActions=any> extends IshPropInfo<TProps, TActions>{
310
+
311
+ parse?: boolean;
295
312
  def?: any;
296
313
  attrName?: string;
297
- propName?: string;
298
314
  /**
299
315
  * form associated read only property
300
316
  * https://web.dev/articles/more-capable-form-controls#:~:text=Form-associated%20custom%20elements%20aim%20to%20bridge%20the%20gap,associated%20with%20the%20form%2C%20like%20a%20browser-provided%20control.
@@ -317,6 +333,8 @@ export interface PropInfo{
317
333
  * examples: role, ariaRole
318
334
  */
319
335
  ip?: boolean;
336
+
337
+
320
338
  }
321
339
 
322
340
  export type ConstString = string;
package/waitForEvent.ts CHANGED
@@ -9,5 +9,5 @@ export function waitForEvent<TEvent extends Event = Event>(et: EventTarget, even
9
9
  }, {once: true});
10
10
  }
11
11
 
12
- })
12
+ });
13
13
  }
package/waitForIsh.js ADDED
@@ -0,0 +1,21 @@
1
+ export function waitForIsh(el) {
2
+ return new Promise((resolve, reject) => {
3
+ const ish = el['ish']; // [TODO] should we make this something that can
4
+ // be passed in, more generic function -- waitForProperty?
5
+ if (ish) {
6
+ resolve(ish);
7
+ }
8
+ else {
9
+ // If the element is not yet defined, wait for it to be defined
10
+ el.addEventListener('ishAttached', () => {
11
+ const ish = el['ish'];
12
+ if (ish) {
13
+ resolve(ish);
14
+ }
15
+ else {
16
+ reject(new Error('ish not found'));
17
+ }
18
+ }, { once: true });
19
+ }
20
+ });
21
+ }
package/waitForIsh.ts ADDED
@@ -0,0 +1,20 @@
1
+ export function waitForIsh(el: Element){
2
+ return new Promise((resolve, reject) => {
3
+ const ish = (<any>el)['ish']; // [TODO] should we make this something that can
4
+ // be passed in, more generic function -- waitForProperty?
5
+ if (ish) {
6
+ resolve(ish);
7
+ } else {
8
+ // If the element is not yet defined, wait for it to be defined
9
+ el.addEventListener('ishAttached', () => {
10
+ const ish = (<any>el)['ish'];
11
+ if (ish) {
12
+ resolve(ish);
13
+ } else {
14
+ reject(new Error('ish not found'));
15
+ }
16
+ }, { once: true });
17
+
18
+ }
19
+ });
20
+ }