@tecsinapse/cortex-react 1.15.0-beta.5 → 1.15.0-beta.7
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/cjs/components/Uploader/Manager.js +4 -3
- package/dist/cjs/components/Uploader/Upload.js +93 -0
- package/dist/esm/components/Uploader/Manager.js +5 -4
- package/dist/esm/components/Uploader/Upload.js +94 -3
- package/dist/types/components/Uploader/Manager.d.ts +1 -1
- package/dist/types/components/Uploader/Upload.d.ts +3 -1
- package/dist/types/components/Uploader/index.d.ts +1 -1
- package/dist/types/components/Uploader/types.d.ts +10 -0
- package/package.json +3 -3
|
@@ -15,7 +15,8 @@ const Manager = ({
|
|
|
15
15
|
files,
|
|
16
16
|
onDelete,
|
|
17
17
|
uploadProgressText = "Upload(s) in progress",
|
|
18
|
-
onClose
|
|
18
|
+
onClose,
|
|
19
|
+
type = "file"
|
|
19
20
|
}) => {
|
|
20
21
|
const [min, setMin] = React.useState(false);
|
|
21
22
|
return reactDom.createPortal(
|
|
@@ -54,7 +55,7 @@ const Manager = ({
|
|
|
54
55
|
"flex flex-col": !min,
|
|
55
56
|
"pb-kilo overflow-scroll pr-deca": files.length > 3
|
|
56
57
|
}),
|
|
57
|
-
children: files.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
58
|
+
children: type === "file" ? files.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
58
59
|
Upload.File,
|
|
59
60
|
{
|
|
60
61
|
file,
|
|
@@ -63,7 +64,7 @@ const Manager = ({
|
|
|
63
64
|
showDelete: false
|
|
64
65
|
},
|
|
65
66
|
file.uid
|
|
66
|
-
))
|
|
67
|
+
)) : /* @__PURE__ */ jsxRuntime.jsx(Upload.FolderList, { files })
|
|
67
68
|
}
|
|
68
69
|
)
|
|
69
70
|
] })
|
|
@@ -63,5 +63,98 @@ const File = ({
|
|
|
63
63
|
)
|
|
64
64
|
] }, index);
|
|
65
65
|
};
|
|
66
|
+
const Folder = ({ name, size, intent, loading }) => {
|
|
67
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col w-full", children: [
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between border rounded-t-mili shadow p-mili", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-centi", children: [
|
|
69
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "border-2 text-kilo text-primary-medium w-tera h-tera flex items-center justify-center rounded-mili", children: /* @__PURE__ */ jsxRuntime.jsx(fa6.FaRegFolder, {}) }),
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-col", children: [
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-semibold truncate max-w-[200px]", children: name }),
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-gray-500", children: [
|
|
73
|
+
size,
|
|
74
|
+
" ",
|
|
75
|
+
size > 1 ? "itens" : "item"
|
|
76
|
+
] })
|
|
77
|
+
] })
|
|
78
|
+
] }) }),
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsx(ProgressBar.ProgressBar, { intent, infinite: loading })
|
|
80
|
+
] });
|
|
81
|
+
};
|
|
82
|
+
const FolderList = ({ files }) => {
|
|
83
|
+
const paths = /* @__PURE__ */ new Set();
|
|
84
|
+
const buildTree = (files2) => {
|
|
85
|
+
const root = {
|
|
86
|
+
type: "root",
|
|
87
|
+
children: /* @__PURE__ */ new Map()
|
|
88
|
+
};
|
|
89
|
+
for (const file of files2) {
|
|
90
|
+
const parts = file.file.relativePath.slice(1).split("/");
|
|
91
|
+
parts.map((item) => paths.add(item));
|
|
92
|
+
let current = root;
|
|
93
|
+
parts.forEach((part, index) => {
|
|
94
|
+
const isLast = index === parts.length - 1;
|
|
95
|
+
if (isLast) {
|
|
96
|
+
current.children.set(part, {
|
|
97
|
+
type: "file",
|
|
98
|
+
file
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
if (!current.children.has(part)) {
|
|
102
|
+
current.children.set(part, {
|
|
103
|
+
type: "folder",
|
|
104
|
+
children: /* @__PURE__ */ new Map()
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
current = current.children.get(part);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return root;
|
|
112
|
+
};
|
|
113
|
+
const tree = buildTree(files);
|
|
114
|
+
const count = (node) => {
|
|
115
|
+
let total = 0;
|
|
116
|
+
const files2 = [];
|
|
117
|
+
for (const child of node.children.values()) {
|
|
118
|
+
if (child.type === "file") {
|
|
119
|
+
total += 1;
|
|
120
|
+
files2.push(child.file);
|
|
121
|
+
} else if (child.type === "folder") {
|
|
122
|
+
total += 1;
|
|
123
|
+
const nested = count(child);
|
|
124
|
+
total += nested.total;
|
|
125
|
+
files2.push(...nested.files);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { total, files: files2 };
|
|
129
|
+
};
|
|
130
|
+
const children = [];
|
|
131
|
+
for (const [name, node] of tree.children) {
|
|
132
|
+
const size = count(node).total;
|
|
133
|
+
const files2 = count(node).files;
|
|
134
|
+
children.push({
|
|
135
|
+
name,
|
|
136
|
+
size,
|
|
137
|
+
files: files2
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const folders = children.map((folder) => {
|
|
141
|
+
const intent = (folder.files ?? []).some((item) => item.status === "success") ? "success" : (files ?? []).some((item) => item.status === "error") ? "error" : "info";
|
|
142
|
+
return { ...folder, intent };
|
|
143
|
+
});
|
|
144
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: folders.map(({ intent, name, size, files: files2 }, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
145
|
+
Folder,
|
|
146
|
+
{
|
|
147
|
+
name,
|
|
148
|
+
size,
|
|
149
|
+
intent,
|
|
150
|
+
loading: files2.some(
|
|
151
|
+
(file) => file.status === "uploading"
|
|
152
|
+
)
|
|
153
|
+
},
|
|
154
|
+
index
|
|
155
|
+
)) });
|
|
156
|
+
};
|
|
66
157
|
|
|
67
158
|
exports.File = File;
|
|
159
|
+
exports.Folder = Folder;
|
|
160
|
+
exports.FolderList = FolderList;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
|
-
import { File } from './Upload.js';
|
|
3
|
+
import { File, FolderList } from './Upload.js';
|
|
4
4
|
import { Button } from '../Button.js';
|
|
5
5
|
import { IoMdClose } from 'react-icons/io';
|
|
6
6
|
import { useState } from 'react';
|
|
@@ -13,7 +13,8 @@ const Manager = ({
|
|
|
13
13
|
files,
|
|
14
14
|
onDelete,
|
|
15
15
|
uploadProgressText = "Upload(s) in progress",
|
|
16
|
-
onClose
|
|
16
|
+
onClose,
|
|
17
|
+
type = "file"
|
|
17
18
|
}) => {
|
|
18
19
|
const [min, setMin] = useState(false);
|
|
19
20
|
return createPortal(
|
|
@@ -52,7 +53,7 @@ const Manager = ({
|
|
|
52
53
|
"flex flex-col": !min,
|
|
53
54
|
"pb-kilo overflow-scroll pr-deca": files.length > 3
|
|
54
55
|
}),
|
|
55
|
-
children: files.map((file, index) => /* @__PURE__ */ jsx(
|
|
56
|
+
children: type === "file" ? files.map((file, index) => /* @__PURE__ */ jsx(
|
|
56
57
|
File,
|
|
57
58
|
{
|
|
58
59
|
file,
|
|
@@ -61,7 +62,7 @@ const Manager = ({
|
|
|
61
62
|
showDelete: false
|
|
62
63
|
},
|
|
63
64
|
file.uid
|
|
64
|
-
))
|
|
65
|
+
)) : /* @__PURE__ */ jsx(FolderList, { files })
|
|
65
66
|
}
|
|
66
67
|
)
|
|
67
68
|
] })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { button } from '@tecsinapse/cortex-core';
|
|
3
|
-
import { FaRegFileLines } from 'react-icons/fa6';
|
|
3
|
+
import { FaRegFileLines, FaRegFolder } from 'react-icons/fa6';
|
|
4
4
|
import { MdClose } from 'react-icons/md';
|
|
5
5
|
import { ProgressBar } from '../ProgressBar/ProgressBar.js';
|
|
6
6
|
|
|
@@ -61,5 +61,96 @@ const File = ({
|
|
|
61
61
|
)
|
|
62
62
|
] }, index);
|
|
63
63
|
};
|
|
64
|
+
const Folder = ({ name, size, intent, loading }) => {
|
|
65
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col w-full", children: [
|
|
66
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-between border rounded-t-mili shadow p-mili", children: /* @__PURE__ */ jsxs("div", { className: "flex gap-centi", children: [
|
|
67
|
+
/* @__PURE__ */ jsx("span", { className: "border-2 text-kilo text-primary-medium w-tera h-tera flex items-center justify-center rounded-mili", children: /* @__PURE__ */ jsx(FaRegFolder, {}) }),
|
|
68
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-col", children: [
|
|
69
|
+
/* @__PURE__ */ jsx("p", { className: "font-semibold truncate max-w-[200px]", children: name }),
|
|
70
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-500", children: [
|
|
71
|
+
size,
|
|
72
|
+
" ",
|
|
73
|
+
size > 1 ? "itens" : "item"
|
|
74
|
+
] })
|
|
75
|
+
] })
|
|
76
|
+
] }) }),
|
|
77
|
+
/* @__PURE__ */ jsx(ProgressBar, { intent, infinite: loading })
|
|
78
|
+
] });
|
|
79
|
+
};
|
|
80
|
+
const FolderList = ({ files }) => {
|
|
81
|
+
const paths = /* @__PURE__ */ new Set();
|
|
82
|
+
const buildTree = (files2) => {
|
|
83
|
+
const root = {
|
|
84
|
+
type: "root",
|
|
85
|
+
children: /* @__PURE__ */ new Map()
|
|
86
|
+
};
|
|
87
|
+
for (const file of files2) {
|
|
88
|
+
const parts = file.file.relativePath.slice(1).split("/");
|
|
89
|
+
parts.map((item) => paths.add(item));
|
|
90
|
+
let current = root;
|
|
91
|
+
parts.forEach((part, index) => {
|
|
92
|
+
const isLast = index === parts.length - 1;
|
|
93
|
+
if (isLast) {
|
|
94
|
+
current.children.set(part, {
|
|
95
|
+
type: "file",
|
|
96
|
+
file
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
if (!current.children.has(part)) {
|
|
100
|
+
current.children.set(part, {
|
|
101
|
+
type: "folder",
|
|
102
|
+
children: /* @__PURE__ */ new Map()
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
current = current.children.get(part);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return root;
|
|
110
|
+
};
|
|
111
|
+
const tree = buildTree(files);
|
|
112
|
+
const count = (node) => {
|
|
113
|
+
let total = 0;
|
|
114
|
+
const files2 = [];
|
|
115
|
+
for (const child of node.children.values()) {
|
|
116
|
+
if (child.type === "file") {
|
|
117
|
+
total += 1;
|
|
118
|
+
files2.push(child.file);
|
|
119
|
+
} else if (child.type === "folder") {
|
|
120
|
+
total += 1;
|
|
121
|
+
const nested = count(child);
|
|
122
|
+
total += nested.total;
|
|
123
|
+
files2.push(...nested.files);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { total, files: files2 };
|
|
127
|
+
};
|
|
128
|
+
const children = [];
|
|
129
|
+
for (const [name, node] of tree.children) {
|
|
130
|
+
const size = count(node).total;
|
|
131
|
+
const files2 = count(node).files;
|
|
132
|
+
children.push({
|
|
133
|
+
name,
|
|
134
|
+
size,
|
|
135
|
+
files: files2
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const folders = children.map((folder) => {
|
|
139
|
+
const intent = (folder.files ?? []).some((item) => item.status === "success") ? "success" : (files ?? []).some((item) => item.status === "error") ? "error" : "info";
|
|
140
|
+
return { ...folder, intent };
|
|
141
|
+
});
|
|
142
|
+
return /* @__PURE__ */ jsx(Fragment, { children: folders.map(({ intent, name, size, files: files2 }, index) => /* @__PURE__ */ jsx(
|
|
143
|
+
Folder,
|
|
144
|
+
{
|
|
145
|
+
name,
|
|
146
|
+
size,
|
|
147
|
+
intent,
|
|
148
|
+
loading: files2.some(
|
|
149
|
+
(file) => file.status === "uploading"
|
|
150
|
+
)
|
|
151
|
+
},
|
|
152
|
+
index
|
|
153
|
+
)) });
|
|
154
|
+
};
|
|
64
155
|
|
|
65
|
-
export { File };
|
|
156
|
+
export { File, Folder, FolderList };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ManagerProps } from './types';
|
|
2
|
-
export declare const Manager: <T>({ open, files, onDelete, uploadProgressText, onClose, }: ManagerProps<T>) => any;
|
|
2
|
+
export declare const Manager: <T>({ open, files, onDelete, uploadProgressText, onClose, type, }: ManagerProps<T>) => any;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { FileProps } from './types';
|
|
1
|
+
import { FileProps, FolderListProps, FolderProps } from './types';
|
|
2
2
|
export declare const File: <T>({ file, index, onDelete, showDelete, }: FileProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const Folder: <T>({ name, size, intent, loading }: FolderProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare const FolderList: <T>({ files }: FolderListProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,5 +5,5 @@ export declare const Uploader: {
|
|
|
5
5
|
Files: <T>({ files, onDelete, uploadProgressText, }: import("./types").FilesProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
Modal: ({ open, onClose, children, title, }: import("./types").ModalProps) => any;
|
|
7
7
|
Root: <T>({ open, onClose, files, onDelete, dropzoneProps, selectFileText, dropText, buttonText, uploadProgressText, titleModal, isManagerOpen, closeManager, }: import("./types").RootUploaderProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
-
Manager: <T>({ open, files, onDelete, uploadProgressText, onClose, }: import("./types").ManagerProps<T>) => any;
|
|
8
|
+
Manager: <T>({ open, files, onDelete, uploadProgressText, onClose, type, }: import("./types").ManagerProps<T>) => any;
|
|
9
9
|
};
|
|
@@ -9,6 +9,15 @@ export interface FileProps<T> {
|
|
|
9
9
|
onDelete: (index: number) => void;
|
|
10
10
|
showDelete?: boolean;
|
|
11
11
|
}
|
|
12
|
+
export interface FolderProps {
|
|
13
|
+
name: string;
|
|
14
|
+
size: number;
|
|
15
|
+
intent: 'default' | 'success' | 'warning' | 'info' | 'error';
|
|
16
|
+
loading: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface FolderListProps<T> {
|
|
19
|
+
files: FileUpload<T>[];
|
|
20
|
+
}
|
|
12
21
|
export interface FilesProps<T> {
|
|
13
22
|
files: FileUpload<T>[];
|
|
14
23
|
onDelete: (index: number) => void;
|
|
@@ -64,6 +73,7 @@ export interface ManagerProps<T> {
|
|
|
64
73
|
onDelete: (index: number) => void;
|
|
65
74
|
uploadProgressText?: string;
|
|
66
75
|
onClose: () => void;
|
|
76
|
+
type?: 'file' | 'folder';
|
|
67
77
|
}
|
|
68
78
|
export declare const AcceptSpecificMap: {
|
|
69
79
|
readonly APPLICATION: readonly ["application/pdf", "application/zip", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/x-rar-compressed", "application/x-7z-compressed", "application/json", "application/xml", "application/rtf", "application/x-tar", "application/x-httpd-php", "application/octet-stream"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/cortex-react",
|
|
3
|
-
"version": "1.15.0-beta.
|
|
3
|
+
"version": "1.15.0-beta.7",
|
|
4
4
|
"description": "React components based in @tecsinapse/cortex-core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@floating-ui/react": "^0.26.18",
|
|
22
22
|
"@internationalized/date": "3.7.0",
|
|
23
|
-
"@tecsinapse/cortex-core": "1.2.0-beta.
|
|
23
|
+
"@tecsinapse/cortex-core": "1.2.0-beta.5",
|
|
24
24
|
"clsx": "2.1.1",
|
|
25
25
|
"currency.js": "2.0.4",
|
|
26
26
|
"embla-carousel-autoplay": "^8.0.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react-icons": ">=5.2.0",
|
|
49
49
|
"tailwind": ">=3.3.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "2082dfbefdac0dc3a0773f8876885fdae29a8609"
|
|
52
52
|
}
|