Spaces:
Running
Running
File size: 10,514 Bytes
c592d77 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
ReadonlyURLSearchParams: null,
RedirectType: null,
ServerInsertedHTMLContext: null,
forbidden: null,
notFound: null,
permanentRedirect: null,
redirect: null,
unauthorized: null,
unstable_isUnrecognizedActionError: null,
unstable_rethrow: null,
useParams: null,
usePathname: null,
useRouter: null,
useSearchParams: null,
useSelectedLayoutSegment: null,
useSelectedLayoutSegments: null,
useServerInsertedHTML: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
// We need the same class that was used to instantiate the context value
// Otherwise instanceof checks will fail in usercode
ReadonlyURLSearchParams: function() {
return _hooksclientcontextsharedruntime.ReadonlyURLSearchParams;
},
RedirectType: function() {
return _navigationreactserver.RedirectType;
},
ServerInsertedHTMLContext: function() {
return _serverinsertedhtmlsharedruntime.ServerInsertedHTMLContext;
},
forbidden: function() {
return _navigationreactserver.forbidden;
},
notFound: function() {
return _navigationreactserver.notFound;
},
permanentRedirect: function() {
return _navigationreactserver.permanentRedirect;
},
redirect: function() {
return _navigationreactserver.redirect;
},
unauthorized: function() {
return _navigationreactserver.unauthorized;
},
unstable_isUnrecognizedActionError: function() {
return _unrecognizedactionerror.unstable_isUnrecognizedActionError;
},
unstable_rethrow: function() {
return _navigationreactserver.unstable_rethrow;
},
useParams: function() {
return useParams;
},
usePathname: function() {
return usePathname;
},
useRouter: function() {
return useRouter;
},
useSearchParams: function() {
return useSearchParams;
},
useSelectedLayoutSegment: function() {
return useSelectedLayoutSegment;
},
useSelectedLayoutSegments: function() {
return useSelectedLayoutSegments;
},
useServerInsertedHTML: function() {
return _serverinsertedhtmlsharedruntime.useServerInsertedHTML;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _approutercontextsharedruntime = require("../../shared/lib/app-router-context.shared-runtime");
const _hooksclientcontextsharedruntime = require("../../shared/lib/hooks-client-context.shared-runtime");
const _segment = require("../../shared/lib/segment");
const _serverinsertedhtmlsharedruntime = require("../../shared/lib/server-inserted-html.shared-runtime");
const _unrecognizedactionerror = require("./unrecognized-action-error");
const _navigationreactserver = require("./navigation.react-server");
const useDynamicRouteParams = typeof window === 'undefined' ? require('../../server/app-render/dynamic-rendering').useDynamicRouteParams : undefined;
const useDynamicSearchParams = typeof window === 'undefined' ? require('../../server/app-render/dynamic-rendering').useDynamicSearchParams : undefined;
const { instrumentParamsForClientValidation, instrumentSearchParamsForClientValidation, expectCompleteParamsInClientValidation } = typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS ? require('../../server/app-render/instant-validation/instant-samples-client') : {};
function useSearchParams() {
useDynamicSearchParams?.('useSearchParams()');
const searchParams = (0, _react.useContext)(_hooksclientcontextsharedruntime.SearchParamsContext);
// In the case where this is `null`, the compat types added in
// `next-env.d.ts` will add a new overload that changes the return type to
// include `null`.
const readonlySearchParams = (0, _react.useMemo)(()=>{
if (!searchParams) {
// When the router is not ready in pages, we won't have the search params
// available.
return null;
}
return new _hooksclientcontextsharedruntime.ReadonlyURLSearchParams(searchParams);
}, [
searchParams
]);
// During build-time instant validation, wrap with an proxy
// so that accessing undeclared search params throws an error.
if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS && readonlySearchParams) {
return instrumentSearchParamsForClientValidation(readonlySearchParams);
}
// Instrument with Suspense DevTools (dev-only)
if (process.env.NODE_ENV !== 'production' && 'use' in _react.default) {
const navigationPromises = (0, _react.use)(_hooksclientcontextsharedruntime.NavigationPromisesContext);
if (navigationPromises) {
return (0, _react.use)(navigationPromises.searchParams);
}
}
return readonlySearchParams;
}
function usePathname() {
useDynamicRouteParams?.('usePathname()');
// In the case where this is `null`, the compat types added in `next-env.d.ts`
// will add a new overload that changes the return type to include `null`.
const pathname = (0, _react.useContext)(_hooksclientcontextsharedruntime.PathnameContext);
// During build-time instant validation, error if fallback params exist
// because usePathname() can't return a sensible value without all params.
if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS && pathname) {
expectCompleteParamsInClientValidation('usePathname()');
return pathname;
}
// Instrument with Suspense DevTools (dev-only)
if (process.env.NODE_ENV !== 'production' && 'use' in _react.default) {
const navigationPromises = (0, _react.use)(_hooksclientcontextsharedruntime.NavigationPromisesContext);
if (navigationPromises) {
return (0, _react.use)(navigationPromises.pathname);
}
}
return pathname;
}
function useRouter() {
const router = (0, _react.useContext)(_approutercontextsharedruntime.AppRouterContext);
if (router === null) {
throw Object.defineProperty(new Error('invariant expected app router to be mounted'), "__NEXT_ERROR_CODE", {
value: "E238",
enumerable: false,
configurable: true
});
}
return router;
}
function useParams() {
useDynamicRouteParams?.('useParams()');
const params = (0, _react.useContext)(_hooksclientcontextsharedruntime.PathParamsContext);
// During build-time instant validation, wrap with a proxy
// so that accessing undeclared params throws an error.
if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS && params) {
return instrumentParamsForClientValidation(params);
}
// Instrument with Suspense DevTools (dev-only)
if (process.env.NODE_ENV !== 'production' && 'use' in _react.default) {
const navigationPromises = (0, _react.use)(_hooksclientcontextsharedruntime.NavigationPromisesContext);
if (navigationPromises) {
return (0, _react.use)(navigationPromises.params);
}
}
return params;
}
function useSelectedLayoutSegments(parallelRouteKey = 'children') {
useDynamicRouteParams?.('useSelectedLayoutSegments()');
const context = (0, _react.useContext)(_approutercontextsharedruntime.LayoutRouterContext);
// @ts-expect-error This only happens in `pages`. Type is overwritten in navigation.d.ts
if (!context) return null;
// During build-time instant validation, error if fallback params exist
// because useSelectedLayoutSegments() can't return a sensible value without all params.
if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS && context) {
expectCompleteParamsInClientValidation('useSelectedLayoutSegments()');
}
// Instrument with Suspense DevTools (dev-only)
if (process.env.NODE_ENV !== 'production' && 'use' in _react.default) {
const navigationPromises = (0, _react.use)(_hooksclientcontextsharedruntime.NavigationPromisesContext);
if (navigationPromises) {
const promise = navigationPromises.selectedLayoutSegmentsPromises?.get(parallelRouteKey);
if (promise) {
// We should always have a promise here, but if we don't, it's not worth erroring over.
// We just won't be able to instrument it, but can still provide the value.
return (0, _react.use)(promise);
}
}
}
return (0, _segment.getSelectedLayoutSegmentPath)(context.parentTree, parallelRouteKey);
}
function useSelectedLayoutSegment(parallelRouteKey = 'children') {
useDynamicRouteParams?.('useSelectedLayoutSegment()');
const navigationPromises = (0, _react.useContext)(_hooksclientcontextsharedruntime.NavigationPromisesContext);
const selectedLayoutSegments = useSelectedLayoutSegments(parallelRouteKey);
// During build-time instant validation, error if fallback params exist
// because useSelectedLayoutSegment() can't return a sensible value without all params.
if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS) {
expectCompleteParamsInClientValidation('useSelectedLayoutSegment()');
}
// Instrument with Suspense DevTools (dev-only)
if (process.env.NODE_ENV !== 'production' && navigationPromises && 'use' in _react.default) {
const promise = navigationPromises.selectedLayoutSegmentPromises?.get(parallelRouteKey);
if (promise) {
// We should always have a promise here, but if we don't, it's not worth erroring over.
// We just won't be able to instrument it, but can still provide the value.
return (0, _react.use)(promise);
}
}
return (0, _segment.computeSelectedLayoutSegment)(selectedLayoutSegments, parallelRouteKey);
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=navigation.js.map |