@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.
- package/dist/index.js +159 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -93
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -7
- package/src/components/controls/time-frame-indicator.tsx +36 -25
- package/src/components/interaction-details.tsx +99 -48
- package/src/components/interactions-list.tsx +74 -39
- package/src/utils/prop-value-utils.ts +1 -12
|
@@ -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
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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:
|
|
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',
|