@inertiajs/core 2.2.19 → 2.2.21
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.esm.js +613 -499
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +818 -704
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/types/domUtils.d.ts +1 -0
- package/types/index.d.ts +1 -1
- package/types/page.d.ts +4 -0
- package/types/prefetched.d.ts +3 -1
- package/types/requestParams.d.ts +1 -0
- package/types/response.d.ts +1 -0
- package/types/router.d.ts +8 -0
- package/types/types.d.ts +9 -2
package/dist/index.esm.js
CHANGED
|
@@ -38,7 +38,8 @@ var config = new Config({
|
|
|
38
38
|
future: {
|
|
39
39
|
preserveEqualProps: false,
|
|
40
40
|
useDataInertiaHeadAttribute: false,
|
|
41
|
-
useDialogForErrorModal: false
|
|
41
|
+
useDialogForErrorModal: false,
|
|
42
|
+
useScriptElementForInitialPage: false
|
|
42
43
|
},
|
|
43
44
|
prefetch: {
|
|
44
45
|
cacheFor: 3e4,
|
|
@@ -97,7 +98,7 @@ var firePrefetchingEvent = (visit) => {
|
|
|
97
98
|
};
|
|
98
99
|
|
|
99
100
|
// src/history.ts
|
|
100
|
-
import { cloneDeep, isEqual } from "lodash-es";
|
|
101
|
+
import { cloneDeep as cloneDeep2, isEqual } from "lodash-es";
|
|
101
102
|
|
|
102
103
|
// src/sessionStorage.ts
|
|
103
104
|
var SessionStorage = class {
|
|
@@ -268,6 +269,308 @@ var getKeyFromSessionStorage = async () => {
|
|
|
268
269
|
return key;
|
|
269
270
|
};
|
|
270
271
|
|
|
272
|
+
// src/prefetched.ts
|
|
273
|
+
import { cloneDeep } from "lodash-es";
|
|
274
|
+
|
|
275
|
+
// src/objectUtils.ts
|
|
276
|
+
var objectsAreEqual = (obj1, obj2, excludeKeys) => {
|
|
277
|
+
if (obj1 === obj2) {
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
for (const key in obj1) {
|
|
281
|
+
if (excludeKeys.includes(key)) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (obj1[key] === obj2[key]) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (!compareValues(obj1[key], obj2[key])) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
for (const key in obj2) {
|
|
292
|
+
if (excludeKeys.includes(key)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (!(key in obj1)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return true;
|
|
300
|
+
};
|
|
301
|
+
var compareValues = (value1, value2) => {
|
|
302
|
+
switch (typeof value1) {
|
|
303
|
+
case "object":
|
|
304
|
+
return objectsAreEqual(value1, value2, []);
|
|
305
|
+
case "function":
|
|
306
|
+
return value1.toString() === value2.toString();
|
|
307
|
+
default:
|
|
308
|
+
return value1 === value2;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/time.ts
|
|
313
|
+
var conversionMap = {
|
|
314
|
+
ms: 1,
|
|
315
|
+
s: 1e3,
|
|
316
|
+
m: 1e3 * 60,
|
|
317
|
+
h: 1e3 * 60 * 60,
|
|
318
|
+
d: 1e3 * 60 * 60 * 24
|
|
319
|
+
};
|
|
320
|
+
var timeToMs = (time) => {
|
|
321
|
+
if (typeof time === "number") {
|
|
322
|
+
return time;
|
|
323
|
+
}
|
|
324
|
+
for (const [unit, conversion] of Object.entries(conversionMap)) {
|
|
325
|
+
if (time.endsWith(unit)) {
|
|
326
|
+
return parseFloat(time) * conversion;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return parseInt(time);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/prefetched.ts
|
|
333
|
+
var PrefetchedRequests = class {
|
|
334
|
+
constructor() {
|
|
335
|
+
this.cached = [];
|
|
336
|
+
this.inFlightRequests = [];
|
|
337
|
+
this.removalTimers = [];
|
|
338
|
+
this.currentUseId = null;
|
|
339
|
+
}
|
|
340
|
+
add(params, sendFunc, { cacheFor, cacheTags }) {
|
|
341
|
+
const inFlight = this.findInFlight(params);
|
|
342
|
+
if (inFlight) {
|
|
343
|
+
return Promise.resolve();
|
|
344
|
+
}
|
|
345
|
+
const existing = this.findCached(params);
|
|
346
|
+
if (!params.fresh && existing && existing.staleTimestamp > Date.now()) {
|
|
347
|
+
return Promise.resolve();
|
|
348
|
+
}
|
|
349
|
+
const [stale, prefetchExpiresIn] = this.extractStaleValues(cacheFor);
|
|
350
|
+
const promise = new Promise((resolve, reject) => {
|
|
351
|
+
sendFunc({
|
|
352
|
+
...params,
|
|
353
|
+
onCancel: () => {
|
|
354
|
+
this.remove(params);
|
|
355
|
+
params.onCancel();
|
|
356
|
+
reject();
|
|
357
|
+
},
|
|
358
|
+
onError: (error) => {
|
|
359
|
+
this.remove(params);
|
|
360
|
+
params.onError(error);
|
|
361
|
+
reject();
|
|
362
|
+
},
|
|
363
|
+
onPrefetching(visitParams) {
|
|
364
|
+
params.onPrefetching(visitParams);
|
|
365
|
+
},
|
|
366
|
+
onPrefetched(response, visit) {
|
|
367
|
+
params.onPrefetched(response, visit);
|
|
368
|
+
},
|
|
369
|
+
onPrefetchResponse(response) {
|
|
370
|
+
resolve(response);
|
|
371
|
+
},
|
|
372
|
+
onPrefetchError(error) {
|
|
373
|
+
prefetchedRequests.removeFromInFlight(params);
|
|
374
|
+
reject(error);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}).then((response) => {
|
|
378
|
+
this.remove(params);
|
|
379
|
+
const pageResponse = response.getPageResponse();
|
|
380
|
+
page.mergeOncePropsIntoResponse(pageResponse);
|
|
381
|
+
this.cached.push({
|
|
382
|
+
params: { ...params },
|
|
383
|
+
staleTimestamp: Date.now() + stale,
|
|
384
|
+
expiresAt: Date.now() + prefetchExpiresIn,
|
|
385
|
+
response: promise,
|
|
386
|
+
singleUse: prefetchExpiresIn === 0,
|
|
387
|
+
timestamp: Date.now(),
|
|
388
|
+
inFlight: false,
|
|
389
|
+
tags: Array.isArray(cacheTags) ? cacheTags : [cacheTags]
|
|
390
|
+
});
|
|
391
|
+
const oncePropExpiresIn = this.getShortestOncePropTtl(pageResponse);
|
|
392
|
+
this.scheduleForRemoval(
|
|
393
|
+
params,
|
|
394
|
+
oncePropExpiresIn ? Math.min(prefetchExpiresIn, oncePropExpiresIn) : prefetchExpiresIn
|
|
395
|
+
);
|
|
396
|
+
this.removeFromInFlight(params);
|
|
397
|
+
response.handlePrefetch();
|
|
398
|
+
return response;
|
|
399
|
+
});
|
|
400
|
+
this.inFlightRequests.push({
|
|
401
|
+
params: { ...params },
|
|
402
|
+
response: promise,
|
|
403
|
+
staleTimestamp: null,
|
|
404
|
+
inFlight: true
|
|
405
|
+
});
|
|
406
|
+
return promise;
|
|
407
|
+
}
|
|
408
|
+
removeAll() {
|
|
409
|
+
this.cached = [];
|
|
410
|
+
this.removalTimers.forEach((removalTimer) => {
|
|
411
|
+
clearTimeout(removalTimer.timer);
|
|
412
|
+
});
|
|
413
|
+
this.removalTimers = [];
|
|
414
|
+
}
|
|
415
|
+
removeByTags(tags) {
|
|
416
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
417
|
+
return !prefetched.tags.some((tag) => tags.includes(tag));
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
remove(params) {
|
|
421
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
422
|
+
return !this.paramsAreEqual(prefetched.params, params);
|
|
423
|
+
});
|
|
424
|
+
this.clearTimer(params);
|
|
425
|
+
}
|
|
426
|
+
removeFromInFlight(params) {
|
|
427
|
+
this.inFlightRequests = this.inFlightRequests.filter((prefetching) => {
|
|
428
|
+
return !this.paramsAreEqual(prefetching.params, params);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
extractStaleValues(cacheFor) {
|
|
432
|
+
const [stale, expires] = this.cacheForToStaleAndExpires(cacheFor);
|
|
433
|
+
return [timeToMs(stale), timeToMs(expires)];
|
|
434
|
+
}
|
|
435
|
+
cacheForToStaleAndExpires(cacheFor) {
|
|
436
|
+
if (!Array.isArray(cacheFor)) {
|
|
437
|
+
return [cacheFor, cacheFor];
|
|
438
|
+
}
|
|
439
|
+
switch (cacheFor.length) {
|
|
440
|
+
case 0:
|
|
441
|
+
return [0, 0];
|
|
442
|
+
case 1:
|
|
443
|
+
return [cacheFor[0], cacheFor[0]];
|
|
444
|
+
default:
|
|
445
|
+
return [cacheFor[0], cacheFor[1]];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
clearTimer(params) {
|
|
449
|
+
const timer = this.removalTimers.find((removalTimer) => {
|
|
450
|
+
return this.paramsAreEqual(removalTimer.params, params);
|
|
451
|
+
});
|
|
452
|
+
if (timer) {
|
|
453
|
+
clearTimeout(timer.timer);
|
|
454
|
+
this.removalTimers = this.removalTimers.filter((removalTimer) => removalTimer !== timer);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
scheduleForRemoval(params, expiresIn) {
|
|
458
|
+
if (typeof window === "undefined") {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
this.clearTimer(params);
|
|
462
|
+
if (expiresIn > 0) {
|
|
463
|
+
const timer = window.setTimeout(() => this.remove(params), expiresIn);
|
|
464
|
+
this.removalTimers.push({
|
|
465
|
+
params,
|
|
466
|
+
timer
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
get(params) {
|
|
471
|
+
return this.findCached(params) || this.findInFlight(params);
|
|
472
|
+
}
|
|
473
|
+
use(prefetched, params) {
|
|
474
|
+
const id = `${params.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
475
|
+
this.currentUseId = id;
|
|
476
|
+
return prefetched.response.then((response) => {
|
|
477
|
+
if (this.currentUseId !== id) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
response.mergeParams({ ...params, onPrefetched: () => {
|
|
481
|
+
} });
|
|
482
|
+
this.removeSingleUseItems(params);
|
|
483
|
+
return response.handle();
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
removeSingleUseItems(params) {
|
|
487
|
+
this.cached = this.cached.filter((prefetched) => {
|
|
488
|
+
if (!this.paramsAreEqual(prefetched.params, params)) {
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
return !prefetched.singleUse;
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
findCached(params) {
|
|
495
|
+
return this.cached.find((prefetched) => {
|
|
496
|
+
return this.paramsAreEqual(prefetched.params, params);
|
|
497
|
+
}) || null;
|
|
498
|
+
}
|
|
499
|
+
findInFlight(params) {
|
|
500
|
+
return this.inFlightRequests.find((prefetched) => {
|
|
501
|
+
return this.paramsAreEqual(prefetched.params, params);
|
|
502
|
+
}) || null;
|
|
503
|
+
}
|
|
504
|
+
withoutPurposePrefetchHeader(params) {
|
|
505
|
+
const newParams = cloneDeep(params);
|
|
506
|
+
if (newParams.headers["Purpose"] === "prefetch") {
|
|
507
|
+
delete newParams.headers["Purpose"];
|
|
508
|
+
}
|
|
509
|
+
return newParams;
|
|
510
|
+
}
|
|
511
|
+
paramsAreEqual(params1, params2) {
|
|
512
|
+
return objectsAreEqual(
|
|
513
|
+
this.withoutPurposePrefetchHeader(params1),
|
|
514
|
+
this.withoutPurposePrefetchHeader(params2),
|
|
515
|
+
[
|
|
516
|
+
"showProgress",
|
|
517
|
+
"replace",
|
|
518
|
+
"prefetch",
|
|
519
|
+
"preserveScroll",
|
|
520
|
+
"preserveState",
|
|
521
|
+
"onBefore",
|
|
522
|
+
"onBeforeUpdate",
|
|
523
|
+
"onStart",
|
|
524
|
+
"onProgress",
|
|
525
|
+
"onFinish",
|
|
526
|
+
"onCancel",
|
|
527
|
+
"onSuccess",
|
|
528
|
+
"onError",
|
|
529
|
+
"onPrefetched",
|
|
530
|
+
"onCancelToken",
|
|
531
|
+
"onPrefetching",
|
|
532
|
+
"async",
|
|
533
|
+
"viewTransition"
|
|
534
|
+
]
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
updateCachedOncePropsFromCurrentPage() {
|
|
538
|
+
this.cached.forEach((prefetched) => {
|
|
539
|
+
prefetched.response.then((response) => {
|
|
540
|
+
const pageResponse = response.getPageResponse();
|
|
541
|
+
page.mergeOncePropsIntoResponse(pageResponse, { force: true });
|
|
542
|
+
for (const [group, deferredProps] of Object.entries(pageResponse.deferredProps ?? {})) {
|
|
543
|
+
const remaining = deferredProps.filter((prop) => pageResponse.props[prop] === void 0);
|
|
544
|
+
if (remaining.length > 0) {
|
|
545
|
+
pageResponse.deferredProps[group] = remaining;
|
|
546
|
+
} else {
|
|
547
|
+
delete pageResponse.deferredProps[group];
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const oncePropExpiresIn = this.getShortestOncePropTtl(pageResponse);
|
|
551
|
+
if (oncePropExpiresIn === null) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const prefetchExpiresIn = prefetched.expiresAt - Date.now();
|
|
555
|
+
const expiresIn = Math.min(prefetchExpiresIn, oncePropExpiresIn);
|
|
556
|
+
if (expiresIn > 0) {
|
|
557
|
+
this.scheduleForRemoval(prefetched.params, expiresIn);
|
|
558
|
+
} else {
|
|
559
|
+
this.remove(prefetched.params);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
getShortestOncePropTtl(page2) {
|
|
565
|
+
const expiryTimestamps = Object.values(page2.onceProps ?? {}).map((onceProp) => onceProp.expiresAt).filter((expiresAt) => !!expiresAt);
|
|
566
|
+
if (expiryTimestamps.length === 0) {
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
return Math.min(...expiryTimestamps) - Date.now();
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var prefetchedRequests = new PrefetchedRequests();
|
|
573
|
+
|
|
271
574
|
// src/scroll.ts
|
|
272
575
|
var Scroll = class {
|
|
273
576
|
static save() {
|
|
@@ -526,6 +829,9 @@ var CurrentPage = class {
|
|
|
526
829
|
}
|
|
527
830
|
this.page = page2;
|
|
528
831
|
this.cleared = false;
|
|
832
|
+
if (this.hasOnceProps()) {
|
|
833
|
+
prefetchedRequests.updateCachedOncePropsFromCurrentPage();
|
|
834
|
+
}
|
|
529
835
|
if (isNewComponent) {
|
|
530
836
|
this.fireEventsFor("newComponent");
|
|
531
837
|
}
|
|
@@ -574,6 +880,9 @@ var CurrentPage = class {
|
|
|
574
880
|
get() {
|
|
575
881
|
return this.page;
|
|
576
882
|
}
|
|
883
|
+
hasOnceProps() {
|
|
884
|
+
return Object.keys(this.page.onceProps ?? {}).length > 0;
|
|
885
|
+
}
|
|
577
886
|
merge(data) {
|
|
578
887
|
this.page = { ...this.page, ...data };
|
|
579
888
|
}
|
|
@@ -616,6 +925,18 @@ var CurrentPage = class {
|
|
|
616
925
|
fireEventsFor(event) {
|
|
617
926
|
this.listeners.filter((listener) => listener.event === event).forEach((listener) => listener.callback());
|
|
618
927
|
}
|
|
928
|
+
mergeOncePropsIntoResponse(response, { force = false } = {}) {
|
|
929
|
+
Object.entries(response.onceProps ?? {}).forEach(([key, onceProp]) => {
|
|
930
|
+
const existingOnceProp = this.page.onceProps?.[key];
|
|
931
|
+
if (existingOnceProp === void 0) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
if (force || response.props[onceProp.prop] === void 0) {
|
|
935
|
+
response.props[onceProp.prop] = this.page.props[existingOnceProp.prop];
|
|
936
|
+
response.onceProps[key].expiresAt = existingOnceProp.expiresAt;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
}
|
|
619
940
|
};
|
|
620
941
|
var page = new CurrentPage();
|
|
621
942
|
|
|
@@ -699,7 +1020,7 @@ var History = class {
|
|
|
699
1020
|
} catch {
|
|
700
1021
|
return {
|
|
701
1022
|
...page2,
|
|
702
|
-
props:
|
|
1023
|
+
props: cloneDeep2(page2.props)
|
|
703
1024
|
};
|
|
704
1025
|
}
|
|
705
1026
|
}
|
|
@@ -806,546 +1127,285 @@ var History = class {
|
|
|
806
1127
|
);
|
|
807
1128
|
}
|
|
808
1129
|
doPushState(data, url) {
|
|
809
|
-
return Promise.resolve().then(() => window.history.pushState(data, "", url));
|
|
810
|
-
}
|
|
811
|
-
getState(key, defaultValue) {
|
|
812
|
-
return this.current?.[key] ?? defaultValue;
|
|
813
|
-
}
|
|
814
|
-
deleteState(key) {
|
|
815
|
-
if (this.current[key] !== void 0) {
|
|
816
|
-
delete this.current[key];
|
|
817
|
-
this.replaceState(this.current);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
clearInitialState(key) {
|
|
821
|
-
if (this.initialState && this.initialState[key] !== void 0) {
|
|
822
|
-
delete this.initialState[key];
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
hasAnyState() {
|
|
826
|
-
return !!this.getAllState();
|
|
827
|
-
}
|
|
828
|
-
clear() {
|
|
829
|
-
SessionStorage.remove(historySessionStorageKeys.key);
|
|
830
|
-
SessionStorage.remove(historySessionStorageKeys.iv);
|
|
831
|
-
}
|
|
832
|
-
setCurrent(page2) {
|
|
833
|
-
this.current = page2;
|
|
834
|
-
}
|
|
835
|
-
isValidState(state) {
|
|
836
|
-
return !!state.page;
|
|
837
|
-
}
|
|
838
|
-
getAllState() {
|
|
839
|
-
return this.current;
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
if (typeof window !== "undefined" && window.history.scrollRestoration) {
|
|
843
|
-
window.history.scrollRestoration = "manual";
|
|
844
|
-
}
|
|
845
|
-
var history = new History();
|
|
846
|
-
|
|
847
|
-
// src/eventHandler.ts
|
|
848
|
-
var EventHandler = class {
|
|
849
|
-
constructor() {
|
|
850
|
-
this.internalListeners = [];
|
|
851
|
-
}
|
|
852
|
-
init() {
|
|
853
|
-
if (typeof window !== "undefined") {
|
|
854
|
-
window.addEventListener("popstate", this.handlePopstateEvent.bind(this));
|
|
855
|
-
window.addEventListener("scroll", debounce(Scroll.onWindowScroll.bind(Scroll), 100), true);
|
|
856
|
-
}
|
|
857
|
-
if (typeof document !== "undefined") {
|
|
858
|
-
document.addEventListener("scroll", debounce(Scroll.onScroll.bind(Scroll), 100), true);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
onGlobalEvent(type, callback) {
|
|
862
|
-
const listener = ((event) => {
|
|
863
|
-
const response = callback(event);
|
|
864
|
-
if (event.cancelable && !event.defaultPrevented && response === false) {
|
|
865
|
-
event.preventDefault();
|
|
866
|
-
}
|
|
867
|
-
});
|
|
868
|
-
return this.registerListener(`inertia:${type}`, listener);
|
|
869
|
-
}
|
|
870
|
-
on(event, callback) {
|
|
871
|
-
this.internalListeners.push({ event, listener: callback });
|
|
872
|
-
return () => {
|
|
873
|
-
this.internalListeners = this.internalListeners.filter((listener) => listener.listener !== callback);
|
|
874
|
-
};
|
|
875
|
-
}
|
|
876
|
-
onMissingHistoryItem() {
|
|
877
|
-
page.clear();
|
|
878
|
-
this.fireInternalEvent("missingHistoryItem");
|
|
879
|
-
}
|
|
880
|
-
fireInternalEvent(event, ...args) {
|
|
881
|
-
this.internalListeners.filter((listener) => listener.event === event).forEach((listener) => listener.listener(...args));
|
|
882
|
-
}
|
|
883
|
-
registerListener(type, listener) {
|
|
884
|
-
document.addEventListener(type, listener);
|
|
885
|
-
return () => document.removeEventListener(type, listener);
|
|
886
|
-
}
|
|
887
|
-
handlePopstateEvent(event) {
|
|
888
|
-
const state = event.state || null;
|
|
889
|
-
if (state === null) {
|
|
890
|
-
const url = hrefToUrl(page.get().url);
|
|
891
|
-
url.hash = window.location.hash;
|
|
892
|
-
history.replaceState({ ...page.get(), url: url.href });
|
|
893
|
-
Scroll.reset();
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
if (!history.isValidState(state)) {
|
|
897
|
-
return this.onMissingHistoryItem();
|
|
898
|
-
}
|
|
899
|
-
history.decrypt(state.page).then((data) => {
|
|
900
|
-
if (page.get().version !== data.version) {
|
|
901
|
-
this.onMissingHistoryItem();
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
router.cancelAll();
|
|
905
|
-
page.setQuietly(data, { preserveState: false }).then(() => {
|
|
906
|
-
Scroll.restore(history.getScrollRegions());
|
|
907
|
-
fireNavigateEvent(page.get());
|
|
908
|
-
});
|
|
909
|
-
}).catch(() => {
|
|
910
|
-
this.onMissingHistoryItem();
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
var eventHandler = new EventHandler();
|
|
915
|
-
|
|
916
|
-
// src/navigationType.ts
|
|
917
|
-
var NavigationType = class {
|
|
918
|
-
constructor() {
|
|
919
|
-
this.type = this.resolveType();
|
|
920
|
-
}
|
|
921
|
-
resolveType() {
|
|
922
|
-
if (typeof window === "undefined") {
|
|
923
|
-
return "navigate";
|
|
924
|
-
}
|
|
925
|
-
if (window.performance && window.performance.getEntriesByType && window.performance.getEntriesByType("navigation").length > 0) {
|
|
926
|
-
return window.performance.getEntriesByType("navigation")[0].type;
|
|
927
|
-
}
|
|
928
|
-
return "navigate";
|
|
929
|
-
}
|
|
930
|
-
get() {
|
|
931
|
-
return this.type;
|
|
932
|
-
}
|
|
933
|
-
isBackForward() {
|
|
934
|
-
return this.type === "back_forward";
|
|
935
|
-
}
|
|
936
|
-
isReload() {
|
|
937
|
-
return this.type === "reload";
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
var navigationType = new NavigationType();
|
|
941
|
-
|
|
942
|
-
// src/initialVisit.ts
|
|
943
|
-
var InitialVisit = class {
|
|
944
|
-
static handle() {
|
|
945
|
-
this.clearRememberedStateOnReload();
|
|
946
|
-
const scenarios = [this.handleBackForward, this.handleLocation, this.handleDefault];
|
|
947
|
-
scenarios.find((handler) => handler.bind(this)());
|
|
948
|
-
}
|
|
949
|
-
static clearRememberedStateOnReload() {
|
|
950
|
-
if (navigationType.isReload()) {
|
|
951
|
-
history.deleteState(history.rememberedState);
|
|
952
|
-
history.clearInitialState(history.rememberedState);
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
static handleBackForward() {
|
|
956
|
-
if (!navigationType.isBackForward() || !history.hasAnyState()) {
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
959
|
-
const scrollRegions = history.getScrollRegions();
|
|
960
|
-
history.decrypt().then((data) => {
|
|
961
|
-
page.set(data, { preserveScroll: true, preserveState: true }).then(() => {
|
|
962
|
-
Scroll.restore(scrollRegions);
|
|
963
|
-
fireNavigateEvent(page.get());
|
|
964
|
-
});
|
|
965
|
-
}).catch(() => {
|
|
966
|
-
eventHandler.onMissingHistoryItem();
|
|
967
|
-
});
|
|
968
|
-
return true;
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* @link https://inertiajs.com/redirects#external-redirects
|
|
972
|
-
*/
|
|
973
|
-
static handleLocation() {
|
|
974
|
-
if (!SessionStorage.exists(SessionStorage.locationVisitKey)) {
|
|
975
|
-
return false;
|
|
976
|
-
}
|
|
977
|
-
const locationVisit = SessionStorage.get(SessionStorage.locationVisitKey) || {};
|
|
978
|
-
SessionStorage.remove(SessionStorage.locationVisitKey);
|
|
979
|
-
if (typeof window !== "undefined") {
|
|
980
|
-
page.setUrlHash(window.location.hash);
|
|
981
|
-
}
|
|
982
|
-
history.decrypt(page.get()).then(() => {
|
|
983
|
-
const rememberedState = history.getState(history.rememberedState, {});
|
|
984
|
-
const scrollRegions = history.getScrollRegions();
|
|
985
|
-
page.remember(rememberedState);
|
|
986
|
-
page.set(page.get(), {
|
|
987
|
-
preserveScroll: locationVisit.preserveScroll,
|
|
988
|
-
preserveState: true
|
|
989
|
-
}).then(() => {
|
|
990
|
-
if (locationVisit.preserveScroll) {
|
|
991
|
-
Scroll.restore(scrollRegions);
|
|
992
|
-
}
|
|
993
|
-
fireNavigateEvent(page.get());
|
|
994
|
-
});
|
|
995
|
-
}).catch(() => {
|
|
996
|
-
eventHandler.onMissingHistoryItem();
|
|
997
|
-
});
|
|
998
|
-
return true;
|
|
999
|
-
}
|
|
1000
|
-
static handleDefault() {
|
|
1001
|
-
if (typeof window !== "undefined") {
|
|
1002
|
-
page.setUrlHash(window.location.hash);
|
|
1003
|
-
}
|
|
1004
|
-
page.set(page.get(), { preserveScroll: true, preserveState: true }).then(() => {
|
|
1005
|
-
if (navigationType.isReload()) {
|
|
1006
|
-
Scroll.restore(history.getScrollRegions());
|
|
1007
|
-
} else {
|
|
1008
|
-
Scroll.scrollToAnchor();
|
|
1009
|
-
}
|
|
1010
|
-
fireNavigateEvent(page.get());
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
};
|
|
1014
|
-
|
|
1015
|
-
// src/poll.ts
|
|
1016
|
-
var Poll = class {
|
|
1017
|
-
constructor(interval, cb, options) {
|
|
1018
|
-
this.id = null;
|
|
1019
|
-
this.throttle = false;
|
|
1020
|
-
this.keepAlive = false;
|
|
1021
|
-
this.cbCount = 0;
|
|
1022
|
-
this.keepAlive = options.keepAlive ?? false;
|
|
1023
|
-
this.cb = cb;
|
|
1024
|
-
this.interval = interval;
|
|
1025
|
-
if (options.autoStart ?? true) {
|
|
1026
|
-
this.start();
|
|
1027
|
-
}
|
|
1130
|
+
return Promise.resolve().then(() => window.history.pushState(data, "", url));
|
|
1028
1131
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
clearInterval(this.id);
|
|
1032
|
-
}
|
|
1132
|
+
getState(key, defaultValue) {
|
|
1133
|
+
return this.current?.[key] ?? defaultValue;
|
|
1033
1134
|
}
|
|
1034
|
-
|
|
1035
|
-
if (
|
|
1036
|
-
|
|
1135
|
+
deleteState(key) {
|
|
1136
|
+
if (this.current[key] !== void 0) {
|
|
1137
|
+
delete this.current[key];
|
|
1138
|
+
this.replaceState(this.current);
|
|
1037
1139
|
}
|
|
1038
|
-
this.stop();
|
|
1039
|
-
this.id = window.setInterval(() => {
|
|
1040
|
-
if (!this.throttle || this.cbCount % 10 === 0) {
|
|
1041
|
-
this.cb();
|
|
1042
|
-
}
|
|
1043
|
-
if (this.throttle) {
|
|
1044
|
-
this.cbCount++;
|
|
1045
|
-
}
|
|
1046
|
-
}, this.interval);
|
|
1047
1140
|
}
|
|
1048
|
-
|
|
1049
|
-
this.
|
|
1050
|
-
|
|
1051
|
-
this.cbCount = 0;
|
|
1141
|
+
clearInitialState(key) {
|
|
1142
|
+
if (this.initialState && this.initialState[key] !== void 0) {
|
|
1143
|
+
delete this.initialState[key];
|
|
1052
1144
|
}
|
|
1053
1145
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
// src/polls.ts
|
|
1057
|
-
var Polls = class {
|
|
1058
|
-
constructor() {
|
|
1059
|
-
this.polls = [];
|
|
1060
|
-
this.setupVisibilityListener();
|
|
1061
|
-
}
|
|
1062
|
-
add(interval, cb, options) {
|
|
1063
|
-
const poll = new Poll(interval, cb, options);
|
|
1064
|
-
this.polls.push(poll);
|
|
1065
|
-
return {
|
|
1066
|
-
stop: () => poll.stop(),
|
|
1067
|
-
start: () => poll.start()
|
|
1068
|
-
};
|
|
1146
|
+
hasAnyState() {
|
|
1147
|
+
return !!this.getAllState();
|
|
1069
1148
|
}
|
|
1070
1149
|
clear() {
|
|
1071
|
-
|
|
1072
|
-
|
|
1150
|
+
SessionStorage.remove(historySessionStorageKeys.key);
|
|
1151
|
+
SessionStorage.remove(historySessionStorageKeys.iv);
|
|
1073
1152
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
},
|
|
1083
|
-
false
|
|
1084
|
-
);
|
|
1153
|
+
setCurrent(page2) {
|
|
1154
|
+
this.current = page2;
|
|
1155
|
+
}
|
|
1156
|
+
isValidState(state) {
|
|
1157
|
+
return !!state.page;
|
|
1158
|
+
}
|
|
1159
|
+
getAllState() {
|
|
1160
|
+
return this.current;
|
|
1085
1161
|
}
|
|
1086
1162
|
};
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1163
|
+
if (typeof window !== "undefined" && window.history.scrollRestoration) {
|
|
1164
|
+
window.history.scrollRestoration = "manual";
|
|
1165
|
+
}
|
|
1166
|
+
var history = new History();
|
|
1091
1167
|
|
|
1092
|
-
// src/
|
|
1093
|
-
var
|
|
1094
|
-
|
|
1095
|
-
|
|
1168
|
+
// src/eventHandler.ts
|
|
1169
|
+
var EventHandler = class {
|
|
1170
|
+
constructor() {
|
|
1171
|
+
this.internalListeners = [];
|
|
1096
1172
|
}
|
|
1097
|
-
|
|
1098
|
-
if (
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
if (obj1[key] === obj2[key]) {
|
|
1102
|
-
continue;
|
|
1173
|
+
init() {
|
|
1174
|
+
if (typeof window !== "undefined") {
|
|
1175
|
+
window.addEventListener("popstate", this.handlePopstateEvent.bind(this));
|
|
1176
|
+
window.addEventListener("scroll", debounce(Scroll.onWindowScroll.bind(Scroll), 100), true);
|
|
1103
1177
|
}
|
|
1104
|
-
if (
|
|
1105
|
-
|
|
1178
|
+
if (typeof document !== "undefined") {
|
|
1179
|
+
document.addEventListener("scroll", debounce(Scroll.onScroll.bind(Scroll), 100), true);
|
|
1106
1180
|
}
|
|
1107
1181
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
}
|
|
1182
|
+
onGlobalEvent(type, callback) {
|
|
1183
|
+
const listener = ((event) => {
|
|
1184
|
+
const response = callback(event);
|
|
1185
|
+
if (event.cancelable && !event.defaultPrevented && response === false) {
|
|
1186
|
+
event.preventDefault();
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
return this.registerListener(`inertia:${type}`, listener);
|
|
1115
1190
|
}
|
|
1116
|
-
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
return objectsAreEqual(value1, value2, []);
|
|
1122
|
-
case "function":
|
|
1123
|
-
return value1.toString() === value2.toString();
|
|
1124
|
-
default:
|
|
1125
|
-
return value1 === value2;
|
|
1191
|
+
on(event, callback) {
|
|
1192
|
+
this.internalListeners.push({ event, listener: callback });
|
|
1193
|
+
return () => {
|
|
1194
|
+
this.internalListeners = this.internalListeners.filter((listener) => listener.listener !== callback);
|
|
1195
|
+
};
|
|
1126
1196
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
var conversionMap = {
|
|
1131
|
-
ms: 1,
|
|
1132
|
-
s: 1e3,
|
|
1133
|
-
m: 1e3 * 60,
|
|
1134
|
-
h: 1e3 * 60 * 60,
|
|
1135
|
-
d: 1e3 * 60 * 60 * 24
|
|
1136
|
-
};
|
|
1137
|
-
var timeToMs = (time) => {
|
|
1138
|
-
if (typeof time === "number") {
|
|
1139
|
-
return time;
|
|
1197
|
+
onMissingHistoryItem() {
|
|
1198
|
+
page.clear();
|
|
1199
|
+
this.fireInternalEvent("missingHistoryItem");
|
|
1140
1200
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1201
|
+
fireInternalEvent(event, ...args) {
|
|
1202
|
+
this.internalListeners.filter((listener) => listener.event === event).forEach((listener) => listener.listener(...args));
|
|
1203
|
+
}
|
|
1204
|
+
registerListener(type, listener) {
|
|
1205
|
+
document.addEventListener(type, listener);
|
|
1206
|
+
return () => document.removeEventListener(type, listener);
|
|
1207
|
+
}
|
|
1208
|
+
handlePopstateEvent(event) {
|
|
1209
|
+
const state = event.state || null;
|
|
1210
|
+
if (state === null) {
|
|
1211
|
+
const url = hrefToUrl(page.get().url);
|
|
1212
|
+
url.hash = window.location.hash;
|
|
1213
|
+
history.replaceState({ ...page.get(), url: url.href });
|
|
1214
|
+
Scroll.reset();
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
if (!history.isValidState(state)) {
|
|
1218
|
+
return this.onMissingHistoryItem();
|
|
1144
1219
|
}
|
|
1220
|
+
history.decrypt(state.page).then((data) => {
|
|
1221
|
+
if (page.get().version !== data.version) {
|
|
1222
|
+
this.onMissingHistoryItem();
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
router.cancelAll();
|
|
1226
|
+
page.setQuietly(data, { preserveState: false }).then(() => {
|
|
1227
|
+
Scroll.restore(history.getScrollRegions());
|
|
1228
|
+
fireNavigateEvent(page.get());
|
|
1229
|
+
});
|
|
1230
|
+
}).catch(() => {
|
|
1231
|
+
this.onMissingHistoryItem();
|
|
1232
|
+
});
|
|
1145
1233
|
}
|
|
1146
|
-
return parseInt(time);
|
|
1147
1234
|
};
|
|
1235
|
+
var eventHandler = new EventHandler();
|
|
1148
1236
|
|
|
1149
|
-
// src/
|
|
1150
|
-
var
|
|
1237
|
+
// src/navigationType.ts
|
|
1238
|
+
var NavigationType = class {
|
|
1151
1239
|
constructor() {
|
|
1152
|
-
this.
|
|
1153
|
-
this.inFlightRequests = [];
|
|
1154
|
-
this.removalTimers = [];
|
|
1155
|
-
this.currentUseId = null;
|
|
1240
|
+
this.type = this.resolveType();
|
|
1156
1241
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
return Promise.resolve();
|
|
1242
|
+
resolveType() {
|
|
1243
|
+
if (typeof window === "undefined") {
|
|
1244
|
+
return "navigate";
|
|
1161
1245
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
return Promise.resolve();
|
|
1246
|
+
if (window.performance && window.performance.getEntriesByType && window.performance.getEntriesByType("navigation").length > 0) {
|
|
1247
|
+
return window.performance.getEntriesByType("navigation")[0].type;
|
|
1165
1248
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
reject();
|
|
1174
|
-
},
|
|
1175
|
-
onError: (error) => {
|
|
1176
|
-
this.remove(params);
|
|
1177
|
-
params.onError(error);
|
|
1178
|
-
reject();
|
|
1179
|
-
},
|
|
1180
|
-
onPrefetching(visitParams) {
|
|
1181
|
-
params.onPrefetching(visitParams);
|
|
1182
|
-
},
|
|
1183
|
-
onPrefetched(response, visit) {
|
|
1184
|
-
params.onPrefetched(response, visit);
|
|
1185
|
-
},
|
|
1186
|
-
onPrefetchResponse(response) {
|
|
1187
|
-
resolve(response);
|
|
1188
|
-
},
|
|
1189
|
-
onPrefetchError(error) {
|
|
1190
|
-
prefetchedRequests.removeFromInFlight(params);
|
|
1191
|
-
reject(error);
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
}).then((response) => {
|
|
1195
|
-
this.remove(params);
|
|
1196
|
-
this.cached.push({
|
|
1197
|
-
params: { ...params },
|
|
1198
|
-
staleTimestamp: Date.now() + stale,
|
|
1199
|
-
response: promise,
|
|
1200
|
-
singleUse: expires === 0,
|
|
1201
|
-
timestamp: Date.now(),
|
|
1202
|
-
inFlight: false,
|
|
1203
|
-
tags: Array.isArray(cacheTags) ? cacheTags : [cacheTags]
|
|
1204
|
-
});
|
|
1205
|
-
this.scheduleForRemoval(params, expires);
|
|
1206
|
-
this.removeFromInFlight(params);
|
|
1207
|
-
response.handlePrefetch();
|
|
1208
|
-
return response;
|
|
1209
|
-
});
|
|
1210
|
-
this.inFlightRequests.push({
|
|
1211
|
-
params: { ...params },
|
|
1212
|
-
response: promise,
|
|
1213
|
-
staleTimestamp: null,
|
|
1214
|
-
inFlight: true
|
|
1215
|
-
});
|
|
1216
|
-
return promise;
|
|
1249
|
+
return "navigate";
|
|
1250
|
+
}
|
|
1251
|
+
get() {
|
|
1252
|
+
return this.type;
|
|
1253
|
+
}
|
|
1254
|
+
isBackForward() {
|
|
1255
|
+
return this.type === "back_forward";
|
|
1217
1256
|
}
|
|
1218
|
-
|
|
1219
|
-
this.
|
|
1220
|
-
this.removalTimers.forEach((removalTimer) => {
|
|
1221
|
-
clearTimeout(removalTimer.timer);
|
|
1222
|
-
});
|
|
1223
|
-
this.removalTimers = [];
|
|
1257
|
+
isReload() {
|
|
1258
|
+
return this.type === "reload";
|
|
1224
1259
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1260
|
+
};
|
|
1261
|
+
var navigationType = new NavigationType();
|
|
1262
|
+
|
|
1263
|
+
// src/initialVisit.ts
|
|
1264
|
+
var InitialVisit = class {
|
|
1265
|
+
static handle() {
|
|
1266
|
+
this.clearRememberedStateOnReload();
|
|
1267
|
+
const scenarios = [this.handleBackForward, this.handleLocation, this.handleDefault];
|
|
1268
|
+
scenarios.find((handler) => handler.bind(this)());
|
|
1229
1269
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1270
|
+
static clearRememberedStateOnReload() {
|
|
1271
|
+
if (navigationType.isReload()) {
|
|
1272
|
+
history.deleteState(history.rememberedState);
|
|
1273
|
+
history.clearInitialState(history.rememberedState);
|
|
1274
|
+
}
|
|
1235
1275
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
return
|
|
1276
|
+
static handleBackForward() {
|
|
1277
|
+
if (!navigationType.isBackForward() || !history.hasAnyState()) {
|
|
1278
|
+
return false;
|
|
1279
|
+
}
|
|
1280
|
+
const scrollRegions = history.getScrollRegions();
|
|
1281
|
+
history.decrypt().then((data) => {
|
|
1282
|
+
page.set(data, { preserveScroll: true, preserveState: true }).then(() => {
|
|
1283
|
+
Scroll.restore(scrollRegions);
|
|
1284
|
+
fireNavigateEvent(page.get());
|
|
1285
|
+
});
|
|
1286
|
+
}).catch(() => {
|
|
1287
|
+
eventHandler.onMissingHistoryItem();
|
|
1239
1288
|
});
|
|
1289
|
+
return true;
|
|
1240
1290
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
return [cacheFor, cacheFor];
|
|
1291
|
+
/**
|
|
1292
|
+
* @link https://inertiajs.com/redirects#external-redirects
|
|
1293
|
+
*/
|
|
1294
|
+
static handleLocation() {
|
|
1295
|
+
if (!SessionStorage.exists(SessionStorage.locationVisitKey)) {
|
|
1296
|
+
return false;
|
|
1248
1297
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
return [cacheFor[0], cacheFor[0]];
|
|
1254
|
-
default:
|
|
1255
|
-
return [cacheFor[0], cacheFor[1]];
|
|
1298
|
+
const locationVisit = SessionStorage.get(SessionStorage.locationVisitKey) || {};
|
|
1299
|
+
SessionStorage.remove(SessionStorage.locationVisitKey);
|
|
1300
|
+
if (typeof window !== "undefined") {
|
|
1301
|
+
page.setUrlHash(window.location.hash);
|
|
1256
1302
|
}
|
|
1303
|
+
history.decrypt(page.get()).then(() => {
|
|
1304
|
+
const rememberedState = history.getState(history.rememberedState, {});
|
|
1305
|
+
const scrollRegions = history.getScrollRegions();
|
|
1306
|
+
page.remember(rememberedState);
|
|
1307
|
+
page.set(page.get(), {
|
|
1308
|
+
preserveScroll: locationVisit.preserveScroll,
|
|
1309
|
+
preserveState: true
|
|
1310
|
+
}).then(() => {
|
|
1311
|
+
if (locationVisit.preserveScroll) {
|
|
1312
|
+
Scroll.restore(scrollRegions);
|
|
1313
|
+
}
|
|
1314
|
+
fireNavigateEvent(page.get());
|
|
1315
|
+
});
|
|
1316
|
+
}).catch(() => {
|
|
1317
|
+
eventHandler.onMissingHistoryItem();
|
|
1318
|
+
});
|
|
1319
|
+
return true;
|
|
1257
1320
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1321
|
+
static handleDefault() {
|
|
1322
|
+
if (typeof window !== "undefined") {
|
|
1323
|
+
page.setUrlHash(window.location.hash);
|
|
1324
|
+
}
|
|
1325
|
+
page.set(page.get(), { preserveScroll: true, preserveState: true }).then(() => {
|
|
1326
|
+
if (navigationType.isReload()) {
|
|
1327
|
+
Scroll.restore(history.getScrollRegions());
|
|
1328
|
+
} else {
|
|
1329
|
+
Scroll.scrollToAnchor();
|
|
1330
|
+
}
|
|
1331
|
+
fireNavigateEvent(page.get());
|
|
1261
1332
|
});
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
|
|
1336
|
+
// src/poll.ts
|
|
1337
|
+
var Poll = class {
|
|
1338
|
+
constructor(interval, cb, options) {
|
|
1339
|
+
this.id = null;
|
|
1340
|
+
this.throttle = false;
|
|
1341
|
+
this.keepAlive = false;
|
|
1342
|
+
this.cbCount = 0;
|
|
1343
|
+
this.keepAlive = options.keepAlive ?? false;
|
|
1344
|
+
this.cb = cb;
|
|
1345
|
+
this.interval = interval;
|
|
1346
|
+
if (options.autoStart ?? true) {
|
|
1347
|
+
this.start();
|
|
1265
1348
|
}
|
|
1266
1349
|
}
|
|
1267
|
-
|
|
1350
|
+
stop() {
|
|
1351
|
+
if (this.id) {
|
|
1352
|
+
clearInterval(this.id);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
start() {
|
|
1268
1356
|
if (typeof window === "undefined") {
|
|
1269
1357
|
return;
|
|
1270
1358
|
}
|
|
1271
|
-
this.
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
params,
|
|
1276
|
-
timer
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
get(params) {
|
|
1281
|
-
return this.findCached(params) || this.findInFlight(params);
|
|
1282
|
-
}
|
|
1283
|
-
use(prefetched, params) {
|
|
1284
|
-
const id = `${params.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
1285
|
-
this.currentUseId = id;
|
|
1286
|
-
return prefetched.response.then((response) => {
|
|
1287
|
-
if (this.currentUseId !== id) {
|
|
1288
|
-
return;
|
|
1359
|
+
this.stop();
|
|
1360
|
+
this.id = window.setInterval(() => {
|
|
1361
|
+
if (!this.throttle || this.cbCount % 10 === 0) {
|
|
1362
|
+
this.cb();
|
|
1289
1363
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
this.removeSingleUseItems(params);
|
|
1293
|
-
return response.handle();
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
removeSingleUseItems(params) {
|
|
1297
|
-
this.cached = this.cached.filter((prefetched) => {
|
|
1298
|
-
if (!this.paramsAreEqual(prefetched.params, params)) {
|
|
1299
|
-
return true;
|
|
1364
|
+
if (this.throttle) {
|
|
1365
|
+
this.cbCount++;
|
|
1300
1366
|
}
|
|
1301
|
-
|
|
1302
|
-
});
|
|
1367
|
+
}, this.interval);
|
|
1303
1368
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1369
|
+
isInBackground(hidden) {
|
|
1370
|
+
this.throttle = this.keepAlive ? false : hidden;
|
|
1371
|
+
if (this.throttle) {
|
|
1372
|
+
this.cbCount = 0;
|
|
1373
|
+
}
|
|
1308
1374
|
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1377
|
+
// src/polls.ts
|
|
1378
|
+
var Polls = class {
|
|
1379
|
+
constructor() {
|
|
1380
|
+
this.polls = [];
|
|
1381
|
+
this.setupVisibilityListener();
|
|
1313
1382
|
}
|
|
1314
|
-
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1383
|
+
add(interval, cb, options) {
|
|
1384
|
+
const poll = new Poll(interval, cb, options);
|
|
1385
|
+
this.polls.push(poll);
|
|
1386
|
+
return {
|
|
1387
|
+
stop: () => poll.stop(),
|
|
1388
|
+
start: () => poll.start()
|
|
1389
|
+
};
|
|
1320
1390
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
"onFinish",
|
|
1336
|
-
"onCancel",
|
|
1337
|
-
"onSuccess",
|
|
1338
|
-
"onError",
|
|
1339
|
-
"onPrefetched",
|
|
1340
|
-
"onCancelToken",
|
|
1341
|
-
"onPrefetching",
|
|
1342
|
-
"async",
|
|
1343
|
-
"viewTransition"
|
|
1344
|
-
]
|
|
1391
|
+
clear() {
|
|
1392
|
+
this.polls.forEach((poll) => poll.stop());
|
|
1393
|
+
this.polls = [];
|
|
1394
|
+
}
|
|
1395
|
+
setupVisibilityListener() {
|
|
1396
|
+
if (typeof document === "undefined") {
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
document.addEventListener(
|
|
1400
|
+
"visibilitychange",
|
|
1401
|
+
() => {
|
|
1402
|
+
this.polls.forEach((poll) => poll.isInBackground(document.hidden));
|
|
1403
|
+
},
|
|
1404
|
+
false
|
|
1345
1405
|
);
|
|
1346
1406
|
}
|
|
1347
1407
|
};
|
|
1348
|
-
var
|
|
1408
|
+
var polls = new Polls();
|
|
1349
1409
|
|
|
1350
1410
|
// src/request.ts
|
|
1351
1411
|
import { default as axios } from "axios";
|
|
@@ -1392,6 +1452,9 @@ var RequestParams = class _RequestParams {
|
|
|
1392
1452
|
isPartial() {
|
|
1393
1453
|
return this.params.only.length > 0 || this.params.except.length > 0 || this.params.reset.length > 0;
|
|
1394
1454
|
}
|
|
1455
|
+
isDeferredPropsRequest() {
|
|
1456
|
+
return this.params.deferredProps === true;
|
|
1457
|
+
}
|
|
1395
1458
|
onCancelToken(cb) {
|
|
1396
1459
|
this.params.onCancelToken({
|
|
1397
1460
|
cancel: cb
|
|
@@ -1650,6 +1713,9 @@ var Response = class _Response {
|
|
|
1650
1713
|
mergeParams(params) {
|
|
1651
1714
|
this.requestParams.merge(params);
|
|
1652
1715
|
}
|
|
1716
|
+
getPageResponse() {
|
|
1717
|
+
return this.response.data = this.getDataFromResponse(this.response.data);
|
|
1718
|
+
}
|
|
1653
1719
|
async handleNonInertiaResponse() {
|
|
1654
1720
|
if (this.isLocationVisit()) {
|
|
1655
1721
|
const locationUrl = hrefToUrl(this.getHeader("x-inertia-location"));
|
|
@@ -1700,11 +1766,12 @@ var Response = class _Response {
|
|
|
1700
1766
|
}
|
|
1701
1767
|
}
|
|
1702
1768
|
async setPage() {
|
|
1703
|
-
const pageResponse = this.
|
|
1769
|
+
const pageResponse = this.getPageResponse();
|
|
1704
1770
|
if (!this.shouldSetPage(pageResponse)) {
|
|
1705
1771
|
return Promise.resolve();
|
|
1706
1772
|
}
|
|
1707
1773
|
this.mergeProps(pageResponse);
|
|
1774
|
+
page.mergeOncePropsIntoResponse(pageResponse);
|
|
1708
1775
|
this.preserveEqualProps(pageResponse);
|
|
1709
1776
|
await this.setRememberedState(pageResponse);
|
|
1710
1777
|
this.requestParams.setPreserveOptions(pageResponse);
|
|
@@ -1809,12 +1876,24 @@ var Response = class _Response {
|
|
|
1809
1876
|
pageResponse.props[prop] = deepMerge(currentProp, incomingProp, prop);
|
|
1810
1877
|
});
|
|
1811
1878
|
pageResponse.props = { ...page.get().props, ...pageResponse.props };
|
|
1879
|
+
if (this.requestParams.isDeferredPropsRequest()) {
|
|
1880
|
+
const currentErrors = page.get().props.errors;
|
|
1881
|
+
if (currentErrors && Object.keys(currentErrors).length > 0) {
|
|
1882
|
+
pageResponse.props.errors = currentErrors;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1812
1885
|
if (page.get().scrollProps) {
|
|
1813
1886
|
pageResponse.scrollProps = {
|
|
1814
1887
|
...page.get().scrollProps || {},
|
|
1815
1888
|
...pageResponse.scrollProps || {}
|
|
1816
1889
|
};
|
|
1817
1890
|
}
|
|
1891
|
+
if (page.hasOnceProps()) {
|
|
1892
|
+
pageResponse.onceProps = {
|
|
1893
|
+
...page.get().onceProps || {},
|
|
1894
|
+
...pageResponse.onceProps || {}
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1818
1897
|
}
|
|
1819
1898
|
mergeOrMatchItems(existingItems, newItems, matchProp, matchPropsOn, shouldAppend = true) {
|
|
1820
1899
|
const items = Array.isArray(existingItems) ? existingItems : [];
|
|
@@ -1971,8 +2050,18 @@ var Request = class _Request {
|
|
|
1971
2050
|
"X-Requested-With": "XMLHttpRequest",
|
|
1972
2051
|
"X-Inertia": true
|
|
1973
2052
|
};
|
|
1974
|
-
|
|
1975
|
-
|
|
2053
|
+
const page2 = page.get();
|
|
2054
|
+
if (page2.version) {
|
|
2055
|
+
headers["X-Inertia-Version"] = page2.version;
|
|
2056
|
+
}
|
|
2057
|
+
const onceProps = Object.entries(page2.onceProps || {}).filter(([, onceProp]) => {
|
|
2058
|
+
if (page2.props[onceProp.prop] === void 0) {
|
|
2059
|
+
return false;
|
|
2060
|
+
}
|
|
2061
|
+
return !onceProp.expiresAt || onceProp.expiresAt > Date.now();
|
|
2062
|
+
}).map(([key]) => key);
|
|
2063
|
+
if (onceProps.length > 0) {
|
|
2064
|
+
headers["X-Inertia-Except-Once-Props"] = onceProps.join(",");
|
|
1976
2065
|
}
|
|
1977
2066
|
return headers;
|
|
1978
2067
|
}
|
|
@@ -2023,6 +2112,7 @@ var Router = class {
|
|
|
2023
2112
|
maxConcurrent: Infinity,
|
|
2024
2113
|
interruptible: false
|
|
2025
2114
|
});
|
|
2115
|
+
this.clientVisitQueue = new Queue();
|
|
2026
2116
|
}
|
|
2027
2117
|
init({
|
|
2028
2118
|
initialPage,
|
|
@@ -2061,6 +2151,9 @@ var Router = class {
|
|
|
2061
2151
|
return this.visit(url, { preserveState: true, ...options, method: "delete" });
|
|
2062
2152
|
}
|
|
2063
2153
|
reload(options = {}) {
|
|
2154
|
+
return this.doReload(options);
|
|
2155
|
+
}
|
|
2156
|
+
doReload(options = {}) {
|
|
2064
2157
|
if (typeof window === "undefined") {
|
|
2065
2158
|
return;
|
|
2066
2159
|
}
|
|
@@ -2249,6 +2342,9 @@ var Router = class {
|
|
|
2249
2342
|
this.clientVisit(params);
|
|
2250
2343
|
}
|
|
2251
2344
|
clientVisit(params, { replace = false } = {}) {
|
|
2345
|
+
this.clientVisitQueue.add(() => this.performClientVisit(params, { replace }));
|
|
2346
|
+
}
|
|
2347
|
+
performClientVisit(params, { replace = false } = {}) {
|
|
2252
2348
|
const current = page.get();
|
|
2253
2349
|
const props = typeof params.props === "function" ? params.props(current.props) : params.props ?? current.props;
|
|
2254
2350
|
const { viewTransition, onError, onFinish, onSuccess, ...pageParams } = params;
|
|
@@ -2259,7 +2355,7 @@ var Router = class {
|
|
|
2259
2355
|
};
|
|
2260
2356
|
const preserveScroll = RequestParams.resolvePreserveOption(params.preserveScroll ?? false, page2);
|
|
2261
2357
|
const preserveState = RequestParams.resolvePreserveOption(params.preserveState ?? false, page2);
|
|
2262
|
-
page.set(page2, {
|
|
2358
|
+
return page.set(page2, {
|
|
2263
2359
|
replace,
|
|
2264
2360
|
preserveScroll,
|
|
2265
2361
|
preserveState,
|
|
@@ -2267,10 +2363,11 @@ var Router = class {
|
|
|
2267
2363
|
}).then(() => {
|
|
2268
2364
|
const errors = page.get().props.errors || {};
|
|
2269
2365
|
if (Object.keys(errors).length === 0) {
|
|
2270
|
-
|
|
2366
|
+
onSuccess?.(page.get());
|
|
2367
|
+
return;
|
|
2271
2368
|
}
|
|
2272
2369
|
const scopedErrors = params.errorBag ? errors[params.errorBag || ""] || {} : errors;
|
|
2273
|
-
|
|
2370
|
+
onError?.(scopedErrors);
|
|
2274
2371
|
}).finally(() => onFinish?.(params));
|
|
2275
2372
|
}
|
|
2276
2373
|
getPrefetchParams(href, options) {
|
|
@@ -2366,7 +2463,7 @@ var Router = class {
|
|
|
2366
2463
|
loadDeferredProps(deferred) {
|
|
2367
2464
|
if (deferred) {
|
|
2368
2465
|
Object.entries(deferred).forEach(([_, group]) => {
|
|
2369
|
-
this.
|
|
2466
|
+
this.doReload({ only: group, deferredProps: true });
|
|
2370
2467
|
});
|
|
2371
2468
|
}
|
|
2372
2469
|
}
|
|
@@ -2462,6 +2559,22 @@ var requestAnimationFrame = (cb, times = 1) => {
|
|
|
2462
2559
|
}
|
|
2463
2560
|
});
|
|
2464
2561
|
};
|
|
2562
|
+
var getInitialPageFromDOM = (id, useScriptElement = false) => {
|
|
2563
|
+
if (typeof window === "undefined") {
|
|
2564
|
+
return null;
|
|
2565
|
+
}
|
|
2566
|
+
if (!useScriptElement) {
|
|
2567
|
+
const el = document.getElementById(id);
|
|
2568
|
+
if (el?.dataset.page) {
|
|
2569
|
+
return JSON.parse(el.dataset.page);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
const scriptEl = document.querySelector(`script[data-page="${id}"][type="application/json"]`);
|
|
2573
|
+
if (scriptEl?.textContent) {
|
|
2574
|
+
return JSON.parse(scriptEl.textContent);
|
|
2575
|
+
}
|
|
2576
|
+
return null;
|
|
2577
|
+
};
|
|
2465
2578
|
|
|
2466
2579
|
// src/formObject.ts
|
|
2467
2580
|
import { get as get4, set as set4 } from "lodash-es";
|
|
@@ -3689,6 +3802,7 @@ export {
|
|
|
3689
3802
|
config,
|
|
3690
3803
|
createHeadManager,
|
|
3691
3804
|
formDataToObject,
|
|
3805
|
+
getInitialPageFromDOM,
|
|
3692
3806
|
getScrollableParent,
|
|
3693
3807
|
hide2 as hideProgress,
|
|
3694
3808
|
hrefToUrl,
|