@ailaw/venus 1.309.0 → 1.310.0

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.
Files changed (2) hide show
  1. package/dist/venus.es.js +44 -11
  2. package/package.json +1 -1
package/dist/venus.es.js CHANGED
@@ -2064,13 +2064,47 @@ async function selectFolderTree() {
2064
2064
  el.multiple = true;
2065
2065
  document.body.appendChild(el);
2066
2066
  el.click();
2067
- el.onchange = async () => {
2068
- const files = Array.from(el.files);
2069
- document.body.removeChild(el);
2070
- console.log("selectFolderTree files count", files.length);
2067
+ const buildZipFromEntries = async (entries) => {
2071
2068
  const zip = new JSZip();
2072
2069
  const folderSet = new Set();
2073
- if (files.length > 0) {
2070
+ const traverse = async (entry, path2) => {
2071
+ if (entry.isDirectory) {
2072
+ const dirPath = path2 + entry.name + "/";
2073
+ folderSet.add(dirPath);
2074
+ const reader = entry.createReader();
2075
+ const readEntries = () => new Promise((res) => reader.readEntries(res));
2076
+ let batch = await readEntries();
2077
+ while (batch.length) {
2078
+ for (const e of batch) {
2079
+ await traverse(e, dirPath);
2080
+ }
2081
+ batch = await readEntries();
2082
+ }
2083
+ } else {
2084
+ const dirPath = path2;
2085
+ if (dirPath)
2086
+ folderSet.add(dirPath);
2087
+ }
2088
+ };
2089
+ for (const entry of entries) {
2090
+ await traverse(entry, "");
2091
+ }
2092
+ folderSet.forEach((dir) => {
2093
+ zip.folder(dir);
2094
+ });
2095
+ const blob = await zip.generateAsync({ type: "blob" });
2096
+ return { zipBlob: blob, folderTree: Array.from(folderSet) };
2097
+ };
2098
+ el.onchange = async (e) => {
2099
+ const fileInput = e.target;
2100
+ const entries = fileInput.webkitEntries || el.webkitEntries || [];
2101
+ let zipBlob, folderTree;
2102
+ if (entries.length) {
2103
+ ({ zipBlob, folderTree } = await buildZipFromEntries(entries));
2104
+ } else {
2105
+ const files = Array.from(el.files);
2106
+ const zip = new JSZip();
2107
+ const folderSet = new Set();
2074
2108
  files.forEach((file2) => {
2075
2109
  const path2 = file2.webkitRelativePath;
2076
2110
  if (!path2)
@@ -2081,13 +2115,12 @@ async function selectFolderTree() {
2081
2115
  folderSet.add(dir);
2082
2116
  }
2083
2117
  });
2084
- folderSet.forEach((dir) => {
2085
- zip.folder(dir);
2086
- });
2118
+ folderSet.forEach((dir) => zip.folder(dir));
2119
+ zipBlob = await zip.generateAsync({ type: "blob" });
2120
+ folderTree = Array.from(folderSet);
2087
2121
  }
2088
- const blob = await zip.generateAsync({ type: "blob" });
2089
- const file = new File([blob], "folder-structure.zip", { type: "application/zip" });
2090
- const folderTree = Array.from(folderSet);
2122
+ document.body.removeChild(el);
2123
+ const file = new File([zipBlob], "folder-structure.zip", { type: "application/zip" });
2091
2124
  resolve({ file, folderTree });
2092
2125
  };
2093
2126
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ailaw/venus",
3
- "version": "1.309.0",
3
+ "version": "1.310.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],