gbs-add-block 0.0.11 → 0.0.13

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/index.js CHANGED
@@ -19,8 +19,14 @@ const COMPONENTS = [
19
19
  "Toast",
20
20
  "Uploader",
21
21
  ];
22
+
23
+ const FRAMEWORKS = {
24
+ next: "Next.js",
25
+ vite: "Vite",
26
+ };
27
+
22
28
  const SOURCE_PATH = path.join(__dirname, "source", "components");
23
- const DEST_PATH = path.join(process.cwd(), "src", "component-lib");
29
+ let DEST_PATH;
24
30
 
25
31
  const rl = readline.createInterface({
26
32
  input: process.stdin,
@@ -29,15 +35,15 @@ const rl = readline.createInterface({
29
35
 
30
36
  let isFirstCopy = true;
31
37
 
38
+ function listFrameworks() {
39
+ console.log("Available frameworks:");
40
+ console.log("");
41
+ Object.entries(FRAMEWORKS).forEach(([key, name], index) => {
42
+ console.log(`${index + 1}. ${name}`);
43
+ });
44
+ }
45
+
32
46
  function listComponents() {
33
- console.log(
34
- ` _____ ____ _____
35
- / ____| | \\ / ___|
36
- | | __ | |_) | | (___
37
- | | |_ | | < \\ __ \\
38
- | |__| | | |_) | ____) |
39
- \\_____| |____/ |_____/ `
40
- );
41
47
  console.log(" ");
42
48
  console.log("Available components:");
43
49
  console.log(" ");
@@ -84,6 +90,35 @@ function copyComponent(component) {
84
90
  }
85
91
  }
86
92
 
93
+ function promptForFramework() {
94
+ listFrameworks();
95
+ rl.question("Select your framework (enter the number): ", (answer) => {
96
+ const index = parseInt(answer) - 1;
97
+ const frameworks = Object.keys(FRAMEWORKS);
98
+
99
+ if (isNaN(index) || index < 0 || index >= frameworks.length) {
100
+ console.log("Invalid selection. Please try again.");
101
+ promptForFramework();
102
+ return;
103
+ }
104
+
105
+ const selectedFramework = frameworks[index];
106
+
107
+ // Set destination path based on framework
108
+ if (selectedFramework === "next") {
109
+ DEST_PATH = path.join(process.cwd(), "app", "component-lib");
110
+ } else {
111
+ DEST_PATH = path.join(process.cwd(), "src", "component-lib");
112
+ }
113
+
114
+ // Ensure the destination directory exists
115
+ fs.ensureDirSync(DEST_PATH);
116
+
117
+ // Continue with component selection
118
+ promptForComponent();
119
+ });
120
+ }
121
+
87
122
  function promptForComponent() {
88
123
  listComponents();
89
124
  rl.question(
@@ -118,8 +153,5 @@ function promptForComponent() {
118
153
  );
119
154
  }
120
155
 
121
- // Ensure the destination directory exists
122
- fs.ensureDirSync(DEST_PATH);
123
-
124
- // Start the component selection process
125
- promptForComponent();
156
+ // Start with framework selection
157
+ promptForFramework();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",
@@ -6,8 +6,8 @@
6
6
  */
7
7
 
8
8
  import React, { useState, useRef, useEffect } from "react";
9
- import { upload, x } from "../../icon/iconPaths";
10
- import Icon from "../../icon/Icon";
9
+ import { upload, x } from "@/src/component-lib/icon/iconPaths";
10
+ import Icon from "@/src/component-lib/icon/Icon";
11
11
  import { GetFileIcon } from "./uploaderIcon";
12
12
  import AestheticProcessingAnimationWithStyles from "./ProgressAnimation";
13
13
 
@@ -163,6 +163,7 @@ export const FileUploader = ({
163
163
  {fileSizeErrors.map((error, index) => (
164
164
  <span key={index} className="text-xs text-red-500">
165
165
  {error}
166
+ <br />
166
167
  </span>
167
168
  ))}
168
169
  </div>
@@ -17,29 +17,54 @@ function processFiles(files: File[], chunkSize: number) {
17
17
  return finalFiles;
18
18
  }
19
19
 
20
- // Converts large files to chunks to send over network and sends
21
20
  export async function sendFiles(
22
21
  files: File[],
23
22
  chunkSize: number,
24
23
  apiUrl = "http://localhost:8080/upload"
25
24
  ) {
26
25
  const processedFiles = processFiles(files, chunkSize);
27
- const totalChunks = processedFiles.length;
26
+
27
+ // Track how many chunks belong to the current file being processed
28
+ const fileChunkCounts: { [key: string]: number } = {};
29
+ files.forEach((file) => {
30
+ fileChunkCounts[file.name] = Math.ceil(file.size / chunkSize);
31
+ });
32
+
33
+ // To track chunk index per file
34
+ const chunkIndexTracker: { [key: string]: number } = {};
28
35
 
29
36
  for (let i = 0; i < processedFiles.length; i++) {
30
37
  const { file, originalFile } = processedFiles[i];
31
38
  const formData = new FormData();
32
39
  formData.append("file", file, originalFile.name);
33
40
  formData.append("originalname", originalFile.name);
41
+ formData.append("originalFileSize", originalFile.size.toString());
34
42
 
35
- if (file.size > chunkSize) {
36
- formData.append("chunkIndex", i.toString());
37
- formData.append("totalChunks", totalChunks.toString());
38
- } else {
39
- formData.append("chunkIndex", "0");
40
- formData.append("totalChunks", "1");
43
+ const chunkCount = fileChunkCounts[originalFile.name];
44
+ const isChunked = chunkCount > 1;
45
+
46
+ // Initialize or reset chunkIndex per file
47
+ if (!chunkIndexTracker[originalFile.name]) {
48
+ chunkIndexTracker[originalFile.name] = 0; // Start at 0 for each file
41
49
  }
42
50
 
51
+ const chunkIndex = isChunked
52
+ ? chunkIndexTracker[originalFile.name].toString()
53
+ : "";
54
+ formData.append("chunkIndex", chunkIndex);
55
+ formData.append("totalChunks", isChunked ? chunkCount.toString() : "");
56
+
57
+ // Increment chunkIndex for the current file
58
+ if (isChunked) {
59
+ chunkIndexTracker[originalFile.name]++;
60
+ }
61
+
62
+ // Don't Remove the following console
63
+ // console.log("FormData contents:");
64
+ // formData.forEach((value, key) => {
65
+ // console.log(`${key}: ${value}`);
66
+ // });
67
+
43
68
  try {
44
69
  const response = await fetch(apiUrl, {
45
70
  method: "POST",
@@ -57,7 +82,9 @@ export async function sendFiles(
57
82
  `File uploaded successfully. Document ID: ${data.documentId}`
58
83
  );
59
84
  } else {
60
- console.log(`Chunk ${i + 1}/${totalChunks} uploaded`);
85
+ console.log(
86
+ `Chunk ${chunkIndexTracker[originalFile.name]}/${chunkCount} uploaded`
87
+ );
61
88
  }
62
89
  } catch (error) {
63
90
  console.error("Error uploading file chunk:", error);
@@ -1,12 +1,23 @@
1
1
  import React from "react";
2
2
 
3
3
  type SvgElement = {
4
- type: "path" | "circle";
4
+ type: "path" | "circle" | "polyline" | "rect" | "line";
5
5
  key: string;
6
6
  d?: string;
7
7
  cx?: number;
8
8
  cy?: number;
9
9
  r?: number;
10
+ points?: string;
11
+ x?: number;
12
+ y?: number;
13
+ width?: number;
14
+ height?: number;
15
+ rx?: number;
16
+ ry?: number;
17
+ x1?: number;
18
+ y1?: number;
19
+ x2?: number;
20
+ y2?: number;
10
21
  };
11
22
 
12
23
  type IconProps = {
@@ -21,6 +32,18 @@ export default function Icon({
21
32
  { type: "path", d: "m11 17-5-5 5-5", key: "13zhaf" },
22
33
  { type: "path", d: "m18 17-5-5 5-5", key: "h8a8et" },
23
34
  { type: "circle", cx: 12, cy: 12, r: 5, key: "circle1" },
35
+ { type: "polyline", points: "20 6 12 13 4 6", key: "polyline1" },
36
+ {
37
+ type: "rect",
38
+ x: 4,
39
+ y: 4,
40
+ width: 16,
41
+ height: 16,
42
+ key: "rect1",
43
+ rx: 2,
44
+ ry: 2,
45
+ },
46
+ { type: "line", x1: 0, y1: 0, x2: 24, y2: 24, key: "line1" }, // Example line
24
47
  ],
25
48
  dimensions = { width: "24", height: "24" },
26
49
  }: IconProps) {
@@ -47,6 +70,30 @@ export default function Icon({
47
70
  key={element.key}
48
71
  />
49
72
  );
73
+ } else if (element.type === "polyline") {
74
+ return <polyline points={element.points} key={element.key} />;
75
+ } else if (element.type === "rect") {
76
+ return (
77
+ <rect
78
+ x={element.x}
79
+ y={element.y}
80
+ width={element.width}
81
+ height={element.height}
82
+ rx={element.rx}
83
+ ry={element.ry}
84
+ key={element.key}
85
+ />
86
+ );
87
+ } else if (element.type === "line") {
88
+ return (
89
+ <line
90
+ x1={element.x1}
91
+ y1={element.y1}
92
+ x2={element.x2}
93
+ y2={element.y2}
94
+ key={element.key}
95
+ />
96
+ );
50
97
  }
51
98
  return null;
52
99
  })}