clear-react-router 1.0.16 → 1.0.17
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/index.js +556 -352
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,440 +1,644 @@
|
|
|
1
|
-
import { Suspense
|
|
1
|
+
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region context/RouterContext.ts
|
|
10
|
+
var ActionsContext = createContext({});
|
|
11
|
+
var DataContext = createContext({});
|
|
12
|
+
var NavigationContext = createContext({});
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../../node_modules/react/cjs/react-jsx-runtime.production.js
|
|
15
|
+
/**
|
|
16
|
+
* @license React
|
|
17
|
+
* react-jsx-runtime.production.js
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
25
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
26
|
+
function jsxProd(type, config, maybeKey) {
|
|
27
|
+
var key = null;
|
|
28
|
+
void 0 !== maybeKey && (key = "" + maybeKey);
|
|
29
|
+
void 0 !== config.key && (key = "" + config.key);
|
|
30
|
+
if ("key" in config) {
|
|
31
|
+
maybeKey = {};
|
|
32
|
+
for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
|
|
33
|
+
} else maybeKey = config;
|
|
34
|
+
config = maybeKey.ref;
|
|
35
|
+
return {
|
|
36
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
37
|
+
type,
|
|
38
|
+
key,
|
|
39
|
+
ref: void 0 !== config ? config : null,
|
|
40
|
+
props: maybeKey
|
|
18
41
|
};
|
|
19
42
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
44
|
+
exports.jsx = jsxProd;
|
|
45
|
+
exports.jsxs = jsxProd;
|
|
46
|
+
}));
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region ../../node_modules/react/cjs/react-jsx-runtime.development.js
|
|
49
|
+
/**
|
|
50
|
+
* @license React
|
|
51
|
+
* react-jsx-runtime.development.js
|
|
52
|
+
*
|
|
53
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
54
|
+
*
|
|
55
|
+
* This source code is licensed under the MIT license found in the
|
|
56
|
+
* LICENSE file in the root directory of this source tree.
|
|
57
|
+
*/
|
|
58
|
+
var require_react_jsx_runtime_development = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
59
|
+
"production" !== process.env.NODE_ENV && (function() {
|
|
60
|
+
function getComponentNameFromType(type) {
|
|
61
|
+
if (null == type) return null;
|
|
62
|
+
if ("function" === typeof type) return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
|
|
63
|
+
if ("string" === typeof type) return type;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case REACT_FRAGMENT_TYPE: return "Fragment";
|
|
66
|
+
case REACT_PROFILER_TYPE: return "Profiler";
|
|
67
|
+
case REACT_STRICT_MODE_TYPE: return "StrictMode";
|
|
68
|
+
case REACT_SUSPENSE_TYPE: return "Suspense";
|
|
69
|
+
case REACT_SUSPENSE_LIST_TYPE: return "SuspenseList";
|
|
70
|
+
case REACT_ACTIVITY_TYPE: return "Activity";
|
|
34
71
|
}
|
|
35
|
-
if (typeof
|
|
36
|
-
case
|
|
37
|
-
case
|
|
38
|
-
case
|
|
39
|
-
case
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
72
|
+
if ("object" === typeof type) switch ("number" === typeof type.tag && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), type.$$typeof) {
|
|
73
|
+
case REACT_PORTAL_TYPE: return "Portal";
|
|
74
|
+
case REACT_CONTEXT_TYPE: return type.displayName || "Context";
|
|
75
|
+
case REACT_CONSUMER_TYPE: return (type._context.displayName || "Context") + ".Consumer";
|
|
76
|
+
case REACT_FORWARD_REF_TYPE:
|
|
77
|
+
var innerType = type.render;
|
|
78
|
+
type = type.displayName;
|
|
79
|
+
type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
80
|
+
return type;
|
|
81
|
+
case REACT_MEMO_TYPE: return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
82
|
+
case REACT_LAZY_TYPE:
|
|
83
|
+
innerType = type._payload;
|
|
84
|
+
type = type._init;
|
|
45
85
|
try {
|
|
46
|
-
return
|
|
47
|
-
} catch {}
|
|
86
|
+
return getComponentNameFromType(type(innerType));
|
|
87
|
+
} catch (x) {}
|
|
48
88
|
}
|
|
49
89
|
return null;
|
|
50
90
|
}
|
|
51
|
-
function
|
|
52
|
-
return "" +
|
|
91
|
+
function testStringCoercion(value) {
|
|
92
|
+
return "" + value;
|
|
53
93
|
}
|
|
54
|
-
function
|
|
94
|
+
function checkKeyStringCoercion(value) {
|
|
55
95
|
try {
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
} catch {
|
|
59
|
-
|
|
96
|
+
testStringCoercion(value);
|
|
97
|
+
var JSCompiler_inline_result = !1;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
JSCompiler_inline_result = !0;
|
|
60
100
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
var
|
|
64
|
-
|
|
101
|
+
if (JSCompiler_inline_result) {
|
|
102
|
+
JSCompiler_inline_result = console;
|
|
103
|
+
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
|
104
|
+
var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
105
|
+
JSCompiler_temp_const.call(JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0);
|
|
106
|
+
return testStringCoercion(value);
|
|
65
107
|
}
|
|
66
108
|
}
|
|
67
|
-
function
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
109
|
+
function getTaskName(type) {
|
|
110
|
+
if (type === REACT_FRAGMENT_TYPE) return "<>";
|
|
111
|
+
if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE) return "<...>";
|
|
70
112
|
try {
|
|
71
|
-
var
|
|
72
|
-
return
|
|
73
|
-
} catch {
|
|
113
|
+
var name = getComponentNameFromType(type);
|
|
114
|
+
return name ? "<" + name + ">" : "<...>";
|
|
115
|
+
} catch (x) {
|
|
74
116
|
return "<...>";
|
|
75
117
|
}
|
|
76
118
|
}
|
|
77
|
-
function
|
|
78
|
-
var
|
|
79
|
-
return
|
|
119
|
+
function getOwner() {
|
|
120
|
+
var dispatcher = ReactSharedInternals.A;
|
|
121
|
+
return null === dispatcher ? null : dispatcher.getOwner();
|
|
80
122
|
}
|
|
81
|
-
function
|
|
123
|
+
function UnknownOwner() {
|
|
82
124
|
return Error("react-stack-top-frame");
|
|
83
125
|
}
|
|
84
|
-
function
|
|
85
|
-
if (
|
|
86
|
-
var
|
|
87
|
-
if (
|
|
126
|
+
function hasValidKey(config) {
|
|
127
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
128
|
+
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
129
|
+
if (getter && getter.isReactWarning) return !1;
|
|
88
130
|
}
|
|
89
|
-
return
|
|
131
|
+
return void 0 !== config.key;
|
|
90
132
|
}
|
|
91
|
-
function
|
|
92
|
-
function
|
|
93
|
-
|
|
133
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
134
|
+
function warnAboutAccessingKey() {
|
|
135
|
+
specialPropKeyWarningShown || (specialPropKeyWarningShown = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName));
|
|
94
136
|
}
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
warnAboutAccessingKey.isReactWarning = !0;
|
|
138
|
+
Object.defineProperty(props, "key", {
|
|
139
|
+
get: warnAboutAccessingKey,
|
|
97
140
|
configurable: !0
|
|
98
141
|
});
|
|
99
142
|
}
|
|
100
|
-
function
|
|
101
|
-
var
|
|
102
|
-
|
|
143
|
+
function elementRefGetterWithDeprecationWarning() {
|
|
144
|
+
var componentName = getComponentNameFromType(this.type);
|
|
145
|
+
didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."));
|
|
146
|
+
componentName = this.props.ref;
|
|
147
|
+
return void 0 !== componentName ? componentName : null;
|
|
103
148
|
}
|
|
104
|
-
function
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
$$typeof:
|
|
108
|
-
type
|
|
109
|
-
key
|
|
110
|
-
props
|
|
111
|
-
_owner:
|
|
112
|
-
}
|
|
149
|
+
function ReactElement(type, key, props, owner, debugStack, debugTask) {
|
|
150
|
+
var refProp = props.ref;
|
|
151
|
+
type = {
|
|
152
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
153
|
+
type,
|
|
154
|
+
key,
|
|
155
|
+
props,
|
|
156
|
+
_owner: owner
|
|
157
|
+
};
|
|
158
|
+
null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", {
|
|
113
159
|
enumerable: !1,
|
|
114
|
-
|
|
115
|
-
}) : Object.defineProperty(
|
|
160
|
+
get: elementRefGetterWithDeprecationWarning
|
|
161
|
+
}) : Object.defineProperty(type, "ref", {
|
|
116
162
|
enumerable: !1,
|
|
117
|
-
|
|
118
|
-
})
|
|
163
|
+
value: null
|
|
164
|
+
});
|
|
165
|
+
type._store = {};
|
|
166
|
+
Object.defineProperty(type._store, "validated", {
|
|
119
167
|
configurable: !1,
|
|
120
168
|
enumerable: !1,
|
|
121
169
|
writable: !0,
|
|
122
170
|
value: 0
|
|
123
|
-
})
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(type, "_debugInfo", {
|
|
124
173
|
configurable: !1,
|
|
125
174
|
enumerable: !1,
|
|
126
175
|
writable: !0,
|
|
127
176
|
value: null
|
|
128
|
-
})
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(type, "_debugStack", {
|
|
129
179
|
configurable: !1,
|
|
130
180
|
enumerable: !1,
|
|
131
181
|
writable: !0,
|
|
132
|
-
value:
|
|
133
|
-
})
|
|
182
|
+
value: debugStack
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(type, "_debugTask", {
|
|
134
185
|
configurable: !1,
|
|
135
186
|
enumerable: !1,
|
|
136
187
|
writable: !0,
|
|
137
|
-
value:
|
|
138
|
-
})
|
|
188
|
+
value: debugTask
|
|
189
|
+
});
|
|
190
|
+
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
191
|
+
return type;
|
|
139
192
|
}
|
|
140
|
-
function
|
|
141
|
-
var
|
|
142
|
-
if (
|
|
143
|
-
for (
|
|
144
|
-
Object.freeze && Object.freeze(
|
|
193
|
+
function jsxDEVImpl(type, config, maybeKey, isStaticChildren, debugStack, debugTask) {
|
|
194
|
+
var children = config.children;
|
|
195
|
+
if (void 0 !== children) if (isStaticChildren) if (isArrayImpl(children)) {
|
|
196
|
+
for (isStaticChildren = 0; isStaticChildren < children.length; isStaticChildren++) validateChildKeys(children[isStaticChildren]);
|
|
197
|
+
Object.freeze && Object.freeze(children);
|
|
145
198
|
} else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
146
|
-
else
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
var
|
|
150
|
-
return
|
|
199
|
+
else validateChildKeys(children);
|
|
200
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
201
|
+
children = getComponentNameFromType(type);
|
|
202
|
+
var keys = Object.keys(config).filter(function(k) {
|
|
203
|
+
return "key" !== k;
|
|
151
204
|
});
|
|
152
|
-
|
|
205
|
+
isStaticChildren = 0 < keys.length ? "{key: someKey, " + keys.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
206
|
+
didWarnAboutKeySpread[children + isStaticChildren] || (keys = 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", isStaticChildren, children, keys, children), didWarnAboutKeySpread[children + isStaticChildren] = !0);
|
|
153
207
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
208
|
+
children = null;
|
|
209
|
+
void 0 !== maybeKey && (checkKeyStringCoercion(maybeKey), children = "" + maybeKey);
|
|
210
|
+
hasValidKey(config) && (checkKeyStringCoercion(config.key), children = "" + config.key);
|
|
211
|
+
if ("key" in config) {
|
|
212
|
+
maybeKey = {};
|
|
213
|
+
for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
|
|
214
|
+
} else maybeKey = config;
|
|
215
|
+
children && defineKeyPropWarningGetter(maybeKey, "function" === typeof type ? type.displayName || type.name || "Unknown" : type);
|
|
216
|
+
return ReactElement(type, children, maybeKey, getOwner(), debugStack, debugTask);
|
|
157
217
|
}
|
|
158
|
-
function
|
|
159
|
-
|
|
218
|
+
function validateChildKeys(node) {
|
|
219
|
+
isValidElement(node) ? node._store && (node._store.validated = 1) : "object" === typeof node && null !== node && node.$$typeof === REACT_LAZY_TYPE && ("fulfilled" === node._payload.status ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
|
|
160
220
|
}
|
|
161
|
-
function
|
|
162
|
-
return
|
|
221
|
+
function isValidElement(object) {
|
|
222
|
+
return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
163
223
|
}
|
|
164
|
-
var
|
|
224
|
+
var React = __require("react"), REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, hasOwnProperty = Object.prototype.hasOwnProperty, isArrayImpl = Array.isArray, createTask = console.createTask ? console.createTask : function() {
|
|
165
225
|
return null;
|
|
166
226
|
};
|
|
167
|
-
|
|
168
|
-
return
|
|
227
|
+
React = { react_stack_bottom_frame: function(callStackForError) {
|
|
228
|
+
return callStackForError();
|
|
169
229
|
} };
|
|
170
|
-
var
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
230
|
+
var specialPropKeyWarningShown;
|
|
231
|
+
var didWarnAboutElementRef = {};
|
|
232
|
+
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(React, UnknownOwner)();
|
|
233
|
+
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
234
|
+
var didWarnAboutKeySpread = {};
|
|
235
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
236
|
+
exports.jsx = function(type, config, maybeKey) {
|
|
237
|
+
var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
238
|
+
return jsxDEVImpl(type, config, maybeKey, !1, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
239
|
+
};
|
|
240
|
+
exports.jsxs = function(type, config, maybeKey) {
|
|
241
|
+
var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
242
|
+
return jsxDEVImpl(type, config, maybeKey, !0, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
177
243
|
};
|
|
178
244
|
})();
|
|
179
|
-
}))
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
children: /* @__PURE__ */ (0, g.jsx)(f.Provider, {
|
|
245
|
+
}));
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region provider/RouterProvider.tsx
|
|
248
|
+
var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
249
|
+
if (process.env.NODE_ENV === "production") module.exports = require_react_jsx_runtime_production();
|
|
250
|
+
else module.exports = require_react_jsx_runtime_development();
|
|
251
|
+
})))();
|
|
252
|
+
var RouterProvider = ({ children, setContext, context, updateBlockedRoute, updateLocation, location, params, prefetchLoader, loaderCache, blockerState }) => {
|
|
253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionsContext.Provider, {
|
|
189
254
|
value: {
|
|
190
|
-
|
|
191
|
-
|
|
255
|
+
updateLocation,
|
|
256
|
+
updateBlockedRoute,
|
|
257
|
+
prefetchLoader,
|
|
258
|
+
setContext
|
|
192
259
|
},
|
|
193
|
-
children: /* @__PURE__ */ (0,
|
|
260
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataContext.Provider, {
|
|
194
261
|
value: {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
location: a
|
|
262
|
+
context,
|
|
263
|
+
loaderCache
|
|
198
264
|
},
|
|
199
|
-
children:
|
|
265
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NavigationContext.Provider, {
|
|
266
|
+
value: {
|
|
267
|
+
blockerState,
|
|
268
|
+
params,
|
|
269
|
+
location
|
|
270
|
+
},
|
|
271
|
+
children
|
|
272
|
+
})
|
|
200
273
|
})
|
|
201
|
-
})
|
|
202
|
-
}), v = (t, r) => {
|
|
203
|
-
let i = n(() => t().then((e) => ({ default: e.default || e })));
|
|
204
|
-
return () => /* @__PURE__ */ (0, g.jsx)(e, {
|
|
205
|
-
fallback: typeof r == "function" ? r() : r || null,
|
|
206
|
-
children: /* @__PURE__ */ (0, g.jsx)(i, {})
|
|
207
274
|
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
275
|
+
};
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region utils/createLazyComponent.tsx
|
|
278
|
+
var createLazyComponent = (importFn, fallback) => {
|
|
279
|
+
const LazyComp = lazy(() => importFn().then((module) => ({ default: module.default || module })));
|
|
280
|
+
return () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Suspense, {
|
|
281
|
+
fallback: typeof fallback === "function" ? fallback() : fallback || null,
|
|
282
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComp, {})
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region utils/utils.ts
|
|
287
|
+
var isLazy = (el) => typeof el.element === "function" && el.element.toString().includes("import(");
|
|
288
|
+
var parseClientRouteItem = (el, parentParams = [], parentPath = "") => {
|
|
289
|
+
const currentParamsList = el.path.match(/:[^/]+/g);
|
|
290
|
+
const normalizedSplitPath = el.path.replaceAll(/:[^/]+(\/|$)/g, "").split("/").filter(Boolean);
|
|
291
|
+
const splitPath = el.path.split("/");
|
|
292
|
+
const currentParams = currentParamsList ? [...parentParams, ...currentParamsList.map((param, index) => ({
|
|
293
|
+
key: normalizedSplitPath[index],
|
|
294
|
+
value: param.slice(1)
|
|
295
|
+
}))] : parentParams;
|
|
296
|
+
const path = currentParams.length ? `${parentPath}${splitPath.slice(0, splitPath.length - 1).join("/")}` : el.path;
|
|
297
|
+
const resolvedElement = isLazy(el) ? createLazyComponent(el.element, el.fallback) : el.element;
|
|
213
298
|
return [{
|
|
214
|
-
...
|
|
215
|
-
path
|
|
216
|
-
params:
|
|
217
|
-
element:
|
|
218
|
-
}, ...
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
299
|
+
...el,
|
|
300
|
+
path,
|
|
301
|
+
params: currentParams,
|
|
302
|
+
element: resolvedElement
|
|
303
|
+
}, ...el.children?.flatMap((child) => parseClientRouteItem(child, currentParams, path)) || []];
|
|
304
|
+
};
|
|
305
|
+
var createRouter = (clientList) => clientList.flatMap((el) => parseClientRouteItem(el, []));
|
|
306
|
+
var getParamsObject = (params) => {
|
|
307
|
+
const { pathname } = window.location;
|
|
308
|
+
const split = pathname.split("/");
|
|
309
|
+
return (params || []).map((el) => ({
|
|
310
|
+
index: split.findIndex((item) => item === el.key),
|
|
311
|
+
value: el.value
|
|
312
|
+
})).reduce((acc, cur) => ({
|
|
313
|
+
...acc,
|
|
314
|
+
[cur.value]: split[cur.index + 1]
|
|
227
315
|
}), {});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
316
|
+
};
|
|
317
|
+
var parseWindowLocation = (location) => ({
|
|
318
|
+
pathname: location.pathname,
|
|
319
|
+
search: location.search
|
|
320
|
+
});
|
|
321
|
+
var comparePaths = (el, pathname) => {
|
|
322
|
+
const splitElementPath = el.path.split("/").filter(Boolean);
|
|
323
|
+
const paramsLength = el.params ? Object.keys(el.params).length : 0;
|
|
324
|
+
const splitPathname = pathname.split("/").filter(Boolean);
|
|
325
|
+
return splitElementPath.every((item, index) => item === splitPathname[index + (index ? 1 : 0)]) && splitPathname.length === splitElementPath.length + paramsLength;
|
|
326
|
+
};
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region hooks/useLatest.ts
|
|
329
|
+
var useLatest = (value) => {
|
|
330
|
+
const ref = useRef(value);
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
ref.current = value;
|
|
333
|
+
}, [value]);
|
|
334
|
+
return ref;
|
|
335
|
+
};
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region hooks/useHandleNavigation.ts
|
|
338
|
+
var isRedirect = (error) => typeof error === "object" && error !== null && error.cause === "redirect";
|
|
339
|
+
var useHandleNavigation = ({ setLocation, routeList, context, revalidateCache }) => {
|
|
340
|
+
const [blockedRoute, setBlockedRoute] = useState({
|
|
241
341
|
from: "",
|
|
242
342
|
to: ""
|
|
243
|
-
})
|
|
343
|
+
});
|
|
344
|
+
const prevPathname = useRef("");
|
|
345
|
+
const setNextLocationRef = useLatest(useCallback(async (nextLocation) => {
|
|
244
346
|
try {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
347
|
+
const nextItem = routeList.find((el) => comparePaths(el, nextLocation.pathname));
|
|
348
|
+
if (nextItem?.beforeLoad) await nextItem?.beforeLoad(context);
|
|
349
|
+
setLocation(nextLocation);
|
|
350
|
+
if (nextLocation.pathname !== window.location.pathname) {
|
|
351
|
+
history.pushState(null, "", nextLocation.pathname);
|
|
352
|
+
prevPathname.current = nextLocation.pathname;
|
|
353
|
+
}
|
|
354
|
+
await revalidateCache(nextItem);
|
|
355
|
+
if (nextItem?.afterLoad) await nextItem?.afterLoad(context);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
const redirect = error;
|
|
358
|
+
if (!isRedirect(redirect)) return redirect;
|
|
359
|
+
history.replaceState(null, "", redirect.url);
|
|
360
|
+
setLocation({
|
|
361
|
+
pathname: redirect.url,
|
|
362
|
+
search: redirect.search
|
|
254
363
|
});
|
|
255
364
|
}
|
|
256
365
|
}, [
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
]))
|
|
262
|
-
|
|
263
|
-
from
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
} : (e === "process" && f.current({ pathname: n.to }), !n.from && !n.to ? n : {
|
|
268
|
-
from: "",
|
|
269
|
-
to: ""
|
|
270
|
-
})), [f]), m = r(async (e) => {
|
|
271
|
-
l.from ? u((t) => ({
|
|
272
|
-
...t,
|
|
273
|
-
to: e.pathname
|
|
274
|
-
})) : await f.current(e);
|
|
275
|
-
}, [l.from, f]);
|
|
276
|
-
return a(() => {
|
|
277
|
-
let e = async (e) => {
|
|
278
|
-
let t = C(e.target.location);
|
|
279
|
-
d.current === l.from ? (u({
|
|
280
|
-
from: d.current,
|
|
281
|
-
to: t.pathname
|
|
282
|
-
}), history.replaceState(null, "", d.current)) : f.current(t);
|
|
366
|
+
context,
|
|
367
|
+
revalidateCache,
|
|
368
|
+
routeList,
|
|
369
|
+
setLocation
|
|
370
|
+
]));
|
|
371
|
+
const updateBlockedRoute = useCallback(({ type, payload = "" }) => setBlockedRoute((prevState) => {
|
|
372
|
+
if (prevState.from === payload && type === "charge") return prevState;
|
|
373
|
+
if (payload && prevState.from !== payload && type === "charge") return {
|
|
374
|
+
...prevState,
|
|
375
|
+
from: payload
|
|
283
376
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}, [
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}), {}));
|
|
310
|
-
try {
|
|
311
|
-
a(!1);
|
|
312
|
-
let t = await e?.loader();
|
|
313
|
-
u.current = {
|
|
314
|
-
...u.current,
|
|
315
|
-
[e.path]: Date.now()
|
|
316
|
-
}, d({
|
|
317
|
-
key: e.path,
|
|
318
|
-
value: t
|
|
377
|
+
if (type === "reset") return {
|
|
378
|
+
...prevState,
|
|
379
|
+
to: ""
|
|
380
|
+
};
|
|
381
|
+
if (type === "process") setNextLocationRef.current({ pathname: prevState.to });
|
|
382
|
+
if (!prevState.from && !prevState.to) return prevState;
|
|
383
|
+
return {
|
|
384
|
+
from: "",
|
|
385
|
+
to: ""
|
|
386
|
+
};
|
|
387
|
+
}), [setNextLocationRef]);
|
|
388
|
+
const updateLocation = useCallback(async (nextLocation) => {
|
|
389
|
+
if (blockedRoute.from) setBlockedRoute((prevState) => ({
|
|
390
|
+
...prevState,
|
|
391
|
+
to: nextLocation.pathname
|
|
392
|
+
}));
|
|
393
|
+
else await setNextLocationRef.current(nextLocation);
|
|
394
|
+
}, [blockedRoute.from, setNextLocationRef]);
|
|
395
|
+
useEffect(() => {
|
|
396
|
+
const handler = async (event) => {
|
|
397
|
+
const newLocation = parseWindowLocation(event.target.location);
|
|
398
|
+
if (prevPathname.current === blockedRoute.from) {
|
|
399
|
+
setBlockedRoute({
|
|
400
|
+
from: prevPathname.current,
|
|
401
|
+
to: newLocation.pathname
|
|
319
402
|
});
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
403
|
+
history.replaceState(null, "", prevPathname.current);
|
|
404
|
+
} else setNextLocationRef.current(newLocation);
|
|
405
|
+
};
|
|
406
|
+
window.addEventListener("popstate", handler);
|
|
407
|
+
return () => window.removeEventListener("popstate", handler);
|
|
408
|
+
}, [blockedRoute.from, setNextLocationRef]);
|
|
409
|
+
useEffect(() => {
|
|
410
|
+
const currentLocation = parseWindowLocation(window.location);
|
|
411
|
+
setNextLocationRef.current(currentLocation);
|
|
412
|
+
prevPathname.current = currentLocation.pathname;
|
|
413
|
+
}, [setNextLocationRef]);
|
|
414
|
+
return {
|
|
415
|
+
blockerState: useMemo(() => {
|
|
416
|
+
if (blockedRoute.from && blockedRoute.to) return "blocked";
|
|
417
|
+
if (blockedRoute.from) return "charged";
|
|
418
|
+
return "unblocked";
|
|
419
|
+
}, [blockedRoute]),
|
|
420
|
+
updateLocation,
|
|
421
|
+
updateBlockedRoute
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region hooks/useLoader.ts
|
|
426
|
+
var useLoader = (routeList) => {
|
|
427
|
+
const [loaderCache, setLoaderCache] = useState({});
|
|
428
|
+
const [loaderError, setLoaderError] = useState(false);
|
|
429
|
+
const [isLoadingMap, setIsLoadingMap] = useState({});
|
|
430
|
+
const cacheTimestampsRef = useRef({});
|
|
431
|
+
const updateCache = useCallback(({ key, value }) => setLoaderCache((prevState) => ({
|
|
432
|
+
...prevState,
|
|
433
|
+
[key]: value
|
|
434
|
+
})), []);
|
|
435
|
+
const isCacheItemFresh = useCallback((routeItem) => {
|
|
436
|
+
if (!routeItem) return true;
|
|
437
|
+
const currentCacheTimestamp = cacheTimestampsRef.current[routeItem.path];
|
|
438
|
+
return Boolean(currentCacheTimestamp && Date.now() - currentCacheTimestamp < (routeItem.staleTime || 0));
|
|
439
|
+
}, []);
|
|
440
|
+
const revalidateCache = useCallback(async (routeItem) => {
|
|
441
|
+
if (!routeItem?.loader) return;
|
|
442
|
+
if (isCacheItemFresh(routeItem)) return;
|
|
443
|
+
setIsLoadingMap((prev) => ({
|
|
444
|
+
...prev,
|
|
445
|
+
[routeItem.path]: true
|
|
446
|
+
}));
|
|
447
|
+
setLoaderCache((prevState) => Object.keys(prevState).filter((el) => el !== routeItem.path).reduce((acc, cur) => ({
|
|
448
|
+
...acc,
|
|
449
|
+
[cur]: prevState[cur]
|
|
450
|
+
}), {}));
|
|
451
|
+
try {
|
|
452
|
+
setLoaderError(false);
|
|
453
|
+
const result = await routeItem?.loader();
|
|
454
|
+
cacheTimestampsRef.current = {
|
|
455
|
+
...cacheTimestampsRef.current,
|
|
456
|
+
[routeItem.path]: Date.now()
|
|
457
|
+
};
|
|
458
|
+
updateCache({
|
|
459
|
+
key: routeItem.path,
|
|
460
|
+
value: result
|
|
461
|
+
});
|
|
462
|
+
} catch {
|
|
463
|
+
setLoaderError(true);
|
|
464
|
+
} finally {
|
|
465
|
+
setIsLoadingMap((prev) => ({
|
|
466
|
+
...prev,
|
|
467
|
+
[routeItem.path]: false
|
|
468
|
+
}));
|
|
328
469
|
}
|
|
329
|
-
}, [
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
470
|
+
}, [isCacheItemFresh, updateCache]);
|
|
471
|
+
const prefetchLoader = useCallback(async (pathname) => {
|
|
472
|
+
const item = routeList.find((el) => comparePaths(el, pathname));
|
|
473
|
+
if (item) await revalidateCache(item);
|
|
474
|
+
}, [revalidateCache, routeList]);
|
|
333
475
|
return {
|
|
334
|
-
loaderCache:
|
|
335
|
-
loaderError
|
|
336
|
-
prefetchLoader
|
|
337
|
-
revalidateCache
|
|
338
|
-
isLoading:
|
|
476
|
+
loaderCache: loaderCache[window.location.pathname],
|
|
477
|
+
loaderError,
|
|
478
|
+
prefetchLoader,
|
|
479
|
+
revalidateCache,
|
|
480
|
+
isLoading: isLoadingMap[window.location.pathname]
|
|
339
481
|
};
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
482
|
+
};
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region utils/renderElement.tsx
|
|
485
|
+
var renderElement = (Component) => {
|
|
486
|
+
if (!Component) return null;
|
|
487
|
+
return typeof Component === "function" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) : Component;
|
|
488
|
+
};
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region components/Router.tsx
|
|
491
|
+
var PAGE_NOT_FOUND = "error 404. Page not found";
|
|
492
|
+
var ALL_LOCATIONS = "*";
|
|
493
|
+
var Router = ({ routeList, context: initialContext = {} }) => {
|
|
494
|
+
const [location, setLocation] = useState(parseWindowLocation(window.location));
|
|
495
|
+
const [context, setContext] = useState(initialContext);
|
|
496
|
+
const routeItem = useMemo(() => routeList.find((el) => el.path === ALL_LOCATIONS || comparePaths(el, location.pathname)), [location.pathname, routeList]);
|
|
497
|
+
const { loaderError, loaderCache, prefetchLoader, revalidateCache, isLoading } = useLoader(routeList);
|
|
498
|
+
const { blockerState, updateLocation, updateBlockedRoute } = useHandleNavigation({
|
|
499
|
+
setLocation,
|
|
500
|
+
routeList,
|
|
501
|
+
context,
|
|
502
|
+
revalidateCache
|
|
503
|
+
});
|
|
504
|
+
const params = useMemo(() => routeItem?.params ? getParamsObject(routeItem.params) : {}, [routeItem]);
|
|
505
|
+
const providerProps = useMemo(() => ({
|
|
506
|
+
location,
|
|
507
|
+
updateLocation,
|
|
508
|
+
params,
|
|
509
|
+
loaderCache,
|
|
510
|
+
prefetchLoader,
|
|
511
|
+
updateBlockedRoute,
|
|
512
|
+
blockerState,
|
|
513
|
+
context,
|
|
514
|
+
setContext
|
|
356
515
|
}), [
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
516
|
+
blockerState,
|
|
517
|
+
loaderCache,
|
|
518
|
+
location,
|
|
519
|
+
params,
|
|
520
|
+
prefetchLoader,
|
|
521
|
+
context,
|
|
522
|
+
updateBlockedRoute,
|
|
523
|
+
updateLocation
|
|
365
524
|
]);
|
|
366
|
-
|
|
367
|
-
...
|
|
368
|
-
children:
|
|
369
|
-
}) : l ? /* @__PURE__ */ (0, g.jsx)(_, {
|
|
370
|
-
...b,
|
|
371
|
-
children: k(s?.errorElement)
|
|
372
|
-
}) : /* @__PURE__ */ (0, g.jsx)(_, {
|
|
373
|
-
...b,
|
|
374
|
-
children: k(s?.element) || A
|
|
525
|
+
if (routeItem?.loader && !loaderError && isLoading) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterProvider, {
|
|
526
|
+
...providerProps,
|
|
527
|
+
children: renderElement(routeItem?.loaderFallback)
|
|
375
528
|
});
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
return
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
529
|
+
if (loaderError) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterProvider, {
|
|
530
|
+
...providerProps,
|
|
531
|
+
children: renderElement(routeItem?.errorElement)
|
|
532
|
+
});
|
|
533
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterProvider, {
|
|
534
|
+
...providerProps,
|
|
535
|
+
children: renderElement(routeItem?.element) || PAGE_NOT_FOUND
|
|
536
|
+
});
|
|
537
|
+
};
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region hooks/useServiceContext.ts
|
|
540
|
+
var useNavigationState = () => {
|
|
541
|
+
const context = useContext(NavigationContext);
|
|
542
|
+
if (!Object.keys(context).length) throw new Error("useNavigationState must be used within Router component");
|
|
543
|
+
return context;
|
|
544
|
+
};
|
|
545
|
+
var useRouterActions = () => {
|
|
546
|
+
const context = useContext(ActionsContext);
|
|
547
|
+
if (!Object.keys(context).length) throw new Error("useRouterActions must be used within Router component");
|
|
548
|
+
return context;
|
|
549
|
+
};
|
|
550
|
+
var useRouterData = () => {
|
|
551
|
+
const context = useContext(DataContext);
|
|
552
|
+
if (!Object.keys(context).length) throw new Error("useRouterData must be used within Router component");
|
|
553
|
+
return context;
|
|
554
|
+
};
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region hooks/useNavigate.ts
|
|
557
|
+
var useNavigate = () => {
|
|
558
|
+
const { updateLocation } = useRouterActions();
|
|
559
|
+
return useCallback(async (arg) => arg === -1 ? history.go(-1) : await updateLocation(arg), [updateLocation]);
|
|
560
|
+
};
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region components/Link.tsx
|
|
563
|
+
var Link = ({ children, to, prefetch = true }) => {
|
|
564
|
+
const { prefetchLoader } = useRouterActions();
|
|
565
|
+
const navigate = useNavigate();
|
|
566
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
|
|
394
567
|
style: { cursor: "pointer" },
|
|
395
|
-
onClick: () =>
|
|
396
|
-
onMouseOver: () =>
|
|
397
|
-
children
|
|
568
|
+
onClick: () => navigate({ pathname: to }),
|
|
569
|
+
onMouseOver: () => prefetch && prefetchLoader(to),
|
|
570
|
+
children
|
|
398
571
|
});
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
572
|
+
};
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region hooks/useParams.ts
|
|
575
|
+
var useParams = () => {
|
|
576
|
+
const { params } = useNavigationState();
|
|
577
|
+
return params;
|
|
578
|
+
};
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region hooks/useLocation.ts
|
|
581
|
+
var useLocation = () => {
|
|
582
|
+
return useNavigationState().location;
|
|
583
|
+
};
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region hooks/useLoaderState.ts
|
|
586
|
+
var useLoaderState = () => {
|
|
587
|
+
const { loaderCache } = useRouterData();
|
|
588
|
+
return loaderCache;
|
|
589
|
+
};
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region hooks/useBlocker.ts
|
|
592
|
+
var useBlocker = (blockerFn) => {
|
|
593
|
+
const { location: { pathname }, blockerState } = useNavigationState();
|
|
594
|
+
const { updateBlockedRoute } = useRouterActions();
|
|
595
|
+
const shouldBlock = blockerFn();
|
|
596
|
+
useEffect(() => updateBlockedRoute(shouldBlock ? {
|
|
408
597
|
type: "charge",
|
|
409
|
-
payload:
|
|
598
|
+
payload: pathname
|
|
410
599
|
} : { type: "unblock" }), [
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
])
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
600
|
+
shouldBlock,
|
|
601
|
+
pathname,
|
|
602
|
+
updateBlockedRoute
|
|
603
|
+
]);
|
|
604
|
+
return {
|
|
605
|
+
state: blockerState,
|
|
606
|
+
process: () => updateBlockedRoute({ type: "process" }),
|
|
607
|
+
reset: () => updateBlockedRoute({ type: "reset" })
|
|
418
608
|
};
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
609
|
+
};
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region hooks/useBeforeUnload.ts
|
|
612
|
+
var useBeforeUnload = (callback) => {
|
|
613
|
+
useEffect(() => {
|
|
614
|
+
const handler = (event) => {
|
|
615
|
+
if (!callback) return;
|
|
616
|
+
event.preventDefault();
|
|
617
|
+
callback();
|
|
423
618
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
},
|
|
427
|
-
|
|
619
|
+
window.addEventListener("beforeunload", handler);
|
|
620
|
+
return () => window.removeEventListener("beforeunload", handler);
|
|
621
|
+
}, [callback]);
|
|
622
|
+
};
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region hooks/useRouterContext.ts
|
|
625
|
+
var useRouterContext = () => {
|
|
626
|
+
const { context } = useRouterData();
|
|
627
|
+
const { setContext } = useRouterActions();
|
|
428
628
|
return {
|
|
429
|
-
context
|
|
430
|
-
setContext
|
|
629
|
+
context,
|
|
630
|
+
setContext
|
|
431
631
|
};
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
632
|
+
};
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region utils/redirect.ts
|
|
635
|
+
var redirect = (url, search) => {
|
|
636
|
+
const error = /* @__PURE__ */ new Error();
|
|
637
|
+
error.cause = "redirect";
|
|
638
|
+
throw Object.assign(error, {
|
|
639
|
+
url,
|
|
640
|
+
search: search || ""
|
|
437
641
|
});
|
|
438
642
|
};
|
|
439
643
|
//#endregion
|
|
440
|
-
export {
|
|
644
|
+
export { Link, Router, createRouter, redirect, useBeforeUnload, useBlocker, useLoaderState, useLocation, useNavigate, useParams, useRouterContext };
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-react-router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "A lightweight, type-safe routing library for React applications",
|
|
5
5
|
"author": "Andrew Bubnov",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
6
|
"scripts": {
|
|
10
7
|
"build": "vite build && tsc --emitDeclarationOnly"
|
|
11
8
|
},
|
|
@@ -31,6 +28,9 @@
|
|
|
31
28
|
],
|
|
32
29
|
"license": "MIT",
|
|
33
30
|
"type": "module",
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
36
36
|
"types": "./dist/index.d.ts",
|