@adview/react 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AdViewUnit/AdViewUnit.cjs +273 -243
- package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.cjs +234 -198
- package/dist/AdViewUnit/AdViewUnit.client.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.d.cts +2 -2
- package/dist/AdViewUnit/AdViewUnit.client.d.ts +2 -2
- package/dist/AdViewUnit/AdViewUnit.client.js +226 -190
- package/dist/AdViewUnit/AdViewUnit.client.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnit.d.ts +1 -1
- package/dist/AdViewUnit/AdViewUnit.js +261 -231
- package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.cjs +229 -157
- package/dist/AdViewUnit/AdViewUnit.server.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.d.cts +3 -3
- package/dist/AdViewUnit/AdViewUnit.server.d.ts +3 -3
- package/dist/AdViewUnit/AdViewUnit.server.js +227 -155
- package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
- package/dist/AdViewUnit/{AdViewUnitBanner.cjs → AdViewUnitBannerTemplate.cjs} +36 -14
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +17 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +17 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.js +51 -0
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.js.map +1 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs +66 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +16 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +16 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js +35 -0
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.js.map +1 -0
- package/dist/AdViewUnit/{AdViewUnitNative.cjs → AdViewUnitNativeTemplate.cjs} +31 -13
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +16 -0
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +16 -0
- package/dist/AdViewUnit/{AdViewUnitNative.js → AdViewUnitNativeTemplate.js} +28 -10
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.js.map +1 -0
- package/dist/AdViewUnit/{AdViewUnitProxy.cjs → AdViewUnitProxyTemplate.cjs} +33 -13
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.cjs.map +1 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +17 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +17 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.js +52 -0
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.js.map +1 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.cjs +132 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.d.cts +14 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.d.ts +14 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.js +95 -0
- package/dist/AdViewUnit/AdViewUnitTemplate.js.map +1 -1
- package/dist/AdViewUnit/useAdViewController.cjs +5 -3
- package/dist/AdViewUnit/useAdViewController.cjs.map +1 -1
- package/dist/AdViewUnit/useAdViewController.d.cts +2 -2
- package/dist/AdViewUnit/useAdViewController.d.ts +2 -2
- package/dist/AdViewUnit/useAdViewController.js +5 -3
- package/dist/AdViewUnit/useAdViewController.js.map +1 -1
- package/dist/AdViewUnit/utils.cjs +33 -0
- package/dist/AdViewUnit/utils.cjs.map +1 -0
- package/dist/AdViewUnit/utils.d.cts +7 -0
- package/dist/AdViewUnit/utils.d.ts +7 -0
- package/dist/AdViewUnit/utils.js +8 -0
- package/dist/AdViewUnit/utils.js.map +1 -0
- package/dist/index.cjs +305 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +286 -193
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +302 -167
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +7 -6
- package/dist/server.d.ts +7 -6
- package/dist/server.js +288 -160
- package/dist/server.js.map +1 -1
- package/dist/{types-BaV07oMT.d.cts → types-DHjNgnRW.d.cts} +35 -43
- package/dist/{types-BaV07oMT.d.ts → types-DHjNgnRW.d.ts} +35 -43
- package/package.json +1 -1
- package/dist/AdViewUnit/AdViewUnitBanner.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitBanner.d.cts +0 -10
- package/dist/AdViewUnit/AdViewUnitBanner.d.ts +0 -10
- package/dist/AdViewUnit/AdViewUnitBanner.js +0 -29
- package/dist/AdViewUnit/AdViewUnitBanner.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitNative.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitNative.d.cts +0 -10
- package/dist/AdViewUnit/AdViewUnitNative.d.ts +0 -10
- package/dist/AdViewUnit/AdViewUnitNative.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitProxy.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitProxy.d.cts +0 -10
- package/dist/AdViewUnit/AdViewUnitProxy.d.ts +0 -10
- package/dist/AdViewUnit/AdViewUnitProxy.js +0 -32
- package/dist/AdViewUnit/AdViewUnitProxy.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs +0 -203
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.cts +0 -12
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.d.ts +0 -12
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.js +0 -170
- package/dist/AdViewUnit/AdViewUnitTypeSwitch.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs +0 -250
- package/dist/AdViewUnit/AdViewUnitWrapper.client.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.client.d.cts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.client.d.ts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.client.js +0 -220
- package/dist/AdViewUnit/AdViewUnitWrapper.client.js.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs +0 -232
- package/dist/AdViewUnit/AdViewUnitWrapper.server.cjs.map +0 -1
- package/dist/AdViewUnit/AdViewUnitWrapper.server.d.cts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.server.d.ts +0 -11
- package/dist/AdViewUnit/AdViewUnitWrapper.server.js +0 -201
- package/dist/AdViewUnit/AdViewUnitWrapper.server.js.map +0 -1
|
@@ -27,18 +27,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/AdViewUnit/
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
default: () =>
|
|
30
|
+
// src/AdViewUnit/AdViewUnitProxyTemplate.tsx
|
|
31
|
+
var AdViewUnitProxyTemplate_exports = {};
|
|
32
|
+
__export(AdViewUnitProxyTemplate_exports, {
|
|
33
|
+
default: () => AdViewUnitProxyTemplate_default
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(AdViewUnitProxyTemplate_exports);
|
|
36
36
|
var import_react = __toESM(require("react"), 1);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
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/AdViewUnitProxyTemplate.tsx
|
|
44
|
+
function AdViewUnitProxyTemplate({ className, style, data, state, ...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
|
+
}
|
|
57
|
+
const { url, fields } = data;
|
|
42
58
|
const iframeSrc = fields?.url || url;
|
|
43
59
|
if (!iframeSrc) {
|
|
44
60
|
return null;
|
|
@@ -46,6 +62,7 @@ function AdViewUnitProxy({
|
|
|
46
62
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
47
63
|
"iframe",
|
|
48
64
|
{
|
|
65
|
+
className,
|
|
49
66
|
width: "100%",
|
|
50
67
|
height: "100%",
|
|
51
68
|
frameBorder: "0",
|
|
@@ -54,10 +71,13 @@ function AdViewUnitProxy({
|
|
|
54
71
|
allowTransparency: true,
|
|
55
72
|
scrolling: "no",
|
|
56
73
|
allowFullScreen: true,
|
|
57
|
-
style: { width: "100%", height: "100%" },
|
|
74
|
+
style: { width: "100%", height: "100%", border: "none", ...style },
|
|
58
75
|
src: iframeSrc
|
|
59
76
|
}
|
|
60
77
|
);
|
|
61
78
|
}
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
AdViewUnitProxyTemplate.defaults = {
|
|
80
|
+
type: "proxy"
|
|
81
|
+
};
|
|
82
|
+
var AdViewUnitProxyTemplate_default = AdViewUnitProxyTemplate;
|
|
83
|
+
//# sourceMappingURL=AdViewUnitProxyTemplate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["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","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;;;ADCA,SAAS,wBAAwB,EAAC,WAAW,OAAO,MAAM,OAAO,GAAG,MAAK,GAAiC;AACxG,MAAI,CAAC,MAAM;AACT,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,QAAM,EAAE,KAAK,OAAO,IAAI;AACxB,QAAM,YAAY,QAAQ,OAAO;AAEjC,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,SACE,6BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAM;AAAA,MACN,QAAO;AAAA,MACP,aAAY;AAAA,MACZ,aAAa;AAAA,MACb,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,WAAU;AAAA,MACV,iBAAiB;AAAA,MACjB,OAAO,EAAE,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,MAAM;AAAA,MACjE,KAAK;AAAA;AAAA,EACN;AAEL;AAEA,wBAAwB,WAAW;AAAA,EACjC,MAAM;AACR;AAEA,IAAO,kCAAQ;","names":["React"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { b as AdViewUnitTemplateTypeProps } from '../types-DHjNgnRW.cjs';
|
|
3
|
+
import '@adview/core/typings';
|
|
4
|
+
|
|
5
|
+
type AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {
|
|
6
|
+
type?: 'proxy';
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
};
|
|
10
|
+
declare function AdViewUnitProxyTemplate({ className, style, data, state, ...props }: AdViewUnitProxyTemplateProps): React.JSX.Element | null;
|
|
11
|
+
declare namespace AdViewUnitProxyTemplate {
|
|
12
|
+
var defaults: {
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { AdViewUnitProxyTemplate as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { b as AdViewUnitTemplateTypeProps } from '../types-DHjNgnRW.js';
|
|
3
|
+
import '@adview/core/typings';
|
|
4
|
+
|
|
5
|
+
type AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {
|
|
6
|
+
type?: 'proxy';
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
};
|
|
10
|
+
declare function AdViewUnitProxyTemplate({ className, style, data, state, ...props }: AdViewUnitProxyTemplateProps): React.JSX.Element | null;
|
|
11
|
+
declare namespace AdViewUnitProxyTemplate {
|
|
12
|
+
var defaults: {
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { AdViewUnitProxyTemplate as default };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/AdViewUnit/AdViewUnitProxyTemplate.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
// src/AdViewUnit/utils.ts
|
|
5
|
+
var matchExpectedState = (expectState, state) => {
|
|
6
|
+
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);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/AdViewUnit/AdViewUnitProxyTemplate.tsx
|
|
10
|
+
function AdViewUnitProxyTemplate({ className, style, data, state, ...props }) {
|
|
11
|
+
if (!data) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
15
|
+
isInitial: props?.isInitial,
|
|
16
|
+
isLoading: props?.isLoading,
|
|
17
|
+
isError: props?.isError,
|
|
18
|
+
isComplete: props?.isComplete
|
|
19
|
+
} : { isComplete: true };
|
|
20
|
+
if (!matchExpectedState(expectState, state)) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const { url, fields } = data;
|
|
24
|
+
const iframeSrc = fields?.url || url;
|
|
25
|
+
if (!iframeSrc) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return /* @__PURE__ */ React.createElement(
|
|
29
|
+
"iframe",
|
|
30
|
+
{
|
|
31
|
+
className,
|
|
32
|
+
width: "100%",
|
|
33
|
+
height: "100%",
|
|
34
|
+
frameBorder: "0",
|
|
35
|
+
marginWidth: 0,
|
|
36
|
+
marginHeight: 0,
|
|
37
|
+
allowTransparency: true,
|
|
38
|
+
scrolling: "no",
|
|
39
|
+
allowFullScreen: true,
|
|
40
|
+
style: { width: "100%", height: "100%", border: "none", ...style },
|
|
41
|
+
src: iframeSrc
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
AdViewUnitProxyTemplate.defaults = {
|
|
46
|
+
type: "proxy"
|
|
47
|
+
};
|
|
48
|
+
var AdViewUnitProxyTemplate_default = AdViewUnitProxyTemplate;
|
|
49
|
+
export {
|
|
50
|
+
AdViewUnitProxyTemplate_default as default
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=AdViewUnitProxyTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["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","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,OAAO,WAAW;;;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;;;ADCA,SAAS,wBAAwB,EAAC,WAAW,OAAO,MAAM,OAAO,GAAG,MAAK,GAAiC;AACxG,MAAI,CAAC,MAAM;AACT,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,QAAM,EAAE,KAAK,OAAO,IAAI;AACxB,QAAM,YAAY,QAAQ,OAAO;AAEjC,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAM;AAAA,MACN,QAAO;AAAA,MACP,aAAY;AAAA,MACZ,aAAa;AAAA,MACb,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,WAAU;AAAA,MACV,iBAAiB;AAAA,MACjB,OAAO,EAAE,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,MAAM;AAAA,MACjE,KAAK;AAAA;AAAA,EACN;AAEL;AAEA,wBAAwB,WAAW;AAAA,EACjC,MAAM;AACR;AAEA,IAAO,kCAAQ;","names":[]}
|
|
@@ -1,2 +1,134 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/AdViewUnit/AdViewUnitTemplate.tsx
|
|
31
|
+
var AdViewUnitTemplate_exports = {};
|
|
32
|
+
__export(AdViewUnitTemplate_exports, {
|
|
33
|
+
default: () => AdViewUnitTemplate_default,
|
|
34
|
+
renderAnyTemplates: () => renderAnyTemplates,
|
|
35
|
+
renderTemplate: () => renderTemplate,
|
|
36
|
+
renderTemplates: () => renderTemplates,
|
|
37
|
+
templateFromListRender: () => templateFromListRender
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(AdViewUnitTemplate_exports);
|
|
40
|
+
var import_react = __toESM(require("react"), 1);
|
|
41
|
+
|
|
42
|
+
// src/AdViewUnit/utils.ts
|
|
43
|
+
var matchExpectedState = (expectState, state) => {
|
|
44
|
+
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);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/AdViewUnit/AdViewUnitTemplate.tsx
|
|
48
|
+
var templateFromListRender = (tmpls, data, wrap) => {
|
|
49
|
+
let renderedRemplates = tmpls.map((tmpl, index) => {
|
|
50
|
+
let tmp = renderTemplate(tmpl, data);
|
|
51
|
+
return !!tmp && import_react.default.isValidElement(tmp) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
52
|
+
}).filter((it) => !!it);
|
|
53
|
+
if (!renderedRemplates.length) {
|
|
54
|
+
renderedRemplates = tmpls.map((tmpl, index) => {
|
|
55
|
+
let tmp = renderTemplate(tmpl, { ...data, type: "default" });
|
|
56
|
+
return !!tmp && import_react.default.isValidElement(tmp) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
57
|
+
}).filter((it) => !!it);
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, renderedRemplates);
|
|
60
|
+
};
|
|
61
|
+
var renderTemplate = (tmpl, data) => {
|
|
62
|
+
const isFunction = typeof tmpl === "function";
|
|
63
|
+
const isReactElement = import_react.default.isValidElement(tmpl);
|
|
64
|
+
if (isReactElement) {
|
|
65
|
+
let { type, children } = tmpl.props;
|
|
66
|
+
if (!type && typeof tmpl.type !== "string") {
|
|
67
|
+
type = tmpl.type?.defaults?.type;
|
|
68
|
+
}
|
|
69
|
+
if (data.type !== type) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (typeof children === "function") {
|
|
73
|
+
return children(data);
|
|
74
|
+
}
|
|
75
|
+
return import_react.default.cloneElement(tmpl, {
|
|
76
|
+
...data,
|
|
77
|
+
children
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (isFunction) {
|
|
81
|
+
return tmpl(data);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
};
|
|
85
|
+
var renderTemplates = (tmpls, data, listRender) => {
|
|
86
|
+
return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);
|
|
87
|
+
};
|
|
88
|
+
var renderAnyTemplates = (tmpls, data, listRender) => {
|
|
89
|
+
if (!tmpls) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(tmpls)) {
|
|
93
|
+
return renderTemplates(tmpls, data, listRender);
|
|
94
|
+
}
|
|
95
|
+
if (typeof tmpls === "function") {
|
|
96
|
+
return tmpls(data);
|
|
97
|
+
}
|
|
98
|
+
if (import_react.default.isValidElement(tmpls)) {
|
|
99
|
+
return templateFromListRender([tmpls], data);
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
var AdViewUnitTemplate = ({ type, state, children, ...props }) => {
|
|
104
|
+
const tmplProps = {
|
|
105
|
+
type,
|
|
106
|
+
state,
|
|
107
|
+
...props
|
|
108
|
+
};
|
|
109
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
110
|
+
isInitial: props?.isInitial,
|
|
111
|
+
isLoading: props?.isLoading,
|
|
112
|
+
isError: props?.isError,
|
|
113
|
+
isComplete: props?.isComplete
|
|
114
|
+
} : { isComplete: true };
|
|
115
|
+
if (!matchExpectedState(expectState, state)) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (typeof children === "function") {
|
|
119
|
+
return children(tmplProps);
|
|
120
|
+
}
|
|
121
|
+
if (import_react.default.isValidElement(children)) {
|
|
122
|
+
return import_react.default.cloneElement(children, tmplProps);
|
|
123
|
+
}
|
|
124
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
|
|
125
|
+
};
|
|
126
|
+
var AdViewUnitTemplate_default = AdViewUnitTemplate;
|
|
127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
+
0 && (module.exports = {
|
|
129
|
+
renderAnyTemplates,
|
|
130
|
+
renderTemplate,
|
|
131
|
+
renderTemplates,
|
|
132
|
+
templateFromListRender
|
|
133
|
+
});
|
|
2
134
|
//# sourceMappingURL=AdViewUnitTemplate.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["//\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 (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","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;AAAA;AAAA;AAAA;AASA,mBAA2B;;;ACPpB,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;;;ADeO,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,aAAAA,QAAM,eAAe,GAAG,IACpC,6BAAAA,QAAA,cAAC,aAAAA,QAAM,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,aAAAA,QAAM,eAAe,GAAG,IACpC,6BAAAA,QAAA,cAAC,aAAAA,QAAM,UAAN,EAAe,KAAK,SAAQ,CAAC,CAAC,OAAO,KAAK,GAAG,IAAI,GAAI,IACtD;AAAA,IACN,CAAC,EAAE,OAAO,QAAM,CAAC,CAAC,EAAE;AAAA,EACtB;AAEA,SAAQ,6BAAAA,Q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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;AAGA,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,SAAS,SAA0C;AAAA,EAC5D;AAGA,MAAI,aAAAA,QAAM,eAAe,QAAQ,GAAG;AAClC,WAAO,aAAAA,QAAM,aAAa,UAAU,SAAS;AAAA,EAC/C;AAGA,SAAO,6BAAAA,QAAA,2BAAAA,QAAA,cAAE;AACX;AAEA,IAAO,6BAAQ;","names":["React"]}
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
+
import React, { JSX } from 'react';
|
|
2
|
+
import { e as AdViewUnitTemplateProps, b as AdViewUnitTemplateTypeProps } from '../types-DHjNgnRW.cjs';
|
|
3
|
+
import '@adview/core/typings';
|
|
1
4
|
|
|
2
|
-
|
|
5
|
+
type TemplateListRender = (tmpls: TemplateElement[]) => React.ReactElement | JSX.Element;
|
|
6
|
+
type TemplateType = React.Component<AdViewUnitTemplateProps>;
|
|
7
|
+
type TemplateElement = React.ReactElement<AdViewUnitTemplateProps>;
|
|
8
|
+
type TemplateTypeFunction = (props: AdViewUnitTemplateTypeProps) => React.ReactNode | React.ReactElement;
|
|
9
|
+
declare const templateFromListRender: (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, wrap?: (children: React.ReactNode) => React.ReactNode) => JSX.Element | React.ReactElement;
|
|
10
|
+
declare const renderTemplate: (tmpl: TemplateElement | TemplateTypeFunction, data: AdViewUnitTemplateTypeProps) => React.ReactNode;
|
|
11
|
+
declare const renderTemplates: (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender) => React.ReactNode | React.ReactElement | JSX.Element;
|
|
12
|
+
declare const renderAnyTemplates: (tmpls: any, data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender) => React.ReactNode | React.ReactElement | JSX.Element | null;
|
|
13
|
+
declare const AdViewUnitTemplate: ({ type, state, children, ...props }: AdViewUnitTemplateProps) => JSX.Element | null;
|
|
14
|
+
|
|
15
|
+
export { type TemplateElement, type TemplateListRender, type TemplateType, type TemplateTypeFunction, AdViewUnitTemplate as default, renderAnyTemplates, renderTemplate, renderTemplates, templateFromListRender };
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
+
import React, { JSX } from 'react';
|
|
2
|
+
import { e as AdViewUnitTemplateProps, b as AdViewUnitTemplateTypeProps } from '../types-DHjNgnRW.js';
|
|
3
|
+
import '@adview/core/typings';
|
|
1
4
|
|
|
2
|
-
|
|
5
|
+
type TemplateListRender = (tmpls: TemplateElement[]) => React.ReactElement | JSX.Element;
|
|
6
|
+
type TemplateType = React.Component<AdViewUnitTemplateProps>;
|
|
7
|
+
type TemplateElement = React.ReactElement<AdViewUnitTemplateProps>;
|
|
8
|
+
type TemplateTypeFunction = (props: AdViewUnitTemplateTypeProps) => React.ReactNode | React.ReactElement;
|
|
9
|
+
declare const templateFromListRender: (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, wrap?: (children: React.ReactNode) => React.ReactNode) => JSX.Element | React.ReactElement;
|
|
10
|
+
declare const renderTemplate: (tmpl: TemplateElement | TemplateTypeFunction, data: AdViewUnitTemplateTypeProps) => React.ReactNode;
|
|
11
|
+
declare const renderTemplates: (tmpls: TemplateElement[], data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender) => React.ReactNode | React.ReactElement | JSX.Element;
|
|
12
|
+
declare const renderAnyTemplates: (tmpls: any, data: AdViewUnitTemplateTypeProps, listRender?: TemplateListRender) => React.ReactNode | React.ReactElement | JSX.Element | null;
|
|
13
|
+
declare const AdViewUnitTemplate: ({ type, state, children, ...props }: AdViewUnitTemplateProps) => JSX.Element | null;
|
|
14
|
+
|
|
15
|
+
export { type TemplateElement, type TemplateListRender, type TemplateType, type TemplateTypeFunction, AdViewUnitTemplate as default, renderAnyTemplates, renderTemplate, renderTemplates, templateFromListRender };
|
|
@@ -1 +1,96 @@
|
|
|
1
|
+
// src/AdViewUnit/AdViewUnitTemplate.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
// src/AdViewUnit/utils.ts
|
|
5
|
+
var matchExpectedState = (expectState, state) => {
|
|
6
|
+
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);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/AdViewUnit/AdViewUnitTemplate.tsx
|
|
10
|
+
var templateFromListRender = (tmpls, data, wrap) => {
|
|
11
|
+
let renderedRemplates = tmpls.map((tmpl, index) => {
|
|
12
|
+
let tmp = renderTemplate(tmpl, data);
|
|
13
|
+
return !!tmp && React.isValidElement(tmp) ? /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
14
|
+
}).filter((it) => !!it);
|
|
15
|
+
if (!renderedRemplates.length) {
|
|
16
|
+
renderedRemplates = tmpls.map((tmpl, index) => {
|
|
17
|
+
let tmp = renderTemplate(tmpl, { ...data, type: "default" });
|
|
18
|
+
return !!tmp && React.isValidElement(tmp) ? /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, !!wrap ? wrap(tmp) : tmp) : null;
|
|
19
|
+
}).filter((it) => !!it);
|
|
20
|
+
}
|
|
21
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, renderedRemplates);
|
|
22
|
+
};
|
|
23
|
+
var renderTemplate = (tmpl, data) => {
|
|
24
|
+
const isFunction = typeof tmpl === "function";
|
|
25
|
+
const isReactElement = React.isValidElement(tmpl);
|
|
26
|
+
if (isReactElement) {
|
|
27
|
+
let { type, children } = tmpl.props;
|
|
28
|
+
if (!type && typeof tmpl.type !== "string") {
|
|
29
|
+
type = tmpl.type?.defaults?.type;
|
|
30
|
+
}
|
|
31
|
+
if (data.type !== type) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (typeof children === "function") {
|
|
35
|
+
return children(data);
|
|
36
|
+
}
|
|
37
|
+
return React.cloneElement(tmpl, {
|
|
38
|
+
...data,
|
|
39
|
+
children
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (isFunction) {
|
|
43
|
+
return tmpl(data);
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
var renderTemplates = (tmpls, data, listRender) => {
|
|
48
|
+
return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);
|
|
49
|
+
};
|
|
50
|
+
var renderAnyTemplates = (tmpls, data, listRender) => {
|
|
51
|
+
if (!tmpls) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(tmpls)) {
|
|
55
|
+
return renderTemplates(tmpls, data, listRender);
|
|
56
|
+
}
|
|
57
|
+
if (typeof tmpls === "function") {
|
|
58
|
+
return tmpls(data);
|
|
59
|
+
}
|
|
60
|
+
if (React.isValidElement(tmpls)) {
|
|
61
|
+
return templateFromListRender([tmpls], data);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
var AdViewUnitTemplate = ({ type, state, children, ...props }) => {
|
|
66
|
+
const tmplProps = {
|
|
67
|
+
type,
|
|
68
|
+
state,
|
|
69
|
+
...props
|
|
70
|
+
};
|
|
71
|
+
const expectState = props?.isInitial || props?.isLoading || props?.isError || props?.isComplete ? {
|
|
72
|
+
isInitial: props?.isInitial,
|
|
73
|
+
isLoading: props?.isLoading,
|
|
74
|
+
isError: props?.isError,
|
|
75
|
+
isComplete: props?.isComplete
|
|
76
|
+
} : { isComplete: true };
|
|
77
|
+
if (!matchExpectedState(expectState, state)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
if (typeof children === "function") {
|
|
81
|
+
return children(tmplProps);
|
|
82
|
+
}
|
|
83
|
+
if (React.isValidElement(children)) {
|
|
84
|
+
return React.cloneElement(children, tmplProps);
|
|
85
|
+
}
|
|
86
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
87
|
+
};
|
|
88
|
+
var AdViewUnitTemplate_default = AdViewUnitTemplate;
|
|
89
|
+
export {
|
|
90
|
+
AdViewUnitTemplate_default as default,
|
|
91
|
+
renderAnyTemplates,
|
|
92
|
+
renderTemplate,
|
|
93
|
+
renderTemplates,
|
|
94
|
+
templateFromListRender
|
|
95
|
+
};
|
|
1
96
|
//# sourceMappingURL=AdViewUnitTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/utils.ts"],"sourcesContent":["//\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 (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","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":";AASA,OAAO,WAAoB;;;ACPpB,IAAM,qBAAqB,CAAC,aAA2B,UAAwB;AACpF,SAAO,CAAC,gBACL,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,cAA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AAQ;","names":[]}
|
|
@@ -52,13 +52,15 @@ function useAdViewController(adUnitConfig, unitId, format) {
|
|
|
52
52
|
const [errorMessage, setErrorMessage] = (0, import_react2.useState)(null);
|
|
53
53
|
const globalConfig = (0, import_react2.useContext)(AdViewProviderContext);
|
|
54
54
|
const baseConfig = (0, import_utils.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
|
|
55
|
-
const requestUrl = (0, import_utils.getAdRequestUrl)(
|
|
55
|
+
const requestUrl = (0, import_utils.getAdRequestUrl)(
|
|
56
|
+
baseConfig,
|
|
57
|
+
unitId,
|
|
58
|
+
typeof format === "string" ? format : format?.join(",") || ""
|
|
59
|
+
);
|
|
56
60
|
const loadAd = async () => {
|
|
57
61
|
setAdLoadState("loading");
|
|
58
62
|
try {
|
|
59
|
-
console.log("Requesting ad data from:", import_utils.adViewFetcher, "with URL:", requestUrl);
|
|
60
63
|
const response = await (0, import_utils.adViewFetcher)(requestUrl, baseConfig.defaultAdData);
|
|
61
|
-
console.log("AdViewController response:", response);
|
|
62
64
|
if (response instanceof Error) {
|
|
63
65
|
setAdLoadState("error");
|
|
64
66
|
setErrorMessage(response);
|
|
@@ -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
|
|
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 const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAiE;AACjE,IAAAA,gBAAgD;;;ACFhD,mBAAqC;AAK9B,IAAM,4BAAwB;AAAA,EACnC,CAAC;AACH;;;ADCA,SAAS,oBACP,cACA,QACA,QAC0B;AAC1B,QAAM,CAAC,aAAa,cAAc,QAAI,wBAAiB,SAAS;AAChE,QAAM,CAAC,QAAQ,SAAS,QAAI,wBAA4B,IAAI;AAC5D,QAAM,CAAC,cAAc,eAAe,QAAI,wBAAuB,IAAI;AACnE,QAAM,mBAAe,0BAAW,qBAAqB;AACrD,QAAM,iBAAa,+BAAiB,EAAE,GAAG,cAAc,GAAG,aAAa,CAAC;AACxE,QAAM,iBAAa;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,YAAM,WAAW,UAAM,4BAAc,YAAY,WAAW,aAAa;AAEzE,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,+BAAU,MAAM;AAAC,WAAO;AAAA,EAAC,GAAG,CAAC,CAAC;AAE9B,SAAO,CAAC,QAAQ,cAAc,SAAS;AACzC;AAEA,IAAO,8BAAQ;","names":["import_react"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AdViewConfig, AdViewData } from '@adview/core/typings';
|
|
2
|
-
import {
|
|
2
|
+
import { f as AdLoadState } from '../types-DHjNgnRW.cjs';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
type UseAdViewControllerProps = [AdViewData | null, Error | null, AdLoadState];
|
|
6
|
-
declare function useAdViewController(adUnitConfig: AdViewConfig, unitId: string, format?: string): UseAdViewControllerProps;
|
|
6
|
+
declare function useAdViewController(adUnitConfig: AdViewConfig, unitId: string, format?: string | string[]): UseAdViewControllerProps;
|
|
7
7
|
|
|
8
8
|
export { useAdViewController as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AdViewConfig, AdViewData } from '@adview/core/typings';
|
|
2
|
-
import {
|
|
2
|
+
import { f as AdLoadState } from '../types-DHjNgnRW.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
type UseAdViewControllerProps = [AdViewData | null, Error | null, AdLoadState];
|
|
6
|
-
declare function useAdViewController(adUnitConfig: AdViewConfig, unitId: string, format?: string): UseAdViewControllerProps;
|
|
6
|
+
declare function useAdViewController(adUnitConfig: AdViewConfig, unitId: string, format?: string | string[]): UseAdViewControllerProps;
|
|
7
7
|
|
|
8
8
|
export { useAdViewController as default };
|
|
@@ -19,13 +19,15 @@ function useAdViewController(adUnitConfig, unitId, format) {
|
|
|
19
19
|
const [errorMessage, setErrorMessage] = useState(null);
|
|
20
20
|
const globalConfig = useContext(AdViewProviderContext);
|
|
21
21
|
const baseConfig = getResolveConfig({ ...adUnitConfig, ...globalConfig });
|
|
22
|
-
const requestUrl = getAdRequestUrl(
|
|
22
|
+
const requestUrl = getAdRequestUrl(
|
|
23
|
+
baseConfig,
|
|
24
|
+
unitId,
|
|
25
|
+
typeof format === "string" ? format : format?.join(",") || ""
|
|
26
|
+
);
|
|
23
27
|
const loadAd = async () => {
|
|
24
28
|
setAdLoadState("loading");
|
|
25
29
|
try {
|
|
26
|
-
console.log("Requesting ad data from:", adViewFetcher, "with URL:", requestUrl);
|
|
27
30
|
const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);
|
|
28
|
-
console.log("AdViewController response:", response);
|
|
29
31
|
if (response instanceof Error) {
|
|
30
32
|
setAdLoadState("error");
|
|
31
33
|
setErrorMessage(response);
|
|
@@ -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
|
|
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 const response = await adViewFetcher(requestUrl, baseConfig.defaultAdData);\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;;;ACFh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OwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/AdViewUnit/utils.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
matchExpectedState: () => matchExpectedState
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var matchExpectedState = (expectState, state) => {
|
|
27
|
+
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);
|
|
28
|
+
};
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
matchExpectedState
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/utils.ts"],"sourcesContent":["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;AAEO,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;","names":[]}
|