Skip to content

Commit 7b986a2

Browse files
authored
🤖 Merge PR DefinitelyTyped#71743 Support for winbox 0.2.82 types by @rijnb
1 parent b11fef1 commit 7b986a2

File tree

5 files changed

+145
-310
lines changed

5 files changed

+145
-310
lines changed

attw.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@
362362
"webidl2",
363363
"webscopeio__react-textarea-autocomplete",
364364
"when",
365-
"winbox",
366365
"wnumb",
367366
"yargs-parser",
368367
"yargs-parser/v20",

types/winbox/index.d.ts

Lines changed: 121 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,157 @@
1-
export as namespace WinBox;
1+
interface WinBoxControlType {
2+
class?: string;
3+
image?: string;
4+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
5+
click?: Function;
6+
index?: number;
7+
}
28

39
interface WinBox {
10+
id: string | number;
11+
title: string;
412
dom: Node;
5-
background: string;
13+
window: Node;
14+
index: number;
615
body: HTMLElement;
7-
border: string | number;
16+
header: number;
817

9-
class: string | string[];
18+
x: string | number;
19+
y: string | number;
20+
width: string | number;
21+
height: string | number;
22+
minwidth: string | number;
23+
minheight: string | number;
24+
maxwidth: string | number;
25+
maxheight: string | number;
26+
left: string | number;
27+
right: string | number;
28+
top: string | number;
29+
bottom: string | number;
1030

11-
html: string;
12-
id: string | number;
13-
index: number;
31+
overflow: boolean;
32+
min: boolean;
1433
max: boolean;
15-
modal: boolean;
16-
root: Node;
17-
title: string;
18-
url: string;
34+
full: boolean;
35+
hidden: boolean;
36+
focused: boolean;
37+
38+
onclose: (this: WinBox, force: boolean) => boolean;
1939
onfocus: (this: WinBox) => void;
2040
onblur: (this: WinBox) => void;
21-
onresize: (this: WinBox, width: number, height: number) => void;
2241
onmove: (this: WinBox, x: number, y: number) => void;
23-
onclose: (this: WinBox, force: boolean) => boolean;
42+
onresize: (this: WinBox, width: number, height: number) => void;
43+
onfullscreen: (this: WinBox) => void;
44+
onmaximize: (this: WinBox) => void;
45+
onminimize: (this: WinBox) => void;
46+
onrestore: (this: WinBox) => void;
47+
onhide: (this: WinBox) => void;
48+
onshow: (this: WinBox) => void;
49+
2450
mount(src?: Element): WinBox;
51+
2552
unmount(dest?: Element): WinBox;
53+
2654
setTitle(title: string): WinBox;
55+
56+
setIcon(url: string): WinBox;
57+
2758
setBackground(background: string): WinBox;
59+
2860
setUrl(url: string): WinBox;
29-
focus(): WinBox;
30-
hide(): WinBox;
31-
show(): WinBox;
61+
62+
focus(state?: boolean): WinBox;
63+
64+
blur(state?: boolean): WinBox;
65+
66+
hide(state?: boolean): WinBox;
67+
68+
show(state?: boolean): WinBox;
69+
3270
minimize(state?: boolean): WinBox;
71+
72+
restore(): WinBox;
73+
3374
maximize(state?: boolean): WinBox;
75+
3476
fullscreen(state?: boolean): WinBox;
35-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
36-
close(force?: boolean): boolean | void;
77+
78+
close(force?: boolean): boolean | undefined;
79+
3780
move(x?: string | number, y?: string | number, skipUpdate?: boolean): WinBox;
81+
3882
resize(w?: string | number, h?: string | number, skipUpdate?: boolean): WinBox;
83+
84+
addControl(control: WinBoxControlType): WinBox;
85+
86+
removeControl(control: WinBoxControlType): WinBox;
87+
3988
addClass(classname: string): WinBox;
89+
4090
removeClass(classname: string): WinBox;
91+
92+
hasClass(classname: string): WinBox;
93+
94+
toggleClass(classname: string): WinBox;
4195
}
96+
4297
declare namespace WinBox {
4398
interface WinBoxConstructor {
4499
(title: string, params?: Params): WinBox;
100+
45101
(params: Params): WinBox;
102+
46103
new(title: string, params?: Params): WinBox;
104+
47105
new(params: Params): WinBox;
48106
}
49107

50108
interface Params {
51-
background?: string | undefined;
52-
body?: HTMLElement | undefined;
53-
border?: string | number | undefined;
54-
bottom?: string | number | undefined;
55-
class?: string | string[] | undefined;
56-
height?: string | number | undefined;
57-
html?: string | undefined;
58-
id?: string | number | undefined;
59-
index?: number | undefined;
60-
left?: string | number | undefined;
61-
max?: boolean | undefined;
62-
minheight?: string | number | undefined;
63-
minwidth?: string | number | undefined;
64-
modal?: boolean | undefined;
65-
mount?: Node | undefined;
66-
right?: string | number | undefined;
67-
root?: Node | undefined;
68-
splitscreen?: boolean | undefined;
69-
title?: string | undefined;
70-
top?: string | number | undefined;
71-
url?: string | undefined;
72-
width?: string | number | undefined;
73-
x?: "right" | "center" | string | number | undefined;
74-
y?: "bottom" | "center" | string | number | undefined;
75-
onclose?: ((this: WinBox, force?: boolean) => boolean) | undefined;
76-
onfocus?: ((this: WinBox) => void) | undefined;
77-
onblur?: ((this: WinBox) => void) | undefined;
78-
onresize?: ((this: WinBox, width: number, height: number) => void) | undefined;
79-
onmove?: ((this: WinBox, x: number, y: number) => void) | undefined;
80-
}
109+
id?: string;
110+
index?: number;
111+
root?: Node;
112+
tpl?: Node;
113+
title?: string;
114+
icon?: string;
115+
mount?: Node;
116+
html?: string;
117+
url?: string;
81118

82-
interface Params {
83-
background?: string | undefined;
84-
body?: HTMLElement | undefined;
85-
border?: string | number | undefined;
86-
bottom?: string | number | undefined;
87-
class?: string | string[] | undefined;
88-
height?: string | number | undefined;
89-
html?: string | undefined;
90-
id?: string | number | undefined;
91-
index?: number | undefined;
92-
left?: string | number | undefined;
93-
max?: boolean | undefined;
94-
modal?: boolean | undefined;
95-
mount?: Node | undefined;
96-
right?: string | number | undefined;
97-
root?: Node | undefined;
98-
title?: string | undefined;
99-
top?: string | number | undefined;
100-
url?: string | undefined;
101-
width?: string | number | undefined;
102-
x?: "right" | "center" | string | number | undefined;
103-
y?: "bottom" | "center" | string | number | undefined;
104-
onclose?: ((this: WinBox, force?: boolean) => boolean) | undefined;
105-
onfocus?: ((this: WinBox) => void) | undefined;
106-
onblur?: ((this: WinBox) => void) | undefined;
107-
onresize?: ((this: WinBox, width: number, height: number) => void) | undefined;
108-
onmove?: ((this: WinBox, x: number, y: number) => void) | undefined;
119+
x?: "right" | "center" | string | number;
120+
y?: "bottom" | "center" | string | number;
121+
width?: string | number;
122+
height?: string | number;
123+
minwidth?: string | number;
124+
minheight?: string | number;
125+
maxwidth?: string | number;
126+
maxheight?: string | number;
127+
left?: string | number;
128+
right?: string | number;
129+
top?: string | number;
130+
bottom?: string | number;
131+
132+
min?: boolean;
133+
max?: boolean;
134+
hidden?: boolean;
135+
modal?: boolean;
136+
137+
background?: string;
138+
border?: string | number;
139+
header?: number;
140+
class?: string | string[];
141+
142+
oncreate?: (this: WinBox, params?: Params) => void;
143+
onclose?: (this: WinBox, force?: boolean) => boolean;
144+
onfocus?: (this: WinBox) => void;
145+
onblur?: (this: WinBox) => void;
146+
onmove?: (this: WinBox, x: number, y: number) => void;
147+
onresize?: (this: WinBox, width: number, height: number) => void;
148+
onfullscreen?: (this: WinBox) => void;
149+
onminimize?: (this: WinBox) => void;
150+
onmaximize?: (this: WinBox) => void;
151+
onrestore?: (this: WinBox) => void;
152+
onhide?: (this: WinBox) => void;
153+
onshow?: (this: WinBox) => void;
154+
onload?: (this: WinBox) => void;
109155
}
110156
}
111157

types/winbox/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"private": true,
3+
"type": "module",
34
"name": "@types/winbox",
45
"version": "0.2.9999",
56
"projects": [
Lines changed: 2 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,4 @@
1-
declare const content: HTMLElement;
2-
1+
// @ts-expect-error
32
WinBox.new("Basic Window");
43

5-
WinBox.new("Custom Root", {
6-
root: document.body,
7-
});
8-
9-
WinBox("Basic Window");
10-
11-
WinBox("Custom Root", {
12-
root: document.body,
13-
});
14-
15-
new WinBox("Basic Window");
16-
17-
new WinBox("Custom Root", {
18-
root: document.body,
19-
});
20-
new WinBox("Custom Border", {
21-
border: "0.3em",
22-
});
23-
24-
new WinBox({
25-
title: "Custom Color",
26-
background: "#ff005d",
27-
border: 4,
28-
});
29-
30-
new WinBox("Limit Viewport", {
31-
top: 50,
32-
right: 50,
33-
bottom: 0,
34-
left: 50,
35-
});
36-
37-
new WinBox({
38-
title: "Custom Position / Size",
39-
x: "center",
40-
y: "center",
41-
width: "50%",
42-
height: "50%",
43-
});
44-
45-
new WinBox({
46-
title: "Window",
47-
y: "center",
48-
x: "center",
49-
width: "50%",
50-
});
51-
52-
new WinBox("Modal Window", {
53-
modal: true,
54-
});
55-
56-
new WinBox({
57-
title: "Set innerHTML",
58-
html: "<h1>Lorem Ipsum</h1>",
59-
});
60-
61-
new WinBox("Mount DOM", {
62-
mount: content.cloneNode(true),
63-
});
64-
65-
new WinBox("Mount DOM", {
66-
mount: content,
67-
});
68-
69-
new WinBox("WinBox.js", {
70-
url: "https://nextapps-de.github.io/winbox/",
71-
class: "iframe",
72-
});
73-
74-
new WinBox({
75-
background: "#fff",
76-
border: 4,
77-
bottom: 0,
78-
class: ["no-full", "my-theme"],
79-
height: 200,
80-
html: "width: 200, height: 200",
81-
id: "my-window",
82-
index: 50,
83-
left: 50,
84-
max: false,
85-
minwidth: 50,
86-
minheight: 50,
87-
right: 50,
88-
root: document.body,
89-
splitscreen: true,
90-
title: "All Options",
91-
top: 50,
92-
width: 200,
93-
x: "center",
94-
y: "center",
95-
onfocus() {
96-
this.setBackground("#fff");
97-
},
98-
onblur() {
99-
this.setBackground("#999");
100-
},
101-
onresize(width, height) {
102-
this.body.textContent = `width: ${width}, height: ${height}`;
103-
},
104-
onmove(x, y) {
105-
this.body.textContent = `x: ${x}, y: ${y}`;
106-
},
107-
onclose(force) {
108-
return !force && !window.confirm("Are you sure to close window?");
109-
},
110-
});
111-
112-
new WinBox("Custom CSS", {
113-
class: "custom",
114-
mount: content.cloneNode(true),
115-
});
116-
117-
new WinBox("Custom CSS (Class)", {
118-
class: "my-theme",
119-
mount: content.cloneNode(true),
120-
});
121-
122-
new WinBox("Theme: Modern", {
123-
class: "modern",
124-
mount: content.cloneNode(true),
125-
});
126-
127-
const winbox = new WinBox("Controls", {
128-
mount: document.getElementById("controls")!,
129-
border: 4,
130-
onclose(force) {
131-
return !force && !window.confirm("Are you sure to close window?");
132-
},
133-
});
134-
winbox.minimize();
135-
winbox.maximize();
136-
winbox.fullscreen();
137-
138-
winbox.move("center", "center");
139-
winbox.move("right", "bottom");
140-
winbox.resize("50%", "50%");
141-
winbox.setTitle("Title-" + Math.random());
142-
winbox.setBackground("rgb(178, 76, 247)");
143-
winbox.body.parentElement!.classList.toggle("modal");
144-
winbox.addClass("my-theme");
145-
winbox.removeClass("my-theme");
146-
winbox.close();
147-
winbox.close(true);
4+
// Other tests done in module test.

0 commit comments

Comments
 (0)