@esic-lab/data-core-ui 0.0.43 → 0.0.44

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.d.mts CHANGED
@@ -451,8 +451,9 @@ interface FileUploaderProps {
451
451
  mode: "upload" | "drop";
452
452
  description?: string;
453
453
  label?: string;
454
+ value?: File[] | any[];
454
455
  }
455
- declare function FileUploader({ onUpload, onError, onRemove, accept, maxSize, disabled, mode, description, label, }: FileUploaderProps): react_jsx_runtime.JSX.Element;
456
+ declare function FileUploader({ onUpload, onError, onRemove, accept, maxSize, disabled, mode, description, label, value, }: FileUploaderProps): react_jsx_runtime.JSX.Element;
456
457
 
457
458
  declare function setMessageApi(api: MessageInstance): void;
458
459
  declare function messageSuccess(content: string): void;
package/dist/index.d.ts CHANGED
@@ -451,8 +451,9 @@ interface FileUploaderProps {
451
451
  mode: "upload" | "drop";
452
452
  description?: string;
453
453
  label?: string;
454
+ value?: File[] | any[];
454
455
  }
455
- declare function FileUploader({ onUpload, onError, onRemove, accept, maxSize, disabled, mode, description, label, }: FileUploaderProps): react_jsx_runtime.JSX.Element;
456
+ declare function FileUploader({ onUpload, onError, onRemove, accept, maxSize, disabled, mode, description, label, value, }: FileUploaderProps): react_jsx_runtime.JSX.Element;
456
457
 
457
458
  declare function setMessageApi(api: MessageInstance): void;
458
459
  declare function messageSuccess(content: string): void;
package/dist/index.js CHANGED
@@ -3004,12 +3004,14 @@ function FileUploader({
3004
3004
  disabled,
3005
3005
  mode = "drop",
3006
3006
  description,
3007
- label
3007
+ label,
3008
+ value
3008
3009
  }) {
3009
- const [fileList, setFileList] = (0, import_react13.useState)([]);
3010
+ const [internalFileList, setInternalFileList] = (0, import_react13.useState)([]);
3010
3011
  const [uploading, setUploading] = (0, import_react13.useState)(false);
3011
3012
  const [dragActive, setDragActive] = (0, import_react13.useState)(false);
3012
3013
  const inputRef = (0, import_react13.useRef)(null);
3014
+ const filesToDisplay = value || internalFileList;
3013
3015
  const validateFile = (file) => {
3014
3016
  if (accept && !accept.includes(file.type)) {
3015
3017
  onError?.(`Invalid file type. file: ${file.name}`);
@@ -3029,9 +3031,11 @@ function FileUploader({
3029
3031
  if (onRemove) {
3030
3032
  await onRemove(index);
3031
3033
  }
3032
- const updatedList = [...fileList];
3033
- updatedList.splice(index, 1);
3034
- setFileList(updatedList);
3034
+ if (!value) {
3035
+ const updatedList = [...internalFileList];
3036
+ updatedList.splice(index, 1);
3037
+ setInternalFileList(updatedList);
3038
+ }
3035
3039
  } catch (error) {
3036
3040
  console.log(error);
3037
3041
  }
@@ -3049,13 +3053,19 @@ function FileUploader({
3049
3053
  if (!files) return;
3050
3054
  const fileArray = Array.from(files);
3051
3055
  for (const file of fileArray) {
3052
- if (!validateFile(file)) continue;
3056
+ try {
3057
+ validateFile(file);
3058
+ } catch (e) {
3059
+ continue;
3060
+ }
3053
3061
  setUploading(true);
3054
3062
  try {
3055
3063
  if (onUpload) {
3056
3064
  await onUpload(file);
3057
3065
  }
3058
- setFileList((prev) => [...prev, file]);
3066
+ if (!value) {
3067
+ setInternalFileList((prev) => [...prev, file]);
3068
+ }
3059
3069
  } catch (err) {
3060
3070
  console.log("catch");
3061
3071
  console.error(err);
@@ -3122,10 +3132,10 @@ function FileUploader({
3122
3132
  )
3123
3133
  ] }),
3124
3134
  description && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("p", { className: "text-gray-400 body-4", children: description }),
3125
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "mt-[8px]", children: fileList.length !== 0 && fileList.map((file, index) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex items-center gap-2 rounded-[4px] px-[8px] py-[4px] body-1", children: [
3135
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "mt-[8px]", children: filesToDisplay.length !== 0 && filesToDisplay.map((file, index) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex items-center gap-2 rounded-[4px] px-[8px] py-[4px] body-1", children: [
3126
3136
  /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex items-center gap-2 w-[75%] overflow-hidden", children: [
3127
3137
  /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "w-[15px] h-[15px]", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_icons_react10.IconPaperclip, { size: 15 }) }),
3128
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "truncate", children: file.name })
3138
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "truncate", children: file.name || file.fileName })
3129
3139
  ] }),
3130
3140
  /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3131
3141
  import_icons_react10.IconTrash,
package/dist/index.mjs CHANGED
@@ -2946,12 +2946,14 @@ function FileUploader({
2946
2946
  disabled,
2947
2947
  mode = "drop",
2948
2948
  description,
2949
- label
2949
+ label,
2950
+ value
2950
2951
  }) {
2951
- const [fileList, setFileList] = useState11([]);
2952
+ const [internalFileList, setInternalFileList] = useState11([]);
2952
2953
  const [uploading, setUploading] = useState11(false);
2953
2954
  const [dragActive, setDragActive] = useState11(false);
2954
2955
  const inputRef = useRef4(null);
2956
+ const filesToDisplay = value || internalFileList;
2955
2957
  const validateFile = (file) => {
2956
2958
  if (accept && !accept.includes(file.type)) {
2957
2959
  onError?.(`Invalid file type. file: ${file.name}`);
@@ -2971,9 +2973,11 @@ function FileUploader({
2971
2973
  if (onRemove) {
2972
2974
  await onRemove(index);
2973
2975
  }
2974
- const updatedList = [...fileList];
2975
- updatedList.splice(index, 1);
2976
- setFileList(updatedList);
2976
+ if (!value) {
2977
+ const updatedList = [...internalFileList];
2978
+ updatedList.splice(index, 1);
2979
+ setInternalFileList(updatedList);
2980
+ }
2977
2981
  } catch (error) {
2978
2982
  console.log(error);
2979
2983
  }
@@ -2991,13 +2995,19 @@ function FileUploader({
2991
2995
  if (!files) return;
2992
2996
  const fileArray = Array.from(files);
2993
2997
  for (const file of fileArray) {
2994
- if (!validateFile(file)) continue;
2998
+ try {
2999
+ validateFile(file);
3000
+ } catch (e) {
3001
+ continue;
3002
+ }
2995
3003
  setUploading(true);
2996
3004
  try {
2997
3005
  if (onUpload) {
2998
3006
  await onUpload(file);
2999
3007
  }
3000
- setFileList((prev) => [...prev, file]);
3008
+ if (!value) {
3009
+ setInternalFileList((prev) => [...prev, file]);
3010
+ }
3001
3011
  } catch (err) {
3002
3012
  console.log("catch");
3003
3013
  console.error(err);
@@ -3064,10 +3074,10 @@ function FileUploader({
3064
3074
  )
3065
3075
  ] }),
3066
3076
  description && /* @__PURE__ */ jsx34("p", { className: "text-gray-400 body-4", children: description }),
3067
- /* @__PURE__ */ jsx34("div", { className: "mt-[8px]", children: fileList.length !== 0 && fileList.map((file, index) => /* @__PURE__ */ jsxs30("div", { className: "flex items-center gap-2 rounded-[4px] px-[8px] py-[4px] body-1", children: [
3077
+ /* @__PURE__ */ jsx34("div", { className: "mt-[8px]", children: filesToDisplay.length !== 0 && filesToDisplay.map((file, index) => /* @__PURE__ */ jsxs30("div", { className: "flex items-center gap-2 rounded-[4px] px-[8px] py-[4px] body-1", children: [
3068
3078
  /* @__PURE__ */ jsxs30("div", { className: "flex items-center gap-2 w-[75%] overflow-hidden", children: [
3069
3079
  /* @__PURE__ */ jsx34("div", { className: "w-[15px] h-[15px]", children: /* @__PURE__ */ jsx34(IconPaperclip, { size: 15 }) }),
3070
- /* @__PURE__ */ jsx34("span", { className: "truncate", children: file.name })
3080
+ /* @__PURE__ */ jsx34("span", { className: "truncate", children: file.name || file.fileName })
3071
3081
  ] }),
3072
3082
  /* @__PURE__ */ jsx34(
3073
3083
  IconTrash2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esic-lab/data-core-ui",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",