mount-observer 0.0.112 → 0.1.1
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/Events.js +62 -26
- package/Events.ts +52 -30
- package/MountObserver.js +285 -514
- package/MountObserver.ts +362 -538
- package/README.md +149 -56
- package/SharedMutationObserver.js +70 -0
- package/SharedMutationObserver.ts +96 -0
- package/attrCoordinates.js +93 -0
- package/attrCoordinates.ts +122 -0
- package/index.js +3 -0
- package/index.ts +22 -0
- package/loadImports.js +47 -0
- package/loadImports.ts +56 -0
- package/mediaQuery.js +86 -0
- package/mediaQuery.ts +113 -0
- package/package.json +11 -119
- package/playwright.config.ts +0 -1
- package/types.d.ts +104 -0
- package/whereAttr.js +174 -0
- package/whereAttr.ts +221 -0
- package/LICENSE +0 -21
- package/Newish.js +0 -145
- package/Newish.ts +0 -169
- package/ObsAttr.js +0 -18
- package/ObsAttr.ts +0 -18
- package/RootMutObs.js +0 -49
- package/RootMutObs.ts +0 -58
- package/Synthesizer.js +0 -125
- package/Synthesizer.ts +0 -130
- package/bindish.js +0 -15
- package/bindish.ts +0 -22
- package/compose.js +0 -148
- package/compose.ts +0 -164
- package/doCleanup.js +0 -31
- package/doCleanup.ts +0 -34
- package/getWhereAttrSelector.js +0 -83
- package/getWhereAttrSelector.ts +0 -92
- package/preloadContent.js +0 -44
- package/preloadContent.ts +0 -47
- package/readAttrs.ts +0 -60
- package/refid/README.md +0 -259
- package/refid/arr.js +0 -4
- package/refid/arr.ts +0 -4
- package/refid/camelToKebab.js +0 -4
- package/refid/camelToKebab.ts +0 -4
- package/refid/genIds.js +0 -190
- package/refid/genIds.ts +0 -177
- package/refid/getAdjRefs.js +0 -38
- package/refid/getAdjRefs.ts +0 -38
- package/refid/getContext.js +0 -13
- package/refid/getContext.ts +0 -14
- package/refid/getCount.js +0 -8
- package/refid/getCount.ts +0 -8
- package/refid/getIsh.js +0 -35
- package/refid/getIsh.ts +0 -37
- package/refid/hostish.js +0 -18
- package/refid/hostish.ts +0 -20
- package/refid/ism.js +0 -78
- package/refid/ism.ts +0 -81
- package/refid/itemprops.js +0 -60
- package/refid/itemprops.ts +0 -67
- package/refid/joinMatching.js +0 -56
- package/refid/joinMatching.ts +0 -54
- package/refid/nudge.js +0 -23
- package/refid/nudge.ts +0 -23
- package/refid/regIsh.js +0 -27
- package/refid/regIsh.ts +0 -31
- package/refid/secretKeys.js +0 -5
- package/refid/secretKeys.ts +0 -5
- package/refid/splitRefs.js +0 -6
- package/refid/splitRefs.ts +0 -6
- package/refid/stdVal.js +0 -15
- package/refid/stdVal.ts +0 -15
- package/refid/via.js +0 -114
- package/refid/via.ts +0 -113
- package/slotkin/affine.js +0 -39
- package/slotkin/affine.ts +0 -46
- package/slotkin/beKindred.js +0 -45
- package/slotkin/beKindred.ts +0 -55
- package/slotkin/getBreadth.js +0 -19
- package/slotkin/getBreadth.ts +0 -21
- package/slotkin/getFrag.js +0 -22
- package/slotkin/getFrag.ts +0 -21
- package/slotkin/toQuery.js +0 -12
- package/slotkin/toQuery.ts +0 -13
- package/slotkin/wrap.js +0 -13
- package/slotkin/wrap.ts +0 -18
- package/ts-refs/LICENSE +0 -21
- package/ts-refs/README.md +0 -18
- package/ts-refs/be-a-beacon/types.d.ts +0 -22
- package/ts-refs/be-alit/types.d.ts +0 -1
- package/ts-refs/be-based/types.d.ts +0 -32
- package/ts-refs/be-bound/types.d.ts +0 -65
- package/ts-refs/be-buttoned-up/types.d.ts +0 -21
- package/ts-refs/be-calculating/types.d.ts +0 -57
- package/ts-refs/be-clonable/types.d.ts +0 -28
- package/ts-refs/be-committed/types.d.ts +0 -26
- package/ts-refs/be-consoling/types.d.ts +0 -25
- package/ts-refs/be-counted/types.d.ts +0 -88
- package/ts-refs/be-delible/types.d.ts +0 -26
- package/ts-refs/be-directive/types.d.ts +0 -43
- package/ts-refs/be-dispatching/types.d.ts +0 -41
- package/ts-refs/be-elevating/types.d.ts +0 -55
- package/ts-refs/be-enhanced/types.d.ts +0 -32
- package/ts-refs/be-enhancing/types.d.ts +0 -31
- package/ts-refs/be-evanescent/types.d.ts +0 -20
- package/ts-refs/be-eventing/types.d.ts +0 -27
- package/ts-refs/be-exportable/types.d.ts +0 -26
- package/ts-refs/be-fetching/types.d.ts +0 -73
- package/ts-refs/be-flashy/types.d.ts +0 -27
- package/ts-refs/be-formalizing/types.d.ts +0 -29
- package/ts-refs/be-formidable/types.d.ts +0 -64
- package/ts-refs/be-giddy/types.d.ts +0 -26
- package/ts-refs/be-gingerly/types.d.ts +0 -19
- package/ts-refs/be-gone/types.d.ts +0 -24
- package/ts-refs/be-hashing-out/types.d.ts +0 -22
- package/ts-refs/be-hive/types.d.ts +0 -18
- package/ts-refs/be-imbued/types.d.ts +0 -30
- package/ts-refs/be-included/types.d.ts +0 -20
- package/ts-refs/be-inclusive/types.d.ts +0 -30
- package/ts-refs/be-intersectional/types.d.ts +0 -37
- package/ts-refs/be-intl/types.d.ts +0 -28
- package/ts-refs/be-invoking/types.d.ts +0 -28
- package/ts-refs/be-joining/types.d.ts +0 -26
- package/ts-refs/be-kvetching/types.d.ts +0 -24
- package/ts-refs/be-lazy/types.d.ts +0 -29
- package/ts-refs/be-literate/types.d.ts +0 -29
- package/ts-refs/be-mediating/types.d.ts +0 -34
- package/ts-refs/be-methodical/types.d.ts +0 -20
- package/ts-refs/be-modding/types.d.ts +0 -18
- package/ts-refs/be-observant/types.d.ts +0 -27
- package/ts-refs/be-observing/types.d.ts +0 -84
- package/ts-refs/be-parsed/types.d.ts +0 -19
- package/ts-refs/be-parsing/types.d.ts +0 -37
- package/ts-refs/be-persistent/types.d.ts +0 -66
- package/ts-refs/be-propagating/types.d.ts +0 -26
- package/ts-refs/be-reformable/types.d.ts +0 -48
- package/ts-refs/be-render-neutral/types.d.ts +0 -31
- package/ts-refs/be-scoped/types.d.ts +0 -24
- package/ts-refs/be-sharing/types.d.ts +0 -17
- package/ts-refs/be-switched/types.d.ts +0 -155
- package/ts-refs/be-typed/types.d.ts +0 -36
- package/ts-refs/be-value-added/types.d.ts +0 -34
- package/ts-refs/be-valued/types.d.ts +0 -22
- package/ts-refs/be-written/types.d.ts +0 -59
- package/ts-refs/css-charts/types.d.ts +0 -38
- package/ts-refs/css-echarts/types.d.ts +0 -13
- package/ts-refs/data-props/types.d.ts +0 -27
- package/ts-refs/do-inc/types.d.ts +0 -28
- package/ts-refs/do-invoke/types.d.ts +0 -28
- package/ts-refs/do-toggle/types.d.ts +0 -27
- package/ts-refs/em-bower/types.d.ts +0 -24
- package/ts-refs/fetch-for/types.d.ts +0 -37
- package/ts-refs/folder-picker/types.d.ts +0 -43
- package/ts-refs/for-fetch/doc.d.ts +0 -98
- package/ts-refs/for-fetch/types.d.ts +0 -83
- package/ts-refs/mount-observer/types.d.ts +0 -248
- package/ts-refs/mt-si/types.d.ts +0 -21
- package/ts-refs/per-each/types.d.ts +0 -51
- package/ts-refs/soak-up/types.d.ts +0 -36
- package/ts-refs/trans-render/XV/types.d.ts +0 -69
- package/ts-refs/trans-render/asmr/types.d.ts +0 -138
- package/ts-refs/trans-render/be/types.d.ts +0 -198
- package/ts-refs/trans-render/dss/types.d.ts +0 -57
- package/ts-refs/trans-render/froop/types.d.ts +0 -416
- package/ts-refs/trans-render/funions/types.d.ts +0 -12
- package/ts-refs/trans-render/lib/mixins/types.d.ts +0 -42
- package/ts-refs/trans-render/lib/prs/types.d.ts +0 -40
- package/ts-refs/trans-render/lib/types.d.ts +0 -489
- package/ts-refs/trans-render/types.d.ts +0 -583
- package/ts-refs/wc-info/SimpleWCInfo.d.ts +0 -15
- package/ts-refs/when-resolved/types.d.ts +0 -30
- package/ts-refs/xp-as/types.d.ts +0 -20
- package/ts-refs/xtal-element/types.d.ts +0 -43
- package/ts-refs/xtal-frappe-chart/types.d.ts +0 -193
- package/upShadowSearch.js +0 -25
- package/upShadowSearch.ts +0 -23
- package/waitForEvent.js +0 -12
- package/waitForEvent.ts +0 -13
- package/waitForIsh.js +0 -21
- package/waitForIsh.ts +0 -20
package/readAttrs.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { AttrChangeInfo, AttrParts, MountInit } from "./ts-refs/mount-observer/types";
|
|
2
|
-
|
|
3
|
-
export function readAttrs(
|
|
4
|
-
match: Element, mountInit: MountInit, branchIndexes?: Set<number>,
|
|
5
|
-
fullListOfEnhancementAttrs?: string[],
|
|
6
|
-
attrParts?: AttrParts[],
|
|
7
|
-
){
|
|
8
|
-
//TODO: externalize
|
|
9
|
-
const fullListOfAttrs = fullListOfEnhancementAttrs;
|
|
10
|
-
const attrChangeInfos: Array<AttrChangeInfo> = [];
|
|
11
|
-
const oldValue = null;
|
|
12
|
-
if(fullListOfAttrs !== undefined){
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for(let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++){
|
|
16
|
-
const parts = attrParts![idx];
|
|
17
|
-
const {branchIdx} = parts;
|
|
18
|
-
if(branchIndexes !== undefined){
|
|
19
|
-
if(!branchIndexes.has(branchIdx)) continue;
|
|
20
|
-
}
|
|
21
|
-
const name = fullListOfAttrs[idx];
|
|
22
|
-
|
|
23
|
-
const newValue = match.getAttribute(name);
|
|
24
|
-
|
|
25
|
-
attrChangeInfos.push({
|
|
26
|
-
idx,
|
|
27
|
-
isSOfTAttr: false,
|
|
28
|
-
newValue,
|
|
29
|
-
oldValue,
|
|
30
|
-
name,
|
|
31
|
-
parts
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
const {observedAttrsWhenMounted} = mountInit;
|
|
37
|
-
if(observedAttrsWhenMounted !== undefined){
|
|
38
|
-
for(const observedAttr of observedAttrsWhenMounted){
|
|
39
|
-
const attrIsString = typeof observedAttr === 'string';
|
|
40
|
-
const name = attrIsString ? observedAttr : observedAttr.name;
|
|
41
|
-
let mapsTo: string | undefined;
|
|
42
|
-
let newValue = match.getAttribute(name);
|
|
43
|
-
if(!attrIsString){
|
|
44
|
-
const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
|
|
45
|
-
if(instanceOf || customParser) throw 'NI';
|
|
46
|
-
if(newValue === null) newValue = valIfNull;
|
|
47
|
-
mapsTo = mt;
|
|
48
|
-
}
|
|
49
|
-
attrChangeInfos.push({
|
|
50
|
-
isSOfTAttr: true,
|
|
51
|
-
newValue,
|
|
52
|
-
oldValue,
|
|
53
|
-
name,
|
|
54
|
-
mapsTo
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return attrChangeInfos;
|
|
60
|
-
}
|
package/refid/README.md
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
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
|
-
-->
|
package/refid/arr.js
DELETED
package/refid/arr.ts
DELETED
package/refid/camelToKebab.js
DELETED
package/refid/camelToKebab.ts
DELETED
package/refid/genIds.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { nudge } from './nudge.js';
|
|
2
|
-
import { getCount } from './getCount.js';
|
|
3
|
-
const attrMap = {
|
|
4
|
-
'@': 'name',
|
|
5
|
-
'|': 'itemprop',
|
|
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
|
-
}
|
|
18
|
-
export function genIds(enhancedElement) {
|
|
19
|
-
// const {parentElement} = enhancedElement;
|
|
20
|
-
// if(parentElement === null) throw 404;
|
|
21
|
-
const scopeFragment = (enhancedElement.closest(scopeMatches) || enhancedElement.getRootNode());
|
|
22
|
-
//first find all elements with attribute #
|
|
23
|
-
const hashTest = '[\\#]';
|
|
24
|
-
const hashIds = Array.from(scopeFragment.querySelectorAll(hashTest)).filter(x => inScope(scopeFragment, x));
|
|
25
|
-
if (scopeFragment instanceof Element && scopeFragment.matches(hashTest))
|
|
26
|
-
hashIds.push(scopeFragment);
|
|
27
|
-
const uniqueCheck = new Set();
|
|
28
|
-
for (const hi of hashIds) {
|
|
29
|
-
if (!(hi instanceof HTMLElement))
|
|
30
|
-
continue;
|
|
31
|
-
const idName = hi.getAttribute('itemscope') || hi.localName;
|
|
32
|
-
if (uniqueCheck.has(idName))
|
|
33
|
-
throw 500;
|
|
34
|
-
uniqueCheck.add(idName);
|
|
35
|
-
let sideEffects = '';
|
|
36
|
-
const hashValue = hi.getAttribute('#');
|
|
37
|
-
if (hashValue) {
|
|
38
|
-
sideEffects = `${hashValue} `;
|
|
39
|
-
}
|
|
40
|
-
hi.dataset.id = `{{${sideEffects}${idName}}}`;
|
|
41
|
-
hi.removeAttribute('#');
|
|
42
|
-
}
|
|
43
|
-
//now find all elements with attribute @
|
|
44
|
-
const nameTest = '[name]:not([name=""])[\\@]';
|
|
45
|
-
const names = Array.from(scopeFragment.querySelectorAll(nameTest)).filter(x => inScope(scopeFragment, x));
|
|
46
|
-
if (scopeFragment instanceof Element && scopeFragment.matches(nameTest))
|
|
47
|
-
names.push(scopeFragment);
|
|
48
|
-
for (const nameEl of names) {
|
|
49
|
-
if (!(nameEl instanceof HTMLElement))
|
|
50
|
-
continue;
|
|
51
|
-
const val = nameEl.getAttribute('name');
|
|
52
|
-
if (uniqueCheck.has(val))
|
|
53
|
-
throw 500;
|
|
54
|
-
uniqueCheck.add(val);
|
|
55
|
-
let sideEffects = '';
|
|
56
|
-
const nameValue = nameEl.getAttribute('@');
|
|
57
|
-
if (nameValue) {
|
|
58
|
-
sideEffects = `${nameValue} `;
|
|
59
|
-
}
|
|
60
|
-
nameEl.dataset.id = `{{${sideEffects}${val}}}`;
|
|
61
|
-
nameEl.removeAttribute('@');
|
|
62
|
-
}
|
|
63
|
-
//now find all elements with attribute |
|
|
64
|
-
const itemScopeTest = '[itemprop]:not([itemprop=""])[\\|]';
|
|
65
|
-
const itemprops = Array.from(scopeFragment.querySelectorAll(itemScopeTest)).filter(x => inScope(scopeFragment, x));
|
|
66
|
-
if (scopeFragment instanceof Element && scopeFragment.matches(itemScopeTest))
|
|
67
|
-
itemprops.push(scopeFragment);
|
|
68
|
-
for (const itempropEl of itemprops) {
|
|
69
|
-
if (!(itempropEl instanceof HTMLElement))
|
|
70
|
-
continue;
|
|
71
|
-
const val = itempropEl.getAttribute('itemprop');
|
|
72
|
-
if (uniqueCheck.has(val))
|
|
73
|
-
throw 500;
|
|
74
|
-
uniqueCheck.add(val);
|
|
75
|
-
let sideEffects = '';
|
|
76
|
-
const nameValue = itempropEl.getAttribute('|');
|
|
77
|
-
if (nameValue) {
|
|
78
|
-
sideEffects = `${nameValue} `;
|
|
79
|
-
}
|
|
80
|
-
itempropEl.dataset.id = `{{${sideEffects}${val}}}`;
|
|
81
|
-
itempropEl.removeAttribute('|');
|
|
82
|
-
}
|
|
83
|
-
const dataIdTest = '[data-id^="{{"][data-id$="}}"]';
|
|
84
|
-
const dataIds = Array.from(scopeFragment.querySelectorAll(dataIdTest)).filter(x => inScope(scopeFragment, x));
|
|
85
|
-
if (scopeFragment instanceof Element && scopeFragment.matches(dataIdTest))
|
|
86
|
-
dataIds.push(scopeFragment);
|
|
87
|
-
const ids = [];
|
|
88
|
-
for (const di of dataIds) {
|
|
89
|
-
if (!(di instanceof HTMLElement))
|
|
90
|
-
continue;
|
|
91
|
-
const unparsedID = di.dataset.id;
|
|
92
|
-
const inner = unparsedID?.substring(2, unparsedID.length - 2);
|
|
93
|
-
if (!inner)
|
|
94
|
-
continue;
|
|
95
|
-
const split = inner.split(' ');
|
|
96
|
-
const id = split.length === 2 ? split[1] : split[0];
|
|
97
|
-
if (ids.includes(id))
|
|
98
|
-
throw 500;
|
|
99
|
-
ids.push(id);
|
|
100
|
-
}
|
|
101
|
-
if (ids.length === 0)
|
|
102
|
-
return;
|
|
103
|
-
const allChildren = Array.from(scopeFragment.querySelectorAll('*')).filter(x => inScope(scopeFragment, x));
|
|
104
|
-
if (scopeFragment instanceof Element)
|
|
105
|
-
allChildren.push(scopeFragment);
|
|
106
|
-
const idLookup = {};
|
|
107
|
-
const base = 'gid';
|
|
108
|
-
for (const child of allChildren) {
|
|
109
|
-
const attrs = child.attributes;
|
|
110
|
-
for (const attr of attrs) {
|
|
111
|
-
const { name, value } = attr;
|
|
112
|
-
if (!name.startsWith('data-'))
|
|
113
|
-
continue;
|
|
114
|
-
if (name === 'data-id') {
|
|
115
|
-
if (!value.startsWith('{{') || !value.endsWith('}}'))
|
|
116
|
-
continue;
|
|
117
|
-
const inner = value.substring(2, value.length - 2);
|
|
118
|
-
const split = inner.split(' ');
|
|
119
|
-
const id = split.length === 2 ? split[1] : split[0];
|
|
120
|
-
if (!(id in idLookup)) {
|
|
121
|
-
idLookup[id] = `${base}-${getCount(base)}`;
|
|
122
|
-
}
|
|
123
|
-
if (split.length === 2) {
|
|
124
|
-
const sideEffects = split[0];
|
|
125
|
-
for (const char of sideEffects) {
|
|
126
|
-
switch (char) {
|
|
127
|
-
case '@':
|
|
128
|
-
case '|':
|
|
129
|
-
child.setAttribute(attrMap[char], id);
|
|
130
|
-
break;
|
|
131
|
-
case '%':
|
|
132
|
-
child.part.add(id);
|
|
133
|
-
break;
|
|
134
|
-
case '.':
|
|
135
|
-
child.classList.add(id);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
child.id = idLookup[id];
|
|
141
|
-
child.setAttribute('data-id', id);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
let newValue = value;
|
|
145
|
-
for (const id of ids) {
|
|
146
|
-
const token = `{{${id}}}`;
|
|
147
|
-
if (!newValue.includes(token))
|
|
148
|
-
continue;
|
|
149
|
-
if (!(id in idLookup)) {
|
|
150
|
-
idLookup[id] = `${base}-${getCount(base)}`;
|
|
151
|
-
}
|
|
152
|
-
newValue = newValue.replaceAll(token, idLookup[id]);
|
|
153
|
-
}
|
|
154
|
-
if (newValue === value)
|
|
155
|
-
continue;
|
|
156
|
-
child.setAttribute(name.substring(5), newValue);
|
|
157
|
-
child.removeAttribute(name);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
for (const attr of attrs) {
|
|
161
|
-
const { name, value } = attr;
|
|
162
|
-
if (!name.startsWith('defer-'))
|
|
163
|
-
continue;
|
|
164
|
-
const nameWithoutDefer = name.substring(6);
|
|
165
|
-
const attrWithoutDefer = child.getAttributeNode(nameWithoutDefer);
|
|
166
|
-
if (attrWithoutDefer === null)
|
|
167
|
-
continue;
|
|
168
|
-
const valueWithoutDefer = attrWithoutDefer.value;
|
|
169
|
-
let newValue = valueWithoutDefer;
|
|
170
|
-
let changeMade = false;
|
|
171
|
-
for (const id of ids) {
|
|
172
|
-
const token = `{{${id}}}`;
|
|
173
|
-
if (!newValue.includes(token))
|
|
174
|
-
continue;
|
|
175
|
-
if (!(id in idLookup)) {
|
|
176
|
-
idLookup[id] = `${base}-${getCount(base)}`;
|
|
177
|
-
}
|
|
178
|
-
newValue = newValue.replaceAll(token, idLookup[id]);
|
|
179
|
-
changeMade = true;
|
|
180
|
-
}
|
|
181
|
-
//child.setAttribute(nameWithoutDefer, newValue);
|
|
182
|
-
if (changeMade)
|
|
183
|
-
attrWithoutDefer.value = newValue;
|
|
184
|
-
nudge(child, name);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (scopeFragment instanceof Element && 'disabled' in scopeFragment) {
|
|
188
|
-
nudge(scopeFragment);
|
|
189
|
-
}
|
|
190
|
-
}
|