@happy-table/vue3
Version:
A high-performance Vue 3 table component for B2B systems with TypeScript support
48 lines (47 loc) • 1.52 kB
TypeScript
import { TableColumn, TableRow } from '../types';
export interface TemplateContext {
value: unknown;
row: TableRow;
column: TableColumn;
index: number;
}
export interface TemplateOptions {
escapeHtml?: boolean;
defaultValue?: string;
throwOnError?: boolean;
}
/**
* 解析模板字符串,提取所有变量
* @param template 模板字符串
* @returns 变量名数组
*/
export declare function parseTemplate(template: string): string[];
/**
* 获取模板变量的值
* @param variable 变量名,如 'value'、'row.name'、'column.title' 或表达式 'value + 100'
* @param context 模板上下文
* @returns 变量值或表达式计算结果
*/
export declare function getTemplateVariable(variable: string, context: TemplateContext): unknown;
/**
* 渲染模板字符串
* @param template 模板字符串
* @param context 模板上下文
* @param options 渲染选项
* @returns 渲染后的字符串
*/
export declare function renderTemplate(template: string, context: TemplateContext, options?: TemplateOptions): string;
/**
* 验证模板字符串是否有效
* @param template 模板字符串
* @returns 验证结果 { valid: boolean, errors: string[] }
*/
export declare function validateTemplate(template: string): {
valid: boolean;
errors: string[];
};
/**
* 创建模板渲染器
* 返回一个可复用的渲染函数
*/
export declare function createTemplateRenderer(template: string, options?: TemplateOptions): (context: TemplateContext) => string;