@elementor/editor-variables 3.35.0-362 → 3.35.0-363

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
@@ -203,17 +203,18 @@ var apiClient = {
203
203
  value
204
204
  });
205
205
  },
206
- update: (id2, label, value) => {
206
+ update: (id2, label, value, type) => {
207
207
  return httpService().put(BASE_PATH + "/update", {
208
208
  id: id2,
209
209
  label,
210
- value
210
+ value,
211
+ type
211
212
  });
212
213
  },
213
214
  delete: (id2) => {
214
215
  return httpService().post(BASE_PATH + "/delete", { id: id2 });
215
216
  },
216
- restore: (id2, label, value) => {
217
+ restore: (id2, label, value, type) => {
217
218
  const payload = { id: id2 };
218
219
  if (label) {
219
220
  payload.label = label;
@@ -221,6 +222,9 @@ var apiClient = {
221
222
  if (value) {
222
223
  payload.value = value;
223
224
  }
225
+ if (type) {
226
+ payload.type = type;
227
+ }
224
228
  return httpService().post(BASE_PATH + "/restore", payload);
225
229
  },
226
230
  batch: (payload) => {
@@ -486,8 +490,8 @@ var service = {
486
490
  };
487
491
  });
488
492
  },
489
- update: (id2, { label, value }) => {
490
- return apiClient.update(id2, label, value).then((response) => {
493
+ update: (id2, { label, value, type }) => {
494
+ return apiClient.update(id2, label, value, type).then((response) => {
491
495
  const { success, data: payload } = response.data;
492
496
  if (!success) {
493
497
  const errorMessage = payload?.message || __2("Unexpected response from server", "elementor");
@@ -529,8 +533,8 @@ var service = {
529
533
  };
530
534
  });
531
535
  },
532
- restore: (id2, label, value) => {
533
- return apiClient.restore(id2, label, value).then((response) => {
536
+ restore: (id2, label, value, type) => {
537
+ return apiClient.restore(id2, label, value, type).then((response) => {
534
538
  const { success, data: payload } = response.data;
535
539
  if (!success) {
536
540
  throw new Error("Unexpected response from server");
@@ -951,14 +955,14 @@ var extractId = ({ id: id2 }) => id2;
951
955
  var createVariable = (newVariable) => {
952
956
  return service.create(newVariable).then(extractId);
953
957
  };
954
- var updateVariable = (updateId, { value, label }) => {
955
- return service.update(updateId, { value, label }).then(extractId);
958
+ var updateVariable = (updateId, { value, label, type }) => {
959
+ return service.update(updateId, { value, label, type }).then(extractId);
956
960
  };
957
961
  var deleteVariable = (deleteId) => {
958
962
  return service.delete(deleteId).then(extractId);
959
963
  };
960
- var restoreVariable = (restoreId, label, value) => {
961
- return service.restore(restoreId, label, value).then(extractId);
964
+ var restoreVariable = (restoreId, label, value, type) => {
965
+ return service.restore(restoreId, label, value, type).then(extractId);
962
966
  };
963
967
 
964
968
  // src/components/variables-manager/hooks/use-variables-manager-state.ts
@@ -2256,7 +2260,7 @@ var EditConfirmationDialog = ({
2256
2260
  var SIZE3 = "tiny";
2257
2261
  var DELETE_LABEL = __12("Delete variable", "elementor");
2258
2262
  var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
2259
- const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
2263
+ const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
2260
2264
  const { setVariableValue: notifyBoundPropChange, variableId } = useVariableBoundProp();
2261
2265
  const { propType } = useBoundProp5();
2262
2266
  const [isMessageSuppressed, suppressMessage] = useSuppressedMessage(EDIT_CONFIRMATION_DIALOG_ID);
@@ -2266,6 +2270,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
2266
2270
  const [valueFieldError, setValueFieldError] = useState9("");
2267
2271
  const { labelFieldError, setLabelFieldError } = useLabelError();
2268
2272
  const variable = useVariable(editId);
2273
+ const [propTypeKey, setPropTypeKey] = useState9(variable?.type ?? propTypeUtil.key);
2269
2274
  if (!variable) {
2270
2275
  throw new Error(`Global ${variableType} variable not found`);
2271
2276
  }
@@ -2293,10 +2298,9 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
2293
2298
  }
2294
2299
  };
2295
2300
  const handleSaveVariable = () => {
2296
- updateVariable(editId, {
2297
- value,
2298
- label
2299
- }).then(() => {
2301
+ const typeChanged = propTypeKey !== variable.type;
2302
+ const updatePayload = typeChanged ? { value, label, type: propTypeKey } : { value, label };
2303
+ updateVariable(editId, updatePayload).then(() => {
2300
2304
  maybeTriggerBoundPropChange();
2301
2305
  onSubmit?.();
2302
2306
  }).catch((error) => {
@@ -2400,6 +2404,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
2400
2404
  ValueField,
2401
2405
  {
2402
2406
  propTypeKey: variable.type,
2407
+ onPropTypeKeyChange: (key) => setPropTypeKey(key),
2403
2408
  value,
2404
2409
  onChange: (newValue) => {
2405
2410
  setValue(newValue);
@@ -2861,7 +2866,7 @@ import { Button as Button7, CardActions as CardActions3, Divider as Divider5, Fo
2861
2866
  import { __ as __16 } from "@wordpress/i18n";
2862
2867
  var SIZE7 = "tiny";
2863
2868
  var VariableRestore = ({ variableId, onClose, onSubmit }) => {
2864
- const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
2869
+ const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
2865
2870
  const { setVariableValue: notifyBoundPropChange } = useVariableBoundProp();
2866
2871
  const { propType } = useBoundProp7();
2867
2872
  const variable = useVariable(variableId);
@@ -2872,12 +2877,15 @@ var VariableRestore = ({ variableId, onClose, onSubmit }) => {
2872
2877
  const [valueFieldError, setValueFieldError] = useState12("");
2873
2878
  const [label, setLabel] = useState12(variable.label);
2874
2879
  const [value, setValue] = useState12(variable.value);
2880
+ const [propTypeKey, setPropTypeKey] = useState12(variable?.type ?? propTypeUtil.key);
2875
2881
  const { labelFieldError, setLabelFieldError } = useLabelError({
2876
2882
  value: variable.label,
2877
2883
  message: ERROR_MESSAGES.DUPLICATED_LABEL
2878
2884
  });
2879
2885
  const handleRestore = () => {
2880
- restoreVariable(variableId, label, value).then(() => {
2886
+ const typeChanged = propTypeKey !== variable.type;
2887
+ const restorePromise = typeChanged ? restoreVariable(variableId, label, value, propTypeKey) : restoreVariable(variableId, label, value);
2888
+ restorePromise.then(() => {
2881
2889
  notifyBoundPropChange(variableId);
2882
2890
  onSubmit?.();
2883
2891
  }).catch((error) => {
@@ -2945,6 +2953,8 @@ var VariableRestore = ({ variableId, onClose, onSubmit }) => {
2945
2953
  ), ValueField && /* @__PURE__ */ React23.createElement(FormField, { errorMsg: valueFieldError, label: __16("Value", "elementor") }, /* @__PURE__ */ React23.createElement(Typography11, { variant: "h5" }, /* @__PURE__ */ React23.createElement(
2946
2954
  ValueField,
2947
2955
  {
2956
+ propTypeKey,
2957
+ onPropTypeKeyChange: (key) => setPropTypeKey(key),
2948
2958
  value,
2949
2959
  onChange: (newValue) => {
2950
2960
  setValue(newValue);