mount-observer 0.0.102 → 0.0.103

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,12 +1,12 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.102",
3
+ "version": "0.0.103",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
7
7
  "devDependencies": {
8
- "@playwright/test": "1.55.0",
9
- "spa-ssi": "0.0.9"
8
+ "@playwright/test": "1.55.1",
9
+ "spa-ssi": "0.0.23"
10
10
  },
11
11
  "exports": {
12
12
  ".": {
@@ -53,6 +53,10 @@
53
53
  "default": "./refid/camelToKebab.js",
54
54
  "types": "./refid/camelToKebab.ts"
55
55
  },
56
+ "./refid/refid/genIds.js": {
57
+ "default": "./refid/refid/genIds.js",
58
+ "types": "./refid/refid/genIds.ts"
59
+ },
56
60
  "./refid/getAdjRefs.js": {
57
61
  "default": "./refid/getAdjRefs.js",
58
62
  "types": "./refid/getAdjRefs.ts"
@@ -65,6 +69,10 @@
65
69
  "default": "./refid/getCount.js",
66
70
  "types": "./refid/getCount.ts"
67
71
  },
72
+ "./refid/itemprops.js": {
73
+ "default": "./refid/itemprops.js",
74
+ "types": "./refid/itemprops.ts"
75
+ },
68
76
  "./refid/joinMatching.js": {
69
77
  "default": "./refid/joinMatching.js",
70
78
  "types": "./refid/joinMatching.ts"
@@ -0,0 +1,259 @@
1
+ # Auto generated id polyfill
2
+
3
+ *mount-observer* has a polyfill for [this proposal](https://github.com/whatwg/html/issues/11585), but with some differences due to the limited ability a polyfill can provide compared to the platform.
4
+
5
+ ## Installation
6
+
7
+ Any DOM fragment that gets observed by the MountObserver class instance will automatically apply the rules discussed below.
8
+
9
+ In the absence of such observing, call:
10
+
11
+ ```JavaScript
12
+ import {genIds} from 'mount-observer/refid/genIds.js';
13
+ genIds(oElementContainer);
14
+ ```
15
+
16
+ ## Activation
17
+
18
+ To activate a scoped id generation, add attribute -id to the last streamed element inside either the fieldset element, or an element adorned by the itemscope attribute, or the (Shadow) root.
19
+
20
+ If the -id attribute is not added to the last streamed element, but elsewhere, then the functionality will likely work the same, but may possibly miss some elements after the attribute, in the unlikely event that the auto generated id's are created prior to some additional elements streaming in.
21
+
22
+ ## Example 1
23
+
24
+ ```html
25
+ <fieldset disabled>
26
+ <label>
27
+ LHS: <input data-id={{lhs}}>
28
+ </label>
29
+
30
+ <label for=rhs>
31
+ RHS: <input data-id={{rhs}}>
32
+ </label>
33
+
34
+ <template -id defer-🎚️ 🎚️='on if isEqual, based on #{{lhs}} and #{{rhs}}.'>
35
+ <div>LHS === RHS</div>
36
+ </template>
37
+ </fieldset>
38
+ ```
39
+
40
+ adjusts the DOM so as to become:
41
+
42
+ ```html
43
+ <fieldset>
44
+ <label>
45
+ LHS: <input id=gid-0 data-id=lhs>
46
+ </label>
47
+
48
+ <label for=rhs>
49
+ RHS: <input id=gid-1 data-id=rhs>
50
+ </label>
51
+
52
+ <template 🎚️='on if isEqual, based on #gid-0 and #gid-1.'>
53
+ <div>LHS === RHS</div>
54
+ </template>
55
+ </fieldset>
56
+ ```
57
+
58
+ Note that the numbers after gid- will vary depending on previous DOM elements that may have been processed by the ID generator.
59
+
60
+ Note the use of the "disabled" attribute on the fieldset element, and the defer-🎚️ attributes, both of which get removed after the id auto generation completes. The idea is that while the live DOM tree has these attributes, allowing user interactivity could be problematic before the id's are generated, so at a minimum, we should disable input elements, and prevent [enhancements from loading](https://github.com/WICG/webcomponents/issues/1000) until the id connection is established, scoped preferably by fieldset elements, or itemscope attributes, or the root document as a last resort.
61
+
62
+ The reason why we keep the names lhs, rhs in the data-id attribute after stripping away curly braces and other side-effect inducing symbols, is that some libraries will want to refer to the name that was used to generate the id's.
63
+
64
+
65
+ ## Creating id references with global or built in attributes
66
+
67
+ Again, because 1. unlike the platform, we can't manipulate the server-streamed DOM before the browser sees it, and 2. we don't want to "confuse" the browser by creating nonsensical id reference connections that aren't valid, even temporarily, this polyfill opts to use data-* attributes as a way of staging the dynamic attribute adjustments. So for example:
68
+
69
+ ```html
70
+ <fieldset disabled>
71
+ <scratch-box>
72
+ <label slot=label data-for={{createDemo}}>Create demo</label>
73
+ <input data-id="{{@ createDemo}}" type=checkbox>
74
+ </scratch-box>
75
+ <scratch-box>
76
+ <label slot=label data-for={{writeArticle}}>Write article</label>
77
+ <input data-id="{{@ writeArticle}}" type=checkbox>
78
+ </scratch-box>
79
+ <scratch-box>
80
+ <label slot=label data-for={{exercise}}>Exercise</label>
81
+ <input -id data-id="{{@ exercise}}" type=checkbox>
82
+ </scratch-box>
83
+ </fieldset>
84
+ ```
85
+
86
+ becomes
87
+
88
+ ```html
89
+ <fieldset disabled>
90
+ <scratch-box enh-be-importing=scratch-box/root.mjs>
91
+ <label slot=label for=gid-0>Create demo</label>
92
+ <input id=gid-0 name=createDemo data-id=createDemo type=checkbox>
93
+ </scratch-box>
94
+ <scratch-box>
95
+ <label slot=label for=gid-1>Write article</label>
96
+ <input id=gid-1 name=writeArticle data-id=writeArticle type=checkbox>
97
+ </scratch-box>
98
+ <scratch-box>
99
+ <label slot=label for=gid-2>Exercise</label>
100
+ <input id=gid-2 name=exercise data-id=exercise type=checkbox>
101
+ </scratch-box>
102
+ </fieldset>
103
+ ```
104
+
105
+ It is often the case that the name we want to use to auto generate the unique id's will match the "name" attribute we want to assign the element, and/or the itemprop and/or the class and/or the part. This can be done in a few ways.
106
+
107
+ ## Side Effects from dynamic data-id attribute
108
+
109
+ ```html
110
+ <form>
111
+ <fieldset disabled>
112
+ <label>
113
+ LHS: <input class=my-class data-id="{{@. lhs}}">
114
+ </label>
115
+
116
+ <label for=rhs>
117
+ RHS: <span contenteditable part=my-part data-id="{{|% rhs}}">
118
+ </label>
119
+
120
+ <template -id defer-🎚️ 🎚️='on if isEqual, based on #{{lhs}} and #{{rhs}}.'>
121
+ <div>LHS === RHS</div>
122
+ </template>
123
+ </fieldset>
124
+ </form>
125
+ ```
126
+
127
+ results in
128
+
129
+ ```html
130
+ <form>
131
+ <fieldset>
132
+ <label>
133
+ LHS: <input name=lhs class="my-part lhs" id=gid-0 data-id=lhs>
134
+ </label>
135
+
136
+ <label for=rhs>
137
+ RHS: <span itemprop=rhs part="my-part rhs" id=gid-1 data-id=rhs>
138
+ </label>
139
+
140
+ <template 🎚️='on if isEqual, based on #gid-0 and #gid-1.'>
141
+ <div>LHS === RHS</div>
142
+ </template>
143
+ </fieldset>
144
+ </form>
145
+ ```
146
+
147
+ So we are using some special symbols to correspond with key attributes:
148
+
149
+ Symbol | Translates to | Connection / meaning |
150
+ |--------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
151
+ | # | id | # used by css for id, also bookmarks in urls that points to id's |
152
+ | \| | itemprop | "Pipe" is kind of close to itemprop, and is half of a dollar sign, and it kind of looks like an I |
153
+ | @ | name | Second letter of name. Also, common in social media sites/github to type this letter in order to select someone's name. |
154
+ | $ | itemscope + itemprop | Combination of S for Scope and Pipe which resembles itemprop a bit |
155
+ | % | part | Starts with p, percent is used for indicating what proportion something is. |
156
+ | . | class | css selector |
157
+
158
+ These match the symbols used in the [template instantiation productivity proposal](https://github.com/WICG/webcomponents/issues/1013#issuecomment-2257557589).
159
+
160
+ The examples that follow go in the opposite direction -- we "infer" the id generating name based on either the name of the element, or one of the key attributes
161
+
162
+ ## By tag name
163
+
164
+ Id's based on the element name
165
+
166
+ ```html
167
+ <ways-of-science itemscope>
168
+ <carrot-nosed-woman #></carrot-nosed-woman>
169
+ <a-duck #></a-duck>
170
+ <template -id defer-🎚️
171
+ 🎚️="on based on #{{carrot-nosed-woman}}::weight-change and #{{a-duck}}::molting."
172
+ onchange="event.r = Math.abs(event.args[0] - event.args[1]) < 10"
173
+ >
174
+ <div>A witch!</div>
175
+ <div>Burn her!</div>
176
+ </template>
177
+ </ways-of-science>
178
+ ```
179
+
180
+ results in:
181
+
182
+ ```html
183
+ <ways-of-science itemscope>
184
+ <carrot-nosed-woman id=gid-0 data-id=carrot-nosed-woman></carrot-nosed-woman>
185
+ <a-duck id=gid-1 data-id=a-duck></a-duck>
186
+ <template
187
+ 🎚️="on based on #gid-0::weight-change and #gid-1::molting."
188
+ onchange="event.r = Math.abs(event.args[0] - event.args[1]) < 10"
189
+ >
190
+ <div>A witch!</div>
191
+ <div>Burn her!</div>
192
+ </template>
193
+ </ways-of-science>
194
+ ```
195
+
196
+ ## By N@me
197
+
198
+ ```html
199
+ <form>
200
+ <fieldset disabled>
201
+ <input name=isHappy type="checkbox" @>
202
+ <template -id defer-🎚️ 🎚️='on when #{{isHappy}}.'>
203
+ <my-content></my-content>
204
+ </template>
205
+ </fieldset>
206
+ </form>
207
+ ```
208
+
209
+ results in:
210
+
211
+ ```html
212
+ <form>
213
+ <fieldset>
214
+ <input name=isHappy id=gid-0 data-id=isHappy type="checkbox">
215
+ <template 🎚️='on when #gid-0.'>
216
+ <my-content></my-content>
217
+ </template>
218
+ </fieldset>
219
+ </form>
220
+ ```
221
+
222
+ ## By |temprop
223
+
224
+ ```html
225
+ <form>
226
+ <fieldset disabled>
227
+ <data value=true itemprop=isHappy hidden |></data>
228
+ <template -id defer-🎚️ 🎚️='on when #{{isHappy}}.'>
229
+ <my-content></my-content>
230
+ </template>
231
+ </fieldset>
232
+ </form>
233
+ ```
234
+
235
+ results in:
236
+
237
+ ```html
238
+ <form>
239
+ <fieldset>
240
+ <data value=true data-id=isHappy id=gid-0 itemprop=isHappy hidden></data>
241
+ <template 🎚️='on when #gid-0.'>
242
+ <my-content></my-content>
243
+ </template>
244
+ </fieldset>
245
+ </form>
246
+ ```
247
+
248
+ <!--
249
+ ## By Itemscope
250
+
251
+ ```html
252
+ <table>
253
+ <tbody>
254
+ <tr itemscope=myRowHandler #>
255
+ </tr>
256
+ </tbody>
257
+ </table>
258
+ ```
259
+ -->
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ function getScopedChildren(element, lookup) {
3
+ if (lookup === undefined)
4
+ lookup = {};
5
+ for (const child of element.children) {
6
+ const itemprop = child.getAttribute('itemprop');
7
+ if (itemprop !== null) {
8
+ const lookupItemProp = lookup[itemprop];
9
+ if (lookupItemProp) {
10
+ if (!Array.isArray(lookupItemProp)) {
11
+ lookup[itemprop] = [lookupItemProp];
12
+ }
13
+ lookup[itemprop].push(child);
14
+ }
15
+ else {
16
+ lookup[itemprop] = child;
17
+ }
18
+ }
19
+ if (!child.hasAttribute('itemscope')) {
20
+ getScopedChildren(child, lookup);
21
+ }
22
+ }
23
+ }
24
+ Object.defineProperty(Element.prototype, 'itemprops', {
25
+ get() {
26
+ if (!this.hasAttribute('itemscope'))
27
+ return undefined;
28
+ return getScopedChildren(this);
29
+ }
30
+ });
@@ -0,0 +1,27 @@
1
+ function getScopedChildren(element: Element, lookup?: {[key: string]: Element | Element[]}){
2
+ if(lookup === undefined) lookup = {};
3
+ for(const child of element.children){
4
+ const itemprop = child.getAttribute('itemprop');
5
+ if(itemprop !== null){
6
+ const lookupItemProp = lookup[itemprop]
7
+ if(lookupItemProp){
8
+ if(!Array.isArray(lookupItemProp)){
9
+ lookup[itemprop] = [lookupItemProp];
10
+ }
11
+ (lookup[itemprop] as Element[]).push(child);
12
+ }else{
13
+ lookup[itemprop] = child;
14
+ }
15
+ }
16
+ if(!child.hasAttribute('itemscope')){
17
+ getScopedChildren(child, lookup);
18
+ }
19
+ }
20
+ }
21
+ Object.defineProperty(Element.prototype, 'itemprops', {
22
+ get(){
23
+ if(!this.hasAttribute('itemscope')) return undefined;
24
+ return getScopedChildren(this);
25
+ }
26
+ });
27
+
@@ -0,0 +1,41 @@
1
+ import {IEnhancement, BEAllProps, EMC} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps extends IEnhancement{
4
+
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps{
8
+ crudeDispatchRules: Array<CrudeDispatchRule>,
9
+ dispatchRules: Array<DispatchRule>
10
+ }
11
+
12
+ export type DispatchStatement = string;
13
+
14
+ export interface CrudeDispatchRule{
15
+ dispatchOn?: string,
16
+ dispatchOnPropChange?: string,
17
+ qualifiers: string,
18
+ dispatch: string,
19
+ }
20
+
21
+ export interface DispatchRule extends CrudeDispatchRule{
22
+
23
+ bubbles?: boolean,
24
+ cancelable?: boolean,
25
+ composed?: boolean,
26
+ replace?: boolean,
27
+ }
28
+
29
+ export type AP = AllProps;
30
+
31
+ export type PAP = Partial<AP>;
32
+
33
+ export type ProPAP = Promise<PAP>;
34
+
35
+ export type BAP = AP & BEAllProps;
36
+
37
+ export interface Actions{
38
+ //onCamelized(self: this): ProPAP;
39
+ finishParsing(self: BAP): PAP;
40
+ hydrate(self: BAP): ProPAP;
41
+ }
@@ -10,8 +10,10 @@ export interface EndUserProps extends IEnhancement<RenderingHTMLScriptElement>{
10
10
  with: Array<string>,
11
11
  }
12
12
 
13
+ export type Renderer = (vm: any, html: any) => any;
14
+
13
15
  export interface AP extends EndUserProps{
14
- renderer: (vm: any, html: any) => any,
16
+ renderer: Renderer,
15
17
  absorbingObject: AbsorbingObject
16
18
  }
17
19
 
@@ -0,0 +1,22 @@
1
+ import {IEnhancement, BEAllProps, EMC} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps extends IEnhancement{
4
+ on: string[],
5
+ props: string[],
6
+ }
7
+
8
+ export interface AllProps extends EndUserProps {}
9
+
10
+ export type AP = AllProps;
11
+
12
+ export type PAP = Partial<AP>;
13
+
14
+ export type ProPAP = Promise<PAP>;
15
+
16
+ export type BAP = AP & BEAllProps;
17
+
18
+
19
+ export interface Actions{
20
+ hydrate(self: BAP): void;
21
+ //finale(proxy: Proxy, target: Element, beDecorProps: BeDecoratedProps): void;
22
+ }
@@ -339,6 +339,8 @@ export interface UnitOfWork<TProps, TMethods = TProps, TElement = {}>{
339
339
  $?: ScopeInstructions<TProps, TMethods>,
340
340
 
341
341
  $$?: ScopedLoop<TProps, TMethods>,
342
+
343
+ nudge?: boolean,
342
344
  }
343
345
 
344
346
  export interface YieldSettings<TProps>{
@@ -1,6 +1,7 @@
1
1
  import { XForm } from "trans-render/types";
2
2
  import { PropInfo, Actions } from 'trans-render/froop/types';
3
3
  import {Scope} from 'trans-render/lib/types';
4
+ import { Compacts, WCConfig } from "../trans-render/froop/types";
4
5
 
5
6
  export interface PropInferenceCriteria{
6
7
  cssSelector: string,
@@ -8,7 +9,7 @@ export interface PropInferenceCriteria{
8
9
 
9
10
  }
10
11
 
11
- export interface EndUserProps<TProps = any, TActions = TProps> {
12
+ export interface EndUserProps<TProps = any, TActions = TProps> extends WCConfig<TProps, TActions>{
12
13
  aka?: string,
13
14
  inferProps?: boolean,
14
15
  xform?: XForm<TProps, TActions>,
@@ -16,7 +17,7 @@ export interface EndUserProps<TProps = any, TActions = TProps> {
16
17
  shadowRootMode?: ShadowRootMode,
17
18
  propDefaults?: Partial<TProps>,
18
19
  propInfo: Partial<{[key in keyof TProps]: PropInfo}>,
19
- compacts: Compacts<TProps, TActions>,
20
+ compacts?: Compacts<TProps, TActions>,
20
21
  targetScope?: Scope,
21
22
  assumeCSR?: boolean,
22
23
  propInferenceCriteria?: Array<PropInferenceCriteria>,