@pushwoosh/dumb-components 1.1.173 → 1.1.174

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.
@@ -9,6 +9,7 @@ export declare function contrastOn(hex: string): string;
9
9
  export declare function withAlpha(hex: string, a: number): string;
10
10
  export declare function mixHex(hex: string, target: string, t: number): string;
11
11
  export declare function surfaceBackground(background: string | string[] | undefined, fallbackHex: string): string;
12
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
12
13
  export declare function asText(value: unknown): string;
13
14
  export type NativeRichMediaTextValue = {
14
15
  text: string;
@@ -65,6 +65,9 @@ export function surfaceBackground(background, fallbackHex) {
65
65
  }
66
66
  return background || fallbackHex;
67
67
  }
68
+ export function isObject(value) {
69
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
70
+ }
68
71
  export function asText(value) {
69
72
  return typeof value === 'string' ? value : '';
70
73
  }
@@ -1,4 +1,5 @@
1
1
  export type { NativeRichMediaConfig, NativeRichMediaDisplayType, NativeRichMediaText, NativeRichMediaBorder, NativeRichMediaCover, NativeRichMediaAction, NativeRichMediaButton, NativeRichMediaReward, NativeRichMediaModalBlock, NativeRichMediaSheetBlock, NativeRichMediaCarouselBlock, NativeRichMediaStoriesBlock, NativeRichMediaBannerBlock, NativeRichMediaFullscreenBlock, NativeRichMediaVideoBlock, NativeRichMediaPipBlock, NativeRichMediaScratchcardBlock, NativeRichMediaSpinwheelBlock, NativeRichMediaPreviewProps, NativeRichMediaLocalization, } from './types';
2
2
  export { NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './types';
3
3
  export { parseNativeRichMediaConfig } from './parseNativeRichMediaConfig';
4
+ export { parseLocalizationParams } from './parseLocalizationParams';
4
5
  export { NativeRichMediaPreview } from './NativeRichMediaPreview';
@@ -1,3 +1,4 @@
1
1
  export { NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './types';
2
2
  export { parseNativeRichMediaConfig } from './parseNativeRichMediaConfig';
3
+ export { parseLocalizationParams } from './parseLocalizationParams';
3
4
  export { NativeRichMediaPreview } from './NativeRichMediaPreview';
@@ -0,0 +1,9 @@
1
+ import type { NativeRichMediaLocalization } from './types';
2
+ /**
3
+ * Parses a rich media `params` JSON string into a {@link NativeRichMediaLocalization}
4
+ * ready for the `localization` prop of {@link NativeRichMediaPreview}. Accepts both the
5
+ * wrapped shape (`{ localization: { … } }`) and a bare localization object, and tolerates
6
+ * malformed input: a missing, non-JSON, or non-object `params` yields `{}`, and non-string
7
+ * leaves are dropped so the result is always `Record<string, Record<string, string>>`.
8
+ */
9
+ export declare function parseLocalizationParams(params?: string): NativeRichMediaLocalization;
@@ -0,0 +1,37 @@
1
+ import { isObject } from './helpers';
2
+ /**
3
+ * Parses a rich media `params` JSON string into a {@link NativeRichMediaLocalization}
4
+ * ready for the `localization` prop of {@link NativeRichMediaPreview}. Accepts both the
5
+ * wrapped shape (`{ localization: { … } }`) and a bare localization object, and tolerates
6
+ * malformed input: a missing, non-JSON, or non-object `params` yields `{}`, and non-string
7
+ * leaves are dropped so the result is always `Record<string, Record<string, string>>`.
8
+ */
9
+ export function parseLocalizationParams(params) {
10
+ if (!params) {
11
+ return {};
12
+ }
13
+ let parsed;
14
+ try {
15
+ parsed = JSON.parse(params);
16
+ } catch {
17
+ return {};
18
+ }
19
+ if (!isObject(parsed)) {
20
+ return {};
21
+ }
22
+ const source = isObject(parsed.localization) ? parsed.localization : parsed;
23
+ const result = {};
24
+ Object.entries(source).forEach(([code, dict]) => {
25
+ if (!isObject(dict)) {
26
+ return;
27
+ }
28
+ const clean = {};
29
+ Object.entries(dict).forEach(([key, value]) => {
30
+ if (typeof value === 'string') {
31
+ clean[key] = value;
32
+ }
33
+ });
34
+ result[code] = clean;
35
+ });
36
+ return result;
37
+ }
@@ -1,7 +1,5 @@
1
+ import { isObject } from './helpers';
1
2
  import { NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './types';
2
- function isObject(value) {
3
- return typeof value === 'object' && value !== null && !Array.isArray(value);
4
- }
5
3
  function isNonEmptyString(value) {
6
4
  return typeof value === 'string' && value.length > 0;
7
5
  }
package/index.d.ts CHANGED
@@ -44,7 +44,7 @@ export { EnhancedInput, SearchInput } from './EnhancedInput';
44
44
  export { Chip, type ChipProps, type ChipVariant } from './Chip';
45
45
  export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
46
46
  export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type IsolatedSandboxedHtmlFrameProps, type InspectableSandboxedHtmlFrameProps, } from './SandboxedHtmlFrame';
47
- export { NativeRichMediaPreview, parseNativeRichMediaConfig, NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
47
+ export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
48
48
  export type { NativeRichMediaConfig, NativeRichMediaDisplayType, NativeRichMediaText, NativeRichMediaBorder, NativeRichMediaCover, NativeRichMediaAction, NativeRichMediaButton, NativeRichMediaReward, NativeRichMediaModalBlock, NativeRichMediaSheetBlock, NativeRichMediaCarouselBlock, NativeRichMediaStoriesBlock, NativeRichMediaBannerBlock, NativeRichMediaFullscreenBlock, NativeRichMediaVideoBlock, NativeRichMediaPipBlock, NativeRichMediaScratchcardBlock, NativeRichMediaSpinwheelBlock, NativeRichMediaPreviewProps, NativeRichMediaLocalization, } from './NativeRichMediaPreview';
49
49
  export { RichMessageEditor, RichMessageViewer, type DynamicContent, } from './RichMessageEditor';
50
50
  export { FrequencyCappingEdit, FrequencyCappingReadonly, FrequencyCappingInApps, type LocalCapping, type CappingInAppBase, } from './FrequencyCapping';
package/index.js CHANGED
@@ -44,7 +44,7 @@ export { EnhancedInput, SearchInput } from './EnhancedInput';
44
44
  export { Chip } from './Chip';
45
45
  export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
46
46
  export { SandboxedHtmlFrame } from './SandboxedHtmlFrame';
47
- export { NativeRichMediaPreview, parseNativeRichMediaConfig, NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
47
+ export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
48
48
  export { RichMessageEditor, RichMessageViewer } from './RichMessageEditor';
49
49
  export { FrequencyCappingEdit, FrequencyCappingReadonly, FrequencyCappingInApps } from './FrequencyCapping';
50
50
  export { SendRateEdit, SendRateReadonly } from './SendRate';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.173",
3
+ "version": "1.1.174",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",