knt-shared 1.10.4 → 1.10.6

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
@@ -1824,6 +1824,19 @@ const DEFAULT_CONFIG = {
1824
1824
  filePath: "filePath",
1825
1825
  fullFilePath: "fullFilePath"
1826
1826
  };
1827
+ function generateBackfillUid(fileObj, config, url, index = 0) {
1828
+ if ((fileObj == null ? void 0 : fileObj.id) != null) {
1829
+ return `back-${fileObj.id}`;
1830
+ }
1831
+ const path = fileObj == null ? void 0 : fileObj[config.filePath];
1832
+ if (path) {
1833
+ return `back-${path}`;
1834
+ }
1835
+ if (url) {
1836
+ return `back-${url}`;
1837
+ }
1838
+ return `back-${Date.now()}-${index}`;
1839
+ }
1827
1840
  function transformUploadUrl(transferUrl) {
1828
1841
  var _a;
1829
1842
  if (isNullOrUnDef(transferUrl)) {
@@ -1842,13 +1855,13 @@ function transformUploadUrl(transferUrl) {
1842
1855
  }
1843
1856
  return void 0;
1844
1857
  }
1845
- function transformBackUrl(transferUrl, config) {
1858
+ function transformBackUrl(transferUrl, config, index = 0) {
1846
1859
  const mergedConfig = { ...DEFAULT_CONFIG, ...config };
1847
1860
  if (!isArray(transferUrl) && (isNullOrUnDef(transferUrl) || isNullOrUnDef(transferUrl[mergedConfig.fullFilePath]) || isNullOrUnDef(transferUrl[mergedConfig.filePath]))) {
1848
1861
  return void 0;
1849
1862
  }
1850
1863
  if (isArray(transferUrl)) {
1851
- const result = transferUrl.map((item) => transformBackUrl(item, config)).filter((item) => !isNullOrUnDef(item));
1864
+ const result = transferUrl.map((item, index2) => transformBackUrl(item, config, index2)).filter((item) => !isNullOrUnDef(item));
1852
1865
  if (mergedConfig.backType === "object") {
1853
1866
  return result;
1854
1867
  }
@@ -1857,14 +1870,19 @@ function transformBackUrl(transferUrl, config) {
1857
1870
  let resultObj;
1858
1871
  if (isString(transferUrl)) {
1859
1872
  resultObj = {
1873
+ uid: generateBackfillUid(null, mergedConfig, transferUrl, index),
1874
+ name: transferUrl.split("/").pop() || `file-${index}`,
1860
1875
  url: transferUrl,
1861
1876
  path: void 0,
1862
1877
  status: "done"
1863
1878
  };
1864
1879
  } else if (isObject(transferUrl)) {
1865
1880
  const fileObj = transferUrl;
1881
+ const url = fileObj[mergedConfig.fullFilePath];
1866
1882
  resultObj = {
1867
- url: fileObj[mergedConfig.fullFilePath],
1883
+ uid: generateBackfillUid(fileObj, mergedConfig, url, index),
1884
+ name: (url == null ? void 0 : url.split("/").pop()) || `file-${index}`,
1885
+ url,
1868
1886
  path: fileObj[mergedConfig.filePath],
1869
1887
  status: "done"
1870
1888
  };
@@ -2956,7 +2974,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2956
2974
  emits: ["register", "update:modelValue", "change", "success", "handleSuccess", "error", "handlError", "progress", "remove", "preview", "exceed", "sortChange"],
2957
2975
  setup(__props, { expose: __expose, emit: __emit }) {
2958
2976
  useCssVars((_ctx) => ({
2959
- "v74ec8601": cardSizeValue.value
2977
+ "eb56f194": cardSizeValue.value
2960
2978
  }));
2961
2979
  const MAX_SIZE_UNIT_BYTES = {
2962
2980
  B: 1,
@@ -3342,10 +3360,30 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3342
3360
  emit("update:modelValue", fileList);
3343
3361
  }
3344
3362
  };
3363
+ const normalizeFileItem = (item, index) => {
3364
+ var _a;
3365
+ return {
3366
+ ...item,
3367
+ uid: item.uid || `file-${item.path || item.url || index}-${index}`,
3368
+ name: item.name || ((_a = item.url) == null ? void 0 : _a.split("/").pop()) || `file-${index}`,
3369
+ status: item.status || "done"
3370
+ };
3371
+ };
3372
+ const findFileIndex = (fileItem) => {
3373
+ if (fileItem.uid != null) {
3374
+ const index = fileListRef.value.findIndex(
3375
+ (item) => item.uid != null && item.uid === fileItem.uid
3376
+ );
3377
+ if (index !== -1) return index;
3378
+ }
3379
+ return fileListRef.value.findIndex(
3380
+ (item) => item.url === fileItem.url && item.path === fileItem.path
3381
+ );
3382
+ };
3345
3383
  const parseModelValue = (value) => {
3346
3384
  if (!value) return [];
3347
3385
  if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") {
3348
- return value;
3386
+ return value.map(normalizeFileItem);
3349
3387
  }
3350
3388
  if (Array.isArray(value)) {
3351
3389
  return value.map((url, index) => ({
@@ -3399,18 +3437,14 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3399
3437
  updateModelValue(fileListRef.value);
3400
3438
  };
3401
3439
  const removeFile = (fileItem) => {
3402
- const index = fileListRef.value.findIndex(
3403
- (item) => item.uid === fileItem.uid
3404
- );
3440
+ const index = findFileIndex(fileItem);
3405
3441
  if (index !== -1) {
3406
3442
  fileListRef.value.splice(index, 1);
3407
3443
  updateModelValue(fileListRef.value);
3408
3444
  }
3409
3445
  };
3410
3446
  const updateFile = (fileItem) => {
3411
- const index = fileListRef.value.findIndex(
3412
- (item) => item.uid === fileItem.uid
3413
- );
3447
+ const index = findFileIndex(fileItem);
3414
3448
  if (index !== -1) {
3415
3449
  fileListRef.value[index] = { ...fileListRef.value[index], ...fileItem };
3416
3450
  updateModelValue(fileListRef.value);
@@ -3617,7 +3651,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
3617
3651
  };
3618
3652
  }
3619
3653
  });
3620
- const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-d316e747"]]);
3654
+ const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-3a5bef91"]]);
3621
3655
  function useUpload(props) {
3622
3656
  const uploadRef = ref(null);
3623
3657
  const fileListRef = ref((props == null ? void 0 : props.defaultFileList) || []);
@@ -6817,6 +6851,12 @@ function useTableEdit(props, dataSource, getRowKey) {
6817
6851
  cancelEdit(record);
6818
6852
  });
6819
6853
  };
6854
+ const clearEditingRows = () => {
6855
+ Object.keys(editingStateMap).forEach((key) => delete editingStateMap[key]);
6856
+ Object.keys(editValueMap).forEach((key) => delete editValueMap[key]);
6857
+ Object.keys(originalDataMap).forEach((key) => delete originalDataMap[key]);
6858
+ Object.keys(validationErrorMap).forEach((key) => delete validationErrorMap[key]);
6859
+ };
6820
6860
  return {
6821
6861
  editingStateMap,
6822
6862
  editValueMap,
@@ -6833,6 +6873,7 @@ function useTableEdit(props, dataSource, getRowKey) {
6833
6873
  getEditingRows,
6834
6874
  saveAllEdits,
6835
6875
  cancelAllEdits,
6876
+ clearEditingRows,
6836
6877
  getChangedValues
6837
6878
  };
6838
6879
  }
@@ -7156,6 +7197,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
7156
7197
  getEditingRows,
7157
7198
  saveAllEdits,
7158
7199
  cancelAllEdits,
7200
+ clearEditingRows,
7159
7201
  getChangedValues
7160
7202
  } = useTableEdit(getMergedProps, dataSource, getRowKey);
7161
7203
  const originalColumnsMap = computed(() => {
@@ -7837,6 +7879,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
7837
7879
  getEditingRows,
7838
7880
  saveAllEdits,
7839
7881
  cancelAllEdits,
7882
+ clearEditingRows,
7840
7883
  isEditing,
7841
7884
  getEditValue,
7842
7885
  setEditValue,
@@ -7881,6 +7924,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
7881
7924
  getEditingRows,
7882
7925
  saveAllEdits,
7883
7926
  cancelAllEdits,
7927
+ clearEditingRows,
7884
7928
  isEditing,
7885
7929
  getEditValue,
7886
7930
  setEditValue,
@@ -8350,7 +8394,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
8350
8394
  };
8351
8395
  }
8352
8396
  });
8353
- const BasicTable = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-b3a2e402"]]);
8397
+ const BasicTable = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-1a0967ac"]]);
8354
8398
  function useTable(options = {}) {
8355
8399
  const tableRef = ref(null);
8356
8400
  const formRef = ref(null);
@@ -8627,6 +8671,13 @@ function useTable(options = {}) {
8627
8671
  table.cancelAllEdits();
8628
8672
  }
8629
8673
  };
8674
+ const clearEditingRows = () => {
8675
+ const table = getTable();
8676
+ if (!table) return;
8677
+ if (table.clearEditingRows) {
8678
+ table.clearEditingRows();
8679
+ }
8680
+ };
8630
8681
  const isEditing = (record, column) => {
8631
8682
  const table = getTable();
8632
8683
  if (!table) return false;
@@ -8694,6 +8745,7 @@ function useTable(options = {}) {
8694
8745
  getEditingRows,
8695
8746
  saveAllEdits,
8696
8747
  cancelAllEdits,
8748
+ clearEditingRows,
8697
8749
  isEditing,
8698
8750
  getEditValue,
8699
8751
  setEditValue,