/// import { Aspect, EntityDict, CheckerType, AggregationResult, SubDataDef, OpRecord } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from './Feature'; import { Pagination } from "./Pagination"; import { BasicFeatures } from "../features"; import { NamedFilterItem, NamedSorterItem } from './NamedCondition'; import { NotificationProps } from './Notification'; import { MessageProps } from './Message'; import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore"; import { SyncContext } from "oak-domain/lib/store/SyncRowStore"; import React from "react"; export type DataOption = WechatMiniprogram.Component.DataOption; export type MethodOption = WechatMiniprogram.Component.MethodOption; /** * 微信的原声明中少写了FunctionConstructor,只能抄一遍 */ export type ActionDef = { action: ED[T]['Action']; filter?: ED[T]['Selection']['filter']; data?: Partial; label?: string; color?: string; key?: string; } | ED[T]['Action']; export type RowWithActions = Partial & { '#oakLegalActions': ActionDef[]; '#oakLegalCascadeActions': { [K in keyof ED[T]['Schema']]?: ActionDef[]; }; }; type FeatureDef, FrontCxt extends SyncContext, AD extends Record>, FD extends Record> = (keyof (FD & BasicFeatures>)) | { feature: keyof (FD & BasicFeatures>); behavior: 'reRender' | 'refresh'; }; interface ComponentOption, FrontCxt extends SyncContext, AD extends Record>, FD extends Record, FormedData extends Record, TData extends DataOption, TProperty extends DataOption, TMethod extends Record, EMethod extends Record = {}> { isList?: IsList; getTotal?: { max: number; deviceWidth?: 'pc' | 'mobile' | 'all'; } | number; entity?: T | ((this: ComponentPublicThisType) => T); path?: string; features?: FeatureDef[]; cascadeActions?: (this: ComponentPublicThisType) => { [K in keyof ED[T]['Schema']]?: ActionDef[]; }; actions?: ActionDef[] | ((this: ComponentPublicThisType) => ActionDef[]); projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType) => ED[T]['Selection']['data'] | undefined); append?: boolean; pagination?: Pagination; filters?: Array<{ filter: NonNullable | ((this: ComponentPublicThisType) => ED[T]['Selection']['filter'] | undefined); '#name'?: string; }>; sorters?: Array<{ sorter: NonNullable[number] | ((this: ComponentPublicThisType) => ED[T]['Selection']['sorter'] | NonNullable[number]); '#name'?: string; }>; formData?: (options: { data: IsList extends true ? RowWithActions[] : RowWithActions | undefined; features: BasicFeatures> & FD; props: TProperty; legalActions?: ActionDef[]; }) => FormedData; ns?: T | T[]; data?: ((this: ComponentPublicThisType) => TData) | TData; properties?: TProperty; methods?: TMethod; } export type MiniprogramStyleMethods = { animate(selector: string, keyFrames: WechatMiniprogram.Component.KeyFrame[], duration: number, callback?: () => void): void; clearAnimation(selector: string, options?: WechatMiniprogram.Component.ClearAnimationOptions, callback?: () => void): void; triggerEvent: (name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; }; export type ComponentProps = IsList extends true ? OakListComponentProperties & OakComponentProperties & Partial : OakComponentProperties & Partial; export type ReactComponentProps = ComponentProps & { className?: string; style?: Record; }; export type ComponentData = TData & FormedData & OakComponentData; export type ComponentPublicThisType, FrontCxt extends SyncContext, AD extends Record>, FD extends Record, FormedData extends Record, IsList extends boolean, TData extends Record = {}, TProperty extends DataOption = {}, TMethod extends MethodOption = {}, EMethod extends Record = {}> = { subscribed: Array<() => void>; features: FD & BasicFeatures>; state: ComponentData; props: Readonly>; setState: (data: Partial>, callback?: () => void) => void; triggerEvent: (name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; } & TMethod & EMethod & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; export type ComponentFullThisType, FrontCxt extends SyncContext> = { subscribed: Array<() => void>; features: BasicFeatures>; state: OakComponentData; props: ComponentProps; setState: (data: Partial>, callback?: () => void) => void; triggerEvent: (name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; } & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; export type OakComponentOption, FrontCxt extends SyncContext, AD extends Record>, FD extends Record, FormedData extends Record, TData extends Record, TProperty extends DataOption, TMethod extends Record, EMethod extends Record = {}> = ComponentOption & Partial<{ lifetimes: { created?(): void; attached?(): void; ready?(): void; moved?(): void; detached?(): void; error?(err: Error): void; show?(): void; hide?(): void; }; listeners: Record, prev: Record, next: Record) => void>; }> & Partial<{ wechatMp: { externalClasses?: string[]; options?: Partial | undefined; }; }> & ThisType>; export type OakComponentProperties = Partial<{ width?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'; oakPath: string; oakId: string; oakFrom: string; oakParentEntity: string; oakDisablePulldownRefresh: boolean; oakAutoUnmount: boolean; oakActions: string; oakCascadeActions: string; }>; export type OakListComponentProperties = Partial<{}>; export type OakNavigateToParameters = { oakId?: string; oakPath?: string; oakParent?: string; [k: string]: any; }; export type OakCommonComponentMethods = { unsubscribeAll: () => void; subEvent: (type: string, callback: Function) => void; unsubEvent: (type: string, callback: Function) => void; pubEvent: (type: string, options?: any) => void; unsubAllEvents: (type: string) => void; save: (key: string, item: any) => Promise; load: (key: string) => Promise; clear: (key?: string) => Promise; setNotification: (data: NotificationProps) => void; consumeNotification: () => NotificationProps | undefined; setMessage: (data: MessageProps) => void; consumeMessage: () => MessageProps | undefined; reRender: (extra?: Record) => void; getFreshValue: (path?: string) => Partial[] | Partial | undefined; navigateTo: (options: { url: string; } & OakNavigateToParameters, state?: Record, disableNamespace?: boolean) => Promise; navigateBack: (delta?: number) => Promise; redirectTo: (options: Parameters[0] & OakNavigateToParameters, state?: Record, disableNamespace?: boolean) => Promise; switchTab: (options: Parameters[0] & OakNavigateToParameters, state?: Record, disableNamespace?: boolean) => Promise; clean: (path?: string) => void; isDirty: (path?: string) => boolean; t(key: string, params?: object): string; execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps, path?: string) => Promise; checkOperation: (entity: T, action: ED[T]['Action'], data?: ED[T]['Update']['data'], filter?: ED[T]['Update']['filter'], checkerTypes?: CheckerType[]) => boolean; tryExecute: (path?: string) => boolean | Error; getOperations: (path?: string) => { operation: ED[T]['Operation']; entity: T; }[] | undefined; refresh: () => Promise; aggregate: (aggregation: ED[T]['Aggregation']) => Promise>; subData: (data: SubDataDef[], callback?: (records: OpRecord[], ids: string[]) => void) => Promise; unSubData: (ids: string[]) => Promise; }; export type OakSingleComponentMethods = { setId: (id: string) => void; unsetId: () => void; getId: () => string | undefined; create: (data: Omit, path?: string) => void; update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], path?: string) => void; remove: (path?: string) => void; isCreation: (path?: string) => boolean; }; export type OakListComponentMethods = { loadMore: () => Promise; setFilters: (filters: NamedFilterItem[], path?: string) => void; getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined; getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined; addNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => void; setNamedFilters: (filters: NamedFilterItem[], refresh?: boolean, path?: string) => void; removeNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => void; removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void; setNamedSorters: (sorters: NamedSorterItem[], refresh?: boolean, path?: string) => void; getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined; getSorterByName: (name: string, path?: string) => NonNullable[number] | undefined; addNamedSorter: (sorter: NamedSorterItem, refresh?: boolean, path?: string) => void; removeNamedSorter: (sorter: NamedSorterItem, refresh?: boolean, path?: string) => void; removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => void; getPagination: (path?: string) => Pagination | undefined; setPageSize: (pageSize: number, path?: string) => void; setCurrentPage: (current: number, path?: string) => void; addItem: (data: Omit, path?: string) => string; removeItem: (id: string, path?: string) => void; updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], path?: string) => void; recoverItem: (id: string, path?: string) => void; resetItem: (id: string, path?: string) => void; }; type ComponentOnPropsChangeOption = { path?: string; parent?: string; }; export type OakComponentOnlyMethods = { onPropsChanged: (options: ComponentOnPropsChangeOption) => void; registerReRender: () => void; setOakActions: () => void; }; export type OakComponentData = { oakExecutable: boolean | Error; oakExecuting: boolean; oakFocused: { attr: string; message: string; }; oakDirty: boolean; oakLoading: boolean; oakLoadingMore: boolean; oakPullDownRefreshLoading: boolean; oakEntity: T; oakFullpath: string; oakLegalActions?: ED[T]['Action'][]; oakLocales: Record; oakLocalesVersion: number; oakLng: string; oakDefaultLng: string; }; type OakListComoponetData = { oakPagination?: Pagination; }; export type MakeOakComponent, FrontCxt extends SyncContext, AD extends Record>, FD extends Record> = (options: OakComponentOption) => (props: ReactComponentProps) => React.ReactElement; export type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'aggregate' | 'checkOperation' | 'isDirty'; export type WebComponentListMethodNames = 'loadMore' | 'setFilters' | 'addNamedFilter' | 'removeNamedFilter' | 'removeNamedFilterByName' | 'setNamedSorters' | 'addNamedSorter' | 'removeNamedSorter' | 'removeNamedSorterByName' | 'setPageSize' | 'setCurrentPage' | 'addItem' | 'removeItem' | 'updateItem' | 'resetItem' | 'recoverItem'; export type WebComponentSingleMethodNames = 'update' | 'remove' | 'create' | 'isCreation'; export type WebComponentProps = { methods: TMethod & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; data: TData & OakComponentData & (IsList extends true ? OakListComoponetData : { oakId?: string; }); }; export {};