base-js-sw 1.0.8 → 1.0.9

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.
@@ -91,6 +91,7 @@ export const ImagePicker = ({
91
91
  setAttributes={setAttributes}
92
92
  imageRef={imageRef}
93
93
  buttonText={buttonText}
94
+ crop={showCrop ? undefined : false}
94
95
  />
95
96
  )}
96
97
  </div>
@@ -144,9 +145,13 @@ export const ImagePickerPreview = ({
144
145
  imageElementWrapperClass = blockClass + '__image-wrapper';
145
146
  }
146
147
 
147
- let imagecrop = crop ? '1' : '0';
148
- if (imageObject.crop) {
149
- imagecrop = imageObject.crop.replace(/\s+/g, '-');
148
+ let imagecrop;
149
+ if (crop === false) {
150
+ imagecrop = '0';
151
+ } else if (typeof imageObject.crop === 'string' && imageObject.crop !== '') {
152
+ imagecrop = imageObject.crop === '0' ? '0' : imageObject.crop.replace(/\s+/g, '-');
153
+ } else {
154
+ imagecrop = '1';
150
155
  }
151
156
 
152
157
  let imageOptionsString = `images/width=${width},height=${height},crop=${imagecrop}`;
@@ -198,6 +203,7 @@ export const ImagePickerPreview = ({
198
203
  replaceText=''
199
204
  removeText=''
200
205
  imageId={imageObject.id}
206
+ crop={crop}
201
207
  />
202
208
  </MediaUploadCheck>
203
209
  ) : ( // No image
@@ -206,6 +212,7 @@ export const ImagePickerPreview = ({
206
212
  setAttributes={setAttributes}
207
213
  imageRef={imageRef}
208
214
  buttonText={buttonText}
215
+ crop={crop}
209
216
  />
210
217
  )}
211
218
  </div>
@@ -213,11 +220,11 @@ export const ImagePickerPreview = ({
213
220
  };
214
221
 
215
222
  // ============= Image Controls (appear over image within editor)
216
- export const EditImageButtons = ({ componentClass, setAttributes, replaceText, removeText, imageRef, imageId }) => {
223
+ export const EditImageButtons = ({ componentClass, setAttributes, replaceText, removeText, imageRef, imageId, crop }) => {
217
224
  return (
218
225
  <MediaUpload
219
226
  title={'Icon'}
220
- onSelect={(media) => updateImageAttr(setAttributes, media, imageRef)}
227
+ onSelect={(media) => updateImageAttr(setAttributes, media, imageRef, crop)}
221
228
  allowedTypes={['image']}
222
229
  value={imageId}
223
230
  render={({ open }) => (
@@ -236,7 +243,7 @@ export const EditImageButtons = ({ componentClass, setAttributes, replaceText, r
236
243
  className={componentClass + "__edit-button"}
237
244
  isDestructive
238
245
  onClick={(media) => {
239
- updateImageAttr(setAttributes, false, imageRef)
246
+ updateImageAttr(setAttributes, false, imageRef, crop)
240
247
  }}
241
248
  icon="remove"
242
249
  >
@@ -248,10 +255,7 @@ export const EditImageButtons = ({ componentClass, setAttributes, replaceText, r
248
255
  )
249
256
  }
250
257
 
251
- export const UploadImageButton = ({ componentClass, setAttributes, imageRef, buttonText }) => {
252
-
253
-
254
-
258
+ export const UploadImageButton = ({ componentClass, setAttributes, imageRef, buttonText, crop }) => {
255
259
  return (
256
260
  <MediaUploadCheck>
257
261
  <MediaUpload
@@ -287,20 +291,25 @@ const updateImageAttr = (
287
291
  setAttributes,
288
292
  media = false,
289
293
  imageRef,
294
+ crop = 'center center'
290
295
  ) => {
291
-
292
296
  imageRef ??= 'imageObject';
293
297
 
294
- let newImageUrl = media ? media.sizes.full.url : ''
298
+ let newImageUrl = media ? (media.sizes?.full?.url || media.url) : '';
295
299
 
300
+ let newImage = {
301
+ id: media ? media.id : 0,
302
+ url: newImageUrl,
303
+ alt: media ? media.alt : '',
304
+ };
305
+
306
+ if (crop === false) {
307
+ newImage.crop = '0';
308
+ } else {
309
+ newImage.crop = typeof crop === 'string' ? crop : 'center center';
310
+ }
296
311
 
297
312
  setAttributes({
298
- [imageRef]: {
299
- id: media.id,
300
- url: newImageUrl,
301
- alt: media.alt,
302
- crop: 'center center'
303
- },
313
+ [imageRef]: newImage,
304
314
  });
305
315
  };
306
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "base-js-sw",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Reusable Gutenberg block components for WordPress projects",
5
5
  "main": "index.js",
6
6
  "author": "Shape Works",