@developer_tribe/react-builder 1.2.28 → 1.2.29
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/index.cjs.js +4 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +4 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.web.cjs.js +1 -1
- package/dist/index.web.cjs.js.map +1 -1
- package/dist/index.web.esm.js +1 -1
- package/dist/index.web.esm.js.map +1 -1
- package/dist/product-base/index.d.ts +24 -0
- package/package.json +1 -1
- package/src/assets/meta.json +1 -1
- package/src/index.ts +2 -0
- package/src/modals/ProductPresetsModal.tsx +2 -2
- package/src/product-base/index.ts +36 -0
- package/src/utils/replaceLocalizationParams.ts +1 -1
|
@@ -25,3 +25,27 @@ export * from './extractAndroidParams';
|
|
|
25
25
|
export * from './extractIOSParams';
|
|
26
26
|
export * from './buildPaywallLocalizationParams';
|
|
27
27
|
export * from './usePaywallLocalizationParams';
|
|
28
|
+
import type { Product } from './types';
|
|
29
|
+
/** Preset map: preset key → product array. */
|
|
30
|
+
export type MockProductPresets = Record<string, Product[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a deep-copy of all mock product presets.
|
|
33
|
+
*
|
|
34
|
+
* Use this instead of importing `mockProducts.json` directly so that:
|
|
35
|
+
* 1. Consumers don't couple to a JSON file path.
|
|
36
|
+
* 2. Each call returns a fresh copy (safe to mutate).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* import { getMockProducts } from '@developer_tribe/react-builder';
|
|
40
|
+
* const presets = getMockProducts(); // { 'preset-1': [...], ... }
|
|
41
|
+
*/
|
|
42
|
+
export declare function getMockProducts(): MockProductPresets;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the product list for a specific preset key (deep-copied).
|
|
45
|
+
* Returns an empty array if the key doesn't exist.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* import { getMockProductsByPreset } from '@developer_tribe/react-builder';
|
|
49
|
+
* const products = getMockProductsByPreset('preset-1');
|
|
50
|
+
*/
|
|
51
|
+
export declare function getMockProductsByPreset(presetKey: string): Product[];
|
package/package.json
CHANGED
package/src/assets/meta.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -79,6 +79,8 @@ export {
|
|
|
79
79
|
buildPaywallLocalizationParams,
|
|
80
80
|
usePaywallLocalizationParams,
|
|
81
81
|
} from './product-base';
|
|
82
|
+
export type { MockProductPresets } from './product-base';
|
|
83
|
+
export { getMockProducts, getMockProductsByPreset } from './product-base';
|
|
82
84
|
|
|
83
85
|
// Context (RN-safe). In React Native, `products` should come from an IAP wrapper
|
|
84
86
|
// (e.g. `react-native-iap`) and be passed into `BuilderProvider` by the host app.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import Modal from './Modal';
|
|
3
3
|
import type { Product } from '../paywall/types/paywall-types';
|
|
4
|
-
import
|
|
4
|
+
import { getMockProducts } from '../product-base';
|
|
5
5
|
|
|
6
6
|
type PresetMap = Record<string, Product[]>;
|
|
7
7
|
const DEFAULT_PRESET_KEY = 'preset-1';
|
|
@@ -18,7 +18,7 @@ function ensureProductId(p: Product): Product {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function getPresetMap(): PresetMap {
|
|
21
|
-
const raw =
|
|
21
|
+
const raw = getMockProducts();
|
|
22
22
|
const safe: PresetMap = {};
|
|
23
23
|
Object.entries(raw ?? {}).forEach(([key, list]) => {
|
|
24
24
|
if (!key || typeof key !== 'string') return;
|
|
@@ -26,3 +26,39 @@ export * from './extractAndroidParams';
|
|
|
26
26
|
export * from './extractIOSParams';
|
|
27
27
|
export * from './buildPaywallLocalizationParams';
|
|
28
28
|
export * from './usePaywallLocalizationParams';
|
|
29
|
+
|
|
30
|
+
/* ── Mock Products ── */
|
|
31
|
+
|
|
32
|
+
import presetsJson from './mockProducts.json';
|
|
33
|
+
import type { Product } from './types';
|
|
34
|
+
|
|
35
|
+
/** Preset map: preset key → product array. */
|
|
36
|
+
export type MockProductPresets = Record<string, Product[]>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns a deep-copy of all mock product presets.
|
|
40
|
+
*
|
|
41
|
+
* Use this instead of importing `mockProducts.json` directly so that:
|
|
42
|
+
* 1. Consumers don't couple to a JSON file path.
|
|
43
|
+
* 2. Each call returns a fresh copy (safe to mutate).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* import { getMockProducts } from '@developer_tribe/react-builder';
|
|
47
|
+
* const presets = getMockProducts(); // { 'preset-1': [...], ... }
|
|
48
|
+
*/
|
|
49
|
+
export function getMockProducts(): MockProductPresets {
|
|
50
|
+
return JSON.parse(JSON.stringify(presetsJson)) as MockProductPresets;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns the product list for a specific preset key (deep-copied).
|
|
55
|
+
* Returns an empty array if the key doesn't exist.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* import { getMockProductsByPreset } from '@developer_tribe/react-builder';
|
|
59
|
+
* const products = getMockProductsByPreset('preset-1');
|
|
60
|
+
*/
|
|
61
|
+
export function getMockProductsByPreset(presetKey: string): Product[] {
|
|
62
|
+
const all = getMockProducts();
|
|
63
|
+
return all[presetKey] ?? [];
|
|
64
|
+
}
|