@elementor/editor-props 0.15.0 → 0.18.0
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/CHANGELOG.md +26 -0
- package/dist/index.d.mts +3402 -85
- package/dist/index.d.ts +3402 -85
- package/dist/index.js +119 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/prop-types/filter-prop-types/backdrop-filter.ts +10 -0
- package/src/prop-types/filter-prop-types/contrast-filter.ts +8 -0
- package/src/prop-types/filter-prop-types/drop-shadow-filter.ts +8 -0
- package/src/prop-types/filter-prop-types/filter.ts +18 -1
- package/src/prop-types/filter-prop-types/grayscale-filter.ts +8 -0
- package/src/prop-types/filter-prop-types/hue-rotate-filter.ts +8 -0
- package/src/prop-types/filter-prop-types/invert-filter.ts +8 -0
- package/src/prop-types/filter-prop-types/saturate-filter.ts +8 -0
- package/src/prop-types/filter-prop-types/sepia-filter.ts +8 -0
- package/src/prop-types/index.ts +10 -0
- package/src/prop-types/size.ts +1 -1
- package/src/prop-types/transform-prop-types/move-transform.ts +15 -0
- package/src/prop-types/transform-prop-types/scale-transform.ts +13 -0
- package/src/prop-types/transform-prop-types/transform.ts +12 -0
- package/src/types.ts +3 -4
- package/src/utils/prop-dependency-utils.ts +41 -25
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { type Dependency, type DependencyTerm, type PropValue } from '../types';
|
|
1
|
+
import { type Dependency, type DependencyTerm, type PropValue, type TransformablePropValue } from '../types';
|
|
2
2
|
|
|
3
|
-
type ParsedTerm = DependencyTerm
|
|
3
|
+
type ParsedTerm = DependencyTerm;
|
|
4
4
|
|
|
5
5
|
type Relation = Dependency[ 'relation' ];
|
|
6
6
|
|
|
7
|
-
export function shouldApplyEffect( { relation, terms }: Dependency
|
|
7
|
+
export function shouldApplyEffect( { relation, terms }: Dependency, values: PropValue ): boolean {
|
|
8
8
|
if ( ! terms.length ) {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const method = getRelationMethod( relation );
|
|
13
13
|
|
|
14
|
-
return terms[ method ]( ( term: ParsedTerm | Dependency
|
|
15
|
-
isDependency( term ) ? shouldApplyEffect( term ) : evaluateTerm( term, term.
|
|
14
|
+
return terms[ method ]( ( term: ParsedTerm | Dependency ) =>
|
|
15
|
+
isDependency( term ) ? shouldApplyEffect( term, values ) : evaluateTerm( term, getValue( term.path, values ) )
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function evaluateTerm( term: DependencyTerm
|
|
19
|
+
export function evaluateTerm( term: DependencyTerm, actualValue: PropValue ) {
|
|
20
20
|
const { value: valueToCompare, operator } = term;
|
|
21
21
|
|
|
22
22
|
switch ( operator ) {
|
|
@@ -26,31 +26,37 @@ export function evaluateTerm( term: DependencyTerm< true >, actualValue: PropVal
|
|
|
26
26
|
|
|
27
27
|
case 'gt':
|
|
28
28
|
case 'lte':
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
29
|
+
if ( ! isNumber( actualValue ) || ! isNumber( valueToCompare ) ) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return Number( actualValue ) > Number( valueToCompare ) === ( 'gt' === operator );
|
|
34
34
|
|
|
35
35
|
case 'lt':
|
|
36
36
|
case 'gte':
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Number( actualValue ) < Number( valueToCompare ) === ( 'lt' === operator )
|
|
41
|
-
);
|
|
37
|
+
if ( ! isNumber( actualValue ) || ! isNumber( valueToCompare ) ) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
42
40
|
|
|
41
|
+
return Number( actualValue ) < Number( valueToCompare ) === ( 'lt' === operator );
|
|
43
42
|
case 'in':
|
|
44
43
|
case 'nin':
|
|
45
|
-
|
|
44
|
+
if ( ! Array.isArray( valueToCompare ) ) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return valueToCompare.includes( actualValue ) === ( 'in' === operator );
|
|
46
49
|
|
|
47
50
|
case 'contains':
|
|
48
51
|
case 'ncontains':
|
|
49
|
-
|
|
50
|
-
'string'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (
|
|
53
|
+
( 'string' !== typeof actualValue || 'string' !== typeof valueToCompare ) &&
|
|
54
|
+
! Array.isArray( actualValue )
|
|
55
|
+
) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return ( 'contains' === operator ) === actualValue.includes( valueToCompare as never );
|
|
54
60
|
|
|
55
61
|
case 'exists':
|
|
56
62
|
case 'not_exist':
|
|
@@ -63,6 +69,10 @@ export function evaluateTerm( term: DependencyTerm< true >, actualValue: PropVal
|
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
|
|
72
|
+
function isNumber( value: PropValue ): value is number {
|
|
73
|
+
return typeof value === 'number' && ! isNaN( value );
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
function getRelationMethod( relation: Relation ) {
|
|
67
77
|
switch ( relation ) {
|
|
68
78
|
case 'or':
|
|
@@ -76,8 +86,14 @@ function getRelationMethod( relation: Relation ) {
|
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
function getValue( path: string[], elementValues: PropValue ): PropValue | null {
|
|
90
|
+
return path.reduce( ( acc, key ) => {
|
|
91
|
+
return 'object' === typeof acc && acc !== null && key in acc
|
|
92
|
+
? ( ( acc[ key as keyof typeof acc ] as TransformablePropValue< string > )?.value as PropValue )
|
|
93
|
+
: null;
|
|
94
|
+
}, elementValues );
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isDependency( term: DependencyTerm | Dependency ): term is Dependency {
|
|
82
98
|
return 'relation' in term;
|
|
83
99
|
}
|