@folklore/ads 0.0.125 → 0.0.128
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/index.d.ts +335 -0
- package/dist/{es.js → index.js} +28 -26
- package/package.json +20 -16
- package/dist/cjs.js +0 -1316
- package/types/Ad.d.ts +0 -30
- package/types/AdSlot.d.ts +0 -57
- package/types/AdsContext.d.ts +0 -37
- package/types/AdsManager.d.ts +0 -72
- package/types/AdsTargetingContext.d.ts +0 -11
- package/types/RichAd.d.ts +0 -7
- package/types/__tests__/utils.test.d.ts +0 -1
- package/types/defaults.d.ts +0 -3
- package/types/index.d.ts +0 -13
- package/types/propTypes.d.ts +0 -7
- package/types/types.d.ts +0 -34
- package/types/useAd.d.ts +0 -30
- package/types/useAdsTracking.d.ts +0 -2
- package/types/useRichAd.d.ts +0 -6
- package/types/utils.d.ts +0 -10
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { Ref, ReactNode, ElementType } from 'react';
|
|
4
|
+
import { EventEmitter } from '@folklore/events';
|
|
5
|
+
|
|
6
|
+
declare const adPath: any;
|
|
7
|
+
declare const adSize: any;
|
|
8
|
+
declare const adSizeMapping: any;
|
|
9
|
+
declare const adViewports: any;
|
|
10
|
+
declare const adSlot: any;
|
|
11
|
+
declare const adSlots: any;
|
|
12
|
+
declare const adTargeting: any;
|
|
13
|
+
|
|
14
|
+
declare const propTypes_d_adPath: typeof adPath;
|
|
15
|
+
declare const propTypes_d_adSize: typeof adSize;
|
|
16
|
+
declare const propTypes_d_adSizeMapping: typeof adSizeMapping;
|
|
17
|
+
declare const propTypes_d_adSlot: typeof adSlot;
|
|
18
|
+
declare const propTypes_d_adSlots: typeof adSlots;
|
|
19
|
+
declare const propTypes_d_adTargeting: typeof adTargeting;
|
|
20
|
+
declare const propTypes_d_adViewports: typeof adViewports;
|
|
21
|
+
declare namespace propTypes_d {
|
|
22
|
+
export {
|
|
23
|
+
propTypes_d_adPath as adPath,
|
|
24
|
+
propTypes_d_adSize as adSize,
|
|
25
|
+
propTypes_d_adSizeMapping as adSizeMapping,
|
|
26
|
+
propTypes_d_adSlot as adSlot,
|
|
27
|
+
propTypes_d_adSlots as adSlots,
|
|
28
|
+
propTypes_d_adTargeting as adTargeting,
|
|
29
|
+
propTypes_d_adViewports as adViewports,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type AdSize = googletag.SingleSize;
|
|
34
|
+
type Viewport = googletag.SingleSizeArray;
|
|
35
|
+
type AdSizeMapping = googletag.SizeMapping;
|
|
36
|
+
interface Size {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}
|
|
40
|
+
interface Viewports {
|
|
41
|
+
[name: string]: Viewport;
|
|
42
|
+
}
|
|
43
|
+
interface SlotDefinition {
|
|
44
|
+
sizeMapping?: Record<string, AdSize[]> | boolean | null | AdSizeMapping[] | null;
|
|
45
|
+
size?: AdSize[];
|
|
46
|
+
path?: string | null;
|
|
47
|
+
}
|
|
48
|
+
interface Slot extends SlotDefinition {
|
|
49
|
+
sizeMapping?: AdSizeMapping[] | null;
|
|
50
|
+
}
|
|
51
|
+
interface Slots {
|
|
52
|
+
[name: string]: Slot;
|
|
53
|
+
}
|
|
54
|
+
interface SlotsDefinition {
|
|
55
|
+
[name: string]: SlotDefinition;
|
|
56
|
+
}
|
|
57
|
+
interface AdsTargeting {
|
|
58
|
+
refreshAds?: 'inactive' | false | null | number;
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
viewport?: string | null;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
interface RichAdType {
|
|
64
|
+
type: string;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type RenderEvent = googletag.events.SlotRenderEndedEvent & {
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
isFluid: boolean;
|
|
72
|
+
slot: AdSlot;
|
|
73
|
+
};
|
|
74
|
+
interface AdSlotOptions$1 {
|
|
75
|
+
sizeMapping?: null | AdSizeMapping[];
|
|
76
|
+
targeting?: AdsTargeting;
|
|
77
|
+
categoryExclusions?: Array<string>;
|
|
78
|
+
visible?: boolean;
|
|
79
|
+
}
|
|
80
|
+
type AddSlotEvents = {
|
|
81
|
+
render: {
|
|
82
|
+
event: googletag.events.SlotRenderEndedEvent;
|
|
83
|
+
slot: AdSlot;
|
|
84
|
+
};
|
|
85
|
+
visible: {
|
|
86
|
+
visible: boolean;
|
|
87
|
+
slot: AdSlot;
|
|
88
|
+
};
|
|
89
|
+
destroy: AdSlot;
|
|
90
|
+
};
|
|
91
|
+
declare class AdSlot extends EventEmitter<AddSlotEvents> {
|
|
92
|
+
options: AdSlotOptions$1;
|
|
93
|
+
elementId: string;
|
|
94
|
+
adPath: string;
|
|
95
|
+
adSize: string | Array<string>;
|
|
96
|
+
visible: boolean;
|
|
97
|
+
wasVisible: boolean;
|
|
98
|
+
adSlot: googletag.Slot | null;
|
|
99
|
+
rendered: boolean;
|
|
100
|
+
displayed: boolean;
|
|
101
|
+
viewable: boolean;
|
|
102
|
+
renderEvent: googletag.events.SlotRenderEndedEvent;
|
|
103
|
+
refreshDisabled: boolean;
|
|
104
|
+
destroyed: boolean;
|
|
105
|
+
constructor(id: any, path: any, size: any, opts?: {});
|
|
106
|
+
updateAdSlot(): void;
|
|
107
|
+
setAdSlot(slot: any): this;
|
|
108
|
+
setRenderEvent(event: googletag.events.SlotRenderEndedEvent): this;
|
|
109
|
+
setViewable(viewable: any): void;
|
|
110
|
+
setDisplayed(displayed: any): this;
|
|
111
|
+
setVisible(visible: any): this;
|
|
112
|
+
setRefreshDisabled(): void;
|
|
113
|
+
setTargeting(targeting: any): void;
|
|
114
|
+
destroy(): void;
|
|
115
|
+
getElementId(): string;
|
|
116
|
+
getAdSlot(): googletag.Slot;
|
|
117
|
+
getAdPath(): string;
|
|
118
|
+
getAdSize(): string | string[];
|
|
119
|
+
getTargeting(): AdsTargeting;
|
|
120
|
+
isVisible(): boolean;
|
|
121
|
+
isDefined(): boolean;
|
|
122
|
+
isDisplayed(): boolean;
|
|
123
|
+
isViewable(): boolean;
|
|
124
|
+
isRendered(): boolean;
|
|
125
|
+
isRefreshDisabled(): boolean;
|
|
126
|
+
isDestroyed(): boolean;
|
|
127
|
+
isEmpty(): boolean;
|
|
128
|
+
canBeDisplayed(): boolean;
|
|
129
|
+
getRenderedSize(): {
|
|
130
|
+
width: string | number;
|
|
131
|
+
height: string | number;
|
|
132
|
+
isFluid: boolean;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
interface AdProps {
|
|
137
|
+
slot: string;
|
|
138
|
+
path?: string | null;
|
|
139
|
+
size?: AdSize[] | null;
|
|
140
|
+
sizeMapping?: AdSizeMapping[] | null;
|
|
141
|
+
viewport?: string | null;
|
|
142
|
+
targeting?: AdsTargeting | null;
|
|
143
|
+
refreshInterval?: number | null;
|
|
144
|
+
alwaysRender?: boolean;
|
|
145
|
+
disabled?: boolean;
|
|
146
|
+
disableTracking?: boolean;
|
|
147
|
+
shouldKeepSize?: boolean;
|
|
148
|
+
withoutStyle?: boolean;
|
|
149
|
+
withoutMinimumSize?: boolean;
|
|
150
|
+
withReactId?: boolean;
|
|
151
|
+
className?: string | null;
|
|
152
|
+
emptyClassName?: string | null;
|
|
153
|
+
adClassName?: string | null;
|
|
154
|
+
richAdClassName?: string | null;
|
|
155
|
+
richAdIframeClassName?: string | null;
|
|
156
|
+
onRender?: ((event: RenderEvent) => void) | null;
|
|
157
|
+
onDestroy?: ((slot: AdSlot) => void) | null;
|
|
158
|
+
onRichAd?: ((richAd: RichAdType) => void) | null;
|
|
159
|
+
slotRef?: Ref<AdSlot> | null;
|
|
160
|
+
}
|
|
161
|
+
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): react_jsx_runtime.JSX.Element;
|
|
162
|
+
|
|
163
|
+
interface RichAdProps {
|
|
164
|
+
richAd: RichAdType;
|
|
165
|
+
[key: string]: unknown;
|
|
166
|
+
}
|
|
167
|
+
declare function RichAd({ richAd, ...props }: RichAdProps): react_jsx_runtime.JSX.Element;
|
|
168
|
+
|
|
169
|
+
declare global {
|
|
170
|
+
interface Window {
|
|
171
|
+
googletag?: typeof googletag;
|
|
172
|
+
refreshDisabledLineItems?: number[];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
interface AdSlotOptions extends AdSlotOptions$1 {
|
|
176
|
+
id?: string;
|
|
177
|
+
}
|
|
178
|
+
type AdsManagerEvents = {
|
|
179
|
+
ready: void;
|
|
180
|
+
'destroy:slot': AdSlot;
|
|
181
|
+
};
|
|
182
|
+
declare class AdsManager extends EventEmitter<AdsManagerEvents> {
|
|
183
|
+
static ID_PREFIX: string;
|
|
184
|
+
disabled: boolean;
|
|
185
|
+
personnalizedAdsDisabled: boolean;
|
|
186
|
+
ready: boolean;
|
|
187
|
+
enabled: boolean;
|
|
188
|
+
googletag: typeof googletag;
|
|
189
|
+
slots: AdSlot[];
|
|
190
|
+
index: number;
|
|
191
|
+
options: {
|
|
192
|
+
disabled: boolean;
|
|
193
|
+
disablePersonnalizedAds: boolean;
|
|
194
|
+
disableSingleRequest: boolean;
|
|
195
|
+
disableLazyLoad: boolean;
|
|
196
|
+
disableVideoAds: boolean;
|
|
197
|
+
autoInit: boolean;
|
|
198
|
+
mobileScaling?: number;
|
|
199
|
+
renderMarginPercent?: number;
|
|
200
|
+
fetchMarginPercent?: number;
|
|
201
|
+
};
|
|
202
|
+
static getArticleTargeting(article: any): {
|
|
203
|
+
title: any;
|
|
204
|
+
slug: any;
|
|
205
|
+
postID: any;
|
|
206
|
+
categories: any;
|
|
207
|
+
authors: any;
|
|
208
|
+
sponsors: any;
|
|
209
|
+
GoogleSafeTargeting: any;
|
|
210
|
+
};
|
|
211
|
+
static getSectionTargeting(section: any): {
|
|
212
|
+
section: any;
|
|
213
|
+
};
|
|
214
|
+
static getIndexTargeting(index: any): {
|
|
215
|
+
index: any;
|
|
216
|
+
};
|
|
217
|
+
static getIndexItemTargeting(index: any, item: any): {
|
|
218
|
+
[index.id]: any[];
|
|
219
|
+
};
|
|
220
|
+
constructor(opts?: {});
|
|
221
|
+
createAdId(): string;
|
|
222
|
+
init(): void;
|
|
223
|
+
initGpt(): void;
|
|
224
|
+
onSlotRenderEnded(event: googletag.events.SlotRenderEndedEvent): void;
|
|
225
|
+
onSlotImpressionViewable(event: any): void;
|
|
226
|
+
onSlotVisibleChange({ visible, slot }: {
|
|
227
|
+
visible: any;
|
|
228
|
+
slot: any;
|
|
229
|
+
}): void;
|
|
230
|
+
isReady(): boolean;
|
|
231
|
+
isDisabled(): boolean;
|
|
232
|
+
setDisabled(disabled: any): void;
|
|
233
|
+
disablePersonnalizedAds(disablePersonnalizedAds: any): void;
|
|
234
|
+
createSlot(path: string, size: AdSize, opts?: AdSlotOptions): AdSlot;
|
|
235
|
+
defineSlot(slot: any): void;
|
|
236
|
+
displaySlots(): boolean;
|
|
237
|
+
displaySlot(slot: any): void;
|
|
238
|
+
callDisplaySlot(slot: any): void;
|
|
239
|
+
destroySlot(id: any): void;
|
|
240
|
+
refreshSlot(id: any): void;
|
|
241
|
+
refreshSlots(ids: any): void;
|
|
242
|
+
refreshAllSlots(): void;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
interface AdsContextType {
|
|
246
|
+
ready: boolean;
|
|
247
|
+
ads?: AdsManager;
|
|
248
|
+
viewports?: Viewports;
|
|
249
|
+
viewport?: string | null;
|
|
250
|
+
slots?: Slots;
|
|
251
|
+
slotsPath?: Record<string, string>;
|
|
252
|
+
trackingDisabled?: boolean;
|
|
253
|
+
richAdComponents?: Record<string, ElementType>;
|
|
254
|
+
}
|
|
255
|
+
declare const useAdsContext: () => AdsContextType;
|
|
256
|
+
interface AdsProviderProps {
|
|
257
|
+
children: ReactNode;
|
|
258
|
+
defaultSlotPath?: string | null;
|
|
259
|
+
slotsPath?: Record<string, string> | null;
|
|
260
|
+
disableSingleRequest?: boolean;
|
|
261
|
+
disableVideoAds?: boolean;
|
|
262
|
+
disableLazyLoad?: boolean;
|
|
263
|
+
autoInit?: boolean;
|
|
264
|
+
resizeDebounceDelay?: number;
|
|
265
|
+
refreshOnResize?: boolean;
|
|
266
|
+
mobileScaling?: number;
|
|
267
|
+
renderMarginPercent?: number;
|
|
268
|
+
fetchMarginPercent?: number;
|
|
269
|
+
viewport?: string | null;
|
|
270
|
+
viewports?: Viewports;
|
|
271
|
+
slots?: SlotsDefinition;
|
|
272
|
+
richAdComponents?: Record<string, ElementType> | null;
|
|
273
|
+
disabled?: boolean;
|
|
274
|
+
disableTracking?: boolean;
|
|
275
|
+
}
|
|
276
|
+
declare function AdsProvider({ children, defaultSlotPath, slotsPath, disableSingleRequest, disableVideoAds, disableLazyLoad, autoInit, resizeDebounceDelay, refreshOnResize, mobileScaling, renderMarginPercent, fetchMarginPercent, viewport, viewports, slots, richAdComponents, disabled, disableTracking, }: AdsProviderProps): react_jsx_runtime.JSX.Element;
|
|
277
|
+
|
|
278
|
+
declare const useAdsTargeting: () => AdsTargeting | null;
|
|
279
|
+
interface AdsTargetingProviderProps {
|
|
280
|
+
children: ReactNode;
|
|
281
|
+
targeting?: AdsTargeting;
|
|
282
|
+
replace?: boolean;
|
|
283
|
+
}
|
|
284
|
+
declare function AdsTargetingProvider({ children, targeting, replace, }: AdsTargetingProviderProps): react_jsx_runtime.JSX.Element;
|
|
285
|
+
|
|
286
|
+
declare const viewports: Viewports;
|
|
287
|
+
declare const slots: SlotsDefinition;
|
|
288
|
+
|
|
289
|
+
interface UseAdOptions {
|
|
290
|
+
id?: string;
|
|
291
|
+
sizeMapping?: AdSizeMapping[] | null;
|
|
292
|
+
viewport?: string | null;
|
|
293
|
+
targeting?: AdsTargeting | null;
|
|
294
|
+
categoryExclusions?: string[] | null;
|
|
295
|
+
refreshInterval?: number | null;
|
|
296
|
+
alwaysRender?: boolean;
|
|
297
|
+
onRender?: (event: RenderEvent) => void | null;
|
|
298
|
+
onDestroy?: (slot: AdSlot) => void | null;
|
|
299
|
+
disabled?: boolean;
|
|
300
|
+
disableTracking?: boolean;
|
|
301
|
+
rootMargin?: string;
|
|
302
|
+
}
|
|
303
|
+
declare function useAd(path: string, size: any, { id, sizeMapping, viewport, targeting, categoryExclusions, refreshInterval, alwaysRender, onRender, onDestroy, disabled, disableTracking, rootMargin, }?: UseAdOptions): {
|
|
304
|
+
width: string | number;
|
|
305
|
+
height: string | number;
|
|
306
|
+
isFluid: boolean;
|
|
307
|
+
refObserver: react.RefObject<HTMLElement>;
|
|
308
|
+
slot: AdSlot;
|
|
309
|
+
disabled: boolean;
|
|
310
|
+
id: string;
|
|
311
|
+
isRendered: boolean;
|
|
312
|
+
isEmpty: boolean;
|
|
313
|
+
isVisible: boolean;
|
|
314
|
+
renderEvent: any;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
declare function useAdsTracking(): (action: string, slot?: AdSlot, renderEvent?: RenderEvent) => void;
|
|
318
|
+
|
|
319
|
+
interface UseRichAdOptions {
|
|
320
|
+
onRichAd?: (richAd: RichAdType) => void | null;
|
|
321
|
+
}
|
|
322
|
+
declare function useRichAd(containerRef: any, id: string, opts?: UseRichAdOptions): any;
|
|
323
|
+
|
|
324
|
+
declare function normalizeAdSizes(size: any): AdSize[];
|
|
325
|
+
declare function getAdSizes(sizes: any): AdSize[];
|
|
326
|
+
declare function getMinimumAdSize(sizes: any): Size;
|
|
327
|
+
declare function sizeFitsInViewport(size: AdSize, viewport: Viewport): boolean;
|
|
328
|
+
declare function getSortedViewports(viewports: Viewports): any;
|
|
329
|
+
declare function buildSizeMappingFromViewports(sizeMapping: any, viewports: any): AdSizeMapping[];
|
|
330
|
+
declare function buildSizeMappingFromSizes(sizes: any, viewports: any): AdSizeMapping[];
|
|
331
|
+
declare function getSizeMappingFromSlot({ size: allSizes, sizeMapping }: Slot | SlotDefinition, viewports: Viewports): AdSizeMapping[] | null;
|
|
332
|
+
declare function getSizeFromSizeMapping(sizeMapping: any): AdSize[] | null;
|
|
333
|
+
|
|
334
|
+
export { Ad, AdSlot, AdsManager, AdsProvider, AdsTargetingProvider, propTypes_d as PropTypes, RichAd, buildSizeMappingFromSizes, buildSizeMappingFromViewports, getAdSizes, getMinimumAdSize, getSizeFromSizeMapping, getSizeMappingFromSlot, getSortedViewports, normalizeAdSizes, sizeFitsInViewport, slots, useAd, useAdsContext, useAdsTargeting, useAdsTracking, useRichAd, viewports };
|
|
335
|
+
export type { AdSize, AdSizeMapping, AdsTargeting, RichAdType, Size, Slot, SlotDefinition, Slots, SlotsDefinition, Viewport, Viewports };
|
package/dist/{es.js → index.js}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import
|
|
3
|
+
import { useState, useRef, useMemo, useEffect, useContext, createContext, useCallback, useId } from 'react';
|
|
4
4
|
import isArray from 'lodash/isArray';
|
|
5
5
|
import isObject from 'lodash/isObject';
|
|
6
6
|
import sortBy from 'lodash/sortBy';
|
|
7
7
|
import uniqBy from 'lodash/uniqBy';
|
|
8
8
|
import debounce from 'lodash/debounce';
|
|
9
|
+
import { EventEmitter } from '@folklore/events';
|
|
9
10
|
import createDebug from 'debug';
|
|
10
|
-
import EventEmitter from 'wolfy87-eventemitter';
|
|
11
11
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
12
12
|
import { getComponentFromName } from '@folklore/utils';
|
|
13
13
|
import { useIntersectionObserver, useWindowEvent } from '@folklore/hooks';
|
|
@@ -50,7 +50,7 @@ function getAdSizes(sizes) {
|
|
|
50
50
|
return uniqBy(sizes, size => isArray(size) ? size.join('x') : size);
|
|
51
51
|
}
|
|
52
52
|
function getMinimumAdSize(sizes) {
|
|
53
|
-
return getAdSizes(sizes).filter(size => size !== 'fluid').reduce((minimumSize, size) => ({
|
|
53
|
+
return getAdSizes(sizes).filter(size => size !== 'fluid' && !(isArray(size) && size[0] === 'fluid')).reduce((minimumSize, size) => ({
|
|
54
54
|
width: Math.min(minimumSize.width, size[0]),
|
|
55
55
|
height: Math.min(minimumSize.height, size[1])
|
|
56
56
|
}), {
|
|
@@ -59,7 +59,8 @@ function getMinimumAdSize(sizes) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
function sizeFitsInViewport(size, viewport) {
|
|
62
|
-
|
|
62
|
+
const isFluid = size === 'fluid' || isArray(size) && size[0] === 'fluid';
|
|
63
|
+
return isFluid && viewport[0] > 600 || !isFluid && (viewport[0] === 0 || size[0] <= viewport[0]) && (viewport[1] === 0 || size[1] <= viewport[1]);
|
|
63
64
|
}
|
|
64
65
|
function getSortedViewports(viewports) {
|
|
65
66
|
return sortBy(Object.keys(viewports).map(name => ({
|
|
@@ -176,7 +177,10 @@ class AdSlot extends EventEmitter {
|
|
|
176
177
|
setRenderEvent(event) {
|
|
177
178
|
this.renderEvent = event;
|
|
178
179
|
this.rendered = true;
|
|
179
|
-
this.emit('render',
|
|
180
|
+
this.emit('render', {
|
|
181
|
+
event,
|
|
182
|
+
slot: this
|
|
183
|
+
});
|
|
180
184
|
return this;
|
|
181
185
|
}
|
|
182
186
|
setViewable(viewable) {
|
|
@@ -186,14 +190,15 @@ class AdSlot extends EventEmitter {
|
|
|
186
190
|
this.displayed = displayed;
|
|
187
191
|
return this;
|
|
188
192
|
}
|
|
189
|
-
|
|
190
|
-
// eslint-disable-next-line
|
|
191
193
|
setVisible(visible) {
|
|
192
194
|
this.visible = visible;
|
|
193
195
|
if (!this.wasVisible && visible) {
|
|
194
196
|
this.wasVisible = visible;
|
|
195
197
|
}
|
|
196
|
-
this.emit('visible',
|
|
198
|
+
this.emit('visible', {
|
|
199
|
+
visible,
|
|
200
|
+
slot: this
|
|
201
|
+
});
|
|
197
202
|
return this;
|
|
198
203
|
}
|
|
199
204
|
setRefreshDisabled() {
|
|
@@ -281,7 +286,6 @@ class AdSlot extends EventEmitter {
|
|
|
281
286
|
}
|
|
282
287
|
}
|
|
283
288
|
|
|
284
|
-
/* globals refreshDisabledLineItems: [] */
|
|
285
289
|
const debug$1 = createDebug('folklore:ads');
|
|
286
290
|
class AdsManager extends EventEmitter {
|
|
287
291
|
// static index = 0;
|
|
@@ -455,7 +459,7 @@ class AdsManager extends EventEmitter {
|
|
|
455
459
|
if (event.isEmpty) {
|
|
456
460
|
debug$1('Render ended for slot #%s(%s). Slot is empty.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
|
|
457
461
|
} else {
|
|
458
|
-
debug$1('Render ended for slot #%s(%s) with size %s.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath(), size !== null ? size.join('x') : '-');
|
|
462
|
+
debug$1('Render ended for slot #%s(%s) with size %s.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath(), size !== null && isArray(size) ? size.join('x') : '-');
|
|
459
463
|
}
|
|
460
464
|
}
|
|
461
465
|
onSlotImpressionViewable(event) {
|
|
@@ -468,9 +472,10 @@ class AdsManager extends EventEmitter {
|
|
|
468
472
|
}
|
|
469
473
|
debug$1('Impression viewable for slot #%s(%s).', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
|
|
470
474
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
475
|
+
onSlotVisibleChange({
|
|
476
|
+
visible,
|
|
477
|
+
slot
|
|
478
|
+
}) {
|
|
474
479
|
debug$1('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
|
|
475
480
|
}
|
|
476
481
|
isReady() {
|
|
@@ -544,8 +549,6 @@ class AdsManager extends EventEmitter {
|
|
|
544
549
|
displaySlot(slot) {
|
|
545
550
|
this.callDisplaySlot(slot);
|
|
546
551
|
}
|
|
547
|
-
|
|
548
|
-
/* eslint-disable */
|
|
549
552
|
callDisplaySlot(slot) {
|
|
550
553
|
const {
|
|
551
554
|
googletag
|
|
@@ -564,8 +567,6 @@ class AdsManager extends EventEmitter {
|
|
|
564
567
|
slot.setDisplayed(true);
|
|
565
568
|
});
|
|
566
569
|
}
|
|
567
|
-
/* eslint-enable */
|
|
568
|
-
|
|
569
570
|
destroySlot(id) {
|
|
570
571
|
const {
|
|
571
572
|
googletag
|
|
@@ -675,8 +676,7 @@ const slots = {
|
|
|
675
676
|
}
|
|
676
677
|
};
|
|
677
678
|
|
|
678
|
-
|
|
679
|
-
const AdsContext = /*#__PURE__*/React.createContext({
|
|
679
|
+
const AdsContext = /*#__PURE__*/createContext({
|
|
680
680
|
ready: false
|
|
681
681
|
});
|
|
682
682
|
const useAdsContext = () => useContext(AdsContext);
|
|
@@ -813,7 +813,6 @@ function AdsTargetingProvider({
|
|
|
813
813
|
});
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
-
/* eslint-disable react/jsx-props-no-spreading */
|
|
817
816
|
function RichAd({
|
|
818
817
|
richAd,
|
|
819
818
|
...props
|
|
@@ -835,7 +834,7 @@ function RichAd({
|
|
|
835
834
|
function useAdsTracking() {
|
|
836
835
|
const tracking = useTracking() || null;
|
|
837
836
|
const trackEvent = useCallback((action, slot = null, renderEvent = null) => {
|
|
838
|
-
if (tracking !== null && typeof tracking.trackAd
|
|
837
|
+
if (tracking !== null && typeof tracking.trackAd === 'undefined') {
|
|
839
838
|
tracking.trackAd(action, slot, renderEvent);
|
|
840
839
|
}
|
|
841
840
|
}, [tracking]);
|
|
@@ -978,7 +977,9 @@ function useAd(path, size, {
|
|
|
978
977
|
}
|
|
979
978
|
return () => {};
|
|
980
979
|
}
|
|
981
|
-
|
|
980
|
+
function onSlotRender({
|
|
981
|
+
event
|
|
982
|
+
}) {
|
|
982
983
|
const newRenderEvent = {
|
|
983
984
|
...event,
|
|
984
985
|
...(slot !== null ? slot.getRenderedSize() : null),
|
|
@@ -996,7 +997,7 @@ function useAd(path, size, {
|
|
|
996
997
|
} else {
|
|
997
998
|
track('Render', slot, newRenderEvent);
|
|
998
999
|
}
|
|
999
|
-
}
|
|
1000
|
+
}
|
|
1000
1001
|
slot.on('render', onSlotRender);
|
|
1001
1002
|
return () => slot.off('render', onSlotRender);
|
|
1002
1003
|
}, [slot, disabled, setRenderEvent, onRender, track]);
|
|
@@ -1047,7 +1048,10 @@ function parseRichAd(data) {
|
|
|
1047
1048
|
try {
|
|
1048
1049
|
const eventData = JSON.parse(data) || null;
|
|
1049
1050
|
richAd = eventData !== null ? eventData.richAd || null : null;
|
|
1050
|
-
} catch
|
|
1051
|
+
} catch {
|
|
1052
|
+
richAd = null;
|
|
1053
|
+
console.warn('Failed to parse rich ad data', data);
|
|
1054
|
+
}
|
|
1051
1055
|
return richAd;
|
|
1052
1056
|
}
|
|
1053
1057
|
function useRichAd(containerRef, id, opts = {}) {
|
|
@@ -1087,7 +1091,6 @@ function useRichAd(containerRef, id, opts = {}) {
|
|
|
1087
1091
|
return richAd;
|
|
1088
1092
|
}
|
|
1089
1093
|
|
|
1090
|
-
/* eslint-disable react/require-default-props */
|
|
1091
1094
|
function Ad({
|
|
1092
1095
|
slot: slotName,
|
|
1093
1096
|
path: providedPath = null,
|
|
@@ -1224,7 +1227,6 @@ function Ad({
|
|
|
1224
1227
|
if (slotRef !== null && typeof slotRef === 'function') {
|
|
1225
1228
|
slotRef(slotObject);
|
|
1226
1229
|
} else if (slotRef !== null && typeof slotRef === 'object') {
|
|
1227
|
-
// eslint-disable-next-line no-param-reassign
|
|
1228
1230
|
slotRef.current = slotObject;
|
|
1229
1231
|
}
|
|
1230
1232
|
const keepSize = shouldKeepSize && lastRenderedSize !== null && !isRendered;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.128",
|
|
4
4
|
"description": "Ads library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -27,18 +27,21 @@
|
|
|
27
27
|
"email": "nrb@folklore.email"
|
|
28
28
|
}
|
|
29
29
|
],
|
|
30
|
-
"
|
|
31
|
-
"module": "dist/
|
|
32
|
-
"types": "
|
|
30
|
+
"type": "module",
|
|
31
|
+
"module": "dist/index.js",
|
|
32
|
+
"types": "dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"default": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
33
39
|
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
"types"
|
|
40
|
+
"dist"
|
|
36
41
|
],
|
|
37
42
|
"scripts": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"build": "npm run build:types && rollup --bundleConfigAsCjs --config ../../rollup.config.js",
|
|
41
|
-
"prepublishOnly": "npm run clean && npm run build"
|
|
43
|
+
"build": "../../scripts/prepare-package.sh --types",
|
|
44
|
+
"prepublishOnly": "npm run build"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"prop-types": "^15.7.2",
|
|
@@ -53,14 +56,15 @@
|
|
|
53
56
|
"publishConfig": {
|
|
54
57
|
"access": "public"
|
|
55
58
|
},
|
|
56
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "59edcc27c3dec97af55f90279ef184e209df4fbd",
|
|
57
60
|
"dependencies": {
|
|
58
|
-
"@folklore/
|
|
59
|
-
"@folklore/
|
|
60
|
-
"@folklore/
|
|
61
|
+
"@folklore/events": "^0.0.12",
|
|
62
|
+
"@folklore/hooks": "^0.0.86",
|
|
63
|
+
"@folklore/tracking": "^0.0.36",
|
|
64
|
+
"@folklore/utils": "^0.1.6",
|
|
65
|
+
"@types/google-publisher-tag": "^1.20260216.0",
|
|
61
66
|
"classnames": "^2.5.1",
|
|
62
67
|
"debug": "^4.3.4",
|
|
63
|
-
"lodash": "^4.17.21"
|
|
64
|
-
"wolfy87-eventemitter": "^5.2.9"
|
|
68
|
+
"lodash": "^4.17.21"
|
|
65
69
|
}
|
|
66
70
|
}
|