@elementor/editor-variables 3.33.0-120 → 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 +80 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/fields/color-field.tsx +1 -0
- package/src/components/fields/font-field.tsx +1 -0
- 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 +10 -3
- package/src/components/variable-edit.tsx +4 -3
- package/src/components/variable-restore.tsx +3 -2
- package/src/components/variables-selection.tsx +4 -4
- 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.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { injectIntoTop } from "@elementor/editor";
|
|
3
3
|
import { controlActionsMenu, registerControlReplacement } from "@elementor/editor-editing-panel";
|
|
4
4
|
import { __registerPanel as registerPanel } from "@elementor/editor-panels";
|
|
5
|
+
import { isTransformable as isTransformable2 } from "@elementor/editor-props";
|
|
5
6
|
|
|
6
7
|
// src/components/variables-manager/variables-manager-panel.tsx
|
|
7
8
|
import * as React9 from "react";
|
|
@@ -1288,7 +1289,7 @@ var usePermissions = () => {
|
|
|
1288
1289
|
// src/components/variable-creation.tsx
|
|
1289
1290
|
import * as React12 from "react";
|
|
1290
1291
|
import { useState as useState6 } from "react";
|
|
1291
|
-
import { PopoverContent, useBoundProp as
|
|
1292
|
+
import { PopoverContent, useBoundProp as useBoundProp4 } from "@elementor/editor-controls";
|
|
1292
1293
|
import { PopoverBody } from "@elementor/editor-editing-panel";
|
|
1293
1294
|
import { PopoverHeader } from "@elementor/editor-ui";
|
|
1294
1295
|
import { ArrowLeftIcon } from "@elementor/icons";
|
|
@@ -1299,14 +1300,42 @@ import { __ as __7 } from "@wordpress/i18n";
|
|
|
1299
1300
|
import { useBoundProp as useBoundProp2 } from "@elementor/editor-controls";
|
|
1300
1301
|
var useInitialValue = () => {
|
|
1301
1302
|
const { value: initial } = useBoundProp2();
|
|
1302
|
-
const
|
|
1303
|
-
const variable = useVariable(
|
|
1304
|
-
if (
|
|
1303
|
+
const hasAssignedVariable = hasVariableType(initial?.$$type) && Boolean(initial?.value);
|
|
1304
|
+
const variable = useVariable(hasAssignedVariable ? initial.value : "");
|
|
1305
|
+
if (hasAssignedVariable) {
|
|
1305
1306
|
return variable ? variable.value : "";
|
|
1306
1307
|
}
|
|
1307
1308
|
return initial?.value ?? "";
|
|
1308
1309
|
};
|
|
1309
1310
|
|
|
1311
|
+
// src/hooks/use-variable-bound-prop.ts
|
|
1312
|
+
import { useBoundProp as useBoundProp3 } from "@elementor/editor-controls";
|
|
1313
|
+
import { isTransformable } from "@elementor/editor-props";
|
|
1314
|
+
var useVariableBoundProp = () => {
|
|
1315
|
+
const { propTypeUtil } = useVariableType();
|
|
1316
|
+
const boundProp = useBoundProp3(propTypeUtil);
|
|
1317
|
+
return {
|
|
1318
|
+
...boundProp,
|
|
1319
|
+
setVariableValue: (value) => resolveBoundPropAndSetValue(value, boundProp),
|
|
1320
|
+
variableId: boundProp.value ?? boundProp.placeholder
|
|
1321
|
+
};
|
|
1322
|
+
};
|
|
1323
|
+
var resolveBoundPropAndSetValue = (value, boundProp) => {
|
|
1324
|
+
const propValue = unwrapValue(boundProp.value);
|
|
1325
|
+
const placeholder = unwrapValue(boundProp.placeholder);
|
|
1326
|
+
const newValue = unwrapValue(value);
|
|
1327
|
+
if (!propValue && placeholder === newValue) {
|
|
1328
|
+
return boundProp.setValue(null);
|
|
1329
|
+
}
|
|
1330
|
+
return boundProp.setValue(value);
|
|
1331
|
+
};
|
|
1332
|
+
var unwrapValue = (input) => {
|
|
1333
|
+
if (isTransformable(input)) {
|
|
1334
|
+
return input.value;
|
|
1335
|
+
}
|
|
1336
|
+
return input;
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1310
1339
|
// src/utils/tracking.ts
|
|
1311
1340
|
var trackVariableEvent = ({ varType, controlPath, action }) => {
|
|
1312
1341
|
const extendedWindow = window;
|
|
@@ -1336,8 +1365,8 @@ var FormField = ({ id: id2, label, errorMsg, noticeMsg, children }) => {
|
|
|
1336
1365
|
var SIZE = "tiny";
|
|
1337
1366
|
var VariableCreation = ({ onGoBack, onClose }) => {
|
|
1338
1367
|
const { icon: VariableIcon, valueField: ValueField, variableType, propTypeUtil } = useVariableType();
|
|
1339
|
-
const {
|
|
1340
|
-
const { propType } =
|
|
1368
|
+
const { setVariableValue: setVariable, path } = useVariableBoundProp();
|
|
1369
|
+
const { propType } = useBoundProp4();
|
|
1341
1370
|
const initialValue = useInitialValue();
|
|
1342
1371
|
const [value, setValue] = useState6(initialValue);
|
|
1343
1372
|
const [label, setLabel] = useState6("");
|
|
@@ -1426,7 +1455,7 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
1426
1455
|
}
|
|
1427
1456
|
}
|
|
1428
1457
|
)
|
|
1429
|
-
), /* @__PURE__ */ React12.createElement(FormField, { errorMsg: valueFieldError, label: __7("Value", "elementor") }, /* @__PURE__ */ React12.createElement(Typography3, { variant: "h5" }, /* @__PURE__ */ React12.createElement(
|
|
1458
|
+
), /* @__PURE__ */ React12.createElement(FormField, { errorMsg: valueFieldError, label: __7("Value", "elementor") }, /* @__PURE__ */ React12.createElement(Typography3, { variant: "h5", id: "variable-value-wrapper" }, /* @__PURE__ */ React12.createElement(
|
|
1430
1459
|
ValueField,
|
|
1431
1460
|
{
|
|
1432
1461
|
value,
|
|
@@ -1438,13 +1467,23 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
1438
1467
|
onValidationChange: setValueFieldError,
|
|
1439
1468
|
propType
|
|
1440
1469
|
}
|
|
1441
|
-
))), errorMessage && /* @__PURE__ */ React12.createElement(FormHelperText2, { error: true }, errorMessage)), /* @__PURE__ */ React12.createElement(CardActions, { sx: { pt: 0.5, pb: 1 } }, /* @__PURE__ */ React12.createElement(
|
|
1470
|
+
))), errorMessage && /* @__PURE__ */ React12.createElement(FormHelperText2, { error: true }, errorMessage)), /* @__PURE__ */ React12.createElement(CardActions, { sx: { pt: 0.5, pb: 1 } }, /* @__PURE__ */ React12.createElement(
|
|
1471
|
+
Button3,
|
|
1472
|
+
{
|
|
1473
|
+
id: "create-variable-button",
|
|
1474
|
+
size: "small",
|
|
1475
|
+
variant: "contained",
|
|
1476
|
+
disabled: isSubmitDisabled,
|
|
1477
|
+
onClick: handleCreateAndTrack
|
|
1478
|
+
},
|
|
1479
|
+
__7("Create", "elementor")
|
|
1480
|
+
)));
|
|
1442
1481
|
};
|
|
1443
1482
|
|
|
1444
1483
|
// src/components/variable-edit.tsx
|
|
1445
1484
|
import * as React14 from "react";
|
|
1446
1485
|
import { useEffect as useEffect2, useState as useState8 } from "react";
|
|
1447
|
-
import { PopoverContent as PopoverContent2, useBoundProp as
|
|
1486
|
+
import { PopoverContent as PopoverContent2, useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
|
|
1448
1487
|
import { useSuppressedMessage } from "@elementor/editor-current-user";
|
|
1449
1488
|
import { PopoverBody as PopoverBody2 } from "@elementor/editor-editing-panel";
|
|
1450
1489
|
import { PopoverHeader as PopoverHeader2 } from "@elementor/editor-ui";
|
|
@@ -1503,9 +1542,9 @@ var EditConfirmationDialog = ({
|
|
|
1503
1542
|
// src/components/variable-edit.tsx
|
|
1504
1543
|
var SIZE2 = "tiny";
|
|
1505
1544
|
var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
1506
|
-
const { icon: VariableIcon, valueField: ValueField, variableType
|
|
1507
|
-
const {
|
|
1508
|
-
const { propType } =
|
|
1545
|
+
const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
|
|
1546
|
+
const { setVariableValue: notifyBoundPropChange, variableId } = useVariableBoundProp();
|
|
1547
|
+
const { propType } = useBoundProp5();
|
|
1509
1548
|
const [isMessageSuppressed, suppressMessage] = useSuppressedMessage(EDIT_CONFIRMATION_DIALOG_ID);
|
|
1510
1549
|
const [deleteConfirmation, setDeleteConfirmation] = useState8(false);
|
|
1511
1550
|
const [editConfirmation, setEditConfirmation] = useState8(false);
|
|
@@ -1566,7 +1605,7 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
1566
1605
|
});
|
|
1567
1606
|
};
|
|
1568
1607
|
const maybeTriggerBoundPropChange = () => {
|
|
1569
|
-
if (editId ===
|
|
1608
|
+
if (editId === variableId) {
|
|
1570
1609
|
notifyBoundPropChange(editId);
|
|
1571
1610
|
}
|
|
1572
1611
|
};
|
|
@@ -1685,7 +1724,6 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
1685
1724
|
// src/components/variables-selection.tsx
|
|
1686
1725
|
import * as React18 from "react";
|
|
1687
1726
|
import { useState as useState9 } from "react";
|
|
1688
|
-
import { useBoundProp as useBoundProp5 } from "@elementor/editor-controls";
|
|
1689
1727
|
import { PopoverBody as PopoverBody3 } from "@elementor/editor-editing-panel";
|
|
1690
1728
|
import { PopoverHeader as PopoverHeader3, PopoverMenuList, PopoverSearch } from "@elementor/editor-ui";
|
|
1691
1729
|
import { ColorFilterIcon as ColorFilterIcon2, PlusIcon, SettingsIcon } from "@elementor/icons";
|
|
@@ -1836,7 +1874,7 @@ var VariablesStyledMenuList = styled2(MenuList)(({ theme }) => ({
|
|
|
1836
1874
|
var SIZE4 = "tiny";
|
|
1837
1875
|
var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
|
|
1838
1876
|
const { icon: VariableIcon, startIcon, variableType, propTypeUtil } = useVariableType();
|
|
1839
|
-
const { value: variable, setValue: setVariable, path } =
|
|
1877
|
+
const { value: variable, setValue: setVariable, path } = useVariableBoundProp();
|
|
1840
1878
|
const [searchValue, setSearchValue] = useState9("");
|
|
1841
1879
|
const {
|
|
1842
1880
|
list: variables,
|
|
@@ -1864,12 +1902,12 @@ var VariablesSelection = ({ closePopover, onAdd, onEdit, onSettings }) => {
|
|
|
1864
1902
|
const actions = [];
|
|
1865
1903
|
if (onAdd) {
|
|
1866
1904
|
actions.push(
|
|
1867
|
-
/* @__PURE__ */ React18.createElement(IconButton7, { key: "add", size: SIZE4, onClick: onAddAndTrack }, /* @__PURE__ */ React18.createElement(PlusIcon, { fontSize: SIZE4 }))
|
|
1905
|
+
/* @__PURE__ */ React18.createElement(IconButton7, { id: "add-variable-button", key: "add", size: SIZE4, onClick: onAddAndTrack }, /* @__PURE__ */ React18.createElement(PlusIcon, { fontSize: SIZE4 }))
|
|
1868
1906
|
);
|
|
1869
1907
|
}
|
|
1870
1908
|
if (onSettings) {
|
|
1871
1909
|
actions.push(
|
|
1872
|
-
/* @__PURE__ */ React18.createElement(IconButton7, { key: "settings", size: SIZE4, onClick: onSettings }, /* @__PURE__ */ React18.createElement(SettingsIcon, { fontSize: SIZE4 }))
|
|
1910
|
+
/* @__PURE__ */ React18.createElement(IconButton7, { id: "variables-manager-button", key: "settings", size: SIZE4, onClick: onSettings }, /* @__PURE__ */ React18.createElement(SettingsIcon, { fontSize: SIZE4 }))
|
|
1873
1911
|
);
|
|
1874
1912
|
}
|
|
1875
1913
|
const StartIcon = startIcon || (() => /* @__PURE__ */ React18.createElement(VariableIcon, { fontSize: SIZE4 }));
|
|
@@ -2121,8 +2159,8 @@ import { Button as Button7, CardActions as CardActions3, Divider as Divider5, Fo
|
|
|
2121
2159
|
import { __ as __15 } from "@wordpress/i18n";
|
|
2122
2160
|
var SIZE6 = "tiny";
|
|
2123
2161
|
var VariableRestore = ({ variableId, onClose, onSubmit }) => {
|
|
2124
|
-
const { icon: VariableIcon, valueField: ValueField, variableType
|
|
2125
|
-
const {
|
|
2162
|
+
const { icon: VariableIcon, valueField: ValueField, variableType } = useVariableType();
|
|
2163
|
+
const { setVariableValue: notifyBoundPropChange } = useVariableBoundProp();
|
|
2126
2164
|
const { propType } = useBoundProp7();
|
|
2127
2165
|
const variable = useVariable(variableId);
|
|
2128
2166
|
if (!variable) {
|
|
@@ -2273,7 +2311,7 @@ WarningVariableTag.displayName = "WarningVariableTag";
|
|
|
2273
2311
|
// src/components/ui/variable/deleted-variable.tsx
|
|
2274
2312
|
var DeletedVariable = ({ variable, propTypeKey }) => {
|
|
2275
2313
|
const { propTypeUtil } = getVariableType(propTypeKey);
|
|
2276
|
-
const
|
|
2314
|
+
const boundProp = useBoundProp8();
|
|
2277
2315
|
const userPermissions = usePermissions();
|
|
2278
2316
|
const [showInfotip, setShowInfotip] = useState12(false);
|
|
2279
2317
|
const toggleInfotip = () => setShowInfotip((prev) => !prev);
|
|
@@ -2286,15 +2324,15 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
|
|
|
2286
2324
|
});
|
|
2287
2325
|
const handlers = {};
|
|
2288
2326
|
if (userPermissions.canUnlink()) {
|
|
2289
|
-
handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, setValue);
|
|
2327
|
+
handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, boundProp.setValue);
|
|
2290
2328
|
}
|
|
2291
2329
|
if (userPermissions.canRestore()) {
|
|
2292
2330
|
handlers.onRestore = () => {
|
|
2293
2331
|
if (!variable.key) {
|
|
2294
2332
|
return;
|
|
2295
2333
|
}
|
|
2296
|
-
restoreVariable(variable.key).then((
|
|
2297
|
-
|
|
2334
|
+
restoreVariable(variable.key).then((id2) => {
|
|
2335
|
+
resolveBoundPropAndSetValue(propTypeUtil.create(id2), boundProp);
|
|
2298
2336
|
closeInfotip();
|
|
2299
2337
|
}).catch(() => {
|
|
2300
2338
|
closeInfotip();
|
|
@@ -2403,7 +2441,7 @@ var MismatchVariableAlert = ({ onClose, onClear, triggerSelect }) => {
|
|
|
2403
2441
|
|
|
2404
2442
|
// src/components/ui/variable/mismatch-variable.tsx
|
|
2405
2443
|
var MismatchVariable = ({ variable }) => {
|
|
2406
|
-
const { setValue } = useBoundProp9();
|
|
2444
|
+
const { setValue, value } = useBoundProp9();
|
|
2407
2445
|
const anchorRef = useRef3(null);
|
|
2408
2446
|
const popupId = useId3();
|
|
2409
2447
|
const popupState = usePopupState4({
|
|
@@ -2422,6 +2460,7 @@ var MismatchVariable = ({ variable }) => {
|
|
|
2422
2460
|
closeInfotip();
|
|
2423
2461
|
setValue(null);
|
|
2424
2462
|
};
|
|
2463
|
+
const showClearButton = !!value;
|
|
2425
2464
|
return /* @__PURE__ */ React27.createElement(Box8, { ref: anchorRef }, infotipVisible && /* @__PURE__ */ React27.createElement(Backdrop2, { open: true, onClick: closeInfotip, invisible: true }), /* @__PURE__ */ React27.createElement(
|
|
2426
2465
|
Infotip2,
|
|
2427
2466
|
{
|
|
@@ -2434,7 +2473,7 @@ var MismatchVariable = ({ variable }) => {
|
|
|
2434
2473
|
MismatchVariableAlert,
|
|
2435
2474
|
{
|
|
2436
2475
|
onClose: closeInfotip,
|
|
2437
|
-
onClear: clearValue,
|
|
2476
|
+
onClear: showClearButton ? clearValue : void 0,
|
|
2438
2477
|
triggerSelect
|
|
2439
2478
|
}
|
|
2440
2479
|
),
|
|
@@ -2543,7 +2582,7 @@ var MissingVariable = () => {
|
|
|
2543
2582
|
// src/controls/variable-control.tsx
|
|
2544
2583
|
var VariableControl = () => {
|
|
2545
2584
|
const boundProp = useBoundProp11();
|
|
2546
|
-
const boundPropValue = boundProp.value;
|
|
2585
|
+
const boundPropValue = boundProp.value ?? boundProp.placeholder;
|
|
2547
2586
|
const assignedVariable = useVariable(boundPropValue?.value);
|
|
2548
2587
|
if (!assignedVariable) {
|
|
2549
2588
|
return /* @__PURE__ */ React30.createElement(MissingVariable, null);
|
|
@@ -2624,6 +2663,7 @@ var ColorField = ({ value, onChange, onValidationChange }) => {
|
|
|
2624
2663
|
return /* @__PURE__ */ React32.createElement(
|
|
2625
2664
|
UnstableColorField,
|
|
2626
2665
|
{
|
|
2666
|
+
id: "color-variable-field",
|
|
2627
2667
|
size: "tiny",
|
|
2628
2668
|
fullWidth: true,
|
|
2629
2669
|
value: color,
|
|
@@ -2703,6 +2743,7 @@ var FontField = ({ value, onChange, onValidationChange }) => {
|
|
|
2703
2743
|
/* @__PURE__ */ React33.createElement(
|
|
2704
2744
|
ItemSelector,
|
|
2705
2745
|
{
|
|
2746
|
+
id: "font-family-variables-selector",
|
|
2706
2747
|
itemsList: mapFontSubs,
|
|
2707
2748
|
selectedItem: fontFamily,
|
|
2708
2749
|
onItemChange: handleFontFamilyChange,
|
|
@@ -2842,7 +2883,7 @@ function init() {
|
|
|
2842
2883
|
registerRepeaterInjections();
|
|
2843
2884
|
registerControlReplacement({
|
|
2844
2885
|
component: VariableControl,
|
|
2845
|
-
condition: ({ value }) =>
|
|
2886
|
+
condition: ({ value, placeholder }) => hasVariable(value) || hasVariable(placeholder)
|
|
2846
2887
|
});
|
|
2847
2888
|
registerPopoverAction({
|
|
2848
2889
|
id: "variables",
|
|
@@ -2855,9 +2896,9 @@ function init() {
|
|
|
2855
2896
|
});
|
|
2856
2897
|
registerPanel(panel);
|
|
2857
2898
|
}
|
|
2858
|
-
function
|
|
2859
|
-
if (
|
|
2860
|
-
return hasVariableType(
|
|
2899
|
+
function hasVariable(value) {
|
|
2900
|
+
if (isTransformable2(value)) {
|
|
2901
|
+
return hasVariableType(value.$$type);
|
|
2861
2902
|
}
|
|
2862
2903
|
return false;
|
|
2863
2904
|
}
|