@elementor/editor-props 0.16.0 → 3.32.0-20
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 +11 -0
- package/dist/index.d.mts +10109 -1407
- package/dist/index.d.ts +10109 -1407
- package/dist/index.js +218 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +207 -108
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -1
- package/src/prop-types/filter-prop-types/backdrop-filter.ts +13 -0
- package/src/prop-types/filter-prop-types/drop-shadow-filter.ts +17 -0
- package/src/prop-types/filter-prop-types/filter.ts +13 -5
- package/src/prop-types/flex.ts +15 -0
- package/src/prop-types/index.ts +8 -2
- package/src/prop-types/selection-size.ts +16 -0
- package/src/prop-types/size.ts +12 -0
- package/src/prop-types/transform-prop-types/move-transform.ts +2 -1
- package/src/prop-types/transform-prop-types/rotate-transform.ts +16 -0
- package/src/prop-types/transform-prop-types/scale-transform.ts +8 -5
- package/src/prop-types/transform-prop-types/skew-transform.ts +15 -0
- package/src/prop-types/transform-prop-types/transform.ts +8 -1
- package/src/prop-types/transform-prop-types/types.ts +8 -0
- package/src/types.ts +1 -4
- package/src/utils/create-prop-utils.ts +3 -2
- package/src/utils/prop-dependency-utils.ts +35 -24
- package/src/prop-types/filter-prop-types/blur-filter.ts +0 -8
- package/src/prop-types/filter-prop-types/brightness-filter.ts +0 -8
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Dependency,
|
|
3
|
+
type DependencyTerm,
|
|
4
|
+
type PropKey,
|
|
5
|
+
type PropValue,
|
|
6
|
+
type TransformablePropValue,
|
|
7
|
+
} from '../types';
|
|
8
|
+
import { isTransformable } from './is-transformable';
|
|
2
9
|
|
|
3
10
|
type ParsedTerm = DependencyTerm;
|
|
4
11
|
|
|
5
12
|
type Relation = Dependency[ 'relation' ];
|
|
6
13
|
|
|
7
|
-
export function
|
|
8
|
-
if ( ! terms.length ) {
|
|
9
|
-
return
|
|
14
|
+
export function isDependencyMet( dependency: Dependency | undefined, values: PropValue ): boolean {
|
|
15
|
+
if ( ! dependency?.terms.length ) {
|
|
16
|
+
return true;
|
|
10
17
|
}
|
|
11
18
|
|
|
19
|
+
const { relation, terms } = dependency;
|
|
12
20
|
const method = getRelationMethod( relation );
|
|
13
21
|
|
|
14
22
|
return terms[ method ]( ( term: ParsedTerm | Dependency ) =>
|
|
15
|
-
isDependency( term )
|
|
23
|
+
isDependency( term )
|
|
24
|
+
? isDependencyMet( term, values )
|
|
25
|
+
: evaluateTerm( term, extractValue( term.path, values )?.value )
|
|
16
26
|
);
|
|
17
27
|
}
|
|
18
28
|
|
|
19
|
-
export function evaluateTerm( term: DependencyTerm, actualValue:
|
|
29
|
+
export function evaluateTerm( term: DependencyTerm, actualValue: unknown ) {
|
|
20
30
|
const { value: valueToCompare, operator } = term;
|
|
21
31
|
|
|
22
32
|
switch ( operator ) {
|
|
@@ -26,27 +36,26 @@ export function evaluateTerm( term: DependencyTerm, actualValue: PropValue ) {
|
|
|
26
36
|
|
|
27
37
|
case 'gt':
|
|
28
38
|
case 'lte':
|
|
29
|
-
if (
|
|
30
|
-
|
|
39
|
+
if ( ! isNumber( actualValue ) || ! isNumber( valueToCompare ) ) {
|
|
40
|
+
return false;
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
return Number( actualValue ) > Number( valueToCompare ) === ( 'gt' === operator );
|
|
34
44
|
|
|
35
45
|
case 'lt':
|
|
36
46
|
case 'gte':
|
|
37
|
-
if (
|
|
38
|
-
|
|
47
|
+
if ( ! isNumber( actualValue ) || ! isNumber( valueToCompare ) ) {
|
|
48
|
+
return false;
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
return Number( actualValue ) < Number( valueToCompare ) === ( 'lt' === operator );
|
|
42
|
-
|
|
43
52
|
case 'in':
|
|
44
53
|
case 'nin':
|
|
45
54
|
if ( ! Array.isArray( valueToCompare ) ) {
|
|
46
|
-
|
|
55
|
+
return false;
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
return valueToCompare.includes( actualValue ) === ( 'in' === operator );
|
|
58
|
+
return valueToCompare.includes( actualValue as never ) === ( 'in' === operator );
|
|
50
59
|
|
|
51
60
|
case 'contains':
|
|
52
61
|
case 'ncontains':
|
|
@@ -54,9 +63,7 @@ export function evaluateTerm( term: DependencyTerm, actualValue: PropValue ) {
|
|
|
54
63
|
( 'string' !== typeof actualValue || 'string' !== typeof valueToCompare ) &&
|
|
55
64
|
! Array.isArray( actualValue )
|
|
56
65
|
) {
|
|
57
|
-
|
|
58
|
-
'The "contains" and "ncontains" operators require a string or an array for comparison.'
|
|
59
|
-
);
|
|
66
|
+
return false;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
return ( 'contains' === operator ) === actualValue.includes( valueToCompare as never );
|
|
@@ -68,10 +75,14 @@ export function evaluateTerm( term: DependencyTerm, actualValue: PropValue ) {
|
|
|
68
75
|
return ( 'exists' === operator ) === evaluation;
|
|
69
76
|
|
|
70
77
|
default:
|
|
71
|
-
return
|
|
78
|
+
return true;
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
|
|
82
|
+
function isNumber( value: unknown ): value is number {
|
|
83
|
+
return typeof value === 'number' && ! isNaN( value );
|
|
84
|
+
}
|
|
85
|
+
|
|
75
86
|
function getRelationMethod( relation: Relation ) {
|
|
76
87
|
switch ( relation ) {
|
|
77
88
|
case 'or':
|
|
@@ -85,14 +96,14 @@ function getRelationMethod( relation: Relation ) {
|
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
function
|
|
89
|
-
return path.reduce( ( acc, key ) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}, elementValues )
|
|
99
|
+
export function extractValue( path: string[], elementValues: PropValue ): TransformablePropValue< PropKey > | null {
|
|
100
|
+
return path.reduce( ( acc, key, index ) => {
|
|
101
|
+
const value = acc?.[ key as keyof typeof acc ] as PropValue | null;
|
|
102
|
+
|
|
103
|
+
return index !== path.length - 1 && isTransformable( value ) ? value.value ?? null : value;
|
|
104
|
+
}, elementValues ) as TransformablePropValue< PropKey >;
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
function isDependency( term: DependencyTerm | Dependency ): term is Dependency {
|
|
107
|
+
export function isDependency( term: DependencyTerm | Dependency ): term is Dependency {
|
|
97
108
|
return 'relation' in term;
|
|
98
109
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type z } from '@elementor/schema';
|
|
2
|
-
|
|
3
|
-
import { createPropUtils } from '../../utils/create-prop-utils';
|
|
4
|
-
import { unknownChildrenSchema } from '../utils';
|
|
5
|
-
|
|
6
|
-
export const blurFilterPropTypeUtil = createPropUtils( 'blur', unknownChildrenSchema );
|
|
7
|
-
|
|
8
|
-
export type BlurFilterPropValue = z.infer< typeof blurFilterPropTypeUtil.schema >;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type z } from '@elementor/schema';
|
|
2
|
-
|
|
3
|
-
import { createPropUtils } from '../../utils/create-prop-utils';
|
|
4
|
-
import { unknownChildrenSchema } from '../utils';
|
|
5
|
-
|
|
6
|
-
export const brightnessFilterPropTypeUtil = createPropUtils( 'brightness', unknownChildrenSchema );
|
|
7
|
-
|
|
8
|
-
export type BrightnessFilterPropValue = z.infer< typeof brightnessFilterPropTypeUtil.schema >;
|