Skip to content

Commit a09aab6

Browse files
author
Berni
committed
chore(*): Rewrite in TypeScript
1 parent 52835c9 commit a09aab6

10 files changed

+1486
-1291
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.markdown renamed to README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creating a form is easy:
1616
fields: [f1, f2]
1717
});
1818

19-
You can call the constructor for Forms directly with $form:
19+
You can call the constructor for Forms directly with \$form:
2020

2121
$form({
2222
...

lib/strophe.x.d.ts

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
declare type FormType = "form" | "submit" | "cancel" | "result";
2+
declare type FormOptions = {
3+
type?: FormType;
4+
title?: string;
5+
instructions?: string;
6+
fields?: Field[];
7+
items?: Item[];
8+
};
9+
declare class Form {
10+
type: FormType;
11+
title: string | undefined;
12+
instructions: string | undefined;
13+
fields: Field[];
14+
items: Item[];
15+
reported: string[];
16+
constructor(opt?: FormOptions);
17+
updateReported(): void;
18+
toXML(): Element;
19+
toJSON(): {
20+
type: FormType;
21+
title: string | undefined;
22+
instructions: string | undefined;
23+
fields: {
24+
type: FieldType;
25+
var: string;
26+
required: boolean;
27+
desc: string | undefined;
28+
label: string | undefined;
29+
values: string[];
30+
options: {
31+
label: string;
32+
value: string;
33+
}[];
34+
}[];
35+
items: {
36+
fields: {
37+
type: FieldType;
38+
var: string;
39+
required: boolean;
40+
desc: string | undefined;
41+
label: string | undefined;
42+
values: string[];
43+
options: {
44+
label: string;
45+
value: string;
46+
}[];
47+
}[];
48+
}[];
49+
reported: string[];
50+
};
51+
toHTML(): HTMLElement;
52+
static fromXML(xmlIn: Element): Form;
53+
static fromHTML(htmlIn: HTMLElement): Form;
54+
}
55+
declare type FieldType = "boolean" | "fixed" | "hidden" | "jid-multi" | "jid-single" | "list-multi" | "list-single" | "text-multi" | "text-private" | "text-single";
56+
declare type FieldValue = string | number;
57+
interface FieldOptions {
58+
type: FieldType;
59+
desc?: string;
60+
label?: string;
61+
var?: string;
62+
required?: boolean | "true";
63+
options?: FieldOption[];
64+
value?: FieldValue;
65+
values?: FieldValue[];
66+
}
67+
declare class Field {
68+
type: FieldType;
69+
desc: string | undefined;
70+
label: string | undefined;
71+
var: string;
72+
required: boolean;
73+
options: FieldOption[];
74+
values: string[];
75+
constructor(opt: FieldOptions);
76+
addValue(val: FieldValue): this;
77+
addValues(vals: FieldValue[]): this;
78+
addOption(opt: FieldOption): this;
79+
addOptions(opts: FieldOption[]): this;
80+
toJSON(): {
81+
type: FieldType;
82+
var: string;
83+
required: boolean;
84+
desc: string | undefined;
85+
label: string | undefined;
86+
values: string[];
87+
options: {
88+
label: string;
89+
value: string;
90+
}[];
91+
};
92+
toXML(): Element;
93+
toHTML(): HTMLElement;
94+
static fromXML(xmlIn: Element): Field;
95+
static _htmlElementToFieldType(html: HTMLElement): FieldType;
96+
static fromHTML(htmlIn: HTMLElement): Field;
97+
}
98+
declare type FieldOptionOptions = {
99+
label?: string;
100+
value?: FieldValue;
101+
};
102+
declare class FieldOption {
103+
label: string;
104+
value: string;
105+
constructor(opt?: FieldOptionOptions);
106+
toXML(): Element;
107+
toJSON(): {
108+
label: string;
109+
value: string;
110+
};
111+
toHTML(): HTMLElement;
112+
static fromXML(xml: Element): FieldOption;
113+
static fromHTML(html: HTMLElement): FieldOption;
114+
}
115+
declare type ItemOptions = {
116+
fields?: Field[];
117+
};
118+
declare class Item {
119+
fields: Field[];
120+
constructor(opts?: ItemOptions);
121+
toXML(): Element;
122+
toJSON(): {
123+
fields: {
124+
type: FieldType;
125+
var: string;
126+
required: boolean;
127+
desc: string | undefined;
128+
label: string | undefined;
129+
values: string[];
130+
options: {
131+
label: string;
132+
value: string;
133+
}[];
134+
}[];
135+
};
136+
toHTML(): HTMLElement;
137+
static fromXML(xmlIn: Element): Item;
138+
static fromHTML(html: HTMLElement): Item;
139+
}
140+
declare type StropheDataforms = {
141+
Form: typeof Form;
142+
Field: typeof Field;
143+
Option: typeof FieldOption;
144+
Item: typeof Item;
145+
};
146+
declare const $form: (opt: FormOptions) => Form;
147+
declare const $field: (opt: FieldOptions) => Field;
148+
declare const $opt: (opt: FieldOptionOptions) => FieldOption;
149+
declare const $item: (opt: ItemOptions) => Item;
150+
export { $form, $field, $opt, $item, StropheDataforms };

0 commit comments

Comments
 (0)