mount-observer 0.0.34 → 0.0.35

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/README.md CHANGED
@@ -11,7 +11,7 @@ Author: Bruce B. Anderson (with valuable feedback from @doeixd )
11
11
 
12
12
  Issues / pr's / polyfill: [mount-observer](https://github.com/bahrus/mount-observer)
13
13
 
14
- Last Update: 2024-6-11
14
+ Last Update: 2024-9-7
15
15
 
16
16
  ## Benefits of this API
17
17
 
@@ -118,7 +118,7 @@ This proposal would also include support for JSON and HTML module imports.
118
118
  Following an approach similar to the [speculation api](https://developer.chrome.com/blog/speculation-rules-improvements), we can add a script element anywhere in the DOM:
119
119
 
120
120
  ```html
121
- <script type="mountobserver" id=myMountObserver onmount="{
121
+ <script type="mountobserver" id=myMountObserver onload="{...}" onmount="{
122
122
  const {matchingElement} = event;
123
123
  const {localName} = matchingElement;
124
124
  if(!customElements.get(localName)) {
@@ -146,6 +146,11 @@ The "scope" of the observer would be the ShadowRoot containing the script elemen
146
146
 
147
147
  No arrays of settings would be supported within a single tag (as this causes issues as far as supporting a single onmount, ondismount, etc event attributes), but remember that the "on" criteria can be an array of selectors.
148
148
 
149
+ > [!Note]
150
+ > To support the event handlers above, I believe it would require that CSP solutions factor in both the inner content of the script element as well as all the event handlers via the string concatenation operator. I actually think such support is quite critical due to lack of support of import.meta.[some reference to the script element] not being available, as it was pre-ES Modules.
151
+
152
+
153
+
149
154
  ## Shadow Root inheritance
150
155
 
151
156
  Inside a shadow root, we can plop a script element, also with type "mountobserver", optionally giving it the same id as above:
@@ -163,6 +168,11 @@ If no id is found in the parent ShadowRoot (or in the parent window if the shado
163
168
 
164
169
  But if a matching id is found, then the values from the parent script element get merged in with the one in the child, with the child settings, including the event handling attributes.
165
170
 
171
+ > [!Note]
172
+ > The onload event is critical for a number of reasons, among them:
173
+ > 1. We need a way to inject non JSON serializable settings (described below) when necessary, and
174
+ > 2. We need a way to override settings in child Shadow DOM's programmatically in some cases.
175
+
166
176
  We will come back to some important [additional features](#creating-frameworks-that-revolve-around-moses) of using these script elements later, but first we want to cover the highlights of this proposal, in order to give more context as to what kinds of functionality these MOSEs can provide.
167
177
 
168
178
  ## Binding from a distance
@@ -750,6 +760,7 @@ The sky is the limit, but focusing on the first example, be-hive, they are:
750
760
 
751
761
  1. Managing, interpreting and parsing the attributes that add semantic enhancement vocabularies onto exiting elements.
752
762
  2. Establishing the "handshake" that imports the enhancement package, instantiates the enhancement, and passes properties that were previously assigned to the pre-enhanced element to the attached enhancement/behavior.
763
+ 3. Providing an inheritable "registry" of reusable scriptlets that can be leveraged in a declarative way.
753
764
 
754
765
  If one inspects the DOM, one will see grouped (already "parsed") MOSEs, like so:
755
766
 
@@ -765,7 +776,7 @@ Without the help of the synthesize method / Synthesizer base class, the develope
765
776
  The developer of each package defines their MOSE "template", and then syndicates it via the synthesize method:
766
777
 
767
778
  ```JavaScript
768
- mountObserver.synthesize(root: document | shadowRootNode, ctr: ({new() => Synthesizer}), mose: MOSE)
779
+ MountObserver.synthesize(root: document | shadowRootNode, ctr: ({new() => Synthesizer}), mose: MOSE)
769
780
  ```
770
781
 
771
782
  What this method does is it:
@@ -781,7 +792,7 @@ Then in our shadowroot, rather than adding a script type=mountobserver for every
781
792
  <be-hive></be-hive>
782
793
  ```
783
794
 
784
- And we can give each inheriting ShadowRoot a personality of its own by customizing the settings within that shadow scope, by (manually?) adding a MOSE with matching id that overrides the inheriting settings with custom settings:
795
+ And we can give each inheriting ShadowRoot a personality of its own by customizing the settings within that shadow scope, by manually adding a MOSE with matching id that overrides the inheriting settings with custom settings:
785
796
 
786
797
  ```html
787
798
  <be-hive>
@@ -793,3 +804,5 @@ And we can give each inheriting ShadowRoot a personality of its own by customizi
793
804
  </be-hive>
794
805
  ```
795
806
 
807
+
808
+
package/Synthesizer.ts CHANGED
@@ -30,7 +30,7 @@ export abstract class Synthesizer extends HTMLElement{
30
30
  const mose = s as MOSE;
31
31
  this.mountObserverElements.push(mose);
32
32
  this.activate(mose);
33
- })
33
+ });
34
34
  this.#mutationObserver = new MutationObserver(this.mutationCallback.bind(this));
35
35
  this.#mutationObserver.observe(this, init);
36
36
  this.inherit();
@@ -52,6 +52,7 @@ export abstract class Synthesizer extends HTMLElement{
52
52
 
53
53
  activate(mose: MOSE){
54
54
  if(!this.checkIfAllowed(mose)) return;
55
+ mose.dispatchEvent(new LoadEvent());
55
56
  const {init, do: d} = mose;
56
57
  const mi: MountInit = {
57
58
  do: d,
@@ -118,4 +119,12 @@ export class SynthesizeEvent extends Event{
118
119
  constructor(public mountObserverElement: MOSE) {
119
120
  super(SynthesizeEvent.eventName);
120
121
  }
122
+ }
123
+
124
+ export class LoadEvent extends Event {
125
+ static eventName = 'load';
126
+
127
+ constructor(){
128
+ super(LoadEvent.eventName);
129
+ }
121
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
@@ -0,0 +1,68 @@
1
+ import {IEnhancement, BEAllProps} from '../trans-render/be/types';
2
+ import { Specifier } from "../trans-render/dss/types";
3
+ import {AbsorbingObject, SharingObject} from '../trans-render/asmr/types';
4
+
5
+ export interface EndUserProps extends IEnhancement{
6
+ With?: Array<WithStatement>,
7
+ Between?: Array<BetweenStatement>,
8
+ with?: Array<WithStatement>,
9
+ between?: Array<BetweenStatement>,
10
+ }
11
+
12
+ export interface AllProps extends EndUserProps{
13
+ bindingRules: Array<BindingRule>,
14
+ bindings: Array<Binding>,
15
+ //partialBindingRules?: Array<BindingRule>,
16
+ isParsed?: boolean,
17
+ //parsedWith?: boolean,
18
+ //parsedBetween?: boolean,
19
+ rawStatements?: Array<string>
20
+ }
21
+
22
+ export type SignalEnhancement = 'be-value-added' | 'be-propagating' | undefined;
23
+
24
+ export interface BindingRule {
25
+
26
+ localProp?: string,
27
+ localEvent?: string,
28
+ remoteSpecifierString?: string,
29
+ remoteSpecifier?: Specifier,
30
+
31
+
32
+ }
33
+
34
+ export interface Binding {
35
+ //new and improved
36
+ localAbsObj: AbsorbingObject;
37
+ localShareObj: SharingObject;
38
+ remoteAbsObj: AbsorbingObject;
39
+ remoteShareObj: SharingObject;
40
+ //remoteRef: WeakRef<Element>;
41
+ }
42
+
43
+ export type AP = AllProps;
44
+
45
+ export type PAP = Partial<AP>;
46
+
47
+ export type ProPAP = Promise<PAP>;
48
+
49
+ export type BAP = AP & BEAllProps;
50
+
51
+
52
+ export interface Actions{
53
+ noAttrs(self: BAP): ProPAP;
54
+ getBindings(self: BAP): ProPAP;
55
+ hydrate(self: BAP): ProPAP;
56
+ onRawStatements(self: BAP): void;
57
+ }
58
+
59
+ export type WithStatement = string;
60
+
61
+ export type BetweenStatement = string;
62
+
63
+ export type TriggerSource = 'local' | 'remote' | 'tie';
64
+
65
+ export interface SpecificityResult {
66
+ val?: any,
67
+ winner?: TriggerSource;
68
+ }
@@ -0,0 +1,69 @@
1
+ import {BEAllProps, IEnhancement} from '../trans-render/be/types';
2
+ import {StringWithAutocompleteOptions} from '../trans-render/types';
3
+ import { Specifier } from '../trans-render/dss/types';
4
+ import {AbsorbingObject} from '../trans-render/asmr/types';
5
+
6
+ export interface EndUserProps extends IEnhancement<HTMLElement>{
7
+ forAttr?: string,
8
+ //onInput?: string,
9
+ //onChange?: string,
10
+ //onLoad?: string,
11
+ //assignTo?: Array<Specifier>,
12
+ nameOfCalculator: string,
13
+ eventArg: string,
14
+ }
15
+
16
+ export interface AllProps extends EndUserProps{
17
+ calculator: {new: () => EventListenerObject},
18
+ // value: any;
19
+ // isParsed: boolean;
20
+ // attrExpr?: string | null;
21
+ scriptEl?: HTMLScriptElement;
22
+ publishEventType: 'input' | 'change' | 'load',
23
+ defaultEventType: StringWithAutocompleteOptions<
24
+ | 'input'
25
+ | 'change'
26
+ >,
27
+ forArgs: string[],
28
+ remoteSpecifiers: Array<Specifier>,
29
+ isAttached?: boolean,
30
+ isOutputEl?: boolean,
31
+ enhElLocalName: string,
32
+ categorized?: boolean,
33
+ remSpecifierLen?: number,
34
+ propToAO: {[key: string] : AbsorbingObject},
35
+ hasInlineEvent: boolean,
36
+ }
37
+
38
+ export type AP = AllProps;
39
+
40
+ export type PAP = Partial<AP>;
41
+
42
+ export type ProPAP = Promise<PAP>
43
+
44
+ // export interface Actions{
45
+ // parseForAttr(self: this): PAP;
46
+ // regOnInput(self: this): PAP;
47
+ // regOnChange(self: this): PAP;
48
+ // regOnLoad(self: this): PAP;
49
+ // genRemoteSpecifiers(self: this): PAP;
50
+ // hydrate(self: this): ProPAP;
51
+ // findScriptEl(self: this): PAP;
52
+ // //getArgs(self: this): PAP;
53
+ // //observe(self: this): ProPAP;
54
+ // importSymbols(self: this): ProPAP;
55
+ // //onValue(self: this): void;
56
+ // }
57
+
58
+ export type BAP = AP & BEAllProps;
59
+
60
+ export interface Actions{
61
+ categorizeEl(self: BAP): PAP;
62
+ parseForAttr(self: BAP): PAP;
63
+ getDefltEvtType(self: BAP): PAP;
64
+ findScriptEl(self: BAP): PAP;
65
+ importSymbols(self: BAP): ProPAP;
66
+ genRemoteSpecifiers(self: BAP): PAP;
67
+ seek(self: BAP): ProPAP;
68
+ hydrate(self: BAP): ProPAP;
69
+ }
@@ -0,0 +1,26 @@
1
+ import {IEnhancement, BEAllProps} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps<Exports=any> extends IEnhancement<HTMLScriptElement>{
4
+ // //guid?: string;
5
+ // //shareByID?: boolean;
6
+ // enabled?: boolean;
7
+ // beOosoom?: string;
8
+ preferAttrForBareImports?: boolean;
9
+ attached: boolean;
10
+ }
11
+
12
+ export interface AllProps<Exports=any> extends EndUserProps<Exports>{
13
+ exports?: Exports;
14
+
15
+ }
16
+
17
+ export type PAP = Partial<AllProps>;
18
+
19
+ export type ProPAP = Promise<PAP>
20
+
21
+
22
+ export interface Actions{
23
+ hydrate(ap: AllProps): Promise<PAP>;
24
+ }
25
+
26
+
@@ -0,0 +1,19 @@
1
+ import { BEAllProps, IEnhancement } from '../be-enhanced/types';
2
+
3
+ export interface EndUserProps extends IEnhancement {
4
+ }
5
+
6
+ export interface AP extends EndUserProps{
7
+ queue?: Array<any>,
8
+ itemCE?: string,
9
+ cnt?: number,
10
+ ref?: WeakRef<Element>,
11
+ }
12
+
13
+ export type PAP = Partial<AP>;
14
+
15
+ export type ProPAP = Promise<PAP>;
16
+
17
+ export interface Actions{
18
+ }
19
+
@@ -0,0 +1,28 @@
1
+ import {BVAEndUserProps, BVAAllProps, BVAActions} from '../be-value-added/types';
2
+ import {BEAllProps} from '../be-enhanced/types';
3
+
4
+ export interface EndUserProps extends BVAEndUserProps{
5
+ format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions,
6
+ locale?: string;
7
+ observeAttr?: string;
8
+ currency?: string;
9
+ }
10
+
11
+ export interface AllProps extends EndUserProps, BVAAllProps{
12
+ attached?: boolean;
13
+ intlDateFormat?: Intl.DateTimeFormat,
14
+ intlNumberFormat: Intl.NumberFormat,
15
+ }
16
+
17
+ export type AP = AllProps;
18
+
19
+ export type PAP = Partial<AP>;
20
+
21
+ export type ProPAP = Promise<PAP>;
22
+
23
+
24
+ export interface Actions extends BVAActions {
25
+ formatNumber(self: AP & BEAllProps): void;
26
+ formatDate(self: this): void;
27
+ onFormattingChange(self: this): PAP;
28
+ }
@@ -0,0 +1,21 @@
1
+ import {IEnhancement, BEAllProps} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps extends IEnhancement<HTMLInputElement>{
4
+ readVerb: 'readAsText' | 'readAsDataURL' | 'readAsArrayBuffer' | 'readAsBinaryString';
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps{
8
+ fileContents: any[];
9
+ }
10
+
11
+
12
+ export type AP = AllProps;
13
+
14
+ export type PAP = Partial<AP>;
15
+
16
+ export type ProPAP = Promise<PAP>;
17
+
18
+
19
+ export interface Actions {
20
+ hydrate(self: AP & BEAllProps): ProPAP
21
+ }
@@ -0,0 +1,26 @@
1
+ import {IEnhancement} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps extends IEnhancement{
4
+ propagate?: string[],
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps{
8
+ propagators: Map<string, EventTarget>;
9
+
10
+ }
11
+
12
+ export type AP = AllProps;
13
+ export type PAP = Partial<AP>;
14
+ export type ProPAP = Promise<PAP>;
15
+
16
+ export interface ISignal extends EventTarget{
17
+ value: any;
18
+ }
19
+
20
+
21
+ export interface Actions{
22
+ hydrate(self: this): ProPAP;
23
+ setKeyVal(key: string, val: any, tsKey?: string): Promise<EventTarget>;
24
+ getPropagator(key: string): Promise<EventTarget>;
25
+ getGate(prop: string, key?: string): Promise<ISignal>
26
+ }
@@ -0,0 +1,17 @@
1
+ import { BEAllProps, IEnhancement } from './ts-refs/be-enhanced/types';
2
+
3
+ export interface EndUserProps extends IEnhancement {
4
+
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps {}
8
+
9
+ export type AP = AllProps;
10
+
11
+ export type PAP = Partial<AP>;
12
+
13
+ export type ProPAP = Promise<PAP>;
14
+
15
+
16
+ export interface Actions{
17
+ }
@@ -500,4 +500,11 @@ export interface IObject$tring{
500
500
  parse(): Promise<void>;
501
501
  }
502
502
 
503
- export type ZeroOrMore<T> = T | Array<T> | undefined;
503
+ export type ZeroOrMore<T> = T | Array<T> | undefined;
504
+
505
+ /**
506
+ * https://x.com/mattpocockuk/status/1821926395380986219
507
+ */
508
+ export type StringWithAutocompleteOptions<TOptions> =
509
+ | (string & {})
510
+ | TOptions;