clear-react-router 1.0.15 → 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.
Files changed (2) hide show
  1. package/dist/index.js +556 -351
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,439 +1,644 @@
1
- import { Suspense as e, createContext as t, lazy as n, useCallback as r, useContext as i, useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
1
+ import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
2
2
  //#region \0rolldown/runtime.js
3
- var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), u = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
4
- if (typeof require < "u") return require.apply(this, arguments);
5
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
- }), d = t({}), f = t({}), p = t({}), m = /* @__PURE__ */ l(((e) => {
7
- var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
8
- function r(e, n, r) {
9
- var i = null;
10
- if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
11
- else r = n;
12
- return n = r.ref, {
13
- $$typeof: t,
14
- type: e,
15
- key: i,
16
- ref: n === void 0 ? null : n,
17
- props: r
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
- e.Fragment = n, e.jsx = r, e.jsxs = r;
21
- })), h = /* @__PURE__ */ l(((e) => {
22
- process.env.NODE_ENV !== "production" && (function() {
23
- function t(e) {
24
- if (e == null) return null;
25
- if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
26
- if (typeof e == "string") return e;
27
- switch (e) {
28
- case v: return "Fragment";
29
- case b: return "Profiler";
30
- case y: return "StrictMode";
31
- case w: return "Suspense";
32
- case T: return "SuspenseList";
33
- case O: return "Activity";
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 e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
36
- case _: return "Portal";
37
- case S: return e.displayName || "Context";
38
- case x: return (e._context.displayName || "Context") + ".Consumer";
39
- case C:
40
- var n = e.render;
41
- return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
42
- case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
43
- case D:
44
- n = e._payload, e = e._init;
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 t(e(n));
47
- } catch {}
86
+ return getComponentNameFromType(type(innerType));
87
+ } catch (x) {}
48
88
  }
49
89
  return null;
50
90
  }
51
- function n(e) {
52
- return "" + e;
91
+ function testStringCoercion(value) {
92
+ return "" + value;
53
93
  }
54
- function r(e) {
94
+ function checkKeyStringCoercion(value) {
55
95
  try {
56
- n(e);
57
- var t = !1;
58
- } catch {
59
- t = !0;
96
+ testStringCoercion(value);
97
+ var JSCompiler_inline_result = !1;
98
+ } catch (e) {
99
+ JSCompiler_inline_result = !0;
60
100
  }
61
- if (t) {
62
- t = console;
63
- var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
64
- return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
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 i(e) {
68
- if (e === v) return "<>";
69
- if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
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 n = t(e);
72
- return n ? "<" + n + ">" : "<...>";
73
- } catch {
113
+ var name = getComponentNameFromType(type);
114
+ return name ? "<" + name + ">" : "<...>";
115
+ } catch (x) {
74
116
  return "<...>";
75
117
  }
76
118
  }
77
- function a() {
78
- var e = A.A;
79
- return e === null ? null : e.getOwner();
119
+ function getOwner() {
120
+ var dispatcher = ReactSharedInternals.A;
121
+ return null === dispatcher ? null : dispatcher.getOwner();
80
122
  }
81
- function o() {
123
+ function UnknownOwner() {
82
124
  return Error("react-stack-top-frame");
83
125
  }
84
- function s(e) {
85
- if (j.call(e, "key")) {
86
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
87
- if (t && t.isReactWarning) return !1;
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 e.key !== void 0;
131
+ return void 0 !== config.key;
90
132
  }
91
- function c(e, t) {
92
- function n() {
93
- P || (P = !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)", t));
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
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
96
- get: n,
137
+ warnAboutAccessingKey.isReactWarning = !0;
138
+ Object.defineProperty(props, "key", {
139
+ get: warnAboutAccessingKey,
97
140
  configurable: !0
98
141
  });
99
142
  }
100
- function l() {
101
- var e = t(this.type);
102
- return F[e] || (F[e] = !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.")), e = this.props.ref, e === void 0 ? null : e;
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 d(e, t, n, r, i, a) {
105
- var o = n.ref;
106
- return e = {
107
- $$typeof: g,
108
- type: e,
109
- key: t,
110
- props: n,
111
- _owner: r
112
- }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
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
- value: null
115
- }) : Object.defineProperty(e, "ref", {
160
+ get: elementRefGetterWithDeprecationWarning
161
+ }) : Object.defineProperty(type, "ref", {
116
162
  enumerable: !1,
117
- get: l
118
- }), e._store = {}, Object.defineProperty(e._store, "validated", {
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
- }), Object.defineProperty(e, "_debugInfo", {
171
+ });
172
+ Object.defineProperty(type, "_debugInfo", {
124
173
  configurable: !1,
125
174
  enumerable: !1,
126
175
  writable: !0,
127
176
  value: null
128
- }), Object.defineProperty(e, "_debugStack", {
177
+ });
178
+ Object.defineProperty(type, "_debugStack", {
129
179
  configurable: !1,
130
180
  enumerable: !1,
131
181
  writable: !0,
132
- value: i
133
- }), Object.defineProperty(e, "_debugTask", {
182
+ value: debugStack
183
+ });
184
+ Object.defineProperty(type, "_debugTask", {
134
185
  configurable: !1,
135
186
  enumerable: !1,
136
187
  writable: !0,
137
- value: a
138
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
188
+ value: debugTask
189
+ });
190
+ Object.freeze && (Object.freeze(type.props), Object.freeze(type));
191
+ return type;
139
192
  }
140
- function f(e, n, i, o, l, u) {
141
- var f = n.children;
142
- if (f !== void 0) if (o) if (M(f)) {
143
- for (o = 0; o < f.length; o++) p(f[o]);
144
- Object.freeze && Object.freeze(f);
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 p(f);
147
- if (j.call(n, "key")) {
148
- f = t(e);
149
- var m = Object.keys(n).filter(function(e) {
150
- return e !== "key";
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
- o = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + o] || (m = 0 < m.length ? "{" + m.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} />", o, f, m, f), R[f + o] = !0);
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
- if (f = null, i !== void 0 && (r(i), f = "" + i), s(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
155
- else i = n;
156
- return f && c(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), l, u);
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 p(e) {
159
- m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
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 m(e) {
162
- return typeof e == "object" && !!e && e.$$typeof === g;
221
+ function isValidElement(object) {
222
+ return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
163
223
  }
164
- var h = u("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
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
- h = { react_stack_bottom_frame: function(e) {
168
- return e();
227
+ React = { react_stack_bottom_frame: function(callStackForError) {
228
+ return callStackForError();
169
229
  } };
170
- var P, F = {}, I = h.react_stack_bottom_frame.bind(h, o)(), L = N(i(o)), R = {};
171
- e.Fragment = v, e.jsx = function(e, t, n) {
172
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
173
- return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
174
- }, e.jsxs = function(e, t, n) {
175
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
176
- return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
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
- })), g = (/* @__PURE__ */ l(((e, t) => {
180
- process.env.NODE_ENV === "production" ? t.exports = m() : t.exports = h();
181
- })))(), _ = ({ children: e, setContext: t, context: n, updateBlockedRoute: r, updateLocation: i, location: a, params: o, prefetchLoader: s, loaderCache: c, blockerState: l }) => /* @__PURE__ */ (0, g.jsx)(d.Provider, {
182
- value: {
183
- updateLocation: i,
184
- updateBlockedRoute: r,
185
- prefetchLoader: s,
186
- setContext: t
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
- context: n,
191
- loaderCache: c
255
+ updateLocation,
256
+ updateBlockedRoute,
257
+ prefetchLoader,
258
+ setContext
192
259
  },
193
- children: /* @__PURE__ */ (0, g.jsx)(p.Provider, {
260
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataContext.Provider, {
194
261
  value: {
195
- blockerState: l,
196
- params: o,
197
- location: a
262
+ context,
263
+ loaderCache
198
264
  },
199
- children: e
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
- }, y = (e) => typeof e.element == "function" && e.element.toString().includes("import("), b = (e, t = [], n = "") => {
209
- let r = e.path.match(/:[^/]+/g), i = e.path.replaceAll(/:[^/]+(\/|$)/g, "").split("/").filter(Boolean), a = e.path.split("/"), o = r ? [...t, ...r.map((e, t) => ({
210
- key: i[t],
211
- value: e.slice(1)
212
- }))] : t, s = o.length ? `${n}${a.slice(0, a.length - 1).join("/")}` : e.path, c = y(e) ? v(e.element, e.fallback) : e.element;
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
- ...e,
215
- path: s,
216
- params: o,
217
- element: c
218
- }, ...e.children?.flatMap((e) => b(e, o, s)) || []];
219
- }, x = (e) => e.flatMap((e) => b(e, [])), S = (e) => {
220
- let { pathname: t } = window.location, n = t.split("/");
221
- return (e || []).map((e) => ({
222
- index: n.findIndex((t) => t === e.key),
223
- value: e.value
224
- })).reduce((e, t) => ({
225
- ...e,
226
- [t.value]: n[t.index + 1]
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
- }, C = (e) => ({
229
- pathname: e.pathname,
230
- search: e.search
231
- }), w = (e, t) => {
232
- let n = e.path.split("/").filter(Boolean), r = e.params ? Object.keys(e.params).length : 0, i = t.split("/").filter(Boolean);
233
- return n.every((e, t) => e === i[t + +!!t]) && i.length === n.length + r;
234
- }, T = (e) => {
235
- let t = s(e);
236
- return a(() => {
237
- t.current = e;
238
- }, [e]), t;
239
- }, E = (e) => typeof e == "object" && !!e && e.cause === "redirect", D = ({ setLocation: e, routeList: t, context: n, revalidateCache: i }) => {
240
- let [l, u] = c({
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
- }), d = s(""), f = T(r(async (r) => {
343
+ });
344
+ const prevPathname = useRef("");
345
+ const setNextLocationRef = useLatest(useCallback(async (nextLocation) => {
244
346
  try {
245
- let a = t.find((e) => w(e, r.pathname));
246
- a?.beforeLoad && await a?.beforeLoad(n), e(r), r.pathname !== window.location.pathname && (history.pushState(null, "", r.pathname), d.current = r.pathname), await i(a), a?.afterLoad && await a?.afterLoad(n);
247
- } catch (t) {
248
- let n = t;
249
- if (!E(n)) return n;
250
- history.replaceState(null, "", n.url), e({
251
- pathname: n.url,
252
- search: n.search
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
253
363
  });
254
364
  }
255
365
  }, [
256
- n,
257
- i,
258
- t,
259
- e
260
- ])), p = r(({ type: e, payload: t = "" }) => u((n) => n.from === t && e === "charge" ? n : t && n.from !== t && e === "charge" ? {
261
- ...n,
262
- from: t
263
- } : e === "reset" ? {
264
- ...n,
265
- to: ""
266
- } : (e === "process" && f.current({ pathname: n.to }), !n.from && !n.to ? n : {
267
- from: "",
268
- to: ""
269
- })), [f]), m = r(async (e) => {
270
- l.from ? u((t) => ({
271
- ...t,
272
- to: e.pathname
273
- })) : await f.current(e);
274
- }, [l.from, f]);
275
- return a(() => {
276
- let e = async (e) => {
277
- let t = C(e.target.location);
278
- d.current === l.from ? (u({
279
- from: d.current,
280
- to: t.pathname
281
- }), 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
282
376
  };
283
- return window.addEventListener("popstate", e), () => window.removeEventListener("popstate", e);
284
- }, [l.from, f]), a(() => {
285
- let e = C(window.location);
286
- f.current(e), d.current = e.pathname;
287
- }, [f]), {
288
- blockerState: o(() => l.from && l.to ? "blocked" : l.from ? "charged" : "unblocked", [l]),
289
- updateLocation: m,
290
- updateBlockedRoute: p
291
- };
292
- }, O = (e) => {
293
- let [t, n] = c({}), [i, a] = c(!1), [o, l] = c({}), u = s({}), d = r(({ key: e, value: t }) => n((n) => ({
294
- ...n,
295
- [e]: t
296
- })), []), f = r((e) => {
297
- if (!e) return !0;
298
- let t = u.current[e.path];
299
- return !!(t && Date.now() - t < (e.staleTime || 0));
300
- }, []), p = r(async (e) => {
301
- if (e?.loader && !f(e)) {
302
- l((t) => ({
303
- ...t,
304
- [e.path]: !0
305
- })), n((t) => Object.keys(t).filter((t) => t !== e.path).reduce((e, n) => ({
306
- ...e,
307
- [n]: t[n]
308
- }), {}));
309
- try {
310
- a(!1);
311
- let t = await e?.loader();
312
- u.current = {
313
- ...u.current,
314
- [e.path]: Date.now()
315
- }, d({
316
- key: e.path,
317
- 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
318
402
  });
319
- } catch {
320
- a(!0);
321
- } finally {
322
- l((t) => ({
323
- ...t,
324
- [e.path]: !1
325
- }));
326
- }
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
+ }));
327
469
  }
328
- }, [f, d]), m = r(async (t) => {
329
- let n = e.find((e) => w(e, t));
330
- n && await p(n);
331
- }, [p, e]);
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]);
332
475
  return {
333
- loaderCache: t[window.location.pathname],
334
- loaderError: i,
335
- prefetchLoader: m,
336
- revalidateCache: p,
337
- isLoading: o[window.location.pathname]
476
+ loaderCache: loaderCache[window.location.pathname],
477
+ loaderError,
478
+ prefetchLoader,
479
+ revalidateCache,
480
+ isLoading: isLoadingMap[window.location.pathname]
338
481
  };
339
- }, k = (e) => e ? typeof e == "function" ? /* @__PURE__ */ (0, g.jsx)(e, {}) : e : null, A = "error 404. Page not found", j = "*", M = ({ routeList: e, context: t = {} }) => {
340
- let [n, r] = c(C(window.location)), [i, a] = c(t), s = o(() => e.find((e) => e.path === j || w(e, n.pathname)), [n.pathname, e]), { loaderError: l, loaderCache: u, prefetchLoader: d, revalidateCache: f, isLoading: p } = O(e), { blockerState: m, updateLocation: h, updateBlockedRoute: v } = D({
341
- setLocation: r,
342
- routeList: e,
343
- context: i,
344
- revalidateCache: f
345
- }), y = o(() => s?.params ? S(s.params) : {}, [s]), b = o(() => ({
346
- location: n,
347
- updateLocation: h,
348
- params: y,
349
- loaderCache: u,
350
- prefetchLoader: d,
351
- updateBlockedRoute: v,
352
- blockerState: m,
353
- context: i,
354
- setContext: a
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
355
515
  }), [
356
- m,
357
- u,
358
- n,
359
- y,
360
- d,
361
- i,
362
- v,
363
- h
516
+ blockerState,
517
+ loaderCache,
518
+ location,
519
+ params,
520
+ prefetchLoader,
521
+ context,
522
+ updateBlockedRoute,
523
+ updateLocation
364
524
  ]);
365
- return s?.loader && !l && p ? /* @__PURE__ */ (0, g.jsx)(_, {
366
- ...b,
367
- children: k(s?.loaderFallback)
368
- }) : l ? /* @__PURE__ */ (0, g.jsx)(_, {
369
- ...b,
370
- children: k(s?.errorElement)
371
- }) : /* @__PURE__ */ (0, g.jsx)(_, {
372
- ...b,
373
- 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)
374
528
  });
375
- }, N = () => {
376
- let e = i(p);
377
- if (!Object.keys(e).length) throw Error("useNavigationState must be used within Router component");
378
- return e;
379
- }, P = () => {
380
- let e = i(d);
381
- if (!Object.keys(e).length) throw Error("useRouterActions must be used within Router component");
382
- return e;
383
- }, F = () => {
384
- let e = i(f);
385
- if (!Object.keys(e).length) throw Error("useRouterData must be used within Router component");
386
- return e;
387
- }, I = () => {
388
- let { updateLocation: e } = P();
389
- return r(async (t) => t === -1 ? history.go(-1) : await e(t), [e]);
390
- }, L = ({ children: e, to: t, prefetch: n = !0 }) => {
391
- let { prefetchLoader: r } = P(), i = I();
392
- return /* @__PURE__ */ (0, g.jsx)("a", {
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", {
393
567
  style: { cursor: "pointer" },
394
- onClick: () => i({ pathname: t }),
395
- onMouseOver: () => n && r(t),
396
- children: e
568
+ onClick: () => navigate({ pathname: to }),
569
+ onMouseOver: () => prefetch && prefetchLoader(to),
570
+ children
397
571
  });
398
- }, R = () => {
399
- let { params: e } = N();
400
- return e;
401
- }, z = () => N().location, B = () => {
402
- let { loaderCache: e } = F();
403
- return e;
404
- }, V = (e) => {
405
- let { location: { pathname: t }, blockerState: n } = N(), { updateBlockedRoute: r } = P(), i = e();
406
- return a(() => r(i ? {
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 ? {
407
597
  type: "charge",
408
- payload: t
598
+ payload: pathname
409
599
  } : { type: "unblock" }), [
410
- i,
411
- t,
412
- r
413
- ]), {
414
- state: n,
415
- process: () => r({ type: "process" }),
416
- reset: () => r({ type: "reset" })
600
+ shouldBlock,
601
+ pathname,
602
+ updateBlockedRoute
603
+ ]);
604
+ return {
605
+ state: blockerState,
606
+ process: () => updateBlockedRoute({ type: "process" }),
607
+ reset: () => updateBlockedRoute({ type: "reset" })
417
608
  };
418
- }, H = (e) => {
419
- a(() => {
420
- let t = (t) => {
421
- e && (t.preventDefault(), e());
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();
422
618
  };
423
- return window.addEventListener("beforeunload", t), () => window.removeEventListener("beforeunload", t);
424
- }, [e]);
425
- }, U = () => {
426
- let { context: e } = F(), { setContext: t } = P();
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();
427
628
  return {
428
- context: e,
429
- setContext: t
629
+ context,
630
+ setContext
430
631
  };
431
- }, W = (e, t) => {
432
- let n = /* @__PURE__ */ Error();
433
- throw n.cause = "redirect", Object.assign(n, {
434
- url: e,
435
- search: t || ""
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 || ""
436
641
  });
437
642
  };
438
643
  //#endregion
439
- export { L as Link, M as Router, x as createRouter, W as redirect, H as useBeforeUnload, V as useBlocker, B as useLoaderState, z as useLocation, I as useNavigate, R as useParams, U as useRouterContext };
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.15",
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",