Skip to content

Commit e1d8859

Browse files
brc-ddCopilothaoqunjiang
authored
feat: rewrite validators and tests (#648)
--------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
1 parent 36c44ba commit e1d8859

163 files changed

Lines changed: 3517 additions & 2746 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ declare module 'v-calendar' {
77
export * from 'v-calendar/dist/types/src/index.d.ts'
88
export { default } from 'v-calendar/dist/types/src/index.d.ts'
99
}
10+
11+
interface NumberConstructor {
12+
isFinite(value: unknown): value is number
13+
isInteger(value: unknown): value is number
14+
}

lib/components/SButton.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const hasTooltip = computed(() => {
9494
)
9595
})
9696
97-
function handleClick(): void {
97+
function onClick(): void {
9898
if (!props.loading) {
9999
props.disabled ? emit('disabled-click') : emit('click')
100100
}
@@ -119,7 +119,7 @@ function handleClick(): void {
119119
:class="classes"
120120
:href
121121
role="button"
122-
@click="handleClick"
122+
@click="onClick"
123123
>
124124
<span class="content">
125125
<span v-if="_leadIcon" class="icon" :class="iconMode">

lib/components/SDropdownSectionFilter.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function focusNext(event: any) {
6161
event.target.parentNode.nextElementSibling?.firstElementChild?.focus()
6262
}
6363
64-
function handleClick(option: DropdownSectionFilterOption, value: any) {
64+
function onClick(option: DropdownSectionFilterOption, value: any) {
6565
option.onClick && option.onClick(value)
6666
props.onClick && props.onClick(value)
6767
}
@@ -81,7 +81,7 @@ function handleClick(option: DropdownSectionFilterOption, value: any) {
8181
tabindex="0"
8282
@keyup.up.prevent="focusPrev"
8383
@keyup.down.prevent="focusNext"
84-
@click="handleClick(option, option.value)"
84+
@click="onClick(option, option.value)"
8585
>
8686
<span v-if="Array.isArray(unref(selected))" class="checkbox">
8787
<span class="checkbox-box">

lib/components/SInputAddon.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
useManualDropdownPosition
88
} from '../composables/Dropdown'
99
import { useFlyout } from '../composables/Flyout'
10-
import { isString } from '../support/Utils'
1110
import SDropdown from './SDropdown.vue'
1211
1312
const props = withDefaults(defineProps<{
@@ -44,19 +43,19 @@ const selectedOptionLabel = computed(() => {
4443
const { isOpen, open } = useFlyout(container)
4544
const { position, update: updatePosition } = useManualDropdownPosition(container)
4645
47-
function handleFocus() {
46+
function onFocus() {
4847
if (!props.disabled) {
4948
isFocused.value = true
5049
}
5150
}
5251
53-
function handleBlur() {
52+
function onBlur() {
5453
if (!props.disabled) {
5554
isFocused.value = false
5655
}
5756
}
5857
59-
function handleClickButton() {
58+
function onClickButton() {
6059
if (!props.disabled) {
6160
emit('click')
6261
@@ -74,14 +73,14 @@ function handleClickButton() {
7473
:is="clickable ? 'button' : 'div'"
7574
class="action"
7675
:disabled="clickable ? props.disabled : null"
77-
@focus="handleFocus"
78-
@blur="handleBlur"
79-
@click="handleClickButton"
76+
@focus="onFocus"
77+
@blur="onBlur"
78+
@click="onClickButton"
8079
>
8180
<span class="action-label">
8281
<component
8382
:is="props.label"
84-
v-if="props.label && !isString(props.label)"
83+
v-if="props.label && (typeof props.label !== 'string')"
8584
class="action-icon"
8685
/>
8786
<span v-else>

lib/components/SInputCheckboxes.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function isChecked(value: Value): boolean {
5252
return _value.value.includes(value)
5353
}
5454
55-
function handleChange(value: Value): void {
55+
function onChange(value: Value): void {
5656
const distinct = _value.value
5757
.filter((v) => v !== value)
5858
.concat(_value.value.includes(value) ? [] : [value])
@@ -88,7 +88,7 @@ function handleChange(value: Value): void {
8888
:text="option.label"
8989
:disabled="option.disabled ?? disabled"
9090
:model-value="isChecked(option.value)"
91-
@update:model-value="handleChange(option.value)"
91+
@update:model-value="onChange(option.value)"
9292
/>
9393
</div>
9494
</div>

lib/components/SInputDate.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function emitInput(date?: string) {
4141
emit('update:model-value', date ? day(date) : null)
4242
}
4343
44-
function emitBlur() {
44+
function onBlur() {
4545
setTimeout(() => {
4646
props.validation && props.validation.$touch()
4747
}, 100)
@@ -86,7 +86,7 @@ function emitBlur() {
8686
:disabled
8787
:tabindex
8888
v-on="disabled ? {} : inputEvents"
89-
@blur="emitBlur"
89+
@blur="onBlur"
9090
>
9191
</DatePicker>
9292
</div>

lib/components/SInputDropdownItem.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ defineEmits<{
3838
<template>
3939
<div class="SInputDropdownItem" :class="[size, { disabled }]">
4040
<div v-if="Array.isArray(item)" class="many">
41-
<template v-for="(item, i) in item" :key="i">
42-
<div v-if="item.type === undefined || item.type === 'text'" class="many-text">
43-
<div class="many-text-value">{{ item.label }}</div>
41+
<template v-for="(el, i) in item" :key="i">
42+
<div v-if="el.type === undefined || el.type === 'text'" class="many-text">
43+
<div class="many-text-value">{{ el.label }}</div>
4444
<button
4545
v-if="removable"
4646
class="many-text-close"
47-
@click.stop="$emit('remove', item.value)"
47+
@click.stop="$emit('remove', el.value)"
4848
>
4949
<IconX class="many-text-close-icon" />
5050
</button>
5151
</div>
52-
<div v-else-if="item.type === 'avatar'" class="many-avatar">
52+
<div v-else-if="el.type === 'avatar'" class="many-avatar">
5353
<div class="many-avatar-body">
54-
<div class="many-avatar-image"><SAvatar size="fill" :avatar="item.image" /></div>
55-
<div class="many-avatar-name">{{ item.label }}</div>
54+
<div class="many-avatar-image"><SAvatar size="fill" :avatar="el.image" /></div>
55+
<div class="many-avatar-name">{{ el.label }}</div>
5656
</div>
5757
<button
5858
v-if="removable"
5959
class="many-avatar-close"
60-
@click.stop="$emit('remove', item.value)"
60+
@click.stop="$emit('remove', el.value)"
6161
>
6262
<IconX class="many-avatar-close-icon" />
6363
</button>

lib/components/SInputNumber.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script setup lang="ts">
22
import { computed } from 'vue'
3-
import { isString } from '../support/Utils'
43
import { type Props as BaseProps } from './SInputBase.vue'
54
import SInputText from './SInputText.vue'
65
@@ -41,7 +40,7 @@ const _textColor = computed(() => {
4140
return 'neutral'
4241
}
4342
44-
if (isString(props.textColor)) {
43+
if (typeof props.textColor === 'string') {
4544
return props.textColor
4645
}
4746

lib/components/SInputSwitches.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function isChecked(value: any): boolean {
4040
return props.modelValue.includes(value)
4141
}
4242
43-
function handleChange(value: any): void {
43+
function onChange(value: any): void {
4444
const difference = props.modelValue
4545
.filter((v) => v !== value)
4646
.concat(props.modelValue.includes(value) ? [] : [value])
@@ -71,7 +71,7 @@ function handleChange(value: any): void {
7171
size="sm"
7272
:text="option.label"
7373
:model-value="isChecked(option.value)"
74-
@update:model-value="handleChange(option.value)"
74+
@update:model-value="onChange(option.value)"
7575
/>
7676
</div>
7777
</div>

lib/components/SInputText.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script setup lang="ts">
22
import { type Component, computed, ref } from 'vue'
3-
import { isString } from '../support/Utils'
43
import SInputBase, { type Props as BaseProps } from './SInputBase.vue'
54
65
export type { Color, Size } from './SInputBase.vue'
@@ -42,7 +41,7 @@ const textColor = computed(() => {
4241
return 'neutral'
4342
}
4443
45-
if (isString(props.textColor)) {
44+
if (typeof props.textColor === 'string') {
4645
return props.textColor
4746
}
4847
@@ -124,7 +123,7 @@ function getValue(e: Event | FocusEvent | KeyboardEvent): string | null {
124123

125124
<div class="value">
126125
<div v-if="unitBefore" class="unit before">
127-
<span v-if="isString(unitBefore)" class="unit-text">{{ unitBefore }}</span>
126+
<span v-if="typeof unitBefore === 'string'" class="unit-text">{{ unitBefore }}</span>
128127
<component :is="unitBefore" v-else class="unit-icon" />
129128
</div>
130129

@@ -150,7 +149,7 @@ function getValue(e: Event | FocusEvent | KeyboardEvent): string | null {
150149
</div>
151150

152151
<div v-if="unitAfter" class="unit after">
153-
<span v-if="isString(unitAfter)" class="unit-text">{{ unitAfter }}</span>
152+
<span v-if="typeof unitAfter === 'string'" class="unit-text">{{ unitAfter }}</span>
154153
<component :is="unitAfter" v-else class="unit-icon" />
155154
</div>
156155
</div>

0 commit comments

Comments
 (0)