pixuireactcomponents 1.5.15 → 1.5.17
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/components/react/app/dragList/dragList.d.ts +57 -0
- package/src/components/react/app/dragList/dragList.js +204 -0
- package/src/components/react/app/listDrag/listDrag.d.ts +0 -27
- package/src/components/react/app/listDrag/listDrag.js +0 -150
package/index.d.ts
CHANGED
|
@@ -18,6 +18,6 @@ export { tools } from "./src/components/tools/tools";
|
|
|
18
18
|
export { PreloadImg } from "./src/components/react/app/preloadImg/PreloadImg";
|
|
19
19
|
export { LoadChecker } from "./src/components/tools/LoadChecker";
|
|
20
20
|
export { AntiRepeat } from "./src/components/tools/antiRepeat";
|
|
21
|
-
export { DragList } from "./src/components/react/app/
|
|
21
|
+
export { DragList } from "./src/components/react/app/dragList/dragList";
|
|
22
22
|
export { Slider, SliderProps } from "./src/components/react/app/slider/Slider";
|
|
23
23
|
export { ImgPreLoader_base64, PreLoadPic_base64 } from "./src/components/tools/ImgPreLoader";
|
package/index.js
CHANGED
|
@@ -23,4 +23,4 @@ export { tools } from './src/components/tools/tools';
|
|
|
23
23
|
export { PreloadImg } from './src/components/react/app/preloadImg/PreloadImg';
|
|
24
24
|
export { LoadChecker } from './src/components/tools/LoadChecker';
|
|
25
25
|
export { AntiRepeat } from './src/components/tools/antiRepeat';
|
|
26
|
-
export { DragList } from './src/components/react/app/
|
|
26
|
+
export { DragList } from './src/components/react/app/dragList/dragList';
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { h, Component, JSX } from 'preact';
|
|
2
|
+
interface DragListProps {
|
|
3
|
+
/** 在渲染时回调, 返回需要绘制的内容 */
|
|
4
|
+
renderItemFunc: (index: number) => JSX.Element;
|
|
5
|
+
/** item宽度 */
|
|
6
|
+
itemWidth: number;
|
|
7
|
+
/** item高度 */
|
|
8
|
+
itemHeight: number;
|
|
9
|
+
/** item数量 */
|
|
10
|
+
itemSize: number;
|
|
11
|
+
/** 可视区域宽度 */
|
|
12
|
+
width: any;
|
|
13
|
+
/** 可视区域高度 */
|
|
14
|
+
height: any;
|
|
15
|
+
/** 拖动时虚块的样式 */
|
|
16
|
+
hoverItemStyle?: {};
|
|
17
|
+
/** 被拖动item样式 */
|
|
18
|
+
dragItemStyle?: {};
|
|
19
|
+
/** item样式 */
|
|
20
|
+
itemStyle?: {};
|
|
21
|
+
/** ms, 动画速度, 0为没有动画, 默认150 */
|
|
22
|
+
animationTime?: number;
|
|
23
|
+
}
|
|
24
|
+
interface DragListState {
|
|
25
|
+
itemIndex: number[];
|
|
26
|
+
draggingIndex: number | null;
|
|
27
|
+
dragOffsetX: number;
|
|
28
|
+
dragOffsetY: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
itemHeight: number;
|
|
32
|
+
itemWidth: number;
|
|
33
|
+
itemSize: number;
|
|
34
|
+
}
|
|
35
|
+
export declare class DragList extends Component<DragListProps, DragListState> {
|
|
36
|
+
itemCache: Array<{
|
|
37
|
+
vNode: h.JSX.Element;
|
|
38
|
+
isValid: any;
|
|
39
|
+
ref: any;
|
|
40
|
+
}>;
|
|
41
|
+
ref: any;
|
|
42
|
+
listSize: number;
|
|
43
|
+
animated: any;
|
|
44
|
+
/** 每行可以放置元素 */
|
|
45
|
+
protected visibleCount: number;
|
|
46
|
+
private dragIndex;
|
|
47
|
+
private dragEndIndex;
|
|
48
|
+
private containerRect;
|
|
49
|
+
constructor(props: DragListProps);
|
|
50
|
+
componentDidMount(): void;
|
|
51
|
+
moveItem(oldIndex: number, newIndex: number): void;
|
|
52
|
+
handleDragStart: (index: number, e: MouseEvent) => void;
|
|
53
|
+
handleDrag: (index: number, e: MouseEvent) => void;
|
|
54
|
+
handleDragEnd: (index: number, e: MouseEvent) => void;
|
|
55
|
+
render(): h.JSX.Element;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
import { h, Component, createRef } from 'preact';
|
|
28
|
+
var DragItem = /** @class */ (function (_super) {
|
|
29
|
+
__extends(DragItem, _super);
|
|
30
|
+
function DragItem(props) {
|
|
31
|
+
var _this = _super.call(this, props) || this;
|
|
32
|
+
_this.updateIndex = function (index) {
|
|
33
|
+
var newCol = index % _this.props.visibleCount;
|
|
34
|
+
var newRow = Math.floor(index / _this.props.visibleCount);
|
|
35
|
+
_this.setState({ index: index, col: newCol, row: newRow });
|
|
36
|
+
if (_this.props.animationTime != 0) {
|
|
37
|
+
if (_this.animation) {
|
|
38
|
+
clearTimeout(_this.animation);
|
|
39
|
+
}
|
|
40
|
+
_this.animation = setTimeout(function () {
|
|
41
|
+
_this.animation = null;
|
|
42
|
+
}, _this.props.animationTime);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
_this.handleDragStart = function (e) {
|
|
46
|
+
_this.setState({ isDragging: true });
|
|
47
|
+
_this.props.onDragStart(_this.state.index, e);
|
|
48
|
+
};
|
|
49
|
+
_this.handleDrag = function (e) {
|
|
50
|
+
_this.props.onDrag(_this.state.index, e);
|
|
51
|
+
};
|
|
52
|
+
_this.handleDragEnd = function (e) {
|
|
53
|
+
_this.setState({ isDragging: false });
|
|
54
|
+
_this.props.onDragEnd(_this.state.index, e);
|
|
55
|
+
};
|
|
56
|
+
_this.state = {
|
|
57
|
+
index: props.index,
|
|
58
|
+
isValid: true,
|
|
59
|
+
child: props.child,
|
|
60
|
+
col: _this.props.index % _this.props.visibleCount,
|
|
61
|
+
row: Math.floor(_this.props.index / _this.props.visibleCount),
|
|
62
|
+
isDragging: false,
|
|
63
|
+
};
|
|
64
|
+
_this.ref = createRef();
|
|
65
|
+
return _this;
|
|
66
|
+
}
|
|
67
|
+
DragItem.prototype.render = function () {
|
|
68
|
+
var _this = this;
|
|
69
|
+
var DragItemStyle;
|
|
70
|
+
DragItemStyle = {
|
|
71
|
+
position: 'absolute',
|
|
72
|
+
left: 0,
|
|
73
|
+
top: 0,
|
|
74
|
+
width: this.props.itemWidth,
|
|
75
|
+
height: this.props.itemHeight,
|
|
76
|
+
display: 'flex',
|
|
77
|
+
transform: "translate3d(".concat(this.state.col * this.props.itemWidth, "px, ").concat(this.state.row * this.props.itemHeight, "px, 0)"),
|
|
78
|
+
};
|
|
79
|
+
if (this.props.animationTime != 0) {
|
|
80
|
+
DragItemStyle['transition'] = "transform ".concat(this.props.animationTime, "ms ease");
|
|
81
|
+
}
|
|
82
|
+
DragItemStyle = __assign(__assign({}, DragItemStyle), this.props.style);
|
|
83
|
+
if (this.state.isDragging) {
|
|
84
|
+
DragItemStyle = __assign(__assign({}, DragItemStyle), this.props.dragStyle);
|
|
85
|
+
}
|
|
86
|
+
return h("div", { draggable: true, onDragStart: function (e) {
|
|
87
|
+
_this.handleDragStart(e);
|
|
88
|
+
}, onDrag: function (e) {
|
|
89
|
+
_this.handleDrag(e);
|
|
90
|
+
}, onDragEnd: function (e) {
|
|
91
|
+
_this.handleDragEnd(e);
|
|
92
|
+
}, ref: this.ref, style: DragItemStyle }, this.state.child);
|
|
93
|
+
};
|
|
94
|
+
return DragItem;
|
|
95
|
+
}(Component));
|
|
96
|
+
var DragList = /** @class */ (function (_super) {
|
|
97
|
+
__extends(DragList, _super);
|
|
98
|
+
function DragList(props) {
|
|
99
|
+
var _this = _super.call(this, props) || this;
|
|
100
|
+
_this.itemCache = [];
|
|
101
|
+
_this.handleDragStart = function (index, e) {
|
|
102
|
+
_this.dragIndex = index;
|
|
103
|
+
_this.setState({
|
|
104
|
+
draggingIndex: index,
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
_this.handleDrag = function (index, e) {
|
|
108
|
+
if (!_this.containerRect || e.screenX == 0) // 浏览器松开鼠标后会派发一次错误的drag事件
|
|
109
|
+
return;
|
|
110
|
+
var relativeX = e.clientX - _this.containerRect.left;
|
|
111
|
+
var relativeY = e.clientY - _this.containerRect.top;
|
|
112
|
+
var col = Math.floor(relativeX / _this.props.itemWidth);
|
|
113
|
+
var row = Math.floor(relativeY / _this.props.itemHeight);
|
|
114
|
+
var targetIndex = row * _this.visibleCount + col;
|
|
115
|
+
var validIndex = Math.max(0, Math.min(targetIndex, _this.props.itemSize - 1));
|
|
116
|
+
_this.setState({
|
|
117
|
+
dragOffsetX: relativeX - _this.props.itemWidth / 2,
|
|
118
|
+
dragOffsetY: relativeY - _this.props.itemHeight / 2,
|
|
119
|
+
});
|
|
120
|
+
if (_this.state.draggingIndex !== null && validIndex !== _this.state.draggingIndex) {
|
|
121
|
+
_this.moveItem(_this.state.draggingIndex, validIndex);
|
|
122
|
+
_this.setState({ draggingIndex: validIndex });
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
_this.handleDragEnd = function (index, e) {
|
|
126
|
+
console.log('dragend', e);
|
|
127
|
+
_this.dragIndex = -1;
|
|
128
|
+
_this.setState({
|
|
129
|
+
draggingIndex: null,
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
_this.ref = createRef();
|
|
133
|
+
_this.listSize = 0;
|
|
134
|
+
_this.visibleCount = 0;
|
|
135
|
+
_this.dragIndex = -1;
|
|
136
|
+
_this.dragEndIndex = -1;
|
|
137
|
+
_this.state = {
|
|
138
|
+
itemHeight: props.itemHeight,
|
|
139
|
+
itemWidth: props.itemWidth,
|
|
140
|
+
itemSize: props.itemSize,
|
|
141
|
+
itemIndex: Array.from({ length: props.itemSize }, function (_, i) { return i; }),
|
|
142
|
+
draggingIndex: null,
|
|
143
|
+
dragOffsetX: 0,
|
|
144
|
+
dragOffsetY: 0,
|
|
145
|
+
width: 0,
|
|
146
|
+
height: 0,
|
|
147
|
+
};
|
|
148
|
+
return _this;
|
|
149
|
+
}
|
|
150
|
+
DragList.prototype.componentDidMount = function () {
|
|
151
|
+
if (this.ref.current) {
|
|
152
|
+
this.containerRect = this.ref.current.getBoundingClientRect();
|
|
153
|
+
this.listSize = this.containerRect.width;
|
|
154
|
+
}
|
|
155
|
+
this.visibleCount = Math.floor(this.listSize / this.props.itemWidth);
|
|
156
|
+
for (var i = 0; i < this.props.itemSize; i++) {
|
|
157
|
+
var ref = createRef();
|
|
158
|
+
var item = {
|
|
159
|
+
vNode: (h(DragItem, { onDragStart: this.handleDragStart, onDrag: this.handleDrag, onDragEnd: this.handleDragEnd, key: i, ref: ref, index: i, child: this.props.renderItemFunc(i), itemHeight: this.props.itemHeight, itemWidth: this.props.itemWidth, visibleCount: this.visibleCount, animationTime: this.props.animationTime != null ? this.props.animationTime : 150, style: this.props.itemStyle ? this.props.itemStyle : {}, dragStyle: this.props.dragItemStyle ? this.props.dragItemStyle : {} })),
|
|
160
|
+
isValid: false,
|
|
161
|
+
ref: ref,
|
|
162
|
+
};
|
|
163
|
+
this.itemCache.push(item);
|
|
164
|
+
}
|
|
165
|
+
this.forceUpdate();
|
|
166
|
+
};
|
|
167
|
+
DragList.prototype.moveItem = function (oldIndex, newIndex) {
|
|
168
|
+
var item = this.itemCache[oldIndex];
|
|
169
|
+
// this.itemCache.splice(oldIndex, 1);
|
|
170
|
+
// this.itemCache.splice(newIndex, 0, item);
|
|
171
|
+
for (var i = 0; i < this.itemCache.length; i++) {
|
|
172
|
+
var node = this.itemCache[i].ref.current;
|
|
173
|
+
if (oldIndex < newIndex) {
|
|
174
|
+
if (node.state.index > oldIndex && node.state.index <= newIndex) {
|
|
175
|
+
this.itemCache[i].ref.current.updateIndex(node.state.index - 1);
|
|
176
|
+
}
|
|
177
|
+
else if (node.state.index == oldIndex) {
|
|
178
|
+
this.itemCache[i].ref.current.updateIndex(newIndex);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (node.state.index >= newIndex && node.state.index < oldIndex) {
|
|
183
|
+
this.itemCache[i].ref.current.updateIndex(node.state.index + 1);
|
|
184
|
+
}
|
|
185
|
+
else if (node.state.index == oldIndex) {
|
|
186
|
+
this.itemCache[i].ref.current.updateIndex(newIndex);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
this.forceUpdate();
|
|
191
|
+
};
|
|
192
|
+
DragList.prototype.render = function () {
|
|
193
|
+
return (h("div", { ref: this.ref, style: {
|
|
194
|
+
position: 'relative',
|
|
195
|
+
display: 'flex',
|
|
196
|
+
width: this.props.width,
|
|
197
|
+
height: this.props.height,
|
|
198
|
+
} },
|
|
199
|
+
this.itemCache.map(function (item) { return item.vNode; }),
|
|
200
|
+
this.state.draggingIndex !== null && (h("div", { style: __assign({ position: 'absolute', top: "".concat(this.state.dragOffsetY, "px"), left: "".concat(this.state.dragOffsetX, "px"), width: this.props.itemWidth, height: this.props.itemHeight, zIndex: 1000, pointerEvents: 'none', opacity: 0.5 }, this.props.hoverItemStyle) }))));
|
|
201
|
+
};
|
|
202
|
+
return DragList;
|
|
203
|
+
}(Component));
|
|
204
|
+
export { DragList };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { h, Component } from 'preact';
|
|
2
|
-
interface DragListProps {
|
|
3
|
-
items: string[];
|
|
4
|
-
}
|
|
5
|
-
interface DragListState {
|
|
6
|
-
items: string[];
|
|
7
|
-
draggingIndex: number | null;
|
|
8
|
-
dragOverIndex: number | null;
|
|
9
|
-
dragStartX: number;
|
|
10
|
-
dragStartY: number;
|
|
11
|
-
dragOffsetX: number;
|
|
12
|
-
dragOffsetY: number;
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
hoverIndex: number | null;
|
|
16
|
-
}
|
|
17
|
-
export declare class DragList extends Component<DragListProps, DragListState> {
|
|
18
|
-
constructor(props: DragListProps);
|
|
19
|
-
handleMouseDown: (index: number, e: MouseEvent) => void;
|
|
20
|
-
handleMouseMove: (e: MouseEvent) => void;
|
|
21
|
-
handleMouseUp: () => void;
|
|
22
|
-
handleMouseEnter: (index: number) => void;
|
|
23
|
-
handleMouseLeave: () => void;
|
|
24
|
-
getDragOverIndex: (clientX: number, clientY: number) => number | null;
|
|
25
|
-
render(): h.JSX.Element;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
17
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
18
|
-
if (ar || !(i in from)) {
|
|
19
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
20
|
-
ar[i] = from[i];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
24
|
-
};
|
|
25
|
-
import { h, Component } from 'preact';
|
|
26
|
-
var DragList = /** @class */ (function (_super) {
|
|
27
|
-
__extends(DragList, _super);
|
|
28
|
-
function DragList(props) {
|
|
29
|
-
var _this = _super.call(this, props) || this;
|
|
30
|
-
_this.handleMouseDown = function (index, e) {
|
|
31
|
-
var rect = e.target.getBoundingClientRect();
|
|
32
|
-
_this.setState({
|
|
33
|
-
draggingIndex: index,
|
|
34
|
-
dragStartX: e.clientX,
|
|
35
|
-
dragStartY: e.clientY,
|
|
36
|
-
dragOffsetX: e.clientX - rect.left,
|
|
37
|
-
dragOffsetY: e.clientY - rect.top,
|
|
38
|
-
width: rect.width,
|
|
39
|
-
height: rect.height,
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
_this.handleMouseMove = function (e) {
|
|
43
|
-
var draggingIndex = _this.state.draggingIndex;
|
|
44
|
-
if (draggingIndex !== null) {
|
|
45
|
-
var dragOverIndex = _this.getDragOverIndex(e.clientX, e.clientY);
|
|
46
|
-
_this.setState({
|
|
47
|
-
dragOverIndex: dragOverIndex,
|
|
48
|
-
dragStartX: e.clientX,
|
|
49
|
-
dragStartY: e.clientY,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
_this.handleMouseUp = function () {
|
|
54
|
-
var _a = _this.state, draggingIndex = _a.draggingIndex, dragOverIndex = _a.dragOverIndex, items = _a.items;
|
|
55
|
-
if (draggingIndex !== null && dragOverIndex !== null) {
|
|
56
|
-
var newItems = __spreadArray([], items, true);
|
|
57
|
-
var draggedItem = newItems.splice(draggingIndex, 1)[0];
|
|
58
|
-
newItems.splice(dragOverIndex, 0, draggedItem);
|
|
59
|
-
_this.setState({
|
|
60
|
-
items: newItems,
|
|
61
|
-
draggingIndex: null,
|
|
62
|
-
dragOverIndex: null,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
_this.setState({
|
|
67
|
-
draggingIndex: null,
|
|
68
|
-
dragOverIndex: null,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
_this.handleMouseEnter = function (index) {
|
|
73
|
-
_this.setState({ hoverIndex: index });
|
|
74
|
-
};
|
|
75
|
-
_this.handleMouseLeave = function () {
|
|
76
|
-
_this.setState({ hoverIndex: null });
|
|
77
|
-
};
|
|
78
|
-
_this.getDragOverIndex = function (clientX, clientY) {
|
|
79
|
-
var _a = _this.state, draggingIndex = _a.draggingIndex, width = _a.width, height = _a.height, hoverIndex = _a.hoverIndex;
|
|
80
|
-
if (draggingIndex === null)
|
|
81
|
-
return null;
|
|
82
|
-
var element = document.elementFromPoint ? document.elementFromPoint(clientX, clientY) : null;
|
|
83
|
-
if (element == null) {
|
|
84
|
-
return hoverIndex;
|
|
85
|
-
}
|
|
86
|
-
if (element && element.className.includes('drag-item')) {
|
|
87
|
-
var targetIndex = Array.from(element.parentNode.children).indexOf(element);
|
|
88
|
-
if (targetIndex === draggingIndex)
|
|
89
|
-
return null;
|
|
90
|
-
var targetRect = element.getBoundingClientRect();
|
|
91
|
-
var draggingRect = {
|
|
92
|
-
left: clientX - _this.state.dragOffsetX,
|
|
93
|
-
top: clientY - _this.state.dragOffsetY,
|
|
94
|
-
right: clientX - _this.state.dragOffsetX + width,
|
|
95
|
-
bottom: clientY - _this.state.dragOffsetY + height,
|
|
96
|
-
};
|
|
97
|
-
var overlapX = Math.min(draggingRect.right, targetRect.right) - Math.max(draggingRect.left, targetRect.left);
|
|
98
|
-
var overlapY = Math.min(draggingRect.bottom, targetRect.bottom) - Math.max(draggingRect.top, targetRect.top);
|
|
99
|
-
var overlapRatioX = overlapX / width;
|
|
100
|
-
var overlapRatioY = overlapY / height;
|
|
101
|
-
if (overlapRatioX >= 0.5 && overlapRatioY >= 0.5) {
|
|
102
|
-
return targetIndex;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
};
|
|
107
|
-
_this.state = {
|
|
108
|
-
items: props.items,
|
|
109
|
-
draggingIndex: null,
|
|
110
|
-
dragOverIndex: null,
|
|
111
|
-
dragStartX: 0,
|
|
112
|
-
dragStartY: 0,
|
|
113
|
-
dragOffsetX: 0,
|
|
114
|
-
dragOffsetY: 0,
|
|
115
|
-
width: 0,
|
|
116
|
-
height: 0,
|
|
117
|
-
hoverIndex: null,
|
|
118
|
-
};
|
|
119
|
-
return _this;
|
|
120
|
-
}
|
|
121
|
-
DragList.prototype.render = function () {
|
|
122
|
-
var _this = this;
|
|
123
|
-
var _a = this.state, items = _a.items, width = _a.width, height = _a.height, draggingIndex = _a.draggingIndex, dragOverIndex = _a.dragOverIndex, dragStartX = _a.dragStartX, dragStartY = _a.dragStartY, dragOffsetX = _a.dragOffsetX, dragOffsetY = _a.dragOffsetY, hoverIndex = _a.hoverIndex;
|
|
124
|
-
return (h("div", { style: { display: 'flex', flexWrap: 'wrap', flexDirection: 'row', alignItems: 'center', justifyContent: 'center' } },
|
|
125
|
-
items.map(function (item, index) { return (h("div", { key: index, draggable: true, style: {
|
|
126
|
-
padding: '8px',
|
|
127
|
-
border: '1px solid #ccc',
|
|
128
|
-
cursor: 'grab',
|
|
129
|
-
transition: 'transform 0.2s ease',
|
|
130
|
-
margin: '0.1rem',
|
|
131
|
-
position: 'relative',
|
|
132
|
-
opacity: index === draggingIndex ? 0.5 : 1,
|
|
133
|
-
zIndex: index === draggingIndex ? 1 : 'auto',
|
|
134
|
-
backgroundColor: index === dragOverIndex ? '#f0f0f0' : '#fff',
|
|
135
|
-
}, onDragStart: function (e) { return _this.handleMouseDown(index, e); }, onDrag: _this.handleMouseMove, onDragEnd: _this.handleMouseUp, onMouseEnter: function () { return _this.handleMouseEnter(index); }, onMouseLeave: _this.handleMouseLeave }, item)); }),
|
|
136
|
-
draggingIndex !== null && (h("div", { style: {
|
|
137
|
-
position: 'fixed',
|
|
138
|
-
width: width,
|
|
139
|
-
height: height,
|
|
140
|
-
left: dragStartX - dragOffsetX,
|
|
141
|
-
top: dragStartY - dragOffsetY,
|
|
142
|
-
pointerEvents: 'none',
|
|
143
|
-
backgroundColor: '#f0f0f0',
|
|
144
|
-
padding: '8px',
|
|
145
|
-
border: '1px solid #ccc',
|
|
146
|
-
} }, items[draggingIndex]))));
|
|
147
|
-
};
|
|
148
|
-
return DragList;
|
|
149
|
-
}(Component));
|
|
150
|
-
export { DragList };
|