@patternfly/pfe-core 4.0.1 → 4.0.2

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.
@@ -30,7 +30,9 @@ export class OverflowController {
30
30
  }
31
31
  }));
32
32
  _OverflowController_ro.set(this, new ResizeObserver(() => {
33
- __classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
33
+ requestAnimationFrame(() => {
34
+ __classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
35
+ });
34
36
  }));
35
37
  this.showScrollButtons = false;
36
38
  this.overflowLeft = false;
@@ -1 +1 @@
1
- {"version":3,"file":"overflow-controller.js","sourceRoot":"","sources":["overflow-controller.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AAapF,MAAM,OAAO,kBAAkB;IAuC7B,IAAI,SAAS;QACX,OAAO,uBAAA,IAAI,iCAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,iCAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED;IACE,kDAAkD;IAC3C,IAAqB,EACpB,OAA6B;;QAD9B,SAAI,GAAJ,IAAI,CAAiB;QACpB,YAAO,GAAP,OAAO,CAAsB;QAtCvC,yBAAyB;QACzB,gDAAyB;QACzB,iCAAiC;QACjC,oCAAwB,EAAE,EAAC;QAE3B,yDAA4B;QAC5B,oDAA+C;QAE/C,oBAAoB;QACpB,0DAA8B;QAE9B,iCAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE;YACrC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;oBAClC,uBAAA,IAAI,2EAAkB,MAAtB,IAAI,CAAoB,CAAC;gBAC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EAAE,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC,GAAA,CAAA","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { isElementInView } from '@patternfly/pfe-core/functions/isElementInView.js';\n\nexport interface Options {\n /**\n * Force hide the scroll buttons regardless of overflow\n */\n hideOverflowButtons?: boolean;\n /**\n * Delay in ms to wait before checking for overflow\n */\n scrollTimeoutDelay?: number;\n}\n\nexport class OverflowController implements ReactiveController {\n static #instances = new Set<OverflowController>();\n\n static {\n // on resize check for overflows to add or remove scroll buttons\n globalThis.addEventListener?.('resize', () => {\n for (const instance of this.#instances) {\n instance.onScroll();\n }\n }, { capture: false, passive: true });\n }\n\n /** Overflow container */\n #container?: HTMLElement;\n /** Children that can overflow */\n #items: HTMLElement[] = [];\n\n #scrollTimeoutDelay: number;\n #scrollTimeout?: ReturnType<typeof setTimeout>;\n\n /** Default state */\n #hideOverflowButtons: boolean;\n\n #mo = new MutationObserver(mutations => {\n for (const mutation of mutations) {\n if (mutation.type === 'childList') {\n this.#setOverflowState();\n }\n }\n });\n\n #ro = new ResizeObserver(() => {\n this.#setOverflowState();\n });\n\n showScrollButtons = false;\n overflowLeft = false;\n overflowRight = false;\n\n get firstItem(): HTMLElement | undefined {\n return this.#items.at(0);\n }\n\n get lastItem(): HTMLElement | undefined {\n return this.#items.at(-1);\n }\n\n constructor(\n // TODO: widen this type to ReactiveControllerHost\n public host: ReactiveElement,\n private options?: Options | undefined,\n ) {\n this.#hideOverflowButtons = options?.hideOverflowButtons ?? false;\n this.#scrollTimeoutDelay = options?.scrollTimeoutDelay ?? 0;\n if (host.isConnected) {\n OverflowController.#instances.add(this);\n }\n host.addController(this);\n if (host.isConnected) {\n this.hostConnected();\n }\n }\n\n #setOverflowState(): void {\n if (!this.firstItem || !this.lastItem || !this.#container) {\n return;\n }\n const prevLeft = this.overflowLeft;\n const prevRight = this.overflowRight;\n\n this.overflowLeft = !this.#hideOverflowButtons\n && !isElementInView(this.#container, this.firstItem);\n this.overflowRight = !this.#hideOverflowButtons\n && !isElementInView(this.#container, this.lastItem);\n let scrollButtonsWidth = 0;\n if (this.overflowLeft || this.overflowRight) {\n scrollButtonsWidth =\n (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0)\n * 2;\n }\n this.showScrollButtons = !this.#hideOverflowButtons\n && this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);\n\n // only request update if there has been a change\n if ((prevLeft !== this.overflowLeft) || (prevRight !== this.overflowRight)) {\n this.host.requestUpdate();\n }\n }\n\n init(container: HTMLElement, items: HTMLElement[]): void {\n this.#container = container;\n // convert HTMLCollection to HTMLElement[]\n this.#items = items;\n }\n\n onScroll = (): void => {\n clearTimeout(this.#scrollTimeout);\n this.#scrollTimeout = setTimeout(() => this.#setOverflowState(), this.#scrollTimeoutDelay);\n };\n\n scrollLeft(): void {\n if (!this.#container) {\n return;\n }\n const leftScroll = this.#container.scrollLeft - this.#container.clientWidth;\n this.#container.scroll({ left: leftScroll, behavior: 'smooth' });\n this.#setOverflowState();\n }\n\n scrollRight(): void {\n if (!this.#container) {\n return;\n }\n const leftScroll = this.#container.scrollLeft + this.#container.clientWidth;\n this.#container.scroll({ left: leftScroll, behavior: 'smooth' });\n this.#setOverflowState();\n }\n\n update(): void {\n this.#setOverflowState();\n }\n\n hostConnected(): void {\n this.#mo.observe(this.host, { attributes: false, childList: true, subtree: true });\n this.#ro.observe(this.host);\n this.onScroll();\n this.#setOverflowState();\n }\n}\n"]}
1
+ {"version":3,"file":"overflow-controller.js","sourceRoot":"","sources":["overflow-controller.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AAapF,MAAM,OAAO,kBAAkB;IAyC7B,IAAI,SAAS;QACX,OAAO,uBAAA,IAAI,iCAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,iCAAO,CAAC,E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,WAAW,GAAG,CAAC,uBAAA,IAAI,qCAAW,CAAC,WAAW,GAAG,kBAAkB,CAAC,CAAC;IAEpF,iDAAiD;IACjD,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3E,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAxFM,2CAAa,IAAI,GAAG,EAAsB,EAAhC,CAAiC;AAElD;IACE,gEAAgE;IAChE,UAAU,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QAC3C,KAAK,MAAM,QAAQ,IAAI,oEAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtB,CAAC;IACH,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC,GAAA,CAAA","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { isElementInView } from '@patternfly/pfe-core/functions/isElementInView.js';\n\nexport interface Options {\n /**\n * Force hide the scroll buttons regardless of overflow\n */\n hideOverflowButtons?: boolean;\n /**\n * Delay in ms to wait before checking for overflow\n */\n scrollTimeoutDelay?: number;\n}\n\nexport class OverflowController implements ReactiveController {\n static #instances = new Set<OverflowController>();\n\n static {\n // on resize check for overflows to add or remove scroll buttons\n globalThis.addEventListener?.('resize', () => {\n for (const instance of this.#instances) {\n instance.onScroll();\n }\n }, { capture: false, passive: true });\n }\n\n /** Overflow container */\n #container?: HTMLElement;\n /** Children that can overflow */\n #items: HTMLElement[] = [];\n\n #scrollTimeoutDelay: number;\n #scrollTimeout?: ReturnType<typeof setTimeout>;\n\n /** Default state */\n #hideOverflowButtons: boolean;\n\n #mo = new MutationObserver(mutations => {\n for (const mutation of mutations) {\n if (mutation.type === 'childList') {\n this.#setOverflowState();\n }\n }\n });\n\n #ro = new ResizeObserver(() => {\n requestAnimationFrame(() => {\n this.#setOverflowState();\n });\n });\n\n showScrollButtons = false;\n overflowLeft = false;\n overflowRight = false;\n\n get firstItem(): HTMLElement | undefined {\n return this.#items.at(0);\n }\n\n get lastItem(): HTMLElement | undefined {\n return this.#items.at(-1);\n }\n\n constructor(\n // TODO: widen this type to ReactiveControllerHost\n public host: ReactiveElement,\n private options?: Options | undefined,\n ) {\n this.#hideOverflowButtons = options?.hideOverflowButtons ?? false;\n this.#scrollTimeoutDelay = options?.scrollTimeoutDelay ?? 0;\n if (host.isConnected) {\n OverflowController.#instances.add(this);\n }\n host.addController(this);\n if (host.isConnected) {\n this.hostConnected();\n }\n }\n\n #setOverflowState(): void {\n if (!this.firstItem || !this.lastItem || !this.#container) {\n return;\n }\n const prevLeft = this.overflowLeft;\n const prevRight = this.overflowRight;\n\n this.overflowLeft = !this.#hideOverflowButtons\n && !isElementInView(this.#container, this.firstItem);\n this.overflowRight = !this.#hideOverflowButtons\n && !isElementInView(this.#container, this.lastItem);\n let scrollButtonsWidth = 0;\n if (this.overflowLeft || this.overflowRight) {\n scrollButtonsWidth =\n (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0)\n * 2;\n }\n this.showScrollButtons = !this.#hideOverflowButtons\n && this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);\n\n // only request update if there has been a change\n if ((prevLeft !== this.overflowLeft) || (prevRight !== this.overflowRight)) {\n this.host.requestUpdate();\n }\n }\n\n init(container: HTMLElement, items: HTMLElement[]): void {\n this.#container = container;\n // convert HTMLCollection to HTMLElement[]\n this.#items = items;\n }\n\n onScroll = (): void => {\n clearTimeout(this.#scrollTimeout);\n this.#scrollTimeout = setTimeout(() => this.#setOverflowState(), this.#scrollTimeoutDelay);\n };\n\n scrollLeft(): void {\n if (!this.#container) {\n return;\n }\n const leftScroll = this.#container.scrollLeft - this.#container.clientWidth;\n this.#container.scroll({ left: leftScroll, behavior: 'smooth' });\n this.#setOverflowState();\n }\n\n scrollRight(): void {\n if (!this.#container) {\n return;\n }\n const leftScroll = this.#container.scrollLeft + this.#container.clientWidth;\n this.#container.scroll({ left: leftScroll, behavior: 'smooth' });\n this.#setOverflowState();\n }\n\n update(): void {\n this.#setOverflowState();\n }\n\n hostConnected(): void {\n this.#mo.observe(this.host, { attributes: false, childList: true, subtree: true });\n this.#ro.observe(this.host);\n this.onScroll();\n this.#setOverflowState();\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/pfe-core",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "license": "MIT",
5
5
  "description": "PatternFly Elements Core Library",
6
6
  "customElements": "custom-elements.json",