Skip to content

Commit a2b5e95

Browse files
ValJedboutell
andauthored
fixes widgetOptions not being used when passed from props (widget con… (#5046)
* fixes widgetOptions not being used when passed from props (widget controls adjust image) * removed useless method * adds changelog --------- Co-authored-by: Tom Boutell <tom@apostrophecms.com>
1 parent f3bab99 commit a2b5e95

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Make conditional fields work in Image Editor.
1818
* Importing a custom icon from an npm module using a `~` path per the admin UI now works per the documentation, as long as the Vue component used for the icon is structured like those found in `@apostrophecms/vue-material-design-icons`.
1919
* The `button: true` flag works again for piece module utility operations. Previously the button appeared but did not trigger the desired operation.
20+
* Fix the fact that area options `minSize` and `aspectRatio` weren't passed to the image cropper when coming directly from the area and the widget controls (without passing through the widget editor).
2021
* Fixes the widget data being cloned to be saved before the `postprocess` method being called, which leads to a loss of data in `AposWidgetEditor` (like the autocrop data).
2122
* In editors like `AposWidgetEditor` relationships are now post processed after they are updated in `AposInputRelationship` only for the relationship that has been updated.
2223
It allows live preview to work well with it, it also avoids complexity and fixes updated data not being properly synced between the editor and the `AposSchema`.

modules/@apostrophecms/image/ui/apos/components/AposImageRelationshipEditor.vue

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</label>
4343
<AposSelect
4444
:selected="aspectRatio"
45-
:choices="aspectRatios"
45+
:choices="aspectRatioChoices"
4646
:disabled="disableAspectRatio"
4747
@change="updateAspectRatio"
4848
/>
@@ -140,7 +140,11 @@ export default {
140140
},
141141
widgetSchema: {
142142
type: Array,
143-
default: () => ([])
143+
default: () => []
144+
},
145+
widgetOptions: {
146+
type: Object,
147+
default: null
144148
},
145149
item: {
146150
type: Object,
@@ -149,8 +153,13 @@ export default {
149153
},
150154
emits: [ 'modal-result' ],
151155
data() {
152-
const { aspectRatio, disableAspectRatio } = this.getAspectRatioFromConfig();
153-
const minSize = this.getMinSize();
156+
const widgetOptions = this.getWidgetOptions();
157+
const {
158+
aspectRatio,
159+
aspectRatioChoices,
160+
disableAspectRatio
161+
} = this.getAspectRatioData(widgetOptions);
162+
const minSize = this.widgetOptions.minSize || [];
154163
const image = this.getImage();
155164
const data = this.setDataValues(image);
156165
@@ -173,7 +182,7 @@ export default {
173182
},
174183
currentTab: null,
175184
aspectRatio,
176-
aspectRatios: getAspectRatios(this.$t('apostrophe:aspectRatioFree')),
185+
aspectRatioChoices,
177186
disableAspectRatio,
178187
minSize,
179188
correctingSizes: false,
@@ -201,6 +210,14 @@ export default {
201210
this.computeMinSizes();
202211
},
203212
methods: {
213+
getWidgetOptions() {
214+
if (this.widgetOptions) {
215+
return this.widgetOptions;
216+
}
217+
218+
const [ widgetOptions = {} ] = apos.area.widgetOptions || [];
219+
return widgetOptions;
220+
},
204221
getImage() {
205222
return this.item || this.widget?._image?.[0];
206223
},
@@ -254,8 +271,8 @@ export default {
254271
return;
255272
}
256273
257-
// If ratio wants a square, we simply take the higher min size of the
258-
// image
274+
// If ratio wants a square,
275+
// we simply take the higher min size of the image
259276
if (this.aspectRatio === 1) {
260277
const higherValue = minWidth > minHeight ? minWidth : minHeight;
261278
this.minWidth = higherValue;
@@ -425,29 +442,34 @@ export default {
425442
switchPane(name) {
426443
this.currentTab = name;
427444
},
428-
getAspectRatioFromConfig() {
429-
const [ widgetOptions = {} ] = apos.area.widgetOptions || [];
430-
431-
return widgetOptions.aspectRatio && widgetOptions.aspectRatio.length === 2
432-
? {
433-
aspectRatio: widgetOptions.aspectRatio[0] / widgetOptions.aspectRatio[1],
434-
disableAspectRatio: true
435-
}
436-
: {
445+
getAspectRatioData(widgetOptions = {}) {
446+
if (
447+
!Array.isArray(widgetOptions.aspectRatio) ||
448+
widgetOptions.aspectRatio.length !== 2
449+
) {
450+
return {
437451
aspectRatio: null,
438-
disableAspectRatio: false
452+
disableAspectRatio: false,
453+
aspectRatioChoices: getAspectRatios(this.$t('apostrophe:aspectRatioFree'))
439454
};
455+
}
456+
457+
const [ x, y ] = widgetOptions.aspectRatio;
458+
const aspectRatio = x / y;
459+
return {
460+
aspectRatio,
461+
disableAspectRatio: true,
462+
aspectRatioChoices: [ {
463+
label: `${x}:${y}`,
464+
value: aspectRatio
465+
} ]
466+
};
440467
},
441468
updateAspectRatio(value) {
442469
this.aspectRatio = value;
443470
this.computeMaxSizes();
444471
this.computeMinSizes();
445472
},
446-
getMinSize() {
447-
const [ widgetOptions = {} ] = apos.area.widgetOptions;
448-
449-
return widgetOptions.minSize || [];
450-
},
451473
computeAspectRatio(value, name) {
452474
if (!this.aspectRatio) {
453475
return;

0 commit comments

Comments
 (0)