roymondchen cbc4b25072 feat(editor): 字段对比模式逐项展示差异并补充历史记录面板文档
- CodeSelect/CodeSelectCol/EventSelect/DataSource 等复合字段在对比模式下
  按索引对齐前后值,逐项展示新增/删除/修改高亮,并隐藏写操作按钮
- form 容器/列表/表格支持对比模式只读展示
- 新增「历史记录面板」指南文档,完善表单对比文档及 menu props 说明
- 补充相关单元测试

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 15:51:47 +08:00

64 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { InjectionKey } from 'vue';
import type { FormItemConfig } from '@tmagic/form-schema';
export * from '@tmagic/form-schema';
/**
* 对比模式相关配置,由 `MForm` 通过 `provide` 注入,
* 所有层级的 Container含嵌套在 fieldset / panel 等容器组件内部的 Container通过 `inject` 获取,
* 无需逐层透传 prop。
*/
export interface FormDiffConfig {
/**
* 自定义"是否展示对比内容"的判断函数(仅在对比模式下生效)。
*
* - 不传:使用默认逻辑 `!isEqual(curValue, lastValue)`
* - 传函数:完全以函数返回值为准,返回 `true` 才展示前后两份对比内容。
*/
showDiff?: (_data: { curValue: any; lastValue: any; config: FormItemConfig }) => boolean;
/**
* 自定义「自接管对比」的字段类型(仅在对比模式下生效)。
*
* - 传数组:在内置类型基础上「追加」这些类型;
* - 传函数:入参为内置类型数组,返回值作为「最终」完整类型列表(可完全替换内置项)。
*/
selfDiffFieldTypes?: string[] | ((_defaultTypes: string[]) => string[]);
}
export const FORM_DIFF_CONFIG_KEY: InjectionKey<FormDiffConfig> = Symbol('mFormDiffConfig');
export interface ValidateError {
message: string;
field: string;
}
export interface ChangeRecord {
propPath?: string;
value: any;
}
export interface ContainerChangeEventData {
modifyKey?: string;
changeRecords?: ChangeRecord[];
}
/** 自定义 label slot 的作用域参数 */
export interface FormLabelSlotProps {
/** 当前表单项配置 */
config: FormItemConfig;
/** 经处理后的类型 */
type: string;
/** 经 filterFunction 处理后的 label 文案 */
text?: string;
/** 完整字段路径(包含父级前缀) */
prop: string;
/** 经 filterFunction 处理后的最终禁用状态 */
disabled?: boolean;
}
/** Form / Container 暴露的具名 slot 定义 */
export interface FormSlots {
label(_props: FormLabelSlotProps): any;
}