chore: format all frontend files (#430)

This commit is contained in:
tecvan
2025-07-31 23:15:48 +08:00
committed by GitHub
parent 8b078ff013
commit 6995cec404
8787 changed files with 11975 additions and 10924 deletions

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default as useHover } from './use-hover';
export { default as usePersistCallback } from './use-persist-callback';
export { default as useUpdateEffect } from './use-update-effect';

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { renderHook, act } from '@testing-library/react-hooks';
import useBoolean from '../index';

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useState, useMemo } from 'react';
export interface ReturnValue {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { act, renderHook } from '@testing-library/react-hooks';
import useHover from '../index';

View File

@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {type DependencyList} from 'react';
import { type DependencyList } from 'react';
import type React from 'react';
import { useState, useCallback, useRef, useLayoutEffect } from 'react';
interface Options {
onEnter?: () => void
onLeave?: () => void
onEnter?: () => void;
onLeave?: () => void;
}
const useHover = <T extends HTMLElement = any>(
@@ -28,25 +28,31 @@ const useHover = <T extends HTMLElement = any>(
options: Options = {},
deps: DependencyList = [],
): [React.MutableRefObject<T>, boolean] => {
const { onEnter, onLeave } = options
const { onEnter, onLeave } = options;
const ref = useRef<T>();
const [isHovered, setIsHovered] = useState(false);
const handleMouseEnter = useCallback(() => {
if (onEnter) {onEnter()}
setIsHovered(true)
}, [typeof onEnter === 'function']);
if (onEnter) {
onEnter();
}
setIsHovered(true);
}, [typeof onEnter === 'function']);
const handleMouseLeave = useCallback(() => {
if (onLeave) {onLeave()}
setIsHovered(false)
}, [typeof onLeave === 'function']);
if (onLeave) {
onLeave();
}
setIsHovered(false);
}, [typeof onLeave === 'function']);
useLayoutEffect(() => {
let target = ref.current
let target = ref.current;
if (el) {
target = typeof el === 'function' ? el() : el;
}
if (!target) {return}
if (!target) {
return;
}
target.addEventListener('mouseenter', handleMouseEnter);
target.addEventListener('mouseleave', handleMouseLeave);
return () => {

View File

@@ -13,8 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { act, renderHook, type RenderHookResult } from '@testing-library/react-hooks';
import {
act,
renderHook,
type RenderHookResult,
} from '@testing-library/react-hooks';
import { useState } from 'react';
import usePersistCallback from '..';

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useRef, useCallback, useMemo } from 'react';
function usePersistCallback<T extends (...args: any[]) => any>(fn?: T) {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
import { act, renderHook } from '@testing-library/react-hooks';
import useStateRealtime from '../index';

View File

@@ -13,24 +13,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useState, useRef, type Dispatch, type SetStateAction, useCallback } from 'react';
import {
useState,
useRef,
type Dispatch,
type SetStateAction,
useCallback,
} from 'react';
const isFunction = (val: any): val is Function => typeof val === 'function';
// Get a new state value, compatible with passing values and functions
function getStateVal<T>(preState: T, initVal?: SetStateAction<T>): T | undefined {
function getStateVal<T>(
preState: T,
initVal?: SetStateAction<T>,
): T | undefined {
if (isFunction(initVal)) {
return initVal(preState);
}
return initVal;
}
function useStateRealtime<T>(initialState: T | (() => T)): [T, Dispatch<SetStateAction<T>>, () => T]
function useStateRealtime<T = undefined>(): [T | undefined, Dispatch<SetStateAction<T | undefined>>, () => T | undefined]
function useStateRealtime<T>(
initialState: T | (() => T),
): [T, Dispatch<SetStateAction<T>>, () => T];
function useStateRealtime<T = undefined>(): [
T | undefined,
Dispatch<SetStateAction<T | undefined>>,
() => T | undefined,
];
function useStateRealtime<T>(
initVal?: T | (() => T),
): [T | undefined, Dispatch<SetStateAction<T | undefined>>, () => T | undefined] {
): [
T | undefined,
Dispatch<SetStateAction<T | undefined>>,
() => T | undefined,
] {
const initState = getStateVal(undefined, initVal);
const [val, setVal] = useState(initState);
const valRef = useRef(initState);
@@ -38,8 +57,8 @@ function useStateRealtime<T>(
const newState = getStateVal(valRef.current, newVal);
valRef.current = newState;
setVal(newState);
}, [])
const getRealState = useCallback(() => valRef.current, [])
}, []);
const getRealState = useCallback(() => valRef.current, []);
return [val, setState, getRealState];
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { act, renderHook } from '@testing-library/react-hooks';
import useToggle from '../index';

View File

@@ -13,50 +13,52 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useState, useMemo } from 'react'
type State = any
import { useState, useMemo } from 'react';
type State = any;
export interface ReturnValue<T = State> {
state: T;
toggle: (value?: T) => void;
}
function useToggle<T = boolean>(): ReturnValue<T>
function useToggle<T = boolean>(): ReturnValue<T>;
function useToggle<T = State>(defaultValue: T): ReturnValue<T>
function useToggle<T = State>(defaultValue: T): ReturnValue<T>;
function useToggle<T = State, U = State>(
defaultValue: T,
reverseValue: U,
): ReturnValue<T | U>
): ReturnValue<T | U>;
function useToggle<D extends State = State, R extends State = State>(
defaultValue: D = false as D,
reverseValue?: R,
) {
const [state, setState] = useState<D | R>(defaultValue)
const [state, setState] = useState<D | R>(defaultValue);
const actions = useMemo(() => {
const reverseValueOrigin = (reverseValue === undefined ? !defaultValue : reverseValue) as D | R
const reverseValueOrigin = (
reverseValue === undefined ? !defaultValue : reverseValue
) as D | R;
const toggle = (value?: D | R) => {
if (value !== undefined) {
setState(value)
return
setState(value);
return;
}
setState((s) => (s === defaultValue ? reverseValueOrigin : defaultValue))
}
setState(s => (s === defaultValue ? reverseValueOrigin : defaultValue));
};
return {
toggle,
}
}, [defaultValue, reverseValue])
};
}, [defaultValue, reverseValue]);
return {
state,
...actions,
}
};
}
export default useToggle
export default useToggle;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { renderHook } from '@testing-library/react-hooks';
import useUpdateEffect from '../index';

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useEffect, useRef } from 'react';
const useUpdateEffect: typeof useEffect = (effect, deps) => {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
useEffect,
useState,

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({