@elementor/editor-interactions 3.35.0-361 → 3.35.0-363

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/src/types.ts CHANGED
@@ -1,4 +1,20 @@
1
- import { type ElementInteractions } from '@elementor/editor-elements';
1
+ import type {
2
+ AnimationPresetPropValue,
3
+ ElementInteractions,
4
+ InteractionItemPropValue,
5
+ NumberPropValue,
6
+ StringPropValue,
7
+ TimingConfigPropValue,
8
+ } from '@elementor/editor-elements';
9
+
10
+ export type {
11
+ StringPropValue,
12
+ NumberPropValue,
13
+ TimingConfigPropValue,
14
+ AnimationPresetPropValue,
15
+ InteractionItemPropValue,
16
+ ElementInteractions,
17
+ };
2
18
 
3
19
  export type AnimationOption = {
4
20
  value: string;
@@ -28,19 +44,21 @@ export type DirectionFieldProps = FieldProps & {
28
44
  interactionType: string;
29
45
  };
30
46
 
31
- export type InteractionItem = {
47
+ export type ElementInteractionData = {
32
48
  elementId: string;
33
49
  dataId: string; // The data-id attribute for DOM selection
34
50
  interactions: ElementInteractions;
35
51
  };
36
52
 
37
- export type InteractionsCollection = InteractionItem[];
53
+ export type InteractionsCollection = ElementInteractionData[];
38
54
 
39
55
  export type InteractionsProvider = {
40
56
  getKey: () => string;
41
57
  priority: number;
42
58
  subscribe: ( callback: () => void ) => () => void;
43
59
  actions: {
44
- all: () => InteractionItem[];
60
+ all: () => ElementInteractionData[];
45
61
  };
46
62
  };
63
+
64
+ export type InteractionItemValue = InteractionItemPropValue[ 'value' ];
@@ -0,0 +1,110 @@
1
+ import type {
2
+ AnimationPresetPropValue,
3
+ ElementInteractions,
4
+ InteractionItemPropValue,
5
+ InteractionItemValue,
6
+ NumberPropValue,
7
+ StringPropValue,
8
+ TimingConfigPropValue,
9
+ } from '../types';
10
+
11
+ export const createString = ( value: string ): StringPropValue => ( {
12
+ $$type: 'string',
13
+ value,
14
+ } );
15
+
16
+ export const createNumber = ( value: number ): NumberPropValue => ( {
17
+ $$type: 'number',
18
+ value,
19
+ } );
20
+
21
+ export const createTimingConfig = ( duration: number, delay: number ): TimingConfigPropValue => ( {
22
+ $$type: 'timing-config',
23
+ value: {
24
+ duration: createNumber( duration ),
25
+ delay: createNumber( delay ),
26
+ },
27
+ } );
28
+
29
+ export const createAnimationPreset = (
30
+ effect: string,
31
+ type: string,
32
+ direction: string,
33
+ duration: number,
34
+ delay: number
35
+ ): AnimationPresetPropValue => ( {
36
+ $$type: 'animation-preset-props',
37
+ value: {
38
+ effect: createString( effect ),
39
+ type: createString( type ),
40
+ direction: createString( direction ),
41
+ timing_config: createTimingConfig( duration, delay ),
42
+ },
43
+ } );
44
+
45
+ export const createInteractionItem = (
46
+ trigger: string,
47
+ effect: string,
48
+ type: string,
49
+ direction: string,
50
+ duration: number,
51
+ delay: number,
52
+ interactionId?: string
53
+ ): InteractionItemPropValue => ( {
54
+ $$type: 'interaction-item',
55
+ value: {
56
+ ...( interactionId && { interaction_id: createString( interactionId ) } ),
57
+ trigger: createString( trigger ),
58
+ animation: createAnimationPreset( effect, type, direction, duration, delay ),
59
+ },
60
+ } );
61
+
62
+ export const createDefaultInteractionItem = (): InteractionItemPropValue => {
63
+ return createInteractionItem( 'load', 'fade', 'in', '', 300, 0 );
64
+ };
65
+
66
+ export const createDefaultInteractions = (): ElementInteractions => ( {
67
+ version: 1,
68
+ items: [ createDefaultInteractionItem() ],
69
+ } );
70
+
71
+ export const extractString = ( prop: StringPropValue | undefined, fallback = '' ): string => {
72
+ return prop?.value ?? fallback;
73
+ };
74
+
75
+ export const extractNumber = ( prop: NumberPropValue | undefined, fallback = 0 ): number => {
76
+ return prop?.value ?? fallback;
77
+ };
78
+
79
+ export const buildAnimationIdString = ( item: InteractionItemValue ): string => {
80
+ const trigger = extractString( item.trigger );
81
+ const effect = extractString( item.animation.value.effect );
82
+ const type = extractString( item.animation.value.type );
83
+ const direction = extractString( item.animation.value.direction );
84
+ const duration = extractNumber( item.animation.value.timing_config.value.duration );
85
+ const delay = extractNumber( item.animation.value.timing_config.value.delay );
86
+
87
+ return [ trigger, effect, type, direction, duration, delay ].join( '-' );
88
+ };
89
+
90
+ const TRIGGER_LABELS: Record< string, string > = {
91
+ load: 'On page load',
92
+ scrollIn: 'Scroll into view',
93
+ scrollOut: 'Scroll out of view',
94
+ };
95
+
96
+ const capitalize = ( str: string ): string => {
97
+ return str.charAt( 0 ).toUpperCase() + str.slice( 1 );
98
+ };
99
+
100
+ export const buildDisplayLabel = ( item: InteractionItemValue ): string => {
101
+ const trigger = extractString( item.trigger );
102
+ const effect = extractString( item.animation.value.effect );
103
+ const type = extractString( item.animation.value.type );
104
+
105
+ const triggerLabel = TRIGGER_LABELS[ trigger ] || capitalize( trigger );
106
+ const effectLabel = capitalize( effect );
107
+ const typeLabel = capitalize( type );
108
+
109
+ return `${ triggerLabel }: ${ effectLabel } ${ typeLabel }`;
110
+ };