@formkit/core

介绍

官方的FormKit核心库。该包负责FormKit的大部分内部功能。您可以在formkit.com上阅读有关其工作原理的专门文档。

您可以使用npm install @formkit/coreyarn add @formkit/core来添加此包。

FormKitNode

由createNode()创建的FormKit的节点对象。每个<FormKit />输入都有一个与之关联的FormKitNode(“核心节点”)。所有输入、表单和组都是节点的实例。在架构文档中详细了解核心节点。

add()

向节点添加子节点。节点必须是组或列表。

签名

add: (node: FormKitNode, index?: number) => FormKitNode

参数

  • node — 一个FormKitNode
  • index 可选 — 要添加到的索引。

返回值

添加的FormKitNode

address

当前节点相对于树根的地址。

签名

address: FormKitAddress

返回值

一个FormKitAddress

addProps()

通过从node.props.attrs中删除它们并将它们移动到顶级node.props对象,向给定节点添加props。

签名

addProps: (props: string[]) => FormKitNode

参数

  • props — 要添加为props键的字符串数组。

返回值

FormKitNode

at()

获取另一个地址处的节点。地址是节点名称的点语法路径(或数组)。例如:form.users.0.first_name。还有一些“特殊”的遍历标记:

  • $root — 选择根节点。
  • $parent — 选择父节点。
  • $self — 选择当前节点。

签名

at: (address: FormKitAddress | string) => FormKitNode | undefined

参数

返回值

找到的FormKitNodeundefined

children

子节点(组和列表)的数组。

签名

children: Array<FormKitNode>

返回值

一个FormKitNode的数组。

clearErrors()

清除节点的错误,可选择清除所有子节点的错误。

签名

clearErrors: (clearChildren?: boolean, sourceKey?: string) => FormKitNode

参数

  • clearChildren 可选 — 是否清除子节点。
  • sourceKey 可选 — 用于重置的源键。

返回值

FormKitNode

config

一个FormKitConfig对象,与整个树共享,包含应应用于整个树的各种配置选项。

签名

config: FormKitConfig

返回值

一个FormKitConfig

define()

定义当前输入的库类型定义,包括节点类型、模式和props。

签名

define: (definition: FormKitTypeDefinition) => void

参数

destroy()

从全局注册表和其父节点中删除节点,并触发“destroying”事件。

签名

destroy: () => void

each()

对给定节点的每个子节点执行给定的回调函数。

签名

each: (callback: FormKitChildCallback) => void

参数

emit()

从节点中发出事件,以便可以被on监听。

签名

emit: (event: string, payload?: any, bubble?: boolean) => FormKitNode

参数

  • event — 要发出的事件名称。
  • payload 可选 — 与事件一起传递的值。
  • bubble 可选 — 事件是否应冒泡到父节点。

返回值

FormKitNode

extend()

通过添加可以通过node.{property}()访问的任意属性来扩展FormKitNode

签名

extend: (property: string, trap: FormKitTrap) => FormKitNode

参数

  • property — 要添加到核心节点(node.{property})的属性。
  • trap — 一个具有get和set属性的对象。

返回值

FormKitNode

find()

在给定的树中,查找与给定选择器匹配的节点。选择器可以是简单字符串或函数。

签名

find: (
 selector: string,
 searcher?: keyof FormKitNode | FormKitSearchFunction
) => FormKitNode | undefined

参数

返回值

找到的 FormKitNodeundefined

hook

一组钩子。

签名

hook: FormKitHooks

返回值

FormKitHooks

index

节点相对于其兄弟节点的索引。仅适用于节点是列表的子节点的情况。

签名

index: number

返回值

一个 number

input()

用于设置节点值的函数。所有对节点值的更改都应使用此函数,因为它确保始终完全跟踪树的状态。

签名

input: (value: unknown, async?: boolean) => Promise<unknown>

参数

  • value — 用于节点的任何值。
  • async 可选 — 是否异步进行输入。

返回值

一个 Promise<unknown>

isCreated

初始值为 false,当节点完成创建时设置为 true。

签名

isCreated: boolean

返回值

一个 boolean

isSettled

反映节点及其子树的解决状态的布尔值。

签名

isSettled: boolean

返回值

一个 boolean

ledger

用于任意消息计数的计数分类帐。

签名

ledger: FormKitLedger

返回值

一个 FormKitLedger

name

节点树中输入的名称。当节点是列表的子节点时,它自动成为其索引。

签名

name: string

返回值

一个 string

off()

通过其标记删除事件侦听器。接收器可以在侦听器函数中显式声明“receipt”属性,从而可以在多个事件侦听器之间共享。如果它们共享相同的接收器,则可以使用单个 off() 调用将它们全部取消注册。

签名

off: (receipt: string) => FormKitNode

参数

  • receipt — 由 on 函数生成的接收器。

返回值

一个接收器 string

on()

为给定的事件添加事件侦听器,并返回一个“receipt”,即一个随机字符串标记。此标记应在将来用于删除侦听器。或者,您可以为侦听器函数分配一个“receipt”属性,然后将使用该接收器。如果它们共享相同的接收器,则可以使用单个 off() 调用将它们全部取消注册。

签名

on: (eventName: string, listener: FormKitEventListener) => string

参数

  • eventName — 要监听的事件名称。
  • listener — 当事件发生时要运行的 FormKitEventListener

返回值

一个接收器 string

parent

节点的父节点。

签名

parent: FormKitNode | null

返回值

如果找到则为 FormKitNode,否则为 null

props

代理对象的属性。这些通常由所选适配器提供。

签名

props: Partial<FormKitProps>

返回值

一个可选的 FormKitProps 列表。

remove()

从节点中删除子节点。

签名

remove: (node: FormKitNode) => FormKitNode

参数

返回值

FormKitNode

reset()

将节点的值重置为其原始值。

签名

reset: () => FormKitNode

返回值

FormKitNode

root

检索树的根节点。这是通过按请求进行的树遍历完成的,因此不应在频繁调用的函数中使用。

签名

root: FormKitNode

返回值

FormKitNode

setErrors()

在输入上设置错误,可选择设置子输入的错误。

签名

setErrors: (localErrors: ErrorMessages, childErrors?: ErrorMessages) => void

参数

settled

一个在节点及其整个子树解决时解析的 Promise。换句话说,所有输入都已提交其值。

签名

settled: Promise<unknown>

返回值

一个 Promise<unknown>

store

内部节点存储。

签名

store: FormKitStore

返回值

一个 FormKitStore

submit()

在最近的表单上触发提交事件。

签名

submit: () => void

t()

一个文本或翻译函数,将给定的字符串暴露给“text”钩子。在显示给用户之前,所有文本都应通过此函数传递 - 尤其是对于核心和插件作者。

签名

t: (key: string | FormKitTextFragment) => string

参数

返回值

翻译后的 string

type

节点的类型,只能是 'input'、'list' 或 'group'。

签名

type: FormKitNodeType

返回值

一个 FormKitNodeType

use()

在节点及其子树上注册一个新的插件。

签名

use: (
 plugin: FormKitPlugin | FormKitPlugin[] | Set<FormKitPlugin>,
 run?: boolean,
 library?: boolean
) => FormKitNode

参数

  • plugin — 一个 FormKitPluginFormKitPlugin 的数组或集合。
  • run 可选 — 是否在创建时执行插件。
  • library 可选 — 是否在创建时执行插件的库函数。

返回值

FormKitNode

value

输入的值。不应直接修改此值。任何所需的更改都应通过 input 进行。

签名

readonly value: unknown

walk()

对其子树中的每个节点执行一个函数(不包括节点本身)。这是一个昂贵的操作,因此应该非常少使用,只在相对罕见的生命周期事件(如启动和关闭)中使用。

签名

walk: (callback: FormKitChildCallback, stopOnFalse?: boolean, recurseOnFalse?: boolean) => void

参数

  • callback — 用于每个子节点执行的 FormKitChildCallback
  • stopOnFalse 可选 — 如果返回值为 false,则是否停止执行。

函数

bfs()

在节点子树上执行广度优先搜索,并找到第一个匹配项。

签名

bfs(tree: FormKitNode, searchValue: string | number, searchGoal?: keyof FormKitNode | FormKitSearchFunction): FormKitNode | undefined;

参数

  • tree — 要从中开始的 FormKitNode
  • searchValue — 要搜索的值。
  • searchGoal 可选 — 目标值。

返回值

FormKitNodeundefined

clearErrors()

清除节点及其子节点上的错误。

签名

clearErrors(id: string, clearChildren?: boolean): void;

参数

  • id — 要清除错误的节点的 ID。
  • clearChildren 可选 — 确定是否清除此节点的子节点的错误。

compile()

将逻辑字符串(如 "a != z || b == c")编译为单个函数。返回值是一个具有 "provide" 方法的对象,该方法遍历所有要求标记以用作替换。

签名

compile(expr: string): FormKitCompilerOutput;

参数

  • expr — 要编译的字符串。

返回值

FormKitCompilerOutput

示例

let name = {
  value: 'jon'
}
const condition = compile("$name == 'bob'").provide((token) => {
 return () => name.value // 必须返回一个函数!
})

condition() // false

createClasses()

生成 CSS 类的标准化对象表示形式的函数。

签名

createClasses(propertyKey: string, node: FormKitNode, sectionClassList?: FormKitClasses | string | Record<string, boolean>): Record<string, boolean>;

参数

  • propertyKey — 区块键。
  • node — 一个 FormKitNode
  • sectionClassList 可选 — 一个 string | Record<string, boolean>FormKitClasses

返回值

Record<string, boolean>

createConfig()

创建一个全局配置选项的新实例。该对象本质上只是一个 FormKitOption 对象,但它可以用作 FormKitConfig 的代理根,并保留事件“发射”。

签名

createConfig(options?: Partial<FormKitConfig>): FormKitRootConfig;

参数

返回值

FormKitRootConfig

createMessage()

创建一个新的 FormKitMessage 对象。

签名

createMessage(conf: Partial<FormKitMessage>, node?: FormKitNode): FormKitMessageProps;

参数

返回值

FormKitMessageProps

createNode()

创建一个新的FormKit节点实例。节点是FormKit图的原子单位。

签名

createNode<V = unknown>(options?: FormKitOptions): FormKitNode<V>;

参数

  • options 可选FormKitOptions的选项对象,用于覆盖默认值。

返回值

FormKitNode

示例

import { createNode } from '@formkit/core'

const input = createNode({
  type: 'input', // 如果未指定,默认为 'input'
  value: 'hello node world',
})

console.log(input.value)
// 'hello node world'

createValue()

根据传入的选项和输入的类型创建节点的初始值。

签名

createValue(options: FormKitOptions): unknown;

参数

返回值

unknown

deregister()

从注册表中注销一个节点。

签名

deregister(node: FormKitNode): void;

参数

error()

发出一个错误。通常应该导致异常。

签名

error(code: number, data?: any): never;

参数

  • code — 整数错误代码。
  • data 可选 — 通常是要包含的信息对象。

generateClassList()

将多个类列表合并为一个列表。

签名

generateClassList(node: FormKitNode, property: string, ...args: Record<string, boolean>[]): string | null;

参数

  • nodeFormKitNode
  • property — 要应用类列表的属性键。
  • args — CSS类列表的 Record<string, boolean> 数组。

返回值

string | null

getNode()

通过特定的id获取节点。

签名

getNode(id: string): FormKitNode | undefined;

参数

  • id — 通过给定的id获取节点。

返回值

FormKitNodeundefined

isComponent()

类型缩小,判断节点是否为DOM节点。

签名

isComponent(node: string | Record<PropertyKey, any>): node is FormKitSchemaComponent;

参数

  • node — 要检查的模式节点。

返回值

boolean

isConditional()

确定节点是否有条件地呈现。

签名

isConditional(node: FormKitSchemaNode): node is FormKitSchemaCondition;
isConditional(node: FormKitSchemaAttributesCondition | FormKitSchemaAttributes): node is FormKitSchemaAttributesCondition;

参数

  • node — 要检查的模式节点。

返回值

boolean

isDOM()

类型缩小,判断节点是否为DOM节点。

签名

isDOM(node: string | Record<PropertyKey, any>): node is FormKitSchemaDOMNode;

参数

  • node — 要检查的模式节点。

返回值

boolean

isList()

一个简单的类型保护,用于确定正在评估的上下文是否为列表类型。

签名

isList(arg: FormKitContextShape): arg is FormKitListContext;

参数

返回值

返回一个 boolean

isNode()

确定给定的对象是否为节点。

签名

isNode(node: any): node is FormKitNode;

参数

  • node — 任何值。

返回值

返回一个 boolean

示例

import { isNode, createNode } from '@formkit/core'

const input = createNode({
  type: 'input', // 如果未指定,默认为 'input'
  value: 'hello node world',
})

const obj = {};

isNode(obj)
// false

isNode(input)
// true

isPlaceholder()

确定节点是否为占位符节点。

签名

isPlaceholder(node: FormKitNode | FormKitPlaceholderNode): node is FormKitPlaceholderNode;

参数

返回值

isSugar()

确定节点是否为语法糖。

签名

isSugar(node: FormKitSchemaNode): node is FormKitSchemaFormKit;

参数

  • node — 要检查的模式节点。

返回值

boolean

names()

创建一个基于名称的字典,包含数组中所有子项。

签名

names(children: FormKitNode[]): {
    [index: string]: FormKitNode;
};

参数

返回值

包含命名的 FormKitNode 的字典。

register()

如果节点是根节点,或者节点具有显式的 node.props.alias,则将节点注册到注册表中。如果这两个条件都不满足,则不会注册任何节点(幂等)。

签名

register(node: FormKitNode): void;

参数

reset()

将输入重置为其“初始”值。如果输入是一个组或列表,它也会重置所有子项。

签名

reset(id: string | FormKitNode, resetTo?: unknown): FormKitNode | undefined;

参数

  • id — 要重置的输入的 id。
  • resetTo 可选 — 要将节点重置为的值。

返回值

FormKitNodeundefined

resetCount()

重置节点注册的全局数量,对于确定性节点命名很有用。

签名

resetCount(): void;

resetRegistry()

重置整个注册表。取消注册所有节点并删除所有监听器。

签名

resetRegistry(): void;

setErrors()

在表单、组或输入上设置错误。

签名

setErrors(id: string, localErrors: ErrorMessages, childErrors?: ErrorMessages): void;

参数

  • id — 表单的 id。
  • localErrors — 要在表单或表单的输入上设置的错误,格式为 ErrorMessages
  • childErrors 可选 — (可选)要在表单或表单的输入上设置的错误,格式为 ErrorMessages

submitForm()

以编程方式提交 FormKit 表单。

签名

submitForm(id: string): void;

参数

  • id — 表单的 id。

sugar()

将语法糖节点转换为标准节点。

签名

sugar<T extends FormKitSchemaNode>(node: T): Exclude<FormKitSchemaNode, string | FormKitSchemaFormKit>;

参数

  • node — 要转换的节点。

返回值

不包含 FormKitSchemaFormKit 属性的 FormKitSchemaNode

warn()

全局发出警告。

签名

warn(code: number, data?: any): void;

参数

  • code — 整数警告代码。
  • data 可选 — 通常是要包含的信息对象。

watchRegistry()

以一种监视全局注册表变化的方式。

签名

watchRegistry(id: string, callback: FormKitEventListener): void;

参数

  • id — 节点所在的点语法 id。
  • callback — 格式为 FormKitEventListener 的回调,用于在设置或删除节点时通知。

TypeScript

FormKitChildCallback

节点.each() 的回调类型。

interface FormKitChildCallback {
    (child: FormKitNode): any;
}

FormKitChildValue

子值的描述符,通常通过节点树上传递。

interface FormKitChildValue {
    from?: number | symbol;
    name: string | number | symbol;
    value: any;
}

FormKitClasses

生成 CSS 类的函数的定义。

interface FormKitClasses {
    (node: FormKitNode, sectionKey: string): string | Record<string, boolean>;
}

FormKitCompilerOutput

编译器输出,一个添加所需标记的函数。

interface FormKitCompilerOutput {
    (tokens?: Record<string, any>): boolean | number | string;
    provide: FormKitCompilerProvider;
}

FormKitConfig

通用的“应用程序”配置选项,这些选项会自动继承到所有子项中,它们不是响应式的。

interface FormKitConfig {
    [index: string]: any;
    classes?: Record<string, FormKitClasses | string | Record<string, boolean>>;
    delimiter: string;
    rootClasses: (sectionKey: string, node: FormKitNode) => Record<string, boolean>;
    rootConfig?: FormKitRootConfig;
}

FormKitContext

FormKit 节点的上下文对象接口。FormKit 节点是该对象的代理。

interface FormKitContext {
    _d: number;
    _e: FormKitEventEmitter;
    _resolve: ((value: unknown) => void) | false;
    _tmo: number | false;
    _value: unknown;
    children: Array<FormKitNode | FormKitPlaceholderNode>;
    config: FormKitConfig;
    context?: FormKitFrameworkContext;
    hook: FormKitHooks;
    isCreated: boolean;
    isSettled: boolean;
    ledger: FormKitLedger;
    name: string | symbol;
    parent: FormKitNode | null;
    plugins: Set<FormKitPlugin>;
    props: Partial<FormKitProps>;
    settled: Promise<unknown>;
    store: FormKitStore;
    sync: boolean;
    traps: FormKitTraps;
    type: FormKitNodeType;
    uid: symbol;
    value: unknown;
}

FormKitContextShape

定义用于类型保护的上下文对象的最基本形状。

interface FormKitContextShape {
    _value: unknown;
    type: FormKitNodeType;
    value: unknown;
}

FormKitCounter

用于在树中执行实例计数的计数器对象。

interface FormKitCounter {
    condition: FormKitCounterCondition;
    count: number;
    name: string;
    node: FormKitNode;
    promise: Promise<void>;
    resolve: () => void;
}

FormKitCounterCondition

账本计数器需要一个条件函数来确定给定的消息是否适用于它。

interface FormKitCounterCondition {
    (message: FormKitMessage): boolean;
}

FormKitDispatcher

FormKitDispatcher 接口负责创建/运行 "hooks"。

interface FormKitDispatcher<T> {
    (dispatchable: FormKitMiddleware<T>): number;
    dispatch: (payload: T) => T;
    remove: (dispatchable: FormKitMiddleware<T>) => void;
    unshift: (dispatchable: FormKitMiddleware<T>) => number;
}

FormKitEvent

FormKitEvent 的内部结构。

interface FormKitEvent {
    bubble: boolean;
    name: string;
    origin: FormKitNode;
    payload: any;
}

FormKitEventEmitter

FormKitEventEmitter 的定义。

interface FormKitEventEmitter {
    (node: FormKitNode, event: FormKitEvent): void;
    flush: () => void;
    off: (receipt: string) => void;
    on: (eventName: string, listener: FormKitEventListener) => string;
    pause: (node?: FormKitNode) => void;
    play: (node?: FormKitNode) => void;
}

FormKitEventListener

事件监听器函数的定义。

interface FormKitEventListener {
    (event: FormKitEvent): void;
    receipt?: string;
}

FormKitExtendableSchemaRoot

定义一个函数,允许有选择地覆盖给定的 schema。

interface FormKitExtendableSchemaRoot {
    (extensions: Record<string, Partial<FormKitSchemaNode> | FormKitSchemaCondition>): FormKitSchemaDefinition;
    memoKey?: string;
}

FormKitFrameworkContext

由每个相应的 UI 框架创建和使用的上下文对象。FormKitCore 不创建或输出任何值,但是每个相应的插件应该遵循这个接口。

interface FormKitFrameworkContext {
    _value: any;
    [index: string]: unknown;
    attrs: Record<string, any>;
    classes: Record<string, string>;
    defaultMessagePlacement: boolean;
    fns: Record<string, (...args: any[]) => any>;
    handlers:{
        blur: () => void;
        touch: () => void;
        DOMInput: (e: Event) => void;
    }&Record<string, (...args: any[]) => void>;
    help?: string;
    id: string;
    items: symbol[];
    label?: string;
    messages: Record<string, FormKitMessage>;
    node: FormKitNode;
    options?: Array<Record<string, any>&{
        label: string;
        value: any;
    }>;
    state: FormKitFrameworkContextState;
    type: string;
    value: any;
}

FormKitFrameworkContextState

节点框架上下文中的状态。通常用于跟踪模糊和有效状态等信息。

interface FormKitFrameworkContextState {
    [index: string]: boolean;
    blurred: boolean;
    complete: boolean;
    dirty: boolean;
    errors: boolean;
    rules: boolean;
    settled: boolean;
    submitted: boolean;
    valid: boolean;
    validationVisible: boolean;
}

FormKitGroupValue

FormKit 输入类型为 'group' 的输入必须具有键值。

interface FormKitGroupValue {
    __init?: boolean;
    [index: string]: unknown;
}

FormKitHandlerPayload

描述通过错误和警告处理程序传递的数据。

interface FormKitHandlerPayload {
    code: number;
    data: any;
    message?: string;
}

FormKitHooks

用于中间件的可用 hooks。

interface FormKitHooks {
    classes: FormKitDispatcher<{
        property: string;
        classes: Record<string, boolean>;
    }>;
    commit: FormKitDispatcher<any>;
    error: FormKitDispatcher<string>;
    init: FormKitDispatcher<FormKitNode>;
    input: FormKitDispatcher<any>;
    message: FormKitDispatcher<FormKitMessage>;
    prop: FormKitDispatcher<{
        prop: string | symbol;
        value: any;
    }>;
    schema: FormKitDispatcher<FormKitSchemaNode[] | FormKitSchemaCondition>;
    setErrors: FormKitDispatcher<{
        localErrors: ErrorMessages;
        childErrors?: ErrorMessages;
    }>;
    submit: FormKitDispatcher<Record<string, any>>;
    text: FormKitDispatcher<FormKitTextFragment>;
}

FormKitInputMessages

一个输入消息的注册表,应该应用于传递给它们的节点的子节点,其中对象的字符串键是要应用消息的节点的地址,值是消息本身。

interface FormKitInputMessages {
    [address: string]: FormKitMessage[];
}

FormKitLedger

FormKit分类账,是FormKit核心提供的一个通用计数服务,用于计算整个树中的消息数量。

interface FormKitLedger {
    count: (name: string, condition?: FormKitCounterCondition, increment?: number) => Promise<void>;
    init: (node: FormKitNode) => void;
    merge: (child: FormKitNode) => void;
    settled: (name: string) => Promise<void>;
    unmerge: (child: FormKitNode) => void;
    value: (name: string) => number;
}

FormKitLibrary

一个输入库,以类型名称为键。

interface FormKitLibrary {
    [index: string]: FormKitTypeDefinition;
}

FormKitListContext

类型为"list"的上下文的最简单定义。

interface FormKitListContext {
    _value: FormKitListContextValue;
    type:'list';
    value: FormKitListContextValue;
}

FormKitMessageMeta

消息可以附加任意元数据。

interface FormKitMessageMeta {
    [index: string]: any;
    i18nArgs?: any[];
    messageKey?: string;
}

FormKitMessageProps

核心FormKitMessage的结构。这些消息用于存储节点的状态信息。

interface FormKitMessageProps {
    blocking: boolean;
    key: string;
    meta: FormKitMessageMeta;
    type: string;
    value?: string | number | boolean;
    visible: boolean;
}

FormKitMessageStore

定义实际的消息存储。

interface FormKitMessageStore {
    [index: string]: FormKitMessage;
}

FormKitNodeExtensions

用于添加FormKit节点扩展的空接口。

interface FormKitNodeExtensions {
}

FormKitPlaceholderNode

一种伪节点,在各种节点操作期间用作子节点数组中的占位符。

interface FormKitPlaceholderNode<V = unknown> {
    __FKP: true;
    _value: V;
    input: (value: unknown, async?: boolean) => Promise<unknown>;
    isSettled: boolean;
    name: string;
    type: FormKitNodeType;
    uid: symbol;
    use: (...args: any[]) => void;
    value: V;
}

FormKitPlugin

FormKitPlugin的基本接口定义。它只是一个接受节点参数的函数。

interface FormKitPlugin {
    (node: FormKitNode): false | any | void;
    library?: (node: FormKitNode) => void;
}

FormKitSchemaAttributesCondition

嵌套在属性声明中的条件。

interface FormKitSchemaAttributesCondition {
    else?: FormKitAttributeValue;
    if: string;
    then: FormKitAttributeValue;
}

FormKitSchemaComposable

可以扩展给定模式节点的函数的定义。

interface FormKitSchemaComposable {
    (extendWith?: Partial<FormKitSchemaNode>, children?: string | FormKitSchemaNode[] | FormKitSchemaCondition, ...args: any[]): FormKitSchemaNode;
}

FormKitSchemaContext

从一个模式渲染传递到下一个的上下文。

interface FormKitSchemaContext {
    __FK_SCP: Map<symbol, Record<string, any>>;
    [index: string]: any;
}

FormKitSchemaProps

所有模式节点中可用的属性。

interface FormKitSchemaProps {
    bind?: string;
    children?: string | FormKitSchemaNode[] | FormKitSchemaCondition;
    for?: FormKitListStatement;
    if?: string;
    key?: string;
    meta?: FormKitSchemaMeta;
}

FormKitStoreTraps

FormKit存储中可用的陷阱。

interface FormKitStoreTraps {
    apply: (messages: Array<FormKitMessage> | FormKitInputMessages, clear?: MessageClearer) => void;
    filter: (callback: (message: FormKitMessage) => boolean, type?: string) => FormKitStore;
    reduce:<T>(reducer: (accumulator: T, message: FormKitMessage) => T, accumulator: T) => T;
    release: () => void;
    remove: (key: string) => FormKitStore;
    set: (message: FormKitMessageProps) => FormKitStore;
    touch: () => void;
}

FormKitTrap

FormKitTrap的定义。它们有点像每个FormKitNode上的方法。它们始终是对称的(get/set)- 虽然其中一个抛出异常是可以接受的。

interface FormKitTrap {
    get: TrapGetter;
    set: TrapSetter;
}

KeyedValue

具有属性的任意数据。可以是POJO,也可以是数组。

interface KeyedValue {
    [index: number]: any;
    [index: string]: any;
}

ChildMessageBuffer

由于子节点不存在而未立即应用的子消息。

type ChildMessageBuffer = Map<string, Array<[FormKitMessage[], MessageClearer | undefined]>>;

ErrorMessages

错误消息。

type ErrorMessages = string | string[] | Record<string, string | string[]>;

FormKitAddress

描述从树顶部到特定节点的路径。

type FormKitAddress = Array<string | number>;

FormKitAttributeValue

属性(在模式中)的可能值类型。

type FormKitAttributeValue = string | number | boolean | undefined | FormKitSchemaAttributes | FormKitSchemaAttributesCondition;

FormKitCompilerProvider

接受一个带有令牌作为唯一参数的回调函数,并必须返回一个提供令牌真实值的函数。

type FormKitCompilerProvider = (callback: (requirements: string[]) => Record<string, () => any>) => FormKitCompilerOutput;

FormKitListContextValue

默认情况下,类型为'list'的FormKit输入必须具有数组值。

type FormKitListContextValue<T = any> = Array<T>;

FormKitListStatement

元组语法中的完整循环语句。可以读作“foreach value, key? in list”。

type FormKitListStatement = [value: any, key: number | string, list: FormKitListValue] | [value: any, list: FormKitListValue];

FormKitListValue

正在列出的值。可以是数组、对象或数字。

type FormKitListValue = string | Record<string, any> | Array<string | number | Record<string, any>> | number;

FormKitMessage

FormKit消息是不可变的,因此所有属性都应该是只读的。

type FormKitMessage = Readonly<FormKitMessageProps>;

FormKitMiddleware

所有FormKitMiddleware都符合接受有效载荷和next()函数的模式。它们可以显式地将有效载荷传递给下一个中间件(作为next的参数),也可以隐式地传递(next没有参数)。

type FormKitMiddleware<T = unknown> = (payload: T, next: (payload?: T) => T) => T;

FormKitNodeType

这些是可以创建的节点类型。它们与可用输入类型不同,而是描述它们在树中的目的。

type FormKitNodeType = 'input' | 'list' | 'group';

FormKitOptions

可以使用createNode()实例化新节点的选项。

type FormKitOptions = Partial<Omit<FormKitContext, 'children' | 'plugins' | 'config' | 'hook'> & {
    config: Partial<FormKitConfig>;
    props: Partial<FormKitProps>;
    children: FormKitNode[] | Set<FormKitNode>;
    index?: number;
    sync: boolean;
    plugins: FormKitPlugin[];
    alias: string;
    schemaAlias: string;
}>;

FormKitProps

用户自定义的每个实例的"props",通常类似于在前端组件中传递的props。

type FormKitProps = {
    delay: number;
    id: string;
    validationLabelStrategy?: (node?: FormKitNode) => string;
    validationRules?: Record<string, (node: FormKitNode) => boolean | Promise<boolean>>;
    validationMessages?: Record<string, ((ctx: {
        name: string;
        args: any[];
        node: FormKitNode;
    }) => string) | string>;
    definition?: FormKitTypeDefinition;
    context?: FormKitFrameworkContext;
    [index: string]: any;
} & FormKitConfig;

FormKitRootConfig

全局配置选项。

type FormKitRootConfig = Partial<FormKitConfig> & {
    _add: (node: FormKitNode) => void;
    _rm: (node: FormKitNode) => void;
};

FormKitSchemaAttributes

DOM属性是简单的字符串字典。

type FormKitSchemaAttributes = {
    [index: string]: FormKitAttributeValue;
} | null | FormKitSchemaAttributesCondition;

FormKitSchemaComponent

在定义通用的非FormKit组件时可用的属性。

type FormKitSchemaComponent = {
    $cmp: string;
    props?: Record<string, any>;
} & FormKitSchemaProps;

FormKitSchemaCondition

确定要渲染的_哪个_内容的模式节点。

type FormKitSchemaCondition = {
    if: string;
    then: FormKitSchemaNode | FormKitSchemaNode[];
    else?: FormKitSchemaNode | FormKitSchemaNode[];
};

FormKitSchemaDefinition

从任何入口点获取的整个模式对象或子树。可以是单个节点、节点数组或条件。这是传递给FormKitSchema构造函数的类型。

type FormKitSchemaDefinition = FormKitSchemaNode | FormKitSchemaNode[] | FormKitSchemaCondition;

FormKitSchemaDOMNode

在使用DOM节点时可用的属性。

type FormKitSchemaDOMNode = {
    $el: string | null;
    attrs?: FormKitSchemaAttributes;
} & FormKitSchemaProps;

FormKitSchemaFormKit

用于使用FormKit的FormKitSchemaComponent节点的语法糖。

type FormKitSchemaFormKit = {
    $formkit: string;
} & Record<string, any> & FormKitSchemaProps;

FormKitSchemaMeta

元属性在解析模式时不使用,但可以用于创建工具。

type FormKitSchemaMeta = {
    [key: string]: string | number | boolean | undefined | null | CallableFunction | FormKitSchemaMeta;
};

FormKitSchemaNode

定义模式节点时可用的属性。

type FormKitSchemaNode = FormKitSchemaDOMNode | FormKitSchemaComponent | FormKitSchemaTextNode | FormKitSchemaCondition | FormKitSchemaFormKit;

FormKitSchemaTextNode

一个简单的文本节点。

type FormKitSchemaTextNode = string;

FormKitSearchFunction

广度优先和深度优先搜索可以使用此回调函数。

type FormKitSearchFunction = (node: FormKitNode, searchTerm?: string | number) => boolean;

FormKitStore

消息存储包含与给定节点相关的所有消息。

type FormKitStore = FormKitMessageStore & {
    _n: FormKitNode;
    _b: Array<[messages: FormKitMessage[], clear?: MessageClearer]>;
    _m: ChildMessageBuffer;
    _r?: string;
    buffer: boolean;
} & FormKitStoreTraps;

FormKitTextFragment

文本片段是用于界面验证消息或可能公开进行修改甚至翻译的错误的小片段文本。

type FormKitTextFragment = Partial<FormKitMessageProps> & {
    key: string;
    value: string;
    type: string;
};

FormKitTraps

节点陷阱映射的签名。

type FormKitTraps = Map<string | symbol, FormKitTrap>;

FormKitTypeDefinition

库项的定义-注册新的库项时,这些是必需和可用的属性。

type FormKitTypeDefinition = {
    type: FormKitNodeType;
    family?: string;
    forceTypeProp?: string;
    props?: string[];
    schema?: FormKitExtendableSchemaRoot | FormKitSchemaNode[] | FormKitSchemaCondition;
    component?: unknown;
    library?: Record<string, unknown>;
    features?: Array<(node: FormKitNode) => void>;
    schemaMemoKey?: string;
};

MessageClearer

允许清除消息的字符串或函数。

type MessageClearer = string | ((message: FormKitMessage) => boolean);

TrapGetter

节点的getter陷阱的签名。请记住,因为这些是陷阱而不是类方法,它们的响应类型在FormKitNode接口中明确声明。

type TrapGetter = ((node: FormKitNode, context: FormKitContext, ...args: any[]) => unknown) | false;

TrapSetter

节点的setter陷阱的签名-这些比getter陷阱更少见,但可以用于阻止访问某些上下文属性或修改分配的行为(例如,请参见setParent)。

type TrapSetter = ((node: FormKitNode, context: FormKitContext, property: string | number | symbol, value: any) => boolean | never) | false;