@ama-mfe/ng-utils 15.3.0-prerelease.9 → 15.4.0-prerelease.0
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/README.md +4 -2
- package/fesm2022/ama-mfe-ng-utils.mjs +2334 -2429
- package/fesm2022/ama-mfe-ng-utils.mjs.map +1 -1
- package/package.json +6 -6
- package/schematics/ng-add/schema.json +0 -3
- package/types/ama-mfe-ng-utils.d.ts +1083 -1060
- package/types/ama-mfe-ng-utils.d.ts.map +1 -1
|
@@ -1,2480 +1,2385 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
1
|
+
import { MESSAGE_PEER_CONFIG, MESSAGE_PEER_CONNECT_OPTIONS, MessagePeerService, MessagePeerService as ConnectionService } from "@amadeus-it-group/microfrontends-angular";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, HostBinding, Injectable, InjectionToken, Pipe, Renderer2, SecurityContext, ViewEncapsulation, afterNextRender, computed, effect, inject, input, makeEnvironmentProviders, provideAppInitializer, signal, untracked } from "@angular/core";
|
|
4
|
+
import { DomSanitizer } from "@angular/platform-browser";
|
|
5
|
+
import { LoggerService } from "@o3r/logger";
|
|
6
|
+
import { HISTORY_MESSAGE_TYPE, NAVIGATION_BLOCK_STATE_MESSAGE_TYPE, NAVIGATION_DECISION_MESSAGE_TYPE, NAVIGATION_MESSAGE_TYPE, NAVIGATION_REQUEST_MESSAGE_TYPE, RESIZE_MESSAGE_TYPE, THEME_MESSAGE_TYPE, USER_ACTIVITY_MESSAGE_TYPE } from "@ama-mfe/messages";
|
|
7
|
+
import { takeUntilDestroyed, toSignal } from "@angular/core/rxjs-interop";
|
|
8
|
+
import { Subject, filter, fromEvent, map, throttleTime } from "rxjs";
|
|
9
|
+
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
|
10
|
+
var ConnectDirective = class ConnectDirective {
|
|
11
|
+
get srcAttr() {
|
|
12
|
+
return this.src();
|
|
13
|
+
}
|
|
14
|
+
constructor() {
|
|
15
|
+
this.connect = input.required(...ngDevMode ? [{ debugName: "connect" }] : /* istanbul ignore next */ []);
|
|
16
|
+
this.src = input(...ngDevMode ? [void 0, { debugName: "src" }] : /* istanbul ignore next */ []);
|
|
17
|
+
this.messageService = inject(MessagePeerService);
|
|
18
|
+
this.domSanitizer = inject(DomSanitizer);
|
|
19
|
+
this.iframeElement = inject(ElementRef).nativeElement;
|
|
20
|
+
this.clientOrigin = computed(() => {
|
|
21
|
+
const src = this.src();
|
|
22
|
+
const srcString = src && this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, src);
|
|
23
|
+
return srcString && new URL(srcString).origin;
|
|
24
|
+
}, ...ngDevMode ? [{ debugName: "clientOrigin" }] : /* istanbul ignore next */ []);
|
|
25
|
+
const logger = inject(LoggerService);
|
|
26
|
+
effect((onCleanup) => {
|
|
27
|
+
let stopHandshakeListening = () => {};
|
|
28
|
+
const origin = this.clientOrigin();
|
|
29
|
+
const id = this.connect();
|
|
30
|
+
const source = this.iframeElement.contentWindow;
|
|
31
|
+
if (origin && source && id) try {
|
|
32
|
+
stopHandshakeListening = this.messageService.listen({
|
|
33
|
+
id,
|
|
34
|
+
source,
|
|
35
|
+
origin
|
|
36
|
+
});
|
|
37
|
+
} catch (e) {
|
|
38
|
+
logger.error(`Failed to start listening for (connection ID: ${id})`, e);
|
|
39
|
+
}
|
|
40
|
+
onCleanup(() => {
|
|
41
|
+
stopHandshakeListening();
|
|
42
|
+
this.messageService.disconnect();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static {
|
|
47
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
48
|
+
minVersion: "12.0.0",
|
|
49
|
+
version: "22.2.3",
|
|
50
|
+
ngImport: i0,
|
|
51
|
+
type: ConnectDirective,
|
|
52
|
+
deps: [],
|
|
53
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
static {
|
|
57
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
58
|
+
minVersion: "17.1.0",
|
|
59
|
+
version: "22.2.3",
|
|
60
|
+
type: ConnectDirective,
|
|
61
|
+
isStandalone: true,
|
|
62
|
+
selector: "iframe[connect]",
|
|
63
|
+
inputs: {
|
|
64
|
+
connect: {
|
|
65
|
+
classPropertyName: "connect",
|
|
66
|
+
publicName: "connect",
|
|
67
|
+
isSignal: true,
|
|
68
|
+
isRequired: true,
|
|
69
|
+
transformFunction: null
|
|
70
|
+
},
|
|
71
|
+
src: {
|
|
72
|
+
classPropertyName: "src",
|
|
73
|
+
publicName: "src",
|
|
74
|
+
isSignal: true,
|
|
75
|
+
isRequired: false,
|
|
76
|
+
transformFunction: null
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
host: { properties: { "src": "this.srcAttr" } },
|
|
80
|
+
ngImport: i0
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
85
|
+
minVersion: "12.0.0",
|
|
86
|
+
version: "22.2.3",
|
|
87
|
+
ngImport: i0,
|
|
88
|
+
type: ConnectDirective,
|
|
89
|
+
decorators: [{
|
|
90
|
+
type: Directive,
|
|
91
|
+
args: [{
|
|
92
|
+
selector: "iframe[connect]",
|
|
93
|
+
standalone: true
|
|
94
|
+
}]
|
|
95
|
+
}],
|
|
96
|
+
ctorParameters: () => [],
|
|
97
|
+
propDecorators: {
|
|
98
|
+
connect: [{
|
|
99
|
+
type: i0.Input,
|
|
100
|
+
args: [{
|
|
101
|
+
isSignal: true,
|
|
102
|
+
alias: "connect",
|
|
103
|
+
required: true
|
|
104
|
+
}]
|
|
105
|
+
}],
|
|
106
|
+
src: [{
|
|
107
|
+
type: i0.Input,
|
|
108
|
+
args: [{
|
|
109
|
+
isSignal: true,
|
|
110
|
+
alias: "src",
|
|
111
|
+
required: false
|
|
112
|
+
}]
|
|
113
|
+
}],
|
|
114
|
+
srcAttr: [{
|
|
115
|
+
type: HostBinding,
|
|
116
|
+
args: ["src"]
|
|
117
|
+
}]
|
|
118
|
+
}
|
|
119
|
+
});
|
|
83
120
|
const getAvailableConsumers = (consumers) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
121
|
+
return {
|
|
122
|
+
type: "declare_messages",
|
|
123
|
+
version: "1.0",
|
|
124
|
+
messages: consumers.flatMap(({ type, supportedVersions }) => Object.keys(supportedVersions).map((version) => ({
|
|
125
|
+
type,
|
|
126
|
+
version
|
|
127
|
+
})))
|
|
128
|
+
};
|
|
89
129
|
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Helper function to send an error message by the given endpoint (peer)
|
|
93
|
-
* @param peer The endpoint sending the message
|
|
94
|
-
* @param content the content of the error message to be sent
|
|
95
|
-
*/
|
|
96
130
|
const sendError = (peer, content) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
return peer.send({
|
|
132
|
+
type: "error",
|
|
133
|
+
version: "1.0",
|
|
134
|
+
...content
|
|
135
|
+
});
|
|
102
136
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
type: Injectable,
|
|
154
|
-
args: [{
|
|
155
|
-
providedIn: 'root'
|
|
156
|
-
}]
|
|
157
|
-
}] });
|
|
158
|
-
|
|
137
|
+
const isErrorMessage = (message) => message && typeof message === "object" && message.type === "error" && !!message.reason;
|
|
138
|
+
var ProducerManagerService = class ProducerManagerService {
|
|
139
|
+
constructor() {
|
|
140
|
+
this.registeredProducers = /* @__PURE__ */ new Set();
|
|
141
|
+
}
|
|
142
|
+
get producers() {
|
|
143
|
+
return [...this.registeredProducers];
|
|
144
|
+
}
|
|
145
|
+
register(producer) {
|
|
146
|
+
this.registeredProducers.add(producer);
|
|
147
|
+
}
|
|
148
|
+
unregister(producer) {
|
|
149
|
+
this.registeredProducers.delete(producer);
|
|
150
|
+
}
|
|
151
|
+
async dispatchError(message) {
|
|
152
|
+
const handlers = this.producers.filter(({ types }) => (Array.isArray(types) ? types : [types]).includes(message.source.type));
|
|
153
|
+
const handlersPresent = handlers.length > 0;
|
|
154
|
+
if (handlersPresent) await Promise.all(handlers.map((handler) => handler.handleError(message)));
|
|
155
|
+
return handlersPresent;
|
|
156
|
+
}
|
|
157
|
+
static {
|
|
158
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
159
|
+
minVersion: "12.0.0",
|
|
160
|
+
version: "22.2.3",
|
|
161
|
+
ngImport: i0,
|
|
162
|
+
type: ProducerManagerService,
|
|
163
|
+
deps: [],
|
|
164
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
static {
|
|
168
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
169
|
+
minVersion: "12.0.0",
|
|
170
|
+
version: "22.2.3",
|
|
171
|
+
ngImport: i0,
|
|
172
|
+
type: ProducerManagerService,
|
|
173
|
+
providedIn: "root"
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
178
|
+
minVersion: "12.0.0",
|
|
179
|
+
version: "22.2.3",
|
|
180
|
+
ngImport: i0,
|
|
181
|
+
type: ProducerManagerService,
|
|
182
|
+
decorators: [{
|
|
183
|
+
type: Injectable,
|
|
184
|
+
args: [{ providedIn: "root" }]
|
|
185
|
+
}]
|
|
186
|
+
});
|
|
159
187
|
const VERSION_MATCH = /^(\d+)\.(\d+)$/;
|
|
160
|
-
/**
|
|
161
|
-
* Parses a "major.minor" version string. Returns undefined if the string is malformed.
|
|
162
|
-
* @param version
|
|
163
|
-
*/
|
|
164
188
|
const parseVersion = (version) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
189
|
+
const match = VERSION_MATCH.exec(version);
|
|
190
|
+
if (!match) return;
|
|
191
|
+
const [major, minor] = match.slice(1).map(Number);
|
|
192
|
+
return {
|
|
193
|
+
major,
|
|
194
|
+
minor,
|
|
195
|
+
raw: version
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
var ConsumerManagerService = class ConsumerManagerService {
|
|
199
|
+
constructor() {
|
|
200
|
+
this.messageService = inject(MessagePeerService);
|
|
201
|
+
this.producerManagerService = inject(ProducerManagerService);
|
|
202
|
+
this.registeredConsumers = signal([], ...ngDevMode ? [{ debugName: "registeredConsumers" }] : /* istanbul ignore next */ []);
|
|
203
|
+
this.logger = inject(LoggerService);
|
|
204
|
+
this.consumers = this.registeredConsumers.asReadonly();
|
|
205
|
+
this.messageService.messages$.pipe(takeUntilDestroyed()).subscribe((message) => this.consumeMessage(message));
|
|
206
|
+
effect(() => {
|
|
207
|
+
const declareMessages = getAvailableConsumers(this.consumers());
|
|
208
|
+
for (const message of declareMessages.messages) this.messageService.registerMessage(message);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
async consumeMessage(message) {
|
|
212
|
+
if (isErrorMessage(message.payload)) {
|
|
213
|
+
if (!await this.producerManagerService.dispatchError(message.payload)) this.logger.warn("Error message not handled", message);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
return this.consumeAdditionalMessage(message);
|
|
217
|
+
}
|
|
218
|
+
async consumeAdditionalMessage(message) {
|
|
219
|
+
if (!message.payload) {
|
|
220
|
+
this.logger.warn("Cannot consume a messages with undefined payload.");
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const typeMatchingConsumers = this.consumers().filter((consumer) => consumer.type === message.payload.type);
|
|
224
|
+
if (typeMatchingConsumers.length === 0) {
|
|
225
|
+
this.logger.warn(`No consumer found for message type: ${message.payload.type}`);
|
|
226
|
+
return sendError(this.messageService, {
|
|
227
|
+
reason: "unknown_type",
|
|
228
|
+
source: message.payload
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const messageVersion = parseVersion(message.payload.version);
|
|
232
|
+
const resolvedConsumers = messageVersion ? typeMatchingConsumers.map((consumer) => {
|
|
233
|
+
const fallbackVersion = Object.keys(consumer.supportedVersions).map((version) => parseVersion(version)).filter((v) => !!v && v.major === messageVersion.major && v.minor <= messageVersion.minor).toSorted((a, b) => b.minor - a.minor).at(0);
|
|
234
|
+
return fallbackVersion && {
|
|
235
|
+
consumer,
|
|
236
|
+
version: fallbackVersion.raw
|
|
237
|
+
};
|
|
238
|
+
}).filter((entry) => !!entry) : [];
|
|
239
|
+
if (resolvedConsumers.length === 0) {
|
|
240
|
+
this.logger.warn(`No consumer found for message version: ${message.payload.version}`);
|
|
241
|
+
return sendError(this.messageService, {
|
|
242
|
+
reason: "version_mismatch",
|
|
243
|
+
source: message.payload
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
await Promise.all(resolvedConsumers.map(async ({ consumer, version }) => {
|
|
247
|
+
try {
|
|
248
|
+
await consumer.supportedVersions[version](message);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
this.logger.error("Error while consuming message", error);
|
|
251
|
+
sendError(this.messageService, {
|
|
252
|
+
reason: "internal_error",
|
|
253
|
+
source: message.payload
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
register(consumer) {
|
|
259
|
+
this.registeredConsumers.update((consumers) => {
|
|
260
|
+
return [...new Set(consumers).add(consumer)];
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
unregister(consumer) {
|
|
264
|
+
this.registeredConsumers.update((consumers) => {
|
|
265
|
+
return consumers.filter((c) => c !== consumer);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
static {
|
|
269
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
270
|
+
minVersion: "12.0.0",
|
|
271
|
+
version: "22.2.3",
|
|
272
|
+
ngImport: i0,
|
|
273
|
+
type: ConsumerManagerService,
|
|
274
|
+
deps: [],
|
|
275
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
static {
|
|
279
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
280
|
+
minVersion: "12.0.0",
|
|
281
|
+
version: "22.2.3",
|
|
282
|
+
ngImport: i0,
|
|
283
|
+
type: ConsumerManagerService,
|
|
284
|
+
providedIn: "root"
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
289
|
+
minVersion: "12.0.0",
|
|
290
|
+
version: "22.2.3",
|
|
291
|
+
ngImport: i0,
|
|
292
|
+
type: ConsumerManagerService,
|
|
293
|
+
decorators: [{
|
|
294
|
+
type: Injectable,
|
|
295
|
+
args: [{ providedIn: "root" }]
|
|
296
|
+
}],
|
|
297
|
+
ctorParameters: () => []
|
|
298
|
+
});
|
|
299
|
+
var AbstractMessageConsumer = class {
|
|
300
|
+
constructor() {
|
|
301
|
+
this.consumerManagerService = inject(ConsumerManagerService);
|
|
302
|
+
this.destroyRef = inject(DestroyRef);
|
|
303
|
+
this.logger = inject(LoggerService);
|
|
304
|
+
}
|
|
305
|
+
start() {
|
|
306
|
+
this.consumerManagerService.register(this);
|
|
307
|
+
this.unregisterCallback?.();
|
|
308
|
+
this.unregisterCallback = this.destroyRef.onDestroy(() => this.stop());
|
|
309
|
+
}
|
|
310
|
+
stop() {
|
|
311
|
+
this.consumerManagerService.unregister(this);
|
|
312
|
+
this.unregisterCallback?.();
|
|
313
|
+
this.unregisterCallback = void 0;
|
|
314
|
+
}
|
|
171
315
|
};
|
|
172
|
-
class ConsumerManagerService {
|
|
173
|
-
constructor() {
|
|
174
|
-
this.messageService = inject(MessagePeerService);
|
|
175
|
-
this.producerManagerService = inject(ProducerManagerService);
|
|
176
|
-
this.registeredConsumers = signal([], /* @ts-ignore */
|
|
177
|
-
...(ngDevMode ? [{ debugName: "registeredConsumers" }] : /* istanbul ignore next */ []));
|
|
178
|
-
this.logger = inject(LoggerService);
|
|
179
|
-
/** The list of registered consumers */
|
|
180
|
-
this.consumers = this.registeredConsumers.asReadonly();
|
|
181
|
-
this.messageService.messages$.pipe(takeUntilDestroyed()).subscribe((message) => this.consumeMessage(message));
|
|
182
|
-
// Each time a consumer is registered/unregistered update the list of registered messages.
|
|
183
|
-
effect(() => {
|
|
184
|
-
const declareMessages = getAvailableConsumers(this.consumers());
|
|
185
|
-
// registering consumed messages locally for validation
|
|
186
|
-
for (const message of declareMessages.messages) {
|
|
187
|
-
this.messageService.registerMessage(message);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Consume a received message
|
|
193
|
-
* @param message the received message body
|
|
194
|
-
*/
|
|
195
|
-
async consumeMessage(message) {
|
|
196
|
-
if (isErrorMessage(message.payload)) {
|
|
197
|
-
const isHandled = await this.producerManagerService.dispatchError(message.payload);
|
|
198
|
-
if (!isHandled) {
|
|
199
|
-
this.logger.warn('Error message not handled', message);
|
|
200
|
-
}
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
return this.consumeAdditionalMessage(message);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Call the registered message callback(s) to consume the given message
|
|
207
|
-
* Handle error messages of internal communication protocol messages
|
|
208
|
-
* @param message message to consume
|
|
209
|
-
*/
|
|
210
|
-
async consumeAdditionalMessage(message) {
|
|
211
|
-
if (!message.payload) {
|
|
212
|
-
this.logger.warn('Cannot consume a messages with undefined payload.');
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const consumers = this.consumers();
|
|
216
|
-
const typeMatchingConsumers = consumers
|
|
217
|
-
.filter((consumer) => consumer.type === message.payload.type);
|
|
218
|
-
if (typeMatchingConsumers.length === 0) {
|
|
219
|
-
this.logger.warn(`No consumer found for message type: ${message.payload.type}`);
|
|
220
|
-
return sendError(this.messageService, { reason: 'unknown_type', source: message.payload });
|
|
221
|
-
}
|
|
222
|
-
// Semver-compatible dispatch: for an incoming v{major}.{minor}, pick each consumer's highest
|
|
223
|
-
// declared v{major}.{n} where n <= minor.
|
|
224
|
-
// Major versions are isolated: no cross-major fallback in either direction. An incoming v2.x
|
|
225
|
-
// will never fall back to a v1.x handler (breaking changes), and a consumer that declares
|
|
226
|
-
// only v2.x will not match an incoming v1.x (the consumer is ahead of the producer). Both
|
|
227
|
-
// result in a version_mismatch error.
|
|
228
|
-
const messageVersion = parseVersion(message.payload.version);
|
|
229
|
-
const resolvedConsumers = messageVersion
|
|
230
|
-
? typeMatchingConsumers
|
|
231
|
-
.map((consumer) => {
|
|
232
|
-
const fallbackVersion = Object.keys(consumer.supportedVersions)
|
|
233
|
-
.map((version) => parseVersion(version))
|
|
234
|
-
.filter((v) => !!v && v.major === messageVersion.major && v.minor <= messageVersion.minor)
|
|
235
|
-
.toSorted((a, b) => b.minor - a.minor)
|
|
236
|
-
.at(0);
|
|
237
|
-
return fallbackVersion && { consumer, version: fallbackVersion.raw };
|
|
238
|
-
})
|
|
239
|
-
.filter((entry) => !!entry)
|
|
240
|
-
: [];
|
|
241
|
-
if (resolvedConsumers.length === 0) {
|
|
242
|
-
this.logger.warn(`No consumer found for message version: ${message.payload.version}`);
|
|
243
|
-
return sendError(this.messageService, { reason: 'version_mismatch', source: message.payload });
|
|
244
|
-
}
|
|
245
|
-
await Promise.all(resolvedConsumers
|
|
246
|
-
.map(async ({ consumer, version }) => {
|
|
247
|
-
try {
|
|
248
|
-
await consumer.supportedVersions[version](message);
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
this.logger.error('Error while consuming message', error);
|
|
252
|
-
sendError(this.messageService, { reason: 'internal_error', source: message.payload });
|
|
253
|
-
}
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Register a message consumer
|
|
258
|
-
* @param consumer an instance of message consumer
|
|
259
|
-
*/
|
|
260
|
-
register(consumer) {
|
|
261
|
-
this.registeredConsumers.update((consumers) => {
|
|
262
|
-
return [...new Set(consumers).add(consumer)];
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Unregister a message consumer
|
|
267
|
-
* @param consumer an instance of message consumer
|
|
268
|
-
*/
|
|
269
|
-
unregister(consumer) {
|
|
270
|
-
this.registeredConsumers.update((consumers) => {
|
|
271
|
-
return consumers.filter((c) => c !== consumer);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ConsumerManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
275
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ConsumerManagerService, providedIn: 'root' }); }
|
|
276
|
-
}
|
|
277
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ConsumerManagerService, decorators: [{
|
|
278
|
-
type: Injectable,
|
|
279
|
-
args: [{
|
|
280
|
-
providedIn: 'root'
|
|
281
|
-
}]
|
|
282
|
-
}], ctorParameters: () => [] });
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* An abstract base class for message consumers that provides common functionality for registering and unregistering with the ConsumerManagerService.
|
|
286
|
-
*
|
|
287
|
-
* This class implements the MessageConsumer interface and provides a default implementation for the start and stop methods.
|
|
288
|
-
* It also handles the automatic registration and unregistration of the consumer with the ConsumerManagerService when the service is created and destroyed.
|
|
289
|
-
*
|
|
290
|
-
* To use this class, simply extend it and implement the required properties (type and supportedVersions) and any additional logic needed to consume messages.
|
|
291
|
-
*/
|
|
292
|
-
class AbstractMessageConsumer {
|
|
293
|
-
constructor() {
|
|
294
|
-
/** The service used to register the consumer */
|
|
295
|
-
this.consumerManagerService = inject(ConsumerManagerService);
|
|
296
|
-
/** The reference used to handle the destruction of the consumer */
|
|
297
|
-
this.destroyRef = inject(DestroyRef);
|
|
298
|
-
/** Logger shared with subclasses. */
|
|
299
|
-
this.logger = inject(LoggerService);
|
|
300
|
-
}
|
|
301
|
-
/** @inheritdoc */
|
|
302
|
-
start() {
|
|
303
|
-
this.consumerManagerService.register(this);
|
|
304
|
-
this.unregisterCallback?.();
|
|
305
|
-
this.unregisterCallback = this.destroyRef.onDestroy(() => this.stop());
|
|
306
|
-
}
|
|
307
|
-
/** @inheritdoc */
|
|
308
|
-
stop() {
|
|
309
|
-
this.consumerManagerService.unregister(this);
|
|
310
|
-
this.unregisterCallback?.();
|
|
311
|
-
this.unregisterCallback = undefined;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Method to call in the constructor of a producer
|
|
317
|
-
* @note should be used in injection context
|
|
318
|
-
* @param producer
|
|
319
|
-
*/
|
|
320
316
|
const registerProducer = (producer) => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
317
|
+
const producerManagerService = inject(ProducerManagerService);
|
|
318
|
+
producerManagerService.register(producer);
|
|
319
|
+
inject(DestroyRef).onDestroy(() => {
|
|
320
|
+
producerManagerService.unregister(producer);
|
|
321
|
+
});
|
|
326
322
|
};
|
|
327
|
-
/**
|
|
328
|
-
* Method to call in the constructor of a consumer
|
|
329
|
-
* @note should be used in injection context
|
|
330
|
-
* @param consumer
|
|
331
|
-
*/
|
|
332
323
|
const registerConsumer = (consumer) => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
324
|
+
const consumerManagerService = inject(ConsumerManagerService);
|
|
325
|
+
consumerManagerService.register(consumer);
|
|
326
|
+
inject(DestroyRef).onDestroy(() => {
|
|
327
|
+
consumerManagerService.unregister(consumer);
|
|
328
|
+
});
|
|
338
329
|
};
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
* - Prevent pushing states to history, replace state instead
|
|
378
|
-
* - Handle history navigation via History messages to let the host manage the states
|
|
379
|
-
*/
|
|
330
|
+
var HistoryConsumerService = class HistoryConsumerService extends AbstractMessageConsumer {
|
|
331
|
+
constructor() {
|
|
332
|
+
super(...arguments);
|
|
333
|
+
this.type = HISTORY_MESSAGE_TYPE;
|
|
334
|
+
this.supportedVersions = { "1.0": (message) => {
|
|
335
|
+
history.go(message.payload.delta);
|
|
336
|
+
} };
|
|
337
|
+
}
|
|
338
|
+
static {
|
|
339
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
340
|
+
minVersion: "12.0.0",
|
|
341
|
+
version: "22.2.3",
|
|
342
|
+
ngImport: i0,
|
|
343
|
+
type: HistoryConsumerService,
|
|
344
|
+
deps: null,
|
|
345
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
static {
|
|
349
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
350
|
+
minVersion: "12.0.0",
|
|
351
|
+
version: "22.2.3",
|
|
352
|
+
ngImport: i0,
|
|
353
|
+
type: HistoryConsumerService,
|
|
354
|
+
providedIn: "root"
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
359
|
+
minVersion: "12.0.0",
|
|
360
|
+
version: "22.2.3",
|
|
361
|
+
ngImport: i0,
|
|
362
|
+
type: HistoryConsumerService,
|
|
363
|
+
decorators: [{
|
|
364
|
+
type: Injectable,
|
|
365
|
+
args: [{ providedIn: "root" }]
|
|
366
|
+
}]
|
|
367
|
+
});
|
|
380
368
|
function provideHistoryOverrides() {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
369
|
+
return provideAppInitializer(() => {
|
|
370
|
+
const messageService = inject(MessagePeerService);
|
|
371
|
+
const navigate = (delta) => {
|
|
372
|
+
messageService.send({
|
|
373
|
+
type: "history",
|
|
374
|
+
version: "1.0",
|
|
375
|
+
delta
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
Object.defineProperty(history, "pushState", {
|
|
379
|
+
value: (data, unused, url) => {
|
|
380
|
+
history.replaceState(data, unused, url);
|
|
381
|
+
},
|
|
382
|
+
writable: false,
|
|
383
|
+
configurable: false
|
|
384
|
+
});
|
|
385
|
+
Object.defineProperty(history, "back", {
|
|
386
|
+
value: () => navigate(-1),
|
|
387
|
+
writable: false,
|
|
388
|
+
configurable: false
|
|
389
|
+
});
|
|
390
|
+
Object.defineProperty(history, "forward", {
|
|
391
|
+
value: () => navigate(1),
|
|
392
|
+
writable: false,
|
|
393
|
+
configurable: false
|
|
394
|
+
});
|
|
395
|
+
Object.defineProperty(history, "go", {
|
|
396
|
+
value: (delta) => navigate(delta),
|
|
397
|
+
writable: false,
|
|
398
|
+
configurable: false
|
|
399
|
+
});
|
|
400
|
+
});
|
|
413
401
|
}
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
* Search parameter to add to the URL to let a module know on which application it's embedded
|
|
424
|
-
*/
|
|
425
|
-
const MFE_HOST_APPLICATION_ID_PARAM = 'ama-mfe-host-app-id';
|
|
426
|
-
/**
|
|
427
|
-
* Search parameter to add to the URL to identify the application in the network of peers in the communication protocol
|
|
428
|
-
*/
|
|
429
|
-
const MFE_MODULE_APPLICATION_ID_PARAM = 'ama-mfe-module-app-id';
|
|
430
|
-
/** The list of query parameters which can be set by the host */
|
|
431
|
-
const hostQueryParams = [MFE_HOST_URL_PARAM, MFE_HOST_APPLICATION_ID_PARAM, MFE_MODULE_APPLICATION_ID_PARAM];
|
|
432
|
-
/**
|
|
433
|
-
* Gather the host information from the url parameters
|
|
434
|
-
* The host url will use the first found among:
|
|
435
|
-
* - look for the search parameter {@link MFE_HOST_URL_PARAM} in the URL of the iframe
|
|
436
|
-
* - use the first item in `location.ancestorOrigins` (currently not supported on Firefox)
|
|
437
|
-
* - use `document.referrer` (will only work if called before any redirection in the iframe)
|
|
438
|
-
* The host application ID is taken from the search parameter {@link MFE_HOST_APPLICATION_ID_PARAM} in the URL of the iframe
|
|
439
|
-
* The module application ID is taken from the search parameter {@link MFE_APPLICATION_ID_PARAM} in the URL of the iframe
|
|
440
|
-
* @param locationParam - A {@link Location} object with information about the current location of the document. Defaults to global {@link location}.
|
|
441
|
-
*/
|
|
402
|
+
const SESSION_STORAGE_KEY = "ama-mfe-host-info";
|
|
403
|
+
const MFE_HOST_URL_PARAM = "ama-mfe-host-url";
|
|
404
|
+
const MFE_HOST_APPLICATION_ID_PARAM = "ama-mfe-host-app-id";
|
|
405
|
+
const MFE_MODULE_APPLICATION_ID_PARAM = "ama-mfe-module-app-id";
|
|
406
|
+
const hostQueryParams = [
|
|
407
|
+
MFE_HOST_URL_PARAM,
|
|
408
|
+
MFE_HOST_APPLICATION_ID_PARAM,
|
|
409
|
+
MFE_MODULE_APPLICATION_ID_PARAM
|
|
410
|
+
];
|
|
442
411
|
function getHostInfo(locationParam = location) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
412
|
+
const searchParams = new URLSearchParams(locationParam.search);
|
|
413
|
+
const storedHostInfo = JSON.parse(sessionStorage.getItem(SESSION_STORAGE_KEY) || "{}");
|
|
414
|
+
return {
|
|
415
|
+
hostURL: searchParams.get("ama-mfe-host-url") || storedHostInfo.hostURL || locationParam.ancestorOrigins?.[0] || document.referrer,
|
|
416
|
+
hostApplicationId: searchParams.get("ama-mfe-host-app-id") || storedHostInfo.hostApplicationId,
|
|
417
|
+
moduleApplicationId: searchParams.get("ama-mfe-module-app-id") || storedHostInfo.moduleApplicationId
|
|
418
|
+
};
|
|
450
419
|
}
|
|
451
|
-
/**
|
|
452
|
-
* Gather the host information from the url parameters and handle the persistence in session storage.
|
|
453
|
-
*/
|
|
454
420
|
function persistHostInfo() {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* A pipe that adds the host information in the URL of an iframe,
|
|
461
|
-
*/
|
|
462
|
-
class HostInfoPipe {
|
|
463
|
-
constructor() {
|
|
464
|
-
this.domSanitizer = inject(DomSanitizer);
|
|
465
|
-
}
|
|
466
|
-
transform(url, options) {
|
|
467
|
-
const urlString = typeof url === 'string'
|
|
468
|
-
? url
|
|
469
|
-
: this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url || null);
|
|
470
|
-
if (!url) {
|
|
471
|
-
return undefined;
|
|
472
|
-
}
|
|
473
|
-
if (urlString) {
|
|
474
|
-
const moduleUrl = new URL(urlString);
|
|
475
|
-
moduleUrl.searchParams.set(MFE_HOST_URL_PARAM, window.location.origin);
|
|
476
|
-
moduleUrl.searchParams.set(MFE_HOST_APPLICATION_ID_PARAM, options.hostId);
|
|
477
|
-
if (options.moduleId) {
|
|
478
|
-
moduleUrl.searchParams.set(MFE_MODULE_APPLICATION_ID_PARAM, options.moduleId);
|
|
479
|
-
}
|
|
480
|
-
const moduleUrlStringyfied = moduleUrl.toString();
|
|
481
|
-
return typeof url === 'string' ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: HostInfoPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
485
|
-
/** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: HostInfoPipe, isStandalone: true, name: "hostInfo" }); }
|
|
421
|
+
const hostInfo = getHostInfo();
|
|
422
|
+
sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(hostInfo));
|
|
486
423
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
424
|
+
var HostInfoPipe = class HostInfoPipe {
|
|
425
|
+
constructor() {
|
|
426
|
+
this.domSanitizer = inject(DomSanitizer);
|
|
427
|
+
}
|
|
428
|
+
transform(url, options) {
|
|
429
|
+
const urlString = typeof url === "string" ? url : this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url || null);
|
|
430
|
+
if (!url) return;
|
|
431
|
+
if (urlString) {
|
|
432
|
+
const moduleUrl = new URL(urlString);
|
|
433
|
+
moduleUrl.searchParams.set(MFE_HOST_URL_PARAM, window.location.origin);
|
|
434
|
+
moduleUrl.searchParams.set(MFE_HOST_APPLICATION_ID_PARAM, options.hostId);
|
|
435
|
+
if (options.moduleId) moduleUrl.searchParams.set(MFE_MODULE_APPLICATION_ID_PARAM, options.moduleId);
|
|
436
|
+
const moduleUrlStringyfied = moduleUrl.toString();
|
|
437
|
+
return typeof url === "string" ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
static {
|
|
441
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
442
|
+
minVersion: "12.0.0",
|
|
443
|
+
version: "22.2.3",
|
|
444
|
+
ngImport: i0,
|
|
445
|
+
type: HostInfoPipe,
|
|
446
|
+
deps: [],
|
|
447
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
static {
|
|
451
|
+
this.ɵpipe = i0.ɵɵngDeclarePipe({
|
|
452
|
+
minVersion: "14.0.0",
|
|
453
|
+
version: "22.2.3",
|
|
454
|
+
ngImport: i0,
|
|
455
|
+
type: HostInfoPipe,
|
|
456
|
+
isStandalone: true,
|
|
457
|
+
name: "hostInfo"
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
462
|
+
minVersion: "12.0.0",
|
|
463
|
+
version: "22.2.3",
|
|
464
|
+
ngImport: i0,
|
|
465
|
+
type: HostInfoPipe,
|
|
466
|
+
decorators: [{
|
|
467
|
+
type: Pipe,
|
|
468
|
+
args: [{ name: "hostInfo" }]
|
|
469
|
+
}]
|
|
470
|
+
});
|
|
471
|
+
const ERROR_MESSAGE_TYPE = "error";
|
|
501
472
|
function isUserActivityMessage(message) {
|
|
502
|
-
|
|
503
|
-
&& message !== null
|
|
504
|
-
&& 'type' in message
|
|
505
|
-
&& message.type === USER_ACTIVITY_MESSAGE_TYPE);
|
|
473
|
+
return typeof message === "object" && message !== null && "type" in message && message.type === USER_ACTIVITY_MESSAGE_TYPE;
|
|
506
474
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
const KNOWN_MESSAGES = [
|
|
512
|
-
{
|
|
513
|
-
type: ERROR_MESSAGE_TYPE,
|
|
514
|
-
version: '1.0'
|
|
515
|
-
}
|
|
516
|
-
];
|
|
517
|
-
/**
|
|
518
|
-
* Returns the default options for starting a client endpoint peer connection.
|
|
519
|
-
* As `origin`, it will take the hostURL from {@link getHostInfo} and the `window` will be the parent window.
|
|
520
|
-
*/
|
|
475
|
+
const KNOWN_MESSAGES = [{
|
|
476
|
+
type: ERROR_MESSAGE_TYPE,
|
|
477
|
+
version: "1.0"
|
|
478
|
+
}];
|
|
521
479
|
function getDefaultClientEndpointStartOptions() {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
return {};
|
|
480
|
+
const hostInfo = getHostInfo();
|
|
481
|
+
if (hostInfo.hostURL) return {
|
|
482
|
+
origin: new URL(hostInfo.hostURL).origin,
|
|
483
|
+
window: window.parent
|
|
484
|
+
};
|
|
485
|
+
return {};
|
|
530
486
|
}
|
|
531
|
-
/**
|
|
532
|
-
* Return `true` if embedded inside an iframe, `false` otherwise
|
|
533
|
-
* @param windowParam - A {@link window} object with information about the current window of the document. Defaults to global {@link window}.
|
|
534
|
-
*/
|
|
535
487
|
function isEmbedded(windowParam = window) {
|
|
536
|
-
|
|
488
|
+
return windowParam.top !== windowParam.self;
|
|
537
489
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
* @param prefix Optional prefix used by the fallback path to make ids easier to identify in logs (ignored when `crypto.randomUUID` is available).
|
|
542
|
-
*/
|
|
543
|
-
function generateCorrelationId(prefix = 'corr') {
|
|
544
|
-
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
545
|
-
return crypto.randomUUID();
|
|
546
|
-
}
|
|
547
|
-
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
490
|
+
function generateCorrelationId(prefix = "corr") {
|
|
491
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
492
|
+
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
548
493
|
}
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Provide the communication protocol connection configuration
|
|
552
|
-
* @param connectionConfigOptions The identifier of the application in the communication protocol ecosystem plus the types of messages able to exchange and a logger object
|
|
553
|
-
*/
|
|
554
494
|
function provideConnection(connectionConfigOptions) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
* This service listens for resize messages and updates the height of elements based on the received messages.
|
|
583
|
-
*/
|
|
584
|
-
class ResizeConsumerService extends AbstractMessageConsumer {
|
|
585
|
-
constructor() {
|
|
586
|
-
super(...arguments);
|
|
587
|
-
this.newHeight = signal(undefined, /* @ts-ignore */
|
|
588
|
-
...(ngDevMode ? [{ debugName: "newHeight" }] : /* istanbul ignore next */ []));
|
|
589
|
-
/**
|
|
590
|
-
* A readonly signal that provides the new height information from the channel.
|
|
591
|
-
*/
|
|
592
|
-
this.newHeightFromChannel = this.newHeight.asReadonly();
|
|
593
|
-
/**
|
|
594
|
-
* The type of messages this service handles ('resize').
|
|
595
|
-
*/
|
|
596
|
-
this.type = RESIZE_MESSAGE_TYPE;
|
|
597
|
-
/**
|
|
598
|
-
* The supported versions of resize messages and their handlers.
|
|
599
|
-
*/
|
|
600
|
-
this.supportedVersions = {
|
|
601
|
-
/**
|
|
602
|
-
* Use the message paylod to compute a new height and emit it via the public signal
|
|
603
|
-
* @param message message to consume
|
|
604
|
-
*/
|
|
605
|
-
'1.0': (message) => this.newHeight.set({ height: message.payload.height, channelId: message.from })
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ResizeConsumerService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
609
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ResizeConsumerService, providedIn: 'root' }); }
|
|
495
|
+
persistHostInfo();
|
|
496
|
+
const connectionId = isEmbedded() && getHostInfo().moduleApplicationId || connectionConfigOptions?.id;
|
|
497
|
+
if (!connectionId) {
|
|
498
|
+
(connectionConfigOptions?.logger || console).error("An id (moduleId) needs to be provided for the application in order to establish a connection inside the communication protocol");
|
|
499
|
+
return makeEnvironmentProviders([]);
|
|
500
|
+
}
|
|
501
|
+
const config = {
|
|
502
|
+
id: connectionId,
|
|
503
|
+
messageCheckStrategy: "version",
|
|
504
|
+
knownMessages: [...KNOWN_MESSAGES, ...connectionConfigOptions?.knownMessages || []]
|
|
505
|
+
};
|
|
506
|
+
return makeEnvironmentProviders([
|
|
507
|
+
{
|
|
508
|
+
provide: MESSAGE_PEER_CONFIG,
|
|
509
|
+
useValue: config
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
provide: MESSAGE_PEER_CONNECT_OPTIONS,
|
|
513
|
+
useValue: getDefaultClientEndpointStartOptions()
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
provide: MessagePeerService,
|
|
517
|
+
useClass: ConnectionService,
|
|
518
|
+
deps: [MESSAGE_PEER_CONFIG]
|
|
519
|
+
},
|
|
520
|
+
...isEmbedded() ? [provideHistoryOverrides()] : []
|
|
521
|
+
]);
|
|
610
522
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
523
|
+
var ResizeConsumerService = class ResizeConsumerService extends AbstractMessageConsumer {
|
|
524
|
+
constructor() {
|
|
525
|
+
super(...arguments);
|
|
526
|
+
this.newHeight = signal(void 0, ...ngDevMode ? [{ debugName: "newHeight" }] : /* istanbul ignore next */ []);
|
|
527
|
+
this.newHeightFromChannel = this.newHeight.asReadonly();
|
|
528
|
+
this.type = RESIZE_MESSAGE_TYPE;
|
|
529
|
+
this.supportedVersions = { "1.0": (message) => this.newHeight.set({
|
|
530
|
+
height: message.payload.height,
|
|
531
|
+
channelId: message.from
|
|
532
|
+
}) };
|
|
533
|
+
}
|
|
534
|
+
static {
|
|
535
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
536
|
+
minVersion: "12.0.0",
|
|
537
|
+
version: "22.2.3",
|
|
538
|
+
ngImport: i0,
|
|
539
|
+
type: ResizeConsumerService,
|
|
540
|
+
deps: null,
|
|
541
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
static {
|
|
545
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
546
|
+
minVersion: "12.0.0",
|
|
547
|
+
version: "22.2.3",
|
|
548
|
+
ngImport: i0,
|
|
549
|
+
type: ResizeConsumerService,
|
|
550
|
+
providedIn: "root"
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
555
|
+
minVersion: "12.0.0",
|
|
556
|
+
version: "22.2.3",
|
|
557
|
+
ngImport: i0,
|
|
558
|
+
type: ResizeConsumerService,
|
|
559
|
+
decorators: [{
|
|
560
|
+
type: Injectable,
|
|
561
|
+
args: [{ providedIn: "root" }]
|
|
562
|
+
}]
|
|
563
|
+
});
|
|
564
|
+
var ScalableDirective = class ScalableDirective {
|
|
565
|
+
constructor() {
|
|
566
|
+
this.connect = input(...ngDevMode ? [void 0, { debugName: "connect" }] : /* istanbul ignore next */ []);
|
|
567
|
+
this.scalable = input(...ngDevMode ? [void 0, { debugName: "scalable" }] : /* istanbul ignore next */ []);
|
|
568
|
+
this.resizeHandler = inject(ResizeConsumerService);
|
|
569
|
+
this.destroyRef = inject(DestroyRef);
|
|
570
|
+
this.elem = inject(ElementRef);
|
|
571
|
+
this.renderer = inject(Renderer2);
|
|
572
|
+
this.availableHeight = signal(void 0, ...ngDevMode ? [{ debugName: "availableHeight" }] : /* istanbul ignore next */ []);
|
|
573
|
+
this.container = null;
|
|
574
|
+
this.newHeightFromChannel = computed(() => {
|
|
575
|
+
const channelAskingResize = this.scalable() || this.connect();
|
|
576
|
+
const newHeightFromChannel = this.resizeHandler.newHeightFromChannel();
|
|
577
|
+
if (channelAskingResize && newHeightFromChannel?.channelId === channelAskingResize) return newHeightFromChannel;
|
|
578
|
+
}, ...ngDevMode ? [{ debugName: "newHeightFromChannel" }] : /* istanbul ignore next */ []);
|
|
579
|
+
this.resizeHandler.start();
|
|
580
|
+
afterNextRender({ read: () => this.startHeightObserver() });
|
|
581
|
+
effect(() => this.applyMinHeight(this.newHeightFromChannel()?.height));
|
|
582
|
+
effect(() => this.applyMinHeight(this.availableHeight()));
|
|
583
|
+
this.destroyRef.onDestroy(() => {
|
|
584
|
+
this.resizeObserver?.disconnect();
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
getViewportHeight() {
|
|
588
|
+
const visualViewport = window.visualViewport;
|
|
589
|
+
return visualViewport ? visualViewport.height * visualViewport.scale : window.innerHeight;
|
|
590
|
+
}
|
|
591
|
+
calculateAvailableHeight() {
|
|
592
|
+
if (this.container) return this.container.clientHeight || void 0;
|
|
593
|
+
const rect = this.elem.nativeElement.getBoundingClientRect();
|
|
594
|
+
const availableHeight = Math.floor(this.getViewportHeight() - rect.top);
|
|
595
|
+
return availableHeight > 0 ? availableHeight : void 0;
|
|
596
|
+
}
|
|
597
|
+
findScrollableParent(element) {
|
|
598
|
+
let parent = element.parentElement;
|
|
599
|
+
while (parent) {
|
|
600
|
+
const { overflowY, overflow } = window.getComputedStyle(parent);
|
|
601
|
+
if (overflowY === "auto" || overflowY === "scroll" || overflow === "auto" || overflow === "scroll") return parent;
|
|
602
|
+
parent = parent.parentElement;
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
startHeightObserver() {
|
|
607
|
+
this.container = this.findScrollableParent(this.elem.nativeElement);
|
|
608
|
+
this.observeWindowResize();
|
|
609
|
+
this.resizeObserver = new ResizeObserver(() => this.updateAvailableHeight());
|
|
610
|
+
this.resizeObserver.observe(this.container || document.body);
|
|
611
|
+
this.updateAvailableHeight();
|
|
612
|
+
}
|
|
613
|
+
observeWindowResize() {
|
|
614
|
+
fromEvent(window, "resize").pipe(throttleTime(16), takeUntilDestroyed(this.destroyRef)).subscribe(() => {
|
|
615
|
+
this.updateAvailableHeight();
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
updateAvailableHeight() {
|
|
619
|
+
const height = this.calculateAvailableHeight();
|
|
620
|
+
if (height && height !== this.availableHeight()) this.availableHeight.set(height);
|
|
621
|
+
}
|
|
622
|
+
applyMinHeight(height) {
|
|
623
|
+
if (height && height !== this.lastAppliedMinHeight) {
|
|
624
|
+
this.lastAppliedMinHeight = height;
|
|
625
|
+
this.renderer.setStyle(this.elem.nativeElement, "min-height", `${height}px`);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
static {
|
|
629
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
630
|
+
minVersion: "12.0.0",
|
|
631
|
+
version: "22.2.3",
|
|
632
|
+
ngImport: i0,
|
|
633
|
+
type: ScalableDirective,
|
|
634
|
+
deps: [],
|
|
635
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
static {
|
|
639
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
640
|
+
minVersion: "17.1.0",
|
|
641
|
+
version: "22.2.3",
|
|
642
|
+
type: ScalableDirective,
|
|
643
|
+
isStandalone: true,
|
|
644
|
+
selector: "[scalable]",
|
|
645
|
+
inputs: {
|
|
646
|
+
connect: {
|
|
647
|
+
classPropertyName: "connect",
|
|
648
|
+
publicName: "connect",
|
|
649
|
+
isSignal: true,
|
|
650
|
+
isRequired: false,
|
|
651
|
+
transformFunction: null
|
|
652
|
+
},
|
|
653
|
+
scalable: {
|
|
654
|
+
classPropertyName: "scalable",
|
|
655
|
+
publicName: "scalable",
|
|
656
|
+
isSignal: true,
|
|
657
|
+
isRequired: false,
|
|
658
|
+
transformFunction: null
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
ngImport: i0
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
666
|
+
minVersion: "12.0.0",
|
|
667
|
+
version: "22.2.3",
|
|
668
|
+
ngImport: i0,
|
|
669
|
+
type: ScalableDirective,
|
|
670
|
+
decorators: [{
|
|
671
|
+
type: Directive,
|
|
672
|
+
args: [{
|
|
673
|
+
selector: "[scalable]",
|
|
674
|
+
standalone: true
|
|
675
|
+
}]
|
|
676
|
+
}],
|
|
677
|
+
ctorParameters: () => [],
|
|
678
|
+
propDecorators: {
|
|
679
|
+
connect: [{
|
|
680
|
+
type: i0.Input,
|
|
681
|
+
args: [{
|
|
682
|
+
isSignal: true,
|
|
683
|
+
alias: "connect",
|
|
684
|
+
required: false
|
|
685
|
+
}]
|
|
686
|
+
}],
|
|
687
|
+
scalable: [{
|
|
688
|
+
type: i0.Input,
|
|
689
|
+
args: [{
|
|
690
|
+
isSignal: true,
|
|
691
|
+
alias: "scalable",
|
|
692
|
+
required: false
|
|
693
|
+
}]
|
|
694
|
+
}]
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
const THEME_URL_SUFFIX = "-theme.css";
|
|
698
|
+
const THEME_QUERY_PARAM_NAME = "theme";
|
|
783
699
|
async function getStyle(cssPath, options) {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
return '';
|
|
700
|
+
try {
|
|
701
|
+
const myRequest = new Request(cssPath);
|
|
702
|
+
const response = await fetch(myRequest);
|
|
703
|
+
return response.ok ? await response.text() : "";
|
|
704
|
+
} catch (error) {
|
|
705
|
+
options?.logger?.warn(`Failed to download style from: ${cssPath} with error: ${error?.toString()}`);
|
|
706
|
+
}
|
|
707
|
+
return "";
|
|
794
708
|
}
|
|
795
|
-
/**
|
|
796
|
-
* Applies the given CSS theme as a stylesheet.
|
|
797
|
-
* @param themeValue - CSS as text containing a theme definition.
|
|
798
|
-
* @param cleanPrevious - Whether to remove previously applied stylesheets if no themeValue provided. Default is true.
|
|
799
|
-
*/
|
|
800
709
|
function applyTheme(themeValue, cleanPrevious = true) {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
else if (cleanPrevious) { // remove the styles if the theme value comes undefined or empty string
|
|
807
|
-
document.adoptedStyleSheets = [];
|
|
808
|
-
}
|
|
710
|
+
if (themeValue !== void 0) {
|
|
711
|
+
const sheet = new CSSStyleSheet();
|
|
712
|
+
sheet.replaceSync(themeValue);
|
|
713
|
+
document.adoptedStyleSheets = cleanPrevious ? [sheet] : [...document.adoptedStyleSheets, sheet];
|
|
714
|
+
} else if (cleanPrevious) document.adoptedStyleSheets = [];
|
|
809
715
|
}
|
|
810
|
-
/**
|
|
811
|
-
* Download the application additional theme
|
|
812
|
-
* @param theme Name of the theme to download from the current application
|
|
813
|
-
* @param options Options and context for Style helpers
|
|
814
|
-
*/
|
|
815
716
|
function downloadApplicationThemeCss(theme, options) {
|
|
816
|
-
|
|
817
|
-
return getStyle(cssHref, options);
|
|
717
|
+
return getStyle(`${theme.endsWith(".css") ? theme : theme + THEME_URL_SUFFIX}`, options);
|
|
818
718
|
}
|
|
819
|
-
/**
|
|
820
|
-
* Applies the initial theme based on the URL query parameters.
|
|
821
|
-
*
|
|
822
|
-
* This function fetches the CSS theme specified in the URL query parameters and applies it as a stylesheet.
|
|
823
|
-
* If a referrer is present, it also attempts to fetch and apply the theme from the referrer's URL.
|
|
824
|
-
* @param options Options and context for Style helpers
|
|
825
|
-
*/
|
|
826
719
|
async function applyInitialTheme(options) {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
840
|
-
return Promise.allSettled(themeRequest);
|
|
841
|
-
}
|
|
842
|
-
return undefined;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
/**
|
|
846
|
-
* This service exposing the current theme signal
|
|
847
|
-
*/
|
|
848
|
-
class ThemeProducerService {
|
|
849
|
-
constructor() {
|
|
850
|
-
this.messageService = inject((MessagePeerService));
|
|
851
|
-
this.logger = inject(LoggerService);
|
|
852
|
-
this.window = inject(Window, { optional: true }) || window;
|
|
853
|
-
/**
|
|
854
|
-
* The type of messages this service handles ('theme').
|
|
855
|
-
*/
|
|
856
|
-
this.types = THEME_MESSAGE_TYPE;
|
|
857
|
-
registerProducer(this);
|
|
858
|
-
// get the current theme name from the url (if any) and emit a first value for the current theme
|
|
859
|
-
const parentUrl = new URL(this.window.location.toString());
|
|
860
|
-
const selectedThemeName = parentUrl.searchParams.get(THEME_QUERY_PARAM_NAME);
|
|
861
|
-
this.currentThemeSelection = signal(selectedThemeName
|
|
862
|
-
? {
|
|
863
|
-
name: selectedThemeName,
|
|
864
|
-
css: null
|
|
865
|
-
}
|
|
866
|
-
: undefined, /* @ts-ignore */
|
|
867
|
-
...(ngDevMode ? [{ debugName: "currentThemeSelection" }] : /* istanbul ignore next */ []));
|
|
868
|
-
this.currentTheme = this.currentThemeSelection.asReadonly();
|
|
869
|
-
if (selectedThemeName) {
|
|
870
|
-
void this.changeTheme(selectedThemeName);
|
|
871
|
-
}
|
|
872
|
-
// When the current theme changes, apply it to the current application
|
|
873
|
-
effect(() => {
|
|
874
|
-
const themeObj = this.currentTheme();
|
|
875
|
-
if (themeObj?.css !== null) {
|
|
876
|
-
applyTheme(themeObj?.css);
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
/**
|
|
880
|
-
* This effect listens for changes in the `currentTheme` signal. If a valid theme object with CSS is present,
|
|
881
|
-
* it creates a theme message and sends it via the message service.
|
|
882
|
-
*/
|
|
883
|
-
effect(() => {
|
|
884
|
-
const themeObj = this.currentTheme();
|
|
885
|
-
if (themeObj && themeObj.css !== null) {
|
|
886
|
-
const messageV10 = {
|
|
887
|
-
type: 'theme',
|
|
888
|
-
name: themeObj.name,
|
|
889
|
-
css: themeObj.css,
|
|
890
|
-
version: '1.0'
|
|
891
|
-
};
|
|
892
|
-
// TODO: sendBest() is not yet implemented -- https://github.com/AmadeusITGroup/microfrontends/issues/11
|
|
893
|
-
this.messageService.send(messageV10);
|
|
894
|
-
}
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* Changes the current theme to the specified theme name.
|
|
899
|
-
* @param themeName - The name of the theme to change to.
|
|
900
|
-
*/
|
|
901
|
-
async changeTheme(themeName) {
|
|
902
|
-
const cssHref = themeName && `${themeName}${THEME_URL_SUFFIX}`;
|
|
903
|
-
const styleObj = cssHref ? await getStyle(cssHref) : '';
|
|
904
|
-
this.currentThemeSelection.update((theme) => {
|
|
905
|
-
this.previousTheme = theme;
|
|
906
|
-
return themeName
|
|
907
|
-
? { name: themeName, css: styleObj }
|
|
908
|
-
: undefined;
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* Reverts to the previous theme.
|
|
913
|
-
*/
|
|
914
|
-
revertToPreviousTheme() {
|
|
915
|
-
this.currentThemeSelection.set(this.previousTheme);
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* @inheritdoc
|
|
919
|
-
*/
|
|
920
|
-
handleError(message) {
|
|
921
|
-
this.logger.error('Error in theme service message', message);
|
|
922
|
-
this.revertToPreviousTheme();
|
|
923
|
-
}
|
|
924
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ThemeProducerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
925
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ThemeProducerService, providedIn: 'root' }); }
|
|
926
|
-
}
|
|
927
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ThemeProducerService, decorators: [{
|
|
928
|
-
type: Injectable,
|
|
929
|
-
args: [{
|
|
930
|
-
providedIn: 'root'
|
|
931
|
-
}]
|
|
932
|
-
}], ctorParameters: () => [] });
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* A pipe that applies the current theme from a theme manager service, to a given URL or SafeResourceUrl, as query param
|
|
936
|
-
*/
|
|
937
|
-
class ApplyTheme {
|
|
938
|
-
constructor() {
|
|
939
|
-
this.themeManagerService = inject(ThemeProducerService);
|
|
940
|
-
this.domSanitizer = inject(DomSanitizer);
|
|
941
|
-
}
|
|
942
|
-
transform(url) {
|
|
943
|
-
if (!url) {
|
|
944
|
-
return undefined;
|
|
945
|
-
}
|
|
946
|
-
const currentTheme = this.themeManagerService.currentTheme();
|
|
947
|
-
const urlString = typeof url === 'string'
|
|
948
|
-
? url
|
|
949
|
-
: this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url);
|
|
950
|
-
if (urlString) {
|
|
951
|
-
const moduleUrl = new URL(urlString);
|
|
952
|
-
if (currentTheme) {
|
|
953
|
-
moduleUrl.searchParams.set('theme', currentTheme.name);
|
|
954
|
-
}
|
|
955
|
-
const moduleUrlStringyfied = moduleUrl.toString();
|
|
956
|
-
return typeof url === 'string' ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
|
|
957
|
-
}
|
|
958
|
-
return undefined;
|
|
959
|
-
}
|
|
960
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ApplyTheme, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
961
|
-
/** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: ApplyTheme, isStandalone: true, name: "applyTheme" }); }
|
|
962
|
-
}
|
|
963
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ApplyTheme, decorators: [{
|
|
964
|
-
type: Pipe,
|
|
965
|
-
args: [{
|
|
966
|
-
name: 'applyTheme'
|
|
967
|
-
}]
|
|
968
|
-
}] });
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Directive to set the sandbox attribute on an iframe element.
|
|
972
|
-
* Uses Renderer2 to set the attribute once at initialization, respecting the security intent (no runtime changes).
|
|
973
|
-
* @example
|
|
974
|
-
* ```html
|
|
975
|
-
* <iframe [mfeSandbox]="'allow-scripts allow-same-origin'" />
|
|
976
|
-
* ```
|
|
977
|
-
*/
|
|
978
|
-
class SandboxDirective {
|
|
979
|
-
constructor() {
|
|
980
|
-
this.elementRef = inject(ElementRef);
|
|
981
|
-
this.renderer = inject(Renderer2);
|
|
982
|
-
/**
|
|
983
|
-
* The sandbox permissions to apply to the iframe.
|
|
984
|
-
* Defaults to empty string (most restrictive: all restrictions apply).
|
|
985
|
-
* Set once at initialization; runtime changes are ignored for security reasons.
|
|
986
|
-
*/
|
|
987
|
-
this.mfeSandbox = input('', /* @ts-ignore */
|
|
988
|
-
...(ngDevMode ? [{ debugName: "mfeSandbox" }] : /* istanbul ignore next */ []));
|
|
989
|
-
}
|
|
990
|
-
ngOnInit() {
|
|
991
|
-
this.renderer.setAttribute(this.elementRef.nativeElement, 'sandbox', this.mfeSandbox());
|
|
992
|
-
}
|
|
993
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: SandboxDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
994
|
-
/** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: SandboxDirective, isStandalone: true, selector: "iframe[mfeSandbox]", inputs: { mfeSandbox: { classPropertyName: "mfeSandbox", publicName: "mfeSandbox", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
|
|
995
|
-
}
|
|
996
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: SandboxDirective, decorators: [{
|
|
997
|
-
type: Directive,
|
|
998
|
-
args: [{
|
|
999
|
-
selector: 'iframe[mfeSandbox]'
|
|
1000
|
-
}]
|
|
1001
|
-
}], propDecorators: { mfeSandbox: [{ type: i0.Input, args: [{ isSignal: true, alias: "mfeSandbox", required: false }] }] } });
|
|
1002
|
-
|
|
1003
|
-
/**
|
|
1004
|
-
* Presentational component for rendering an iframe with MFE integration directives.
|
|
1005
|
-
* Applies host info injection, theming and cross-iframe communication.
|
|
1006
|
-
*/
|
|
1007
|
-
class IframeEmbedComponent {
|
|
1008
|
-
constructor() {
|
|
1009
|
-
this.domSanitizer = inject(DomSanitizer);
|
|
1010
|
-
/** The URL for the iframe source (plain string or pre-sanitized SafeResourceUrl). */
|
|
1011
|
-
this.src = input.required(/* @ts-ignore */
|
|
1012
|
-
...(ngDevMode ? [{ debugName: "src" }] : /* istanbul ignore next */ []));
|
|
1013
|
-
/** The sanitized URL, auto-sanitized if a plain string is provided. */
|
|
1014
|
-
this.safeSrc = computed(() => {
|
|
1015
|
-
const value = this.src();
|
|
1016
|
-
return typeof value === 'string'
|
|
1017
|
-
? this.domSanitizer.bypassSecurityTrustResourceUrl(value)
|
|
1018
|
-
: value;
|
|
1019
|
-
}, /* @ts-ignore */
|
|
1020
|
-
...(ngDevMode ? [{ debugName: "safeSrc" }] : /* istanbul ignore next */ []));
|
|
1021
|
-
/** The unique identifier for the module, used for cross-iframe communication. */
|
|
1022
|
-
this.moduleId = input.required(/* @ts-ignore */
|
|
1023
|
-
...(ngDevMode ? [{ debugName: "moduleId" }] : /* istanbul ignore next */ []));
|
|
1024
|
-
/** The host application identifier sent to the embedded module. */
|
|
1025
|
-
this.hostApplicationId = input.required(/* @ts-ignore */
|
|
1026
|
-
...(ngDevMode ? [{ debugName: "hostApplicationId" }] : /* istanbul ignore next */ []));
|
|
1027
|
-
/**
|
|
1028
|
-
* The sandbox attribute for the iframe.
|
|
1029
|
-
* Pass through to the SandboxDirective on the iframe element.
|
|
1030
|
-
*/
|
|
1031
|
-
this.sandbox = input('allow-scripts allow-same-origin', /* @ts-ignore */
|
|
1032
|
-
...(ngDevMode ? [{ debugName: "sandbox" }] : /* istanbul ignore next */ []));
|
|
1033
|
-
}
|
|
1034
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: IframeEmbedComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1035
|
-
/** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.0", type: IframeEmbedComponent, isStandalone: true, selector: "mfe-iframe-embed", inputs: { src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: true, transformFunction: null }, moduleId: { classPropertyName: "moduleId", publicName: "moduleId", isSignal: true, isRequired: true, transformFunction: null }, hostApplicationId: { classPropertyName: "hostApplicationId", publicName: "hostApplicationId", isSignal: true, isRequired: true, transformFunction: null }, sandbox: { classPropertyName: "sandbox", publicName: "sandbox", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "@let hostInfoOptions = {hostId: hostApplicationId(), moduleId: moduleId()};\n<iframe\n [connect]=\"hostInfoOptions.moduleId\"\n scalable\n [src]=\"safeSrc() | hostInfo: hostInfoOptions | applyTheme\"\n [mfeSandbox]=\"sandbox()\">\n</iframe>\n", styles: ["mfe-iframe-embed iframe{height:100%;width:100%;display:block}\n"], dependencies: [{ kind: "directive", type: ConnectDirective, selector: "iframe[connect]", inputs: ["connect", "src"] }, { kind: "directive", type: ScalableDirective, selector: "[scalable]", inputs: ["connect", "scalable"] }, { kind: "directive", type: SandboxDirective, selector: "iframe[mfeSandbox]", inputs: ["mfeSandbox"] }, { kind: "pipe", type: ApplyTheme, name: "applyTheme" }, { kind: "pipe", type: HostInfoPipe, name: "hostInfo" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
1036
|
-
}
|
|
1037
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: IframeEmbedComponent, decorators: [{
|
|
1038
|
-
type: Component,
|
|
1039
|
-
args: [{ selector: 'mfe-iframe-embed', imports: [
|
|
1040
|
-
ConnectDirective,
|
|
1041
|
-
ScalableDirective,
|
|
1042
|
-
ApplyTheme,
|
|
1043
|
-
HostInfoPipe,
|
|
1044
|
-
SandboxDirective
|
|
1045
|
-
], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "@let hostInfoOptions = {hostId: hostApplicationId(), moduleId: moduleId()};\n<iframe\n [connect]=\"hostInfoOptions.moduleId\"\n scalable\n [src]=\"safeSrc() | hostInfo: hostInfoOptions | applyTheme\"\n [mfeSandbox]=\"sandbox()\">\n</iframe>\n", styles: ["mfe-iframe-embed iframe{height:100%;width:100%;display:block}\n"] }]
|
|
1046
|
-
}], propDecorators: { src: [{ type: i0.Input, args: [{ isSignal: true, alias: "src", required: true }] }], moduleId: [{ type: i0.Input, args: [{ isSignal: true, alias: "moduleId", required: true }] }], hostApplicationId: [{ type: i0.Input, args: [{ isSignal: true, alias: "hostApplicationId", required: true }] }], sandbox: [{ type: i0.Input, args: [{ isSignal: true, alias: "sandbox", required: false }] }] } });
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* A service that handles navigation messages and routing.
|
|
1050
|
-
*
|
|
1051
|
-
* This service listens for navigation messages and updates the router state accordingly.
|
|
1052
|
-
*/
|
|
1053
|
-
class NavigationConsumerService extends AbstractMessageConsumer {
|
|
1054
|
-
constructor() {
|
|
1055
|
-
super(...arguments);
|
|
1056
|
-
this.router = inject(Router);
|
|
1057
|
-
this.activeRoute = inject(ActivatedRoute);
|
|
1058
|
-
this.requestedUrl = new Subject();
|
|
1059
|
-
/**
|
|
1060
|
-
* An observable that emits the requested URL and optional channel ID.
|
|
1061
|
-
*/
|
|
1062
|
-
this.requestedUrl$ = this.requestedUrl.asObservable();
|
|
1063
|
-
/**
|
|
1064
|
-
* The type of messages this service handles.
|
|
1065
|
-
*/
|
|
1066
|
-
this.type = NAVIGATION_MESSAGE_TYPE;
|
|
1067
|
-
/**
|
|
1068
|
-
* @inheritdoc
|
|
1069
|
-
*/
|
|
1070
|
-
this.supportedVersions = {
|
|
1071
|
-
/**
|
|
1072
|
-
* Use the message paylod to compute a new url and emit it via the public subject
|
|
1073
|
-
* Additionally navigate to the new url
|
|
1074
|
-
* @param message message to consume
|
|
1075
|
-
*/
|
|
1076
|
-
'1.0': (message) => {
|
|
1077
|
-
const channelId = message.from || undefined;
|
|
1078
|
-
this.requestedUrl.next({ url: message.payload.url, channelId });
|
|
1079
|
-
this.navigate(message.payload.url);
|
|
1080
|
-
},
|
|
1081
|
-
/**
|
|
1082
|
-
* Same as 1.0 but applies the navigation extras (e.g. replaceUrl) forwarded by the producer
|
|
1083
|
-
* so the host router reproduces the original history semantics.
|
|
1084
|
-
* @param message message to consume
|
|
1085
|
-
*/
|
|
1086
|
-
// eslint-disable-next-line @stylistic/quote-props -- keep quotes for consistency with '1.0'
|
|
1087
|
-
'1.1': (message) => {
|
|
1088
|
-
const channelId = message.from || undefined;
|
|
1089
|
-
this.requestedUrl.next({ url: message.payload.url, channelId });
|
|
1090
|
-
this.navigate(message.payload.url, message.payload.extras);
|
|
1091
|
-
}
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
/**
|
|
1095
|
-
* Parses a URL and returns an object containing the paths and query parameters.
|
|
1096
|
-
* @param url - The URL to parse.
|
|
1097
|
-
* @returns An object containing the paths and query parameters.
|
|
1098
|
-
*/
|
|
1099
|
-
parseUrl(url) {
|
|
1100
|
-
const urlObject = new URL(window.origin + url);
|
|
1101
|
-
const paths = urlObject.pathname.split('/').filter((segment) => !!segment);
|
|
1102
|
-
const queryParams = Object.fromEntries(urlObject.searchParams.entries());
|
|
1103
|
-
return { paths, queryParams };
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* Navigates to the specified URL.
|
|
1107
|
-
* @param url - The URL to navigate to.
|
|
1108
|
-
* @param extras - Optional navigation extras forwarded from the embedded application.
|
|
1109
|
-
*/
|
|
1110
|
-
navigate(url, extras) {
|
|
1111
|
-
const { paths, queryParams } = this.parseUrl(url);
|
|
1112
|
-
// No need to keep these in the URL
|
|
1113
|
-
hostQueryParams.forEach((key) => delete queryParams[key]);
|
|
1114
|
-
void this.router.navigate(paths, {
|
|
1115
|
-
relativeTo: this.activeRoute.children.at(-1),
|
|
1116
|
-
queryParams,
|
|
1117
|
-
replaceUrl: extras?.replaceUrl
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationConsumerService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1121
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationConsumerService, providedIn: 'root' }); }
|
|
1122
|
-
}
|
|
1123
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationConsumerService, decorators: [{
|
|
1124
|
-
type: Injectable,
|
|
1125
|
-
args: [{
|
|
1126
|
-
providedIn: 'root'
|
|
1127
|
-
}]
|
|
1128
|
-
}] });
|
|
1129
|
-
|
|
1130
|
-
/**
|
|
1131
|
-
* This service allows routes to be memorized with an optional lifetime and provides methods to retrieve and manage these routes.
|
|
1132
|
-
*/
|
|
1133
|
-
class RouteMemorizeService {
|
|
1134
|
-
constructor() {
|
|
1135
|
-
this.routeTimers = {};
|
|
1136
|
-
/** All memorized routes */
|
|
1137
|
-
this.routeStack = {};
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* Memorizes a route for a given channel ID with an optional lifetime.
|
|
1141
|
-
* @param channelId - The ID of the channel to memorize the route for.
|
|
1142
|
-
* @param url - The URL of the route to memorize.
|
|
1143
|
-
* @param liveTime - The optional lifetime of the memorized route in milliseconds. If provided, the route will be removed after this time.
|
|
1144
|
-
*/
|
|
1145
|
-
memorizeRoute(channelId, url, liveTime) {
|
|
1146
|
-
this.routeStack[channelId] = url;
|
|
1147
|
-
const timerRef = this.routeTimers[channelId];
|
|
1148
|
-
if (timerRef) {
|
|
1149
|
-
clearTimeout(timerRef);
|
|
1150
|
-
}
|
|
1151
|
-
if (liveTime && liveTime > 0) {
|
|
1152
|
-
this.routeTimers[channelId] = setTimeout(() => {
|
|
1153
|
-
delete this.routeStack[channelId];
|
|
1154
|
-
delete this.routeTimers[channelId];
|
|
1155
|
-
}, liveTime);
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* Retrieves the memorized route for a given channel ID.
|
|
1160
|
-
* @param channelId - The ID of the channel to retrieve the memorized route for.
|
|
1161
|
-
* @returns The memorized route URL or undefined if no route is memorized for the given channel ID.
|
|
1162
|
-
*/
|
|
1163
|
-
getRoute(channelId) {
|
|
1164
|
-
return this.routeStack[channelId];
|
|
1165
|
-
}
|
|
1166
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RouteMemorizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1167
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RouteMemorizeService, providedIn: 'root' }); }
|
|
1168
|
-
}
|
|
1169
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RouteMemorizeService, decorators: [{
|
|
1170
|
-
type: Injectable,
|
|
1171
|
-
args: [{
|
|
1172
|
-
providedIn: 'root'
|
|
1173
|
-
}]
|
|
1174
|
-
}] });
|
|
1175
|
-
|
|
1176
|
-
/**
|
|
1177
|
-
* A pipe that restores a route with optional query parameters and memory channel ID.
|
|
1178
|
-
*
|
|
1179
|
-
* This pipe is used to transform a URL or SafeResourceUrl by appending query parameters
|
|
1180
|
-
* and adjusting the pathname based on the current active route and memorized route.
|
|
1181
|
-
*/
|
|
1182
|
-
class RestoreRoute {
|
|
1183
|
-
constructor() {
|
|
1184
|
-
this.activeRoute = inject(ActivatedRoute);
|
|
1185
|
-
this.domSanitizer = inject(DomSanitizer);
|
|
1186
|
-
this.routeMemorizeService = inject(RouteMemorizeService, { optional: true });
|
|
1187
|
-
this.window = inject(Window, { optional: true }) || window;
|
|
1188
|
-
}
|
|
1189
|
-
transform(url, options) {
|
|
1190
|
-
const urlString = typeof url === 'string'
|
|
1191
|
-
? url
|
|
1192
|
-
: this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url || null);
|
|
1193
|
-
if (!url) {
|
|
1194
|
-
return undefined;
|
|
1195
|
-
}
|
|
1196
|
-
if (urlString) {
|
|
1197
|
-
const moduleUrl = new URL(urlString);
|
|
1198
|
-
const queryParamsModule = new URLSearchParams(moduleUrl.searchParams);
|
|
1199
|
-
const channelId = options?.memoryChannelId;
|
|
1200
|
-
const memorizedRoute = channelId && this.routeMemorizeService?.getRoute(channelId);
|
|
1201
|
-
const topWindowUrl = new URL(memorizedRoute ? this.window.origin + memorizedRoute : this.window.location.href);
|
|
1202
|
-
const queryParamsTopWindow = new URLSearchParams(topWindowUrl.search);
|
|
1203
|
-
if (options?.propagateQueryParams) {
|
|
1204
|
-
for (const [key, value] of queryParamsTopWindow) {
|
|
1205
|
-
if (options?.overrideQueryParams || !queryParamsModule.has(key)) {
|
|
1206
|
-
queryParamsModule.set(key, value);
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
moduleUrl.search = queryParamsModule.toString();
|
|
1211
|
-
moduleUrl.pathname += topWindowUrl.pathname.split(`/${this.activeRoute.routeConfig?.path}`).pop() || '';
|
|
1212
|
-
moduleUrl.pathname = moduleUrl.pathname.replace(/\/{2,}/g, '/');
|
|
1213
|
-
const moduleUrlStringyfied = moduleUrl.toString();
|
|
1214
|
-
return typeof url === 'string' ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RestoreRoute, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1218
|
-
/** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: RestoreRoute, isStandalone: true, name: "restoreRoute" }); }
|
|
1219
|
-
}
|
|
1220
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RestoreRoute, decorators: [{
|
|
1221
|
-
type: Pipe,
|
|
1222
|
-
args: [{
|
|
1223
|
-
name: 'restoreRoute'
|
|
1224
|
-
}]
|
|
1225
|
-
}] });
|
|
1226
|
-
|
|
1227
|
-
class RouteMemorizeDirective {
|
|
1228
|
-
constructor() {
|
|
1229
|
-
/**
|
|
1230
|
-
* Whether to memorize the route.
|
|
1231
|
-
* Default is true.
|
|
1232
|
-
*/
|
|
1233
|
-
this.memorizeRoute = input(true, /* @ts-ignore */
|
|
1234
|
-
...(ngDevMode ? [{ debugName: "memorizeRoute" }] : /* istanbul ignore next */ []));
|
|
1235
|
-
/**
|
|
1236
|
-
* The ID used to memorize the route.
|
|
1237
|
-
*/
|
|
1238
|
-
this.memorizeRouteId = input(/* @ts-ignore */
|
|
1239
|
-
...(ngDevMode ? [undefined, { debugName: "memorizeRouteId" }] : /* istanbul ignore next */ []));
|
|
1240
|
-
/**
|
|
1241
|
-
* The maximum age for memorizing the route.
|
|
1242
|
-
* Default is 0.
|
|
1243
|
-
*/
|
|
1244
|
-
this.memorizeMaxAge = input(0, /* @ts-ignore */
|
|
1245
|
-
...(ngDevMode ? [{ debugName: "memorizeMaxAge" }] : /* istanbul ignore next */ []));
|
|
1246
|
-
/**
|
|
1247
|
-
* The maximum age for memorizing the route, used as a fallback.
|
|
1248
|
-
* Default is 0.
|
|
1249
|
-
*/
|
|
1250
|
-
this.memorizeRouteMaxAge = input(0, /* @ts-ignore */
|
|
1251
|
-
...(ngDevMode ? [{ debugName: "memorizeRouteMaxAge" }] : /* istanbul ignore next */ []));
|
|
1252
|
-
/**
|
|
1253
|
-
* The connection ID for the iframe where the actual directive is applied.
|
|
1254
|
-
*/
|
|
1255
|
-
this.connect = input(/* @ts-ignore */
|
|
1256
|
-
...(ngDevMode ? [undefined, { debugName: "connect" }] : /* istanbul ignore next */ []));
|
|
1257
|
-
this.maxAge = computed(() => {
|
|
1258
|
-
return this.memorizeMaxAge() || this.memorizeRouteMaxAge();
|
|
1259
|
-
}, /* @ts-ignore */
|
|
1260
|
-
...(ngDevMode ? [{ debugName: "maxAge" }] : /* istanbul ignore next */ []));
|
|
1261
|
-
const memory = inject(RouteMemorizeService);
|
|
1262
|
-
const requestedUrlSignal = toSignal(inject(NavigationConsumerService).requestedUrl$);
|
|
1263
|
-
/**
|
|
1264
|
-
* This effect listens for changes in the `memorizeRoute`, `requestedUrlSignal`, and `memorizeRouteId` or `connect` inputs.
|
|
1265
|
-
* If `memorizeRoute` is not false and a requested URL with a matching channel ID is found, it memorizes the route using the route memory service.
|
|
1266
|
-
*/
|
|
1267
|
-
effect(() => {
|
|
1268
|
-
const memorizeRoute = this.memorizeRoute();
|
|
1269
|
-
if (memorizeRoute === false) {
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
const requested = requestedUrlSignal();
|
|
1273
|
-
const channelId = this.connect();
|
|
1274
|
-
const id = this.memorizeRouteId() || channelId;
|
|
1275
|
-
if (requested && id && requested.channelId === channelId) {
|
|
1276
|
-
memory.memorizeRoute(id, requested.url, untracked(this.maxAge));
|
|
1277
|
-
}
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RouteMemorizeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1281
|
-
/** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: RouteMemorizeDirective, isStandalone: true, selector: "iframe[memorizeRoute]", inputs: { memorizeRoute: { classPropertyName: "memorizeRoute", publicName: "memorizeRoute", isSignal: true, isRequired: false, transformFunction: null }, memorizeRouteId: { classPropertyName: "memorizeRouteId", publicName: "memorizeRouteId", isSignal: true, isRequired: false, transformFunction: null }, memorizeMaxAge: { classPropertyName: "memorizeMaxAge", publicName: "memorizeMaxAge", isSignal: true, isRequired: false, transformFunction: null }, memorizeRouteMaxAge: { classPropertyName: "memorizeRouteMaxAge", publicName: "memorizeRouteMaxAge", isSignal: true, isRequired: false, transformFunction: null }, connect: { classPropertyName: "connect", publicName: "connect", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
|
|
1282
|
-
}
|
|
1283
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RouteMemorizeDirective, decorators: [{
|
|
1284
|
-
type: Directive,
|
|
1285
|
-
args: [{
|
|
1286
|
-
selector: 'iframe[memorizeRoute]',
|
|
1287
|
-
standalone: true
|
|
1288
|
-
}]
|
|
1289
|
-
}], ctorParameters: () => [], propDecorators: { memorizeRoute: [{ type: i0.Input, args: [{ isSignal: true, alias: "memorizeRoute", required: false }] }], memorizeRouteId: [{ type: i0.Input, args: [{ isSignal: true, alias: "memorizeRouteId", required: false }] }], memorizeMaxAge: [{ type: i0.Input, args: [{ isSignal: true, alias: "memorizeMaxAge", required: false }] }], memorizeRouteMaxAge: [{ type: i0.Input, args: [{ isSignal: true, alias: "memorizeRouteMaxAge", required: false }] }], connect: [{ type: i0.Input, args: [{ isSignal: true, alias: "connect", required: false }] }] } });
|
|
1290
|
-
|
|
1291
|
-
/**
|
|
1292
|
-
* A service that keeps in sync Router navigation and navigation messages.
|
|
1293
|
-
*
|
|
1294
|
-
* - listens to Router events and sends navigation messages
|
|
1295
|
-
* - handles incoming navigation messages and triggers Router navigation
|
|
1296
|
-
*/
|
|
1297
|
-
class RoutingService {
|
|
1298
|
-
constructor() {
|
|
1299
|
-
this.router = inject(Router);
|
|
1300
|
-
this.activatedRoute = inject(ActivatedRoute);
|
|
1301
|
-
this.messageService = inject((MessagePeerService));
|
|
1302
|
-
this.logger = inject(LoggerService);
|
|
1303
|
-
this.window = inject(Window, { optional: true }) || window;
|
|
1304
|
-
/**
|
|
1305
|
-
* @inheritdoc
|
|
1306
|
-
*/
|
|
1307
|
-
this.types = NAVIGATION_MESSAGE_TYPE;
|
|
1308
|
-
/**
|
|
1309
|
-
* @inheritdoc
|
|
1310
|
-
*/
|
|
1311
|
-
this.type = 'navigation';
|
|
1312
|
-
/**
|
|
1313
|
-
* Use the message payload to navigate to the specified URL.
|
|
1314
|
-
* @param message message to consume
|
|
1315
|
-
*/
|
|
1316
|
-
this.supportedVersions = {
|
|
1317
|
-
'1.0': async (message) => {
|
|
1318
|
-
// Navigation has been triggered from the communication protocol request.
|
|
1319
|
-
await this.router.navigateByUrl(message.payload.url, { state: { triggeredByMessage: true } });
|
|
1320
|
-
},
|
|
1321
|
-
// eslint-disable-next-line @stylistic/quote-props -- keep quotes for consistency with '1.0'
|
|
1322
|
-
'1.1': async (message) => {
|
|
1323
|
-
// Navigation has been triggered from the communication protocol request.
|
|
1324
|
-
await this.router.navigateByUrl(message.payload.url, {
|
|
1325
|
-
state: { triggeredByMessage: true },
|
|
1326
|
-
replaceUrl: message.payload.extras?.replaceUrl
|
|
1327
|
-
});
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1330
|
-
registerProducer(this);
|
|
1331
|
-
registerConsumer(this);
|
|
1332
|
-
}
|
|
1333
|
-
/**
|
|
1334
|
-
* @inheritdoc
|
|
1335
|
-
*/
|
|
1336
|
-
start() { }
|
|
1337
|
-
/**
|
|
1338
|
-
* @inheritdoc
|
|
1339
|
-
*/
|
|
1340
|
-
stop() { }
|
|
1341
|
-
/**
|
|
1342
|
-
* @inheritdoc
|
|
1343
|
-
*/
|
|
1344
|
-
handleError(message) {
|
|
1345
|
-
this.logger.error('Error in navigation service message', message);
|
|
1346
|
-
}
|
|
1347
|
-
/**
|
|
1348
|
-
* Handles embedded routing by listening to router events and sending navigation messages to the connected endpoints.
|
|
1349
|
-
* It can be a parent window or another iframe
|
|
1350
|
-
* @note - This method has to be called in an injection context
|
|
1351
|
-
* @param options - Optional parameters to control the routing behavior {@link RoutingServiceOptions}.
|
|
1352
|
-
*/
|
|
1353
|
-
handleEmbeddedRouting(options) {
|
|
1354
|
-
const subRouteOnly = options?.subRouteOnly ?? false;
|
|
1355
|
-
this.router.events.pipe(takeUntilDestroyed(), filter((event) => event instanceof NavigationEnd), filter((_event) => {
|
|
1356
|
-
const extras = this.router.getCurrentNavigation()?.extras || {};
|
|
1357
|
-
// Navigation triggered by the application host, no need to request it to navigate to the same route
|
|
1358
|
-
return !extras.skipLocationChange && !extras.state?.triggeredByMessage;
|
|
1359
|
-
}), map(({ urlAfterRedirects }) => {
|
|
1360
|
-
const extras = this.router.getCurrentNavigation()?.extras || {};
|
|
1361
|
-
const { channelId } = extras.state || {};
|
|
1362
|
-
const currentRouteRegExp = subRouteOnly && this.activatedRoute.routeConfig?.path && new RegExp('^' + this.activatedRoute.routeConfig.path.replace(/(?=\W)/g, '\\'), 'i');
|
|
1363
|
-
return ({
|
|
1364
|
-
url: currentRouteRegExp ? urlAfterRedirects.replace(currentRouteRegExp, '') : urlAfterRedirects,
|
|
1365
|
-
channelId,
|
|
1366
|
-
replaceUrl: extras.replaceUrl
|
|
1367
|
-
});
|
|
1368
|
-
})).subscribe(({ url, channelId, replaceUrl }) => {
|
|
1369
|
-
// Always emit the latest version we produce. The ConsumerManagerService dispatches to the
|
|
1370
|
-
// highest compatible minor a consumer has declared, so v1.0-only peers still navigate
|
|
1371
|
-
// correctly — they just ignore the optional extras.
|
|
1372
|
-
const message = {
|
|
1373
|
-
type: 'navigation',
|
|
1374
|
-
version: '1.1',
|
|
1375
|
-
url,
|
|
1376
|
-
...(replaceUrl ? { extras: { replaceUrl: true } } : {})
|
|
1377
|
-
};
|
|
1378
|
-
// TODO: sendBest() is not implemented -- https://github.com/AmadeusITGroup/microfrontends/issues/11
|
|
1379
|
-
// When multiple majors are supported, sendBest should receive the latest minor of each
|
|
1380
|
-
// supported major and dispatch to peers according to their declared compatibility.
|
|
1381
|
-
if (isEmbedded(this.window)) {
|
|
1382
|
-
this.messageService.send(message);
|
|
1383
|
-
}
|
|
1384
|
-
else if (channelId === undefined) {
|
|
1385
|
-
this.logger.warn('No channelId provided for navigation message');
|
|
1386
|
-
}
|
|
1387
|
-
else {
|
|
1388
|
-
try {
|
|
1389
|
-
this.messageService.send(message, { to: [channelId] });
|
|
1390
|
-
}
|
|
1391
|
-
catch (error) {
|
|
1392
|
-
this.logger.error('Error sending navigation message', error);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RoutingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1398
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RoutingService, providedIn: 'root' }); }
|
|
1399
|
-
}
|
|
1400
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: RoutingService, decorators: [{
|
|
1401
|
-
type: Injectable,
|
|
1402
|
-
args: [{
|
|
1403
|
-
providedIn: 'root'
|
|
1404
|
-
}]
|
|
1405
|
-
}], ctorParameters: () => [] });
|
|
1406
|
-
|
|
1407
|
-
/**
|
|
1408
|
-
* Module-side writable source of truth for the navigation block state.
|
|
1409
|
-
*
|
|
1410
|
-
* Feature code (forms, editors, etc.) calls {@link block} when unsaved changes appear and {@link unblock} once they are saved or discarded.
|
|
1411
|
-
* The {@link NavigationBlockStateProducerService} watches this signal and mirrors the state to the shell;
|
|
1412
|
-
* the {@link navigationBlockModuleGuard} reads it to decide whether to intercept in-module navigation.
|
|
1413
|
-
*/
|
|
1414
|
-
class NavigationBlockService {
|
|
1415
|
-
constructor() {
|
|
1416
|
-
this.stateSignal = signal({ blocked: false }, /* @ts-ignore */
|
|
1417
|
-
...(ngDevMode ? [{ debugName: "stateSignal" }] : /* istanbul ignore next */ []));
|
|
1418
|
-
/** Readonly view of the current navigation block state. */
|
|
1419
|
-
this.state = this.stateSignal.asReadonly();
|
|
1420
|
-
}
|
|
1421
|
-
/**
|
|
1422
|
-
* Mark the module as blocked (unsaved changes present).
|
|
1423
|
-
* @param reason Optional human-readable reason shown in the confirmation modal.
|
|
1424
|
-
*/
|
|
1425
|
-
block(reason) {
|
|
1426
|
-
this.stateSignal.set({ blocked: true, reason });
|
|
1427
|
-
}
|
|
1428
|
-
/** Mark the module as unblocked (no unsaved changes). */
|
|
1429
|
-
unblock() {
|
|
1430
|
-
this.stateSignal.set({ blocked: false });
|
|
1431
|
-
}
|
|
1432
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBlockService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1433
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBlockService, providedIn: 'root' }); }
|
|
720
|
+
const theme = new URLSearchParams(window.location.search).get(THEME_QUERY_PARAM_NAME);
|
|
721
|
+
document.adoptedStyleSheets = [];
|
|
722
|
+
if (theme) {
|
|
723
|
+
const themeRequest = [downloadApplicationThemeCss(theme, options).then((styleToApply) => applyTheme(styleToApply, false))];
|
|
724
|
+
const hostInfo = getHostInfo();
|
|
725
|
+
if (hostInfo.hostURL) {
|
|
726
|
+
const url = new URL(hostInfo.hostURL);
|
|
727
|
+
url.pathname += `${url.pathname.endsWith("/") ? "" : "/"}${theme}`;
|
|
728
|
+
themeRequest.unshift(getStyle(url.toString(), options).then((styleToApply) => applyTheme(styleToApply, false)));
|
|
729
|
+
}
|
|
730
|
+
return Promise.allSettled(themeRequest);
|
|
731
|
+
}
|
|
1434
732
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
733
|
+
var ThemeProducerService = class ThemeProducerService {
|
|
734
|
+
constructor() {
|
|
735
|
+
this.messageService = inject(MessagePeerService);
|
|
736
|
+
this.logger = inject(LoggerService);
|
|
737
|
+
this.window = inject(Window, { optional: true }) || window;
|
|
738
|
+
this.types = THEME_MESSAGE_TYPE;
|
|
739
|
+
registerProducer(this);
|
|
740
|
+
const selectedThemeName = new URL(this.window.location.toString()).searchParams.get(THEME_QUERY_PARAM_NAME);
|
|
741
|
+
this.currentThemeSelection = signal(selectedThemeName ? {
|
|
742
|
+
name: selectedThemeName,
|
|
743
|
+
css: null
|
|
744
|
+
} : void 0, ...ngDevMode ? [{ debugName: "currentThemeSelection" }] : /* istanbul ignore next */ []);
|
|
745
|
+
this.currentTheme = this.currentThemeSelection.asReadonly();
|
|
746
|
+
if (selectedThemeName) this.changeTheme(selectedThemeName);
|
|
747
|
+
effect(() => {
|
|
748
|
+
const themeObj = this.currentTheme();
|
|
749
|
+
if (themeObj?.css !== null) applyTheme(themeObj?.css);
|
|
750
|
+
});
|
|
751
|
+
effect(() => {
|
|
752
|
+
const themeObj = this.currentTheme();
|
|
753
|
+
if (themeObj && themeObj.css !== null) {
|
|
754
|
+
const messageV10 = {
|
|
755
|
+
type: "theme",
|
|
756
|
+
name: themeObj.name,
|
|
757
|
+
css: themeObj.css,
|
|
758
|
+
version: "1.0"
|
|
759
|
+
};
|
|
760
|
+
this.messageService.send(messageV10);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
async changeTheme(themeName) {
|
|
765
|
+
const cssHref = themeName && `${themeName}-theme.css`;
|
|
766
|
+
const styleObj = cssHref ? await getStyle(cssHref) : "";
|
|
767
|
+
this.currentThemeSelection.update((theme) => {
|
|
768
|
+
this.previousTheme = theme;
|
|
769
|
+
return themeName ? {
|
|
770
|
+
name: themeName,
|
|
771
|
+
css: styleObj
|
|
772
|
+
} : void 0;
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
revertToPreviousTheme() {
|
|
776
|
+
this.currentThemeSelection.set(this.previousTheme);
|
|
777
|
+
}
|
|
778
|
+
handleError(message) {
|
|
779
|
+
this.logger.error("Error in theme service message", message);
|
|
780
|
+
this.revertToPreviousTheme();
|
|
781
|
+
}
|
|
782
|
+
static {
|
|
783
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
784
|
+
minVersion: "12.0.0",
|
|
785
|
+
version: "22.2.3",
|
|
786
|
+
ngImport: i0,
|
|
787
|
+
type: ThemeProducerService,
|
|
788
|
+
deps: [],
|
|
789
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
static {
|
|
793
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
794
|
+
minVersion: "12.0.0",
|
|
795
|
+
version: "22.2.3",
|
|
796
|
+
ngImport: i0,
|
|
797
|
+
type: ThemeProducerService,
|
|
798
|
+
providedIn: "root"
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
803
|
+
minVersion: "12.0.0",
|
|
804
|
+
version: "22.2.3",
|
|
805
|
+
ngImport: i0,
|
|
806
|
+
type: ThemeProducerService,
|
|
807
|
+
decorators: [{
|
|
808
|
+
type: Injectable,
|
|
809
|
+
args: [{ providedIn: "root" }]
|
|
810
|
+
}],
|
|
811
|
+
ctorParameters: () => []
|
|
812
|
+
});
|
|
813
|
+
var ApplyTheme = class ApplyTheme {
|
|
814
|
+
constructor() {
|
|
815
|
+
this.themeManagerService = inject(ThemeProducerService);
|
|
816
|
+
this.domSanitizer = inject(DomSanitizer);
|
|
817
|
+
}
|
|
818
|
+
transform(url) {
|
|
819
|
+
if (!url) return;
|
|
820
|
+
const currentTheme = this.themeManagerService.currentTheme();
|
|
821
|
+
const urlString = typeof url === "string" ? url : this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url);
|
|
822
|
+
if (urlString) {
|
|
823
|
+
const moduleUrl = new URL(urlString);
|
|
824
|
+
if (currentTheme) moduleUrl.searchParams.set("theme", currentTheme.name);
|
|
825
|
+
const moduleUrlStringyfied = moduleUrl.toString();
|
|
826
|
+
return typeof url === "string" ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
static {
|
|
830
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
831
|
+
minVersion: "12.0.0",
|
|
832
|
+
version: "22.2.3",
|
|
833
|
+
ngImport: i0,
|
|
834
|
+
type: ApplyTheme,
|
|
835
|
+
deps: [],
|
|
836
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
static {
|
|
840
|
+
this.ɵpipe = i0.ɵɵngDeclarePipe({
|
|
841
|
+
minVersion: "14.0.0",
|
|
842
|
+
version: "22.2.3",
|
|
843
|
+
ngImport: i0,
|
|
844
|
+
type: ApplyTheme,
|
|
845
|
+
isStandalone: true,
|
|
846
|
+
name: "applyTheme"
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
851
|
+
minVersion: "12.0.0",
|
|
852
|
+
version: "22.2.3",
|
|
853
|
+
ngImport: i0,
|
|
854
|
+
type: ApplyTheme,
|
|
855
|
+
decorators: [{
|
|
856
|
+
type: Pipe,
|
|
857
|
+
args: [{ name: "applyTheme" }]
|
|
858
|
+
}]
|
|
859
|
+
});
|
|
860
|
+
var AllowDirective = class AllowDirective {
|
|
861
|
+
constructor() {
|
|
862
|
+
this.elementRef = inject(ElementRef);
|
|
863
|
+
this.renderer = inject(Renderer2);
|
|
864
|
+
this.mfeAllow = input("", ...ngDevMode ? [{ debugName: "mfeAllow" }] : /* istanbul ignore next */ []);
|
|
865
|
+
}
|
|
866
|
+
ngOnInit() {
|
|
867
|
+
const allow = this.mfeAllow();
|
|
868
|
+
if (allow) this.renderer.setAttribute(this.elementRef.nativeElement, "allow", allow);
|
|
869
|
+
}
|
|
870
|
+
static {
|
|
871
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
872
|
+
minVersion: "12.0.0",
|
|
873
|
+
version: "22.2.3",
|
|
874
|
+
ngImport: i0,
|
|
875
|
+
type: AllowDirective,
|
|
876
|
+
deps: [],
|
|
877
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
static {
|
|
881
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
882
|
+
minVersion: "17.1.0",
|
|
883
|
+
version: "22.2.3",
|
|
884
|
+
type: AllowDirective,
|
|
885
|
+
isStandalone: true,
|
|
886
|
+
selector: "iframe[mfeAllow]",
|
|
887
|
+
inputs: { mfeAllow: {
|
|
888
|
+
classPropertyName: "mfeAllow",
|
|
889
|
+
publicName: "mfeAllow",
|
|
890
|
+
isSignal: true,
|
|
891
|
+
isRequired: false,
|
|
892
|
+
transformFunction: null
|
|
893
|
+
} },
|
|
894
|
+
ngImport: i0
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
899
|
+
minVersion: "12.0.0",
|
|
900
|
+
version: "22.2.3",
|
|
901
|
+
ngImport: i0,
|
|
902
|
+
type: AllowDirective,
|
|
903
|
+
decorators: [{
|
|
904
|
+
type: Directive,
|
|
905
|
+
args: [{ selector: "iframe[mfeAllow]" }]
|
|
906
|
+
}],
|
|
907
|
+
propDecorators: { mfeAllow: [{
|
|
908
|
+
type: i0.Input,
|
|
909
|
+
args: [{
|
|
910
|
+
isSignal: true,
|
|
911
|
+
alias: "mfeAllow",
|
|
912
|
+
required: false
|
|
913
|
+
}]
|
|
914
|
+
}] }
|
|
915
|
+
});
|
|
916
|
+
var SandboxDirective = class SandboxDirective {
|
|
917
|
+
constructor() {
|
|
918
|
+
this.elementRef = inject(ElementRef);
|
|
919
|
+
this.renderer = inject(Renderer2);
|
|
920
|
+
this.mfeSandbox = input("", ...ngDevMode ? [{ debugName: "mfeSandbox" }] : /* istanbul ignore next */ []);
|
|
921
|
+
}
|
|
922
|
+
ngOnInit() {
|
|
923
|
+
this.renderer.setAttribute(this.elementRef.nativeElement, "sandbox", this.mfeSandbox());
|
|
924
|
+
}
|
|
925
|
+
static {
|
|
926
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
927
|
+
minVersion: "12.0.0",
|
|
928
|
+
version: "22.2.3",
|
|
929
|
+
ngImport: i0,
|
|
930
|
+
type: SandboxDirective,
|
|
931
|
+
deps: [],
|
|
932
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
static {
|
|
936
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
937
|
+
minVersion: "17.1.0",
|
|
938
|
+
version: "22.2.3",
|
|
939
|
+
type: SandboxDirective,
|
|
940
|
+
isStandalone: true,
|
|
941
|
+
selector: "iframe[mfeSandbox]",
|
|
942
|
+
inputs: { mfeSandbox: {
|
|
943
|
+
classPropertyName: "mfeSandbox",
|
|
944
|
+
publicName: "mfeSandbox",
|
|
945
|
+
isSignal: true,
|
|
946
|
+
isRequired: false,
|
|
947
|
+
transformFunction: null
|
|
948
|
+
} },
|
|
949
|
+
ngImport: i0
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
954
|
+
minVersion: "12.0.0",
|
|
955
|
+
version: "22.2.3",
|
|
956
|
+
ngImport: i0,
|
|
957
|
+
type: SandboxDirective,
|
|
958
|
+
decorators: [{
|
|
959
|
+
type: Directive,
|
|
960
|
+
args: [{ selector: "iframe[mfeSandbox]" }]
|
|
961
|
+
}],
|
|
962
|
+
propDecorators: { mfeSandbox: [{
|
|
963
|
+
type: i0.Input,
|
|
964
|
+
args: [{
|
|
965
|
+
isSignal: true,
|
|
966
|
+
alias: "mfeSandbox",
|
|
967
|
+
required: false
|
|
968
|
+
}]
|
|
969
|
+
}] }
|
|
970
|
+
});
|
|
971
|
+
var IframeEmbedComponent = class IframeEmbedComponent {
|
|
972
|
+
constructor() {
|
|
973
|
+
this.domSanitizer = inject(DomSanitizer);
|
|
974
|
+
this.src = input.required(...ngDevMode ? [{ debugName: "src" }] : /* istanbul ignore next */ []);
|
|
975
|
+
this.safeSrc = computed(() => {
|
|
976
|
+
const value = this.src();
|
|
977
|
+
return typeof value === "string" ? this.domSanitizer.bypassSecurityTrustResourceUrl(value) : value;
|
|
978
|
+
}, ...ngDevMode ? [{ debugName: "safeSrc" }] : /* istanbul ignore next */ []);
|
|
979
|
+
this.moduleId = input.required(...ngDevMode ? [{ debugName: "moduleId" }] : /* istanbul ignore next */ []);
|
|
980
|
+
this.hostApplicationId = input.required(...ngDevMode ? [{ debugName: "hostApplicationId" }] : /* istanbul ignore next */ []);
|
|
981
|
+
this.sandbox = input("allow-scripts allow-same-origin", ...ngDevMode ? [{ debugName: "sandbox" }] : /* istanbul ignore next */ []);
|
|
982
|
+
this.allow = input("", ...ngDevMode ? [{ debugName: "allow" }] : /* istanbul ignore next */ []);
|
|
983
|
+
}
|
|
984
|
+
static {
|
|
985
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
986
|
+
minVersion: "12.0.0",
|
|
987
|
+
version: "22.2.3",
|
|
988
|
+
ngImport: i0,
|
|
989
|
+
type: IframeEmbedComponent,
|
|
990
|
+
deps: [],
|
|
991
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
static {
|
|
995
|
+
this.ɵcmp = i0.ɵɵngDeclareComponent({
|
|
996
|
+
minVersion: "17.1.0",
|
|
997
|
+
version: "22.2.3",
|
|
998
|
+
type: IframeEmbedComponent,
|
|
999
|
+
isStandalone: true,
|
|
1000
|
+
selector: "mfe-iframe-embed",
|
|
1001
|
+
inputs: {
|
|
1002
|
+
src: {
|
|
1003
|
+
classPropertyName: "src",
|
|
1004
|
+
publicName: "src",
|
|
1005
|
+
isSignal: true,
|
|
1006
|
+
isRequired: true,
|
|
1007
|
+
transformFunction: null
|
|
1008
|
+
},
|
|
1009
|
+
moduleId: {
|
|
1010
|
+
classPropertyName: "moduleId",
|
|
1011
|
+
publicName: "moduleId",
|
|
1012
|
+
isSignal: true,
|
|
1013
|
+
isRequired: true,
|
|
1014
|
+
transformFunction: null
|
|
1015
|
+
},
|
|
1016
|
+
hostApplicationId: {
|
|
1017
|
+
classPropertyName: "hostApplicationId",
|
|
1018
|
+
publicName: "hostApplicationId",
|
|
1019
|
+
isSignal: true,
|
|
1020
|
+
isRequired: true,
|
|
1021
|
+
transformFunction: null
|
|
1022
|
+
},
|
|
1023
|
+
sandbox: {
|
|
1024
|
+
classPropertyName: "sandbox",
|
|
1025
|
+
publicName: "sandbox",
|
|
1026
|
+
isSignal: true,
|
|
1027
|
+
isRequired: false,
|
|
1028
|
+
transformFunction: null
|
|
1029
|
+
},
|
|
1030
|
+
allow: {
|
|
1031
|
+
classPropertyName: "allow",
|
|
1032
|
+
publicName: "allow",
|
|
1033
|
+
isSignal: true,
|
|
1034
|
+
isRequired: false,
|
|
1035
|
+
transformFunction: null
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
ngImport: i0,
|
|
1039
|
+
template: "@let hostInfoOptions = {hostId: hostApplicationId(), moduleId: moduleId()};\n<iframe\n [connect]=\"hostInfoOptions.moduleId\"\n scalable\n [src]=\"safeSrc() | hostInfo: hostInfoOptions | applyTheme\"\n [mfeSandbox]=\"sandbox()\"\n [mfeAllow]=\"allow()\">\n</iframe>\n",
|
|
1040
|
+
styles: ["mfe-iframe-embed iframe{height:100%;width:100%;display:block}\n"],
|
|
1041
|
+
dependencies: [
|
|
1042
|
+
{
|
|
1043
|
+
kind: "directive",
|
|
1044
|
+
type: ConnectDirective,
|
|
1045
|
+
selector: "iframe[connect]",
|
|
1046
|
+
inputs: ["connect", "src"]
|
|
1047
|
+
},
|
|
1048
|
+
{
|
|
1049
|
+
kind: "directive",
|
|
1050
|
+
type: ScalableDirective,
|
|
1051
|
+
selector: "[scalable]",
|
|
1052
|
+
inputs: ["connect", "scalable"]
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
kind: "directive",
|
|
1056
|
+
type: SandboxDirective,
|
|
1057
|
+
selector: "iframe[mfeSandbox]",
|
|
1058
|
+
inputs: ["mfeSandbox"]
|
|
1059
|
+
},
|
|
1060
|
+
{
|
|
1061
|
+
kind: "directive",
|
|
1062
|
+
type: AllowDirective,
|
|
1063
|
+
selector: "iframe[mfeAllow]",
|
|
1064
|
+
inputs: ["mfeAllow"]
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
kind: "pipe",
|
|
1068
|
+
type: ApplyTheme,
|
|
1069
|
+
name: "applyTheme"
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
kind: "pipe",
|
|
1073
|
+
type: HostInfoPipe,
|
|
1074
|
+
name: "hostInfo"
|
|
1075
|
+
}
|
|
1076
|
+
],
|
|
1077
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush,
|
|
1078
|
+
encapsulation: i0.ViewEncapsulation.None
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1083
|
+
minVersion: "12.0.0",
|
|
1084
|
+
version: "22.2.3",
|
|
1085
|
+
ngImport: i0,
|
|
1086
|
+
type: IframeEmbedComponent,
|
|
1087
|
+
decorators: [{
|
|
1088
|
+
type: Component,
|
|
1089
|
+
args: [{
|
|
1090
|
+
selector: "mfe-iframe-embed",
|
|
1091
|
+
imports: [
|
|
1092
|
+
ConnectDirective,
|
|
1093
|
+
ScalableDirective,
|
|
1094
|
+
ApplyTheme,
|
|
1095
|
+
HostInfoPipe,
|
|
1096
|
+
SandboxDirective,
|
|
1097
|
+
AllowDirective
|
|
1098
|
+
],
|
|
1099
|
+
encapsulation: ViewEncapsulation.None,
|
|
1100
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
1101
|
+
template: "@let hostInfoOptions = {hostId: hostApplicationId(), moduleId: moduleId()};\n<iframe\n [connect]=\"hostInfoOptions.moduleId\"\n scalable\n [src]=\"safeSrc() | hostInfo: hostInfoOptions | applyTheme\"\n [mfeSandbox]=\"sandbox()\"\n [mfeAllow]=\"allow()\">\n</iframe>\n",
|
|
1102
|
+
styles: ["mfe-iframe-embed iframe{height:100%;width:100%;display:block}\n"]
|
|
1103
|
+
}]
|
|
1104
|
+
}],
|
|
1105
|
+
propDecorators: {
|
|
1106
|
+
src: [{
|
|
1107
|
+
type: i0.Input,
|
|
1108
|
+
args: [{
|
|
1109
|
+
isSignal: true,
|
|
1110
|
+
alias: "src",
|
|
1111
|
+
required: true
|
|
1112
|
+
}]
|
|
1113
|
+
}],
|
|
1114
|
+
moduleId: [{
|
|
1115
|
+
type: i0.Input,
|
|
1116
|
+
args: [{
|
|
1117
|
+
isSignal: true,
|
|
1118
|
+
alias: "moduleId",
|
|
1119
|
+
required: true
|
|
1120
|
+
}]
|
|
1121
|
+
}],
|
|
1122
|
+
hostApplicationId: [{
|
|
1123
|
+
type: i0.Input,
|
|
1124
|
+
args: [{
|
|
1125
|
+
isSignal: true,
|
|
1126
|
+
alias: "hostApplicationId",
|
|
1127
|
+
required: true
|
|
1128
|
+
}]
|
|
1129
|
+
}],
|
|
1130
|
+
sandbox: [{
|
|
1131
|
+
type: i0.Input,
|
|
1132
|
+
args: [{
|
|
1133
|
+
isSignal: true,
|
|
1134
|
+
alias: "sandbox",
|
|
1135
|
+
required: false
|
|
1136
|
+
}]
|
|
1137
|
+
}],
|
|
1138
|
+
allow: [{
|
|
1139
|
+
type: i0.Input,
|
|
1140
|
+
args: [{
|
|
1141
|
+
isSignal: true,
|
|
1142
|
+
alias: "allow",
|
|
1143
|
+
required: false
|
|
1144
|
+
}]
|
|
1145
|
+
}]
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
var NavigationConsumerService = class NavigationConsumerService extends AbstractMessageConsumer {
|
|
1149
|
+
constructor() {
|
|
1150
|
+
super(...arguments);
|
|
1151
|
+
this.router = inject(Router);
|
|
1152
|
+
this.activeRoute = inject(ActivatedRoute);
|
|
1153
|
+
this.requestedUrl = new Subject();
|
|
1154
|
+
this.requestedUrl$ = this.requestedUrl.asObservable();
|
|
1155
|
+
this.type = NAVIGATION_MESSAGE_TYPE;
|
|
1156
|
+
this.supportedVersions = {
|
|
1157
|
+
"1.0": (message) => {
|
|
1158
|
+
const channelId = message.from || void 0;
|
|
1159
|
+
this.requestedUrl.next({
|
|
1160
|
+
url: message.payload.url,
|
|
1161
|
+
channelId
|
|
1162
|
+
});
|
|
1163
|
+
this.navigate(message.payload.url);
|
|
1164
|
+
},
|
|
1165
|
+
"1.1": (message) => {
|
|
1166
|
+
const channelId = message.from || void 0;
|
|
1167
|
+
this.requestedUrl.next({
|
|
1168
|
+
url: message.payload.url,
|
|
1169
|
+
channelId
|
|
1170
|
+
});
|
|
1171
|
+
this.navigate(message.payload.url, message.payload.extras);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
parseUrl(url) {
|
|
1176
|
+
const urlObject = new URL(window.origin + url);
|
|
1177
|
+
return {
|
|
1178
|
+
paths: urlObject.pathname.split("/").filter((segment) => !!segment),
|
|
1179
|
+
queryParams: Object.fromEntries(urlObject.searchParams.entries())
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
navigate(url, extras) {
|
|
1183
|
+
const { paths, queryParams } = this.parseUrl(url);
|
|
1184
|
+
hostQueryParams.forEach((key) => delete queryParams[key]);
|
|
1185
|
+
this.router.navigate(paths, {
|
|
1186
|
+
relativeTo: this.activeRoute.children.at(-1),
|
|
1187
|
+
queryParams,
|
|
1188
|
+
replaceUrl: extras?.replaceUrl
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
static {
|
|
1192
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1193
|
+
minVersion: "12.0.0",
|
|
1194
|
+
version: "22.2.3",
|
|
1195
|
+
ngImport: i0,
|
|
1196
|
+
type: NavigationConsumerService,
|
|
1197
|
+
deps: null,
|
|
1198
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
static {
|
|
1202
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1203
|
+
minVersion: "12.0.0",
|
|
1204
|
+
version: "22.2.3",
|
|
1205
|
+
ngImport: i0,
|
|
1206
|
+
type: NavigationConsumerService,
|
|
1207
|
+
providedIn: "root"
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1212
|
+
minVersion: "12.0.0",
|
|
1213
|
+
version: "22.2.3",
|
|
1214
|
+
ngImport: i0,
|
|
1215
|
+
type: NavigationConsumerService,
|
|
1216
|
+
decorators: [{
|
|
1217
|
+
type: Injectable,
|
|
1218
|
+
args: [{ providedIn: "root" }]
|
|
1219
|
+
}]
|
|
1220
|
+
});
|
|
1221
|
+
var RouteMemorizeService = class RouteMemorizeService {
|
|
1222
|
+
constructor() {
|
|
1223
|
+
this.routeTimers = {};
|
|
1224
|
+
this.routeStack = {};
|
|
1225
|
+
}
|
|
1226
|
+
memorizeRoute(channelId, url, liveTime) {
|
|
1227
|
+
this.routeStack[channelId] = url;
|
|
1228
|
+
const timerRef = this.routeTimers[channelId];
|
|
1229
|
+
if (timerRef) clearTimeout(timerRef);
|
|
1230
|
+
if (liveTime && liveTime > 0) this.routeTimers[channelId] = setTimeout(() => {
|
|
1231
|
+
delete this.routeStack[channelId];
|
|
1232
|
+
delete this.routeTimers[channelId];
|
|
1233
|
+
}, liveTime);
|
|
1234
|
+
}
|
|
1235
|
+
getRoute(channelId) {
|
|
1236
|
+
return this.routeStack[channelId];
|
|
1237
|
+
}
|
|
1238
|
+
static {
|
|
1239
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1240
|
+
minVersion: "12.0.0",
|
|
1241
|
+
version: "22.2.3",
|
|
1242
|
+
ngImport: i0,
|
|
1243
|
+
type: RouteMemorizeService,
|
|
1244
|
+
deps: [],
|
|
1245
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
static {
|
|
1249
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1250
|
+
minVersion: "12.0.0",
|
|
1251
|
+
version: "22.2.3",
|
|
1252
|
+
ngImport: i0,
|
|
1253
|
+
type: RouteMemorizeService,
|
|
1254
|
+
providedIn: "root"
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1259
|
+
minVersion: "12.0.0",
|
|
1260
|
+
version: "22.2.3",
|
|
1261
|
+
ngImport: i0,
|
|
1262
|
+
type: RouteMemorizeService,
|
|
1263
|
+
decorators: [{
|
|
1264
|
+
type: Injectable,
|
|
1265
|
+
args: [{ providedIn: "root" }]
|
|
1266
|
+
}]
|
|
1267
|
+
});
|
|
1268
|
+
var RestoreRoute = class RestoreRoute {
|
|
1269
|
+
constructor() {
|
|
1270
|
+
this.activeRoute = inject(ActivatedRoute);
|
|
1271
|
+
this.domSanitizer = inject(DomSanitizer);
|
|
1272
|
+
this.routeMemorizeService = inject(RouteMemorizeService, { optional: true });
|
|
1273
|
+
this.window = inject(Window, { optional: true }) || window;
|
|
1274
|
+
}
|
|
1275
|
+
transform(url, options) {
|
|
1276
|
+
const urlString = typeof url === "string" ? url : this.domSanitizer.sanitize(SecurityContext.RESOURCE_URL, url || null);
|
|
1277
|
+
if (!url) return;
|
|
1278
|
+
if (urlString) {
|
|
1279
|
+
const moduleUrl = new URL(urlString);
|
|
1280
|
+
const queryParamsModule = new URLSearchParams(moduleUrl.searchParams);
|
|
1281
|
+
const channelId = options?.memoryChannelId;
|
|
1282
|
+
const memorizedRoute = channelId && this.routeMemorizeService?.getRoute(channelId);
|
|
1283
|
+
const topWindowUrl = new URL(memorizedRoute ? this.window.origin + memorizedRoute : this.window.location.href);
|
|
1284
|
+
const queryParamsTopWindow = new URLSearchParams(topWindowUrl.search);
|
|
1285
|
+
if (options?.propagateQueryParams) {
|
|
1286
|
+
for (const [key, value] of queryParamsTopWindow) if (options?.overrideQueryParams || !queryParamsModule.has(key)) queryParamsModule.set(key, value);
|
|
1287
|
+
}
|
|
1288
|
+
moduleUrl.search = queryParamsModule.toString();
|
|
1289
|
+
moduleUrl.pathname += topWindowUrl.pathname.split(`/${this.activeRoute.routeConfig?.path}`).pop() || "";
|
|
1290
|
+
moduleUrl.pathname = moduleUrl.pathname.replace(/\/{2,}/g, "/");
|
|
1291
|
+
const moduleUrlStringyfied = moduleUrl.toString();
|
|
1292
|
+
return typeof url === "string" ? moduleUrlStringyfied : this.domSanitizer.bypassSecurityTrustResourceUrl(moduleUrlStringyfied);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
static {
|
|
1296
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1297
|
+
minVersion: "12.0.0",
|
|
1298
|
+
version: "22.2.3",
|
|
1299
|
+
ngImport: i0,
|
|
1300
|
+
type: RestoreRoute,
|
|
1301
|
+
deps: [],
|
|
1302
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
static {
|
|
1306
|
+
this.ɵpipe = i0.ɵɵngDeclarePipe({
|
|
1307
|
+
minVersion: "14.0.0",
|
|
1308
|
+
version: "22.2.3",
|
|
1309
|
+
ngImport: i0,
|
|
1310
|
+
type: RestoreRoute,
|
|
1311
|
+
isStandalone: true,
|
|
1312
|
+
name: "restoreRoute"
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1317
|
+
minVersion: "12.0.0",
|
|
1318
|
+
version: "22.2.3",
|
|
1319
|
+
ngImport: i0,
|
|
1320
|
+
type: RestoreRoute,
|
|
1321
|
+
decorators: [{
|
|
1322
|
+
type: Pipe,
|
|
1323
|
+
args: [{ name: "restoreRoute" }]
|
|
1324
|
+
}]
|
|
1325
|
+
});
|
|
1326
|
+
var RouteMemorizeDirective = class RouteMemorizeDirective {
|
|
1327
|
+
constructor() {
|
|
1328
|
+
this.memorizeRoute = input(true, ...ngDevMode ? [{ debugName: "memorizeRoute" }] : /* istanbul ignore next */ []);
|
|
1329
|
+
this.memorizeRouteId = input(...ngDevMode ? [void 0, { debugName: "memorizeRouteId" }] : /* istanbul ignore next */ []);
|
|
1330
|
+
this.memorizeMaxAge = input(0, ...ngDevMode ? [{ debugName: "memorizeMaxAge" }] : /* istanbul ignore next */ []);
|
|
1331
|
+
this.memorizeRouteMaxAge = input(0, ...ngDevMode ? [{ debugName: "memorizeRouteMaxAge" }] : /* istanbul ignore next */ []);
|
|
1332
|
+
this.connect = input(...ngDevMode ? [void 0, { debugName: "connect" }] : /* istanbul ignore next */ []);
|
|
1333
|
+
this.maxAge = computed(() => {
|
|
1334
|
+
return this.memorizeMaxAge() || this.memorizeRouteMaxAge();
|
|
1335
|
+
}, ...ngDevMode ? [{ debugName: "maxAge" }] : /* istanbul ignore next */ []);
|
|
1336
|
+
const memory = inject(RouteMemorizeService);
|
|
1337
|
+
const requestedUrlSignal = toSignal(inject(NavigationConsumerService).requestedUrl$);
|
|
1338
|
+
effect(() => {
|
|
1339
|
+
if (this.memorizeRoute() === false) return;
|
|
1340
|
+
const requested = requestedUrlSignal();
|
|
1341
|
+
const channelId = this.connect();
|
|
1342
|
+
const id = this.memorizeRouteId() || channelId;
|
|
1343
|
+
if (requested && id && requested.channelId === channelId) memory.memorizeRoute(id, requested.url, untracked(this.maxAge));
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
static {
|
|
1347
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1348
|
+
minVersion: "12.0.0",
|
|
1349
|
+
version: "22.2.3",
|
|
1350
|
+
ngImport: i0,
|
|
1351
|
+
type: RouteMemorizeDirective,
|
|
1352
|
+
deps: [],
|
|
1353
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
static {
|
|
1357
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
1358
|
+
minVersion: "17.1.0",
|
|
1359
|
+
version: "22.2.3",
|
|
1360
|
+
type: RouteMemorizeDirective,
|
|
1361
|
+
isStandalone: true,
|
|
1362
|
+
selector: "iframe[memorizeRoute]",
|
|
1363
|
+
inputs: {
|
|
1364
|
+
memorizeRoute: {
|
|
1365
|
+
classPropertyName: "memorizeRoute",
|
|
1366
|
+
publicName: "memorizeRoute",
|
|
1367
|
+
isSignal: true,
|
|
1368
|
+
isRequired: false,
|
|
1369
|
+
transformFunction: null
|
|
1370
|
+
},
|
|
1371
|
+
memorizeRouteId: {
|
|
1372
|
+
classPropertyName: "memorizeRouteId",
|
|
1373
|
+
publicName: "memorizeRouteId",
|
|
1374
|
+
isSignal: true,
|
|
1375
|
+
isRequired: false,
|
|
1376
|
+
transformFunction: null
|
|
1377
|
+
},
|
|
1378
|
+
memorizeMaxAge: {
|
|
1379
|
+
classPropertyName: "memorizeMaxAge",
|
|
1380
|
+
publicName: "memorizeMaxAge",
|
|
1381
|
+
isSignal: true,
|
|
1382
|
+
isRequired: false,
|
|
1383
|
+
transformFunction: null
|
|
1384
|
+
},
|
|
1385
|
+
memorizeRouteMaxAge: {
|
|
1386
|
+
classPropertyName: "memorizeRouteMaxAge",
|
|
1387
|
+
publicName: "memorizeRouteMaxAge",
|
|
1388
|
+
isSignal: true,
|
|
1389
|
+
isRequired: false,
|
|
1390
|
+
transformFunction: null
|
|
1391
|
+
},
|
|
1392
|
+
connect: {
|
|
1393
|
+
classPropertyName: "connect",
|
|
1394
|
+
publicName: "connect",
|
|
1395
|
+
isSignal: true,
|
|
1396
|
+
isRequired: false,
|
|
1397
|
+
transformFunction: null
|
|
1398
|
+
}
|
|
1399
|
+
},
|
|
1400
|
+
ngImport: i0
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1405
|
+
minVersion: "12.0.0",
|
|
1406
|
+
version: "22.2.3",
|
|
1407
|
+
ngImport: i0,
|
|
1408
|
+
type: RouteMemorizeDirective,
|
|
1409
|
+
decorators: [{
|
|
1410
|
+
type: Directive,
|
|
1411
|
+
args: [{
|
|
1412
|
+
selector: "iframe[memorizeRoute]",
|
|
1413
|
+
standalone: true
|
|
1414
|
+
}]
|
|
1415
|
+
}],
|
|
1416
|
+
ctorParameters: () => [],
|
|
1417
|
+
propDecorators: {
|
|
1418
|
+
memorizeRoute: [{
|
|
1419
|
+
type: i0.Input,
|
|
1420
|
+
args: [{
|
|
1421
|
+
isSignal: true,
|
|
1422
|
+
alias: "memorizeRoute",
|
|
1423
|
+
required: false
|
|
1424
|
+
}]
|
|
1425
|
+
}],
|
|
1426
|
+
memorizeRouteId: [{
|
|
1427
|
+
type: i0.Input,
|
|
1428
|
+
args: [{
|
|
1429
|
+
isSignal: true,
|
|
1430
|
+
alias: "memorizeRouteId",
|
|
1431
|
+
required: false
|
|
1432
|
+
}]
|
|
1433
|
+
}],
|
|
1434
|
+
memorizeMaxAge: [{
|
|
1435
|
+
type: i0.Input,
|
|
1436
|
+
args: [{
|
|
1437
|
+
isSignal: true,
|
|
1438
|
+
alias: "memorizeMaxAge",
|
|
1439
|
+
required: false
|
|
1440
|
+
}]
|
|
1441
|
+
}],
|
|
1442
|
+
memorizeRouteMaxAge: [{
|
|
1443
|
+
type: i0.Input,
|
|
1444
|
+
args: [{
|
|
1445
|
+
isSignal: true,
|
|
1446
|
+
alias: "memorizeRouteMaxAge",
|
|
1447
|
+
required: false
|
|
1448
|
+
}]
|
|
1449
|
+
}],
|
|
1450
|
+
connect: [{
|
|
1451
|
+
type: i0.Input,
|
|
1452
|
+
args: [{
|
|
1453
|
+
isSignal: true,
|
|
1454
|
+
alias: "connect",
|
|
1455
|
+
required: false
|
|
1456
|
+
}]
|
|
1457
|
+
}]
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
var RoutingService = class RoutingService {
|
|
1461
|
+
constructor() {
|
|
1462
|
+
this.router = inject(Router);
|
|
1463
|
+
this.activatedRoute = inject(ActivatedRoute);
|
|
1464
|
+
this.messageService = inject(MessagePeerService);
|
|
1465
|
+
this.logger = inject(LoggerService);
|
|
1466
|
+
this.window = inject(Window, { optional: true }) || window;
|
|
1467
|
+
this.types = NAVIGATION_MESSAGE_TYPE;
|
|
1468
|
+
this.type = "navigation";
|
|
1469
|
+
this.supportedVersions = {
|
|
1470
|
+
"1.0": async (message) => {
|
|
1471
|
+
await this.router.navigateByUrl(message.payload.url, { state: { triggeredByMessage: true } });
|
|
1472
|
+
},
|
|
1473
|
+
"1.1": async (message) => {
|
|
1474
|
+
await this.router.navigateByUrl(message.payload.url, {
|
|
1475
|
+
state: { triggeredByMessage: true },
|
|
1476
|
+
replaceUrl: message.payload.extras?.replaceUrl
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
};
|
|
1480
|
+
registerProducer(this);
|
|
1481
|
+
registerConsumer(this);
|
|
1482
|
+
}
|
|
1483
|
+
start() {}
|
|
1484
|
+
stop() {}
|
|
1485
|
+
handleError(message) {
|
|
1486
|
+
this.logger.error("Error in navigation service message", message);
|
|
1487
|
+
}
|
|
1488
|
+
handleEmbeddedRouting(options) {
|
|
1489
|
+
const subRouteOnly = options?.subRouteOnly ?? false;
|
|
1490
|
+
this.router.events.pipe(takeUntilDestroyed(), filter((event) => event instanceof NavigationEnd), filter((_event) => {
|
|
1491
|
+
const extras = this.router.getCurrentNavigation()?.extras || {};
|
|
1492
|
+
return !extras.skipLocationChange && !extras.state?.triggeredByMessage;
|
|
1493
|
+
}), map(({ urlAfterRedirects }) => {
|
|
1494
|
+
const extras = this.router.getCurrentNavigation()?.extras || {};
|
|
1495
|
+
const { channelId } = extras.state || {};
|
|
1496
|
+
const currentRouteRegExp = subRouteOnly && this.activatedRoute.routeConfig?.path && new RegExp("^" + this.activatedRoute.routeConfig.path.replace(/(?=\W)/g, "\\"), "i");
|
|
1497
|
+
return {
|
|
1498
|
+
url: currentRouteRegExp ? urlAfterRedirects.replace(currentRouteRegExp, "") : urlAfterRedirects,
|
|
1499
|
+
channelId,
|
|
1500
|
+
replaceUrl: extras.replaceUrl
|
|
1501
|
+
};
|
|
1502
|
+
})).subscribe(({ url, channelId, replaceUrl }) => {
|
|
1503
|
+
const message = {
|
|
1504
|
+
type: "navigation",
|
|
1505
|
+
version: "1.1",
|
|
1506
|
+
url,
|
|
1507
|
+
...replaceUrl ? { extras: { replaceUrl: true } } : {}
|
|
1508
|
+
};
|
|
1509
|
+
if (isEmbedded(this.window)) this.messageService.send(message);
|
|
1510
|
+
else if (channelId === void 0) this.logger.warn("No channelId provided for navigation message");
|
|
1511
|
+
else try {
|
|
1512
|
+
this.messageService.send(message, { to: [channelId] });
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
this.logger.error("Error sending navigation message", error);
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
static {
|
|
1519
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1520
|
+
minVersion: "12.0.0",
|
|
1521
|
+
version: "22.2.3",
|
|
1522
|
+
ngImport: i0,
|
|
1523
|
+
type: RoutingService,
|
|
1524
|
+
deps: [],
|
|
1525
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
static {
|
|
1529
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1530
|
+
minVersion: "12.0.0",
|
|
1531
|
+
version: "22.2.3",
|
|
1532
|
+
ngImport: i0,
|
|
1533
|
+
type: RoutingService,
|
|
1534
|
+
providedIn: "root"
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1539
|
+
minVersion: "12.0.0",
|
|
1540
|
+
version: "22.2.3",
|
|
1541
|
+
ngImport: i0,
|
|
1542
|
+
type: RoutingService,
|
|
1543
|
+
decorators: [{
|
|
1544
|
+
type: Injectable,
|
|
1545
|
+
args: [{ providedIn: "root" }]
|
|
1546
|
+
}],
|
|
1547
|
+
ctorParameters: () => []
|
|
1548
|
+
});
|
|
1549
|
+
var NavigationBlockService = class NavigationBlockService {
|
|
1550
|
+
constructor() {
|
|
1551
|
+
this.stateSignal = signal({ blocked: false }, ...ngDevMode ? [{ debugName: "stateSignal" }] : /* istanbul ignore next */ []);
|
|
1552
|
+
this.state = this.stateSignal.asReadonly();
|
|
1553
|
+
}
|
|
1554
|
+
block(reason) {
|
|
1555
|
+
this.stateSignal.set({
|
|
1556
|
+
blocked: true,
|
|
1557
|
+
reason
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
unblock() {
|
|
1561
|
+
this.stateSignal.set({ blocked: false });
|
|
1562
|
+
}
|
|
1563
|
+
static {
|
|
1564
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1565
|
+
minVersion: "12.0.0",
|
|
1566
|
+
version: "22.2.3",
|
|
1567
|
+
ngImport: i0,
|
|
1568
|
+
type: NavigationBlockService,
|
|
1569
|
+
deps: [],
|
|
1570
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
static {
|
|
1574
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1575
|
+
minVersion: "12.0.0",
|
|
1576
|
+
version: "22.2.3",
|
|
1577
|
+
ngImport: i0,
|
|
1578
|
+
type: NavigationBlockService,
|
|
1579
|
+
providedIn: "root"
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1584
|
+
minVersion: "12.0.0",
|
|
1585
|
+
version: "22.2.3",
|
|
1586
|
+
ngImport: i0,
|
|
1587
|
+
type: NavigationBlockService,
|
|
1588
|
+
decorators: [{
|
|
1589
|
+
type: Injectable,
|
|
1590
|
+
args: [{ providedIn: "root" }]
|
|
1591
|
+
}]
|
|
1592
|
+
});
|
|
1593
|
+
var NavigationBlockStateProducerService = class NavigationBlockStateProducerService {
|
|
1594
|
+
constructor() {
|
|
1595
|
+
this.types = NAVIGATION_BLOCK_STATE_MESSAGE_TYPE;
|
|
1596
|
+
this.connectionService = inject(ConnectionService);
|
|
1597
|
+
this.producerManagerService = inject(ProducerManagerService);
|
|
1598
|
+
this.logger = inject(LoggerService);
|
|
1599
|
+
this.store = inject(NavigationBlockService);
|
|
1600
|
+
this.producerManagerService.register(this);
|
|
1601
|
+
inject(DestroyRef).onDestroy(() => this.producerManagerService.unregister(this));
|
|
1602
|
+
effect(() => {
|
|
1603
|
+
const state = this.store.state();
|
|
1604
|
+
const message = {
|
|
1605
|
+
type: NAVIGATION_BLOCK_STATE_MESSAGE_TYPE,
|
|
1606
|
+
version: "1.0",
|
|
1607
|
+
blocked: state.blocked,
|
|
1608
|
+
reason: state.reason
|
|
1609
|
+
};
|
|
1610
|
+
this.connectionService.send(message);
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
handleError(message) {
|
|
1614
|
+
this.logger.error("navigation-block state message could not be consumed by the shell", message);
|
|
1615
|
+
}
|
|
1616
|
+
static {
|
|
1617
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1618
|
+
minVersion: "12.0.0",
|
|
1619
|
+
version: "22.2.3",
|
|
1620
|
+
ngImport: i0,
|
|
1621
|
+
type: NavigationBlockStateProducerService,
|
|
1622
|
+
deps: [],
|
|
1623
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
static {
|
|
1627
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1628
|
+
minVersion: "12.0.0",
|
|
1629
|
+
version: "22.2.3",
|
|
1630
|
+
ngImport: i0,
|
|
1631
|
+
type: NavigationBlockStateProducerService,
|
|
1632
|
+
providedIn: "root"
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1637
|
+
minVersion: "12.0.0",
|
|
1638
|
+
version: "22.2.3",
|
|
1639
|
+
ngImport: i0,
|
|
1640
|
+
type: NavigationBlockStateProducerService,
|
|
1641
|
+
decorators: [{
|
|
1642
|
+
type: Injectable,
|
|
1643
|
+
args: [{ providedIn: "root" }]
|
|
1644
|
+
}],
|
|
1645
|
+
ctorParameters: () => []
|
|
1646
|
+
});
|
|
1647
|
+
var NavigationBlockStateConsumerService = class NavigationBlockStateConsumerService extends AbstractMessageConsumer {
|
|
1648
|
+
constructor() {
|
|
1649
|
+
super(...arguments);
|
|
1650
|
+
this.type = NAVIGATION_BLOCK_STATE_MESSAGE_TYPE;
|
|
1651
|
+
this.supportedVersions = { "1.0": (message) => {
|
|
1652
|
+
this.blockStateSignal.set({
|
|
1653
|
+
blocked: message.payload.blocked,
|
|
1654
|
+
reason: message.payload.reason,
|
|
1655
|
+
channelId: message.from
|
|
1656
|
+
});
|
|
1657
|
+
} };
|
|
1658
|
+
this.blockStateSignal = signal(void 0, ...ngDevMode ? [{ debugName: "blockStateSignal" }] : /* istanbul ignore next */ []);
|
|
1659
|
+
this.blockState = this.blockStateSignal.asReadonly();
|
|
1660
|
+
}
|
|
1661
|
+
clear() {
|
|
1662
|
+
this.blockStateSignal.set({ blocked: false });
|
|
1663
|
+
}
|
|
1664
|
+
static {
|
|
1665
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1666
|
+
minVersion: "12.0.0",
|
|
1667
|
+
version: "22.2.3",
|
|
1668
|
+
ngImport: i0,
|
|
1669
|
+
type: NavigationBlockStateConsumerService,
|
|
1670
|
+
deps: null,
|
|
1671
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
static {
|
|
1675
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1676
|
+
minVersion: "12.0.0",
|
|
1677
|
+
version: "22.2.3",
|
|
1678
|
+
ngImport: i0,
|
|
1679
|
+
type: NavigationBlockStateConsumerService,
|
|
1680
|
+
providedIn: "root"
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1685
|
+
minVersion: "12.0.0",
|
|
1686
|
+
version: "22.2.3",
|
|
1687
|
+
ngImport: i0,
|
|
1688
|
+
type: NavigationBlockStateConsumerService,
|
|
1689
|
+
decorators: [{
|
|
1690
|
+
type: Injectable,
|
|
1691
|
+
args: [{ providedIn: "root" }]
|
|
1692
|
+
}]
|
|
1693
|
+
});
|
|
1694
|
+
var NavigationRequestManagerService = class NavigationRequestManagerService {
|
|
1695
|
+
constructor() {
|
|
1696
|
+
this.types = [NAVIGATION_REQUEST_MESSAGE_TYPE, NAVIGATION_DECISION_MESSAGE_TYPE];
|
|
1697
|
+
this.connectionService = inject(ConnectionService);
|
|
1698
|
+
this.producerManagerService = inject(ProducerManagerService);
|
|
1699
|
+
this.logger = inject(LoggerService);
|
|
1700
|
+
this.producerManagerService.register(this);
|
|
1701
|
+
}
|
|
1702
|
+
requestNavigation(target, reason) {
|
|
1703
|
+
if (this.pendingRequest) return this.pendingRequest.promise;
|
|
1704
|
+
const correlationId = generateCorrelationId("nav-req");
|
|
1705
|
+
let resolveFn;
|
|
1706
|
+
const promise = new Promise((resolve) => {
|
|
1707
|
+
resolveFn = resolve;
|
|
1708
|
+
});
|
|
1709
|
+
this.pendingRequest = {
|
|
1710
|
+
correlationId,
|
|
1711
|
+
promise,
|
|
1712
|
+
resolve: resolveFn
|
|
1713
|
+
};
|
|
1714
|
+
const message = {
|
|
1715
|
+
type: NAVIGATION_REQUEST_MESSAGE_TYPE,
|
|
1716
|
+
version: "1.0",
|
|
1717
|
+
correlationId,
|
|
1718
|
+
reason
|
|
1719
|
+
};
|
|
1720
|
+
this.connectionService.send(message, target ? { to: target } : void 0);
|
|
1721
|
+
return promise;
|
|
1722
|
+
}
|
|
1723
|
+
sendDecision(correlationId, target, proceed = true) {
|
|
1724
|
+
const message = {
|
|
1725
|
+
type: NAVIGATION_DECISION_MESSAGE_TYPE,
|
|
1726
|
+
version: "1.0",
|
|
1727
|
+
correlationId,
|
|
1728
|
+
proceed
|
|
1729
|
+
};
|
|
1730
|
+
this.connectionService.send(message, { to: target });
|
|
1731
|
+
}
|
|
1732
|
+
resolvePendingRequest(correlationId, proceed) {
|
|
1733
|
+
const pending = this.pendingRequest;
|
|
1734
|
+
if (!pending || pending.correlationId !== correlationId) return;
|
|
1735
|
+
this.pendingRequest = void 0;
|
|
1736
|
+
pending.resolve(proceed);
|
|
1737
|
+
}
|
|
1738
|
+
handleError(message) {
|
|
1739
|
+
this.logger.error("navigation negotiation message could not be consumed by a peer", message);
|
|
1740
|
+
}
|
|
1741
|
+
ngOnDestroy() {
|
|
1742
|
+
if (this.pendingRequest) {
|
|
1743
|
+
this.pendingRequest.resolve(false);
|
|
1744
|
+
this.pendingRequest = void 0;
|
|
1745
|
+
}
|
|
1746
|
+
this.producerManagerService.unregister(this);
|
|
1747
|
+
}
|
|
1748
|
+
static {
|
|
1749
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1750
|
+
minVersion: "12.0.0",
|
|
1751
|
+
version: "22.2.3",
|
|
1752
|
+
ngImport: i0,
|
|
1753
|
+
type: NavigationRequestManagerService,
|
|
1754
|
+
deps: [],
|
|
1755
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
static {
|
|
1759
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1760
|
+
minVersion: "12.0.0",
|
|
1761
|
+
version: "22.2.3",
|
|
1762
|
+
ngImport: i0,
|
|
1763
|
+
type: NavigationRequestManagerService,
|
|
1764
|
+
providedIn: "root"
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1769
|
+
minVersion: "12.0.0",
|
|
1770
|
+
version: "22.2.3",
|
|
1771
|
+
ngImport: i0,
|
|
1772
|
+
type: NavigationRequestManagerService,
|
|
1773
|
+
decorators: [{
|
|
1774
|
+
type: Injectable,
|
|
1775
|
+
args: [{ providedIn: "root" }]
|
|
1776
|
+
}],
|
|
1777
|
+
ctorParameters: () => []
|
|
1778
|
+
});
|
|
1646
1779
|
const createNavigationRequestHandler = () => {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1652
|
-
};
|
|
1780
|
+
const store = inject(NavigationBlockService);
|
|
1781
|
+
return { handle: () => {
|
|
1782
|
+
store.unblock();
|
|
1783
|
+
} };
|
|
1653
1784
|
};
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
* **Default behavior (modules):** Clears the block state (unblock) — see {@link createNavigationRequestHandler}.
|
|
1658
|
-
* **Shell override:** Opens confirmation modal and awaits user decision.
|
|
1659
|
-
*
|
|
1660
|
-
* The module handler is provided by default at root level. Only the shell application needs to override it
|
|
1661
|
-
* with `provideNavigationRequestShellHandler()`.
|
|
1662
|
-
*/
|
|
1663
|
-
const NAVIGATION_REQUEST_HANDLER = new InjectionToken('NAVIGATION_REQUEST_HANDLER', {
|
|
1664
|
-
providedIn: 'root',
|
|
1665
|
-
factory: createNavigationRequestHandler
|
|
1785
|
+
const NAVIGATION_REQUEST_HANDLER = new InjectionToken("NAVIGATION_REQUEST_HANDLER", {
|
|
1786
|
+
providedIn: "root",
|
|
1787
|
+
factory: createNavigationRequestHandler
|
|
1666
1788
|
});
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1789
|
+
var NavigationRequestConsumerService = class NavigationRequestConsumerService extends AbstractMessageConsumer {
|
|
1790
|
+
constructor() {
|
|
1791
|
+
super(...arguments);
|
|
1792
|
+
this.type = NAVIGATION_REQUEST_MESSAGE_TYPE;
|
|
1793
|
+
this.supportedVersions = { "1.0": (message) => this.handleRequest(message) };
|
|
1794
|
+
this.producerService = inject(NavigationRequestManagerService);
|
|
1795
|
+
this.handler = inject(NAVIGATION_REQUEST_HANDLER);
|
|
1796
|
+
}
|
|
1797
|
+
async handleRequest(message) {
|
|
1798
|
+
try {
|
|
1799
|
+
await this.handler.handle({
|
|
1800
|
+
from: message.from,
|
|
1801
|
+
reason: message.payload.reason
|
|
1802
|
+
});
|
|
1803
|
+
} catch (error) {
|
|
1804
|
+
this.logger.error("navigation-request handler rejected", error, message);
|
|
1805
|
+
this.producerService.sendDecision(message.payload.correlationId, message.from, false);
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
this.producerService.sendDecision(message.payload.correlationId, message.from);
|
|
1809
|
+
}
|
|
1810
|
+
static {
|
|
1811
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1812
|
+
minVersion: "12.0.0",
|
|
1813
|
+
version: "22.2.3",
|
|
1814
|
+
ngImport: i0,
|
|
1815
|
+
type: NavigationRequestConsumerService,
|
|
1816
|
+
deps: null,
|
|
1817
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
static {
|
|
1821
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1822
|
+
minVersion: "12.0.0",
|
|
1823
|
+
version: "22.2.3",
|
|
1824
|
+
ngImport: i0,
|
|
1825
|
+
type: NavigationRequestConsumerService,
|
|
1826
|
+
providedIn: "root"
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1831
|
+
minVersion: "12.0.0",
|
|
1832
|
+
version: "22.2.3",
|
|
1833
|
+
ngImport: i0,
|
|
1834
|
+
type: NavigationRequestConsumerService,
|
|
1835
|
+
decorators: [{
|
|
1836
|
+
type: Injectable,
|
|
1837
|
+
args: [{ providedIn: "root" }]
|
|
1838
|
+
}]
|
|
1839
|
+
});
|
|
1840
|
+
const provideNavigationRequestModuleHandler = () => makeEnvironmentProviders([{
|
|
1841
|
+
provide: NAVIGATION_REQUEST_HANDLER,
|
|
1842
|
+
useFactory: createNavigationRequestHandler
|
|
1843
|
+
}]);
|
|
1844
|
+
var BrowserConfirmationStrategy = class BrowserConfirmationStrategy {
|
|
1845
|
+
confirm(reason) {
|
|
1846
|
+
const message = `${reason ? reason + "\n" : ""}Do you want to leave this page?`;
|
|
1847
|
+
return Promise.resolve(window.confirm(message));
|
|
1848
|
+
}
|
|
1849
|
+
static {
|
|
1850
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1851
|
+
minVersion: "12.0.0",
|
|
1852
|
+
version: "22.2.3",
|
|
1853
|
+
ngImport: i0,
|
|
1854
|
+
type: BrowserConfirmationStrategy,
|
|
1855
|
+
deps: [],
|
|
1856
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
static {
|
|
1860
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1861
|
+
minVersion: "12.0.0",
|
|
1862
|
+
version: "22.2.3",
|
|
1863
|
+
ngImport: i0,
|
|
1864
|
+
type: BrowserConfirmationStrategy,
|
|
1865
|
+
providedIn: "root"
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1870
|
+
minVersion: "12.0.0",
|
|
1871
|
+
version: "22.2.3",
|
|
1872
|
+
ngImport: i0,
|
|
1873
|
+
type: BrowserConfirmationStrategy,
|
|
1874
|
+
decorators: [{
|
|
1875
|
+
type: Injectable,
|
|
1876
|
+
args: [{ providedIn: "root" }]
|
|
1877
|
+
}]
|
|
1878
|
+
});
|
|
1879
|
+
const NAVIGATION_BLOCK_CONFIRMATION = new InjectionToken("NAVIGATION_BLOCK_CONFIRMATION", {
|
|
1880
|
+
providedIn: "root",
|
|
1881
|
+
factory: () => inject(BrowserConfirmationStrategy)
|
|
1882
|
+
});
|
|
1883
|
+
var NavigationBlockConfirmationService = class NavigationBlockConfirmationService {
|
|
1884
|
+
constructor() {
|
|
1885
|
+
this.strategy = inject(NAVIGATION_BLOCK_CONFIRMATION);
|
|
1886
|
+
}
|
|
1887
|
+
confirm(reason) {
|
|
1888
|
+
if (this.pendingConfirmation) return this.pendingConfirmation;
|
|
1889
|
+
const pending = this.strategy.confirm(reason).finally(() => {
|
|
1890
|
+
this.pendingConfirmation = void 0;
|
|
1891
|
+
});
|
|
1892
|
+
this.pendingConfirmation = pending;
|
|
1893
|
+
return pending;
|
|
1894
|
+
}
|
|
1895
|
+
static {
|
|
1896
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1897
|
+
minVersion: "12.0.0",
|
|
1898
|
+
version: "22.2.3",
|
|
1899
|
+
ngImport: i0,
|
|
1900
|
+
type: NavigationBlockConfirmationService,
|
|
1901
|
+
deps: [],
|
|
1902
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
static {
|
|
1906
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1907
|
+
minVersion: "12.0.0",
|
|
1908
|
+
version: "22.2.3",
|
|
1909
|
+
ngImport: i0,
|
|
1910
|
+
type: NavigationBlockConfirmationService,
|
|
1911
|
+
providedIn: "root"
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1916
|
+
minVersion: "12.0.0",
|
|
1917
|
+
version: "22.2.3",
|
|
1918
|
+
ngImport: i0,
|
|
1919
|
+
type: NavigationBlockConfirmationService,
|
|
1920
|
+
decorators: [{
|
|
1921
|
+
type: Injectable,
|
|
1922
|
+
args: [{ providedIn: "root" }]
|
|
1923
|
+
}]
|
|
1771
1924
|
});
|
|
1772
|
-
|
|
1773
|
-
/**
|
|
1774
|
-
* Orchestrates navigation block confirmation by delegating to a pluggable strategy.
|
|
1775
|
-
* Handles concurrent call deduplication to prevent duplicate confirmations when guards run multiple times.
|
|
1776
|
-
*
|
|
1777
|
-
* The confirmation UI is read from the `NAVIGATION_BLOCK_CONFIRMATION` token, which defaults to {@link BrowserConfirmationStrategy}
|
|
1778
|
-
* (no setup required). Apps with a styled modal override the token via `provideNavigationConfig({ confirmationStrategy })`
|
|
1779
|
-
* or by binding the token directly.
|
|
1780
|
-
*/
|
|
1781
|
-
class NavigationBlockConfirmationService {
|
|
1782
|
-
constructor() {
|
|
1783
|
-
this.strategy = inject(NAVIGATION_BLOCK_CONFIRMATION);
|
|
1784
|
-
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Show confirmation and await user decision. Concurrent calls return the same promise to prevent duplicate confirmations.
|
|
1787
|
-
* @param reason Optional reason displayed in the confirmation UI
|
|
1788
|
-
* @returns `true` when the user confirms, `false` when they cancel
|
|
1789
|
-
*/
|
|
1790
|
-
confirm(reason) {
|
|
1791
|
-
// Deduplication: if confirmation already in progress, return same promise
|
|
1792
|
-
if (this.pendingConfirmation) {
|
|
1793
|
-
return this.pendingConfirmation;
|
|
1794
|
-
}
|
|
1795
|
-
// Delegate to injected strategy. Clear the slot only once the promise
|
|
1796
|
-
// settles, so concurrent callers in the meantime get the same promise.
|
|
1797
|
-
const pending = this.strategy.confirm(reason).finally(() => {
|
|
1798
|
-
this.pendingConfirmation = undefined;
|
|
1799
|
-
});
|
|
1800
|
-
this.pendingConfirmation = pending;
|
|
1801
|
-
return pending;
|
|
1802
|
-
}
|
|
1803
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBlockConfirmationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1804
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBlockConfirmationService, providedIn: 'root' }); }
|
|
1805
|
-
}
|
|
1806
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBlockConfirmationService, decorators: [{
|
|
1807
|
-
type: Injectable,
|
|
1808
|
-
args: [{
|
|
1809
|
-
providedIn: 'root'
|
|
1810
|
-
}]
|
|
1811
|
-
}] });
|
|
1812
|
-
|
|
1813
|
-
/**
|
|
1814
|
-
* Shell application `navigation-request` handler used when a module initiates the navigation (in-iframe link click).
|
|
1815
|
-
* Opens the shared confirmation modal, awaits the user's answer, and — on confirm — clears the shell's block mirror.
|
|
1816
|
-
* On cancel the handler throws; the consumer catches it and replies with a `navigation-decision` carrying `proceed: false`,
|
|
1817
|
-
* so the module's pending promise resolves to `false` and the iframe navigation is held until a fresh request is made.
|
|
1818
|
-
*/
|
|
1819
1925
|
const createNavigationRequestShellHandler = () => {
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
throw new Error('navigation-request cancelled by user');
|
|
1827
|
-
}
|
|
1828
|
-
blockConsumer.clear();
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1926
|
+
const confirmation = inject(NavigationBlockConfirmationService);
|
|
1927
|
+
const blockConsumer = inject(NavigationBlockStateConsumerService);
|
|
1928
|
+
return { handle: async ({ reason }) => {
|
|
1929
|
+
if (!await confirmation.confirm(reason)) throw new Error("navigation-request cancelled by user");
|
|
1930
|
+
blockConsumer.clear();
|
|
1931
|
+
} };
|
|
1831
1932
|
};
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
}]
|
|
1876
|
-
}] });
|
|
1877
|
-
|
|
1878
|
-
/**
|
|
1879
|
-
* Shell application guard intercepting shell-initiated navigation (sidebar clicks, URL bar, programmatic `router.navigate`)
|
|
1880
|
-
* when the last state received from a module is `blocked`.
|
|
1881
|
-
*
|
|
1882
|
-
* Can be used as both `canActivate` and `canActivateChild` to ensure the guard runs when entering a route directly
|
|
1883
|
-
* or navigating to its children.
|
|
1884
|
-
*
|
|
1885
|
-
* Flow:
|
|
1886
|
-
* - No state received, or `blocked === false` → navigation proceeds.
|
|
1887
|
-
* - `blocked === true` → open the confirmation modal.
|
|
1888
|
-
* - On cancel/dismiss → return `false`, state is untouched, no message sent to the module.
|
|
1889
|
-
* - On confirm → clear the shell mirror, send a `navigation-request` to the originating module (so it can run its unblock /
|
|
1890
|
-
* future draft-persistence logic), await its `navigation-decision`, then return `true`.
|
|
1891
|
-
*/
|
|
1933
|
+
const provideNavigationRequestShellHandler = () => makeEnvironmentProviders([{
|
|
1934
|
+
provide: NAVIGATION_REQUEST_HANDLER,
|
|
1935
|
+
useFactory: createNavigationRequestShellHandler
|
|
1936
|
+
}]);
|
|
1937
|
+
var NavigationDecisionConsumerService = class NavigationDecisionConsumerService extends AbstractMessageConsumer {
|
|
1938
|
+
constructor() {
|
|
1939
|
+
super(...arguments);
|
|
1940
|
+
this.type = NAVIGATION_DECISION_MESSAGE_TYPE;
|
|
1941
|
+
this.supportedVersions = { "1.0": (message) => {
|
|
1942
|
+
this.producerService.resolvePendingRequest(message.payload.correlationId, message.payload.proceed);
|
|
1943
|
+
} };
|
|
1944
|
+
this.producerService = inject(NavigationRequestManagerService);
|
|
1945
|
+
}
|
|
1946
|
+
static {
|
|
1947
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1948
|
+
minVersion: "12.0.0",
|
|
1949
|
+
version: "22.2.3",
|
|
1950
|
+
ngImport: i0,
|
|
1951
|
+
type: NavigationDecisionConsumerService,
|
|
1952
|
+
deps: null,
|
|
1953
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
static {
|
|
1957
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1958
|
+
minVersion: "12.0.0",
|
|
1959
|
+
version: "22.2.3",
|
|
1960
|
+
ngImport: i0,
|
|
1961
|
+
type: NavigationDecisionConsumerService,
|
|
1962
|
+
providedIn: "root"
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
};
|
|
1966
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1967
|
+
minVersion: "12.0.0",
|
|
1968
|
+
version: "22.2.3",
|
|
1969
|
+
ngImport: i0,
|
|
1970
|
+
type: NavigationDecisionConsumerService,
|
|
1971
|
+
decorators: [{
|
|
1972
|
+
type: Injectable,
|
|
1973
|
+
args: [{ providedIn: "root" }]
|
|
1974
|
+
}]
|
|
1975
|
+
});
|
|
1892
1976
|
const navigationBlockShellGuard = async () => {
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
return false;
|
|
1903
|
-
}
|
|
1904
|
-
consumer.clear();
|
|
1905
|
-
if (!state.channelId) {
|
|
1906
|
-
return true;
|
|
1907
|
-
}
|
|
1908
|
-
return negotiation.requestNavigation(state.channelId, state.reason);
|
|
1977
|
+
const consumer = inject(NavigationBlockStateConsumerService);
|
|
1978
|
+
const confirmation = inject(NavigationBlockConfirmationService);
|
|
1979
|
+
const negotiation = inject(NavigationRequestManagerService);
|
|
1980
|
+
const state = consumer.blockState();
|
|
1981
|
+
if (!state?.blocked) return true;
|
|
1982
|
+
if (!await confirmation.confirm(state.reason)) return false;
|
|
1983
|
+
consumer.clear();
|
|
1984
|
+
if (!state.channelId) return true;
|
|
1985
|
+
return negotiation.requestNavigation(state.channelId, state.reason);
|
|
1909
1986
|
};
|
|
1910
|
-
|
|
1911
|
-
/**
|
|
1912
|
-
* Module-side guard intercepting navigation away from a page that holds unsaved changes.
|
|
1913
|
-
*
|
|
1914
|
-
* - `blocked === false` → navigation proceeds.
|
|
1915
|
-
* - `blocked === true` → broadcast a `navigation-request` to the shell and await the reply. The shell opens the confirmation modal
|
|
1916
|
-
* and replies in both cases: `proceed === true` on confirm, `proceed === false` on cancel/dismiss. On proceed, clear the local
|
|
1917
|
-
* state and return `true`; on cancel, return `false` and leave the block state intact so the navigation is held and a later
|
|
1918
|
-
* attempt can negotiate again.
|
|
1919
|
-
*
|
|
1920
|
-
* Wire it as `canDeactivate` only on the routes that can actually hold unsaved work — modules opt in per page.
|
|
1921
|
-
*/
|
|
1922
1987
|
const navigationBlockModuleGuard = async () => {
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
if (proceed) {
|
|
1931
|
-
store.unblock();
|
|
1932
|
-
}
|
|
1933
|
-
return proceed;
|
|
1988
|
+
const store = inject(NavigationBlockService);
|
|
1989
|
+
const negotiation = inject(NavigationRequestManagerService);
|
|
1990
|
+
const { blocked, reason } = store.state();
|
|
1991
|
+
if (!blocked) return true;
|
|
1992
|
+
const proceed = await negotiation.requestNavigation(void 0, reason);
|
|
1993
|
+
if (proceed) store.unblock();
|
|
1994
|
+
return proceed;
|
|
1934
1995
|
};
|
|
1935
|
-
|
|
1936
|
-
/**
|
|
1937
|
-
* Convenience helper that explicitly binds the {@link NAVIGATION_BLOCK_CONFIRMATION} token to {@link BrowserConfirmationStrategy}.
|
|
1938
|
-
*
|
|
1939
|
-
* **Usually unnecessary** — the token already defaults to `BrowserConfirmationStrategy` via its tree-shakable factory,
|
|
1940
|
-
* so the helper only re-binds the same value. Use it when you want the binding to be visible at the call site
|
|
1941
|
-
* (e.g. for documentation in `app.config.ts`) or when you've previously overridden the token and want to switch back
|
|
1942
|
-
* to the default in a child injector.
|
|
1943
|
-
*
|
|
1944
|
-
* Production apps with a styled modal pass their own strategy via `provideNavigationConfig({ confirmationStrategy })` instead.
|
|
1945
|
-
* @example
|
|
1946
|
-
* ```typescript
|
|
1947
|
-
* // app.config.ts
|
|
1948
|
-
* export const appConfig: ApplicationConfig = {
|
|
1949
|
-
* providers: [
|
|
1950
|
-
* provideDefaultNavigationBlockConfirmation(),
|
|
1951
|
-
* // ... other providers
|
|
1952
|
-
* ]
|
|
1953
|
-
* };
|
|
1954
|
-
* ```
|
|
1955
|
-
*/
|
|
1956
1996
|
function provideDefaultNavigationBlockConfirmation() {
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
}
|
|
1962
|
-
]);
|
|
1997
|
+
return makeEnvironmentProviders([{
|
|
1998
|
+
provide: NAVIGATION_BLOCK_CONFIRMATION,
|
|
1999
|
+
useClass: BrowserConfirmationStrategy
|
|
2000
|
+
}]);
|
|
1963
2001
|
}
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
}
|
|
2054
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2002
|
+
var ResizeService = class ResizeService {
|
|
2003
|
+
constructor() {
|
|
2004
|
+
this.messageService = inject(MessagePeerService);
|
|
2005
|
+
this.types = RESIZE_MESSAGE_TYPE;
|
|
2006
|
+
registerProducer(this);
|
|
2007
|
+
}
|
|
2008
|
+
handleError(message) {
|
|
2009
|
+
console.error("Error in resize service message", message);
|
|
2010
|
+
}
|
|
2011
|
+
startResizeObserver() {
|
|
2012
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
2013
|
+
const newHeight = document.body.getBoundingClientRect().height;
|
|
2014
|
+
if (!this.actualHeight || newHeight !== this.actualHeight) {
|
|
2015
|
+
this.actualHeight = newHeight;
|
|
2016
|
+
const messageV10 = {
|
|
2017
|
+
type: "resize",
|
|
2018
|
+
version: "1.0",
|
|
2019
|
+
height: this.actualHeight
|
|
2020
|
+
};
|
|
2021
|
+
this.messageService.send(messageV10);
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
afterNextRender(() => this.resizeObserver?.observe(document.body));
|
|
2025
|
+
}
|
|
2026
|
+
static {
|
|
2027
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
2028
|
+
minVersion: "12.0.0",
|
|
2029
|
+
version: "22.2.3",
|
|
2030
|
+
ngImport: i0,
|
|
2031
|
+
type: ResizeService,
|
|
2032
|
+
deps: [],
|
|
2033
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
static {
|
|
2037
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2038
|
+
minVersion: "12.0.0",
|
|
2039
|
+
version: "22.2.3",
|
|
2040
|
+
ngImport: i0,
|
|
2041
|
+
type: ResizeService,
|
|
2042
|
+
providedIn: "root"
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2047
|
+
minVersion: "12.0.0",
|
|
2048
|
+
version: "22.2.3",
|
|
2049
|
+
ngImport: i0,
|
|
2050
|
+
type: ResizeService,
|
|
2051
|
+
decorators: [{
|
|
2052
|
+
type: Injectable,
|
|
2053
|
+
args: [{ providedIn: "root" }]
|
|
2054
|
+
}],
|
|
2055
|
+
ctorParameters: () => []
|
|
2056
|
+
});
|
|
2057
|
+
var ThemeConsumerService = class ThemeConsumerService extends AbstractMessageConsumer {
|
|
2058
|
+
constructor() {
|
|
2059
|
+
super(...arguments);
|
|
2060
|
+
this.domSanitizer = inject(DomSanitizer);
|
|
2061
|
+
this.type = THEME_MESSAGE_TYPE;
|
|
2062
|
+
this.supportedVersions = { "1.0": async (message) => {
|
|
2063
|
+
const sanitizedCss = this.domSanitizer.sanitize(SecurityContext.STYLE, message.payload.css);
|
|
2064
|
+
if (sanitizedCss !== null) applyTheme(sanitizedCss);
|
|
2065
|
+
try {
|
|
2066
|
+
applyTheme(await downloadApplicationThemeCss(message.payload.name, { logger: this.logger }), false);
|
|
2067
|
+
} catch (e) {
|
|
2068
|
+
this.logger.warn(`No CSS variable for the theme ${message.payload.name}`, e);
|
|
2069
|
+
}
|
|
2070
|
+
} };
|
|
2071
|
+
}
|
|
2072
|
+
static {
|
|
2073
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
2074
|
+
minVersion: "12.0.0",
|
|
2075
|
+
version: "22.2.3",
|
|
2076
|
+
ngImport: i0,
|
|
2077
|
+
type: ThemeConsumerService,
|
|
2078
|
+
deps: null,
|
|
2079
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
static {
|
|
2083
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2084
|
+
minVersion: "12.0.0",
|
|
2085
|
+
version: "22.2.3",
|
|
2086
|
+
ngImport: i0,
|
|
2087
|
+
type: ThemeConsumerService,
|
|
2088
|
+
providedIn: "root"
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
2092
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2093
|
+
minVersion: "12.0.0",
|
|
2094
|
+
version: "22.2.3",
|
|
2095
|
+
ngImport: i0,
|
|
2096
|
+
type: ThemeConsumerService,
|
|
2097
|
+
decorators: [{
|
|
2098
|
+
type: Injectable,
|
|
2099
|
+
args: [{ providedIn: "root" }]
|
|
2100
|
+
}]
|
|
2101
|
+
});
|
|
2064
2102
|
const ACTIVITY_EVENTS = [
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
];
|
|
2071
|
-
/**
|
|
2072
|
-
* Custom activity event type for iframe interactions.
|
|
2073
|
-
* Emitted programmatically when an iframe gains focus, not from a DOM event listener.
|
|
2074
|
-
*/
|
|
2075
|
-
const IFRAME_INTERACTION_EVENT = 'iframeinteraction';
|
|
2076
|
-
/**
|
|
2077
|
-
* Custom activity event type for visibility changes.
|
|
2078
|
-
* Emitted programmatically when the document becomes visible, not from a DOM event listener.
|
|
2079
|
-
*/
|
|
2080
|
-
const VISIBILITY_CHANGE_EVENT = 'visibilitychange';
|
|
2081
|
-
/**
|
|
2082
|
-
* High-frequency events that require throttling to avoid performance issues
|
|
2083
|
-
*/
|
|
2084
|
-
const HIGH_FREQUENCY_EVENTS = [
|
|
2085
|
-
'scroll'
|
|
2103
|
+
"click",
|
|
2104
|
+
"keydown",
|
|
2105
|
+
"scroll",
|
|
2106
|
+
"touchstart",
|
|
2107
|
+
"focus"
|
|
2086
2108
|
];
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2109
|
+
const IFRAME_INTERACTION_EVENT = "iframeinteraction";
|
|
2110
|
+
const VISIBILITY_CHANGE_EVENT = "visibilitychange";
|
|
2111
|
+
const HIGH_FREQUENCY_EVENTS = ["scroll"];
|
|
2090
2112
|
const DEFAULT_ACTIVITY_PRODUCER_CONFIG = {
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
trackNestedIframes: false,
|
|
2097
|
-
/** Default interval for iframe activity signals (30 seconds) */
|
|
2098
|
-
nestedIframeActivityEmitIntervalMs: 30_000,
|
|
2099
|
-
/** Default polling interval for detecting iframe focus changes (1 second) */
|
|
2100
|
-
nestedIframePollIntervalMs: 1000
|
|
2113
|
+
throttleMs: 1e3,
|
|
2114
|
+
highFrequencyThrottleMs: 300,
|
|
2115
|
+
trackNestedIframes: false,
|
|
2116
|
+
nestedIframeActivityEmitIntervalMs: 3e4,
|
|
2117
|
+
nestedIframePollIntervalMs: 1e3
|
|
2101
2118
|
};
|
|
2119
|
+
var IframeActivityTrackerService = class IframeActivityTrackerService {
|
|
2120
|
+
constructor() {
|
|
2121
|
+
this.visibilityChangeHandler = () => this.handleVisibilityChange();
|
|
2122
|
+
}
|
|
2123
|
+
get started() {
|
|
2124
|
+
return this.config !== void 0;
|
|
2125
|
+
}
|
|
2126
|
+
get isTrackingIframeActivity() {
|
|
2127
|
+
return this.activityIntervalId !== void 0;
|
|
2128
|
+
}
|
|
2129
|
+
checkActiveElement() {
|
|
2130
|
+
const iframeFocused = document.activeElement instanceof HTMLIFrameElement;
|
|
2131
|
+
if (iframeFocused && !this.isTrackingIframeActivity) {
|
|
2132
|
+
this.config?.onActivity();
|
|
2133
|
+
this.startActivityInterval();
|
|
2134
|
+
} else if (!iframeFocused && this.isTrackingIframeActivity) this.stopActivityInterval();
|
|
2135
|
+
}
|
|
2136
|
+
handleVisibilityChange() {
|
|
2137
|
+
if (document.visibilityState === "visible") this.startPolling();
|
|
2138
|
+
else {
|
|
2139
|
+
this.stopPolling();
|
|
2140
|
+
this.stopActivityInterval();
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
startPolling() {
|
|
2144
|
+
if (this.pollIntervalId) return;
|
|
2145
|
+
this.pollIntervalId = setInterval(() => this.checkActiveElement(), this.config.pollIntervalMs);
|
|
2146
|
+
}
|
|
2147
|
+
stopPolling() {
|
|
2148
|
+
if (this.pollIntervalId) {
|
|
2149
|
+
clearInterval(this.pollIntervalId);
|
|
2150
|
+
this.pollIntervalId = void 0;
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
startActivityInterval() {
|
|
2154
|
+
this.stopActivityInterval();
|
|
2155
|
+
this.activityIntervalId = setInterval(() => {
|
|
2156
|
+
this.config?.onActivity();
|
|
2157
|
+
}, this.config.activityIntervalMs);
|
|
2158
|
+
}
|
|
2159
|
+
stopActivityInterval() {
|
|
2160
|
+
if (this.activityIntervalId) {
|
|
2161
|
+
clearInterval(this.activityIntervalId);
|
|
2162
|
+
this.activityIntervalId = void 0;
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
start(config) {
|
|
2166
|
+
if (this.started) return;
|
|
2167
|
+
this.config = config;
|
|
2168
|
+
document.addEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
2169
|
+
if (document.visibilityState === "visible") this.startPolling();
|
|
2170
|
+
}
|
|
2171
|
+
stop() {
|
|
2172
|
+
if (!this.started) return;
|
|
2173
|
+
document.removeEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
2174
|
+
this.stopPolling();
|
|
2175
|
+
this.stopActivityInterval();
|
|
2176
|
+
this.config = void 0;
|
|
2177
|
+
}
|
|
2178
|
+
static {
|
|
2179
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
2180
|
+
minVersion: "12.0.0",
|
|
2181
|
+
version: "22.2.3",
|
|
2182
|
+
ngImport: i0,
|
|
2183
|
+
type: IframeActivityTrackerService,
|
|
2184
|
+
deps: [],
|
|
2185
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
static {
|
|
2189
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2190
|
+
minVersion: "12.0.0",
|
|
2191
|
+
version: "22.2.3",
|
|
2192
|
+
ngImport: i0,
|
|
2193
|
+
type: IframeActivityTrackerService,
|
|
2194
|
+
providedIn: "root"
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2199
|
+
minVersion: "12.0.0",
|
|
2200
|
+
version: "22.2.3",
|
|
2201
|
+
ngImport: i0,
|
|
2202
|
+
type: IframeActivityTrackerService,
|
|
2203
|
+
decorators: [{
|
|
2204
|
+
type: Injectable,
|
|
2205
|
+
args: [{ providedIn: "root" }]
|
|
2206
|
+
}]
|
|
2207
|
+
});
|
|
2208
|
+
var ActivityProducerService = class ActivityProducerService {
|
|
2209
|
+
constructor() {
|
|
2210
|
+
this.messageService = inject(ConnectionService);
|
|
2211
|
+
this.destroyRef = inject(DestroyRef);
|
|
2212
|
+
this.iframeActivityTracker = inject(IframeActivityTrackerService);
|
|
2213
|
+
this.logger = inject(LoggerService);
|
|
2214
|
+
this.lastSentTimestamp = 0;
|
|
2215
|
+
this.boundListeners = /* @__PURE__ */ new Map();
|
|
2216
|
+
this.lastEmitTimestamps = /* @__PURE__ */ new Map();
|
|
2217
|
+
this.started = false;
|
|
2218
|
+
this.localActivityWritable = signal(void 0, ...ngDevMode ? [{ debugName: "localActivityWritable" }] : /* istanbul ignore next */ []);
|
|
2219
|
+
this.localActivity = this.localActivityWritable.asReadonly();
|
|
2220
|
+
this.types = USER_ACTIVITY_MESSAGE_TYPE;
|
|
2221
|
+
registerProducer(this);
|
|
2222
|
+
this.destroyRef.onDestroy(() => this.stop());
|
|
2223
|
+
}
|
|
2224
|
+
shouldProcessHighFrequencyEvent(eventType, throttleMs) {
|
|
2225
|
+
const now = Date.now();
|
|
2226
|
+
if (now - (this.lastEmitTimestamps.get(eventType) ?? 0) >= throttleMs) {
|
|
2227
|
+
this.lastEmitTimestamps.set(eventType, now);
|
|
2228
|
+
return true;
|
|
2229
|
+
}
|
|
2230
|
+
return false;
|
|
2231
|
+
}
|
|
2232
|
+
onActivity(eventType, configObject) {
|
|
2233
|
+
const now = Date.now();
|
|
2234
|
+
this.localActivityWritable.set({
|
|
2235
|
+
channelId: "local",
|
|
2236
|
+
eventType,
|
|
2237
|
+
timestamp: now
|
|
2238
|
+
});
|
|
2239
|
+
if (now - this.lastSentTimestamp >= configObject.throttleMs) {
|
|
2240
|
+
this.lastSentTimestamp = now;
|
|
2241
|
+
this.sendActivityMessage(eventType, now);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
sendActivityMessage(eventType, timestamp) {
|
|
2245
|
+
const message = {
|
|
2246
|
+
type: USER_ACTIVITY_MESSAGE_TYPE,
|
|
2247
|
+
version: "1.0",
|
|
2248
|
+
eventType,
|
|
2249
|
+
timestamp
|
|
2250
|
+
};
|
|
2251
|
+
const registeredPeersIdsForUserActivity = [...this.messageService.knownPeers.entries()].filter(([peerId]) => peerId !== this.messageService.id).filter(([, messages]) => messages.some((msg) => msg.type === USER_ACTIVITY_MESSAGE_TYPE)).map((peer) => peer[0]);
|
|
2252
|
+
if (registeredPeersIdsForUserActivity.length > 0) this.messageService.send(message, { to: registeredPeersIdsForUserActivity });
|
|
2253
|
+
}
|
|
2254
|
+
handleError(message) {
|
|
2255
|
+
this.logger.error("Error in user activity service message", message);
|
|
2256
|
+
}
|
|
2257
|
+
start(config) {
|
|
2258
|
+
if (this.started) return;
|
|
2259
|
+
this.started = true;
|
|
2260
|
+
const configObject = {
|
|
2261
|
+
...DEFAULT_ACTIVITY_PRODUCER_CONFIG,
|
|
2262
|
+
...config
|
|
2263
|
+
};
|
|
2264
|
+
afterNextRender(() => {
|
|
2265
|
+
ACTIVITY_EVENTS.forEach((eventType) => {
|
|
2266
|
+
const isHighFrequency = HIGH_FREQUENCY_EVENTS.includes(eventType);
|
|
2267
|
+
const listener = (event) => {
|
|
2268
|
+
if (eventType === "keydown" && event instanceof KeyboardEvent && event.repeat) return;
|
|
2269
|
+
if (isHighFrequency && !this.shouldProcessHighFrequencyEvent(eventType, configObject.highFrequencyThrottleMs)) return;
|
|
2270
|
+
if (configObject.shouldBroadcast?.(event) === false) return;
|
|
2271
|
+
this.onActivity(eventType, configObject);
|
|
2272
|
+
};
|
|
2273
|
+
this.boundListeners.set(eventType, listener);
|
|
2274
|
+
document.addEventListener(eventType, listener, {
|
|
2275
|
+
passive: true,
|
|
2276
|
+
capture: true
|
|
2277
|
+
});
|
|
2278
|
+
});
|
|
2279
|
+
const visibilityListener = () => {
|
|
2280
|
+
if (document.visibilityState === "visible") this.onActivity(VISIBILITY_CHANGE_EVENT, configObject);
|
|
2281
|
+
};
|
|
2282
|
+
this.boundListeners.set(VISIBILITY_CHANGE_EVENT, visibilityListener);
|
|
2283
|
+
document.addEventListener(VISIBILITY_CHANGE_EVENT, visibilityListener, {
|
|
2284
|
+
passive: true,
|
|
2285
|
+
capture: true
|
|
2286
|
+
});
|
|
2287
|
+
if (configObject.trackNestedIframes) this.iframeActivityTracker.start({
|
|
2288
|
+
pollIntervalMs: configObject.nestedIframePollIntervalMs,
|
|
2289
|
+
activityIntervalMs: configObject.nestedIframeActivityEmitIntervalMs,
|
|
2290
|
+
onActivity: () => this.onActivity(IFRAME_INTERACTION_EVENT, configObject)
|
|
2291
|
+
});
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
stop() {
|
|
2295
|
+
this.boundListeners.forEach((listener, eventType) => {
|
|
2296
|
+
document.removeEventListener(eventType, listener, { capture: true });
|
|
2297
|
+
});
|
|
2298
|
+
this.boundListeners.clear();
|
|
2299
|
+
this.lastEmitTimestamps.clear();
|
|
2300
|
+
this.iframeActivityTracker.stop();
|
|
2301
|
+
}
|
|
2302
|
+
static {
|
|
2303
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
2304
|
+
minVersion: "12.0.0",
|
|
2305
|
+
version: "22.2.3",
|
|
2306
|
+
ngImport: i0,
|
|
2307
|
+
type: ActivityProducerService,
|
|
2308
|
+
deps: [],
|
|
2309
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
static {
|
|
2313
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2314
|
+
minVersion: "12.0.0",
|
|
2315
|
+
version: "22.2.3",
|
|
2316
|
+
ngImport: i0,
|
|
2317
|
+
type: ActivityProducerService,
|
|
2318
|
+
providedIn: "root"
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2323
|
+
minVersion: "12.0.0",
|
|
2324
|
+
version: "22.2.3",
|
|
2325
|
+
ngImport: i0,
|
|
2326
|
+
type: ActivityProducerService,
|
|
2327
|
+
decorators: [{
|
|
2328
|
+
type: Injectable,
|
|
2329
|
+
args: [{ providedIn: "root" }]
|
|
2330
|
+
}],
|
|
2331
|
+
ctorParameters: () => []
|
|
2332
|
+
});
|
|
2333
|
+
var ActivityConsumerService = class ActivityConsumerService {
|
|
2334
|
+
constructor() {
|
|
2335
|
+
this.consumerManagerService = inject(ConsumerManagerService);
|
|
2336
|
+
this.latestReceivedActivityWritable = signal(void 0, ...ngDevMode ? [{ debugName: "latestReceivedActivityWritable" }] : /* istanbul ignore next */ []);
|
|
2337
|
+
this.latestReceivedActivity = this.latestReceivedActivityWritable.asReadonly();
|
|
2338
|
+
this.type = USER_ACTIVITY_MESSAGE_TYPE;
|
|
2339
|
+
this.supportedVersions = { "1.0": (message) => {
|
|
2340
|
+
this.latestReceivedActivityWritable.set({
|
|
2341
|
+
channelId: message.from || "unknown",
|
|
2342
|
+
eventType: message.payload.eventType,
|
|
2343
|
+
timestamp: message.payload.timestamp
|
|
2344
|
+
});
|
|
2345
|
+
} };
|
|
2346
|
+
}
|
|
2347
|
+
start() {
|
|
2348
|
+
this.consumerManagerService.register(this);
|
|
2349
|
+
}
|
|
2350
|
+
stop() {
|
|
2351
|
+
this.consumerManagerService.unregister(this);
|
|
2352
|
+
}
|
|
2353
|
+
static {
|
|
2354
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
2355
|
+
minVersion: "12.0.0",
|
|
2356
|
+
version: "22.2.3",
|
|
2357
|
+
ngImport: i0,
|
|
2358
|
+
type: ActivityConsumerService,
|
|
2359
|
+
deps: [],
|
|
2360
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
static {
|
|
2364
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
2365
|
+
minVersion: "12.0.0",
|
|
2366
|
+
version: "22.2.3",
|
|
2367
|
+
ngImport: i0,
|
|
2368
|
+
type: ActivityConsumerService,
|
|
2369
|
+
providedIn: "root"
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2374
|
+
minVersion: "12.0.0",
|
|
2375
|
+
version: "22.2.3",
|
|
2376
|
+
ngImport: i0,
|
|
2377
|
+
type: ActivityConsumerService,
|
|
2378
|
+
decorators: [{
|
|
2379
|
+
type: Injectable,
|
|
2380
|
+
args: [{ providedIn: "root" }]
|
|
2381
|
+
}]
|
|
2382
|
+
});
|
|
2383
|
+
export { ACTIVITY_EVENTS, AbstractMessageConsumer, ActivityConsumerService, ActivityProducerService, ApplyTheme, BrowserConfirmationStrategy, ConnectDirective, ConnectionService, ConsumerManagerService, DEFAULT_ACTIVITY_PRODUCER_CONFIG, ERROR_MESSAGE_TYPE, HIGH_FREQUENCY_EVENTS, HistoryConsumerService, HostInfoPipe, IFRAME_INTERACTION_EVENT, IframeActivityTrackerService, IframeEmbedComponent, KNOWN_MESSAGES, MFE_HOST_APPLICATION_ID_PARAM, MFE_HOST_URL_PARAM, MFE_MODULE_APPLICATION_ID_PARAM, NAVIGATION_BLOCK_CONFIRMATION, NAVIGATION_REQUEST_HANDLER, NavigationBlockConfirmationService, NavigationBlockService, NavigationBlockStateConsumerService, NavigationBlockStateProducerService, NavigationConsumerService, NavigationDecisionConsumerService, NavigationRequestConsumerService, NavigationRequestManagerService, ProducerManagerService, ResizeConsumerService, ResizeService, RestoreRoute, RouteMemorizeDirective, RouteMemorizeService, RoutingService, ScalableDirective, THEME_QUERY_PARAM_NAME, THEME_URL_SUFFIX, ThemeConsumerService, ThemeProducerService, VISIBILITY_CHANGE_EVENT, applyInitialTheme, applyTheme, createNavigationRequestHandler, createNavigationRequestShellHandler, downloadApplicationThemeCss, generateCorrelationId, getAvailableConsumers, getDefaultClientEndpointStartOptions, getHostInfo, getStyle, hostQueryParams, isEmbedded, isErrorMessage, isUserActivityMessage, navigationBlockModuleGuard, navigationBlockShellGuard, persistHostInfo, provideConnection, provideDefaultNavigationBlockConfirmation, provideHistoryOverrides, provideNavigationRequestModuleHandler, provideNavigationRequestShellHandler, registerConsumer, registerProducer, sendError };
|
|
2102
2384
|
|
|
2103
|
-
|
|
2104
|
-
* Service that tracks user activity within nested iframes.
|
|
2105
|
-
*
|
|
2106
|
-
* Polls document.activeElement frequently to detect when an iframe has focus.
|
|
2107
|
-
* When an iframe gains focus, emits immediately and then at the configured interval.
|
|
2108
|
-
* When focus leaves the iframe, it stops emitting.
|
|
2109
|
-
*
|
|
2110
|
-
* This is needed because cross-origin iframes don't fire focus/blur events
|
|
2111
|
-
* that bubble to the parent, and the regular activity tracker can't detect
|
|
2112
|
-
* user interactions inside iframes.
|
|
2113
|
-
*/
|
|
2114
|
-
class IframeActivityTrackerService {
|
|
2115
|
-
constructor() {
|
|
2116
|
-
/**
|
|
2117
|
-
* Bound visibility change handler for cleanup
|
|
2118
|
-
*/
|
|
2119
|
-
this.visibilityChangeHandler = () => this.handleVisibilityChange();
|
|
2120
|
-
}
|
|
2121
|
-
/**
|
|
2122
|
-
* Whether the service has been started
|
|
2123
|
-
*/
|
|
2124
|
-
get started() {
|
|
2125
|
-
return this.config !== undefined;
|
|
2126
|
-
}
|
|
2127
|
-
/**
|
|
2128
|
-
* Whether we are currently tracking iframe activity (iframe had focus on last poll)
|
|
2129
|
-
*/
|
|
2130
|
-
get isTrackingIframeActivity() {
|
|
2131
|
-
return this.activityIntervalId !== undefined;
|
|
2132
|
-
}
|
|
2133
|
-
/**
|
|
2134
|
-
* Polls document.activeElement to detect iframe focus changes.
|
|
2135
|
-
* When iframe gains focus: emit immediately and start activity interval.
|
|
2136
|
-
* When iframe loses focus: stop activity interval.
|
|
2137
|
-
*/
|
|
2138
|
-
checkActiveElement() {
|
|
2139
|
-
const activeElement = document.activeElement;
|
|
2140
|
-
const iframeFocused = activeElement instanceof HTMLIFrameElement;
|
|
2141
|
-
if (iframeFocused && !this.isTrackingIframeActivity) {
|
|
2142
|
-
// Iframe just gained focus - emit immediately and start activity interval
|
|
2143
|
-
this.config?.onActivity();
|
|
2144
|
-
this.startActivityInterval();
|
|
2145
|
-
}
|
|
2146
|
-
else if (!iframeFocused && this.isTrackingIframeActivity) {
|
|
2147
|
-
// Focus left the iframe - stop activity interval
|
|
2148
|
-
this.stopActivityInterval();
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
/**
|
|
2152
|
-
* Handles visibility change events to pause/resume polling when tab visibility changes.
|
|
2153
|
-
*/
|
|
2154
|
-
handleVisibilityChange() {
|
|
2155
|
-
if (document.visibilityState === 'visible') {
|
|
2156
|
-
this.startPolling();
|
|
2157
|
-
}
|
|
2158
|
-
else {
|
|
2159
|
-
this.stopPolling();
|
|
2160
|
-
this.stopActivityInterval();
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
/**
|
|
2164
|
-
* Starts polling for active element changes.
|
|
2165
|
-
*/
|
|
2166
|
-
startPolling() {
|
|
2167
|
-
if (this.pollIntervalId) {
|
|
2168
|
-
return;
|
|
2169
|
-
}
|
|
2170
|
-
this.pollIntervalId = setInterval(() => this.checkActiveElement(), this.config.pollIntervalMs);
|
|
2171
|
-
}
|
|
2172
|
-
/**
|
|
2173
|
-
* Stops polling for active element changes.
|
|
2174
|
-
*/
|
|
2175
|
-
stopPolling() {
|
|
2176
|
-
if (this.pollIntervalId) {
|
|
2177
|
-
clearInterval(this.pollIntervalId);
|
|
2178
|
-
this.pollIntervalId = undefined;
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
/**
|
|
2182
|
-
* Starts the activity emission interval.
|
|
2183
|
-
*/
|
|
2184
|
-
startActivityInterval() {
|
|
2185
|
-
this.stopActivityInterval();
|
|
2186
|
-
this.activityIntervalId = setInterval(() => {
|
|
2187
|
-
this.config?.onActivity();
|
|
2188
|
-
}, this.config.activityIntervalMs);
|
|
2189
|
-
}
|
|
2190
|
-
/**
|
|
2191
|
-
* Stops the activity emission interval.
|
|
2192
|
-
*/
|
|
2193
|
-
stopActivityInterval() {
|
|
2194
|
-
if (this.activityIntervalId) {
|
|
2195
|
-
clearInterval(this.activityIntervalId);
|
|
2196
|
-
this.activityIntervalId = undefined;
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
/**
|
|
2200
|
-
* Starts tracking nested iframes within the document.
|
|
2201
|
-
* @param config Configuration for the tracker
|
|
2202
|
-
*/
|
|
2203
|
-
start(config) {
|
|
2204
|
-
if (this.started) {
|
|
2205
|
-
return;
|
|
2206
|
-
}
|
|
2207
|
-
this.config = config;
|
|
2208
|
-
// Listen for visibility changes to pause/resume polling
|
|
2209
|
-
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
2210
|
-
// Only start polling if document is currently visible
|
|
2211
|
-
if (document.visibilityState === 'visible') {
|
|
2212
|
-
this.startPolling();
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
/**
|
|
2216
|
-
* Stops tracking nested iframes and cleans up resources.
|
|
2217
|
-
*/
|
|
2218
|
-
stop() {
|
|
2219
|
-
if (!this.started) {
|
|
2220
|
-
return;
|
|
2221
|
-
}
|
|
2222
|
-
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
2223
|
-
this.stopPolling();
|
|
2224
|
-
this.stopActivityInterval();
|
|
2225
|
-
this.config = undefined;
|
|
2226
|
-
}
|
|
2227
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: IframeActivityTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2228
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: IframeActivityTrackerService, providedIn: 'root' }); }
|
|
2229
|
-
}
|
|
2230
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: IframeActivityTrackerService, decorators: [{
|
|
2231
|
-
type: Injectable,
|
|
2232
|
-
args: [{
|
|
2233
|
-
providedIn: 'root'
|
|
2234
|
-
}]
|
|
2235
|
-
}] });
|
|
2236
|
-
|
|
2237
|
-
/**
|
|
2238
|
-
* Generic service that tracks user activity and sends messages.
|
|
2239
|
-
* Can be configured for different contexts (cockpit or modules) via start() method parameter.
|
|
2240
|
-
*/
|
|
2241
|
-
class ActivityProducerService {
|
|
2242
|
-
constructor() {
|
|
2243
|
-
this.messageService = inject(MessagePeerService);
|
|
2244
|
-
this.destroyRef = inject(DestroyRef);
|
|
2245
|
-
this.iframeActivityTracker = inject(IframeActivityTrackerService);
|
|
2246
|
-
this.logger = inject(LoggerService);
|
|
2247
|
-
/**
|
|
2248
|
-
* Timestamp of the last sent activity message
|
|
2249
|
-
*/
|
|
2250
|
-
this.lastSentTimestamp = 0;
|
|
2251
|
-
/**
|
|
2252
|
-
* Bound event listeners for cleanup
|
|
2253
|
-
*/
|
|
2254
|
-
this.boundListeners = new Map();
|
|
2255
|
-
/**
|
|
2256
|
-
* Last emission timestamps for throttled high-frequency events
|
|
2257
|
-
*/
|
|
2258
|
-
this.lastEmitTimestamps = new Map();
|
|
2259
|
-
/**
|
|
2260
|
-
* Whether the service has been started
|
|
2261
|
-
*/
|
|
2262
|
-
this.started = false;
|
|
2263
|
-
/**
|
|
2264
|
-
* Signal that emits local activity information.
|
|
2265
|
-
* This allows consumers to react to activity detected by this producer.
|
|
2266
|
-
*/
|
|
2267
|
-
this.localActivityWritable = signal(undefined, /* @ts-ignore */
|
|
2268
|
-
...(ngDevMode ? [{ debugName: "localActivityWritable" }] : /* istanbul ignore next */ []));
|
|
2269
|
-
/**
|
|
2270
|
-
* Read-only signal containing the latest local activity info.
|
|
2271
|
-
* Use this signal to react to locally detected activity.
|
|
2272
|
-
*/
|
|
2273
|
-
this.localActivity = this.localActivityWritable.asReadonly();
|
|
2274
|
-
/**
|
|
2275
|
-
* @inheritdoc
|
|
2276
|
-
*/
|
|
2277
|
-
this.types = USER_ACTIVITY_MESSAGE_TYPE;
|
|
2278
|
-
registerProducer(this);
|
|
2279
|
-
this.destroyRef.onDestroy(() => this.stop());
|
|
2280
|
-
}
|
|
2281
|
-
/**
|
|
2282
|
-
* Checks if a high-frequency event should be processed based on throttle timing.
|
|
2283
|
-
* This is called before shouldBroadcast to avoid expensive filter operations on every event.
|
|
2284
|
-
* @param eventType The type of activity event
|
|
2285
|
-
* @param throttleMs The throttle interval in milliseconds
|
|
2286
|
-
* @returns true if the event should be processed, false if it should be skipped
|
|
2287
|
-
*/
|
|
2288
|
-
shouldProcessHighFrequencyEvent(eventType, throttleMs) {
|
|
2289
|
-
const now = Date.now();
|
|
2290
|
-
const lastEmit = this.lastEmitTimestamps.get(eventType) ?? 0;
|
|
2291
|
-
if (now - lastEmit >= throttleMs) {
|
|
2292
|
-
this.lastEmitTimestamps.set(eventType, now);
|
|
2293
|
-
return true;
|
|
2294
|
-
}
|
|
2295
|
-
return false;
|
|
2296
|
-
}
|
|
2297
|
-
/**
|
|
2298
|
-
* Handles activity by sending a throttled message and emitting to local signal.
|
|
2299
|
-
* @param eventType The type of activity event that occurred
|
|
2300
|
-
* @param configObject
|
|
2301
|
-
*/
|
|
2302
|
-
onActivity(eventType, configObject) {
|
|
2303
|
-
const now = Date.now();
|
|
2304
|
-
// Always emit local activity signal (not throttled for local detection)
|
|
2305
|
-
this.localActivityWritable.set({
|
|
2306
|
-
channelId: 'local',
|
|
2307
|
-
eventType,
|
|
2308
|
-
timestamp: now
|
|
2309
|
-
});
|
|
2310
|
-
// Send message with throttling
|
|
2311
|
-
if (now - this.lastSentTimestamp >= configObject.throttleMs) {
|
|
2312
|
-
this.lastSentTimestamp = now;
|
|
2313
|
-
this.sendActivityMessage(eventType, now);
|
|
2314
|
-
}
|
|
2315
|
-
}
|
|
2316
|
-
/**
|
|
2317
|
-
* Sends an activity message.
|
|
2318
|
-
* @param eventType The type of activity event
|
|
2319
|
-
* @param timestamp The timestamp of the event
|
|
2320
|
-
*/
|
|
2321
|
-
sendActivityMessage(eventType, timestamp) {
|
|
2322
|
-
const message = {
|
|
2323
|
-
type: USER_ACTIVITY_MESSAGE_TYPE,
|
|
2324
|
-
version: '1.0',
|
|
2325
|
-
eventType,
|
|
2326
|
-
timestamp
|
|
2327
|
-
};
|
|
2328
|
-
const registeredPeersIdsForUserActivity = [...this.messageService.knownPeers.entries()]
|
|
2329
|
-
.filter(([peerId]) => peerId !== this.messageService.id)
|
|
2330
|
-
.filter(([, messages]) => messages.some((msg) => msg.type === USER_ACTIVITY_MESSAGE_TYPE))
|
|
2331
|
-
.map((peer) => peer[0]);
|
|
2332
|
-
// send messages to the peers waiting for user activity
|
|
2333
|
-
// avoids sending the message to modules which are not using it
|
|
2334
|
-
if (registeredPeersIdsForUserActivity.length > 0) {
|
|
2335
|
-
this.messageService.send(message, { to: registeredPeersIdsForUserActivity });
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
/**
|
|
2339
|
-
* @inheritdoc
|
|
2340
|
-
*/
|
|
2341
|
-
handleError(message) {
|
|
2342
|
-
this.logger.error('Error in user activity service message', message);
|
|
2343
|
-
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Starts observing user activity events.
|
|
2346
|
-
* When activity is detected, it sends a throttled message.
|
|
2347
|
-
* Event listeners are attached after the next render to ensure DOM is ready.
|
|
2348
|
-
* @param config Configuration for the activity producer
|
|
2349
|
-
*/
|
|
2350
|
-
start(config) {
|
|
2351
|
-
if (this.started) {
|
|
2352
|
-
return;
|
|
2353
|
-
}
|
|
2354
|
-
this.started = true;
|
|
2355
|
-
const configObject = { ...DEFAULT_ACTIVITY_PRODUCER_CONFIG, ...config };
|
|
2356
|
-
// Always use afterNextRender to ensure DOM is ready in all contexts
|
|
2357
|
-
afterNextRender(() => {
|
|
2358
|
-
ACTIVITY_EVENTS.forEach((eventType) => {
|
|
2359
|
-
const isHighFrequency = HIGH_FREQUENCY_EVENTS.includes(eventType);
|
|
2360
|
-
const listener = (event) => {
|
|
2361
|
-
// do nothing if the event is a key kept pressed
|
|
2362
|
-
if (eventType === 'keydown' && event instanceof KeyboardEvent && event.repeat) {
|
|
2363
|
-
return;
|
|
2364
|
-
}
|
|
2365
|
-
// For high-frequency events, apply throttle BEFORE shouldBroadcast
|
|
2366
|
-
// to avoid expensive filter operations on every event (e.g. reflows)
|
|
2367
|
-
if (isHighFrequency && !this.shouldProcessHighFrequencyEvent(eventType, configObject.highFrequencyThrottleMs)) {
|
|
2368
|
-
return;
|
|
2369
|
-
}
|
|
2370
|
-
// Apply filter if provided
|
|
2371
|
-
if (configObject.shouldBroadcast?.(event) === false) {
|
|
2372
|
-
return;
|
|
2373
|
-
}
|
|
2374
|
-
this.onActivity(eventType, configObject);
|
|
2375
|
-
};
|
|
2376
|
-
this.boundListeners.set(eventType, listener);
|
|
2377
|
-
document.addEventListener(eventType, listener, { passive: true, capture: true });
|
|
2378
|
-
});
|
|
2379
|
-
// Also listen for visibility changes
|
|
2380
|
-
const visibilityListener = () => {
|
|
2381
|
-
if (document.visibilityState === 'visible') {
|
|
2382
|
-
this.onActivity(VISIBILITY_CHANGE_EVENT, configObject);
|
|
2383
|
-
}
|
|
2384
|
-
};
|
|
2385
|
-
this.boundListeners.set(VISIBILITY_CHANGE_EVENT, visibilityListener);
|
|
2386
|
-
document.addEventListener(VISIBILITY_CHANGE_EVENT, visibilityListener, { passive: true, capture: true });
|
|
2387
|
-
// Set up nested iframe tracking if enabled
|
|
2388
|
-
if (configObject.trackNestedIframes) {
|
|
2389
|
-
this.iframeActivityTracker.start({
|
|
2390
|
-
pollIntervalMs: configObject.nestedIframePollIntervalMs,
|
|
2391
|
-
activityIntervalMs: configObject.nestedIframeActivityEmitIntervalMs,
|
|
2392
|
-
onActivity: () => this.onActivity(IFRAME_INTERACTION_EVENT, configObject)
|
|
2393
|
-
});
|
|
2394
|
-
}
|
|
2395
|
-
});
|
|
2396
|
-
}
|
|
2397
|
-
/**
|
|
2398
|
-
* Stops observing user activity events.
|
|
2399
|
-
*/
|
|
2400
|
-
stop() {
|
|
2401
|
-
this.boundListeners.forEach((listener, eventType) => {
|
|
2402
|
-
document.removeEventListener(eventType, listener, { capture: true });
|
|
2403
|
-
});
|
|
2404
|
-
this.boundListeners.clear();
|
|
2405
|
-
this.lastEmitTimestamps.clear();
|
|
2406
|
-
this.iframeActivityTracker.stop();
|
|
2407
|
-
}
|
|
2408
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityProducerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2409
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityProducerService, providedIn: 'root' }); }
|
|
2410
|
-
}
|
|
2411
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityProducerService, decorators: [{
|
|
2412
|
-
type: Injectable,
|
|
2413
|
-
args: [{
|
|
2414
|
-
providedIn: 'root'
|
|
2415
|
-
}]
|
|
2416
|
-
}], ctorParameters: () => [] });
|
|
2417
|
-
|
|
2418
|
-
/**
|
|
2419
|
-
* Generic service that consumes user activity messages.
|
|
2420
|
-
* Can be used in both shell (to receive from modules) and modules (to receive from shell).
|
|
2421
|
-
*/
|
|
2422
|
-
class ActivityConsumerService {
|
|
2423
|
-
constructor() {
|
|
2424
|
-
this.consumerManagerService = inject(ConsumerManagerService);
|
|
2425
|
-
/**
|
|
2426
|
-
* Signal containing the latest activity info
|
|
2427
|
-
*/
|
|
2428
|
-
this.latestReceivedActivityWritable = signal(undefined, /* @ts-ignore */
|
|
2429
|
-
...(ngDevMode ? [{ debugName: "latestReceivedActivityWritable" }] : /* istanbul ignore next */ []));
|
|
2430
|
-
/**
|
|
2431
|
-
* Read-only signal containing the latest activity info received from other peers via the message protocol.
|
|
2432
|
-
* Access the timestamp via latestReceivedActivity()?.timestamp
|
|
2433
|
-
*/
|
|
2434
|
-
this.latestReceivedActivity = this.latestReceivedActivityWritable.asReadonly();
|
|
2435
|
-
/**
|
|
2436
|
-
* @inheritdoc
|
|
2437
|
-
*/
|
|
2438
|
-
this.type = USER_ACTIVITY_MESSAGE_TYPE;
|
|
2439
|
-
/**
|
|
2440
|
-
* @inheritdoc
|
|
2441
|
-
*/
|
|
2442
|
-
this.supportedVersions = {
|
|
2443
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention -- Version keys follow message versioning convention
|
|
2444
|
-
'1.0': (message) => {
|
|
2445
|
-
this.latestReceivedActivityWritable.set({
|
|
2446
|
-
channelId: message.from || 'unknown',
|
|
2447
|
-
eventType: message.payload.eventType,
|
|
2448
|
-
timestamp: message.payload.timestamp
|
|
2449
|
-
});
|
|
2450
|
-
}
|
|
2451
|
-
};
|
|
2452
|
-
}
|
|
2453
|
-
/**
|
|
2454
|
-
* Starts the activity consumer service by registering it with the consumer manager.
|
|
2455
|
-
*/
|
|
2456
|
-
start() {
|
|
2457
|
-
this.consumerManagerService.register(this);
|
|
2458
|
-
}
|
|
2459
|
-
/**
|
|
2460
|
-
* Stops the activity consumer service by unregistering it from the consumer manager.
|
|
2461
|
-
*/
|
|
2462
|
-
stop() {
|
|
2463
|
-
this.consumerManagerService.unregister(this);
|
|
2464
|
-
}
|
|
2465
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityConsumerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2466
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityConsumerService, providedIn: 'root' }); }
|
|
2467
|
-
}
|
|
2468
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityConsumerService, decorators: [{
|
|
2469
|
-
type: Injectable,
|
|
2470
|
-
args: [{
|
|
2471
|
-
providedIn: 'root'
|
|
2472
|
-
}]
|
|
2473
|
-
}] });
|
|
2474
|
-
|
|
2475
|
-
/**
|
|
2476
|
-
* Generated bundle index. Do not edit.
|
|
2477
|
-
*/
|
|
2478
|
-
|
|
2479
|
-
export { ACTIVITY_EVENTS, AbstractMessageConsumer, ActivityConsumerService, ActivityProducerService, ApplyTheme, BrowserConfirmationStrategy, ConnectDirective, ConsumerManagerService, DEFAULT_ACTIVITY_PRODUCER_CONFIG, ERROR_MESSAGE_TYPE, HIGH_FREQUENCY_EVENTS, HistoryConsumerService, HostInfoPipe, IFRAME_INTERACTION_EVENT, IframeActivityTrackerService, IframeEmbedComponent, KNOWN_MESSAGES, MFE_HOST_APPLICATION_ID_PARAM, MFE_HOST_URL_PARAM, MFE_MODULE_APPLICATION_ID_PARAM, NAVIGATION_BLOCK_CONFIRMATION, NAVIGATION_REQUEST_HANDLER, NavigationBlockConfirmationService, NavigationBlockService, NavigationBlockStateConsumerService, NavigationBlockStateProducerService, NavigationConsumerService, NavigationDecisionConsumerService, NavigationRequestConsumerService, NavigationRequestManagerService, ProducerManagerService, ResizeConsumerService, ResizeService, RestoreRoute, RouteMemorizeDirective, RouteMemorizeService, RoutingService, ScalableDirective, THEME_QUERY_PARAM_NAME, THEME_URL_SUFFIX, ThemeConsumerService, ThemeProducerService, VISIBILITY_CHANGE_EVENT, applyInitialTheme, applyTheme, createNavigationRequestHandler, createNavigationRequestShellHandler, downloadApplicationThemeCss, generateCorrelationId, getAvailableConsumers, getDefaultClientEndpointStartOptions, getHostInfo, getStyle, hostQueryParams, isEmbedded, isErrorMessage, isUserActivityMessage, navigationBlockModuleGuard, navigationBlockShellGuard, persistHostInfo, provideConnection, provideDefaultNavigationBlockConfirmation, provideHistoryOverrides, provideNavigationRequestModuleHandler, provideNavigationRequestShellHandler, registerConsumer, registerProducer, sendError };
|
|
2480
|
-
//# sourceMappingURL=ama-mfe-ng-utils.mjs.map
|
|
2385
|
+
//# sourceMappingURL=ama-mfe-ng-utils.mjs.map
|