From 2f082dc785547ace5429f31ca952691f53e678da Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 26 Oct 2023 15:36:51 +0200 Subject: [PATCH] fix changable -> changeable --- .changeset/lemon-apples-lay.md | 6 +++ .../router/src/directives/submit-on-change.ts | 2 +- packages/utils/src/index.ts | 16 +++---- packages/utils/src/utils.test.ts | 48 +++++++++---------- 4 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 .changeset/lemon-apples-lay.md diff --git a/.changeset/lemon-apples-lay.md b/.changeset/lemon-apples-lay.md new file mode 100644 index 0000000..e791d94 --- /dev/null +++ b/.changeset/lemon-apples-lay.md @@ -0,0 +1,6 @@ +--- +'@coldwired/router': patch +'@coldwired/utils': patch +--- + +fix changable -> changeable diff --git a/packages/router/src/directives/submit-on-change.ts b/packages/router/src/directives/submit-on-change.ts index 38c6c16..c5ef8d6 100644 --- a/packages/router/src/directives/submit-on-change.ts +++ b/packages/router/src/directives/submit-on-change.ts @@ -45,7 +45,7 @@ export class SubmitOnChange extends Directive implements EventListenerObject { private onChange(form: HTMLFormElement, target: EventTarget) { matchInputElement(target, { - changable: () => { + changeable: () => { form.requestSubmit(); }, }); diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index a6062f0..998f9a8 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -166,8 +166,8 @@ export function isInputableElement(node: unknown): node is HTMLInputElement | HT return isTextAreaElement(node) || (isInputElement(node) && isInputableType(node.type)); } -export function isChangableElement(node: unknown): node is HTMLInputElement | HTMLSelectElement { - return isSelectElement(node) || (isInputElement(node) && isChangableType(node.type)); +export function isChangeableElement(node: unknown): node is HTMLInputElement | HTMLSelectElement { + return isSelectElement(node) || (isInputElement(node) && isChangeableType(node.type)); } export function isElementOrText(node: unknown): node is Element | Text { @@ -356,9 +356,9 @@ function isInputableType(type: string) { return INPUTABLE_TYPES.includes(type); } -const CHANGABLE_TYPES = ['checkbox', 'radio', 'range', 'file', 'color']; -function isChangableType(type: string) { - return CHANGABLE_TYPES.includes(type); +const CHANGEABLE_TYPES = ['checkbox', 'radio', 'range', 'file', 'color']; +function isChangeableType(type: string) { + return CHANGEABLE_TYPES.includes(type); } type InputMatcher = (element: T) => void; @@ -367,7 +367,7 @@ export function matchInputElement( node: unknown, matcher: { inputable?: InputMatcher; - changable?: InputMatcher; + changeable?: InputMatcher; text?: InputMatcher; select?: InputMatcher; date?: InputMatcher; @@ -395,7 +395,7 @@ export function matchInputElement( } else { matcher.inputable?.(node); } - } else if (isChangableElement(node)) { + } else if (isChangeableElement(node)) { if (matcher.select && isSelectElement(node)) { matcher.select(node); } else if (matcher.checkbox && isCheckboxInputElement(node)) { @@ -409,7 +409,7 @@ export function matchInputElement( } else if (matcher.color && isColorInputElement(node)) { matcher.color(node); } else { - matcher.changable?.(node); + matcher.changeable?.(node); } } else if (isHiddenInputElement(node)) { matcher.hidden?.(node); diff --git a/packages/utils/src/utils.test.ts b/packages/utils/src/utils.test.ts index 31f2ea7..c15eac6 100644 --- a/packages/utils/src/utils.test.ts +++ b/packages/utils/src/utils.test.ts @@ -6,7 +6,7 @@ import { isFormInputElement, isSelectElement, isInputableElement, - isChangableElement, + isChangeableElement, matchInputElement, } from '.'; @@ -96,34 +96,34 @@ describe('@coldwired/utils', () => { }); }); - describe('isChangableElement', () => { + describe('isChangeableElement', () => { it('should match checkbox input element', () => { - expect(isChangableElement(createInputElement('checkbox'))).toBeTruthy(); + expect(isChangeableElement(createInputElement('checkbox'))).toBeTruthy(); }); it('should match radio input element', () => { - expect(isChangableElement(createInputElement('radio'))).toBeTruthy(); + expect(isChangeableElement(createInputElement('radio'))).toBeTruthy(); }); it('should match range input element', () => { - expect(isChangableElement(createInputElement('range'))).toBeTruthy(); + expect(isChangeableElement(createInputElement('range'))).toBeTruthy(); }); it('should match color input element', () => { - expect(isChangableElement(createInputElement('color'))).toBeTruthy(); + expect(isChangeableElement(createInputElement('color'))).toBeTruthy(); }); it('should match file input element', () => { - expect(isChangableElement(createInputElement('file'))).toBeTruthy(); + expect(isChangeableElement(createInputElement('file'))).toBeTruthy(); }); it('should match select element', () => { - expect(isChangableElement(document.createElement('select'))).toBeTruthy(); + expect(isChangeableElement(document.createElement('select'))).toBeTruthy(); }); it('should not match text input element', () => { - expect(isChangableElement(createInputElement('text'))).toBeFalsy(); + expect(isChangeableElement(createInputElement('text'))).toBeFalsy(); }); it('should not match textarea element', () => { - expect(isChangableElement(document.createElement('textarea'))).toBeFalsy(); + expect(isChangeableElement(document.createElement('textarea'))).toBeFalsy(); }); it('should not match div element', () => { - expect(isChangableElement(document.createElement('div'))).toBeFalsy(); + expect(isChangeableElement(document.createElement('div'))).toBeFalsy(); }); }); @@ -137,7 +137,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -152,7 +152,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -169,7 +169,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }, @@ -186,7 +186,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -201,7 +201,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -216,7 +216,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -228,7 +228,7 @@ describe('@coldwired/utils', () => { text: (target) => { expect(target).toBeInstanceOf(HTMLTextAreaElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -255,7 +255,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); @@ -267,13 +267,13 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLTextAreaElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); }); - it('should match input changable element', () => { + it('should match input changeable element', () => { expect.assertions(1); matchInputElement(createInputElement('checkbox'), { checkbox: (target) => { @@ -282,13 +282,13 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, }); }); - it('should match select changable element', () => { + it('should match select changeable element', () => { expect.assertions(1); matchInputElement(document.createElement('select'), { select: (target) => { @@ -297,7 +297,7 @@ describe('@coldwired/utils', () => { inputable: (target) => { expect(target).toBeInstanceOf(HTMLInputElement); }, - changable: (target) => { + changeable: (target) => { expect(target).toBeInstanceOf(HTMLSelectElement); }, });