@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/src/outlet.ts CHANGED
@@ -1,344 +1,316 @@
1
- import {
2
- Component,
3
- DestroyRef,
4
- InjectionToken,
5
- Injector,
6
- PendingTasks,
7
- ViewContainerRef,
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: unknown): unknown =>
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
- @Component({ selector: "hamur-outlet", template: "" })
58
- export class Outlet implements OnInit {
59
- readonly name = input<string>()
60
- readonly context = input<unknown>()
61
- private readonly tree = inject(HAMUR_TREE)
62
- private readonly fail = inject(HAMUR_FAIL)
63
- private readonly app = inject(HAMUR_APP)
64
- private readonly payload = inject(HAMUR_PAYLOAD)
65
- private readonly route = inject(HAMUR_ROUTE)
66
- private readonly above = inject(HAMUR_OUTLET_CONTEXT, { optional: true })
67
- private readonly owner = inject(HAMUR_LEVEL, { optional: true }) ?? -1
68
- private readonly injector = inject(Injector)
69
- private readonly container = inject(ViewContainerRef)
70
- private readonly pageContext = inject(HAMUR_CONTEXT)
71
- private readonly tasks = inject(PendingTasks)
72
- private readonly warned = new Set<string>()
73
- private shown: Shown | undefined
74
- /** The keep-alive wrappers this outlet holds, by keep-alive key. */
75
- private readonly pages = new Map<string, ComponentRef<KeptPage>>()
76
- private started = false
77
- /** Counts what the level shows, so an answer that waits for a microtask finds out the level moved on. */
78
- private shownCount = 0
79
-
80
- /** The tree this outlet reads and the index of its entry in it. */
81
- private readonly view = computed(() => {
82
- const name = this.name()
83
- const tree = this.tree()
84
- if (name === undefined) return { tree, index: this.owner + 1, slot: false }
85
- return { tree: tree.components[this.owner]?.outlets?.[name], index: 0, slot: true }
86
- })
87
-
88
- private readonly value = computed(() => {
89
- const own = this.context()
90
- return own !== undefined ? own : this.above?.()
91
- })
92
-
93
- private readonly slotTree = computed(() => this.view().tree ?? EMPTY)
94
-
95
- private readonly slotRoute = computed(() => {
96
- const slot = this.view().tree
97
- if (!slot?.route) return undefined
98
- const { state, key, navigationType } = this.route()
99
- return routeValue({
100
- route: { ...slot.route, state, key, navigationType },
101
- tree: slot,
102
- app: this.app,
103
- payload: this.payload(),
104
- })
105
- })
106
-
107
- constructor() {
108
- inject(DestroyRef).onDestroy(() => {
109
- this.shownCount++
110
- for (const dispose of this.shown?.disposers ?? []) dispose()
111
- })
112
- effect(() => {
113
- const entry = this.entry()
114
- const units = this.units()
115
- if (this.started) untracked(() => this.apply(entry, units))
116
- })
117
- }
118
-
119
- ngOnInit(): void {
120
- this.started = true
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
- const wanted = new Set<string>()
139
- let index = 0
140
- for (const unit of units) {
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
- if (entry?.keepalive !== undefined) {
145
- this.show(undefined)
146
- this.page(entry.keepalive, undefined, index)
147
- wanted.add(entry.keepalive)
148
- } else this.show(entry)
149
- for (const [key, ref] of this.pages)
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
- ref.setInput("name", key)
172
- ref.setInput("unit", unit)
173
- ref.setInput("hidden", unit !== undefined)
174
- if (this.container.indexOf(ref.hostView) !== index) this.container.move(ref.hostView, index)
175
- }
176
-
177
- private dropPages(): void {
178
- for (const ref of this.pages.values()) ref.destroy()
179
- this.pages.clear()
180
- }
181
-
182
- private dropShown(): void {
183
- const shown = this.shown
184
- this.shown = undefined
185
- if (!shown) return
186
- shown.ref.destroy()
187
- for (const dispose of shown.disposers) dispose()
188
- }
189
-
190
- private entry(): RenderEntry | undefined {
191
- const { tree, index, slot } = this.view()
192
- const name = this.name()
193
- if (mode.dev) {
194
- if (!slot) noteOutlet(this.tree().components[this.owner]?.id)
195
- else if (!tree && name !== undefined && !this.warned.has(name)) {
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
- return tree?.components[index]
201
- }
202
-
203
- private show(entry: RenderEntry | undefined): void {
204
- const shown = this.shown
205
- if (shown && entry && same(shown.entry, entry)) {
206
- shown.entry = entry
207
- this.setInputs(shown, entry)
208
- return
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
- this.shownCount++
211
- this.dropShown()
212
- if (entry) this.place(entry)
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
- const injector = Injector.create({ providers, parent: this.injector })
229
- const failed = (error: unknown) => this.failed(entry, unwrap(error))
230
- try {
231
- const ref = this.container.createComponent(component, { injector, onError: failed })
232
- const inputs = new Set(reflectComponentType(component)?.inputs.map((input) => input.templateName) ?? [])
233
- this.shown = { entry, ref, inputs, disposers }
234
- this.setInputs(this.shown, entry)
235
- } catch (error) {
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
- * A throw of the entry this level creates, in its constructor or its checks. The route boundary covering the entry
242
- * 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.
243
- * A route boundary's own throw skips every boundary above it.
244
- */
245
- private failed(entry: RenderEntry, error: unknown): void {
246
- if (entry.caught) return this.fail(error)
247
- const caught = entry.boundary ? routeBoundary(this.pageContext(), entry, error) : undefined
248
- if (caught) return this.answer(caught)
249
- if (this.owner >= 0) throw error
250
- this.fail(error)
251
- }
252
-
253
- /** The boundary component takes the entry's place once the check that threw is over: Angular is still walking the view. */
254
- private answer(caught: NonNullable<ReturnType<typeof routeBoundary>>): void {
255
- const count = this.shownCount
256
- const done = this.tasks.add()
257
- queueMicrotask(() => {
258
- try {
259
- if (count !== this.shownCount) return
260
- this.shownCount++
261
- this.dropShown()
262
- this.place({
263
- id: caught.id,
264
- component: caught.component,
265
- props: { error: caught.error, clearError: (options?: ClearErrorOptions) => this.clear(options) },
266
- caught: caught.caught,
267
- })
268
- } finally {
269
- done()
270
- }
271
- })
272
- }
273
-
274
- private clear(options?: ClearErrorOptions): Promise<void> {
275
- return this.app.error?.clear(options) ?? Promise.resolve()
276
- }
277
-
278
- private setInputs({ ref, inputs }: Shown, entry: RenderEntry): void {
279
- for (const [name, value] of Object.entries(entry.props ?? {})) if (inputs.has(name)) ref.setInput(name, value)
280
- }
281
- }
282
-
283
- /** What a keep-alive wrapper reads from the outlet that creates it. */
284
- interface KeptSource {
285
- tree: Signal<RenderTree>
286
- /** The index in `tree.components` of the entry whose outlet holds the wrapper; `-1` for the top level. */
287
- level: number
288
- route: Signal<RouteValue>
289
- payload: Signal<RenderContext["payload"]>
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
- const KEPT_SOURCE = new InjectionToken<KeptSource>("hamur kept source")
293
- const keptRoutes = new WeakMap<KeptUnit, RouteValue>()
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
- readonly name = input.required<string>()
318
- readonly unit = input<KeptUnit>()
319
- readonly hidden = input(false)
320
- private readonly source = inject(KEPT_SOURCE)
321
- private readonly app = inject(HAMUR_APP)
322
- readonly activation = activation(inject(HAMUR_ACTIVATION, { skipSelf: true, optional: true }) ?? undefined, false)
323
-
324
- readonly tree: Signal<RenderTree> = computed(
325
- () => this.unit()?.tree ?? { components: this.source.tree().components.slice(this.source.level + 1) },
326
- )
327
- readonly route: Signal<RouteValue> = computed(() => {
328
- const unit = this.unit()
329
- if (!unit) return this.source.route()
330
- let value = keptRoutes.get(unit)
331
- if (!value)
332
- keptRoutes.set(
333
- unit,
334
- (value = routeValue({ route: unit.route, app: this.app, payload: unit.payload, tree: unit.tree })),
335
- )
336
- return value
337
- })
338
- readonly payload: Signal<RenderContext["payload"]> = computed(() => this.unit()?.payload ?? this.source.payload())
339
-
340
- constructor() {
341
- effect(() => setHidden(this.activation, this.hidden()))
342
- inject(DestroyRef).onDestroy(() => detach(this.activation))
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 }] }] } });