@elementor/editor-variables 3.33.0-137 → 3.33.0-138

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
@@ -17,6 +17,7 @@ type NormalizedVariable = {
17
17
  key: string;
18
18
  label: string;
19
19
  value: string;
20
+ order?: number;
20
21
  };
21
22
 
22
23
  type ValueFieldProps = {
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ type NormalizedVariable = {
17
17
  key: string;
18
18
  label: string;
19
19
  value: string;
20
+ order?: number;
20
21
  };
21
22
 
22
23
  type ValueFieldProps = {
package/dist/index.js CHANGED
@@ -81,13 +81,14 @@ var buildOperationsArray = (originalVariables, currentVariables) => {
81
81
  ...original.label !== variable.label && { label: variable.label },
82
82
  ...original.value !== variable.value && { value: variable.value }
83
83
  });
84
- } else if (!variable.deleted && (original.label !== variable.label || original.value !== variable.value)) {
84
+ } else if (!variable.deleted && (original.label !== variable.label || original.value !== variable.value || original.order !== variable.order)) {
85
85
  operations.push({
86
86
  type: "update",
87
87
  id: id2,
88
88
  variable: {
89
89
  ...original.label !== variable.label && { label: variable.label },
90
- ...original.value !== variable.value && { value: variable.value }
90
+ ...original.value !== variable.value && { value: variable.value },
91
+ ...original.order !== variable.order && { order: variable.order }
91
92
  }
92
93
  });
93
94
  }
@@ -623,8 +624,13 @@ var useFilteredVariables = (searchValue, propTypeKey) => {
623
624
  const baseVariables = usePropVariables(propTypeKey);
624
625
  const typeFilteredVariables = useVariableSelectionFilter(baseVariables);
625
626
  const searchFilteredVariables = filterVariablesBySearchValue(typeFilteredVariables, searchValue);
627
+ const sortedVariables = searchFilteredVariables.sort((a, b) => {
628
+ const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
629
+ const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
630
+ return orderA - orderB;
631
+ });
626
632
  return {
627
- list: searchFilteredVariables,
633
+ list: sortedVariables,
628
634
  hasMatches: searchFilteredVariables.length > 0,
629
635
  isSourceNotEmpty: typeFilteredVariables.length > 0,
630
636
  hasNoCompatibleVariables: baseVariables.length > 0 && typeFilteredVariables.length === 0
@@ -644,10 +650,11 @@ var usePropVariables = (propKey) => {
644
650
  };
645
651
  var normalizeVariables = (propKey) => {
646
652
  const variables = getVariables(false);
647
- return Object.entries(variables).filter(([, variable]) => variable.type === propKey).map(([key, { label, value }]) => ({
653
+ return Object.entries(variables).filter(([, variable]) => variable.type === propKey).map(([key, { label, value, order }]) => ({
648
654
  key,
649
655
  label,
650
- value
656
+ value,
657
+ order
651
658
  }));
652
659
  };
653
660
  var extractId = ({ id: id2 }) => id2;
@@ -1078,7 +1085,13 @@ var VariablesManagerTable = ({
1078
1085
  variableRowRefs.current.delete(id2);
1079
1086
  }
1080
1087
  };
1081
- const rows = ids.filter((id2) => !variables[id2].deleted).map((id2) => {
1088
+ (0, import_react7.useEffect)(() => {
1089
+ const sortedIds = [...ids].sort(sortVariablesOrder(variables));
1090
+ if (JSON.stringify(sortedIds) !== JSON.stringify(ids)) {
1091
+ setIds(sortedIds);
1092
+ }
1093
+ }, [ids, variables, setIds]);
1094
+ const rows = ids.filter((id2) => !variables[id2].deleted).sort(sortVariablesOrder(variables)).map((id2) => {
1082
1095
  const variable = variables[id2];
1083
1096
  const variableType = getVariableType(variable.type);
1084
1097
  return {
@@ -1097,7 +1110,19 @@ var VariablesManagerTable = ({
1097
1110
  import_ui9.UnstableSortableProvider,
1098
1111
  {
1099
1112
  value: ids,
1100
- onChange: setIds,
1113
+ onChange: (newIds) => {
1114
+ const updatedVariables = { ...variables };
1115
+ newIds.forEach((id2, index) => {
1116
+ if (updatedVariables[id2]) {
1117
+ updatedVariables[id2] = {
1118
+ ...updatedVariables[id2],
1119
+ order: index + 1
1120
+ };
1121
+ }
1122
+ });
1123
+ handleOnChange(updatedVariables);
1124
+ setIds(newIds);
1125
+ },
1101
1126
  variant: "static",
1102
1127
  restrictAxis: true,
1103
1128
  dragOverlay: ({ children: dragOverlayChildren, ...dragOverlayProps }) => /* @__PURE__ */ React9.createElement(import_ui9.Table, { sx: tableSX, ...dragOverlayProps }, /* @__PURE__ */ React9.createElement(import_ui9.TableBody, null, dragOverlayChildren))
@@ -1247,6 +1272,13 @@ var VariablesManagerTable = ({
1247
1272
  ))
1248
1273
  ))));
1249
1274
  };
1275
+ function sortVariablesOrder(variables) {
1276
+ return (a, b) => {
1277
+ const orderA = variables[a]?.order ?? Number.MAX_SAFE_INTEGER;
1278
+ const orderB = variables[b]?.order ?? Number.MAX_SAFE_INTEGER;
1279
+ return orderA - orderB;
1280
+ };
1281
+ }
1250
1282
 
1251
1283
  // src/components/variables-manager/variables-manager-panel.tsx
1252
1284
  var id = "variables-manager";