@folklore/ads 0.0.13 → 0.0.14
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 +78 -16
- package/dist/es.js +77 -15
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -7,10 +7,10 @@ var classNames = require('classnames');
|
|
|
7
7
|
var isFunction = require('lodash/isFunction');
|
|
8
8
|
var isObject = require('lodash/isObject');
|
|
9
9
|
var React = require('react');
|
|
10
|
-
var debounce = require('lodash/debounce');
|
|
11
10
|
var isArray = require('lodash/isArray');
|
|
12
11
|
var sortBy = require('lodash/sortBy');
|
|
13
12
|
var uniqBy = require('lodash/uniqBy');
|
|
13
|
+
var debounce = require('lodash/debounce');
|
|
14
14
|
var EventEmitter = require('wolfy87-eventemitter');
|
|
15
15
|
var createDebug = require('debug');
|
|
16
16
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -24,10 +24,10 @@ var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
|
24
24
|
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
|
|
25
25
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
26
26
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
27
|
-
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
28
27
|
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
|
|
29
28
|
var sortBy__default = /*#__PURE__*/_interopDefaultLegacy(sortBy);
|
|
30
29
|
var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
|
|
30
|
+
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
31
31
|
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
32
32
|
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
33
33
|
|
|
@@ -869,11 +869,12 @@ function useAd(path, size) {
|
|
|
869
869
|
const onSlotRender = event => {
|
|
870
870
|
const newRenderEvent = {
|
|
871
871
|
...event,
|
|
872
|
-
...(slot !== null ? slot.getRenderedSize() : null)
|
|
872
|
+
...(slot !== null ? slot.getRenderedSize() : null),
|
|
873
|
+
slot
|
|
873
874
|
};
|
|
874
875
|
setRenderEvent(newRenderEvent);
|
|
875
876
|
if (onRender !== null) {
|
|
876
|
-
onRender(newRenderEvent
|
|
877
|
+
onRender(newRenderEvent);
|
|
877
878
|
}
|
|
878
879
|
const {
|
|
879
880
|
isEmpty = true
|
|
@@ -919,6 +920,9 @@ const propTypes = {
|
|
|
919
920
|
refreshInterval: PropTypes__default["default"].number,
|
|
920
921
|
alwaysRender: PropTypes__default["default"].bool,
|
|
921
922
|
disabled: PropTypes__default["default"].bool,
|
|
923
|
+
shouldKeepSize: PropTypes__default["default"].bool,
|
|
924
|
+
withoutStyle: PropTypes__default["default"].bool,
|
|
925
|
+
withoutMinimumSize: PropTypes__default["default"].bool,
|
|
922
926
|
className: PropTypes__default["default"].string,
|
|
923
927
|
emptyClassName: PropTypes__default["default"].string,
|
|
924
928
|
adClassName: PropTypes__default["default"].string,
|
|
@@ -933,6 +937,9 @@ const defaultProps = {
|
|
|
933
937
|
refreshInterval: null,
|
|
934
938
|
alwaysRender: true,
|
|
935
939
|
disabled: false,
|
|
940
|
+
shouldKeepSize: false,
|
|
941
|
+
withoutStyle: false,
|
|
942
|
+
withoutMinimumSize: false,
|
|
936
943
|
className: null,
|
|
937
944
|
emptyClassName: null,
|
|
938
945
|
adClassName: null,
|
|
@@ -949,6 +956,9 @@ function Ad(_ref) {
|
|
|
949
956
|
refreshInterval,
|
|
950
957
|
alwaysRender,
|
|
951
958
|
disabled,
|
|
959
|
+
shouldKeepSize,
|
|
960
|
+
withoutStyle,
|
|
961
|
+
withoutMinimumSize,
|
|
952
962
|
className,
|
|
953
963
|
emptyClassName,
|
|
954
964
|
adClassName,
|
|
@@ -963,6 +973,7 @@ function Ad(_ref) {
|
|
|
963
973
|
const finalPath = path || (slot !== null ? slot.path || null : null) || (slotName !== null ? slotsPath[slotName] : null) || slotsPath.default || null;
|
|
964
974
|
const finalSize = size || (slot !== null ? slot.size || null : null);
|
|
965
975
|
const finalSizeMapping = sizeMapping || (slot !== null ? slot.sizeMapping || null : null);
|
|
976
|
+
const minimumSize = React.useMemo(() => getMinimumAdSize(finalSizeMapping !== null ? finalSizeMapping.reduce((allSizes, sizeMap) => [...allSizes, sizeMap[1]], [finalSize]) : finalSize), [finalSizeMapping, finalSize]);
|
|
966
977
|
|
|
967
978
|
// Targeting
|
|
968
979
|
const contextTargeting = useAdsTargeting();
|
|
@@ -981,6 +992,27 @@ function Ad(_ref) {
|
|
|
981
992
|
targeting: otherProps || {}
|
|
982
993
|
};
|
|
983
994
|
}, [allTargeting, refreshInterval]);
|
|
995
|
+
const lastRenderedSize = React.useRef(null);
|
|
996
|
+
const wasDisabled = React.useRef(disabled);
|
|
997
|
+
const onAdRender = React.useCallback(event => {
|
|
998
|
+
const {
|
|
999
|
+
isEmpty: newIsEmpty = true
|
|
1000
|
+
} = event || {};
|
|
1001
|
+
const newIsRendered = !newIsEmpty;
|
|
1002
|
+
if (disabled) {
|
|
1003
|
+
wasDisabled.current = true;
|
|
1004
|
+
} else if (!disabled && newIsRendered) {
|
|
1005
|
+
wasDisabled.current = false;
|
|
1006
|
+
}
|
|
1007
|
+
const waitingNextRender = wasDisabled.current && !newIsRendered;
|
|
1008
|
+
const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
1009
|
+
if (onRender !== null) {
|
|
1010
|
+
onRender({
|
|
1011
|
+
...event,
|
|
1012
|
+
keepSize
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}, [onRender, shouldKeepSize, disabled]);
|
|
984
1016
|
|
|
985
1017
|
// Create ad
|
|
986
1018
|
const {
|
|
@@ -989,6 +1021,7 @@ function Ad(_ref) {
|
|
|
989
1021
|
width,
|
|
990
1022
|
height,
|
|
991
1023
|
isEmpty,
|
|
1024
|
+
isRendered,
|
|
992
1025
|
refObserver,
|
|
993
1026
|
slot: slotObject = null
|
|
994
1027
|
} = useAd(finalPath, finalSize, {
|
|
@@ -996,7 +1029,7 @@ function Ad(_ref) {
|
|
|
996
1029
|
targeting: finalAdTargeting.targeting,
|
|
997
1030
|
refreshInterval: finalAdTargeting.refreshInterval,
|
|
998
1031
|
alwaysRender,
|
|
999
|
-
onRender,
|
|
1032
|
+
onRender: onAdRender,
|
|
1000
1033
|
disabled
|
|
1001
1034
|
});
|
|
1002
1035
|
if (slotRef !== null && isFunction__default["default"](slotRef)) {
|
|
@@ -1005,28 +1038,57 @@ function Ad(_ref) {
|
|
|
1005
1038
|
// eslint-disable-next-line no-param-reassign
|
|
1006
1039
|
slotRef.current = slotObject;
|
|
1007
1040
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1041
|
+
if (isRendered) {
|
|
1042
|
+
lastRenderedSize.current = {
|
|
1043
|
+
width,
|
|
1044
|
+
height
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
if (disabled) {
|
|
1048
|
+
wasDisabled.current = true;
|
|
1049
|
+
} else if (!disabled && isRendered) {
|
|
1050
|
+
wasDisabled.current = false;
|
|
1051
|
+
}
|
|
1052
|
+
const waitingNextRender = wasDisabled.current && !isRendered;
|
|
1053
|
+
const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
1011
1054
|
if (id === null) {
|
|
1012
1055
|
return null;
|
|
1013
1056
|
}
|
|
1057
|
+
let adStyle = null;
|
|
1058
|
+
if (isRendered) {
|
|
1059
|
+
adStyle = {
|
|
1060
|
+
width,
|
|
1061
|
+
height
|
|
1062
|
+
};
|
|
1063
|
+
} else if (shouldKeepSize && (disabled || waitingNextRender)) {
|
|
1064
|
+
adStyle = lastRenderedSize.current;
|
|
1065
|
+
} else if (!withoutMinimumSize) {
|
|
1066
|
+
adStyle = minimumSize;
|
|
1067
|
+
}
|
|
1068
|
+
let containerStyle = null;
|
|
1069
|
+
if (adsDisabled) {
|
|
1070
|
+
containerStyle = {
|
|
1071
|
+
display: 'none',
|
|
1072
|
+
visibility: 'hidden'
|
|
1073
|
+
};
|
|
1074
|
+
} else if (isEmpty && !keepSize) {
|
|
1075
|
+
containerStyle = {
|
|
1076
|
+
height: 0,
|
|
1077
|
+
paddingBottom: 0,
|
|
1078
|
+
overflow: 'hidden',
|
|
1079
|
+
opacity: 0
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1014
1082
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1015
1083
|
id: id !== null ? `${id}-container` : null,
|
|
1016
1084
|
className: classNames__default["default"]([className, {
|
|
1017
1085
|
[emptyClassName]: emptyClassName !== null && isEmpty
|
|
1018
1086
|
}]),
|
|
1019
|
-
style:
|
|
1020
|
-
display: 'none',
|
|
1021
|
-
visibility: 'hidden'
|
|
1022
|
-
} : null,
|
|
1087
|
+
style: !withoutStyle ? containerStyle : null,
|
|
1023
1088
|
ref: refObserver,
|
|
1024
1089
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1025
1090
|
className: adClassName,
|
|
1026
|
-
style:
|
|
1027
|
-
width,
|
|
1028
|
-
height
|
|
1029
|
-
},
|
|
1091
|
+
style: adStyle,
|
|
1030
1092
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1031
1093
|
id: id
|
|
1032
1094
|
})
|
package/dist/es.js
CHANGED
|
@@ -3,10 +3,10 @@ import classNames from 'classnames';
|
|
|
3
3
|
import isFunction from 'lodash/isFunction';
|
|
4
4
|
import isObject from 'lodash/isObject';
|
|
5
5
|
import React, { useContext, useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
6
|
-
import debounce from 'lodash/debounce';
|
|
7
6
|
import isArray from 'lodash/isArray';
|
|
8
7
|
import sortBy from 'lodash/sortBy';
|
|
9
8
|
import uniqBy from 'lodash/uniqBy';
|
|
9
|
+
import debounce from 'lodash/debounce';
|
|
10
10
|
import EventEmitter from 'wolfy87-eventemitter';
|
|
11
11
|
import createDebug from 'debug';
|
|
12
12
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -851,11 +851,12 @@ function useAd(path, size) {
|
|
|
851
851
|
const onSlotRender = event => {
|
|
852
852
|
const newRenderEvent = {
|
|
853
853
|
...event,
|
|
854
|
-
...(slot !== null ? slot.getRenderedSize() : null)
|
|
854
|
+
...(slot !== null ? slot.getRenderedSize() : null),
|
|
855
|
+
slot
|
|
855
856
|
};
|
|
856
857
|
setRenderEvent(newRenderEvent);
|
|
857
858
|
if (onRender !== null) {
|
|
858
|
-
onRender(newRenderEvent
|
|
859
|
+
onRender(newRenderEvent);
|
|
859
860
|
}
|
|
860
861
|
const {
|
|
861
862
|
isEmpty = true
|
|
@@ -901,6 +902,9 @@ const propTypes = {
|
|
|
901
902
|
refreshInterval: PropTypes.number,
|
|
902
903
|
alwaysRender: PropTypes.bool,
|
|
903
904
|
disabled: PropTypes.bool,
|
|
905
|
+
shouldKeepSize: PropTypes.bool,
|
|
906
|
+
withoutStyle: PropTypes.bool,
|
|
907
|
+
withoutMinimumSize: PropTypes.bool,
|
|
904
908
|
className: PropTypes.string,
|
|
905
909
|
emptyClassName: PropTypes.string,
|
|
906
910
|
adClassName: PropTypes.string,
|
|
@@ -915,6 +919,9 @@ const defaultProps = {
|
|
|
915
919
|
refreshInterval: null,
|
|
916
920
|
alwaysRender: true,
|
|
917
921
|
disabled: false,
|
|
922
|
+
shouldKeepSize: false,
|
|
923
|
+
withoutStyle: false,
|
|
924
|
+
withoutMinimumSize: false,
|
|
918
925
|
className: null,
|
|
919
926
|
emptyClassName: null,
|
|
920
927
|
adClassName: null,
|
|
@@ -931,6 +938,9 @@ function Ad(_ref) {
|
|
|
931
938
|
refreshInterval,
|
|
932
939
|
alwaysRender,
|
|
933
940
|
disabled,
|
|
941
|
+
shouldKeepSize,
|
|
942
|
+
withoutStyle,
|
|
943
|
+
withoutMinimumSize,
|
|
934
944
|
className,
|
|
935
945
|
emptyClassName,
|
|
936
946
|
adClassName,
|
|
@@ -945,6 +955,7 @@ function Ad(_ref) {
|
|
|
945
955
|
const finalPath = path || (slot !== null ? slot.path || null : null) || (slotName !== null ? slotsPath[slotName] : null) || slotsPath.default || null;
|
|
946
956
|
const finalSize = size || (slot !== null ? slot.size || null : null);
|
|
947
957
|
const finalSizeMapping = sizeMapping || (slot !== null ? slot.sizeMapping || null : null);
|
|
958
|
+
const minimumSize = useMemo(() => getMinimumAdSize(finalSizeMapping !== null ? finalSizeMapping.reduce((allSizes, sizeMap) => [...allSizes, sizeMap[1]], [finalSize]) : finalSize), [finalSizeMapping, finalSize]);
|
|
948
959
|
|
|
949
960
|
// Targeting
|
|
950
961
|
const contextTargeting = useAdsTargeting();
|
|
@@ -963,6 +974,27 @@ function Ad(_ref) {
|
|
|
963
974
|
targeting: otherProps || {}
|
|
964
975
|
};
|
|
965
976
|
}, [allTargeting, refreshInterval]);
|
|
977
|
+
const lastRenderedSize = useRef(null);
|
|
978
|
+
const wasDisabled = useRef(disabled);
|
|
979
|
+
const onAdRender = useCallback(event => {
|
|
980
|
+
const {
|
|
981
|
+
isEmpty: newIsEmpty = true
|
|
982
|
+
} = event || {};
|
|
983
|
+
const newIsRendered = !newIsEmpty;
|
|
984
|
+
if (disabled) {
|
|
985
|
+
wasDisabled.current = true;
|
|
986
|
+
} else if (!disabled && newIsRendered) {
|
|
987
|
+
wasDisabled.current = false;
|
|
988
|
+
}
|
|
989
|
+
const waitingNextRender = wasDisabled.current && !newIsRendered;
|
|
990
|
+
const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
991
|
+
if (onRender !== null) {
|
|
992
|
+
onRender({
|
|
993
|
+
...event,
|
|
994
|
+
keepSize
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}, [onRender, shouldKeepSize, disabled]);
|
|
966
998
|
|
|
967
999
|
// Create ad
|
|
968
1000
|
const {
|
|
@@ -971,6 +1003,7 @@ function Ad(_ref) {
|
|
|
971
1003
|
width,
|
|
972
1004
|
height,
|
|
973
1005
|
isEmpty,
|
|
1006
|
+
isRendered,
|
|
974
1007
|
refObserver,
|
|
975
1008
|
slot: slotObject = null
|
|
976
1009
|
} = useAd(finalPath, finalSize, {
|
|
@@ -978,7 +1011,7 @@ function Ad(_ref) {
|
|
|
978
1011
|
targeting: finalAdTargeting.targeting,
|
|
979
1012
|
refreshInterval: finalAdTargeting.refreshInterval,
|
|
980
1013
|
alwaysRender,
|
|
981
|
-
onRender,
|
|
1014
|
+
onRender: onAdRender,
|
|
982
1015
|
disabled
|
|
983
1016
|
});
|
|
984
1017
|
if (slotRef !== null && isFunction(slotRef)) {
|
|
@@ -987,28 +1020,57 @@ function Ad(_ref) {
|
|
|
987
1020
|
// eslint-disable-next-line no-param-reassign
|
|
988
1021
|
slotRef.current = slotObject;
|
|
989
1022
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1023
|
+
if (isRendered) {
|
|
1024
|
+
lastRenderedSize.current = {
|
|
1025
|
+
width,
|
|
1026
|
+
height
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
if (disabled) {
|
|
1030
|
+
wasDisabled.current = true;
|
|
1031
|
+
} else if (!disabled && isRendered) {
|
|
1032
|
+
wasDisabled.current = false;
|
|
1033
|
+
}
|
|
1034
|
+
const waitingNextRender = wasDisabled.current && !isRendered;
|
|
1035
|
+
const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
|
|
993
1036
|
if (id === null) {
|
|
994
1037
|
return null;
|
|
995
1038
|
}
|
|
1039
|
+
let adStyle = null;
|
|
1040
|
+
if (isRendered) {
|
|
1041
|
+
adStyle = {
|
|
1042
|
+
width,
|
|
1043
|
+
height
|
|
1044
|
+
};
|
|
1045
|
+
} else if (shouldKeepSize && (disabled || waitingNextRender)) {
|
|
1046
|
+
adStyle = lastRenderedSize.current;
|
|
1047
|
+
} else if (!withoutMinimumSize) {
|
|
1048
|
+
adStyle = minimumSize;
|
|
1049
|
+
}
|
|
1050
|
+
let containerStyle = null;
|
|
1051
|
+
if (adsDisabled) {
|
|
1052
|
+
containerStyle = {
|
|
1053
|
+
display: 'none',
|
|
1054
|
+
visibility: 'hidden'
|
|
1055
|
+
};
|
|
1056
|
+
} else if (isEmpty && !keepSize) {
|
|
1057
|
+
containerStyle = {
|
|
1058
|
+
height: 0,
|
|
1059
|
+
paddingBottom: 0,
|
|
1060
|
+
overflow: 'hidden',
|
|
1061
|
+
opacity: 0
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
996
1064
|
return /*#__PURE__*/jsx("div", {
|
|
997
1065
|
id: id !== null ? `${id}-container` : null,
|
|
998
1066
|
className: classNames([className, {
|
|
999
1067
|
[emptyClassName]: emptyClassName !== null && isEmpty
|
|
1000
1068
|
}]),
|
|
1001
|
-
style:
|
|
1002
|
-
display: 'none',
|
|
1003
|
-
visibility: 'hidden'
|
|
1004
|
-
} : null,
|
|
1069
|
+
style: !withoutStyle ? containerStyle : null,
|
|
1005
1070
|
ref: refObserver,
|
|
1006
1071
|
children: /*#__PURE__*/jsx("div", {
|
|
1007
1072
|
className: adClassName,
|
|
1008
|
-
style:
|
|
1009
|
-
width,
|
|
1010
|
-
height
|
|
1011
|
-
},
|
|
1073
|
+
style: adStyle,
|
|
1012
1074
|
children: /*#__PURE__*/jsx("div", {
|
|
1013
1075
|
id: id
|
|
1014
1076
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
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": "979144c5a475f77dbfb74a4f351166fec318c6c2",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@folklore/hooks": "^0.0.41",
|
|
56
56
|
"@folklore/tracking": "^0.0.16",
|