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