@adview/react 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/AdViewUnit/AdViewProvider.d.cts +4 -4
  2. package/dist/AdViewUnit/AdViewProvider.d.ts +4 -4
  3. package/dist/AdViewUnit/AdViewUnit.cjs +106 -298
  4. package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
  5. package/dist/AdViewUnit/AdViewUnit.client.cjs +86 -256
  6. package/dist/AdViewUnit/AdViewUnit.client.cjs.map +1 -1
  7. package/dist/AdViewUnit/AdViewUnit.client.d.cts +3 -3
  8. package/dist/AdViewUnit/AdViewUnit.client.d.ts +3 -3
  9. package/dist/AdViewUnit/AdViewUnit.client.js +69 -239
  10. package/dist/AdViewUnit/AdViewUnit.client.js.map +1 -1
  11. package/dist/AdViewUnit/AdViewUnit.d.cts +3 -3
  12. package/dist/AdViewUnit/AdViewUnit.d.ts +3 -3
  13. package/dist/AdViewUnit/AdViewUnit.js +85 -277
  14. package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
  15. package/dist/AdViewUnit/AdViewUnit.server.cjs +82 -214
  16. package/dist/AdViewUnit/AdViewUnit.server.cjs.map +1 -1
  17. package/dist/AdViewUnit/AdViewUnit.server.d.cts +3 -3
  18. package/dist/AdViewUnit/AdViewUnit.server.d.ts +3 -3
  19. package/dist/AdViewUnit/AdViewUnit.server.js +72 -204
  20. package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
  21. package/dist/AdViewUnit/{AdViewUnitBanner.cjs → AdViewUnitBannerTemplate.cjs} +17 -14
  22. package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs.map +1 -0
  23. package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +12 -0
  24. package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +12 -0
  25. package/dist/AdViewUnit/AdViewUnitBannerTemplate.js +32 -0
  26. package/dist/AdViewUnit/AdViewUnitBannerTemplate.js.map +1 -0
  27. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs +48 -0
  28. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs.map +1 -0
  29. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +17 -0
  30. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +17 -0
  31. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js +17 -0
  32. package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js.map +1 -0
  33. package/dist/AdViewUnit/{AdViewUnitNative.cjs → AdViewUnitNativeTemplate.cjs} +12 -13
  34. package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs.map +1 -0
  35. package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +11 -0
  36. package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +11 -0
  37. package/dist/AdViewUnit/{AdViewUnitNative.js → AdViewUnitNativeTemplate.js} +9 -10
  38. package/dist/AdViewUnit/AdViewUnitNativeTemplate.js.map +1 -0
  39. package/dist/AdViewUnit/{AdViewUnitProxy.cjs → AdViewUnitProxyTemplate.cjs} +14 -13
  40. package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs.map +1 -0
  41. package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +12 -0
  42. package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +12 -0
  43. package/dist/AdViewUnit/AdViewUnitProxyTemplate.js +33 -0
  44. package/dist/AdViewUnit/AdViewUnitProxyTemplate.js.map +1 -0
  45. package/dist/AdViewUnit/AdViewUnitTemplate.cjs +114 -0
  46. package/dist/AdViewUnit/AdViewUnitTemplate.cjs.map +1 -1
  47. package/dist/AdViewUnit/AdViewUnitTemplate.d.cts +14 -1
  48. package/dist/AdViewUnit/AdViewUnitTemplate.d.ts +14 -1
  49. package/dist/AdViewUnit/AdViewUnitTemplate.js +77 -0
  50. package/dist/AdViewUnit/AdViewUnitTemplate.js.map +1 -1
  51. package/dist/AdViewUnit/AdViewUnitTracking.d.cts +3 -3
  52. package/dist/AdViewUnit/AdViewUnitTracking.d.ts +3 -3
  53. package/dist/AdViewUnit/useAdViewController.cjs +5 -1
  54. package/dist/AdViewUnit/useAdViewController.cjs.map +1 -1
  55. package/dist/AdViewUnit/useAdViewController.d.cts +2 -2
  56. package/dist/AdViewUnit/useAdViewController.d.ts +2 -2
  57. package/dist/AdViewUnit/useAdViewController.js +5 -1
  58. package/dist/AdViewUnit/useAdViewController.js.map +1 -1
  59. package/dist/index.cjs +250 -255
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +10 -22
  62. package/dist/index.d.ts +10 -22
  63. package/dist/index.js +232 -240
  64. package/dist/index.js.map +1 -1
  65. package/dist/server.cjs +214 -173
  66. package/dist/server.cjs.map +1 -1
  67. package/dist/server.d.cts +7 -17
  68. package/dist/server.d.ts +7 -17
  69. package/dist/server.js +195 -161
  70. package/dist/server.js.map +1 -1
  71. package/dist/{types-BaV07oMT.d.cts → types-B65WDsgh.d.cts} +29 -25
  72. package/dist/{types-BaV07oMT.d.ts → types-B65WDsgh.d.ts} +29 -25
  73. package/package.json +1 -1
  74. package/dist/AdViewUnit/AdViewUnitBanner.cjs.map +0 -1
  75. package/dist/AdViewUnit/AdViewUnitBanner.d.cts +0 -10
  76. package/dist/AdViewUnit/AdViewUnitBanner.d.ts +0 -10
  77. package/dist/AdViewUnit/AdViewUnitBanner.js +0 -29
  78. package/dist/AdViewUnit/AdViewUnitBanner.js.map +0 -1
  79. package/dist/AdViewUnit/AdViewUnitNative.cjs.map +0 -1
  80. package/dist/AdViewUnit/AdViewUnitNative.d.cts +0 -10
  81. package/dist/AdViewUnit/AdViewUnitNative.d.ts +0 -10
  82. package/dist/AdViewUnit/AdViewUnitNative.js.map +0 -1
  83. package/dist/AdViewUnit/AdViewUnitProxy.cjs.map +0 -1
  84. package/dist/AdViewUnit/AdViewUnitProxy.d.cts +0 -10
  85. package/dist/AdViewUnit/AdViewUnitProxy.d.ts +0 -10
  86. package/dist/AdViewUnit/AdViewUnitProxy.js +0 -32
  87. package/dist/AdViewUnit/AdViewUnitProxy.js.map +0 -1
  88. package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs +0 -203
  89. package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs.map +0 -1
  90. package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.cts +0 -12
  91. package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.ts +0 -12
  92. package/dist/AdViewUnit/AdViewUnitTypeSwitch.js +0 -170
  93. package/dist/AdViewUnit/AdViewUnitTypeSwitch.js.map +0 -1
  94. package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs +0 -250
  95. package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs.map +0 -1
  96. package/dist/AdViewUnit/AdViewUnitWrapper.client.d.cts +0 -11
  97. package/dist/AdViewUnit/AdViewUnitWrapper.client.d.ts +0 -11
  98. package/dist/AdViewUnit/AdViewUnitWrapper.client.js +0 -220
  99. package/dist/AdViewUnit/AdViewUnitWrapper.client.js.map +0 -1
  100. package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs +0 -232
  101. package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs.map +0 -1
  102. package/dist/AdViewUnit/AdViewUnitWrapper.server.d.cts +0 -11
  103. package/dist/AdViewUnit/AdViewUnitWrapper.server.d.ts +0 -11
  104. package/dist/AdViewUnit/AdViewUnitWrapper.server.js +0 -201
  105. package/dist/AdViewUnit/AdViewUnitWrapper.server.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx"],"sourcesContent":["'use client';\n\nimport { AdViewData } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { useContext, useEffect, useState } from 'react';\nimport { AdLoadState, AdViewConfig } from '../types';\nimport { AdViewProviderContext } from './AdViewProvider';\n\ntype UseAdViewControllerProps = [AdViewData | null, Error | null, AdLoadState];\n\nfunction useAdViewController(\n adUnitConfig: AdViewConfig,\n unitId: string,\n format?: string,\n): UseAdViewControllerProps {\n const [adLoadState, setAdLoadState] = useState<string>('initial');\n const [adData, setAdData] = useState<AdViewData | null>(null);\n const [errorMessage, setErrorMessage] = useState<Error | null>(null);\n const globalConfig = useContext(AdViewProviderContext);\n const baseConfig = getResolveConfig({ ...adUnitConfig, ...globalConfig });\n const requestUrl = getAdRequestUrl(baseConfig, unitId, format);\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n console.log('Requesting ad data from:', adViewFetcher, 'with URL:', requestUrl);\n const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);\n console.log('AdViewController response:', response);\n\n if (response instanceof Error) {\n setAdLoadState('error');\n setErrorMessage(response);\n } else {\n setAdData(response);\n }\n setAdLoadState('complete');\n } catch (error) {\n setAdLoadState('error');\n setAdLoadState('complete');\n setErrorMessage(error as Error);\n }\n };\n const loadState = {\n isInitial: adLoadState === 'initial',\n isLoading: adLoadState === 'loading',\n isComplete: adLoadState === 'complete',\n isError: adLoadState === 'error',\n };\n\n useEffect(() => {\n loadAd();\n }, []);\n\n return [adData, errorMessage, loadState];\n}\n\nexport default useAdViewController;\n","'use client';\n\nimport React, { createContext } from 'react';\nimport { type AdViewConfig } from '../types';\n\ntype AdViewProviderContextProps = AdViewConfig;\n\nexport const AdViewProviderContext = createContext<AdViewProviderContextProps>(\n {} as AdViewProviderContextProps,\n);\n\ntype AdViewProviderProps = {\n children: React.ReactNode;\n} & AdViewProviderContextProps;\n\nconst AdViewProvider = ({ children, ...props }: AdViewProviderProps) => {\n return (\n <AdViewProviderContext.Provider value={props}>\n {children}\n </AdViewProviderContext.Provider>\n );\n};\n\nexport default AdViewProvider;\n"],"mappings":";;;AAGA,SAAS,eAAe,iBAAiB,wBAAwB;AACjE,SAAS,YAAY,WAAW,gBAAgB;;;ACFhD,OAAO,SAAS,qBAAqB;AAK9B,IAAM,wBAAwB;AAAA,EACnC,CAAC;AACH;;;ADCA,SAAS,oBACP,cACA,QACA,QAC0B;AAC1B,QAAM,CAAC,aAAa,cAAc,IAAI,SAAiB,SAAS;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA4B,IAAI;AAC5D,QAAM,CAAC,cAAc,eAAe,IAAI,SAAuB,IAAI;AACnE,QAAM,eAAe,WAAW,qBAAqB;AACrD,QAAM,aAAa,iBAAiB,EAAE,GAAG,cAAc,GAAG,aAAa,CAAC;AACxE,QAAM,aAAa,gBAAgB,YAAY,QAAQ,MAAM;AAC7D,QAAM,SAAS,YAAY;AACzB,mBAAe,SAAS;AAExB,QAAI;AACF,cAAQ,IAAI,4BAA4B,eAAe,aAAa,UAAU;AAC9E,YAAM,WAAW,MAAM,cAAc,YAAY,WAAW,aAAa;AACzE,cAAQ,IAAI,8BAA8B,QAAQ;AAElD,UAAI,oBAAoB,OAAO;AAC7B,uBAAe,OAAO;AACtB,wBAAgB,QAAQ;AAAA,MAC1B,OAAO;AACL,kBAAU,QAAQ;AAAA,MACpB;AACA,qBAAe,UAAU;AAAA,IAC3B,SAAS,OAAO;AACd,qBAAe,OAAO;AACtB,qBAAe,UAAU;AACzB,sBAAgB,KAAc;AAAA,IAChC;AAAA,EACF;AACA,QAAM,YAAY;AAAA,IAChB,WAAW,gBAAgB;AAAA,IAC3B,WAAW,gBAAgB;AAAA,IAC3B,YAAY,gBAAgB;AAAA,IAC5B,SAAS,gBAAgB;AAAA,EAC3B;AAEA,YAAU,MAAM;AACd,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO,CAAC,QAAQ,cAAc,SAAS;AACzC;AAEA,IAAO,8BAAQ;","names":[]}
1
+ {"version":3,"sources":["../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx"],"sourcesContent":["'use client';\n\nimport { AdViewData } from '@adview/core/typings';\nimport { adViewFetcher, getAdRequestUrl, getResolveConfig } from '@adview/core/utils';\nimport { useContext, useEffect, useState } from 'react';\nimport { AdLoadState, AdViewConfig } from '../types';\nimport { AdViewProviderContext } from './AdViewProvider';\n\ntype UseAdViewControllerProps = [AdViewData | null, Error | null, AdLoadState];\n\nfunction useAdViewController(\n adUnitConfig: AdViewConfig,\n unitId: string,\n format?: string | string[],\n): UseAdViewControllerProps {\n const [adLoadState, setAdLoadState] = useState<string>('initial');\n const [adData, setAdData] = useState<AdViewData | null>(null);\n const [errorMessage, setErrorMessage] = useState<Error | null>(null);\n const globalConfig = useContext(AdViewProviderContext);\n const baseConfig = getResolveConfig({ ...adUnitConfig, ...globalConfig });\n const requestUrl = getAdRequestUrl(baseConfig, unitId,\n typeof format === 'string' ? format : format?.join(',') || '');\n\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n console.log('Requesting ad data from:', adViewFetcher, 'with URL:', requestUrl);\n const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);\n console.log('AdViewController response:', response);\n\n if (response instanceof Error) {\n setAdLoadState('error');\n setErrorMessage(response);\n } else {\n setAdData(response);\n }\n setAdLoadState('complete');\n } catch (error) {\n setAdLoadState('error');\n setAdLoadState('complete');\n setErrorMessage(error as Error);\n }\n };\n\n const loadState = {\n isInitial: adLoadState === 'initial',\n isLoading: adLoadState === 'loading',\n isComplete: adLoadState === 'complete',\n isError: adLoadState === 'error',\n };\n\n useEffect(() => {loadAd()}, []);\n\n return [adData, errorMessage, loadState];\n}\n\nexport default useAdViewController;\n","'use client';\n\nimport React, { createContext } from 'react';\nimport { type AdViewConfig } from '../types';\n\ntype AdViewProviderContextProps = AdViewConfig;\n\nexport const AdViewProviderContext = createContext<AdViewProviderContextProps>(\n {} as AdViewProviderContextProps,\n);\n\ntype AdViewProviderProps = {\n children: React.ReactNode;\n} & AdViewProviderContextProps;\n\nconst AdViewProvider = ({ children, ...props }: AdViewProviderProps) => {\n return (\n <AdViewProviderContext.Provider value={props}>\n {children}\n </AdViewProviderContext.Provider>\n );\n};\n\nexport default AdViewProvider;\n"],"mappings":";;;AAGA,SAAS,eAAe,iBAAiB,wBAAwB;AACjE,SAAS,YAAY,WAAW,gBAAgB;;;ACFhD,OAAO,SAAS,qBAAqB;AAK9B,IAAM,wBAAwB;AAAA,EACnC,CAAC;AACH;;;ADCA,SAAS,oBACP,cACA,QACA,QAC0B;AAC1B,QAAM,CAAC,aAAa,cAAc,IAAI,SAAiB,SAAS;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA4B,IAAI;AAC5D,QAAM,CAAC,cAAc,eAAe,IAAI,SAAuB,IAAI;AACnE,QAAM,eAAe,WAAW,qBAAqB;AACrD,QAAM,aAAa,iBAAiB,EAAE,GAAG,cAAc,GAAG,aAAa,CAAC;AACxE,QAAM,aAAa;AAAA,IAAgB;AAAA,IAAY;AAAA,IAC7C,OAAO,WAAW,WAAW,SAAS,QAAQ,KAAK,GAAG,KAAK;AAAA,EAAE;AAE/D,QAAM,SAAS,YAAY;AACzB,mBAAe,SAAS;AAExB,QAAI;AACF,cAAQ,IAAI,4BAA4B,eAAe,aAAa,UAAU;AAC9E,YAAM,WAAW,MAAM,cAAc,YAAY,WAAW,aAAa;AACzE,cAAQ,IAAI,8BAA8B,QAAQ;AAElD,UAAI,oBAAoB,OAAO;AAC7B,uBAAe,OAAO;AACtB,wBAAgB,QAAQ;AAAA,MAC1B,OAAO;AACL,kBAAU,QAAQ;AAAA,MACpB;AACA,qBAAe,UAAU;AAAA,IAC3B,SAAS,OAAO;AACd,qBAAe,OAAO;AACtB,qBAAe,UAAU;AACzB,sBAAgB,KAAc;AAAA,IAChC;AAAA,EACF;AAEA,QAAM,YAAY;AAAA,IAChB,WAAW,gBAAgB;AAAA,IAC3B,WAAW,gBAAgB;AAAA,IAC3B,YAAY,gBAAgB;AAAA,IAC5B,SAAS,gBAAgB;AAAA,EAC3B;AAEA,YAAU,MAAM;AAAC,WAAO;AAAA,EAAC,GAAG,CAAC,CAAC;AAE9B,SAAO,CAAC,QAAQ,cAAc,SAAS;AACzC;AAEA,IAAO,8BAAQ;","names":[]}
package/dist/index.cjs CHANGED
@@ -33,17 +33,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  var index_exports = {};
34
34
  __export(index_exports, {
35
35
  AdViewProvider: () => AdViewProvider_default,
36
- AdViewUnitBanner: () => AdViewUnitBanner_default,
36
+ AdViewUnitBannerTemplate: () => AdViewUnitBannerTemplate_default,
37
37
  AdViewUnitClient: () => AdViewUnit_client_default,
38
- AdViewUnitNative: () => AdViewUnitNative_default,
39
- AdViewUnitProxy: () => AdViewUnitProxy_default,
40
- AdViewUnitTypeSwitch: () => AdViewUnitTypeSwitch_default,
41
- Banner: () => AdViewUnitBanner_default,
42
- Client: () => AdViewUnit_client_default,
43
- Native: () => AdViewUnitNative_default,
44
- Proxy: () => AdViewUnitProxy_default,
45
- TypeSwitch: () => AdViewUnitTypeSwitch_default,
46
- default: () => index_default
38
+ AdViewUnitDefaultTemplate: () => AdViewUnitDefaultTemplate_default,
39
+ AdViewUnitNativeTemplate: () => AdViewUnitNativeTemplate_default,
40
+ AdViewUnitProxyTemplate: () => AdViewUnitProxyTemplate_default,
41
+ AdViewUnitTemplate: () => AdViewUnitTemplate_default,
42
+ BannerTemplate: () => AdViewUnitBannerTemplate_default,
43
+ DefaultTemplate: () => AdViewUnitDefaultTemplate_default,
44
+ NativeTemplate: () => AdViewUnitNativeTemplate_default,
45
+ Provider: () => AdViewProvider_default,
46
+ ProxyTemplate: () => AdViewUnitProxyTemplate_default,
47
+ Template: () => AdViewUnitTemplate_default,
48
+ Unit: () => AdViewUnit_client_default
47
49
  });
48
50
  module.exports = __toCommonJS(index_exports);
49
51
 
@@ -58,11 +60,82 @@ var AdViewProvider = ({ children, ...props }) => {
58
60
  var AdViewProvider_default = AdViewProvider;
59
61
 
60
62
  // src/AdViewUnit/AdViewUnit.client.tsx
61
- var import_react9 = __toESM(require("react"), 1);
63
+ var import_react5 = __toESM(require("react"), 1);
64
+
65
+ // src/AdViewUnit/AdViewUnitTemplate.tsx
66
+ var import_react2 = __toESM(require("react"), 1);
67
+ var templateFromListRender = (tmpls, data, wrap) => {
68
+ let renderedRemplates = tmpls.map((tmpl, index) => {
69
+ let tmp = renderTemplate(tmpl, data);
70
+ return !!tmp && import_react2.default.isValidElement(tmp) ? /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
71
+ }).filter((it) => !!it);
72
+ if (!renderedRemplates.length) {
73
+ renderedRemplates = tmpls.map((tmpl, index) => {
74
+ let tmp = renderTemplate(tmpl, { ...data, type: "default" });
75
+ return !!tmp && import_react2.default.isValidElement(tmp) ? /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
76
+ }).filter((it) => !!it);
77
+ }
78
+ return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, renderedRemplates);
79
+ };
80
+ var renderTemplate = (tmpl, data) => {
81
+ const isFunction = typeof tmpl === "function";
82
+ const isReactElement = import_react2.default.isValidElement(tmpl);
83
+ if (isReactElement) {
84
+ const { type, children } = tmpl.props;
85
+ console.log("=====>\nrenderTemplate: React element detected, type:", type, "data:", data.type, data.type !== type);
86
+ if (data.type !== type) {
87
+ return null;
88
+ }
89
+ if (typeof children === "function") {
90
+ return children(data);
91
+ }
92
+ console.log("CLONE ELEMENT", tmpl);
93
+ return import_react2.default.cloneElement(tmpl, {
94
+ ...data,
95
+ children
96
+ });
97
+ }
98
+ if (isFunction) {
99
+ return tmpl(data);
100
+ }
101
+ return null;
102
+ };
103
+ var renderTemplates = (tmpls, data, listRender) => {
104
+ return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);
105
+ };
106
+ var renderAnyTemplates = (tmpls, data, listRender) => {
107
+ if (!tmpls) {
108
+ return null;
109
+ }
110
+ if (Array.isArray(tmpls)) {
111
+ return renderTemplates(tmpls, data, listRender);
112
+ }
113
+ if (typeof tmpls === "function") {
114
+ return tmpls(data);
115
+ }
116
+ if (import_react2.default.isValidElement(tmpls)) {
117
+ return templateFromListRender([tmpls], data);
118
+ }
119
+ return null;
120
+ };
121
+ var AdViewUnitTemplate = ({ type, children, ...data }) => {
122
+ const tmplProps = {
123
+ type,
124
+ ...data
125
+ };
126
+ if (typeof children === "function") {
127
+ return children(tmplProps);
128
+ }
129
+ if (import_react2.default.isValidElement(children)) {
130
+ return import_react2.default.cloneElement(children, tmplProps);
131
+ }
132
+ return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null);
133
+ };
134
+ var AdViewUnitTemplate_default = AdViewUnitTemplate;
62
135
 
63
136
  // src/AdViewUnit/AdViewUnitTracking.tsx
64
137
  var import_utils = require("@adview/core/utils");
65
- var import_react2 = __toESM(require("react"), 1);
138
+ var import_react3 = __toESM(require("react"), 1);
66
139
  function AdViewUnitTracking({
67
140
  impressions,
68
141
  views,
@@ -70,12 +143,12 @@ function AdViewUnitTracking({
70
143
  children
71
144
  }) {
72
145
  const isServer = typeof window === "undefined";
73
- const wrapperRef = (0, import_react2.useRef)(null);
74
- const executeImpressionsTrackingHandler = (0, import_react2.useCallback)(
146
+ const wrapperRef = (0, import_react3.useRef)(null);
147
+ const executeImpressionsTrackingHandler = (0, import_react3.useCallback)(
75
148
  () => (0, import_utils.executeImpressionsTracking)(impressions),
76
149
  [impressions]
77
150
  );
78
- const trackingObserverInstanceHandler = (0, import_react2.useCallback)(
151
+ const trackingObserverInstanceHandler = (0, import_react3.useCallback)(
79
152
  (entries) => {
80
153
  entries.forEach((entry) => {
81
154
  if (entry.isIntersecting) {
@@ -86,14 +159,14 @@ function AdViewUnitTracking({
86
159
  },
87
160
  [views]
88
161
  );
89
- const trackingObserverInstance = (0, import_react2.useMemo)(() => {
162
+ const trackingObserverInstance = (0, import_react3.useMemo)(() => {
90
163
  return !isServer ? new IntersectionObserver(trackingObserverInstanceHandler) : null;
91
164
  }, [isServer, trackingObserverInstanceHandler]);
92
- const clickTrackerHandler = (0, import_react2.useCallback)(() => {
165
+ const clickTrackerHandler = (0, import_react3.useCallback)(() => {
93
166
  (0, import_utils.executeImpressionsTracking)(clicks);
94
167
  wrapperRef.current?.removeEventListener("click", clickTrackerHandler);
95
168
  }, [clicks]);
96
- (0, import_react2.useEffect)(() => {
169
+ (0, import_react3.useEffect)(() => {
97
170
  if (wrapperRef.current && trackingObserverInstance) {
98
171
  executeImpressionsTrackingHandler();
99
172
  wrapperRef.current?.addEventListener("click", clickTrackerHandler);
@@ -111,113 +184,223 @@ function AdViewUnitTracking({
111
184
  executeImpressionsTrackingHandler,
112
185
  clickTrackerHandler
113
186
  ]);
114
- return /* @__PURE__ */ import_react2.default.createElement("div", { ref: wrapperRef }, children);
187
+ return /* @__PURE__ */ import_react3.default.createElement("div", { ref: wrapperRef }, children);
115
188
  }
116
189
  var AdViewUnitTracking_default = AdViewUnitTracking;
117
190
 
118
- // src/AdViewUnit/AdViewUnitWrapper.client.tsx
119
- var import_react7 = __toESM(require("react"), 1);
120
-
121
- // src/AdViewUnit/AdViewUnitNative.tsx
191
+ // src/AdViewUnit/useAdViewController.ts
122
192
  var import_utils2 = require("@adview/core/utils");
123
- var import_react3 = __toESM(require("react"), 1);
124
- function AdViewUnitNative({
125
- assets,
126
- fields,
127
- url,
128
- classNames
193
+ var import_react4 = require("react");
194
+ function useAdViewController(adUnitConfig, unitId, format) {
195
+ const [adLoadState, setAdLoadState] = (0, import_react4.useState)("initial");
196
+ const [adData, setAdData] = (0, import_react4.useState)(null);
197
+ const [errorMessage, setErrorMessage] = (0, import_react4.useState)(null);
198
+ const globalConfig = (0, import_react4.useContext)(AdViewProviderContext);
199
+ const baseConfig = (0, import_utils2.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
200
+ const requestUrl = (0, import_utils2.getAdRequestUrl)(
201
+ baseConfig,
202
+ unitId,
203
+ typeof format === "string" ? format : format?.join(",") || ""
204
+ );
205
+ const loadAd = async () => {
206
+ setAdLoadState("loading");
207
+ try {
208
+ console.log("Requesting ad data from:", import_utils2.adViewFetcher, "with URL:", requestUrl);
209
+ const response = await (0, import_utils2.adViewFetcher)(requestUrl, baseConfig.defaultAdData);
210
+ console.log("AdViewController response:", response);
211
+ if (response instanceof Error) {
212
+ setAdLoadState("error");
213
+ setErrorMessage(response);
214
+ } else {
215
+ setAdData(response);
216
+ }
217
+ setAdLoadState("complete");
218
+ } catch (error) {
219
+ setAdLoadState("error");
220
+ setAdLoadState("complete");
221
+ setErrorMessage(error);
222
+ }
223
+ };
224
+ const loadState = {
225
+ isInitial: adLoadState === "initial",
226
+ isLoading: adLoadState === "loading",
227
+ isComplete: adLoadState === "complete",
228
+ isError: adLoadState === "error"
229
+ };
230
+ (0, import_react4.useEffect)(() => {
231
+ loadAd();
232
+ }, []);
233
+ return [adData, errorMessage, loadState];
234
+ }
235
+ var useAdViewController_default = useAdViewController;
236
+
237
+ // src/AdViewUnit/AdViewUnit.client.tsx
238
+ function AdViewUnitClient({
239
+ unitId,
240
+ format,
241
+ children,
242
+ ...config
129
243
  }) {
130
- const asset = (0, import_utils2.getAssetByName)("main", assets);
244
+ const [response, error, loadState] = useAdViewController_default(
245
+ config,
246
+ unitId,
247
+ format
248
+ );
249
+ const responseGroup = error ? null : response?.groups?.[0];
250
+ const customTracker = responseGroup?.custom_tracker ?? {};
251
+ const groupItems = responseGroup?.items;
252
+ if (groupItems && groupItems?.length > 0) {
253
+ return groupItems.map(({ tracker, ...data }) => {
254
+ return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, renderAnyTemplates(children, { data, type: data.type || "default", error, state: loadState }));
255
+ });
256
+ }
257
+ return /* @__PURE__ */ import_react5.default.createElement(AdViewUnitTracking_default, { ...customTracker }, renderAnyTemplates(children, { data: null, type: "default", error, state: loadState }));
258
+ }
259
+ var AdViewUnit_client_default = AdViewUnitClient;
260
+
261
+ // src/AdViewUnit/AdViewUnitBannerTemplate.tsx
262
+ var import_utils3 = require("@adview/core/utils");
263
+ var import_react6 = __toESM(require("react"), 1);
264
+ function AdViewUnitBannerTemplate({ className = "banner", style, data, state }) {
265
+ if (!data || !data.assets || !data.assets.length || !state?.isComplete) {
266
+ return null;
267
+ }
268
+ const asset = (0, import_utils3.getAssetByName)("main", data.assets);
269
+ return /* @__PURE__ */ import_react6.default.createElement(
270
+ "a",
271
+ {
272
+ target: "_blank",
273
+ rel: "noopener noreferrer",
274
+ href: (0, import_utils3.getPrepareURL)(data.url),
275
+ className,
276
+ style: { fontSize: 0, ...style }
277
+ },
278
+ asset && /* @__PURE__ */ import_react6.default.createElement(
279
+ "img",
280
+ {
281
+ alt: "main",
282
+ src: asset.path,
283
+ srcSet: asset.thumbs ? (0, import_utils3.getSrcSetCSSThumbs)(asset.thumbs) : ""
284
+ }
285
+ )
286
+ );
287
+ }
288
+ var AdViewUnitBannerTemplate_default = AdViewUnitBannerTemplate;
289
+
290
+ // src/AdViewUnit/AdViewUnitDefaultTemplate.tsx
291
+ var import_react7 = __toESM(require("react"), 1);
292
+ function AdViewUnitDefaultTemplate({ type = "default", data, state, children, ...props }) {
293
+ if (typeof children === "function") {
294
+ return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, children({ data, state, ...props }));
295
+ }
296
+ 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)));
297
+ }
298
+ AdViewUnitDefaultTemplate.defaultProps = {
299
+ type: "default",
300
+ children: null
301
+ };
302
+ var AdViewUnitDefaultTemplate_default = AdViewUnitDefaultTemplate;
303
+
304
+ // src/AdViewUnit/AdViewUnitNativeTemplate.tsx
305
+ var import_utils4 = require("@adview/core/utils");
306
+ var import_react8 = __toESM(require("react"), 1);
307
+ function AdViewUnitNativeTemplate({ classNames, data, state }) {
308
+ if (!data || !data.assets || !data.assets.length || !state?.isComplete) {
309
+ return null;
310
+ }
311
+ const { assets, url, fields } = data;
312
+ const asset = (0, import_utils4.getAssetByName)("main", assets);
131
313
  if (!url) {
132
314
  return null;
133
315
  }
134
- return /* @__PURE__ */ import_react3.default.createElement("div", { className: classNames?.container }, /* @__PURE__ */ import_react3.default.createElement(
316
+ return /* @__PURE__ */ import_react8.default.createElement("div", { className: classNames?.container }, /* @__PURE__ */ import_react8.default.createElement(
135
317
  "a",
136
318
  {
137
319
  target: "_blank",
138
320
  rel: "noopener noreferrer",
139
- href: (0, import_utils2.getPrepareURL)(url),
321
+ href: (0, import_utils4.getPrepareURL)(url),
140
322
  className: classNames?.imageLink
141
323
  },
142
- asset && /* @__PURE__ */ import_react3.default.createElement(
324
+ asset && /* @__PURE__ */ import_react8.default.createElement(
143
325
  "img",
144
326
  {
145
327
  alt: fields?.title,
146
328
  title: fields?.title,
147
329
  src: asset.path,
148
- srcSet: asset.thumbs ? (0, import_utils2.getSrcSetCSSThumbs)(asset.thumbs) : void 0,
330
+ srcSet: asset.thumbs ? (0, import_utils4.getSrcSetCSSThumbs)(asset.thumbs) : void 0,
149
331
  className: classNames?.image,
150
332
  style: { objectFit: "cover", width: "100%", height: "100%" }
151
333
  }
152
334
  )
153
- ), /* @__PURE__ */ import_react3.default.createElement("div", { className: classNames?.label }, fields?.title && /* @__PURE__ */ import_react3.default.createElement(
335
+ ), /* @__PURE__ */ import_react8.default.createElement("div", { className: classNames?.label }, fields?.title && /* @__PURE__ */ import_react8.default.createElement(
154
336
  "a",
155
337
  {
156
338
  target: "_blank",
157
339
  rel: "noopener noreferrer",
158
- href: (0, import_utils2.getPrepareURL)(url),
340
+ href: (0, import_utils4.getPrepareURL)(url),
159
341
  "data-class": "titleLink",
160
342
  className: classNames?.titleLink
161
343
  },
162
344
  fields.title
163
- ), fields?.description && /* @__PURE__ */ import_react3.default.createElement(
345
+ ), fields?.description && /* @__PURE__ */ import_react8.default.createElement(
164
346
  "a",
165
347
  {
166
348
  target: "_blank",
167
349
  rel: "noopener noreferrer",
168
- href: (0, import_utils2.getPrepareURL)(url),
350
+ href: (0, import_utils4.getPrepareURL)(url),
169
351
  "data-class": "descriptionLink",
170
352
  className: classNames?.descriptionLink
171
353
  },
172
354
  fields.description
173
- ), fields?.brandname && /* @__PURE__ */ import_react3.default.createElement(
355
+ ), fields?.brandname && /* @__PURE__ */ import_react8.default.createElement(
174
356
  "a",
175
357
  {
176
358
  target: "_blank",
177
359
  rel: "noopener noreferrer",
178
- href: (0, import_utils2.getPrepareURL)(url),
360
+ href: (0, import_utils4.getPrepareURL)(url),
179
361
  "data-class": "brandNameLink",
180
362
  className: classNames?.brandNameLink
181
363
  },
182
364
  fields.brandname
183
- ), fields?.phone && /* @__PURE__ */ import_react3.default.createElement(
365
+ ), fields?.phone && /* @__PURE__ */ import_react8.default.createElement(
184
366
  "a",
185
367
  {
186
368
  target: "_blank",
187
369
  rel: "noopener noreferrer",
188
- href: (0, import_utils2.getPrepareURL)(url),
370
+ href: (0, import_utils4.getPrepareURL)(url),
189
371
  "data-class": "phoneLink",
190
372
  className: classNames?.phoneLink
191
373
  },
192
374
  fields.phone
193
- ), fields?.url && /* @__PURE__ */ import_react3.default.createElement(
375
+ ), fields?.url && /* @__PURE__ */ import_react8.default.createElement(
194
376
  "a",
195
377
  {
196
378
  target: "_blank",
197
379
  rel: "noopener noreferrer",
198
- href: (0, import_utils2.getPrepareURL)(url),
380
+ href: (0, import_utils4.getPrepareURL)(url),
199
381
  "data-class": "urlLink",
200
382
  className: classNames?.urlLink
201
383
  },
202
384
  fields?.url
203
385
  )));
204
386
  }
205
- var AdViewUnitNative_default = AdViewUnitNative;
387
+ var AdViewUnitNativeTemplate_default = AdViewUnitNativeTemplate;
206
388
 
207
- // src/AdViewUnit/AdViewUnitProxy.tsx
208
- var import_react4 = __toESM(require("react"), 1);
209
- function AdViewUnitProxy({
210
- // assets,
211
- fields,
212
- url
213
- }) {
389
+ // src/AdViewUnit/AdViewUnitProxyTemplate.tsx
390
+ var import_react9 = __toESM(require("react"), 1);
391
+ function AdViewUnitProxyTemplate({ className, style, data, state }) {
392
+ if (!data || !state?.isComplete) {
393
+ return null;
394
+ }
395
+ const { url, fields } = data;
214
396
  const iframeSrc = fields?.url || url;
215
397
  if (!iframeSrc) {
216
398
  return null;
217
399
  }
218
- return /* @__PURE__ */ import_react4.default.createElement(
400
+ return /* @__PURE__ */ import_react9.default.createElement(
219
401
  "iframe",
220
402
  {
403
+ className,
221
404
  width: "100%",
222
405
  height: "100%",
223
406
  frameBorder: "0",
@@ -226,215 +409,27 @@ function AdViewUnitProxy({
226
409
  allowTransparency: true,
227
410
  scrolling: "no",
228
411
  allowFullScreen: true,
229
- style: { width: "100%", height: "100%" },
412
+ style: { width: "100%", height: "100%", border: "none", ...style },
230
413
  src: iframeSrc
231
414
  }
232
415
  );
233
416
  }
234
- var AdViewUnitProxy_default = AdViewUnitProxy;
235
-
236
- // src/AdViewUnit/AdViewUnitBanner.tsx
237
- var import_utils3 = require("@adview/core/utils");
238
- var import_react5 = __toESM(require("react"), 1);
239
- function AdViewUnitBanner({ assets, url }) {
240
- const asset = (0, import_utils3.getAssetByName)("main", assets);
241
- return /* @__PURE__ */ import_react5.default.createElement("center", null, /* @__PURE__ */ import_react5.default.createElement(
242
- "a",
243
- {
244
- target: "_blank",
245
- rel: "noopener noreferrer",
246
- href: (0, import_utils3.getPrepareURL)(url),
247
- className: "banner",
248
- style: { fontSize: 0 }
249
- },
250
- asset && /* @__PURE__ */ import_react5.default.createElement(
251
- "img",
252
- {
253
- alt: "main",
254
- src: asset.path,
255
- srcSet: asset.thumbs ? (0, import_utils3.getSrcSetCSSThumbs)(asset.thumbs) : ""
256
- }
257
- )
258
- ));
259
- }
260
- var AdViewUnitBanner_default = AdViewUnitBanner;
261
-
262
- // src/AdViewUnit/AdViewUnitTypeSwitch.tsx
263
- var import_react6 = __toESM(require("react"), 1);
264
- function AdViewUnitTypeSwitch({
265
- data,
266
- classNames,
267
- onDefault
268
- }) {
269
- switch (data?.type) {
270
- case "native":
271
- return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitNative_default, { ...data, classNames: classNames?.native });
272
- case "proxy":
273
- return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitProxy_default, { ...data, classNames: classNames?.proxy });
274
- case "banner":
275
- return /* @__PURE__ */ import_react6.default.createElement(AdViewUnitBanner_default, { ...data, classNames: classNames?.banner });
276
- default:
277
- if (import_react6.default.isValidElement(onDefault)) {
278
- return import_react6.default.cloneElement(onDefault);
279
- }
280
- if (typeof onDefault === "function") {
281
- return onDefault();
282
- }
283
- return null;
284
- }
285
- }
286
- var AdViewUnitTypeSwitch_default = AdViewUnitTypeSwitch;
287
-
288
- // src/AdViewUnit/AdViewUnitWrapper.client.tsx
289
- function AdViewUnitWrapperClient({
290
- data,
291
- state,
292
- error,
293
- children,
294
- onDefault
295
- }) {
296
- const { isLoading, isError } = state;
297
- const isChildrenReactNode = import_react7.default.isValidElement(children);
298
- const isChildrenFunction = typeof children === "function";
299
- if (isChildrenReactNode) {
300
- return import_react7.default.cloneElement(children, {
301
- data,
302
- state,
303
- error,
304
- onDefault
305
- });
306
- }
307
- if (isChildrenFunction) {
308
- return children({
309
- data,
310
- state,
311
- error,
312
- onDefault
313
- });
314
- }
315
- if (isLoading) {
316
- return null;
317
- }
318
- if (!children && !isError && data) {
319
- return /* @__PURE__ */ import_react7.default.createElement(AdViewUnitTypeSwitch_default, { data, onDefault });
320
- }
321
- if (import_react7.default.isValidElement(onDefault)) {
322
- return import_react7.default.cloneElement(onDefault);
323
- }
324
- if (typeof onDefault === "function") {
325
- return onDefault();
326
- }
327
- return null;
328
- }
329
- var AdViewUnitWrapper_client_default = AdViewUnitWrapperClient;
330
-
331
- // src/AdViewUnit/useAdViewController.ts
332
- var import_utils4 = require("@adview/core/utils");
333
- var import_react8 = require("react");
334
- function useAdViewController(adUnitConfig, unitId, format) {
335
- const [adLoadState, setAdLoadState] = (0, import_react8.useState)("initial");
336
- const [adData, setAdData] = (0, import_react8.useState)(null);
337
- const [errorMessage, setErrorMessage] = (0, import_react8.useState)(null);
338
- const globalConfig = (0, import_react8.useContext)(AdViewProviderContext);
339
- const baseConfig = (0, import_utils4.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
340
- const requestUrl = (0, import_utils4.getAdRequestUrl)(baseConfig, unitId, format);
341
- const loadAd = async () => {
342
- setAdLoadState("loading");
343
- try {
344
- console.log("Requesting ad data from:", import_utils4.adViewFetcher, "with URL:", requestUrl);
345
- const response = await (0, import_utils4.adViewFetcher)(requestUrl, baseConfig.defaultAdData);
346
- console.log("AdViewController response:", response);
347
- if (response instanceof Error) {
348
- setAdLoadState("error");
349
- setErrorMessage(response);
350
- } else {
351
- setAdData(response);
352
- }
353
- setAdLoadState("complete");
354
- } catch (error) {
355
- setAdLoadState("error");
356
- setAdLoadState("complete");
357
- setErrorMessage(error);
358
- }
359
- };
360
- const loadState = {
361
- isInitial: adLoadState === "initial",
362
- isLoading: adLoadState === "loading",
363
- isComplete: adLoadState === "complete",
364
- isError: adLoadState === "error"
365
- };
366
- (0, import_react8.useEffect)(() => {
367
- loadAd();
368
- }, []);
369
- return [adData, errorMessage, loadState];
370
- }
371
- var useAdViewController_default = useAdViewController;
372
-
373
- // src/AdViewUnit/AdViewUnit.client.tsx
374
- function AdViewUnitClient({
375
- unitId,
376
- format,
377
- children,
378
- onDefault = () => null,
379
- ...config
380
- }) {
381
- const [response, error, loadState] = useAdViewController_default(
382
- config,
383
- unitId,
384
- format
385
- );
386
- const responseGroup = error ? null : response?.groups?.[0];
387
- const customTracker = responseGroup?.custom_tracker ?? {};
388
- const groupItems = responseGroup?.items;
389
- if (groupItems && groupItems?.length) {
390
- return groupItems.map(({ tracker, ...data }) => {
391
- return /* @__PURE__ */ import_react9.default.createElement(AdViewUnitTracking_default, { key: data.id, ...tracker }, /* @__PURE__ */ import_react9.default.createElement(
392
- AdViewUnitWrapper_client_default,
393
- {
394
- state: loadState,
395
- error,
396
- data,
397
- onDefault
398
- },
399
- children
400
- ));
401
- });
402
- }
403
- return /* @__PURE__ */ import_react9.default.createElement(AdViewUnitTracking_default, { ...customTracker }, /* @__PURE__ */ import_react9.default.createElement(
404
- AdViewUnitWrapper_client_default,
405
- {
406
- state: loadState,
407
- error,
408
- onDefault
409
- },
410
- children
411
- ));
412
- }
413
- var AdViewUnit_client_default = AdViewUnitClient;
414
-
415
- // src/index.ts
416
- var AdView = {};
417
- var AdViewExport = Object.assign(AdView, {
418
- Provider: AdViewProvider_default,
419
- Unit: AdViewUnit_client_default,
420
- Banner: AdViewUnitBanner_default,
421
- Native: AdViewUnitNative_default,
422
- Proxy: AdViewUnitProxy_default,
423
- TypeSwitch: AdViewUnitTypeSwitch_default
424
- });
425
- var index_default = AdViewExport;
417
+ var AdViewUnitProxyTemplate_default = AdViewUnitProxyTemplate;
426
418
  // Annotate the CommonJS export names for ESM import in node:
427
419
  0 && (module.exports = {
428
420
  AdViewProvider,
429
- AdViewUnitBanner,
421
+ AdViewUnitBannerTemplate,
430
422
  AdViewUnitClient,
431
- AdViewUnitNative,
432
- AdViewUnitProxy,
433
- AdViewUnitTypeSwitch,
434
- Banner,
435
- Client,
436
- Native,
437
- Proxy,
438
- TypeSwitch
423
+ AdViewUnitDefaultTemplate,
424
+ AdViewUnitNativeTemplate,
425
+ AdViewUnitProxyTemplate,
426
+ AdViewUnitTemplate,
427
+ BannerTemplate,
428
+ DefaultTemplate,
429
+ NativeTemplate,
430
+ Provider,
431
+ ProxyTemplate,
432
+ Template,
433
+ Unit
439
434
  });
440
435
  //# sourceMappingURL=index.cjs.map