happy-dom 4.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/lib/config/ElementTag.d.ts +6 -3
- package/lib/config/ElementTag.js +6 -3
- package/lib/config/ElementTag.js.map +1 -1
- package/lib/config/NonImplemenetedElementClasses.js +0 -3
- package/lib/config/NonImplemenetedElementClasses.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/nodes/document/Document.js +4 -0
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/element/DOMRect.d.ts +9 -0
- package/lib/nodes/element/DOMRect.js +13 -1
- package/lib/nodes/element/DOMRect.js.map +1 -1
- package/lib/nodes/element/Element.d.ts +1 -0
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.d.ts +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.js +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
- package/lib/nodes/html-input-element/IHTMLInputElement.d.ts +1 -1
- package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.d.ts +34 -0
- package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js +58 -0
- package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js.map +1 -0
- package/lib/nodes/html-opt-group-element/IHTMLOptGroupElement.d.ts +11 -0
- package/lib/nodes/html-opt-group-element/IHTMLOptGroupElement.js +3 -0
- package/lib/nodes/html-opt-group-element/IHTMLOptGroupElement.js.map +1 -0
- package/lib/nodes/html-option-element/HTMLOptionElement.d.ts +72 -0
- package/lib/nodes/html-option-element/HTMLOptionElement.js +111 -0
- package/lib/nodes/html-option-element/HTMLOptionElement.js.map +1 -0
- package/lib/nodes/html-option-element/HTMLOptionElementValueSanitizer.d.ts +11 -0
- package/lib/nodes/html-option-element/HTMLOptionElementValueSanitizer.js +18 -0
- package/lib/nodes/html-option-element/HTMLOptionElementValueSanitizer.js.map +1 -0
- package/lib/nodes/html-option-element/HTMLOptionsCollection.d.ts +43 -0
- package/lib/nodes/html-option-element/HTMLOptionsCollection.js +80 -0
- package/lib/nodes/html-option-element/HTMLOptionsCollection.js.map +1 -0
- package/lib/nodes/html-option-element/IHTMLOptionElement.d.ts +16 -0
- package/lib/nodes/html-option-element/IHTMLOptionElement.js +3 -0
- package/lib/nodes/html-option-element/IHTMLOptionElement.js.map +1 -0
- package/lib/nodes/html-option-element/IHTMLOptionsCollection.d.ts +26 -0
- package/lib/nodes/html-option-element/IHTMLOptionsCollection.js +3 -0
- package/lib/nodes/html-option-element/IHTMLOptionsCollection.js.map +1 -0
- package/lib/nodes/html-select-element/HTMLSelectElement.d.ts +128 -0
- package/lib/nodes/html-select-element/HTMLSelectElement.js +215 -0
- package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -0
- package/lib/nodes/html-select-element/HTMLSelectElementValueSanitizer.d.ts +11 -0
- package/lib/nodes/html-select-element/HTMLSelectElementValueSanitizer.js +18 -0
- package/lib/nodes/html-select-element/HTMLSelectElementValueSanitizer.js.map +1 -0
- package/lib/nodes/html-select-element/IHTMLSelectElement.d.ts +26 -0
- package/lib/nodes/html-select-element/IHTMLSelectElement.js +3 -0
- package/lib/nodes/html-select-element/IHTMLSelectElement.js.map +1 -0
- package/lib/nodes/{html-input-element → validity-state}/ValidityState.d.ts +3 -2
- package/lib/nodes/{html-input-element → validity-state}/ValidityState.js +12 -2
- package/lib/nodes/validity-state/ValidityState.js.map +1 -0
- package/lib/window/IWindow.d.ts +2 -0
- package/lib/window/Window.d.ts +2 -0
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-serializer/XMLSerializer.js +3 -0
- package/lib/xml-serializer/XMLSerializer.js.map +1 -1
- package/package.json +2 -2
- package/src/config/ElementTag.ts +6 -3
- package/src/config/NonImplemenetedElementClasses.ts +0 -3
- package/src/index.ts +2 -0
- package/src/nodes/document/Document.ts +3 -0
- package/src/nodes/element/DOMRect.ts +15 -0
- package/src/nodes/element/Element.ts +1 -0
- package/src/nodes/html-input-element/HTMLInputElement.ts +1 -1
- package/src/nodes/html-input-element/IHTMLInputElement.ts +1 -1
- package/src/nodes/html-opt-group-element/HTMLOptGroupElement.ts +54 -0
- package/src/nodes/html-opt-group-element/IHTMLOptGroupElement.ts +12 -0
- package/src/nodes/html-option-element/HTMLOptionElement.ts +117 -0
- package/src/nodes/html-option-element/HTMLOptionElementValueSanitizer.ts +15 -0
- package/src/nodes/html-option-element/HTMLOptionsCollection.ts +94 -0
- package/src/nodes/html-option-element/IHTMLOptionElement.ts +17 -0
- package/src/nodes/html-option-element/IHTMLOptionsCollection.ts +33 -0
- package/src/nodes/html-select-element/HTMLSelectElement.ts +239 -0
- package/src/nodes/html-select-element/HTMLSelectElementValueSanitizer.ts +15 -0
- package/src/nodes/html-select-element/IHTMLSelectElement.ts +27 -0
- package/src/nodes/{html-input-element → validity-state}/ValidityState.ts +13 -5
- package/src/window/IWindow.ts +2 -0
- package/src/window/Window.ts +2 -0
- package/src/xml-serializer/XMLSerializer.ts +5 -0
- package/lib/nodes/html-input-element/ValidityState.js.map +0 -1
@@ -0,0 +1,117 @@
|
|
1
|
+
import HTMLElement from '../html-element/HTMLElement';
|
2
|
+
import IHTMLElement from '../html-element/IHTMLElement';
|
3
|
+
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
|
4
|
+
import HTMLOptionElementValueSanitizer from './HTMLOptionElementValueSanitizer';
|
5
|
+
import IHTMLOptionElement from './IHTMLOptionElement';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* HTML Option Element.
|
9
|
+
*
|
10
|
+
* Reference:
|
11
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
|
12
|
+
*/
|
13
|
+
export default class HTMLOptionElement extends HTMLElement implements IHTMLOptionElement {
|
14
|
+
public _index: number;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Returns inner text, which is the rendered appearance of text.
|
18
|
+
*
|
19
|
+
* @returns Inner text.
|
20
|
+
*/
|
21
|
+
public get text(): string {
|
22
|
+
return this.innerText;
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Sets the inner text, which is the rendered appearance of text.
|
27
|
+
*
|
28
|
+
* @param innerText Inner text.
|
29
|
+
*/
|
30
|
+
public set text(text: string) {
|
31
|
+
this.innerText = text;
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Returns index.
|
36
|
+
*
|
37
|
+
* @returns Index.
|
38
|
+
*/
|
39
|
+
public get index(): number {
|
40
|
+
return this._index;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Returns the parent form element.
|
45
|
+
*
|
46
|
+
* @returns Form.
|
47
|
+
*/
|
48
|
+
public get form(): IHTMLFormElement {
|
49
|
+
let parent = <IHTMLElement>this.parentNode;
|
50
|
+
while (parent && parent.tagName !== 'FORM') {
|
51
|
+
parent = <IHTMLElement>parent.parentNode;
|
52
|
+
}
|
53
|
+
return <IHTMLFormElement>parent;
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Returns selected.
|
58
|
+
*
|
59
|
+
* @returns Selected.
|
60
|
+
*/
|
61
|
+
public get selected(): boolean {
|
62
|
+
return this.getAttributeNS(null, 'selected') !== null;
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Sets selected.
|
67
|
+
*
|
68
|
+
* @param selected Selected.
|
69
|
+
*/
|
70
|
+
public set selected(selected: boolean) {
|
71
|
+
if (!selected) {
|
72
|
+
this.removeAttributeNS(null, 'selected');
|
73
|
+
} else {
|
74
|
+
this.setAttributeNS(null, 'selected', '');
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Returns disabled.
|
80
|
+
*
|
81
|
+
* @returns Disabled.
|
82
|
+
*/
|
83
|
+
public get disabled(): boolean {
|
84
|
+
return this.getAttributeNS(null, 'disabled') !== null;
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Sets disabled.
|
89
|
+
*
|
90
|
+
* @param disabled Disabled.
|
91
|
+
*/
|
92
|
+
public set disabled(disabled: boolean) {
|
93
|
+
if (!disabled) {
|
94
|
+
this.removeAttributeNS(null, 'disabled');
|
95
|
+
} else {
|
96
|
+
this.setAttributeNS(null, 'disabled', '');
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Returns value.
|
102
|
+
*
|
103
|
+
* @returns Value.
|
104
|
+
*/
|
105
|
+
public get value(): string {
|
106
|
+
return this.getAttributeNS(null, 'value') || '';
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Sets value.
|
111
|
+
*
|
112
|
+
* @param value Value.
|
113
|
+
*/
|
114
|
+
public set value(value: string) {
|
115
|
+
this.setAttributeNS(null, 'value', HTMLOptionElementValueSanitizer.sanitize(value));
|
116
|
+
}
|
117
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
const NEW_LINES_REGEXP = /[\n\r]/gm;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* HTML select element value sanitizer.
|
5
|
+
*/
|
6
|
+
export default class HTMLOptionElementValueSanitizer {
|
7
|
+
/**
|
8
|
+
* Sanitizes a value.
|
9
|
+
*
|
10
|
+
* @param value Value.
|
11
|
+
*/
|
12
|
+
public static sanitize(value: string): string {
|
13
|
+
return value.trim().replace(NEW_LINES_REGEXP, '');
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import DOMException from '../../exception/DOMException';
|
2
|
+
import HTMLCollection from '../element/HTMLCollection';
|
3
|
+
import HTMLOptGroupElement from '../html-opt-group-element/HTMLOptGroupElement';
|
4
|
+
import HTMLOptionElement from './HTMLOptionElement';
|
5
|
+
import IHTMLOptionsCollection from './IHTMLOptionsCollection';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* HTML Options Collection.
|
9
|
+
*
|
10
|
+
* Reference:
|
11
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection.
|
12
|
+
*/
|
13
|
+
export default class HTMLOptionsCollection
|
14
|
+
extends HTMLCollection
|
15
|
+
implements IHTMLOptionsCollection
|
16
|
+
{
|
17
|
+
public _selectedIndex: number;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Returns selectedIndex.
|
21
|
+
*
|
22
|
+
* @returns SelectedIndex.
|
23
|
+
*/
|
24
|
+
public get selectedIndex(): number {
|
25
|
+
return this._selectedIndex;
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Sets selectedIndex.
|
30
|
+
*
|
31
|
+
* @param selectedIndex SelectedIndex.
|
32
|
+
*/
|
33
|
+
public set selectedIndex(selectedIndex: number) {
|
34
|
+
this._selectedIndex = selectedIndex;
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Returns item by index.
|
39
|
+
*
|
40
|
+
* @param index Index.
|
41
|
+
*/
|
42
|
+
public item(index: number): HTMLOptionElement | HTMLOptGroupElement {
|
43
|
+
return this[index];
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
*
|
48
|
+
* @param element
|
49
|
+
* @param before
|
50
|
+
*/
|
51
|
+
public add(
|
52
|
+
element: HTMLOptionElement | HTMLOptGroupElement,
|
53
|
+
before?: number | HTMLOptionElement | HTMLOptGroupElement
|
54
|
+
): void {
|
55
|
+
if (!before && before !== 0) {
|
56
|
+
this.push(element);
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
if (!Number.isNaN(Number(before))) {
|
61
|
+
if (before < 0) {
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
|
65
|
+
this.splice(<number>before, 0, element);
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
const idx = this.findIndex((element) => element === before);
|
70
|
+
if (idx === -1) {
|
71
|
+
throw new DOMException(
|
72
|
+
"Failed to execute 'add' on 'DOMException': The node before which the new node is to be inserted is not a child of this node."
|
73
|
+
);
|
74
|
+
}
|
75
|
+
|
76
|
+
this.splice(idx, 0, element);
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Removes indexed element from collection.
|
81
|
+
*
|
82
|
+
* @param index Index.
|
83
|
+
*/
|
84
|
+
public remove(index: number): void {
|
85
|
+
this.splice(index, 1);
|
86
|
+
if (index === this.selectedIndex) {
|
87
|
+
if (this.length) {
|
88
|
+
this.selectedIndex = 0;
|
89
|
+
} else {
|
90
|
+
this.selectedIndex = -1;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import IHTMLElement from '../html-element/IHTMLElement';
|
2
|
+
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* HTML Option Element.
|
6
|
+
*
|
7
|
+
* Reference:
|
8
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
|
9
|
+
*/
|
10
|
+
export default interface IHTMLOptionElement extends IHTMLElement {
|
11
|
+
readonly form: IHTMLFormElement;
|
12
|
+
readonly index: number;
|
13
|
+
selected: boolean;
|
14
|
+
value: string;
|
15
|
+
text: string;
|
16
|
+
disabled: boolean;
|
17
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import IHTMLCollection from '../element/IHTMLCollection';
|
2
|
+
import IHTMLOptGroupElement from '../html-opt-group-element/IHTMLOptGroupElement';
|
3
|
+
import IHTMLOptionElement from './IHTMLOptionElement';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* HTML Options Collection.
|
7
|
+
*
|
8
|
+
* Reference:
|
9
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection.
|
10
|
+
*/
|
11
|
+
export default interface IHTMLOptionsCollection
|
12
|
+
extends IHTMLCollection<IHTMLOptionElement | IHTMLOptGroupElement> {
|
13
|
+
selectedIndex: number;
|
14
|
+
length: number;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Adds new option to collection.
|
18
|
+
*
|
19
|
+
* @param element HTMLOptionElement or HTMLOptGroupElement to add.
|
20
|
+
* @param before HTMLOptionElement or index number.
|
21
|
+
*/
|
22
|
+
add(
|
23
|
+
element: IHTMLOptionElement | IHTMLOptGroupElement,
|
24
|
+
before?: number | IHTMLOptionElement | IHTMLOptGroupElement
|
25
|
+
): void;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Removes option element from the collection.
|
29
|
+
*
|
30
|
+
* @param index Index.
|
31
|
+
*/
|
32
|
+
remove(index: number): void;
|
33
|
+
}
|
@@ -0,0 +1,239 @@
|
|
1
|
+
import DOMException from '../../exception/DOMException';
|
2
|
+
import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum';
|
3
|
+
import HTMLElement from '../html-element/HTMLElement';
|
4
|
+
import IHTMLElement from '../html-element/IHTMLElement';
|
5
|
+
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
|
6
|
+
import ValidityState from '../validity-state/ValidityState';
|
7
|
+
import IHTMLLabelElement from '../html-label-element/IHTMLLabelElement';
|
8
|
+
import HTMLOptGroupElement from '../html-opt-group-element/HTMLOptGroupElement';
|
9
|
+
import HTMLOptionElement from '../html-option-element/HTMLOptionElement';
|
10
|
+
import HTMLOptionsCollection from '../html-option-element/HTMLOptionsCollection';
|
11
|
+
import IHTMLOptionsCollection from '../html-option-element/IHTMLOptionsCollection';
|
12
|
+
import INodeList from '../node/INodeList';
|
13
|
+
import HTMLSelectElementValueSanitizer from './HTMLSelectElementValueSanitizer';
|
14
|
+
import IHTMLSelectElement from './IHTMLSelectElement';
|
15
|
+
|
16
|
+
/**
|
17
|
+
* HTML Select Element.
|
18
|
+
*
|
19
|
+
* Reference:
|
20
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement.
|
21
|
+
*/
|
22
|
+
export default class HTMLSelectElement extends HTMLElement implements IHTMLSelectElement {
|
23
|
+
public type: string;
|
24
|
+
public labels: INodeList<IHTMLLabelElement>;
|
25
|
+
|
26
|
+
public _value = null;
|
27
|
+
public _selectedIndex = -1;
|
28
|
+
public _options: IHTMLOptionsCollection = null;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Returns name.
|
32
|
+
*
|
33
|
+
* @returns Name.
|
34
|
+
*/
|
35
|
+
public get name(): string {
|
36
|
+
return this.getAttributeNS(null, 'name') || '';
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Sets name.
|
41
|
+
*
|
42
|
+
* @param name Name.
|
43
|
+
*/
|
44
|
+
public set name(name: string) {
|
45
|
+
this.setAttributeNS(null, 'name', name);
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Returns disabled.
|
50
|
+
*
|
51
|
+
* @returns Disabled.
|
52
|
+
*/
|
53
|
+
public get disabled(): boolean {
|
54
|
+
return this.getAttributeNS(null, 'disabled') !== null;
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Sets disabled.
|
59
|
+
*
|
60
|
+
* @param disabled Disabled.
|
61
|
+
*/
|
62
|
+
public set disabled(disabled: boolean) {
|
63
|
+
if (!disabled) {
|
64
|
+
this.removeAttributeNS(null, 'disabled');
|
65
|
+
} else {
|
66
|
+
this.setAttributeNS(null, 'disabled', '');
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Returns multiple.
|
72
|
+
*
|
73
|
+
* @returns Multiple.
|
74
|
+
*/
|
75
|
+
public get multiple(): boolean {
|
76
|
+
return this.getAttributeNS(null, 'multiple') !== null;
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Sets multiple.
|
81
|
+
*
|
82
|
+
* @param multiple Multiple.
|
83
|
+
*/
|
84
|
+
public set multiple(multiple: boolean) {
|
85
|
+
if (!multiple) {
|
86
|
+
this.removeAttributeNS(null, 'multiple');
|
87
|
+
} else {
|
88
|
+
this.setAttributeNS(null, 'multiple', '');
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Returns autofocus.
|
94
|
+
*
|
95
|
+
* @returns Autofocus.
|
96
|
+
*/
|
97
|
+
public get autofocus(): boolean {
|
98
|
+
return this.getAttributeNS(null, 'autofocus') !== null;
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Sets autofocus.
|
103
|
+
*
|
104
|
+
* @param autofocus Autofocus.
|
105
|
+
*/
|
106
|
+
public set autofocus(autofocus: boolean) {
|
107
|
+
if (!autofocus) {
|
108
|
+
this.removeAttributeNS(null, 'autofocus');
|
109
|
+
} else {
|
110
|
+
this.setAttributeNS(null, 'autofocus', '');
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Returns required.
|
116
|
+
*
|
117
|
+
* @returns Required.
|
118
|
+
*/
|
119
|
+
public get required(): boolean {
|
120
|
+
return this.getAttributeNS(null, 'required') !== null;
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Sets required.
|
125
|
+
*
|
126
|
+
* @param required Required.
|
127
|
+
*/
|
128
|
+
public set required(required: boolean) {
|
129
|
+
if (!required) {
|
130
|
+
this.removeAttributeNS(null, 'required');
|
131
|
+
} else {
|
132
|
+
this.setAttributeNS(null, 'required', '');
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Returns value.
|
138
|
+
*
|
139
|
+
* @returns Value.
|
140
|
+
*/
|
141
|
+
public get value(): string {
|
142
|
+
return this._value;
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Sets value.
|
147
|
+
*
|
148
|
+
* @param value Value.
|
149
|
+
*/
|
150
|
+
public set value(value: string) {
|
151
|
+
this._value = HTMLSelectElementValueSanitizer.sanitize(value);
|
152
|
+
|
153
|
+
const idx = this.options.findIndex((o) => o.nodeValue === value);
|
154
|
+
if (idx > -1) {
|
155
|
+
this._selectedIndex = idx;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Returns value.
|
161
|
+
*
|
162
|
+
* @returns Value.
|
163
|
+
*/
|
164
|
+
public get selectedIndex(): number {
|
165
|
+
return this._options ? this._options.selectedIndex : -1;
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Sets value.
|
170
|
+
*
|
171
|
+
* @param value Value.
|
172
|
+
*/
|
173
|
+
public set selectedIndex(value: number) {
|
174
|
+
if (this.options.length - 1 > value || value < 0) {
|
175
|
+
throw new DOMException(
|
176
|
+
'Select elements selected index must be valid',
|
177
|
+
DOMExceptionNameEnum.indexSizeError
|
178
|
+
);
|
179
|
+
}
|
180
|
+
|
181
|
+
this._options.selectedIndex = value;
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Returns the parent form element.
|
186
|
+
*
|
187
|
+
* @returns Form.
|
188
|
+
*/
|
189
|
+
public get form(): IHTMLFormElement {
|
190
|
+
let parent = <IHTMLElement>this.parentNode;
|
191
|
+
while (parent && parent.tagName !== 'FORM') {
|
192
|
+
parent = <IHTMLElement>parent.parentNode;
|
193
|
+
}
|
194
|
+
return <IHTMLFormElement>parent;
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Returns validity state.
|
199
|
+
*
|
200
|
+
* @returns Validity state.
|
201
|
+
*/
|
202
|
+
public get validity(): ValidityState {
|
203
|
+
return new ValidityState(this);
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Returns "true" if it will validate.
|
208
|
+
*
|
209
|
+
* @returns "true" if it will validate.
|
210
|
+
*/
|
211
|
+
public get willValidate(): boolean {
|
212
|
+
return (
|
213
|
+
this.type !== 'hidden' &&
|
214
|
+
this.type !== 'reset' &&
|
215
|
+
this.type !== 'button' &&
|
216
|
+
!this.disabled &&
|
217
|
+
!this['readOnly']
|
218
|
+
);
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
* Returns options.
|
223
|
+
*
|
224
|
+
* @returns Options.
|
225
|
+
*/
|
226
|
+
public get options(): IHTMLOptionsCollection {
|
227
|
+
if (this._options === null) {
|
228
|
+
this._options = new HTMLOptionsCollection();
|
229
|
+
const childs = <INodeList<IHTMLElement>>this.childNodes;
|
230
|
+
for (const child of childs) {
|
231
|
+
if (child.tagName === 'OPTION') {
|
232
|
+
this._options.add(<HTMLOptionElement | HTMLOptGroupElement>child);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
return this._options;
|
238
|
+
}
|
239
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
const NEW_LINES_REGEXP = /[\n\r]/gm;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* HTML select element value sanitizer.
|
5
|
+
*/
|
6
|
+
export default class HTMLSelectElementValueSanitizer {
|
7
|
+
/**
|
8
|
+
* Sanitizes a value.
|
9
|
+
*
|
10
|
+
* @param value Value.
|
11
|
+
*/
|
12
|
+
public static sanitize(value: string): string {
|
13
|
+
return value.replace(NEW_LINES_REGEXP, '');
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import IHTMLElement from '../html-element/IHTMLElement';
|
2
|
+
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
|
3
|
+
import IHTMLLabelElement from '../html-label-element/IHTMLLabelElement';
|
4
|
+
import INodeList from '../node/INodeList';
|
5
|
+
import IHTMLOptionsCollection from '../html-option-element/IHTMLOptionsCollection';
|
6
|
+
import ValidityState from '../validity-state/ValidityState';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* HTML Select Element.
|
10
|
+
*
|
11
|
+
* Reference:
|
12
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement.
|
13
|
+
*/
|
14
|
+
export default interface IHTMLSelectElement extends IHTMLElement {
|
15
|
+
readonly form: IHTMLFormElement;
|
16
|
+
readonly labels: INodeList<IHTMLLabelElement>;
|
17
|
+
type: string;
|
18
|
+
autofocus: boolean;
|
19
|
+
disabled: boolean;
|
20
|
+
options: IHTMLOptionsCollection;
|
21
|
+
selectedIndex: number;
|
22
|
+
validity: ValidityState;
|
23
|
+
value: string;
|
24
|
+
willValidate: boolean;
|
25
|
+
name: string;
|
26
|
+
multiple: boolean;
|
27
|
+
}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import HTMLInputElement from '
|
1
|
+
import HTMLInputElement from '../html-input-element/HTMLInputElement';
|
2
|
+
import HTMLSelectElement from '../html-select-element/HTMLSelectElement';
|
2
3
|
|
3
4
|
/**
|
4
5
|
* Input validity state.
|
@@ -12,14 +13,14 @@ export default class ValidityState {
|
|
12
13
|
public rangeOverflow = false;
|
13
14
|
public rangeUnderflow = false;
|
14
15
|
public stepMismatch = false;
|
15
|
-
private element: HTMLInputElement = null;
|
16
|
+
private element: HTMLInputElement | HTMLSelectElement = null;
|
16
17
|
|
17
18
|
/**
|
18
19
|
* Constructor.
|
19
20
|
*
|
20
21
|
* @param element Input element.
|
21
22
|
*/
|
22
|
-
constructor(element: HTMLInputElement) {
|
23
|
+
constructor(element: HTMLInputElement | HTMLSelectElement) {
|
23
24
|
this.element = element;
|
24
25
|
}
|
25
26
|
|
@@ -29,7 +30,10 @@ export default class ValidityState {
|
|
29
30
|
* @returns "true" if valid.
|
30
31
|
*/
|
31
32
|
public get tooLong(): boolean {
|
32
|
-
|
33
|
+
if (this.element instanceof HTMLInputElement) {
|
34
|
+
return this.element.maxLength && this.element.value.length > this.element.maxLength;
|
35
|
+
}
|
36
|
+
return false;
|
33
37
|
}
|
34
38
|
|
35
39
|
/**
|
@@ -38,7 +42,11 @@ export default class ValidityState {
|
|
38
42
|
* @returns "true" if valid.
|
39
43
|
*/
|
40
44
|
public get tooShort(): boolean {
|
41
|
-
|
45
|
+
if (this.element instanceof HTMLInputElement) {
|
46
|
+
return this.element.minLength && this.element.value.length < this.element.minLength;
|
47
|
+
}
|
48
|
+
|
49
|
+
return false;
|
42
50
|
}
|
43
51
|
|
44
52
|
/**
|
package/src/window/IWindow.ts
CHANGED
@@ -80,6 +80,7 @@ import IHeaders from '../fetch/IHeaders';
|
|
80
80
|
import IRequestInit from '../fetch/IRequestInit';
|
81
81
|
import IResponse from '../fetch/IResponse';
|
82
82
|
import MediaQueryList from '../match-media/MediaQueryList';
|
83
|
+
import DOMRect from '../nodes/element/DOMRect';
|
83
84
|
import Window from './Window';
|
84
85
|
import { URLSearchParams } from 'url';
|
85
86
|
import { Performance } from 'perf_hooks';
|
@@ -173,6 +174,7 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
173
174
|
readonly Headers: { new (init?: string[][] | Record<string, string> | IHeaders): IHeaders };
|
174
175
|
readonly Request: { new (input: string | IRequest, init?: IRequestInit): IRequest };
|
175
176
|
readonly Response: { new (body?: unknown | null, init?: IResponseInit): IResponse };
|
177
|
+
readonly DOMRect: typeof DOMRect;
|
176
178
|
|
177
179
|
// Events
|
178
180
|
onload: (event: Event) => void;
|
package/src/window/Window.ts
CHANGED
@@ -87,6 +87,7 @@ import Plugin from '../navigator/Plugin';
|
|
87
87
|
import PluginArray from '../navigator/PluginArray';
|
88
88
|
import { URLSearchParams } from 'url';
|
89
89
|
import FetchHandler from '../fetch/FetchHandler';
|
90
|
+
import DOMRect from '../nodes/element/DOMRect';
|
90
91
|
import VMGlobalPropertyScript from './VMGlobalPropertyScript';
|
91
92
|
import * as PerfHooks from 'perf_hooks';
|
92
93
|
import VM from 'vm';
|
@@ -192,6 +193,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
192
193
|
public readonly Response: {
|
193
194
|
new (body?: NodeJS.ReadableStream | null, init?: IResponseInit): IResponse;
|
194
195
|
} = Response;
|
196
|
+
public readonly DOMRect: typeof DOMRect;
|
195
197
|
|
196
198
|
// Events
|
197
199
|
public onload: (event: Event) => void = null;
|
@@ -75,6 +75,11 @@ export default class XMLSerializer {
|
|
75
75
|
*/
|
76
76
|
private _getAttributes(element: IElement): string {
|
77
77
|
let attributeString = '';
|
78
|
+
|
79
|
+
if (!(<Element>element)._attributes.is && (<Element>element)._isValue) {
|
80
|
+
attributeString += ' is="' + escape((<Element>element)._isValue) + '"';
|
81
|
+
}
|
82
|
+
|
78
83
|
for (const attribute of Object.values((<Element>element)._attributes)) {
|
79
84
|
if (attribute.value !== null) {
|
80
85
|
attributeString += ' ' + attribute.name + '="' + escape(attribute.value) + '"';
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ValidityState.js","sourceRoot":"","sources":["../../../src/nodes/html-input-element/ValidityState.ts"],"names":[],"mappings":";;AAEA;;;;GAIG;AACH,MAAqB,aAAa;IASjC;;;;OAIG;IACH,YAAY,OAAyB;QAb9B,aAAQ,GAAG,KAAK,CAAC;QACjB,gBAAW,GAAG,KAAK,CAAC;QACpB,oBAAe,GAAG,KAAK,CAAC;QACxB,kBAAa,GAAG,KAAK,CAAC;QACtB,mBAAc,GAAG,KAAK,CAAC;QACvB,iBAAY,GAAG,KAAK,CAAC;QACpB,YAAO,GAAqB,IAAI,CAAC;QAQxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,IAAW,OAAO;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACH,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACH,IAAW,YAAY;QACtB,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,IAAW,YAAY;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACH,IAAW,KAAK;QACf,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACpC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;gBACd,OAAO,KAAK,CAAC;aACb;SACD;QAED,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;IACpF,CAAC;CACD;AApED,gCAoEC"}
|