@bigbinary/neeto-image-uploader-frontend 1.4.13 → 1.4.15

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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { createContext, PureComponent, useState, useRef, useMemo, useReducer, useEffect, useCallback, forwardRef, useImperativeHandle, Fragment } from 'react';
2
2
  import { mergeRight, isNil, isEmpty, equals, mergeLeft, concat, __, inc, pipe, values, flatten as flatten$1, join, not } from 'ramda';
3
3
  import { noop as noop$1, isNotEmpty, keysToCamelCase, findBy } from '@bigbinary/neeto-cist';
4
- import { Checkbox, Typography, Input, Button, Toastr, Spinner, Modal as Modal$1, Tab } from '@bigbinary/neetoui';
4
+ import { Switch, Typography, Input, Button, Toastr, Spinner, Modal as Modal$1, Tab } from '@bigbinary/neetoui';
5
5
  import { useTranslation, Trans } from 'react-i18next';
6
6
  import classNames from 'classnames';
7
7
  import { LeftArrow, ImageUpload as ImageUpload$1 } from '@bigbinary/neeto-icons';
@@ -2357,11 +2357,11 @@ var Controls = function Controls(_ref) {
2357
2357
  setAspectRatio = _ref.setAspectRatio,
2358
2358
  setAspectRatioLocked = _ref.setAspectRatioLocked,
2359
2359
  setCrop = _ref.setCrop,
2360
- imageRef = _ref.imageRef;
2360
+ imageRef = _ref.imageRef,
2361
+ isFullImage = _ref.isFullImage,
2362
+ setIsFullImage = _ref.setIsFullImage;
2361
2363
  var _useTranslation = useTranslation(),
2362
2364
  t = _useTranslation.t;
2363
- // const [imageQuality, setImageQuality] = useState("50"); //TODO: Implement image quality
2364
-
2365
2365
  var _useImageControls = useImageControls({
2366
2366
  isAspectRatioLocked: isAspectRatioLocked,
2367
2367
  setAspectRatioLocked: setAspectRatioLocked,
@@ -2378,9 +2378,19 @@ var Controls = function Controls(_ref) {
2378
2378
  handleAspectHeightChange = _useImageControls.handleAspectHeightChange;
2379
2379
  return /*#__PURE__*/React.createElement("div", {
2380
2380
  className: "flex w-1/4 flex-col overflow-scroll pl-6 pt-8"
2381
- }, /*#__PURE__*/React.createElement(Checkbox, {
2382
- checked: isAspectRatioLocked,
2381
+ }, /*#__PURE__*/React.createElement(Switch, {
2382
+ checked: isFullImage,
2383
2383
  className: "flex-grow-0",
2384
+ label: t("neetoImageUploader.labels.selectOriginalImage"),
2385
+ onChange: function onChange() {
2386
+ return setIsFullImage(function (isFullImage) {
2387
+ return !isFullImage;
2388
+ });
2389
+ }
2390
+ }), /*#__PURE__*/React.createElement(Switch, {
2391
+ checked: isAspectRatioLocked,
2392
+ className: "mt-4 flex-grow-0",
2393
+ disabled: isFullImage,
2384
2394
  label: t("neetoImageUploader.labels.lockAspectRatio"),
2385
2395
  onChange: onToggleAspectRatioLock
2386
2396
  }), /*#__PURE__*/React.createElement(Typography, {
@@ -2389,23 +2399,27 @@ var Controls = function Controls(_ref) {
2389
2399
  }, t("neetoImageUploader.imageEditor.aspetRatio")), /*#__PURE__*/React.createElement("div", {
2390
2400
  className: "flex gap-4 self-start"
2391
2401
  }, /*#__PURE__*/React.createElement(Input, {
2402
+ disabled: isFullImage,
2392
2403
  size: "small",
2393
2404
  type: "number",
2394
2405
  value: aspectRatio.width,
2395
2406
  onChange: withEventTargetValue(handleAspectWidthChange)
2396
2407
  }), /*#__PURE__*/React.createElement(Typography, null, " : "), /*#__PURE__*/React.createElement(Input, {
2408
+ disabled: isFullImage,
2397
2409
  size: "small",
2398
2410
  type: "number",
2399
2411
  value: aspectRatio.height,
2400
2412
  onChange: withEventTargetValue(handleAspectHeightChange)
2401
2413
  })), /*#__PURE__*/React.createElement(Input, {
2402
2414
  className: "mt-4 flex-grow-0",
2415
+ disabled: isFullImage,
2403
2416
  label: t("neetoImageUploader.labels.width"),
2404
2417
  type: "number",
2405
2418
  value: crop.width.toFixed(2),
2406
2419
  onChange: withEventTargetValue(handleWidthChange)
2407
2420
  }), /*#__PURE__*/React.createElement(Input, {
2408
2421
  className: "mt-4 flex-grow-0",
2422
+ disabled: isFullImage,
2409
2423
  label: t("neetoImageUploader.labels.height"),
2410
2424
  type: "number",
2411
2425
  value: crop.height.toFixed(2),
@@ -2475,17 +2489,21 @@ var ImageEditor = function ImageEditor(_ref) {
2475
2489
  _useState2 = _slicedToArray$2(_useState, 2),
2476
2490
  isAspectRatioLocked = _useState2[0],
2477
2491
  setIsAspectRatioLocked = _useState2[1];
2478
- var _useState3 = useState({
2492
+ var _useState3 = useState(false),
2493
+ _useState4 = _slicedToArray$2(_useState3, 2),
2494
+ isFullImage = _useState4[0],
2495
+ setIsFullImage = _useState4[1];
2496
+ var _useState5 = useState({
2479
2497
  width: 16,
2480
2498
  height: 9
2481
2499
  }),
2482
- _useState4 = _slicedToArray$2(_useState3, 2),
2483
- aspectRatio = _useState4[0],
2484
- setAspectRatio = _useState4[1];
2485
- var _useState5 = useState(DEFAULT_CROP_CONFIG),
2486
2500
  _useState6 = _slicedToArray$2(_useState5, 2),
2487
- crop = _useState6[0],
2488
- setCrop = _useState6[1];
2501
+ aspectRatio = _useState6[0],
2502
+ setAspectRatio = _useState6[1];
2503
+ var _useState7 = useState(DEFAULT_CROP_CONFIG),
2504
+ _useState8 = _slicedToArray$2(_useState7, 2),
2505
+ crop = _useState8[0],
2506
+ setCrop = _useState8[1];
2489
2507
  var _useTranslation = useTranslation(),
2490
2508
  t = _useTranslation.t;
2491
2509
  var _useCropImage = useCropImage(),
@@ -2493,6 +2511,10 @@ var ImageEditor = function ImageEditor(_ref) {
2493
2511
  var imageRef = useRef(null);
2494
2512
  var wrapperRef = useRef(null);
2495
2513
  var processCrop = function processCrop() {
2514
+ if (isFullImage) {
2515
+ handleImageEditComplete(image);
2516
+ return;
2517
+ }
2496
2518
  cropImage({
2497
2519
  crop: getCropValues({
2498
2520
  crop: crop,
@@ -2508,6 +2530,10 @@ var ImageEditor = function ImageEditor(_ref) {
2508
2530
  processCrop();
2509
2531
  return;
2510
2532
  }
2533
+ if (isFullImage) {
2534
+ handleImageEditComplete(image);
2535
+ return;
2536
+ }
2511
2537
  var newURL = getCroppedImageURL({
2512
2538
  crop: crop,
2513
2539
  imageURL: image.url,
@@ -2537,7 +2563,7 @@ var ImageEditor = function ImageEditor(_ref) {
2537
2563
  })
2538
2564
  })
2539
2565
  }, /*#__PURE__*/React.createElement(ReactCrop, {
2540
- crop: crop,
2566
+ crop: isFullImage ? null : crop,
2541
2567
  src: image === null || image === void 0 ? void 0 : image.url,
2542
2568
  aspect: isAspectRatioLocked ? aspectRatio.width / aspectRatio.height : 0,
2543
2569
  onChange: setCrop,
@@ -2558,8 +2584,10 @@ var ImageEditor = function ImageEditor(_ref) {
2558
2584
  handleSubmit: handleSubmit,
2559
2585
  imageRef: imageRef,
2560
2586
  isAspectRatioLocked: isAspectRatioLocked,
2587
+ isFullImage: isFullImage,
2561
2588
  setAspectRatio: setAspectRatio,
2562
2589
  setCrop: setCrop,
2590
+ setIsFullImage: setIsFullImage,
2563
2591
  setAspectRatioLocked: setIsAspectRatioLocked
2564
2592
  })));
2565
2593
  };
@@ -6076,7 +6104,7 @@ var Modal = function Modal(_ref) {
6076
6104
  var handleImageEditComplete = function handleImageEditComplete(editedImage) {
6077
6105
  if (IS_DEVELOPMENT_OR_HEROKU_ENV) {
6078
6106
  onUploadComplete({
6079
- url: editedImage.metadata.url,
6107
+ url: editedImage.url,
6080
6108
  signedId: editedImage.signedId
6081
6109
  });
6082
6110
  } else {
@@ -6293,7 +6321,9 @@ var ImageUploader = function ImageUploader(_ref) {
6293
6321
  url: "",
6294
6322
  signedId: "",
6295
6323
  key: "",
6296
- filename: ""
6324
+ filename: "",
6325
+ size: "",
6326
+ type: ""
6297
6327
  });
6298
6328
  };
6299
6329
  var onChange = function onChange(file) {
@@ -6307,7 +6337,9 @@ var ImageUploader = function ImageUploader(_ref) {
6307
6337
  filename: attachedImage.filename,
6308
6338
  key: attachedImage.key,
6309
6339
  url: attachedImage.blobUrl,
6310
- signedId: attachedImage.signedId
6340
+ signedId: attachedImage.signedId,
6341
+ size: attachedImage.byteSize,
6342
+ type: attachedImage.contentType
6311
6343
  });
6312
6344
  setSignedId(attachedImage.signedId);
6313
6345
  setIsEditorOpen(false);
@@ -6318,7 +6350,7 @@ var ImageUploader = function ImageUploader(_ref) {
6318
6350
  setSignedId("");
6319
6351
  setIsEditorOpen(false);
6320
6352
  };
6321
- var handleUplaodComplete = function handleUplaodComplete(image) {
6353
+ var handleUploadComplete = function handleUploadComplete(image) {
6322
6354
  if (IS_DEVELOPMENT_OR_HEROKU_ENV) {
6323
6355
  handleSuccess(mergeRight(image, {
6324
6356
  metadata: {
@@ -6362,7 +6394,7 @@ var ImageUploader = function ImageUploader(_ref) {
6362
6394
  var _useDropzoneWithValid = useDropzoneWithValidation({
6363
6395
  maxSize: uploadConfigWithDefaults === null || uploadConfigWithDefaults === void 0 ? void 0 : uploadConfigWithDefaults.maxImageSize,
6364
6396
  acceptedTypes: uploadConfigWithDefaults === null || uploadConfigWithDefaults === void 0 ? void 0 : uploadConfigWithDefaults.allowedImageTypes,
6365
- onUploadComplete: handleUplaodComplete,
6397
+ onUploadComplete: handleUploadComplete,
6366
6398
  setIsUploading: setIsUploading
6367
6399
  }),
6368
6400
  getRootProps = _useDropzoneWithValid.getRootProps,
@@ -6390,7 +6422,7 @@ var ImageUploader = function ImageUploader(_ref) {
6390
6422
  className: "h-full w-auto",
6391
6423
  src: image.url
6392
6424
  })), /*#__PURE__*/React.createElement("div", {
6393
- className: "flex items-stretch justify-center gap-2"
6425
+ className: "mb-2 flex items-stretch justify-center gap-2"
6394
6426
  }, /*#__PURE__*/React.createElement(Button, {
6395
6427
  label: t("neetoImageUploader.imageUpload.assets"),
6396
6428
  style: "link",
@@ -6400,7 +6432,7 @@ var ImageUploader = function ImageUploader(_ref) {
6400
6432
  }), /*#__PURE__*/React.createElement(Button, {
6401
6433
  className: "bg-transparent p-0",
6402
6434
  "data-cy": "attachment-remove-button",
6403
- label: t("neetoImageUploader.imageUpload.delete"),
6435
+ label: t("neetoImageUploader.imageUpload.remove"),
6404
6436
  style: "danger-text",
6405
6437
  onClick: handleDelete
6406
6438
  }), not(IS_DEVELOPMENT_OR_HEROKU_ENV) && isNotEmpty(signedId) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {