import { Scope } from "../Scope"; import { HttpRequestOptions, HttpRequestInput } from "./request-types"; import { IStore, StoreConfig, StoreConfigBase } from "./store-types"; import { Framework } from "../Framework"; import { Page } from "../Page"; import { RuiRockLogger } from "../Logger"; import { GetStringResourceConfig, Lingual } from "./locale-types"; export declare type FieldSettings = { valueType: FieldValueType; valueNotNull?: boolean; description?: string; defaultValue?: any; /** * 当属性值发生变化时,需要触发的事件名 */ onChangeEventName?: string; }; export declare type FieldValueType = "string" | "number" | "boolean" | "object"; export declare type RockRenderer = (context: RockInstanceContext, props: TRockConfig, state?: TRockState & { scope: Scope; }, instance?: RockInstance) => any; export declare type ProCodeRock = { Renderer: RockRenderer; onInit?: (context: RockInitContext, props: TRockConfig) => void; onResolveState?: (props: TRockConfig, state: TRockState, instance: RockInstance) => any; onReceiveMessage?: (message: RockMessageToComponent, state: TRockState, props: TRockConfig, instance: RockInstance) => any; } & ProCodeRockMeta; export declare type DeclarativeRock = { view: RockChildrenConfig; } & DeclarativeRockMeta; export declare type Rock = ProCodeRock | DeclarativeRock; export declare type RockMessage = { name: TName; payload?: TPayload; }; export declare type RockMessageToComponent = TRockMessage & { framework: Framework; page: IPage; }; export declare type RockMetaBase = { $type: string; $version?: string; name?: string; description?: string; icon?: string; thumbnail?: string; document?: string; Presenter?: (props: any) => any; componentRenderer?: any; /** * Void component has no children */ voidComponent?: boolean; props?: RockMetaProps; slots?: RockMetaSlots; events?: RockMetaEvents; commands?: RockMetaCommands; dataLoader?: RockDataLoader; propertyPanels?: RockPropPanels; }; export declare type ProCodeRockMeta = { declarativeComponent?: false; } & RockMetaBase; export declare type DeclarativeRockMeta = { declarativeComponent: true; view: RockChildrenConfig; } & RockMetaBase; export declare type RockMeta = ProCodeRockMeta | DeclarativeRockMeta; export declare type RockMetaProps = Record; export declare type RockMetaSlots = Record; export declare type RockMetaSlot = { name?: string; description?: string; required?: boolean; allowMultiComponents: boolean; argumentsToProps?: boolean; argumentNames?: string[]; /** * 表示该插槽内接受的是组件适配器 */ withAdapter?: boolean; /** * 适配器的插槽。默认为children。 */ adapterSlots?: string[]; /** * 表示需要将插槽内组件包装成 render prop */ toRenderProp?: boolean; /** * 表示是否延迟创建插槽内组件。默认为`false`。 * */ lazyCreate?: boolean; /** * 表示是否在调用Rock.Renderer之前提前创建插槽内组件。默认为`false`。 */ earlyCreate?: boolean; }; export declare type RockMetaEvents = RockMetaEvent[]; export declare type RockMetaEvent = { name: string; label?: string; description?: string; args?: RockMetaEventArgs; }; export declare type RockMetaEventArgs = Record; export declare type RockMetaCommands = RockMetaCommand[]; export declare type RockMetaCommand = { name: string; label?: string; description?: string; args?: RockMetaCommandArgs; }; export declare type RockMetaCommandArgs = Record; export declare type RockDataLoader = {}; export declare type RockPropPanels = RockPropPanel[]; export declare type RockPropPanel = PredefinedRockPropPanel | ComponentSpecifiedRockPropPanel; export declare const PredefinedRockPanelTypes: readonly ["positionPropPanel", "sizePropPanel", "appearancePropPanel", "textPropPanel", "borderPropPanel"]; export declare type PredefinedRockPropPanel = { $type: (typeof PredefinedRockPanelTypes)[number]; title?: string; }; export declare type ComponentSpecifiedRockPropPanel = { $type: "componentPropPanel"; title?: string; setters: RockPropSetter[]; }; export declare type RockPropSetter = ExpressionRockPropSetter | TextRockPropSetter | NumberRockPropSetter | NumberWithSliderRockPropSetter | NumberWithUnitsRockPropSetter | SelectRockPropSetter | SwitchRockPropSetter | SingleControlRockPropSetter | SingleControlMultiPropsSetter | MultiControlsRockPropSetter | MultiControlsMultiPropsSetter; export declare type RockPropSetterBase = { $type: TSetterType; label: string; labelTip?: string; defaultValue?: TPropValue; dynamicForbidden?: boolean; readOnly?: boolean; }; export interface RockSinglePropSetterBase extends RockPropSetterBase { multiProps?: false; propName: string; } export interface RockMultiPropsSetterBase extends RockPropSetterBase { multiProps: true; propNames: string[]; } export interface PropSetterRockConfigBase extends Omit { componentConfig: RockConfig; onPropValueChange?: RockEventHandlerConfig; onPropExpressionChange?: RockEventHandlerConfig; onPropExpressionRemove?: RockEventHandlerConfig; onSettingPropExpression?: RockEventHandlerConfig; } export interface ExpressionRockPropSetter extends RockSinglePropSetterBase<"expressionPropSetter", any> { } export interface TextRockPropSetter extends RockSinglePropSetterBase<"textPropSetter", string> { } export interface NumberRockPropSetter extends RockSinglePropSetterBase<"numberPropSetter", number> { min?: number; max?: number; step?: number; } export interface NumberWithSliderRockPropSetter extends RockSinglePropSetterBase<"numberWithSliderPropSetter", number> { min?: number; max?: number; step?: number; } export interface NumberWithUnitsRockPropSetter extends RockSinglePropSetterBase<"numberWithUnitsPropSetter", number> { defaultUnit?: string; min?: number; max?: number; step?: number; unitOptions: { label: string; value: string; }[]; } export interface SelectRockPropSetter extends RockSinglePropSetterBase<"selectPropSetter", string> { options: { label: string; value: string; }[]; showSearch?: boolean; allowClear?: boolean; } export interface SwitchRockPropSetter extends RockSinglePropSetterBase<"switchPropSetter", boolean> { checkedValue?: any; uncheckedValue?: any; } export interface SingleControlRockPropSetter extends RockSinglePropSetterBase<"singleControlPropSetter", TPropValue> { control: RockConfig; extra?: RockConfig; } export interface SingleControlMultiPropsSetter extends RockMultiPropsSetterBase<"singleControlMultiPropsSetter", TPropValue> { control: RockConfig; extra?: RockConfig; } export interface MultiControlsRockPropSetter extends RockSinglePropSetterBase<"multiControlsPropSetter", TPropValue> { controls?: RockPropSetterControl[]; extra?: RockConfig; } export interface MultiControlsMultiPropsSetter extends RockMultiPropsSetterBase<"multiControlsMultiPropsSetter", TPropValue> { controls?: RockPropSetterControl[]; extra?: RockConfig; } export declare type RockPropSetterControl = { propName?: string; defaultValue?: TValue; control: RockConfig; /** * max=2, default=2 */ span?: number; }; export declare type RockChildrenConfig = RockConfig | RockConfig[] | null; export declare type RockConfig = SimpleRockConfig | RockWithSlotsConfig | ContainerRockConfig | RouterRockConfig; export declare type RockCategory = "simple" | "withSlots" | "container" | "composite" | "router"; export declare type RockConfigBase = { $id?: string; $type: string; $version?: string; $name?: string; /** * 描述 */ $description?: string; $exps?: RockExpsConfig; $i18n?: RockI18nConfig; $locales?: RockLocalesConfig; _hidden?: boolean; }; export declare type RockConfigSystemFields = keyof RockConfigBase; export declare type RuiEvent = RockEvent; export declare type RockEvent = { framework: Framework; page: IPage; scope: IScope; name: string; senderCategory?: "component" | "store" | "actionHandler" | "other"; sender: any; args: any[]; parent?: RockEvent; }; export declare type RockEventSender = RockInstance; export interface HandleRockEventContext { framework: Framework; page: IPage; scope: IScope; } export interface HandleRockEventOptions { context?: HandleRockEventContext; parentEvent?: RockEvent; eventName?: string; sender?: RockEventSender; handlers: RockEventHandlerConfig; args?: any[]; } export declare type RockPageEventSubscriptionConfig = { eventName: string; handlers: RockEventHandlerConfig; }; export declare type RockEventHandlerConfig = RockEventHandler | RockEventHandler[] | null; export declare type RockEventHandler = RockEventHandlerScript | RockEventHandlerPrintToConsole | RockEventHandlerThrowError | RockEventHandlerWait | RockEventHandlerHandleEvent | RockEventHandlerFireEvent | RockEventHandlerNotifyEvent | RockEventHandlerNotifyToPage | RockEventHandlerSetComponentProperty | RockEventHandlerSetComponentProperties | RockEventHandlerRemoveComponentProperty | RockEventHandlerSendHttpRequest | RockEventHandlerLoadStoreData | RockEventHandlerLoadScopeData | RockEventHandlerSetVars | RockEventHandlerOther; export declare type RockEventHandlerBase = { _disabled?: boolean; $exps?: RockExpsConfig; }; export declare type RockEventHandlerScript = RockEventHandlerBase & { $action: "script"; script: string | ((event: RockEvent) => void); generator?: "editor" | "blockly"; blockly?: any; }; export declare type RockEventHandlerPrintToConsole = RockEventHandlerBase & { $action: "printToConsole"; }; export declare type RockEventHandlerThrowError = RockEventHandlerBase & { $action: "throwError"; name?: string; message: string; cause?: any; }; export declare type RockEventHandlerWait = RockEventHandlerBase & { $action: "wait"; time: number; }; export declare type RockEventHandlerHandleEvent = RockEventHandlerBase & { $action: "handleEvent"; eventName?: string; scope?: Scope; handlers?: RockEventHandlerConfig; args?: any; }; export declare type RockEventHandlerFireEvent = RockEventHandlerBase & { $action: "fireEvent"; eventName?: string; scope?: Scope; handlers?: RockEventHandlerConfig; args?: any; }; export declare type RockEventHandlerNotifyEvent = RockEventHandlerBase & { $action: "notifyEvent"; eventName?: string; scopeId?: string; args?: any; }; export declare type RockEventHandlerNotifyToPage = RockEventHandlerBase & { $action: "notifyToPage"; eventName?: string; }; export declare type RockEventHandlerSetComponentProperty = RockEventHandlerBase & { $action: "setComponentProperty"; $exps?: RockExpsConfig; componentId: string; propName: string; propValue: RockPropValue; }; export declare type RockEventHandlerSetComponentProperties = RockEventHandlerBase & { $action: "setComponentProperties"; $exps?: RockExpsConfig; componentId: string; props: Record; }; export declare type RockEventHandlerRemoveComponentProperty = RockEventHandlerBase & { $action: "removeComponentProperty"; $exps?: RockExpsConfig; componentId: string; propName: string; }; export declare type RockEventHandlerSendComponentMessage = RockEventHandlerBase & { $action: "sendComponentMessage"; $exps?: RockExpsConfig; componentId: string; message: TRockMessage; }; export declare type RockEventHandlerSendHttpRequest = RockEventHandlerBase & { $action: "sendHttpRequest"; $exps?: RockExpsConfig; /** * 如果设置为true,则请求出错时不抛出异常 */ silentOnError?: boolean; } & Partial; export declare type RockEventHandlerLoadStoreData = RockEventHandlerBase & { $action: "loadStoreData"; scopeId?: string; rootScope?: boolean; storeName: string; input?: any; }; export declare type RockEventHandlerLoadScopeData = RockEventHandlerBase & { $action: "loadScopeData"; scopeId?: string; }; export declare type RockEventHandlerSetVars = RockEventHandlerBase & { $action: "setVars"; $exps?: RockExpsConfig; scopeId?: string; rootScope?: boolean; name?: string; value?: any; vars?: Record; }; export declare type RockEventHandlerOther = RockEventHandlerBase & { $action: string; [k: string]: any; }; /** * @deprecated * use RockExpsConfig */ export declare type RockPropExpressions = Record; export declare type RockExpsConfig = RockPropExpressions; export declare type RockI18nConfig = Record; export declare type RockLocalesConfig = Record>; export declare type SimpleRockConfig = RockConfigBase & { [k: string]: RockPropValue; }; export declare type RockPropValueProducer = () => RockPropValue; export declare type RockPropValue = string | number | boolean | RockConfig | RockConfig[] | RockEventHandlerConfig | RockExpsConfig | RockI18nConfig | RockLocalesConfig | Record | RockPropValueProducer | any; export declare type RockWithSlotsConfig = RockConfigBase & { slots: Record; } & { [k: string]: RockPropValue; }; export declare type ContainerRockConfig = RockConfigBase & { children?: RockChildrenConfig; } & { [k: string]: RockPropValue; }; export declare type RouterRockConfig = RockConfigBase & { routes: RouteConfig[]; } & { [k: string]: RockPropValue; }; export declare type RouteConfig = { path: string; element: RockConfig; errorElement?: RockConfig; }; export declare type RockInstanceContext = { framework: Framework; page: Page; /** * Host component of the rock instance. */ component?: RockInstance; scope: Scope; logger: RuiRockLogger; }; export declare type RockStateUpdater = (state: Record) => Record; export declare type RockInstanceOriginal = { _context: RockInstanceContext; _scope: Scope; _initialized: boolean; _state: TState; setState: (stateChangesOrUpdater: Record | RockStateUpdater) => void; }; export declare type RockInstanceFields = keyof RockInstanceOriginal; export declare type RockInstance, TMethods extends Record = {}> = TRockConfig & RockInstanceOriginal & TMethods; export declare type PageConfig = { $id?: string; initialVars?: Record; stores?: StoreConfig[]; layout?: PageConfig; view: RockConfig[]; eventSubscriptions?: RockPageEventSubscriptionConfig[]; functions?: FunctionConfig[]; }; export declare type PageCommand = PageCommandSetPageConfig | PageCommandAddComponent | PageCommandRemoveComponents | PageCommandSetComponentProperty | PageCommandSetComponentProperties | PageCommandRemoveComponentProperty | PageCommandSetComponentPropertyExpression | PageCommandRemoveComponentPropertyExpression | PageCommandSetSelectedComponents | PageCommandCutComponents | PageCommandCopyComponents | PageCommandPasteComponents | PageCommandMoveComponents | PageCommandAddStores | PageCommandAddStore | PageCommandModifyStore | PageCommandUpdateStore | PageCommandRemoveStore | PageCommandAddStep | PageCommandModifyStep | PageCommandRemoveStep | PageCommandSetScopeVars; export declare type PageCommandSetPageConfig = { name: "setPageConfig"; payload: { pageConfig: PageConfig; }; }; export declare type PageCommandAddComponent = { name: "addComponent"; payload: { componentType: string; defaultProps?: any; parentComponentId?: string; slotPropName?: string; prevSiblingComponentId?: string; }; }; export declare type PageCommandRemoveComponents = { name: "removeComponents"; payload: { componentIds: string[]; }; }; export declare type PageCommandSetComponentProperty = { name: "setComponentProperty"; payload: { componentId: string; propName: string; propValue: any; }; }; export declare type PageCommandSetComponentProperties = { name: "setComponentProperties"; payload: { componentId: string; props: Record; }; }; export declare type PageCommandRemoveComponentProperty = { name: "removeComponentProperty"; payload: { componentId: string; propName: string; }; }; export declare type PageCommandSetComponentPropertyExpression = { name: "setComponentPropertyExpression"; payload: { componentId: string; propName: string; propExpression: string; }; }; export declare type PageCommandRemoveComponentPropertyExpression = { name: "removeComponentPropertyExpression"; payload: { componentId: string; propName: string; }; }; export declare type PageCommandSetSelectedComponents = { name: "setSelectedComponents"; payload: { componentIds: string[]; }; }; export declare type PageCommandCutComponents = { name: "cutComponents"; payload: { componentIds: string[]; }; }; export declare type PageCommandCopyComponents = { name: "copyComponents"; payload: { componentIds: string[]; }; }; export declare type PageCommandPasteComponents = { name: "pasteComponents"; payload: { parentComponentId?: string; slotPropName?: string; prevSiblingComponentId?: string; }; }; export declare type PageCommandMoveComponents = { name: "moveComponents"; payload: { componentIds: string[]; parentComponentId?: string; slotPropName?: string; prevSiblingComponentId?: string; }; }; export declare type PageCommandAddStores = { name: "addStores"; payload: { stores: StoreConfig[]; }; }; export declare type PageCommandAddStore = { name: "addStore"; payload: { store: StoreConfig; }; }; /** * @deprecated */ export declare type PageCommandModifyStore = { name: "modifyStore"; payload: { store: StoreConfig; }; }; export declare type PageCommandUpdateStore = { name: "updateStore"; payload: { store: StoreConfig; }; }; export declare type PageCommandRemoveStore = { name: "removeStore"; payload: { store: StoreConfig; }; }; /** * @deprecated */ export declare type PageCommandAddStep = { name: "addStep"; payload: { step: Record; }; }; /** * @deprecated */ export declare type PageCommandModifyStep = { name: "modifyStep"; payload: { step: Record; }; }; /** * @deprecated */ export declare type PageCommandRemoveStep = { name: "removeStep"; payload: { step: Record; }; }; export declare type PageCommandSetScopeVars = { name: "setScopeVars"; payload: { scopeId?: string; vars: Record; silent?: boolean; }; }; export interface IPage { get scope(): IScope; generateComponentId(type: string): any; setConfig(pageConfig: PageConfig): any; getConfig(): PageConfig; interpreteExpression(expressionString: string, rootVars: Record): any; addComponents(components: RockConfig[], parentComponentId?: string, slotPropName?: string, prevSiblingComponentId?: string): any; removeComponents(componentIds: string[]): any; setComponentProperty(componentId: string, propName: string, propValue: RockPropValue): any; setComponentProperties(componentId: string, props: Record): any; removeComponentProperty(componentId: string, propName: string): any; getComponentProperty(componentId: string, propName: string): any; setComponentPropertyExpression(componentId: string, propName: string, propExpression: string): any; removeComponentPropertyExpression(componentId: string, propName: string): any; interpreteComponentProperties(parentConfig: RockConfig, config: RockConfig, vars: Record): any; getComponent(componentId: string): RockConfig; getScope(scopeId: string): Scope; getStore>(storeName: string): TStore; addStore(storeConfig: StoreConfig): any; loadStoreData(storeName: string, input?: HttpRequestInput): Promise; notifyEvent(event: RuiEvent): any; sendComponentMessage = RockMessage>(componentId: string, message: TRockMessage): any; /** * 处理事件 * @param options * @example * ``` * page.handleEvent({ * parentEvent: event, * handlers: [ * { * $action: "setComponentProperty", * componentId: "text1", * propName: "text", * propValue: "hello" * } * ] * }) * ``` */ handleEvent(options: HandleRockEventOptions): Promise; } export interface ScopeConfig { $id: string; stores?: StoreConfig[]; initialVars?: Record; eventSubscriptions?: RockPageEventSubscriptionConfig[]; } export interface ScopeState { stores: Record; vars: Record; version: number; } export interface IScope { setConfig(config: ScopeConfig): any; getConfig(): ScopeConfig; setVars(vars: Record): any; get vars(): Record; get stores(): Record; addStore(storeConfig: StoreConfig): any; getStore>(storeName: string): TStore; removeStore(storeConfig: StoreConfig): any; updateStore(storeConfig: StoreConfig): any; loadData(): Promise; loadStoreData(storeName: string, input?: HttpRequestInput): Promise; notifyEvent(event: RuiEvent): Promise; } export declare type RockInitContext = { framework: Framework; page: IPage; scope: IScope; }; export declare type FunctionMeta = { name: string; func: Function; }; export declare type EventActionHandler = EventActionHandler1 | EventActionHandler2; export declare type EventActionHandler1 = (eventName: string, framework: Framework, page: IPage, scope: IScope, sender: any, eventHandler: TEventActionConfig, eventArgs: any) => any; export declare type EventActionHandler2 = (event: RockEvent, handler: TEventActionConfig) => any; export declare type EventAction = { name: TEventActionConfig["$action"]; handler: EventActionHandler; }; export declare type FunctionConfig = { name: string; func: string | Function; };