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

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 CHANGED
@@ -120,7 +120,7 @@ declare const registerVariableType: ({ key, icon, startIcon, valueField, propTyp
120
120
  styleTransformer?: _elementor_editor_canvas.AnyTransformer;
121
121
  fallbackPropTypeUtil: any;
122
122
  propTypeUtil: _elementor_editor_props.PropTypeUtil<string, string>;
123
- selectionFilter?: (variables: NormalizedVariable[], propType: _elementor_editor_props.PropType) => NormalizedVariable[];
123
+ selectionFilter?: (variables: NormalizedVariable[], propType?: _elementor_editor_props.PropType) => NormalizedVariable[];
124
124
  valueTransformer?: (value: string, type?: string) => _elementor_editor_props.PropValue;
125
125
  isCompatible?: (propType: _elementor_editor_props.PropType, variable: Variable) => boolean;
126
126
  emptyState?: react.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -120,7 +120,7 @@ declare const registerVariableType: ({ key, icon, startIcon, valueField, propTyp
120
120
  styleTransformer?: _elementor_editor_canvas.AnyTransformer;
121
121
  fallbackPropTypeUtil: any;
122
122
  propTypeUtil: _elementor_editor_props.PropTypeUtil<string, string>;
123
- selectionFilter?: (variables: NormalizedVariable[], propType: _elementor_editor_props.PropType) => NormalizedVariable[];
123
+ selectionFilter?: (variables: NormalizedVariable[], propType?: _elementor_editor_props.PropType) => NormalizedVariable[];
124
124
  valueTransformer?: (value: string, type?: string) => _elementor_editor_props.PropValue;
125
125
  isCompatible?: (propType: _elementor_editor_props.PropType, variable: Variable) => boolean;
126
126
  emptyState?: react.JSX.Element;
package/dist/index.js CHANGED
@@ -900,6 +900,26 @@ function filterBySearch(variables, searchValue) {
900
900
  return variables.filter((variable) => variable.label.toLowerCase().includes(lowerSearchValue));
901
901
  }
902
902
 
903
+ // src/utils/variables-to-list.ts
904
+ var variablesToList = (variables) => {
905
+ return Object.entries(variables).map(([key, variable]) => ({ key, ...variable }));
906
+ };
907
+ var toNormalizedVariable = ({ key, label, value, order }) => ({
908
+ key,
909
+ label,
910
+ value,
911
+ order
912
+ });
913
+ var applySelectionFilters = (variables, variableTypes) => {
914
+ const grouped = {};
915
+ variables.forEach((item) => (grouped[item.type] ??= []).push(item));
916
+ return Object.entries(grouped).flatMap(([type, vars]) => {
917
+ const filter = variableTypes[type]?.selectionFilter;
918
+ const normalized = vars.map(toNormalizedVariable);
919
+ return (filter?.(normalized) ?? normalized).map((v) => ({ ...v, type }));
920
+ });
921
+ };
922
+
903
923
  // src/hooks/use-prop-variables.ts
904
924
  var getVariables = (includeDeleted = true) => {
905
925
  const variables = service.variables();
@@ -956,12 +976,7 @@ var getMatchingTypes = (propKey) => {
956
976
  var normalizeVariables = (propKey) => {
957
977
  const variables = getVariables(false);
958
978
  const matchingTypes = getMatchingTypes(propKey);
959
- return Object.entries(variables).filter(([, variable]) => matchingTypes.includes(variable.type)).map(([key, { label, value, order }]) => ({
960
- key,
961
- label,
962
- value,
963
- order
964
- }));
979
+ return variablesToList(variables).filter((variable) => matchingTypes.includes(variable.type)).map(toNormalizedVariable);
965
980
  };
966
981
  var extractId = ({ id: id2 }) => id2;
967
982
  var createVariable = (newVariable) => {
@@ -1025,11 +1040,12 @@ var useVariablesManagerState = () => {
1025
1040
  }
1026
1041
  return { success: result.success };
1027
1042
  }, [variables]);
1028
- const filteredVariables = () => {
1029
- const list = Object.entries(variables).map(([id2, value]) => ({ ...value, id: id2 }));
1030
- const filtered = filterBySearch(list, searchValue);
1031
- return Object.fromEntries(filtered.map(({ id: id2, ...rest }) => [id2, rest]));
1032
- };
1043
+ const filteredVariables = (0, import_react5.useCallback)(() => {
1044
+ const list = variablesToList(variables).filter((v) => !v.deleted);
1045
+ const typeFiltered = applySelectionFilters(list, getVariableTypes());
1046
+ const searchFiltered = filterBySearch(typeFiltered, searchValue);
1047
+ return Object.fromEntries(searchFiltered.map(({ key, ...rest }) => [key, rest]));
1048
+ }, [variables, searchValue]);
1033
1049
  return {
1034
1050
  variables: filteredVariables(),
1035
1051
  deletedVariables,
@@ -1513,7 +1529,7 @@ var VariablesManagerTable = ({
1513
1529
  }
1514
1530
  };
1515
1531
  const ids = Object.keys(variables).sort(sortVariablesOrder(variables));
1516
- const rows = ids.filter((id2) => !variables[id2].deleted).map((id2) => {
1532
+ const rows = ids.map((id2) => {
1517
1533
  const variable = variables[id2];
1518
1534
  const variableType = getVariableType(variable.type);
1519
1535
  if (!variableType) {
@@ -1851,7 +1867,7 @@ function VariablesManagerPanel() {
1851
1867
  }
1852
1868
  }
1853
1869
  ];
1854
- const hasVariables = Object.values(variables).some((variable) => !variable.deleted);
1870
+ const hasVariables = Object.keys(variables).length > 0;
1855
1871
  return /* @__PURE__ */ React12.createElement(import_editor_ui5.ThemeProvider, null, /* @__PURE__ */ React12.createElement(import_editor_panels.Panel, null, /* @__PURE__ */ React12.createElement(
1856
1872
  import_editor_panels.PanelHeader,
1857
1873
  {