sard-uniapp 1.21.1 → 1.22.0
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/CHANGELOG.md +24 -0
- package/components/accordion/README.md +13 -6
- package/components/accordion/accordion.vue +10 -3
- package/components/accordion/common.d.ts +2 -0
- package/components/accordion/index.scss +6 -0
- package/components/accordion-item/accordion-item.vue +6 -1
- package/components/accordion-item/index.scss +12 -0
- package/components/calendar-input/README.md +9 -0
- package/components/calendar-input/calendar-input.d.ts +9 -2
- package/components/calendar-input/calendar-input.vue +13 -1
- package/components/calendar-input/common.d.ts +3 -1
- package/components/cascader-input/README.md +8 -1
- package/components/cascader-input/cascader-input.vue +13 -1
- package/components/cascader-input/common.d.ts +2 -2
- package/components/checkbox-input/README.md +9 -0
- package/components/checkbox-input/checkbox-input.d.ts +9 -2
- package/components/checkbox-input/checkbox-input.vue +13 -1
- package/components/checkbox-input/common.d.ts +3 -1
- package/components/config/index.d.ts +5 -0
- package/components/config/index.js +5 -0
- package/components/datetime-picker-input/README.md +9 -0
- package/components/datetime-picker-input/common.d.ts +2 -2
- package/components/datetime-picker-input/datetime-picker-input.vue +13 -1
- package/components/datetime-range-picker-input/README.md +9 -0
- package/components/datetime-range-picker-input/common.d.ts +2 -2
- package/components/datetime-range-picker-input/datetime-range-picker-input.vue +13 -1
- package/components/dnd/README.md +120 -0
- package/components/dnd/common.d.ts +49 -0
- package/components/dnd/common.js +1 -0
- package/components/dnd/dnd.d.ts +37 -0
- package/components/dnd/dnd.vue +136 -0
- package/components/dnd/index.d.ts +1 -0
- package/components/dnd/index.js +1 -0
- package/components/dnd/index.scss +11 -0
- package/components/dnd/variables.scss +7 -0
- package/components/dnd-handle/common.d.ts +12 -0
- package/components/dnd-handle/common.js +1 -0
- package/components/dnd-handle/dnd-handle.d.ts +10 -0
- package/components/dnd-handle/dnd-handle.vue +89 -0
- package/components/dnd-handle/index.d.ts +1 -0
- package/components/dnd-handle/index.js +1 -0
- package/components/dnd-handle/index.scss +13 -0
- package/components/dnd-item/common.d.ts +21 -0
- package/components/dnd-item/common.js +1 -0
- package/components/dnd-item/dnd-item.d.ts +10 -0
- package/components/dnd-item/dnd-item.vue +193 -0
- package/components/dnd-item/index.d.ts +1 -0
- package/components/dnd-item/index.js +1 -0
- package/components/dnd-item/index.scss +28 -0
- package/components/floating-bubble/index.scss +1 -0
- package/components/form/README.md +6 -5
- package/components/form/common.d.ts +4 -0
- package/components/form-item/form-item.vue +10 -4
- package/components/icon/sari.scss +9 -1
- package/components/input/README.md +47 -46
- package/components/input/common.d.ts +1 -0
- package/components/input/index.scss +15 -0
- package/components/input/input.vue +61 -4
- package/components/input/variables.scss +6 -0
- package/components/picker-input/README.md +9 -0
- package/components/picker-input/common.d.ts +2 -2
- package/components/picker-input/picker-input.vue +15 -1
- package/components/popout-input/README.md +20 -11
- package/components/popout-input/common.d.ts +10 -0
- package/components/popout-input/common.js +2 -1
- package/components/popout-input/index.scss +1 -0
- package/components/popout-input/popout-input.d.ts +5 -1
- package/components/popout-input/popout-input.vue +22 -7
- package/components/popup/README.md +24 -22
- package/components/popup/common.d.ts +3 -0
- package/components/popup/popup.d.ts +8 -5
- package/components/popup/popup.vue +25 -2
- package/components/radio-input/README.md +9 -0
- package/components/radio-input/common.d.ts +3 -1
- package/components/radio-input/radio-input.d.ts +9 -2
- package/components/radio-input/radio-input.vue +13 -1
- package/components/share-sheet/share-sheet.vue +1 -1
- package/components/stepper/common.d.ts +1 -1
- package/components/stepper/stepper.vue +1 -1
- package/components/style/mixins/disable-scroll.scss +14 -0
- package/components/style/mixins.scss +1 -0
- package/components/style/variables.scss +4 -0
- package/components/tree/common.d.ts +1 -0
- package/components/tree/index.scss +4 -0
- package/components/tree/tree.vue +33 -21
- package/components/tree/variables.scss +1 -2
- package/components/tree-node/tree-node.vue +2 -0
- package/global.d.ts +3 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/index.scss +1 -0
- package/package.json +2 -2
- package/use/index.d.ts +1 -0
- package/use/index.js +1 -0
- package/use/useKeyList.d.ts +5 -0
- package/use/useKeyList.js +15 -0
- package/utils/array.js +6 -6
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav: 组件
|
|
3
|
+
title: Dnd
|
|
4
|
+
subtitle: 拖放
|
|
5
|
+
group: 反馈组件
|
|
6
|
+
version: 1.22+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 介绍
|
|
10
|
+
|
|
11
|
+
`Dnd (Drag and Drop)` 拖放组件用于列表的拖放排序。
|
|
12
|
+
|
|
13
|
+
`Dnd` 组件用于提供上下文;`DndItem` 组件用于展示拖放样式以及作为列表项容器;`DndHandle` 需放置在 `DndItem` 中,控制着拖拽区域,短按可进入拖拽状态,样式和内容可自定义。
|
|
14
|
+
|
|
15
|
+
@warning
|
|
16
|
+
|
|
17
|
+
暂不支持支付宝。
|
|
18
|
+
|
|
19
|
+
@endwarning
|
|
20
|
+
|
|
21
|
+
## 引入
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import Dnd from 'sard-uniapp/components/dnd/dnd.vue'
|
|
25
|
+
import DndItem from 'sard-uniapp/components/dnd-item/dnd-item.vue'
|
|
26
|
+
import DndHandle from 'sard-uniapp/components/dnd-handle/dnd-handle.vue'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 代码演示
|
|
30
|
+
|
|
31
|
+
### 基础使用
|
|
32
|
+
|
|
33
|
+
通过 `v-model:list` 双向绑定列表,可在拖放时修改绑定数组的元素顺序;使用默认插槽的 `list` 参数渲染列表,需绑定 `itemInfo` 和 `key` 到 `DndItem` 组件;`key` 和数组元素的引用一一对应,无需自行处理循环组件时的唯一性问题;`data` 是原始数组的元素项。
|
|
34
|
+
|
|
35
|
+
下面演示了拖拽组件和列表组件的组合使用。因每个列表项被拖拽项包围分割,没了边框,因此需使用 `Divider` 组件添加边框。
|
|
36
|
+
|
|
37
|
+
@code('${DEMO_PATH}/dnd/demo/Basic.vue')
|
|
38
|
+
|
|
39
|
+
### 表单列表
|
|
40
|
+
|
|
41
|
+
下面演示了拖放组件组合表单组件实现的表单列表增删改以及拖放排序的效果。
|
|
42
|
+
|
|
43
|
+
@code('${DEMO_PATH}/dnd/demo/FormList.vue')
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### DndProps\<T>
|
|
48
|
+
|
|
49
|
+
| 属性 | 描述 | 类型 | 默认值 |
|
|
50
|
+
| ---------- | -------------- | ---------- | ------ |
|
|
51
|
+
| root-class | 组件根元素类名 | string | - |
|
|
52
|
+
| root-style | 组件根元素样式 | StyleValue | - |
|
|
53
|
+
| list | 组件根元素样式 | T[] | - |
|
|
54
|
+
|
|
55
|
+
### DndSlots\<T>
|
|
56
|
+
|
|
57
|
+
| 插槽 | 描述 | 属性 |
|
|
58
|
+
| ------- | -------------- | -------------------------- |
|
|
59
|
+
| default | 自定义默认内容 | {list: DndListItem\<T>[] } |
|
|
60
|
+
|
|
61
|
+
### DndEmits\<T>
|
|
62
|
+
|
|
63
|
+
| 事件 | 描述 | 类型 |
|
|
64
|
+
| --------------- | ---------------------------- | ----------------------------------------------------------- |
|
|
65
|
+
| item-drag-start | 拖拽开始时触发 | (event: { itemIndex: number }) => void |
|
|
66
|
+
| item-drag-move | 拖拽项在拖拽范围内移动时触发 | (event: { itemIndex: number; insertIndex: number }) => void |
|
|
67
|
+
| item-drop | 拖拽被释放时触发 | (event: { itemIndex: number; insertIndex: number }) => void |
|
|
68
|
+
| update:list | 拖拽被释放时触发 | (list: T[]) => void |
|
|
69
|
+
|
|
70
|
+
### DndItemProps
|
|
71
|
+
|
|
72
|
+
| 属性 | 描述 | 类型 | 默认值 |
|
|
73
|
+
| ---------- | -------------- | ----------- | ------ |
|
|
74
|
+
| root-class | 组件根元素类名 | string | - |
|
|
75
|
+
| root-style | 组件根元素样式 | StyleValue | - |
|
|
76
|
+
| item-info | 组件根元素样式 | DndItemInfo | - |
|
|
77
|
+
|
|
78
|
+
### DndItemSlots
|
|
79
|
+
|
|
80
|
+
| 插槽 | 描述 | 属性 |
|
|
81
|
+
| ------- | -------------- | ---- |
|
|
82
|
+
| default | 自定义默认内容 | - |
|
|
83
|
+
|
|
84
|
+
### DndHandleProps
|
|
85
|
+
|
|
86
|
+
| 属性 | 描述 | 类型 | 默认值 |
|
|
87
|
+
| ---------- | -------------- | ---------- | ------ |
|
|
88
|
+
| root-class | 组件根元素类名 | string | - |
|
|
89
|
+
| root-style | 组件根元素样式 | StyleValue | - |
|
|
90
|
+
|
|
91
|
+
### DndHandleSlots
|
|
92
|
+
|
|
93
|
+
| 插槽 | 描述 | 属性 |
|
|
94
|
+
| ------- | -------------- | ---- |
|
|
95
|
+
| default | 自定义默认内容 | - |
|
|
96
|
+
|
|
97
|
+
### DndListItem\<T>
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
export interface DndListItem<T> {
|
|
101
|
+
data: UnwrapRef<T>
|
|
102
|
+
itemInfo: DndItemInfo
|
|
103
|
+
key: string
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### DndItemInfo
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
export interface DndItemInfo {
|
|
111
|
+
offset: number
|
|
112
|
+
dragging: boolean
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 主题定制
|
|
117
|
+
|
|
118
|
+
### CSS 变量
|
|
119
|
+
|
|
120
|
+
@code('./variables.scss#variables')
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type NodeRect } from '../../utils';
|
|
2
|
+
import { type UnwrapRef, type InjectionKey, type StyleValue } from 'vue';
|
|
3
|
+
export interface DndProps<T> {
|
|
4
|
+
rootStyle?: StyleValue;
|
|
5
|
+
rootClass?: string;
|
|
6
|
+
list?: T[];
|
|
7
|
+
}
|
|
8
|
+
export interface DndSlots<T> {
|
|
9
|
+
default?(props: {
|
|
10
|
+
list: DndListItem<T>[];
|
|
11
|
+
}): any;
|
|
12
|
+
}
|
|
13
|
+
export interface DndEmits<T> {
|
|
14
|
+
'item-drag-start': [event: {
|
|
15
|
+
itemIndex: number;
|
|
16
|
+
}];
|
|
17
|
+
'item-drag-move': [event: {
|
|
18
|
+
itemIndex: number;
|
|
19
|
+
insertIndex: number;
|
|
20
|
+
}];
|
|
21
|
+
'item-drop': [event: {
|
|
22
|
+
itemIndex: number;
|
|
23
|
+
insertIndex: number;
|
|
24
|
+
}];
|
|
25
|
+
'update:list': [list: T[]];
|
|
26
|
+
}
|
|
27
|
+
export interface DndExpose {
|
|
28
|
+
}
|
|
29
|
+
export interface DndListItem<T> {
|
|
30
|
+
data: UnwrapRef<T>;
|
|
31
|
+
itemInfo: DndItemInfo;
|
|
32
|
+
key: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DndItemInfo {
|
|
35
|
+
offset: number;
|
|
36
|
+
dragging: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface DndContext<T> {
|
|
39
|
+
list: DndListItem<T>[];
|
|
40
|
+
dragging: boolean;
|
|
41
|
+
currentHeight: number;
|
|
42
|
+
dragStart: (itemIndex: number) => void;
|
|
43
|
+
dragMove: (itemIndex: number, insertIndex: number) => void;
|
|
44
|
+
drop: (itemIndex: number, insertIndex: number) => void;
|
|
45
|
+
rectItems: (() => Promise<NodeRect>)[];
|
|
46
|
+
addRectItem: (getRect: () => Promise<NodeRect>) => void;
|
|
47
|
+
removeRectItem: (getRect: () => Promise<NodeRect>) => void;
|
|
48
|
+
}
|
|
49
|
+
export declare const dndContextKey: InjectionKey<DndContext<any>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const dndContextKey = Symbol('dnd-context');
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DndProps, type DndSlots, type DndExpose } from './common';
|
|
2
|
+
declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_Prettify<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
|
+
props: __VLS_Prettify<Pick<Partial<{}> & Omit<{
|
|
4
|
+
readonly "onItem-drag-start"?: ((event: {
|
|
5
|
+
itemIndex: number;
|
|
6
|
+
}) => any) | undefined;
|
|
7
|
+
readonly "onItem-drag-move"?: ((event: {
|
|
8
|
+
itemIndex: number;
|
|
9
|
+
insertIndex: number;
|
|
10
|
+
}) => any) | undefined;
|
|
11
|
+
readonly "onItem-drop"?: ((event: {
|
|
12
|
+
itemIndex: number;
|
|
13
|
+
insertIndex: number;
|
|
14
|
+
}) => any) | undefined;
|
|
15
|
+
readonly "onUpdate:list"?: ((list: T[]) => any) | undefined;
|
|
16
|
+
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onItem-drag-start" | "onItem-drag-move" | "onItem-drop" | "onUpdate:list"> & DndProps<T>> & import("vue").PublicProps;
|
|
17
|
+
expose(exposed: import("vue").ShallowUnwrapRef<DndExpose>): void;
|
|
18
|
+
attrs: any;
|
|
19
|
+
slots: ReturnType<() => Readonly<DndSlots<T>> & DndSlots<T>>;
|
|
20
|
+
emit: (((evt: "item-drag-start", event: {
|
|
21
|
+
itemIndex: number;
|
|
22
|
+
}) => void) & ((evt: "item-drag-move", event: {
|
|
23
|
+
itemIndex: number;
|
|
24
|
+
insertIndex: number;
|
|
25
|
+
}) => void) & ((evt: "item-drop", event: {
|
|
26
|
+
itemIndex: number;
|
|
27
|
+
insertIndex: number;
|
|
28
|
+
}) => void) & ((evt: "update:list", list: T[]) => void)) & {};
|
|
29
|
+
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}> & {
|
|
32
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
33
|
+
};
|
|
34
|
+
export default _default;
|
|
35
|
+
type __VLS_Prettify<T> = {
|
|
36
|
+
[K in keyof T]: T[K];
|
|
37
|
+
} & {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="dndClass" :style="dndStyle">
|
|
3
|
+
<slot :list="dndList"></slot>
|
|
4
|
+
|
|
5
|
+
<!-- #ifdef MP-ALIPAY -->
|
|
6
|
+
<view
|
|
7
|
+
:class="
|
|
8
|
+
classNames(
|
|
9
|
+
bem.e('disable-scroll'),
|
|
10
|
+
bem.em('disable-scroll', 'dragging', dragging),
|
|
11
|
+
)
|
|
12
|
+
"
|
|
13
|
+
></view>
|
|
14
|
+
<!-- #endif -->
|
|
15
|
+
</view>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
import { defineComponent as _defineComponent } from "vue";
|
|
20
|
+
import { computed, provide, reactive, ref, unref, watch } from "vue";
|
|
21
|
+
import {
|
|
22
|
+
classNames,
|
|
23
|
+
stringifyStyle,
|
|
24
|
+
createBem,
|
|
25
|
+
uniqid,
|
|
26
|
+
arrayMove
|
|
27
|
+
} from "../../utils";
|
|
28
|
+
import {
|
|
29
|
+
dndContextKey
|
|
30
|
+
} from "./common";
|
|
31
|
+
/**
|
|
32
|
+
* @property {string} rootClass 组件根元素类名,默认值:-。
|
|
33
|
+
* @property {StyleValue} rootStyle 组件根元素样式,默认值:-。
|
|
34
|
+
* @property {T[]} list 组件根元素样式,默认值:-。
|
|
35
|
+
* @event {(event: { itemIndex: number }) => void} item-drag-start 拖拽开始时触发
|
|
36
|
+
* @event {(event: { itemIndex: number; insertIndex: number }) => void} item-drag-move 拖拽项在拖拽范围内移动时触发
|
|
37
|
+
* @event {(event: { itemIndex: number; insertIndex: number }) => void} item-drop 拖拽被释放时触发
|
|
38
|
+
* @event {(list: T[]) => void} update 拖拽被释放时触发
|
|
39
|
+
*/
|
|
40
|
+
export default _defineComponent({
|
|
41
|
+
...{
|
|
42
|
+
options: {
|
|
43
|
+
virtualHost: true,
|
|
44
|
+
styleIsolation: "shared"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
__name: "dnd",
|
|
48
|
+
props: {
|
|
49
|
+
rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
|
|
50
|
+
rootClass: { type: String, required: false },
|
|
51
|
+
list: { type: Array, required: false }
|
|
52
|
+
},
|
|
53
|
+
emits: ["item-drag-start", "item-drag-move", "item-drop", "update:list"],
|
|
54
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
55
|
+
const props = __props;
|
|
56
|
+
const emit = __emit;
|
|
57
|
+
const bem = createBem("dnd");
|
|
58
|
+
const keyMap = new WeakMap();
|
|
59
|
+
const innerList = ref(props.list || []);
|
|
60
|
+
watch(
|
|
61
|
+
() => props.list,
|
|
62
|
+
() => {
|
|
63
|
+
innerList.value = props.list || [];
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
const dndList = computed(() => {
|
|
67
|
+
return unref(innerList.value).map((item) => {
|
|
68
|
+
const key = keyMap.get(item) || uniqid();
|
|
69
|
+
keyMap.set(item, key);
|
|
70
|
+
return reactive({
|
|
71
|
+
data: item,
|
|
72
|
+
itemInfo: reactive({
|
|
73
|
+
offset: 0,
|
|
74
|
+
dragging: false
|
|
75
|
+
}),
|
|
76
|
+
key
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const dragStart = (itemIndex) => {
|
|
81
|
+
emit("item-drag-start", { itemIndex });
|
|
82
|
+
};
|
|
83
|
+
const dragMove = (itemIndex, insertIndex) => {
|
|
84
|
+
emit("item-drag-move", { itemIndex, insertIndex });
|
|
85
|
+
};
|
|
86
|
+
const drop = (itemIndex, insertIndex) => {
|
|
87
|
+
if (itemIndex !== insertIndex) {
|
|
88
|
+
innerList.value = arrayMove(props.list || [], itemIndex, insertIndex);
|
|
89
|
+
emit("update:list", innerList.value);
|
|
90
|
+
}
|
|
91
|
+
emit("item-drop", { itemIndex, insertIndex });
|
|
92
|
+
};
|
|
93
|
+
const dragging = ref(false);
|
|
94
|
+
const rectItems = [];
|
|
95
|
+
const addRectItem = (getRect) => {
|
|
96
|
+
if (!rectItems.includes(getRect)) {
|
|
97
|
+
rectItems.push(getRect);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const removeRectItem = (getRect) => {
|
|
101
|
+
if (rectItems.includes(getRect)) {
|
|
102
|
+
rectItems.splice(rectItems.indexOf(getRect), 1);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
provide(
|
|
106
|
+
dndContextKey,
|
|
107
|
+
reactive({
|
|
108
|
+
list: dndList,
|
|
109
|
+
dragging,
|
|
110
|
+
currentHeight: 0,
|
|
111
|
+
dragStart,
|
|
112
|
+
dragMove,
|
|
113
|
+
drop,
|
|
114
|
+
rectItems,
|
|
115
|
+
addRectItem,
|
|
116
|
+
removeRectItem
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
__expose({});
|
|
120
|
+
const dndClass = computed(() => {
|
|
121
|
+
return classNames(bem.b(), props.rootClass);
|
|
122
|
+
});
|
|
123
|
+
const dndStyle = computed(() => {
|
|
124
|
+
return stringifyStyle(props.rootStyle);
|
|
125
|
+
});
|
|
126
|
+
const __returned__ = { props, emit, bem, keyMap, innerList, dndList, dragStart, dragMove, drop, dragging, rectItems, addRectItem, removeRectItem, dndClass, dndStyle, get classNames() {
|
|
127
|
+
return classNames;
|
|
128
|
+
} };
|
|
129
|
+
return __returned__;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
</script>
|
|
133
|
+
|
|
134
|
+
<style lang="scss">
|
|
135
|
+
@import './index.scss';
|
|
136
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { DndProps, DndSlots, DndEmits, DndExpose } from './common';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type StyleValue } from 'vue';
|
|
2
|
+
export interface DndHandleProps {
|
|
3
|
+
rootStyle?: StyleValue;
|
|
4
|
+
rootClass?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DndHandleSlots {
|
|
7
|
+
default?(props: Record<string, never>): any;
|
|
8
|
+
}
|
|
9
|
+
export interface DndHandleEmits {
|
|
10
|
+
}
|
|
11
|
+
export interface DndHandleExpose {
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DndHandleProps, type DndHandleSlots } from './common';
|
|
2
|
+
declare function __VLS_template(): Readonly<DndHandleSlots> & DndHandleSlots;
|
|
3
|
+
declare const __VLS_component: import("vue").DefineComponent<DndHandleProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<DndHandleProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
4
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
|
|
5
|
+
export default _default;
|
|
6
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
7
|
+
new (): {
|
|
8
|
+
$slots: S;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="dndHandleClass"
|
|
4
|
+
:style="dndHandleStyle"
|
|
5
|
+
@touchstart.stop.prevent="onDragTouchStart"
|
|
6
|
+
@touchmove.stop.prevent="onDragTouchMove"
|
|
7
|
+
@touchend="onDragTouchEnd"
|
|
8
|
+
@touchcancel="onDragTouchEnd"
|
|
9
|
+
@mousedown.stop="onDragMouseDown"
|
|
10
|
+
>
|
|
11
|
+
<slot></slot>
|
|
12
|
+
</view>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script>
|
|
16
|
+
import { defineComponent as _defineComponent } from "vue";
|
|
17
|
+
import { computed, inject, ref } from "vue";
|
|
18
|
+
import { classNames, stringifyStyle, createBem } from "../../utils";
|
|
19
|
+
import { useMouseDown, useSimulatedPress } from "../../use";
|
|
20
|
+
import { dndItemContextKey } from "../dnd-item/common";
|
|
21
|
+
export default _defineComponent({
|
|
22
|
+
...{
|
|
23
|
+
options: {
|
|
24
|
+
virtualHost: true,
|
|
25
|
+
styleIsolation: "shared"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
__name: "dnd-handle",
|
|
29
|
+
props: {
|
|
30
|
+
rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
|
|
31
|
+
rootClass: { type: String, required: false }
|
|
32
|
+
},
|
|
33
|
+
setup(__props, { expose: __expose }) {
|
|
34
|
+
const props = __props;
|
|
35
|
+
const bem = createBem("dnd-handle");
|
|
36
|
+
const itemContext = inject(dndItemContextKey);
|
|
37
|
+
if (!itemContext) {
|
|
38
|
+
throw new Error("DndHandle must be included in DndItem.");
|
|
39
|
+
}
|
|
40
|
+
const dragging = ref(false);
|
|
41
|
+
const onDragTouchStart = (event) => {
|
|
42
|
+
itemContext.immediateStart();
|
|
43
|
+
onDragSimulatedPressTouchStart(event);
|
|
44
|
+
};
|
|
45
|
+
const onDragTouchMove = (event) => {
|
|
46
|
+
onDragSimulatedPressTouchMove(event);
|
|
47
|
+
};
|
|
48
|
+
const onDragTouchEnd = () => {
|
|
49
|
+
dragging.value = false;
|
|
50
|
+
onDragSimulatedPressTouchEnd();
|
|
51
|
+
};
|
|
52
|
+
const [
|
|
53
|
+
onDragSimulatedPressTouchStart,
|
|
54
|
+
onDragSimulatedPressTouchMove,
|
|
55
|
+
onDragSimulatedPressTouchEnd
|
|
56
|
+
] = useSimulatedPress({
|
|
57
|
+
start: () => {
|
|
58
|
+
dragging.value = true;
|
|
59
|
+
itemContext.start();
|
|
60
|
+
},
|
|
61
|
+
move: (_, { delta }) => {
|
|
62
|
+
itemContext.move(delta.y);
|
|
63
|
+
},
|
|
64
|
+
end: () => {
|
|
65
|
+
itemContext.end();
|
|
66
|
+
},
|
|
67
|
+
duration: 150
|
|
68
|
+
});
|
|
69
|
+
const onDragMouseDown = useMouseDown(
|
|
70
|
+
onDragTouchStart,
|
|
71
|
+
onDragTouchMove,
|
|
72
|
+
onDragTouchEnd
|
|
73
|
+
);
|
|
74
|
+
__expose({});
|
|
75
|
+
const dndHandleClass = computed(() => {
|
|
76
|
+
return classNames(bem.b(), bem.m("dragging", dragging), props.rootClass);
|
|
77
|
+
});
|
|
78
|
+
const dndHandleStyle = computed(() => {
|
|
79
|
+
return stringifyStyle(props.rootStyle);
|
|
80
|
+
});
|
|
81
|
+
const __returned__ = { props, bem, itemContext, dragging, onDragTouchStart, onDragTouchMove, onDragTouchEnd, onDragSimulatedPressTouchStart, onDragSimulatedPressTouchMove, onDragSimulatedPressTouchEnd, onDragMouseDown, dndHandleClass, dndHandleStyle };
|
|
82
|
+
return __returned__;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<style lang="scss">
|
|
88
|
+
@import './index.scss';
|
|
89
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { DndHandleProps, DndHandleSlots, DndHandleEmits, DndHandleExpose, } from './common';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InjectionKey, type StyleValue } from 'vue';
|
|
2
|
+
import { DndItemInfo } from '../dnd/common';
|
|
3
|
+
export interface DndItemProps {
|
|
4
|
+
rootStyle?: StyleValue;
|
|
5
|
+
rootClass?: string;
|
|
6
|
+
itemInfo: DndItemInfo;
|
|
7
|
+
}
|
|
8
|
+
export interface DndItemSlots {
|
|
9
|
+
default?(props: Record<string, never>): any;
|
|
10
|
+
}
|
|
11
|
+
export interface DndItemEmits {
|
|
12
|
+
}
|
|
13
|
+
export interface DndItemExpose {
|
|
14
|
+
}
|
|
15
|
+
export interface DndItemContext {
|
|
16
|
+
immediateStart: () => void;
|
|
17
|
+
start: () => void;
|
|
18
|
+
move: (delta: number) => void;
|
|
19
|
+
end: () => void;
|
|
20
|
+
}
|
|
21
|
+
export declare const dndItemContextKey: InjectionKey<DndItemContext>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const dndItemContextKey = Symbol('dnd-item-context');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DndItemProps, type DndItemSlots } from './common';
|
|
2
|
+
declare function __VLS_template(): Readonly<DndItemSlots> & DndItemSlots;
|
|
3
|
+
declare const __VLS_component: import("vue").DefineComponent<DndItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<DndItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
4
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
|
|
5
|
+
export default _default;
|
|
6
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
7
|
+
new (): {
|
|
8
|
+
$slots: S;
|
|
9
|
+
};
|
|
10
|
+
};
|