cotomy 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,10 +57,10 @@ The View layer provides thin wrappers around DOM elements and window events.
57
57
  - `is(selector: string): boolean` — Parent-aware matching helper
58
58
  - `empty: boolean` — True for tags that cannot have children or have no content
59
59
  - Attributes, classes, styles
60
- - `attribute(name)` / `attribute(name, value | null): this`
60
+ - `attribute(name)` / `attribute(name, value | null | undefined): this` — `null`/`undefined` removes the attribute
61
61
  - `hasAttribute(name): boolean`
62
62
  - `addClass(name): this` / `removeClass(name): this` / `toggleClass(name, force?): this` / `hasClass(name): boolean`
63
- - `style(name)` / `style(name, value | null): this`
63
+ - `style(name)` / `style(name, value | null | undefined): this` — `null`/`undefined` removes the style
64
64
  - Content & value
65
65
  - `text: string` (get/set)
66
66
  - `html: string` (get/set)
@@ -101,7 +101,7 @@ The View layer provides thin wrappers around DOM elements and window events.
101
101
  - `overlaps(target: CotomyElement): boolean` — True if the two elements' `rect` values overlap (AABB)
102
102
  - `overlapElements: CotomyElement[]` — Returns other CotomyElements (by `data-cotomy-instance`) that overlap this element
103
103
  - Events
104
- - Generic: `on(eventOrEvents, handler, options?)`, `off(eventOrEvents, handler?, options?)`, `once(eventOrEvents, handler, options?)`, `trigger(event[, Event])` — `eventOrEvents` accepts either a single event name or an array for batch registration/removal. `trigger` emits bubbling events by default and can be customized by passing an `Event`.
104
+ - Generic: `on(eventOrEvents, handler, options?)`, `off(eventOrEvents, handler?, options?)`, `once(eventOrEvents, handler, options?)`, `trigger(eventOrEvent[, Event])` — `eventOrEvents` accepts either a single event name or an array for batch registration/removal. `trigger` accepts either an event name or a prebuilt `Event`, emits bubbling events by default, and can be customized by passing an `Event`.
105
105
  - Delegation: `onSubTree(eventOrEvents, selector, handler, options?)` — `eventOrEvents` can also be an array for listening to multiple delegated events at once.
106
106
  - Mouse: `click`, `dblclick`, `mouseover`, `mouseout`, `mousedown`, `mouseup`, `mousemove`, `mouseenter`, `mouseleave`
107
107
  - Keyboard: `keydown`, `keyup`, `keypress`
@@ -165,7 +165,7 @@ npm test -- --run tests/view.spec.ts -t "compares document order with comesBefor
165
165
  - `scrollTo(target, options?: CotomyScrollOptions | Partial<CotomyScrollOptions>): this` — Scrolls to reveal a target (`selector | CotomyElement | HTMLElement`)
166
166
  - `moveNext(focused: CotomyElement, shift = false)` — Move focus to next/previous focusable
167
167
  - Window events
168
- - `on(eventOrEvents, handler): this` / `off(eventOrEvents, handler?): this` / `trigger(event[, Event]): this` — `eventOrEvents` accepts a single event name or an array. CotomyWindow’s `trigger` also bubbles by default and accepts an `Event` to override the behavior.
168
+ - `on(eventOrEvents, handler): this` / `off(eventOrEvents, handler?): this` / `trigger(eventOrEvent[, Event]): this` — `eventOrEvents` accepts a single event name or an array. CotomyWindow’s `trigger` accepts an event name or `Event`, bubbles by default, and accepts an `Event` to override the behavior.
169
169
  - `load(handler): this` / `ready(handler): this`
170
170
  - `resize([handler]): this` / `scroll([handler]): this` / `changeLayout([handler]): this` / `pageshow([handler]): this`
171
171
  - Window state
@@ -1492,7 +1492,7 @@ class CotomyElement {
1492
1492
  if (arguments.length === 1) {
1493
1493
  return this.element.hasAttribute(name) ? this.element.getAttribute(name) : undefined;
1494
1494
  }
1495
- else if (value === null) {
1495
+ else if (value == null) {
1496
1496
  this.element.removeAttribute(name);
1497
1497
  return this;
1498
1498
  }
@@ -1685,6 +1685,10 @@ class CotomyElement {
1685
1685
  return this;
1686
1686
  }
1687
1687
  trigger(event, e) {
1688
+ if (event instanceof Event) {
1689
+ this.element.dispatchEvent(event);
1690
+ return this;
1691
+ }
1688
1692
  this.element.dispatchEvent(e ?? new Event(event, { bubbles: true }));
1689
1693
  return this;
1690
1694
  }
@@ -2134,6 +2138,10 @@ class CotomyWindow {
2134
2138
  }
2135
2139
  }
2136
2140
  trigger(event, e) {
2141
+ if (event instanceof Event) {
2142
+ window.dispatchEvent(event);
2143
+ return this;
2144
+ }
2137
2145
  window.dispatchEvent(e ?? new Event(event, { bubbles: true }));
2138
2146
  return this;
2139
2147
  }