@elementor/editor-variables 4.0.0-609 → 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.js CHANGED
@@ -1248,7 +1248,7 @@ var MenuOption = ({
1248
1248
  promotionRef.current?.toggle();
1249
1249
  return;
1250
1250
  }
1251
- const defaultName = getDefaultName(variables, config.key, config.variableType);
1251
+ const defaultName = getDefaultName(variables, config.variableType);
1252
1252
  onCreate(config.key, defaultName, config.defaultValue);
1253
1253
  trackVariablesManagerEvent({ action: "add", varType: config.variableType });
1254
1254
  onClose();
@@ -1262,15 +1262,15 @@ var MenuOption = ({
1262
1262
  }
1263
1263
  ));
1264
1264
  };
1265
- var getDefaultName = (variables, type, baseName) => {
1266
- const existingNames = Object.values(variables).filter((variable) => variable.type === type).map((variable) => variable.label);
1265
+ var getDefaultName = (variables, baseName) => {
1266
+ const pattern = new RegExp(`^${baseName}-(\\d+)$`, "i");
1267
1267
  let counter = 1;
1268
- let name = `${baseName}-${counter}`;
1269
- while (existingNames.includes(name)) {
1270
- counter++;
1271
- name = `${baseName}-${counter}`;
1272
- }
1273
- return name;
1268
+ Object.values(variables).forEach((variable) => {
1269
+ if (pattern.test(variable.label)) {
1270
+ counter = Math.max(counter, parseInt(variable.label.match(pattern)?.[1] ?? "0", 10) + 1);
1271
+ }
1272
+ });
1273
+ return `${baseName}-${counter}`;
1274
1274
  };
1275
1275
 
1276
1276
  // src/components/variables-manager/variables-manager-table.tsx