Skip to content

Commit

Permalink
#450@trivial: Merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Jun 14, 2022
2 parents d212611 + 8ece290 commit 5c3774c
Show file tree
Hide file tree
Showing 39 changed files with 16,547 additions and 315 deletions.
596 changes: 298 additions & 298 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions packages/happy-dom/src/config/ElementTag.ts
Expand Up @@ -13,6 +13,9 @@ import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
import HTMLSelectElement from '../nodes/html-select-element/HTMLSelectElement';
import HTMLOptionElement from '../nodes/html-option-element/HTMLOptionElement';
import HTMLOptGroupElement from '../nodes/html-opt-group-element/HTMLOptGroupElement';

export default {
A: HTMLElement,
Expand Down Expand Up @@ -102,8 +105,8 @@ export default {
NOSCRIPT: HTMLElement,
OBJECT: HTMLElement,
OL: HTMLElement,
OPTGROUP: HTMLElement,
OPTION: HTMLElement,
OPTGROUP: HTMLOptGroupElement,
OPTION: HTMLOptionElement,
OUTPUT: HTMLElement,
P: HTMLElement,
PARAM: HTMLElement,
Expand All @@ -119,7 +122,7 @@ export default {
S: HTMLElement,
SAMP: HTMLElement,
SECTION: HTMLElement,
SELECT: HTMLElement,
SELECT: HTMLSelectElement,
SMALL: HTMLElement,
SOURCE: HTMLElement,
SPAN: HTMLElement,
Expand Down
Expand Up @@ -32,13 +32,10 @@ export default [
'HTMLMediaElement',
'HTMLMeterElement',
'HTMLModElement',
'HTMLOptGroupElement',
'HTMLOptionElement',
'HTMLOutputElement',
'HTMLPictureElement',
'HTMLProgressElement',
'HTMLQuoteElement',
'HTMLSelectElement',
'HTMLSourceElement',
'HTMLSpanElement',
'HTMLTableCaptionElement',
Expand Down
7 changes: 7 additions & 0 deletions packages/happy-dom/src/dom-token-list/DOMTokenList.ts
Expand Up @@ -212,4 +212,11 @@ export default class DOMTokenList implements IDOMTokenList {

(<number>this.length) = list.length;
}

/**
* Returns DOMTokenList value.
*/
public toString(): string {
return this.value || '';
}
}
1 change: 1 addition & 0 deletions packages/happy-dom/src/dom-token-list/IDOMTokenList.ts
Expand Up @@ -16,4 +16,5 @@ export default interface IDOMTokenList {
entries(): IterableIterator<[number, string]>;
forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void;
keys(): IterableIterator<number>;
toString(): string;
}
3 changes: 2 additions & 1 deletion packages/happy-dom/src/exception/DOMExceptionNameEnum.ts
Expand Up @@ -5,6 +5,7 @@ enum DOMExceptionNameEnum {
hierarchyRequestError = 'HierarchyRequestError',
notSupportedError = 'NotSupportedError',
wrongDocumentError = 'WrongDocumentError',
invalidNodeTypeError = 'InvalidNodeTypeError'
invalidNodeTypeError = 'InvalidNodeTypeError',
invalidCharacterError = 'InvalidCharacterError'
}
export default DOMExceptionNameEnum;
2 changes: 2 additions & 0 deletions packages/happy-dom/src/index.ts
Expand Up @@ -101,6 +101,7 @@ import XMLParser from './xml-parser/XMLParser';
import XMLSerializer from './xml-serializer/XMLSerializer';
import CSSStyleSheet from './css/CSSStyleSheet';
import Storage from './storage/Storage';
import DOMRect from './nodes/element/DOMRect';
import { URLSearchParams } from 'url';
import Selection from './selection/Selection';

Expand Down Expand Up @@ -208,6 +209,7 @@ export {
XMLSerializer,
CSSStyleSheet,
Storage,
DOMRect,
URLSearchParams,
Selection
};
18 changes: 18 additions & 0 deletions packages/happy-dom/src/nodes/document/Document.ts
Expand Up @@ -39,6 +39,7 @@ import Location from '../../location/Location';
import Selection from '../../selection/Selection';
import IShadowRoot from '../shadow-root/IShadowRoot';
import Range from '../../range/Range';
import IHTMLBaseElement from '../html-base-element/IHTMLBaseElement';

/**
* Document.
Expand Down Expand Up @@ -283,6 +284,20 @@ export default class Document extends Node implements IDocument {
return <IHTMLCollection<IHTMLScriptElement>>this.getElementsByTagName('script');
}

/**
* Returns base URI.
*
* @override
* @returns Base URI.
*/
public get baseURI(): string {
const base = <IHTMLBaseElement>this.querySelector('base');
if (base) {
return base.href;
}
return this.defaultView.location.href;
}

/**
* Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
*
Expand Down Expand Up @@ -648,6 +663,9 @@ export default class Document extends Node implements IDocument {
element.tagName = tagName;
element.ownerDocument = this;
element.namespaceURI = namespaceURI;
if (element instanceof Element && options && options.is) {
element._isValue = String(options.is);
}

return element;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/happy-dom/src/nodes/element/DOMRect.ts
Expand Up @@ -12,4 +12,19 @@ export default class DOMRect {
public right = 0;
public bottom = 0;
public left = 0;

/**
* Constructor.
*
* @param [x] X position.
* @param [y] Y position.
* @param [width] Width.
* @param [height] Height.
*/
constructor(x?, y?, width?, height?) {
this.x = x || 0;
this.y = y || 0;
this.width = width || 0;
this.height = height || 0;
}
}
1 change: 1 addition & 0 deletions packages/happy-dom/src/nodes/element/Element.ts
Expand Up @@ -48,6 +48,7 @@ export default class Element extends Node implements IElement {
public _attributes: { [k: string]: Attr } = {};

private _classList: DOMTokenList = null;
public _isValue?: string;

/**
* Returns class list.
Expand Down
@@ -1,6 +1,6 @@
import File from '../../file/File';
import HTMLElement from '../html-element/HTMLElement';
import ValidityState from './ValidityState';
import ValidityState from '../validity-state/ValidityState';
import DOMException from '../../exception/DOMException';
import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum';
import Event from '../../event/Event';
Expand Down
Expand Up @@ -2,7 +2,7 @@ import File from '../../file/File';
import IHTMLElement from '../html-element/IHTMLElement';
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
import HTMLInputElementSelectionModeEnum from './HTMLInputElementSelectionModeEnum';
import ValidityState from './ValidityState';
import ValidityState from '../validity-state/ValidityState';

/**
* HTML Input Element.
Expand Down
@@ -0,0 +1,54 @@
import HTMLElement from '../html-element/HTMLElement';
import IHTMLOptGroupElement from './IHTMLOptGroupElement';

/**
* HTML Opt Group Element.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement.
*/
export default class HTMLOptGroupElement extends HTMLElement implements IHTMLOptGroupElement {
/**
* Returns label.
*
* @returns Label.
*/
public get label(): string {
return this.getAttributeNS(null, 'label') || '';
}

/**
* Sets label.
*
* @param label Label.
*/
public set label(label: string) {
if (!label) {
this.removeAttributeNS(null, 'label');
} else {
this.setAttributeNS(null, 'label', label);
}
}

/**
* Returns disabled.
*
* @returns Disabled.
*/
public get disabled(): boolean {
return this.getAttributeNS(null, 'disabled') !== null;
}

/**
* Sets disabled.
*
* @param disabled Disabled.
*/
public set disabled(disabled: boolean) {
if (!disabled) {
this.removeAttributeNS(null, 'disabled');
} else {
this.setAttributeNS(null, 'disabled', '');
}
}
}
@@ -0,0 +1,12 @@
import IHTMLElement from '../html-element/IHTMLElement';

/**
* HTML Opt Group Element.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement.
*/
export default interface IHTMLOptGroupElement extends IHTMLElement {
disabled: boolean;
label: string;
}
117 changes: 117 additions & 0 deletions packages/happy-dom/src/nodes/html-option-element/HTMLOptionElement.ts
@@ -0,0 +1,117 @@
import HTMLElement from '../html-element/HTMLElement';
import IHTMLElement from '../html-element/IHTMLElement';
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
import HTMLOptionElementValueSanitizer from './HTMLOptionElementValueSanitizer';
import IHTMLOptionElement from './IHTMLOptionElement';

/**
* HTML Option Element.
*
* Reference:
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
*/
export default class HTMLOptionElement extends HTMLElement implements IHTMLOptionElement {
public _index: number;

/**
* Returns inner text, which is the rendered appearance of text.
*
* @returns Inner text.
*/
public get text(): string {
return this.innerText;
}

/**
* Sets the inner text, which is the rendered appearance of text.
*
* @param innerText Inner text.
*/
public set text(text: string) {
this.innerText = text;
}

/**
* Returns index.
*
* @returns Index.
*/
public get index(): number {
return this._index;
}

/**
* Returns the parent form element.
*
* @returns Form.
*/
public get form(): IHTMLFormElement {
let parent = <IHTMLElement>this.parentNode;
while (parent && parent.tagName !== 'FORM') {
parent = <IHTMLElement>parent.parentNode;
}
return <IHTMLFormElement>parent;
}

/**
* Returns selected.
*
* @returns Selected.
*/
public get selected(): boolean {
return this.getAttributeNS(null, 'selected') !== null;
}

/**
* Sets selected.
*
* @param selected Selected.
*/
public set selected(selected: boolean) {
if (!selected) {
this.removeAttributeNS(null, 'selected');
} else {
this.setAttributeNS(null, 'selected', '');
}
}

/**
* Returns disabled.
*
* @returns Disabled.
*/
public get disabled(): boolean {
return this.getAttributeNS(null, 'disabled') !== null;
}

/**
* Sets disabled.
*
* @param disabled Disabled.
*/
public set disabled(disabled: boolean) {
if (!disabled) {
this.removeAttributeNS(null, 'disabled');
} else {
this.setAttributeNS(null, 'disabled', '');
}
}

/**
* Returns value.
*
* @returns Value.
*/
public get value(): string {
return this.getAttributeNS(null, 'value') || '';
}

/**
* Sets value.
*
* @param value Value.
*/
public set value(value: string) {
this.setAttributeNS(null, 'value', HTMLOptionElementValueSanitizer.sanitize(value));
}
}
@@ -0,0 +1,15 @@
const NEW_LINES_REGEXP = /[\n\r]/gm;

/**
* HTML select element value sanitizer.
*/
export default class HTMLOptionElementValueSanitizer {
/**
* Sanitizes a value.
*
* @param value Value.
*/
public static sanitize(value: string): string {
return value.trim().replace(NEW_LINES_REGEXP, '');
}
}

0 comments on commit 5c3774c

Please sign in to comment.