@tecsinapse/cortex-react 1.15.0-beta.6 → 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.
@@ -64,7 +64,7 @@ const Manager = ({
64
64
  showDelete: false
65
65
  },
66
66
  file.uid
67
- )) : /* @__PURE__ */ jsxRuntime.jsx(Upload.Folder, { items: files })
67
+ )) : /* @__PURE__ */ jsxRuntime.jsx(Upload.FolderList, { files })
68
68
  }
69
69
  )
70
70
  ] })
@@ -63,33 +63,98 @@ const File = ({
63
63
  )
64
64
  ] }, index);
65
65
  };
66
- const Folder = ({ items }) => {
67
- const paths = /* @__PURE__ */ new Set();
68
- for (const file in items) {
69
- const path = items[file].file.relativePath.slice(1).split("/");
70
- path.map((item) => paths.add(item));
71
- }
72
- const intent = (items ?? []).some((item) => item.status === "success") ? "success" : (items ?? []).some((item) => item.status === "error") ? "error" : "info";
66
+ const Folder = ({ name, size, intent, loading }) => {
73
67
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col w-full", children: [
74
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: [
75
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, {}) }),
76
70
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-col", children: [
77
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-semibold truncate max-w-[200px]", children: Array.from(paths)[0] }),
71
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-semibold truncate max-w-[200px]", children: name }),
78
72
  /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-gray-500", children: [
79
- paths.size - 1,
80
- " itens"
73
+ size,
74
+ " ",
75
+ size > 1 ? "itens" : "item"
81
76
  ] })
82
77
  ] })
83
78
  ] }) }),
84
- /* @__PURE__ */ jsxRuntime.jsx(
85
- ProgressBar.ProgressBar,
86
- {
87
- intent,
88
- infinite: (items ?? []).some((item) => item.status === "uploading")
89
- }
90
- )
79
+ /* @__PURE__ */ jsxRuntime.jsx(ProgressBar.ProgressBar, { intent, infinite: loading })
91
80
  ] });
92
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
+ };
93
157
 
94
158
  exports.File = File;
95
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, Folder } 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';
@@ -62,7 +62,7 @@ const Manager = ({
62
62
  showDelete: false
63
63
  },
64
64
  file.uid
65
- )) : /* @__PURE__ */ jsx(Folder, { items: files })
65
+ )) : /* @__PURE__ */ jsx(FolderList, { files })
66
66
  }
67
67
  )
68
68
  ] })
@@ -1,4 +1,4 @@
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
3
  import { FaRegFileLines, FaRegFolder } from 'react-icons/fa6';
4
4
  import { MdClose } from 'react-icons/md';
@@ -61,32 +61,96 @@ const File = ({
61
61
  )
62
62
  ] }, index);
63
63
  };
64
- const Folder = ({ items }) => {
65
- const paths = /* @__PURE__ */ new Set();
66
- for (const file in items) {
67
- const path = items[file].file.relativePath.slice(1).split("/");
68
- path.map((item) => paths.add(item));
69
- }
70
- const intent = (items ?? []).some((item) => item.status === "success") ? "success" : (items ?? []).some((item) => item.status === "error") ? "error" : "info";
64
+ const Folder = ({ name, size, intent, loading }) => {
71
65
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col w-full", children: [
72
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: [
73
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, {}) }),
74
68
  /* @__PURE__ */ jsxs("div", { className: "flex-col", children: [
75
- /* @__PURE__ */ jsx("p", { className: "font-semibold truncate max-w-[200px]", children: Array.from(paths)[0] }),
69
+ /* @__PURE__ */ jsx("p", { className: "font-semibold truncate max-w-[200px]", children: name }),
76
70
  /* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-500", children: [
77
- paths.size - 1,
78
- " itens"
71
+ size,
72
+ " ",
73
+ size > 1 ? "itens" : "item"
79
74
  ] })
80
75
  ] })
81
76
  ] }) }),
82
- /* @__PURE__ */ jsx(
83
- ProgressBar,
84
- {
85
- intent,
86
- infinite: (items ?? []).some((item) => item.status === "uploading")
87
- }
88
- )
77
+ /* @__PURE__ */ jsx(ProgressBar, { intent, infinite: loading })
89
78
  ] });
90
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
+ };
91
155
 
92
- export { File, Folder };
156
+ export { File, Folder, FolderList };
@@ -1,3 +1,4 @@
1
- import { FileProps, FolderProps } 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>({ items }: FolderProps<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;
@@ -9,8 +9,14 @@ export interface FileProps<T> {
9
9
  onDelete: (index: number) => void;
10
10
  showDelete?: boolean;
11
11
  }
12
- export interface FolderProps<T> {
13
- items: FileUpload<T>[];
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>[];
14
20
  }
15
21
  export interface FilesProps<T> {
16
22
  files: FileUpload<T>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tecsinapse/cortex-react",
3
- "version": "1.15.0-beta.6",
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.4",
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": "4b3f865fef0e94a662c300ccd5173c9aecdd4fd7"
51
+ "gitHead": "2082dfbefdac0dc3a0773f8876885fdae29a8609"
52
52
  }