@folklore/ads 0.0.104 → 0.0.106

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 +13 -25
  2. package/dist/es.js +13 -25
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -1203,7 +1203,8 @@ function Ad(_ref) {
1203
1203
  const {
1204
1204
  slots = null,
1205
1205
  slotsPath = null,
1206
- viewport: contextViewport = null
1206
+ viewport: contextViewport = null,
1207
+ ads
1207
1208
  } = useAdsContext();
1208
1209
  const {
1209
1210
  default: defaultSlotPath = null
@@ -1244,29 +1245,23 @@ function Ad(_ref) {
1244
1245
  } = allTargeting || {};
1245
1246
  return {
1246
1247
  refreshInterval: refreshAds !== null && refreshAds === 'inactive' ? null : providedRefreshInterval,
1247
- disabled: providedDisabled || targetingDisabled,
1248
+ disabled: providedDisabled || targetingDisabled || ads.isDisabled(),
1248
1249
  viewport: providedViewport || contextViewport || targetingViewport,
1249
1250
  targeting: otherProps || {}
1250
1251
  };
1251
- }, [slotName, contextTargeting, providedTargeting, providedRefreshInterval, providedDisabled, providedViewport, contextViewport]);
1252
- const lastRenderedSize = React.useRef(null);
1253
- const wasDisabled = React.useRef(disabled);
1254
- React.useEffect(() => {}, []);
1252
+ }, [slotName, contextTargeting, providedTargeting, ads, providedRefreshInterval, providedDisabled, providedViewport, contextViewport]);
1253
+ const [lastRenderedSize, setLastRenderedSize] = React.useState(null);
1255
1254
  const onAdRender = React.useCallback(event => {
1256
1255
  const {
1257
1256
  isEmpty: newIsEmpty = true,
1258
1257
  width: newWidth,
1259
1258
  height: newHeight
1260
1259
  } = event || {};
1261
- if (disabled) {
1262
- wasDisabled.current = true;
1263
- } else if (!disabled && !newIsEmpty) {
1264
- wasDisabled.current = false;
1265
- }
1266
- lastRenderedSize.current = !newIsEmpty ? {
1260
+ const isRendered = !newIsEmpty;
1261
+ setLastRenderedSize(isRendered ? {
1267
1262
  width: newWidth,
1268
1263
  height: newHeight
1269
- } : null;
1264
+ } : null);
1270
1265
  if (onRender !== null) {
1271
1266
  onRender(event);
1272
1267
  }
@@ -1287,7 +1282,6 @@ function Ad(_ref) {
1287
1282
 
1288
1283
  // Create ad
1289
1284
  const {
1290
- disabled: adsDisabled,
1291
1285
  id,
1292
1286
  width,
1293
1287
  height,
@@ -1317,13 +1311,7 @@ function Ad(_ref) {
1317
1311
  // eslint-disable-next-line no-param-reassign
1318
1312
  slotRef.current = slotObject;
1319
1313
  }
1320
- if (disabled) {
1321
- wasDisabled.current = true;
1322
- } else if (!disabled && isRendered) {
1323
- wasDisabled.current = false;
1324
- }
1325
- const waitingNextRender = wasDisabled.current && !isRendered;
1326
- const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
1314
+ const keepSize = shouldKeepSize && lastRenderedSize !== null && !isRendered;
1327
1315
  if (id === null && !keepSize) {
1328
1316
  return null;
1329
1317
  }
@@ -1333,13 +1321,13 @@ function Ad(_ref) {
1333
1321
  width,
1334
1322
  height
1335
1323
  } : null;
1336
- } else if (shouldKeepSize && (disabled || waitingNextRender)) {
1337
- adStyle = lastRenderedSize.current;
1324
+ } else if (keepSize) {
1325
+ adStyle = lastRenderedSize;
1338
1326
  } else if (!withoutMinimumSize) {
1339
1327
  adStyle = minimumSize;
1340
1328
  }
1341
1329
  let containerStyle = null;
1342
- if (adsDisabled) {
1330
+ if (disabled) {
1343
1331
  containerStyle = {
1344
1332
  display: 'none',
1345
1333
  visibility: 'hidden'
@@ -1355,7 +1343,7 @@ function Ad(_ref) {
1355
1343
  return /*#__PURE__*/jsxRuntime.jsx("div", {
1356
1344
  id: id !== null ? `${id}-container` : null,
1357
1345
  className: classNames([className, {
1358
- [emptyClassName]: emptyClassName !== null && isEmpty
1346
+ [emptyClassName]: emptyClassName !== null && isEmpty && !keepSize
1359
1347
  }]),
1360
1348
  style: !withoutStyle ? containerStyle : null,
1361
1349
  ref: refObserver,
package/dist/es.js CHANGED
@@ -1201,7 +1201,8 @@ function Ad(_ref) {
1201
1201
  const {
1202
1202
  slots = null,
1203
1203
  slotsPath = null,
1204
- viewport: contextViewport = null
1204
+ viewport: contextViewport = null,
1205
+ ads
1205
1206
  } = useAdsContext();
1206
1207
  const {
1207
1208
  default: defaultSlotPath = null
@@ -1242,29 +1243,23 @@ function Ad(_ref) {
1242
1243
  } = allTargeting || {};
1243
1244
  return {
1244
1245
  refreshInterval: refreshAds !== null && refreshAds === 'inactive' ? null : providedRefreshInterval,
1245
- disabled: providedDisabled || targetingDisabled,
1246
+ disabled: providedDisabled || targetingDisabled || ads.isDisabled(),
1246
1247
  viewport: providedViewport || contextViewport || targetingViewport,
1247
1248
  targeting: otherProps || {}
1248
1249
  };
1249
- }, [slotName, contextTargeting, providedTargeting, providedRefreshInterval, providedDisabled, providedViewport, contextViewport]);
1250
- const lastRenderedSize = useRef(null);
1251
- const wasDisabled = useRef(disabled);
1252
- useEffect(() => {}, []);
1250
+ }, [slotName, contextTargeting, providedTargeting, ads, providedRefreshInterval, providedDisabled, providedViewport, contextViewport]);
1251
+ const [lastRenderedSize, setLastRenderedSize] = useState(null);
1253
1252
  const onAdRender = useCallback(event => {
1254
1253
  const {
1255
1254
  isEmpty: newIsEmpty = true,
1256
1255
  width: newWidth,
1257
1256
  height: newHeight
1258
1257
  } = event || {};
1259
- if (disabled) {
1260
- wasDisabled.current = true;
1261
- } else if (!disabled && !newIsEmpty) {
1262
- wasDisabled.current = false;
1263
- }
1264
- lastRenderedSize.current = !newIsEmpty ? {
1258
+ const isRendered = !newIsEmpty;
1259
+ setLastRenderedSize(isRendered ? {
1265
1260
  width: newWidth,
1266
1261
  height: newHeight
1267
- } : null;
1262
+ } : null);
1268
1263
  if (onRender !== null) {
1269
1264
  onRender(event);
1270
1265
  }
@@ -1285,7 +1280,6 @@ function Ad(_ref) {
1285
1280
 
1286
1281
  // Create ad
1287
1282
  const {
1288
- disabled: adsDisabled,
1289
1283
  id,
1290
1284
  width,
1291
1285
  height,
@@ -1315,13 +1309,7 @@ function Ad(_ref) {
1315
1309
  // eslint-disable-next-line no-param-reassign
1316
1310
  slotRef.current = slotObject;
1317
1311
  }
1318
- if (disabled) {
1319
- wasDisabled.current = true;
1320
- } else if (!disabled && isRendered) {
1321
- wasDisabled.current = false;
1322
- }
1323
- const waitingNextRender = wasDisabled.current && !isRendered;
1324
- const keepSize = shouldKeepSize && (disabled || waitingNextRender) && lastRenderedSize.current !== null;
1312
+ const keepSize = shouldKeepSize && lastRenderedSize !== null && !isRendered;
1325
1313
  if (id === null && !keepSize) {
1326
1314
  return null;
1327
1315
  }
@@ -1331,13 +1319,13 @@ function Ad(_ref) {
1331
1319
  width,
1332
1320
  height
1333
1321
  } : null;
1334
- } else if (shouldKeepSize && (disabled || waitingNextRender)) {
1335
- adStyle = lastRenderedSize.current;
1322
+ } else if (keepSize) {
1323
+ adStyle = lastRenderedSize;
1336
1324
  } else if (!withoutMinimumSize) {
1337
1325
  adStyle = minimumSize;
1338
1326
  }
1339
1327
  let containerStyle = null;
1340
- if (adsDisabled) {
1328
+ if (disabled) {
1341
1329
  containerStyle = {
1342
1330
  display: 'none',
1343
1331
  visibility: 'hidden'
@@ -1353,7 +1341,7 @@ function Ad(_ref) {
1353
1341
  return /*#__PURE__*/jsx("div", {
1354
1342
  id: id !== null ? `${id}-container` : null,
1355
1343
  className: classNames([className, {
1356
- [emptyClassName]: emptyClassName !== null && isEmpty
1344
+ [emptyClassName]: emptyClassName !== null && isEmpty && !keepSize
1357
1345
  }]),
1358
1346
  style: !withoutStyle ? containerStyle : null,
1359
1347
  ref: refObserver,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/ads",
3
- "version": "0.0.104",
3
+ "version": "0.0.106",
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": "2d8bb885c7367b26f1b384e30ef8fe9c2ccfee08",
53
+ "gitHead": "5dcc85d03e017aecc2d19a4fa174382ece4a3225",
54
54
  "dependencies": {
55
55
  "@folklore/hooks": "^0.0.72",
56
56
  "@folklore/tracking": "^0.0.29",