@pixpilot/shadcn 1.2.0 → 1.2.1

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.
@@ -190,6 +190,7 @@ function FileUploadRoot(props) {
190
190
  const dir = useDirection(dirProp);
191
191
  const listeners = useLazyRef(() => /* @__PURE__ */ new Set()).current;
192
192
  const files = useLazyRef(() => /* @__PURE__ */ new Map()).current;
193
+ const progressFrames = useLazyRef(() => /* @__PURE__ */ new Map()).current;
193
194
  const urlCache = useLazyRef(() => /* @__PURE__ */ new WeakMap()).current;
194
195
  const inputRef = React.useRef(null);
195
196
  const isControlled = value !== void 0;
@@ -201,18 +202,24 @@ function FileUploadRoot(props) {
201
202
  urlCache
202
203
  ]);
203
204
  const acceptTypes = React.useMemo(() => accept?.split(",").map((t) => t.trim()) ?? null, [accept]);
205
+ const cancelPendingProgress = React.useCallback((file) => {
206
+ const frameId = progressFrames.get(file);
207
+ if (frameId === void 0) return;
208
+ cancelAnimationFrame(frameId);
209
+ progressFrames.delete(file);
210
+ }, [progressFrames]);
204
211
  const onProgress = useLazyRef(() => {
205
- let frame = 0;
206
212
  return (file, progress) => {
207
- if (frame) return;
208
- frame = requestAnimationFrame(() => {
209
- frame = 0;
213
+ cancelPendingProgress(file);
214
+ const frameId = requestAnimationFrame(() => {
215
+ progressFrames.delete(file);
210
216
  store.dispatch({
211
217
  type: "SET_PROGRESS",
212
218
  file,
213
219
  progress: Math.min(Math.max(0, progress), 100)
214
220
  });
215
221
  });
222
+ progressFrames.set(file, frameId);
216
223
  };
217
224
  }).current;
218
225
  React.useEffect(() => {
@@ -232,12 +239,18 @@ function FileUploadRoot(props) {
232
239
  ]);
233
240
  React.useEffect(() => {
234
241
  return () => {
242
+ for (const frameId of progressFrames.values()) cancelAnimationFrame(frameId);
243
+ progressFrames.clear();
235
244
  for (const file of files.keys()) {
236
245
  const cachedUrl = urlCache.get(file);
237
246
  if (cachedUrl) URL.revokeObjectURL(cachedUrl);
238
247
  }
239
248
  };
240
- }, [files, urlCache]);
249
+ }, [
250
+ files,
251
+ progressFrames,
252
+ urlCache
253
+ ]);
241
254
  const onFilesUpload = React.useCallback(async (files$1) => {
242
255
  try {
243
256
  for (const file of files$1) store.dispatch({
@@ -248,12 +261,14 @@ function FileUploadRoot(props) {
248
261
  if (onUpload) await onUpload(files$1, {
249
262
  onProgress,
250
263
  onSuccess: (file) => {
264
+ cancelPendingProgress(file);
251
265
  store.dispatch({
252
266
  type: "SET_SUCCESS",
253
267
  file
254
268
  });
255
269
  },
256
270
  onError: (file, error) => {
271
+ cancelPendingProgress(file);
257
272
  store.dispatch({
258
273
  type: "SET_ERROR",
259
274
  file,
@@ -261,19 +276,26 @@ function FileUploadRoot(props) {
261
276
  });
262
277
  }
263
278
  });
264
- else for (const file of files$1) store.dispatch({
265
- type: "SET_SUCCESS",
266
- file
267
- });
279
+ else for (const file of files$1) {
280
+ cancelPendingProgress(file);
281
+ store.dispatch({
282
+ type: "SET_SUCCESS",
283
+ file
284
+ });
285
+ }
268
286
  } catch (error) {
269
287
  const errorMessage = error instanceof Error ? error.message : "Upload failed";
270
- for (const file of files$1) store.dispatch({
271
- type: "SET_ERROR",
272
- file,
273
- error: errorMessage
274
- });
288
+ for (const file of files$1) {
289
+ cancelPendingProgress(file);
290
+ store.dispatch({
291
+ type: "SET_ERROR",
292
+ file,
293
+ error: errorMessage
294
+ });
295
+ }
275
296
  }
276
297
  }, [
298
+ cancelPendingProgress,
277
299
  store,
278
300
  onUpload,
279
301
  onProgress
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pixpilot/shadcn",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "description": "A collection of reusable UI components built with shadcn/ui and Radix UI primitives.",
6
6
  "author": "m.doaie <m.doaie@hotmail.com>",
7
7
  "license": "MIT",
@@ -84,10 +84,10 @@
84
84
  "tsdown": "^0.15.12",
85
85
  "typescript": "^5.9.3",
86
86
  "typescript-eslint": "^8.49.0",
87
- "@internal/eslint-config": "0.3.0",
87
+ "@internal/tsdown-config": "0.1.0",
88
88
  "@internal/prettier-config": "0.0.1",
89
+ "@internal/eslint-config": "0.3.0",
89
90
  "@internal/tsconfig": "0.1.0",
90
- "@internal/tsdown-config": "0.1.0",
91
91
  "@internal/vitest-config": "0.1.0"
92
92
  },
93
93
  "prettier": "@internal/prettier-config",