@siemens/live-preview 51.6.0 → 51.8.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/assets/angular/package.json +12 -12
- package/component-loader.cjs +2 -2
- package/elements/package.json +4 -0
- package/fesm2022/siemens-live-preview-elements.mjs +21 -0
- package/fesm2022/siemens-live-preview-elements.mjs.map +1 -0
- package/fesm2022/siemens-live-preview-si-example-editor.component-DSxapfeC.mjs +28 -0
- package/fesm2022/siemens-live-preview-si-example-editor.component-DSxapfeC.mjs.map +1 -0
- package/fesm2022/siemens-live-preview-si-example-overview.component-Co4tIhL5.mjs +107 -0
- package/fesm2022/siemens-live-preview-si-example-overview.component-Co4tIhL5.mjs.map +1 -0
- package/fesm2022/siemens-live-preview-si-live-preview.component-BkiFwumB.mjs +1123 -0
- package/fesm2022/siemens-live-preview-si-live-preview.component-BkiFwumB.mjs.map +1 -0
- package/fesm2022/siemens-live-preview-siemens-live-preview-BU--ZYJz.mjs +1579 -0
- package/fesm2022/siemens-live-preview-siemens-live-preview-BU--ZYJz.mjs.map +1 -0
- package/fesm2022/siemens-live-preview.mjs +1 -2536
- package/fesm2022/siemens-live-preview.mjs.map +1 -1
- package/package.json +12 -2
- package/styles/_variables.scss +4 -3
- package/types/siemens-live-preview-elements.d.ts +11 -0
- package/types/siemens-live-preview.d.ts +133 -37
|
@@ -0,0 +1,1579 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, ChangeDetectorRef, ChangeDetectionStrategy, Component, InjectionToken, computed, signal, effect, Service, DestroyRef, input, output, Injectable, Directive, viewChild, ViewContainerRef, ElementRef, Compiler, Injector, untracked, afterNextRender, ɵcompileComponent as _compileComponent, ɵresetCompiledComponents as _resetCompiledComponents, inputBinding, NgZone, NgModule, ErrorHandler, createComponent, makeEnvironmentProviders, DOCUMENT, numberAttribute, ViewEncapsulation } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/router';
|
|
4
|
+
import { ActivatedRoute, Router, RouterModule, provideRouter, withDisabledInitialNavigation, withHashLocation } from '@angular/router';
|
|
5
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
6
|
+
import { __decorate } from 'tslib';
|
|
7
|
+
import { ɵDomRendererFactory2 as _DomRendererFactory2, createApplication, REMOVE_STYLES_ON_COMPONENT_DESTROY } from '@angular/platform-browser';
|
|
8
|
+
import { fromEvent } from 'rxjs';
|
|
9
|
+
import { LocationStrategy, Location } from '@angular/common';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
13
|
+
* SPDX-License-Identifier: MIT
|
|
14
|
+
*/
|
|
15
|
+
class SiDummyComponent {
|
|
16
|
+
path = '';
|
|
17
|
+
activeRoute = inject(ActivatedRoute);
|
|
18
|
+
cdRef = inject(ChangeDetectorRef);
|
|
19
|
+
constructor() {
|
|
20
|
+
this.activeRoute.url.subscribe(url => {
|
|
21
|
+
this.path = url.toString();
|
|
22
|
+
this.cdRef.markForCheck();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDummyComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
26
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.8", type: SiDummyComponent, isStandalone: true, selector: "si-dummy", ngImport: i0, template: `<div class="ion-padding"> Content with path '{{ path }}'</div>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
27
|
+
}
|
|
28
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDummyComponent, decorators: [{
|
|
29
|
+
type: Component,
|
|
30
|
+
args: [{
|
|
31
|
+
selector: 'si-dummy',
|
|
32
|
+
template: `<div class="ion-padding"> Content with path '{{ path }}'</div>`,
|
|
33
|
+
changeDetection: ChangeDetectionStrategy.Eager
|
|
34
|
+
}]
|
|
35
|
+
}], ctorParameters: () => [] });
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
39
|
+
* SPDX-License-Identifier: MIT
|
|
40
|
+
*/
|
|
41
|
+
const SI_LIVE_PREVIEW_CONFIG = new InjectionToken('SI_LIVE_PREVIEW_CONFIG');
|
|
42
|
+
const SI_LIVE_PREVIEW_INTERNALS = new InjectionToken('SI_LIVE_PREVIEW_INTERNALS');
|
|
43
|
+
const SI_LIVE_PREVIEW_EXAMPLE_ROUTES = new InjectionToken('SI_LIVE_PREVIEW_EXAMPLE_ROUTES');
|
|
44
|
+
|
|
45
|
+
const setDeviceMode = (mode) => {
|
|
46
|
+
const htmlTag = document.documentElement;
|
|
47
|
+
htmlTag.setAttribute('mode', mode);
|
|
48
|
+
htmlTag.classList.add(mode);
|
|
49
|
+
htmlTag.classList.remove(mode === 'ios' ? 'md' : 'ios');
|
|
50
|
+
};
|
|
51
|
+
const setDirectionRtl = (rtl) => {
|
|
52
|
+
document.documentElement.setAttribute('dir', rtl ? 'rtl' : 'ltr');
|
|
53
|
+
};
|
|
54
|
+
const setRootFontSize = (rfs) => {
|
|
55
|
+
const htmlTag = document.documentElement;
|
|
56
|
+
if (!rfs) {
|
|
57
|
+
htmlTag.style.removeProperty('font-size');
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
htmlTag.style.setProperty('font-size', rfs === 'initial' ? rfs : rfs + 'px');
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const provideExampleRoutes = (routes) => {
|
|
64
|
+
return {
|
|
65
|
+
provide: SI_LIVE_PREVIEW_EXAMPLE_ROUTES,
|
|
66
|
+
useValue: routes
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
class SiLivePreviewThemeApi {
|
|
71
|
+
}
|
|
72
|
+
class SiLivePreviewLocaleApi {
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
77
|
+
* SPDX-License-Identifier: MIT
|
|
78
|
+
*/
|
|
79
|
+
class LivePreviewStateService {
|
|
80
|
+
router = inject(Router, { optional: true });
|
|
81
|
+
overviewExample = computed(() => {
|
|
82
|
+
this.router?.lastSuccessfulNavigation();
|
|
83
|
+
const route = this.router && this.findOverviewRoute(this.router.routerState.root);
|
|
84
|
+
return this.getOverviewExample(route?.snapshot.url ?? []);
|
|
85
|
+
}, /* @ts-ignore */
|
|
86
|
+
...(ngDevMode ? [{ debugName: "overviewExample" }] : /* istanbul ignore next */ []));
|
|
87
|
+
delayedLogClearTimer;
|
|
88
|
+
example = signal('', /* @ts-ignore */
|
|
89
|
+
...(ngDevMode ? [{ debugName: "example" }] : /* istanbul ignore next */ []));
|
|
90
|
+
dataId = signal('', /* @ts-ignore */
|
|
91
|
+
...(ngDevMode ? [{ debugName: "dataId" }] : /* istanbul ignore next */ []));
|
|
92
|
+
template = signal('', /* @ts-ignore */
|
|
93
|
+
...(ngDevMode ? [{ debugName: "template" }] : /* istanbul ignore next */ []));
|
|
94
|
+
templateReact = signal('', /* @ts-ignore */
|
|
95
|
+
...(ngDevMode ? [{ debugName: "templateReact" }] : /* istanbul ignore next */ []));
|
|
96
|
+
templateVue = signal('', /* @ts-ignore */
|
|
97
|
+
...(ngDevMode ? [{ debugName: "templateVue" }] : /* istanbul ignore next */ []));
|
|
98
|
+
templateJs = signal('', /* @ts-ignore */
|
|
99
|
+
...(ngDevMode ? [{ debugName: "templateJs" }] : /* istanbul ignore next */ []));
|
|
100
|
+
originalTemplate = signal('', /* @ts-ignore */
|
|
101
|
+
...(ngDevMode ? [{ debugName: "originalTemplate" }] : /* istanbul ignore next */ []));
|
|
102
|
+
theme = signal('light', /* @ts-ignore */
|
|
103
|
+
...(ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []));
|
|
104
|
+
locale = signal(undefined, /* @ts-ignore */
|
|
105
|
+
...(ngDevMode ? [{ debugName: "locale" }] : /* istanbul ignore next */ []));
|
|
106
|
+
isRTL = signal(false, /* @ts-ignore */
|
|
107
|
+
...(ngDevMode ? [{ debugName: "isRTL" }] : /* istanbul ignore next */ []));
|
|
108
|
+
rootFontSize = signal(0, /* @ts-ignore */
|
|
109
|
+
...(ngDevMode ? [{ debugName: "rootFontSize" }] : /* istanbul ignore next */ []));
|
|
110
|
+
framework = signal('angular', /* @ts-ignore */
|
|
111
|
+
...(ngDevMode ? [{ debugName: "framework" }] : /* istanbul ignore next */ []));
|
|
112
|
+
loadReact = signal(false, /* @ts-ignore */
|
|
113
|
+
...(ngDevMode ? [{ debugName: "loadReact" }] : /* istanbul ignore next */ []));
|
|
114
|
+
loadVue = signal(false, /* @ts-ignore */
|
|
115
|
+
...(ngDevMode ? [{ debugName: "loadVue" }] : /* istanbul ignore next */ []));
|
|
116
|
+
loadJs = signal(false, /* @ts-ignore */
|
|
117
|
+
...(ngDevMode ? [{ debugName: "loadJs" }] : /* istanbul ignore next */ []));
|
|
118
|
+
supportsLandscape = signal(false, /* @ts-ignore */
|
|
119
|
+
...(ngDevMode ? [{ debugName: "supportsLandscape" }] : /* istanbul ignore next */ []));
|
|
120
|
+
viewport = signal({ mode: 'ios' }, /* @ts-ignore */
|
|
121
|
+
...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
|
|
122
|
+
iFrameHeight = signal(undefined, /* @ts-ignore */
|
|
123
|
+
...(ngDevMode ? [{ debugName: "iFrameHeight" }] : /* istanbul ignore next */ []));
|
|
124
|
+
iFrameWidth = signal(undefined, /* @ts-ignore */
|
|
125
|
+
...(ngDevMode ? [{ debugName: "iFrameWidth" }] : /* istanbul ignore next */ []));
|
|
126
|
+
renderingError = signal(undefined, /* @ts-ignore */
|
|
127
|
+
...(ngDevMode ? [{ debugName: "renderingError" }] : /* istanbul ignore next */ []));
|
|
128
|
+
logMessages = signal([], /* @ts-ignore */
|
|
129
|
+
...(ngDevMode ? [{ debugName: "logMessages" }] : /* istanbul ignore next */ []));
|
|
130
|
+
newMessages = signal(false, /* @ts-ignore */
|
|
131
|
+
...(ngDevMode ? [{ debugName: "newMessages" }] : /* istanbul ignore next */ []));
|
|
132
|
+
pendingOperations = signal(0, /* @ts-ignore */
|
|
133
|
+
...(ngDevMode ? [{ debugName: "pendingOperations" }] : /* istanbul ignore next */ []));
|
|
134
|
+
inProgress = computed(() => this.pendingOperations() > 0, /* @ts-ignore */
|
|
135
|
+
...(ngDevMode ? [{ debugName: "inProgress" }] : /* istanbul ignore next */ []));
|
|
136
|
+
templateModified = computed(() => this.originalTemplate() !== this.template(), /* @ts-ignore */
|
|
137
|
+
...(ngDevMode ? [{ debugName: "templateModified" }] : /* istanbul ignore next */ []));
|
|
138
|
+
activeWebComponentTemplate = computed(() => {
|
|
139
|
+
switch (this.framework()) {
|
|
140
|
+
case 'react':
|
|
141
|
+
return this.templateReact();
|
|
142
|
+
case 'vue':
|
|
143
|
+
return this.templateVue();
|
|
144
|
+
case 'js':
|
|
145
|
+
return this.templateJs();
|
|
146
|
+
default:
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
}, /* @ts-ignore */
|
|
150
|
+
...(ngDevMode ? [{ debugName: "activeWebComponentTemplate" }] : /* istanbul ignore next */ []));
|
|
151
|
+
constructor() {
|
|
152
|
+
effect(() => {
|
|
153
|
+
const example = this.overviewExample();
|
|
154
|
+
if (example !== undefined) {
|
|
155
|
+
this.clearTemplates();
|
|
156
|
+
this.example.set(example);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
findOverviewRoute(route) {
|
|
161
|
+
if (route.routeConfig?.path === 'overview') {
|
|
162
|
+
let activeRoute = route;
|
|
163
|
+
while (activeRoute.firstChild) {
|
|
164
|
+
activeRoute = activeRoute.firstChild;
|
|
165
|
+
}
|
|
166
|
+
return activeRoute;
|
|
167
|
+
}
|
|
168
|
+
for (const child of route.children) {
|
|
169
|
+
const overviewRoute = this.findOverviewRoute(child);
|
|
170
|
+
if (overviewRoute) {
|
|
171
|
+
return overviewRoute;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
getOverviewExample(segments) {
|
|
177
|
+
return segments.length ? segments.join('/') : undefined;
|
|
178
|
+
}
|
|
179
|
+
setFramework(framework) {
|
|
180
|
+
this.framework.set(framework);
|
|
181
|
+
this.loadReact.set(framework === 'react');
|
|
182
|
+
this.loadVue.set(framework === 'vue');
|
|
183
|
+
this.loadJs.set(framework === 'js');
|
|
184
|
+
}
|
|
185
|
+
applyRenderRequest(request) {
|
|
186
|
+
this.example.set(request.exampleUrl);
|
|
187
|
+
this.template.set(request.template);
|
|
188
|
+
this.loadReact.set(request.loadReact);
|
|
189
|
+
this.loadVue.set(request.loadVue);
|
|
190
|
+
this.loadJs.set(request.loadJs);
|
|
191
|
+
if (request.loadReact) {
|
|
192
|
+
this.framework.set('react');
|
|
193
|
+
this.templateReact.set(request.reactVueTemplate);
|
|
194
|
+
}
|
|
195
|
+
else if (request.loadVue) {
|
|
196
|
+
this.framework.set('vue');
|
|
197
|
+
this.templateVue.set(request.reactVueTemplate);
|
|
198
|
+
}
|
|
199
|
+
else if (request.loadJs) {
|
|
200
|
+
this.framework.set('js');
|
|
201
|
+
this.templateJs.set(request.reactVueTemplate);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
this.framework.set('angular');
|
|
205
|
+
}
|
|
206
|
+
this.viewport.set({
|
|
207
|
+
mode: request.mode,
|
|
208
|
+
safeAreaTop: request.safeAreaTop,
|
|
209
|
+
safeAreaBottom: request.safeAreaBottom,
|
|
210
|
+
safeAreaLeft: request.safeAreaLeft,
|
|
211
|
+
safeAreaRight: request.safeAreaRight
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
stopWebComponentLoading() {
|
|
215
|
+
this.loadReact.set(false);
|
|
216
|
+
this.loadVue.set(false);
|
|
217
|
+
this.loadJs.set(false);
|
|
218
|
+
}
|
|
219
|
+
clearTemplates() {
|
|
220
|
+
this.template.set('');
|
|
221
|
+
this.templateReact.set('');
|
|
222
|
+
this.templateVue.set('');
|
|
223
|
+
this.templateJs.set('');
|
|
224
|
+
this.originalTemplate.set('');
|
|
225
|
+
}
|
|
226
|
+
toggleTheme() {
|
|
227
|
+
this.theme.update(theme => (theme === 'dark' ? 'light' : 'dark'));
|
|
228
|
+
}
|
|
229
|
+
setRenderingProgress(inProgress) {
|
|
230
|
+
this.pendingOperations.update(count => Math.max(0, count + (inProgress ? 1 : -1)));
|
|
231
|
+
}
|
|
232
|
+
resetRenderingProgress() {
|
|
233
|
+
this.pendingOperations.set(0);
|
|
234
|
+
}
|
|
235
|
+
addLog(message) {
|
|
236
|
+
if (this.delayedLogClearTimer) {
|
|
237
|
+
clearTimeout(this.delayedLogClearTimer);
|
|
238
|
+
this.delayedLogClearTimer = undefined;
|
|
239
|
+
this.logMessages.set([]);
|
|
240
|
+
}
|
|
241
|
+
this.logMessages.update(messages => [...messages, message]);
|
|
242
|
+
this.newMessages.set(true);
|
|
243
|
+
}
|
|
244
|
+
clearLogs(delayed = false) {
|
|
245
|
+
if (delayed && this.logMessages().length) {
|
|
246
|
+
this.delayedLogClearTimer = setTimeout(() => {
|
|
247
|
+
this.delayedLogClearTimer = undefined;
|
|
248
|
+
this.logMessages.set([]);
|
|
249
|
+
}, 100);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.logMessages.set([]);
|
|
253
|
+
}
|
|
254
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LivePreviewStateService, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
255
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.0.8", ngImport: i0, type: LivePreviewStateService });
|
|
256
|
+
}
|
|
257
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LivePreviewStateService, decorators: [{
|
|
258
|
+
type: Service
|
|
259
|
+
}], ctorParameters: () => [] });
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
263
|
+
* SPDX-License-Identifier: MIT
|
|
264
|
+
*/
|
|
265
|
+
/** Shared URL handling, provided separately by each editor/viewer route component. */
|
|
266
|
+
class ExampleRouteController {
|
|
267
|
+
router = inject(Router);
|
|
268
|
+
route = inject(ActivatedRoute);
|
|
269
|
+
internalConfig = inject(SI_LIVE_PREVIEW_INTERNALS);
|
|
270
|
+
themeApi = inject(SiLivePreviewThemeApi, { optional: true });
|
|
271
|
+
localeApi = inject(SiLivePreviewLocaleApi, { optional: true });
|
|
272
|
+
state = inject(LivePreviewStateService);
|
|
273
|
+
destroyRef = inject(DestroyRef);
|
|
274
|
+
tabs = signal([], /* @ts-ignore */
|
|
275
|
+
...(ngDevMode ? [{ debugName: "tabs" }] : /* istanbul ignore next */ []));
|
|
276
|
+
hasTabs = computed(() => this.tabs().length > 1, /* @ts-ignore */
|
|
277
|
+
...(ngDevMode ? [{ debugName: "hasTabs" }] : /* istanbul ignore next */ []));
|
|
278
|
+
hasTabsMobile = computed(() => this.hasTabs() && this.internalConfig.isMobile, /* @ts-ignore */
|
|
279
|
+
...(ngDevMode ? [{ debugName: "hasTabsMobile" }] : /* istanbul ignore next */ []));
|
|
280
|
+
activeTabIndex = signal(0, /* @ts-ignore */
|
|
281
|
+
...(ngDevMode ? [{ debugName: "activeTabIndex" }] : /* istanbul ignore next */ []));
|
|
282
|
+
activeExample = computed(() => {
|
|
283
|
+
const tab = this.tabs()[this.activeTabIndex()];
|
|
284
|
+
return tab ? tab.base + tab.example : undefined;
|
|
285
|
+
}, /* @ts-ignore */
|
|
286
|
+
...(ngDevMode ? [{ debugName: "activeExample" }] : /* istanbul ignore next */ []));
|
|
287
|
+
context = 'viewer';
|
|
288
|
+
constructor() {
|
|
289
|
+
effect(() => {
|
|
290
|
+
const example = this.activeExample();
|
|
291
|
+
if (example !== undefined) {
|
|
292
|
+
this.state.example.set(example);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
initialize(context, recompile) {
|
|
297
|
+
this.context = context;
|
|
298
|
+
this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
|
|
299
|
+
if (this.handleQueryParams(params)) {
|
|
300
|
+
recompile?.();
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
handleQueryParams(params) {
|
|
305
|
+
let handled = false;
|
|
306
|
+
let recompile = false;
|
|
307
|
+
const base = params.base ? params.base + '/' : '';
|
|
308
|
+
if (params.e) {
|
|
309
|
+
const prevUrl = this.state.example();
|
|
310
|
+
const previousTemplate = this.state.template();
|
|
311
|
+
this.tabs.set([]);
|
|
312
|
+
this.activeTabIndex.set(0);
|
|
313
|
+
this.state.clearTemplates();
|
|
314
|
+
const examples = Array.isArray(params.e) ? params.e : [params.e];
|
|
315
|
+
examples.forEach(element => {
|
|
316
|
+
const parts = element.split(';');
|
|
317
|
+
this.tabs.update(t => [
|
|
318
|
+
...t,
|
|
319
|
+
{
|
|
320
|
+
heading: parts[1],
|
|
321
|
+
base,
|
|
322
|
+
example: parts[0]
|
|
323
|
+
}
|
|
324
|
+
]);
|
|
325
|
+
});
|
|
326
|
+
if (this.tabs().length) {
|
|
327
|
+
this.activateTab(0);
|
|
328
|
+
recompile = prevUrl === this.activeExample();
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
this.state.example.set('');
|
|
332
|
+
}
|
|
333
|
+
if (this.tabs().length <= 1 && params.t) {
|
|
334
|
+
if (params.framework === 'react') {
|
|
335
|
+
this.state.templateReact.set(params.t);
|
|
336
|
+
}
|
|
337
|
+
else if (params.framework === 'vue') {
|
|
338
|
+
this.state.templateVue.set(params.t);
|
|
339
|
+
}
|
|
340
|
+
else if (params.framework === 'js') {
|
|
341
|
+
this.state.templateJs.set(params.t);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
recompile = recompile || previousTemplate !== params.t;
|
|
345
|
+
this.state.template.set(params.t);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
handled = true;
|
|
349
|
+
}
|
|
350
|
+
if (params.theme) {
|
|
351
|
+
this.setTheme(params.theme);
|
|
352
|
+
handled = true;
|
|
353
|
+
}
|
|
354
|
+
if (params.locale) {
|
|
355
|
+
this.setLocale(params.locale);
|
|
356
|
+
handled = true;
|
|
357
|
+
}
|
|
358
|
+
if (params.rfs) {
|
|
359
|
+
setRootFontSize(params.rfs === 'initial' ? params.rfs : parseInt(params.rfs, 10));
|
|
360
|
+
}
|
|
361
|
+
if (params.isRTL) {
|
|
362
|
+
this.setRTL(params.isRTL);
|
|
363
|
+
handled = true;
|
|
364
|
+
}
|
|
365
|
+
if (params.mode && this.context !== 'editor') {
|
|
366
|
+
setDeviceMode(params.mode);
|
|
367
|
+
recompile = true;
|
|
368
|
+
handled = true;
|
|
369
|
+
}
|
|
370
|
+
if (handled) {
|
|
371
|
+
const { e, t, theme, mode, locale, isRTL, ...newParams } = params;
|
|
372
|
+
this.router.navigate([], { queryParams: newParams });
|
|
373
|
+
}
|
|
374
|
+
if (params.id) {
|
|
375
|
+
recompile = this.state.dataId() !== params.id;
|
|
376
|
+
this.state.dataId.set(params.id);
|
|
377
|
+
}
|
|
378
|
+
return recompile;
|
|
379
|
+
}
|
|
380
|
+
setUiTheme(theme) {
|
|
381
|
+
document.documentElement.classList.toggle('app--dark', theme === 'dark');
|
|
382
|
+
document.documentElement.classList.toggle('app--light', theme === 'light');
|
|
383
|
+
}
|
|
384
|
+
setTheme(theme) {
|
|
385
|
+
if (this.context === 'editor') {
|
|
386
|
+
this.state.theme.set(theme);
|
|
387
|
+
}
|
|
388
|
+
if (this.themeApi) {
|
|
389
|
+
this.themeApi.setThemeFromPreviewer(theme);
|
|
390
|
+
}
|
|
391
|
+
this.setUiTheme(theme);
|
|
392
|
+
}
|
|
393
|
+
setRTL(rtl) {
|
|
394
|
+
this.state.isRTL.set(rtl);
|
|
395
|
+
if (this.context !== 'editor') {
|
|
396
|
+
setDirectionRtl(rtl);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
setLocale(locale) {
|
|
400
|
+
if (this.context === 'editor') {
|
|
401
|
+
this.state.locale.set(locale);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (this.localeApi) {
|
|
405
|
+
this.localeApi.setLocale(locale);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
activateTab(index) {
|
|
409
|
+
if (index >= 0 && index < this.tabs().length) {
|
|
410
|
+
this.activeTabIndex.set(index);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: ExampleRouteController, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
414
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.0.8", ngImport: i0, type: ExampleRouteController });
|
|
415
|
+
}
|
|
416
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: ExampleRouteController, decorators: [{
|
|
417
|
+
type: Service
|
|
418
|
+
}], ctorParameters: () => [] });
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
422
|
+
* SPDX-License-Identifier: MIT
|
|
423
|
+
*/
|
|
424
|
+
class SiExampleHeaderComponent {
|
|
425
|
+
tabs = input.required(/* @ts-ignore */
|
|
426
|
+
...(ngDevMode ? [{ debugName: "tabs" }] : /* istanbul ignore next */ []));
|
|
427
|
+
activeTabIndex = input.required(/* @ts-ignore */
|
|
428
|
+
...(ngDevMode ? [{ debugName: "activeTabIndex" }] : /* istanbul ignore next */ []));
|
|
429
|
+
tabSelected = output();
|
|
430
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiExampleHeaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
431
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: SiExampleHeaderComponent, isStandalone: true, selector: "si-example-header", inputs: { tabs: { classPropertyName: "tabs", publicName: "tabs", isSignal: true, isRequired: true, transformFunction: null }, activeTabIndex: { classPropertyName: "activeTabIndex", publicName: "activeTabIndex", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { tabSelected: "tabSelected" }, ngImport: i0, template: `
|
|
432
|
+
<div class="wrapper">
|
|
433
|
+
<ng-content />
|
|
434
|
+
@if (tabs().length > 1) {
|
|
435
|
+
<div class="tab-wrapper">
|
|
436
|
+
<div role="tablist" aria-label="Examples" class="nav lp-tabs">
|
|
437
|
+
@for (tab of tabs(); track $index) {
|
|
438
|
+
<button
|
|
439
|
+
type="button"
|
|
440
|
+
role="tab"
|
|
441
|
+
class="tab-item tab-link focus-inside"
|
|
442
|
+
[class.tab-active]="activeTabIndex() === $index"
|
|
443
|
+
[attr.aria-selected]="activeTabIndex() === $index"
|
|
444
|
+
(click)="tabSelected.emit($index)"
|
|
445
|
+
>
|
|
446
|
+
{{ tab.heading }}
|
|
447
|
+
</button>
|
|
448
|
+
}
|
|
449
|
+
</div>
|
|
450
|
+
</div>
|
|
451
|
+
}
|
|
452
|
+
</div>
|
|
453
|
+
`, isInline: true, styles: [".lp-tabs{display:flex;flex-wrap:wrap;padding-inline-start:0;margin:0;list-style:none;background:none;inline-size:inherit;font-weight:700}.lp-tabs .tab-item:focus-visible{outline-offset:calc(-1 * var(--si-sys-sizing-focus-ring-width, 2px))}.lp-tabs .tab-item.tab-active.tab-link{color:var(--si-sys-color-text-accent);border-block-end-color:var(--si-sys-color-text-accent)!important}.lp-tabs .tab-item.tab-active.tab-link:hover{color:var(--si-sys-color-text-accent-hover)}.lp-tabs .tab-item.tab-link{font:inherit;background:none;min-inline-size:150px;display:block;padding-block:8px;padding-inline:15px;cursor:pointer;text-align:start;line-height:20px;color:var(--si-sys-color-text-primary);border:0;border-block-end:4px solid transparent}.lp-tabs .tab-item.tab-link:hover{text-decoration:none;color:var(--si-sys-color-text-accent-hover);border-block-end-color:var(--si-sys-color-border-4)}*:focus-visible{outline:var(--si-sys-sizing-focus-ring-width, 2px) solid var(--si-sys-color-effects-focus);outline-offset:var(--si-sys-sizing-focus-ring-offset, 1px)}.wrapper{background-color:var(--si-sys-color-background-0);color:var(--si-sys-color-text-primary)}:host-context(.has-tabs) .tab-wrapper{background-color:var(--si-sys-color-background-0)}:host-context(.has-tabs-mobile) .wrapper{background-color:var(--si-sys-color-background-0)}.tab-wrapper{margin-block-end:10px;border-block-end:1px solid var(--si-sys-color-border-4)}:host{display:contents}\n"] });
|
|
454
|
+
}
|
|
455
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiExampleHeaderComponent, decorators: [{
|
|
456
|
+
type: Component,
|
|
457
|
+
args: [{ selector: 'si-example-header', template: `
|
|
458
|
+
<div class="wrapper">
|
|
459
|
+
<ng-content />
|
|
460
|
+
@if (tabs().length > 1) {
|
|
461
|
+
<div class="tab-wrapper">
|
|
462
|
+
<div role="tablist" aria-label="Examples" class="nav lp-tabs">
|
|
463
|
+
@for (tab of tabs(); track $index) {
|
|
464
|
+
<button
|
|
465
|
+
type="button"
|
|
466
|
+
role="tab"
|
|
467
|
+
class="tab-item tab-link focus-inside"
|
|
468
|
+
[class.tab-active]="activeTabIndex() === $index"
|
|
469
|
+
[attr.aria-selected]="activeTabIndex() === $index"
|
|
470
|
+
(click)="tabSelected.emit($index)"
|
|
471
|
+
>
|
|
472
|
+
{{ tab.heading }}
|
|
473
|
+
</button>
|
|
474
|
+
}
|
|
475
|
+
</div>
|
|
476
|
+
</div>
|
|
477
|
+
}
|
|
478
|
+
</div>
|
|
479
|
+
`, styles: [".lp-tabs{display:flex;flex-wrap:wrap;padding-inline-start:0;margin:0;list-style:none;background:none;inline-size:inherit;font-weight:700}.lp-tabs .tab-item:focus-visible{outline-offset:calc(-1 * var(--si-sys-sizing-focus-ring-width, 2px))}.lp-tabs .tab-item.tab-active.tab-link{color:var(--si-sys-color-text-accent);border-block-end-color:var(--si-sys-color-text-accent)!important}.lp-tabs .tab-item.tab-active.tab-link:hover{color:var(--si-sys-color-text-accent-hover)}.lp-tabs .tab-item.tab-link{font:inherit;background:none;min-inline-size:150px;display:block;padding-block:8px;padding-inline:15px;cursor:pointer;text-align:start;line-height:20px;color:var(--si-sys-color-text-primary);border:0;border-block-end:4px solid transparent}.lp-tabs .tab-item.tab-link:hover{text-decoration:none;color:var(--si-sys-color-text-accent-hover);border-block-end-color:var(--si-sys-color-border-4)}*:focus-visible{outline:var(--si-sys-sizing-focus-ring-width, 2px) solid var(--si-sys-color-effects-focus);outline-offset:var(--si-sys-sizing-focus-ring-offset, 1px)}.wrapper{background-color:var(--si-sys-color-background-0);color:var(--si-sys-color-text-primary)}:host-context(.has-tabs) .tab-wrapper{background-color:var(--si-sys-color-background-0)}:host-context(.has-tabs-mobile) .wrapper{background-color:var(--si-sys-color-background-0)}.tab-wrapper{margin-block-end:10px;border-block-end:1px solid var(--si-sys-color-border-4)}:host{display:contents}\n"] }]
|
|
480
|
+
}], propDecorators: { tabs: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabs", required: true }] }], activeTabIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeTabIndex", required: true }] }], tabSelected: [{ type: i0.Output, args: ["tabSelected"] }] } });
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
484
|
+
* SPDX-License-Identifier: MIT
|
|
485
|
+
*/
|
|
486
|
+
const LOG_EVENT = new InjectionToken('si.live-previewer.log-event');
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
490
|
+
* SPDX-License-Identifier: MIT
|
|
491
|
+
*/
|
|
492
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
493
|
+
class LandscapeSupportService {
|
|
494
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LandscapeSupportService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
495
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LandscapeSupportService, providedIn: 'any' });
|
|
496
|
+
}
|
|
497
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LandscapeSupportService, decorators: [{
|
|
498
|
+
type: Injectable,
|
|
499
|
+
args: [{
|
|
500
|
+
providedIn: 'any'
|
|
501
|
+
}]
|
|
502
|
+
}] });
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
506
|
+
* SPDX-License-Identifier: MIT
|
|
507
|
+
*/
|
|
508
|
+
/**
|
|
509
|
+
* Base class for components that act as a live-preview runtime shell.
|
|
510
|
+
* Extend this class when providing `SiLivePreviewConfig.runtimeComponent`.
|
|
511
|
+
*/
|
|
512
|
+
class SiLivePreviewRuntimeComponent {
|
|
513
|
+
component = input.required(/* @ts-ignore */
|
|
514
|
+
...(ngDevMode ? [{ debugName: "component" }] : /* istanbul ignore next */ []));
|
|
515
|
+
ready = output();
|
|
516
|
+
renderingError = output();
|
|
517
|
+
changeDetector = inject(ChangeDetectorRef);
|
|
518
|
+
activatedRoute = inject(ActivatedRoute);
|
|
519
|
+
config = inject(SI_LIVE_PREVIEW_CONFIG);
|
|
520
|
+
componentRef;
|
|
521
|
+
childRouteBackup;
|
|
522
|
+
hasRenderingError = false;
|
|
523
|
+
ngAfterViewInit() {
|
|
524
|
+
this.componentRef = this.container().createComponent(this.component());
|
|
525
|
+
const exampleRoutes = this.componentRef.injector.get(SI_LIVE_PREVIEW_EXAMPLE_ROUTES, undefined, {
|
|
526
|
+
optional: true,
|
|
527
|
+
self: true
|
|
528
|
+
}) ??
|
|
529
|
+
this.config.defaultRoutes ??
|
|
530
|
+
this.activatedRoute.routeConfig?.children ??
|
|
531
|
+
[];
|
|
532
|
+
const route = this.activatedRoute.routeConfig;
|
|
533
|
+
if (route) {
|
|
534
|
+
this.childRouteBackup = route.children;
|
|
535
|
+
// Do not reset the router configuration: that destroys child components during navigation.
|
|
536
|
+
route.children = [...exampleRoutes];
|
|
537
|
+
}
|
|
538
|
+
this.ready.emit();
|
|
539
|
+
}
|
|
540
|
+
ngOnDestroy() {
|
|
541
|
+
this.componentRef?.destroy();
|
|
542
|
+
this.componentRef = undefined;
|
|
543
|
+
const route = this.activatedRoute.routeConfig;
|
|
544
|
+
if (route) {
|
|
545
|
+
route.children = this.childRouteBackup;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
ngDoCheck() {
|
|
549
|
+
if (this.hasRenderingError) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
try {
|
|
553
|
+
this.changeDetector.detectChanges();
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
this.hasRenderingError = true;
|
|
557
|
+
this.renderingError.emit(error instanceof Error ? error : new Error(String(error)));
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRuntimeComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
561
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.8", type: SiLivePreviewRuntimeComponent, isStandalone: true, inputs: { component: { classPropertyName: "component", publicName: "component", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { ready: "ready", renderingError: "renderingError" }, ngImport: i0 });
|
|
562
|
+
}
|
|
563
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRuntimeComponent, decorators: [{
|
|
564
|
+
type: Directive
|
|
565
|
+
}], propDecorators: { component: [{ type: i0.Input, args: [{ isSignal: true, alias: "component", required: true }] }], ready: [{ type: i0.Output, args: ["ready"] }], renderingError: [{ type: i0.Output, args: ["renderingError"] }] } });
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
569
|
+
* SPDX-License-Identifier: MIT
|
|
570
|
+
*/
|
|
571
|
+
/** Default standalone shell used to render a live-preview example. */
|
|
572
|
+
class SiDefaultLivePreviewRuntimeComponent extends SiLivePreviewRuntimeComponent {
|
|
573
|
+
container = viewChild.required('container', { ...(ngDevMode ? { debugName: "container" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
|
|
574
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDefaultLivePreviewRuntimeComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
575
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.8", type: SiDefaultLivePreviewRuntimeComponent, isStandalone: true, selector: "si-live-preview-runtime", viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true, read: ViewContainerRef, isSignal: true }], usesInheritance: true, ngImport: i0, template: '<ng-container #container />', isInline: true });
|
|
576
|
+
}
|
|
577
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDefaultLivePreviewRuntimeComponent, decorators: [{
|
|
578
|
+
type: Component,
|
|
579
|
+
args: [{
|
|
580
|
+
selector: 'si-live-preview-runtime',
|
|
581
|
+
template: '<ng-container #container />'
|
|
582
|
+
}]
|
|
583
|
+
}], propDecorators: { container: [{ type: i0.ViewChild, args: ['container', { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
|
|
584
|
+
|
|
585
|
+
// for handling JSON.stringify with circular references, from MDN
|
|
586
|
+
const getCircularReplacer = () => {
|
|
587
|
+
const seen = new WeakSet();
|
|
588
|
+
return (_key, value) => {
|
|
589
|
+
if (typeof value === 'object' && value !== null) {
|
|
590
|
+
if (seen.has(value)) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
seen.add(value);
|
|
594
|
+
}
|
|
595
|
+
return value;
|
|
596
|
+
};
|
|
597
|
+
};
|
|
598
|
+
let DummyAppSampleComponent = class DummyAppSampleComponent {
|
|
599
|
+
};
|
|
600
|
+
DummyAppSampleComponent = __decorate([
|
|
601
|
+
Component({
|
|
602
|
+
// eslint-disable-next-line @angular-eslint/component-selector
|
|
603
|
+
selector: 'app-sample',
|
|
604
|
+
template: '',
|
|
605
|
+
jit: true
|
|
606
|
+
})
|
|
607
|
+
], DummyAppSampleComponent);
|
|
608
|
+
class SiLivePreviewRendererComponent {
|
|
609
|
+
renderedExample = viewChild.required('renderedExample', { ...(ngDevMode ? { debugName: "renderedExample" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
|
|
610
|
+
react = viewChild.required('react', { ...(ngDevMode ? { debugName: "react" } : /* istanbul ignore next */ {}), read: ElementRef });
|
|
611
|
+
state = inject(LivePreviewStateService);
|
|
612
|
+
config = inject(SI_LIVE_PREVIEW_CONFIG);
|
|
613
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
614
|
+
compiler = inject(Compiler);
|
|
615
|
+
injector = Injector.create({
|
|
616
|
+
parent: inject(Injector),
|
|
617
|
+
providers: [
|
|
618
|
+
{
|
|
619
|
+
provide: LOG_EVENT,
|
|
620
|
+
useValue: (...msg) => this.logMessage.emit(this.stringifyLog(msg))
|
|
621
|
+
}
|
|
622
|
+
]
|
|
623
|
+
});
|
|
624
|
+
rendererFactory = inject(_DomRendererFactory2);
|
|
625
|
+
cdRef = inject(ChangeDetectorRef);
|
|
626
|
+
exampleUrl = computed(() => this.config.examplesBaseUrl + this.state.example(), /* @ts-ignore */
|
|
627
|
+
...(ngDevMode ? [{ debugName: "exampleUrl" }] : /* istanbul ignore next */ []));
|
|
628
|
+
renderingDone = signal(false, /* @ts-ignore */
|
|
629
|
+
...(ngDevMode ? [{ debugName: "renderingDone" }] : /* istanbul ignore next */ []));
|
|
630
|
+
templateFromComponent = output();
|
|
631
|
+
logClear = output();
|
|
632
|
+
logMessage = output();
|
|
633
|
+
logRenderingError = output();
|
|
634
|
+
inProgress = output();
|
|
635
|
+
supportsLandscapeMode = output();
|
|
636
|
+
componentRef;
|
|
637
|
+
componentTs;
|
|
638
|
+
componentTsSampleComponent;
|
|
639
|
+
dynamicComponent;
|
|
640
|
+
dynamicComponentId;
|
|
641
|
+
componentTsFirstLoad = true;
|
|
642
|
+
compiledTemplate;
|
|
643
|
+
constructor() {
|
|
644
|
+
effect(() => {
|
|
645
|
+
const url = this.exampleUrl();
|
|
646
|
+
if (url) {
|
|
647
|
+
untracked(() => this.loadFromUrl());
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
effect(() => {
|
|
651
|
+
const template = this.state.template();
|
|
652
|
+
// when the initial template is pushed from the renderer to the editor, this.state.template is
|
|
653
|
+
// initially empty, but later changes to what the renderer has pushed out. In this case
|
|
654
|
+
// don't compile
|
|
655
|
+
if (template && template !== this.compiledTemplate) {
|
|
656
|
+
untracked(() => {
|
|
657
|
+
this.setInProgress(true);
|
|
658
|
+
this.compileWhenReady();
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
ngOnDestroy() {
|
|
664
|
+
this.clear();
|
|
665
|
+
}
|
|
666
|
+
recompile() {
|
|
667
|
+
this.removeComponentInstance();
|
|
668
|
+
this.logClear.emit();
|
|
669
|
+
this.setRenderingError(false);
|
|
670
|
+
try {
|
|
671
|
+
this.createComponentInstance();
|
|
672
|
+
}
|
|
673
|
+
catch (error) {
|
|
674
|
+
this.setRenderingError(true, error);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
logError(error) {
|
|
678
|
+
if (this.config.errorHandler) {
|
|
679
|
+
this.config.errorHandler(error);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
setRenderingError(hasError, msg) {
|
|
683
|
+
this.logRenderingError.emit(msg);
|
|
684
|
+
if (hasError) {
|
|
685
|
+
setTimeout(() => {
|
|
686
|
+
this.setInProgress(false);
|
|
687
|
+
this.cdRef.markForCheck();
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
loadFromUrl() {
|
|
692
|
+
this.logClear.emit();
|
|
693
|
+
this.clear();
|
|
694
|
+
this.componentTsSampleComponent = undefined;
|
|
695
|
+
this.dynamicComponent = undefined;
|
|
696
|
+
this.componentTsFirstLoad = true;
|
|
697
|
+
this.componentTs = this.config.componentLoader.load(this.exampleUrl());
|
|
698
|
+
if (this.componentTs) {
|
|
699
|
+
this.setInProgress(true);
|
|
700
|
+
this.componentTs
|
|
701
|
+
.then(m => {
|
|
702
|
+
this.componentTsSampleComponent = m.SampleComponent;
|
|
703
|
+
this.dynamicComponent = m.SampleComponent;
|
|
704
|
+
this.compileWhenReady();
|
|
705
|
+
if (!this.componentTsSampleComponent && !this.state.template()) {
|
|
706
|
+
afterNextRender(() => {
|
|
707
|
+
this.setInProgress(false);
|
|
708
|
+
this.cdRef.markForCheck();
|
|
709
|
+
}, { injector: this.injector });
|
|
710
|
+
}
|
|
711
|
+
})
|
|
712
|
+
.catch(e => {
|
|
713
|
+
this.componentTs = undefined;
|
|
714
|
+
this.logRenderingError.emit(e ? e.toString() : 'Failed loading TS');
|
|
715
|
+
afterNextRender(() => {
|
|
716
|
+
this.setInProgress(false);
|
|
717
|
+
this.cdRef.markForCheck();
|
|
718
|
+
}, { injector: this.injector });
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
// set the dummy component
|
|
723
|
+
this.componentTsSampleComponent = DummyAppSampleComponent;
|
|
724
|
+
// let the editor know there is no component, so no template
|
|
725
|
+
this.templateFromComponent.emit(undefined);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
setInProgress(inProgress) {
|
|
729
|
+
this.renderingDone.set(!inProgress);
|
|
730
|
+
this.inProgress.emit(inProgress);
|
|
731
|
+
}
|
|
732
|
+
compileWhenReady() {
|
|
733
|
+
if (this.componentTs) {
|
|
734
|
+
if (!this.componentTsSampleComponent) {
|
|
735
|
+
// TS, but code not yet loaded
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (!this.componentTsFirstLoad && !this.state.template()) {
|
|
739
|
+
// TS, first load done, template not yet available
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else if (!this.state.template()) {
|
|
744
|
+
// no TS, no template
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
this.doCompileTemplate();
|
|
748
|
+
}
|
|
749
|
+
doCompileTemplate() {
|
|
750
|
+
this.logClear.emit();
|
|
751
|
+
this.clear();
|
|
752
|
+
this.createComponent();
|
|
753
|
+
}
|
|
754
|
+
stringifyLog(args) {
|
|
755
|
+
return args.map(a => JSON.stringify(a, getCircularReplacer())).join(', ');
|
|
756
|
+
}
|
|
757
|
+
// this exists because in production mode, the ivy internal props are defined as
|
|
758
|
+
// non-configurable and cannot be overwritten
|
|
759
|
+
cloneComponentWithoutIvyStuff() {
|
|
760
|
+
if (!this.componentTsSampleComponent) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
const orig = this.componentTsSampleComponent;
|
|
764
|
+
const ignoreProps = ['ɵcmp', 'ɵfac', 'ɵprov'];
|
|
765
|
+
const copy = orig.bind({});
|
|
766
|
+
const descriptors = Object.getOwnPropertyDescriptors(orig);
|
|
767
|
+
for (const name of Object.getOwnPropertyNames(orig)) {
|
|
768
|
+
if (ignoreProps.includes(name)) {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
Object.defineProperty(copy, name, descriptors[name]);
|
|
772
|
+
}
|
|
773
|
+
this.dynamicComponent = copy;
|
|
774
|
+
}
|
|
775
|
+
// patches the template into the loaded component (if any), returns the template to use
|
|
776
|
+
updateDynamicTemplate() {
|
|
777
|
+
if (this.componentTsSampleComponent) {
|
|
778
|
+
const ann = this.componentTsSampleComponent?.decorators
|
|
779
|
+
? this.getAnnotationInAot(this.componentTsSampleComponent)
|
|
780
|
+
: this.getAnnotation(this.componentTsSampleComponent, Component);
|
|
781
|
+
if (ann) {
|
|
782
|
+
const supportsLandscape = ann.providers?.includes(LandscapeSupportService);
|
|
783
|
+
this.supportsLandscapeMode.emit(supportsLandscape);
|
|
784
|
+
if (this.componentTsFirstLoad && !this.state.template()) {
|
|
785
|
+
// skipping compile on first load
|
|
786
|
+
this.compiledTemplate = ann.template;
|
|
787
|
+
this.templateFromComponent.emit(ann.template);
|
|
788
|
+
}
|
|
789
|
+
else if (ann.template !== this.state.template()) {
|
|
790
|
+
// recompile with new template
|
|
791
|
+
this.componentTsFirstLoad = false;
|
|
792
|
+
this.cloneComponentWithoutIvyStuff();
|
|
793
|
+
ann.template = this.state.template();
|
|
794
|
+
this.compiledTemplate = this.state.template();
|
|
795
|
+
_compileComponent(this.dynamicComponent, ann);
|
|
796
|
+
this.reuseResolvedScopeOfOriginalComponent();
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* When the host application is built with AOT, the Angular compiler tree-shakes the
|
|
803
|
+
* `ɵɵsetNgModuleScope` calls (because `ngJitMode` is `false`). As a result, NgModules that are
|
|
804
|
+
* compiled from source expose no `imports`/`exports` scope on their `ɵmod` at runtime.
|
|
805
|
+
*
|
|
806
|
+
* Re-compiling the edited example via JIT (`compileComponent`) therefore cannot resolve the
|
|
807
|
+
* directives and pipes that are exported through such an imported NgModule. A common symptom is
|
|
808
|
+
* a missing value accessor for a form control component used with `ngModel`, which throws
|
|
809
|
+
* `NG01203`.
|
|
810
|
+
*
|
|
811
|
+
* The originally (AOT-)compiled component already carries the fully resolved scope in its
|
|
812
|
+
* component definition. Reusing its directive and pipe defs on the recompiled component restores
|
|
813
|
+
* the complete scope without depending on runtime NgModule metadata.
|
|
814
|
+
*/
|
|
815
|
+
reuseResolvedScopeOfOriginalComponent() {
|
|
816
|
+
const originalDef = this.componentTsSampleComponent?.['ɵcmp'];
|
|
817
|
+
const recompiledDef = this.dynamicComponent?.['ɵcmp'];
|
|
818
|
+
if (!originalDef || !recompiledDef) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
if (originalDef.directiveDefs) {
|
|
822
|
+
recompiledDef.directiveDefs = this.mergeDefs(recompiledDef.directiveDefs, originalDef.directiveDefs);
|
|
823
|
+
}
|
|
824
|
+
if (originalDef.pipeDefs) {
|
|
825
|
+
recompiledDef.pipeDefs = this.mergeDefs(recompiledDef.pipeDefs, originalDef.pipeDefs);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
/** Merges two (possibly lazy) Ivy def lists into a single deduplicated factory. */
|
|
829
|
+
mergeDefs(recompiled, original) {
|
|
830
|
+
const resolve = (defs) => typeof defs === 'function' ? defs() : (defs ?? []);
|
|
831
|
+
return () => [...new Set([...resolve(recompiled), ...resolve(original)])];
|
|
832
|
+
}
|
|
833
|
+
getAnnotation(obj, type) {
|
|
834
|
+
return obj?.__annotations__?.find((a) => a instanceof type);
|
|
835
|
+
}
|
|
836
|
+
getAnnotationInAot(obj) {
|
|
837
|
+
return obj.decorators?.[0]?.args?.[0];
|
|
838
|
+
}
|
|
839
|
+
clear() {
|
|
840
|
+
this.removeComponentInstance();
|
|
841
|
+
if (this.dynamicComponent) {
|
|
842
|
+
this.compiler.clearCacheFor(this.dynamicComponent);
|
|
843
|
+
}
|
|
844
|
+
_resetCompiledComponents();
|
|
845
|
+
}
|
|
846
|
+
removeComponentInstance() {
|
|
847
|
+
this.componentRef?.destroy();
|
|
848
|
+
this.componentRef = undefined;
|
|
849
|
+
try {
|
|
850
|
+
this.renderedExample().remove();
|
|
851
|
+
}
|
|
852
|
+
catch (error) {
|
|
853
|
+
// FIXME: there's no point in logging this as rendering error since it will be cleared right away
|
|
854
|
+
console.warn('Error during ngOnDestroy():', error);
|
|
855
|
+
}
|
|
856
|
+
// clear out render for component id:
|
|
857
|
+
// - contains the styles
|
|
858
|
+
// - stays mostly the same for all examples
|
|
859
|
+
if (this.dynamicComponentId) {
|
|
860
|
+
this.rendererFactory.rendererByCompId?.delete(this.dynamicComponentId);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
createComponent() {
|
|
864
|
+
this.setRenderingError(false);
|
|
865
|
+
try {
|
|
866
|
+
this.updateDynamicTemplate();
|
|
867
|
+
this.createComponentInstance();
|
|
868
|
+
}
|
|
869
|
+
catch (error) {
|
|
870
|
+
this.setRenderingError(true, error.toString());
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
createComponentInstance() {
|
|
874
|
+
this.dynamicComponentId = this.dynamicComponent?.['ɵcmp']?.id;
|
|
875
|
+
if (!this.dynamicComponent) {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
if (!this.dynamicComponent['ɵcmp']?.standalone) {
|
|
879
|
+
throw new Error('Live preview examples must be standalone components.');
|
|
880
|
+
}
|
|
881
|
+
const runtimeComponent = this.config.runtimeComponent ?? SiDefaultLivePreviewRuntimeComponent;
|
|
882
|
+
this.componentRef = this.renderedExample().createComponent(runtimeComponent, {
|
|
883
|
+
injector: this.injector,
|
|
884
|
+
bindings: [inputBinding('component', () => this.dynamicComponent)]
|
|
885
|
+
});
|
|
886
|
+
this.componentRef.instance.ready.subscribe(() => {
|
|
887
|
+
queueMicrotask(() => {
|
|
888
|
+
this.setInProgress(false);
|
|
889
|
+
this.cdRef.markForCheck();
|
|
890
|
+
});
|
|
891
|
+
});
|
|
892
|
+
this.componentRef.instance.renderingError.subscribe(error => {
|
|
893
|
+
this.setRenderingError(true, error.message);
|
|
894
|
+
this.logError(error);
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRendererComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
898
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.8", type: SiLivePreviewRendererComponent, isStandalone: true, selector: "si-live-preview-renderer", outputs: { templateFromComponent: "templateFromComponent", logClear: "logClear", logMessage: "logMessage", logRenderingError: "logRenderingError", inProgress: "inProgress", supportsLandscapeMode: "supportsLandscapeMode" }, host: { properties: { "class.live-preview-done": "renderingDone()", "attr.data-example": "exampleUrl()", "attr.data-id": "state.dataId()" } }, viewQueries: [{ propertyName: "renderedExample", first: true, predicate: ["renderedExample"], descendants: true, read: ViewContainerRef, isSignal: true }, { propertyName: "react", first: true, predicate: ["react"], descendants: true, read: ElementRef, isSignal: true }], ngImport: i0, template: '<div #renderedExample></div><div #react id="app"></div>', isInline: true, changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
899
|
+
}
|
|
900
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRendererComponent, decorators: [{
|
|
901
|
+
type: Component,
|
|
902
|
+
args: [{
|
|
903
|
+
selector: 'si-live-preview-renderer',
|
|
904
|
+
template: '<div #renderedExample></div><div #react id="app"></div>',
|
|
905
|
+
changeDetection: ChangeDetectionStrategy.Eager,
|
|
906
|
+
host: {
|
|
907
|
+
'[class.live-preview-done]': 'renderingDone()',
|
|
908
|
+
'[attr.data-example]': 'exampleUrl()',
|
|
909
|
+
'[attr.data-id]': 'state.dataId()'
|
|
910
|
+
}
|
|
911
|
+
}]
|
|
912
|
+
}], ctorParameters: () => [], propDecorators: { renderedExample: [{ type: i0.ViewChild, args: ['renderedExample', { ...{ read: ViewContainerRef }, isSignal: true }] }], react: [{ type: i0.ViewChild, args: ['react', { ...{ read: ElementRef }, isSignal: true }] }], templateFromComponent: [{ type: i0.Output, args: ["templateFromComponent"] }], logClear: [{ type: i0.Output, args: ["logClear"] }], logMessage: [{ type: i0.Output, args: ["logMessage"] }], logRenderingError: [{ type: i0.Output, args: ["logRenderingError"] }], inProgress: [{ type: i0.Output, args: ["inProgress"] }], supportsLandscapeMode: [{ type: i0.Output, args: ["supportsLandscapeMode"] }] } });
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
916
|
+
* SPDX-License-Identifier: MIT
|
|
917
|
+
*/
|
|
918
|
+
class SiExampleViewerComponent {
|
|
919
|
+
state = inject(LivePreviewStateService);
|
|
920
|
+
routeController = inject(ExampleRouteController);
|
|
921
|
+
renderer = viewChild(SiLivePreviewRendererComponent, /* @ts-ignore */
|
|
922
|
+
...(ngDevMode ? [{ debugName: "renderer" }] : /* istanbul ignore next */ []));
|
|
923
|
+
constructor() {
|
|
924
|
+
this.routeController.initialize('viewer', () => this.renderer()?.recompile());
|
|
925
|
+
}
|
|
926
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiExampleViewerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
927
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: SiExampleViewerComponent, isStandalone: true, selector: "si-example-viewer", host: { properties: { "class.has-tabs": "routeController.hasTabs()", "class.has-tabs-mobile": "routeController.hasTabsMobile()" } }, providers: [ExampleRouteController], viewQueries: [{ propertyName: "renderer", first: true, predicate: SiLivePreviewRendererComponent, descendants: true, isSignal: true }], ngImport: i0, template: "<si-example-header\n [tabs]=\"routeController.tabs()\"\n [activeTabIndex]=\"routeController.activeTabIndex()\"\n (tabSelected)=\"routeController.activateTab($event)\"\n>\n @if (!state.example() && !state.template()) {\n <p class=\"text-information\" style=\"margin: 1em\">\n No example specified. Head to\n <strong><a href=\"#/overview\">/overview</a></strong>\n for a list of them.\n </p>\n }\n</si-example-header>\n\n<si-live-preview-renderer />\n", styles: ["si-live-preview-renderer{flex:1;transform:translate(0)}\n"], dependencies: [{ kind: "component", type: SiExampleHeaderComponent, selector: "si-example-header", inputs: ["tabs", "activeTabIndex"], outputs: ["tabSelected"] }, { kind: "component", type: SiLivePreviewRendererComponent, selector: "si-live-preview-renderer", outputs: ["templateFromComponent", "logClear", "logMessage", "logRenderingError", "inProgress", "supportsLandscapeMode"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
928
|
+
}
|
|
929
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiExampleViewerComponent, decorators: [{
|
|
930
|
+
type: Component,
|
|
931
|
+
args: [{ selector: 'si-example-viewer', imports: [SiExampleHeaderComponent, SiLivePreviewRendererComponent], providers: [ExampleRouteController], changeDetection: ChangeDetectionStrategy.Eager, host: {
|
|
932
|
+
'[class.has-tabs]': 'routeController.hasTabs()',
|
|
933
|
+
'[class.has-tabs-mobile]': 'routeController.hasTabsMobile()'
|
|
934
|
+
}, template: "<si-example-header\n [tabs]=\"routeController.tabs()\"\n [activeTabIndex]=\"routeController.activeTabIndex()\"\n (tabSelected)=\"routeController.activateTab($event)\"\n>\n @if (!state.example() && !state.template()) {\n <p class=\"text-information\" style=\"margin: 1em\">\n No example specified. Head to\n <strong><a href=\"#/overview\">/overview</a></strong>\n for a list of them.\n </p>\n }\n</si-example-header>\n\n<si-live-preview-renderer />\n", styles: ["si-live-preview-renderer{flex:1;transform:translate(0)}\n"] }]
|
|
935
|
+
}], ctorParameters: () => [], propDecorators: { renderer: [{ type: i0.ViewChild, args: [i0.forwardRef(() => SiLivePreviewRendererComponent), { isSignal: true }] }] } });
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
939
|
+
* SPDX-License-Identifier: MIT
|
|
940
|
+
*/
|
|
941
|
+
class SiLivePreviewWebComponentService {
|
|
942
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewWebComponentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
943
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewWebComponentService });
|
|
944
|
+
}
|
|
945
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewWebComponentService, decorators: [{
|
|
946
|
+
type: Injectable
|
|
947
|
+
}] });
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
951
|
+
* SPDX-License-Identifier: MIT
|
|
952
|
+
*/
|
|
953
|
+
const filterTargets = ['_self', '_top', '_parent', ''];
|
|
954
|
+
class SiLivePreviewWrapperComponent {
|
|
955
|
+
renderer = viewChild.required('renderer', /* @ts-ignore */
|
|
956
|
+
...(ngDevMode ? [{ debugName: "renderer" }] : /* istanbul ignore next */ []));
|
|
957
|
+
webcomponentRenderer = viewChild.required('webcomponentRenderer', /* @ts-ignore */
|
|
958
|
+
...(ngDevMode ? [{ debugName: "webcomponentRenderer" }] : /* istanbul ignore next */ []));
|
|
959
|
+
state = inject(LivePreviewStateService);
|
|
960
|
+
config = inject(SI_LIVE_PREVIEW_CONFIG);
|
|
961
|
+
themeApi = inject(SiLivePreviewThemeApi, { optional: true });
|
|
962
|
+
localeApi = inject(SiLivePreviewLocaleApi, { optional: true });
|
|
963
|
+
internalConfig = inject(SI_LIVE_PREVIEW_INTERNALS);
|
|
964
|
+
ngZone = inject(NgZone);
|
|
965
|
+
webcomponentService = inject(SiLivePreviewWebComponentService, {
|
|
966
|
+
optional: true
|
|
967
|
+
});
|
|
968
|
+
cdRef = inject(ChangeDetectorRef);
|
|
969
|
+
parentOrigin = this.resolveParentOrigin();
|
|
970
|
+
isMobile = false;
|
|
971
|
+
initialUrl;
|
|
972
|
+
constructor() {
|
|
973
|
+
this.themeApi
|
|
974
|
+
?.getApplicationThemeObservable()
|
|
975
|
+
.pipe(takeUntilDestroyed())
|
|
976
|
+
.subscribe(theme => {
|
|
977
|
+
this.state.theme.set(theme);
|
|
978
|
+
this.sendMessage('theme', theme);
|
|
979
|
+
});
|
|
980
|
+
this.localeApi
|
|
981
|
+
?.getLocale()
|
|
982
|
+
.pipe(takeUntilDestroyed())
|
|
983
|
+
.subscribe(locale => {
|
|
984
|
+
if (this.state.locale() !== locale) {
|
|
985
|
+
this.state.locale.set(locale);
|
|
986
|
+
this.sendMessage('locale', locale);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
this.initialUrl = window.location.toString();
|
|
990
|
+
this.isMobile = this.internalConfig.isMobile;
|
|
991
|
+
if (this.isMobile) {
|
|
992
|
+
setDeviceMode(this.state.viewport().mode);
|
|
993
|
+
}
|
|
994
|
+
// send ready message only when locale/theme are communicated to avoid loops
|
|
995
|
+
this.sendMessage('ready');
|
|
996
|
+
this.ngZone.runOutsideAngular(() => fromEvent(window, 'message')
|
|
997
|
+
.pipe(takeUntilDestroyed())
|
|
998
|
+
.subscribe(message => {
|
|
999
|
+
this.onMessage(message);
|
|
1000
|
+
this.cdRef.markForCheck();
|
|
1001
|
+
}));
|
|
1002
|
+
}
|
|
1003
|
+
onMessage(event) {
|
|
1004
|
+
// Render requests contain executable templates. Only trust the embedding editor, with
|
|
1005
|
+
// a loopback-only exception for documentation development on a separate local port.
|
|
1006
|
+
if (event.origin !== this.parentOrigin ||
|
|
1007
|
+
event.source !== window.parent ||
|
|
1008
|
+
event.data?.src !== 'editor') {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
this.ngZone.run(() => this.onMessageInZone(event));
|
|
1012
|
+
}
|
|
1013
|
+
onMessageInZone(event) {
|
|
1014
|
+
const modeChanged = this.state.viewport().mode !== event.data.mode;
|
|
1015
|
+
this.state.applyRenderRequest(event.data);
|
|
1016
|
+
if (this.state.theme() !== event.data.theme) {
|
|
1017
|
+
this.setTheme(event.data.theme);
|
|
1018
|
+
}
|
|
1019
|
+
if (this.state.locale() !== event.data.locale) {
|
|
1020
|
+
this.setLocale(event.data.locale);
|
|
1021
|
+
}
|
|
1022
|
+
if (this.state.rootFontSize() !== event.data.rootFontSize) {
|
|
1023
|
+
this.state.rootFontSize.set(event.data.rootFontSize);
|
|
1024
|
+
setRootFontSize(event.data.rootFontSize);
|
|
1025
|
+
}
|
|
1026
|
+
if (this.state.isRTL() !== event.data.isRTL) {
|
|
1027
|
+
this.setRTL(event.data.isRTL);
|
|
1028
|
+
}
|
|
1029
|
+
if (this.isMobile) {
|
|
1030
|
+
this.setSafeArea(event.data.safeAreaTop, event.data.safeAreaBottom, event.data.safeAreaLeft, event.data.safeAreaRight);
|
|
1031
|
+
}
|
|
1032
|
+
if (modeChanged && this.isMobile) {
|
|
1033
|
+
setDeviceMode(event.data.mode);
|
|
1034
|
+
this.renderer().recompile();
|
|
1035
|
+
}
|
|
1036
|
+
const webcomponentRenderer = this.webcomponentRenderer();
|
|
1037
|
+
if (webcomponentRenderer &&
|
|
1038
|
+
(this.state.loadReact() || this.state.loadVue() || this.state.loadJs())) {
|
|
1039
|
+
this.webcomponentService?.injectComponent(webcomponentRenderer, {
|
|
1040
|
+
exampleUrl: this.config.examplesBaseUrl + this.state.example(),
|
|
1041
|
+
loadReact: this.state.loadReact(),
|
|
1042
|
+
loadJs: this.state.loadJs(),
|
|
1043
|
+
webcomponentTemplateCode: this.state.activeWebComponentTemplate(),
|
|
1044
|
+
loadVue: this.state.loadVue(),
|
|
1045
|
+
config: this.config
|
|
1046
|
+
}, {
|
|
1047
|
+
inProgress: (type, message) => this.sendMessage(type, message)
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
else {
|
|
1051
|
+
this.webcomponentService?.destroyComponent();
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
onClick(event) {
|
|
1055
|
+
const target = event?.target;
|
|
1056
|
+
if (target?.tagName === 'A' && !event.defaultPrevented) {
|
|
1057
|
+
// for normal link: ok if it starts with the proper route, else open in a new window
|
|
1058
|
+
const newUrl = target.href;
|
|
1059
|
+
const linkTarget = target.target;
|
|
1060
|
+
if (newUrl && !newUrl.startsWith(this.initialUrl) && filterTargets.includes(linkTarget)) {
|
|
1061
|
+
event.preventDefault();
|
|
1062
|
+
window.open(newUrl, '_blank', 'noopener,noreferrer');
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
sendMessage(type, message) {
|
|
1067
|
+
window.parent.postMessage({ src: 'renderer', type, message }, this.parentOrigin);
|
|
1068
|
+
}
|
|
1069
|
+
resolveParentOrigin() {
|
|
1070
|
+
const location = window.location;
|
|
1071
|
+
// Keep the editor origin across locale-triggered reloads, which replace the referrer.
|
|
1072
|
+
const parameters = new URLSearchParams(location.hash.split('?')[1]);
|
|
1073
|
+
const source = parameters.get('parentOrigin') ?? document.referrer;
|
|
1074
|
+
if (!source || !URL.canParse(source)) {
|
|
1075
|
+
return location.origin;
|
|
1076
|
+
}
|
|
1077
|
+
const parent = new URL(source);
|
|
1078
|
+
const isLoopback = (hostname) => hostname === 'localhost' || hostname === '[::1]' || /^127(?:\.\d{1,3}){3}$/.test(hostname);
|
|
1079
|
+
return parent.origin === location.origin ||
|
|
1080
|
+
(parent.protocol === 'http:' &&
|
|
1081
|
+
location.protocol === 'http:' &&
|
|
1082
|
+
isLoopback(parent.hostname) &&
|
|
1083
|
+
isLoopback(location.hostname))
|
|
1084
|
+
? parent.origin
|
|
1085
|
+
: location.origin;
|
|
1086
|
+
}
|
|
1087
|
+
setTheme(theme) {
|
|
1088
|
+
this.state.theme.set(theme);
|
|
1089
|
+
if (this.themeApi) {
|
|
1090
|
+
this.themeApi.setThemeFromPreviewer(theme);
|
|
1091
|
+
}
|
|
1092
|
+
else {
|
|
1093
|
+
document.documentElement.classList.toggle('app--dark', theme === 'dark');
|
|
1094
|
+
document.documentElement.classList.toggle('app--light', theme === 'light');
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
setRTL(rtl) {
|
|
1098
|
+
this.state.isRTL.set(rtl);
|
|
1099
|
+
setDirectionRtl(rtl);
|
|
1100
|
+
}
|
|
1101
|
+
setLocale(locale) {
|
|
1102
|
+
if (!locale) {
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
this.state.locale.set(locale);
|
|
1106
|
+
if (this.localeApi) {
|
|
1107
|
+
this.localeApi.setLocale(locale);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
setSafeArea(top, bottom, left, right) {
|
|
1111
|
+
const htmlTag = document.documentElement;
|
|
1112
|
+
htmlTag.style.setProperty('--ion-safe-area-top', (top ?? 0) + 'px');
|
|
1113
|
+
htmlTag.style.setProperty('--ion-safe-area-bottom', (bottom ?? 0) + 'px');
|
|
1114
|
+
htmlTag.style.setProperty('--ion-safe-area-left', (left ?? 0) + 'px');
|
|
1115
|
+
htmlTag.style.setProperty('--ion-safe-area-right', (right ?? 0) + 'px');
|
|
1116
|
+
}
|
|
1117
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewWrapperComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1118
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.8", type: SiLivePreviewWrapperComponent, isStandalone: true, selector: "si-live-preview-wrapper", host: { listeners: { "click": "onClick($event)" } }, viewQueries: [{ propertyName: "renderer", first: true, predicate: ["renderer"], descendants: true, isSignal: true }, { propertyName: "webcomponentRenderer", first: true, predicate: ["webcomponentRenderer"], descendants: true, isSignal: true }], ngImport: i0, template: "<si-live-preview-renderer\n #renderer\n [hidden]=\"state.loadReact() || state.loadVue() || state.loadJs()\"\n (templateFromComponent)=\"sendMessage('templateFromComponent', $event)\"\n (logClear)=\"sendMessage('clear')\"\n (logMessage)=\"sendMessage('log', $event)\"\n (logRenderingError)=\"sendMessage('error', $event)\"\n (inProgress)=\"sendMessage('progress', $event)\"\n (supportsLandscapeMode)=\"sendMessage('landscapeMode', $event)\"\n/>\n\n<div #webcomponentRenderer></div>\n", styles: ["si-live-preview-renderer{flex:1}\n"], dependencies: [{ kind: "component", type: SiLivePreviewRendererComponent, selector: "si-live-preview-renderer", outputs: ["templateFromComponent", "logClear", "logMessage", "logRenderingError", "inProgress", "supportsLandscapeMode"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
1119
|
+
}
|
|
1120
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewWrapperComponent, decorators: [{
|
|
1121
|
+
type: Component,
|
|
1122
|
+
args: [{ selector: 'si-live-preview-wrapper', imports: [SiLivePreviewRendererComponent], changeDetection: ChangeDetectionStrategy.Eager, host: {
|
|
1123
|
+
'(click)': 'onClick($event)'
|
|
1124
|
+
}, template: "<si-live-preview-renderer\n #renderer\n [hidden]=\"state.loadReact() || state.loadVue() || state.loadJs()\"\n (templateFromComponent)=\"sendMessage('templateFromComponent', $event)\"\n (logClear)=\"sendMessage('clear')\"\n (logMessage)=\"sendMessage('log', $event)\"\n (logRenderingError)=\"sendMessage('error', $event)\"\n (inProgress)=\"sendMessage('progress', $event)\"\n (supportsLandscapeMode)=\"sendMessage('landscapeMode', $event)\"\n/>\n\n<div #webcomponentRenderer></div>\n", styles: ["si-live-preview-renderer{flex:1}\n"] }]
|
|
1125
|
+
}], ctorParameters: () => [], propDecorators: { renderer: [{ type: i0.ViewChild, args: ['renderer', { isSignal: true }] }], webcomponentRenderer: [{ type: i0.ViewChild, args: ['webcomponentRenderer', { isSignal: true }] }] } });
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1129
|
+
* SPDX-License-Identifier: MIT
|
|
1130
|
+
*/
|
|
1131
|
+
const livePreviewRoutes = [
|
|
1132
|
+
{
|
|
1133
|
+
path: 'overview',
|
|
1134
|
+
children: [
|
|
1135
|
+
{
|
|
1136
|
+
path: '**',
|
|
1137
|
+
loadComponent: () => import('./siemens-live-preview-si-example-overview.component-Co4tIhL5.mjs').then(m => m.SiExampleOverviewComponent)
|
|
1138
|
+
}
|
|
1139
|
+
]
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
path: 'viewer/editor',
|
|
1143
|
+
loadComponent: () => import('./siemens-live-preview-si-example-editor.component-DSxapfeC.mjs').then(m => m.SiExampleEditorComponent),
|
|
1144
|
+
children: [{ path: '**', component: SiDummyComponent }]
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
path: 'viewer/:mode',
|
|
1148
|
+
// Keep the renderer eager for the viewer/viewer route used by e2e tests.
|
|
1149
|
+
component: SiExampleViewerComponent,
|
|
1150
|
+
children: [{ path: '**', component: SiDummyComponent }]
|
|
1151
|
+
},
|
|
1152
|
+
{
|
|
1153
|
+
path: 'iframe',
|
|
1154
|
+
component: SiLivePreviewWrapperComponent,
|
|
1155
|
+
children: [{ path: '**', component: SiDummyComponent }]
|
|
1156
|
+
},
|
|
1157
|
+
{ path: '', redirectTo: 'viewer/editor', pathMatch: 'full' },
|
|
1158
|
+
{
|
|
1159
|
+
path: '**',
|
|
1160
|
+
loadComponent: () => import('./siemens-live-preview-si-example-editor.component-DSxapfeC.mjs').then(m => m.SiExampleEditorComponent)
|
|
1161
|
+
}
|
|
1162
|
+
];
|
|
1163
|
+
class SiLivePreviewRoutingModule {
|
|
1164
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRoutingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1165
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRoutingModule, imports: [i1.RouterModule], exports: [RouterModule] });
|
|
1166
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRoutingModule, imports: [RouterModule.forRoot(livePreviewRoutes, { useHash: true }), RouterModule] });
|
|
1167
|
+
}
|
|
1168
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewRoutingModule, decorators: [{
|
|
1169
|
+
type: NgModule,
|
|
1170
|
+
args: [{
|
|
1171
|
+
imports: [RouterModule.forRoot(livePreviewRoutes, { useHash: true })],
|
|
1172
|
+
exports: [RouterModule]
|
|
1173
|
+
}]
|
|
1174
|
+
}] });
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1178
|
+
* SPDX-License-Identifier: MIT
|
|
1179
|
+
*/
|
|
1180
|
+
/** A router location that is private to a rendered example application. */
|
|
1181
|
+
class ExampleLocationStrategy extends LocationStrategy {
|
|
1182
|
+
currentPath = '/';
|
|
1183
|
+
state = null;
|
|
1184
|
+
path() {
|
|
1185
|
+
return this.currentPath;
|
|
1186
|
+
}
|
|
1187
|
+
prepareExternalUrl(internal) {
|
|
1188
|
+
return internal;
|
|
1189
|
+
}
|
|
1190
|
+
getState() {
|
|
1191
|
+
return this.state;
|
|
1192
|
+
}
|
|
1193
|
+
pushState(state, _title, url, queryParams) {
|
|
1194
|
+
this.state = state;
|
|
1195
|
+
this.currentPath = url + queryParams;
|
|
1196
|
+
}
|
|
1197
|
+
replaceState(state, _title, url, queryParams) {
|
|
1198
|
+
this.state = state;
|
|
1199
|
+
this.currentPath = url + queryParams;
|
|
1200
|
+
}
|
|
1201
|
+
forward() { }
|
|
1202
|
+
back() { }
|
|
1203
|
+
onPopState(_fn) { }
|
|
1204
|
+
getBaseHref() {
|
|
1205
|
+
return '';
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1211
|
+
* SPDX-License-Identifier: MIT
|
|
1212
|
+
*/
|
|
1213
|
+
/**
|
|
1214
|
+
* Runtime shell that renders each example in an independent Angular application.
|
|
1215
|
+
* The example application owns its router and does not modify the live-preview router.
|
|
1216
|
+
*/
|
|
1217
|
+
class SiLivePreviewApplicationRuntimeComponent extends SiLivePreviewRuntimeComponent {
|
|
1218
|
+
applicationConfig = inject(SI_LIVE_PREVIEW_CONFIG);
|
|
1219
|
+
parentInjector = inject(Injector);
|
|
1220
|
+
exampleComponentRef;
|
|
1221
|
+
applicationRef;
|
|
1222
|
+
hostElement;
|
|
1223
|
+
destroyed = false;
|
|
1224
|
+
ngAfterViewInit() {
|
|
1225
|
+
this.createExampleApplication();
|
|
1226
|
+
}
|
|
1227
|
+
ngOnDestroy() {
|
|
1228
|
+
this.destroyed = true;
|
|
1229
|
+
this.exampleComponentRef?.destroy();
|
|
1230
|
+
this.exampleComponentRef = undefined;
|
|
1231
|
+
this.applicationRef?.destroy();
|
|
1232
|
+
this.hostElement?.remove();
|
|
1233
|
+
}
|
|
1234
|
+
async createExampleApplication() {
|
|
1235
|
+
try {
|
|
1236
|
+
const locationStrategy = new ExampleLocationStrategy();
|
|
1237
|
+
const configuredApplication = this.applicationConfig.exampleApplicationConfig;
|
|
1238
|
+
const exampleApplicationConfig = typeof configuredApplication === 'function'
|
|
1239
|
+
? configuredApplication(this.parentInjector)
|
|
1240
|
+
: configuredApplication;
|
|
1241
|
+
this.applicationRef = await createApplication({
|
|
1242
|
+
...exampleApplicationConfig,
|
|
1243
|
+
providers: [
|
|
1244
|
+
...(exampleApplicationConfig?.providers ?? []),
|
|
1245
|
+
provideRouter([], withDisabledInitialNavigation()),
|
|
1246
|
+
{ provide: LocationStrategy, useValue: locationStrategy },
|
|
1247
|
+
{
|
|
1248
|
+
provide: Location,
|
|
1249
|
+
useFactory: () => new Location(inject(LocationStrategy))
|
|
1250
|
+
},
|
|
1251
|
+
{
|
|
1252
|
+
provide: LOG_EVENT,
|
|
1253
|
+
useFactory: () => this.parentInjector.get(LOG_EVENT)
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
provide: ErrorHandler,
|
|
1257
|
+
useValue: { handleError: (error) => this.handleError(error) }
|
|
1258
|
+
}
|
|
1259
|
+
]
|
|
1260
|
+
});
|
|
1261
|
+
if (this.destroyed) {
|
|
1262
|
+
this.applicationRef.destroy();
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
this.exampleComponentRef = createComponent(this.component(), {
|
|
1266
|
+
environmentInjector: this.applicationRef.injector
|
|
1267
|
+
});
|
|
1268
|
+
this.hostElement = this.exampleComponentRef.location.nativeElement;
|
|
1269
|
+
const anchor = this.container().element.nativeElement;
|
|
1270
|
+
anchor.parentNode?.insertBefore(this.hostElement, anchor);
|
|
1271
|
+
const exampleRoutes = this.exampleComponentRef.injector.get(SI_LIVE_PREVIEW_EXAMPLE_ROUTES, this.applicationConfig.defaultRoutes ?? [{ path: '**', component: SiDummyComponent }], { self: true });
|
|
1272
|
+
this.applicationRef.injector.get(Router).resetConfig(exampleRoutes);
|
|
1273
|
+
this.applicationRef.attachView(this.exampleComponentRef.hostView);
|
|
1274
|
+
this.applicationRef.tick();
|
|
1275
|
+
this.ready.emit();
|
|
1276
|
+
}
|
|
1277
|
+
catch (error) {
|
|
1278
|
+
this.handleError(error);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
handleError(error) {
|
|
1282
|
+
this.renderingError.emit(error instanceof Error ? error : new Error(String(error)));
|
|
1283
|
+
}
|
|
1284
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewApplicationRuntimeComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
1285
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.8", type: SiLivePreviewApplicationRuntimeComponent, isStandalone: true, usesInheritance: true, ngImport: i0 });
|
|
1286
|
+
}
|
|
1287
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewApplicationRuntimeComponent, decorators: [{
|
|
1288
|
+
type: Directive
|
|
1289
|
+
}] });
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1293
|
+
* SPDX-License-Identifier: MIT
|
|
1294
|
+
*/
|
|
1295
|
+
/** Default shell that renders an example in an independent Angular application. */
|
|
1296
|
+
class SiDefaultLivePreviewApplicationRuntimeComponent extends SiLivePreviewApplicationRuntimeComponent {
|
|
1297
|
+
container = viewChild.required('container', { ...(ngDevMode ? { debugName: "container" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
|
|
1298
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDefaultLivePreviewApplicationRuntimeComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
1299
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.8", type: SiDefaultLivePreviewApplicationRuntimeComponent, isStandalone: true, selector: "si-live-preview-application-runtime", viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true, read: ViewContainerRef, isSignal: true }], usesInheritance: true, ngImport: i0, template: '<ng-container #container />', isInline: true });
|
|
1300
|
+
}
|
|
1301
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDefaultLivePreviewApplicationRuntimeComponent, decorators: [{
|
|
1302
|
+
type: Component,
|
|
1303
|
+
args: [{
|
|
1304
|
+
selector: 'si-live-preview-application-runtime',
|
|
1305
|
+
template: '<ng-container #container />'
|
|
1306
|
+
}]
|
|
1307
|
+
}], propDecorators: { container: [{ type: i0.ViewChild, args: ['container', { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1311
|
+
* SPDX-License-Identifier: MIT
|
|
1312
|
+
*/
|
|
1313
|
+
/**
|
|
1314
|
+
* Configures live preview with each example rendered in an independent Angular application.
|
|
1315
|
+
*/
|
|
1316
|
+
const provideLivePreview = (config, isMobile = false) => {
|
|
1317
|
+
return makeEnvironmentProviders([
|
|
1318
|
+
provideRouter(livePreviewRoutes, withHashLocation()),
|
|
1319
|
+
{
|
|
1320
|
+
provide: SI_LIVE_PREVIEW_CONFIG,
|
|
1321
|
+
useValue: {
|
|
1322
|
+
...config,
|
|
1323
|
+
runtimeComponent: config.runtimeComponent ?? SiDefaultLivePreviewApplicationRuntimeComponent
|
|
1324
|
+
}
|
|
1325
|
+
},
|
|
1326
|
+
{
|
|
1327
|
+
provide: SI_LIVE_PREVIEW_INTERNALS,
|
|
1328
|
+
useValue: { isMobile, titleBase: 'Overview - Live Preview' }
|
|
1329
|
+
}
|
|
1330
|
+
]);
|
|
1331
|
+
};
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1335
|
+
* SPDX-License-Identifier: MIT
|
|
1336
|
+
*/
|
|
1337
|
+
class LivePreviewUrlService {
|
|
1338
|
+
config = inject(SI_LIVE_PREVIEW_CONFIG);
|
|
1339
|
+
state = inject(LivePreviewStateService);
|
|
1340
|
+
document = inject(DOCUMENT);
|
|
1341
|
+
// Keep resolution at runtime to avoid Vite rewriting '.' as a filesystem asset.
|
|
1342
|
+
applicationUrl = new URL('.', new URL(import.meta.url));
|
|
1343
|
+
origin = this.applicationUrl.origin;
|
|
1344
|
+
iframeUrl = this.routeUrl('iframe', new URLSearchParams({ parentOrigin: this.document.location.origin }));
|
|
1345
|
+
examplesBaseUrl = new URL(this.config.examplesBaseUrl, this.applicationUrl).href;
|
|
1346
|
+
sourceUrl(path) {
|
|
1347
|
+
return new URL(path, this.examplesBaseUrl).href;
|
|
1348
|
+
}
|
|
1349
|
+
viewerUrl(mode, options = {}) {
|
|
1350
|
+
const parameters = new URLSearchParams({ theme: this.state.theme() });
|
|
1351
|
+
if (this.state.isRTL()) {
|
|
1352
|
+
parameters.set('isRTL', 'true');
|
|
1353
|
+
}
|
|
1354
|
+
const locale = this.state.locale();
|
|
1355
|
+
if (locale) {
|
|
1356
|
+
parameters.set('locale', locale);
|
|
1357
|
+
}
|
|
1358
|
+
const rootFontSize = this.state.rootFontSize();
|
|
1359
|
+
if (rootFontSize) {
|
|
1360
|
+
parameters.set('rfs', String(rootFontSize));
|
|
1361
|
+
}
|
|
1362
|
+
if (options.deviceMode) {
|
|
1363
|
+
parameters.set('mode', options.deviceMode);
|
|
1364
|
+
}
|
|
1365
|
+
if (!options.skipTemplate) {
|
|
1366
|
+
const framework = this.state.framework();
|
|
1367
|
+
if (framework !== 'angular') {
|
|
1368
|
+
parameters.set('t', this.state.activeWebComponentTemplate());
|
|
1369
|
+
parameters.set('framework', framework);
|
|
1370
|
+
}
|
|
1371
|
+
else if (this.state.templateModified()) {
|
|
1372
|
+
parameters.set('t', this.state.template());
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
const example = this.state.example();
|
|
1376
|
+
if (example) {
|
|
1377
|
+
parameters.set('e', example);
|
|
1378
|
+
}
|
|
1379
|
+
return this.routeUrl(`viewer/${mode}`, parameters);
|
|
1380
|
+
}
|
|
1381
|
+
issueUrl(template) {
|
|
1382
|
+
const url = new URL(this.config.ticketBaseUrl, this.document.baseURI);
|
|
1383
|
+
url.searchParams.set('issue[title]', `<${this.state.example()}>:`);
|
|
1384
|
+
url.searchParams.set('issuable_template', template);
|
|
1385
|
+
return url.href;
|
|
1386
|
+
}
|
|
1387
|
+
routeUrl(route, parameters = new URLSearchParams()) {
|
|
1388
|
+
const url = new URL(this.applicationUrl);
|
|
1389
|
+
url.hash = `/${route}${parameters.size ? '?' + parameters : ''}`;
|
|
1390
|
+
return url.href;
|
|
1391
|
+
}
|
|
1392
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LivePreviewUrlService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1393
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LivePreviewUrlService, providedIn: 'root' });
|
|
1394
|
+
}
|
|
1395
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LivePreviewUrlService, decorators: [{
|
|
1396
|
+
type: Injectable,
|
|
1397
|
+
args: [{ providedIn: 'root' }]
|
|
1398
|
+
}] });
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1402
|
+
* SPDX-License-Identifier: MIT
|
|
1403
|
+
*/
|
|
1404
|
+
/**
|
|
1405
|
+
* Documentation component shared with the optional elements entry point.
|
|
1406
|
+
* @internal
|
|
1407
|
+
*/
|
|
1408
|
+
class SiDocsComponentComponent {
|
|
1409
|
+
example = input('', /* @ts-ignore */
|
|
1410
|
+
...(ngDevMode ? [{ debugName: "example" }] : /* istanbul ignore next */ []));
|
|
1411
|
+
base = input('', /* @ts-ignore */
|
|
1412
|
+
...(ngDevMode ? [{ debugName: "base" }] : /* istanbul ignore next */ []));
|
|
1413
|
+
height = input(204, { ...(ngDevMode ? { debugName: "height" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
1414
|
+
theme = input(/* @ts-ignore */
|
|
1415
|
+
...(ngDevMode ? [undefined, { debugName: "theme" }] : /* istanbul ignore next */ []));
|
|
1416
|
+
state = inject(LivePreviewStateService);
|
|
1417
|
+
document = inject(DOCUMENT);
|
|
1418
|
+
host = inject(ElementRef).nativeElement;
|
|
1419
|
+
documentTheme = signal(this.readDocumentTheme(), /* @ts-ignore */
|
|
1420
|
+
...(ngDevMode ? [{ debugName: "documentTheme" }] : /* istanbul ignore next */ []));
|
|
1421
|
+
childExamples = signal([], /* @ts-ignore */
|
|
1422
|
+
...(ngDevMode ? [{ debugName: "childExamples" }] : /* istanbul ignore next */ []));
|
|
1423
|
+
previewTheme = computed(() => this.theme() ?? this.documentTheme(), /* @ts-ignore */
|
|
1424
|
+
...(ngDevMode ? [{ debugName: "previewTheme" }] : /* istanbul ignore next */ []));
|
|
1425
|
+
activeTabIndex = signal(0, /* @ts-ignore */
|
|
1426
|
+
...(ngDevMode ? [{ debugName: "activeTabIndex" }] : /* istanbul ignore next */ []));
|
|
1427
|
+
previewHeight = computed(() => {
|
|
1428
|
+
const height = this.height();
|
|
1429
|
+
return Number.isFinite(height) && height >= 0 ? height : 204;
|
|
1430
|
+
}, /* @ts-ignore */
|
|
1431
|
+
...(ngDevMode ? [{ debugName: "previewHeight" }] : /* istanbul ignore next */ []));
|
|
1432
|
+
tabs = computed(() => [
|
|
1433
|
+
...(this.example() ? [{ example: this.example(), heading: '' }] : []),
|
|
1434
|
+
...this.childExamples()
|
|
1435
|
+
], /* @ts-ignore */
|
|
1436
|
+
...(ngDevMode ? [{ debugName: "tabs" }] : /* istanbul ignore next */ []));
|
|
1437
|
+
constructor() {
|
|
1438
|
+
const readTabs = () => {
|
|
1439
|
+
this.childExamples.set(Array.from(this.host.querySelectorAll(':scope > si-docs-tab[example]'), tab => ({
|
|
1440
|
+
example: tab.getAttribute('example') ?? '',
|
|
1441
|
+
heading: tab.getAttribute('heading') ?? ''
|
|
1442
|
+
})));
|
|
1443
|
+
};
|
|
1444
|
+
readTabs();
|
|
1445
|
+
const observer = new MutationObserver(readTabs);
|
|
1446
|
+
observer.observe(this.host, {
|
|
1447
|
+
childList: true,
|
|
1448
|
+
subtree: true,
|
|
1449
|
+
attributes: true,
|
|
1450
|
+
attributeFilter: ['example', 'heading']
|
|
1451
|
+
});
|
|
1452
|
+
const themeObserver = new MutationObserver(() => this.documentTheme.set(this.readDocumentTheme()));
|
|
1453
|
+
themeObserver.observe(this.document.body, {
|
|
1454
|
+
attributes: true,
|
|
1455
|
+
attributeFilter: ['data-md-color-scheme']
|
|
1456
|
+
});
|
|
1457
|
+
inject(DestroyRef).onDestroy(() => {
|
|
1458
|
+
observer.disconnect();
|
|
1459
|
+
themeObserver.disconnect();
|
|
1460
|
+
});
|
|
1461
|
+
effect(() => {
|
|
1462
|
+
this.tabs();
|
|
1463
|
+
this.activeTabIndex.set(0);
|
|
1464
|
+
});
|
|
1465
|
+
effect(() => {
|
|
1466
|
+
const tab = this.tabs()[this.activeTabIndex()];
|
|
1467
|
+
const base = this.base().replace(/\/$/, '');
|
|
1468
|
+
this.state.clearTemplates();
|
|
1469
|
+
this.state.example.set(tab ? `${base ? base + '/' : ''}${tab.example}` : '');
|
|
1470
|
+
});
|
|
1471
|
+
effect(() => {
|
|
1472
|
+
this.state.theme.set(this.previewTheme());
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
readDocumentTheme() {
|
|
1476
|
+
return this.document.body.getAttribute('data-md-color-scheme') === 'dark' ? 'dark' : 'light';
|
|
1477
|
+
}
|
|
1478
|
+
activateTab(index, focus = false) {
|
|
1479
|
+
this.activeTabIndex.set(index);
|
|
1480
|
+
if (focus) {
|
|
1481
|
+
this.host.shadowRoot?.querySelector(`#example-tab-${index}`)?.focus();
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiDocsComponentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1485
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: SiDocsComponentComponent, isStandalone: true, selector: "si-docs-component", inputs: { example: { classPropertyName: "example", publicName: "example", isSignal: true, isRequired: false, transformFunction: null }, base: { classPropertyName: "base", publicName: "base", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, theme: { classPropertyName: "theme", publicName: "theme", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.--preview-height": "previewHeight() + \"px\"" } }, providers: [LivePreviewStateService, LivePreviewUrlService], ngImport: i0, template: "<slot hidden></slot>\n@defer (on viewport) {\n @if (tabs().length > 1) {\n <div role=\"tablist\" class=\"lp-tabs\" aria-label=\"Examples\">\n @for (tab of tabs(); track $index) {\n <button\n type=\"button\"\n role=\"tab\"\n class=\"tab-item tab-link\"\n aria-controls=\"example-panel\"\n [id]=\"'example-tab-' + $index\"\n [class.tab-active]=\"activeTabIndex() === $index\"\n [attr.aria-selected]=\"activeTabIndex() === $index\"\n [tabIndex]=\"activeTabIndex() === $index ? 0 : -1\"\n (click)=\"activateTab($index)\"\n (keydown.arrowRight)=\"activateTab(($index + 1) % $count, true); $event.preventDefault()\"\n (keydown.arrowLeft)=\"\n activateTab(($index + $count - 1) % $count, true); $event.preventDefault()\n \"\n (keydown.home)=\"activateTab(0, true); $event.preventDefault()\"\n (keydown.end)=\"activateTab($count - 1, true); $event.preventDefault()\"\n >\n {{ tab.heading || tab.example }}\n </button>\n }\n </div>\n }\n <div\n id=\"example-panel\"\n class=\"preview\"\n [attr.role]=\"tabs().length > 1 ? 'tabpanel' : null\"\n [attr.aria-labelledby]=\"tabs().length > 1 ? 'example-tab-' + activeTabIndex() : null\"\n >\n <si-live-preview class=\"embedded\" [initialTheme]=\"previewTheme()\" />\n </div>\n} @placeholder {\n <div class=\"preview placeholder\" aria-hidden=\"true\"></div>\n}\n", styles: [".lp-tabs{display:flex;flex-wrap:wrap;padding-inline-start:0;margin:0;list-style:none;background:none;inline-size:inherit;font-weight:700}.lp-tabs .tab-item:focus-visible{outline-offset:calc(-1 * var(--si-sys-sizing-focus-ring-width, 2px))}.lp-tabs .tab-item.tab-active.tab-link{color:var(--si-sys-color-text-accent);border-block-end-color:var(--si-sys-color-text-accent)!important}.lp-tabs .tab-item.tab-active.tab-link:hover{color:var(--si-sys-color-text-accent-hover)}.lp-tabs .tab-item.tab-link{font:inherit;background:none;min-inline-size:150px;display:block;padding-block:8px;padding-inline:15px;cursor:pointer;text-align:start;line-height:20px;color:var(--si-sys-color-text-primary);border:0;border-block-end:4px solid transparent}.lp-tabs .tab-item.tab-link:hover{text-decoration:none;color:var(--si-sys-color-text-accent-hover);border-block-end-color:var(--si-sys-color-border-4)}:host{display:block;box-sizing:border-box;inline-size:100%;border:1px solid var(--si-sys-color-border-4);color:var(--si-sys-color-text-primary);background:var(--si-sys-color-background-0)}*,*:before,*:after{box-sizing:border-box}button,select,textarea{font:inherit}button{cursor:pointer}.preview{display:flex;flex-direction:column}.placeholder{block-size:var(--preview-height, 204px)}.lp-tabs{border-block-end:1px solid var(--si-sys-color-border-4)}\n"], encapsulation: i0.ViewEncapsulation.ShadowDom, deferBlockDependencies: [() => [/* @ts-ignore */
|
|
1486
|
+
import('./siemens-live-preview-si-live-preview.component-BkiFwumB.mjs').then(m => m.SiLivePreviewComponent)]] });
|
|
1487
|
+
}
|
|
1488
|
+
i0.ɵɵngDeclareClassMetadataAsync({ minVersion: "18.0.0", version: "22.0.8", ngImport: i0, type: SiDocsComponentComponent, resolveDeferredDeps: () => [/* @ts-ignore */
|
|
1489
|
+
import('./siemens-live-preview-si-live-preview.component-BkiFwumB.mjs').then(m => m.SiLivePreviewComponent)], resolveMetadata: SiLivePreviewComponent => ({ decorators: [{
|
|
1490
|
+
type: Component,
|
|
1491
|
+
args: [{ selector: 'si-docs-component', imports: [SiLivePreviewComponent], providers: [LivePreviewStateService, LivePreviewUrlService], encapsulation: ViewEncapsulation.ShadowDom, host: {
|
|
1492
|
+
'[style.--preview-height]': 'previewHeight() + "px"'
|
|
1493
|
+
}, template: "<slot hidden></slot>\n@defer (on viewport) {\n @if (tabs().length > 1) {\n <div role=\"tablist\" class=\"lp-tabs\" aria-label=\"Examples\">\n @for (tab of tabs(); track $index) {\n <button\n type=\"button\"\n role=\"tab\"\n class=\"tab-item tab-link\"\n aria-controls=\"example-panel\"\n [id]=\"'example-tab-' + $index\"\n [class.tab-active]=\"activeTabIndex() === $index\"\n [attr.aria-selected]=\"activeTabIndex() === $index\"\n [tabIndex]=\"activeTabIndex() === $index ? 0 : -1\"\n (click)=\"activateTab($index)\"\n (keydown.arrowRight)=\"activateTab(($index + 1) % $count, true); $event.preventDefault()\"\n (keydown.arrowLeft)=\"\n activateTab(($index + $count - 1) % $count, true); $event.preventDefault()\n \"\n (keydown.home)=\"activateTab(0, true); $event.preventDefault()\"\n (keydown.end)=\"activateTab($count - 1, true); $event.preventDefault()\"\n >\n {{ tab.heading || tab.example }}\n </button>\n }\n </div>\n }\n <div\n id=\"example-panel\"\n class=\"preview\"\n [attr.role]=\"tabs().length > 1 ? 'tabpanel' : null\"\n [attr.aria-labelledby]=\"tabs().length > 1 ? 'example-tab-' + activeTabIndex() : null\"\n >\n <si-live-preview class=\"embedded\" [initialTheme]=\"previewTheme()\" />\n </div>\n} @placeholder {\n <div class=\"preview placeholder\" aria-hidden=\"true\"></div>\n}\n", styles: [".lp-tabs{display:flex;flex-wrap:wrap;padding-inline-start:0;margin:0;list-style:none;background:none;inline-size:inherit;font-weight:700}.lp-tabs .tab-item:focus-visible{outline-offset:calc(-1 * var(--si-sys-sizing-focus-ring-width, 2px))}.lp-tabs .tab-item.tab-active.tab-link{color:var(--si-sys-color-text-accent);border-block-end-color:var(--si-sys-color-text-accent)!important}.lp-tabs .tab-item.tab-active.tab-link:hover{color:var(--si-sys-color-text-accent-hover)}.lp-tabs .tab-item.tab-link{font:inherit;background:none;min-inline-size:150px;display:block;padding-block:8px;padding-inline:15px;cursor:pointer;text-align:start;line-height:20px;color:var(--si-sys-color-text-primary);border:0;border-block-end:4px solid transparent}.lp-tabs .tab-item.tab-link:hover{text-decoration:none;color:var(--si-sys-color-text-accent-hover);border-block-end-color:var(--si-sys-color-border-4)}:host{display:block;box-sizing:border-box;inline-size:100%;border:1px solid var(--si-sys-color-border-4);color:var(--si-sys-color-text-primary);background:var(--si-sys-color-background-0)}*,*:before,*:after{box-sizing:border-box}button,select,textarea{font:inherit}button{cursor:pointer}.preview{display:flex;flex-direction:column}.placeholder{block-size:var(--preview-height, 204px)}.lp-tabs{border-block-end:1px solid var(--si-sys-color-border-4)}\n"] }]
|
|
1494
|
+
}], ctorParameters: () => [], propDecorators: { example: [{ type: i0.Input, args: [{ isSignal: true, alias: "example", required: false }] }], base: [{ type: i0.Input, args: [{ isSignal: true, alias: "base", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], theme: [{ type: i0.Input, args: [{ isSignal: true, alias: "theme", required: false }] }] } }) });
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1498
|
+
* SPDX-License-Identifier: MIT
|
|
1499
|
+
*/
|
|
1500
|
+
/** Injection token to configure the open in Stackblitz button. */
|
|
1501
|
+
const SI_STACKBLITZ_CONFIG = new InjectionToken('SI_STACKBLITZ_CONFIG');
|
|
1502
|
+
/** Provides the Stackblitz configuration with default template projects. */
|
|
1503
|
+
const provideStackblitzConfig = (config) => ({
|
|
1504
|
+
provide: SI_STACKBLITZ_CONFIG,
|
|
1505
|
+
useFactory: () => {
|
|
1506
|
+
return { templates: [angularTemplateProject()], ...config };
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
/**
|
|
1510
|
+
* Create default Angular template project config.
|
|
1511
|
+
* The files are loaded from the assets folder, consumers need to add the following asset configuration
|
|
1512
|
+
* to their angular.json file:
|
|
1513
|
+
*
|
|
1514
|
+
* ```json
|
|
1515
|
+
* "assets": [
|
|
1516
|
+
* ...
|
|
1517
|
+
* {
|
|
1518
|
+
* "glob": "**\/*",
|
|
1519
|
+
* "input": "projects/live-preview/assets/",
|
|
1520
|
+
* "output": "/assets/"
|
|
1521
|
+
* }]
|
|
1522
|
+
* ```
|
|
1523
|
+
*/
|
|
1524
|
+
const angularTemplateProject = () => ({
|
|
1525
|
+
name: 'angular',
|
|
1526
|
+
assetUrl: 'assets/angular',
|
|
1527
|
+
files: [
|
|
1528
|
+
'angular.json',
|
|
1529
|
+
'package.json',
|
|
1530
|
+
'tsconfig.json',
|
|
1531
|
+
'tsconfig.app.json',
|
|
1532
|
+
'src/index.html',
|
|
1533
|
+
'src/main.ts',
|
|
1534
|
+
'src/app/app.component.ts',
|
|
1535
|
+
'src/app/example.component.ts',
|
|
1536
|
+
'src/styles.scss'
|
|
1537
|
+
]
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
/**
|
|
1541
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1542
|
+
* SPDX-License-Identifier: MIT
|
|
1543
|
+
*/
|
|
1544
|
+
class SiLivePreviewModule {
|
|
1545
|
+
static forRoot(config, isMobile = false) {
|
|
1546
|
+
return {
|
|
1547
|
+
ngModule: SiLivePreviewModule,
|
|
1548
|
+
providers: [
|
|
1549
|
+
{ provide: SI_LIVE_PREVIEW_CONFIG, useValue: config },
|
|
1550
|
+
{
|
|
1551
|
+
provide: SI_LIVE_PREVIEW_INTERNALS,
|
|
1552
|
+
useValue: { isMobile, titleBase: 'Overview - Live Preview' }
|
|
1553
|
+
}
|
|
1554
|
+
]
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1558
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewModule });
|
|
1559
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewModule, providers: [{ provide: REMOVE_STYLES_ON_COMPONENT_DESTROY, useValue: true }] });
|
|
1560
|
+
}
|
|
1561
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: SiLivePreviewModule, decorators: [{
|
|
1562
|
+
type: NgModule,
|
|
1563
|
+
args: [{
|
|
1564
|
+
providers: [{ provide: REMOVE_STYLES_ON_COMPONENT_DESTROY, useValue: true }]
|
|
1565
|
+
}]
|
|
1566
|
+
}] });
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* Copyright (c) Siemens 2016 - 2026
|
|
1570
|
+
* SPDX-License-Identifier: MIT
|
|
1571
|
+
*/
|
|
1572
|
+
// Public API Surface
|
|
1573
|
+
|
|
1574
|
+
/**
|
|
1575
|
+
* Generated bundle index. Do not edit.
|
|
1576
|
+
*/
|
|
1577
|
+
|
|
1578
|
+
export { ExampleRouteController as E, LivePreviewStateService as L, SI_LIVE_PREVIEW_CONFIG as S, SI_LIVE_PREVIEW_INTERNALS as a, SiExampleHeaderComponent as b, LivePreviewUrlService as c, SI_STACKBLITZ_CONFIG as d, SiLivePreviewLocaleApi as e, LOG_EVENT as f, LandscapeSupportService as g, SI_LIVE_PREVIEW_EXAMPLE_ROUTES as h, SiDocsComponentComponent as i, SiDummyComponent as j, SiLivePreviewApplicationRuntimeComponent as k, SiLivePreviewModule as l, SiLivePreviewRoutingModule as m, SiLivePreviewRuntimeComponent as n, SiLivePreviewThemeApi as o, SiLivePreviewWebComponentService as p, angularTemplateProject as q, livePreviewRoutes as r, provideExampleRoutes as s, provideLivePreview as t, provideStackblitzConfig as u };
|
|
1579
|
+
//# sourceMappingURL=siemens-live-preview-siemens-live-preview-BU--ZYJz.mjs.map
|