@elementor/editor-variables 4.0.0-manual → 4.1.0-684

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-variables",
3
- "version": "4.0.0-manual",
3
+ "version": "4.1.0-684",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,22 +39,22 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.0.0-manual",
43
- "@elementor/editor-canvas": "4.0.0-manual",
44
- "@elementor/editor-controls": "4.0.0-manual",
45
- "@elementor/editor-current-user": "4.0.0-manual",
46
- "@elementor/editor-mcp": "4.0.0-manual",
47
- "@elementor/editor-panels": "4.0.0-manual",
48
- "@elementor/editor-props": "4.0.0-manual",
49
- "@elementor/editor-ui": "4.0.0-manual",
50
- "@elementor/editor-v1-adapters": "4.0.0-manual",
51
- "@elementor/menus": "4.0.0-manual",
52
- "@elementor/http-client": "4.0.0-manual",
42
+ "@elementor/editor": "4.1.0-684",
43
+ "@elementor/editor-canvas": "4.1.0-684",
44
+ "@elementor/editor-controls": "4.1.0-684",
45
+ "@elementor/editor-current-user": "4.1.0-684",
46
+ "@elementor/editor-mcp": "4.1.0-684",
47
+ "@elementor/editor-panels": "4.1.0-684",
48
+ "@elementor/editor-props": "4.1.0-684",
49
+ "@elementor/editor-ui": "4.1.0-684",
50
+ "@elementor/editor-v1-adapters": "4.1.0-684",
51
+ "@elementor/menus": "4.1.0-684",
52
+ "@elementor/http-client": "4.1.0-684",
53
53
  "@elementor/icons": "^1.68.0",
54
- "@elementor/events": "4.0.0-manual",
55
- "@elementor/schema": "4.0.0-manual",
54
+ "@elementor/events": "4.1.0-684",
55
+ "@elementor/schema": "4.1.0-684",
56
56
  "@elementor/ui": "1.37.2",
57
- "@elementor/utils": "4.0.0-manual",
57
+ "@elementor/utils": "4.1.0-684",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -0,0 +1,46 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import {
3
+ __privateListenTo as listenTo,
4
+ __privateOpenRoute as openRoute,
5
+ routeOpenEvent,
6
+ } from '@elementor/editor-v1-adapters';
7
+
8
+ import { usePanelActions } from './variables-manager/variables-manager-panel';
9
+
10
+ const EVENT_NAME = 'elementor/open-variables-manager';
11
+ const DEFAULT_PANEL_ROUTE = 'panel/elements/categories';
12
+
13
+ export function OpenPanelFromEvent() {
14
+ const { open } = usePanelActions();
15
+ const pendingRef = useRef( false );
16
+ const [ readyToOpen, setReadyToOpen ] = useState( false );
17
+
18
+ useEffect( () => {
19
+ if ( readyToOpen ) {
20
+ setReadyToOpen( false );
21
+ open();
22
+ }
23
+ }, [ readyToOpen, open ] );
24
+
25
+ useEffect( () => {
26
+ return listenTo( routeOpenEvent( DEFAULT_PANEL_ROUTE ), () => {
27
+ if ( pendingRef.current ) {
28
+ pendingRef.current = false;
29
+ setReadyToOpen( true );
30
+ }
31
+ } );
32
+ }, [] );
33
+
34
+ useEffect( () => {
35
+ const handler = () => {
36
+ pendingRef.current = true;
37
+ openRoute( DEFAULT_PANEL_ROUTE );
38
+ };
39
+
40
+ window.addEventListener( EVENT_NAME, handler );
41
+
42
+ return () => window.removeEventListener( EVENT_NAME, handler );
43
+ }, [] );
44
+
45
+ return null;
46
+ }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { forwardRef, type MouseEvent, useImperativeHandle, useState } from 'react';
2
+ import { forwardRef, type MouseEvent, useCallback, useImperativeHandle, useState } from 'react';
3
+ import { type PromotionTrackingData, trackUpgradePromotionClick, trackViewPromotion } from '@elementor/editor-controls';
3
4
  import { PromotionChip, PromotionPopover, useCanvasClickHandler } from '@elementor/editor-ui';
4
5
  import { Box } from '@elementor/ui';
5
6
  import { capitalize } from '@elementor/utils';
@@ -8,6 +9,7 @@ import { __, sprintf } from '@wordpress/i18n';
8
9
  type VariablePromotionChipProps = {
9
10
  variableType: string;
10
11
  upgradeUrl: string;
12
+ trackingData: PromotionTrackingData;
11
13
  };
12
14
 
13
15
  export type VariablePromotionChipRef = {
@@ -15,14 +17,21 @@ export type VariablePromotionChipRef = {
15
17
  };
16
18
 
17
19
  export const VariablePromotionChip = forwardRef< VariablePromotionChipRef, VariablePromotionChipProps >(
18
- ( { variableType, upgradeUrl }, ref ) => {
20
+ ( { variableType, upgradeUrl, trackingData }, ref ) => {
19
21
  const [ isOpen, setIsOpen ] = useState( false );
20
22
 
21
23
  useCanvasClickHandler( isOpen, () => setIsOpen( false ) );
22
24
 
23
- const toggle = () => setIsOpen( ( prev ) => ! prev );
25
+ const toggle = useCallback( () => {
26
+ setIsOpen( ( prev ) => {
27
+ if ( ! prev ) {
28
+ trackViewPromotion( trackingData );
29
+ }
30
+ return ! prev;
31
+ } );
32
+ }, [ trackingData ] );
24
33
 
25
- useImperativeHandle( ref, () => ( { toggle } ), [] );
34
+ useImperativeHandle( ref, () => ( { toggle } ), [ toggle ] );
26
35
 
27
36
  const title = sprintf(
28
37
  /* translators: %s: Variable Type. */
@@ -47,6 +56,7 @@ export const VariablePromotionChip = forwardRef< VariablePromotionChipRef, Varia
47
56
  e.stopPropagation();
48
57
  setIsOpen( false );
49
58
  } }
59
+ onCtaClick={ () => trackUpgradePromotionClick( trackingData ) }
50
60
  >
51
61
  <Box
52
62
  onClick={ ( e: MouseEvent ) => {
@@ -13,6 +13,8 @@ import { VariableEditableCell } from '../variable-editable-cell';
13
13
  import { VariableEditMenu, type VariableManagerMenuAction } from './variable-edit-menu';
14
14
  import { VariableTableCell } from './variable-table-cell';
15
15
 
16
+ const TRACKING_DATA = { target_name: 'variables_manager', target_location: 'variables_manager' } as const;
17
+
16
18
  export type Row = ReturnType< typeof getVariableType > & {
17
19
  id: string;
18
20
  type: string;
@@ -200,6 +202,7 @@ export const VariableRow = (
200
202
  variableType={ row.variableType }
201
203
  upgradeUrl={ `https://go.elementor.com/renew-license-manager-${ row.variableType }-variable` }
202
204
  ref={ promotionRef }
205
+ trackingData={ TRACKING_DATA }
203
206
  />
204
207
  ) }
205
208
  <VariableEditMenu menuActions={ menuActions( row.id ) } disabled={ isSorting } itemId={ row.id } />
@@ -11,6 +11,12 @@ import { trackVariablesManagerEvent } from '../../utils/tracking';
11
11
  import { getVariableTypes } from '../../variables-registry/variable-type-registry';
12
12
  import { VariablePromotionChip, type VariablePromotionChipRef } from '../ui/variable-promotion-chip';
13
13
 
14
+ const TRACKING_DATA = {
15
+ target_name: 'variables_manager',
16
+ target_location: 'variables_manager',
17
+ location_l1: 'create variable menu',
18
+ } as const;
19
+
14
20
  export const SIZE = 'tiny';
15
21
 
16
22
  type MenuOptionConfig = {
@@ -133,6 +139,7 @@ const MenuOption = ( {
133
139
  variableType={ config.variableType }
134
140
  upgradeUrl={ `https://go.elementor.com/go-pro-manager-${ config.variableType }-variable/` }
135
141
  ref={ promotionRef }
142
+ trackingData={ TRACKING_DATA }
136
143
  />
137
144
  ) }
138
145
  </MenuItem>
@@ -142,13 +149,19 @@ const MenuOption = ( {
142
149
  export const getDefaultName = ( variables: TVariablesList, baseName: string ) => {
143
150
  const pattern = new RegExp( `^${ baseName }-(\\d+)$`, 'i' );
144
151
 
145
- let counter = 1;
152
+ const takenNumbers = new Set< number >();
146
153
 
147
154
  Object.values( variables ).forEach( ( variable ) => {
148
- if ( pattern.test( variable.label ) ) {
149
- counter = Math.max( counter, parseInt( variable.label.match( pattern )?.[ 1 ] ?? '0', 10 ) + 1 );
155
+ const match = variable.label.match( pattern );
156
+ if ( match ) {
157
+ takenNumbers.add( parseInt( match[ 1 ], 10 ) );
150
158
  }
151
159
  } );
152
160
 
161
+ let counter = 1;
162
+ while ( takenNumbers.has( counter ) ) {
163
+ counter++;
164
+ }
165
+
153
166
  return `${ baseName }-${ counter }`;
154
167
  };
@@ -436,7 +436,7 @@ const StopSyncConfirmationDialog = ( { open, onClose, onConfirm }: StopSyncConfi
436
436
  <ConfirmationDialog.Content>
437
437
  <ConfirmationDialog.ContentText>
438
438
  { __(
439
- 'This will disconnect the variable color from version 3. Existing uses on your site will automatically switch to a default color.',
439
+ 'This will disconnect the variable color from Global Colors. Existing uses on your site will automatically switch to a default color.',
440
440
  'elementor'
441
441
  ) }
442
442
  </ConfirmationDialog.ContentText>
@@ -1,5 +1,6 @@
1
- import { useState } from 'react';
1
+ import { useEffect, useState } from 'react';
2
2
  import * as React from 'react';
3
+ import { trackUpgradePromotionClick, trackViewPromotion } from '@elementor/editor-controls';
3
4
  import {
4
5
  PopoverHeader,
5
6
  PopoverMenuList,
@@ -132,6 +133,16 @@ export const VariablesSelection = ( { closePopover, onAdd, onEdit, onSettings, d
132
133
  setSearchValue( '' );
133
134
  };
134
135
 
136
+ useEffect( () => {
137
+ if ( disabled ) {
138
+ trackViewPromotion( {
139
+ target_name: 'variables_popover',
140
+ target_location: 'widget_panel',
141
+ location_l1: 'variables_list',
142
+ } );
143
+ }
144
+ }, [ disabled ] );
145
+
135
146
  return (
136
147
  <SectionPopoverBody>
137
148
  <PopoverHeader
@@ -172,6 +183,12 @@ export const VariablesSelection = ( { closePopover, onAdd, onEdit, onSettings, d
172
183
  variableType
173
184
  ) }
174
185
  upgradeUrl={ getProUpgradeUrl( variableType ) }
186
+ onCtaClick={ () =>
187
+ trackUpgradePromotionClick( {
188
+ target_name: 'variables_popover',
189
+ location_l1: 'variables_list',
190
+ } )
191
+ }
175
192
  />
176
193
  ) }
177
194
  </>
package/src/init.ts CHANGED
@@ -4,6 +4,7 @@ import { __registerPanel as registerPanel } from '@elementor/editor-panels';
4
4
  import { isTransformable, type PropValue } from '@elementor/editor-props';
5
5
  import { controlActionsMenu } from '@elementor/menus';
6
6
 
7
+ import { OpenPanelFromEvent } from './components/open-panel-from-event';
7
8
  import { OpenPanelFromUrl } from './components/open-panel-from-url';
8
9
  import { panel } from './components/variables-manager/variables-manager-panel';
9
10
  import { VariableControl } from './controls/variable-control';
@@ -56,6 +57,11 @@ export function init() {
56
57
  component: OpenPanelFromUrl,
57
58
  } );
58
59
 
60
+ injectIntoLogic( {
61
+ id: 'variables-open-panel-from-event',
62
+ component: OpenPanelFromEvent,
63
+ } );
64
+
59
65
  registerPanel( panel );
60
66
  }
61
67
 
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { trackUpgradePromotionClick } from '@elementor/editor-controls';
2
3
  import { colorPropTypeUtil, sizePropTypeUtil, stringPropTypeUtil } from '@elementor/editor-props';
3
4
  import { CtaButton } from '@elementor/editor-ui';
4
5
  import { isExperimentActive } from '@elementor/editor-v1-adapters';
@@ -33,14 +34,14 @@ export function registerVariableTypes() {
33
34
 
34
35
  if ( variable.sync_to_v3 ) {
35
36
  actions.push( {
36
- name: __( 'Stop syncing to Version 3', 'elementor' ),
37
+ name: __( 'Stop syncing to Global Colors', 'elementor' ),
37
38
  icon: ResetIcon,
38
39
  color: 'text.primary',
39
40
  onClick: () => handlers.onStopSync( variableId ),
40
41
  } );
41
42
  } else {
42
43
  actions.push( {
43
- name: __( 'Sync to Version 3', 'elementor' ),
44
+ name: __( 'Sync to Global Colors', 'elementor' ),
44
45
  icon: ResetIcon,
45
46
  color: 'text.primary',
46
47
  onClick: () => handlers.onStartSync( variableId ),
@@ -69,7 +70,15 @@ export function registerVariableTypes() {
69
70
  styleTransformer: EmptyTransformer,
70
71
  variableType: 'size',
71
72
  selectionFilter: () => [],
72
- emptyState: <CtaButton size="small" href={ 'https://go.elementor.com/go-pro-panel-size-variable/' } />,
73
+ emptyState: (
74
+ <CtaButton
75
+ size="small"
76
+ href={ 'https://go.elementor.com/go-pro-panel-size-variable/' }
77
+ onClick={ () =>
78
+ trackUpgradePromotionClick( { target_name: 'variables_popover', location_l1: 'variables_list' } )
79
+ }
80
+ />
81
+ ),
73
82
  };
74
83
 
75
84
  registerVariableType( {
@@ -10,7 +10,7 @@ import { Portal } from '@elementor/ui';
10
10
  import { styleVariablesRepository } from '../style-variables-repository';
11
11
  import { type StyleVariables, type Variable } from '../types';
12
12
 
13
- const VARIABLES_WRAPPER = 'body';
13
+ const VARIABLES_WRAPPER = ':root';
14
14
 
15
15
  export function StyleVariablesRenderer() {
16
16
  const container = usePortalContainer();