@startlibs/components 1.0.4 → 1.1.1
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/lib/BasicBulletList.mjs +9 -0
- package/lib/BasicBulletList.mjs.map +1 -0
- package/lib/Button.mjs +95 -0
- package/lib/Button.mjs.map +1 -0
- package/lib/ContextMenu.mjs +452 -0
- package/lib/ContextMenu.mjs.map +1 -0
- package/lib/Dialog.mjs +232 -0
- package/lib/Dialog.mjs.map +1 -0
- package/lib/Draggable.mjs +880 -0
- package/lib/Draggable.mjs.map +1 -0
- package/lib/ErrorBoundary.mjs +108 -0
- package/lib/ErrorBoundary.mjs.map +1 -0
- package/lib/FillLastLineResizer.mjs +238 -0
- package/lib/FillLastLineResizer.mjs.map +1 -0
- package/lib/Flip.mjs +604 -0
- package/lib/Flip.mjs.map +1 -0
- package/lib/FlipList.mjs +186 -0
- package/lib/FlipList.mjs.map +1 -0
- package/lib/FormatDate.mjs +25 -0
- package/lib/FormatDate.mjs.map +1 -0
- package/lib/Icon.mjs +50 -0
- package/lib/Icon.mjs.map +1 -0
- package/lib/Image.mjs +41 -0
- package/lib/Image.mjs.map +1 -0
- package/lib/Link.mjs +116 -0
- package/lib/Link.mjs.map +1 -0
- package/lib/Loading.mjs +10 -0
- package/lib/Loading.mjs.map +1 -0
- package/lib/LoadingDiv.mjs +83 -0
- package/lib/LoadingDiv.mjs.map +1 -0
- package/lib/Notifications.mjs +63 -0
- package/lib/Notifications.mjs.map +1 -0
- package/lib/PageLoader.mjs +42 -0
- package/lib/PageLoader.mjs.map +1 -0
- package/lib/PersistentNotifications.mjs +130 -0
- package/lib/PersistentNotifications.mjs.map +1 -0
- package/lib/Popup.mjs +49 -0
- package/lib/Popup.mjs.map +1 -0
- package/lib/SplitColumnsContainer.mjs +43 -0
- package/lib/SplitColumnsContainer.mjs.map +1 -0
- package/lib/SwitchDiv.mjs +61 -0
- package/lib/SwitchDiv.mjs.map +1 -0
- package/lib/TextButton.mjs +41 -0
- package/lib/TextButton.mjs.map +1 -0
- package/lib/ToastNotifications.mjs +215 -0
- package/lib/ToastNotifications.mjs.map +1 -0
- package/lib/Tooltip.mjs +160 -0
- package/lib/Tooltip.mjs.map +1 -0
- package/lib/TransitionDiv.mjs +56 -0
- package/lib/TransitionDiv.mjs.map +1 -0
- package/lib/WarningDialog.mjs +84 -0
- package/lib/WarningDialog.mjs.map +1 -0
- package/lib/alt/buttons/OnClickLoadingButton.mjs +36 -0
- package/lib/alt/buttons/OnClickLoadingButton.mjs.map +1 -0
- package/lib/alt/dialogs/DialogWithImageHeader.mjs +14 -0
- package/lib/alt/dialogs/DialogWithImageHeader.mjs.map +1 -0
- package/lib/alt/dialogs/DialogWithSidebar.mjs +106 -0
- package/lib/alt/dialogs/DialogWithSidebar.mjs.map +1 -0
- package/lib/alt/dialogs/MobileBubbleDialog.mjs +49 -0
- package/lib/alt/dialogs/MobileBubbleDialog.mjs.map +1 -0
- package/lib/containers/DialogContainer.mjs +413 -0
- package/lib/containers/DialogContainer.mjs.map +1 -0
- package/lib/containers/Reposition.mjs +35 -0
- package/lib/containers/Reposition.mjs.map +1 -0
- package/lib/containers/usePositioning.mjs +294 -0
- package/lib/containers/usePositioning.mjs.map +1 -0
- package/lib/index.cjs +5000 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.mjs +37 -0
- package/lib/index.mjs.map +1 -0
- package/lib/useDialogWithToggle.mjs +18 -0
- package/lib/useDialogWithToggle.mjs.map +1 -0
- package/lib/willUseIsSticky.mjs +123 -0
- package/lib/willUseIsSticky.mjs.map +1 -0
- package/package.json +47 -30
- package/src/BasicBulletList.jsx +21 -0
- package/src/Button.jsx +288 -0
- package/src/ContextMenu.jsx +621 -0
- package/src/Dialog.jsx +413 -0
- package/src/Draggable.jsx +801 -0
- package/src/ErrorBoundary.jsx +75 -0
- package/src/FillLastLineResizer.jsx +226 -0
- package/src/Flip.jsx +560 -0
- package/src/FlipList.jsx +136 -0
- package/src/FormatDate.jsx +9 -0
- package/src/Icon.jsx +49 -0
- package/src/Image.jsx +23 -0
- package/src/Link.jsx +68 -0
- package/src/Loading.jsx +29 -0
- package/src/LoadingDiv.jsx +75 -0
- package/src/Notifications.jsx +89 -0
- package/src/PageLoader.jsx +48 -0
- package/src/PersistentNotifications.jsx +182 -0
- package/src/Popup.jsx +49 -0
- package/src/SplitColumnsContainer.jsx +63 -0
- package/src/SwitchDiv.jsx +30 -0
- package/src/TextButton.jsx +34 -0
- package/src/ToastNotifications.jsx +298 -0
- package/src/Tooltip.jsx +158 -0
- package/src/TransitionDiv.jsx +34 -0
- package/src/WarningDialog.jsx +70 -0
- package/src/alt/buttons/OnClickLoadingButton.jsx +16 -0
- package/src/alt/dialogs/DialogWithImageHeader.jsx +42 -0
- package/src/alt/dialogs/DialogWithSidebar.jsx +135 -0
- package/src/alt/dialogs/MobileBubbleDialog.jsx +56 -0
- package/src/containers/DialogContainer.jsx +423 -0
- package/src/containers/Reposition.jsx +24 -0
- package/src/containers/usePositioning.jsx +305 -0
- package/src/index.js +35 -0
- package/src/useDialogWithToggle.jsx +12 -0
- package/src/willUseIsSticky.jsx +113 -0
- package/.babelrc +0 -27
- package/lib/index.js +0 -5429
- package/rollup.config.js +0 -52
- package/yarn-error.log +0 -3724
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
+
import _set from 'lodash/fp/set';
|
|
5
|
+
import _assign from 'lodash/fp/assign';
|
|
6
|
+
import _pullAt from 'lodash/fp/pullAt';
|
|
7
|
+
import _map from 'lodash/fp/map';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import ReactDOM from 'react-dom';
|
|
10
|
+
import styled from 'styled-components';
|
|
11
|
+
import { getScrollParent, normalizeMouse, normalizeTouch } from '@startlibs/utils';
|
|
12
|
+
import { FlipList } from './FlipList.mjs';
|
|
13
|
+
|
|
14
|
+
const _excluded = ["DragTag", "as", "eventHandlers", "className", "isDragging", "droppable", "dragIndex", "roundedPlaceholder", "inheritRadius", "children"],
|
|
15
|
+
_excluded2 = ["setItemOrder", "noResistance", "animation", "timing", "disabled", "list", "ghostScale", "setDragRef", "scrollOnDrag", "holdTouchTimer", "children"];
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
const {
|
|
19
|
+
Provider,
|
|
20
|
+
Consumer
|
|
21
|
+
} = /*#__PURE__*/React.createContext({});
|
|
22
|
+
const DropPosition = /*#__PURE__*/styled.div.withConfig({
|
|
23
|
+
displayName: "Draggable__DropPosition",
|
|
24
|
+
componentId: "sc-1g7nmwq-0"
|
|
25
|
+
})(["border:2px dashed rgba(0,0,0,0.1);background-color:rgba(0,0,0,0.025);border-radius:18px;position:absolute;top:0;bottom:0;right:0;left:0;visibility:visible;display:block;border-radius:inherit;", ""], props => props.rounded && "\n border-radius: 1000rem;\n ");
|
|
26
|
+
const EmptyPlaceholder = /*#__PURE__*/styled.div.withConfig({
|
|
27
|
+
displayName: "Draggable__EmptyPlaceholder",
|
|
28
|
+
componentId: "sc-1g7nmwq-1"
|
|
29
|
+
})(["position:absolute;"]);
|
|
30
|
+
const HORIZONTAL_DIMENSIONS = {
|
|
31
|
+
min: 'left',
|
|
32
|
+
max: 'right',
|
|
33
|
+
axis: 'x',
|
|
34
|
+
size: 'Width'
|
|
35
|
+
};
|
|
36
|
+
const VERTICAL_DIMENSIONS = {
|
|
37
|
+
min: 'top',
|
|
38
|
+
max: 'bottom',
|
|
39
|
+
axis: 'y',
|
|
40
|
+
size: 'Height'
|
|
41
|
+
};
|
|
42
|
+
const AUTO_SCROLL_BORDER_SIZE = 30;
|
|
43
|
+
const AUTO_SCROLL_MAX_VELOCITY = 20;
|
|
44
|
+
const AUTO_SCROLL_OVERFLOW_BUFFER = 100;
|
|
45
|
+
function easeInCubic(t) {
|
|
46
|
+
return Math.ceil(t * t * t / (AUTO_SCROLL_MAX_VELOCITY * AUTO_SCROLL_MAX_VELOCITY));
|
|
47
|
+
}
|
|
48
|
+
const disableWillChange = el => {
|
|
49
|
+
const willChange = el === null || el === void 0 ? void 0 : el.closest(".JS-has-wc");
|
|
50
|
+
if (willChange) {
|
|
51
|
+
willChange.classList.add('JS-wc-off');
|
|
52
|
+
disableWillChange(willChange.parentNode);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const reenableWillChange = el => {
|
|
56
|
+
const willChange = el === null || el === void 0 ? void 0 : el.closest(".JS-has-wc");
|
|
57
|
+
if (willChange) {
|
|
58
|
+
willChange.classList.remove('JS-wc-off');
|
|
59
|
+
reenableWillChange(willChange.parentNode);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const shouldPreventDrag = e => !e.target.closest('body,.drag-drop-item,[data-drag="false"],input,textarea,button').matches('body,.drag-drop-item,[data-drag="true"]');
|
|
63
|
+
class DraggableItem extends React.Component {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments);
|
|
66
|
+
this.events = this.props.eventHandlers(this);
|
|
67
|
+
}
|
|
68
|
+
render() {
|
|
69
|
+
const _this$props = this.props,
|
|
70
|
+
{
|
|
71
|
+
DragTag,
|
|
72
|
+
as = 'div',
|
|
73
|
+
eventHandlers,
|
|
74
|
+
className,
|
|
75
|
+
isDragging,
|
|
76
|
+
droppable,
|
|
77
|
+
dragIndex,
|
|
78
|
+
roundedPlaceholder,
|
|
79
|
+
inheritRadius,
|
|
80
|
+
children
|
|
81
|
+
} = _this$props,
|
|
82
|
+
props = _objectWithoutProperties(_this$props, _excluded);
|
|
83
|
+
const Wrapper = DragTag || as;
|
|
84
|
+
const extraClassName = (isDragging ? ' drag-drop-placeholder' : '') + ' drag-drop-item';
|
|
85
|
+
return typeof children === 'function' ? children(_objectSpread(_objectSpread({
|
|
86
|
+
className: extraClassName
|
|
87
|
+
}, this.events), {}, {
|
|
88
|
+
children: isDragging && /*#__PURE__*/React.createElement(DropPosition, {
|
|
89
|
+
rounded: roundedPlaceholder,
|
|
90
|
+
inheritRadius: inheritRadius
|
|
91
|
+
})
|
|
92
|
+
})) : /*#__PURE__*/React.createElement(Wrapper, _extends({
|
|
93
|
+
className: className + extraClassName,
|
|
94
|
+
isDragging: isDragging
|
|
95
|
+
}, props, this.events), children, isDragging && /*#__PURE__*/React.createElement(DropPosition, {
|
|
96
|
+
rounded: roundedPlaceholder,
|
|
97
|
+
inheritRadius: inheritRadius
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
DraggableItem.a = props => /*#__PURE__*/React.createElement(DraggableItem, _extends({}, props, {
|
|
102
|
+
DragTag: "a"
|
|
103
|
+
}));
|
|
104
|
+
const DroppableContainer = props => /*#__PURE__*/React.createElement(Consumer, null, dragProps => /*#__PURE__*/React.createElement(DroppableContainerComponent, _extends({}, props, dragProps)));
|
|
105
|
+
class DroppableContainerComponent extends React.Component {
|
|
106
|
+
constructor() {
|
|
107
|
+
super(...arguments);
|
|
108
|
+
this.draggables = [];
|
|
109
|
+
this.emptyPlaceholder = void 0;
|
|
110
|
+
this.addProps = (children, eventHandlers, activeIndex, extraProps) => children.map((c, index) => c.type === DraggableItem ? /*#__PURE__*/React.cloneElement(c, {
|
|
111
|
+
isDragging: activeIndex === index,
|
|
112
|
+
dragIndex: index,
|
|
113
|
+
droppable: this,
|
|
114
|
+
ref: el => this.draggables[index] = el,
|
|
115
|
+
eventHandlers: eventHandlers
|
|
116
|
+
}) : c);
|
|
117
|
+
this.toPosition = (parentRect, _ref) => {
|
|
118
|
+
let {
|
|
119
|
+
scrollTop,
|
|
120
|
+
scrollLeft
|
|
121
|
+
} = _ref;
|
|
122
|
+
return (el, i) => {
|
|
123
|
+
if (el) {
|
|
124
|
+
const domNode = ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode(el);
|
|
125
|
+
const {
|
|
126
|
+
width,
|
|
127
|
+
height
|
|
128
|
+
} = domNode.getBoundingClientRect();
|
|
129
|
+
return {
|
|
130
|
+
droppable: this,
|
|
131
|
+
index: i,
|
|
132
|
+
width,
|
|
133
|
+
height,
|
|
134
|
+
y: parentRect.top + domNode.offsetTop + height / 2 + (scrollTop || 0),
|
|
135
|
+
x: parentRect.left + domNode.offsetLeft + width / 2 + (scrollLeft || 0)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
this.getPosition = (i, scrollXY) => {
|
|
141
|
+
const el = this.draggables[i];
|
|
142
|
+
if (el) {
|
|
143
|
+
const parent = ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode(this).offsetParent;
|
|
144
|
+
const parentRect = parent.getBoundingClientRect();
|
|
145
|
+
return this.toPosition(parentRect, 0)(el, i);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
this.getPositions = (scrollXY, dragInfo) => {
|
|
149
|
+
if (this.props.allowDrop && !this.props.allowDrop(_map(dragInfo, v => v && v.props ? v.props.id : v))) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
const parent = ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode(this).offsetParent;
|
|
153
|
+
if (!parent) {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
const parentRect = parent.getBoundingClientRect();
|
|
157
|
+
const toPosition = this.toPosition(parentRect, scrollXY);
|
|
158
|
+
const existing = this.draggables.map(toPosition).filter(_ => _);
|
|
159
|
+
if (existing.length || !this.props.placeholder) return existing;
|
|
160
|
+
return [ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode(this)].map(toPosition).filter(_ => _);
|
|
161
|
+
};
|
|
162
|
+
this.repositionDragged = (array, _ref2, getActiveElement) => {
|
|
163
|
+
let {
|
|
164
|
+
active,
|
|
165
|
+
startIndex,
|
|
166
|
+
startDroppable,
|
|
167
|
+
activeIndex,
|
|
168
|
+
activeDroppable
|
|
169
|
+
} = _ref2;
|
|
170
|
+
// Repositioning dereferences startDroppable.props further down. Rendering with an
|
|
171
|
+
// activeDroppable but no startDroppable would take the whole tree down, so render
|
|
172
|
+
// the list untouched instead and let the next commit reconcile it.
|
|
173
|
+
if (!startDroppable) {
|
|
174
|
+
return array;
|
|
175
|
+
}
|
|
176
|
+
if (activeDroppable && (activeDroppable === this || startDroppable === this)) {
|
|
177
|
+
// remove
|
|
178
|
+
const removedOrInserted = _pullAt(startDroppable === this ? startIndex : [], array);
|
|
179
|
+
if (activeDroppable === this) {
|
|
180
|
+
// insert
|
|
181
|
+
removedOrInserted.splice(activeIndex, 0, getActiveElement());
|
|
182
|
+
}
|
|
183
|
+
return removedOrInserted;
|
|
184
|
+
}
|
|
185
|
+
return array;
|
|
186
|
+
};
|
|
187
|
+
this.getPlaceholder = (childArray, dragInfo) => childArray.find(_ => _.props.droppable) || dragInfo.startDroppable.props.children[dragInfo.startIndex];
|
|
188
|
+
this.getDragged = (childArray, dragInfo) => dragInfo.startDroppable === this ? childArray[dragInfo.startIndex] : /*#__PURE__*/React.cloneElement(this.getPlaceholder(childArray, dragInfo), {
|
|
189
|
+
key: childArray[0].key + 'si' + dragInfo.startIndex
|
|
190
|
+
});
|
|
191
|
+
this.childrenToarray = _ref3 => {
|
|
192
|
+
let {
|
|
193
|
+
children,
|
|
194
|
+
list,
|
|
195
|
+
dragInfo
|
|
196
|
+
} = _ref3;
|
|
197
|
+
const {
|
|
198
|
+
startDroppable,
|
|
199
|
+
startIndex
|
|
200
|
+
} = dragInfo;
|
|
201
|
+
if (list) {
|
|
202
|
+
return React.Children.toArray(children(this.repositionDragged(list, dragInfo, () => startDroppable.props.list[startIndex])));
|
|
203
|
+
} else {
|
|
204
|
+
const childArray = React.Children.toArray(children);
|
|
205
|
+
return this.repositionDragged(childArray, dragInfo, () => this.getDragged(childArray, dragInfo));
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
componentDidMount() {
|
|
210
|
+
this.props.addDroppable(this);
|
|
211
|
+
}
|
|
212
|
+
componentWillUnmount() {
|
|
213
|
+
this.props.removeDroppable(this);
|
|
214
|
+
}
|
|
215
|
+
render() {
|
|
216
|
+
const {
|
|
217
|
+
group,
|
|
218
|
+
placeholder,
|
|
219
|
+
dragInfo,
|
|
220
|
+
animation,
|
|
221
|
+
timing,
|
|
222
|
+
eventHandlers
|
|
223
|
+
} = this.props;
|
|
224
|
+
const {
|
|
225
|
+
active,
|
|
226
|
+
activeIndex,
|
|
227
|
+
activeDroppable
|
|
228
|
+
} = dragInfo;
|
|
229
|
+
const childArray = this.childrenToarray(this.props);
|
|
230
|
+
if (!childArray.length && placeholder) {
|
|
231
|
+
return placeholder();
|
|
232
|
+
}
|
|
233
|
+
return /*#__PURE__*/React.createElement(FlipList, {
|
|
234
|
+
animation: animation,
|
|
235
|
+
timing: timing,
|
|
236
|
+
play: active
|
|
237
|
+
}, this.addProps(childArray, eventHandlers, active && activeDroppable === this && activeIndex));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
DroppableContainerComponent.defaultProps = {
|
|
241
|
+
placeholder: () => /*#__PURE__*/React.createElement(EmptyPlaceholder, null)
|
|
242
|
+
};
|
|
243
|
+
class DraggableContainer extends React.Component {
|
|
244
|
+
constructor() {
|
|
245
|
+
var _this;
|
|
246
|
+
super(...arguments);
|
|
247
|
+
_this = this;
|
|
248
|
+
this.props = void 0;
|
|
249
|
+
/*: {
|
|
250
|
+
scrollContainer,
|
|
251
|
+
setItemOrder,
|
|
252
|
+
children,
|
|
253
|
+
noResistance,
|
|
254
|
+
holdTouchTimer
|
|
255
|
+
}*/
|
|
256
|
+
this.ghost = void 0;
|
|
257
|
+
// dragEnd animates the ghost out over 300ms, so the tail of a drag is asynchronous
|
|
258
|
+
// and a new drag can start before the previous one has finished. Each drag therefore
|
|
259
|
+
// gets its own session holding everything its completion needs (ghost, dragInfo),
|
|
260
|
+
// instead of reading the shared slots a newer drag may already have taken over.
|
|
261
|
+
// dragToken identifies the drag that currently owns the shared state.
|
|
262
|
+
this.dragToken = 0;
|
|
263
|
+
this.activeSession = null;
|
|
264
|
+
this.positions = {};
|
|
265
|
+
this.passedResistance = false;
|
|
266
|
+
this.pressedEnough = false;
|
|
267
|
+
this.holdTouchTimer = void 0;
|
|
268
|
+
//: number
|
|
269
|
+
this.preventScroll = void 0;
|
|
270
|
+
//: boolean
|
|
271
|
+
this.state = {
|
|
272
|
+
dragInfo: {}
|
|
273
|
+
};
|
|
274
|
+
this.droppables = {};
|
|
275
|
+
this.offsetParent = void 0;
|
|
276
|
+
//: HTMLElement
|
|
277
|
+
this.parent = void 0;
|
|
278
|
+
//: HTMLElement
|
|
279
|
+
this.ghostDimensions = void 0;
|
|
280
|
+
//: GhostDimensions
|
|
281
|
+
this.itemsPositions = void 0;
|
|
282
|
+
//: Array<{ index: number, y: number, x: number }>
|
|
283
|
+
this.scrollContainer = void 0;
|
|
284
|
+
//: HTMLElement & any
|
|
285
|
+
this.lastScrollTop = void 0;
|
|
286
|
+
//: number
|
|
287
|
+
this.lastScrollLeft = void 0;
|
|
288
|
+
//: number
|
|
289
|
+
this.settedDragRef = false;
|
|
290
|
+
this.preventDefault = e => {
|
|
291
|
+
if (!shouldPreventDrag(e) && this.preventScroll) e.preventDefault();
|
|
292
|
+
};
|
|
293
|
+
this.getScrollContainer = () => {
|
|
294
|
+
return this.scrollContainer = this.scrollContainer || (this.props.scrollContainer ? this.props.scrollContainer : getScrollParent(ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode(this)));
|
|
295
|
+
};
|
|
296
|
+
this.removeItem = el => {
|
|
297
|
+
this.domItems = this.domItems.filter(e => e !== el);
|
|
298
|
+
};
|
|
299
|
+
this.setOffsetParent = e => {
|
|
300
|
+
this.parent = e;
|
|
301
|
+
this.offsetParent = e && (window.getComputedStyle(e).position !== 'static' ? e : e.offsetParent);
|
|
302
|
+
};
|
|
303
|
+
this.getConstraintDimensions = () => {
|
|
304
|
+
if (!this.offsetParent) return {
|
|
305
|
+
left: 0,
|
|
306
|
+
top: 0,
|
|
307
|
+
bottom: 0,
|
|
308
|
+
right: 0,
|
|
309
|
+
width: 0,
|
|
310
|
+
height: 0
|
|
311
|
+
};
|
|
312
|
+
return this.offsetParent.getBoundingClientRect();
|
|
313
|
+
};
|
|
314
|
+
this.dragStart = draggable => (e, _ref4) => {
|
|
315
|
+
let {
|
|
316
|
+
pageX,
|
|
317
|
+
pageY,
|
|
318
|
+
clientX,
|
|
319
|
+
clientY
|
|
320
|
+
} = _ref4;
|
|
321
|
+
const currentTarget = e.currentTarget;
|
|
322
|
+
if (shouldPreventDrag(e) || this.props.disabled) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (e.type === 'mousedown' && e.button !== 0) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
e.stopPropagation();
|
|
329
|
+
this.passedResistance = false;
|
|
330
|
+
const holdTouchTimer = this.props.holdTouchTimer;
|
|
331
|
+
this.pressedEnough = !holdTouchTimer;
|
|
332
|
+
if (holdTouchTimer) {
|
|
333
|
+
e.persist();
|
|
334
|
+
this.holdTouchTimer = setTimeout(() => {
|
|
335
|
+
this.pressedEnough = true;
|
|
336
|
+
if (window.navigator.vibrate) window.navigator.vibrate([65]);
|
|
337
|
+
if (!this.state.dragInfo.active) {
|
|
338
|
+
this.dragMove(e, {
|
|
339
|
+
pageX,
|
|
340
|
+
pageY,
|
|
341
|
+
clientX,
|
|
342
|
+
clientY
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}, holdTouchTimer);
|
|
346
|
+
}
|
|
347
|
+
const {
|
|
348
|
+
width,
|
|
349
|
+
height,
|
|
350
|
+
top,
|
|
351
|
+
left
|
|
352
|
+
} = currentTarget.getBoundingClientRect();
|
|
353
|
+
const targetStyle = window.getComputedStyle(currentTarget);
|
|
354
|
+
const {
|
|
355
|
+
top: parentTop,
|
|
356
|
+
left: parentLeft
|
|
357
|
+
} = this.getConstraintDimensions();
|
|
358
|
+
const offsetTop = parentTop + pageY - top + parseInt(targetStyle['margin-top'], 10);
|
|
359
|
+
const offsetLeft = parentLeft + pageX - left + parseInt(targetStyle['margin-left'], 10);
|
|
360
|
+
const {
|
|
361
|
+
scrollTop,
|
|
362
|
+
scrollLeft,
|
|
363
|
+
scrollY,
|
|
364
|
+
scrollX
|
|
365
|
+
} = this.getScrollContainer();
|
|
366
|
+
this.positions = {
|
|
367
|
+
originalX: pageX,
|
|
368
|
+
originalY: pageY,
|
|
369
|
+
offsetTop,
|
|
370
|
+
offsetLeft,
|
|
371
|
+
ghostHeight: height,
|
|
372
|
+
ghostWidth: width,
|
|
373
|
+
ghostMarginTop: parseInt(targetStyle['margin-top'], 10),
|
|
374
|
+
ghostMarginLeft: parseInt(targetStyle['margin-left'], 10),
|
|
375
|
+
scrollLeft: scrollLeft || 0,
|
|
376
|
+
scrollTop: scrollTop || 0,
|
|
377
|
+
scrollY: scrollY || 0,
|
|
378
|
+
scrollX: scrollX || 0
|
|
379
|
+
};
|
|
380
|
+
const ghost = currentTarget.cloneNode(true);
|
|
381
|
+
ghost.className += ' dragging';
|
|
382
|
+
Object.assign(ghost.style, {
|
|
383
|
+
transition: '',
|
|
384
|
+
position: 'fixed',
|
|
385
|
+
display: 'none',
|
|
386
|
+
zIndex: '10',
|
|
387
|
+
width: width + 'px',
|
|
388
|
+
height: height + 'px',
|
|
389
|
+
margin: '0',
|
|
390
|
+
top: top - clientY + 'px',
|
|
391
|
+
left: left - clientX + 'px'
|
|
392
|
+
});
|
|
393
|
+
this.setupMove(ghost, currentTarget.offsetParent, draggable, {
|
|
394
|
+
width,
|
|
395
|
+
height,
|
|
396
|
+
offsetX: pageX - left,
|
|
397
|
+
offsetY: pageY - top
|
|
398
|
+
});
|
|
399
|
+
window.addEventListener('mousemove', this.mouseMove);
|
|
400
|
+
window.addEventListener('touchmove', this.touchMove, {
|
|
401
|
+
passive: false
|
|
402
|
+
});
|
|
403
|
+
window.addEventListener('mouseup', this.dragEnd);
|
|
404
|
+
window.addEventListener('touchend', this.dragEnd);
|
|
405
|
+
window.addEventListener('visibilitychange', this.dragEnd);
|
|
406
|
+
window.addEventListener('blur', this.dragEnd, false);
|
|
407
|
+
window.addEventListener('selectstart', this.disableSelect);
|
|
408
|
+
};
|
|
409
|
+
this.setupMove = (el, parent, item, ghostDimensions) => {
|
|
410
|
+
this.ghostDimensions = ghostDimensions;
|
|
411
|
+
parent.click(); // close popups
|
|
412
|
+
this.ghost = el;
|
|
413
|
+
// Open this drag's session and take ownership of the shared state. Any previous
|
|
414
|
+
// session is now superseded: it still holds its own ghost and dragInfo, so it can
|
|
415
|
+
// finish animating and clean itself up without touching anything below.
|
|
416
|
+
this.dragToken++;
|
|
417
|
+
this.activeSession = {
|
|
418
|
+
token: this.dragToken,
|
|
419
|
+
ghost: el,
|
|
420
|
+
dragInfo: null,
|
|
421
|
+
ended: false,
|
|
422
|
+
endTimeout: null,
|
|
423
|
+
onTransitionEnd: null
|
|
424
|
+
};
|
|
425
|
+
parent.appendChild(this.ghost);
|
|
426
|
+
disableWillChange(this.ghost);
|
|
427
|
+
this.setState({
|
|
428
|
+
dragInfo: {
|
|
429
|
+
active: false,
|
|
430
|
+
startIndex: item.props.dragIndex,
|
|
431
|
+
activeGroup: item.props.droppable.props.group,
|
|
432
|
+
startDroppable: item.props.droppable
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
this.settedDragRef = false;
|
|
436
|
+
};
|
|
437
|
+
this.getScrollPosition = () => {
|
|
438
|
+
const {
|
|
439
|
+
scrollY,
|
|
440
|
+
scrollX,
|
|
441
|
+
scrollLeft,
|
|
442
|
+
scrollTop
|
|
443
|
+
} = this.getScrollContainer();
|
|
444
|
+
const left = (scrollX || 0 + scrollLeft || 0) - this.positions.scrollX - this.positions.scrollLeft;
|
|
445
|
+
const top = (scrollY || 0 + scrollTop || 0) - this.positions.scrollY - this.positions.scrollTop;
|
|
446
|
+
return {
|
|
447
|
+
scrollLeft: left,
|
|
448
|
+
scrollTop: top
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
this.resetPositions = function () {
|
|
452
|
+
let group = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.state.dragInfo.activeGroup;
|
|
453
|
+
_this.itemsPositions = _this.droppables[group].reduce((acc, _) => acc.concat(_.getPositions(_this.getScrollPosition(), _this.state.dragInfo)), []).sort((a, b) => a.y - b.y || a.x - b.x);
|
|
454
|
+
};
|
|
455
|
+
this.move = (x, y) => {
|
|
456
|
+
if (!this.settedDragRef && this.props.setDragRef) {
|
|
457
|
+
this.props.setDragRef(this.ghost);
|
|
458
|
+
this.settedDragRef = true;
|
|
459
|
+
}
|
|
460
|
+
const {
|
|
461
|
+
scrollTop,
|
|
462
|
+
scrollLeft
|
|
463
|
+
} = this.getScrollPosition();
|
|
464
|
+
this.preventScroll = true;
|
|
465
|
+
let item = this.findGhostIndex(x - this.ghostDimensions.offsetX + (scrollLeft || 0), y - this.ghostDimensions.offsetY + (scrollTop || 0), this.ghostDimensions.width, this.ghostDimensions.height);
|
|
466
|
+
if (!item) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const dragInfo = this.state.dragInfo;
|
|
470
|
+
if (item.index !== dragInfo.activeIndex || item.droppable !== dragInfo.activeDroppable) {
|
|
471
|
+
this.setState({
|
|
472
|
+
dragInfo: _assign(dragInfo, {
|
|
473
|
+
active: true,
|
|
474
|
+
activePosition: item,
|
|
475
|
+
activeIndex: item.index,
|
|
476
|
+
activeDroppable: item.droppable
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
this.findGhostIndex = (ghostX1, ghostY1, ghostWidth, ghostHeight) => {
|
|
482
|
+
const ghostY2 = ghostY1 + ghostHeight;
|
|
483
|
+
const ghostX2 = ghostX1 + ghostWidth;
|
|
484
|
+
const centerInsideGhost = this.itemsPositions.filter(position => position.y >= ghostY1 && position.x >= ghostX1 && position.y <= ghostY2 && position.x <= ghostX2);
|
|
485
|
+
const ghostX = ghostX1 + ghostWidth / 2;
|
|
486
|
+
const ghostY = ghostY1 + ghostHeight / 2;
|
|
487
|
+
const rectanglesIntersection = (a, b) => Math.max(0, Math.min(a.x2, b.x2) - Math.max(a.x1, b.x1)) * Math.max(0, Math.min(a.y2, b.y2) - Math.max(a.y1, b.y1));
|
|
488
|
+
const closestIndex = centerInsideGhost.map(item => {
|
|
489
|
+
const {
|
|
490
|
+
x,
|
|
491
|
+
y,
|
|
492
|
+
width,
|
|
493
|
+
height
|
|
494
|
+
} = item;
|
|
495
|
+
const area = width * height;
|
|
496
|
+
const intersectionArea = rectanglesIntersection(
|
|
497
|
+
//at least 1px wide
|
|
498
|
+
{
|
|
499
|
+
x1: x - Math.max(1, width) / 2,
|
|
500
|
+
x2: x + width / 2,
|
|
501
|
+
y1: y - Math.max(1, height) / 2,
|
|
502
|
+
y2: y + height / 2
|
|
503
|
+
}, {
|
|
504
|
+
x1: ghostX1,
|
|
505
|
+
x2: ghostX2,
|
|
506
|
+
y1: ghostY1,
|
|
507
|
+
y2: ghostY2
|
|
508
|
+
});
|
|
509
|
+
const distance = Math.sqrt(Math.pow(x - ghostX, 2) + Math.pow(y - ghostY, 2));
|
|
510
|
+
return {
|
|
511
|
+
area: intersectionArea / area,
|
|
512
|
+
distance
|
|
513
|
+
};
|
|
514
|
+
}).reduce((iMax, _ref5, i, arr) => {
|
|
515
|
+
let {
|
|
516
|
+
area,
|
|
517
|
+
distance
|
|
518
|
+
} = _ref5;
|
|
519
|
+
return area > arr[iMax].area || area === arr[iMax].area && distance < arr[iMax].distance ? i : iMax;
|
|
520
|
+
}, 0);
|
|
521
|
+
return centerInsideGhost[closestIndex];
|
|
522
|
+
};
|
|
523
|
+
this.stopMoving = session => {
|
|
524
|
+
// Completion runs from mouseup, from a transitionend, or from the 300ms fallback
|
|
525
|
+
// timer, so it can be reached more than once for the same drag.
|
|
526
|
+
if (!session || session.ended) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
session.ended = true;
|
|
530
|
+
const {
|
|
531
|
+
token,
|
|
532
|
+
ghost,
|
|
533
|
+
dragInfo
|
|
534
|
+
} = session;
|
|
535
|
+
const {
|
|
536
|
+
activeIndex,
|
|
537
|
+
startIndex,
|
|
538
|
+
activeGroup,
|
|
539
|
+
activeDroppable,
|
|
540
|
+
startDroppable
|
|
541
|
+
} = dragInfo || {};
|
|
542
|
+
if (session.endTimeout) {
|
|
543
|
+
clearTimeout(session.endTimeout);
|
|
544
|
+
session.endTimeout = null;
|
|
545
|
+
}
|
|
546
|
+
if (ghost && session.onTransitionEnd) {
|
|
547
|
+
ghost.removeEventListener('transitionend', session.onTransitionEnd);
|
|
548
|
+
session.onTransitionEnd = null;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Everything below acts on this session's own ghost and dragInfo, so it stays
|
|
552
|
+
// correct even once a newer drag has replaced this.ghost and this.state.dragInfo.
|
|
553
|
+
const finish = () => {
|
|
554
|
+
if (ghost !== null && ghost !== void 0 && ghost.parentNode) {
|
|
555
|
+
reenableWillChange(ghost);
|
|
556
|
+
ghost.parentNode.removeChild(ghost);
|
|
557
|
+
}
|
|
558
|
+
if (activeIndex !== startIndex && activeIndex !== undefined || activeDroppable !== startDroppable && activeDroppable !== undefined) {
|
|
559
|
+
var _startDroppable$props, _activeDroppable$prop;
|
|
560
|
+
const promise = this.props.setItemOrder(startIndex, activeIndex, startDroppable === null || startDroppable === void 0 || (_startDroppable$props = startDroppable.props) === null || _startDroppable$props === void 0 ? void 0 : _startDroppable$props.id, activeDroppable === null || activeDroppable === void 0 || (_activeDroppable$prop = activeDroppable.props) === null || _activeDroppable$prop === void 0 ? void 0 : _activeDroppable$prop.id, activeGroup);
|
|
561
|
+
if (promise && promise.then) {
|
|
562
|
+
promise.then(() => this.clearChangedOrder(token), () => this.clearChangedOrder(token));
|
|
563
|
+
} else {
|
|
564
|
+
this.clearChangedOrder(token);
|
|
565
|
+
}
|
|
566
|
+
} else {
|
|
567
|
+
this.clearChangedOrder(token);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
if (token !== this.dragToken) {
|
|
571
|
+
// Superseded: a newer drag owns the shared state and the render output. Drop
|
|
572
|
+
// our ghost and commit our reorder, but leave that drag's state alone.
|
|
573
|
+
finish();
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
this.setState({
|
|
577
|
+
saving: {
|
|
578
|
+
list: this.props.list,
|
|
579
|
+
children: this.props.children,
|
|
580
|
+
dragInfo: _set('active', false, dragInfo || {})
|
|
581
|
+
}
|
|
582
|
+
}, () => {
|
|
583
|
+
this.preventScroll = false;
|
|
584
|
+
this.props.setDragRef(null);
|
|
585
|
+
this.settedDragRef = false;
|
|
586
|
+
finish();
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
this.clearChangedOrder = token => {
|
|
590
|
+
// Only the drag that still owns the shared state may reset it — a superseded
|
|
591
|
+
// session clearing dragInfo here would wipe the drag currently in progress.
|
|
592
|
+
if (token !== undefined && token !== this.dragToken) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
this.setState({
|
|
596
|
+
dragInfo: {},
|
|
597
|
+
saving: false
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
this.dragMove = (e, _ref6) => {
|
|
601
|
+
let {
|
|
602
|
+
pageX,
|
|
603
|
+
pageY,
|
|
604
|
+
clientX,
|
|
605
|
+
clientY
|
|
606
|
+
} = _ref6;
|
|
607
|
+
const distance = Math.sqrt((this.positions.originalX - pageX) ** 2 + (this.positions.originalY - pageY) ** 2);
|
|
608
|
+
if (e.type === 'mousemove') {
|
|
609
|
+
// get touchstart and touchmove
|
|
610
|
+
if (!this.passedResistance && !this.props.noResistance && distance < 5) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
} else {
|
|
614
|
+
if (!this.pressedEnough) {
|
|
615
|
+
if (distance > 5) {
|
|
616
|
+
this.dragEnd();
|
|
617
|
+
}
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
e.preventDefault();
|
|
621
|
+
}
|
|
622
|
+
this.passedResistance = true;
|
|
623
|
+
this.processAutoScroll(pageX, pageY, clientX, clientY);
|
|
624
|
+
};
|
|
625
|
+
this.completeMove = (pageX, pageY) => {
|
|
626
|
+
const {
|
|
627
|
+
scrollTop,
|
|
628
|
+
scrollLeft
|
|
629
|
+
} = this.getScrollContainer();
|
|
630
|
+
const scrollYDelta = this.positions.scrollTop - (scrollTop || 0);
|
|
631
|
+
const scrollXDelta = this.positions.scrollLeft - (scrollLeft || 0);
|
|
632
|
+
const ghostLeft = pageX - this.positions.offsetLeft;
|
|
633
|
+
const ghostTop = pageY - this.positions.offsetTop;
|
|
634
|
+
const {
|
|
635
|
+
height: parentHeight,
|
|
636
|
+
width: parentWidth
|
|
637
|
+
} = this.getConstraintDimensions();
|
|
638
|
+
const normalizedLeft = Math.max(Math.min(ghostLeft, parentWidth - this.positions.ghostWidth - this.positions.ghostMarginLeft + scrollXDelta), 0 - this.positions.ghostMarginLeft + scrollXDelta);
|
|
639
|
+
const normalizedTop = Math.max(Math.min(ghostTop, parentHeight - this.positions.ghostHeight - this.positions.ghostMarginTop + scrollYDelta), 0 - this.positions.ghostMarginTop + scrollYDelta);
|
|
640
|
+
const x = normalizedLeft - ghostLeft + pageX - window.scrollX;
|
|
641
|
+
const y = normalizedTop - ghostTop + pageY - window.scrollY;
|
|
642
|
+
if (this.ghost) {
|
|
643
|
+
this.ghost.style.transform = "translate(".concat(x, "px,").concat(y, "px)") + (this.props.ghostScale ? ' scale(' + this.props.ghostScale + ')' : '');
|
|
644
|
+
this.ghost.style.display = '';
|
|
645
|
+
}
|
|
646
|
+
this.move(pageX - (ghostLeft - normalizedLeft), pageY - (ghostTop - normalizedTop));
|
|
647
|
+
if (!this.state.dragInfo.active) {
|
|
648
|
+
this.setState({
|
|
649
|
+
dragInfo: _assign(this.state.dragInfo, {
|
|
650
|
+
activeIndex: this.state.dragInfo.startIndex,
|
|
651
|
+
activeDroppable: this.state.dragInfo.startDroppable,
|
|
652
|
+
active: true
|
|
653
|
+
})
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
this.autoScrollAnimation = void 0;
|
|
658
|
+
this.autoScrollX = void 0;
|
|
659
|
+
this.autoScrollY = void 0;
|
|
660
|
+
this.getFixedParentRect = (node, not) => {
|
|
661
|
+
if (node) {
|
|
662
|
+
if (window.getComputedStyle(node)['position'].toLowerCase() === 'fixed' && not !== node) return node.getBoundingClientRect();else return this.getFixedParentRect(node.offsetParent, not);
|
|
663
|
+
} else {
|
|
664
|
+
return {};
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
this.calculateDistanceFromBorder = (ghost, position, getElementBeforeBorder, scrollContainer, parentRect, keys) => {
|
|
668
|
+
const fixedUnderMouse = scrollContainer === window ? this.getFixedParentRect(getElementBeforeBorder(+AUTO_SCROLL_BORDER_SIZE), ghost) : {};
|
|
669
|
+
const min = scrollContainer !== window ? scrollContainer.getBoundingClientRect()[keys.min] : fixedUnderMouse[keys.max] || this.getFixedParentRect(getElementBeforeBorder(-AUTO_SCROLL_BORDER_SIZE), ghost)[keys.max] || 0;
|
|
670
|
+
const max = scrollContainer !== window ? scrollContainer.getBoundingClientRect()[keys.max] : fixedUnderMouse[keys.min] || this.getFixedParentRect(getElementBeforeBorder(+AUTO_SCROLL_BORDER_SIZE), ghost)[keys.min] || window['inner' + keys.size];
|
|
671
|
+
const distanceMin = position - AUTO_SCROLL_BORDER_SIZE - min;
|
|
672
|
+
const distanceMax = position + AUTO_SCROLL_BORDER_SIZE - max;
|
|
673
|
+
const containerMin = scrollContainer === window ? 0 : Math.max(scrollContainer.getBoundingClientRect()[keys.min], 0);
|
|
674
|
+
const containerMax = scrollContainer === window ? window['inner' + keys.size] : Math.min(scrollContainer.getBoundingClientRect()[keys.max], window['inner' + keys.size]);
|
|
675
|
+
const afterCenter = (position - containerMin) * 2 / (containerMax - containerMin) > 1;
|
|
676
|
+
if (distanceMin < 0 && !afterCenter) return distanceMin;
|
|
677
|
+
if (distanceMax > 0) return distanceMax;
|
|
678
|
+
return 0;
|
|
679
|
+
};
|
|
680
|
+
this.processAutoScroll = (pageX, pageY, clientX, clientY) => {
|
|
681
|
+
const scrollContainer = this.getScrollContainer();
|
|
682
|
+
const parentRect = this.getConstraintDimensions();
|
|
683
|
+
this.autoScrollY = this.calculateDistanceFromBorder(this.ghost, clientY, diff => document.elementFromPoint(clientX, clientY + diff), scrollContainer, parentRect, VERTICAL_DIMENSIONS);
|
|
684
|
+
// this.autoScrollX = this.calculateDistanceFromBorder(clientX, (diff) => document.elementFromPoint(clientX + diff, clientY), scrollContainer, parentRect, HORIZONTAL_DIMENSIONS)
|
|
685
|
+
this.autoScrollX = 0;
|
|
686
|
+
// noinspection JSSuspiciousNameCombination
|
|
687
|
+
const keepY = this.autoScrollX === 0 || this.autoScrollY !== 0 && Math.abs(this.autoScrollY) < Math.abs(this.autoScrollX);
|
|
688
|
+
this.autoScrollY = this.props.scrollOnDrag && keepY ? this.autoScrollY : 0;
|
|
689
|
+
this.autoScrollX = this.props.scrollOnDrag && !keepY ? this.autoScrollX : 0;
|
|
690
|
+
if (this.autoScrollX || this.autoScrollY) {
|
|
691
|
+
this.startAutoScroll(pageX, pageY, scrollContainer);
|
|
692
|
+
} else {
|
|
693
|
+
if (this.autoScrollAnimation) {
|
|
694
|
+
this.stopAutoScroll();
|
|
695
|
+
}
|
|
696
|
+
this.completeMove(pageX, pageY);
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
this.checkLimits = (delta, boundRect, constraintRect, scrollRect, keys) => {
|
|
700
|
+
if (delta > 0) {
|
|
701
|
+
if (constraintRect[keys.max] + AUTO_SCROLL_OVERFLOW_BUFFER < scrollRect[keys.max]) {
|
|
702
|
+
return 0;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
if (delta < 0) {
|
|
706
|
+
if (constraintRect[keys.min] - AUTO_SCROLL_OVERFLOW_BUFFER > scrollRect[keys.min]) {
|
|
707
|
+
return 0;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return delta;
|
|
711
|
+
};
|
|
712
|
+
this.startAutoScroll = (pageX, pageY, scrollContainer) => {
|
|
713
|
+
if (!this.autoScrollAnimation) {
|
|
714
|
+
this.autoScrollAnimation = window.requestAnimationFrame(timestamp => {
|
|
715
|
+
const ghostRect = this.ghost.getBoundingClientRect();
|
|
716
|
+
const parentRect = this.getConstraintDimensions();
|
|
717
|
+
const scrollRect = scrollContainer === window ? {
|
|
718
|
+
top: 0,
|
|
719
|
+
bottom: window.innerHeight,
|
|
720
|
+
left: 0,
|
|
721
|
+
right: window.innerWidth
|
|
722
|
+
} : scrollContainer.getBoundingClientRect();
|
|
723
|
+
const deltaScrollX = easeInCubic(this.checkLimits(this.autoScrollX < 0 ? Math.max(this.autoScrollX, -AUTO_SCROLL_MAX_VELOCITY) : Math.min(this.autoScrollX, AUTO_SCROLL_MAX_VELOCITY), ghostRect, parentRect, scrollRect, HORIZONTAL_DIMENSIONS));
|
|
724
|
+
const deltaScrollY = easeInCubic(this.checkLimits(this.autoScrollY < 0 ? Math.max(this.autoScrollY, -AUTO_SCROLL_MAX_VELOCITY) : Math.min(this.autoScrollY, AUTO_SCROLL_MAX_VELOCITY), ghostRect, parentRect, scrollRect, VERTICAL_DIMENSIONS));
|
|
725
|
+
const willScroll = deltaScrollX !== 0 || deltaScrollY !== 0;
|
|
726
|
+
if (willScroll) {
|
|
727
|
+
scrollContainer.scroll((isNaN(scrollContainer.scrollLeft) ? scrollContainer.pageXOffset : scrollContainer.scrollLeft) + deltaScrollX, (isNaN(scrollContainer.scrollTop) ? scrollContainer.pageYOffset : scrollContainer.scrollTop) + deltaScrollY);
|
|
728
|
+
}
|
|
729
|
+
this.autoScrollAnimation = 0;
|
|
730
|
+
this.completeMove(pageX, pageY);
|
|
731
|
+
if (willScroll) {
|
|
732
|
+
this.startAutoScroll(pageX + (scrollContainer === window ? deltaScrollX : 0), pageY + (scrollContainer === window ? deltaScrollY : 0), scrollContainer);
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
} else {
|
|
736
|
+
this.completeMove(pageX, pageY);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
this.stopAutoScroll = () => {
|
|
740
|
+
window.cancelAnimationFrame(this.autoScrollAnimation);
|
|
741
|
+
this.autoScrollAnimation = 0;
|
|
742
|
+
};
|
|
743
|
+
this.dragEnd = () => {
|
|
744
|
+
window.removeEventListener('touchmove', this.touchMove);
|
|
745
|
+
window.removeEventListener('mousemove', this.mouseMove);
|
|
746
|
+
window.removeEventListener('mouseup', this.dragEnd);
|
|
747
|
+
window.removeEventListener('touchend', this.dragEnd);
|
|
748
|
+
window.removeEventListener('visibilitychange', this.dragEnd);
|
|
749
|
+
window.removeEventListener('blur', this.dragEnd);
|
|
750
|
+
window.removeEventListener('selectstart', this.disableSelect);
|
|
751
|
+
this.stopAutoScroll();
|
|
752
|
+
this.props.setDragRef && this.props.setDragRef(null);
|
|
753
|
+
clearTimeout(this.holdTouchTimer);
|
|
754
|
+
// Wired to mouseup, touchend, visibilitychange and blur, so this can fire several
|
|
755
|
+
// times for one drag. Only the first call owns the session and completes it.
|
|
756
|
+
const session = this.activeSession;
|
|
757
|
+
if (!session) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
this.activeSession = null;
|
|
761
|
+
session.dragInfo = this.state.dragInfo;
|
|
762
|
+
const ghost = session.ghost;
|
|
763
|
+
const {
|
|
764
|
+
activeDroppable,
|
|
765
|
+
activeIndex
|
|
766
|
+
} = session.dragInfo;
|
|
767
|
+
const finalPosition = activeDroppable && activeDroppable.getPosition(activeIndex, this.getScrollPosition());
|
|
768
|
+
if (activeDroppable && ghost && finalPosition) {
|
|
769
|
+
const {
|
|
770
|
+
marginTop,
|
|
771
|
+
marginLeft,
|
|
772
|
+
left,
|
|
773
|
+
top
|
|
774
|
+
} = window.getComputedStyle(ghost);
|
|
775
|
+
const finalLeft = finalPosition.x - Math.max(1, finalPosition.width) / 2 - parseInt(left) - parseInt(marginLeft);
|
|
776
|
+
const finalTop = finalPosition.y - Math.max(1, finalPosition.height) / 2 - parseInt(top) - parseInt(marginTop);
|
|
777
|
+
ghost.style.transition = "transform 300ms ease-in-out 0ms, opacity 300ms ease-in-out 0ms";
|
|
778
|
+
const newTransform = "translate(".concat(finalLeft, "px,").concat(finalTop, "px)");
|
|
779
|
+
if ((ghost.style.transform || "").replace(/\s/g, '') === newTransform) {
|
|
780
|
+
this.stopMoving(session);
|
|
781
|
+
} else {
|
|
782
|
+
ghost.style.transform = newTransform;
|
|
783
|
+
session.onTransitionEnd = () => this.stopMoving(session);
|
|
784
|
+
ghost.addEventListener('transitionend', session.onTransitionEnd);
|
|
785
|
+
session.endTimeout = setTimeout(session.onTransitionEnd, 300);
|
|
786
|
+
}
|
|
787
|
+
} else {
|
|
788
|
+
this.stopMoving(session);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
this.addDroppable = el => {
|
|
792
|
+
this.droppables[el.props.group] = (this.droppables[el.props.group] || []).concat(el);
|
|
793
|
+
};
|
|
794
|
+
this.remoevDroppable = el => {
|
|
795
|
+
this.droppables[el.props.group] = this.droppables[el.props.group].filter(_ => _ !== el);
|
|
796
|
+
};
|
|
797
|
+
this.mouseDown = draggable => normalizeMouse(this.dragStart(draggable), this.dragEnd);
|
|
798
|
+
this.mouseMove = normalizeMouse(this.dragMove, this.dragEnd);
|
|
799
|
+
this.touchStart = draggable => normalizeTouch(this.dragStart(draggable), this.dragEnd);
|
|
800
|
+
this.touchMove = normalizeTouch(this.dragMove, this.dragEnd);
|
|
801
|
+
this.providerValue = {};
|
|
802
|
+
this.providerEvents = draggable => ({
|
|
803
|
+
onMouseDown: this.mouseDown(draggable),
|
|
804
|
+
onTouchStart: this.touchStart(draggable)
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
componentDidMount() {
|
|
808
|
+
this.parent.addEventListener('touchmove', this.preventDefault);
|
|
809
|
+
}
|
|
810
|
+
componentWillUnmount() {
|
|
811
|
+
this.parent.removeEventListener('touchmove', this.preventDefault);
|
|
812
|
+
}
|
|
813
|
+
componentDidUpdate(_, prevState) {
|
|
814
|
+
if (!isNaN(this.lastScrollTop) || !isNaN(this.lastScrollLeft)) {
|
|
815
|
+
this.getScrollContainer().scroll(this.lastScrollLeft, this.lastScrollTop);
|
|
816
|
+
this.lastScrollLeft = this.lastScrollTop = undefined;
|
|
817
|
+
}
|
|
818
|
+
if (this.ghost && this.ghost.parentNode) {
|
|
819
|
+
this.ghost.parentNode.appendChild(this.ghost);
|
|
820
|
+
}
|
|
821
|
+
if (this.state.dragInfo !== prevState.dragInfo) {
|
|
822
|
+
this.resetPositions();
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
disableSelect(event) {
|
|
826
|
+
event.preventDefault();
|
|
827
|
+
}
|
|
828
|
+
render() {
|
|
829
|
+
const _this$props2 = this.props,
|
|
830
|
+
{
|
|
831
|
+
setItemOrder,
|
|
832
|
+
noResistance,
|
|
833
|
+
animation,
|
|
834
|
+
timing,
|
|
835
|
+
disabled,
|
|
836
|
+
list,
|
|
837
|
+
ghostScale,
|
|
838
|
+
setDragRef,
|
|
839
|
+
scrollOnDrag,
|
|
840
|
+
holdTouchTimer,
|
|
841
|
+
children
|
|
842
|
+
} = _this$props2,
|
|
843
|
+
rest = _objectWithoutProperties(_this$props2, _excluded2);
|
|
844
|
+
const {
|
|
845
|
+
saving,
|
|
846
|
+
dragInfo
|
|
847
|
+
} = this.state;
|
|
848
|
+
this.providerValue = _assign(this.providerValue, {
|
|
849
|
+
addDroppable: this.addDroppable,
|
|
850
|
+
removeDroppable: this.remoevDroppable,
|
|
851
|
+
dragInfo: saving ? saving.dragInfo : dragInfo,
|
|
852
|
+
eventHandlers: this.providerEvents
|
|
853
|
+
});
|
|
854
|
+
if (this.scrollContainer) {
|
|
855
|
+
const scrollContainer = this.getScrollContainer();
|
|
856
|
+
this.lastScrollTop = (isNaN(scrollContainer['scrollTop']) ? scrollContainer['pageYOffset'] : scrollContainer['scrollTop']) || undefined;
|
|
857
|
+
this.lastScrollLeft = (isNaN(scrollContainer['scrollLeft']) ? scrollContainer['pageXOffset'] : scrollContainer['scrollLeft']) || undefined;
|
|
858
|
+
}
|
|
859
|
+
return /*#__PURE__*/React.createElement(Provider, {
|
|
860
|
+
value: this.providerValue
|
|
861
|
+
}, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
862
|
+
ref: this.setOffsetParent
|
|
863
|
+
}), /*#__PURE__*/React.createElement(DroppableContainer, {
|
|
864
|
+
animation: animation,
|
|
865
|
+
timing: timing,
|
|
866
|
+
list: saving ? saving.list : list,
|
|
867
|
+
placeholder: false
|
|
868
|
+
}, saving ? saving.children : children)));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// type GhostDimensions = { offsetX: number, offsetY: number, width: number, height: number }
|
|
873
|
+
DraggableContainer.defaultProps = {
|
|
874
|
+
holdTouchTimer: 500,
|
|
875
|
+
scrollOnDrag: true,
|
|
876
|
+
setDragRef: () => {}
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
export { DraggableContainer, DraggableItem, DroppableContainer };
|
|
880
|
+
//# sourceMappingURL=Draggable.mjs.map
|