knt-shared 1.10.7 → 1.10.8

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/dist/index.esm.js CHANGED
@@ -2483,6 +2483,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2483
2483
  const props = __props;
2484
2484
  const emit = __emit;
2485
2485
  const videoRef = ref();
2486
+ const progressBarRef = ref();
2486
2487
  const isPlaying = ref(false);
2487
2488
  const isLoading = ref(true);
2488
2489
  const currentTime = ref(0);
@@ -2511,7 +2512,11 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2511
2512
  videoRef.value.pause();
2512
2513
  emit("pause");
2513
2514
  } else {
2514
- videoRef.value.play();
2515
+ videoRef.value.play().catch((err) => {
2516
+ if (err.name !== "AbortError") {
2517
+ console.error("[VideoPreview] play() 失败:", err);
2518
+ }
2519
+ });
2515
2520
  emit("play");
2516
2521
  }
2517
2522
  };
@@ -2579,11 +2584,8 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2579
2584
  document.addEventListener("mouseup", handleProgressMouseUp);
2580
2585
  };
2581
2586
  const handleProgressMouseMove = (event) => {
2582
- var _a2, _b;
2583
- if (!isDraggingProgress.value || !videoRef.value) return;
2584
- const container = (_b = (_a2 = videoRef.value.parentElement) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b.querySelector(".progress-bar-container");
2585
- if (!container) return;
2586
- const rect = container.getBoundingClientRect();
2587
+ if (!isDraggingProgress.value || !videoRef.value || !progressBarRef.value) return;
2588
+ const rect = progressBarRef.value.getBoundingClientRect();
2587
2589
  let percent = (event.clientX - rect.left) / rect.width;
2588
2590
  percent = Math.max(0, Math.min(1, percent));
2589
2591
  videoRef.value.currentTime = percent * duration.value;
@@ -2696,6 +2698,8 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2696
2698
  }, ["stop"]))
2697
2699
  }, [
2698
2700
  createElementVNode("div", {
2701
+ ref_key: "progressBarRef",
2702
+ ref: progressBarRef,
2699
2703
  class: "progress-bar-container",
2700
2704
  onClick: handleProgressClick
2701
2705
  }, [
@@ -2714,7 +2718,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2714
2718
  onMousedown: handleProgressMouseDown
2715
2719
  }, null, 36)
2716
2720
  ])
2717
- ]),
2721
+ ], 512),
2718
2722
  createElementVNode("div", _hoisted_6$3, [
2719
2723
  createElementVNode("div", _hoisted_7$2, [
2720
2724
  createElementVNode("button", {
@@ -2808,7 +2812,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2808
2812
  };
2809
2813
  }
2810
2814
  });
2811
- const VideoPreview = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["__scopeId", "data-v-b982f870"]]);
2815
+ const VideoPreview = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["__scopeId", "data-v-d4fd2c00"]]);
2812
2816
  const _hoisted_1$a = { class: "video-modal-title" };
2813
2817
  const _hoisted_2$7 = { class: "file-name" };
2814
2818
  const _hoisted_3$5 = { class: "video-modal-content" };
@@ -2831,7 +2835,6 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2831
2835
  },
2832
2836
  emits: ["update:visible", "play", "pause", "ended"],
2833
2837
  setup(__props, { emit: __emit }) {
2834
- const props = __props;
2835
2838
  const emit = __emit;
2836
2839
  const handleClose = () => {
2837
2840
  emit("update:visible", false);
@@ -2845,11 +2848,6 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2845
2848
  const handleEnded = () => {
2846
2849
  emit("ended");
2847
2850
  };
2848
- watch(
2849
- () => props.visible,
2850
- (newVisible) => {
2851
- }
2852
- );
2853
2851
  return (_ctx, _cache) => {
2854
2852
  return openBlock(), createBlock(unref(Modal), {
2855
2853
  visible: __props.visible,
@@ -2883,7 +2881,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2883
2881
  };
2884
2882
  }
2885
2883
  });
2886
- const VideoPreviewModal = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-cac8e63e"]]);
2884
+ const VideoPreviewModal = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-db151e2d"]]);
2887
2885
  const _hoisted_1$9 = { class: "basic-upload" };
2888
2886
  const _hoisted_2$6 = {
2889
2887
  key: 0,
@@ -2971,10 +2969,10 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2971
2969
  showErrorMessage: { type: Boolean, default: true },
2972
2970
  showSuccessMessage: { type: Boolean, default: true }
2973
2971
  },
2974
- emits: ["register", "update:modelValue", "change", "success", "handleSuccess", "error", "handlError", "progress", "remove", "preview", "exceed", "sortChange"],
2972
+ emits: ["register", "update:modelValue", "change", "handleSuccess", "handleError", "progress", "remove", "preview", "exceed", "sortChange"],
2975
2973
  setup(__props, { expose: __expose, emit: __emit }) {
2976
2974
  useCssVars((_ctx) => ({
2977
- "eb56f194": cardSizeValue.value
2975
+ "v0a277aea": cardSizeValue.value
2978
2976
  }));
2979
2977
  const MAX_SIZE_UNIT_BYTES = {
2980
2978
  B: 1,
@@ -3144,6 +3142,11 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3144
3142
  }
3145
3143
  return defaultUpload(options);
3146
3144
  };
3145
+ const isSafeUrl = (url) => {
3146
+ if (!url || typeof url !== "string") return false;
3147
+ const lower = url.trim().toLowerCase();
3148
+ return !lower.startsWith("javascript:") && !lower.startsWith("data:");
3149
+ };
3147
3150
  const extractUrlFromResponse = (response) => {
3148
3151
  const urlPaths = [
3149
3152
  "url",
@@ -3155,11 +3158,11 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3155
3158
  ];
3156
3159
  for (const path of urlPaths) {
3157
3160
  const value = path.split(".").reduce((obj, key) => obj == null ? void 0 : obj[key], response);
3158
- if (value && typeof value === "string") {
3161
+ if (value && typeof value === "string" && isSafeUrl(value)) {
3159
3162
  return value;
3160
3163
  }
3161
3164
  }
3162
- if (response.data && typeof response.data === "string") {
3165
+ if (response.data && typeof response.data === "string" && isSafeUrl(response.data)) {
3163
3166
  return response.data;
3164
3167
  }
3165
3168
  return null;
@@ -3182,11 +3185,8 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3182
3185
  }, 3e3);
3183
3186
  }
3184
3187
  onError(new Error("上传地址未配置"));
3185
- return {
3186
- abort() {
3187
- xhr.abort();
3188
- }
3189
- };
3188
+ return { abort() {
3189
+ } };
3190
3190
  }
3191
3191
  const formData = new FormData();
3192
3192
  formData.append(propsData.name || "file", fileItem.file);
@@ -3252,23 +3252,17 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3252
3252
  }
3253
3253
  };
3254
3254
  };
3255
+ const VIDEO_EXTENSIONS = [".mp4", ".avi", ".mov", ".wmv", ".flv", ".webm", ".mkv", ".m4v"];
3255
3256
  const addVideoFileClass = () => {
3256
3257
  nextTick(() => {
3257
- const uploadItems = document.querySelectorAll(".arco-upload-list-picture");
3258
+ var _a;
3259
+ const root = ((_a = uploadRef.value) == null ? void 0 : _a.$el) ?? null;
3260
+ const scope = root ?? document;
3261
+ const uploadItems = scope.querySelectorAll(".arco-upload-list-picture");
3258
3262
  uploadItems.forEach((item) => {
3259
3263
  const img = item.querySelector("img");
3260
3264
  if (img && img.src) {
3261
- const videoExtensions = [
3262
- ".mp4",
3263
- ".avi",
3264
- ".mov",
3265
- ".wmv",
3266
- ".flv",
3267
- ".webm",
3268
- ".mkv",
3269
- ".m4v"
3270
- ];
3271
- const isVideo = videoExtensions.some(
3265
+ const isVideo = VIDEO_EXTENSIONS.some(
3272
3266
  (ext) => img.src.toLowerCase().includes(ext)
3273
3267
  );
3274
3268
  if (isVideo) {
@@ -3282,14 +3276,15 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3282
3276
  };
3283
3277
  const handleChange = (fileList, currentFile) => {
3284
3278
  const oldLength = fileListRef.value.length;
3285
- const newLength = fileList.length;
3279
+ const newFileList = currentFile.status === "error" ? fileList.filter((f) => f.uid !== currentFile.uid) : fileList;
3280
+ const newLength = newFileList.length;
3286
3281
  if (newLength > oldLength) {
3287
3282
  const added = newLength - oldLength;
3288
3283
  pendingCount.value = Math.max(0, pendingCount.value - added);
3289
3284
  }
3290
- fileListRef.value = fileList;
3285
+ fileListRef.value = newFileList;
3291
3286
  addVideoFileClass();
3292
- emit("change", fileList);
3287
+ emit("change", newFileList);
3293
3288
  const isRemove = newLength < oldLength;
3294
3289
  const fileKey = currentFile.uid || `file-${Date.now()}-${Math.random()}`;
3295
3290
  const lastStatus = processedFiles.value.get(fileKey);
@@ -3297,19 +3292,18 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3297
3292
  processedFiles.value.set(fileKey, "done");
3298
3293
  emit("handleSuccess", currentFile.response, currentFile);
3299
3294
  } else if (currentFile.status === "error" && lastStatus !== "error") {
3300
- processedFiles.value.set(fileKey, "error");
3301
3295
  const error = new Error("上传失败");
3302
- emit("handlError", error, currentFile);
3296
+ emit("handleError", error, currentFile);
3303
3297
  }
3304
3298
  if (isRemove) {
3305
- const fileUids = new Set(fileList.map((f) => f.uid));
3299
+ const fileUids = new Set(newFileList.map((f) => f.uid));
3306
3300
  processedFiles.value.forEach((_value, uid) => {
3307
3301
  if (!fileUids.has(uid)) {
3308
3302
  processedFiles.value.delete(uid);
3309
3303
  }
3310
3304
  });
3311
3305
  }
3312
- updateModelValue(fileList);
3306
+ updateModelValue(newFileList);
3313
3307
  };
3314
3308
  const handleProgress = (currentFile) => {
3315
3309
  const percent = currentFile.percent || 0;
@@ -3380,14 +3374,17 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3380
3374
  (item) => item.url === fileItem.url && item.path === fileItem.path
3381
3375
  );
3382
3376
  };
3377
+ const stableUid = (url, index) => `url-${index}-${url.replace(/[^a-zA-Z0-9.\-_]/g, "_")}`;
3383
3378
  const parseModelValue = (value) => {
3384
3379
  if (!value) return [];
3385
- if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") {
3386
- return value.map(normalizeFileItem);
3387
- }
3388
3380
  if (Array.isArray(value)) {
3389
- return value.map((url, index) => ({
3390
- uid: `${Date.now()}-${index}`,
3381
+ if (value.length === 0) return [];
3382
+ const first = value[0];
3383
+ if (first !== null && first !== void 0 && typeof first === "object") {
3384
+ return value.filter((item) => item !== null && item !== void 0).map(normalizeFileItem);
3385
+ }
3386
+ return value.filter((url) => url && typeof url === "string").map((url, index) => ({
3387
+ uid: stableUid(url.trim(), index),
3391
3388
  name: url.split("/").pop() || `file-${index}`,
3392
3389
  url,
3393
3390
  status: "done"
@@ -3396,8 +3393,8 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3396
3393
  if (typeof value === "string") {
3397
3394
  const urls = value.split(",").filter(Boolean);
3398
3395
  return urls.map((url, index) => ({
3399
- uid: `${Date.now()}-${index}`,
3400
- name: url.split("/").pop() || `file-${index}`,
3396
+ uid: stableUid(url.trim(), index),
3397
+ name: url.trim().split("/").pop() || `file-${index}`,
3401
3398
  url: url.trim(),
3402
3399
  status: "done"
3403
3400
  }));
@@ -3481,10 +3478,23 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3481
3478
  watch(
3482
3479
  () => getProps.value.modelValue,
3483
3480
  (val) => {
3484
- fileListRef.value = parseModelValue(val);
3481
+ const parsed = parseModelValue(val);
3482
+ const isExternalClear = !val || Array.isArray(val) && val.length === 0 || typeof val === "string" && val.trim() === "";
3483
+ if (!isExternalClear) {
3484
+ const hasUploading = fileListRef.value.some(
3485
+ (f) => f.status === "uploading" || f.status === "init"
3486
+ );
3487
+ if (hasUploading) return;
3488
+ }
3489
+ const isSame = parsed.length === fileListRef.value.length && parsed.every((newItem, i) => {
3490
+ const oldItem = fileListRef.value[i];
3491
+ return newItem.uid === (oldItem == null ? void 0 : oldItem.uid) && newItem.url === (oldItem == null ? void 0 : oldItem.url);
3492
+ });
3493
+ if (isSame) return;
3494
+ fileListRef.value = parsed;
3485
3495
  addVideoFileClass();
3486
3496
  },
3487
- { immediate: true }
3497
+ { immediate: true, deep: true }
3488
3498
  );
3489
3499
  onMounted(() => {
3490
3500
  nextTick(() => {
@@ -3651,7 +3661,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3651
3661
  };
3652
3662
  }
3653
3663
  });
3654
- const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-3a5bef91"]]);
3664
+ const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-d256c7da"]]);
3655
3665
  function useUpload(props) {
3656
3666
  const uploadRef = ref(null);
3657
3667
  const fileListRef = ref((props == null ? void 0 : props.defaultFileList) || []);
@@ -3661,7 +3671,7 @@ function useUpload(props) {
3661
3671
  uploadInstance.setFileList(props.defaultFileList);
3662
3672
  }
3663
3673
  if (props && Object.keys(props).length > 0) {
3664
- const { defaultFileList, ...restProps } = props;
3674
+ const { defaultFileList: _, ...restProps } = props;
3665
3675
  if (Object.keys(restProps).length > 0) {
3666
3676
  setProps(restProps);
3667
3677
  }
@@ -3685,48 +3695,36 @@ function useUpload(props) {
3685
3695
  fileListRef.value = [];
3686
3696
  };
3687
3697
  const getFileList = () => {
3688
- return getUpload().getFileList();
3698
+ const list = getUpload().getFileList();
3699
+ fileListRef.value = list;
3700
+ return list;
3689
3701
  };
3690
3702
  const upload = (fileItem) => {
3691
3703
  getUpload().upload(fileItem);
3692
3704
  };
3693
3705
  const setFileList = (files) => {
3694
- fileListRef.value = files;
3706
+ var _a;
3695
3707
  const upload2 = getUpload();
3696
- if (upload2.setFileList) {
3697
- upload2.setFileList(files);
3698
- }
3708
+ (_a = upload2.setFileList) == null ? void 0 : _a.call(upload2, files);
3709
+ fileListRef.value = upload2.getFileList();
3699
3710
  };
3700
3711
  const addFile = (file) => {
3701
- fileListRef.value.push(file);
3712
+ var _a;
3702
3713
  const upload2 = getUpload();
3703
- if (upload2.addFile) {
3704
- upload2.addFile(file);
3705
- }
3714
+ (_a = upload2.addFile) == null ? void 0 : _a.call(upload2, file);
3715
+ fileListRef.value = upload2.getFileList();
3706
3716
  };
3707
3717
  const removeFile = (fileItem) => {
3708
- const index = fileListRef.value.findIndex(
3709
- (item) => item.uid === fileItem.uid
3710
- );
3711
- if (index !== -1) {
3712
- fileListRef.value.splice(index, 1);
3713
- }
3718
+ var _a;
3714
3719
  const upload2 = getUpload();
3715
- if (upload2.removeFile) {
3716
- upload2.removeFile(fileItem);
3717
- }
3720
+ (_a = upload2.removeFile) == null ? void 0 : _a.call(upload2, fileItem);
3721
+ fileListRef.value = upload2.getFileList();
3718
3722
  };
3719
3723
  const updateFile = (fileItem) => {
3720
- const index = fileListRef.value.findIndex(
3721
- (item) => item.uid === fileItem.uid
3722
- );
3723
- if (index !== -1) {
3724
- fileListRef.value[index] = { ...fileListRef.value[index], ...fileItem };
3725
- }
3724
+ var _a;
3726
3725
  const upload2 = getUpload();
3727
- if (upload2.updateFile) {
3728
- upload2.updateFile(fileItem);
3729
- }
3726
+ (_a = upload2.updateFile) == null ? void 0 : _a.call(upload2, fileItem);
3727
+ fileListRef.value = upload2.getFileList();
3730
3728
  };
3731
3729
  const setProps = (uploadProps) => {
3732
3730
  getUpload().setProps(uploadProps);