gbs-add-block 0.0.12 → 0.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",
@@ -74,6 +74,7 @@ export const Input = ({
74
74
  {/* If Type is password, this will show a password visible toggle button */}
75
75
  {props.type && props.type === "password" && (
76
76
  <button
77
+ type="button"
77
78
  className="absolute inset-y-0 right-0 flex items-center pr-2"
78
79
  onClick={toggleTypeForPassword}
79
80
  >
@@ -98,7 +99,9 @@ export const Input = ({
98
99
  value={otpValues[index]}
99
100
  onChange={(e) => updateOtpValue(index, e)}
100
101
  onKeyDown={(e) => handleKeydown(index, e)}
101
- // ref={(ref) => (inputRefs.current[index] = ref)}
102
+ ref={(ref) => {
103
+ inputRefs.current[index] = ref;
104
+ }}
102
105
  className={OTPClass}
103
106
  />
104
107
  ))}
@@ -8,6 +8,7 @@
8
8
  import React, {
9
9
  forwardRef,
10
10
  memo,
11
+ useCallback,
11
12
  useEffect,
12
13
  useImperativeHandle,
13
14
  useRef,
@@ -50,10 +51,6 @@ const MultiSelect = forwardRef<any, MultiSelectProps>((props, ref) => {
50
51
  handleDataSource();
51
52
  }, [items]);
52
53
 
53
- useEffect(() => {
54
- if (onSelect) onSelect(selected);
55
- }, [selected, onSelect]);
56
-
57
54
  useEffect(() => {
58
55
  const handleClickOutside = (event: MouseEvent) => {
59
56
  if (
@@ -87,13 +84,16 @@ const MultiSelect = forwardRef<any, MultiSelectProps>((props, ref) => {
87
84
  setShowPopover(!showPopover);
88
85
  };
89
86
 
90
- const handleSelect = (value: string) => {
91
- setSelected((prev) =>
92
- prev.includes(value)
93
- ? prev.filter((item) => item !== value)
94
- : [...prev, value]
95
- );
96
- };
87
+ const handleSelect = useCallback(
88
+ (value: string) => {
89
+ const newSelected = selected.includes(value)
90
+ ? selected.filter((item) => item !== value)
91
+ : [...selected, value];
92
+ setSelected(newSelected);
93
+ onSelect?.(newSelected);
94
+ },
95
+ [selected, onSelect]
96
+ );
97
97
 
98
98
  const getSelectedDisplay = () => {
99
99
  if (selected.length === 0) return placeholder;
@@ -127,6 +127,7 @@ const MultiSelect = forwardRef<any, MultiSelectProps>((props, ref) => {
127
127
  const clearSelected = () => {
128
128
  setSelected([]);
129
129
  setShowPopover(false);
130
+ if (onSelect) onSelect([]);
130
131
  };
131
132
 
132
133
  useImperativeHandle(ref, () => ({
@@ -142,19 +143,27 @@ const MultiSelect = forwardRef<any, MultiSelectProps>((props, ref) => {
142
143
  return (
143
144
  <div className="relative w-[200px]" ref={selectRef}>
144
145
  <div className="relative border w-[200px] flex items-center px-4 py-2 rounded-lg">
145
- <button onClick={togglePopover} className="flex-grow text-sm text-left">
146
+ <button
147
+ onClick={togglePopover}
148
+ className="flex-grow text-sm text-left"
149
+ type="button"
150
+ >
146
151
  {getSelectedDisplay()}
147
152
  </button>
148
153
  <div className="flex items-center space-x-2">
149
154
  {selected.length > 0 && (
150
- <button className="flex items-center px-2" onClick={clearSelected}>
155
+ <button
156
+ className="flex items-center px-2"
157
+ onClick={clearSelected}
158
+ type="button"
159
+ >
151
160
  <Icon
152
161
  elements={x}
153
162
  svgClass="h-4 w-4 stroke-gray-500 fill-none dark:stroke-white"
154
163
  />
155
164
  </button>
156
165
  )}
157
- <button onClick={togglePopover}>
166
+ <button onClick={togglePopover} type="button">
158
167
  <Icon
159
168
  elements={upDown}
160
169
  svgClass="h-4 w-4 stroke-gray-500 fill-none dark:stroke-white"
@@ -187,6 +196,7 @@ const MultiSelect = forwardRef<any, MultiSelectProps>((props, ref) => {
187
196
  {filteredItems.length > 0 ? (
188
197
  filteredItems.map(({ value, label }) => (
189
198
  <button
199
+ type="button"
190
200
  key={value}
191
201
  className="flex items-center w-full px-2 py-1 text-left hover:bg-blue-100 gap-2 rounded-lg mt-1 text-sm dark:hover:bg-blue-600"
192
202
  onClick={() => handleSelect(value)}
@@ -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
  })}