@adview/react 1.0.14 → 1.0.16

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 (75) hide show
  1. package/dist/AdViewUnit/AdViewUnit.cjs +288 -66
  2. package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
  3. package/dist/AdViewUnit/AdViewUnit.client.cjs +249 -43
  4. package/dist/AdViewUnit/AdViewUnit.client.cjs.map +1 -1
  5. package/dist/AdViewUnit/AdViewUnit.client.d.cts +1 -1
  6. package/dist/AdViewUnit/AdViewUnit.client.d.ts +1 -1
  7. package/dist/AdViewUnit/AdViewUnit.client.js +228 -22
  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 +263 -41
  12. package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
  13. package/dist/AdViewUnit/AdViewUnit.server.cjs +246 -42
  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 +233 -29
  18. package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
  19. package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs +21 -2
  20. package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs.map +1 -1
  21. package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +7 -2
  22. package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +7 -2
  23. package/dist/AdViewUnit/AdViewUnitBannerTemplate.js +21 -2
  24. package/dist/AdViewUnit/AdViewUnitBannerTemplate.js.map +1 -1
  25. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs +21 -3
  26. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs.map +1 -1
  27. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +3 -4
  28. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +3 -4
  29. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js +21 -3
  30. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js.map +1 -1
  31. package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs +21 -2
  32. package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs.map +1 -1
  33. package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +7 -2
  34. package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +7 -2
  35. package/dist/AdViewUnit/AdViewUnitNativeTemplate.js +21 -2
  36. package/dist/AdViewUnit/AdViewUnitNativeTemplate.js.map +1 -1
  37. package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs +21 -2
  38. package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs.map +1 -1
  39. package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +7 -2
  40. package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +7 -2
  41. package/dist/AdViewUnit/AdViewUnitProxyTemplate.js +21 -2
  42. package/dist/AdViewUnit/AdViewUnitProxyTemplate.js.map +1 -1
  43. package/dist/AdViewUnit/AdViewUnitTemplate.cjs +24 -6
  44. package/dist/AdViewUnit/AdViewUnitTemplate.cjs.map +1 -1
  45. package/dist/AdViewUnit/AdViewUnitTemplate.d.cts +2 -2
  46. package/dist/AdViewUnit/AdViewUnitTemplate.d.ts +2 -2
  47. package/dist/AdViewUnit/AdViewUnitTemplate.js +24 -6
  48. package/dist/AdViewUnit/AdViewUnitTemplate.js.map +1 -1
  49. package/dist/AdViewUnit/useAdViewController.cjs +0 -2
  50. package/dist/AdViewUnit/useAdViewController.cjs.map +1 -1
  51. package/dist/AdViewUnit/useAdViewController.d.cts +1 -1
  52. package/dist/AdViewUnit/useAdViewController.d.ts +1 -1
  53. package/dist/AdViewUnit/useAdViewController.js +0 -2
  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 +278 -195
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +1 -1
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.js +257 -174
  66. package/dist/index.js.map +1 -1
  67. package/dist/server.cjs +277 -196
  68. package/dist/server.cjs.map +1 -1
  69. package/dist/server.d.cts +1 -1
  70. package/dist/server.d.ts +1 -1
  71. package/dist/server.js +264 -183
  72. package/dist/server.js.map +1 -1
  73. package/dist/{types-B65WDsgh.d.cts → types-E00UyX0q.d.cts} +15 -27
  74. package/dist/{types-B65WDsgh.d.ts → types-E00UyX0q.d.ts} +15 -27
  75. package/package.json +1 -1
@@ -1,38 +1,226 @@
1
1
  'use client';
2
2
 
3
3
  // src/AdViewUnit/AdViewUnit.server.tsx
4
- import React3 from "react";
4
+ import React6 from "react";
5
5
  import { adViewFetcher, getAdRequestUrl, getResolveConfig } from "@adview/core/utils";
6
6
 
7
- // src/AdViewUnit/AdViewUnitTemplate.tsx
7
+ // src/AdViewUnit/AdViewUnitBannerTemplate.tsx
8
+ import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from "@adview/core/utils";
8
9
  import React from "react";
10
+
11
+ // src/AdViewUnit/utils.ts
12
+ var matchExpectedState = (expectState, state) => {
13
+ return !expectState || (expectState.isInitial === void 0 || expectState.isInitial === state?.isInitial) && (expectState.isLoading === void 0 || expectState.isLoading === state?.isLoading) && (expectState.isError === void 0 || expectState.isError === state?.isError) && (expectState.isComplete === void 0 || expectState.isComplete === state?.isComplete);
14
+ };
15
+
16
+ // src/AdViewUnit/AdViewUnitBannerTemplate.tsx
17
+ function AdViewUnitBannerTemplate({ className = "banner", style, data, state, ...props }) {
18
+ const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
19
+ isInitial: props?.isInitial,
20
+ isLoading: props?.isLoading,
21
+ isError: props?.isError,
22
+ isComplete: props?.isComplete
23
+ } : { isComplete: true };
24
+ if (!data || !data.assets || !data.assets.length) {
25
+ return null;
26
+ }
27
+ if (!matchExpectedState(expectState, state)) {
28
+ return null;
29
+ }
30
+ const asset = getAssetByName("main", data.assets);
31
+ return /* @__PURE__ */ React.createElement(
32
+ "a",
33
+ {
34
+ target: "_blank",
35
+ rel: "noopener noreferrer",
36
+ href: getPrepareURL(data.url),
37
+ className,
38
+ style: { fontSize: 0, ...style }
39
+ },
40
+ asset && /* @__PURE__ */ React.createElement(
41
+ "img",
42
+ {
43
+ alt: "main",
44
+ src: asset.path,
45
+ srcSet: asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ""
46
+ }
47
+ )
48
+ );
49
+ }
50
+ AdViewUnitBannerTemplate.defaults = {
51
+ type: "banner"
52
+ };
53
+ var AdViewUnitBannerTemplate_default = AdViewUnitBannerTemplate;
54
+
55
+ // src/AdViewUnit/AdViewUnitNativeTemplate.tsx
56
+ import { getAssetByName as getAssetByName2, getPrepareURL as getPrepareURL2, getSrcSetCSSThumbs as getSrcSetCSSThumbs2 } from "@adview/core/utils";
57
+ import React2 from "react";
58
+ function AdViewUnitNativeTemplate({ classNames, data, state, ...props }) {
59
+ if (!data || !data.assets || !data.assets.length) {
60
+ return null;
61
+ }
62
+ const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
63
+ isInitial: props?.isInitial,
64
+ isLoading: props?.isLoading,
65
+ isError: props?.isError,
66
+ isComplete: props?.isComplete
67
+ } : { isComplete: true };
68
+ if (!matchExpectedState(expectState, state)) {
69
+ return null;
70
+ }
71
+ const { assets, url, fields } = data;
72
+ const asset = getAssetByName2("main", assets);
73
+ if (!url) {
74
+ return null;
75
+ }
76
+ return /* @__PURE__ */ React2.createElement("div", { className: classNames?.container }, /* @__PURE__ */ React2.createElement(
77
+ "a",
78
+ {
79
+ target: "_blank",
80
+ rel: "noopener noreferrer",
81
+ href: getPrepareURL2(url),
82
+ className: classNames?.imageLink
83
+ },
84
+ asset && /* @__PURE__ */ React2.createElement(
85
+ "img",
86
+ {
87
+ alt: fields?.title,
88
+ title: fields?.title,
89
+ src: asset.path,
90
+ srcSet: asset.thumbs ? getSrcSetCSSThumbs2(asset.thumbs) : void 0,
91
+ className: classNames?.image,
92
+ style: { objectFit: "cover", width: "100%", height: "100%" }
93
+ }
94
+ )
95
+ ), /* @__PURE__ */ React2.createElement("div", { className: classNames?.label }, fields?.title && /* @__PURE__ */ React2.createElement(
96
+ "a",
97
+ {
98
+ target: "_blank",
99
+ rel: "noopener noreferrer",
100
+ href: getPrepareURL2(url),
101
+ "data-class": "titleLink",
102
+ className: classNames?.titleLink
103
+ },
104
+ fields.title
105
+ ), fields?.description && /* @__PURE__ */ React2.createElement(
106
+ "a",
107
+ {
108
+ target: "_blank",
109
+ rel: "noopener noreferrer",
110
+ href: getPrepareURL2(url),
111
+ "data-class": "descriptionLink",
112
+ className: classNames?.descriptionLink
113
+ },
114
+ fields.description
115
+ ), fields?.brandname && /* @__PURE__ */ React2.createElement(
116
+ "a",
117
+ {
118
+ target: "_blank",
119
+ rel: "noopener noreferrer",
120
+ href: getPrepareURL2(url),
121
+ "data-class": "brandNameLink",
122
+ className: classNames?.brandNameLink
123
+ },
124
+ fields.brandname
125
+ ), fields?.phone && /* @__PURE__ */ React2.createElement(
126
+ "a",
127
+ {
128
+ target: "_blank",
129
+ rel: "noopener noreferrer",
130
+ href: getPrepareURL2(url),
131
+ "data-class": "phoneLink",
132
+ className: classNames?.phoneLink
133
+ },
134
+ fields.phone
135
+ ), fields?.url && /* @__PURE__ */ React2.createElement(
136
+ "a",
137
+ {
138
+ target: "_blank",
139
+ rel: "noopener noreferrer",
140
+ href: getPrepareURL2(url),
141
+ "data-class": "urlLink",
142
+ className: classNames?.urlLink
143
+ },
144
+ fields?.url
145
+ )));
146
+ }
147
+ AdViewUnitNativeTemplate.defaults = {
148
+ type: "native"
149
+ };
150
+ var AdViewUnitNativeTemplate_default = AdViewUnitNativeTemplate;
151
+
152
+ // src/AdViewUnit/AdViewUnitProxyTemplate.tsx
153
+ import React3 from "react";
154
+ function AdViewUnitProxyTemplate({ className, style, data, state, ...props }) {
155
+ if (!data) {
156
+ return null;
157
+ }
158
+ const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
159
+ isInitial: props?.isInitial,
160
+ isLoading: props?.isLoading,
161
+ isError: props?.isError,
162
+ isComplete: props?.isComplete
163
+ } : { isComplete: true };
164
+ if (!matchExpectedState(expectState, state)) {
165
+ return null;
166
+ }
167
+ const { url, fields } = data;
168
+ const iframeSrc = fields?.url || url;
169
+ if (!iframeSrc) {
170
+ return null;
171
+ }
172
+ return /* @__PURE__ */ React3.createElement(
173
+ "iframe",
174
+ {
175
+ className,
176
+ width: "100%",
177
+ height: "100%",
178
+ frameBorder: "0",
179
+ marginWidth: 0,
180
+ marginHeight: 0,
181
+ allowTransparency: true,
182
+ scrolling: "no",
183
+ allowFullScreen: true,
184
+ style: { width: "100%", height: "100%", border: "none", ...style },
185
+ src: iframeSrc
186
+ }
187
+ );
188
+ }
189
+ AdViewUnitProxyTemplate.defaults = {
190
+ type: "proxy"
191
+ };
192
+ var AdViewUnitProxyTemplate_default = AdViewUnitProxyTemplate;
193
+
194
+ // src/AdViewUnit/AdViewUnitTemplate.tsx
195
+ import React4 from "react";
9
196
  var templateFromListRender = (tmpls, data, wrap) => {
10
197
  let renderedRemplates = tmpls.map((tmpl, index) => {
11
198
  let tmp = renderTemplate(tmpl, data);
12
- return !!tmp && React.isValidElement(tmp) ? /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
199
+ return !!tmp && React4.isValidElement(tmp) ? /* @__PURE__ */ React4.createElement(React4.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
13
200
  }).filter((it) => !!it);
14
201
  if (!renderedRemplates.length) {
15
202
  renderedRemplates = tmpls.map((tmpl, index) => {
16
203
  let tmp = renderTemplate(tmpl, { ...data, type: "default" });
17
- return !!tmp && React.isValidElement(tmp) ? /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
204
+ return !!tmp && React4.isValidElement(tmp) ? /* @__PURE__ */ React4.createElement(React4.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
18
205
  }).filter((it) => !!it);
19
206
  }
20
- return /* @__PURE__ */ React.createElement(React.Fragment, null, renderedRemplates);
207
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, renderedRemplates);
21
208
  };
22
209
  var renderTemplate = (tmpl, data) => {
23
210
  const isFunction = typeof tmpl === "function";
24
- const isReactElement = React.isValidElement(tmpl);
211
+ const isReactElement = React4.isValidElement(tmpl);
25
212
  if (isReactElement) {
26
- const { type, children } = tmpl.props;
27
- console.log("=====>\nrenderTemplate: React element detected, type:", type, "data:", data.type, data.type !== type);
28
- if (data.type !== type) {
213
+ let { type, children } = tmpl.props;
214
+ if (!type && typeof tmpl.type !== "string") {
215
+ type = tmpl.type?.defaults?.type;
216
+ }
217
+ if (!!type && type !== "*" && data.type !== type) {
29
218
  return null;
30
219
  }
31
220
  if (typeof children === "function") {
32
221
  return children(data);
33
222
  }
34
- console.log("CLONE ELEMENT", tmpl);
35
- return React.cloneElement(tmpl, {
223
+ return React4.cloneElement(tmpl, {
36
224
  ...data,
37
225
  children
38
226
  });
@@ -55,7 +243,7 @@ var renderAnyTemplates = (tmpls, data, listRender) => {
55
243
  if (typeof tmpls === "function") {
56
244
  return tmpls(data);
57
245
  }
58
- if (React.isValidElement(tmpls)) {
246
+ if (React4.isValidElement(tmpls)) {
59
247
  return templateFromListRender([tmpls], data);
60
248
  }
61
249
  return null;
@@ -63,7 +251,7 @@ var renderAnyTemplates = (tmpls, data, listRender) => {
63
251
 
64
252
  // src/AdViewUnit/AdViewUnitTracking.tsx
65
253
  import { executeImpressionsTracking } from "@adview/core/utils";
66
- import React2, { useCallback, useEffect, useMemo, useRef } from "react";
254
+ import React5, { useCallback, useEffect, useMemo, useRef } from "react";
67
255
  function AdViewUnitTracking({
68
256
  impressions,
69
257
  views,
@@ -112,7 +300,7 @@ function AdViewUnitTracking({
112
300
  executeImpressionsTrackingHandler,
113
301
  clickTrackerHandler
114
302
  ]);
115
- return /* @__PURE__ */ React2.createElement("div", { ref: wrapperRef }, children);
303
+ return /* @__PURE__ */ React5.createElement("div", { ref: wrapperRef }, children);
116
304
  }
117
305
  var AdViewUnitTracking_default = AdViewUnitTracking;
118
306
 
@@ -123,30 +311,46 @@ async function AdViewUnitServer({
123
311
  children,
124
312
  ...config
125
313
  }) {
314
+ const checkFormat = (f) => {
315
+ if (!format) {
316
+ return true;
317
+ }
318
+ return Array.isArray(format) ? format.includes(f) : f === format;
319
+ };
126
320
  const baseConfig = getResolveConfig(config);
127
321
  const requestUrl = getAdRequestUrl(baseConfig, unitId, format);
128
322
  const response = await adViewFetcher(requestUrl);
129
323
  const isLoadingError = response instanceof Error;
130
324
  const error = isLoadingError ? response : void 0;
131
- const responseGroup = response instanceof Error ? null : response?.groups?.[0];
132
- const customTracker = responseGroup?.custom_tracker ?? {};
133
- const groupItems = responseGroup?.items;
134
- if (groupItems && groupItems.length) {
135
- return groupItems.map(({ tracker, ...data }) => {
136
- return /* @__PURE__ */ React3.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state: {
137
- isLoading: true,
138
- isComplete: true,
139
- isInitial: false,
140
- isError: isLoadingError
141
- } }));
142
- });
143
- }
144
- return /* @__PURE__ */ React3.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state: {
325
+ const state = {
145
326
  isLoading: true,
146
327
  isComplete: true,
147
328
  isInitial: false,
148
329
  isError: isLoadingError
149
- } }));
330
+ };
331
+ const { responseGroup: _, customTracker, groupItems } = error ? { responseGroup: null, customTracker: {}, groupItems: [] } : (() => {
332
+ for (let responseGroup of response?.groups || []) {
333
+ const customTracker2 = responseGroup?.custom_tracker ?? {};
334
+ const groupItems2 = (responseGroup?.items || []).map((it) => checkFormat(it.type) ? it : null).filter(Boolean);
335
+ if (groupItems2 && groupItems2.length > 0) {
336
+ return { responseGroup, customTracker: customTracker2, groupItems: groupItems2 };
337
+ }
338
+ }
339
+ return { responseGroup: null, customTracker: {}, groupItems: [] };
340
+ })();
341
+ if (!children) {
342
+ children = [
343
+ /* @__PURE__ */ React6.createElement(AdViewUnitBannerTemplate_default, null),
344
+ /* @__PURE__ */ React6.createElement(AdViewUnitNativeTemplate_default, null),
345
+ /* @__PURE__ */ React6.createElement(AdViewUnitProxyTemplate_default, null)
346
+ ];
347
+ }
348
+ if (groupItems && groupItems.length) {
349
+ return groupItems.map(({ tracker, ...data }) => {
350
+ return /* @__PURE__ */ React6.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state }));
351
+ });
352
+ }
353
+ return /* @__PURE__ */ React6.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state }));
150
354
  }
151
355
  var AdViewUnit_server_default = AdViewUnitServer;
152
356
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.server.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx"],"sourcesContent":["import React from 'react';\n\nimport { AdViewGroupItem } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { AdViewUnitPropsBase, AdViewUnitServerChildren } from '../types';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\n\nexport type AdViewUnitServerProps = AdViewUnitPropsBase & {\n children?: AdViewUnitServerChildren;\n};\n\nasync function AdViewUnitServer({\n unitId,\n format,\n children,\n ...config\n}: AdViewUnitServerProps) {\n const baseConfig = getResolveConfig(config);\n const requestUrl = getAdRequestUrl(baseConfig, unitId, format);\n const response = await adViewFetcher(requestUrl);\n const isLoadingError = response instanceof Error;\n const error = isLoadingError ? response : undefined;\n const responseGroup =\n response instanceof Error ? null : response?.groups?.[0];\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = responseGroup?.items;\n\n if (groupItems && groupItems.length) {\n return groupItems.map(({ tracker, ...data }: AdViewGroupItem) => {\n return (\n <AdViewUnitTracking key={data.id} {...tracker}>\n {renderAnyTemplates(children, {data, type: data.type || 'default', error, state: {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n }})}\n </AdViewUnitTracking>\n );\n });\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n {renderAnyTemplates(children, {data: null, type: 'default', error, state: {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n }})}\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitServer;\n","//\n// Example\n// <AdView.Unit>\n// <AdView.Template type=\"banner\">\n// <...>\n// </AdView.Template>\n// </AdView.Unit>\n//\n\nimport React, { JSX } from 'react';\nimport { AdViewUnitClientChildrenProps, AdViewUnitTemplateProps, AdViewUnitTemplateTypeProps } from '../types';\n\n// TemplateListRender is a function that takes a list of TemplateType and returns a React element\nexport type TemplateListRender = (tmpls: TemplateElement[]) => React.ReactElement | JSX.Element;\n\n// TemplateType is a React component that can be used to render ad templates\nexport type TemplateType = React.Component<AdViewUnitTemplateProps>;\nexport type TemplateElement = React.ReactElement<AdViewUnitTemplateProps>;\n\n// TemplateTypeFunction is a function that takes AdViewUnitTemplateTypeProps and returns a React node or element\nexport type TemplateTypeFunction = (props: AdViewUnitTemplateTypeProps) => React.ReactNode | React.ReactElement;\n\n// templateFromListRender is a function that takes a list of TemplateType and returns a React element\nexport const templateFromListRender = (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, wrap?: (children: React.ReactNode) => React.ReactNode): JSX.Element | React.ReactElement => {\n let renderedRemplates = tmpls.map((tmpl, index) => {\n let tmp = renderTemplate(tmpl, data);\n return !!tmp && React.isValidElement(tmp)\n ? <React.Fragment key={index}>{!!wrap ? wrap(tmp) : tmp}</React.Fragment>\n : null;\n }).filter(it => !!it);\n\n if (!renderedRemplates.length) {\n renderedRemplates = tmpls.map((tmpl, index) => {\n let tmp = renderTemplate(tmpl, {...data, type: 'default'});\n return !!tmp && React.isValidElement(tmp)\n ? <React.Fragment key={index}>{!!wrap ? wrap(tmp) : tmp}</React.Fragment>\n : null;\n }).filter(it => !!it);\n }\n\n return (<>{renderedRemplates}</>);\n};\n\n// renderTemplate is a function that takes a TemplateType or a function and returns a React node\nexport const renderTemplate = (tmpl: TemplateElement | TemplateTypeFunction, data: AdViewUnitTemplateTypeProps): React.ReactNode => {\n const isFunction = typeof tmpl === 'function';\n const isReactElement = React.isValidElement(tmpl);\n\n if (isReactElement) {\n // Extract type and children from the React element\n const { type, children } = (tmpl as TemplateElement).props;\n console.log('=====>\\nrenderTemplate: React element detected, type:', type, 'data:', data.type, data.type !== type);\n // If the type does not match, return null\n if (data.type !== type) {\n return null;\n }\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(data as AdViewUnitClientChildrenProps);\n }\n console.log('CLONE ELEMENT', tmpl);\n // If children is a React element, clone it with the new props\n return React.cloneElement((tmpl as TemplateElement), {\n ...data,\n children: children,\n });\n }\n\n if (isFunction) {\n return tmpl(data);\n }\n\n return null;\n}\n\n// renderTemplates is a function that takes a list of TemplateType and returns a React element\nexport const renderTemplates = (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender): React.ReactNode | React.ReactElement | JSX.Element => {\n return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);\n};\n\nexport const renderAnyTemplates = (tmpls: any, data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender): React.ReactNode | React.ReactElement | JSX.Element | null => {\n if (!tmpls) {\n return null;\n }\n\n if (Array.isArray(tmpls)) {\n return renderTemplates(tmpls as TemplateElement[], data, listRender);\n }\n\n if (typeof tmpls === 'function') {\n return tmpls(data);\n }\n\n if (React.isValidElement(tmpls)) {\n return templateFromListRender([tmpls as TemplateElement], data);\n }\n\n return null;\n}\n\n// Template is a React component that renders a template based on the type and data provided\n// Example usage:\n// <AdView.Unit>\n// <AdView.Template type=\"banner\" data={{...}}>\n// </AdView.Unit>\nconst AdViewUnitTemplate = ({ type, children, ...data }: AdViewUnitTemplateProps) => {\n const tmplProps: AdViewUnitTemplateTypeProps = {\n type,\n ...data,\n };\n\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(tmplProps as AdViewUnitClientChildrenProps) as React.ReactElement;\n }\n\n // If children is a React element, clone it with the new props\n if (React.isValidElement(children)) {\n return React.cloneElement(children, tmplProps);\n }\n\n // If no children are provided, return an empty fragment\n return <></>;\n}\n\nexport default AdViewUnitTemplate;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return <div ref={wrapperRef}>{children}</div>;\n}\n\nexport default AdViewUnitTracking;\n"],"mappings":";AAAA,OAAOA,YAAW;AAGlB,SAAS,eAAe,iBAAiB,wBAAwB;;;ACMjE,OAAO,WAAoB;AAcpB,IAAM,yBAAyB,CAAC,OAA0B,MAAmC,SAA4F;AAC9L,MAAI,oBAAoB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,MAAM,eAAe,MAAM,IAAI;AACnC,WAAO,CAAC,CAAC,OAAO,MAAM,eAAe,GAAG,IACpC,oCAAC,MAAM,UAAN,EAAe,KAAK,SAAQ,CAAC,CAAC,OAAO,KAAK,GAAG,IAAI,GAAI,IACtD;AAAA,EACN,CAAC,EAAE,OAAO,QAAM,CAAC,CAAC,EAAE;AAEpB,MAAI,CAAC,kBAAkB,QAAQ;AAC7B,wBAAoB,MAAM,IAAI,CAAC,MAAM,UAAU;AAC7C,UAAI,MAAM,eAAe,MAAM,EAAC,GAAG,MAAM,MAAM,UAAS,CAAC;AACzD,aAAO,CAAC,CAAC,OAAO,MAAM,eAAe,GAAG,IACpC,oCAAC,MAAM,UAAN,EAAe,KAAK,SA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AAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA0B;AACxB,QAAM,aAAa,iBAAiB,MAAM;AAC1C,QAAM,aAAa,gBAAgB,YAAY,QAAQ,MAAM;AAC7D,QAAM,WAAW,MAAM,cAAc,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,gBAAAC,OAAA,cAAC,8BAAmB,KAAK,KAAK,IAAK,GAAG,WACnC,mBAAmB,UAAU,EAAC,MAAM,MAAM,KAAK,QAAQ,WAAW,OAAO,OAAO;AAAA,QAC/E,WAAW;AAAA,QACX,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,SAAS;AAAA,MACX,EAAC,CAAC,CACJ;AAAA,IAEJ,CAAC;AAAA,EACH;AAEA,SACE,gBAAAA,OAAA,cAAC,8BAAoB,GAAG,iBACrB,mBAAmB,UAAU,EAAC,MAAM,MAAM,MAAM,WAAW,OAAO,OAAO;AAAA,IACxE,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,SAAS;AAAA,EACX,EAAC,CAAC,CACJ;AAEJ;AAEA,IAAO,4BAAQ;","names":["React","React","React"]}
1
+ {"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.server.tsx","../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts","../../src/AdViewUnit/AdViewUnitNativeTemplate.tsx","../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx"],"sourcesContent":["import React from 'react';\n\nimport { AdViewData } from '@adview/core';\nimport { AdViewGroupItem } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\n\nexport type AdViewUnitServerProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n};\n\nasync function AdViewUnitServer({\n unitId,\n format,\n children,\n ...config\n}: AdViewUnitServerProps) {\n const checkFormat = (f: string) => {\n if (!format) { return true; }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\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 state = {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n };\n\n const { responseGroup: _, customTracker, groupItems } = error ? {responseGroup: null, customTracker: {}, groupItems: []} : (() => {\n for (let responseGroup of (response as AdViewData)?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || []).map(it => checkFormat(it.type) ? it : null).\n filter(Boolean) as AdViewGroupItem[];\n if (groupItems && groupItems.length > 0) {\n return {responseGroup, customTracker, groupItems};\n }\n }\n return {responseGroup: null, customTracker: {}, groupItems: []};\n })();\n \n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />\n ];\n }\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: state})}\n </AdViewUnitTracking>\n );\n });\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n {renderAnyTemplates(children, {data: null, type: 'default', error, state: state})}\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitServer;\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({className=\"banner\", style, data, state, ...props}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n \n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewStyleTokensNative, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitNativeTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'native';\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitNativeTemplate({classNames, data, state, ...props}: AdViewUnitNativeTemplateProps) {\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { assets, url, fields } = data;\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\nAdViewUnitNativeTemplate.defaults = {\n type: 'native',\n};\n\nexport default AdViewUnitNativeTemplate;\n","import React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'proxy';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitProxyTemplate({className, style, data, state, ...props}: AdViewUnitProxyTemplateProps) {\n if (!data) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { url, fields } = data;\n const iframeSrc = fields?.url || url;\n\n if (!iframeSrc) {\n return null;\n }\n\n return (\n <iframe\n className={className}\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%', border: 'none', ...style }}\n src={iframeSrc}\n ></iframe>\n );\n}\n\nAdViewUnitProxyTemplate.defaults = {\n type: 'proxy',\n};\n\nexport default AdViewUnitProxyTemplate;\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 { AdLoadState, AdViewUnitClientChildrenProps, AdViewUnitTemplateProps, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\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 let { type, children } = tmpl.props;\n if (!type && typeof tmpl.type !== 'string') {\n type = (tmpl.type as any)?.defaults?.type;\n }\n // If the type does not match, return null\n if (!!type && type !== '*' && 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 // 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, state, children, ...props }: AdViewUnitTemplateProps) => {\n const tmplProps: AdViewUnitTemplateTypeProps = {\n type,\n state,\n ...props,\n };\n \n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\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 AdVi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AAA,MAC1B,gBAAAA,OAAA,cAAC,qCAAwB;AAAA,IAC3B;AAAA,EACF;AAEA,MAAI,cAAc,WAAW,QAAQ;AACnC,WAAO,WAAW,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,MAAuB;AAC/D,aACE,gBAAAA,OAAA,cAAC,8BAAmB,KAAK,KAAK,IAAK,GAAG,WACnC,mBAAmB,UAAU,EAAC,MAAM,MAAM,KAAK,QAAQ,WAAW,OAAO,MAAY,CAAC,CACzF;AAAA,IAEJ,CAAC;AAAA,EACH;AAEA,SACE,gBAAAA,OAAA,cAAC,8BAAoB,GAAG,iBACrB,mBAAmB,UAAU,EAAC,MAAM,MAAM,MAAM,WAAW,OAAO,MAAY,CAAC,CAClF;AAEJ;AAEA,IAAO,4BAAQ;","names":["React","getAssetByName","getPrepareURL","getSrcSetCSSThumbs","React","getAssetByName","React","getPrepareURL","getSrcSetCSSThumbs","React","React","React","React","React","customTracker","groupItems","React"]}
@@ -35,8 +35,24 @@ __export(AdViewUnitBannerTemplate_exports, {
35
35
  module.exports = __toCommonJS(AdViewUnitBannerTemplate_exports);
36
36
  var import_utils = require("@adview/core/utils");
37
37
  var import_react = __toESM(require("react"), 1);
38
- function AdViewUnitBannerTemplate({ className = "banner", style, data, state }) {
39
- if (!data || !data.assets || !data.assets.length || !state?.isComplete) {
38
+
39
+ // src/AdViewUnit/utils.ts
40
+ var matchExpectedState = (expectState, state) => {
41
+ 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);
42
+ };
43
+
44
+ // src/AdViewUnit/AdViewUnitBannerTemplate.tsx
45
+ function AdViewUnitBannerTemplate({ className = "banner", style, data, state, ...props }) {
46
+ const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
47
+ isInitial: props?.isInitial,
48
+ isLoading: props?.isLoading,
49
+ isError: props?.isError,
50
+ isComplete: props?.isComplete
51
+ } : { isComplete: true };
52
+ if (!data || !data.assets || !data.assets.length) {
53
+ return null;
54
+ }
55
+ if (!matchExpectedState(expectState, state)) {
40
56
  return null;
41
57
  }
42
58
  const asset = (0, import_utils.getAssetByName)("main", data.assets);
@@ -59,5 +75,8 @@ function AdViewUnitBannerTemplate({ className = "banner", style, data, state })
59
75
  )
60
76
  );
61
77
  }
78
+ AdViewUnitBannerTemplate.defaults = {
79
+ type: "banner"
80
+ };
62
81
  var AdViewUnitBannerTemplate_default = AdViewUnitBannerTemplate;
63
82
  //# sourceMappingURL=AdViewUnitBannerTemplate.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx"],"sourcesContent":["import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdViewUnitTemplateTypeProps } from '../types';\n\ntype AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({className=\"banner\", style, data, state}: AdViewUnitBannerTemplateProps) {\n if (!data || !data.assets || !data.assets.length || !state?.isComplete) {\n return null;\n }\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n />\n )}\n </a>\n );\n}\n\nexport default AdViewUnitBannerTemplate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,mBAAkB;AASlB,SAAS,yBAAyB,EAAC,YAAU,UAAU,OAAO,MAAM,MAAK,GAAkC;AACzG,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,UAAU,CAAC,OAAO,YAAY;AACtE,WAAO;AAAA,EACT;AACA,QAAM,YAAQ,6BAAe,QAAQ,KAAK,MAAM;AAEhD,SACE,6BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,UAAM,4BAAc,KAAK,GAAG;AAAA,MAC5B;AAAA,MACA,OAAO,EAAE,UAAU,GAAG,GAAG,MAAM;AAAA;AAAA,IAE9B,SACC,6BAAAA,QAAA;AAAA,MAAC;AAAA;AAAA,QACC,KAAI;AAAA,QACJ,KAAK,MAAM;AAAA,QACX,QAAQ,MAAM,aAAS,iCAAmB,MAAM,MAAM,IAAI;AAAA;AAAA,IAC5D;AAAA,EAEJ;AAEJ;AAEA,IAAO,mCAAQ;","names":["React"]}
1
+ {"version":3,"sources":["../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({className=\"banner\", style, data, state, ...props}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n \n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,mBAAkB;;;ACCX,IAAM,qBAAqB,CAAC,aAA2B,UAAwB;AACpF,SAAO,CAAC,gBACL,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,YAAY,UAAa,YAAY,YAAY,OAAO,aACpE,YAAY,eAAe,UAAa,YAAY,eAAe,OAAO;AAE/E;;;ADEA,SAAS,yBAAyB,EAAC,YAAU,UAAU,OAAO,MAAM,OAAO,GAAG,MAAK,GAAkC;AACnH,QAAM,cACH,OAAO,aAAa,OAAO,aAAa,OAAO,WAAW,OAAO,aAAc;AAAA,IAC9E,WAAW,OAAO;AAAA,IAClB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,YAAY,OAAO;AAAA,EACrB,IAAI,EAAC,YAAY,KAAI;AAEvB,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,QAAQ;AAChD,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,mBAAmB,aAAa,KAAK,GAAG;AAC3C,WAAO;AAAA,EACT;AAEA,QAAM,YAAQ,6BAAe,QAAQ,KAAK,MAAM;AAEhD,SACE,6BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,UAAM,4BAAc,KAAK,GAAG;AAAA,MAC5B;AAAA,MACA,OAAO,EAAE,UAAU,GAAG,GAAG,MAAM;AAAA;AAAA,IAE9B,SACC,6BAAAA,QAAA;AAAA,MAAC;AAAA;AAAA,QACC,KAAI;AAAA,QACJ,KAAK,MAAM;AAAA,QACX,QAAQ,MAAM,aAAS,iCAAmB,MAAM,MAAM,IAAI;AAAA;AAAA,IAC5D;AAAA,EAEJ;AAEJ;AAEA,yBAAyB,WAAW;AAAA,EAClC,MAAM;AACR;AAEA,IAAO,mCAAQ;","names":["React"]}
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { c as AdViewUnitTemplateTypeProps } from '../types-B65WDsgh.cjs';
2
+ import { b as AdViewUnitTemplateTypeProps } from '../types-E00UyX0q.cjs';
3
3
  import '@adview/core/typings';
4
4
 
5
5
  type AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {
@@ -7,6 +7,11 @@ type AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> &
7
7
  className?: string;
8
8
  style?: React.CSSProperties;
9
9
  };
10
- declare function AdViewUnitBannerTemplate({ className, style, data, state }: AdViewUnitBannerTemplateProps): React.JSX.Element | null;
10
+ declare function AdViewUnitBannerTemplate({ className, style, data, state, ...props }: AdViewUnitBannerTemplateProps): React.JSX.Element | null;
11
+ declare namespace AdViewUnitBannerTemplate {
12
+ var defaults: {
13
+ type: string;
14
+ };
15
+ }
11
16
 
12
17
  export { AdViewUnitBannerTemplate as default };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { c as AdViewUnitTemplateTypeProps } from '../types-B65WDsgh.js';
2
+ import { b as AdViewUnitTemplateTypeProps } from '../types-E00UyX0q.js';
3
3
  import '@adview/core/typings';
4
4
 
5
5
  type AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {
@@ -7,6 +7,11 @@ type AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> &
7
7
  className?: string;
8
8
  style?: React.CSSProperties;
9
9
  };
10
- declare function AdViewUnitBannerTemplate({ className, style, data, state }: AdViewUnitBannerTemplateProps): React.JSX.Element | null;
10
+ declare function AdViewUnitBannerTemplate({ className, style, data, state, ...props }: AdViewUnitBannerTemplateProps): React.JSX.Element | null;
11
+ declare namespace AdViewUnitBannerTemplate {
12
+ var defaults: {
13
+ type: string;
14
+ };
15
+ }
11
16
 
12
17
  export { AdViewUnitBannerTemplate as default };
@@ -1,8 +1,24 @@
1
1
  // src/AdViewUnit/AdViewUnitBannerTemplate.tsx
2
2
  import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from "@adview/core/utils";
3
3
  import React from "react";
4
- function AdViewUnitBannerTemplate({ className = "banner", style, data, state }) {
5
- if (!data || !data.assets || !data.assets.length || !state?.isComplete) {
4
+
5
+ // src/AdViewUnit/utils.ts
6
+ var matchExpectedState = (expectState, state) => {
7
+ 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);
8
+ };
9
+
10
+ // src/AdViewUnit/AdViewUnitBannerTemplate.tsx
11
+ function AdViewUnitBannerTemplate({ className = "banner", style, data, state, ...props }) {
12
+ const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
13
+ isInitial: props?.isInitial,
14
+ isLoading: props?.isLoading,
15
+ isError: props?.isError,
16
+ isComplete: props?.isComplete
17
+ } : { isComplete: true };
18
+ if (!data || !data.assets || !data.assets.length) {
19
+ return null;
20
+ }
21
+ if (!matchExpectedState(expectState, state)) {
6
22
  return null;
7
23
  }
8
24
  const asset = getAssetByName("main", data.assets);
@@ -25,6 +41,9 @@ function AdViewUnitBannerTemplate({ className = "banner", style, data, state })
25
41
  )
26
42
  );
27
43
  }
44
+ AdViewUnitBannerTemplate.defaults = {
45
+ type: "banner"
46
+ };
28
47
  var AdViewUnitBannerTemplate_default = AdViewUnitBannerTemplate;
29
48
  export {
30
49
  AdViewUnitBannerTemplate_default as default
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx"],"sourcesContent":["import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdViewUnitTemplateTypeProps } from '../types';\n\ntype AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({className=\"banner\", style, data, state}: AdViewUnitBannerTemplateProps) {\n if (!data || !data.assets || !data.assets.length || !state?.isComplete) {\n return null;\n }\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n />\n )}\n </a>\n );\n}\n\nexport default AdViewUnitBannerTemplate;\n"],"mappings":";AAAA,SAAS,gBAAgB,eAAe,0BAA0B;AAClE,OAAO,WAAW;AASlB,SAAS,yBAAyB,EAAC,YAAU,UAAU,OAAO,MAAM,MAAK,GAAkC;AACzG,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,UAAU,CAAC,OAAO,YAAY;AACtE,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,eAAe,QAAQ,KAAK,MAAM;AAEhD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,MAAM,cAAc,KAAK,GAAG;AAAA,MAC5B;AAAA,MACA,OAAO,EAAE,UAAU,GAAG,GAAG,MAAM;AAAA;AAAA,IAE9B,SACC;AAAA,MAAC;AAAA;AAAA,QACC,KAAI;AAAA,QACJ,KAAK,MAAM;AAAA,QACX,QAAQ,MAAM,SAAS,mBAAmB,MAAM,MAAM,IAAI;AAAA;AAAA,IAC5D;AAAA,EAEJ;AAEJ;AAEA,IAAO,mCAAQ;","names":[]}
1
+ {"version":3,"sources":["../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({className=\"banner\", style, data, state, ...props}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n \n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n"],"mappings":";AAAA,SAAS,gBAAgB,eAAe,0BAA0B;AAClE,OAAO,WAAW;;;ACCX,IAAM,qBAAqB,CAAC,aAA2B,UAAwB;AACpF,SAAO,CAAC,gBACL,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,YAAY,UAAa,YAAY,YAAY,OAAO,aACpE,YAAY,eAAe,UAAa,YAAY,eAAe,OAAO;AAE/E;;;ADEA,SAAS,yBAAyB,EAAC,YAAU,UAAU,OAAO,MAAM,OAAO,GAAG,MAAK,GAAkC;AACnH,QAAM,cACH,OAAO,aAAa,OAAO,aAAa,OAAO,WAAW,OAAO,aAAc;AAAA,IAC9E,WAAW,OAAO;AAAA,IAClB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,YAAY,OAAO;AAAA,EACrB,IAAI,EAAC,YAAY,KAAI;AAEvB,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,QAAQ;AAChD,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,mBAAmB,aAAa,KAAK,GAAG;AAC3C,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,eAAe,QAAQ,KAAK,MAAM;AAEhD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,MAAM,cAAc,KAAK,GAAG;AAAA,MAC5B;AAAA,MACA,OAAO,EAAE,UAAU,GAAG,GAAG,MAAM;AAAA;AAAA,IAE9B,SACC;AAAA,MAAC;AAAA;AAAA,QACC,KAAI;AAAA,QACJ,KAAK,MAAM;AAAA,QACX,QAAQ,MAAM,SAAS,mBAAmB,MAAM,MAAM,IAAI;AAAA;AAAA,IAC5D;AAAA,EAEJ;AAEJ;AAEA,yBAAyB,WAAW;AAAA,EAClC,MAAM;AACR;AAEA,IAAO,mCAAQ;","names":[]}
@@ -34,15 +34,33 @@ __export(AdViewUnitDefaultTemplate_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(AdViewUnitDefaultTemplate_exports);
36
36
  var import_react = __toESM(require("react"), 1);
37
+
38
+ // src/AdViewUnit/utils.ts
39
+ var matchExpectedState = (expectState, state) => {
40
+ 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);
41
+ };
42
+
43
+ // src/AdViewUnit/AdViewUnitDefaultTemplate.tsx
37
44
  function AdViewUnitDefaultTemplate({ type = "default", data, state, children, ...props }) {
45
+ if (data) {
46
+ return null;
47
+ }
48
+ const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
49
+ isInitial: props?.isInitial,
50
+ isLoading: props?.isLoading,
51
+ isError: props?.isError,
52
+ isComplete: props?.isComplete
53
+ } : { isComplete: true };
54
+ if (!matchExpectedState(expectState, state)) {
55
+ return null;
56
+ }
38
57
  if (typeof children === "function") {
39
58
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children({ data, state, ...props }));
40
59
  }
41
60
  return children ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children) : /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "1rem", textAlign: "center", color: "#666" } }, /* @__PURE__ */ import_react.default.createElement("p", null, "\u{1F504} Default content for ad unit"), /* @__PURE__ */ import_react.default.createElement("p", null, "Data: ", JSON.stringify(data)), /* @__PURE__ */ import_react.default.createElement("p", null, "State: ", JSON.stringify(state)));
42
61
  }
43
- AdViewUnitDefaultTemplate.defaultProps = {
44
- type: "default",
45
- children: null
62
+ AdViewUnitDefaultTemplate.defaults = {
63
+ type: "default"
46
64
  };
47
65
  var AdViewUnitDefaultTemplate_default = AdViewUnitDefaultTemplate;
48
66
  //# sourceMappingURL=AdViewUnitDefaultTemplate.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AdViewUnit/AdViewUnitDefaultTemplate.tsx"],"sourcesContent":["import React from \"react\";\nimport { AdViewOptionalDataProps, AdViewUnitTemplateTypeProps } from \"../types\";\n\ntype AdViewUnitDefaultTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'default';\n children?: React.ReactNode | ((props: AdViewOptionalDataProps) => React.ReactNode);\n};\n\nfunction AdViewUnitDefaultTemplate({ type='default', data, state, children, ...props }: AdViewUnitDefaultTemplateProps) {\n if (typeof children === 'function') {\n return <>{children({ data, state, ...props })}</>;\n }\n\n return (\n children ? <>{children}</> : (\n <div style={{ padding: '1rem', textAlign: 'center', color: '#666' }}>\n <p>🔄 Default content for ad unit</p>\n <p>Data: {JSON.stringify(data)}</p>\n <p>State: {JSON.stringify(state)}</p>\n </div>\n )\n );\n}\n\nAdViewUnitDefaultTemplate.defaultProps = {\n type: 'default',\n children: null,\n};\n\nexport default AdViewUnitDefaultTemplate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAQlB,SAAS,0BAA0B,EAAE,OAAK,WAAW,MAAM,OAAO,UAAU,GAAG,MAAM,GAAmC;AACtH,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,6BAAAA,QAAA,2BAAAA,QAAA,gBAAG,SAAS,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,CAAE;AAAA,EAChD;AAEA,SACE,WAAW,6BAAAA,QAAA,2BAAAA,QAAA,gBAAG,QAAS,IACrB,6BAAAA,QAAA,cAAC,SAAI,OAAO,EAAE,SAAS,QAAQ,WAAW,UAAU,OAAO,OAAO,KAChE,6BAAAA,QAAA,cAAC,WAAE,uCAA8B,GACjC,6BAAAA,QAAA,cAAC,WAAE,UAAO,KAAK,UAAU,IAAI,CAAE,GAC/B,6BAAAA,QAAA,cAAC,WAAE,WAAQ,KAAK,UAAU,KAAK,CAAE,CACnC;AAGN;AAEA,0BAA0B,eAAe;AAAA,EACvC,MAAM;AAAA,EACN,UAAU;AACZ;AAEA,IAAO,oCAAQ;","names":["React"]}
1
+ {"version":3,"sources":["../../src/AdViewUnit/AdViewUnitDefaultTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["import React from \"react\";\nimport { AdLoadState, AdViewOptionalDataProps, AdViewUnitTemplateTypeProps } from \"../types\";\nimport { matchExpectedState } from \"./utils\";\n\ntype AdViewUnitDefaultTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'default';\n children?: React.ReactNode | ((props: AdViewOptionalDataProps) => React.ReactNode);\n};\n\nfunction AdViewUnitDefaultTemplate({ type='default', data, state, children, ...props }: AdViewUnitDefaultTemplateProps) {\n if (data) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n if (typeof children === 'function') {\n return <>{children({ data, state, ...props })}</>;\n }\n\n return (\n children ? <>{children}</> : (\n <div style={{ padding: '1rem', textAlign: 'center', color: '#666' }}>\n <p>🔄 Default content for ad unit</p>\n <p>Data: {JSON.stringify(data)}</p>\n <p>State: {JSON.stringify(state)}</p>\n </div>\n )\n );\n}\n\nAdViewUnitDefaultTemplate.defaults = {\n type: 'default',\n};\n\nexport default AdViewUnitDefaultTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;;;ACEX,IAAM,qBAAqB,CAAC,aAA2B,UAAwB;AACpF,SAAO,CAAC,gBACL,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,YAAY,UAAa,YAAY,YAAY,OAAO,aACpE,YAAY,eAAe,UAAa,YAAY,eAAe,OAAO;AAE/E;;;ADAA,SAAS,0BAA0B,EAAE,OAAK,WAAW,MAAM,OAAO,UAAU,GAAG,MAAM,GAAmC;AACtH,MAAI,MAAM;AACR,WAAO;AAAA,EACT;AAEA,QAAM,cACH,OAAO,aAAa,OAAO,aAAa,OAAO,WAAW,OAAO,aAAc;AAAA,IAC9E,WAAW,OAAO;AAAA,IAClB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,YAAY,OAAO;AAAA,EACrB,IAAI,EAAC,YAAY,KAAI;AAGvB,MAAI,CAAC,mBAAmB,aAAa,KAAK,GAAG;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,6BAAAA,QAAA,2BAAAA,QAAA,gBAAG,SAAS,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,CAAE;AAAA,EAChD;AAEA,SACE,WAAW,6BAAAA,QAAA,2BAAAA,QAAA,gBAAG,QAAS,IACrB,6BAAAA,QAAA,cAAC,SAAI,OAAO,EAAE,SAAS,QAAQ,WAAW,UAAU,OAAO,OAAO,KAChE,6BAAAA,QAAA,cAAC,WAAE,uCAA8B,GACjC,6BAAAA,QAAA,cAAC,WAAE,UAAO,KAAK,UAAU,IAAI,CAAE,GAC/B,6BAAAA,QAAA,cAAC,WAAE,WAAQ,KAAK,UAAU,KAAK,CAAE,CACnC;AAGN;AAEA,0BAA0B,WAAW;AAAA,EACnC,MAAM;AACR;AAEA,IAAO,oCAAQ;","names":["React"]}
@@ -1,16 +1,15 @@
1
1
  import React from 'react';
2
- import { c as AdViewUnitTemplateTypeProps, d as AdViewOptionalDataProps } from '../types-B65WDsgh.cjs';
2
+ import { b as AdViewUnitTemplateTypeProps, c as AdViewOptionalDataProps } from '../types-E00UyX0q.cjs';
3
3
  import '@adview/core/typings';
4
4
 
5
5
  type AdViewUnitDefaultTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {
6
6
  type?: 'default';
7
7
  children?: React.ReactNode | ((props: AdViewOptionalDataProps) => React.ReactNode);
8
8
  };
9
- declare function AdViewUnitDefaultTemplate({ type, data, state, children, ...props }: AdViewUnitDefaultTemplateProps): React.JSX.Element;
9
+ declare function AdViewUnitDefaultTemplate({ type, data, state, children, ...props }: AdViewUnitDefaultTemplateProps): React.JSX.Element | null;
10
10
  declare namespace AdViewUnitDefaultTemplate {
11
- var defaultProps: {
11
+ var defaults: {
12
12
  type: string;
13
- children: null;
14
13
  };
15
14
  }
16
15