@veltra/compositions 1.3.2 → 1.3.4

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,6 +1,7 @@
1
1
  import { useComponentProps } from "./use-component-props/index.js";
2
2
  import { setDocumentSize, useConfig } from "./use-config/index.js";
3
3
  import { useDrag } from "./use-drag/index.js";
4
+ import { BaseDragState, DNDPlugin, DNDPluginData, DragState, DragendEvent, DragendEventData, DragstartEvent, DragstartEventData, DropSwapConfig, InsertConfig, InsertEvent, NativeDragEffects, Node, NodeData, NodeDragEventData, NodeEventData, NodePointerEventData, NodeRecord, NodeTargetData, ParentConfig, ParentData, ParentDragEventData, ParentEventData, ParentRecord, ParentTargetData, PointeroverNodeEvent, PointeroverParentEvent, SetupNode, SetupNodeData, ShouldSwapData, SortEvent, SortEventData, SynthDragState, TearDownNode, TearDownNodeData, TransferEvent, TransferEventData, UseDnDOptions, UseDnDResult, VueDragAndDropData, VueElement, VueParentConfig, animations, dragAndDrop, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setParentValues, tearDown, updateConfig, useDnD, useDragAndDrop } from "./use-dnd/index.js";
4
5
  import { useFallbackProps, useFormFallbackProps } from "./use-fallback-props/index.js";
5
6
  import { useFocus } from "./use-focus/index.js";
6
7
  import { UserAction, UserActionResult, useUserAction } from "./use-user-action/index.js";
@@ -10,4 +11,4 @@ import { RefElement, ResizeObserverReturn, useObserverCallback, useResizeObserve
10
11
  import { useReactiveSize } from "./use-reactive-size/index.js";
11
12
  import { useTransition } from "./use-transition/index.js";
12
13
  import { UseVirtualizerOptions, UseVirtualizerReturned, useVirtualizer } from "./use-virtualizer/index.js";
13
- export { RefElement, ResizeObserverReturn, UseVirtualizerOptions, UseVirtualizerReturned, UserAction, UserActionResult, setDocumentSize, useComponentProps, useConfig, useDrag, useFallbackProps, useFocus, useFormFallbackProps, useModel, useObserverCallback, usePop, useReactiveSize, useResizeObserver, useTransition, useUserAction, useVirtualizer };
14
+ export { type BaseDragState, type DNDPlugin, type DNDPluginData, type DragState, type DragendEvent, type DragendEventData, type DragstartEvent, type DragstartEventData, type DropSwapConfig, type InsertConfig, type InsertEvent, type NativeDragEffects, type Node, type NodeData, type NodeDragEventData, type NodeEventData, type NodePointerEventData, type NodeRecord, type NodeTargetData, type ParentConfig, type ParentData, type ParentDragEventData, type ParentEventData, type ParentRecord, type ParentTargetData, type PointeroverNodeEvent, type PointeroverParentEvent, RefElement, ResizeObserverReturn, type SetupNode, type SetupNodeData, type ShouldSwapData, type SortEvent, type SortEventData, type SynthDragState, type TearDownNode, type TearDownNodeData, type TransferEvent, type TransferEventData, UseDnDOptions, UseDnDResult, UseVirtualizerOptions, UseVirtualizerReturned, UserAction, UserActionResult, type VueDragAndDropData, type VueElement, type VueParentConfig, animations, dragAndDrop, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setDocumentSize, setParentValues, tearDown, updateConfig, useComponentProps, useConfig, useDnD, useDrag, useDragAndDrop, useFallbackProps, useFocus, useFormFallbackProps, useModel, useObserverCallback, usePop, useReactiveSize, useResizeObserver, useTransition, useUserAction, useVirtualizer };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useComponentProps } from "./use-component-props/index.js";
2
2
  import { setDocumentSize, useConfig } from "./use-config/index.js";
3
3
  import { useDrag } from "./use-drag/index.js";
4
+ import { animations, dragAndDrop, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setParentValues, tearDown, updateConfig, useDnD, useDragAndDrop } from "./use-dnd/index.js";
4
5
  import { useFallbackProps, useFormFallbackProps } from "./use-fallback-props/index.js";
5
6
  import { useFocus } from "./use-focus/index.js";
6
7
  import { useUserAction } from "./use-user-action/index.js";
@@ -10,4 +11,4 @@ import { useObserverCallback, useResizeObserver } from "./use-resize-observer/in
10
11
  import { useReactiveSize } from "./use-reactive-size/index.js";
11
12
  import { useTransition } from "./use-transition/index.js";
12
13
  import { useVirtualizer } from "./use-virtualizer/index.js";
13
- export { setDocumentSize, useComponentProps, useConfig, useDrag, useFallbackProps, useFocus, useFormFallbackProps, useModel, useObserverCallback, usePop, useReactiveSize, useResizeObserver, useTransition, useUserAction, useVirtualizer };
14
+ export { animations, dragAndDrop, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setDocumentSize, setParentValues, tearDown, updateConfig, useComponentProps, useConfig, useDnD, useDrag, useDragAndDrop, useFallbackProps, useFocus, useFormFallbackProps, useModel, useObserverCallback, usePop, useReactiveSize, useResizeObserver, useTransition, useUserAction, useVirtualizer };
@@ -1,5 +1,4 @@
1
1
  import { Component, MaybeRef } from "vue";
2
-
3
2
  //#region src/use-component-props/index.d.ts
4
3
  /**
5
4
  * 生成一个用于设置组件通用属性的组件
@@ -1,5 +1,4 @@
1
1
  import { ComponentSize } from "@veltra/utils";
2
-
3
2
  //#region src/use-config/index.d.ts
4
3
  interface State {
5
4
  /** 是否开启动画,机器老可以关闭动画来获得性能 */
@@ -8,7 +7,8 @@ interface State {
8
7
  size: ComponentSize;
9
8
  /** 表单 */
10
9
  form: {
11
- /** 标签宽度 */labelWidth?: number | string;
10
+ /** 标签宽度 */
11
+ labelWidth?: number | string;
12
12
  };
13
13
  paginator: {
14
14
  pageSize: number;
@@ -0,0 +1,47 @@
1
+ import { Ref } from "vue";
2
+ import { BaseDragState, DNDPlugin, DNDPluginData, DragState, DragendEvent, DragendEventData, DragstartEvent, DragstartEventData, DropSwapConfig, InsertConfig, InsertEvent, NativeDragEffects, Node, NodeData, NodeDragEventData, NodeEventData, NodePointerEventData, NodeRecord, NodeTargetData, ParentConfig, ParentData, ParentDragEventData, ParentEventData, ParentRecord, ParentTargetData, PointeroverNodeEvent, PointeroverParentEvent, SetupNode, SetupNodeData, ShouldSwapData, SortEvent, SortEventData, SynthDragState, TearDownNode, TearDownNodeData, TransferEvent, TransferEventData, animations, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setParentValues, tearDown as tearDown$1, updateConfig } from "@formkit/drag-and-drop";
3
+ import { VueDragAndDropData, VueElement, VueParentConfig, VueParentConfig as VueParentConfig$1, dragAndDrop as dragAndDrop$1, useDragAndDrop } from "@formkit/drag-and-drop/vue";
4
+ //#region src/use-dnd/index.d.ts
5
+ interface UseDnDOptions<T> extends VueParentConfig<T> {
6
+ /**
7
+ * 列表数据。传入 ref 时与外部共享同一个引用,拖拽排序/转移后直接写回;
8
+ * 传入普通数组或不传时内部创建 ref。
9
+ */
10
+ values?: T[] | Ref<T[]>;
11
+ }
12
+ interface UseDnDResult<T> {
13
+ /** 拖拽容器元素,通过 `ref` 绑定到列表容器元素上 */
14
+ parentRef: Ref<HTMLElement | undefined>;
15
+ /** 列表数据,排序/跨容器转移后自动更新 */
16
+ values: Ref<T[]>;
17
+ /**
18
+ * 运行时更新拖拽配置(整体替换,不与初始配置合并)
19
+ * @param config 新配置
20
+ */
21
+ updateConfig: (config?: VueParentConfig<T>) => void;
22
+ }
23
+ /**
24
+ * 拖拽排序组合式方法,基于 `@formkit/drag-and-drop` 的 Vue 适配层封装。
25
+ *
26
+ * 相比官方 `useDragAndDrop` 的元组返回,这里使用 options 对象传参并返回命名结果。
27
+ * 组件卸载时自动销毁拖拽实例。
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const { parentRef, values } = useDnD({
32
+ * values: list,
33
+ * plugins: [animations()],
34
+ * onSort: ({ previousValues, values }) => {}
35
+ * })
36
+ * ```
37
+ *
38
+ * ```vue
39
+ * <ul ref="parentRef">
40
+ * <li v-for="item in values" :key="item.id">{{ item.label }}</li>
41
+ * </ul>
42
+ * ```
43
+ */
44
+ declare function useDnD<T>(options?: UseDnDOptions<T>): UseDnDResult<T>;
45
+ //#endregion
46
+ export { type BaseDragState, type DNDPlugin, type DNDPluginData, type DragState, type DragendEvent, type DragendEventData, type DragstartEvent, type DragstartEventData, type DropSwapConfig, type InsertConfig, type InsertEvent, type NativeDragEffects, type Node, type NodeData, type NodeDragEventData, type NodeEventData, type NodePointerEventData, type NodeRecord, type NodeTargetData, type ParentConfig, type ParentData, type ParentDragEventData, type ParentEventData, type ParentRecord, type ParentTargetData, type PointeroverNodeEvent, type PointeroverParentEvent, type SetupNode, type SetupNodeData, type ShouldSwapData, type SortEvent, type SortEventData, type SynthDragState, type TearDownNode, type TearDownNodeData, type TransferEvent, type TransferEventData, UseDnDOptions, UseDnDResult, type VueDragAndDropData, type VueElement, type VueParentConfig$1 as VueParentConfig, animations, dragAndDrop$1 as dragAndDrop, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setParentValues, tearDown$1 as tearDown, updateConfig, useDnD, useDragAndDrop };
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,50 @@
1
+ import { isRef, onBeforeUnmount, ref } from "vue";
2
+ import { animations, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setParentValues, tearDown, tearDown as tearDown$1, updateConfig } from "@formkit/drag-and-drop";
3
+ import { dragAndDrop, dragAndDrop as dragAndDrop$1, useDragAndDrop } from "@formkit/drag-and-drop/vue";
4
+ //#region src/use-dnd/index.ts
5
+ /**
6
+ * 拖拽排序组合式方法,基于 `@formkit/drag-and-drop` 的 Vue 适配层封装。
7
+ *
8
+ * 相比官方 `useDragAndDrop` 的元组返回,这里使用 options 对象传参并返回命名结果。
9
+ * 组件卸载时自动销毁拖拽实例。
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const { parentRef, values } = useDnD({
14
+ * values: list,
15
+ * plugins: [animations()],
16
+ * onSort: ({ previousValues, values }) => {}
17
+ * })
18
+ * ```
19
+ *
20
+ * ```vue
21
+ * <ul ref="parentRef">
22
+ * <li v-for="item in values" :key="item.id">{{ item.label }}</li>
23
+ * </ul>
24
+ * ```
25
+ */
26
+ function useDnD(options = {}) {
27
+ const { values: initialValues, ...config } = options;
28
+ const parentRef = ref();
29
+ const values = isRef(initialValues) ? initialValues : ref(initialValues ?? []);
30
+ function updateConfig(newConfig = {}) {
31
+ dragAndDrop({
32
+ parent: parentRef,
33
+ values,
34
+ ...newConfig
35
+ });
36
+ }
37
+ updateConfig(config);
38
+ onBeforeUnmount(() => {
39
+ parentRef.value && tearDown(parentRef.value);
40
+ });
41
+ return {
42
+ parentRef,
43
+ values,
44
+ updateConfig
45
+ };
46
+ }
47
+ //#endregion
48
+ export { animations, dragAndDrop$1 as dragAndDrop, dragValues, dropOrSwap, insert, isBrowser, isDragState, isSynthDragState, parentValues, performSort, performTransfer, remapNodes, setParentValues, tearDown$1 as tearDown, updateConfig, useDnD, useDragAndDrop };
49
+
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/use-dnd/index.ts"],"sourcesContent":["import { tearDown } from '@formkit/drag-and-drop'\nimport { dragAndDrop, type VueParentConfig } from '@formkit/drag-and-drop/vue'\nimport { isRef, onBeforeUnmount, ref, type Ref } from 'vue'\n\nexport interface UseDnDOptions<T> extends VueParentConfig<T> {\n /**\n * 列表数据。传入 ref 时与外部共享同一个引用,拖拽排序/转移后直接写回;\n * 传入普通数组或不传时内部创建 ref。\n */\n values?: T[] | Ref<T[]>\n}\n\nexport interface UseDnDResult<T> {\n /** 拖拽容器元素,通过 `ref` 绑定到列表容器元素上 */\n parentRef: Ref<HTMLElement | undefined>\n /** 列表数据,排序/跨容器转移后自动更新 */\n values: Ref<T[]>\n /**\n * 运行时更新拖拽配置(整体替换,不与初始配置合并)\n * @param config 新配置\n */\n updateConfig: (config?: VueParentConfig<T>) => void\n}\n\n/**\n * 拖拽排序组合式方法,基于 `@formkit/drag-and-drop` 的 Vue 适配层封装。\n *\n * 相比官方 `useDragAndDrop` 的元组返回,这里使用 options 对象传参并返回命名结果。\n * 组件卸载时自动销毁拖拽实例。\n *\n * @example\n * ```ts\n * const { parentRef, values } = useDnD({\n * values: list,\n * plugins: [animations()],\n * onSort: ({ previousValues, values }) => {}\n * })\n * ```\n *\n * ```vue\n * <ul ref=\"parentRef\">\n * <li v-for=\"item in values\" :key=\"item.id\">{{ item.label }}</li>\n * </ul>\n * ```\n */\nexport function useDnD<T>(options: UseDnDOptions<T> = {}): UseDnDResult<T> {\n const { values: initialValues, ...config } = options\n\n const parentRef = ref<HTMLElement>()\n const values = isRef(initialValues) ? initialValues : (ref(initialValues ?? []) as Ref<T[]>)\n\n function updateConfig(newConfig: VueParentConfig<T> = {}) {\n dragAndDrop({ parent: parentRef, values, ...newConfig })\n }\n\n updateConfig(config)\n\n onBeforeUnmount(() => {\n parentRef.value && tearDown(parentRef.value)\n })\n\n return { parentRef, values, updateConfig }\n}\n\n// 重导出 `@formkit/drag-and-drop`,下游项目统一从 `@veltra/compositions` 获取,\n// 避免本库与下游各自安装导致版本不一致(体积膨胀 / 兼容问题)。\nexport {\n // Vue 适配层原始 API\n dragAndDrop,\n useDragAndDrop,\n type VueDragAndDropData,\n type VueElement,\n type VueParentConfig\n} from '@formkit/drag-and-drop/vue'\n\nexport {\n // 插件\n animations,\n dropOrSwap,\n insert,\n // 操作与状态工具\n performSort,\n performTransfer,\n remapNodes,\n updateConfig,\n parentValues,\n setParentValues,\n dragValues,\n isDragState,\n isSynthDragState,\n isBrowser,\n tearDown,\n // 类型\n type ParentConfig,\n type ParentData,\n type ParentRecord,\n type Node,\n type NodeData,\n type NodeRecord,\n type NodeTargetData,\n type ParentTargetData,\n type BaseDragState,\n type DragState,\n type SynthDragState,\n type NativeDragEffects,\n type DNDPlugin,\n type DNDPluginData,\n type NodeEventData,\n type NodeDragEventData,\n type NodePointerEventData,\n type ParentEventData,\n type ParentDragEventData,\n type SortEvent,\n type SortEventData,\n type TransferEvent,\n type TransferEventData,\n type DragstartEvent,\n type DragstartEventData,\n type DragendEvent,\n type DragendEventData,\n type ShouldSwapData,\n type DropSwapConfig,\n type InsertConfig,\n type InsertEvent,\n type SetupNode,\n type SetupNodeData,\n type TearDownNode,\n type TearDownNodeData,\n type PointeroverNodeEvent,\n type PointeroverParentEvent\n} from '@formkit/drag-and-drop'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,OAAU,UAA4B,CAAC,GAAoB;CACzE,MAAM,EAAE,QAAQ,eAAe,GAAG,WAAW;CAE7C,MAAM,YAAY,IAAiB;CACnC,MAAM,SAAS,MAAM,aAAa,IAAI,gBAAiB,IAAI,iBAAiB,CAAC,CAAC;CAE9E,SAAS,aAAa,YAAgC,CAAC,GAAG;EACxD,YAAY;GAAE,QAAQ;GAAW;GAAQ,GAAG;EAAU,CAAC;CACzD;CAEA,aAAa,MAAM;CAEnB,sBAAsB;EACpB,UAAU,SAAS,SAAS,UAAU,KAAK;CAC7C,CAAC;CAED,OAAO;EAAE;EAAW;EAAQ;CAAa;AAC3C"}
@@ -1,5 +1,4 @@
1
1
  import { Ref, ShallowRef } from "vue";
2
-
3
2
  //#region src/use-drag/index.d.ts
4
3
  interface DragParams {
5
4
  /** 本次拖动水平距离 */
@@ -1,13 +1,12 @@
1
1
  import { ComponentSize } from "@veltra/utils";
2
2
  import { ComputedRef } from "vue";
3
-
4
3
  //#region src/use-fallback-props/index.d.ts
5
4
  /**
6
5
  * 使用回滚属性,用于控制多级属性的使用优先级,如果多级属性中不存在该值,则使用全局配置中的属性,如再不存在则为undefined
7
6
  * @param propsList 属性列表,最右边的属性优先级最高
8
7
  * @param fallbackProps 要回滚的属性和默认值
9
8
  */
10
- declare function useFallbackProps<F extends Record<string, any>, R extends { [key in keyof F]: ComputedRef<F[key]> }>(propsList: Record<string, any>[], fallbackProps: F): R;
9
+ declare function useFallbackProps<F extends Record<string, any>, R extends { [key in keyof F]: ComputedRef<F[key]>; }>(propsList: Record<string, any>[], fallbackProps: F): R;
11
10
  type FormFallbackProps = {
12
11
  size: ComponentSize;
13
12
  disabled: boolean;
@@ -18,14 +17,14 @@ type FormFallbackProps = {
18
17
  * @param propsList props列表
19
18
  * @returns
20
19
  */
21
- declare function useFormFallbackProps(propsList: Record<string, any>[]): { [key in keyof FormFallbackProps]: ComputedRef<FormFallbackProps[key]> };
20
+ declare function useFormFallbackProps(propsList: Record<string, any>[]): { [key in keyof FormFallbackProps]: ComputedRef<FormFallbackProps[key]>; };
22
21
  /**
23
22
  * 表单组件的回滚属性
24
23
  * @param propsList props列表
25
24
  * @param fallbackProps 回滚属性,可以只指定部分表单属性
26
25
  * @returns
27
26
  */
28
- declare function useFormFallbackProps<F extends Partial<FormFallbackProps>>(propsList: Record<string, any>[], fallbackProps: F): { [key in keyof F]: key extends keyof FormFallbackProps ? ComputedRef<FormFallbackProps[key]> : never };
27
+ declare function useFormFallbackProps<F extends Partial<FormFallbackProps>>(propsList: Record<string, any>[], fallbackProps: F): { [key in keyof F]: key extends keyof FormFallbackProps ? ComputedRef<FormFallbackProps[key]> : never; };
29
28
  //#endregion
30
29
  export { useFallbackProps, useFormFallbackProps };
31
30
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,4 @@
1
1
  import { Ref } from "vue";
2
-
3
2
  //#region src/use-focus/index.d.ts
4
3
  /**
5
4
  * 聚焦
@@ -1,5 +1,4 @@
1
1
  import { Ref } from "vue";
2
-
3
2
  //#region src/use-model/index.d.ts
4
3
  interface ModelOptions<Props extends Record<string, unknown>, Name extends keyof Props> {
5
4
  /** 组件定义的属性 */
@@ -1,6 +1,5 @@
1
1
  import { ShallowRef } from "vue";
2
2
  import { ComputePositionReturn } from "@floating-ui/dom";
3
-
4
3
  //#region src/use-pop/index.d.ts
5
4
  type TipDirection = 'top' | 'bottom' | 'left' | 'right';
6
5
  type TipAlign = 'center' | 'start' | 'end';
@@ -1,5 +1,4 @@
1
1
  import { RefElement } from "../use-resize-observer/index.js";
2
-
3
2
  //#region src/use-reactive-size/index.d.ts
4
3
  interface ElementSize {
5
4
  width: number;
@@ -1,5 +1,4 @@
1
1
  import { Ref, ShallowRef } from "vue";
2
-
3
2
  //#region src/use-resize-observer/index.d.ts
4
3
  type RefElement = ShallowRef<HTMLElement | undefined | null> | Ref<HTMLElement | undefined | null>;
5
4
  interface ResizeObserverOptions {
@@ -12,7 +11,8 @@ interface ResizeObserverOptions {
12
11
  }
13
12
  /** 监听器 */
14
13
  type ResizeObserverReturn = {
15
- /** 终止监听 */disconnect: () => void;
14
+ /** 终止监听 */
15
+ disconnect: () => void;
16
16
  };
17
17
  /**
18
18
  * 监听目标尺寸变化
@@ -1,5 +1,4 @@
1
1
  import { CssTransitionOptions, Returned, StyleTransitionOptions } from "./type.js";
2
-
3
2
  //#region src/use-transition/index.d.ts
4
3
  /**
5
4
  * 使用CSS类过渡
@@ -1,5 +1,4 @@
1
1
  import { CSSProperties, Ref, ShallowRef } from "vue";
2
-
3
2
  //#region src/use-transition/type.d.ts
4
3
  interface TransitionBase {
5
4
  /** 被应用的目标元素 */
@@ -43,5 +42,5 @@ interface Returned {
43
42
  leave(): void;
44
43
  }
45
44
  //#endregion
46
- export { CssTransitionOptions, Returned, StyleTransitionOptions };
45
+ export { CssTransitionOptions, Returned, StyleTransitionOptions, TransitionBase };
47
46
  //# sourceMappingURL=type.d.ts.map
@@ -117,7 +117,8 @@ function useCssTransition(options) {
117
117
  });
118
118
  else if (target) addEvent(target);
119
119
  onBeforeUnmount(() => {
120
- removeEvent(getDom());
120
+ const dom = getDom();
121
+ removeEvent(dom);
121
122
  });
122
123
  return {
123
124
  toggle,
@@ -1 +1 @@
1
- {"version":3,"file":"use-css-transition.js","names":[],"sources":["../../src/use-transition/use-css-transition.ts"],"sourcesContent":["import { createToggle } from '@veltra/utils'\nimport { isRef, watch, onBeforeUnmount, computed } from 'vue'\n\nimport type { Returned, CssTransitionOptions } from './type'\n\nconst increaseTransitionCount = (el: HTMLElement & { _count?: number }) => {\n el._count = (el._count ?? 0) + 1\n}\n\nconst decreaseTransitionCount = (el: HTMLElement & { _count?: number }) => {\n el._count = (el._count ?? 0) - 1\n if (el._count <= 0) {\n delete el._count\n }\n}\n\n/**\n * 使用css过渡\n * @param options 过渡选项\n */\nexport function useCssTransition(options: CssTransitionOptions): Returned {\n const {\n name,\n target,\n afterEnter,\n afterLeave,\n enterCanceled,\n leaveCanceled,\n keepEnterTo = false\n } = options\n\n const getDom = (): (HTMLElement & { _count?: number }) | undefined =>\n isRef(target) ? target.value : target\n\n const classes = computed(() => {\n const _name = typeof name === 'string' ? name : name.value\n return {\n /** 进入前的类 */\n enterFrom: `${_name}-enter-from`,\n /** 进入后最终的类 */\n enterTo: `${_name}-enter-to`,\n /** 【进入动画】持续时的类 */\n enterActive: `${_name}-enter-active`,\n /** 离开前的类 */\n leaveFrom: `${_name}-leave-from`,\n /** 离开类 */\n leaveTo: `${_name}-leave-to`,\n /** 【离开动画】持续时的类 */\n leaveActive: `${_name}-leave-active`\n }\n })\n\n /** 开始进入动画 */\n const startTransitionIn = () => {\n const { enterActive, enterTo, enterFrom } = classes.value\n const dom = getDom()\n\n dom?.classList.add(enterFrom)\n\n requestAnimationFrame(() => {\n dom?.classList.add(enterActive)\n requestAnimationFrame(() => {\n dom?.classList.remove(enterFrom)\n dom?.classList.add(enterTo)\n })\n })\n }\n\n /** 开始离开动画 */\n const startTransitionOut = () => {\n const { leaveTo, leaveActive, leaveFrom, enterTo } = classes.value\n const dom = getDom()\n\n // 标记动画进入离开状态\n if (keepEnterTo) {\n dom?.classList.remove(enterTo)\n }\n dom?.classList.add(leaveFrom, leaveActive)\n\n requestAnimationFrame(() => {\n dom?.classList.add(leaveActive)\n requestAnimationFrame(() => {\n dom?.classList.remove(leaveFrom)\n dom?.classList.add(leaveTo)\n })\n })\n }\n\n const [active, toggle] = createToggle(false, (_active) => {\n _active ? startTransitionIn() : startTransitionOut()\n })\n\n const transitionEndHandler = (e: TransitionEvent) => {\n e.stopPropagation()\n\n const { leaveActive, enterActive, enterTo, leaveTo } = classes.value\n const dom = getDom()\n\n if (dom !== e.target) return\n\n decreaseTransitionCount(dom)\n\n if (dom._count) return\n\n // 激活状态,移除enter-active类\n if (active.value) {\n if (keepEnterTo) {\n dom?.classList.remove(enterActive)\n } else {\n dom?.classList.remove(enterActive, enterTo)\n }\n afterEnter?.()\n } else {\n dom?.classList.remove(leaveActive, leaveTo)\n afterLeave?.()\n }\n }\n\n const transitionRunHandler = (e: TransitionEvent) => {\n e.stopPropagation()\n const dom = getDom()\n if (dom !== e.target) return\n increaseTransitionCount(dom)\n }\n\n const transitionCancelHandler = (e: TransitionEvent) => {\n e.stopPropagation()\n const dom = getDom()\n\n if (dom !== e.target) return\n decreaseTransitionCount(dom)\n\n if (dom._count) return\n\n const { leaveActive, enterActive } = classes.value\n\n // 激活状态,移除enter-active类\n if (active.value) {\n dom?.classList.remove(enterActive)\n enterCanceled?.()\n } else {\n dom?.classList.remove(leaveActive)\n leaveCanceled?.()\n }\n }\n\n /** 添加事件 */\n const addEvent = (el?: HTMLElement) => {\n el?.addEventListener('transitioncancel', transitionCancelHandler)\n el?.addEventListener('transitionend', transitionEndHandler)\n el?.addEventListener('transitionrun', transitionRunHandler)\n }\n\n /** 移除事件 */\n const removeEvent = (el?: HTMLElement) => {\n el?.removeEventListener('transitioncancel', transitionCancelHandler)\n el?.removeEventListener('transitionend', transitionEndHandler)\n el?.removeEventListener('transitionrun', transitionRunHandler)\n }\n\n if (isRef(target)) {\n watch(target, (_target, oldTarget) => {\n if (oldTarget) {\n removeEvent(oldTarget)\n }\n _target && addEvent(_target)\n })\n } else if (target) {\n addEvent(target)\n }\n\n onBeforeUnmount(() => {\n const dom = getDom()\n removeEvent(dom)\n })\n\n return {\n toggle,\n enter() {\n toggle(true)\n },\n leave() {\n toggle(false)\n }\n }\n}\n"],"mappings":";;;AAKA,MAAM,2BAA2B,OAA0C;CACzE,GAAG,UAAU,GAAG,UAAU,KAAK;AACjC;AAEA,MAAM,2BAA2B,OAA0C;CACzE,GAAG,UAAU,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;CAGjB,sBAAsB;EAEpB,YADY,OACE,CAAC;CACjB,CAAC;CAED,OAAO;EACL;EACA,QAAQ;GACN,OAAO,IAAI;EACb;EACA,QAAQ;GACN,OAAO,KAAK;EACd;CACF;AACF"}
1
+ {"version":3,"file":"use-css-transition.js","names":[],"sources":["../../src/use-transition/use-css-transition.ts"],"sourcesContent":["import { createToggle } from '@veltra/utils'\nimport { isRef, watch, onBeforeUnmount, computed } from 'vue'\n\nimport type { Returned, CssTransitionOptions } from './type'\n\nconst increaseTransitionCount = (el: HTMLElement & { _count?: number }) => {\n el._count = (el._count ?? 0) + 1\n}\n\nconst decreaseTransitionCount = (el: HTMLElement & { _count?: number }) => {\n el._count = (el._count ?? 0) - 1\n if (el._count <= 0) {\n delete el._count\n }\n}\n\n/**\n * 使用css过渡\n * @param options 过渡选项\n */\nexport function useCssTransition(options: CssTransitionOptions): Returned {\n const {\n name,\n target,\n afterEnter,\n afterLeave,\n enterCanceled,\n leaveCanceled,\n keepEnterTo = false\n } = options\n\n const getDom = (): (HTMLElement & { _count?: number }) | undefined =>\n isRef(target) ? target.value : target\n\n const classes = computed(() => {\n const _name = typeof name === 'string' ? name : name.value\n return {\n /** 进入前的类 */\n enterFrom: `${_name}-enter-from`,\n /** 进入后最终的类 */\n enterTo: `${_name}-enter-to`,\n /** 【进入动画】持续时的类 */\n enterActive: `${_name}-enter-active`,\n /** 离开前的类 */\n leaveFrom: `${_name}-leave-from`,\n /** 离开类 */\n leaveTo: `${_name}-leave-to`,\n /** 【离开动画】持续时的类 */\n leaveActive: `${_name}-leave-active`\n }\n })\n\n /** 开始进入动画 */\n const startTransitionIn = () => {\n const { enterActive, enterTo, enterFrom } = classes.value\n const dom = getDom()\n\n dom?.classList.add(enterFrom)\n\n requestAnimationFrame(() => {\n dom?.classList.add(enterActive)\n requestAnimationFrame(() => {\n dom?.classList.remove(enterFrom)\n dom?.classList.add(enterTo)\n })\n })\n }\n\n /** 开始离开动画 */\n const startTransitionOut = () => {\n const { leaveTo, leaveActive, leaveFrom, enterTo } = classes.value\n const dom = getDom()\n\n // 标记动画进入离开状态\n if (keepEnterTo) {\n dom?.classList.remove(enterTo)\n }\n dom?.classList.add(leaveFrom, leaveActive)\n\n requestAnimationFrame(() => {\n dom?.classList.add(leaveActive)\n requestAnimationFrame(() => {\n dom?.classList.remove(leaveFrom)\n dom?.classList.add(leaveTo)\n })\n })\n }\n\n const [active, toggle] = createToggle(false, (_active) => {\n _active ? startTransitionIn() : startTransitionOut()\n })\n\n const transitionEndHandler = (e: TransitionEvent) => {\n e.stopPropagation()\n\n const { leaveActive, enterActive, enterTo, leaveTo } = classes.value\n const dom = getDom()\n\n if (dom !== e.target) return\n\n decreaseTransitionCount(dom)\n\n if (dom._count) return\n\n // 激活状态,移除enter-active类\n if (active.value) {\n if (keepEnterTo) {\n dom?.classList.remove(enterActive)\n } else {\n dom?.classList.remove(enterActive, enterTo)\n }\n afterEnter?.()\n } else {\n dom?.classList.remove(leaveActive, leaveTo)\n afterLeave?.()\n }\n }\n\n const transitionRunHandler = (e: TransitionEvent) => {\n e.stopPropagation()\n const dom = getDom()\n if (dom !== e.target) return\n increaseTransitionCount(dom)\n }\n\n const transitionCancelHandler = (e: TransitionEvent) => {\n e.stopPropagation()\n const dom = getDom()\n\n if (dom !== e.target) return\n decreaseTransitionCount(dom)\n\n if (dom._count) return\n\n const { leaveActive, enterActive } = classes.value\n\n // 激活状态,移除enter-active类\n if (active.value) {\n dom?.classList.remove(enterActive)\n enterCanceled?.()\n } else {\n dom?.classList.remove(leaveActive)\n leaveCanceled?.()\n }\n }\n\n /** 添加事件 */\n const addEvent = (el?: HTMLElement) => {\n el?.addEventListener('transitioncancel', transitionCancelHandler)\n el?.addEventListener('transitionend', transitionEndHandler)\n el?.addEventListener('transitionrun', transitionRunHandler)\n }\n\n /** 移除事件 */\n const removeEvent = (el?: HTMLElement) => {\n el?.removeEventListener('transitioncancel', transitionCancelHandler)\n el?.removeEventListener('transitionend', transitionEndHandler)\n el?.removeEventListener('transitionrun', transitionRunHandler)\n }\n\n if (isRef(target)) {\n watch(target, (_target, oldTarget) => {\n if (oldTarget) {\n removeEvent(oldTarget)\n }\n _target && addEvent(_target)\n })\n } else if (target) {\n addEvent(target)\n }\n\n onBeforeUnmount(() => {\n const dom = getDom()\n removeEvent(dom)\n })\n\n return {\n toggle,\n enter() {\n toggle(true)\n },\n leave() {\n toggle(false)\n }\n }\n}\n"],"mappings":";;;AAKA,MAAM,2BAA2B,OAA0C;CACzE,GAAG,UAAU,GAAG,UAAU,KAAK;AACjC;AAEA,MAAM,2BAA2B,OAA0C;CACzE,GAAG,UAAU,GAAG,UAAU,KAAK;CAC/B,IAAI,GAAG,UAAU,GACf,OAAO,GAAG;AAEd;;;;;AAMA,SAAgB,iBAAiB,SAAyC;CACxE,MAAM,EACJ,MACA,QACA,YACA,YACA,eACA,eACA,cAAc,UACZ;CAEJ,MAAM,eACJ,MAAM,MAAM,IAAI,OAAO,QAAQ;CAEjC,MAAM,UAAU,eAAe;EAC7B,MAAM,QAAQ,OAAO,SAAS,WAAW,OAAO,KAAK;EACrD,OAAO;;GAEL,WAAW,GAAG,MAAM;;GAEpB,SAAS,GAAG,MAAM;;GAElB,aAAa,GAAG,MAAM;;GAEtB,WAAW,GAAG,MAAM;;GAEpB,SAAS,GAAG,MAAM;;GAElB,aAAa,GAAG,MAAM;EACxB;CACF,CAAC;;CAGD,MAAM,0BAA0B;EAC9B,MAAM,EAAE,aAAa,SAAS,cAAc,QAAQ;EACpD,MAAM,MAAM,OAAO;EAEnB,KAAK,UAAU,IAAI,SAAS;EAE5B,4BAA4B;GAC1B,KAAK,UAAU,IAAI,WAAW;GAC9B,4BAA4B;IAC1B,KAAK,UAAU,OAAO,SAAS;IAC/B,KAAK,UAAU,IAAI,OAAO;GAC5B,CAAC;EACH,CAAC;CACH;;CAGA,MAAM,2BAA2B;EAC/B,MAAM,EAAE,SAAS,aAAa,WAAW,YAAY,QAAQ;EAC7D,MAAM,MAAM,OAAO;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AoB,uBAAuB;EAChE,IAAI,iBAAiB,iBAAiB,oBAAoB;EAC1D,IAAI,iBAAiB,iBAAiB,oBAAoB;CAC5D;;CAGA,MAAM,eAAe,OAAqB;EACxC,IAAI,oBAAoB,oBAAoB,uBAAuB;EACnE,IAAI,oBAAoB,iBAAiB,oBAAoB;EAC7D,IAAI,oBAAoB,iBAAiB,oBAAoB;CAC/D;CAEA,IAAI,MAAM,MAAM,GACd,MAAM,SAAS,SAAS,cAAc;EACpC,IAAI,WACF,YAAY,SAAS;EAEvB,WAAW,SAAS,OAAO;CAC7B,CAAC;MACI,IAAI,QACT,SAAS,MAAM;CAGjB,sBAAsB;EACpB,MAAM,MAAM,OAAO;EACnB,YAAY,GAAG;CACjB,CAAC;CAED,OAAO;EACL;EACA,QAAQ;GACN,OAAO,IAAI;EACb;EACA,QAAQ;GACN,OAAO,KAAK;EACd;CACF;AACF"}
@@ -1,6 +1,5 @@
1
1
  import { MaybeRefOrGetter, Ref, ShallowRef } from "vue";
2
2
  import { VirtualItem, VirtualSnapshot, Virtualizer, VirtualizerOptions } from "@cat-kit/fe";
3
-
4
3
  //#region src/use-virtualizer/index.d.ts
5
4
  type MaybeEl = HTMLElement | null | undefined;
6
5
  interface UseVirtualizerOptions extends Omit<VirtualizerOptions, 'count'> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/compositions",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -13,7 +13,8 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@floating-ui/dom": "^1.7.6"
16
+ "@floating-ui/dom": "^1.8.0",
17
+ "@formkit/drag-and-drop": "^0.6.1"
17
18
  },
18
19
  "devDependencies": {
19
20
  "@cat-kit/fe": "^1.1.8"
@@ -21,7 +22,7 @@
21
22
  "peerDependencies": {
22
23
  "@cat-kit/core": ">=1.1.8",
23
24
  "@cat-kit/fe": ">=1.1.8",
24
- "@veltra/utils": "1.3.2",
25
- "vue": ">=3.5.39"
25
+ "@veltra/utils": "1.3.4",
26
+ "vue": ">=3.5.40"
26
27
  }
27
28
  }
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ export * from './use-config'
4
4
 
5
5
  export * from './use-drag'
6
6
 
7
+ export * from './use-dnd'
8
+
7
9
  export * from './use-fallback-props'
8
10
 
9
11
  export * from './use-focus'
@@ -0,0 +1,131 @@
1
+ import { tearDown } from '@formkit/drag-and-drop'
2
+ import { dragAndDrop, type VueParentConfig } from '@formkit/drag-and-drop/vue'
3
+ import { isRef, onBeforeUnmount, ref, type Ref } from 'vue'
4
+
5
+ export interface UseDnDOptions<T> extends VueParentConfig<T> {
6
+ /**
7
+ * 列表数据。传入 ref 时与外部共享同一个引用,拖拽排序/转移后直接写回;
8
+ * 传入普通数组或不传时内部创建 ref。
9
+ */
10
+ values?: T[] | Ref<T[]>
11
+ }
12
+
13
+ export interface UseDnDResult<T> {
14
+ /** 拖拽容器元素,通过 `ref` 绑定到列表容器元素上 */
15
+ parentRef: Ref<HTMLElement | undefined>
16
+ /** 列表数据,排序/跨容器转移后自动更新 */
17
+ values: Ref<T[]>
18
+ /**
19
+ * 运行时更新拖拽配置(整体替换,不与初始配置合并)
20
+ * @param config 新配置
21
+ */
22
+ updateConfig: (config?: VueParentConfig<T>) => void
23
+ }
24
+
25
+ /**
26
+ * 拖拽排序组合式方法,基于 `@formkit/drag-and-drop` 的 Vue 适配层封装。
27
+ *
28
+ * 相比官方 `useDragAndDrop` 的元组返回,这里使用 options 对象传参并返回命名结果。
29
+ * 组件卸载时自动销毁拖拽实例。
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const { parentRef, values } = useDnD({
34
+ * values: list,
35
+ * plugins: [animations()],
36
+ * onSort: ({ previousValues, values }) => {}
37
+ * })
38
+ * ```
39
+ *
40
+ * ```vue
41
+ * <ul ref="parentRef">
42
+ * <li v-for="item in values" :key="item.id">{{ item.label }}</li>
43
+ * </ul>
44
+ * ```
45
+ */
46
+ export function useDnD<T>(options: UseDnDOptions<T> = {}): UseDnDResult<T> {
47
+ const { values: initialValues, ...config } = options
48
+
49
+ const parentRef = ref<HTMLElement>()
50
+ const values = isRef(initialValues) ? initialValues : (ref(initialValues ?? []) as Ref<T[]>)
51
+
52
+ function updateConfig(newConfig: VueParentConfig<T> = {}) {
53
+ dragAndDrop({ parent: parentRef, values, ...newConfig })
54
+ }
55
+
56
+ updateConfig(config)
57
+
58
+ onBeforeUnmount(() => {
59
+ parentRef.value && tearDown(parentRef.value)
60
+ })
61
+
62
+ return { parentRef, values, updateConfig }
63
+ }
64
+
65
+ // 重导出 `@formkit/drag-and-drop`,下游项目统一从 `@veltra/compositions` 获取,
66
+ // 避免本库与下游各自安装导致版本不一致(体积膨胀 / 兼容问题)。
67
+ export {
68
+ // Vue 适配层原始 API
69
+ dragAndDrop,
70
+ useDragAndDrop,
71
+ type VueDragAndDropData,
72
+ type VueElement,
73
+ type VueParentConfig
74
+ } from '@formkit/drag-and-drop/vue'
75
+
76
+ export {
77
+ // 插件
78
+ animations,
79
+ dropOrSwap,
80
+ insert,
81
+ // 操作与状态工具
82
+ performSort,
83
+ performTransfer,
84
+ remapNodes,
85
+ updateConfig,
86
+ parentValues,
87
+ setParentValues,
88
+ dragValues,
89
+ isDragState,
90
+ isSynthDragState,
91
+ isBrowser,
92
+ tearDown,
93
+ // 类型
94
+ type ParentConfig,
95
+ type ParentData,
96
+ type ParentRecord,
97
+ type Node,
98
+ type NodeData,
99
+ type NodeRecord,
100
+ type NodeTargetData,
101
+ type ParentTargetData,
102
+ type BaseDragState,
103
+ type DragState,
104
+ type SynthDragState,
105
+ type NativeDragEffects,
106
+ type DNDPlugin,
107
+ type DNDPluginData,
108
+ type NodeEventData,
109
+ type NodeDragEventData,
110
+ type NodePointerEventData,
111
+ type ParentEventData,
112
+ type ParentDragEventData,
113
+ type SortEvent,
114
+ type SortEventData,
115
+ type TransferEvent,
116
+ type TransferEventData,
117
+ type DragstartEvent,
118
+ type DragstartEventData,
119
+ type DragendEvent,
120
+ type DragendEventData,
121
+ type ShouldSwapData,
122
+ type DropSwapConfig,
123
+ type InsertConfig,
124
+ type InsertEvent,
125
+ type SetupNode,
126
+ type SetupNodeData,
127
+ type TearDownNode,
128
+ type TearDownNodeData,
129
+ type PointeroverNodeEvent,
130
+ type PointeroverParentEvent
131
+ } from '@formkit/drag-and-drop'