| 1 |
import { useMemo } from 'react'; |
| 2 |
|
| 3 |
export const PLUGINS_KEYS = Object.freeze( { |
| 4 |
ELEMENTOR: 'Elementor', |
| 5 |
ELEMENTOR_PRO: 'Elementor Pro', |
| 6 |
} ); |
| 7 |
|
| 8 |
export default function usePluginsData( plugins ) { |
| 9 |
const getPluginsData = () => { |
| 10 |
if ( ! plugins ) { |
| 11 |
return []; |
| 12 |
} |
| 13 |
|
| 14 |
const elementorPlugins = [], |
| 15 |
generalPlugins = []; |
| 16 |
|
| 17 |
plugins.forEach( ( plugin ) => { |
| 18 |
switch ( plugin.name ) { |
| 19 |
case PLUGINS_KEYS.ELEMENTOR: |
| 20 |
// Making sure that the core plugin is always first. |
| 21 |
elementorPlugins.unshift( plugin ); |
| 22 |
break; |
| 23 |
case PLUGINS_KEYS.ELEMENTOR_PRO: |
| 24 |
// Making sure that the pro plugin is always second. |
| 25 |
elementorPlugins.push( plugin ); |
| 26 |
break; |
| 27 |
default: |
| 28 |
generalPlugins.push( plugin ); |
| 29 |
} |
| 30 |
} ); |
| 31 |
|
| 32 |
// Making sure that the elementor plugins are always first. |
| 33 |
return elementorPlugins.concat( generalPlugins ); |
| 34 |
}; |
| 35 |
|
| 36 |
return { |
| 37 |
pluginsData: useMemo( () => getPluginsData(), [ plugins ] ), |
| 38 |
}; |
| 39 |
} |
| 40 |
|