@elementor/editor-interactions 4.0.0-497 → 4.0.0-499

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.
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
3
3
  import { Repeater } from '@elementor/editor-controls';
4
4
  import { InfoCircleFilledIcon, PlayerPlayIcon } from '@elementor/icons';
5
5
  import { Alert, AlertTitle, Box, IconButton, Tooltip } from '@elementor/ui';
@@ -17,6 +17,13 @@ export type InteractionListProps = {
17
17
  triggerCreateOnShowEmpty?: boolean;
18
18
  };
19
19
 
20
+ type InteractionItemContextValue = {
21
+ onInteractionChange: ( index: number, newInteractionValue: InteractionItemValue ) => void;
22
+ onPlayInteraction: ( interactionId: string ) => void;
23
+ };
24
+
25
+ const InteractionItemContext = createContext< InteractionItemContextValue | null >( null );
26
+
20
27
  export function InteractionsList( props: InteractionListProps ) {
21
28
  const { interactions, onSelectInteractions, onPlayInteraction, triggerCreateOnShowEmpty } = props;
22
29
 
@@ -85,44 +92,72 @@ export function InteractionsList( props: InteractionListProps ) {
85
92
  [ interactions, handleUpdateInteractions ]
86
93
  );
87
94
 
95
+ const contextValue = useMemo(
96
+ () => ( {
97
+ onInteractionChange: handleInteractionChange,
98
+ onPlayInteraction,
99
+ } ),
100
+ [ handleInteractionChange, onPlayInteraction ]
101
+ );
102
+
88
103
  return (
89
- <Repeater
90
- openOnAdd
91
- openItem={ triggerCreateOnShowEmpty ? 0 : undefined }
92
- label={ __( 'Interactions', 'elementor' ) }
93
- values={ interactions.items }
94
- setValues={ handleRepeaterChange }
95
- showDuplicate={ false }
96
- showToggle={ false }
97
- isSortable={ false }
98
- disableAddItemButton={ isMaxNumberOfInteractionsReached }
99
- addButtonInfotipContent={ infotipContent }
100
- itemSettings={ {
101
- initialValues: createDefaultInteractionItem(),
102
- Label: ( { value }: { value: InteractionItemPropValue } ) => buildDisplayLabel( value.value ),
103
- Icon: () => null,
104
- Content: ( { index, value }: { index: number; value: InteractionItemPropValue } ) => (
105
- <InteractionDetails
106
- key={ index }
107
- interaction={ value.value }
108
- onChange={ ( newInteractionValue: InteractionItemValue ) => {
109
- handleInteractionChange( index, newInteractionValue );
110
- } }
111
- onPlayInteraction={ onPlayInteraction }
112
- />
113
- ),
114
- actions: ( value: InteractionItemPropValue ) => (
115
- <Tooltip key="preview" placement="top" title={ __( 'Preview', 'elementor' ) }>
116
- <IconButton
117
- aria-label={ __( 'Play interaction', 'elementor' ) }
118
- size="tiny"
119
- onClick={ () => onPlayInteraction( extractString( value.value.interaction_id ) ) }
120
- >
121
- <PlayerPlayIcon fontSize="tiny" />
122
- </IconButton>
123
- </Tooltip>
124
- ),
125
- } }
126
- />
104
+ <InteractionItemContext.Provider value={ contextValue }>
105
+ <Repeater
106
+ openOnAdd
107
+ openItem={ triggerCreateOnShowEmpty ? 0 : undefined }
108
+ label={ __( 'Interactions', 'elementor' ) }
109
+ values={ interactions.items }
110
+ setValues={ handleRepeaterChange }
111
+ showDuplicate={ false }
112
+ showToggle={ false }
113
+ isSortable={ false }
114
+ disableAddItemButton={ isMaxNumberOfInteractionsReached }
115
+ addButtonInfotipContent={ infotipContent }
116
+ itemSettings={ {
117
+ initialValues: createDefaultInteractionItem(),
118
+ Label: ( { value }: { value: InteractionItemPropValue } ) => buildDisplayLabel( value.value ),
119
+ Icon: () => null,
120
+ Content,
121
+ actions: ( value: InteractionItemPropValue ) => (
122
+ <Tooltip key="preview" placement="top" title={ __( 'Preview', 'elementor' ) }>
123
+ <IconButton
124
+ aria-label={ __( 'Play interaction', 'elementor' ) }
125
+ size="tiny"
126
+ onClick={ () => onPlayInteraction( extractString( value.value.interaction_id ) ) }
127
+ >
128
+ <PlayerPlayIcon fontSize="tiny" />
129
+ </IconButton>
130
+ </Tooltip>
131
+ ),
132
+ } }
133
+ />
134
+ </InteractionItemContext.Provider>
127
135
  );
128
136
  }
137
+
138
+ const Content = ( { index, value }: { index: number; value: InteractionItemPropValue } ) => {
139
+ const context = useContext( InteractionItemContext );
140
+
141
+ const handleChange = useCallback(
142
+ ( newInteractionValue: InteractionItemValue ) => {
143
+ context?.onInteractionChange( index, newInteractionValue );
144
+ },
145
+ [ context, index ]
146
+ );
147
+
148
+ const handlePlayInteraction = useCallback(
149
+ ( interactionId: string ) => {
150
+ context?.onPlayInteraction( interactionId );
151
+ },
152
+ [ context ]
153
+ );
154
+
155
+ return (
156
+ <InteractionDetails
157
+ key={ index }
158
+ interaction={ value.value }
159
+ onChange={ handleChange }
160
+ onPlayInteraction={ handlePlayInteraction }
161
+ />
162
+ );
163
+ };
@@ -132,7 +132,7 @@ export const createDefaultInteractionItem = (): InteractionItemPropValue => {
132
132
  trigger: 'load',
133
133
  effect: 'fade',
134
134
  type: 'in',
135
- duration: 300,
135
+ duration: 600,
136
136
  delay: 0,
137
137
  replay: false,
138
138
  interactionId: generateTempInteractionId(),
@@ -152,17 +152,6 @@ export const extractNumber = ( prop: NumberPropValue | undefined, fallback = 0 )
152
152
  return prop?.value ?? fallback;
153
153
  };
154
154
 
155
- export const buildAnimationIdString = ( item: InteractionItemValue ): string => {
156
- const trigger = extractString( item.trigger );
157
- const effect = extractString( item.animation.value.effect );
158
- const type = extractString( item.animation.value.type );
159
- const direction = extractString( item.animation.value.direction );
160
- const duration = extractNumber( item.animation.value.timing_config.value.duration );
161
- const delay = extractNumber( item.animation.value.timing_config.value.delay );
162
-
163
- return [ trigger, effect, type, direction, duration, delay ].join( '-' );
164
- };
165
-
166
155
  const TRIGGER_LABELS: Record< string, string > = {
167
156
  load: 'On page load',
168
157
  scrollIn: 'Scroll into view',