@folklore/ads 0.0.27 → 0.0.29
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/cjs.js +23 -13
- package/dist/es.js +23 -13
- package/package.json +3 -3
package/dist/cjs.js
CHANGED
|
@@ -637,6 +637,7 @@ const propTypes$2 = {
|
|
|
637
637
|
refreshOnResize: PropTypes__default["default"].bool,
|
|
638
638
|
slots: adSlots,
|
|
639
639
|
viewports: adViewports,
|
|
640
|
+
disabled: PropTypes__default["default"].bool,
|
|
640
641
|
trackingDisabled: PropTypes__default["default"].bool
|
|
641
642
|
};
|
|
642
643
|
const defaultProps$2 = {
|
|
@@ -648,6 +649,7 @@ const defaultProps$2 = {
|
|
|
648
649
|
refreshOnResize: false,
|
|
649
650
|
slots: slots,
|
|
650
651
|
viewports: viewports,
|
|
652
|
+
disabled: false,
|
|
651
653
|
trackingDisabled: false
|
|
652
654
|
};
|
|
653
655
|
function AdsProvider(_ref) {
|
|
@@ -661,6 +663,7 @@ function AdsProvider(_ref) {
|
|
|
661
663
|
refreshOnResize,
|
|
662
664
|
viewports,
|
|
663
665
|
slots,
|
|
666
|
+
disabled,
|
|
664
667
|
trackingDisabled
|
|
665
668
|
} = _ref;
|
|
666
669
|
const [ready, setReady] = React.useState(false);
|
|
@@ -669,11 +672,14 @@ function AdsProvider(_ref) {
|
|
|
669
672
|
if (adsRef.current === null) {
|
|
670
673
|
adsRef.current = new AdsManager({
|
|
671
674
|
enableSingleRequest,
|
|
672
|
-
autoInit
|
|
675
|
+
autoInit,
|
|
676
|
+
disabled
|
|
673
677
|
});
|
|
678
|
+
} else {
|
|
679
|
+
adsRef.current.setDisabled(disabled);
|
|
674
680
|
}
|
|
675
681
|
return adsRef.current;
|
|
676
|
-
}, [enableSingleRequest, autoInit]);
|
|
682
|
+
}, [enableSingleRequest, autoInit, disabled]);
|
|
677
683
|
React.useEffect(() => {
|
|
678
684
|
let onReady = null;
|
|
679
685
|
if (!ads.isReady()) {
|
|
@@ -723,7 +729,7 @@ function AdsProvider(_ref) {
|
|
|
723
729
|
...slotsPath
|
|
724
730
|
},
|
|
725
731
|
trackingDisabled
|
|
726
|
-
}), [ready, ads, viewports, slots, slotsPath, defaultSlotPath, trackingDisabled]);
|
|
732
|
+
}), [ready, ads, viewports, slots, slotsPath, defaultSlotPath, trackingDisabled, disabled]);
|
|
727
733
|
return /*#__PURE__*/jsxRuntime.jsx(AdsContext.Provider, {
|
|
728
734
|
value: value,
|
|
729
735
|
children: children
|
|
@@ -995,7 +1001,11 @@ function Ad(_ref) {
|
|
|
995
1001
|
const minimumSize = React.useMemo(() => getMinimumAdSize(finalSizeMapping !== null ? finalSizeMapping.reduce((allSizes, sizeMap) => [...allSizes, sizeMap[1]], [finalSize]) : finalSize), [finalSizeMapping, finalSize]);
|
|
996
1002
|
|
|
997
1003
|
// Targeting
|
|
998
|
-
const
|
|
1004
|
+
const {
|
|
1005
|
+
disabled: targetingDisabled = false,
|
|
1006
|
+
...contextTargeting
|
|
1007
|
+
} = useAdsTargeting();
|
|
1008
|
+
const finalDisabled = disabled || targetingDisabled;
|
|
999
1009
|
const allTargeting = React.useMemo(() => ({
|
|
1000
1010
|
...(slotName !== null ? {
|
|
1001
1011
|
slot: slotName
|
|
@@ -1014,16 +1024,16 @@ function Ad(_ref) {
|
|
|
1014
1024
|
};
|
|
1015
1025
|
}, [allTargeting, refreshInterval]);
|
|
1016
1026
|
const lastRenderedSize = React.useRef(null);
|
|
1017
|
-
const wasDisabled = React.useRef(
|
|
1027
|
+
const wasDisabled = React.useRef(finalDisabled);
|
|
1018
1028
|
const onAdRender = React.useCallback(event => {
|
|
1019
1029
|
const {
|
|
1020
1030
|
isEmpty: newIsEmpty = true,
|
|
1021
1031
|
width: newWidth,
|
|
1022
1032
|
height: newHeight
|
|
1023
1033
|
} = event || {};
|
|
1024
|
-
if (
|
|
1034
|
+
if (finalDisabled) {
|
|
1025
1035
|
wasDisabled.current = true;
|
|
1026
|
-
} else if (!
|
|
1036
|
+
} else if (!finalDisabled && !newIsEmpty) {
|
|
1027
1037
|
wasDisabled.current = false;
|
|
1028
1038
|
}
|
|
1029
1039
|
lastRenderedSize.current = !newIsEmpty ? {
|
|
@@ -1033,7 +1043,7 @@ function Ad(_ref) {
|
|
|
1033
1043
|
if (onRender !== null) {
|
|
1034
1044
|
onRender(event);
|
|
1035
1045
|
}
|
|
1036
|
-
}, [onRender, shouldKeepSize,
|
|
1046
|
+
}, [onRender, shouldKeepSize, finalDisabled]);
|
|
1037
1047
|
|
|
1038
1048
|
// useEffect(() => {
|
|
1039
1049
|
// if (!disabled) {
|
|
@@ -1064,7 +1074,7 @@ function Ad(_ref) {
|
|
|
1064
1074
|
refreshInterval: finalAdTargeting.refreshInterval,
|
|
1065
1075
|
alwaysRender,
|
|
1066
1076
|
onRender: onAdRender,
|
|
1067
|
-
disabled,
|
|
1077
|
+
disabled: finalDisabled,
|
|
1068
1078
|
trackingDisabled
|
|
1069
1079
|
});
|
|
1070
1080
|
if (slotRef !== null && isFunction__default["default"](slotRef)) {
|
|
@@ -1073,13 +1083,13 @@ function Ad(_ref) {
|
|
|
1073
1083
|
// eslint-disable-next-line no-param-reassign
|
|
1074
1084
|
slotRef.current = slotObject;
|
|
1075
1085
|
}
|
|
1076
|
-
if (
|
|
1086
|
+
if (finalDisabled) {
|
|
1077
1087
|
wasDisabled.current = true;
|
|
1078
|
-
} else if (!
|
|
1088
|
+
} else if (!finalDisabled && isRendered) {
|
|
1079
1089
|
wasDisabled.current = false;
|
|
1080
1090
|
}
|
|
1081
1091
|
const waitingNextRender = wasDisabled.current && !isRendered;
|
|
1082
|
-
const keepSize = shouldKeepSize && (
|
|
1092
|
+
const keepSize = shouldKeepSize && (finalDisabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
1083
1093
|
if (id === null && !keepSize) {
|
|
1084
1094
|
return null;
|
|
1085
1095
|
}
|
|
@@ -1089,7 +1099,7 @@ function Ad(_ref) {
|
|
|
1089
1099
|
width,
|
|
1090
1100
|
height
|
|
1091
1101
|
};
|
|
1092
|
-
} else if (shouldKeepSize && (
|
|
1102
|
+
} else if (shouldKeepSize && (finalDisabled || waitingNextRender)) {
|
|
1093
1103
|
adStyle = lastRenderedSize.current;
|
|
1094
1104
|
} else if (!withoutMinimumSize) {
|
|
1095
1105
|
adStyle = minimumSize;
|
package/dist/es.js
CHANGED
|
@@ -619,6 +619,7 @@ const propTypes$2 = {
|
|
|
619
619
|
refreshOnResize: PropTypes.bool,
|
|
620
620
|
slots: adSlots,
|
|
621
621
|
viewports: adViewports,
|
|
622
|
+
disabled: PropTypes.bool,
|
|
622
623
|
trackingDisabled: PropTypes.bool
|
|
623
624
|
};
|
|
624
625
|
const defaultProps$2 = {
|
|
@@ -630,6 +631,7 @@ const defaultProps$2 = {
|
|
|
630
631
|
refreshOnResize: false,
|
|
631
632
|
slots: slots,
|
|
632
633
|
viewports: viewports,
|
|
634
|
+
disabled: false,
|
|
633
635
|
trackingDisabled: false
|
|
634
636
|
};
|
|
635
637
|
function AdsProvider(_ref) {
|
|
@@ -643,6 +645,7 @@ function AdsProvider(_ref) {
|
|
|
643
645
|
refreshOnResize,
|
|
644
646
|
viewports,
|
|
645
647
|
slots,
|
|
648
|
+
disabled,
|
|
646
649
|
trackingDisabled
|
|
647
650
|
} = _ref;
|
|
648
651
|
const [ready, setReady] = useState(false);
|
|
@@ -651,11 +654,14 @@ function AdsProvider(_ref) {
|
|
|
651
654
|
if (adsRef.current === null) {
|
|
652
655
|
adsRef.current = new AdsManager({
|
|
653
656
|
enableSingleRequest,
|
|
654
|
-
autoInit
|
|
657
|
+
autoInit,
|
|
658
|
+
disabled
|
|
655
659
|
});
|
|
660
|
+
} else {
|
|
661
|
+
adsRef.current.setDisabled(disabled);
|
|
656
662
|
}
|
|
657
663
|
return adsRef.current;
|
|
658
|
-
}, [enableSingleRequest, autoInit]);
|
|
664
|
+
}, [enableSingleRequest, autoInit, disabled]);
|
|
659
665
|
useEffect(() => {
|
|
660
666
|
let onReady = null;
|
|
661
667
|
if (!ads.isReady()) {
|
|
@@ -705,7 +711,7 @@ function AdsProvider(_ref) {
|
|
|
705
711
|
...slotsPath
|
|
706
712
|
},
|
|
707
713
|
trackingDisabled
|
|
708
|
-
}), [ready, ads, viewports, slots, slotsPath, defaultSlotPath, trackingDisabled]);
|
|
714
|
+
}), [ready, ads, viewports, slots, slotsPath, defaultSlotPath, trackingDisabled, disabled]);
|
|
709
715
|
return /*#__PURE__*/jsx(AdsContext.Provider, {
|
|
710
716
|
value: value,
|
|
711
717
|
children: children
|
|
@@ -977,7 +983,11 @@ function Ad(_ref) {
|
|
|
977
983
|
const minimumSize = useMemo(() => getMinimumAdSize(finalSizeMapping !== null ? finalSizeMapping.reduce((allSizes, sizeMap) => [...allSizes, sizeMap[1]], [finalSize]) : finalSize), [finalSizeMapping, finalSize]);
|
|
978
984
|
|
|
979
985
|
// Targeting
|
|
980
|
-
const
|
|
986
|
+
const {
|
|
987
|
+
disabled: targetingDisabled = false,
|
|
988
|
+
...contextTargeting
|
|
989
|
+
} = useAdsTargeting();
|
|
990
|
+
const finalDisabled = disabled || targetingDisabled;
|
|
981
991
|
const allTargeting = useMemo(() => ({
|
|
982
992
|
...(slotName !== null ? {
|
|
983
993
|
slot: slotName
|
|
@@ -996,16 +1006,16 @@ function Ad(_ref) {
|
|
|
996
1006
|
};
|
|
997
1007
|
}, [allTargeting, refreshInterval]);
|
|
998
1008
|
const lastRenderedSize = useRef(null);
|
|
999
|
-
const wasDisabled = useRef(
|
|
1009
|
+
const wasDisabled = useRef(finalDisabled);
|
|
1000
1010
|
const onAdRender = useCallback(event => {
|
|
1001
1011
|
const {
|
|
1002
1012
|
isEmpty: newIsEmpty = true,
|
|
1003
1013
|
width: newWidth,
|
|
1004
1014
|
height: newHeight
|
|
1005
1015
|
} = event || {};
|
|
1006
|
-
if (
|
|
1016
|
+
if (finalDisabled) {
|
|
1007
1017
|
wasDisabled.current = true;
|
|
1008
|
-
} else if (!
|
|
1018
|
+
} else if (!finalDisabled && !newIsEmpty) {
|
|
1009
1019
|
wasDisabled.current = false;
|
|
1010
1020
|
}
|
|
1011
1021
|
lastRenderedSize.current = !newIsEmpty ? {
|
|
@@ -1015,7 +1025,7 @@ function Ad(_ref) {
|
|
|
1015
1025
|
if (onRender !== null) {
|
|
1016
1026
|
onRender(event);
|
|
1017
1027
|
}
|
|
1018
|
-
}, [onRender, shouldKeepSize,
|
|
1028
|
+
}, [onRender, shouldKeepSize, finalDisabled]);
|
|
1019
1029
|
|
|
1020
1030
|
// useEffect(() => {
|
|
1021
1031
|
// if (!disabled) {
|
|
@@ -1046,7 +1056,7 @@ function Ad(_ref) {
|
|
|
1046
1056
|
refreshInterval: finalAdTargeting.refreshInterval,
|
|
1047
1057
|
alwaysRender,
|
|
1048
1058
|
onRender: onAdRender,
|
|
1049
|
-
disabled,
|
|
1059
|
+
disabled: finalDisabled,
|
|
1050
1060
|
trackingDisabled
|
|
1051
1061
|
});
|
|
1052
1062
|
if (slotRef !== null && isFunction(slotRef)) {
|
|
@@ -1055,13 +1065,13 @@ function Ad(_ref) {
|
|
|
1055
1065
|
// eslint-disable-next-line no-param-reassign
|
|
1056
1066
|
slotRef.current = slotObject;
|
|
1057
1067
|
}
|
|
1058
|
-
if (
|
|
1068
|
+
if (finalDisabled) {
|
|
1059
1069
|
wasDisabled.current = true;
|
|
1060
|
-
} else if (!
|
|
1070
|
+
} else if (!finalDisabled && isRendered) {
|
|
1061
1071
|
wasDisabled.current = false;
|
|
1062
1072
|
}
|
|
1063
1073
|
const waitingNextRender = wasDisabled.current && !isRendered;
|
|
1064
|
-
const keepSize = shouldKeepSize && (
|
|
1074
|
+
const keepSize = shouldKeepSize && (finalDisabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
1065
1075
|
if (id === null && !keepSize) {
|
|
1066
1076
|
return null;
|
|
1067
1077
|
}
|
|
@@ -1071,7 +1081,7 @@ function Ad(_ref) {
|
|
|
1071
1081
|
width,
|
|
1072
1082
|
height
|
|
1073
1083
|
};
|
|
1074
|
-
} else if (shouldKeepSize && (
|
|
1084
|
+
} else if (shouldKeepSize && (finalDisabled || waitingNextRender)) {
|
|
1075
1085
|
adStyle = lastRenderedSize.current;
|
|
1076
1086
|
} else if (!withoutMinimumSize) {
|
|
1077
1087
|
adStyle = minimumSize;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Ads library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "3d6a994986575b5e4705182dbeecfd3b8c760513",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@folklore/hooks": "^0.0.43",
|
|
56
|
-
"@folklore/tracking": "^0.0.
|
|
56
|
+
"@folklore/tracking": "^0.0.21",
|
|
57
57
|
"classnames": "^2.5.1",
|
|
58
58
|
"debug": "^4.3.4",
|
|
59
59
|
"lodash": "^4.17.21",
|