-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathslot-controller-server.ts
45 lines (34 loc) · 1.29 KB
/
slot-controller-server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { ReactiveElement } from 'lit';
import {
type SlotControllerArgs,
type SlotControllerPublicAPI,
} from './slot-controller.js';
export class SlotController implements SlotControllerPublicAPI {
public static default = Symbol('default slot') satisfies symbol as symbol;
/** @deprecated use `default` */
public static anonymous: symbol = this.default;
static property = 'ssrHintHasSlotted' as const;
static attribute = 'ssr-hint-has-slotted' as const;
static anonymousAttribute = 'ssr-hint-has-default-slotted' as const;
constructor(public host: ReactiveElement, ..._: SlotControllerArgs) {
host.addController(this);
}
hostConnected?(): Promise<void>;
private fromAttribute(slots: string | null) {
return (slots ?? '')
.split(/[, ]/)
.map(x => x.trim());
}
getSlotted<T extends Element = Element>(..._: string[]): T[] {
return [];
}
hasSlotted(...names: (string | null)[]): boolean {
const attr = this.host.getAttribute(SlotController.attribute);
const anon = this.host.hasAttribute(SlotController.anonymousAttribute);
const hints = new Set(this.fromAttribute(attr));
return names.every(x => x === null ? anon : hints.has(x));
}
isEmpty(...names: (string | null)[]): boolean {
return !this.hasSlotted(...names);
}
}