@elementor/editor-variables 3.32.0-30 → 3.32.0-31
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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/ui/variable/assigned-variable.tsx +3 -5
- package/src/components/ui/variable/deleted-variable.tsx +3 -4
- package/src/utils/unlink-variable.ts +27 -0
- package/src/variables-registry/create-variable-type-registry.ts +10 -1
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ type NormalizedVariable = {
|
|
|
10
10
|
value: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, selectionFilter, fallbackPropTypeUtil, }: {
|
|
13
|
+
declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, selectionFilter, valueTransformer, fallbackPropTypeUtil, }: {
|
|
14
14
|
icon: react.ForwardRefExoticComponent<Omit<_mui_material.SvgIconProps, "ref"> & react.RefAttributes<SVGSVGElement>>;
|
|
15
15
|
startIcon?: ({ value }: {
|
|
16
16
|
value: string;
|
|
@@ -24,6 +24,7 @@ declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil
|
|
|
24
24
|
fallbackPropTypeUtil: any;
|
|
25
25
|
propTypeUtil: _elementor_editor_props.PropTypeUtil<string, string>;
|
|
26
26
|
selectionFilter?: (variables: NormalizedVariable[], propType: _elementor_editor_props.PropType) => NormalizedVariable[];
|
|
27
|
+
valueTransformer?: (value: string) => _elementor_editor_props.PropValue;
|
|
27
28
|
}) => void;
|
|
28
29
|
|
|
29
30
|
export { init, registerVariableType };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ type NormalizedVariable = {
|
|
|
10
10
|
value: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, selectionFilter, fallbackPropTypeUtil, }: {
|
|
13
|
+
declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil, variableType, selectionFilter, valueTransformer, fallbackPropTypeUtil, }: {
|
|
14
14
|
icon: react.ForwardRefExoticComponent<Omit<_mui_material.SvgIconProps, "ref"> & react.RefAttributes<SVGSVGElement>>;
|
|
15
15
|
startIcon?: ({ value }: {
|
|
16
16
|
value: string;
|
|
@@ -24,6 +24,7 @@ declare const registerVariableType: ({ icon, startIcon, valueField, propTypeUtil
|
|
|
24
24
|
fallbackPropTypeUtil: any;
|
|
25
25
|
propTypeUtil: _elementor_editor_props.PropTypeUtil<string, string>;
|
|
26
26
|
selectionFilter?: (variables: NormalizedVariable[], propType: _elementor_editor_props.PropType) => NormalizedVariable[];
|
|
27
|
+
valueTransformer?: (value: string) => _elementor_editor_props.PropValue;
|
|
27
28
|
}) => void;
|
|
28
29
|
|
|
29
30
|
export { init, registerVariableType };
|
package/dist/index.js
CHANGED
|
@@ -486,6 +486,7 @@ function createVariableTypeRegistry() {
|
|
|
486
486
|
propTypeUtil,
|
|
487
487
|
variableType,
|
|
488
488
|
selectionFilter,
|
|
489
|
+
valueTransformer,
|
|
489
490
|
fallbackPropTypeUtil
|
|
490
491
|
}) => {
|
|
491
492
|
if (variableTypes[propTypeUtil.key]) {
|
|
@@ -498,6 +499,7 @@ function createVariableTypeRegistry() {
|
|
|
498
499
|
propTypeUtil,
|
|
499
500
|
variableType,
|
|
500
501
|
selectionFilter,
|
|
502
|
+
valueTransformer,
|
|
501
503
|
fallbackPropTypeUtil
|
|
502
504
|
};
|
|
503
505
|
registerTransformer(propTypeUtil.key);
|
|
@@ -525,6 +527,22 @@ function createVariableTypeRegistry() {
|
|
|
525
527
|
// src/variables-registry/variable-type-registry.ts
|
|
526
528
|
var { registerVariableType, getVariableType, hasVariableType } = createVariableTypeRegistry();
|
|
527
529
|
|
|
530
|
+
// src/utils/unlink-variable.ts
|
|
531
|
+
function transformValueBeforeUnlink(variable, propTypeKey) {
|
|
532
|
+
const { valueTransformer } = getVariableType(propTypeKey);
|
|
533
|
+
if (valueTransformer) {
|
|
534
|
+
return valueTransformer(variable.value);
|
|
535
|
+
}
|
|
536
|
+
return variable.value;
|
|
537
|
+
}
|
|
538
|
+
function createUnlinkHandler(variable, propTypeKey, setValue) {
|
|
539
|
+
return () => {
|
|
540
|
+
const { fallbackPropTypeUtil } = getVariableType(propTypeKey);
|
|
541
|
+
const transformedValue = transformValueBeforeUnlink(variable, propTypeKey);
|
|
542
|
+
setValue(fallbackPropTypeUtil.create(transformedValue));
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
528
546
|
// src/components/variable-selection-popover.tsx
|
|
529
547
|
var React15 = __toESM(require("react"));
|
|
530
548
|
var import_react10 = require("react");
|
|
@@ -1455,7 +1473,7 @@ var AssignedTag = ({ startIcon, label, onUnlink, ...props }) => {
|
|
|
1455
1473
|
|
|
1456
1474
|
// src/components/ui/variable/assigned-variable.tsx
|
|
1457
1475
|
var AssignedVariable = ({ variable, propTypeKey }) => {
|
|
1458
|
-
const {
|
|
1476
|
+
const { startIcon, propTypeUtil } = getVariableType(propTypeKey);
|
|
1459
1477
|
const { setValue } = (0, import_editor_controls6.useBoundProp)();
|
|
1460
1478
|
const anchorRef = (0, import_react11.useRef)(null);
|
|
1461
1479
|
const popupId = (0, import_react11.useId)();
|
|
@@ -1463,10 +1481,7 @@ var AssignedVariable = ({ variable, propTypeKey }) => {
|
|
|
1463
1481
|
variant: "popover",
|
|
1464
1482
|
popupId: `elementor-variables-list-${popupId}`
|
|
1465
1483
|
});
|
|
1466
|
-
const unlinkVariable = (
|
|
1467
|
-
const fallbackValue = fallbackPropTypeUtil.create(variable.value);
|
|
1468
|
-
setValue(fallbackValue);
|
|
1469
|
-
};
|
|
1484
|
+
const unlinkVariable = createUnlinkHandler(variable, propTypeKey, setValue);
|
|
1470
1485
|
const StartIcon = startIcon || (() => null);
|
|
1471
1486
|
return /* @__PURE__ */ React17.createElement(import_ui17.Box, { ref: anchorRef }, /* @__PURE__ */ React17.createElement(
|
|
1472
1487
|
AssignedTag,
|
|
@@ -1646,7 +1661,7 @@ var DeletedTag = React20.forwardRef(({ label, onClick, ...props }, ref) => {
|
|
|
1646
1661
|
|
|
1647
1662
|
// src/components/ui/variable/deleted-variable.tsx
|
|
1648
1663
|
var DeletedVariable = ({ variable, propTypeKey }) => {
|
|
1649
|
-
const {
|
|
1664
|
+
const { propTypeUtil } = getVariableType(propTypeKey);
|
|
1650
1665
|
const { setValue } = (0, import_editor_controls8.useBoundProp)();
|
|
1651
1666
|
const userPermissions = usePermissions();
|
|
1652
1667
|
const [showInfotip, setShowInfotip] = (0, import_react13.useState)(false);
|
|
@@ -1660,9 +1675,7 @@ var DeletedVariable = ({ variable, propTypeKey }) => {
|
|
|
1660
1675
|
});
|
|
1661
1676
|
const handlers = {};
|
|
1662
1677
|
if (userPermissions.canUnlink()) {
|
|
1663
|
-
handlers.onUnlink = (
|
|
1664
|
-
setValue(fallbackPropTypeUtil.create(variable.value));
|
|
1665
|
-
};
|
|
1678
|
+
handlers.onUnlink = createUnlinkHandler(variable, propTypeKey, setValue);
|
|
1666
1679
|
}
|
|
1667
1680
|
if (userPermissions.canRestore()) {
|
|
1668
1681
|
handlers.onRestore = () => {
|