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