one 2.0.0-beta.107.1 → 2.0.0-beta.111.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.
- package/dist/cjs/router/router.cjs +53 -42
- package/dist/cjs/router/router.native.cjs +63 -52
- package/dist/cjs/router/router.native.js +63 -52
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/esm/router/router.mjs +55 -43
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +65 -53
- package/dist/esm/router/router.native.js.map +1 -1
- package/ios/OneNativeTabsView.swift +18 -4
- package/package.json +10 -10
- package/src/platform/README.md +1 -1
- package/src/router/router.ts +103 -72
- package/types/router/router.d.ts.map +1 -1
|
@@ -458,14 +458,23 @@ function syncStoreRootState() {
|
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
|
+
function useRootStateSnapshot(snapshot2) {
|
|
462
|
+
const [state, rerender] = (0, import_react.useReducer)(snapshot2, void 0, snapshot2);
|
|
463
|
+
(0, import_react.useEffect)(() => {
|
|
464
|
+
const unsubscribe = subscribeToRootState(rerender);
|
|
465
|
+
rerender();
|
|
466
|
+
return unsubscribe;
|
|
467
|
+
}, []);
|
|
468
|
+
const browserPath = (0, import_path2.getSafeWindowPath)();
|
|
469
|
+
return browserPath !== void 0 && routeInfo?.unstable_globalHref === browserPath + window.location.hash ? snapshot2() : state;
|
|
470
|
+
}
|
|
461
471
|
function useStoreRootState() {
|
|
462
472
|
syncStoreRootState();
|
|
463
|
-
|
|
464
|
-
return (0, import_react.useDeferredValue)(state);
|
|
473
|
+
return (0, import_react.useDeferredValue)(useRootStateSnapshot(rootStateSnapshot));
|
|
465
474
|
}
|
|
466
475
|
function useStoreRouteInfo() {
|
|
467
476
|
syncStoreRootState();
|
|
468
|
-
return (
|
|
477
|
+
return useRootStateSnapshot(routeInfoSnapshot);
|
|
469
478
|
}
|
|
470
479
|
function cleanup() {
|
|
471
480
|
if (splashScreenAnimationFrame) cancelAnimationFrame(splashScreenAnimationFrame);
|
|
@@ -824,46 +833,48 @@ async function linkTo(href, event, options) {
|
|
|
824
833
|
...state,
|
|
825
834
|
linkOptions: nextOptions
|
|
826
835
|
} : state;
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
key: currentFocusedRoute?.key ?? targetRoute.key
|
|
847
|
-
};
|
|
848
|
-
navigationRef.resetRoot({
|
|
849
|
-
...freshRootState,
|
|
850
|
-
routes
|
|
851
|
-
});
|
|
852
|
-
} else {
|
|
853
|
-
const existingTargetRoute = freshRootState.routes.find((route) => route.name === targetRootName);
|
|
854
|
-
const existingRoutes = freshRootState.routes.filter((route) => route.name !== targetRootName);
|
|
855
|
-
const nextRootState = {
|
|
856
|
-
...freshRootState,
|
|
857
|
-
routes: [...existingRoutes, {
|
|
836
|
+
const action = event === "REPLACE" ? null : (0, import_getNavigateAction.getNavigateAction)(state, freshRootState, event);
|
|
837
|
+
(0, import_react.startTransition)(() => {
|
|
838
|
+
updateState(optimisticState);
|
|
839
|
+
pendingNavigationPathname = targetPathname;
|
|
840
|
+
notifyRootStateSubscribers(optimisticState);
|
|
841
|
+
if (!action) navigationRef.resetRoot(state);
|
|
842
|
+
else {
|
|
843
|
+
const targetName = action.payload?.name;
|
|
844
|
+
const isGroupTarget = typeof targetName === "string" && targetName.startsWith("(") && targetName.endsWith(")");
|
|
845
|
+
const hasFreshRootState = freshRootState.type === "stack";
|
|
846
|
+
const isRootTarget = action.target === freshRootState.key;
|
|
847
|
+
const currentFocusedRoute = freshRootState.routes[freshRootState.index];
|
|
848
|
+
const currentFocusedName = currentFocusedRoute?.name;
|
|
849
|
+
if (isRootTarget && isGroupTarget && hasFreshRootState) {
|
|
850
|
+
const targetRoute = state.routes[state.index ?? state.routes.length - 1];
|
|
851
|
+
const targetRootName = targetRoute.name;
|
|
852
|
+
if (currentFocusedName === targetRootName) {
|
|
853
|
+
const routes = [...freshRootState.routes];
|
|
854
|
+
routes[freshRootState.index] = {
|
|
858
855
|
...targetRoute,
|
|
859
|
-
key:
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
856
|
+
key: currentFocusedRoute?.key ?? targetRoute.key
|
|
857
|
+
};
|
|
858
|
+
navigationRef.resetRoot({
|
|
859
|
+
...freshRootState,
|
|
860
|
+
routes
|
|
861
|
+
});
|
|
862
|
+
} else {
|
|
863
|
+
const existingTargetRoute = freshRootState.routes.find((route) => route.name === targetRootName);
|
|
864
|
+
const existingRoutes = freshRootState.routes.filter((route) => route.name !== targetRootName);
|
|
865
|
+
const nextRootState = {
|
|
866
|
+
...freshRootState,
|
|
867
|
+
routes: [...existingRoutes, {
|
|
868
|
+
...targetRoute,
|
|
869
|
+
key: existingTargetRoute?.key ?? `${targetRootName}-${freshRootState.key}`
|
|
870
|
+
}],
|
|
871
|
+
index: existingRoutes.length
|
|
872
|
+
};
|
|
873
|
+
navigationRef.resetRoot(nextRootState);
|
|
874
|
+
}
|
|
875
|
+
} else navigationRef.dispatch(action);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
867
878
|
let warningTm;
|
|
868
879
|
const interval = setInterval(() => {
|
|
869
880
|
if (!navigationRef.isReady()) {
|
|
@@ -583,14 +583,23 @@ function syncStoreRootState() {
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
+
function useRootStateSnapshot(snapshot2) {
|
|
587
|
+
var [state, rerender] = (0, import_react.useReducer)(snapshot2, void 0, snapshot2);
|
|
588
|
+
(0, import_react.useEffect)(function() {
|
|
589
|
+
var unsubscribe = subscribeToRootState(rerender);
|
|
590
|
+
rerender();
|
|
591
|
+
return unsubscribe;
|
|
592
|
+
}, []);
|
|
593
|
+
var browserPath = (0, import_path2.getSafeWindowPath)();
|
|
594
|
+
return browserPath !== void 0 && (routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.unstable_globalHref) === browserPath + window.location.hash ? snapshot2() : state;
|
|
595
|
+
}
|
|
586
596
|
function useStoreRootState() {
|
|
587
597
|
syncStoreRootState();
|
|
588
|
-
|
|
589
|
-
return (0, import_react.useDeferredValue)(state);
|
|
598
|
+
return (0, import_react.useDeferredValue)(useRootStateSnapshot(rootStateSnapshot));
|
|
590
599
|
}
|
|
591
600
|
function useStoreRouteInfo() {
|
|
592
601
|
syncStoreRootState();
|
|
593
|
-
return (
|
|
602
|
+
return useRootStateSnapshot(routeInfoSnapshot);
|
|
594
603
|
}
|
|
595
604
|
function cleanup() {
|
|
596
605
|
if (splashScreenAnimationFrame) cancelAnimationFrame(splashScreenAnimationFrame);
|
|
@@ -686,12 +695,12 @@ async function linkTo(href, event, options) {
|
|
|
686
695
|
var _routeInfo_params;
|
|
687
696
|
if (!segment.startsWith("[")) return segment;
|
|
688
697
|
if (segment.startsWith("[...")) {
|
|
689
|
-
var
|
|
698
|
+
var _ref2;
|
|
690
699
|
var _routeInfo_params1, _params_split;
|
|
691
700
|
segment = segment.slice(4, -1);
|
|
692
701
|
var params3 = routeInfo === null || routeInfo === void 0 ? void 0 : (_routeInfo_params1 = routeInfo.params) === null || _routeInfo_params1 === void 0 ? void 0 : _routeInfo_params1[segment];
|
|
693
702
|
if (Array.isArray(params3)) return params3.join("/");
|
|
694
|
-
return (
|
|
703
|
+
return (_ref2 = params3 === null || params3 === void 0 ? void 0 : (_params_split = params3.split(",")) === null || _params_split === void 0 ? void 0 : _params_split.join("/")) !== null && _ref2 !== void 0 ? _ref2 : "";
|
|
695
704
|
}
|
|
696
705
|
segment = segment.slice(1, -1);
|
|
697
706
|
return routeInfo === null || routeInfo === void 0 ? void 0 : (_routeInfo_params = routeInfo.params) === null || _routeInfo_params === void 0 ? void 0 : _routeInfo_params[segment];
|
|
@@ -811,54 +820,56 @@ async function linkTo(href, event, options) {
|
|
|
811
820
|
...state,
|
|
812
821
|
linkOptions: nextOptions
|
|
813
822
|
} : state;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
key: (_ref1 = currentFocusedRoute === null || currentFocusedRoute === void 0 ? void 0 : currentFocusedRoute.key) !== null && _ref1 !== void 0 ? _ref1 : targetRoute.key
|
|
837
|
-
};
|
|
838
|
-
navigationRef.resetRoot({
|
|
839
|
-
...freshRootState,
|
|
840
|
-
routes
|
|
841
|
-
});
|
|
842
|
-
} else {
|
|
843
|
-
var _ref2;
|
|
844
|
-
var existingTargetRoute = freshRootState.routes.find(function(route) {
|
|
845
|
-
return route.name === targetRootName;
|
|
846
|
-
});
|
|
847
|
-
var existingRoutes = freshRootState.routes.filter(function(route) {
|
|
848
|
-
return route.name !== targetRootName;
|
|
849
|
-
});
|
|
850
|
-
var nextRootState = {
|
|
851
|
-
...freshRootState,
|
|
852
|
-
routes: [...existingRoutes, {
|
|
823
|
+
var action = event === "REPLACE" ? null : (0, import_getNavigateAction.getNavigateAction)(state, freshRootState, event);
|
|
824
|
+
(0, import_react.startTransition)(function() {
|
|
825
|
+
updateState(optimisticState);
|
|
826
|
+
pendingNavigationPathname = targetPathname;
|
|
827
|
+
notifyRootStateSubscribers(optimisticState);
|
|
828
|
+
if (!action) navigationRef.resetRoot(state);
|
|
829
|
+
else {
|
|
830
|
+
var _action_payload;
|
|
831
|
+
var targetName = (_action_payload = action.payload) === null || _action_payload === void 0 ? void 0 : _action_payload.name;
|
|
832
|
+
var isGroupTarget = typeof targetName === "string" && targetName.startsWith("(") && targetName.endsWith(")");
|
|
833
|
+
var hasFreshRootState = freshRootState.type === "stack";
|
|
834
|
+
var isRootTarget = action.target === freshRootState.key;
|
|
835
|
+
var currentFocusedRoute = freshRootState.routes[freshRootState.index];
|
|
836
|
+
var currentFocusedName = currentFocusedRoute === null || currentFocusedRoute === void 0 ? void 0 : currentFocusedRoute.name;
|
|
837
|
+
if (isRootTarget && isGroupTarget && hasFreshRootState) {
|
|
838
|
+
var _state_index;
|
|
839
|
+
var targetRoute = state.routes[(_state_index = state.index) !== null && _state_index !== void 0 ? _state_index : state.routes.length - 1];
|
|
840
|
+
var targetRootName = targetRoute.name;
|
|
841
|
+
if (currentFocusedName === targetRootName) {
|
|
842
|
+
var _ref2;
|
|
843
|
+
var routes = [...freshRootState.routes];
|
|
844
|
+
routes[freshRootState.index] = {
|
|
853
845
|
...targetRoute,
|
|
854
|
-
key: (_ref2 =
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
846
|
+
key: (_ref2 = currentFocusedRoute === null || currentFocusedRoute === void 0 ? void 0 : currentFocusedRoute.key) !== null && _ref2 !== void 0 ? _ref2 : targetRoute.key
|
|
847
|
+
};
|
|
848
|
+
navigationRef.resetRoot({
|
|
849
|
+
...freshRootState,
|
|
850
|
+
routes
|
|
851
|
+
});
|
|
852
|
+
} else {
|
|
853
|
+
var _ref1;
|
|
854
|
+
var existingTargetRoute = freshRootState.routes.find(function(route) {
|
|
855
|
+
return route.name === targetRootName;
|
|
856
|
+
});
|
|
857
|
+
var existingRoutes = freshRootState.routes.filter(function(route) {
|
|
858
|
+
return route.name !== targetRootName;
|
|
859
|
+
});
|
|
860
|
+
var nextRootState = {
|
|
861
|
+
...freshRootState,
|
|
862
|
+
routes: [...existingRoutes, {
|
|
863
|
+
...targetRoute,
|
|
864
|
+
key: (_ref1 = existingTargetRoute === null || existingTargetRoute === void 0 ? void 0 : existingTargetRoute.key) !== null && _ref1 !== void 0 ? _ref1 : `${targetRootName}-${freshRootState.key}`
|
|
865
|
+
}],
|
|
866
|
+
index: existingRoutes.length
|
|
867
|
+
};
|
|
868
|
+
navigationRef.resetRoot(nextRootState);
|
|
869
|
+
}
|
|
870
|
+
} else navigationRef.dispatch(action);
|
|
871
|
+
}
|
|
872
|
+
});
|
|
862
873
|
var warningTm;
|
|
863
874
|
var interval = setInterval(function() {
|
|
864
875
|
if (!navigationRef.isReady()) {
|
|
@@ -583,14 +583,23 @@ function syncStoreRootState() {
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
+
function useRootStateSnapshot(snapshot2) {
|
|
587
|
+
var [state, rerender] = (0, import_react.useReducer)(snapshot2, void 0, snapshot2);
|
|
588
|
+
(0, import_react.useEffect)(function() {
|
|
589
|
+
var unsubscribe = subscribeToRootState(rerender);
|
|
590
|
+
rerender();
|
|
591
|
+
return unsubscribe;
|
|
592
|
+
}, []);
|
|
593
|
+
var browserPath = (0, import_path2.getSafeWindowPath)();
|
|
594
|
+
return browserPath !== void 0 && (routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.unstable_globalHref) === browserPath + window.location.hash ? snapshot2() : state;
|
|
595
|
+
}
|
|
586
596
|
function useStoreRootState() {
|
|
587
597
|
syncStoreRootState();
|
|
588
|
-
|
|
589
|
-
return (0, import_react.useDeferredValue)(state);
|
|
598
|
+
return (0, import_react.useDeferredValue)(useRootStateSnapshot(rootStateSnapshot));
|
|
590
599
|
}
|
|
591
600
|
function useStoreRouteInfo() {
|
|
592
601
|
syncStoreRootState();
|
|
593
|
-
return (
|
|
602
|
+
return useRootStateSnapshot(routeInfoSnapshot);
|
|
594
603
|
}
|
|
595
604
|
function cleanup() {
|
|
596
605
|
if (splashScreenAnimationFrame) cancelAnimationFrame(splashScreenAnimationFrame);
|
|
@@ -686,12 +695,12 @@ async function linkTo(href, event, options) {
|
|
|
686
695
|
var _routeInfo_params;
|
|
687
696
|
if (!segment.startsWith("[")) return segment;
|
|
688
697
|
if (segment.startsWith("[...")) {
|
|
689
|
-
var
|
|
698
|
+
var _ref2;
|
|
690
699
|
var _routeInfo_params1, _params_split;
|
|
691
700
|
segment = segment.slice(4, -1);
|
|
692
701
|
var params3 = routeInfo === null || routeInfo === void 0 ? void 0 : (_routeInfo_params1 = routeInfo.params) === null || _routeInfo_params1 === void 0 ? void 0 : _routeInfo_params1[segment];
|
|
693
702
|
if (Array.isArray(params3)) return params3.join("/");
|
|
694
|
-
return (
|
|
703
|
+
return (_ref2 = params3 === null || params3 === void 0 ? void 0 : (_params_split = params3.split(",")) === null || _params_split === void 0 ? void 0 : _params_split.join("/")) !== null && _ref2 !== void 0 ? _ref2 : "";
|
|
695
704
|
}
|
|
696
705
|
segment = segment.slice(1, -1);
|
|
697
706
|
return routeInfo === null || routeInfo === void 0 ? void 0 : (_routeInfo_params = routeInfo.params) === null || _routeInfo_params === void 0 ? void 0 : _routeInfo_params[segment];
|
|
@@ -811,54 +820,56 @@ async function linkTo(href, event, options) {
|
|
|
811
820
|
...state,
|
|
812
821
|
linkOptions: nextOptions
|
|
813
822
|
} : state;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
key: (_ref1 = currentFocusedRoute === null || currentFocusedRoute === void 0 ? void 0 : currentFocusedRoute.key) !== null && _ref1 !== void 0 ? _ref1 : targetRoute.key
|
|
837
|
-
};
|
|
838
|
-
navigationRef.resetRoot({
|
|
839
|
-
...freshRootState,
|
|
840
|
-
routes
|
|
841
|
-
});
|
|
842
|
-
} else {
|
|
843
|
-
var _ref2;
|
|
844
|
-
var existingTargetRoute = freshRootState.routes.find(function(route) {
|
|
845
|
-
return route.name === targetRootName;
|
|
846
|
-
});
|
|
847
|
-
var existingRoutes = freshRootState.routes.filter(function(route) {
|
|
848
|
-
return route.name !== targetRootName;
|
|
849
|
-
});
|
|
850
|
-
var nextRootState = {
|
|
851
|
-
...freshRootState,
|
|
852
|
-
routes: [...existingRoutes, {
|
|
823
|
+
var action = event === "REPLACE" ? null : (0, import_getNavigateAction.getNavigateAction)(state, freshRootState, event);
|
|
824
|
+
(0, import_react.startTransition)(function() {
|
|
825
|
+
updateState(optimisticState);
|
|
826
|
+
pendingNavigationPathname = targetPathname;
|
|
827
|
+
notifyRootStateSubscribers(optimisticState);
|
|
828
|
+
if (!action) navigationRef.resetRoot(state);
|
|
829
|
+
else {
|
|
830
|
+
var _action_payload;
|
|
831
|
+
var targetName = (_action_payload = action.payload) === null || _action_payload === void 0 ? void 0 : _action_payload.name;
|
|
832
|
+
var isGroupTarget = typeof targetName === "string" && targetName.startsWith("(") && targetName.endsWith(")");
|
|
833
|
+
var hasFreshRootState = freshRootState.type === "stack";
|
|
834
|
+
var isRootTarget = action.target === freshRootState.key;
|
|
835
|
+
var currentFocusedRoute = freshRootState.routes[freshRootState.index];
|
|
836
|
+
var currentFocusedName = currentFocusedRoute === null || currentFocusedRoute === void 0 ? void 0 : currentFocusedRoute.name;
|
|
837
|
+
if (isRootTarget && isGroupTarget && hasFreshRootState) {
|
|
838
|
+
var _state_index;
|
|
839
|
+
var targetRoute = state.routes[(_state_index = state.index) !== null && _state_index !== void 0 ? _state_index : state.routes.length - 1];
|
|
840
|
+
var targetRootName = targetRoute.name;
|
|
841
|
+
if (currentFocusedName === targetRootName) {
|
|
842
|
+
var _ref2;
|
|
843
|
+
var routes = [...freshRootState.routes];
|
|
844
|
+
routes[freshRootState.index] = {
|
|
853
845
|
...targetRoute,
|
|
854
|
-
key: (_ref2 =
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
846
|
+
key: (_ref2 = currentFocusedRoute === null || currentFocusedRoute === void 0 ? void 0 : currentFocusedRoute.key) !== null && _ref2 !== void 0 ? _ref2 : targetRoute.key
|
|
847
|
+
};
|
|
848
|
+
navigationRef.resetRoot({
|
|
849
|
+
...freshRootState,
|
|
850
|
+
routes
|
|
851
|
+
});
|
|
852
|
+
} else {
|
|
853
|
+
var _ref1;
|
|
854
|
+
var existingTargetRoute = freshRootState.routes.find(function(route) {
|
|
855
|
+
return route.name === targetRootName;
|
|
856
|
+
});
|
|
857
|
+
var existingRoutes = freshRootState.routes.filter(function(route) {
|
|
858
|
+
return route.name !== targetRootName;
|
|
859
|
+
});
|
|
860
|
+
var nextRootState = {
|
|
861
|
+
...freshRootState,
|
|
862
|
+
routes: [...existingRoutes, {
|
|
863
|
+
...targetRoute,
|
|
864
|
+
key: (_ref1 = existingTargetRoute === null || existingTargetRoute === void 0 ? void 0 : existingTargetRoute.key) !== null && _ref1 !== void 0 ? _ref1 : `${targetRootName}-${freshRootState.key}`
|
|
865
|
+
}],
|
|
866
|
+
index: existingRoutes.length
|
|
867
|
+
};
|
|
868
|
+
navigationRef.resetRoot(nextRootState);
|
|
869
|
+
}
|
|
870
|
+
} else navigationRef.dispatch(action);
|
|
871
|
+
}
|
|
872
|
+
});
|
|
862
873
|
var warningTm;
|
|
863
874
|
var interval = setInterval(function() {
|
|
864
875
|
if (!navigationRef.isReady()) {
|