"use client" import { type FC, type ReactNode, createContext, useContext } from "react" import { assign } from "deepsea-tools" export type EmptyValue = "null" | "undefined" export type GetEmptyValue = T extends "undefined" ? undefined : null export function getEmptyValue(value?: T): GetEmptyValue { return (value === "undefined" ? undefined : null) as GetEmptyValue } export interface FormContext { /** * 空值设置,默认是 null */ emptyValue: EmptyValue } export const FormContext = createContext({ emptyValue: "null" }) export interface FormProviderProps extends Partial { children?: ReactNode } export const FormProvider: FC = ({ children, emptyValue }) => { const config = useContext(FormContext) const newConfig = assign(config, { emptyValue }) return {children} }