Socket
Socket
Sign inDemoInstall

@patternfly/pfe-core

Package Overview
Dependencies
9
Maintainers
16
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.1 to 2.4.0

controllers/timestamp-controller.d.ts

2

controllers/cascade-controller.js

@@ -6,2 +6,3 @@ import { __decorate } from "tslib";

class CascadeController {
static { this.instances = new WeakMap(); }
constructor(host, options) {

@@ -133,3 +134,2 @@ this.host = host;

}
CascadeController.instances = new WeakMap();
__decorate([

@@ -136,0 +136,0 @@ bound

import type { Placement } from '@floating-ui/dom';
import type { ReactiveController, ReactiveElement } from 'lit';
import type { StyleInfo } from 'lit/directives/style-map.js';
import type { Options as Offset } from '@floating-ui/core/src/middleware/offset';
import type { OffsetOptions as Offset } from '@floating-ui/core';
export type { Placement };

@@ -6,0 +6,0 @@ type Lazy<T> = T | (() => T | null | undefined);

@@ -1,3 +0,1 @@

var _FloatingDOMController_instances, _FloatingDOMController_open, _FloatingDOMController_opening, _FloatingDOMController_cleanup, _FloatingDOMController_anchor, _FloatingDOMController_alignment, _FloatingDOMController_styles, _FloatingDOMController_placement, _FloatingDOMController_options, _FloatingDOMController_invoker_get, _FloatingDOMController_content_get, _FloatingDOMController_arrow_get, _FloatingDOMController_update;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { autoUpdate, computePosition, offset as offsetMiddleware, shift as shiftMiddleware, flip as flipMiddleware, arrow as arrowMiddleware } from '@floating-ui/dom';

@@ -8,9 +6,29 @@ /**

export class FloatingDOMController {
#open = false;
#opening = false;
#cleanup;
#anchor;
#alignment;
#styles;
#placement;
#options;
get #invoker() {
const { invoker } = this.#options;
return typeof invoker === 'function' ? invoker() : invoker;
}
get #content() {
const { content } = this.#options;
return typeof content === 'function' ? content() : content;
}
get #arrow() {
const { arrow } = this.#options;
return typeof arrow === 'function' ? arrow() : arrow;
}
/** The crosswise alignment of the invoker on which to display the floating DOM */
get alignment() {
return __classPrivateFieldGet(this, _FloatingDOMController_alignment, "f") ?? 'center';
return this.#alignment ?? 'center';
}
/** The side of the invoker on which to display the floating DOM */
get anchor() {
return __classPrivateFieldGet(this, _FloatingDOMController_anchor, "f") ?? '';
return this.#anchor ?? '';
}

@@ -21,7 +39,7 @@ /**

get open() {
return __classPrivateFieldGet(this, _FloatingDOMController_open, "f");
return this.#open;
}
/** The computed placement of the floating DOM */
get placement() {
return __classPrivateFieldGet(this, _FloatingDOMController_placement, "f") ?? 'top';
return this.#placement ?? 'top';
}

@@ -34,39 +52,70 @@ /**

get styles() {
return __classPrivateFieldGet(this, _FloatingDOMController_styles, "f") ?? {};
return this.#styles ?? {};
}
constructor(host, options) {
var _a, _b;
_FloatingDOMController_instances.add(this);
this.host = host;
_FloatingDOMController_open.set(this, false);
_FloatingDOMController_opening.set(this, false);
_FloatingDOMController_cleanup.set(this, void 0);
_FloatingDOMController_anchor.set(this, void 0);
_FloatingDOMController_alignment.set(this, void 0);
_FloatingDOMController_styles.set(this, void 0);
_FloatingDOMController_placement.set(this, void 0);
_FloatingDOMController_options.set(this, void 0);
host.addController(this);
__classPrivateFieldSet(this, _FloatingDOMController_options, options, "f");
(_a = __classPrivateFieldGet(this, _FloatingDOMController_options, "f")).invoker ?? (_a.invoker = host);
(_b = __classPrivateFieldGet(this, _FloatingDOMController_options, "f")).shift ?? (_b.shift = true);
this.#options = options;
this.#options.invoker ??= host;
this.#options.shift ??= true;
}
hostDisconnected() {
__classPrivateFieldGet(this, _FloatingDOMController_cleanup, "f")?.call(this);
this.#cleanup?.();
}
async #update(placement = 'top', offset, flip = true, fallbackPlacements) {
const { padding, shift } = this.#options;
const invoker = this.#invoker;
const content = this.#content;
const arrow = this.#arrow;
if (!invoker || !content) {
return;
}
const { x, y, placement: _placement, middlewareData } = await computePosition(invoker, content, {
strategy: 'absolute',
placement,
middleware: [
offsetMiddleware(offset),
shift && shiftMiddleware({ padding }),
arrow && arrowMiddleware({ element: arrow, padding: arrow.offsetHeight / 2 }),
flip && flipMiddleware({ padding, fallbackPlacements }),
].filter(Boolean)
});
if (arrow) {
const { x: arrowX, y: arrowY } = middlewareData.arrow || {};
const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[_placement.split('-')[0]] || '';
Object.assign(arrow.style, {
left: arrowX != null ? `${arrowX}px` : '',
top: arrowY != null && !['top'].includes(_placement) ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: `-${arrow.offsetHeight / 2}px`,
});
}
this.#placement = _placement;
[this.#anchor, this.#alignment] = (this.#placement.split('-') ?? []);
this.#styles = {
'--_floating-content-translate': `${x}px ${y}px`,
};
this.host.requestUpdate();
}
/** Show the floating DOM */
async show({ offset, placement, flip, fallbackPlacements } = {}) {
const invoker = __classPrivateFieldGet(this, _FloatingDOMController_instances, "a", _FloatingDOMController_invoker_get);
const content = __classPrivateFieldGet(this, _FloatingDOMController_instances, "a", _FloatingDOMController_content_get);
const invoker = this.#invoker;
const content = this.#content;
if (!invoker || !content) {
return;
}
if (!__classPrivateFieldGet(this, _FloatingDOMController_opening, "f")) {
__classPrivateFieldSet(this, _FloatingDOMController_opening, true, "f");
const p = __classPrivateFieldGet(this, _FloatingDOMController_instances, "m", _FloatingDOMController_update).call(this, placement, offset, flip, fallbackPlacements);
__classPrivateFieldSet(this, _FloatingDOMController_cleanup, __classPrivateFieldGet(this, _FloatingDOMController_cleanup, "f") ?? autoUpdate(invoker, content, () => __classPrivateFieldGet(this, _FloatingDOMController_instances, "m", _FloatingDOMController_update).call(this, placement, offset, flip, fallbackPlacements)), "f");
if (!this.#opening) {
this.#opening = true;
const p = this.#update(placement, offset, flip, fallbackPlacements);
this.#cleanup ??= autoUpdate(invoker, content, () => this.#update(placement, offset, flip, fallbackPlacements));
await p;
__classPrivateFieldSet(this, _FloatingDOMController_opening, false, "f");
this.#opening = false;
}
__classPrivateFieldSet(this, _FloatingDOMController_open, true, "f");
this.#open = true;
this.host.requestUpdate();

@@ -77,7 +126,7 @@ }

await this.host.updateComplete;
while (__classPrivateFieldGet(this, _FloatingDOMController_opening, "f") && !this.open) {
while (this.#opening && !this.open) {
await new Promise(requestAnimationFrame);
}
__classPrivateFieldSet(this, _FloatingDOMController_open, false, "f");
__classPrivateFieldGet(this, _FloatingDOMController_cleanup, "f")?.call(this);
this.#open = false;
this.#cleanup?.();
this.host.requestUpdate();

@@ -87,53 +136,2 @@ await this.host.updateComplete;

}
_FloatingDOMController_open = new WeakMap(), _FloatingDOMController_opening = new WeakMap(), _FloatingDOMController_cleanup = new WeakMap(), _FloatingDOMController_anchor = new WeakMap(), _FloatingDOMController_alignment = new WeakMap(), _FloatingDOMController_styles = new WeakMap(), _FloatingDOMController_placement = new WeakMap(), _FloatingDOMController_options = new WeakMap(), _FloatingDOMController_instances = new WeakSet(), _FloatingDOMController_invoker_get = function _FloatingDOMController_invoker_get() {
const { invoker } = __classPrivateFieldGet(this, _FloatingDOMController_options, "f");
return typeof invoker === 'function' ? invoker() : invoker;
}, _FloatingDOMController_content_get = function _FloatingDOMController_content_get() {
const { content } = __classPrivateFieldGet(this, _FloatingDOMController_options, "f");
return typeof content === 'function' ? content() : content;
}, _FloatingDOMController_arrow_get = function _FloatingDOMController_arrow_get() {
const { arrow } = __classPrivateFieldGet(this, _FloatingDOMController_options, "f");
return typeof arrow === 'function' ? arrow() : arrow;
}, _FloatingDOMController_update = async function _FloatingDOMController_update(placement = 'top', offset, flip = true, fallbackPlacements) {
var _a, _b;
const { padding, shift } = __classPrivateFieldGet(this, _FloatingDOMController_options, "f");
const invoker = __classPrivateFieldGet(this, _FloatingDOMController_instances, "a", _FloatingDOMController_invoker_get);
const content = __classPrivateFieldGet(this, _FloatingDOMController_instances, "a", _FloatingDOMController_content_get);
const arrow = __classPrivateFieldGet(this, _FloatingDOMController_instances, "a", _FloatingDOMController_arrow_get);
if (!invoker || !content) {
return;
}
const { x, y, placement: _placement, middlewareData } = await computePosition(invoker, content, {
strategy: 'absolute',
placement,
middleware: [
offsetMiddleware(offset),
shift && shiftMiddleware({ padding }),
arrow && arrowMiddleware({ element: arrow, padding: arrow.offsetHeight / 2 }),
flip && flipMiddleware({ padding, fallbackPlacements }),
].filter(Boolean)
});
if (arrow) {
const { x: arrowX, y: arrowY } = middlewareData.arrow || {};
const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[_placement.split('-')[0]] || '';
Object.assign(arrow.style, {
left: arrowX != null ? `${arrowX}px` : '',
top: arrowY != null && !['top'].includes(_placement) ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: `-${arrow.offsetHeight / 2}px`,
});
}
__classPrivateFieldSet(this, _FloatingDOMController_placement, _placement, "f");
_a = this, _b = this, [({ set value(_c) { __classPrivateFieldSet(_a, _FloatingDOMController_anchor, _c, "f"); } }).value, ({ set value(_c) { __classPrivateFieldSet(_b, _FloatingDOMController_alignment, _c, "f"); } }).value] = (__classPrivateFieldGet(this, _FloatingDOMController_placement, "f").split('-') ?? []);
__classPrivateFieldSet(this, _FloatingDOMController_styles, {
'--_floating-content-translate': `${x}px ${y}px`,
}, "f");
this.host.requestUpdate();
};
//# sourceMappingURL=floating-dom-controller.js.map

@@ -1,3 +0,1 @@

var _InternalsController_internals, _InternalsController_formDisabled;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
function isARIAMixinProp(key) {

@@ -7,17 +5,18 @@ return key === 'role' || key.startsWith('aria');

class InternalsController {
#internals;
#formDisabled = false;
/** True when the control is disabled via it's containing fieldset element */
get formDisabled() {
return this.host.matches(':disabled') || __classPrivateFieldGet(this, _InternalsController_formDisabled, "f");
return this.host.matches(':disabled') || this.#formDisabled;
}
static { this.protos = new WeakMap(); }
get labels() {
return __classPrivateFieldGet(this, _InternalsController_internals, "f").labels;
return this.#internals.labels;
}
get validity() {
return __classPrivateFieldGet(this, _InternalsController_internals, "f").validity;
return this.#internals.validity;
}
constructor(host, options) {
this.host = host;
_InternalsController_internals.set(this, void 0);
_InternalsController_formDisabled.set(this, false);
__classPrivateFieldSet(this, _InternalsController_internals, host.attachInternals(), "f");
this.#internals = host.attachInternals();
// We need to polyfill :disabled

@@ -27,14 +26,14 @@ // see https://github.com/calebdwilliams/element-internals-polyfill/issues/88

host.formDisabledCallback = disabled => {
__classPrivateFieldSet(this, _InternalsController_formDisabled, disabled, "f");
this.#formDisabled = disabled;
orig?.call(host, disabled);
};
// proxy the internals object's aria prototype
for (const key of Object.keys(Object.getPrototypeOf(__classPrivateFieldGet(this, _InternalsController_internals, "f")))) {
for (const key of Object.keys(Object.getPrototypeOf(this.#internals))) {
if (isARIAMixinProp(key)) {
Object.defineProperty(this, key, {
get() {
return __classPrivateFieldGet(this, _InternalsController_internals, "f")[key];
return this.#internals[key];
},
set(value) {
__classPrivateFieldGet(this, _InternalsController_internals, "f")[key] = value;
this.#internals[key] = value;
this.host.requestUpdate();

@@ -52,23 +51,21 @@ }

setFormValue(...args) {
return __classPrivateFieldGet(this, _InternalsController_internals, "f").setFormValue(...args);
return this.#internals.setFormValue(...args);
}
setValidity(...args) {
return __classPrivateFieldGet(this, _InternalsController_internals, "f").setValidity(...args);
return this.#internals.setValidity(...args);
}
checkValidity(...args) {
return __classPrivateFieldGet(this, _InternalsController_internals, "f").checkValidity(...args);
return this.#internals.checkValidity(...args);
}
reportValidity(...args) {
return __classPrivateFieldGet(this, _InternalsController_internals, "f").reportValidity(...args);
return this.#internals.reportValidity(...args);
}
submit() {
__classPrivateFieldGet(this, _InternalsController_internals, "f").form?.requestSubmit();
this.#internals.form?.requestSubmit();
}
reset() {
__classPrivateFieldGet(this, _InternalsController_internals, "f").form?.reset();
this.#internals.form?.reset();
}
}
_InternalsController_internals = new WeakMap(), _InternalsController_formDisabled = new WeakMap();
InternalsController.protos = new WeakMap();
export { InternalsController };
//# sourceMappingURL=internals-controller.js.map
class Logger {
static { this.instances = new WeakMap(); }
get prefix() {

@@ -89,4 +90,3 @@ return `[${this.host.localName}${this.host.id ? `#${this.host.id}` : ''}]`;

}
Logger.instances = new WeakMap();
export { Logger };
//# sourceMappingURL=logger.js.map

@@ -1,23 +0,25 @@

var _OverflowController_instances, _OverflowController_container, _OverflowController_items, _OverflowController_scrollTimeoutDelay, _OverflowController_scrollTimeout, _OverflowController_hideOverflowButtons, _OverflowController_setOverflowState;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { isElementInView } from '@patternfly/pfe-core/functions/isElementInView.js';
export class OverflowController {
/** Overflow container */
#container;
/** Children that can overflow */
#items;
#scrollTimeoutDelay;
#scrollTimeout;
/** Default state */
#hideOverflowButtons;
get firstItem() {
return __classPrivateFieldGet(this, _OverflowController_items, "f").at(0);
return this.#items.at(0);
}
get lastItem() {
return __classPrivateFieldGet(this, _OverflowController_items, "f").at(-1);
return this.#items.at(-1);
}
constructor(host, options) {
_OverflowController_instances.add(this);
this.host = host;
this.options = options;
/** Overflow container */
_OverflowController_container.set(this, void 0);
/** Children that can overflow */
_OverflowController_items.set(this, []);
_OverflowController_scrollTimeoutDelay.set(this, 0);
_OverflowController_scrollTimeout.set(this, void 0);
this.#items = [];
this.#scrollTimeoutDelay = 0;
/** Default state */
_OverflowController_hideOverflowButtons.set(this, false);
this.#hideOverflowButtons = false;
this.showScrollButtons = false;

@@ -27,53 +29,53 @@ this.overflowLeft = false;

this.onScroll = () => {
clearTimeout(__classPrivateFieldGet(this, _OverflowController_scrollTimeout, "f"));
__classPrivateFieldSet(this, _OverflowController_scrollTimeout, setTimeout(() => __classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this), __classPrivateFieldGet(this, _OverflowController_scrollTimeoutDelay, "f")), "f");
clearTimeout(this.#scrollTimeout);
this.#scrollTimeout = setTimeout(() => this.#setOverflowState(), this.#scrollTimeoutDelay);
};
this.host.addController(this);
if (options?.hideOverflowButtons) {
__classPrivateFieldSet(this, _OverflowController_hideOverflowButtons, options?.hideOverflowButtons, "f");
this.#hideOverflowButtons = options?.hideOverflowButtons;
}
}
#setOverflowState() {
if (!this.firstItem || !this.lastItem || !this.#container) {
return;
}
this.overflowLeft = !this.#hideOverflowButtons && !isElementInView(this.#container, this.firstItem);
this.overflowRight = !this.#hideOverflowButtons && !isElementInView(this.#container, this.lastItem);
let scrollButtonsWidth = 0;
if (this.overflowLeft || this.overflowRight) {
scrollButtonsWidth = (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0) * 2;
}
this.showScrollButtons = !this.#hideOverflowButtons &&
this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);
this.host.requestUpdate();
}
init(container, items) {
__classPrivateFieldSet(this, _OverflowController_container, container, "f");
this.#container = container;
// convert HTMLCollection to HTMLElement[]
__classPrivateFieldSet(this, _OverflowController_items, items, "f");
this.#items = items;
}
scrollLeft() {
if (!__classPrivateFieldGet(this, _OverflowController_container, "f")) {
if (!this.#container) {
return;
}
const leftScroll = __classPrivateFieldGet(this, _OverflowController_container, "f").scrollLeft - __classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth;
__classPrivateFieldGet(this, _OverflowController_container, "f").scroll({ left: leftScroll, behavior: 'smooth' });
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
const leftScroll = this.#container.scrollLeft - this.#container.clientWidth;
this.#container.scroll({ left: leftScroll, behavior: 'smooth' });
this.#setOverflowState();
}
scrollRight() {
if (!__classPrivateFieldGet(this, _OverflowController_container, "f")) {
if (!this.#container) {
return;
}
const leftScroll = __classPrivateFieldGet(this, _OverflowController_container, "f").scrollLeft + __classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth;
__classPrivateFieldGet(this, _OverflowController_container, "f").scroll({ left: leftScroll, behavior: 'smooth' });
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
const leftScroll = this.#container.scrollLeft + this.#container.clientWidth;
this.#container.scroll({ left: leftScroll, behavior: 'smooth' });
this.#setOverflowState();
}
update() {
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
this.#setOverflowState();
}
hostConnected() {
this.onScroll();
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
this.#setOverflowState();
}
}
_OverflowController_container = new WeakMap(), _OverflowController_items = new WeakMap(), _OverflowController_scrollTimeoutDelay = new WeakMap(), _OverflowController_scrollTimeout = new WeakMap(), _OverflowController_hideOverflowButtons = new WeakMap(), _OverflowController_instances = new WeakSet(), _OverflowController_setOverflowState = function _OverflowController_setOverflowState() {
if (!this.firstItem || !this.lastItem || !__classPrivateFieldGet(this, _OverflowController_container, "f")) {
return;
}
this.overflowLeft = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f") && !isElementInView(__classPrivateFieldGet(this, _OverflowController_container, "f"), this.firstItem);
this.overflowRight = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f") && !isElementInView(__classPrivateFieldGet(this, _OverflowController_container, "f"), this.lastItem);
let scrollButtonsWidth = 0;
if (this.overflowLeft || this.overflowRight) {
scrollButtonsWidth = (__classPrivateFieldGet(this, _OverflowController_container, "f").parentElement?.querySelector('button')?.getBoundingClientRect().width || 0) * 2;
}
this.showScrollButtons = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f") &&
__classPrivateFieldGet(this, _OverflowController_container, "f").scrollWidth > (__classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth + scrollButtonsWidth);
this.host.requestUpdate();
};
//# sourceMappingURL=overflow-controller.js.map
export const observedController = Symbol('observed properties controller');
/** This controller holds a cache of observed property values which were set before the element updated */
class PropertyObserverController {
static { this.hosts = new WeakMap(); }
delete(key) {

@@ -32,4 +33,3 @@ this.values.delete(key);

}
PropertyObserverController.hosts = new WeakMap();
export { PropertyObserverController };
//# sourceMappingURL=property-observer-controller.js.map

@@ -1,3 +0,1 @@

var _RovingTabindexController_instances, _RovingTabindexController_activeItem, _RovingTabindexController_itemsContainer, _RovingTabindexController_items, _RovingTabindexController_focusableItems_get, _RovingTabindexController_activeIndex_get, _RovingTabindexController_itemIndex_get, _RovingTabindexController_onKeydown;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
const isFocusableElement = (el) => !!el &&

@@ -13,7 +11,31 @@ !el.hasAttribute('disabled') &&

export class RovingTabindexController {
/** active focusable element */
#activeItem;
/** closest ancestor containing items */
#itemsContainer;
/** array of all focusable elements */
#items = [];
/**
* finds focusable items from a group of items
*/
get #focusableItems() {
return this.#items.filter(isFocusableElement);
}
/**
* index of active item in array of focusable items
*/
get #activeIndex() {
return !!this.#focusableItems && !!this.activeItem ? this.#focusableItems.indexOf(this.activeItem) : -1;
}
/**
* index of active item in array of items
*/
get #itemIndex() {
return this.activeItem ? this.#items.indexOf(this.activeItem) : -1;
}
/**
* active item of array of items
*/
get activeItem() {
return __classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f");
return this.#activeItem;
}

@@ -24,3 +46,3 @@ /**

get firstItem() {
return __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)[0];
return this.#focusableItems[0];
}

@@ -31,3 +53,3 @@ /**

get lastItem() {
return __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).at(-1);
return this.#focusableItems.at(-1);
}

@@ -38,4 +60,4 @@ /**

get nextItem() {
return (__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) >= __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).length - 1 ? this.firstItem
: __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)[__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) + 1]);
return (this.#activeIndex >= this.#focusableItems.length - 1 ? this.firstItem
: this.#focusableItems[this.#activeIndex + 1]);
}

@@ -46,86 +68,79 @@ /**

get prevItem() {
return (__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) > 0 ? __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)[__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) - 1]
return (this.#activeIndex > 0 ? this.#focusableItems[this.#activeIndex - 1]
: this.lastItem);
}
constructor(host) {
_RovingTabindexController_instances.add(this);
this.host = host;
/** active focusable element */
_RovingTabindexController_activeItem.set(this, void 0);
/** closest ancestor containing items */
_RovingTabindexController_itemsContainer.set(this, void 0);
/** array of all focusable elements */
_RovingTabindexController_items.set(this, []);
/**
* handles keyboard navigation
*/
_RovingTabindexController_onKeydown.set(this, (event) => {
if (event.ctrlKey ||
event.altKey ||
event.metaKey ||
!__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).length ||
!event.composedPath().some(x => __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).includes(x))) {
return;
}
const item = this.activeItem;
let shouldPreventDefault = false;
const horizontalOnly = !item ? false
: item.tagName === 'SELECT' ||
item.getAttribute('role') === 'spinbutton';
switch (event.key) {
case 'ArrowLeft':
this.focusOnItem(this.prevItem);
shouldPreventDefault = true;
break;
case 'ArrowRight':
this.focusOnItem(this.nextItem);
shouldPreventDefault = true;
break;
case 'ArrowUp':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.prevItem);
shouldPreventDefault = true;
break;
case 'ArrowDown':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.nextItem);
shouldPreventDefault = true;
break;
case 'Home':
this.focusOnItem(this.firstItem);
shouldPreventDefault = true;
break;
case 'PageUp':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.firstItem);
shouldPreventDefault = true;
break;
case 'End':
this.focusOnItem(this.lastItem);
shouldPreventDefault = true;
break;
case 'PageDown':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.lastItem);
shouldPreventDefault = true;
break;
default:
break;
}
if (shouldPreventDefault) {
event.stopPropagation();
event.preventDefault();
}
});
this.host.addController(this);
}
/**
* handles keyboard navigation
*/
#onKeydown = (event) => {
if (event.ctrlKey ||
event.altKey ||
event.metaKey ||
!this.#focusableItems.length ||
!event.composedPath().some(x => this.#focusableItems.includes(x))) {
return;
}
const item = this.activeItem;
let shouldPreventDefault = false;
const horizontalOnly = !item ? false
: item.tagName === 'SELECT' ||
item.getAttribute('role') === 'spinbutton';
switch (event.key) {
case 'ArrowLeft':
this.focusOnItem(this.prevItem);
shouldPreventDefault = true;
break;
case 'ArrowRight':
this.focusOnItem(this.nextItem);
shouldPreventDefault = true;
break;
case 'ArrowUp':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.prevItem);
shouldPreventDefault = true;
break;
case 'ArrowDown':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.nextItem);
shouldPreventDefault = true;
break;
case 'Home':
this.focusOnItem(this.firstItem);
shouldPreventDefault = true;
break;
case 'PageUp':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.firstItem);
shouldPreventDefault = true;
break;
case 'End':
this.focusOnItem(this.lastItem);
shouldPreventDefault = true;
break;
case 'PageDown':
if (horizontalOnly) {
return;
}
this.focusOnItem(this.lastItem);
shouldPreventDefault = true;
break;
default:
break;
}
if (shouldPreventDefault) {
event.stopPropagation();
event.preventDefault();
}
};
/**
* sets tabindex of item based on whether or not it is active

@@ -135,7 +150,7 @@ */

if (item) {
if (!!__classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f") && item !== __classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f")) {
__classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f").tabIndex = -1;
if (!!this.#activeItem && item !== this.#activeItem) {
this.#activeItem.tabIndex = -1;
}
item.tabIndex = 0;
__classPrivateFieldSet(this, _RovingTabindexController_activeItem, item, "f");
this.#activeItem = item;
}

@@ -148,3 +163,3 @@ }

this.updateActiveItem(item || this.firstItem);
__classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f")?.focus();
this.#activeItem?.focus();
this.host.requestUpdate();

@@ -156,4 +171,4 @@ }

updateItems(items) {
const sequence = [...items.slice(__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_itemIndex_get)), ...items.slice(0, __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_itemIndex_get))];
const first = sequence.find(item => __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).includes(item));
const sequence = [...items.slice(this.#itemIndex), ...items.slice(0, this.#itemIndex)];
const first = sequence.find(item => this.#focusableItems.includes(item));
this.focusOnItem(first || this.firstItem);

@@ -165,8 +180,8 @@ }

initItems(items, itemsContainer = this.host) {
__classPrivateFieldSet(this, _RovingTabindexController_items, items ?? [], "f");
const focusableItems = __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get);
this.#items = items ?? [];
const focusableItems = this.#focusableItems;
const [focusableItem] = focusableItems;
__classPrivateFieldSet(this, _RovingTabindexController_activeItem, focusableItem, "f");
this.#activeItem = focusableItem;
for (const item of focusableItems) {
item.tabIndex = __classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f") === item ? 0 : -1;
item.tabIndex = this.#activeItem === item ? 0 : -1;
}

@@ -176,5 +191,5 @@ /**

*/
if (!__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f") || itemsContainer !== __classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f")) {
__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f")?.removeEventListener('keydown', __classPrivateFieldGet(this, _RovingTabindexController_onKeydown, "f"));
__classPrivateFieldSet(this, _RovingTabindexController_itemsContainer, itemsContainer, "f");
if (!this.#itemsContainer || itemsContainer !== this.#itemsContainer) {
this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);
this.#itemsContainer = itemsContainer;
this.hostConnected();

@@ -187,3 +202,3 @@ }

hostConnected() {
__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f")?.addEventListener('keydown', __classPrivateFieldGet(this, _RovingTabindexController_onKeydown, "f"));
this.#itemsContainer?.addEventListener('keydown', this.#onKeydown);
}

@@ -194,12 +209,5 @@ /**

hostDisconnected() {
__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f")?.removeEventListener('keydown', __classPrivateFieldGet(this, _RovingTabindexController_onKeydown, "f"));
this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);
}
}
_RovingTabindexController_activeItem = new WeakMap(), _RovingTabindexController_itemsContainer = new WeakMap(), _RovingTabindexController_items = new WeakMap(), _RovingTabindexController_onKeydown = new WeakMap(), _RovingTabindexController_instances = new WeakSet(), _RovingTabindexController_focusableItems_get = function _RovingTabindexController_focusableItems_get() {
return __classPrivateFieldGet(this, _RovingTabindexController_items, "f").filter(isFocusableElement);
}, _RovingTabindexController_activeIndex_get = function _RovingTabindexController_activeIndex_get() {
return !!__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get) && !!this.activeItem ? __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).indexOf(this.activeItem) : -1;
}, _RovingTabindexController_itemIndex_get = function _RovingTabindexController_itemIndex_get() {
return this.activeItem ? __classPrivateFieldGet(this, _RovingTabindexController_items, "f").indexOf(this.activeItem) : -1;
};
//# sourceMappingURL=roving-tabindex-controller.js.map

@@ -1,64 +0,114 @@

var _ScrollSpyController_instances, _ScrollSpyController_tagNames, _ScrollSpyController_activeAttribute, _ScrollSpyController_io, _ScrollSpyController_passedLinks, _ScrollSpyController_force, _ScrollSpyController_intersected, _ScrollSpyController_root, _ScrollSpyController_rootMargin, _ScrollSpyController_threshold, _ScrollSpyController_rootNode, _ScrollSpyController_getHash, _ScrollSpyController_linkChildren_get, _ScrollSpyController_initIo, _ScrollSpyController_markPassed, _ScrollSpyController_setActive, _ScrollSpyController_nextIntersection, _ScrollSpyController_onIo;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
export class ScrollSpyController {
#tagNames;
#activeAttribute;
#io;
/** Which link's targets have already scrolled past? */
#passedLinks = new Set();
/** Ignore intersections? */
#force = false;
/** Has the intersection observer found an element? */
#intersected = false;
#root;
#rootMargin;
#threshold;
#rootNode;
#getHash;
get #linkChildren() {
return Array.from(this.host.querySelectorAll(this.#tagNames.join(',')))
.filter(this.#getHash);
}
get root() {
return __classPrivateFieldGet(this, _ScrollSpyController_root, "f");
return this.#root;
}
set root(v) {
__classPrivateFieldSet(this, _ScrollSpyController_root, v, "f");
__classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
this.#root = v;
this.#io?.disconnect();
this.#initIo();
}
get rootMargin() {
return __classPrivateFieldGet(this, _ScrollSpyController_rootMargin, "f");
return this.#rootMargin;
}
set rootMargin(v) {
__classPrivateFieldSet(this, _ScrollSpyController_rootMargin, v, "f");
__classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
this.#rootMargin = v;
this.#io?.disconnect();
this.#initIo();
}
get threshold() {
return __classPrivateFieldGet(this, _ScrollSpyController_threshold, "f");
return this.#threshold;
}
set threshold(v) {
__classPrivateFieldSet(this, _ScrollSpyController_threshold, v, "f");
__classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
this.#threshold = v;
this.#io?.disconnect();
this.#initIo();
}
constructor(host, options) {
_ScrollSpyController_instances.add(this);
this.host = host;
_ScrollSpyController_tagNames.set(this, void 0);
_ScrollSpyController_activeAttribute.set(this, void 0);
_ScrollSpyController_io.set(this, void 0);
/** Which link's targets have already scrolled past? */
_ScrollSpyController_passedLinks.set(this, new Set());
/** Ignore intersections? */
_ScrollSpyController_force.set(this, false);
/** Has the intersection observer found an element? */
_ScrollSpyController_intersected.set(this, false);
_ScrollSpyController_root.set(this, void 0);
_ScrollSpyController_rootMargin.set(this, void 0);
_ScrollSpyController_threshold.set(this, void 0);
_ScrollSpyController_rootNode.set(this, void 0);
_ScrollSpyController_getHash.set(this, void 0);
host.addController(this);
__classPrivateFieldSet(this, _ScrollSpyController_tagNames, options.tagNames, "f");
__classPrivateFieldSet(this, _ScrollSpyController_root, options.root, "f");
__classPrivateFieldSet(this, _ScrollSpyController_rootMargin, options.rootMargin, "f");
__classPrivateFieldSet(this, _ScrollSpyController_activeAttribute, options.activeAttribute ?? 'active', "f");
__classPrivateFieldSet(this, _ScrollSpyController_threshold, options.threshold ?? 0.85, "f");
__classPrivateFieldSet(this, _ScrollSpyController_rootNode, options.rootNode ?? host.getRootNode(), "f");
__classPrivateFieldSet(this, _ScrollSpyController_getHash, options?.getHash ?? ((el) => el.getAttribute('href')), "f");
this.#tagNames = options.tagNames;
this.#root = options.root;
this.#rootMargin = options.rootMargin;
this.#activeAttribute = options.activeAttribute ?? 'active';
this.#threshold = options.threshold ?? 0.85;
this.#rootNode = options.rootNode ?? host.getRootNode();
this.#getHash = options?.getHash ?? ((el) => el.getAttribute('href'));
}
hostConnected() {
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
this.#initIo();
}
#initIo() {
const rootNode = this.#rootNode;
if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {
const { rootMargin, threshold, root } = this;
this.#io = new IntersectionObserver(r => this.#onIo(r), { root, rootMargin, threshold });
this.#linkChildren
.map(x => this.#getHash(x))
.filter((x) => !!x)
.map(x => rootNode.getElementById(x.replace('#', '')))
.filter((x) => !!x)
.forEach(target => this.#io?.observe(target));
}
}
#markPassed(link, force) {
if (force) {
this.#passedLinks.add(link);
}
else {
this.#passedLinks.delete(link);
}
}
#setActive(link) {
for (const child of this.#linkChildren) {
child.toggleAttribute(this.#activeAttribute, child === link);
}
}
async #nextIntersection() {
this.#intersected = false;
// safeguard the loop
setTimeout(() => this.#intersected = false, 3000);
while (!this.#intersected) {
await new Promise(requestAnimationFrame);
}
}
async #onIo(entries) {
if (!this.#force) {
for (const { target, boundingClientRect, intersectionRect } of entries) {
const selector = `:is(${this.#tagNames.join(',')})[href="#${target.id}"]`;
const link = this.host.querySelector(selector);
if (link) {
this.#markPassed(link, boundingClientRect.top < intersectionRect.top);
}
}
const link = [...this.#passedLinks];
const last = link.at(-1);
this.#setActive(last ?? this.#linkChildren.at(0));
}
this.#intersected = true;
}
/** Explicitly set the active item */
async setActive(link) {
__classPrivateFieldSet(this, _ScrollSpyController_force, true, "f");
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_setActive).call(this, link);
this.#force = true;
this.#setActive(link);
let sawActive = false;
for (const child of __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)) {
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_markPassed).call(this, child, !sawActive);
for (const child of this.#linkChildren) {
this.#markPassed(child, !sawActive);
if (child === link) {

@@ -68,54 +118,6 @@ sawActive = true;

}
await __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_nextIntersection).call(this);
__classPrivateFieldSet(this, _ScrollSpyController_force, false, "f");
await this.#nextIntersection();
this.#force = false;
}
}
_ScrollSpyController_tagNames = new WeakMap(), _ScrollSpyController_activeAttribute = new WeakMap(), _ScrollSpyController_io = new WeakMap(), _ScrollSpyController_passedLinks = new WeakMap(), _ScrollSpyController_force = new WeakMap(), _ScrollSpyController_intersected = new WeakMap(), _ScrollSpyController_root = new WeakMap(), _ScrollSpyController_rootMargin = new WeakMap(), _ScrollSpyController_threshold = new WeakMap(), _ScrollSpyController_rootNode = new WeakMap(), _ScrollSpyController_getHash = new WeakMap(), _ScrollSpyController_instances = new WeakSet(), _ScrollSpyController_linkChildren_get = function _ScrollSpyController_linkChildren_get() {
return Array.from(this.host.querySelectorAll(__classPrivateFieldGet(this, _ScrollSpyController_tagNames, "f").join(',')))
.filter(__classPrivateFieldGet(this, _ScrollSpyController_getHash, "f"));
}, _ScrollSpyController_initIo = function _ScrollSpyController_initIo() {
const rootNode = __classPrivateFieldGet(this, _ScrollSpyController_rootNode, "f");
if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {
const { rootMargin, threshold, root } = this;
__classPrivateFieldSet(this, _ScrollSpyController_io, new IntersectionObserver(r => __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_onIo).call(this, r), { root, rootMargin, threshold }), "f");
__classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)
.map(x => __classPrivateFieldGet(this, _ScrollSpyController_getHash, "f").call(this, x))
.filter((x) => !!x)
.map(x => rootNode.getElementById(x.replace('#', '')))
.filter((x) => !!x)
.forEach(target => __classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.observe(target));
}
}, _ScrollSpyController_markPassed = function _ScrollSpyController_markPassed(link, force) {
if (force) {
__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f").add(link);
}
else {
__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f").delete(link);
}
}, _ScrollSpyController_setActive = function _ScrollSpyController_setActive(link) {
for (const child of __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)) {
child.toggleAttribute(__classPrivateFieldGet(this, _ScrollSpyController_activeAttribute, "f"), child === link);
}
}, _ScrollSpyController_nextIntersection = async function _ScrollSpyController_nextIntersection() {
__classPrivateFieldSet(this, _ScrollSpyController_intersected, false, "f");
// safeguard the loop
setTimeout(() => __classPrivateFieldSet(this, _ScrollSpyController_intersected, false, "f"), 3000);
while (!__classPrivateFieldGet(this, _ScrollSpyController_intersected, "f")) {
await new Promise(requestAnimationFrame);
}
}, _ScrollSpyController_onIo = async function _ScrollSpyController_onIo(entries) {
if (!__classPrivateFieldGet(this, _ScrollSpyController_force, "f")) {
for (const { target, boundingClientRect, intersectionRect } of entries) {
const selector = `:is(${__classPrivateFieldGet(this, _ScrollSpyController_tagNames, "f").join(',')})[href="#${target.id}"]`;
const link = this.host.querySelector(selector);
if (link) {
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_markPassed).call(this, link, boundingClientRect.top < intersectionRect.top);
}
}
const link = [...__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f")];
const last = link.at(-1);
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_setActive).call(this, last ?? __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get).at(0));
}
__classPrivateFieldSet(this, _ScrollSpyController_intersected, true, "f");
};
//# sourceMappingURL=scroll-spy-controller.js.map

@@ -14,2 +14,3 @@ import { __decorate } from "tslib";

class SlotController {
static { this.anonymous = Symbol('anonymous slot'); }
constructor(host, ...config) {

@@ -136,3 +137,2 @@ this.host = host;

}
SlotController.anonymous = Symbol('anonymous slot');
__decorate([

@@ -139,0 +139,0 @@ bound

{
"name": "@patternfly/pfe-core",
"version": "2.3.1",
"version": "2.4.0",
"license": "MIT",

@@ -31,2 +31,3 @@ "description": "PatternFly Elements Core Library",

"./controllers/style-controller.js": "./controllers/style-controller.js",
"./controllers/timestamp-controller.js": "./controllers/timestamp-controller.js",
"./decorators/bound.js": "./decorators/bound.js",

@@ -33,0 +34,0 @@ "./decorators/cascades.js": "./decorators/cascades.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc