@patternfly/pfe-core 4.0.5 → 5.0.0
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.
- package/controllers/light-dom-controller.d.ts +1 -1
- package/controllers/light-dom-controller.js +8 -2
- package/controllers/light-dom-controller.js.map +1 -1
- package/controllers/scroll-spy-controller.d.ts +6 -1
- package/controllers/scroll-spy-controller.js +80 -12
- package/controllers/scroll-spy-controller.js.map +1 -1
- package/controllers/slot-controller-server.d.ts +16 -0
- package/controllers/slot-controller-server.js +32 -0
- package/controllers/slot-controller-server.js.map +1 -0
- package/controllers/slot-controller.d.ts +47 -4
- package/controllers/slot-controller.js +50 -74
- package/controllers/slot-controller.js.map +1 -1
- package/custom-elements.json +467 -130
- package/functions/context.js +5 -0
- package/functions/context.js.map +1 -1
- package/package.json +8 -4
- package/ssr-shims.d.ts +1 -17
- package/ssr-shims.js +23 -27
- package/ssr-shims.js.map +1 -1
|
@@ -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,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,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,uBAAA,IAAI,6BAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,KAAK,CAAC,CAAC;QACtE,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"]}
|
|
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,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;AAmDzC,MAAM,OAAO,cAAc;IAgBzB,YAAmB,IAAqB,EAAE,GAAG,IAAwB;;QAAlD,SAAI,GAAJ,IAAI,CAAiB;QAVxC,gCAAS,IAAI,GAAG,EAAgD,EAAC;QAEjE,6CAAsB,KAAK,EAAC;QAE5B,oCAAgC,EAAE,EAAC;QAEnC,uCAAwC,EAAE,EAAC;QAE3C,6BAAM,IAAI,gBAAgB,CAAC,uBAAA,IAAI,8DAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAC;QAGvD,uBAAA,IAAI,6DAAY,MAAhB,IAAI,EAAa,GAAG,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,uBAAA,IAAI,iCAAW,CAAC,MAAM,EAAE,CAAC;YAC5B,uBAAA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C,CAAC;AACH,CAAC;AArFa,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\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 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\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 #nodes = new Map<string | typeof SlotController.default, Slot>();\n\n #slotMapInitialized = false;\n\n #slotNames: (string | null)[] = [];\n\n #deprecations: Record<string, string> = {};\n\n #mo = new MutationObserver(this.#initSlotMap.bind(this));\n\n constructor(public host: ReactiveElement, ...args: SlotControllerArgs) {\n this.#initialize(...args);\n host.addController(this);\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 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.#nodes.clear();\n this.#initSlotMap();\n // insurance for framework integrations\n await this.host.updateComplete;\n this.host.requestUpdate();\n }\n\n hostUpdated(): void {\n if (!this.#slotMapInitialized) {\n this.#initSlotMap();\n }\n }\n\n hostDisconnected(): void {\n this.#mo.disconnect();\n }\n\n #initSlotMap() {\n // Loop over the properties provided by the schema\n for (const slotName of this.#slotNames\n .concat(Object.values(this.#deprecations))) {\n const slotId = slotName || SlotController.default;\n const name = slotName ?? '';\n const elements = this.#getChildrenForSlot(slotId);\n const slot = this.#getSlotElement(slotId);\n const hasContent =\n !!elements.length || !!slot?.assignedNodes?.()?.filter(x => x.textContent?.trim()).length;\n this.#nodes.set(slotId, { elements, name, hasContent, slot });\n }\n this.host.requestUpdate();\n this.#slotMapInitialized = true;\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 #getChildrenForSlot<T extends Element = Element>(\n name: string | typeof SlotController.default,\n ): T[] {\n if (this.#nodes.has(name)) {\n return (this.#nodes.get(name)!.slot?.assignedElements?.() ?? []) as T[];\n } else {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\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 * @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"]}
|