@elementor/editor-variables 3.33.0-121 → 3.33.0-122

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
@@ -2,6 +2,7 @@
2
2
  import { injectIntoTop } from "@elementor/editor";
3
3
  import { controlActionsMenu, registerControlReplacement } from "@elementor/editor-editing-panel";
4
4
  import { __registerPanel as registerPanel } from "@elementor/editor-panels";
5
+ import { isTransformable as isTransformable2 } from "@elementor/editor-props";
5
6
 
6
7
  // src/components/variables-manager/variables-manager-panel.tsx
7
8
  import * as React9 from "react";
@@ -1288,7 +1289,7 @@ var usePermissions = () => {
1288
1289
  // src/components/variable-creation.tsx
1289
1290
  import * as React12 from "react";
1290
1291
  import { useState as useState6 } from "react";
1291
- import { PopoverContent, useBoundProp as useBoundProp3 } from "@elementor/editor-controls";
1292
+ import { PopoverContent, useBoundProp as useBoundProp4 } from "@elementor/editor-controls";
1292
1293
  import { PopoverBody } from "@elementor/editor-editing-panel";
1293
1294
  import { PopoverHeader } from "@elementor/editor-ui";
1294
1295
  import { ArrowLeftIcon } from "@elementor/icons";
@@ -1299,14 +1300,42 @@ import { __ as __7 } from "@wordpress/i18n";
1299
1300
  import { useBoundProp as useBoundProp2 } from "@elementor/editor-controls";
1300
1301
  var useInitialValue = () => {
1301
1302
  const { value: initial } = useBoundProp2();
1302
- const hasAssignedVariable2 = hasVariableType(initial?.$$type) && Boolean(initial?.value);
1303
- const variable = useVariable(hasAssignedVariable2 ? initial.value : "");
1304
- if (hasAssignedVariable2) {
1303
+ const hasAssignedVariable = hasVariableType(initial?.$$type) && Boolean(initial?.value);
1304
+ const variable = useVariable(hasAssignedVariable ? initial.value : "");
1305
+ if (hasAssignedVariable) {
1305
1306
  return variable ? variable.value : "";
1306
1307
  }
1307
1308
  return initial?.value ?? "";
1308
1309
  };
1309
1310
 
1311
+ // src/hooks/use-variable-bound-prop.ts
1312
+ import { useBoundProp as useBoundProp3 } from "@elementor/editor-controls";
1313
+ import { isTransformable } from "@elementor/editor-props";
1314
+ var useVariableBoundProp = () => {
1315
+ const { propTypeUtil } = useVariableType();
1316
+ const boundProp = useBoundProp3(propTypeUtil);
1317
+ return {
1318
+ ...boundProp,
1319
+ setVariableValue: (value) => resolveBoundPropAndSetValue(value, boundProp),
1320
+ variableId: boundProp.value ?? boundProp.placeholder
1321
+ };
1322
+ };
1323
+ var resolveBoundPropAndSetValue = (value, boundProp) => {
1324
+ const propValue = unwrapValue(boundProp.value);
1325
+ const placeholder = unwrapValue(boundProp.placeholder);
1326
+ const newValue = unwrapValue(value);
1327
+ if (!propValue && placeholder === newValue) {
1328
+ return boundProp.setValue(null);
1329
+ }
1330
+ return boundProp.setValue(value);
1331
+ };
1332
+ var unwrapValue = (input) => {
1333
+ if (isTransformable(input)) {
1334
+ return input.value;
1335
+ }
1336
+ return input;
1337
+ };
1338
+
1310
1339
  // src/utils/tracking.ts
1311
1340
  var trackVariableEvent = ({ varType, controlPath, action }) => {
1312
1341
  const extendedWindow = window;
@@ -1336,8 +1365,8 @@ var FormField = ({ id: id2, label, errorMsg, noticeMsg, children }) => {
1336
1365
  var SIZE = "tiny";
1337
1366
  var VariableCreation = ({ onGoBack, onClose }) => {
1338
1367
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
1339
- const { setValue: setVariable, path } = useBoundProp3(propTypeUtil);
1340
- const { propType } = useBoundProp3();
1368
+ const { setVariableValue: setVariable, path } = useVariableBoundProp();
1369
+ const { propType } = useBoundProp4();
1341
1370
  const initialValue = useInitialValue();
1342
1371
  const [value, setValue] = useState6(initialValue);
1343
1372
  const [label, setLabel] = useState6("");
@@ -1454,7 +1483,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
1454
1483
  // src/components/variable-edit.tsx
1455
1484
  import * as React14 from "react";
1456
1485
  import { useEffect as useEffect2, useState as useState8 } from "react";
1457
- import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp4 } from "@elementor/editor-controls";
1486
+ import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
1458
1487
  import { useSuppressedMessage } from "@elementor/editor-current-user";
1459
1488
  import { PopoverBody as PopoverBody2 } from "@elementor/editor-editing-panel";
1460
1489
  import { PopoverHeader as PopoverHeader2 } from "@elementor/editor-ui";
@@ -1513,9 +1542,9 @@ var EditConfirmationDialog = ({
1513
1542
  // src/components/variable-edit.tsx
1514
1543
  var SIZE2 = "tiny";
1515
1544
  var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1516
- const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
1517
- const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp4(propTypeUtil);
1518
- const { propType } = useBoundProp4();
1545
+ const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
1546
+ const { setVariableValue: notifyBoundPropChange, variableId } = useVariableBoundProp();
1547
+ const { propType } = useBoundProp5();
1519
1548
  const [isMessageSuppressed, suppressMessage] = useSuppressedMessage(EDIT_CONFIRMATION_DIALOG_ID);
1520
1549
  const [deleteConfirmation, setDeleteConfirmation] = useState8(false);
1521
1550
  const [editConfirmation, setEditConfirmation] = useState8(false);
@@ -1576,7 +1605,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1576
1605
  });
1577
1606
  };
1578
1607
  const maybeTriggerBoundPropChange = () => {
1579
- if (editId === assignedValue) {
1608
+ if (editId === variableId) {
1580
1609
  notifyBoundPropChange(editId);
1581
1610
  }
1582
1611
  };
@@ -1695,7 +1724,6 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1695
1724
  // src/components/variables-selection.tsx
1696
1725
  import * as React18 from "react";
1697
1726
  import { useState as useState9 } from "react";
1698
- import { useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
1699
1727
  import { PopoverBody as PopoverBody3 } from "@elementor/editor-editing-panel";
1700
1728
  import { PopoverHeader as PopoverHeader3, PopoverMenuList, PopoverSearch } from "@elementor/editor-ui";
1701
1729
  import { ColorFilterIcon as ColorFilterIcon2, PlusIcon, SettingsIcon } from "@elementor/icons";
@@ -1846,7 +1874,7 @@ var VariablesStyledMenuList = styled2(MenuList)(({ theme }) => ({
1846
1874
  var SIZE4 = "tiny";
1847
1875
  var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
1848
1876
  const { icon: VariableIcon, startIcon, variableType, propTypeUtil } = useVariableType();
1849
- const { value: variable, setValue: setVariable, path } = useBoundProp5(propTypeUtil);
1877
+ const { value: variable, setValue: setVariable, path } = useVariableBoundProp();
1850
1878
  const [searchValue, setSearchValue] = useState9("");
1851
1879
  const {
1852
1880
  list: variables,
@@ -2131,8 +2159,8 @@ import { Button as Button7, CardActions as CardActions3, Divider as Divider5, Fo
2131
2159
  import { __ as __15 } from "@wordpress/i18n";
2132
2160
  var SIZE6 = "tiny";
2133
2161
  var VariableRestore = ({ variableId, onClose, onSubmit }) => {
2134
- const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
2135
- const { setValue: notifyBoundPropChange } = useBoundProp7(propTypeUtil);
2162
+ const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
2163
+ const { setVariableValue: notifyBoundPropChange } = useVariableBoundProp();
2136
2164
  const { propType } = useBoundProp7();
2137
2165
  const variable = useVariable(variableId);
2138
2166
  if (!variable) {
@@ -2283,7 +2311,7 @@ WarningVariableTag.displayName = "WarningVariableTag";
2283
2311
  // src/components/ui/variable/deleted-variable.tsx
2284
2312
  var DeletedVariable = ({ variable, propTypeKey }) => {
2285
2313
  const { propTypeUtil } = getVariableType(propTypeKey);
2286
- const { setValue } = useBoundProp8();
2314
+ const boundProp = useBoundProp8();
2287
2315
  const userPermissions = usePermissions();
2288
2316
  const [showInfotip, setShowInfotip] = useState12(false);
2289
2317
  const toggleInfotip = () => setShowInfotip((prev) => !prev);
@@ -2296,15 +2324,15 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
2296
2324
  });
2297
2325
  const handlers = {};
2298
2326
  if (userPermissions.canUnlink()) {
2299
- handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, setValue);
2327
+ handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, boundProp.setValue);
2300
2328
  }
2301
2329
  if (userPermissions.canRestore()) {
2302
2330
  handlers.onRestore = () => {
2303
2331
  if (!variable.key) {
2304
2332
  return;
2305
2333
  }
2306
- restoreVariable(variable.key).then((key) => {
2307
- setValue(propTypeUtil.create(key));
2334
+ restoreVariable(variable.key).then((id2) => {
2335
+ resolveBoundPropAndSetValue(propTypeUtil.create(id2), boundProp);
2308
2336
  closeInfotip();
2309
2337
  }).catch(() => {
2310
2338
  closeInfotip();
@@ -2413,7 +2441,7 @@ var MismatchVariableAlert = ({ onClose, onClear, triggerSelect }) => {
2413
2441
 
2414
2442
  // src/components/ui/variable/mismatch-variable.tsx
2415
2443
  var MismatchVariable = ({ variable }) => {
2416
- const { setValue } = useBoundProp9();
2444
+ const { setValue, value } = useBoundProp9();
2417
2445
  const anchorRef = useRef3(null);
2418
2446
  const popupId = useId3();
2419
2447
  const popupState = usePopupState4({
@@ -2432,6 +2460,7 @@ var MismatchVariable = ({ variable }) => {
2432
2460
  closeInfotip();
2433
2461
  setValue(null);
2434
2462
  };
2463
+ const showClearButton = !!value;
2435
2464
  return /* @__PURE__ */ React27.createElement(Box8, { ref: anchorRef }, infotipVisible && /* @__PURE__ */ React27.createElement(Backdrop2, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React27.createElement(
2436
2465
  Infotip2,
2437
2466
  {
@@ -2444,7 +2473,7 @@ var MismatchVariable = ({ variable }) => {
2444
2473
  MismatchVariableAlert,
2445
2474
  {
2446
2475
  onClose: closeInfotip,
2447
- onClear: clearValue,
2476
+ onClear: showClearButton ? clearValue : void 0,
2448
2477
  triggerSelect
2449
2478
  }
2450
2479
  ),
@@ -2553,7 +2582,7 @@ var MissingVariable = () => {
2553
2582
  // src/controls/variable-control.tsx
2554
2583
  var VariableControl = () => {
2555
2584
  const boundProp = useBoundProp11();
2556
- const boundPropValue = boundProp.value;
2585
+ const boundPropValue = boundProp.value ?? boundProp.placeholder;
2557
2586
  const assignedVariable = useVariable(boundPropValue?.value);
2558
2587
  if (!assignedVariable) {
2559
2588
  return /* @__PURE__ */ React30.createElement(MissingVariable, null);
@@ -2854,7 +2883,7 @@ function init() {
2854
2883
  registerRepeaterInjections();
2855
2884
  registerControlReplacement({
2856
2885
  component: VariableControl,
2857
- condition: ({ value }) => hasAssignedVariable(value)
2886
+ condition: ({ value, placeholder }) => hasVariable(value) || hasVariable(placeholder)
2858
2887
  });
2859
2888
  registerPopoverAction({
2860
2889
  id: "variables",
@@ -2867,9 +2896,9 @@ function init() {
2867
2896
  });
2868
2897
  registerPanel(panel);
2869
2898
  }
2870
- function hasAssignedVariable(propValue) {
2871
- if (propValue && typeof propValue === "object" && "$$type" in propValue) {
2872
- return hasVariableType(propValue.$$type);
2899
+ function hasVariable(value) {
2900
+ if (isTransformable2(value)) {
2901
+ return hasVariableType(value.$$type);
2873
2902
  }
2874
2903
  return false;
2875
2904
  }