@proulr/sdui-components 0.1.11 → 0.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proulr/sdui-components",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "main": "./src/renderer/index.ts",
5
5
  "types": "./src/renderer/index.ts",
6
6
  "exports": {
@@ -1,11 +1,21 @@
1
+ import type { ReactElement } from 'react';
2
+
1
3
  export type NativeAdPlacementConfig = {
2
4
  aspectRatio?: number;
3
5
  };
4
6
 
7
+ export type NativeAdWebSlotProps = {
8
+ placement: string;
9
+ width?: number;
10
+ aspectRatio: number;
11
+ };
12
+
5
13
  export type NativeAdCatalog = {
6
14
  isEnabled: () => boolean;
7
15
  resolveAdUnitId: (placement: string, testNativeUnitId: string) => string;
8
16
  getPlacementConfig?: (placement: string) => NativeAdPlacementConfig | undefined;
17
+ /** Web-only: AdSense (ou outro). Mobile ignora. */
18
+ renderWebSlot?: (props: NativeAdWebSlotProps) => ReactElement | null;
9
19
  };
10
20
 
11
21
  let nativeAdCatalog: NativeAdCatalog | null = null;
@@ -1,6 +1,41 @@
1
+ import {
2
+ DEFAULT_NATIVE_AD_ASPECT_RATIO,
3
+ DEFAULT_NATIVE_AD_PLACEMENT,
4
+ getNativeAdCatalog,
5
+ } from '../ads/native-ad-catalog';
1
6
  import type { SduiBlockRenderProps } from './SduiPrimitiveBlocks';
2
7
 
3
- /** Web stub — native ads require a native build. */
4
- export function SduiNativeAdBlock(_props: SduiBlockRenderProps) {
5
- return null;
8
+ function resolveBlockWidth(props: Record<string, unknown>): number | undefined {
9
+ if (typeof props.width === 'number' && props.width > 0) return props.width;
10
+ return undefined;
11
+ }
12
+
13
+ function resolvePlacement(props: Record<string, unknown>): string {
14
+ return typeof props.placement === 'string' && props.placement.length > 0
15
+ ? props.placement
16
+ : DEFAULT_NATIVE_AD_PLACEMENT;
17
+ }
18
+
19
+ function resolveAspectRatio(placement: string, props: Record<string, unknown>): number {
20
+ if (typeof props.aspect_ratio === 'number' && props.aspect_ratio > 0) {
21
+ return props.aspect_ratio;
22
+ }
23
+
24
+ const catalog = getNativeAdCatalog();
25
+ const placementConfig = catalog?.getPlacementConfig?.(placement);
26
+ return placementConfig?.aspectRatio ?? DEFAULT_NATIVE_AD_ASPECT_RATIO;
27
+ }
28
+
29
+ /** Web — AdSense via `catalog.renderWebSlot` (configurado no app). */
30
+ export function SduiNativeAdBlock({ block }: SduiBlockRenderProps) {
31
+ const catalog = getNativeAdCatalog();
32
+ if (!catalog?.isEnabled() || !catalog.renderWebSlot) {
33
+ return null;
34
+ }
35
+
36
+ const placement = resolvePlacement(block.props);
37
+ const width = resolveBlockWidth(block.props);
38
+ const aspectRatio = resolveAspectRatio(placement, block.props);
39
+
40
+ return catalog.renderWebSlot({ placement, width, aspectRatio });
6
41
  }
@@ -50,6 +50,10 @@ export {
50
50
  DEFAULT_NATIVE_AD_PLACEMENT,
51
51
  DEFAULT_NATIVE_AD_ASPECT_RATIO,
52
52
  } from './ads/native-ad-catalog';
53
- export type { NativeAdCatalog, NativeAdPlacementConfig } from './ads/native-ad-catalog';
53
+ export type {
54
+ NativeAdCatalog,
55
+ NativeAdPlacementConfig,
56
+ NativeAdWebSlotProps,
57
+ } from './ads/native-ad-catalog';
54
58
  export * from './ui';
55
59
  export { brToISO, isValidDateBR, maskDateBR } from './lib/brazilian-date-input';