componentes-sinco 1.0.19 → 1.0.21

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.cjs CHANGED
@@ -55,6 +55,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
55
  mod
56
56
  ));
57
57
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
58
78
 
59
79
  // src/index.ts
60
80
  var src_exports = {};
@@ -453,6 +473,7 @@ var Attachment = ({
453
473
  onLoading,
454
474
  onChange,
455
475
  downloadAction,
476
+ deleteAction,
456
477
  initialFiles = []
457
478
  }) => {
458
479
  const [files, setFiles] = (0, import_react5.useState)([]);
@@ -463,17 +484,9 @@ var Attachment = ({
463
484
  const inputRef = (0, import_react5.useRef)(null);
464
485
  (0, import_react5.useEffect)(() => {
465
486
  if (initialFiles.length > 0) {
466
- const initials = initialFiles.map((f) => {
467
- var _a, _b;
468
- return __spreadProps(__spreadValues({}, f), {
469
- progress: (_a = f.progress) != null ? _a : 100,
470
- uploadError: (_b = f.uploadError) != null ? _b : false
471
- });
472
- });
473
- setFiles(initials);
474
- onChange == null ? void 0 : onChange(initials.map((f) => new File([], f.name, { type: f.type })));
487
+ setFiles(initialFiles);
475
488
  }
476
- }, []);
489
+ }, [initialFiles]);
477
490
  const handleDrop = (event2) => {
478
491
  event2.preventDefault();
479
492
  setIsDragFile(false);
@@ -738,7 +751,7 @@ var Attachment = ({
738
751
  },
739
752
  file.uploadError && file.size / (1024 * 1024) > maxSize ? "Archivo super\xF3 el l\xEDmite \u2022 Carga fallida" : file.uploadError ? "Archivo duplicado o inv\xE1lido \u2022 Carga fallida" : `${(file.size / (1024 * 1024)).toFixed(2)}MB \u2022 ${file.type}`
740
753
  ))),
741
- /* @__PURE__ */ import_react5.default.createElement(import_material3.Tooltip, { title: "Descargar" }, /* @__PURE__ */ import_react5.default.createElement(import_material3.IconButton, { size: "small", onClick: downloadAction }, /* @__PURE__ */ import_react5.default.createElement(import_icons_material5.FileDownload, { fontSize: "small", color: "action" }))),
754
+ /* @__PURE__ */ import_react5.default.createElement(import_material3.Tooltip, { title: "Descargar" }, /* @__PURE__ */ import_react5.default.createElement(import_material3.IconButton, { size: "small", onClick: () => downloadAction == null ? void 0 : downloadAction(file.name) }, /* @__PURE__ */ import_react5.default.createElement(import_icons_material5.FileDownload, { fontSize: "small", color: "action" }))),
742
755
  /* @__PURE__ */ import_react5.default.createElement(import_material3.Tooltip, { title: "Eliminar" }, /* @__PURE__ */ import_react5.default.createElement(
743
756
  import_material3.IconButton,
744
757
  {
@@ -762,18 +775,30 @@ var Attachment = ({
762
775
  action: [
763
776
  {
764
777
  text: "Eliminar",
765
- fn: () => {
778
+ fn: () => __async(void 0, null, function* () {
766
779
  if (fileToDelete) {
767
- deleteFiles(fileToDelete.name);
768
- setFileToDelete(null);
769
- setToast({
770
- title: "Archivo eliminado",
771
- type: "success",
772
- time: 2
773
- });
780
+ try {
781
+ if (deleteAction) {
782
+ yield deleteAction(fileToDelete.name);
783
+ }
784
+ deleteFiles(fileToDelete.name);
785
+ setToast({
786
+ title: "Archivo eliminado",
787
+ type: "success",
788
+ time: 2
789
+ });
790
+ } catch (error2) {
791
+ setToast({
792
+ title: "Error al eliminar archivo",
793
+ type: "error",
794
+ time: 4
795
+ });
796
+ } finally {
797
+ setFileToDelete(null);
798
+ setOpenModal(false);
799
+ }
774
800
  }
775
- setOpenModal(false);
776
- }
801
+ })
777
802
  }
778
803
  ]
779
804
  }