@adview/react 1.0.13 → 1.0.15
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/AdViewUnit/AdViewUnit.cjs +273 -243
- package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.cjs +234 -198
- package/dist/AdViewUnit/AdViewUnit.client.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.d.cts +2 -2
- package/dist/AdViewUnit/AdViewUnit.client.d.ts +2 -2
- package/dist/AdViewUnit/AdViewUnit.client.js +226 -190
- package/dist/AdViewUnit/AdViewUnit.client.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnit.d.ts +1 -1
- package/dist/AdViewUnit/AdViewUnit.js +261 -231
- package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.cjs +229 -157
- package/dist/AdViewUnit/AdViewUnit.server.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.d.cts +3 -3
- package/dist/AdViewUnit/AdViewUnit.server.d.ts +3 -3
- package/dist/AdViewUnit/AdViewUnit.server.js +227 -155
- package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
- package/dist/AdViewUnit/{AdViewUnitBanner.cjs → AdViewUnitBannerTemplate.cjs} +36 -14
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +17 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +17 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.js +51 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.js.map +1 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs +66 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +16 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +16 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js +35 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js.map +1 -0
- package/dist/AdViewUnit/{AdViewUnitNative.cjs → AdViewUnitNativeTemplate.cjs} +31 -13
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +16 -0
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +16 -0
- package/dist/AdViewUnit/{AdViewUnitNative.js → AdViewUnitNativeTemplate.js} +28 -10
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.js.map +1 -0
- package/dist/AdViewUnit/{AdViewUnitProxy.cjs → AdViewUnitProxyTemplate.cjs} +33 -13
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +17 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +17 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.js +52 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.js.map +1 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.cjs +132 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.d.cts +14 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.d.ts +14 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.js +95 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.js.map +1 -1
- package/dist/AdViewUnit/useAdViewController.cjs +5 -3
- package/dist/AdViewUnit/useAdViewController.cjs.map +1 -1
- package/dist/AdViewUnit/useAdViewController.d.cts +2 -2
- package/dist/AdViewUnit/useAdViewController.d.ts +2 -2
- package/dist/AdViewUnit/useAdViewController.js +5 -3
- package/dist/AdViewUnit/useAdViewController.js.map +1 -1
- package/dist/AdViewUnit/utils.cjs +33 -0
- package/dist/AdViewUnit/utils.cjs.map +1 -0
- package/dist/AdViewUnit/utils.d.cts +7 -0
- package/dist/AdViewUnit/utils.d.ts +7 -0
- package/dist/AdViewUnit/utils.js +8 -0
- package/dist/AdViewUnit/utils.js.map +1 -0
- package/dist/index.cjs +305 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +286 -193
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +302 -167
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +7 -6
- package/dist/server.d.ts +7 -6
- package/dist/server.js +288 -160
- package/dist/server.js.map +1 -1
- package/dist/{types-BaV07oMT.d.cts → types-DHjNgnRW.d.cts} +35 -43
- package/dist/{types-BaV07oMT.d.ts → types-DHjNgnRW.d.ts} +35 -43
- package/package.json +1 -1
- package/dist/AdViewUnit/AdViewUnitBanner.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitBanner.d.cts +0 -10
- package/dist/AdViewUnit/AdViewUnitBanner.d.ts +0 -10
- package/dist/AdViewUnit/AdViewUnitBanner.js +0 -29
- package/dist/AdViewUnit/AdViewUnitBanner.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitNative.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitNative.d.cts +0 -10
- package/dist/AdViewUnit/AdViewUnitNative.d.ts +0 -10
- package/dist/AdViewUnit/AdViewUnitNative.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitProxy.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitProxy.d.cts +0 -10
- package/dist/AdViewUnit/AdViewUnitProxy.d.ts +0 -10
- package/dist/AdViewUnit/AdViewUnitProxy.js +0 -32
- package/dist/AdViewUnit/AdViewUnitProxy.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs +0 -203
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.cts +0 -12
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.ts +0 -12
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.js +0 -170
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs +0 -250
- package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.client.d.cts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.client.d.ts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.client.js +0 -220
- package/dist/AdViewUnit/AdViewUnitWrapper.client.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs +0 -232
- package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.server.d.cts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.server.d.ts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.server.js +0 -201
- package/dist/AdViewUnit/AdViewUnitWrapper.server.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -1,77 +1,75 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
// src/AdViewUnit/AdViewUnit.server.tsx
|
|
4
|
-
import
|
|
4
|
+
import React6 from "react";
|
|
5
5
|
import { adViewFetcher, getAdRequestUrl, getResolveConfig } from "@adview/core/utils";
|
|
6
6
|
|
|
7
|
-
// src/AdViewUnit/
|
|
8
|
-
import {
|
|
9
|
-
import React
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
7
|
+
// src/AdViewUnit/AdViewUnitBannerTemplate.tsx
|
|
8
|
+
import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from "@adview/core/utils";
|
|
9
|
+
import React from "react";
|
|
10
|
+
|
|
11
|
+
// src/AdViewUnit/utils.ts
|
|
12
|
+
var matchExpectedState = (expectState, state) => {
|
|
13
|
+
return !expectState || (expectState.isInitial === void 0 || expectState.isInitial === state?.isInitial) && (expectState.isLoading === void 0 || expectState.isLoading === state?.isLoading) && (expectState.isError === void 0 || expectState.isError === state?.isError) && (expectState.isComplete === void 0 || expectState.isComplete === state?.isComplete);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/AdViewUnit/AdViewUnitBannerTemplate.tsx
|
|
17
|
+
function AdViewUnitBannerTemplate({ className = "banner", style, data, state, ...props }) {
|
|
18
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
19
|
+
isInitial: props?.isInitial,
|
|
20
|
+
isLoading: props?.isLoading,
|
|
21
|
+
isError: props?.isError,
|
|
22
|
+
isComplete: props?.isComplete
|
|
23
|
+
} : { isComplete: true };
|
|
24
|
+
if (!data || !data.assets || !data.assets.length) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!matchExpectedState(expectState, state)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const asset = getAssetByName("main", data.assets);
|
|
31
|
+
return /* @__PURE__ */ React.createElement(
|
|
32
|
+
"a",
|
|
33
|
+
{
|
|
34
|
+
target: "_blank",
|
|
35
|
+
rel: "noopener noreferrer",
|
|
36
|
+
href: getPrepareURL(data.url),
|
|
37
|
+
className,
|
|
38
|
+
style: { fontSize: 0, ...style }
|
|
30
39
|
},
|
|
31
|
-
|
|
40
|
+
asset && /* @__PURE__ */ React.createElement(
|
|
41
|
+
"img",
|
|
42
|
+
{
|
|
43
|
+
alt: "main",
|
|
44
|
+
src: asset.path,
|
|
45
|
+
srcSet: asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ""
|
|
46
|
+
}
|
|
47
|
+
)
|
|
32
48
|
);
|
|
33
|
-
const trackingObserverInstance = useMemo(() => {
|
|
34
|
-
return !isServer ? new IntersectionObserver(trackingObserverInstanceHandler) : null;
|
|
35
|
-
}, [isServer, trackingObserverInstanceHandler]);
|
|
36
|
-
const clickTrackerHandler = useCallback(() => {
|
|
37
|
-
executeImpressionsTracking(clicks);
|
|
38
|
-
wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
|
|
39
|
-
}, [clicks]);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (wrapperRef.current && trackingObserverInstance) {
|
|
42
|
-
executeImpressionsTrackingHandler();
|
|
43
|
-
wrapperRef.current?.addEventListener("click", clickTrackerHandler);
|
|
44
|
-
trackingObserverInstance?.observe(wrapperRef.current);
|
|
45
|
-
return () => {
|
|
46
|
-
wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
|
|
47
|
-
if (wrapperRef.current)
|
|
48
|
-
trackingObserverInstance?.unobserve(wrapperRef.current);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return () => {
|
|
52
|
-
};
|
|
53
|
-
}, [
|
|
54
|
-
trackingObserverInstance,
|
|
55
|
-
executeImpressionsTrackingHandler,
|
|
56
|
-
clickTrackerHandler
|
|
57
|
-
]);
|
|
58
|
-
return /* @__PURE__ */ React.createElement("div", { ref: wrapperRef }, children);
|
|
59
49
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
AdViewUnitBannerTemplate.defaults = {
|
|
51
|
+
type: "banner"
|
|
52
|
+
};
|
|
53
|
+
var AdViewUnitBannerTemplate_default = AdViewUnitBannerTemplate;
|
|
64
54
|
|
|
65
|
-
// src/AdViewUnit/
|
|
66
|
-
import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from "@adview/core/utils";
|
|
55
|
+
// src/AdViewUnit/AdViewUnitNativeTemplate.tsx
|
|
56
|
+
import { getAssetByName as getAssetByName2, getPrepareURL as getPrepareURL2, getSrcSetCSSThumbs as getSrcSetCSSThumbs2 } from "@adview/core/utils";
|
|
67
57
|
import React2 from "react";
|
|
68
|
-
function
|
|
69
|
-
assets
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
function AdViewUnitNativeTemplate({ classNames, data, state, ...props }) {
|
|
59
|
+
if (!data || !data.assets || !data.assets.length) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
63
|
+
isInitial: props?.isInitial,
|
|
64
|
+
isLoading: props?.isLoading,
|
|
65
|
+
isError: props?.isError,
|
|
66
|
+
isComplete: props?.isComplete
|
|
67
|
+
} : { isComplete: true };
|
|
68
|
+
if (!matchExpectedState(expectState, state)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const { assets, url, fields } = data;
|
|
72
|
+
const asset = getAssetByName2("main", assets);
|
|
75
73
|
if (!url) {
|
|
76
74
|
return null;
|
|
77
75
|
}
|
|
@@ -80,7 +78,7 @@ function AdViewUnitNative({
|
|
|
80
78
|
{
|
|
81
79
|
target: "_blank",
|
|
82
80
|
rel: "noopener noreferrer",
|
|
83
|
-
href:
|
|
81
|
+
href: getPrepareURL2(url),
|
|
84
82
|
className: classNames?.imageLink
|
|
85
83
|
},
|
|
86
84
|
asset && /* @__PURE__ */ React2.createElement(
|
|
@@ -89,7 +87,7 @@ function AdViewUnitNative({
|
|
|
89
87
|
alt: fields?.title,
|
|
90
88
|
title: fields?.title,
|
|
91
89
|
src: asset.path,
|
|
92
|
-
srcSet: asset.thumbs ?
|
|
90
|
+
srcSet: asset.thumbs ? getSrcSetCSSThumbs2(asset.thumbs) : void 0,
|
|
93
91
|
className: classNames?.image,
|
|
94
92
|
style: { objectFit: "cover", width: "100%", height: "100%" }
|
|
95
93
|
}
|
|
@@ -99,7 +97,7 @@ function AdViewUnitNative({
|
|
|
99
97
|
{
|
|
100
98
|
target: "_blank",
|
|
101
99
|
rel: "noopener noreferrer",
|
|
102
|
-
href:
|
|
100
|
+
href: getPrepareURL2(url),
|
|
103
101
|
"data-class": "titleLink",
|
|
104
102
|
className: classNames?.titleLink
|
|
105
103
|
},
|
|
@@ -109,7 +107,7 @@ function AdViewUnitNative({
|
|
|
109
107
|
{
|
|
110
108
|
target: "_blank",
|
|
111
109
|
rel: "noopener noreferrer",
|
|
112
|
-
href:
|
|
110
|
+
href: getPrepareURL2(url),
|
|
113
111
|
"data-class": "descriptionLink",
|
|
114
112
|
className: classNames?.descriptionLink
|
|
115
113
|
},
|
|
@@ -119,7 +117,7 @@ function AdViewUnitNative({
|
|
|
119
117
|
{
|
|
120
118
|
target: "_blank",
|
|
121
119
|
rel: "noopener noreferrer",
|
|
122
|
-
href:
|
|
120
|
+
href: getPrepareURL2(url),
|
|
123
121
|
"data-class": "brandNameLink",
|
|
124
122
|
className: classNames?.brandNameLink
|
|
125
123
|
},
|
|
@@ -129,7 +127,7 @@ function AdViewUnitNative({
|
|
|
129
127
|
{
|
|
130
128
|
target: "_blank",
|
|
131
129
|
rel: "noopener noreferrer",
|
|
132
|
-
href:
|
|
130
|
+
href: getPrepareURL2(url),
|
|
133
131
|
"data-class": "phoneLink",
|
|
134
132
|
className: classNames?.phoneLink
|
|
135
133
|
},
|
|
@@ -139,22 +137,34 @@ function AdViewUnitNative({
|
|
|
139
137
|
{
|
|
140
138
|
target: "_blank",
|
|
141
139
|
rel: "noopener noreferrer",
|
|
142
|
-
href:
|
|
140
|
+
href: getPrepareURL2(url),
|
|
143
141
|
"data-class": "urlLink",
|
|
144
142
|
className: classNames?.urlLink
|
|
145
143
|
},
|
|
146
144
|
fields?.url
|
|
147
145
|
)));
|
|
148
146
|
}
|
|
149
|
-
|
|
147
|
+
AdViewUnitNativeTemplate.defaults = {
|
|
148
|
+
type: "native"
|
|
149
|
+
};
|
|
150
|
+
var AdViewUnitNativeTemplate_default = AdViewUnitNativeTemplate;
|
|
150
151
|
|
|
151
|
-
// src/AdViewUnit/
|
|
152
|
+
// src/AdViewUnit/AdViewUnitProxyTemplate.tsx
|
|
152
153
|
import React3 from "react";
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
function AdViewUnitProxyTemplate({ className, style, data, state, ...props }) {
|
|
155
|
+
if (!data) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
159
|
+
isInitial: props?.isInitial,
|
|
160
|
+
isLoading: props?.isLoading,
|
|
161
|
+
isError: props?.isError,
|
|
162
|
+
isComplete: props?.isComplete
|
|
163
|
+
} : { isComplete: true };
|
|
164
|
+
if (!matchExpectedState(expectState, state)) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const { url, fields } = data;
|
|
158
168
|
const iframeSrc = fields?.url || url;
|
|
159
169
|
if (!iframeSrc) {
|
|
160
170
|
return null;
|
|
@@ -162,6 +172,7 @@ function AdViewUnitProxy({
|
|
|
162
172
|
return /* @__PURE__ */ React3.createElement(
|
|
163
173
|
"iframe",
|
|
164
174
|
{
|
|
175
|
+
className,
|
|
165
176
|
width: "100%",
|
|
166
177
|
height: "100%",
|
|
167
178
|
frameBorder: "0",
|
|
@@ -170,122 +181,239 @@ function AdViewUnitProxy({
|
|
|
170
181
|
allowTransparency: true,
|
|
171
182
|
scrolling: "no",
|
|
172
183
|
allowFullScreen: true,
|
|
173
|
-
style: { width: "100%", height: "100%" },
|
|
184
|
+
style: { width: "100%", height: "100%", border: "none", ...style },
|
|
174
185
|
src: iframeSrc
|
|
175
186
|
}
|
|
176
187
|
);
|
|
177
188
|
}
|
|
178
|
-
|
|
189
|
+
AdViewUnitProxyTemplate.defaults = {
|
|
190
|
+
type: "proxy"
|
|
191
|
+
};
|
|
192
|
+
var AdViewUnitProxyTemplate_default = AdViewUnitProxyTemplate;
|
|
179
193
|
|
|
180
|
-
// src/AdViewUnit/
|
|
181
|
-
import { getAssetByName as getAssetByName2, getPrepareURL as getPrepareURL2, getSrcSetCSSThumbs as getSrcSetCSSThumbs2 } from "@adview/core/utils";
|
|
194
|
+
// src/AdViewUnit/AdViewUnitTemplate.tsx
|
|
182
195
|
import React4 from "react";
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// src/AdViewUnit/AdViewUnitTypeSwitch.tsx
|
|
207
|
-
import React5 from "react";
|
|
208
|
-
function AdViewUnitTypeSwitch({
|
|
209
|
-
data,
|
|
210
|
-
classNames,
|
|
211
|
-
onDefault
|
|
212
|
-
}) {
|
|
213
|
-
switch (data?.type) {
|
|
214
|
-
case "native":
|
|
215
|
-
return /* @__PURE__ */ React5.createElement(AdViewUnitNative_default, { ...data, classNames: classNames?.native });
|
|
216
|
-
case "proxy":
|
|
217
|
-
return /* @__PURE__ */ React5.createElement(AdViewUnitProxy_default, { ...data, classNames: classNames?.proxy });
|
|
218
|
-
case "banner":
|
|
219
|
-
return /* @__PURE__ */ React5.createElement(AdViewUnitBanner_default, { ...data, classNames: classNames?.banner });
|
|
220
|
-
default:
|
|
221
|
-
if (React5.isValidElement(onDefault)) {
|
|
222
|
-
return React5.cloneElement(onDefault);
|
|
223
|
-
}
|
|
224
|
-
if (typeof onDefault === "function") {
|
|
225
|
-
return onDefault();
|
|
226
|
-
}
|
|
196
|
+
var templateFromListRender = (tmpls, data, wrap) => {
|
|
197
|
+
let renderedRemplates = tmpls.map((tmpl, index) => {
|
|
198
|
+
let tmp = renderTemplate(tmpl, data);
|
|
199
|
+
return !!tmp && React4.isValidElement(tmp) ? /* @__PURE__ */ React4.createElement(React4.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
200
|
+
}).filter((it) => !!it);
|
|
201
|
+
if (!renderedRemplates.length) {
|
|
202
|
+
renderedRemplates = tmpls.map((tmpl, index) => {
|
|
203
|
+
let tmp = renderTemplate(tmpl, { ...data, type: "default" });
|
|
204
|
+
return !!tmp && React4.isValidElement(tmp) ? /* @__PURE__ */ React4.createElement(React4.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
205
|
+
}).filter((it) => !!it);
|
|
206
|
+
}
|
|
207
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, renderedRemplates);
|
|
208
|
+
};
|
|
209
|
+
var renderTemplate = (tmpl, data) => {
|
|
210
|
+
const isFunction = typeof tmpl === "function";
|
|
211
|
+
const isReactElement = React4.isValidElement(tmpl);
|
|
212
|
+
if (isReactElement) {
|
|
213
|
+
let { type, children } = tmpl.props;
|
|
214
|
+
if (!type && typeof tmpl.type !== "string") {
|
|
215
|
+
type = tmpl.type?.defaults?.type;
|
|
216
|
+
}
|
|
217
|
+
if (data.type !== type) {
|
|
227
218
|
return null;
|
|
219
|
+
}
|
|
220
|
+
if (typeof children === "function") {
|
|
221
|
+
return children(data);
|
|
222
|
+
}
|
|
223
|
+
return React4.cloneElement(tmpl, {
|
|
224
|
+
...data,
|
|
225
|
+
children
|
|
226
|
+
});
|
|
228
227
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// src/AdViewUnit/AdViewUnitWrapper.server.tsx
|
|
233
|
-
async function AdViewUnitWrapperServer({
|
|
234
|
-
data,
|
|
235
|
-
children,
|
|
236
|
-
onDefault
|
|
237
|
-
}) {
|
|
238
|
-
const isChildrenReactNode = React6.isValidElement(children);
|
|
239
|
-
const isChildrenFunction = typeof children === "function";
|
|
240
|
-
const isLoadingError = data instanceof Error;
|
|
241
|
-
if (isChildrenReactNode) {
|
|
242
|
-
return React6.cloneElement(children, { data, onDefault });
|
|
228
|
+
if (isFunction) {
|
|
229
|
+
return tmpl(data);
|
|
243
230
|
}
|
|
244
|
-
|
|
245
|
-
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
233
|
+
var renderTemplates = (tmpls, data, listRender) => {
|
|
234
|
+
return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);
|
|
235
|
+
};
|
|
236
|
+
var renderAnyTemplates = (tmpls, data, listRender) => {
|
|
237
|
+
if (!tmpls) {
|
|
238
|
+
return null;
|
|
246
239
|
}
|
|
247
|
-
if (
|
|
248
|
-
return
|
|
240
|
+
if (Array.isArray(tmpls)) {
|
|
241
|
+
return renderTemplates(tmpls, data, listRender);
|
|
249
242
|
}
|
|
250
|
-
if (
|
|
251
|
-
return
|
|
243
|
+
if (typeof tmpls === "function") {
|
|
244
|
+
return tmpls(data);
|
|
252
245
|
}
|
|
253
|
-
if (
|
|
254
|
-
return
|
|
246
|
+
if (React4.isValidElement(tmpls)) {
|
|
247
|
+
return templateFromListRender([tmpls], data);
|
|
255
248
|
}
|
|
256
249
|
return null;
|
|
250
|
+
};
|
|
251
|
+
var AdViewUnitTemplate = ({ type, state, children, ...props }) => {
|
|
252
|
+
const tmplProps = {
|
|
253
|
+
type,
|
|
254
|
+
state,
|
|
255
|
+
...props
|
|
256
|
+
};
|
|
257
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
258
|
+
isInitial: props?.isInitial,
|
|
259
|
+
isLoading: props?.isLoading,
|
|
260
|
+
isError: props?.isError,
|
|
261
|
+
isComplete: props?.isComplete
|
|
262
|
+
} : { isComplete: true };
|
|
263
|
+
if (!matchExpectedState(expectState, state)) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
if (typeof children === "function") {
|
|
267
|
+
return children(tmplProps);
|
|
268
|
+
}
|
|
269
|
+
if (React4.isValidElement(children)) {
|
|
270
|
+
return React4.cloneElement(children, tmplProps);
|
|
271
|
+
}
|
|
272
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
|
|
273
|
+
};
|
|
274
|
+
var AdViewUnitTemplate_default = AdViewUnitTemplate;
|
|
275
|
+
|
|
276
|
+
// src/AdViewUnit/AdViewUnitTracking.tsx
|
|
277
|
+
import { executeImpressionsTracking } from "@adview/core/utils";
|
|
278
|
+
import React5, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
279
|
+
function AdViewUnitTracking({
|
|
280
|
+
impressions,
|
|
281
|
+
views,
|
|
282
|
+
clicks,
|
|
283
|
+
children
|
|
284
|
+
}) {
|
|
285
|
+
const isServer = typeof window === "undefined";
|
|
286
|
+
const wrapperRef = useRef(null);
|
|
287
|
+
const executeImpressionsTrackingHandler = useCallback(
|
|
288
|
+
() => executeImpressionsTracking(impressions),
|
|
289
|
+
[impressions]
|
|
290
|
+
);
|
|
291
|
+
const trackingObserverInstanceHandler = useCallback(
|
|
292
|
+
(entries) => {
|
|
293
|
+
entries.forEach((entry) => {
|
|
294
|
+
if (entry.isIntersecting) {
|
|
295
|
+
executeImpressionsTracking(views);
|
|
296
|
+
trackingObserverInstance?.unobserve(wrapperRef.current);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
[views]
|
|
301
|
+
);
|
|
302
|
+
const trackingObserverInstance = useMemo(() => {
|
|
303
|
+
return !isServer ? new IntersectionObserver(trackingObserverInstanceHandler) : null;
|
|
304
|
+
}, [isServer, trackingObserverInstanceHandler]);
|
|
305
|
+
const clickTrackerHandler = useCallback(() => {
|
|
306
|
+
executeImpressionsTracking(clicks);
|
|
307
|
+
wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
|
|
308
|
+
}, [clicks]);
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
if (wrapperRef.current && trackingObserverInstance) {
|
|
311
|
+
executeImpressionsTrackingHandler();
|
|
312
|
+
wrapperRef.current?.addEventListener("click", clickTrackerHandler);
|
|
313
|
+
trackingObserverInstance?.observe(wrapperRef.current);
|
|
314
|
+
return () => {
|
|
315
|
+
wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
|
|
316
|
+
if (wrapperRef.current)
|
|
317
|
+
trackingObserverInstance?.unobserve(wrapperRef.current);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return () => {
|
|
321
|
+
};
|
|
322
|
+
}, [
|
|
323
|
+
trackingObserverInstance,
|
|
324
|
+
executeImpressionsTrackingHandler,
|
|
325
|
+
clickTrackerHandler
|
|
326
|
+
]);
|
|
327
|
+
return /* @__PURE__ */ React5.createElement("div", { ref: wrapperRef }, children);
|
|
257
328
|
}
|
|
258
|
-
var
|
|
329
|
+
var AdViewUnitTracking_default = AdViewUnitTracking;
|
|
259
330
|
|
|
260
331
|
// src/AdViewUnit/AdViewUnit.server.tsx
|
|
261
332
|
async function AdViewUnitServer({
|
|
262
333
|
unitId,
|
|
263
334
|
format,
|
|
264
335
|
children,
|
|
265
|
-
onDefault = () => null,
|
|
266
336
|
...config
|
|
267
337
|
}) {
|
|
338
|
+
const checkFormat = (f) => {
|
|
339
|
+
if (!format) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
return Array.isArray(format) ? format.includes(f) : f === format;
|
|
343
|
+
};
|
|
268
344
|
const baseConfig = getResolveConfig(config);
|
|
269
345
|
const requestUrl = getAdRequestUrl(baseConfig, unitId, format);
|
|
270
346
|
const response = await adViewFetcher(requestUrl);
|
|
271
347
|
const isLoadingError = response instanceof Error;
|
|
272
348
|
const error = isLoadingError ? response : void 0;
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
349
|
+
const state = {
|
|
350
|
+
isLoading: true,
|
|
351
|
+
isComplete: true,
|
|
352
|
+
isInitial: false,
|
|
353
|
+
isError: isLoadingError
|
|
354
|
+
};
|
|
355
|
+
const { responseGroup: _, customTracker, groupItems } = error ? { responseGroup: null, customTracker: {}, groupItems: [] } : (() => {
|
|
356
|
+
for (let responseGroup of response?.groups || []) {
|
|
357
|
+
const customTracker2 = responseGroup?.custom_tracker ?? {};
|
|
358
|
+
const groupItems2 = responseGroup?.items.map((it) => checkFormat(it.type) ? it : null).filter(Boolean);
|
|
359
|
+
if (groupItems2 && groupItems2.length > 0) {
|
|
360
|
+
return { responseGroup, customTracker: customTracker2, groupItems: groupItems2 };
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return { responseGroup: null, customTracker: {}, groupItems: [] };
|
|
364
|
+
})();
|
|
365
|
+
if (!children) {
|
|
366
|
+
children = [
|
|
367
|
+
/* @__PURE__ */ React6.createElement(AdViewUnitBannerTemplate_default, null),
|
|
368
|
+
/* @__PURE__ */ React6.createElement(AdViewUnitNativeTemplate_default, null),
|
|
369
|
+
/* @__PURE__ */ React6.createElement(AdViewUnitProxyTemplate_default, null)
|
|
370
|
+
];
|
|
371
|
+
}
|
|
276
372
|
if (groupItems && groupItems.length) {
|
|
277
373
|
return groupItems.map(({ tracker, ...data }) => {
|
|
278
|
-
return /* @__PURE__ */
|
|
374
|
+
return /* @__PURE__ */ React6.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state }));
|
|
279
375
|
});
|
|
280
376
|
}
|
|
281
|
-
return /* @__PURE__ */
|
|
377
|
+
return /* @__PURE__ */ React6.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state }));
|
|
282
378
|
}
|
|
283
379
|
var AdViewUnit_server_default = AdViewUnitServer;
|
|
380
|
+
|
|
381
|
+
// src/AdViewUnit/AdViewUnitDefaultTemplate.tsx
|
|
382
|
+
import React7 from "react";
|
|
383
|
+
function AdViewUnitDefaultTemplate({ type = "default", data, state, children, ...props }) {
|
|
384
|
+
if (data) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
388
|
+
isInitial: props?.isInitial,
|
|
389
|
+
isLoading: props?.isLoading,
|
|
390
|
+
isError: props?.isError,
|
|
391
|
+
isComplete: props?.isComplete
|
|
392
|
+
} : { isComplete: true };
|
|
393
|
+
if (!matchExpectedState(expectState, state)) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
if (typeof children === "function") {
|
|
397
|
+
return /* @__PURE__ */ React7.createElement(React7.Fragment, null, children({ data, state, ...props }));
|
|
398
|
+
}
|
|
399
|
+
return children ? /* @__PURE__ */ React7.createElement(React7.Fragment, null, children) : /* @__PURE__ */ React7.createElement("div", { style: { padding: "1rem", textAlign: "center", color: "#666" } }, /* @__PURE__ */ React7.createElement("p", null, "\u{1F504} Default content for ad unit"), /* @__PURE__ */ React7.createElement("p", null, "Data: ", JSON.stringify(data)), /* @__PURE__ */ React7.createElement("p", null, "State: ", JSON.stringify(state)));
|
|
400
|
+
}
|
|
401
|
+
AdViewUnitDefaultTemplate.defaults = {
|
|
402
|
+
type: "default"
|
|
403
|
+
};
|
|
404
|
+
var AdViewUnitDefaultTemplate_default = AdViewUnitDefaultTemplate;
|
|
284
405
|
export {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
406
|
+
AdViewUnitBannerTemplate_default as AdViewUnitBannerTemplate,
|
|
407
|
+
AdViewUnitDefaultTemplate_default as AdViewUnitDefaultTemplate,
|
|
408
|
+
AdViewUnitNativeTemplate_default as AdViewUnitNativeTemplate,
|
|
409
|
+
AdViewUnitProxyTemplate_default as AdViewUnitProxyTemplate,
|
|
410
|
+
AdViewUnit_server_default as AdViewUnitServer,
|
|
411
|
+
AdViewUnitTemplate_default as AdViewUnitTemplate,
|
|
412
|
+
AdViewUnitBannerTemplate_default as BannerTemplate,
|
|
413
|
+
AdViewUnitDefaultTemplate_default as DefaultTemplate,
|
|
414
|
+
AdViewUnitNativeTemplate_default as NativeTemplate,
|
|
415
|
+
AdViewUnitProxyTemplate_default as ProxyTemplate,
|
|
416
|
+
AdViewUnitTemplate_default as Template,
|
|
417
|
+
AdViewUnit_server_default as Unit
|
|
290
418
|
};
|
|
291
419
|
//# sourceMappingURL=server.js.map
|