@developer_tribe/react-builder 1.0.7 → 1.0.9

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.
Files changed (217) hide show
  1. package/dist/build-components/BIcon/BIconProps.generated.d.ts +3 -0
  2. package/dist/build-components/BackgroundImage/BackgroundImageProps.generated.d.ts +1 -0
  3. package/dist/build-components/Button/ButtonProps.generated.d.ts +1 -0
  4. package/dist/build-components/Carousel/CarouselProps.generated.d.ts +5 -0
  5. package/dist/build-components/CarouselButtons/CarouselButtonsProps.generated.d.ts +1 -0
  6. package/dist/build-components/CarouselDots/CarouselDotsProps.generated.d.ts +1 -0
  7. package/dist/build-components/CarouselItem/CarouselItemProps.generated.d.ts +1 -0
  8. package/dist/build-components/CarouselProvider/CarouselProviderProps.generated.d.ts +1 -0
  9. package/dist/build-components/Image/ImageProps.generated.d.ts +1 -0
  10. package/dist/build-components/Main/MainProps.generated.d.ts +1 -1
  11. package/dist/build-components/Onboard/OnboardProps.generated.d.ts +1 -0
  12. package/dist/build-components/OnboardButton/OnboardButtonProps.generated.d.ts +1 -0
  13. package/dist/build-components/OnboardButtons/OnboardButtonsProps.generated.d.ts +1 -0
  14. package/dist/build-components/OnboardDot/OnboardDotProps.generated.d.ts +1 -0
  15. package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +3 -0
  16. package/dist/build-components/OnboardImage/OnboardImageProps.generated.d.ts +1 -0
  17. package/dist/build-components/OnboardItem/OnboardItemProps.generated.d.ts +1 -0
  18. package/dist/build-components/OnboardProvider/OnboardProviderProps.generated.d.ts +3 -0
  19. package/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +3 -0
  20. package/dist/build-components/OnboardTitle/OnboardTitleProps.generated.d.ts +3 -0
  21. package/dist/build-components/PaywallBackground/PaywallBackgroundProps.generated.d.ts +1 -1
  22. package/dist/build-components/PaywallCloseButton/PaywallCloseButtonProps.generated.d.ts +3 -1
  23. package/dist/build-components/PaywallOptions/PaywallOptionsProps.generated.d.ts +1 -1
  24. package/dist/build-components/PaywallProvider/PaywallContext.d.ts +12 -0
  25. package/dist/build-components/PaywallProvider/PaywallProviderProps.generated.d.ts +1 -1
  26. package/dist/build-components/PaywallSubscribeButton/PaywallSubscribeButtonProps.generated.d.ts +1 -0
  27. package/dist/build-components/RadioButton/RadioButtonProps.generated.d.ts +1 -1
  28. package/dist/build-components/Text/TextProps.generated.d.ts +3 -0
  29. package/dist/build-components/View/ViewProps.generated.d.ts +1 -0
  30. package/dist/build-components/patterns.generated.d.ts +372 -374
  31. package/dist/components/BuilderProvider.d.ts +2 -0
  32. package/dist/components/ParamsProvider.d.ts +5 -0
  33. package/dist/components/RenderErrorBoundary.d.ts +28 -0
  34. package/dist/hooks/useSyncHtmlThemeClass.d.ts +7 -0
  35. package/dist/index.cjs.js +5 -5
  36. package/dist/index.cjs.js.map +1 -1
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.esm.js +3 -3
  39. package/dist/index.esm.js.map +1 -1
  40. package/dist/index.native.cjs.js +4 -4
  41. package/dist/index.native.cjs.js.map +1 -1
  42. package/dist/index.native.d.ts +1 -0
  43. package/dist/index.native.esm.js +4 -4
  44. package/dist/index.native.esm.js.map +1 -1
  45. package/dist/migrations/migratePipe.d.ts +14 -0
  46. package/dist/migrations/migrations/1.1.0_normalize_style_attributes.d.ts +2 -0
  47. package/dist/migrations/semver.d.ts +8 -0
  48. package/dist/migrations/types.d.ts +8 -0
  49. package/dist/mockOS/components/SubscriptionModal.d.ts +7 -0
  50. package/dist/mockOS/context/MockOSContextBase.d.ts +1 -0
  51. package/dist/mockOS/hooks/useMockIap.d.ts +3 -0
  52. package/dist/mockOS/index.d.ts +4 -0
  53. package/dist/mockOS/managers/mockOSIapManager.d.ts +6 -0
  54. package/dist/mockOS/managers/subscriptionManager.d.ts +10 -0
  55. package/dist/pages/ProjectDebug.d.ts +14 -0
  56. package/dist/pages/ProjectMigrationPage.d.ts +23 -0
  57. package/dist/pages/ProjectValidationPage.d.ts +15 -0
  58. package/dist/styles.css +1 -1
  59. package/dist/types/Device.d.ts +5 -0
  60. package/dist/utils/__special_exceptions.d.ts +7 -0
  61. package/dist/utils/getImage.d.ts +23 -0
  62. package/dist/utils/pasteNode.d.ts +15 -0
  63. package/dist/utils/patterns.d.ts +1 -2
  64. package/package.json +6 -2
  65. package/scripts/migrate-patterns-to-v2.mjs +131 -0
  66. package/scripts/migrate-samples-to-current.ts +79 -0
  67. package/scripts/prebuild/utils/createGeneratedProps.js +4 -5
  68. package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +32 -21
  69. package/scripts/prebuild/utils/validatePatternJson.js +12 -10
  70. package/src/.DS_Store +0 -0
  71. package/src/AttributesEditor.tsx +41 -11
  72. package/src/RenderPage.tsx +55 -0
  73. package/src/assets/.DS_Store +0 -0
  74. package/src/assets/devices.json +91 -0
  75. package/src/assets/samples/carousel-sample.json +141 -29
  76. package/src/assets/samples/getSamples.ts +9 -0
  77. package/src/assets/samples/paywall-1.json +119 -71
  78. package/src/assets/samples/simple-1.json +28 -16
  79. package/src/assets/samples/simple-2.json +157 -82
  80. package/src/assets/samples/unmigrated-builder1.json +42 -0
  81. package/src/assets/samples/unvalidated-builder1.json +49 -0
  82. package/src/assets/samples/unvalidated-crash1.json +19 -0
  83. package/src/assets/samples/unvalidated-crashcomponent1.json +16 -0
  84. package/src/assets/samples/vpn-onboard-1.json +91 -51
  85. package/src/assets/samples/vpn-onboard-2.json +318 -278
  86. package/src/assets/samples/vpn-onboard-3.json +286 -252
  87. package/src/assets/samples/vpn-onboard-4.json +286 -252
  88. package/src/assets/samples/vpn-onboard-5.json +434 -374
  89. package/src/assets/samples/vpn-onboard-6.json +290 -250
  90. package/src/attributes-editor/Field.tsx +1 -1
  91. package/src/attributes-editor/LayoutPreviewPicker.tsx +5 -2
  92. package/src/build-components/BIcon/BIconProps.generated.ts +3 -0
  93. package/src/build-components/BIcon/pattern.json +12 -9
  94. package/src/build-components/BackgroundImage/BackgroundImage.tsx +3 -1
  95. package/src/build-components/BackgroundImage/BackgroundImageProps.generated.ts +1 -0
  96. package/src/build-components/BackgroundImage/pattern.json +25 -16
  97. package/src/build-components/Button/Button.tsx +26 -3
  98. package/src/build-components/Button/ButtonProps.generated.ts +1 -0
  99. package/src/build-components/Button/pattern.json +10 -6
  100. package/src/build-components/Carousel/CarouselProps.generated.ts +5 -0
  101. package/src/build-components/Carousel/pattern.json +19 -8
  102. package/src/build-components/CarouselButtons/CarouselButtonsProps.generated.ts +1 -0
  103. package/src/build-components/CarouselButtons/pattern.json +11 -5
  104. package/src/build-components/CarouselDots/CarouselDotsProps.generated.ts +1 -0
  105. package/src/build-components/CarouselDots/pattern.json +5 -4
  106. package/src/build-components/CarouselItem/CarouselItemProps.generated.ts +1 -0
  107. package/src/build-components/CarouselItem/pattern.json +5 -4
  108. package/src/build-components/CarouselProvider/CarouselProvider.tsx +44 -2
  109. package/src/build-components/CarouselProvider/CarouselProviderProps.generated.ts +1 -0
  110. package/src/build-components/Image/Image.tsx +2 -1
  111. package/src/build-components/Image/ImageProps.generated.ts +1 -0
  112. package/src/build-components/Image/pattern.json +11 -5
  113. package/src/build-components/Main/MainProps.generated.ts +1 -1
  114. package/src/build-components/Main/pattern.json +12 -9
  115. package/src/build-components/Onboard/OnboardProps.generated.ts +1 -0
  116. package/src/build-components/Onboard/pattern.json +14 -9
  117. package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +1 -0
  118. package/src/build-components/OnboardButton/pattern.json +5 -4
  119. package/src/build-components/OnboardButtons/OnboardButtonsProps.generated.ts +1 -0
  120. package/src/build-components/OnboardButtons/pattern.json +5 -4
  121. package/src/build-components/OnboardDot/OnboardDotProps.generated.ts +1 -0
  122. package/src/build-components/OnboardDot/pattern.json +5 -4
  123. package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +3 -0
  124. package/src/build-components/OnboardFooter/pattern.json +8 -5
  125. package/src/build-components/OnboardImage/OnboardImageProps.generated.ts +1 -0
  126. package/src/build-components/OnboardImage/pattern.json +7 -4
  127. package/src/build-components/OnboardItem/OnboardItemProps.generated.ts +1 -0
  128. package/src/build-components/OnboardItem/pattern.json +18 -9
  129. package/src/build-components/OnboardProvider/OnboardProviderProps.generated.ts +3 -0
  130. package/src/build-components/OnboardProvider/pattern.json +21 -6
  131. package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +3 -0
  132. package/src/build-components/OnboardSubtitle/pattern.json +10 -6
  133. package/src/build-components/OnboardTitle/OnboardTitleProps.generated.ts +3 -0
  134. package/src/build-components/OnboardTitle/pattern.json +11 -7
  135. package/src/build-components/PaywallBackground/PaywallBackgroundProps.generated.ts +1 -1
  136. package/src/build-components/PaywallBackground/pattern.json +5 -4
  137. package/src/build-components/PaywallCloseButton/PaywallCloseButton.tsx +6 -1
  138. package/src/build-components/PaywallCloseButton/PaywallCloseButtonProps.generated.ts +3 -1
  139. package/src/build-components/PaywallCloseButton/pattern.json +15 -12
  140. package/src/build-components/PaywallOptions/PaywallOptionButton.tsx +0 -1
  141. package/src/build-components/PaywallOptions/PaywallOptions.tsx +3 -2
  142. package/src/build-components/PaywallOptions/PaywallOptionsProps.generated.ts +1 -1
  143. package/src/build-components/PaywallOptions/pattern.json +14 -11
  144. package/src/build-components/PaywallProvider/PaywallContext.ts +25 -0
  145. package/src/build-components/PaywallProvider/PaywallProvider.tsx +102 -5
  146. package/src/build-components/PaywallProvider/PaywallProviderProps.generated.ts +1 -1
  147. package/src/build-components/PaywallProvider/pattern.json +11 -8
  148. package/src/build-components/PaywallSubscribeButton/PaywallSubscribeButton.tsx +7 -0
  149. package/src/build-components/PaywallSubscribeButton/PaywallSubscribeButtonProps.generated.ts +1 -0
  150. package/src/build-components/PaywallSubscribeButton/pattern.json +16 -13
  151. package/src/build-components/RadioButton/RadioButtonProps.generated.ts +1 -1
  152. package/src/build-components/RadioButton/pattern.json +5 -4
  153. package/src/build-components/Text/Text.tsx +107 -4
  154. package/src/build-components/Text/TextProps.generated.ts +3 -0
  155. package/src/build-components/Text/pattern.json +19 -4
  156. package/src/build-components/View/ViewProps.generated.ts +1 -0
  157. package/src/build-components/View/pattern.json +28 -13
  158. package/src/build-components/other.tsx +15 -0
  159. package/src/build-components/patterns.generated.ts +340 -235
  160. package/src/build-components/useNode.ts +22 -3
  161. package/src/components/BottomBar.tsx +45 -45
  162. package/src/components/Builder.tsx +20 -6
  163. package/src/components/BuilderButton.tsx +75 -38
  164. package/src/components/BuilderProvider.tsx +22 -2
  165. package/src/components/DeviceButton.tsx +12 -5
  166. package/src/components/EditorHeader.tsx +296 -38
  167. package/src/components/ParamsProvider.tsx +7 -0
  168. package/src/components/RenderErrorBoundary.tsx +200 -0
  169. package/src/hooks/useParams.ts +5 -1
  170. package/src/hooks/useSyncHtmlThemeClass.ts +19 -0
  171. package/src/index.native.ts +7 -0
  172. package/src/index.ts +8 -0
  173. package/src/migrations/migratePipe.ts +59 -0
  174. package/src/migrations/migrations/1.1.0_normalize_style_attributes.ts +80 -0
  175. package/src/migrations/semver.ts +24 -0
  176. package/src/migrations/types.ts +9 -0
  177. package/src/mockOS/components/PermissionModal.tsx +3 -2
  178. package/src/mockOS/components/SubscriptionModal.tsx +400 -0
  179. package/src/mockOS/context/MockOSContext.tsx +61 -10
  180. package/src/mockOS/context/MockOSContextBase.ts +1 -0
  181. package/src/mockOS/hooks/useMockIap.ts +11 -0
  182. package/src/mockOS/index.ts +7 -0
  183. package/src/mockOS/managers/mockOSIapManager.ts +10 -0
  184. package/src/mockOS/managers/subscriptionManager.ts +36 -0
  185. package/src/modals/IconPickerModal.tsx +1 -1
  186. package/src/pages/ProjectDebug.tsx +331 -0
  187. package/src/pages/ProjectMigrationPage.tsx +92 -0
  188. package/src/pages/ProjectPage.tsx +318 -166
  189. package/src/pages/ProjectValidationPage.tsx +54 -0
  190. package/src/styles/base/_global.scss +58 -11
  191. package/src/styles/components/_attributes-editor.scss +1 -1
  192. package/src/styles/components/_bottom-bar.scss +7 -4
  193. package/src/styles/components/_editor-shell.scss +126 -4
  194. package/src/styles/components/_mockos-router.scss +3 -2
  195. package/src/styles/components/_ui-components.scss +10 -5
  196. package/src/styles/foundation/_colors.scss +78 -11
  197. package/src/styles/foundation/_mixins.scss +4 -1
  198. package/src/styles/foundation/_sizes.scss +4 -2
  199. package/src/styles/index.scss +1 -0
  200. package/src/styles/layout/_builder.scss +61 -0
  201. package/src/styles/layout/_project-validation.scss +214 -0
  202. package/src/styles/modals/_add-component.scss +4 -2
  203. package/src/styles/modals/_color-modal.scss +4 -2
  204. package/src/styles/modals/_modal-shell.scss +3 -1
  205. package/src/types/Device.ts +5 -0
  206. package/src/utils/__special_exceptions.ts +88 -0
  207. package/src/utils/analyseNode.ts +8 -2
  208. package/src/utils/analyseNodeByPatterns.ts +43 -9
  209. package/src/utils/extractTextStyle.ts +19 -6
  210. package/src/utils/extractViewStyle.ts +68 -59
  211. package/src/utils/getImage.ts +76 -0
  212. package/src/utils/novaToJson.ts +2 -1
  213. package/src/utils/pasteNode.ts +172 -0
  214. package/src/utils/patterns.ts +4 -3
  215. package/dist/android.svg +0 -43
  216. package/dist/apple.svg +0 -16
  217. package/dist/background.jpg +0 -0
@@ -0,0 +1,59 @@
1
+ import type { Project } from '../types/Project';
2
+ import type { Migration } from './types';
3
+ import { isSemverLess } from './semver';
4
+ import { migration_1_1_0_normalize_style_attributes } from './migrations/1.1.0_normalize_style_attributes';
5
+
6
+ export const CURRENT_PROJECT_VERSION = '1.1.0';
7
+
8
+ const MIGRATIONS: Migration[] = [migration_1_1_0_normalize_style_attributes];
9
+
10
+ export type MigrationPipe = {
11
+ projectVersion: string;
12
+ requiredVersion: string;
13
+ required: boolean;
14
+ pending: Migration[];
15
+ };
16
+
17
+ export function getMigrationPipe(
18
+ project: Pick<Project, 'version'>,
19
+ ): MigrationPipe {
20
+ const projectVersion =
21
+ typeof project?.version === 'string' && project.version.trim()
22
+ ? project.version
23
+ : '0.0.0';
24
+
25
+ const required = isSemverLess(projectVersion, CURRENT_PROJECT_VERSION);
26
+
27
+ const pending = required
28
+ ? MIGRATIONS.filter((m) => isSemverLess(projectVersion, m.toVersion))
29
+ : [];
30
+
31
+ return {
32
+ projectVersion,
33
+ requiredVersion: CURRENT_PROJECT_VERSION,
34
+ required,
35
+ pending,
36
+ };
37
+ }
38
+
39
+ export function runProjectMigrations(project: Project): {
40
+ project: Project;
41
+ applied: Migration[];
42
+ } {
43
+ const pipe = getMigrationPipe(project);
44
+ let next = project;
45
+ const applied: Migration[] = [];
46
+
47
+ for (const m of pipe.pending) {
48
+ if (isSemverLess(next.version, m.toVersion)) {
49
+ next = m.run(next);
50
+ applied.push(m);
51
+ }
52
+ }
53
+
54
+ if (isSemverLess(next.version, CURRENT_PROJECT_VERSION)) {
55
+ next = { ...next, version: CURRENT_PROJECT_VERSION };
56
+ }
57
+
58
+ return { project: next, applied };
59
+ }
@@ -0,0 +1,80 @@
1
+ import type { Project } from '../../types/Project';
2
+ import type { Node, NodeData, NodeDefaultAttribute } from '../../types/Node';
3
+ import {
4
+ isEmptyObject,
5
+ isNodeArray,
6
+ isNodeNullOrUndefined,
7
+ isNodeString,
8
+ } from '../../utils/nodeGuards';
9
+ import { getAttributeSchema } from '../../utils/patterns';
10
+ import type { Migration } from '../types';
11
+
12
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
13
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
14
+ }
15
+
16
+ function buildStyleKeySet(): Set<string> {
17
+ const viewSchema = getAttributeSchema('View') ?? {};
18
+ const textSchema = getAttributeSchema('Text') ?? {};
19
+ return new Set([...Object.keys(viewSchema), ...Object.keys(textSchema)]);
20
+ }
21
+
22
+ function migrateNode(node: Node, styleKeys: Set<string>): Node {
23
+ if (
24
+ isNodeNullOrUndefined(node) ||
25
+ isNodeString(node) ||
26
+ isEmptyObject(node)
27
+ ) {
28
+ return node;
29
+ }
30
+ if (isNodeArray(node)) {
31
+ return (node as Node[]).map((n) => migrateNode(n, styleKeys));
32
+ }
33
+
34
+ const record = node as NodeData<NodeDefaultAttribute>;
35
+ const nextChildren = migrateNode(record.children as Node, styleKeys);
36
+
37
+ if (!isPlainObject(record.attributes)) {
38
+ return { ...record, children: nextChildren };
39
+ }
40
+
41
+ const nextAttrs: Record<string, unknown> = { ...(record.attributes ?? {}) };
42
+
43
+ const prevStyle = isPlainObject(nextAttrs.style) ? nextAttrs.style : {};
44
+ const nextStyle: Record<string, unknown> = { ...prevStyle };
45
+
46
+ for (const [k, v] of Object.entries(nextAttrs)) {
47
+ if (k === 'style') continue;
48
+ if (!styleKeys.has(k)) continue;
49
+
50
+ // If already set in style, prefer style (drop legacy flat key).
51
+ if (!(k in nextStyle)) nextStyle[k] = v;
52
+ delete nextAttrs[k];
53
+ }
54
+
55
+ if (Object.keys(nextStyle).length > 0) {
56
+ nextAttrs.style = nextStyle;
57
+ }
58
+
59
+ return {
60
+ ...record,
61
+ children: nextChildren,
62
+ attributes: nextAttrs as NodeDefaultAttribute,
63
+ };
64
+ }
65
+
66
+ export const migration_1_1_0_normalize_style_attributes: Migration = {
67
+ id: '1.1.0-normalize-style-attributes',
68
+ title: 'Normalize legacy style attributes into attributes.style',
69
+ fromVersion: '0.0.0',
70
+ toVersion: '1.1.0',
71
+ run: (project: Project): Project => {
72
+ const styleKeys = buildStyleKeySet();
73
+ const nextData = migrateNode(project.data as unknown as Node, styleKeys);
74
+ return {
75
+ ...project,
76
+ version: '1.1.0',
77
+ data: nextData as any,
78
+ };
79
+ },
80
+ };
@@ -0,0 +1,24 @@
1
+ export type Semver = { major: number; minor: number; patch: number };
2
+
3
+ export function parseSemver(input?: string | null): Semver {
4
+ const raw = typeof input === 'string' ? input.trim() : '';
5
+ const [maj, min, pat] = raw.split('.').slice(0, 3);
6
+ const toNum = (v?: string) => {
7
+ const n = Number(String(v ?? '').replace(/[^\d].*$/, ''));
8
+ return Number.isFinite(n) ? n : 0;
9
+ };
10
+ return { major: toNum(maj), minor: toNum(min), patch: toNum(pat) };
11
+ }
12
+
13
+ export function compareSemver(a: string, b: string): number {
14
+ const A = parseSemver(a);
15
+ const B = parseSemver(b);
16
+ if (A.major !== B.major) return A.major < B.major ? -1 : 1;
17
+ if (A.minor !== B.minor) return A.minor < B.minor ? -1 : 1;
18
+ if (A.patch !== B.patch) return A.patch < B.patch ? -1 : 1;
19
+ return 0;
20
+ }
21
+
22
+ export function isSemverLess(a: string, b: string): boolean {
23
+ return compareSemver(a, b) < 0;
24
+ }
@@ -0,0 +1,9 @@
1
+ import type { Project } from '../types/Project';
2
+
3
+ export type Migration = {
4
+ id: string;
5
+ title: string;
6
+ fromVersion: string;
7
+ toVersion: string;
8
+ run: (project: Project) => Project;
9
+ };
@@ -84,7 +84,8 @@ export const PermissionModal: React.FC<PermissionModalProps> = ({
84
84
  >
85
85
  <div
86
86
  style={{
87
- backgroundColor: 'rgba(255, 255, 255, 0.95)',
87
+ backgroundColor:
88
+ 'hsl(var(--card, var(--rb-card, 0 0% 100%)) / 0.95)',
88
89
  borderRadius: 14,
89
90
  width: '100%',
90
91
  maxWidth: 270,
@@ -187,7 +188,7 @@ export const PermissionModal: React.FC<PermissionModalProps> = ({
187
188
  >
188
189
  <div
189
190
  style={{
190
- backgroundColor: '#FFFFFF',
191
+ backgroundColor: 'hsl(var(--card, var(--rb-card, 0 0% 100%)))',
191
192
  borderRadius: 4,
192
193
  width: '100%',
193
194
  maxWidth: 280,
@@ -0,0 +1,400 @@
1
+ import React, { useCallback, useEffect } from 'react';
2
+ import { useRenderStore } from '../../store';
3
+
4
+ type SubscriptionModalProps = {
5
+ productId: string;
6
+ onBuy: () => void;
7
+ onCancel: () => void;
8
+ };
9
+
10
+ export function SubscriptionModal({
11
+ productId,
12
+ onBuy,
13
+ onCancel,
14
+ }: SubscriptionModalProps) {
15
+ const device = useRenderStore((s) => s.device);
16
+ const isIOS = device.platform === 'ios';
17
+
18
+ const onOverlayClick = useCallback(
19
+ (e: React.MouseEvent<HTMLDivElement>) => {
20
+ if (e.target === e.currentTarget) onCancel();
21
+ },
22
+ [onCancel],
23
+ );
24
+
25
+ useEffect(() => {
26
+ const onKeyDown = (e: KeyboardEvent) => {
27
+ if (e.key === 'Escape') onCancel();
28
+ };
29
+ window.addEventListener('keydown', onKeyDown);
30
+ return () => window.removeEventListener('keydown', onKeyDown);
31
+ }, [onCancel]);
32
+
33
+ const titleFromProductId = productId
34
+ .split('.')
35
+ .slice(-2)
36
+ .join(' ')
37
+ .replace(/[-_]/g, ' ')
38
+ .replace(/\b\w/g, (c) => c.toUpperCase());
39
+
40
+ // Bottom sheet (both iOS + Android)
41
+ return (
42
+ <div
43
+ style={{
44
+ position: 'absolute',
45
+ top: 0,
46
+ left: 0,
47
+ right: 0,
48
+ bottom: 0,
49
+ backgroundColor: isIOS ? 'rgba(0, 0, 0, 0.35)' : 'rgba(0, 0, 0, 0.5)',
50
+ display: 'flex',
51
+ alignItems: 'flex-end',
52
+ justifyContent: 'stretch',
53
+ zIndex: 9999,
54
+ padding: 0,
55
+ }}
56
+ onClick={onOverlayClick}
57
+ >
58
+ <div
59
+ style={{
60
+ width: '100%',
61
+ backgroundColor: isIOS
62
+ ? 'hsl(var(--card, var(--rb-card, 0 0% 100%)) / 0.96)'
63
+ : 'hsl(var(--card, var(--rb-card, 0 0% 100%)))',
64
+ borderTopLeftRadius: 16,
65
+ borderTopRightRadius: 16,
66
+ overflow: 'hidden',
67
+ backdropFilter: isIOS ? 'blur(20px)' : undefined,
68
+ boxShadow: isIOS
69
+ ? '0 -12px 30px rgba(0,0,0,0.18), 0 -2px 6px rgba(0,0,0,0.08)'
70
+ : '0 -10px 20px rgba(0,0,0,0.22), 0 -2px 6px rgba(0,0,0,0.14)',
71
+ paddingBottom: 'max(12px, env(safe-area-inset-bottom))',
72
+ transform: 'translateY(0px)',
73
+ }}
74
+ >
75
+ <div
76
+ aria-hidden
77
+ style={{
78
+ width: 44,
79
+ height: 5,
80
+ borderRadius: 999,
81
+ background:
82
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.18)',
83
+ margin: '10px auto 0',
84
+ }}
85
+ />
86
+
87
+ {isIOS ? (
88
+ <div
89
+ style={{
90
+ padding: '10px 16px 10px',
91
+ textAlign: 'center',
92
+ }}
93
+ >
94
+ <div
95
+ style={{
96
+ display: 'flex',
97
+ justifyContent: 'flex-end',
98
+ marginBottom: 6,
99
+ }}
100
+ >
101
+ <button
102
+ onClick={onCancel}
103
+ aria-label="Close"
104
+ style={{
105
+ width: 28,
106
+ height: 28,
107
+ borderRadius: 999,
108
+ border: 'none',
109
+ background:
110
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.06)',
111
+ color:
112
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.55)',
113
+ fontSize: 18,
114
+ lineHeight: '28px',
115
+ cursor: 'pointer',
116
+ }}
117
+ >
118
+ ×
119
+ </button>
120
+ </div>
121
+ <div
122
+ style={{
123
+ fontSize: 15,
124
+ fontWeight: 600,
125
+ color: '#000',
126
+ marginBottom: 8,
127
+ lineHeight: 1.3,
128
+ letterSpacing: 0.2,
129
+ }}
130
+ >
131
+ Confirm with Apple ID
132
+ </div>
133
+ <div
134
+ style={{
135
+ fontSize: 13,
136
+ color: '#000',
137
+ lineHeight: 1.4,
138
+ opacity: 0.6,
139
+ }}
140
+ >
141
+ Subscribe to <b>{titleFromProductId}</b>
142
+ </div>
143
+ <div
144
+ style={{
145
+ marginTop: 12,
146
+ padding: '10px 12px',
147
+ borderRadius: 12,
148
+ background:
149
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.04)',
150
+ textAlign: 'left',
151
+ }}
152
+ >
153
+ <div
154
+ style={{
155
+ display: 'flex',
156
+ alignItems: 'center',
157
+ gap: 10,
158
+ }}
159
+ >
160
+ <div
161
+ aria-hidden
162
+ style={{
163
+ width: 38,
164
+ height: 38,
165
+ borderRadius: 10,
166
+ background:
167
+ 'linear-gradient(135deg, rgba(0,122,255,0.25), rgba(88,86,214,0.22))',
168
+ border: '1px solid rgba(0,0,0,0.06)',
169
+ }}
170
+ />
171
+ <div style={{ flex: 1, minWidth: 0 }}>
172
+ <div
173
+ style={{
174
+ fontSize: 14,
175
+ fontWeight: 600,
176
+ color: 'rgba(0,0,0,0.88)',
177
+ lineHeight: 1.2,
178
+ whiteSpace: 'nowrap',
179
+ overflow: 'hidden',
180
+ textOverflow: 'ellipsis',
181
+ }}
182
+ title={productId}
183
+ >
184
+ {productId}
185
+ </div>
186
+ <div
187
+ style={{
188
+ marginTop: 2,
189
+ fontSize: 12,
190
+ color: 'rgba(0,0,0,0.55)',
191
+ }}
192
+ >
193
+ Renews automatically until cancelled.
194
+ </div>
195
+ </div>
196
+ <div
197
+ style={{
198
+ fontSize: 13,
199
+ fontWeight: 700,
200
+ color: 'rgba(0,0,0,0.8)',
201
+ }}
202
+ >
203
+ $4.99
204
+ </div>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ ) : (
209
+ <div style={{ padding: '14px 16px 10px' }}>
210
+ <div
211
+ style={{
212
+ display: 'flex',
213
+ justifyContent: 'space-between',
214
+ alignItems: 'center',
215
+ gap: 12,
216
+ }}
217
+ >
218
+ <div
219
+ style={{
220
+ fontSize: 16,
221
+ fontWeight: 600,
222
+ color: 'rgba(0,0,0,0.87)',
223
+ }}
224
+ >
225
+ Subscribe with Google Play
226
+ </div>
227
+ <button
228
+ onClick={onCancel}
229
+ aria-label="Close"
230
+ style={{
231
+ width: 28,
232
+ height: 28,
233
+ borderRadius: 999,
234
+ border: 'none',
235
+ background:
236
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.06)',
237
+ color:
238
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.55)',
239
+ fontSize: 18,
240
+ lineHeight: '28px',
241
+ cursor: 'pointer',
242
+ }}
243
+ >
244
+ ×
245
+ </button>
246
+ </div>
247
+ <div
248
+ style={{
249
+ marginTop: 8,
250
+ fontSize: 14,
251
+ color: 'rgba(0, 0, 0, 0.6)',
252
+ lineHeight: 1.5,
253
+ }}
254
+ >
255
+ You’re about to subscribe to <b>{titleFromProductId}</b>.
256
+ </div>
257
+
258
+ <div
259
+ style={{
260
+ marginTop: 14,
261
+ padding: '10px 12px',
262
+ borderRadius: 10,
263
+ background:
264
+ 'hsl(var(--foreground, var(--rb-foreground, 220.9 39.3% 11%)) / 0.04)',
265
+ border: '1px solid rgba(0,0,0,0.06)',
266
+ }}
267
+ >
268
+ <div
269
+ style={{
270
+ display: 'flex',
271
+ alignItems: 'center',
272
+ justifyContent: 'space-between',
273
+ gap: 10,
274
+ }}
275
+ >
276
+ <div style={{ minWidth: 0 }}>
277
+ <div
278
+ style={{
279
+ fontSize: 13,
280
+ fontWeight: 600,
281
+ color: 'rgba(0,0,0,0.78)',
282
+ whiteSpace: 'nowrap',
283
+ overflow: 'hidden',
284
+ textOverflow: 'ellipsis',
285
+ }}
286
+ >
287
+ {productId}
288
+ </div>
289
+ <div
290
+ style={{
291
+ marginTop: 2,
292
+ fontSize: 12,
293
+ color: 'rgba(0,0,0,0.55)',
294
+ }}
295
+ >
296
+ Auto-renews • Cancel anytime in Play Store
297
+ </div>
298
+ </div>
299
+ <div
300
+ style={{
301
+ fontSize: 13,
302
+ fontWeight: 700,
303
+ color: 'rgba(0,0,0,0.8)',
304
+ }}
305
+ >
306
+ $4.99
307
+ </div>
308
+ </div>
309
+ </div>
310
+ </div>
311
+ )}
312
+
313
+ {isIOS ? (
314
+ <div
315
+ style={{
316
+ borderTop: '0.5px solid rgba(0, 0, 0, 0.16)',
317
+ display: 'flex',
318
+ }}
319
+ >
320
+ <button
321
+ onClick={onCancel}
322
+ style={{
323
+ flex: 1,
324
+ padding: '13px 0',
325
+ fontSize: 17,
326
+ fontWeight: 400,
327
+ color: '#007AFF',
328
+ background: 'transparent',
329
+ border: 'none',
330
+ borderRight: '0.5px solid rgba(0, 0, 0, 0.16)',
331
+ cursor: 'pointer',
332
+ }}
333
+ >
334
+ Cancel
335
+ </button>
336
+ <button
337
+ onClick={onBuy}
338
+ style={{
339
+ flex: 1,
340
+ padding: '13px 0',
341
+ fontSize: 17,
342
+ fontWeight: 600,
343
+ color: '#007AFF',
344
+ background: 'transparent',
345
+ border: 'none',
346
+ cursor: 'pointer',
347
+ }}
348
+ >
349
+ Subscribe
350
+ </button>
351
+ </div>
352
+ ) : (
353
+ <div
354
+ style={{
355
+ padding: '10px 12px 12px',
356
+ display: 'flex',
357
+ justifyContent: 'flex-end',
358
+ gap: 8,
359
+ }}
360
+ >
361
+ <button
362
+ onClick={onCancel}
363
+ style={{
364
+ padding: '10px 16px',
365
+ fontSize: 14,
366
+ fontWeight: 500,
367
+ color: '#5F6368',
368
+ background: 'transparent',
369
+ border: 'none',
370
+ borderRadius: 4,
371
+ cursor: 'pointer',
372
+ textTransform: 'uppercase',
373
+ letterSpacing: 0.5,
374
+ }}
375
+ >
376
+ Cancel
377
+ </button>
378
+ <button
379
+ onClick={onBuy}
380
+ style={{
381
+ padding: '10px 16px',
382
+ fontSize: 14,
383
+ fontWeight: 700,
384
+ color: '#1A73E8',
385
+ background: 'rgba(26,115,232,0.12)',
386
+ border: 'none',
387
+ borderRadius: 999,
388
+ cursor: 'pointer',
389
+ textTransform: 'uppercase',
390
+ letterSpacing: 0.5,
391
+ }}
392
+ >
393
+ Subscribe
394
+ </button>
395
+ </div>
396
+ )}
397
+ </div>
398
+ </div>
399
+ );
400
+ }
@@ -1,6 +1,13 @@
1
- import React, { ReactNode, useState, useCallback } from 'react';
1
+ import React, {
2
+ ReactNode,
3
+ useCallback,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ } from 'react';
2
8
  import type { PermissionType } from '../managers/mockPermissionManager';
3
9
  import { PermissionModal } from '../components/PermissionModal';
10
+ import { SubscriptionModal } from '../components/SubscriptionModal';
4
11
  import { MockOSRouter } from '../components/MockOSRouter';
5
12
  import { DeviceStatusBar } from '../../components/DeviceStatusBar';
6
13
  import { DeviceNavigationBar } from '../../components/DeviceNavigationBar';
@@ -53,6 +60,12 @@ export function MockOSProvider({
53
60
  const [permission, setPermission] = useState<PermissionType | string | null>(
54
61
  null,
55
62
  );
63
+ const [subscriptionProductId, setSubscriptionProductId] = useState<
64
+ string | null
65
+ >(null);
66
+ const subscriptionResolverRef = useRef<((result: boolean) => void) | null>(
67
+ null,
68
+ );
56
69
  const [currentRoute, setCurrentRoute] = useState<RouteType>(defaultRoute);
57
70
  const [navigationStack, setNavigationStack] = useState<RouteStackItem[]>([
58
71
  { route: defaultRoute, timestamp: Date.now() },
@@ -93,15 +106,46 @@ export function MockOSProvider({
93
106
  return false;
94
107
  }, [navigationStack]);
95
108
 
96
- const value: MockOSContextValue = {
97
- isEnabled: true,
98
- permission,
99
- setPermission,
100
- currentRoute,
101
- navigation,
102
- goBack,
103
- navigationStack,
104
- };
109
+ const requestSubscriptionPurchase = useCallback((productId: string) => {
110
+ // Cancel any existing pending request (resolve false)
111
+ if (subscriptionResolverRef.current) {
112
+ subscriptionResolverRef.current(false);
113
+ subscriptionResolverRef.current = null;
114
+ }
115
+ setSubscriptionProductId(productId);
116
+
117
+ return new Promise<boolean>((resolve) => {
118
+ subscriptionResolverRef.current = resolve;
119
+ });
120
+ }, []);
121
+
122
+ const resolveSubscriptionPurchase = useCallback((result: boolean) => {
123
+ const resolver = subscriptionResolverRef.current;
124
+ subscriptionResolverRef.current = null;
125
+ setSubscriptionProductId(null);
126
+ resolver?.(result);
127
+ }, []);
128
+
129
+ const value: MockOSContextValue = useMemo(
130
+ () => ({
131
+ isEnabled: true,
132
+ permission,
133
+ setPermission,
134
+ requestSubscriptionPurchase,
135
+ currentRoute,
136
+ navigation,
137
+ goBack,
138
+ navigationStack,
139
+ }),
140
+ [
141
+ permission,
142
+ requestSubscriptionPurchase,
143
+ currentRoute,
144
+ navigation,
145
+ goBack,
146
+ navigationStack,
147
+ ],
148
+ );
105
149
 
106
150
  const handleAllow = () => {
107
151
  setPermission(null);
@@ -120,6 +164,13 @@ export function MockOSProvider({
120
164
  onDeny={handleDeny}
121
165
  />
122
166
  )}
167
+ {subscriptionProductId !== null && (
168
+ <SubscriptionModal
169
+ productId={subscriptionProductId}
170
+ onBuy={() => resolveSubscriptionPurchase(true)}
171
+ onCancel={() => resolveSubscriptionPurchase(false)}
172
+ />
173
+ )}
123
174
  <DeviceStatusBar
124
175
  height={statusBarHeight}
125
176
  backgroundColor={statusBarBackgroundColor}
@@ -17,6 +17,7 @@ export interface MockOSContextValue {
17
17
  isEnabled: boolean;
18
18
  permission: PermissionType | string | null;
19
19
  setPermission: (permission: PermissionType | string | null) => void;
20
+ requestSubscriptionPurchase: (productId: string) => Promise<boolean>;
20
21
  // Router
21
22
  currentRoute: RouteType;
22
23
  navigation: (route: RouteType) => void;