@adview/react 1.0.12 → 1.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/AdViewUnit/AdViewProvider.d.cts +4 -4
- package/dist/AdViewUnit/AdViewProvider.d.ts +4 -4
- package/dist/AdViewUnit/AdViewUnit.cjs +106 -298
- package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.cjs +86 -256
- package/dist/AdViewUnit/AdViewUnit.client.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.d.cts +3 -3
- package/dist/AdViewUnit/AdViewUnit.client.d.ts +3 -3
- package/dist/AdViewUnit/AdViewUnit.client.js +69 -239
- package/dist/AdViewUnit/AdViewUnit.client.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.d.cts +3 -3
- package/dist/AdViewUnit/AdViewUnit.d.ts +3 -3
- package/dist/AdViewUnit/AdViewUnit.js +85 -277
- package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.cjs +82 -214
- 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 +72 -204
- package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
- package/dist/AdViewUnit/{AdViewUnitBanner.cjs → AdViewUnitBannerTemplate.cjs} +17 -14
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +12 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +12 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.js +32 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.js.map +1 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs +48 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +17 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +17 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js +17 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js.map +1 -0
- package/dist/AdViewUnit/{AdViewUnitNative.cjs → AdViewUnitNativeTemplate.cjs} +12 -13
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +11 -0
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +11 -0
- package/dist/AdViewUnit/{AdViewUnitNative.js → AdViewUnitNativeTemplate.js} +9 -10
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.js.map +1 -0
- package/dist/AdViewUnit/{AdViewUnitProxy.cjs → AdViewUnitProxyTemplate.cjs} +14 -13
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +12 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +12 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.js +33 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.js.map +1 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.cjs +114 -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 +77 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnitTracking.d.cts +3 -3
- package/dist/AdViewUnit/AdViewUnitTracking.d.ts +3 -3
- package/dist/AdViewUnit/useAdViewController.cjs +5 -1
- 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 -1
- package/dist/AdViewUnit/useAdViewController.js.map +1 -1
- package/dist/index.cjs +250 -255
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -22
- package/dist/index.d.ts +10 -22
- package/dist/index.js +232 -240
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +214 -173
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +7 -17
- package/dist/server.d.ts +7 -17
- package/dist/server.js +195 -161
- package/dist/server.js.map +1 -1
- package/dist/{types-BaV07oMT.d.cts → types-B65WDsgh.d.cts} +29 -25
- package/dist/{types-BaV07oMT.d.ts → types-B65WDsgh.d.ts} +29 -25
- 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
|
@@ -35,12 +35,69 @@ __export(AdViewUnit_server_exports, {
|
|
|
35
35
|
default: () => AdViewUnit_server_default
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(AdViewUnit_server_exports);
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
39
|
+
var import_utils2 = require("@adview/core/utils");
|
|
40
|
+
|
|
41
|
+
// src/AdViewUnit/AdViewUnitTemplate.tsx
|
|
42
|
+
var import_react = __toESM(require("react"), 1);
|
|
43
|
+
var templateFromListRender = (tmpls, data, wrap) => {
|
|
44
|
+
let renderedRemplates = tmpls.map((tmpl, index) => {
|
|
45
|
+
let tmp = renderTemplate(tmpl, data);
|
|
46
|
+
return !!tmp && import_react.default.isValidElement(tmp) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
47
|
+
}).filter((it) => !!it);
|
|
48
|
+
if (!renderedRemplates.length) {
|
|
49
|
+
renderedRemplates = tmpls.map((tmpl, index) => {
|
|
50
|
+
let tmp = renderTemplate(tmpl, { ...data, type: "default" });
|
|
51
|
+
return !!tmp && import_react.default.isValidElement(tmp) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
52
|
+
}).filter((it) => !!it);
|
|
53
|
+
}
|
|
54
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, renderedRemplates);
|
|
55
|
+
};
|
|
56
|
+
var renderTemplate = (tmpl, data) => {
|
|
57
|
+
const isFunction = typeof tmpl === "function";
|
|
58
|
+
const isReactElement = import_react.default.isValidElement(tmpl);
|
|
59
|
+
if (isReactElement) {
|
|
60
|
+
const { type, children } = tmpl.props;
|
|
61
|
+
console.log("=====>\nrenderTemplate: React element detected, type:", type, "data:", data.type, data.type !== type);
|
|
62
|
+
if (data.type !== type) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (typeof children === "function") {
|
|
66
|
+
return children(data);
|
|
67
|
+
}
|
|
68
|
+
console.log("CLONE ELEMENT", tmpl);
|
|
69
|
+
return import_react.default.cloneElement(tmpl, {
|
|
70
|
+
...data,
|
|
71
|
+
children
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (isFunction) {
|
|
75
|
+
return tmpl(data);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
};
|
|
79
|
+
var renderTemplates = (tmpls, data, listRender) => {
|
|
80
|
+
return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);
|
|
81
|
+
};
|
|
82
|
+
var renderAnyTemplates = (tmpls, data, listRender) => {
|
|
83
|
+
if (!tmpls) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(tmpls)) {
|
|
87
|
+
return renderTemplates(tmpls, data, listRender);
|
|
88
|
+
}
|
|
89
|
+
if (typeof tmpls === "function") {
|
|
90
|
+
return tmpls(data);
|
|
91
|
+
}
|
|
92
|
+
if (import_react.default.isValidElement(tmpls)) {
|
|
93
|
+
return templateFromListRender([tmpls], data);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
};
|
|
40
97
|
|
|
41
98
|
// src/AdViewUnit/AdViewUnitTracking.tsx
|
|
42
99
|
var import_utils = require("@adview/core/utils");
|
|
43
|
-
var
|
|
100
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
44
101
|
function AdViewUnitTracking({
|
|
45
102
|
impressions,
|
|
46
103
|
views,
|
|
@@ -48,12 +105,12 @@ function AdViewUnitTracking({
|
|
|
48
105
|
children
|
|
49
106
|
}) {
|
|
50
107
|
const isServer = typeof window === "undefined";
|
|
51
|
-
const wrapperRef = (0,
|
|
52
|
-
const executeImpressionsTrackingHandler = (0,
|
|
108
|
+
const wrapperRef = (0, import_react2.useRef)(null);
|
|
109
|
+
const executeImpressionsTrackingHandler = (0, import_react2.useCallback)(
|
|
53
110
|
() => (0, import_utils.executeImpressionsTracking)(impressions),
|
|
54
111
|
[impressions]
|
|
55
112
|
);
|
|
56
|
-
const trackingObserverInstanceHandler = (0,
|
|
113
|
+
const trackingObserverInstanceHandler = (0, import_react2.useCallback)(
|
|
57
114
|
(entries) => {
|
|
58
115
|
entries.forEach((entry) => {
|
|
59
116
|
if (entry.isIntersecting) {
|
|
@@ -64,14 +121,14 @@ function AdViewUnitTracking({
|
|
|
64
121
|
},
|
|
65
122
|
[views]
|
|
66
123
|
);
|
|
67
|
-
const trackingObserverInstance = (0,
|
|
124
|
+
const trackingObserverInstance = (0, import_react2.useMemo)(() => {
|
|
68
125
|
return !isServer ? new IntersectionObserver(trackingObserverInstanceHandler) : null;
|
|
69
126
|
}, [isServer, trackingObserverInstanceHandler]);
|
|
70
|
-
const clickTrackerHandler = (0,
|
|
127
|
+
const clickTrackerHandler = (0, import_react2.useCallback)(() => {
|
|
71
128
|
(0, import_utils.executeImpressionsTracking)(clicks);
|
|
72
129
|
wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
|
|
73
130
|
}, [clicks]);
|
|
74
|
-
(0,
|
|
131
|
+
(0, import_react2.useEffect)(() => {
|
|
75
132
|
if (wrapperRef.current && trackingObserverInstance) {
|
|
76
133
|
executeImpressionsTrackingHandler();
|
|
77
134
|
wrapperRef.current?.addEventListener("click", clickTrackerHandler);
|
|
@@ -89,219 +146,20 @@ function AdViewUnitTracking({
|
|
|
89
146
|
executeImpressionsTrackingHandler,
|
|
90
147
|
clickTrackerHandler
|
|
91
148
|
]);
|
|
92
|
-
return /* @__PURE__ */
|
|
149
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", { ref: wrapperRef }, children);
|
|
93
150
|
}
|
|
94
151
|
var AdViewUnitTracking_default = AdViewUnitTracking;
|
|
95
152
|
|
|
96
|
-
// src/AdViewUnit/AdViewUnitWrapper.server.tsx
|
|
97
|
-
var import_react6 = __toESM(require("react"), 1);
|
|
98
|
-
|
|
99
|
-
// src/AdViewUnit/AdViewUnitNative.tsx
|
|
100
|
-
var import_utils2 = require("@adview/core/utils");
|
|
101
|
-
var import_react2 = __toESM(require("react"), 1);
|
|
102
|
-
function AdViewUnitNative({
|
|
103
|
-
assets,
|
|
104
|
-
fields,
|
|
105
|
-
url,
|
|
106
|
-
classNames
|
|
107
|
-
}) {
|
|
108
|
-
const asset = (0, import_utils2.getAssetByName)("main", assets);
|
|
109
|
-
if (!url) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return /* @__PURE__ */ import_react2.default.createElement("div", { className: classNames?.container }, /* @__PURE__ */ import_react2.default.createElement(
|
|
113
|
-
"a",
|
|
114
|
-
{
|
|
115
|
-
target: "_blank",
|
|
116
|
-
rel: "noopener noreferrer",
|
|
117
|
-
href: (0, import_utils2.getPrepareURL)(url),
|
|
118
|
-
className: classNames?.imageLink
|
|
119
|
-
},
|
|
120
|
-
asset && /* @__PURE__ */ import_react2.default.createElement(
|
|
121
|
-
"img",
|
|
122
|
-
{
|
|
123
|
-
alt: fields?.title,
|
|
124
|
-
title: fields?.title,
|
|
125
|
-
src: asset.path,
|
|
126
|
-
srcSet: asset.thumbs ? (0, import_utils2.getSrcSetCSSThumbs)(asset.thumbs) : void 0,
|
|
127
|
-
className: classNames?.image,
|
|
128
|
-
style: { objectFit: "cover", width: "100%", height: "100%" }
|
|
129
|
-
}
|
|
130
|
-
)
|
|
131
|
-
), /* @__PURE__ */ import_react2.default.createElement("div", { className: classNames?.label }, fields?.title && /* @__PURE__ */ import_react2.default.createElement(
|
|
132
|
-
"a",
|
|
133
|
-
{
|
|
134
|
-
target: "_blank",
|
|
135
|
-
rel: "noopener noreferrer",
|
|
136
|
-
href: (0, import_utils2.getPrepareURL)(url),
|
|
137
|
-
"data-class": "titleLink",
|
|
138
|
-
className: classNames?.titleLink
|
|
139
|
-
},
|
|
140
|
-
fields.title
|
|
141
|
-
), fields?.description && /* @__PURE__ */ import_react2.default.createElement(
|
|
142
|
-
"a",
|
|
143
|
-
{
|
|
144
|
-
target: "_blank",
|
|
145
|
-
rel: "noopener noreferrer",
|
|
146
|
-
href: (0, import_utils2.getPrepareURL)(url),
|
|
147
|
-
"data-class": "descriptionLink",
|
|
148
|
-
className: classNames?.descriptionLink
|
|
149
|
-
},
|
|
150
|
-
fields.description
|
|
151
|
-
), fields?.brandname && /* @__PURE__ */ import_react2.default.createElement(
|
|
152
|
-
"a",
|
|
153
|
-
{
|
|
154
|
-
target: "_blank",
|
|
155
|
-
rel: "noopener noreferrer",
|
|
156
|
-
href: (0, import_utils2.getPrepareURL)(url),
|
|
157
|
-
"data-class": "brandNameLink",
|
|
158
|
-
className: classNames?.brandNameLink
|
|
159
|
-
},
|
|
160
|
-
fields.brandname
|
|
161
|
-
), fields?.phone && /* @__PURE__ */ import_react2.default.createElement(
|
|
162
|
-
"a",
|
|
163
|
-
{
|
|
164
|
-
target: "_blank",
|
|
165
|
-
rel: "noopener noreferrer",
|
|
166
|
-
href: (0, import_utils2.getPrepareURL)(url),
|
|
167
|
-
"data-class": "phoneLink",
|
|
168
|
-
className: classNames?.phoneLink
|
|
169
|
-
},
|
|
170
|
-
fields.phone
|
|
171
|
-
), fields?.url && /* @__PURE__ */ import_react2.default.createElement(
|
|
172
|
-
"a",
|
|
173
|
-
{
|
|
174
|
-
target: "_blank",
|
|
175
|
-
rel: "noopener noreferrer",
|
|
176
|
-
href: (0, import_utils2.getPrepareURL)(url),
|
|
177
|
-
"data-class": "urlLink",
|
|
178
|
-
className: classNames?.urlLink
|
|
179
|
-
},
|
|
180
|
-
fields?.url
|
|
181
|
-
)));
|
|
182
|
-
}
|
|
183
|
-
var AdViewUnitNative_default = AdViewUnitNative;
|
|
184
|
-
|
|
185
|
-
// src/AdViewUnit/AdViewUnitProxy.tsx
|
|
186
|
-
var import_react3 = __toESM(require("react"), 1);
|
|
187
|
-
function AdViewUnitProxy({
|
|
188
|
-
// assets,
|
|
189
|
-
fields,
|
|
190
|
-
url
|
|
191
|
-
}) {
|
|
192
|
-
const iframeSrc = fields?.url || url;
|
|
193
|
-
if (!iframeSrc) {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
return /* @__PURE__ */ import_react3.default.createElement(
|
|
197
|
-
"iframe",
|
|
198
|
-
{
|
|
199
|
-
width: "100%",
|
|
200
|
-
height: "100%",
|
|
201
|
-
frameBorder: "0",
|
|
202
|
-
marginWidth: 0,
|
|
203
|
-
marginHeight: 0,
|
|
204
|
-
allowTransparency: true,
|
|
205
|
-
scrolling: "no",
|
|
206
|
-
allowFullScreen: true,
|
|
207
|
-
style: { width: "100%", height: "100%" },
|
|
208
|
-
src: iframeSrc
|
|
209
|
-
}
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
var AdViewUnitProxy_default = AdViewUnitProxy;
|
|
213
|
-
|
|
214
|
-
// src/AdViewUnit/AdViewUnitBanner.tsx
|
|
215
|
-
var import_utils3 = require("@adview/core/utils");
|
|
216
|
-
var import_react4 = __toESM(require("react"), 1);
|
|
217
|
-
function AdViewUnitBanner({ assets, url }) {
|
|
218
|
-
const asset = (0, import_utils3.getAssetByName)("main", assets);
|
|
219
|
-
return /* @__PURE__ */ import_react4.default.createElement("center", null, /* @__PURE__ */ import_react4.default.createElement(
|
|
220
|
-
"a",
|
|
221
|
-
{
|
|
222
|
-
target: "_blank",
|
|
223
|
-
rel: "noopener noreferrer",
|
|
224
|
-
href: (0, import_utils3.getPrepareURL)(url),
|
|
225
|
-
className: "banner",
|
|
226
|
-
style: { fontSize: 0 }
|
|
227
|
-
},
|
|
228
|
-
asset && /* @__PURE__ */ import_react4.default.createElement(
|
|
229
|
-
"img",
|
|
230
|
-
{
|
|
231
|
-
alt: "main",
|
|
232
|
-
src: asset.path,
|
|
233
|
-
srcSet: asset.thumbs ? (0, import_utils3.getSrcSetCSSThumbs)(asset.thumbs) : ""
|
|
234
|
-
}
|
|
235
|
-
)
|
|
236
|
-
));
|
|
237
|
-
}
|
|
238
|
-
var AdViewUnitBanner_default = AdViewUnitBanner;
|
|
239
|
-
|
|
240
|
-
// src/AdViewUnit/AdViewUnitTypeSwitch.tsx
|
|
241
|
-
var import_react5 = __toESM(require("react"), 1);
|
|
242
|
-
function AdViewUnitTypeSwitch({
|
|
243
|
-
data,
|
|
244
|
-
classNames,
|
|
245
|
-
onDefault
|
|
246
|
-
}) {
|
|
247
|
-
switch (data?.type) {
|
|
248
|
-
case "native":
|
|
249
|
-
return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitNative_default, { ...data, classNames: classNames?.native });
|
|
250
|
-
case "proxy":
|
|
251
|
-
return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitProxy_default, { ...data, classNames: classNames?.proxy });
|
|
252
|
-
case "banner":
|
|
253
|
-
return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitBanner_default, { ...data, classNames: classNames?.banner });
|
|
254
|
-
default:
|
|
255
|
-
if (import_react5.default.isValidElement(onDefault)) {
|
|
256
|
-
return import_react5.default.cloneElement(onDefault);
|
|
257
|
-
}
|
|
258
|
-
if (typeof onDefault === "function") {
|
|
259
|
-
return onDefault();
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
var AdViewUnitTypeSwitch_default = AdViewUnitTypeSwitch;
|
|
265
|
-
|
|
266
|
-
// src/AdViewUnit/AdViewUnitWrapper.server.tsx
|
|
267
|
-
async function AdViewUnitWrapperServer({
|
|
268
|
-
data,
|
|
269
|
-
children,
|
|
270
|
-
onDefault
|
|
271
|
-
}) {
|
|
272
|
-
const isChildrenReactNode = import_react6.default.isValidElement(children);
|
|
273
|
-
const isChildrenFunction = typeof children === "function";
|
|
274
|
-
const isLoadingError = data instanceof Error;
|
|
275
|
-
if (isChildrenReactNode) {
|
|
276
|
-
return import_react6.default.cloneElement(children, { data, onDefault });
|
|
277
|
-
}
|
|
278
|
-
if (isChildrenFunction) {
|
|
279
|
-
return children({ data, onDefault });
|
|
280
|
-
}
|
|
281
|
-
if (!children && !isLoadingError) {
|
|
282
|
-
return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitTypeSwitch_default, { data, onDefault });
|
|
283
|
-
}
|
|
284
|
-
if (import_react6.default.isValidElement(onDefault)) {
|
|
285
|
-
return import_react6.default.cloneElement(onDefault);
|
|
286
|
-
}
|
|
287
|
-
if (typeof onDefault === "function") {
|
|
288
|
-
return onDefault();
|
|
289
|
-
}
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
var AdViewUnitWrapper_server_default = AdViewUnitWrapperServer;
|
|
293
|
-
|
|
294
153
|
// src/AdViewUnit/AdViewUnit.server.tsx
|
|
295
154
|
async function AdViewUnitServer({
|
|
296
155
|
unitId,
|
|
297
156
|
format,
|
|
298
157
|
children,
|
|
299
|
-
onDefault = () => null,
|
|
300
158
|
...config
|
|
301
159
|
}) {
|
|
302
|
-
const baseConfig = (0,
|
|
303
|
-
const requestUrl = (0,
|
|
304
|
-
const response = await (0,
|
|
160
|
+
const baseConfig = (0, import_utils2.getResolveConfig)(config);
|
|
161
|
+
const requestUrl = (0, import_utils2.getAdRequestUrl)(baseConfig, unitId, format);
|
|
162
|
+
const response = await (0, import_utils2.adViewFetcher)(requestUrl);
|
|
305
163
|
const isLoadingError = response instanceof Error;
|
|
306
164
|
const error = isLoadingError ? response : void 0;
|
|
307
165
|
const responseGroup = response instanceof Error ? null : response?.groups?.[0];
|
|
@@ -309,10 +167,20 @@ async function AdViewUnitServer({
|
|
|
309
167
|
const groupItems = responseGroup?.items;
|
|
310
168
|
if (groupItems && groupItems.length) {
|
|
311
169
|
return groupItems.map(({ tracker, ...data }) => {
|
|
312
|
-
return /* @__PURE__ */
|
|
170
|
+
return /* @__PURE__ */ import_react3.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state: {
|
|
171
|
+
isLoading: true,
|
|
172
|
+
isComplete: true,
|
|
173
|
+
isInitial: false,
|
|
174
|
+
isError: isLoadingError
|
|
175
|
+
} }));
|
|
313
176
|
});
|
|
314
177
|
}
|
|
315
|
-
return /* @__PURE__ */
|
|
178
|
+
return /* @__PURE__ */ import_react3.default.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state: {
|
|
179
|
+
isLoading: true,
|
|
180
|
+
isComplete: true,
|
|
181
|
+
isInitial: false,
|
|
182
|
+
isError: isLoadingError
|
|
183
|
+
} }));
|
|
316
184
|
}
|
|
317
185
|
var AdViewUnit_server_default = AdViewUnitServer;
|
|
318
186
|
//# sourceMappingURL=AdViewUnit.server.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.server.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/AdViewUnitWrapper.server.tsx","../../src/AdViewUnit/AdViewUnitNative.tsx","../../src/AdViewUnit/AdViewUnitProxy.tsx","../../src/AdViewUnit/AdViewUnitBanner.tsx","../../src/AdViewUnit/AdViewUnitTypeSwitch.tsx"],"sourcesContent":["import React from 'react';\n\nimport { AdViewGroupItem } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { AdViewUnitPropsBase, AdViewUnitServerChildren } from '../types';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport AdViewUnitWrapperServer from './AdViewUnitWrapper.server';\n\nexport type AdViewUnitServerProps = AdViewUnitPropsBase & {\n children?: AdViewUnitServerChildren;\n};\n\nasync function AdViewUnitServer({\n unitId,\n format,\n children,\n onDefault = () => null,\n ...config\n}: AdViewUnitServerProps) {\n const baseConfig = getResolveConfig(config);\n const requestUrl = getAdRequestUrl(baseConfig, unitId, format);\n const response = await adViewFetcher(requestUrl);\n const isLoadingError = response instanceof Error;\n const error = isLoadingError ? response : undefined;\n const responseGroup =\n response instanceof Error ? null : response?.groups?.[0];\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = responseGroup?.items;\n\n if (groupItems && groupItems.length) {\n return groupItems.map(({ tracker, ...data }: AdViewGroupItem) => {\n return (\n <AdViewUnitTracking key={data.id} {...tracker}>\n <AdViewUnitWrapperServer data={data} onDefault={onDefault}>\n {children}\n </AdViewUnitWrapperServer>\n </AdViewUnitTracking>\n );\n });\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n <AdViewUnitWrapperServer data={error} onDefault={onDefault}>\n {children}\n </AdViewUnitWrapperServer>\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitServer;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return <div ref={wrapperRef}>{children}</div>;\n}\n\nexport default AdViewUnitTracking;\n","import React from 'react';\nimport AdViewUnitTypeSwitch from './/AdViewUnitTypeSwitch';\n\nimport {\n AdViewUnitDefault,\n AdViewUnitServerChildren,\n AdViewUnitServerChildrenProps,\n} from '../types';\n\nexport type AdViewUnitWrapperServerProps = AdViewUnitServerChildrenProps & {\n children?: AdViewUnitServerChildren;\n onDefault?: AdViewUnitDefault;\n};\n\nasync function AdViewUnitWrapperServer({\n data,\n children,\n onDefault,\n}: AdViewUnitWrapperServerProps) {\n const isChildrenReactNode = React.isValidElement(children);\n const isChildrenFunction = typeof children === 'function';\n const isLoadingError = data instanceof Error;\n\n if (isChildrenReactNode) {\n return React.cloneElement(children, { data, onDefault });\n }\n\n if (isChildrenFunction) {\n return children({ data, onDefault });\n }\n\n if (!children && !isLoadingError) {\n return <AdViewUnitTypeSwitch data={data} onDefault={onDefault} />;\n }\n\n if (React.isValidElement(onDefault)) {\n return React.cloneElement(onDefault);\n }\n\n if (typeof onDefault === 'function') {\n return onDefault();\n }\n\n return null;\n}\n\nexport default AdViewUnitWrapperServer;\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdViewDataClient, AdViewStyleTokensNative } from '../types';\n\ntype AdViewUnitNativeProps = AdViewDataClient & {\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitNative({\n assets,\n fields,\n url,\n classNames,\n}: AdViewUnitNativeProps) {\n const asset = getAssetByName('main', assets);\n\n if (!url) {\n return null;\n }\n\n return (\n <div className={classNames?.container}>\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n className={classNames?.imageLink}\n >\n {asset && (\n <img\n alt={fields?.title}\n title={fields?.title}\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : undefined}\n className={classNames?.image}\n style={{ objectFit: 'cover', width: '100%', height: '100%' }}\n />\n )}\n </a>\n <div className={classNames?.label}>\n {fields?.title && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"titleLink\"\n className={classNames?.titleLink}\n >\n {fields.title}\n </a>\n )}\n {fields?.description && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"descriptionLink\"\n className={classNames?.descriptionLink}\n >\n {fields.description}\n </a>\n )}\n {fields?.brandname && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"brandNameLink\"\n className={classNames?.brandNameLink}\n >\n {fields.brandname}\n </a>\n )}\n {fields?.phone && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"phoneLink\"\n className={classNames?.phoneLink}\n >\n {fields.phone}\n </a>\n )}\n {fields?.url && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"urlLink\"\n className={classNames?.urlLink}\n >\n {fields?.url}\n </a>\n )}\n </div>\n </div>\n );\n}\n\nexport default AdViewUnitNative;\n","import React from 'react';\nimport { AdViewDataClient, AdViewStyleTokensNative } from '../types';\n\ntype AdViewUnitProxyProps = AdViewDataClient & {\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitProxy({\n // assets,\n fields,\n url,\n}: AdViewUnitProxyProps) {\n const iframeSrc = fields?.url || url;\n\n if (!iframeSrc) {\n return null;\n }\n\n return (\n <iframe\n width=\"100%\"\n height=\"100%\"\n frameBorder=\"0\"\n marginWidth={0}\n marginHeight={0}\n allowTransparency={true}\n scrolling=\"no\"\n allowFullScreen={true}\n style={{ width: '100%', height: '100%' }}\n src={iframeSrc}\n ></iframe>\n );\n}\n\nexport default AdViewUnitProxy;\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdViewDataClient, AdViewStyleTokensNative } from '../types';\n\ntype AdViewUnitBannerProps = AdViewDataClient & {\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitBanner({ assets, url }: AdViewUnitBannerProps) {\n const asset = getAssetByName('main', assets);\n\n return (\n <center>\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n className=\"banner\"\n style={{ fontSize: 0 }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n />\n )}\n </a>\n </center>\n );\n}\n\nexport default AdViewUnitBanner;\n","import {\n AdViewDataClient,\n AdViewStyleTokens,\n AdViewUnitDefault,\n} from '../types';\nimport AdViewUnitNative from './AdViewUnitNative';\nimport AdViewUnitProxy from './AdViewUnitProxy';\nimport AdViewUnitBanner from './AdViewUnitBanner';\nimport React from 'react';\n\ntype AdViewUnitDefaultProps = {\n data?: AdViewDataClient;\n classNames?: AdViewStyleTokens;\n onDefault?: AdViewUnitDefault;\n};\n\nfunction AdViewUnitTypeSwitch({\n data,\n classNames,\n onDefault,\n}: AdViewUnitDefaultProps) {\n switch (data?.type) {\n case 'native':\n return <AdViewUnitNative {...data} classNames={classNames?.native} />;\n case 'proxy':\n return <AdViewUnitProxy {...data} classNames={classNames?.proxy} />;\n case 'banner':\n return <AdViewUnitBanner {...data} classNames={classNames?.banner} />;\n default:\n if (React.isValidElement(onDefault)) {\n return React.cloneElement(onDefault);\n }\n\n if (typeof onDefault === 'function') {\n return onDefault();\n }\n\n return null;\n }\n}\n\nexport default AdViewUnitTypeSwitch;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkB;AAGlB,IAAAC,gBAAiE;;;ACDjE,mBAA2C;AAC3C,mBAA+D;AAS/D,SAAS,mBAAmB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4B;AAC1B,QAAM,WAAW,OAAO,WAAW;AACnC,QAAM,iBAAa,qBAAuB,IAAI;AAC9C,QAAM,wCAAoC;AAAA,IACxC,UAAM,yCAA2B,WAAW;AAAA,IAC5C,CAAC,WAAW;AAAA,EACd;AACA,QAAM,sCAAkC;AAAA,IACtC,CAAC,YAAyC;AACxC,cAAQ,QAAQ,WAAS;AACvB,YAAI,MAAM,gBAAgB;AACxB,uDAA2B,KAAK;AAChC,oCAA0B,UAAU,WAAW,OAAQ;AAAA,QACzD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,KAAK;AAAA,EACR;AACA,QAAM,+BAA2B,sBAAqC,MAAM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U;AAC/C,QAAM,iBAAiB,oBAAoB;AAC3C,QAAM,QAAQ,iBAAiB,WAAW;AAC1C,QAAM,gBACJ,oBAAoB,QAAQ,OAAO,UAAU,SAAS,CAAC;AACzD,QAAM,gBAAgB,eAAe,kBAAkB,CAAC;AACxD,QAAM,aAAa,eAAe;AAElC,MAAI,cAAc,WAAW,QAAQ;AACnC,WAAO,WAAW,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,MAAuB;AAC/D,aACE,8BAAAC,QAAA,cAAC,8BAAmB,KAAK,KAAK,IAAK,GAAG,WACpC,8BAAAA,QAAA,cAAC,oCAAwB,MAAY,aAClC,QACH,CACF;AAAA,IAEJ,CAAC;AAAA,EACH;AAEA,SACE,8BAAAA,QAAA,cAAC,8BAAoB,GAAG,iBACtB,8BAAAA,QAAA,cAAC,oCAAwB,MAAM,OAAO,aACnC,QACH,CACF;AAEJ;AAEA,IAAO,4BAAQ;","names":["import_react","import_utils","React","import_react","import_utils","import_react","React","import_react","React","import_utils","import_react","React","import_react","React","React","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.server.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx"],"sourcesContent":["import React from 'react';\n\nimport { AdViewGroupItem } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { AdViewUnitPropsBase, AdViewUnitServerChildren } from '../types';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\n\nexport type AdViewUnitServerProps = AdViewUnitPropsBase & {\n children?: AdViewUnitServerChildren;\n};\n\nasync function AdViewUnitServer({\n unitId,\n format,\n children,\n ...config\n}: AdViewUnitServerProps) {\n const baseConfig = getResolveConfig(config);\n const requestUrl = getAdRequestUrl(baseConfig, unitId, format);\n const response = await adViewFetcher(requestUrl);\n const isLoadingError = response instanceof Error;\n const error = isLoadingError ? response : undefined;\n const responseGroup =\n response instanceof Error ? null : response?.groups?.[0];\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = responseGroup?.items;\n\n if (groupItems && groupItems.length) {\n return groupItems.map(({ tracker, ...data }: AdViewGroupItem) => {\n return (\n <AdViewUnitTracking key={data.id} {...tracker}>\n {renderAnyTemplates(children, {data, type: data.type || 'default', error, state: {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n }})}\n </AdViewUnitTracking>\n );\n });\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n {renderAnyTemplates(children, {data: null, type: 'default', error, state: {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n }})}\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitServer;\n","//\n// Example\n// <AdView.Unit>\n// <AdView.Template type=\"banner\">\n// <...>\n// </AdView.Template>\n// </AdView.Unit>\n//\n\nimport React, { JSX } from 'react';\nimport { AdViewUnitClientChildrenProps, AdViewUnitTemplateProps, AdViewUnitTemplateTypeProps } from '../types';\n\n// TemplateListRender is a function that takes a list of TemplateType and returns a React element\nexport type TemplateListRender = (tmpls: TemplateElement[]) => React.ReactElement | JSX.Element;\n\n// TemplateType is a React component that can be used to render ad templates\nexport type TemplateType = React.Component<AdViewUnitTemplateProps>;\nexport type TemplateElement = React.ReactElement<AdViewUnitTemplateProps>;\n\n// TemplateTypeFunction is a function that takes AdViewUnitTemplateTypeProps and returns a React node or element\nexport type TemplateTypeFunction = (props: AdViewUnitTemplateTypeProps) => React.ReactNode | React.ReactElement;\n\n// templateFromListRender is a function that takes a list of TemplateType and returns a React element\nexport const templateFromListRender = (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, wrap?: (children: React.ReactNode) => React.ReactNode): JSX.Element | React.ReactElement => {\n let renderedRemplates = tmpls.map((tmpl, index) => {\n let tmp = renderTemplate(tmpl, data);\n return !!tmp && React.isValidElement(tmp)\n ? <React.Fragment key={index}>{!!wrap ? wrap(tmp) : tmp}</React.Fragment>\n : null;\n }).filter(it => !!it);\n\n if (!renderedRemplates.length) {\n renderedRemplates = tmpls.map((tmpl, index) => {\n let tmp = renderTemplate(tmpl, {...data, type: 'default'});\n return !!tmp && React.isValidElement(tmp)\n ? <React.Fragment key={index}>{!!wrap ? wrap(tmp) : tmp}</React.Fragment>\n : null;\n }).filter(it => !!it);\n }\n\n return (<>{renderedRemplates}</>);\n};\n\n// renderTemplate is a function that takes a TemplateType or a function and returns a React node\nexport const renderTemplate = (tmpl: TemplateElement | TemplateTypeFunction, data: AdViewUnitTemplateTypeProps): React.ReactNode => {\n const isFunction = typeof tmpl === 'function';\n const isReactElement = React.isValidElement(tmpl);\n\n if (isReactElement) {\n // Extract type and children from the React element\n const { type, children } = (tmpl as TemplateElement).props;\n console.log('=====>\\nrenderTemplate: React element detected, type:', type, 'data:', data.type, data.type !== type);\n // If the type does not match, return null\n if (data.type !== type) {\n return null;\n }\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(data as AdViewUnitClientChildrenProps);\n }\n console.log('CLONE ELEMENT', tmpl);\n // If children is a React element, clone it with the new props\n return React.cloneElement((tmpl as TemplateElement), {\n ...data,\n children: children,\n });\n }\n\n if (isFunction) {\n return tmpl(data);\n }\n\n return null;\n}\n\n// renderTemplates is a function that takes a list of TemplateType and returns a React element\nexport const renderTemplates = (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender): React.ReactNode | React.ReactElement | JSX.Element => {\n return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);\n};\n\nexport const renderAnyTemplates = (tmpls: any, data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender): React.ReactNode | React.ReactElement | JSX.Element | null => {\n if (!tmpls) {\n return null;\n }\n\n if (Array.isArray(tmpls)) {\n return renderTemplates(tmpls as TemplateElement[], data, listRender);\n }\n\n if (typeof tmpls === 'function') {\n return tmpls(data);\n }\n\n if (React.isValidElement(tmpls)) {\n return templateFromListRender([tmpls as TemplateElement], data);\n }\n\n return null;\n}\n\n// Template is a React component that renders a template based on the type and data provided\n// Example usage:\n// <AdView.Unit>\n// <AdView.Template type=\"banner\" data={{...}}>\n// </AdView.Unit>\nconst AdViewUnitTemplate = ({ type, children, ...data }: AdViewUnitTemplateProps) => {\n const tmplProps: AdViewUnitTemplateTypeProps = {\n type,\n ...data,\n };\n\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(tmplProps as AdViewUnitClientChildrenProps) as React.ReactElement;\n }\n\n // If children is a React element, clone it with the new props\n if (React.isValidElement(children)) {\n return React.cloneElement(children, tmplProps);\n }\n\n // If no children are provided, return an empty fragment\n return <></>;\n}\n\nexport default AdViewUnitTemplate;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return <div ref={wrapperRef}>{children}</div>;\n}\n\nexport default AdViewUnitTracking;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkB;AAGlB,IAAAC,gBAAiE;;;ACMjE,mBAA2B;AAcpB,IAAM,yBAAyB,CAAC,OAA0B,MAAmC,SAA4F;AAC9L,MAAI,oBAAoB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,MAAM,eAAe,MAAM,IAAI;AACnC,WAAO,CAAC,CAAC,OAAO,aAAAC,QAAM,eAAe,GAAG,IACpC,6BAAAA,QAAA,cAAC,aAAAA,QAAM,UAAN,EAAe,KAAK,SAAQ,CAAC,CAAC,OAAO,KAAK,GAAG,IAAI,GAAI,IACtD;AAAA,EACN,CAAC,EAAE,OAAO,QAAM,CAAC,CAAC,EAAE;AAEpB,MAAI,CAAC,kBAAkB,QAAQ;AAC7B,wBAAoB,MAAM,IAAI,CAAC,MAAM,UAAU;AAC7C,UAAI,MAAM,eAAe,MAAM,EAAC,GAAG,MAAM,MAAM,UAAS,CAAC;AACzD,aAAO,CAAC,CAAC,OAAO,aAAAA,QAAM,eAAe,GAAG,IACpC,6BAAAA,QAAA,cAAC,aAAAA,QAAM,UAAN,EAAe,KAAK,SAAQ,CAAC,CAAC,OAAO,KAAK,GAAG,IAAI,GAAI,IACtD;AAAA,IACN,CAAC,EAAE,OAAO,QAAM,CAAC,CAAC,EAAE;AAAA,EACtB;AAEA,SAAQ,6BAAAA,QAAA,2BAAAA,QAAA,gBAAG,iBAAkB;AAC/B;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M,6BAAc,UAAU;AAC/C,QAAM,iBAAiB,oBAAoB;AAC3C,QAAM,QAAQ,iBAAiB,WAAW;AAC1C,QAAM,gBACJ,oBAAoB,QAAQ,OAAO,UAAU,SAAS,CAAC;AACzD,QAAM,gBAAgB,eAAe,kBAAkB,CAAC;AACxD,QAAM,aAAa,eAAe;AAElC,MAAI,cAAc,WAAW,QAAQ;AACnC,WAAO,WAAW,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,MAAuB;AAC/D,aACE,8BAAAC,QAAA,cAAC,8BAAmB,KAAK,KAAK,IAAK,GAAG,WACnC,mBAAmB,UAAU,EAAC,MAAM,MAAM,KAAK,QAAQ,WAAW,OAAO,OAAO;AAAA,QAC/E,WAAW;AAAA,QACX,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,SAAS;AAAA,MACX,EAAC,CAAC,CACJ;AAAA,IAEJ,CAAC;AAAA,EACH;AAEA,SACE,8BAAAA,QAAA,cAAC,8BAAoB,GAAG,iBACrB,mBAAmB,UAAU,EAAC,MAAM,MAAM,MAAM,WAAW,OAAO,OAAO;AAAA,IACxE,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,SAAS;AAAA,EACX,EAAC,CAAC,CACJ;AAEJ;AAEA,IAAO,4BAAQ;","names":["import_react","import_utils","React","import_react","React","React"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { A as AdViewUnitPropsBase, b as AdViewUnitServerChildren } from '../types-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { A as AdViewUnitPropsBase, b as AdViewUnitServerChildren } from '../types-B65WDsgh.cjs';
|
|
3
3
|
import '@adview/core/typings';
|
|
4
4
|
|
|
5
5
|
type AdViewUnitServerProps = AdViewUnitPropsBase & {
|
|
6
6
|
children?: AdViewUnitServerChildren;
|
|
7
7
|
};
|
|
8
|
-
declare function AdViewUnitServer({ unitId, format, children,
|
|
8
|
+
declare function AdViewUnitServer({ unitId, format, children, ...config }: AdViewUnitServerProps): Promise<React.JSX.Element | React.JSX.Element[]>;
|
|
9
9
|
|
|
10
10
|
export { type AdViewUnitServerProps, AdViewUnitServer as default };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { A as AdViewUnitPropsBase, b as AdViewUnitServerChildren } from '../types-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { A as AdViewUnitPropsBase, b as AdViewUnitServerChildren } from '../types-B65WDsgh.js';
|
|
3
3
|
import '@adview/core/typings';
|
|
4
4
|
|
|
5
5
|
type AdViewUnitServerProps = AdViewUnitPropsBase & {
|
|
6
6
|
children?: AdViewUnitServerChildren;
|
|
7
7
|
};
|
|
8
|
-
declare function AdViewUnitServer({ unitId, format, children,
|
|
8
|
+
declare function AdViewUnitServer({ unitId, format, children, ...config }: AdViewUnitServerProps): Promise<React.JSX.Element | React.JSX.Element[]>;
|
|
9
9
|
|
|
10
10
|
export { type AdViewUnitServerProps, AdViewUnitServer as default };
|