create-sitecore-jss 22.2.0-canary.26 → 22.2.0-canary.28
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.
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<ng-container [ngTemplateOutlet]="variant"></ng-container>
|
|
2
|
+
|
|
3
|
+
<ng-template #default>
|
|
4
|
+
<div class="component image {{ styles }}" [attr.id]="id" *ngIf="rendering.fields; else empty">
|
|
5
|
+
<div className="component-content">
|
|
6
|
+
<ng-container *ngIf="isEditing || !rendering.fields.TargetUrl?.value?.href; else withLink">
|
|
7
|
+
<img *scImage="rendering.fields.Image" />
|
|
8
|
+
</ng-container>
|
|
9
|
+
<span class="image-caption field-imagecaption" *scText="rendering.fields.ImageCaption"></span>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
</ng-template>
|
|
13
|
+
|
|
14
|
+
<ng-template #banner>
|
|
15
|
+
<div class="component hero-banner {{ styles }} {{ classHeroBannerEmpty }}" [attr.id]="id">
|
|
16
|
+
<div class="component-content sc-sxa-image-hero-banner" [ngStyle]="backgroundStyle">
|
|
17
|
+
<ng-container *ngIf="isEditing">
|
|
18
|
+
<img *scImage="modifyImageProps" />
|
|
19
|
+
</ng-container>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</ng-template>
|
|
23
|
+
|
|
24
|
+
<ng-template #withLink>
|
|
25
|
+
<a *scLink="rendering.fields.TargetUrl">
|
|
26
|
+
<img *scImage="rendering.fields.Image" />
|
|
27
|
+
</a>
|
|
28
|
+
</ng-template>
|
|
29
|
+
|
|
30
|
+
<ng-template #empty>
|
|
31
|
+
<div className="component image {{ styles }}">
|
|
32
|
+
<div class="component-content">
|
|
33
|
+
<span class="is-empty-hint">Image</span>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</ng-template>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Component, OnInit, OnDestroy, ViewChild, TemplateRef } from '@angular/core';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { EditMode, ImageField } from '@sitecore-jss/sitecore-jss-angular';
|
|
4
|
+
import { SxaComponent } from '../sxa.component';
|
|
5
|
+
import { JssContextService } from '../../jss-context.service';
|
|
6
|
+
|
|
7
|
+
@Component({
|
|
8
|
+
selector: 'app-image',
|
|
9
|
+
templateUrl: './image.component.html',
|
|
10
|
+
})
|
|
11
|
+
export class ImageComponent extends SxaComponent implements OnInit, OnDestroy {
|
|
12
|
+
@ViewChild('default', { static: true }) defaultVariant: TemplateRef<any>;
|
|
13
|
+
@ViewChild('banner', { static: true }) bannerVariant: TemplateRef<any>;
|
|
14
|
+
classHeroBannerEmpty = '';
|
|
15
|
+
backgroundStyle = {};
|
|
16
|
+
modifyImageProps = {};
|
|
17
|
+
isEditing = false;
|
|
18
|
+
private contextSubscription: Subscription;
|
|
19
|
+
|
|
20
|
+
constructor(private jssContext: JssContextService) {
|
|
21
|
+
super();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ngOnInit() {
|
|
25
|
+
super.ngOnInit();
|
|
26
|
+
|
|
27
|
+
const imageField = this.rendering.fields?.Image as ImageField;
|
|
28
|
+
this.backgroundStyle = imageField?.value?.src && {
|
|
29
|
+
'background-image': `url('${imageField.value.src}')`,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
this.contextSubscription = this.jssContext.state.subscribe((newState) => {
|
|
33
|
+
this.isEditing = newState.sitecore && newState.sitecore.context.pageEditing;
|
|
34
|
+
|
|
35
|
+
this.classHeroBannerEmpty =
|
|
36
|
+
this.isEditing && imageField?.value?.class === 'scEmptyImage' ? 'hero-banner-empty' : '';
|
|
37
|
+
|
|
38
|
+
const isMetadataMode = newState.sitecore?.context?.editMode === EditMode.Metadata;
|
|
39
|
+
this.modifyImageProps = !isMetadataMode
|
|
40
|
+
? {
|
|
41
|
+
...imageField,
|
|
42
|
+
editable: imageField?.editable
|
|
43
|
+
?.replace(`width="${imageField?.value?.width}"`, 'width="100%"')
|
|
44
|
+
.replace(`height="${imageField?.value?.height}"`, 'height="100%"'),
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
...imageField,
|
|
48
|
+
value: {
|
|
49
|
+
...imageField?.value,
|
|
50
|
+
style: { width: '100%', height: '100%' },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
ngOnDestroy() {
|
|
57
|
+
if (this.contextSubscription) {
|
|
58
|
+
this.contextSubscription.unsubscribe();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public get variant(): TemplateRef<any> {
|
|
63
|
+
return this.rendering.params?.FieldNames === 'Banner'
|
|
64
|
+
? this.bannerVariant
|
|
65
|
+
: this.defaultVariant;
|
|
66
|
+
}
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.2.0-canary.
|
|
3
|
+
"version": "22.2.0-canary.28",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"ts-node": "^10.9.1",
|
|
64
64
|
"typescript": "~4.9.5"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "10579b9584dafc025150ee6f269d0fbe78dec256"
|
|
67
67
|
}
|