@veltra/compositions 1.3.3 → 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 };
@@ -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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/compositions",
3
- "version": "1.3.3",
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.8.0"
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.3",
25
+ "@veltra/utils": "1.3.4",
25
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'