Files
ui-lib/lib/types.d.ts
T
2026-11-23 17:22:07 +08:00

287 lines
7.6 KiB
TypeScript

export type GetTextCallback = (key: string, defaultValue?: string | null) => string;
export interface LanguageResource {
[key: string]: string | undefined | GetTextCallback;
r: GetTextCallback;
}
export interface OptionParamBase {
getText?: GetTextCallback;
}
export interface RectLike {
top?: number;
left?: number;
width?: number;
height?: number;
zIndex?: number;
}
export type BoxRect = Required<Omit<RectLike, 'zIndex'>>;
export interface SnapLine {
axis: 'x' | 'y';
pos: number;
}
export interface MovableOptions<T = void> {
movable: boolean;
resizable: boolean;
minSize?: number;
snapThreshold?: number;
snapToContainer?: boolean;
snapToSiblings?: boolean;
hoverSelector?: string;
hoverIgnore?: string;
dragSelector?: string;
resizerSelector?: string;
rootDragClass?: string;
context?: T;
onMoved?(this: T | undefined, rect: BoxRect): void;
onResizeStart?(this: T | undefined): void;
onResized?(this: T | undefined, rect: BoxRect): void;
onSnap?(this: T | undefined, guides: SnapLine[]): void;
}
export type MarkRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
export interface NotifyOption {
message: string | Node;
parent?: HTMLElement;
title?: string;
type?: "success" | "warning" | "error";
icon?: string;
persistent?: boolean;
timeout?: number;
onDismissed?: (auto?: boolean) => void;
}
export interface PopupRectParam {
collapsed?: boolean;
left?: number;
top?: number;
width?: number;
height?: number;
}
export interface Popup {
readonly container: HTMLElement | undefined;
title: string | HTMLElement;
loading: boolean;
get rect(): PopupRectParam | undefined;
set rect(r: PopupRectParam);
close(result?: any, animation?: boolean): void;
create(): HTMLDivElement;
show(parent?: HTMLElement, hidden?: boolean): Promise<HTMLElement> | undefined;
}
export interface PopupButton {
className?: string;
tabIndex?: number;
key?: string;
text: string;
isPrimary?: boolean;
trigger?: (popup: Popup, button?: PopupButton) => boolean | Promise<boolean> | string | number;
}
export interface PopupOptions {
/** 弹出框内容,可以是文本或者 html 元素 */
content: string | HTMLElement;
/** 弹出框标题,可以是文本或者 html 元素 */
title: string | HTMLElement;
/** 是否持久化显示 */
persistent?: boolean;
/** 是否包含遮罩层,默认为 `true` */
mask?: boolean;
/** 遮罩层 z-index */
zIndex?: number;
/** 是否在获取焦点时修改 z-index */
changeZIndex?: boolean;
/** 是否允许关闭 */
closable?: boolean;
/** 是否允许移动 */
movable?: boolean;
/** 是否允许修改大小 */
resizable?: boolean;
/** 最小宽度,默认 200 */
minWidth?: number;
/** 最小高度,默认 200 */
minHeight?: number;
/** 是否允许弹出框收折 */
collapsable?: boolean;
/** 弹出框的按钮定义集合 */
buttons?: PopupButton[];
/**
* 遮罩层显示或者隐藏时的回调函数
* @param this 当前 popup 对象
* @param masking 显示或隐藏遮罩层
*/
onMasking?: (this: Popup, masking: boolean) => void;
/**
* 移动结束时的回调函数
* @param this 当前 popup 对象
*/
onMoveEnded?: (this: Popup) => void;
/**
* 修改大小开始时的回调函数
* @param this 当前 popup 对象
*/
onResizeStarted?: (this: Popup) => void;
/**
* 修改大小中的回调函数
* @param this 当前 popup 对象
* @param x 坐标 x
* @param y 坐标 y
* @param width 当前宽度
* @param height 当前高度
*/
onResizing?: (this: Popup, x: number, y: number, width: number, height: number) => void;
/**
* 修改大小结束时的回调函数
* @param this 当前 popup 对象
*/
onResizeEnded?: (this: Popup) => void;
/**
* 弹出框关闭时的回调函数
*/
resolve?: (this: Popup, result: { result: any, popup: Popup }) => void;
}
export interface InputOptions {
tabIndex?: number;
default?: string;
placeholder?: string;
[key: string]: string;
}
/**
* 复选框选项
*/
export interface CheckboxOptions {
/** 样式类名 */
className?: string;
/** 是否可用 */
enabled?: boolean;
/** html 名称 */
name?: string;
/** 焦点索引 */
tabIndex?: number;
/** 是否为 switch 样式 */
switch?: boolean;
/** 样式分类 */
type?: "fa-light" | "fa-regular" | "fa-solid";
/** 标签 */
label?: string | HTMLElement;
/** 标签提示文本 */
title?: string;
/** 是否已选中 */
checked?: boolean;
/** 是否处于中间状态 */
indeterminate?: boolean;
/** 图片高度 */
imageHeight?: number;
/** 选中时显示的元素 */
checkedNode?: Element;
/** 未选中时显示的元素 */
uncheckedNode?: Element;
/** 自定义 html 属性 */
customAttributes?: { [key: string]: string };
/**
* 复选框选择状态改变时触发
* @param this 当前复选框对应的 HtmlInput 元素
* @param ev 选择事件对象
*/
onchange?: (this: HTMLInputElement, ev: Event) => any;
}
/**
* 数据项基础类型
*/
export interface DropdownItemBase {
__checked?: 0 | 1 | 2 | undefined;
__p?: string;
__level?: number;
}
/**
* 数据项类型
*/
export type DropdownItem = DropdownItemBase & Record<string, any>;
export interface Dropdown {
sourceFilter?: (this: Dropdown) => DropdownItem[];
onSelectedList?: (this: Dropdown, list: DropdownItem[]) => void;
onSelected?: (this: Dropdown, it?: DropdownItem) => void;
onExpanded?: (this: Dropdown) => void;
onCollapsed?: (this: Dropdown) => void;
create(): HTMLDivElement;
readonly multiSelect?: boolean;
readonly ignoreAll?: boolean;
disabled: boolean;
source: DropdownItem[];
readonly selected?: DropdownItem;
readonly selectedList: DropdownItem[];
select(selected?: string, silence?: boolean, ignoreCase?: boolean): boolean | undefined;
selectlist(selectedlist: string[], silence: boolean): boolean | undefined;
}
/** 下拉列表参数对象 */
export interface DropdownOptions {
/** 文本关键字 */
textKey?: string;
/** 值关键字 */
valueKey?: string;
/** 源码显示的关键字 */
htmlKey?: string;
/** 子集合的关键字 */
childKey?: string;
/** 最大输入长度 */
maxLength?: number;
/**
* 模板创建函数
* @param this 当前Dropdown
* @param it 下拉项目
* @returns 返回渲染的字符串
*/
htmlTemplate?: (this: Dropdown, it: DropdownItem) => string;
/** 是否允许多选 */
multiSelect?: boolean;
/** 选中值 */
selected?: string;
/** 选中的数组 */
selectedList?: string[];
/** 是否禁用 */
disabled?: boolean;
/** 是否支持输入 */
input?: boolean;
/** 是否支持搜索 */
search?: boolean;
/** 搜索的关键字数组 */
searchKeys?: string[];
/** 搜索提示文本,默认值取语言资源 `searchHolder` "Search..." */
searchPlaceholder?: string;
/** 焦点索引 */
tabIndex?: number;
/** 输入框的提示文本 */
placeholder?: string;
/** 是否固定为向下展开 */
slideFixed?: boolean;
/** 父元素,默认添加到头元素之后 */
wrapper?: HTMLElement;
/** 是否忽略 All 选项 */
ignoreAll?: boolean;
/** 获取文本的代理函数 */
getText?: GetTextCallback;
}