@folklore/ads 0.0.109 → 0.0.110
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 +92 -159
- package/dist/es.js +93 -160
- package/package.json +8 -5
- package/types/Ad.d.ts +30 -0
- package/types/AdSlot.d.ts +57 -0
- package/types/AdsContext.d.ts +37 -0
- package/types/AdsManager.d.ts +72 -0
- package/types/AdsTargetingContext.d.ts +11 -0
- package/types/RichAd.d.ts +7 -0
- package/types/__tests__/utils.test.d.ts +1 -0
- package/types/defaults.d.ts +3 -0
- package/types/index.d.ts +13 -0
- package/types/propTypes.d.ts +7 -0
- package/types/types.d.ts +34 -0
- package/types/useAd.d.ts +30 -0
- package/types/useAdsTracking.d.ts +2 -0
- package/types/useRichAd.d.ts +6 -0
- package/types/utils.d.ts +10 -0
package/dist/cjs.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var PropTypes = require('prop-types');
|
|
4
4
|
var classNames = require('classnames');
|
|
5
|
-
var isFunction = require('lodash/isFunction');
|
|
6
|
-
var isObject = require('lodash/isObject');
|
|
7
5
|
var React = require('react');
|
|
8
6
|
var isArray = require('lodash/isArray');
|
|
7
|
+
var isObject = require('lodash/isObject');
|
|
9
8
|
var sortBy = require('lodash/sortBy');
|
|
10
9
|
var uniqBy = require('lodash/uniqBy');
|
|
11
10
|
var debounce = require('lodash/debounce');
|
|
@@ -29,7 +28,7 @@ const adTargeting = PropTypes.shape({
|
|
|
29
28
|
domain: PropTypes.string
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
var propTypes
|
|
31
|
+
var propTypes = /*#__PURE__*/Object.freeze({
|
|
33
32
|
__proto__: null,
|
|
34
33
|
adPath: adPath,
|
|
35
34
|
adSize: adSize,
|
|
@@ -52,33 +51,43 @@ function normalizeAdSizes(size) {
|
|
|
52
51
|
function getAdSizes(sizes) {
|
|
53
52
|
return uniqBy(sizes, size => isArray(size) ? size.join('x') : size);
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
size
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
name,
|
|
70
|
-
size: viewPortSize
|
|
71
|
-
} = _ref;
|
|
72
|
-
return typeof sizeMapping[name] !== 'undefined' ? [...newSizeMapping, [viewPortSize, sizeMapping[name]]] : newSizeMapping;
|
|
73
|
-
}, []) : sizeMapping;
|
|
74
|
-
const buildSizeMappingFromSizes = (sizes, viewports) => getSortedViewports(viewports).map(_ref2 => {
|
|
75
|
-
let {
|
|
54
|
+
function getMinimumAdSize(sizes) {
|
|
55
|
+
return getAdSizes(sizes).filter(size => size !== 'fluid').reduce((minimumSize, size) => ({
|
|
56
|
+
width: Math.min(minimumSize.width, size[0]),
|
|
57
|
+
height: Math.min(minimumSize.height, size[1])
|
|
58
|
+
}), {
|
|
59
|
+
width: Infinity,
|
|
60
|
+
height: Infinity
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function sizeFitsInViewport(size, viewport) {
|
|
64
|
+
return size === 'fluid' && viewport[0] > 600 || size !== 'fluid' && (viewport[0] === 0 || size[0] <= viewport[0]) && (viewport[1] === 0 || size[1] <= viewport[1]);
|
|
65
|
+
}
|
|
66
|
+
function getSortedViewports(viewports) {
|
|
67
|
+
return sortBy(Object.keys(viewports).map(name => ({
|
|
76
68
|
name,
|
|
77
|
-
size:
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
size: viewports[name]
|
|
70
|
+
})), [viewport => viewport.size[0]]).reverse();
|
|
71
|
+
}
|
|
72
|
+
function buildSizeMappingFromViewports(sizeMapping, viewports) {
|
|
73
|
+
return isObject(sizeMapping) && !isArray(sizeMapping) ? getSortedViewports(viewports).reduce((newSizeMapping, _ref) => {
|
|
74
|
+
let {
|
|
75
|
+
name,
|
|
76
|
+
size: viewPortSize
|
|
77
|
+
} = _ref;
|
|
78
|
+
return typeof sizeMapping[name] !== 'undefined' ? [...newSizeMapping, [viewPortSize, sizeMapping[name]]] : newSizeMapping;
|
|
79
|
+
}, []) : sizeMapping;
|
|
80
|
+
}
|
|
81
|
+
function buildSizeMappingFromSizes(sizes, viewports) {
|
|
82
|
+
return getSortedViewports(viewports).map(_ref2 => {
|
|
83
|
+
let {
|
|
84
|
+
name,
|
|
85
|
+
size: viewPortSize
|
|
86
|
+
} = _ref2;
|
|
87
|
+
return [viewPortSize, sizes.filter(size => sizeFitsInViewport(size, name === 'default' ? [300, 300] : viewPortSize))];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function getSizeMappingFromSlot(_ref3, viewports) {
|
|
82
91
|
let {
|
|
83
92
|
size: allSizes = [],
|
|
84
93
|
sizeMapping = null
|
|
@@ -87,7 +96,7 @@ const getSizeMappingFromSlot = (_ref3, viewports) => {
|
|
|
87
96
|
return buildSizeMappingFromSizes(allSizes, viewports);
|
|
88
97
|
}
|
|
89
98
|
return sizeMapping !== null ? buildSizeMappingFromViewports(sizeMapping, viewports) : null;
|
|
90
|
-
}
|
|
99
|
+
}
|
|
91
100
|
function getSizeFromSizeMapping(sizeMapping) {
|
|
92
101
|
if (sizeMapping === null) {
|
|
93
102
|
return null;
|
|
@@ -683,65 +692,26 @@ const AdsContext = /*#__PURE__*/React.createContext({
|
|
|
683
692
|
ready: false
|
|
684
693
|
});
|
|
685
694
|
const useAdsContext = () => React.useContext(AdsContext);
|
|
686
|
-
const propTypes$3 = {
|
|
687
|
-
children: PropTypes.node.isRequired,
|
|
688
|
-
defaultSlotPath: PropTypes.string,
|
|
689
|
-
slotsPath: PropTypes.objectOf(PropTypes.string),
|
|
690
|
-
disableSingleRequest: PropTypes.bool,
|
|
691
|
-
disableVideoAds: PropTypes.bool,
|
|
692
|
-
disableLazyLoad: PropTypes.bool,
|
|
693
|
-
autoInit: PropTypes.bool,
|
|
694
|
-
resizeDebounceDelay: PropTypes.number,
|
|
695
|
-
refreshOnResize: PropTypes.bool,
|
|
696
|
-
mobileScaling: PropTypes.number,
|
|
697
|
-
renderMarginPercent: PropTypes.number,
|
|
698
|
-
fetchMarginPercent: PropTypes.number,
|
|
699
|
-
viewport: PropTypes.string,
|
|
700
|
-
slots: adSlots,
|
|
701
|
-
viewports: adViewports,
|
|
702
|
-
richAdComponents: PropTypes.objectOf(PropTypes.elementType),
|
|
703
|
-
disabled: PropTypes.bool,
|
|
704
|
-
disableTracking: PropTypes.bool
|
|
705
|
-
};
|
|
706
|
-
const defaultProps$2 = {
|
|
707
|
-
defaultSlotPath: null,
|
|
708
|
-
slotsPath: null,
|
|
709
|
-
disableSingleRequest: false,
|
|
710
|
-
disableVideoAds: false,
|
|
711
|
-
disableLazyLoad: false,
|
|
712
|
-
autoInit: true,
|
|
713
|
-
resizeDebounceDelay: 500,
|
|
714
|
-
refreshOnResize: false,
|
|
715
|
-
mobileScaling: 1.0,
|
|
716
|
-
renderMarginPercent: 100,
|
|
717
|
-
fetchMarginPercent: 300,
|
|
718
|
-
viewport: null,
|
|
719
|
-
slots: slots,
|
|
720
|
-
viewports: viewports,
|
|
721
|
-
richAdComponents: null,
|
|
722
|
-
disabled: false,
|
|
723
|
-
disableTracking: false
|
|
724
|
-
};
|
|
725
695
|
function AdsProvider(_ref) {
|
|
726
696
|
let {
|
|
727
697
|
children,
|
|
728
|
-
defaultSlotPath,
|
|
729
|
-
slotsPath,
|
|
730
|
-
disableSingleRequest,
|
|
731
|
-
disableVideoAds,
|
|
732
|
-
disableLazyLoad,
|
|
733
|
-
autoInit,
|
|
734
|
-
resizeDebounceDelay,
|
|
735
|
-
refreshOnResize,
|
|
736
|
-
mobileScaling,
|
|
737
|
-
renderMarginPercent,
|
|
738
|
-
fetchMarginPercent,
|
|
739
|
-
viewport,
|
|
740
|
-
viewports,
|
|
741
|
-
slots,
|
|
742
|
-
richAdComponents,
|
|
743
|
-
disabled,
|
|
744
|
-
disableTracking
|
|
698
|
+
defaultSlotPath = null,
|
|
699
|
+
slotsPath = null,
|
|
700
|
+
disableSingleRequest = false,
|
|
701
|
+
disableVideoAds = false,
|
|
702
|
+
disableLazyLoad = false,
|
|
703
|
+
autoInit = true,
|
|
704
|
+
resizeDebounceDelay = 500,
|
|
705
|
+
refreshOnResize = false,
|
|
706
|
+
mobileScaling = 1.0,
|
|
707
|
+
renderMarginPercent = 100,
|
|
708
|
+
fetchMarginPercent = 300,
|
|
709
|
+
viewport = null,
|
|
710
|
+
viewports: viewports$1 = viewports,
|
|
711
|
+
slots: slots$1 = slots,
|
|
712
|
+
richAdComponents = null,
|
|
713
|
+
disabled = false,
|
|
714
|
+
disableTracking = false
|
|
745
715
|
} = _ref;
|
|
746
716
|
const [ready, setReady] = React.useState(false);
|
|
747
717
|
const adsRef = React.useRef(null);
|
|
@@ -793,12 +763,12 @@ function AdsProvider(_ref) {
|
|
|
793
763
|
onResize.cancel();
|
|
794
764
|
};
|
|
795
765
|
}, [ads, resizeDebounceDelay, refreshOnResize]);
|
|
796
|
-
const slotsWithSizeMapping = React.useMemo(() => Object.keys(slots || {}).reduce((map, key) => {
|
|
797
|
-
const slot = slots[key];
|
|
766
|
+
const slotsWithSizeMapping = React.useMemo(() => Object.keys(slots$1 || {}).reduce((map, key) => {
|
|
767
|
+
const slot = slots$1[key];
|
|
798
768
|
const {
|
|
799
769
|
size
|
|
800
770
|
} = slot;
|
|
801
|
-
const sizeMapping = getSizeMappingFromSlot(slot, viewports);
|
|
771
|
+
const sizeMapping = getSizeMappingFromSlot(slot, viewports$1);
|
|
802
772
|
return {
|
|
803
773
|
...map,
|
|
804
774
|
[key]: {
|
|
@@ -807,50 +777,44 @@ function AdsProvider(_ref) {
|
|
|
807
777
|
sizeMapping
|
|
808
778
|
}
|
|
809
779
|
};
|
|
810
|
-
}, {}), []);
|
|
811
|
-
const finalSlotsPath = React.useMemo(() =>
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
780
|
+
}, {}), [slots$1, viewports$1]);
|
|
781
|
+
const finalSlotsPath = React.useMemo(() => {
|
|
782
|
+
if (defaultSlotPath !== null && slotsPath) {
|
|
783
|
+
return {
|
|
784
|
+
default: defaultSlotPath,
|
|
785
|
+
...slotsPath
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
return slotsPath ? {
|
|
789
|
+
...slotsPath
|
|
790
|
+
} : {};
|
|
816
791
|
}, [defaultSlotPath, slotsPath]);
|
|
817
792
|
const value = React.useMemo(() => ({
|
|
818
793
|
ready,
|
|
819
794
|
ads,
|
|
820
|
-
viewports,
|
|
795
|
+
viewports: viewports$1,
|
|
821
796
|
viewport,
|
|
822
797
|
slots: slotsWithSizeMapping,
|
|
823
798
|
slotsPath: finalSlotsPath,
|
|
824
799
|
trackingDisabled: disableTracking,
|
|
825
800
|
richAdComponents
|
|
826
|
-
}), [ready, ads, viewports, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
801
|
+
}), [ready, ads, viewports$1, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
827
802
|
return /*#__PURE__*/jsxRuntime.jsx(AdsContext.Provider, {
|
|
828
803
|
value: value,
|
|
829
804
|
children: children
|
|
830
805
|
});
|
|
831
806
|
}
|
|
832
|
-
AdsProvider.propTypes = propTypes$3;
|
|
833
|
-
AdsProvider.defaultProps = defaultProps$2;
|
|
834
807
|
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
const propTypes$2 = {
|
|
838
|
-
children: PropTypes.node.isRequired,
|
|
839
|
-
// eslint-disable-next-line react/forbid-prop-types
|
|
840
|
-
targeting: PropTypes.object,
|
|
841
|
-
replace: PropTypes.bool
|
|
842
|
-
};
|
|
843
|
-
const defaultProps$1 = {
|
|
844
|
-
targeting: {
|
|
845
|
-
domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
|
|
846
|
-
},
|
|
847
|
-
replace: false
|
|
808
|
+
const defaultTargeting = {
|
|
809
|
+
domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
|
|
848
810
|
};
|
|
811
|
+
const AdsTargetingContext = /*#__PURE__*/React.createContext(defaultTargeting);
|
|
812
|
+
const useAdsTargeting = () => React.useContext(AdsTargetingContext);
|
|
849
813
|
function AdsTargetingProvider(_ref) {
|
|
850
814
|
let {
|
|
851
815
|
children,
|
|
852
|
-
targeting,
|
|
853
|
-
replace
|
|
816
|
+
targeting = defaultTargeting,
|
|
817
|
+
replace = false
|
|
854
818
|
} = _ref;
|
|
855
819
|
const previousTargeting = useAdsTargeting();
|
|
856
820
|
const mergedTargeting = React.useMemo(() => replace ? targeting : {
|
|
@@ -862,16 +826,8 @@ function AdsTargetingProvider(_ref) {
|
|
|
862
826
|
children: children
|
|
863
827
|
});
|
|
864
828
|
}
|
|
865
|
-
AdsTargetingProvider.propTypes = propTypes$2;
|
|
866
|
-
AdsTargetingProvider.defaultProps = defaultProps$1;
|
|
867
829
|
|
|
868
830
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
869
|
-
const propTypes$1 = {
|
|
870
|
-
richAd: PropTypes.shape({
|
|
871
|
-
type: PropTypes.string.isRequired
|
|
872
|
-
}).isRequired
|
|
873
|
-
};
|
|
874
|
-
const defaultProps = {};
|
|
875
831
|
function RichAd(_ref) {
|
|
876
832
|
let {
|
|
877
833
|
richAd,
|
|
@@ -890,12 +846,12 @@ function RichAd(_ref) {
|
|
|
890
846
|
...richAdProps
|
|
891
847
|
}) : null;
|
|
892
848
|
}
|
|
893
|
-
RichAd.propTypes = propTypes$1;
|
|
894
|
-
RichAd.defaultProps = defaultProps;
|
|
895
849
|
|
|
896
850
|
function useAdsTracking() {
|
|
897
851
|
const tracking$1 = tracking.useTracking() || null;
|
|
898
|
-
const trackEvent = React.useCallback((action
|
|
852
|
+
const trackEvent = React.useCallback(function (action) {
|
|
853
|
+
let slot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
854
|
+
let renderEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
899
855
|
if (tracking$1 !== null && typeof tracking$1.trackAd !== 'undefined') {
|
|
900
856
|
tracking$1.trackAd(action, slot, renderEvent);
|
|
901
857
|
}
|
|
@@ -925,9 +881,11 @@ function useAd(path, size) {
|
|
|
925
881
|
trackingDisabled: globalTrackingDisabled = false
|
|
926
882
|
} = useAdsContext();
|
|
927
883
|
const trackAd = useAdsTracking();
|
|
928
|
-
const track = React.useCallback(function () {
|
|
884
|
+
const track = React.useCallback(function (action) {
|
|
885
|
+
let slot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
886
|
+
let renderEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
929
887
|
if (!disableTracking && !globalTrackingDisabled) {
|
|
930
|
-
trackAd(
|
|
888
|
+
trackAd(action, slot, renderEvent);
|
|
931
889
|
}
|
|
932
890
|
}, [disableTracking, globalTrackingDisabled, trackAd]);
|
|
933
891
|
|
|
@@ -1115,7 +1073,8 @@ function parseRichAd(data) {
|
|
|
1115
1073
|
} catch (e) {}
|
|
1116
1074
|
return richAd;
|
|
1117
1075
|
}
|
|
1118
|
-
function useRichAd(containerRef, id
|
|
1076
|
+
function useRichAd(containerRef, id) {
|
|
1077
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1119
1078
|
const [richAd, setRichAd] = React.useState(null);
|
|
1120
1079
|
const {
|
|
1121
1080
|
onRichAd = null
|
|
@@ -1153,34 +1112,9 @@ function useRichAd(containerRef, id, opts) {
|
|
|
1153
1112
|
}
|
|
1154
1113
|
|
|
1155
1114
|
/* eslint-disable react/require-default-props */
|
|
1156
|
-
const propTypes = {
|
|
1157
|
-
slot: PropTypes.string.isRequired,
|
|
1158
|
-
path: adPath,
|
|
1159
|
-
size: adSize,
|
|
1160
|
-
sizeMapping: adSizeMapping,
|
|
1161
|
-
viewport: PropTypes.string,
|
|
1162
|
-
targeting: adTargeting,
|
|
1163
|
-
refreshInterval: PropTypes.number,
|
|
1164
|
-
alwaysRender: PropTypes.bool,
|
|
1165
|
-
disabled: PropTypes.bool,
|
|
1166
|
-
disableTracking: PropTypes.bool,
|
|
1167
|
-
shouldKeepSize: PropTypes.bool,
|
|
1168
|
-
withoutStyle: PropTypes.bool,
|
|
1169
|
-
withoutMinimumSize: PropTypes.bool,
|
|
1170
|
-
withReactId: PropTypes.bool,
|
|
1171
|
-
className: PropTypes.string,
|
|
1172
|
-
emptyClassName: PropTypes.string,
|
|
1173
|
-
adClassName: PropTypes.string,
|
|
1174
|
-
richAdClassName: PropTypes.string,
|
|
1175
|
-
richAdIframeClassName: PropTypes.string,
|
|
1176
|
-
onRender: PropTypes.func,
|
|
1177
|
-
onDestroy: PropTypes.func,
|
|
1178
|
-
onRichAd: PropTypes.func,
|
|
1179
|
-
slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
|
1180
|
-
};
|
|
1181
1115
|
function Ad(_ref) {
|
|
1182
1116
|
let {
|
|
1183
|
-
slot: slotName
|
|
1117
|
+
slot: slotName,
|
|
1184
1118
|
path: providedPath = null,
|
|
1185
1119
|
size: providedSize = null,
|
|
1186
1120
|
sizeMapping: providedSizeMapping = null,
|
|
@@ -1213,7 +1147,7 @@ function Ad(_ref) {
|
|
|
1213
1147
|
const {
|
|
1214
1148
|
default: defaultSlotPath = null
|
|
1215
1149
|
} = slotsPath || {};
|
|
1216
|
-
const slot = slotName
|
|
1150
|
+
const slot = slotName && slots !== null ? slots[slotName] || null : null;
|
|
1217
1151
|
const {
|
|
1218
1152
|
sizeMapping: slotSizeMapping = null,
|
|
1219
1153
|
size: slotSize = null,
|
|
@@ -1312,9 +1246,9 @@ function Ad(_ref) {
|
|
|
1312
1246
|
const richAd = useRichAd(adContainerRef, id, {
|
|
1313
1247
|
onRichAd
|
|
1314
1248
|
});
|
|
1315
|
-
if (slotRef !== null &&
|
|
1249
|
+
if (slotRef !== null && typeof slotRef === 'function') {
|
|
1316
1250
|
slotRef(slotObject);
|
|
1317
|
-
} else if (slotRef !== null &&
|
|
1251
|
+
} else if (slotRef !== null && typeof slotRef === 'object') {
|
|
1318
1252
|
// eslint-disable-next-line no-param-reassign
|
|
1319
1253
|
slotRef.current = slotObject;
|
|
1320
1254
|
}
|
|
@@ -1376,14 +1310,13 @@ function Ad(_ref) {
|
|
|
1376
1310
|
})
|
|
1377
1311
|
});
|
|
1378
1312
|
}
|
|
1379
|
-
Ad.propTypes = propTypes;
|
|
1380
1313
|
|
|
1381
1314
|
exports.Ad = Ad;
|
|
1382
1315
|
exports.AdSlot = AdSlot;
|
|
1383
1316
|
exports.AdsManager = AdsManager;
|
|
1384
1317
|
exports.AdsProvider = AdsProvider;
|
|
1385
1318
|
exports.AdsTargetingProvider = AdsTargetingProvider;
|
|
1386
|
-
exports.PropTypes = propTypes
|
|
1319
|
+
exports.PropTypes = propTypes;
|
|
1387
1320
|
exports.RichAd = RichAd;
|
|
1388
1321
|
exports.buildSizeMappingFromSizes = buildSizeMappingFromSizes;
|
|
1389
1322
|
exports.buildSizeMappingFromViewports = buildSizeMappingFromViewports;
|
package/dist/es.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import
|
|
4
|
-
import isObject from 'lodash/isObject';
|
|
5
|
-
import React, { useContext, useState, useRef, useMemo, useEffect, useCallback, useId } from 'react';
|
|
3
|
+
import React, { useContext, useState, useRef, useMemo, useEffect, createContext, useCallback, useId } from 'react';
|
|
6
4
|
import isArray from 'lodash/isArray';
|
|
5
|
+
import isObject from 'lodash/isObject';
|
|
7
6
|
import sortBy from 'lodash/sortBy';
|
|
8
7
|
import uniqBy from 'lodash/uniqBy';
|
|
9
8
|
import debounce from 'lodash/debounce';
|
|
@@ -27,7 +26,7 @@ const adTargeting = PropTypes.shape({
|
|
|
27
26
|
domain: PropTypes.string
|
|
28
27
|
});
|
|
29
28
|
|
|
30
|
-
var propTypes
|
|
29
|
+
var propTypes = /*#__PURE__*/Object.freeze({
|
|
31
30
|
__proto__: null,
|
|
32
31
|
adPath: adPath,
|
|
33
32
|
adSize: adSize,
|
|
@@ -50,33 +49,43 @@ function normalizeAdSizes(size) {
|
|
|
50
49
|
function getAdSizes(sizes) {
|
|
51
50
|
return uniqBy(sizes, size => isArray(size) ? size.join('x') : size);
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
size
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
name,
|
|
68
|
-
size: viewPortSize
|
|
69
|
-
} = _ref;
|
|
70
|
-
return typeof sizeMapping[name] !== 'undefined' ? [...newSizeMapping, [viewPortSize, sizeMapping[name]]] : newSizeMapping;
|
|
71
|
-
}, []) : sizeMapping;
|
|
72
|
-
const buildSizeMappingFromSizes = (sizes, viewports) => getSortedViewports(viewports).map(_ref2 => {
|
|
73
|
-
let {
|
|
52
|
+
function getMinimumAdSize(sizes) {
|
|
53
|
+
return getAdSizes(sizes).filter(size => size !== 'fluid').reduce((minimumSize, size) => ({
|
|
54
|
+
width: Math.min(minimumSize.width, size[0]),
|
|
55
|
+
height: Math.min(minimumSize.height, size[1])
|
|
56
|
+
}), {
|
|
57
|
+
width: Infinity,
|
|
58
|
+
height: Infinity
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function sizeFitsInViewport(size, viewport) {
|
|
62
|
+
return size === 'fluid' && viewport[0] > 600 || size !== 'fluid' && (viewport[0] === 0 || size[0] <= viewport[0]) && (viewport[1] === 0 || size[1] <= viewport[1]);
|
|
63
|
+
}
|
|
64
|
+
function getSortedViewports(viewports) {
|
|
65
|
+
return sortBy(Object.keys(viewports).map(name => ({
|
|
74
66
|
name,
|
|
75
|
-
size:
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
size: viewports[name]
|
|
68
|
+
})), [viewport => viewport.size[0]]).reverse();
|
|
69
|
+
}
|
|
70
|
+
function buildSizeMappingFromViewports(sizeMapping, viewports) {
|
|
71
|
+
return isObject(sizeMapping) && !isArray(sizeMapping) ? getSortedViewports(viewports).reduce((newSizeMapping, _ref) => {
|
|
72
|
+
let {
|
|
73
|
+
name,
|
|
74
|
+
size: viewPortSize
|
|
75
|
+
} = _ref;
|
|
76
|
+
return typeof sizeMapping[name] !== 'undefined' ? [...newSizeMapping, [viewPortSize, sizeMapping[name]]] : newSizeMapping;
|
|
77
|
+
}, []) : sizeMapping;
|
|
78
|
+
}
|
|
79
|
+
function buildSizeMappingFromSizes(sizes, viewports) {
|
|
80
|
+
return getSortedViewports(viewports).map(_ref2 => {
|
|
81
|
+
let {
|
|
82
|
+
name,
|
|
83
|
+
size: viewPortSize
|
|
84
|
+
} = _ref2;
|
|
85
|
+
return [viewPortSize, sizes.filter(size => sizeFitsInViewport(size, name === 'default' ? [300, 300] : viewPortSize))];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function getSizeMappingFromSlot(_ref3, viewports) {
|
|
80
89
|
let {
|
|
81
90
|
size: allSizes = [],
|
|
82
91
|
sizeMapping = null
|
|
@@ -85,7 +94,7 @@ const getSizeMappingFromSlot = (_ref3, viewports) => {
|
|
|
85
94
|
return buildSizeMappingFromSizes(allSizes, viewports);
|
|
86
95
|
}
|
|
87
96
|
return sizeMapping !== null ? buildSizeMappingFromViewports(sizeMapping, viewports) : null;
|
|
88
|
-
}
|
|
97
|
+
}
|
|
89
98
|
function getSizeFromSizeMapping(sizeMapping) {
|
|
90
99
|
if (sizeMapping === null) {
|
|
91
100
|
return null;
|
|
@@ -681,65 +690,26 @@ const AdsContext = /*#__PURE__*/React.createContext({
|
|
|
681
690
|
ready: false
|
|
682
691
|
});
|
|
683
692
|
const useAdsContext = () => useContext(AdsContext);
|
|
684
|
-
const propTypes$3 = {
|
|
685
|
-
children: PropTypes.node.isRequired,
|
|
686
|
-
defaultSlotPath: PropTypes.string,
|
|
687
|
-
slotsPath: PropTypes.objectOf(PropTypes.string),
|
|
688
|
-
disableSingleRequest: PropTypes.bool,
|
|
689
|
-
disableVideoAds: PropTypes.bool,
|
|
690
|
-
disableLazyLoad: PropTypes.bool,
|
|
691
|
-
autoInit: PropTypes.bool,
|
|
692
|
-
resizeDebounceDelay: PropTypes.number,
|
|
693
|
-
refreshOnResize: PropTypes.bool,
|
|
694
|
-
mobileScaling: PropTypes.number,
|
|
695
|
-
renderMarginPercent: PropTypes.number,
|
|
696
|
-
fetchMarginPercent: PropTypes.number,
|
|
697
|
-
viewport: PropTypes.string,
|
|
698
|
-
slots: adSlots,
|
|
699
|
-
viewports: adViewports,
|
|
700
|
-
richAdComponents: PropTypes.objectOf(PropTypes.elementType),
|
|
701
|
-
disabled: PropTypes.bool,
|
|
702
|
-
disableTracking: PropTypes.bool
|
|
703
|
-
};
|
|
704
|
-
const defaultProps$2 = {
|
|
705
|
-
defaultSlotPath: null,
|
|
706
|
-
slotsPath: null,
|
|
707
|
-
disableSingleRequest: false,
|
|
708
|
-
disableVideoAds: false,
|
|
709
|
-
disableLazyLoad: false,
|
|
710
|
-
autoInit: true,
|
|
711
|
-
resizeDebounceDelay: 500,
|
|
712
|
-
refreshOnResize: false,
|
|
713
|
-
mobileScaling: 1.0,
|
|
714
|
-
renderMarginPercent: 100,
|
|
715
|
-
fetchMarginPercent: 300,
|
|
716
|
-
viewport: null,
|
|
717
|
-
slots: slots,
|
|
718
|
-
viewports: viewports,
|
|
719
|
-
richAdComponents: null,
|
|
720
|
-
disabled: false,
|
|
721
|
-
disableTracking: false
|
|
722
|
-
};
|
|
723
693
|
function AdsProvider(_ref) {
|
|
724
694
|
let {
|
|
725
695
|
children,
|
|
726
|
-
defaultSlotPath,
|
|
727
|
-
slotsPath,
|
|
728
|
-
disableSingleRequest,
|
|
729
|
-
disableVideoAds,
|
|
730
|
-
disableLazyLoad,
|
|
731
|
-
autoInit,
|
|
732
|
-
resizeDebounceDelay,
|
|
733
|
-
refreshOnResize,
|
|
734
|
-
mobileScaling,
|
|
735
|
-
renderMarginPercent,
|
|
736
|
-
fetchMarginPercent,
|
|
737
|
-
viewport,
|
|
738
|
-
viewports,
|
|
739
|
-
slots,
|
|
740
|
-
richAdComponents,
|
|
741
|
-
disabled,
|
|
742
|
-
disableTracking
|
|
696
|
+
defaultSlotPath = null,
|
|
697
|
+
slotsPath = null,
|
|
698
|
+
disableSingleRequest = false,
|
|
699
|
+
disableVideoAds = false,
|
|
700
|
+
disableLazyLoad = false,
|
|
701
|
+
autoInit = true,
|
|
702
|
+
resizeDebounceDelay = 500,
|
|
703
|
+
refreshOnResize = false,
|
|
704
|
+
mobileScaling = 1.0,
|
|
705
|
+
renderMarginPercent = 100,
|
|
706
|
+
fetchMarginPercent = 300,
|
|
707
|
+
viewport = null,
|
|
708
|
+
viewports: viewports$1 = viewports,
|
|
709
|
+
slots: slots$1 = slots,
|
|
710
|
+
richAdComponents = null,
|
|
711
|
+
disabled = false,
|
|
712
|
+
disableTracking = false
|
|
743
713
|
} = _ref;
|
|
744
714
|
const [ready, setReady] = useState(false);
|
|
745
715
|
const adsRef = useRef(null);
|
|
@@ -791,12 +761,12 @@ function AdsProvider(_ref) {
|
|
|
791
761
|
onResize.cancel();
|
|
792
762
|
};
|
|
793
763
|
}, [ads, resizeDebounceDelay, refreshOnResize]);
|
|
794
|
-
const slotsWithSizeMapping = useMemo(() => Object.keys(slots || {}).reduce((map, key) => {
|
|
795
|
-
const slot = slots[key];
|
|
764
|
+
const slotsWithSizeMapping = useMemo(() => Object.keys(slots$1 || {}).reduce((map, key) => {
|
|
765
|
+
const slot = slots$1[key];
|
|
796
766
|
const {
|
|
797
767
|
size
|
|
798
768
|
} = slot;
|
|
799
|
-
const sizeMapping = getSizeMappingFromSlot(slot, viewports);
|
|
769
|
+
const sizeMapping = getSizeMappingFromSlot(slot, viewports$1);
|
|
800
770
|
return {
|
|
801
771
|
...map,
|
|
802
772
|
[key]: {
|
|
@@ -805,50 +775,44 @@ function AdsProvider(_ref) {
|
|
|
805
775
|
sizeMapping
|
|
806
776
|
}
|
|
807
777
|
};
|
|
808
|
-
}, {}), []);
|
|
809
|
-
const finalSlotsPath = useMemo(() =>
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
778
|
+
}, {}), [slots$1, viewports$1]);
|
|
779
|
+
const finalSlotsPath = useMemo(() => {
|
|
780
|
+
if (defaultSlotPath !== null && slotsPath) {
|
|
781
|
+
return {
|
|
782
|
+
default: defaultSlotPath,
|
|
783
|
+
...slotsPath
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
return slotsPath ? {
|
|
787
|
+
...slotsPath
|
|
788
|
+
} : {};
|
|
814
789
|
}, [defaultSlotPath, slotsPath]);
|
|
815
790
|
const value = useMemo(() => ({
|
|
816
791
|
ready,
|
|
817
792
|
ads,
|
|
818
|
-
viewports,
|
|
793
|
+
viewports: viewports$1,
|
|
819
794
|
viewport,
|
|
820
795
|
slots: slotsWithSizeMapping,
|
|
821
796
|
slotsPath: finalSlotsPath,
|
|
822
797
|
trackingDisabled: disableTracking,
|
|
823
798
|
richAdComponents
|
|
824
|
-
}), [ready, ads, viewports, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
799
|
+
}), [ready, ads, viewports$1, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
|
|
825
800
|
return /*#__PURE__*/jsx(AdsContext.Provider, {
|
|
826
801
|
value: value,
|
|
827
802
|
children: children
|
|
828
803
|
});
|
|
829
804
|
}
|
|
830
|
-
AdsProvider.propTypes = propTypes$3;
|
|
831
|
-
AdsProvider.defaultProps = defaultProps$2;
|
|
832
805
|
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
const propTypes$2 = {
|
|
836
|
-
children: PropTypes.node.isRequired,
|
|
837
|
-
// eslint-disable-next-line react/forbid-prop-types
|
|
838
|
-
targeting: PropTypes.object,
|
|
839
|
-
replace: PropTypes.bool
|
|
840
|
-
};
|
|
841
|
-
const defaultProps$1 = {
|
|
842
|
-
targeting: {
|
|
843
|
-
domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
|
|
844
|
-
},
|
|
845
|
-
replace: false
|
|
806
|
+
const defaultTargeting = {
|
|
807
|
+
domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
|
|
846
808
|
};
|
|
809
|
+
const AdsTargetingContext = /*#__PURE__*/createContext(defaultTargeting);
|
|
810
|
+
const useAdsTargeting = () => useContext(AdsTargetingContext);
|
|
847
811
|
function AdsTargetingProvider(_ref) {
|
|
848
812
|
let {
|
|
849
813
|
children,
|
|
850
|
-
targeting,
|
|
851
|
-
replace
|
|
814
|
+
targeting = defaultTargeting,
|
|
815
|
+
replace = false
|
|
852
816
|
} = _ref;
|
|
853
817
|
const previousTargeting = useAdsTargeting();
|
|
854
818
|
const mergedTargeting = useMemo(() => replace ? targeting : {
|
|
@@ -860,16 +824,8 @@ function AdsTargetingProvider(_ref) {
|
|
|
860
824
|
children: children
|
|
861
825
|
});
|
|
862
826
|
}
|
|
863
|
-
AdsTargetingProvider.propTypes = propTypes$2;
|
|
864
|
-
AdsTargetingProvider.defaultProps = defaultProps$1;
|
|
865
827
|
|
|
866
828
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
867
|
-
const propTypes$1 = {
|
|
868
|
-
richAd: PropTypes.shape({
|
|
869
|
-
type: PropTypes.string.isRequired
|
|
870
|
-
}).isRequired
|
|
871
|
-
};
|
|
872
|
-
const defaultProps = {};
|
|
873
829
|
function RichAd(_ref) {
|
|
874
830
|
let {
|
|
875
831
|
richAd,
|
|
@@ -888,12 +844,12 @@ function RichAd(_ref) {
|
|
|
888
844
|
...richAdProps
|
|
889
845
|
}) : null;
|
|
890
846
|
}
|
|
891
|
-
RichAd.propTypes = propTypes$1;
|
|
892
|
-
RichAd.defaultProps = defaultProps;
|
|
893
847
|
|
|
894
848
|
function useAdsTracking() {
|
|
895
849
|
const tracking = useTracking() || null;
|
|
896
|
-
const trackEvent = useCallback((action
|
|
850
|
+
const trackEvent = useCallback(function (action) {
|
|
851
|
+
let slot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
852
|
+
let renderEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
897
853
|
if (tracking !== null && typeof tracking.trackAd !== 'undefined') {
|
|
898
854
|
tracking.trackAd(action, slot, renderEvent);
|
|
899
855
|
}
|
|
@@ -923,9 +879,11 @@ function useAd(path, size) {
|
|
|
923
879
|
trackingDisabled: globalTrackingDisabled = false
|
|
924
880
|
} = useAdsContext();
|
|
925
881
|
const trackAd = useAdsTracking();
|
|
926
|
-
const track = useCallback(function () {
|
|
882
|
+
const track = useCallback(function (action) {
|
|
883
|
+
let slot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
884
|
+
let renderEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
927
885
|
if (!disableTracking && !globalTrackingDisabled) {
|
|
928
|
-
trackAd(
|
|
886
|
+
trackAd(action, slot, renderEvent);
|
|
929
887
|
}
|
|
930
888
|
}, [disableTracking, globalTrackingDisabled, trackAd]);
|
|
931
889
|
|
|
@@ -1113,7 +1071,8 @@ function parseRichAd(data) {
|
|
|
1113
1071
|
} catch (e) {}
|
|
1114
1072
|
return richAd;
|
|
1115
1073
|
}
|
|
1116
|
-
function useRichAd(containerRef, id
|
|
1074
|
+
function useRichAd(containerRef, id) {
|
|
1075
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1117
1076
|
const [richAd, setRichAd] = useState(null);
|
|
1118
1077
|
const {
|
|
1119
1078
|
onRichAd = null
|
|
@@ -1151,34 +1110,9 @@ function useRichAd(containerRef, id, opts) {
|
|
|
1151
1110
|
}
|
|
1152
1111
|
|
|
1153
1112
|
/* eslint-disable react/require-default-props */
|
|
1154
|
-
const propTypes = {
|
|
1155
|
-
slot: PropTypes.string.isRequired,
|
|
1156
|
-
path: adPath,
|
|
1157
|
-
size: adSize,
|
|
1158
|
-
sizeMapping: adSizeMapping,
|
|
1159
|
-
viewport: PropTypes.string,
|
|
1160
|
-
targeting: adTargeting,
|
|
1161
|
-
refreshInterval: PropTypes.number,
|
|
1162
|
-
alwaysRender: PropTypes.bool,
|
|
1163
|
-
disabled: PropTypes.bool,
|
|
1164
|
-
disableTracking: PropTypes.bool,
|
|
1165
|
-
shouldKeepSize: PropTypes.bool,
|
|
1166
|
-
withoutStyle: PropTypes.bool,
|
|
1167
|
-
withoutMinimumSize: PropTypes.bool,
|
|
1168
|
-
withReactId: PropTypes.bool,
|
|
1169
|
-
className: PropTypes.string,
|
|
1170
|
-
emptyClassName: PropTypes.string,
|
|
1171
|
-
adClassName: PropTypes.string,
|
|
1172
|
-
richAdClassName: PropTypes.string,
|
|
1173
|
-
richAdIframeClassName: PropTypes.string,
|
|
1174
|
-
onRender: PropTypes.func,
|
|
1175
|
-
onDestroy: PropTypes.func,
|
|
1176
|
-
onRichAd: PropTypes.func,
|
|
1177
|
-
slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
|
1178
|
-
};
|
|
1179
1113
|
function Ad(_ref) {
|
|
1180
1114
|
let {
|
|
1181
|
-
slot: slotName
|
|
1115
|
+
slot: slotName,
|
|
1182
1116
|
path: providedPath = null,
|
|
1183
1117
|
size: providedSize = null,
|
|
1184
1118
|
sizeMapping: providedSizeMapping = null,
|
|
@@ -1211,7 +1145,7 @@ function Ad(_ref) {
|
|
|
1211
1145
|
const {
|
|
1212
1146
|
default: defaultSlotPath = null
|
|
1213
1147
|
} = slotsPath || {};
|
|
1214
|
-
const slot = slotName
|
|
1148
|
+
const slot = slotName && slots !== null ? slots[slotName] || null : null;
|
|
1215
1149
|
const {
|
|
1216
1150
|
sizeMapping: slotSizeMapping = null,
|
|
1217
1151
|
size: slotSize = null,
|
|
@@ -1310,9 +1244,9 @@ function Ad(_ref) {
|
|
|
1310
1244
|
const richAd = useRichAd(adContainerRef, id, {
|
|
1311
1245
|
onRichAd
|
|
1312
1246
|
});
|
|
1313
|
-
if (slotRef !== null &&
|
|
1247
|
+
if (slotRef !== null && typeof slotRef === 'function') {
|
|
1314
1248
|
slotRef(slotObject);
|
|
1315
|
-
} else if (slotRef !== null &&
|
|
1249
|
+
} else if (slotRef !== null && typeof slotRef === 'object') {
|
|
1316
1250
|
// eslint-disable-next-line no-param-reassign
|
|
1317
1251
|
slotRef.current = slotObject;
|
|
1318
1252
|
}
|
|
@@ -1374,6 +1308,5 @@ function Ad(_ref) {
|
|
|
1374
1308
|
})
|
|
1375
1309
|
});
|
|
1376
1310
|
}
|
|
1377
|
-
Ad.propTypes = propTypes;
|
|
1378
1311
|
|
|
1379
|
-
export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes
|
|
1312
|
+
export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes as PropTypes, RichAd, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeFromSizeMapping, getSizeMappingFromSlot, getSortedViewports, normalizeAdSizes, 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.110",
|
|
4
4
|
"description": "Ads library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -29,12 +29,15 @@
|
|
|
29
29
|
],
|
|
30
30
|
"main": "dist/cjs.js",
|
|
31
31
|
"module": "dist/es.js",
|
|
32
|
+
"types": "types/index.d.ts",
|
|
32
33
|
"files": [
|
|
33
|
-
"dist"
|
|
34
|
+
"dist",
|
|
35
|
+
"types"
|
|
34
36
|
],
|
|
35
37
|
"scripts": {
|
|
36
|
-
"clean": "rm -rf dist",
|
|
37
|
-
"build": "
|
|
38
|
+
"clean": "rm -rf dist && rm -rf types",
|
|
39
|
+
"build:types": "tsc --p tsconfig.json",
|
|
40
|
+
"build": "npm run build:types && rollup --bundleConfigAsCjs --config ../../rollup.config.js",
|
|
38
41
|
"prepare": "npm run clean && npm run build"
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
@@ -50,7 +53,7 @@
|
|
|
50
53
|
"publishConfig": {
|
|
51
54
|
"access": "public"
|
|
52
55
|
},
|
|
53
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "94ad547d193769ed8f6a056adee68f1b2b5c8120",
|
|
54
57
|
"dependencies": {
|
|
55
58
|
"@folklore/hooks": "^0.0.73",
|
|
56
59
|
"@folklore/tracking": "^0.0.29",
|
package/types/Ad.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { AdSize, AdSizeMapping, AdsTargeting } from './types';
|
|
3
|
+
import AdSlot from './AdSlot';
|
|
4
|
+
export interface AdProps {
|
|
5
|
+
slot: string;
|
|
6
|
+
path?: string | null;
|
|
7
|
+
size?: AdSize[] | null;
|
|
8
|
+
sizeMapping?: AdSizeMapping[] | null;
|
|
9
|
+
viewport?: string | null;
|
|
10
|
+
targeting?: AdsTargeting | null;
|
|
11
|
+
refreshInterval?: number | null;
|
|
12
|
+
alwaysRender?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
disableTracking?: boolean;
|
|
15
|
+
shouldKeepSize?: boolean;
|
|
16
|
+
withoutStyle?: boolean;
|
|
17
|
+
withoutMinimumSize?: boolean;
|
|
18
|
+
withReactId?: boolean;
|
|
19
|
+
className?: string | null;
|
|
20
|
+
emptyClassName?: string | null;
|
|
21
|
+
adClassName?: string | null;
|
|
22
|
+
richAdClassName?: string | null;
|
|
23
|
+
richAdIframeClassName?: string | null;
|
|
24
|
+
onRender?: ((event: any) => void) | null;
|
|
25
|
+
onDestroy?: (() => void) | null;
|
|
26
|
+
onRichAd?: ((richAd: any) => void) | null;
|
|
27
|
+
slotRef?: Ref<AdSlot> | null;
|
|
28
|
+
}
|
|
29
|
+
declare function Ad({ slot: slotName, path: providedPath, size: providedSize, sizeMapping: providedSizeMapping, viewport: providedViewport, targeting: providedTargeting, refreshInterval: providedRefreshInterval, alwaysRender, disabled: providedDisabled, disableTracking, shouldKeepSize, withoutStyle, withoutMinimumSize, withReactId, className, emptyClassName, adClassName, richAdClassName, richAdIframeClassName, onRender, onDestroy, onRichAd, slotRef, }: AdProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export default Ad;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import EventEmitter from 'wolfy87-eventemitter';
|
|
2
|
+
import { AdSizeMapping } from './types';
|
|
3
|
+
export interface AdSlotOptions {
|
|
4
|
+
sizeMapping?: null | AdSizeMapping[];
|
|
5
|
+
targeting?: {
|
|
6
|
+
[key: string]: string | Array<string>;
|
|
7
|
+
};
|
|
8
|
+
categoryExclusions?: Array<string>;
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare class AdSlot extends EventEmitter {
|
|
12
|
+
options: AdSlotOptions;
|
|
13
|
+
elementId: string;
|
|
14
|
+
adPath: string;
|
|
15
|
+
adSize: string | Array<string>;
|
|
16
|
+
visible: boolean;
|
|
17
|
+
wasVisible: boolean;
|
|
18
|
+
adSlot: any;
|
|
19
|
+
rendered: boolean;
|
|
20
|
+
displayed: boolean;
|
|
21
|
+
viewable: boolean;
|
|
22
|
+
renderEvent: any;
|
|
23
|
+
refreshDisabled: boolean;
|
|
24
|
+
destroyed: boolean;
|
|
25
|
+
constructor(id: any, path: any, size: any, opts?: {});
|
|
26
|
+
updateAdSlot(): void;
|
|
27
|
+
setAdSlot(slot: any): this;
|
|
28
|
+
setRenderEvent(event: any): this;
|
|
29
|
+
setViewable(viewable: any): void;
|
|
30
|
+
setDisplayed(displayed: any): this;
|
|
31
|
+
setVisible(visible: any): this;
|
|
32
|
+
setRefreshDisabled(): void;
|
|
33
|
+
setTargeting(targeting: any): void;
|
|
34
|
+
destroy(): void;
|
|
35
|
+
getElementId(): string;
|
|
36
|
+
getAdSlot(): any;
|
|
37
|
+
getAdPath(): string;
|
|
38
|
+
getAdSize(): string | string[];
|
|
39
|
+
getTargeting(): {
|
|
40
|
+
[key: string]: string | string[];
|
|
41
|
+
};
|
|
42
|
+
isVisible(): boolean;
|
|
43
|
+
isDefined(): boolean;
|
|
44
|
+
isDisplayed(): boolean;
|
|
45
|
+
isViewable(): boolean;
|
|
46
|
+
isRendered(): boolean;
|
|
47
|
+
isRefreshDisabled(): boolean;
|
|
48
|
+
isDestroyed(): boolean;
|
|
49
|
+
isEmpty(): any;
|
|
50
|
+
canBeDisplayed(): boolean;
|
|
51
|
+
getRenderedSize(): {
|
|
52
|
+
width: any;
|
|
53
|
+
height: any;
|
|
54
|
+
isFluid: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export default AdSlot;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import AdsManager from './AdsManager';
|
|
3
|
+
import { Slots, SlotsDefinition, Viewports } from './types';
|
|
4
|
+
interface AdsContextType {
|
|
5
|
+
ready: boolean;
|
|
6
|
+
ads?: AdsManager;
|
|
7
|
+
viewports?: Viewports;
|
|
8
|
+
viewport?: string | null;
|
|
9
|
+
slots?: Slots;
|
|
10
|
+
slotsPath?: Record<string, string>;
|
|
11
|
+
trackingDisabled?: boolean;
|
|
12
|
+
richAdComponents?: Record<string, React.ElementType>;
|
|
13
|
+
}
|
|
14
|
+
declare const AdsContext: React.Context<AdsContextType>;
|
|
15
|
+
export declare const useAdsContext: () => AdsContextType;
|
|
16
|
+
interface AdsProviderProps {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
defaultSlotPath?: string | null;
|
|
19
|
+
slotsPath?: Record<string, string> | null;
|
|
20
|
+
disableSingleRequest?: boolean;
|
|
21
|
+
disableVideoAds?: boolean;
|
|
22
|
+
disableLazyLoad?: boolean;
|
|
23
|
+
autoInit?: boolean;
|
|
24
|
+
resizeDebounceDelay?: number;
|
|
25
|
+
refreshOnResize?: boolean;
|
|
26
|
+
mobileScaling?: number;
|
|
27
|
+
renderMarginPercent?: number;
|
|
28
|
+
fetchMarginPercent?: number;
|
|
29
|
+
viewport?: string | null;
|
|
30
|
+
viewports?: Viewports;
|
|
31
|
+
slots?: SlotsDefinition;
|
|
32
|
+
richAdComponents?: Record<string, React.ElementType> | null;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
disableTracking?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare function AdsProvider({ children, defaultSlotPath, slotsPath, disableSingleRequest, disableVideoAds, disableLazyLoad, autoInit, resizeDebounceDelay, refreshOnResize, mobileScaling, renderMarginPercent, fetchMarginPercent, viewport, viewports, slots, richAdComponents, disabled, disableTracking, }: AdsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export default AdsContext;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import EventEmitter from 'wolfy87-eventemitter';
|
|
2
|
+
import AdSlot, { AdSlotOptions as BaseAdSlotOptions } from './AdSlot';
|
|
3
|
+
import { AdSize } from './types';
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
googletag?: any;
|
|
7
|
+
refreshDisabledLineItems?: string[];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
interface AdSlotOptions extends BaseAdSlotOptions {
|
|
11
|
+
id?: string;
|
|
12
|
+
}
|
|
13
|
+
declare class AdsManager extends EventEmitter {
|
|
14
|
+
static ID_PREFIX: string;
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
personnalizedAdsDisabled: boolean;
|
|
17
|
+
ready: boolean;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
googletag: any;
|
|
20
|
+
slots: AdSlot[];
|
|
21
|
+
index: number;
|
|
22
|
+
options: {
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
disablePersonnalizedAds: boolean;
|
|
25
|
+
disableSingleRequest: boolean;
|
|
26
|
+
disableLazyLoad: boolean;
|
|
27
|
+
disableVideoAds: boolean;
|
|
28
|
+
autoInit: boolean;
|
|
29
|
+
mobileScaling?: number;
|
|
30
|
+
renderMarginPercent?: number;
|
|
31
|
+
fetchMarginPercent?: number;
|
|
32
|
+
};
|
|
33
|
+
static getArticleTargeting(article: any): {
|
|
34
|
+
title: any;
|
|
35
|
+
slug: any;
|
|
36
|
+
postID: any;
|
|
37
|
+
categories: any;
|
|
38
|
+
authors: any;
|
|
39
|
+
sponsors: any;
|
|
40
|
+
GoogleSafeTargeting: any;
|
|
41
|
+
};
|
|
42
|
+
static getSectionTargeting(section: any): {
|
|
43
|
+
section: any;
|
|
44
|
+
};
|
|
45
|
+
static getIndexTargeting(index: any): {
|
|
46
|
+
index: any;
|
|
47
|
+
};
|
|
48
|
+
static getIndexItemTargeting(index: any, item: any): {
|
|
49
|
+
[index.id]: any[];
|
|
50
|
+
};
|
|
51
|
+
constructor(opts?: {});
|
|
52
|
+
createAdId(): string;
|
|
53
|
+
init(): void;
|
|
54
|
+
initGpt(): void;
|
|
55
|
+
onSlotRenderEnded(event: any): void;
|
|
56
|
+
onSlotImpressionViewable(event: any): void;
|
|
57
|
+
onSlotVisibleChange(visible: any, slot: any): void;
|
|
58
|
+
isReady(): boolean;
|
|
59
|
+
isDisabled(): boolean;
|
|
60
|
+
setDisabled(disabled: any): void;
|
|
61
|
+
disablePersonnalizedAds(disablePersonnalizedAds: any): void;
|
|
62
|
+
createSlot(path: string, size: AdSize, opts?: AdSlotOptions): AdSlot;
|
|
63
|
+
defineSlot(slot: any): void;
|
|
64
|
+
displaySlots(): boolean;
|
|
65
|
+
displaySlot(slot: any): void;
|
|
66
|
+
callDisplaySlot(slot: any): void;
|
|
67
|
+
destroySlot(id: any): void;
|
|
68
|
+
refreshSlot(id: any): void;
|
|
69
|
+
refreshSlots(ids: any): void;
|
|
70
|
+
refreshAllSlots(): void;
|
|
71
|
+
}
|
|
72
|
+
export default AdsManager;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AdsTargeting } from './types';
|
|
3
|
+
interface AdsTargetingProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
targeting?: AdsTargeting;
|
|
6
|
+
replace?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const AdsTargetingContext: import("react").Context<AdsTargeting>;
|
|
9
|
+
export declare const useAdsTargeting: () => AdsTargeting | null;
|
|
10
|
+
export declare function AdsTargetingProvider({ children, targeting, replace, }: AdsTargetingProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default AdsTargetingContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * as PropTypes from "./propTypes";
|
|
2
|
+
export { default as Ad } from "./Ad";
|
|
3
|
+
export { default as RichAd } from "./RichAd";
|
|
4
|
+
export * from "./AdsContext";
|
|
5
|
+
export * from "./AdsTargetingContext";
|
|
6
|
+
export * from "./defaults";
|
|
7
|
+
export * from "./utils";
|
|
8
|
+
export * from "./types";
|
|
9
|
+
export { default as AdSlot } from "./AdSlot";
|
|
10
|
+
export { default as AdsManager } from "./AdsManager";
|
|
11
|
+
export { default as useAd } from "./useAd";
|
|
12
|
+
export { default as useAdsTracking } from "./useAdsTracking";
|
|
13
|
+
export { default as useRichAd } from "./useRichAd";
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type AdSize = [number, number] | 'fluid';
|
|
2
|
+
export type Viewport = [number, number];
|
|
3
|
+
export type AdSizeMapping = [Viewport, AdSize[]];
|
|
4
|
+
export interface Size {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface Viewports {
|
|
9
|
+
[name: string]: Viewport;
|
|
10
|
+
}
|
|
11
|
+
export interface SlotDefinition {
|
|
12
|
+
sizeMapping?: Record<string, AdSize[]> | boolean | null | AdSizeMapping[] | null;
|
|
13
|
+
size?: AdSize[];
|
|
14
|
+
path?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface Slot extends SlotDefinition {
|
|
17
|
+
sizeMapping?: AdSizeMapping[] | null;
|
|
18
|
+
}
|
|
19
|
+
export interface Slots {
|
|
20
|
+
[name: string]: Slot;
|
|
21
|
+
}
|
|
22
|
+
export interface SlotsDefinition {
|
|
23
|
+
[name: string]: SlotDefinition;
|
|
24
|
+
}
|
|
25
|
+
export interface AdsTargeting {
|
|
26
|
+
refreshAds?: 'inactive' | false | null | number;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
viewport?: string | null;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
export interface RichAd {
|
|
32
|
+
type: string;
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}
|
package/types/useAd.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import AdSlot from './AdSlot';
|
|
2
|
+
import { AdSizeMapping, AdsTargeting } from './types';
|
|
3
|
+
interface UseAdOptions {
|
|
4
|
+
id?: string;
|
|
5
|
+
sizeMapping?: AdSizeMapping[] | null;
|
|
6
|
+
viewport?: string | null;
|
|
7
|
+
targeting?: AdsTargeting | null;
|
|
8
|
+
categoryExclusions?: string[] | null;
|
|
9
|
+
refreshInterval?: number | null;
|
|
10
|
+
alwaysRender?: boolean;
|
|
11
|
+
onRender?: (event: any) => void | null;
|
|
12
|
+
onDestroy?: (event: any) => void | null;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
disableTracking?: boolean;
|
|
15
|
+
rootMargin?: string;
|
|
16
|
+
}
|
|
17
|
+
declare function useAd(path: string, size: any, { id, sizeMapping, viewport, targeting, categoryExclusions, refreshInterval, alwaysRender, onRender, onDestroy, disabled, disableTracking, rootMargin, }?: UseAdOptions): {
|
|
18
|
+
width: any;
|
|
19
|
+
height: any;
|
|
20
|
+
isFluid: boolean;
|
|
21
|
+
refObserver: import("react").RefObject<any>;
|
|
22
|
+
slot: AdSlot;
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
id: string;
|
|
25
|
+
isRendered: boolean;
|
|
26
|
+
isEmpty: any;
|
|
27
|
+
isVisible: boolean;
|
|
28
|
+
renderEvent: any;
|
|
29
|
+
};
|
|
30
|
+
export default useAd;
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AdSize, AdSizeMapping, Size, Slot, SlotDefinition, Viewport, Viewports } from './types';
|
|
2
|
+
export declare function normalizeAdSizes(size: any): AdSize[];
|
|
3
|
+
export declare function getAdSizes(sizes: any): AdSize[];
|
|
4
|
+
export declare function getMinimumAdSize(sizes: any): Size;
|
|
5
|
+
export declare function sizeFitsInViewport(size: AdSize, viewport: Viewport): boolean;
|
|
6
|
+
export declare function getSortedViewports(viewports: Viewports): any;
|
|
7
|
+
export declare function buildSizeMappingFromViewports(sizeMapping: any, viewports: any): AdSizeMapping[];
|
|
8
|
+
export declare function buildSizeMappingFromSizes(sizes: any, viewports: any): AdSizeMapping[];
|
|
9
|
+
export declare function getSizeMappingFromSlot({ size: allSizes, sizeMapping }: Slot | SlotDefinition, viewports: Viewports): AdSizeMapping[] | null;
|
|
10
|
+
export declare function getSizeFromSizeMapping(sizeMapping: any): AdSize[] | null;
|