@oscarpalmer/toretto 0.44.0 → 0.45.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.
package/dist/index.d.mts CHANGED
@@ -462,6 +462,12 @@ declare function isEventTarget(value: unknown): value is EventTarget;
462
462
  * @returns `true` if it's an HTML or SVG element, otherwise `false`
463
463
  */
464
464
  declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
465
+ /**
466
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
467
+ * @param value Value to check
468
+ * @returns `true` if it's an input element, otherwise `false`
469
+ */
470
+ declare function isInputElement(value: unknown): value is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
465
471
  //#endregion
466
472
  //#region src/is.d.ts
467
473
  /**
@@ -591,4 +597,4 @@ declare function setStyles(element: Element, styles: Styles): void;
591
597
  */
592
598
  declare function toggleStyles(element: Element, styles: Styles): StyleToggler;
593
599
  //#endregion
594
- export { findElement as $, findElement, findElements as $$, findElements, Attribute, CustomEventListener, EventPosition, RemovableEventListener, Selector, StyleToggler, TextDirection, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
600
+ export { findElement as $, findElement, findElements as $$, findElements, Attribute, CustomEventListener, EventPosition, RemovableEventListener, Selector, StyleToggler, TextDirection, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
package/dist/index.mjs CHANGED
@@ -397,6 +397,14 @@ function isEventTarget(value) {
397
397
  function isHTMLOrSVGElement(value) {
398
398
  return value instanceof HTMLElement || value instanceof SVGElement;
399
399
  }
400
+ /**
401
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
402
+ * @param value Value to check
403
+ * @returns `true` if it's an input element, otherwise `false`
404
+ */
405
+ function isInputElement(value) {
406
+ return value instanceof HTMLInputElement || value instanceof HTMLSelectElement || value instanceof HTMLTextAreaElement;
407
+ }
400
408
  //#endregion
401
409
  //#region src/is.ts
402
410
  /**
@@ -459,11 +467,16 @@ function updateElementValue(element, key, value, set, remove, isBoolean, json) {
459
467
  const CSS_VARIABLE_PREFIX$1 = "--";
460
468
  //#endregion
461
469
  //#region src/internal/property.ts
470
+ function getPropertyValue$1(element, name, value) {
471
+ if (isInputElement(element) && name === "value") return getString(value);
472
+ return value;
473
+ }
462
474
  function updateProperty(element, name, value, dispatch) {
463
475
  let property = name;
464
476
  if (!(property in element)) property = camelCase(name);
465
- if (!(property in element) || Object.is(element[property], value)) return;
466
- element[property] = value;
477
+ const next = getPropertyValue$1(element, name, value);
478
+ if (!(property in element) || Object.is(element[property], next)) return;
479
+ element[property] = next;
467
480
  const event = dispatch && elementEvents[element.tagName]?.[property];
468
481
  if (typeof event === "string") element.dispatchEvent(new Event(event, {
469
482
  bubbles: true,
@@ -1518,4 +1531,4 @@ const templates = new SizedMap(128);
1518
1531
  let parser;
1519
1532
  window.templates = templates;
1520
1533
  //#endregion
1521
- export { findElement as $, findElement, findElements as $$, findElements, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
1534
+ export { findElement as $, findElement, findElements as $$, findElements, booleanAttributes, createElement, dispatch, findAncestor, findRelatives, getAttribute, getAttributes, getData, getDistance, getElementUnderPointer, getFocusable, getPosition, getProperties, getProperty, getStyle, getStyles, getTabbable, getTextDirection, html, isBadAttribute, isBooleanAttribute, isChildNode, isEventTarget, isFocusable, isHTMLOrSVGElement, isInDocument, isInputElement, isInvalidBooleanAttribute, isTabbable, off, on, sanitize, setAttribute, setAttributes, setData, setProperties, setProperty, setStyle, setStyles, supportsTouch, toggleStyles };
@@ -11,5 +11,11 @@ declare function isEventTarget(value: unknown): value is EventTarget;
11
11
  * @returns `true` if it's an HTML or SVG element, otherwise `false`
12
12
  */
13
13
  declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
14
+ /**
15
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
16
+ * @param value Value to check
17
+ * @returns `true` if it's an input element, otherwise `false`
18
+ */
19
+ declare function isInputElement(value: unknown): value is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
14
20
  //#endregion
15
- export { isEventTarget, isHTMLOrSVGElement };
21
+ export { isEventTarget, isHTMLOrSVGElement, isInputElement };
@@ -15,5 +15,13 @@ function isEventTarget(value) {
15
15
  function isHTMLOrSVGElement(value) {
16
16
  return value instanceof HTMLElement || value instanceof SVGElement;
17
17
  }
18
+ /**
19
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
20
+ * @param value Value to check
21
+ * @returns `true` if it's an input element, otherwise `false`
22
+ */
23
+ function isInputElement(value) {
24
+ return value instanceof HTMLInputElement || value instanceof HTMLSelectElement || value instanceof HTMLTextAreaElement;
25
+ }
18
26
  //#endregion
19
- export { isEventTarget, isHTMLOrSVGElement };
27
+ export { isEventTarget, isHTMLOrSVGElement, isInputElement };
@@ -1,10 +1,17 @@
1
+ import { isInputElement } from "./is.mjs";
2
+ import { getString } from "@oscarpalmer/atoms/string";
1
3
  import { camelCase } from "@oscarpalmer/atoms/string/case";
2
4
  //#region src/internal/property.ts
5
+ function getPropertyValue(element, name, value) {
6
+ if (isInputElement(element) && name === "value") return getString(value);
7
+ return value;
8
+ }
3
9
  function updateProperty(element, name, value, dispatch) {
4
10
  let property = name;
5
11
  if (!(property in element)) property = camelCase(name);
6
- if (!(property in element) || Object.is(element[property], value)) return;
7
- element[property] = value;
12
+ const next = getPropertyValue(element, name, value);
13
+ if (!(property in element) || Object.is(element[property], next)) return;
14
+ element[property] = next;
8
15
  const event = dispatch && elementEvents[element.tagName]?.[property];
9
16
  if (typeof event === "string") element.dispatchEvent(new Event(event, {
10
17
  bubbles: true,
package/dist/is.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.mjs";
1
+ import { isEventTarget, isHTMLOrSVGElement, isInputElement } from "./internal/is.mjs";
2
2
 
3
3
  //#region src/is.d.ts
4
4
  /**
@@ -21,4 +21,4 @@ declare function isInDocument(node: Node): boolean;
21
21
  */
22
22
  declare function isInDocument(node: Node, document: Document): boolean;
23
23
  //#endregion
24
- export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument };
24
+ export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument, isInputElement };
package/dist/is.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isEventTarget, isHTMLOrSVGElement } from "./internal/is.mjs";
1
+ import { isEventTarget, isHTMLOrSVGElement, isInputElement } from "./internal/is.mjs";
2
2
  //#region src/is.ts
3
3
  /**
4
4
  * Is the value a child node?
@@ -21,4 +21,4 @@ const CHILD_NODE_TYPES = new Set([
21
21
  Node.DOCUMENT_TYPE_NODE
22
22
  ]);
23
23
  //#endregion
24
- export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument };
24
+ export { isChildNode, isEventTarget, isHTMLOrSVGElement, isInDocument, isInputElement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/toretto",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "A collection of badass DOM utilities.",
5
5
  "keywords": [
6
6
  "dom",
@@ -24,4 +24,19 @@ export function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGEl
24
24
  return value instanceof HTMLElement || value instanceof SVGElement;
25
25
  }
26
26
 
27
+ /**
28
+ * Is the value an input element? _(`<input>`, `<select>`, or `<textarea>`)_
29
+ * @param value Value to check
30
+ * @returns `true` if it's an input element, otherwise `false`
31
+ */
32
+ export function isInputElement(
33
+ value: unknown,
34
+ ): value is HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement {
35
+ return (
36
+ value instanceof HTMLInputElement ||
37
+ value instanceof HTMLSelectElement ||
38
+ value instanceof HTMLTextAreaElement
39
+ );
40
+ }
41
+
27
42
  // #endregion
@@ -1,8 +1,18 @@
1
1
  import type {PlainObject} from '@oscarpalmer/atoms/models';
2
+ import {getString} from '@oscarpalmer/atoms/string';
2
3
  import {camelCase} from '@oscarpalmer/atoms/string/case';
4
+ import {isInputElement} from './is';
3
5
 
4
6
  // #region Functions
5
7
 
8
+ function getPropertyValue(element: Element, name: string, value: unknown): unknown {
9
+ if (isInputElement(element) && name === 'value') {
10
+ return getString(value);
11
+ }
12
+
13
+ return value;
14
+ }
15
+
6
16
  export function updateProperty(
7
17
  element: Element,
8
18
  name: string,
@@ -15,11 +25,13 @@ export function updateProperty(
15
25
  property = camelCase(name);
16
26
  }
17
27
 
18
- if (!(property in element) || Object.is((element as unknown as PlainObject)[property], value)) {
28
+ const next = getPropertyValue(element, name, value);
29
+
30
+ if (!(property in element) || Object.is((element as unknown as PlainObject)[property], next)) {
19
31
  return;
20
32
  }
21
33
 
22
- (element as unknown as PlainObject)[property] = value;
34
+ (element as unknown as PlainObject)[property] = next;
23
35
 
24
36
  const event = dispatch && elementEvents[element.tagName]?.[property];
25
37
 
package/src/is.ts CHANGED
@@ -54,6 +54,6 @@ const CHILD_NODE_TYPES: Set<number> = new Set([
54
54
 
55
55
  // #region Exports
56
56
 
57
- export {isEventTarget, isHTMLOrSVGElement} from './internal/is';
57
+ export {isEventTarget, isHTMLOrSVGElement, isInputElement} from './internal/is';
58
58
 
59
59
  // #endregion