@elementor/editor-variables 3.32.0-81 → 3.32.0-82

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
@@ -667,7 +667,7 @@ var React4 = __toESM(require("react"));
667
667
  var import_react4 = require("react");
668
668
  var import_icons = require("@elementor/icons");
669
669
  var import_ui4 = require("@elementor/ui");
670
- var VariableEditMenu = ({ menuActions, disabled }) => {
670
+ var VariableEditMenu = ({ menuActions, disabled, itemId }) => {
671
671
  const menuState = (0, import_ui4.usePopupState)({
672
672
  variant: "popover"
673
673
  });
@@ -699,7 +699,7 @@ var VariableEditMenu = ({ menuActions, disabled }) => {
699
699
  {
700
700
  key: action.name,
701
701
  onClick: () => {
702
- action.onClick?.();
702
+ action.onClick?.(itemId);
703
703
  menuState.close();
704
704
  },
705
705
  sx: {
@@ -724,7 +724,7 @@ var VariableEditableCell = ({
724
724
  initialValue,
725
725
  children,
726
726
  editableElement,
727
- onSave,
727
+ onChange,
728
728
  prefixElement
729
729
  }) => {
730
730
  const [value, setValue] = (0, import_react5.useState)(initialValue);
@@ -733,7 +733,7 @@ var VariableEditableCell = ({
733
733
  setIsEditing(true);
734
734
  };
735
735
  const handleSave = () => {
736
- onSave(value);
736
+ onChange(value);
737
737
  setIsEditing(false);
738
738
  };
739
739
  const handleKeyDown = (event) => {
@@ -751,7 +751,24 @@ var VariableEditableCell = ({
751
751
  setValue(newValue);
752
752
  };
753
753
  const editableContent = editableElement({ value, onChange: handleChange });
754
- return /* @__PURE__ */ React5.createElement(import_ui5.ClickAwayListener, { onClickAway: handleSave }, /* @__PURE__ */ React5.createElement(
754
+ if (isEditing) {
755
+ return /* @__PURE__ */ React5.createElement(import_ui5.ClickAwayListener, { onClickAway: handleSave }, /* @__PURE__ */ React5.createElement(
756
+ import_ui5.Stack,
757
+ {
758
+ direction: "row",
759
+ alignItems: "center",
760
+ gap: 1,
761
+ onDoubleClick: handleDoubleClick,
762
+ onKeyDown: handleKeyDown,
763
+ tabIndex: 0,
764
+ role: "button",
765
+ "aria-label": "Double click or press Space to edit"
766
+ },
767
+ prefixElement,
768
+ editableContent
769
+ ));
770
+ }
771
+ return /* @__PURE__ */ React5.createElement(
755
772
  import_ui5.Stack,
756
773
  {
757
774
  direction: "row",
@@ -764,8 +781,8 @@ var VariableEditableCell = ({
764
781
  "aria-label": "Double click or press Space to edit"
765
782
  },
766
783
  prefixElement,
767
- isEditing ? editableContent : children
768
- ));
784
+ children
785
+ );
769
786
  };
770
787
 
771
788
  // src/components/variables-manager/variable-table-cell.tsx
@@ -793,9 +810,9 @@ var VariableTableCell = ({
793
810
  };
794
811
 
795
812
  // src/components/variables-manager/variables-manager-table.tsx
796
- var VariablesManagerTable = ({ menuActions, variables }) => {
813
+ var VariablesManagerTable = ({ menuActions, variables, onChange: handleOnChange }) => {
797
814
  const [ids, setIds] = (0, import_react6.useState)(Object.keys(variables));
798
- const rows = ids.map((id2) => {
815
+ const rows = ids.filter((id2) => !variables[id2].deleted).map((id2) => {
799
816
  const variable = variables[id2];
800
817
  const variableType = getVariableType(variable.type);
801
818
  return {
@@ -885,7 +902,13 @@ var VariablesManagerTable = ({ menuActions, variables }) => {
885
902
  VariableEditableCell,
886
903
  {
887
904
  initialValue: row.name,
888
- onSave: () => {
905
+ onChange: (value) => {
906
+ if (value !== row.name) {
907
+ handleOnChange({
908
+ ...variables,
909
+ [row.id]: { ...variables[row.id], label: value }
910
+ });
911
+ }
889
912
  },
890
913
  prefixElement: (0, import_react6.createElement)(row.icon, { fontSize: "inherit" }),
891
914
  editableElement: ({ value, onChange }) => /* @__PURE__ */ React7.createElement(
@@ -912,7 +935,13 @@ var VariablesManagerTable = ({ menuActions, variables }) => {
912
935
  VariableEditableCell,
913
936
  {
914
937
  initialValue: row.value,
915
- onSave: () => {
938
+ onChange: (value) => {
939
+ if (value !== row.value) {
940
+ handleOnChange({
941
+ ...variables,
942
+ [row.id]: { ...variables[row.id], value }
943
+ });
944
+ }
916
945
  },
917
946
  editableElement: row.valueField
918
947
  },
@@ -939,7 +968,8 @@ var VariablesManagerTable = ({ menuActions, variables }) => {
939
968
  VariableEditMenu,
940
969
  {
941
970
  menuActions,
942
- disabled: isSorting
971
+ disabled: isSorting,
972
+ itemId: row.id
943
973
  }
944
974
  ))
945
975
  )
@@ -965,18 +995,26 @@ var { panel, usePanelActions } = (0, import_editor_panels.__createPanel)({
965
995
  });
966
996
  function VariablesManagerPanel() {
967
997
  const { close: closePanel } = usePanelActions();
968
- const isDirty = false;
969
- const variables = getVariables(false);
998
+ const [isDirty, setIsDirty] = (0, import_react7.useState)(false);
999
+ const [variables, setVariables] = (0, import_react7.useState)(getVariables(false));
1000
+ const [deletedVariables, setDeletedVariables] = (0, import_react7.useState)([]);
970
1001
  usePreventUnload(isDirty);
971
1002
  const menuActions = [
972
1003
  {
973
1004
  name: (0, import_i18n5.__)("Delete", "elementor"),
974
1005
  icon: import_icons3.TrashIcon,
975
1006
  color: "error.main",
976
- onClick: () => {
1007
+ onClick: (itemId) => {
1008
+ setDeletedVariables([...deletedVariables, itemId]);
1009
+ setVariables({ ...variables, [itemId]: { ...variables[itemId], deleted: true } });
1010
+ setIsDirty(true);
977
1011
  }
978
1012
  }
979
1013
  ];
1014
+ const handleOnChange = (newVariables) => {
1015
+ setVariables(newVariables);
1016
+ setIsDirty(true);
1017
+ };
980
1018
  return /* @__PURE__ */ React8.createElement(import_editor_ui2.ThemeProvider, null, /* @__PURE__ */ React8.createElement(import_ui8.ErrorBoundary, { fallback: /* @__PURE__ */ React8.createElement(ErrorBoundaryFallback, null) }, /* @__PURE__ */ React8.createElement(import_editor_panels.Panel, null, /* @__PURE__ */ React8.createElement(import_editor_panels.PanelHeader, null, /* @__PURE__ */ React8.createElement(import_ui8.Stack, { width: "100%", direction: "column", alignItems: "center" }, /* @__PURE__ */ React8.createElement(import_ui8.Stack, { p: 1, pl: 2, width: "100%", direction: "row", alignItems: "center" }, /* @__PURE__ */ React8.createElement(import_ui8.Stack, { width: "100%", direction: "row", gap: 1 }, /* @__PURE__ */ React8.createElement(import_editor_panels.PanelHeaderTitle, { sx: { display: "flex", alignItems: "center", gap: 0.5 } }, /* @__PURE__ */ React8.createElement(import_icons3.ColorFilterIcon, { fontSize: "inherit" }), (0, import_i18n5.__)("Variable Manager", "elementor"))), /* @__PURE__ */ React8.createElement(
981
1019
  CloseButton,
982
1020
  {
@@ -994,7 +1032,14 @@ function VariablesManagerPanel() {
994
1032
  height: "100%"
995
1033
  }
996
1034
  },
997
- /* @__PURE__ */ React8.createElement(VariablesManagerTable, { menuActions, variables })
1035
+ /* @__PURE__ */ React8.createElement(
1036
+ VariablesManagerTable,
1037
+ {
1038
+ menuActions,
1039
+ variables,
1040
+ onChange: handleOnChange
1041
+ }
1042
+ )
998
1043
  ), /* @__PURE__ */ React8.createElement(import_editor_panels.PanelFooter, null, /* @__PURE__ */ React8.createElement(import_ui8.Button, { fullWidth: true, size: "small", color: "global", variant: "contained", disabled: !isDirty }, (0, import_i18n5.__)("Save changes", "elementor"))))));
999
1044
  }
1000
1045
  var CloseButton = ({ onClose, ...props }) => /* @__PURE__ */ React8.createElement(import_ui8.IconButton, { size: "small", color: "secondary", onClick: onClose, "aria-label": "Close", ...props }, /* @__PURE__ */ React8.createElement(import_icons3.XIcon, { fontSize: "small" }));