@elementor/editor-variables 4.3.0-947 → 4.3.0-949
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.d.mts +27 -11
- package/dist/index.d.ts +27 -11
- package/dist/index.js +229 -134
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/mcp-variable-connect-listener.tsx +31 -0
- package/src/components/variable-creation.tsx +9 -13
- package/src/components/variable-edit.tsx +2 -2
- package/src/hooks/use-prop-variables.ts +6 -5
- package/src/init.ts +6 -0
- package/src/mcp/manage-variable-tool.ts +2 -2
- package/src/service.ts +32 -2
- package/src/utils/extract-variables-from-style-value.ts +55 -0
- package/src/utils/tracking.ts +27 -9
package/dist/index.mjs
CHANGED
|
@@ -10,20 +10,31 @@ import { __ as __10 } from "@wordpress/i18n";
|
|
|
10
10
|
|
|
11
11
|
// src/utils/tracking.ts
|
|
12
12
|
import { getMixpanel } from "@elementor/events";
|
|
13
|
-
var trackVariableEvent = ({ varType, controlPath, action }) => {
|
|
13
|
+
var trackVariableEvent = ({ varType, controlPath, action, executedBy }) => {
|
|
14
14
|
const { dispatchEvent, config } = getMixpanel();
|
|
15
15
|
if (!config?.names?.variables?.[action]) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
const name = config.names.variables[action];
|
|
19
|
-
|
|
20
|
-
location: config?.locations?.variables || "",
|
|
21
|
-
secondaryLocation: config?.secondaryLocations?.variablesPopover || "",
|
|
22
|
-
trigger: config?.triggers?.click || "",
|
|
19
|
+
let eventData = {
|
|
23
20
|
var_type: varType,
|
|
24
|
-
control_path: controlPath,
|
|
25
21
|
action_type: name
|
|
26
|
-
}
|
|
22
|
+
};
|
|
23
|
+
if (executedBy) {
|
|
24
|
+
eventData.executed_by = executedBy;
|
|
25
|
+
}
|
|
26
|
+
const defaultLocationInfo = {
|
|
27
|
+
location: config?.locations?.variables || "",
|
|
28
|
+
secondaryLocation: config?.secondaryLocations?.variablesPopover || "",
|
|
29
|
+
trigger: config?.triggers?.click || ""
|
|
30
|
+
};
|
|
31
|
+
if (!executedBy || executedBy !== "mcp_tool") {
|
|
32
|
+
eventData = { ...defaultLocationInfo, ...eventData };
|
|
33
|
+
}
|
|
34
|
+
if (controlPath) {
|
|
35
|
+
eventData.control_path = controlPath;
|
|
36
|
+
}
|
|
37
|
+
dispatchEvent?.(name, eventData);
|
|
27
38
|
};
|
|
28
39
|
var trackVariablesManagerEvent = ({ action, source, varType, controlPath }) => {
|
|
29
40
|
const { dispatchEvent, config } = getMixpanel();
|
|
@@ -465,7 +476,7 @@ var service = {
|
|
|
465
476
|
return variables;
|
|
466
477
|
});
|
|
467
478
|
},
|
|
468
|
-
create: ({ type, label, value }) => {
|
|
479
|
+
create: ({ type, label, value }, options = {}) => {
|
|
469
480
|
return apiClient.create(type, label, value).then((response) => {
|
|
470
481
|
const { success, data: payload } = response.data;
|
|
471
482
|
if (!success) {
|
|
@@ -481,13 +492,18 @@ var service = {
|
|
|
481
492
|
styleVariablesRepository.update({
|
|
482
493
|
[variableId]: createdVariable
|
|
483
494
|
});
|
|
495
|
+
trackVariableEvent({
|
|
496
|
+
varType: type,
|
|
497
|
+
action: "save",
|
|
498
|
+
...options.eventData
|
|
499
|
+
});
|
|
484
500
|
return {
|
|
485
501
|
id: variableId,
|
|
486
502
|
variable: createdVariable
|
|
487
503
|
};
|
|
488
504
|
});
|
|
489
505
|
},
|
|
490
|
-
update: (id, { label, value, type }) => {
|
|
506
|
+
update: (id, { label, value, type }, options = {}) => {
|
|
491
507
|
return apiClient.update(id, label, value, type).then((response) => {
|
|
492
508
|
const { success, data: payload } = response.data;
|
|
493
509
|
if (!success) {
|
|
@@ -503,6 +519,11 @@ var service = {
|
|
|
503
519
|
styleVariablesRepository.update({
|
|
504
520
|
[variableId]: updatedVariable
|
|
505
521
|
});
|
|
522
|
+
trackVariableEvent({
|
|
523
|
+
varType: updatedVariable.type,
|
|
524
|
+
action: "update",
|
|
525
|
+
...options.eventData
|
|
526
|
+
});
|
|
506
527
|
return {
|
|
507
528
|
id: variableId,
|
|
508
529
|
variable: updatedVariable
|
|
@@ -979,11 +1000,11 @@ var normalizeVariables = (propKey) => {
|
|
|
979
1000
|
return variablesToList(variables).filter((variable) => matchingTypes.includes(variable.type)).map(toNormalizedVariable);
|
|
980
1001
|
};
|
|
981
1002
|
var extractId = ({ id }) => id;
|
|
982
|
-
var createVariable = (newVariable) => {
|
|
983
|
-
return service.create(newVariable).then(extractId);
|
|
1003
|
+
var createVariable = (newVariable, options) => {
|
|
1004
|
+
return service.create(newVariable, options).then(extractId);
|
|
984
1005
|
};
|
|
985
|
-
var updateVariable = (updateId, { value, label, type }) => {
|
|
986
|
-
return service.update(updateId, { value, label, type }).then(extractId);
|
|
1006
|
+
var updateVariable = (updateId, { value, label, type }, options) => {
|
|
1007
|
+
return service.update(updateId, { value, label, type }, options).then(extractId);
|
|
987
1008
|
};
|
|
988
1009
|
var deleteVariable = (deleteId) => {
|
|
989
1010
|
return service.delete(deleteId).then(extractId);
|
|
@@ -2319,7 +2340,7 @@ var StopSyncConfirmationDialog = ({ open, onClose, onConfirm }) => {
|
|
|
2319
2340
|
import { injectIntoLogic, injectIntoTop } from "@elementor/editor";
|
|
2320
2341
|
import { registerControlReplacement } from "@elementor/editor-controls";
|
|
2321
2342
|
import { getMCPByDomain } from "@elementor/editor-mcp";
|
|
2322
|
-
import { isTransformable as
|
|
2343
|
+
import { isTransformable as isTransformable3 } from "@elementor/editor-props";
|
|
2323
2344
|
import { controlActionsMenu } from "@elementor/menus";
|
|
2324
2345
|
|
|
2325
2346
|
// src/components/global-styles-import-listener.tsx
|
|
@@ -2338,6 +2359,78 @@ function GlobalStylesImportListener() {
|
|
|
2338
2359
|
return null;
|
|
2339
2360
|
}
|
|
2340
2361
|
|
|
2362
|
+
// src/components/mcp-variable-connect-listener.tsx
|
|
2363
|
+
import { useEffect as useEffect6 } from "react";
|
|
2364
|
+
import { MCP_STYLES_APPLIED_EVENT } from "@elementor/editor-mcp";
|
|
2365
|
+
|
|
2366
|
+
// src/utils/extract-variables-from-style-value.ts
|
|
2367
|
+
import { getPropSchemaFromCache, isTransformable } from "@elementor/editor-props";
|
|
2368
|
+
var VARIABLE_TYPE_KEYS = [
|
|
2369
|
+
"global-color-variable",
|
|
2370
|
+
"global-font-variable",
|
|
2371
|
+
"global-size-variable",
|
|
2372
|
+
"global-custom-size-variable"
|
|
2373
|
+
];
|
|
2374
|
+
function tryExtractVariable(value) {
|
|
2375
|
+
for (const key of VARIABLE_TYPE_KEYS) {
|
|
2376
|
+
const propUtil = getPropSchemaFromCache(key);
|
|
2377
|
+
if (propUtil?.isValid(value)) {
|
|
2378
|
+
return {
|
|
2379
|
+
type: key,
|
|
2380
|
+
variableId: propUtil.extract(value)
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
return null;
|
|
2385
|
+
}
|
|
2386
|
+
function traverse(value, path, result) {
|
|
2387
|
+
const extracted = tryExtractVariable(value);
|
|
2388
|
+
if (extracted) {
|
|
2389
|
+
result.push({
|
|
2390
|
+
...extracted,
|
|
2391
|
+
controlPath: path.join(".")
|
|
2392
|
+
});
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
if (isTransformable(value)) {
|
|
2396
|
+
traverse(value.value, path, result);
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
if (value && typeof value === "object") {
|
|
2400
|
+
for (const [key, val] of Object.entries(value)) {
|
|
2401
|
+
traverse(val, [...path, key], result);
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
function extractVariablesFromStyleValue(styleValue) {
|
|
2406
|
+
const result = [];
|
|
2407
|
+
traverse(styleValue, [], result);
|
|
2408
|
+
return result;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// src/components/mcp-variable-connect-listener.tsx
|
|
2412
|
+
function McpVariableConnectListener() {
|
|
2413
|
+
useEffect6(() => {
|
|
2414
|
+
const handleMcpStylesApplied = (event) => {
|
|
2415
|
+
const { styleValue } = event.detail;
|
|
2416
|
+
const variables = extractVariablesFromStyleValue(styleValue);
|
|
2417
|
+
variables.forEach(({ type, controlPath }) => {
|
|
2418
|
+
trackVariableEvent({
|
|
2419
|
+
varType: type,
|
|
2420
|
+
controlPath,
|
|
2421
|
+
action: "connect",
|
|
2422
|
+
executedBy: "mcp_tool"
|
|
2423
|
+
});
|
|
2424
|
+
});
|
|
2425
|
+
};
|
|
2426
|
+
window.addEventListener(MCP_STYLES_APPLIED_EVENT, handleMcpStylesApplied);
|
|
2427
|
+
return () => {
|
|
2428
|
+
window.removeEventListener(MCP_STYLES_APPLIED_EVENT, handleMcpStylesApplied);
|
|
2429
|
+
};
|
|
2430
|
+
}, []);
|
|
2431
|
+
return null;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2341
2434
|
// src/controls/variable-control.tsx
|
|
2342
2435
|
import * as React33 from "react";
|
|
2343
2436
|
import { useBoundProp as useBoundProp11 } from "@elementor/editor-controls";
|
|
@@ -2406,7 +2499,7 @@ var useInitialValue = () => {
|
|
|
2406
2499
|
|
|
2407
2500
|
// src/hooks/use-variable-bound-prop.ts
|
|
2408
2501
|
import { useBoundProp as useBoundProp3 } from "@elementor/editor-controls";
|
|
2409
|
-
import { isTransformable } from "@elementor/editor-props";
|
|
2502
|
+
import { isTransformable as isTransformable2 } from "@elementor/editor-props";
|
|
2410
2503
|
var useVariableBoundProp = () => {
|
|
2411
2504
|
const { propTypeUtil } = useVariableType();
|
|
2412
2505
|
const boundProp = useBoundProp3(propTypeUtil);
|
|
@@ -2426,7 +2519,7 @@ var resolveBoundPropAndSetValue = (value, boundProp) => {
|
|
|
2426
2519
|
return boundProp.setValue(value);
|
|
2427
2520
|
};
|
|
2428
2521
|
var unwrapValue = (input) => {
|
|
2429
|
-
if (
|
|
2522
|
+
if (isTransformable2(input)) {
|
|
2430
2523
|
return input.value;
|
|
2431
2524
|
}
|
|
2432
2525
|
return input;
|
|
@@ -2442,7 +2535,7 @@ var FormField = ({ id, label, errorMsg, noticeMsg, children }) => {
|
|
|
2442
2535
|
// src/components/variable-creation.tsx
|
|
2443
2536
|
var SIZE2 = "tiny";
|
|
2444
2537
|
var VariableCreation = ({ onGoBack, onClose }) => {
|
|
2445
|
-
const { icon: VariableIcon, valueField: ValueField,
|
|
2538
|
+
const { icon: VariableIcon, valueField: ValueField, propTypeUtil } = useVariableType();
|
|
2446
2539
|
const { setVariableValue: setVariable, path } = useVariableBoundProp();
|
|
2447
2540
|
const { propType } = useBoundProp4();
|
|
2448
2541
|
const initialValue = useInitialValue();
|
|
@@ -2463,11 +2556,14 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
2463
2556
|
onClose();
|
|
2464
2557
|
};
|
|
2465
2558
|
const handleCreateAndTrack = () => {
|
|
2466
|
-
createVariable(
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2559
|
+
createVariable(
|
|
2560
|
+
{
|
|
2561
|
+
value,
|
|
2562
|
+
label,
|
|
2563
|
+
type: propTypeKey
|
|
2564
|
+
},
|
|
2565
|
+
{ eventData: { controlPath: path.join(".") } }
|
|
2566
|
+
).then((key) => {
|
|
2471
2567
|
setVariable(key);
|
|
2472
2568
|
closePopover();
|
|
2473
2569
|
}).catch((error) => {
|
|
@@ -2482,11 +2578,6 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
2482
2578
|
}
|
|
2483
2579
|
setErrorMessage(ERROR_MESSAGES.UNEXPECTED_ERROR);
|
|
2484
2580
|
});
|
|
2485
|
-
trackVariableEvent({
|
|
2486
|
-
varType: variableType,
|
|
2487
|
-
controlPath: path.join("."),
|
|
2488
|
-
action: "save"
|
|
2489
|
-
});
|
|
2490
2581
|
};
|
|
2491
2582
|
const hasEmptyFields = () => {
|
|
2492
2583
|
if ("" === label.trim()) {
|
|
@@ -2571,7 +2662,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
2571
2662
|
|
|
2572
2663
|
// src/components/variable-edit.tsx
|
|
2573
2664
|
import * as React19 from "react";
|
|
2574
|
-
import { useEffect as
|
|
2665
|
+
import { useEffect as useEffect7, useState as useState10 } from "react";
|
|
2575
2666
|
import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
|
|
2576
2667
|
import { useSuppressedMessage as useSuppressedMessage2 } from "@elementor/editor-current-user";
|
|
2577
2668
|
import { PopoverHeader as PopoverHeader2, SectionPopoverBody as SectionPopoverBody2 } from "@elementor/editor-ui";
|
|
@@ -2632,7 +2723,7 @@ var SIZE3 = "tiny";
|
|
|
2632
2723
|
var DELETE_LABEL = __13("Delete variable", "elementor");
|
|
2633
2724
|
var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
2634
2725
|
const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
|
|
2635
|
-
const { setVariableValue: notifyBoundPropChange, variableId } = useVariableBoundProp();
|
|
2726
|
+
const { setVariableValue: notifyBoundPropChange, variableId, path } = useVariableBoundProp();
|
|
2636
2727
|
const { propType } = useBoundProp5();
|
|
2637
2728
|
const [isMessageSuppressed, suppressMessage] = useSuppressedMessage2(EDIT_CONFIRMATION_DIALOG_ID);
|
|
2638
2729
|
const [deleteConfirmation, setDeleteConfirmation] = useState10(false);
|
|
@@ -2648,7 +2739,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2648
2739
|
const userPermissions = usePermissions();
|
|
2649
2740
|
const [value, setValue] = useState10(() => variable.value);
|
|
2650
2741
|
const [label, setLabel] = useState10(() => variable.label);
|
|
2651
|
-
|
|
2742
|
+
useEffect7(() => {
|
|
2652
2743
|
styleVariablesRepository.update({
|
|
2653
2744
|
[editId]: {
|
|
2654
2745
|
...variable,
|
|
@@ -2671,7 +2762,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2671
2762
|
const handleSaveVariable = () => {
|
|
2672
2763
|
const typeChanged = propTypeKey !== variable.type;
|
|
2673
2764
|
const updatePayload = typeChanged ? { value, label, type: propTypeKey } : { value, label };
|
|
2674
|
-
updateVariable(editId, updatePayload).then(() => {
|
|
2765
|
+
updateVariable(editId, updatePayload, { eventData: { controlPath: path.join(".") } }).then(() => {
|
|
2675
2766
|
maybeTriggerBoundPropChange();
|
|
2676
2767
|
onSubmit?.();
|
|
2677
2768
|
}).catch((error) => {
|
|
@@ -2813,7 +2904,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2813
2904
|
};
|
|
2814
2905
|
|
|
2815
2906
|
// src/components/variables-selection.tsx
|
|
2816
|
-
import { useEffect as
|
|
2907
|
+
import { useEffect as useEffect8, useState as useState11 } from "react";
|
|
2817
2908
|
import * as React21 from "react";
|
|
2818
2909
|
import { trackUpgradePromotionClick as trackUpgradePromotionClick2, trackViewPromotion as trackViewPromotion2 } from "@elementor/editor-controls";
|
|
2819
2910
|
import {
|
|
@@ -3004,7 +3095,7 @@ var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings, disabled =
|
|
|
3004
3095
|
const handleClearSearch = () => {
|
|
3005
3096
|
setSearchValue("");
|
|
3006
3097
|
};
|
|
3007
|
-
|
|
3098
|
+
useEffect8(() => {
|
|
3008
3099
|
if (disabled) {
|
|
3009
3100
|
trackViewPromotion2({
|
|
3010
3101
|
target_name: "variables_popover",
|
|
@@ -3996,7 +4087,7 @@ function getServiceActions(svc) {
|
|
|
3996
4087
|
if (valueError) {
|
|
3997
4088
|
throw new Error(valueError);
|
|
3998
4089
|
}
|
|
3999
|
-
return svc.create({ type, label, value });
|
|
4090
|
+
return svc.create({ type, label, value }, { eventData: { executedBy: "mcp_tool" } });
|
|
4000
4091
|
},
|
|
4001
4092
|
update({ id, label, value }) {
|
|
4002
4093
|
if (!id || !label || !value) {
|
|
@@ -4013,7 +4104,7 @@ function getServiceActions(svc) {
|
|
|
4013
4104
|
throw new Error(valueError);
|
|
4014
4105
|
}
|
|
4015
4106
|
}
|
|
4016
|
-
return svc.update(id, { label, value });
|
|
4107
|
+
return svc.update(id, { label, value }, { eventData: { executedBy: "mcp_tool" } });
|
|
4017
4108
|
},
|
|
4018
4109
|
delete({ id }) {
|
|
4019
4110
|
if (!id) {
|
|
@@ -4239,7 +4330,7 @@ function registerVariableTypes() {
|
|
|
4239
4330
|
|
|
4240
4331
|
// src/renderers/style-variables-renderer.tsx
|
|
4241
4332
|
import * as React38 from "react";
|
|
4242
|
-
import { useEffect as
|
|
4333
|
+
import { useEffect as useEffect9, useState as useState19 } from "react";
|
|
4243
4334
|
import {
|
|
4244
4335
|
__privateUseListenTo as useListenTo,
|
|
4245
4336
|
commandEndEvent as commandEndEvent2,
|
|
@@ -4263,7 +4354,7 @@ function usePortalContainer() {
|
|
|
4263
4354
|
}
|
|
4264
4355
|
function useStyleVariables() {
|
|
4265
4356
|
const [variables, setVariables] = useState19({});
|
|
4266
|
-
|
|
4357
|
+
useEffect9(() => {
|
|
4267
4358
|
const unsubscribe = styleVariablesRepository.subscribe(setVariables);
|
|
4268
4359
|
return () => {
|
|
4269
4360
|
unsubscribe();
|
|
@@ -4577,9 +4668,13 @@ function init() {
|
|
|
4577
4668
|
id: "variables-import-listener",
|
|
4578
4669
|
component: GlobalStylesImportListener
|
|
4579
4670
|
});
|
|
4671
|
+
injectIntoLogic({
|
|
4672
|
+
id: "mcp-variable-connect-listener",
|
|
4673
|
+
component: McpVariableConnectListener
|
|
4674
|
+
});
|
|
4580
4675
|
}
|
|
4581
4676
|
function hasVariableAssigned(value) {
|
|
4582
|
-
if (
|
|
4677
|
+
if (isTransformable3(value)) {
|
|
4583
4678
|
return hasVariableType(value.$$type);
|
|
4584
4679
|
}
|
|
4585
4680
|
return false;
|