@formspec/ core (帮助)
共享类型,犬形IR节点,以及FormSpec的扩展注册API.
安装
pnpm add @formspec/core
大部分应用代码应该更喜欢 formspec 除非您正在构建工具、扩展或低级集成.
主要责任
- 窗体元素和状态类型
- 建造管道所用的罐式IR型
- 约束定义元数据
- 为自定义类型、限制和说明提供扩展注册帮助
- 共用类型警卫
示例
import type { FormElement, FormIR } from "@formspec/core";
import {
defineAnnotation,
defineConstraint,
defineCustomType,
defineExtension,
} from "@formspec/core";
function isFieldElement(element: FormElement): boolean {
return element._type === "field";
}
const decimalType = defineCustomType({
typeName: "Decimal",
tsTypeNames: ["Decimal"],
toJsonSchema: (_payload, vendorPrefix) => ({
type: "string",
[`${vendorPrefix}-decimal`]: true,
}),
});
const displayCurrency = defineAnnotation({
annotationName: "DisplayCurrency",
inheritFromBase: "local-wins",
});
const extension = defineExtension({
extensionId: "x-example/decimal",
types: [decimalType],
constraints: [],
annotations: [displayCurrency],
});
inheritFromBase 只有语义上的继承。 它允许一个类型级自定义注释流经类/界面遗产并被命名为类型别名的切入点,当所衍生的宣告在当地不声明相同的扩展注释,但不会将注释序列化为JSON Schema. 外观排放仍由可选的现有 toJsonSchema 钩子,所以地产级注释继承和元数据位继承仍然超出了范围.
密钥导出
窗体类型
FormSpecFormElementAnyFieldGroupConditionalFieldStateFormState
IR 类型
FormIRFieldNodeLayoutNodeTypeNodeConstraintNodeAnnotationNodeProvenance
扩展 API
defineExtensiondefineConstraintdefineConstraintTagdefineAnnotationdefineCustomType
公用事业
normalizeConstraintTagNamecreateInitialFieldStateIR_VERSION- 字段和布局类型
条目点
| 入境点 | 目的 |
|---|---|
@formspec/core | 稳定公共类型和扩展 API |
@formspec/core/internals | 不稳定的低级别内部类型 |
许可证
这个包是FormSpec monorepo的一部分,根据MIT许可证发行. 见 自由主义 详细情况.