react-big-schedule 5.5.2-beta.5 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,125 +1,116 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _default = require("../config/default");
8
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
10
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
13
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
- var DnDSource = exports["default"] = /*#__PURE__*/_createClass(function DnDSource(resolveDragObjFunc, DnDEnabled) {
16
- var _this = this;
17
- var dndType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _default.DnDTypes.EVENT;
18
- _classCallCheck(this, DnDSource);
19
- _defineProperty(this, "getDragSpec", function () {
20
- return {
21
- // beginDrag: (props, monitor, component) => this.resolveDragObjFunc(props),
22
- beginDrag: function beginDrag(props) {
23
- return _this.resolveDragObjFunc(props);
24
- },
25
- // endDrag: (props, monitor, component) => {
26
- endDrag: function endDrag(props, monitor) {
27
- if (!monitor.didDrop()) return;
28
- var moveEvent = props.moveEvent,
29
- newEvent = props.newEvent,
30
- schedulerData = props.schedulerData;
31
- var events = schedulerData.events,
32
- config = schedulerData.config,
33
- viewType = schedulerData.viewType,
34
- localeDayjs = schedulerData.localeDayjs;
35
- var item = monitor.getItem();
36
- var type = monitor.getItemType();
37
- var dropResult = monitor.getDropResult();
38
- var slotId = dropResult.slotId;
39
- var slotName = dropResult.slotName;
40
- var newStart = dropResult.start;
41
- var newEnd = dropResult.end;
42
- var initialStart = dropResult.initialStart;
43
- // const { initialEnd } = dropResult;
44
- var action = 'New';
45
- var isEvent = type === _default.DnDTypes.EVENT;
46
- if (isEvent) {
47
- var event = item;
48
- if (config.relativeMove) {
49
- newStart = localeDayjs(event.start).add(localeDayjs(newStart).diff(localeDayjs(new Date(initialStart))), 'ms').format(_default.DATETIME_FORMAT);
50
- } else if (viewType !== _default.ViewType.Day) {
51
- var tmpDayjs = localeDayjs(newStart);
52
- newStart = localeDayjs(event.start).year(tmpDayjs.year()).month(tmpDayjs.month()).date(tmpDayjs.date()).format(_default.DATETIME_FORMAT);
53
- }
54
- newEnd = localeDayjs(newStart).add(localeDayjs(event.end).diff(localeDayjs(event.start)), 'ms').format(_default.DATETIME_FORMAT);
55
-
56
- // if crossResourceMove disabled, slot returns old value
57
- if (config.crossResourceMove === false) {
58
- slotId = schedulerData._getEventSlotId(item);
59
- slotName = undefined;
60
- var slot = schedulerData.getSlotById(slotId);
61
- if (slot) slotName = slot.name;
62
- }
63
- action = 'Move';
1
+ import { DATETIME_FORMAT, DnDTypes, ViewType } from '../config/default';
2
+ export default class DnDSource {
3
+ constructor(resolveDragObjFunc, DnDEnabled, dndType = DnDTypes.EVENT) {
4
+ this.resolveDragObjFunc = resolveDragObjFunc;
5
+ this.dndType = dndType;
6
+ this.DnDEnabled = DnDEnabled;
7
+ }
8
+ getDragSpec = () => ({
9
+ // beginDrag: (props, monitor, component) => this.resolveDragObjFunc(props),
10
+ beginDrag: props => this.resolveDragObjFunc(props),
11
+ // endDrag: (props, monitor, component) => {
12
+ endDrag: (props, monitor) => {
13
+ if (!monitor.didDrop()) return;
14
+ const {
15
+ moveEvent,
16
+ newEvent,
17
+ schedulerData
18
+ } = props;
19
+ const {
20
+ events,
21
+ config,
22
+ viewType,
23
+ localeDayjs
24
+ } = schedulerData;
25
+ const item = monitor.getItem();
26
+ const type = monitor.getItemType();
27
+ const dropResult = monitor.getDropResult();
28
+ let {
29
+ slotId
30
+ } = dropResult;
31
+ let {
32
+ slotName
33
+ } = dropResult;
34
+ let newStart = dropResult.start;
35
+ let newEnd = dropResult.end;
36
+ const {
37
+ initialStart
38
+ } = dropResult;
39
+ // const { initialEnd } = dropResult;
40
+ let action = 'New';
41
+ const isEvent = type === DnDTypes.EVENT;
42
+ if (isEvent) {
43
+ const event = item;
44
+ if (config.relativeMove) {
45
+ newStart = localeDayjs(event.start).add(localeDayjs(newStart).diff(localeDayjs(new Date(initialStart))), 'ms').format(DATETIME_FORMAT);
46
+ } else if (viewType !== ViewType.Day) {
47
+ const tmpDayjs = localeDayjs(newStart);
48
+ newStart = localeDayjs(event.start).year(tmpDayjs.year()).month(tmpDayjs.month()).date(tmpDayjs.date()).format(DATETIME_FORMAT);
64
49
  }
65
- var hasConflict = false;
66
- if (config.checkConflict) {
67
- var start = localeDayjs(newStart);
68
- var end = localeDayjs(newEnd);
69
- events.forEach(function (e) {
70
- if (schedulerData._getEventSlotId(e) === slotId && (!isEvent || e.id !== item.id)) {
71
- var eStart = localeDayjs(e.start);
72
- var eEnd = localeDayjs(e.end);
73
- if (start >= eStart && start < eEnd || end > eStart && end <= eEnd || eStart >= start && eStart < end || eEnd > start && eEnd <= end) hasConflict = true;
74
- }
75
- });
50
+ newEnd = localeDayjs(newStart).add(localeDayjs(event.end).diff(localeDayjs(event.start)), 'ms').format(DATETIME_FORMAT);
51
+
52
+ // if crossResourceMove disabled, slot returns old value
53
+ if (config.crossResourceMove === false) {
54
+ slotId = schedulerData._getEventSlotId(item);
55
+ slotName = undefined;
56
+ const slot = schedulerData.getSlotById(slotId);
57
+ if (slot) slotName = slot.name;
76
58
  }
77
- if (hasConflict) {
78
- var conflictOccurred = props.conflictOccurred;
79
- if (conflictOccurred !== undefined) {
80
- conflictOccurred(schedulerData, action, item, type, slotId, slotName, newStart, newEnd);
81
- } else {
82
- console.log('Conflict occurred, set conflictOccurred func in Scheduler to handle it');
83
- }
84
- } else if (isEvent) {
85
- if (moveEvent !== undefined) {
86
- moveEvent(schedulerData, item, slotId, slotName, newStart, newEnd);
59
+ action = 'Move';
60
+ }
61
+ let hasConflict = false;
62
+ if (config.checkConflict) {
63
+ const start = localeDayjs(newStart);
64
+ const end = localeDayjs(newEnd);
65
+ events.forEach(e => {
66
+ if (schedulerData._getEventSlotId(e) === slotId && (!isEvent || e.id !== item.id)) {
67
+ const eStart = localeDayjs(e.start);
68
+ const eEnd = localeDayjs(e.end);
69
+ if (start >= eStart && start < eEnd || end > eStart && end <= eEnd || eStart >= start && eStart < end || eEnd > start && eEnd <= end) hasConflict = true;
87
70
  }
88
- } else if (newEvent !== undefined) newEvent(schedulerData, slotId, slotName, newStart, newEnd, type, item);
89
- },
90
- canDrag: function canDrag(props) {
91
- var schedulerData = props.schedulerData,
92
- resourceEvents = props.resourceEvents;
93
- var item = _this.resolveDragObjFunc(props);
94
- if (schedulerData._isResizing()) return false;
95
- var config = schedulerData.config;
96
- return config.movable && (resourceEvents === undefined || !resourceEvents.groupOnly) && (item.movable === undefined || item.movable !== false);
71
+ });
97
72
  }
98
- };
73
+ if (hasConflict) {
74
+ const {
75
+ conflictOccurred
76
+ } = props;
77
+ if (conflictOccurred !== undefined) {
78
+ conflictOccurred(schedulerData, action, item, type, slotId, slotName, newStart, newEnd);
79
+ } else {
80
+ console.log('Conflict occurred, set conflictOccurred func in Scheduler to handle it');
81
+ }
82
+ } else if (isEvent) {
83
+ if (moveEvent !== undefined) {
84
+ moveEvent(schedulerData, item, slotId, slotName, newStart, newEnd);
85
+ }
86
+ } else if (newEvent !== undefined) newEvent(schedulerData, slotId, slotName, newStart, newEnd, type, item);
87
+ },
88
+ canDrag: props => {
89
+ const {
90
+ schedulerData,
91
+ resourceEvents
92
+ } = props;
93
+ const item = this.resolveDragObjFunc(props);
94
+ if (schedulerData._isResizing()) return false;
95
+ const {
96
+ config
97
+ } = schedulerData;
98
+ return config.movable && (resourceEvents === undefined || !resourceEvents.groupOnly) && (item.movable === undefined || item.movable !== false);
99
+ }
99
100
  });
101
+
100
102
  // Returns the drag specification for use with useDrag hook
101
103
  // This should be called with props from the component using the hook
102
- _defineProperty(this, "getDragOptions", function (props) {
103
- var spec = _this.getDragSpec();
104
+ getDragOptions = props => {
105
+ const spec = this.getDragSpec();
104
106
  return {
105
- type: _this.dndType,
106
- item: function item() {
107
- return spec.beginDrag(props);
108
- },
109
- end: function end(_item, monitor) {
110
- return spec.endDrag(props, monitor);
111
- },
112
- canDrag: function canDrag() {
113
- return spec.canDrag(props);
114
- },
115
- collect: function collect(monitor) {
116
- return {
117
- isDragging: monitor.isDragging()
118
- };
119
- }
107
+ type: this.dndType,
108
+ item: () => spec.beginDrag(props),
109
+ end: (_item, monitor) => spec.endDrag(props, monitor),
110
+ canDrag: () => spec.canDrag(props),
111
+ collect: monitor => ({
112
+ isDragging: monitor.isDragging()
113
+ })
120
114
  };
121
- });
122
- this.resolveDragObjFunc = resolveDragObjFunc;
123
- this.dndType = dndType;
124
- this.DnDEnabled = DnDEnabled;
125
- });
115
+ };
116
+ }