@hamur/adapter-angular 0.0.0-stage → 0.0.1
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/LICENSE +22 -0
- package/README.md +42 -2
- package/dist/chunks/browser-index-7h7x2xz2.js +131 -0
- package/dist/chunks/browser-index-nann848q.js +205 -0
- package/dist/chunks/browser-index-qn8q5fa2.js +580 -0
- package/dist/src/adapter.js +1073 -0
- package/dist/src/error-page.js +34 -0
- package/dist/src/index.js +1729 -0
- package/dist/src/keepalive.js +0 -0
- package/dist/src/runtime/client.js +21 -0
- package/dist/src/runtime/island.js +92 -0
- package/dist/src/runtime/server.js +175 -0
- package/dist/types/src/activation.d.ts +20 -0
- package/dist/types/src/adapter.d.ts +7 -0
- package/dist/types/src/app.d.ts +3 -0
- package/dist/types/src/async-data.d.ts +21 -0
- package/dist/types/src/client-parts.d.ts +32 -0
- package/dist/types/src/compile.d.ts +97 -0
- package/dist/types/src/context.d.ts +74 -0
- package/dist/types/src/data.d.ts +65 -0
- package/dist/types/src/definition.d.ts +13 -0
- package/dist/types/src/error-page.d.ts +5 -0
- package/dist/types/src/error.d.ts +4 -0
- package/dist/types/src/form.d.ts +65 -0
- package/dist/types/src/head.d.ts +12 -0
- package/dist/types/src/hmr.d.ts +14 -0
- package/dist/types/src/hydration.d.ts +16 -0
- package/dist/types/src/index.d.ts +24 -0
- package/dist/types/src/indicators.d.ts +69 -0
- package/dist/types/src/island.d.ts +39 -0
- package/dist/types/src/keepalive.d.ts +1 -0
- package/dist/types/src/link.d.ts +65 -0
- package/dist/types/src/markdown-page.d.ts +10 -0
- package/dist/types/src/markdown.d.ts +37 -0
- package/dist/types/src/mask.d.ts +12 -0
- package/dist/types/src/navigate.d.ts +14 -0
- package/dist/types/src/outlet.d.ts +71 -0
- package/dist/types/src/request.d.ts +31 -0
- package/dist/types/src/routing.d.ts +47 -0
- package/dist/types/src/runtime/client.d.ts +29 -0
- package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
- package/dist/types/src/runtime/hydration.d.ts +8 -0
- package/dist/types/src/runtime/island.d.ts +8 -0
- package/dist/types/src/runtime/server.d.ts +15 -0
- package/dist/types/src/server-island.d.ts +21 -0
- package/dist/types/src/state.d.ts +14 -0
- package/dist/types/src/svg.d.ts +15 -0
- package/dist/types/src/time.d.ts +37 -0
- package/dist/types/src/wrapper.d.ts +21 -0
- package/package.json +56 -4
- package/src/activation.ts +83 -0
- package/src/adapter.ts +107 -0
- package/src/app.ts +6 -0
- package/src/async-data.ts +105 -0
- package/src/client-parts.ts +127 -0
- package/src/compile.ts +959 -0
- package/src/context.ts +189 -0
- package/src/data.ts +389 -0
- package/src/definition.ts +144 -0
- package/src/error-page.ts +17 -0
- package/src/error.ts +15 -0
- package/src/form.ts +253 -0
- package/src/head.ts +63 -0
- package/src/hmr.ts +61 -0
- package/src/hydration.ts +120 -0
- package/src/index.ts +98 -0
- package/src/indicators.ts +251 -0
- package/src/island.ts +95 -0
- package/src/keepalive.ts +1 -0
- package/src/link.ts +251 -0
- package/src/markdown-page.ts +31 -0
- package/src/markdown.ts +170 -0
- package/src/mask.ts +36 -0
- package/src/navigate.ts +19 -0
- package/src/outlet.ts +344 -0
- package/src/request.ts +170 -0
- package/src/routing.ts +218 -0
- package/src/runtime/client.ts +140 -0
- package/src/runtime/contract.d.ts +4 -0
- package/src/runtime/hydration-dev.ts +18 -0
- package/src/runtime/hydration.ts +7 -0
- package/src/runtime/island.ts +109 -0
- package/src/runtime/server.ts +228 -0
- package/src/server-island.ts +54 -0
- package/src/state.ts +70 -0
- package/src/svg.ts +65 -0
- package/src/time.ts +108 -0
- package/src/wrapper.ts +187 -0
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
// packages/adapter-angular/src/outlet.ts
|
|
2
|
+
import { Component, DestroyRef as DestroyRef2, InjectionToken as InjectionToken3, Injector, PendingTasks, ViewContainerRef, computed, effect, inject as inject3, input, reflectComponentType, untracked } from "@angular/core";
|
|
3
|
+
import { noteOutlet, routeBoundary } from "hamur/adapter";
|
|
4
|
+
|
|
5
|
+
// packages/adapter-angular/src/activation.ts
|
|
6
|
+
import { DestroyRef, InjectionToken as InjectionToken2, afterNextRender, assertInInjectionContext, inject as inject2 } from "@angular/core";
|
|
7
|
+
|
|
8
|
+
// packages/adapter-angular/src/context.ts
|
|
9
|
+
import { InjectionToken, PLATFORM_ID, inject, signal } from "@angular/core";
|
|
10
|
+
import { createRouterApi, routeStateOf } from "hamur/adapter";
|
|
11
|
+
import { withBase } from "hamur/app";
|
|
12
|
+
var mode = { dev: import.meta.dev === true };
|
|
13
|
+
var HAMUR_APP = new InjectionToken("hamur app");
|
|
14
|
+
var HAMUR_TREE = new InjectionToken("hamur tree");
|
|
15
|
+
var HAMUR_ROOT_TREE = new InjectionToken("hamur root tree");
|
|
16
|
+
var HAMUR_ROUTER = new InjectionToken("hamur router");
|
|
17
|
+
var HAMUR_NAVIGATION = new InjectionToken("hamur navigation");
|
|
18
|
+
var HAMUR_BASE_URL = new InjectionToken("hamur base url");
|
|
19
|
+
var HAMUR_HREF = new InjectionToken("hamur href");
|
|
20
|
+
var HAMUR_OUTLET_CONTEXT = new InjectionToken("hamur outlet context");
|
|
21
|
+
var HAMUR_ROUTE = new InjectionToken("hamur route");
|
|
22
|
+
var HAMUR_PAYLOAD = new InjectionToken("hamur payload");
|
|
23
|
+
var HAMUR_FAIL = new InjectionToken("hamur fail");
|
|
24
|
+
var HAMUR_CONTEXT = new InjectionToken("hamur context");
|
|
25
|
+
var HAMUR_CAUGHT = new InjectionToken("hamur caught error");
|
|
26
|
+
var HAMUR_LEVEL = new InjectionToken("hamur level");
|
|
27
|
+
var HAMUR_LEVEL_DISPOSE = new InjectionToken("hamur level dispose");
|
|
28
|
+
function onServer() {
|
|
29
|
+
const platform = inject(PLATFORM_ID, { optional: true });
|
|
30
|
+
return platform === null ? typeof document === "undefined" : platform === "server";
|
|
31
|
+
}
|
|
32
|
+
function required(token, name) {
|
|
33
|
+
const value = inject(token, { optional: true });
|
|
34
|
+
if (value === null)
|
|
35
|
+
throw new Error(`${name}() must be called inside a Hamur app`);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function entryOf(name) {
|
|
39
|
+
const tree = required(HAMUR_TREE, name);
|
|
40
|
+
const level = inject(HAMUR_LEVEL, { optional: true });
|
|
41
|
+
if (level === null)
|
|
42
|
+
throw new Error(`${name}() must be called inside a Hamur app`);
|
|
43
|
+
return () => tree().components[level]?.id;
|
|
44
|
+
}
|
|
45
|
+
var dataOf = (payload) => payload().data ?? {};
|
|
46
|
+
function routeValue({ route, app, payload, tree }) {
|
|
47
|
+
return {
|
|
48
|
+
path: route.path,
|
|
49
|
+
fullPath: route.fullPath,
|
|
50
|
+
params: route.params,
|
|
51
|
+
query: route.query,
|
|
52
|
+
search: route.search,
|
|
53
|
+
hash: route.hash,
|
|
54
|
+
name: route.name,
|
|
55
|
+
meta: route.meta,
|
|
56
|
+
matched: route.matched,
|
|
57
|
+
groups: route.groups ?? [],
|
|
58
|
+
...routeStateOf({ route, app, payload, tree })
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function navigationOf(navigator) {
|
|
62
|
+
const source = navigator;
|
|
63
|
+
if (typeof source?.get !== "function" || typeof source.subscribe !== "function")
|
|
64
|
+
return signal({ state: "idle", pending: false });
|
|
65
|
+
const navigation = signal(source.get());
|
|
66
|
+
source.subscribe(() => navigation.set(source.get()));
|
|
67
|
+
return navigation;
|
|
68
|
+
}
|
|
69
|
+
function islandHref(baseURL) {
|
|
70
|
+
return (to) => {
|
|
71
|
+
if (typeof to !== "string")
|
|
72
|
+
throw new Error(`Link to the route "${to.name}" cannot render in an island; give it a path`);
|
|
73
|
+
return withBase(to, baseURL);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function detachedHref(to) {
|
|
77
|
+
if (typeof to !== "string")
|
|
78
|
+
throw new Error(`Link to the route "${to.name}" must be rendered inside a Hamur app`);
|
|
79
|
+
return withBase(to, "/");
|
|
80
|
+
}
|
|
81
|
+
function createState(source) {
|
|
82
|
+
const baseURL = source.baseURL ?? "/";
|
|
83
|
+
const href = source.href ?? detachedHref;
|
|
84
|
+
let current = source;
|
|
85
|
+
const state = {
|
|
86
|
+
tree: signal(source.tree),
|
|
87
|
+
route: signal(routeValue(source)),
|
|
88
|
+
payload: signal(source.payload),
|
|
89
|
+
navigation: navigationOf(source.navigator).asReadonly(),
|
|
90
|
+
router: createRouterApi({ navigator: source.navigator, baseURL, href, route: source.route, url: source.url }),
|
|
91
|
+
baseURL,
|
|
92
|
+
href,
|
|
93
|
+
context: () => ({
|
|
94
|
+
...current,
|
|
95
|
+
url: current.url ?? new URL(current.route.fullPath, "http://localhost"),
|
|
96
|
+
baseURL
|
|
97
|
+
}),
|
|
98
|
+
write(next) {
|
|
99
|
+
current = next;
|
|
100
|
+
state.route.set(routeValue(next));
|
|
101
|
+
state.payload.set(next.payload);
|
|
102
|
+
state.tree.set(next.tree);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
return state;
|
|
106
|
+
}
|
|
107
|
+
function hamurProviders(app, state, fail) {
|
|
108
|
+
return [
|
|
109
|
+
{ provide: HAMUR_APP, useValue: app },
|
|
110
|
+
{ provide: HAMUR_TREE, useValue: state.tree.asReadonly() },
|
|
111
|
+
{ provide: HAMUR_ROOT_TREE, useValue: state.tree.asReadonly() },
|
|
112
|
+
{ provide: HAMUR_ROUTE, useValue: state.route.asReadonly() },
|
|
113
|
+
{ provide: HAMUR_PAYLOAD, useValue: state.payload.asReadonly() },
|
|
114
|
+
{ provide: HAMUR_ROUTER, useValue: state.router },
|
|
115
|
+
{ provide: HAMUR_NAVIGATION, useValue: state.navigation },
|
|
116
|
+
{ provide: HAMUR_BASE_URL, useValue: state.baseURL },
|
|
117
|
+
{ provide: HAMUR_HREF, useValue: state.href },
|
|
118
|
+
{ provide: HAMUR_FAIL, useValue: fail },
|
|
119
|
+
{ provide: HAMUR_CONTEXT, useValue: state.context }
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
var setups = new WeakMap;
|
|
123
|
+
function setupOf(app) {
|
|
124
|
+
let held = setups.get(app);
|
|
125
|
+
if (!held) {
|
|
126
|
+
const own = {
|
|
127
|
+
setup: {
|
|
128
|
+
providers: [],
|
|
129
|
+
get injector() {
|
|
130
|
+
return own.injector;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
setups.set(app, held = own);
|
|
135
|
+
}
|
|
136
|
+
const current = held;
|
|
137
|
+
return { setup: current.setup, bootstrapped: (injector) => void (current.injector = injector) };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// packages/adapter-angular/src/activation.ts
|
|
141
|
+
var HAMUR_ACTIVATION = new InjectionToken2("hamur activation");
|
|
142
|
+
function activation(parent, hidden) {
|
|
143
|
+
const own = { hidden, parent, children: new Set, on: new Set, off: new Set };
|
|
144
|
+
parent?.children.add(own);
|
|
145
|
+
return own;
|
|
146
|
+
}
|
|
147
|
+
function detach(own) {
|
|
148
|
+
own.parent?.children.delete(own);
|
|
149
|
+
}
|
|
150
|
+
function shown(own) {
|
|
151
|
+
return !own || !own.hidden && shown(own.parent);
|
|
152
|
+
}
|
|
153
|
+
var queue;
|
|
154
|
+
function later(isShown, fn) {
|
|
155
|
+
if (!queue) {
|
|
156
|
+
queue = [];
|
|
157
|
+
queueMicrotask(() => {
|
|
158
|
+
const run = queue;
|
|
159
|
+
queue = undefined;
|
|
160
|
+
for (const item of run)
|
|
161
|
+
if (!item.shown)
|
|
162
|
+
item.fn();
|
|
163
|
+
for (const item of run)
|
|
164
|
+
if (item.shown)
|
|
165
|
+
item.fn();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
queue.push({ shown: isShown, fn });
|
|
169
|
+
}
|
|
170
|
+
function fire(own, isShown) {
|
|
171
|
+
for (const fn of isShown ? own.on : own.off)
|
|
172
|
+
later(isShown, fn);
|
|
173
|
+
for (const child of own.children)
|
|
174
|
+
if (!child.hidden)
|
|
175
|
+
fire(child, isShown);
|
|
176
|
+
}
|
|
177
|
+
function setHidden(own, hidden) {
|
|
178
|
+
if (own.hidden === hidden)
|
|
179
|
+
return;
|
|
180
|
+
const before = shown(own);
|
|
181
|
+
own.hidden = hidden;
|
|
182
|
+
if (shown(own) !== before)
|
|
183
|
+
fire(own, !before);
|
|
184
|
+
}
|
|
185
|
+
function onPageActivated2(fn) {
|
|
186
|
+
assertInInjectionContext(onPageActivated2);
|
|
187
|
+
const own = inject2(HAMUR_ACTIVATION, { optional: true }) ?? undefined;
|
|
188
|
+
const destroy = inject2(DestroyRef);
|
|
189
|
+
const run = () => fn();
|
|
190
|
+
own?.on.add(run);
|
|
191
|
+
afterNextRender(() => {
|
|
192
|
+
if (shown(own))
|
|
193
|
+
later(true, run);
|
|
194
|
+
});
|
|
195
|
+
destroy.onDestroy(() => void own?.on.delete(run));
|
|
196
|
+
}
|
|
197
|
+
function onPageDeactivated2(fn) {
|
|
198
|
+
assertInInjectionContext(onPageDeactivated2);
|
|
199
|
+
if (onServer())
|
|
200
|
+
return;
|
|
201
|
+
const own = inject2(HAMUR_ACTIVATION, { optional: true }) ?? undefined;
|
|
202
|
+
const run = () => fn();
|
|
203
|
+
own?.off.add(run);
|
|
204
|
+
inject2(DestroyRef).onDestroy(() => {
|
|
205
|
+
own?.off.delete(run);
|
|
206
|
+
if (shown(own))
|
|
207
|
+
later(false, run);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// packages/adapter-angular/src/outlet.ts
|
|
212
|
+
import * as i0 from "@angular/core";
|
|
213
|
+
var EMPTY = { components: [] };
|
|
214
|
+
var same = (a, b) => a.id === b.id && a.key === b.key && a.component === b.component;
|
|
215
|
+
var unwrap = (error) => error instanceof Error && error.name === "ErrorBoundaryWrappedError" ? error.cause : error;
|
|
216
|
+
|
|
217
|
+
class Outlet2 {
|
|
218
|
+
name = input(...ngDevMode ? [undefined, { debugName: "name" }] : []);
|
|
219
|
+
context = input(...ngDevMode ? [undefined, { debugName: "context" }] : []);
|
|
220
|
+
tree = inject3(HAMUR_TREE);
|
|
221
|
+
fail = inject3(HAMUR_FAIL);
|
|
222
|
+
app = inject3(HAMUR_APP);
|
|
223
|
+
payload = inject3(HAMUR_PAYLOAD);
|
|
224
|
+
route = inject3(HAMUR_ROUTE);
|
|
225
|
+
above = inject3(HAMUR_OUTLET_CONTEXT, { optional: true });
|
|
226
|
+
owner = inject3(HAMUR_LEVEL, { optional: true }) ?? -1;
|
|
227
|
+
injector = inject3(Injector);
|
|
228
|
+
container = inject3(ViewContainerRef);
|
|
229
|
+
pageContext = inject3(HAMUR_CONTEXT);
|
|
230
|
+
tasks = inject3(PendingTasks);
|
|
231
|
+
warned = new Set;
|
|
232
|
+
shown;
|
|
233
|
+
pages = new Map;
|
|
234
|
+
started = false;
|
|
235
|
+
shownCount = 0;
|
|
236
|
+
view = computed(() => {
|
|
237
|
+
const name = this.name();
|
|
238
|
+
const tree = this.tree();
|
|
239
|
+
if (name === undefined)
|
|
240
|
+
return { tree, index: this.owner + 1, slot: false };
|
|
241
|
+
return { tree: tree.components[this.owner]?.outlets?.[name], index: 0, slot: true };
|
|
242
|
+
}, ...ngDevMode ? [{ debugName: "view" }] : []);
|
|
243
|
+
value = computed(() => {
|
|
244
|
+
const own = this.context();
|
|
245
|
+
return own !== undefined ? own : this.above?.();
|
|
246
|
+
}, ...ngDevMode ? [{ debugName: "value" }] : []);
|
|
247
|
+
slotTree = computed(() => this.view().tree ?? EMPTY, ...ngDevMode ? [{ debugName: "slotTree" }] : []);
|
|
248
|
+
slotRoute = computed(() => {
|
|
249
|
+
const slot = this.view().tree;
|
|
250
|
+
if (!slot?.route)
|
|
251
|
+
return;
|
|
252
|
+
const { state, key, navigationType } = this.route();
|
|
253
|
+
return routeValue({
|
|
254
|
+
route: { ...slot.route, state, key, navigationType },
|
|
255
|
+
tree: slot,
|
|
256
|
+
app: this.app,
|
|
257
|
+
payload: this.payload()
|
|
258
|
+
});
|
|
259
|
+
}, ...ngDevMode ? [{ debugName: "slotRoute" }] : []);
|
|
260
|
+
constructor() {
|
|
261
|
+
inject3(DestroyRef2).onDestroy(() => {
|
|
262
|
+
this.shownCount++;
|
|
263
|
+
for (const dispose of this.shown?.disposers ?? [])
|
|
264
|
+
dispose();
|
|
265
|
+
});
|
|
266
|
+
effect(() => {
|
|
267
|
+
const entry = this.entry();
|
|
268
|
+
const units = this.units();
|
|
269
|
+
if (this.started)
|
|
270
|
+
untracked(() => this.apply(entry, units));
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
ngOnInit() {
|
|
274
|
+
this.started = true;
|
|
275
|
+
this.apply(this.entry(), this.units());
|
|
276
|
+
}
|
|
277
|
+
units() {
|
|
278
|
+
if (this.name() !== undefined)
|
|
279
|
+
return;
|
|
280
|
+
const tree = this.tree();
|
|
281
|
+
return (this.owner >= 0 ? tree.components[this.owner] : tree)?.kept;
|
|
282
|
+
}
|
|
283
|
+
apply(entry, units) {
|
|
284
|
+
if (units === undefined) {
|
|
285
|
+
this.dropPages();
|
|
286
|
+
this.show(entry);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const wanted = new Set;
|
|
290
|
+
let index = 0;
|
|
291
|
+
for (const unit of units) {
|
|
292
|
+
this.page(unit.key, unit, index++);
|
|
293
|
+
wanted.add(unit.key);
|
|
294
|
+
}
|
|
295
|
+
if (entry?.keepalive !== undefined) {
|
|
296
|
+
this.show(undefined);
|
|
297
|
+
this.page(entry.keepalive, undefined, index);
|
|
298
|
+
wanted.add(entry.keepalive);
|
|
299
|
+
} else
|
|
300
|
+
this.show(entry);
|
|
301
|
+
for (const [key, ref] of this.pages)
|
|
302
|
+
if (!wanted.has(key)) {
|
|
303
|
+
ref.destroy();
|
|
304
|
+
this.pages.delete(key);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
page(key, unit, index) {
|
|
308
|
+
let ref = this.pages.get(key);
|
|
309
|
+
if (!ref) {
|
|
310
|
+
const injector = Injector.create({
|
|
311
|
+
providers: [
|
|
312
|
+
{
|
|
313
|
+
provide: KEPT_SOURCE,
|
|
314
|
+
useValue: { tree: this.tree, level: this.owner, route: this.route, payload: this.payload }
|
|
315
|
+
}
|
|
316
|
+
],
|
|
317
|
+
parent: this.injector
|
|
318
|
+
});
|
|
319
|
+
ref = this.container.createComponent(KeptPage, { injector, index });
|
|
320
|
+
this.pages.set(key, ref);
|
|
321
|
+
}
|
|
322
|
+
ref.setInput("name", key);
|
|
323
|
+
ref.setInput("unit", unit);
|
|
324
|
+
ref.setInput("hidden", unit !== undefined);
|
|
325
|
+
if (this.container.indexOf(ref.hostView) !== index)
|
|
326
|
+
this.container.move(ref.hostView, index);
|
|
327
|
+
}
|
|
328
|
+
dropPages() {
|
|
329
|
+
for (const ref of this.pages.values())
|
|
330
|
+
ref.destroy();
|
|
331
|
+
this.pages.clear();
|
|
332
|
+
}
|
|
333
|
+
dropShown() {
|
|
334
|
+
const shown = this.shown;
|
|
335
|
+
this.shown = undefined;
|
|
336
|
+
if (!shown)
|
|
337
|
+
return;
|
|
338
|
+
shown.ref.destroy();
|
|
339
|
+
for (const dispose of shown.disposers)
|
|
340
|
+
dispose();
|
|
341
|
+
}
|
|
342
|
+
entry() {
|
|
343
|
+
const { tree, index, slot } = this.view();
|
|
344
|
+
const name = this.name();
|
|
345
|
+
if (mode.dev) {
|
|
346
|
+
if (!slot)
|
|
347
|
+
noteOutlet(this.tree().components[this.owner]?.id);
|
|
348
|
+
else if (!tree && name !== undefined && !this.warned.has(name)) {
|
|
349
|
+
this.warned.add(name);
|
|
350
|
+
console.warn(`Outlet name "${name}" has no slot in ${this.tree().components[this.owner]?.id}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return tree?.components[index];
|
|
354
|
+
}
|
|
355
|
+
show(entry) {
|
|
356
|
+
const shown = this.shown;
|
|
357
|
+
if (shown && entry && same(shown.entry, entry)) {
|
|
358
|
+
shown.entry = entry;
|
|
359
|
+
this.setInputs(shown, entry);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
this.shownCount++;
|
|
363
|
+
this.dropShown();
|
|
364
|
+
if (entry)
|
|
365
|
+
this.place(entry);
|
|
366
|
+
}
|
|
367
|
+
place(entry) {
|
|
368
|
+
const component = entry.component;
|
|
369
|
+
const disposers = new Set;
|
|
370
|
+
const providers = [
|
|
371
|
+
{ provide: HAMUR_LEVEL, useValue: this.view().index },
|
|
372
|
+
{ provide: HAMUR_LEVEL_DISPOSE, useValue: (dispose) => disposers.add(dispose) },
|
|
373
|
+
{ provide: HAMUR_OUTLET_CONTEXT, useValue: this.value }
|
|
374
|
+
];
|
|
375
|
+
if (entry.caught)
|
|
376
|
+
providers.push({ provide: HAMUR_CAUGHT, useValue: entry.props.error });
|
|
377
|
+
if (this.view().slot) {
|
|
378
|
+
providers.push({ provide: HAMUR_TREE, useValue: this.slotTree });
|
|
379
|
+
providers.push({ provide: HAMUR_ROUTE, useFactory: () => computed(() => this.slotRoute() ?? this.route()) });
|
|
380
|
+
}
|
|
381
|
+
const injector = Injector.create({ providers, parent: this.injector });
|
|
382
|
+
const failed = (error) => this.failed(entry, unwrap(error));
|
|
383
|
+
try {
|
|
384
|
+
const ref = this.container.createComponent(component, { injector, onError: failed });
|
|
385
|
+
const inputs = new Set(reflectComponentType(component)?.inputs.map((input2) => input2.templateName) ?? []);
|
|
386
|
+
this.shown = { entry, ref, inputs, disposers };
|
|
387
|
+
this.setInputs(this.shown, entry);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
failed(error);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
failed(entry, error) {
|
|
393
|
+
if (entry.caught)
|
|
394
|
+
return this.fail(error);
|
|
395
|
+
const caught = entry.boundary ? routeBoundary(this.pageContext(), entry, error) : undefined;
|
|
396
|
+
if (caught)
|
|
397
|
+
return this.answer(caught);
|
|
398
|
+
if (this.owner >= 0)
|
|
399
|
+
throw error;
|
|
400
|
+
this.fail(error);
|
|
401
|
+
}
|
|
402
|
+
answer(caught) {
|
|
403
|
+
const count = this.shownCount;
|
|
404
|
+
const done = this.tasks.add();
|
|
405
|
+
queueMicrotask(() => {
|
|
406
|
+
try {
|
|
407
|
+
if (count !== this.shownCount)
|
|
408
|
+
return;
|
|
409
|
+
this.shownCount++;
|
|
410
|
+
this.dropShown();
|
|
411
|
+
this.place({
|
|
412
|
+
id: caught.id,
|
|
413
|
+
component: caught.component,
|
|
414
|
+
props: { error: caught.error, clearError: (options) => this.clear(options) },
|
|
415
|
+
caught: caught.caught
|
|
416
|
+
});
|
|
417
|
+
} finally {
|
|
418
|
+
done();
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
clear(options) {
|
|
423
|
+
return this.app.error?.clear(options) ?? Promise.resolve();
|
|
424
|
+
}
|
|
425
|
+
setInputs({ ref, inputs }, entry) {
|
|
426
|
+
for (const [name, value] of Object.entries(entry.props ?? {}))
|
|
427
|
+
if (inputs.has(name))
|
|
428
|
+
ref.setInput(name, value);
|
|
429
|
+
}
|
|
430
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Outlet2, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
431
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: Outlet2, 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 });
|
|
432
|
+
}
|
|
433
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Outlet2, decorators: [{
|
|
434
|
+
type: Component,
|
|
435
|
+
args: [{ selector: "hamur-outlet", template: "" }]
|
|
436
|
+
}], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
|
|
437
|
+
var KEPT_SOURCE = new InjectionToken3("hamur kept source");
|
|
438
|
+
var keptRoutes = new WeakMap;
|
|
439
|
+
|
|
440
|
+
class KeptPage {
|
|
441
|
+
name = input.required(...ngDevMode ? [{ debugName: "name" }] : []);
|
|
442
|
+
unit = input(...ngDevMode ? [undefined, { debugName: "unit" }] : []);
|
|
443
|
+
hidden = input(false, ...ngDevMode ? [{ debugName: "hidden" }] : []);
|
|
444
|
+
source = inject3(KEPT_SOURCE);
|
|
445
|
+
app = inject3(HAMUR_APP);
|
|
446
|
+
activation = activation(inject3(HAMUR_ACTIVATION, { skipSelf: true, optional: true }) ?? undefined, false);
|
|
447
|
+
tree = computed(() => this.unit()?.tree ?? { components: this.source.tree().components.slice(this.source.level + 1) }, ...ngDevMode ? [{ debugName: "tree" }] : []);
|
|
448
|
+
route = computed(() => {
|
|
449
|
+
const unit = this.unit();
|
|
450
|
+
if (!unit)
|
|
451
|
+
return this.source.route();
|
|
452
|
+
let value = keptRoutes.get(unit);
|
|
453
|
+
if (!value)
|
|
454
|
+
keptRoutes.set(unit, value = routeValue({ route: unit.route, app: this.app, payload: unit.payload, tree: unit.tree }));
|
|
455
|
+
return value;
|
|
456
|
+
}, ...ngDevMode ? [{ debugName: "route" }] : []);
|
|
457
|
+
payload = computed(() => this.unit()?.payload ?? this.source.payload(), ...ngDevMode ? [{ debugName: "payload" }] : []);
|
|
458
|
+
constructor() {
|
|
459
|
+
effect(() => setHidden(this.activation, this.hidden()));
|
|
460
|
+
inject3(DestroyRef2).onDestroy(() => detach(this.activation));
|
|
461
|
+
}
|
|
462
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: KeptPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
463
|
+
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: [
|
|
464
|
+
{ provide: HAMUR_LEVEL, useValue: -1 },
|
|
465
|
+
{ provide: HAMUR_TREE, useFactory: () => inject3(KeptPage).tree },
|
|
466
|
+
{ provide: HAMUR_ROUTE, useFactory: () => inject3(KeptPage).route },
|
|
467
|
+
{ provide: HAMUR_PAYLOAD, useFactory: () => inject3(KeptPage).payload },
|
|
468
|
+
{ provide: HAMUR_ACTIVATION, useFactory: () => inject3(KeptPage).activation }
|
|
469
|
+
], ngImport: i0, template: "<hamur-outlet />", isInline: true, dependencies: [{ kind: "component", type: Outlet2, selector: "hamur-outlet", inputs: ["name", "context"] }] });
|
|
470
|
+
}
|
|
471
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: KeptPage, decorators: [{
|
|
472
|
+
type: Component,
|
|
473
|
+
args: [{
|
|
474
|
+
selector: "div[data-hamur-keepalive]",
|
|
475
|
+
imports: [Outlet2],
|
|
476
|
+
template: "<hamur-outlet />",
|
|
477
|
+
providers: [
|
|
478
|
+
{ provide: HAMUR_LEVEL, useValue: -1 },
|
|
479
|
+
{ provide: HAMUR_TREE, useFactory: () => inject3(KeptPage).tree },
|
|
480
|
+
{ provide: HAMUR_ROUTE, useFactory: () => inject3(KeptPage).route },
|
|
481
|
+
{ provide: HAMUR_PAYLOAD, useFactory: () => inject3(KeptPage).payload },
|
|
482
|
+
{ provide: HAMUR_ACTIVATION, useFactory: () => inject3(KeptPage).activation }
|
|
483
|
+
],
|
|
484
|
+
host: {
|
|
485
|
+
"[attr.data-hamur-keepalive]": "name()",
|
|
486
|
+
"[attr.hidden]": "hidden() ? '' : null",
|
|
487
|
+
"[style.display]": "hidden() ? null : 'contents'"
|
|
488
|
+
}
|
|
489
|
+
}]
|
|
490
|
+
}], 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 }] }] } });
|
|
491
|
+
|
|
492
|
+
// packages/adapter-angular/src/client-parts.ts
|
|
493
|
+
import { APP_ID, DestroyRef as DestroyRef3, Directive, InjectionToken as InjectionToken4, PendingTasks as PendingTasks2, TemplateRef, ViewContainerRef as ViewContainerRef2, afterNextRender as afterNextRender2, assertInInjectionContext as assertInInjectionContext2, computed as computed2, inject as inject4, signal as signal2 } from "@angular/core";
|
|
494
|
+
import { checkTransitionName, prehydrate, settledOf } from "hamur/adapter";
|
|
495
|
+
import * as i02 from "@angular/core";
|
|
496
|
+
|
|
497
|
+
class DevOnly2 {
|
|
498
|
+
constructor() {
|
|
499
|
+
if (mode.dev)
|
|
500
|
+
inject4(ViewContainerRef2).createEmbeddedView(inject4(TemplateRef));
|
|
501
|
+
}
|
|
502
|
+
static ɵfac = i02.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i02, type: DevOnly2, deps: [], target: i02.ɵɵFactoryTarget.Directive });
|
|
503
|
+
static ɵdir = i02.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.3.2", type: DevOnly2, isStandalone: true, selector: "[hamurDevOnly]", ngImport: i02 });
|
|
504
|
+
}
|
|
505
|
+
i02.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i02, type: DevOnly2, decorators: [{
|
|
506
|
+
type: Directive,
|
|
507
|
+
args: [{ selector: "[hamurDevOnly]" }]
|
|
508
|
+
}], ctorParameters: () => [] });
|
|
509
|
+
var isThenable = (value) => typeof value?.then === "function";
|
|
510
|
+
function injectDeferred2(promise) {
|
|
511
|
+
assertInInjectionContext2(injectDeferred2);
|
|
512
|
+
const snapshot = signal2({ status: "loading", value: undefined }, ...ngDevMode ? [{ debugName: "snapshot" }] : []);
|
|
513
|
+
const known = isThenable(promise) ? settledOf(promise) : { status: "fulfilled", value: promise };
|
|
514
|
+
if (known)
|
|
515
|
+
snapshot.set(known.status === "fulfilled" ? { status: "resolved", value: known.value } : { status: "error", error: errorOf(known.reason) });
|
|
516
|
+
else {
|
|
517
|
+
const done = onServer() ? inject4(PendingTasks2).add() : undefined;
|
|
518
|
+
const destroyed = { value: false };
|
|
519
|
+
inject4(DestroyRef3).onDestroy(() => destroyed.value = true);
|
|
520
|
+
Promise.resolve(promise).then((value) => {
|
|
521
|
+
if (!destroyed.value)
|
|
522
|
+
snapshot.set({ status: "resolved", value });
|
|
523
|
+
done?.();
|
|
524
|
+
}, (reason) => {
|
|
525
|
+
if (!destroyed.value)
|
|
526
|
+
snapshot.set({ status: "error", error: errorOf(reason) });
|
|
527
|
+
done?.();
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
const read = snapshot.asReadonly();
|
|
531
|
+
return {
|
|
532
|
+
value: computed2(() => {
|
|
533
|
+
const current = read();
|
|
534
|
+
if (current.status === "error")
|
|
535
|
+
throw current.error;
|
|
536
|
+
return current.value;
|
|
537
|
+
}),
|
|
538
|
+
status: computed2(() => read().status),
|
|
539
|
+
error: computed2(() => {
|
|
540
|
+
const current = read();
|
|
541
|
+
return current.status === "error" ? current.error : undefined;
|
|
542
|
+
}),
|
|
543
|
+
isLoading: computed2(() => read().status === "loading"),
|
|
544
|
+
snapshot: read,
|
|
545
|
+
hasValue: () => {
|
|
546
|
+
const current = read();
|
|
547
|
+
return current.status === "resolved";
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
var errorOf = (reason) => reason instanceof Error ? reason : new Error(String(reason));
|
|
552
|
+
function injectHydrated2() {
|
|
553
|
+
assertInInjectionContext2(injectHydrated2);
|
|
554
|
+
const app = required(HAMUR_APP, "injectHydrated");
|
|
555
|
+
const hydrated = signal2(typeof document !== "undefined" && !onServer() && !app.asyncData.hydrating, ...ngDevMode ? [{ debugName: "hydrated" }] : []);
|
|
556
|
+
const destroy = inject4(DestroyRef3);
|
|
557
|
+
afterNextRender2(() => {
|
|
558
|
+
hydrated.set(!app.asyncData.hydrating);
|
|
559
|
+
destroy.onDestroy(app.hooks.hook("app:mounted", () => hydrated.set(true)));
|
|
560
|
+
});
|
|
561
|
+
return hydrated.asReadonly();
|
|
562
|
+
}
|
|
563
|
+
var HAMUR_IDS = new InjectionToken4("hamur ids", {
|
|
564
|
+
providedIn: "root",
|
|
565
|
+
factory: () => ({ next: 0, prefix: "" })
|
|
566
|
+
});
|
|
567
|
+
function injectId2() {
|
|
568
|
+
assertInInjectionContext2(injectId2);
|
|
569
|
+
const counter = inject4(HAMUR_IDS);
|
|
570
|
+
return `${counter.prefix}${inject4(APP_ID)}-${counter.next++}`;
|
|
571
|
+
}
|
|
572
|
+
function onPrehydrate2(fn) {
|
|
573
|
+
assertInInjectionContext2(onPrehydrate2);
|
|
574
|
+
return prehydrate(required(HAMUR_APP, "onPrehydrate"), fn);
|
|
575
|
+
}
|
|
576
|
+
function transitionName2(name) {
|
|
577
|
+
return { "view-transition-name": checkTransitionName(name) };
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export { HAMUR_APP, HAMUR_ROOT_TREE, HAMUR_ROUTER, HAMUR_NAVIGATION, HAMUR_BASE_URL, HAMUR_HREF, HAMUR_OUTLET_CONTEXT, HAMUR_ROUTE, HAMUR_PAYLOAD, HAMUR_FAIL, HAMUR_CAUGHT, HAMUR_LEVEL_DISPOSE, onServer, required, entryOf, dataOf, islandHref, detachedHref, createState, hamurProviders, setupOf, onPageActivated2, onPageDeactivated2, Outlet2, DevOnly2, injectDeferred2, injectHydrated2, HAMUR_IDS, injectId2, onPrehydrate2, transitionName2 };
|