@muraldevkit/ui-toolkit 4.77.1 → 4.77.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/hooks/useTriggerPosition/index.tsx"],"sourcesContent":["import { useMemo, useState, RefObject, useEffect, useCallback, useLayoutEffect } from 'react';\nimport { Alignment, Position } from './constants';\nimport { getPosition } from './utilities';\nimport debounce from 'lodash.debounce';\n\n/**\n * useTriggerPosition hook.\n *\n * Calculates the position of a menu element based on the alignment settings relative to a trigger element.\n *\n * @param triggerRef - Reference to the DOM element that triggers the menu.\n * @param elementRef - Reference to the DOM element that is the menu.\n * @param menuAlign - The alignment configuration of the menu.\n * @param isElementVisible - Tells the hook if the element is visible. If false, the hook will not calculate the position.\n * @param menuOffset - The offset of the menu from the trigger element.\n * @param disable - Whether to disable the hook.\n * @param disableFlipping - Whether to disable flipping logic when the menu overflows the screen.\n * @returns {Position} The calculated position of the menu element.\n */\nexport const useTriggerPosition = (\n\ttriggerRef: RefObject<HTMLElement> | undefined,\n\telementRef: RefObject<HTMLElement>,\n\tmenuAlign: Alignment,\n\tisElementVisible: boolean = true,\n\tmenuOffset: number = 10,\n\tdisable = false,\n\tdisableFlipping = false\n): Position => {\n\tconst offset = menuOffset;\n\n\t// Holds the current calculated position of the menu\n\tconst [menuPosition, setMenuPosition] = useState<Position>({ flipped: false, left: 0, top: 0 });\n\n\t// Memoize alignment so it only recalculates when specific props change\n\tconst alignment = useMemo(\n\t\t() => ({\n\t\t\talign: menuAlign.align,\n\t\t\tcustomPosition: menuAlign.customPosition,\n\t\t\tposition: menuAlign.position\n\t\t}),\n\t\t[menuAlign.align, menuAlign.position, menuAlign.customPosition]\n\t);\n\n\t/**\n\t * Calculates and updates the menu position relative to the trigger.\n\t * Uses requestAnimationFrame to ensure layout is stable before measuring.\n\t */\n\tconst updatePosition = useCallback(() => {\n\t\tif (!elementRef.current || !isElementVisible) return;\n\n\t\trequestAnimationFrame(() => {\n\t\t\tconst triggerRect = triggerRef?.current?.getBoundingClientRect();\n\t\t\tconst elementRect = elementRef.current?.getBoundingClientRect();\n\n\t\t\t// Don't update if the element is not visible/rendered\n\t\t\tif (!elementRect || elementRect.height === 0 || elementRect.width === 0) return;\n\n\t\t\tconst newPosition = getPosition(alignment, offset, elementRect, triggerRect, disableFlipping);\n\n\t\t\t// Only update state if the position has changed\n\t\t\tsetMenuPosition((prevPosition) => {\n\t\t\t\tif (prevPosition.left !== newPosition.left || prevPosition.top !== newPosition.top) {\n\t\t\t\t\treturn newPosition;\n\t\t\t\t}\n\t\t\t\treturn prevPosition;\n\t\t\t});\n\t\t});\n\t}, [alignment, elementRef, isElementVisible, offset, triggerRef, disableFlipping]);\n\n\t/**\n\t * Debounced version of the updatePosition function used for scroll and resize events.\n\t * 5ms debounce gives a balance between performance and responsiveness.\n\t */\n\tconst debouncedUpdatePosition = useMemo(() => debounce(updatePosition, 5), [updatePosition]);\n\n\tuseEffect(() => {\n\t\tif (disable) return;\n\n\t\tconst currentElement = elementRef.current;\n\n\t\t/**\n\t\t * We need to debounce the resize observer to prevent \"resize loops\"\n\t\t * There are instances where the ResizeObserver will trigger a resize event\n\t\t * before the browser has painted, which causes a loop of resize events\n\t\t * and can throw errors or performance issues.\n\t\t *\n\t\t * The observers are purposefully using a different debounce than the event listeners.\n\t\t * Observers need to be more aggressively debounced to prevent loops,\n\t\t * while event listeners (resize/scroll) should update positioning more responsively.\n\t\t */\n\t\tconst resizeObserver = new ResizeObserver(debounce(updatePosition));\n\t\tconst mutationObserver = new MutationObserver(debounce(updatePosition));\n\n\t\t// Observe changes in size and style/className\n\t\tif (currentElement) {\n\t\t\tresizeObserver.observe(currentElement);\n\t\t\tmutationObserver.observe(currentElement, {\n\t\t\t\tattributeFilter: ['style', 'class'],\n\t\t\t\tattributes: true\n\t\t\t});\n\t\t}\n\n\t\t// Add listeners on open to respond to browser resizing and scrolling\n\t\tif (isElementVisible) {\n\t\t\tupdatePosition();\n\t\t\twindow.addEventListener('resize', debouncedUpdatePosition);\n\t\t\twindow.addEventListener('scroll', debouncedUpdatePosition);\n\t\t}\n\n\t\t// Cleanup observers and listeners on unmount or re-render\n\t\treturn () => {\n\t\t\tif (currentElement) {\n\t\t\t\tresizeObserver.unobserve(currentElement);\n\t\t\t\tmutationObserver.disconnect();\n\t\t\t}\n\t\t\twindow.removeEventListener('resize', debouncedUpdatePosition);\n\t\t\twindow.removeEventListener('scroll', debouncedUpdatePosition);\n\t\t};\n\t}, [\n\t\tdisable,\n\t\ttriggerRef,\n\t\telementRef,\n\t\talignment,\n\t\toffset,\n\t\tisElementVisible,\n\t\tupdatePosition,\n\t\tdebouncedUpdatePosition\n\t]);\n\n\t/**\n\t * This effect handles an edge case where the menu is rendered,\n\t * but its size is not immediately available in the first frame.\n\t * A short timeout ensures we recalculate the position once layout stabilizes.\n\t */\n\tuseEffect(() => {\n\t\tif (!disable && isElementVisible) {\n\t\t\tconst timeoutId = setTimeout(updatePosition, 10);\n\n\t\t\treturn () => clearTimeout(timeoutId);\n\t\t}\n\t}, [isElementVisible, disable, updatePosition]);\n\n\t/**\n\t * useLayoutEffect ensures the position is recalculated during the layout phase,\n\t * just after DOM mutations but before the browser paints.\n\t */\n\tuseLayoutEffect(() => {\n\t\tif (!disable && isElementVisible && elementRef.current && triggerRef?.current) {\n\t\t\tupdatePosition();\n\t\t\trequestAnimationFrame(updatePosition);\n\t\t}\n\t}, [isElementVisible, updatePosition, disable, elementRef, triggerRef]);\n\n\treturn menuPosition;\n};\n"],"names":["useTriggerPosition","triggerRef","elementRef","menuAlign","isElementVisible","arguments","length","undefined","menuOffset","disable","disableFlipping","offset","_useState","useState","flipped","left","top","_useState2","_slicedToArray","menuPosition","setMenuPosition","alignment","useMemo","align","customPosition","position","updatePosition","useCallback","current","requestAnimationFrame","_triggerRef$current","_elementRef$current","triggerRect","getBoundingClientRect","elementRect","height","width","newPosition","getPosition","prevPosition","debouncedUpdatePosition","debounce","useEffect","currentElement","resizeObserver","ResizeObserver","mutationObserver","MutationObserver","observe","attributeFilter","attributes","window","addEventListener","unobserve","disconnect","removeEventListener","timeoutId","setTimeout","clearTimeout","useLayoutEffect"],"mappings":";;;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAkBA,CAC9BC,UAA8C,EAC9CC,UAAkC,EAClCC,SAAoB,EAKN;AAAA,EAAA,IAJdC,gBAAyB,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,IAAI;AAAA,EAAA,IAChCG,UAAkB,GAAAH,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE;AAAA,EAAA,IACvBI,OAAO,GAAAJ,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,KAAK;AAAA,EAAA,IACfK,eAAe,GAAAL,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,KAAK;EAEvB,IAAMM,MAAM,GAAGH,UAAU;;AAEzB;EACA,IAAAI,SAAA,GAAwCC,QAAQ,CAAW;AAAEC,MAAAA,OAAO,EAAE,KAAK;AAAEC,MAAAA,IAAI,EAAE,CAAC;AAAEC,MAAAA,GAAG,EAAE;AAAE,KAAC,CAAC;IAAAC,UAAA,GAAAC,cAAA,CAAAN,SAAA,EAAA,CAAA,CAAA;AAAxFO,IAAAA,YAAY,GAAAF,UAAA,CAAA,CAAA,CAAA;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;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/hooks/useTriggerPosition/index.tsx"],"sourcesContent":["import {\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tRefObject,\n\tuseEffect,\n\tuseCallback,\n\tuseLayoutEffect\n} from 'react';\nimport { Alignment, Position, TriggerPosition } from './constants';\nimport { getPosition } from './utilities';\nimport debounce from 'lodash.debounce';\n\n/**\n * useTriggerPosition hook.\n *\n * Calculates the position of a menu element based on the alignment settings relative to a trigger element.\n *\n * @param triggerRef - Reference to the DOM element that triggers the menu.\n * @param elementRef - Reference to the DOM element that is the menu.\n * @param menuAlign - The alignment configuration of the menu.\n * @param isElementVisible - Tells the hook if the element is visible. If false, the hook will not calculate the position.\n * @param menuOffset - The offset of the menu from the trigger element.\n * @param disable - Whether to disable the hook.\n * @param disableFlipping - Whether to disable flipping logic when the menu overflows the screen.\n * @returns {TriggerPosition} The calculated position of the menu element and whether it has been calculated yet.\n */\nexport const useTriggerPosition = (\n\ttriggerRef: RefObject<HTMLElement> | undefined,\n\telementRef: RefObject<HTMLElement>,\n\tmenuAlign: Alignment,\n\tisElementVisible: boolean = true,\n\tmenuOffset: number = 10,\n\tdisable = false,\n\tdisableFlipping = false\n): TriggerPosition => {\n\tconst offset = menuOffset;\n\n\t// Holds the current calculated position of the menu\n\tconst [menuPosition, setMenuPosition] = useState<Position>({ flipped: false, left: 0, top: 0 });\n\n\t// The first position is calculated in a requestAnimationFrame, after the element has\n\t// already rendered. Consumers can use this flag to hide the element until then.\n\tconst [isPositioned, setIsPositioned] = useState(false);\n\n\t// Read inside requestAnimationFrame callbacks, which can run after the element was hidden\n\tconst isVisibleRef = useRef(isElementVisible);\n\n\t// Memoize alignment so it only recalculates when specific props change\n\tconst alignment = useMemo(\n\t\t() => ({\n\t\t\talign: menuAlign.align,\n\t\t\tcustomPosition: menuAlign.customPosition,\n\t\t\tposition: menuAlign.position\n\t\t}),\n\t\t[menuAlign.align, menuAlign.position, menuAlign.customPosition]\n\t);\n\n\t/**\n\t * Calculates and updates the menu position relative to the trigger.\n\t * Uses requestAnimationFrame to ensure layout is stable before measuring.\n\t */\n\tconst updatePosition = useCallback(() => {\n\t\tif (!elementRef.current || !isElementVisible) return;\n\n\t\trequestAnimationFrame(() => {\n\t\t\tconst triggerRect = triggerRef?.current?.getBoundingClientRect();\n\t\t\tconst elementRect = elementRef.current?.getBoundingClientRect();\n\n\t\t\t// Set before the size check so the element is never hidden indefinitely\n\t\t\t// (e.g. environments without layout, where every rect is empty)\n\t\t\tif (isVisibleRef.current) setIsPositioned(true);\n\n\t\t\t// Don't update if the element is not visible/rendered\n\t\t\tif (!elementRect || elementRect.height === 0 || elementRect.width === 0) return;\n\n\t\t\tconst newPosition = getPosition(alignment, offset, elementRect, triggerRect, disableFlipping);\n\n\t\t\t// Only update state if the position has changed\n\t\t\tsetMenuPosition((prevPosition) => {\n\t\t\t\tif (prevPosition.left !== newPosition.left || prevPosition.top !== newPosition.top) {\n\t\t\t\t\treturn newPosition;\n\t\t\t\t}\n\t\t\t\treturn prevPosition;\n\t\t\t});\n\t\t});\n\t}, [alignment, elementRef, isElementVisible, offset, triggerRef, disableFlipping]);\n\n\t/**\n\t * Debounced version of the updatePosition function used for scroll and resize events.\n\t * 5ms debounce gives a balance between performance and responsiveness.\n\t */\n\tconst debouncedUpdatePosition = useMemo(() => debounce(updatePosition, 5), [updatePosition]);\n\n\tuseEffect(() => {\n\t\tif (disable) return;\n\n\t\tconst currentElement = elementRef.current;\n\n\t\t/**\n\t\t * We need to debounce the resize observer to prevent \"resize loops\"\n\t\t * There are instances where the ResizeObserver will trigger a resize event\n\t\t * before the browser has painted, which causes a loop of resize events\n\t\t * and can throw errors or performance issues.\n\t\t *\n\t\t * The observers are purposefully using a different debounce than the event listeners.\n\t\t * Observers need to be more aggressively debounced to prevent loops,\n\t\t * while event listeners (resize/scroll) should update positioning more responsively.\n\t\t */\n\t\tconst resizeObserver = new ResizeObserver(debounce(updatePosition));\n\t\tconst mutationObserver = new MutationObserver(debounce(updatePosition));\n\n\t\t// Observe changes in size and style/className\n\t\tif (currentElement) {\n\t\t\tresizeObserver.observe(currentElement);\n\t\t\tmutationObserver.observe(currentElement, {\n\t\t\t\tattributeFilter: ['style', 'class'],\n\t\t\t\tattributes: true\n\t\t\t});\n\t\t}\n\n\t\t// Add listeners on open to respond to browser resizing and scrolling\n\t\tif (isElementVisible) {\n\t\t\tupdatePosition();\n\t\t\twindow.addEventListener('resize', debouncedUpdatePosition);\n\t\t\twindow.addEventListener('scroll', debouncedUpdatePosition);\n\t\t}\n\n\t\t// Cleanup observers and listeners on unmount or re-render\n\t\treturn () => {\n\t\t\tif (currentElement) {\n\t\t\t\tresizeObserver.unobserve(currentElement);\n\t\t\t\tmutationObserver.disconnect();\n\t\t\t}\n\t\t\twindow.removeEventListener('resize', debouncedUpdatePosition);\n\t\t\twindow.removeEventListener('scroll', debouncedUpdatePosition);\n\t\t};\n\t}, [\n\t\tdisable,\n\t\ttriggerRef,\n\t\telementRef,\n\t\talignment,\n\t\toffset,\n\t\tisElementVisible,\n\t\tupdatePosition,\n\t\tdebouncedUpdatePosition\n\t]);\n\n\t/**\n\t * This effect handles an edge case where the menu is rendered,\n\t * but its size is not immediately available in the first frame.\n\t * A short timeout ensures we recalculate the position once layout stabilizes.\n\t */\n\tuseEffect(() => {\n\t\tif (!disable && isElementVisible) {\n\t\t\tconst timeoutId = setTimeout(updatePosition, 10);\n\n\t\t\treturn () => clearTimeout(timeoutId);\n\t\t}\n\t}, [isElementVisible, disable, updatePosition]);\n\n\t/**\n\t * useLayoutEffect ensures the position is recalculated during the layout phase,\n\t * just after DOM mutations but before the browser paints.\n\t */\n\tuseLayoutEffect(() => {\n\t\tif (!disable && isElementVisible && elementRef.current && triggerRef?.current) {\n\t\t\tupdatePosition();\n\t\t\trequestAnimationFrame(updatePosition);\n\t\t}\n\t}, [isElementVisible, updatePosition, disable, elementRef, triggerRef]);\n\n\t/**\n\t * Resets isPositioned when the element is hidden, so the next time it is shown\n\t * it is not reported as positioned until a fresh calculation has run.\n\t */\n\tuseLayoutEffect(() => {\n\t\tisVisibleRef.current = isElementVisible;\n\n\t\tif (!isElementVisible) setIsPositioned(false);\n\t}, [isElementVisible]);\n\n\treturn useMemo(() => ({ ...menuPosition, isPositioned }), [menuPosition, isPositioned]);\n};\n"],"names":["useTriggerPosition","triggerRef","elementRef","menuAlign","isElementVisible","arguments","length","undefined","menuOffset","disable","disableFlipping","offset","_useState","useState","flipped","left","top","_useState2","_slicedToArray","menuPosition","setMenuPosition","_useState3","_useState4","isPositioned","setIsPositioned","isVisibleRef","useRef","alignment","useMemo","align","customPosition","position","updatePosition","useCallback","current","requestAnimationFrame","_triggerRef$current","_elementRef$current","triggerRect","getBoundingClientRect","elementRect","height","width","newPosition","getPosition","prevPosition","debouncedUpdatePosition","debounce","useEffect","currentElement","resizeObserver","ResizeObserver","mutationObserver","MutationObserver","observe","attributeFilter","attributes","window","addEventListener","unobserve","disconnect","removeEventListener","timeoutId","setTimeout","clearTimeout","useLayoutEffect","_objectSpread"],"mappings":";;;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAkBA,CAC9BC,UAA8C,EAC9CC,UAAkC,EAClCC,SAAoB,EAKC;AAAA,EAAA,IAJrBC,gBAAyB,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,IAAI;AAAA,EAAA,IAChCG,UAAkB,GAAAH,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE;AAAA,EAAA,IACvBI,OAAO,GAAAJ,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA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CAACJ,YAAY,EAAEI,YAAY,CAAC,CAAC;AACxF;;;;"}
@@ -1,4 +1,4 @@
1
- var TOOLKIT_VERSION = "4.77.1";
1
+ var TOOLKIT_VERSION = "4.77.2";
2
2
 
3
3
  export { TOOLKIT_VERSION };
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["export const TOOLKIT_VERSION = \"4.77.1\";"],"names":["TOOLKIT_VERSION"],"mappings":"AAAO,IAAMA,eAAe,GAAG;;;;"}
1
+ {"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["export const TOOLKIT_VERSION = \"4.77.2\";"],"names":["TOOLKIT_VERSION"],"mappings":"AAAO,IAAMA,eAAe,GAAG;;;;"}
@@ -9,3 +9,7 @@ export interface Position {
9
9
  left: number;
10
10
  flipped: boolean;
11
11
  }
12
+ export interface TriggerPosition extends Position {
13
+ /** True once the position has been calculated for the current visible state */
14
+ isPositioned: boolean;
15
+ }
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { Alignment, Position } from './constants';
2
+ import { Alignment, TriggerPosition } from './constants';
3
3
  /**
4
4
  * useTriggerPosition hook.
5
5
  *
@@ -12,6 +12,6 @@ import { Alignment, Position } from './constants';
12
12
  * @param menuOffset - The offset of the menu from the trigger element.
13
13
  * @param disable - Whether to disable the hook.
14
14
  * @param disableFlipping - Whether to disable flipping logic when the menu overflows the screen.
15
- * @returns {Position} The calculated position of the menu element.
15
+ * @returns {TriggerPosition} The calculated position of the menu element and whether it has been calculated yet.
16
16
  */
17
- export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>, menuAlign: Alignment, isElementVisible?: boolean, menuOffset?: number, disable?: boolean, disableFlipping?: boolean) => Position;
17
+ export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>, menuAlign: Alignment, isElementVisible?: boolean, menuOffset?: number, disable?: boolean, disableFlipping?: boolean) => TriggerPosition;
@@ -9,3 +9,7 @@ export interface Position {
9
9
  left: number;
10
10
  flipped: boolean;
11
11
  }
12
+ export interface TriggerPosition extends Position {
13
+ /** True once the position has been calculated for the current visible state */
14
+ isPositioned: boolean;
15
+ }
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { Alignment, Position } from './constants';
2
+ import { Alignment, TriggerPosition } from './constants';
3
3
  /**
4
4
  * useTriggerPosition hook.
5
5
  *
@@ -12,6 +12,6 @@ import { Alignment, Position } from './constants';
12
12
  * @param menuOffset - The offset of the menu from the trigger element.
13
13
  * @param disable - Whether to disable the hook.
14
14
  * @param disableFlipping - Whether to disable flipping logic when the menu overflows the screen.
15
- * @returns {Position} The calculated position of the menu element.
15
+ * @returns {TriggerPosition} The calculated position of the menu element and whether it has been calculated yet.
16
16
  */
17
- export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>, menuAlign: Alignment, isElementVisible?: boolean, menuOffset?: number, disable?: boolean, disableFlipping?: boolean) => Position;
17
+ export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>, menuAlign: Alignment, isElementVisible?: boolean, menuOffset?: number, disable?: boolean, disableFlipping?: boolean) => TriggerPosition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muraldevkit/ui-toolkit",
3
- "version": "4.77.1",
3
+ "version": "4.77.2",
4
4
  "description": "Mural's UI Toolkit",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",