@react-navigation/routers 6.1.5 → 7.0.0-alpha.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 (46) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/BaseRouter.js +11 -18
  3. package/lib/commonjs/BaseRouter.js.map +1 -1
  4. package/lib/commonjs/CommonActions.js +23 -8
  5. package/lib/commonjs/CommonActions.js.map +1 -1
  6. package/lib/commonjs/DrawerRouter.js +13 -45
  7. package/lib/commonjs/DrawerRouter.js.map +1 -1
  8. package/lib/commonjs/StackRouter.js +155 -97
  9. package/lib/commonjs/StackRouter.js.map +1 -1
  10. package/lib/commonjs/TabRouter.js +28 -69
  11. package/lib/commonjs/TabRouter.js.map +1 -1
  12. package/lib/commonjs/index.js +0 -11
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/types.js.map +1 -1
  15. package/lib/module/BaseRouter.js +11 -17
  16. package/lib/module/BaseRouter.js.map +1 -1
  17. package/lib/module/CommonActions.js +22 -4
  18. package/lib/module/CommonActions.js.map +1 -1
  19. package/lib/module/DrawerRouter.js +13 -39
  20. package/lib/module/DrawerRouter.js.map +1 -1
  21. package/lib/module/StackRouter.js +155 -92
  22. package/lib/module/StackRouter.js.map +1 -1
  23. package/lib/module/TabRouter.js +28 -65
  24. package/lib/module/TabRouter.js.map +1 -1
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/types.js.map +1 -1
  27. package/lib/typescript/src/BaseRouter.d.ts +1 -0
  28. package/lib/typescript/src/BaseRouter.d.ts.map +1 -0
  29. package/lib/typescript/src/CommonActions.d.ts +14 -13
  30. package/lib/typescript/src/CommonActions.d.ts.map +1 -0
  31. package/lib/typescript/src/DrawerRouter.d.ts +6 -5
  32. package/lib/typescript/src/DrawerRouter.d.ts.map +1 -0
  33. package/lib/typescript/src/StackRouter.d.ts +24 -5
  34. package/lib/typescript/src/StackRouter.d.ts.map +1 -0
  35. package/lib/typescript/src/TabRouter.d.ts +6 -5
  36. package/lib/typescript/src/TabRouter.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts +1 -0
  38. package/lib/typescript/src/index.d.ts.map +1 -0
  39. package/lib/typescript/src/types.d.ts +15 -14
  40. package/lib/typescript/src/types.d.ts.map +1 -0
  41. package/package.json +5 -5
  42. package/src/BaseRouter.tsx +1 -1
  43. package/src/CommonActions.tsx +48 -28
  44. package/src/DrawerRouter.tsx +2 -1
  45. package/src/StackRouter.tsx +270 -147
  46. package/src/TabRouter.tsx +10 -17
@@ -1,25 +1,22 @@
1
1
  import { nanoid } from 'nanoid/non-secure';
2
2
  import TabRouter, { TabActions } from './TabRouter';
3
- export const DrawerActions = { ...TabActions,
4
-
3
+ export const DrawerActions = {
4
+ ...TabActions,
5
5
  openDrawer() {
6
6
  return {
7
7
  type: 'OPEN_DRAWER'
8
8
  };
9
9
  },
10
-
11
10
  closeDrawer() {
12
11
  return {
13
12
  type: 'CLOSE_DRAWER'
14
13
  };
15
14
  },
16
-
17
15
  toggleDrawer() {
18
16
  return {
19
17
  type: 'TOGGLE_DRAWER'
20
18
  };
21
19
  }
22
-
23
20
  };
24
21
  export default function DrawerRouter(_ref) {
25
22
  let {
@@ -27,55 +24,46 @@ export default function DrawerRouter(_ref) {
27
24
  ...rest
28
25
  } = _ref;
29
26
  const router = TabRouter(rest);
30
-
31
27
  const isDrawerInHistory = state => {
32
28
  var _state$history;
33
-
34
29
  return Boolean((_state$history = state.history) === null || _state$history === void 0 ? void 0 : _state$history.some(it => it.type === 'drawer'));
35
30
  };
36
-
37
31
  const addDrawerToHistory = state => {
38
32
  if (isDrawerInHistory(state)) {
39
33
  return state;
40
34
  }
41
-
42
- return { ...state,
35
+ return {
36
+ ...state,
43
37
  history: [...state.history, {
44
38
  type: 'drawer',
45
39
  status: defaultStatus === 'open' ? 'closed' : 'open'
46
40
  }]
47
41
  };
48
42
  };
49
-
50
43
  const removeDrawerFromHistory = state => {
51
44
  if (!isDrawerInHistory(state)) {
52
45
  return state;
53
46
  }
54
-
55
- return { ...state,
47
+ return {
48
+ ...state,
56
49
  history: state.history.filter(it => it.type !== 'drawer')
57
50
  };
58
51
  };
59
-
60
52
  const openDrawer = state => {
61
53
  if (defaultStatus === 'open') {
62
54
  return removeDrawerFromHistory(state);
63
55
  }
64
-
65
56
  return addDrawerToHistory(state);
66
57
  };
67
-
68
58
  const closeDrawer = state => {
69
59
  if (defaultStatus === 'open') {
70
60
  return addDrawerToHistory(state);
71
61
  }
72
-
73
62
  return removeDrawerFromHistory(state);
74
63
  };
75
-
76
- return { ...router,
64
+ return {
65
+ ...router,
77
66
  type: 'drawer',
78
-
79
67
  getInitialState(_ref2) {
80
68
  let {
81
69
  routeNames,
@@ -87,88 +75,74 @@ export default function DrawerRouter(_ref) {
87
75
  routeParamList,
88
76
  routeGetIdList
89
77
  });
90
- return { ...state,
78
+ return {
79
+ ...state,
91
80
  default: defaultStatus,
92
81
  stale: false,
93
82
  type: 'drawer',
94
83
  key: `drawer-${nanoid()}`
95
84
  };
96
85
  },
97
-
98
86
  getRehydratedState(partialState, _ref3) {
99
87
  let {
100
88
  routeNames,
101
89
  routeParamList,
102
90
  routeGetIdList
103
91
  } = _ref3;
104
-
105
92
  if (partialState.stale === false) {
106
93
  return partialState;
107
94
  }
108
-
109
95
  let state = router.getRehydratedState(partialState, {
110
96
  routeNames,
111
97
  routeParamList,
112
98
  routeGetIdList
113
99
  });
114
-
115
100
  if (isDrawerInHistory(partialState)) {
116
101
  // Re-sync the drawer entry in history to correct it if it was wrong
117
102
  state = removeDrawerFromHistory(state);
118
103
  state = addDrawerToHistory(state);
119
104
  }
120
-
121
- return { ...state,
105
+ return {
106
+ ...state,
122
107
  default: defaultStatus,
123
108
  type: 'drawer',
124
109
  key: `drawer-${nanoid()}`
125
110
  };
126
111
  },
127
-
128
112
  getStateForRouteFocus(state, key) {
129
113
  const result = router.getStateForRouteFocus(state, key);
130
114
  return closeDrawer(result);
131
115
  },
132
-
133
116
  getStateForAction(state, action, options) {
134
117
  switch (action.type) {
135
118
  case 'OPEN_DRAWER':
136
119
  return openDrawer(state);
137
-
138
120
  case 'CLOSE_DRAWER':
139
121
  return closeDrawer(state);
140
-
141
122
  case 'TOGGLE_DRAWER':
142
123
  if (isDrawerInHistory(state)) {
143
124
  return removeDrawerFromHistory(state);
144
125
  }
145
-
146
126
  return addDrawerToHistory(state);
147
-
148
127
  case 'JUMP_TO':
149
128
  case 'NAVIGATE':
129
+ case 'NAVIGATE_DEPRECATED':
150
130
  {
151
131
  const result = router.getStateForAction(state, action, options);
152
-
153
132
  if (result != null && result.index !== state.index) {
154
133
  return closeDrawer(result);
155
134
  }
156
-
157
135
  return result;
158
136
  }
159
-
160
137
  case 'GO_BACK':
161
138
  if (isDrawerInHistory(state)) {
162
139
  return removeDrawerFromHistory(state);
163
140
  }
164
-
165
141
  return router.getStateForAction(state, action, options);
166
-
167
142
  default:
168
143
  return router.getStateForAction(state, action, options);
169
144
  }
170
145
  },
171
-
172
146
  actionCreators: DrawerActions
173
147
  };
174
148
  }
@@ -1 +1 @@
1
- {"version":3,"names":["nanoid","TabRouter","TabActions","DrawerActions","openDrawer","type","closeDrawer","toggleDrawer","DrawerRouter","defaultStatus","rest","router","isDrawerInHistory","state","Boolean","history","some","it","addDrawerToHistory","status","removeDrawerFromHistory","filter","getInitialState","routeNames","routeParamList","routeGetIdList","default","stale","key","getRehydratedState","partialState","getStateForRouteFocus","result","getStateForAction","action","options","index","actionCreators"],"sources":["DrawerRouter.tsx"],"sourcesContent":["import { nanoid } from 'nanoid/non-secure';\n\nimport TabRouter, {\n TabActionHelpers,\n TabActions,\n TabActionType,\n TabNavigationState,\n TabRouterOptions,\n} from './TabRouter';\nimport type {\n CommonNavigationAction,\n ParamListBase,\n PartialState,\n Router,\n} from './types';\nexport type DrawerStatus = 'open' | 'closed';\n\nexport type DrawerActionType =\n | TabActionType\n | {\n type: 'OPEN_DRAWER' | 'CLOSE_DRAWER' | 'TOGGLE_DRAWER';\n source?: string;\n target?: string;\n };\n\nexport type DrawerRouterOptions = TabRouterOptions & {\n defaultStatus?: DrawerStatus;\n};\n\nexport type DrawerNavigationState<ParamList extends ParamListBase> = Omit<\n TabNavigationState<ParamList>,\n 'type' | 'history'\n> & {\n /**\n * Type of the router, in this case, it's drawer.\n */\n type: 'drawer';\n /**\n * Default status of the drawer.\n */\n default: DrawerStatus;\n /**\n * List of previously visited route keys and drawer open status.\n */\n history: (\n | { type: 'route'; key: string }\n | { type: 'drawer'; status: DrawerStatus }\n )[];\n};\n\nexport type DrawerActionHelpers<ParamList extends ParamListBase> =\n TabActionHelpers<ParamList> & {\n /**\n * Open the drawer sidebar.\n */\n openDrawer(): void;\n\n /**\n * Close the drawer sidebar.\n */\n closeDrawer(): void;\n\n /**\n * Open the drawer sidebar if closed, or close if opened.\n */\n toggleDrawer(): void;\n };\n\nexport const DrawerActions = {\n ...TabActions,\n openDrawer(): DrawerActionType {\n return { type: 'OPEN_DRAWER' };\n },\n closeDrawer(): DrawerActionType {\n return { type: 'CLOSE_DRAWER' };\n },\n toggleDrawer(): DrawerActionType {\n return { type: 'TOGGLE_DRAWER' };\n },\n};\n\nexport default function DrawerRouter({\n defaultStatus = 'closed',\n ...rest\n}: DrawerRouterOptions): Router<\n DrawerNavigationState<ParamListBase>,\n DrawerActionType | CommonNavigationAction\n> {\n const router = TabRouter(rest) as unknown as Router<\n DrawerNavigationState<ParamListBase>,\n TabActionType | CommonNavigationAction\n >;\n\n const isDrawerInHistory = (\n state:\n | DrawerNavigationState<ParamListBase>\n | PartialState<DrawerNavigationState<ParamListBase>>\n ) => Boolean(state.history?.some((it) => it.type === 'drawer'));\n\n const addDrawerToHistory = (\n state: DrawerNavigationState<ParamListBase>\n ): DrawerNavigationState<ParamListBase> => {\n if (isDrawerInHistory(state)) {\n return state;\n }\n\n return {\n ...state,\n history: [\n ...state.history,\n {\n type: 'drawer',\n status: defaultStatus === 'open' ? 'closed' : 'open',\n },\n ],\n };\n };\n\n const removeDrawerFromHistory = (\n state: DrawerNavigationState<ParamListBase>\n ): DrawerNavigationState<ParamListBase> => {\n if (!isDrawerInHistory(state)) {\n return state;\n }\n\n return {\n ...state,\n history: state.history.filter((it) => it.type !== 'drawer'),\n };\n };\n\n const openDrawer = (\n state: DrawerNavigationState<ParamListBase>\n ): DrawerNavigationState<ParamListBase> => {\n if (defaultStatus === 'open') {\n return removeDrawerFromHistory(state);\n }\n\n return addDrawerToHistory(state);\n };\n\n const closeDrawer = (\n state: DrawerNavigationState<ParamListBase>\n ): DrawerNavigationState<ParamListBase> => {\n if (defaultStatus === 'open') {\n return addDrawerToHistory(state);\n }\n\n return removeDrawerFromHistory(state);\n };\n\n return {\n ...router,\n\n type: 'drawer',\n\n getInitialState({ routeNames, routeParamList, routeGetIdList }) {\n const state = router.getInitialState({\n routeNames,\n routeParamList,\n routeGetIdList,\n });\n\n return {\n ...state,\n default: defaultStatus,\n stale: false,\n type: 'drawer',\n key: `drawer-${nanoid()}`,\n };\n },\n\n getRehydratedState(\n partialState,\n { routeNames, routeParamList, routeGetIdList }\n ) {\n if (partialState.stale === false) {\n return partialState;\n }\n\n let state = router.getRehydratedState(partialState, {\n routeNames,\n routeParamList,\n routeGetIdList,\n });\n\n if (isDrawerInHistory(partialState)) {\n // Re-sync the drawer entry in history to correct it if it was wrong\n state = removeDrawerFromHistory(state);\n state = addDrawerToHistory(state);\n }\n\n return {\n ...state,\n default: defaultStatus,\n type: 'drawer',\n key: `drawer-${nanoid()}`,\n };\n },\n\n getStateForRouteFocus(state, key) {\n const result = router.getStateForRouteFocus(state, key);\n\n return closeDrawer(result);\n },\n\n getStateForAction(state, action, options) {\n switch (action.type) {\n case 'OPEN_DRAWER':\n return openDrawer(state);\n\n case 'CLOSE_DRAWER':\n return closeDrawer(state);\n\n case 'TOGGLE_DRAWER':\n if (isDrawerInHistory(state)) {\n return removeDrawerFromHistory(state);\n }\n\n return addDrawerToHistory(state);\n\n case 'JUMP_TO':\n case 'NAVIGATE': {\n const result = router.getStateForAction(state, action, options);\n\n if (result != null && result.index !== state.index) {\n return closeDrawer(result as DrawerNavigationState<ParamListBase>);\n }\n\n return result;\n }\n\n case 'GO_BACK':\n if (isDrawerInHistory(state)) {\n return removeDrawerFromHistory(state);\n }\n\n return router.getStateForAction(state, action, options);\n\n default:\n return router.getStateForAction(state, action, options);\n }\n },\n\n actionCreators: DrawerActions,\n };\n}\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,mBAAvB;AAEA,OAAOC,SAAP,IAEEC,UAFF,QAMO,aANP;AAkEA,OAAO,MAAMC,aAAa,GAAG,EAC3B,GAAGD,UADwB;;EAE3BE,UAAU,GAAqB;IAC7B,OAAO;MAAEC,IAAI,EAAE;IAAR,CAAP;EACD,CAJ0B;;EAK3BC,WAAW,GAAqB;IAC9B,OAAO;MAAED,IAAI,EAAE;IAAR,CAAP;EACD,CAP0B;;EAQ3BE,YAAY,GAAqB;IAC/B,OAAO;MAAEF,IAAI,EAAE;IAAR,CAAP;EACD;;AAV0B,CAAtB;AAaP,eAAe,SAASG,YAAT,OAMb;EAAA,IANmC;IACnCC,aAAa,GAAG,QADmB;IAEnC,GAAGC;EAFgC,CAMnC;EACA,MAAMC,MAAM,GAAGV,SAAS,CAACS,IAAD,CAAxB;;EAKA,MAAME,iBAAiB,GACrBC,KADwB;IAAA;;IAAA,OAIrBC,OAAO,mBAACD,KAAK,CAACE,OAAP,mDAAC,eAAeC,IAAf,CAAqBC,EAAD,IAAQA,EAAE,CAACZ,IAAH,KAAY,QAAxC,CAAD,CAJc;EAAA,CAA1B;;EAMA,MAAMa,kBAAkB,GACtBL,KADyB,IAEgB;IACzC,IAAID,iBAAiB,CAACC,KAAD,CAArB,EAA8B;MAC5B,OAAOA,KAAP;IACD;;IAED,OAAO,EACL,GAAGA,KADE;MAELE,OAAO,EAAE,CACP,GAAGF,KAAK,CAACE,OADF,EAEP;QACEV,IAAI,EAAE,QADR;QAEEc,MAAM,EAAEV,aAAa,KAAK,MAAlB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,IAAV,IAAkBA,MAAM,CAACI,KAAP,KAAiBvB,KAAK,CAACuB,KAA7C,EAAoD;cAClD,OAAO9B,WAAW,CAAC0B,MAAD,CAAlB;YACD;;YAED,OAAOA,MAAP;UACD;;QAED,KAAK,SAAL;UACE,IAAIpB,iBAAiB,CAACC,KAAD,CAArB,EAA8B;YAC5B,OAAOO,uBAAuB,CAACP,KAAD,CAA9B;UACD;;UAED,OAAOF,MAAM,CAACsB,iBAAP,CAAyBpB,KAAzB,EAAgCqB,MAAhC,EAAwCC,OAAxC,CAAP;;QAEF;UACE,OAAOxB,MAAM,CAACsB,iBAAP,CAAyBpB,KAAzB,EAAgCqB,MAAhC,EAAwCC,OAAxC,CAAP;MAjCJ;IAmCD,CA3FI;;IA6FLE,cAAc,EAAElC;EA7FX,CAAP;AA+FD"}
1
+ {"version":3,"names":["nanoid","TabRouter","TabActions","DrawerActions","openDrawer","type","closeDrawer","toggleDrawer","DrawerRouter","defaultStatus","rest","router","isDrawerInHistory","state","Boolean","history","some","it","addDrawerToHistory","status","removeDrawerFromHistory","filter","getInitialState","routeNames","routeParamList","routeGetIdList","default","stale","key","getRehydratedState","partialState","getStateForRouteFocus","result","getStateForAction","action","options","index","actionCreators"],"sourceRoot":"../../src","sources":["DrawerRouter.tsx"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,OAAOC,SAAS,IAEdC,UAAU,QAIL,aAAa;AA4DpB,OAAO,MAAMC,aAAa,GAAG;EAC3B,GAAGD,UAAU;EACbE,UAAU,GAAqB;IAC7B,OAAO;MAAEC,IAAI,EAAE;IAAc,CAAC;EAChC,CAAC;EACDC,WAAW,GAAqB;IAC9B,OAAO;MAAED,IAAI,EAAE;IAAe,CAAC;EACjC,CAAC;EACDE,YAAY,GAAqB;IAC/B,OAAO;MAAEF,IAAI,EAAE;IAAgB,CAAC;EAClC;AACF,CAAC;AAED,eAAe,SAASG,YAAY,OAMlC;EAAA,IANmC;IACnCC,aAAa,GAAG,QAAQ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QACjB,KAAK,aAAa;UAChB,OAAOD,UAAU,CAACS,KAAK,CAAC;QAE1B,KAAK,cAAc;UACjB,OAAOP,WAAW,CAACO,KAAK,CAAC;QAE3B,KAAK,eAAe;UAClB,IAAID,iBAAiB,CAACC,KAAK,CAAC,EAAE;YAC5B,OAAOO,uBAAuB,CAACP,KAAK,CAAC;UACvC;UAEA,OAAOK,kBAAkB,CAACL,KAAK,CAAC;QAElC,KAAK,SAAS;QACd,KAAK,UAAU;QACf,KAAK,qBAAqB;UAAE;YAC1B,MAAMmB,MAAM,GAAGrB,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;YAE/D,IAAIH,MAAM,IAAI,IAAI,IAAIA,MAAM,CAACI,KAAK,KAAKvB,KAAK,CAACuB,KAAK,EAAE;cAClD,OAAO9B,WAAW,CAAC0B,MAAM,CAAyC;YACpE;YAEA,OAAOA,MAAM;UACf;QAEA,KAAK,SAAS;UACZ,IAAIpB,iBAAiB,CAACC,KAAK,CAAC,EAAE;YAC5B,OAAOO,uBAAuB,CAACP,KAAK,CAAC;UACvC;UAEA,OAAOF,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;QAEzD;UACE,OAAOxB,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;MAAC;IAE9D,CAAC;IAEDE,cAAc,EAAElC;EAClB,CAAC;AACH"}
@@ -10,7 +10,6 @@ export const StackActions = {
10
10
  }
11
11
  };
12
12
  },
13
-
14
13
  push(name, params) {
15
14
  return {
16
15
  type: 'PUSH',
@@ -20,7 +19,6 @@ export const StackActions = {
20
19
  }
21
20
  };
22
21
  },
23
-
24
22
  pop() {
25
23
  let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
26
24
  return {
@@ -30,18 +28,26 @@ export const StackActions = {
30
28
  }
31
29
  };
32
30
  },
33
-
34
31
  popToTop() {
35
32
  return {
36
33
  type: 'POP_TO_TOP'
37
34
  };
35
+ },
36
+ popTo(name, params, merge) {
37
+ return {
38
+ type: 'POP_TO',
39
+ payload: {
40
+ name,
41
+ params,
42
+ merge
43
+ }
44
+ };
38
45
  }
39
-
40
46
  };
41
47
  export default function StackRouter(options) {
42
- const router = { ...BaseRouter,
48
+ const router = {
49
+ ...BaseRouter,
43
50
  type: 'stack',
44
-
45
51
  getInitialState(_ref) {
46
52
  let {
47
53
  routeNames,
@@ -61,25 +67,23 @@ export default function StackRouter(options) {
61
67
  }]
62
68
  };
63
69
  },
64
-
65
70
  getRehydratedState(partialState, _ref2) {
66
71
  let {
67
72
  routeNames,
68
73
  routeParamList
69
74
  } = _ref2;
70
75
  let state = partialState;
71
-
72
76
  if (state.stale === false) {
73
77
  return state;
74
78
  }
75
-
76
- const routes = state.routes.filter(route => routeNames.includes(route.name)).map(route => ({ ...route,
79
+ const routes = state.routes.filter(route => routeNames.includes(route.name)).map(route => ({
80
+ ...route,
77
81
  key: route.key || `${route.name}-${nanoid()}`,
78
- params: routeParamList[route.name] !== undefined ? { ...routeParamList[route.name],
82
+ params: routeParamList[route.name] !== undefined ? {
83
+ ...routeParamList[route.name],
79
84
  ...route.params
80
85
  } : route.params
81
86
  }));
82
-
83
87
  if (routes.length === 0) {
84
88
  const initialRouteName = options.initialRouteName !== undefined ? options.initialRouteName : routeNames[0];
85
89
  routes.push({
@@ -88,7 +92,6 @@ export default function StackRouter(options) {
88
92
  params: routeParamList[initialRouteName]
89
93
  });
90
94
  }
91
-
92
95
  return {
93
96
  stale: false,
94
97
  type: 'stack',
@@ -98,7 +101,6 @@ export default function StackRouter(options) {
98
101
  routes
99
102
  };
100
103
  },
101
-
102
104
  getStateForRouteNamesChange(state, _ref3) {
103
105
  let {
104
106
  routeNames,
@@ -106,7 +108,6 @@ export default function StackRouter(options) {
106
108
  routeKeyChanges
107
109
  } = _ref3;
108
110
  const routes = state.routes.filter(route => routeNames.includes(route.name) && !routeKeyChanges.includes(route.name));
109
-
110
111
  if (routes.length === 0) {
111
112
  const initialRouteName = options.initialRouteName !== undefined && routeNames.includes(options.initialRouteName) ? options.initialRouteName : routeNames[0];
112
113
  routes.push({
@@ -115,114 +116,191 @@ export default function StackRouter(options) {
115
116
  params: routeParamList[initialRouteName]
116
117
  });
117
118
  }
118
-
119
- return { ...state,
119
+ return {
120
+ ...state,
120
121
  routeNames,
121
122
  routes,
122
123
  index: Math.min(state.index, routes.length - 1)
123
124
  };
124
125
  },
125
-
126
126
  getStateForRouteFocus(state, key) {
127
127
  const index = state.routes.findIndex(r => r.key === key);
128
-
129
128
  if (index === -1 || index === state.index) {
130
129
  return state;
131
130
  }
132
-
133
- return { ...state,
131
+ return {
132
+ ...state,
134
133
  index,
135
134
  routes: state.routes.slice(0, index + 1)
136
135
  };
137
136
  },
138
-
139
137
  getStateForAction(state, action, options) {
140
138
  const {
141
139
  routeParamList
142
140
  } = options;
143
-
144
141
  switch (action.type) {
145
142
  case 'REPLACE':
146
143
  {
147
144
  const index = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
148
-
149
145
  if (index === -1) {
150
146
  return null;
151
147
  }
152
-
153
148
  const {
154
149
  name,
155
- key,
156
150
  params
157
151
  } = action.payload;
158
-
159
152
  if (!state.routeNames.includes(name)) {
160
153
  return null;
161
154
  }
162
-
163
- return { ...state,
155
+ return {
156
+ ...state,
164
157
  routes: state.routes.map((route, i) => i === index ? {
165
- key: key !== undefined ? key : `${name}-${nanoid()}`,
158
+ key: `${name}-${nanoid()}`,
166
159
  name,
167
- params: routeParamList[name] !== undefined ? { ...routeParamList[name],
160
+ params: routeParamList[name] !== undefined ? {
161
+ ...routeParamList[name],
168
162
  ...params
169
163
  } : params
170
164
  } : route)
171
165
  };
172
166
  }
173
-
174
167
  case 'PUSH':
175
- if (state.routeNames.includes(action.payload.name)) {
168
+ case 'NAVIGATE':
169
+ {
170
+ if (!state.routeNames.includes(action.payload.name)) {
171
+ return null;
172
+ }
176
173
  const getId = options.routeGetIdList[action.payload.name];
177
174
  const id = getId === null || getId === void 0 ? void 0 : getId({
178
175
  params: action.payload.params
179
176
  });
180
- const route = id ? state.routes.find(route => route.name === action.payload.name && id === (getId === null || getId === void 0 ? void 0 : getId({
181
- params: route.params
182
- }))) : undefined;
183
- let routes;
177
+ let route;
178
+ if (id !== undefined) {
179
+ route = state.routes.find(route => route.name === action.payload.name && id === (getId === null || getId === void 0 ? void 0 : getId({
180
+ params: route.params
181
+ })));
182
+ } else {
183
+ const currentRoute = state.routes[state.index];
184
184
 
185
+ // If the route matches the current one, then navigate to it
186
+ if (action.type === 'NAVIGATE' && action.payload.name === currentRoute.name) {
187
+ route = currentRoute;
188
+ }
189
+ }
190
+ let params;
191
+ if (action.type === 'NAVIGATE' && action.payload.merge && route) {
192
+ params = action.payload.params !== undefined || routeParamList[action.payload.name] !== undefined ? {
193
+ ...routeParamList[action.payload.name],
194
+ ...route.params,
195
+ ...action.payload.params
196
+ } : route.params;
197
+ } else {
198
+ params = routeParamList[action.payload.name] !== undefined ? {
199
+ ...routeParamList[action.payload.name],
200
+ ...action.payload.params
201
+ } : action.payload.params;
202
+ }
203
+ let routes;
185
204
  if (route) {
186
- routes = state.routes.filter(r => r.key !== route.key);
187
- routes.push({ ...route,
188
- params: routeParamList[action.payload.name] !== undefined ? { ...routeParamList[action.payload.name],
189
- ...action.payload.params
190
- } : action.payload.params
205
+ const routeKey = route.key;
206
+ routes = state.routes.filter(r => r.key !== routeKey);
207
+ routes.push({
208
+ ...route,
209
+ path: action.type === 'NAVIGATE' && action.payload.path !== undefined ? action.payload.path : route.path,
210
+ params
191
211
  });
192
212
  } else {
193
213
  routes = [...state.routes, {
194
214
  key: `${action.payload.name}-${nanoid()}`,
195
215
  name: action.payload.name,
196
- params: routeParamList[action.payload.name] !== undefined ? { ...routeParamList[action.payload.name],
197
- ...action.payload.params
198
- } : action.payload.params
216
+ path: action.type === 'NAVIGATE' ? action.payload.path : undefined,
217
+ params
199
218
  }];
200
219
  }
201
-
202
- return { ...state,
220
+ return {
221
+ ...state,
203
222
  index: routes.length - 1,
204
223
  routes
205
224
  };
206
225
  }
226
+ case 'NAVIGATE_DEPRECATED':
227
+ {
228
+ if (!state.routeNames.includes(action.payload.name)) {
229
+ return null;
230
+ }
207
231
 
208
- return null;
209
-
232
+ // If the route already exists, navigate to that
233
+ let index = -1;
234
+ const getId = options.routeGetIdList[action.payload.name];
235
+ const id = getId === null || getId === void 0 ? void 0 : getId({
236
+ params: action.payload.params
237
+ });
238
+ if (id) {
239
+ index = state.routes.findIndex(route => route.name === action.payload.name && id === (getId === null || getId === void 0 ? void 0 : getId({
240
+ params: route.params
241
+ })));
242
+ } else if (state.routes[state.index].name === action.payload.name) {
243
+ index = state.index;
244
+ } else {
245
+ for (let i = state.routes.length - 1; i >= 0; i--) {
246
+ if (state.routes[i].name === action.payload.name) {
247
+ index = i;
248
+ break;
249
+ }
250
+ }
251
+ }
252
+ if (index === -1) {
253
+ const routes = [...state.routes, {
254
+ key: `${action.payload.name}-${nanoid()}`,
255
+ name: action.payload.name,
256
+ params: routeParamList[action.payload.name] !== undefined ? {
257
+ ...routeParamList[action.payload.name],
258
+ ...action.payload.params
259
+ } : action.payload.params
260
+ }];
261
+ return {
262
+ ...state,
263
+ routes,
264
+ index: routes.length - 1
265
+ };
266
+ }
267
+ const route = state.routes[index];
268
+ let params;
269
+ if (action.payload.merge) {
270
+ params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
271
+ ...routeParamList[route.name],
272
+ ...route.params,
273
+ ...action.payload.params
274
+ } : route.params;
275
+ } else {
276
+ params = routeParamList[route.name] !== undefined ? {
277
+ ...routeParamList[route.name],
278
+ ...action.payload.params
279
+ } : action.payload.params;
280
+ }
281
+ return {
282
+ ...state,
283
+ index,
284
+ routes: [...state.routes.slice(0, index), params !== route.params ? {
285
+ ...route,
286
+ params
287
+ } : state.routes[index]]
288
+ };
289
+ }
210
290
  case 'POP':
211
291
  {
212
292
  const index = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
213
-
214
293
  if (index > 0) {
215
294
  const count = Math.max(index - action.payload.count + 1, 1);
216
295
  const routes = state.routes.slice(0, count).concat(state.routes.slice(index + 1));
217
- return { ...state,
296
+ return {
297
+ ...state,
218
298
  index: routes.length - 1,
219
299
  routes
220
300
  };
221
301
  }
222
-
223
302
  return null;
224
303
  }
225
-
226
304
  case 'POP_TO_TOP':
227
305
  return router.getStateForAction(state, {
228
306
  type: 'POP',
@@ -230,84 +308,72 @@ export default function StackRouter(options) {
230
308
  count: state.routes.length - 1
231
309
  }
232
310
  }, options);
233
-
234
- case 'NAVIGATE':
235
- if (action.payload.name !== undefined && !state.routeNames.includes(action.payload.name)) {
236
- return null;
237
- }
238
-
239
- if (action.payload.key || action.payload.name) {
240
- var _action$payload$path;
311
+ case 'POP_TO':
312
+ {
313
+ if (!state.routeNames.includes(action.payload.name)) {
314
+ return null;
315
+ }
241
316
 
242
317
  // If the route already exists, navigate to that
243
318
  let index = -1;
244
- const getId = // `getId` and `key` can't be used together
245
- action.payload.key === undefined && action.payload.name !== undefined ? options.routeGetIdList[action.payload.name] : undefined;
319
+ const getId = options.routeGetIdList[action.payload.name];
246
320
  const id = getId === null || getId === void 0 ? void 0 : getId({
247
321
  params: action.payload.params
248
322
  });
249
-
250
323
  if (id) {
251
324
  index = state.routes.findIndex(route => route.name === action.payload.name && id === (getId === null || getId === void 0 ? void 0 : getId({
252
325
  params: route.params
253
326
  })));
254
- } else if (state.routes[state.index].name === action.payload.name && action.payload.key === undefined || state.routes[state.index].key === action.payload.key) {
327
+ } else if (state.routes[state.index].name === action.payload.name) {
255
328
  index = state.index;
256
329
  } else {
257
330
  for (let i = state.routes.length - 1; i >= 0; i--) {
258
- if (state.routes[i].name === action.payload.name && action.payload.key === undefined || state.routes[i].key === action.payload.key) {
331
+ if (state.routes[i].name === action.payload.name) {
259
332
  index = i;
260
333
  break;
261
334
  }
262
335
  }
263
336
  }
264
337
 
265
- if (index === -1 && action.payload.key && action.payload.name === undefined) {
266
- return null;
267
- }
268
-
269
- if (index === -1 && action.payload.name !== undefined) {
270
- var _action$payload$key;
271
-
272
- const routes = [...state.routes, {
273
- key: (_action$payload$key = action.payload.key) !== null && _action$payload$key !== void 0 ? _action$payload$key : `${action.payload.name}-${nanoid()}`,
338
+ // If the route doesn't exist, remove the current route and add the new one
339
+ if (index === -1) {
340
+ const routes = [...state.routes.slice(0, -1), {
341
+ key: `${action.payload.name}-${nanoid()}`,
274
342
  name: action.payload.name,
275
- path: action.payload.path,
276
- params: routeParamList[action.payload.name] !== undefined ? { ...routeParamList[action.payload.name],
343
+ params: routeParamList[action.payload.name] !== undefined ? {
344
+ ...routeParamList[action.payload.name],
277
345
  ...action.payload.params
278
346
  } : action.payload.params
279
347
  }];
280
- return { ...state,
348
+ return {
349
+ ...state,
281
350
  routes,
282
351
  index: routes.length - 1
283
352
  };
284
353
  }
285
-
286
354
  const route = state.routes[index];
287
355
  let params;
288
-
289
356
  if (action.payload.merge) {
290
- params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? { ...routeParamList[route.name],
357
+ params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
358
+ ...routeParamList[route.name],
291
359
  ...route.params,
292
360
  ...action.payload.params
293
361
  } : route.params;
294
362
  } else {
295
- params = routeParamList[route.name] !== undefined ? { ...routeParamList[route.name],
363
+ params = routeParamList[route.name] !== undefined ? {
364
+ ...routeParamList[route.name],
296
365
  ...action.payload.params
297
366
  } : action.payload.params;
298
367
  }
299
-
300
- return { ...state,
368
+ return {
369
+ ...state,
301
370
  index,
302
- routes: [...state.routes.slice(0, index), params !== route.params || action.payload.path && action.payload.path !== route.path ? { ...route,
303
- path: (_action$payload$path = action.payload.path) !== null && _action$payload$path !== void 0 ? _action$payload$path : route.path,
371
+ routes: [...state.routes.slice(0, index), params !== route.params ? {
372
+ ...route,
304
373
  params
305
374
  } : state.routes[index]]
306
375
  };
307
376
  }
308
-
309
- return null;
310
-
311
377
  case 'GO_BACK':
312
378
  if (state.index > 0) {
313
379
  return router.getStateForAction(state, {
@@ -319,14 +385,11 @@ export default function StackRouter(options) {
319
385
  source: action.source
320
386
  }, options);
321
387
  }
322
-
323
388
  return null;
324
-
325
389
  default:
326
390
  return BaseRouter.getStateForAction(state, action);
327
391
  }
328
392
  },
329
-
330
393
  actionCreators: StackActions
331
394
  };
332
395
  return router;