@oddle.me/react-calendar-timeline 0.29.0-rc3
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/LICENSE.md +8 -0
- package/README.md +1298 -0
- package/lib/Timeline.css +107 -0
- package/lib/index.js +77 -0
- package/lib/lib/Timeline.js +929 -0
- package/lib/lib/columns/Columns.js +137 -0
- package/lib/lib/default-config.js +73 -0
- package/lib/lib/headers/CustomDateHeader.js +48 -0
- package/lib/lib/headers/CustomHeader.js +276 -0
- package/lib/lib/headers/DateHeader.js +206 -0
- package/lib/lib/headers/HeadersContext.js +94 -0
- package/lib/lib/headers/Interval.js +131 -0
- package/lib/lib/headers/SidebarHeader.js +130 -0
- package/lib/lib/headers/TimelineHeaders.js +180 -0
- package/lib/lib/headers/constants.js +10 -0
- package/lib/lib/interaction/PreventClickOnDrag.js +99 -0
- package/lib/lib/items/Item.js +627 -0
- package/lib/lib/items/Items.js +178 -0
- package/lib/lib/items/defaultItemRenderer.js +40 -0
- package/lib/lib/items/styles.js +65 -0
- package/lib/lib/layout/Sidebar.js +120 -0
- package/lib/lib/markers/MarkerCanvas.js +159 -0
- package/lib/lib/markers/MarkerCanvasContext.js +28 -0
- package/lib/lib/markers/TimelineMarkersContext.js +157 -0
- package/lib/lib/markers/TimelineMarkersRenderer.js +69 -0
- package/lib/lib/markers/implementations/CursorMarker.js +137 -0
- package/lib/lib/markers/implementations/CustomMarker.js +79 -0
- package/lib/lib/markers/implementations/TodayMarker.js +123 -0
- package/lib/lib/markers/implementations/shared.js +51 -0
- package/lib/lib/markers/markerType.js +12 -0
- package/lib/lib/markers/public/CursorMarker.js +97 -0
- package/lib/lib/markers/public/CustomMarker.js +116 -0
- package/lib/lib/markers/public/TimelineMarkers.js +27 -0
- package/lib/lib/markers/public/TodayMarker.js +121 -0
- package/lib/lib/row/GroupRow.js +94 -0
- package/lib/lib/row/GroupRows.js +117 -0
- package/lib/lib/scroll/ScrollElement.js +289 -0
- package/lib/lib/timeline/TimelineStateContext.js +155 -0
- package/lib/lib/utility/calendar.js +672 -0
- package/lib/lib/utility/dom-helpers.js +62 -0
- package/lib/lib/utility/events.js +23 -0
- package/lib/lib/utility/generic.js +44 -0
- package/lib/resize-detector/container.js +36 -0
- package/lib/resize-detector/window.js +25 -0
- package/package.json +160 -0
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _interactjs = _interopRequireDefault(require("interactjs"));
|
|
13
|
+
|
|
14
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
15
|
+
|
|
16
|
+
var _generic = require("../utility/generic");
|
|
17
|
+
|
|
18
|
+
var _events = require("../utility/events");
|
|
19
|
+
|
|
20
|
+
var _defaultItemRenderer = require("./defaultItemRenderer");
|
|
21
|
+
|
|
22
|
+
var _calendar = require("../utility/calendar");
|
|
23
|
+
|
|
24
|
+
var _domHelpers = require("../utility/dom-helpers");
|
|
25
|
+
|
|
26
|
+
var _styles = require("./styles");
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
+
|
|
30
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
31
|
+
|
|
32
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
|
+
|
|
34
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
35
|
+
|
|
36
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
37
|
+
|
|
38
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
39
|
+
|
|
40
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
41
|
+
|
|
42
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
+
|
|
44
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
45
|
+
|
|
46
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
47
|
+
|
|
48
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
49
|
+
|
|
50
|
+
var Item =
|
|
51
|
+
/*#__PURE__*/
|
|
52
|
+
function (_Component) {
|
|
53
|
+
_inherits(Item, _Component);
|
|
54
|
+
|
|
55
|
+
// removed prop type check for SPEED!
|
|
56
|
+
// they are coming from a trusted component anyway
|
|
57
|
+
// (this complicates performance debugging otherwise)
|
|
58
|
+
function Item(_props) {
|
|
59
|
+
var _this;
|
|
60
|
+
|
|
61
|
+
_classCallCheck(this, Item);
|
|
62
|
+
|
|
63
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Item).call(this, _props));
|
|
64
|
+
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "onMouseDown", function (e) {
|
|
66
|
+
if (!_this.state.interactMounted) {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
_this.startedClicking = true;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
_defineProperty(_assertThisInitialized(_this), "onMouseUp", function (e) {
|
|
73
|
+
if (!_this.state.interactMounted && _this.startedClicking) {
|
|
74
|
+
_this.startedClicking = false;
|
|
75
|
+
|
|
76
|
+
_this.actualClick(e, 'click');
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
_defineProperty(_assertThisInitialized(_this), "onTouchStart", function (e) {
|
|
81
|
+
if (!_this.state.interactMounted) {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
_this.startedTouching = true;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
_defineProperty(_assertThisInitialized(_this), "onTouchEnd", function (e) {
|
|
88
|
+
if (!_this.state.interactMounted && _this.startedTouching) {
|
|
89
|
+
_this.startedTouching = false;
|
|
90
|
+
|
|
91
|
+
_this.actualClick(e, 'touch');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
_defineProperty(_assertThisInitialized(_this), "handleDoubleClick", function (e) {
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
|
|
98
|
+
if (_this.props.onItemDoubleClick) {
|
|
99
|
+
_this.props.onItemDoubleClick(_this.itemId, e);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "handleContextMenu", function (e) {
|
|
104
|
+
if (_this.props.onContextMenu) {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
e.stopPropagation();
|
|
107
|
+
|
|
108
|
+
_this.props.onContextMenu(_this.itemId, e);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
_defineProperty(_assertThisInitialized(_this), "getItemRef", function (el) {
|
|
113
|
+
return _this.item = el;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
_defineProperty(_assertThisInitialized(_this), "getDragLeftRef", function (el) {
|
|
117
|
+
return _this.dragLeft = el;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
_defineProperty(_assertThisInitialized(_this), "getDragRightRef", function (el) {
|
|
121
|
+
return _this.dragRight = el;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
_defineProperty(_assertThisInitialized(_this), "getItemProps", function () {
|
|
125
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
126
|
+
//TODO: maybe shouldnt include all of these classes
|
|
127
|
+
var classNames = 'rct-item' + (_this.props.item.className ? " ".concat(_this.props.item.className) : '');
|
|
128
|
+
return {
|
|
129
|
+
key: _this.itemId,
|
|
130
|
+
ref: _this.getItemRef,
|
|
131
|
+
title: _this.itemDivTitle,
|
|
132
|
+
className: classNames + " ".concat(props.className ? props.className : ''),
|
|
133
|
+
onMouseDown: (0, _events.composeEvents)(_this.onMouseDown, props.onMouseDown),
|
|
134
|
+
onMouseUp: (0, _events.composeEvents)(_this.onMouseUp, props.onMouseUp),
|
|
135
|
+
onTouchStart: (0, _events.composeEvents)(_this.onTouchStart, props.onTouchStart),
|
|
136
|
+
onTouchEnd: (0, _events.composeEvents)(_this.onTouchEnd, props.onTouchEnd),
|
|
137
|
+
onDoubleClick: (0, _events.composeEvents)(_this.handleDoubleClick, props.onDoubleClick),
|
|
138
|
+
onContextMenu: (0, _events.composeEvents)(_this.handleContextMenu, props.onContextMenu),
|
|
139
|
+
style: Object.assign({}, _this.getItemStyle(props))
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
_defineProperty(_assertThisInitialized(_this), "getResizeProps", function () {
|
|
144
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
145
|
+
var leftName = 'rct-item-handler rct-item-handler-left rct-item-handler-resize-left';
|
|
146
|
+
|
|
147
|
+
if (props.leftClassName) {
|
|
148
|
+
leftName += " ".concat(props.leftClassName);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var rightName = 'rct-item-handler rct-item-handler-right rct-item-handler-resize-right';
|
|
152
|
+
|
|
153
|
+
if (props.rightClassName) {
|
|
154
|
+
rightName += " ".concat(props.rightClassName);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
left: {
|
|
159
|
+
ref: _this.getDragLeftRef,
|
|
160
|
+
className: leftName,
|
|
161
|
+
style: Object.assign({}, _styles.leftResizeStyle, props.leftStyle)
|
|
162
|
+
},
|
|
163
|
+
right: {
|
|
164
|
+
ref: _this.getDragRightRef,
|
|
165
|
+
className: rightName,
|
|
166
|
+
style: Object.assign({}, _styles.rightResizeStyle, props.rightStyle)
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
_this.cacheDataFromProps(_props);
|
|
172
|
+
|
|
173
|
+
_this.state = {
|
|
174
|
+
interactMounted: false,
|
|
175
|
+
dragging: null,
|
|
176
|
+
dragStart: null,
|
|
177
|
+
preDragPosition: null,
|
|
178
|
+
dragTime: null,
|
|
179
|
+
dragGroupDelta: null,
|
|
180
|
+
resizing: null,
|
|
181
|
+
resizeEdge: null,
|
|
182
|
+
resizeStart: null,
|
|
183
|
+
resizeTime: null
|
|
184
|
+
};
|
|
185
|
+
return _this;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_createClass(Item, [{
|
|
189
|
+
key: "shouldComponentUpdate",
|
|
190
|
+
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
191
|
+
var shouldUpdate = nextState.dragging !== this.state.dragging || nextState.dragTime !== this.state.dragTime || nextState.dragGroupDelta !== this.state.dragGroupDelta || nextState.resizing !== this.state.resizing || nextState.resizeTime !== this.state.resizeTime || nextProps.keys !== this.props.keys || !(0, _generic.deepObjectCompare)(nextProps.itemProps, this.props.itemProps) || nextProps.selected !== this.props.selected || nextProps.item !== this.props.item || nextProps.canvasTimeStart !== this.props.canvasTimeStart || nextProps.canvasTimeEnd !== this.props.canvasTimeEnd || nextProps.canvasWidth !== this.props.canvasWidth || (nextProps.order ? nextProps.order.index : undefined) !== (this.props.order ? this.props.order.index : undefined) || nextProps.dragSnap !== this.props.dragSnap || nextProps.minResizeWidth !== this.props.minResizeWidth || nextProps.canChangeGroup !== this.props.canChangeGroup || nextProps.canSelect !== this.props.canSelect || nextProps.canMove !== this.props.canMove || nextProps.canResizeLeft !== this.props.canResizeLeft || nextProps.canResizeRight !== this.props.canResizeRight || nextProps.dimensions !== this.props.dimensions;
|
|
192
|
+
return shouldUpdate;
|
|
193
|
+
}
|
|
194
|
+
}, {
|
|
195
|
+
key: "cacheDataFromProps",
|
|
196
|
+
value: function cacheDataFromProps(props) {
|
|
197
|
+
this.itemId = (0, _generic._get)(props.item, props.keys.itemIdKey);
|
|
198
|
+
this.itemTitle = (0, _generic._get)(props.item, props.keys.itemTitleKey);
|
|
199
|
+
this.itemDivTitle = props.keys.itemDivTitleKey ? (0, _generic._get)(props.item, props.keys.itemDivTitleKey) : this.itemTitle;
|
|
200
|
+
this.itemTimeStart = (0, _generic._get)(props.item, props.keys.itemTimeStartKey);
|
|
201
|
+
this.itemTimeEnd = (0, _generic._get)(props.item, props.keys.itemTimeEndKey);
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
204
|
+
key: "getTimeRatio",
|
|
205
|
+
value: function getTimeRatio() {
|
|
206
|
+
var _this$props = this.props,
|
|
207
|
+
canvasTimeStart = _this$props.canvasTimeStart,
|
|
208
|
+
canvasTimeEnd = _this$props.canvasTimeEnd,
|
|
209
|
+
canvasWidth = _this$props.canvasWidth;
|
|
210
|
+
return (0, _calendar.coordinateToTimeRatio)(canvasTimeStart, canvasTimeEnd, canvasWidth);
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "dragTimeSnap",
|
|
214
|
+
value: function dragTimeSnap(dragTime, considerOffset) {
|
|
215
|
+
var dragSnap = this.props.dragSnap;
|
|
216
|
+
|
|
217
|
+
if (dragSnap) {
|
|
218
|
+
var offset = considerOffset ? (0, _moment["default"])().utcOffset() * 60 * 1000 : 0;
|
|
219
|
+
return Math.round(dragTime / dragSnap) * dragSnap - offset % dragSnap;
|
|
220
|
+
} else {
|
|
221
|
+
return dragTime;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "resizeTimeSnap",
|
|
226
|
+
value: function resizeTimeSnap(dragTime) {
|
|
227
|
+
var dragSnap = this.props.dragSnap;
|
|
228
|
+
|
|
229
|
+
if (dragSnap) {
|
|
230
|
+
var endTime = this.itemTimeEnd % dragSnap;
|
|
231
|
+
return Math.round((dragTime - endTime) / dragSnap) * dragSnap + endTime;
|
|
232
|
+
} else {
|
|
233
|
+
return dragTime;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, {
|
|
237
|
+
key: "dragTime",
|
|
238
|
+
value: function dragTime(e) {
|
|
239
|
+
var startTime = (0, _moment["default"])(this.itemTimeStart);
|
|
240
|
+
|
|
241
|
+
if (this.state.dragging) {
|
|
242
|
+
return this.dragTimeSnap(this.timeFor(e) + this.state.dragStart.offset, true);
|
|
243
|
+
} else {
|
|
244
|
+
return startTime;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}, {
|
|
248
|
+
key: "timeFor",
|
|
249
|
+
value: function timeFor(e) {
|
|
250
|
+
var ratio = (0, _calendar.coordinateToTimeRatio)(this.props.canvasTimeStart, this.props.canvasTimeEnd, this.props.canvasWidth);
|
|
251
|
+
var offset = (0, _domHelpers.getSumOffset)(this.props.scrollRef).offsetLeft;
|
|
252
|
+
var scrolls = (0, _domHelpers.getSumScroll)(this.props.scrollRef);
|
|
253
|
+
return (e.pageX - offset + scrolls.scrollLeft) * ratio + this.props.canvasTimeStart;
|
|
254
|
+
}
|
|
255
|
+
}, {
|
|
256
|
+
key: "dragGroupDelta",
|
|
257
|
+
value: function dragGroupDelta(e) {
|
|
258
|
+
var _this$props2 = this.props,
|
|
259
|
+
groupTops = _this$props2.groupTops,
|
|
260
|
+
order = _this$props2.order;
|
|
261
|
+
|
|
262
|
+
if (this.state.dragging) {
|
|
263
|
+
if (!this.props.canChangeGroup) {
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
var groupDelta = 0;
|
|
268
|
+
var offset = (0, _domHelpers.getSumOffset)(this.props.scrollRef).offsetTop;
|
|
269
|
+
var scrolls = (0, _domHelpers.getSumScroll)(this.props.scrollRef);
|
|
270
|
+
|
|
271
|
+
for (var _i = 0, _Object$keys = Object.keys(groupTops); _i < _Object$keys.length; _i++) {
|
|
272
|
+
var key = _Object$keys[_i];
|
|
273
|
+
var groupTop = groupTops[key];
|
|
274
|
+
|
|
275
|
+
if (e.pageY - offset + scrolls.scrollTop > groupTop) {
|
|
276
|
+
groupDelta = parseInt(key, 10) - order.index;
|
|
277
|
+
} else {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (this.props.order.index + groupDelta < 0) {
|
|
283
|
+
return 0 - this.props.order.index;
|
|
284
|
+
} else {
|
|
285
|
+
return groupDelta;
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
292
|
+
key: "resizeTimeDelta",
|
|
293
|
+
value: function resizeTimeDelta(e, resizeEdge) {
|
|
294
|
+
var length = this.itemTimeEnd - this.itemTimeStart;
|
|
295
|
+
var timeDelta = this.dragTimeSnap((e.pageX - this.state.resizeStart) * this.getTimeRatio());
|
|
296
|
+
|
|
297
|
+
if (length + (resizeEdge === 'left' ? -timeDelta : timeDelta) < (this.props.dragSnap || 1000)) {
|
|
298
|
+
if (resizeEdge === 'left') {
|
|
299
|
+
return length - (this.props.dragSnap || 1000);
|
|
300
|
+
} else {
|
|
301
|
+
return (this.props.dragSnap || 1000) - length;
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
return timeDelta;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}, {
|
|
308
|
+
key: "mountInteract",
|
|
309
|
+
value: function mountInteract() {
|
|
310
|
+
var _this2 = this;
|
|
311
|
+
|
|
312
|
+
var leftResize = this.props.useResizeHandle ? '.rct-item-handler-resize-left' : true;
|
|
313
|
+
var rightResize = this.props.useResizeHandle ? '.rct-item-handler-resize-right' : true;
|
|
314
|
+
(0, _interactjs["default"])(this.item).resizable({
|
|
315
|
+
edges: {
|
|
316
|
+
left: this.canResizeLeft() && leftResize,
|
|
317
|
+
right: this.canResizeRight() && rightResize,
|
|
318
|
+
top: false,
|
|
319
|
+
bottom: false
|
|
320
|
+
},
|
|
321
|
+
enabled: this.props.selected && (this.canResizeLeft() || this.canResizeRight())
|
|
322
|
+
}).draggable({
|
|
323
|
+
enabled: this.props.selected && this.canMove()
|
|
324
|
+
}).styleCursor(false).on('dragstart', function (e) {
|
|
325
|
+
if (_this2.props.selected) {
|
|
326
|
+
var clickTime = _this2.timeFor(e);
|
|
327
|
+
|
|
328
|
+
_this2.setState({
|
|
329
|
+
dragging: true,
|
|
330
|
+
dragStart: {
|
|
331
|
+
x: e.pageX,
|
|
332
|
+
y: e.pageY,
|
|
333
|
+
offset: _this2.itemTimeStart - clickTime
|
|
334
|
+
},
|
|
335
|
+
preDragPosition: {
|
|
336
|
+
x: e.target.offsetLeft,
|
|
337
|
+
y: e.target.offsetTop
|
|
338
|
+
},
|
|
339
|
+
dragTime: _this2.itemTimeStart,
|
|
340
|
+
dragGroupDelta: 0
|
|
341
|
+
});
|
|
342
|
+
} else {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}).on('dragmove', function (e) {
|
|
346
|
+
if (_this2.state.dragging) {
|
|
347
|
+
var dragTime = _this2.dragTime(e);
|
|
348
|
+
|
|
349
|
+
var dragGroupDelta = _this2.dragGroupDelta(e);
|
|
350
|
+
|
|
351
|
+
if (_this2.props.moveResizeValidator) {
|
|
352
|
+
dragTime = _this2.props.moveResizeValidator('move', _this2.props.item, dragTime);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (_this2.props.onDrag) {
|
|
356
|
+
_this2.props.onDrag(_this2.itemId, dragTime, _this2.props.order.index + dragGroupDelta);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
_this2.setState({
|
|
360
|
+
dragTime: dragTime,
|
|
361
|
+
dragGroupDelta: dragGroupDelta
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}).on('dragend', function (e) {
|
|
365
|
+
if (_this2.state.dragging) {
|
|
366
|
+
if (_this2.props.onDrop) {
|
|
367
|
+
var dragTime = _this2.dragTime(e);
|
|
368
|
+
|
|
369
|
+
if (_this2.props.moveResizeValidator) {
|
|
370
|
+
dragTime = _this2.props.moveResizeValidator('move', _this2.props.item, dragTime);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
_this2.props.onDrop(_this2.itemId, dragTime, _this2.props.order.index + _this2.dragGroupDelta(e));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
_this2.setState({
|
|
377
|
+
dragging: false,
|
|
378
|
+
dragStart: null,
|
|
379
|
+
preDragPosition: null,
|
|
380
|
+
dragTime: null,
|
|
381
|
+
dragGroupDelta: null
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}).on('resizestart', function (e) {
|
|
385
|
+
if (_this2.props.selected) {
|
|
386
|
+
_this2.setState({
|
|
387
|
+
resizing: true,
|
|
388
|
+
resizeEdge: null,
|
|
389
|
+
// we don't know yet
|
|
390
|
+
resizeStart: e.pageX,
|
|
391
|
+
resizeTime: 0
|
|
392
|
+
});
|
|
393
|
+
} else {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}).on('resizemove', function (e) {
|
|
397
|
+
if (_this2.state.resizing) {
|
|
398
|
+
var resizeEdge = _this2.state.resizeEdge;
|
|
399
|
+
|
|
400
|
+
if (!resizeEdge) {
|
|
401
|
+
resizeEdge = e.deltaRect.left !== 0 ? 'left' : 'right';
|
|
402
|
+
|
|
403
|
+
_this2.setState({
|
|
404
|
+
resizeEdge: resizeEdge
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var resizeTime = _this2.resizeTimeSnap(_this2.timeFor(e));
|
|
409
|
+
|
|
410
|
+
if (_this2.props.moveResizeValidator) {
|
|
411
|
+
resizeTime = _this2.props.moveResizeValidator('resize', _this2.props.item, resizeTime, resizeEdge);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (_this2.props.onResizing) {
|
|
415
|
+
_this2.props.onResizing(_this2.itemId, resizeTime, resizeEdge);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
_this2.setState({
|
|
419
|
+
resizeTime: resizeTime
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}).on('resizeend', function (e) {
|
|
423
|
+
if (_this2.state.resizing) {
|
|
424
|
+
var resizeEdge = _this2.state.resizeEdge;
|
|
425
|
+
|
|
426
|
+
var resizeTime = _this2.resizeTimeSnap(_this2.timeFor(e));
|
|
427
|
+
|
|
428
|
+
if (_this2.props.moveResizeValidator) {
|
|
429
|
+
resizeTime = _this2.props.moveResizeValidator('resize', _this2.props.item, resizeTime, resizeEdge);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (_this2.props.onResized) {
|
|
433
|
+
_this2.props.onResized(_this2.itemId, resizeTime, resizeEdge, _this2.resizeTimeDelta(e, resizeEdge));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
_this2.setState({
|
|
437
|
+
resizing: null,
|
|
438
|
+
resizeStart: null,
|
|
439
|
+
resizeEdge: null,
|
|
440
|
+
resizeTime: null
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}).on('tap', function (e) {
|
|
444
|
+
_this2.actualClick(e, e.pointerType === 'mouse' ? 'click' : 'touch');
|
|
445
|
+
});
|
|
446
|
+
this.setState({
|
|
447
|
+
interactMounted: true
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}, {
|
|
451
|
+
key: "canResizeLeft",
|
|
452
|
+
value: function canResizeLeft() {
|
|
453
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
|
|
454
|
+
|
|
455
|
+
if (!props.canResizeLeft) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
var width = parseInt(props.dimensions.width, 10);
|
|
460
|
+
return width >= props.minResizeWidth;
|
|
461
|
+
}
|
|
462
|
+
}, {
|
|
463
|
+
key: "canResizeRight",
|
|
464
|
+
value: function canResizeRight() {
|
|
465
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
|
|
466
|
+
|
|
467
|
+
if (!props.canResizeRight) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
var width = parseInt(props.dimensions.width, 10);
|
|
472
|
+
return width >= props.minResizeWidth;
|
|
473
|
+
}
|
|
474
|
+
}, {
|
|
475
|
+
key: "canMove",
|
|
476
|
+
value: function canMove() {
|
|
477
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
|
|
478
|
+
return !!props.canMove;
|
|
479
|
+
}
|
|
480
|
+
}, {
|
|
481
|
+
key: "componentDidUpdate",
|
|
482
|
+
value: function componentDidUpdate(prevProps) {
|
|
483
|
+
this.cacheDataFromProps(this.props);
|
|
484
|
+
var interactMounted = this.state.interactMounted;
|
|
485
|
+
var couldDrag = prevProps.selected && this.canMove(prevProps);
|
|
486
|
+
var couldResizeLeft = prevProps.selected && this.canResizeLeft(prevProps);
|
|
487
|
+
var couldResizeRight = prevProps.selected && this.canResizeRight(prevProps);
|
|
488
|
+
var willBeAbleToDrag = this.props.selected && this.canMove(this.props);
|
|
489
|
+
var willBeAbleToResizeLeft = this.props.selected && this.canResizeLeft(this.props);
|
|
490
|
+
var willBeAbleToResizeRight = this.props.selected && this.canResizeRight(this.props);
|
|
491
|
+
|
|
492
|
+
if (this.item) {
|
|
493
|
+
if (this.props.selected && !interactMounted) {
|
|
494
|
+
this.mountInteract();
|
|
495
|
+
interactMounted = true;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (interactMounted && (couldResizeLeft !== willBeAbleToResizeLeft || couldResizeRight !== willBeAbleToResizeRight)) {
|
|
499
|
+
var leftResize = this.props.useResizeHandle ? this.dragLeft : true;
|
|
500
|
+
var rightResize = this.props.useResizeHandle ? this.dragRight : true;
|
|
501
|
+
(0, _interactjs["default"])(this.item).resizable({
|
|
502
|
+
enabled: willBeAbleToResizeLeft || willBeAbleToResizeRight,
|
|
503
|
+
edges: {
|
|
504
|
+
top: false,
|
|
505
|
+
bottom: false,
|
|
506
|
+
left: willBeAbleToResizeLeft && leftResize,
|
|
507
|
+
right: willBeAbleToResizeRight && rightResize
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (interactMounted && couldDrag !== willBeAbleToDrag) {
|
|
513
|
+
(0, _interactjs["default"])(this.item).draggable({
|
|
514
|
+
enabled: willBeAbleToDrag
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
interactMounted = false;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
this.setState({
|
|
522
|
+
interactMounted: interactMounted
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}, {
|
|
526
|
+
key: "actualClick",
|
|
527
|
+
value: function actualClick(e, clickType) {
|
|
528
|
+
if (this.props.canSelect && this.props.onSelect) {
|
|
529
|
+
this.props.onSelect(this.itemId, clickType, e);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}, {
|
|
533
|
+
key: "getItemStyle",
|
|
534
|
+
value: function getItemStyle(props) {
|
|
535
|
+
var dimensions = this.props.dimensions;
|
|
536
|
+
var baseStyles = {
|
|
537
|
+
position: 'absolute',
|
|
538
|
+
boxSizing: 'border-box',
|
|
539
|
+
left: "".concat(dimensions.left, "px"),
|
|
540
|
+
top: "".concat(dimensions.top, "px"),
|
|
541
|
+
width: "".concat(dimensions.width, "px"),
|
|
542
|
+
height: "".concat(dimensions.height, "px"),
|
|
543
|
+
lineHeight: "".concat(dimensions.height, "px")
|
|
544
|
+
};
|
|
545
|
+
var finalStyle = Object.assign({}, _styles.overridableStyles, this.props.selected ? _styles.selectedStyle : {}, this.props.selected & this.canMove(this.props) ? _styles.selectedAndCanMove : {}, this.props.selected & this.canResizeLeft(this.props) ? _styles.selectedAndCanResizeLeft : {}, this.props.selected & this.canResizeLeft(this.props) & this.state.dragging ? _styles.selectedAndCanResizeLeftAndDragLeft : {}, this.props.selected & this.canResizeRight(this.props) ? _styles.selectedAndCanResizeRight : {}, this.props.selected & this.canResizeRight(this.props) & this.state.dragging ? _styles.selectedAndCanResizeRightAndDragRight : {}, props.style, baseStyles);
|
|
546
|
+
return finalStyle;
|
|
547
|
+
}
|
|
548
|
+
}, {
|
|
549
|
+
key: "render",
|
|
550
|
+
value: function render() {
|
|
551
|
+
if (typeof this.props.order === 'undefined' || this.props.order === null) {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
var timelineContext = this.context.getTimelineContext();
|
|
556
|
+
var itemContext = {
|
|
557
|
+
dimensions: this.props.dimensions,
|
|
558
|
+
useResizeHandle: this.props.useResizeHandle,
|
|
559
|
+
title: this.itemTitle,
|
|
560
|
+
canMove: this.canMove(this.props),
|
|
561
|
+
canResizeLeft: this.canResizeLeft(this.props),
|
|
562
|
+
canResizeRight: this.canResizeRight(this.props),
|
|
563
|
+
selected: this.props.selected,
|
|
564
|
+
dragging: this.state.dragging,
|
|
565
|
+
dragStart: this.state.dragStart,
|
|
566
|
+
dragTime: this.state.dragTime,
|
|
567
|
+
dragGroupDelta: this.state.dragGroupDelta,
|
|
568
|
+
resizing: this.state.resizing,
|
|
569
|
+
resizeEdge: this.state.resizeEdge,
|
|
570
|
+
resizeStart: this.state.resizeStart,
|
|
571
|
+
resizeTime: this.state.resizeTime,
|
|
572
|
+
width: this.props.dimensions.width
|
|
573
|
+
};
|
|
574
|
+
return this.props.itemRenderer({
|
|
575
|
+
item: this.props.item,
|
|
576
|
+
timelineContext: timelineContext,
|
|
577
|
+
itemContext: itemContext,
|
|
578
|
+
getItemProps: this.getItemProps,
|
|
579
|
+
getResizeProps: this.getResizeProps
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}]);
|
|
583
|
+
|
|
584
|
+
return Item;
|
|
585
|
+
}(_react.Component);
|
|
586
|
+
|
|
587
|
+
exports["default"] = Item;
|
|
588
|
+
|
|
589
|
+
_defineProperty(Item, "propTypes", {
|
|
590
|
+
canvasTimeStart: _propTypes["default"].number.isRequired,
|
|
591
|
+
canvasTimeEnd: _propTypes["default"].number.isRequired,
|
|
592
|
+
canvasWidth: _propTypes["default"].number.isRequired,
|
|
593
|
+
order: _propTypes["default"].object,
|
|
594
|
+
dragSnap: _propTypes["default"].number,
|
|
595
|
+
minResizeWidth: _propTypes["default"].number,
|
|
596
|
+
selected: _propTypes["default"].bool,
|
|
597
|
+
canChangeGroup: _propTypes["default"].bool.isRequired,
|
|
598
|
+
canMove: _propTypes["default"].bool.isRequired,
|
|
599
|
+
canResizeLeft: _propTypes["default"].bool.isRequired,
|
|
600
|
+
canResizeRight: _propTypes["default"].bool.isRequired,
|
|
601
|
+
keys: _propTypes["default"].object.isRequired,
|
|
602
|
+
item: _propTypes["default"].object.isRequired,
|
|
603
|
+
onSelect: _propTypes["default"].func,
|
|
604
|
+
onDrag: _propTypes["default"].func,
|
|
605
|
+
onDrop: _propTypes["default"].func,
|
|
606
|
+
onResizing: _propTypes["default"].func,
|
|
607
|
+
onResized: _propTypes["default"].func,
|
|
608
|
+
onContextMenu: _propTypes["default"].func,
|
|
609
|
+
itemRenderer: _propTypes["default"].func,
|
|
610
|
+
itemProps: _propTypes["default"].object,
|
|
611
|
+
canSelect: _propTypes["default"].bool,
|
|
612
|
+
dimensions: _propTypes["default"].object,
|
|
613
|
+
groupTops: _propTypes["default"].array,
|
|
614
|
+
useResizeHandle: _propTypes["default"].bool,
|
|
615
|
+
moveResizeValidator: _propTypes["default"].func,
|
|
616
|
+
onItemDoubleClick: _propTypes["default"].func,
|
|
617
|
+
scrollRef: _propTypes["default"].object
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
_defineProperty(Item, "defaultProps", {
|
|
621
|
+
selected: false,
|
|
622
|
+
itemRenderer: _defaultItemRenderer.defaultItemRenderer
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
_defineProperty(Item, "contextTypes", {
|
|
626
|
+
getTimelineContext: _propTypes["default"].func
|
|
627
|
+
});
|