Skip to content

Commit dd752d5

Browse files
committed
fix: revert slot controller changes
This will be addressed in a later PR
1 parent 0b3dffa commit dd752d5

File tree

2 files changed

+7
-115
lines changed

2 files changed

+7
-115
lines changed

core/pfe-core/controllers/slot-controller-server.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

core/pfe-core/controllers/slot-controller.ts

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isServer, type ReactiveController, type ReactiveElement } from 'lit';
1+
import { type ReactiveController, type ReactiveElement } from 'lit';
22

33
interface AnonymousSlot {
44
hasContent: boolean;
@@ -49,56 +49,7 @@ const isSlot =
4949
n === SlotController.default ? !child.hasAttribute('slot')
5050
: child.getAttribute('slot') === n;
5151

52-
export declare class SlotControllerPublicAPI implements ReactiveController {
53-
static default: symbol;
54-
55-
public host: ReactiveElement;
56-
57-
constructor(host: ReactiveElement, ...args: SlotControllerArgs);
58-
59-
hostConnected?(): Promise<void>;
60-
61-
hostDisconnected?(): void;
62-
63-
hostUpdated?(): void;
64-
65-
/**
66-
* Given a slot name or slot names, returns elements assigned to the requested slots as an array.
67-
* If no value is provided, it returns all children not assigned to a slot (without a slot attribute).
68-
* @param slotNames slots to query
69-
* @example Get header-slotted elements
70-
* ```js
71-
* this.getSlotted('header')
72-
* ```
73-
* @example Get header- and footer-slotted elements
74-
* ```js
75-
* this.getSlotted('header', 'footer')
76-
* ```
77-
* @example Get default-slotted elements
78-
* ```js
79-
* this.getSlotted();
80-
* ```
81-
*/
82-
getSlotted<T extends Element = Element>(...slotNames: string[]): T[];
83-
84-
/**
85-
* Returns a boolean statement of whether or not any of those slots exists in the light DOM.
86-
* @param names The slot names to check.
87-
* @example this.hasSlotted('header');
88-
*/
89-
hasSlotted(...names: (string | null | undefined)[]): boolean;
90-
91-
/**
92-
* Whether or not all the requested slots are empty.
93-
* @param names The slot names to query. If no value is provided, it returns the default slot.
94-
* @example this.isEmpty('header', 'footer');
95-
* @example this.isEmpty();
96-
* @returns
97-
*/
98-
isEmpty(...names: (string | null | undefined)[]): boolean;
99-
}
100-
101-
export class SlotController implements SlotControllerPublicAPI {
52+
export class SlotController implements ReactiveController {
10253
public static default = Symbol('default slot') satisfies symbol as symbol;
10354

10455
/** @deprecated use `default` */
@@ -110,8 +61,6 @@ export class SlotController implements SlotControllerPublicAPI {
11061

11162
#slotNames: (string | null)[] = [];
11263

113-
#ssrHintHasSlotted: (string | null)[] = [];
114-
11564
#deprecations: Record<string, string> = {};
11665

11766
#mo = new MutationObserver(this.#initSlotMap.bind(this));
@@ -137,11 +86,6 @@ export class SlotController implements SlotControllerPublicAPI {
13786

13887
async hostConnected(): Promise<void> {
13988
this.#mo.observe(this.host, { childList: true });
140-
this.#ssrHintHasSlotted =
141-
this.host
142-
// @ts-expect-error: this is a ponyfill for ::has-slotted, is not intended as a public API
143-
.ssrHintHasSlotted
144-
?? [];
14589
// Map the defined slots into an object that is easier to query
14690
this.#nodes.clear();
14791
this.#initSlotMap();
@@ -169,31 +113,24 @@ export class SlotController implements SlotControllerPublicAPI {
169113
const elements = this.#getChildrenForSlot(slotId);
170114
const slot = this.#getSlotElement(slotId);
171115
const hasContent =
172-
isServer ? this.#ssrHintHasSlotted.includes(slotName)
173-
: !!elements.length || !!slot?.assignedNodes?.()?.filter(x => x.textContent?.trim()).length;
116+
!!elements.length || !!slot?.assignedNodes?.()?.filter(x => x.textContent?.trim()).length;
174117
this.#nodes.set(slotId, { elements, name, hasContent, slot });
175118
}
176119
this.host.requestUpdate();
177120
this.#slotMapInitialized = true;
178121
}
179122

180123
#getSlotElement(slotId: string | symbol) {
181-
if (isServer) {
182-
return null;
183-
} else {
184-
const selector =
124+
const selector =
185125
slotId === SlotController.default ? 'slot:not([name])' : `slot[name="${slotId as string}"]`;
186-
return this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;
187-
}
126+
return this.host.shadowRoot?.querySelector<HTMLSlotElement>(selector) ?? null;
188127
}
189128

190129
#getChildrenForSlot<T extends Element = Element>(
191130
name: string | typeof SlotController.default,
192131
): T[] {
193-
if (isServer) {
194-
return [];
195-
} else if (this.#nodes.has(name)) {
196-
return (this.#nodes.get(name)!.slot?.assignedElements?.() ?? []) as T[];
132+
if (this.#nodes.has(name)) {
133+
return (this.#nodes.get(name)!.slot?.assignedElements() ?? []) as T[];
197134
} else {
198135
const children = Array.from(this.host.children) as T[];
199136
return children.filter(isSlot(name));

0 commit comments

Comments
 (0)