@elementor/editor-variables 4.0.0-607 → 4.0.0-619

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.mjs CHANGED
@@ -1224,7 +1224,7 @@ var MenuOption = ({
1224
1224
  promotionRef.current?.toggle();
1225
1225
  return;
1226
1226
  }
1227
- const defaultName = getDefaultName(variables, config.key, config.variableType);
1227
+ const defaultName = getDefaultName(variables, config.variableType);
1228
1228
  onCreate(config.key, defaultName, config.defaultValue);
1229
1229
  trackVariablesManagerEvent({ action: "add", varType: config.variableType });
1230
1230
  onClose();
@@ -1238,15 +1238,15 @@ var MenuOption = ({
1238
1238
  }
1239
1239
  ));
1240
1240
  };
1241
- var getDefaultName = (variables, type, baseName) => {
1242
- const existingNames = Object.values(variables).filter((variable) => variable.type === type).map((variable) => variable.label);
1241
+ var getDefaultName = (variables, baseName) => {
1242
+ const pattern = new RegExp(`^${baseName}-(\\d+)$`, "i");
1243
1243
  let counter = 1;
1244
- let name = `${baseName}-${counter}`;
1245
- while (existingNames.includes(name)) {
1246
- counter++;
1247
- name = `${baseName}-${counter}`;
1248
- }
1249
- return name;
1244
+ Object.values(variables).forEach((variable) => {
1245
+ if (pattern.test(variable.label)) {
1246
+ counter = Math.max(counter, parseInt(variable.label.match(pattern)?.[1] ?? "0", 10) + 1);
1247
+ }
1248
+ });
1249
+ return `${baseName}-${counter}`;
1250
1250
  };
1251
1251
 
1252
1252
  // src/components/variables-manager/variables-manager-table.tsx