@folklore/ads 0.0.109 → 0.0.111

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/es.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import classNames from 'classnames';
3
- import isFunction from 'lodash/isFunction';
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$4 = /*#__PURE__*/Object.freeze({
29
+ var propTypes = /*#__PURE__*/Object.freeze({
31
30
  __proto__: null,
32
31
  adPath: adPath,
33
32
  adSize: adSize,
@@ -50,42 +49,45 @@ function normalizeAdSizes(size) {
50
49
  function getAdSizes(sizes) {
51
50
  return uniqBy(sizes, size => isArray(size) ? size.join('x') : size);
52
51
  }
53
- const getMinimumAdSize = sizes => 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
- const sizeFitsInViewport = (size, viewport) => size === 'fluid' && viewport[0] > 600 || size !== 'fluid' && (viewport[0] === 0 || size[0] <= viewport[0]) && (viewport[1] === 0 || size[1] <= viewport[1]);
61
- const getSortedViewports = viewports => sortBy(Object.keys(viewports).map(name => ({
62
- name,
63
- size: viewports[name]
64
- })), [viewport => viewport.size[0]]).reverse();
65
- const buildSizeMappingFromViewports = (sizeMapping, viewports) => isObject(sizeMapping) && !isArray(sizeMapping) ? getSortedViewports(viewports).reduce((newSizeMapping, _ref) => {
66
- 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 => ({
66
+ name,
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, {
67
72
  name,
68
73
  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 {
74
+ }) => typeof sizeMapping[name] !== 'undefined' ? [...newSizeMapping, [viewPortSize, sizeMapping[name]]] : newSizeMapping, []) : sizeMapping;
75
+ }
76
+ function buildSizeMappingFromSizes(sizes, viewports) {
77
+ return getSortedViewports(viewports).map(({
74
78
  name,
75
79
  size: viewPortSize
76
- } = _ref2;
77
- return [viewPortSize, sizes.filter(size => sizeFitsInViewport(size, name === 'default' ? [300, 300] : viewPortSize))];
78
- });
79
- const getSizeMappingFromSlot = (_ref3, viewports) => {
80
- let {
81
- size: allSizes = [],
82
- sizeMapping = null
83
- } = _ref3;
80
+ }) => [viewPortSize, sizes.filter(size => sizeFitsInViewport(size, name === 'default' ? [300, 300] : viewPortSize))]);
81
+ }
82
+ function getSizeMappingFromSlot({
83
+ size: allSizes = [],
84
+ sizeMapping = null
85
+ }, viewports) {
84
86
  if (sizeMapping === true) {
85
87
  return buildSizeMappingFromSizes(allSizes, viewports);
86
88
  }
87
89
  return sizeMapping !== null ? buildSizeMappingFromViewports(sizeMapping, viewports) : null;
88
- };
90
+ }
89
91
  function getSizeFromSizeMapping(sizeMapping) {
90
92
  if (sizeMapping === null) {
91
93
  return null;
@@ -105,8 +107,7 @@ function getSizeFromSizeMapping(sizeMapping) {
105
107
  }
106
108
 
107
109
  class AdSlot extends EventEmitter {
108
- constructor(id, path, size) {
109
- let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
110
+ constructor(id, path, size, opts = {}) {
110
111
  super();
111
112
  this.options = {
112
113
  sizeMapping: null,
@@ -334,8 +335,7 @@ class AdsManager extends EventEmitter {
334
335
  [index.id]: [item.slug]
335
336
  } : null;
336
337
  }
337
- constructor() {
338
- let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
338
+ constructor(opts = {}) {
339
339
  super();
340
340
  this.options = {
341
341
  disabled: false,
@@ -503,8 +503,7 @@ class AdsManager extends EventEmitter {
503
503
  googletag.pubads().setRequestNonPersonalizedAds(disablePersonnalizedAds ? 1 : 0);
504
504
  });
505
505
  }
506
- createSlot(path, size) {
507
- let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
506
+ createSlot(path, size, opts = {}) {
508
507
  const {
509
508
  id: providedId = null
510
509
  } = opts;
@@ -681,66 +680,26 @@ const AdsContext = /*#__PURE__*/React.createContext({
681
680
  ready: false
682
681
  });
683
682
  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
- function AdsProvider(_ref) {
724
- let {
725
- 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
743
- } = _ref;
683
+ function AdsProvider({
684
+ children,
685
+ defaultSlotPath = null,
686
+ slotsPath = null,
687
+ disableSingleRequest = false,
688
+ disableVideoAds = false,
689
+ disableLazyLoad = false,
690
+ autoInit = true,
691
+ resizeDebounceDelay = 500,
692
+ refreshOnResize = false,
693
+ mobileScaling = 1.0,
694
+ renderMarginPercent = 100,
695
+ fetchMarginPercent = 300,
696
+ viewport = null,
697
+ viewports: viewports$1 = viewports,
698
+ slots: slots$1 = slots,
699
+ richAdComponents = null,
700
+ disabled = false,
701
+ disableTracking = false
702
+ }) {
744
703
  const [ready, setReady] = useState(false);
745
704
  const adsRef = useRef(null);
746
705
  const ads = useMemo(() => {
@@ -791,12 +750,12 @@ function AdsProvider(_ref) {
791
750
  onResize.cancel();
792
751
  };
793
752
  }, [ads, resizeDebounceDelay, refreshOnResize]);
794
- const slotsWithSizeMapping = useMemo(() => Object.keys(slots || {}).reduce((map, key) => {
795
- const slot = slots[key];
753
+ const slotsWithSizeMapping = useMemo(() => Object.keys(slots$1 || {}).reduce((map, key) => {
754
+ const slot = slots$1[key];
796
755
  const {
797
756
  size
798
757
  } = slot;
799
- const sizeMapping = getSizeMappingFromSlot(slot, viewports);
758
+ const sizeMapping = getSizeMappingFromSlot(slot, viewports$1);
800
759
  return {
801
760
  ...map,
802
761
  [key]: {
@@ -805,51 +764,44 @@ function AdsProvider(_ref) {
805
764
  sizeMapping
806
765
  }
807
766
  };
808
- }, {}), []);
809
- const finalSlotsPath = useMemo(() => defaultSlotPath !== null ? {
810
- default: defaultSlotPath,
811
- ...slotsPath
812
- } : {
813
- ...slotsPath
767
+ }, {}), [slots$1, viewports$1]);
768
+ const finalSlotsPath = useMemo(() => {
769
+ if (defaultSlotPath !== null && slotsPath) {
770
+ return {
771
+ default: defaultSlotPath,
772
+ ...slotsPath
773
+ };
774
+ }
775
+ return slotsPath ? {
776
+ ...slotsPath
777
+ } : {};
814
778
  }, [defaultSlotPath, slotsPath]);
815
779
  const value = useMemo(() => ({
816
780
  ready,
817
781
  ads,
818
- viewports,
782
+ viewports: viewports$1,
819
783
  viewport,
820
784
  slots: slotsWithSizeMapping,
821
785
  slotsPath: finalSlotsPath,
822
786
  trackingDisabled: disableTracking,
823
787
  richAdComponents
824
- }), [ready, ads, viewports, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
788
+ }), [ready, ads, viewports$1, viewport, slotsWithSizeMapping, finalSlotsPath, disableTracking, richAdComponents]);
825
789
  return /*#__PURE__*/jsx(AdsContext.Provider, {
826
790
  value: value,
827
791
  children: children
828
792
  });
829
793
  }
830
- AdsProvider.propTypes = propTypes$3;
831
- AdsProvider.defaultProps = defaultProps$2;
832
794
 
833
- const AdsTargetingContext = /*#__PURE__*/React.createContext(null);
834
- const useAdsTargeting = () => useContext(AdsTargetingContext);
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
795
+ const defaultTargeting = {
796
+ domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
840
797
  };
841
- const defaultProps$1 = {
842
- targeting: {
843
- domain: typeof window !== 'undefined' ? `${window.location.protocol}//${window.location.host}` : null
844
- },
845
- replace: false
846
- };
847
- function AdsTargetingProvider(_ref) {
848
- let {
849
- children,
850
- targeting,
851
- replace
852
- } = _ref;
798
+ const AdsTargetingContext = /*#__PURE__*/createContext(defaultTargeting);
799
+ const useAdsTargeting = () => useContext(AdsTargetingContext);
800
+ function AdsTargetingProvider({
801
+ children,
802
+ targeting = defaultTargeting,
803
+ replace = false
804
+ }) {
853
805
  const previousTargeting = useAdsTargeting();
854
806
  const mergedTargeting = useMemo(() => replace ? targeting : {
855
807
  ...previousTargeting,
@@ -860,21 +812,12 @@ function AdsTargetingProvider(_ref) {
860
812
  children: children
861
813
  });
862
814
  }
863
- AdsTargetingProvider.propTypes = propTypes$2;
864
- AdsTargetingProvider.defaultProps = defaultProps$1;
865
815
 
866
816
  /* 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
- function RichAd(_ref) {
874
- let {
875
- richAd,
876
- ...props
877
- } = _ref;
817
+ function RichAd({
818
+ richAd,
819
+ ...props
820
+ }) {
878
821
  const {
879
822
  type = null,
880
823
  ...richAdProps
@@ -888,12 +831,10 @@ function RichAd(_ref) {
888
831
  ...richAdProps
889
832
  }) : null;
890
833
  }
891
- RichAd.propTypes = propTypes$1;
892
- RichAd.defaultProps = defaultProps;
893
834
 
894
835
  function useAdsTracking() {
895
836
  const tracking = useTracking() || null;
896
- const trackEvent = useCallback((action, slot, renderEvent) => {
837
+ const trackEvent = useCallback((action, slot = null, renderEvent = null) => {
897
838
  if (tracking !== null && typeof tracking.trackAd !== 'undefined') {
898
839
  tracking.trackAd(action, slot, renderEvent);
899
840
  }
@@ -901,21 +842,20 @@ function useAdsTracking() {
901
842
  return trackEvent;
902
843
  }
903
844
 
904
- function useAd(path, size) {
905
- let {
906
- id,
907
- sizeMapping = null,
908
- viewport = null,
909
- targeting = null,
910
- categoryExclusions = null,
911
- refreshInterval = null,
912
- alwaysRender = false,
913
- onRender = null,
914
- onDestroy = null,
915
- disabled = false,
916
- disableTracking = false,
917
- rootMargin = '300px'
918
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
845
+ function useAd(path, size, {
846
+ id,
847
+ sizeMapping = null,
848
+ viewport = null,
849
+ targeting = null,
850
+ categoryExclusions = null,
851
+ refreshInterval = null,
852
+ alwaysRender = false,
853
+ onRender = null,
854
+ onDestroy = null,
855
+ disabled = false,
856
+ disableTracking = false,
857
+ rootMargin = '300px'
858
+ } = {}) {
919
859
  const {
920
860
  ads: adsManager,
921
861
  viewports,
@@ -923,9 +863,9 @@ function useAd(path, size) {
923
863
  trackingDisabled: globalTrackingDisabled = false
924
864
  } = useAdsContext();
925
865
  const trackAd = useAdsTracking();
926
- const track = useCallback(function () {
866
+ const track = useCallback((action, slot = null, renderEvent = null) => {
927
867
  if (!disableTracking && !globalTrackingDisabled) {
928
- trackAd(...arguments);
868
+ trackAd(action, slot, renderEvent);
929
869
  }
930
870
  }, [disableTracking, globalTrackingDisabled, trackAd]);
931
871
 
@@ -933,7 +873,7 @@ function useAd(path, size) {
933
873
  const {
934
874
  ref: refObserver,
935
875
  entry: {
936
- isIntersecting
876
+ isIntersecting = false
937
877
  }
938
878
  } = useIntersectionObserver({
939
879
  rootMargin,
@@ -963,10 +903,7 @@ function useAd(path, size) {
963
903
  adsManager.destroySlot(currentSlot);
964
904
  }
965
905
  const viewportSize = viewport !== null ? viewports[viewport] || null : null;
966
- const [, viewportFixedSize = null] = sizeMapping !== null && viewportSize !== null ? sizeMapping.find(_ref => {
967
- let [itViewport] = _ref;
968
- return itViewport.join('x') === viewportSize.join('x');
969
- }) || [] : [];
906
+ const [, viewportFixedSize = null] = sizeMapping !== null && viewportSize !== null ? sizeMapping.find(([itViewport]) => itViewport.join('x') === viewportSize.join('x')) || [] : [];
970
907
  const newSlot = path !== null && !disabled ? adsManager.createSlot(path, viewportFixedSize || size, {
971
908
  id,
972
909
  visible: isVisible,
@@ -1113,7 +1050,7 @@ function parseRichAd(data) {
1113
1050
  } catch (e) {}
1114
1051
  return richAd;
1115
1052
  }
1116
- function useRichAd(containerRef, id, opts) {
1053
+ function useRichAd(containerRef, id, opts = {}) {
1117
1054
  const [richAd, setRichAd] = useState(null);
1118
1055
  const {
1119
1056
  onRichAd = null
@@ -1151,57 +1088,31 @@ function useRichAd(containerRef, id, opts) {
1151
1088
  }
1152
1089
 
1153
1090
  /* 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
- function Ad(_ref) {
1180
- let {
1181
- slot: slotName = null,
1182
- path: providedPath = null,
1183
- size: providedSize = null,
1184
- sizeMapping: providedSizeMapping = null,
1185
- viewport: providedViewport = null,
1186
- targeting: providedTargeting = null,
1187
- refreshInterval: providedRefreshInterval = null,
1188
- alwaysRender = true,
1189
- disabled: providedDisabled = false,
1190
- disableTracking = false,
1191
- shouldKeepSize = false,
1192
- withoutStyle = false,
1193
- withoutMinimumSize = false,
1194
- withReactId = false,
1195
- className = null,
1196
- emptyClassName = null,
1197
- adClassName = null,
1198
- richAdClassName = null,
1199
- richAdIframeClassName = null,
1200
- onRender = null,
1201
- onDestroy = null,
1202
- onRichAd = null,
1203
- slotRef = null
1204
- } = _ref;
1091
+ function Ad({
1092
+ slot: slotName,
1093
+ path: providedPath = null,
1094
+ size: providedSize = null,
1095
+ sizeMapping: providedSizeMapping = null,
1096
+ viewport: providedViewport = null,
1097
+ targeting: providedTargeting = null,
1098
+ refreshInterval: providedRefreshInterval = null,
1099
+ alwaysRender = true,
1100
+ disabled: providedDisabled = false,
1101
+ disableTracking = false,
1102
+ shouldKeepSize = false,
1103
+ withoutStyle = false,
1104
+ withoutMinimumSize = false,
1105
+ withReactId = false,
1106
+ className = null,
1107
+ emptyClassName = null,
1108
+ adClassName = null,
1109
+ richAdClassName = null,
1110
+ richAdIframeClassName = null,
1111
+ onRender = null,
1112
+ onDestroy = null,
1113
+ onRichAd = null,
1114
+ slotRef = null
1115
+ }) {
1205
1116
  const {
1206
1117
  slots = null,
1207
1118
  slotsPath = null,
@@ -1211,7 +1122,7 @@ function Ad(_ref) {
1211
1122
  const {
1212
1123
  default: defaultSlotPath = null
1213
1124
  } = slotsPath || {};
1214
- const slot = slotName !== null && slots !== null ? slots[slotName] || null : null;
1125
+ const slot = slotName && slots !== null ? slots[slotName] || null : null;
1215
1126
  const {
1216
1127
  sizeMapping: slotSizeMapping = null,
1217
1128
  size: slotSize = null,
@@ -1310,9 +1221,9 @@ function Ad(_ref) {
1310
1221
  const richAd = useRichAd(adContainerRef, id, {
1311
1222
  onRichAd
1312
1223
  });
1313
- if (slotRef !== null && isFunction(slotRef)) {
1224
+ if (slotRef !== null && typeof slotRef === 'function') {
1314
1225
  slotRef(slotObject);
1315
- } else if (slotRef !== null && isObject(slotRef)) {
1226
+ } else if (slotRef !== null && typeof slotRef === 'object') {
1316
1227
  // eslint-disable-next-line no-param-reassign
1317
1228
  slotRef.current = slotObject;
1318
1229
  }
@@ -1374,6 +1285,5 @@ function Ad(_ref) {
1374
1285
  })
1375
1286
  });
1376
1287
  }
1377
- Ad.propTypes = propTypes;
1378
1288
 
1379
- export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes$4 as PropTypes, RichAd, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeFromSizeMapping, getSizeMappingFromSlot, getSortedViewports, normalizeAdSizes, sizeFitsInViewport, slots, useAd, useAdsContext, useAdsTargeting, useAdsTracking, useRichAd, viewports };
1289
+ 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.109",
3
+ "version": "0.0.111",
4
4
  "description": "Ads library",
5
5
  "keywords": [
6
6
  "javascript",
@@ -29,13 +29,16 @@
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": "rollup --bundleConfigAsCjs --config ../../rollup.config.js",
38
- "prepare": "npm run clean && npm run 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",
41
+ "prepublishOnly": "npm run clean && npm run build"
39
42
  },
40
43
  "devDependencies": {
41
44
  "prop-types": "^15.7.2",
@@ -50,11 +53,11 @@
50
53
  "publishConfig": {
51
54
  "access": "public"
52
55
  },
53
- "gitHead": "6879f02e1991265ab2248de470fbf8e1240483a9",
56
+ "gitHead": "a04cfaacb364f3b35307d65d8778b078dace4491",
54
57
  "dependencies": {
55
- "@folklore/hooks": "^0.0.73",
56
- "@folklore/tracking": "^0.0.29",
57
- "@folklore/utils": "^0.1.3",
58
+ "@folklore/hooks": "^0.0.74",
59
+ "@folklore/tracking": "^0.0.30",
60
+ "@folklore/utils": "^0.1.4",
58
61
  "classnames": "^2.5.1",
59
62
  "debug": "^4.3.4",
60
63
  "lodash": "^4.17.21",
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;