@elementor/editor-variables 3.35.0-393 → 3.35.0-395

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
@@ -1038,10 +1038,32 @@ var useVariablesManagerState = () => {
1038
1038
 
1039
1039
  // src/components/variables-manager/variables-manager-create-menu.tsx
1040
1040
  import * as React6 from "react";
1041
- import { createElement as createElement7, useRef as useRef2 } from "react";
1041
+ import { createElement as createElement7, useMemo as useMemo2, useRef as useRef2 } from "react";
1042
+ import { PromotionChip } from "@elementor/editor-ui";
1042
1043
  import { PlusIcon } from "@elementor/icons";
1043
- import { bindMenu, bindTrigger, IconButton, Menu, MenuItem, Typography as Typography5 } from "@elementor/ui";
1044
+ import { bindMenu, bindTrigger, Box, IconButton, Menu, MenuItem, Typography as Typography5 } from "@elementor/ui";
1044
1045
  import { __ as __7 } from "@wordpress/i18n";
1046
+
1047
+ // src/sync/license-info.ts
1048
+ function getLicenseInfo() {
1049
+ const extendedWindow = window;
1050
+ return {
1051
+ hasPro: !!extendedWindow.elementorPro
1052
+ };
1053
+ }
1054
+
1055
+ // src/hooks/use-quota-permissions.ts
1056
+ var useQuotaPermissions = (variableType) => {
1057
+ const quotaConfig = window.ElementorVariablesQuotaConfig || {};
1058
+ const limit = quotaConfig[variableType] || 0;
1059
+ const hasQuota = limit > 0;
1060
+ return {
1061
+ canAdd: () => hasQuota || getLicenseInfo().hasPro,
1062
+ canEdit: () => hasQuota || getLicenseInfo().hasPro
1063
+ };
1064
+ };
1065
+
1066
+ // src/components/variables-manager/variables-manager-create-menu.tsx
1045
1067
  var SIZE = "tiny";
1046
1068
  var VariableManagerCreateMenu = ({
1047
1069
  variables,
@@ -1051,19 +1073,16 @@ var VariableManagerCreateMenu = ({
1051
1073
  }) => {
1052
1074
  const buttonRef = useRef2(null);
1053
1075
  const variableTypes = getVariableTypes();
1054
- const menuOptions = Object.entries(variableTypes).filter(([, variable]) => !!variable.defaultValue).map(([key, variable]) => {
1055
- const displayName = variable.variableType.charAt(0).toUpperCase() + variable.variableType.slice(1);
1056
- return {
1076
+ const menuOptionConfigs = useMemo2(
1077
+ () => Object.entries(variableTypes).filter(([, variable]) => !!variable.defaultValue).map(([key, variable]) => ({
1057
1078
  key,
1058
- name: displayName,
1059
- icon: variable.icon,
1060
- onClick: () => {
1061
- const defaultName = getDefaultName(variables, key, variable.variableType);
1062
- onCreate(key, defaultName, variable.defaultValue || "");
1063
- trackVariablesManagerEvent({ action: "add", varType: variable.variableType });
1064
- }
1065
- };
1066
- });
1079
+ propTypeKey: variable.propTypeUtil.key,
1080
+ variableType: variable.variableType,
1081
+ defaultValue: variable.defaultValue || "",
1082
+ icon: variable.icon
1083
+ })),
1084
+ [variableTypes]
1085
+ );
1067
1086
  return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(
1068
1087
  IconButton,
1069
1088
  {
@@ -1096,26 +1115,47 @@ var VariableManagerCreateMenu = ({
1096
1115
  },
1097
1116
  "data-testid": "variable-manager-create-menu"
1098
1117
  },
1099
- menuOptions.map((option) => /* @__PURE__ */ React6.createElement(
1100
- MenuItem,
1118
+ menuOptionConfigs.map((config) => /* @__PURE__ */ React6.createElement(
1119
+ MenuOption,
1101
1120
  {
1102
- key: option.key,
1103
- onClick: () => {
1104
- option.onClick?.();
1105
- menuState.close();
1106
- },
1107
- sx: {
1108
- gap: 1.5
1109
- }
1110
- },
1111
- createElement7(option.icon, {
1112
- fontSize: SIZE,
1113
- color: "action"
1114
- }),
1115
- /* @__PURE__ */ React6.createElement(Typography5, { variant: "caption", color: "text.primary" }, option.name)
1121
+ key: config.key,
1122
+ config,
1123
+ variables,
1124
+ onCreate,
1125
+ onClose: menuState.close
1126
+ }
1116
1127
  ))
1117
1128
  ));
1118
1129
  };
1130
+ var MenuOption = ({
1131
+ config,
1132
+ variables,
1133
+ onCreate,
1134
+ onClose
1135
+ }) => {
1136
+ const displayName = config.variableType.charAt(0).toUpperCase() + config.variableType.slice(1);
1137
+ const userQuotaPermissions = useQuotaPermissions(config.propTypeKey);
1138
+ const isDisabled = !userQuotaPermissions.canAdd();
1139
+ const handleClick = () => {
1140
+ if (isDisabled) {
1141
+ return;
1142
+ }
1143
+ const defaultName = getDefaultName(variables, config.key, config.variableType);
1144
+ onCreate(config.key, defaultName, config.defaultValue);
1145
+ trackVariablesManagerEvent({ action: "add", varType: config.variableType });
1146
+ onClose();
1147
+ };
1148
+ return /* @__PURE__ */ React6.createElement(MenuItem, { onClick: handleClick, sx: { gap: 1.5, cursor: isDisabled ? "default" : "pointer" } }, createElement7(config.icon, { fontSize: SIZE, color: isDisabled ? "disabled" : "action" }), /* @__PURE__ */ React6.createElement(Typography5, { variant: "caption", color: isDisabled ? "text.disabled" : "text.primary" }, displayName), isDisabled && /* @__PURE__ */ React6.createElement(
1149
+ Box,
1150
+ {
1151
+ onClick: () => {
1152
+ event?.stopPropagation();
1153
+ }
1154
+ },
1155
+ /* @__PURE__ */ React6.createElement(PromotionChip, { onClick: () => {
1156
+ } })
1157
+ ));
1158
+ };
1119
1159
  var getDefaultName = (variables, type, baseName) => {
1120
1160
  const existingNames = Object.values(variables).filter((variable) => variable.type === type).map((variable) => variable.label);
1121
1161
  let counter = 1;
@@ -1342,14 +1382,14 @@ var VariableEditableCell = React10.memo(
1342
1382
  const handleDoubleClick = () => {
1343
1383
  setIsEditing(true);
1344
1384
  };
1345
- const handleKeyDown = (event) => {
1346
- if (event.key === "Enter") {
1385
+ const handleKeyDown = (event2) => {
1386
+ if (event2.key === "Enter") {
1347
1387
  handleSave();
1348
- } else if (event.key === "Escape") {
1388
+ } else if (event2.key === "Escape") {
1349
1389
  setIsEditing(false);
1350
1390
  }
1351
- if (event.key === " " && !isEditing) {
1352
- event.preventDefault();
1391
+ if (event2.key === " " && !isEditing) {
1392
+ event2.preventDefault();
1353
1393
  setIsEditing(true);
1354
1394
  }
1355
1395
  };
@@ -1944,9 +1984,9 @@ function VariablesManagerPanel() {
1944
1984
  }
1945
1985
  var usePreventUnload = (isDirty) => {
1946
1986
  useEffect3(() => {
1947
- const handleBeforeUnload = (event) => {
1987
+ const handleBeforeUnload = (event2) => {
1948
1988
  if (isDirty) {
1949
- event.preventDefault();
1989
+ event2.preventDefault();
1950
1990
  }
1951
1991
  };
1952
1992
  window.addEventListener("beforeunload", handleBeforeUnload);
@@ -1965,7 +2005,7 @@ import { useId, useRef as useRef6 } from "react";
1965
2005
  import * as React22 from "react";
1966
2006
  import { useBoundProp as useBoundProp6 } from "@elementor/editor-controls";
1967
2007
  import { ColorFilterIcon as ColorFilterIcon3 } from "@elementor/icons";
1968
- import { bindPopover, bindTrigger as bindTrigger3, Box as Box4, Popover, usePopupState as usePopupState3 } from "@elementor/ui";
2008
+ import { bindPopover, bindTrigger as bindTrigger3, Box as Box5, Popover, usePopupState as usePopupState3 } from "@elementor/ui";
1969
2009
 
1970
2010
  // src/utils/unlink-variable.ts
1971
2011
  function transformValueBeforeUnlink(variable, propTypeKey) {
@@ -1991,35 +2031,16 @@ import { isExperimentActive } from "@elementor/editor-v1-adapters";
1991
2031
  // src/context/variable-selection-popover.context.tsx
1992
2032
  import * as React13 from "react";
1993
2033
  import { createContext as createContext2, useContext as useContext2, useState as useState6 } from "react";
1994
- import { Box } from "@elementor/ui";
2034
+ import { Box as Box2 } from "@elementor/ui";
1995
2035
  var PopoverContentRefContext = createContext2(null);
1996
2036
  var PopoverContentRefContextProvider = ({ children }) => {
1997
2037
  const [anchorRef, setAnchorRef] = useState6(null);
1998
- return /* @__PURE__ */ React13.createElement(PopoverContentRefContext.Provider, { value: anchorRef }, /* @__PURE__ */ React13.createElement(Box, { ref: setAnchorRef }, children));
2038
+ return /* @__PURE__ */ React13.createElement(PopoverContentRefContext.Provider, { value: anchorRef }, /* @__PURE__ */ React13.createElement(Box2, { ref: setAnchorRef }, children));
1999
2039
  };
2000
2040
  var usePopoverContentRef = () => {
2001
2041
  return useContext2(PopoverContentRefContext);
2002
2042
  };
2003
2043
 
2004
- // src/sync/license-info.ts
2005
- function getLicenseInfo() {
2006
- const extendedWindow = window;
2007
- return {
2008
- hasPro: !!extendedWindow.elementorPro
2009
- };
2010
- }
2011
-
2012
- // src/hooks/use-quota-permissions.ts
2013
- var useQuotaPermissions = (variableType) => {
2014
- const quotaConfig = window.ElementorVariablesQuotaConfig || {};
2015
- const limit = quotaConfig[variableType] || 0;
2016
- const hasQuota = limit > 0;
2017
- return {
2018
- canAdd: () => hasQuota || getLicenseInfo().hasPro,
2019
- canEdit: () => hasQuota || getLicenseInfo().hasPro
2020
- };
2021
- };
2022
-
2023
2044
  // src/components/variable-creation.tsx
2024
2045
  import * as React15 from "react";
2025
2046
  import { useState as useState7 } from "react";
@@ -2248,7 +2269,7 @@ var EditConfirmationDialog = ({
2248
2269
  Checkbox,
2249
2270
  {
2250
2271
  checked: dontShowAgain,
2251
- onChange: (event) => setDontShowAgain(event.target.checked),
2272
+ onChange: (event2) => setDontShowAgain(event2.target.checked),
2252
2273
  size: "small"
2253
2274
  }
2254
2275
  ),
@@ -2446,14 +2467,14 @@ import { __ as __14, sprintf as sprintf2 } from "@wordpress/i18n";
2446
2467
  import * as React18 from "react";
2447
2468
  import { EllipsisWithTooltip as EllipsisWithTooltip2 } from "@elementor/editor-ui";
2448
2469
  import { EditIcon } from "@elementor/icons";
2449
- import { Box as Box2, IconButton as IconButton6, ListItemIcon, Tooltip as Tooltip2, Typography as Typography9 } from "@elementor/ui";
2470
+ import { Box as Box3, IconButton as IconButton6, ListItemIcon, Tooltip as Tooltip2, Typography as Typography9 } from "@elementor/ui";
2450
2471
  import { __ as __13 } from "@wordpress/i18n";
2451
2472
  var SIZE4 = "tiny";
2452
2473
  var EDIT_LABEL = __13("Edit variable", "elementor");
2453
2474
  var MenuItemContent = ({ item }) => {
2454
2475
  const onEdit = item.onEdit;
2455
2476
  return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement(ListItemIcon, null, item.icon), /* @__PURE__ */ React18.createElement(
2456
- Box2,
2477
+ Box3,
2457
2478
  {
2458
2479
  sx: {
2459
2480
  flex: 1,
@@ -2783,7 +2804,7 @@ function RenderView(props) {
2783
2804
  // src/components/ui/tags/assigned-tag.tsx
2784
2805
  import * as React21 from "react";
2785
2806
  import { DetachIcon } from "@elementor/icons";
2786
- import { Box as Box3, IconButton as IconButton8, Stack as Stack7, Tooltip as Tooltip4, Typography as Typography10, UnstableTag as Tag } from "@elementor/ui";
2807
+ import { Box as Box4, IconButton as IconButton8, Stack as Stack7, Tooltip as Tooltip4, Typography as Typography10, UnstableTag as Tag } from "@elementor/ui";
2787
2808
  import { __ as __15 } from "@wordpress/i18n";
2788
2809
  var SIZE6 = "tiny";
2789
2810
  var UNLINK_LABEL = __15("Unlink variable", "elementor");
@@ -2800,7 +2821,7 @@ var AssignedTag = ({ startIcon, label, onUnlink, ...props }) => {
2800
2821
  fullWidth: true,
2801
2822
  showActionsOnHover: true,
2802
2823
  startIcon: /* @__PURE__ */ React21.createElement(Stack7, { gap: 0.5, direction: "row", alignItems: "center" }, startIcon),
2803
- label: /* @__PURE__ */ React21.createElement(Box3, { sx: { display: "inline-grid", minWidth: 0 } }, /* @__PURE__ */ React21.createElement(Typography10, { sx: { lineHeight: 1.34 }, variant: "caption", noWrap: true }, label)),
2824
+ label: /* @__PURE__ */ React21.createElement(Box4, { sx: { display: "inline-grid", minWidth: 0 } }, /* @__PURE__ */ React21.createElement(Typography10, { sx: { lineHeight: 1.34 }, variant: "caption", noWrap: true }, label)),
2804
2825
  actions,
2805
2826
  ...props
2806
2827
  }
@@ -2819,7 +2840,7 @@ var AssignedVariable = ({ variable, propTypeKey }) => {
2819
2840
  });
2820
2841
  const unlinkVariable = createUnlinkHandler(variable, propTypeKey, setValue);
2821
2842
  const StartIcon = startIcon || (() => null);
2822
- return /* @__PURE__ */ React22.createElement(Box4, { ref: anchorRef }, /* @__PURE__ */ React22.createElement(
2843
+ return /* @__PURE__ */ React22.createElement(Box5, { ref: anchorRef }, /* @__PURE__ */ React22.createElement(
2823
2844
  AssignedTag,
2824
2845
  {
2825
2846
  label: variable.label,
@@ -2854,7 +2875,7 @@ var AssignedVariable = ({ variable, propTypeKey }) => {
2854
2875
  import * as React26 from "react";
2855
2876
  import { useId as useId2, useRef as useRef7, useState as useState13 } from "react";
2856
2877
  import { useBoundProp as useBoundProp8 } from "@elementor/editor-controls";
2857
- import { Backdrop, bindPopover as bindPopover2, Box as Box6, Infotip as Infotip2, Popover as Popover2, usePopupState as usePopupState4 } from "@elementor/ui";
2878
+ import { Backdrop, bindPopover as bindPopover2, Box as Box7, Infotip as Infotip2, Popover as Popover2, usePopupState as usePopupState4 } from "@elementor/ui";
2858
2879
  import { __ as __18 } from "@wordpress/i18n";
2859
2880
 
2860
2881
  // src/components/variable-restore.tsx
@@ -2993,7 +3014,7 @@ var DeletedVariableAlert = ({ onClose, onUnlink, onRestore, label }) => {
2993
3014
  // src/components/ui/tags/warning-variable-tag.tsx
2994
3015
  import * as React25 from "react";
2995
3016
  import { AlertTriangleFilledIcon as AlertTriangleFilledIcon4 } from "@elementor/icons";
2996
- import { Box as Box5, Chip, Tooltip as Tooltip5, Typography as Typography13 } from "@elementor/ui";
3017
+ import { Box as Box6, Chip, Tooltip as Tooltip5, Typography as Typography13 } from "@elementor/ui";
2997
3018
  var WarningVariableTag = React25.forwardRef(
2998
3019
  ({ label, suffix, onClick, icon, ...props }, ref) => {
2999
3020
  const displayText = suffix ? `${label} (${suffix})` : label;
@@ -3007,7 +3028,7 @@ var WarningVariableTag = React25.forwardRef(
3007
3028
  variant: "standard",
3008
3029
  onClick,
3009
3030
  icon: /* @__PURE__ */ React25.createElement(AlertTriangleFilledIcon4, null),
3010
- label: /* @__PURE__ */ React25.createElement(Tooltip5, { title: displayText, placement: "top" }, /* @__PURE__ */ React25.createElement(Box5, { sx: { display: "inline-grid", minWidth: 0 } }, /* @__PURE__ */ React25.createElement(Typography13, { variant: "caption", noWrap: true, sx: { lineHeight: 1.34 } }, displayText))),
3031
+ label: /* @__PURE__ */ React25.createElement(Tooltip5, { title: displayText, placement: "top" }, /* @__PURE__ */ React25.createElement(Box6, { sx: { display: "inline-grid", minWidth: 0 } }, /* @__PURE__ */ React25.createElement(Typography13, { variant: "caption", noWrap: true, sx: { lineHeight: 1.34 } }, displayText))),
3011
3032
  sx: {
3012
3033
  height: (theme) => theme.spacing(3.5),
3013
3034
  borderRadius: (theme) => theme.spacing(1),
@@ -3057,7 +3078,7 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
3057
3078
  const handleRestoreWithOverrides = () => {
3058
3079
  popupState.close();
3059
3080
  };
3060
- return /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement(Box6, { ref: deletedChipAnchorRef }, showInfotip && /* @__PURE__ */ React26.createElement(Backdrop, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React26.createElement(
3081
+ return /* @__PURE__ */ React26.createElement(React26.Fragment, null, /* @__PURE__ */ React26.createElement(Box7, { ref: deletedChipAnchorRef }, showInfotip && /* @__PURE__ */ React26.createElement(Backdrop, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React26.createElement(
3061
3082
  Infotip2,
3062
3083
  {
3063
3084
  color: "warning",
@@ -3119,7 +3140,7 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
3119
3140
  import * as React28 from "react";
3120
3141
  import { useId as useId3, useRef as useRef8, useState as useState14 } from "react";
3121
3142
  import { useBoundProp as useBoundProp9 } from "@elementor/editor-controls";
3122
- import { Backdrop as Backdrop2, bindPopover as bindPopover3, Box as Box7, Infotip as Infotip3, Popover as Popover3, usePopupState as usePopupState5 } from "@elementor/ui";
3143
+ import { Backdrop as Backdrop2, bindPopover as bindPopover3, Box as Box8, Infotip as Infotip3, Popover as Popover3, usePopupState as usePopupState5 } from "@elementor/ui";
3123
3144
  import { __ as __20 } from "@wordpress/i18n";
3124
3145
 
3125
3146
  // src/components/ui/mismatch-variable-alert.tsx
@@ -3174,7 +3195,7 @@ var MismatchVariable = ({ variable }) => {
3174
3195
  setValue(null);
3175
3196
  };
3176
3197
  const showClearButton = !!value;
3177
- return /* @__PURE__ */ React28.createElement(Box7, { ref: anchorRef }, infotipVisible && /* @__PURE__ */ React28.createElement(Backdrop2, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React28.createElement(
3198
+ return /* @__PURE__ */ React28.createElement(Box8, { ref: anchorRef }, infotipVisible && /* @__PURE__ */ React28.createElement(Backdrop2, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React28.createElement(
3178
3199
  Infotip3,
3179
3200
  {
3180
3201
  color: "warning",
@@ -3752,7 +3773,8 @@ function registerVariableTypes() {
3752
3773
  };
3753
3774
  registerVariableType({
3754
3775
  ...sizePromotions,
3755
- key: sizeVariablePropTypeUtil.key
3776
+ key: sizeVariablePropTypeUtil.key,
3777
+ defaultValue: "0px"
3756
3778
  });
3757
3779
  registerVariableType({
3758
3780
  ...sizePromotions,