gemi 0.1.1 → 0.2.0
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/ApiRouter.d.ts +5 -0
- package/dist/ApiRouter.d.ts.map +1 -0
- package/dist/Controller.d.ts +3 -0
- package/dist/Controller.d.ts.map +1 -0
- package/dist/ViewRouter.d.ts +3 -0
- package/dist/ViewRouter.d.ts.map +1 -0
- package/dist/app/App.d.ts +93 -0
- package/dist/app/App.d.ts.map +1 -0
- package/dist/app/Plugin.d.ts +10 -0
- package/dist/app/Plugin.d.ts.map +1 -0
- package/dist/app/index.js +1697 -0
- package/dist/bin/gemi +0 -0
- package/dist/client/ClientRouter.d.ts +4 -0
- package/dist/client/ClientRouter.d.ts.map +1 -0
- package/dist/client/ClientRouterContext.d.ts +32 -0
- package/dist/client/ClientRouterContext.d.ts.map +1 -0
- package/dist/client/Form.d.ts +27 -3
- package/dist/client/Form.d.ts.map +1 -1
- package/dist/client/Image.d.ts +11 -0
- package/dist/client/Image.d.ts.map +1 -0
- package/dist/client/Mutation.d.ts +17 -0
- package/dist/client/Mutation.d.ts.map +1 -0
- package/dist/client/Root.d.ts +2 -0
- package/dist/client/Root.d.ts.map +1 -0
- package/dist/client/ServerDataProvider.d.ts +33 -0
- package/dist/client/ServerDataProvider.d.ts.map +1 -0
- package/dist/client/index.d.ts +7 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1641 -0
- package/dist/client/main.d.ts +2 -0
- package/dist/client/main.d.ts.map +1 -0
- package/dist/client/types.d.ts +4 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/useMutation.d.ts +8 -0
- package/dist/client/useMutation.d.ts.map +1 -0
- package/dist/client/useQuery.d.ts +6 -0
- package/dist/client/useQuery.d.ts.map +1 -0
- package/dist/client/useUser.d.ts +2 -0
- package/dist/client/useUser.d.ts.map +1 -0
- package/dist/email/index.js +9098 -0
- package/dist/facades/index.js +71 -0
- package/dist/http/ApiRouter.d.ts +50 -0
- package/dist/http/ApiRouter.d.ts.map +1 -1
- package/dist/http/Controller.d.ts +2 -0
- package/dist/http/Controller.d.ts.map +1 -1
- package/dist/http/Error.d.ts +7 -0
- package/dist/http/Error.d.ts.map +1 -0
- package/dist/http/HttpRequest.d.ts +21 -0
- package/dist/http/HttpRequest.d.ts.map +1 -0
- package/dist/http/Middleware.d.ts +4 -0
- package/dist/http/Middleware.d.ts.map +1 -0
- package/dist/http/Router.d.ts +31 -0
- package/dist/http/Router.d.ts.map +1 -0
- package/dist/http/ViewRouter.d.ts +30 -0
- package/dist/http/ViewRouter.d.ts.map +1 -1
- package/dist/http/getCookies.d.ts +2 -0
- package/dist/http/getCookies.d.ts.map +1 -0
- package/dist/http/index.d.ts +4 -0
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +341 -0
- package/dist/http/requestContext.d.ts +4 -0
- package/dist/http/requestContext.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/server/generateEtag.d.ts +2 -0
- package/dist/server/generateEtag.d.ts.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/Subject.d.ts +9 -0
- package/dist/utils/Subject.d.ts.map +1 -0
- package/dist/utils/type.d.ts +2 -0
- package/dist/utils/type.d.ts.map +1 -0
- package/package.json +21 -8
- package/dist/client/index.mjs +0 -3174
- package/dist/client/useRouter.d.ts +0 -2
- package/dist/client/useRouter.d.ts.map +0 -1
- package/dist/fsevents-X6WP4TKM.node +0 -0
- package/dist/http/index.mjs +0 -16
- package/dist/server/Server.d.ts +0 -10
- package/dist/server/Server.d.ts.map +0 -1
- package/dist/server/dev.d.ts +0 -3
- package/dist/server/dev.d.ts.map +0 -1
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.mjs +0 -16315
|
@@ -0,0 +1,1641 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
var __accessCheck = (obj, member, msg) => {
|
|
8
|
+
if (!member.has(obj))
|
|
9
|
+
throw TypeError("Cannot " + msg);
|
|
10
|
+
};
|
|
11
|
+
var __privateGet = (obj, member, getter) => {
|
|
12
|
+
__accessCheck(obj, member, "read from private field");
|
|
13
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
14
|
+
};
|
|
15
|
+
var __privateAdd = (obj, member, value) => {
|
|
16
|
+
if (member.has(obj))
|
|
17
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
18
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
+
};
|
|
20
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
21
|
+
__accessCheck(obj, member, "write to private field");
|
|
22
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
var __privateMethod = (obj, member, method) => {
|
|
26
|
+
__accessCheck(obj, member, "access private method");
|
|
27
|
+
return method;
|
|
28
|
+
};
|
|
29
|
+
var _i, _n, _t, _e, _s, _l, _o, _d, _p, _g, _r, r_fn, _R, R_fn, _b, b_fn, _u, u_fn, _m, m_fn, _a, a_fn, _P, P_fn, _E, E_fn, _S, S_fn, _O, O_fn, _k, k_fn, _x, x_fn, _h, h_fn, _f, f_fn, _T, T_fn, _A, A_fn, _y, y_fn, _w, w_fn, _c, c_fn, _C, C_fn, _a2, _i2, _n2, _t2, _e2, _s2, _l2, _b2;
|
|
30
|
+
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
31
|
+
import { createContext, useContext, useState, startTransition, useEffect, useRef, lazy, Suspense } from "react";
|
|
32
|
+
const ServerDataContext = createContext({});
|
|
33
|
+
const ServerDataProvider = (props) => {
|
|
34
|
+
let _value = props.value;
|
|
35
|
+
if (props.value) {
|
|
36
|
+
_value = props.value;
|
|
37
|
+
} else {
|
|
38
|
+
_value = window.__GEMI_DATA__;
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ jsx(ServerDataContext.Provider, { value: _value, children: props.children });
|
|
41
|
+
};
|
|
42
|
+
function _extends() {
|
|
43
|
+
return _extends = Object.assign ? Object.assign.bind() : function(n) {
|
|
44
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
45
|
+
var t = arguments[e];
|
|
46
|
+
for (var r in t)
|
|
47
|
+
({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
48
|
+
}
|
|
49
|
+
return n;
|
|
50
|
+
}, _extends.apply(null, arguments);
|
|
51
|
+
}
|
|
52
|
+
var Action;
|
|
53
|
+
(function(Action2) {
|
|
54
|
+
Action2["Pop"] = "POP";
|
|
55
|
+
Action2["Push"] = "PUSH";
|
|
56
|
+
Action2["Replace"] = "REPLACE";
|
|
57
|
+
})(Action || (Action = {}));
|
|
58
|
+
var readOnly = process.env.NODE_ENV !== "production" ? function(obj) {
|
|
59
|
+
return Object.freeze(obj);
|
|
60
|
+
} : function(obj) {
|
|
61
|
+
return obj;
|
|
62
|
+
};
|
|
63
|
+
function warning(cond, message) {
|
|
64
|
+
{
|
|
65
|
+
if (typeof console !== "undefined")
|
|
66
|
+
console.warn(message);
|
|
67
|
+
try {
|
|
68
|
+
throw new Error(message);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
var BeforeUnloadEventType = "beforeunload";
|
|
74
|
+
var PopStateEventType = "popstate";
|
|
75
|
+
function createBrowserHistory(options) {
|
|
76
|
+
if (options === void 0) {
|
|
77
|
+
options = {};
|
|
78
|
+
}
|
|
79
|
+
var _options = options, _options$window = _options.window, window2 = _options$window === void 0 ? document.defaultView : _options$window;
|
|
80
|
+
var globalHistory = window2.history;
|
|
81
|
+
function getIndexAndLocation() {
|
|
82
|
+
var _window$location = window2.location, pathname = _window$location.pathname, search = _window$location.search, hash = _window$location.hash;
|
|
83
|
+
var state = globalHistory.state || {};
|
|
84
|
+
return [state.idx, readOnly({
|
|
85
|
+
pathname,
|
|
86
|
+
search,
|
|
87
|
+
hash,
|
|
88
|
+
state: state.usr || null,
|
|
89
|
+
key: state.key || "default"
|
|
90
|
+
})];
|
|
91
|
+
}
|
|
92
|
+
var blockedPopTx = null;
|
|
93
|
+
function handlePop() {
|
|
94
|
+
if (blockedPopTx) {
|
|
95
|
+
blockers.call(blockedPopTx);
|
|
96
|
+
blockedPopTx = null;
|
|
97
|
+
} else {
|
|
98
|
+
var nextAction = Action.Pop;
|
|
99
|
+
var _getIndexAndLocation = getIndexAndLocation(), nextIndex = _getIndexAndLocation[0], nextLocation = _getIndexAndLocation[1];
|
|
100
|
+
if (blockers.length) {
|
|
101
|
+
if (nextIndex != null) {
|
|
102
|
+
var delta = index - nextIndex;
|
|
103
|
+
if (delta) {
|
|
104
|
+
blockedPopTx = {
|
|
105
|
+
action: nextAction,
|
|
106
|
+
location: nextLocation,
|
|
107
|
+
retry: function retry() {
|
|
108
|
+
go(delta * -1);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
go(delta);
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
process.env.NODE_ENV !== "production" ? warning(
|
|
115
|
+
false,
|
|
116
|
+
// TODO: Write up a doc that explains our blocking strategy in
|
|
117
|
+
// detail and link to it here so people can understand better what
|
|
118
|
+
// is going on and how to avoid it.
|
|
119
|
+
"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
|
|
120
|
+
) : void 0;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
applyTx(nextAction);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
window2.addEventListener(PopStateEventType, handlePop);
|
|
128
|
+
var action = Action.Pop;
|
|
129
|
+
var _getIndexAndLocation2 = getIndexAndLocation(), index = _getIndexAndLocation2[0], location = _getIndexAndLocation2[1];
|
|
130
|
+
var listeners = createEvents();
|
|
131
|
+
var blockers = createEvents();
|
|
132
|
+
if (index == null) {
|
|
133
|
+
index = 0;
|
|
134
|
+
globalHistory.replaceState(_extends({}, globalHistory.state, {
|
|
135
|
+
idx: index
|
|
136
|
+
}), "");
|
|
137
|
+
}
|
|
138
|
+
function createHref(to) {
|
|
139
|
+
return typeof to === "string" ? to : createPath(to);
|
|
140
|
+
}
|
|
141
|
+
function getNextLocation(to, state) {
|
|
142
|
+
if (state === void 0) {
|
|
143
|
+
state = null;
|
|
144
|
+
}
|
|
145
|
+
return readOnly(_extends({
|
|
146
|
+
pathname: location.pathname,
|
|
147
|
+
hash: "",
|
|
148
|
+
search: ""
|
|
149
|
+
}, typeof to === "string" ? parsePath(to) : to, {
|
|
150
|
+
state,
|
|
151
|
+
key: createKey()
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
function getHistoryStateAndUrl(nextLocation, index2) {
|
|
155
|
+
return [{
|
|
156
|
+
usr: nextLocation.state,
|
|
157
|
+
key: nextLocation.key,
|
|
158
|
+
idx: index2
|
|
159
|
+
}, createHref(nextLocation)];
|
|
160
|
+
}
|
|
161
|
+
function allowTx(action2, location2, retry) {
|
|
162
|
+
return !blockers.length || (blockers.call({
|
|
163
|
+
action: action2,
|
|
164
|
+
location: location2,
|
|
165
|
+
retry
|
|
166
|
+
}), false);
|
|
167
|
+
}
|
|
168
|
+
function applyTx(nextAction) {
|
|
169
|
+
action = nextAction;
|
|
170
|
+
var _getIndexAndLocation3 = getIndexAndLocation();
|
|
171
|
+
index = _getIndexAndLocation3[0];
|
|
172
|
+
location = _getIndexAndLocation3[1];
|
|
173
|
+
listeners.call({
|
|
174
|
+
action,
|
|
175
|
+
location
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function push(to, state) {
|
|
179
|
+
var nextAction = Action.Push;
|
|
180
|
+
var nextLocation = getNextLocation(to, state);
|
|
181
|
+
function retry() {
|
|
182
|
+
push(to, state);
|
|
183
|
+
}
|
|
184
|
+
if (allowTx(nextAction, nextLocation, retry)) {
|
|
185
|
+
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1), historyState = _getHistoryStateAndUr[0], url = _getHistoryStateAndUr[1];
|
|
186
|
+
try {
|
|
187
|
+
globalHistory.pushState(historyState, "", url);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
window2.location.assign(url);
|
|
190
|
+
}
|
|
191
|
+
applyTx(nextAction);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function replace(to, state) {
|
|
195
|
+
var nextAction = Action.Replace;
|
|
196
|
+
var nextLocation = getNextLocation(to, state);
|
|
197
|
+
function retry() {
|
|
198
|
+
replace(to, state);
|
|
199
|
+
}
|
|
200
|
+
if (allowTx(nextAction, nextLocation, retry)) {
|
|
201
|
+
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index), historyState = _getHistoryStateAndUr2[0], url = _getHistoryStateAndUr2[1];
|
|
202
|
+
globalHistory.replaceState(historyState, "", url);
|
|
203
|
+
applyTx(nextAction);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function go(delta) {
|
|
207
|
+
globalHistory.go(delta);
|
|
208
|
+
}
|
|
209
|
+
var history = {
|
|
210
|
+
get action() {
|
|
211
|
+
return action;
|
|
212
|
+
},
|
|
213
|
+
get location() {
|
|
214
|
+
return location;
|
|
215
|
+
},
|
|
216
|
+
createHref,
|
|
217
|
+
push,
|
|
218
|
+
replace,
|
|
219
|
+
go,
|
|
220
|
+
back: function back() {
|
|
221
|
+
go(-1);
|
|
222
|
+
},
|
|
223
|
+
forward: function forward() {
|
|
224
|
+
go(1);
|
|
225
|
+
},
|
|
226
|
+
listen: function listen(listener) {
|
|
227
|
+
return listeners.push(listener);
|
|
228
|
+
},
|
|
229
|
+
block: function block(blocker) {
|
|
230
|
+
var unblock = blockers.push(blocker);
|
|
231
|
+
if (blockers.length === 1) {
|
|
232
|
+
window2.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
233
|
+
}
|
|
234
|
+
return function() {
|
|
235
|
+
unblock();
|
|
236
|
+
if (!blockers.length) {
|
|
237
|
+
window2.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
return history;
|
|
243
|
+
}
|
|
244
|
+
function promptBeforeUnload(event) {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
event.returnValue = "";
|
|
247
|
+
}
|
|
248
|
+
function createEvents() {
|
|
249
|
+
var handlers = [];
|
|
250
|
+
return {
|
|
251
|
+
get length() {
|
|
252
|
+
return handlers.length;
|
|
253
|
+
},
|
|
254
|
+
push: function push(fn) {
|
|
255
|
+
handlers.push(fn);
|
|
256
|
+
return function() {
|
|
257
|
+
handlers = handlers.filter(function(handler) {
|
|
258
|
+
return handler !== fn;
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
call: function call(arg) {
|
|
263
|
+
handlers.forEach(function(fn) {
|
|
264
|
+
return fn && fn(arg);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function createKey() {
|
|
270
|
+
return Math.random().toString(36).substr(2, 8);
|
|
271
|
+
}
|
|
272
|
+
function createPath(_ref) {
|
|
273
|
+
var _ref$pathname = _ref.pathname, pathname = _ref$pathname === void 0 ? "/" : _ref$pathname, _ref$search = _ref.search, search = _ref$search === void 0 ? "" : _ref$search, _ref$hash = _ref.hash, hash = _ref$hash === void 0 ? "" : _ref$hash;
|
|
274
|
+
if (search && search !== "?")
|
|
275
|
+
pathname += search.charAt(0) === "?" ? search : "?" + search;
|
|
276
|
+
if (hash && hash !== "#")
|
|
277
|
+
pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
|
278
|
+
return pathname;
|
|
279
|
+
}
|
|
280
|
+
function parsePath(path) {
|
|
281
|
+
var parsedPath = {};
|
|
282
|
+
if (path) {
|
|
283
|
+
var hashIndex = path.indexOf("#");
|
|
284
|
+
if (hashIndex >= 0) {
|
|
285
|
+
parsedPath.hash = path.substr(hashIndex);
|
|
286
|
+
path = path.substr(0, hashIndex);
|
|
287
|
+
}
|
|
288
|
+
var searchIndex = path.indexOf("?");
|
|
289
|
+
if (searchIndex >= 0) {
|
|
290
|
+
parsedPath.search = path.substr(searchIndex);
|
|
291
|
+
path = path.substr(0, searchIndex);
|
|
292
|
+
}
|
|
293
|
+
if (path) {
|
|
294
|
+
parsedPath.pathname = path;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return parsedPath;
|
|
298
|
+
}
|
|
299
|
+
class Subject {
|
|
300
|
+
constructor(initialValue) {
|
|
301
|
+
__publicField(this, "subscribers", /* @__PURE__ */ new Set());
|
|
302
|
+
__publicField(this, "value");
|
|
303
|
+
this.value = initialValue;
|
|
304
|
+
}
|
|
305
|
+
subscribe(subscriber) {
|
|
306
|
+
this.subscribers.add(subscriber);
|
|
307
|
+
return () => {
|
|
308
|
+
this.subscribers.delete(subscriber);
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
next(value) {
|
|
312
|
+
this.value = value;
|
|
313
|
+
this.subscribers.forEach((subscriber) => subscriber(value));
|
|
314
|
+
}
|
|
315
|
+
getValue() {
|
|
316
|
+
return this.value;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
var R = class {
|
|
320
|
+
constructor(t, r, n, o, c, l) {
|
|
321
|
+
__publicField(this, "type", 3);
|
|
322
|
+
__publicField(this, "name", "");
|
|
323
|
+
__publicField(this, "prefix", "");
|
|
324
|
+
__publicField(this, "value", "");
|
|
325
|
+
__publicField(this, "suffix", "");
|
|
326
|
+
__publicField(this, "modifier", 3);
|
|
327
|
+
this.type = t, this.name = r, this.prefix = n, this.value = o, this.suffix = c, this.modifier = l;
|
|
328
|
+
}
|
|
329
|
+
hasCustomName() {
|
|
330
|
+
return this.name !== "" && typeof this.name != "number";
|
|
331
|
+
}
|
|
332
|
+
}, be = /[$_\p{ID_Start}]/u, Pe = /[$_\u200C\u200D\p{ID_Continue}]/u, M = ".*";
|
|
333
|
+
function Re(e, t) {
|
|
334
|
+
return /^[\x00-\x7F]*$/.test(e);
|
|
335
|
+
}
|
|
336
|
+
function v(e, t = false) {
|
|
337
|
+
let r = [], n = 0;
|
|
338
|
+
for (; n < e.length; ) {
|
|
339
|
+
let o = e[n], c = function(l) {
|
|
340
|
+
if (!t)
|
|
341
|
+
throw new TypeError(l);
|
|
342
|
+
r.push({ type: "INVALID_CHAR", index: n, value: e[n++] });
|
|
343
|
+
};
|
|
344
|
+
if (o === "*") {
|
|
345
|
+
r.push({ type: "ASTERISK", index: n, value: e[n++] });
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (o === "+" || o === "?") {
|
|
349
|
+
r.push({ type: "OTHER_MODIFIER", index: n, value: e[n++] });
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (o === "\\") {
|
|
353
|
+
r.push({ type: "ESCAPED_CHAR", index: n++, value: e[n++] });
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (o === "{") {
|
|
357
|
+
r.push({ type: "OPEN", index: n, value: e[n++] });
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (o === "}") {
|
|
361
|
+
r.push({ type: "CLOSE", index: n, value: e[n++] });
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (o === ":") {
|
|
365
|
+
let l = "", s = n + 1;
|
|
366
|
+
for (; s < e.length; ) {
|
|
367
|
+
let i = e.substr(s, 1);
|
|
368
|
+
if (s === n + 1 && be.test(i) || s !== n + 1 && Pe.test(i)) {
|
|
369
|
+
l += e[s++];
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
if (!l) {
|
|
375
|
+
c(`Missing parameter name at ${n}`);
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
r.push({ type: "NAME", index: n, value: l }), n = s;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (o === "(") {
|
|
382
|
+
let l = 1, s = "", i = n + 1, a = false;
|
|
383
|
+
if (e[i] === "?") {
|
|
384
|
+
c(`Pattern cannot start with "?" at ${i}`);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
for (; i < e.length; ) {
|
|
388
|
+
if (!Re(e[i])) {
|
|
389
|
+
c(`Invalid character '${e[i]}' at ${i}.`), a = true;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
if (e[i] === "\\") {
|
|
393
|
+
s += e[i++] + e[i++];
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (e[i] === ")") {
|
|
397
|
+
if (l--, l === 0) {
|
|
398
|
+
i++;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
} else if (e[i] === "(" && (l++, e[i + 1] !== "?")) {
|
|
402
|
+
c(`Capturing groups are not allowed at ${i}`), a = true;
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
s += e[i++];
|
|
406
|
+
}
|
|
407
|
+
if (a)
|
|
408
|
+
continue;
|
|
409
|
+
if (l) {
|
|
410
|
+
c(`Unbalanced pattern at ${n}`);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (!s) {
|
|
414
|
+
c(`Missing pattern at ${n}`);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
r.push({ type: "REGEX", index: n, value: s }), n = i;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
r.push({ type: "CHAR", index: n, value: e[n++] });
|
|
421
|
+
}
|
|
422
|
+
return r.push({ type: "END", index: n, value: "" }), r;
|
|
423
|
+
}
|
|
424
|
+
function D(e, t = {}) {
|
|
425
|
+
let r = v(e);
|
|
426
|
+
t.delimiter ?? (t.delimiter = "/#?"), t.prefixes ?? (t.prefixes = "./");
|
|
427
|
+
let n = `[^${S(t.delimiter)}]+?`, o = [], c = 0, l = 0, i = /* @__PURE__ */ new Set(), a = (h) => {
|
|
428
|
+
if (l < r.length && r[l].type === h)
|
|
429
|
+
return r[l++].value;
|
|
430
|
+
}, f = () => a("OTHER_MODIFIER") ?? a("ASTERISK"), d = (h) => {
|
|
431
|
+
let u = a(h);
|
|
432
|
+
if (u !== void 0)
|
|
433
|
+
return u;
|
|
434
|
+
let { type: p, index: A } = r[l];
|
|
435
|
+
throw new TypeError(`Unexpected ${p} at ${A}, expected ${h}`);
|
|
436
|
+
}, T = () => {
|
|
437
|
+
let h = "", u;
|
|
438
|
+
for (; u = a("CHAR") ?? a("ESCAPED_CHAR"); )
|
|
439
|
+
h += u;
|
|
440
|
+
return h;
|
|
441
|
+
}, Se = (h) => h, L = t.encodePart || Se, I = "", U = (h) => {
|
|
442
|
+
I += h;
|
|
443
|
+
}, $ = () => {
|
|
444
|
+
I.length && (o.push(new R(3, "", "", L(I), "", 3)), I = "");
|
|
445
|
+
}, V = (h, u, p, A, Y) => {
|
|
446
|
+
let g = 3;
|
|
447
|
+
switch (Y) {
|
|
448
|
+
case "?":
|
|
449
|
+
g = 1;
|
|
450
|
+
break;
|
|
451
|
+
case "*":
|
|
452
|
+
g = 0;
|
|
453
|
+
break;
|
|
454
|
+
case "+":
|
|
455
|
+
g = 2;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
if (!u && !p && g === 3) {
|
|
459
|
+
U(h);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if ($(), !u && !p) {
|
|
463
|
+
if (!h)
|
|
464
|
+
return;
|
|
465
|
+
o.push(new R(3, "", "", L(h), "", g));
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
let m;
|
|
469
|
+
p ? p === "*" ? m = M : m = p : m = n;
|
|
470
|
+
let O = 2;
|
|
471
|
+
m === n ? (O = 1, m = "") : m === M && (O = 0, m = "");
|
|
472
|
+
let P;
|
|
473
|
+
if (u ? P = u : p && (P = c++), i.has(P))
|
|
474
|
+
throw new TypeError(`Duplicate name '${P}'.`);
|
|
475
|
+
i.add(P), o.push(new R(O, P, L(h), m, L(A), g));
|
|
476
|
+
};
|
|
477
|
+
for (; l < r.length; ) {
|
|
478
|
+
let h = a("CHAR"), u = a("NAME"), p = a("REGEX");
|
|
479
|
+
if (!u && !p && (p = a("ASTERISK")), u || p) {
|
|
480
|
+
let g = h ?? "";
|
|
481
|
+
t.prefixes.indexOf(g) === -1 && (U(g), g = ""), $();
|
|
482
|
+
let m = f();
|
|
483
|
+
V(g, u, p, "", m);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
let A = h ?? a("ESCAPED_CHAR");
|
|
487
|
+
if (A) {
|
|
488
|
+
U(A);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (a("OPEN")) {
|
|
492
|
+
let g = T(), m = a("NAME"), O = a("REGEX");
|
|
493
|
+
!m && !O && (O = a("ASTERISK"));
|
|
494
|
+
let P = T();
|
|
495
|
+
d("CLOSE");
|
|
496
|
+
let xe = f();
|
|
497
|
+
V(g, m, O, P, xe);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
$(), d("END");
|
|
501
|
+
}
|
|
502
|
+
return o;
|
|
503
|
+
}
|
|
504
|
+
function S(e) {
|
|
505
|
+
return e.replace(/([.+*?^${}()[\]|/\\])/g, "\\$1");
|
|
506
|
+
}
|
|
507
|
+
function X(e) {
|
|
508
|
+
return e && e.ignoreCase ? "ui" : "u";
|
|
509
|
+
}
|
|
510
|
+
function Z(e, t, r) {
|
|
511
|
+
return F(D(e, r), t, r);
|
|
512
|
+
}
|
|
513
|
+
function k(e) {
|
|
514
|
+
switch (e) {
|
|
515
|
+
case 0:
|
|
516
|
+
return "*";
|
|
517
|
+
case 1:
|
|
518
|
+
return "?";
|
|
519
|
+
case 2:
|
|
520
|
+
return "+";
|
|
521
|
+
case 3:
|
|
522
|
+
return "";
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function F(e, t, r = {}) {
|
|
526
|
+
r.delimiter ?? (r.delimiter = "/#?"), r.prefixes ?? (r.prefixes = "./"), r.sensitive ?? (r.sensitive = false), r.strict ?? (r.strict = false), r.end ?? (r.end = true), r.start ?? (r.start = true), r.endsWith = "";
|
|
527
|
+
let n = r.start ? "^" : "";
|
|
528
|
+
for (let s of e) {
|
|
529
|
+
if (s.type === 3) {
|
|
530
|
+
s.modifier === 3 ? n += S(s.value) : n += `(?:${S(s.value)})${k(s.modifier)}`;
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
t && t.push(s.name);
|
|
534
|
+
let i = `[^${S(r.delimiter)}]+?`, a = s.value;
|
|
535
|
+
if (s.type === 1 ? a = i : s.type === 0 && (a = M), !s.prefix.length && !s.suffix.length) {
|
|
536
|
+
s.modifier === 3 || s.modifier === 1 ? n += `(${a})${k(s.modifier)}` : n += `((?:${a})${k(s.modifier)})`;
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (s.modifier === 3 || s.modifier === 1) {
|
|
540
|
+
n += `(?:${S(s.prefix)}(${a})${S(s.suffix)})`, n += k(s.modifier);
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
n += `(?:${S(s.prefix)}`, n += `((?:${a})(?:`, n += S(s.suffix), n += S(s.prefix), n += `(?:${a}))*)${S(s.suffix)})`, s.modifier === 0 && (n += "?");
|
|
544
|
+
}
|
|
545
|
+
let o = `[${S(r.endsWith)}]|$`, c = `[${S(r.delimiter)}]`;
|
|
546
|
+
if (r.end)
|
|
547
|
+
return r.strict || (n += `${c}?`), r.endsWith.length ? n += `(?=${o})` : n += "$", new RegExp(n, X(r));
|
|
548
|
+
r.strict || (n += `(?:${c}(?=${o}))?`);
|
|
549
|
+
let l = false;
|
|
550
|
+
if (e.length) {
|
|
551
|
+
let s = e[e.length - 1];
|
|
552
|
+
s.type === 3 && s.modifier === 3 && (l = r.delimiter.indexOf(s) > -1);
|
|
553
|
+
}
|
|
554
|
+
return l || (n += `(?=${c}|${o})`), new RegExp(n, X(r));
|
|
555
|
+
}
|
|
556
|
+
var x = { delimiter: "", prefixes: "", sensitive: true, strict: true }, B = { delimiter: ".", prefixes: "", sensitive: true, strict: true }, q = { delimiter: "/", prefixes: "/", sensitive: true, strict: true };
|
|
557
|
+
function J(e, t) {
|
|
558
|
+
return e.length ? e[0] === "/" ? true : !t || e.length < 2 ? false : (e[0] == "\\" || e[0] == "{") && e[1] == "/" : false;
|
|
559
|
+
}
|
|
560
|
+
function Q(e, t) {
|
|
561
|
+
return e.startsWith(t) ? e.substring(t.length, e.length) : e;
|
|
562
|
+
}
|
|
563
|
+
function Ee(e, t) {
|
|
564
|
+
return e.endsWith(t) ? e.substr(0, e.length - t.length) : e;
|
|
565
|
+
}
|
|
566
|
+
function W(e) {
|
|
567
|
+
return !e || e.length < 2 ? false : e[0] === "[" || (e[0] === "\\" || e[0] === "{") && e[1] === "[";
|
|
568
|
+
}
|
|
569
|
+
var ee = ["ftp", "file", "http", "https", "ws", "wss"];
|
|
570
|
+
function N(e) {
|
|
571
|
+
if (!e)
|
|
572
|
+
return true;
|
|
573
|
+
for (let t of ee)
|
|
574
|
+
if (e.test(t))
|
|
575
|
+
return true;
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
function te(e, t) {
|
|
579
|
+
if (e = Q(e, "#"), t || e === "")
|
|
580
|
+
return e;
|
|
581
|
+
let r = new URL("https://example.com");
|
|
582
|
+
return r.hash = e, r.hash ? r.hash.substring(1, r.hash.length) : "";
|
|
583
|
+
}
|
|
584
|
+
function re(e, t) {
|
|
585
|
+
if (e = Q(e, "?"), t || e === "")
|
|
586
|
+
return e;
|
|
587
|
+
let r = new URL("https://example.com");
|
|
588
|
+
return r.search = e, r.search ? r.search.substring(1, r.search.length) : "";
|
|
589
|
+
}
|
|
590
|
+
function ne(e, t) {
|
|
591
|
+
return t || e === "" ? e : W(e) ? j(e) : z(e);
|
|
592
|
+
}
|
|
593
|
+
function se(e, t) {
|
|
594
|
+
if (t || e === "")
|
|
595
|
+
return e;
|
|
596
|
+
let r = new URL("https://example.com");
|
|
597
|
+
return r.password = e, r.password;
|
|
598
|
+
}
|
|
599
|
+
function ie(e, t) {
|
|
600
|
+
if (t || e === "")
|
|
601
|
+
return e;
|
|
602
|
+
let r = new URL("https://example.com");
|
|
603
|
+
return r.username = e, r.username;
|
|
604
|
+
}
|
|
605
|
+
function ae(e, t, r) {
|
|
606
|
+
if (r || e === "")
|
|
607
|
+
return e;
|
|
608
|
+
if (t && !ee.includes(t))
|
|
609
|
+
return new URL(`${t}:${e}`).pathname;
|
|
610
|
+
let n = e[0] == "/";
|
|
611
|
+
return e = new URL(n ? e : "/-" + e, "https://example.com").pathname, n || (e = e.substring(2, e.length)), e;
|
|
612
|
+
}
|
|
613
|
+
function oe(e, t, r) {
|
|
614
|
+
return _(t) === e && (e = ""), r || e === "" ? e : K(e);
|
|
615
|
+
}
|
|
616
|
+
function ce(e, t) {
|
|
617
|
+
return e = Ee(e, ":"), t || e === "" ? e : y(e);
|
|
618
|
+
}
|
|
619
|
+
function _(e) {
|
|
620
|
+
switch (e) {
|
|
621
|
+
case "ws":
|
|
622
|
+
case "http":
|
|
623
|
+
return "80";
|
|
624
|
+
case "wws":
|
|
625
|
+
case "https":
|
|
626
|
+
return "443";
|
|
627
|
+
case "ftp":
|
|
628
|
+
return "21";
|
|
629
|
+
default:
|
|
630
|
+
return "";
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function y(e) {
|
|
634
|
+
if (e === "")
|
|
635
|
+
return e;
|
|
636
|
+
if (/^[-+.A-Za-z0-9]*$/.test(e))
|
|
637
|
+
return e.toLowerCase();
|
|
638
|
+
throw new TypeError(`Invalid protocol '${e}'.`);
|
|
639
|
+
}
|
|
640
|
+
function le(e) {
|
|
641
|
+
if (e === "")
|
|
642
|
+
return e;
|
|
643
|
+
let t = new URL("https://example.com");
|
|
644
|
+
return t.username = e, t.username;
|
|
645
|
+
}
|
|
646
|
+
function fe(e) {
|
|
647
|
+
if (e === "")
|
|
648
|
+
return e;
|
|
649
|
+
let t = new URL("https://example.com");
|
|
650
|
+
return t.password = e, t.password;
|
|
651
|
+
}
|
|
652
|
+
function z(e) {
|
|
653
|
+
if (e === "")
|
|
654
|
+
return e;
|
|
655
|
+
if (/[\t\n\r #%/:<>?@[\]^\\|]/g.test(e))
|
|
656
|
+
throw new TypeError(`Invalid hostname '${e}'`);
|
|
657
|
+
let t = new URL("https://example.com");
|
|
658
|
+
return t.hostname = e, t.hostname;
|
|
659
|
+
}
|
|
660
|
+
function j(e) {
|
|
661
|
+
if (e === "")
|
|
662
|
+
return e;
|
|
663
|
+
if (/[^0-9a-fA-F[\]:]/g.test(e))
|
|
664
|
+
throw new TypeError(`Invalid IPv6 hostname '${e}'`);
|
|
665
|
+
return e.toLowerCase();
|
|
666
|
+
}
|
|
667
|
+
function K(e) {
|
|
668
|
+
if (e === "" || /^[0-9]*$/.test(e) && parseInt(e) <= 65535)
|
|
669
|
+
return e;
|
|
670
|
+
throw new TypeError(`Invalid port '${e}'.`);
|
|
671
|
+
}
|
|
672
|
+
function he(e) {
|
|
673
|
+
if (e === "")
|
|
674
|
+
return e;
|
|
675
|
+
let t = new URL("https://example.com");
|
|
676
|
+
return t.pathname = e[0] !== "/" ? "/-" + e : e, e[0] !== "/" ? t.pathname.substring(2, t.pathname.length) : t.pathname;
|
|
677
|
+
}
|
|
678
|
+
function ue(e) {
|
|
679
|
+
return e === "" ? e : new URL(`data:${e}`).pathname;
|
|
680
|
+
}
|
|
681
|
+
function de(e) {
|
|
682
|
+
if (e === "")
|
|
683
|
+
return e;
|
|
684
|
+
let t = new URL("https://example.com");
|
|
685
|
+
return t.search = e, t.search.substring(1, t.search.length);
|
|
686
|
+
}
|
|
687
|
+
function pe(e) {
|
|
688
|
+
if (e === "")
|
|
689
|
+
return e;
|
|
690
|
+
let t = new URL("https://example.com");
|
|
691
|
+
return t.hash = e, t.hash.substring(1, t.hash.length);
|
|
692
|
+
}
|
|
693
|
+
var H = (_a2 = class {
|
|
694
|
+
constructor(t) {
|
|
695
|
+
__privateAdd(this, _r);
|
|
696
|
+
__privateAdd(this, _R);
|
|
697
|
+
__privateAdd(this, _b);
|
|
698
|
+
__privateAdd(this, _u);
|
|
699
|
+
__privateAdd(this, _m);
|
|
700
|
+
__privateAdd(this, _a);
|
|
701
|
+
__privateAdd(this, _P);
|
|
702
|
+
__privateAdd(this, _E);
|
|
703
|
+
__privateAdd(this, _S);
|
|
704
|
+
__privateAdd(this, _O);
|
|
705
|
+
__privateAdd(this, _k);
|
|
706
|
+
__privateAdd(this, _x);
|
|
707
|
+
__privateAdd(this, _h);
|
|
708
|
+
__privateAdd(this, _f);
|
|
709
|
+
__privateAdd(this, _T);
|
|
710
|
+
__privateAdd(this, _A);
|
|
711
|
+
__privateAdd(this, _y);
|
|
712
|
+
__privateAdd(this, _w);
|
|
713
|
+
__privateAdd(this, _c);
|
|
714
|
+
__privateAdd(this, _C);
|
|
715
|
+
__privateAdd(this, _i, void 0);
|
|
716
|
+
__privateAdd(this, _n, []);
|
|
717
|
+
__privateAdd(this, _t, {});
|
|
718
|
+
__privateAdd(this, _e, 0);
|
|
719
|
+
__privateAdd(this, _s, 1);
|
|
720
|
+
__privateAdd(this, _l, 0);
|
|
721
|
+
__privateAdd(this, _o, 0);
|
|
722
|
+
__privateAdd(this, _d, 0);
|
|
723
|
+
__privateAdd(this, _p, 0);
|
|
724
|
+
__privateAdd(this, _g, false);
|
|
725
|
+
__privateSet(this, _i, t);
|
|
726
|
+
}
|
|
727
|
+
get result() {
|
|
728
|
+
return __privateGet(this, _t);
|
|
729
|
+
}
|
|
730
|
+
parse() {
|
|
731
|
+
for (__privateSet(this, _n, v(__privateGet(this, _i), true)); __privateGet(this, _e) < __privateGet(this, _n).length; __privateSet(this, _e, __privateGet(this, _e) + __privateGet(this, _s))) {
|
|
732
|
+
if (__privateSet(this, _s, 1), __privateGet(this, _n)[__privateGet(this, _e)].type === "END") {
|
|
733
|
+
if (__privateGet(this, _o) === 0) {
|
|
734
|
+
__privateMethod(this, _b, b_fn).call(this), __privateMethod(this, _f, f_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 9, 1) : __privateMethod(this, _h, h_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 8, 1) : __privateMethod(this, _r, r_fn).call(this, 7, 0);
|
|
735
|
+
continue;
|
|
736
|
+
} else if (__privateGet(this, _o) === 2) {
|
|
737
|
+
__privateMethod(this, _u, u_fn).call(this, 5);
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
__privateMethod(this, _r, r_fn).call(this, 10, 0);
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
if (__privateGet(this, _d) > 0)
|
|
744
|
+
if (__privateMethod(this, _A, A_fn).call(this))
|
|
745
|
+
__privateSet(this, _d, __privateGet(this, _d) - 1);
|
|
746
|
+
else
|
|
747
|
+
continue;
|
|
748
|
+
if (__privateMethod(this, _T, T_fn).call(this)) {
|
|
749
|
+
__privateSet(this, _d, __privateGet(this, _d) + 1);
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
switch (__privateGet(this, _o)) {
|
|
753
|
+
case 0:
|
|
754
|
+
__privateMethod(this, _P, P_fn).call(this) && __privateMethod(this, _u, u_fn).call(this, 1);
|
|
755
|
+
break;
|
|
756
|
+
case 1:
|
|
757
|
+
if (__privateMethod(this, _P, P_fn).call(this)) {
|
|
758
|
+
__privateMethod(this, _C, C_fn).call(this);
|
|
759
|
+
let t = 7, r = 1;
|
|
760
|
+
__privateMethod(this, _E, E_fn).call(this) ? (t = 2, r = 3) : __privateGet(this, _g) && (t = 2), __privateMethod(this, _r, r_fn).call(this, t, r);
|
|
761
|
+
}
|
|
762
|
+
break;
|
|
763
|
+
case 2:
|
|
764
|
+
__privateMethod(this, _S, S_fn).call(this) ? __privateMethod(this, _u, u_fn).call(this, 3) : (__privateMethod(this, _x, x_fn).call(this) || __privateMethod(this, _h, h_fn).call(this) || __privateMethod(this, _f, f_fn).call(this)) && __privateMethod(this, _u, u_fn).call(this, 5);
|
|
765
|
+
break;
|
|
766
|
+
case 3:
|
|
767
|
+
__privateMethod(this, _O, O_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 4, 1) : __privateMethod(this, _S, S_fn).call(this) && __privateMethod(this, _r, r_fn).call(this, 5, 1);
|
|
768
|
+
break;
|
|
769
|
+
case 4:
|
|
770
|
+
__privateMethod(this, _S, S_fn).call(this) && __privateMethod(this, _r, r_fn).call(this, 5, 1);
|
|
771
|
+
break;
|
|
772
|
+
case 5:
|
|
773
|
+
__privateMethod(this, _y, y_fn).call(this) ? __privateSet(this, _p, __privateGet(this, _p) + 1) : __privateMethod(this, _w, w_fn).call(this) && __privateSet(this, _p, __privateGet(this, _p) - 1), __privateMethod(this, _k, k_fn).call(this) && !__privateGet(this, _p) ? __privateMethod(this, _r, r_fn).call(this, 6, 1) : __privateMethod(this, _x, x_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 7, 0) : __privateMethod(this, _h, h_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 8, 1) : __privateMethod(this, _f, f_fn).call(this) && __privateMethod(this, _r, r_fn).call(this, 9, 1);
|
|
774
|
+
break;
|
|
775
|
+
case 6:
|
|
776
|
+
__privateMethod(this, _x, x_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 7, 0) : __privateMethod(this, _h, h_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 8, 1) : __privateMethod(this, _f, f_fn).call(this) && __privateMethod(this, _r, r_fn).call(this, 9, 1);
|
|
777
|
+
break;
|
|
778
|
+
case 7:
|
|
779
|
+
__privateMethod(this, _h, h_fn).call(this) ? __privateMethod(this, _r, r_fn).call(this, 8, 1) : __privateMethod(this, _f, f_fn).call(this) && __privateMethod(this, _r, r_fn).call(this, 9, 1);
|
|
780
|
+
break;
|
|
781
|
+
case 8:
|
|
782
|
+
__privateMethod(this, _f, f_fn).call(this) && __privateMethod(this, _r, r_fn).call(this, 9, 1);
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
__privateGet(this, _t).hostname !== void 0 && __privateGet(this, _t).port === void 0 && (__privateGet(this, _t).port = "");
|
|
787
|
+
}
|
|
788
|
+
}, _i = new WeakMap(), _n = new WeakMap(), _t = new WeakMap(), _e = new WeakMap(), _s = new WeakMap(), _l = new WeakMap(), _o = new WeakMap(), _d = new WeakMap(), _p = new WeakMap(), _g = new WeakMap(), _r = new WeakSet(), r_fn = function(t, r) {
|
|
789
|
+
var _a3, _b3, _c2;
|
|
790
|
+
switch (__privateGet(this, _o)) {
|
|
791
|
+
case 0:
|
|
792
|
+
break;
|
|
793
|
+
case 1:
|
|
794
|
+
__privateGet(this, _t).protocol = __privateMethod(this, _c, c_fn).call(this);
|
|
795
|
+
break;
|
|
796
|
+
case 2:
|
|
797
|
+
break;
|
|
798
|
+
case 3:
|
|
799
|
+
__privateGet(this, _t).username = __privateMethod(this, _c, c_fn).call(this);
|
|
800
|
+
break;
|
|
801
|
+
case 4:
|
|
802
|
+
__privateGet(this, _t).password = __privateMethod(this, _c, c_fn).call(this);
|
|
803
|
+
break;
|
|
804
|
+
case 5:
|
|
805
|
+
__privateGet(this, _t).hostname = __privateMethod(this, _c, c_fn).call(this);
|
|
806
|
+
break;
|
|
807
|
+
case 6:
|
|
808
|
+
__privateGet(this, _t).port = __privateMethod(this, _c, c_fn).call(this);
|
|
809
|
+
break;
|
|
810
|
+
case 7:
|
|
811
|
+
__privateGet(this, _t).pathname = __privateMethod(this, _c, c_fn).call(this);
|
|
812
|
+
break;
|
|
813
|
+
case 8:
|
|
814
|
+
__privateGet(this, _t).search = __privateMethod(this, _c, c_fn).call(this);
|
|
815
|
+
break;
|
|
816
|
+
case 9:
|
|
817
|
+
__privateGet(this, _t).hash = __privateMethod(this, _c, c_fn).call(this);
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
__privateGet(this, _o) !== 0 && t !== 10 && ([1, 2, 3, 4].includes(__privateGet(this, _o)) && [6, 7, 8, 9].includes(t) && ((_a3 = __privateGet(this, _t)).hostname ?? (_a3.hostname = "")), [1, 2, 3, 4, 5, 6].includes(__privateGet(this, _o)) && [8, 9].includes(t) && ((_b3 = __privateGet(this, _t)).pathname ?? (_b3.pathname = __privateGet(this, _g) ? "/" : "")), [1, 2, 3, 4, 5, 6, 7].includes(__privateGet(this, _o)) && t === 9 && ((_c2 = __privateGet(this, _t)).search ?? (_c2.search = ""))), __privateMethod(this, _R, R_fn).call(this, t, r);
|
|
821
|
+
}, _R = new WeakSet(), R_fn = function(t, r) {
|
|
822
|
+
__privateSet(this, _o, t), __privateSet(this, _l, __privateGet(this, _e) + r), __privateSet(this, _e, __privateGet(this, _e) + r), __privateSet(this, _s, 0);
|
|
823
|
+
}, _b = new WeakSet(), b_fn = function() {
|
|
824
|
+
__privateSet(this, _e, __privateGet(this, _l)), __privateSet(this, _s, 0);
|
|
825
|
+
}, _u = new WeakSet(), u_fn = function(t) {
|
|
826
|
+
__privateMethod(this, _b, b_fn).call(this), __privateSet(this, _o, t);
|
|
827
|
+
}, _m = new WeakSet(), m_fn = function(t) {
|
|
828
|
+
return t < 0 && (t = __privateGet(this, _n).length - t), t < __privateGet(this, _n).length ? __privateGet(this, _n)[t] : __privateGet(this, _n)[__privateGet(this, _n).length - 1];
|
|
829
|
+
}, _a = new WeakSet(), a_fn = function(t, r) {
|
|
830
|
+
let n = __privateMethod(this, _m, m_fn).call(this, t);
|
|
831
|
+
return n.value === r && (n.type === "CHAR" || n.type === "ESCAPED_CHAR" || n.type === "INVALID_CHAR");
|
|
832
|
+
}, _P = new WeakSet(), P_fn = function() {
|
|
833
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), ":");
|
|
834
|
+
}, _E = new WeakSet(), E_fn = function() {
|
|
835
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e) + 1, "/") && __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e) + 2, "/");
|
|
836
|
+
}, _S = new WeakSet(), S_fn = function() {
|
|
837
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), "@");
|
|
838
|
+
}, _O = new WeakSet(), O_fn = function() {
|
|
839
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), ":");
|
|
840
|
+
}, _k = new WeakSet(), k_fn = function() {
|
|
841
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), ":");
|
|
842
|
+
}, _x = new WeakSet(), x_fn = function() {
|
|
843
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), "/");
|
|
844
|
+
}, _h = new WeakSet(), h_fn = function() {
|
|
845
|
+
if (__privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), "?"))
|
|
846
|
+
return true;
|
|
847
|
+
if (__privateGet(this, _n)[__privateGet(this, _e)].value !== "?")
|
|
848
|
+
return false;
|
|
849
|
+
let t = __privateMethod(this, _m, m_fn).call(this, __privateGet(this, _e) - 1);
|
|
850
|
+
return t.type !== "NAME" && t.type !== "REGEX" && t.type !== "CLOSE" && t.type !== "ASTERISK";
|
|
851
|
+
}, _f = new WeakSet(), f_fn = function() {
|
|
852
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), "#");
|
|
853
|
+
}, _T = new WeakSet(), T_fn = function() {
|
|
854
|
+
return __privateGet(this, _n)[__privateGet(this, _e)].type == "OPEN";
|
|
855
|
+
}, _A = new WeakSet(), A_fn = function() {
|
|
856
|
+
return __privateGet(this, _n)[__privateGet(this, _e)].type == "CLOSE";
|
|
857
|
+
}, _y = new WeakSet(), y_fn = function() {
|
|
858
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), "[");
|
|
859
|
+
}, _w = new WeakSet(), w_fn = function() {
|
|
860
|
+
return __privateMethod(this, _a, a_fn).call(this, __privateGet(this, _e), "]");
|
|
861
|
+
}, _c = new WeakSet(), c_fn = function() {
|
|
862
|
+
let t = __privateGet(this, _n)[__privateGet(this, _e)], r = __privateMethod(this, _m, m_fn).call(this, __privateGet(this, _l)).index;
|
|
863
|
+
return __privateGet(this, _i).substring(r, t.index);
|
|
864
|
+
}, _C = new WeakSet(), C_fn = function() {
|
|
865
|
+
let t = {};
|
|
866
|
+
Object.assign(t, x), t.encodePart = y;
|
|
867
|
+
let r = Z(__privateMethod(this, _c, c_fn).call(this), void 0, t);
|
|
868
|
+
__privateSet(this, _g, N(r));
|
|
869
|
+
}, _a2);
|
|
870
|
+
var G = ["protocol", "username", "password", "hostname", "port", "pathname", "search", "hash"], E = "*";
|
|
871
|
+
function ge(e, t) {
|
|
872
|
+
if (typeof e != "string")
|
|
873
|
+
throw new TypeError("parameter 1 is not of type 'string'.");
|
|
874
|
+
let r = new URL(e, t);
|
|
875
|
+
return { protocol: r.protocol.substring(0, r.protocol.length - 1), username: r.username, password: r.password, hostname: r.hostname, port: r.port, pathname: r.pathname, search: r.search !== "" ? r.search.substring(1, r.search.length) : void 0, hash: r.hash !== "" ? r.hash.substring(1, r.hash.length) : void 0 };
|
|
876
|
+
}
|
|
877
|
+
function b(e, t) {
|
|
878
|
+
return t ? C(e) : e;
|
|
879
|
+
}
|
|
880
|
+
function w(e, t, r) {
|
|
881
|
+
let n;
|
|
882
|
+
if (typeof t.baseURL == "string")
|
|
883
|
+
try {
|
|
884
|
+
n = new URL(t.baseURL), t.protocol === void 0 && (e.protocol = b(n.protocol.substring(0, n.protocol.length - 1), r)), !r && t.protocol === void 0 && t.hostname === void 0 && t.port === void 0 && t.username === void 0 && (e.username = b(n.username, r)), !r && t.protocol === void 0 && t.hostname === void 0 && t.port === void 0 && t.username === void 0 && t.password === void 0 && (e.password = b(n.password, r)), t.protocol === void 0 && t.hostname === void 0 && (e.hostname = b(n.hostname, r)), t.protocol === void 0 && t.hostname === void 0 && t.port === void 0 && (e.port = b(n.port, r)), t.protocol === void 0 && t.hostname === void 0 && t.port === void 0 && t.pathname === void 0 && (e.pathname = b(n.pathname, r)), t.protocol === void 0 && t.hostname === void 0 && t.port === void 0 && t.pathname === void 0 && t.search === void 0 && (e.search = b(n.search.substring(1, n.search.length), r)), t.protocol === void 0 && t.hostname === void 0 && t.port === void 0 && t.pathname === void 0 && t.search === void 0 && t.hash === void 0 && (e.hash = b(n.hash.substring(1, n.hash.length), r));
|
|
885
|
+
} catch {
|
|
886
|
+
throw new TypeError(`invalid baseURL '${t.baseURL}'.`);
|
|
887
|
+
}
|
|
888
|
+
if (typeof t.protocol == "string" && (e.protocol = ce(t.protocol, r)), typeof t.username == "string" && (e.username = ie(t.username, r)), typeof t.password == "string" && (e.password = se(t.password, r)), typeof t.hostname == "string" && (e.hostname = ne(t.hostname, r)), typeof t.port == "string" && (e.port = oe(t.port, e.protocol, r)), typeof t.pathname == "string") {
|
|
889
|
+
if (e.pathname = t.pathname, n && !J(e.pathname, r)) {
|
|
890
|
+
let o = n.pathname.lastIndexOf("/");
|
|
891
|
+
o >= 0 && (e.pathname = b(n.pathname.substring(0, o + 1), r) + e.pathname);
|
|
892
|
+
}
|
|
893
|
+
e.pathname = ae(e.pathname, e.protocol, r);
|
|
894
|
+
}
|
|
895
|
+
return typeof t.search == "string" && (e.search = re(t.search, r)), typeof t.hash == "string" && (e.hash = te(t.hash, r)), e;
|
|
896
|
+
}
|
|
897
|
+
function C(e) {
|
|
898
|
+
return e.replace(/([+*?:{}()\\])/g, "\\$1");
|
|
899
|
+
}
|
|
900
|
+
function Oe(e) {
|
|
901
|
+
return e.replace(/([.+*?^${}()[\]|/\\])/g, "\\$1");
|
|
902
|
+
}
|
|
903
|
+
function ke(e, t) {
|
|
904
|
+
t.delimiter ?? (t.delimiter = "/#?"), t.prefixes ?? (t.prefixes = "./"), t.sensitive ?? (t.sensitive = false), t.strict ?? (t.strict = false), t.end ?? (t.end = true), t.start ?? (t.start = true), t.endsWith = "";
|
|
905
|
+
let r = ".*", n = `[^${Oe(t.delimiter)}]+?`, o = /[$_\u200C\u200D\p{ID_Continue}]/u, c = "";
|
|
906
|
+
for (let l = 0; l < e.length; ++l) {
|
|
907
|
+
let s = e[l];
|
|
908
|
+
if (s.type === 3) {
|
|
909
|
+
if (s.modifier === 3) {
|
|
910
|
+
c += C(s.value);
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
c += `{${C(s.value)}}${k(s.modifier)}`;
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
let i = s.hasCustomName(), a = !!s.suffix.length || !!s.prefix.length && (s.prefix.length !== 1 || !t.prefixes.includes(s.prefix)), f = l > 0 ? e[l - 1] : null, d = l < e.length - 1 ? e[l + 1] : null;
|
|
917
|
+
if (!a && i && s.type === 1 && s.modifier === 3 && d && !d.prefix.length && !d.suffix.length)
|
|
918
|
+
if (d.type === 3) {
|
|
919
|
+
let T = d.value.length > 0 ? d.value[0] : "";
|
|
920
|
+
a = o.test(T);
|
|
921
|
+
} else
|
|
922
|
+
a = !d.hasCustomName();
|
|
923
|
+
if (!a && !s.prefix.length && f && f.type === 3) {
|
|
924
|
+
let T = f.value[f.value.length - 1];
|
|
925
|
+
a = t.prefixes.includes(T);
|
|
926
|
+
}
|
|
927
|
+
a && (c += "{"), c += C(s.prefix), i && (c += `:${s.name}`), s.type === 2 ? c += `(${s.value})` : s.type === 1 ? i || (c += `(${n})`) : s.type === 0 && (!i && (!f || f.type === 3 || f.modifier !== 3 || a || s.prefix !== "") ? c += "*" : c += `(${r})`), s.type === 1 && i && s.suffix.length && o.test(s.suffix[0]) && (c += "\\"), c += C(s.suffix), a && (c += "}"), s.modifier !== 3 && (c += k(s.modifier));
|
|
928
|
+
}
|
|
929
|
+
return c;
|
|
930
|
+
}
|
|
931
|
+
var me = (_b2 = class {
|
|
932
|
+
constructor(t = {}, r, n) {
|
|
933
|
+
__privateAdd(this, _i2, void 0);
|
|
934
|
+
__privateAdd(this, _n2, {});
|
|
935
|
+
__privateAdd(this, _t2, {});
|
|
936
|
+
__privateAdd(this, _e2, {});
|
|
937
|
+
__privateAdd(this, _s2, {});
|
|
938
|
+
__privateAdd(this, _l2, false);
|
|
939
|
+
try {
|
|
940
|
+
let o;
|
|
941
|
+
if (typeof r == "string" ? o = r : n = r, typeof t == "string") {
|
|
942
|
+
let i = new H(t);
|
|
943
|
+
if (i.parse(), t = i.result, o === void 0 && typeof t.protocol != "string")
|
|
944
|
+
throw new TypeError("A base URL must be provided for a relative constructor string.");
|
|
945
|
+
t.baseURL = o;
|
|
946
|
+
} else {
|
|
947
|
+
if (!t || typeof t != "object")
|
|
948
|
+
throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");
|
|
949
|
+
if (o)
|
|
950
|
+
throw new TypeError("parameter 1 is not of type 'string'.");
|
|
951
|
+
}
|
|
952
|
+
typeof n > "u" && (n = { ignoreCase: false });
|
|
953
|
+
let c = { ignoreCase: n.ignoreCase === true }, l = { pathname: E, protocol: E, username: E, password: E, hostname: E, port: E, search: E, hash: E };
|
|
954
|
+
__privateSet(this, _i2, w(l, t, true)), _(__privateGet(this, _i2).protocol) === __privateGet(this, _i2).port && (__privateGet(this, _i2).port = "");
|
|
955
|
+
let s;
|
|
956
|
+
for (s of G) {
|
|
957
|
+
if (!(s in __privateGet(this, _i2)))
|
|
958
|
+
continue;
|
|
959
|
+
let i = {}, a = __privateGet(this, _i2)[s];
|
|
960
|
+
switch (__privateGet(this, _t2)[s] = [], s) {
|
|
961
|
+
case "protocol":
|
|
962
|
+
Object.assign(i, x), i.encodePart = y;
|
|
963
|
+
break;
|
|
964
|
+
case "username":
|
|
965
|
+
Object.assign(i, x), i.encodePart = le;
|
|
966
|
+
break;
|
|
967
|
+
case "password":
|
|
968
|
+
Object.assign(i, x), i.encodePart = fe;
|
|
969
|
+
break;
|
|
970
|
+
case "hostname":
|
|
971
|
+
Object.assign(i, B), W(a) ? i.encodePart = j : i.encodePart = z;
|
|
972
|
+
break;
|
|
973
|
+
case "port":
|
|
974
|
+
Object.assign(i, x), i.encodePart = K;
|
|
975
|
+
break;
|
|
976
|
+
case "pathname":
|
|
977
|
+
N(__privateGet(this, _n2).protocol) ? (Object.assign(i, q, c), i.encodePart = he) : (Object.assign(i, x, c), i.encodePart = ue);
|
|
978
|
+
break;
|
|
979
|
+
case "search":
|
|
980
|
+
Object.assign(i, x, c), i.encodePart = de;
|
|
981
|
+
break;
|
|
982
|
+
case "hash":
|
|
983
|
+
Object.assign(i, x, c), i.encodePart = pe;
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
986
|
+
try {
|
|
987
|
+
__privateGet(this, _s2)[s] = D(a, i), __privateGet(this, _n2)[s] = F(__privateGet(this, _s2)[s], __privateGet(this, _t2)[s], i), __privateGet(this, _e2)[s] = ke(__privateGet(this, _s2)[s], i), __privateSet(this, _l2, __privateGet(this, _l2) || __privateGet(this, _s2)[s].some((f) => f.type === 2));
|
|
988
|
+
} catch {
|
|
989
|
+
throw new TypeError(`invalid ${s} pattern '${__privateGet(this, _i2)[s]}'.`);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
} catch (o) {
|
|
993
|
+
throw new TypeError(`Failed to construct 'URLPattern': ${o.message}`);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
test(t = {}, r) {
|
|
997
|
+
let n = { pathname: "", protocol: "", username: "", password: "", hostname: "", port: "", search: "", hash: "" };
|
|
998
|
+
if (typeof t != "string" && r)
|
|
999
|
+
throw new TypeError("parameter 1 is not of type 'string'.");
|
|
1000
|
+
if (typeof t > "u")
|
|
1001
|
+
return false;
|
|
1002
|
+
try {
|
|
1003
|
+
typeof t == "object" ? n = w(n, t, false) : n = w(n, ge(t, r), false);
|
|
1004
|
+
} catch {
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
let o;
|
|
1008
|
+
for (o of G)
|
|
1009
|
+
if (!__privateGet(this, _n2)[o].exec(n[o]))
|
|
1010
|
+
return false;
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
exec(t = {}, r) {
|
|
1014
|
+
let n = { pathname: "", protocol: "", username: "", password: "", hostname: "", port: "", search: "", hash: "" };
|
|
1015
|
+
if (typeof t != "string" && r)
|
|
1016
|
+
throw new TypeError("parameter 1 is not of type 'string'.");
|
|
1017
|
+
if (typeof t > "u")
|
|
1018
|
+
return;
|
|
1019
|
+
try {
|
|
1020
|
+
typeof t == "object" ? n = w(n, t, false) : n = w(n, ge(t, r), false);
|
|
1021
|
+
} catch {
|
|
1022
|
+
return null;
|
|
1023
|
+
}
|
|
1024
|
+
let o = {};
|
|
1025
|
+
r ? o.inputs = [t, r] : o.inputs = [t];
|
|
1026
|
+
let c;
|
|
1027
|
+
for (c of G) {
|
|
1028
|
+
let l = __privateGet(this, _n2)[c].exec(n[c]);
|
|
1029
|
+
if (!l)
|
|
1030
|
+
return null;
|
|
1031
|
+
let s = {};
|
|
1032
|
+
for (let [i, a] of __privateGet(this, _t2)[c].entries())
|
|
1033
|
+
if (typeof a == "string" || typeof a == "number") {
|
|
1034
|
+
let f = l[i + 1];
|
|
1035
|
+
s[a] = f;
|
|
1036
|
+
}
|
|
1037
|
+
o[c] = { input: n[c] ?? "", groups: s };
|
|
1038
|
+
}
|
|
1039
|
+
return o;
|
|
1040
|
+
}
|
|
1041
|
+
static compareComponent(t, r, n) {
|
|
1042
|
+
let o = (i, a) => {
|
|
1043
|
+
for (let f of ["type", "modifier", "prefix", "value", "suffix"]) {
|
|
1044
|
+
if (i[f] < a[f])
|
|
1045
|
+
return -1;
|
|
1046
|
+
if (i[f] === a[f])
|
|
1047
|
+
continue;
|
|
1048
|
+
return 1;
|
|
1049
|
+
}
|
|
1050
|
+
return 0;
|
|
1051
|
+
}, c = new R(3, "", "", "", "", 3), l = new R(0, "", "", "", "", 3), s = (i, a) => {
|
|
1052
|
+
let f = 0;
|
|
1053
|
+
for (; f < Math.min(i.length, a.length); ++f) {
|
|
1054
|
+
let d = o(i[f], a[f]);
|
|
1055
|
+
if (d)
|
|
1056
|
+
return d;
|
|
1057
|
+
}
|
|
1058
|
+
return i.length === a.length ? 0 : o(i[f] ?? c, a[f] ?? c);
|
|
1059
|
+
};
|
|
1060
|
+
return !__privateGet(r, _e2)[t] && !__privateGet(n, _e2)[t] ? 0 : __privateGet(r, _e2)[t] && !__privateGet(n, _e2)[t] ? s(__privateGet(r, _s2)[t], [l]) : !__privateGet(r, _e2)[t] && __privateGet(n, _e2)[t] ? s([l], __privateGet(n, _s2)[t]) : s(__privateGet(r, _s2)[t], __privateGet(n, _s2)[t]);
|
|
1061
|
+
}
|
|
1062
|
+
get protocol() {
|
|
1063
|
+
return __privateGet(this, _e2).protocol;
|
|
1064
|
+
}
|
|
1065
|
+
get username() {
|
|
1066
|
+
return __privateGet(this, _e2).username;
|
|
1067
|
+
}
|
|
1068
|
+
get password() {
|
|
1069
|
+
return __privateGet(this, _e2).password;
|
|
1070
|
+
}
|
|
1071
|
+
get hostname() {
|
|
1072
|
+
return __privateGet(this, _e2).hostname;
|
|
1073
|
+
}
|
|
1074
|
+
get port() {
|
|
1075
|
+
return __privateGet(this, _e2).port;
|
|
1076
|
+
}
|
|
1077
|
+
get pathname() {
|
|
1078
|
+
return __privateGet(this, _e2).pathname;
|
|
1079
|
+
}
|
|
1080
|
+
get search() {
|
|
1081
|
+
return __privateGet(this, _e2).search;
|
|
1082
|
+
}
|
|
1083
|
+
get hash() {
|
|
1084
|
+
return __privateGet(this, _e2).hash;
|
|
1085
|
+
}
|
|
1086
|
+
get hasRegExpGroups() {
|
|
1087
|
+
return __privateGet(this, _l2);
|
|
1088
|
+
}
|
|
1089
|
+
}, _i2 = new WeakMap(), _n2 = new WeakMap(), _t2 = new WeakMap(), _e2 = new WeakMap(), _s2 = new WeakMap(), _l2 = new WeakMap(), _b2);
|
|
1090
|
+
if (!globalThis.URLPattern) {
|
|
1091
|
+
globalThis.URLPattern = me;
|
|
1092
|
+
}
|
|
1093
|
+
const ClientRouterContext = createContext(
|
|
1094
|
+
{}
|
|
1095
|
+
);
|
|
1096
|
+
const ClientRouterProvider = (props) => {
|
|
1097
|
+
const {
|
|
1098
|
+
children,
|
|
1099
|
+
pathname,
|
|
1100
|
+
currentPath,
|
|
1101
|
+
is404,
|
|
1102
|
+
routeManifest,
|
|
1103
|
+
pageData,
|
|
1104
|
+
params
|
|
1105
|
+
} = props;
|
|
1106
|
+
const [parameters, setParameters] = useState(params);
|
|
1107
|
+
const pageDataRef = useRef(pageData);
|
|
1108
|
+
const scrollHistoryRef = useRef(/* @__PURE__ */ new Map());
|
|
1109
|
+
const initalViewEntries = is404 ? ["404"] : routeManifest[pathname] ?? ["404"];
|
|
1110
|
+
const viewEntriesSubject = useRef(new Subject(initalViewEntries));
|
|
1111
|
+
const locationSubject = useRef(
|
|
1112
|
+
new Subject({
|
|
1113
|
+
hash: "",
|
|
1114
|
+
pathname: currentPath,
|
|
1115
|
+
search: "",
|
|
1116
|
+
state: {},
|
|
1117
|
+
key: ""
|
|
1118
|
+
})
|
|
1119
|
+
);
|
|
1120
|
+
const [history] = useState(() => {
|
|
1121
|
+
let history2 = null;
|
|
1122
|
+
if (typeof window !== "undefined") {
|
|
1123
|
+
history2 = createBrowserHistory();
|
|
1124
|
+
}
|
|
1125
|
+
return history2;
|
|
1126
|
+
});
|
|
1127
|
+
const handleScroll = () => {
|
|
1128
|
+
scrollHistoryRef.current.set(
|
|
1129
|
+
locationSubject.current.getValue().pathname,
|
|
1130
|
+
window.scrollY
|
|
1131
|
+
);
|
|
1132
|
+
};
|
|
1133
|
+
useEffect(() => {
|
|
1134
|
+
history == null ? void 0 : history.listen(({ location }) => {
|
|
1135
|
+
locationSubject.current.next(structuredClone(location));
|
|
1136
|
+
viewEntriesSubject.current.next(
|
|
1137
|
+
(() => {
|
|
1138
|
+
var _a3, _b3;
|
|
1139
|
+
if (((_a3 = location.state) == null ? void 0 : _a3.status) === 404) {
|
|
1140
|
+
return ["404"];
|
|
1141
|
+
}
|
|
1142
|
+
for (const [route, views] of Object.entries(routeManifest)) {
|
|
1143
|
+
const urlPattern = new me({ pathname: route });
|
|
1144
|
+
if (urlPattern.test({ pathname: location.pathname })) {
|
|
1145
|
+
setParameters(
|
|
1146
|
+
(_b3 = urlPattern.exec({ pathname: location.pathname })) == null ? void 0 : _b3.pathname.groups
|
|
1147
|
+
);
|
|
1148
|
+
return views;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return [];
|
|
1152
|
+
})()
|
|
1153
|
+
);
|
|
1154
|
+
});
|
|
1155
|
+
window.addEventListener("scrollend", handleScroll);
|
|
1156
|
+
return () => {
|
|
1157
|
+
window.removeEventListener("scroll", handleScroll);
|
|
1158
|
+
};
|
|
1159
|
+
}, []);
|
|
1160
|
+
const updatePageData = (newPageData) => {
|
|
1161
|
+
var _a3;
|
|
1162
|
+
const [key, value] = Object.entries(newPageData)[0];
|
|
1163
|
+
if (!((_a3 = pageDataRef.current) == null ? void 0 : _a3[key])) {
|
|
1164
|
+
pageDataRef.current[key] = {};
|
|
1165
|
+
}
|
|
1166
|
+
pageDataRef.current[key] = value;
|
|
1167
|
+
};
|
|
1168
|
+
const getPageData = (key) => {
|
|
1169
|
+
return pageDataRef.current[locationSubject.current.getValue().pathname][key];
|
|
1170
|
+
};
|
|
1171
|
+
return /* @__PURE__ */ jsx(
|
|
1172
|
+
ClientRouterContext.Provider,
|
|
1173
|
+
{
|
|
1174
|
+
value: {
|
|
1175
|
+
history,
|
|
1176
|
+
params: parameters,
|
|
1177
|
+
locationSubject: locationSubject.current,
|
|
1178
|
+
getScrollPosition: (path) => {
|
|
1179
|
+
return scrollHistoryRef.current.get(path) || 0;
|
|
1180
|
+
},
|
|
1181
|
+
viewEntriesSubject: viewEntriesSubject.current,
|
|
1182
|
+
updatePageData,
|
|
1183
|
+
getPageData
|
|
1184
|
+
},
|
|
1185
|
+
children
|
|
1186
|
+
}
|
|
1187
|
+
);
|
|
1188
|
+
};
|
|
1189
|
+
function useLocationChange(cb) {
|
|
1190
|
+
const { locationSubject } = useContext(ClientRouterContext);
|
|
1191
|
+
useEffect(() => {
|
|
1192
|
+
cb(locationSubject.getValue());
|
|
1193
|
+
return locationSubject.subscribe(cb);
|
|
1194
|
+
}, []);
|
|
1195
|
+
}
|
|
1196
|
+
function useLocation() {
|
|
1197
|
+
const { locationSubject } = useContext(ClientRouterContext);
|
|
1198
|
+
const [location, setLocation] = useState(locationSubject.getValue());
|
|
1199
|
+
useLocationChange((newLocation) => {
|
|
1200
|
+
setLocation(newLocation);
|
|
1201
|
+
});
|
|
1202
|
+
return location;
|
|
1203
|
+
}
|
|
1204
|
+
function useParams() {
|
|
1205
|
+
const { params } = useContext(ClientRouterContext);
|
|
1206
|
+
return params;
|
|
1207
|
+
}
|
|
1208
|
+
function useRouter() {
|
|
1209
|
+
const { updatePageData, history } = useContext(ClientRouterContext);
|
|
1210
|
+
return {
|
|
1211
|
+
push: async (to, state) => {
|
|
1212
|
+
var _a3;
|
|
1213
|
+
let path = "";
|
|
1214
|
+
if (typeof to === "string") {
|
|
1215
|
+
path = `${to}?json=true`;
|
|
1216
|
+
} else {
|
|
1217
|
+
const { hash, pathname, search } = to;
|
|
1218
|
+
const urlSearchParams = new URLSearchParams(search);
|
|
1219
|
+
urlSearchParams.set("json", "true");
|
|
1220
|
+
path = `${pathname}${urlSearchParams.toString()}${hash}`;
|
|
1221
|
+
}
|
|
1222
|
+
const res = await fetch(path);
|
|
1223
|
+
if (res.ok) {
|
|
1224
|
+
const { data } = await res.json();
|
|
1225
|
+
const is404 = ((_a3 = Object.values(data[to])[0]) == null ? void 0 : _a3.status) === 404;
|
|
1226
|
+
updatePageData(data);
|
|
1227
|
+
history == null ? void 0 : history.push(to, is404 ? { status: 404 } : state);
|
|
1228
|
+
window.scrollTo(0, 0);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
const Link = (props) => {
|
|
1234
|
+
const { href, onClick, ...rest } = props;
|
|
1235
|
+
const { push } = useRouter();
|
|
1236
|
+
let path = "";
|
|
1237
|
+
if (typeof href === "string") {
|
|
1238
|
+
path = `${href}`;
|
|
1239
|
+
} else {
|
|
1240
|
+
const { hash, pathname, search } = href;
|
|
1241
|
+
const urlSearchParams = new URLSearchParams(search);
|
|
1242
|
+
path = `${pathname}${urlSearchParams.toString()}${hash}`;
|
|
1243
|
+
}
|
|
1244
|
+
return /* @__PURE__ */ jsx(
|
|
1245
|
+
"a",
|
|
1246
|
+
{
|
|
1247
|
+
href: path,
|
|
1248
|
+
onClick: (e) => {
|
|
1249
|
+
e.preventDefault();
|
|
1250
|
+
onClick == null ? void 0 : onClick(e);
|
|
1251
|
+
startTransition(() => {
|
|
1252
|
+
push(href);
|
|
1253
|
+
});
|
|
1254
|
+
},
|
|
1255
|
+
...rest
|
|
1256
|
+
}
|
|
1257
|
+
);
|
|
1258
|
+
};
|
|
1259
|
+
const ComponentsContext = createContext({ components: {} });
|
|
1260
|
+
const Route = (props) => {
|
|
1261
|
+
const { componentPath } = props;
|
|
1262
|
+
const { components } = useContext(ComponentsContext);
|
|
1263
|
+
const { viewEntriesSubject, getPageData, history } = useContext(ClientRouterContext);
|
|
1264
|
+
const [render, setRender] = useState(
|
|
1265
|
+
viewEntriesSubject.getValue().includes(componentPath)
|
|
1266
|
+
);
|
|
1267
|
+
const [data, setData] = useState(getPageData(componentPath));
|
|
1268
|
+
useEffect(() => {
|
|
1269
|
+
return viewEntriesSubject.subscribe((viewEntries) => {
|
|
1270
|
+
setRender(viewEntries.includes(componentPath));
|
|
1271
|
+
});
|
|
1272
|
+
}, [componentPath]);
|
|
1273
|
+
useEffect(() => {
|
|
1274
|
+
return history == null ? void 0 : history.listen(() => {
|
|
1275
|
+
setData(getPageData(componentPath));
|
|
1276
|
+
});
|
|
1277
|
+
}, []);
|
|
1278
|
+
if (!render)
|
|
1279
|
+
return null;
|
|
1280
|
+
const Component = components == null ? void 0 : components[`./views/${componentPath}.tsx`];
|
|
1281
|
+
return /* @__PURE__ */ jsx(Component, { ...data, children: props.children });
|
|
1282
|
+
};
|
|
1283
|
+
const Routes = (props) => {
|
|
1284
|
+
const { componentTree } = props;
|
|
1285
|
+
return /* @__PURE__ */ jsx(Fragment, { children: componentTree.map((node, i) => {
|
|
1286
|
+
if (typeof node === "undefined") {
|
|
1287
|
+
return null;
|
|
1288
|
+
}
|
|
1289
|
+
if (typeof node === "string") {
|
|
1290
|
+
return /* @__PURE__ */ jsxs(Suspense, { children: [
|
|
1291
|
+
/* @__PURE__ */ jsx(Route, { componentPath: node }, node),
|
|
1292
|
+
";"
|
|
1293
|
+
] });
|
|
1294
|
+
}
|
|
1295
|
+
if (Array.isArray(node)) {
|
|
1296
|
+
const [path, subtree2] = node;
|
|
1297
|
+
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Route, { componentPath: path, children: /* @__PURE__ */ jsx(Routes, { componentTree: subtree2 }) }, i) }, i);
|
|
1298
|
+
}
|
|
1299
|
+
const [[first, subtree]] = Object.entries(node);
|
|
1300
|
+
return /* @__PURE__ */ jsx(Route, { componentPath: String(first), children: /* @__PURE__ */ jsx(Routes, { componentTree: subtree }) }, i);
|
|
1301
|
+
}) });
|
|
1302
|
+
};
|
|
1303
|
+
const ClientRouter = (props) => {
|
|
1304
|
+
const { routeManifest, router, componentTree, pageData } = useContext(ServerDataContext);
|
|
1305
|
+
const components = Object.entries(props.components).reduce(
|
|
1306
|
+
(acc, [path, importer]) => {
|
|
1307
|
+
return {
|
|
1308
|
+
...acc,
|
|
1309
|
+
[path]: lazy(
|
|
1310
|
+
importer
|
|
1311
|
+
)
|
|
1312
|
+
};
|
|
1313
|
+
},
|
|
1314
|
+
{}
|
|
1315
|
+
);
|
|
1316
|
+
const RootLayout = components["./views/RootLayout.tsx"];
|
|
1317
|
+
return /* @__PURE__ */ jsx(
|
|
1318
|
+
ClientRouterProvider,
|
|
1319
|
+
{
|
|
1320
|
+
params: router.params,
|
|
1321
|
+
pageData,
|
|
1322
|
+
is404: router.is404,
|
|
1323
|
+
pathname: router.pathname,
|
|
1324
|
+
currentPath: router.currentPath,
|
|
1325
|
+
routeManifest,
|
|
1326
|
+
children: /* @__PURE__ */ jsx(ComponentsContext.Provider, { value: { components }, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "Loading..." }), children: /* @__PURE__ */ jsx(RootLayout, { children: /* @__PURE__ */ jsx(Routes, { componentTree }) }) }) })
|
|
1327
|
+
}
|
|
1328
|
+
);
|
|
1329
|
+
};
|
|
1330
|
+
const Main = (props) => {
|
|
1331
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1332
|
+
/* @__PURE__ */ jsx(Fragment, {}),
|
|
1333
|
+
/* @__PURE__ */ jsx(ServerDataProvider, { children: /* @__PURE__ */ jsx(ClientRouter, { components: props.components }) })
|
|
1334
|
+
] });
|
|
1335
|
+
};
|
|
1336
|
+
const Root = (props) => {
|
|
1337
|
+
const { title, meta = [], link = [] } = props.head;
|
|
1338
|
+
return /* @__PURE__ */ jsxs("html", { children: [
|
|
1339
|
+
/* @__PURE__ */ jsxs("head", { children: [
|
|
1340
|
+
props.styles.map((style) => {
|
|
1341
|
+
return /* @__PURE__ */ jsx("link", { rel: "stylesheet", href: `/${style}` }, style);
|
|
1342
|
+
}),
|
|
1343
|
+
/* @__PURE__ */ jsx("title", { children: title }),
|
|
1344
|
+
meta.map((meta2, i) => {
|
|
1345
|
+
return /* @__PURE__ */ jsx("meta", { ...meta2 }, i);
|
|
1346
|
+
}),
|
|
1347
|
+
link.map((link2, i) => {
|
|
1348
|
+
return /* @__PURE__ */ jsx("link", { ...link2 }, i);
|
|
1349
|
+
})
|
|
1350
|
+
] }),
|
|
1351
|
+
/* @__PURE__ */ jsx("body", { children: /* @__PURE__ */ jsx("div", { id: "root", children: /* @__PURE__ */ jsx(ServerDataProvider, { value: props.data, children: /* @__PURE__ */ jsx(ClientRouter, { components: globalThis.components }) }) }) })
|
|
1352
|
+
] });
|
|
1353
|
+
};
|
|
1354
|
+
function useUser() {
|
|
1355
|
+
const { auth } = useContext(ServerDataContext);
|
|
1356
|
+
const [user, setUser] = useState((auth == null ? void 0 : auth.user) ?? {});
|
|
1357
|
+
useEffect(() => {
|
|
1358
|
+
if (auth == null ? void 0 : auth.user) {
|
|
1359
|
+
setUser(auth == null ? void 0 : auth.user);
|
|
1360
|
+
}
|
|
1361
|
+
}, [auth == null ? void 0 : auth.user]);
|
|
1362
|
+
return user;
|
|
1363
|
+
}
|
|
1364
|
+
function useQuery(url) {
|
|
1365
|
+
const [data, setData] = useState(null);
|
|
1366
|
+
const [loading, setLoading] = useState(true);
|
|
1367
|
+
const [error, setError] = useState(null);
|
|
1368
|
+
useEffect(() => {
|
|
1369
|
+
}, [url]);
|
|
1370
|
+
return { data, loading, error };
|
|
1371
|
+
}
|
|
1372
|
+
function useMutation(url, options = { method: "POST" }) {
|
|
1373
|
+
const { method } = options;
|
|
1374
|
+
const [isPending, setIsPending] = useState(false);
|
|
1375
|
+
const [data, setData] = useState(null);
|
|
1376
|
+
return {
|
|
1377
|
+
data,
|
|
1378
|
+
isPending,
|
|
1379
|
+
trigger: async (args) => {
|
|
1380
|
+
setIsPending(true);
|
|
1381
|
+
const response = await fetch(`/api${url}`, {
|
|
1382
|
+
method,
|
|
1383
|
+
headers: {
|
|
1384
|
+
"Content-Type": "application/json"
|
|
1385
|
+
},
|
|
1386
|
+
...args ? { body: JSON.stringify(args) } : {}
|
|
1387
|
+
});
|
|
1388
|
+
const data2 = await response.json();
|
|
1389
|
+
setData(data2);
|
|
1390
|
+
setIsPending(false);
|
|
1391
|
+
return data2;
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
class InputSubject {
|
|
1396
|
+
constructor(initialValue, type, autoFocus = false, validateFn) {
|
|
1397
|
+
__publicField(this, "type");
|
|
1398
|
+
__publicField(this, "state", {
|
|
1399
|
+
isDirty: false,
|
|
1400
|
+
value: null,
|
|
1401
|
+
error: null,
|
|
1402
|
+
isFocused: false,
|
|
1403
|
+
isTouched: false,
|
|
1404
|
+
isInvalid: false
|
|
1405
|
+
});
|
|
1406
|
+
__publicField(this, "subscribers", /* @__PURE__ */ new Set());
|
|
1407
|
+
__publicField(this, "validateFn");
|
|
1408
|
+
__publicField(this, "subscribe", (fn) => {
|
|
1409
|
+
this.subscribers.add(fn);
|
|
1410
|
+
return () => {
|
|
1411
|
+
this.subscribers.delete(fn);
|
|
1412
|
+
};
|
|
1413
|
+
});
|
|
1414
|
+
__publicField(this, "getState", () => {
|
|
1415
|
+
return this.state;
|
|
1416
|
+
});
|
|
1417
|
+
__publicField(this, "next", (state) => {
|
|
1418
|
+
this.state = {
|
|
1419
|
+
...this.state,
|
|
1420
|
+
...state,
|
|
1421
|
+
isInvalid: !!state.error
|
|
1422
|
+
};
|
|
1423
|
+
this.subscribers.forEach((subscriber) => {
|
|
1424
|
+
subscriber(this.state);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
this.state.isFocused = autoFocus;
|
|
1428
|
+
this.state.value = initialValue;
|
|
1429
|
+
this.validateFn = validateFn ?? (() => null);
|
|
1430
|
+
this.type = type;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
const FormContext = createContext({});
|
|
1434
|
+
const inputTypeInitialValueMap = {
|
|
1435
|
+
text: "",
|
|
1436
|
+
number: 0,
|
|
1437
|
+
checkbox: false,
|
|
1438
|
+
email: "",
|
|
1439
|
+
password: ""
|
|
1440
|
+
};
|
|
1441
|
+
function Form(props) {
|
|
1442
|
+
const { onSubmit, schema, ...rest } = props;
|
|
1443
|
+
const inputSubjectsRef = useRef(/* @__PURE__ */ new Map());
|
|
1444
|
+
const getInputValueSubject = (props2) => {
|
|
1445
|
+
if (!inputSubjectsRef.current.has(props2.name)) {
|
|
1446
|
+
const initialValue = props2.value ?? props2.defaultValue ?? (inputTypeInitialValueMap == null ? void 0 : inputTypeInitialValueMap[props2.type]) ?? "";
|
|
1447
|
+
inputSubjectsRef.current.set(
|
|
1448
|
+
props2.name,
|
|
1449
|
+
new InputSubject(
|
|
1450
|
+
initialValue,
|
|
1451
|
+
props2.type ?? "text",
|
|
1452
|
+
props2.autoFocus,
|
|
1453
|
+
props2.validate
|
|
1454
|
+
)
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
return inputSubjectsRef.current.get(props2.name);
|
|
1458
|
+
};
|
|
1459
|
+
const getInputValueSubjectByName = (name) => {
|
|
1460
|
+
return inputSubjectsRef.current.get(name);
|
|
1461
|
+
};
|
|
1462
|
+
const validateSingleField = (name, value) => {
|
|
1463
|
+
let values = {};
|
|
1464
|
+
for (const [name2, inputSubject2] of inputSubjectsRef.current.entries()) {
|
|
1465
|
+
const { value: value2 } = inputSubject2.getState();
|
|
1466
|
+
values[name2] = value2;
|
|
1467
|
+
}
|
|
1468
|
+
values[name] = value;
|
|
1469
|
+
const inputSubject = inputSubjectsRef.current.get(name);
|
|
1470
|
+
if (inputSubject) {
|
|
1471
|
+
const error = inputSubject.validateFn(value);
|
|
1472
|
+
if (error) {
|
|
1473
|
+
return error;
|
|
1474
|
+
}
|
|
1475
|
+
if (schema) {
|
|
1476
|
+
const result = schema.safeParse(values);
|
|
1477
|
+
if (!result.success) {
|
|
1478
|
+
for (let schemaError of result.error.errors) {
|
|
1479
|
+
if (schemaError.path[0] === name) {
|
|
1480
|
+
return schemaError.message;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return null;
|
|
1487
|
+
};
|
|
1488
|
+
const beforeSubmit = () => {
|
|
1489
|
+
let values = {};
|
|
1490
|
+
let errors = {};
|
|
1491
|
+
for (const [name, inputSubject] of inputSubjectsRef.current.entries()) {
|
|
1492
|
+
const { value } = inputSubject.getState();
|
|
1493
|
+
const error = inputSubject.validateFn(values[name]);
|
|
1494
|
+
values[name] = value;
|
|
1495
|
+
errors[name] = error;
|
|
1496
|
+
}
|
|
1497
|
+
if (schema) {
|
|
1498
|
+
const result = schema.safeParse(values);
|
|
1499
|
+
if (!result.success) {
|
|
1500
|
+
result.error.errors.reverse().forEach((schemaError) => {
|
|
1501
|
+
errors[String(schemaError.path[0])] = schemaError.message;
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
for (const [name, inputSubject] of inputSubjectsRef.current.entries()) {
|
|
1506
|
+
const error = errors[name] ? errors[name] : null;
|
|
1507
|
+
inputSubject == null ? void 0 : inputSubject.next({ error, isTouched: true });
|
|
1508
|
+
}
|
|
1509
|
+
return {
|
|
1510
|
+
errors,
|
|
1511
|
+
values
|
|
1512
|
+
};
|
|
1513
|
+
};
|
|
1514
|
+
const reset = () => {
|
|
1515
|
+
for (const [, inputSubject] of inputSubjectsRef.current.entries()) {
|
|
1516
|
+
inputSubject.next({
|
|
1517
|
+
error: null,
|
|
1518
|
+
isDirty: false,
|
|
1519
|
+
isTouched: false,
|
|
1520
|
+
isInvalid: false,
|
|
1521
|
+
value: (inputTypeInitialValueMap == null ? void 0 : inputTypeInitialValueMap[inputSubject.type]) ?? ""
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
return /* @__PURE__ */ jsx(
|
|
1526
|
+
FormContext.Provider,
|
|
1527
|
+
{
|
|
1528
|
+
value: {
|
|
1529
|
+
getInputValueSubject,
|
|
1530
|
+
getInputValueSubjectByName,
|
|
1531
|
+
validateSingleField
|
|
1532
|
+
},
|
|
1533
|
+
children: /* @__PURE__ */ jsx(
|
|
1534
|
+
"form",
|
|
1535
|
+
{
|
|
1536
|
+
...rest,
|
|
1537
|
+
onSubmit: (e) => {
|
|
1538
|
+
e.preventDefault();
|
|
1539
|
+
const { errors, values } = beforeSubmit();
|
|
1540
|
+
const hasErrors = Object.values(errors).some((error) => error);
|
|
1541
|
+
if (!hasErrors) {
|
|
1542
|
+
onSubmit(e, { values, reset });
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
)
|
|
1547
|
+
}
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
const MutationContext = createContext({
|
|
1551
|
+
isPending: false,
|
|
1552
|
+
result: null
|
|
1553
|
+
});
|
|
1554
|
+
const Mutation = (props) => {
|
|
1555
|
+
const [isPending, setIsPending] = useState(false);
|
|
1556
|
+
const formRef = useRef(null);
|
|
1557
|
+
const [result, setResult] = useState(null);
|
|
1558
|
+
const [formError, setFormError] = useState(null);
|
|
1559
|
+
const [validationErrors, setValidationErrors] = useState({});
|
|
1560
|
+
const action = async (e) => {
|
|
1561
|
+
e.preventDefault();
|
|
1562
|
+
const formData = new FormData(formRef.current);
|
|
1563
|
+
setIsPending(true);
|
|
1564
|
+
setResult(null);
|
|
1565
|
+
try {
|
|
1566
|
+
const res = await fetch(`/api${props.url}`, {
|
|
1567
|
+
method: "POST",
|
|
1568
|
+
body: formData
|
|
1569
|
+
});
|
|
1570
|
+
const data = await res.json();
|
|
1571
|
+
if (!res.ok) {
|
|
1572
|
+
if ("error" in data) {
|
|
1573
|
+
if (data.error.kind === "validation_error") {
|
|
1574
|
+
setValidationErrors(data.error.messages);
|
|
1575
|
+
}
|
|
1576
|
+
if (data.error.kind === "form_error") {
|
|
1577
|
+
console.log(data.error.message);
|
|
1578
|
+
setFormError(data.error.message);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
} else {
|
|
1582
|
+
if (props.onSuccess) {
|
|
1583
|
+
props.onSuccess(data);
|
|
1584
|
+
}
|
|
1585
|
+
setResult(data);
|
|
1586
|
+
}
|
|
1587
|
+
} catch (err) {
|
|
1588
|
+
console.log(err);
|
|
1589
|
+
}
|
|
1590
|
+
setIsPending(false);
|
|
1591
|
+
};
|
|
1592
|
+
return /* @__PURE__ */ jsx(
|
|
1593
|
+
MutationContext.Provider,
|
|
1594
|
+
{
|
|
1595
|
+
value: { isPending, result, validationErrors, formError },
|
|
1596
|
+
children: /* @__PURE__ */ jsx("form", { ref: formRef, onSubmit: action, children: props.children })
|
|
1597
|
+
}
|
|
1598
|
+
);
|
|
1599
|
+
};
|
|
1600
|
+
function useMutationStatus() {
|
|
1601
|
+
const { isPending } = useContext(MutationContext);
|
|
1602
|
+
return { isPending };
|
|
1603
|
+
}
|
|
1604
|
+
const ValidationErrors = (props) => {
|
|
1605
|
+
var _a3;
|
|
1606
|
+
const {
|
|
1607
|
+
render = (props2) => /* @__PURE__ */ jsx("div", { ...props2 }),
|
|
1608
|
+
name
|
|
1609
|
+
} = props;
|
|
1610
|
+
const { validationErrors } = useContext(MutationContext);
|
|
1611
|
+
const Comp = render;
|
|
1612
|
+
if (((_a3 = validationErrors[name]) == null ? void 0 : _a3.length) > 0) {
|
|
1613
|
+
return /* @__PURE__ */ jsx(Fragment, { children: validationErrors[name].map((error) => {
|
|
1614
|
+
return /* @__PURE__ */ jsx(Comp, { className: props.className, children: error }, error);
|
|
1615
|
+
}) });
|
|
1616
|
+
}
|
|
1617
|
+
return null;
|
|
1618
|
+
};
|
|
1619
|
+
const FormError = (props) => {
|
|
1620
|
+
const { formError } = useContext(MutationContext);
|
|
1621
|
+
if (formError) {
|
|
1622
|
+
return /* @__PURE__ */ jsx("div", { ...props, children: formError });
|
|
1623
|
+
}
|
|
1624
|
+
return null;
|
|
1625
|
+
};
|
|
1626
|
+
export {
|
|
1627
|
+
Form,
|
|
1628
|
+
FormError,
|
|
1629
|
+
Link,
|
|
1630
|
+
Main,
|
|
1631
|
+
Mutation,
|
|
1632
|
+
Root,
|
|
1633
|
+
ValidationErrors,
|
|
1634
|
+
useLocation,
|
|
1635
|
+
useMutation,
|
|
1636
|
+
useMutationStatus,
|
|
1637
|
+
useParams,
|
|
1638
|
+
useQuery,
|
|
1639
|
+
useRouter,
|
|
1640
|
+
useUser
|
|
1641
|
+
};
|