@elementor/editor-variables 3.35.0-443 → 3.35.0-444

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-variables",
3
- "version": "3.35.0-443",
3
+ "version": "3.35.0-444",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,22 +39,22 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "3.35.0-443",
43
- "@elementor/editor-canvas": "3.35.0-443",
44
- "@elementor/editor-controls": "3.35.0-443",
45
- "@elementor/editor-current-user": "3.35.0-443",
46
- "@elementor/editor-editing-panel": "3.35.0-443",
47
- "@elementor/editor-mcp": "3.35.0-443",
48
- "@elementor/editor-panels": "3.35.0-443",
49
- "@elementor/editor-props": "3.35.0-443",
50
- "@elementor/editor-ui": "3.35.0-443",
51
- "@elementor/editor-v1-adapters": "3.35.0-443",
52
- "@elementor/http-client": "3.35.0-443",
42
+ "@elementor/editor": "3.35.0-444",
43
+ "@elementor/editor-canvas": "3.35.0-444",
44
+ "@elementor/editor-controls": "3.35.0-444",
45
+ "@elementor/editor-current-user": "3.35.0-444",
46
+ "@elementor/editor-editing-panel": "3.35.0-444",
47
+ "@elementor/editor-mcp": "3.35.0-444",
48
+ "@elementor/editor-panels": "3.35.0-444",
49
+ "@elementor/editor-props": "3.35.0-444",
50
+ "@elementor/editor-ui": "3.35.0-444",
51
+ "@elementor/editor-v1-adapters": "3.35.0-444",
52
+ "@elementor/http-client": "3.35.0-444",
53
53
  "@elementor/icons": "^1.63.0",
54
- "@elementor/mixpanel": "3.35.0-443",
55
- "@elementor/schema": "3.35.0-443",
54
+ "@elementor/mixpanel": "3.35.0-444",
55
+ "@elementor/schema": "3.35.0-444",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "3.35.0-443",
57
+ "@elementor/utils": "3.35.0-444",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -5,6 +5,8 @@ import { getVariables } from '../../../hooks/use-prop-variables';
5
5
  import { service } from '../../../service';
6
6
  import { type TVariablesList } from '../../../storage';
7
7
  import { filterBySearch } from '../../../utils/filter-by-search';
8
+ import { applySelectionFilters, variablesToList } from '../../../utils/variables-to-list';
9
+ import { getVariableTypes } from '../../../variables-registry/variable-type-registry';
8
10
 
9
11
  export const useVariablesManagerState = () => {
10
12
  const [ variables, setVariables ] = useState( () => getVariables( false ) );
@@ -64,12 +66,13 @@ export const useVariablesManagerState = () => {
64
66
  return { success: result.success };
65
67
  }, [ variables ] );
66
68
 
67
- const filteredVariables = () => {
68
- const list = Object.entries( variables ).map( ( [ id, value ] ) => ( { ...value, id } ) );
69
- const filtered = filterBySearch( list, searchValue );
69
+ const filteredVariables = useCallback( () => {
70
+ const list = variablesToList( variables ).filter( ( v ) => ! v.deleted );
71
+ const typeFiltered = applySelectionFilters( list, getVariableTypes() );
72
+ const searchFiltered = filterBySearch( typeFiltered, searchValue );
70
73
 
71
- return Object.fromEntries( filtered.map( ( { id, ...rest } ) => [ id, rest ] ) );
72
- };
74
+ return Object.fromEntries( searchFiltered.map( ( { key, ...rest } ) => [ key, rest ] ) );
75
+ }, [ variables, searchValue ] );
73
76
 
74
77
  return {
75
78
  variables: filteredVariables(),
@@ -156,7 +156,7 @@ export function VariablesManagerPanel() {
156
156
  },
157
157
  ];
158
158
 
159
- const hasVariables = Object.values( variables ).some( ( variable ) => ! variable.deleted );
159
+ const hasVariables = Object.keys( variables ).length > 0;
160
160
 
161
161
  return (
162
162
  <ThemeProvider>
@@ -76,7 +76,6 @@ export const VariablesManagerTable = ( {
76
76
 
77
77
  const ids = Object.keys( variables ).sort( sortVariablesOrder( variables ) );
78
78
  const rows = ids
79
- .filter( ( id ) => ! variables[ id ].deleted )
80
79
  .map( ( id ) => {
81
80
  const variable = variables[ id ];
82
81
  const variableType = getVariableType( variable.type );
@@ -6,6 +6,7 @@ import { useVariableType } from '../context/variable-type-context';
6
6
  import { service } from '../service';
7
7
  import { type NormalizedVariable, type Variable } from '../types';
8
8
  import { filterBySearch } from '../utils/filter-by-search';
9
+ import { toNormalizedVariable, variablesToList } from '../utils/variables-to-list';
9
10
  import { getVariableType, getVariableTypes } from '../variables-registry/variable-type-registry';
10
11
 
11
12
  export const getVariables = ( includeDeleted = true ) => {
@@ -75,18 +76,13 @@ const getMatchingTypes = ( propKey: string ): string[] => {
75
76
  return matchingTypes;
76
77
  };
77
78
 
78
- const normalizeVariables = ( propKey: string ) => {
79
+ const normalizeVariables = ( propKey: string ): NormalizedVariable[] => {
79
80
  const variables = getVariables( false );
80
81
  const matchingTypes = getMatchingTypes( propKey );
81
82
 
82
- return Object.entries( variables )
83
- .filter( ( [ , variable ] ) => matchingTypes.includes( variable.type ) )
84
- .map( ( [ key, { label, value, order } ] ) => ( {
85
- key,
86
- label,
87
- value,
88
- order,
89
- } ) );
83
+ return variablesToList( variables )
84
+ .filter( ( variable ) => matchingTypes.includes( variable.type ) )
85
+ .map( toNormalizedVariable );
90
86
  };
91
87
 
92
88
  const extractId = ( { id }: { id: string } ): string => id;
@@ -0,0 +1,33 @@
1
+ import { type TVariable, type TVariablesList } from '../storage';
2
+ import { type NormalizedVariable } from '../types';
3
+ import { type VariableTypesMap } from '../variables-registry/create-variable-type-registry';
4
+
5
+ export type VariableWithKey = TVariable & { key: string };
6
+
7
+ export const variablesToList = ( variables: TVariablesList ): VariableWithKey[] => {
8
+ return Object.entries( variables ).map( ( [ key, variable ] ) => ( { key, ...variable } ) );
9
+ };
10
+
11
+ export const toNormalizedVariable = ( { key, label, value, order }: VariableWithKey ): NormalizedVariable => ( {
12
+ key,
13
+ label,
14
+ value,
15
+ order,
16
+ } );
17
+
18
+ type VariableWithType = NormalizedVariable & { type: string };
19
+
20
+ export const applySelectionFilters = (
21
+ variables: VariableWithKey[],
22
+ variableTypes: VariableTypesMap
23
+ ): VariableWithType[] => {
24
+ const grouped: Record< string, VariableWithKey[] > = {};
25
+ variables.forEach( ( item ) => ( grouped[ item.type ] ??= [] ).push( item ) );
26
+
27
+ return Object.entries( grouped ).flatMap( ( [ type, vars ] ) => {
28
+ const filter = variableTypes[ type ]?.selectionFilter;
29
+ const normalized = vars.map( toNormalizedVariable );
30
+
31
+ return ( filter?.( normalized ) ?? normalized ).map( ( v ) => ( { ...v, type } ) );
32
+ } );
33
+ };
@@ -44,7 +44,7 @@ type VariableTypeOptions = {
44
44
  styleTransformer?: AnyTransformer;
45
45
  fallbackPropTypeUtil: FallbackPropTypeUtil;
46
46
  propTypeUtil: PropTypeUtil< string, string >;
47
- selectionFilter?: ( variables: NormalizedVariable[], propType: PropType ) => NormalizedVariable[];
47
+ selectionFilter?: ( variables: NormalizedVariable[], propType?: PropType ) => NormalizedVariable[];
48
48
  valueTransformer?: ( value: string, type?: string ) => PropValue;
49
49
  isCompatible?: ( propType: PropType, variable: Variable ) => boolean;
50
50
  emptyState?: JSX.Element;