@react-navigation/native 6.1.0 → 6.1.1

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 (136) hide show
  1. package/lib/commonjs/Link.js +2 -12
  2. package/lib/commonjs/Link.js.map +1 -1
  3. package/lib/commonjs/LinkingContext.js +0 -4
  4. package/lib/commonjs/LinkingContext.js.map +1 -1
  5. package/lib/commonjs/NavigationContainer.js +9 -31
  6. package/lib/commonjs/NavigationContainer.js.map +1 -1
  7. package/lib/commonjs/ServerContainer.js +2 -12
  8. package/lib/commonjs/ServerContainer.js.map +1 -1
  9. package/lib/commonjs/ServerContext.js +0 -4
  10. package/lib/commonjs/ServerContext.js.map +1 -1
  11. package/lib/commonjs/createMemoryHistory.js +29 -54
  12. package/lib/commonjs/createMemoryHistory.js.map +1 -1
  13. package/lib/commonjs/extractPathFromURL.js +2 -8
  14. package/lib/commonjs/extractPathFromURL.js.map +1 -1
  15. package/lib/commonjs/index.js +0 -17
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/theming/DarkTheme.js.map +1 -1
  18. package/lib/commonjs/theming/DefaultTheme.js.map +1 -1
  19. package/lib/commonjs/theming/ThemeContext.js +0 -6
  20. package/lib/commonjs/theming/ThemeContext.js.map +1 -1
  21. package/lib/commonjs/theming/ThemeProvider.js +0 -6
  22. package/lib/commonjs/theming/ThemeProvider.js.map +1 -1
  23. package/lib/commonjs/theming/useTheme.js +0 -6
  24. package/lib/commonjs/theming/useTheme.js.map +1 -1
  25. package/lib/commonjs/types.js.map +1 -1
  26. package/lib/commonjs/useBackButton.js +0 -9
  27. package/lib/commonjs/useBackButton.js.map +1 -1
  28. package/lib/commonjs/useDocumentTitle.js +1 -12
  29. package/lib/commonjs/useDocumentTitle.js.map +1 -1
  30. package/lib/commonjs/useDocumentTitle.native.js +2 -2
  31. package/lib/commonjs/useDocumentTitle.native.js.map +1 -1
  32. package/lib/commonjs/useLinkBuilder.js +5 -15
  33. package/lib/commonjs/useLinkBuilder.js.map +1 -1
  34. package/lib/commonjs/useLinkProps.js +8 -24
  35. package/lib/commonjs/useLinkProps.js.map +1 -1
  36. package/lib/commonjs/useLinkTo.js +0 -12
  37. package/lib/commonjs/useLinkTo.js.map +1 -1
  38. package/lib/commonjs/useLinking.js +35 -79
  39. package/lib/commonjs/useLinking.js.map +1 -1
  40. package/lib/commonjs/useLinking.native.js +9 -36
  41. package/lib/commonjs/useLinking.native.js.map +1 -1
  42. package/lib/commonjs/useScrollToTop.js +10 -17
  43. package/lib/commonjs/useScrollToTop.js.map +1 -1
  44. package/lib/commonjs/useThenable.js +2 -9
  45. package/lib/commonjs/useThenable.js.map +1 -1
  46. package/lib/module/Link.js +2 -6
  47. package/lib/module/Link.js.map +1 -1
  48. package/lib/module/LinkingContext.js.map +1 -1
  49. package/lib/module/NavigationContainer.js +9 -18
  50. package/lib/module/NavigationContainer.js.map +1 -1
  51. package/lib/module/ServerContainer.js +2 -5
  52. package/lib/module/ServerContainer.js.map +1 -1
  53. package/lib/module/ServerContext.js.map +1 -1
  54. package/lib/module/createMemoryHistory.js +29 -52
  55. package/lib/module/createMemoryHistory.js.map +1 -1
  56. package/lib/module/extractPathFromURL.js +2 -5
  57. package/lib/module/extractPathFromURL.js.map +1 -1
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/theming/DarkTheme.js.map +1 -1
  60. package/lib/module/theming/DefaultTheme.js.map +1 -1
  61. package/lib/module/theming/ThemeContext.js.map +1 -1
  62. package/lib/module/theming/ThemeProvider.js.map +1 -1
  63. package/lib/module/theming/useTheme.js.map +1 -1
  64. package/lib/module/types.js.map +1 -1
  65. package/lib/module/useBackButton.js +0 -3
  66. package/lib/module/useBackButton.js.map +1 -1
  67. package/lib/module/useDocumentTitle.js +1 -9
  68. package/lib/module/useDocumentTitle.js.map +1 -1
  69. package/lib/module/useDocumentTitle.native.js +2 -1
  70. package/lib/module/useDocumentTitle.native.js.map +1 -1
  71. package/lib/module/useLinkBuilder.js +5 -9
  72. package/lib/module/useLinkBuilder.js.map +1 -1
  73. package/lib/module/useLinkProps.js +8 -16
  74. package/lib/module/useLinkProps.js.map +1 -1
  75. package/lib/module/useLinkTo.js +0 -5
  76. package/lib/module/useLinkTo.js.map +1 -1
  77. package/lib/module/useLinking.js +35 -70
  78. package/lib/module/useLinking.js.map +1 -1
  79. package/lib/module/useLinking.native.js +9 -26
  80. package/lib/module/useLinking.native.js.map +1 -1
  81. package/lib/module/useScrollToTop.js +10 -13
  82. package/lib/module/useScrollToTop.js.map +1 -1
  83. package/lib/module/useThenable.js +2 -5
  84. package/lib/module/useThenable.js.map +1 -1
  85. package/lib/typescript/src/Link.d.ts +1 -0
  86. package/lib/typescript/src/Link.d.ts.map +1 -0
  87. package/lib/typescript/src/LinkingContext.d.ts +1 -0
  88. package/lib/typescript/src/LinkingContext.d.ts.map +1 -0
  89. package/lib/typescript/src/NavigationContainer.d.ts +1 -0
  90. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -0
  91. package/lib/typescript/src/ServerContainer.d.ts +1 -0
  92. package/lib/typescript/src/ServerContainer.d.ts.map +1 -0
  93. package/lib/typescript/src/ServerContext.d.ts +1 -0
  94. package/lib/typescript/src/ServerContext.d.ts.map +1 -0
  95. package/lib/typescript/src/__mocks__/window.d.ts +1 -0
  96. package/lib/typescript/src/__mocks__/window.d.ts.map +1 -0
  97. package/lib/typescript/src/createMemoryHistory.d.ts +1 -0
  98. package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -0
  99. package/lib/typescript/src/extractPathFromURL.d.ts +1 -0
  100. package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -0
  101. package/lib/typescript/src/index.d.ts +1 -0
  102. package/lib/typescript/src/index.d.ts.map +1 -0
  103. package/lib/typescript/src/theming/DarkTheme.d.ts +1 -0
  104. package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -0
  105. package/lib/typescript/src/theming/DefaultTheme.d.ts +1 -0
  106. package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -0
  107. package/lib/typescript/src/theming/ThemeContext.d.ts +1 -0
  108. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -0
  109. package/lib/typescript/src/theming/ThemeProvider.d.ts +1 -0
  110. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -0
  111. package/lib/typescript/src/theming/useTheme.d.ts +1 -0
  112. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -0
  113. package/lib/typescript/src/types.d.ts +1 -0
  114. package/lib/typescript/src/types.d.ts.map +1 -0
  115. package/lib/typescript/src/useBackButton.d.ts +1 -0
  116. package/lib/typescript/src/useBackButton.d.ts.map +1 -0
  117. package/lib/typescript/src/useDocumentTitle.d.ts +1 -0
  118. package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -0
  119. package/lib/typescript/src/useDocumentTitle.native.d.ts +1 -0
  120. package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -0
  121. package/lib/typescript/src/useLinkBuilder.d.ts +1 -0
  122. package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -0
  123. package/lib/typescript/src/useLinkProps.d.ts +1 -0
  124. package/lib/typescript/src/useLinkProps.d.ts.map +1 -0
  125. package/lib/typescript/src/useLinkTo.d.ts +1 -0
  126. package/lib/typescript/src/useLinkTo.d.ts.map +1 -0
  127. package/lib/typescript/src/useLinking.d.ts +1 -0
  128. package/lib/typescript/src/useLinking.d.ts.map +1 -0
  129. package/lib/typescript/src/useLinking.native.d.ts +1 -0
  130. package/lib/typescript/src/useLinking.native.d.ts.map +1 -0
  131. package/lib/typescript/src/useScrollToTop.d.ts +1 -0
  132. package/lib/typescript/src/useScrollToTop.d.ts.map +1 -0
  133. package/lib/typescript/src/useThenable.d.ts +1 -0
  134. package/lib/typescript/src/useThenable.d.ts.map +1 -0
  135. package/package.json +4 -4
  136. package/src/useScrollToTop.tsx +6 -1
@@ -1,97 +1,86 @@
1
1
  import { nanoid } from 'nanoid/non-secure';
2
2
  export default function createMemoryHistory() {
3
3
  let index = 0;
4
- let items = []; // Pending callbacks for `history.go(n)`
5
- // We might modify the callback stored if it was interrupted, so we have a ref to identify it
4
+ let items = [];
6
5
 
6
+ // Pending callbacks for `history.go(n)`
7
+ // We might modify the callback stored if it was interrupted, so we have a ref to identify it
7
8
  const pending = [];
8
-
9
9
  const interrupt = () => {
10
10
  // If another history operation was performed we need to interrupt existing ones
11
11
  // This makes sure that calls such as `history.replace` after `history.go` don't happen
12
12
  // Since otherwise it won't be correct if something else has changed
13
13
  pending.forEach(it => {
14
14
  const cb = it.cb;
15
-
16
15
  it.cb = () => cb(true);
17
16
  });
18
17
  };
19
-
20
18
  const history = {
21
19
  get index() {
22
20
  var _window$history$state;
23
-
24
21
  // We store an id in the state instead of an index
25
22
  // Index could get out of sync with in-memory values if page reloads
26
23
  const id = (_window$history$state = window.history.state) === null || _window$history$state === void 0 ? void 0 : _window$history$state.id;
27
-
28
24
  if (id) {
29
25
  const index = items.findIndex(item => item.id === id);
30
26
  return index > -1 ? index : 0;
31
27
  }
32
-
33
28
  return 0;
34
29
  },
35
-
36
30
  get(index) {
37
31
  return items[index];
38
32
  },
39
-
40
33
  backIndex(_ref) {
41
34
  let {
42
35
  path
43
36
  } = _ref;
44
-
45
37
  // We need to find the index from the element before current to get closest path to go back to
46
38
  for (let i = index - 1; i >= 0; i--) {
47
39
  const item = items[i];
48
-
49
40
  if (item.path === path) {
50
41
  return i;
51
42
  }
52
43
  }
53
-
54
44
  return -1;
55
45
  },
56
-
57
46
  push(_ref2) {
58
47
  let {
59
48
  path,
60
49
  state
61
50
  } = _ref2;
62
51
  interrupt();
63
- const id = nanoid(); // When a new entry is pushed, all the existing entries after index will be inaccessible
64
- // So we remove any existing entries after the current index to clean them up
52
+ const id = nanoid();
65
53
 
54
+ // When a new entry is pushed, all the existing entries after index will be inaccessible
55
+ // So we remove any existing entries after the current index to clean them up
66
56
  items = items.slice(0, index + 1);
67
57
  items.push({
68
58
  path,
69
59
  state,
70
60
  id
71
61
  });
72
- index = items.length - 1; // We pass empty string for title because it's ignored in all browsers except safari
62
+ index = items.length - 1;
63
+
64
+ // We pass empty string for title because it's ignored in all browsers except safari
73
65
  // We don't store state object in history.state because:
74
66
  // - browsers have limits on how big it can be, and we don't control the size
75
67
  // - while not recommended, there could be non-serializable data in state
76
-
77
68
  window.history.pushState({
78
69
  id
79
70
  }, '', path);
80
71
  },
81
-
82
72
  replace(_ref3) {
83
- var _window$history$state2, _window$history$state3;
84
-
73
+ var _window$history$state2;
85
74
  let {
86
75
  path,
87
76
  state
88
77
  } = _ref3;
89
78
  interrupt();
90
- const id = (_window$history$state2 = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id) !== null && _window$history$state2 !== void 0 ? _window$history$state2 : nanoid(); // Need to keep the hash part of the path if there was no previous history entry
91
- // or the previous history entry had the same path
79
+ const id = ((_window$history$state2 = window.history.state) === null || _window$history$state2 === void 0 ? void 0 : _window$history$state2.id) ?? nanoid();
92
80
 
81
+ // Need to keep the hash part of the path if there was no previous history entry
82
+ // or the previous history entry had the same path
93
83
  let pathWithHash = path;
94
-
95
84
  if (!items.length || items.findIndex(item => item.id === id) < 0) {
96
85
  // There are two scenarios for creating an array with only one history record:
97
86
  // - When loaded id not found in the items array, this function by default will replace
@@ -110,31 +99,28 @@ export default function createMemoryHistory() {
110
99
  if (items[index].path === path) {
111
100
  pathWithHash = pathWithHash + location.hash;
112
101
  }
113
-
114
102
  items[index] = {
115
103
  path,
116
104
  state,
117
105
  id
118
106
  };
119
107
  }
120
-
121
108
  window.history.replaceState({
122
109
  id
123
110
  }, '', pathWithHash);
124
111
  },
125
-
126
112
  // `history.go(n)` is asynchronous, there are couple of things to keep in mind:
127
113
  // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.
128
114
  // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.
129
115
  // - the `popstate` event fires before the next frame after calling `history.go(n)`.
130
116
  // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.
131
117
  go(n) {
132
- interrupt(); // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory
133
- // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.
118
+ interrupt();
134
119
 
120
+ // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory
121
+ // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.
135
122
  const nextIndex = index + n;
136
123
  const lastItemIndex = items.length - 1;
137
-
138
124
  if (n < 0 && !items[nextIndex]) {
139
125
  // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item.
140
126
  n = -index;
@@ -146,24 +132,24 @@ export default function createMemoryHistory() {
146
132
  } else {
147
133
  index = nextIndex;
148
134
  }
149
-
150
135
  if (n === 0) {
151
136
  return;
152
- } // When we call `history.go`, `popstate` will fire when there's history to go back to
137
+ }
138
+
139
+ // When we call `history.go`, `popstate` will fire when there's history to go back to
153
140
  // So we need to somehow handle following cases:
154
141
  // - There's history to go back, `history.go` is called, and `popstate` fires
155
142
  // - `history.go` is called multiple times, we need to resolve on respective `popstate`
156
143
  // - No history to go back, but `history.go` was called, browser has no API to detect it
157
-
158
-
159
144
  return new Promise((resolve, reject) => {
160
145
  const done = interrupted => {
161
146
  clearTimeout(timer);
162
-
163
147
  if (interrupted) {
164
148
  reject(new Error('History was changed during navigation.'));
165
149
  return;
166
- } // There seems to be a bug in Chrome regarding updating the title
150
+ }
151
+
152
+ // There seems to be a bug in Chrome regarding updating the title
167
153
  // If we set a title just before calling `history.go`, the title gets lost
168
154
  // However the value of `document.title` is still what we set it to
169
155
  // It's just not displayed in the tab bar
@@ -171,8 +157,6 @@ export default function createMemoryHistory() {
171
157
  // And set the title to what it was before so it gets applied
172
158
  // It won't work without setting it to empty string coz otherwise title isn't changing
173
159
  // Which means that the browser won't do anything after setting the title
174
-
175
-
176
160
  const {
177
161
  title
178
162
  } = window.document;
@@ -180,43 +164,39 @@ export default function createMemoryHistory() {
180
164
  window.document.title = title;
181
165
  resolve();
182
166
  };
183
-
184
167
  pending.push({
185
168
  ref: done,
186
169
  cb: done
187
- }); // If navigation didn't happen within 100ms, assume that it won't happen
170
+ });
171
+
172
+ // If navigation didn't happen within 100ms, assume that it won't happen
188
173
  // This may not be accurate, but hopefully it won't take so much time
189
174
  // In Chrome, navigation seems to happen instantly in next microtask
190
175
  // But on Firefox, it seems to take much longer, around 50ms from our testing
191
176
  // We're using a hacky timeout since there doesn't seem to be way to know for sure
192
-
193
177
  const timer = setTimeout(() => {
194
178
  const index = pending.findIndex(it => it.ref === done);
195
-
196
179
  if (index > -1) {
197
180
  pending[index].cb();
198
181
  pending.splice(index, 1);
199
182
  }
200
183
  }, 100);
201
-
202
184
  const onPopState = () => {
203
- var _window$history$state4;
185
+ var _window$history$state3;
186
+ const id = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id;
187
+ const currentIndex = items.findIndex(item => item.id === id);
204
188
 
205
- const id = (_window$history$state4 = window.history.state) === null || _window$history$state4 === void 0 ? void 0 : _window$history$state4.id;
206
- const currentIndex = items.findIndex(item => item.id === id); // Fix createMemoryHistory.index variable's value
189
+ // Fix createMemoryHistory.index variable's value
207
190
  // as it may go out of sync when navigating in the browser.
208
-
209
191
  index = Math.max(currentIndex, 0);
210
192
  const last = pending.pop();
211
193
  window.removeEventListener('popstate', onPopState);
212
194
  last === null || last === void 0 ? void 0 : last.cb();
213
195
  };
214
-
215
196
  window.addEventListener('popstate', onPopState);
216
197
  window.history.go(n);
217
198
  });
218
199
  },
219
-
220
200
  // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`
221
201
  // If we call `history.go(n)` ourselves, we don't want it to trigger the listener
222
202
  // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener
@@ -226,14 +206,11 @@ export default function createMemoryHistory() {
226
206
  // This was triggered by `history.go(n)`, we shouldn't call the listener
227
207
  return;
228
208
  }
229
-
230
209
  listener();
231
210
  };
232
-
233
211
  window.addEventListener('popstate', onPopState);
234
212
  return () => window.removeEventListener('popstate', onPopState);
235
213
  }
236
-
237
214
  };
238
215
  return history;
239
216
  }
@@ -1 +1 @@
1
- {"version":3,"names":["nanoid","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","pathWithHash","location","hash","replaceState","go","n","nextIndex","lastItemIndex","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","Math","max","last","pop","removeEventListener","addEventListener","listen","listener"],"sources":["createMemoryHistory.tsx"],"sourcesContent":["import type { NavigationState } from '@react-navigation/core';\nimport { nanoid } from 'nanoid/non-secure';\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nexport default function createMemoryHistory() {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n // Need to keep the hash part of the path if there was no previous history entry\n // or the previous history entry had the same path\n let pathWithHash = path;\n\n if (!items.length || items.findIndex((item) => item.id === id) < 0) {\n // There are two scenarios for creating an array with only one history record:\n // - When loaded id not found in the items array, this function by default will replace\n // the first item. We need to keep only the new updated object, otherwise it will break\n // the page when navigating forward in history.\n // - This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n pathWithHash = pathWithHash + location.hash;\n items = [{ path: pathWithHash, state, id }];\n index = 0;\n } else {\n if (items[index].path === path) {\n pathWithHash = pathWithHash + location.hash;\n }\n items[index] = { path, state, id };\n }\n\n window.history.replaceState({ id }, '', pathWithHash);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory\n // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.\n const nextIndex = index + n;\n const lastItemIndex = items.length - 1;\n if (n < 0 && !items[nextIndex]) {\n // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item.\n n = -index;\n index = 0;\n } else if (n > 0 && nextIndex > lastItemIndex) {\n // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there.\n n = lastItemIndex - index;\n index = lastItemIndex;\n } else {\n index = nextIndex;\n }\n\n if (n === 0) {\n return;\n }\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const id = window.history.state?.id;\n const currentIndex = items.findIndex((item) => item.id === id);\n\n // Fix createMemoryHistory.index variable's value\n // as it may go out of sync when navigating in the browser.\n index = Math.max(currentIndex, 0);\n\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n}\n"],"mappings":"AACA,SAASA,MAAT,QAAuB,mBAAvB;AAWA,eAAe,SAASC,mBAAT,GAA+B;EAC5C,IAAIC,KAAK,GAAG,CAAZ;EACA,IAAIC,KAAsB,GAAG,EAA7B,CAF4C,CAI5C;EACA;;EACA,MAAMC,OAAgE,GAAG,EAAzE;;EAEA,MAAMC,SAAS,GAAG,MAAM;IACtB;IACA;IACA;IACAD,OAAO,CAACE,OAAR,CAAiBC,EAAD,IAAQ;MACtB,MAAMC,EAAE,GAAGD,EAAE,CAACC,EAAd;;MACAD,EAAE,CAACC,EAAH,GAAQ,MAAMA,EAAE,CAAC,IAAD,CAAhB;IACD,CAHD;EAID,CARD;;EAUA,MAAMC,OAAO,GAAG;IACd,IAAIP,KAAJ,GAAoB;MAAA;;MAClB;MACA;MACA,MAAMQ,EAAE,4BAAGC,MAAM,CAACF,OAAP,CAAeG,KAAlB,0DAAG,sBAAsBF,EAAjC;;MAEA,IAAIA,EAAJ,EAAQ;QACN,MAAMR,KAAK,GAAGC,KAAK,CAACU,SAAN,CAAiBC,IAAD,IAAUA,IAAI,CAACJ,EAAL,KAAYA,EAAtC,CAAd;QAEA,OAAOR,KAAK,GAAG,CAAC,CAAT,GAAaA,KAAb,GAAqB,CAA5B;MACD;;MAED,OAAO,CAAP;IACD,CAba;;IAeda,GAAG,CAACb,KAAD,EAAgB;MACjB,OAAOC,KAAK,CAACD,KAAD,CAAZ;IACD,CAjBa;;IAmBdc,SAAS,OAA6B;MAAA,IAA5B;QAAEC;MAAF,CAA4B;;MACpC;MACA,KAAK,IAAIC,CAAC,GAAGhB,KAAK,GAAG,CAArB,EAAwBgB,CAAC,IAAI,CAA7B,EAAgCA,CAAC,EAAjC,EAAqC;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,CAZD;;QAcAG,MAAM,CAACyC,gBAAP,CAAwB,UAAxB,EAAoCP,UAApC;QACAlC,MAAM,CAACF,OAAP,CAAemB,EAAf,CAAkBC,CAAlB;MACD,CAzDM,CAAP;IA0DD,CA3Ka;;IA6Kd;IACA;IACA;IACAwB,MAAM,CAACC,QAAD,EAAuB;MAC3B,MAAMT,UAAU,GAAG,MAAM;QACvB,IAAIzC,OAAO,CAACiB,MAAZ,EAAoB;UAClB;UACA;QACD;;QAEDiC,QAAQ;MACT,CAPD;;MASA3C,MAAM,CAACyC,gBAAP,CAAwB,UAAxB,EAAoCP,UAApC;MAEA,OAAO,MAAMlC,MAAM,CAACwC,mBAAP,CAA2B,UAA3B,EAAuCN,UAAvC,CAAb;IACD;;EA7La,CAAhB;EAgMA,OAAOpC,OAAP;AACD"}
1
+ {"version":3,"names":["nanoid","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","pathWithHash","location","hash","replaceState","go","n","nextIndex","lastItemIndex","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","Math","max","last","pop","removeEventListener","addEventListener","listen","listener"],"sourceRoot":"../../src","sources":["createMemoryHistory.tsx"],"mappings":"AACA,SAASA,MAAM,QAAQ,mBAAmB;AAW1C,eAAe,SAASC,mBAAmB,GAAG;EAC5C,IAAIC,KAAK,GAAG,CAAC;EACb,IAAIC,KAAsB,GAAG,EAAE;;EAE/B;EACA;EACA,MAAMC,OAAgE,GAAG,EAAE;EAE3E,MAAMC,SAAS,GAAG,MAAM;IACtB;IACA;IACA;IACAD,OAAO,CAACE,OAAO,CAAEC,EAAE,IAAK;MACtB,MAAMC,EAAE,GAAGD,EAAE,CAACC,EAAE;MAChBD,EAAE,CAACC,EAAE,GAAG,MAAMA,EAAE,CAAC,IAAI,CAAC;IACxB,CAAC,CAAC;EACJ,CAAC;EAED,MAAMC,OAAO,GAAG;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C1B;QACF,CAAC,EAAE,GAAG,CAAC;QAEP,MAAM2C,UAAU,GAAG,MAAM;UAAA;UACvB,MAAMnC,EAAE,6BAAGC,MAAM,CAACF,OAAO,CAACG,KAAK,2DAApB,uBAAsBF,EAAE;UACnC,MAAMoC,YAAY,GAAG3C,KAAK,CAACU,SAAS,CAAEC,IAAI,IAAKA,IAAI,CAACJ,EAAE,KAAKA,EAAE,CAAC;;UAE9D;UACA;UACAR,KAAK,GAAG6C,IAAI,CAACC,GAAG,CAACF,YAAY,EAAE,CAAC,CAAC;UAEjC,MAAMG,IAAI,GAAG7C,OAAO,CAAC8C,GAAG,EAAE;UAE1BvC,MAAM,CAACwC,mBAAmB,CAAC,UAAU,EAAEN,UAAU,CAAC;UAClDI,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEzC,EAAE,EAAE;QACZ,CAAC;QAEDG,MAAM,CAACyC,gBAAgB,CAAC,UAAU,EAAEP,UAAU,CAAC;QAC/ClC,MAAM,CAACF,OAAO,CAACmB,EAAE,CAACC,CAAC,CAAC;MACtB,CAAC,CAAC;IACJ,CAAC;IAED;IACA;IACA;IACAwB,MAAM,CAACC,QAAoB,EAAE;MAC3B,MAAMT,UAAU,GAAG,MAAM;QACvB,IAAIzC,OAAO,CAACiB,MAAM,EAAE;UAClB;UACA;QACF;QAEAiC,QAAQ,EAAE;MACZ,CAAC;MAED3C,MAAM,CAACyC,gBAAgB,CAAC,UAAU,EAAEP,UAAU,CAAC;MAE/C,OAAO,MAAMlC,MAAM,CAACwC,mBAAmB,CAAC,UAAU,EAAEN,UAAU,CAAC;IACjE;EACF,CAAC;EAED,OAAOpC,OAAO;AAChB"}
@@ -1,20 +1,17 @@
1
1
  import escapeStringRegexp from 'escape-string-regexp';
2
2
  export default function extractPathFromURL(prefixes, url) {
3
3
  for (const prefix of prefixes) {
4
- var _prefix$match$, _prefix$match;
5
-
6
- const protocol = (_prefix$match$ = (_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) !== null && _prefix$match$ !== void 0 ? _prefix$match$ : '';
4
+ var _prefix$match;
5
+ const protocol = ((_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) ?? '';
7
6
  const host = prefix.replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '').replace(/\/+/g, '/') // Replace multiple slash (//) with single ones
8
7
  .replace(/^\//, ''); // Remove extra leading slash
9
8
 
10
9
  const prefixRegex = new RegExp(`^${escapeStringRegexp(protocol)}(/)*${host.split('.').map(it => it === '*' ? '[^/]+' : escapeStringRegexp(it)).join('\\.')}`);
11
10
  const normalizedURL = url.replace(/\/+/g, '/');
12
-
13
11
  if (prefixRegex.test(normalizedURL)) {
14
12
  return normalizedURL.replace(prefixRegex, '');
15
13
  }
16
14
  }
17
-
18
15
  return undefined;
19
16
  }
20
17
  //# sourceMappingURL=extractPathFromURL.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["escapeStringRegexp","extractPathFromURL","prefixes","url","prefix","protocol","match","host","replace","RegExp","prefixRegex","split","map","it","join","normalizedURL","test","undefined"],"sources":["extractPathFromURL.tsx"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nexport default function extractPathFromURL(prefixes: string[], url: string) {\n for (const prefix of prefixes) {\n const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';\n const host = prefix\n .replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '')\n .replace(/\\/+/g, '/') // Replace multiple slash (//) with single ones\n .replace(/^\\//, ''); // Remove extra leading slash\n\n const prefixRegex = new RegExp(\n `^${escapeStringRegexp(protocol)}(/)*${host\n .split('.')\n .map((it) => (it === '*' ? '[^/]+' : escapeStringRegexp(it)))\n .join('\\\\.')}`\n );\n\n const normalizedURL = url.replace(/\\/+/g, '/');\n\n if (prefixRegex.test(normalizedURL)) {\n return normalizedURL.replace(prefixRegex, '');\n }\n }\n\n return undefined;\n}\n"],"mappings":"AAAA,OAAOA,kBAAP,MAA+B,sBAA/B;AAEA,eAAe,SAASC,kBAAT,CAA4BC,QAA5B,EAAgDC,GAAhD,EAA6D;EAC1E,KAAK,MAAMC,MAAX,IAAqBF,QAArB,EAA+B;IAAA;;IAC7B,MAAMG,QAAQ,sCAAGD,MAAM,CAACE,KAAP,CAAa,SAAb,CAAH,kDAAG,cAA0B,CAA1B,CAAH,2DAAmC,EAAjD;IACA,MAAMC,IAAI,GAAGH,MAAM,CAChBI,OADU,CACF,IAAIC,MAAJ,CAAY,IAAGT,kBAAkB,CAACK,QAAD,CAAW,EAA5C,CADE,EAC8C,EAD9C,EAEVG,OAFU,CAEF,MAFE,EAEM,GAFN,EAEW;IAFX,CAGVA,OAHU,CAGF,KAHE,EAGK,EAHL,CAAb,CAF6B,CAKN;;IAEvB,MAAME,WAAW,GAAG,IAAID,MAAJ,CACjB,IAAGT,kBAAkB,CAACK,QAAD,CAAW,OAAME,IAAI,CACxCI,KADoC,CAC9B,GAD8B,EAEpCC,GAFoC,CAE/BC,EAAD,IAASA,EAAE,KAAK,GAAP,GAAa,OAAb,GAAuBb,kBAAkB,CAACa,EAAD,CAFlB,EAGpCC,IAHoC,CAG/B,KAH+B,CAGxB,EAJG,CAApB;IAOA,MAAMC,aAAa,GAAGZ,GAAG,CAACK,OAAJ,CAAY,MAAZ,EAAoB,GAApB,CAAtB;;IAEA,IAAIE,WAAW,CAACM,IAAZ,CAAiBD,aAAjB,CAAJ,EAAqC;MACnC,OAAOA,aAAa,CAACP,OAAd,CAAsBE,WAAtB,EAAmC,EAAnC,CAAP;IACD;EACF;;EAED,OAAOO,SAAP;AACD"}
1
+ {"version":3,"names":["escapeStringRegexp","extractPathFromURL","prefixes","url","prefix","protocol","match","host","replace","RegExp","prefixRegex","split","map","it","join","normalizedURL","test","undefined"],"sourceRoot":"../../src","sources":["extractPathFromURL.tsx"],"mappings":"AAAA,OAAOA,kBAAkB,MAAM,sBAAsB;AAErD,eAAe,SAASC,kBAAkB,CAACC,QAAkB,EAAEC,GAAW,EAAE;EAC1E,KAAK,MAAMC,MAAM,IAAIF,QAAQ,EAAE;IAAA;IAC7B,MAAMG,QAAQ,GAAG,kBAAAD,MAAM,CAACE,KAAK,CAAC,SAAS,CAAC,kDAAvB,cAA0B,CAAC,CAAC,KAAI,EAAE;IACnD,MAAMC,IAAI,GAAGH,MAAM,CAChBI,OAAO,CAAC,IAAIC,MAAM,CAAE,IAAGT,kBAAkB,CAACK,QAAQ,CAAE,EAAC,CAAC,EAAE,EAAE,CAAC,CAC3DG,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAA,CACrBA,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;;IAEvB,MAAME,WAAW,GAAG,IAAID,MAAM,CAC3B,IAAGT,kBAAkB,CAACK,QAAQ,CAAE,OAAME,IAAI,CACxCI,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAAEC,EAAE,IAAMA,EAAE,KAAK,GAAG,GAAG,OAAO,GAAGb,kBAAkB,CAACa,EAAE,CAAE,CAAC,CAC5DC,IAAI,CAAC,KAAK,CAAE,EAAC,CACjB;IAED,MAAMC,aAAa,GAAGZ,GAAG,CAACK,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;IAE9C,IAAIE,WAAW,CAACM,IAAI,CAACD,aAAa,CAAC,EAAE;MACnC,OAAOA,aAAa,CAACP,OAAO,CAACE,WAAW,EAAE,EAAE,CAAC;IAC/C;EACF;EAEA,OAAOO,SAAS;AAClB"}
@@ -1 +1 @@
1
- {"version":3,"names":["default","Link","LinkingContext","NavigationContainer","ServerContainer","DarkTheme","DefaultTheme","ThemeProvider","useTheme","useLinkBuilder","useLinkProps","useLinkTo","useScrollToTop"],"sources":["index.tsx"],"sourcesContent":["export { default as Link } from './Link';\nexport { default as LinkingContext } from './LinkingContext';\nexport { default as NavigationContainer } from './NavigationContainer';\nexport { default as ServerContainer } from './ServerContainer';\nexport { default as DarkTheme } from './theming/DarkTheme';\nexport { default as DefaultTheme } from './theming/DefaultTheme';\nexport { default as ThemeProvider } from './theming/ThemeProvider';\nexport { default as useTheme } from './theming/useTheme';\nexport * from './types';\nexport { default as useLinkBuilder } from './useLinkBuilder';\nexport { default as useLinkProps } from './useLinkProps';\nexport { default as useLinkTo } from './useLinkTo';\nexport { default as useScrollToTop } from './useScrollToTop';\nexport * from '@react-navigation/core';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,IAApB,QAAgC,QAAhC;AACA,SAASD,OAAO,IAAIE,cAApB,QAA0C,kBAA1C;AACA,SAASF,OAAO,IAAIG,mBAApB,QAA+C,uBAA/C;AACA,SAASH,OAAO,IAAII,eAApB,QAA2C,mBAA3C;AACA,SAASJ,OAAO,IAAIK,SAApB,QAAqC,qBAArC;AACA,SAASL,OAAO,IAAIM,YAApB,QAAwC,wBAAxC;AACA,SAASN,OAAO,IAAIO,aAApB,QAAyC,yBAAzC;AACA,SAASP,OAAO,IAAIQ,QAApB,QAAoC,oBAApC;AACA,cAAc,SAAd;AACA,SAASR,OAAO,IAAIS,cAApB,QAA0C,kBAA1C;AACA,SAAST,OAAO,IAAIU,YAApB,QAAwC,gBAAxC;AACA,SAASV,OAAO,IAAIW,SAApB,QAAqC,aAArC;AACA,SAASX,OAAO,IAAIY,cAApB,QAA0C,kBAA1C;AACA,cAAc,wBAAd"}
1
+ {"version":3,"names":["default","Link","LinkingContext","NavigationContainer","ServerContainer","DarkTheme","DefaultTheme","ThemeProvider","useTheme","useLinkBuilder","useLinkProps","useLinkTo","useScrollToTop"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,OAAO,IAAIC,IAAI,QAAQ,QAAQ;AACxC,SAASD,OAAO,IAAIE,cAAc,QAAQ,kBAAkB;AAC5D,SAASF,OAAO,IAAIG,mBAAmB,QAAQ,uBAAuB;AACtE,SAASH,OAAO,IAAII,eAAe,QAAQ,mBAAmB;AAC9D,SAASJ,OAAO,IAAIK,SAAS,QAAQ,qBAAqB;AAC1D,SAASL,OAAO,IAAIM,YAAY,QAAQ,wBAAwB;AAChE,SAASN,OAAO,IAAIO,aAAa,QAAQ,yBAAyB;AAClE,SAASP,OAAO,IAAIQ,QAAQ,QAAQ,oBAAoB;AACxD,cAAc,SAAS;AACvB,SAASR,OAAO,IAAIS,cAAc,QAAQ,kBAAkB;AAC5D,SAAST,OAAO,IAAIU,YAAY,QAAQ,gBAAgB;AACxD,SAASV,OAAO,IAAIW,SAAS,QAAQ,aAAa;AAClD,SAASX,OAAO,IAAIY,cAAc,QAAQ,kBAAkB;AAC5D,cAAc,wBAAwB"}
@@ -1 +1 @@
1
- {"version":3,"names":["DarkTheme","dark","colors","primary","background","card","text","border","notification"],"sources":["DarkTheme.tsx"],"sourcesContent":["import type { Theme } from '../types';\n\nconst DarkTheme: Theme = {\n dark: true,\n colors: {\n primary: 'rgb(10, 132, 255)',\n background: 'rgb(1, 1, 1)',\n card: 'rgb(18, 18, 18)',\n text: 'rgb(229, 229, 231)',\n border: 'rgb(39, 39, 41)',\n notification: 'rgb(255, 69, 58)',\n },\n};\n\nexport default DarkTheme;\n"],"mappings":"AAEA,MAAMA,SAAgB,GAAG;EACvBC,IAAI,EAAE,IADiB;EAEvBC,MAAM,EAAE;IACNC,OAAO,EAAE,mBADH;IAENC,UAAU,EAAE,cAFN;IAGNC,IAAI,EAAE,iBAHA;IAINC,IAAI,EAAE,oBAJA;IAKNC,MAAM,EAAE,iBALF;IAMNC,YAAY,EAAE;EANR;AAFe,CAAzB;AAYA,eAAeR,SAAf"}
1
+ {"version":3,"names":["DarkTheme","dark","colors","primary","background","card","text","border","notification"],"sourceRoot":"../../src","sources":["DarkTheme.tsx"],"mappings":"AAEA,MAAMA,SAAgB,GAAG;EACvBC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE;IACNC,OAAO,EAAE,mBAAmB;IAC5BC,UAAU,EAAE,cAAc;IAC1BC,IAAI,EAAE,iBAAiB;IACvBC,IAAI,EAAE,oBAAoB;IAC1BC,MAAM,EAAE,iBAAiB;IACzBC,YAAY,EAAE;EAChB;AACF,CAAC;AAED,eAAeR,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"names":["DefaultTheme","dark","colors","primary","background","card","text","border","notification"],"sources":["DefaultTheme.tsx"],"sourcesContent":["import type { Theme } from '../types';\n\nconst DefaultTheme: Theme = {\n dark: false,\n colors: {\n primary: 'rgb(0, 122, 255)',\n background: 'rgb(242, 242, 242)',\n card: 'rgb(255, 255, 255)',\n text: 'rgb(28, 28, 30)',\n border: 'rgb(216, 216, 216)',\n notification: 'rgb(255, 59, 48)',\n },\n};\n\nexport default DefaultTheme;\n"],"mappings":"AAEA,MAAMA,YAAmB,GAAG;EAC1BC,IAAI,EAAE,KADoB;EAE1BC,MAAM,EAAE;IACNC,OAAO,EAAE,kBADH;IAENC,UAAU,EAAE,oBAFN;IAGNC,IAAI,EAAE,oBAHA;IAINC,IAAI,EAAE,iBAJA;IAKNC,MAAM,EAAE,oBALF;IAMNC,YAAY,EAAE;EANR;AAFkB,CAA5B;AAYA,eAAeR,YAAf"}
1
+ {"version":3,"names":["DefaultTheme","dark","colors","primary","background","card","text","border","notification"],"sourceRoot":"../../src","sources":["DefaultTheme.tsx"],"mappings":"AAEA,MAAMA,YAAmB,GAAG;EAC1BC,IAAI,EAAE,KAAK;EACXC,MAAM,EAAE;IACNC,OAAO,EAAE,kBAAkB;IAC3BC,UAAU,EAAE,oBAAoB;IAChCC,IAAI,EAAE,oBAAoB;IAC1BC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAE,oBAAoB;IAC5BC,YAAY,EAAE;EAChB;AACF,CAAC;AAED,eAAeR,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"names":["React","DefaultTheme","ThemeContext","createContext","displayName"],"sources":["ThemeContext.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport type { Theme } from '../types';\nimport DefaultTheme from './DefaultTheme';\n\nconst ThemeContext = React.createContext<Theme>(DefaultTheme);\n\nThemeContext.displayName = 'ThemeContext';\n\nexport default ThemeContext;\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAGA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,MAAMC,YAAY,gBAAGF,KAAK,CAACG,aAAN,CAA2BF,YAA3B,CAArB;AAEAC,YAAY,CAACE,WAAb,GAA2B,cAA3B;AAEA,eAAeF,YAAf"}
1
+ {"version":3,"names":["React","DefaultTheme","ThemeContext","createContext","displayName"],"sourceRoot":"../../src","sources":["ThemeContext.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,OAAOC,YAAY,MAAM,gBAAgB;AAEzC,MAAMC,YAAY,gBAAGF,KAAK,CAACG,aAAa,CAAQF,YAAY,CAAC;AAE7DC,YAAY,CAACE,WAAW,GAAG,cAAc;AAEzC,eAAeF,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"names":["React","ThemeContext","ThemeProvider","value","children"],"sources":["ThemeProvider.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport type { Theme } from '../types';\nimport ThemeContext from './ThemeContext';\n\ntype Props = {\n value: Theme;\n children: React.ReactNode;\n};\n\nexport default function ThemeProvider({ value, children }: Props) {\n return (\n <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAGA,OAAOC,YAAP,MAAyB,gBAAzB;AAOA,eAAe,SAASC,aAAT,OAAmD;EAAA,IAA5B;IAAEC,KAAF;IAASC;EAAT,CAA4B;EAChE,oBACE,oBAAC,YAAD,CAAc,QAAd;IAAuB,KAAK,EAAED;EAA9B,GAAsCC,QAAtC,CADF;AAGD"}
1
+ {"version":3,"names":["React","ThemeContext","ThemeProvider","value","children"],"sourceRoot":"../../src","sources":["ThemeProvider.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,OAAOC,YAAY,MAAM,gBAAgB;AAOzC,eAAe,SAASC,aAAa,OAA6B;EAAA,IAA5B;IAAEC,KAAK;IAAEC;EAAgB,CAAC;EAC9D,oBACE,oBAAC,YAAY,CAAC,QAAQ;IAAC,KAAK,EAAED;EAAM,GAAEC,QAAQ,CAAyB;AAE3E"}
@@ -1 +1 @@
1
- {"version":3,"names":["React","ThemeContext","useTheme","theme","useContext"],"sources":["useTheme.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport ThemeContext from './ThemeContext';\n\nexport default function useTheme() {\n const theme = React.useContext(ThemeContext);\n\n return theme;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,eAAe,SAASC,QAAT,GAAoB;EACjC,MAAMC,KAAK,GAAGH,KAAK,CAACI,UAAN,CAAiBH,YAAjB,CAAd;EAEA,OAAOE,KAAP;AACD"}
1
+ {"version":3,"names":["React","ThemeContext","useTheme","theme","useContext"],"sourceRoot":"../../src","sources":["useTheme.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,OAAOC,YAAY,MAAM,gBAAgB;AAEzC,eAAe,SAASC,QAAQ,GAAG;EACjC,MAAMC,KAAK,GAAGH,KAAK,CAACI,UAAU,CAACH,YAAY,CAAC;EAE5C,OAAOE,KAAK;AACd"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.tsx"],"sourcesContent":["import type {\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n PathConfigMap,\n Route,\n} from '@react-navigation/core';\n\nexport type Theme = {\n dark: boolean;\n colors: {\n primary: string;\n background: string;\n card: string;\n text: string;\n border: string;\n notification: string;\n };\n};\n\nexport type LinkingOptions<ParamList extends {}> = {\n /**\n * Whether deep link handling should be enabled.\n * Defaults to true.\n */\n enabled?: boolean;\n /**\n * The prefixes are stripped from the URL before parsing them.\n * Usually they are the `scheme` + `host` (e.g. `myapp://chat?user=jane`)\n *\n * This is not supported on Web.\n *\n * @example\n * ```js\n * {\n * prefixes: [\n * \"myapp://\", // App-specific scheme\n * \"https://example.com\", // Prefix for universal links\n * \"https://*.example.com\" // Prefix which matches any subdomain\n * ]\n * }\n * ```\n */\n prefixes: string[];\n /**\n * Optional function which takes an incoming URL returns a boolean\n * indicating whether React Navigation should handle it.\n *\n * This can be used to disable deep linking for specific URLs.\n * e.g. URLs used for authentication, and not for deep linking to screens.\n *\n * This is not supported on Web.\n *\n * @example\n * ```js\n * {\n * // Filter out URLs used by expo-auth-session\n * filter: (url) => !url.includes('+expo-auth-session')\n * }\n * ```\n */\n filter?: (url: string) => boolean;\n /**\n * Config to fine-tune how to parse the path.\n *\n * @example\n * ```js\n * {\n * Chat: {\n * path: 'chat/:author/:id',\n * parse: { id: Number }\n * }\n * }\n * ```\n */\n config?: {\n initialRouteName?: keyof ParamList;\n screens: PathConfigMap<ParamList>;\n };\n /**\n * Custom function to get the initial URL used for linking.\n * Uses `Linking.getInitialURL()` by default.\n *\n * This is not supported on Web.\n *\n * @example\n * ```js\n * {\n * getInitialURL () => Linking.getInitialURL(),\n * }\n * ```\n */\n getInitialURL?: () =>\n | string\n | null\n | undefined\n | Promise<string | null | undefined>;\n /**\n * Custom function to get subscribe to URL updates.\n * Uses `Linking.addEventListener('url', callback)` by default.\n *\n * This is not supported on Web.\n *\n * @example\n * ```js\n * {\n * subscribe: (listener) => {\n * const onReceiveURL = ({ url }) => listener(url);\n *\n * Linking.addEventListener('url', onReceiveURL);\n *\n * return () => Linking.removeEventListener('url', onReceiveURL);\n * }\n * }\n * ```\n */\n subscribe?: (\n listener: (url: string) => void\n ) => undefined | void | (() => void);\n /**\n * Custom function to parse the URL to a valid navigation state (advanced).\n */\n getStateFromPath?: typeof getStateFromPathDefault;\n /**\n * Custom function to convert the state object to a valid URL (advanced).\n * Only applicable on Web.\n */\n getPathFromState?: typeof getPathFromStateDefault;\n /**\n * Custom function to convert the state object to a valid action (advanced).\n */\n getActionFromState?: typeof getActionFromStateDefault;\n};\n\nexport type DocumentTitleOptions = {\n enabled?: boolean;\n formatter?: (\n options: Record<string, any> | undefined,\n route: Route<string> | undefined\n ) => string;\n};\n\nexport type ServerContainerRef = {\n getCurrentOptions(): Record<string, any> | undefined;\n};\n"],"mappings":""}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.tsx"],"mappings":""}
@@ -4,16 +4,13 @@ export default function useBackButton(ref) {
4
4
  React.useEffect(() => {
5
5
  const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
6
6
  const navigation = ref.current;
7
-
8
7
  if (navigation == null) {
9
8
  return false;
10
9
  }
11
-
12
10
  if (navigation.canGoBack()) {
13
11
  navigation.goBack();
14
12
  return true;
15
13
  }
16
-
17
14
  return false;
18
15
  });
19
16
  return () => subscription.remove();
@@ -1 +1 @@
1
- {"version":3,"names":["React","BackHandler","useBackButton","ref","useEffect","subscription","addEventListener","navigation","current","canGoBack","goBack","remove"],"sources":["useBackButton.tsx"],"sourcesContent":["import type {\n NavigationContainerRef,\n ParamListBase,\n} from '@react-navigation/core';\nimport * as React from 'react';\nimport { BackHandler } from 'react-native';\n\nexport default function useBackButton(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>\n) {\n React.useEffect(() => {\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n () => {\n const navigation = ref.current;\n\n if (navigation == null) {\n return false;\n }\n\n if (navigation.canGoBack()) {\n navigation.goBack();\n\n return true;\n }\n\n return false;\n }\n );\n\n return () => subscription.remove();\n }, [ref]);\n}\n"],"mappings":"AAIA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,WAAT,QAA4B,cAA5B;AAEA,eAAe,SAASC,aAAT,CACbC,GADa,EAEb;EACAH,KAAK,CAACI,SAAN,CAAgB,MAAM;IACpB,MAAMC,YAAY,GAAGJ,WAAW,CAACK,gBAAZ,CACnB,mBADmB,EAEnB,MAAM;MACJ,MAAMC,UAAU,GAAGJ,GAAG,CAACK,OAAvB;;MAEA,IAAID,UAAU,IAAI,IAAlB,EAAwB;QACtB,OAAO,KAAP;MACD;;MAED,IAAIA,UAAU,CAACE,SAAX,EAAJ,EAA4B;QAC1BF,UAAU,CAACG,MAAX;QAEA,OAAO,IAAP;MACD;;MAED,OAAO,KAAP;IACD,CAhBkB,CAArB;IAmBA,OAAO,MAAML,YAAY,CAACM,MAAb,EAAb;EACD,CArBD,EAqBG,CAACR,GAAD,CArBH;AAsBD"}
1
+ {"version":3,"names":["React","BackHandler","useBackButton","ref","useEffect","subscription","addEventListener","navigation","current","canGoBack","goBack","remove"],"sourceRoot":"../../src","sources":["useBackButton.tsx"],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,WAAW,QAAQ,cAAc;AAE1C,eAAe,SAASC,aAAa,CACnCC,GAA2D,EAC3D;EACAH,KAAK,CAACI,SAAS,CAAC,MAAM;IACpB,MAAMC,YAAY,GAAGJ,WAAW,CAACK,gBAAgB,CAC/C,mBAAmB,EACnB,MAAM;MACJ,MAAMC,UAAU,GAAGJ,GAAG,CAACK,OAAO;MAE9B,IAAID,UAAU,IAAI,IAAI,EAAE;QACtB,OAAO,KAAK;MACd;MAEA,IAAIA,UAAU,CAACE,SAAS,EAAE,EAAE;QAC1BF,UAAU,CAACG,MAAM,EAAE;QAEnB,OAAO,IAAI;MACb;MAEA,OAAO,KAAK;IACd,CAAC,CACF;IAED,OAAO,MAAML,YAAY,CAACM,MAAM,EAAE;EACpC,CAAC,EAAE,CAACR,GAAG,CAAC,CAAC;AACX"}
@@ -1,29 +1,21 @@
1
1
  import * as React from 'react';
2
-
3
2
  /**
4
3
  * Set the document title for the active screen
5
4
  */
6
5
  export default function useDocumentTitle(ref) {
7
6
  let {
8
7
  enabled = true,
9
- formatter = (options, route) => {
10
- var _options$title;
11
-
12
- return (_options$title = options === null || options === void 0 ? void 0 : options.title) !== null && _options$title !== void 0 ? _options$title : route === null || route === void 0 ? void 0 : route.name;
13
- }
8
+ formatter = (options, route) => (options === null || options === void 0 ? void 0 : options.title) ?? (route === null || route === void 0 ? void 0 : route.name)
14
9
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15
10
  React.useEffect(() => {
16
11
  if (!enabled) {
17
12
  return;
18
13
  }
19
-
20
14
  const navigation = ref.current;
21
-
22
15
  if (navigation) {
23
16
  const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());
24
17
  document.title = title;
25
18
  }
26
-
27
19
  return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => {
28
20
  const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute());
29
21
  document.title = title;
@@ -1 +1 @@
1
- {"version":3,"names":["React","useDocumentTitle","ref","enabled","formatter","options","route","title","name","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"sources":["useDocumentTitle.tsx"],"sourcesContent":["import type {\n NavigationContainerRef,\n ParamListBase,\n} from '@react-navigation/core';\nimport * as React from 'react';\n\nimport type { DocumentTitleOptions } from './types';\n\n/**\n * Set the document title for the active screen\n */\nexport default function useDocumentTitle(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n enabled = true,\n formatter = (options, route) => options?.title ?? route?.name,\n }: DocumentTitleOptions = {}\n) {\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const navigation = ref.current;\n\n if (navigation) {\n const title = formatter(\n navigation.getCurrentOptions(),\n navigation.getCurrentRoute()\n );\n\n document.title = title;\n }\n\n return navigation?.addListener('options', (e) => {\n const title = formatter(e.data.options, navigation?.getCurrentRoute());\n\n document.title = title;\n });\n });\n}\n"],"mappings":"AAIA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAIA;AACA;AACA;AACA,eAAe,SAASC,gBAAT,CACbC,GADa,EAMb;EAAA,IAJA;IACEC,OAAO,GAAG,IADZ;IAEEC,SAAS,GAAG,CAACC,OAAD,EAAUC,KAAV;MAAA;;MAAA,yBAAoBD,OAApB,aAAoBA,OAApB,uBAAoBA,OAAO,CAAEE,KAA7B,2DAAsCD,KAAtC,aAAsCA,KAAtC,uBAAsCA,KAAK,CAAEE,IAA7C;IAAA;EAFd,CAIA,uEAD0B,EAC1B;EACAR,KAAK,CAACS,SAAN,CAAgB,MAAM;IACpB,IAAI,CAACN,OAAL,EAAc;MACZ;IACD;;IAED,MAAMO,UAAU,GAAGR,GAAG,CAACS,OAAvB;;IAEA,IAAID,UAAJ,EAAgB;MACd,MAAMH,KAAK,GAAGH,SAAS,CACrBM,UAAU,CAACE,iBAAX,EADqB,EAErBF,UAAU,CAACG,eAAX,EAFqB,CAAvB;MAKAC,QAAQ,CAACP,KAAT,GAAiBA,KAAjB;IACD;;IAED,OAAOG,UAAP,aAAOA,UAAP,uBAAOA,UAAU,CAAEK,WAAZ,CAAwB,SAAxB,EAAoCC,CAAD,IAAO;MAC/C,MAAMT,KAAK,GAAGH,SAAS,CAACY,CAAC,CAACC,IAAF,CAAOZ,OAAR,EAAiBK,UAAjB,aAAiBA,UAAjB,uBAAiBA,UAAU,CAAEG,eAAZ,EAAjB,CAAvB;MAEAC,QAAQ,CAACP,KAAT,GAAiBA,KAAjB;IACD,CAJM,CAAP;EAKD,CArBD;AAsBD"}
1
+ {"version":3,"names":["React","useDocumentTitle","ref","enabled","formatter","options","route","title","name","useEffect","navigation","current","getCurrentOptions","getCurrentRoute","document","addListener","e","data"],"sourceRoot":"../../src","sources":["useDocumentTitle.tsx"],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAI9B;AACA;AACA;AACA,eAAe,SAASC,gBAAgB,CACtCC,GAA2D,EAK3D;EAAA,IAJA;IACEC,OAAO,GAAG,IAAI;IACdC,SAAS,GAAG,CAACC,OAAO,EAAEC,KAAK,KAAK,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,KAAK,MAAID,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEE,IAAI;EACzC,CAAC,uEAAG,CAAC,CAAC;EAE5BR,KAAK,CAACS,SAAS,CAAC,MAAM;IACpB,IAAI,CAACN,OAAO,EAAE;MACZ;IACF;IAEA,MAAMO,UAAU,GAAGR,GAAG,CAACS,OAAO;IAE9B,IAAID,UAAU,EAAE;MACd,MAAMH,KAAK,GAAGH,SAAS,CACrBM,UAAU,CAACE,iBAAiB,EAAE,EAC9BF,UAAU,CAACG,eAAe,EAAE,CAC7B;MAEDC,QAAQ,CAACP,KAAK,GAAGA,KAAK;IACxB;IAEA,OAAOG,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,WAAW,CAAC,SAAS,EAAGC,CAAC,IAAK;MAC/C,MAAMT,KAAK,GAAGH,SAAS,CAACY,CAAC,CAACC,IAAI,CAACZ,OAAO,EAAEK,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEG,eAAe,EAAE,CAAC;MAEtEC,QAAQ,CAACP,KAAK,GAAGA,KAAK;IACxB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"}
@@ -1,3 +1,4 @@
1
- export default function useDocumentTitle() {// Noop for React Native
1
+ export default function useDocumentTitle() {
2
+ // Noop for React Native
2
3
  }
3
4
  //# sourceMappingURL=useDocumentTitle.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useDocumentTitle"],"sources":["useDocumentTitle.native.tsx"],"sourcesContent":["export default function useDocumentTitle() {\n // Noop for React Native\n}\n"],"mappings":"AAAA,eAAe,SAASA,gBAAT,GAA4B,CACzC;AACD"}
1
+ {"version":3,"names":["useDocumentTitle"],"sourceRoot":"../../src","sources":["useDocumentTitle.native.tsx"],"mappings":"AAAA,eAAe,SAASA,gBAAgB,GAAG;EACzC;AAAA"}
@@ -1,28 +1,25 @@
1
1
  import { getPathFromState, NavigationHelpersContext } from '@react-navigation/core';
2
2
  import * as React from 'react';
3
3
  import LinkingContext from './LinkingContext';
4
-
5
4
  const getRootStateForNavigate = (navigation, state) => {
6
5
  const parent = navigation.getParent();
7
-
8
6
  if (parent) {
9
7
  const parentState = parent.getState();
10
8
  return getRootStateForNavigate(parent, {
11
9
  index: 0,
12
- routes: [{ ...parentState.routes[parentState.index],
10
+ routes: [{
11
+ ...parentState.routes[parentState.index],
13
12
  state: state
14
13
  }]
15
14
  });
16
15
  }
17
-
18
16
  return state;
19
17
  };
18
+
20
19
  /**
21
20
  * Build destination link for a navigate action.
22
21
  * Useful for showing anchor tags on the web for buttons that perform navigation.
23
22
  */
24
-
25
-
26
23
  export default function useLinkBuilder() {
27
24
  const navigation = React.useContext(NavigationHelpersContext);
28
25
  const linking = React.useContext(LinkingContext);
@@ -30,18 +27,17 @@ export default function useLinkBuilder() {
30
27
  const {
31
28
  options
32
29
  } = linking;
33
-
34
30
  if ((options === null || options === void 0 ? void 0 : options.enabled) === false) {
35
31
  return undefined;
36
32
  }
37
-
38
33
  const state = navigation ? getRootStateForNavigate(navigation, {
39
34
  index: 0,
40
35
  routes: [{
41
36
  name,
42
37
  params
43
38
  }]
44
- }) : // If we couldn't find a navigation object in context, we're at root
39
+ }) :
40
+ // If we couldn't find a navigation object in context, we're at root
45
41
  // So we'll construct a basic state object to use
46
42
  {
47
43
  index: 0,
@@ -1 +1 @@
1
- {"version":3,"names":["getPathFromState","NavigationHelpersContext","React","LinkingContext","getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","useContext","linking","buildLink","useCallback","name","params","options","enabled","undefined","path","config"],"sources":["useLinkBuilder.tsx"],"sourcesContent":["import {\n getPathFromState,\n NavigationHelpers,\n NavigationHelpersContext,\n NavigationProp,\n ParamListBase,\n} from '@react-navigation/core';\nimport * as React from 'react';\n\nimport LinkingContext from './LinkingContext';\n\ntype NavigationObject =\n | NavigationHelpers<ParamListBase>\n | NavigationProp<ParamListBase>;\n\ntype MinimalState = {\n index: number;\n routes: { name: string; params?: object; state?: MinimalState }[];\n};\n\nconst getRootStateForNavigate = (\n navigation: NavigationObject,\n state: MinimalState\n): MinimalState => {\n const parent = navigation.getParent();\n\n if (parent) {\n const parentState = parent.getState();\n\n return getRootStateForNavigate(parent, {\n index: 0,\n routes: [\n {\n ...parentState.routes[parentState.index],\n state: state,\n },\n ],\n });\n }\n\n return state;\n};\n\n/**\n * Build destination link for a navigate action.\n * Useful for showing anchor tags on the web for buttons that perform navigation.\n */\nexport default function useLinkBuilder() {\n const navigation = React.useContext(NavigationHelpersContext);\n const linking = React.useContext(LinkingContext);\n\n const buildLink = React.useCallback(\n (name: string, params?: object) => {\n const { options } = linking;\n\n if (options?.enabled === false) {\n return undefined;\n }\n\n const state = navigation\n ? getRootStateForNavigate(navigation, {\n index: 0,\n routes: [{ name, params }],\n })\n : // If we couldn't find a navigation object in context, we're at root\n // So we'll construct a basic state object to use\n {\n index: 0,\n routes: [{ name, params }],\n };\n\n const path = options?.getPathFromState\n ? options.getPathFromState(state, options?.config)\n : getPathFromState(state, options?.config);\n\n return path;\n },\n [linking, navigation]\n );\n\n return buildLink;\n}\n"],"mappings":"AAAA,SACEA,gBADF,EAGEC,wBAHF,QAMO,wBANP;AAOA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,cAAP,MAA2B,kBAA3B;;AAWA,MAAMC,uBAAuB,GAAG,CAC9BC,UAD8B,EAE9BC,KAF8B,KAGb;EACjB,MAAMC,MAAM,GAAGF,UAAU,CAACG,SAAX,EAAf;;EAEA,IAAID,MAAJ,EAAY;IACV,MAAME,WAAW,GAAGF,MAAM,CAACG,QAAP,EAApB;IAEA,OAAON,uBAAuB,CAACG,MAAD,EAAS;MACrCI,KAAK,EAAE,CAD8B;MAErCC,MAAM,EAAE,CACN,EACE,GAAGH,WAAW,CAACG,MAAZ,CAAmBH,WAAW,CAACE,KAA/B,CADL;QAEEL,KAAK,EAAEA;MAFT,CADM;IAF6B,CAAT,CAA9B;EASD;;EAED,OAAOA,KAAP;AACD,CArBD;AAuBA;AACA;AACA;AACA;;;AACA,eAAe,SAASO,cAAT,GAA0B;EACvC,MAAMR,UAAU,GAAGH,KAAK,CAACY,UAAN,CAAiBb,wBAAjB,CAAnB;EACA,MAAMc,OAAO,GAAGb,KAAK,CAACY,UAAN,CAAiBX,cAAjB,CAAhB;EAEA,MAAMa,SAAS,GAAGd,KAAK,CAACe,WAAN,CAChB,CAACC,IAAD,EAAeC,MAAf,KAAmC;IACjC,MAAM;MAAEC;IAAF,IAAcL,OAApB;;IAEA,IAAI,CAAAK,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,OAAT,MAAqB,KAAzB,EAAgC;MAC9B,OAAOC,SAAP;IACD;;IAED,MAAMhB,KAAK,GAAGD,UAAU,GACpBD,uBAAuB,CAACC,UAAD,EAAa;MAClCM,KAAK,EAAE,CAD2B;MAElCC,MAAM,EAAE,CAAC;QAAEM,IAAF;QAAQC;MAAR,CAAD;IAF0B,CAAb,CADH,GAKpB;IACA;IACA;MACER,KAAK,EAAE,CADT;MAEEC,MAAM,EAAE,CAAC;QAAEM,IAAF;QAAQC;MAAR,CAAD;IAFV,CAPJ;IAYA,MAAMI,IAAI,GAAGH,OAAO,SAAP,IAAAA,OAAO,WAAP,IAAAA,OAAO,CAAEpB,gBAAT,GACToB,OAAO,CAACpB,gBAAR,CAAyBM,KAAzB,EAAgCc,OAAhC,aAAgCA,OAAhC,uBAAgCA,OAAO,CAAEI,MAAzC,CADS,GAETxB,gBAAgB,CAACM,KAAD,EAAQc,OAAR,aAAQA,OAAR,uBAAQA,OAAO,CAAEI,MAAjB,CAFpB;IAIA,OAAOD,IAAP;EACD,CAzBe,EA0BhB,CAACR,OAAD,EAAUV,UAAV,CA1BgB,CAAlB;EA6BA,OAAOW,SAAP;AACD"}
1
+ {"version":3,"names":["getPathFromState","NavigationHelpersContext","React","LinkingContext","getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","useContext","linking","buildLink","useCallback","name","params","options","enabled","undefined","path","config"],"sourceRoot":"../../src","sources":["useLinkBuilder.tsx"],"mappings":"AAA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