@elementor/editor-variables 4.2.0-841 → 4.2.0-843

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
@@ -1,6 +1,6 @@
1
1
  // src/components/variables-manager/variables-manager-panel.tsx
2
2
  import * as React14 from "react";
3
- import { useCallback as useCallback6, useEffect as useEffect3, useMemo as useMemo3, useState as useState6 } from "react";
3
+ import { useCallback as useCallback6, useEffect as useEffect4, useMemo as useMemo3, useState as useState6 } from "react";
4
4
  import { useSuppressedMessage } from "@elementor/editor-current-user";
5
5
  import {
6
6
  __createPanel as createPanel,
@@ -310,12 +310,13 @@ var buildOperationsArray = (originalVariables, currentVariables, deletedVariable
310
310
  // src/storage.ts
311
311
  var STORAGE_KEY = "elementor-global-variables";
312
312
  var STORAGE_WATERMARK_KEY = "elementor-global-variables-watermark";
313
+ var STORAGE_UPDATED_EVENT = "variables:updated";
313
314
  var OP_RW = "RW";
314
315
  var OP_RO = "RO";
315
316
  var Storage = class {
316
317
  state;
317
318
  notifyChange() {
318
- window.dispatchEvent(new Event("variables:updated"));
319
+ window.dispatchEvent(new Event(STORAGE_UPDATED_EVENT));
319
320
  }
320
321
  constructor() {
321
322
  this.state = {
@@ -871,7 +872,7 @@ var useErrorNavigation = () => {
871
872
  };
872
873
 
873
874
  // src/components/variables-manager/hooks/use-variables-manager-state.ts
874
- import { useCallback as useCallback3, useState as useState2 } from "react";
875
+ import { useCallback as useCallback3, useEffect, useState as useState2 } from "react";
875
876
 
876
877
  // src/hooks/use-prop-variables.ts
877
878
  import { useMemo } from "react";
@@ -1035,6 +1036,17 @@ var useVariablesManagerState = () => {
1035
1036
  const [isDirty, setIsDirty] = useState2(false);
1036
1037
  const [isSaving, setIsSaving] = useState2(false);
1037
1038
  const [searchValue, setSearchValue] = useState2("");
1039
+ useEffect(() => {
1040
+ const handleStorageUpdated = () => {
1041
+ setVariables(getVariables(false));
1042
+ setDeletedVariables([]);
1043
+ setIsDirty(false);
1044
+ };
1045
+ window.addEventListener(STORAGE_UPDATED_EVENT, handleStorageUpdated);
1046
+ return () => {
1047
+ window.removeEventListener(STORAGE_UPDATED_EVENT, handleStorageUpdated);
1048
+ };
1049
+ }, []);
1038
1050
  const handleOnChange = useCallback3(
1039
1051
  (newVariables) => {
1040
1052
  setVariables({ ...variables, ...newVariables });
@@ -1335,7 +1347,7 @@ var getDefaultName = (variables, baseName) => {
1335
1347
 
1336
1348
  // src/components/variables-manager/variables-manager-table.tsx
1337
1349
  import * as React13 from "react";
1338
- import { useEffect as useEffect2, useRef as useRef6 } from "react";
1350
+ import { useEffect as useEffect3, useRef as useRef6 } from "react";
1339
1351
  import {
1340
1352
  Table,
1341
1353
  TableBody,
@@ -1460,7 +1472,7 @@ var LabelField = ({
1460
1472
 
1461
1473
  // src/components/variables-manager/variable-editable-cell.tsx
1462
1474
  import * as React10 from "react";
1463
- import { useCallback as useCallback5, useEffect, useRef as useRef4, useState as useState5 } from "react";
1475
+ import { useCallback as useCallback5, useEffect as useEffect2, useRef as useRef4, useState as useState5 } from "react";
1464
1476
  import { ClickAwayListener, Stack as Stack4 } from "@elementor/ui";
1465
1477
  var VariableEditableCell = React10.memo(
1466
1478
  ({
@@ -1488,10 +1500,10 @@ var VariableEditableCell = React10.memo(
1488
1500
  }
1489
1501
  setIsEditing(false);
1490
1502
  }, [value, onChange, fieldType, labelFieldError, valueFieldError]);
1491
- useEffect(() => {
1503
+ useEffect2(() => {
1492
1504
  onRowRef?.(rowRef?.current);
1493
1505
  }, [onRowRef]);
1494
- useEffect(() => {
1506
+ useEffect2(() => {
1495
1507
  if (autoEdit && !isEditing && !disabled) {
1496
1508
  setIsEditing(true);
1497
1509
  onAutoEditComplete?.();
@@ -1832,7 +1844,7 @@ var VariablesManagerTable = ({
1832
1844
  }) => {
1833
1845
  const tableContainerRef = useRef6(null);
1834
1846
  const variableRowRefs = useRef6(/* @__PURE__ */ new Map());
1835
- useEffect2(() => {
1847
+ useEffect3(() => {
1836
1848
  if (autoEditVariableId && tableContainerRef.current) {
1837
1849
  const rowElement = variableRowRefs.current.get(autoEditVariableId);
1838
1850
  if (rowElement) {
@@ -2000,7 +2012,7 @@ function VariablesManagerPanelRoot({
2000
2012
  }
2001
2013
  void closePanel();
2002
2014
  }, [isDirty, openSaveChangesDialog, closePanel]);
2003
- useEffect3(() => {
2015
+ useEffect4(() => {
2004
2016
  if (!embedded || !onExposeCloseAttempt) {
2005
2017
  return;
2006
2018
  }
@@ -2351,7 +2363,7 @@ function VariablesManagerPanelRoot({
2351
2363
  return embedded ? core : /* @__PURE__ */ React14.createElement(ThemeProvider, null, core);
2352
2364
  }
2353
2365
  var usePreventUnload = (isDirty) => {
2354
- useEffect3(() => {
2366
+ useEffect4(() => {
2355
2367
  const handleBeforeUnload = (event) => {
2356
2368
  if (isDirty) {
2357
2369
  event.preventDefault();
@@ -2392,18 +2404,11 @@ import { isExperimentActive as isExperimentActive2 } from "@elementor/editor-v1-
2392
2404
  import { controlActionsMenu } from "@elementor/menus";
2393
2405
 
2394
2406
  // src/components/global-styles-import-listener.tsx
2395
- import { useEffect as useEffect4 } from "react";
2407
+ import { useEffect as useEffect5 } from "react";
2396
2408
  import { GLOBAL_STYLES_IMPORTED_EVENT } from "@elementor/editor-canvas";
2397
2409
  function GlobalStylesImportListener() {
2398
- useEffect4(() => {
2399
- const handleGlobalStylesImported = (event) => {
2400
- const importedVars = event.detail?.global_variables;
2401
- if (!importedVars) {
2402
- return;
2403
- }
2404
- if (importedVars.data && typeof importedVars.data === "object") {
2405
- styleVariablesRepository.update(importedVars.data);
2406
- }
2410
+ useEffect5(() => {
2411
+ const handleGlobalStylesImported = () => {
2407
2412
  service.load();
2408
2413
  };
2409
2414
  window.addEventListener(GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
@@ -2415,7 +2420,7 @@ function GlobalStylesImportListener() {
2415
2420
  }
2416
2421
 
2417
2422
  // src/components/open-panel-from-event.tsx
2418
- import { useEffect as useEffect5, useRef as useRef7, useState as useState7 } from "react";
2423
+ import { useEffect as useEffect6, useRef as useRef7, useState as useState7 } from "react";
2419
2424
  import {
2420
2425
  __privateListenTo as listenTo,
2421
2426
  __privateOpenRoute as openRoute,
@@ -2427,13 +2432,13 @@ function OpenPanelFromEvent() {
2427
2432
  const { open } = usePanelActions();
2428
2433
  const pendingRef = useRef7(false);
2429
2434
  const [readyToOpen, setReadyToOpen] = useState7(false);
2430
- useEffect5(() => {
2435
+ useEffect6(() => {
2431
2436
  if (readyToOpen) {
2432
2437
  setReadyToOpen(false);
2433
2438
  open();
2434
2439
  }
2435
2440
  }, [readyToOpen, open]);
2436
- useEffect5(() => {
2441
+ useEffect6(() => {
2437
2442
  return listenTo(routeOpenEvent(DEFAULT_PANEL_ROUTE), () => {
2438
2443
  if (pendingRef.current) {
2439
2444
  pendingRef.current = false;
@@ -2441,7 +2446,7 @@ function OpenPanelFromEvent() {
2441
2446
  }
2442
2447
  });
2443
2448
  }, []);
2444
- useEffect5(() => {
2449
+ useEffect6(() => {
2445
2450
  const handler = () => {
2446
2451
  pendingRef.current = true;
2447
2452
  openRoute(DEFAULT_PANEL_ROUTE);
@@ -2453,7 +2458,7 @@ function OpenPanelFromEvent() {
2453
2458
  }
2454
2459
 
2455
2460
  // src/components/open-panel-from-url.tsx
2456
- import { useEffect as useEffect6, useRef as useRef8 } from "react";
2461
+ import { useEffect as useEffect7, useRef as useRef8 } from "react";
2457
2462
  import { __privateListenTo as listenTo2, routeOpenEvent as routeOpenEvent2 } from "@elementor/editor-v1-adapters";
2458
2463
  var ACTIVE_PANEL_PARAM = "active-panel";
2459
2464
  var PANEL_ID = "variables-manager";
@@ -2461,7 +2466,7 @@ var DEFAULT_PANEL_ROUTE2 = "panel/elements";
2461
2466
  function OpenPanelFromUrl() {
2462
2467
  const { open } = usePanelActions();
2463
2468
  const hasOpened = useRef8(false);
2464
- useEffect6(() => {
2469
+ useEffect7(() => {
2465
2470
  const urlParams = new URLSearchParams(window.location.search);
2466
2471
  const activePanel = urlParams.get(ACTIVE_PANEL_PARAM);
2467
2472
  if (activePanel !== PANEL_ID) {
@@ -2714,7 +2719,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
2714
2719
 
2715
2720
  // src/components/variable-edit.tsx
2716
2721
  import * as React19 from "react";
2717
- import { useEffect as useEffect7, useState as useState11 } from "react";
2722
+ import { useEffect as useEffect8, useState as useState11 } from "react";
2718
2723
  import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
2719
2724
  import { useSuppressedMessage as useSuppressedMessage2 } from "@elementor/editor-current-user";
2720
2725
  import { PopoverHeader as PopoverHeader2, SectionPopoverBody as SectionPopoverBody2 } from "@elementor/editor-ui";
@@ -2791,7 +2796,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
2791
2796
  const userPermissions = usePermissions();
2792
2797
  const [value, setValue] = useState11(() => variable.value);
2793
2798
  const [label, setLabel] = useState11(() => variable.label);
2794
- useEffect7(() => {
2799
+ useEffect8(() => {
2795
2800
  styleVariablesRepository.update({
2796
2801
  [editId]: {
2797
2802
  ...variable,
@@ -2956,7 +2961,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
2956
2961
  };
2957
2962
 
2958
2963
  // src/components/variables-selection.tsx
2959
- import { useEffect as useEffect8, useState as useState12 } from "react";
2964
+ import { useEffect as useEffect9, useState as useState12 } from "react";
2960
2965
  import * as React21 from "react";
2961
2966
  import { trackUpgradePromotionClick as trackUpgradePromotionClick2, trackViewPromotion as trackViewPromotion2 } from "@elementor/editor-controls";
2962
2967
  import {
@@ -3146,7 +3151,7 @@ var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings, disabled =
3146
3151
  const handleClearSearch = () => {
3147
3152
  setSearchValue("");
3148
3153
  };
3149
- useEffect8(() => {
3154
+ useEffect9(() => {
3150
3155
  if (disabled) {
3151
3156
  trackViewPromotion2({
3152
3157
  target_name: "variables_popover",
@@ -3959,7 +3964,7 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3959
3964
  };
3960
3965
  }
3961
3966
  );
3962
- window.addEventListener("variables:updated", notifyGlobalVariablesUpdated);
3967
+ window.addEventListener(STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated);
3963
3968
  listenTo3(commandEndEvent("document/save/update"), notifyGlobalVariablesUpdated);
3964
3969
  });
3965
3970
  };
@@ -3974,7 +3979,9 @@ var initManageVariableTool = (reg) => {
3974
3979
  id: z3.string().optional().describe("Variable id (required for update/delete). Get from list-global-variables."),
3975
3980
  type: z3.string().optional().describe('Variable type: "global-color-variable" or "global-font-variable" (required for create)'),
3976
3981
  label: z3.string().optional().describe("Variable label (required for create/update)"),
3977
- value: z3.string().optional().describe("Variable value (required for create/update)")
3982
+ value: z3.string().optional().describe(
3983
+ "The variable value (required for create/update). Provide a plain CSS value matching the variable type (font: family name; color: CSS color; size: value with unit). Never JSON."
3984
+ )
3978
3985
  },
3979
3986
  outputSchema: {
3980
3987
  status: z3.enum(["ok"]).describe("Operation status"),
@@ -3990,14 +3997,11 @@ var initManageVariableTool = (reg) => {
3990
3997
  description: "Global variables"
3991
3998
  }
3992
3999
  ],
3993
- description: `Manages global variables (create/update/delete). Existing variables available in resources.
3994
- CREATE: requires type, label, value. Ensure label is unique.
3995
- UPDATE: requires id, label, value. When renaming: keep existing value. When updating value: keep exact label.
3996
- DELETE: requires id. DESTRUCTIVE - confirm with user first.
3997
-
3998
- # NAMING - IMPORTANT
3999
- the variables names should ALWAYS be lowercased and dashed spaced. example: "Headline Primary" should be "headline-primary"
4000
- `,
4000
+ description: `Create, update, or delete V4 global variables (distinct from legacy "globals").
4001
+ - Values: any valid CSS value, inserted as-is (1:1 with \`--css-var: VALUE\`). Do NOT pass JSON or legacy-globals object structures.
4002
+ - Names: lowercase, dash-separated (e.g. "Headline Primary" \u2192 "headline-primary").
4003
+ - Update: when renaming, keep the existing value; when updating value, keep the exact label.
4004
+ - Delete: destructive \u2014 confirm with user first.`,
4001
4005
  handler: async (params) => {
4002
4006
  const operations = getServiceActions(service);
4003
4007
  const op = operations[params.action];
@@ -4046,15 +4050,6 @@ function getServiceActions(svc) {
4046
4050
 
4047
4051
  // src/mcp/index.ts
4048
4052
  function initMcp(reg, canvasMcpEntry) {
4049
- const { setMCPDescription } = reg;
4050
- setMCPDescription(
4051
- `Everything related to V4 ( Atomic ) variables.
4052
- # Global variables
4053
- - Create/update/delete global variables
4054
- - Get list of global variables
4055
- - Get details of a global variable
4056
- `
4057
- );
4058
4053
  initManageVariableTool(reg);
4059
4054
  initVariablesResource(reg, canvasMcpEntry);
4060
4055
  }
@@ -4262,7 +4257,7 @@ function registerVariableTypes() {
4262
4257
 
4263
4258
  // src/renderers/style-variables-renderer.tsx
4264
4259
  import * as React38 from "react";
4265
- import { useEffect as useEffect9, useState as useState20 } from "react";
4260
+ import { useEffect as useEffect10, useState as useState20 } from "react";
4266
4261
  import {
4267
4262
  __privateUseListenTo as useListenTo,
4268
4263
  commandEndEvent as commandEndEvent2,
@@ -4286,7 +4281,7 @@ function usePortalContainer() {
4286
4281
  }
4287
4282
  function useStyleVariables() {
4288
4283
  const [variables, setVariables] = useState20({});
4289
- useEffect9(() => {
4284
+ useEffect10(() => {
4290
4285
  const unsubscribe = styleVariablesRepository.subscribe(setVariables);
4291
4286
  return () => {
4292
4287
  unsubscribe();
@@ -4583,7 +4578,15 @@ function init() {
4583
4578
  useProps: usePropVariableAction
4584
4579
  });
4585
4580
  service.init().then(() => {
4586
- initMcp(getMCPByDomain("variables"), getMCPByDomain("canvas"));
4581
+ const variablesMcpRegistry = getMCPByDomain("variables", {
4582
+ instructions: `Everything related to V4 ( Atomic ) variables.
4583
+ # Global variables
4584
+ - Create/update/delete global variables
4585
+ - Get list of global variables
4586
+ - Get details of a global variable
4587
+ `
4588
+ });
4589
+ initMcp(variablesMcpRegistry, getMCPByDomain("canvas"));
4587
4590
  });
4588
4591
  injectIntoTop({
4589
4592
  id: "canvas-style-variables-render",