mount-observer 0.0.94 → 0.0.96

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.94",
3
+ "version": "0.0.96",
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
@@ -4,12 +4,23 @@ const attrMap = {
4
4
  '@': 'name',
5
5
  '|': 'itemprop',
6
6
  };
7
+ const scopeMatches = '[itemscope],fieldset';
8
+ export function inScope(scopeFragment, el) {
9
+ const closest = el.closest(scopeMatches); //TODO account for itemref?
10
+ if (closest === null)
11
+ return true;
12
+ if (scopeFragment === closest)
13
+ return true;
14
+ if (scopeFragment.contains(closest))
15
+ return false;
16
+ return true;
17
+ }
7
18
  export function genIds(enhancedElement) {
8
- const { parentElement } = enhancedElement;
9
- if (parentElement === null)
10
- throw 404;
19
+ // const {parentElement} = enhancedElement;
20
+ // if(parentElement === null) throw 404;
21
+ const scopeFragment = (enhancedElement.closest(scopeMatches) || enhancedElement.getRootNode());
11
22
  //first find all elements with attribute #
12
- const hashIds = Array.from(parentElement.querySelectorAll('[\\#]'));
23
+ const hashIds = Array.from(scopeFragment.querySelectorAll('[\\#]')).filter(x => inScope(scopeFragment, x));
13
24
  const uniqueCheck = new Set();
14
25
  for (const hi of hashIds) {
15
26
  if (!(hi instanceof HTMLElement))
@@ -26,7 +37,23 @@ export function genIds(enhancedElement) {
26
37
  hi.dataset.id = `{{${sideEffects}${localName}}}`;
27
38
  hi.removeAttribute('#');
28
39
  }
29
- const dataIds = Array.from(parentElement.querySelectorAll('[data-id^="{{"][data-id$="}}"]'));
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
+ }
56
+ const dataIds = Array.from(scopeFragment.querySelectorAll('[data-id^="{{"][data-id$="}}"]')).filter(x => inScope(scopeFragment, x));
30
57
  const ids = [];
31
58
  for (const di of dataIds) {
32
59
  if (!(di instanceof HTMLElement))
@@ -41,8 +68,9 @@ export function genIds(enhancedElement) {
41
68
  throw 500;
42
69
  ids.push(id);
43
70
  }
44
- const allChildren = Array.from(parentElement.querySelectorAll('*'));
45
- allChildren.push(parentElement);
71
+ const allChildren = Array.from(scopeFragment.querySelectorAll('*')).filter(x => inScope(scopeFragment, x));
72
+ if (scopeFragment instanceof Element)
73
+ allChildren.push(scopeFragment);
46
74
  const idLookup = {};
47
75
  const base = 'gid';
48
76
  for (const child of allChildren) {
@@ -124,7 +152,7 @@ export function genIds(enhancedElement) {
124
152
  nudge(child, name);
125
153
  }
126
154
  }
127
- if ('disabled' in parentElement) {
128
- nudge(parentElement);
155
+ if (scopeFragment instanceof Element && 'disabled' in scopeFragment) {
156
+ nudge(scopeFragment);
129
157
  }
130
158
  }
package/refid/genIds.ts CHANGED
@@ -6,12 +6,23 @@ const attrMap = {
6
6
  '|': 'itemprop',
7
7
  };
8
8
 
9
+ const scopeMatches = '[itemscope],fieldset';
10
+
11
+ export function inScope(scopeFragment: DocumentFragment | Element, el: Element){
12
+ const closest = el.closest(scopeMatches);//TODO account for itemref?
13
+ if(closest === null) return true;
14
+ if(scopeFragment === closest) return true;
15
+ if(scopeFragment.contains(closest)) return false;
16
+ return true;
17
+ }
18
+
9
19
  export function genIds(enhancedElement: Element){
10
- const {parentElement} = enhancedElement;
11
- if(parentElement === null) throw 404;
20
+ // const {parentElement} = enhancedElement;
21
+ // if(parentElement === null) throw 404;
22
+ const scopeFragment = (enhancedElement.closest(scopeMatches) || enhancedElement.getRootNode()) as DocumentFragment | Element;
12
23
 
13
24
  //first find all elements with attribute #
14
- const hashIds = Array.from(parentElement.querySelectorAll('[\\#]'));
25
+ const hashIds = Array.from(scopeFragment.querySelectorAll('[\\#]')).filter(x => inScope(scopeFragment, x));
15
26
  const uniqueCheck = new Set();
16
27
  for(const hi of hashIds){
17
28
  if(!(hi instanceof HTMLElement)) continue;
@@ -27,7 +38,22 @@ export function genIds(enhancedElement: Element){
27
38
  hi.removeAttribute('#');
28
39
  }
29
40
 
30
- const dataIds = Array.from(parentElement.querySelectorAll('[data-id^="{{"][data-id$="}}"]'));
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
+ }
55
+
56
+ const dataIds = Array.from(scopeFragment.querySelectorAll('[data-id^="{{"][data-id$="}}"]')).filter(x => inScope(scopeFragment, x));
31
57
  const ids: Array<string> = [];
32
58
  for(const di of dataIds){
33
59
  if(!(di instanceof HTMLElement)) continue;
@@ -40,8 +66,8 @@ export function genIds(enhancedElement: Element){
40
66
  ids.push(id);
41
67
  }
42
68
 
43
- const allChildren = Array.from(parentElement.querySelectorAll('*'));
44
- allChildren.push(parentElement);
69
+ const allChildren = Array.from(scopeFragment.querySelectorAll('*')).filter(x => inScope(scopeFragment, x));
70
+ if(scopeFragment instanceof Element) allChildren.push(scopeFragment);
45
71
 
46
72
  const idLookup: {[key: string]: string} = {};
47
73
  const base = 'gid';
@@ -120,7 +146,7 @@ export function genIds(enhancedElement: Element){
120
146
  nudge(child, name);
121
147
  }
122
148
  }
123
- if('disabled' in parentElement){
124
- nudge(parentElement);
149
+ if(scopeFragment instanceof Element && 'disabled' in scopeFragment){
150
+ nudge(scopeFragment);
125
151
  }
126
152
  }
@@ -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 closest = this.closest('[itemscope]');
4
- if (closest === null)
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 closest = this.closest('[itemscope]') as HTMLElement;
6
- if(closest === null) return (<any>this.getRootNode()).host;
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, EnhancementInfo, IEnhancement, IW} from '../trans-render/be/types';
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';
@@ -4,7 +4,7 @@ import {BEAllProps, EMC, IEnhancement} from '../trans-render/be/types';
4
4
  //import {AP as BPAP, ISignal, Actions as BPActions} from 'be-propagating/types';
5
5
  //import {ElTypes, SignalRefType} from 'be-linked/types';
6
6
  //import { Propagator } from "../trans-render/froop/PropSvc";
7
- import {IPE, Specifier} from '../trans-render/dss/types';
7
+ import {Specifier} from '../trans-render/dss/types';
8
8
 
9
9
  export interface Element{
10
10
  hostish(): Promise<any>
@@ -62,7 +62,7 @@ export type SwitchStatement = string;
62
62
 
63
63
  export interface OneValueSwitch{
64
64
  ifPart: string,
65
- ipe: IPE,
65
+ specifier: Specifier,
66
66
  req?: boolean,
67
67
  }
68
68
 
@@ -76,8 +76,8 @@ export interface TwoPartOpStatement{
76
76
  }
77
77
 
78
78
  export interface TwoValueSwitch{
79
- lhsIPE: IPE,
80
- rhsIPE: IPE,
79
+ lhsSpecifier: Specifier,
80
+ rhsSpecifier: Specifier,
81
81
  req?: boolean,
82
82
  op?: Op,
83
83
  lhs?: ISide,
@@ -90,7 +90,7 @@ export interface TwoValueSwitch{
90
90
 
91
91
  }
92
92
 
93
- export interface Dependency extends IPE{}
93
+ export interface Dependency extends Specifier{}
94
94
 
95
95
  export interface CanBeSwitchedOn {
96
96
  switchedOn?: boolean,
@@ -1,6 +1,3 @@
1
- import { Scope } from '../lib/types'
2
- import { CSSQuery } from '../types';
3
-
4
1
  export type ID = `#${string}`;
5
2
  export type Host = `:host()`;
6
3
  export type Hostish = ``;
@@ -20,22 +17,24 @@ export type asOptions =
20
17
  | 'boolean|number'
21
18
  ;
22
19
  export type MindReadType = ``;
23
- export type TypeQualifier = `as ${asOptions}`;
20
+ export type TypeQualifier = `-as-${asOptions}`;
24
21
 
25
22
  export type ValExpression = `${PropPath | ConstVal | MindReadProp}${TypeQualifier | MindReadType}`;
26
23
 
27
24
  export type MindReadEvent = ``;
28
25
 
29
- export type EvtName = `::${string}`;
26
+ export type EventSpecifier = `::${string}`;
27
+
28
+ export type EventPart = MindReadEvent | EventSpecifier;
30
29
 
31
- export type DSS = `${Target}${ValExpression}${EvtName}`;
30
+ export type DSS = `${Target}${ValExpression}${EventPart}`;
32
31
 
33
32
 
34
33
  export interface Specifier {
35
34
  id?: string,
36
35
  prop?: string,
37
36
  path?: SubPropPath,
38
- evtName?: string,
37
+ evtName?: EventName,
39
38
  as?: asOptions,
40
39
  constVal?: any;
41
40
  enhKey?: string;
@@ -28,8 +28,7 @@ export interface RegExpExt<TStatementGroup = any>{
28
28
  dssKeys?: [string, string][],
29
29
  dssArrayKeys?: [string, string][],
30
30
  statementPartParser?: StatementPartParser,
31
- //ipeKeys?: [string, string][];
32
- // ipeArrayKeys?: [string, string][];
31
+
33
32
  }
34
33
 
35
34
  export interface StatementPartParser {