@blocklet/editor 2.4.22 → 2.4.24

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.
@@ -1,4 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ */
2
9
  import { $createCodeNode } from '@lexical/code';
3
10
  import { INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
4
11
  import { INSERT_EMBED_COMMAND } from '@lexical/react/LexicalAutoEmbedPlugin';
@@ -29,6 +36,7 @@ import { INSERT_FILE_COMMAND } from '../../../ext/FilePlugin';
29
36
  import { $insertSubpageListing } from '../../../ext/SubpageListingPlugin/SubpageListingPlugin';
30
37
  import { INSERT_PAGES_KIT_COMPONENT_COMMAND, usePagesKitComponents, } from '../../../ext/PagesKitComponent/PagesKitComponentPlugin';
31
38
  import { icons } from '../../icons';
39
+ import { preventDuplicateUploadSuccess } from '../../utils/prevent-duplicate-upload';
32
40
  class ComponentPickerOption extends TypeaheadOption {
33
41
  // What shows up in the editor
34
42
  title;
@@ -451,19 +459,3 @@ export const uploadFile = (editor) => {
451
459
  throw new Error('Missing required `window.uploaderRef`');
452
460
  }
453
461
  };
454
- // Avoid handling upload success multiple times for the same file within a short interval
455
- // ref: https://github.com/blocklet/media-kit/issues/428
456
- function preventDuplicateUploadSuccess(handler) {
457
- let lastHandledTimestamp = 0;
458
- let lastHandledFileHash = '';
459
- return (...args) => {
460
- const now = Date.now();
461
- const fileHash = args[0]?.file?.hashFileName;
462
- if (now - lastHandledTimestamp < 1000 && fileHash === lastHandledFileHash) {
463
- return;
464
- }
465
- lastHandledTimestamp = now;
466
- lastHandledFileHash = fileHash;
467
- handler(...args);
468
- };
469
- }
@@ -0,0 +1 @@
1
+ export declare function preventDuplicateUploadSuccess(handler: (...args: any[]) => void): (...args: any[]) => void;
@@ -0,0 +1,29 @@
1
+ // Avoid handling upload success multiple times for the same file within a short interval
2
+ // ref: https://github.com/blocklet/media-kit/issues/428
3
+ // Module-level array to store recent uploaded files with timestamps
4
+ const recentUploads = [];
5
+ const DUPLICATE_THRESHOLD_MS = 1000;
6
+ export function preventDuplicateUploadSuccess(handler) {
7
+ return (...args) => {
8
+ const now = Date.now();
9
+ const fileHash = args[0]?.file?.hashFileName;
10
+ if (!fileHash) {
11
+ handler(...args);
12
+ return;
13
+ }
14
+ // Check if this file was recently uploaded
15
+ const isDuplicate = recentUploads.some((record) => record.fileHash === fileHash && now - record.timestamp < DUPLICATE_THRESHOLD_MS);
16
+ if (isDuplicate) {
17
+ return;
18
+ }
19
+ // Add new upload record
20
+ const newRecord = { fileHash, timestamp: now };
21
+ recentUploads.push(newRecord);
22
+ // Clean up old records that are beyond the threshold
23
+ const cutoffTime = now - DUPLICATE_THRESHOLD_MS;
24
+ const filteredUploads = recentUploads.filter((record) => record.timestamp >= cutoffTime);
25
+ recentUploads.length = 0;
26
+ recentUploads.push(...filteredUploads);
27
+ handler(...args);
28
+ };
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/editor",
3
- "version": "2.4.22",
3
+ "version": "2.4.24",
4
4
  "main": "lib/index.js",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -69,7 +69,7 @@
69
69
  "ufo": "^1.5.4",
70
70
  "url-join": "^4.0.1",
71
71
  "zustand": "^4.5.5",
72
- "@blocklet/pdf": "^2.4.22"
72
+ "@blocklet/pdf": "^2.4.24"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@babel/core": "^7.25.2",