@elementor/editor-variables 3.32.0-25 → 3.32.0-27

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
@@ -84,12 +84,12 @@ var usePreventUnload = (isDirty) => {
84
84
 
85
85
  // src/controls/variable-control.tsx
86
86
  import * as React24 from "react";
87
- import { useBoundProp as useBoundProp9 } from "@elementor/editor-controls";
87
+ import { useBoundProp as useBoundProp10 } from "@elementor/editor-controls";
88
88
 
89
89
  // src/components/ui/variable/assigned-variable.tsx
90
90
  import { useId as useId2, useRef } from "react";
91
91
  import * as React16 from "react";
92
- import { useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
92
+ import { useBoundProp as useBoundProp6 } from "@elementor/editor-controls";
93
93
  import { ColorFilterIcon as ColorFilterIcon2 } from "@elementor/icons";
94
94
  import { bindPopover, bindTrigger, Box as Box5, Popover, usePopupState } from "@elementor/ui";
95
95
 
@@ -455,6 +455,7 @@ function createVariableTypeRegistry() {
455
455
  valueField,
456
456
  propTypeUtil,
457
457
  variableType,
458
+ selectionFilter,
458
459
  fallbackPropTypeUtil
459
460
  }) => {
460
461
  if (variableTypes[propTypeUtil.key]) {
@@ -466,6 +467,7 @@ function createVariableTypeRegistry() {
466
467
  valueField,
467
468
  propTypeUtil,
468
469
  variableType,
470
+ selectionFilter,
469
471
  fallbackPropTypeUtil
470
472
  };
471
473
  registerTransformer(propTypeUtil.key);
@@ -544,7 +546,7 @@ var usePermissions = () => {
544
546
  // src/components/variable-creation.tsx
545
547
  import * as React6 from "react";
546
548
  import { useState as useState3 } from "react";
547
- import { PopoverContent, useBoundProp as useBoundProp2 } from "@elementor/editor-controls";
549
+ import { PopoverContent, useBoundProp as useBoundProp3 } from "@elementor/editor-controls";
548
550
  import { PopoverBody } from "@elementor/editor-editing-panel";
549
551
  import { PopoverHeader } from "@elementor/editor-ui";
550
552
  import { ArrowLeftIcon } from "@elementor/icons";
@@ -552,10 +554,11 @@ import { Button as Button2, CardActions, Divider as Divider2, FormHelperText as
552
554
  import { __ as __6 } from "@wordpress/i18n";
553
555
 
554
556
  // src/hooks/use-initial-value.ts
555
- import { useBoundProp } from "@elementor/editor-controls";
557
+ import { useBoundProp as useBoundProp2 } from "@elementor/editor-controls";
556
558
 
557
559
  // src/hooks/use-prop-variables.ts
558
560
  import { useMemo } from "react";
561
+ import { useBoundProp } from "@elementor/editor-controls";
559
562
  var useVariable = (key) => {
560
563
  const variables = service.variables();
561
564
  if (!variables?.[key]) {
@@ -567,16 +570,24 @@ var useVariable = (key) => {
567
570
  };
568
571
  };
569
572
  var useFilteredVariables = (searchValue, propTypeKey) => {
570
- const variables = usePropVariables(propTypeKey);
571
- const filteredVariables = variables.filter(({ label }) => {
572
- return label.toLowerCase().includes(searchValue.toLowerCase());
573
- });
573
+ const baseVariables = usePropVariables(propTypeKey);
574
+ const typeFilteredVariables = useVariableSelectionFilter(baseVariables);
575
+ const searchFilteredVariables = filterVariablesBySearchValue(typeFilteredVariables, searchValue);
574
576
  return {
575
- list: filteredVariables,
576
- hasMatches: filteredVariables.length > 0,
577
- isSourceNotEmpty: variables.length > 0
577
+ list: searchFilteredVariables,
578
+ hasMatches: searchFilteredVariables.length > 0,
579
+ isSourceNotEmpty: typeFilteredVariables.length > 0
578
580
  };
579
581
  };
582
+ var useVariableSelectionFilter = (variables) => {
583
+ const { selectionFilter } = useVariableType();
584
+ const { propType } = useBoundProp();
585
+ return selectionFilter ? selectionFilter(variables, propType) : variables;
586
+ };
587
+ var filterVariablesBySearchValue = (variables, searchValue) => {
588
+ const lowerSearchValue = searchValue.toLowerCase();
589
+ return variables.filter(({ label }) => label.toLowerCase().includes(lowerSearchValue));
590
+ };
580
591
  var usePropVariables = (propKey) => {
581
592
  return useMemo(() => normalizeVariables(propKey), [propKey]);
582
593
  };
@@ -589,30 +600,23 @@ var normalizeVariables = (propKey) => {
589
600
  value
590
601
  }));
591
602
  };
603
+ var extractId = ({ id: id2 }) => id2;
592
604
  var createVariable = (newVariable) => {
593
- return service.create(newVariable).then(({ id: id2 }) => {
594
- return id2;
595
- });
605
+ return service.create(newVariable).then(extractId);
596
606
  };
597
607
  var updateVariable = (updateId, { value, label }) => {
598
- return service.update(updateId, { value, label }).then(({ id: id2 }) => {
599
- return id2;
600
- });
608
+ return service.update(updateId, { value, label }).then(extractId);
601
609
  };
602
610
  var deleteVariable = (deleteId) => {
603
- return service.delete(deleteId).then(({ id: id2 }) => {
604
- return id2;
605
- });
611
+ return service.delete(deleteId).then(extractId);
606
612
  };
607
613
  var restoreVariable = (restoreId, label, value) => {
608
- return service.restore(restoreId, label, value).then(({ id: id2 }) => {
609
- return id2;
610
- });
614
+ return service.restore(restoreId, label, value).then(extractId);
611
615
  };
612
616
 
613
617
  // src/hooks/use-initial-value.ts
614
618
  var useInitialValue = () => {
615
- const { value: initial } = useBoundProp();
619
+ const { value: initial } = useBoundProp2();
616
620
  const hasAssignedVariable2 = hasVariableType(initial?.$$type) && Boolean(initial?.value);
617
621
  const variable = useVariable(hasAssignedVariable2 ? initial.value : "");
618
622
  if (hasAssignedVariable2) {
@@ -742,7 +746,7 @@ var LabelField = ({ value, error, onChange }) => {
742
746
  var SIZE = "tiny";
743
747
  var VariableCreation = ({ onGoBack, onClose }) => {
744
748
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
745
- const { setValue: setVariable, path } = useBoundProp2(propTypeUtil);
749
+ const { setValue: setVariable, path } = useBoundProp3(propTypeUtil);
746
750
  const initialValue = useInitialValue();
747
751
  const [value, setValue] = useState3(initialValue);
748
752
  const [label, setLabel] = useState3("");
@@ -822,7 +826,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
822
826
  // src/components/variable-edit.tsx
823
827
  import * as React9 from "react";
824
828
  import { useEffect as useEffect2, useState as useState5 } from "react";
825
- import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp3 } from "@elementor/editor-controls";
829
+ import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp4 } from "@elementor/editor-controls";
826
830
  import { useSuppressedMessage } from "@elementor/editor-current-user";
827
831
  import { PopoverBody as PopoverBody2 } from "@elementor/editor-editing-panel";
828
832
  import { PopoverHeader as PopoverHeader2 } from "@elementor/editor-ui";
@@ -905,7 +909,7 @@ var EditConfirmationDialog = ({
905
909
  var SIZE2 = "tiny";
906
910
  var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
907
911
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
908
- const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp3(propTypeUtil);
912
+ const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp4(propTypeUtil);
909
913
  const [isMessageSuppressed, suppressMessage] = useSuppressedMessage(EDIT_CONFIRMATION_DIALOG_ID);
910
914
  const [deleteConfirmation, setDeleteConfirmation] = useState5(false);
911
915
  const [editConfirmation, setEditConfirmation] = useState5(false);
@@ -1059,7 +1063,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
1059
1063
  // src/components/variables-selection.tsx
1060
1064
  import * as React13 from "react";
1061
1065
  import { useState as useState6 } from "react";
1062
- import { useBoundProp as useBoundProp4 } from "@elementor/editor-controls";
1066
+ import { useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
1063
1067
  import { PopoverBody as PopoverBody3 } from "@elementor/editor-editing-panel";
1064
1068
  import { PopoverHeader as PopoverHeader3, PopoverMenuList, PopoverSearch } from "@elementor/editor-ui";
1065
1069
  import { ColorFilterIcon, PlusIcon, SettingsIcon } from "@elementor/icons";
@@ -1219,7 +1223,7 @@ var VariablesStyledMenuList = styled2(MenuList)(({ theme }) => ({
1219
1223
  var SIZE4 = "tiny";
1220
1224
  var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
1221
1225
  const { icon: VariableIcon, startIcon, variableType, propTypeUtil } = useVariableType();
1222
- const { value: variable, setValue: setVariable, path } = useBoundProp4(propTypeUtil);
1226
+ const { value: variable, setValue: setVariable, path } = useBoundProp5(propTypeUtil);
1223
1227
  const [searchValue, setSearchValue] = useState6("");
1224
1228
  const {
1225
1229
  list: variables,
@@ -1424,7 +1428,7 @@ var AssignedTag = ({ startIcon, label, onUnlink, ...props }) => {
1424
1428
  // src/components/ui/variable/assigned-variable.tsx
1425
1429
  var AssignedVariable = ({ variable, propTypeKey }) => {
1426
1430
  const { fallbackPropTypeUtil, startIcon, propTypeUtil } = getVariableType(propTypeKey);
1427
- const { setValue } = useBoundProp5();
1431
+ const { setValue } = useBoundProp6();
1428
1432
  const anchorRef = useRef(null);
1429
1433
  const popupId = useId2();
1430
1434
  const popupState = usePopupState({
@@ -1470,13 +1474,13 @@ var AssignedVariable = ({ variable, propTypeKey }) => {
1470
1474
  // src/components/ui/variable/deleted-variable.tsx
1471
1475
  import * as React20 from "react";
1472
1476
  import { useId as useId3, useRef as useRef2, useState as useState9 } from "react";
1473
- import { useBoundProp as useBoundProp7 } from "@elementor/editor-controls";
1477
+ import { useBoundProp as useBoundProp8 } from "@elementor/editor-controls";
1474
1478
  import { Backdrop, bindPopover as bindPopover2, Box as Box7, Infotip, Popover as Popover2, usePopupState as usePopupState2 } from "@elementor/ui";
1475
1479
 
1476
1480
  // src/components/variable-restore.tsx
1477
1481
  import * as React17 from "react";
1478
1482
  import { useState as useState8 } from "react";
1479
- import { PopoverContent as PopoverContent3, useBoundProp as useBoundProp6 } from "@elementor/editor-controls";
1483
+ import { PopoverContent as PopoverContent3, useBoundProp as useBoundProp7 } from "@elementor/editor-controls";
1480
1484
  import { PopoverBody as PopoverBody4 } from "@elementor/editor-editing-panel";
1481
1485
  import { PopoverHeader as PopoverHeader4 } from "@elementor/editor-ui";
1482
1486
  import { Button as Button7, CardActions as CardActions3, Divider as Divider5, FormHelperText as FormHelperText4 } from "@elementor/ui";
@@ -1484,7 +1488,7 @@ import { __ as __15 } from "@wordpress/i18n";
1484
1488
  var SIZE6 = "tiny";
1485
1489
  var VariableRestore = ({ variableId, onClose, onSubmit }) => {
1486
1490
  const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
1487
- const { setValue: notifyBoundPropChange } = useBoundProp6(propTypeUtil);
1491
+ const { setValue: notifyBoundPropChange } = useBoundProp7(propTypeUtil);
1488
1492
  const variable = useVariable(variableId);
1489
1493
  if (!variable) {
1490
1494
  throw new Error(`Global ${variableType} variable not found`);
@@ -1612,7 +1616,7 @@ var DeletedTag = React19.forwardRef(({ label, onClick, ...props }, ref) => {
1612
1616
  // src/components/ui/variable/deleted-variable.tsx
1613
1617
  var DeletedVariable = ({ variable, propTypeKey }) => {
1614
1618
  const { fallbackPropTypeUtil, propTypeUtil } = getVariableType(propTypeKey);
1615
- const { setValue } = useBoundProp7();
1619
+ const { setValue } = useBoundProp8();
1616
1620
  const userPermissions = usePermissions();
1617
1621
  const [showInfotip, setShowInfotip] = useState9(false);
1618
1622
  const toggleInfotip = () => setShowInfotip((prev) => !prev);
@@ -1701,7 +1705,7 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
1701
1705
  // src/components/ui/variable/missing-variable.tsx
1702
1706
  import * as React23 from "react";
1703
1707
  import { useState as useState10 } from "react";
1704
- import { useBoundProp as useBoundProp8 } from "@elementor/editor-controls";
1708
+ import { useBoundProp as useBoundProp9 } from "@elementor/editor-controls";
1705
1709
  import { Backdrop as Backdrop2, Infotip as Infotip2 } from "@elementor/ui";
1706
1710
  import { __ as __19 } from "@wordpress/i18n";
1707
1711
 
@@ -1758,7 +1762,7 @@ var MissingTag = React22.forwardRef(({ label, onClick, ...props }, ref) => {
1758
1762
 
1759
1763
  // src/components/ui/variable/missing-variable.tsx
1760
1764
  var MissingVariable = () => {
1761
- const { setValue } = useBoundProp8();
1765
+ const { setValue } = useBoundProp9();
1762
1766
  const [infotipVisible, setInfotipVisible] = useState10(false);
1763
1767
  const toggleInfotip = () => setInfotipVisible((prev) => !prev);
1764
1768
  const closeInfotip = () => setInfotipVisible(false);
@@ -1789,7 +1793,7 @@ var MissingVariable = () => {
1789
1793
 
1790
1794
  // src/controls/variable-control.tsx
1791
1795
  var VariableControl = () => {
1792
- const boundProp = useBoundProp9().value;
1796
+ const boundProp = useBoundProp10().value;
1793
1797
  const assignedVariable = useVariable(boundProp?.value);
1794
1798
  if (!assignedVariable) {
1795
1799
  return /* @__PURE__ */ React24.createElement(MissingVariable, null);
@@ -1803,11 +1807,11 @@ var VariableControl = () => {
1803
1807
 
1804
1808
  // src/hooks/use-prop-variable-action.tsx
1805
1809
  import * as React25 from "react";
1806
- import { useBoundProp as useBoundProp10 } from "@elementor/editor-editing-panel";
1810
+ import { useBoundProp as useBoundProp11 } from "@elementor/editor-editing-panel";
1807
1811
  import { ColorFilterIcon as ColorFilterIcon3 } from "@elementor/icons";
1808
1812
  import { __ as __20 } from "@wordpress/i18n";
1809
1813
  var usePropVariableAction = () => {
1810
- const { propType, path } = useBoundProp10();
1814
+ const { propType, path } = useBoundProp11();
1811
1815
  const variable = resolveVariableFromPropType(propType);
1812
1816
  return {
1813
1817
  visible: Boolean(variable),