UNPKG

jsdom

Version:

A JavaScript implementation of many web standards

59 lines (45 loc) • 1.59 kB
"use strict"; const idlUtils = require("../../../generated/idl/utils"); const HTMLElement = require("../../../generated/idl/HTMLElement"); const HTMLElementImpl = require("./HTMLElement-impl").implementation; const { assignSlotableForTree, findFlattenedSlotables } = require("../helpers/shadow-dom"); class HTMLSlotElementImpl extends HTMLElementImpl { constructor(globalObject, args, privateData) { super(globalObject, args, privateData); this._assignedNodes = []; } // https://dom.spec.whatwg.org/#slot-name get _name() { return this.getAttributeNS(null, "name") || ""; } _attributeChangeSteps(localName, oldValue, value, namespace) { super._attributeChangeSteps(localName, oldValue, value, namespace); // https://dom.spec.whatwg.org/#slot-name if (namespace === null && localName === "name") { if (value === oldValue) { return; } if (value === null && oldValue === "") { return; } if (value === "" && oldValue === null) { return; } assignSlotableForTree(this.getRootNode()); } } // https://html.spec.whatwg.org/#dom-slot-assignednodes assignedNodes(options) { if (!options || !options.flatten) { return this._assignedNodes.map(idlUtils.wrapperForImpl); } return findFlattenedSlotables(this).map(idlUtils.wrapperForImpl); } // https://html.spec.whatwg.org/#dom-slot-assignedelements assignedElements(options) { return this.assignedNodes(options).filter(HTMLElement.is); } } module.exports = { implementation: HTMLSlotElementImpl };