jj 3.0.0-rc.3 → 3.0.0-rc.4
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/lib/bundle.cjs +35 -24
- package/lib/bundle.cjs.map +1 -1
- package/lib/bundle.d.cts +27 -41
- package/lib/bundle.d.ts +27 -41
- package/lib/bundle.global.js +35 -22
- package/lib/bundle.global.js.map +1 -1
- package/lib/bundle.js +35 -23
- package/lib/bundle.js.map +1 -1
- package/lib/bundle.min.cjs +2 -2
- package/lib/bundle.min.cjs.map +1 -1
- package/lib/bundle.min.d.cts +27 -41
- package/lib/bundle.min.d.ts +27 -41
- package/lib/bundle.min.global.js +2 -2
- package/lib/bundle.min.global.js.map +1 -1
- package/lib/bundle.min.js +2 -2
- package/lib/bundle.min.js.map +1 -1
- package/package.json +5 -5
package/lib/bundle.cjs
CHANGED
|
@@ -38,7 +38,6 @@ __export(src_exports, {
|
|
|
38
38
|
JJSR: () => JJSR,
|
|
39
39
|
JJT: () => JJT,
|
|
40
40
|
attr2prop: () => attr2prop,
|
|
41
|
-
customEvent: () => customEvent,
|
|
42
41
|
defineComponent: () => defineComponent,
|
|
43
42
|
fetchStyle: () => fetchStyle,
|
|
44
43
|
fetchTemplate: () => fetchTemplate
|
|
@@ -102,17 +101,6 @@ function toStr(x) {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
// src/wrappers/JJET.ts
|
|
105
|
-
function customEvent(type, detail, options) {
|
|
106
|
-
if (!isStr(type)) {
|
|
107
|
-
throw typeErr("eventName", "a string", type, 'Pass an event name like "todo-toggle".');
|
|
108
|
-
}
|
|
109
|
-
return new CustomEvent(type, {
|
|
110
|
-
bubbles: true,
|
|
111
|
-
composed: true,
|
|
112
|
-
...options,
|
|
113
|
-
detail
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
104
|
var _ref;
|
|
117
105
|
var _JJET = class _JJET {
|
|
118
106
|
/**
|
|
@@ -162,15 +150,15 @@ var _JJET = class _JJET {
|
|
|
162
150
|
* @example
|
|
163
151
|
* ```ts
|
|
164
152
|
* const target = {
|
|
165
|
-
*
|
|
153
|
+
* dispatching a plain Event object.
|
|
166
154
|
* increment() {
|
|
167
155
|
* this.count++
|
|
168
156
|
* },
|
|
169
157
|
* }
|
|
170
158
|
*
|
|
171
|
-
*
|
|
159
|
+
* @param options Optional event initialization dictionary.
|
|
172
160
|
* ```
|
|
173
|
-
* @
|
|
161
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Event/Event | Event()} for details on event options.
|
|
174
162
|
* @param handler - The event handler.
|
|
175
163
|
* @param options - Optional event listener options.
|
|
176
164
|
* @returns This instance for chaining.
|
|
@@ -210,16 +198,41 @@ var _JJET = class _JJET {
|
|
|
210
198
|
/**
|
|
211
199
|
* Dispatches an Event at the specified EventTarget.
|
|
212
200
|
*
|
|
213
|
-
* @param event - The Event object to dispatch.
|
|
201
|
+
* @param event - The Event object to dispatch. Since CustomEvent extends Event, you can also dispatch CustomEvent instances here.
|
|
214
202
|
* @returns This instance for chaining.
|
|
215
203
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent | EventTarget.dispatchEvent}
|
|
204
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent | CustomEvent} for creating custom events with payloads.
|
|
205
|
+
* @see {@link triggerEvent} for a convenience wrapper that creates and dispatches an Event in one step.
|
|
206
|
+
* @see {@link triggerCustomEvent} for a convenience wrapper that creates and dispatches a CustomEvent with JJ's default settings in one step.
|
|
216
207
|
*/
|
|
217
208
|
trigger(event) {
|
|
218
|
-
|
|
219
|
-
|
|
209
|
+
try {
|
|
210
|
+
this.ref.dispatchEvent(event);
|
|
211
|
+
return this;
|
|
212
|
+
} catch (cause) {
|
|
213
|
+
throw new Error(`Failed to trigger the event ${JSON.stringify(event)}`, { cause });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Creates a new `Event` and dispatches on the wrapped target.
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* This is a convenience wrapper around {@link trigger} for the common case of
|
|
221
|
+
* dispatching a plain Event object.
|
|
222
|
+
*
|
|
223
|
+
* The created event defaults to `bubbles: true` and `composed: true`.
|
|
224
|
+
* Pass `options` to override those defaults.
|
|
225
|
+
*
|
|
226
|
+
* @param type The name identifying the type of the event for example 'click'
|
|
227
|
+
* @param options Optional event initialization dictionary.
|
|
228
|
+
* @returns This instance for chaining.
|
|
229
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Event/Event | Event()} for details on event options.
|
|
230
|
+
*/
|
|
231
|
+
triggerEvent(type, options) {
|
|
232
|
+
return this.trigger(new Event(type, { bubbles: true, composed: true, ...options }));
|
|
220
233
|
}
|
|
221
234
|
/**
|
|
222
|
-
* Creates
|
|
235
|
+
* Creates a new `CustomEvent` and dispatches on the wrapped target.
|
|
223
236
|
*
|
|
224
237
|
* @remarks
|
|
225
238
|
* This is a convenience wrapper around {@link trigger} for the common case of
|
|
@@ -228,11 +241,10 @@ var _JJET = class _JJET {
|
|
|
228
241
|
* The created event defaults to `bubbles: true` and `composed: true`.
|
|
229
242
|
* Pass `options` to override those defaults.
|
|
230
243
|
*
|
|
231
|
-
* @param
|
|
244
|
+
* @param type - The event type name.
|
|
232
245
|
* @param detail - Optional payload exposed as `event.detail`.
|
|
233
246
|
* @param options - Additional `CustomEvent` options excluding `detail`.
|
|
234
247
|
* @returns This instance for chaining.
|
|
235
|
-
* @throws {TypeError} If `eventName` is not a string.
|
|
236
248
|
* @example
|
|
237
249
|
* ```ts
|
|
238
250
|
* JJET.from(window).triggerCustomEvent('panel-ready', { id: '123' })
|
|
@@ -247,8 +259,8 @@ var _JJET = class _JJET {
|
|
|
247
259
|
* ```
|
|
248
260
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent | CustomEvent()}
|
|
249
261
|
*/
|
|
250
|
-
triggerCustomEvent(
|
|
251
|
-
return this.trigger(
|
|
262
|
+
triggerCustomEvent(type, detail, options) {
|
|
263
|
+
return this.trigger(new CustomEvent(type, { bubbles: true, composed: true, ...options, detail }));
|
|
252
264
|
}
|
|
253
265
|
/**
|
|
254
266
|
* Runs a function in the context of this JJET instance.
|
|
@@ -2929,7 +2941,6 @@ async function defineComponent(name, constructor, options) {
|
|
|
2929
2941
|
JJSR,
|
|
2930
2942
|
JJT,
|
|
2931
2943
|
attr2prop,
|
|
2932
|
-
customEvent,
|
|
2933
2944
|
defineComponent,
|
|
2934
2945
|
fetchStyle,
|
|
2935
2946
|
fetchTemplate
|