@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/indicators.ts
CHANGED
|
@@ -1,251 +1,220 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
HostAttributeToken,
|
|
6
|
-
Injector,
|
|
7
|
-
afterNextRender,
|
|
8
|
-
afterRenderEffect,
|
|
9
|
-
assertInInjectionContext,
|
|
10
|
-
computed,
|
|
11
|
-
effect,
|
|
12
|
-
inject,
|
|
13
|
-
input,
|
|
14
|
-
runInInjectionContext,
|
|
15
|
-
signal,
|
|
16
|
-
untracked,
|
|
17
|
-
viewChild,
|
|
18
|
-
type OnInit,
|
|
19
|
-
type Signal,
|
|
20
|
-
} from "@angular/core"
|
|
21
|
-
import {
|
|
22
|
-
ANNOUNCER_ASSERTIVE_ID,
|
|
23
|
-
ANNOUNCER_POLITE_ID,
|
|
24
|
-
ROUTE_ANNOUNCER_ID,
|
|
25
|
-
announcerActions,
|
|
26
|
-
announcerRole,
|
|
27
|
-
createAnnouncer,
|
|
28
|
-
createLoadingIndicator,
|
|
29
|
-
createRouteAnnouncer,
|
|
30
|
-
hideAnnouncer,
|
|
31
|
-
loadingIndicatorOptions,
|
|
32
|
-
paintLoadingIndicator,
|
|
33
|
-
} from "hamur/adapter"
|
|
34
|
-
import type {
|
|
35
|
-
AnnouncerActions,
|
|
36
|
-
AnnouncerPoliteness,
|
|
37
|
-
LoadingIndicatorActions,
|
|
38
|
-
LoadingIndicatorOptions,
|
|
39
|
-
RouteAnnouncerActions,
|
|
40
|
-
RouteAnnouncerPoliteness,
|
|
41
|
-
} from "hamur/adapter"
|
|
42
|
-
import { HAMUR_APP, HAMUR_NAVIGATION, required } from "./context.ts"
|
|
43
|
-
|
|
1
|
+
import { Component, DestroyRef, ElementRef, HostAttributeToken, Injector, afterNextRender, afterRenderEffect, assertInInjectionContext, computed, effect, inject, input, runInInjectionContext, signal, untracked, viewChild, } from "@angular/core";
|
|
2
|
+
import { ANNOUNCER_ASSERTIVE_ID, ANNOUNCER_POLITE_ID, ROUTE_ANNOUNCER_ID, announcerActions, announcerRole, createAnnouncer, createLoadingIndicator, createRouteAnnouncer, hideAnnouncer, loadingIndicatorOptions, paintLoadingIndicator, } from "hamur/adapter";
|
|
3
|
+
import { HAMUR_APP, HAMUR_NAVIGATION, required } from "./context.ts";
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
44
5
|
/** The bar's state as signals, and its `start`, `finish`, `set` and `clear`; it follows the navigation while a component that called it is alive. */
|
|
45
|
-
export function injectLoadingIndicator(options
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
start: store.start,
|
|
87
|
-
finish: store.finish,
|
|
88
|
-
set: store.set,
|
|
89
|
-
clear: store.clear,
|
|
90
|
-
}
|
|
6
|
+
export function injectLoadingIndicator(options) {
|
|
7
|
+
assertInInjectionContext(injectLoadingIndicator);
|
|
8
|
+
const store = createLoadingIndicator(required(HAMUR_APP, "injectLoadingIndicator"), options);
|
|
9
|
+
const navigation = required(HAMUR_NAVIGATION, "injectLoadingIndicator");
|
|
10
|
+
const state = signal(store.get(), /* @ts-ignore */
|
|
11
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
12
|
+
const injector = inject(Injector);
|
|
13
|
+
const destroy = inject(DestroyRef);
|
|
14
|
+
afterNextRender(() => {
|
|
15
|
+
state.set(store.get());
|
|
16
|
+
const stopState = store.subscribe(() => state.set(store.get()));
|
|
17
|
+
const listeners = new Set();
|
|
18
|
+
const watcher = effect(() => {
|
|
19
|
+
navigation();
|
|
20
|
+
untracked(() => {
|
|
21
|
+
for (const listener of [...listeners])
|
|
22
|
+
listener();
|
|
23
|
+
});
|
|
24
|
+
}, { ...(ngDevMode ? { debugName: "watcher" } : /* istanbul ignore next */ {}), injector });
|
|
25
|
+
const stopFollow = store.follow({
|
|
26
|
+
get: () => untracked(navigation),
|
|
27
|
+
subscribe(listener) {
|
|
28
|
+
listeners.add(listener);
|
|
29
|
+
return () => void listeners.delete(listener);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
destroy.onDestroy(() => {
|
|
33
|
+
stopState();
|
|
34
|
+
stopFollow();
|
|
35
|
+
watcher.destroy();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
progress: computed(() => state().progress),
|
|
40
|
+
isLoading: computed(() => state().isLoading),
|
|
41
|
+
error: computed(() => state().error),
|
|
42
|
+
start: store.start,
|
|
43
|
+
finish: store.finish,
|
|
44
|
+
set: store.set,
|
|
45
|
+
clear: store.clear,
|
|
46
|
+
};
|
|
91
47
|
}
|
|
92
|
-
|
|
93
48
|
/**
|
|
94
49
|
* `<hamur-loading-indicator />`, the bar at the top of the page that follows `injectNavigation().state`. Its look is
|
|
95
50
|
* written through `element.style` after the first render, so the server's element has no `style` attribute.
|
|
96
51
|
*/
|
|
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
|
-
{ progress: progress(), isLoading: isLoading(), error: error() },
|
|
125
|
-
{ color: this.color(), errorColor: this.errorColor(), height: this.height() },
|
|
126
|
-
),
|
|
127
|
-
)
|
|
128
|
-
})
|
|
129
|
-
}
|
|
52
|
+
export class LoadingIndicator {
|
|
53
|
+
color = input(/* @ts-ignore */
|
|
54
|
+
...(ngDevMode ? [undefined, { debugName: "color" }] : /* istanbul ignore next */ []));
|
|
55
|
+
errorColor = input(/* @ts-ignore */
|
|
56
|
+
...(ngDevMode ? [undefined, { debugName: "errorColor" }] : /* istanbul ignore next */ []));
|
|
57
|
+
height = input(/* @ts-ignore */
|
|
58
|
+
...(ngDevMode ? [undefined, { debugName: "height" }] : /* istanbul ignore next */ []));
|
|
59
|
+
duration = input(/* @ts-ignore */
|
|
60
|
+
...(ngDevMode ? [undefined, { debugName: "duration" }] : /* istanbul ignore next */ []));
|
|
61
|
+
throttle = input(/* @ts-ignore */
|
|
62
|
+
...(ngDevMode ? [undefined, { debugName: "throttle" }] : /* istanbul ignore next */ []));
|
|
63
|
+
estimatedProgress = input(/* @ts-ignore */
|
|
64
|
+
...(ngDevMode ? [undefined, { debugName: "estimatedProgress" }] : /* istanbul ignore next */ []));
|
|
65
|
+
injector = inject(Injector);
|
|
66
|
+
element = inject(ElementRef).nativeElement;
|
|
67
|
+
ngOnInit() {
|
|
68
|
+
runInInjectionContext(this.injector, () => {
|
|
69
|
+
const { progress, isLoading, error } = injectLoadingIndicator(loadingIndicatorOptions({
|
|
70
|
+
duration: this.duration(),
|
|
71
|
+
throttle: this.throttle(),
|
|
72
|
+
estimatedProgress: this.estimatedProgress(),
|
|
73
|
+
}));
|
|
74
|
+
afterRenderEffect(() => paintLoadingIndicator(this.element, { progress: progress(), isLoading: isLoading(), error: error() }, { color: this.color(), errorColor: this.errorColor(), height: this.height() }));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: LoadingIndicator, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
78
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: LoadingIndicator, isStandalone: true, selector: "hamur-loading-indicator", inputs: { color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: false, transformFunction: null }, errorColor: { classPropertyName: "errorColor", publicName: "errorColor", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, duration: { classPropertyName: "duration", publicName: "duration", isSignal: true, isRequired: false, transformFunction: null }, throttle: { classPropertyName: "throttle", publicName: "throttle", isSignal: true, isRequired: false, transformFunction: null }, estimatedProgress: { classPropertyName: "estimatedProgress", publicName: "estimatedProgress", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "data-hamur-loading-indicator": "", "aria-hidden": "true" } }, ngImport: i0, template: "", isInline: true });
|
|
130
79
|
}
|
|
131
|
-
|
|
80
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: LoadingIndicator, decorators: [{
|
|
81
|
+
type: Component,
|
|
82
|
+
args: [{
|
|
83
|
+
selector: "hamur-loading-indicator",
|
|
84
|
+
template: "",
|
|
85
|
+
host: { "data-hamur-loading-indicator": "", "aria-hidden": "true" },
|
|
86
|
+
}]
|
|
87
|
+
}], propDecorators: { color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: false }] }], errorColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorColor", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], duration: [{ type: i0.Input, args: [{ isSignal: true, alias: "duration", required: false }] }], throttle: [{ type: i0.Input, args: [{ isSignal: true, alias: "throttle", required: false }] }], estimatedProgress: [{ type: i0.Input, args: [{ isSignal: true, alias: "estimatedProgress", required: false }] }] } });
|
|
132
88
|
/** The page's route announcer as signals, and `set`, `polite` and `assertive`. */
|
|
133
|
-
export function injectRouteAnnouncer()
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
assertive: store.assertive,
|
|
151
|
-
}
|
|
89
|
+
export function injectRouteAnnouncer() {
|
|
90
|
+
assertInInjectionContext(injectRouteAnnouncer);
|
|
91
|
+
const store = createRouteAnnouncer(required(HAMUR_APP, "injectRouteAnnouncer"));
|
|
92
|
+
const state = signal(store.get(), /* @ts-ignore */
|
|
93
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
94
|
+
const destroy = inject(DestroyRef);
|
|
95
|
+
afterNextRender(() => {
|
|
96
|
+
state.set(store.get());
|
|
97
|
+
destroy.onDestroy(store.subscribe(() => state.set(store.get())));
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
message: computed(() => state().message),
|
|
101
|
+
politeness: computed(() => state().politeness),
|
|
102
|
+
set: store.set,
|
|
103
|
+
polite: store.polite,
|
|
104
|
+
assertive: store.assertive,
|
|
105
|
+
};
|
|
152
106
|
}
|
|
153
|
-
|
|
154
107
|
/**
|
|
155
108
|
* `<hamur-route-announcer />` is the region that speaks each navigation; the first one mounted holds `#__hamur_announcer`
|
|
156
109
|
* and the navigator's own region goes away while it is. A `politeness` pins `aria-live` and `role`; a `class` or `style` on the
|
|
157
110
|
* element keeps it visible.
|
|
158
111
|
*/
|
|
159
|
-
@Component({
|
|
160
|
-
selector: "hamur-route-announcer",
|
|
161
|
-
template: "",
|
|
162
|
-
host: {
|
|
163
|
-
"[attr.id]": "owner() ? id : null",
|
|
164
|
-
"[attr.aria-live]": "owner() ? live() : 'off'",
|
|
165
|
-
"aria-atomic": "true",
|
|
166
|
-
"[attr.role]": "owner() ? role() : null",
|
|
167
|
-
"[textContent]": "owner() ? message() : ''",
|
|
168
|
-
},
|
|
169
|
-
})
|
|
170
112
|
export class RouteAnnouncer {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
inject(new HostAttributeToken("class"), { optional: true }) !== null ||
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
113
|
+
politeness = input(/* @ts-ignore */
|
|
114
|
+
...(ngDevMode ? [undefined, { debugName: "politeness" }] : /* istanbul ignore next */ []));
|
|
115
|
+
id = ROUTE_ANNOUNCER_ID;
|
|
116
|
+
store = createRouteAnnouncer(required(HAMUR_APP, "RouteAnnouncer"));
|
|
117
|
+
state = injectRouteAnnouncer();
|
|
118
|
+
element = inject(ElementRef).nativeElement;
|
|
119
|
+
styled = inject(new HostAttributeToken("class"), { optional: true }) !== null ||
|
|
120
|
+
inject(new HostAttributeToken("style"), { optional: true }) !== null;
|
|
121
|
+
key = {};
|
|
122
|
+
tick = signal(0, /* @ts-ignore */
|
|
123
|
+
...(ngDevMode ? [{ debugName: "tick" }] : /* istanbul ignore next */ []));
|
|
124
|
+
message = this.state.message;
|
|
125
|
+
live = computed(() => this.politeness() ?? this.state.politeness(), /* @ts-ignore */
|
|
126
|
+
...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
127
|
+
role = computed(() => announcerRole(this.live()), /* @ts-ignore */
|
|
128
|
+
...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
|
|
129
|
+
owner = computed(() => {
|
|
130
|
+
this.tick();
|
|
131
|
+
return this.store.claim(this.key, () => this.tick.update((count) => count + 1));
|
|
132
|
+
}, /* @ts-ignore */
|
|
133
|
+
...(ngDevMode ? [{ debugName: "owner" }] : /* istanbul ignore next */ []));
|
|
134
|
+
constructor() {
|
|
135
|
+
afterRenderEffect((onCleanup) => {
|
|
136
|
+
if (!this.owner())
|
|
137
|
+
return;
|
|
138
|
+
onCleanup(this.store.mount());
|
|
139
|
+
if (!this.styled)
|
|
140
|
+
hideAnnouncer(this.element);
|
|
141
|
+
});
|
|
142
|
+
inject(DestroyRef).onDestroy(() => this.store.release(this.key));
|
|
143
|
+
}
|
|
144
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: RouteAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
145
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: RouteAnnouncer, isStandalone: true, selector: "hamur-route-announcer", inputs: { politeness: { classPropertyName: "politeness", publicName: "politeness", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "aria-atomic": "true" }, properties: { "attr.id": "owner() ? id : null", "attr.aria-live": "owner() ? live() : 'off'", "attr.role": "owner() ? role() : null", "textContent": "owner() ? message() : ''" } }, ngImport: i0, template: "", isInline: true });
|
|
198
146
|
}
|
|
199
|
-
|
|
147
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: RouteAnnouncer, decorators: [{
|
|
148
|
+
type: Component,
|
|
149
|
+
args: [{
|
|
150
|
+
selector: "hamur-route-announcer",
|
|
151
|
+
template: "",
|
|
152
|
+
host: {
|
|
153
|
+
"[attr.id]": "owner() ? id : null",
|
|
154
|
+
"[attr.aria-live]": "owner() ? live() : 'off'",
|
|
155
|
+
"aria-atomic": "true",
|
|
156
|
+
"[attr.role]": "owner() ? role() : null",
|
|
157
|
+
"[textContent]": "owner() ? message() : ''",
|
|
158
|
+
},
|
|
159
|
+
}]
|
|
160
|
+
}], ctorParameters: () => [], propDecorators: { politeness: [{ type: i0.Input, args: [{ isSignal: true, alias: "politeness", required: false }] }] } });
|
|
200
161
|
/** The page's announcer as signals, and `set`, `polite` and `assertive` (`polite` unless `politeness` says otherwise). */
|
|
201
|
-
export function injectAnnouncer({ politeness = "polite" }
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
...announcerActions(store, politeness),
|
|
217
|
-
}
|
|
162
|
+
export function injectAnnouncer({ politeness = "polite" } = {}) {
|
|
163
|
+
assertInInjectionContext(injectAnnouncer);
|
|
164
|
+
const store = createAnnouncer(required(HAMUR_APP, "injectAnnouncer"));
|
|
165
|
+
const state = signal(store.get(), /* @ts-ignore */
|
|
166
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
167
|
+
const destroy = inject(DestroyRef);
|
|
168
|
+
afterNextRender(() => {
|
|
169
|
+
state.set(store.get());
|
|
170
|
+
destroy.onDestroy(store.subscribe(() => state.set(store.get())));
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
message: computed(() => state().message),
|
|
174
|
+
politeness: computed(() => state().politeness),
|
|
175
|
+
...announcerActions(store, politeness),
|
|
176
|
+
};
|
|
218
177
|
}
|
|
219
|
-
|
|
220
178
|
/** `<hamur-announcer />` holds the two regions `injectAnnouncer()` writes to: `#__hamur_announcer_polite` and `#__hamur_announcer_assertive`. */
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
179
|
+
export class Announcer {
|
|
180
|
+
politeId = ANNOUNCER_POLITE_ID;
|
|
181
|
+
assertiveId = ANNOUNCER_ASSERTIVE_ID;
|
|
182
|
+
store = createAnnouncer(required(HAMUR_APP, "Announcer"));
|
|
183
|
+
state = signal(this.store.get(), /* @ts-ignore */
|
|
184
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
185
|
+
regions = computed(() => this.state().regions, /* @ts-ignore */
|
|
186
|
+
...(ngDevMode ? [{ debugName: "regions" }] : /* istanbul ignore next */ []));
|
|
187
|
+
polite = viewChild.required("polite", /* @ts-ignore */
|
|
188
|
+
...(ngDevMode ? [{ debugName: "polite" }] : /* istanbul ignore next */ []));
|
|
189
|
+
assertive = viewChild.required("assertive", /* @ts-ignore */
|
|
190
|
+
...(ngDevMode ? [{ debugName: "assertive" }] : /* istanbul ignore next */ []));
|
|
191
|
+
constructor() {
|
|
192
|
+
const destroy = inject(DestroyRef);
|
|
193
|
+
afterNextRender(() => {
|
|
194
|
+
this.state.set(this.store.get());
|
|
195
|
+
hideAnnouncer(this.polite().nativeElement);
|
|
196
|
+
hideAnnouncer(this.assertive().nativeElement);
|
|
197
|
+
const stop = this.store.subscribe(() => this.state.set(this.store.get()));
|
|
198
|
+
const unmount = this.store.mount();
|
|
199
|
+
destroy.onDestroy(() => {
|
|
200
|
+
stop();
|
|
201
|
+
unmount();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Announcer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
206
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.3.2", type: Announcer, isStandalone: true, selector: "hamur-announcer", viewQueries: [{ propertyName: "polite", first: true, predicate: ["polite"], descendants: true, isSignal: true }, { propertyName: "assertive", first: true, predicate: ["assertive"], descendants: true, isSignal: true }], ngImport: i0, template: `<div #polite [attr.id]="politeId" aria-live="polite" aria-atomic="true" role="status">{{ regions().polite }}</div
|
|
224
207
|
><div #assertive [attr.id]="assertiveId" aria-live="assertive" aria-atomic="true" role="alert">{{
|
|
225
208
|
regions().assertive
|
|
226
|
-
}}</div>`,
|
|
227
|
-
})
|
|
228
|
-
export class Announcer {
|
|
229
|
-
protected readonly politeId = ANNOUNCER_POLITE_ID
|
|
230
|
-
protected readonly assertiveId = ANNOUNCER_ASSERTIVE_ID
|
|
231
|
-
private readonly store = createAnnouncer(required(HAMUR_APP, "Announcer"))
|
|
232
|
-
private readonly state = signal(this.store.get())
|
|
233
|
-
protected readonly regions = computed(() => this.state().regions)
|
|
234
|
-
private readonly polite = viewChild.required<ElementRef<HTMLElement>>("polite")
|
|
235
|
-
private readonly assertive = viewChild.required<ElementRef<HTMLElement>>("assertive")
|
|
236
|
-
|
|
237
|
-
constructor() {
|
|
238
|
-
const destroy = inject(DestroyRef)
|
|
239
|
-
afterNextRender(() => {
|
|
240
|
-
this.state.set(this.store.get())
|
|
241
|
-
hideAnnouncer(this.polite().nativeElement)
|
|
242
|
-
hideAnnouncer(this.assertive().nativeElement)
|
|
243
|
-
const stop = this.store.subscribe(() => this.state.set(this.store.get()))
|
|
244
|
-
const unmount = this.store.mount()
|
|
245
|
-
destroy.onDestroy(() => {
|
|
246
|
-
stop()
|
|
247
|
-
unmount()
|
|
248
|
-
})
|
|
249
|
-
})
|
|
250
|
-
}
|
|
209
|
+
}}</div>`, isInline: true });
|
|
251
210
|
}
|
|
211
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Announcer, decorators: [{
|
|
212
|
+
type: Component,
|
|
213
|
+
args: [{
|
|
214
|
+
selector: "hamur-announcer",
|
|
215
|
+
template: `<div #polite [attr.id]="politeId" aria-live="polite" aria-atomic="true" role="status">{{ regions().polite }}</div
|
|
216
|
+
><div #assertive [attr.id]="assertiveId" aria-live="assertive" aria-atomic="true" role="alert">{{
|
|
217
|
+
regions().assertive
|
|
218
|
+
}}</div>`,
|
|
219
|
+
}]
|
|
220
|
+
}], ctorParameters: () => [], propDecorators: { polite: [{ type: i0.ViewChild, args: ["polite", { isSignal: true }] }], assertive: [{ type: i0.ViewChild, args: ["assertive", { isSignal: true }] }] } });
|
package/src/island.ts
CHANGED
|
@@ -1,95 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
InjectionToken,
|
|
7
|
-
Injector,
|
|
8
|
-
PendingTasks,
|
|
9
|
-
Renderer2,
|
|
10
|
-
booleanAttribute,
|
|
11
|
-
inject,
|
|
12
|
-
input,
|
|
13
|
-
type OnInit,
|
|
14
|
-
type TemplateRef,
|
|
15
|
-
type Type,
|
|
16
|
-
} from "@angular/core"
|
|
17
|
-
import { ISLAND_ELEMENT, renderIsland } from "hamur/adapter"
|
|
18
|
-
import type { IslandOn } from "hamur/adapter"
|
|
19
|
-
import { injectId } from "./client-parts.ts"
|
|
20
|
-
import { HAMUR_APP, HAMUR_FAIL, onServer } from "./context.ts"
|
|
21
|
-
|
|
1
|
+
import { ApplicationRef, Component, DestroyRef, ElementRef, InjectionToken, Injector, PendingTasks, Renderer2, booleanAttribute, inject, input, } from "@angular/core";
|
|
2
|
+
import { ISLAND_ELEMENT, renderIsland } from "hamur/adapter";
|
|
3
|
+
import { injectId } from "./client-parts.ts";
|
|
4
|
+
import { HAMUR_APP, HAMUR_FAIL, onServer } from "./context.ts";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
22
6
|
/** A component that writes its own nodes below its host: a template it renders there is a view the application checks. */
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
7
|
+
export class HostWriter {
|
|
8
|
+
host = inject(ElementRef).nativeElement;
|
|
9
|
+
renderer = inject(Renderer2);
|
|
10
|
+
appRef = inject(ApplicationRef);
|
|
11
|
+
injector = inject(Injector);
|
|
12
|
+
destroyRef = inject(DestroyRef);
|
|
13
|
+
append(template, into = this.host) {
|
|
14
|
+
const view = template.createEmbeddedView({}, this.injector);
|
|
15
|
+
this.appRef.attachView(view);
|
|
16
|
+
for (const node of view.rootNodes)
|
|
17
|
+
this.renderer.appendChild(into, node);
|
|
18
|
+
this.destroyRef.onDestroy(() => view.destroy());
|
|
19
|
+
}
|
|
36
20
|
}
|
|
37
|
-
|
|
38
21
|
/** The element the core's islands runtime reads, `<appId>-island` of the build; a token, so a test gives it another app id. */
|
|
39
|
-
export const HAMUR_ISLAND_ELEMENT = new InjectionToken
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
|
|
22
|
+
export const HAMUR_ISLAND_ELEMENT = new InjectionToken("hamur island element", {
|
|
23
|
+
providedIn: "root",
|
|
24
|
+
factory: () => ISLAND_ELEMENT,
|
|
25
|
+
});
|
|
44
26
|
/**
|
|
45
27
|
* On an island page, `component` rendered on the server as an application of its own inside `<hamur-island>`,
|
|
46
28
|
* hydrated on its own in the browser; `fallback` is what the server renders under `on="only"`. Its template is empty: the island's
|
|
47
29
|
* HTML is written below its host on the server and left as it is in the browser. The host is the core's element when the app id is
|
|
48
30
|
* `hamur`; under another app id the host holds `<appId>-island`, which the runtime reads.
|
|
49
31
|
*/
|
|
50
|
-
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
32
|
+
export class Island extends HostWriter {
|
|
33
|
+
/** The default export of a file under `app/islands/`. */
|
|
34
|
+
component = input.required(/* @ts-ignore */
|
|
35
|
+
...(ngDevMode ? [{ debugName: "component" }] : /* istanbul ignore next */ []));
|
|
36
|
+
props = input(/* @ts-ignore */
|
|
37
|
+
...(ngDevMode ? [undefined, { debugName: "props" }] : /* istanbul ignore next */ []));
|
|
38
|
+
/** The island directive: when the island hydrates, `"only"` to mount it in the browser alone, or a directive a module adds; default `"load"`. */
|
|
39
|
+
on = input(/* @ts-ignore */
|
|
40
|
+
...(ngDevMode ? [undefined, { debugName: "on" }] : /* istanbul ignore next */ []));
|
|
41
|
+
fallback = input(/* @ts-ignore */
|
|
42
|
+
...(ngDevMode ? [undefined, { debugName: "fallback" }] : /* istanbul ignore next */ []));
|
|
43
|
+
/** The island's id across swaps; a swap to a page with the same id keeps its element and state. */
|
|
44
|
+
persist = input(/* @ts-ignore */
|
|
45
|
+
...(ngDevMode ? [undefined, { debugName: "persist" }] : /* istanbul ignore next */ []));
|
|
46
|
+
/** With `persist`, a swap keeps the island's old props. */
|
|
47
|
+
persistProps = input(false, { ...(ngDevMode ? { debugName: "persistProps" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
48
|
+
app = inject(HAMUR_APP, { optional: true });
|
|
49
|
+
id = injectId();
|
|
50
|
+
tasks = inject(PendingTasks);
|
|
51
|
+
fail = inject(HAMUR_FAIL, { optional: true });
|
|
52
|
+
server = onServer();
|
|
53
|
+
element = inject(HAMUR_ISLAND_ELEMENT);
|
|
54
|
+
constructor() {
|
|
55
|
+
super();
|
|
56
|
+
if (!this.app)
|
|
57
|
+
throw new Error("Island must be rendered inside a Hamur app");
|
|
58
|
+
}
|
|
59
|
+
ngOnInit() {
|
|
60
|
+
if (!this.server)
|
|
61
|
+
return;
|
|
62
|
+
const island = renderIsland(this.app, this.id, this.component(), this.props() ?? {}, this.on(), undefined, {
|
|
63
|
+
persist: this.persist(),
|
|
64
|
+
persistProps: this.persistProps(),
|
|
65
|
+
});
|
|
66
|
+
const element = this.host.localName === this.element ? this.host : this.renderer.createElement(this.element);
|
|
67
|
+
if (element !== this.host)
|
|
68
|
+
this.renderer.appendChild(this.host, element);
|
|
69
|
+
for (const [name, value] of Object.entries(island.attributes))
|
|
70
|
+
this.renderer.setAttribute(element, name, value);
|
|
71
|
+
if (!island.html) {
|
|
72
|
+
const fallback = this.fallback();
|
|
73
|
+
if (fallback)
|
|
74
|
+
this.append(fallback, element);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const done = this.tasks.add();
|
|
78
|
+
island.html
|
|
79
|
+
.then((html) => this.renderer.setProperty(element, "innerHTML", html))
|
|
80
|
+
.catch((error) => this.fail?.(error))
|
|
81
|
+
.finally(done);
|
|
88
82
|
}
|
|
89
|
-
|
|
90
|
-
island
|
|
91
|
-
.then((html) => this.renderer.setProperty(element, "innerHTML", html))
|
|
92
|
-
.catch((error: unknown) => this.fail?.(error))
|
|
93
|
-
.finally(done)
|
|
94
|
-
}
|
|
83
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Island, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
84
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: Island, isStandalone: true, selector: "hamur-island", inputs: { component: { classPropertyName: "component", publicName: "component", isSignal: true, isRequired: true, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, on: { classPropertyName: "on", publicName: "on", isSignal: true, isRequired: false, transformFunction: null }, fallback: { classPropertyName: "fallback", publicName: "fallback", isSignal: true, isRequired: false, transformFunction: null }, persist: { classPropertyName: "persist", publicName: "persist", isSignal: true, isRequired: false, transformFunction: null }, persistProps: { classPropertyName: "persistProps", publicName: "persistProps", isSignal: true, isRequired: false, transformFunction: null } }, usesInheritance: true, ngImport: i0, template: "", isInline: true });
|
|
95
85
|
}
|
|
86
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Island, decorators: [{
|
|
87
|
+
type: Component,
|
|
88
|
+
args: [{ selector: "hamur-island", template: "" }]
|
|
89
|
+
}], ctorParameters: () => [], propDecorators: { component: [{ type: i0.Input, args: [{ isSignal: true, alias: "component", required: true }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], on: [{ type: i0.Input, args: [{ isSignal: true, alias: "on", required: false }] }], fallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "fallback", required: false }] }], persist: [{ type: i0.Input, args: [{ isSignal: true, alias: "persist", required: false }] }], persistProps: [{ type: i0.Input, args: [{ isSignal: true, alias: "persistProps", required: false }] }] } });
|