@adview/react 1.0.13 → 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.
Files changed (101) hide show
  1. package/dist/AdViewUnit/AdViewUnit.cjs +106 -298
  2. package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
  3. package/dist/AdViewUnit/AdViewUnit.client.cjs +86 -256
  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 +69 -239
  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 +85 -277
  12. package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
  13. package/dist/AdViewUnit/AdViewUnit.server.cjs +82 -214
  14. package/dist/AdViewUnit/AdViewUnit.server.cjs.map +1 -1
  15. package/dist/AdViewUnit/AdViewUnit.server.d.cts +2 -2
  16. package/dist/AdViewUnit/AdViewUnit.server.d.ts +2 -2
  17. package/dist/AdViewUnit/AdViewUnit.server.js +72 -204
  18. package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
  19. package/dist/AdViewUnit/{AdViewUnitBanner.cjs → AdViewUnitBannerTemplate.cjs} +17 -14
  20. package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs.map +1 -0
  21. package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +12 -0
  22. package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +12 -0
  23. package/dist/AdViewUnit/AdViewUnitBannerTemplate.js +32 -0
  24. package/dist/AdViewUnit/AdViewUnitBannerTemplate.js.map +1 -0
  25. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs +48 -0
  26. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs.map +1 -0
  27. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +17 -0
  28. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +17 -0
  29. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js +17 -0
  30. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js.map +1 -0
  31. package/dist/AdViewUnit/{AdViewUnitNative.cjs → AdViewUnitNativeTemplate.cjs} +12 -13
  32. package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs.map +1 -0
  33. package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +11 -0
  34. package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +11 -0
  35. package/dist/AdViewUnit/{AdViewUnitNative.js → AdViewUnitNativeTemplate.js} +9 -10
  36. package/dist/AdViewUnit/AdViewUnitNativeTemplate.js.map +1 -0
  37. package/dist/AdViewUnit/{AdViewUnitProxy.cjs → AdViewUnitProxyTemplate.cjs} +14 -13
  38. package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs.map +1 -0
  39. package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +12 -0
  40. package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +12 -0
  41. package/dist/AdViewUnit/AdViewUnitProxyTemplate.js +33 -0
  42. package/dist/AdViewUnit/AdViewUnitProxyTemplate.js.map +1 -0
  43. package/dist/AdViewUnit/AdViewUnitTemplate.cjs +114 -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 +77 -0
  48. package/dist/AdViewUnit/AdViewUnitTemplate.js.map +1 -1
  49. package/dist/AdViewUnit/useAdViewController.cjs +5 -1
  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 -1
  54. package/dist/AdViewUnit/useAdViewController.js.map +1 -1
  55. package/dist/index.cjs +250 -232
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +8 -7
  58. package/dist/index.d.ts +8 -7
  59. package/dist/index.js +232 -222
  60. package/dist/index.js.map +1 -1
  61. package/dist/server.cjs +216 -162
  62. package/dist/server.cjs.map +1 -1
  63. package/dist/server.d.cts +7 -6
  64. package/dist/server.d.ts +7 -6
  65. package/dist/server.js +196 -149
  66. package/dist/server.js.map +1 -1
  67. package/dist/{types-BaV07oMT.d.cts → types-B65WDsgh.d.cts} +29 -25
  68. package/dist/{types-BaV07oMT.d.ts → types-B65WDsgh.d.ts} +29 -25
  69. package/package.json +1 -1
  70. package/dist/AdViewUnit/AdViewUnitBanner.cjs.map +0 -1
  71. package/dist/AdViewUnit/AdViewUnitBanner.d.cts +0 -10
  72. package/dist/AdViewUnit/AdViewUnitBanner.d.ts +0 -10
  73. package/dist/AdViewUnit/AdViewUnitBanner.js +0 -29
  74. package/dist/AdViewUnit/AdViewUnitBanner.js.map +0 -1
  75. package/dist/AdViewUnit/AdViewUnitNative.cjs.map +0 -1
  76. package/dist/AdViewUnit/AdViewUnitNative.d.cts +0 -10
  77. package/dist/AdViewUnit/AdViewUnitNative.d.ts +0 -10
  78. package/dist/AdViewUnit/AdViewUnitNative.js.map +0 -1
  79. package/dist/AdViewUnit/AdViewUnitProxy.cjs.map +0 -1
  80. package/dist/AdViewUnit/AdViewUnitProxy.d.cts +0 -10
  81. package/dist/AdViewUnit/AdViewUnitProxy.d.ts +0 -10
  82. package/dist/AdViewUnit/AdViewUnitProxy.js +0 -32
  83. package/dist/AdViewUnit/AdViewUnitProxy.js.map +0 -1
  84. package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs +0 -203
  85. package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs.map +0 -1
  86. package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.cts +0 -12
  87. package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.ts +0 -12
  88. package/dist/AdViewUnit/AdViewUnitTypeSwitch.js +0 -170
  89. package/dist/AdViewUnit/AdViewUnitTypeSwitch.js.map +0 -1
  90. package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs +0 -250
  91. package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs.map +0 -1
  92. package/dist/AdViewUnit/AdViewUnitWrapper.client.d.cts +0 -11
  93. package/dist/AdViewUnit/AdViewUnitWrapper.client.d.ts +0 -11
  94. package/dist/AdViewUnit/AdViewUnitWrapper.client.js +0 -220
  95. package/dist/AdViewUnit/AdViewUnitWrapper.client.js.map +0 -1
  96. package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs +0 -232
  97. package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs.map +0 -1
  98. package/dist/AdViewUnit/AdViewUnitWrapper.server.d.cts +0 -11
  99. package/dist/AdViewUnit/AdViewUnitWrapper.server.d.ts +0 -11
  100. package/dist/AdViewUnit/AdViewUnitWrapper.server.js +0 -201
  101. package/dist/AdViewUnit/AdViewUnitWrapper.server.js.map +0 -1
@@ -35,14 +35,71 @@ __export(AdViewUnit_exports, {
35
35
  default: () => AdViewUnit_default
36
36
  });
37
37
  module.exports = __toCommonJS(AdViewUnit_exports);
38
- var import_react12 = __toESM(require("react"), 1);
38
+ var import_react7 = __toESM(require("react"), 1);
39
39
 
40
40
  // src/AdViewUnit/AdViewUnit.client.tsx
41
- var import_react9 = __toESM(require("react"), 1);
41
+ var import_react5 = __toESM(require("react"), 1);
42
+
43
+ // src/AdViewUnit/AdViewUnitTemplate.tsx
44
+ var import_react = __toESM(require("react"), 1);
45
+ var templateFromListRender = (tmpls, data, wrap) => {
46
+ let renderedRemplates = tmpls.map((tmpl, index) => {
47
+ let tmp = renderTemplate(tmpl, data);
48
+ return !!tmp && import_react.default.isValidElement(tmp) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
49
+ }).filter((it) => !!it);
50
+ if (!renderedRemplates.length) {
51
+ renderedRemplates = tmpls.map((tmpl, index) => {
52
+ let tmp = renderTemplate(tmpl, { ...data, type: "default" });
53
+ return !!tmp && import_react.default.isValidElement(tmp) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
54
+ }).filter((it) => !!it);
55
+ }
56
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, renderedRemplates);
57
+ };
58
+ var renderTemplate = (tmpl, data) => {
59
+ const isFunction = typeof tmpl === "function";
60
+ const isReactElement = import_react.default.isValidElement(tmpl);
61
+ if (isReactElement) {
62
+ const { type, children } = tmpl.props;
63
+ console.log("=====>\nrenderTemplate: React element detected, type:", type, "data:", data.type, data.type !== type);
64
+ if (data.type !== type) {
65
+ return null;
66
+ }
67
+ if (typeof children === "function") {
68
+ return children(data);
69
+ }
70
+ console.log("CLONE ELEMENT", tmpl);
71
+ return import_react.default.cloneElement(tmpl, {
72
+ ...data,
73
+ children
74
+ });
75
+ }
76
+ if (isFunction) {
77
+ return tmpl(data);
78
+ }
79
+ return null;
80
+ };
81
+ var renderTemplates = (tmpls, data, listRender) => {
82
+ return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);
83
+ };
84
+ var renderAnyTemplates = (tmpls, data, listRender) => {
85
+ if (!tmpls) {
86
+ return null;
87
+ }
88
+ if (Array.isArray(tmpls)) {
89
+ return renderTemplates(tmpls, data, listRender);
90
+ }
91
+ if (typeof tmpls === "function") {
92
+ return tmpls(data);
93
+ }
94
+ if (import_react.default.isValidElement(tmpls)) {
95
+ return templateFromListRender([tmpls], data);
96
+ }
97
+ return null;
98
+ };
42
99
 
43
100
  // src/AdViewUnit/AdViewUnitTracking.tsx
44
101
  var import_utils = require("@adview/core/utils");
45
- var import_react = __toESM(require("react"), 1);
102
+ var import_react2 = __toESM(require("react"), 1);
46
103
  function AdViewUnitTracking({
47
104
  impressions,
48
105
  views,
@@ -50,12 +107,12 @@ function AdViewUnitTracking({
50
107
  children
51
108
  }) {
52
109
  const isServer = typeof window === "undefined";
53
- const wrapperRef = (0, import_react.useRef)(null);
54
- const executeImpressionsTrackingHandler = (0, import_react.useCallback)(
110
+ const wrapperRef = (0, import_react2.useRef)(null);
111
+ const executeImpressionsTrackingHandler = (0, import_react2.useCallback)(
55
112
  () => (0, import_utils.executeImpressionsTracking)(impressions),
56
113
  [impressions]
57
114
  );
58
- const trackingObserverInstanceHandler = (0, import_react.useCallback)(
115
+ const trackingObserverInstanceHandler = (0, import_react2.useCallback)(
59
116
  (entries) => {
60
117
  entries.forEach((entry) => {
61
118
  if (entry.isIntersecting) {
@@ -66,14 +123,14 @@ function AdViewUnitTracking({
66
123
  },
67
124
  [views]
68
125
  );
69
- const trackingObserverInstance = (0, import_react.useMemo)(() => {
126
+ const trackingObserverInstance = (0, import_react2.useMemo)(() => {
70
127
  return !isServer ? new IntersectionObserver(trackingObserverInstanceHandler) : null;
71
128
  }, [isServer, trackingObserverInstanceHandler]);
72
- const clickTrackerHandler = (0, import_react.useCallback)(() => {
129
+ const clickTrackerHandler = (0, import_react2.useCallback)(() => {
73
130
  (0, import_utils.executeImpressionsTracking)(clicks);
74
131
  wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
75
132
  }, [clicks]);
76
- (0, import_react.useEffect)(() => {
133
+ (0, import_react2.useEffect)(() => {
77
134
  if (wrapperRef.current && trackingObserverInstance) {
78
135
  executeImpressionsTrackingHandler();
79
136
  wrapperRef.current?.addEventListener("click", clickTrackerHandler);
@@ -91,246 +148,37 @@ function AdViewUnitTracking({
91
148
  executeImpressionsTrackingHandler,
92
149
  clickTrackerHandler
93
150
  ]);
94
- return /* @__PURE__ */ import_react.default.createElement("div", { ref: wrapperRef }, children);
151
+ return /* @__PURE__ */ import_react2.default.createElement("div", { ref: wrapperRef }, children);
95
152
  }
96
153
  var AdViewUnitTracking_default = AdViewUnitTracking;
97
154
 
98
- // src/AdViewUnit/AdViewUnitWrapper.client.tsx
99
- var import_react6 = __toESM(require("react"), 1);
100
-
101
- // src/AdViewUnit/AdViewUnitNative.tsx
102
- var import_utils2 = require("@adview/core/utils");
103
- var import_react2 = __toESM(require("react"), 1);
104
- function AdViewUnitNative({
105
- assets,
106
- fields,
107
- url,
108
- classNames
109
- }) {
110
- const asset = (0, import_utils2.getAssetByName)("main", assets);
111
- if (!url) {
112
- return null;
113
- }
114
- return /* @__PURE__ */ import_react2.default.createElement("div", { className: classNames?.container }, /* @__PURE__ */ import_react2.default.createElement(
115
- "a",
116
- {
117
- target: "_blank",
118
- rel: "noopener noreferrer",
119
- href: (0, import_utils2.getPrepareURL)(url),
120
- className: classNames?.imageLink
121
- },
122
- asset && /* @__PURE__ */ import_react2.default.createElement(
123
- "img",
124
- {
125
- alt: fields?.title,
126
- title: fields?.title,
127
- src: asset.path,
128
- srcSet: asset.thumbs ? (0, import_utils2.getSrcSetCSSThumbs)(asset.thumbs) : void 0,
129
- className: classNames?.image,
130
- style: { objectFit: "cover", width: "100%", height: "100%" }
131
- }
132
- )
133
- ), /* @__PURE__ */ import_react2.default.createElement("div", { className: classNames?.label }, fields?.title && /* @__PURE__ */ import_react2.default.createElement(
134
- "a",
135
- {
136
- target: "_blank",
137
- rel: "noopener noreferrer",
138
- href: (0, import_utils2.getPrepareURL)(url),
139
- "data-class": "titleLink",
140
- className: classNames?.titleLink
141
- },
142
- fields.title
143
- ), fields?.description && /* @__PURE__ */ import_react2.default.createElement(
144
- "a",
145
- {
146
- target: "_blank",
147
- rel: "noopener noreferrer",
148
- href: (0, import_utils2.getPrepareURL)(url),
149
- "data-class": "descriptionLink",
150
- className: classNames?.descriptionLink
151
- },
152
- fields.description
153
- ), fields?.brandname && /* @__PURE__ */ import_react2.default.createElement(
154
- "a",
155
- {
156
- target: "_blank",
157
- rel: "noopener noreferrer",
158
- href: (0, import_utils2.getPrepareURL)(url),
159
- "data-class": "brandNameLink",
160
- className: classNames?.brandNameLink
161
- },
162
- fields.brandname
163
- ), fields?.phone && /* @__PURE__ */ import_react2.default.createElement(
164
- "a",
165
- {
166
- target: "_blank",
167
- rel: "noopener noreferrer",
168
- href: (0, import_utils2.getPrepareURL)(url),
169
- "data-class": "phoneLink",
170
- className: classNames?.phoneLink
171
- },
172
- fields.phone
173
- ), fields?.url && /* @__PURE__ */ import_react2.default.createElement(
174
- "a",
175
- {
176
- target: "_blank",
177
- rel: "noopener noreferrer",
178
- href: (0, import_utils2.getPrepareURL)(url),
179
- "data-class": "urlLink",
180
- className: classNames?.urlLink
181
- },
182
- fields?.url
183
- )));
184
- }
185
- var AdViewUnitNative_default = AdViewUnitNative;
186
-
187
- // src/AdViewUnit/AdViewUnitProxy.tsx
188
- var import_react3 = __toESM(require("react"), 1);
189
- function AdViewUnitProxy({
190
- // assets,
191
- fields,
192
- url
193
- }) {
194
- const iframeSrc = fields?.url || url;
195
- if (!iframeSrc) {
196
- return null;
197
- }
198
- return /* @__PURE__ */ import_react3.default.createElement(
199
- "iframe",
200
- {
201
- width: "100%",
202
- height: "100%",
203
- frameBorder: "0",
204
- marginWidth: 0,
205
- marginHeight: 0,
206
- allowTransparency: true,
207
- scrolling: "no",
208
- allowFullScreen: true,
209
- style: { width: "100%", height: "100%" },
210
- src: iframeSrc
211
- }
212
- );
213
- }
214
- var AdViewUnitProxy_default = AdViewUnitProxy;
215
-
216
- // src/AdViewUnit/AdViewUnitBanner.tsx
217
- var import_utils3 = require("@adview/core/utils");
218
- var import_react4 = __toESM(require("react"), 1);
219
- function AdViewUnitBanner({ assets, url }) {
220
- const asset = (0, import_utils3.getAssetByName)("main", assets);
221
- return /* @__PURE__ */ import_react4.default.createElement("center", null, /* @__PURE__ */ import_react4.default.createElement(
222
- "a",
223
- {
224
- target: "_blank",
225
- rel: "noopener noreferrer",
226
- href: (0, import_utils3.getPrepareURL)(url),
227
- className: "banner",
228
- style: { fontSize: 0 }
229
- },
230
- asset && /* @__PURE__ */ import_react4.default.createElement(
231
- "img",
232
- {
233
- alt: "main",
234
- src: asset.path,
235
- srcSet: asset.thumbs ? (0, import_utils3.getSrcSetCSSThumbs)(asset.thumbs) : ""
236
- }
237
- )
238
- ));
239
- }
240
- var AdViewUnitBanner_default = AdViewUnitBanner;
241
-
242
- // src/AdViewUnit/AdViewUnitTypeSwitch.tsx
243
- var import_react5 = __toESM(require("react"), 1);
244
- function AdViewUnitTypeSwitch({
245
- data,
246
- classNames,
247
- onDefault
248
- }) {
249
- switch (data?.type) {
250
- case "native":
251
- return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitNative_default, { ...data, classNames: classNames?.native });
252
- case "proxy":
253
- return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitProxy_default, { ...data, classNames: classNames?.proxy });
254
- case "banner":
255
- return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitBanner_default, { ...data, classNames: classNames?.banner });
256
- default:
257
- if (import_react5.default.isValidElement(onDefault)) {
258
- return import_react5.default.cloneElement(onDefault);
259
- }
260
- if (typeof onDefault === "function") {
261
- return onDefault();
262
- }
263
- return null;
264
- }
265
- }
266
- var AdViewUnitTypeSwitch_default = AdViewUnitTypeSwitch;
267
-
268
- // src/AdViewUnit/AdViewUnitWrapper.client.tsx
269
- function AdViewUnitWrapperClient({
270
- data,
271
- state,
272
- error,
273
- children,
274
- onDefault
275
- }) {
276
- const { isLoading, isError } = state;
277
- const isChildrenReactNode = import_react6.default.isValidElement(children);
278
- const isChildrenFunction = typeof children === "function";
279
- if (isChildrenReactNode) {
280
- return import_react6.default.cloneElement(children, {
281
- data,
282
- state,
283
- error,
284
- onDefault
285
- });
286
- }
287
- if (isChildrenFunction) {
288
- return children({
289
- data,
290
- state,
291
- error,
292
- onDefault
293
- });
294
- }
295
- if (isLoading) {
296
- return null;
297
- }
298
- if (!children && !isError && data) {
299
- return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitTypeSwitch_default, { data, onDefault });
300
- }
301
- if (import_react6.default.isValidElement(onDefault)) {
302
- return import_react6.default.cloneElement(onDefault);
303
- }
304
- if (typeof onDefault === "function") {
305
- return onDefault();
306
- }
307
- return null;
308
- }
309
- var AdViewUnitWrapper_client_default = AdViewUnitWrapperClient;
310
-
311
155
  // src/AdViewUnit/useAdViewController.ts
312
- var import_utils4 = require("@adview/core/utils");
313
- var import_react8 = require("react");
156
+ var import_utils2 = require("@adview/core/utils");
157
+ var import_react4 = require("react");
314
158
 
315
159
  // src/AdViewUnit/AdViewProvider.tsx
316
- var import_react7 = __toESM(require("react"), 1);
317
- var AdViewProviderContext = (0, import_react7.createContext)(
160
+ var import_react3 = __toESM(require("react"), 1);
161
+ var AdViewProviderContext = (0, import_react3.createContext)(
318
162
  {}
319
163
  );
320
164
 
321
165
  // src/AdViewUnit/useAdViewController.ts
322
166
  function useAdViewController(adUnitConfig, unitId, format) {
323
- const [adLoadState, setAdLoadState] = (0, import_react8.useState)("initial");
324
- const [adData, setAdData] = (0, import_react8.useState)(null);
325
- const [errorMessage, setErrorMessage] = (0, import_react8.useState)(null);
326
- const globalConfig = (0, import_react8.useContext)(AdViewProviderContext);
327
- const baseConfig = (0, import_utils4.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
328
- const requestUrl = (0, import_utils4.getAdRequestUrl)(baseConfig, unitId, format);
167
+ const [adLoadState, setAdLoadState] = (0, import_react4.useState)("initial");
168
+ const [adData, setAdData] = (0, import_react4.useState)(null);
169
+ const [errorMessage, setErrorMessage] = (0, import_react4.useState)(null);
170
+ const globalConfig = (0, import_react4.useContext)(AdViewProviderContext);
171
+ const baseConfig = (0, import_utils2.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
172
+ const requestUrl = (0, import_utils2.getAdRequestUrl)(
173
+ baseConfig,
174
+ unitId,
175
+ typeof format === "string" ? format : format?.join(",") || ""
176
+ );
329
177
  const loadAd = async () => {
330
178
  setAdLoadState("loading");
331
179
  try {
332
- console.log("Requesting ad data from:", import_utils4.adViewFetcher, "with URL:", requestUrl);
333
- const response = await (0, import_utils4.adViewFetcher)(requestUrl, baseConfig.defaultAdData);
180
+ console.log("Requesting ad data from:", import_utils2.adViewFetcher, "with URL:", requestUrl);
181
+ const response = await (0, import_utils2.adViewFetcher)(requestUrl, baseConfig.defaultAdData);
334
182
  console.log("AdViewController response:", response);
335
183
  if (response instanceof Error) {
336
184
  setAdLoadState("error");
@@ -351,7 +199,7 @@ function useAdViewController(adUnitConfig, unitId, format) {
351
199
  isComplete: adLoadState === "complete",
352
200
  isError: adLoadState === "error"
353
201
  };
354
- (0, import_react8.useEffect)(() => {
202
+ (0, import_react4.useEffect)(() => {
355
203
  loadAd();
356
204
  }, []);
357
205
  return [adData, errorMessage, loadState];
@@ -363,7 +211,6 @@ function AdViewUnitClient({
363
211
  unitId,
364
212
  format,
365
213
  children,
366
- onDefault = () => null,
367
214
  ...config
368
215
  }) {
369
216
  const [response, error, loadState] = useAdViewController_default(
@@ -374,76 +221,27 @@ function AdViewUnitClient({
374
221
  const responseGroup = error ? null : response?.groups?.[0];
375
222
  const customTracker = responseGroup?.custom_tracker ?? {};
376
223
  const groupItems = responseGroup?.items;
377
- if (groupItems && groupItems?.length) {
224
+ if (groupItems && groupItems?.length > 0) {
378
225
  return groupItems.map(({ tracker, ...data }) => {
379
- return /* @__PURE__ */ import_react9.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, /* @__PURE__ */ import_react9.default.createElement(
380
- AdViewUnitWrapper_client_default,
381
- {
382
- state: loadState,
383
- error,
384
- data,
385
- onDefault
386
- },
387
- children
388
- ));
226
+ return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state: loadState }));
389
227
  });
390
228
  }
391
- return /* @__PURE__ */ import_react9.default.createElement(AdViewUnitTracking_default, { ...customTracker }, /* @__PURE__ */ import_react9.default.createElement(
392
- AdViewUnitWrapper_client_default,
393
- {
394
- state: loadState,
395
- error,
396
- onDefault
397
- },
398
- children
399
- ));
229
+ return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state: loadState }));
400
230
  }
401
231
  var AdViewUnit_client_default = AdViewUnitClient;
402
232
 
403
233
  // src/AdViewUnit/AdViewUnit.server.tsx
404
- var import_react11 = __toESM(require("react"), 1);
405
- var import_utils5 = require("@adview/core/utils");
406
-
407
- // src/AdViewUnit/AdViewUnitWrapper.server.tsx
408
- var import_react10 = __toESM(require("react"), 1);
409
- async function AdViewUnitWrapperServer({
410
- data,
411
- children,
412
- onDefault
413
- }) {
414
- const isChildrenReactNode = import_react10.default.isValidElement(children);
415
- const isChildrenFunction = typeof children === "function";
416
- const isLoadingError = data instanceof Error;
417
- if (isChildrenReactNode) {
418
- return import_react10.default.cloneElement(children, { data, onDefault });
419
- }
420
- if (isChildrenFunction) {
421
- return children({ data, onDefault });
422
- }
423
- if (!children && !isLoadingError) {
424
- return /* @__PURE__ */ import_react10.default.createElement(AdViewUnitTypeSwitch_default, { data, onDefault });
425
- }
426
- if (import_react10.default.isValidElement(onDefault)) {
427
- return import_react10.default.cloneElement(onDefault);
428
- }
429
- if (typeof onDefault === "function") {
430
- return onDefault();
431
- }
432
- return null;
433
- }
434
- var AdViewUnitWrapper_server_default = AdViewUnitWrapperServer;
435
-
436
- // src/AdViewUnit/AdViewUnit.server.tsx
234
+ var import_react6 = __toESM(require("react"), 1);
235
+ var import_utils3 = require("@adview/core/utils");
437
236
  async function AdViewUnitServer({
438
237
  unitId,
439
238
  format,
440
239
  children,
441
- onDefault = () => null,
442
240
  ...config
443
241
  }) {
444
- const baseConfig = (0, import_utils5.getResolveConfig)(config);
445
- const requestUrl = (0, import_utils5.getAdRequestUrl)(baseConfig, unitId, format);
446
- const response = await (0, import_utils5.adViewFetcher)(requestUrl);
242
+ const baseConfig = (0, import_utils3.getResolveConfig)(config);
243
+ const requestUrl = (0, import_utils3.getAdRequestUrl)(baseConfig, unitId, format);
244
+ const response = await (0, import_utils3.adViewFetcher)(requestUrl);
447
245
  const isLoadingError = response instanceof Error;
448
246
  const error = isLoadingError ? response : void 0;
449
247
  const responseGroup = response instanceof Error ? null : response?.groups?.[0];
@@ -451,10 +249,20 @@ async function AdViewUnitServer({
451
249
  const groupItems = responseGroup?.items;
452
250
  if (groupItems && groupItems.length) {
453
251
  return groupItems.map(({ tracker, ...data }) => {
454
- return /* @__PURE__ */ import_react11.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, /* @__PURE__ */ import_react11.default.createElement(AdViewUnitWrapper_server_default, { data, onDefault }, children));
252
+ return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state: {
253
+ isLoading: true,
254
+ isComplete: true,
255
+ isInitial: false,
256
+ isError: isLoadingError
257
+ } }));
455
258
  });
456
259
  }
457
- return /* @__PURE__ */ import_react11.default.createElement(AdViewUnitTracking_default, { ...customTracker }, /* @__PURE__ */ import_react11.default.createElement(AdViewUnitWrapper_server_default, { data: error, onDefault }, children));
260
+ return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state: {
261
+ isLoading: true,
262
+ isComplete: true,
263
+ isInitial: false,
264
+ isError: isLoadingError
265
+ } }));
458
266
  }
459
267
  var AdViewUnit_server_default = AdViewUnitServer;
460
268
 
@@ -462,9 +270,9 @@ var AdViewUnit_server_default = AdViewUnitServer;
462
270
  function AdViewUnit(props) {
463
271
  const isServer = typeof window === "undefined";
464
272
  if (isServer) {
465
- return /* @__PURE__ */ import_react12.default.createElement(AdViewUnit_server_default, { ...props });
273
+ return /* @__PURE__ */ import_react7.default.createElement(AdViewUnit_server_default, { ...props });
466
274
  }
467
- return /* @__PURE__ */ import_react12.default.createElement(AdViewUnit_client_default, { ...props });
275
+ return /* @__PURE__ */ import_react7.default.createElement(AdViewUnit_client_default, { ...props });
468
276
  }
469
277
  var AdViewUnit_default = AdViewUnit;
470
278
  //# sourceMappingURL=AdViewUnit.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.tsx","../../src/AdViewUnit/AdViewUnit.client.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/AdViewUnitWrapper.client.tsx","../../src/AdViewUnit/AdViewUnitNative.tsx","../../src/AdViewUnit/AdViewUnitProxy.tsx","../../src/AdViewUnit/AdViewUnitBanner.tsx","../../src/AdViewUnit/AdViewUnitTypeSwitch.tsx","../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx","../../src/AdViewUnit/AdViewUnit.server.tsx","../../src/AdViewUnit/AdViewUnitWrapper.server.tsx"],"sourcesContent":["import React from 'react';\nimport AdViewUnitClient, { AdViewUnitClientProps } from './AdViewUnit.client';\nimport AdViewUnitServer, { AdViewUnitServerProps } from './AdViewUnit.server';\n\nexport type AdViewUnitProps = typeof window extends undefined\n ? AdViewUnitServerProps\n : AdViewUnitClientProps;\n\nfunction AdViewUnit(props: AdViewUnitProps) {\n const isServer = typeof window === 'undefined';\n\n if (isServer) {\n return <AdViewUnitServer {...(props as AdViewUnitServerProps)} />;\n }\n\n return <AdViewUnitClient {...(props as AdViewUnitClientProps)} />;\n}\n\nexport default AdViewUnit;\n","'use client';\n\nimport React from 'react';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport AdViewUnitWrapperClient from './AdViewUnitWrapper.client';\nimport useAdViewController from './useAdViewController';\n\nexport type AdViewUnitClientProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n};\n\nfunction AdViewUnitClient({\n unitId,\n format,\n children,\n onDefault = () => null,\n ...config\n}: AdViewUnitClientProps) {\n const [response, error, loadState] = useAdViewController(\n config,\n unitId,\n format,\n );\n const responseGroup = 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 }) => {\n return (\n <AdViewUnitTracking key={data.id} {...tracker}>\n <AdViewUnitWrapperClient\n state={loadState}\n error={error}\n data={data}\n onDefault={onDefault}\n >\n {children}\n </AdViewUnitWrapperClient>\n </AdViewUnitTracking>\n );\n });\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n <AdViewUnitWrapperClient\n state={loadState}\n error={error}\n onDefault={onDefault}\n >\n {children}\n </AdViewUnitWrapperClient>\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitClient;\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","'use client';\n\nimport React from 'react';\nimport AdViewUnitTypeSwitch from './AdViewUnitTypeSwitch';\nimport {\n AdViewUnitClientChildren,\n AdViewUnitClientChildrenProps,\n AdViewUnitDefault,\n} from '../types';\n\nexport type AdViewUnitWrapperClientProps = AdViewUnitClientChildrenProps & {\n children?: AdViewUnitClientChildren;\n onDefault: AdViewUnitDefault;\n};\n\nfunction AdViewUnitWrapperClient({\n data,\n state,\n error,\n children,\n onDefault,\n}: AdViewUnitWrapperClientProps) {\n const { isLoading, isError } = state;\n const isChildrenReactNode = React.isValidElement(children);\n const isChildrenFunction = typeof children === 'function';\n\n if (isChildrenReactNode) {\n return React.cloneElement(children, {\n data,\n state,\n error,\n onDefault,\n });\n }\n\n if (isChildrenFunction) {\n return children({\n data,\n state,\n error,\n onDefault,\n });\n }\n\n if (isLoading) {\n return null;\n }\n\n if (!children && !isError && data) {\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 AdViewUnitWrapperClient;\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","'use client';\n\nimport { AdViewData } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { useContext, useEffect, useState } from 'react';\nimport { AdLoadState, AdViewConfig } from '../types';\nimport { AdViewProviderContext } from './AdViewProvider';\n\ntype UseAdViewControllerProps = [AdViewData | null, Error | null, AdLoadState];\n\nfunction useAdViewController(\n adUnitConfig: AdViewConfig,\n unitId: string,\n format?: string,\n): UseAdViewControllerProps {\n const [adLoadState, setAdLoadState] = useState<string>('initial');\n const [adData, setAdData] = useState<AdViewData | null>(null);\n const [errorMessage, setErrorMessage] = useState<Error | null>(null);\n const globalConfig = useContext(AdViewProviderContext);\n const baseConfig = getResolveConfig({ ...adUnitConfig, ...globalConfig });\n const requestUrl = getAdRequestUrl(baseConfig, unitId, format);\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n console.log('Requesting ad data from:', adViewFetcher, 'with URL:', requestUrl);\n const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);\n console.log('AdViewController response:', response);\n\n if (response instanceof Error) {\n setAdLoadState('error');\n setErrorMessage(response);\n } else {\n setAdData(response);\n }\n setAdLoadState('complete');\n } catch (error) {\n setAdLoadState('error');\n setAdLoadState('complete');\n setErrorMessage(error as Error);\n }\n };\n const loadState = {\n isInitial: adLoadState === 'initial',\n isLoading: adLoadState === 'loading',\n isComplete: adLoadState === 'complete',\n isError: adLoadState === 'error',\n };\n\n useEffect(() => {\n loadAd();\n }, []);\n\n return [adData, errorMessage, loadState];\n}\n\nexport default useAdViewController;\n","'use client';\n\nimport React, { createContext } from 'react';\nimport { type AdViewConfig } from '../types';\n\ntype AdViewProviderContextProps = AdViewConfig;\n\nexport const AdViewProviderContext = createContext<AdViewProviderContextProps>(\n {} as AdViewProviderContextProps,\n);\n\ntype AdViewProviderProps = {\n children: React.ReactNode;\n} & AdViewProviderContextProps;\n\nconst AdViewProvider = ({ children, ...props }: AdViewProviderProps) => {\n return (\n <AdViewProviderContext.Provider value={props}>\n {children}\n </AdViewProviderContext.Provider>\n );\n};\n\nexport default AdViewProvider;\n","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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAkB;;;ACElB,IAAAC,gBAAkB;;;ACAlB,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;AAC1E,WAAO,CAAC,WACJ,IAAI,qBAAqB,+BAA+B,IACxD;AAAA,EACN,GAAG,CAAC,UAAU,+BAA+B,CAAC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ACT;AAEA,IAAO,mCAAQ;;;ADlCf,eAAe,iBAAiB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,MAAM;AAAA,EAClB,GAAG;AACL,GAA0B;AACxB,QAAM,iBAAa,gCAAiB,MAAM;AAC1C,QAAM,iBAAa,+BAAgB,YAAY,QAAQ,MAAM;AAC7D,QAAM,WAAW,UAAM,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,+BAAAC,QAAA,cAAC,8BAAmB,KAAK,KAAK,IAAK,GAAG,WACpC,+BAAAA,QAAA,cAAC,oCAAwB,MAAY,aAClC,QACH,CACF;AAAA,IAEJ,CAAC;AAAA,EACH;AAEA,SACE,+BAAAA,QAAA,cAAC,8BAAoB,GAAG,iBACtB,+BAAAA,QAAA,cAAC,oCAAwB,MAAM,OAAO,aACnC,QACH,CACF;AAEJ;AAEA,IAAO,4BAAQ;;;AV1Cf,SAAS,WAAW,OAAwB;AAC1C,QAAM,WAAW,OAAO,WAAW;AAEnC,MAAI,UAAU;AACZ,WAAO,+BAAAC,QAAA,cAAC,6BAAkB,GAAI,OAAiC;AAAA,EACjE;AAEA,SAAO,+BAAAA,QAAA,cAAC,6BAAkB,GAAI,OAAiC;AACjE;AAEA,IAAO,qBAAQ;","names":["import_react","import_react","React","import_react","import_utils","import_react","React","import_react","React","import_utils","import_react","React","import_react","React","React","import_utils","import_react","import_react","React","import_react","import_utils","import_react","React","React","React"]}
1
+ {"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.tsx","../../src/AdViewUnit/AdViewUnit.client.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx","../../src/AdViewUnit/AdViewUnit.server.tsx"],"sourcesContent":["import React from 'react';\nimport AdViewUnitClient, { AdViewUnitClientProps } from './AdViewUnit.client';\nimport AdViewUnitServer, { AdViewUnitServerProps } from './AdViewUnit.server';\n\nexport type AdViewUnitProps = typeof window extends undefined\n ? AdViewUnitServerProps\n : AdViewUnitClientProps;\n\nfunction AdViewUnit(props: AdViewUnitProps) {\n const isServer = typeof window === 'undefined';\n\n if (isServer) {\n return <AdViewUnitServer {...(props as AdViewUnitServerProps)} />;\n }\n\n return <AdViewUnitClient {...(props as AdViewUnitClientProps)} />;\n}\n\nexport default AdViewUnit;\n","'use client';\n\nimport React from 'react';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport useAdViewController from './useAdViewController';\n\nexport type AdViewUnitClientProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n};\n\n// AdViewUnitClient is a client-side component that fetches ad data and renders it\n// using the provided children function. It handles loading, error states, and\n// tracks ad interactions.\n//\n// Example usage:\n// <AdView.Unit unitId=\"my-unit\" format=\"banner\" srcURL=\"https://api.example.com/ads/{<id>}\">\n// {({ data, state, error }) => (\n// <div>\n// {state.isLoading && <span>Loading...</span>}\n// {error && <span>Error: {error.message}</span>}\n// {data && <img src={data.imageUrl} alt={data.title} />\n// </div>\n// )}\n// </AdView.Unit>\n//\n// Note: This component is designed to be used in a client-side environment where\n// ad data can be fetched dynamically. It is not suitable for server-side rendering.\n// It uses the AdViewUnitTracking component to handle ad tracking and interactions.\nfunction AdViewUnitClient({\n unitId,\n format,\n children,\n ...config\n}: AdViewUnitClientProps) {\n const [response, error, loadState] = useAdViewController(\n config,\n unitId,\n format,\n );\n const responseGroup = error ? null : response?.groups?.[0];\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = responseGroup?.items;\n\n if (groupItems && groupItems?.length > 0) {\n return groupItems.map(({ tracker, ...data }) => {\n return (\n <AdViewUnitTracking key={data.id} {...tracker}>\n {renderAnyTemplates(children, {data, type: data.type || 'default', error, state: loadState})}\n </AdViewUnitTracking>\n );\n });\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n {renderAnyTemplates(children, {data: null, type: 'default', error, state: loadState})}\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitClient;\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","'use client';\n\nimport { AdViewData } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { useContext, useEffect, useState } from 'react';\nimport { AdLoadState, AdViewConfig } from '../types';\nimport { AdViewProviderContext } from './AdViewProvider';\n\ntype UseAdViewControllerProps = [AdViewData | null, Error | null, AdLoadState];\n\nfunction useAdViewController(\n adUnitConfig: AdViewConfig,\n unitId: string,\n format?: string | string[],\n): UseAdViewControllerProps {\n const [adLoadState, setAdLoadState] = useState<string>('initial');\n const [adData, setAdData] = useState<AdViewData | null>(null);\n const [errorMessage, setErrorMessage] = useState<Error | null>(null);\n const globalConfig = useContext(AdViewProviderContext);\n const baseConfig = getResolveConfig({ ...adUnitConfig, ...globalConfig });\n const requestUrl = getAdRequestUrl(baseConfig, unitId,\n typeof format === 'string' ? format : format?.join(',') || '');\n\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n console.log('Requesting ad data from:', adViewFetcher, 'with URL:', requestUrl);\n const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);\n console.log('AdViewController response:', response);\n\n if (response instanceof Error) {\n setAdLoadState('error');\n setErrorMessage(response);\n } else {\n setAdData(response);\n }\n setAdLoadState('complete');\n } catch (error) {\n setAdLoadState('error');\n setAdLoadState('complete');\n setErrorMessage(error as Error);\n }\n };\n\n const loadState = {\n isInitial: adLoadState === 'initial',\n isLoading: adLoadState === 'loading',\n isComplete: adLoadState === 'complete',\n isError: adLoadState === 'error',\n };\n\n useEffect(() => {loadAd()}, []);\n\n return [adData, errorMessage, loadState];\n}\n\nexport default useAdViewController;\n","'use client';\n\nimport React, { createContext } from 'react';\nimport { type AdViewConfig } from '../types';\n\ntype AdViewProviderContextProps = AdViewConfig;\n\nexport const AdViewProviderContext = createContext<AdViewProviderContextProps>(\n {} as AdViewProviderContextProps,\n);\n\ntype AdViewProviderProps = {\n children: React.ReactNode;\n} & AdViewProviderContextProps;\n\nconst AdViewProvider = ({ children, ...props }: AdViewProviderProps) => {\n return (\n <AdViewProviderContext.Provider value={props}>\n {children}\n </AdViewProviderContext.Provider>\n );\n};\n\nexport default AdViewProvider;\n","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"],"mappings":";;;;;;;;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;AAEA,IAAO,4BAAQ;;;AN/Cf,SAAS,WAAW,OAAwB;AAC1C,QAAM,WAAW,OAAO,WAAW;AAEnC,MAAI,UAAU;AACZ,WAAO,8BAAAC,QAAA,cAAC,6BAAkB,GAAI,OAAiC;AAAA,EACjE;AAEA,SAAO,8BAAAA,QAAA,cAAC,6BAAkB,GAAI,OAAiC;AACjE;AAEA,IAAO,qBAAQ;","names":["import_react","import_react","React","import_react","React","import_utils","import_react","import_react","React","import_react","import_utils","React","React"]}