@patternfly/pfe-core 2.4.0 → 2.4.1

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.
@@ -26,16 +26,11 @@ export interface SlotsConfig {
26
26
  deprecations?: Record<string, string>;
27
27
  }
28
28
  export declare class SlotController implements ReactiveController {
29
+ #private;
29
30
  host: ReactiveElement;
30
31
  static anonymous: symbol;
31
- private nodes;
32
- private logger;
33
- private firstUpdated;
34
- private mo;
35
- private slotNames;
36
- private deprecations;
37
32
  constructor(host: ReactiveElement, ...config: ([SlotsConfig] | (string | null)[]));
38
- hostConnected(): void;
33
+ hostConnected(): Promise<void>;
39
34
  hostUpdated(): void;
40
35
  hostDisconnected(): void;
41
36
  /**
@@ -65,13 +60,5 @@ export declare class SlotController implements ReactiveController {
65
60
  * ```
66
61
  */
67
62
  getSlotted<T extends Element = Element>(...slotNames: string[]): T[];
68
- private onSlotChange;
69
- private onMutation;
70
- private getChildrenForSlot;
71
- private initSlot;
72
- /**
73
- * Maps the defined slots into an object that is easier to query
74
- */
75
- private init;
76
63
  }
77
64
  export {};
@@ -1,5 +1,3 @@
1
- import { __decorate } from "tslib";
2
- import { bound } from '../decorators/bound.js';
3
1
  import { Logger } from './logger.js';
4
2
  function isObjectConfigSpread(config) {
5
3
  return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;
@@ -12,41 +10,51 @@ const isSlot = (n) => (child) => n === SlotController.anonymous ? !child.hasAttr
12
10
  : child.getAttribute('slot') === n;
13
11
  class SlotController {
14
12
  static { this.anonymous = Symbol('anonymous slot'); }
13
+ #nodes = new Map();
14
+ #logger;
15
+ #firstUpdated = false;
16
+ #mo = new MutationObserver(records => this.#onMutation(records));
17
+ #slotNames;
18
+ #deprecations = {};
15
19
  constructor(host, ...config) {
16
20
  this.host = host;
17
- this.nodes = new Map();
18
- this.firstUpdated = false;
19
- this.mo = new MutationObserver(this.onMutation);
20
- this.deprecations = {};
21
- this.logger = new Logger(this.host);
21
+ this.#logger = new Logger(this.host);
22
22
  if (isObjectConfigSpread(config)) {
23
23
  const [{ slots, deprecations }] = config;
24
- this.slotNames = slots;
25
- this.deprecations = deprecations ?? {};
24
+ this.#slotNames = slots;
25
+ this.#deprecations = deprecations ?? {};
26
26
  }
27
27
  else if (config.length >= 1) {
28
- this.slotNames = config;
29
- this.deprecations = {};
28
+ this.#slotNames = config;
29
+ this.#deprecations = {};
30
30
  }
31
31
  else {
32
- this.slotNames = [null];
32
+ this.#slotNames = [null];
33
33
  }
34
34
  host.addController(this);
35
35
  }
36
- hostConnected() {
37
- this.host.addEventListener('slotchange', this.onSlotChange);
38
- this.firstUpdated = false;
39
- this.mo.observe(this.host, { childList: true });
40
- this.init();
36
+ async hostConnected() {
37
+ this.host.addEventListener('slotchange', this.#onSlotChange);
38
+ this.#firstUpdated = false;
39
+ this.#mo.observe(this.host, { childList: true });
40
+ // Map the defined slots into an object that is easier to query
41
+ this.#nodes.clear();
42
+ // Loop over the properties provided by the schema
43
+ this.#slotNames.forEach(this.#initSlot);
44
+ Object.values(this.#deprecations).forEach(this.#initSlot);
45
+ this.host.requestUpdate();
46
+ // insurance for framework integrations
47
+ await this.host.updateComplete;
48
+ this.host.requestUpdate();
41
49
  }
42
50
  hostUpdated() {
43
- if (!this.firstUpdated) {
44
- this.slotNames.forEach(this.initSlot);
45
- this.firstUpdated = true;
51
+ if (!this.#firstUpdated) {
52
+ this.#slotNames.forEach(this.#initSlot);
53
+ this.#firstUpdated = true;
46
54
  }
47
55
  }
48
56
  hostDisconnected() {
49
- this.mo.disconnect();
57
+ this.#mo.disconnect();
50
58
  }
51
59
  /**
52
60
  * Returns a boolean statement of whether or not any of those slots exists in the light DOM.
@@ -56,11 +64,11 @@ class SlotController {
56
64
  */
57
65
  hasSlotted(...names) {
58
66
  if (!names.length) {
59
- this.logger.warn(`Please provide at least one slot name for which to search.`);
67
+ this.#logger.warn(`Please provide at least one slot name for which to search.`);
60
68
  return false;
61
69
  }
62
70
  else {
63
- return names.some(x => this.nodes.get(x)?.hasContent ?? false);
71
+ return names.some(x => this.#nodes.get(x)?.hasContent ?? false);
64
72
  }
65
73
  }
66
74
  /**
@@ -84,66 +92,42 @@ class SlotController {
84
92
  */
85
93
  getSlotted(...slotNames) {
86
94
  if (!slotNames.length) {
87
- return (this.nodes.get(SlotController.anonymous)?.elements ?? []);
95
+ return (this.#nodes.get(SlotController.anonymous)?.elements ?? []);
88
96
  }
89
97
  else {
90
- return slotNames.flatMap(slotName => this.nodes.get(slotName)?.elements ?? []);
98
+ return slotNames.flatMap(slotName => this.#nodes.get(slotName)?.elements ?? []);
91
99
  }
92
100
  }
93
- onSlotChange(event) {
101
+ #onSlotChange = (event) => {
94
102
  const slotName = event.target.name;
95
- this.initSlot(slotName);
103
+ this.#initSlot(slotName);
96
104
  this.host.requestUpdate();
97
- }
98
- async onMutation(records) {
105
+ };
106
+ #onMutation = async (records) => {
99
107
  const changed = [];
100
108
  for (const { addedNodes, removedNodes } of records) {
101
109
  for (const node of [...addedNodes, ...removedNodes]) {
102
110
  if (node instanceof HTMLElement && node.slot) {
103
- this.initSlot(node.slot);
111
+ this.#initSlot(node.slot);
104
112
  changed.push(node.slot);
105
113
  }
106
114
  }
107
115
  }
108
- if (changed.length) {
109
- this.host.requestUpdate();
110
- }
111
- }
112
- getChildrenForSlot(name) {
116
+ this.host.requestUpdate();
117
+ };
118
+ #getChildrenForSlot(name) {
113
119
  const children = Array.from(this.host.children);
114
120
  return children.filter(isSlot(name));
115
121
  }
116
- initSlot(slotName) {
122
+ #initSlot = (slotName) => {
117
123
  const name = slotName || SlotController.anonymous;
118
- const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? this.getChildrenForSlot(name);
124
+ const elements = this.#nodes.get(name)?.slot?.assignedElements?.() ?? this.#getChildrenForSlot(name);
119
125
  const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';
120
126
  const slot = this.host.shadowRoot?.querySelector?.(selector) ?? null;
121
127
  const hasContent = !!elements.length;
122
- this.nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });
123
- this.logger.log(slotName, hasContent);
124
- }
125
- /**
126
- * Maps the defined slots into an object that is easier to query
127
- */
128
- init() {
129
- this.nodes.clear();
130
- // Loop over the properties provided by the schema
131
- this.slotNames.forEach(this.initSlot);
132
- Object.values(this.deprecations).forEach(this.initSlot);
133
- this.host.requestUpdate();
134
- }
128
+ this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });
129
+ this.#logger.log(slotName, hasContent);
130
+ };
135
131
  }
136
- __decorate([
137
- bound
138
- ], SlotController.prototype, "onSlotChange", null);
139
- __decorate([
140
- bound
141
- ], SlotController.prototype, "onMutation", null);
142
- __decorate([
143
- bound
144
- ], SlotController.prototype, "initSlot", null);
145
- __decorate([
146
- bound
147
- ], SlotController.prototype, "init", null);
148
132
  export { SlotController };
149
133
  //# sourceMappingURL=slot-controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"slot-controller.js","sourceRoot":"","sources":["slot-controller.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgCrC,SAAS,oBAAoB,CAAC,MAA2C;IACvE,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;;;GAGG;AACH,MAAM,MAAM,GACV,CAA8B,CAA2C,EAAE,EAAE,CAC3E,CAAC,KAAc,EAAc,EAAE,CAC3B,CAAC,KAAK,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;IAC9D,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEzC,MAAa,cAAc;aACX,cAAS,GAAG,MA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,IAAI,EAAE,QAAQ,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACY,IAAI;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,kDAAkD;QAClD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;;AA7Cc;IAAd,KAAK;kDAIL;AAEoB;IAApB,KAAK;gDAaL;AAOc;IAAd,KAAK;8CAQL;AAKc;IAAd,KAAK;0CAML;SA5IU,cAAc","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { bound } from '../decorators/bound.js';\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(config: ([SlotsConfig] | (string | null)[])): 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 */\nconst isSlot =\n <T extends Element = Element>(n: string | typeof SlotController.anonymous) =>\n (child: Element): child is T =>\n n === SlotController.anonymous ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static anonymous = Symbol('anonymous slot');\n\n private nodes = new Map<string | typeof SlotController.anonymous, Slot>();\n\n private logger: Logger;\n\n private firstUpdated = false;\n\n private mo = new MutationObserver(this.onMutation);\n\n private slotNames: (string | null)[];\n\n private 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 hostConnected() {\n this.host.addEventListener('slotchange', this.onSlotChange as EventListener);\n this.firstUpdated = false;\n this.mo.observe(this.host, { childList: true });\n this.init();\n }\n\n hostUpdated() {\n if (!this.firstUpdated) {\n this.slotNames.forEach(this.initSlot);\n this.firstUpdated = true;\n }\n }\n\n hostDisconnected() {\n this.mo.disconnect();\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n *\n * @param {String|Array} name The slot name.\n * @example this.hasSlotted(\"header\");\n */\n hasSlotted(...names: string[]): boolean {\n if (!names.length) {\n this.logger.warn(`Please provide at least one slot name for which to search.`);\n return false;\n } else {\n return names.some(x =>\n this.nodes.get(x)?.hasContent ?? false);\n }\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 *\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n *\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\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.anonymous)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.nodes.get(slotName)?.elements ?? []) as T[];\n }\n }\n\n @bound private onSlotChange(event: Event & { target: HTMLSlotElement }) {\n const slotName = event.target.name;\n this.initSlot(slotName);\n this.host.requestUpdate();\n }\n\n @bound private async onMutation(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 if (changed.length) {\n this.host.requestUpdate();\n }\n }\n\n private getChildrenForSlot<T extends Element = Element>(name: string | typeof SlotController.anonymous): T[] {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\n }\n\n @bound private initSlot(slotName: string | null) {\n const name = slotName || SlotController.anonymous;\n const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? 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.log(slotName, hasContent);\n }\n\n /**\n * Maps the defined slots into an object that is easier to query\n */\n @bound private init() {\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 }\n}\n"]}
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,CAAC,MAA2C;IACvE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,M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AC;IAEF,mBAAmB,CAA8B,IAA8C;QAC7F,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAQ,CAAC;QACvD,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,SAAS,GAAG,CAAC,QAAuB,EAAE,EAAE;QACtC,MAAM,IAAI,GAAG,QAAQ,IAAI,cAAc,CAAC,SAAS,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,IAAI,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACrG,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,cAAc,QAAQ,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC;QAC5E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,EAAE,CAAkB,QAAQ,CAAC,IAAI,IAAI,CAAC;QACtF,MAAM,UAAU,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACzC,CAAC,CAAC;;SAvIS,cAAc","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(config: ([SlotsConfig] | (string | null)[])): 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 */\nconst isSlot =\n <T extends Element = Element>(n: string | typeof SlotController.anonymous) =>\n (child: Element): child is T =>\n n === SlotController.anonymous ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static anonymous = Symbol('anonymous slot');\n\n #nodes = new Map<string | typeof SlotController.anonymous, 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() {\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() {\n if (!this.#firstUpdated) {\n this.#slotNames.forEach(this.#initSlot);\n this.#firstUpdated = true;\n }\n }\n\n hostDisconnected() {\n this.#mo.disconnect();\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n *\n * @param {String|Array} name The slot name.\n * @example this.hasSlotted(\"header\");\n */\n hasSlotted(...names: string[]): boolean {\n if (!names.length) {\n this.#logger.warn(`Please provide at least one slot name for which to search.`);\n return false;\n } else {\n return names.some(x =>\n this.#nodes.get(x)?.hasContent ?? false);\n }\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 *\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n *\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\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.anonymous)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.#nodes.get(slotName)?.elements ?? []) as T[];\n }\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>(name: string | typeof SlotController.anonymous): 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.anonymous;\n const elements = this.#nodes.get(name)?.slot?.assignedElements?.() ?? 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.log(slotName, hasContent);\n };\n}\n"]}
@@ -4915,6 +4915,11 @@
4915
4915
  "description": "",
4916
4916
  "name": "SlotController",
4917
4917
  "members": [
4918
+ {
4919
+ "kind": "field",
4920
+ "name": "#private",
4921
+ "privacy": "private"
4922
+ },
4918
4923
  {
4919
4924
  "kind": "field",
4920
4925
  "name": "host",
@@ -4930,42 +4935,12 @@
4930
4935
  },
4931
4936
  "static": true
4932
4937
  },
4933
- {
4934
- "kind": "field",
4935
- "name": "nodes",
4936
- "privacy": "private"
4937
- },
4938
- {
4939
- "kind": "field",
4940
- "name": "logger",
4941
- "privacy": "private"
4942
- },
4943
- {
4944
- "kind": "field",
4945
- "name": "firstUpdated",
4946
- "privacy": "private"
4947
- },
4948
- {
4949
- "kind": "field",
4950
- "name": "mo",
4951
- "privacy": "private"
4952
- },
4953
- {
4954
- "kind": "field",
4955
- "name": "slotNames",
4956
- "privacy": "private"
4957
- },
4958
- {
4959
- "kind": "field",
4960
- "name": "deprecations",
4961
- "privacy": "private"
4962
- },
4963
4938
  {
4964
4939
  "kind": "method",
4965
4940
  "name": "hostConnected",
4966
4941
  "return": {
4967
4942
  "type": {
4968
- "text": "void"
4943
+ "text": "Promise<void>"
4969
4944
  }
4970
4945
  }
4971
4946
  },
@@ -5029,32 +5004,6 @@
5029
5004
  }
5030
5005
  ],
5031
5006
  "description": "Given a slot name or slot names, returns elements assigned to the requested slots as an array.\nIf no value is provided, it returns all children not assigned to a slot (without a slot attribute)."
5032
- },
5033
- {
5034
- "kind": "field",
5035
- "name": "onSlotChange",
5036
- "privacy": "private"
5037
- },
5038
- {
5039
- "kind": "field",
5040
- "name": "onMutation",
5041
- "privacy": "private"
5042
- },
5043
- {
5044
- "kind": "field",
5045
- "name": "getChildrenForSlot",
5046
- "privacy": "private"
5047
- },
5048
- {
5049
- "kind": "field",
5050
- "name": "initSlot",
5051
- "privacy": "private"
5052
- },
5053
- {
5054
- "kind": "field",
5055
- "name": "init",
5056
- "privacy": "private",
5057
- "description": "Maps the defined slots into an object that is easier to query"
5058
5007
  }
5059
5008
  ]
5060
5009
  }
@@ -5115,49 +5064,49 @@
5115
5064
  },
5116
5065
  {
5117
5066
  "kind": "field",
5118
- "name": "nodes",
5067
+ "name": "#nodes",
5119
5068
  "privacy": "private",
5120
5069
  "default": "new Map<string | typeof SlotController.anonymous, Slot>()"
5121
5070
  },
5122
5071
  {
5123
5072
  "kind": "field",
5124
- "name": "logger",
5073
+ "name": "#logger",
5074
+ "privacy": "private",
5125
5075
  "type": {
5126
5076
  "text": "Logger"
5127
5077
  },
5128
- "privacy": "private",
5129
5078
  "default": "new Logger(this.host)"
5130
5079
  },
5131
5080
  {
5132
5081
  "kind": "field",
5133
- "name": "firstUpdated",
5082
+ "name": "#firstUpdated",
5083
+ "privacy": "private",
5134
5084
  "type": {
5135
5085
  "text": "boolean"
5136
5086
  },
5137
- "privacy": "private",
5138
5087
  "default": "false"
5139
5088
  },
5140
5089
  {
5141
5090
  "kind": "field",
5142
- "name": "mo",
5091
+ "name": "#mo",
5143
5092
  "privacy": "private",
5144
- "default": "new MutationObserver(this.onMutation)"
5093
+ "default": "new MutationObserver(records => this.#onMutation(records))"
5145
5094
  },
5146
5095
  {
5147
5096
  "kind": "field",
5148
- "name": "slotNames",
5097
+ "name": "#slotNames",
5098
+ "privacy": "private",
5149
5099
  "type": {
5150
5100
  "text": "(string | null)[]"
5151
- },
5152
- "privacy": "private"
5101
+ }
5153
5102
  },
5154
5103
  {
5155
5104
  "kind": "field",
5156
- "name": "deprecations",
5105
+ "name": "#deprecations",
5106
+ "privacy": "private",
5157
5107
  "type": {
5158
5108
  "text": "Record<string, string>"
5159
5109
  },
5160
- "privacy": "private",
5161
5110
  "default": "{}"
5162
5111
  },
5163
5112
  {
@@ -5216,35 +5165,18 @@
5216
5165
  "description": "Given a slot name or slot names, returns elements assigned to the requested slots as an array.\nIf no value is provided, it returns all children not assigned to a slot (without a slot attribute)."
5217
5166
  },
5218
5167
  {
5219
- "kind": "method",
5220
- "name": "onSlotChange",
5221
- "privacy": "private",
5222
- "parameters": [
5223
- {
5224
- "name": "event",
5225
- "type": {
5226
- "text": "Event & { target: HTMLSlotElement }"
5227
- }
5228
- }
5229
- ]
5168
+ "kind": "field",
5169
+ "name": "#onSlotChange",
5170
+ "privacy": "private"
5230
5171
  },
5231
5172
  {
5232
- "kind": "method",
5233
- "name": "onMutation",
5234
- "privacy": "private",
5235
- "parameters": [
5236
- {
5237
- "name": "records",
5238
- "type": {
5239
- "text": "MutationRecord[]"
5240
- }
5241
- }
5242
- ]
5173
+ "kind": "field",
5174
+ "name": "#onMutation",
5175
+ "privacy": "private"
5243
5176
  },
5244
5177
  {
5245
5178
  "kind": "method",
5246
- "name": "getChildrenForSlot",
5247
- "privacy": "private",
5179
+ "name": "#getChildrenForSlot",
5248
5180
  "return": {
5249
5181
  "type": {
5250
5182
  "text": "T[]"
@@ -5260,23 +5192,9 @@
5260
5192
  ]
5261
5193
  },
5262
5194
  {
5263
- "kind": "method",
5264
- "name": "initSlot",
5265
- "privacy": "private",
5266
- "parameters": [
5267
- {
5268
- "name": "slotName",
5269
- "type": {
5270
- "text": "string | null"
5271
- }
5272
- }
5273
- ]
5274
- },
5275
- {
5276
- "kind": "method",
5277
- "name": "init",
5278
- "privacy": "private",
5279
- "description": "Maps the defined slots into an object that is easier to query"
5195
+ "kind": "field",
5196
+ "name": "#initSlot",
5197
+ "privacy": "private"
5280
5198
  },
5281
5199
  {
5282
5200
  "kind": "field",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/pfe-core",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "description": "PatternFly Elements Core Library",
6
6
  "customElements": "custom-elements.json",