Skip to content

Commit 1b29c8b

Browse files
authored
🤖 Merge PR DefinitelyTyped#74646 feat(types/layui): Update typings to v2.13.4 by @Sight-wcg
1 parent 7a23f66 commit 1b29c8b

37 files changed

+1221
-280
lines changed

types/layui/index.d.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
/// <reference types="jquery" />
2+
/// <reference path="modules/breadcrumb.d.ts" />
23
/// <reference path="modules/carousel.d.ts" />
34
/// <reference path="modules/code.d.ts" />
5+
/// <reference path="modules/collapse.d.ts" />
46
/// <reference path="modules/colorpicker.d.ts" />
57
/// <reference path="modules/component.d.ts" />
68
/// <reference path="modules/dropdown.d.ts" />
79
/// <reference path="modules/element.d.ts" />
810
/// <reference path="modules/flow.d.ts" />
911
/// <reference path="modules/form.d.ts" />
12+
/// <reference path="modules/i18n.d.ts" />
1013
/// <reference path="modules/lay.d.ts" />
1114
/// <reference path="modules/laydate.d.ts" />
1215
/// <reference path="modules/layedit.d.ts" />
1316
/// <reference path="modules/layer.d.ts" />
1417
/// <reference path="modules/laypage.d.ts" />
1518
/// <reference path="modules/laytpl.d.ts" />
19+
/// <reference path="modules/nav.d.ts" />
20+
/// <reference path="modules/progress.d.ts" />
1621
/// <reference path="modules/rate.d.ts" />
1722
/// <reference path="modules/slider.d.ts" />
23+
/// <reference path="modules/tab.d.ts" />
1824
/// <reference path="modules/table.d.ts" />
1925
/// <reference path="modules/tabs.d.ts" />
2026
/// <reference path="modules/transfer.d.ts" />
@@ -28,19 +34,11 @@
2834
declare const layui: Layui;
2935
declare const lay: Layui.LayStatic;
3036
declare const layer: Layui.Layer;
31-
/**
32-
* 动态加载等特殊场景设置 layui 目录
33-
* @since 2.6.6
34-
*/
35-
declare const LAYUI_GLOBAL: { dir: string };
37+
declare const LAYUI_GLOBAL: Layui.GlobalProperties;
3638

3739
interface Window {
3840
layui: Layui;
3941
lay: Layui.LayStatic;
4042
layer: Layui.Layer;
41-
/**
42-
* 动态加载等特殊场景设置 layui 目录
43-
* @since 2.6.6
44-
*/
45-
LAYUI_GLOBAL: { dir: string };
43+
LAYUI_GLOBAL: Layui.GlobalProperties;
4644
}

types/layui/misc.d.ts

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,33 @@ declare namespace Layui {
1818
};
1919
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
2020
type LiteralStringUnion<T> = LiteralUnion<T, string>;
21+
type ObjectPathLeaf = Primitive | AnyFn | Date | Array<any>;
22+
type DeepPath<T, Prefix extends string = ""> = {
23+
[K in keyof T & string]: T[K] extends ObjectPathLeaf ? `${Prefix}${K}`
24+
: T[K] extends object ? DeepPath<T[K], `${Prefix}${K}.`>
25+
: never;
26+
}[keyof T & string];
27+
type DeepType<T, Path extends string> = Path extends `${infer Key}.${infer Rest}`
28+
? Key extends keyof T ? DeepType<T[Key], Rest>
29+
: T extends any[] ? DeepType<T[number], Rest>
30+
: never
31+
: Path extends keyof T ? T[Path]
32+
: T extends any[] ? T[number]
33+
: never;
34+
type DeepPartial<T> = T extends AnyFn ? T
35+
: T extends Date ? T
36+
: T extends Array<infer U> ? Array<DeepPartial<U>>
37+
: T extends Map<infer K, infer V> ? Map<K, DeepPartial<V>>
38+
: T extends Set<infer U> ? Set<DeepPartial<U>>
39+
: T extends object ? { [P in keyof T]?: DeepPartial<T[P]> }
40+
: T;
2141

2242
type Selector = string;
2343
type ExportsCallback = (this: Layui, fn: (app: string, exports: object) => void) => void;
2444

2545
/**
26-
* 全局属性
46+
* 全局配置选项
47+
* layui.config(options)
2748
*/
2849
interface GlobalConfigOptions {
2950
/**
@@ -44,6 +65,22 @@ declare namespace Layui {
4465
base?: string;
4566
}
4667

68+
/**
69+
* window.LAYUI_GLOBAL
70+
*/
71+
interface GlobalProperties {
72+
/**
73+
* 动态加载等特殊场景设置 layui 目录
74+
* @since 2.6.6
75+
*/
76+
dir?: string;
77+
/**
78+
* 国际化消息对象
79+
* @since 2.13.0
80+
*/
81+
i18n?: I18nMessages;
82+
}
83+
4784
/**
4885
* 缓存的所有数据
4986
*/
@@ -98,6 +135,12 @@ declare namespace Layui {
98135
* @internal
99136
*/
100137
all: any;
138+
/**
139+
* 面包屑
140+
* @see https://layui.dev/docs/2/nav/#separator
141+
* @since 2.13.0
142+
*/
143+
breadcrumb: Breadcrumb;
101144
/**
102145
* 轮播
103146
* @see https://layui.dev/docs/2/carousel/
@@ -108,6 +151,12 @@ declare namespace Layui {
108151
* @see https://layui.dev/docs/2/code/
109152
*/
110153
code: Code;
154+
/**
155+
* 折叠面板
156+
* @see https://layui.dev/docs/2/panel/
157+
* @since 2.13.0
158+
*/
159+
collapse: Collapse;
111160
/**
112161
* 颜色选择器
113162
* @see https://layui.dev/docs/2/colorpicker/
@@ -132,7 +181,7 @@ declare namespace Layui {
132181
* @see https://layui.dev/docs/2/progress/ - 进度条
133182
* @see https://layui.dev/docs/2/nav/#separator - 面包屑
134183
*/
135-
element: Element;
184+
element: LayElement;
136185
/**
137186
* 流加载
138187
* @see https://layui.dev/docs/2/flow/
@@ -181,6 +230,18 @@ declare namespace Layui {
181230
* @internal
182231
*/
183232
"layui.all": string;
233+
/**
234+
* 导航栏
235+
* @see https://layui.dev/docs/2/nav/
236+
* @since 2.13.0
237+
*/
238+
nav: Nav;
239+
/**
240+
* 进度条
241+
* @see https://layui.dev/docs/2/progress/
242+
* @since 2.13.0
243+
*/
244+
progress: Progress;
184245
/**
185246
* 评分
186247
* @see https://layui.dev/docs/2/rate/
@@ -192,6 +253,13 @@ declare namespace Layui {
192253
* @see https://layui.dev/docs/2/slider/
193254
*/
194255
slider: Slider;
256+
/**
257+
* 选项卡
258+
* @see https://layui.dev/docs/2/tab/
259+
* @since 2.13.0
260+
* @deprecated 已废弃,使用 {@link Tabs}
261+
*/
262+
tab: Tab;
195263
/**
196264
* 表格
197265
* @see https://layui.dev/docs/2/table
@@ -230,6 +298,12 @@ declare namespace Layui {
230298
* @see https://layui.dev/docs/2/util/
231299
*/
232300
util: Util;
301+
/**
302+
* 国际化
303+
* @see https://layui.dev/docs/2/i18n/
304+
* @since 2.12.0
305+
*/
306+
i18n: I18n;
233307
}
234308

235309
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
declare namespace Layui {
2+
interface BreadcrumbOptions {
3+
/**
4+
* 组件渲染指定的目标元素选择器或 DOM 对象
5+
*/
6+
elem: string | HTMLElement | JQuery;
7+
}
8+
9+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
10+
class BreadcrumbClass extends Component<BreadcrumbOptions> {
11+
}
12+
13+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
14+
interface BreadcrumbReturn extends ComponentReturn<BreadcrumbOptions> {
15+
}
16+
17+
interface Breadcrumb extends ComponentInterface<BreadcrumbOptions, BreadcrumbClass, BreadcrumbReturn> {
18+
/**
19+
* 渲染面包屑组件
20+
* @param options 面包屑组件的配置选项
21+
*/
22+
render(options: BreadcrumbOptions): BreadcrumbReturn;
23+
}
24+
}

types/layui/modules/carousel.d.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ declare namespace Layui {
9191
item: JQuery;
9292
}
9393

94-
interface CarouselClass {
94+
class CarouselClass extends Component<CarouselOptions> {
9595
/**
9696
* 配置属性
9797
*/
@@ -175,28 +175,34 @@ declare namespace Layui {
175175
goto(index: number): void;
176176
}
177177

178+
interface CarouselReturn extends ComponentReturn<CarouselOptions> {
179+
/**
180+
* 切换到指定的索引
181+
* @param index 轮播下标,从 0 开始计算
182+
* @since 2.8.0
183+
*/
184+
goto(index: number): void;
185+
elemInd: any;
186+
elemItem: any;
187+
timer: any;
188+
}
189+
178190
/**
179191
* 轮播
180192
* @see https://layui.dev/docs/2/carousel/
193+
* @since 2.13.0 之后继承自 Component 组件
181194
*/
182-
interface Carousel {
183-
config: Required<CarouselOptions>;
195+
interface Carousel extends ComponentInterface<CarouselOptions, CarouselClass, CarouselReturn> {
184196
/**
185197
* 渲染方法
186198
* @param options 基础参数
187-
* @return 实例对象,包含操作当前实例的相关成员方法
188199
*/
189-
render(options: CarouselOptions): CarouselClass;
200+
render(options: CarouselOptions): CarouselReturn;
190201
/**
191202
* 绑定切换事件
192203
* @param event 事件
193204
* @param callback 回调
194205
*/
195206
on(event: string, callback: (this: CarouselClass, obj: CarouselItem) => any): any;
196-
/**
197-
* 设置轮播组件的全局参数
198-
* @param options 基础参数
199-
*/
200-
set(options: Partial<CarouselOptions>): this;
201207
}
202208
}

types/layui/modules/code.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,55 @@ declare namespace Layui {
196196
* @since 2.8.18
197197
*/
198198
code?: string;
199+
/**
200+
* 设置行高亮
201+
* @since 2.12.0
202+
*/
203+
highlightLine?: {
204+
/**
205+
* 高亮
206+
*/
207+
hl?: CodeHighlightLineOptions;
208+
/**
209+
* diff++
210+
*/
211+
"++"?: CodeHighlightLineOptions;
212+
/**
213+
* diff--
214+
*/
215+
"--"?: CodeHighlightLineOptions;
216+
/**
217+
* 聚焦
218+
*/
219+
focus?: CodeHighlightLineOptions;
220+
} & Record<string, CodeHighlightLineOptions>;
221+
}
222+
223+
interface CodeHighlightLineOptions {
224+
/**
225+
* 高亮范围,不可全局设置值
226+
* @example
227+
* '1,3-5,8'
228+
*/
229+
range: string;
230+
/**
231+
* 是否解析行内的特定高亮注释。出于性能考虑,不建议全局开启。
232+
*
233+
* 注释格式:`[!code <type>:<lines>]`
234+
* - `<type>` : `highlightLine` 的可选项,如 `hl, focus` 等
235+
* - `<lines>` : 行数(含本行)
236+
*/
237+
comment?: boolean;
238+
/**
239+
* 添加到高亮行上的类
240+
* @internal
241+
*/
242+
classActiveLine?: string;
243+
/**
244+
* 有高亮行时向根元素添加的类
245+
* @internal
246+
*/
247+
classActivePre?: string;
199248
}
200249

201250
interface CodeReturn {

types/layui/modules/collapse.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare namespace Layui {
2+
interface CollapseOptions {
3+
/**
4+
* 组件渲染指定的目标元素选择器或 DOM 对象
5+
*/
6+
elem: string | HTMLElement | JQuery;
7+
}
8+
9+
interface CollapseEventMap {
10+
/**
11+
* 折叠面板点击事件
12+
* @param data 事件对象
13+
* - `title` 折叠面板标题元素
14+
* - `content` 折叠面板内容元素
15+
* - `show` 折叠面板是否展开,true 为展开状态,false 为收起状态
16+
*/
17+
collapse(this: HTMLElement, data: { title: JQuery; content: JQuery; show: boolean }): void;
18+
}
19+
20+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
21+
class CollapseClass extends Component<CollapseOptions> {
22+
}
23+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
24+
interface CollapseReturn extends ComponentReturn<CollapseOptions> {
25+
}
26+
27+
interface Collapse extends ComponentInterface<CollapseOptions, CollapseClass, CollapseReturn> {
28+
/**
29+
* 渲染折叠面板组件
30+
* @param options 折叠面板组件的配置选项
31+
*/
32+
render(options: CollapseOptions): CollapseReturn;
33+
}
34+
}

types/layui/modules/colorpicker.d.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,16 @@ declare namespace Layui {
7171
/**
7272
* 颜色选择器
7373
* @see https://layui.dev/docs/2/colorpicker/
74+
* @since 2.13.0 之后继承自 Component 组件
7475
*/
75-
interface ColorPicker {
76-
config: Record<string, any>;
77-
index: number;
76+
interface ColorPicker
77+
extends
78+
ComponentInterface<ColorPickerOptions, Component<ColorPickerOptions>, ComponentReturn<ColorPickerOptions>>
79+
{
7880
/**
7981
* colorpicker 组件渲染方法
8082
* @param option 属性选项
8183
*/
82-
render(option: ColorPickerOptions): ColorPicker;
83-
/**
84-
* 全局设置
85-
* @param option 属性选项
86-
*/
87-
set(option: ColorPickerOptions): ColorPicker;
88-
/**
89-
* 绑定切换事件
90-
* @param event 事件名
91-
* @param callback 回调函数
92-
*/
93-
on(event: string, callback: (this: Layui, params: any) => any): any;
84+
render(option: ColorPickerOptions): ComponentReturn<ColorPickerOptions>;
9485
}
9586
}

0 commit comments

Comments
 (0)