@elementor/editor-variables 3.32.0-25 → 3.32.0-26
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.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +51 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/hooks/use-prop-variables.ts +35 -25
- package/src/types.ts +6 -0
- package/src/variables-registry/create-variable-type-registry.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-variables",
|
|
3
|
-
"version": "3.32.0-
|
|
3
|
+
"version": "3.32.0-26",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "3.32.0-
|
|
43
|
-
"@elementor/editor-canvas": "3.32.0-
|
|
44
|
-
"@elementor/editor-controls": "3.32.0-
|
|
45
|
-
"@elementor/editor-current-user": "3.32.0-
|
|
46
|
-
"@elementor/editor-editing-panel": "3.32.0-
|
|
47
|
-
"@elementor/editor-panels": "3.32.0-
|
|
48
|
-
"@elementor/editor-props": "3.32.0-
|
|
49
|
-
"@elementor/editor-ui": "3.32.0-
|
|
50
|
-
"@elementor/editor-v1-adapters": "3.32.0-
|
|
51
|
-
"@elementor/http-client": "3.32.0-
|
|
42
|
+
"@elementor/editor": "3.32.0-26",
|
|
43
|
+
"@elementor/editor-canvas": "3.32.0-26",
|
|
44
|
+
"@elementor/editor-controls": "3.32.0-26",
|
|
45
|
+
"@elementor/editor-current-user": "3.32.0-26",
|
|
46
|
+
"@elementor/editor-editing-panel": "3.32.0-26",
|
|
47
|
+
"@elementor/editor-panels": "3.32.0-26",
|
|
48
|
+
"@elementor/editor-props": "3.32.0-26",
|
|
49
|
+
"@elementor/editor-ui": "3.32.0-26",
|
|
50
|
+
"@elementor/editor-v1-adapters": "3.32.0-26",
|
|
51
|
+
"@elementor/http-client": "3.32.0-26",
|
|
52
52
|
"@elementor/icons": "1.46.0",
|
|
53
|
-
"@elementor/schema": "3.32.0-
|
|
53
|
+
"@elementor/schema": "3.32.0-26",
|
|
54
54
|
"@elementor/ui": "1.36.2",
|
|
55
55
|
"@wordpress/i18n": "^5.13.0"
|
|
56
56
|
},
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
+
import { useBoundProp } from '@elementor/editor-controls';
|
|
2
3
|
import { type PropKey } from '@elementor/editor-props';
|
|
3
4
|
|
|
5
|
+
import { useVariableType } from '../context/variable-type-context';
|
|
4
6
|
import { service } from '../service';
|
|
5
|
-
import { type Variable } from '../types';
|
|
7
|
+
import { type NormalizedVariable, type Variable } from '../types';
|
|
6
8
|
|
|
7
9
|
export const useVariable = ( key: string ) => {
|
|
8
10
|
const variables = service.variables();
|
|
@@ -18,26 +20,37 @@ export const useVariable = ( key: string ) => {
|
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const useFilteredVariables = ( searchValue: string, propTypeKey: string ) => {
|
|
21
|
-
const
|
|
23
|
+
const baseVariables = usePropVariables( propTypeKey );
|
|
22
24
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
} );
|
|
25
|
+
const typeFilteredVariables = useVariableSelectionFilter( baseVariables );
|
|
26
|
+
const searchFilteredVariables = filterVariablesBySearchValue( typeFilteredVariables, searchValue );
|
|
26
27
|
|
|
27
28
|
return {
|
|
28
|
-
list:
|
|
29
|
-
hasMatches:
|
|
30
|
-
isSourceNotEmpty:
|
|
29
|
+
list: searchFilteredVariables,
|
|
30
|
+
hasMatches: searchFilteredVariables.length > 0,
|
|
31
|
+
isSourceNotEmpty: typeFilteredVariables.length > 0,
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const useVariableSelectionFilter = ( variables: NormalizedVariable[] ): NormalizedVariable[] => {
|
|
36
|
+
const { selectionFilter } = useVariableType();
|
|
37
|
+
const { propType } = useBoundProp();
|
|
38
|
+
|
|
39
|
+
return selectionFilter ? selectionFilter( variables, propType ) : variables;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const filterVariablesBySearchValue = ( variables: NormalizedVariable[], searchValue: string ): NormalizedVariable[] => {
|
|
43
|
+
const lowerSearchValue = searchValue.toLowerCase();
|
|
44
|
+
return variables.filter( ( { label } ) => label.toLowerCase().includes( lowerSearchValue ) );
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const usePropVariables = ( propKey: PropKey ): NormalizedVariable[] => {
|
|
35
48
|
return useMemo( () => normalizeVariables( propKey ), [ propKey ] );
|
|
36
49
|
};
|
|
37
50
|
|
|
38
51
|
const isNotDeleted = ( { deleted }: { deleted?: boolean } ) => ! deleted;
|
|
39
52
|
|
|
40
|
-
const normalizeVariables = ( propKey: string ) => {
|
|
53
|
+
const normalizeVariables = ( propKey: string ): NormalizedVariable[] => {
|
|
41
54
|
const variables = service.variables();
|
|
42
55
|
|
|
43
56
|
return Object.entries( variables )
|
|
@@ -49,26 +62,23 @@ const normalizeVariables = ( propKey: string ) => {
|
|
|
49
62
|
} ) );
|
|
50
63
|
};
|
|
51
64
|
|
|
65
|
+
const extractId = ( { id }: { id: string } ): string => id;
|
|
66
|
+
|
|
52
67
|
export const createVariable = ( newVariable: Variable ): Promise< string > => {
|
|
53
|
-
return service.create( newVariable ).then(
|
|
54
|
-
return id;
|
|
55
|
-
} );
|
|
68
|
+
return service.create( newVariable ).then( extractId );
|
|
56
69
|
};
|
|
57
70
|
|
|
58
|
-
export const updateVariable = (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
export const updateVariable = (
|
|
72
|
+
updateId: string,
|
|
73
|
+
{ value, label }: { value: string; label: string }
|
|
74
|
+
): Promise< string > => {
|
|
75
|
+
return service.update( updateId, { value, label } ).then( extractId );
|
|
62
76
|
};
|
|
63
77
|
|
|
64
|
-
export const deleteVariable = ( deleteId: string ) => {
|
|
65
|
-
return service.delete( deleteId ).then(
|
|
66
|
-
return id;
|
|
67
|
-
} );
|
|
78
|
+
export const deleteVariable = ( deleteId: string ): Promise< string > => {
|
|
79
|
+
return service.delete( deleteId ).then( extractId );
|
|
68
80
|
};
|
|
69
81
|
|
|
70
|
-
export const restoreVariable = ( restoreId: string, label?: string, value?: string ) => {
|
|
71
|
-
return service.restore( restoreId, label, value ).then(
|
|
72
|
-
return id;
|
|
73
|
-
} );
|
|
82
|
+
export const restoreVariable = ( restoreId: string, label?: string, value?: string ): Promise< string > => {
|
|
83
|
+
return service.restore( restoreId, label, value ).then( extractId );
|
|
74
84
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type ForwardRefExoticComponent, type JSX, type RefAttributes } from 'react';
|
|
2
2
|
import { styleTransformersRegistry } from '@elementor/editor-canvas';
|
|
3
3
|
import { stylesInheritanceTransformersRegistry } from '@elementor/editor-editing-panel';
|
|
4
|
-
import { type createPropUtils, type PropTypeKey, type PropTypeUtil } from '@elementor/editor-props';
|
|
4
|
+
import { type createPropUtils, type PropType, type PropTypeKey, type PropTypeUtil } from '@elementor/editor-props';
|
|
5
5
|
import { type SvgIconProps } from '@elementor/ui';
|
|
6
6
|
|
|
7
7
|
import { inheritanceTransformer } from '../transformers/inheritance-transformer';
|
|
8
8
|
import { variableTransformer } from '../transformers/variable-transformer';
|
|
9
|
+
import { type NormalizedVariable } from '../types';
|
|
9
10
|
|
|
10
11
|
type ValueFieldProps = {
|
|
11
12
|
value: string;
|
|
@@ -21,6 +22,7 @@ type VariableTypeOptions = {
|
|
|
21
22
|
variableType: string;
|
|
22
23
|
fallbackPropTypeUtil: FallbackPropTypeUtil;
|
|
23
24
|
propTypeUtil: PropTypeUtil< string, string >;
|
|
25
|
+
selectionFilter?: ( variables: NormalizedVariable[], propType: PropType ) => NormalizedVariable[];
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export type VariableTypesMap = Record< string, VariableTypeOptions >;
|
|
@@ -34,6 +36,7 @@ export function createVariableTypeRegistry() {
|
|
|
34
36
|
valueField,
|
|
35
37
|
propTypeUtil,
|
|
36
38
|
variableType,
|
|
39
|
+
selectionFilter,
|
|
37
40
|
fallbackPropTypeUtil,
|
|
38
41
|
}: VariableTypeOptions ) => {
|
|
39
42
|
if ( variableTypes[ propTypeUtil.key ] ) {
|
|
@@ -46,6 +49,7 @@ export function createVariableTypeRegistry() {
|
|
|
46
49
|
valueField,
|
|
47
50
|
propTypeUtil,
|
|
48
51
|
variableType,
|
|
52
|
+
selectionFilter,
|
|
49
53
|
fallbackPropTypeUtil,
|
|
50
54
|
};
|
|
51
55
|
|