@elementor/editor-variables 4.1.0-720 → 4.1.0-722

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
@@ -45,6 +45,7 @@ module.exports = __toCommonJS(index_exports);
45
45
  // src/init.ts
46
46
  var import_editor = require("@elementor/editor");
47
47
  var import_editor_controls18 = require("@elementor/editor-controls");
48
+ var import_editor_mcp = require("@elementor/editor-mcp");
48
49
  var import_editor_panels2 = require("@elementor/editor-panels");
49
50
  var import_editor_props7 = require("@elementor/editor-props");
50
51
  var import_menus = require("@elementor/menus");
@@ -538,6 +539,26 @@ var trackVariablesManagerEvent = ({ action, varType, controlPath }) => {
538
539
  }
539
540
  dispatchEvent?.(name, eventData);
540
541
  };
542
+ var trackVariableSyncToV3 = ({ variableLabel, action }) => {
543
+ try {
544
+ const { dispatchEvent, config } = (0, import_events.getMixpanel)();
545
+ if (!config?.names?.variables?.variableSyncToV3) {
546
+ return;
547
+ }
548
+ const name = config.names.variables.variableSyncToV3;
549
+ const isSync = action === "sync";
550
+ dispatchEvent?.(name, {
551
+ interaction_type: "click",
552
+ target_type: variableLabel,
553
+ target_name: isSync ? "sync_to_v3" : "unsync_to_v3",
554
+ interaction_result: isSync ? "var_is_synced_to_V3" : "var_is_unsynced_from_V3",
555
+ target_location: "widget_panel",
556
+ location_l1: "var_manager",
557
+ interaction_description: isSync ? `user_synced_${variableLabel}_to_v3` : `user_unsync_${variableLabel}_from_v3`
558
+ });
559
+ } catch {
560
+ }
561
+ };
541
562
 
542
563
  // src/utils/validations.ts
543
564
  var import_icons = require("@elementor/icons");
@@ -1932,8 +1953,8 @@ function VariablesManagerPanel() {
1932
1953
  handleOnChange,
1933
1954
  createVariable: createVariable2,
1934
1955
  handleDeleteVariable,
1935
- handleStartSync,
1936
- handleStopSync,
1956
+ handleStartSync: startSyncFromState,
1957
+ handleStopSync: stopSyncFromState,
1937
1958
  handleSave,
1938
1959
  isSaving,
1939
1960
  handleSearch,
@@ -1994,22 +2015,35 @@ function VariablesManagerPanel() {
1994
2015
  },
1995
2016
  [handleDeleteVariable]
1996
2017
  );
1997
- const handleStopSyncWithConfirmation = (0, import_react14.useCallback)(
2018
+ const commitStopSync = (0, import_react14.useCallback)(
2019
+ (itemId) => {
2020
+ stopSyncFromState(itemId);
2021
+ const variable = variables[itemId];
2022
+ if (variable) {
2023
+ trackVariableSyncToV3({ variableLabel: variable.label, action: "unsync" });
2024
+ }
2025
+ },
2026
+ [stopSyncFromState, variables]
2027
+ );
2028
+ const handleStartSync = (0, import_react14.useCallback)(
1998
2029
  (itemId) => {
1999
- handleStopSync(itemId);
2000
- setStopSyncConfirmation(null);
2030
+ startSyncFromState(itemId);
2031
+ const variable = variables[itemId];
2032
+ if (variable) {
2033
+ trackVariableSyncToV3({ variableLabel: variable.label, action: "sync" });
2034
+ }
2001
2035
  },
2002
- [handleStopSync]
2036
+ [startSyncFromState, variables]
2003
2037
  );
2004
- const handleShowStopSyncDialog = (0, import_react14.useCallback)(
2038
+ const handleStopSync = (0, import_react14.useCallback)(
2005
2039
  (itemId) => {
2006
2040
  if (!isStopSyncSuppressed) {
2007
2041
  setStopSyncConfirmation(itemId);
2008
2042
  } else {
2009
- handleStopSync(itemId);
2043
+ commitStopSync(itemId);
2010
2044
  }
2011
2045
  },
2012
- [isStopSyncSuppressed, handleStopSync]
2046
+ [isStopSyncSuppressed, commitStopSync]
2013
2047
  );
2014
2048
  const buildMenuActions = (0, import_react14.useCallback)(
2015
2049
  (variableId) => {
@@ -2022,7 +2056,7 @@ function VariablesManagerPanel() {
2022
2056
  variableId,
2023
2057
  handlers: {
2024
2058
  onStartSync: handleStartSync,
2025
- onStopSync: handleShowStopSyncDialog
2059
+ onStopSync: handleStopSync
2026
2060
  }
2027
2061
  });
2028
2062
  const deleteAction = {
@@ -2040,7 +2074,7 @@ function VariablesManagerPanel() {
2040
2074
  };
2041
2075
  return [...typeActions, deleteAction];
2042
2076
  },
2043
- [variables, handleStartSync, handleShowStopSyncDialog]
2077
+ [variables, handleStartSync, handleStopSync]
2044
2078
  );
2045
2079
  const hasVariables = Object.keys(variables).length > 0;
2046
2080
  return /* @__PURE__ */ React14.createElement(import_editor_ui5.ThemeProvider, null, /* @__PURE__ */ React14.createElement(import_editor_panels.Panel, null, /* @__PURE__ */ React14.createElement(
@@ -2175,7 +2209,10 @@ function VariablesManagerPanel() {
2175
2209
  {
2176
2210
  open: true,
2177
2211
  onClose: () => setStopSyncConfirmation(null),
2178
- onConfirm: () => handleStopSyncWithConfirmation(stopSyncConfirmation)
2212
+ onConfirm: () => {
2213
+ commitStopSync(stopSyncConfirmation);
2214
+ setStopSyncConfirmation(null);
2215
+ }
2179
2216
  }
2180
2217
  ), isSaveChangesDialogOpen && /* @__PURE__ */ React14.createElement(import_editor_ui5.SaveChangesDialog, null, /* @__PURE__ */ React14.createElement(import_editor_ui5.SaveChangesDialog.Title, { onClose: closeSaveChangesDialog }, (0, import_i18n10.__)("You have unsaved changes", "elementor")), /* @__PURE__ */ React14.createElement(import_editor_ui5.SaveChangesDialog.Content, null, /* @__PURE__ */ React14.createElement(import_editor_ui5.SaveChangesDialog.ContentText, null, (0, import_i18n10.__)("To avoid losing your updates, save your changes before leaving.", "elementor"))), /* @__PURE__ */ React14.createElement(
2181
2218
  import_editor_ui5.SaveChangesDialog.Actions,
@@ -3714,22 +3751,15 @@ var trackOpenVariablePopover = (path, variableType) => {
3714
3751
  });
3715
3752
  };
3716
3753
 
3717
- // src/mcp/index.ts
3718
- var import_editor_mcp3 = require("@elementor/editor-mcp");
3719
-
3720
3754
  // src/mcp/manage-variable-tool.ts
3721
- var import_editor_mcp2 = require("@elementor/editor-mcp");
3722
3755
  var import_schema3 = require("@elementor/schema");
3723
3756
 
3724
3757
  // src/mcp/variables-resource.ts
3725
- var import_editor_mcp = require("@elementor/editor-mcp");
3726
3758
  var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3727
- var initVariablesResource = () => {
3728
- const canvasMcpEntry = (0, import_editor_mcp.getMCPByDomain)("canvas");
3729
- const variablesMcpEntry = (0, import_editor_mcp.getMCPByDomain)("variables");
3759
+ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3730
3760
  [canvasMcpEntry, variablesMcpEntry].forEach((entry) => {
3731
- const { mcpServer } = entry;
3732
- mcpServer.resource(
3761
+ const { resource, sendResourceUpdated } = entry;
3762
+ resource(
3733
3763
  "global-variables",
3734
3764
  GLOBAL_VARIABLES_URI,
3735
3765
  {
@@ -3748,7 +3778,7 @@ var initVariablesResource = () => {
3748
3778
  }
3749
3779
  );
3750
3780
  window.addEventListener("variables:updated", () => {
3751
- mcpServer.server.sendResourceUpdated({
3781
+ sendResourceUpdated({
3752
3782
  uri: GLOBAL_VARIABLES_URI
3753
3783
  });
3754
3784
  });
@@ -3756,8 +3786,9 @@ var initVariablesResource = () => {
3756
3786
  };
3757
3787
 
3758
3788
  // src/mcp/manage-variable-tool.ts
3759
- var initManageVariableTool = () => {
3760
- (0, import_editor_mcp2.getMCPByDomain)("variables").addTool({
3789
+ var initManageVariableTool = (reg) => {
3790
+ const { addTool } = reg;
3791
+ addTool({
3761
3792
  name: "manage-global-variable",
3762
3793
  schema: {
3763
3794
  action: import_schema3.z.enum(["create", "update", "delete"]).describe("Operation to perform"),
@@ -3827,12 +3858,18 @@ function getServiceActions(svc) {
3827
3858
  }
3828
3859
 
3829
3860
  // src/mcp/index.ts
3830
- function initMcp() {
3831
- if (!(0, import_editor_mcp3.isAngieAvailable)()) {
3832
- return;
3833
- }
3834
- initManageVariableTool();
3835
- initVariablesResource();
3861
+ function initMcp(reg, canvasMcpEntry) {
3862
+ const { setMCPDescription } = reg;
3863
+ setMCPDescription(
3864
+ `Everything related to V4 ( Atomic ) variables.
3865
+ # Global variables
3866
+ - Create/update/delete global variables
3867
+ - Get list of global variables
3868
+ - Get details of a global variable
3869
+ `
3870
+ );
3871
+ initManageVariableTool(reg);
3872
+ initVariablesResource(reg, canvasMcpEntry);
3836
3873
  }
3837
3874
 
3838
3875
  // src/register-variable-types.tsx
@@ -4150,7 +4187,7 @@ function init() {
4150
4187
  useProps: usePropVariableAction
4151
4188
  });
4152
4189
  service.init().then(() => {
4153
- initMcp();
4190
+ initMcp((0, import_editor_mcp.getMCPByDomain)("variables"), (0, import_editor_mcp.getMCPByDomain)("canvas"));
4154
4191
  });
4155
4192
  (0, import_editor.injectIntoTop)({
4156
4193
  id: "canvas-style-variables-render",