@ankhorage/navigator 1.6.1 → 2.0.0

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 (230) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/{expo-router/resolveCustomNavigatorPlan.d.ts → features/custom/application/resolveCustomNavigatorAdapterPlan.d.ts} +2 -4
  4. package/dist/features/custom/application/resolveCustomNavigatorAdapterPlan.d.ts.map +1 -0
  5. package/dist/{expo-router/resolveCustomNavigatorPlan.js → features/custom/application/resolveCustomNavigatorAdapterPlan.js} +1 -1
  6. package/dist/features/custom/application/resolveCustomNavigatorAdapterPlan.js.map +1 -0
  7. package/dist/{validation/validateCustomNavigator.d.ts → features/custom/domain/addCustomNavigatorDiagnostics.d.ts} +2 -4
  8. package/dist/features/custom/domain/addCustomNavigatorDiagnostics.d.ts.map +1 -0
  9. package/dist/{validation/validateCustomNavigator.js → features/custom/domain/addCustomNavigatorDiagnostics.js} +50 -50
  10. package/dist/features/custom/domain/addCustomNavigatorDiagnostics.js.map +1 -0
  11. package/dist/features/custom/domain/defineCustomNavigatorRegistry.d.ts +4 -0
  12. package/dist/features/custom/domain/defineCustomNavigatorRegistry.d.ts.map +1 -0
  13. package/dist/{custom/CustomNavigatorRegistry.js → features/custom/domain/defineCustomNavigatorRegistry.js} +5 -5
  14. package/dist/features/custom/domain/defineCustomNavigatorRegistry.js.map +1 -0
  15. package/dist/features/drawer/adapters/outbound/resolveDrawerRouteOptions.d.ts +4 -0
  16. package/dist/features/drawer/adapters/outbound/resolveDrawerRouteOptions.d.ts.map +1 -0
  17. package/dist/features/drawer/adapters/outbound/resolveDrawerRouteOptions.js +8 -0
  18. package/dist/features/drawer/adapters/outbound/resolveDrawerRouteOptions.js.map +1 -0
  19. package/dist/features/drawer/application/createDrawerAdapter.d.ts +4 -0
  20. package/dist/features/drawer/application/createDrawerAdapter.d.ts.map +1 -0
  21. package/dist/features/drawer/application/createDrawerAdapter.js +12 -0
  22. package/dist/features/drawer/application/createDrawerAdapter.js.map +1 -0
  23. package/dist/features/slot/adapters/outbound/generateSlotLayoutFile.d.ts +4 -0
  24. package/dist/features/slot/adapters/outbound/generateSlotLayoutFile.d.ts.map +1 -0
  25. package/dist/features/slot/adapters/outbound/generateSlotLayoutFile.js +8 -0
  26. package/dist/features/slot/adapters/outbound/generateSlotLayoutFile.js.map +1 -0
  27. package/dist/features/slot/application/createSlotAdapter.d.ts +4 -0
  28. package/dist/features/slot/application/createSlotAdapter.d.ts.map +1 -0
  29. package/dist/features/slot/application/createSlotAdapter.js +12 -0
  30. package/dist/features/slot/application/createSlotAdapter.js.map +1 -0
  31. package/dist/features/slot/domain/addSlotDiagnostics.d.ts +4 -0
  32. package/dist/features/slot/domain/addSlotDiagnostics.d.ts.map +1 -0
  33. package/dist/features/slot/domain/addSlotDiagnostics.js +24 -0
  34. package/dist/features/slot/domain/addSlotDiagnostics.js.map +1 -0
  35. package/dist/{generation → features/split-view/adapters/outbound}/generateSplitViewLayoutFile.d.ts +1 -1
  36. package/dist/features/split-view/adapters/outbound/generateSplitViewLayoutFile.d.ts.map +1 -0
  37. package/dist/{generation → features/split-view/adapters/outbound}/generateSplitViewLayoutFile.js +37 -36
  38. package/dist/features/split-view/adapters/outbound/generateSplitViewLayoutFile.js.map +1 -0
  39. package/dist/{expo-router/resolveSplitViewNavigatorPlan.d.ts → features/split-view/application/resolveSplitViewAdapterPlan.d.ts} +2 -2
  40. package/dist/features/split-view/application/resolveSplitViewAdapterPlan.d.ts.map +1 -0
  41. package/dist/{expo-router/resolveSplitViewNavigatorPlan.js → features/split-view/application/resolveSplitViewAdapterPlan.js} +1 -1
  42. package/dist/features/split-view/application/resolveSplitViewAdapterPlan.js.map +1 -0
  43. package/dist/{validation/validateSplitView.d.ts → features/split-view/domain/addSplitViewDiagnostics.d.ts} +2 -3
  44. package/dist/features/split-view/domain/addSplitViewDiagnostics.d.ts.map +1 -0
  45. package/dist/{validation/validateSplitView.js → features/split-view/domain/addSplitViewDiagnostics.js} +76 -76
  46. package/dist/features/split-view/domain/addSplitViewDiagnostics.js.map +1 -0
  47. package/dist/features/stack/application/createStackAdapter.d.ts +4 -0
  48. package/dist/features/stack/application/createStackAdapter.d.ts.map +1 -0
  49. package/dist/features/stack/application/createStackAdapter.js +43 -0
  50. package/dist/features/stack/application/createStackAdapter.js.map +1 -0
  51. package/dist/{validation/validateExperimentalStack.d.ts → features/stack/domain/addExperimentalStackDiagnostics.d.ts} +2 -3
  52. package/dist/features/stack/domain/addExperimentalStackDiagnostics.d.ts.map +1 -0
  53. package/dist/{validation/validateExperimentalStack.js → features/stack/domain/addExperimentalStackDiagnostics.js} +49 -49
  54. package/dist/features/stack/domain/addExperimentalStackDiagnostics.js.map +1 -0
  55. package/dist/features/stack/domain/addStackAdapterDiagnostics.d.ts +4 -0
  56. package/dist/features/stack/domain/addStackAdapterDiagnostics.d.ts.map +1 -0
  57. package/dist/features/stack/domain/addStackAdapterDiagnostics.js +15 -0
  58. package/dist/features/stack/domain/addStackAdapterDiagnostics.js.map +1 -0
  59. package/dist/features/stack/domain/resolveEffectiveStackConfig.d.ts +4 -0
  60. package/dist/features/stack/domain/resolveEffectiveStackConfig.d.ts.map +1 -0
  61. package/dist/features/stack/domain/resolveEffectiveStackConfig.js +6 -0
  62. package/dist/features/stack/domain/resolveEffectiveStackConfig.js.map +1 -0
  63. package/dist/features/stack/domain/resolveEffectiveStackConfigSource.d.ts +9 -0
  64. package/dist/features/stack/domain/resolveEffectiveStackConfigSource.d.ts.map +1 -0
  65. package/dist/{expo-router/resolveNavigatorConfig.js → features/stack/domain/resolveEffectiveStackConfigSource.js} +20 -46
  66. package/dist/features/stack/domain/resolveEffectiveStackConfigSource.js.map +1 -0
  67. package/dist/features/stack/domain/validateStackRouteOptions.d.ts +4 -0
  68. package/dist/features/stack/domain/validateStackRouteOptions.d.ts.map +1 -0
  69. package/dist/features/stack/domain/validateStackRouteOptions.js +25 -0
  70. package/dist/features/stack/domain/validateStackRouteOptions.js.map +1 -0
  71. package/dist/{tabs → features/tabs/adapters/inbound}/CustomTabsLayout.d.ts +16 -17
  72. package/dist/features/tabs/adapters/inbound/CustomTabsLayout.d.ts.map +1 -0
  73. package/dist/{tabs → features/tabs/adapters/inbound}/CustomTabsLayout.js +62 -61
  74. package/dist/features/tabs/adapters/inbound/CustomTabsLayout.js.map +1 -0
  75. package/dist/features/tabs/adapters/inbound/NativeFontAwesome5Family.d.ts +4 -0
  76. package/dist/features/tabs/adapters/inbound/NativeFontAwesome5Family.d.ts.map +1 -0
  77. package/dist/features/tabs/adapters/inbound/NativeFontAwesome5Family.js +9 -0
  78. package/dist/features/tabs/adapters/inbound/NativeFontAwesome5Family.js.map +1 -0
  79. package/dist/features/tabs/adapters/inbound/NativeFontAwesome6Family.d.ts +4 -0
  80. package/dist/features/tabs/adapters/inbound/NativeFontAwesome6Family.d.ts.map +1 -0
  81. package/dist/features/tabs/adapters/inbound/NativeFontAwesome6Family.js +9 -0
  82. package/dist/features/tabs/adapters/inbound/NativeFontAwesome6Family.js.map +1 -0
  83. package/dist/features/tabs/adapters/inbound/NativeFontAwesomeFamily.d.ts +4 -0
  84. package/dist/features/tabs/adapters/inbound/NativeFontAwesomeFamily.d.ts.map +1 -0
  85. package/dist/features/tabs/adapters/inbound/NativeFontAwesomeFamily.js +4 -0
  86. package/dist/features/tabs/adapters/inbound/NativeFontAwesomeFamily.js.map +1 -0
  87. package/dist/features/tabs/adapters/inbound/NativeIoniconsFamily.d.ts +4 -0
  88. package/dist/features/tabs/adapters/inbound/NativeIoniconsFamily.d.ts.map +1 -0
  89. package/dist/features/tabs/adapters/inbound/NativeIoniconsFamily.js +4 -0
  90. package/dist/features/tabs/adapters/inbound/NativeIoniconsFamily.js.map +1 -0
  91. package/dist/features/tabs/adapters/inbound/NativeMaterialDesignIconsFamily.d.ts +4 -0
  92. package/dist/features/tabs/adapters/inbound/NativeMaterialDesignIconsFamily.d.ts.map +1 -0
  93. package/dist/features/tabs/adapters/inbound/NativeMaterialDesignIconsFamily.js +4 -0
  94. package/dist/features/tabs/adapters/inbound/NativeMaterialDesignIconsFamily.js.map +1 -0
  95. package/dist/{generation → features/tabs/adapters/outbound}/generateTabsLayoutFile.d.ts +1 -1
  96. package/dist/features/tabs/adapters/outbound/generateTabsLayoutFile.d.ts.map +1 -0
  97. package/dist/{generation → features/tabs/adapters/outbound}/generateTabsLayoutFile.js +95 -92
  98. package/dist/features/tabs/adapters/outbound/generateTabsLayoutFile.js.map +1 -0
  99. package/dist/features/tabs/application/createTabsAdapter.d.ts +4 -0
  100. package/dist/features/tabs/application/createTabsAdapter.d.ts.map +1 -0
  101. package/dist/features/tabs/application/createTabsAdapter.js +18 -0
  102. package/dist/features/tabs/application/createTabsAdapter.js.map +1 -0
  103. package/dist/{expo-router → features/tabs/application}/resolveTabsNavigatorPlan.d.ts +1 -2
  104. package/dist/features/tabs/application/resolveTabsNavigatorPlan.d.ts.map +1 -0
  105. package/dist/{expo-router → features/tabs/application}/resolveTabsNavigatorPlan.js +41 -41
  106. package/dist/features/tabs/application/resolveTabsNavigatorPlan.js.map +1 -0
  107. package/dist/features/tabs/application/resolveTabsPlan.d.ts +4 -0
  108. package/dist/features/tabs/application/resolveTabsPlan.d.ts.map +1 -0
  109. package/dist/features/tabs/application/resolveTabsPlan.js +14 -0
  110. package/dist/features/tabs/application/resolveTabsPlan.js.map +1 -0
  111. package/dist/{validation/validateTabsNavigator.d.ts → features/tabs/domain/addTabsAdapterDiagnostics.d.ts} +2 -3
  112. package/dist/features/tabs/domain/addTabsAdapterDiagnostics.d.ts.map +1 -0
  113. package/dist/{validation/validateTabsNavigator.js → features/tabs/domain/addTabsAdapterDiagnostics.js} +47 -47
  114. package/dist/features/tabs/domain/addTabsAdapterDiagnostics.js.map +1 -0
  115. package/dist/features/tabs/domain/resolveCustomTabsPresentation.d.ts +4 -0
  116. package/dist/features/tabs/domain/resolveCustomTabsPresentation.d.ts.map +1 -0
  117. package/dist/{presentation → features/tabs/domain}/resolveCustomTabsPresentation.js +16 -16
  118. package/dist/features/tabs/domain/resolveCustomTabsPresentation.js.map +1 -0
  119. package/dist/features/tabs/domain/resolveEffectiveTabsConfig.d.ts +4 -0
  120. package/dist/features/tabs/domain/resolveEffectiveTabsConfig.d.ts.map +1 -0
  121. package/dist/features/tabs/domain/resolveEffectiveTabsConfig.js +24 -0
  122. package/dist/features/tabs/domain/resolveEffectiveTabsConfig.js.map +1 -0
  123. package/dist/features/tabs/nativeIcons.d.ts +6 -0
  124. package/dist/features/tabs/nativeIcons.d.ts.map +1 -0
  125. package/dist/features/tabs/nativeIcons.js +6 -0
  126. package/dist/features/tabs/nativeIcons.js.map +1 -0
  127. package/dist/features/tabs/tabs.d.ts +2 -0
  128. package/dist/features/tabs/tabs.d.ts.map +1 -0
  129. package/dist/features/tabs/tabs.js +2 -0
  130. package/dist/features/tabs/tabs.js.map +1 -0
  131. package/dist/navigator.d.ts +8 -0
  132. package/dist/navigator.d.ts.map +1 -0
  133. package/dist/navigator.js +8 -0
  134. package/dist/navigator.js.map +1 -0
  135. package/dist/types/nativeIcons.d.ts +5 -0
  136. package/dist/types/nativeIcons.d.ts.map +1 -0
  137. package/dist/types/nativeIcons.js +2 -0
  138. package/dist/types/nativeIcons.js.map +1 -0
  139. package/dist/{metadata/index.d.ts → utils/NAVIGATOR_PACKAGE_METADATA.d.ts} +1 -1
  140. package/dist/utils/NAVIGATOR_PACKAGE_METADATA.d.ts.map +1 -0
  141. package/dist/{metadata/index.js → utils/NAVIGATOR_PACKAGE_METADATA.js} +1 -1
  142. package/dist/utils/NAVIGATOR_PACKAGE_METADATA.js.map +1 -0
  143. package/dist/utils/createNavigatorPlan.d.ts +4 -0
  144. package/dist/utils/createNavigatorPlan.d.ts.map +1 -0
  145. package/dist/{expo-router → utils}/createNavigatorPlan.js +67 -140
  146. package/dist/utils/createNavigatorPlan.js.map +1 -0
  147. package/dist/{generation → utils}/generateNavigatorFiles.d.ts +1 -1
  148. package/dist/utils/generateNavigatorFiles.d.ts.map +1 -0
  149. package/dist/{generation → utils}/generateNavigatorFiles.js +160 -154
  150. package/dist/utils/generateNavigatorFiles.js.map +1 -0
  151. package/dist/utils/parseExpoRouterMajor.d.ts +3 -0
  152. package/dist/utils/parseExpoRouterMajor.d.ts.map +1 -0
  153. package/dist/utils/parseExpoRouterMajor.js +6 -0
  154. package/dist/utils/parseExpoRouterMajor.js.map +1 -0
  155. package/dist/utils/resolveNavigatorPreset.d.ts.map +1 -0
  156. package/dist/utils/resolveNavigatorPreset.js.map +1 -0
  157. package/dist/utils/validateNavigatorManifest.d.ts +4 -0
  158. package/dist/utils/validateNavigatorManifest.d.ts.map +1 -0
  159. package/dist/{validation → utils}/validateNavigatorManifest.js +53 -92
  160. package/dist/utils/validateNavigatorManifest.js.map +1 -0
  161. package/dist/{validation → utils}/validatePresetTopology.d.ts +1 -2
  162. package/dist/utils/validatePresetTopology.d.ts.map +1 -0
  163. package/dist/{validation → utils}/validatePresetTopology.js +1 -1
  164. package/dist/utils/validatePresetTopology.js.map +1 -0
  165. package/package.json +16 -15
  166. package/dist/custom/CustomNavigatorRegistry.d.ts +0 -25
  167. package/dist/custom/CustomNavigatorRegistry.d.ts.map +0 -1
  168. package/dist/custom/CustomNavigatorRegistry.js.map +0 -1
  169. package/dist/definitions/NavigatorPlan.d.ts +0 -119
  170. package/dist/definitions/NavigatorPlan.d.ts.map +0 -1
  171. package/dist/definitions/NavigatorPlan.js +0 -2
  172. package/dist/definitions/NavigatorPlan.js.map +0 -1
  173. package/dist/expo-router/createNavigatorPlan.d.ts +0 -12
  174. package/dist/expo-router/createNavigatorPlan.d.ts.map +0 -1
  175. package/dist/expo-router/createNavigatorPlan.js.map +0 -1
  176. package/dist/expo-router/resolveCustomNavigatorPlan.d.ts.map +0 -1
  177. package/dist/expo-router/resolveCustomNavigatorPlan.js.map +0 -1
  178. package/dist/expo-router/resolveNavigatorConfig.d.ts +0 -13
  179. package/dist/expo-router/resolveNavigatorConfig.d.ts.map +0 -1
  180. package/dist/expo-router/resolveNavigatorConfig.js.map +0 -1
  181. package/dist/expo-router/resolveSplitViewNavigatorPlan.d.ts.map +0 -1
  182. package/dist/expo-router/resolveSplitViewNavigatorPlan.js.map +0 -1
  183. package/dist/expo-router/resolveTabsNavigatorPlan.d.ts.map +0 -1
  184. package/dist/expo-router/resolveTabsNavigatorPlan.js.map +0 -1
  185. package/dist/generation/generateNavigatorFiles.d.ts.map +0 -1
  186. package/dist/generation/generateNavigatorFiles.js.map +0 -1
  187. package/dist/generation/generateSplitViewLayoutFile.d.ts.map +0 -1
  188. package/dist/generation/generateSplitViewLayoutFile.js.map +0 -1
  189. package/dist/generation/generateTabsLayoutFile.d.ts.map +0 -1
  190. package/dist/generation/generateTabsLayoutFile.js.map +0 -1
  191. package/dist/generation/generationSafety.d.ts +0 -10
  192. package/dist/generation/generationSafety.d.ts.map +0 -1
  193. package/dist/generation/generationSafety.js +0 -54
  194. package/dist/generation/generationSafety.js.map +0 -1
  195. package/dist/index.d.ts +0 -12
  196. package/dist/index.d.ts.map +0 -1
  197. package/dist/index.js +0 -8
  198. package/dist/index.js.map +0 -1
  199. package/dist/metadata/index.d.ts.map +0 -1
  200. package/dist/metadata/index.js.map +0 -1
  201. package/dist/presentation/resolveCustomTabsPresentation.d.ts +0 -9
  202. package/dist/presentation/resolveCustomTabsPresentation.d.ts.map +0 -1
  203. package/dist/presentation/resolveCustomTabsPresentation.js.map +0 -1
  204. package/dist/tabs/CustomTabsLayout.d.ts.map +0 -1
  205. package/dist/tabs/CustomTabsLayout.js.map +0 -1
  206. package/dist/tabs/index.d.ts +0 -3
  207. package/dist/tabs/index.d.ts.map +0 -1
  208. package/dist/tabs/index.js +0 -2
  209. package/dist/tabs/index.js.map +0 -1
  210. package/dist/tabs/nativeIconFamilies.d.ts +0 -16
  211. package/dist/tabs/nativeIconFamilies.d.ts.map +0 -1
  212. package/dist/tabs/nativeIconFamilies.js +0 -24
  213. package/dist/tabs/nativeIconFamilies.js.map +0 -1
  214. package/dist/topology/resolveNavigatorPreset.d.ts.map +0 -1
  215. package/dist/topology/resolveNavigatorPreset.js.map +0 -1
  216. package/dist/validation/validateCustomNavigator.d.ts.map +0 -1
  217. package/dist/validation/validateCustomNavigator.js.map +0 -1
  218. package/dist/validation/validateExperimentalStack.d.ts.map +0 -1
  219. package/dist/validation/validateExperimentalStack.js.map +0 -1
  220. package/dist/validation/validateNavigatorManifest.d.ts +0 -6
  221. package/dist/validation/validateNavigatorManifest.d.ts.map +0 -1
  222. package/dist/validation/validateNavigatorManifest.js.map +0 -1
  223. package/dist/validation/validatePresetTopology.d.ts.map +0 -1
  224. package/dist/validation/validatePresetTopology.js.map +0 -1
  225. package/dist/validation/validateSplitView.d.ts.map +0 -1
  226. package/dist/validation/validateSplitView.js.map +0 -1
  227. package/dist/validation/validateTabsNavigator.d.ts.map +0 -1
  228. package/dist/validation/validateTabsNavigator.js.map +0 -1
  229. /package/dist/{topology → utils}/resolveNavigatorPreset.d.ts +0 -0
  230. /package/dist/{topology → utils}/resolveNavigatorPreset.js +0 -0
@@ -1,88 +1,81 @@
1
- import { validateNavigatorManifest } from '../validation/validateNavigatorManifest';
2
- import { resolveCustomNavigatorAdapterPlan } from './resolveCustomNavigatorPlan';
3
- import { parseExpoRouterMajor, resolveEffectiveStackConfig, resolveEffectiveTabsConfig, } from './resolveNavigatorConfig';
4
- import { resolveSplitViewAdapterPlan } from './resolveSplitViewNavigatorPlan';
5
- import { resolveTabsNavigatorPlan } from './resolveTabsNavigatorPlan';
6
- /*** Resolve a Stack implementation to its version- and platform-aware Expo Router adapter. */
7
- function createStackAdapter(stack, platform, routerMajor) {
8
- const implementation = stack?.implementation ?? 'native';
9
- if (implementation === 'javascript') {
10
- return {
11
- id: 'stack.javascript',
12
- module: 'expo-router/js-stack',
13
- exportName: 'Stack',
14
- support: routerMajor !== undefined && routerMajor >= 56 ? 'supported' : 'unavailable',
15
- stability: 'stable',
16
- limitations: ['Requires Expo Router 56.0.0 or newer.'],
17
- };
18
- }
19
- if (implementation === 'experimental') {
20
- return {
21
- id: 'stack.experimental',
22
- module: 'expo-router',
23
- exportName: 'ExperimentalStack',
24
- support: routerMajor !== undefined && routerMajor >= 56 ? 'supported' : 'unavailable',
25
- stability: 'alpha',
26
- limitations: platform === 'web'
27
- ? ['Testing-only API; Expo Router falls back to the standard Stack on web.']
28
- : [
29
- 'Testing-only API; supports only title and header visibility options.',
30
- ...(platform === 'android'
31
- ? [
32
- 'Cannot coexist with the standard native Stack on Android.',
33
- 'Requires android.predictiveBackGestureEnabled in app config.',
34
- ]
35
- : []),
36
- ],
37
- };
38
- }
1
+ import { resolveCustomNavigatorAdapterPlan } from '../features/custom/application/resolveCustomNavigatorAdapterPlan';
2
+ import { createDrawerAdapter } from '../features/drawer/application/createDrawerAdapter';
3
+ import { createSlotAdapter } from '../features/slot/application/createSlotAdapter';
4
+ import { resolveSplitViewAdapterPlan } from '../features/split-view/application/resolveSplitViewAdapterPlan';
5
+ import { createStackAdapter } from '../features/stack/application/createStackAdapter';
6
+ import { resolveEffectiveStackConfig } from '../features/stack/domain/resolveEffectiveStackConfig';
7
+ import { createTabsAdapter } from '../features/tabs/application/createTabsAdapter';
8
+ import { resolveTabsPlan } from '../features/tabs/application/resolveTabsPlan';
9
+ import { resolveEffectiveTabsConfig } from '../features/tabs/domain/resolveEffectiveTabsConfig';
10
+ import { parseExpoRouterMajor } from './parseExpoRouterMajor';
11
+ import { validateNavigatorManifest } from './validateNavigatorManifest';
12
+ /*** Create a disposable, provider-aware plan from only the navigator desired-state slice. */
13
+ export function createNavigatorPlan(manifest, options) {
14
+ const context = {
15
+ platform: options.platform,
16
+ expoRouterVersion: options.expoRouterVersion,
17
+ };
18
+ const diagnostics = validateNavigatorManifest(manifest, context, options.customNavigators);
19
+ const root = createNodePlan(manifest, manifest, '', options, options.responsiveSize ?? 'compact');
39
20
  return {
40
- id: 'stack.native',
41
- module: 'expo-router',
42
- exportName: 'Stack',
43
- support: 'supported',
44
- stability: 'stable',
45
- limitations: [],
21
+ context,
22
+ root,
23
+ diagnostics,
24
+ supported: diagnostics.every((diagnostic) => diagnostic.severity !== 'error') &&
25
+ root.adapter.support === 'supported',
26
+ flows: {
27
+ onboarding: manifest.flows?.onboarding ?? false,
28
+ authentication: manifest.flows?.authentication ?? false,
29
+ },
46
30
  };
47
31
  }
48
- function createTabsAdapter(tabs, platform, routerMajor) {
49
- const nativeUnavailable = tabs.implementation === 'native' &&
50
- (platform === 'web' || routerMajor === undefined || routerMajor < 54);
32
+ /*** Resolve a node and its descendants using one platform and responsive-size context. */
33
+ function createNodePlan(manifest, node, pointer, options, responsiveSize) {
34
+ const stack = node.type === 'stack'
35
+ ? resolveEffectiveStackConfig(manifest, node, options.platform)
36
+ : undefined;
37
+ const tabs = node.type === 'tabs'
38
+ ? resolveTabsPlan(resolveEffectiveTabsConfig(manifest, node, options.platform), options.platform, responsiveSize)
39
+ : undefined;
40
+ const routes = node.routes.map((route, index) => createRoutePlan(manifest, route, `${pointer}/routes/${index}`, options, responsiveSize));
51
41
  return {
52
- id: `tabs.${tabs.implementation}`,
53
- module: tabs.module,
54
- exportName: tabs.exportName,
55
- support: nativeUnavailable ? 'unavailable' : 'supported',
56
- stability: tabs.stability,
57
- limitations: tabs.implementation === 'native'
58
- ? ['Alpha API; unavailable on web and requires Expo Router 54.0.0 or newer.']
59
- : tabs.implementation === 'custom'
60
- ? ['Surface presentation over Expo Router headless tabs.']
61
- : [],
42
+ type: node.type,
43
+ pointer,
44
+ adapter: createAdapter(node, stack, tabs, options.platform, parseExpoRouterMajor(options.expoRouterVersion), options.customNavigators),
45
+ ...(node.initialRouteName === undefined ? {} : { initialRouteName: node.initialRouteName }),
46
+ routes,
47
+ ...createNodeDetails(node, stack, tabs),
48
+ };
49
+ }
50
+ /*** Preserve portable route metadata and recursively plan a nested navigator when present. */
51
+ function createRoutePlan(manifest, route, pointer, options, responsiveSize) {
52
+ return {
53
+ name: route.name,
54
+ ...(route.path === undefined ? {} : { path: route.path }),
55
+ ...(route.label === undefined ? {} : { label: route.label }),
56
+ ...(route.icon === undefined ? {} : { icon: route.icon }),
57
+ ...(route.showInPrimaryNavigation === undefined
58
+ ? {}
59
+ : { showInPrimaryNavigation: route.showInPrimaryNavigation }),
60
+ guards: route.guards ?? [],
61
+ ...(route.screenId === undefined ? {} : { screenId: route.screenId }),
62
+ ...(route.stackOptions === undefined ? {} : { stackOptions: route.stackOptions }),
63
+ ...(route.navigator === undefined
64
+ ? {}
65
+ : {
66
+ navigator: createNodePlan(manifest, route.navigator, `${pointer}/navigator`, options, responsiveSize),
67
+ }),
62
68
  };
63
69
  }
70
+ /*** Dispatch adapter planning to the feature that owns the authored navigator type. */
64
71
  function createAdapter(node, stack, tabs, platform, routerMajor, customNavigators) {
65
72
  switch (node.type) {
66
73
  case 'slot':
67
- return {
68
- id: 'slot',
69
- module: 'expo-router',
70
- exportName: 'Slot',
71
- support: 'supported',
72
- stability: 'stable',
73
- limitations: [],
74
- };
74
+ return createSlotAdapter();
75
75
  case 'stack':
76
76
  return createStackAdapter(stack, platform, routerMajor);
77
77
  case 'drawer':
78
- return {
79
- id: 'drawer',
80
- module: 'expo-router/drawer',
81
- exportName: 'Drawer',
82
- support: 'supported',
83
- stability: 'stable',
84
- limitations: [],
85
- };
78
+ return createDrawerAdapter();
86
79
  case 'tabs':
87
80
  if (tabs === undefined)
88
81
  throw new Error('Tabs planning did not resolve an adapter.');
@@ -93,17 +86,7 @@ function createAdapter(node, stack, tabs, platform, routerMajor, customNavigator
93
86
  return resolveCustomNavigatorAdapterPlan(node, platform, routerMajor, customNavigators);
94
87
  }
95
88
  }
96
- function resolveTabsPlan(config, platform, responsiveSize) {
97
- if (config?.implementation === 'native' && platform === 'web') {
98
- return {
99
- implementation: 'native',
100
- module: 'expo-router/unstable-native-tabs',
101
- exportName: 'NativeTabs',
102
- stability: 'alpha',
103
- };
104
- }
105
- return resolveTabsNavigatorPlan(config, platform, responsiveSize);
106
- }
89
+ /*** Project each navigator's resolved configuration onto the shared recursive plan. */
107
90
  function createNodeDetails(node, stack, tabs) {
108
91
  switch (node.type) {
109
92
  case 'stack':
@@ -143,60 +126,4 @@ function createNodeDetails(node, stack, tabs) {
143
126
  return {};
144
127
  }
145
128
  }
146
- function createRoutePlan(manifest, route, pointer, options, responsiveSize) {
147
- return {
148
- name: route.name,
149
- ...(route.path === undefined ? {} : { path: route.path }),
150
- ...(route.label === undefined ? {} : { label: route.label }),
151
- ...(route.icon === undefined ? {} : { icon: route.icon }),
152
- ...(route.showInPrimaryNavigation === undefined
153
- ? {}
154
- : { showInPrimaryNavigation: route.showInPrimaryNavigation }),
155
- guards: route.guards ?? [],
156
- ...(route.screenId === undefined ? {} : { screenId: route.screenId }),
157
- ...(route.stackOptions === undefined ? {} : { stackOptions: route.stackOptions }),
158
- ...(route.navigator === undefined
159
- ? {}
160
- : {
161
- navigator: createNodePlan(manifest, route.navigator, `${pointer}/navigator`, options, responsiveSize),
162
- }),
163
- };
164
- }
165
- function createNodePlan(manifest, node, pointer, options, responsiveSize) {
166
- const stack = node.type === 'stack'
167
- ? resolveEffectiveStackConfig(manifest, node, options.platform)
168
- : undefined;
169
- const tabs = node.type === 'tabs'
170
- ? resolveTabsPlan(resolveEffectiveTabsConfig(manifest, node, options.platform), options.platform, responsiveSize)
171
- : undefined;
172
- const routes = node.routes.map((route, index) => createRoutePlan(manifest, route, `${pointer}/routes/${index}`, options, responsiveSize));
173
- return {
174
- type: node.type,
175
- pointer,
176
- adapter: createAdapter(node, stack, tabs, options.platform, parseExpoRouterMajor(options.expoRouterVersion), options.customNavigators),
177
- ...(node.initialRouteName === undefined ? {} : { initialRouteName: node.initialRouteName }),
178
- routes,
179
- ...createNodeDetails(node, stack, tabs),
180
- };
181
- }
182
- /*** Create a disposable, provider-aware plan from only the navigator desired-state slice. */
183
- export function createNavigatorPlan(manifest, options) {
184
- const context = {
185
- platform: options.platform,
186
- expoRouterVersion: options.expoRouterVersion,
187
- };
188
- const diagnostics = validateNavigatorManifest(manifest, context, options.customNavigators);
189
- const root = createNodePlan(manifest, manifest, '', options, options.responsiveSize ?? 'compact');
190
- return {
191
- context,
192
- root,
193
- diagnostics,
194
- supported: diagnostics.every((diagnostic) => diagnostic.severity !== 'error') &&
195
- root.adapter.support === 'supported',
196
- flows: {
197
- onboarding: manifest.flows?.onboarding ?? false,
198
- authentication: manifest.flows?.authentication ?? false,
199
- },
200
- };
201
- }
202
129
  //# sourceMappingURL=createNavigatorPlan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNavigatorPlan.js","sourceRoot":"","sources":["../../src/utils/createNavigatorPlan.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iCAAiC,EAAE,MAAM,kEAAkE,CAAC;AACrH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,gEAAgE,CAAC;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,sDAAsD,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,oDAAoD,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,6FAA6F;AAC7F,MAAM,UAAU,mBAAmB,CACjC,QAA8B,EAC9B,OAAmC;IAEnC,MAAM,OAAO,GAAG;QACd,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;KACpC,CAAC;IACX,MAAM,WAAW,GAAG,yBAAyB,CAAC,QAAQ,EAA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C,CAAC,EAAE;wBACJ,CAAC,CAAC,EAAE,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,EAAE,CAAC;iBAC7D;aACF,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO;gBACL,MAAM,EAAE;oBACN,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;iBAC9D;aACF,CAAC;QACJ,KAAK,MAAM;YACT,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { NavigatorGeneratedFile, NavigatorGenerationBindings, NavigatorGenerationOptions, NavigatorPlan } from '../definitions/NavigatorPlan';
1
+ import type { NavigatorGeneratedFile, NavigatorGenerationBindings, NavigatorGenerationOptions, NavigatorPlan } from '@ankhorage/contracts/navigator';
2
2
  /*** Generate deterministic Expo Router files from a validated disposable plan and narrow bindings. */
3
3
  export declare function generateNavigatorFiles(plan: NavigatorPlan, bindings: NavigatorGenerationBindings, options?: NavigatorGenerationOptions): readonly NavigatorGeneratedFile[];
4
4
  //# sourceMappingURL=generateNavigatorFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateNavigatorFiles.d.ts","sourceRoot":"","sources":["../../src/utils/generateNavigatorFiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,2BAA2B,EAC3B,0BAA0B,EAE1B,aAAa,EAGd,MAAM,gCAAgC,CAAC;AASxC,sGAAsG;AACtG,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,2BAA2B,EACrC,OAAO,GAAE,0BAA+B,GACvC,SAAS,sBAAsB,EAAE,CAsBnC"}
@@ -1,9 +1,53 @@
1
- import { generateSplitViewLayoutFile } from './generateSplitViewLayoutFile';
2
- import { generateTabsLayoutFile } from './generateTabsLayoutFile';
3
- import { assertModuleBinding, quote, quoteJsxAttribute, sourceLiteral } from './generationSafety';
4
- const APP_DIRECTORY = 'src/app';
5
- const SAFE_ROUTE_NAME = /^[A-Za-z0-9_.()[\]-]+$/u;
6
- /** Resolve a safe directory below the Expo Router app root without filesystem normalization. */
1
+ import { quoteJavaScriptString, serializeJavaScriptLiteral } from '@ankhorage/utility/string';
2
+ import { assertStaticImportBinding } from '@ankhorage/utility/validation';
3
+ import { resolveDrawerRouteOptions } from '../features/drawer/adapters/outbound/resolveDrawerRouteOptions';
4
+ import { generateSlotLayoutFile } from '../features/slot/adapters/outbound/generateSlotLayoutFile';
5
+ import { generateSplitViewLayoutFile } from '../features/split-view/adapters/outbound/generateSplitViewLayoutFile';
6
+ import { generateTabsLayoutFile } from '../features/tabs/adapters/outbound/generateTabsLayoutFile';
7
+ /*** Generate deterministic Expo Router files from a validated disposable plan and narrow bindings. */
8
+ export function generateNavigatorFiles(plan, bindings, options = {}) {
9
+ const errors = plan.diagnostics.filter((diagnostic) => diagnostic.severity === 'error');
10
+ if (!plan.supported || errors.length > 0) {
11
+ throw new Error(`Cannot generate an unsupported navigator plan: ${errors.map((error) => error.code).join(', ') || 'adapter unavailable'}.`);
12
+ }
13
+ validateFlowBindings(plan, bindings);
14
+ const rootDirectory = resolveRootDirectory(options.rootDirectory);
15
+ const files = collectFiles(plan.root, rootDirectory, bindings, options.includeScreenFiles ?? true).sort((left, right) => left.path.localeCompare(right.path));
16
+ const paths = new Set();
17
+ for (const file of files) {
18
+ if (paths.has(file.path))
19
+ throw new Error(`Generated file path ${JSON.stringify(file.path)} is duplicated.`);
20
+ paths.add(file.path);
21
+ }
22
+ return files;
23
+ }
24
+ /*** Require enabled onboarding and authentication flows to reference an existing route. */
25
+ function validateFlowBindings(plan, bindings) {
26
+ const routeIds = new Set(collectRouteIds(plan.root));
27
+ for (const [enabled, routeId, name] of [
28
+ [plan.flows.onboarding, bindings.flows?.onboardingRoute, 'onboarding'],
29
+ [plan.flows.authentication, bindings.flows?.authenticationRoute, 'authentication'],
30
+ ]) {
31
+ if (!enabled)
32
+ continue;
33
+ if (routeId === undefined)
34
+ throw new Error(`Missing ${name} flow-route binding.`);
35
+ if (!routeIds.has(routeId)) {
36
+ throw new Error(`${name[0]?.toUpperCase()}${name.slice(1)} flow route ${JSON.stringify(routeId)} does not exist.`);
37
+ }
38
+ }
39
+ }
40
+ /*** Collect nested route identifiers without changing their authored segment names. */
41
+ function collectRouteIds(node, parent = []) {
42
+ return node.routes.flatMap((route) => {
43
+ const segments = [...parent, route.name];
44
+ const routeId = segments.join('/');
45
+ return route.navigator === undefined
46
+ ? [routeId]
47
+ : [routeId, ...collectRouteIds(route.navigator, segments)];
48
+ });
49
+ }
50
+ /*** Resolve a safe directory below the Expo Router app root without filesystem normalization. */
7
51
  function resolveRootDirectory(rootDirectory) {
8
52
  const directory = rootDirectory ?? APP_DIRECTORY;
9
53
  const segments = directory.split('/');
@@ -16,80 +60,67 @@ function resolveRootDirectory(rootDirectory) {
16
60
  }
17
61
  return directory;
18
62
  }
19
- function assertRouteName(name) {
20
- if (!SAFE_ROUTE_NAME.test(name) || name === '.' || name === '..') {
21
- throw new Error(`Route name ${JSON.stringify(name)} is not a safe generated file segment.`);
22
- }
23
- }
24
- function routeOptions(node, route) {
25
- const options = {};
26
- if (route.label !== undefined)
27
- options.title = route.label;
28
- if (node.type === 'stack' && route.stackOptions !== undefined) {
29
- Object.assign(options, route.stackOptions);
30
- }
31
- if (node.type === 'drawer') {
32
- if (route.label !== undefined)
33
- options.drawerLabel = route.label;
34
- if (route.showInPrimaryNavigation === false) {
35
- options.drawerItemStyle = { display: 'none' };
63
+ const APP_DIRECTORY = 'src/app';
64
+ const SAFE_ROUTE_NAME = /^[A-Za-z0-9_.()[\]-]+$/u;
65
+ /*** Traverse the plan to emit layouts and optional screen bindings in their route directories. */
66
+ function collectFiles(node, directory, bindings, includeScreenFiles) {
67
+ const files = [createLayoutFile(node, directory, bindings)];
68
+ for (const route of node.routes) {
69
+ assertRouteName(route.name);
70
+ if (includeScreenFiles) {
71
+ const screen = createScreenFile(route, directory, bindings);
72
+ if (screen !== undefined)
73
+ files.push(screen);
74
+ }
75
+ if (route.navigator !== undefined) {
76
+ files.push(...collectFiles(route.navigator, `${directory}/${route.name}`, bindings, includeScreenFiles));
36
77
  }
37
78
  }
38
- if (node.type === 'tabs' &&
39
- node.tabs?.implementation === 'javascript' &&
40
- route.showInPrimaryNavigation === false) {
41
- if (node.tabs.presentation === 'top')
42
- options.tabBarItemStyle = { display: 'none' };
43
- else
44
- options.href = null;
45
- }
46
- return Object.keys(options).length === 0 ? undefined : options;
79
+ return files;
47
80
  }
48
- /*** Render one generated Screen with a stable multiline options object when route options exist. */
49
- function renderScreenElement(componentName, routeName, options, indentation) {
50
- if (options === undefined) {
51
- return `${indentation}<${componentName}.Screen name=${quoteJsxAttribute(routeName)} />`;
81
+ /*** Dispatch specialized layout generation or render the shared Screen-registration contract. */
82
+ function createLayoutFile(node, directory, bindings) {
83
+ if (node.adapter.support !== 'supported' ||
84
+ node.adapter.module === undefined ||
85
+ node.adapter.exportName === undefined) {
86
+ throw new Error(`Cannot generate unavailable navigator adapter ${JSON.stringify(node.adapter.id)} at ${node.pointer || '/'}.`);
52
87
  }
53
- const optionLines = Object.entries(options)
54
- .filter(([, value]) => value !== undefined)
55
- .map(([key, value]) => `${indentation} ${key}: ${sourceLiteral(value)},`)
56
- .join('\n');
57
- return `${indentation}<${componentName}.Screen
58
- ${indentation} name=${quoteJsxAttribute(routeName)}
59
- ${indentation} options={{
60
- ${optionLines}
61
- ${indentation} }}
62
- ${indentation}/>`;
63
- }
64
- function renderScreen(componentName, node, route, guardAliases) {
65
- const options = routeOptions(node, route);
66
- const screen = renderScreenElement(componentName, route.name, options, route.guards.length === 0 ? ' ' : ' ');
67
- if (route.guards.length === 0)
68
- return screen;
69
- const guardExpression = route.guards
70
- .map((guard) => {
71
- const alias = guardAliases.get(guard);
72
- if (alias === undefined)
73
- throw new Error(`Missing generated guard alias for ${JSON.stringify(guard)}.`);
74
- return `${alias}()`;
75
- })
76
- .join(' && ');
77
- return ` <${componentName}.Protected guard={${guardExpression}}>
78
- ${screen}
79
- </${componentName}.Protected>`;
88
+ const tabsLayout = generateTabsLayoutFile(node, directory, bindings);
89
+ if (tabsLayout !== undefined)
90
+ return tabsLayout;
91
+ const splitViewLayout = generateSplitViewLayoutFile(node, directory, bindings);
92
+ if (splitViewLayout !== undefined)
93
+ return splitViewLayout;
94
+ const componentName = node.adapter.exportName;
95
+ assertStaticImportBinding(node.adapter.module, componentName, `Adapter ${JSON.stringify(node.adapter.id)}`);
96
+ const guardAliases = new Map();
97
+ const guardImports = createGuardImports(node, bindings, guardAliases);
98
+ const imports = [
99
+ `import { ${componentName} } from ${quoteJavaScriptString(node.adapter.module)};`,
100
+ ...(guardImports.length > 0 ? ['', ...guardImports] : []),
101
+ ].join('\n');
102
+ if (node.type === 'slot') {
103
+ return generateSlotLayoutFile(directory, componentName, imports);
104
+ }
105
+ return {
106
+ path: `${directory}/_layout.tsx`,
107
+ contents: createNavigatorContents(node, componentName, imports, guardAliases),
108
+ };
80
109
  }
110
+ /*** Validate and alias every distinct guard binding used by a navigator's routes. */
81
111
  function createGuardImports(node, bindings, guardAliases) {
82
112
  const guards = [...new Set(node.routes.flatMap((route) => route.guards))].sort();
83
113
  return guards.map((guard, index) => {
84
114
  const binding = Reflect.get(bindings.guards, guard);
85
115
  if (binding === undefined)
86
116
  throw new Error(`Missing guard binding for ${JSON.stringify(guard)}.`);
87
- assertModuleBinding(binding, `Guard ${JSON.stringify(guard)}`);
117
+ assertStaticImportBinding(binding.module, binding.exportName, `Guard ${JSON.stringify(guard)}`);
88
118
  const alias = `navigatorGuard${index}`;
89
119
  guardAliases.set(guard, alias);
90
- return `import { ${binding.exportName} as ${alias} } from ${quote(binding.module)};`;
120
+ return `import { ${binding.exportName} as ${alias} } from ${quoteJavaScriptString(binding.module)};`;
91
121
  });
92
122
  }
123
+ /*** Render navigator options and registered screens using the resolved adapter component. */
93
124
  function createNavigatorContents(node, componentName, imports, guardAliases) {
94
125
  const navigatorOptions = node.type === 'stack'
95
126
  ? node.stack?.options
@@ -99,12 +130,12 @@ function createNavigatorContents(node, componentName, imports, guardAliases) {
99
130
  const props = [
100
131
  node.initialRouteName === undefined
101
132
  ? undefined
102
- : `initialRouteName=${quoteJsxAttribute(node.initialRouteName)}`,
133
+ : `initialRouteName=${JSON.stringify(node.initialRouteName)}`,
103
134
  navigatorOptions === undefined
104
135
  ? undefined
105
- : `screenOptions={${sourceLiteral(navigatorOptions)}}`,
136
+ : `screenOptions={${serializeJavaScriptLiteral(navigatorOptions)}}`,
106
137
  node.type === 'custom' && node.custom?.config !== undefined
107
- ? `{...${sourceLiteral(node.custom.config)}}`
138
+ ? `{...${serializeJavaScriptLiteral(node.custom.config)}}`
108
139
  : undefined,
109
140
  ].filter((value) => value !== undefined);
110
141
  const openingTag = `<${componentName}${props.length === 0 ? '' : ` ${props.join(' ')}`}>`;
@@ -113,37 +144,68 @@ function createNavigatorContents(node, componentName, imports, guardAliases) {
113
144
  .join('\n');
114
145
  return `${imports}\n\nexport default function NavigatorLayout() {\n return (\n ${openingTag}\n${screens}\n </${componentName}>\n );\n}\n`;
115
146
  }
116
- function createLayoutFile(node, directory, bindings) {
117
- if (node.adapter.support !== 'supported' ||
118
- node.adapter.module === undefined ||
119
- node.adapter.exportName === undefined) {
120
- throw new Error(`Cannot generate unavailable navigator adapter ${JSON.stringify(node.adapter.id)} at ${node.pointer || '/'}.`);
147
+ /*** Wrap a generated screen in the conjunction of its registered route guards. */
148
+ function renderScreen(componentName, node, route, guardAliases) {
149
+ const options = routeOptions(node, route);
150
+ const screen = renderScreenElement(componentName, route.name, options, route.guards.length === 0 ? ' ' : ' ');
151
+ if (route.guards.length === 0)
152
+ return screen;
153
+ const guardExpression = route.guards
154
+ .map((guard) => {
155
+ const alias = guardAliases.get(guard);
156
+ if (alias === undefined)
157
+ throw new Error(`Missing generated guard alias for ${JSON.stringify(guard)}.`);
158
+ return `${alias}()`;
159
+ })
160
+ .join(' && ');
161
+ return ` <${componentName}.Protected guard={${guardExpression}}>
162
+ ${screen}
163
+ </${componentName}.Protected>`;
164
+ }
165
+ /*** Merge route labels with the owning adapter's screen-option mapping. */
166
+ function routeOptions(node, route) {
167
+ const options = {};
168
+ if (route.label !== undefined)
169
+ options.title = route.label;
170
+ if (node.type === 'stack' && route.stackOptions !== undefined) {
171
+ Object.assign(options, route.stackOptions);
121
172
  }
122
- const tabsLayout = generateTabsLayoutFile(node, directory, bindings);
123
- if (tabsLayout !== undefined)
124
- return tabsLayout;
125
- const splitViewLayout = generateSplitViewLayoutFile(node, directory, bindings);
126
- if (splitViewLayout !== undefined)
127
- return splitViewLayout;
128
- const componentName = node.adapter.exportName;
129
- assertModuleBinding({ module: node.adapter.module, exportName: componentName }, `Adapter ${JSON.stringify(node.adapter.id)}`);
130
- const guardAliases = new Map();
131
- const guardImports = createGuardImports(node, bindings, guardAliases);
132
- const imports = [
133
- `import { ${componentName} } from ${quote(node.adapter.module)};`,
134
- ...(guardImports.length > 0 ? ['', ...guardImports] : []),
135
- ].join('\n');
136
- if (node.type === 'slot') {
137
- return {
138
- path: `${directory}/_layout.tsx`,
139
- contents: `${imports}\n\nexport default function NavigatorLayout() {\n return <${componentName} />;\n}\n`,
140
- };
173
+ if (node.type === 'drawer') {
174
+ Object.assign(options, resolveDrawerRouteOptions(route));
141
175
  }
142
- return {
143
- path: `${directory}/_layout.tsx`,
144
- contents: createNavigatorContents(node, componentName, imports, guardAliases),
145
- };
176
+ if (node.type === 'tabs' &&
177
+ node.tabs?.implementation === 'javascript' &&
178
+ route.showInPrimaryNavigation === false) {
179
+ if (node.tabs.presentation === 'top')
180
+ options.tabBarItemStyle = { display: 'none' };
181
+ else
182
+ options.href = null;
183
+ }
184
+ return Object.keys(options).length === 0 ? undefined : options;
146
185
  }
186
+ /*** Render one generated Screen with a stable multiline options object when route options exist. */
187
+ function renderScreenElement(componentName, routeName, options, indentation) {
188
+ if (options === undefined) {
189
+ return `${indentation}<${componentName}.Screen name=${JSON.stringify(routeName)} />`;
190
+ }
191
+ const optionLines = Object.entries(options)
192
+ .filter(([, value]) => value !== undefined)
193
+ .map(([key, value]) => `${indentation} ${key}: ${serializeJavaScriptLiteral(value)},`)
194
+ .join('\n');
195
+ return `${indentation}<${componentName}.Screen
196
+ ${indentation} name=${JSON.stringify(routeName)}
197
+ ${indentation} options={{
198
+ ${optionLines}
199
+ ${indentation} }}
200
+ ${indentation}/>`;
201
+ }
202
+ /*** Reject route segments that could escape or invalidate the generated directory. */
203
+ function assertRouteName(name) {
204
+ if (!SAFE_ROUTE_NAME.test(name) || name === '.' || name === '..') {
205
+ throw new Error(`Route name ${JSON.stringify(name)} is not a safe generated file segment.`);
206
+ }
207
+ }
208
+ /*** Emit a route module that re-exports its registered screen as the default component. */
147
209
  function createScreenFile(route, directory, bindings) {
148
210
  if (route.screenId === undefined)
149
211
  return undefined;
@@ -151,66 +213,10 @@ function createScreenFile(route, directory, bindings) {
151
213
  const binding = Reflect.get(bindings.screens, route.screenId);
152
214
  if (binding === undefined)
153
215
  throw new Error(`Missing screen binding for ${JSON.stringify(route.screenId)}.`);
154
- assertModuleBinding(binding, `Screen ${JSON.stringify(route.screenId)}`);
216
+ assertStaticImportBinding(binding.module, binding.exportName, `Screen ${JSON.stringify(route.screenId)}`);
155
217
  return {
156
218
  path: `${directory}/${route.name}.tsx`,
157
- contents: `export { ${binding.exportName} as default } from ${quote(binding.module)};\n`,
219
+ contents: `export { ${binding.exportName} as default } from ${quoteJavaScriptString(binding.module)};\n`,
158
220
  };
159
221
  }
160
- function collectFiles(node, directory, bindings, includeScreenFiles) {
161
- const files = [createLayoutFile(node, directory, bindings)];
162
- for (const route of node.routes) {
163
- assertRouteName(route.name);
164
- if (includeScreenFiles) {
165
- const screen = createScreenFile(route, directory, bindings);
166
- if (screen !== undefined)
167
- files.push(screen);
168
- }
169
- if (route.navigator !== undefined) {
170
- files.push(...collectFiles(route.navigator, `${directory}/${route.name}`, bindings, includeScreenFiles));
171
- }
172
- }
173
- return files;
174
- }
175
- function collectRouteIds(node, parent = []) {
176
- return node.routes.flatMap((route) => {
177
- const segments = [...parent, route.name];
178
- const routeId = segments.join('/');
179
- return route.navigator === undefined
180
- ? [routeId]
181
- : [routeId, ...collectRouteIds(route.navigator, segments)];
182
- });
183
- }
184
- function validateFlowBindings(plan, bindings) {
185
- const routeIds = new Set(collectRouteIds(plan.root));
186
- for (const [enabled, routeId, name] of [
187
- [plan.flows.onboarding, bindings.flows?.onboardingRoute, 'onboarding'],
188
- [plan.flows.authentication, bindings.flows?.authenticationRoute, 'authentication'],
189
- ]) {
190
- if (!enabled)
191
- continue;
192
- if (routeId === undefined)
193
- throw new Error(`Missing ${name} flow-route binding.`);
194
- if (!routeIds.has(routeId)) {
195
- throw new Error(`${name[0]?.toUpperCase()}${name.slice(1)} flow route ${JSON.stringify(routeId)} does not exist.`);
196
- }
197
- }
198
- }
199
- /*** Generate deterministic Expo Router files from a validated disposable plan and narrow bindings. */
200
- export function generateNavigatorFiles(plan, bindings, options = {}) {
201
- const errors = plan.diagnostics.filter((diagnostic) => diagnostic.severity === 'error');
202
- if (!plan.supported || errors.length > 0) {
203
- throw new Error(`Cannot generate an unsupported navigator plan: ${errors.map((error) => error.code).join(', ') || 'adapter unavailable'}.`);
204
- }
205
- validateFlowBindings(plan, bindings);
206
- const rootDirectory = resolveRootDirectory(options.rootDirectory);
207
- const files = collectFiles(plan.root, rootDirectory, bindings, options.includeScreenFiles ?? true).sort((left, right) => left.path.localeCompare(right.path));
208
- const paths = new Set();
209
- for (const file of files) {
210
- if (paths.has(file.path))
211
- throw new Error(`Generated file path ${JSON.stringify(file.path)} is duplicated.`);
212
- paths.add(file.path);
213
- }
214
- return files;
215
- }
216
222
  //# sourceMappingURL=generateNavigatorFiles.js.map