@elementor/editor-interactions 4.1.0-712 → 4.1.0-713

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.1.0-712",
3
+ "version": "4.1.0-713",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,19 +39,19 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor-controls": "4.1.0-712",
43
- "@elementor/editor-elements": "4.1.0-712",
44
- "@elementor/editor-mcp": "4.1.0-712",
45
- "@elementor/editor-props": "4.1.0-712",
46
- "@elementor/editor-responsive": "4.1.0-712",
47
- "@elementor/editor-ui": "4.1.0-712",
48
- "@elementor/editor-v1-adapters": "4.1.0-712",
42
+ "@elementor/editor-controls": "4.1.0-713",
43
+ "@elementor/editor-elements": "4.1.0-713",
44
+ "@elementor/editor-mcp": "4.1.0-713",
45
+ "@elementor/editor-props": "4.1.0-713",
46
+ "@elementor/editor-responsive": "4.1.0-713",
47
+ "@elementor/editor-ui": "4.1.0-713",
48
+ "@elementor/editor-v1-adapters": "4.1.0-713",
49
49
  "@elementor/icons": "^1.68.0",
50
- "@elementor/schema": "4.1.0-712",
51
- "@elementor/session": "4.1.0-712",
50
+ "@elementor/schema": "4.1.0-713",
51
+ "@elementor/session": "4.1.0-713",
52
52
  "@elementor/ui": "1.36.17",
53
- "@elementor/utils": "4.1.0-712",
54
- "@elementor/events": "4.1.0-712",
53
+ "@elementor/utils": "4.1.0-713",
54
+ "@elementor/events": "4.1.0-713",
55
55
  "@wordpress/i18n": "^5.13.0"
56
56
  },
57
57
  "peerDependencies": {
@@ -1,48 +1,100 @@
1
1
  import * as React from 'react';
2
2
  import { useMemo } from 'react';
3
- import { type ToggleButtonGroupItem, ToggleButtonGroupUi } from '@elementor/editor-controls';
3
+ import { StyledToggleButton, StyledToggleButtonGroup } from '@elementor/editor-controls';
4
4
  import { ArrowDownSmallIcon, ArrowLeftIcon, ArrowRightIcon, ArrowUpSmallIcon } from '@elementor/icons';
5
+ import { Tooltip } from '@elementor/ui';
5
6
  import { __ } from '@wordpress/i18n';
6
7
 
7
8
  import { type DirectionFieldProps } from '../../types';
8
9
 
9
10
  type Direction = 'top' | 'bottom' | 'left' | 'right';
10
11
 
12
+ const AXIS: Record< Direction, 'vertical' | 'horizontal' > = {
13
+ top: 'vertical',
14
+ bottom: 'vertical',
15
+ left: 'horizontal',
16
+ right: 'horizontal',
17
+ };
18
+
19
+ function parseValue( value: string ): Direction[] {
20
+ return value.split( '-' ).filter( Boolean ) as Direction[];
21
+ }
22
+
23
+ function serializeValue( directions: Direction[] ): string {
24
+ const vertical = directions.find( ( d ) => d === 'top' || d === 'bottom' );
25
+ const horizontal = directions.find( ( d ) => d === 'left' || d === 'right' );
26
+ if ( vertical && horizontal ) {
27
+ return `${ vertical }-${ horizontal }`;
28
+ }
29
+ return directions[ 0 ] ?? '';
30
+ }
31
+
32
+ function toggleDirection( current: Direction[], clicked: Direction ): Direction[] {
33
+ if ( current.includes( clicked ) ) {
34
+ return current.filter( ( d ) => d !== clicked );
35
+ }
36
+ const filtered = current.filter( ( d ) => AXIS[ d ] !== AXIS[ clicked ] );
37
+ return [ ...filtered, clicked ];
38
+ }
39
+
11
40
  export function Direction( { value, onChange, interactionType }: DirectionFieldProps ) {
12
- const options: ToggleButtonGroupItem< Direction >[] = useMemo( () => {
13
- const isIn = interactionType === 'in';
41
+ const isIn = interactionType === 'in';
14
42
 
15
- return [
43
+ const options = useMemo(
44
+ () => [
16
45
  {
17
- value: 'top',
46
+ dir: 'top' as Direction,
18
47
  label: isIn ? __( 'From top', 'elementor' ) : __( 'To top', 'elementor' ),
19
- renderContent: ( { size } ) =>
20
- isIn ? <ArrowDownSmallIcon fontSize={ size } /> : <ArrowUpSmallIcon fontSize={ size } />,
21
- showTooltip: true,
48
+ Icon: isIn ? ArrowDownSmallIcon : ArrowUpSmallIcon,
22
49
  },
23
50
  {
24
- value: 'bottom',
25
- label: interactionType === 'in' ? __( 'From bottom', 'elementor' ) : __( 'To bottom', 'elementor' ),
26
- renderContent: ( { size } ) =>
27
- isIn ? <ArrowUpSmallIcon fontSize={ size } /> : <ArrowDownSmallIcon fontSize={ size } />,
28
- showTooltip: true,
51
+ dir: 'bottom' as Direction,
52
+ label: isIn ? __( 'From bottom', 'elementor' ) : __( 'To bottom', 'elementor' ),
53
+ Icon: isIn ? ArrowUpSmallIcon : ArrowDownSmallIcon,
29
54
  },
30
55
  {
31
- value: 'left',
32
- label: interactionType === 'in' ? __( 'From left', 'elementor' ) : __( 'To left', 'elementor' ),
33
- renderContent: ( { size } ) =>
34
- isIn ? <ArrowRightIcon fontSize={ size } /> : <ArrowLeftIcon fontSize={ size } />,
35
- showTooltip: true,
56
+ dir: 'left' as Direction,
57
+ label: isIn ? __( 'From left', 'elementor' ) : __( 'To left', 'elementor' ),
58
+ Icon: isIn ? ArrowRightIcon : ArrowLeftIcon,
36
59
  },
37
60
  {
38
- value: 'right',
39
- label: interactionType === 'in' ? __( 'From right', 'elementor' ) : __( 'To right', 'elementor' ),
40
- renderContent: ( { size } ) =>
41
- isIn ? <ArrowLeftIcon fontSize={ size } /> : <ArrowRightIcon fontSize={ size } />,
42
- showTooltip: true,
61
+ dir: 'right' as Direction,
62
+ label: isIn ? __( 'From right', 'elementor' ) : __( 'To right', 'elementor' ),
63
+ Icon: isIn ? ArrowLeftIcon : ArrowRightIcon,
43
64
  },
44
- ];
45
- }, [ interactionType ] );
65
+ ],
66
+ [ isIn ]
67
+ );
68
+
69
+ const selectedDirections = useMemo( () => parseValue( value ), [ value ] );
46
70
 
47
- return <ToggleButtonGroupUi items={ options } exclusive onChange={ onChange } value={ value } />;
71
+ return (
72
+ <StyledToggleButtonGroup
73
+ size="tiny"
74
+ justify="end"
75
+ sx={ {
76
+ display: 'grid',
77
+ gridTemplateColumns: 'repeat(4, minmax(0, 25%))',
78
+ width: '100%',
79
+ } }
80
+ >
81
+ { options.map( ( { dir, label, Icon } ) => (
82
+ <Tooltip key={ dir } title={ label } disableFocusListener placement="top">
83
+ <StyledToggleButton
84
+ value={ dir }
85
+ selected={ selectedDirections.includes( dir ) }
86
+ aria-label={ label }
87
+ size="tiny"
88
+ isPlaceholder={ false }
89
+ onChange={ () => {
90
+ const next = toggleDirection( selectedDirections, dir );
91
+ onChange( serializeValue( next ) );
92
+ } }
93
+ >
94
+ <Icon fontSize="tiny" />
95
+ </StyledToggleButton>
96
+ </Tooltip>
97
+ ) ) }
98
+ </StyledToggleButtonGroup>
99
+ );
48
100
  }
@@ -5,9 +5,11 @@ export const baseSchema = {
5
5
  effect: z.enum( [ 'fade', 'slide', 'scale' ] ).optional().describe( 'Animation effect type' ),
6
6
  effectType: z.enum( [ 'in', 'out' ] ).optional().describe( 'Whether the animation plays in or out' ),
7
7
  direction: z
8
- .enum( [ 'top', 'bottom', 'left', 'right', '' ] )
8
+ .enum( [ 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right' ] )
9
9
  .optional()
10
- .describe( 'Direction for slide effect. Use empty string for fade/scale.' ),
10
+ .describe(
11
+ 'Direction of the Animation. Can be one of the following or empty if not needed. At slide effect, this is required field.'
12
+ ),
11
13
  duration: z.number().min( 0 ).max( 10000 ).optional().describe( 'Animation duration in milliseconds' ),
12
14
  delay: z.number().min( 0 ).max( 10000 ).optional().describe( 'Animation delay in milliseconds' ),
13
15
  easing: z.string().optional().describe( 'Easing function. See interactions schema for options.' ),