@elementor/editor-variables 3.33.0-121 → 3.33.0-122
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 +64 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/ui/variable/deleted-variable.tsx +6 -4
- package/src/components/ui/variable/mismatch-variable.tsx +4 -2
- package/src/components/variable-creation.tsx +2 -1
- package/src/components/variable-edit.tsx +4 -3
- package/src/components/variable-restore.tsx +3 -2
- package/src/components/variables-selection.tsx +2 -2
- package/src/controls/variable-control.tsx +1 -1
- package/src/hooks/use-variable-bound-prop.ts +42 -0
- package/src/init.ts +5 -5
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
40
|
var import_editor = require("@elementor/editor");
|
|
41
41
|
var import_editor_editing_panel8 = require("@elementor/editor-editing-panel");
|
|
42
42
|
var import_editor_panels2 = require("@elementor/editor-panels");
|
|
43
|
+
var import_editor_props6 = require("@elementor/editor-props");
|
|
43
44
|
|
|
44
45
|
// src/components/variables-manager/variables-manager-panel.tsx
|
|
45
46
|
var React9 = __toESM(require("react"));
|
|
@@ -1301,7 +1302,7 @@ var usePermissions = () => {
|
|
|
1301
1302
|
// src/components/variable-creation.tsx
|
|
1302
1303
|
var React12 = __toESM(require("react"));
|
|
1303
1304
|
var import_react9 = require("react");
|
|
1304
|
-
var
|
|
1305
|
+
var import_editor_controls4 = require("@elementor/editor-controls");
|
|
1305
1306
|
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
1306
1307
|
var import_editor_ui3 = require("@elementor/editor-ui");
|
|
1307
1308
|
var import_icons5 = require("@elementor/icons");
|
|
@@ -1312,14 +1313,42 @@ var import_i18n7 = require("@wordpress/i18n");
|
|
|
1312
1313
|
var import_editor_controls2 = require("@elementor/editor-controls");
|
|
1313
1314
|
var useInitialValue = () => {
|
|
1314
1315
|
const { value: initial } = (0, import_editor_controls2.useBoundProp)();
|
|
1315
|
-
const
|
|
1316
|
-
const variable = useVariable(
|
|
1317
|
-
if (
|
|
1316
|
+
const hasAssignedVariable = hasVariableType(initial?.$$type) && Boolean(initial?.value);
|
|
1317
|
+
const variable = useVariable(hasAssignedVariable ? initial.value : "");
|
|
1318
|
+
if (hasAssignedVariable) {
|
|
1318
1319
|
return variable ? variable.value : "";
|
|
1319
1320
|
}
|
|
1320
1321
|
return initial?.value ?? "";
|
|
1321
1322
|
};
|
|
1322
1323
|
|
|
1324
|
+
// src/hooks/use-variable-bound-prop.ts
|
|
1325
|
+
var import_editor_controls3 = require("@elementor/editor-controls");
|
|
1326
|
+
var import_editor_props3 = require("@elementor/editor-props");
|
|
1327
|
+
var useVariableBoundProp = () => {
|
|
1328
|
+
const { propTypeUtil } = useVariableType();
|
|
1329
|
+
const boundProp = (0, import_editor_controls3.useBoundProp)(propTypeUtil);
|
|
1330
|
+
return {
|
|
1331
|
+
...boundProp,
|
|
1332
|
+
setVariableValue: (value) => resolveBoundPropAndSetValue(value, boundProp),
|
|
1333
|
+
variableId: boundProp.value ?? boundProp.placeholder
|
|
1334
|
+
};
|
|
1335
|
+
};
|
|
1336
|
+
var resolveBoundPropAndSetValue = (value, boundProp) => {
|
|
1337
|
+
const propValue = unwrapValue(boundProp.value);
|
|
1338
|
+
const placeholder = unwrapValue(boundProp.placeholder);
|
|
1339
|
+
const newValue = unwrapValue(value);
|
|
1340
|
+
if (!propValue && placeholder === newValue) {
|
|
1341
|
+
return boundProp.setValue(null);
|
|
1342
|
+
}
|
|
1343
|
+
return boundProp.setValue(value);
|
|
1344
|
+
};
|
|
1345
|
+
var unwrapValue = (input) => {
|
|
1346
|
+
if ((0, import_editor_props3.isTransformable)(input)) {
|
|
1347
|
+
return input.value;
|
|
1348
|
+
}
|
|
1349
|
+
return input;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1323
1352
|
// src/utils/tracking.ts
|
|
1324
1353
|
var trackVariableEvent = ({ varType, controlPath, action }) => {
|
|
1325
1354
|
const extendedWindow = window;
|
|
@@ -1349,8 +1378,8 @@ var FormField = ({ id: id2, label, errorMsg, noticeMsg, children }) => {
|
|
|
1349
1378
|
var SIZE = "tiny";
|
|
1350
1379
|
var VariableCreation = ({ onGoBack, onClose }) => {
|
|
1351
1380
|
const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
|
|
1352
|
-
const {
|
|
1353
|
-
const { propType } = (0,
|
|
1381
|
+
const { setVariableValue: setVariable, path } = useVariableBoundProp();
|
|
1382
|
+
const { propType } = (0, import_editor_controls4.useBoundProp)();
|
|
1354
1383
|
const initialValue = useInitialValue();
|
|
1355
1384
|
const [value, setValue] = (0, import_react9.useState)(initialValue);
|
|
1356
1385
|
const [label, setLabel] = (0, import_react9.useState)("");
|
|
@@ -1413,7 +1442,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
1413
1442
|
title: (0, import_i18n7.__)("Create variable", "elementor"),
|
|
1414
1443
|
onClose: closePopover
|
|
1415
1444
|
}
|
|
1416
|
-
), /* @__PURE__ */ React12.createElement(import_ui12.Divider, null), /* @__PURE__ */ React12.createElement(
|
|
1445
|
+
), /* @__PURE__ */ React12.createElement(import_ui12.Divider, null), /* @__PURE__ */ React12.createElement(import_editor_controls4.PopoverContent, { p: 2 }, /* @__PURE__ */ React12.createElement(
|
|
1417
1446
|
FormField,
|
|
1418
1447
|
{
|
|
1419
1448
|
id: "variable-label",
|
|
@@ -1467,7 +1496,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
1467
1496
|
// src/components/variable-edit.tsx
|
|
1468
1497
|
var React14 = __toESM(require("react"));
|
|
1469
1498
|
var import_react11 = require("react");
|
|
1470
|
-
var
|
|
1499
|
+
var import_editor_controls5 = require("@elementor/editor-controls");
|
|
1471
1500
|
var import_editor_current_user2 = require("@elementor/editor-current-user");
|
|
1472
1501
|
var import_editor_editing_panel3 = require("@elementor/editor-editing-panel");
|
|
1473
1502
|
var import_editor_ui4 = require("@elementor/editor-ui");
|
|
@@ -1516,9 +1545,9 @@ var EditConfirmationDialog = ({
|
|
|
1516
1545
|
// src/components/variable-edit.tsx
|
|
1517
1546
|
var SIZE2 = "tiny";
|
|
1518
1547
|
var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
1519
|
-
const { icon: VariableIcon, valueField: ValueField, variableType
|
|
1520
|
-
const {
|
|
1521
|
-
const { propType } = (0,
|
|
1548
|
+
const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
|
|
1549
|
+
const { setVariableValue: notifyBoundPropChange, variableId } = useVariableBoundProp();
|
|
1550
|
+
const { propType } = (0, import_editor_controls5.useBoundProp)();
|
|
1522
1551
|
const [isMessageSuppressed, suppressMessage] = (0, import_editor_current_user2.useSuppressedMessage)(EDIT_CONFIRMATION_DIALOG_ID);
|
|
1523
1552
|
const [deleteConfirmation, setDeleteConfirmation] = (0, import_react11.useState)(false);
|
|
1524
1553
|
const [editConfirmation, setEditConfirmation] = (0, import_react11.useState)(false);
|
|
@@ -1579,7 +1608,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
1579
1608
|
});
|
|
1580
1609
|
};
|
|
1581
1610
|
const maybeTriggerBoundPropChange = () => {
|
|
1582
|
-
if (editId ===
|
|
1611
|
+
if (editId === variableId) {
|
|
1583
1612
|
notifyBoundPropChange(editId);
|
|
1584
1613
|
}
|
|
1585
1614
|
};
|
|
@@ -1639,7 +1668,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
1639
1668
|
), /* @__PURE__ */ React14.createElement(VariableIcon, { fontSize: SIZE2 })),
|
|
1640
1669
|
actions
|
|
1641
1670
|
}
|
|
1642
|
-
), /* @__PURE__ */ React14.createElement(import_ui14.Divider, null), /* @__PURE__ */ React14.createElement(
|
|
1671
|
+
), /* @__PURE__ */ React14.createElement(import_ui14.Divider, null), /* @__PURE__ */ React14.createElement(import_editor_controls5.PopoverContent, { p: 2 }, /* @__PURE__ */ React14.createElement(
|
|
1643
1672
|
FormField,
|
|
1644
1673
|
{
|
|
1645
1674
|
id: "variable-label",
|
|
@@ -1698,7 +1727,6 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
1698
1727
|
// src/components/variables-selection.tsx
|
|
1699
1728
|
var React18 = __toESM(require("react"));
|
|
1700
1729
|
var import_react12 = require("react");
|
|
1701
|
-
var import_editor_controls5 = require("@elementor/editor-controls");
|
|
1702
1730
|
var import_editor_editing_panel4 = require("@elementor/editor-editing-panel");
|
|
1703
1731
|
var import_editor_ui6 = require("@elementor/editor-ui");
|
|
1704
1732
|
var import_icons9 = require("@elementor/icons");
|
|
@@ -1849,7 +1877,7 @@ var VariablesStyledMenuList = (0, import_ui18.styled)(import_ui18.MenuList)(({ t
|
|
|
1849
1877
|
var SIZE4 = "tiny";
|
|
1850
1878
|
var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
|
|
1851
1879
|
const { icon: VariableIcon, startIcon, variableType, propTypeUtil } = useVariableType();
|
|
1852
|
-
const { value: variable, setValue: setVariable, path } = (
|
|
1880
|
+
const { value: variable, setValue: setVariable, path } = useVariableBoundProp();
|
|
1853
1881
|
const [searchValue, setSearchValue] = (0, import_react12.useState)("");
|
|
1854
1882
|
const {
|
|
1855
1883
|
list: variables,
|
|
@@ -2134,8 +2162,8 @@ var import_ui22 = require("@elementor/ui");
|
|
|
2134
2162
|
var import_i18n15 = require("@wordpress/i18n");
|
|
2135
2163
|
var SIZE6 = "tiny";
|
|
2136
2164
|
var VariableRestore = ({ variableId, onClose, onSubmit }) => {
|
|
2137
|
-
const { icon: VariableIcon, valueField: ValueField, variableType
|
|
2138
|
-
const {
|
|
2165
|
+
const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
|
|
2166
|
+
const { setVariableValue: notifyBoundPropChange } = useVariableBoundProp();
|
|
2139
2167
|
const { propType } = (0, import_editor_controls7.useBoundProp)();
|
|
2140
2168
|
const variable = useVariable(variableId);
|
|
2141
2169
|
if (!variable) {
|
|
@@ -2286,7 +2314,7 @@ WarningVariableTag.displayName = "WarningVariableTag";
|
|
|
2286
2314
|
// src/components/ui/variable/deleted-variable.tsx
|
|
2287
2315
|
var DeletedVariable = ({ variable, propTypeKey }) => {
|
|
2288
2316
|
const { propTypeUtil } = getVariableType(propTypeKey);
|
|
2289
|
-
const
|
|
2317
|
+
const boundProp = (0, import_editor_controls8.useBoundProp)();
|
|
2290
2318
|
const userPermissions = usePermissions();
|
|
2291
2319
|
const [showInfotip, setShowInfotip] = (0, import_react16.useState)(false);
|
|
2292
2320
|
const toggleInfotip = () => setShowInfotip((prev) => !prev);
|
|
@@ -2299,15 +2327,15 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
|
|
|
2299
2327
|
});
|
|
2300
2328
|
const handlers = {};
|
|
2301
2329
|
if (userPermissions.canUnlink()) {
|
|
2302
|
-
handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, setValue);
|
|
2330
|
+
handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, boundProp.setValue);
|
|
2303
2331
|
}
|
|
2304
2332
|
if (userPermissions.canRestore()) {
|
|
2305
2333
|
handlers.onRestore = () => {
|
|
2306
2334
|
if (!variable.key) {
|
|
2307
2335
|
return;
|
|
2308
2336
|
}
|
|
2309
|
-
restoreVariable(variable.key).then((
|
|
2310
|
-
|
|
2337
|
+
restoreVariable(variable.key).then((id2) => {
|
|
2338
|
+
resolveBoundPropAndSetValue(propTypeUtil.create(id2), boundProp);
|
|
2311
2339
|
closeInfotip();
|
|
2312
2340
|
}).catch(() => {
|
|
2313
2341
|
closeInfotip();
|
|
@@ -2416,7 +2444,7 @@ var MismatchVariableAlert = ({ onClose, onClear, triggerSelect }) => {
|
|
|
2416
2444
|
|
|
2417
2445
|
// src/components/ui/variable/mismatch-variable.tsx
|
|
2418
2446
|
var MismatchVariable = ({ variable }) => {
|
|
2419
|
-
const { setValue } = (0, import_editor_controls9.useBoundProp)();
|
|
2447
|
+
const { setValue, value } = (0, import_editor_controls9.useBoundProp)();
|
|
2420
2448
|
const anchorRef = (0, import_react17.useRef)(null);
|
|
2421
2449
|
const popupId = (0, import_react17.useId)();
|
|
2422
2450
|
const popupState = (0, import_ui27.usePopupState)({
|
|
@@ -2435,6 +2463,7 @@ var MismatchVariable = ({ variable }) => {
|
|
|
2435
2463
|
closeInfotip();
|
|
2436
2464
|
setValue(null);
|
|
2437
2465
|
};
|
|
2466
|
+
const showClearButton = !!value;
|
|
2438
2467
|
return /* @__PURE__ */ React27.createElement(import_ui27.Box, { ref: anchorRef }, infotipVisible && /* @__PURE__ */ React27.createElement(import_ui27.Backdrop, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React27.createElement(
|
|
2439
2468
|
import_ui27.Infotip,
|
|
2440
2469
|
{
|
|
@@ -2447,7 +2476,7 @@ var MismatchVariable = ({ variable }) => {
|
|
|
2447
2476
|
MismatchVariableAlert,
|
|
2448
2477
|
{
|
|
2449
2478
|
onClose: closeInfotip,
|
|
2450
|
-
onClear: clearValue,
|
|
2479
|
+
onClear: showClearButton ? clearValue : void 0,
|
|
2451
2480
|
triggerSelect
|
|
2452
2481
|
}
|
|
2453
2482
|
),
|
|
@@ -2556,7 +2585,7 @@ var MissingVariable = () => {
|
|
|
2556
2585
|
// src/controls/variable-control.tsx
|
|
2557
2586
|
var VariableControl = () => {
|
|
2558
2587
|
const boundProp = (0, import_editor_controls11.useBoundProp)();
|
|
2559
|
-
const boundPropValue = boundProp.value;
|
|
2588
|
+
const boundPropValue = boundProp.value ?? boundProp.placeholder;
|
|
2560
2589
|
const assignedVariable = useVariable(boundPropValue?.value);
|
|
2561
2590
|
if (!assignedVariable) {
|
|
2562
2591
|
return /* @__PURE__ */ React30.createElement(MissingVariable, null);
|
|
@@ -2615,7 +2644,7 @@ var trackOpenVariablePopover = (path, variableType) => {
|
|
|
2615
2644
|
|
|
2616
2645
|
// src/register-variable-types.tsx
|
|
2617
2646
|
var React34 = __toESM(require("react"));
|
|
2618
|
-
var
|
|
2647
|
+
var import_editor_props4 = require("@elementor/editor-props");
|
|
2619
2648
|
var import_icons15 = require("@elementor/icons");
|
|
2620
2649
|
|
|
2621
2650
|
// src/components/fields/color-field.tsx
|
|
@@ -2738,7 +2767,7 @@ function registerVariableTypes() {
|
|
|
2738
2767
|
valueField: ColorField,
|
|
2739
2768
|
icon: import_icons15.BrushIcon,
|
|
2740
2769
|
propTypeUtil: colorVariablePropTypeUtil,
|
|
2741
|
-
fallbackPropTypeUtil:
|
|
2770
|
+
fallbackPropTypeUtil: import_editor_props4.colorPropTypeUtil,
|
|
2742
2771
|
variableType: "color",
|
|
2743
2772
|
startIcon: ({ value }) => /* @__PURE__ */ React34.createElement(ColorIndicator, { size: "inherit", component: "span", value })
|
|
2744
2773
|
});
|
|
@@ -2746,7 +2775,7 @@ function registerVariableTypes() {
|
|
|
2746
2775
|
valueField: FontField,
|
|
2747
2776
|
icon: import_icons15.TextIcon,
|
|
2748
2777
|
propTypeUtil: fontVariablePropTypeUtil,
|
|
2749
|
-
fallbackPropTypeUtil:
|
|
2778
|
+
fallbackPropTypeUtil: import_editor_props4.stringPropTypeUtil,
|
|
2750
2779
|
variableType: "font"
|
|
2751
2780
|
});
|
|
2752
2781
|
}
|
|
@@ -2801,7 +2830,7 @@ function convertToCssVariables(variables) {
|
|
|
2801
2830
|
|
|
2802
2831
|
// src/repeater-injections.ts
|
|
2803
2832
|
var import_editor_controls13 = require("@elementor/editor-controls");
|
|
2804
|
-
var
|
|
2833
|
+
var import_editor_props5 = require("@elementor/editor-props");
|
|
2805
2834
|
|
|
2806
2835
|
// src/components/variables-repeater-item-slot.tsx
|
|
2807
2836
|
var React36 = __toESM(require("react"));
|
|
@@ -2828,21 +2857,21 @@ function registerRepeaterInjections() {
|
|
|
2828
2857
|
id: "color-variables-background-icon",
|
|
2829
2858
|
component: BackgroundRepeaterColorIndicator,
|
|
2830
2859
|
condition: ({ value: prop }) => {
|
|
2831
|
-
return hasAssignedColorVariable(
|
|
2860
|
+
return hasAssignedColorVariable(import_editor_props5.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
|
|
2832
2861
|
}
|
|
2833
2862
|
});
|
|
2834
2863
|
(0, import_editor_controls13.injectIntoRepeaterItemIcon)({
|
|
2835
2864
|
id: "color-variables-icon",
|
|
2836
2865
|
component: BoxShadowRepeaterColorIndicator,
|
|
2837
2866
|
condition: ({ value: prop }) => {
|
|
2838
|
-
return hasAssignedColorVariable(
|
|
2867
|
+
return hasAssignedColorVariable(import_editor_props5.shadowPropTypeUtil.extract(prop)?.color);
|
|
2839
2868
|
}
|
|
2840
2869
|
});
|
|
2841
2870
|
(0, import_editor_controls13.injectIntoRepeaterItemLabel)({
|
|
2842
2871
|
id: "color-variables-label",
|
|
2843
2872
|
component: BackgroundRepeaterLabel,
|
|
2844
2873
|
condition: ({ value: prop }) => {
|
|
2845
|
-
return hasAssignedColorVariable(
|
|
2874
|
+
return hasAssignedColorVariable(import_editor_props5.backgroundColorOverlayPropTypeUtil.extract(prop)?.color);
|
|
2846
2875
|
}
|
|
2847
2876
|
});
|
|
2848
2877
|
}
|
|
@@ -2857,7 +2886,7 @@ function init() {
|
|
|
2857
2886
|
registerRepeaterInjections();
|
|
2858
2887
|
(0, import_editor_editing_panel8.registerControlReplacement)({
|
|
2859
2888
|
component: VariableControl,
|
|
2860
|
-
condition: ({ value }) =>
|
|
2889
|
+
condition: ({ value, placeholder }) => hasVariable(value) || hasVariable(placeholder)
|
|
2861
2890
|
});
|
|
2862
2891
|
registerPopoverAction({
|
|
2863
2892
|
id: "variables",
|
|
@@ -2870,9 +2899,9 @@ function init() {
|
|
|
2870
2899
|
});
|
|
2871
2900
|
(0, import_editor_panels2.__registerPanel)(panel);
|
|
2872
2901
|
}
|
|
2873
|
-
function
|
|
2874
|
-
if (
|
|
2875
|
-
return hasVariableType(
|
|
2902
|
+
function hasVariable(value) {
|
|
2903
|
+
if ((0, import_editor_props6.isTransformable)(value)) {
|
|
2904
|
+
return hasVariableType(value.$$type);
|
|
2876
2905
|
}
|
|
2877
2906
|
return false;
|
|
2878
2907
|
}
|