import { LEVEL_ENUM, Vertex, View, Attr, Directive, Event, ActionOptions, Structure } from '..'; import Variable from '../logic/Variable'; export interface ElementToVueOptions { indentStyle?: 'space' | 'tab'; tabSize?: number; indentLevel?: number; aslIdAttr?: string | boolean; nodePathAttr?: string | boolean; getExtraParts?: (element?: Element) => Array; attrFormat?: (attr: Attr | Event | Directive, element?: Element, defaultResult?: string) => string; finalCode?: boolean; } export interface ParseContext { variables?: Array; structures?: Array; dataSchema?: string; [key: string]: any; } /** * 前端页面元素 * @example * */ export declare class Element extends Vertex { /** * 概念类型 */ readonly level: LEVEL_ENUM; /** * 元素类型 * 去除了 expression 和 text,目前只有一种节点类型 */ readonly type: number; /** * 元素 Id */ readonly id: string; /** * 元素标签 */ readonly tag: string; /** * 元素名称 * 用户可以自定义 * Vue 中的 ref */ readonly name: string; /** * 属性列表 * 和原来的 attrsList 不同,注意区分 */ readonly attrList?: Array; /** * 事件列表 */ readonly eventList?: Array; /** * 指令列表 */ readonly directiveList?: Array; /** * 插槽目标 * @example * 'cell' */ readonly slotTarget?: string; /** * 插槽 scope 表达式 * @example * 'scope' */ readonly slotScope?: string; /** * 静态 class 名 * 不计划支持动态 class */ readonly staticClass?: string; /** * 静态 style * 不计划支持动态样式 */ readonly staticStyle?: string; /** * 当前节点路径,只在前端动态计算后使用 */ nodePath: string; /** * 所在父元素 Id */ readonly parentId: string; /** * 所在位置 */ _posIndex: number; /** * 所在父元素 */ readonly parent?: Element; /** * 所在父元素 Id */ readonly viewId: string; /** * 所在子页面 */ readonly view?: View; /** * 子元素 */ readonly children?: Array; /** * @param source 需要合并的部分参数 */ constructor(source?: Partial); assign(source?: any): void; /** * 添加元素 */ create(none?: void, actionOptions?: ActionOptions): Promise; /** * 删除元素 */ delete(none?: void, actionOptions?: ActionOptions): Promise; /** * 修改元素 */ update(source?: Element, actionOptions?: ActionOptions): Promise; move(options: { parentId?: string; _posIndex?: number; nodePath?: string; position?: 'append' | 'insertBefore' | 'insertAfter'; }, actionOptions?: ActionOptions): Promise; /** * 添加元素副本 * 在所在父节点的后面添加一个相同的元素 */ duplicate(): Promise; /** * 添加子元素 * @param child */ addChild(child: string | Element, actionOptions?: ActionOptions): Promise; /** * 删除子元素 * @param child */ removeChild(child: Element, actionOptions?: ActionOptions): Promise; getElementTitle(): string; /** * 设置组件名称 */ setName(name: string): Promise; /** * 添加组件属性 */ addAttr(attr: Attr, actionOptions?: ActionOptions): Promise; /** * 删除组件属性 */ deleteAttr(attr: Attr, actionOptions?: ActionOptions): Promise; /** * 获取组件属性 */ getAttr(name: string): Attr; /** * 设置组件属性 */ setAttr(name: string, type: 'string' | 'static' | 'dynamic', value?: any): Promise; /** * 添加组件事件 */ addEvent(data: Event, actionOptions?: ActionOptions): Promise; /** * 删除组件属性 */ deleteEvent(event: Event, actionOptions?: ActionOptions): Promise; /** * 添加组件指令 */ addDirective(data: Directive, actionOptions?: ActionOptions): Promise; /** * 删除组件属性 */ deleteDirective(directive: Directive, actionOptions?: ActionOptions): Promise; /** * 转换成 Vue 的模板格式 */ toVue(options?: ElementToVueOptions): string; /** * 转换成设计器中使用的 Vue 文件 * @param options */ toDesignerVue(options?: ElementToVueOptions): string; /** * 同 toVue 方法 * @param options 缩进等选项 */ toHTML(options?: ElementToVueOptions): string; /** * 根据标签查找元素 * @param tag */ findElementByTag(tag: string): Element; /** * 根据属性查找元素 * @param name * @param value */ findElementByAttr(name: string, value: string): Element; /** * 从 Vue 的 ASTNode 转换成 ASL 元素 * @param astNode Vue 的 ASTNode */ private static _fromASTNode; /** * 解析属性中的表达式 * @param value * @param $def 目前 $def 只用来查找 $def.variables 和 $def.structures * @param dataSchema */ private static _parseExpression; /** * 解析 Vue 模板 * 该方法不会绑定 view 和 parent,如果是添加元素优先使用 fromHTML * @param html Vue 的模板 * @TODO 处理多个元素的问题 */ static parse(html: string, context?: ParseContext): Element; /** * 从模板生成规范的 Element 对象 */ static fromHTML(html: string, parent: Element, view: View, context?: ParseContext): Element; /** * 从后端 JSON 生成规范的 Element 对象 */ static from(source: any, parent: Element, view: View, currentElement?: Element): Element; } export default Element;