mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 17:21:16 +08:00
- 实现配置模式解析器,支持对象、数组和标量类型的递归验证 - 添加 YAML 解析和注释提取功能,支持嵌套对象和数组结构 - 实现配置验证诊断,提供详细的错误和警告信息 - 添加表单更新应用功能,支持标量值和数组的批量编辑 - 实现配置示例生成功能,包含描述信息作为 YAML 注释 - 添加数值约束验证,包括最小值、最大值、倍数和长度限制 - 实现枚举值和模式匹配验证,确保数据符合预定义规则 - 添加常量值比较功能,支持对象和数组类型的深度比较
68 lines
2.5 KiB
JavaScript
68 lines
2.5 KiB
JavaScript
/**
|
|
* Build a compact contains-schema summary for array field hints.
|
|
* The summary reuses existing localized hint strings so Chinese UI surfaces
|
|
* do not fall back to mixed English tokens such as const/enum/pattern/ref.
|
|
*
|
|
* @param {{type?: string, enumValues?: string[], constValue?: string, constDisplayValue?: string, pattern?: string, refTable?: string}} containsSchema Parsed contains schema metadata.
|
|
* @param {{t: (key: string, params?: Record<string, string | number>) => string}} localizer Runtime localizer.
|
|
* @returns {string} Human-facing summary.
|
|
*/
|
|
function describeContainsSchema(containsSchema, localizer) {
|
|
const parts = [];
|
|
if (containsSchema.type) {
|
|
parts.push(containsSchema.type);
|
|
}
|
|
|
|
if (containsSchema.constValue !== undefined) {
|
|
parts.push(localizer.t("webview.hint.const", {
|
|
value: containsSchema.constDisplayValue ?? containsSchema.constValue
|
|
}));
|
|
} else if (Array.isArray(containsSchema.enumValues) && containsSchema.enumValues.length > 0) {
|
|
parts.push(localizer.t("webview.hint.allowed", {
|
|
values: containsSchema.enumValues.join(", ")
|
|
}));
|
|
} else if (containsSchema.pattern) {
|
|
parts.push(localizer.t("webview.hint.pattern", {
|
|
value: containsSchema.pattern
|
|
}));
|
|
}
|
|
|
|
if (containsSchema.refTable) {
|
|
parts.push(localizer.t("webview.hint.refTable", {
|
|
refTable: containsSchema.refTable
|
|
}));
|
|
}
|
|
|
|
return parts.join(", ") || localizer.t("webview.objectArray.item");
|
|
}
|
|
|
|
/**
|
|
* Build localized contains-related hint lines for array fields.
|
|
*
|
|
* @param {{contains?: {type?: string, enumValues?: string[], constValue?: string, constDisplayValue?: string, pattern?: string, refTable?: string}, minContains?: number}} propertySchema Array property schema metadata.
|
|
* @param {{t: (key: string, params?: Record<string, string | number>) => string}} localizer Runtime localizer.
|
|
* @returns {string[]} Localized contains hint lines.
|
|
*/
|
|
function buildContainsHintLines(propertySchema, localizer) {
|
|
if (!propertySchema.contains) {
|
|
return [];
|
|
}
|
|
|
|
const effectiveMinContains = typeof propertySchema.minContains === "number"
|
|
? propertySchema.minContains
|
|
: 1;
|
|
return [
|
|
localizer.t("webview.hint.contains", {
|
|
summary: describeContainsSchema(propertySchema.contains, localizer)
|
|
}),
|
|
localizer.t("webview.hint.minContains", {
|
|
value: effectiveMinContains
|
|
})
|
|
];
|
|
}
|
|
|
|
module.exports = {
|
|
describeContainsSchema,
|
|
buildContainsHintLines
|
|
};
|