@elementor/editor-ui 0.11.0 → 0.13.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.
@@ -0,0 +1,28 @@
1
+ import { useEffect } from 'react';
2
+ import type { Virtualizer } from '@tanstack/react-virtual';
3
+
4
+ import type { VirtualizedItem } from '../components/popover/menu-list';
5
+
6
+ type UseScrollToSelectedProps< T, V extends string > = {
7
+ selectedValue?: V;
8
+ items: VirtualizedItem< T, V >[];
9
+ virtualizer: Virtualizer< HTMLDivElement, Element >;
10
+ };
11
+
12
+ export const useScrollToSelected = < T, V extends string >( {
13
+ selectedValue,
14
+ items,
15
+ virtualizer,
16
+ }: UseScrollToSelectedProps< T, V > ) => {
17
+ useEffect( () => {
18
+ if ( ! selectedValue || items.length === 0 ) {
19
+ return;
20
+ }
21
+
22
+ const selectedIndex = items.findIndex( ( item ) => item.value === selectedValue );
23
+
24
+ if ( selectedIndex !== -1 ) {
25
+ virtualizer.scrollToIndex( selectedIndex, { align: 'center' } );
26
+ }
27
+ }, [ selectedValue, items, virtualizer ] );
28
+ };
@@ -0,0 +1,26 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ type UseScrollTopProps = {
4
+ containerRef: React.RefObject< HTMLDivElement >;
5
+ };
6
+
7
+ export const useScrollTop = ( { containerRef }: UseScrollTopProps ) => {
8
+ const [ scrollTop, setScrollTop ] = useState( 0 );
9
+
10
+ useEffect( () => {
11
+ const container = containerRef.current;
12
+
13
+ if ( ! container ) {
14
+ return;
15
+ }
16
+
17
+ const handleScroll = () => {
18
+ setScrollTop( container.scrollTop );
19
+ };
20
+
21
+ container.addEventListener( 'scroll', handleScroll );
22
+ return () => container.removeEventListener( 'scroll', handleScroll );
23
+ }, [ containerRef ] );
24
+
25
+ return scrollTop;
26
+ };
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ export { MenuListItem, MenuItemInfotip } from './components/menu-item';
7
7
  export { InfoTipCard } from './components/infotip-card';
8
8
  export { InfoAlert } from './components/info-alert';
9
9
  export { WarningInfotip } from './components/warning-infotip';
10
- export { PopoverHeader } from './components/popover/header';
10
+ export * from './components/popover';
11
11
 
12
12
  // hooks
13
13
  export { useEditable } from './hooks/use-editable';