@astrolimit/vue3-web-hooks 25.12.14 → 26.1.3

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.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as vue0 from "vue";
2
- import { DefineComponent, FunctionalComponent, Ref, VNode } from "vue";
2
+ import { ComputedRef, DefineComponent, FunctionalComponent, Ref, VNode } from "vue";
3
3
  import * as _vueuse_core0 from "@vueuse/core";
4
4
  import mitt from "mitt";
5
- import * as _vue_reactivity0 from "@vue/reactivity";
6
5
 
7
6
  //#region src/hooks/useDivSize.d.ts
8
7
 
@@ -130,12 +129,12 @@ declare const useSortable: <T extends AnyRecord>(params: {
130
129
  /**
131
130
  * 原始数据列表
132
131
  */
133
- rawDataList: Ref<Array<T>>;
132
+ rawDataList: Ref<Array<T>> | ComputedRef<Array<T>>;
134
133
  }) => {
135
134
  initSort: _vueuse_core0.PromisifyFn<() => void>;
136
135
  handleSortCancel: () => void;
137
136
  handleSortToggle: () => void;
138
- tableDataList: Ref<_vue_reactivity0.UnwrapRefSimple<T>[], T[] | _vue_reactivity0.UnwrapRefSimple<T>[]>;
137
+ sortedResult: ComputedRef<any>;
139
138
  isSorting: Ref<boolean, boolean>;
140
139
  };
141
140
  //#endregion
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import _, { cloneDeep } from "lodash";
1
+ import _, { isNil } from "lodash";
2
2
  import { computed, createElementVNode, defineComponent, inject, isRef, nextTick, onBeforeUnmount, onMounted, onUnmounted, provide, reactive, ref, toRefs, unref, watch } from "vue";
3
3
  import { tryOnMounted, tryOnUnmounted, useDebounceFn, useWindowSize } from "@vueuse/core";
4
4
  import mitt from "mitt";
5
- import { get, isInteger, isNil, toSafeInteger } from "lodash-es";
5
+ import { get, isInteger, isNil as isNil$1, toSafeInteger } from "lodash-es";
6
6
  import dayjs from "dayjs";
7
7
  import Sortable from "sortablejs";
8
8
 
@@ -303,7 +303,7 @@ const useStyleSheetLink = (option) => {
303
303
  const rLinkUrl = ref();
304
304
  const createLink = () => {
305
305
  const eid = `${id}`;
306
- if (!isNil(document.getElementById(eid))) return;
306
+ if (!isNil$1(document.getElementById(eid))) return;
307
307
  const blob = new Blob([`${cssContent}`], { type: "text/css" });
308
308
  const url = URL.createObjectURL(blob);
309
309
  const link = document.createElement("link");
@@ -315,11 +315,11 @@ const useStyleSheetLink = (option) => {
315
315
  rLinkUrl.value = url;
316
316
  };
317
317
  const destroy = () => {
318
- if (!isNil(rLinkDom.value)) {
318
+ if (!isNil$1(rLinkDom.value)) {
319
319
  document.head.removeChild(rLinkDom.value);
320
320
  rLinkDom.value = null;
321
321
  }
322
- if (!isNil(rLinkUrl.value)) {
322
+ if (!isNil$1(rLinkUrl.value)) {
323
323
  URL.revokeObjectURL(rLinkUrl.value);
324
324
  rLinkUrl.value = null;
325
325
  }
@@ -349,45 +349,63 @@ const useStyleSheetLink = (option) => {
349
349
  const useSortable = (params) => {
350
350
  const { tableCls, handleCls, rawDataList } = params;
351
351
  /**
352
- * 排序结果
352
+ * 排序内部数组
353
353
  */
354
354
  const tableDataList = ref([]);
355
355
  /**
356
+ * 排序结果
357
+ */
358
+ const sortedResult = computed(() => {
359
+ return JSON.parse(JSON.stringify(tableDataList.value));
360
+ });
361
+ /**
356
362
  * 是否正处于排序状态
357
363
  */
358
364
  const isSorting = ref(false);
359
365
  const initSort = useDebounceFn(() => {
360
366
  const table = document.querySelector(`.${tableCls} .el-table__body-wrapper tbody`);
361
367
  if (!table) return;
362
- Sortable.create(table, {
363
- group: "shared",
364
- animation: 150,
365
- draggable: ".el-table__row",
366
- handle: `.${handleCls || "drag-icon"}`,
367
- onEnd: ({ newDraggableIndex, oldDraggableIndex }) => {
368
- if (oldDraggableIndex !== newDraggableIndex) tableDataList.value.splice(newDraggableIndex, 0, tableDataList.value.splice(oldDraggableIndex, 1)[0]);
369
- }
368
+ nextTick(() => {
369
+ Sortable.create(table, {
370
+ group: "shared",
371
+ animation: 150,
372
+ draggable: ".el-table__row",
373
+ handle: `.${handleCls || "drag-icon"}`,
374
+ onEnd: ({ newDraggableIndex, oldDraggableIndex }) => {
375
+ if (oldDraggableIndex !== newDraggableIndex) tableDataList.value.splice(newDraggableIndex, 0, tableDataList.value.splice(oldDraggableIndex, 1)[0]);
376
+ }
377
+ });
370
378
  });
371
379
  }, 200);
380
+ /**
381
+ * 开始排序,完成排序
382
+ */
372
383
  const handleSortToggle = () => {
373
- if (isSorting.value) handleSortCancel();
384
+ if (isSorting.value) isSorting.value = false;
374
385
  else {
375
386
  isSorting.value = true;
376
387
  initSort();
377
388
  }
378
389
  };
390
+ /**
391
+ * 取消排序(重置内部数组)
392
+ */
379
393
  const handleSortCancel = () => {
380
- tableDataList.value = cloneDeep(rawDataList.value);
394
+ tableDataList.value = JSON.parse(JSON.stringify(rawDataList.value));
381
395
  isSorting.value = false;
382
396
  };
383
- watch(() => rawDataList.value, () => {
384
- tableDataList.value = cloneDeep(rawDataList.value);
397
+ watch(() => rawDataList.value, (newVal) => {
398
+ if (!isNil(newVal) && JSON.stringify(newVal) != JSON.stringify(tableDataList.value)) tableDataList.value = JSON.parse(JSON.stringify(newVal));
399
+ }, {
400
+ deep: true,
401
+ immediate: true,
402
+ flush: "post"
385
403
  });
386
404
  return {
387
405
  initSort,
388
406
  handleSortCancel,
389
407
  handleSortToggle,
390
- tableDataList,
408
+ sortedResult,
391
409
  isSorting
392
410
  };
393
411
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrolimit/vue3-web-hooks",
3
- "version": "25.12.014",
3
+ "version": "26.01.003",
4
4
  "description": "A starter for creating a Vue component library.",
5
5
  "type": "module",
6
6
  "license": "SFR",