@patternfly/pfe-core 4.0.4 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import type { ReactiveElement, ReactiveController } from 'lit';
2
2
  export declare class CssVariableController implements ReactiveController {
3
3
  host: ReactiveElement;
4
- style: CSSStyleDeclaration;
4
+ style?: CSSStyleDeclaration;
5
5
  constructor(host: ReactiveElement);
6
6
  private parseProperty;
7
7
  getVariable(name: string): string | null;
8
- hostConnected?(): void;
8
+ hostConnected(): void;
9
9
  }
@@ -1,13 +1,19 @@
1
1
  export class CssVariableController {
2
2
  constructor(host) {
3
3
  this.host = host;
4
- this.style = window.getComputedStyle(host);
4
+ if (this.host.isConnected) {
5
+ this.hostConnected();
6
+ }
5
7
  }
6
8
  parseProperty(name) {
7
9
  return name.substring(0, 2) !== '--' ? `--${name}` : name;
8
10
  }
9
11
  getVariable(name) {
10
- return this.style.getPropertyValue(this.parseProperty(name)).trim() || null;
12
+ return this.style?.getPropertyValue(this.parseProperty(name)).trim() || null;
11
13
  }
14
+ hostConnected() {
15
+ this.style = window.getComputedStyle(this.host);
16
+ }
17
+ ;
12
18
  }
13
19
  //# sourceMappingURL=css-variable-controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"css-variable-controller.js","sourceRoot":"","sources":["css-variable-controller.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,qBAAqB;IAGhC,YAAmB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QACtC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEO,aAAa,CAAC,IAAY;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5D,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;IAC9E,CAAC;CAGF","sourcesContent":["import type { ReactiveElement, ReactiveController } from 'lit';\n\nexport class CssVariableController implements ReactiveController {\n style: CSSStyleDeclaration;\n\n constructor(public host: ReactiveElement) {\n this.style = window.getComputedStyle(host);\n }\n\n private parseProperty(name: string) {\n return name.substring(0, 2) !== '--' ? `--${name}` : name;\n }\n\n getVariable(name: string): string | null {\n return this.style.getPropertyValue(this.parseProperty(name)).trim() || null;\n }\n\n hostConnected?(): void;\n}\n"]}
1
+ {"version":3,"file":"css-variable-controller.js","sourceRoot":"","sources":["css-variable-controller.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,qBAAqB;IAGhC,YAAmB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QACtC,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1B,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,IAAY;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5D,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;IAC/E,CAAC;IAED,aAAa;QACX,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAAA,CAAC;CACH","sourcesContent":["import type { ReactiveElement, ReactiveController } from 'lit';\n\nexport class CssVariableController implements ReactiveController {\n style?: CSSStyleDeclaration;\n\n constructor(public host: ReactiveElement) {\n if (this.host.isConnected) {\n this.hostConnected();\n }\n }\n\n private parseProperty(name: string) {\n return name.substring(0, 2) !== '--' ? `--${name}` : name;\n }\n\n getVariable(name: string): string | null {\n return this.style?.getPropertyValue(this.parseProperty(name)).trim() || null;\n }\n\n hostConnected(): void {\n this.style = window.getComputedStyle(this.host);\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ReactiveController, ReactiveElement } from 'lit';
1
+ import { type ReactiveController, type ReactiveElement } from 'lit';
2
2
  interface AnonymousSlot {
3
3
  hasContent: boolean;
4
4
  elements: Element[];
@@ -1,5 +1,6 @@
1
1
  var _SlotController_instances, _a, _SlotController_nodes, _SlotController_logger, _SlotController_firstUpdated, _SlotController_mo, _SlotController_slotNames, _SlotController_deprecations, _SlotController_onSlotChange, _SlotController_onMutation, _SlotController_getChildrenForSlot, _SlotController_initSlot;
2
2
  import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { isServer } from 'lit';
3
4
  import { Logger } from './logger.js';
4
5
  function isObjectConfigSpread(config) {
5
6
  return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;
@@ -44,7 +45,8 @@ export class SlotController {
44
45
  ?? __classPrivateFieldGet(this, _SlotController_instances, "m", _SlotController_getChildrenForSlot).call(this, name);
45
46
  const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';
46
47
  const slot = this.host.shadowRoot?.querySelector?.(selector) ?? null;
47
- const hasContent = !!elements.length;
48
+ const nodes = slot?.assignedNodes?.();
49
+ const hasContent = !!elements.length || !!nodes?.filter(x => x.textContent?.trim()).length;
48
50
  __classPrivateFieldGet(this, _SlotController_nodes, "f").set(name, { elements, name: slotName ?? '', hasContent, slot });
49
51
  __classPrivateFieldGet(this, _SlotController_logger, "f").debug(slotName, hasContent);
50
52
  });
@@ -117,11 +119,20 @@ export class SlotController {
117
119
  * @example this.hasSlotted('header');
118
120
  */
119
121
  hasSlotted(...names) {
120
- const slotNames = Array.from(names, x => x == null ? _a.default : x);
121
- if (!slotNames.length) {
122
- slotNames.push(_a.default);
122
+ if (isServer) {
123
+ return this.host
124
+ .getAttribute('ssr-hint-has-slotted')
125
+ ?.split(',')
126
+ .map(name => name.trim())
127
+ .some(name => names.includes(name === 'default' ? null : name)) ?? false;
128
+ }
129
+ else {
130
+ const slotNames = Array.from(names, x => x == null ? _a.default : x);
131
+ if (!slotNames.length) {
132
+ slotNames.push(_a.default);
133
+ }
134
+ return slotNames.some(x => __classPrivateFieldGet(this, _SlotController_nodes, "f").get(x)?.hasContent ?? false);
123
135
  }
124
- return slotNames.some(x => __classPrivateFieldGet(this, _SlotController_nodes, "f").get(x)?.hasContent ?? false);
125
136
  }
126
137
  /**
127
138
  * Whether or not all the requested slots are empty.
@@ -1 +1 @@
1
- {"version":3,"file":"slot-controller.js","sourceRoot":"","sources":["slot-controller.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgCrC,SAAS,oBAAoB,CAC3B,MAA2C;IAE3C,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AACpF,CAAC;AAED;;;;GAIG;AACH,MAAM,MAAM,GACV,CAA8B,CAAyC,EAAE,EAAE,CACzE,CAAC,KAAc,EAAc,EAAE,CAC3B,CAAC,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;IAC5D,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEzC,MAAM,OAAO,cAAc;IAkBzB,YAAmB,IAAqB,EAAE,GAAG,MAA2C;;QAArE,SAAI,GAAJ,IAAI,CAAiB;QAZxC,gCAAS,IAAI,GAAG,EAAgD,EAAC;QAE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C,QAAQ,CAAC,EAAE,CAClC,uBAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,QAAQ,IAAI,EAAE,CAAQ,CAAC;QACtD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,GAAG,KAAoC;QAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YACtB,SAAS,CAAC,IAAI,CAAC,EAAc,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,uBAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,KAAK,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,KAAoC;QAC7C,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC;IACpC,CAAC;;+gBAsBC,IAA4C;IAE5C,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAQ,CAAC;IACvD,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACvC,CAAC;AAvIa,sBAAO,GAAG,MAAM,CAAC,cAAc,CAA4B,AAApD,CAAqD;AAE1E,gCAAgC;AAClB,wBAAS,GAAW,EAAI,CAAC,OAAO,AAAvB,CAAwB","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { Logger } from './logger.js';\n\ninterface AnonymousSlot {\n hasContent: boolean;\n elements: Element[];\n slot: HTMLSlotElement | null;\n}\n\ninterface NamedSlot extends AnonymousSlot {\n name: string;\n initialized: true;\n}\n\nexport type Slot = NamedSlot | AnonymousSlot;\n\nexport interface SlotsConfig {\n slots: (string | null)[];\n /**\n * Object mapping new slot name keys to deprecated slot name values\n * @example `pf-modal--header` is deprecated in favour of `header`\n * ```js\n * new SlotController(this, {\n * slots: ['header'],\n * deprecations: {\n * 'header': 'pf-modal--header'\n * }\n * })\n * ```\n */\n deprecations?: Record<string, string>;\n}\n\nfunction isObjectConfigSpread(\n config: ([SlotsConfig] | (string | null)[]),\n): config is [SlotsConfig] {\n return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;\n}\n\n/**\n * If it's a named slot, return its children,\n * for the default slot, look for direct children not assigned to a slot\n * @param n slot name\n */\nconst isSlot =\n <T extends Element = Element>(n: string | typeof SlotController.default) =>\n (child: Element): child is T =>\n n === SlotController.default ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static default = Symbol('default slot') satisfies symbol as symbol;\n\n /** @deprecated use `default` */\n public static anonymous: symbol = this.default;\n\n #nodes = new Map<string | typeof SlotController.default, Slot>();\n\n #logger: Logger;\n\n #firstUpdated = false;\n\n #mo = new MutationObserver(records => this.#onMutation(records));\n\n #slotNames: (string | null)[];\n\n #deprecations: Record<string, string> = {};\n\n constructor(public host: ReactiveElement, ...config: ([SlotsConfig] | (string | null)[])) {\n this.#logger = new Logger(this.host);\n\n if (isObjectConfigSpread(config)) {\n const [{ slots, deprecations }] = config;\n this.#slotNames = slots;\n this.#deprecations = deprecations ?? {};\n } else if (config.length >= 1) {\n this.#slotNames = config;\n this.#deprecations = {};\n } else {\n this.#slotNames = [null];\n }\n\n\n host.addController(this);\n }\n\n async hostConnected(): Promise<void> {\n this.host.addEventListener('slotchange', this.#onSlotChange as EventListener);\n this.#firstUpdated = false;\n this.#mo.observe(this.host, { childList: true });\n // Map the defined slots into an object that is easier to query\n this.#nodes.clear();\n // Loop over the properties provided by the schema\n this.#slotNames.forEach(this.#initSlot);\n Object.values(this.#deprecations).forEach(this.#initSlot);\n this.host.requestUpdate();\n // insurance for framework integrations\n await this.host.updateComplete;\n this.host.requestUpdate();\n }\n\n hostUpdated(): void {\n if (!this.#firstUpdated) {\n this.#slotNames.forEach(this.#initSlot);\n this.#firstUpdated = true;\n }\n }\n\n hostDisconnected(): void {\n this.#mo.disconnect();\n }\n\n /**\n * Given a slot name or slot names, returns elements assigned to the requested slots as an array.\n * If no value is provided, it returns all children not assigned to a slot (without a slot attribute).\n * @param slotNames slots to query\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\n * @example Get default-slotted elements\n * ```js\n * this.getSlotted();\n * ```\n */\n getSlotted<T extends Element = Element>(...slotNames: string[]): T[] {\n if (!slotNames.length) {\n return (this.#nodes.get(SlotController.default)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.#nodes.get(slotName)?.elements ?? []) as T[];\n }\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n * @param names The slot names to check.\n * @example this.hasSlotted('header');\n */\n hasSlotted(...names: (string | null | undefined)[]): boolean {\n const slotNames = Array.from(names, x => x == null ? SlotController.default : x);\n if (!slotNames.length) {\n slotNames.push(SlotController.default);\n }\n return slotNames.some(x => this.#nodes.get(x)?.hasContent ?? false);\n }\n\n /**\n * Whether or not all the requested slots are empty.\n * @param names The slot names to query. If no value is provided, it returns the default slot.\n * @example this.isEmpty('header', 'footer');\n * @example this.isEmpty();\n * @returns\n */\n isEmpty(...names: (string | null | undefined)[]): boolean {\n return !this.hasSlotted(...names);\n }\n\n #onSlotChange = (event: Event & { target: HTMLSlotElement }) => {\n const slotName = event.target.name;\n this.#initSlot(slotName);\n this.host.requestUpdate();\n };\n\n #onMutation = async (records: MutationRecord[]) => {\n const changed = [];\n for (const { addedNodes, removedNodes } of records) {\n for (const node of [...addedNodes, ...removedNodes]) {\n if (node instanceof HTMLElement && node.slot) {\n this.#initSlot(node.slot);\n changed.push(node.slot);\n }\n }\n }\n this.host.requestUpdate();\n };\n\n #getChildrenForSlot<T extends Element = Element>(\n name: string | typeof SlotController.default,\n ): T[] {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\n }\n\n #initSlot = (slotName: string | null) => {\n const name = slotName || SlotController.default;\n const elements = this.#nodes.get(name)?.slot?.assignedElements?.()\n ?? this.#getChildrenForSlot(name);\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;\n const hasContent = !!elements.length;\n this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });\n this.#logger.debug(slotName, hasContent);\n };\n}\n"]}
1
+ {"version":3,"file":"slot-controller.js","sourceRoot":"","sources":["slot-controller.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAiD,MAAM,KAAK,CAAC;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgCrC,SAAS,oBAAoB,CAC3B,MAA2C;IAE3C,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AACpF,CAAC;AAED;;;;GAIG;AACH,MAAM,MAAM,GACV,CAA8B,CAAyC,EAAE,EAAE,CACzE,CAAC,KAAc,EAAc,EAAE,CAC3B,CAAC,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;IAC5D,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEzC,MAAM,OAAO,cAAc;IAkBzB,YAAmB,IAAqB,EAAE,GAAG,MAA2C;;QAArE,SAAI,GAAJ,IAAI,CAAiB;QAZxC,gCAA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ACtE,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,KAAoC;QAC7C,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC;IACpC,CAAC;;+gBAsBC,IAA4C;IAE5C,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAQ,CAAC;IACvD,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACvC,CAAC;AA/Ia,sBAAO,GAAG,MAAM,CAAC,cAAc,CAA4B,AAApD,CAAqD;AAE1E,gCAAgC;AAClB,wBAAS,GAAW,EAAI,CAAC,OAAO,AAAvB,CAAwB","sourcesContent":["import { isServer, type ReactiveController, type ReactiveElement } from 'lit';\n\nimport { Logger } from './logger.js';\n\ninterface AnonymousSlot {\n hasContent: boolean;\n elements: Element[];\n slot: HTMLSlotElement | null;\n}\n\ninterface NamedSlot extends AnonymousSlot {\n name: string;\n initialized: true;\n}\n\nexport type Slot = NamedSlot | AnonymousSlot;\n\nexport interface SlotsConfig {\n slots: (string | null)[];\n /**\n * Object mapping new slot name keys to deprecated slot name values\n * @example `pf-modal--header` is deprecated in favour of `header`\n * ```js\n * new SlotController(this, {\n * slots: ['header'],\n * deprecations: {\n * 'header': 'pf-modal--header'\n * }\n * })\n * ```\n */\n deprecations?: Record<string, string>;\n}\n\nfunction isObjectConfigSpread(\n config: ([SlotsConfig] | (string | null)[]),\n): config is [SlotsConfig] {\n return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;\n}\n\n/**\n * If it's a named slot, return its children,\n * for the default slot, look for direct children not assigned to a slot\n * @param n slot name\n */\nconst isSlot =\n <T extends Element = Element>(n: string | typeof SlotController.default) =>\n (child: Element): child is T =>\n n === SlotController.default ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static default = Symbol('default slot') satisfies symbol as symbol;\n\n /** @deprecated use `default` */\n public static anonymous: symbol = this.default;\n\n #nodes = new Map<string | typeof SlotController.default, Slot>();\n\n #logger: Logger;\n\n #firstUpdated = false;\n\n #mo = new MutationObserver(records => this.#onMutation(records));\n\n #slotNames: (string | null)[];\n\n #deprecations: Record<string, string> = {};\n\n constructor(public host: ReactiveElement, ...config: ([SlotsConfig] | (string | null)[])) {\n this.#logger = new Logger(this.host);\n\n if (isObjectConfigSpread(config)) {\n const [{ slots, deprecations }] = config;\n this.#slotNames = slots;\n this.#deprecations = deprecations ?? {};\n } else if (config.length >= 1) {\n this.#slotNames = config;\n this.#deprecations = {};\n } else {\n this.#slotNames = [null];\n }\n\n\n host.addController(this);\n }\n\n async hostConnected(): Promise<void> {\n this.host.addEventListener('slotchange', this.#onSlotChange as EventListener);\n this.#firstUpdated = false;\n this.#mo.observe(this.host, { childList: true });\n // Map the defined slots into an object that is easier to query\n this.#nodes.clear();\n // Loop over the properties provided by the schema\n this.#slotNames.forEach(this.#initSlot);\n Object.values(this.#deprecations).forEach(this.#initSlot);\n this.host.requestUpdate();\n // insurance for framework integrations\n await this.host.updateComplete;\n this.host.requestUpdate();\n }\n\n hostUpdated(): void {\n if (!this.#firstUpdated) {\n this.#slotNames.forEach(this.#initSlot);\n this.#firstUpdated = true;\n }\n }\n\n hostDisconnected(): void {\n this.#mo.disconnect();\n }\n\n /**\n * Given a slot name or slot names, returns elements assigned to the requested slots as an array.\n * If no value is provided, it returns all children not assigned to a slot (without a slot attribute).\n * @param slotNames slots to query\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\n * @example Get default-slotted elements\n * ```js\n * this.getSlotted();\n * ```\n */\n getSlotted<T extends Element = Element>(...slotNames: string[]): T[] {\n if (!slotNames.length) {\n return (this.#nodes.get(SlotController.default)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.#nodes.get(slotName)?.elements ?? []) as T[];\n }\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n * @param names The slot names to check.\n * @example this.hasSlotted('header');\n */\n hasSlotted(...names: (string | null | undefined)[]): boolean {\n if (isServer) {\n return this.host\n .getAttribute('ssr-hint-has-slotted')\n ?.split(',')\n .map(name => name.trim())\n .some(name => names.includes(name === 'default' ? null : name)) ?? false;\n } else {\n const slotNames = Array.from(names, x => x == null ? SlotController.default : x);\n if (!slotNames.length) {\n slotNames.push(SlotController.default);\n }\n return slotNames.some(x => this.#nodes.get(x)?.hasContent ?? false);\n }\n }\n\n /**\n * Whether or not all the requested slots are empty.\n * @param names The slot names to query. If no value is provided, it returns the default slot.\n * @example this.isEmpty('header', 'footer');\n * @example this.isEmpty();\n * @returns\n */\n isEmpty(...names: (string | null | undefined)[]): boolean {\n return !this.hasSlotted(...names);\n }\n\n #onSlotChange = (event: Event & { target: HTMLSlotElement }) => {\n const slotName = event.target.name;\n this.#initSlot(slotName);\n this.host.requestUpdate();\n };\n\n #onMutation = async (records: MutationRecord[]) => {\n const changed = [];\n for (const { addedNodes, removedNodes } of records) {\n for (const node of [...addedNodes, ...removedNodes]) {\n if (node instanceof HTMLElement && node.slot) {\n this.#initSlot(node.slot);\n changed.push(node.slot);\n }\n }\n }\n this.host.requestUpdate();\n };\n\n #getChildrenForSlot<T extends Element = Element>(\n name: string | typeof SlotController.default,\n ): T[] {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\n }\n\n #initSlot = (slotName: string | null) => {\n const name = slotName || SlotController.default;\n const elements = this.#nodes.get(name)?.slot?.assignedElements?.()\n ?? this.#getChildrenForSlot(name);\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;\n const nodes = slot?.assignedNodes?.();\n const hasContent = !!elements.length || !!nodes?.filter(x => x.textContent?.trim()).length;\n this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });\n this.#logger.debug(slotName, hasContent);\n };\n}\n"]}
@@ -2709,7 +2709,7 @@
2709
2709
  "kind": "field",
2710
2710
  "name": "style",
2711
2711
  "type": {
2712
- "text": "CSSStyleDeclaration"
2712
+ "text": "CSSStyleDeclaration | undefined"
2713
2713
  }
2714
2714
  },
2715
2715
  {
@@ -2785,13 +2785,13 @@
2785
2785
  ]
2786
2786
  },
2787
2787
  {
2788
- "kind": "field",
2789
- "name": "host",
2790
- "default": "host"
2788
+ "kind": "method",
2789
+ "name": "hostConnected"
2791
2790
  },
2792
2791
  {
2793
2792
  "kind": "field",
2794
- "name": "style"
2793
+ "name": "host",
2794
+ "default": "host"
2795
2795
  }
2796
2796
  ]
2797
2797
  }
@@ -2820,7 +2820,7 @@
2820
2820
  "kind": "field",
2821
2821
  "name": "style",
2822
2822
  "type": {
2823
- "text": "CSSStyleDeclaration"
2823
+ "text": "CSSStyleDeclaration | undefined"
2824
2824
  }
2825
2825
  },
2826
2826
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/pfe-core",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "license": "MIT",
5
5
  "description": "PatternFly Elements Core Library",
6
6
  "customElements": "custom-elements.json",