@aegisjsproject/callback-registry 1.0.0 → 1.0.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/CHANGELOG.md +9 -0
- package/callbackRegistry.cjs +3 -3
- package/callbackRegistry.mjs +2 -509
- package/callbackRegistry.mjs.map +1 -0
- package/callbacks.cjs +3 -3
- package/callbacks.js +3 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [v1.0.1] - 2024-11-17
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Add sourcemap for minified main export module
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Fix registration for `back` and `forward` callbacks
|
|
17
|
+
- Fix eslint config
|
|
18
|
+
|
|
10
19
|
## [v1.0.0] - 2024-11-16
|
|
11
20
|
|
|
12
21
|
Initial Release
|
package/callbackRegistry.cjs
CHANGED
|
@@ -42,8 +42,8 @@ const registry = new Map([
|
|
|
42
42
|
[FUNCS.debug.warn, console.warn],
|
|
43
43
|
[FUNCS.debug.error, console.error],
|
|
44
44
|
[FUNCS.debug.info, console.info],
|
|
45
|
-
[FUNCS.navigate.back, history.back],
|
|
46
|
-
[FUNCS.navigate.forward, history.forward],
|
|
45
|
+
[FUNCS.navigate.back, () => history.back()],
|
|
46
|
+
[FUNCS.navigate.forward, () => history.forward()],
|
|
47
47
|
[FUNCS.navigate.reload, () => history.go(0)],
|
|
48
48
|
[FUNCS.navigate.link, event => {
|
|
49
49
|
if (event.isTrusted) {
|
|
@@ -170,7 +170,7 @@ const unregisterCallback = name => _isRegistrationOpen && registry.delete(name);
|
|
|
170
170
|
/**
|
|
171
171
|
* Remove all callbacks from the registry
|
|
172
172
|
*
|
|
173
|
-
* @returns {
|
|
173
|
+
* @returns {void}
|
|
174
174
|
*/
|
|
175
175
|
const clearRegistry = () => registry.clear();
|
|
176
176
|
|
package/callbackRegistry.mjs
CHANGED
|
@@ -1,509 +1,2 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
3
|
-
const $$ = (selector, base = document) => base.querySelectorAll(selector);
|
|
4
|
-
|
|
5
|
-
const $ = (selector, base = document) => base.querySelector(selector);
|
|
6
|
-
|
|
7
|
-
const FUNCS = {
|
|
8
|
-
debug: {
|
|
9
|
-
log: 'aegis:debug:log',
|
|
10
|
-
info: 'aegis:debug:info',
|
|
11
|
-
warn: 'aegis:debug:warn',
|
|
12
|
-
error: 'aegis:debug:error',
|
|
13
|
-
},
|
|
14
|
-
navigate: {
|
|
15
|
-
back: 'aegis:navigate:back',
|
|
16
|
-
forward: 'aegis:navigate:forward',
|
|
17
|
-
reload: 'aegis:navigate:reload',
|
|
18
|
-
link: 'aegis:navigate:go',
|
|
19
|
-
popup: 'aegis:navigate:popup',
|
|
20
|
-
},
|
|
21
|
-
ui: {
|
|
22
|
-
print: 'aegis:ui:print',
|
|
23
|
-
remove: 'aegis:ui:remove',
|
|
24
|
-
hide: 'aegis:ui:hide',
|
|
25
|
-
unhide: 'aegis:ui:unhide',
|
|
26
|
-
showModal: 'aegis:ui:showModal',
|
|
27
|
-
closeModal: 'aegis:ui:closeModal',
|
|
28
|
-
showPopover: 'aegis:ui:showPopover',
|
|
29
|
-
hidePopover: 'aegis:ui:hidePopover',
|
|
30
|
-
togglePopover: 'aegis:ui:togglePopover',
|
|
31
|
-
enable: 'aegis:ui:enable',
|
|
32
|
-
disable: 'aegis:ui:disable',
|
|
33
|
-
scrollTo: 'aegis:ui:scrollTo',
|
|
34
|
-
prevent: 'aegis:ui:prevent',
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const registry = new Map([
|
|
39
|
-
[FUNCS.debug.log, console.log],
|
|
40
|
-
[FUNCS.debug.warn, console.warn],
|
|
41
|
-
[FUNCS.debug.error, console.error],
|
|
42
|
-
[FUNCS.debug.info, console.info],
|
|
43
|
-
[FUNCS.navigate.back, history.back],
|
|
44
|
-
[FUNCS.navigate.forward, history.forward],
|
|
45
|
-
[FUNCS.navigate.reload, () => history.go(0)],
|
|
46
|
-
[FUNCS.navigate.link, event => {
|
|
47
|
-
if (event.isTrusted) {
|
|
48
|
-
event.preventDefault();
|
|
49
|
-
location.href = event.currentTarget.dataset.url;
|
|
50
|
-
}
|
|
51
|
-
}],
|
|
52
|
-
[FUNCS.navigate.popup, event => {
|
|
53
|
-
if (event.isTrusted) {
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
globalThis.open(event.currentTarget.dataset.url);
|
|
56
|
-
}
|
|
57
|
-
}],
|
|
58
|
-
[FUNCS.ui.hide, ({ currentTarget }) => {
|
|
59
|
-
$$(currentTarget.dataset.hideSelector).forEach(el => el.hidden = true);
|
|
60
|
-
}],
|
|
61
|
-
[FUNCS.ui.unhide, ({ currentTarget }) => {
|
|
62
|
-
$$(currentTarget.dataset.unhideSelector).forEach(el => el.hidden = false);
|
|
63
|
-
}],
|
|
64
|
-
[FUNCS.ui.disable, ({ currentTarget }) => {
|
|
65
|
-
$$(currentTarget.dataset.disableSelector).forEach(el => el.disabled = true);
|
|
66
|
-
}],
|
|
67
|
-
[FUNCS.ui.enable, ({ currentTarget }) => {
|
|
68
|
-
$$(currentTarget.dataset.enableSelector).forEach(el => el.disabled = false);
|
|
69
|
-
}],
|
|
70
|
-
[FUNCS.ui.remove, ({ currentTarget }) => {
|
|
71
|
-
$$(currentTarget.dataset.removeSelector).forEach(el => el.remove());
|
|
72
|
-
}],
|
|
73
|
-
[FUNCS.ui.scrollTo, ({ currentTarget }) => {
|
|
74
|
-
const target = $(currentTarget.dataset.scrollToSelector);
|
|
75
|
-
|
|
76
|
-
if (target instanceof Element) {
|
|
77
|
-
target.scrollIntoView({
|
|
78
|
-
behavior: matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
79
|
-
? 'instant'
|
|
80
|
-
: 'smooth',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}],
|
|
84
|
-
[FUNCS.ui.showModal, ({ currentTarget }) => {
|
|
85
|
-
const target = $(currentTarget.dataset.showModalSelector);
|
|
86
|
-
|
|
87
|
-
if (target instanceof HTMLDialogElement) {
|
|
88
|
-
target.showModal();
|
|
89
|
-
}
|
|
90
|
-
}],
|
|
91
|
-
[FUNCS.ui.closeModal, ({ currentTarget }) => {
|
|
92
|
-
const target = $(currentTarget.dataset.closeModalSelector);
|
|
93
|
-
|
|
94
|
-
if (target instanceof HTMLDialogElement) {
|
|
95
|
-
target.close();
|
|
96
|
-
}
|
|
97
|
-
}],
|
|
98
|
-
[FUNCS.ui.showPopover, ({ currentTarget }) => {
|
|
99
|
-
const target = $(currentTarget.dataset.showPopoverSelector);
|
|
100
|
-
|
|
101
|
-
if (target instanceof HTMLElement) {
|
|
102
|
-
target.showPopover();
|
|
103
|
-
}
|
|
104
|
-
}],
|
|
105
|
-
[FUNCS.ui.hidePopover, ({ currentTarget }) => {
|
|
106
|
-
const target = $(currentTarget.dataset.hidePopoverSelector);
|
|
107
|
-
|
|
108
|
-
if (target instanceof HTMLElement) {
|
|
109
|
-
target.hidePopover();
|
|
110
|
-
}
|
|
111
|
-
}],
|
|
112
|
-
[FUNCS.ui.togglePopover, ({ currentTarget }) => {
|
|
113
|
-
const target = $(currentTarget.dataset.togglePopoverSelector);
|
|
114
|
-
|
|
115
|
-
if (target instanceof HTMLElement) {
|
|
116
|
-
target.togglePopover();
|
|
117
|
-
}
|
|
118
|
-
}],
|
|
119
|
-
[FUNCS.ui.print, () => globalThis.print()],
|
|
120
|
-
[FUNCS.ui.prevent, event => event.preventDefault()],
|
|
121
|
-
]);
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Check if callback registry is open
|
|
125
|
-
*
|
|
126
|
-
* @returns {boolean} Whether or not callback registry is open
|
|
127
|
-
*/
|
|
128
|
-
const isRegistrationOpen = () => _isRegistrationOpen;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Close callback registry
|
|
132
|
-
*
|
|
133
|
-
* @returns {boolean} Whether or not the callback was succesfully removed
|
|
134
|
-
*/
|
|
135
|
-
const closeRegistration = () => _isRegistrationOpen = false;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Get an array of registered callbacks
|
|
139
|
-
*
|
|
140
|
-
* @returns {Array} A frozen array listing keys to all registered callbacks
|
|
141
|
-
*/
|
|
142
|
-
const listCallbacks = () => Object.freeze(Array.from(registry.keys()));
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Check if a callback is registered
|
|
146
|
-
*
|
|
147
|
-
* @param {string} name The name/key to check for in callback registry
|
|
148
|
-
* @returns {boolean} Whether or not a callback is registered
|
|
149
|
-
*/
|
|
150
|
-
const hasCallback = name => registry.has(name);
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Get a callback from the registry by name/key
|
|
154
|
-
*
|
|
155
|
-
* @param {string} name The name/key of the callback to get
|
|
156
|
-
* @returns {Function|undefined} The corresponding function registered under that name/key
|
|
157
|
-
*/
|
|
158
|
-
const getCallback = name => registry.get(name);
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Remove a callback from the registry
|
|
162
|
-
*
|
|
163
|
-
* @param {string} name The name/key of the callback to get
|
|
164
|
-
* @returns {boolean} Whether or not the callback was successfully unregisterd
|
|
165
|
-
*/
|
|
166
|
-
const unregisterCallback = name => _isRegistrationOpen && registry.delete(name);
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Remove all callbacks from the registry
|
|
170
|
-
*
|
|
171
|
-
* @returns {undefined}
|
|
172
|
-
*/
|
|
173
|
-
const clearRegistry = () => registry.clear();
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Create a registered callback with a randomly generated name
|
|
177
|
-
*
|
|
178
|
-
* @param {Function} callback Callback function to register
|
|
179
|
-
* @returns {string} The automatically generated key/name of the registered callback
|
|
180
|
-
*/
|
|
181
|
-
const createCallback = (callback) => registerCallback('aegis:callback:' + crypto.randomUUID(), callback);
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Call a callback fromt the registry by name/key
|
|
185
|
-
*
|
|
186
|
-
* @param {string} name The name/key of the registered function
|
|
187
|
-
* @param {...any} args Any arguments to pass along to the function
|
|
188
|
-
* @returns {any} Whatever the return value of the function is
|
|
189
|
-
* @throws {Error} Throws if callback is not found or any error resulting from calling the function
|
|
190
|
-
*/
|
|
191
|
-
function callCallback(name, ...args) {
|
|
192
|
-
if (registry.has(name)) {
|
|
193
|
-
return registry.get(name).apply(this || globalThis, args);
|
|
194
|
-
} else {
|
|
195
|
-
throw new Error(`No ${name} function registered.`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Register a named callback in registry
|
|
201
|
-
*
|
|
202
|
-
* @param {string} name The name/key to register the callback under
|
|
203
|
-
* @param {Function} callback The callback value to register
|
|
204
|
-
* @returns {string} The registered name/key
|
|
205
|
-
*/
|
|
206
|
-
function registerCallback(name, callback) {
|
|
207
|
-
if (typeof name !== 'string' || name.length === 0) {
|
|
208
|
-
throw new TypeError('Callback name must be a string.');
|
|
209
|
-
} if (! (callback instanceof Function)) {
|
|
210
|
-
throw new TypeError('Callback must be a function.');
|
|
211
|
-
} else if (! _isRegistrationOpen) {
|
|
212
|
-
throw new TypeError('Cannot register new callbacks because registry is closed.');
|
|
213
|
-
} else if (registry.has(name)) {
|
|
214
|
-
throw new Error(`Handler "${name}" is already registered.`);
|
|
215
|
-
} else {
|
|
216
|
-
registry.set(name, callback);
|
|
217
|
-
return name;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Get the host/root node of a given thing.
|
|
223
|
-
*
|
|
224
|
-
* @param {Event|Document|Element|ShadowRoot} target Source thing to search for host of
|
|
225
|
-
* @returns {Document|Element|null} The host/root node, or null
|
|
226
|
-
*/
|
|
227
|
-
function getHost(target) {
|
|
228
|
-
if (target instanceof Event) {
|
|
229
|
-
return getHost(target.currentTarget);
|
|
230
|
-
} else if (target instanceof Document) {
|
|
231
|
-
return target;
|
|
232
|
-
} else if (target instanceof Element) {
|
|
233
|
-
return getHost(target.getRootNode());
|
|
234
|
-
} else if (target instanceof ShadowRoot) {
|
|
235
|
-
return target.host;
|
|
236
|
-
} else {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const EVENT_PREFIX = 'data-aegis-event-on-';
|
|
242
|
-
const EVENT_PREFIX_LENGTH = EVENT_PREFIX.length;
|
|
243
|
-
const DATA_PREFIX = 'aegisEventOn';
|
|
244
|
-
const DATA_PREFIX_LENGTH = DATA_PREFIX.length;
|
|
245
|
-
|
|
246
|
-
const once = 'data-aegis-event-once',
|
|
247
|
-
passive = 'data-aegis-event-passive',
|
|
248
|
-
capture = 'data-aegis-event-capture';
|
|
249
|
-
|
|
250
|
-
const eventAttrs = [
|
|
251
|
-
EVENT_PREFIX + 'abort',
|
|
252
|
-
EVENT_PREFIX + 'blur',
|
|
253
|
-
EVENT_PREFIX + 'focus',
|
|
254
|
-
EVENT_PREFIX + 'cancel',
|
|
255
|
-
EVENT_PREFIX + 'auxclick',
|
|
256
|
-
EVENT_PREFIX + 'beforeinput',
|
|
257
|
-
EVENT_PREFIX + 'beforetoggle',
|
|
258
|
-
EVENT_PREFIX + 'canplay',
|
|
259
|
-
EVENT_PREFIX + 'canplaythrough',
|
|
260
|
-
EVENT_PREFIX + 'change',
|
|
261
|
-
EVENT_PREFIX + 'click',
|
|
262
|
-
EVENT_PREFIX + 'close',
|
|
263
|
-
EVENT_PREFIX + 'contextmenu',
|
|
264
|
-
EVENT_PREFIX + 'copy',
|
|
265
|
-
EVENT_PREFIX + 'cuechange',
|
|
266
|
-
EVENT_PREFIX + 'cut',
|
|
267
|
-
EVENT_PREFIX + 'dblclick',
|
|
268
|
-
EVENT_PREFIX + 'drag',
|
|
269
|
-
EVENT_PREFIX + 'dragend',
|
|
270
|
-
EVENT_PREFIX + 'dragenter',
|
|
271
|
-
EVENT_PREFIX + 'dragexit',
|
|
272
|
-
EVENT_PREFIX + 'dragleave',
|
|
273
|
-
EVENT_PREFIX + 'dragover',
|
|
274
|
-
EVENT_PREFIX + 'dragstart',
|
|
275
|
-
EVENT_PREFIX + 'drop',
|
|
276
|
-
EVENT_PREFIX + 'durationchange',
|
|
277
|
-
EVENT_PREFIX + 'emptied',
|
|
278
|
-
EVENT_PREFIX + 'ended',
|
|
279
|
-
EVENT_PREFIX + 'formdata',
|
|
280
|
-
EVENT_PREFIX + 'input',
|
|
281
|
-
EVENT_PREFIX + 'invalid',
|
|
282
|
-
EVENT_PREFIX + 'keydown',
|
|
283
|
-
EVENT_PREFIX + 'keypress',
|
|
284
|
-
EVENT_PREFIX + 'keyup',
|
|
285
|
-
EVENT_PREFIX + 'load',
|
|
286
|
-
EVENT_PREFIX + 'loadeddata',
|
|
287
|
-
EVENT_PREFIX + 'loadedmetadata',
|
|
288
|
-
EVENT_PREFIX + 'loadstart',
|
|
289
|
-
EVENT_PREFIX + 'mousedown',
|
|
290
|
-
EVENT_PREFIX + 'mouseenter',
|
|
291
|
-
EVENT_PREFIX + 'mouseleave',
|
|
292
|
-
EVENT_PREFIX + 'mousemove',
|
|
293
|
-
EVENT_PREFIX + 'mouseout',
|
|
294
|
-
EVENT_PREFIX + 'mouseover',
|
|
295
|
-
EVENT_PREFIX + 'mouseup',
|
|
296
|
-
EVENT_PREFIX + 'wheel',
|
|
297
|
-
EVENT_PREFIX + 'paste',
|
|
298
|
-
EVENT_PREFIX + 'pause',
|
|
299
|
-
EVENT_PREFIX + 'play',
|
|
300
|
-
EVENT_PREFIX + 'playing',
|
|
301
|
-
EVENT_PREFIX + 'progress',
|
|
302
|
-
EVENT_PREFIX + 'ratechange',
|
|
303
|
-
EVENT_PREFIX + 'reset',
|
|
304
|
-
EVENT_PREFIX + 'resize',
|
|
305
|
-
EVENT_PREFIX + 'scroll',
|
|
306
|
-
EVENT_PREFIX + 'scrollend',
|
|
307
|
-
EVENT_PREFIX + 'securitypolicyviolation',
|
|
308
|
-
EVENT_PREFIX + 'seeked',
|
|
309
|
-
EVENT_PREFIX + 'seeking',
|
|
310
|
-
EVENT_PREFIX + 'select',
|
|
311
|
-
EVENT_PREFIX + 'slotchange',
|
|
312
|
-
EVENT_PREFIX + 'stalled',
|
|
313
|
-
EVENT_PREFIX + 'submit',
|
|
314
|
-
EVENT_PREFIX + 'suspend',
|
|
315
|
-
EVENT_PREFIX + 'timeupdate',
|
|
316
|
-
EVENT_PREFIX + 'volumechange',
|
|
317
|
-
EVENT_PREFIX + 'waiting',
|
|
318
|
-
EVENT_PREFIX + 'selectstart',
|
|
319
|
-
EVENT_PREFIX + 'selectionchange',
|
|
320
|
-
EVENT_PREFIX + 'toggle',
|
|
321
|
-
EVENT_PREFIX + 'pointercancel',
|
|
322
|
-
EVENT_PREFIX + 'pointerdown',
|
|
323
|
-
EVENT_PREFIX + 'pointerup',
|
|
324
|
-
EVENT_PREFIX + 'pointermove',
|
|
325
|
-
EVENT_PREFIX + 'pointerout',
|
|
326
|
-
EVENT_PREFIX + 'pointerover',
|
|
327
|
-
EVENT_PREFIX + 'pointerenter',
|
|
328
|
-
EVENT_PREFIX + 'pointerleave',
|
|
329
|
-
EVENT_PREFIX + 'gotpointercapture',
|
|
330
|
-
EVENT_PREFIX + 'lostpointercapture',
|
|
331
|
-
EVENT_PREFIX + 'mozfullscreenchange',
|
|
332
|
-
EVENT_PREFIX + 'mozfullscreenerror',
|
|
333
|
-
EVENT_PREFIX + 'animationcancel',
|
|
334
|
-
EVENT_PREFIX + 'animationend',
|
|
335
|
-
EVENT_PREFIX + 'animationiteration',
|
|
336
|
-
EVENT_PREFIX + 'animationstart',
|
|
337
|
-
EVENT_PREFIX + 'transitioncancel',
|
|
338
|
-
EVENT_PREFIX + 'transitionend',
|
|
339
|
-
EVENT_PREFIX + 'transitionrun',
|
|
340
|
-
EVENT_PREFIX + 'transitionstart',
|
|
341
|
-
EVENT_PREFIX + 'webkitanimationend',
|
|
342
|
-
EVENT_PREFIX + 'webkitanimationiteration',
|
|
343
|
-
EVENT_PREFIX + 'webkitanimationstart',
|
|
344
|
-
EVENT_PREFIX + 'webkittransitionend',
|
|
345
|
-
EVENT_PREFIX + 'error',
|
|
346
|
-
];
|
|
347
|
-
|
|
348
|
-
let selector = eventAttrs.map(attr => `[${CSS.escape(attr)}]`).join(', ');
|
|
349
|
-
|
|
350
|
-
const attrToProp = attr => `on${attr[EVENT_PREFIX_LENGTH].toUpperCase()}${attr.substring(EVENT_PREFIX_LENGTH + 1)}`;
|
|
351
|
-
|
|
352
|
-
const attrEntriesMap = attr => [attrToProp(attr), attr];
|
|
353
|
-
|
|
354
|
-
const isEventDataAttr = ([name]) => name.startsWith(DATA_PREFIX);
|
|
355
|
-
|
|
356
|
-
const DATA_EVENTS = Object.fromEntries([...eventAttrs].map(attrEntriesMap));
|
|
357
|
-
|
|
358
|
-
function _addListeners(el, { signal, attrFilter = EVENTS } = {}) {
|
|
359
|
-
const dataset = el.dataset;
|
|
360
|
-
|
|
361
|
-
for (const [attr, val] of Object.entries(dataset).filter(isEventDataAttr)) {
|
|
362
|
-
try {
|
|
363
|
-
const event = 'on' + attr.substring(DATA_PREFIX_LENGTH);
|
|
364
|
-
|
|
365
|
-
if (attrFilter.hasOwnProperty(event) && hasCallback(val)) {
|
|
366
|
-
el.addEventListener(event.substring(2).toLowerCase(), getCallback(val), {
|
|
367
|
-
passive: dataset.hasOwnProperty('aegisEventPassive'),
|
|
368
|
-
capture: dataset.hasOwnProperty('aegisEventCapture'),
|
|
369
|
-
once: dataset.hasOwnProperty('aegisEventOnce'),
|
|
370
|
-
signal,
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
} catch(err) {
|
|
374
|
-
console.error(err);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const observer = new MutationObserver(records => {
|
|
380
|
-
records.forEach(record => {
|
|
381
|
-
switch(record.type) {
|
|
382
|
-
case 'childList':
|
|
383
|
-
[...record.addedNodes]
|
|
384
|
-
.filter(node => node.nodeType === Node.ELEMENT_NODE)
|
|
385
|
-
.forEach(node => attachListeners(node));
|
|
386
|
-
break;
|
|
387
|
-
|
|
388
|
-
case 'attributes':
|
|
389
|
-
if (typeof record.oldValue === 'string' && hasCallback(record.oldValue)) {
|
|
390
|
-
record.target.removeEventListener(
|
|
391
|
-
record.attributeName.substring(EVENT_PREFIX_LENGTH),
|
|
392
|
-
getCallback(record.oldValue), {
|
|
393
|
-
once: record.target.hasAttribute(once),
|
|
394
|
-
capture: record.target.hasAttribute(capture),
|
|
395
|
-
passive: record.target.hasAttribute(passive),
|
|
396
|
-
}
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (
|
|
401
|
-
record.target.hasAttribute(record.attributeName)
|
|
402
|
-
&& hasCallback(record.target.getAttribute(record.attributeName))
|
|
403
|
-
) {
|
|
404
|
-
record.target.addEventListener(
|
|
405
|
-
record.attributeName.substring(EVENT_PREFIX_LENGTH),
|
|
406
|
-
getCallback(record.target.getAttribute(record.attributeName)), {
|
|
407
|
-
once: record.target.hasAttribute(once),
|
|
408
|
-
capture: record.target.hasAttribute(capture),
|
|
409
|
-
passive: record.target.hasAttribute(passive),
|
|
410
|
-
}
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
const EVENTS = { ...DATA_EVENTS, once, passive, capture };
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Register an attribute to observe for adding/removing event listeners
|
|
422
|
-
*
|
|
423
|
-
* @param {string} attr Name of the attribute to observe
|
|
424
|
-
* @param {object} options
|
|
425
|
-
* @param {boolean} [options.addListeners=false] Whether or not to automatically add listeners
|
|
426
|
-
* @param {Document|Element} [options.base=document.body] Root node to observe
|
|
427
|
-
* @param {AbortSignal} [options.signal] An abort signal to remove any listeners when aborted
|
|
428
|
-
* @returns {string} The resulting `data-*` attribute name
|
|
429
|
-
*/
|
|
430
|
-
function registerEventAttribute(attr, {
|
|
431
|
-
addListeners = false,
|
|
432
|
-
base = document.body,
|
|
433
|
-
signal,
|
|
434
|
-
} = {}) {
|
|
435
|
-
const fullAttr = EVENT_PREFIX + attr.toLowerCase();
|
|
436
|
-
|
|
437
|
-
if (! eventAttrs.includes(fullAttr)) {
|
|
438
|
-
const sel = `[${CSS.escape(fullAttr)}]`;
|
|
439
|
-
const prop = attrToProp(fullAttr);
|
|
440
|
-
eventAttrs.push(fullAttr);
|
|
441
|
-
EVENTS[prop] = fullAttr;
|
|
442
|
-
selector += `, ${sel}`;
|
|
443
|
-
|
|
444
|
-
if (addListeners) {
|
|
445
|
-
requestAnimationFrame(() => {
|
|
446
|
-
const config = { attrFilter: { [prop]: sel }, signal };
|
|
447
|
-
[base, ...base.querySelectorAll(sel)].forEach(el => _addListeners(el, config));
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return fullAttr;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Add listeners to an element and its children, matching a generated query based on registered attributes
|
|
457
|
-
*
|
|
458
|
-
* @param {Element|Document} target Root node to add listeners from
|
|
459
|
-
* @param {object} options
|
|
460
|
-
* @param {AbortSignal} [options.signal] Optional signal to remove event listeners
|
|
461
|
-
* @returns {Element|Document} Returns the passed target node
|
|
462
|
-
*/
|
|
463
|
-
function attachListeners(target, { signal } = {}) {
|
|
464
|
-
const nodes = target instanceof Element && target.matches(selector)
|
|
465
|
-
? [target, ...target.querySelectorAll(selector)]
|
|
466
|
-
: target.querySelectorAll(selector);
|
|
467
|
-
|
|
468
|
-
nodes.forEach(el => _addListeners(el, { signal }));
|
|
469
|
-
|
|
470
|
-
return target;
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Add a node to the `MutationObserver` to observe attributes and add/remove event listeners
|
|
474
|
-
*
|
|
475
|
-
* @param {Document|Element} root Element to observe attributes on
|
|
476
|
-
*/
|
|
477
|
-
function observeEvents(root = document) {
|
|
478
|
-
attachListeners(root);
|
|
479
|
-
observer.observe(root, {
|
|
480
|
-
subtree: true,
|
|
481
|
-
childList:true,
|
|
482
|
-
attributes: true,
|
|
483
|
-
attributeOldValue: true,
|
|
484
|
-
attributeFilter: eventAttrs,
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Disconnects the `MutationObserver`, disabling observing of all attribute changes
|
|
490
|
-
*
|
|
491
|
-
* @returns {void}
|
|
492
|
-
*/
|
|
493
|
-
const disconnectEventsObserver = () => observer.disconnect();
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Register a global error handler callback
|
|
497
|
-
*
|
|
498
|
-
* @param {Function} callback Callback to register as a global error handler
|
|
499
|
-
* @param {EventInit} config Typical event listener config object
|
|
500
|
-
*/
|
|
501
|
-
function setGlobalErrorHandler(callback, { capture, once, passive, signal } = {}) {
|
|
502
|
-
if (callback instanceof Function) {
|
|
503
|
-
globalThis.addEventListener('error', callback, { capture, once, passive, signal });
|
|
504
|
-
} else {
|
|
505
|
-
throw new TypeError('Callback is not a function.');
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
export { EVENTS, FUNCS, attachListeners, callCallback, clearRegistry, closeRegistration, createCallback, disconnectEventsObserver, getCallback, getHost, hasCallback, isRegistrationOpen, listCallbacks, observeEvents, registerCallback, registerEventAttribute, setGlobalErrorHandler, unregisterCallback };
|
|
1
|
+
let e=!0;const t=(e,t=document)=>t.querySelectorAll(e),a=(e,t=document)=>t.querySelector(e),r={debug:{log:"aegis:debug:log",info:"aegis:debug:info",warn:"aegis:debug:warn",error:"aegis:debug:error"},navigate:{back:"aegis:navigate:back",forward:"aegis:navigate:forward",reload:"aegis:navigate:reload",link:"aegis:navigate:go",popup:"aegis:navigate:popup"},ui:{print:"aegis:ui:print",remove:"aegis:ui:remove",hide:"aegis:ui:hide",unhide:"aegis:ui:unhide",showModal:"aegis:ui:showModal",closeModal:"aegis:ui:closeModal",showPopover:"aegis:ui:showPopover",hidePopover:"aegis:ui:hidePopover",togglePopover:"aegis:ui:togglePopover",enable:"aegis:ui:enable",disable:"aegis:ui:disable",scrollTo:"aegis:ui:scrollTo",prevent:"aegis:ui:prevent"}},o=new Map([[r.debug.log,console.log],[r.debug.warn,console.warn],[r.debug.error,console.error],[r.debug.info,console.info],[r.navigate.back,()=>history.back()],[r.navigate.forward,()=>history.forward()],[r.navigate.reload,()=>history.go(0)],[r.navigate.link,e=>{e.isTrusted&&(e.preventDefault(),location.href=e.currentTarget.dataset.url)}],[r.navigate.popup,e=>{e.isTrusted&&(e.preventDefault(),globalThis.open(e.currentTarget.dataset.url))}],[r.ui.hide,({currentTarget:e})=>{t(e.dataset.hideSelector).forEach((e=>e.hidden=!0))}],[r.ui.unhide,({currentTarget:e})=>{t(e.dataset.unhideSelector).forEach((e=>e.hidden=!1))}],[r.ui.disable,({currentTarget:e})=>{t(e.dataset.disableSelector).forEach((e=>e.disabled=!0))}],[r.ui.enable,({currentTarget:e})=>{t(e.dataset.enableSelector).forEach((e=>e.disabled=!1))}],[r.ui.remove,({currentTarget:e})=>{t(e.dataset.removeSelector).forEach((e=>e.remove()))}],[r.ui.scrollTo,({currentTarget:e})=>{const t=a(e.dataset.scrollToSelector);t instanceof Element&&t.scrollIntoView({behavior:matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":"smooth"})}],[r.ui.showModal,({currentTarget:e})=>{const t=a(e.dataset.showModalSelector);t instanceof HTMLDialogElement&&t.showModal()}],[r.ui.closeModal,({currentTarget:e})=>{const t=a(e.dataset.closeModalSelector);t instanceof HTMLDialogElement&&t.close()}],[r.ui.showPopover,({currentTarget:e})=>{const t=a(e.dataset.showPopoverSelector);t instanceof HTMLElement&&t.showPopover()}],[r.ui.hidePopover,({currentTarget:e})=>{const t=a(e.dataset.hidePopoverSelector);t instanceof HTMLElement&&t.hidePopover()}],[r.ui.togglePopover,({currentTarget:e})=>{const t=a(e.dataset.togglePopoverSelector);t instanceof HTMLElement&&t.togglePopover()}],[r.ui.print,()=>globalThis.print()],[r.ui.prevent,e=>e.preventDefault()]]),n=()=>e,i=()=>e=!1,s=()=>Object.freeze(Array.from(o.keys())),c=e=>o.has(e),l=e=>o.get(e),u=t=>e&&o.delete(t),g=()=>o.clear(),d=e=>h("aegis:callback:"+crypto.randomUUID(),e);function p(e,...t){if(o.has(e))return o.get(e).apply(this||globalThis,t);throw new Error(`No ${e} function registered.`)}function h(t,a){if("string"!=typeof t||0===t.length)throw new TypeError("Callback name must be a string.");if(a instanceof Function){if(e){if(o.has(t))throw new Error(`Handler "${t}" is already registered.`);return o.set(t,a),t}throw new TypeError("Cannot register new callbacks because registry is closed.")}throw new TypeError("Callback must be a function.")}function b(e){return e instanceof Event?b(e.currentTarget):e instanceof Document?e:e instanceof Element?b(e.getRootNode()):e instanceof ShadowRoot?e.host:null}const v="data-aegis-event-on-",f="aegisEventOn",m="data-aegis-event-once",w="data-aegis-event-passive",y="data-aegis-event-capture",E=[v+"abort",v+"blur",v+"focus",v+"cancel",v+"auxclick",v+"beforeinput",v+"beforetoggle",v+"canplay",v+"canplaythrough",v+"change",v+"click",v+"close",v+"contextmenu",v+"copy",v+"cuechange",v+"cut",v+"dblclick",v+"drag",v+"dragend",v+"dragenter",v+"dragexit",v+"dragleave",v+"dragover",v+"dragstart",v+"drop",v+"durationchange",v+"emptied",v+"ended",v+"formdata",v+"input",v+"invalid",v+"keydown",v+"keypress",v+"keyup",v+"load",v+"loadeddata",v+"loadedmetadata",v+"loadstart",v+"mousedown",v+"mouseenter",v+"mouseleave",v+"mousemove",v+"mouseout",v+"mouseover",v+"mouseup",v+"wheel",v+"paste",v+"pause",v+"play",v+"playing",v+"progress",v+"ratechange",v+"reset",v+"resize",v+"scroll",v+"scrollend",v+"securitypolicyviolation",v+"seeked",v+"seeking",v+"select",v+"slotchange",v+"stalled",v+"submit",v+"suspend",v+"timeupdate",v+"volumechange",v+"waiting",v+"selectstart",v+"selectionchange",v+"toggle",v+"pointercancel",v+"pointerdown",v+"pointerup",v+"pointermove",v+"pointerout",v+"pointerover",v+"pointerenter",v+"pointerleave",v+"gotpointercapture",v+"lostpointercapture",v+"mozfullscreenchange",v+"mozfullscreenerror",v+"animationcancel",v+"animationend",v+"animationiteration",v+"animationstart",v+"transitioncancel",v+"transitionend",v+"transitionrun",v+"transitionstart",v+"webkitanimationend",v+"webkitanimationiteration",v+"webkitanimationstart",v+"webkittransitionend",v+"error"];let T=E.map((e=>`[${CSS.escape(e)}]`)).join(", ");const k=e=>`on${e[20].toUpperCase()}${e.substring(21)}`,S=([e])=>e.startsWith(f),P=Object.fromEntries([...E].map((e=>[k(e),e])));function M(e,{signal:t,attrFilter:a=L}={}){const r=e.dataset;for(const[o,n]of Object.entries(r).filter(S))try{const i="on"+o.substring(12);a.hasOwnProperty(i)&&c(n)&&e.addEventListener(i.substring(2).toLowerCase(),l(n),{passive:r.hasOwnProperty("aegisEventPassive"),capture:r.hasOwnProperty("aegisEventCapture"),once:r.hasOwnProperty("aegisEventOnce"),signal:t})}catch(e){console.error(e)}}const A=new MutationObserver((e=>{e.forEach((e=>{switch(e.type){case"childList":[...e.addedNodes].filter((e=>e.nodeType===Node.ELEMENT_NODE)).forEach((e=>N(e)));break;case"attributes":"string"==typeof e.oldValue&&c(e.oldValue)&&e.target.removeEventListener(e.attributeName.substring(20),l(e.oldValue),{once:e.target.hasAttribute(m),capture:e.target.hasAttribute(y),passive:e.target.hasAttribute(w)}),e.target.hasAttribute(e.attributeName)&&c(e.target.getAttribute(e.attributeName))&&e.target.addEventListener(e.attributeName.substring(20),l(e.target.getAttribute(e.attributeName)),{once:e.target.hasAttribute(m),capture:e.target.hasAttribute(y),passive:e.target.hasAttribute(w)})}}))})),L={...P,once:m,passive:w,capture:y};function O(e,{addListeners:t=!1,base:a=document.body,signal:r}={}){const o=v+e.toLowerCase();if(!E.includes(o)){const e=`[${CSS.escape(o)}]`,n=k(o);E.push(o),L[n]=o,T+=`, ${e}`,t&&requestAnimationFrame((()=>{const t={attrFilter:{[n]:e},signal:r};[a,...a.querySelectorAll(e)].forEach((e=>M(e,t)))}))}return o}function N(e,{signal:t}={}){return(e instanceof Element&&e.matches(T)?[e,...e.querySelectorAll(T)]:e.querySelectorAll(T)).forEach((e=>M(e,{signal:t}))),e}function C(e=document){N(e),A.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:E})}const D=()=>A.disconnect();function $(e,{capture:t,once:a,passive:r,signal:o}={}){if(!(e instanceof Function))throw new TypeError("Callback is not a function.");globalThis.addEventListener("error",e,{capture:t,once:a,passive:r,signal:o})}export{L as EVENTS,r as FUNCS,N as attachListeners,p as callCallback,g as clearRegistry,i as closeRegistration,d as createCallback,D as disconnectEventsObserver,l as getCallback,b as getHost,c as hasCallback,n as isRegistrationOpen,s as listCallbacks,C as observeEvents,h as registerCallback,O as registerEventAttribute,$ as setGlobalErrorHandler,u as unregisterCallback};
|
|
2
|
+
//# sourceMappingURL=callbackRegistry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callbackRegistry.mjs","sources":["callbacks.js","events.js"],"sourcesContent":["let _isRegistrationOpen = true;\n\nconst $$ = (selector, base = document) => base.querySelectorAll(selector);\n\nconst $ = (selector, base = document) => base.querySelector(selector);\n\nexport const FUNCS = {\n\tdebug: {\n\t\tlog: 'aegis:debug:log',\n\t\tinfo: 'aegis:debug:info',\n\t\twarn: 'aegis:debug:warn',\n\t\terror: 'aegis:debug:error',\n\t},\n\tnavigate: {\n\t\tback: 'aegis:navigate:back',\n\t\tforward: 'aegis:navigate:forward',\n\t\treload: 'aegis:navigate:reload',\n\t\tlink: 'aegis:navigate:go',\n\t\tpopup: 'aegis:navigate:popup',\n\t},\n\tui: {\n\t\tprint: 'aegis:ui:print',\n\t\tremove: 'aegis:ui:remove',\n\t\thide: 'aegis:ui:hide',\n\t\tunhide: 'aegis:ui:unhide',\n\t\tshowModal: 'aegis:ui:showModal',\n\t\tcloseModal: 'aegis:ui:closeModal',\n\t\tshowPopover: 'aegis:ui:showPopover',\n\t\thidePopover: 'aegis:ui:hidePopover',\n\t\ttogglePopover: 'aegis:ui:togglePopover',\n\t\tenable: 'aegis:ui:enable',\n\t\tdisable: 'aegis:ui:disable',\n\t\tscrollTo: 'aegis:ui:scrollTo',\n\t\tprevent: 'aegis:ui:prevent',\n\t},\n};\n\nconst registry = new Map([\n\t[FUNCS.debug.log, console.log],\n\t[FUNCS.debug.warn, console.warn],\n\t[FUNCS.debug.error, console.error],\n\t[FUNCS.debug.info, console.info],\n\t[FUNCS.navigate.back, () => history.back()],\n\t[FUNCS.navigate.forward, () => history.forward()],\n\t[FUNCS.navigate.reload, () => history.go(0)],\n\t[FUNCS.navigate.link, event => {\n\t\tif (event.isTrusted) {\n\t\t\tevent.preventDefault();\n\t\t\tlocation.href = event.currentTarget.dataset.url;\n\t\t}\n\t}],\n\t[FUNCS.navigate.popup, event => {\n\t\tif (event.isTrusted) {\n\t\t\tevent.preventDefault();\n\t\t\tglobalThis.open(event.currentTarget.dataset.url);\n\t\t}\n\t}],\n\t[FUNCS.ui.hide, ({ currentTarget }) => {\n\t\t$$(currentTarget.dataset.hideSelector).forEach(el => el.hidden = true);\n\t}],\n\t[FUNCS.ui.unhide, ({ currentTarget }) => {\n\t\t$$(currentTarget.dataset.unhideSelector).forEach(el => el.hidden = false);\n\t}],\n\t[FUNCS.ui.disable, ({ currentTarget }) => {\n\t\t$$(currentTarget.dataset.disableSelector).forEach(el => el.disabled = true);\n\t}],\n\t[FUNCS.ui.enable, ({ currentTarget }) => {\n\t\t$$(currentTarget.dataset.enableSelector).forEach(el => el.disabled = false);\n\t}],\n\t[FUNCS.ui.remove, ({ currentTarget }) => {\n\t\t$$(currentTarget.dataset.removeSelector).forEach(el => el.remove());\n\t}],\n\t[FUNCS.ui.scrollTo, ({ currentTarget }) => {\n\t\tconst target = $(currentTarget.dataset.scrollToSelector);\n\n\t\tif (target instanceof Element) {\n\t\t\ttarget.scrollIntoView({\n\t\t\t\tbehavior: matchMedia('(prefers-reduced-motion: reduce)').matches\n\t\t\t\t\t? 'instant'\n\t\t\t\t\t: 'smooth',\n\t\t\t});\n\t\t}\n\t}],\n\t[FUNCS.ui.showModal, ({ currentTarget }) => {\n\t\tconst target = $(currentTarget.dataset.showModalSelector);\n\n\t\tif (target instanceof HTMLDialogElement) {\n\t\t\ttarget.showModal();\n\t\t}\n\t}],\n\t[FUNCS.ui.closeModal, ({ currentTarget }) => {\n\t\tconst target = $(currentTarget.dataset.closeModalSelector);\n\n\t\tif (target instanceof HTMLDialogElement) {\n\t\t\ttarget.close();\n\t\t}\n\t}],\n\t[FUNCS.ui.showPopover, ({ currentTarget }) => {\n\t\tconst target = $(currentTarget.dataset.showPopoverSelector);\n\n\t\tif (target instanceof HTMLElement) {\n\t\t\ttarget.showPopover();\n\t\t}\n\t}],\n\t[FUNCS.ui.hidePopover, ({ currentTarget }) => {\n\t\tconst target = $(currentTarget.dataset.hidePopoverSelector);\n\n\t\tif (target instanceof HTMLElement) {\n\t\t\ttarget.hidePopover();\n\t\t}\n\t}],\n\t[FUNCS.ui.togglePopover, ({ currentTarget }) => {\n\t\tconst target = $(currentTarget.dataset.togglePopoverSelector);\n\n\t\tif (target instanceof HTMLElement) {\n\t\t\ttarget.togglePopover();\n\t\t}\n\t}],\n\t[FUNCS.ui.print, () => globalThis.print()],\n\t[FUNCS.ui.prevent, event => event.preventDefault()],\n]);\n\n/**\n * Check if callback registry is open\n *\n * @returns {boolean} Whether or not callback registry is open\n */\nexport const isRegistrationOpen = () => _isRegistrationOpen;\n\n/**\n * Close callback registry\n *\n * @returns {boolean} Whether or not the callback was succesfully removed\n */\nexport const closeRegistration = () => _isRegistrationOpen = false;\n\n/**\n * Get an array of registered callbacks\n *\n * @returns {Array} A frozen array listing keys to all registered callbacks\n */\nexport const listCallbacks = () => Object.freeze(Array.from(registry.keys()));\n\n/**\n * Check if a callback is registered\n *\n * @param {string} name The name/key to check for in callback registry\n * @returns {boolean} Whether or not a callback is registered\n */\nexport const hasCallback = name => registry.has(name);\n\n/**\n * Get a callback from the registry by name/key\n *\n * @param {string} name The name/key of the callback to get\n * @returns {Function|undefined} The corresponding function registered under that name/key\n */\nexport const getCallback = name => registry.get(name);\n\n/**\n *\t Remove a callback from the registry\n *\n * @param {string} name The name/key of the callback to get\n * @returns {boolean} Whether or not the callback was successfully unregisterd\n */\nexport const unregisterCallback = name => _isRegistrationOpen && registry.delete(name);\n\n/**\n * Remove all callbacks from the registry\n *\n * @returns {void}\n */\nexport const clearRegistry = () => registry.clear();\n\n/**\n * Create a registered callback with a randomly generated name\n *\n * @param {Function} callback Callback function to register\n * @returns {string} The automatically generated key/name of the registered callback\n */\nexport const createCallback = (callback) => registerCallback('aegis:callback:' + crypto.randomUUID(), callback);\n\n/**\n * Call a callback fromt the registry by name/key\n *\n * @param {string} name The name/key of the registered function\n * @param {...any} args Any arguments to pass along to the function\n * @returns {any} Whatever the return value of the function is\n * @throws {Error} Throws if callback is not found or any error resulting from calling the function\n */\nexport function callCallback(name, ...args) {\n\tif (registry.has(name)) {\n\t\treturn registry.get(name).apply(this || globalThis, args);\n\t} else {\n\t\tthrow new Error(`No ${name} function registered.`);\n\t}\n}\n\n/**\n * Register a named callback in registry\n *\n * @param {string} name The name/key to register the callback under\n * @param {Function} callback The callback value to register\n * @returns {string} The registered name/key\n */\nexport function registerCallback(name, callback) {\n\tif (typeof name !== 'string' || name.length === 0) {\n\t\tthrow new TypeError('Callback name must be a string.');\n\t} if (! (callback instanceof Function)) {\n\t\tthrow new TypeError('Callback must be a function.');\n\t} else if (! _isRegistrationOpen) {\n\t\tthrow new TypeError('Cannot register new callbacks because registry is closed.');\n\t} else if (registry.has(name)) {\n\t\tthrow new Error(`Handler \"${name}\" is already registered.`);\n\t} else {\n\t\tregistry.set(name, callback);\n\t\treturn name;\n\t}\n}\n\n/**\n * Get the host/root node of a given thing.\n *\n * @param {Event|Document|Element|ShadowRoot} target Source thing to search for host of\n * @returns {Document|Element|null} The host/root node, or null\n */\nexport function getHost(target) {\n\tif (target instanceof Event) {\n\t\treturn getHost(target.currentTarget);\n\t} else if (target instanceof Document) {\n\t\treturn target;\n\t} else if (target instanceof Element) {\n\t\treturn getHost(target.getRootNode());\n\t} else if (target instanceof ShadowRoot) {\n\t\treturn target.host;\n\t} else {\n\t\treturn null;\n\t}\n}\n","import { hasCallback, getCallback } from './callbacks.js';\n\nconst EVENT_PREFIX = 'data-aegis-event-on-';\nconst EVENT_PREFIX_LENGTH = EVENT_PREFIX.length;\nconst DATA_PREFIX = 'aegisEventOn';\nconst DATA_PREFIX_LENGTH = DATA_PREFIX.length;\n\nconst once = 'data-aegis-event-once',\n\tpassive = 'data-aegis-event-passive',\n\tcapture = 'data-aegis-event-capture';\n\nconst eventAttrs = [\n\tEVENT_PREFIX + 'abort',\n\tEVENT_PREFIX + 'blur',\n\tEVENT_PREFIX + 'focus',\n\tEVENT_PREFIX + 'cancel',\n\tEVENT_PREFIX + 'auxclick',\n\tEVENT_PREFIX + 'beforeinput',\n\tEVENT_PREFIX + 'beforetoggle',\n\tEVENT_PREFIX + 'canplay',\n\tEVENT_PREFIX + 'canplaythrough',\n\tEVENT_PREFIX + 'change',\n\tEVENT_PREFIX + 'click',\n\tEVENT_PREFIX + 'close',\n\tEVENT_PREFIX + 'contextmenu',\n\tEVENT_PREFIX + 'copy',\n\tEVENT_PREFIX + 'cuechange',\n\tEVENT_PREFIX + 'cut',\n\tEVENT_PREFIX + 'dblclick',\n\tEVENT_PREFIX + 'drag',\n\tEVENT_PREFIX + 'dragend',\n\tEVENT_PREFIX + 'dragenter',\n\tEVENT_PREFIX + 'dragexit',\n\tEVENT_PREFIX + 'dragleave',\n\tEVENT_PREFIX + 'dragover',\n\tEVENT_PREFIX + 'dragstart',\n\tEVENT_PREFIX + 'drop',\n\tEVENT_PREFIX + 'durationchange',\n\tEVENT_PREFIX + 'emptied',\n\tEVENT_PREFIX + 'ended',\n\tEVENT_PREFIX + 'formdata',\n\tEVENT_PREFIX + 'input',\n\tEVENT_PREFIX + 'invalid',\n\tEVENT_PREFIX + 'keydown',\n\tEVENT_PREFIX + 'keypress',\n\tEVENT_PREFIX + 'keyup',\n\tEVENT_PREFIX + 'load',\n\tEVENT_PREFIX + 'loadeddata',\n\tEVENT_PREFIX + 'loadedmetadata',\n\tEVENT_PREFIX + 'loadstart',\n\tEVENT_PREFIX + 'mousedown',\n\tEVENT_PREFIX + 'mouseenter',\n\tEVENT_PREFIX + 'mouseleave',\n\tEVENT_PREFIX + 'mousemove',\n\tEVENT_PREFIX + 'mouseout',\n\tEVENT_PREFIX + 'mouseover',\n\tEVENT_PREFIX + 'mouseup',\n\tEVENT_PREFIX + 'wheel',\n\tEVENT_PREFIX + 'paste',\n\tEVENT_PREFIX + 'pause',\n\tEVENT_PREFIX + 'play',\n\tEVENT_PREFIX + 'playing',\n\tEVENT_PREFIX + 'progress',\n\tEVENT_PREFIX + 'ratechange',\n\tEVENT_PREFIX + 'reset',\n\tEVENT_PREFIX + 'resize',\n\tEVENT_PREFIX + 'scroll',\n\tEVENT_PREFIX + 'scrollend',\n\tEVENT_PREFIX + 'securitypolicyviolation',\n\tEVENT_PREFIX + 'seeked',\n\tEVENT_PREFIX + 'seeking',\n\tEVENT_PREFIX + 'select',\n\tEVENT_PREFIX + 'slotchange',\n\tEVENT_PREFIX + 'stalled',\n\tEVENT_PREFIX + 'submit',\n\tEVENT_PREFIX + 'suspend',\n\tEVENT_PREFIX + 'timeupdate',\n\tEVENT_PREFIX + 'volumechange',\n\tEVENT_PREFIX + 'waiting',\n\tEVENT_PREFIX + 'selectstart',\n\tEVENT_PREFIX + 'selectionchange',\n\tEVENT_PREFIX + 'toggle',\n\tEVENT_PREFIX + 'pointercancel',\n\tEVENT_PREFIX + 'pointerdown',\n\tEVENT_PREFIX + 'pointerup',\n\tEVENT_PREFIX + 'pointermove',\n\tEVENT_PREFIX + 'pointerout',\n\tEVENT_PREFIX + 'pointerover',\n\tEVENT_PREFIX + 'pointerenter',\n\tEVENT_PREFIX + 'pointerleave',\n\tEVENT_PREFIX + 'gotpointercapture',\n\tEVENT_PREFIX + 'lostpointercapture',\n\tEVENT_PREFIX + 'mozfullscreenchange',\n\tEVENT_PREFIX + 'mozfullscreenerror',\n\tEVENT_PREFIX + 'animationcancel',\n\tEVENT_PREFIX + 'animationend',\n\tEVENT_PREFIX + 'animationiteration',\n\tEVENT_PREFIX + 'animationstart',\n\tEVENT_PREFIX + 'transitioncancel',\n\tEVENT_PREFIX + 'transitionend',\n\tEVENT_PREFIX + 'transitionrun',\n\tEVENT_PREFIX + 'transitionstart',\n\tEVENT_PREFIX + 'webkitanimationend',\n\tEVENT_PREFIX + 'webkitanimationiteration',\n\tEVENT_PREFIX + 'webkitanimationstart',\n\tEVENT_PREFIX + 'webkittransitionend',\n\tEVENT_PREFIX + 'error',\n];\n\nlet selector = eventAttrs.map(attr => `[${CSS.escape(attr)}]`).join(', ');\n\nconst attrToProp = attr => `on${attr[EVENT_PREFIX_LENGTH].toUpperCase()}${attr.substring(EVENT_PREFIX_LENGTH + 1)}`;\n\nconst attrEntriesMap = attr => [attrToProp(attr), attr];\n\nconst isEventDataAttr = ([name]) => name.startsWith(DATA_PREFIX);\n\nconst DATA_EVENTS = Object.fromEntries([...eventAttrs].map(attrEntriesMap));\n\nfunction _addListeners(el, { signal, attrFilter = EVENTS } = {}) {\n\tconst dataset = el.dataset;\n\n\tfor (const [attr, val] of Object.entries(dataset).filter(isEventDataAttr)) {\n\t\ttry {\n\t\t\tconst event = 'on' + attr.substring(DATA_PREFIX_LENGTH);\n\n\t\t\tif (attrFilter.hasOwnProperty(event) && hasCallback(val)) {\n\t\t\t\tel.addEventListener(event.substring(2).toLowerCase(), getCallback(val), {\n\t\t\t\t\tpassive: dataset.hasOwnProperty('aegisEventPassive'),\n\t\t\t\t\tcapture: dataset.hasOwnProperty('aegisEventCapture'),\n\t\t\t\t\tonce: dataset.hasOwnProperty('aegisEventOnce'),\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch(err) {\n\t\t\tconsole.error(err);\n\t\t}\n\t}\n}\n\nconst observer = new MutationObserver(records => {\n\trecords.forEach(record => {\n\t\tswitch(record.type) {\n\t\t\tcase 'childList':\n\t\t\t\t[...record.addedNodes]\n\t\t\t\t\t.filter(node => node.nodeType === Node.ELEMENT_NODE)\n\t\t\t\t\t.forEach(node => attachListeners(node));\n\t\t\t\tbreak;\n\n\t\t\tcase 'attributes':\n\t\t\t\tif (typeof record.oldValue === 'string' && hasCallback(record.oldValue)) {\n\t\t\t\t\trecord.target.removeEventListener(\n\t\t\t\t\t\trecord.attributeName.substring(EVENT_PREFIX_LENGTH),\n\t\t\t\t\t\tgetCallback(record.oldValue), {\n\t\t\t\t\t\t\tonce: record.target.hasAttribute(once),\n\t\t\t\t\t\t\tcapture: record.target.hasAttribute(capture),\n\t\t\t\t\t\t\tpassive: record.target.hasAttribute(passive),\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\trecord.target.hasAttribute(record.attributeName)\n\t\t\t\t\t&& hasCallback(record.target.getAttribute(record.attributeName))\n\t\t\t\t) {\n\t\t\t\t\trecord.target.addEventListener(\n\t\t\t\t\t\trecord.attributeName.substring(EVENT_PREFIX_LENGTH),\n\t\t\t\t\t\tgetCallback(record.target.getAttribute(record.attributeName)), {\n\t\t\t\t\t\t\tonce: record.target.hasAttribute(once),\n\t\t\t\t\t\t\tcapture: record.target.hasAttribute(capture),\n\t\t\t\t\t\t\tpassive: record.target.hasAttribute(passive),\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t});\n});\n\nexport const EVENTS = { ...DATA_EVENTS, once, passive, capture };\n\n/**\n * Register an attribute to observe for adding/removing event listeners\n *\n * @param {string} attr Name of the attribute to observe\n * @param {object} options\n * @param {boolean} [options.addListeners=false] Whether or not to automatically add listeners\n * @param {Document|Element} [options.base=document.body] Root node to observe\n * @param {AbortSignal} [options.signal] An abort signal to remove any listeners when aborted\n * @returns {string} The resulting `data-*` attribute name\n */\nexport function registerEventAttribute(attr, {\n\taddListeners = false,\n\tbase = document.body,\n\tsignal,\n} = {}) {\n\tconst fullAttr = EVENT_PREFIX + attr.toLowerCase();\n\n\tif (! eventAttrs.includes(fullAttr)) {\n\t\tconst sel = `[${CSS.escape(fullAttr)}]`;\n\t\tconst prop = attrToProp(fullAttr);\n\t\teventAttrs.push(fullAttr);\n\t\tEVENTS[prop] = fullAttr;\n\t\tselector += `, ${sel}`;\n\n\t\tif (addListeners) {\n\t\t\trequestAnimationFrame(() => {\n\t\t\t\tconst config = { attrFilter: { [prop]: sel }, signal };\n\t\t\t\t[base, ...base.querySelectorAll(sel)].forEach(el => _addListeners(el, config));\n\t\t\t});\n\t\t}\n\t}\n\n\treturn fullAttr;\n}\n\n/**\n * Add listeners to an element and its children, matching a generated query based on registered attributes\n *\n * @param {Element|Document} target Root node to add listeners from\n * @param {object} options\n * @param {AbortSignal} [options.signal] Optional signal to remove event listeners\n * @returns {Element|Document} Returns the passed target node\n */\nexport function attachListeners(target, { signal } = {}) {\n\tconst nodes = target instanceof Element && target.matches(selector)\n\t\t? [target, ...target.querySelectorAll(selector)]\n\t\t: target.querySelectorAll(selector);\n\n\tnodes.forEach(el => _addListeners(el, { signal }));\n\n\treturn target;\n}\n/**\n * Add a node to the `MutationObserver` to observe attributes and add/remove event listeners\n *\n * @param {Document|Element} root Element to observe attributes on\n */\nexport function observeEvents(root = document) {\n\tattachListeners(root);\n\tobserver.observe(root, {\n\t\tsubtree: true,\n\t\tchildList:true,\n\t\tattributes: true,\n\t\tattributeOldValue: true,\n\t\tattributeFilter: eventAttrs,\n\t});\n}\n\n/**\n * Disconnects the `MutationObserver`, disabling observing of all attribute changes\n *\n * @returns {void}\n */\nexport const disconnectEventsObserver = () => observer.disconnect();\n\n/**\n * Register a global error handler callback\n *\n * @param {Function} callback Callback to register as a global error handler\n * @param {EventInit} config Typical event listener config object\n */\nexport function setGlobalErrorHandler(callback, { capture, once, passive, signal } = {}) {\n\tif (callback instanceof Function) {\n\t\tglobalThis.addEventListener('error', callback, { capture, once, passive, signal });\n\t} else {\n\t\tthrow new TypeError('Callback is not a function.');\n\t}\n}\n"],"names":["_isRegistrationOpen","$$","selector","base","document","querySelectorAll","$","querySelector","FUNCS","debug","log","info","warn","error","navigate","back","forward","reload","link","popup","ui","print","remove","hide","unhide","showModal","closeModal","showPopover","hidePopover","togglePopover","enable","disable","scrollTo","prevent","registry","Map","console","history","go","event","isTrusted","preventDefault","location","href","currentTarget","dataset","url","globalThis","open","hideSelector","forEach","el","hidden","unhideSelector","disableSelector","disabled","enableSelector","removeSelector","target","scrollToSelector","Element","scrollIntoView","behavior","matchMedia","matches","showModalSelector","HTMLDialogElement","closeModalSelector","close","showPopoverSelector","HTMLElement","hidePopoverSelector","togglePopoverSelector","isRegistrationOpen","closeRegistration","listCallbacks","Object","freeze","Array","from","keys","hasCallback","name","has","getCallback","get","unregisterCallback","delete","clearRegistry","clear","createCallback","callback","registerCallback","crypto","randomUUID","callCallback","args","apply","this","Error","length","TypeError","Function","set","getHost","Event","Document","getRootNode","ShadowRoot","host","EVENT_PREFIX","DATA_PREFIX","once","passive","capture","eventAttrs","map","attr","CSS","escape","join","attrToProp","toUpperCase","substring","EVENT_PREFIX_LENGTH","isEventDataAttr","startsWith","DATA_EVENTS","fromEntries","_addListeners","signal","attrFilter","EVENTS","val","entries","filter","hasOwnProperty","addEventListener","toLowerCase","err","observer","MutationObserver","records","record","type","addedNodes","node","nodeType","Node","ELEMENT_NODE","attachListeners","oldValue","removeEventListener","attributeName","hasAttribute","getAttribute","registerEventAttribute","addListeners","body","fullAttr","includes","sel","prop","push","requestAnimationFrame","config","observeEvents","root","observe","subtree","childList","attributes","attributeOldValue","attributeFilter","disconnectEventsObserver","disconnect","setGlobalErrorHandler"],"mappings":"AAAA,IAAIA,GAAsB,EAE1B,MAAMC,EAAK,CAACC,EAAUC,EAAOC,WAAaD,EAAKE,iBAAiBH,GAE1DI,EAAI,CAACJ,EAAUC,EAAOC,WAAaD,EAAKI,cAAcL,GAE/CM,EAAQ,CACpBC,MAAO,CACNC,IAAK,kBACLC,KAAM,mBACNC,KAAM,mBACNC,MAAO,qBAERC,SAAU,CACTC,KAAM,sBACNC,QAAS,yBACTC,OAAQ,wBACRC,KAAM,oBACNC,MAAO,wBAERC,GAAI,CACHC,MAAO,iBACPC,OAAQ,kBACRC,KAAM,gBACNC,OAAQ,kBACRC,UAAW,qBACXC,WAAY,sBACZC,YAAa,uBACbC,YAAa,uBACbC,cAAe,yBACfC,OAAQ,kBACRC,QAAS,mBACTC,SAAU,oBACVC,QAAS,qBAILC,EAAW,IAAIC,IAAI,CACxB,CAAC3B,EAAMC,MAAMC,IAAK0B,QAAQ1B,KAC1B,CAACF,EAAMC,MAAMG,KAAMwB,QAAQxB,MAC3B,CAACJ,EAAMC,MAAMI,MAAOuB,QAAQvB,OAC5B,CAACL,EAAMC,MAAME,KAAMyB,QAAQzB,MAC3B,CAACH,EAAMM,SAASC,KAAM,IAAMsB,QAAQtB,QACpC,CAACP,EAAMM,SAASE,QAAS,IAAMqB,QAAQrB,WACvC,CAACR,EAAMM,SAASG,OAAQ,IAAMoB,QAAQC,GAAG,IACzC,CAAC9B,EAAMM,SAASI,KAAMqB,IACjBA,EAAMC,YACTD,EAAME,iBACNC,SAASC,KAAOJ,EAAMK,cAAcC,QAAQC,IAC/C,GAEC,CAACtC,EAAMM,SAASK,MAAOoB,IAClBA,EAAMC,YACTD,EAAME,iBACNM,WAAWC,KAAKT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C,EAAOnK,UACpCkJ,EAAgBiB,GAChB3B,EAAS4B,QAAQD,EAAM,CACtBE,SAAS,EACTC,WAAU,EACVC,YAAY,EACZC,mBAAmB,EACnBC,gBAAiB1D,GAEnB,CAOY,MAAC2D,EAA2B,IAAMlC,EAASmC,aAQhD,SAASC,EAAsBrF,GAAUuB,QAAEA,EAAOF,KAAEA,EAAIC,QAAEA,EAAOiB,OAAEA,GAAW,IACpF,KAAIvC,aAAoBW,UAGvB,MAAM,IAAID,UAAU,+BAFpBtD,WAAW0F,iBAAiB,QAAS9C,EAAU,CAAEuB,UAASF,OAAMC,UAASiB,UAI3E"}
|
package/callbacks.cjs
CHANGED
|
@@ -42,8 +42,8 @@ const registry = new Map([
|
|
|
42
42
|
[FUNCS.debug.warn, console.warn],
|
|
43
43
|
[FUNCS.debug.error, console.error],
|
|
44
44
|
[FUNCS.debug.info, console.info],
|
|
45
|
-
[FUNCS.navigate.back, history.back],
|
|
46
|
-
[FUNCS.navigate.forward, history.forward],
|
|
45
|
+
[FUNCS.navigate.back, () => history.back()],
|
|
46
|
+
[FUNCS.navigate.forward, () => history.forward()],
|
|
47
47
|
[FUNCS.navigate.reload, () => history.go(0)],
|
|
48
48
|
[FUNCS.navigate.link, event => {
|
|
49
49
|
if (event.isTrusted) {
|
|
@@ -170,7 +170,7 @@ const unregisterCallback = name => _isRegistrationOpen && registry.delete(name);
|
|
|
170
170
|
/**
|
|
171
171
|
* Remove all callbacks from the registry
|
|
172
172
|
*
|
|
173
|
-
* @returns {
|
|
173
|
+
* @returns {void}
|
|
174
174
|
*/
|
|
175
175
|
const clearRegistry = () => registry.clear();
|
|
176
176
|
|
package/callbacks.js
CHANGED
|
@@ -40,8 +40,8 @@ const registry = new Map([
|
|
|
40
40
|
[FUNCS.debug.warn, console.warn],
|
|
41
41
|
[FUNCS.debug.error, console.error],
|
|
42
42
|
[FUNCS.debug.info, console.info],
|
|
43
|
-
[FUNCS.navigate.back, history.back],
|
|
44
|
-
[FUNCS.navigate.forward, history.forward],
|
|
43
|
+
[FUNCS.navigate.back, () => history.back()],
|
|
44
|
+
[FUNCS.navigate.forward, () => history.forward()],
|
|
45
45
|
[FUNCS.navigate.reload, () => history.go(0)],
|
|
46
46
|
[FUNCS.navigate.link, event => {
|
|
47
47
|
if (event.isTrusted) {
|
|
@@ -168,7 +168,7 @@ export const unregisterCallback = name => _isRegistrationOpen && registry.delete
|
|
|
168
168
|
/**
|
|
169
169
|
* Remove all callbacks from the registry
|
|
170
170
|
*
|
|
171
|
-
* @returns {
|
|
171
|
+
* @returns {void}
|
|
172
172
|
*/
|
|
173
173
|
export const clearRegistry = () => registry.clear();
|
|
174
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aegisjsproject/callback-registry",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": " A callback registry for AegisJSProject",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aegis",
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
},
|
|
76
76
|
"homepage": "https://github.com/AegisJSProject/callback-registry#readme",
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@rollup/plugin-
|
|
78
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
79
79
|
"@shgysk8zer0/eslint-config": "^1.0.1",
|
|
80
|
-
"
|
|
81
|
-
"
|
|
80
|
+
"eslint": "^9.15.0",
|
|
81
|
+
"rollup": "^4.27.2"
|
|
82
82
|
}
|
|
83
83
|
}
|