@folklore/ads 0.0.5 → 0.0.7

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.
Files changed (3) hide show
  1. package/dist/cjs.js +28 -38
  2. package/dist/es.js +27 -37
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -32,12 +32,12 @@ var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
32
32
  const adPath = PropTypes__default["default"].string;
33
33
  const adSize = PropTypes__default["default"].oneOfType([PropTypes__default["default"].arrayOf(PropTypes__default["default"].number), PropTypes__default["default"].arrayOf(PropTypes__default["default"].string), PropTypes__default["default"].string, PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].arrayOf(PropTypes__default["default"].number), PropTypes__default["default"].arrayOf(PropTypes__default["default"].string), PropTypes__default["default"].string]))]);
34
34
  const adSizeMapping = PropTypes__default["default"].arrayOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].arrayOf(PropTypes__default["default"].number), adSize])));
35
- const adPosition = PropTypes__default["default"].shape({
35
+ const adViewports = PropTypes__default["default"].objectOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].number));
36
+ const adSlot = PropTypes__default["default"].shape({
36
37
  size: adSize,
37
38
  sizeMapping: PropTypes__default["default"].objectOf(adSize)
38
39
  });
39
- const adPositions = PropTypes__default["default"].objectOf(adPosition);
40
- const adViewports = PropTypes__default["default"].objectOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].number));
40
+ const adSlots = PropTypes__default["default"].objectOf(adSlot);
41
41
  const adTargeting = PropTypes__default["default"].shape({
42
42
  domain: PropTypes__default["default"].string
43
43
  });
@@ -47,9 +47,9 @@ var propTypes$3 = /*#__PURE__*/Object.freeze({
47
47
  adPath: adPath,
48
48
  adSize: adSize,
49
49
  adSizeMapping: adSizeMapping,
50
- adPosition: adPosition,
51
- adPositions: adPositions,
52
50
  adViewports: adViewports,
51
+ adSlot: adSlot,
52
+ adSlots: adSlots,
53
53
  adTargeting: adTargeting
54
54
  });
55
55
 
@@ -85,7 +85,7 @@ const buildSizeMappingFromSizes = (sizes, viewports) => getSortedViewports(viewp
85
85
  } = _ref2;
86
86
  return [viewPortSize, sizes.filter(size => sizeFitsInViewport(size, name === 'default' ? [300, 300] : viewPortSize))];
87
87
  });
88
- const getSizeMappingFromPosition = (_ref3, viewports) => {
88
+ const getSizeMappingFromSlot = (_ref3, viewports) => {
89
89
  let {
90
90
  size: allSizes = [],
91
91
  sizeMapping = null
@@ -330,7 +330,9 @@ class AdsManager extends EventEmitter__default["default"] {
330
330
  this.personnalizedAdsDisabled = this.options.disablePersonnalizedAds;
331
331
  this.ready = false;
332
332
  this.enabled = false;
333
- this.googletag = window.googletag;
333
+ this.googletag = typeof window !== 'undefined' ? window.googletag : {
334
+ cmd: []
335
+ };
334
336
  this.slots = [];
335
337
  if (this.options.autoInit) {
336
338
  this.init();
@@ -391,7 +393,7 @@ class AdsManager extends EventEmitter__default["default"] {
391
393
  if (renderSlot !== null) {
392
394
  renderSlot.setRenderEvent(event);
393
395
  }
394
- const lineItems = window.refreshDisabledLineItems || [];
396
+ const lineItems = typeof window !== 'undefined' ? window.refreshDisabledLineItems || [] : [];
395
397
  if (isArray__default["default"](lineItems) && lineItems.indexOf(lineItemId) > -1) {
396
398
  renderSlot.setRefreshDisabled();
397
399
  }
@@ -580,7 +582,7 @@ const viewports = {
580
582
  desktop: [1024, 0],
581
583
  laptop: [1400, 700]
582
584
  };
583
- const positions = {
585
+ const slots = {
584
586
  top: {
585
587
  size: [[320, 50], [1382, 600], [320, 100], [970, 90], [1024, 300], [970, 250], [300, 150], [1382, 300], [300, 100], [250, 250], [300, 250]],
586
588
  sizeMapping: {
@@ -631,7 +633,7 @@ const propTypes$2 = {
631
633
  autoInit: PropTypes__default["default"].bool,
632
634
  resizeDebounceDelay: PropTypes__default["default"].number,
633
635
  refreshOnResize: PropTypes__default["default"].bool,
634
- positions: adViewports,
636
+ slots: adSlots,
635
637
  viewports: adViewports
636
638
  };
637
639
  const defaultProps$2 = {
@@ -641,7 +643,7 @@ const defaultProps$2 = {
641
643
  autoInit: true,
642
644
  resizeDebounceDelay: 500,
643
645
  refreshOnResize: false,
644
- positions: positions,
646
+ slots: slots,
645
647
  viewports: viewports
646
648
  };
647
649
  function AdsProvider(_ref) {
@@ -654,7 +656,7 @@ function AdsProvider(_ref) {
654
656
  resizeDebounceDelay,
655
657
  refreshOnResize,
656
658
  viewports,
657
- positions
659
+ slots
658
660
  } = _ref;
659
661
  const [ready, setReady] = React.useState(false);
660
662
  const adsRef = React.useRef(null);
@@ -702,14 +704,14 @@ function AdsProvider(_ref) {
702
704
  ready,
703
705
  ads,
704
706
  viewports,
705
- positions,
707
+ slots,
706
708
  slotsPath: defaultSlotPath !== null ? {
707
709
  default: defaultSlotPath,
708
710
  ...slotsPath
709
711
  } : {
710
712
  ...slotsPath
711
713
  }
712
- }), [ready, ads, viewports, positions, slotsPath, defaultSlotPath]);
714
+ }), [ready, ads, viewports, slots, slotsPath, defaultSlotPath]);
713
715
  return /*#__PURE__*/jsxRuntime.jsx(AdsContext.Provider, {
714
716
  value: value,
715
717
  children: children
@@ -896,8 +898,7 @@ function useAd(path, size) {
896
898
  }
897
899
 
898
900
  const propTypes = {
899
- position: PropTypes__default["default"].string.isRequired,
900
- slot: PropTypes__default["default"].string,
901
+ slot: PropTypes__default["default"].string.isRequired,
901
902
  path: adPath,
902
903
  size: adSize,
903
904
  sizeMapping: adSizeMapping,
@@ -912,7 +913,6 @@ const propTypes = {
912
913
  };
913
914
  const defaultProps = {
914
915
  path: null,
915
- slot: 'default',
916
916
  size: null,
917
917
  sizeMapping: null,
918
918
  targeting: null,
@@ -926,7 +926,6 @@ const defaultProps = {
926
926
  };
927
927
  function Ad(_ref) {
928
928
  let {
929
- position: positionName,
930
929
  slot: slotName,
931
930
  path,
932
931
  size,
@@ -942,21 +941,21 @@ function Ad(_ref) {
942
941
  } = _ref;
943
942
  const {
944
943
  viewports,
945
- positions,
944
+ slots,
946
945
  slotsPath
947
946
  } = useAdsContext();
948
- const position = positionName !== null ? positions[positionName] || null : null;
949
- const finalPath = path || (slotName !== null ? slotsPath[slotName] : null) || (positionName !== null ? slotsPath[positionName] : null);
950
- const finalSize = size !== null ? size : position.size;
947
+ const slot = slotName !== null ? slots[slotName] || null : null;
948
+ const finalPath = path || (slotName !== null ? slotsPath[slotName] : null) || slotsPath.default;
949
+ const finalSize = size !== null ? size : slot.size;
951
950
 
952
951
  // Targeting
953
952
  const contextTargeting = useAdsTargeting();
954
- const finalSizeMapping = React.useMemo(() => sizeMapping !== null ? sizeMapping : getSizeMappingFromPosition(position, viewports), [sizeMapping, position, viewports]);
955
- const allTargeting = React.useMemo(() => contextTargeting !== null || targeting !== null || positionName !== null ? {
956
- position: positionName,
953
+ const finalSizeMapping = React.useMemo(() => sizeMapping !== null ? sizeMapping : getSizeMappingFromSlot(slot, viewports), [sizeMapping, slot, viewports]);
954
+ const allTargeting = React.useMemo(() => contextTargeting !== null || targeting !== null || slotName !== null ? {
955
+ slot: slotName,
957
956
  ...contextTargeting,
958
957
  ...targeting
959
- } : null, [contextTargeting, targeting, positionName]);
958
+ } : null, [contextTargeting, targeting, slotName]);
960
959
  const finalAdTargeting = React.useMemo(() => {
961
960
  const {
962
961
  refreshAds = null,
@@ -1026,18 +1025,9 @@ function Ad(_ref) {
1026
1025
  [emptyClassName]: emptyClassName !== null && isEmpty && !keepSize
1027
1026
  }]),
1028
1027
  ref: refObserver,
1029
- style: isEmpty && !keepSize ? {
1030
- height: 0,
1031
- paddingBottom: 0,
1032
- overflow: 'hidden',
1033
- opacity: 0
1034
- } : null,
1035
1028
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
1036
1029
  className: adClassName,
1037
- style: {
1038
- ...sizeStyle,
1039
- margin: 'auto'
1040
- },
1030
+ style: sizeStyle,
1041
1031
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
1042
1032
  id: id
1043
1033
  })
@@ -1057,10 +1047,10 @@ exports.buildSizeMappingFromSizes = buildSizeMappingFromSizes;
1057
1047
  exports.buildSizeMappingFromViewports = buildSizeMappingFromViewports;
1058
1048
  exports.getAdSizes = getAdSizes;
1059
1049
  exports.getMinimumAdSize = getMinimumAdSize;
1060
- exports.getSizeMappingFromPosition = getSizeMappingFromPosition;
1050
+ exports.getSizeMappingFromSlot = getSizeMappingFromSlot;
1061
1051
  exports.getSortedViewports = getSortedViewports;
1062
- exports.positions = positions;
1063
1052
  exports.sizeFitsInViewport = sizeFitsInViewport;
1053
+ exports.slots = slots;
1064
1054
  exports.useAd = useAd;
1065
1055
  exports.useAdsContext = useAdsContext;
1066
1056
  exports.useAdsTargeting = useAdsTargeting;
package/dist/es.js CHANGED
@@ -15,12 +15,12 @@ import { useTracking } from '@folklore/tracking';
15
15
  const adPath = PropTypes.string;
16
16
  const adSize = PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.arrayOf(PropTypes.string), PropTypes.string, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.arrayOf(PropTypes.string), PropTypes.string]))]);
17
17
  const adSizeMapping = PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), adSize])));
18
- const adPosition = PropTypes.shape({
18
+ const adViewports = PropTypes.objectOf(PropTypes.arrayOf(PropTypes.number));
19
+ const adSlot = PropTypes.shape({
19
20
  size: adSize,
20
21
  sizeMapping: PropTypes.objectOf(adSize)
21
22
  });
22
- const adPositions = PropTypes.objectOf(adPosition);
23
- const adViewports = PropTypes.objectOf(PropTypes.arrayOf(PropTypes.number));
23
+ const adSlots = PropTypes.objectOf(adSlot);
24
24
  const adTargeting = PropTypes.shape({
25
25
  domain: PropTypes.string
26
26
  });
@@ -30,9 +30,9 @@ var propTypes$3 = /*#__PURE__*/Object.freeze({
30
30
  adPath: adPath,
31
31
  adSize: adSize,
32
32
  adSizeMapping: adSizeMapping,
33
- adPosition: adPosition,
34
- adPositions: adPositions,
35
33
  adViewports: adViewports,
34
+ adSlot: adSlot,
35
+ adSlots: adSlots,
36
36
  adTargeting: adTargeting
37
37
  });
38
38
 
@@ -68,7 +68,7 @@ const buildSizeMappingFromSizes = (sizes, viewports) => getSortedViewports(viewp
68
68
  } = _ref2;
69
69
  return [viewPortSize, sizes.filter(size => sizeFitsInViewport(size, name === 'default' ? [300, 300] : viewPortSize))];
70
70
  });
71
- const getSizeMappingFromPosition = (_ref3, viewports) => {
71
+ const getSizeMappingFromSlot = (_ref3, viewports) => {
72
72
  let {
73
73
  size: allSizes = [],
74
74
  sizeMapping = null
@@ -313,7 +313,9 @@ class AdsManager extends EventEmitter {
313
313
  this.personnalizedAdsDisabled = this.options.disablePersonnalizedAds;
314
314
  this.ready = false;
315
315
  this.enabled = false;
316
- this.googletag = window.googletag;
316
+ this.googletag = typeof window !== 'undefined' ? window.googletag : {
317
+ cmd: []
318
+ };
317
319
  this.slots = [];
318
320
  if (this.options.autoInit) {
319
321
  this.init();
@@ -374,7 +376,7 @@ class AdsManager extends EventEmitter {
374
376
  if (renderSlot !== null) {
375
377
  renderSlot.setRenderEvent(event);
376
378
  }
377
- const lineItems = window.refreshDisabledLineItems || [];
379
+ const lineItems = typeof window !== 'undefined' ? window.refreshDisabledLineItems || [] : [];
378
380
  if (isArray(lineItems) && lineItems.indexOf(lineItemId) > -1) {
379
381
  renderSlot.setRefreshDisabled();
380
382
  }
@@ -563,7 +565,7 @@ const viewports = {
563
565
  desktop: [1024, 0],
564
566
  laptop: [1400, 700]
565
567
  };
566
- const positions = {
568
+ const slots = {
567
569
  top: {
568
570
  size: [[320, 50], [1382, 600], [320, 100], [970, 90], [1024, 300], [970, 250], [300, 150], [1382, 300], [300, 100], [250, 250], [300, 250]],
569
571
  sizeMapping: {
@@ -614,7 +616,7 @@ const propTypes$2 = {
614
616
  autoInit: PropTypes.bool,
615
617
  resizeDebounceDelay: PropTypes.number,
616
618
  refreshOnResize: PropTypes.bool,
617
- positions: adViewports,
619
+ slots: adSlots,
618
620
  viewports: adViewports
619
621
  };
620
622
  const defaultProps$2 = {
@@ -624,7 +626,7 @@ const defaultProps$2 = {
624
626
  autoInit: true,
625
627
  resizeDebounceDelay: 500,
626
628
  refreshOnResize: false,
627
- positions: positions,
629
+ slots: slots,
628
630
  viewports: viewports
629
631
  };
630
632
  function AdsProvider(_ref) {
@@ -637,7 +639,7 @@ function AdsProvider(_ref) {
637
639
  resizeDebounceDelay,
638
640
  refreshOnResize,
639
641
  viewports,
640
- positions
642
+ slots
641
643
  } = _ref;
642
644
  const [ready, setReady] = useState(false);
643
645
  const adsRef = useRef(null);
@@ -685,14 +687,14 @@ function AdsProvider(_ref) {
685
687
  ready,
686
688
  ads,
687
689
  viewports,
688
- positions,
690
+ slots,
689
691
  slotsPath: defaultSlotPath !== null ? {
690
692
  default: defaultSlotPath,
691
693
  ...slotsPath
692
694
  } : {
693
695
  ...slotsPath
694
696
  }
695
- }), [ready, ads, viewports, positions, slotsPath, defaultSlotPath]);
697
+ }), [ready, ads, viewports, slots, slotsPath, defaultSlotPath]);
696
698
  return /*#__PURE__*/jsx(AdsContext.Provider, {
697
699
  value: value,
698
700
  children: children
@@ -879,8 +881,7 @@ function useAd(path, size) {
879
881
  }
880
882
 
881
883
  const propTypes = {
882
- position: PropTypes.string.isRequired,
883
- slot: PropTypes.string,
884
+ slot: PropTypes.string.isRequired,
884
885
  path: adPath,
885
886
  size: adSize,
886
887
  sizeMapping: adSizeMapping,
@@ -895,7 +896,6 @@ const propTypes = {
895
896
  };
896
897
  const defaultProps = {
897
898
  path: null,
898
- slot: 'default',
899
899
  size: null,
900
900
  sizeMapping: null,
901
901
  targeting: null,
@@ -909,7 +909,6 @@ const defaultProps = {
909
909
  };
910
910
  function Ad(_ref) {
911
911
  let {
912
- position: positionName,
913
912
  slot: slotName,
914
913
  path,
915
914
  size,
@@ -925,21 +924,21 @@ function Ad(_ref) {
925
924
  } = _ref;
926
925
  const {
927
926
  viewports,
928
- positions,
927
+ slots,
929
928
  slotsPath
930
929
  } = useAdsContext();
931
- const position = positionName !== null ? positions[positionName] || null : null;
932
- const finalPath = path || (slotName !== null ? slotsPath[slotName] : null) || (positionName !== null ? slotsPath[positionName] : null);
933
- const finalSize = size !== null ? size : position.size;
930
+ const slot = slotName !== null ? slots[slotName] || null : null;
931
+ const finalPath = path || (slotName !== null ? slotsPath[slotName] : null) || slotsPath.default;
932
+ const finalSize = size !== null ? size : slot.size;
934
933
 
935
934
  // Targeting
936
935
  const contextTargeting = useAdsTargeting();
937
- const finalSizeMapping = useMemo(() => sizeMapping !== null ? sizeMapping : getSizeMappingFromPosition(position, viewports), [sizeMapping, position, viewports]);
938
- const allTargeting = useMemo(() => contextTargeting !== null || targeting !== null || positionName !== null ? {
939
- position: positionName,
936
+ const finalSizeMapping = useMemo(() => sizeMapping !== null ? sizeMapping : getSizeMappingFromSlot(slot, viewports), [sizeMapping, slot, viewports]);
937
+ const allTargeting = useMemo(() => contextTargeting !== null || targeting !== null || slotName !== null ? {
938
+ slot: slotName,
940
939
  ...contextTargeting,
941
940
  ...targeting
942
- } : null, [contextTargeting, targeting, positionName]);
941
+ } : null, [contextTargeting, targeting, slotName]);
943
942
  const finalAdTargeting = useMemo(() => {
944
943
  const {
945
944
  refreshAds = null,
@@ -1009,18 +1008,9 @@ function Ad(_ref) {
1009
1008
  [emptyClassName]: emptyClassName !== null && isEmpty && !keepSize
1010
1009
  }]),
1011
1010
  ref: refObserver,
1012
- style: isEmpty && !keepSize ? {
1013
- height: 0,
1014
- paddingBottom: 0,
1015
- overflow: 'hidden',
1016
- opacity: 0
1017
- } : null,
1018
1011
  children: /*#__PURE__*/jsx("div", {
1019
1012
  className: adClassName,
1020
- style: {
1021
- ...sizeStyle,
1022
- margin: 'auto'
1023
- },
1013
+ style: sizeStyle,
1024
1014
  children: /*#__PURE__*/jsx("div", {
1025
1015
  id: id
1026
1016
  })
@@ -1030,4 +1020,4 @@ function Ad(_ref) {
1030
1020
  Ad.propTypes = propTypes;
1031
1021
  Ad.defaultProps = defaultProps;
1032
1022
 
1033
- export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes$3 as PropTypes, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeMappingFromPosition, getSortedViewports, positions, sizeFitsInViewport, useAd, useAdsContext, useAdsTargeting, useTrackAd as useAdsTracking, viewports };
1023
+ export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes$3 as PropTypes, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeMappingFromSlot, getSortedViewports, sizeFitsInViewport, slots, useAd, useAdsContext, useAdsTargeting, useTrackAd as useAdsTracking, viewports };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/ads",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
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": "cbdee31b7e205f95c4ab462380feee74c076daa1",
53
+ "gitHead": "534c66f1119953e57b47773878494c1b7bab2620",
54
54
  "dependencies": {
55
55
  "@folklore/hooks": "^0.0.41",
56
56
  "@folklore/tracking": "^0.0.16",