@pnkx-lib/ui 1.9.465 → 1.9.467

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.
@@ -1,4 +1,4 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { Modal, Spin } from 'antd';
3
3
  import * as React from 'react';
4
4
  import React__default, { isValidElement, version as version$1, useRef, useLayoutEffect, useEffect, Component, useContext, forwardRef, useMemo as useMemo$1, useState, Children, useImperativeHandle } from 'react';
@@ -13,7 +13,7 @@ import { R as RefIcon$7 } from '../chunks/LoadingOutlined-C5-PNVpb.js';
13
13
  import { R as RefIcon$8, a as RefIcon$a } from '../chunks/CloseCircleFilled-4jnV3XJV.js';
14
14
  import { R as RefIcon$9 } from '../chunks/CloseOutlined-DdLJZQvZ.js';
15
15
  import { C as Controller } from '../chunks/index.esm-Dr5ZHcf7.js';
16
- import { ViewPdf } from './ViewPdf.js';
16
+ import { toast } from '@pnkx-lib/core';
17
17
  import { R as RefIcon$b } from '../chunks/InboxOutlined-W7xl_mLq.js';
18
18
 
19
19
  // This icon file is generated automatically.
@@ -11480,13 +11480,11 @@ function GenericUploadModal({
11480
11480
  control,
11481
11481
  setFileList,
11482
11482
  record,
11483
- fileList,
11484
11483
  allowedExtensions,
11485
11484
  maxSize = 5,
11486
11485
  texts
11487
11486
  }) {
11488
11487
  const [displayFileList, setDisplayFileList] = useState([]);
11489
- const [previewPdf, setPreviewPdf] = useState(null);
11490
11488
  useEffect(() => {
11491
11489
  if (open) {
11492
11490
  const recordFiles = record?.map((item) => ({
@@ -11505,17 +11503,17 @@ function GenericUploadModal({
11505
11503
  showUploadList: true,
11506
11504
  fileList: displayFileList,
11507
11505
  beforeUpload: async (file) => {
11508
- const isLtMax = file.size / 1024 / 1024 < maxSize;
11506
+ const isLtMax = file.size / 1024 / 1024 <= maxSize;
11509
11507
  const fileExtension = file.name.split(".").pop()?.toLowerCase() || "";
11510
- if (!allowedExtensions.includes(fileExtension)) {
11511
- Modal.error({
11512
- content: texts?.fileTypeError ?? "File type not allowed"
11513
- });
11514
- return false;
11508
+ if (allowedExtensions.includes(fileExtension) && texts?.fileTypeError) {
11509
+ toast.warning(texts?.fileTypeError);
11510
+ return;
11515
11511
  }
11516
11512
  if (!isLtMax) {
11517
- Modal.error({ content: texts?.fileSizeError ?? "File too large" });
11518
- return false;
11513
+ toast.warning(
11514
+ texts?.fileSizeError ?? `File must be smaller than ${maxSize}MB`
11515
+ );
11516
+ return;
11519
11517
  }
11520
11518
  const newFile = {
11521
11519
  uid: file.uid,
@@ -11524,25 +11522,25 @@ function GenericUploadModal({
11524
11522
  originFileObj: file
11525
11523
  };
11526
11524
  const newList = [...displayFileList, newFile];
11527
- setDisplayFileList(newList);
11525
+ setDisplayFileList((prev) => {
11526
+ const newList2 = [...prev, newFile];
11527
+ setFileList(newList2);
11528
+ onChange(newList2);
11529
+ return newList2;
11530
+ });
11528
11531
  setFileList(newList);
11529
11532
  onChange(newList);
11530
11533
  return false;
11531
11534
  },
11532
11535
  onPreview: (file) => {
11533
11536
  const fileUrl = file.url || (file.originFileObj ? URL.createObjectURL(file.originFileObj) : "");
11534
- const extension = file.name?.split(".").pop()?.toLowerCase();
11535
- if (extension === "pdf") {
11536
- setPreviewPdf(fileUrl);
11537
- } else {
11538
- const link = document.createElement("a");
11539
- link.href = fileUrl;
11540
- link.download = file.name || "download";
11541
- link.target = "_blank";
11542
- document.body.appendChild(link);
11543
- link.click();
11544
- document.body.removeChild(link);
11545
- }
11537
+ const link = document.createElement("a");
11538
+ link.href = fileUrl;
11539
+ link.download = file.name || "download";
11540
+ link.target = "_blank";
11541
+ document.body.appendChild(link);
11542
+ link.click();
11543
+ document.body.removeChild(link);
11546
11544
  },
11547
11545
  onRemove: (file) => {
11548
11546
  const newList = displayFileList.filter((item) => item.uid !== file.uid);
@@ -11552,7 +11550,7 @@ function GenericUploadModal({
11552
11550
  return true;
11553
11551
  }
11554
11552
  });
11555
- return /* @__PURE__ */ jsxs(
11553
+ return /* @__PURE__ */ jsx(
11556
11554
  Modal,
11557
11555
  {
11558
11556
  open,
@@ -11563,39 +11561,23 @@ function GenericUploadModal({
11563
11561
  onOk: onCancel,
11564
11562
  width: 800,
11565
11563
  centered: true,
11566
- children: [
11567
- previewPdf && /* @__PURE__ */ jsx(
11568
- ViewPdf,
11569
- {
11570
- workerUrl: "https://unpkg.com/pdfjs-dist@3.4.120/build/pdf.worker.min.js",
11571
- fileUrl: previewPdf
11572
- }
11573
- ),
11574
- /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsx(
11575
- Controller,
11576
- {
11577
- name: "file",
11578
- control,
11579
- render: ({ field }) => {
11580
- const { onChange } = field;
11581
- const props = createUploadProps(onChange);
11582
- return /* @__PURE__ */ jsx(Spin, { spinning: false, tip: texts?.uploading ?? "Uploading...", children: /* @__PURE__ */ jsxs(
11583
- Dragger,
11584
- {
11585
- ...props,
11586
- accept: allowedExtensions.map((ext) => `.${ext}`).join(","),
11587
- children: [
11588
- /* @__PURE__ */ jsx("p", { className: "ant-upload-drag-icon", children: /* @__PURE__ */ jsx(RefIcon$b, {}) }),
11589
- /* @__PURE__ */ jsx("p", { className: "ant-upload-text", children: texts?.dragText ?? "Click or drag files to this area to upload" }),
11590
- /* @__PURE__ */ jsx("p", { className: "ant-upload-hint", children: texts?.hint1 ?? "Max size 5MB" }),
11591
- /* @__PURE__ */ jsx("p", { className: "ant-upload-hint", children: texts?.hint2 ?? "Supported formats: " + allowedExtensions.join(", ") })
11592
- ]
11593
- }
11594
- ) });
11595
- }
11564
+ children: /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsx(
11565
+ Controller,
11566
+ {
11567
+ name: "file",
11568
+ control,
11569
+ render: ({ field }) => {
11570
+ const { onChange } = field;
11571
+ const props = createUploadProps(onChange);
11572
+ return /* @__PURE__ */ jsx(Spin, { spinning: false, tip: texts?.uploading ?? "Uploading...", children: /* @__PURE__ */ jsxs(Dragger, { ...props, accept: ".pdf,.docx,image/*", children: [
11573
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-drag-icon", children: /* @__PURE__ */ jsx(RefIcon$b, {}) }),
11574
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-text", children: texts?.dragText ?? "Click or drag files to this area to upload" }),
11575
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-hint", children: texts?.hint1 ?? "Max size 5MB" }),
11576
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-hint", children: texts?.hint2 })
11577
+ ] }) });
11596
11578
  }
11597
- ) })
11598
- ]
11579
+ }
11580
+ ) })
11599
11581
  }
11600
11582
  );
11601
11583
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pnkx-lib/ui",
3
3
  "private": false,
4
- "version": "1.9.465",
4
+ "version": "1.9.467",
5
5
  "type": "module",
6
6
  "main": "./es/index.js",
7
7
  "module": "./es/index.js",
@@ -5,7 +5,6 @@ export interface GenericUploadModalProps {
5
5
  onCancel: () => void;
6
6
  control: Control<any>;
7
7
  setFileList(fileList: UploadFile[]): void;
8
- fileList: UploadFile[];
9
8
  /** danh sách file từ API để hiển thị */
10
9
  record?: Array<{
11
10
  filePath: string;
@@ -29,4 +28,4 @@ export interface GenericUploadModalProps {
29
28
  uploading?: string;
30
29
  };
31
30
  }
32
- export declare function GenericUploadModal({ open, onCancel, control, setFileList, record, fileList, allowedExtensions, maxSize, texts, }: GenericUploadModalProps): import("react/jsx-runtime").JSX.Element;
31
+ export declare function GenericUploadModal({ open, onCancel, control, setFileList, record, allowedExtensions, maxSize, texts, }: GenericUploadModalProps): import("react/jsx-runtime").JSX.Element;