@elementor/editor-variables 3.32.0-24 → 3.32.0-26

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.d.mts CHANGED
@@ -4,7 +4,13 @@ import * as _mui_material from '@mui/material';
4
4
 
5
5
  declare function init(): void;
6
6
 
7
- declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, fallbackPropTypeUtil, }: {
7
+ type NormalizedVariable = {
8
+ key: string;
9
+ label: string;
10
+ value: string;
11
+ };
12
+
13
+ declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, selectionFilter, fallbackPropTypeUtil, }: {
8
14
  icon: react.ForwardRefExoticComponent<Omit<_mui_material.SvgIconProps, "ref"> & react.RefAttributes<SVGSVGElement>>;
9
15
  startIcon?: ({ value }: {
10
16
  value: string;
@@ -16,6 +22,7 @@ declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil
16
22
  variableType: string;
17
23
  fallbackPropTypeUtil: any;
18
24
  propTypeUtil: _elementor_editor_props.PropTypeUtil<string, string>;
25
+ selectionFilter?: (variables: NormalizedVariable[], propType: _elementor_editor_props.PropType) => NormalizedVariable[];
19
26
  }) => void;
20
27
 
21
28
  export { init, registerVariableType };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,13 @@ import * as _mui_material from '@mui/material';
4
4
 
5
5
  declare function init(): void;
6
6
 
7
- declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, fallbackPropTypeUtil, }: {
7
+ type NormalizedVariable = {
8
+ key: string;
9
+ label: string;
10
+ value: string;
11
+ };
12
+
13
+ declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, selectionFilter, fallbackPropTypeUtil, }: {
8
14
  icon: react.ForwardRefExoticComponent<Omit<_mui_material.SvgIconProps, "ref"> & react.RefAttributes<SVGSVGElement>>;
9
15
  startIcon?: ({ value }: {
10
16
  value: string;
@@ -16,6 +22,7 @@ declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil
16
22
  variableType: string;
17
23
  fallbackPropTypeUtil: any;
18
24
  propTypeUtil: _elementor_editor_props.PropTypeUtil<string, string>;
25
+ selectionFilter?: (variables: NormalizedVariable[], propType: _elementor_editor_props.PropType) => NormalizedVariable[];
19
26
  }) => void;
20
27
 
21
28
  export { init, registerVariableType };
package/dist/index.js CHANGED
@@ -114,12 +114,12 @@ var usePreventUnload = (isDirty) => {
114
114
 
115
115
  // src/controls/variable-control.tsx
116
116
  var React24 = __toESM(require("react"));
117
- var import_editor_controls9 = require("@elementor/editor-controls");
117
+ var import_editor_controls10 = require("@elementor/editor-controls");
118
118
 
119
119
  // src/components/ui/variable/assigned-variable.tsx
120
120
  var import_react11 = require("react");
121
121
  var React16 = __toESM(require("react"));
122
- var import_editor_controls5 = require("@elementor/editor-controls");
122
+ var import_editor_controls6 = require("@elementor/editor-controls");
123
123
  var import_icons9 = require("@elementor/icons");
124
124
  var import_ui16 = require("@elementor/ui");
125
125
 
@@ -485,6 +485,7 @@ function createVariableTypeRegistry() {
485
485
  valueField,
486
486
  propTypeUtil,
487
487
  variableType,
488
+ selectionFilter,
488
489
  fallbackPropTypeUtil
489
490
  }) => {
490
491
  if (variableTypes[propTypeUtil.key]) {
@@ -496,6 +497,7 @@ function createVariableTypeRegistry() {
496
497
  valueField,
497
498
  propTypeUtil,
498
499
  variableType,
500
+ selectionFilter,
499
501
  fallbackPropTypeUtil
500
502
  };
501
503
  registerTransformer(propTypeUtil.key);
@@ -574,7 +576,7 @@ var usePermissions = () => {
574
576
  // src/components/variable-creation.tsx
575
577
  var React6 = __toESM(require("react"));
576
578
  var import_react6 = require("react");
577
- var import_editor_controls2 = require("@elementor/editor-controls");
579
+ var import_editor_controls3 = require("@elementor/editor-controls");
578
580
  var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
579
581
  var import_editor_ui2 = require("@elementor/editor-ui");
580
582
  var import_icons2 = require("@elementor/icons");
@@ -582,10 +584,11 @@ var import_ui6 = require("@elementor/ui");
582
584
  var import_i18n6 = require("@wordpress/i18n");
583
585
 
584
586
  // src/hooks/use-initial-value.ts
585
- var import_editor_controls = require("@elementor/editor-controls");
587
+ var import_editor_controls2 = require("@elementor/editor-controls");
586
588
 
587
589
  // src/hooks/use-prop-variables.ts
588
590
  var import_react4 = require("react");
591
+ var import_editor_controls = require("@elementor/editor-controls");
589
592
  var useVariable = (key) => {
590
593
  const variables = service.variables();
591
594
  if (!variables?.[key]) {
@@ -597,16 +600,24 @@ var useVariable = (key) => {
597
600
  };
598
601
  };
599
602
  var useFilteredVariables = (searchValue, propTypeKey) => {
600
- const variables = usePropVariables(propTypeKey);
601
- const filteredVariables = variables.filter(({ label }) => {
602
- return label.toLowerCase().includes(searchValue.toLowerCase());
603
- });
603
+ const baseVariables = usePropVariables(propTypeKey);
604
+ const typeFilteredVariables = useVariableSelectionFilter(baseVariables);
605
+ const searchFilteredVariables = filterVariablesBySearchValue(typeFilteredVariables, searchValue);
604
606
  return {
605
- list: filteredVariables,
606
- hasMatches: filteredVariables.length > 0,
607
- isSourceNotEmpty: variables.length > 0
607
+ list: searchFilteredVariables,
608
+ hasMatches: searchFilteredVariables.length > 0,
609
+ isSourceNotEmpty: typeFilteredVariables.length > 0
608
610
  };
609
611
  };
612
+ var useVariableSelectionFilter = (variables) => {
613
+ const { selectionFilter } = useVariableType();
614
+ const { propType } = (0, import_editor_controls.useBoundProp)();
615
+ return selectionFilter ? selectionFilter(variables, propType) : variables;
616
+ };
617
+ var filterVariablesBySearchValue = (variables, searchValue) => {
618
+ const lowerSearchValue = searchValue.toLowerCase();
619
+ return variables.filter(({ label }) => label.toLowerCase().includes(lowerSearchValue));
620
+ };
610
621
  var usePropVariables = (propKey) => {
611
622
  return (0, import_react4.useMemo)(() => normalizeVariables(propKey), [propKey]);
612
623
  };
@@ -619,30 +630,23 @@ var normalizeVariables = (propKey) => {
619
630
  value
620
631
  }));
621
632
  };
633
+ var extractId = ({ id: id2 }) => id2;
622
634
  var createVariable = (newVariable) => {
623
- return service.create(newVariable).then(({ id: id2 }) => {
624
- return id2;
625
- });
635
+ return service.create(newVariable).then(extractId);
626
636
  };
627
637
  var updateVariable = (updateId, { value, label }) => {
628
- return service.update(updateId, { value, label }).then(({ id: id2 }) => {
629
- return id2;
630
- });
638
+ return service.update(updateId, { value, label }).then(extractId);
631
639
  };
632
640
  var deleteVariable = (deleteId) => {
633
- return service.delete(deleteId).then(({ id: id2 }) => {
634
- return id2;
635
- });
641
+ return service.delete(deleteId).then(extractId);
636
642
  };
637
643
  var restoreVariable = (restoreId, label, value) => {
638
- return service.restore(restoreId, label, value).then(({ id: id2 }) => {
639
- return id2;
640
- });
644
+ return service.restore(restoreId, label, value).then(extractId);
641
645
  };
642
646
 
643
647
  // src/hooks/use-initial-value.ts
644
648
  var useInitialValue = () => {
645
- const { value: initial } = (0, import_editor_controls.useBoundProp)();
649
+ const { value: initial } = (0, import_editor_controls2.useBoundProp)();
646
650
  const hasAssignedVariable2 = hasVariableType(initial?.$$type) && Boolean(initial?.value);
647
651
  const variable = useVariable(hasAssignedVariable2 ? initial.value : "");
648
652
  if (hasAssignedVariable2) {
@@ -772,7 +776,7 @@ var LabelField = ({ value, error, onChange }) => {
772
776
  var SIZE = "tiny";
773
777
  var VariableCreation = ({ onGoBack, onClose }) => {
774
778
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
775
- const { setValue: setVariable, path } = (0, import_editor_controls2.useBoundProp)(propTypeUtil);
779
+ const { setValue: setVariable, path } = (0, import_editor_controls3.useBoundProp)(propTypeUtil);
776
780
  const initialValue = useInitialValue();
777
781
  const [value, setValue] = (0, import_react6.useState)(initialValue);
778
782
  const [label, setLabel] = (0, import_react6.useState)("");
@@ -827,7 +831,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
827
831
  title: (0, import_i18n6.__)("Create variable", "elementor"),
828
832
  onClose: closePopover
829
833
  }
830
- ), /* @__PURE__ */ React6.createElement(import_ui6.Divider, null), /* @__PURE__ */ React6.createElement(import_editor_controls2.PopoverContent, { p: 2 }, /* @__PURE__ */ React6.createElement(
834
+ ), /* @__PURE__ */ React6.createElement(import_ui6.Divider, null), /* @__PURE__ */ React6.createElement(import_editor_controls3.PopoverContent, { p: 2 }, /* @__PURE__ */ React6.createElement(
831
835
  LabelField,
832
836
  {
833
837
  value: label,
@@ -852,7 +856,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
852
856
  // src/components/variable-edit.tsx
853
857
  var React9 = __toESM(require("react"));
854
858
  var import_react8 = require("react");
855
- var import_editor_controls3 = require("@elementor/editor-controls");
859
+ var import_editor_controls4 = require("@elementor/editor-controls");
856
860
  var import_editor_current_user2 = require("@elementor/editor-current-user");
857
861
  var import_editor_editing_panel3 = require("@elementor/editor-editing-panel");
858
862
  var import_editor_ui3 = require("@elementor/editor-ui");
@@ -917,7 +921,7 @@ var EditConfirmationDialog = ({
917
921
  var SIZE2 = "tiny";
918
922
  var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
919
923
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
920
- const { setValue: notifyBoundPropChange, value: assignedValue } = (0, import_editor_controls3.useBoundProp)(propTypeUtil);
924
+ const { setValue: notifyBoundPropChange, value: assignedValue } = (0, import_editor_controls4.useBoundProp)(propTypeUtil);
921
925
  const [isMessageSuppressed, suppressMessage] = (0, import_editor_current_user2.useSuppressedMessage)(EDIT_CONFIRMATION_DIALOG_ID);
922
926
  const [deleteConfirmation, setDeleteConfirmation] = (0, import_react8.useState)(false);
923
927
  const [editConfirmation, setEditConfirmation] = (0, import_react8.useState)(false);
@@ -1031,7 +1035,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1031
1035
  ), /* @__PURE__ */ React9.createElement(VariableIcon, { fontSize: SIZE2 })),
1032
1036
  actions
1033
1037
  }
1034
- ), /* @__PURE__ */ React9.createElement(import_ui9.Divider, null), /* @__PURE__ */ React9.createElement(import_editor_controls3.PopoverContent, { p: 2 }, /* @__PURE__ */ React9.createElement(
1038
+ ), /* @__PURE__ */ React9.createElement(import_ui9.Divider, null), /* @__PURE__ */ React9.createElement(import_editor_controls4.PopoverContent, { p: 2 }, /* @__PURE__ */ React9.createElement(
1035
1039
  LabelField,
1036
1040
  {
1037
1041
  value: label,
@@ -1071,7 +1075,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1071
1075
  // src/components/variables-selection.tsx
1072
1076
  var React13 = __toESM(require("react"));
1073
1077
  var import_react9 = require("react");
1074
- var import_editor_controls4 = require("@elementor/editor-controls");
1078
+ var import_editor_controls5 = require("@elementor/editor-controls");
1075
1079
  var import_editor_editing_panel4 = require("@elementor/editor-editing-panel");
1076
1080
  var import_editor_ui5 = require("@elementor/editor-ui");
1077
1081
  var import_icons7 = require("@elementor/icons");
@@ -1231,7 +1235,7 @@ var VariablesStyledMenuList = (0, import_ui13.styled)(import_ui13.MenuList)(({ t
1231
1235
  var SIZE4 = "tiny";
1232
1236
  var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
1233
1237
  const { icon: VariableIcon, startIcon, variableType, propTypeUtil } = useVariableType();
1234
- const { value: variable, setValue: setVariable, path } = (0, import_editor_controls4.useBoundProp)(propTypeUtil);
1238
+ const { value: variable, setValue: setVariable, path } = (0, import_editor_controls5.useBoundProp)(propTypeUtil);
1235
1239
  const [searchValue, setSearchValue] = (0, import_react9.useState)("");
1236
1240
  const {
1237
1241
  list: variables,
@@ -1436,7 +1440,7 @@ var AssignedTag = ({ startIcon, label, onUnlink, ...props }) => {
1436
1440
  // src/components/ui/variable/assigned-variable.tsx
1437
1441
  var AssignedVariable = ({ variable, propTypeKey }) => {
1438
1442
  const { fallbackPropTypeUtil, startIcon, propTypeUtil } = getVariableType(propTypeKey);
1439
- const { setValue } = (0, import_editor_controls5.useBoundProp)();
1443
+ const { setValue } = (0, import_editor_controls6.useBoundProp)();
1440
1444
  const anchorRef = (0, import_react11.useRef)(null);
1441
1445
  const popupId = (0, import_react11.useId)();
1442
1446
  const popupState = (0, import_ui16.usePopupState)({
@@ -1482,13 +1486,13 @@ var AssignedVariable = ({ variable, propTypeKey }) => {
1482
1486
  // src/components/ui/variable/deleted-variable.tsx
1483
1487
  var React20 = __toESM(require("react"));
1484
1488
  var import_react13 = require("react");
1485
- var import_editor_controls7 = require("@elementor/editor-controls");
1489
+ var import_editor_controls8 = require("@elementor/editor-controls");
1486
1490
  var import_ui20 = require("@elementor/ui");
1487
1491
 
1488
1492
  // src/components/variable-restore.tsx
1489
1493
  var React17 = __toESM(require("react"));
1490
1494
  var import_react12 = require("react");
1491
- var import_editor_controls6 = require("@elementor/editor-controls");
1495
+ var import_editor_controls7 = require("@elementor/editor-controls");
1492
1496
  var import_editor_editing_panel5 = require("@elementor/editor-editing-panel");
1493
1497
  var import_editor_ui6 = require("@elementor/editor-ui");
1494
1498
  var import_ui17 = require("@elementor/ui");
@@ -1496,7 +1500,7 @@ var import_i18n15 = require("@wordpress/i18n");
1496
1500
  var SIZE6 = "tiny";
1497
1501
  var VariableRestore = ({ variableId, onClose, onSubmit }) => {
1498
1502
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
1499
- const { setValue: notifyBoundPropChange } = (0, import_editor_controls6.useBoundProp)(propTypeUtil);
1503
+ const { setValue: notifyBoundPropChange } = (0, import_editor_controls7.useBoundProp)(propTypeUtil);
1500
1504
  const variable = useVariable(variableId);
1501
1505
  if (!variable) {
1502
1506
  throw new Error(`Global ${variableType} variable not found`);
@@ -1542,7 +1546,7 @@ var VariableRestore = ({ variableId, onClose, onSubmit }) => {
1542
1546
  title: (0, import_i18n15.__)("Restore variable", "elementor"),
1543
1547
  onClose
1544
1548
  }
1545
- ), /* @__PURE__ */ React17.createElement(import_ui17.Divider, null), /* @__PURE__ */ React17.createElement(import_editor_controls6.PopoverContent, { p: 2 }, /* @__PURE__ */ React17.createElement(
1549
+ ), /* @__PURE__ */ React17.createElement(import_ui17.Divider, null), /* @__PURE__ */ React17.createElement(import_editor_controls7.PopoverContent, { p: 2 }, /* @__PURE__ */ React17.createElement(
1546
1550
  LabelField,
1547
1551
  {
1548
1552
  value: label,
@@ -1624,7 +1628,7 @@ var DeletedTag = React19.forwardRef(({ label, onClick, ...props }, ref) => {
1624
1628
  // src/components/ui/variable/deleted-variable.tsx
1625
1629
  var DeletedVariable = ({ variable, propTypeKey }) => {
1626
1630
  const { fallbackPropTypeUtil, propTypeUtil } = getVariableType(propTypeKey);
1627
- const { setValue } = (0, import_editor_controls7.useBoundProp)();
1631
+ const { setValue } = (0, import_editor_controls8.useBoundProp)();
1628
1632
  const userPermissions = usePermissions();
1629
1633
  const [showInfotip, setShowInfotip] = (0, import_react13.useState)(false);
1630
1634
  const toggleInfotip = () => setShowInfotip((prev) => !prev);
@@ -1713,7 +1717,7 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
1713
1717
  // src/components/ui/variable/missing-variable.tsx
1714
1718
  var React23 = __toESM(require("react"));
1715
1719
  var import_react14 = require("react");
1716
- var import_editor_controls8 = require("@elementor/editor-controls");
1720
+ var import_editor_controls9 = require("@elementor/editor-controls");
1717
1721
  var import_ui23 = require("@elementor/ui");
1718
1722
  var import_i18n19 = require("@wordpress/i18n");
1719
1723
 
@@ -1770,7 +1774,7 @@ var MissingTag = React22.forwardRef(({ label, onClick, ...props }, ref) => {
1770
1774
 
1771
1775
  // src/components/ui/variable/missing-variable.tsx
1772
1776
  var MissingVariable = () => {
1773
- const { setValue } = (0, import_editor_controls8.useBoundProp)();
1777
+ const { setValue } = (0, import_editor_controls9.useBoundProp)();
1774
1778
  const [infotipVisible, setInfotipVisible] = (0, import_react14.useState)(false);
1775
1779
  const toggleInfotip = () => setInfotipVisible((prev) => !prev);
1776
1780
  const closeInfotip = () => setInfotipVisible(false);
@@ -1801,7 +1805,7 @@ var MissingVariable = () => {
1801
1805
 
1802
1806
  // src/controls/variable-control.tsx
1803
1807
  var VariableControl = () => {
1804
- const boundProp = (0, import_editor_controls9.useBoundProp)().value;
1808
+ const boundProp = (0, import_editor_controls10.useBoundProp)().value;
1805
1809
  const assignedVariable = useVariable(boundProp?.value);
1806
1810
  if (!assignedVariable) {
1807
1811
  return /* @__PURE__ */ React24.createElement(MissingVariable, null);
@@ -1897,7 +1901,7 @@ var ColorField = ({ value, onChange }) => {
1897
1901
  // src/components/fields/font-field.tsx
1898
1902
  var React27 = __toESM(require("react"));
1899
1903
  var import_react16 = require("react");
1900
- var import_editor_controls10 = require("@elementor/editor-controls");
1904
+ var import_editor_controls11 = require("@elementor/editor-controls");
1901
1905
  var import_editor_editing_panel9 = require("@elementor/editor-editing-panel");
1902
1906
  var import_icons13 = require("@elementor/icons");
1903
1907
  var import_ui25 = require("@elementor/ui");
@@ -1946,7 +1950,7 @@ var FontField = ({ value, onChange }) => {
1946
1950
  ...(0, import_ui25.bindPopover)(fontPopoverState)
1947
1951
  },
1948
1952
  /* @__PURE__ */ React27.createElement(
1949
- import_editor_controls10.ItemSelector,
1953
+ import_editor_controls11.ItemSelector,
1950
1954
  {
1951
1955
  itemsList: mapFontSubs,
1952
1956
  selectedItem: fontFamily,
@@ -1955,7 +1959,7 @@ var FontField = ({ value, onChange }) => {
1955
1959
  sectionWidth,
1956
1960
  title: (0, import_i18n22.__)("Font Family", "elementor"),
1957
1961
  itemStyle: (item) => ({ fontFamily: item.value }),
1958
- onDebounce: import_editor_controls10.enqueueFont,
1962
+ onDebounce: import_editor_controls11.enqueueFont,
1959
1963
  icon: import_icons13.TextIcon
1960
1964
  }
1961
1965
  )
@@ -2030,7 +2034,7 @@ function convertToCssVariables(variables) {
2030
2034
  }
2031
2035
 
2032
2036
  // src/repeater-injections.ts
2033
- var import_editor_controls11 = require("@elementor/editor-controls");
2037
+ var import_editor_controls12 = require("@elementor/editor-controls");
2034
2038
  var import_editor_props4 = require("@elementor/editor-props");
2035
2039
 
2036
2040
  // src/components/variables-repeater-item-slot.tsx
@@ -2054,21 +2058,21 @@ var BoxShadowRepeaterColorIndicator = ({ value }) => {
2054
2058
 
2055
2059
  // src/repeater-injections.ts
2056
2060
  function registerRepeaterInjections() {
2057
- (0, import_editor_controls11.injectIntoRepeaterItemIcon)({
2061
+ (0, import_editor_controls12.injectIntoRepeaterItemIcon)({
2058
2062
  id: "color-variables-background-icon",
2059
2063
  component: BackgroundRepeaterColorIndicator,
2060
2064
  condition: ({ value: prop }) => {
2061
2065
  return hasAssignedColorVariable(import_editor_props4.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
2062
2066
  }
2063
2067
  });
2064
- (0, import_editor_controls11.injectIntoRepeaterItemIcon)({
2068
+ (0, import_editor_controls12.injectIntoRepeaterItemIcon)({
2065
2069
  id: "color-variables-icon",
2066
2070
  component: BoxShadowRepeaterColorIndicator,
2067
2071
  condition: ({ value: prop }) => {
2068
2072
  return hasAssignedColorVariable(import_editor_props4.shadowPropTypeUtil.extract(prop)?.color);
2069
2073
  }
2070
2074
  });
2071
- (0, import_editor_controls11.injectIntoRepeaterItemLabel)({
2075
+ (0, import_editor_controls12.injectIntoRepeaterItemLabel)({
2072
2076
  id: "color-variables-label",
2073
2077
  component: BackgroundRepeaterLabel,
2074
2078
  condition: ({ value: prop }) => {