@patternfly/pfe-core 4.0.5 → 5.0.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.
@@ -1,90 +1,84 @@
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;
1
+ var _SlotController_instances, _a, _SlotController_slotRecords, _SlotController_slotNames, _SlotController_deprecations, _SlotController_initSlotMap, _SlotController_mo, _SlotController_initialize, _SlotController_getSlotElement;
2
2
  import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
- import { isServer } from 'lit';
4
- import { Logger } from './logger.js';
5
- function isObjectConfigSpread(config) {
3
+ export function isObjectSpread(config) {
6
4
  return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;
7
5
  }
8
- /**
9
- * If it's a named slot, return its children,
10
- * for the default slot, look for direct children not assigned to a slot
11
- * @param n slot name
12
- */
13
- const isSlot = (n) => (child) => n === SlotController.default ? !child.hasAttribute('slot')
14
- : child.getAttribute('slot') === n;
6
+ function isContent(node) {
7
+ switch (node.nodeType) {
8
+ case Node.TEXT_NODE:
9
+ return !!node.textContent?.trim();
10
+ case Node.COMMENT_NODE:
11
+ return false;
12
+ default:
13
+ return true;
14
+ }
15
+ }
16
+ class SlotRecord {
17
+ constructor(slot, name, host) {
18
+ this.slot = slot;
19
+ this.name = name;
20
+ this.host = host;
21
+ }
22
+ get elements() {
23
+ return this.slot?.assignedElements?.();
24
+ }
25
+ get hasContent() {
26
+ if (this.name === SlotController.default) {
27
+ return !!this.elements.length
28
+ || !![...this.host.childNodes]
29
+ .some(node => {
30
+ if (node instanceof Element) {
31
+ return !node.hasAttribute('slot');
32
+ }
33
+ else {
34
+ return isContent(node);
35
+ }
36
+ });
37
+ }
38
+ else {
39
+ return !!this.slot.assignedNodes()
40
+ .some(isContent);
41
+ }
42
+ }
43
+ }
15
44
  export class SlotController {
16
- constructor(host, ...config) {
45
+ constructor(host, ...args) {
17
46
  _SlotController_instances.add(this);
18
47
  this.host = host;
19
- _SlotController_nodes.set(this, new Map());
20
- _SlotController_logger.set(this, void 0);
21
- _SlotController_firstUpdated.set(this, false);
22
- _SlotController_mo.set(this, new MutationObserver(records => __classPrivateFieldGet(this, _SlotController_onMutation, "f").call(this, records)));
23
- _SlotController_slotNames.set(this, void 0);
48
+ _SlotController_slotRecords.set(this, new Map());
49
+ _SlotController_slotNames.set(this, []);
24
50
  _SlotController_deprecations.set(this, {});
25
- _SlotController_onSlotChange.set(this, (event) => {
26
- const slotName = event.target.name;
27
- __classPrivateFieldGet(this, _SlotController_initSlot, "f").call(this, slotName);
28
- this.host.requestUpdate();
29
- });
30
- _SlotController_onMutation.set(this, async (records) => {
31
- const changed = [];
32
- for (const { addedNodes, removedNodes } of records) {
33
- for (const node of [...addedNodes, ...removedNodes]) {
34
- if (node instanceof HTMLElement && node.slot) {
35
- __classPrivateFieldGet(this, _SlotController_initSlot, "f").call(this, node.slot);
36
- changed.push(node.slot);
37
- }
51
+ _SlotController_initSlotMap.set(this, async () => {
52
+ const { host } = this;
53
+ await host.updateComplete;
54
+ const slotRecords = __classPrivateFieldGet(this, _SlotController_slotRecords, "f");
55
+ // Loop over the properties provided by the schema
56
+ for (let slotName of __classPrivateFieldGet(this, _SlotController_slotNames, "f").concat(Object.values(__classPrivateFieldGet(this, _SlotController_deprecations, "f")))) {
57
+ slotName || (slotName = _a.default);
58
+ const slot = __classPrivateFieldGet(this, _SlotController_instances, "m", _SlotController_getSlotElement).call(this, slotName);
59
+ if (slot) {
60
+ slotRecords.set(slotName, new SlotRecord(slot, slotName, host));
38
61
  }
39
62
  }
40
- this.host.requestUpdate();
63
+ host.requestUpdate();
41
64
  });
42
- _SlotController_initSlot.set(this, (slotName) => {
43
- const name = slotName || _a.default;
44
- const elements = __classPrivateFieldGet(this, _SlotController_nodes, "f").get(name)?.slot?.assignedElements?.()
45
- ?? __classPrivateFieldGet(this, _SlotController_instances, "m", _SlotController_getChildrenForSlot).call(this, name);
46
- const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';
47
- const slot = this.host.shadowRoot?.querySelector?.(selector) ?? null;
48
- const nodes = slot?.assignedNodes?.();
49
- const hasContent = !!elements.length || !!nodes?.filter(x => x.textContent?.trim()).length;
50
- __classPrivateFieldGet(this, _SlotController_nodes, "f").set(name, { elements, name: slotName ?? '', hasContent, slot });
51
- __classPrivateFieldGet(this, _SlotController_logger, "f").debug(slotName, hasContent);
52
- });
53
- __classPrivateFieldSet(this, _SlotController_logger, new Logger(this.host), "f");
54
- if (isObjectConfigSpread(config)) {
55
- const [{ slots, deprecations }] = config;
56
- __classPrivateFieldSet(this, _SlotController_slotNames, slots, "f");
57
- __classPrivateFieldSet(this, _SlotController_deprecations, deprecations ?? {}, "f");
58
- }
59
- else if (config.length >= 1) {
60
- __classPrivateFieldSet(this, _SlotController_slotNames, config, "f");
61
- __classPrivateFieldSet(this, _SlotController_deprecations, {}, "f");
62
- }
63
- else {
65
+ _SlotController_mo.set(this, new MutationObserver(__classPrivateFieldGet(this, _SlotController_initSlotMap, "f")));
66
+ host.addController(this);
67
+ __classPrivateFieldGet(this, _SlotController_instances, "m", _SlotController_initialize).call(this, ...args);
68
+ if (!__classPrivateFieldGet(this, _SlotController_slotNames, "f").length) {
64
69
  __classPrivateFieldSet(this, _SlotController_slotNames, [null], "f");
65
70
  }
66
- host.addController(this);
67
71
  }
68
72
  async hostConnected() {
69
- this.host.addEventListener('slotchange', __classPrivateFieldGet(this, _SlotController_onSlotChange, "f"));
70
- __classPrivateFieldSet(this, _SlotController_firstUpdated, false, "f");
71
73
  __classPrivateFieldGet(this, _SlotController_mo, "f").observe(this.host, { childList: true });
72
74
  // Map the defined slots into an object that is easier to query
73
- __classPrivateFieldGet(this, _SlotController_nodes, "f").clear();
74
- // Loop over the properties provided by the schema
75
- __classPrivateFieldGet(this, _SlotController_slotNames, "f").forEach(__classPrivateFieldGet(this, _SlotController_initSlot, "f"));
76
- Object.values(__classPrivateFieldGet(this, _SlotController_deprecations, "f")).forEach(__classPrivateFieldGet(this, _SlotController_initSlot, "f"));
77
- this.host.requestUpdate();
75
+ __classPrivateFieldGet(this, _SlotController_slotRecords, "f").clear();
76
+ await this.host.updateComplete;
77
+ __classPrivateFieldGet(this, _SlotController_initSlotMap, "f").call(this);
78
78
  // insurance for framework integrations
79
79
  await this.host.updateComplete;
80
80
  this.host.requestUpdate();
81
81
  }
82
- hostUpdated() {
83
- if (!__classPrivateFieldGet(this, _SlotController_firstUpdated, "f")) {
84
- __classPrivateFieldGet(this, _SlotController_slotNames, "f").forEach(__classPrivateFieldGet(this, _SlotController_initSlot, "f"));
85
- __classPrivateFieldSet(this, _SlotController_firstUpdated, true, "f");
86
- }
87
- }
88
82
  hostDisconnected() {
89
83
  __classPrivateFieldGet(this, _SlotController_mo, "f").disconnect();
90
84
  }
@@ -106,11 +100,11 @@ export class SlotController {
106
100
  * ```
107
101
  */
108
102
  getSlotted(...slotNames) {
109
- if (!slotNames.length) {
110
- return (__classPrivateFieldGet(this, _SlotController_nodes, "f").get(_a.default)?.elements ?? []);
103
+ if (!slotNames.length || slotNames.length === 1 && slotNames.at(0) === null) {
104
+ return (__classPrivateFieldGet(this, _SlotController_slotRecords, "f").get(_a.default)?.elements ?? []);
111
105
  }
112
106
  else {
113
- return slotNames.flatMap(slotName => __classPrivateFieldGet(this, _SlotController_nodes, "f").get(slotName)?.elements ?? []);
107
+ return slotNames.flatMap(slotName => __classPrivateFieldGet(this, _SlotController_slotRecords, "f").get(slotName ?? _a.default)?.elements ?? []);
114
108
  }
115
109
  }
116
110
  /**
@@ -119,20 +113,19 @@ export class SlotController {
119
113
  * @example this.hasSlotted('header');
120
114
  */
121
115
  hasSlotted(...names) {
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;
116
+ const slotNames = Array.from(names, x => x == null ? _a.default : x);
117
+ if (!slotNames.length) {
118
+ slotNames.push(_a.default);
128
119
  }
129
- else {
130
- const slotNames = Array.from(names, x => x == null ? _a.default : x);
131
- if (!slotNames.length) {
132
- slotNames.push(_a.default);
120
+ return slotNames.some(slotName => {
121
+ const slot = __classPrivateFieldGet(this, _SlotController_slotRecords, "f").get(slotName);
122
+ if (!slot) {
123
+ return false;
133
124
  }
134
- return slotNames.some(x => __classPrivateFieldGet(this, _SlotController_nodes, "f").get(x)?.hasContent ?? false);
135
- }
125
+ else {
126
+ return slot.hasContent;
127
+ }
128
+ });
136
129
  }
137
130
  /**
138
131
  * Whether or not all the requested slots are empty.
@@ -145,9 +138,19 @@ export class SlotController {
145
138
  return !this.hasSlotted(...names);
146
139
  }
147
140
  }
148
- _a = SlotController, _SlotController_nodes = new WeakMap(), _SlotController_logger = new WeakMap(), _SlotController_firstUpdated = new WeakMap(), _SlotController_mo = new WeakMap(), _SlotController_slotNames = new WeakMap(), _SlotController_deprecations = new WeakMap(), _SlotController_onSlotChange = new WeakMap(), _SlotController_onMutation = new WeakMap(), _SlotController_initSlot = new WeakMap(), _SlotController_instances = new WeakSet(), _SlotController_getChildrenForSlot = function _SlotController_getChildrenForSlot(name) {
149
- const children = Array.from(this.host.children);
150
- return children.filter(isSlot(name));
141
+ _a = SlotController, _SlotController_slotRecords = new WeakMap(), _SlotController_slotNames = new WeakMap(), _SlotController_deprecations = new WeakMap(), _SlotController_initSlotMap = new WeakMap(), _SlotController_mo = new WeakMap(), _SlotController_instances = new WeakSet(), _SlotController_initialize = function _SlotController_initialize(...config) {
142
+ if (isObjectSpread(config)) {
143
+ const [{ slots, deprecations }] = config;
144
+ __classPrivateFieldSet(this, _SlotController_slotNames, slots, "f");
145
+ __classPrivateFieldSet(this, _SlotController_deprecations, deprecations ?? {}, "f");
146
+ }
147
+ else if (config.length >= 1) {
148
+ __classPrivateFieldSet(this, _SlotController_slotNames, config, "f");
149
+ __classPrivateFieldSet(this, _SlotController_deprecations, {}, "f");
150
+ }
151
+ }, _SlotController_getSlotElement = function _SlotController_getSlotElement(slotId) {
152
+ const selector = slotId === _a.default ? 'slot:not([name])' : `slot[name="${slotId}"]`;
153
+ return this.host.shadowRoot?.querySelector?.(selector) ?? null;
151
154
  };
152
155
  SlotController.default = Symbol('default slot');
153
156
  /** @deprecated use `default` */
@@ -1 +1 @@
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,gCAAS,IAAI,GAAG,EAAgD,EAAC;QAEjE,yCAAgB;QAEhB,uCAAgB,KAAK,EAAC;QAEtB,6BAAM,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,uBAAA,IAAI,kCAAY,MAAhB,IAAI,EAAa,OAAO,CAAC,CAAC,EAAC;QAE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,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"]}
1
+ {"version":3,"file":"slot-controller.js","sourceRoot":"","sources":["slot-controller.ts"],"names":[],"mappings":";;AAoCA,MAAM,UAAU,cAAc,CAAC,MAA0B;IACvD,OAAO,MAAM,CAAC,MAAM,KA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kB,QAAQ,CAAC,IAAI,IAAI,CAAC;AAClF,CAAC;AAnDa,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\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 type SlotName = string | null;\n\nexport interface SlotsConfig {\n slots: SlotName[];\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\nexport type SlotControllerArgs = [SlotsConfig] | SlotName[];\n\nexport function isObjectSpread(config: SlotControllerArgs): config is [SlotsConfig] {\n return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;\n}\n\nfunction isContent(node: Node) {\n switch (node.nodeType) {\n case Node.TEXT_NODE:\n return !!node.textContent?.trim();\n case Node.COMMENT_NODE:\n return false;\n default:\n return true;\n }\n}\n\nexport declare class SlotControllerPublicAPI implements ReactiveController {\n static default: symbol;\n\n public host: ReactiveElement;\n\n constructor(host: ReactiveElement, ...args: SlotControllerArgs);\n\n hostConnected?(): Promise<void>;\n\n hostDisconnected?(): void;\n\n hostUpdated?(): void;\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\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\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}\n\nclass SlotRecord {\n constructor(\n public slot: HTMLSlotElement,\n public name: string | symbol,\n private host: ReactiveElement,\n ) {}\n\n get elements() {\n return this.slot?.assignedElements?.();\n }\n\n get hasContent() {\n if (this.name === SlotController.default) {\n return !!this.elements.length\n || !![...this.host.childNodes]\n .some(node => {\n if (node instanceof Element) {\n return !node.hasAttribute('slot');\n } else {\n return isContent(node);\n }\n });\n } else {\n return !!this.slot.assignedNodes()\n .some(isContent);\n }\n }\n}\n\nexport class SlotController implements SlotControllerPublicAPI {\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 #slotRecords = new Map<string | typeof SlotController.default, SlotRecord>();\n\n #slotNames: (string | symbol | null)[] = [];\n\n #deprecations: Record<string, string> = {};\n\n #initSlotMap = async () => {\n const { host } = this;\n await host.updateComplete;\n const slotRecords = this.#slotRecords;\n // Loop over the properties provided by the schema\n for (let slotName of this.#slotNames.concat(Object.values(this.#deprecations))) {\n slotName ||= SlotController.default;\n const slot = this.#getSlotElement(slotName);\n if (slot) {\n slotRecords.set(slotName, new SlotRecord(slot, slotName, host));\n }\n }\n host.requestUpdate();\n };\n\n #mo = new MutationObserver(this.#initSlotMap);\n\n constructor(public host: ReactiveElement, ...args: SlotControllerArgs) {\n host.addController(this);\n this.#initialize(...args);\n if (!this.#slotNames.length) {\n this.#slotNames = [null];\n }\n }\n\n #initialize(...config: SlotControllerArgs) {\n if (isObjectSpread(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 }\n }\n\n #getSlotElement(slotId: string | symbol) {\n const selector =\n slotId === SlotController.default ? 'slot:not([name])' : `slot[name=\"${slotId as string}\"]`;\n return this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;\n }\n\n async hostConnected(): Promise<void> {\n this.#mo.observe(this.host, { childList: true });\n // Map the defined slots into an object that is easier to query\n this.#slotRecords.clear();\n await this.host.updateComplete;\n this.#initSlotMap();\n // insurance for framework integrations\n await this.host.updateComplete;\n this.host.requestUpdate();\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 public getSlotted<T extends Element = Element>(...slotNames: string[] | [null]): T[] {\n if (!slotNames.length || slotNames.length === 1 && slotNames.at(0) === null) {\n return (this.#slotRecords.get(SlotController.default)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.#slotRecords.get(slotName ?? SlotController.default)?.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 public hasSlotted(...names: (string | null | undefined)[]): boolean {\n const slotNames = Array.from(names, x =>\n x == null ? SlotController.default : x);\n if (!slotNames.length) {\n slotNames.push(SlotController.default);\n }\n return slotNames.some(slotName => {\n const slot = this.#slotRecords.get(slotName);\n if (!slot) {\n return false;\n } else {\n return slot.hasContent;\n }\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 public isEmpty(...names: (string | null | undefined)[]): boolean {\n return !this.hasSlotted(...names);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,148 @@
1
+ import { __decorate } from "tslib";
2
+ import { expect, fixture, nextFrame } from '@open-wc/testing';
3
+ import { customElement } from 'lit/decorators/custom-element.js';
4
+ import { LitElement, html } from 'lit';
5
+ import { SlotController } from '../slot-controller.js';
6
+ let TestSlotControllerWithNamedAndAnonymous = class TestSlotControllerWithNamedAndAnonymous extends LitElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.controller = new SlotController(this, 'a', null);
10
+ }
11
+ render() {
12
+ return html `
13
+ <slot name="a"></slot>
14
+ <slot name="b"></slot>
15
+ <slot></slot>
16
+ `;
17
+ }
18
+ };
19
+ TestSlotControllerWithNamedAndAnonymous = __decorate([
20
+ customElement('test-slot-controller-with-named-and-anonymous')
21
+ ], TestSlotControllerWithNamedAndAnonymous);
22
+ describe('SlotController', function () {
23
+ describe('with named and anonymous slots', function () {
24
+ describe('with no content', function () {
25
+ let element;
26
+ beforeEach(async function () {
27
+ element = await fixture(html `
28
+ <test-slot-controller-with-named-and-anonymous></test-slot-controller-with-named-and-anonymous>
29
+ `);
30
+ });
31
+ it('reports empty named slots', function () {
32
+ expect(element.controller.hasSlotted('a')).to.be.false;
33
+ expect(element.controller.isEmpty('a')).to.be.true;
34
+ });
35
+ it('reports empty default slot', function () {
36
+ expect(element.controller.hasSlotted(null)).to.be.false;
37
+ expect(element.controller.isEmpty(null)).to.be.true;
38
+ });
39
+ it('reports empty default slot with no arguments', function () {
40
+ expect(element.controller.hasSlotted()).to.be.false;
41
+ expect(element.controller.isEmpty()).to.be.true;
42
+ });
43
+ it('returns empty list for getSlotted("a")', function () {
44
+ expect(element.controller.getSlotted('a')).to.be.empty;
45
+ });
46
+ it('returns empty list for getSlotted(null)', function () {
47
+ expect(element.controller.getSlotted(null)).to.be.empty;
48
+ });
49
+ it('returns empty list for getSlotted()', function () {
50
+ expect(element.controller.getSlotted()).to.be.empty;
51
+ });
52
+ });
53
+ describe('with element content in default slot', function () {
54
+ let element;
55
+ beforeEach(async function () {
56
+ element = await fixture(html `
57
+ <test-slot-controller-with-named-and-anonymous>
58
+ <p>element</p>
59
+ </test-slot-controller-with-named-and-anonymous>
60
+ `);
61
+ });
62
+ it('reports empty named slots', function () {
63
+ expect(element.controller.hasSlotted('a')).to.be.false;
64
+ expect(element.controller.isEmpty('a')).to.be.true;
65
+ });
66
+ it('reports non-empty default slot', function () {
67
+ expect(element.controller.hasSlotted(null)).to.be.true;
68
+ expect(element.controller.isEmpty(null)).to.be.false;
69
+ });
70
+ it('reports non-empty default slot with no arguments', function () {
71
+ expect(element.controller.hasSlotted()).to.be.true;
72
+ expect(element.controller.isEmpty()).to.be.false;
73
+ });
74
+ it('returns empty list for getSlotted("a")', function () {
75
+ expect(element.controller.getSlotted('a')).to.be.empty;
76
+ });
77
+ it('returns lengthy list for getSlotted(null)', function () {
78
+ expect(element.controller.getSlotted(null)).to.not.be.empty;
79
+ });
80
+ it('returns lengthy list for getSlotted()', function () {
81
+ expect(element.controller.getSlotted()).to.not.be.empty;
82
+ });
83
+ });
84
+ describe('with element content in named slot', function () {
85
+ let element;
86
+ beforeEach(async function () {
87
+ element = await fixture(html `
88
+ <test-slot-controller-with-named-and-anonymous>
89
+ <p slot="a">element</p>
90
+ </test-slot-controller-with-named-and-anonymous>
91
+ `);
92
+ });
93
+ it('reports non-empty named slots', function () {
94
+ expect(element.controller.hasSlotted('a')).to.be.true;
95
+ expect(element.controller.isEmpty('a')).to.be.false;
96
+ });
97
+ it('reports empty default slot', function () {
98
+ expect(element.controller.hasSlotted(null)).to.be.false;
99
+ expect(element.controller.isEmpty(null)).to.be.true;
100
+ });
101
+ it('reports empty default slot with no arguments', function () {
102
+ expect(element.controller.hasSlotted()).to.be.false;
103
+ expect(element.controller.isEmpty()).to.be.true;
104
+ });
105
+ it('returns lengthy list for getSlotted("a")', function () {
106
+ expect(element.controller.getSlotted('a')).to.not.be.empty;
107
+ });
108
+ it('returns empty list for getSlotted(null)', function () {
109
+ expect(element.controller.getSlotted(null)).to.be.empty;
110
+ });
111
+ it('returns empty list for getSlotted()', function () {
112
+ expect(element.controller.getSlotted()).to.be.empty;
113
+ });
114
+ });
115
+ describe('with text content in default slot', function () {
116
+ let element;
117
+ beforeEach(async function () {
118
+ element = await fixture(html `
119
+ <test-slot-controller-with-named-and-anonymous>
120
+ text
121
+ </test-slot-controller-with-named-and-anonymous>
122
+ `);
123
+ });
124
+ it('reports empty named slots', function () {
125
+ expect(element.controller.hasSlotted('a')).to.be.false;
126
+ expect(element.controller.isEmpty('a')).to.be.true;
127
+ });
128
+ it('reports non-empty default slot', function () {
129
+ expect(element.controller.hasSlotted(null)).to.be.true;
130
+ expect(element.controller.isEmpty(null)).to.be.false;
131
+ });
132
+ it('reports non-empty default slot with no arguments', function () {
133
+ expect(element.controller.hasSlotted()).to.be.true;
134
+ expect(element.controller.isEmpty()).to.be.false;
135
+ });
136
+ it('returns empty list for getSlotted("a")', function () {
137
+ expect(element.controller.getSlotted('a')).to.be.empty;
138
+ });
139
+ it('returns lengthy list for getSlotted(null)', function () {
140
+ expect(element.controller.getSlotted(null)).to.be.empty;
141
+ });
142
+ it('returns lengthy list for getSlotted()', function () {
143
+ expect(element.controller.getSlotted()).to.be.empty;
144
+ });
145
+ });
146
+ });
147
+ });
148
+ //# sourceMappingURL=slot-controller.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slot-controller.spec.js","sourceRoot":"","sources":["slot-controller.spec.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,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3C,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;YACzD,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,2CAA2C,EAAE;gBAC9C,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;YAC1D,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,uCAAuC,EAAE;gBAC1C,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;YACtD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect, fixture, nextFrame } from '@open-wc/testing';\n\nimport { customElement } from 'lit/decorators/custom-element.js';\nimport { LitElement, html, type TemplateResult } from 'lit';\n\nimport { SlotController } from '../slot-controller.js';\n\n@customElement('test-slot-controller-with-named-and-anonymous')\nclass TestSlotControllerWithNamedAndAnonymous extends LitElement {\n controller = new SlotController(this, 'a', null);\n render(): TemplateResult {\n return html`\n <slot name=\"a\"></slot>\n <slot name=\"b\"></slot>\n <slot></slot>\n `;\n }\n}\n\ndescribe('SlotController', function() {\n describe('with named and anonymous slots', function() {\n describe('with no content', function() {\n let element: TestSlotControllerWithNamedAndAnonymous;\n beforeEach(async function() {\n element = await fixture(html`\n <test-slot-controller-with-named-and-anonymous></test-slot-controller-with-named-and-anonymous>\n `);\n });\n it('reports empty named slots', function() {\n expect(element.controller.hasSlotted('a')).to.be.false;\n expect(element.controller.isEmpty('a')).to.be.true;\n });\n it('reports empty default slot', function() {\n expect(element.controller.hasSlotted(null)).to.be.false;\n expect(element.controller.isEmpty(null)).to.be.true;\n });\n it('reports empty default slot with no arguments', function() {\n expect(element.controller.hasSlotted()).to.be.false;\n expect(element.controller.isEmpty()).to.be.true;\n });\n it('returns empty list for getSlotted(\"a\")', function() {\n expect(element.controller.getSlotted('a')).to.be.empty;\n });\n it('returns empty list for getSlotted(null)', function() {\n expect(element.controller.getSlotted(null)).to.be.empty;\n });\n it('returns empty list for getSlotted()', function() {\n expect(element.controller.getSlotted()).to.be.empty;\n });\n });\n\n describe('with element content in default slot', function() {\n let element: TestSlotControllerWithNamedAndAnonymous;\n beforeEach(async function() {\n element = await fixture(html`\n <test-slot-controller-with-named-and-anonymous>\n <p>element</p>\n </test-slot-controller-with-named-and-anonymous>\n `);\n });\n it('reports empty named slots', function() {\n expect(element.controller.hasSlotted('a')).to.be.false;\n expect(element.controller.isEmpty('a')).to.be.true;\n });\n it('reports non-empty default slot', function() {\n expect(element.controller.hasSlotted(null)).to.be.true;\n expect(element.controller.isEmpty(null)).to.be.false;\n });\n it('reports non-empty default slot with no arguments', function() {\n expect(element.controller.hasSlotted()).to.be.true;\n expect(element.controller.isEmpty()).to.be.false;\n });\n it('returns empty list for getSlotted(\"a\")', function() {\n expect(element.controller.getSlotted('a')).to.be.empty;\n });\n it('returns lengthy list for getSlotted(null)', function() {\n expect(element.controller.getSlotted(null)).to.not.be.empty;\n });\n it('returns lengthy list for getSlotted()', function() {\n expect(element.controller.getSlotted()).to.not.be.empty;\n });\n });\n\n describe('with element content in named slot', function() {\n let element: TestSlotControllerWithNamedAndAnonymous;\n beforeEach(async function() {\n element = await fixture(html`\n <test-slot-controller-with-named-and-anonymous>\n <p slot=\"a\">element</p>\n </test-slot-controller-with-named-and-anonymous>\n `);\n });\n it('reports non-empty named slots', function() {\n expect(element.controller.hasSlotted('a')).to.be.true;\n expect(element.controller.isEmpty('a')).to.be.false;\n });\n it('reports empty default slot', function() {\n expect(element.controller.hasSlotted(null)).to.be.false;\n expect(element.controller.isEmpty(null)).to.be.true;\n });\n it('reports empty default slot with no arguments', function() {\n expect(element.controller.hasSlotted()).to.be.false;\n expect(element.controller.isEmpty()).to.be.true;\n });\n it('returns lengthy list for getSlotted(\"a\")', function() {\n expect(element.controller.getSlotted('a')).to.not.be.empty;\n });\n it('returns empty list for getSlotted(null)', function() {\n expect(element.controller.getSlotted(null)).to.be.empty;\n });\n it('returns empty list for getSlotted()', function() {\n expect(element.controller.getSlotted()).to.be.empty;\n });\n });\n\n describe('with text content in default slot', function() {\n let element: TestSlotControllerWithNamedAndAnonymous;\n beforeEach(async function() {\n element = await fixture(html`\n <test-slot-controller-with-named-and-anonymous>\n text\n </test-slot-controller-with-named-and-anonymous>\n `);\n });\n it('reports empty named slots', function() {\n expect(element.controller.hasSlotted('a')).to.be.false;\n expect(element.controller.isEmpty('a')).to.be.true;\n });\n it('reports non-empty default slot', function() {\n expect(element.controller.hasSlotted(null)).to.be.true;\n expect(element.controller.isEmpty(null)).to.be.false;\n });\n it('reports non-empty default slot with no arguments', function() {\n expect(element.controller.hasSlotted()).to.be.true;\n expect(element.controller.isEmpty()).to.be.false;\n });\n it('returns empty list for getSlotted(\"a\")', function() {\n expect(element.controller.getSlotted('a')).to.be.empty;\n });\n it('returns lengthy list for getSlotted(null)', function() {\n expect(element.controller.getSlotted(null)).to.be.empty;\n });\n it('returns lengthy list for getSlotted()', function() {\n expect(element.controller.getSlotted()).to.be.empty;\n });\n });\n });\n});\n"]}