@elementor/editor-interactions 4.0.0-678 → 4.0.0-680

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-interactions",
3
- "version": "4.0.0-678",
3
+ "version": "4.0.0-680",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,18 +39,19 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor-controls": "4.0.0-678",
43
- "@elementor/editor-elements": "4.0.0-678",
44
- "@elementor/editor-mcp": "4.0.0-678",
45
- "@elementor/editor-props": "4.0.0-678",
46
- "@elementor/editor-responsive": "4.0.0-678",
47
- "@elementor/editor-ui": "4.0.0-678",
48
- "@elementor/editor-v1-adapters": "4.0.0-678",
42
+ "@elementor/editor-controls": "4.0.0-680",
43
+ "@elementor/editor-elements": "4.0.0-680",
44
+ "@elementor/editor-mcp": "4.0.0-680",
45
+ "@elementor/editor-props": "4.0.0-680",
46
+ "@elementor/editor-responsive": "4.0.0-680",
47
+ "@elementor/editor-ui": "4.0.0-680",
48
+ "@elementor/editor-v1-adapters": "4.0.0-680",
49
49
  "@elementor/icons": "^1.68.0",
50
- "@elementor/schema": "4.0.0-678",
51
- "@elementor/session": "4.0.0-678",
50
+ "@elementor/schema": "4.0.0-680",
51
+ "@elementor/session": "4.0.0-680",
52
52
  "@elementor/ui": "1.36.17",
53
- "@elementor/utils": "4.0.0-678",
53
+ "@elementor/utils": "4.0.0-680",
54
+ "@elementor/events": "4.0.0-680",
54
55
  "@wordpress/i18n": "^5.13.0"
55
56
  },
56
57
  "peerDependencies": {
@@ -1,13 +1,15 @@
1
1
  import * as React from 'react';
2
2
  import { useCallback, useEffect, useMemo, useRef } from 'react';
3
- import { Repeater } from '@elementor/editor-controls';
3
+ import { Repeater, type SetRepeaterValuesMeta } from '@elementor/editor-controls';
4
4
  import { InfoCircleFilledIcon, PlayerPlayIcon } from '@elementor/icons';
5
5
  import { Alert, AlertTitle, Box, IconButton, Tooltip } from '@elementor/ui';
6
6
  import { __ } from '@wordpress/i18n';
7
7
 
8
+ import { useInteractionsContext } from '../contexts/interactions-context';
8
9
  import { InteractionItemContextProvider } from '../contexts/interactions-item-context';
9
10
  import type { ElementInteractions, InteractionItemPropValue, InteractionItemValue } from '../types';
10
11
  import { buildDisplayLabel, createDefaultInteractionItem, extractString } from '../utils/prop-value-utils';
12
+ import { trackInteractionCreated } from '../utils/tracking';
11
13
  import { InteractionsListItem } from './interactions-list-item';
12
14
  export const MAX_NUMBER_OF_INTERACTIONS = 5;
13
15
 
@@ -20,6 +22,7 @@ export type InteractionListProps = {
20
22
 
21
23
  export function InteractionsList( props: InteractionListProps ) {
22
24
  const { interactions, onSelectInteractions, onPlayInteraction, triggerCreateOnShowEmpty } = props;
25
+ const { elementId } = useInteractionsContext();
23
26
 
24
27
  const hasInitializedRef = useRef( false );
25
28
 
@@ -62,13 +65,23 @@ export function InteractionsList( props: InteractionListProps ) {
62
65
  ) : undefined;
63
66
 
64
67
  const handleRepeaterChange = useCallback(
65
- ( newItems: ElementInteractions[ 'items' ] ) => {
68
+ (
69
+ newItems: ElementInteractions[ 'items' ],
70
+ _: unknown,
71
+ meta?: SetRepeaterValuesMeta< InteractionItemPropValue >
72
+ ) => {
66
73
  handleUpdateInteractions( {
67
74
  ...interactions,
68
75
  items: newItems,
69
76
  } );
77
+ if ( meta?.action?.type === 'add' ) {
78
+ const addedItem = meta.action.payload[ 0 ]?.item;
79
+ if ( addedItem ) {
80
+ trackInteractionCreated( elementId, addedItem );
81
+ }
82
+ }
70
83
  },
71
- [ interactions, handleUpdateInteractions ]
84
+ [ interactions, handleUpdateInteractions, elementId ]
72
85
  );
73
86
 
74
87
  const handleInteractionChange = useCallback(
@@ -7,6 +7,8 @@ import { InteractionsProvider, useInteractionsContext } from '../contexts/intera
7
7
  import { PopupStateProvider } from '../contexts/popup-state-context';
8
8
  import { useElementInteractions } from '../hooks/use-element-interactions';
9
9
  import type { ElementInteractions } from '../types';
10
+ import { createDefaultInteractionItem } from '../utils/prop-value-utils';
11
+ import { trackInteractionCreated } from '../utils/tracking';
10
12
  import { EmptyState } from './empty-state';
11
13
  import { InteractionsList } from './interactions-list';
12
14
 
@@ -33,6 +35,7 @@ function InteractionsTabContent( { elementId }: { elementId: string } ) {
33
35
  <EmptyState
34
36
  onCreateInteraction={ () => {
35
37
  firstInteractionState[ 1 ]( true );
38
+ trackInteractionCreated( elementId, createDefaultInteractionItem() );
36
39
  } }
37
40
  />
38
41
  ) }
@@ -9,6 +9,7 @@ import {
9
9
  import { useElementInteractions } from '../hooks/use-element-interactions';
10
10
 
11
11
  type InteractionsContextValue = {
12
+ elementId: string;
12
13
  interactions: ElementInteractions;
13
14
  setInteractions: ( value: ElementInteractions | undefined ) => void;
14
15
  playInteractions: ( interactionId: string ) => void;
@@ -45,6 +46,7 @@ export const InteractionsProvider = ( { children, elementId }: { children: React
45
46
  };
46
47
 
47
48
  const contextValue: InteractionsContextValue = {
49
+ elementId,
48
50
  interactions,
49
51
  setInteractions,
50
52
  playInteractions,
@@ -2,18 +2,22 @@ import { useState } from 'react';
2
2
  import { type ElementID, type ElementInteractions, getElementInteractions } from '@elementor/editor-elements';
3
3
  import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';
4
4
 
5
+ import { filterInteractions } from '../utils/filter-interactions';
6
+
5
7
  export const useElementInteractions = ( elementId: ElementID ) => {
6
8
  const [ interactions, setInteractions ] = useState< ElementInteractions >( () => {
7
9
  const initial = getElementInteractions( elementId );
10
+ const filteredInteractions = filterInteractions( initial?.items ?? [] );
8
11
 
9
- return initial ?? { version: 1, items: [] };
12
+ return { version: initial?.version ?? 1, items: filteredInteractions };
10
13
  } );
11
14
 
12
15
  useListenTo(
13
16
  windowEvent( 'elementor/element/update_interactions' ),
14
17
  () => {
15
18
  const newInteractions = getElementInteractions( elementId );
16
- setInteractions( newInteractions ?? { version: 1, items: [] } );
19
+ const filteredInteractions = filterInteractions( newInteractions?.items ?? [] );
20
+ setInteractions( { version: newInteractions?.version ?? 1, items: filteredInteractions } );
17
21
  },
18
22
  [ elementId ]
19
23
  );
package/src/init.ts CHANGED
@@ -33,7 +33,7 @@ export function init() {
33
33
  registerInteractionsControl( {
34
34
  type: 'replay',
35
35
  component: Replay,
36
- options: [ 'true', 'false' ],
36
+ options: [ 'no' ],
37
37
  } );
38
38
 
39
39
  registerInteractionsControl( {
@@ -9,7 +9,7 @@ import {
9
9
  type TimesFieldProps,
10
10
  } from './types';
11
11
 
12
- type InteractionsControlType =
12
+ export type InteractionsControlType =
13
13
  | 'trigger'
14
14
  | 'effect'
15
15
  | 'effectType'
@@ -0,0 +1,9 @@
1
+ import { type InteractionItemPropValue } from '@elementor/editor-elements';
2
+
3
+ import { isSupportedInteractionItem } from './is-supported-interaction-item';
4
+
5
+ export const filterInteractions = ( interactions: InteractionItemPropValue[] ) => {
6
+ return interactions.filter( ( interaction ) => {
7
+ return isSupportedInteractionItem( interaction );
8
+ } );
9
+ };
@@ -0,0 +1,39 @@
1
+ import { getInteractionsControlOptions, type InteractionsControlType } from '../interactions-controls-registry';
2
+ import { type InteractionItemPropValue } from '../types';
3
+ import { extractBoolean, extractString } from '../utils/prop-value-utils';
4
+
5
+ export function isSupportedInteractionItem( interaction: InteractionItemPropValue ): boolean {
6
+ const value = interaction.value;
7
+
8
+ const replay = extractBoolean( value.animation.value.config?.value.replay );
9
+ if ( true === replay ) {
10
+ return hasSupport( 'replay', 'yes' );
11
+ }
12
+
13
+ const trigger = extractString( value.trigger );
14
+ const easing = extractString( value.animation.value.config?.value.easing );
15
+ const effect = extractString( value.animation.value.effect );
16
+
17
+ const checks: Array< [ string, string ] > = [
18
+ [ 'trigger', trigger ],
19
+ [ 'easing', easing ],
20
+ [ 'effect', effect ],
21
+ ];
22
+
23
+ return checks.every( ( [ controlType, controlValue ] ) => {
24
+ if ( controlValue === '' || controlValue === null ) {
25
+ return true;
26
+ }
27
+ return hasSupport( controlType, controlValue );
28
+ } );
29
+ }
30
+
31
+ function hasSupport( controlType: string, controlValue: string ) {
32
+ const supportedOptions = getInteractionsControlOptions( controlType as InteractionsControlType );
33
+
34
+ if ( 1 > supportedOptions.length ) {
35
+ return true;
36
+ }
37
+
38
+ return supportedOptions.includes( controlValue );
39
+ }
@@ -0,0 +1,42 @@
1
+ import { getElementLabel } from '@elementor/editor-elements';
2
+ import { getMixpanel } from '@elementor/events';
3
+
4
+ import type { InteractionItemPropValue } from '../types';
5
+ import { extractString } from './prop-value-utils';
6
+
7
+ const TRIGGER_LABELS: Record< string, string > = {
8
+ load: 'On page load',
9
+ scrollIn: 'Scroll into view',
10
+ scrollOut: 'Scroll out of view',
11
+ scrollOn: 'While scrolling',
12
+ hover: 'Hover',
13
+ click: 'Click',
14
+ };
15
+
16
+ const capitalize = ( s: string ) => s.charAt( 0 ).toUpperCase() + s.slice( 1 );
17
+
18
+ export const trackInteractionCreated = ( elementId: string, item: InteractionItemPropValue ) => {
19
+ const { dispatchEvent, config } = getMixpanel();
20
+ if ( ! config?.names?.interactions?.created ) {
21
+ return;
22
+ }
23
+
24
+ const trigger = extractString( item.value.trigger );
25
+ const effect = extractString( item.value.animation.value.effect );
26
+ const type = extractString( item.value.animation.value.type );
27
+
28
+ dispatchEvent?.( config.names.interactions.created, {
29
+ app_type: config?.appTypes?.editor,
30
+ window_name: config?.appTypes?.editor,
31
+ interaction_type: config?.triggers?.click,
32
+ target_name: getElementLabel( elementId ),
33
+ interaction_result: 'interaction_created',
34
+ target_location: config?.locations?.widgetPanel,
35
+ location_l1: getElementLabel( elementId ),
36
+ location_l2: 'interactions',
37
+ interaction_description: 'interaction_created',
38
+ interaction_trigger: TRIGGER_LABELS[ trigger ] ?? capitalize( trigger ),
39
+ interaction_effect:
40
+ effect === 'custom' ? capitalize( effect ) : `${ capitalize( effect ) } ${ capitalize( type ) }`,
41
+ } );
42
+ };