mount-observer 0.0.15 → 0.0.16
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 +14 -12
- package/package.json +1 -1
- package/types.d.ts +19 -9
- package/doWhereAttr.js +0 -43
package/README.md
CHANGED
|
@@ -284,9 +284,9 @@ So let's say we want to insist that on custom elements, we must have the data- p
|
|
|
284
284
|
|
|
285
285
|
And we want to support an alternative, more semantic sounding prefix to data, say enh-*, endorsed by [this proposal](https://github.com/WICG/webcomponents/issues/1000).
|
|
286
286
|
|
|
287
|
-
Here's what the api
|
|
287
|
+
Here's what the api **doesn't** provide:
|
|
288
288
|
|
|
289
|
-
##
|
|
289
|
+
## Rejected option -- The carpal syndrome syntax
|
|
290
290
|
|
|
291
291
|
```JavaScript
|
|
292
292
|
import {MountObserver} from '../MountObserver.js';
|
|
@@ -320,7 +320,7 @@ const mo = new MountObserver({
|
|
|
320
320
|
});
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
##
|
|
323
|
+
## Supported -- The DRY Way
|
|
324
324
|
|
|
325
325
|
```JavaScript
|
|
326
326
|
import {MountObserver} from '../MountObserver.js';
|
|
@@ -360,16 +360,18 @@ MountObserver provides a breakdown of the matching attribute when encountered:
|
|
|
360
360
|
console.log(e);
|
|
361
361
|
// {
|
|
362
362
|
// matchingElement,
|
|
363
|
-
// attrChangeInfo:{
|
|
364
|
-
// name: 'data-my-enhancement-first-aspect-wow-this-is-deep'
|
|
365
|
-
// root: 'data',
|
|
366
|
-
// base: 'my-enhancement',
|
|
367
|
-
// branch: 'first-aspect',
|
|
368
|
-
// leaf: 'wow-this-is-deep',
|
|
369
|
-
// oldValue: null,
|
|
370
|
-
// newValue: 'good-bye'
|
|
363
|
+
// attrChangeInfo:[{
|
|
371
364
|
// idx: 0,
|
|
372
|
-
//
|
|
365
|
+
// oldValue: null,
|
|
366
|
+
// newValue: 'good-bye',
|
|
367
|
+
// parts:{
|
|
368
|
+
// name: 'data-my-enhancement-first-aspect-wow-this-is-deep'
|
|
369
|
+
// root: 'data',
|
|
370
|
+
// base: 'my-enhancement',
|
|
371
|
+
// branch: 'first-aspect',
|
|
372
|
+
// leaf: 'wow-this-is-deep',
|
|
373
|
+
// }
|
|
374
|
+
// }]
|
|
373
375
|
// }
|
|
374
376
|
});
|
|
375
377
|
mo.observe(div);
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface MountInit{
|
|
|
5
5
|
readonly whereAttr?: WhereAttr,
|
|
6
6
|
readonly whereElementIntersectsWith?: IntersectionObserverInit,
|
|
7
7
|
readonly whereMediaMatches?: MediaQuery,
|
|
8
|
-
readonly whereInstanceOf?: Array<
|
|
8
|
+
readonly whereInstanceOf?: Array<{new(): Element}>,
|
|
9
9
|
readonly whereSatisfies?: PipelineProcessor<boolean>,
|
|
10
10
|
readonly import?: ImportString | [ImportString, ImportAssertions] | PipelineProcessor,
|
|
11
11
|
readonly do?: {
|
|
@@ -21,13 +21,18 @@ export interface MountInit{
|
|
|
21
21
|
// */
|
|
22
22
|
// readonly ignoreInitialMatches?: boolean,
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
export interface RootCnfg{
|
|
26
|
+
start: string,
|
|
27
|
+
context: 'BuiltIn' | 'CustomElement' | 'Both'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//export type RootAttrOptions = Array<string | RootCnfg>;
|
|
31
|
+
export type delimiter = string;
|
|
24
32
|
export interface WhereAttr{
|
|
25
|
-
hasBase: string | [
|
|
26
|
-
hasBranchIn?: Array<string> | [
|
|
27
|
-
hasRootIn?: Array<
|
|
28
|
-
path: string,
|
|
29
|
-
context: 'BuiltIn' | 'CustomElement' | 'Both'
|
|
30
|
-
}>,
|
|
33
|
+
hasBase: string | [delimiter, string],
|
|
34
|
+
hasBranchIn?: Array<string> | [delimiter, Array<string>],
|
|
35
|
+
hasRootIn?: Array<RootCnfg>,
|
|
31
36
|
}
|
|
32
37
|
type CSSMatch = string;
|
|
33
38
|
type ImportString = string;
|
|
@@ -70,15 +75,20 @@ export interface AddMutationEventListener {
|
|
|
70
75
|
}
|
|
71
76
|
//#endregion
|
|
72
77
|
|
|
73
|
-
interface
|
|
78
|
+
interface AttrParts{
|
|
74
79
|
name: string,
|
|
75
80
|
root?: string,
|
|
76
81
|
base?: string,
|
|
77
82
|
branch?: string,
|
|
78
83
|
leaf?: string, //TODO
|
|
84
|
+
rootCnfg?: RootCnfg
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface AttrChangeInfo{
|
|
79
88
|
oldValue: string | null,
|
|
80
89
|
newValue: string | null,
|
|
81
90
|
idx: number,
|
|
91
|
+
parts: AttrParts,
|
|
82
92
|
//parsedNewValue?: any,
|
|
83
93
|
}
|
|
84
94
|
|
|
@@ -123,7 +133,7 @@ export interface AddDisconnectEventListener {
|
|
|
123
133
|
//#region attribute change event
|
|
124
134
|
export type attrChangeEventName = 'attr-change';
|
|
125
135
|
export interface IAttrChangeEvent extends IMountEvent {
|
|
126
|
-
|
|
136
|
+
attrChangeInfos: Array<AttrChangeInfo>,
|
|
127
137
|
}
|
|
128
138
|
export type attrChangeEventHandler = (e: IAttrChangeEvent) => void;
|
|
129
139
|
export interface AddAttrChangeEventListener{
|
package/doWhereAttr.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AttrChangeEvent } from "./MountObserver.js";
|
|
2
|
-
export function doWhereAttr(whereAttr, attributeName, target, oldValue, mo) {
|
|
3
|
-
const { hasRootIn, hasBase, hasBranchIn } = whereAttr;
|
|
4
|
-
const name = attributeName;
|
|
5
|
-
let restOfName = name;
|
|
6
|
-
let root;
|
|
7
|
-
let branch;
|
|
8
|
-
let idx = 0;
|
|
9
|
-
const hasBaseIsString = typeof hasBase === 'string';
|
|
10
|
-
const baseSelector = hasBaseIsString ? hasBase : hasBase[1];
|
|
11
|
-
const rootToBaseDelimiter = hasBaseIsString ? '-' : hasBase[0];
|
|
12
|
-
if (hasRootIn !== undefined) {
|
|
13
|
-
for (const rootTest in hasRootIn) {
|
|
14
|
-
if (restOfName.startsWith(rootTest)) {
|
|
15
|
-
root = rootTest;
|
|
16
|
-
restOfName = restOfName.substring(root.length + rootToBaseDelimiter.length);
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (!restOfName.startsWith(baseSelector))
|
|
22
|
-
return;
|
|
23
|
-
restOfName = restOfName.substring(hasBase.length);
|
|
24
|
-
if (hasBranchIn) {
|
|
25
|
-
for (const branchTest in hasBranchIn) {
|
|
26
|
-
if (restOfName.startsWith(branchTest)) {
|
|
27
|
-
branch = branchTest;
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const newValue = target.getAttribute(attributeName);
|
|
33
|
-
const attrChangeInfo = {
|
|
34
|
-
name,
|
|
35
|
-
root,
|
|
36
|
-
base: baseSelector,
|
|
37
|
-
branch,
|
|
38
|
-
oldValue,
|
|
39
|
-
newValue,
|
|
40
|
-
idx
|
|
41
|
-
};
|
|
42
|
-
mo.dispatchEvent(new AttrChangeEvent(target, attrChangeInfo));
|
|
43
|
-
}
|