grainjs 1.0.1 → 1.1.0
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 +23 -26
- package/dist/cjs/index.js +28 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/PriorityQueue.d.ts +2 -2
- package/dist/cjs/lib/PriorityQueue.js +1 -0
- package/dist/cjs/lib/PriorityQueue.js.map +1 -1
- package/dist/cjs/lib/_computed_queue.js +4 -3
- package/dist/cjs/lib/_computed_queue.js.map +1 -1
- package/dist/cjs/lib/binding.d.ts +11 -4
- package/dist/cjs/lib/binding.js +6 -5
- package/dist/cjs/lib/binding.js.map +1 -1
- package/dist/cjs/lib/browserGlobals.d.ts +4 -1
- package/dist/cjs/lib/browserGlobals.js +2 -0
- package/dist/cjs/lib/browserGlobals.js.map +1 -1
- package/dist/cjs/lib/computed.d.ts +49 -28
- package/dist/cjs/lib/computed.js +38 -51
- package/dist/cjs/lib/computed.js.map +1 -1
- package/dist/cjs/lib/dispose.d.ts +109 -96
- package/dist/cjs/lib/dispose.js +106 -79
- package/dist/cjs/lib/dispose.js.map +1 -1
- package/dist/cjs/lib/dom.d.ts +40 -18
- package/dist/cjs/lib/dom.js +63 -29
- package/dist/cjs/lib/dom.js.map +1 -1
- package/dist/cjs/lib/domComponent.d.ts +56 -51
- package/dist/cjs/lib/domComponent.js +46 -44
- package/dist/cjs/lib/domComponent.js.map +1 -1
- package/dist/cjs/lib/domComputed.d.ts +50 -20
- package/dist/cjs/lib/domComputed.js +37 -7
- package/dist/cjs/lib/domComputed.js.map +1 -1
- package/dist/cjs/lib/domDispose.d.ts +27 -12
- package/dist/cjs/lib/domDispose.js +27 -11
- package/dist/cjs/lib/domDispose.js.map +1 -1
- package/dist/cjs/lib/domForEach.d.ts +5 -4
- package/dist/cjs/lib/domForEach.js +41 -41
- package/dist/cjs/lib/domForEach.js.map +1 -1
- package/dist/cjs/lib/domImpl.d.ts +33 -10
- package/dist/cjs/lib/domImpl.js +29 -9
- package/dist/cjs/lib/domImpl.js.map +1 -1
- package/dist/cjs/lib/domMethods.d.ts +93 -47
- package/dist/cjs/lib/domMethods.js +91 -47
- package/dist/cjs/lib/domMethods.js.map +1 -1
- package/dist/cjs/lib/domevent.d.ts +87 -62
- package/dist/cjs/lib/domevent.js +85 -59
- package/dist/cjs/lib/domevent.js.map +1 -1
- package/dist/cjs/lib/emit.d.ts +62 -32
- package/dist/cjs/lib/emit.js +68 -53
- package/dist/cjs/lib/emit.js.map +1 -1
- package/dist/cjs/lib/kowrap.d.ts +6 -3
- package/dist/cjs/lib/kowrap.js +7 -3
- package/dist/cjs/lib/kowrap.js.map +1 -1
- package/dist/cjs/lib/obsArray.d.ts +91 -53
- package/dist/cjs/lib/obsArray.js +87 -54
- package/dist/cjs/lib/obsArray.js.map +1 -1
- package/dist/cjs/lib/observable.d.ts +25 -15
- package/dist/cjs/lib/observable.js +31 -19
- package/dist/cjs/lib/observable.js.map +1 -1
- package/dist/cjs/lib/pureComputed.d.ts +12 -15
- package/dist/cjs/lib/pureComputed.js +16 -18
- package/dist/cjs/lib/pureComputed.js.map +1 -1
- package/dist/cjs/lib/styled.d.ts +78 -61
- package/dist/cjs/lib/styled.js +27 -79
- package/dist/cjs/lib/styled.js.map +1 -1
- package/dist/cjs/lib/subscribe.d.ts +41 -37
- package/dist/cjs/lib/subscribe.js +31 -39
- package/dist/cjs/lib/subscribe.js.map +1 -1
- package/dist/cjs/lib/util.js +2 -0
- package/dist/cjs/lib/util.js.map +1 -1
- package/dist/cjs/lib/widgets/input.d.ts +3 -1
- package/dist/cjs/lib/widgets/input.js +7 -4
- package/dist/cjs/lib/widgets/input.js.map +1 -1
- package/dist/cjs/lib/widgets/select.d.ts +4 -2
- package/dist/cjs/lib/widgets/select.js +8 -5
- package/dist/cjs/lib/widgets/select.js.map +1 -1
- package/dist/esm/lib/_computed_queue.js +3 -3
- package/dist/esm/lib/_computed_queue.js.map +1 -1
- package/dist/esm/lib/binding.js +2 -2
- package/dist/esm/lib/binding.js.map +1 -1
- package/dist/esm/lib/browserGlobals.js +1 -0
- package/dist/esm/lib/browserGlobals.js.map +1 -1
- package/dist/esm/lib/computed.js +36 -50
- package/dist/esm/lib/computed.js.map +1 -1
- package/dist/esm/lib/dispose.js +104 -78
- package/dist/esm/lib/dispose.js.map +1 -1
- package/dist/esm/lib/dom.js +40 -18
- package/dist/esm/lib/dom.js.map +1 -1
- package/dist/esm/lib/domComponent.js +45 -44
- package/dist/esm/lib/domComponent.js.map +1 -1
- package/dist/esm/lib/domComputed.js +32 -5
- package/dist/esm/lib/domComputed.js.map +1 -1
- package/dist/esm/lib/domDispose.js +26 -11
- package/dist/esm/lib/domDispose.js.map +1 -1
- package/dist/esm/lib/domForEach.js +40 -41
- package/dist/esm/lib/domForEach.js.map +1 -1
- package/dist/esm/lib/domImpl.js +26 -7
- package/dist/esm/lib/domImpl.js.map +1 -1
- package/dist/esm/lib/domMethods.js +77 -35
- package/dist/esm/lib/domMethods.js.map +1 -1
- package/dist/esm/lib/domevent.js +84 -59
- package/dist/esm/lib/domevent.js.map +1 -1
- package/dist/esm/lib/emit.js +67 -53
- package/dist/esm/lib/emit.js.map +1 -1
- package/dist/esm/lib/kowrap.js +5 -2
- package/dist/esm/lib/kowrap.js.map +1 -1
- package/dist/esm/lib/obsArray.js +82 -50
- package/dist/esm/lib/obsArray.js.map +1 -1
- package/dist/esm/lib/observable.js +26 -15
- package/dist/esm/lib/observable.js.map +1 -1
- package/dist/esm/lib/pureComputed.js +15 -18
- package/dist/esm/lib/pureComputed.js.map +1 -1
- package/dist/esm/lib/styled.js +24 -77
- package/dist/esm/lib/styled.js.map +1 -1
- package/dist/esm/lib/subscribe.js +27 -36
- package/dist/esm/lib/subscribe.js.map +1 -1
- package/dist/esm/lib/util.js +1 -0
- package/dist/esm/lib/util.js.map +1 -1
- package/dist/esm/lib/widgets/input.js +3 -1
- package/dist/esm/lib/widgets/input.js.map +1 -1
- package/dist/esm/lib/widgets/select.js +3 -1
- package/dist/esm/lib/widgets/select.js.map +1 -1
- package/dist/grain-full.debug.js +2138 -3052
- package/dist/grain-full.debug.js.map +7 -0
- package/dist/grain-full.min.js +6 -2
- package/dist/grain-full.min.js.map +7 -1
- package/lib/binding.ts +9 -2
- package/lib/browserGlobals.ts +3 -1
- package/lib/computed.ts +56 -56
- package/lib/dispose.ts +110 -85
- package/lib/dom.ts +41 -20
- package/lib/domComponent.ts +68 -70
- package/lib/domComputed.ts +66 -21
- package/lib/domDispose.ts +28 -11
- package/lib/domForEach.ts +13 -12
- package/lib/domImpl.ts +30 -7
- package/lib/domMethods.ts +101 -46
- package/lib/domevent.ts +86 -61
- package/lib/emit.ts +64 -50
- package/lib/kowrap.ts +5 -2
- package/lib/obsArray.ts +89 -54
- package/lib/observable.ts +26 -15
- package/lib/pureComputed.ts +16 -22
- package/lib/styled.ts +85 -71
- package/lib/subscribe.ts +41 -45
- package/lib/util.ts +1 -0
- package/lib/widgets/input.ts +3 -1
- package/lib/widgets/select.ts +3 -1
- package/package.json +48 -38
|
@@ -23,6 +23,7 @@ function _walkDom(elem, visitFunc) {
|
|
|
23
23
|
visitFunc(elem);
|
|
24
24
|
}
|
|
25
25
|
// Internal helper to run all disposers for a single element.
|
|
26
|
+
/** @internal */
|
|
26
27
|
export function _disposeNode(node) {
|
|
27
28
|
let disposer = _disposeMap.get(node);
|
|
28
29
|
if (disposer) {
|
|
@@ -54,20 +55,21 @@ export const domDisposeHooks = {
|
|
|
54
55
|
* It is automatically called if one of the function arguments to dom() throws an exception during
|
|
55
56
|
* element creation. This way any onDispose() handlers set on the unfinished element get called.
|
|
56
57
|
*
|
|
57
|
-
* @param
|
|
58
|
+
* @param node - The element to run disposers on.
|
|
58
59
|
*/
|
|
59
60
|
export function domDispose(node) {
|
|
60
61
|
domDisposeHooks.disposeRecursive(node);
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
|
-
* Associate a
|
|
64
|
-
* using domDispose() on it or any of its parents. If
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param {Function} disposerFunc(elem): Will be called when domDispose() is called on the
|
|
68
|
-
* element or its ancestor.
|
|
64
|
+
* Associate a disposer function with a DOM element. It will be called when the element is disposed
|
|
65
|
+
* using `domDispose()` on it or any of its parents. If called multiple times, all
|
|
66
|
+
* disposer functions will be called in reverse order.
|
|
67
|
+
*
|
|
69
68
|
* Note that it is not necessary usually to dispose event listeners attached to an element (e.g.
|
|
70
|
-
* with dom.on()) since their lifetime is naturally limited to the lifetime of the element.
|
|
69
|
+
* with `dom.on()`) since their lifetime is naturally limited to the lifetime of the element.
|
|
70
|
+
*
|
|
71
|
+
* @param elem - The element to associate the disposer with.
|
|
72
|
+
* @param disposerFunc - Will be called when `domDispose()` is called on the element or its ancestor.
|
|
71
73
|
*/
|
|
72
74
|
export function onDisposeElem(elem, disposerFunc) {
|
|
73
75
|
const prevDisposer = _disposeMap.get(elem);
|
|
@@ -76,20 +78,33 @@ export function onDisposeElem(elem, disposerFunc) {
|
|
|
76
78
|
_disposeMap.set(disposerFunc, prevDisposer);
|
|
77
79
|
}
|
|
78
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Associate a disposer function with a DOM element. It will be called when the element is disposed
|
|
83
|
+
* using `domDispose()` on it or any of its parents. If called multiple times, all
|
|
84
|
+
* disposer functions will be called in reverse order.
|
|
85
|
+
*
|
|
86
|
+
* @param disposerFunc - Will be called when `domDispose()` is called on the element or its ancestor.
|
|
87
|
+
*/
|
|
79
88
|
export function onDispose(disposerFunc) {
|
|
80
89
|
return (elem) => onDisposeElem(elem, disposerFunc);
|
|
81
90
|
}
|
|
82
91
|
/**
|
|
83
|
-
* Make the given element own the disposable, and call its dispose method when domDispose() is
|
|
92
|
+
* Make the given element own the disposable, and call its dispose method when `domDispose()` is
|
|
84
93
|
* called on the element or any of its parents.
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
94
|
+
* @param elem - The element to own the disposable.
|
|
95
|
+
* @param disposable - Anything with a `.dispose()` method.
|
|
87
96
|
*/
|
|
88
97
|
export function autoDisposeElem(elem, disposable) {
|
|
89
98
|
if (disposable) {
|
|
90
99
|
onDisposeElem(elem, () => disposable.dispose());
|
|
91
100
|
}
|
|
92
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Make the given element own the disposable, and call its dispose method when `domDispose()` is
|
|
104
|
+
* called on the element or any of its parents.
|
|
105
|
+
*
|
|
106
|
+
* @param disposable - Anything with a `.dispose()` method.
|
|
107
|
+
*/
|
|
93
108
|
export function autoDispose(disposable) {
|
|
94
109
|
if (disposable) {
|
|
95
110
|
return (elem) => autoDisposeElem(elem, disposable);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domDispose.js","sourceRoot":"","sources":["../../../lib/domDispose.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,GAAuC,IAAI,OAAO,EAAE,CAAC;AAItE,4FAA4F;AAC5F,mCAAmC;AACnC,SAAS,QAAQ,CAAC,IAAU,EAAE,SAAoB;IAChD,IAAI,CAAC,GAAc,IAAI,CAAC,UAAU,CAAC;IACnC,OAAO,CAAC,EAAE;QACR,4FAA4F;QAC5F,gCAAgC;QAChC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACvB,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC;KACnB;IACD,SAAS,CAAC,IAAI,CAAC,CAAC;AAClB,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,YAAY,CAAC,IAAU;IACrC,IAAI,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,QAAQ,EAAE;QACZ,IAAI,GAAG,GAAmB,IAAI,CAAC;QAC/B,GAAG;YACD,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACxB,QAAQ,CAAC,IAAI,CAAC,CAAC;YACf,qEAAqE;YACrE,GAAG,GAAG,QAAQ,CAAC;YACf,Q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AAI,EAAE,UAAU,CAAC,CAAC;KAC1D;AACH,CAAC"}
|
|
@@ -16,55 +16,54 @@ import { G } from './browserGlobals';
|
|
|
16
16
|
* If the created nodes are removed from their parent externally, forEach() will cope with it, but
|
|
17
17
|
* will consider these elements as no longer owned, and will not run domDispose() on them.
|
|
18
18
|
*
|
|
19
|
-
* Note that itemCreateFunc()
|
|
20
|
-
*
|
|
19
|
+
* Note that itemCreateFunc() is called with an index as the second argument, but that index is
|
|
20
|
+
* only accurate at the time of the call, and will stop reflecting the true index if more items
|
|
21
|
+
* are inserted or removed before it.
|
|
21
22
|
*
|
|
22
23
|
* If you'd like to map the DOM node back to its source item, use dom.data() and dom.getData() in
|
|
23
24
|
* itemCreateFunc().
|
|
24
25
|
*/
|
|
25
26
|
export function forEach(obsArray, itemCreateFunc) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// Remove the elements that are gone.
|
|
41
|
-
for (const node of splice.deleted) {
|
|
42
|
-
if (node && node.parentNode === elem) {
|
|
43
|
-
domDispose(node);
|
|
44
|
-
elem.removeChild(node);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (splice.numAdded > 0) {
|
|
48
|
-
// Find a valid child immediately following the spliced out portion, for DOM insertion.
|
|
49
|
-
const endIndex = splice.start + splice.numAdded;
|
|
50
|
-
let nextElem = markerPost;
|
|
51
|
-
for (let i = endIndex; i < newArr.length; i++) {
|
|
52
|
-
const node = newArr[i];
|
|
27
|
+
const markerPre = G.document.createComment('a');
|
|
28
|
+
const markerPost = G.document.createComment('b');
|
|
29
|
+
return [markerPre, markerPost, (elem) => {
|
|
30
|
+
if (Array.isArray(obsArray)) {
|
|
31
|
+
replaceContent(markerPre, markerPost, obsArray.map(itemCreateFunc));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const nodes = computedArray(obsArray, itemCreateFunc);
|
|
35
|
+
// Be sure to dispose the newly-created array when the DOM it's associated with is gone.
|
|
36
|
+
autoDisposeElem(markerPost, nodes);
|
|
37
|
+
nodes.addListener((newArr, oldArr, splice) => {
|
|
38
|
+
if (splice) {
|
|
39
|
+
// Remove the elements that are gone.
|
|
40
|
+
for (const node of splice.deleted) {
|
|
53
41
|
if (node && node.parentNode === elem) {
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
domDispose(node);
|
|
43
|
+
elem.removeChild(node);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (splice.numAdded > 0) {
|
|
47
|
+
// Find a valid child immediately following the spliced out portion, for DOM insertion.
|
|
48
|
+
const endIndex = splice.start + splice.numAdded;
|
|
49
|
+
let nextElem = markerPost;
|
|
50
|
+
for (let i = endIndex; i < newArr.length; i++) {
|
|
51
|
+
const node = newArr[i];
|
|
52
|
+
if (node && node.parentNode === elem) {
|
|
53
|
+
nextElem = node;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
56
|
}
|
|
57
|
+
// Insert the new elements.
|
|
58
|
+
const content = frag(newArr.slice(splice.start, endIndex));
|
|
59
|
+
elem.insertBefore(content, nextElem);
|
|
57
60
|
}
|
|
58
|
-
// Insert the new elements.
|
|
59
|
-
const content = frag(newArr.slice(splice.start, endIndex));
|
|
60
|
-
elem.insertBefore(content, nextElem);
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
62
|
+
else {
|
|
63
|
+
replaceContent(markerPre, markerPost, newArr);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
replaceContent(markerPre, markerPost, nodes.get());
|
|
67
|
+
}];
|
|
69
68
|
}
|
|
70
69
|
//# sourceMappingURL=domForEach.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domForEach.js","sourceRoot":"","sources":["../../../lib/domForEach.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"domForEach.js","sourceRoot":"","sources":["../../../lib/domForEach.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAC,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AACzD,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAC,aAAa,EAA0B,MAAM,YAAY,CAAC;AAElE,mFAAmF;AACnF,OAAO,EAAC,CAAC,EAAC,MAAM,kBAAkB,CAAC;AAEnC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CACrB,QAA0B,EAC1B,cAAqD;IAErD,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACjD,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,IAAU,EAAE,EAAE;YAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAC3B,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;gBACpE,OAAO;aACR;YAED,MAAM,KAAK,GAAwB,aAAa,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAE3E,wFAAwF;YACxF,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YAEnC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAwB,EAAE,MAAwB,EAAE,MAAO,EAAE,EAAE;gBAChF,IAAI,MAAM,EAAE;oBACV,qCAAqC;oBACrC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE;wBACjC,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE;4BACpC,UAAU,CAAC,IAAI,CAAC,CAAC;4BACjB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;yBACxB;qBACF;oBAED,IAAI,MAAM,CAAC,QAAQ,GAAG,CAAC,EAAE;wBACvB,uFAAuF;wBACvF,MAAM,QAAQ,GAAW,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC;wBACxD,IAAI,QAAQ,GAAS,UAAU,CAAC;wBAChC,KAAK,IAAI,CAAC,GAAG,QAAQ,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;4BAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;4BACvB,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE;gCACpC,QAAQ,GAAG,IAAI,CAAC;gCAChB,MAAM;6BACP;yBACF;wBAED,2BAA2B;wBAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;wBAC3D,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;qBACtC;iBACF;qBAAM;oBACL,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;iBAC/C;YACH,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/lib/domImpl.js
CHANGED
|
@@ -17,14 +17,14 @@ import { G } from './browserGlobals';
|
|
|
17
17
|
* to add the ID 'foo', and zero or more .bar suffixes to add a CSS class 'bar'.
|
|
18
18
|
*
|
|
19
19
|
* NOTE that better typings are available when a tag is used directly, e.g.
|
|
20
|
-
* dom('input', {id: 'foo'}, (elem) => ...)
|
|
21
|
-
* dom('input#foo', (elem) => ...)
|
|
20
|
+
* `dom('input', {id: 'foo'}, (elem) => ...)` -- elem has type HTMLInputElement
|
|
21
|
+
* `dom('input#foo', (elem) => ...)` -- elem has type HTMLElement
|
|
22
22
|
*
|
|
23
23
|
* The rest of the arguments are optional and may be:
|
|
24
24
|
*
|
|
25
25
|
* Nodes - which become children of the created element;
|
|
26
26
|
* strings - which become text node children;
|
|
27
|
-
* objects - of the form {attr: val} to set additional attributes on the element;
|
|
27
|
+
* objects - of the form `{attr: val}` to set additional attributes on the element;
|
|
28
28
|
* Arrays - which are flattened with each item processed recursively;
|
|
29
29
|
* functions - which are called with elem as the argument, for a chance to modify the
|
|
30
30
|
* element as it's being created. Return values are processed recursively.
|
|
@@ -52,11 +52,11 @@ function _createElementSvg(tag) {
|
|
|
52
52
|
/**
|
|
53
53
|
* Internal helper to parse tagString, create an element using createFunc with the given tag, and
|
|
54
54
|
* set its id and classes from the tagString.
|
|
55
|
-
* @param
|
|
55
|
+
* @param createFunc(tag) - Function that should create an element given a tag name.
|
|
56
56
|
* It is passed in to allow creating elements in different namespaces (e.g. plain HTML vs SVG).
|
|
57
|
-
* @param
|
|
57
|
+
* @param tagString - String of the form "tag#id.class1.class2" where id and classes are
|
|
58
58
|
* optional.
|
|
59
|
-
* @
|
|
59
|
+
* @returns {Element} The result of createFunc(), possibly with id and class attributes also set.
|
|
60
60
|
*/
|
|
61
61
|
function _createFromTagString(createFunc, tagString) {
|
|
62
62
|
// We do careful hand-written parsing rather than use a regexp for speed. Using a regexp is
|
|
@@ -145,7 +145,26 @@ function _updateWithArg(elem, arg) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
* Creates a DocumentFragment processing arguments the same way as the dom() function.
|
|
148
|
+
* Creates a `DocumentFragment`, processing arguments in the same way as the `dom()` function.
|
|
149
|
+
*
|
|
150
|
+
* It's rarely needed since an array of `dom()` arguments is treated the same as a
|
|
151
|
+
* `DocumentFragment` in most cases.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* dom.frag(dom('span', 'Hello'), ' good ', dom('div', 'world'))
|
|
156
|
+
* ```
|
|
157
|
+
* creates document fragment with `<span>Hello</span> good <div>world</div>`.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* These two examples are equivalent:
|
|
161
|
+
* ```ts
|
|
162
|
+
* const world1 = () => dom.frag(' good ', dom('div', 'world'));
|
|
163
|
+
* dom('div', 'Hello', world1);
|
|
164
|
+
*
|
|
165
|
+
* const world2 = () => [' good ', dom('div', 'world')];
|
|
166
|
+
* dom('div', 'Hello', world2);
|
|
167
|
+
* ```
|
|
149
168
|
*/
|
|
150
169
|
export function frag(...args) {
|
|
151
170
|
const elem = G.document.createDocumentFragment();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domImpl.js","sourceRoot":"","sources":["../../../lib/domImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,mFAAmF;AACnF,OAAO,EAAC,CAAC,EAAC,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"domImpl.js","sourceRoot":"","sources":["../../../lib/domImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,mFAAmF;AACnF,OAAO,EAAC,CAAC,EAAC,MAAM,kBAAkB,CAAC;AAqCnC,kGAAkG;AAClG,8CAA8C;AAC9C,4CAA4C;AAC5C,2CAA2C;AAC3C,2CAA2C;AAC3C,2CAA2C;AAC3C,2CAA2C;AAC3C,gFAAgF;AAChF,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,GAAG,CA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ets multiple attributes of a DOM element.
|
|
11
|
+
* Sets multiple attributes of a DOM element.
|
|
12
12
|
* Null and undefined values are omitted, and booleans are either omitted or set to empty string.
|
|
13
|
-
* @param
|
|
13
|
+
* @param attrsObj - Object mapping attribute names to attribute values.
|
|
14
14
|
*/
|
|
15
15
|
export function attrsElem(elem, attrsObj) {
|
|
16
16
|
for (const key of Object.keys(attrsObj)) {
|
|
@@ -20,16 +20,19 @@ export function attrsElem(elem, attrsObj) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Sets multiple attributes of a DOM element. Null and undefined values are omitted, and booleans
|
|
25
|
+
* are either omitted or set to empty string.
|
|
26
|
+
*/
|
|
23
27
|
export function attrs(attrsObj) {
|
|
24
28
|
return (elem) => attrsElem(elem, attrsObj);
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* Sets an attribute of a DOM element to the given value. Removes the attribute when the value is
|
|
28
|
-
* null or undefined.
|
|
29
|
-
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param {String|null} attrValue: The string value or null to remove the attribute.
|
|
32
|
+
* null or undefined.
|
|
33
|
+
* @param elem - The element to update.
|
|
34
|
+
* @param attrName - The name of the attribute to bind, e.g. 'href'.
|
|
35
|
+
* @param attrValue - The string value, or null or undefined to remove the attribute.
|
|
33
36
|
*/
|
|
34
37
|
export function attrElem(elem, attrName, attrValue) {
|
|
35
38
|
if (attrValue === null || attrValue === undefined) {
|
|
@@ -39,32 +42,47 @@ export function attrElem(elem, attrName, attrValue) {
|
|
|
39
42
|
elem.setAttribute(attrName, attrValue);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets an attribute of a DOM element to the given value. Removes the attribute when the value is
|
|
47
|
+
* null or undefined.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* dom('a', dom.attr('href', urlObs))
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
42
54
|
export function attr(attrName, attrValueObs) {
|
|
43
55
|
return (elem) => _subscribe(elem, attrValueObs, (val) => attrElem(elem, attrName, val));
|
|
44
56
|
}
|
|
45
57
|
/**
|
|
46
58
|
* Sets or removes a boolean attribute of a DOM element. According to the spec, empty string is a
|
|
47
59
|
* valid true value for the attribute, and the false value is indicated by the attribute's absence.
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param {Boolean} boolValue: Boolean value whether to set or unset the attribute.
|
|
60
|
+
* @param elem - The element to update.
|
|
61
|
+
* @param attrName - The name of the attribute to bind, e.g. 'checked'.
|
|
62
|
+
* @param boolValue - Boolean value whether to set or unset the attribute.
|
|
52
63
|
*/
|
|
53
64
|
export function boolAttrElem(elem, attrName, boolValue) {
|
|
54
65
|
attrElem(elem, attrName, boolValue ? '' : null);
|
|
55
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Dom-method that sets or removes a boolean attribute of a DOM element.
|
|
69
|
+
* @param attrName - The name of the attribute to bind, e.g. 'checked'.
|
|
70
|
+
* @param boolValueObs - Value, observable, or function for a whether to set or unset the attribute.
|
|
71
|
+
*/
|
|
56
72
|
export function boolAttr(attrName, boolValueObs) {
|
|
57
73
|
return (elem) => _subscribe(elem, boolValueObs, (val) => boolAttrElem(elem, attrName, val));
|
|
58
74
|
}
|
|
59
75
|
/**
|
|
60
|
-
* Adds a text node to the element.
|
|
61
|
-
*
|
|
62
|
-
* @param
|
|
63
|
-
* @param {String} value: The text value to add.
|
|
76
|
+
* Adds a text node to the element.
|
|
77
|
+
* @param elem - The element to update.
|
|
78
|
+
* @param value - The text value to add.
|
|
64
79
|
*/
|
|
65
80
|
export function textElem(elem, value) {
|
|
66
81
|
elem.appendChild(G.document.createTextNode(value));
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Sets text content of a DOM element to a value that may be an observable or a function.
|
|
85
|
+
*/
|
|
68
86
|
export function text(valueObs) {
|
|
69
87
|
return (elem) => {
|
|
70
88
|
const textNode = G.document.createTextNode('');
|
|
@@ -73,53 +91,70 @@ export function text(valueObs) {
|
|
|
73
91
|
};
|
|
74
92
|
}
|
|
75
93
|
/**
|
|
76
|
-
* Sets a style property of a DOM element to the given value.
|
|
77
|
-
*
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
80
|
-
* @param {String} value: The value for the property.
|
|
94
|
+
* Sets a style property of a DOM element to the given value.
|
|
95
|
+
* @param elem - The element to update.
|
|
96
|
+
* @param property - The name of the style property to update, e.g. 'fontWeight'.
|
|
97
|
+
* @param value - The value for the property.
|
|
81
98
|
*/
|
|
82
99
|
export function styleElem(elem, property, value) {
|
|
83
100
|
elem.style[property] = value;
|
|
84
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Sets a style property of a DOM element to the given value, which may be an observable or a
|
|
104
|
+
* function.
|
|
105
|
+
* @param property - The name of the style property to update, e.g. 'fontWeight'.
|
|
106
|
+
* @param value - The value for the property.
|
|
107
|
+
*/
|
|
85
108
|
export function style(property, valueObs) {
|
|
86
109
|
return (elem) => _subscribe(elem, valueObs, (val) => styleElem(elem, property, val));
|
|
87
110
|
}
|
|
88
111
|
/**
|
|
89
112
|
* Sets the property of a DOM element to the given value.
|
|
90
|
-
*
|
|
91
|
-
* @param
|
|
92
|
-
* @param
|
|
93
|
-
* @param {Object} value: The value for the property.
|
|
113
|
+
* @param elem - The element to update.
|
|
114
|
+
* @param property - The name of the property to update, e.g. 'disabled'.
|
|
115
|
+
* @param value - The value for the property.
|
|
94
116
|
*/
|
|
95
117
|
export function propElem(elem, property, value) {
|
|
96
118
|
elem[property] = value;
|
|
97
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Sets the property of a DOM element to the given value, which may be an observable or a
|
|
122
|
+
* function.
|
|
123
|
+
* @param property - The name of the property to update, e.g. 'disabled'.
|
|
124
|
+
* @param value - The value for the property.
|
|
125
|
+
*/
|
|
98
126
|
export function prop(property, valueObs) {
|
|
99
127
|
return (elem) => _subscribe(elem, valueObs, (val) => propElem(elem, property, val));
|
|
100
128
|
}
|
|
101
129
|
/**
|
|
102
130
|
* Shows or hides the element depending on a boolean value. Note that the element must be visible
|
|
103
131
|
* initially (i.e. unsetting style.display should show it).
|
|
104
|
-
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param {Boolean} boolValue: True to show the element, false to hide it.
|
|
132
|
+
* @param elem - The element to update.
|
|
133
|
+
* @param boolValue - True to show the element, false to hide it.
|
|
107
134
|
*/
|
|
108
135
|
export function showElem(elem, boolValue) {
|
|
109
136
|
elem.style.display = boolValue ? '' : 'none';
|
|
110
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Shows or hides the element depending on a boolean value, which may be an observable or a function.
|
|
140
|
+
* Note that the element must be visible by default (i.e. unsetting `style.display` should show it).
|
|
141
|
+
*/
|
|
111
142
|
export function show(boolValueObs) {
|
|
112
143
|
return (elem) => _subscribe(elem, boolValueObs, (val) => showElem(elem, val));
|
|
113
144
|
}
|
|
114
145
|
/**
|
|
115
146
|
* The opposite of show, hiding the element when boolValue is true.
|
|
116
|
-
*
|
|
117
|
-
* @param
|
|
118
|
-
* @param {Boolean} boolValue: True to hide the element, false to show it.
|
|
147
|
+
* @param elem - The element to update.
|
|
148
|
+
* @param boolValue - True to hide the element, false to show it.
|
|
119
149
|
*/
|
|
120
150
|
export function hideElem(elem, boolValue) {
|
|
121
151
|
elem.style.display = boolValue ? 'none' : '';
|
|
122
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The opposite of show, hiding the element when boolValue is true. `boolValueObs` may be an
|
|
155
|
+
* observable or a function.
|
|
156
|
+
* Note that the element must be visible by default (i.e. unsetting `style.display` should show it).
|
|
157
|
+
*/
|
|
123
158
|
export function hide(boolValueObs) {
|
|
124
159
|
return (elem) => _subscribe(elem, boolValueObs, (val) => hideElem(elem, val));
|
|
125
160
|
}
|
|
@@ -163,11 +198,10 @@ function _clsDynamicPrefix(prefix, className) {
|
|
|
163
198
|
};
|
|
164
199
|
}
|
|
165
200
|
/**
|
|
166
|
-
* Associate arbitrary data with a DOM element.
|
|
167
|
-
*
|
|
168
|
-
* @param
|
|
169
|
-
* @param
|
|
170
|
-
* @param {Object} value: Arbitrary value to associate with elem.
|
|
201
|
+
* Associate arbitrary data with a DOM element.
|
|
202
|
+
* @param elem - The element with which to associate data.
|
|
203
|
+
* @param key - Key to identify this piece of data among others attached to elem.
|
|
204
|
+
* @param value - Arbitrary value to associate with elem.
|
|
171
205
|
*/
|
|
172
206
|
export function dataElem(elem, key, value) {
|
|
173
207
|
const obj = _dataMap.get(elem);
|
|
@@ -179,9 +213,17 @@ export function dataElem(elem, key, value) {
|
|
|
179
213
|
_dataMap.set(elem, { [key]: value });
|
|
180
214
|
}
|
|
181
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Associate arbitrary data with a DOM element: `value` may be an observable or a function.
|
|
218
|
+
* @param key - Key to identify this piece of data among others attached to elem.
|
|
219
|
+
* @param value - Arbitrary value to associate with elem.
|
|
220
|
+
*/
|
|
182
221
|
export function data(key, valueObs) {
|
|
183
222
|
return (elem) => _subscribe(elem, valueObs, (val) => dataElem(elem, key, val));
|
|
184
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Retrieve data associated with a DOM element using `data()` or `dataElem()`.
|
|
226
|
+
*/
|
|
185
227
|
export function getData(elem, key) {
|
|
186
228
|
const obj = _dataMap.get(elem);
|
|
187
229
|
return obj && obj[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domMethods.js","sourceRoot":"","sources":["../../../lib/domMethods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,IAAI,UAAU,EAAC,MAAM,WAAW,CAAC;AACrE,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAG3C,mFAAmF;AACnF,OAAO,EAAC,CAAC,EAAC,MAAM,kBAAkB,CAAC;AAEnC;;;GAGG;AACH,MAAM,QA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