Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v2.0.1] - 2026-03-06

### Changed
- Use `Signal.State` for attributes & `Signal.Computed` to derive the selectors

## [v2.0.0] - 2026-03-01

## Added
Expand Down
23 changes: 12 additions & 11 deletions events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hasCallback, getCallback } from './callbacks.js';
import { Signal } from '@shgysk8zer0/signals';

const PREFIX = 'data-aegis-event-';
const EVENT_PREFIX = PREFIX + 'on-';
Expand Down Expand Up @@ -112,7 +113,7 @@ export const onWebkitanimationstart = EVENT_PREFIX + 'webkitanimationstart';
export const onWebkittransitionend = EVENT_PREFIX + 'webkittransitionend';
export const onError = EVENT_PREFIX + 'error';

export const eventAttrs = [
const eventAttrs = new Signal.State([
onAbort,
onBlur,
onFocus,
Expand Down Expand Up @@ -209,15 +210,15 @@ export const eventAttrs = [
onWebkitanimationstart,
onWebkittransitionend,
onError,
];
]);

let selector = eventAttrs.map(attr => `[${CSS.escape(attr)}]`).join(', ');
const selector = new Signal.Computed(() => eventAttrs.get().map(attr => `[${CSS.escape(attr)}]`).join(', '));

const attrToProp = attr => `on${attr[EVENT_PREFIX_LENGTH].toUpperCase()}${attr.substring(EVENT_PREFIX_LENGTH + 1)}`;

export const eventToProp = event => EVENT_PREFIX + event;

export const hasEventAttribute = event => eventAttrs.includes(EVENT_PREFIX + event);
export const hasEventAttribute = event => eventAttrs.get().includes(EVENT_PREFIX + event);

const isEventDataAttr = ([name]) => name.startsWith(DATA_PREFIX);

Expand Down Expand Up @@ -400,13 +401,13 @@ export function registerEventAttribute(attr, {
signal,
} = {}) {
const fullAttr = EVENT_PREFIX + attr.toLowerCase();
const attrs = eventAttrs.get();

if (! eventAttrs.includes(fullAttr)) {
if (! attrs.includes(fullAttr)) {
const sel = `[${CSS.escape(fullAttr)}]`;
const prop = attrToProp(fullAttr);
eventAttrs.push(fullAttr);
eventAttrs.set([...attrs, fullAttr]);
EVENTS[prop] = fullAttr;
selector += `, ${sel}`;

if (addListeners) {
requestAnimationFrame(() => {
Expand Down Expand Up @@ -556,9 +557,9 @@ export function unregisterSignal(signal) {
* @returns {Element|Document} Returns the passed target node
*/
export function attachListeners(target, { signal } = {}) {
const nodes = target instanceof Element && target.matches(selector)
? [target, ...target.querySelectorAll(selector)]
: target.querySelectorAll(selector);
const nodes = target instanceof Element && target.matches(selector.get())
? [target, ...target.querySelectorAll(selector.get())]
: target.querySelectorAll(selector.get());

nodes.forEach(el => _addListeners(el, { signal }));

Expand All @@ -578,7 +579,7 @@ export function observeEvents(root = document) {
childList:true,
attributes: true,
attributeOldValue: true,
attributeFilter: eventAttrs,
attributeFilter: eventAttrs.get(),
});
}

Expand Down
129 changes: 124 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aegisjsproject/callback-registry",
"version": "2.0.0",
"version": "2.0.1",
"description": " A callback registry for AegisJSProject",
"keywords": [
"aegis",
Expand Down Expand Up @@ -49,6 +49,7 @@
"run:tests": "node --test *.test.js",
"clean": "rm -f ./*.cjs",
"build:js": "npm run clean && rollup -c rollup.config.js",
"update:importmap": "npx --package=@shgysk8zer0/importmap importmap-html test/index.html",
"create:lock": "npm i --package-lock-only --ignore-scripts --no-audit --no-fund",
"version:bump": "npm run version:bump:patch",
"version:bump:patch": "npm version --no-git-tag-version patch && npm run create:lock",
Expand Down Expand Up @@ -78,9 +79,13 @@
"devDependencies": {
"@rollup/plugin-terser": "^1.0.0",
"@shgysk8zer0/eslint-config": "^1.0.5",
"@shgysk8zer0/polyfills": "^0.6.0",
"eslint": "^10.0.0",
"@shgysk8zer0/polyfills": "^0.6.2",
"@shgysk8zer0/rollup-import": "^2.0.2",
"eslint": "^10.0.2",
"http-server": "^14.1.1",
"rollup": "^4.27.2"
"rollup": "^4.59.0"
},
"dependencies": {
"@shgysk8zer0/signals": "^0.0.3"
}
}
Loading
Loading