grainjs 1.0.2 → 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.
Files changed (138) hide show
  1. package/README.md +23 -71
  2. package/dist/cjs/index.js +5 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/lib/PriorityQueue.d.ts +1 -1
  5. package/dist/cjs/lib/_computed_queue.js +3 -3
  6. package/dist/cjs/lib/_computed_queue.js.map +1 -1
  7. package/dist/cjs/lib/binding.d.ts +11 -4
  8. package/dist/cjs/lib/binding.js +5 -5
  9. package/dist/cjs/lib/binding.js.map +1 -1
  10. package/dist/cjs/lib/computed.d.ts +49 -28
  11. package/dist/cjs/lib/computed.js +38 -52
  12. package/dist/cjs/lib/computed.js.map +1 -1
  13. package/dist/cjs/lib/dispose.d.ts +109 -96
  14. package/dist/cjs/lib/dispose.js +106 -80
  15. package/dist/cjs/lib/dispose.js.map +1 -1
  16. package/dist/cjs/lib/dom.d.ts +38 -18
  17. package/dist/cjs/lib/dom.js +44 -20
  18. package/dist/cjs/lib/dom.js.map +1 -1
  19. package/dist/cjs/lib/domComponent.d.ts +56 -48
  20. package/dist/cjs/lib/domComponent.js +66 -1
  21. package/dist/cjs/lib/domComponent.js.map +1 -1
  22. package/dist/cjs/lib/domComputed.d.ts +31 -21
  23. package/dist/cjs/lib/domComputed.js +14 -11
  24. package/dist/cjs/lib/domComputed.js.map +1 -1
  25. package/dist/cjs/lib/domDispose.d.ts +27 -12
  26. package/dist/cjs/lib/domDispose.js +26 -11
  27. package/dist/cjs/lib/domDispose.js.map +1 -1
  28. package/dist/cjs/lib/domForEach.d.ts +4 -3
  29. package/dist/cjs/lib/domForEach.js +10 -9
  30. package/dist/cjs/lib/domForEach.js.map +1 -1
  31. package/dist/cjs/lib/domImpl.d.ts +33 -10
  32. package/dist/cjs/lib/domImpl.js +28 -9
  33. package/dist/cjs/lib/domImpl.js.map +1 -1
  34. package/dist/cjs/lib/domMethods.d.ts +93 -47
  35. package/dist/cjs/lib/domMethods.js +88 -46
  36. package/dist/cjs/lib/domMethods.js.map +1 -1
  37. package/dist/cjs/lib/domevent.d.ts +87 -62
  38. package/dist/cjs/lib/domevent.js +84 -59
  39. package/dist/cjs/lib/domevent.js.map +1 -1
  40. package/dist/cjs/lib/emit.d.ts +62 -32
  41. package/dist/cjs/lib/emit.js +67 -53
  42. package/dist/cjs/lib/emit.js.map +1 -1
  43. package/dist/cjs/lib/kowrap.d.ts +6 -3
  44. package/dist/cjs/lib/kowrap.js +6 -3
  45. package/dist/cjs/lib/kowrap.js.map +1 -1
  46. package/dist/cjs/lib/obsArray.d.ts +91 -53
  47. package/dist/cjs/lib/obsArray.js +87 -55
  48. package/dist/cjs/lib/obsArray.js.map +1 -1
  49. package/dist/cjs/lib/observable.d.ts +25 -15
  50. package/dist/cjs/lib/observable.js +29 -18
  51. package/dist/cjs/lib/observable.js.map +1 -1
  52. package/dist/cjs/lib/pureComputed.d.ts +12 -15
  53. package/dist/cjs/lib/pureComputed.js +15 -18
  54. package/dist/cjs/lib/pureComputed.js.map +1 -1
  55. package/dist/cjs/lib/styled.d.ts +78 -61
  56. package/dist/cjs/lib/styled.js +26 -79
  57. package/dist/cjs/lib/styled.js.map +1 -1
  58. package/dist/cjs/lib/subscribe.d.ts +41 -37
  59. package/dist/cjs/lib/subscribe.js +31 -40
  60. package/dist/cjs/lib/subscribe.js.map +1 -1
  61. package/dist/cjs/lib/util.js +1 -0
  62. package/dist/cjs/lib/util.js.map +1 -1
  63. package/dist/cjs/lib/widgets/input.d.ts +3 -1
  64. package/dist/cjs/lib/widgets/input.js +6 -4
  65. package/dist/cjs/lib/widgets/input.js.map +1 -1
  66. package/dist/cjs/lib/widgets/select.d.ts +4 -2
  67. package/dist/cjs/lib/widgets/select.js +7 -5
  68. package/dist/cjs/lib/widgets/select.js.map +1 -1
  69. package/dist/esm/lib/_computed_queue.js +3 -3
  70. package/dist/esm/lib/_computed_queue.js.map +1 -1
  71. package/dist/esm/lib/binding.js +2 -2
  72. package/dist/esm/lib/binding.js.map +1 -1
  73. package/dist/esm/lib/computed.js +36 -50
  74. package/dist/esm/lib/computed.js.map +1 -1
  75. package/dist/esm/lib/dispose.js +104 -78
  76. package/dist/esm/lib/dispose.js.map +1 -1
  77. package/dist/esm/lib/dom.js +38 -18
  78. package/dist/esm/lib/dom.js.map +1 -1
  79. package/dist/esm/lib/domComponent.js +65 -0
  80. package/dist/esm/lib/domComponent.js.map +1 -1
  81. package/dist/esm/lib/domComputed.js +10 -7
  82. package/dist/esm/lib/domComputed.js.map +1 -1
  83. package/dist/esm/lib/domDispose.js +26 -11
  84. package/dist/esm/lib/domDispose.js.map +1 -1
  85. package/dist/esm/lib/domForEach.js +3 -2
  86. package/dist/esm/lib/domForEach.js.map +1 -1
  87. package/dist/esm/lib/domImpl.js +26 -7
  88. package/dist/esm/lib/domImpl.js.map +1 -1
  89. package/dist/esm/lib/domMethods.js +77 -35
  90. package/dist/esm/lib/domMethods.js.map +1 -1
  91. package/dist/esm/lib/domevent.js +84 -59
  92. package/dist/esm/lib/domevent.js.map +1 -1
  93. package/dist/esm/lib/emit.js +67 -53
  94. package/dist/esm/lib/emit.js.map +1 -1
  95. package/dist/esm/lib/kowrap.js +5 -2
  96. package/dist/esm/lib/kowrap.js.map +1 -1
  97. package/dist/esm/lib/obsArray.js +82 -50
  98. package/dist/esm/lib/obsArray.js.map +1 -1
  99. package/dist/esm/lib/observable.js +26 -15
  100. package/dist/esm/lib/observable.js.map +1 -1
  101. package/dist/esm/lib/pureComputed.js +15 -18
  102. package/dist/esm/lib/pureComputed.js.map +1 -1
  103. package/dist/esm/lib/styled.js +24 -77
  104. package/dist/esm/lib/styled.js.map +1 -1
  105. package/dist/esm/lib/subscribe.js +27 -36
  106. package/dist/esm/lib/subscribe.js.map +1 -1
  107. package/dist/esm/lib/util.js +1 -0
  108. package/dist/esm/lib/util.js.map +1 -1
  109. package/dist/esm/lib/widgets/input.js +3 -1
  110. package/dist/esm/lib/widgets/input.js.map +1 -1
  111. package/dist/esm/lib/widgets/select.js +3 -1
  112. package/dist/esm/lib/widgets/select.js.map +1 -1
  113. package/dist/grain-full.debug.js +2146 -3062
  114. package/dist/grain-full.debug.js.map +7 -0
  115. package/dist/grain-full.min.js +6 -2
  116. package/dist/grain-full.min.js.map +7 -1
  117. package/lib/binding.ts +9 -2
  118. package/lib/computed.ts +56 -56
  119. package/lib/dispose.ts +110 -85
  120. package/lib/dom.ts +39 -20
  121. package/lib/domComponent.ts +66 -57
  122. package/lib/domComputed.ts +29 -19
  123. package/lib/domDispose.ts +28 -11
  124. package/lib/domForEach.ts +7 -3
  125. package/lib/domImpl.ts +30 -7
  126. package/lib/domMethods.ts +101 -46
  127. package/lib/domevent.ts +85 -60
  128. package/lib/emit.ts +64 -50
  129. package/lib/kowrap.ts +5 -2
  130. package/lib/obsArray.ts +89 -54
  131. package/lib/observable.ts +26 -15
  132. package/lib/pureComputed.ts +16 -22
  133. package/lib/styled.ts +85 -71
  134. package/lib/subscribe.ts +41 -45
  135. package/lib/util.ts +1 -0
  136. package/lib/widgets/input.ts +3 -1
  137. package/lib/widgets/select.ts +3 -1
  138. package/package.json +38 -27
@@ -11,9 +11,9 @@ const browserGlobals_1 = require("./browserGlobals");
11
11
  */
12
12
  const _dataMap = new WeakMap();
13
13
  /**
14
- * Sets multiple attributes of a DOM element. The `attrs()` variant takes no `elem` argument.
14
+ * Sets multiple attributes of a DOM element.
15
15
  * Null and undefined values are omitted, and booleans are either omitted or set to empty string.
16
- * @param {Object} attrsObj: Object mapping attribute names to attribute values.
16
+ * @param attrsObj - Object mapping attribute names to attribute values.
17
17
  */
18
18
  function attrsElem(elem, attrsObj) {
19
19
  for (const key of Object.keys(attrsObj)) {
@@ -24,17 +24,20 @@ function attrsElem(elem, attrsObj) {
24
24
  }
25
25
  }
26
26
  exports.attrsElem = attrsElem;
27
+ /**
28
+ * Sets multiple attributes of a DOM element. Null and undefined values are omitted, and booleans
29
+ * are either omitted or set to empty string.
30
+ */
27
31
  function attrs(attrsObj) {
28
32
  return (elem) => attrsElem(elem, attrsObj);
29
33
  }
30
34
  exports.attrs = attrs;
31
35
  /**
32
36
  * Sets an attribute of a DOM element to the given value. Removes the attribute when the value is
33
- * null or undefined. The `attr()` variant takes no `elem` argument, and `attrValue` may be an
34
- * observable or function.
35
- * @param {Element} elem: The element to update.
36
- * @param {String} attrName: The name of the attribute to bind, e.g. 'href'.
37
- * @param {String|null} attrValue: The string value or null to remove the attribute.
37
+ * null or undefined.
38
+ * @param elem - The element to update.
39
+ * @param attrName - The name of the attribute to bind, e.g. 'href'.
40
+ * @param attrValue - The string value, or null or undefined to remove the attribute.
38
41
  */
39
42
  function attrElem(elem, attrName, attrValue) {
40
43
  if (attrValue === null || attrValue === undefined) {
@@ -45,101 +48,133 @@ function attrElem(elem, attrName, attrValue) {
45
48
  }
46
49
  }
47
50
  exports.attrElem = attrElem;
51
+ /**
52
+ * Sets an attribute of a DOM element to the given value. Removes the attribute when the value is
53
+ * null or undefined.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * dom('a', dom.attr('href', urlObs))
58
+ * ```
59
+ */
48
60
  function attr(attrName, attrValueObs) {
49
- return (elem) => binding_1.subscribeElem(elem, attrValueObs, (val) => attrElem(elem, attrName, val));
61
+ return (elem) => (0, binding_1.subscribeElem)(elem, attrValueObs, (val) => attrElem(elem, attrName, val));
50
62
  }
51
63
  exports.attr = attr;
52
64
  /**
53
65
  * Sets or removes a boolean attribute of a DOM element. According to the spec, empty string is a
54
66
  * valid true value for the attribute, and the false value is indicated by the attribute's absence.
55
- * The `boolAttr()` variant takes no `elem`, and `boolValue` may be an observable or function.
56
- * @param {Element} elem: The element to update.
57
- * @param {String} attrName: The name of the attribute to bind, e.g. 'checked'.
58
- * @param {Boolean} boolValue: Boolean value whether to set or unset the attribute.
67
+ * @param elem - The element to update.
68
+ * @param attrName - The name of the attribute to bind, e.g. 'checked'.
69
+ * @param boolValue - Boolean value whether to set or unset the attribute.
59
70
  */
60
71
  function boolAttrElem(elem, attrName, boolValue) {
61
72
  attrElem(elem, attrName, boolValue ? '' : null);
62
73
  }
63
74
  exports.boolAttrElem = boolAttrElem;
75
+ /**
76
+ * Dom-method that sets or removes a boolean attribute of a DOM element.
77
+ * @param attrName - The name of the attribute to bind, e.g. 'checked'.
78
+ * @param boolValueObs - Value, observable, or function for a whether to set or unset the attribute.
79
+ */
64
80
  function boolAttr(attrName, boolValueObs) {
65
- return (elem) => binding_1.subscribeElem(elem, boolValueObs, (val) => boolAttrElem(elem, attrName, val));
81
+ return (elem) => (0, binding_1.subscribeElem)(elem, boolValueObs, (val) => boolAttrElem(elem, attrName, val));
66
82
  }
67
83
  exports.boolAttr = boolAttr;
68
84
  /**
69
- * Adds a text node to the element. The `text()` variant takes no `elem`, and `value` may be an
70
- * observable or function.
71
- * @param {Element} elem: The element to update.
72
- * @param {String} value: The text value to add.
85
+ * Adds a text node to the element.
86
+ * @param elem - The element to update.
87
+ * @param value - The text value to add.
73
88
  */
74
89
  function textElem(elem, value) {
75
90
  elem.appendChild(browserGlobals_1.G.document.createTextNode(value));
76
91
  }
77
92
  exports.textElem = textElem;
93
+ /**
94
+ * Sets text content of a DOM element to a value that may be an observable or a function.
95
+ */
78
96
  function text(valueObs) {
79
97
  return (elem) => {
80
98
  const textNode = browserGlobals_1.G.document.createTextNode('');
81
- binding_1.subscribeElem(elem, valueObs, (val) => { textNode.nodeValue = val; });
99
+ (0, binding_1.subscribeElem)(elem, valueObs, (val) => { textNode.nodeValue = val; });
82
100
  elem.appendChild(textNode);
83
101
  };
84
102
  }
85
103
  exports.text = text;
86
104
  /**
87
- * Sets a style property of a DOM element to the given value. The `style()` variant takes no
88
- * `elem`, and `value` may be an observable or function.
89
- * @param {Element} elem: The element to update.
90
- * @param {String} property: The name of the style property to update, e.g. 'fontWeight'.
91
- * @param {String} value: The value for the property.
105
+ * Sets a style property of a DOM element to the given value.
106
+ * @param elem - The element to update.
107
+ * @param property - The name of the style property to update, e.g. 'fontWeight'.
108
+ * @param value - The value for the property.
92
109
  */
93
110
  function styleElem(elem, property, value) {
94
111
  elem.style[property] = value;
95
112
  }
96
113
  exports.styleElem = styleElem;
114
+ /**
115
+ * Sets a style property of a DOM element to the given value, which may be an observable or a
116
+ * function.
117
+ * @param property - The name of the style property to update, e.g. 'fontWeight'.
118
+ * @param value - The value for the property.
119
+ */
97
120
  function style(property, valueObs) {
98
- return (elem) => binding_1.subscribeElem(elem, valueObs, (val) => styleElem(elem, property, val));
121
+ return (elem) => (0, binding_1.subscribeElem)(elem, valueObs, (val) => styleElem(elem, property, val));
99
122
  }
100
123
  exports.style = style;
101
124
  /**
102
125
  * Sets the property of a DOM element to the given value.
103
- * The `prop()` variant takes no `elem`, and `value` may be an observable or function.
104
- * @param {Element} elem: The element to update.
105
- * @param {String} property: The name of the property to update, e.g. 'disabled'.
106
- * @param {Object} value: The value for the property.
126
+ * @param elem - The element to update.
127
+ * @param property - The name of the property to update, e.g. 'disabled'.
128
+ * @param value - The value for the property.
107
129
  */
108
130
  function propElem(elem, property, value) {
109
131
  elem[property] = value;
110
132
  }
111
133
  exports.propElem = propElem;
134
+ /**
135
+ * Sets the property of a DOM element to the given value, which may be an observable or a
136
+ * function.
137
+ * @param property - The name of the property to update, e.g. 'disabled'.
138
+ * @param value - The value for the property.
139
+ */
112
140
  function prop(property, valueObs) {
113
- return (elem) => binding_1.subscribeElem(elem, valueObs, (val) => propElem(elem, property, val));
141
+ return (elem) => (0, binding_1.subscribeElem)(elem, valueObs, (val) => propElem(elem, property, val));
114
142
  }
115
143
  exports.prop = prop;
116
144
  /**
117
145
  * Shows or hides the element depending on a boolean value. Note that the element must be visible
118
146
  * initially (i.e. unsetting style.display should show it).
119
- * The `show()` variant takes no `elem`, and `boolValue` may be an observable or function.
120
- * @param {Element} elem: The element to update.
121
- * @param {Boolean} boolValue: True to show the element, false to hide it.
147
+ * @param elem - The element to update.
148
+ * @param boolValue - True to show the element, false to hide it.
122
149
  */
123
150
  function showElem(elem, boolValue) {
124
151
  elem.style.display = boolValue ? '' : 'none';
125
152
  }
126
153
  exports.showElem = showElem;
154
+ /**
155
+ * Shows or hides the element depending on a boolean value, which may be an observable or a function.
156
+ * Note that the element must be visible by default (i.e. unsetting `style.display` should show it).
157
+ */
127
158
  function show(boolValueObs) {
128
- return (elem) => binding_1.subscribeElem(elem, boolValueObs, (val) => showElem(elem, val));
159
+ return (elem) => (0, binding_1.subscribeElem)(elem, boolValueObs, (val) => showElem(elem, val));
129
160
  }
130
161
  exports.show = show;
131
162
  /**
132
163
  * The opposite of show, hiding the element when boolValue is true.
133
- * The `hide()` variant takes no `elem`, and `boolValue` may be an observable or function.
134
- * @param {Element} elem: The element to update.
135
- * @param {Boolean} boolValue: True to hide the element, false to show it.
164
+ * @param elem - The element to update.
165
+ * @param boolValue - True to hide the element, false to show it.
136
166
  */
137
167
  function hideElem(elem, boolValue) {
138
168
  elem.style.display = boolValue ? 'none' : '';
139
169
  }
140
170
  exports.hideElem = hideElem;
171
+ /**
172
+ * The opposite of show, hiding the element when boolValue is true. `boolValueObs` may be an
173
+ * observable or a function.
174
+ * Note that the element must be visible by default (i.e. unsetting `style.display` should show it).
175
+ */
141
176
  function hide(boolValueObs) {
142
- return (elem) => binding_1.subscribeElem(elem, boolValueObs, (val) => hideElem(elem, val));
177
+ return (elem) => (0, binding_1.subscribeElem)(elem, boolValueObs, (val) => hideElem(elem, val));
143
178
  }
144
179
  exports.hide = hide;
145
180
  /**
@@ -157,7 +192,7 @@ function cls(className, boolValue) {
157
192
  return (elem) => clsElem(elem, className, boolValue);
158
193
  }
159
194
  else {
160
- return (elem) => binding_1.subscribeElem(elem, boolValue, (val) => clsElem(elem, className, val));
195
+ return (elem) => (0, binding_1.subscribeElem)(elem, boolValue, (val) => clsElem(elem, className, val));
161
196
  }
162
197
  }
163
198
  exports.cls = cls;
@@ -173,7 +208,7 @@ exports.clsPrefix = clsPrefix;
173
208
  function _clsDynamicPrefix(prefix, className) {
174
209
  return (elem) => {
175
210
  let prevClass = null;
176
- binding_1.subscribeElem(elem, className, (name) => {
211
+ (0, binding_1.subscribeElem)(elem, className, (name) => {
177
212
  if (prevClass) {
178
213
  elem.classList.remove(prevClass);
179
214
  }
@@ -185,11 +220,10 @@ function _clsDynamicPrefix(prefix, className) {
185
220
  };
186
221
  }
187
222
  /**
188
- * Associate arbitrary data with a DOM element. The `data()` variant takes no `elem`, and `value`
189
- * may be an observable or function.
190
- * @param {Element} elem: The element with which to associate data.
191
- * @param {String} key: Key to identify this piece of data among others attached to elem.
192
- * @param {Object} value: Arbitrary value to associate with elem.
223
+ * Associate arbitrary data with a DOM element.
224
+ * @param elem - The element with which to associate data.
225
+ * @param key - Key to identify this piece of data among others attached to elem.
226
+ * @param value - Arbitrary value to associate with elem.
193
227
  */
194
228
  function dataElem(elem, key, value) {
195
229
  const obj = _dataMap.get(elem);
@@ -197,15 +231,23 @@ function dataElem(elem, key, value) {
197
231
  obj[key] = value;
198
232
  }
199
233
  else {
200
- domDispose_1.onDisposeElem(elem, () => _dataMap.delete(elem));
234
+ (0, domDispose_1.onDisposeElem)(elem, () => _dataMap.delete(elem));
201
235
  _dataMap.set(elem, { [key]: value });
202
236
  }
203
237
  }
204
238
  exports.dataElem = dataElem;
239
+ /**
240
+ * Associate arbitrary data with a DOM element: `value` may be an observable or a function.
241
+ * @param key - Key to identify this piece of data among others attached to elem.
242
+ * @param value - Arbitrary value to associate with elem.
243
+ */
205
244
  function data(key, valueObs) {
206
- return (elem) => binding_1.subscribeElem(elem, valueObs, (val) => dataElem(elem, key, val));
245
+ return (elem) => (0, binding_1.subscribeElem)(elem, valueObs, (val) => dataElem(elem, key, val));
207
246
  }
208
247
  exports.data = data;
248
+ /**
249
+ * Retrieve data associated with a DOM element using `data()` or `dataElem()`.
250
+ */
209
251
  function getData(elem, key) {
210
252
  const obj = _dataMap.get(elem);
211
253
  return obj && obj[key];
@@ -1 +1 @@
1
- {"version":3,"file":"domMethods.js","sourceRoot":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C,IAAI,CAAC,CAAC,CAAC;QACjD,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAC,CAAC,CAAC;KACpC;AACH,CAAC;AARD,4BAQC;AAED;;;;GAIG;AACH,SAAgB,IAAI,CAAC,GAAW,EAAE,QAA4B;IAC5D,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,uBAAU,EAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACjF,CAAC;AAFD,oBAEC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,IAAU,EAAE,GAAW;IAC7C,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAHD,0BAGC;AAkCD;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC;AAFD,gCAEC;AAED;;GAEG;AACI,MAAM,QAAQ,GAAW,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC;AAA1C,QAAA,QAAQ,YAAkC"}
@@ -1,86 +1,106 @@
1
+ import { IDisposable } from './dispose';
2
+ import { DomElementMethod, DomMethod } from './domImpl';
3
+ export type EventName = keyof HTMLElementEventMap;
4
+ export type EventType<E extends EventName | string> = E extends EventName ? HTMLElementEventMap[E] : Event;
5
+ export type EventCB<E extends Event = Event, T extends EventTarget = EventTarget> = (this: void, event: E, elem: T) => void;
1
6
  /**
2
- * domevent provides a way to listen to DOM events, similar to JQuery's `on()` function. Its
3
- * methods are also exposed via the dom.js module, as `dom.on()`, etc.
4
- *
5
- * It is typically used as an argument to the dom() function:
6
- *
7
- * dom('div', dom.on('click', (event, elem) => { ... }));
8
- *
9
- * When the div is disposed, the listener is automatically removed.
10
- *
11
- * The underlying interface to listen to an event is this:
12
- *
13
- * let listener = dom.onElem(elem, 'click', (event, elem) => { ... });
14
- *
15
- * The callback is called with the event and the element to which it was attached. Unlike in
16
- * JQuery, the callback's return value is ignored. Use event.stopPropagation() and
17
- * event.preventDefault() explicitly if needed.
7
+ * Listen to a DOM event, returning the listener object.
8
+ * ```ts
9
+ * const listener = dom.onElem(elem, 'click', (event, elem) => { ... });
10
+ * ```
18
11
  *
19
12
  * To stop listening:
13
+ * ```ts
14
+ * listener.dispose();
15
+ * ```
16
+ *
17
+ * Disposing the listener returned by `onElem()` is the only way to stop listening to an event. You
18
+ * can use `autoDispose` to stop listening automatically when subscribing in a `Disposable` object:
19
+ * ```ts
20
+ * this.autoDispose(domevent.onElem(document, 'mouseup', callback));
21
+ * ```
22
+ *
23
+ * If you need "once" semantics, i.e. to remove the callback on first call, here's a useful pattern:
24
+ * ```ts
25
+ * const lis = domevent.onElem(elem, 'mouseup', e => { lis.dispose(); other_work(); });
26
+ * ```
27
+ *
28
+ * @param elem - DOM Element to listen to.
29
+ * @param eventType - Event type to listen for (e.g. `'click'`).
30
+ * @param callback - Callback to call as `callback(event, elem)`, where elem is `elem`.
31
+ * @param options - `useCapture: boolean`: Add the listener in the capture phase. This should very
32
+ * rarely be useful (e.g. JQuery doesn't even offer it as an option).
33
+ * @returns Listener object whose `.dispose()` method will remove the event listener.
34
+ */
35
+ export declare function onElem<E extends EventName | string, T extends EventTarget>(elem: T, eventType: E, callback: EventCB<EventType<E>, T>, { useCapture }?: {
36
+ useCapture?: boolean | undefined;
37
+ }): IDisposable;
38
+ /**
39
+ * Listen to a DOM event. It is typically used as an argument to the `dom()` function:
40
+ * ```ts
41
+ * dom('div', dom.on('click', (event, elem) => { ... }));
42
+ * ```
20
43
  *
21
- * listener.dispose();
22
- *
23
- * Disposing the listener returned by .onElem() is the only way to stop listening to an event. You
24
- * can use autoDispose to stop listening automatically when subscribing in a Disposable object:
44
+ * When the div is disposed, the listener is automatically removed.
25
45
  *
26
- * this.autoDispose(domevent.onElem(document, 'mouseup', callback));
46
+ * The callback is called with the event and the element to which it was attached. Unlike in, say,
47
+ * JQuery, the callback's return value is ignored. Use `event.stopPropagation()` and
48
+ * `event.preventDefault()` explicitly if needed.
27
49
  *
28
50
  * To listen to descendants of an element matching the given selector (what JQuery calls
29
- * "delegated events", see http://api.jquery.com/on/):
30
- *
31
- * dom('div', dom.onMatch('.selector', 'click', (event, elem) => { ... }));
32
- * or
33
- * let lis = domevent.onMatchElem(elem, '.selector', 'click', (event, el) => { ... });
51
+ * "delegated events", see http://api.jquery.com/on/), see [`onMatch`](#onMatch).
34
52
  *
35
- * In this usage, the element passed to the callback will be a DOM element matching the given
36
- * selector. If there are multiple matches, the callback is only called for the innermost one.
37
- *
38
- * If you need to remove the callback on first call, here's a useful pattern:
39
- * let lis = domevent.onElem(elem, 'mouseup', e => { lis.dispose(); other_work(); });
40
- */
41
- import { IDisposable } from './dispose';
42
- import { DomElementMethod, DomMethod } from './domImpl';
43
- export declare type EventName = keyof HTMLElementEventMap;
44
- export declare type EventType<E extends EventName | string> = E extends EventName ? HTMLElementEventMap[E] : Event;
45
- export declare type EventCB<E extends Event = Event, T extends EventTarget = EventTarget> = (this: void, event: E, elem: T) => void;
46
- /**
47
- * Listen to a DOM event. The `on()` variant takes no `elem` argument, and may be used as an
48
- * argument to dom() function.
49
- * @param {DOMElement} elem: DOM Element to listen to.
50
- * @param {String} eventType: Event type to listen for (e.g. 'click').
51
- * @param {Function} callback: Callback to call as `callback(event, elem)`, where elem is `elem`.
52
- * @param [Boolean] options.useCapture: Add the listener in the capture phase. This should very
53
- * rarely be useful (e.g. JQuery doesn't even offer it as an option).
54
- * @returns {Object} Listener object whose .dispose() method will remove the event listener.
53
+ * @param eventType - Event type to listen for (e.g. `'click'`).
54
+ * @param callback - Callback to call as `callback(event, elem)`, where `elem` is the element this
55
+ * listener is attached to.
56
+ * @param options - `useCapture?: boolean`: Add the listener in the capture phase.
55
57
  */
56
- export declare function onElem<E extends EventName | string, T extends EventTarget>(elem: T, eventType: E, callback: EventCB<EventType<E>, T>, { useCapture }?: {
57
- useCapture?: boolean | undefined;
58
- }): IDisposable;
59
58
  export declare function on<E extends EventName | string, T extends EventTarget>(eventType: E, callback: EventCB<EventType<E>, T>, { useCapture }?: {
60
59
  useCapture?: boolean | undefined;
61
60
  }): DomMethod<T>;
62
61
  /**
63
- * Listen to a DOM event on descendants of the given elem matching the given selector. The
64
- * `onMatch()` variant takes no `elem` argument, and may be used as an argument to dom().
65
- * @param {DOMElement} elem: DOM Element to whose descendants to listen.
66
- * @param {String} selector: CSS selector string to filter elements that trigger this event.
62
+ * Listen to a DOM event on descendants of the given elem matching the given selector.
63
+ *
64
+ * ```ts
65
+ * const let lis = domevent.onMatchElem(elem, '.selector', 'click', (event, el) => { ... });
66
+ * ```
67
+ *
68
+ * @param elem - DOM Element to whose descendants to listen.
69
+ * @param selector - CSS selector string to filter elements that trigger this event.
67
70
  * JQuery calls it "delegated events" (http://api.jquery.com/on/). The callback will only be
68
71
  * called when the event occurs for an element matching the given selector. If there are
69
72
  * multiple elements matching the selector, the callback is only called for the innermost one.
70
- * @param {String} eventType: Event type to listen for (e.g. 'click').
71
- * @param {Function} callback: Callback to call as `callback(event, elem)`, where elem is a
73
+ * @param eventType - Event type to listen for (e.g. 'click').
74
+ * @param callback - Callback to call as `callback(event, elem)`, where elem is a
72
75
  * descendent of `elem` which matches `selector`.
73
- * @param [Boolean] options.useCapture: Add the listener in the capture phase. This should very
74
- * rarely be useful (e.g. JQuery doesn't even offer it as an option).
75
- * @returns {Object} Listener object whose .dispose() method will remove the event listener.
76
+ * @param options - `useCapture?: boolean`: Add the listener in the capture phase.
77
+ * @returns Listener object whose `.dispose()` method will remove the event listener.
76
78
  */
77
79
  export declare function onMatchElem(elem: EventTarget, selector: string, eventType: string, callback: EventCB, { useCapture }?: {
78
80
  useCapture?: boolean | undefined;
79
81
  }): IDisposable;
82
+ /**
83
+ * Listen to a DOM event on descendants of the given element matching the given selector.
84
+ *
85
+ * This is similar to JQuery's [delegated events](https://api.jquery.com/on/#direct-and-delegated-events)
86
+ *
87
+ * ```ts
88
+ * dom('div', dom.onMatch('.selector', 'click', (event, elem) => { ... }));
89
+ * ```
90
+ *
91
+ * In this usage, the element passed to the callback will be a DOM element matching the given
92
+ * selector. If there are multiple matches, the callback is only called for the innermost one.
93
+ *
94
+ * @param selector - CSS selector string to filter elements that trigger this event.
95
+ * @param eventType - Event type to listen for (e.g. `'click'`).
96
+ * @param callback - Callback to call as `callback(event, elem)`, where `elem` is an element
97
+ * matching `selector`.
98
+ * @param options - `useCapture?: boolean`: Add the listener in the capture phase.
99
+ */
80
100
  export declare function onMatch(selector: string, eventType: string, callback: EventCB, { useCapture }?: {
81
101
  useCapture?: boolean | undefined;
82
102
  }): DomElementMethod;
83
- export declare type KeyEventType = 'keypress' | 'keyup' | 'keydown';
103
+ export type KeyEventType = 'keypress' | 'keyup' | 'keydown';
84
104
  export interface IKeyHandlers<T extends HTMLElement = HTMLElement> {
85
105
  [key: string]: (this: void, ev: KeyboardEvent, elem: T) => void;
86
106
  }
@@ -88,8 +108,6 @@ export interface IKeyHandlers<T extends HTMLElement = HTMLElement> {
88
108
  * Listen to key events (typically 'keydown' or 'keypress'), with specified per-key callbacks.
89
109
  * Key names are listed at https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
90
110
  *
91
- * Methods onKeyPress() and onKeyDown() are intended to be used as arguments to dom().
92
- *
93
111
  * By default, handled events are stopped from bubbling with stopPropagation() and
94
112
  * preventDefault(). If, however, you register a key with a "$" suffix (i.e. "Enter$" instead of
95
113
  * "Enter"), then the event is allowed to bubble normally.
@@ -98,7 +116,7 @@ export interface IKeyHandlers<T extends HTMLElement = HTMLElement> {
98
116
  * to allow this element to receive keyboard events.
99
117
  *
100
118
  * For example:
101
- *
119
+ * ```
102
120
  * dom('input', ...
103
121
  * dom.onKeyDown({
104
122
  * Enter: (e, elem) => console.log("Enter pressed"),
@@ -106,7 +124,14 @@ export interface IKeyHandlers<T extends HTMLElement = HTMLElement> {
106
124
  * Delete$: (e, elem) => console.log("Delete pressed, will bubble"),
107
125
  * })
108
126
  * )
127
+ * ```
109
128
  */
110
129
  export declare function onKeyElem<T extends HTMLElement>(elem: T, evType: KeyEventType, keyHandlers: IKeyHandlers<T>): IDisposable;
130
+ /**
131
+ * Add listeners to `"keypress"` events. See [`onKeyElem`](#onKeyElem) for details.
132
+ */
111
133
  export declare function onKeyPress<T extends HTMLElement>(keyHandlers: IKeyHandlers<T>): DomMethod<T>;
134
+ /**
135
+ * Add listeners to `"keydown"` events. See [`onKeyElem`](#onKeyElem) for details.
136
+ */
112
137
  export declare function onKeyDown<T extends HTMLElement>(keyHandlers: IKeyHandlers<T>): DomMethod<T>;