@elementor/editor-variables 4.0.0-609 → 4.0.0-621
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.
|
|
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,
|
|
1266
|
-
const
|
|
1265
|
+
var getDefaultName = (variables, baseName) => {
|
|
1266
|
+
const pattern = new RegExp(`^${baseName}-(\\d+)$`, "i");
|
|
1267
1267
|
let counter = 1;
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
}
|
|
1273
|
-
return
|
|
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
|