@elementor/editor-app-bar 3.32.0-34 → 3.32.0-36

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,60 @@
1
+ import { useCallback } from 'react';
2
+ import { UserIcon } from '@elementor/icons';
3
+ import { __ } from '@wordpress/i18n';
4
+
5
+ import { type ExtendedWindow } from '../../../types';
6
+
7
+ export default function useConnectLinkConfig() {
8
+ const extendedWindow = window as unknown as ExtendedWindow;
9
+ let isUserConnected = false;
10
+ const isPro = extendedWindow?.elementor?.helpers.hasPro();
11
+ let target = '_blank';
12
+ if ( isPro ) {
13
+ isUserConnected = extendedWindow?.elementorPro?.config.isActive ?? false;
14
+ } else {
15
+ isUserConnected = extendedWindow?.elementorCommon?.config.library_connect.is_connected ?? false;
16
+ target = '_self';
17
+ }
18
+
19
+ const handleConnectClick = useCallback(
20
+ ( event: React.MouseEvent< HTMLElement > ) => {
21
+ event.preventDefault();
22
+
23
+ if ( extendedWindow.jQuery && extendedWindow.jQuery.fn?.elementorConnect ) {
24
+ const connectUrl = extendedWindow?.elementor?.config.user.top_bar.connect_url;
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ const $tempButton = ( extendedWindow as any ).jQuery( '<a>' );
27
+ $tempButton
28
+ ?.attr( 'href', connectUrl )
29
+ ?.attr( 'target', '_blank' )
30
+ ?.attr( 'rel', 'opener' )
31
+ ?.css( 'display', 'none' )
32
+ ?.appendTo( 'body' );
33
+
34
+ $tempButton.elementorConnect();
35
+
36
+ $tempButton[ 0 ].click();
37
+
38
+ setTimeout( () => {
39
+ $tempButton.remove();
40
+ }, 1000 );
41
+ }
42
+ },
43
+ [ extendedWindow ]
44
+ );
45
+
46
+ return isUserConnected
47
+ ? {
48
+ title: __( 'My Elementor', 'elementor' ),
49
+ href: extendedWindow?.elementor?.config.user.top_bar.my_elementor_url,
50
+ icon: UserIcon,
51
+ target: '_blank',
52
+ }
53
+ : {
54
+ title: __( 'Connect my account', 'elementor' ),
55
+ href: extendedWindow?.elementor?.config.user.top_bar.connect_url,
56
+ icon: UserIcon,
57
+ target,
58
+ onClick: handleConnectClick,
59
+ };
60
+ }
@@ -0,0 +1,11 @@
1
+ import { mainMenu } from '../../locations';
2
+ import useConnectLinkConfig from './hooks/use-connect-link-config';
3
+
4
+ export function init() {
5
+ mainMenu.registerLink( {
6
+ id: 'app-bar-connect',
7
+ group: 'exits',
8
+ priority: 10,
9
+ useProps: useConnectLinkConfig,
10
+ } );
11
+ }
@@ -14,6 +14,7 @@ export function init() {
14
14
  href: 'https://go.elementor.com/editor-top-bar-learn/',
15
15
  icon: HelpIcon,
16
16
  target: '_blank',
17
+ showExternalLinkIcon: true,
17
18
  onClick: () => {
18
19
  const extendedWindow = window as unknown as ExtendedWindow;
19
20
  const config = extendedWindow?.elementorCommon?.eventsManager?.config;
@@ -3,6 +3,7 @@
3
3
  * The code should be moved to the appropriate packages.
4
4
  */
5
5
 
6
+ import { init as initConnect } from './connect';
6
7
  import { init as initDocumentsIndicator } from './documents-indicator';
7
8
  import { init as initDocumentsPreview } from './documents-preview';
8
9
  import { init as initDocumentsSave } from './documents-save';
@@ -33,4 +34,5 @@ export function init() {
33
34
  initThemeBuilder();
34
35
  initUserPreferences();
35
36
  initWordpress();
37
+ initConnect();
36
38
  }
@@ -9,6 +9,7 @@ export function init() {
9
9
  mainMenu.registerLink( {
10
10
  id: 'exit-to-wordpress',
11
11
  group: 'exits',
12
+ priority: 20,
12
13
  useProps: () => {
13
14
  const document = useActiveDocument();
14
15
  return {
package/src/types.ts CHANGED
@@ -12,6 +12,34 @@ export type ExtendedWindow = Window & {
12
12
  };
13
13
  };
14
14
  };
15
+ config: {
16
+ library_connect: {
17
+ is_connected: boolean;
18
+ };
19
+ };
20
+ };
21
+ elementor: {
22
+ helpers: {
23
+ hasPro: () => boolean;
24
+ };
25
+ config: {
26
+ user: {
27
+ top_bar: {
28
+ my_elementor_url: string;
29
+ connect_url: string;
30
+ };
31
+ };
32
+ };
33
+ };
34
+ elementorPro: {
35
+ config: {
36
+ isActive: boolean;
37
+ };
38
+ };
39
+ jQuery: {
40
+ fn?: {
41
+ elementorConnect?: ( selector: string ) => never;
42
+ };
15
43
  };
16
44
  };
17
45