@analogjs/router 3.0.0-alpha.92 → 3.0.0-alpha.94
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/fesm2022/analogjs-router-i18n.mjs +4 -0
- package/fesm2022/analogjs-router-i18n.mjs.map +1 -1
- package/fesm2022/analogjs-router-server-actions.mjs +416 -2
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -0
- package/fesm2022/analogjs-router-server.mjs +294 -63
- package/fesm2022/analogjs-router-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query-server.mjs +4 -4
- package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query.mjs +70 -2
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -1
- package/fesm2022/analogjs-router-tokens.mjs.map +1 -1
- package/fesm2022/analogjs-router.mjs +144 -78
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/fesm2022/debug.page.mjs +3 -3
- package/fesm2022/route-files.mjs +1 -1
- package/package.json +4 -4
- package/types/server/actions/src/define-action.d.ts +8 -15
- package/types/server/actions/src/define-api-route.d.ts +2 -3
- package/types/server/actions/src/define-page-load.d.ts +8 -9
- package/types/server/actions/src/define-server-route.d.ts +1 -1
- package/types/server/actions/src/index.d.ts +3 -2
- package/types/server/actions/src/parse-request-data.d.ts +3 -4
- package/types/server/actions/src/standard-schema.d.ts +39 -0
- package/types/server/actions/src/validate.d.ts +1 -1
- package/types/server/src/defer-reconcile-runtime.d.ts +1 -1
- package/types/server/src/ssr-navigation.d.ts +6 -0
- package/types/server/src/utils/ssr-stream-lifecycle.d.ts +14 -0
- package/types/server/src/utils/stream-shell.d.ts +3 -0
- package/types/src/index.d.ts +2 -4
- package/types/src/lib/form-action.directive.d.ts +11 -9
- package/types/src/lib/server-fn/inject-server-fn.d.ts +1 -1
- package/types/tanstack-query/server/src/define-page-load-queries.d.ts +4 -6
- package/types/tanstack-query/server/src/index.d.ts +1 -1
- package/types/tanstack-query/server/src/provide-server-analog-query.d.ts +2 -0
- package/types/tanstack-query/src/index.d.ts +3 -2
- package/types/tanstack-query/src/server-query.d.ts +1 -1
- package/types/tokens/src/index.d.ts +8 -0
- package/fesm2022/provide-analog-query.mjs +0 -72
- package/fesm2022/provide-analog-query.mjs.map +0 -1
- package/fesm2022/src.mjs +0 -334
- package/fesm2022/src.mjs.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { API_PREFIX, injectAPIPrefix, injectBaseURL, injectInternalServerFetch, injectRequest } from "./analogjs-router-tokens.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as ANALOG_META_KEY, i as injectRouteEndpointURL, n as ANALOG_ROUTE_FILES, o as updateMetaTagsOnRouteChange, r as createRoutes$1, s as updateJsonLdOnRouteChange, t as ANALOG_EXTRA_ROUTE_FILE_SOURCES } from "./route-files.mjs";
|
|
3
3
|
import { n as createRoutes, r as routes, t as injectDebugRoutes } from "./routes.mjs";
|
|
4
4
|
import * as i1 from "@angular/router";
|
|
5
5
|
import { ActivatedRoute, ROUTES, Router, RouterLink, provideRouter } from "@angular/router";
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
|
-
import { DOCUMENT, Directive, Injectable, InjectionToken, Injector, PLATFORM_ID, TransferState, assertInInjectionContext, inject, input, makeEnvironmentProviders, makeStateKey, output, provideAppInitializer, resource, signal } from "@angular/core";
|
|
7
|
+
import { DOCUMENT, Directive, ElementRef, Injectable, InjectionToken, Injector, PLATFORM_ID, Renderer2, TransferState, assertInInjectionContext, booleanAttribute, effect, inject, input, makeEnvironmentProviders, makeStateKey, output, provideAppInitializer, resource, runInInjectionContext, signal } from "@angular/core";
|
|
8
8
|
import { HttpClient, HttpHeaders, HttpResponse, ɵHTTP_ROOT_INTERCEPTOR_FNS } from "@angular/common/http";
|
|
9
9
|
import { combineLatest, firstValueFrom, from, map, of } from "rxjs";
|
|
10
10
|
import { Meta } from "@angular/platform-browser";
|
|
@@ -427,41 +427,73 @@ function requestContextInterceptor(req, next) {
|
|
|
427
427
|
var FormAction = class FormAction {
|
|
428
428
|
constructor() {
|
|
429
429
|
this.action = input("", ...[]);
|
|
430
|
+
this.enhanceForm = input(false, { transform: booleanAttribute });
|
|
430
431
|
this.onSuccess = output();
|
|
431
432
|
this.onError = output();
|
|
432
433
|
this.state = output();
|
|
434
|
+
this.currentState = signal("idle", ...[]);
|
|
435
|
+
this.injector = inject(Injector);
|
|
433
436
|
this.router = inject(Router);
|
|
434
437
|
this.route = inject(ActivatedRoute);
|
|
435
|
-
this.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
+
this.path = this._getPath();
|
|
439
|
+
const form = inject(ElementRef).nativeElement;
|
|
440
|
+
const renderer = inject(Renderer2);
|
|
441
|
+
effect((onCleanup) => {
|
|
442
|
+
if (!this.enhanceForm()) return;
|
|
443
|
+
const previous = {
|
|
444
|
+
"data-state": form.getAttribute("data-state"),
|
|
445
|
+
"aria-busy": form.getAttribute("aria-busy")
|
|
446
|
+
};
|
|
447
|
+
const state = this.currentState();
|
|
448
|
+
renderer.setAttribute(form, "data-state", state);
|
|
449
|
+
if (state === "submitting") renderer.setAttribute(form, "aria-busy", "true");
|
|
450
|
+
else renderer.removeAttribute(form, "aria-busy");
|
|
451
|
+
onCleanup(() => {
|
|
452
|
+
for (const [name, value] of Object.entries(previous)) if (value === null) renderer.removeAttribute(form, name);
|
|
453
|
+
else renderer.setAttribute(form, name, value);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
438
456
|
}
|
|
439
457
|
submitted($event) {
|
|
440
458
|
$event.preventDefault();
|
|
441
|
-
const form = $event.target;
|
|
442
459
|
this._emitState("submitting");
|
|
443
|
-
const body = new FormData(
|
|
444
|
-
if (
|
|
445
|
-
|
|
460
|
+
const body = new FormData($event.target);
|
|
461
|
+
if (this.enhanceForm()) {
|
|
462
|
+
const form = $event.target;
|
|
463
|
+
try {
|
|
464
|
+
const action = this.action().trim() || form.getAttribute("action")?.trim();
|
|
465
|
+
if (form.method.toUpperCase() === "GET") this._handleEnhancedGet(body, action || this.router.url);
|
|
466
|
+
else {
|
|
467
|
+
const path = action ? new URL(action, window.location.href).toString() : this._getPath();
|
|
468
|
+
this._handleEnhancedPost(body, path, form.method);
|
|
469
|
+
}
|
|
470
|
+
} catch {
|
|
471
|
+
this._emitState("error");
|
|
472
|
+
}
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if ($event.target.method.toUpperCase() === "GET") this._handleGet(body, this.router.url);
|
|
476
|
+
else this._handlePost(body, this.path, $event);
|
|
446
477
|
}
|
|
447
478
|
_handleGet(body, path) {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
body.forEach((value, key) => {
|
|
451
|
-
params.append(key, value instanceof File ? value.name : value);
|
|
452
|
-
});
|
|
453
|
-
url.search = params.toString();
|
|
479
|
+
const params = {};
|
|
480
|
+
body.forEach((formVal, formKey) => params[formKey] = formVal);
|
|
454
481
|
this._emitState("navigate");
|
|
455
|
-
|
|
482
|
+
const url = path.split("?")[0];
|
|
483
|
+
this.router.navigate([url], {
|
|
484
|
+
queryParams: params,
|
|
485
|
+
onSameUrlNavigation: "reload"
|
|
486
|
+
});
|
|
456
487
|
}
|
|
457
|
-
_handlePost(body, path,
|
|
488
|
+
_handlePost(body, path, $event) {
|
|
458
489
|
fetch(path, {
|
|
459
|
-
method,
|
|
490
|
+
method: $event.target.method,
|
|
460
491
|
body
|
|
461
492
|
}).then((res) => {
|
|
462
493
|
if (res.ok) if (res.redirected) {
|
|
494
|
+
const redirectUrl = new URL(res.url).pathname;
|
|
463
495
|
this._emitState("redirect");
|
|
464
|
-
this.
|
|
496
|
+
this.router.navigate([redirectUrl]);
|
|
465
497
|
} else if (this._isJSON(res.headers.get("Content-type"))) res.json().then((result) => {
|
|
466
498
|
this.onSuccess.emit(result);
|
|
467
499
|
this._emitState("success");
|
|
@@ -479,17 +511,43 @@ var FormAction = class FormAction {
|
|
|
479
511
|
this._emitState("error");
|
|
480
512
|
});
|
|
481
513
|
}
|
|
482
|
-
|
|
483
|
-
|
|
514
|
+
_getPath() {
|
|
515
|
+
const snapshot = this.route.snapshot;
|
|
516
|
+
if (snapshot.routeConfig && ANALOG_META_KEY in snapshot.routeConfig) return runInInjectionContext(this.injector, () => injectRouteEndpointURL(snapshot)).pathname;
|
|
517
|
+
return `/api/_analog/pages${window.location.pathname}`;
|
|
484
518
|
}
|
|
485
|
-
|
|
486
|
-
|
|
519
|
+
_handleEnhancedGet(body, path) {
|
|
520
|
+
const url = new URL(path, window.location.href);
|
|
521
|
+
const params = new URLSearchParams(url.search);
|
|
522
|
+
body.forEach((_value, key) => params.delete(key));
|
|
523
|
+
body.forEach((value, key) => {
|
|
524
|
+
params.append(key, value instanceof File ? value.name : value);
|
|
525
|
+
});
|
|
526
|
+
url.search = params.toString();
|
|
527
|
+
this._emitState("navigate");
|
|
528
|
+
this._navigateTo(url);
|
|
487
529
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
530
|
+
async _handleEnhancedPost(body, path, method) {
|
|
531
|
+
try {
|
|
532
|
+
const response = await fetch(path, {
|
|
533
|
+
method,
|
|
534
|
+
body
|
|
535
|
+
});
|
|
536
|
+
if (response.ok) if (response.redirected) {
|
|
537
|
+
this._emitState("redirect");
|
|
538
|
+
this._navigateTo(new URL(response.url, window.location.href));
|
|
539
|
+
} else {
|
|
540
|
+
const result = this._isJSON(response.headers.get("Content-type")) ? await response.json() : await response.text();
|
|
541
|
+
this.onSuccess.emit(result);
|
|
542
|
+
this._emitState("success");
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
if (response.headers.get("X-Analog-Errors")) this.onError.emit(await response.json());
|
|
546
|
+
this._emitState("error");
|
|
547
|
+
}
|
|
548
|
+
} catch {
|
|
549
|
+
this._emitState("error");
|
|
550
|
+
}
|
|
493
551
|
}
|
|
494
552
|
_emitState(state) {
|
|
495
553
|
this.currentState.set(state);
|
|
@@ -508,7 +566,7 @@ var FormAction = class FormAction {
|
|
|
508
566
|
static {
|
|
509
567
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
510
568
|
minVersion: "12.0.0",
|
|
511
|
-
version: "22.
|
|
569
|
+
version: "22.2.0",
|
|
512
570
|
ngImport: i0,
|
|
513
571
|
type: FormAction,
|
|
514
572
|
deps: [],
|
|
@@ -518,50 +576,50 @@ var FormAction = class FormAction {
|
|
|
518
576
|
static {
|
|
519
577
|
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
520
578
|
minVersion: "17.1.0",
|
|
521
|
-
version: "22.
|
|
579
|
+
version: "22.2.0",
|
|
522
580
|
type: FormAction,
|
|
523
581
|
isStandalone: true,
|
|
524
|
-
selector: "form[action],form[method]",
|
|
525
|
-
inputs: {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
582
|
+
selector: "form[action],form[method],form[enhanceForm]",
|
|
583
|
+
inputs: {
|
|
584
|
+
action: {
|
|
585
|
+
classPropertyName: "action",
|
|
586
|
+
publicName: "action",
|
|
587
|
+
isSignal: true,
|
|
588
|
+
isRequired: false,
|
|
589
|
+
transformFunction: null
|
|
590
|
+
},
|
|
591
|
+
enhanceForm: {
|
|
592
|
+
classPropertyName: "enhanceForm",
|
|
593
|
+
publicName: "enhanceForm",
|
|
594
|
+
isSignal: true,
|
|
595
|
+
isRequired: false,
|
|
596
|
+
transformFunction: null
|
|
597
|
+
}
|
|
598
|
+
},
|
|
532
599
|
outputs: {
|
|
533
600
|
onSuccess: "onSuccess",
|
|
534
601
|
onError: "onError",
|
|
535
602
|
state: "state"
|
|
536
603
|
},
|
|
537
|
-
host: {
|
|
538
|
-
listeners: { "submit": "submitted($event)" },
|
|
539
|
-
properties: {
|
|
540
|
-
"attr.data-state": "currentState()",
|
|
541
|
-
"attr.aria-busy": "currentState() === \"submitting\" ? \"true\" : null"
|
|
542
|
-
}
|
|
543
|
-
},
|
|
604
|
+
host: { listeners: { "submit": "submitted($event)" } },
|
|
544
605
|
ngImport: i0
|
|
545
606
|
});
|
|
546
607
|
}
|
|
547
608
|
};
|
|
548
609
|
i0.ɵɵngDeclareClassMetadata({
|
|
549
610
|
minVersion: "12.0.0",
|
|
550
|
-
version: "22.
|
|
611
|
+
version: "22.2.0",
|
|
551
612
|
ngImport: i0,
|
|
552
613
|
type: FormAction,
|
|
553
614
|
decorators: [{
|
|
554
615
|
type: Directive,
|
|
555
616
|
args: [{
|
|
556
|
-
selector: "form[action],form[method]",
|
|
557
|
-
host: {
|
|
558
|
-
"(submit)": `submitted($event)`,
|
|
559
|
-
"[attr.data-state]": "currentState()",
|
|
560
|
-
"[attr.aria-busy]": "currentState() === \"submitting\" ? \"true\" : null"
|
|
561
|
-
},
|
|
617
|
+
selector: "form[action],form[method],form[enhanceForm]",
|
|
618
|
+
host: { "(submit)": `submitted($event)` },
|
|
562
619
|
standalone: true
|
|
563
620
|
}]
|
|
564
621
|
}],
|
|
622
|
+
ctorParameters: () => [],
|
|
565
623
|
propDecorators: {
|
|
566
624
|
action: [{
|
|
567
625
|
type: i0.Input,
|
|
@@ -571,6 +629,14 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
571
629
|
required: false
|
|
572
630
|
}]
|
|
573
631
|
}],
|
|
632
|
+
enhanceForm: [{
|
|
633
|
+
type: i0.Input,
|
|
634
|
+
args: [{
|
|
635
|
+
isSignal: true,
|
|
636
|
+
alias: "enhanceForm",
|
|
637
|
+
required: false
|
|
638
|
+
}]
|
|
639
|
+
}],
|
|
574
640
|
onSuccess: [{
|
|
575
641
|
type: i0.Output,
|
|
576
642
|
args: ["onSuccess"]
|
|
@@ -586,6 +652,26 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
586
652
|
}
|
|
587
653
|
});
|
|
588
654
|
//#endregion
|
|
655
|
+
//#region packages/router/src/lib/validation-errors.ts
|
|
656
|
+
function getPathSegmentKey(segment) {
|
|
657
|
+
return typeof segment === "object" ? segment.key : segment;
|
|
658
|
+
}
|
|
659
|
+
function issuePathToFieldName(path) {
|
|
660
|
+
return path.map((segment) => String(getPathSegmentKey(segment))).join(".");
|
|
661
|
+
}
|
|
662
|
+
function issuesToFieldErrors(issues) {
|
|
663
|
+
return issues.reduce((errors, issue) => {
|
|
664
|
+
if (!issue.path?.length) return errors;
|
|
665
|
+
const fieldName = issuePathToFieldName(issue.path);
|
|
666
|
+
errors[fieldName] ??= [];
|
|
667
|
+
errors[fieldName].push(issue.message);
|
|
668
|
+
return errors;
|
|
669
|
+
}, Object.create(null));
|
|
670
|
+
}
|
|
671
|
+
function issuesToFormErrors(issues) {
|
|
672
|
+
return issues.filter((issue) => !issue.path?.length).map((issue) => issue.message);
|
|
673
|
+
}
|
|
674
|
+
//#endregion
|
|
589
675
|
//#region packages/router/src/lib/debug/index.ts
|
|
590
676
|
/**
|
|
591
677
|
* Provides routes that provide additional
|
|
@@ -606,26 +692,6 @@ function withDebugRoutes() {
|
|
|
606
692
|
};
|
|
607
693
|
}
|
|
608
694
|
//#endregion
|
|
609
|
-
//#region packages/router/src/lib/validation-errors.ts
|
|
610
|
-
function getPathSegmentKey(segment) {
|
|
611
|
-
return typeof segment === "object" ? segment.key : segment;
|
|
612
|
-
}
|
|
613
|
-
function issuePathToFieldName(path) {
|
|
614
|
-
return path.map((segment) => String(getPathSegmentKey(segment))).join(".");
|
|
615
|
-
}
|
|
616
|
-
function issuesToFieldErrors(issues) {
|
|
617
|
-
return issues.reduce((errors, issue) => {
|
|
618
|
-
if (!issue.path?.length) return errors;
|
|
619
|
-
const fieldName = issuePathToFieldName(issue.path);
|
|
620
|
-
errors[fieldName] ??= [];
|
|
621
|
-
errors[fieldName].push(issue.message);
|
|
622
|
-
return errors;
|
|
623
|
-
}, {});
|
|
624
|
-
}
|
|
625
|
-
function issuesToFormErrors(issues) {
|
|
626
|
-
return issues.filter((issue) => !issue.path?.length).map((issue) => issue.message);
|
|
627
|
-
}
|
|
628
|
-
//#endregion
|
|
629
695
|
//#region packages/router/src/lib/server-fn/dispatcher.ts
|
|
630
696
|
var SERVER_FN_DISPATCHER = new InjectionToken("@analogjs/router Server Function Dispatcher");
|
|
631
697
|
//#endregion
|
|
@@ -670,7 +736,7 @@ var ServerFnClient = class ServerFnClient {
|
|
|
670
736
|
static {
|
|
671
737
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
672
738
|
minVersion: "12.0.0",
|
|
673
|
-
version: "22.
|
|
739
|
+
version: "22.2.0",
|
|
674
740
|
ngImport: i0,
|
|
675
741
|
type: ServerFnClient,
|
|
676
742
|
deps: [],
|
|
@@ -680,7 +746,7 @@ var ServerFnClient = class ServerFnClient {
|
|
|
680
746
|
static {
|
|
681
747
|
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
682
748
|
minVersion: "12.0.0",
|
|
683
|
-
version: "22.
|
|
749
|
+
version: "22.2.0",
|
|
684
750
|
ngImport: i0,
|
|
685
751
|
type: ServerFnClient,
|
|
686
752
|
providedIn: "root"
|
|
@@ -689,7 +755,7 @@ var ServerFnClient = class ServerFnClient {
|
|
|
689
755
|
};
|
|
690
756
|
i0.ɵɵngDeclareClassMetadata({
|
|
691
757
|
minVersion: "12.0.0",
|
|
692
|
-
version: "22.
|
|
758
|
+
version: "22.2.0",
|
|
693
759
|
ngImport: i0,
|
|
694
760
|
type: ServerFnClient,
|
|
695
761
|
decorators: [{
|
|
@@ -963,7 +1029,7 @@ var LinkTo = class LinkTo {
|
|
|
963
1029
|
static {
|
|
964
1030
|
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
965
1031
|
minVersion: "12.0.0",
|
|
966
|
-
version: "22.
|
|
1032
|
+
version: "22.2.0",
|
|
967
1033
|
ngImport: i0,
|
|
968
1034
|
type: LinkTo,
|
|
969
1035
|
deps: [],
|
|
@@ -973,7 +1039,7 @@ var LinkTo = class LinkTo {
|
|
|
973
1039
|
static {
|
|
974
1040
|
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
975
1041
|
minVersion: "17.1.0",
|
|
976
|
-
version: "22.
|
|
1042
|
+
version: "22.2.0",
|
|
977
1043
|
type: LinkTo,
|
|
978
1044
|
isStandalone: true,
|
|
979
1045
|
selector: "[linkTo]",
|
|
@@ -1017,7 +1083,7 @@ var LinkTo = class LinkTo {
|
|
|
1017
1083
|
};
|
|
1018
1084
|
i0.ɵɵngDeclareClassMetadata({
|
|
1019
1085
|
minVersion: "12.0.0",
|
|
1020
|
-
version: "22.
|
|
1086
|
+
version: "22.2.0",
|
|
1021
1087
|
ngImport: i0,
|
|
1022
1088
|
type: LinkTo,
|
|
1023
1089
|
decorators: [{
|