|
| 1 | +interface Translate { |
| 2 | + translate: string; |
| 3 | + args?: Array<TextContent>; |
| 4 | +} |
| 5 | +type TextContent = string | Translate | Array<TextContent>; |
| 6 | +type NormalizedTextContent = { |
| 7 | + type: "translate"; |
| 8 | + translate: string; |
| 9 | + args?: Array<string> | Array<NormalizedTextContent>; |
| 10 | +} | { |
| 11 | + type: "text"; |
| 12 | + text: string; |
| 13 | +} | { |
| 14 | + type: "array"; |
| 15 | + array: Array<NormalizedTextContent>; |
| 16 | +}; |
| 17 | +interface FormAction { |
| 18 | + form?: string; |
| 19 | + event?: string; |
| 20 | + eventArgs?: Array<unknown>; |
| 21 | + copyArgs?: boolean; |
| 22 | +} |
| 23 | +interface DualButtonForm { |
| 24 | + type: "dual-button"; |
| 25 | + title: TextContent; |
| 26 | + body?: TextContent; |
| 27 | + topButton: DualButtonElementButton; |
| 28 | + bottomButton: DualButtonElementButton; |
| 29 | +} |
| 30 | +type DualButtonElement = DualButtonElementButton; |
| 31 | +interface DualButtonElementButton { |
| 32 | + type: "button"; |
| 33 | + text: TextContent; |
| 34 | + action?: FormAction; |
| 35 | +} |
| 36 | +interface InputForm { |
| 37 | + type: "input"; |
| 38 | + title: TextContent; |
| 39 | + submit?: TextContent; |
| 40 | + elements: Array<InputElement>; |
| 41 | + action?: FormAction; |
| 42 | +} |
| 43 | +type InputValue = string | number | boolean; |
| 44 | +type InputElement = InputElementSlider | InputElementDropdown | InputElementText | InputElementToggle; |
| 45 | +type InputElementSlider = { |
| 46 | + type: "slider"; |
| 47 | + name?: string; |
| 48 | + text: TextContent; |
| 49 | + min: number; |
| 50 | + max: number; |
| 51 | + step: number; |
| 52 | + defaultValue?: number; |
| 53 | +}; |
| 54 | +type InputElementDropdown = { |
| 55 | + type: "dropdown"; |
| 56 | + name?: string; |
| 57 | + text: TextContent; |
| 58 | + defaultValue?: InputValue; |
| 59 | + options: Array<{ |
| 60 | + text: TextContent; |
| 61 | + value: InputValue; |
| 62 | + }>; |
| 63 | +}; |
| 64 | +type InputElementText = { |
| 65 | + type: "text"; |
| 66 | + name?: string; |
| 67 | + text: TextContent; |
| 68 | + placeholder: TextContent; |
| 69 | + defaultValue?: string; |
| 70 | +}; |
| 71 | +type InputElementToggle = { |
| 72 | + type: "toggle"; |
| 73 | + name?: string; |
| 74 | + text: TextContent; |
| 75 | + defaultValue?: boolean; |
| 76 | +}; |
| 77 | +interface MultiButtonForm { |
| 78 | + type: "multi-button"; |
| 79 | + title: TextContent; |
| 80 | + body?: TextContent; |
| 81 | + elements: Array<MultiButtonElement>; |
| 82 | +} |
| 83 | +type MultiButtonElement = MultiButtonElementButton; |
| 84 | +interface MultiButtonElementButton { |
| 85 | + type: "button"; |
| 86 | + text: TextContent; |
| 87 | + icon?: string; |
| 88 | + action?: FormAction; |
| 89 | +} |
| 90 | +type Form = MultiButtonForm | InputForm | DualButtonForm; |
| 91 | +interface ToString { |
| 92 | + toString(): string; |
| 93 | +} |
| 94 | +type StringResolvableMap = { |
| 95 | + [key: string]: StringResolvable; |
| 96 | +}; |
| 97 | +type StringResolvable = ToString | StringResolvableMap; |
| 98 | +declare class FormArguments { |
| 99 | + private _args; |
| 100 | + set(name: string, arg: StringResolvable): void; |
| 101 | + setAll(args: Record<string, StringResolvable>): void; |
| 102 | + getAll(): Record<string, StringResolvable>; |
| 103 | + get<Arg extends StringResolvable>(name: string): Arg; |
| 104 | + resolvePath(path: string): string; |
| 105 | + resolveTemplate(template: string): string; |
| 106 | + normalize(content: TextContent): NormalizedTextContent; |
| 107 | +} |
| 108 | +declare class FormError extends Error { |
| 109 | + constructor(msg: string); |
| 110 | +} |
| 111 | +declare class FormArgumentError extends FormError { |
| 112 | + readonly path: string; |
| 113 | + readonly step: string; |
| 114 | + readonly current: unknown; |
| 115 | + constructor(path: string, step: string, current: unknown); |
| 116 | +} |
| 117 | +interface FormHub { |
| 118 | + entrypoint: string; |
| 119 | + forms: Record<string, Form>; |
| 120 | +} |
| 121 | +declare class FormEvent { |
| 122 | + protected _form: Form | undefined; |
| 123 | + protected _name: string | undefined; |
| 124 | + protected _continueProcessing: boolean; |
| 125 | + protected readonly _hub: FormHub; |
| 126 | + protected _args: FormArguments; |
| 127 | + protected _eventArgs: Array<unknown>; |
| 128 | + constructor(hub: FormHub, action?: FormAction, previousArgs?: FormArguments); |
| 129 | + loadForm(name: string): Form; |
| 130 | + loadForm(name: string, type: "multi-button"): MultiButtonForm; |
| 131 | + loadForm(name: string, type: "input"): InputForm; |
| 132 | + loadForm(name: string, type: "dual-button"): InputForm; |
| 133 | + set form(form: Form | undefined); |
| 134 | + get form(): Form | undefined; |
| 135 | + get name(): string | undefined; |
| 136 | + get args(): FormArguments; |
| 137 | + get eventArgs(): unknown[]; |
| 138 | + get continueProcessing(): boolean; |
| 139 | + cancelProcessing(): void; |
| 140 | +} |
| 141 | +type EventReceiverFunction = (event: FormEvent) => Promise<void>; |
| 142 | +type EventReceiverMap = Record<string, EventReceiverFunction>; |
| 143 | +type EventReceiver = EventReceiverFunction | EventReceiverMap | undefined; |
| 144 | +declare const triggerEvent: (event: FormEvent, receiver: EventReceiver) => Promise<Form | undefined>; |
| 145 | +declare const _: (value: string) => Translate; |
| 146 | +export { InputForm, MultiButtonForm, MultiButtonElement, MultiButtonElementButton, DualButtonForm, DualButtonElement, DualButtonElementButton, Form, StringResolvable, FormArguments, FormError, FormArgumentError, FormEvent, EventReceiver, triggerEvent, FormHub, Translate, TextContent, NormalizedTextContent, FormAction, _ }; |
0 commit comments