crossroad 3.0.4 → 3.0.5
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.min.js +687 -0
- package/dist/src/Context.d.ts +3 -0
- package/dist/src/Route.d.ts +36 -0
- package/dist/src/Router.d.ts +8 -0
- package/dist/src/Switch.d.ts +10 -0
- package/dist/src/helpers/format.d.ts +3 -0
- package/dist/src/helpers/getHref.d.ts +2 -0
- package/dist/src/helpers/isServer.d.ts +2 -0
- package/dist/src/helpers/samePath.d.ts +2 -0
- package/dist/src/hooks/useHash.d.ts +5 -0
- package/dist/src/hooks/useParams.d.ts +4 -0
- package/dist/src/hooks/usePath.d.ts +5 -0
- package/dist/src/hooks/useQuery.d.ts +8 -0
- package/dist/src/hooks/useUrl.d.ts +3 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/types.d.ts +18 -0
- package/package.json +16 -31
- package/index.d.ts +0 -95
- package/index.min.js +0 -1
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
import { createContext as hr, useCallback as U, useContext as xe, useEffect as re, useRef as gr, useState as mr } from "react";
|
|
2
|
+
var ne = (n, a) => () => (a || n((a = { exports: {} }).exports, a), a.exports), Ae = /* @__PURE__ */ ((n) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(n, { get: (a, f) => (typeof require < "u" ? require : a)[f] }) : n)(function(n) {
|
|
3
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
4
|
+
throw Error('Calling `require` for "' + n + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
+
}), B = hr(void 0), br = (n) => n.length > 1 ? n : n[0], j = (n) => {
|
|
6
|
+
if (typeof n != "string") return n;
|
|
7
|
+
const a = { query: {} }, f = new URL(n, "http://localhost:3000/");
|
|
8
|
+
a.path = (f.pathname.replace(/\/$/, "") || "/").replaceAll("%3C", "<").replaceAll("%3E", ">"), a.query = {};
|
|
9
|
+
for (const [s] of f.searchParams) a.query[s] = br(f.searchParams.getAll(s));
|
|
10
|
+
return f.hash && (a.hash = f.hash.replace(/^#/, "")), a;
|
|
11
|
+
}, q = (n) => {
|
|
12
|
+
if (typeof n == "string") return n;
|
|
13
|
+
const { path: a, query: f = {}, hash: s } = n || {};
|
|
14
|
+
let o = a || "/";
|
|
15
|
+
const p = new URLSearchParams(Object.entries(f).map(([u, l]) => (Array.isArray(l) ? l : [l]).map((y) => [u, y])).flat().filter(([u, l]) => l)).toString();
|
|
16
|
+
return p && (o += "?" + p), s && (o += "#" + s), o;
|
|
17
|
+
}, _r = (n) => {
|
|
18
|
+
if (!n) return null;
|
|
19
|
+
const a = n.getAttribute("href");
|
|
20
|
+
if (!a) return null;
|
|
21
|
+
const f = a.trim();
|
|
22
|
+
return /^[a-zA-Z][a-zA-Z0-9+\-.]*:/.test(f) || n.getAttribute("target") !== null ? null : f;
|
|
23
|
+
}, ke = () => typeof window > "u", Er = /* @__PURE__ */ ne(((n) => {
|
|
24
|
+
var a = Ae("react"), f = /* @__PURE__ */ Symbol.for("react.element"), s = /* @__PURE__ */ Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, p = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, u = {
|
|
25
|
+
key: !0,
|
|
26
|
+
ref: !0,
|
|
27
|
+
__self: !0,
|
|
28
|
+
__source: !0
|
|
29
|
+
};
|
|
30
|
+
function l(y, g, R) {
|
|
31
|
+
var m, h = {}, P = null, k = null;
|
|
32
|
+
R !== void 0 && (P = "" + R), g.key !== void 0 && (P = "" + g.key), g.ref !== void 0 && (k = g.ref);
|
|
33
|
+
for (m in g) o.call(g, m) && !u.hasOwnProperty(m) && (h[m] = g[m]);
|
|
34
|
+
if (y && y.defaultProps) for (m in g = y.defaultProps, g) h[m] === void 0 && (h[m] = g[m]);
|
|
35
|
+
return {
|
|
36
|
+
$$typeof: f,
|
|
37
|
+
type: y,
|
|
38
|
+
key: P,
|
|
39
|
+
ref: k,
|
|
40
|
+
props: h,
|
|
41
|
+
_owner: p.current
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
n.Fragment = s, n.jsx = l, n.jsxs = l;
|
|
45
|
+
})), Rr = /* @__PURE__ */ ne(((n) => {
|
|
46
|
+
process.env.NODE_ENV !== "production" && (function() {
|
|
47
|
+
"use strict";
|
|
48
|
+
var a = Ae("react"), f = /* @__PURE__ */ Symbol.for("react.element"), s = /* @__PURE__ */ Symbol.for("react.portal"), o = /* @__PURE__ */ Symbol.for("react.fragment"), p = /* @__PURE__ */ Symbol.for("react.strict_mode"), u = /* @__PURE__ */ Symbol.for("react.profiler"), l = /* @__PURE__ */ Symbol.for("react.provider"), y = /* @__PURE__ */ Symbol.for("react.context"), g = /* @__PURE__ */ Symbol.for("react.forward_ref"), R = /* @__PURE__ */ Symbol.for("react.suspense"), m = /* @__PURE__ */ Symbol.for("react.suspense_list"), h = /* @__PURE__ */ Symbol.for("react.memo"), P = /* @__PURE__ */ Symbol.for("react.lazy"), k = /* @__PURE__ */ Symbol.for("react.offscreen"), ae = Symbol.iterator, De = "@@iterator";
|
|
49
|
+
function Fe(e) {
|
|
50
|
+
if (e === null || typeof e != "object") return null;
|
|
51
|
+
var r = ae && e[ae] || e[De];
|
|
52
|
+
return typeof r == "function" ? r : null;
|
|
53
|
+
}
|
|
54
|
+
var D = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
55
|
+
function w(e) {
|
|
56
|
+
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), i = 1; i < r; i++) t[i - 1] = arguments[i];
|
|
57
|
+
Ie("error", e, t);
|
|
58
|
+
}
|
|
59
|
+
function Ie(e, r, t) {
|
|
60
|
+
var i = D.ReactDebugCurrentFrame.getStackAddendum();
|
|
61
|
+
i !== "" && (r += "%s", t = t.concat([i]));
|
|
62
|
+
var d = t.map(function(b) {
|
|
63
|
+
return String(b);
|
|
64
|
+
});
|
|
65
|
+
d.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, d);
|
|
66
|
+
}
|
|
67
|
+
var Ne = !1, We = !1, $e = !1, Le = !1, Ue = !1, Ye = /* @__PURE__ */ Symbol.for("react.module.reference");
|
|
68
|
+
function Me(e) {
|
|
69
|
+
return !!(typeof e == "string" || typeof e == "function" || e === o || e === u || Ue || e === p || e === R || e === m || Le || e === k || Ne || We || $e || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === h || e.$$typeof === l || e.$$typeof === y || e.$$typeof === g || e.$$typeof === Ye || e.getModuleId !== void 0));
|
|
70
|
+
}
|
|
71
|
+
function Ve(e, r, t) {
|
|
72
|
+
var i = e.displayName;
|
|
73
|
+
if (i) return i;
|
|
74
|
+
var d = r.displayName || r.name || "";
|
|
75
|
+
return d !== "" ? t + "(" + d + ")" : t;
|
|
76
|
+
}
|
|
77
|
+
function oe(e) {
|
|
78
|
+
return e.displayName || "Context";
|
|
79
|
+
}
|
|
80
|
+
function C(e) {
|
|
81
|
+
if (e == null) return null;
|
|
82
|
+
if (typeof e.tag == "number" && w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null;
|
|
83
|
+
if (typeof e == "string") return e;
|
|
84
|
+
switch (e) {
|
|
85
|
+
case o:
|
|
86
|
+
return "Fragment";
|
|
87
|
+
case s:
|
|
88
|
+
return "Portal";
|
|
89
|
+
case u:
|
|
90
|
+
return "Profiler";
|
|
91
|
+
case p:
|
|
92
|
+
return "StrictMode";
|
|
93
|
+
case R:
|
|
94
|
+
return "Suspense";
|
|
95
|
+
case m:
|
|
96
|
+
return "SuspenseList";
|
|
97
|
+
}
|
|
98
|
+
if (typeof e == "object") switch (e.$$typeof) {
|
|
99
|
+
case y:
|
|
100
|
+
return oe(e) + ".Consumer";
|
|
101
|
+
case l:
|
|
102
|
+
return oe(e._context) + ".Provider";
|
|
103
|
+
case g:
|
|
104
|
+
return Ve(e, e.render, "ForwardRef");
|
|
105
|
+
case h:
|
|
106
|
+
var r = e.displayName || null;
|
|
107
|
+
return r !== null ? r : C(e.type) || "Memo";
|
|
108
|
+
case P:
|
|
109
|
+
var t = e, i = t._payload, d = t._init;
|
|
110
|
+
try {
|
|
111
|
+
return C(d(i));
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
var x = Object.assign, W = 0, ie, se, ue, le, fe, ce, pe;
|
|
119
|
+
function ve() {
|
|
120
|
+
}
|
|
121
|
+
ve.__reactDisabledLog = !0;
|
|
122
|
+
function Be() {
|
|
123
|
+
if (W === 0) {
|
|
124
|
+
ie = console.log, se = console.info, ue = console.warn, le = console.error, fe = console.group, ce = console.groupCollapsed, pe = console.groupEnd;
|
|
125
|
+
var e = {
|
|
126
|
+
configurable: !0,
|
|
127
|
+
enumerable: !0,
|
|
128
|
+
value: ve,
|
|
129
|
+
writable: !0
|
|
130
|
+
};
|
|
131
|
+
Object.defineProperties(console, {
|
|
132
|
+
info: e,
|
|
133
|
+
log: e,
|
|
134
|
+
warn: e,
|
|
135
|
+
error: e,
|
|
136
|
+
group: e,
|
|
137
|
+
groupCollapsed: e,
|
|
138
|
+
groupEnd: e
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
W++;
|
|
142
|
+
}
|
|
143
|
+
function Ke() {
|
|
144
|
+
if (W--, W === 0) {
|
|
145
|
+
var e = {
|
|
146
|
+
configurable: !0,
|
|
147
|
+
enumerable: !0,
|
|
148
|
+
writable: !0
|
|
149
|
+
};
|
|
150
|
+
Object.defineProperties(console, {
|
|
151
|
+
log: x({}, e, { value: ie }),
|
|
152
|
+
info: x({}, e, { value: se }),
|
|
153
|
+
warn: x({}, e, { value: ue }),
|
|
154
|
+
error: x({}, e, { value: le }),
|
|
155
|
+
group: x({}, e, { value: fe }),
|
|
156
|
+
groupCollapsed: x({}, e, { value: ce }),
|
|
157
|
+
groupEnd: x({}, e, { value: pe })
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
W < 0 && w("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
|
|
161
|
+
}
|
|
162
|
+
var K = D.ReactCurrentDispatcher, H;
|
|
163
|
+
function Y(e, r, t) {
|
|
164
|
+
if (H === void 0) try {
|
|
165
|
+
throw Error();
|
|
166
|
+
} catch (d) {
|
|
167
|
+
var i = d.stack.trim().match(/\n( *(at )?)/);
|
|
168
|
+
H = i && i[1] || "";
|
|
169
|
+
}
|
|
170
|
+
return `
|
|
171
|
+
` + H + e;
|
|
172
|
+
}
|
|
173
|
+
var J = !1, z = new (typeof WeakMap == "function" ? WeakMap : Map)();
|
|
174
|
+
function de(e, r) {
|
|
175
|
+
if (!e || J) return "";
|
|
176
|
+
var t = z.get(e);
|
|
177
|
+
if (t !== void 0) return t;
|
|
178
|
+
var i;
|
|
179
|
+
J = !0;
|
|
180
|
+
var d = Error.prepareStackTrace;
|
|
181
|
+
Error.prepareStackTrace = void 0;
|
|
182
|
+
var b = K.current;
|
|
183
|
+
K.current = null, Be();
|
|
184
|
+
try {
|
|
185
|
+
if (r) {
|
|
186
|
+
var v = function() {
|
|
187
|
+
throw Error();
|
|
188
|
+
};
|
|
189
|
+
if (Object.defineProperty(v.prototype, "props", { set: function() {
|
|
190
|
+
throw Error();
|
|
191
|
+
} }), typeof Reflect == "object" && Reflect.construct) {
|
|
192
|
+
try {
|
|
193
|
+
Reflect.construct(v, []);
|
|
194
|
+
} catch (S) {
|
|
195
|
+
i = S;
|
|
196
|
+
}
|
|
197
|
+
Reflect.construct(e, [], v);
|
|
198
|
+
} else {
|
|
199
|
+
try {
|
|
200
|
+
v.call();
|
|
201
|
+
} catch (S) {
|
|
202
|
+
i = S;
|
|
203
|
+
}
|
|
204
|
+
e.call(v.prototype);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
try {
|
|
208
|
+
throw Error();
|
|
209
|
+
} catch (S) {
|
|
210
|
+
i = S;
|
|
211
|
+
}
|
|
212
|
+
e();
|
|
213
|
+
}
|
|
214
|
+
} catch (S) {
|
|
215
|
+
if (S && i && typeof S.stack == "string") {
|
|
216
|
+
for (var c = S.stack.split(`
|
|
217
|
+
`), T = i.stack.split(`
|
|
218
|
+
`), _ = c.length - 1, E = T.length - 1; _ >= 1 && E >= 0 && c[_] !== T[E]; ) E--;
|
|
219
|
+
for (; _ >= 1 && E >= 0; _--, E--) if (c[_] !== T[E]) {
|
|
220
|
+
if (_ !== 1 || E !== 1) do
|
|
221
|
+
if (_--, E--, E < 0 || c[_] !== T[E]) {
|
|
222
|
+
var O = `
|
|
223
|
+
` + c[_].replace(" at new ", " at ");
|
|
224
|
+
return e.displayName && O.includes("<anonymous>") && (O = O.replace("<anonymous>", e.displayName)), typeof e == "function" && z.set(e, O), O;
|
|
225
|
+
}
|
|
226
|
+
while (_ >= 1 && E >= 0);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} finally {
|
|
231
|
+
J = !1, K.current = b, Ke(), Error.prepareStackTrace = d;
|
|
232
|
+
}
|
|
233
|
+
var I = e ? e.displayName || e.name : "", A = I ? Y(I) : "";
|
|
234
|
+
return typeof e == "function" && z.set(e, A), A;
|
|
235
|
+
}
|
|
236
|
+
function He(e, r, t) {
|
|
237
|
+
return de(e, !1);
|
|
238
|
+
}
|
|
239
|
+
function Je(e) {
|
|
240
|
+
var r = e.prototype;
|
|
241
|
+
return !!(r && r.isReactComponent);
|
|
242
|
+
}
|
|
243
|
+
function M(e, r, t) {
|
|
244
|
+
if (e == null) return "";
|
|
245
|
+
if (typeof e == "function") return de(e, Je(e));
|
|
246
|
+
if (typeof e == "string") return Y(e);
|
|
247
|
+
switch (e) {
|
|
248
|
+
case R:
|
|
249
|
+
return Y("Suspense");
|
|
250
|
+
case m:
|
|
251
|
+
return Y("SuspenseList");
|
|
252
|
+
}
|
|
253
|
+
if (typeof e == "object") switch (e.$$typeof) {
|
|
254
|
+
case g:
|
|
255
|
+
return He(e.render);
|
|
256
|
+
case h:
|
|
257
|
+
return M(e.type, r, t);
|
|
258
|
+
case P:
|
|
259
|
+
var i = e, d = i._payload, b = i._init;
|
|
260
|
+
try {
|
|
261
|
+
return M(b(d), r, t);
|
|
262
|
+
} catch {
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return "";
|
|
266
|
+
}
|
|
267
|
+
var $ = Object.prototype.hasOwnProperty, ye = {}, he = D.ReactDebugCurrentFrame;
|
|
268
|
+
function V(e) {
|
|
269
|
+
if (e) {
|
|
270
|
+
var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
|
|
271
|
+
he.setExtraStackFrame(t);
|
|
272
|
+
} else he.setExtraStackFrame(null);
|
|
273
|
+
}
|
|
274
|
+
function ze(e, r, t, i, d) {
|
|
275
|
+
var b = Function.call.bind($);
|
|
276
|
+
for (var v in e) if (b(e, v)) {
|
|
277
|
+
var c = void 0;
|
|
278
|
+
try {
|
|
279
|
+
if (typeof e[v] != "function") {
|
|
280
|
+
var T = Error((i || "React class") + ": " + t + " type `" + v + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[v] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
|
|
281
|
+
throw T.name = "Invariant Violation", T;
|
|
282
|
+
}
|
|
283
|
+
c = e[v](r, v, i, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
|
|
284
|
+
} catch (_) {
|
|
285
|
+
c = _;
|
|
286
|
+
}
|
|
287
|
+
c && !(c instanceof Error) && (V(d), w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", i || "React class", t, v, typeof c), V(null)), c instanceof Error && !(c.message in ye) && (ye[c.message] = !0, V(d), w("Failed %s type: %s", t, c.message), V(null));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
var Ge = Array.isArray;
|
|
291
|
+
function G(e) {
|
|
292
|
+
return Ge(e);
|
|
293
|
+
}
|
|
294
|
+
function Qe(e) {
|
|
295
|
+
return typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
296
|
+
}
|
|
297
|
+
function Xe(e) {
|
|
298
|
+
try {
|
|
299
|
+
return ge(e), !1;
|
|
300
|
+
} catch {
|
|
301
|
+
return !0;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function ge(e) {
|
|
305
|
+
return "" + e;
|
|
306
|
+
}
|
|
307
|
+
function me(e) {
|
|
308
|
+
if (Xe(e))
|
|
309
|
+
return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Qe(e)), ge(e);
|
|
310
|
+
}
|
|
311
|
+
var L = D.ReactCurrentOwner, Ze = {
|
|
312
|
+
key: !0,
|
|
313
|
+
ref: !0,
|
|
314
|
+
__self: !0,
|
|
315
|
+
__source: !0
|
|
316
|
+
}, be, _e, Ee = {};
|
|
317
|
+
function er(e) {
|
|
318
|
+
if ($.call(e, "ref")) {
|
|
319
|
+
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
|
|
320
|
+
if (r && r.isReactWarning) return !1;
|
|
321
|
+
}
|
|
322
|
+
return e.ref !== void 0;
|
|
323
|
+
}
|
|
324
|
+
function rr(e) {
|
|
325
|
+
if ($.call(e, "key")) {
|
|
326
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
327
|
+
if (r && r.isReactWarning) return !1;
|
|
328
|
+
}
|
|
329
|
+
return e.key !== void 0;
|
|
330
|
+
}
|
|
331
|
+
function tr(e, r) {
|
|
332
|
+
if (typeof e.ref == "string" && L.current && r && L.current.stateNode !== r) {
|
|
333
|
+
var t = C(L.current.type);
|
|
334
|
+
Ee[t] || (w('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', C(L.current.type), e.ref), Ee[t] = !0);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function nr(e, r) {
|
|
338
|
+
var t = function() {
|
|
339
|
+
be || (be = !0, w("%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://reactjs.org/link/special-props)", r));
|
|
340
|
+
};
|
|
341
|
+
t.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
342
|
+
get: t,
|
|
343
|
+
configurable: !0
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function ar(e, r) {
|
|
347
|
+
var t = function() {
|
|
348
|
+
_e || (_e = !0, w("%s: `ref` 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://reactjs.org/link/special-props)", r));
|
|
349
|
+
};
|
|
350
|
+
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
|
|
351
|
+
get: t,
|
|
352
|
+
configurable: !0
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
var or = function(e, r, t, i, d, b, v) {
|
|
356
|
+
var c = {
|
|
357
|
+
$$typeof: f,
|
|
358
|
+
type: e,
|
|
359
|
+
key: r,
|
|
360
|
+
ref: t,
|
|
361
|
+
props: v,
|
|
362
|
+
_owner: b
|
|
363
|
+
};
|
|
364
|
+
return c._store = {}, Object.defineProperty(c._store, "validated", {
|
|
365
|
+
configurable: !1,
|
|
366
|
+
enumerable: !1,
|
|
367
|
+
writable: !0,
|
|
368
|
+
value: !1
|
|
369
|
+
}), Object.defineProperty(c, "_self", {
|
|
370
|
+
configurable: !1,
|
|
371
|
+
enumerable: !1,
|
|
372
|
+
writable: !1,
|
|
373
|
+
value: i
|
|
374
|
+
}), Object.defineProperty(c, "_source", {
|
|
375
|
+
configurable: !1,
|
|
376
|
+
enumerable: !1,
|
|
377
|
+
writable: !1,
|
|
378
|
+
value: d
|
|
379
|
+
}), Object.freeze && (Object.freeze(c.props), Object.freeze(c)), c;
|
|
380
|
+
};
|
|
381
|
+
function ir(e, r, t, i, d) {
|
|
382
|
+
var b, v = {}, c = null, T = null;
|
|
383
|
+
t !== void 0 && (me(t), c = "" + t), rr(r) && (me(r.key), c = "" + r.key), er(r) && (T = r.ref, tr(r, d));
|
|
384
|
+
for (b in r) $.call(r, b) && !Ze.hasOwnProperty(b) && (v[b] = r[b]);
|
|
385
|
+
if (e && e.defaultProps) {
|
|
386
|
+
var _ = e.defaultProps;
|
|
387
|
+
for (b in _) v[b] === void 0 && (v[b] = _[b]);
|
|
388
|
+
}
|
|
389
|
+
if (c || T) {
|
|
390
|
+
var E = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
|
|
391
|
+
c && nr(v, E), T && ar(v, E);
|
|
392
|
+
}
|
|
393
|
+
return or(e, c, T, d, i, L.current, v);
|
|
394
|
+
}
|
|
395
|
+
var Q = D.ReactCurrentOwner, Re = D.ReactDebugCurrentFrame;
|
|
396
|
+
function F(e) {
|
|
397
|
+
if (e) {
|
|
398
|
+
var r = e._owner, t = M(e.type, e._source, r ? r.type : null);
|
|
399
|
+
Re.setExtraStackFrame(t);
|
|
400
|
+
} else Re.setExtraStackFrame(null);
|
|
401
|
+
}
|
|
402
|
+
var we = !1;
|
|
403
|
+
function X(e) {
|
|
404
|
+
return typeof e == "object" && e !== null && e.$$typeof === f;
|
|
405
|
+
}
|
|
406
|
+
function Te() {
|
|
407
|
+
if (Q.current) {
|
|
408
|
+
var e = C(Q.current.type);
|
|
409
|
+
if (e) return `
|
|
410
|
+
|
|
411
|
+
Check the render method of \`` + e + "`.";
|
|
412
|
+
}
|
|
413
|
+
return "";
|
|
414
|
+
}
|
|
415
|
+
function sr(e) {
|
|
416
|
+
if (e !== void 0) {
|
|
417
|
+
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
|
|
418
|
+
return `
|
|
419
|
+
|
|
420
|
+
Check your code at ` + r + ":" + t + ".";
|
|
421
|
+
}
|
|
422
|
+
return "";
|
|
423
|
+
}
|
|
424
|
+
var Se = {};
|
|
425
|
+
function ur(e) {
|
|
426
|
+
var r = Te();
|
|
427
|
+
if (!r) {
|
|
428
|
+
var t = typeof e == "string" ? e : e.displayName || e.name;
|
|
429
|
+
t && (r = `
|
|
430
|
+
|
|
431
|
+
Check the top-level render call using <` + t + ">.");
|
|
432
|
+
}
|
|
433
|
+
return r;
|
|
434
|
+
}
|
|
435
|
+
function Pe(e, r) {
|
|
436
|
+
if (!(!e._store || e._store.validated || e.key != null)) {
|
|
437
|
+
e._store.validated = !0;
|
|
438
|
+
var t = ur(r);
|
|
439
|
+
if (!Se[t]) {
|
|
440
|
+
Se[t] = !0;
|
|
441
|
+
var i = "";
|
|
442
|
+
e && e._owner && e._owner !== Q.current && (i = " It was passed a child from " + C(e._owner.type) + "."), F(e), w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, i), F(null);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function Oe(e, r) {
|
|
447
|
+
if (typeof e == "object") {
|
|
448
|
+
if (G(e)) for (var t = 0; t < e.length; t++) {
|
|
449
|
+
var i = e[t];
|
|
450
|
+
X(i) && Pe(i, r);
|
|
451
|
+
}
|
|
452
|
+
else if (X(e))
|
|
453
|
+
e._store && (e._store.validated = !0);
|
|
454
|
+
else if (e) {
|
|
455
|
+
var d = Fe(e);
|
|
456
|
+
if (typeof d == "function" && d !== e.entries)
|
|
457
|
+
for (var b = d.call(e), v; !(v = b.next()).done; ) X(v.value) && Pe(v.value, r);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function lr(e) {
|
|
462
|
+
var r = e.type;
|
|
463
|
+
if (!(r == null || typeof r == "string")) {
|
|
464
|
+
var t;
|
|
465
|
+
if (typeof r == "function") t = r.propTypes;
|
|
466
|
+
else if (typeof r == "object" && (r.$$typeof === g || r.$$typeof === h)) t = r.propTypes;
|
|
467
|
+
else return;
|
|
468
|
+
if (t) {
|
|
469
|
+
var i = C(r);
|
|
470
|
+
ze(t, e.props, "prop", i, e);
|
|
471
|
+
} else r.PropTypes !== void 0 && !we && (we = !0, w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", C(r) || "Unknown"));
|
|
472
|
+
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function fr(e) {
|
|
476
|
+
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
|
|
477
|
+
var i = r[t];
|
|
478
|
+
if (i !== "children" && i !== "key") {
|
|
479
|
+
F(e), w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", i), F(null);
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
e.ref !== null && (F(e), w("Invalid attribute `ref` supplied to `React.Fragment`."), F(null));
|
|
484
|
+
}
|
|
485
|
+
var Ce = {};
|
|
486
|
+
function je(e, r, t, i, d, b) {
|
|
487
|
+
var v = Me(e);
|
|
488
|
+
if (!v) {
|
|
489
|
+
var c = "";
|
|
490
|
+
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (c += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
|
|
491
|
+
var T = sr(d);
|
|
492
|
+
T ? c += T : c += Te();
|
|
493
|
+
var _;
|
|
494
|
+
e === null ? _ = "null" : G(e) ? _ = "array" : e !== void 0 && e.$$typeof === f ? (_ = "<" + (C(e.type) || "Unknown") + " />", c = " Did you accidentally export a JSX literal instead of a component?") : _ = typeof e, w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", _, c);
|
|
495
|
+
}
|
|
496
|
+
var E = ir(e, r, t, d, b);
|
|
497
|
+
if (E == null) return E;
|
|
498
|
+
if (v) {
|
|
499
|
+
var O = r.children;
|
|
500
|
+
if (O !== void 0) if (i) if (G(O)) {
|
|
501
|
+
for (var I = 0; I < O.length; I++) Oe(O[I], e);
|
|
502
|
+
Object.freeze && Object.freeze(O);
|
|
503
|
+
} else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
504
|
+
else Oe(O, e);
|
|
505
|
+
}
|
|
506
|
+
if ($.call(r, "key")) {
|
|
507
|
+
var A = C(e), S = Object.keys(r).filter(function(yr) {
|
|
508
|
+
return yr !== "key";
|
|
509
|
+
}), Z = S.length > 0 ? "{key: someKey, " + S.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
510
|
+
Ce[A + Z] || (w(`A props object containing a "key" prop is being spread into JSX:
|
|
511
|
+
let props = %s;
|
|
512
|
+
<%s {...props} />
|
|
513
|
+
React keys must be passed directly to JSX without using spread:
|
|
514
|
+
let props = %s;
|
|
515
|
+
<%s key={someKey} {...props} />`, Z, A, S.length > 0 ? "{" + S.join(": ..., ") + ": ...}" : "{}", A), Ce[A + Z] = !0);
|
|
516
|
+
}
|
|
517
|
+
return e === o ? fr(E) : lr(E), E;
|
|
518
|
+
}
|
|
519
|
+
function cr(e, r, t) {
|
|
520
|
+
return je(e, r, t, !0);
|
|
521
|
+
}
|
|
522
|
+
function pr(e, r, t) {
|
|
523
|
+
return je(e, r, t, !1);
|
|
524
|
+
}
|
|
525
|
+
var vr = pr, dr = cr;
|
|
526
|
+
n.Fragment = o, n.jsx = vr, n.jsxs = dr;
|
|
527
|
+
})();
|
|
528
|
+
})), wr = /* @__PURE__ */ ne(((n, a) => {
|
|
529
|
+
process.env.NODE_ENV === "production" ? a.exports = Er() : a.exports = Rr();
|
|
530
|
+
})), te = wr(), Tr = ({ scrollUp: n, url: a, children: f }) => {
|
|
531
|
+
const s = a || (ke() ? "/" : window.location.href), [o, p] = mr(() => j(s)), u = gr(o), l = U((y, { mode: g = "push" } = {}) => {
|
|
532
|
+
if (!history[g + "State"]) throw new Error(`Invalid mode "${g}"`);
|
|
533
|
+
p((h) => {
|
|
534
|
+
const P = typeof y == "function" ? y(h) : y;
|
|
535
|
+
return q(h) === q(P) ? h : j(P);
|
|
536
|
+
});
|
|
537
|
+
const R = u.current, m = typeof y == "function" ? y(R) : y;
|
|
538
|
+
if (q(R) !== q(m)) {
|
|
539
|
+
const h = j(m);
|
|
540
|
+
u.current = h, history[g + "State"]({}, null, q(h)), n && window.scrollTo(0, 0);
|
|
541
|
+
}
|
|
542
|
+
}, []);
|
|
543
|
+
return re(() => {
|
|
544
|
+
u.current = o;
|
|
545
|
+
}, [o]), re(() => {
|
|
546
|
+
if (ke()) return;
|
|
547
|
+
const y = () => p(j(window.location.href)), g = (R) => {
|
|
548
|
+
const m = R.target, h = _r(m?.closest("a") ?? null);
|
|
549
|
+
if (!h) return !1;
|
|
550
|
+
R.preventDefault();
|
|
551
|
+
const [P, k] = h.split("#");
|
|
552
|
+
P ? l(h) : k && (window.location.hash = "#" + k);
|
|
553
|
+
};
|
|
554
|
+
return window.addEventListener("popstate", y), document.addEventListener("click", g), () => {
|
|
555
|
+
window.removeEventListener("popstate", y), document.removeEventListener("click", g);
|
|
556
|
+
};
|
|
557
|
+
}, [l]), /* @__PURE__ */ (0, te.jsx)(B.Provider, {
|
|
558
|
+
value: [o, l],
|
|
559
|
+
children: f
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
function qe(n, a, f = {}) {
|
|
563
|
+
let s = JSON.parse(JSON.stringify(j(n))), o = JSON.parse(JSON.stringify(j(a)));
|
|
564
|
+
if (o.path = o.path.replace(/\/$/, "") || "/", s.path = s.path.replace(/\/$/, "") || "/", s.path.endsWith("*")) {
|
|
565
|
+
s.path = s.path.replace(/\/?\*/, "") || "/";
|
|
566
|
+
const l = s.path.split("/").filter(Boolean).length;
|
|
567
|
+
o.path = "/" + o.path.slice(1).split("/").slice(0, l).join("/");
|
|
568
|
+
}
|
|
569
|
+
if (Object.entries(s.query).length) {
|
|
570
|
+
for (const l in s.query)
|
|
571
|
+
if (!(l in o.query) || s.query[l] && s.query[l] !== o.query[l]) return !1;
|
|
572
|
+
}
|
|
573
|
+
if (!s.path.includes(":")) return s.path === o.path && f;
|
|
574
|
+
if (s.path.split("/").length !== o.path.split("/").length) return !1;
|
|
575
|
+
const p = {}, u = s.path.split("/").every((l, y) => {
|
|
576
|
+
const g = o.path.split("/")[y];
|
|
577
|
+
if (l.startsWith(":")) {
|
|
578
|
+
let R = l.slice(1), m = "string";
|
|
579
|
+
R.includes("<") && ([R, m] = R.split("<"), m = m.slice(0, -1));
|
|
580
|
+
const h = decodeURIComponent(g);
|
|
581
|
+
return p[R] = m === "number" ? Number(h) : m === "date" ? new Date(/^\d+$/.test(h) ? Number(h) : h) : m === "boolean" ? h === "true" : h, f;
|
|
582
|
+
}
|
|
583
|
+
return g === l;
|
|
584
|
+
});
|
|
585
|
+
return u && Object.assign(f, p), u && f;
|
|
586
|
+
}
|
|
587
|
+
var N = () => {
|
|
588
|
+
const n = xe(B);
|
|
589
|
+
if (!n) throw new Error("Wrap your App with <Router>");
|
|
590
|
+
return n;
|
|
591
|
+
}, jr = ({ path: n = "*", scrollUp: a, component: f, render: s, children: o }) => {
|
|
592
|
+
const p = N(), u = qe(n, p[0]);
|
|
593
|
+
if (!u) return null;
|
|
594
|
+
if (a && window.scrollTo(0, 0), f) o = /* @__PURE__ */ (0, te.jsx)(f, { ...u });
|
|
595
|
+
else if (s) o = s(u);
|
|
596
|
+
else if (!o) throw new Error("Route needs prop `component`, `render` or `children`");
|
|
597
|
+
return /* @__PURE__ */ (0, te.jsx)(B.Provider, {
|
|
598
|
+
value: [{
|
|
599
|
+
...p[0],
|
|
600
|
+
params: u
|
|
601
|
+
}, p[1]],
|
|
602
|
+
children: o
|
|
603
|
+
});
|
|
604
|
+
}, Sr = (n) => (Array.isArray(n) ? n : [n]).filter((a) => a != null && typeof a == "object" && "props" in a), kr = ({ redirect: n, children: a }) => {
|
|
605
|
+
const [f, s] = N(), o = (u) => qe(u.props.path || "*", f), p = Sr(a).find(o) || null;
|
|
606
|
+
return re(() => {
|
|
607
|
+
n && (p || s(q(typeof n == "function" ? n(f) : n)));
|
|
608
|
+
}, [n, p]), p;
|
|
609
|
+
}, xr = () => {
|
|
610
|
+
const [n, a] = N(), s = U((o, p) => {
|
|
611
|
+
a((u) => {
|
|
612
|
+
const l = typeof o == "function" ? o(u.path) : o;
|
|
613
|
+
return {
|
|
614
|
+
...u,
|
|
615
|
+
path: typeof l == "string" ? l : "/"
|
|
616
|
+
};
|
|
617
|
+
}, p);
|
|
618
|
+
}, []);
|
|
619
|
+
return [n.path, s];
|
|
620
|
+
}, ee = (n) => q({ query: n }), Pr = (n) => {
|
|
621
|
+
const [a, f] = N(), s = U((o, p) => {
|
|
622
|
+
f((u) => {
|
|
623
|
+
const l = u.query[n], y = typeof o == "function" ? o(l) : o;
|
|
624
|
+
if (y === l) return u;
|
|
625
|
+
if (y)
|
|
626
|
+
return {
|
|
627
|
+
...u,
|
|
628
|
+
query: {
|
|
629
|
+
...u.query,
|
|
630
|
+
[n]: y
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
{
|
|
634
|
+
const { [n]: g, ...R } = u.query;
|
|
635
|
+
return {
|
|
636
|
+
...u,
|
|
637
|
+
query: R
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}, p);
|
|
641
|
+
}, []);
|
|
642
|
+
return [a.query[n], s];
|
|
643
|
+
}, Or = () => {
|
|
644
|
+
const [n, a] = N(), f = U((s, o) => {
|
|
645
|
+
a((p) => {
|
|
646
|
+
let u = typeof s == "function" ? s(p.query) : s;
|
|
647
|
+
typeof u == "string" && (u = j("/?" + u.replace(/^\?/, "")).query);
|
|
648
|
+
const l = j(ee(u)).query;
|
|
649
|
+
return ee(l) === ee(p.query) ? p : {
|
|
650
|
+
...p,
|
|
651
|
+
query: l
|
|
652
|
+
};
|
|
653
|
+
}, o);
|
|
654
|
+
}, []);
|
|
655
|
+
return [n.query, f];
|
|
656
|
+
};
|
|
657
|
+
function Ar(n) {
|
|
658
|
+
return n ? Pr(n) : Or();
|
|
659
|
+
}
|
|
660
|
+
var qr = () => {
|
|
661
|
+
const [n, a] = N(), s = U((o, p) => {
|
|
662
|
+
a((u) => {
|
|
663
|
+
const l = typeof o == "function" ? o(u.hash) : o, y = typeof l != "string" ? "" : l.replace(/^#/, "");
|
|
664
|
+
return {
|
|
665
|
+
...u,
|
|
666
|
+
hash: y
|
|
667
|
+
};
|
|
668
|
+
}, p);
|
|
669
|
+
}, []);
|
|
670
|
+
return [n.hash, s];
|
|
671
|
+
};
|
|
672
|
+
function Dr(n) {
|
|
673
|
+
const [{ params: a }] = xe(B);
|
|
674
|
+
return n ? n in a ? a[n] : "" : a || {};
|
|
675
|
+
}
|
|
676
|
+
var Fr = Tr;
|
|
677
|
+
export {
|
|
678
|
+
B as Context,
|
|
679
|
+
jr as Route,
|
|
680
|
+
kr as Switch,
|
|
681
|
+
Fr as default,
|
|
682
|
+
qr as useHash,
|
|
683
|
+
Dr as useParams,
|
|
684
|
+
xr as usePath,
|
|
685
|
+
Ar as useQuery,
|
|
686
|
+
N as useUrl
|
|
687
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
type ParseParamType<T extends string> = T extends `${infer Name}<${infer Type}>` ? Type extends "number" ? {
|
|
3
|
+
[K in Name]: number;
|
|
4
|
+
} : Type extends "string" ? {
|
|
5
|
+
[K in Name]: string;
|
|
6
|
+
} : Type extends "date" ? {
|
|
7
|
+
[K in Name]: Date;
|
|
8
|
+
} : Type extends "boolean" ? {
|
|
9
|
+
[K in Name]: boolean;
|
|
10
|
+
} : {
|
|
11
|
+
[K in Name]: string;
|
|
12
|
+
} : {
|
|
13
|
+
[K in T]: string;
|
|
14
|
+
};
|
|
15
|
+
type ExtractParams<T extends string> = T extends `${infer _Prefix}/:${infer Param}/${infer Rest}` ? ParseParamType<Param> & ExtractParams<`/${Rest}`> : T extends `${infer _Prefix}/:${infer Param}` ? ParseParamType<Param> : {};
|
|
16
|
+
type InferParamsFromPath<T extends string> = T extends `${string}/:${string}` ? ExtractParams<T> : {};
|
|
17
|
+
interface RoutePropsBase {
|
|
18
|
+
path?: string;
|
|
19
|
+
scrollUp?: boolean;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
type RouteProps<T extends Record<string, string | number | boolean | Date> = {}> = RoutePropsBase & ({
|
|
23
|
+
component: React.FunctionComponent<T>;
|
|
24
|
+
render?: never;
|
|
25
|
+
} | {
|
|
26
|
+
render: (params: T) => React.ReactNode;
|
|
27
|
+
component?: never;
|
|
28
|
+
} | {
|
|
29
|
+
component?: never;
|
|
30
|
+
render?: never;
|
|
31
|
+
});
|
|
32
|
+
type RouteType = <P extends string = string>(props: RouteProps<InferParamsFromPath<P>> & {
|
|
33
|
+
path?: P;
|
|
34
|
+
}) => React.ReactNode;
|
|
35
|
+
declare const _default: RouteType;
|
|
36
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
interface RouterProps {
|
|
3
|
+
scrollUp?: boolean;
|
|
4
|
+
url?: string;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: ({ scrollUp, url: baseUrl, children }: RouterProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Url } from './types';
|
|
3
|
+
interface SwitchProps {
|
|
4
|
+
redirect?: string | {
|
|
5
|
+
path: string;
|
|
6
|
+
} | ((url: Url) => string);
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: ({ redirect, children }: SwitchProps) => ReactElement | null;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Query, SetUrlOptions } from '../types';
|
|
2
|
+
type QueryValue = string | string[] | undefined;
|
|
3
|
+
type SetQueryProp = (value: string | ((prev: QueryValue) => string), opts?: SetUrlOptions) => void;
|
|
4
|
+
type QueryUpdater = (query: Query) => Query | string;
|
|
5
|
+
type SetQuery = (newQuery: Query | string | QueryUpdater, opts?: SetUrlOptions) => void;
|
|
6
|
+
declare function useQuery(key: string): [QueryValue, SetQueryProp];
|
|
7
|
+
declare function useQuery(): [Query, SetQuery];
|
|
8
|
+
export default useQuery;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as Router } from './Router';
|
|
2
|
+
import { default as Route } from './Route';
|
|
3
|
+
import { default as Switch } from './Switch';
|
|
4
|
+
import { default as Context } from './Context';
|
|
5
|
+
import { default as useUrl } from './hooks/useUrl';
|
|
6
|
+
import { default as usePath } from './hooks/usePath';
|
|
7
|
+
import { default as useQuery } from './hooks/useQuery';
|
|
8
|
+
import { default as useHash } from './hooks/useHash';
|
|
9
|
+
import { default as useParams } from './hooks/useParams';
|
|
10
|
+
export default Router;
|
|
11
|
+
export { Route, Switch, useUrl, usePath, useQuery, useHash, useParams, Context };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Query = Record<string, string | string[]>;
|
|
2
|
+
export type Url = {
|
|
3
|
+
path: string;
|
|
4
|
+
query: Query;
|
|
5
|
+
hash?: string;
|
|
6
|
+
params?: Params;
|
|
7
|
+
};
|
|
8
|
+
export type UrlSet = {
|
|
9
|
+
path?: string;
|
|
10
|
+
query?: Query;
|
|
11
|
+
hash?: string;
|
|
12
|
+
};
|
|
13
|
+
export type Params = Record<string, string | number | boolean | Date>;
|
|
14
|
+
export type SetUrlOptions = {
|
|
15
|
+
mode?: "push" | "replace";
|
|
16
|
+
};
|
|
17
|
+
export type NewUrlValue = Url | UrlSet | string;
|
|
18
|
+
export type SetUrl = (newUrl: NewUrlValue | ((prev: Url) => NewUrlValue), opts?: SetUrlOptions) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crossroad",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "A React library to handle navigation easily in your WebApp",
|
|
5
5
|
"homepage": "https://crossroad.page/",
|
|
6
6
|
"repository": "github:franciscop/crossroad",
|
|
@@ -24,48 +24,33 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "
|
|
27
|
+
"build": "vite build",
|
|
28
28
|
"lint": "tsc",
|
|
29
|
-
"size": "echo $(gzip -c index.min.js | wc -c) bytes",
|
|
30
|
-
"start": "
|
|
31
|
-
"test": "
|
|
29
|
+
"size": "echo $(gzip -c dist/index.min.js | wc -c) bytes",
|
|
30
|
+
"start": "vitest",
|
|
31
|
+
"test": "vitest run --coverage"
|
|
32
32
|
},
|
|
33
|
-
"main": "index.min.js",
|
|
33
|
+
"main": "dist/index.min.js",
|
|
34
34
|
"type": "module",
|
|
35
|
-
"types": "index.d.ts",
|
|
35
|
+
"types": "dist/src/index.d.ts",
|
|
36
36
|
"files": [
|
|
37
|
-
"
|
|
37
|
+
"dist"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@babel/core": "^7.29.0",
|
|
41
|
-
"@babel/preset-env": "^7.29.2",
|
|
42
|
-
"@babel/preset-react": "^7.28.5",
|
|
43
|
-
"@babel/preset-typescript": "^7.28.5",
|
|
44
|
-
"@rollup/plugin-babel": "^6.0.0",
|
|
45
|
-
"@rollup/plugin-terser": "^1.0.0",
|
|
46
|
-
"@types/jest": "^30.0.0",
|
|
47
40
|
"@types/node": "^25.5.2",
|
|
48
41
|
"@types/react": "^18.3.4",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
42
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
43
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
44
|
+
"jsdom": "^26.1.0",
|
|
51
45
|
"react": "^18.3.1",
|
|
52
46
|
"react-dom": "^18.3.1",
|
|
53
|
-
"react-test": "^0.23.
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
47
|
+
"react-test": "^0.23.3",
|
|
48
|
+
"typescript": "^6.0.2",
|
|
49
|
+
"vite": "^8.0.3",
|
|
50
|
+
"vite-plugin-dts": "^4.5.4",
|
|
51
|
+
"vitest": "^3.2.4"
|
|
57
52
|
},
|
|
58
53
|
"peerDependencies": {
|
|
59
54
|
"react": ">=16.8.0"
|
|
60
|
-
},
|
|
61
|
-
"babel": {
|
|
62
|
-
"presets": [
|
|
63
|
-
"@babel/preset-env",
|
|
64
|
-
"@babel/preset-react",
|
|
65
|
-
"@babel/preset-typescript"
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
"jest": {
|
|
69
|
-
"testEnvironment": "jsdom"
|
|
70
55
|
}
|
|
71
56
|
}
|
package/index.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import React__default, { ReactNode, ReactElement } from 'react';
|
|
3
|
-
|
|
4
|
-
interface RouterProps {
|
|
5
|
-
scrollUp?: boolean;
|
|
6
|
-
url?: string;
|
|
7
|
-
children?: React__default.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
declare const _default$6: ({ scrollUp, url: baseUrl, children }: RouterProps) => React__default.JSX.Element;
|
|
10
|
-
|
|
11
|
-
type ParseParamType<T extends string> = T extends `${infer Name}<${infer Type}>` ? Type extends "number" ? {
|
|
12
|
-
[K in Name]: number;
|
|
13
|
-
} : Type extends "string" ? {
|
|
14
|
-
[K in Name]: string;
|
|
15
|
-
} : Type extends "date" ? {
|
|
16
|
-
[K in Name]: Date;
|
|
17
|
-
} : Type extends "boolean" ? {
|
|
18
|
-
[K in Name]: boolean;
|
|
19
|
-
} : {
|
|
20
|
-
[K in Name]: string;
|
|
21
|
-
} : {
|
|
22
|
-
[K in T]: string;
|
|
23
|
-
};
|
|
24
|
-
type ExtractParams<T extends string> = T extends `${infer _Prefix}/:${infer Param}/${infer Rest}` ? ParseParamType<Param> & ExtractParams<`/${Rest}`> : T extends `${infer _Prefix}/:${infer Param}` ? ParseParamType<Param> : {};
|
|
25
|
-
type InferParamsFromPath<T extends string> = T extends `${string}/:${string}` ? ExtractParams<T> : {};
|
|
26
|
-
interface RoutePropsBase {
|
|
27
|
-
path?: string;
|
|
28
|
-
scrollUp?: boolean;
|
|
29
|
-
children?: React__default.ReactNode;
|
|
30
|
-
}
|
|
31
|
-
type RouteProps<T extends Record<string, string | number | boolean | Date> = {}> = RoutePropsBase & ({
|
|
32
|
-
component: React__default.FunctionComponent<T>;
|
|
33
|
-
render?: never;
|
|
34
|
-
} | {
|
|
35
|
-
render: (params: T) => React__default.ReactNode;
|
|
36
|
-
component?: never;
|
|
37
|
-
} | {
|
|
38
|
-
component?: never;
|
|
39
|
-
render?: never;
|
|
40
|
-
});
|
|
41
|
-
type RouteType = <P extends string = string>(props: RouteProps<InferParamsFromPath<P>> & {
|
|
42
|
-
path?: P;
|
|
43
|
-
}) => React__default.ReactNode;
|
|
44
|
-
declare const _default$5: RouteType;
|
|
45
|
-
|
|
46
|
-
type Query = Record<string, string | string[]>;
|
|
47
|
-
type Url = {
|
|
48
|
-
path: string;
|
|
49
|
-
query: Query;
|
|
50
|
-
hash?: string;
|
|
51
|
-
params?: Params;
|
|
52
|
-
};
|
|
53
|
-
type UrlSet = {
|
|
54
|
-
path?: string;
|
|
55
|
-
query?: Query;
|
|
56
|
-
hash?: string;
|
|
57
|
-
};
|
|
58
|
-
type Params = Record<string, string | number | boolean | Date>;
|
|
59
|
-
type SetUrlOptions = {
|
|
60
|
-
mode?: "push" | "replace";
|
|
61
|
-
};
|
|
62
|
-
type NewUrlValue = Url | UrlSet | string;
|
|
63
|
-
type SetUrl = (newUrl: NewUrlValue | ((prev: Url) => NewUrlValue), opts?: SetUrlOptions) => void;
|
|
64
|
-
|
|
65
|
-
interface SwitchProps {
|
|
66
|
-
redirect?: string | {
|
|
67
|
-
path: string;
|
|
68
|
-
} | ((url: Url) => string);
|
|
69
|
-
children?: ReactNode;
|
|
70
|
-
}
|
|
71
|
-
declare const _default$4: ({ redirect, children }: SwitchProps) => ReactElement | null;
|
|
72
|
-
|
|
73
|
-
declare const _default$3: React.Context<[Url, SetUrl] | undefined>;
|
|
74
|
-
|
|
75
|
-
declare const _default$2: () => [Url, SetUrl];
|
|
76
|
-
|
|
77
|
-
type PathUpdater = (path: string) => string;
|
|
78
|
-
type SetPath = (path: string | PathUpdater, opts?: SetUrlOptions) => void;
|
|
79
|
-
declare const _default$1: () => [string, SetPath];
|
|
80
|
-
|
|
81
|
-
type QueryValue = string | string[] | undefined;
|
|
82
|
-
type SetQueryProp = (value: string | ((prev: QueryValue) => string), opts?: SetUrlOptions) => void;
|
|
83
|
-
type QueryUpdater = (query: Query) => Query | string;
|
|
84
|
-
type SetQuery = (newQuery: Query | string | QueryUpdater, opts?: SetUrlOptions) => void;
|
|
85
|
-
declare function useQuery(key: string): [QueryValue, SetQueryProp];
|
|
86
|
-
declare function useQuery(): [Query, SetQuery];
|
|
87
|
-
|
|
88
|
-
type HashUpdater = (hash: string | undefined) => string;
|
|
89
|
-
type SetHash = (hash: string | HashUpdater, opts?: SetUrlOptions) => void;
|
|
90
|
-
declare const _default: () => [string | undefined, SetHash];
|
|
91
|
-
|
|
92
|
-
declare function useParams(): Params;
|
|
93
|
-
declare function useParams<T = string | number | boolean | Date>(key: string): T;
|
|
94
|
-
|
|
95
|
-
export { _default$3 as Context, _default$5 as Route, _default$4 as Switch, _default$6 as default, _default as useHash, useParams, _default$1 as usePath, useQuery, _default$2 as useUrl };
|
package/index.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t,{createContext as e,useState as r,useRef as n,useCallback as o,useEffect as i,useContext as s}from"react";var a=e(void 0);const u=t=>t.length>1?t:t[0],c=t=>{if("string"!=typeof t)return t;const e={query:{}},r=new URL(t,"http://localhost:3000/");e.path=(r.pathname.replace(/\/$/,"")||"/").replaceAll("%3C","<").replaceAll("%3E",">"),e.query={};for(const[t]of r.searchParams)e.query[t]=u(r.searchParams.getAll(t));return r.hash&&(e.hash=r.hash.replace(/^#/,"")),e},l=t=>{if("string"==typeof t)return t;const{path:e,query:r={},hash:n}=t||{};let o=e||"/";const i=new URLSearchParams(Object.entries(r).map(([t,e])=>(Array.isArray(e)?e:[e]).map(e=>[t,e])).flat().filter(([t,e])=>e)).toString();return i&&(o+="?"+i),n&&(o+="#"+n),o};var p=()=>"undefined"==typeof window,h=({scrollUp:e,url:s,children:u})=>{const h=s||(p()?"/":window.location.href),[f,y]=r(()=>c(h)),d=n(f),m=o((t,{mode:r="push"}={})=>{if(!history[r+"State"])throw new Error(`Invalid mode "${r}"`);y(e=>{const r="function"==typeof t?t(e):t;return l(e)===l(r)?e:c(r)});const n=d.current,o="function"==typeof t?t(n):t;if(l(n)!==l(o)){const t=c(o);d.current=t,history[r+"State"]({},null,l(t)),e&&window.scrollTo(0,0)}},[]);return i(()=>{d.current=f},[f]),i(()=>{if(p())return;const t=()=>y(c(window.location.href)),e=t=>{const e=t.target,r=(t=>{if(!t)return null;const e=t.getAttribute("href");if(!e)return null;const r=e.trim();return/^[a-zA-Z][a-zA-Z0-9+\-.]*:/.test(r)||null!==t.getAttribute("target")?null:r})(e?.closest("a")??null);if(!r)return!1;t.preventDefault();const[n,o]=r.split("#");n?m(r):o&&(window.location.hash="#"+o)};return window.addEventListener("popstate",t),document.addEventListener("click",e),()=>{window.removeEventListener("popstate",t),document.removeEventListener("click",e)}},[m]),t.createElement(a.Provider,{value:[f,m]},u)};function f(t,e,r={}){let n=JSON.parse(JSON.stringify(c(t))),o=JSON.parse(JSON.stringify(c(e)));if(o.path=o.path.replace(/\/$/,"")||"/",n.path=n.path.replace(/\/$/,"")||"/",n.path.endsWith("*")){n.path=n.path.replace(/\/?\*/,"")||"/";const t=n.path.split("/").filter(Boolean).length;o.path="/"+o.path.slice(1).split("/").slice(0,t).join("/")}if(Object.entries(n.query).length)for(const t in n.query){if(!(t in o.query))return!1;if(n.query[t]&&n.query[t]!==o.query[t])return!1}if(!n.path.includes(":"))return n.path===o.path&&r;if(n.path.split("/").length!==o.path.split("/").length)return!1;const i={},s=n.path.split("/").every((t,e)=>{const n=o.path.split("/")[e];if(t.startsWith(":")){let e=t.slice(1),o="string";e.includes("<")&&([e,o]=e.split("<"),o=o.slice(0,-1));const s=decodeURIComponent(n);return i[e]="number"===o?Number(s):"date"===o?new Date(/^\d+$/.test(s)?Number(s):s):"boolean"===o?"true"===s:s,r}return n===t});return s&&Object.assign(r,i),s&&r}var y=()=>{const t=s(a);if(!t)throw new Error("Wrap your App with <Router>");return t};const d=({path:e="*",scrollUp:r,component:n,render:o,children:i})=>{const s=y(),u=f(e,s[0]);if(!u)return null;if(r&&window.scrollTo(0,0),n){const e=n;i=t.createElement(e,u)}else if(o)i=o(u);else if(!i)throw new Error("Route needs prop `component`, `render` or `children`");return t.createElement(a.Provider,{value:[{...s[0],params:u},s[1]]},i)};var m=({redirect:t,children:e})=>{const[r,n]=y(),o=(t=>(Array.isArray(t)?t:[t]).filter(t=>null!=t&&"object"==typeof t&&"props"in t))(e).find(t=>f(t.props.path||"*",r))||null;return i(()=>{if(!t)return;if(o)return;const e="function"==typeof t?t(r):t;n(l(e))},[t,o]),o},w=()=>{const[t,e]=y(),r=o((t,r)=>{e(e=>{const r="function"==typeof t?t(e.path):t;return{...e,path:"string"==typeof r?r:"/"}},r)},[]);return[t.path,r]};const q=t=>l({query:t});function g(t){return t?(t=>{const[e,r]=y(),n=o((e,n)=>{r(r=>{const n=r.query[t],o="function"==typeof e?e(n):e;if(o===n)return r;if(o)return{...r,query:{...r.query,[t]:o}};{const{[t]:e,...n}=r.query;return{...r,query:n}}},n)},[]);return[e.query[t],n]})(t):(()=>{const[t,e]=y(),r=o((t,r)=>{e(e=>{let r="function"==typeof t?t(e.query):t;"string"==typeof r&&(r=c("/?"+r.replace(/^\?/,"")).query);const n=c(q(r)).query;return q(n)===q(e.query)?e:{...e,query:n}},r)},[]);return[t.query,r]})()}var v=()=>{const[t,e]=y(),r=o((t,r)=>{e(e=>{const r="function"==typeof t?t(e.hash):t,n="string"!=typeof r?"":r.replace(/^#/,"");return{...e,hash:n}},r)},[]);return[t.hash,r]};function A(t){const[{params:e}]=s(a);return t?t in e?e[t]:"":e||{}}export{a as Context,d as Route,m as Switch,h as default,v as useHash,A as useParams,w as usePath,g as useQuery,y as useUrl};
|