@elementor/editor-variables 4.1.0-838 → 4.1.0-beta1
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 +33 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/global-styles-import-listener.tsx +3 -14
- package/src/components/variables-manager/hooks/use-variables-manager-state.ts +16 -2
- package/src/components/variables-manager/variables-manager-panel.tsx +0 -1
- package/src/init.ts +9 -1
- package/src/mcp/index.ts +0 -9
- package/src/mcp/manage-variable-tool.ts +11 -9
- package/src/mcp/variables-resource.ts +2 -2
- package/src/storage.ts +3 -1
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
|
|
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(
|
|
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
|
|
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
|
-
|
|
1503
|
+
useEffect2(() => {
|
|
1492
1504
|
onRowRef?.(rowRef?.current);
|
|
1493
1505
|
}, [onRowRef]);
|
|
1494
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2015
|
+
useEffect4(() => {
|
|
2004
2016
|
if (!embedded || !onExposeCloseAttempt) {
|
|
2005
2017
|
return;
|
|
2006
2018
|
}
|
|
@@ -2305,8 +2317,7 @@ function VariablesManagerPanelRoot({
|
|
|
2305
2317
|
display: "flex",
|
|
2306
2318
|
flexDirection: "column",
|
|
2307
2319
|
flex: 1,
|
|
2308
|
-
minHeight: 0
|
|
2309
|
-
overflow: "hidden"
|
|
2320
|
+
minHeight: 0
|
|
2310
2321
|
}
|
|
2311
2322
|
},
|
|
2312
2323
|
bodyInner
|
|
@@ -2351,7 +2362,7 @@ function VariablesManagerPanelRoot({
|
|
|
2351
2362
|
return embedded ? core : /* @__PURE__ */ React14.createElement(ThemeProvider, null, core);
|
|
2352
2363
|
}
|
|
2353
2364
|
var usePreventUnload = (isDirty) => {
|
|
2354
|
-
|
|
2365
|
+
useEffect4(() => {
|
|
2355
2366
|
const handleBeforeUnload = (event) => {
|
|
2356
2367
|
if (isDirty) {
|
|
2357
2368
|
event.preventDefault();
|
|
@@ -2392,18 +2403,11 @@ import { isExperimentActive as isExperimentActive2 } from "@elementor/editor-v1-
|
|
|
2392
2403
|
import { controlActionsMenu } from "@elementor/menus";
|
|
2393
2404
|
|
|
2394
2405
|
// src/components/global-styles-import-listener.tsx
|
|
2395
|
-
import { useEffect as
|
|
2406
|
+
import { useEffect as useEffect5 } from "react";
|
|
2396
2407
|
import { GLOBAL_STYLES_IMPORTED_EVENT } from "@elementor/editor-canvas";
|
|
2397
2408
|
function GlobalStylesImportListener() {
|
|
2398
|
-
|
|
2399
|
-
const handleGlobalStylesImported = (
|
|
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
|
-
}
|
|
2409
|
+
useEffect5(() => {
|
|
2410
|
+
const handleGlobalStylesImported = () => {
|
|
2407
2411
|
service.load();
|
|
2408
2412
|
};
|
|
2409
2413
|
window.addEventListener(GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
|
|
@@ -2415,7 +2419,7 @@ function GlobalStylesImportListener() {
|
|
|
2415
2419
|
}
|
|
2416
2420
|
|
|
2417
2421
|
// src/components/open-panel-from-event.tsx
|
|
2418
|
-
import { useEffect as
|
|
2422
|
+
import { useEffect as useEffect6, useRef as useRef7, useState as useState7 } from "react";
|
|
2419
2423
|
import {
|
|
2420
2424
|
__privateListenTo as listenTo,
|
|
2421
2425
|
__privateOpenRoute as openRoute,
|
|
@@ -2427,13 +2431,13 @@ function OpenPanelFromEvent() {
|
|
|
2427
2431
|
const { open } = usePanelActions();
|
|
2428
2432
|
const pendingRef = useRef7(false);
|
|
2429
2433
|
const [readyToOpen, setReadyToOpen] = useState7(false);
|
|
2430
|
-
|
|
2434
|
+
useEffect6(() => {
|
|
2431
2435
|
if (readyToOpen) {
|
|
2432
2436
|
setReadyToOpen(false);
|
|
2433
2437
|
open();
|
|
2434
2438
|
}
|
|
2435
2439
|
}, [readyToOpen, open]);
|
|
2436
|
-
|
|
2440
|
+
useEffect6(() => {
|
|
2437
2441
|
return listenTo(routeOpenEvent(DEFAULT_PANEL_ROUTE), () => {
|
|
2438
2442
|
if (pendingRef.current) {
|
|
2439
2443
|
pendingRef.current = false;
|
|
@@ -2441,7 +2445,7 @@ function OpenPanelFromEvent() {
|
|
|
2441
2445
|
}
|
|
2442
2446
|
});
|
|
2443
2447
|
}, []);
|
|
2444
|
-
|
|
2448
|
+
useEffect6(() => {
|
|
2445
2449
|
const handler = () => {
|
|
2446
2450
|
pendingRef.current = true;
|
|
2447
2451
|
openRoute(DEFAULT_PANEL_ROUTE);
|
|
@@ -2453,7 +2457,7 @@ function OpenPanelFromEvent() {
|
|
|
2453
2457
|
}
|
|
2454
2458
|
|
|
2455
2459
|
// src/components/open-panel-from-url.tsx
|
|
2456
|
-
import { useEffect as
|
|
2460
|
+
import { useEffect as useEffect7, useRef as useRef8 } from "react";
|
|
2457
2461
|
import { __privateListenTo as listenTo2, routeOpenEvent as routeOpenEvent2 } from "@elementor/editor-v1-adapters";
|
|
2458
2462
|
var ACTIVE_PANEL_PARAM = "active-panel";
|
|
2459
2463
|
var PANEL_ID = "variables-manager";
|
|
@@ -2461,7 +2465,7 @@ var DEFAULT_PANEL_ROUTE2 = "panel/elements";
|
|
|
2461
2465
|
function OpenPanelFromUrl() {
|
|
2462
2466
|
const { open } = usePanelActions();
|
|
2463
2467
|
const hasOpened = useRef8(false);
|
|
2464
|
-
|
|
2468
|
+
useEffect7(() => {
|
|
2465
2469
|
const urlParams = new URLSearchParams(window.location.search);
|
|
2466
2470
|
const activePanel = urlParams.get(ACTIVE_PANEL_PARAM);
|
|
2467
2471
|
if (activePanel !== PANEL_ID) {
|
|
@@ -2714,7 +2718,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
2714
2718
|
|
|
2715
2719
|
// src/components/variable-edit.tsx
|
|
2716
2720
|
import * as React19 from "react";
|
|
2717
|
-
import { useEffect as
|
|
2721
|
+
import { useEffect as useEffect8, useState as useState11 } from "react";
|
|
2718
2722
|
import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
|
|
2719
2723
|
import { useSuppressedMessage as useSuppressedMessage2 } from "@elementor/editor-current-user";
|
|
2720
2724
|
import { PopoverHeader as PopoverHeader2, SectionPopoverBody as SectionPopoverBody2 } from "@elementor/editor-ui";
|
|
@@ -2791,7 +2795,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2791
2795
|
const userPermissions = usePermissions();
|
|
2792
2796
|
const [value, setValue] = useState11(() => variable.value);
|
|
2793
2797
|
const [label, setLabel] = useState11(() => variable.label);
|
|
2794
|
-
|
|
2798
|
+
useEffect8(() => {
|
|
2795
2799
|
styleVariablesRepository.update({
|
|
2796
2800
|
[editId]: {
|
|
2797
2801
|
...variable,
|
|
@@ -2956,7 +2960,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2956
2960
|
};
|
|
2957
2961
|
|
|
2958
2962
|
// src/components/variables-selection.tsx
|
|
2959
|
-
import { useEffect as
|
|
2963
|
+
import { useEffect as useEffect9, useState as useState12 } from "react";
|
|
2960
2964
|
import * as React21 from "react";
|
|
2961
2965
|
import { trackUpgradePromotionClick as trackUpgradePromotionClick2, trackViewPromotion as trackViewPromotion2 } from "@elementor/editor-controls";
|
|
2962
2966
|
import {
|
|
@@ -3146,7 +3150,7 @@ var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings, disabled =
|
|
|
3146
3150
|
const handleClearSearch = () => {
|
|
3147
3151
|
setSearchValue("");
|
|
3148
3152
|
};
|
|
3149
|
-
|
|
3153
|
+
useEffect9(() => {
|
|
3150
3154
|
if (disabled) {
|
|
3151
3155
|
trackViewPromotion2({
|
|
3152
3156
|
target_name: "variables_popover",
|
|
@@ -3959,7 +3963,7 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
|
|
|
3959
3963
|
};
|
|
3960
3964
|
}
|
|
3961
3965
|
);
|
|
3962
|
-
window.addEventListener(
|
|
3966
|
+
window.addEventListener(STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated);
|
|
3963
3967
|
listenTo3(commandEndEvent("document/save/update"), notifyGlobalVariablesUpdated);
|
|
3964
3968
|
});
|
|
3965
3969
|
};
|
|
@@ -3974,7 +3978,9 @@ var initManageVariableTool = (reg) => {
|
|
|
3974
3978
|
id: z3.string().optional().describe("Variable id (required for update/delete). Get from list-global-variables."),
|
|
3975
3979
|
type: z3.string().optional().describe('Variable type: "global-color-variable" or "global-font-variable" (required for create)'),
|
|
3976
3980
|
label: z3.string().optional().describe("Variable label (required for create/update)"),
|
|
3977
|
-
value: z3.string().optional().describe(
|
|
3981
|
+
value: z3.string().optional().describe(
|
|
3982
|
+
"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."
|
|
3983
|
+
)
|
|
3978
3984
|
},
|
|
3979
3985
|
outputSchema: {
|
|
3980
3986
|
status: z3.enum(["ok"]).describe("Operation status"),
|
|
@@ -3990,14 +3996,11 @@ var initManageVariableTool = (reg) => {
|
|
|
3990
3996
|
description: "Global variables"
|
|
3991
3997
|
}
|
|
3992
3998
|
],
|
|
3993
|
-
description: `
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
# NAMING - IMPORTANT
|
|
3999
|
-
the variables names should ALWAYS be lowercased and dashed spaced. example: "Headline Primary" should be "headline-primary"
|
|
4000
|
-
`,
|
|
3999
|
+
description: `Create, update, or delete V4 global variables (distinct from legacy "globals").
|
|
4000
|
+
- Values: any valid CSS value, inserted as-is (1:1 with \`--css-var: VALUE\`). Do NOT pass JSON or legacy-globals object structures.
|
|
4001
|
+
- Names: lowercase, dash-separated (e.g. "Headline Primary" \u2192 "headline-primary").
|
|
4002
|
+
- Update: when renaming, keep the existing value; when updating value, keep the exact label.
|
|
4003
|
+
- Delete: destructive \u2014 confirm with user first.`,
|
|
4001
4004
|
handler: async (params) => {
|
|
4002
4005
|
const operations = getServiceActions(service);
|
|
4003
4006
|
const op = operations[params.action];
|
|
@@ -4046,15 +4049,6 @@ function getServiceActions(svc) {
|
|
|
4046
4049
|
|
|
4047
4050
|
// src/mcp/index.ts
|
|
4048
4051
|
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
4052
|
initManageVariableTool(reg);
|
|
4059
4053
|
initVariablesResource(reg, canvasMcpEntry);
|
|
4060
4054
|
}
|
|
@@ -4262,7 +4256,7 @@ function registerVariableTypes() {
|
|
|
4262
4256
|
|
|
4263
4257
|
// src/renderers/style-variables-renderer.tsx
|
|
4264
4258
|
import * as React38 from "react";
|
|
4265
|
-
import { useEffect as
|
|
4259
|
+
import { useEffect as useEffect10, useState as useState20 } from "react";
|
|
4266
4260
|
import {
|
|
4267
4261
|
__privateUseListenTo as useListenTo,
|
|
4268
4262
|
commandEndEvent as commandEndEvent2,
|
|
@@ -4286,7 +4280,7 @@ function usePortalContainer() {
|
|
|
4286
4280
|
}
|
|
4287
4281
|
function useStyleVariables() {
|
|
4288
4282
|
const [variables, setVariables] = useState20({});
|
|
4289
|
-
|
|
4283
|
+
useEffect10(() => {
|
|
4290
4284
|
const unsubscribe = styleVariablesRepository.subscribe(setVariables);
|
|
4291
4285
|
return () => {
|
|
4292
4286
|
unsubscribe();
|
|
@@ -4583,7 +4577,15 @@ function init() {
|
|
|
4583
4577
|
useProps: usePropVariableAction
|
|
4584
4578
|
});
|
|
4585
4579
|
service.init().then(() => {
|
|
4586
|
-
|
|
4580
|
+
const variablesMcpRegistry = getMCPByDomain("variables", {
|
|
4581
|
+
instructions: `Everything related to V4 ( Atomic ) variables.
|
|
4582
|
+
# Global variables
|
|
4583
|
+
- Create/update/delete global variables
|
|
4584
|
+
- Get list of global variables
|
|
4585
|
+
- Get details of a global variable
|
|
4586
|
+
`
|
|
4587
|
+
});
|
|
4588
|
+
initMcp(variablesMcpRegistry, getMCPByDomain("canvas"));
|
|
4587
4589
|
});
|
|
4588
4590
|
injectIntoTop({
|
|
4589
4591
|
id: "canvas-style-variables-render",
|