@hamur/adapter-angular 0.0.1 → 0.0.2
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/src/adapter.js +3 -1
- package/dist/types/src/app.d.ts +3 -0
- package/dist/types/src/client-parts.d.ts +3 -0
- package/dist/types/src/compile.d.ts +4 -2
- package/dist/types/src/error-page.d.ts +5 -2
- package/dist/types/src/form.d.ts +12 -9
- package/dist/types/src/indicators.d.ts +15 -8
- package/dist/types/src/island.d.ts +9 -6
- package/dist/types/src/link.d.ts +25 -22
- package/dist/types/src/markdown.d.ts +6 -3
- package/dist/types/src/navigate.d.ts +6 -3
- package/dist/types/src/outlet.d.ts +10 -5
- package/dist/types/src/server-island.d.ts +6 -3
- package/dist/types/src/time.d.ts +28 -25
- package/package.json +30 -9
- package/src/app.ts +11 -5
- package/src/client-parts.ts +83 -103
- package/src/compile.ts +9 -5
- package/src/error-page.ts +23 -10
- package/src/form.ts +166 -237
- package/src/indicators.ts +198 -229
- package/src/island.ts +78 -84
- package/src/link.ts +204 -241
- package/src/markdown.ts +129 -159
- package/src/navigate.ts +20 -17
- package/src/outlet.ts +297 -325
- package/src/server-island.ts +62 -49
- package/src/time.ts +108 -101
package/src/link.ts
CHANGED
|
@@ -1,251 +1,214 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
InjectionToken,
|
|
7
|
-
assertInInjectionContext,
|
|
8
|
-
booleanAttribute,
|
|
9
|
-
computed,
|
|
10
|
-
effect,
|
|
11
|
-
forwardRef,
|
|
12
|
-
inject,
|
|
13
|
-
input,
|
|
14
|
-
numberAttribute,
|
|
15
|
-
output,
|
|
16
|
-
type Signal,
|
|
17
|
-
} from "@angular/core"
|
|
18
|
-
import { withoutBase } from "hamur/app"
|
|
19
|
-
import type { RouteLocation, ViewTransitionCall } from "hamur/app"
|
|
20
|
-
import {
|
|
21
|
-
createLinkSlot,
|
|
22
|
-
linkAttributes,
|
|
23
|
-
linkDefaultsOf,
|
|
24
|
-
linkPending,
|
|
25
|
-
linkPrefetchProps,
|
|
26
|
-
linkState,
|
|
27
|
-
relativeTarget,
|
|
28
|
-
resolveLinkTarget,
|
|
29
|
-
searchTarget,
|
|
30
|
-
setLinkState,
|
|
31
|
-
} from "hamur/adapter"
|
|
32
|
-
import type { CheckedTarget, LinkSlot, Navigation, PrefetchOn, UseLinkOptions } from "hamur/adapter"
|
|
33
|
-
import {
|
|
34
|
-
HAMUR_APP,
|
|
35
|
-
HAMUR_BASE_URL,
|
|
36
|
-
HAMUR_HREF,
|
|
37
|
-
HAMUR_NAVIGATION,
|
|
38
|
-
HAMUR_ROUTE,
|
|
39
|
-
HAMUR_ROUTER,
|
|
40
|
-
detachedHref,
|
|
41
|
-
} from "./context.ts"
|
|
42
|
-
|
|
43
|
-
type AriaCurrent = "page" | "step" | "location" | "date" | "time" | "true"
|
|
44
|
-
type Query = (prev: never) => Record<string, unknown>
|
|
45
|
-
|
|
1
|
+
import { DestroyRef, Directive, ElementRef, HostAttributeToken, InjectionToken, assertInInjectionContext, booleanAttribute, computed, effect, forwardRef, inject, input, numberAttribute, output, } from "@angular/core";
|
|
2
|
+
import { withoutBase } from "hamur/app";
|
|
3
|
+
import { createLinkSlot, linkAttributes, linkDefaultsOf, linkPending, linkPrefetchProps, linkState, relativeTarget, resolveLinkTarget, searchTarget, setLinkState, } from "hamur/adapter";
|
|
4
|
+
import { HAMUR_APP, HAMUR_BASE_URL, HAMUR_HREF, HAMUR_NAVIGATION, HAMUR_ROUTE, HAMUR_ROUTER, detachedHref, } from "./context.ts";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
46
6
|
/** What a `Link`'s content reads through `injectLinkStatus()`. */
|
|
47
|
-
const LINK_HREF = new InjectionToken
|
|
48
|
-
|
|
49
|
-
const optionalBoolean = (value: unknown): boolean | undefined =>
|
|
50
|
-
value === undefined ? undefined : booleanAttribute(value)
|
|
51
|
-
|
|
7
|
+
const LINK_HREF = new InjectionToken("hamur link href");
|
|
8
|
+
const optionalBoolean = (value) => value === undefined ? undefined : booleanAttribute(value);
|
|
52
9
|
/**
|
|
53
10
|
* `<a hamurLink="/path">`. The host bindings write what the other adapters' `Link` writes on its anchor; the
|
|
54
11
|
* core navigator takes the click. A `target`, `rel` or `aria-current` written on the element stays.
|
|
55
12
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
})
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
constructor() {
|
|
177
|
-
effect(() => {
|
|
178
|
-
const state = this.state()
|
|
179
|
-
setLinkState(this.element, state, (navigation) => this.beforeNavigate.emit(navigation))
|
|
180
|
-
})
|
|
181
|
-
inject(DestroyRef).onDestroy(() => setLinkState(this.element, undefined))
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
protected attr(name: string): string | undefined {
|
|
185
|
-
return this.attrs()[name] ?? (name === "rel" ? (this.rel ?? undefined) : undefined)
|
|
186
|
-
}
|
|
13
|
+
export class Link {
|
|
14
|
+
to = input.required({ ...(ngDevMode ? { debugName: "to" } : /* istanbul ignore next */ {}), alias: "hamurLink" });
|
|
15
|
+
replace = input(false, { ...(ngDevMode ? { debugName: "replace" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
16
|
+
prefetch = input(undefined, { ...(ngDevMode ? { debugName: "prefetch" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
|
|
17
|
+
prefetchOn = input(/* @ts-ignore */
|
|
18
|
+
...(ngDevMode ? [undefined, { debugName: "prefetchOn" }] : /* istanbul ignore next */ []));
|
|
19
|
+
prefetchDelay = input(undefined, { ...(ngDevMode ? { debugName: "prefetchDelay" } : /* istanbul ignore next */ {}), transform: (value) => (value === undefined ? undefined : numberAttribute(value)) });
|
|
20
|
+
viewTransition = input(/* @ts-ignore */
|
|
21
|
+
...(ngDevMode ? [undefined, { debugName: "viewTransition" }] : /* istanbul ignore next */ []));
|
|
22
|
+
query = input(/* @ts-ignore */
|
|
23
|
+
...(ngDevMode ? [undefined, { debugName: "query" }] : /* istanbul ignore next */ []));
|
|
24
|
+
state = input(/* @ts-ignore */
|
|
25
|
+
...(ngDevMode ? [undefined, { debugName: "state" }] : /* istanbul ignore next */ []));
|
|
26
|
+
relative = input(/* @ts-ignore */
|
|
27
|
+
...(ngDevMode ? [undefined, { debugName: "relative" }] : /* istanbul ignore next */ []));
|
|
28
|
+
mask = input(/* @ts-ignore */
|
|
29
|
+
...(ngDevMode ? [undefined, { debugName: "mask" }] : /* istanbul ignore next */ []));
|
|
30
|
+
unmaskOnReload = input(undefined, { ...(ngDevMode ? { debugName: "unmaskOnReload" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
|
|
31
|
+
activeClass = input(/* @ts-ignore */
|
|
32
|
+
...(ngDevMode ? [undefined, { debugName: "activeClass" }] : /* istanbul ignore next */ []));
|
|
33
|
+
exactActiveClass = input(/* @ts-ignore */
|
|
34
|
+
...(ngDevMode ? [undefined, { debugName: "exactActiveClass" }] : /* istanbul ignore next */ []));
|
|
35
|
+
pendingClass = input(/* @ts-ignore */
|
|
36
|
+
...(ngDevMode ? [undefined, { debugName: "pendingClass" }] : /* istanbul ignore next */ []));
|
|
37
|
+
prefetchedClass = input(/* @ts-ignore */
|
|
38
|
+
...(ngDevMode ? [undefined, { debugName: "prefetchedClass" }] : /* istanbul ignore next */ []));
|
|
39
|
+
ariaCurrentValue = input("page", /* @ts-ignore */
|
|
40
|
+
...(ngDevMode ? [{ debugName: "ariaCurrentValue" }] : /* istanbul ignore next */ []));
|
|
41
|
+
external = input(false, { ...(ngDevMode ? { debugName: "external" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
42
|
+
noRel = input(false, { ...(ngDevMode ? { debugName: "noRel" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
43
|
+
scroll = input(undefined, { ...(ngDevMode ? { debugName: "scroll" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
|
|
44
|
+
keepFocus = input(false, { ...(ngDevMode ? { debugName: "keepFocus" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
45
|
+
beforeNavigate = output();
|
|
46
|
+
app = inject(HAMUR_APP, { optional: true });
|
|
47
|
+
route = inject(HAMUR_ROUTE, { optional: true });
|
|
48
|
+
resolve = inject(HAMUR_HREF, { optional: true }) ?? detachedHref;
|
|
49
|
+
baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/";
|
|
50
|
+
element = inject(ElementRef).nativeElement;
|
|
51
|
+
rel = inject(new HostAttributeToken("rel"), { optional: true });
|
|
52
|
+
target = inject(new HostAttributeToken("target"), { optional: true });
|
|
53
|
+
given = inject(new HostAttributeToken("aria-current"), { optional: true });
|
|
54
|
+
defaults = computed(() => linkDefaultsOf(this.app), /* @ts-ignore */
|
|
55
|
+
...(ngDevMode ? [{ debugName: "defaults" }] : /* istanbul ignore next */ []));
|
|
56
|
+
classNames = computed(() => ({
|
|
57
|
+
active: this.activeClass() ?? this.defaults().activeClass,
|
|
58
|
+
exact: this.exactActiveClass() ?? this.defaults().exactActiveClass,
|
|
59
|
+
pending: this.pendingClass() ?? this.defaults().pendingClass,
|
|
60
|
+
prefetched: this.prefetchedClass() ?? this.defaults().prefetchedClass,
|
|
61
|
+
}), /* @ts-ignore */
|
|
62
|
+
...(ngDevMode ? [{ debugName: "classNames" }] : /* istanbul ignore next */ []));
|
|
63
|
+
linked = computed(() => {
|
|
64
|
+
const route = this.route?.();
|
|
65
|
+
const to = this.to();
|
|
66
|
+
return resolveLinkTarget(this.app, route ? searchTarget(relativeTarget(to, route, this.relative()), route, this.query()) : to, {
|
|
67
|
+
replace: this.replace(),
|
|
68
|
+
prefetch: this.prefetch(),
|
|
69
|
+
prefetchOn: this.prefetchOn(),
|
|
70
|
+
external: this.external(),
|
|
71
|
+
scroll: this.scroll(),
|
|
72
|
+
mask: this.mask(),
|
|
73
|
+
...(this.target === null ? {} : { target: this.target }),
|
|
74
|
+
}, this.resolve, this.external());
|
|
75
|
+
}, /* @ts-ignore */
|
|
76
|
+
...(ngDevMode ? [{ debugName: "linked" }] : /* istanbul ignore next */ []));
|
|
77
|
+
matched = computed(() => {
|
|
78
|
+
const route = this.route?.();
|
|
79
|
+
const target = this.linked().to;
|
|
80
|
+
if (!route)
|
|
81
|
+
return { active: false, exact: false };
|
|
82
|
+
return linkState(typeof target === "string" ? target : withoutBase(this.href(), this.baseURL), route);
|
|
83
|
+
}, /* @ts-ignore */
|
|
84
|
+
...(ngDevMode ? [{ debugName: "matched" }] : /* istanbul ignore next */ []));
|
|
85
|
+
/** The based `href` of the link. */
|
|
86
|
+
href = computed(() => this.resolve(this.linked().to), /* @ts-ignore */
|
|
87
|
+
...(ngDevMode ? [{ debugName: "href" }] : /* istanbul ignore next */ []));
|
|
88
|
+
ariaCurrent = computed(() => this.given ?? (this.matched().exact ? this.ariaCurrentValue() : undefined), /* @ts-ignore */
|
|
89
|
+
...(ngDevMode ? [{ debugName: "ariaCurrent" }] : /* istanbul ignore next */ []));
|
|
90
|
+
keepFocusValue = computed(() => (this.keepFocus() ? "" : undefined), /* @ts-ignore */
|
|
91
|
+
...(ngDevMode ? [{ debugName: "keepFocusValue" }] : /* istanbul ignore next */ []));
|
|
92
|
+
classes = computed(() => {
|
|
93
|
+
const { active, exact } = this.matched();
|
|
94
|
+
return [active && this.classNames().active, exact && this.classNames().exact].filter(Boolean).join(" ");
|
|
95
|
+
}, /* @ts-ignore */
|
|
96
|
+
...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
|
|
97
|
+
attrs = computed(() => {
|
|
98
|
+
const defaults = this.defaults();
|
|
99
|
+
return linkAttributes({
|
|
100
|
+
href: this.href(),
|
|
101
|
+
external: this.external(),
|
|
102
|
+
...linkPrefetchProps({ prefetch: this.prefetch(), prefetchOn: this.prefetchOn() }, defaults),
|
|
103
|
+
replace: this.replace(),
|
|
104
|
+
viewTransition: this.viewTransition(),
|
|
105
|
+
pendingClass: this.classNames().pending,
|
|
106
|
+
trim: !!this.query(),
|
|
107
|
+
mask: this.mask() === undefined ? undefined : this.resolve(this.mask()),
|
|
108
|
+
unmaskOnReload: this.unmaskOnReload(),
|
|
109
|
+
rel: this.rel ?? undefined,
|
|
110
|
+
target: this.target ?? undefined,
|
|
111
|
+
noRel: this.noRel(),
|
|
112
|
+
prefetchedClass: this.classNames().prefetched,
|
|
113
|
+
scroll: this.scroll(),
|
|
114
|
+
prefetchDelay: this.prefetchDelay() ?? defaults.prefetchDelay,
|
|
115
|
+
externalRelAttribute: defaults.externalRelAttribute,
|
|
116
|
+
});
|
|
117
|
+
}, /* @ts-ignore */
|
|
118
|
+
...(ngDevMode ? [{ debugName: "attrs" }] : /* istanbul ignore next */ []));
|
|
119
|
+
constructor() {
|
|
120
|
+
effect(() => {
|
|
121
|
+
const state = this.state();
|
|
122
|
+
setLinkState(this.element, state, (navigation) => this.beforeNavigate.emit(navigation));
|
|
123
|
+
});
|
|
124
|
+
inject(DestroyRef).onDestroy(() => setLinkState(this.element, undefined));
|
|
125
|
+
}
|
|
126
|
+
attr(name) {
|
|
127
|
+
return this.attrs()[name] ?? (name === "rel" ? (this.rel ?? undefined) : undefined);
|
|
128
|
+
}
|
|
129
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Link, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
130
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.2", type: Link, isStandalone: true, selector: "a[hamurLink]", inputs: { to: { classPropertyName: "to", publicName: "hamurLink", isSignal: true, isRequired: true, transformFunction: null }, replace: { classPropertyName: "replace", publicName: "replace", isSignal: true, isRequired: false, transformFunction: null }, prefetch: { classPropertyName: "prefetch", publicName: "prefetch", isSignal: true, isRequired: false, transformFunction: null }, prefetchOn: { classPropertyName: "prefetchOn", publicName: "prefetchOn", isSignal: true, isRequired: false, transformFunction: null }, prefetchDelay: { classPropertyName: "prefetchDelay", publicName: "prefetchDelay", isSignal: true, isRequired: false, transformFunction: null }, viewTransition: { classPropertyName: "viewTransition", publicName: "viewTransition", isSignal: true, isRequired: false, transformFunction: null }, query: { classPropertyName: "query", publicName: "query", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, relative: { classPropertyName: "relative", publicName: "relative", isSignal: true, isRequired: false, transformFunction: null }, mask: { classPropertyName: "mask", publicName: "mask", isSignal: true, isRequired: false, transformFunction: null }, unmaskOnReload: { classPropertyName: "unmaskOnReload", publicName: "unmaskOnReload", isSignal: true, isRequired: false, transformFunction: null }, activeClass: { classPropertyName: "activeClass", publicName: "activeClass", isSignal: true, isRequired: false, transformFunction: null }, exactActiveClass: { classPropertyName: "exactActiveClass", publicName: "exactActiveClass", isSignal: true, isRequired: false, transformFunction: null }, pendingClass: { classPropertyName: "pendingClass", publicName: "pendingClass", isSignal: true, isRequired: false, transformFunction: null }, prefetchedClass: { classPropertyName: "prefetchedClass", publicName: "prefetchedClass", isSignal: true, isRequired: false, transformFunction: null }, ariaCurrentValue: { classPropertyName: "ariaCurrentValue", publicName: "ariaCurrentValue", isSignal: true, isRequired: false, transformFunction: null }, external: { classPropertyName: "external", publicName: "external", isSignal: true, isRequired: false, transformFunction: null }, noRel: { classPropertyName: "noRel", publicName: "noRel", isSignal: true, isRequired: false, transformFunction: null }, scroll: { classPropertyName: "scroll", publicName: "scroll", isSignal: true, isRequired: false, transformFunction: null }, keepFocus: { classPropertyName: "keepFocus", publicName: "keepFocus", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { beforeNavigate: "beforeNavigate" }, host: { properties: { "attr.href": "href()", "attr.aria-current": "ariaCurrent()", "attr.rel": "attr('rel')", "attr.data-hamur-prefetch": "attr('data-hamur-prefetch')", "attr.data-hamur-replace": "attr('data-hamur-replace')", "attr.data-hamur-view-transition": "attr('data-hamur-view-transition')", "attr.data-hamur-pending-class": "attr('data-hamur-pending-class')", "attr.data-hamur-trim": "attr('data-hamur-trim')", "attr.data-hamur-mask": "attr('data-hamur-mask')", "attr.data-hamur-unmask": "attr('data-hamur-unmask')", "attr.data-hamur-prefetched-class": "attr('data-hamur-prefetched-class')", "attr.data-hamur-scroll": "attr('data-hamur-scroll')", "attr.data-hamur-prefetch-delay": "attr('data-hamur-prefetch-delay')", "attr.data-hamur-keepfocus": "keepFocusValue()", "class": "classes()" } }, providers: [{ provide: LINK_HREF, useExisting: forwardRef(() => Link) }], ngImport: i0 });
|
|
187
131
|
}
|
|
188
|
-
|
|
132
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Link, decorators: [{
|
|
133
|
+
type: Directive,
|
|
134
|
+
args: [{
|
|
135
|
+
selector: "a[hamurLink]",
|
|
136
|
+
providers: [{ provide: LINK_HREF, useExisting: forwardRef(() => Link) }],
|
|
137
|
+
host: {
|
|
138
|
+
"[attr.href]": "href()",
|
|
139
|
+
"[attr.aria-current]": "ariaCurrent()",
|
|
140
|
+
"[attr.rel]": "attr('rel')",
|
|
141
|
+
"[attr.data-hamur-prefetch]": "attr('data-hamur-prefetch')",
|
|
142
|
+
"[attr.data-hamur-replace]": "attr('data-hamur-replace')",
|
|
143
|
+
"[attr.data-hamur-view-transition]": "attr('data-hamur-view-transition')",
|
|
144
|
+
"[attr.data-hamur-pending-class]": "attr('data-hamur-pending-class')",
|
|
145
|
+
"[attr.data-hamur-trim]": "attr('data-hamur-trim')",
|
|
146
|
+
"[attr.data-hamur-mask]": "attr('data-hamur-mask')",
|
|
147
|
+
"[attr.data-hamur-unmask]": "attr('data-hamur-unmask')",
|
|
148
|
+
"[attr.data-hamur-prefetched-class]": "attr('data-hamur-prefetched-class')",
|
|
149
|
+
"[attr.data-hamur-scroll]": "attr('data-hamur-scroll')",
|
|
150
|
+
"[attr.data-hamur-prefetch-delay]": "attr('data-hamur-prefetch-delay')",
|
|
151
|
+
"[attr.data-hamur-keepfocus]": "keepFocusValue()",
|
|
152
|
+
"[class]": "classes()",
|
|
153
|
+
},
|
|
154
|
+
}]
|
|
155
|
+
}], ctorParameters: () => [], propDecorators: { to: [{ type: i0.Input, args: [{ isSignal: true, alias: "hamurLink", required: true }] }], replace: [{ type: i0.Input, args: [{ isSignal: true, alias: "replace", required: false }] }], prefetch: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetch", required: false }] }], prefetchOn: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetchOn", required: false }] }], prefetchDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetchDelay", required: false }] }], viewTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewTransition", required: false }] }], query: [{ type: i0.Input, args: [{ isSignal: true, alias: "query", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], relative: [{ type: i0.Input, args: [{ isSignal: true, alias: "relative", required: false }] }], mask: [{ type: i0.Input, args: [{ isSignal: true, alias: "mask", required: false }] }], unmaskOnReload: [{ type: i0.Input, args: [{ isSignal: true, alias: "unmaskOnReload", required: false }] }], activeClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeClass", required: false }] }], exactActiveClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "exactActiveClass", required: false }] }], pendingClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "pendingClass", required: false }] }], prefetchedClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetchedClass", required: false }] }], ariaCurrentValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaCurrentValue", required: false }] }], external: [{ type: i0.Input, args: [{ isSignal: true, alias: "external", required: false }] }], noRel: [{ type: i0.Input, args: [{ isSignal: true, alias: "noRel", required: false }] }], scroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "scroll", required: false }] }], keepFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "keepFocus", required: false }] }], beforeNavigate: [{ type: i0.Output, args: ["beforeNavigate"] }] } });
|
|
189
156
|
/** The `LinkSlot` of a link to `to`, for an element that renders its own `<a>`; `app.link` sets its defaults. */
|
|
190
|
-
export function injectLink
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
router,
|
|
240
|
-
})
|
|
241
|
-
})
|
|
157
|
+
export function injectLink(to, options) {
|
|
158
|
+
assertInInjectionContext(injectLink);
|
|
159
|
+
const app = inject(HAMUR_APP, { optional: true });
|
|
160
|
+
const route = inject(HAMUR_ROUTE, { optional: true });
|
|
161
|
+
const router = inject(HAMUR_ROUTER, { optional: true });
|
|
162
|
+
const navigation = inject(HAMUR_NAVIGATION, { optional: true });
|
|
163
|
+
const resolve = inject(HAMUR_HREF, { optional: true }) ?? detachedHref;
|
|
164
|
+
const baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/";
|
|
165
|
+
return computed(() => {
|
|
166
|
+
const given = (typeof options === "function" ? options() : options) ?? {};
|
|
167
|
+
const defaults = linkDefaultsOf(app);
|
|
168
|
+
const base = (typeof to === "function" ? to() : to);
|
|
169
|
+
const current = route?.();
|
|
170
|
+
const searched = current ? searchTarget(relativeTarget(base, current, given.relative), current, given.query) : base;
|
|
171
|
+
const { to: target } = resolveLinkTarget(app, searched, given, resolve, given.external);
|
|
172
|
+
const href = resolve(target);
|
|
173
|
+
const state = current
|
|
174
|
+
? linkState(typeof target === "string" ? target : withoutBase(href, baseURL), current)
|
|
175
|
+
: { active: false, exact: false };
|
|
176
|
+
return createLinkSlot({
|
|
177
|
+
href,
|
|
178
|
+
to: target,
|
|
179
|
+
attrs: linkAttributes({
|
|
180
|
+
href,
|
|
181
|
+
external: given.external,
|
|
182
|
+
...linkPrefetchProps({}, defaults),
|
|
183
|
+
replace: given.replace,
|
|
184
|
+
viewTransition: given.viewTransition,
|
|
185
|
+
pendingClass: defaults.pendingClass,
|
|
186
|
+
trim: !!given.query,
|
|
187
|
+
ariaCurrent: state.exact ? "page" : undefined,
|
|
188
|
+
prefetchedClass: defaults.prefetchedClass,
|
|
189
|
+
scroll: given.scroll,
|
|
190
|
+
prefetchDelay: defaults.prefetchDelay,
|
|
191
|
+
externalRelAttribute: defaults.externalRelAttribute,
|
|
192
|
+
}),
|
|
193
|
+
active: state.active,
|
|
194
|
+
exact: state.exact,
|
|
195
|
+
pending: navigation ? linkPending(href, navigation(), baseURL) : false,
|
|
196
|
+
external: given.external,
|
|
197
|
+
options: {
|
|
198
|
+
replace: given.replace,
|
|
199
|
+
state: given.state,
|
|
200
|
+
viewTransition: given.viewTransition,
|
|
201
|
+
scroll: given.scroll === false ? false : undefined,
|
|
202
|
+
},
|
|
203
|
+
router,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
242
206
|
}
|
|
243
|
-
|
|
244
207
|
/** Inside a `Link`'s content, whether a navigation to that link is in flight; `false` anywhere else. */
|
|
245
|
-
export function injectLinkStatus()
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
208
|
+
export function injectLinkStatus() {
|
|
209
|
+
assertInInjectionContext(injectLinkStatus);
|
|
210
|
+
const link = inject(LINK_HREF, { optional: true });
|
|
211
|
+
const navigation = inject(HAMUR_NAVIGATION, { optional: true });
|
|
212
|
+
const baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/";
|
|
213
|
+
return { pending: computed(() => !!link && !!navigation && linkPending(link.href(), navigation(), baseURL)) };
|
|
251
214
|
}
|