Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16]
node-version: [20]

steps:
- uses: actions/checkout@v2
Expand Down
54 changes: 52 additions & 2 deletions cjs/html/slot-element.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
'use strict';
const {HTMLElement} = require('./element.js');
const {registerHTMLClass} = require('../shared/register-html-class.js');

const tagName = 'slot';

/**
* @implements globalThis.HTMLSlotElement
*/
class HTMLSlotElement extends HTMLElement {
constructor(ownerDocument, localName = 'slot') {
constructor(ownerDocument, localName = tagName) {
super(ownerDocument, localName);
}

/* c8 ignore start */
get name() { return this.getAttribute('name'); }
set name(value) { this.setAttribute('name', value); }

assign() {}

assignedNodes(options) {
const isNamedSlot = !!this.name;
const hostChildNodes = this.getRootNode().host?.childNodes ?? [];
let slottables;

if (isNamedSlot) {
slottables = [...hostChildNodes].filter(node => node.slot === this.name);
} else {
slottables = [...hostChildNodes].filter(node => !node.slot);
}

if (options?.flatten) {
const result = [];

// Element and Text nodes are slottables. A slot can be a slottable.
for (let slottable of slottables) {
if (slottable.localName === 'slot') {
result.push(...slottable.assignedNodes({ flatten: true }));
} else {
result.push(slottable);
}
}

slottables = result;
}

// If no assigned nodes are found, it returns the slot's fallback content.
return slottables.length ? slottables : [...this.childNodes];
}

assignedElements(options) {
const slottables = this.assignedNodes(options).filter(n => n.nodeType === 1);

// If no assigned elements are found, it returns the slot's fallback content.
return slottables.length ? slottables : [...this.children];
}
/* c8 ignore stop */
}
exports.HTMLSlotElement = HTMLSlotElement

registerHTMLClass(tagName, HTMLSlotElement);

exports.HTMLSlotElement = HTMLSlotElement;
3 changes: 3 additions & 0 deletions cjs/interface/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class Element extends ParentNode {

get tabIndex() { return numericAttribute.get(this, 'tabindex') || -1; }
set tabIndex(value) { numericAttribute.set(this, 'tabindex', value); }

get slot() { return stringAttribute.get(this, 'slot'); }
set slot(value) { stringAttribute.set(this, 'slot', value); }
// </specialGetters>


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkedom",
"version": "0.15.6",
"version": "0.16.0",
"description": "A triple-linked lists based DOM implementation",
"main": "./cjs/index.js",
"types": "./types/index.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions types/esm/html/slot-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
* @implements globalThis.HTMLSlotElement
*/
export class HTMLSlotElement extends HTMLElement implements globalThis.HTMLSlotElement {
set name(arg: any);
get name(): any;
assign(): void;
assignedNodes(options: any): any[];
assignedElements(options: any): any[];
}
import { HTMLElement } from "./element.js";
2 changes: 2 additions & 0 deletions types/esm/interface/element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class Element extends ParentNode implements globalThis.Element {
get style(): any;
set tabIndex(arg: number);
get tabIndex(): number;
set slot(arg: any);
get slot(): any;
get innerText(): string;
set innerHTML(arg: any);
get innerHTML(): any;
Expand Down
1 change: 1 addition & 0 deletions types/esm/interface/image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function ImageClass(ownerDocument: any): {
nonce: any;
readonly style: any;
tabIndex: number;
slot: any;
readonly innerText: string;
textContent: string;
innerHTML: string;
Expand Down
2 changes: 1 addition & 1 deletion types/esm/interface/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Node extends EventTarget implements globalThis.Node {
set textContent(arg: any);
get textContent(): any;
normalize(): void;
cloneNode(deep?: boolean): any;
cloneNode(): any;
contains(): boolean;
/**
* Inserts a node before a reference node as a child of this parent node.
Expand Down
Loading