import type { IWidget, WidgetConstructor, WidgetProps } from '@oinone/kunlun-engine'; import { BehaviorSubject, Subject, Subscription } from '@oinone/kunlun-state'; import { InnerWidgetType } from '../typing/typing'; type WidgetTypeKey = keyof typeof InnerWidgetType; interface BaseWidgetSubjection { subscribe: (func: (data: T) => void) => Subscription; subject: BehaviorSubject | Subject; } export interface WidgetSubjection extends BaseWidgetSubjection { subject: Subject; } export interface WidgetBehaviorSubjection extends BaseWidgetSubjection { subject: BehaviorSubject; } export type watcher = { path: string; handler: (newVal: T, oldVal: T) => void; options?: { deep?: boolean; }; }; export type HANDLE = string; export declare abstract class Widget implements IWidget { private static widgetCount; private static createHandle; private static widgetMap; private static attributeMap; private static protoChainsCache; private static watchMap; private static nameContextMap; private subscriptionMap; private $$props?; private $$subNames?; private static Attribute; /** * 添加事件监听 * * @param {string} path 监听的路径 * @param {deep?:boolean;immediate?:boolean} options? * * @example * * @Widget.Watch('formData.name', {deep: true, immediate: true}) * private watchName(name: string) { * ... todo * } * */ protected static Watch(path: string, options?: { deep?: boolean; immediate?: boolean; }): (target: T, nativeName: string, descriptor: TypedPropertyDescriptor<(newValue: K, oldValue?: K) => void> | TypedPropertyDescriptor<(newValue: K, oldValue?: K) => Promise> | TypedPropertyDescriptor<(newValue?: K, oldValue?: K) => void> | TypedPropertyDescriptor<(newValue?: K, oldValue?: K) => Promise>) => void; private static Sub; /** * 可以用来处理不同widget之间的通讯,当被订阅的时候,会将默认值发送出去 * * @param {Symbol} name 唯一标示 * @param {unknown} value? 默认值 * @param {scope?: WidgetTypeKey} option? 作用域检查,如果设置了该值,那么发布的时候会携带发布者的widget实例,订阅的时候会检查发布者的widget实例是否和订阅者在同一个作用域下,如果是,那么才会触发订阅函数 * * @example * * const identifier = Symbol('example-sub') * * * field.ts * // 文件 * * @Widget.BehaviorSubContext(identifier, {value: '这是默认值'}) * private exampleSub!:WidgetBehaviorSubjection<{value: string}> * * onValueChange() { * this.exampleSub.subject.next({value: '这是新的值'}) * } * * * other-field.ts * // 文件 * @Widget.BehaviorSubContext(identifier, {value: '这是默认值'}) * private exampleSub!:WidgetBehaviorSubjection<{value: string}> * * mounted() { * this.exampleSub.subscribe((value) => { * ...todo * }) * } * */ protected static BehaviorSubContext(name: Symbol, value?: unknown, option?: { scope?: WidgetTypeKey; }): (target: K, paramName: string) => void; /** * 与 `BehaviorSubContext` 一样,区别在于第一次不会发射默认值 * * @param {Symbol} name 唯一标示 * @param {unknown} value? 默认值 * @param {scope?: WidgetTypeKey} option? 作用域检查,如果设置了该值,那么发布订阅只会在同一个作用域下的widget之间进行 */ protected static SubContext(name: Symbol, value?: unknown, option?: { scope?: WidgetTypeKey; }): (target: K, paramName: string) => void; /** * 将数据绑定为响应式,并且组件中可以获取该值 */ protected static Reactive(params?: { displayName?: string; render?: boolean; }): (target: T, nativeName: string, description?: TypedPropertyDescriptor) => void; /** * 将方法绑定为能够被组件获取的方法 */ protected static Method(displayName?: string): (target: T, nativeName: string, description?: TypedPropertyDescriptor) => void; static select(handle: string): T | undefined; /** * 获取上级注入的依赖,与 Provide 一起使用 * * @param {string|Symbol} injectName? 被注入的name,如果不传递,那么取target中的name * * @example * * * children.ts * // 文件 * * @Widget.Inject('InjectName') * private rootData!: * * 如果要将该值变为响应式,如果加上Reactive * * @Widget.Reactive() * @Widget.Inject('InjectName') * private rootData!:; */ protected static Inject(injectName?: string | Symbol): (target: T, name: string) => void; /** * 获取下级注入的依赖,与 Inject 一起使用 * * @param {string|Symbol} provideName? 被注入的name,如果不传递,那么取target中的name * * @example * * * parent.ts * // 文件 * * @Widget.Provide('ProvideName') * private rootData!: * * 如果要将该值变为响应式,如果加上Reactive * * @Widget.Reactive() * @Widget.Provide('ProvideName') * private rootData!:; */ protected static Provide(provideName?: string | Symbol): (target: T, name: string) => void; private parent; protected $$innerWidgetType: InnerWidgetType | null | undefined; protected childrenInstance: Widget[]; protected children: Widget[]; protected childrenWidget: Widget[]; private readonly handle; config: Props; private name; private initialized; private self; constructor(handle?: string); protected getSelf(): Widget | null; getOperator(): this; initialize(config?: Props): Widget; /** * 启动订阅 */ private startSubscription; /** * 包装发布者事件 * 如果启动了作用域检查,那么发布的时候会携带发布者的widget实例 **/ private wrapSubjectWithScope; /** * 创建发布订阅对象 */ private createWidgetSubjection; private isSameScopeWidget; /** * 销毁widget * * 内部会根据handle匹配到对应的widget,然后进行销毁,如果children中出现了相同的handle,那么会销毁第一个 */ dispose(force?: boolean): void; /** * 创建一个widget * * @param {Widget} constructor 对应的widget * @param {string} name? 插槽 * @param {IViewProps} config? widget中initialize方法接收的参数 * */ createWidget(constructor: WidgetConstructor, name?: string, config?: T['config'], specifiedIndex?: number): T; getHandle(): HANDLE; /** * 删除指定的widget */ deleteWidget(name: string): boolean; moveChildWidget(endIndex: number, startIndex: number): void; insertWidget(widget: Widget, index: number): void; deleteWidgetByIndex(index: number, handle?: string): boolean; getConfig(key: string): unknown; getAllConfig(): Props; getSibling(): Widget[] | null; /** * 返回当前元素在其父元素的子元素节点中的前一个元素节点,如果该元素已经是第一个元素节点,则返回 null */ previousWidgetSibling(): Widget | null; /** * 返回当前元素在其父元素的子元素节点中的后一个元素节点,如果该元素已经是最后一个元素节点,则返回 null */ nextWidgetSibling(): Widget | null; /** * 获取父元素 */ getParentWidget(): Widget | null; private getParentWidgetByType; /** * 获取子元素 */ getChildrenWidget(): Widget[]; /** * @inner * */ getParent(): Widget | null; getName(): string; getWidgetType(): string; static getProtoChains(obj: T): Function[]; private currentAttributeMapCache; /** * 获取所有的属性 */ getAttributes(): Map; /** * 获取所有的监听事件 */ getWatchers(): watcher[]; /** * @deprecated 使用 getChildrenWidget() * * 获取所有的children */ getChildren(): Widget[]; /** * @inner * */ getChildrenInstance(): Widget[]; protected addChildrenInstance(widget: Widget): void; protected getShared(injectName: string | Symbol): { host?: Widget; value?: unknown; }; private releaseInjection; getComputeHandler(name: string): { get: Function; set: Function; }; protected getProps(): string[]; abstract render(...args: any[]): R; } export {};