@react-motion-router/stack 2.0.0-beta.sha-1c021e3 → 2.0.0-beta.sha-6f2a71f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Navigation.d.ts +11 -10
- package/build/Router.d.ts +18 -8
- package/build/Screen.d.ts +48 -42
- package/build/common/constants.d.ts +1 -1
- package/build/common/events.d.ts +6 -6
- package/build/common/hooks.d.ts +2 -1
- package/build/common/promise-wrapper.d.ts +9 -0
- package/build/common/types.d.ts +11 -2
- package/build/common/utils.d.ts +2 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +335 -199
- package/build/index.js.map +1 -1
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -895,6 +895,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
895
895
|
"zF": () => (/* reexport */ FadeInKeyframes),
|
|
896
896
|
"JA": () => (/* reexport */ FadeOutKeyframes),
|
|
897
897
|
"rN": () => (/* reexport */ GestureRegion),
|
|
898
|
+
"c4": () => (/* reexport */ HistoryEntry),
|
|
898
899
|
"W_": () => (/* reexport */ Navigation),
|
|
899
900
|
"F0": () => (/* reexport */ Router),
|
|
900
901
|
"lL": () => (/* reexport */ Screen),
|
|
@@ -946,7 +947,7 @@ var web_gesture_events = __webpack_require__(190);
|
|
|
946
947
|
;// CONCATENATED MODULE: external "@react-motion-router/core"
|
|
947
948
|
var x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
|
|
948
949
|
var y = x => () => x
|
|
949
|
-
const core_namespaceObject = x({ ["NavigationBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.NavigationBase, ["RouterBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.RouterBase, ["ScreenBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.ScreenBase, ["includesRoute"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.includesRoute, ["isValidScreenChild"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.isValidScreenChild, ["matchRoute"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.matchRoute, ["resolveBaseURLFromPattern"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.resolveBaseURLFromPattern, ["useNavigationBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.useNavigationBase, ["useRouteBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.useRouteBase, ["useRouterBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.useRouterBase });
|
|
950
|
+
const core_namespaceObject = x({ ["NavigationBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.NavigationBase, ["RouterBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.RouterBase, ["ScreenBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.ScreenBase, ["cloneAndInject"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.cloneAndInject, ["includesRoute"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.includesRoute, ["isValidScreenChild"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.isValidScreenChild, ["matchRoute"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.matchRoute, ["resolveBaseURLFromPattern"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.resolveBaseURLFromPattern, ["useNavigationBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.useNavigationBase, ["useRouteBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.useRouteBase, ["useRouterBase"]: () => __WEBPACK_EXTERNAL_MODULE__react_motion_router_core_d1cff82c__.useRouterBase });
|
|
950
951
|
;// CONCATENATED MODULE: ./src/common/events.ts
|
|
951
952
|
class NavigateEvent extends Event {
|
|
952
953
|
routerId;
|
|
@@ -954,42 +955,42 @@ class NavigateEvent extends Event {
|
|
|
954
955
|
props;
|
|
955
956
|
navigationType;
|
|
956
957
|
signal;
|
|
957
|
-
|
|
958
|
+
committed;
|
|
958
959
|
transition;
|
|
959
|
-
constructor(routerId, route, props, type, signal,
|
|
960
|
+
constructor(routerId, route, props, type, signal, committed, transition) {
|
|
960
961
|
super('navigate');
|
|
961
962
|
this.routerId = routerId;
|
|
962
963
|
this.route = route;
|
|
963
964
|
this.props = props;
|
|
964
965
|
this.navigationType = type ?? "push";
|
|
965
966
|
this.signal = signal;
|
|
966
|
-
this.
|
|
967
|
+
this.committed = committed;
|
|
967
968
|
this.transition = transition;
|
|
968
969
|
}
|
|
969
970
|
}
|
|
970
971
|
class BackEvent extends Event {
|
|
971
972
|
routerId;
|
|
972
973
|
signal;
|
|
973
|
-
|
|
974
|
+
committed;
|
|
974
975
|
transition;
|
|
975
|
-
constructor(routerId, signal,
|
|
976
|
+
constructor(routerId, signal, committed, transition) {
|
|
976
977
|
super('back');
|
|
977
978
|
this.routerId = routerId;
|
|
978
979
|
this.signal = signal;
|
|
979
|
-
this.
|
|
980
|
+
this.committed = committed;
|
|
980
981
|
this.transition = transition;
|
|
981
982
|
}
|
|
982
983
|
}
|
|
983
984
|
class ForwardEvent extends Event {
|
|
984
985
|
routerId;
|
|
985
986
|
signal;
|
|
986
|
-
|
|
987
|
+
committed;
|
|
987
988
|
transition;
|
|
988
|
-
constructor(routerId, signal,
|
|
989
|
+
constructor(routerId, signal, committed, transition) {
|
|
989
990
|
super('forward');
|
|
990
991
|
this.routerId = routerId;
|
|
991
992
|
this.signal = signal;
|
|
992
|
-
this.
|
|
993
|
+
this.committed = committed;
|
|
993
994
|
this.transition = transition;
|
|
994
995
|
}
|
|
995
996
|
}
|
|
@@ -1068,12 +1069,9 @@ class HistoryEntry {
|
|
|
1068
1069
|
class Navigation extends core_namespaceObject.NavigationBase {
|
|
1069
1070
|
router;
|
|
1070
1071
|
constructor(router) {
|
|
1071
|
-
super(
|
|
1072
|
+
super();
|
|
1072
1073
|
this.router = router;
|
|
1073
1074
|
}
|
|
1074
|
-
traverseTo(key) {
|
|
1075
|
-
return window.navigation.traverseTo(key);
|
|
1076
|
-
}
|
|
1077
1075
|
replace(route, props = {}, options = {}) {
|
|
1078
1076
|
return this.navigate(route, props, { ...options, type: "replace" });
|
|
1079
1077
|
}
|
|
@@ -1083,6 +1081,24 @@ class Navigation extends core_namespaceObject.NavigationBase {
|
|
|
1083
1081
|
reload(props = {}) {
|
|
1084
1082
|
return window.navigation.reload({ state: props });
|
|
1085
1083
|
}
|
|
1084
|
+
traverseTo(key, options = {}) {
|
|
1085
|
+
const result = window.navigation.traverseTo(key);
|
|
1086
|
+
const transition = window.navigation.transition;
|
|
1087
|
+
const fromIndex = transition.from.index;
|
|
1088
|
+
const destinationIndex = window.navigation.entries().findIndex(entry => entry.key === key);
|
|
1089
|
+
const controller = new AbortController();
|
|
1090
|
+
controller.signal.addEventListener('abort', () => this.traverseTo(transition.from.key), { once: true });
|
|
1091
|
+
options.signal?.addEventListener('abort', controller.abort, { once: true });
|
|
1092
|
+
let event;
|
|
1093
|
+
if (fromIndex > destinationIndex) {
|
|
1094
|
+
event = this.createBackEvent(controller.signal, result.committed, transition);
|
|
1095
|
+
}
|
|
1096
|
+
else {
|
|
1097
|
+
event = this.createForwardEvent(controller.signal, result.committed, transition);
|
|
1098
|
+
}
|
|
1099
|
+
this.dispatchEvent?.(event);
|
|
1100
|
+
return result;
|
|
1101
|
+
}
|
|
1086
1102
|
navigate(route, props = {}, options = {}) {
|
|
1087
1103
|
const { type: history = "push" } = options;
|
|
1088
1104
|
const url = new URL(route, this.baseURL);
|
|
@@ -1091,50 +1107,51 @@ class Navigation extends core_namespaceObject.NavigationBase {
|
|
|
1091
1107
|
const controller = new AbortController();
|
|
1092
1108
|
controller.signal.addEventListener('abort', () => this.goBack(), { once: true });
|
|
1093
1109
|
options.signal?.addEventListener('abort', controller.abort, { once: true });
|
|
1094
|
-
const event = this.createNavigateEvent(route, props, history, controller.signal, result, transition);
|
|
1110
|
+
const event = this.createNavigateEvent(route, props, history, controller.signal, result.committed, transition);
|
|
1095
1111
|
this.dispatchEvent?.(event);
|
|
1096
1112
|
return result;
|
|
1097
1113
|
}
|
|
1098
1114
|
goBack(options = {}) {
|
|
1099
|
-
if (!this.canGoBack)
|
|
1115
|
+
if (!this.canGoBack())
|
|
1100
1116
|
return;
|
|
1101
|
-
const
|
|
1102
|
-
const result = window.navigation.traverseTo(previous.key);
|
|
1117
|
+
const result = window.navigation.traverseTo(this.previous.key);
|
|
1103
1118
|
const transition = window.navigation.transition;
|
|
1104
1119
|
const controller = new AbortController();
|
|
1105
1120
|
controller.signal.addEventListener('abort', () => this.goForward(), { once: true });
|
|
1106
1121
|
options.signal?.addEventListener('abort', controller.abort, { once: true });
|
|
1107
|
-
const event = this.createBackEvent(controller.signal, result, transition);
|
|
1122
|
+
const event = this.createBackEvent(controller.signal, result.committed, transition);
|
|
1108
1123
|
this.dispatchEvent?.(event);
|
|
1109
1124
|
return result;
|
|
1110
1125
|
}
|
|
1111
1126
|
goForward(options = {}) {
|
|
1112
|
-
if (!this.canGoForward)
|
|
1127
|
+
if (!this.canGoForward())
|
|
1113
1128
|
return;
|
|
1114
|
-
const
|
|
1115
|
-
const result = window.navigation.traverseTo(next.key);
|
|
1129
|
+
const result = window.navigation.traverseTo(this.next.key);
|
|
1116
1130
|
const transition = window.navigation.transition;
|
|
1117
1131
|
const controller = new AbortController();
|
|
1118
1132
|
controller.signal.addEventListener('abort', () => this.goBack(), { once: true });
|
|
1119
1133
|
options.signal?.addEventListener('abort', controller.abort, { once: true });
|
|
1120
|
-
const event = this.createForwardEvent(controller.signal, result, transition);
|
|
1134
|
+
const event = this.createForwardEvent(controller.signal, result.committed, transition);
|
|
1121
1135
|
this.dispatchEvent?.(event);
|
|
1122
1136
|
return result;
|
|
1123
1137
|
}
|
|
1124
|
-
createBackEvent(signal,
|
|
1138
|
+
createBackEvent(signal, committed, transition) {
|
|
1125
1139
|
if (!this.routerId)
|
|
1126
1140
|
throw new Error("Router ID is not set");
|
|
1127
|
-
return new BackEvent(this.routerId, signal,
|
|
1141
|
+
return new BackEvent(this.routerId, signal, committed, transition);
|
|
1128
1142
|
}
|
|
1129
|
-
createForwardEvent(signal,
|
|
1143
|
+
createForwardEvent(signal, committed, transition) {
|
|
1130
1144
|
if (!this.routerId)
|
|
1131
1145
|
throw new Error("Router ID is not set");
|
|
1132
|
-
return new ForwardEvent(this.routerId, signal,
|
|
1146
|
+
return new ForwardEvent(this.routerId, signal, committed, transition);
|
|
1133
1147
|
}
|
|
1134
|
-
createNavigateEvent(route, props, type, signal,
|
|
1148
|
+
createNavigateEvent(route, props, type, signal, committed, transition) {
|
|
1135
1149
|
if (!this.routerId)
|
|
1136
1150
|
throw new Error("Router ID is not set");
|
|
1137
|
-
return new NavigateEvent(this.routerId, route, props, type, signal,
|
|
1151
|
+
return new NavigateEvent(this.routerId, route, props, type, signal, committed, transition);
|
|
1152
|
+
}
|
|
1153
|
+
get committed() {
|
|
1154
|
+
return this.router.committed;
|
|
1138
1155
|
}
|
|
1139
1156
|
get transition() {
|
|
1140
1157
|
return this.router.state.transition;
|
|
@@ -1190,49 +1207,87 @@ class Navigation extends core_namespaceObject.NavigationBase {
|
|
|
1190
1207
|
get current() {
|
|
1191
1208
|
return this.entries[this.index];
|
|
1192
1209
|
}
|
|
1193
|
-
|
|
1210
|
+
canGoBack() {
|
|
1194
1211
|
return Boolean(this.previous?.sameDocument);
|
|
1195
1212
|
}
|
|
1196
|
-
|
|
1213
|
+
canGoForward() {
|
|
1197
1214
|
return Boolean(this.next?.sameDocument);
|
|
1198
1215
|
}
|
|
1199
1216
|
}
|
|
1200
1217
|
|
|
1218
|
+
;// CONCATENATED MODULE: ./src/common/utils.ts
|
|
1219
|
+
function searchParamsToObject(searchParams) {
|
|
1220
|
+
const entries = searchParams.entries();
|
|
1221
|
+
const result = {};
|
|
1222
|
+
for (const [key, value] of entries) { // each 'entry' is a [key, value] tuple
|
|
1223
|
+
let parsedValue = '';
|
|
1224
|
+
try {
|
|
1225
|
+
parsedValue = JSON.parse(value);
|
|
1226
|
+
}
|
|
1227
|
+
catch (e) {
|
|
1228
|
+
console.warn("Non JSON serialisable value was passed as URL route param.");
|
|
1229
|
+
parsedValue = value;
|
|
1230
|
+
}
|
|
1231
|
+
result[key] = parsedValue;
|
|
1232
|
+
}
|
|
1233
|
+
return Object.keys(result).length ? result : undefined;
|
|
1234
|
+
}
|
|
1235
|
+
function searchParamsFromObject(params) {
|
|
1236
|
+
try {
|
|
1237
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1238
|
+
params[key] = JSON.stringify(value);
|
|
1239
|
+
}
|
|
1240
|
+
return new URLSearchParams(params).toString();
|
|
1241
|
+
}
|
|
1242
|
+
catch (e) {
|
|
1243
|
+
console.error(e);
|
|
1244
|
+
console.warn("Non JSON serialisable value was passed as query param.");
|
|
1245
|
+
}
|
|
1246
|
+
return '';
|
|
1247
|
+
}
|
|
1248
|
+
function isGesture(info) {
|
|
1249
|
+
if (info && typeof info === 'object' && 'gesture' in info)
|
|
1250
|
+
return Boolean(info.gesture);
|
|
1251
|
+
return false;
|
|
1252
|
+
}
|
|
1253
|
+
function isRollback(info) {
|
|
1254
|
+
if (info && typeof info === 'object' && 'rollback' in info)
|
|
1255
|
+
return Boolean(info.rollback);
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
function deepEquals(obj1, obj2) {
|
|
1259
|
+
if (obj1 === obj2) {
|
|
1260
|
+
return true;
|
|
1261
|
+
}
|
|
1262
|
+
if (obj1 === null || obj2 === null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
const keys1 = Object.keys(obj1);
|
|
1266
|
+
const keys2 = Object.keys(obj2);
|
|
1267
|
+
if (keys1.length !== keys2.length) {
|
|
1268
|
+
return false;
|
|
1269
|
+
}
|
|
1270
|
+
for (let key of keys1) {
|
|
1271
|
+
if (!keys2.includes(key) || !deepEquals(obj1[key], obj2[key])) {
|
|
1272
|
+
return false;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
return true;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1201
1278
|
;// CONCATENATED MODULE: ./src/Screen.tsx
|
|
1202
1279
|
|
|
1280
|
+
|
|
1203
1281
|
class Screen extends core_namespaceObject.ScreenBase {
|
|
1204
|
-
|
|
1282
|
+
#historyEntry;
|
|
1205
1283
|
constructor(props, context) {
|
|
1206
1284
|
super(props, context);
|
|
1207
|
-
const
|
|
1208
|
-
const
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
setConfig,
|
|
1214
|
-
get path() {
|
|
1215
|
-
return getProps().path;
|
|
1216
|
-
},
|
|
1217
|
-
get resolvedPathname() {
|
|
1218
|
-
return getProps().resolvedPathname;
|
|
1219
|
-
},
|
|
1220
|
-
get focused() {
|
|
1221
|
-
return getState().focused;
|
|
1222
|
-
},
|
|
1223
|
-
get config() {
|
|
1224
|
-
return {
|
|
1225
|
-
...getProps().config,
|
|
1226
|
-
...context.screenState.get(this.path)?.config
|
|
1227
|
-
};
|
|
1228
|
-
},
|
|
1229
|
-
get params() {
|
|
1230
|
-
return {
|
|
1231
|
-
...getProps().defaultParams,
|
|
1232
|
-
...context.screenState.get(this.path)?.params
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
};
|
|
1285
|
+
const router = context;
|
|
1286
|
+
const id = this.internalProps.id;
|
|
1287
|
+
const historyEntry = router.navigation.entries.find(entry => entry.key === id);
|
|
1288
|
+
if (!historyEntry)
|
|
1289
|
+
throw new Error(`No history entry found for: ${id}`);
|
|
1290
|
+
this.#historyEntry = historyEntry;
|
|
1236
1291
|
}
|
|
1237
1292
|
static getDerivedStateFromProps(props) {
|
|
1238
1293
|
if (props.config?.presentation === "dialog"
|
|
@@ -1241,30 +1296,81 @@ class Screen extends core_namespaceObject.ScreenBase {
|
|
|
1241
1296
|
else
|
|
1242
1297
|
return { elementType: "div" };
|
|
1243
1298
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1299
|
+
setParams(newParams) {
|
|
1300
|
+
super.setParams(newParams);
|
|
1301
|
+
this.setHistoryState(({ params }) => ({ params: { ...params, ...newParams } }));
|
|
1302
|
+
}
|
|
1303
|
+
setConfig(newConfig) {
|
|
1304
|
+
super.setConfig(newConfig);
|
|
1305
|
+
this.setHistoryState(({ config }) => ({ config: { ...config, ...newConfig } }));
|
|
1306
|
+
}
|
|
1307
|
+
get router() {
|
|
1308
|
+
return this.context;
|
|
1309
|
+
}
|
|
1310
|
+
get internalProps() {
|
|
1311
|
+
return this.props;
|
|
1312
|
+
}
|
|
1313
|
+
get resolvedPathname() {
|
|
1314
|
+
return this.internalProps.resolvedPathname;
|
|
1315
|
+
}
|
|
1316
|
+
get historyEntryState() {
|
|
1317
|
+
const entry = this.#historyEntry;
|
|
1318
|
+
if (entry?.url) {
|
|
1319
|
+
const state = entry.getState() ?? {};
|
|
1320
|
+
const queryParams = searchParamsToObject(entry.url.searchParams);
|
|
1321
|
+
state.params = {
|
|
1322
|
+
...state.params,
|
|
1323
|
+
...queryParams
|
|
1324
|
+
};
|
|
1325
|
+
return state;
|
|
1326
|
+
}
|
|
1327
|
+
return {};
|
|
1328
|
+
}
|
|
1329
|
+
get id() {
|
|
1330
|
+
return this.internalProps.id.toString();
|
|
1249
1331
|
}
|
|
1250
1332
|
get params() {
|
|
1251
1333
|
return {
|
|
1252
1334
|
...this.props.defaultParams,
|
|
1253
|
-
...this.
|
|
1335
|
+
...this.historyEntryState.params,
|
|
1336
|
+
...this.state.params
|
|
1254
1337
|
};
|
|
1255
1338
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1339
|
+
get config() {
|
|
1340
|
+
return {
|
|
1341
|
+
...this.props.config,
|
|
1342
|
+
...this.historyEntryState.config,
|
|
1343
|
+
...this.state.config
|
|
1344
|
+
};
|
|
1260
1345
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1346
|
+
get routeProp() {
|
|
1347
|
+
const setParams = this.setParams.bind(this);
|
|
1348
|
+
const setConfig = this.setConfig.bind(this);
|
|
1349
|
+
const { path } = this.props;
|
|
1350
|
+
const { focused } = this.state;
|
|
1351
|
+
const { params, config, resolvedPathname } = this;
|
|
1352
|
+
return {
|
|
1353
|
+
setParams,
|
|
1354
|
+
setConfig,
|
|
1355
|
+
path,
|
|
1356
|
+
resolvedPathname,
|
|
1357
|
+
focused,
|
|
1358
|
+
params,
|
|
1359
|
+
config
|
|
1360
|
+
};
|
|
1265
1361
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1362
|
+
setHistoryState(newState) {
|
|
1363
|
+
if (!this.state.focused)
|
|
1364
|
+
return;
|
|
1365
|
+
const prevState = this.#historyEntry.getState() ?? {};
|
|
1366
|
+
if (newState instanceof Function) {
|
|
1367
|
+
newState = newState(prevState);
|
|
1368
|
+
}
|
|
1369
|
+
const state = {
|
|
1370
|
+
...prevState ?? {},
|
|
1371
|
+
...newState
|
|
1372
|
+
};
|
|
1373
|
+
window.navigation.updateCurrentEntry({ state });
|
|
1268
1374
|
}
|
|
1269
1375
|
onClickOutside(e) {
|
|
1270
1376
|
if (!this.transitionProvider.current?.ref.current)
|
|
@@ -1326,8 +1432,26 @@ function isRefObject(value) {
|
|
|
1326
1432
|
return true;
|
|
1327
1433
|
return false;
|
|
1328
1434
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1435
|
+
const directions = {
|
|
1436
|
+
"horizontal": ["left", "right"],
|
|
1437
|
+
"vertical": ["up", "down"],
|
|
1438
|
+
"up": ["up"],
|
|
1439
|
+
"down": ["down"],
|
|
1440
|
+
"left": ["left"],
|
|
1441
|
+
"right": ["right"]
|
|
1442
|
+
};
|
|
1443
|
+
function isSupportedDirection(direction, supported) {
|
|
1444
|
+
return directions[supported].includes(direction);
|
|
1445
|
+
}
|
|
1446
|
+
function isOutOfBounds(direction, { x, y }, clientRect, gestureAreaWidth) {
|
|
1447
|
+
if (direction === "right" && Math.abs(x - clientRect.left) >= gestureAreaWidth)
|
|
1448
|
+
return false;
|
|
1449
|
+
if (direction === "left" && Math.abs(x - clientRect.right) >= gestureAreaWidth)
|
|
1450
|
+
return false;
|
|
1451
|
+
if (direction === "down" && Math.abs(y - clientRect.top) >= gestureAreaWidth)
|
|
1452
|
+
return false;
|
|
1453
|
+
if (direction === "up" && Math.abs(y - clientRect.bottom) >= gestureAreaWidth)
|
|
1454
|
+
return false;
|
|
1331
1455
|
}
|
|
1332
1456
|
function isHorizontalDirection(direction) {
|
|
1333
1457
|
return direction === 'left' || direction === 'right' || direction === 'horizontal';
|
|
@@ -1339,67 +1463,41 @@ var external_react_ = __webpack_require__(810);
|
|
|
1339
1463
|
var external_web_animations_extension_x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
|
|
1340
1464
|
var external_web_animations_extension_y = x => () => x
|
|
1341
1465
|
const external_web_animations_extension_namespaceObject = external_web_animations_extension_x({ ["GestureTimeline"]: () => __WEBPACK_EXTERNAL_MODULE_web_animations_extension_74b2916c__.GestureTimeline, ["easingToLinear"]: () => __WEBPACK_EXTERNAL_MODULE_web_animations_extension_74b2916c__.easingToLinear, ["springToLinear"]: () => __WEBPACK_EXTERNAL_MODULE_web_animations_extension_74b2916c__.springToLinear });
|
|
1342
|
-
;// CONCATENATED MODULE: ./src/common/utils.ts
|
|
1343
|
-
function searchParamsToObject(searchPart) {
|
|
1344
|
-
const entries = new URLSearchParams(decodeURI(searchPart)).entries();
|
|
1345
|
-
const result = {};
|
|
1346
|
-
for (const [key, value] of entries) { // each 'entry' is a [key, value] tuple
|
|
1347
|
-
let parsedValue = '';
|
|
1348
|
-
try {
|
|
1349
|
-
parsedValue = JSON.parse(value);
|
|
1350
|
-
}
|
|
1351
|
-
catch (e) {
|
|
1352
|
-
console.warn("Non JSON serialisable value was passed as URL route param.");
|
|
1353
|
-
parsedValue = value;
|
|
1354
|
-
}
|
|
1355
|
-
result[key] = parsedValue;
|
|
1356
|
-
}
|
|
1357
|
-
return Object.keys(result).length ? result : undefined;
|
|
1358
|
-
}
|
|
1359
|
-
function searchParamsFromObject(params) {
|
|
1360
|
-
try {
|
|
1361
|
-
return new URLSearchParams(params).toString();
|
|
1362
|
-
}
|
|
1363
|
-
catch (e) {
|
|
1364
|
-
console.error(e);
|
|
1365
|
-
console.warn("Non JSON serialisable value was passed as query param.");
|
|
1366
|
-
}
|
|
1367
|
-
return '';
|
|
1368
|
-
}
|
|
1369
|
-
function isRollback(info) {
|
|
1370
|
-
if (info && typeof info === 'object' && 'rollback' in info)
|
|
1371
|
-
return Boolean(info.rollback);
|
|
1372
|
-
return false;
|
|
1373
|
-
}
|
|
1374
|
-
function deepEquals(obj1, obj2) {
|
|
1375
|
-
if (obj1 === obj2) {
|
|
1376
|
-
return true;
|
|
1377
|
-
}
|
|
1378
|
-
if (obj1 === null || obj2 === null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
|
|
1379
|
-
return false;
|
|
1380
|
-
}
|
|
1381
|
-
const keys1 = Object.keys(obj1);
|
|
1382
|
-
const keys2 = Object.keys(obj2);
|
|
1383
|
-
if (keys1.length !== keys2.length) {
|
|
1384
|
-
return false;
|
|
1385
|
-
}
|
|
1386
|
-
for (let key of keys1) {
|
|
1387
|
-
if (!keys2.includes(key) || !deepEquals(obj1[key], obj2[key])) {
|
|
1388
|
-
return false;
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
return true;
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
1466
|
;// CONCATENATED MODULE: ./src/common/constants.ts
|
|
1395
1467
|
const DEFAULT_GESTURE_CONFIG = {
|
|
1396
1468
|
gestureHysteresis: 0.5,
|
|
1397
1469
|
gestureMinFlingVelocity: 400,
|
|
1398
1470
|
gestureAreaWidth: 100,
|
|
1399
1471
|
gestureDirection: 'right',
|
|
1400
|
-
|
|
1472
|
+
gestureDisabled: false
|
|
1401
1473
|
};
|
|
1402
1474
|
|
|
1475
|
+
;// CONCATENATED MODULE: ./src/common/promise-wrapper.ts
|
|
1476
|
+
class PromiseWrapper {
|
|
1477
|
+
promise;
|
|
1478
|
+
state;
|
|
1479
|
+
nativeResolve;
|
|
1480
|
+
nativeReject;
|
|
1481
|
+
constructor() {
|
|
1482
|
+
this.state = 'pending';
|
|
1483
|
+
this.nativeResolve = this.nativeReject = null;
|
|
1484
|
+
this.promise = new Promise((resolve, reject) => {
|
|
1485
|
+
this.nativeResolve = resolve;
|
|
1486
|
+
this.nativeReject = reject;
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
resolve(value) {
|
|
1490
|
+
this.state = 'resolved';
|
|
1491
|
+
this.nativeResolve?.(value);
|
|
1492
|
+
}
|
|
1493
|
+
reject(reason) {
|
|
1494
|
+
this.state = 'rejected';
|
|
1495
|
+
// Do not report unhandled promise rejections.
|
|
1496
|
+
this.promise.catch(() => { });
|
|
1497
|
+
this.nativeReject?.(reason);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1403
1501
|
;// CONCATENATED MODULE: ./src/Router.tsx
|
|
1404
1502
|
|
|
1405
1503
|
|
|
@@ -1409,8 +1507,10 @@ const DEFAULT_GESTURE_CONFIG = {
|
|
|
1409
1507
|
|
|
1410
1508
|
|
|
1411
1509
|
|
|
1510
|
+
|
|
1412
1511
|
class Router extends core_namespaceObject.RouterBase {
|
|
1413
1512
|
navigation = new Navigation(this);
|
|
1513
|
+
#committed = null;
|
|
1414
1514
|
constructor(props, context) {
|
|
1415
1515
|
super(props, context);
|
|
1416
1516
|
this.state = {
|
|
@@ -1418,13 +1518,13 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1418
1518
|
gestureDirection: "horizontal",
|
|
1419
1519
|
gestureAreaWidth: 50,
|
|
1420
1520
|
gestureHysteresis: 0.5,
|
|
1421
|
-
|
|
1521
|
+
gestureDisabled: true,
|
|
1422
1522
|
gestureMinFlingVelocity: 500,
|
|
1423
1523
|
transition: null,
|
|
1424
|
-
backNavigating: false,
|
|
1425
1524
|
documentTitle: document.title,
|
|
1426
1525
|
fromKey: null,
|
|
1427
|
-
destinationKey: null
|
|
1526
|
+
destinationKey: null,
|
|
1527
|
+
controller: null
|
|
1428
1528
|
};
|
|
1429
1529
|
}
|
|
1430
1530
|
static defaultProps = {
|
|
@@ -1442,7 +1542,7 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1442
1542
|
gestureAreaWidth: config?.gestureAreaWidth ?? DEFAULT_GESTURE_CONFIG.gestureAreaWidth,
|
|
1443
1543
|
gestureMinFlingVelocity: config?.gestureMinFlingVelocity ?? DEFAULT_GESTURE_CONFIG.gestureMinFlingVelocity,
|
|
1444
1544
|
gestureHysteresis: config?.gestureHysteresis ?? DEFAULT_GESTURE_CONFIG.gestureHysteresis,
|
|
1445
|
-
|
|
1545
|
+
gestureDisabled: config?.gestureDisabled ?? DEFAULT_GESTURE_CONFIG.gestureDisabled,
|
|
1446
1546
|
documentTitle: config?.title
|
|
1447
1547
|
};
|
|
1448
1548
|
}
|
|
@@ -1450,6 +1550,10 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1450
1550
|
super.componentDidMount();
|
|
1451
1551
|
this.ref.current?.addEventListener('swipestart', this.onSwipeStart);
|
|
1452
1552
|
this.ref.current?.addEventListener('swipeend', this.onSwipeEnd);
|
|
1553
|
+
window.navigation.addEventListener("currententrychange", this.onCurrentEntryChange);
|
|
1554
|
+
window.navigation.addEventListener("navigate", this.onNavigate);
|
|
1555
|
+
window.navigation.addEventListener("navigatesuccess", this.onNavigateSuccess);
|
|
1556
|
+
window.navigation.addEventListener("navigateerror", this.onNavigateError);
|
|
1453
1557
|
}
|
|
1454
1558
|
shouldComponentUpdate(nextProps, nextState) {
|
|
1455
1559
|
return (!deepEquals(this.props.config, nextProps.config)
|
|
@@ -1459,29 +1563,44 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1459
1563
|
componentWillUnmount() {
|
|
1460
1564
|
this.ref.current?.removeEventListener('swipestart', this.onSwipeStart);
|
|
1461
1565
|
this.ref.current?.removeEventListener('swipeend', this.onSwipeEnd);
|
|
1566
|
+
window.navigation.removeEventListener("currententrychange", this.onCurrentEntryChange);
|
|
1567
|
+
window.navigation.removeEventListener("navigate", this.onNavigate);
|
|
1568
|
+
window.navigation.removeEventListener("navigatesuccess", this.onNavigateSuccess);
|
|
1569
|
+
window.navigation.removeEventListener("navigateerror", this.onNavigateError);
|
|
1462
1570
|
}
|
|
1571
|
+
onNavigate = () => {
|
|
1572
|
+
this.#committed = new PromiseWrapper();
|
|
1573
|
+
};
|
|
1574
|
+
onCurrentEntryChange = () => {
|
|
1575
|
+
this.#committed?.nativeResolve?.(window.navigation.currentEntry);
|
|
1576
|
+
};
|
|
1577
|
+
onNavigateSuccess = () => {
|
|
1578
|
+
this.#committed = null;
|
|
1579
|
+
};
|
|
1580
|
+
onNavigateError = ({ error }) => {
|
|
1581
|
+
if (this.#committed?.state === "pending")
|
|
1582
|
+
this.#committed.nativeReject?.(error); // TODO: find out what the spec does for cancelled navigations
|
|
1583
|
+
this.#committed = null;
|
|
1584
|
+
};
|
|
1585
|
+
onGestureCancel = () => {
|
|
1586
|
+
if (!this.state.transition)
|
|
1587
|
+
throw new Error("Rollback failed, transition is null");
|
|
1588
|
+
window.navigation.traverseTo(this.state.transition.from.key, { info: { rollback: true } });
|
|
1589
|
+
};
|
|
1463
1590
|
canGestureNavigate(e) {
|
|
1464
1591
|
if (!this.ref.current)
|
|
1465
1592
|
return false;
|
|
1466
|
-
if (this.state.
|
|
1593
|
+
if (this.state.gestureDisabled)
|
|
1467
1594
|
return false;
|
|
1468
1595
|
const clientRect = this.ref.current.getBoundingClientRect();
|
|
1469
1596
|
const { direction } = e;
|
|
1470
|
-
if ((direction === "down" || direction === "right") && !this.navigation.canGoBack)
|
|
1471
|
-
return false;
|
|
1472
|
-
if ((direction === "up" || direction === "left") && !this.navigation.canGoForward)
|
|
1473
|
-
return false;
|
|
1474
|
-
if (isHorizontalDirection(direction) !== isHorizontalDirection(this.state.gestureDirection))
|
|
1475
|
-
return false;
|
|
1476
|
-
if (direction === "right" && Math.abs(e.x - clientRect.left) >= this.state.gestureAreaWidth)
|
|
1477
|
-
return false;
|
|
1478
|
-
if (direction === "left" && Math.abs(e.x - clientRect.right) >= this.state.gestureAreaWidth)
|
|
1597
|
+
if ((direction === "down" || direction === "right") && !this.navigation.canGoBack())
|
|
1479
1598
|
return false;
|
|
1480
|
-
if (direction === "
|
|
1599
|
+
if ((direction === "up" || direction === "left") && !this.navigation.canGoForward())
|
|
1481
1600
|
return false;
|
|
1482
|
-
if (direction
|
|
1601
|
+
if (isOutOfBounds(direction, e, clientRect, this.state.gestureAreaWidth))
|
|
1483
1602
|
return false;
|
|
1484
|
-
return
|
|
1603
|
+
return isSupportedDirection(direction, this.state.gestureDirection);
|
|
1485
1604
|
}
|
|
1486
1605
|
onSwipeStart = (e) => {
|
|
1487
1606
|
if (!this.canGestureNavigate(e))
|
|
@@ -1517,10 +1636,11 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1517
1636
|
rangeStart,
|
|
1518
1637
|
rangeEnd
|
|
1519
1638
|
});
|
|
1639
|
+
const gesture = true;
|
|
1520
1640
|
if (direction === "down" || direction === "right")
|
|
1521
|
-
this.navigation.
|
|
1641
|
+
window.navigation.traverseTo(this.navigation.previous.key, { info: { gesture } });
|
|
1522
1642
|
else
|
|
1523
|
-
this.navigation.
|
|
1643
|
+
window.navigation.traverseTo(this.navigation.next.key, { info: { gesture } });
|
|
1524
1644
|
this.dispatchEvent(new GestureStartEvent(e));
|
|
1525
1645
|
};
|
|
1526
1646
|
onSwipeEnd = (e) => {
|
|
@@ -1530,22 +1650,29 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1530
1650
|
const playbackRate = this.screenTransitionLayer.current.animation.playbackRate;
|
|
1531
1651
|
this.screenTransitionLayer.current.animation.timeline = document.timeline;
|
|
1532
1652
|
const hysteresisReached = playbackRate > 0 ? progress > this.state.gestureHysteresis : progress < this.state.gestureHysteresis;
|
|
1533
|
-
let
|
|
1653
|
+
let gestureCancelled = false;
|
|
1534
1654
|
if (e.velocity < this.state.gestureMinFlingVelocity && !hysteresisReached) {
|
|
1655
|
+
gestureCancelled = true;
|
|
1535
1656
|
this.screenTransitionLayer.current.animation.reverse();
|
|
1536
|
-
rollback = true;
|
|
1537
1657
|
this.dispatchEvent(new GestureCancelEvent());
|
|
1538
1658
|
}
|
|
1539
1659
|
else {
|
|
1540
1660
|
this.dispatchEvent(new GestureEndEvent(e));
|
|
1541
1661
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
window.navigation.traverseTo(fromKey.toString(), { info: { rollback } });
|
|
1662
|
+
if (gestureCancelled) {
|
|
1663
|
+
this.screenTransitionLayer.current.animation.finished.then(() => {
|
|
1664
|
+
this.state.controller?.abort("gesture-cancel");
|
|
1546
1665
|
});
|
|
1547
1666
|
}
|
|
1548
1667
|
};
|
|
1668
|
+
get committed() {
|
|
1669
|
+
return this.#committed?.promise ?? null;
|
|
1670
|
+
}
|
|
1671
|
+
get backNavigating() {
|
|
1672
|
+
const fromIndex = this.state.screenStack.findIndex(screen => screen.key === this.state.fromKey);
|
|
1673
|
+
const destinationIndex = this.state.screenStack.findIndex(screen => screen.key === this.state.destinationKey);
|
|
1674
|
+
return destinationIndex >= 0 && destinationIndex < fromIndex;
|
|
1675
|
+
}
|
|
1549
1676
|
get screens() {
|
|
1550
1677
|
const screenStack = this.state.screenStack;
|
|
1551
1678
|
return screenStack
|
|
@@ -1560,26 +1687,23 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1560
1687
|
|| screen.key === this.state.destinationKey;
|
|
1561
1688
|
});
|
|
1562
1689
|
}
|
|
1563
|
-
screenChildFromPathname(pathname, key
|
|
1690
|
+
screenChildFromPathname(pathname, key) {
|
|
1564
1691
|
const screenChild = external_react_.Children.toArray(this.props.children)
|
|
1565
|
-
.find(child => {
|
|
1692
|
+
.find((child) => {
|
|
1566
1693
|
if (!(0,core_namespaceObject.isValidScreenChild)(child))
|
|
1567
|
-
return;
|
|
1568
|
-
return (0,core_namespaceObject.matchRoute)(child.props.path, pathname, this.baseURLPattern.pathname, child.props.caseSensitive);
|
|
1694
|
+
return false;
|
|
1695
|
+
return (0,core_namespaceObject.matchRoute)(child.props.path, pathname, this.baseURLPattern.pathname, child.props.caseSensitive) !== null;
|
|
1569
1696
|
});
|
|
1570
|
-
if (!
|
|
1697
|
+
if (!screenChild)
|
|
1571
1698
|
return null;
|
|
1572
|
-
|
|
1699
|
+
key ??= crypto.randomUUID();
|
|
1700
|
+
return (0,core_namespaceObject.cloneAndInject)(screenChild, {
|
|
1573
1701
|
config: {
|
|
1574
1702
|
title: document.title,
|
|
1575
1703
|
...this.props.config?.screenConfig,
|
|
1576
|
-
...screenChild.props.config
|
|
1577
|
-
...config
|
|
1578
|
-
},
|
|
1579
|
-
defaultParams: {
|
|
1580
|
-
...screenChild.props.defaultParams,
|
|
1581
|
-
...params
|
|
1704
|
+
...screenChild.props.config
|
|
1582
1705
|
},
|
|
1706
|
+
id: key,
|
|
1583
1707
|
resolvedPathname: pathname,
|
|
1584
1708
|
key,
|
|
1585
1709
|
ref: (0,external_react_.createRef)()
|
|
@@ -1641,9 +1765,7 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1641
1765
|
entries.forEach((entry) => {
|
|
1642
1766
|
if (!entry.url)
|
|
1643
1767
|
return null;
|
|
1644
|
-
const
|
|
1645
|
-
const queryParams = searchParamsToObject(entry.url.search);
|
|
1646
|
-
const screen = this.screenChildFromPathname(entry.url.pathname, entry.key, config, { ...queryParams, ...params });
|
|
1768
|
+
const screen = this.screenChildFromPathname(entry.url.pathname, entry.key);
|
|
1647
1769
|
if (!screen)
|
|
1648
1770
|
return null;
|
|
1649
1771
|
screenStack.push(screen);
|
|
@@ -1680,10 +1802,8 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1680
1802
|
const screenStack = this.state.screenStack;
|
|
1681
1803
|
const destination = e.destination;
|
|
1682
1804
|
const destinationPathname = new URL(destination.url).pathname;
|
|
1683
|
-
const { params, config } = destination.getState() ?? {};
|
|
1684
|
-
const queryParams = searchParamsToObject(new URL(destination.url).search);
|
|
1685
1805
|
const destinationKey = window.navigation.currentEntry?.key ?? destination.key;
|
|
1686
|
-
const destinationScreen = this.screenChildFromPathname(destinationPathname, destinationKey
|
|
1806
|
+
const destinationScreen = this.screenChildFromPathname(destinationPathname, destinationKey);
|
|
1687
1807
|
if (!destinationScreen)
|
|
1688
1808
|
return e.preventDefault();
|
|
1689
1809
|
const handler = () => {
|
|
@@ -1691,7 +1811,6 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1691
1811
|
const transition = this.state.transition ?? window.navigation.transition;
|
|
1692
1812
|
const fromKey = transition?.from?.key ?? null;
|
|
1693
1813
|
const currentIndex = screenStack.findIndex(screen => screen.key === this.navigation.current?.key);
|
|
1694
|
-
const backNavigating = this.state.backNavigating;
|
|
1695
1814
|
screenStack.splice(currentIndex, 1, destinationScreen);
|
|
1696
1815
|
return new Promise((resolve, reject) => (0,external_react_.startTransition)(() => {
|
|
1697
1816
|
this.setState({ destinationKey, fromKey, transition, screenStack }, async () => {
|
|
@@ -1703,7 +1822,7 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1703
1822
|
const currentTime = this.screenTransitionLayer.current?.animation.currentTime ?? 0;
|
|
1704
1823
|
this.screenTransitionLayer.current?.animation.cancel();
|
|
1705
1824
|
await new Promise(requestAnimationFrame);
|
|
1706
|
-
const animation = this.screenTransition(incomingScreen, outgoingScreen
|
|
1825
|
+
const animation = this.screenTransition(incomingScreen, outgoingScreen);
|
|
1707
1826
|
if (animation) {
|
|
1708
1827
|
animation.currentTime = currentTime;
|
|
1709
1828
|
}
|
|
@@ -1724,6 +1843,8 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1724
1843
|
if (!(0,core_namespaceObject.isValidScreenChild)(this.getScreenChildByPathname(destinationPathname)))
|
|
1725
1844
|
return e.preventDefault();
|
|
1726
1845
|
const handler = () => {
|
|
1846
|
+
if (isRollback(e.info))
|
|
1847
|
+
return Promise.resolve();
|
|
1727
1848
|
const transition = window.navigation.transition;
|
|
1728
1849
|
let fromIndex = screenStack.findIndex(screen => screen.key === transition?.from.key);
|
|
1729
1850
|
if (fromIndex === -1 && e.navigationType === "traverse") {
|
|
@@ -1738,51 +1859,62 @@ class Router extends core_namespaceObject.RouterBase {
|
|
|
1738
1859
|
const fromKey = (screenStack[fromIndex]?.key || transition?.from.key) ?? null;
|
|
1739
1860
|
const destinationIndex = screenStack.findIndex(screen => screen.key === e.destination.key);
|
|
1740
1861
|
const destinationKey = (screenStack[destinationIndex]?.key || window.navigation.currentEntry?.key) ?? null;
|
|
1741
|
-
const backNavigating = destinationIndex >= 0 && destinationIndex < fromIndex;
|
|
1742
1862
|
if (e.navigationType === "push") {
|
|
1743
|
-
const { params, config } = destination.getState() ?? {};
|
|
1744
1863
|
const destinationPathname = new URL(destination.url).pathname;
|
|
1745
|
-
const
|
|
1746
|
-
const destinationScreen = this.screenChildFromPathname(destinationPathname, destinationKey, config, { ...queryParams, ...params });
|
|
1864
|
+
const destinationScreen = this.screenChildFromPathname(destinationPathname, destinationKey);
|
|
1747
1865
|
if (!destinationScreen)
|
|
1748
1866
|
return Promise.resolve();
|
|
1749
1867
|
screenStack.splice(fromIndex + 1, Infinity, // Remove all screens after current
|
|
1750
1868
|
destinationScreen);
|
|
1751
1869
|
}
|
|
1870
|
+
const controller = new AbortController();
|
|
1752
1871
|
return new Promise((resolve, reject) => (0,external_react_.startTransition)(() => {
|
|
1753
|
-
this.setState({ destinationKey, fromKey, transition, screenStack
|
|
1872
|
+
this.setState({ controller, destinationKey, fromKey, transition, screenStack }, async () => {
|
|
1873
|
+
controller.signal.onabort = reject;
|
|
1754
1874
|
const signal = e.signal;
|
|
1755
1875
|
const outgoingScreen = this.getScreenRefByKey(String(fromKey));
|
|
1756
1876
|
const incomingScreen = this.getScreenRefByKey(String(destinationKey));
|
|
1757
1877
|
const pendingLifecycleHandlers = this.dispatchLifecycleHandlers(incomingScreen, outgoingScreen, signal).catch(reject);
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
animation?.finished.catch(reject);
|
|
1762
|
-
}
|
|
1878
|
+
const animation = this.screenTransition(incomingScreen, outgoingScreen);
|
|
1879
|
+
animation?.updatePlaybackRate(1);
|
|
1880
|
+
animation?.finished.catch(reject);
|
|
1763
1881
|
await pendingLifecycleHandlers;
|
|
1764
|
-
this.setState({ destinationKey: null, fromKey: null, transition: null }, resolve);
|
|
1882
|
+
this.setState({ destinationKey: null, fromKey: null, transition: null, controller: null }, resolve);
|
|
1765
1883
|
});
|
|
1766
1884
|
}));
|
|
1767
1885
|
};
|
|
1768
|
-
|
|
1886
|
+
let commit;
|
|
1887
|
+
if (isGesture(e.info)) {
|
|
1888
|
+
commit = "after-transition";
|
|
1889
|
+
this.addEventListener("gesture-end", () => e.commit?.(), { once: true });
|
|
1890
|
+
this.addEventListener("gesture-cancel", this.onGestureCancel, { once: true });
|
|
1891
|
+
}
|
|
1892
|
+
else {
|
|
1893
|
+
commit = "immediate";
|
|
1894
|
+
}
|
|
1895
|
+
const options = { handler, commit };
|
|
1896
|
+
e.intercept(options);
|
|
1769
1897
|
}
|
|
1770
1898
|
async dispatchLifecycleHandlers(incomingScreen, outgoingScreen, signal) {
|
|
1771
1899
|
let animationStarted = false;
|
|
1772
1900
|
this.addEventListener('transition-start', () => animationStarted = true, { once: true });
|
|
1773
1901
|
await Promise.all([
|
|
1774
|
-
outgoingScreen?.current?.onExit(signal)
|
|
1775
|
-
incomingScreen?.current?.onEnter(signal)
|
|
1902
|
+
outgoingScreen?.current?.onExit(signal),
|
|
1903
|
+
incomingScreen?.current?.onEnter(signal),
|
|
1776
1904
|
incomingScreen?.current?.load(signal)
|
|
1777
1905
|
]);
|
|
1778
1906
|
if (animationStarted)
|
|
1779
1907
|
await new Promise((resolve) => this.addEventListener('transition-end', resolve, { once: true }));
|
|
1908
|
+
// if gesture navigation cancelled then exit here
|
|
1909
|
+
if (this.state.controller?.signal.aborted)
|
|
1910
|
+
return;
|
|
1780
1911
|
await Promise.all([
|
|
1781
|
-
outgoingScreen?.current?.onExited(signal),
|
|
1782
|
-
incomingScreen?.current?.onEntered(signal)
|
|
1912
|
+
outgoingScreen?.current?.onExited(signal).then(() => outgoingScreen.current?.blur()),
|
|
1913
|
+
incomingScreen?.current?.onEntered(signal).then(() => incomingScreen.current?.focus())
|
|
1783
1914
|
]);
|
|
1784
1915
|
}
|
|
1785
|
-
screenTransition(incomingScreen, outgoingScreen
|
|
1916
|
+
screenTransition(incomingScreen, outgoingScreen) {
|
|
1917
|
+
const { backNavigating } = this;
|
|
1786
1918
|
if (this.screenTransitionLayer.current && incomingScreen && outgoingScreen) {
|
|
1787
1919
|
this.screenTransitionLayer.current.direction = backNavigating ? 'reverse' : 'normal';
|
|
1788
1920
|
if (incomingScreen.current?.transitionProvider.current) {
|
|
@@ -1818,15 +1950,15 @@ var jsx_runtime = __webpack_require__(322);
|
|
|
1818
1950
|
|
|
1819
1951
|
|
|
1820
1952
|
function useNavigation() {
|
|
1821
|
-
(0,external_react_.useDebugValue)("
|
|
1953
|
+
(0,external_react_.useDebugValue)("Stack.Navigation");
|
|
1822
1954
|
return (0,core_namespaceObject.useNavigationBase)();
|
|
1823
1955
|
}
|
|
1824
1956
|
function useRouter() {
|
|
1825
|
-
(0,external_react_.useDebugValue)("
|
|
1957
|
+
(0,external_react_.useDebugValue)("Stack.Router");
|
|
1826
1958
|
return (0,core_namespaceObject.useRouterBase)();
|
|
1827
1959
|
}
|
|
1828
1960
|
function useRoute() {
|
|
1829
|
-
(0,external_react_.useDebugValue)("
|
|
1961
|
+
(0,external_react_.useDebugValue)("Stack.Route");
|
|
1830
1962
|
return (0,core_namespaceObject.useRouteBase)();
|
|
1831
1963
|
}
|
|
1832
1964
|
|
|
@@ -2286,6 +2418,8 @@ function androidScaleFromCentre({ ref, direction, index, playbackRate }) {
|
|
|
2286
2418
|
function GestureRegion({ disabled, children, ...props }) {
|
|
2287
2419
|
const ref = (0,external_react_.useRef)(null);
|
|
2288
2420
|
(0,external_react_.useEffect)(() => {
|
|
2421
|
+
if (disabled)
|
|
2422
|
+
return;
|
|
2289
2423
|
const onSwipeStart = (e) => {
|
|
2290
2424
|
e.stopPropagation();
|
|
2291
2425
|
e.preventDefault();
|
|
@@ -2294,7 +2428,7 @@ function GestureRegion({ disabled, children, ...props }) {
|
|
|
2294
2428
|
return () => {
|
|
2295
2429
|
ref.current?.removeEventListener('swipestart', onSwipeStart);
|
|
2296
2430
|
};
|
|
2297
|
-
}, [ref]);
|
|
2431
|
+
}, [ref, disabled]);
|
|
2298
2432
|
return ((0,jsx_runtime.jsx)("div", { ref: ref, className: "gesture-region", "data-disabled": disabled, style: { display: 'contents' }, ...props, children: children }));
|
|
2299
2433
|
}
|
|
2300
2434
|
|
|
@@ -2311,12 +2445,14 @@ function GestureRegion({ disabled, children, ...props }) {
|
|
|
2311
2445
|
|
|
2312
2446
|
|
|
2313
2447
|
|
|
2448
|
+
|
|
2314
2449
|
})();
|
|
2315
2450
|
|
|
2316
2451
|
var __webpack_exports__Anchor = __webpack_exports__.ee;
|
|
2317
2452
|
var __webpack_exports__FadeInKeyframes = __webpack_exports__.zF;
|
|
2318
2453
|
var __webpack_exports__FadeOutKeyframes = __webpack_exports__.JA;
|
|
2319
2454
|
var __webpack_exports__GestureRegion = __webpack_exports__.rN;
|
|
2455
|
+
var __webpack_exports__HistoryEntry = __webpack_exports__.c4;
|
|
2320
2456
|
var __webpack_exports__Navigation = __webpack_exports__.W_;
|
|
2321
2457
|
var __webpack_exports__Router = __webpack_exports__.F0;
|
|
2322
2458
|
var __webpack_exports__Screen = __webpack_exports__.lL;
|
|
@@ -2361,6 +2497,6 @@ var __webpack_exports__iOSSlideOutToRightKeyframes = __webpack_exports__.Cj;
|
|
|
2361
2497
|
var __webpack_exports__useNavigation = __webpack_exports__.HJ;
|
|
2362
2498
|
var __webpack_exports__useRoute = __webpack_exports__.yj;
|
|
2363
2499
|
var __webpack_exports__useRouter = __webpack_exports__.tv;
|
|
2364
|
-
export { __webpack_exports__Anchor as Anchor, __webpack_exports__FadeInKeyframes as FadeInKeyframes, __webpack_exports__FadeOutKeyframes as FadeOutKeyframes, __webpack_exports__GestureRegion as GestureRegion, __webpack_exports__Navigation as Navigation, __webpack_exports__Router as Router, __webpack_exports__Screen as Screen, __webpack_exports__SlideInFromBottomKeyframes as SlideInFromBottomKeyframes, __webpack_exports__SlideInFromLeftKeyframes as SlideInFromLeftKeyframes, __webpack_exports__SlideInFromRightKeyframes as SlideInFromRightKeyframes, __webpack_exports__SlideInFromTopKeyframes as SlideInFromTopKeyframes, __webpack_exports__SlideOutToBottomKeyframes as SlideOutToBottomKeyframes, __webpack_exports__SlideOutToLeftKeyframes as SlideOutToLeftKeyframes, __webpack_exports__SlideOutToRightKeyframes as SlideOutToRightKeyframes, __webpack_exports__SlideOutToTopKeyframes as SlideOutToTopKeyframes, __webpack_exports__ZoomInKeyframes as ZoomInKeyframes, __webpack_exports__ZoomOutKeyframes as ZoomOutKeyframes, __webpack_exports__androidBottomSheetSlideInOptions as androidBottomSheetSlideInOptions, __webpack_exports__androidBottomSheetSlideOutOptions as androidBottomSheetSlideOutOptions, __webpack_exports__androidConcealToBottomKeyframes as androidConcealToBottomKeyframes, __webpack_exports__androidFadeInFromBottom as androidFadeInFromBottom, __webpack_exports__androidFadeInFromBottomKeyframes as androidFadeInFromBottomKeyframes, __webpack_exports__androidFadeInFromBottomOptions as androidFadeInFromBottomOptions, __webpack_exports__androidFadeInFromBottomSheet as androidFadeInFromBottomSheet, __webpack_exports__androidFadeInFromBottomSheetKeyframes as androidFadeInFromBottomSheetKeyframes, __webpack_exports__androidFadeInFromRight as androidFadeInFromRight, __webpack_exports__androidFadeInFromRightKeyframes as androidFadeInFromRightKeyframes, __webpack_exports__androidFadeOutToBottomOptions as androidFadeOutToBottomOptions, __webpack_exports__androidFadeOutToLeftKeyframes as androidFadeOutToLeftKeyframes, __webpack_exports__androidRevealFromBottom as androidRevealFromBottom, __webpack_exports__androidRevealFromBottomKeyframes as androidRevealFromBottomKeyframes, __webpack_exports__androidRevealFromBottomOptions as androidRevealFromBottomOptions, __webpack_exports__androidScaleFromCentre as androidScaleFromCentre, __webpack_exports__androidScaleFromCentreKeyframes as androidScaleFromCentreKeyframes, __webpack_exports__androidScaleFromCentreOptions as androidScaleFromCentreOptions, __webpack_exports__androidScaleToCentreKeyframes as androidScaleToCentreKeyframes, __webpack_exports__iOSKeyframeOptions as iOSKeyframeOptions, __webpack_exports__iOSSlideInFromBottom as iOSSlideInFromBottom, __webpack_exports__iOSSlideInFromBottomKeyframes as iOSSlideInFromBottomKeyframes, __webpack_exports__iOSSlideInFromLeft as iOSSlideInFromLeft, __webpack_exports__iOSSlideInFromLeftKeyframes as iOSSlideInFromLeftKeyframes, __webpack_exports__iOSSlideInFromRight as iOSSlideInFromRight, __webpack_exports__iOSSlideInFromRightKeyframes as iOSSlideInFromRightKeyframes, __webpack_exports__iOSSlideOutToLeftKeyframes as iOSSlideOutToLeftKeyframes, __webpack_exports__iOSSlideOutToRightKeyframes as iOSSlideOutToRightKeyframes, __webpack_exports__useNavigation as useNavigation, __webpack_exports__useRoute as useRoute, __webpack_exports__useRouter as useRouter };
|
|
2500
|
+
export { __webpack_exports__Anchor as Anchor, __webpack_exports__FadeInKeyframes as FadeInKeyframes, __webpack_exports__FadeOutKeyframes as FadeOutKeyframes, __webpack_exports__GestureRegion as GestureRegion, __webpack_exports__HistoryEntry as HistoryEntry, __webpack_exports__Navigation as Navigation, __webpack_exports__Router as Router, __webpack_exports__Screen as Screen, __webpack_exports__SlideInFromBottomKeyframes as SlideInFromBottomKeyframes, __webpack_exports__SlideInFromLeftKeyframes as SlideInFromLeftKeyframes, __webpack_exports__SlideInFromRightKeyframes as SlideInFromRightKeyframes, __webpack_exports__SlideInFromTopKeyframes as SlideInFromTopKeyframes, __webpack_exports__SlideOutToBottomKeyframes as SlideOutToBottomKeyframes, __webpack_exports__SlideOutToLeftKeyframes as SlideOutToLeftKeyframes, __webpack_exports__SlideOutToRightKeyframes as SlideOutToRightKeyframes, __webpack_exports__SlideOutToTopKeyframes as SlideOutToTopKeyframes, __webpack_exports__ZoomInKeyframes as ZoomInKeyframes, __webpack_exports__ZoomOutKeyframes as ZoomOutKeyframes, __webpack_exports__androidBottomSheetSlideInOptions as androidBottomSheetSlideInOptions, __webpack_exports__androidBottomSheetSlideOutOptions as androidBottomSheetSlideOutOptions, __webpack_exports__androidConcealToBottomKeyframes as androidConcealToBottomKeyframes, __webpack_exports__androidFadeInFromBottom as androidFadeInFromBottom, __webpack_exports__androidFadeInFromBottomKeyframes as androidFadeInFromBottomKeyframes, __webpack_exports__androidFadeInFromBottomOptions as androidFadeInFromBottomOptions, __webpack_exports__androidFadeInFromBottomSheet as androidFadeInFromBottomSheet, __webpack_exports__androidFadeInFromBottomSheetKeyframes as androidFadeInFromBottomSheetKeyframes, __webpack_exports__androidFadeInFromRight as androidFadeInFromRight, __webpack_exports__androidFadeInFromRightKeyframes as androidFadeInFromRightKeyframes, __webpack_exports__androidFadeOutToBottomOptions as androidFadeOutToBottomOptions, __webpack_exports__androidFadeOutToLeftKeyframes as androidFadeOutToLeftKeyframes, __webpack_exports__androidRevealFromBottom as androidRevealFromBottom, __webpack_exports__androidRevealFromBottomKeyframes as androidRevealFromBottomKeyframes, __webpack_exports__androidRevealFromBottomOptions as androidRevealFromBottomOptions, __webpack_exports__androidScaleFromCentre as androidScaleFromCentre, __webpack_exports__androidScaleFromCentreKeyframes as androidScaleFromCentreKeyframes, __webpack_exports__androidScaleFromCentreOptions as androidScaleFromCentreOptions, __webpack_exports__androidScaleToCentreKeyframes as androidScaleToCentreKeyframes, __webpack_exports__iOSKeyframeOptions as iOSKeyframeOptions, __webpack_exports__iOSSlideInFromBottom as iOSSlideInFromBottom, __webpack_exports__iOSSlideInFromBottomKeyframes as iOSSlideInFromBottomKeyframes, __webpack_exports__iOSSlideInFromLeft as iOSSlideInFromLeft, __webpack_exports__iOSSlideInFromLeftKeyframes as iOSSlideInFromLeftKeyframes, __webpack_exports__iOSSlideInFromRight as iOSSlideInFromRight, __webpack_exports__iOSSlideInFromRightKeyframes as iOSSlideInFromRightKeyframes, __webpack_exports__iOSSlideOutToLeftKeyframes as iOSSlideOutToLeftKeyframes, __webpack_exports__iOSSlideOutToRightKeyframes as iOSSlideOutToRightKeyframes, __webpack_exports__useNavigation as useNavigation, __webpack_exports__useRoute as useRoute, __webpack_exports__useRouter as useRouter };
|
|
2365
2501
|
|
|
2366
2502
|
//# sourceMappingURL=index.js.map
|