Solid 包 API 参考(@piying/view-solid)
本文介绍 Solid 包 @piying/view-solid 的公开 API。
| Token | 说明 |
|---|---|
PI_VIEW_FIELD_TOKEN |
当前字段配置(Solid Context) |
InjectorToken |
静态注入器(Context) |
CVA |
Symbol.for('ControlValueAccessor'),标识组件暴露的 CVA 属性 |
PiyingView
Section titled “PiyingView”表单根组件:
PiyingFieldTemplate
Section titled “PiyingFieldTemplate”🧭 手动模式:属于 两种使用模式 中的模式二。只手动渲染位置,字段内部仍全自动渲染。
把「包装器链 + 组件 + 递归子字段」整棵树渲染到指定位置:
| Props | 类型 | 说明 |
|---|---|---|
field |
PiResolvedViewFieldConfig(必填) |
要渲染的字段配置 |
path |
KeyPath(可选) |
定位子字段;不传则渲染整个根字段 |
完整渲染管线、懒加载与常见坑见 PiyingFieldTemplate(字段渲染)。
PiyingField
Section titled “PiyingField”🧭 手动模式:同
PiyingFieldTemplate,属于模式二(手动绑定)。
字段绑定:把字段的 FieldControl 接到你手写的控件上,通过 children 渲染函数暴露 cvaa / field:
| Props | 类型 | 说明 |
|---|---|---|
field |
PiResolvedViewFieldConfig(必填) |
字段配置 |
path |
KeyPath(可选) |
定位叶子子字段再绑定 |
children |
({ cvaa, field }) => JSX.Element |
渲染作用域,类型跟着 path 推导 |
完整说明(含
cvaa成员、错误码、与PiyingFieldTemplate对比)见 PiyingField(字段绑定)。
PiyingGroup
Section titled “PiyingGroup”字段组容器组件,用于渲染 object / array / record 等容器类型:
PiyingWrapper
Section titled “PiyingWrapper”Wrapper 组件(包装器容器)。
useControlValueAccessor — CVA 适配器
Section titled “useControlValueAccessor — CVA 适配器”返回 cva(ControlValueAccessor)与 cvaa(适配器):
cvaa 提供(注意 Solid 中值/禁用状态为 Accessor,需调用 () 获取):
| 成员 | 类型 | 说明 |
|---|---|---|
value |
Accessor<any> |
当前值(访问器) |
disabled |
Accessor<boolean> |
禁用状态(访问器) |
valueChange(v) |
(v) => void |
更新值并触发变更 |
touchedChange() |
() => void |
触发 touched |
createSignalConvert — Signal 转换
Section titled “createSignalConvert — Signal 转换”将信号转换为 Solid 访问器:
useEffectSync — 副作用同步
Section titled “useEffectSync — 副作用同步”仅接收 fn,基于 createMemo + createEffect:
convertToField — Schema 转换
Section titled “convertToField — Schema 转换”typedFieldComponentPipe — 路径 + 组件双强类型
Section titled “typedFieldComponentPipe — 路径 + 组件双强类型”按「路径 + 组件」写配置,inputs 收非函数 prop,outputs 收函数 prop(名字原样,onChange 就是 onChange)。详见 typedFieldComponentPipe(Solid)。
Solid 版没有
d.models;懒加载必须用solid-js的lazy()包一层;内置 prop 多了classList。
use-*Model 绑定 Hook
Section titled “use-*Model 绑定 Hook”将原生控件与 cvaa 双向绑定。详见 字段模型绑定:
| Hook | 目标控件 |
|---|---|
useInputTextModel |
文本输入 |
useInputCheckboxModel |
复选框 |
useInputNumberModel |
数字输入 |
useInputRadioModel |
单选按钮 |
useInputRangeModel |
范围滑块 |
useSelectModel |
下拉选择(单选/多选) |
SolidSchemaHandle / SolidFormBuilder
Section titled “SolidSchemaHandle / SolidFormBuilder”PiResolvedViewFieldConfig
Section titled “PiResolvedViewFieldConfig”Solid 的字段配置类型:
PiyingView、PiyingFieldTemplate、PiyingField、PiyingGroup、PiyingWrapper、PI_VIEW_FIELD_TOKEN、InjectorToken、CVA、useControlValueAccessor、createSignalConvert、useEffectSync、use-*Model 系列、typedFieldComponentPipe、convertToField、SolidSchemaHandle、SolidFormBuilder、PiResolvedViewFieldConfig。
- 字段模型绑定 — use-*Model 详解
- typedFieldComponentPipe(Solid) — 路径 + 组件双强类型
- 框架差异 — 各框架 CVA / Signal 对比
- 基础字段定义 — setComponent / formConfig