@folklore/ads 0.0.99 → 0.0.101
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 +159 -157
- package/dist/es.js +159 -158
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -40,13 +40,10 @@ var propTypes$4 = /*#__PURE__*/Object.freeze({
|
|
|
40
40
|
adViewports: adViewports
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return sizes.split('x').map(it => parseInt(it, 10));
|
|
48
|
-
};
|
|
49
|
-
const getMinimumAdSize = sizes => getAdSizes(sizes).reduce((minimumSize, size) => ({
|
|
43
|
+
function getAdSizes(sizes) {
|
|
44
|
+
return uniqBy(sizes, size => isArray(size) ? size.join('x') : size);
|
|
45
|
+
}
|
|
46
|
+
const getMinimumAdSize = sizes => getAdSizes(sizes).filter(size => size !== 'fluid').reduce((minimumSize, size) => ({
|
|
50
47
|
width: Math.min(minimumSize.width, size[0]),
|
|
51
48
|
height: Math.min(minimumSize.height, size[1])
|
|
52
49
|
}), {
|
|
@@ -82,6 +79,23 @@ const getSizeMappingFromSlot = (_ref3, viewports) => {
|
|
|
82
79
|
}
|
|
83
80
|
return sizeMapping !== null ? buildSizeMappingFromViewports(sizeMapping, viewports) : null;
|
|
84
81
|
};
|
|
82
|
+
function getSizeFromSizeMapping(sizeMapping) {
|
|
83
|
+
if (sizeMapping === null) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return getAdSizes(sizeMapping.reduce((allSizes, sizeMap) => [...allSizes, ...sizeMap[1]], [])).sort((a, b) => {
|
|
87
|
+
if (a === 'fluid') {
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
if (b === 'fluid') {
|
|
91
|
+
return -1;
|
|
92
|
+
}
|
|
93
|
+
if (a[0] === b[0]) {
|
|
94
|
+
return a[1] > b[1] ? 1 : -1;
|
|
95
|
+
}
|
|
96
|
+
return a[0] > b[0] ? 1 : -1;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
85
99
|
|
|
86
100
|
class AdSlot extends EventEmitter {
|
|
87
101
|
constructor(id, path, size) {
|
|
@@ -615,19 +629,6 @@ const viewports = {
|
|
|
615
629
|
};
|
|
616
630
|
const slots = {
|
|
617
631
|
top: {
|
|
618
|
-
size: [[300, 100], [300, 150], [320, 50], [320, 100], [320, 180]
|
|
619
|
-
// [300, 100],
|
|
620
|
-
// [300, 150],
|
|
621
|
-
// [320, 50],
|
|
622
|
-
// [320, 100],
|
|
623
|
-
// [640, 350],
|
|
624
|
-
// [728, 90],
|
|
625
|
-
// [970, 90],
|
|
626
|
-
// [970, 250],
|
|
627
|
-
// [1024, 300],
|
|
628
|
-
// [1382, 300],
|
|
629
|
-
// [1382, 600],
|
|
630
|
-
],
|
|
631
632
|
sizeMapping: {
|
|
632
633
|
default: [[300, 100], [300, 150], [320, 50], [320, 100], [320, 180]],
|
|
633
634
|
tablet: [[300, 100], [300, 150], [320, 50], [320, 100], [320, 180], [728, 90]],
|
|
@@ -639,14 +640,12 @@ const slots = {
|
|
|
639
640
|
size: [[250, 250], [300, 250]]
|
|
640
641
|
},
|
|
641
642
|
sidebar: {
|
|
642
|
-
size: [[120, 600], [160, 600], [300, 600], [300, 250]],
|
|
643
643
|
sizeMapping: {
|
|
644
644
|
default: [[300, 250]],
|
|
645
645
|
laptop: [[120, 600], [160, 600], [300, 250], [300, 600]]
|
|
646
646
|
}
|
|
647
647
|
},
|
|
648
648
|
fullwidth: {
|
|
649
|
-
size: [[250, 250], [300, 100], [300, 150], [300, 250], [320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 360], [640, 350], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300], [1382, 300], [1382, 600]],
|
|
650
649
|
sizeMapping: {
|
|
651
650
|
default: [[250, 250], [300, 100], [300, 150], [300, 250], [320, 50], [320, 100], [320, 180], [336, 280]],
|
|
652
651
|
tablet: [[250, 250], [300, 100], [300, 150], [300, 250], [320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 350], [640, 360], [728, 90]],
|
|
@@ -655,32 +654,17 @@ const slots = {
|
|
|
655
654
|
}
|
|
656
655
|
},
|
|
657
656
|
content: {
|
|
658
|
-
size: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250], [300, 600], [320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 350], [640, 360], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300], [1382, 300], [1382, 600]
|
|
659
|
-
// [120, 600],
|
|
660
|
-
// [160, 600],
|
|
661
|
-
// [250, 250],
|
|
662
|
-
// [300, 100],
|
|
663
|
-
// [300, 150],
|
|
664
|
-
// [300, 250],
|
|
665
|
-
// [300, 600],
|
|
666
|
-
// [320, 50],
|
|
667
|
-
// [320, 100],
|
|
668
|
-
// [336, 280],
|
|
669
|
-
// [634, 634],
|
|
670
|
-
// [640, 350],
|
|
671
|
-
// [728, 90],
|
|
672
|
-
// [970, 90],
|
|
673
|
-
// [970, 250],
|
|
674
|
-
// [970, 415],
|
|
675
|
-
// [1024, 300],
|
|
676
|
-
// [1382, 300],
|
|
677
|
-
// [1382, 600],
|
|
678
|
-
],
|
|
679
657
|
sizeMapping: {
|
|
680
658
|
default: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250], [300, 600], [320, 50], [320, 100], [320, 180], [336, 280]],
|
|
681
|
-
tablet: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250],
|
|
682
|
-
|
|
683
|
-
|
|
659
|
+
tablet: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250],
|
|
660
|
+
// [300, 600],
|
|
661
|
+
[320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 350], [640, 360], [728, 90]],
|
|
662
|
+
desktop: [[120, 600], [160, 600],
|
|
663
|
+
// [300, 600],
|
|
664
|
+
[634, 634], [640, 350], [640, 360], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300]],
|
|
665
|
+
laptop: [[120, 600], [160, 600],
|
|
666
|
+
// [300, 600],
|
|
667
|
+
[634, 634], [640, 350], [640, 360], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300], [1382, 300], [1382, 600]]
|
|
684
668
|
}
|
|
685
669
|
}
|
|
686
670
|
};
|
|
@@ -703,13 +687,14 @@ const propTypes$3 = {
|
|
|
703
687
|
mobileScaling: PropTypes.number,
|
|
704
688
|
renderMarginPercent: PropTypes.number,
|
|
705
689
|
fetchMarginPercent: PropTypes.number,
|
|
690
|
+
viewport: PropTypes.string,
|
|
706
691
|
slots: adSlots,
|
|
707
692
|
viewports: adViewports,
|
|
708
693
|
richAdComponents: PropTypes.objectOf(PropTypes.elementType),
|
|
709
694
|
disabled: PropTypes.bool,
|
|
710
695
|
disableTracking: PropTypes.bool
|
|
711
696
|
};
|
|
712
|
-
const defaultProps$
|
|
697
|
+
const defaultProps$2 = {
|
|
713
698
|
defaultSlotPath: null,
|
|
714
699
|
slotsPath: null,
|
|
715
700
|
disableSingleRequest: false,
|
|
@@ -721,6 +706,7 @@ const defaultProps$3 = {
|
|
|
721
706
|
mobileScaling: 1.0,
|
|
722
707
|
renderMarginPercent: 100,
|
|
723
708
|
fetchMarginPercent: 300,
|
|
709
|
+
viewport: null,
|
|
724
710
|
slots: slots,
|
|
725
711
|
viewports: viewports,
|
|
726
712
|
richAdComponents: null,
|
|
@@ -741,6 +727,7 @@ function AdsProvider(_ref) {
|
|
|
741
727
|
mobileScaling,
|
|
742
728
|
renderMarginPercent,
|
|
743
729
|
fetchMarginPercent,
|
|
730
|
+
viewport,
|
|
744
731
|
viewports,
|
|
745
732
|
slots,
|
|
746
733
|
richAdComponents,
|
|
@@ -797,13 +784,21 @@ function AdsProvider(_ref) {
|
|
|
797
784
|
onResize.cancel();
|
|
798
785
|
};
|
|
799
786
|
}, [ads, resizeDebounceDelay, refreshOnResize]);
|
|
800
|
-
const slotsWithSizeMapping = React.useMemo(() => Object.keys(slots || {}).reduce((map, key) =>
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
787
|
+
const slotsWithSizeMapping = React.useMemo(() => Object.keys(slots || {}).reduce((map, key) => {
|
|
788
|
+
const slot = slots[key];
|
|
789
|
+
const {
|
|
790
|
+
size
|
|
791
|
+
} = slot;
|
|
792
|
+
const sizeMapping = getSizeMappingFromSlot(slot, viewports);
|
|
793
|
+
return {
|
|
794
|
+
...map,
|
|
795
|
+
[key]: {
|
|
796
|
+
...slot,
|
|
797
|
+
size: size || getSizeFromSizeMapping(sizeMapping || null),
|
|
798
|
+
sizeMapping
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
}, {}), []);
|
|
807
802
|
const finalSlotsPath = React.useMemo(() => defaultSlotPath !== null ? {
|
|
808
803
|
default: defaultSlotPath,
|
|
809
804
|
...slotsPath
|
|
@@ -814,18 +809,19 @@ function AdsProvider(_ref) {
|
|
|
814
809
|
ready,
|
|
815
810
|
ads,
|
|
816
811
|
viewports,
|
|
812
|
+
viewport,
|
|
817
813
|
slots: slotsWithSizeMapping,
|
|
818
814
|
slotsPath: finalSlotsPath,
|
|
819
815
|
trackingDisabled: disableTracking,
|
|
820
816
|
richAdComponents
|
|
821
|
-
}), [ready, ads, viewports, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
817
|
+
}), [ready, ads, viewports, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
822
818
|
return /*#__PURE__*/jsxRuntime.jsx(AdsContext.Provider, {
|
|
823
819
|
value: value,
|
|
824
820
|
children: children
|
|
825
821
|
});
|
|
826
822
|
}
|
|
827
823
|
AdsProvider.propTypes = propTypes$3;
|
|
828
|
-
AdsProvider.defaultProps = defaultProps$
|
|
824
|
+
AdsProvider.defaultProps = defaultProps$2;
|
|
829
825
|
|
|
830
826
|
const AdsTargetingContext = /*#__PURE__*/React.createContext(null);
|
|
831
827
|
const useAdsTargeting = () => React.useContext(AdsTargetingContext);
|
|
@@ -835,7 +831,7 @@ const propTypes$2 = {
|
|
|
835
831
|
targeting: PropTypes.object,
|
|
836
832
|
replace: PropTypes.bool
|
|
837
833
|
};
|
|
838
|
-
const defaultProps$
|
|
834
|
+
const defaultProps$1 = {
|
|
839
835
|
targeting: {
|
|
840
836
|
domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
|
|
841
837
|
},
|
|
@@ -858,7 +854,7 @@ function AdsTargetingProvider(_ref) {
|
|
|
858
854
|
});
|
|
859
855
|
}
|
|
860
856
|
AdsTargetingProvider.propTypes = propTypes$2;
|
|
861
|
-
AdsTargetingProvider.defaultProps = defaultProps$
|
|
857
|
+
AdsTargetingProvider.defaultProps = defaultProps$1;
|
|
862
858
|
|
|
863
859
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
864
860
|
const propTypes$1 = {
|
|
@@ -866,7 +862,7 @@ const propTypes$1 = {
|
|
|
866
862
|
type: PropTypes.string.isRequired
|
|
867
863
|
}).isRequired
|
|
868
864
|
};
|
|
869
|
-
const defaultProps
|
|
865
|
+
const defaultProps = {};
|
|
870
866
|
function RichAd(_ref) {
|
|
871
867
|
let {
|
|
872
868
|
richAd,
|
|
@@ -886,7 +882,7 @@ function RichAd(_ref) {
|
|
|
886
882
|
}) : null;
|
|
887
883
|
}
|
|
888
884
|
RichAd.propTypes = propTypes$1;
|
|
889
|
-
RichAd.defaultProps = defaultProps
|
|
885
|
+
RichAd.defaultProps = defaultProps;
|
|
890
886
|
|
|
891
887
|
function useAdsTracking() {
|
|
892
888
|
const tracking$1 = tracking.useTracking() || null;
|
|
@@ -901,6 +897,7 @@ function useAdsTracking() {
|
|
|
901
897
|
function useAd(path, size) {
|
|
902
898
|
let {
|
|
903
899
|
sizeMapping = null,
|
|
900
|
+
viewport = null,
|
|
904
901
|
targeting = null,
|
|
905
902
|
categoryExclusions = null,
|
|
906
903
|
refreshInterval = null,
|
|
@@ -913,6 +910,7 @@ function useAd(path, size) {
|
|
|
913
910
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
914
911
|
const {
|
|
915
912
|
ads: adsManager,
|
|
913
|
+
viewports,
|
|
916
914
|
ready: adsReady,
|
|
917
915
|
trackingDisabled: globalTrackingDisabled = false
|
|
918
916
|
} = useAdsContext();
|
|
@@ -946,30 +944,41 @@ function useAd(path, size) {
|
|
|
946
944
|
const [renderEvent, setRenderEvent] = React.useState(null);
|
|
947
945
|
|
|
948
946
|
// Create slot
|
|
949
|
-
|
|
950
|
-
const
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
947
|
+
const slotRef = React.useRef(null);
|
|
948
|
+
// const { current: slot } = slotRef;
|
|
949
|
+
// const [slot, setSlot] = useState(null);
|
|
950
|
+
const slot = React.useMemo(() => {
|
|
951
|
+
const {
|
|
952
|
+
current: currentSlot = null
|
|
953
|
+
} = slotRef;
|
|
954
|
+
if (currentSlot !== null) {
|
|
955
|
+
adsManager.destroySlot(currentSlot);
|
|
956
|
+
}
|
|
957
|
+
const viewportSize = viewport !== null ? viewports[viewport] || null : null;
|
|
958
|
+
const [, viewportFixedSize = null] = sizeMapping !== null && viewportSize !== null ? sizeMapping.find(_ref => {
|
|
959
|
+
let [itViewport] = _ref;
|
|
960
|
+
return itViewport.join('x') === viewportSize.join('x');
|
|
961
|
+
}) || [] : [];
|
|
962
|
+
const newSlot = path !== null && !disabled ? adsManager.createSlot(path, viewportFixedSize || size, {
|
|
957
963
|
visible: isVisible,
|
|
958
|
-
sizeMapping,
|
|
964
|
+
sizeMapping: viewportFixedSize === null ? sizeMapping : null,
|
|
959
965
|
targeting,
|
|
960
966
|
categoryExclusions
|
|
961
967
|
}) : null;
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
//
|
|
965
|
-
//
|
|
966
|
-
//
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
968
|
+
slotRef.current = newSlot;
|
|
969
|
+
return newSlot;
|
|
970
|
+
// // setSlot(newSlot);
|
|
971
|
+
// // if (currentSlot.current !== null && adsReady) {
|
|
972
|
+
// // adsManager.defineSlot(currentSlot.current);
|
|
973
|
+
// // }
|
|
974
|
+
// // return currentSlot.current;
|
|
975
|
+
// return () => {
|
|
976
|
+
// slotRef.current = null;
|
|
977
|
+
// if (newSlot !== null) {
|
|
978
|
+
// adsManager.destroySlot(newSlot);
|
|
979
|
+
// }
|
|
980
|
+
// };
|
|
981
|
+
}, [adsManager, path, disabled, size, sizeMapping, viewport, categoryExclusions]);
|
|
973
982
|
React.useEffect(() => {
|
|
974
983
|
if (slot !== null) {
|
|
975
984
|
slot.setTargeting(targeting);
|
|
@@ -1132,11 +1141,13 @@ function useRichAd(containerRef, id, opts) {
|
|
|
1132
1141
|
return richAd;
|
|
1133
1142
|
}
|
|
1134
1143
|
|
|
1144
|
+
/* eslint-disable react/require-default-props */
|
|
1135
1145
|
const propTypes = {
|
|
1136
1146
|
slot: PropTypes.string.isRequired,
|
|
1137
1147
|
path: adPath,
|
|
1138
1148
|
size: adSize,
|
|
1139
1149
|
sizeMapping: adSizeMapping,
|
|
1150
|
+
viewport: PropTypes.string,
|
|
1140
1151
|
targeting: adTargeting,
|
|
1141
1152
|
refreshInterval: PropTypes.number,
|
|
1142
1153
|
alwaysRender: PropTypes.bool,
|
|
@@ -1155,102 +1166,92 @@ const propTypes = {
|
|
|
1155
1166
|
onRichAd: PropTypes.func,
|
|
1156
1167
|
slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
|
1157
1168
|
};
|
|
1158
|
-
const defaultProps = {
|
|
1159
|
-
path: null,
|
|
1160
|
-
size: null,
|
|
1161
|
-
sizeMapping: null,
|
|
1162
|
-
targeting: null,
|
|
1163
|
-
refreshInterval: null,
|
|
1164
|
-
alwaysRender: true,
|
|
1165
|
-
disabled: false,
|
|
1166
|
-
disableTracking: false,
|
|
1167
|
-
shouldKeepSize: false,
|
|
1168
|
-
withoutStyle: false,
|
|
1169
|
-
withoutMinimumSize: false,
|
|
1170
|
-
className: null,
|
|
1171
|
-
emptyClassName: null,
|
|
1172
|
-
adClassName: null,
|
|
1173
|
-
richAdClassName: null,
|
|
1174
|
-
richAdIframeClassName: null,
|
|
1175
|
-
onRender: null,
|
|
1176
|
-
onDestroy: null,
|
|
1177
|
-
onRichAd: null,
|
|
1178
|
-
slotRef: null
|
|
1179
|
-
};
|
|
1180
1169
|
function Ad(_ref) {
|
|
1181
1170
|
let {
|
|
1182
|
-
slot: slotName,
|
|
1183
|
-
path,
|
|
1184
|
-
size,
|
|
1185
|
-
sizeMapping,
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1171
|
+
slot: slotName = null,
|
|
1172
|
+
path: providedPath = null,
|
|
1173
|
+
size: providedSize = null,
|
|
1174
|
+
sizeMapping: providedSizeMapping = null,
|
|
1175
|
+
viewport: providedViewport = null,
|
|
1176
|
+
targeting: providedTargeting = null,
|
|
1177
|
+
refreshInterval: providedRefreshInterval = null,
|
|
1178
|
+
alwaysRender = true,
|
|
1179
|
+
disabled: providedDisabled = false,
|
|
1180
|
+
disableTracking = false,
|
|
1181
|
+
shouldKeepSize = false,
|
|
1182
|
+
withoutStyle = false,
|
|
1183
|
+
withoutMinimumSize = false,
|
|
1184
|
+
className = null,
|
|
1185
|
+
emptyClassName = null,
|
|
1186
|
+
adClassName = null,
|
|
1187
|
+
richAdClassName = null,
|
|
1188
|
+
richAdIframeClassName = null,
|
|
1189
|
+
onRender = null,
|
|
1190
|
+
onDestroy = null,
|
|
1191
|
+
onRichAd = null,
|
|
1192
|
+
slotRef = null
|
|
1203
1193
|
} = _ref;
|
|
1204
1194
|
const {
|
|
1205
1195
|
slots = null,
|
|
1206
|
-
slotsPath =
|
|
1196
|
+
slotsPath = null,
|
|
1197
|
+
viewport: contextViewport = null
|
|
1207
1198
|
} = useAdsContext();
|
|
1199
|
+
const {
|
|
1200
|
+
default: defaultSlotPath = null
|
|
1201
|
+
} = slotsPath || {};
|
|
1208
1202
|
const slot = slotName !== null && slots !== null ? slots[slotName] || null : null;
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1203
|
+
const {
|
|
1204
|
+
sizeMapping: slotSizeMapping = null,
|
|
1205
|
+
size: slotSize = null,
|
|
1206
|
+
path: slotPath = null
|
|
1207
|
+
} = slot || {};
|
|
1208
|
+
const path = providedPath || slotPath || (slotName !== null && slotsPath !== null ? slotsPath[slotName] : null) || defaultSlotPath || null;
|
|
1209
|
+
|
|
1210
|
+
// Size
|
|
1211
|
+
const size = providedSize || slotSize;
|
|
1212
|
+
const sizeMapping = providedSizeMapping || slotSizeMapping;
|
|
1213
|
+
const minimumSize = React.useMemo(() => getMinimumAdSize(sizeMapping !== null ? sizeMapping.reduce((allSizes, sizeMap) => [...allSizes, sizeMap[1]], [size]) : [size]), [sizeMapping, size]);
|
|
1213
1214
|
|
|
1214
1215
|
// Targeting
|
|
1215
1216
|
const contextTargeting = useAdsTargeting();
|
|
1216
1217
|
const {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
...otherTargeting
|
|
1224
|
-
} = contextTargeting || {};
|
|
1225
|
-
return {
|
|
1218
|
+
targeting,
|
|
1219
|
+
refreshInterval,
|
|
1220
|
+
disabled,
|
|
1221
|
+
viewport
|
|
1222
|
+
} = React.useMemo(() => {
|
|
1223
|
+
const allTargeting = {
|
|
1226
1224
|
...(slotName !== null ? {
|
|
1227
1225
|
slot: slotName
|
|
1228
1226
|
} : null),
|
|
1229
|
-
...
|
|
1230
|
-
...
|
|
1227
|
+
...contextTargeting,
|
|
1228
|
+
...providedTargeting
|
|
1231
1229
|
};
|
|
1232
|
-
}, [contextTargeting, targeting, slotName]);
|
|
1233
|
-
const finalAdTargeting = React.useMemo(() => {
|
|
1234
1230
|
const {
|
|
1235
1231
|
refreshAds = null,
|
|
1232
|
+
disabled: targetingDisabled = false,
|
|
1233
|
+
viewport: targetingViewport = null,
|
|
1236
1234
|
...otherProps
|
|
1237
1235
|
} = allTargeting || {};
|
|
1238
1236
|
return {
|
|
1239
|
-
refreshInterval: refreshAds !== null && refreshAds === 'inactive' ? null :
|
|
1237
|
+
refreshInterval: refreshAds !== null && refreshAds === 'inactive' ? null : providedRefreshInterval,
|
|
1238
|
+
disabled: providedDisabled || targetingDisabled,
|
|
1239
|
+
viewport: providedViewport || contextViewport || targetingViewport,
|
|
1240
1240
|
targeting: otherProps || {}
|
|
1241
1241
|
};
|
|
1242
|
-
}, [
|
|
1242
|
+
}, [contextTargeting, providedTargeting, slotName, providedRefreshInterval]);
|
|
1243
1243
|
const lastRenderedSize = React.useRef(null);
|
|
1244
|
-
const wasDisabled = React.useRef(
|
|
1244
|
+
const wasDisabled = React.useRef(disabled);
|
|
1245
|
+
React.useEffect(() => {}, []);
|
|
1245
1246
|
const onAdRender = React.useCallback(event => {
|
|
1246
1247
|
const {
|
|
1247
1248
|
isEmpty: newIsEmpty = true,
|
|
1248
1249
|
width: newWidth,
|
|
1249
1250
|
height: newHeight
|
|
1250
1251
|
} = event || {};
|
|
1251
|
-
if (
|
|
1252
|
+
if (disabled) {
|
|
1252
1253
|
wasDisabled.current = true;
|
|
1253
|
-
} else if (!
|
|
1254
|
+
} else if (!disabled && !newIsEmpty) {
|
|
1254
1255
|
wasDisabled.current = false;
|
|
1255
1256
|
}
|
|
1256
1257
|
lastRenderedSize.current = !newIsEmpty ? {
|
|
@@ -1260,7 +1261,7 @@ function Ad(_ref) {
|
|
|
1260
1261
|
if (onRender !== null) {
|
|
1261
1262
|
onRender(event);
|
|
1262
1263
|
}
|
|
1263
|
-
}, [onRender, shouldKeepSize,
|
|
1264
|
+
}, [onRender, shouldKeepSize, disabled]);
|
|
1264
1265
|
|
|
1265
1266
|
// useEffect(() => {
|
|
1266
1267
|
// if (!disabled) {
|
|
@@ -1286,14 +1287,15 @@ function Ad(_ref) {
|
|
|
1286
1287
|
isRendered,
|
|
1287
1288
|
refObserver,
|
|
1288
1289
|
slot: slotObject = null
|
|
1289
|
-
} = useAd(
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1290
|
+
} = useAd(path, size, {
|
|
1291
|
+
viewport,
|
|
1292
|
+
sizeMapping,
|
|
1293
|
+
targeting,
|
|
1294
|
+
refreshInterval,
|
|
1293
1295
|
alwaysRender,
|
|
1294
1296
|
onRender: onAdRender,
|
|
1295
1297
|
onDestroy,
|
|
1296
|
-
disabled
|
|
1298
|
+
disabled,
|
|
1297
1299
|
disableTracking
|
|
1298
1300
|
});
|
|
1299
1301
|
const adContainerRef = React.useRef(null);
|
|
@@ -1306,13 +1308,13 @@ function Ad(_ref) {
|
|
|
1306
1308
|
// eslint-disable-next-line no-param-reassign
|
|
1307
1309
|
slotRef.current = slotObject;
|
|
1308
1310
|
}
|
|
1309
|
-
if (
|
|
1311
|
+
if (disabled) {
|
|
1310
1312
|
wasDisabled.current = true;
|
|
1311
|
-
} else if (!
|
|
1313
|
+
} else if (!disabled && isRendered) {
|
|
1312
1314
|
wasDisabled.current = false;
|
|
1313
1315
|
}
|
|
1314
1316
|
const waitingNextRender = wasDisabled.current && !isRendered;
|
|
1315
|
-
const keepSize = shouldKeepSize && (
|
|
1317
|
+
const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
1316
1318
|
if (id === null && !keepSize) {
|
|
1317
1319
|
return null;
|
|
1318
1320
|
}
|
|
@@ -1322,7 +1324,7 @@ function Ad(_ref) {
|
|
|
1322
1324
|
width,
|
|
1323
1325
|
height
|
|
1324
1326
|
} : null;
|
|
1325
|
-
} else if (shouldKeepSize && (
|
|
1327
|
+
} else if (shouldKeepSize && (disabled || waitingNextRender)) {
|
|
1326
1328
|
adStyle = lastRenderedSize.current;
|
|
1327
1329
|
} else if (!withoutMinimumSize) {
|
|
1328
1330
|
adStyle = minimumSize;
|
|
@@ -1371,7 +1373,6 @@ function Ad(_ref) {
|
|
|
1371
1373
|
});
|
|
1372
1374
|
}
|
|
1373
1375
|
Ad.propTypes = propTypes;
|
|
1374
|
-
Ad.defaultProps = defaultProps;
|
|
1375
1376
|
|
|
1376
1377
|
exports.Ad = Ad;
|
|
1377
1378
|
exports.AdSlot = AdSlot;
|
|
@@ -1384,6 +1385,7 @@ exports.buildSizeMappingFromSizes = buildSizeMappingFromSizes;
|
|
|
1384
1385
|
exports.buildSizeMappingFromViewports = buildSizeMappingFromViewports;
|
|
1385
1386
|
exports.getAdSizes = getAdSizes;
|
|
1386
1387
|
exports.getMinimumAdSize = getMinimumAdSize;
|
|
1388
|
+
exports.getSizeFromSizeMapping = getSizeFromSizeMapping;
|
|
1387
1389
|
exports.getSizeMappingFromSlot = getSizeMappingFromSlot;
|
|
1388
1390
|
exports.getSortedViewports = getSortedViewports;
|
|
1389
1391
|
exports.sizeFitsInViewport = sizeFitsInViewport;
|
package/dist/es.js
CHANGED
|
@@ -38,13 +38,10 @@ var propTypes$4 = /*#__PURE__*/Object.freeze({
|
|
|
38
38
|
adViewports: adViewports
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return sizes.split('x').map(it => parseInt(it, 10));
|
|
46
|
-
};
|
|
47
|
-
const getMinimumAdSize = sizes => getAdSizes(sizes).reduce((minimumSize, size) => ({
|
|
41
|
+
function getAdSizes(sizes) {
|
|
42
|
+
return uniqBy(sizes, size => isArray(size) ? size.join('x') : size);
|
|
43
|
+
}
|
|
44
|
+
const getMinimumAdSize = sizes => getAdSizes(sizes).filter(size => size !== 'fluid').reduce((minimumSize, size) => ({
|
|
48
45
|
width: Math.min(minimumSize.width, size[0]),
|
|
49
46
|
height: Math.min(minimumSize.height, size[1])
|
|
50
47
|
}), {
|
|
@@ -80,6 +77,23 @@ const getSizeMappingFromSlot = (_ref3, viewports) => {
|
|
|
80
77
|
}
|
|
81
78
|
return sizeMapping !== null ? buildSizeMappingFromViewports(sizeMapping, viewports) : null;
|
|
82
79
|
};
|
|
80
|
+
function getSizeFromSizeMapping(sizeMapping) {
|
|
81
|
+
if (sizeMapping === null) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return getAdSizes(sizeMapping.reduce((allSizes, sizeMap) => [...allSizes, ...sizeMap[1]], [])).sort((a, b) => {
|
|
85
|
+
if (a === 'fluid') {
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
if (b === 'fluid') {
|
|
89
|
+
return -1;
|
|
90
|
+
}
|
|
91
|
+
if (a[0] === b[0]) {
|
|
92
|
+
return a[1] > b[1] ? 1 : -1;
|
|
93
|
+
}
|
|
94
|
+
return a[0] > b[0] ? 1 : -1;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
83
97
|
|
|
84
98
|
class AdSlot extends EventEmitter {
|
|
85
99
|
constructor(id, path, size) {
|
|
@@ -613,19 +627,6 @@ const viewports = {
|
|
|
613
627
|
};
|
|
614
628
|
const slots = {
|
|
615
629
|
top: {
|
|
616
|
-
size: [[300, 100], [300, 150], [320, 50], [320, 100], [320, 180]
|
|
617
|
-
// [300, 100],
|
|
618
|
-
// [300, 150],
|
|
619
|
-
// [320, 50],
|
|
620
|
-
// [320, 100],
|
|
621
|
-
// [640, 350],
|
|
622
|
-
// [728, 90],
|
|
623
|
-
// [970, 90],
|
|
624
|
-
// [970, 250],
|
|
625
|
-
// [1024, 300],
|
|
626
|
-
// [1382, 300],
|
|
627
|
-
// [1382, 600],
|
|
628
|
-
],
|
|
629
630
|
sizeMapping: {
|
|
630
631
|
default: [[300, 100], [300, 150], [320, 50], [320, 100], [320, 180]],
|
|
631
632
|
tablet: [[300, 100], [300, 150], [320, 50], [320, 100], [320, 180], [728, 90]],
|
|
@@ -637,14 +638,12 @@ const slots = {
|
|
|
637
638
|
size: [[250, 250], [300, 250]]
|
|
638
639
|
},
|
|
639
640
|
sidebar: {
|
|
640
|
-
size: [[120, 600], [160, 600], [300, 600], [300, 250]],
|
|
641
641
|
sizeMapping: {
|
|
642
642
|
default: [[300, 250]],
|
|
643
643
|
laptop: [[120, 600], [160, 600], [300, 250], [300, 600]]
|
|
644
644
|
}
|
|
645
645
|
},
|
|
646
646
|
fullwidth: {
|
|
647
|
-
size: [[250, 250], [300, 100], [300, 150], [300, 250], [320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 360], [640, 350], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300], [1382, 300], [1382, 600]],
|
|
648
647
|
sizeMapping: {
|
|
649
648
|
default: [[250, 250], [300, 100], [300, 150], [300, 250], [320, 50], [320, 100], [320, 180], [336, 280]],
|
|
650
649
|
tablet: [[250, 250], [300, 100], [300, 150], [300, 250], [320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 350], [640, 360], [728, 90]],
|
|
@@ -653,32 +652,17 @@ const slots = {
|
|
|
653
652
|
}
|
|
654
653
|
},
|
|
655
654
|
content: {
|
|
656
|
-
size: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250], [300, 600], [320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 350], [640, 360], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300], [1382, 300], [1382, 600]
|
|
657
|
-
// [120, 600],
|
|
658
|
-
// [160, 600],
|
|
659
|
-
// [250, 250],
|
|
660
|
-
// [300, 100],
|
|
661
|
-
// [300, 150],
|
|
662
|
-
// [300, 250],
|
|
663
|
-
// [300, 600],
|
|
664
|
-
// [320, 50],
|
|
665
|
-
// [320, 100],
|
|
666
|
-
// [336, 280],
|
|
667
|
-
// [634, 634],
|
|
668
|
-
// [640, 350],
|
|
669
|
-
// [728, 90],
|
|
670
|
-
// [970, 90],
|
|
671
|
-
// [970, 250],
|
|
672
|
-
// [970, 415],
|
|
673
|
-
// [1024, 300],
|
|
674
|
-
// [1382, 300],
|
|
675
|
-
// [1382, 600],
|
|
676
|
-
],
|
|
677
655
|
sizeMapping: {
|
|
678
656
|
default: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250], [300, 600], [320, 50], [320, 100], [320, 180], [336, 280]],
|
|
679
|
-
tablet: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250],
|
|
680
|
-
|
|
681
|
-
|
|
657
|
+
tablet: [[120, 600], [160, 600], [250, 250], [300, 100], [300, 150], [300, 250],
|
|
658
|
+
// [300, 600],
|
|
659
|
+
[320, 50], [320, 100], [320, 180], [336, 280], [634, 634], [640, 350], [640, 360], [728, 90]],
|
|
660
|
+
desktop: [[120, 600], [160, 600],
|
|
661
|
+
// [300, 600],
|
|
662
|
+
[634, 634], [640, 350], [640, 360], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300]],
|
|
663
|
+
laptop: [[120, 600], [160, 600],
|
|
664
|
+
// [300, 600],
|
|
665
|
+
[634, 634], [640, 350], [640, 360], [728, 90], [960, 540], [970, 90], [970, 250], [970, 415], [1024, 300], [1382, 300], [1382, 600]]
|
|
682
666
|
}
|
|
683
667
|
}
|
|
684
668
|
};
|
|
@@ -701,13 +685,14 @@ const propTypes$3 = {
|
|
|
701
685
|
mobileScaling: PropTypes.number,
|
|
702
686
|
renderMarginPercent: PropTypes.number,
|
|
703
687
|
fetchMarginPercent: PropTypes.number,
|
|
688
|
+
viewport: PropTypes.string,
|
|
704
689
|
slots: adSlots,
|
|
705
690
|
viewports: adViewports,
|
|
706
691
|
richAdComponents: PropTypes.objectOf(PropTypes.elementType),
|
|
707
692
|
disabled: PropTypes.bool,
|
|
708
693
|
disableTracking: PropTypes.bool
|
|
709
694
|
};
|
|
710
|
-
const defaultProps$
|
|
695
|
+
const defaultProps$2 = {
|
|
711
696
|
defaultSlotPath: null,
|
|
712
697
|
slotsPath: null,
|
|
713
698
|
disableSingleRequest: false,
|
|
@@ -719,6 +704,7 @@ const defaultProps$3 = {
|
|
|
719
704
|
mobileScaling: 1.0,
|
|
720
705
|
renderMarginPercent: 100,
|
|
721
706
|
fetchMarginPercent: 300,
|
|
707
|
+
viewport: null,
|
|
722
708
|
slots: slots,
|
|
723
709
|
viewports: viewports,
|
|
724
710
|
richAdComponents: null,
|
|
@@ -739,6 +725,7 @@ function AdsProvider(_ref) {
|
|
|
739
725
|
mobileScaling,
|
|
740
726
|
renderMarginPercent,
|
|
741
727
|
fetchMarginPercent,
|
|
728
|
+
viewport,
|
|
742
729
|
viewports,
|
|
743
730
|
slots,
|
|
744
731
|
richAdComponents,
|
|
@@ -795,13 +782,21 @@ function AdsProvider(_ref) {
|
|
|
795
782
|
onResize.cancel();
|
|
796
783
|
};
|
|
797
784
|
}, [ads, resizeDebounceDelay, refreshOnResize]);
|
|
798
|
-
const slotsWithSizeMapping = useMemo(() => Object.keys(slots || {}).reduce((map, key) =>
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
785
|
+
const slotsWithSizeMapping = useMemo(() => Object.keys(slots || {}).reduce((map, key) => {
|
|
786
|
+
const slot = slots[key];
|
|
787
|
+
const {
|
|
788
|
+
size
|
|
789
|
+
} = slot;
|
|
790
|
+
const sizeMapping = getSizeMappingFromSlot(slot, viewports);
|
|
791
|
+
return {
|
|
792
|
+
...map,
|
|
793
|
+
[key]: {
|
|
794
|
+
...slot,
|
|
795
|
+
size: size || getSizeFromSizeMapping(sizeMapping || null),
|
|
796
|
+
sizeMapping
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
}, {}), []);
|
|
805
800
|
const finalSlotsPath = useMemo(() => defaultSlotPath !== null ? {
|
|
806
801
|
default: defaultSlotPath,
|
|
807
802
|
...slotsPath
|
|
@@ -812,18 +807,19 @@ function AdsProvider(_ref) {
|
|
|
812
807
|
ready,
|
|
813
808
|
ads,
|
|
814
809
|
viewports,
|
|
810
|
+
viewport,
|
|
815
811
|
slots: slotsWithSizeMapping,
|
|
816
812
|
slotsPath: finalSlotsPath,
|
|
817
813
|
trackingDisabled: disableTracking,
|
|
818
814
|
richAdComponents
|
|
819
|
-
}), [ready, ads, viewports, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
815
|
+
}), [ready, ads, viewports, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
820
816
|
return /*#__PURE__*/jsx(AdsContext.Provider, {
|
|
821
817
|
value: value,
|
|
822
818
|
children: children
|
|
823
819
|
});
|
|
824
820
|
}
|
|
825
821
|
AdsProvider.propTypes = propTypes$3;
|
|
826
|
-
AdsProvider.defaultProps = defaultProps$
|
|
822
|
+
AdsProvider.defaultProps = defaultProps$2;
|
|
827
823
|
|
|
828
824
|
const AdsTargetingContext = /*#__PURE__*/React.createContext(null);
|
|
829
825
|
const useAdsTargeting = () => useContext(AdsTargetingContext);
|
|
@@ -833,7 +829,7 @@ const propTypes$2 = {
|
|
|
833
829
|
targeting: PropTypes.object,
|
|
834
830
|
replace: PropTypes.bool
|
|
835
831
|
};
|
|
836
|
-
const defaultProps$
|
|
832
|
+
const defaultProps$1 = {
|
|
837
833
|
targeting: {
|
|
838
834
|
domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
|
|
839
835
|
},
|
|
@@ -856,7 +852,7 @@ function AdsTargetingProvider(_ref) {
|
|
|
856
852
|
});
|
|
857
853
|
}
|
|
858
854
|
AdsTargetingProvider.propTypes = propTypes$2;
|
|
859
|
-
AdsTargetingProvider.defaultProps = defaultProps$
|
|
855
|
+
AdsTargetingProvider.defaultProps = defaultProps$1;
|
|
860
856
|
|
|
861
857
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
862
858
|
const propTypes$1 = {
|
|
@@ -864,7 +860,7 @@ const propTypes$1 = {
|
|
|
864
860
|
type: PropTypes.string.isRequired
|
|
865
861
|
}).isRequired
|
|
866
862
|
};
|
|
867
|
-
const defaultProps
|
|
863
|
+
const defaultProps = {};
|
|
868
864
|
function RichAd(_ref) {
|
|
869
865
|
let {
|
|
870
866
|
richAd,
|
|
@@ -884,7 +880,7 @@ function RichAd(_ref) {
|
|
|
884
880
|
}) : null;
|
|
885
881
|
}
|
|
886
882
|
RichAd.propTypes = propTypes$1;
|
|
887
|
-
RichAd.defaultProps = defaultProps
|
|
883
|
+
RichAd.defaultProps = defaultProps;
|
|
888
884
|
|
|
889
885
|
function useAdsTracking() {
|
|
890
886
|
const tracking = useTracking() || null;
|
|
@@ -899,6 +895,7 @@ function useAdsTracking() {
|
|
|
899
895
|
function useAd(path, size) {
|
|
900
896
|
let {
|
|
901
897
|
sizeMapping = null,
|
|
898
|
+
viewport = null,
|
|
902
899
|
targeting = null,
|
|
903
900
|
categoryExclusions = null,
|
|
904
901
|
refreshInterval = null,
|
|
@@ -911,6 +908,7 @@ function useAd(path, size) {
|
|
|
911
908
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
912
909
|
const {
|
|
913
910
|
ads: adsManager,
|
|
911
|
+
viewports,
|
|
914
912
|
ready: adsReady,
|
|
915
913
|
trackingDisabled: globalTrackingDisabled = false
|
|
916
914
|
} = useAdsContext();
|
|
@@ -944,30 +942,41 @@ function useAd(path, size) {
|
|
|
944
942
|
const [renderEvent, setRenderEvent] = useState(null);
|
|
945
943
|
|
|
946
944
|
// Create slot
|
|
947
|
-
|
|
948
|
-
const
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
945
|
+
const slotRef = useRef(null);
|
|
946
|
+
// const { current: slot } = slotRef;
|
|
947
|
+
// const [slot, setSlot] = useState(null);
|
|
948
|
+
const slot = useMemo(() => {
|
|
949
|
+
const {
|
|
950
|
+
current: currentSlot = null
|
|
951
|
+
} = slotRef;
|
|
952
|
+
if (currentSlot !== null) {
|
|
953
|
+
adsManager.destroySlot(currentSlot);
|
|
954
|
+
}
|
|
955
|
+
const viewportSize = viewport !== null ? viewports[viewport] || null : null;
|
|
956
|
+
const [, viewportFixedSize = null] = sizeMapping !== null && viewportSize !== null ? sizeMapping.find(_ref => {
|
|
957
|
+
let [itViewport] = _ref;
|
|
958
|
+
return itViewport.join('x') === viewportSize.join('x');
|
|
959
|
+
}) || [] : [];
|
|
960
|
+
const newSlot = path !== null && !disabled ? adsManager.createSlot(path, viewportFixedSize || size, {
|
|
955
961
|
visible: isVisible,
|
|
956
|
-
sizeMapping,
|
|
962
|
+
sizeMapping: viewportFixedSize === null ? sizeMapping : null,
|
|
957
963
|
targeting,
|
|
958
964
|
categoryExclusions
|
|
959
965
|
}) : null;
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
//
|
|
963
|
-
//
|
|
964
|
-
//
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
966
|
+
slotRef.current = newSlot;
|
|
967
|
+
return newSlot;
|
|
968
|
+
// // setSlot(newSlot);
|
|
969
|
+
// // if (currentSlot.current !== null && adsReady) {
|
|
970
|
+
// // adsManager.defineSlot(currentSlot.current);
|
|
971
|
+
// // }
|
|
972
|
+
// // return currentSlot.current;
|
|
973
|
+
// return () => {
|
|
974
|
+
// slotRef.current = null;
|
|
975
|
+
// if (newSlot !== null) {
|
|
976
|
+
// adsManager.destroySlot(newSlot);
|
|
977
|
+
// }
|
|
978
|
+
// };
|
|
979
|
+
}, [adsManager, path, disabled, size, sizeMapping, viewport, categoryExclusions]);
|
|
971
980
|
useEffect(() => {
|
|
972
981
|
if (slot !== null) {
|
|
973
982
|
slot.setTargeting(targeting);
|
|
@@ -1130,11 +1139,13 @@ function useRichAd(containerRef, id, opts) {
|
|
|
1130
1139
|
return richAd;
|
|
1131
1140
|
}
|
|
1132
1141
|
|
|
1142
|
+
/* eslint-disable react/require-default-props */
|
|
1133
1143
|
const propTypes = {
|
|
1134
1144
|
slot: PropTypes.string.isRequired,
|
|
1135
1145
|
path: adPath,
|
|
1136
1146
|
size: adSize,
|
|
1137
1147
|
sizeMapping: adSizeMapping,
|
|
1148
|
+
viewport: PropTypes.string,
|
|
1138
1149
|
targeting: adTargeting,
|
|
1139
1150
|
refreshInterval: PropTypes.number,
|
|
1140
1151
|
alwaysRender: PropTypes.bool,
|
|
@@ -1153,102 +1164,92 @@ const propTypes = {
|
|
|
1153
1164
|
onRichAd: PropTypes.func,
|
|
1154
1165
|
slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
|
1155
1166
|
};
|
|
1156
|
-
const defaultProps = {
|
|
1157
|
-
path: null,
|
|
1158
|
-
size: null,
|
|
1159
|
-
sizeMapping: null,
|
|
1160
|
-
targeting: null,
|
|
1161
|
-
refreshInterval: null,
|
|
1162
|
-
alwaysRender: true,
|
|
1163
|
-
disabled: false,
|
|
1164
|
-
disableTracking: false,
|
|
1165
|
-
shouldKeepSize: false,
|
|
1166
|
-
withoutStyle: false,
|
|
1167
|
-
withoutMinimumSize: false,
|
|
1168
|
-
className: null,
|
|
1169
|
-
emptyClassName: null,
|
|
1170
|
-
adClassName: null,
|
|
1171
|
-
richAdClassName: null,
|
|
1172
|
-
richAdIframeClassName: null,
|
|
1173
|
-
onRender: null,
|
|
1174
|
-
onDestroy: null,
|
|
1175
|
-
onRichAd: null,
|
|
1176
|
-
slotRef: null
|
|
1177
|
-
};
|
|
1178
1167
|
function Ad(_ref) {
|
|
1179
1168
|
let {
|
|
1180
|
-
slot: slotName,
|
|
1181
|
-
path,
|
|
1182
|
-
size,
|
|
1183
|
-
sizeMapping,
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1169
|
+
slot: slotName = null,
|
|
1170
|
+
path: providedPath = null,
|
|
1171
|
+
size: providedSize = null,
|
|
1172
|
+
sizeMapping: providedSizeMapping = null,
|
|
1173
|
+
viewport: providedViewport = null,
|
|
1174
|
+
targeting: providedTargeting = null,
|
|
1175
|
+
refreshInterval: providedRefreshInterval = null,
|
|
1176
|
+
alwaysRender = true,
|
|
1177
|
+
disabled: providedDisabled = false,
|
|
1178
|
+
disableTracking = false,
|
|
1179
|
+
shouldKeepSize = false,
|
|
1180
|
+
withoutStyle = false,
|
|
1181
|
+
withoutMinimumSize = false,
|
|
1182
|
+
className = null,
|
|
1183
|
+
emptyClassName = null,
|
|
1184
|
+
adClassName = null,
|
|
1185
|
+
richAdClassName = null,
|
|
1186
|
+
richAdIframeClassName = null,
|
|
1187
|
+
onRender = null,
|
|
1188
|
+
onDestroy = null,
|
|
1189
|
+
onRichAd = null,
|
|
1190
|
+
slotRef = null
|
|
1201
1191
|
} = _ref;
|
|
1202
1192
|
const {
|
|
1203
1193
|
slots = null,
|
|
1204
|
-
slotsPath =
|
|
1194
|
+
slotsPath = null,
|
|
1195
|
+
viewport: contextViewport = null
|
|
1205
1196
|
} = useAdsContext();
|
|
1197
|
+
const {
|
|
1198
|
+
default: defaultSlotPath = null
|
|
1199
|
+
} = slotsPath || {};
|
|
1206
1200
|
const slot = slotName !== null && slots !== null ? slots[slotName] || null : null;
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1201
|
+
const {
|
|
1202
|
+
sizeMapping: slotSizeMapping = null,
|
|
1203
|
+
size: slotSize = null,
|
|
1204
|
+
path: slotPath = null
|
|
1205
|
+
} = slot || {};
|
|
1206
|
+
const path = providedPath || slotPath || (slotName !== null && slotsPath !== null ? slotsPath[slotName] : null) || defaultSlotPath || null;
|
|
1207
|
+
|
|
1208
|
+
// Size
|
|
1209
|
+
const size = providedSize || slotSize;
|
|
1210
|
+
const sizeMapping = providedSizeMapping || slotSizeMapping;
|
|
1211
|
+
const minimumSize = useMemo(() => getMinimumAdSize(sizeMapping !== null ? sizeMapping.reduce((allSizes, sizeMap) => [...allSizes, sizeMap[1]], [size]) : [size]), [sizeMapping, size]);
|
|
1211
1212
|
|
|
1212
1213
|
// Targeting
|
|
1213
1214
|
const contextTargeting = useAdsTargeting();
|
|
1214
1215
|
const {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
...otherTargeting
|
|
1222
|
-
} = contextTargeting || {};
|
|
1223
|
-
return {
|
|
1216
|
+
targeting,
|
|
1217
|
+
refreshInterval,
|
|
1218
|
+
disabled,
|
|
1219
|
+
viewport
|
|
1220
|
+
} = useMemo(() => {
|
|
1221
|
+
const allTargeting = {
|
|
1224
1222
|
...(slotName !== null ? {
|
|
1225
1223
|
slot: slotName
|
|
1226
1224
|
} : null),
|
|
1227
|
-
...
|
|
1228
|
-
...
|
|
1225
|
+
...contextTargeting,
|
|
1226
|
+
...providedTargeting
|
|
1229
1227
|
};
|
|
1230
|
-
}, [contextTargeting, targeting, slotName]);
|
|
1231
|
-
const finalAdTargeting = useMemo(() => {
|
|
1232
1228
|
const {
|
|
1233
1229
|
refreshAds = null,
|
|
1230
|
+
disabled: targetingDisabled = false,
|
|
1231
|
+
viewport: targetingViewport = null,
|
|
1234
1232
|
...otherProps
|
|
1235
1233
|
} = allTargeting || {};
|
|
1236
1234
|
return {
|
|
1237
|
-
refreshInterval: refreshAds !== null && refreshAds === 'inactive' ? null :
|
|
1235
|
+
refreshInterval: refreshAds !== null && refreshAds === 'inactive' ? null : providedRefreshInterval,
|
|
1236
|
+
disabled: providedDisabled || targetingDisabled,
|
|
1237
|
+
viewport: providedViewport || contextViewport || targetingViewport,
|
|
1238
1238
|
targeting: otherProps || {}
|
|
1239
1239
|
};
|
|
1240
|
-
}, [
|
|
1240
|
+
}, [contextTargeting, providedTargeting, slotName, providedRefreshInterval]);
|
|
1241
1241
|
const lastRenderedSize = useRef(null);
|
|
1242
|
-
const wasDisabled = useRef(
|
|
1242
|
+
const wasDisabled = useRef(disabled);
|
|
1243
|
+
useEffect(() => {}, []);
|
|
1243
1244
|
const onAdRender = useCallback(event => {
|
|
1244
1245
|
const {
|
|
1245
1246
|
isEmpty: newIsEmpty = true,
|
|
1246
1247
|
width: newWidth,
|
|
1247
1248
|
height: newHeight
|
|
1248
1249
|
} = event || {};
|
|
1249
|
-
if (
|
|
1250
|
+
if (disabled) {
|
|
1250
1251
|
wasDisabled.current = true;
|
|
1251
|
-
} else if (!
|
|
1252
|
+
} else if (!disabled && !newIsEmpty) {
|
|
1252
1253
|
wasDisabled.current = false;
|
|
1253
1254
|
}
|
|
1254
1255
|
lastRenderedSize.current = !newIsEmpty ? {
|
|
@@ -1258,7 +1259,7 @@ function Ad(_ref) {
|
|
|
1258
1259
|
if (onRender !== null) {
|
|
1259
1260
|
onRender(event);
|
|
1260
1261
|
}
|
|
1261
|
-
}, [onRender, shouldKeepSize,
|
|
1262
|
+
}, [onRender, shouldKeepSize, disabled]);
|
|
1262
1263
|
|
|
1263
1264
|
// useEffect(() => {
|
|
1264
1265
|
// if (!disabled) {
|
|
@@ -1284,14 +1285,15 @@ function Ad(_ref) {
|
|
|
1284
1285
|
isRendered,
|
|
1285
1286
|
refObserver,
|
|
1286
1287
|
slot: slotObject = null
|
|
1287
|
-
} = useAd(
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1288
|
+
} = useAd(path, size, {
|
|
1289
|
+
viewport,
|
|
1290
|
+
sizeMapping,
|
|
1291
|
+
targeting,
|
|
1292
|
+
refreshInterval,
|
|
1291
1293
|
alwaysRender,
|
|
1292
1294
|
onRender: onAdRender,
|
|
1293
1295
|
onDestroy,
|
|
1294
|
-
disabled
|
|
1296
|
+
disabled,
|
|
1295
1297
|
disableTracking
|
|
1296
1298
|
});
|
|
1297
1299
|
const adContainerRef = useRef(null);
|
|
@@ -1304,13 +1306,13 @@ function Ad(_ref) {
|
|
|
1304
1306
|
// eslint-disable-next-line no-param-reassign
|
|
1305
1307
|
slotRef.current = slotObject;
|
|
1306
1308
|
}
|
|
1307
|
-
if (
|
|
1309
|
+
if (disabled) {
|
|
1308
1310
|
wasDisabled.current = true;
|
|
1309
|
-
} else if (!
|
|
1311
|
+
} else if (!disabled && isRendered) {
|
|
1310
1312
|
wasDisabled.current = false;
|
|
1311
1313
|
}
|
|
1312
1314
|
const waitingNextRender = wasDisabled.current && !isRendered;
|
|
1313
|
-
const keepSize = shouldKeepSize && (
|
|
1315
|
+
const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
1314
1316
|
if (id === null && !keepSize) {
|
|
1315
1317
|
return null;
|
|
1316
1318
|
}
|
|
@@ -1320,7 +1322,7 @@ function Ad(_ref) {
|
|
|
1320
1322
|
width,
|
|
1321
1323
|
height
|
|
1322
1324
|
} : null;
|
|
1323
|
-
} else if (shouldKeepSize && (
|
|
1325
|
+
} else if (shouldKeepSize && (disabled || waitingNextRender)) {
|
|
1324
1326
|
adStyle = lastRenderedSize.current;
|
|
1325
1327
|
} else if (!withoutMinimumSize) {
|
|
1326
1328
|
adStyle = minimumSize;
|
|
@@ -1369,6 +1371,5 @@ function Ad(_ref) {
|
|
|
1369
1371
|
});
|
|
1370
1372
|
}
|
|
1371
1373
|
Ad.propTypes = propTypes;
|
|
1372
|
-
Ad.defaultProps = defaultProps;
|
|
1373
1374
|
|
|
1374
|
-
export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes$4 as PropTypes, RichAd, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeMappingFromSlot, getSortedViewports, sizeFitsInViewport, slots, useAd, useAdsContext, useAdsTargeting, useAdsTracking, useRichAd, viewports };
|
|
1375
|
+
export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes$4 as PropTypes, RichAd, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeFromSizeMapping, getSizeMappingFromSlot, getSortedViewports, sizeFitsInViewport, slots, useAd, useAdsContext, useAdsTargeting, useAdsTracking, useRichAd, viewports };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.101",
|
|
4
4
|
"description": "Ads library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "4d23bd8673f61fcb67526866cf0366455f4f674a",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@folklore/hooks": "^0.0.72",
|
|
56
56
|
"@folklore/tracking": "^0.0.29",
|