diff --git a/packages/buefy-next/rollup.config.mjs b/packages/buefy-next/rollup.config.mjs index 6ef37fc76..fe20e8f2c 100644 --- a/packages/buefy-next/rollup.config.mjs +++ b/packages/buefy-next/rollup.config.mjs @@ -30,12 +30,9 @@ const components = fs ) const JS_COMPONENTS = [ - 'autocomplete', 'clockpicker', - 'colorpicker', 'datepicker', 'datetimepicker', - 'numberinput', 'timepicker', ] diff --git a/packages/buefy-next/src/components/autocomplete/Autocomplete.spec.js b/packages/buefy-next/src/components/autocomplete/Autocomplete.spec.ts similarity index 94% rename from packages/buefy-next/src/components/autocomplete/Autocomplete.spec.js rename to packages/buefy-next/src/components/autocomplete/Autocomplete.spec.ts index 0d97cbd0b..eed740160 100644 --- a/packages/buefy-next/src/components/autocomplete/Autocomplete.spec.js +++ b/packages/buefy-next/src/components/autocomplete/Autocomplete.spec.ts @@ -1,7 +1,9 @@ import { mount, shallowMount } from '@vue/test-utils' -import BAutocomplete from '@components/autocomplete/Autocomplete' +import type { DOMWrapper, VueWrapper } from '@vue/test-utils' +import { beforeEach, describe, expect, it, vi } from 'vitest' +import BAutocomplete from '@components/autocomplete/Autocomplete.vue' -const findStringsStartingWith = (array, value) => +const findStringsStartingWith = (array: string[], value: string) => array.filter((x) => x.startsWith(value)) const DATA_LIST = [ @@ -19,11 +21,13 @@ const DATA_LIST = [ 'Vue.js' ] const dropdownMenu = '.dropdown-menu' -let wrapper, $input, $dropdown, stubs +let wrapper: VueWrapper> +let $input: DOMWrapper +let $dropdown: DOMWrapper +const stubs = { 'b-icon': true } describe('BAutocomplete', () => { beforeEach(() => { - stubs = { 'b-icon': true } wrapper = mount(BAutocomplete, { props: { checkInfiniteScroll: true @@ -56,7 +60,7 @@ describe('BAutocomplete', () => { }) it('can apply a maximum height for the dropdown', async () => { - expect(wrapper.vm.contentStyle.maxHeight).toBeNull() + expect(wrapper.vm.contentStyle.maxHeight).toBeUndefined() const maxHeight = 200 @@ -186,7 +190,7 @@ describe('BAutocomplete', () => { }) it('close dropdown on esc', async () => { - jest.useFakeTimers() + vi.useFakeTimers() await wrapper.setProps({ data: DATA_LIST }) await wrapper.setData({ isActive: true }) @@ -196,12 +200,12 @@ describe('BAutocomplete', () => { expect($dropdown.isVisible()).toBeFalsy() - wrapper.vm.calcDropdownInViewportVertical = jest.fn( + wrapper.vm.calcDropdownInViewportVertical = vi.fn( () => wrapper.vm.calcDropdownInViewportVertical ) - jest.runAllTimers() + vi.runAllTimers() expect(wrapper.vm.calcDropdownInViewportVertical).toHaveBeenCalled() - jest.useRealTimers() + vi.useRealTimers() }) it('close dropdown on click outside', async () => { @@ -216,7 +220,7 @@ describe('BAutocomplete', () => { }) it('open dropdown on down key click', async () => { - wrapper.vm.setHovered = jest.fn(() => wrapper.vm.setHovered) + wrapper.vm.setHovered = vi.fn(() => wrapper.vm.setHovered) await wrapper.setProps({ data: DATA_LIST, dropdownPosition: 'bottom' @@ -295,7 +299,7 @@ describe('BAutocomplete', () => { it('can be used with a custom data formatter', async () => { await wrapper.setProps({ data: DATA_LIST, - customFormatter: (val) => `${val} formatted` + customFormatter: (val: string) => `${val} formatted` }) await wrapper.setData({ isActive: true }) @@ -373,8 +377,8 @@ describe('BAutocomplete', () => { }) it('reset events before destroy', () => { - document.removeEventListener = jest.fn() - window.removeEventListener = jest.fn() + document.removeEventListener = vi.fn() + window.removeEventListener = vi.fn() wrapper.unmount() diff --git a/packages/buefy-next/src/components/autocomplete/Autocomplete.vue b/packages/buefy-next/src/components/autocomplete/Autocomplete.vue index 861566237..50bc5e457 100644 --- a/packages/buefy-next/src/components/autocomplete/Autocomplete.vue +++ b/packages/buefy-next/src/components/autocomplete/Autocomplete.vue @@ -27,7 +27,7 @@ @keydown.up.prevent="keyArrows('up')" @keydown.down.prevent="keyArrows('down')" @icon-right-click="rightIconClick" - @icon-click="(event) => $emit('icon-click', event)" + @icon-click="(event: MouseEvent) => $emit('icon-click', event)" /> @@ -84,7 +84,7 @@ :index="index" /> - {{ getValue(option, true) }} + {{ getValue(option) }} @@ -110,7 +110,10 @@ - diff --git a/packages/buefy-next/src/components/autocomplete/__snapshots__/Autocomplete.spec.js.snap b/packages/buefy-next/src/components/autocomplete/__snapshots__/Autocomplete.spec.js.snap deleted file mode 100644 index 26c01f545..000000000 --- a/packages/buefy-next/src/components/autocomplete/__snapshots__/Autocomplete.spec.js.snap +++ /dev/null @@ -1,21 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BAutocomplete render correctly 1`] = ` -
-
- - - -
- - - -
-`; diff --git a/packages/buefy-next/src/components/autocomplete/__snapshots__/Autocomplete.spec.ts.snap b/packages/buefy-next/src/components/autocomplete/__snapshots__/Autocomplete.spec.ts.snap new file mode 100644 index 000000000..543f6c6d8 --- /dev/null +++ b/packages/buefy-next/src/components/autocomplete/__snapshots__/Autocomplete.spec.ts.snap @@ -0,0 +1,21 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`BAutocomplete > render correctly 1`] = ` +"
+
+ + + +
+ +
+
+ + + + +
+
+
+
" +`; diff --git a/packages/buefy-next/src/components/autocomplete/index.js b/packages/buefy-next/src/components/autocomplete/index.ts similarity index 81% rename from packages/buefy-next/src/components/autocomplete/index.js rename to packages/buefy-next/src/components/autocomplete/index.ts index d70dbb2c2..0f8ccb13e 100644 --- a/packages/buefy-next/src/components/autocomplete/index.js +++ b/packages/buefy-next/src/components/autocomplete/index.ts @@ -1,9 +1,10 @@ +import type { App } from 'vue' import Autocomplete from './Autocomplete.vue' import { registerComponent } from '../../utils/plugins' const Plugin = { - install(Vue) { + install(Vue: App) { registerComponent(Vue, Autocomplete) } } diff --git a/packages/buefy-next/src/components/colorpicker/Colorpicker.spec.js b/packages/buefy-next/src/components/colorpicker/Colorpicker.spec.ts similarity index 83% rename from packages/buefy-next/src/components/colorpicker/Colorpicker.spec.js rename to packages/buefy-next/src/components/colorpicker/Colorpicker.spec.ts index 7abc6a308..e81b3c103 100644 --- a/packages/buefy-next/src/components/colorpicker/Colorpicker.spec.js +++ b/packages/buefy-next/src/components/colorpicker/Colorpicker.spec.ts @@ -1,5 +1,6 @@ +import { describe, expect, it } from 'vitest' import { shallowMount } from '@vue/test-utils' -import BColorpicker from '@components/colorpicker/Colorpicker' +import BColorpicker from '@components/colorpicker/Colorpicker.vue' describe('BColorpicker', () => { it('render correctly', () => { diff --git a/packages/buefy-next/src/components/colorpicker/Colorpicker.vue b/packages/buefy-next/src/components/colorpicker/Colorpicker.vue index 3548e3f02..1b352b252 100644 --- a/packages/buefy-next/src/components/colorpicker/Colorpicker.vue +++ b/packages/buefy-next/src/components/colorpicker/Colorpicker.vue @@ -98,25 +98,46 @@ - diff --git a/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.spec.js b/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.spec.ts similarity index 86% rename from packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.spec.js rename to packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.spec.ts index 91b8746f2..c92ff18c0 100644 --- a/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.spec.js +++ b/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.spec.ts @@ -1,6 +1,7 @@ +import { describe, expect, it } from 'vitest' import { shallowMount } from '@vue/test-utils' import Color from '@utils/color' -import BColorpickerAlphaSlider from '@components/colorpicker/ColorpickerAlphaSlider' +import BColorpickerAlphaSlider from '@components/colorpicker/ColorpickerAlphaSlider.vue' describe('BColorpickerAlphaSlider', () => { it('render correctly', () => { diff --git a/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.vue b/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.vue index c814f04df..4c115b616 100644 --- a/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.vue +++ b/packages/buefy-next/src/components/colorpicker/ColorpickerAlphaSlider.vue @@ -25,23 +25,28 @@ - diff --git a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.js b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.ts similarity index 79% rename from packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.js rename to packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.ts index 8fe30ebbd..c33313f9b 100644 --- a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.js +++ b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.spec.ts @@ -1,8 +1,9 @@ +import { beforeEach, describe, expect, it } from 'vitest' import { shallowMount } from '@vue/test-utils' import Color from '@utils/color' -import BColorpickerHSLRepresentationSquare from '@components/colorpicker/ColorpickerHSLRepresentationSquare' +import BColorpickerHSLRepresentationSquare from '@components/colorpicker/ColorpickerHSLRepresentationSquare.vue' -let defaultProps +let defaultProps: () => { value: Color } describe('BColorpickerHSLRepresentationSquare', () => { beforeEach(() => { diff --git a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.vue b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.vue index ff9c92d99..fb5726a04 100644 --- a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.vue +++ b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationSquare.vue @@ -44,18 +44,25 @@ - diff --git a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.js b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.ts similarity index 79% rename from packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.js rename to packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.ts index 3f6bf7d05..e54dc972d 100644 --- a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.js +++ b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.spec.ts @@ -1,8 +1,9 @@ +import { beforeEach, describe, expect, it } from 'vitest' import { shallowMount } from '@vue/test-utils' import Color from '@utils/color' -import BColorpickerHSLRepresentationTriangle from '@components/colorpicker/ColorpickerHSLRepresentationTriangle' +import BColorpickerHSLRepresentationTriangle from '@components/colorpicker/ColorpickerHSLRepresentationTriangle.vue' -let defaultProps +let defaultProps: () => { value: Color } describe('BColorpickerHSLRepresentationTriangle', () => { beforeEach(() => { diff --git a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.vue b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.vue index 7e7b0439d..5897ffbe6 100644 --- a/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.vue +++ b/packages/buefy-next/src/components/colorpicker/ColorpickerHSLRepresentationTriangle.vue @@ -115,20 +115,25 @@ - diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/Colorpicker.spec.js.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/Colorpicker.spec.js.snap deleted file mode 100644 index 3d9c806bb..000000000 --- a/packages/buefy-next/src/components/colorpicker/__snapshots__/Colorpicker.spec.js.snap +++ /dev/null @@ -1,77 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BColorpicker render correctly 1`] = ` -
- -
-`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/Colorpicker.spec.ts.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/Colorpicker.spec.ts.snap new file mode 100644 index 000000000..3e8d5f517 --- /dev/null +++ b/packages/buefy-next/src/components/colorpicker/__snapshots__/Colorpicker.spec.ts.snap @@ -0,0 +1,77 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`BColorpicker > render correctly 1`] = ` +"
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+ + + +
+
+ +
+
+
+
+
+ + + +
+
+ +
+
+
+
+
+ + + +
+
+ +
+ +
+
+ +
+
+
+
+
+
+
+
" +`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.js.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.js.snap deleted file mode 100644 index 808c06c06..000000000 --- a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.js.snap +++ /dev/null @@ -1,9 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BColorpickerAlphaSlider render correctly 1`] = ` -
-
- -
-
-`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.ts.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.ts.snap new file mode 100644 index 000000000..647ee5227 --- /dev/null +++ b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerAlphaSlider.spec.ts.snap @@ -0,0 +1,9 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`BColorpickerAlphaSlider > render correctly 1`] = ` +"
+
+ +
+
" +`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationSquare.spec.js.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationSquare.spec.js.snap deleted file mode 100644 index 146c82bc4..000000000 --- a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationSquare.spec.js.snap +++ /dev/null @@ -1,12 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BColorpickerHSLRepresentationSquare render correctly 1`] = ` -
-
-
-
-
-
-
-
-`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationSquare.spec.ts.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationSquare.spec.ts.snap new file mode 100644 index 000000000..e1a8861b5 --- /dev/null +++ b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationSquare.spec.ts.snap @@ -0,0 +1,12 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`BColorpickerHSLRepresentationSquare > render correctly 1`] = ` +"
+
+
+
+
+
+
+
" +`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.js.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.js.snap deleted file mode 100644 index 510663aa0..000000000 --- a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.js.snap +++ /dev/null @@ -1,36 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BColorpickerHSLRepresentationTriangle render correctly 1`] = ` - - - - - - - - - - - - - - - - -
-
- - -
-
-
-
- - - - -
-
-
-
-`; diff --git a/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.ts.snap b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.ts.snap new file mode 100644 index 000000000..8adc1b24e --- /dev/null +++ b/packages/buefy-next/src/components/colorpicker/__snapshots__/ColorpickerHSLRepresentationTriangle.spec.ts.snap @@ -0,0 +1,36 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`BColorpickerHSLRepresentationTriangle > render correctly 1`] = ` +" + + + + + + + + + + + + + + + +
+
+ + +
+
+
+
+ + + + +
+
+
+
" +`; diff --git a/packages/buefy-next/src/components/colorpicker/index.js b/packages/buefy-next/src/components/colorpicker/index.ts similarity index 81% rename from packages/buefy-next/src/components/colorpicker/index.js rename to packages/buefy-next/src/components/colorpicker/index.ts index be4f79ab2..9ce155936 100644 --- a/packages/buefy-next/src/components/colorpicker/index.js +++ b/packages/buefy-next/src/components/colorpicker/index.ts @@ -1,9 +1,10 @@ +import type { App } from 'vue' import Colorpicker from './Colorpicker.vue' import { registerComponent } from '../../utils/plugins' const Plugin = { - install(Vue) { + install(Vue: App) { registerComponent(Vue, Colorpicker) } } diff --git a/packages/buefy-next/src/components/numberinput/Numberinput.spec.js b/packages/buefy-next/src/components/numberinput/Numberinput.spec.ts similarity index 93% rename from packages/buefy-next/src/components/numberinput/Numberinput.spec.js rename to packages/buefy-next/src/components/numberinput/Numberinput.spec.ts index 45a4a4f87..f2c466451 100644 --- a/packages/buefy-next/src/components/numberinput/Numberinput.spec.js +++ b/packages/buefy-next/src/components/numberinput/Numberinput.spec.ts @@ -1,7 +1,9 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { shallowMount, mount } from '@vue/test-utils' -import BNumberinput from '@components/numberinput/Numberinput' +import type { VueWrapper } from '@vue/test-utils' +import BNumberinput from '@components/numberinput/Numberinput.vue' -let wrapper +let wrapper: VueWrapper> describe('BNumberinput', () => { describe('Rendered', () => { @@ -10,7 +12,7 @@ describe('BNumberinput', () => { }) afterEach(() => { - jest.useRealTimers() + vi.useRealTimers() }) it('is called', () => { @@ -37,7 +39,7 @@ describe('BNumberinput', () => { it('increments/decrements on long pressing exponentially', async () => { // we should not depend on a real timer // otherwise the results will depend on the machine - jest.useFakeTimers() + vi.useFakeTimers() await wrapper.setProps({ exponential: true, modelValue: 1, step: 1 }) @@ -47,16 +49,16 @@ describe('BNumberinput', () => { for (let n = 1; n <= 10; ++n) { // while Jest's fake setTimeout truncates the delay to an exact // ms when it schedules the callback, - // jest.advanceTimersByTime floors the value + // vi.advanceTimersByTime floors the value // and accumulates the remainder. // so should be floored to prevent the accumulated remainder // from triggering an extra callback - jest.advanceTimersByTime(Math.floor(250 / n)) + vi.advanceTimersByTime(Math.floor(250 / n)) expect(wrapper.vm.computedValue).toBe(n + 2) } wrapper.find('.control.plus').trigger('mouseup') - jest.runAllTimers() + vi.runAllTimers() await wrapper.vm.$nextTick() expect(wrapper.vm.computedValue).toBe(12) @@ -68,22 +70,22 @@ describe('BNumberinput', () => { for (let n = 1; n <= 20; ++n) { // while Jest's fake setTimeout truncates the delay to an exact // ms when it schedules the callback, - // jest.advanceTimersByTime floors the value + // vi.advanceTimersByTime floors the value // and accumulates the remainder. // so should be floored to prevent the accumulated remainder // from triggering an extra callback - jest.advanceTimersByTime(Math.floor(250 / (n * 3))) + vi.advanceTimersByTime(Math.floor(250 / (n * 3))) expect(wrapper.vm.computedValue).toBe(n + 1) } wrapper.find('.control.plus').trigger('mouseup') - jest.runAllTimers() + vi.runAllTimers() await wrapper.vm.$nextTick() expect(wrapper.vm.computedValue).toBe(21) }) it('increments/decrements on long pressing', async () => { - jest.useFakeTimers() + vi.useFakeTimers() let val = 0 @@ -92,9 +94,9 @@ describe('BNumberinput', () => { val++ // await wait(2000) - jest.runOnlyPendingTimers() - jest.runOnlyPendingTimers() - jest.runOnlyPendingTimers() + vi.runOnlyPendingTimers() + vi.runOnlyPendingTimers() + vi.runOnlyPendingTimers() val += 3 wrapper.find('.control.plus').trigger('mouseup') @@ -104,8 +106,8 @@ describe('BNumberinput', () => { wrapper.find('.control.minus button').trigger('mousedown') val-- - jest.runOnlyPendingTimers() - jest.runOnlyPendingTimers() + vi.runOnlyPendingTimers() + vi.runOnlyPendingTimers() val -= 2 wrapper.find('.control.minus button').trigger('mouseup') @@ -119,16 +121,16 @@ describe('BNumberinput', () => { await wrapper.setProps({ longPress: false }) - jest.useFakeTimers() + vi.useFakeTimers() wrapper.vm.computedValue = 0 // Increment wrapper.find('.control.plus button').trigger('mousedown') // await wait(2000) - jest.runOnlyPendingTimers() - jest.runOnlyPendingTimers() - jest.runOnlyPendingTimers() + vi.runOnlyPendingTimers() + vi.runOnlyPendingTimers() + vi.runOnlyPendingTimers() wrapper.find('.control.plus').trigger('mouseup') expect(wrapper.vm.computedValue).toBe(1) @@ -136,8 +138,8 @@ describe('BNumberinput', () => { // Decrement wrapper.find('.control.minus button').trigger('mousedown') - jest.runOnlyPendingTimers() - jest.runOnlyPendingTimers() + vi.runOnlyPendingTimers() + vi.runOnlyPendingTimers() wrapper.find('.control.minus button').trigger('mouseup') // Trigger it another time to check for unexpected browser behavior @@ -172,7 +174,7 @@ describe('BNumberinput', () => { expect(wrapper.find('input').element.checkValidity()).toEqual(true) await wrapper.setProps({ step: 'any', modelValue: 1 }) expect(wrapper.find('input').element.checkValidity()).toEqual(true) - await wrapper.setProps({ step: 'any', modelValue: '' }) // produces a warning + await wrapper.setProps({ step: 'any', modelValue: null }) expect(wrapper.find('input').element.checkValidity()).toEqual(true) }) }) diff --git a/packages/buefy-next/src/components/numberinput/Numberinput.vue b/packages/buefy-next/src/components/numberinput/Numberinput.vue index 88ca532c1..9ce343409 100644 --- a/packages/buefy-next/src/components/numberinput/Numberinput.vue +++ b/packages/buefy-next/src/components/numberinput/Numberinput.vue @@ -56,8 +56,8 @@ :expanded="expanded" :placeholder="placeholder" :use-html5-validation="useHtml5Validation" - @focus="$emit('focus', $event)" - @blur="$emit('blur', $event)" + @focus="$emit('focus', $event!)" + @blur="$emit('blur', $event!)" />

- diff --git a/packages/buefy-next/src/components/numberinput/index.js b/packages/buefy-next/src/components/numberinput/index.ts similarity index 81% rename from packages/buefy-next/src/components/numberinput/index.js rename to packages/buefy-next/src/components/numberinput/index.ts index 5d1d99141..c2ef5a73c 100644 --- a/packages/buefy-next/src/components/numberinput/index.js +++ b/packages/buefy-next/src/components/numberinput/index.ts @@ -1,9 +1,10 @@ +import type { App } from 'vue' import Numberinput from './Numberinput.vue' import { registerComponent } from '../../utils/plugins' const Plugin = { - install(Vue) { + install(Vue: App) { registerComponent(Vue, Numberinput) } } diff --git a/packages/buefy-next/src/utils/color.spec.js b/packages/buefy-next/src/utils/color.spec.ts similarity index 97% rename from packages/buefy-next/src/utils/color.spec.js rename to packages/buefy-next/src/utils/color.spec.ts index ecc086de4..effe819fc 100644 --- a/packages/buefy-next/src/utils/color.spec.js +++ b/packages/buefy-next/src/utils/color.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest' import Color from '@utils/color' describe('Color', () => { diff --git a/packages/buefy-next/src/utils/color.js b/packages/buefy-next/src/utils/color.ts similarity index 76% rename from packages/buefy-next/src/utils/color.js rename to packages/buefy-next/src/utils/color.ts index 10ad313bd..7d8def072 100644 --- a/packages/buefy-next/src/utils/color.js +++ b/packages/buefy-next/src/utils/color.ts @@ -1,4 +1,21 @@ -export const colorChannels = ['red', 'green', 'blue', 'alpha'] +export const colorChannels = ['red', 'green', 'blue', 'alpha'] as const +export type ColorChannel = typeof colorChannels[number] + +export type Rgba = { + [C in ColorChannel]: number +} +export type Rgb = Omit + +export const hslChannels = ['hue', 'saturation', 'lightness'] as const +export type HslChannel = typeof hslChannels[number] +export type CapitalizedHslChannel = Capitalize + +export type Hsla = { + [C in HslChannel]: number +} +export type Hsl = Omit + +type ChannelTuple = [number, number, number, number] export const colorsNammed = { transparent: '#00000000', @@ -150,7 +167,9 @@ export const colorsNammed = { whitesmoke: '#f5f5f5', yellowgreen: '#9acd32', rebeccapurple: '#663399' -} +} as const + +export type ColorName = keyof typeof colorsNammed export class ColorTypeError extends Error { constructor() { @@ -159,46 +178,91 @@ export class ColorTypeError extends Error { } class Color { - constructor(...args) { + // @ts-expect-error - TypeScript failed to inter the initialization of this property + $channels: Uint8Array + + // Since getters and setters for the color channels, e.g., "alpha", are + // dynamically defined with `Object.defineProperty` in the constructor, we + // cannot write property declarations inside the class body. Instead, we + // augment the `Color` class with an ambient module declared in `color.ts`. + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + constructor(...args: any[]) { if (args.length > 0) { return Color.parse(...args) } this.$channels = new Uint8Array(colorChannels.length) - colorChannels.forEach((channel, index) => { - Object.defineProperty( - this, - channel, - { - get: () => this.$channels[index], - set: (byte) => { - if (!Number.isNaN(byte / 1)) { - this.$channels[index] = Math.min(255, Math.max(0, byte)) - } - }, - enumerable: true, - configurable: true - } - ) - }) - // Required for observability - ;['hue', 'saturation', 'lightness'].forEach((name) => { - const capitalizedName = name.replace(/^./, (m) => m.toUpperCase()) - Object.defineProperty( - this, - name, - { - get: () => this[`get${capitalizedName}`](), - set: (value) => { - if (!Number.isNaN(value / 1)) { - this[`set${capitalizedName}`](value) - } - }, - enumerable: true, - configurable: true - } - ) - }) + } + + get red(): number { + return this.$channels[0] + } + + set red(byte: number) { + if (!Number.isNaN(byte / 1)) { + this.$channels[0] = Math.min(255, Math.max(0, byte)) + } + } + + get green(): number { + return this.$channels[1] + } + + set green(byte: number) { + if (!Number.isNaN(byte / 1)) { + this.$channels[1] = Math.min(255, Math.max(0, byte)) + } + } + + get blue(): number { + return this.$channels[2] + } + + set blue(byte: number) { + if (!Number.isNaN(byte / 1)) { + this.$channels[2] = Math.min(255, Math.max(0, byte)) + } + } + + get alpha(): number { + return this.$channels[3] + } + + set alpha(byte: number) { + if (!Number.isNaN(byte / 1)) { + this.$channels[3] = Math.min(255, Math.max(0, byte)) + } + } + + get hue(): number { + return this.getHue() + } + + set hue(value: number) { + if (!Number.isNaN(value / 1)) { + this.setHue(value) + } + } + + get saturation(): number { + return this.getSaturation() + } + + set saturation(value: number) { + if (!Number.isNaN(value / 1)) { + this.setSaturation(value) + } + } + + get lightness(): number { + return this.getLightness() + } + + set lightness(value: number) { + if (!Number.isNaN(value / 1)) { + this.setLightness(value) + } } getHue() { @@ -225,7 +289,7 @@ class Color { return Math.round(hue % 360) } - setHue(value) { + setHue(value: number) { const color = Color.fromHSL(value, this.saturation, this.lightness, this.alpha / 255) for (let i = 0; i < this.$channels.length; i++) { this.$channels[i] = Number(color.$channels[i]) @@ -242,7 +306,7 @@ class Color { : 0 } - setSaturation(value) { + setSaturation(value: number) { const color = Color.fromHSL(this.hue, value, this.lightness, this.alpha / 255) colorChannels.forEach((_, i) => (this.$channels[i] = color.$channels[i])) } @@ -254,7 +318,7 @@ class Color { return Math.round((max + min) / 2 * 100) / 100 } - setLightness(value) { + setLightness(value: number) { const color = Color.fromHSL(this.hue, this.lightness, value, this.alpha / 255) colorChannels.forEach((_, i) => (this.$channels[i] = color.$channels[i])) } @@ -289,11 +353,12 @@ class Color { } } - get [Symbol.toString]() { + get [Symbol.toStringTag]() { return this.toString('hex') } - static parse(...args) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static parse(...args: any[]): Color { if (typeof args[0] === 'object') { return Color.parseObject(args[0]) } else if (args.every((arg) => !Number.isNaN(arg / 1))) { @@ -314,8 +379,8 @@ class Color { } else if (typeof args[0] === 'string') { let match = null - if (typeof colorsNammed[args[0].toLowerCase()] === 'string') { - return Color.parseHex(colorsNammed[args[0].toLowerCase()]) + if (typeof colorsNammed[args[0].toLowerCase() as ColorName] === 'string') { + return Color.parseHex(colorsNammed[args[0].toLowerCase() as ColorName]) } else if ((match = args[0].match(/^(#|&h|0x)?(([a-f0-9]{3,4}){1,2})$/i)) !== null) { return Color.parseHex(match[2]) } else if ((match = args[0].match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(\s*,\s*(\d*\.?\d+))?\s*\)$/i)) !== null) { @@ -328,7 +393,7 @@ class Color { : 1 ] - return Color.fromRGB(...channels.map((value) => Number(value))) + return Color.fromRGB(...(channels.map((value) => Number(value)) as ChannelTuple)) } else if ((args[0].match(/^(h(sl|wb)a?|lab|color|cmyk)\(/i))) { throw new Error('Color expression not implemented yet') } @@ -337,7 +402,7 @@ class Color { throw new Error('Invalid color expression') } - static parseObject(object) { + static parseObject(object: unknown) { const color = new Color() if (object === null || typeof object !== 'object') { @@ -348,15 +413,15 @@ class Color { } colorChannels.forEach((channel) => { - if (!Number.isNaN(object[channel])) { - color[channel] = object[channel] + if (!Number.isNaN((object as Rgba)[channel])) { + color[channel] = (object as Rgba)[channel] } }) return color } - static parseHex(hex) { + static parseHex(hex: string) { if (typeof hex !== 'string') { throw new Error('Hex expression must be a string') } @@ -378,10 +443,10 @@ class Color { if (typeof chans[3] === 'number') { chans[3] /= 255 } - return Color.fromRGB(...chans) + return Color.fromRGB(...(chans as ChannelTuple)) } - static parseIndex(value, channels = 3) { + static parseIndex(value: number, channels: number = 3) { const color = new Color() for (let i = 0; i < 4; i++) { @@ -391,7 +456,7 @@ class Color { return color } - static fromRGB(red, green, blue, alpha = 1) { + static fromRGB(red: number, green: number, blue: number, alpha: number = 1) { if ([red, green, blue, alpha].some((arg) => Number.isNaN(arg / 1))) { throw new Error('Invalid arguments') } @@ -405,7 +470,7 @@ class Color { return color } - static fromHSL(hue, saturation, lightness, alpha = 1) { + static fromHSL(hue: number, saturation: number, lightness: number, alpha: number = 1) { if ([hue, saturation, lightness, alpha].some((arg) => Number.isNaN(arg))) { throw new Error('Invalid arguments') } @@ -434,7 +499,7 @@ class Color { return Color.fromRGB((r + m) * 255, (g + m) * 255, (b + m) * 255, alpha) } - static isColor(arg) { + static isColor(arg: unknown): arg is Color { return arg instanceof Color } } diff --git a/packages/docs/src/pages/components/autocomplete/Autocomplete.vue b/packages/docs/src/pages/components/autocomplete/Autocomplete.vue index e288d3f99..08aeff61b 100644 --- a/packages/docs/src/pages/components/autocomplete/Autocomplete.vue +++ b/packages/docs/src/pages/components/autocomplete/Autocomplete.vue @@ -86,36 +86,47 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/api/autocomplete.js b/packages/docs/src/pages/components/autocomplete/api/autocomplete.ts similarity index 100% rename from packages/docs/src/pages/components/autocomplete/api/autocomplete.js rename to packages/docs/src/pages/components/autocomplete/api/autocomplete.ts diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExCustomAsync.vue b/packages/docs/src/pages/components/autocomplete/examples/ExCustomAsync.vue index 02777ca41..354b89ca8 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExCustomAsync.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExCustomAsync.vue @@ -8,7 +8,7 @@ field="title" :loading="isFetching" @typing="getAsyncData" - @select="option => selected = option"> + @select="(option: DataItem) => selected = option"> - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExFooter.vue b/packages/docs/src/pages/components/autocomplete/examples/ExFooter.vue index 8aa27e8db..f19472b73 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExFooter.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExFooter.vue @@ -26,8 +26,18 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExGroups.vue b/packages/docs/src/pages/components/autocomplete/examples/ExGroups.vue index 5ffc6f116..8ddfeec03 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExGroups.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExGroups.vue @@ -14,9 +14,20 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExHeader.vue b/packages/docs/src/pages/components/autocomplete/examples/ExHeader.vue index 2826c7aef..4dc6bd986 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExHeader.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExHeader.vue @@ -39,8 +39,18 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExInfiniteScroll.vue b/packages/docs/src/pages/components/autocomplete/examples/ExInfiniteScroll.vue index a1e43fd67..d71aa88d7 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExInfiniteScroll.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExInfiniteScroll.vue @@ -9,7 +9,7 @@ :loading="isFetching" :check-infinite-scroll="true" @typing="getAsyncData" - @select="option => selected = option" + @select="(option: DataItem) => selected = option" @infinite-scroll="getMoreAsyncData"> - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExKeepFirst.vue b/packages/docs/src/pages/components/autocomplete/examples/ExKeepFirst.vue index 0c908b296..c70e3a0a8 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExKeepFirst.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExKeepFirst.vue @@ -23,8 +23,16 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExObjArray.vue b/packages/docs/src/pages/components/autocomplete/examples/ExObjArray.vue index f75dd0333..424dedd50 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExObjArray.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExObjArray.vue @@ -34,10 +34,18 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/examples/ExSimple.vue b/packages/docs/src/pages/components/autocomplete/examples/ExSimple.vue index edf7f4550..4954b1637 100644 --- a/packages/docs/src/pages/components/autocomplete/examples/ExSimple.vue +++ b/packages/docs/src/pages/components/autocomplete/examples/ExSimple.vue @@ -16,8 +16,15 @@ - diff --git a/packages/docs/src/pages/components/autocomplete/variables/autocomplete.js b/packages/docs/src/pages/components/autocomplete/variables/autocomplete.ts similarity index 100% rename from packages/docs/src/pages/components/autocomplete/variables/autocomplete.js rename to packages/docs/src/pages/components/autocomplete/variables/autocomplete.ts diff --git a/packages/docs/src/pages/components/colorpicker/Colorpicker.vue b/packages/docs/src/pages/components/colorpicker/Colorpicker.vue index 757e00192..fd9476d97 100644 --- a/packages/docs/src/pages/components/colorpicker/Colorpicker.vue +++ b/packages/docs/src/pages/components/colorpicker/Colorpicker.vue @@ -15,27 +15,38 @@ - diff --git a/packages/docs/src/pages/components/colorpicker/api/colorpicker.js b/packages/docs/src/pages/components/colorpicker/api/colorpicker.ts similarity index 100% rename from packages/docs/src/pages/components/colorpicker/api/colorpicker.js rename to packages/docs/src/pages/components/colorpicker/api/colorpicker.ts diff --git a/packages/docs/src/pages/components/colorpicker/examples/ExAlpha.vue b/packages/docs/src/pages/components/colorpicker/examples/ExAlpha.vue index 56da327be..b6763bd2d 100644 --- a/packages/docs/src/pages/components/colorpicker/examples/ExAlpha.vue +++ b/packages/docs/src/pages/components/colorpicker/examples/ExAlpha.vue @@ -11,10 +11,16 @@ - diff --git a/packages/docs/src/pages/components/colorpicker/examples/ExFields.vue b/packages/docs/src/pages/components/colorpicker/examples/ExFields.vue index 157011e1d..1fe8037af 100644 --- a/packages/docs/src/pages/components/colorpicker/examples/ExFields.vue +++ b/packages/docs/src/pages/components/colorpicker/examples/ExFields.vue @@ -90,10 +90,17 @@ - diff --git a/packages/docs/src/pages/components/colorpicker/examples/ExFormatter.vue b/packages/docs/src/pages/components/colorpicker/examples/ExFormatter.vue index cee61376e..e223d0c66 100644 --- a/packages/docs/src/pages/components/colorpicker/examples/ExFormatter.vue +++ b/packages/docs/src/pages/components/colorpicker/examples/ExFormatter.vue @@ -21,10 +21,11 @@ - diff --git a/packages/docs/src/pages/components/colorpicker/examples/ExRepresentation.vue b/packages/docs/src/pages/components/colorpicker/examples/ExRepresentation.vue index 9ab775b11..911997a80 100644 --- a/packages/docs/src/pages/components/colorpicker/examples/ExRepresentation.vue +++ b/packages/docs/src/pages/components/colorpicker/examples/ExRepresentation.vue @@ -6,14 +6,15 @@ - diff --git a/packages/docs/src/pages/components/colorpicker/examples/ExSimple.vue b/packages/docs/src/pages/components/colorpicker/examples/ExSimple.vue index 7b5fec330..84e2a3885 100644 --- a/packages/docs/src/pages/components/colorpicker/examples/ExSimple.vue +++ b/packages/docs/src/pages/components/colorpicker/examples/ExSimple.vue @@ -5,3 +5,7 @@ + + diff --git a/packages/docs/src/pages/components/colorpicker/variables/colorpicker.js b/packages/docs/src/pages/components/colorpicker/variables/colorpicker.ts similarity index 100% rename from packages/docs/src/pages/components/colorpicker/variables/colorpicker.js rename to packages/docs/src/pages/components/colorpicker/variables/colorpicker.ts diff --git a/packages/docs/src/pages/components/numberinput/Numberinput.vue b/packages/docs/src/pages/components/numberinput/Numberinput.vue index ec3c55520..61766fa89 100644 --- a/packages/docs/src/pages/components/numberinput/Numberinput.vue +++ b/packages/docs/src/pages/components/numberinput/Numberinput.vue @@ -23,35 +23,44 @@ - diff --git a/packages/docs/src/pages/components/numberinput/api/numberinput.js b/packages/docs/src/pages/components/numberinput/api/numberinput.ts similarity index 100% rename from packages/docs/src/pages/components/numberinput/api/numberinput.js rename to packages/docs/src/pages/components/numberinput/api/numberinput.ts diff --git a/packages/docs/src/pages/components/numberinput/examples/ExAlignment.vue b/packages/docs/src/pages/components/numberinput/examples/ExAlignment.vue index ac50f4dfa..8532b8b8c 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExAlignment.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExAlignment.vue @@ -25,3 +25,7 @@ + + diff --git a/packages/docs/src/pages/components/numberinput/examples/ExCustomize.vue b/packages/docs/src/pages/components/numberinput/examples/ExCustomize.vue index 9d94012d8..09874f755 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExCustomize.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExCustomize.vue @@ -62,3 +62,7 @@ + + diff --git a/packages/docs/src/pages/components/numberinput/examples/ExExpon.vue b/packages/docs/src/pages/components/numberinput/examples/ExExpon.vue index 045179e2e..767e20002 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExExpon.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExExpon.vue @@ -11,3 +11,7 @@ + + diff --git a/packages/docs/src/pages/components/numberinput/examples/ExRange.vue b/packages/docs/src/pages/components/numberinput/examples/ExRange.vue index 6a03d0a52..f1574534e 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExRange.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExRange.vue @@ -11,3 +11,7 @@ + + diff --git a/packages/docs/src/pages/components/numberinput/examples/ExSimple.vue b/packages/docs/src/pages/components/numberinput/examples/ExSimple.vue index 2a7084ec8..ddfd84c0c 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExSimple.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExSimple.vue @@ -34,13 +34,20 @@ - diff --git a/packages/docs/src/pages/components/numberinput/examples/ExSizes.vue b/packages/docs/src/pages/components/numberinput/examples/ExSizes.vue index a9881efeb..e3ecb3f6a 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExSizes.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExSizes.vue @@ -21,3 +21,7 @@ + + diff --git a/packages/docs/src/pages/components/numberinput/examples/ExStep.vue b/packages/docs/src/pages/components/numberinput/examples/ExStep.vue index 42c7323bb..b7c5bde65 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExStep.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExStep.vue @@ -26,3 +26,7 @@ + + diff --git a/packages/docs/src/pages/components/numberinput/examples/ExTypes.vue b/packages/docs/src/pages/components/numberinput/examples/ExTypes.vue index 91205406f..9cd031507 100644 --- a/packages/docs/src/pages/components/numberinput/examples/ExTypes.vue +++ b/packages/docs/src/pages/components/numberinput/examples/ExTypes.vue @@ -29,3 +29,7 @@ + +