@elementor/editor-variables 3.33.0-120 → 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.js CHANGED
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(index_exports);
40
40
  var import_editor = require("@elementor/editor");
41
41
  var import_editor_editing_panel8 = require("@elementor/editor-editing-panel");
42
42
  var import_editor_panels2 = require("@elementor/editor-panels");
43
+ var import_editor_props6 = require("@elementor/editor-props");
43
44
 
44
45
  // src/components/variables-manager/variables-manager-panel.tsx
45
46
  var React9 = __toESM(require("react"));
@@ -1301,7 +1302,7 @@ var usePermissions = () => {
1301
1302
  // src/components/variable-creation.tsx
1302
1303
  var React12 = __toESM(require("react"));
1303
1304
  var import_react9 = require("react");
1304
- var import_editor_controls3 = require("@elementor/editor-controls");
1305
+ var import_editor_controls4 = require("@elementor/editor-controls");
1305
1306
  var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
1306
1307
  var import_editor_ui3 = require("@elementor/editor-ui");
1307
1308
  var import_icons5 = require("@elementor/icons");
@@ -1312,14 +1313,42 @@ var import_i18n7 = require("@wordpress/i18n");
1312
1313
  var import_editor_controls2 = require("@elementor/editor-controls");
1313
1314
  var useInitialValue = () => {
1314
1315
  const { value: initial } = (0, import_editor_controls2.useBoundProp)();
1315
- const hasAssignedVariable2 = hasVariableType(initial?.$$type) && Boolean(initial?.value);
1316
- const variable = useVariable(hasAssignedVariable2 ? initial.value : "");
1317
- if (hasAssignedVariable2) {
1316
+ const hasAssignedVariable = hasVariableType(initial?.$$type) && Boolean(initial?.value);
1317
+ const variable = useVariable(hasAssignedVariable ? initial.value : "");
1318
+ if (hasAssignedVariable) {
1318
1319
  return variable ? variable.value : "";
1319
1320
  }
1320
1321
  return initial?.value ?? "";
1321
1322
  };
1322
1323
 
1324
+ // src/hooks/use-variable-bound-prop.ts
1325
+ var import_editor_controls3 = require("@elementor/editor-controls");
1326
+ var import_editor_props3 = require("@elementor/editor-props");
1327
+ var useVariableBoundProp = () => {
1328
+ const { propTypeUtil } = useVariableType();
1329
+ const boundProp = (0, import_editor_controls3.useBoundProp)(propTypeUtil);
1330
+ return {
1331
+ ...boundProp,
1332
+ setVariableValue: (value) => resolveBoundPropAndSetValue(value, boundProp),
1333
+ variableId: boundProp.value ?? boundProp.placeholder
1334
+ };
1335
+ };
1336
+ var resolveBoundPropAndSetValue = (value, boundProp) => {
1337
+ const propValue = unwrapValue(boundProp.value);
1338
+ const placeholder = unwrapValue(boundProp.placeholder);
1339
+ const newValue = unwrapValue(value);
1340
+ if (!propValue && placeholder === newValue) {
1341
+ return boundProp.setValue(null);
1342
+ }
1343
+ return boundProp.setValue(value);
1344
+ };
1345
+ var unwrapValue = (input) => {
1346
+ if ((0, import_editor_props3.isTransformable)(input)) {
1347
+ return input.value;
1348
+ }
1349
+ return input;
1350
+ };
1351
+
1323
1352
  // src/utils/tracking.ts
1324
1353
  var trackVariableEvent = ({ varType, controlPath, action }) => {
1325
1354
  const extendedWindow = window;
@@ -1349,8 +1378,8 @@ var FormField = ({ id: id2, label, errorMsg, noticeMsg, children }) => {
1349
1378
  var SIZE = "tiny";
1350
1379
  var VariableCreation = ({ onGoBack, onClose }) => {
1351
1380
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
1352
- const { setValue: setVariable, path } = (0, import_editor_controls3.useBoundProp)(propTypeUtil);
1353
- const { propType } = (0, import_editor_controls3.useBoundProp)();
1381
+ const { setVariableValue: setVariable, path } = useVariableBoundProp();
1382
+ const { propType } = (0, import_editor_controls4.useBoundProp)();
1354
1383
  const initialValue = useInitialValue();
1355
1384
  const [value, setValue] = (0, import_react9.useState)(initialValue);
1356
1385
  const [label, setLabel] = (0, import_react9.useState)("");
@@ -1413,7 +1442,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
1413
1442
  title: (0, import_i18n7.__)("Create variable", "elementor"),
1414
1443
  onClose: closePopover
1415
1444
  }
1416
- ), /* @__PURE__ */ React12.createElement(import_ui12.Divider, null), /* @__PURE__ */ React12.createElement(import_editor_controls3.PopoverContent, { p: 2 }, /* @__PURE__ */ React12.createElement(
1445
+ ), /* @__PURE__ */ React12.createElement(import_ui12.Divider, null), /* @__PURE__ */ React12.createElement(import_editor_controls4.PopoverContent, { p: 2 }, /* @__PURE__ */ React12.createElement(
1417
1446
  FormField,
1418
1447
  {
1419
1448
  id: "variable-label",
@@ -1439,7 +1468,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
1439
1468
  }
1440
1469
  }
1441
1470
  )
1442
- ), /* @__PURE__ */ React12.createElement(FormField, { errorMsg: valueFieldError, label: (0, import_i18n7.__)("Value", "elementor") }, /* @__PURE__ */ React12.createElement(import_ui12.Typography, { variant: "h5" }, /* @__PURE__ */ React12.createElement(
1471
+ ), /* @__PURE__ */ React12.createElement(FormField, { errorMsg: valueFieldError, label: (0, import_i18n7.__)("Value", "elementor") }, /* @__PURE__ */ React12.createElement(import_ui12.Typography, { variant: "h5", id: "variable-value-wrapper" }, /* @__PURE__ */ React12.createElement(
1443
1472
  ValueField,
1444
1473
  {
1445
1474
  value,
@@ -1451,13 +1480,23 @@ var VariableCreation = ({ onGoBack, onClose }) => {
1451
1480
  onValidationChange: setValueFieldError,
1452
1481
  propType
1453
1482
  }
1454
- ))), errorMessage && /* @__PURE__ */ React12.createElement(import_ui12.FormHelperText, { error: true }, errorMessage)), /* @__PURE__ */ React12.createElement(import_ui12.CardActions, { sx: { pt: 0.5, pb: 1 } }, /* @__PURE__ */ React12.createElement(import_ui12.Button, { size: "small", variant: "contained", disabled: isSubmitDisabled, onClick: handleCreateAndTrack }, (0, import_i18n7.__)("Create", "elementor"))));
1483
+ ))), errorMessage && /* @__PURE__ */ React12.createElement(import_ui12.FormHelperText, { error: true }, errorMessage)), /* @__PURE__ */ React12.createElement(import_ui12.CardActions, { sx: { pt: 0.5, pb: 1 } }, /* @__PURE__ */ React12.createElement(
1484
+ import_ui12.Button,
1485
+ {
1486
+ id: "create-variable-button",
1487
+ size: "small",
1488
+ variant: "contained",
1489
+ disabled: isSubmitDisabled,
1490
+ onClick: handleCreateAndTrack
1491
+ },
1492
+ (0, import_i18n7.__)("Create", "elementor")
1493
+ )));
1455
1494
  };
1456
1495
 
1457
1496
  // src/components/variable-edit.tsx
1458
1497
  var React14 = __toESM(require("react"));
1459
1498
  var import_react11 = require("react");
1460
- var import_editor_controls4 = require("@elementor/editor-controls");
1499
+ var import_editor_controls5 = require("@elementor/editor-controls");
1461
1500
  var import_editor_current_user2 = require("@elementor/editor-current-user");
1462
1501
  var import_editor_editing_panel3 = require("@elementor/editor-editing-panel");
1463
1502
  var import_editor_ui4 = require("@elementor/editor-ui");
@@ -1506,9 +1545,9 @@ var EditConfirmationDialog = ({
1506
1545
  // src/components/variable-edit.tsx
1507
1546
  var SIZE2 = "tiny";
1508
1547
  var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1509
- const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
1510
- const { setValue: notifyBoundPropChange, value: assignedValue } = (0, import_editor_controls4.useBoundProp)(propTypeUtil);
1511
- const { propType } = (0, import_editor_controls4.useBoundProp)();
1548
+ const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
1549
+ const { setVariableValue: notifyBoundPropChange, variableId } = useVariableBoundProp();
1550
+ const { propType } = (0, import_editor_controls5.useBoundProp)();
1512
1551
  const [isMessageSuppressed, suppressMessage] = (0, import_editor_current_user2.useSuppressedMessage)(EDIT_CONFIRMATION_DIALOG_ID);
1513
1552
  const [deleteConfirmation, setDeleteConfirmation] = (0, import_react11.useState)(false);
1514
1553
  const [editConfirmation, setEditConfirmation] = (0, import_react11.useState)(false);
@@ -1569,7 +1608,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1569
1608
  });
1570
1609
  };
1571
1610
  const maybeTriggerBoundPropChange = () => {
1572
- if (editId === assignedValue) {
1611
+ if (editId === variableId) {
1573
1612
  notifyBoundPropChange(editId);
1574
1613
  }
1575
1614
  };
@@ -1629,7 +1668,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1629
1668
  ), /* @__PURE__ */ React14.createElement(VariableIcon, { fontSize: SIZE2 })),
1630
1669
  actions
1631
1670
  }
1632
- ), /* @__PURE__ */ React14.createElement(import_ui14.Divider, null), /* @__PURE__ */ React14.createElement(import_editor_controls4.PopoverContent, { p: 2 }, /* @__PURE__ */ React14.createElement(
1671
+ ), /* @__PURE__ */ React14.createElement(import_ui14.Divider, null), /* @__PURE__ */ React14.createElement(import_editor_controls5.PopoverContent, { p: 2 }, /* @__PURE__ */ React14.createElement(
1633
1672
  FormField,
1634
1673
  {
1635
1674
  id: "variable-label",
@@ -1688,7 +1727,6 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1688
1727
  // src/components/variables-selection.tsx
1689
1728
  var React18 = __toESM(require("react"));
1690
1729
  var import_react12 = require("react");
1691
- var import_editor_controls5 = require("@elementor/editor-controls");
1692
1730
  var import_editor_editing_panel4 = require("@elementor/editor-editing-panel");
1693
1731
  var import_editor_ui6 = require("@elementor/editor-ui");
1694
1732
  var import_icons9 = require("@elementor/icons");
@@ -1839,7 +1877,7 @@ var VariablesStyledMenuList = (0, import_ui18.styled)(import_ui18.MenuList)(({ t
1839
1877
  var SIZE4 = "tiny";
1840
1878
  var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
1841
1879
  const { icon: VariableIcon, startIcon, variableType, propTypeUtil } = useVariableType();
1842
- const { value: variable, setValue: setVariable, path } = (0, import_editor_controls5.useBoundProp)(propTypeUtil);
1880
+ const { value: variable, setValue: setVariable, path } = useVariableBoundProp();
1843
1881
  const [searchValue, setSearchValue] = (0, import_react12.useState)("");
1844
1882
  const {
1845
1883
  list: variables,
@@ -1867,12 +1905,12 @@ var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
1867
1905
  const actions = [];
1868
1906
  if (onAdd) {
1869
1907
  actions.push(
1870
- /* @__PURE__ */ React18.createElement(import_ui19.IconButton, { key: "add", size: SIZE4, onClick: onAddAndTrack }, /* @__PURE__ */ React18.createElement(import_icons9.PlusIcon, { fontSize: SIZE4 }))
1908
+ /* @__PURE__ */ React18.createElement(import_ui19.IconButton, { id: "add-variable-button", key: "add", size: SIZE4, onClick: onAddAndTrack }, /* @__PURE__ */ React18.createElement(import_icons9.PlusIcon, { fontSize: SIZE4 }))
1871
1909
  );
1872
1910
  }
1873
1911
  if (onSettings) {
1874
1912
  actions.push(
1875
- /* @__PURE__ */ React18.createElement(import_ui19.IconButton, { key: "settings", size: SIZE4, onClick: onSettings }, /* @__PURE__ */ React18.createElement(import_icons9.SettingsIcon, { fontSize: SIZE4 }))
1913
+ /* @__PURE__ */ React18.createElement(import_ui19.IconButton, { id: "variables-manager-button", key: "settings", size: SIZE4, onClick: onSettings }, /* @__PURE__ */ React18.createElement(import_icons9.SettingsIcon, { fontSize: SIZE4 }))
1876
1914
  );
1877
1915
  }
1878
1916
  const StartIcon = startIcon || (() => /* @__PURE__ */ React18.createElement(VariableIcon, { fontSize: SIZE4 }));
@@ -2124,8 +2162,8 @@ var import_ui22 = require("@elementor/ui");
2124
2162
  var import_i18n15 = require("@wordpress/i18n");
2125
2163
  var SIZE6 = "tiny";
2126
2164
  var VariableRestore = ({ variableId, onClose, onSubmit }) => {
2127
- const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
2128
- const { setValue: notifyBoundPropChange } = (0, import_editor_controls7.useBoundProp)(propTypeUtil);
2165
+ const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
2166
+ const { setVariableValue: notifyBoundPropChange } = useVariableBoundProp();
2129
2167
  const { propType } = (0, import_editor_controls7.useBoundProp)();
2130
2168
  const variable = useVariable(variableId);
2131
2169
  if (!variable) {
@@ -2276,7 +2314,7 @@ WarningVariableTag.displayName = "WarningVariableTag";
2276
2314
  // src/components/ui/variable/deleted-variable.tsx
2277
2315
  var DeletedVariable = ({ variable, propTypeKey }) => {
2278
2316
  const { propTypeUtil } = getVariableType(propTypeKey);
2279
- const { setValue } = (0, import_editor_controls8.useBoundProp)();
2317
+ const boundProp = (0, import_editor_controls8.useBoundProp)();
2280
2318
  const userPermissions = usePermissions();
2281
2319
  const [showInfotip, setShowInfotip] = (0, import_react16.useState)(false);
2282
2320
  const toggleInfotip = () => setShowInfotip((prev) => !prev);
@@ -2289,15 +2327,15 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
2289
2327
  });
2290
2328
  const handlers = {};
2291
2329
  if (userPermissions.canUnlink()) {
2292
- handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, setValue);
2330
+ handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, boundProp.setValue);
2293
2331
  }
2294
2332
  if (userPermissions.canRestore()) {
2295
2333
  handlers.onRestore = () => {
2296
2334
  if (!variable.key) {
2297
2335
  return;
2298
2336
  }
2299
- restoreVariable(variable.key).then((key) => {
2300
- setValue(propTypeUtil.create(key));
2337
+ restoreVariable(variable.key).then((id2) => {
2338
+ resolveBoundPropAndSetValue(propTypeUtil.create(id2), boundProp);
2301
2339
  closeInfotip();
2302
2340
  }).catch(() => {
2303
2341
  closeInfotip();
@@ -2406,7 +2444,7 @@ var MismatchVariableAlert = ({ onClose, onClear, triggerSelect }) => {
2406
2444
 
2407
2445
  // src/components/ui/variable/mismatch-variable.tsx
2408
2446
  var MismatchVariable = ({ variable }) => {
2409
- const { setValue } = (0, import_editor_controls9.useBoundProp)();
2447
+ const { setValue, value } = (0, import_editor_controls9.useBoundProp)();
2410
2448
  const anchorRef = (0, import_react17.useRef)(null);
2411
2449
  const popupId = (0, import_react17.useId)();
2412
2450
  const popupState = (0, import_ui27.usePopupState)({
@@ -2425,6 +2463,7 @@ var MismatchVariable = ({ variable }) => {
2425
2463
  closeInfotip();
2426
2464
  setValue(null);
2427
2465
  };
2466
+ const showClearButton = !!value;
2428
2467
  return /* @__PURE__ */ React27.createElement(import_ui27.Box, { ref: anchorRef }, infotipVisible && /* @__PURE__ */ React27.createElement(import_ui27.Backdrop, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React27.createElement(
2429
2468
  import_ui27.Infotip,
2430
2469
  {
@@ -2437,7 +2476,7 @@ var MismatchVariable = ({ variable }) => {
2437
2476
  MismatchVariableAlert,
2438
2477
  {
2439
2478
  onClose: closeInfotip,
2440
- onClear: clearValue,
2479
+ onClear: showClearButton ? clearValue : void 0,
2441
2480
  triggerSelect
2442
2481
  }
2443
2482
  ),
@@ -2546,7 +2585,7 @@ var MissingVariable = () => {
2546
2585
  // src/controls/variable-control.tsx
2547
2586
  var VariableControl = () => {
2548
2587
  const boundProp = (0, import_editor_controls11.useBoundProp)();
2549
- const boundPropValue = boundProp.value;
2588
+ const boundPropValue = boundProp.value ?? boundProp.placeholder;
2550
2589
  const assignedVariable = useVariable(boundPropValue?.value);
2551
2590
  if (!assignedVariable) {
2552
2591
  return /* @__PURE__ */ React30.createElement(MissingVariable, null);
@@ -2605,7 +2644,7 @@ var trackOpenVariablePopover = (path, variableType) => {
2605
2644
 
2606
2645
  // src/register-variable-types.tsx
2607
2646
  var React34 = __toESM(require("react"));
2608
- var import_editor_props3 = require("@elementor/editor-props");
2647
+ var import_editor_props4 = require("@elementor/editor-props");
2609
2648
  var import_icons15 = require("@elementor/icons");
2610
2649
 
2611
2650
  // src/components/fields/color-field.tsx
@@ -2627,6 +2666,7 @@ var ColorField = ({ value, onChange, onValidationChange }) => {
2627
2666
  return /* @__PURE__ */ React32.createElement(
2628
2667
  import_ui30.UnstableColorField,
2629
2668
  {
2669
+ id: "color-variable-field",
2630
2670
  size: "tiny",
2631
2671
  fullWidth: true,
2632
2672
  value: color,
@@ -2706,6 +2746,7 @@ var FontField = ({ value, onChange, onValidationChange }) => {
2706
2746
  /* @__PURE__ */ React33.createElement(
2707
2747
  import_editor_controls12.ItemSelector,
2708
2748
  {
2749
+ id: "font-family-variables-selector",
2709
2750
  itemsList: mapFontSubs,
2710
2751
  selectedItem: fontFamily,
2711
2752
  onItemChange: handleFontFamilyChange,
@@ -2726,7 +2767,7 @@ function registerVariableTypes() {
2726
2767
  valueField: ColorField,
2727
2768
  icon: import_icons15.BrushIcon,
2728
2769
  propTypeUtil: colorVariablePropTypeUtil,
2729
- fallbackPropTypeUtil: import_editor_props3.colorPropTypeUtil,
2770
+ fallbackPropTypeUtil: import_editor_props4.colorPropTypeUtil,
2730
2771
  variableType: "color",
2731
2772
  startIcon: ({ value }) => /* @__PURE__ */ React34.createElement(ColorIndicator, { size: "inherit", component: "span", value })
2732
2773
  });
@@ -2734,7 +2775,7 @@ function registerVariableTypes() {
2734
2775
  valueField: FontField,
2735
2776
  icon: import_icons15.TextIcon,
2736
2777
  propTypeUtil: fontVariablePropTypeUtil,
2737
- fallbackPropTypeUtil: import_editor_props3.stringPropTypeUtil,
2778
+ fallbackPropTypeUtil: import_editor_props4.stringPropTypeUtil,
2738
2779
  variableType: "font"
2739
2780
  });
2740
2781
  }
@@ -2789,7 +2830,7 @@ function convertToCssVariables(variables) {
2789
2830
 
2790
2831
  // src/repeater-injections.ts
2791
2832
  var import_editor_controls13 = require("@elementor/editor-controls");
2792
- var import_editor_props4 = require("@elementor/editor-props");
2833
+ var import_editor_props5 = require("@elementor/editor-props");
2793
2834
 
2794
2835
  // src/components/variables-repeater-item-slot.tsx
2795
2836
  var React36 = __toESM(require("react"));
@@ -2816,21 +2857,21 @@ function registerRepeaterInjections() {
2816
2857
  id: "color-variables-background-icon",
2817
2858
  component: BackgroundRepeaterColorIndicator,
2818
2859
  condition: ({ value: prop }) => {
2819
- return hasAssignedColorVariable(import_editor_props4.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
2860
+ return hasAssignedColorVariable(import_editor_props5.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
2820
2861
  }
2821
2862
  });
2822
2863
  (0, import_editor_controls13.injectIntoRepeaterItemIcon)({
2823
2864
  id: "color-variables-icon",
2824
2865
  component: BoxShadowRepeaterColorIndicator,
2825
2866
  condition: ({ value: prop }) => {
2826
- return hasAssignedColorVariable(import_editor_props4.shadowPropTypeUtil.extract(prop)?.color);
2867
+ return hasAssignedColorVariable(import_editor_props5.shadowPropTypeUtil.extract(prop)?.color);
2827
2868
  }
2828
2869
  });
2829
2870
  (0, import_editor_controls13.injectIntoRepeaterItemLabel)({
2830
2871
  id: "color-variables-label",
2831
2872
  component: BackgroundRepeaterLabel,
2832
2873
  condition: ({ value: prop }) => {
2833
- return hasAssignedColorVariable(import_editor_props4.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
2874
+ return hasAssignedColorVariable(import_editor_props5.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
2834
2875
  }
2835
2876
  });
2836
2877
  }
@@ -2845,7 +2886,7 @@ function init() {
2845
2886
  registerRepeaterInjections();
2846
2887
  (0, import_editor_editing_panel8.registerControlReplacement)({
2847
2888
  component: VariableControl,
2848
- condition: ({ value }) => hasAssignedVariable(value)
2889
+ condition: ({ value, placeholder }) => hasVariable(value) || hasVariable(placeholder)
2849
2890
  });
2850
2891
  registerPopoverAction({
2851
2892
  id: "variables",
@@ -2858,9 +2899,9 @@ function init() {
2858
2899
  });
2859
2900
  (0, import_editor_panels2.__registerPanel)(panel);
2860
2901
  }
2861
- function hasAssignedVariable(propValue) {
2862
- if (propValue && typeof propValue === "object" && "$$type" in propValue) {
2863
- return hasVariableType(propValue.$$type);
2902
+ function hasVariable(value) {
2903
+ if ((0, import_editor_props6.isTransformable)(value)) {
2904
+ return hasVariableType(value.$$type);
2864
2905
  }
2865
2906
  return false;
2866
2907
  }