@hamur/adapter-angular 0.0.1 → 0.0.3

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/src/link.ts CHANGED
@@ -1,251 +1,214 @@
1
- import {
2
- DestroyRef,
3
- Directive,
4
- ElementRef,
5
- HostAttributeToken,
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<{ readonly href: Signal<string> }>("hamur link href")
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
- @Directive({
57
- selector: "a[hamurLink]",
58
- providers: [{ provide: LINK_HREF, useExisting: forwardRef(() => Link) }],
59
- host: {
60
- "[attr.href]": "href()",
61
- "[attr.aria-current]": "ariaCurrent()",
62
- "[attr.rel]": "attr('rel')",
63
- "[attr.data-hamur-prefetch]": "attr('data-hamur-prefetch')",
64
- "[attr.data-hamur-replace]": "attr('data-hamur-replace')",
65
- "[attr.data-hamur-view-transition]": "attr('data-hamur-view-transition')",
66
- "[attr.data-hamur-pending-class]": "attr('data-hamur-pending-class')",
67
- "[attr.data-hamur-trim]": "attr('data-hamur-trim')",
68
- "[attr.data-hamur-mask]": "attr('data-hamur-mask')",
69
- "[attr.data-hamur-unmask]": "attr('data-hamur-unmask')",
70
- "[attr.data-hamur-prefetched-class]": "attr('data-hamur-prefetched-class')",
71
- "[attr.data-hamur-scroll]": "attr('data-hamur-scroll')",
72
- "[attr.data-hamur-prefetch-delay]": "attr('data-hamur-prefetch-delay')",
73
- "[attr.data-hamur-keepfocus]": "keepFocusValue()",
74
- "[class]": "classes()",
75
- },
76
- })
77
- export class Link<T extends string = string> {
78
- readonly to = input.required<CheckedTarget<T> | RouteLocation>({ alias: "hamurLink" })
79
- readonly replace = input(false, { transform: booleanAttribute })
80
- readonly prefetch = input<boolean | undefined, unknown>(undefined, { transform: optionalBoolean })
81
- readonly prefetchOn = input<PrefetchOn>()
82
- readonly prefetchDelay = input<number | undefined, unknown>(undefined, {
83
- transform: (value: unknown) => (value === undefined ? undefined : numberAttribute(value)),
84
- })
85
- readonly viewTransition = input<ViewTransitionCall>()
86
- readonly query = input<Query>()
87
- readonly state = input<Record<string, unknown>>()
88
- readonly relative = input<"route">()
89
- readonly mask = input<string>()
90
- readonly unmaskOnReload = input<boolean | undefined, unknown>(undefined, { transform: optionalBoolean })
91
- readonly activeClass = input<string>()
92
- readonly exactActiveClass = input<string>()
93
- readonly pendingClass = input<string>()
94
- readonly prefetchedClass = input<string>()
95
- readonly ariaCurrentValue = input<AriaCurrent>("page")
96
- readonly external = input(false, { transform: booleanAttribute })
97
- readonly noRel = input(false, { transform: booleanAttribute })
98
- readonly scroll = input<boolean | undefined, unknown>(undefined, { transform: optionalBoolean })
99
- readonly keepFocus = input(false, { transform: booleanAttribute })
100
- readonly beforeNavigate = output<Navigation>()
101
-
102
- private readonly app = inject(HAMUR_APP, { optional: true })
103
- private readonly route = inject(HAMUR_ROUTE, { optional: true })
104
- private readonly resolve = inject(HAMUR_HREF, { optional: true }) ?? detachedHref
105
- private readonly baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/"
106
- private readonly element = inject<ElementRef<HTMLAnchorElement>>(ElementRef).nativeElement
107
- private readonly rel = inject(new HostAttributeToken("rel"), { optional: true })
108
- private readonly target = inject(new HostAttributeToken("target"), { optional: true })
109
- private readonly given = inject(new HostAttributeToken("aria-current"), { optional: true })
110
-
111
- private readonly defaults = computed(() => linkDefaultsOf(this.app))
112
- private readonly classNames = computed(() => ({
113
- active: this.activeClass() ?? this.defaults().activeClass,
114
- exact: this.exactActiveClass() ?? this.defaults().exactActiveClass,
115
- pending: this.pendingClass() ?? this.defaults().pendingClass,
116
- prefetched: this.prefetchedClass() ?? this.defaults().prefetchedClass,
117
- }))
118
- private readonly linked = computed(() => {
119
- const route = this.route?.()
120
- const to = this.to() as string | RouteLocation
121
- return resolveLinkTarget(
122
- this.app,
123
- route ? searchTarget(relativeTarget(to, route, this.relative()), route, this.query()) : to,
124
- {
125
- replace: this.replace(),
126
- prefetch: this.prefetch(),
127
- prefetchOn: this.prefetchOn(),
128
- external: this.external(),
129
- scroll: this.scroll(),
130
- mask: this.mask(),
131
- ...(this.target === null ? {} : { target: this.target }),
132
- },
133
- this.resolve,
134
- this.external(),
135
- )
136
- })
137
- private readonly matched = computed(() => {
138
- const route = this.route?.()
139
- const target = this.linked().to
140
- if (!route) return { active: false, exact: false }
141
- return linkState(typeof target === "string" ? target : withoutBase(this.href(), this.baseURL), route)
142
- })
143
-
144
- /** The based `href` of the link. */
145
- readonly href = computed(() => this.resolve(this.linked().to))
146
- protected readonly ariaCurrent = computed(
147
- () => this.given ?? (this.matched().exact ? this.ariaCurrentValue() : undefined),
148
- )
149
- protected readonly keepFocusValue = computed(() => (this.keepFocus() ? "" : undefined))
150
- protected readonly classes = computed(() => {
151
- const { active, exact } = this.matched()
152
- return [active && this.classNames().active, exact && this.classNames().exact].filter(Boolean).join(" ")
153
- })
154
- private readonly attrs = computed(() => {
155
- const defaults = this.defaults()
156
- return linkAttributes({
157
- href: this.href(),
158
- external: this.external(),
159
- ...linkPrefetchProps({ prefetch: this.prefetch(), prefetchOn: this.prefetchOn() }, defaults),
160
- replace: this.replace(),
161
- viewTransition: this.viewTransition(),
162
- pendingClass: this.classNames().pending,
163
- trim: !!this.query(),
164
- mask: this.mask() === undefined ? undefined : this.resolve(this.mask()!),
165
- unmaskOnReload: this.unmaskOnReload(),
166
- rel: this.rel ?? undefined,
167
- target: this.target ?? undefined,
168
- noRel: this.noRel(),
169
- prefetchedClass: this.classNames().prefetched,
170
- scroll: this.scroll(),
171
- prefetchDelay: this.prefetchDelay() ?? defaults.prefetchDelay,
172
- externalRelAttribute: defaults.externalRelAttribute,
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<T extends string = string>(
191
- to: CheckedTarget<T> | RouteLocation | (() => CheckedTarget<T> | RouteLocation),
192
- options?: UseLinkOptions | (() => UseLinkOptions),
193
- ): Signal<LinkSlot> {
194
- assertInInjectionContext(injectLink)
195
- const app = inject(HAMUR_APP, { optional: true })
196
- const route = inject(HAMUR_ROUTE, { optional: true })
197
- const router = inject(HAMUR_ROUTER, { optional: true })
198
- const navigation = inject(HAMUR_NAVIGATION, { optional: true })
199
- const resolve = inject(HAMUR_HREF, { optional: true }) ?? detachedHref
200
- const baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/"
201
- return computed(() => {
202
- const given = (typeof options === "function" ? options() : options) ?? {}
203
- const defaults = linkDefaultsOf(app)
204
- const base = (typeof to === "function" ? to() : to) as string | RouteLocation
205
- const current = route?.()
206
- const searched = current ? searchTarget(relativeTarget(base, current, given.relative), current, given.query) : base
207
- const { to: target } = resolveLinkTarget(app, searched, given, resolve, given.external)
208
- const href = resolve(target)
209
- const state = current
210
- ? linkState(typeof target === "string" ? target : withoutBase(href, baseURL), current)
211
- : { active: false, exact: false }
212
- return createLinkSlot({
213
- href,
214
- to: target,
215
- attrs: linkAttributes({
216
- href,
217
- external: given.external,
218
- ...linkPrefetchProps({}, defaults),
219
- replace: given.replace,
220
- viewTransition: given.viewTransition,
221
- pendingClass: defaults.pendingClass,
222
- trim: !!given.query,
223
- ariaCurrent: state.exact ? "page" : undefined,
224
- prefetchedClass: defaults.prefetchedClass,
225
- scroll: given.scroll,
226
- prefetchDelay: defaults.prefetchDelay,
227
- externalRelAttribute: defaults.externalRelAttribute,
228
- }),
229
- active: state.active,
230
- exact: state.exact,
231
- pending: navigation ? linkPending(href, navigation(), baseURL) : false,
232
- external: given.external,
233
- options: {
234
- replace: given.replace,
235
- state: given.state,
236
- viewTransition: given.viewTransition,
237
- scroll: given.scroll === false ? false : undefined,
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(): { pending: Signal<boolean> } {
246
- assertInInjectionContext(injectLinkStatus)
247
- const link = inject(LINK_HREF, { optional: true })
248
- const navigation = inject(HAMUR_NAVIGATION, { optional: true })
249
- const baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/"
250
- return { pending: computed(() => !!link && !!navigation && linkPending(link.href(), navigation(), baseURL)) }
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
  }