@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/outlet.ts
CHANGED
|
@@ -1,344 +1,316 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
computed,
|
|
9
|
-
effect,
|
|
10
|
-
inject,
|
|
11
|
-
input,
|
|
12
|
-
reflectComponentType,
|
|
13
|
-
untracked,
|
|
14
|
-
type ComponentRef,
|
|
15
|
-
type OnInit,
|
|
16
|
-
type Provider,
|
|
17
|
-
type Signal,
|
|
18
|
-
type Type,
|
|
19
|
-
} from "@angular/core"
|
|
20
|
-
import { noteOutlet, routeBoundary } from "hamur/adapter"
|
|
21
|
-
import type { KeptUnit, RenderContext, RenderEntry, RenderTree, RouteValue } from "hamur/adapter"
|
|
22
|
-
import type { ClearErrorOptions } from "hamur/app"
|
|
23
|
-
import { HAMUR_ACTIVATION, activation, detach, setHidden } from "./activation.ts"
|
|
24
|
-
import {
|
|
25
|
-
HAMUR_APP,
|
|
26
|
-
HAMUR_CAUGHT,
|
|
27
|
-
HAMUR_CONTEXT,
|
|
28
|
-
HAMUR_FAIL,
|
|
29
|
-
HAMUR_LEVEL,
|
|
30
|
-
HAMUR_LEVEL_DISPOSE,
|
|
31
|
-
HAMUR_OUTLET_CONTEXT,
|
|
32
|
-
HAMUR_PAYLOAD,
|
|
33
|
-
HAMUR_ROUTE,
|
|
34
|
-
HAMUR_TREE,
|
|
35
|
-
mode,
|
|
36
|
-
routeValue,
|
|
37
|
-
} from "./context.ts"
|
|
38
|
-
|
|
39
|
-
interface Shown {
|
|
40
|
-
entry: RenderEntry
|
|
41
|
-
ref: ComponentRef<unknown>
|
|
42
|
-
inputs: Set<string>
|
|
43
|
-
disposers: Set<() => void>
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const EMPTY: RenderTree = { components: [] }
|
|
47
|
-
const same = (a: RenderEntry, b: RenderEntry) => a.id === b.id && a.key === b.key && a.component === b.component
|
|
48
|
-
|
|
1
|
+
import { Component, DestroyRef, InjectionToken, Injector, PendingTasks, ViewContainerRef, computed, effect, inject, input, reflectComponentType, untracked, } from "@angular/core";
|
|
2
|
+
import { noteOutlet, routeBoundary } from "hamur/adapter";
|
|
3
|
+
import { HAMUR_ACTIVATION, activation, detach, setHidden } from "./activation.ts";
|
|
4
|
+
import { HAMUR_APP, HAMUR_CAUGHT, HAMUR_CONTEXT, HAMUR_FAIL, HAMUR_LEVEL, HAMUR_LEVEL_DISPOSE, HAMUR_OUTLET_CONTEXT, HAMUR_PAYLOAD, HAMUR_ROUTE, HAMUR_TREE, mode, routeValue, } from "./context.ts";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
const EMPTY = { components: [] };
|
|
7
|
+
const same = (a, b) => a.id === b.id && a.key === b.key && a.component === b.component;
|
|
49
8
|
/** `onError` gets a thrown value that is not an `Error` as the `cause` of one. */
|
|
50
|
-
const unwrap = (error
|
|
51
|
-
error instanceof Error && error.name === "ErrorBoundaryWrappedError" ? error.cause : error
|
|
52
|
-
|
|
9
|
+
const unwrap = (error) => error instanceof Error && error.name === "ErrorBoundaryWrappedError" ? error.cause : error;
|
|
53
10
|
/**
|
|
54
11
|
* Places the next level of the tree as its next sibling; the `hamur-outlet` element stays empty. With `name` it places
|
|
55
12
|
* the chain of that slot of the entry it sits in; `context` reaches the entries below through `injectOutletContext()`.
|
|
56
13
|
*/
|
|
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
|
-
this.apply(this.entry(), this.units())
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** The kept units of this outlet; `undefined` while the app has keep-alive off, so the outlet keeps one shape. */
|
|
125
|
-
private units(): KeptUnit[] | undefined {
|
|
126
|
-
if (this.name() !== undefined) return undefined
|
|
127
|
-
const tree = this.tree()
|
|
128
|
-
return (this.owner >= 0 ? tree.components[this.owner] : tree)?.kept
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Each kept unit hidden in its wrapper, then the current child, in the wrapper of its key when its route keeps its pages. */
|
|
132
|
-
private apply(entry: RenderEntry | undefined, units: KeptUnit[] | undefined): void {
|
|
133
|
-
if (units === undefined) {
|
|
134
|
-
this.dropPages()
|
|
135
|
-
this.show(entry)
|
|
136
|
-
return
|
|
14
|
+
export class Outlet {
|
|
15
|
+
name = input(/* @ts-ignore */
|
|
16
|
+
...(ngDevMode ? [undefined, { debugName: "name" }] : /* istanbul ignore next */ []));
|
|
17
|
+
context = input(/* @ts-ignore */
|
|
18
|
+
...(ngDevMode ? [undefined, { debugName: "context" }] : /* istanbul ignore next */ []));
|
|
19
|
+
tree = inject(HAMUR_TREE);
|
|
20
|
+
fail = inject(HAMUR_FAIL);
|
|
21
|
+
app = inject(HAMUR_APP);
|
|
22
|
+
payload = inject(HAMUR_PAYLOAD);
|
|
23
|
+
route = inject(HAMUR_ROUTE);
|
|
24
|
+
above = inject(HAMUR_OUTLET_CONTEXT, { optional: true });
|
|
25
|
+
owner = inject(HAMUR_LEVEL, { optional: true }) ?? -1;
|
|
26
|
+
injector = inject(Injector);
|
|
27
|
+
container = inject(ViewContainerRef);
|
|
28
|
+
pageContext = inject(HAMUR_CONTEXT);
|
|
29
|
+
tasks = inject(PendingTasks);
|
|
30
|
+
warned = new Set();
|
|
31
|
+
shown;
|
|
32
|
+
/** The keep-alive wrappers this outlet holds, by keep-alive key. */
|
|
33
|
+
pages = new Map();
|
|
34
|
+
started = false;
|
|
35
|
+
/** Counts what the level shows, so an answer that waits for a microtask finds out the level moved on. */
|
|
36
|
+
shownCount = 0;
|
|
37
|
+
/** The tree this outlet reads and the index of its entry in it. */
|
|
38
|
+
view = computed(() => {
|
|
39
|
+
const name = this.name();
|
|
40
|
+
const tree = this.tree();
|
|
41
|
+
if (name === undefined)
|
|
42
|
+
return { tree, index: this.owner + 1, slot: false };
|
|
43
|
+
return { tree: tree.components[this.owner]?.outlets?.[name], index: 0, slot: true };
|
|
44
|
+
}, /* @ts-ignore */
|
|
45
|
+
...(ngDevMode ? [{ debugName: "view" }] : /* istanbul ignore next */ []));
|
|
46
|
+
value = computed(() => {
|
|
47
|
+
const own = this.context();
|
|
48
|
+
return own !== undefined ? own : this.above?.();
|
|
49
|
+
}, /* @ts-ignore */
|
|
50
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
51
|
+
slotTree = computed(() => this.view().tree ?? EMPTY, /* @ts-ignore */
|
|
52
|
+
...(ngDevMode ? [{ debugName: "slotTree" }] : /* istanbul ignore next */ []));
|
|
53
|
+
slotRoute = computed(() => {
|
|
54
|
+
const slot = this.view().tree;
|
|
55
|
+
if (!slot?.route)
|
|
56
|
+
return undefined;
|
|
57
|
+
const { state, key, navigationType } = this.route();
|
|
58
|
+
return routeValue({
|
|
59
|
+
route: { ...slot.route, state, key, navigationType },
|
|
60
|
+
tree: slot,
|
|
61
|
+
app: this.app,
|
|
62
|
+
payload: this.payload(),
|
|
63
|
+
});
|
|
64
|
+
}, /* @ts-ignore */
|
|
65
|
+
...(ngDevMode ? [{ debugName: "slotRoute" }] : /* istanbul ignore next */ []));
|
|
66
|
+
constructor() {
|
|
67
|
+
inject(DestroyRef).onDestroy(() => {
|
|
68
|
+
this.shownCount++;
|
|
69
|
+
for (const dispose of this.shown?.disposers ?? [])
|
|
70
|
+
dispose();
|
|
71
|
+
});
|
|
72
|
+
effect(() => {
|
|
73
|
+
const entry = this.entry();
|
|
74
|
+
const units = this.units();
|
|
75
|
+
if (this.started)
|
|
76
|
+
untracked(() => this.apply(entry, units));
|
|
77
|
+
});
|
|
137
78
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.page(unit.key, unit, index++)
|
|
142
|
-
wanted.add(unit.key)
|
|
79
|
+
ngOnInit() {
|
|
80
|
+
this.started = true;
|
|
81
|
+
this.apply(this.entry(), this.units());
|
|
143
82
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!wanted.has(key)) {
|
|
151
|
-
ref.destroy()
|
|
152
|
-
this.pages.delete(key)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private page(key: string, unit: KeptUnit | undefined, index: number): void {
|
|
157
|
-
let ref = this.pages.get(key)
|
|
158
|
-
if (!ref) {
|
|
159
|
-
const injector = Injector.create({
|
|
160
|
-
providers: [
|
|
161
|
-
{
|
|
162
|
-
provide: KEPT_SOURCE,
|
|
163
|
-
useValue: { tree: this.tree, level: this.owner, route: this.route, payload: this.payload },
|
|
164
|
-
},
|
|
165
|
-
],
|
|
166
|
-
parent: this.injector,
|
|
167
|
-
})
|
|
168
|
-
ref = this.container.createComponent(KeptPage, { injector, index })
|
|
169
|
-
this.pages.set(key, ref)
|
|
83
|
+
/** The kept units of this outlet; `undefined` while the app has keep-alive off, so the outlet keeps one shape. */
|
|
84
|
+
units() {
|
|
85
|
+
if (this.name() !== undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
const tree = this.tree();
|
|
88
|
+
return (this.owner >= 0 ? tree.components[this.owner] : tree)?.kept;
|
|
170
89
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.warned.add(name)
|
|
197
|
-
console.warn(`Outlet name "${name}" has no slot in ${this.tree().components[this.owner]?.id}`)
|
|
198
|
-
}
|
|
90
|
+
/** Each kept unit hidden in its wrapper, then the current child, in the wrapper of its key when its route keeps its pages. */
|
|
91
|
+
apply(entry, units) {
|
|
92
|
+
if (units === undefined) {
|
|
93
|
+
this.dropPages();
|
|
94
|
+
this.show(entry);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const wanted = new Set();
|
|
98
|
+
let index = 0;
|
|
99
|
+
for (const unit of units) {
|
|
100
|
+
this.page(unit.key, unit, index++);
|
|
101
|
+
wanted.add(unit.key);
|
|
102
|
+
}
|
|
103
|
+
if (entry?.keepalive !== undefined) {
|
|
104
|
+
this.show(undefined);
|
|
105
|
+
this.page(entry.keepalive, undefined, index);
|
|
106
|
+
wanted.add(entry.keepalive);
|
|
107
|
+
}
|
|
108
|
+
else
|
|
109
|
+
this.show(entry);
|
|
110
|
+
for (const [key, ref] of this.pages)
|
|
111
|
+
if (!wanted.has(key)) {
|
|
112
|
+
ref.destroy();
|
|
113
|
+
this.pages.delete(key);
|
|
114
|
+
}
|
|
199
115
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
116
|
+
page(key, unit, index) {
|
|
117
|
+
let ref = this.pages.get(key);
|
|
118
|
+
if (!ref) {
|
|
119
|
+
const injector = Injector.create({
|
|
120
|
+
providers: [
|
|
121
|
+
{
|
|
122
|
+
provide: KEPT_SOURCE,
|
|
123
|
+
useValue: { tree: this.tree, level: this.owner, route: this.route, payload: this.payload },
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
parent: this.injector,
|
|
127
|
+
});
|
|
128
|
+
ref = this.container.createComponent(KeptPage, { injector, index });
|
|
129
|
+
this.pages.set(key, ref);
|
|
130
|
+
}
|
|
131
|
+
ref.setInput("name", key);
|
|
132
|
+
ref.setInput("unit", unit);
|
|
133
|
+
ref.setInput("hidden", unit !== undefined);
|
|
134
|
+
if (this.container.indexOf(ref.hostView) !== index)
|
|
135
|
+
this.container.move(ref.hostView, index);
|
|
209
136
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
private place(entry: RenderEntry): void {
|
|
216
|
-
const component = entry.component as Type<unknown>
|
|
217
|
-
const disposers = new Set<() => void>()
|
|
218
|
-
const providers: Provider[] = [
|
|
219
|
-
{ provide: HAMUR_LEVEL, useValue: this.view().index },
|
|
220
|
-
{ provide: HAMUR_LEVEL_DISPOSE, useValue: (dispose: () => void) => disposers.add(dispose) },
|
|
221
|
-
{ provide: HAMUR_OUTLET_CONTEXT, useValue: this.value },
|
|
222
|
-
]
|
|
223
|
-
if (entry.caught) providers.push({ provide: HAMUR_CAUGHT, useValue: (entry.props as { error: unknown }).error })
|
|
224
|
-
if (this.view().slot) {
|
|
225
|
-
providers.push({ provide: HAMUR_TREE, useValue: this.slotTree })
|
|
226
|
-
providers.push({ provide: HAMUR_ROUTE, useFactory: () => computed(() => this.slotRoute() ?? this.route()) })
|
|
137
|
+
dropPages() {
|
|
138
|
+
for (const ref of this.pages.values())
|
|
139
|
+
ref.destroy();
|
|
140
|
+
this.pages.clear();
|
|
227
141
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
failed(error)
|
|
142
|
+
dropShown() {
|
|
143
|
+
const shown = this.shown;
|
|
144
|
+
this.shown = undefined;
|
|
145
|
+
if (!shown)
|
|
146
|
+
return;
|
|
147
|
+
shown.ref.destroy();
|
|
148
|
+
for (const dispose of shown.disposers)
|
|
149
|
+
dispose();
|
|
237
150
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
151
|
+
entry() {
|
|
152
|
+
const { tree, index, slot } = this.view();
|
|
153
|
+
const name = this.name();
|
|
154
|
+
if (mode.dev) {
|
|
155
|
+
if (!slot)
|
|
156
|
+
noteOutlet(this.tree().components[this.owner]?.id);
|
|
157
|
+
else if (!tree && name !== undefined && !this.warned.has(name)) {
|
|
158
|
+
this.warned.add(name);
|
|
159
|
+
console.warn(`Outlet name "${name}" has no slot in ${this.tree().components[this.owner]?.id}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return tree?.components[index];
|
|
163
|
+
}
|
|
164
|
+
show(entry) {
|
|
165
|
+
const shown = this.shown;
|
|
166
|
+
if (shown && entry && same(shown.entry, entry)) {
|
|
167
|
+
shown.entry = entry;
|
|
168
|
+
this.setInputs(shown, entry);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.shownCount++;
|
|
172
|
+
this.dropShown();
|
|
173
|
+
if (entry)
|
|
174
|
+
this.place(entry);
|
|
175
|
+
}
|
|
176
|
+
place(entry) {
|
|
177
|
+
const component = entry.component;
|
|
178
|
+
const disposers = new Set();
|
|
179
|
+
const providers = [
|
|
180
|
+
{ provide: HAMUR_LEVEL, useValue: this.view().index },
|
|
181
|
+
{ provide: HAMUR_LEVEL_DISPOSE, useValue: (dispose) => disposers.add(dispose) },
|
|
182
|
+
{ provide: HAMUR_OUTLET_CONTEXT, useValue: this.value },
|
|
183
|
+
];
|
|
184
|
+
if (entry.caught)
|
|
185
|
+
providers.push({ provide: HAMUR_CAUGHT, useValue: entry.props.error });
|
|
186
|
+
if (this.view().slot) {
|
|
187
|
+
providers.push({ provide: HAMUR_TREE, useValue: this.slotTree });
|
|
188
|
+
providers.push({ provide: HAMUR_ROUTE, useFactory: () => computed(() => this.slotRoute() ?? this.route()) });
|
|
189
|
+
}
|
|
190
|
+
const injector = Injector.create({ providers, parent: this.injector });
|
|
191
|
+
const failed = (error) => this.failed(entry, unwrap(error));
|
|
192
|
+
try {
|
|
193
|
+
const ref = this.container.createComponent(component, { injector, onError: failed });
|
|
194
|
+
const inputs = new Set(reflectComponentType(component)?.inputs.map((input) => input.templateName) ?? []);
|
|
195
|
+
this.shown = { entry, ref, inputs, disposers };
|
|
196
|
+
this.setInputs(this.shown, entry);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
failed(error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* A throw of the entry this level creates, in its constructor or its checks. The route boundary covering the entry
|
|
204
|
+
* answers in its place; with none the error goes up to the next `@boundary` or level, and from the first level to the app's error page.
|
|
205
|
+
* A route boundary's own throw skips every boundary above it.
|
|
206
|
+
*/
|
|
207
|
+
failed(entry, error) {
|
|
208
|
+
if (entry.caught)
|
|
209
|
+
return this.fail(error);
|
|
210
|
+
const caught = entry.boundary ? routeBoundary(this.pageContext(), entry, error) : undefined;
|
|
211
|
+
if (caught)
|
|
212
|
+
return this.answer(caught);
|
|
213
|
+
if (this.owner >= 0)
|
|
214
|
+
throw error;
|
|
215
|
+
this.fail(error);
|
|
216
|
+
}
|
|
217
|
+
/** The boundary component takes the entry's place once the check that threw is over: Angular is still walking the view. */
|
|
218
|
+
answer(caught) {
|
|
219
|
+
const count = this.shownCount;
|
|
220
|
+
const done = this.tasks.add();
|
|
221
|
+
queueMicrotask(() => {
|
|
222
|
+
try {
|
|
223
|
+
if (count !== this.shownCount)
|
|
224
|
+
return;
|
|
225
|
+
this.shownCount++;
|
|
226
|
+
this.dropShown();
|
|
227
|
+
this.place({
|
|
228
|
+
id: caught.id,
|
|
229
|
+
component: caught.component,
|
|
230
|
+
props: { error: caught.error, clearError: (options) => this.clear(options) },
|
|
231
|
+
caught: caught.caught,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
done();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
clear(options) {
|
|
240
|
+
return this.app.error?.clear(options) ?? Promise.resolve();
|
|
241
|
+
}
|
|
242
|
+
setInputs({ ref, inputs }, entry) {
|
|
243
|
+
for (const [name, value] of Object.entries(entry.props ?? {}))
|
|
244
|
+
if (inputs.has(name))
|
|
245
|
+
ref.setInput(name, value);
|
|
246
|
+
}
|
|
247
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Outlet, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
248
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: Outlet, isStandalone: true, selector: "hamur-outlet", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "", isInline: true });
|
|
290
249
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
250
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Outlet, decorators: [{
|
|
251
|
+
type: Component,
|
|
252
|
+
args: [{ selector: "hamur-outlet", template: "" }]
|
|
253
|
+
}], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
|
|
254
|
+
const KEPT_SOURCE = new InjectionToken("hamur kept source");
|
|
255
|
+
const keptRoutes = new WeakMap();
|
|
295
256
|
/**
|
|
296
257
|
* The `<div data-hamur-keepalive="<key>">` of a page whose route keeps its pages, `display:contents` while it is shown
|
|
297
258
|
* and `hidden` while kept. A kept unit reads its own tree, route and payload; a shown one reads the page's, from its own level down.
|
|
298
259
|
*/
|
|
299
|
-
@Component({
|
|
300
|
-
selector: "div[data-hamur-keepalive]",
|
|
301
|
-
imports: [Outlet],
|
|
302
|
-
template: "<hamur-outlet />",
|
|
303
|
-
providers: [
|
|
304
|
-
{ provide: HAMUR_LEVEL, useValue: -1 },
|
|
305
|
-
{ provide: HAMUR_TREE, useFactory: () => inject(KeptPage).tree },
|
|
306
|
-
{ provide: HAMUR_ROUTE, useFactory: () => inject(KeptPage).route },
|
|
307
|
-
{ provide: HAMUR_PAYLOAD, useFactory: () => inject(KeptPage).payload },
|
|
308
|
-
{ provide: HAMUR_ACTIVATION, useFactory: () => inject(KeptPage).activation },
|
|
309
|
-
],
|
|
310
|
-
host: {
|
|
311
|
-
"[attr.data-hamur-keepalive]": "name()",
|
|
312
|
-
"[attr.hidden]": "hidden() ? '' : null",
|
|
313
|
-
"[style.display]": "hidden() ? null : 'contents'",
|
|
314
|
-
},
|
|
315
|
-
})
|
|
316
260
|
export class KeptPage {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
261
|
+
name = input.required(/* @ts-ignore */
|
|
262
|
+
...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
|
|
263
|
+
unit = input(/* @ts-ignore */
|
|
264
|
+
...(ngDevMode ? [undefined, { debugName: "unit" }] : /* istanbul ignore next */ []));
|
|
265
|
+
hidden = input(false, /* @ts-ignore */
|
|
266
|
+
...(ngDevMode ? [{ debugName: "hidden" }] : /* istanbul ignore next */ []));
|
|
267
|
+
source = inject(KEPT_SOURCE);
|
|
268
|
+
app = inject(HAMUR_APP);
|
|
269
|
+
activation = activation(inject(HAMUR_ACTIVATION, { skipSelf: true, optional: true }) ?? undefined, false);
|
|
270
|
+
tree = computed(() => this.unit()?.tree ?? { components: this.source.tree().components.slice(this.source.level + 1) }, /* @ts-ignore */
|
|
271
|
+
...(ngDevMode ? [{ debugName: "tree" }] : /* istanbul ignore next */ []));
|
|
272
|
+
route = computed(() => {
|
|
273
|
+
const unit = this.unit();
|
|
274
|
+
if (!unit)
|
|
275
|
+
return this.source.route();
|
|
276
|
+
let value = keptRoutes.get(unit);
|
|
277
|
+
if (!value)
|
|
278
|
+
keptRoutes.set(unit, (value = routeValue({ route: unit.route, app: this.app, payload: unit.payload, tree: unit.tree })));
|
|
279
|
+
return value;
|
|
280
|
+
}, /* @ts-ignore */
|
|
281
|
+
...(ngDevMode ? [{ debugName: "route" }] : /* istanbul ignore next */ []));
|
|
282
|
+
payload = computed(() => this.unit()?.payload ?? this.source.payload(), /* @ts-ignore */
|
|
283
|
+
...(ngDevMode ? [{ debugName: "payload" }] : /* istanbul ignore next */ []));
|
|
284
|
+
constructor() {
|
|
285
|
+
effect(() => setHidden(this.activation, this.hidden()));
|
|
286
|
+
inject(DestroyRef).onDestroy(() => detach(this.activation));
|
|
287
|
+
}
|
|
288
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: KeptPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
289
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: KeptPage, isStandalone: true, selector: "div[data-hamur-keepalive]", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, hidden: { classPropertyName: "hidden", publicName: "hidden", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-hamur-keepalive": "name()", "attr.hidden": "hidden() ? '' : null", "style.display": "hidden() ? null : 'contents'" } }, providers: [
|
|
290
|
+
{ provide: HAMUR_LEVEL, useValue: -1 },
|
|
291
|
+
{ provide: HAMUR_TREE, useFactory: () => inject(KeptPage).tree },
|
|
292
|
+
{ provide: HAMUR_ROUTE, useFactory: () => inject(KeptPage).route },
|
|
293
|
+
{ provide: HAMUR_PAYLOAD, useFactory: () => inject(KeptPage).payload },
|
|
294
|
+
{ provide: HAMUR_ACTIVATION, useFactory: () => inject(KeptPage).activation },
|
|
295
|
+
], ngImport: i0, template: "<hamur-outlet />", isInline: true, dependencies: [{ kind: "component", type: Outlet, selector: "hamur-outlet", inputs: ["name", "context"] }] });
|
|
344
296
|
}
|
|
297
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: KeptPage, decorators: [{
|
|
298
|
+
type: Component,
|
|
299
|
+
args: [{
|
|
300
|
+
selector: "div[data-hamur-keepalive]",
|
|
301
|
+
imports: [Outlet],
|
|
302
|
+
template: "<hamur-outlet />",
|
|
303
|
+
providers: [
|
|
304
|
+
{ provide: HAMUR_LEVEL, useValue: -1 },
|
|
305
|
+
{ provide: HAMUR_TREE, useFactory: () => inject(KeptPage).tree },
|
|
306
|
+
{ provide: HAMUR_ROUTE, useFactory: () => inject(KeptPage).route },
|
|
307
|
+
{ provide: HAMUR_PAYLOAD, useFactory: () => inject(KeptPage).payload },
|
|
308
|
+
{ provide: HAMUR_ACTIVATION, useFactory: () => inject(KeptPage).activation },
|
|
309
|
+
],
|
|
310
|
+
host: {
|
|
311
|
+
"[attr.data-hamur-keepalive]": "name()",
|
|
312
|
+
"[attr.hidden]": "hidden() ? '' : null",
|
|
313
|
+
"[style.display]": "hidden() ? null : 'contents'",
|
|
314
|
+
},
|
|
315
|
+
}]
|
|
316
|
+
}], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }], unit: [{ type: i0.Input, args: [{ isSignal: true, alias: "unit", required: false }] }], hidden: [{ type: i0.Input, args: [{ isSignal: true, alias: "hidden", required: false }] }] } });
|