@adview/react 1.1.9 → 1.1.11
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 +62 -25
- package/dist/AdViewUnit/AdViewUnit.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.cjs +16 -4
- package/dist/AdViewUnit/AdViewUnit.client.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.client.d.cts +3 -2
- package/dist/AdViewUnit/AdViewUnit.client.d.ts +3 -2
- package/dist/AdViewUnit/AdViewUnit.client.js +16 -4
- 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 +62 -25
- package/dist/AdViewUnit/AdViewUnit.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.cjs +46 -21
- package/dist/AdViewUnit/AdViewUnit.server.cjs.map +1 -1
- package/dist/AdViewUnit/AdViewUnit.server.d.cts +5 -2
- package/dist/AdViewUnit/AdViewUnit.server.d.ts +5 -2
- package/dist/AdViewUnit/AdViewUnit.server.js +46 -21
- package/dist/AdViewUnit/AdViewUnit.server.js.map +1 -1
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnitBannerTemplate.d.ts +1 -1
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnitDefaultTemplate.d.ts +1 -1
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnitNativeTemplate.d.ts +1 -1
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnitProxyTemplate.d.ts +1 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.d.cts +1 -1
- package/dist/AdViewUnit/AdViewUnitTemplate.d.ts +1 -1
- package/dist/AdViewUnit/useAdViewController.cjs +11 -3
- package/dist/AdViewUnit/useAdViewController.cjs.map +1 -1
- package/dist/AdViewUnit/useAdViewController.d.cts +4 -2
- package/dist/AdViewUnit/useAdViewController.d.ts +4 -2
- package/dist/AdViewUnit/useAdViewController.js +11 -3
- package/dist/AdViewUnit/useAdViewController.js.map +1 -1
- package/dist/AdViewUnit/utils.d.cts +1 -1
- package/dist/AdViewUnit/utils.d.ts +1 -1
- package/dist/index.cjs +16 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +46 -21
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +46 -21
- package/dist/server.js.map +1 -1
- package/dist/{types-BocWXLhL.d.cts → types-Bc2HTUyk.d.cts} +4 -0
- package/dist/{types-BocWXLhL.d.ts → types-Bc2HTUyk.d.ts} +4 -0
- package/package.json +2 -2
|
@@ -369,17 +369,25 @@ var AdViewProviderContext = (0, import_react6.createContext)(
|
|
|
369
369
|
);
|
|
370
370
|
|
|
371
371
|
// src/AdViewUnit/useAdViewController.ts
|
|
372
|
-
function useAdViewController(adUnitConfig, unitId, limit = 1, format) {
|
|
372
|
+
function useAdViewController(adUnitConfig, unitId, limit = 1, format, query, sources) {
|
|
373
373
|
const [adLoadState, setAdLoadState] = (0, import_react7.useState)("initial");
|
|
374
374
|
const [adData, setAdData] = (0, import_react7.useState)(null);
|
|
375
375
|
const [errorMessage, setErrorMessage] = (0, import_react7.useState)(null);
|
|
376
376
|
const globalConfig = (0, import_react7.useContext)(AdViewProviderContext);
|
|
377
377
|
const baseConfig = (0, import_utils8.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
|
|
378
|
-
const dataLoader = (0, import_utils8.getDataLoaderFromConfig)(
|
|
378
|
+
const dataLoader = (0, import_utils8.getDataLoaderFromConfig)(
|
|
379
|
+
baseConfig,
|
|
380
|
+
sources
|
|
381
|
+
);
|
|
379
382
|
const loadAd = async () => {
|
|
380
383
|
setAdLoadState("loading");
|
|
381
384
|
try {
|
|
382
|
-
const response = await dataLoader.fetchAdData(
|
|
385
|
+
const response = await dataLoader.fetchAdData(
|
|
386
|
+
unitId,
|
|
387
|
+
limit || 1,
|
|
388
|
+
format,
|
|
389
|
+
query
|
|
390
|
+
);
|
|
383
391
|
if (response instanceof Error) {
|
|
384
392
|
setAdLoadState("error");
|
|
385
393
|
setErrorMessage(response);
|
|
@@ -411,9 +419,11 @@ function AdViewUnitClient({
|
|
|
411
419
|
unitId,
|
|
412
420
|
limit = 1,
|
|
413
421
|
format,
|
|
422
|
+
query,
|
|
414
423
|
children,
|
|
415
424
|
wrapper,
|
|
416
425
|
trackingWrapperClassName,
|
|
426
|
+
sources,
|
|
417
427
|
...config
|
|
418
428
|
}) {
|
|
419
429
|
const checkFormat = (f) => {
|
|
@@ -426,7 +436,9 @@ function AdViewUnitClient({
|
|
|
426
436
|
config,
|
|
427
437
|
unitId,
|
|
428
438
|
limit || 1,
|
|
429
|
-
format
|
|
439
|
+
format,
|
|
440
|
+
query,
|
|
441
|
+
sources
|
|
430
442
|
);
|
|
431
443
|
const {
|
|
432
444
|
responseGroup: _,
|
|
@@ -495,6 +507,10 @@ async function AdViewUnitServer({
|
|
|
495
507
|
format,
|
|
496
508
|
children,
|
|
497
509
|
limit,
|
|
510
|
+
query,
|
|
511
|
+
wrapper,
|
|
512
|
+
trackingWrapperClassName,
|
|
513
|
+
sources,
|
|
498
514
|
...config
|
|
499
515
|
}) {
|
|
500
516
|
const checkFormat = (f) => {
|
|
@@ -504,8 +520,16 @@ async function AdViewUnitServer({
|
|
|
504
520
|
return Array.isArray(format) ? format.includes(f) : f === format;
|
|
505
521
|
};
|
|
506
522
|
const baseConfig = (0, import_utils9.getResolveConfig)(config);
|
|
507
|
-
const dataLoader = (0, import_utils9.getDataLoaderFromConfig)(
|
|
508
|
-
|
|
523
|
+
const dataLoader = (0, import_utils9.getDataLoaderFromConfig)(
|
|
524
|
+
baseConfig,
|
|
525
|
+
sources
|
|
526
|
+
);
|
|
527
|
+
const response = await dataLoader.fetchAdData(
|
|
528
|
+
unitId,
|
|
529
|
+
limit || 1,
|
|
530
|
+
format,
|
|
531
|
+
query
|
|
532
|
+
);
|
|
509
533
|
const isLoadingError = response instanceof Error;
|
|
510
534
|
const error = isLoadingError ? response : void 0;
|
|
511
535
|
const state = {
|
|
@@ -535,28 +559,41 @@ async function AdViewUnitServer({
|
|
|
535
559
|
/* @__PURE__ */ import_react9.default.createElement(AdViewUnitProxyTemplate_default, null)
|
|
536
560
|
];
|
|
537
561
|
}
|
|
562
|
+
if (!wrapper) {
|
|
563
|
+
wrapper = (elms) => /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, elms);
|
|
564
|
+
}
|
|
538
565
|
if (groupItems && groupItems.length) {
|
|
539
|
-
return
|
|
540
|
-
({ tracker, ...data }, index) => {
|
|
541
|
-
return /* @__PURE__ */ import_react9.default.createElement(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
566
|
+
return wrapper(
|
|
567
|
+
groupItems.map(({ tracker, ...data }, index) => {
|
|
568
|
+
return /* @__PURE__ */ import_react9.default.createElement(
|
|
569
|
+
AdViewUnitTracking_default,
|
|
570
|
+
{
|
|
571
|
+
key: data.id,
|
|
572
|
+
...tracker,
|
|
573
|
+
className: trackingWrapperClassName
|
|
574
|
+
},
|
|
575
|
+
renderAnyTemplates(children, {
|
|
576
|
+
unitId,
|
|
577
|
+
index,
|
|
578
|
+
data,
|
|
579
|
+
type: data.type || "default",
|
|
580
|
+
error,
|
|
581
|
+
state
|
|
582
|
+
})
|
|
583
|
+
);
|
|
584
|
+
})
|
|
550
585
|
);
|
|
551
586
|
}
|
|
552
|
-
return
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
587
|
+
return wrapper([
|
|
588
|
+
/* @__PURE__ */ import_react9.default.createElement(AdViewUnitTracking_default, { ...customTracker, className: trackingWrapperClassName }, renderAnyTemplates(children, {
|
|
589
|
+
unitId,
|
|
590
|
+
index: -1,
|
|
591
|
+
data: null,
|
|
592
|
+
type: "default",
|
|
593
|
+
error,
|
|
594
|
+
state
|
|
595
|
+
}))
|
|
596
|
+
]);
|
|
560
597
|
}
|
|
561
598
|
var AdViewUnit_server_default = AdViewUnitServer;
|
|
562
599
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.tsx","../../src/AdViewUnit/AdViewUnit.client.tsx","../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts","../../src/AdViewUnit/AdViewUnitNativeTemplate.tsx","../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx","../../src/AdViewUnit/AdViewUnit.server.tsx"],"sourcesContent":["import React from 'react';\nimport AdViewUnitClient, { AdViewUnitClientProps } from './AdViewUnit.client';\nimport AdViewUnitServer, { AdViewUnitServerProps } from './AdViewUnit.server';\n\nexport type AdViewUnitProps = typeof window extends undefined\n ? AdViewUnitServerProps\n : AdViewUnitClientProps;\n\nfunction AdViewUnit(props: AdViewUnitProps) {\n const isServer = typeof window === 'undefined';\n\n if (isServer) {\n return <AdViewUnitServer {...(props as AdViewUnitServerProps)} />;\n }\n\n return <AdViewUnitClient {...(props as AdViewUnitClientProps)} />;\n}\n\nexport default AdViewUnit;\n","'use client';\n\nimport { AdViewGroupItem } from '@adview/core';\nimport React from 'react';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport useAdViewController from './useAdViewController';\n\nexport type AdViewUnitClientProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n wrapper?: (elms: React.ReactNode[]) => React.ReactNode;\n trackingWrapperClassName?: string;\n};\n\n// AdViewUnitClient is a client-side component that fetches ad data and renders it\n// using the provided children function. It handles loading, error states, and\n// tracks ad interactions.\n//\n// Example usage:\n// <AdView.Unit unitId=\"my-unit\" format=\"banner\" srcURL=\"https://api.example.com/ads/{<id>}\">\n// {({ data, state, error }) => (\n// <div>\n// {state.isLoading && <span>Loading...</span>}\n// {error && <span>Error: {error.message}</span>}\n// {data && <img src={data.imageUrl} alt={data.title} />\n// </div>\n// )}\n// </AdView.Unit>\n//\n// Note: This component is designed to be used in a client-side environment where\n// ad data can be fetched dynamically. It is not suitable for server-side rendering.\n// It uses the AdViewUnitTracking component to handle ad tracking and interactions.\nfunction AdViewUnitClient({\n unitId,\n limit = 1,\n format,\n children,\n wrapper,\n trackingWrapperClassName,\n ...config\n}: AdViewUnitClientProps) {\n const checkFormat = (f: string) => {\n if (!format) {\n return true;\n }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\n const [response, error, loadState] = useAdViewController(\n config,\n unitId,\n limit || 1,\n format,\n );\n\n const {\n responseGroup: _,\n customTracker,\n groupItems,\n } = error\n ? { responseGroup: null, customTracker: {}, groupItems: [] }\n : (() => {\n for (let responseGroup of response?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || [])\n .map(it => (checkFormat(it.type) ? it : null))\n .filter(Boolean);\n if (groupItems && groupItems.length > 0) {\n return { responseGroup, customTracker, groupItems };\n }\n }\n return { responseGroup: null, customTracker: {}, groupItems: [] };\n })();\n\n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />,\n ];\n }\n\n if (!wrapper) {\n wrapper = (elms: React.ReactNode[]) => <>{elms}</>;\n }\n\n if (groupItems && groupItems?.length > 0) {\n return wrapper(\n (groupItems as AdViewGroupItem[]).map(({ tracker, ...data }, index) => {\n return (\n <AdViewUnitTracking\n key={data.id}\n {...tracker}\n className={trackingWrapperClassName}\n >\n {renderAnyTemplates(children, {\n unitId,\n index,\n data,\n type: data.type || 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>\n );\n }),\n );\n }\n\n return wrapper([\n <AdViewUnitTracking {...customTracker} className={trackingWrapperClassName}>\n {renderAnyTemplates(children, {\n unitId,\n index: -1,\n data: null,\n type: 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>,\n ]);\n}\n\nexport default AdViewUnitClient;\n","import {\n getAssetByName,\n getPrepareURL,\n getSrcSetCSSThumbs,\n} from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<\n AdViewUnitTemplateTypeProps,\n 'type'\n> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({\n className = 'banner',\n style,\n data,\n state,\n ...props\n}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n props?.isInitial || props?.isLoading || props?.isError || props?.isComplete\n ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\n : { isComplete: true };\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n style={{ maxWidth: '100%' }}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewStyleTokensNative, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitNativeTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'native';\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitNativeTemplate({classNames, data, state, ...props}: AdViewUnitNativeTemplateProps) {\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { assets, url, fields } = data;\n const asset = getAssetByName('main', assets);\n\n if (!url) {\n return null;\n }\n\n return (\n <div className={classNames?.container}>\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n className={classNames?.imageLink}\n >\n {asset && (\n <img\n alt={fields?.title}\n title={fields?.title}\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : undefined}\n className={classNames?.image}\n style={{ objectFit: 'cover', width: '100%', height: '100%' }}\n />\n )}\n </a>\n <div className={classNames?.label}>\n {fields?.title && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"titleLink\"\n className={classNames?.titleLink}\n >\n {fields.title}\n </a>\n )}\n {fields?.description && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"descriptionLink\"\n className={classNames?.descriptionLink}\n >\n {fields.description}\n </a>\n )}\n {fields?.brandname && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"brandNameLink\"\n className={classNames?.brandNameLink}\n >\n {fields.brandname}\n </a>\n )}\n {fields?.phone && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"phoneLink\"\n className={classNames?.phoneLink}\n >\n {fields.phone}\n </a>\n )}\n {fields?.url && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"urlLink\"\n className={classNames?.urlLink}\n >\n {fields?.url}\n </a>\n )}\n </div>\n </div>\n );\n}\n\nAdViewUnitNativeTemplate.defaults = {\n type: 'native',\n};\n\nexport default AdViewUnitNativeTemplate;\n","import React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'proxy';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitProxyTemplate({className, style, data, state, ...props}: AdViewUnitProxyTemplateProps) {\n if (!data) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { url, fields } = data;\n const iframeSrc = fields?.url || url;\n\n if (!iframeSrc) {\n return null;\n }\n\n return (\n <iframe\n className={className}\n width=\"100%\"\n height=\"100%\"\n frameBorder=\"0\"\n marginWidth={0}\n marginHeight={0}\n allowTransparency={true}\n scrolling=\"no\"\n allowFullScreen={true}\n style={{ width: '100%', height: '100%', border: 'none', ...style }}\n src={iframeSrc}\n ></iframe>\n );\n}\n\nAdViewUnitProxyTemplate.defaults = {\n type: 'proxy',\n};\n\nexport default AdViewUnitProxyTemplate;\n","//\n// Example\n// <AdView.Unit>\n// <AdView.Template type=\"banner\">\n// <...>\n// </AdView.Template>\n// </AdView.Unit>\n//\n\nimport React, { JSX } from 'react';\nimport {\n AdLoadState,\n AdViewUnitClientChildrenProps,\n AdViewUnitTemplateProps,\n AdViewUnitTemplateTypeProps,\n} 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 = (\n tmpls: TemplateElement[],\n) => 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 = (\n props: AdViewUnitTemplateTypeProps,\n) => React.ReactNode | React.ReactElement;\n\n// templateFromListRender is a function that takes a list of TemplateType and returns a React element\nexport const templateFromListRender = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n wrap?: (children: React.ReactNode) => React.ReactNode,\n): JSX.Element | React.ReactElement => {\n if (!wrap) {\n wrap = (children: React.ReactNode) => children;\n }\n\n let renderedTemplate = null;\n\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, data);\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n\n if (!renderedTemplate) {\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, { ...data, type: 'default' });\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n }\n\n return <>{renderedTemplate}</>;\n};\n\n// renderTemplate is a function that takes a TemplateType or a function and returns a React node\nexport const renderTemplate = (\n tmpl: TemplateElement | TemplateTypeFunction,\n data: AdViewUnitTemplateTypeProps,\n): React.ReactNode => {\n const isFunction = typeof tmpl === 'function';\n const isReactElement = React.isValidElement(tmpl);\n\n if (isReactElement) {\n // Extract type and children from the React element\n let { type, children } = tmpl.props;\n if (!type && typeof tmpl.type !== 'string') {\n type = (tmpl.type as any)?.defaults?.type;\n }\n // If the type does not match, return null\n if (!!type && type !== '*' && data.type !== type) {\n return null;\n }\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(data as AdViewUnitClientChildrenProps);\n }\n // If children is a React element, clone it with the new props\n return React.cloneElement(tmpl as TemplateElement, {\n ...data,\n children: children,\n });\n }\n\n if (isFunction) {\n return tmpl(data);\n }\n\n return null;\n};\n\n// renderTemplates is a function that takes a list of TemplateType and returns a React element\nexport const renderTemplates = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): React.ReactNode | React.ReactElement | JSX.Element => {\n return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);\n};\n\nexport const renderAnyTemplates = (\n tmpls: any,\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): 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 = ({\n type,\n state,\n children,\n ...props\n}: 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 ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\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(\n tmplProps as AdViewUnitClientChildrenProps,\n ) as React.ReactElement;\n }\n\n // If children is a React element, clone it with the new props\n if (React.isValidElement(children)) {\n return React.cloneElement(children, tmplProps);\n }\n\n // If no children are provided, return an empty fragment\n return <></>;\n};\n\nexport default AdViewUnitTemplate;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n className?: string;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n className,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return (\n <div ref={wrapperRef} className={className}>\n {children}\n </div>\n );\n}\n\nexport default AdViewUnitTracking;\n","'use client';\n\nimport { AdViewData, AdViewDataLoader } from '@adview/core/typings';\nimport { getDataLoaderFromConfig, 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 limit: number = 1,\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 dataLoader: AdViewDataLoader = getDataLoaderFromConfig(baseConfig);\n\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n const response = await dataLoader.fetchAdData(unitId, limit || 1, format);\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(() => {\n loadAd();\n }, [unitId, limit, format]);\n\n return [adData, errorMessage, loadState];\n}\n\nexport default useAdViewController;\n","'use client';\n\nimport React, { createContext } from 'react';\nimport { type AdViewConfig } from '../types';\n\ntype AdViewProviderContextProps = AdViewConfig;\n\nexport const AdViewProviderContext = createContext<AdViewProviderContextProps>(\n {} as AdViewProviderContextProps,\n);\n\ntype AdViewProviderProps = {\n children: React.ReactNode;\n} & AdViewProviderContextProps;\n\nconst AdViewProvider = ({ children, ...props }: AdViewProviderProps) => {\n return (\n <AdViewProviderContext.Provider value={props}>\n {children}\n </AdViewProviderContext.Provider>\n );\n};\n\nexport default AdViewProvider;\n","import React from 'react';\n\nimport { AdViewData, AdViewDataLoader } from '@adview/core';\nimport { AdViewGroupItem } from '@adview/core/typings';\nimport { getDataLoaderFromConfig, getResolveConfig } from '@adview/core/utils';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\n\nexport type AdViewUnitServerProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n};\n\nasync function AdViewUnitServer({\n unitId,\n format,\n children,\n limit,\n ...config\n}: AdViewUnitServerProps) {\n const checkFormat = (f: string) => {\n if (!format) {\n return true;\n }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\n const baseConfig = getResolveConfig(config);\n const dataLoader: AdViewDataLoader = getDataLoaderFromConfig(baseConfig);\n const response = await dataLoader.fetchAdData(unitId, limit || 1, format);\n const isLoadingError = response instanceof Error;\n const error = isLoadingError ? response : undefined;\n const state = {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n };\n\n const {\n responseGroup: _,\n customTracker,\n groupItems,\n } = error\n ? { responseGroup: null, customTracker: {}, groupItems: [] }\n : (() => {\n for (let responseGroup of (response as AdViewData)?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || [])\n .map(it => (checkFormat(it.type) ? it : null))\n .filter(Boolean) as AdViewGroupItem[];\n if (groupItems && groupItems.length > 0) {\n return { responseGroup, customTracker, groupItems };\n }\n }\n return { responseGroup: null, customTracker: {}, groupItems: [] };\n })();\n\n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />,\n ];\n }\n\n if (groupItems && groupItems.length) {\n return groupItems.map(\n ({ tracker, ...data }: AdViewGroupItem, index: number) => {\n return (\n <AdViewUnitTracking key={data.id} {...tracker}>\n {renderAnyTemplates(children, {\n unitId,\n index,\n data,\n type: data.type || 'default',\n error,\n state: state,\n })}\n </AdViewUnitTracking>\n );\n },\n );\n }\n\n return (\n <AdViewUnitTracking {...customTracker}>\n {renderAnyTemplates(children, {\n unitId,\n index: -1,\n data: null,\n type: 'default',\n error,\n state: state,\n })}\n </AdViewUnitTracking>\n );\n}\n\nexport default AdViewUnitServer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAkB;;;ACGlB,IAAAC,gBAAkB;;;ACHlB,mBAIO;AACP,mBAAkB;;;ACHX,IAAM,qBAAqB,CAAC,aAA2B,UAAwB;AACpF,SAAO,CAAC,gBACL,YAAY,cAAc,UAAa,YAAY,cAAc,OAAO,eACxE,YAAY,cAAc,UA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pD;AAAA,IACF;AACA,WAAO,EAAE,eAAe,MAAM,eAAe,CAAC,GAAG,YAAY,CAAC,EAAE;AAAA,EAClE,GAAG;AAEP,MAAI,CAAC,UAAU;AACb,eAAW;AAAA,MACT,8BAAAC,QAAA,cAAC,sCAAyB;AAAA,MAC1B,8BAAAA,QAAA,cAAC,sCAAyB;AAAA,MAC1B,8BAAAA,QAAA,cAAC,qCAAwB;AAAA,IAC3B;AAAA,EACF;AAEA,MAAI,cAAc,WAAW,QAAQ;AACnC,WAAO,WAAW;AAAA,MAChB,CAAC,EAAE,SAAS,GAAG,KAAK,GAAoB,UAAkB;AACxD,eACE,8BAAAA,QAAA,cAAC,8BAAmB,KAAK,KAAK,IAAK,GAAG,WACnC,mBAAmB,UAAU;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA,MAAM,KAAK,QAAQ;AAAA,UACnB;AAAA,UACA;AAAA,QACF,CAAC,CACH;AAAA,MAEJ;AAAA,IACF;AAAA,EACF;AAEA,SACE,8BAAAA,QAAA,cAAC,8BAAoB,GAAG,iBACrB,mBAAmB,UAAU;AAAA,IAC5B;AAAA,IACA,OAAO;AAAA,IACP,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF,CAAC,CACH;AAEJ;AAEA,IAAO,4BAAQ;;;AV9Ff,SAAS,WAAW,OAAwB;AAC1C,QAAM,WAAW,OAAO,WAAW;AAEnC,MAAI,UAAU;AACZ,WAAO,+BAAAC,QAAA,cAAC,6BAAkB,GAAI,OAAiC;AAAA,EACjE;AAEA,SAAO,+BAAAA,QAAA,cAAC,6BAAkB,GAAI,OAAiC;AACjE;AAEA,IAAO,qBAAQ;","names":["import_react","import_react","React","import_utils","import_react","React","import_react","React","import_react","React","import_utils","import_react","React","import_utils","import_react","import_react","customTracker","groupItems","React","import_react","import_utils","customTracker","groupItems","React","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.tsx","../../src/AdViewUnit/AdViewUnit.client.tsx","../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts","../../src/AdViewUnit/AdViewUnitNativeTemplate.tsx","../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx","../../src/AdViewUnit/AdViewUnit.server.tsx"],"sourcesContent":["import React from 'react';\nimport AdViewUnitClient, { AdViewUnitClientProps } from './AdViewUnit.client';\nimport AdViewUnitServer, { AdViewUnitServerProps } from './AdViewUnit.server';\n\nexport type AdViewUnitProps = typeof window extends undefined\n ? AdViewUnitServerProps\n : AdViewUnitClientProps;\n\nfunction AdViewUnit(props: AdViewUnitProps) {\n const isServer = typeof window === 'undefined';\n\n if (isServer) {\n return <AdViewUnitServer {...(props as AdViewUnitServerProps)} />;\n }\n\n return <AdViewUnitClient {...(props as AdViewUnitClientProps)} />;\n}\n\nexport default AdViewUnit;\n","'use client';\n\nimport { AdViewGroupItem } from '@adview/core';\nimport React from 'react';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport useAdViewController from './useAdViewController';\n\nexport type AdViewUnitClientProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n wrapper?: (elms: React.ReactNode[]) => React.ReactNode;\n trackingWrapperClassName?: string;\n sources?: string[];\n};\n\n// AdViewUnitClient is a client-side component that fetches ad data and renders it\n// using the provided children function. It handles loading, error states, and\n// tracks ad interactions.\n//\n// Example usage:\n// <AdView.Unit unitId=\"my-unit\" format=\"banner\" srcURL=\"https://api.example.com/ads/{<id>}\">\n// {({ data, state, error }) => (\n// <div>\n// {state.isLoading && <span>Loading...</span>}\n// {error && <span>Error: {error.message}</span>}\n// {data && <img src={data.imageUrl} alt={data.title} />\n// </div>\n// )}\n// </AdView.Unit>\n//\n// Note: This component is designed to be used in a client-side environment where\n// ad data can be fetched dynamically. It is not suitable for server-side rendering.\n// It uses the AdViewUnitTracking component to handle ad tracking and interactions.\nfunction AdViewUnitClient({\n unitId,\n limit = 1,\n format,\n query,\n children,\n wrapper,\n trackingWrapperClassName,\n sources,\n ...config\n}: AdViewUnitClientProps) {\n const checkFormat = (f: string) => {\n if (!format) {\n return true;\n }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\n const [response, error, loadState] = useAdViewController(\n config,\n unitId,\n limit || 1,\n format,\n query,\n sources,\n );\n\n const {\n responseGroup: _,\n customTracker,\n groupItems,\n } = error\n ? { responseGroup: null, customTracker: {}, groupItems: [] }\n : (() => {\n for (let responseGroup of response?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || [])\n .map(it => (checkFormat(it.type) ? it : null))\n .filter(Boolean);\n if (groupItems && groupItems.length > 0) {\n return { responseGroup, customTracker, groupItems };\n }\n }\n return { responseGroup: null, customTracker: {}, groupItems: [] };\n })();\n\n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />,\n ];\n }\n\n if (!wrapper) {\n wrapper = (elms: React.ReactNode[]) => <>{elms}</>;\n }\n\n if (groupItems && groupItems?.length > 0) {\n return wrapper(\n (groupItems as AdViewGroupItem[]).map(({ tracker, ...data }, index) => {\n return (\n <AdViewUnitTracking\n key={data.id}\n {...tracker}\n className={trackingWrapperClassName}\n >\n {renderAnyTemplates(children, {\n unitId,\n index,\n data,\n type: data.type || 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>\n );\n }),\n );\n }\n\n return wrapper([\n <AdViewUnitTracking {...customTracker} className={trackingWrapperClassName}>\n {renderAnyTemplates(children, {\n unitId,\n index: -1,\n data: null,\n type: 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>,\n ]);\n}\n\nexport default AdViewUnitClient;\n","import {\n getAssetByName,\n getPrepareURL,\n getSrcSetCSSThumbs,\n} from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<\n AdViewUnitTemplateTypeProps,\n 'type'\n> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({\n className = 'banner',\n style,\n data,\n state,\n ...props\n}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n props?.isInitial || props?.isLoading || props?.isError || props?.isComplete\n ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\n : { isComplete: true };\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n style={{ maxWidth: '100%' }}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewStyleTokensNative, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitNativeTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'native';\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitNativeTemplate({classNames, data, state, ...props}: AdViewUnitNativeTemplateProps) {\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { assets, url, fields } = data;\n const asset = getAssetByName('main', assets);\n\n if (!url) {\n return null;\n }\n\n return (\n <div className={classNames?.container}>\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n className={classNames?.imageLink}\n >\n {asset && (\n <img\n alt={fields?.title}\n title={fields?.title}\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : undefined}\n className={classNames?.image}\n style={{ objectFit: 'cover', width: '100%', height: '100%' }}\n />\n )}\n </a>\n <div className={classNames?.label}>\n {fields?.title && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"titleLink\"\n className={classNames?.titleLink}\n >\n {fields.title}\n </a>\n )}\n {fields?.description && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"descriptionLink\"\n className={classNames?.descriptionLink}\n >\n {fields.description}\n </a>\n )}\n {fields?.brandname && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"brandNameLink\"\n className={classNames?.brandNameLink}\n >\n {fields.brandname}\n </a>\n )}\n {fields?.phone && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"phoneLink\"\n className={classNames?.phoneLink}\n >\n {fields.phone}\n </a>\n )}\n {fields?.url && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"urlLink\"\n className={classNames?.urlLink}\n >\n {fields?.url}\n </a>\n )}\n </div>\n </div>\n );\n}\n\nAdViewUnitNativeTemplate.defaults = {\n type: 'native',\n};\n\nexport default AdViewUnitNativeTemplate;\n","import React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'proxy';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitProxyTemplate({className, style, data, state, ...props}: AdViewUnitProxyTemplateProps) {\n if (!data) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { url, fields } = data;\n const iframeSrc = fields?.url || url;\n\n if (!iframeSrc) {\n return null;\n }\n\n return (\n <iframe\n className={className}\n width=\"100%\"\n height=\"100%\"\n frameBorder=\"0\"\n marginWidth={0}\n marginHeight={0}\n allowTransparency={true}\n scrolling=\"no\"\n allowFullScreen={true}\n style={{ width: '100%', height: '100%', border: 'none', ...style }}\n src={iframeSrc}\n ></iframe>\n );\n}\n\nAdViewUnitProxyTemplate.defaults = {\n type: 'proxy',\n};\n\nexport default AdViewUnitProxyTemplate;\n","//\n// Example\n// <AdView.Unit>\n// <AdView.Template type=\"banner\">\n// <...>\n// </AdView.Template>\n// </AdView.Unit>\n//\n\nimport React, { JSX } from 'react';\nimport {\n AdLoadState,\n AdViewUnitClientChildrenProps,\n AdViewUnitTemplateProps,\n AdViewUnitTemplateTypeProps,\n} 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 = (\n tmpls: TemplateElement[],\n) => 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 = (\n props: AdViewUnitTemplateTypeProps,\n) => React.ReactNode | React.ReactElement;\n\n// templateFromListRender is a function that takes a list of TemplateType and returns a React element\nexport const templateFromListRender = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n wrap?: (children: React.ReactNode) => React.ReactNode,\n): JSX.Element | React.ReactElement => {\n if (!wrap) {\n wrap = (children: React.ReactNode) => children;\n }\n\n let renderedTemplate = null;\n\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, data);\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n\n if (!renderedTemplate) {\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, { ...data, type: 'default' });\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n }\n\n return <>{renderedTemplate}</>;\n};\n\n// renderTemplate is a function that takes a TemplateType or a function and returns a React node\nexport const renderTemplate = (\n tmpl: TemplateElement | TemplateTypeFunction,\n data: AdViewUnitTemplateTypeProps,\n): React.ReactNode => {\n const isFunction = typeof tmpl === 'function';\n const isReactElement = React.isValidElement(tmpl);\n\n if (isReactElement) {\n // Extract type and children from the React element\n let { type, children } = tmpl.props;\n if (!type && typeof tmpl.type !== 'string') {\n type = (tmpl.type as any)?.defaults?.type;\n }\n // If the type does not match, return null\n if (!!type && type !== '*' && data.type !== type) {\n return null;\n }\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(data as AdViewUnitClientChildrenProps);\n }\n // If children is a React element, clone it with the new props\n return React.cloneElement(tmpl as TemplateElement, {\n ...data,\n children: children,\n });\n }\n\n if (isFunction) {\n return tmpl(data);\n }\n\n return null;\n};\n\n// renderTemplates is a function that takes a list of TemplateType and returns a React element\nexport const renderTemplates = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): React.ReactNode | React.ReactElement | JSX.Element => {\n return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);\n};\n\nexport const renderAnyTemplates = (\n tmpls: any,\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): 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 = ({\n type,\n state,\n children,\n ...props\n}: 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 ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\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(\n tmplProps as AdViewUnitClientChildrenProps,\n ) as React.ReactElement;\n }\n\n // If children is a React element, clone it with the new props\n if (React.isValidElement(children)) {\n return React.cloneElement(children, tmplProps);\n }\n\n // If no children are provided, return an empty fragment\n return <></>;\n};\n\nexport default AdViewUnitTemplate;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n className?: string;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n className,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return (\n <div ref={wrapperRef} className={className}>\n {children}\n </div>\n );\n}\n\nexport default AdViewUnitTracking;\n","'use client';\n\nimport { AdViewData, AdViewDataLoader } from '@adview/core/typings';\nimport { getDataLoaderFromConfig, 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 limit: number = 1,\n format?: string | string[],\n query?: { [key: string]: any },\n sources?: 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 dataLoader: AdViewDataLoader = getDataLoaderFromConfig(\n baseConfig,\n sources,\n );\n\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n const response = await dataLoader.fetchAdData(\n unitId,\n limit || 1,\n format,\n query,\n );\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(() => {\n loadAd();\n }, [unitId, limit, format]);\n\n return [adData, errorMessage, loadState];\n}\n\nexport default useAdViewController;\n","'use client';\n\nimport React, { createContext } from 'react';\nimport { type AdViewConfig } from '../types';\n\ntype AdViewProviderContextProps = AdViewConfig;\n\nexport const AdViewProviderContext = createContext<AdViewProviderContextProps>(\n {} as AdViewProviderContextProps,\n);\n\ntype AdViewProviderProps = {\n children: React.ReactNode;\n} & AdViewProviderContextProps;\n\nconst AdViewProvider = ({ children, ...props }: AdViewProviderProps) => {\n return (\n <AdViewProviderContext.Provider value={props}>\n {children}\n </AdViewProviderContext.Provider>\n );\n};\n\nexport default AdViewProvider;\n","import React from 'react';\n\nimport { AdViewData, AdViewDataLoader } from '@adview/core';\nimport { AdViewGroupItem } from '@adview/core/typings';\nimport { getDataLoaderFromConfig, getResolveConfig } from '@adview/core/utils';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\n\nexport type AdViewUnitServerProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n wrapper?: (elms: React.ReactNode[]) => React.ReactNode;\n trackingWrapperClassName?: string;\n sources?: string[];\n};\n\nasync function AdViewUnitServer({\n unitId,\n format,\n children,\n limit,\n query,\n wrapper,\n trackingWrapperClassName,\n sources,\n ...config\n}: AdViewUnitServerProps) {\n const checkFormat = (f: string) => {\n if (!format) {\n return true;\n }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\n const baseConfig = getResolveConfig(config);\n const dataLoader: AdViewDataLoader = getDataLoaderFromConfig(\n baseConfig,\n sources,\n );\n const response = await dataLoader.fetchAdData(\n unitId,\n limit || 1,\n format,\n query,\n );\n const isLoadingError = response instanceof Error;\n const error = isLoadingError ? response : undefined;\n const state = {\n isLoading: true,\n isComplete: true,\n isInitial: false,\n isError: isLoadingError,\n };\n\n const {\n responseGroup: _,\n customTracker,\n groupItems,\n } = error\n ? { responseGroup: null, customTracker: {}, groupItems: [] }\n : (() => {\n for (let responseGroup of (response as AdViewData)?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || [])\n .map(it => (checkFormat(it.type) ? it : null))\n .filter(Boolean) as AdViewGroupItem[];\n if (groupItems && groupItems.length > 0) {\n return { responseGroup, customTracker, groupItems };\n }\n }\n return { responseGroup: null, customTracker: {}, groupItems: [] };\n })();\n\n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />,\n ];\n }\n\n if (!wrapper) {\n wrapper = (elms: React.ReactNode[]) => <>{elms}</>;\n }\n\n if (groupItems && groupItems.length) {\n return wrapper(\n groupItems.map(({ tracker, ...data }: AdViewGroupItem, index: number) => {\n return (\n <AdViewUnitTracking\n key={data.id}\n {...tracker}\n className={trackingWrapperClassName}\n >\n {renderAnyTemplates(children, {\n unitId,\n index,\n data,\n type: data.type || 'default',\n error,\n state: state,\n })}\n </AdViewUnitTracking>\n );\n }),\n );\n }\n\n return wrapper([\n <AdViewUnitTracking {...customTracker} className={trackingWrapperClassName}>\n {renderAnyTemplates(children, {\n unitId,\n index: -1,\n data: null,\n type: 'default',\n error,\n state: state,\n })}\n </AdViewUnitTracking>,\n ]);\n}\n\nexport default AdViewUnitServer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAkB;;;ACGlB,IAAAC,gBAAkB;;;ACHlB,mBAIO;AACP,mBAAkB;;;ACHX,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;;;ADSA,SAAS,yBAAyB;AAAA,EAChC,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EAC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jE;AAEA,IAAO,qBAAQ;","names":["import_react","import_react","React","import_utils","import_react","React","import_react","React","import_react","React","import_utils","import_react","React","import_utils","import_react","import_react","customTracker","groupItems","React","import_react","import_utils","customTracker","groupItems","React","React"]}
|
|
@@ -367,17 +367,25 @@ var AdViewProviderContext = (0, import_react6.createContext)(
|
|
|
367
367
|
);
|
|
368
368
|
|
|
369
369
|
// src/AdViewUnit/useAdViewController.ts
|
|
370
|
-
function useAdViewController(adUnitConfig, unitId, limit = 1, format) {
|
|
370
|
+
function useAdViewController(adUnitConfig, unitId, limit = 1, format, query, sources) {
|
|
371
371
|
const [adLoadState, setAdLoadState] = (0, import_react7.useState)("initial");
|
|
372
372
|
const [adData, setAdData] = (0, import_react7.useState)(null);
|
|
373
373
|
const [errorMessage, setErrorMessage] = (0, import_react7.useState)(null);
|
|
374
374
|
const globalConfig = (0, import_react7.useContext)(AdViewProviderContext);
|
|
375
375
|
const baseConfig = (0, import_utils8.getResolveConfig)({ ...adUnitConfig, ...globalConfig });
|
|
376
|
-
const dataLoader = (0, import_utils8.getDataLoaderFromConfig)(
|
|
376
|
+
const dataLoader = (0, import_utils8.getDataLoaderFromConfig)(
|
|
377
|
+
baseConfig,
|
|
378
|
+
sources
|
|
379
|
+
);
|
|
377
380
|
const loadAd = async () => {
|
|
378
381
|
setAdLoadState("loading");
|
|
379
382
|
try {
|
|
380
|
-
const response = await dataLoader.fetchAdData(
|
|
383
|
+
const response = await dataLoader.fetchAdData(
|
|
384
|
+
unitId,
|
|
385
|
+
limit || 1,
|
|
386
|
+
format,
|
|
387
|
+
query
|
|
388
|
+
);
|
|
381
389
|
if (response instanceof Error) {
|
|
382
390
|
setAdLoadState("error");
|
|
383
391
|
setErrorMessage(response);
|
|
@@ -409,9 +417,11 @@ function AdViewUnitClient({
|
|
|
409
417
|
unitId,
|
|
410
418
|
limit = 1,
|
|
411
419
|
format,
|
|
420
|
+
query,
|
|
412
421
|
children,
|
|
413
422
|
wrapper,
|
|
414
423
|
trackingWrapperClassName,
|
|
424
|
+
sources,
|
|
415
425
|
...config
|
|
416
426
|
}) {
|
|
417
427
|
const checkFormat = (f) => {
|
|
@@ -424,7 +434,9 @@ function AdViewUnitClient({
|
|
|
424
434
|
config,
|
|
425
435
|
unitId,
|
|
426
436
|
limit || 1,
|
|
427
|
-
format
|
|
437
|
+
format,
|
|
438
|
+
query,
|
|
439
|
+
sources
|
|
428
440
|
);
|
|
429
441
|
const {
|
|
430
442
|
responseGroup: _,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.client.tsx","../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts","../../src/AdViewUnit/AdViewUnitNativeTemplate.tsx","../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx"],"sourcesContent":["'use client';\n\nimport { AdViewGroupItem } from '@adview/core';\nimport React from 'react';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport useAdViewController from './useAdViewController';\n\nexport type AdViewUnitClientProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n wrapper?: (elms: React.ReactNode[]) => React.ReactNode;\n trackingWrapperClassName?: string;\n};\n\n// AdViewUnitClient is a client-side component that fetches ad data and renders it\n// using the provided children function. It handles loading, error states, and\n// tracks ad interactions.\n//\n// Example usage:\n// <AdView.Unit unitId=\"my-unit\" format=\"banner\" srcURL=\"https://api.example.com/ads/{<id>}\">\n// {({ data, state, error }) => (\n// <div>\n// {state.isLoading && <span>Loading...</span>}\n// {error && <span>Error: {error.message}</span>}\n// {data && <img src={data.imageUrl} alt={data.title} />\n// </div>\n// )}\n// </AdView.Unit>\n//\n// Note: This component is designed to be used in a client-side environment where\n// ad data can be fetched dynamically. It is not suitable for server-side rendering.\n// It uses the AdViewUnitTracking component to handle ad tracking and interactions.\nfunction AdViewUnitClient({\n unitId,\n limit = 1,\n format,\n children,\n wrapper,\n trackingWrapperClassName,\n ...config\n}: AdViewUnitClientProps) {\n const checkFormat = (f: string) => {\n if (!format) {\n return true;\n }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\n const [response, error, loadState] = useAdViewController(\n config,\n unitId,\n limit || 1,\n format,\n );\n\n const {\n responseGroup: _,\n customTracker,\n groupItems,\n } = error\n ? { responseGroup: null, customTracker: {}, groupItems: [] }\n : (() => {\n for (let responseGroup of response?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || [])\n .map(it => (checkFormat(it.type) ? it : null))\n .filter(Boolean);\n if (groupItems && groupItems.length > 0) {\n return { responseGroup, customTracker, groupItems };\n }\n }\n return { responseGroup: null, customTracker: {}, groupItems: [] };\n })();\n\n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />,\n ];\n }\n\n if (!wrapper) {\n wrapper = (elms: React.ReactNode[]) => <>{elms}</>;\n }\n\n if (groupItems && groupItems?.length > 0) {\n return wrapper(\n (groupItems as AdViewGroupItem[]).map(({ tracker, ...data }, index) => {\n return (\n <AdViewUnitTracking\n key={data.id}\n {...tracker}\n className={trackingWrapperClassName}\n >\n {renderAnyTemplates(children, {\n unitId,\n index,\n data,\n type: data.type || 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>\n );\n }),\n );\n }\n\n return wrapper([\n <AdViewUnitTracking {...customTracker} className={trackingWrapperClassName}>\n {renderAnyTemplates(children, {\n unitId,\n index: -1,\n data: null,\n type: 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>,\n ]);\n}\n\nexport default AdViewUnitClient;\n","import {\n getAssetByName,\n getPrepareURL,\n getSrcSetCSSThumbs,\n} from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<\n AdViewUnitTemplateTypeProps,\n 'type'\n> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({\n className = 'banner',\n style,\n data,\n state,\n ...props\n}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n props?.isInitial || props?.isLoading || props?.isError || props?.isComplete\n ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\n : { isComplete: true };\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n style={{ maxWidth: '100%' }}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewStyleTokensNative, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitNativeTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'native';\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitNativeTemplate({classNames, data, state, ...props}: AdViewUnitNativeTemplateProps) {\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { assets, url, fields } = data;\n const asset = getAssetByName('main', assets);\n\n if (!url) {\n return null;\n }\n\n return (\n <div className={classNames?.container}>\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n className={classNames?.imageLink}\n >\n {asset && (\n <img\n alt={fields?.title}\n title={fields?.title}\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : undefined}\n className={classNames?.image}\n style={{ objectFit: 'cover', width: '100%', height: '100%' }}\n />\n )}\n </a>\n <div className={classNames?.label}>\n {fields?.title && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"titleLink\"\n className={classNames?.titleLink}\n >\n {fields.title}\n </a>\n )}\n {fields?.description && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"descriptionLink\"\n className={classNames?.descriptionLink}\n >\n {fields.description}\n </a>\n )}\n {fields?.brandname && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"brandNameLink\"\n className={classNames?.brandNameLink}\n >\n {fields.brandname}\n </a>\n )}\n {fields?.phone && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"phoneLink\"\n className={classNames?.phoneLink}\n >\n {fields.phone}\n </a>\n )}\n {fields?.url && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"urlLink\"\n className={classNames?.urlLink}\n >\n {fields?.url}\n </a>\n )}\n </div>\n </div>\n );\n}\n\nAdViewUnitNativeTemplate.defaults = {\n type: 'native',\n};\n\nexport default AdViewUnitNativeTemplate;\n","import React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'proxy';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitProxyTemplate({className, style, data, state, ...props}: AdViewUnitProxyTemplateProps) {\n if (!data) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { url, fields } = data;\n const iframeSrc = fields?.url || url;\n\n if (!iframeSrc) {\n return null;\n }\n\n return (\n <iframe\n className={className}\n width=\"100%\"\n height=\"100%\"\n frameBorder=\"0\"\n marginWidth={0}\n marginHeight={0}\n allowTransparency={true}\n scrolling=\"no\"\n allowFullScreen={true}\n style={{ width: '100%', height: '100%', border: 'none', ...style }}\n src={iframeSrc}\n ></iframe>\n );\n}\n\nAdViewUnitProxyTemplate.defaults = {\n type: 'proxy',\n};\n\nexport default AdViewUnitProxyTemplate;\n","//\n// Example\n// <AdView.Unit>\n// <AdView.Template type=\"banner\">\n// <...>\n// </AdView.Template>\n// </AdView.Unit>\n//\n\nimport React, { JSX } from 'react';\nimport {\n AdLoadState,\n AdViewUnitClientChildrenProps,\n AdViewUnitTemplateProps,\n AdViewUnitTemplateTypeProps,\n} 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 = (\n tmpls: TemplateElement[],\n) => 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 = (\n props: AdViewUnitTemplateTypeProps,\n) => React.ReactNode | React.ReactElement;\n\n// templateFromListRender is a function that takes a list of TemplateType and returns a React element\nexport const templateFromListRender = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n wrap?: (children: React.ReactNode) => React.ReactNode,\n): JSX.Element | React.ReactElement => {\n if (!wrap) {\n wrap = (children: React.ReactNode) => children;\n }\n\n let renderedTemplate = null;\n\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, data);\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n\n if (!renderedTemplate) {\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, { ...data, type: 'default' });\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n }\n\n return <>{renderedTemplate}</>;\n};\n\n// renderTemplate is a function that takes a TemplateType or a function and returns a React node\nexport const renderTemplate = (\n tmpl: TemplateElement | TemplateTypeFunction,\n data: AdViewUnitTemplateTypeProps,\n): React.ReactNode => {\n const isFunction = typeof tmpl === 'function';\n const isReactElement = React.isValidElement(tmpl);\n\n if (isReactElement) {\n // Extract type and children from the React element\n let { type, children } = tmpl.props;\n if (!type && typeof tmpl.type !== 'string') {\n type = (tmpl.type as any)?.defaults?.type;\n }\n // If the type does not match, return null\n if (!!type && type !== '*' && data.type !== type) {\n return null;\n }\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(data as AdViewUnitClientChildrenProps);\n }\n // If children is a React element, clone it with the new props\n return React.cloneElement(tmpl as TemplateElement, {\n ...data,\n children: children,\n });\n }\n\n if (isFunction) {\n return tmpl(data);\n }\n\n return null;\n};\n\n// renderTemplates is a function that takes a list of TemplateType and returns a React element\nexport const renderTemplates = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): React.ReactNode | React.ReactElement | JSX.Element => {\n return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);\n};\n\nexport const renderAnyTemplates = (\n tmpls: any,\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): 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 = ({\n type,\n state,\n children,\n ...props\n}: 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 ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\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(\n tmplProps as AdViewUnitClientChildrenProps,\n ) as React.ReactElement;\n }\n\n // If children is a React element, clone it with the new props\n if (React.isValidElement(children)) {\n return React.cloneElement(children, tmplProps);\n }\n\n // If no children are provided, return an empty fragment\n return <></>;\n};\n\nexport default AdViewUnitTemplate;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n className?: string;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n className,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return (\n <div ref={wrapperRef} className={className}>\n {children}\n </div>\n );\n}\n\nexport default AdViewUnitTracking;\n","'use client';\n\nimport { AdViewData, AdViewDataLoader } from '@adview/core/typings';\nimport { getDataLoaderFromConfig, 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 limit: number = 1,\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 dataLoader: AdViewDataLoader = getDataLoaderFromConfig(baseConfig);\n\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n const response = await dataLoader.fetchAdData(unitId, limit || 1, format);\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(() => {\n loadAd();\n }, [unitId, limit, format]);\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,IAAAA,gBAAkB;;;ACHlB,mBAIO;AACP,mBAAkB;;;ACHX,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;;;ADSA,SAAS,yBAAyB;AAAA,EAChC,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAkC;AAChC,QAAM,cACJ,OAAO,aAAa,OAAO,aAAa,OAAO,WAAW,OAAO,aAC7D;AAAA,IACE,WAAW,OAAO;AAAA,IAClB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,YAAY,OAAO;AAAA,EACrB,IACA,EAAE,YAAY,KAAK;AAEzB,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,QAAQ;AAChD,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,mBAAmB,aAAa,KAAK,GAAG;AAC3C,WAAO;AAAA,EACT;AAEA,QAAM,YAAQ,6BAAe,QAAQ,KAAK,MAAM;AAEhD,SACE,6BAAAC,QAAA;AAAA,IAAC;AAAA;AAAA,MACC,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,UAAM,4BAAc,KAAK,GAAG;AAAA,MAC5B;AAAA,MACA,OAAO,EAAE,UAAU,GAAG,GAAG,MAAM;AAAA;AAAA,IAE9B,SACC,6BAAAA,QAAA;AAAA,MAAC;AAAA;AAAA,QACC,KAAI;AAAA,QACJ,KAAK,MAA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AAAA,QAAA;AAAA,UAAC;AAAA;AAAA,YACC,KAAK,KAAK;AAAA,YACT,GAAG;AAAA,YACJ,WAAW;AAAA;AAAA,UAEV,mBAAmB,UAAU;AAAA,YAC5B;AAAA,YACA;AAAA,YACA;AAAA,YACA,MAAM,KAAK,QAAQ;AAAA,YACnB;AAAA,YACA,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MAEJ,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,QAAQ;AAAA,IACb,8BAAAA,QAAA,cAAC,8BAAoB,GAAG,eAAe,WAAW,4BAC/C,mBAAmB,UAAU;AAAA,MAC5B;AAAA,MACA,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,IACT,CAAC,CACH;AAAA,EACF,CAAC;AACH;AAEA,IAAO,4BAAQ;","names":["import_react","React","import_utils","import_react","React","import_react","React","import_react","React","import_utils","import_react","React","import_utils","import_react","import_react","customTracker","groupItems","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/AdViewUnit/AdViewUnit.client.tsx","../../src/AdViewUnit/AdViewUnitBannerTemplate.tsx","../../src/AdViewUnit/utils.ts","../../src/AdViewUnit/AdViewUnitNativeTemplate.tsx","../../src/AdViewUnit/AdViewUnitProxyTemplate.tsx","../../src/AdViewUnit/AdViewUnitTemplate.tsx","../../src/AdViewUnit/AdViewUnitTracking.tsx","../../src/AdViewUnit/useAdViewController.ts","../../src/AdViewUnit/AdViewProvider.tsx"],"sourcesContent":["'use client';\n\nimport { AdViewGroupItem } from '@adview/core';\nimport React from 'react';\nimport { AdViewUnitClientChildren, AdViewUnitPropsBase } from '../types';\nimport AdViewUnitBannerTemplate from './AdViewUnitBannerTemplate';\nimport AdViewUnitNativeTemplate from './AdViewUnitNativeTemplate';\nimport AdViewUnitProxyTemplate from './AdViewUnitProxyTemplate';\nimport { renderAnyTemplates } from './AdViewUnitTemplate';\nimport AdViewUnitTracking from './AdViewUnitTracking';\nimport useAdViewController from './useAdViewController';\n\nexport type AdViewUnitClientProps = AdViewUnitPropsBase & {\n children?: AdViewUnitClientChildren;\n wrapper?: (elms: React.ReactNode[]) => React.ReactNode;\n trackingWrapperClassName?: string;\n sources?: string[];\n};\n\n// AdViewUnitClient is a client-side component that fetches ad data and renders it\n// using the provided children function. It handles loading, error states, and\n// tracks ad interactions.\n//\n// Example usage:\n// <AdView.Unit unitId=\"my-unit\" format=\"banner\" srcURL=\"https://api.example.com/ads/{<id>}\">\n// {({ data, state, error }) => (\n// <div>\n// {state.isLoading && <span>Loading...</span>}\n// {error && <span>Error: {error.message}</span>}\n// {data && <img src={data.imageUrl} alt={data.title} />\n// </div>\n// )}\n// </AdView.Unit>\n//\n// Note: This component is designed to be used in a client-side environment where\n// ad data can be fetched dynamically. It is not suitable for server-side rendering.\n// It uses the AdViewUnitTracking component to handle ad tracking and interactions.\nfunction AdViewUnitClient({\n unitId,\n limit = 1,\n format,\n query,\n children,\n wrapper,\n trackingWrapperClassName,\n sources,\n ...config\n}: AdViewUnitClientProps) {\n const checkFormat = (f: string) => {\n if (!format) {\n return true;\n }\n return Array.isArray(format) ? format.includes(f) : f === format;\n };\n\n const [response, error, loadState] = useAdViewController(\n config,\n unitId,\n limit || 1,\n format,\n query,\n sources,\n );\n\n const {\n responseGroup: _,\n customTracker,\n groupItems,\n } = error\n ? { responseGroup: null, customTracker: {}, groupItems: [] }\n : (() => {\n for (let responseGroup of response?.groups || []) {\n const customTracker = responseGroup?.custom_tracker ?? {};\n const groupItems = (responseGroup?.items || [])\n .map(it => (checkFormat(it.type) ? it : null))\n .filter(Boolean);\n if (groupItems && groupItems.length > 0) {\n return { responseGroup, customTracker, groupItems };\n }\n }\n return { responseGroup: null, customTracker: {}, groupItems: [] };\n })();\n\n if (!children) {\n children = [\n <AdViewUnitBannerTemplate />,\n <AdViewUnitNativeTemplate />,\n <AdViewUnitProxyTemplate />,\n ];\n }\n\n if (!wrapper) {\n wrapper = (elms: React.ReactNode[]) => <>{elms}</>;\n }\n\n if (groupItems && groupItems?.length > 0) {\n return wrapper(\n (groupItems as AdViewGroupItem[]).map(({ tracker, ...data }, index) => {\n return (\n <AdViewUnitTracking\n key={data.id}\n {...tracker}\n className={trackingWrapperClassName}\n >\n {renderAnyTemplates(children, {\n unitId,\n index,\n data,\n type: data.type || 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>\n );\n }),\n );\n }\n\n return wrapper([\n <AdViewUnitTracking {...customTracker} className={trackingWrapperClassName}>\n {renderAnyTemplates(children, {\n unitId,\n index: -1,\n data: null,\n type: 'default',\n error,\n state: loadState,\n })}\n </AdViewUnitTracking>,\n ]);\n}\n\nexport default AdViewUnitClient;\n","import {\n getAssetByName,\n getPrepareURL,\n getSrcSetCSSThumbs,\n} from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitBannerTemplateProps = Omit<\n AdViewUnitTemplateTypeProps,\n 'type'\n> & {\n type?: 'banner';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitBannerTemplate({\n className = 'banner',\n style,\n data,\n state,\n ...props\n}: AdViewUnitBannerTemplateProps) {\n const expectState: AdLoadState =\n props?.isInitial || props?.isLoading || props?.isError || props?.isComplete\n ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\n : { isComplete: true };\n\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const asset = getAssetByName('main', data.assets);\n\n return (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(data.url)}\n className={className}\n style={{ fontSize: 0, ...style }}\n >\n {asset && (\n <img\n alt=\"main\"\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : ''}\n style={{ maxWidth: '100%' }}\n />\n )}\n </a>\n );\n}\n\nAdViewUnitBannerTemplate.defaults = {\n type: 'banner',\n};\n\nexport default AdViewUnitBannerTemplate;\n","import { AdLoadState } from \"../types\";\n\nexport const matchExpectedState = (expectState?: AdLoadState, state?: AdLoadState) => {\n return !expectState || (\n (expectState.isInitial === undefined || expectState.isInitial === state?.isInitial) &&\n (expectState.isLoading === undefined || expectState.isLoading === state?.isLoading) &&\n (expectState.isError === undefined || expectState.isError === state?.isError) &&\n (expectState.isComplete === undefined || expectState.isComplete === state?.isComplete)\n );\n};\n","import { getAssetByName, getPrepareURL, getSrcSetCSSThumbs } from '@adview/core/utils';\nimport React from 'react';\nimport { AdLoadState, AdViewStyleTokensNative, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitNativeTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'native';\n classNames?: AdViewStyleTokensNative;\n};\n\nfunction AdViewUnitNativeTemplate({classNames, data, state, ...props}: AdViewUnitNativeTemplateProps) {\n if (!data || !data.assets || !data.assets.length) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { assets, url, fields } = data;\n const asset = getAssetByName('main', assets);\n\n if (!url) {\n return null;\n }\n\n return (\n <div className={classNames?.container}>\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n className={classNames?.imageLink}\n >\n {asset && (\n <img\n alt={fields?.title}\n title={fields?.title}\n src={asset.path}\n srcSet={asset.thumbs ? getSrcSetCSSThumbs(asset.thumbs) : undefined}\n className={classNames?.image}\n style={{ objectFit: 'cover', width: '100%', height: '100%' }}\n />\n )}\n </a>\n <div className={classNames?.label}>\n {fields?.title && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"titleLink\"\n className={classNames?.titleLink}\n >\n {fields.title}\n </a>\n )}\n {fields?.description && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"descriptionLink\"\n className={classNames?.descriptionLink}\n >\n {fields.description}\n </a>\n )}\n {fields?.brandname && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"brandNameLink\"\n className={classNames?.brandNameLink}\n >\n {fields.brandname}\n </a>\n )}\n {fields?.phone && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"phoneLink\"\n className={classNames?.phoneLink}\n >\n {fields.phone}\n </a>\n )}\n {fields?.url && (\n <a\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n href={getPrepareURL(url)}\n data-class=\"urlLink\"\n className={classNames?.urlLink}\n >\n {fields?.url}\n </a>\n )}\n </div>\n </div>\n );\n}\n\nAdViewUnitNativeTemplate.defaults = {\n type: 'native',\n};\n\nexport default AdViewUnitNativeTemplate;\n","import React from 'react';\nimport { AdLoadState, AdViewUnitTemplateTypeProps } from '../types';\nimport { matchExpectedState } from './utils';\n\ntype AdViewUnitProxyTemplateProps = Omit<AdViewUnitTemplateTypeProps, 'type'> & {\n type?: 'proxy';\n className?: string;\n style?: React.CSSProperties;\n};\n\nfunction AdViewUnitProxyTemplate({className, style, data, state, ...props}: AdViewUnitProxyTemplateProps) {\n if (!data) {\n return null;\n }\n\n const expectState: AdLoadState =\n (props?.isInitial || props?.isLoading || props?.isError || props?.isComplete) ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete\n } : {isComplete: true};\n\n // Check if the expected state matches the current state\n if (!matchExpectedState(expectState, state)) {\n return null;\n }\n\n const { url, fields } = data;\n const iframeSrc = fields?.url || url;\n\n if (!iframeSrc) {\n return null;\n }\n\n return (\n <iframe\n className={className}\n width=\"100%\"\n height=\"100%\"\n frameBorder=\"0\"\n marginWidth={0}\n marginHeight={0}\n allowTransparency={true}\n scrolling=\"no\"\n allowFullScreen={true}\n style={{ width: '100%', height: '100%', border: 'none', ...style }}\n src={iframeSrc}\n ></iframe>\n );\n}\n\nAdViewUnitProxyTemplate.defaults = {\n type: 'proxy',\n};\n\nexport default AdViewUnitProxyTemplate;\n","//\n// Example\n// <AdView.Unit>\n// <AdView.Template type=\"banner\">\n// <...>\n// </AdView.Template>\n// </AdView.Unit>\n//\n\nimport React, { JSX } from 'react';\nimport {\n AdLoadState,\n AdViewUnitClientChildrenProps,\n AdViewUnitTemplateProps,\n AdViewUnitTemplateTypeProps,\n} 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 = (\n tmpls: TemplateElement[],\n) => 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 = (\n props: AdViewUnitTemplateTypeProps,\n) => React.ReactNode | React.ReactElement;\n\n// templateFromListRender is a function that takes a list of TemplateType and returns a React element\nexport const templateFromListRender = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n wrap?: (children: React.ReactNode) => React.ReactNode,\n): JSX.Element | React.ReactElement => {\n if (!wrap) {\n wrap = (children: React.ReactNode) => children;\n }\n\n let renderedTemplate = null;\n\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, data);\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n\n if (!renderedTemplate) {\n for (let tpl of tmpls) {\n let tmp = renderTemplate(tpl, { ...data, type: 'default' });\n if (tmp && React.isValidElement(tmp)) {\n renderedTemplate = wrap(tmp);\n break;\n }\n }\n }\n\n return <>{renderedTemplate}</>;\n};\n\n// renderTemplate is a function that takes a TemplateType or a function and returns a React node\nexport const renderTemplate = (\n tmpl: TemplateElement | TemplateTypeFunction,\n data: AdViewUnitTemplateTypeProps,\n): React.ReactNode => {\n const isFunction = typeof tmpl === 'function';\n const isReactElement = React.isValidElement(tmpl);\n\n if (isReactElement) {\n // Extract type and children from the React element\n let { type, children } = tmpl.props;\n if (!type && typeof tmpl.type !== 'string') {\n type = (tmpl.type as any)?.defaults?.type;\n }\n // If the type does not match, return null\n if (!!type && type !== '*' && data.type !== type) {\n return null;\n }\n // If children is a function, call it with the data\n if (typeof children === 'function') {\n return children(data as AdViewUnitClientChildrenProps);\n }\n // If children is a React element, clone it with the new props\n return React.cloneElement(tmpl as TemplateElement, {\n ...data,\n children: children,\n });\n }\n\n if (isFunction) {\n return tmpl(data);\n }\n\n return null;\n};\n\n// renderTemplates is a function that takes a list of TemplateType and returns a React element\nexport const renderTemplates = (\n tmpls: TemplateElement[],\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): React.ReactNode | React.ReactElement | JSX.Element => {\n return listRender ? listRender(tmpls) : templateFromListRender(tmpls, data);\n};\n\nexport const renderAnyTemplates = (\n tmpls: any,\n data: AdViewUnitTemplateTypeProps,\n listRender?: TemplateListRender,\n): 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 = ({\n type,\n state,\n children,\n ...props\n}: 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 ? {\n isInitial: props?.isInitial,\n isLoading: props?.isLoading,\n isError: props?.isError,\n isComplete: props?.isComplete,\n }\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(\n tmplProps as AdViewUnitClientChildrenProps,\n ) as React.ReactElement;\n }\n\n // If children is a React element, clone it with the new props\n if (React.isValidElement(children)) {\n return React.cloneElement(children, tmplProps);\n }\n\n // If no children are provided, return an empty fragment\n return <></>;\n};\n\nexport default AdViewUnitTemplate;\n","'use client';\n\nimport { executeImpressionsTracking } from '@adview/core/utils';\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\ntype AdViewUnitTrackingProps = {\n impressions?: string[];\n views?: string[];\n clicks?: string[];\n children: React.ReactNode;\n className?: string;\n};\n\nfunction AdViewUnitTracking({\n impressions,\n views,\n clicks,\n children,\n className,\n}: AdViewUnitTrackingProps) {\n const isServer = typeof window === 'undefined';\n const wrapperRef = useRef<HTMLDivElement>(null);\n const executeImpressionsTrackingHandler = useCallback(\n () => executeImpressionsTracking(impressions),\n [impressions],\n );\n const trackingObserverInstanceHandler = useCallback(\n (entries: IntersectionObserverEntry[]) => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n executeImpressionsTracking(views);\n trackingObserverInstance?.unobserve(wrapperRef.current!);\n }\n });\n },\n [views],\n );\n const trackingObserverInstance = useMemo<IntersectionObserver | null>(() => {\n return !isServer\n ? new IntersectionObserver(trackingObserverInstanceHandler)\n : null;\n }, [isServer, trackingObserverInstanceHandler]);\n const clickTrackerHandler = useCallback(() => {\n executeImpressionsTracking(clicks);\n\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n }, [clicks]);\n\n useEffect(() => {\n if (wrapperRef.current && trackingObserverInstance) {\n executeImpressionsTrackingHandler();\n wrapperRef.current?.addEventListener('click', clickTrackerHandler);\n trackingObserverInstance?.observe(wrapperRef.current);\n\n return () => {\n wrapperRef.current?.removeEventListener('click', clickTrackerHandler);\n if (wrapperRef.current)\n trackingObserverInstance?.unobserve(wrapperRef.current);\n };\n }\n\n return () => {};\n }, [\n trackingObserverInstance,\n executeImpressionsTrackingHandler,\n clickTrackerHandler,\n ]);\n\n return (\n <div ref={wrapperRef} className={className}>\n {children}\n </div>\n );\n}\n\nexport default AdViewUnitTracking;\n","'use client';\n\nimport { AdViewData, AdViewDataLoader } from '@adview/core/typings';\nimport { getDataLoaderFromConfig, 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 limit: number = 1,\n format?: string | string[],\n query?: { [key: string]: any },\n sources?: 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 dataLoader: AdViewDataLoader = getDataLoaderFromConfig(\n baseConfig,\n sources,\n );\n\n const loadAd = async () => {\n setAdLoadState('loading');\n\n try {\n const response = await dataLoader.fetchAdData(\n unitId,\n limit || 1,\n format,\n query,\n );\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(() => {\n loadAd();\n }, [unitId, limit, format]);\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,IAAAA,gBAAkB;;;ACHlB,mBAIO;AACP,mBAAkB;;;ACHX,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;;;ADSA,SAAS,yBAAyB;AAAA,EAChC,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAkC;AAChC,QAAM,cACJ,OAAO,aAAa,OAAO,aAAa,OAAO,WAAW,OAAO,aAC7D;AAAA,IACE,WAAW,OAAO;AAAA,IAClB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,YAAY,OAAO;AAAA,EACrB,IACA,EAAE,YAAY,KAAK;AAEzB,MAAI,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,KAAK,OAAO,QAAQ;AAChD,WAAO;AA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ACA,WAAO,EAAE,eAAe,MAAM,eAAe,CAAC,GAAG,YAAY,CAAC,EAAE;AAAA,EAClE,GAAG;AAEP,MAAI,CAAC,UAAU;AACb,eAAW;AAAA,MACT,8BAAAC,QAAA,cAAC,sCAAyB;AAAA,MAC1B,8BAAAA,QAAA,cAAC,sCAAyB;AAAA,MAC1B,8BAAAA,QAAA,cAAC,qCAAwB;AAAA,IAC3B;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,cAAU,CAAC,SAA4B,8BAAAA,QAAA,4BAAAA,QAAA,gBAAG,IAAK;AAAA,EACjD;AAEA,MAAI,cAAc,YAAY,SAAS,GAAG;AACxC,WAAO;AAAA,MACJ,WAAiC,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,UAAU;AACrE,eACE,8BAAAA,QAAA;AAAA,UAAC;AAAA;AAAA,YACC,KAAK,KAAK;AAAA,YACT,GAAG;AAAA,YACJ,WAAW;AAAA;AAAA,UAEV,mBAAmB,UAAU;AAAA,YAC5B;AAAA,YACA;AAAA,YACA;AAAA,YACA,MAAM,KAAK,QAAQ;AAAA,YACnB;AAAA,YACA,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MAEJ,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,QAAQ;AAAA,IACb,8BAAAA,QAAA,cAAC,8BAAoB,GAAG,eAAe,WAAW,4BAC/C,mBAAmB,UAAU;AAAA,MAC5B;AAAA,MACA,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,IACT,CAAC,CACH;AAAA,EACF,CAAC;AACH;AAEA,IAAO,4BAAQ;","names":["import_react","React","import_utils","import_react","React","import_react","React","import_react","React","import_utils","import_react","React","import_utils","import_react","import_react","customTracker","groupItems","React"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { d as AdViewUnitPropsBase, a as AdViewUnitClientChildren } from '../types-
|
|
2
|
+
import { d as AdViewUnitPropsBase, a as AdViewUnitClientChildren } from '../types-Bc2HTUyk.cjs';
|
|
3
3
|
import '@adview/core/typings';
|
|
4
4
|
|
|
5
5
|
type AdViewUnitClientProps = AdViewUnitPropsBase & {
|
|
6
6
|
children?: AdViewUnitClientChildren;
|
|
7
7
|
wrapper?: (elms: React.ReactNode[]) => React.ReactNode;
|
|
8
8
|
trackingWrapperClassName?: string;
|
|
9
|
+
sources?: string[];
|
|
9
10
|
};
|
|
10
|
-
declare function AdViewUnitClient({ unitId, limit, format, children, wrapper, trackingWrapperClassName, ...config }: AdViewUnitClientProps): React.ReactNode;
|
|
11
|
+
declare function AdViewUnitClient({ unitId, limit, format, query, children, wrapper, trackingWrapperClassName, sources, ...config }: AdViewUnitClientProps): React.ReactNode;
|
|
11
12
|
|
|
12
13
|
export { type AdViewUnitClientProps, AdViewUnitClient as default };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { d as AdViewUnitPropsBase, a as AdViewUnitClientChildren } from '../types-
|
|
2
|
+
import { d as AdViewUnitPropsBase, a as AdViewUnitClientChildren } from '../types-Bc2HTUyk.js';
|
|
3
3
|
import '@adview/core/typings';
|
|
4
4
|
|
|
5
5
|
type AdViewUnitClientProps = AdViewUnitPropsBase & {
|
|
6
6
|
children?: AdViewUnitClientChildren;
|
|
7
7
|
wrapper?: (elms: React.ReactNode[]) => React.ReactNode;
|
|
8
8
|
trackingWrapperClassName?: string;
|
|
9
|
+
sources?: string[];
|
|
9
10
|
};
|
|
10
|
-
declare function AdViewUnitClient({ unitId, limit, format, children, wrapper, trackingWrapperClassName, ...config }: AdViewUnitClientProps): React.ReactNode;
|
|
11
|
+
declare function AdViewUnitClient({ unitId, limit, format, query, children, wrapper, trackingWrapperClassName, sources, ...config }: AdViewUnitClientProps): React.ReactNode;
|
|
11
12
|
|
|
12
13
|
export { type AdViewUnitClientProps, AdViewUnitClient as default };
|
|
@@ -338,17 +338,25 @@ var AdViewProviderContext = createContext(
|
|
|
338
338
|
);
|
|
339
339
|
|
|
340
340
|
// src/AdViewUnit/useAdViewController.ts
|
|
341
|
-
function useAdViewController(adUnitConfig, unitId, limit = 1, format) {
|
|
341
|
+
function useAdViewController(adUnitConfig, unitId, limit = 1, format, query, sources) {
|
|
342
342
|
const [adLoadState, setAdLoadState] = useState("initial");
|
|
343
343
|
const [adData, setAdData] = useState(null);
|
|
344
344
|
const [errorMessage, setErrorMessage] = useState(null);
|
|
345
345
|
const globalConfig = useContext(AdViewProviderContext);
|
|
346
346
|
const baseConfig = getResolveConfig({ ...adUnitConfig, ...globalConfig });
|
|
347
|
-
const dataLoader = getDataLoaderFromConfig(
|
|
347
|
+
const dataLoader = getDataLoaderFromConfig(
|
|
348
|
+
baseConfig,
|
|
349
|
+
sources
|
|
350
|
+
);
|
|
348
351
|
const loadAd = async () => {
|
|
349
352
|
setAdLoadState("loading");
|
|
350
353
|
try {
|
|
351
|
-
const response = await dataLoader.fetchAdData(
|
|
354
|
+
const response = await dataLoader.fetchAdData(
|
|
355
|
+
unitId,
|
|
356
|
+
limit || 1,
|
|
357
|
+
format,
|
|
358
|
+
query
|
|
359
|
+
);
|
|
352
360
|
if (response instanceof Error) {
|
|
353
361
|
setAdLoadState("error");
|
|
354
362
|
setErrorMessage(response);
|
|
@@ -380,9 +388,11 @@ function AdViewUnitClient({
|
|
|
380
388
|
unitId,
|
|
381
389
|
limit = 1,
|
|
382
390
|
format,
|
|
391
|
+
query,
|
|
383
392
|
children,
|
|
384
393
|
wrapper,
|
|
385
394
|
trackingWrapperClassName,
|
|
395
|
+
sources,
|
|
386
396
|
...config
|
|
387
397
|
}) {
|
|
388
398
|
const checkFormat = (f) => {
|
|
@@ -395,7 +405,9 @@ function AdViewUnitClient({
|
|
|
395
405
|
config,
|
|
396
406
|
unitId,
|
|
397
407
|
limit || 1,
|
|
398
|
-
format
|
|
408
|
+
format,
|
|
409
|
+
query,
|
|
410
|
+
sources
|
|
399
411
|
);
|
|
400
412
|
const {
|
|
401
413
|
responseGroup: _,
|