react-sync-board 0.4.2 → 0.4.5
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/dist/cjs/index.js +440 -333
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +440 -334
- package/dist/esm/index.js.map +1 -1
- package/dist/react-sync-board.min.js +3 -3
- package/dist/react-sync-board.min.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -4692,11 +4692,35 @@ var isItemInsideElement = function isItemInsideElement(itemElement, otherElem) {
|
|
|
4692
4692
|
}, rect);
|
|
4693
4693
|
});
|
|
4694
4694
|
};
|
|
4695
|
+
var getItemElem = function getItemElem(wrapper, itemId) {
|
|
4696
|
+
var elems = wrapper.getElementsByClassName("item ".concat(itemId));
|
|
4697
|
+
var elem = elems[0];
|
|
4698
|
+
|
|
4699
|
+
if (!elem) {
|
|
4700
|
+
// eslint-disable-next-line no-console
|
|
4701
|
+
console.error("Missing item ".concat(itemId));
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
return elem;
|
|
4705
|
+
};
|
|
4706
|
+
var getIdFromElem = function getIdFromElem(elem) {
|
|
4707
|
+
var _elem$dataset;
|
|
4708
|
+
|
|
4709
|
+
var value = elem === null || elem === void 0 ? void 0 : (_elem$dataset = elem.dataset) === null || _elem$dataset === void 0 ? void 0 : _elem$dataset.id;
|
|
4710
|
+
|
|
4711
|
+
if (!value) {
|
|
4712
|
+
var _elem$dataset2;
|
|
4713
|
+
|
|
4714
|
+
// eslint-disable-next-line no-console
|
|
4715
|
+
console.error("getIdFromElem call fails", elem, JSON.stringify(elem === null || elem === void 0 ? void 0 : elem.dataset), elem === null || elem === void 0 ? void 0 : (_elem$dataset2 = elem.dataset) === null || _elem$dataset2 === void 0 ? void 0 : _elem$dataset2.id);
|
|
4716
|
+
}
|
|
4717
|
+
|
|
4718
|
+
return value;
|
|
4719
|
+
};
|
|
4695
4720
|
var getItemBoundingBox = function getItemBoundingBox(items) {
|
|
4696
4721
|
var wrapper = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
|
|
4697
4722
|
var result = items.reduce(function (prev, itemId) {
|
|
4698
|
-
var
|
|
4699
|
-
var elem = elems[0];
|
|
4723
|
+
var elem = getItemElem(wrapper, itemId);
|
|
4700
4724
|
if (!elem) return null;
|
|
4701
4725
|
|
|
4702
4726
|
var _elem$getBoundingClie = elem.getBoundingClientRect(),
|
|
@@ -4782,23 +4806,53 @@ var computeDistance = function computeDistance(_ref, _ref2) {
|
|
|
4782
4806
|
|
|
4783
4807
|
var empty = function empty() {};
|
|
4784
4808
|
|
|
4785
|
-
var
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4809
|
+
var protect = function protect(fn) {
|
|
4810
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
4811
|
+
var _args = arguments;
|
|
4812
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
4813
|
+
while (1) {
|
|
4814
|
+
switch (_context.prev = _context.next) {
|
|
4815
|
+
case 0:
|
|
4816
|
+
_context.prev = 0;
|
|
4817
|
+
_context.next = 3;
|
|
4818
|
+
return fn.apply(void 0, _args);
|
|
4819
|
+
|
|
4820
|
+
case 3:
|
|
4821
|
+
_context.next = 8;
|
|
4822
|
+
break;
|
|
4823
|
+
|
|
4824
|
+
case 5:
|
|
4825
|
+
_context.prev = 5;
|
|
4826
|
+
_context.t0 = _context["catch"](0);
|
|
4827
|
+
// eslint-disable-next-line no-console
|
|
4828
|
+
console.error(_context.t0);
|
|
4829
|
+
|
|
4830
|
+
case 8:
|
|
4831
|
+
case "end":
|
|
4832
|
+
return _context.stop();
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
}, _callee, null, [[0, 5]]);
|
|
4836
|
+
}));
|
|
4837
|
+
};
|
|
4838
|
+
|
|
4839
|
+
var Gesture = function Gesture(_ref6) {
|
|
4840
|
+
var children = _ref6.children,
|
|
4841
|
+
_ref6$onDrag = _ref6.onDrag,
|
|
4842
|
+
onDrag = _ref6$onDrag === void 0 ? empty : _ref6$onDrag,
|
|
4843
|
+
_ref6$onDragStart = _ref6.onDragStart,
|
|
4844
|
+
onDragStart = _ref6$onDragStart === void 0 ? empty : _ref6$onDragStart,
|
|
4845
|
+
_ref6$onDragEnd = _ref6.onDragEnd,
|
|
4846
|
+
onDragEnd = _ref6$onDragEnd === void 0 ? empty : _ref6$onDragEnd,
|
|
4847
|
+
_ref6$onPan = _ref6.onPan,
|
|
4848
|
+
onPan = _ref6$onPan === void 0 ? empty : _ref6$onPan,
|
|
4849
|
+
_ref6$onTap = _ref6.onTap,
|
|
4850
|
+
onTap = _ref6$onTap === void 0 ? empty : _ref6$onTap,
|
|
4851
|
+
_ref6$onLongTap = _ref6.onLongTap,
|
|
4852
|
+
onLongTap = _ref6$onLongTap === void 0 ? empty : _ref6$onLongTap,
|
|
4853
|
+
_ref6$onDoubleTap = _ref6.onDoubleTap,
|
|
4854
|
+
onDoubleTap = _ref6$onDoubleTap === void 0 ? empty : _ref6$onDoubleTap,
|
|
4855
|
+
onZoom = _ref6.onZoom;
|
|
4802
4856
|
var wrapperRef = React__default['default'].useRef(null);
|
|
4803
4857
|
var stateRef = React__default['default'].useRef({
|
|
4804
4858
|
moving: false,
|
|
@@ -4807,36 +4861,36 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4807
4861
|
});
|
|
4808
4862
|
var queueRef = React__default['default'].useRef([]); // Queue event to avoid async mess
|
|
4809
4863
|
|
|
4810
|
-
var queue = React__default['default'].useCallback(function (callback) {
|
|
4811
|
-
queueRef.current.push( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
4812
|
-
return regeneratorRuntime.wrap(function
|
|
4864
|
+
var queue = React__default['default'].useCallback(function (callback, args) {
|
|
4865
|
+
queueRef.current.push( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
4866
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
4813
4867
|
while (1) {
|
|
4814
|
-
switch (
|
|
4868
|
+
switch (_context2.prev = _context2.next) {
|
|
4815
4869
|
case 0:
|
|
4816
|
-
|
|
4817
|
-
return callback();
|
|
4870
|
+
_context2.next = 2;
|
|
4871
|
+
return protect(callback)(args);
|
|
4818
4872
|
|
|
4819
4873
|
case 2:
|
|
4820
4874
|
queueRef.current.shift();
|
|
4821
4875
|
|
|
4822
4876
|
if (!(queueRef.current.length !== 0)) {
|
|
4823
|
-
|
|
4877
|
+
_context2.next = 6;
|
|
4824
4878
|
break;
|
|
4825
4879
|
}
|
|
4826
4880
|
|
|
4827
|
-
|
|
4828
|
-
return queueRef.current[0]();
|
|
4881
|
+
_context2.next = 6;
|
|
4882
|
+
return protect(queueRef.current[0])();
|
|
4829
4883
|
|
|
4830
4884
|
case 6:
|
|
4831
4885
|
case "end":
|
|
4832
|
-
return
|
|
4886
|
+
return _context2.stop();
|
|
4833
4887
|
}
|
|
4834
4888
|
}
|
|
4835
|
-
},
|
|
4889
|
+
}, _callee2);
|
|
4836
4890
|
})));
|
|
4837
4891
|
|
|
4838
4892
|
if (queueRef.current.length === 1) {
|
|
4839
|
-
queueRef.current[0]();
|
|
4893
|
+
protect(queueRef.current[0])();
|
|
4840
4894
|
}
|
|
4841
4895
|
}, []);
|
|
4842
4896
|
var onWheel = React__default['default'].useCallback(function (e) {
|
|
@@ -4861,16 +4915,14 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4861
4915
|
|
|
4862
4916
|
|
|
4863
4917
|
if (isMacOS() && !ctrlKey) {
|
|
4864
|
-
queue(
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
event: e
|
|
4873
|
-
});
|
|
4918
|
+
queue(onPan, {
|
|
4919
|
+
deltaX: -2 * deltaX,
|
|
4920
|
+
deltaY: -2 * deltaY,
|
|
4921
|
+
button: 1,
|
|
4922
|
+
ctrlKey: ctrlKey,
|
|
4923
|
+
metaKey: metaKey,
|
|
4924
|
+
target: target,
|
|
4925
|
+
event: e
|
|
4874
4926
|
});
|
|
4875
4927
|
} else {
|
|
4876
4928
|
// Quit if onZoom is not set
|
|
@@ -4892,26 +4944,24 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4892
4944
|
scale *= 2;
|
|
4893
4945
|
}
|
|
4894
4946
|
|
|
4895
|
-
queue(
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
event: e
|
|
4901
|
-
});
|
|
4947
|
+
queue(onZoom, {
|
|
4948
|
+
scale: scale,
|
|
4949
|
+
clientX: clientX,
|
|
4950
|
+
clientY: clientY,
|
|
4951
|
+
event: e
|
|
4902
4952
|
});
|
|
4903
4953
|
}
|
|
4904
4954
|
}, [onPan, onZoom, queue]);
|
|
4905
|
-
var onPointerDown = React__default['default'].useCallback(function (
|
|
4906
|
-
var target =
|
|
4907
|
-
button =
|
|
4908
|
-
clientX =
|
|
4909
|
-
clientY =
|
|
4910
|
-
pointerId =
|
|
4911
|
-
altKey =
|
|
4912
|
-
ctrlKey =
|
|
4913
|
-
metaKey =
|
|
4914
|
-
isPrimary =
|
|
4955
|
+
var onPointerDown = React__default['default'].useCallback(function (_ref8) {
|
|
4956
|
+
var target = _ref8.target,
|
|
4957
|
+
button = _ref8.button,
|
|
4958
|
+
clientX = _ref8.clientX,
|
|
4959
|
+
clientY = _ref8.clientY,
|
|
4960
|
+
pointerId = _ref8.pointerId,
|
|
4961
|
+
altKey = _ref8.altKey,
|
|
4962
|
+
ctrlKey = _ref8.ctrlKey,
|
|
4963
|
+
metaKey = _ref8.metaKey,
|
|
4964
|
+
isPrimary = _ref8.isPrimary;
|
|
4915
4965
|
// Add pointer to map
|
|
4916
4966
|
stateRef.current.pointers[pointerId] = {
|
|
4917
4967
|
clientX: clientX,
|
|
@@ -4947,6 +4997,7 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4947
4997
|
prevDistance: distance
|
|
4948
4998
|
});
|
|
4949
4999
|
} catch (e) {
|
|
5000
|
+
// eslint-disable-next-line no-console
|
|
4950
5001
|
console.log("Error while getting other pointer. Ignoring", e); // eslint-disable-next-line no-unused-expressions
|
|
4951
5002
|
|
|
4952
5003
|
stateRef.current.mainPointer === undefined;
|
|
@@ -4970,35 +5021,34 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4970
5021
|
currentButton: button,
|
|
4971
5022
|
target: target,
|
|
4972
5023
|
timeStart: Date.now(),
|
|
4973
|
-
longTapTimeout: setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
4974
|
-
return regeneratorRuntime.wrap(function
|
|
5024
|
+
longTapTimeout: setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
5025
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
4975
5026
|
while (1) {
|
|
4976
|
-
switch (
|
|
5027
|
+
switch (_context3.prev = _context3.next) {
|
|
4977
5028
|
case 0:
|
|
4978
5029
|
stateRef.current.noTap = true;
|
|
4979
|
-
queue(
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
target: target
|
|
4987
|
-
});
|
|
5030
|
+
queue(onLongTap, {
|
|
5031
|
+
clientX: clientX,
|
|
5032
|
+
clientY: clientY,
|
|
5033
|
+
altKey: altKey,
|
|
5034
|
+
ctrlKey: ctrlKey,
|
|
5035
|
+
metaKey: metaKey,
|
|
5036
|
+
target: target
|
|
4988
5037
|
});
|
|
4989
5038
|
|
|
4990
5039
|
case 2:
|
|
4991
5040
|
case "end":
|
|
4992
|
-
return
|
|
5041
|
+
return _context3.stop();
|
|
4993
5042
|
}
|
|
4994
5043
|
}
|
|
4995
|
-
},
|
|
5044
|
+
}, _callee3);
|
|
4996
5045
|
})), 750)
|
|
4997
5046
|
});
|
|
4998
5047
|
|
|
4999
5048
|
try {
|
|
5000
5049
|
target.setPointerCapture(pointerId);
|
|
5001
5050
|
} catch (e) {
|
|
5051
|
+
// eslint-disable-next-line no-console
|
|
5002
5052
|
console.log("Fail to capture pointer", e);
|
|
5003
5053
|
}
|
|
5004
5054
|
}, [onLongTap, queue]);
|
|
@@ -5058,38 +5108,13 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5058
5108
|
stateRef.current.gestureStart = true; // Clear tap timeout
|
|
5059
5109
|
|
|
5060
5110
|
clearTimeout(stateRef.current.longTapTimeout);
|
|
5061
|
-
queue(
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
deltaY: 0,
|
|
5065
|
-
startX: stateRef.current.startX,
|
|
5066
|
-
startY: stateRef.current.startY,
|
|
5067
|
-
distanceX: 0,
|
|
5068
|
-
distanceY: 0,
|
|
5069
|
-
button: stateRef.current.currentButton,
|
|
5070
|
-
altKey: altKey,
|
|
5071
|
-
ctrlKey: ctrlKey,
|
|
5072
|
-
metaKey: metaKey,
|
|
5073
|
-
target: stateRef.current.target,
|
|
5074
|
-
event: e
|
|
5075
|
-
});
|
|
5076
|
-
});
|
|
5077
|
-
} // Create closure
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
var deltaX = clientX - stateRef.current.prevX;
|
|
5081
|
-
var deltaY = clientY - stateRef.current.prevY;
|
|
5082
|
-
var distanceX = clientX - stateRef.current.startX;
|
|
5083
|
-
var distanceY = clientY - stateRef.current.startY; // Drag event
|
|
5084
|
-
|
|
5085
|
-
queue(function () {
|
|
5086
|
-
return onDrag({
|
|
5087
|
-
deltaX: deltaX,
|
|
5088
|
-
deltaY: deltaY,
|
|
5111
|
+
queue(onDragStart, {
|
|
5112
|
+
deltaX: 0,
|
|
5113
|
+
deltaY: 0,
|
|
5089
5114
|
startX: stateRef.current.startX,
|
|
5090
5115
|
startY: stateRef.current.startY,
|
|
5091
|
-
distanceX:
|
|
5092
|
-
distanceY:
|
|
5116
|
+
distanceX: 0,
|
|
5117
|
+
distanceY: 0,
|
|
5093
5118
|
button: stateRef.current.currentButton,
|
|
5094
5119
|
altKey: altKey,
|
|
5095
5120
|
ctrlKey: ctrlKey,
|
|
@@ -5097,6 +5122,27 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5097
5122
|
target: stateRef.current.target,
|
|
5098
5123
|
event: e
|
|
5099
5124
|
});
|
|
5125
|
+
} // Create closure
|
|
5126
|
+
|
|
5127
|
+
|
|
5128
|
+
var deltaX = clientX - stateRef.current.prevX;
|
|
5129
|
+
var deltaY = clientY - stateRef.current.prevY;
|
|
5130
|
+
var distanceX = clientX - stateRef.current.startX;
|
|
5131
|
+
var distanceY = clientY - stateRef.current.startY; // Drag event
|
|
5132
|
+
|
|
5133
|
+
queue(onDrag, {
|
|
5134
|
+
deltaX: deltaX,
|
|
5135
|
+
deltaY: deltaY,
|
|
5136
|
+
startX: stateRef.current.startX,
|
|
5137
|
+
startY: stateRef.current.startY,
|
|
5138
|
+
distanceX: distanceX,
|
|
5139
|
+
distanceY: distanceY,
|
|
5140
|
+
button: stateRef.current.currentButton,
|
|
5141
|
+
altKey: altKey,
|
|
5142
|
+
ctrlKey: ctrlKey,
|
|
5143
|
+
metaKey: metaKey,
|
|
5144
|
+
target: stateRef.current.target,
|
|
5145
|
+
event: e
|
|
5100
5146
|
});
|
|
5101
5147
|
} else {
|
|
5102
5148
|
if (!stateRef.current.gestureStart) {
|
|
@@ -5113,30 +5159,26 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5113
5159
|
|
|
5114
5160
|
var target = stateRef.current.target; // Pan event
|
|
5115
5161
|
|
|
5116
|
-
queue(
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
event: e
|
|
5126
|
-
});
|
|
5162
|
+
queue(onPan, {
|
|
5163
|
+
deltaX: _deltaX,
|
|
5164
|
+
deltaY: _deltaY,
|
|
5165
|
+
button: stateRef.current.currentButton,
|
|
5166
|
+
altKey: altKey,
|
|
5167
|
+
ctrlKey: ctrlKey,
|
|
5168
|
+
metaKey: metaKey,
|
|
5169
|
+
target: target,
|
|
5170
|
+
event: e
|
|
5127
5171
|
});
|
|
5128
5172
|
|
|
5129
5173
|
if (twoFingers && distance !== stateRef.current.prevDistance && onZoom) {
|
|
5130
5174
|
var scale = stateRef.current.prevDistance - distance;
|
|
5131
5175
|
|
|
5132
5176
|
if (Math.abs(scale) > 0) {
|
|
5133
|
-
queue(
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
event: e
|
|
5139
|
-
});
|
|
5177
|
+
queue(onZoom, {
|
|
5178
|
+
scale: scale,
|
|
5179
|
+
clientX: clientX,
|
|
5180
|
+
clientY: clientY,
|
|
5181
|
+
event: e
|
|
5140
5182
|
});
|
|
5141
5183
|
stateRef.current.prevDistance = distance;
|
|
5142
5184
|
}
|
|
@@ -5178,6 +5220,7 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5178
5220
|
stateRef.current.target.setPointerCapture(stateRef.current.mainPointer);
|
|
5179
5221
|
return;
|
|
5180
5222
|
} catch (error) {
|
|
5223
|
+
// eslint-disable-next-line no-console
|
|
5181
5224
|
console.log("Fails to set pointer capture", error);
|
|
5182
5225
|
stateRef.current.mainPointer = undefined;
|
|
5183
5226
|
delete stateRef.current.pointers[Object.keys(stateRef.current.pointers)[0]];
|
|
@@ -5192,20 +5235,18 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5192
5235
|
if (stateRef.current.moving) {
|
|
5193
5236
|
// If we were moving, send drag end event
|
|
5194
5237
|
stateRef.current.moving = false;
|
|
5195
|
-
queue(
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
event: e
|
|
5208
|
-
});
|
|
5238
|
+
queue(onDragEnd, {
|
|
5239
|
+
deltaX: clientX - stateRef.current.prevX,
|
|
5240
|
+
deltaY: clientY - stateRef.current.prevY,
|
|
5241
|
+
startX: stateRef.current.startX,
|
|
5242
|
+
startY: stateRef.current.startY,
|
|
5243
|
+
distanceX: clientX - stateRef.current.startX,
|
|
5244
|
+
distanceY: clientY - stateRef.current.startY,
|
|
5245
|
+
button: stateRef.current.currentButton,
|
|
5246
|
+
altKey: altKey,
|
|
5247
|
+
ctrlKey: ctrlKey,
|
|
5248
|
+
metaKey: metaKey,
|
|
5249
|
+
event: e
|
|
5209
5250
|
});
|
|
5210
5251
|
wrapperRef.current.style.cursor = "auto";
|
|
5211
5252
|
} else {
|
|
@@ -5215,22 +5256,20 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5215
5256
|
stateRef.current.noTap = false;
|
|
5216
5257
|
} // Send tap event only if time less than 300ms
|
|
5217
5258
|
else if (stateRef.current.timeStart - now < 300) {
|
|
5218
|
-
queue(
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
target: target
|
|
5226
|
-
});
|
|
5259
|
+
queue(onTap, {
|
|
5260
|
+
clientX: clientX,
|
|
5261
|
+
clientY: clientY,
|
|
5262
|
+
altKey: altKey,
|
|
5263
|
+
ctrlKey: ctrlKey,
|
|
5264
|
+
metaKey: metaKey,
|
|
5265
|
+
target: target
|
|
5227
5266
|
});
|
|
5228
5267
|
}
|
|
5229
5268
|
}
|
|
5230
5269
|
}, [onDragEnd, onTap, queue]);
|
|
5231
5270
|
var onDoubleTapHandler = React__default['default'].useCallback(function (event) {
|
|
5232
|
-
onDoubleTap
|
|
5233
|
-
}, [onDoubleTap]);
|
|
5271
|
+
queue(onDoubleTap, event);
|
|
5272
|
+
}, [onDoubleTap, queue]);
|
|
5234
5273
|
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
5235
5274
|
onWheel: onWheel,
|
|
5236
5275
|
onPointerDown: onPointerDown,
|
|
@@ -5263,22 +5302,16 @@ var findSelected = function findSelected(itemMap, wrapper) {
|
|
|
5263
5302
|
|
|
5264
5303
|
var selector = selectors[0];
|
|
5265
5304
|
return Array.from(wrapper.getElementsByClassName("item")).filter(function (elem) {
|
|
5266
|
-
var id = elem
|
|
5305
|
+
var id = getIdFromElem(elem);
|
|
5267
5306
|
var item = itemMap[id];
|
|
5268
5307
|
|
|
5269
|
-
if (!item) {
|
|
5270
|
-
// Avoid to find item that are not yet removed from DOM
|
|
5271
|
-
console.error("Missing item ".concat(id));
|
|
5272
|
-
return false;
|
|
5273
|
-
}
|
|
5274
|
-
|
|
5275
|
-
if (item.locked) {
|
|
5308
|
+
if (!item || item.locked) {
|
|
5276
5309
|
return false;
|
|
5277
5310
|
}
|
|
5278
5311
|
|
|
5279
5312
|
return isItemInsideElement(elem, selector);
|
|
5280
5313
|
}).map(function (elem) {
|
|
5281
|
-
return elem
|
|
5314
|
+
return getIdFromElem(elem);
|
|
5282
5315
|
});
|
|
5283
5316
|
};
|
|
5284
5317
|
|
|
@@ -5456,7 +5489,8 @@ var Selector = function Selector(_ref) {
|
|
|
5456
5489
|
var foundElement = insideClass(target, "item");
|
|
5457
5490
|
|
|
5458
5491
|
if (foundElement) {
|
|
5459
|
-
|
|
5492
|
+
var id = getIdFromElem(foundElement);
|
|
5493
|
+
setSelected([id]);
|
|
5460
5494
|
}
|
|
5461
5495
|
}, [setSelected]);
|
|
5462
5496
|
var onTap = recoil.useRecoilCallback(function (_ref9) {
|
|
@@ -5477,15 +5511,25 @@ var Selector = function Selector(_ref) {
|
|
|
5477
5511
|
}
|
|
5478
5512
|
|
|
5479
5513
|
setSelected([]);
|
|
5480
|
-
_context3.next =
|
|
5514
|
+
_context3.next = 14;
|
|
5481
5515
|
break;
|
|
5482
5516
|
|
|
5483
5517
|
case 6:
|
|
5484
|
-
itemId = foundItem
|
|
5485
|
-
|
|
5518
|
+
itemId = getIdFromElem(foundItem); // Being defensive here to avoid bug
|
|
5519
|
+
|
|
5520
|
+
if (itemId) {
|
|
5521
|
+
_context3.next = 10;
|
|
5522
|
+
break;
|
|
5523
|
+
}
|
|
5524
|
+
|
|
5525
|
+
setSelected([]);
|
|
5526
|
+
return _context3.abrupt("return");
|
|
5527
|
+
|
|
5528
|
+
case 10:
|
|
5529
|
+
_context3.next = 12;
|
|
5486
5530
|
return snapshot.getPromise(SelectedItemsAtom);
|
|
5487
5531
|
|
|
5488
|
-
case
|
|
5532
|
+
case 12:
|
|
5489
5533
|
selectedItems = _context3.sent;
|
|
5490
5534
|
|
|
5491
5535
|
if (foundItem && !selectedItems.includes(itemId)) {
|
|
@@ -5498,7 +5542,7 @@ var Selector = function Selector(_ref) {
|
|
|
5498
5542
|
}
|
|
5499
5543
|
}
|
|
5500
5544
|
|
|
5501
|
-
case
|
|
5545
|
+
case 14:
|
|
5502
5546
|
case "end":
|
|
5503
5547
|
return _context3.stop();
|
|
5504
5548
|
}
|
|
@@ -5577,7 +5621,7 @@ var ActionPane = function ActionPane(_ref) {
|
|
|
5577
5621
|
case 8:
|
|
5578
5622
|
selectedItems = _context.sent;
|
|
5579
5623
|
selectedItemRef.current.items = selectedItems;
|
|
5580
|
-
itemId = foundElement
|
|
5624
|
+
itemId = getIdFromElem(foundElement);
|
|
5581
5625
|
|
|
5582
5626
|
if (!selectedItems.includes(itemId)) {
|
|
5583
5627
|
if (ctrlKey || metaKey) {
|
|
@@ -5970,8 +6014,8 @@ function F(t) {
|
|
|
5970
6014
|
var _excluded$1 = ["pos"];
|
|
5971
6015
|
|
|
5972
6016
|
var _templateObject$1, _templateObject2;
|
|
5973
|
-
var StyledCursor = newStyled.div(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: row;\n align-items: center;\n z-index: 210;\n"])));
|
|
5974
|
-
var CursorName = newStyled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n color: ", ";\n font-weight: bold;\n padding: 0 0.5em;\n border-radius: 2px;\n max-width: 5em;\n overflow: hidden;\n text-overflow: ellipsis;\n margin-left: -0.5em;\n margin-top: 1.7em;\n whitespace: nowrap;\n background-color: ", ";\n"])), function (_ref) {
|
|
6017
|
+
var StyledCursor = newStyled.div(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: row;\n align-items: center;\n z-index: 210;\n pointer-events: none;\n"])));
|
|
6018
|
+
var CursorName = newStyled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n color: ", ";\n font-weight: bold;\n padding: 0 0.5em;\n border-radius: 2px;\n max-width: 5em;\n overflow: hidden;\n text-overflow: ellipsis;\n margin-left: -0.5em;\n margin-top: 1.7em;\n whitespace: nowrap;\n pointer-events: none;\n background-color: ", ";\n"])), function (_ref) {
|
|
5975
6019
|
var textColor = _ref.textColor;
|
|
5976
6020
|
return textColor;
|
|
5977
6021
|
}, function (_ref2) {
|
|
@@ -6023,7 +6067,8 @@ var PositionnedCursor = function PositionnedCursor(_ref4) {
|
|
|
6023
6067
|
top: 0,
|
|
6024
6068
|
left: 0,
|
|
6025
6069
|
zIndex: 210,
|
|
6026
|
-
position: "fixed"
|
|
6070
|
+
position: "fixed",
|
|
6071
|
+
pointerEvents: "none"
|
|
6027
6072
|
}
|
|
6028
6073
|
}, /*#__PURE__*/React__default['default'].createElement(MemoizedCursor, rest));
|
|
6029
6074
|
};
|
|
@@ -6153,6 +6198,21 @@ var usersAtom = recoil.atom({
|
|
|
6153
6198
|
key: "users",
|
|
6154
6199
|
"default": []
|
|
6155
6200
|
});
|
|
6201
|
+
var localUsersAtom = recoil.selector({
|
|
6202
|
+
key: "localUsersAtom",
|
|
6203
|
+
get: function get(_ref) {
|
|
6204
|
+
var _get = _ref.get;
|
|
6205
|
+
|
|
6206
|
+
var currentUser = _get(userAtom);
|
|
6207
|
+
|
|
6208
|
+
var users = _get(usersAtom);
|
|
6209
|
+
|
|
6210
|
+
return users.filter(function (_ref2) {
|
|
6211
|
+
var space = _ref2.space;
|
|
6212
|
+
return space === currentUser.space;
|
|
6213
|
+
});
|
|
6214
|
+
}
|
|
6215
|
+
});
|
|
6156
6216
|
|
|
6157
6217
|
var useUsers = function useUsers() {
|
|
6158
6218
|
var _useRecoilState = recoil.useRecoilState(userAtom),
|
|
@@ -6161,6 +6221,7 @@ var useUsers = function useUsers() {
|
|
|
6161
6221
|
setCurrentUserState = _useRecoilState2[1];
|
|
6162
6222
|
|
|
6163
6223
|
var users = recoil.useRecoilValue(usersAtom);
|
|
6224
|
+
var localUsers = recoil.useRecoilValue(localUsersAtom);
|
|
6164
6225
|
var setCurrentUser = React__default['default'].useCallback(function (callbackOrUser) {
|
|
6165
6226
|
var callback = callbackOrUser;
|
|
6166
6227
|
|
|
@@ -6180,12 +6241,10 @@ var useUsers = function useUsers() {
|
|
|
6180
6241
|
return newUser;
|
|
6181
6242
|
});
|
|
6182
6243
|
}, [setCurrentUserState]);
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
});
|
|
6188
|
-
}, [currentUser.space, users]);
|
|
6244
|
+
React__default['default'].useEffect(function () {
|
|
6245
|
+
// eslint-disable-next-line no-console
|
|
6246
|
+
console.debug("Curent user is in space ".concat(currentUser.space));
|
|
6247
|
+
}, [currentUser.space]);
|
|
6189
6248
|
return {
|
|
6190
6249
|
currentUser: currentUser,
|
|
6191
6250
|
setCurrentUser: setCurrentUser,
|
|
@@ -6977,10 +7036,16 @@ var useDim = function useDim() {
|
|
|
6977
7036
|
var _useRecoilValue = recoil.useRecoilValue(ConfigurationAtom),
|
|
6978
7037
|
itemExtentGlobal = _useRecoilValue.itemExtent;
|
|
6979
7038
|
|
|
6980
|
-
var
|
|
7039
|
+
var getDim = recoil.useRecoilCallback(function (_ref2) {
|
|
6981
7040
|
var snapshot = _ref2.snapshot;
|
|
7041
|
+
return function () {
|
|
7042
|
+
return snapshot.getPromise(BoardTransformAtom);
|
|
7043
|
+
};
|
|
7044
|
+
}, []);
|
|
7045
|
+
var setDimSafe = recoil.useRecoilCallback(function (_ref3) {
|
|
7046
|
+
var snapshot = _ref3.snapshot;
|
|
6982
7047
|
return /*#__PURE__*/function () {
|
|
6983
|
-
var
|
|
7048
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(fn) {
|
|
6984
7049
|
var _yield$snapshot$getPr, itemExtent, boardWrapperRect, boardSize;
|
|
6985
7050
|
|
|
6986
7051
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -7052,14 +7117,14 @@ var useDim = function useDim() {
|
|
|
7052
7117
|
}));
|
|
7053
7118
|
|
|
7054
7119
|
return function (_x) {
|
|
7055
|
-
return
|
|
7120
|
+
return _ref4.apply(this, arguments);
|
|
7056
7121
|
};
|
|
7057
7122
|
}();
|
|
7058
7123
|
}, [setDim]);
|
|
7059
|
-
var zoomTo = recoil.useRecoilCallback(function (
|
|
7060
|
-
var snapshot =
|
|
7124
|
+
var zoomTo = recoil.useRecoilCallback(function (_ref5) {
|
|
7125
|
+
var snapshot = _ref5.snapshot;
|
|
7061
7126
|
return /*#__PURE__*/function () {
|
|
7062
|
-
var
|
|
7127
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(factor, zoomCenter) {
|
|
7063
7128
|
var _yield$snapshot$getPr2, itemExtent, boardWrapperRect, boardSize, center;
|
|
7064
7129
|
|
|
7065
7130
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
@@ -7131,12 +7196,12 @@ var useDim = function useDim() {
|
|
|
7131
7196
|
}));
|
|
7132
7197
|
|
|
7133
7198
|
return function (_x2, _x3) {
|
|
7134
|
-
return
|
|
7199
|
+
return _ref6.apply(this, arguments);
|
|
7135
7200
|
};
|
|
7136
7201
|
}();
|
|
7137
7202
|
}, [setDim]);
|
|
7138
|
-
var updateScaleBoundaries = recoil.useRecoilCallback(function (
|
|
7139
|
-
var snapshot =
|
|
7203
|
+
var updateScaleBoundaries = recoil.useRecoilCallback(function (_ref7) {
|
|
7204
|
+
var snapshot = _ref7.snapshot;
|
|
7140
7205
|
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
7141
7206
|
var _yield$snapshot$getPr3, _yield$snapshot$getPr4, width, height, boardWrapperRect, scaleX, scaleY, newScale;
|
|
7142
7207
|
|
|
@@ -7166,8 +7231,8 @@ var useDim = function useDim() {
|
|
|
7166
7231
|
}, _callee3);
|
|
7167
7232
|
}));
|
|
7168
7233
|
}, []);
|
|
7169
|
-
var getCenterCoordinates = recoil.useRecoilCallback(function (
|
|
7170
|
-
var snapshot =
|
|
7234
|
+
var getCenterCoordinates = recoil.useRecoilCallback(function (_ref9) {
|
|
7235
|
+
var snapshot = _ref9.snapshot;
|
|
7171
7236
|
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
7172
7237
|
var _yield$snapshot$getPr5, boardWrapperRect, boardSize, _yield$snapshot$getPr6, translateX, translateY, scale;
|
|
7173
7238
|
|
|
@@ -7203,11 +7268,11 @@ var useDim = function useDim() {
|
|
|
7203
7268
|
}, _callee4);
|
|
7204
7269
|
}));
|
|
7205
7270
|
}, []);
|
|
7206
|
-
var updateItemExtent = recoil.useRecoilCallback(function (
|
|
7207
|
-
var snapshot =
|
|
7208
|
-
set =
|
|
7271
|
+
var updateItemExtent = recoil.useRecoilCallback(function (_ref11) {
|
|
7272
|
+
var snapshot = _ref11.snapshot,
|
|
7273
|
+
set = _ref11.set;
|
|
7209
7274
|
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
7210
|
-
var itemIds, _yield$snapshot$getPr7, boardWrapperRect, boardWrapper, boardSize, _yield$snapshot$getPr8, scale, translateX, translateY,
|
|
7275
|
+
var itemIds, _yield$snapshot$getPr7, boardWrapperRect, boardWrapper, boardSize, _yield$snapshot$getPr8, scale, translateX, translateY, _ref13, left, top, width, height, relativeExtent, delta, _delta;
|
|
7211
7276
|
|
|
7212
7277
|
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
7213
7278
|
while (1) {
|
|
@@ -7234,12 +7299,12 @@ var useDim = function useDim() {
|
|
|
7234
7299
|
scale = _yield$snapshot$getPr8.scale;
|
|
7235
7300
|
translateX = _yield$snapshot$getPr8.translateX;
|
|
7236
7301
|
translateY = _yield$snapshot$getPr8.translateY;
|
|
7237
|
-
|
|
7302
|
+
_ref13 = getItemBoundingBox(itemIds, boardWrapper) || {
|
|
7238
7303
|
left: boardSize / 2 * scale + boardWrapperRect.left + translateX,
|
|
7239
7304
|
top: boardSize / 2 * scale + boardWrapperRect.top + translateY,
|
|
7240
7305
|
width: 0,
|
|
7241
7306
|
height: 0
|
|
7242
|
-
}, left =
|
|
7307
|
+
}, left = _ref13.left, top = _ref13.top, width = _ref13.width, height = _ref13.height;
|
|
7243
7308
|
relativeExtent = {
|
|
7244
7309
|
left: (left - boardWrapperRect.left - translateX) / scale,
|
|
7245
7310
|
top: (top - boardWrapperRect.top - translateY) / scale,
|
|
@@ -7285,6 +7350,7 @@ var useDim = function useDim() {
|
|
|
7285
7350
|
}, [updateScaleBoundaries, itemExtentGlobal]);
|
|
7286
7351
|
return {
|
|
7287
7352
|
setDim: setDimSafe,
|
|
7353
|
+
getDim: getDim,
|
|
7288
7354
|
zoomTo: zoomTo,
|
|
7289
7355
|
getCenter: getCenterCoordinates,
|
|
7290
7356
|
updateItemExtent: debouncedUpdateItemExtent
|
|
@@ -7462,6 +7528,11 @@ var useItemActions = function useItemActions() {
|
|
|
7462
7528
|
|
|
7463
7529
|
itemIds.forEach(function (id) {
|
|
7464
7530
|
var item = prevItemMap[id];
|
|
7531
|
+
|
|
7532
|
+
if (!item) {
|
|
7533
|
+
return;
|
|
7534
|
+
}
|
|
7535
|
+
|
|
7465
7536
|
result[id] = _objectSpread2(_objectSpread2({}, item), {}, {
|
|
7466
7537
|
x: (item.x || 0) + posDelta.x,
|
|
7467
7538
|
y: (item.y || 0) + posDelta.y,
|
|
@@ -7498,120 +7569,155 @@ var useItemActions = function useItemActions() {
|
|
|
7498
7569
|
return result;
|
|
7499
7570
|
});
|
|
7500
7571
|
}, [setItemList, wire]);
|
|
7501
|
-
var stickOnGrid =
|
|
7502
|
-
var
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7572
|
+
var stickOnGrid = recoil.useRecoilCallback(function (_ref4) {
|
|
7573
|
+
var snapshot = _ref4.snapshot;
|
|
7574
|
+
return /*#__PURE__*/function () {
|
|
7575
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(itemIds) {
|
|
7576
|
+
var _ref6,
|
|
7577
|
+
globalType,
|
|
7578
|
+
globalSize,
|
|
7579
|
+
sync,
|
|
7580
|
+
_yield$snapshot$getPr,
|
|
7581
|
+
boardWrapper,
|
|
7582
|
+
updatedItems,
|
|
7583
|
+
_args2 = arguments;
|
|
7510
7584
|
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7585
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
7586
|
+
while (1) {
|
|
7587
|
+
switch (_context2.prev = _context2.next) {
|
|
7588
|
+
case 0:
|
|
7589
|
+
_ref6 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, globalType = _ref6.type, globalSize = _ref6.size;
|
|
7590
|
+
sync = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : true;
|
|
7591
|
+
_context2.next = 4;
|
|
7592
|
+
return snapshot.getPromise(ConfigurationAtom);
|
|
7515
7593
|
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7594
|
+
case 4:
|
|
7595
|
+
_yield$snapshot$getPr = _context2.sent;
|
|
7596
|
+
boardWrapper = _yield$snapshot$getPr.boardWrapper;
|
|
7597
|
+
updatedItems = {};
|
|
7598
|
+
setItemMap(function (prevItemMap) {
|
|
7599
|
+
var result = _objectSpread2({}, prevItemMap);
|
|
7519
7600
|
|
|
7520
|
-
|
|
7521
|
-
|
|
7601
|
+
itemIds.forEach(function (id) {
|
|
7602
|
+
var item = prevItemMap[id];
|
|
7603
|
+
var elem = getItemElem(boardWrapper, id);
|
|
7522
7604
|
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
}
|
|
7605
|
+
if (!elem) {
|
|
7606
|
+
return;
|
|
7607
|
+
}
|
|
7527
7608
|
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
var newY;
|
|
7532
|
-
var sizeX;
|
|
7533
|
-
var sizeY;
|
|
7534
|
-
var px1;
|
|
7535
|
-
var px2;
|
|
7536
|
-
var py1;
|
|
7537
|
-
var py2;
|
|
7538
|
-
var diff1;
|
|
7539
|
-
var diff2;
|
|
7540
|
-
var h = size / 1.1547;
|
|
7541
|
-
|
|
7542
|
-
switch (type) {
|
|
7543
|
-
case "grid":
|
|
7544
|
-
newX = Math.round(centerX / size) * size;
|
|
7545
|
-
newY = Math.round(centerY / size) * size;
|
|
7546
|
-
break;
|
|
7609
|
+
var _ref7 = item.grid || {},
|
|
7610
|
+
itemType = _ref7.type,
|
|
7611
|
+
itemSize = _ref7.size;
|
|
7547
7612
|
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
sizeY = 3 * size;
|
|
7551
|
-
px1 = Math.round(centerX / sizeX) * sizeX;
|
|
7552
|
-
py1 = Math.round(centerY / sizeY) * sizeY;
|
|
7553
|
-
px2 = px1 > centerX ? px1 - h : px1 + h;
|
|
7554
|
-
py2 = py1 > centerY ? py1 - 1.5 * size : py1 + 1.5 * size;
|
|
7555
|
-
diff1 = Math.hypot.apply(Math, [px1 - centerX, py1 - centerY]);
|
|
7556
|
-
diff2 = Math.hypot.apply(Math, [px2 - centerX, py2 - centerY]);
|
|
7557
|
-
|
|
7558
|
-
if (diff1 < diff2) {
|
|
7559
|
-
newX = px1;
|
|
7560
|
-
newY = py1;
|
|
7561
|
-
} else {
|
|
7562
|
-
newX = px2;
|
|
7563
|
-
newY = py2;
|
|
7564
|
-
}
|
|
7613
|
+
var type = globalType;
|
|
7614
|
+
var size = globalSize || 1; // If item specific
|
|
7565
7615
|
|
|
7566
|
-
|
|
7616
|
+
if (itemType) {
|
|
7617
|
+
type = itemType;
|
|
7618
|
+
size = itemSize || 1;
|
|
7619
|
+
}
|
|
7567
7620
|
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7621
|
+
var centerX = item.x + elem.clientWidth / 2,
|
|
7622
|
+
centerY = item.y + elem.clientHeight / 2;
|
|
7623
|
+
var newX;
|
|
7624
|
+
var newY;
|
|
7625
|
+
var sizeX;
|
|
7626
|
+
var sizeY;
|
|
7627
|
+
var px1;
|
|
7628
|
+
var px2;
|
|
7629
|
+
var py1;
|
|
7630
|
+
var py2;
|
|
7631
|
+
var diff1;
|
|
7632
|
+
var diff2;
|
|
7633
|
+
var h = size / 1.1547;
|
|
7634
|
+
|
|
7635
|
+
switch (type) {
|
|
7636
|
+
case "grid":
|
|
7637
|
+
newX = Math.round(centerX / size) * size;
|
|
7638
|
+
newY = Math.round(centerY / size) * size;
|
|
7639
|
+
break;
|
|
7640
|
+
|
|
7641
|
+
case "hexH":
|
|
7642
|
+
sizeX = 2 * h;
|
|
7643
|
+
sizeY = 3 * size;
|
|
7644
|
+
px1 = Math.round(centerX / sizeX) * sizeX;
|
|
7645
|
+
py1 = Math.round(centerY / sizeY) * sizeY;
|
|
7646
|
+
px2 = px1 > centerX ? px1 - h : px1 + h;
|
|
7647
|
+
py2 = py1 > centerY ? py1 - 1.5 * size : py1 + 1.5 * size;
|
|
7648
|
+
diff1 = Math.hypot.apply(Math, [px1 - centerX, py1 - centerY]);
|
|
7649
|
+
diff2 = Math.hypot.apply(Math, [px2 - centerX, py2 - centerY]);
|
|
7650
|
+
|
|
7651
|
+
if (diff1 < diff2) {
|
|
7652
|
+
newX = px1;
|
|
7653
|
+
newY = py1;
|
|
7654
|
+
} else {
|
|
7655
|
+
newX = px2;
|
|
7656
|
+
newY = py2;
|
|
7657
|
+
}
|
|
7658
|
+
|
|
7659
|
+
break;
|
|
7660
|
+
|
|
7661
|
+
case "hexV":
|
|
7662
|
+
sizeX = 3 * size;
|
|
7663
|
+
sizeY = 2 * h;
|
|
7664
|
+
px1 = Math.round(centerX / sizeX) * sizeX;
|
|
7665
|
+
py1 = Math.round(centerY / sizeY) * sizeY;
|
|
7666
|
+
px2 = px1 > centerX ? px1 - 1.5 * size : px1 + 1.5 * size;
|
|
7667
|
+
py2 = py1 > centerY ? py1 - h : py1 + h;
|
|
7668
|
+
diff1 = Math.hypot.apply(Math, [px1 - centerX, py1 - centerY]);
|
|
7669
|
+
diff2 = Math.hypot.apply(Math, [px2 - centerX, py2 - centerY]);
|
|
7670
|
+
|
|
7671
|
+
if (diff1 < diff2) {
|
|
7672
|
+
newX = px1;
|
|
7673
|
+
newY = py1;
|
|
7674
|
+
} else {
|
|
7675
|
+
newX = px2;
|
|
7676
|
+
newY = py2;
|
|
7677
|
+
}
|
|
7678
|
+
|
|
7679
|
+
break;
|
|
7680
|
+
|
|
7681
|
+
default:
|
|
7682
|
+
newX = item.x + elem.clientWidth / 2;
|
|
7683
|
+
newY = item.y + elem.clientHeight / 2;
|
|
7684
|
+
}
|
|
7585
7685
|
|
|
7586
|
-
|
|
7686
|
+
result[id] = _objectSpread2(_objectSpread2({}, item), {}, {
|
|
7687
|
+
x: newX - elem.clientWidth / 2,
|
|
7688
|
+
y: newY - elem.clientHeight / 2
|
|
7689
|
+
});
|
|
7690
|
+
updatedItems[id] = result[id];
|
|
7691
|
+
});
|
|
7692
|
+
return result;
|
|
7693
|
+
});
|
|
7587
7694
|
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
}
|
|
7695
|
+
if (sync) {
|
|
7696
|
+
wire.publish("batchItemsUpdate", updatedItems);
|
|
7697
|
+
}
|
|
7592
7698
|
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
});
|
|
7699
|
+
case 9:
|
|
7700
|
+
case "end":
|
|
7701
|
+
return _context2.stop();
|
|
7702
|
+
}
|
|
7703
|
+
}
|
|
7704
|
+
}, _callee2);
|
|
7705
|
+
}));
|
|
7601
7706
|
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7707
|
+
return function (_x3) {
|
|
7708
|
+
return _ref5.apply(this, arguments);
|
|
7709
|
+
};
|
|
7710
|
+
}();
|
|
7605
7711
|
}, [wire, setItemMap]);
|
|
7606
7712
|
var placeItems = React__default['default'].useCallback( /*#__PURE__*/function () {
|
|
7607
|
-
var
|
|
7713
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(itemIds, gridConfig) {
|
|
7608
7714
|
var sync,
|
|
7609
|
-
|
|
7610
|
-
return regeneratorRuntime.wrap(function
|
|
7715
|
+
_args3 = arguments;
|
|
7716
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
7611
7717
|
while (1) {
|
|
7612
|
-
switch (
|
|
7718
|
+
switch (_context3.prev = _context3.next) {
|
|
7613
7719
|
case 0:
|
|
7614
|
-
sync =
|
|
7720
|
+
sync = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : true;
|
|
7615
7721
|
// Put moved items on top
|
|
7616
7722
|
putItemsOnTop(itemIds, sync); // Remove moving state
|
|
7617
7723
|
|
|
@@ -7627,14 +7733,14 @@ var useItemActions = function useItemActions() {
|
|
|
7627
7733
|
|
|
7628
7734
|
case 6:
|
|
7629
7735
|
case "end":
|
|
7630
|
-
return
|
|
7736
|
+
return _context3.stop();
|
|
7631
7737
|
}
|
|
7632
7738
|
}
|
|
7633
|
-
},
|
|
7739
|
+
}, _callee3);
|
|
7634
7740
|
}));
|
|
7635
7741
|
|
|
7636
|
-
return function (
|
|
7637
|
-
return
|
|
7742
|
+
return function (_x4, _x5) {
|
|
7743
|
+
return _ref8.apply(this, arguments);
|
|
7638
7744
|
};
|
|
7639
7745
|
}(), [batchUpdateItems, callPlaceInteractions, putItemsOnTop, stickOnGrid, updateItemExtent]);
|
|
7640
7746
|
var updateItemOrder = React__default['default'].useCallback(function (newOrder) {
|
|
@@ -7673,27 +7779,27 @@ var useItemActions = function useItemActions() {
|
|
|
7673
7779
|
return reversed;
|
|
7674
7780
|
});
|
|
7675
7781
|
}, [setItemList, wire, setSelectItems]);
|
|
7676
|
-
var swapItems = recoil.useRecoilCallback(function (
|
|
7677
|
-
var snapshot =
|
|
7782
|
+
var swapItems = recoil.useRecoilCallback(function (_ref9) {
|
|
7783
|
+
var snapshot = _ref9.snapshot;
|
|
7678
7784
|
return /*#__PURE__*/function () {
|
|
7679
|
-
var
|
|
7785
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(fromIds, toIds) {
|
|
7680
7786
|
var sync,
|
|
7681
7787
|
itemMap,
|
|
7682
7788
|
fromItems,
|
|
7683
7789
|
toItems,
|
|
7684
7790
|
replaceMapItems,
|
|
7685
7791
|
replaceMap,
|
|
7686
|
-
|
|
7687
|
-
return regeneratorRuntime.wrap(function
|
|
7792
|
+
_args4 = arguments;
|
|
7793
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
7688
7794
|
while (1) {
|
|
7689
|
-
switch (
|
|
7795
|
+
switch (_context4.prev = _context4.next) {
|
|
7690
7796
|
case 0:
|
|
7691
|
-
sync =
|
|
7692
|
-
|
|
7797
|
+
sync = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : true;
|
|
7798
|
+
_context4.next = 3;
|
|
7693
7799
|
return snapshot.getPromise(ItemMapAtom);
|
|
7694
7800
|
|
|
7695
7801
|
case 3:
|
|
7696
|
-
itemMap =
|
|
7802
|
+
itemMap = _context4.sent;
|
|
7697
7803
|
fromItems = fromIds.map(function (id) {
|
|
7698
7804
|
return itemMap[id];
|
|
7699
7805
|
});
|
|
@@ -7748,38 +7854,38 @@ var useItemActions = function useItemActions() {
|
|
|
7748
7854
|
|
|
7749
7855
|
case 10:
|
|
7750
7856
|
case "end":
|
|
7751
|
-
return
|
|
7857
|
+
return _context4.stop();
|
|
7752
7858
|
}
|
|
7753
7859
|
}
|
|
7754
|
-
},
|
|
7860
|
+
}, _callee4);
|
|
7755
7861
|
}));
|
|
7756
7862
|
|
|
7757
|
-
return function (
|
|
7758
|
-
return
|
|
7863
|
+
return function (_x6, _x7) {
|
|
7864
|
+
return _ref10.apply(this, arguments);
|
|
7759
7865
|
};
|
|
7760
7866
|
}();
|
|
7761
7867
|
}, [wire, setItemList, setItemMap]);
|
|
7762
7868
|
var pushItems = React__default['default'].useCallback( /*#__PURE__*/function () {
|
|
7763
|
-
var
|
|
7869
|
+
var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(itemsToInsert, beforeId) {
|
|
7764
7870
|
var sync,
|
|
7765
|
-
|
|
7766
|
-
return regeneratorRuntime.wrap(function
|
|
7871
|
+
_args6 = arguments;
|
|
7872
|
+
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
7767
7873
|
while (1) {
|
|
7768
|
-
switch (
|
|
7874
|
+
switch (_context6.prev = _context6.next) {
|
|
7769
7875
|
case 0:
|
|
7770
|
-
sync =
|
|
7876
|
+
sync = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : true;
|
|
7771
7877
|
itemsToInsert.forEach( /*#__PURE__*/function () {
|
|
7772
|
-
var
|
|
7878
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(item, index) {
|
|
7773
7879
|
var center, newItem;
|
|
7774
|
-
return regeneratorRuntime.wrap(function
|
|
7880
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
7775
7881
|
while (1) {
|
|
7776
|
-
switch (
|
|
7882
|
+
switch (_context5.prev = _context5.next) {
|
|
7777
7883
|
case 0:
|
|
7778
|
-
|
|
7884
|
+
_context5.next = 2;
|
|
7779
7885
|
return getCenter();
|
|
7780
7886
|
|
|
7781
7887
|
case 2:
|
|
7782
|
-
center =
|
|
7888
|
+
center = _context5.sent;
|
|
7783
7889
|
newItem = _objectSpread2({}, item);
|
|
7784
7890
|
|
|
7785
7891
|
if (!newItem.x || !newItem.y) {
|
|
@@ -7811,28 +7917,28 @@ var useItemActions = function useItemActions() {
|
|
|
7811
7917
|
|
|
7812
7918
|
case 8:
|
|
7813
7919
|
case "end":
|
|
7814
|
-
return
|
|
7920
|
+
return _context5.stop();
|
|
7815
7921
|
}
|
|
7816
7922
|
}
|
|
7817
|
-
},
|
|
7923
|
+
}, _callee5);
|
|
7818
7924
|
}));
|
|
7819
7925
|
|
|
7820
|
-
return function (
|
|
7821
|
-
return
|
|
7926
|
+
return function (_x10, _x11) {
|
|
7927
|
+
return _ref12.apply(this, arguments);
|
|
7822
7928
|
};
|
|
7823
7929
|
}());
|
|
7824
7930
|
updateItemExtent();
|
|
7825
7931
|
|
|
7826
7932
|
case 3:
|
|
7827
7933
|
case "end":
|
|
7828
|
-
return
|
|
7934
|
+
return _context6.stop();
|
|
7829
7935
|
}
|
|
7830
7936
|
}
|
|
7831
|
-
},
|
|
7937
|
+
}, _callee6);
|
|
7832
7938
|
}));
|
|
7833
7939
|
|
|
7834
|
-
return function (
|
|
7835
|
-
return
|
|
7940
|
+
return function (_x8, _x9) {
|
|
7941
|
+
return _ref11.apply(this, arguments);
|
|
7836
7942
|
};
|
|
7837
7943
|
}(), [updateItemExtent, getCenter, setItemMap, setItemList, wire]);
|
|
7838
7944
|
var pushItem = React__default['default'].useCallback(function (itemToInsert, beforeId) {
|
|
@@ -7865,40 +7971,40 @@ var useItemActions = function useItemActions() {
|
|
|
7865
7971
|
wire.publish("removeItems", itemsIdToRemove);
|
|
7866
7972
|
}
|
|
7867
7973
|
}, [wire, setItemList, setItemMap, setSelectItems]);
|
|
7868
|
-
var getItemList = recoil.useRecoilCallback(function (
|
|
7869
|
-
var snapshot =
|
|
7974
|
+
var getItemList = recoil.useRecoilCallback(function (_ref13) {
|
|
7975
|
+
var snapshot = _ref13.snapshot;
|
|
7870
7976
|
return function () {
|
|
7871
7977
|
return snapshot.getPromise(AllItemsSelector);
|
|
7872
7978
|
};
|
|
7873
7979
|
}, []);
|
|
7874
|
-
var getItems = recoil.useRecoilCallback(function (
|
|
7875
|
-
var snapshot =
|
|
7980
|
+
var getItems = recoil.useRecoilCallback(function (_ref14) {
|
|
7981
|
+
var snapshot = _ref14.snapshot;
|
|
7876
7982
|
return /*#__PURE__*/function () {
|
|
7877
|
-
var
|
|
7983
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(itemIds) {
|
|
7878
7984
|
var itemMap;
|
|
7879
|
-
return regeneratorRuntime.wrap(function
|
|
7985
|
+
return regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
7880
7986
|
while (1) {
|
|
7881
|
-
switch (
|
|
7987
|
+
switch (_context7.prev = _context7.next) {
|
|
7882
7988
|
case 0:
|
|
7883
|
-
|
|
7989
|
+
_context7.next = 2;
|
|
7884
7990
|
return snapshot.getPromise(ItemMapAtom);
|
|
7885
7991
|
|
|
7886
7992
|
case 2:
|
|
7887
|
-
itemMap =
|
|
7888
|
-
return
|
|
7993
|
+
itemMap = _context7.sent;
|
|
7994
|
+
return _context7.abrupt("return", itemIds.map(function (id) {
|
|
7889
7995
|
return itemMap[id];
|
|
7890
7996
|
}));
|
|
7891
7997
|
|
|
7892
7998
|
case 4:
|
|
7893
7999
|
case "end":
|
|
7894
|
-
return
|
|
8000
|
+
return _context7.stop();
|
|
7895
8001
|
}
|
|
7896
8002
|
}
|
|
7897
|
-
},
|
|
8003
|
+
}, _callee7);
|
|
7898
8004
|
}));
|
|
7899
8005
|
|
|
7900
|
-
return function (
|
|
7901
|
-
return
|
|
8006
|
+
return function (_x12) {
|
|
8007
|
+
return _ref15.apply(this, arguments);
|
|
7902
8008
|
};
|
|
7903
8009
|
}();
|
|
7904
8010
|
}, []);
|
|
@@ -8845,6 +8951,7 @@ exports.BoardWrapper = ConnectedSyncBoard;
|
|
|
8845
8951
|
exports.RoomWrapper = ConnectedSyncRoom;
|
|
8846
8952
|
exports.useAvailableActions = useAvailableActions;
|
|
8847
8953
|
exports.useBoardConfig = useBoardConfig;
|
|
8954
|
+
exports.useBoardPosition = useDim;
|
|
8848
8955
|
exports.useBoardState = useBoardState;
|
|
8849
8956
|
exports.useItemActions = useItemActions;
|
|
8850
8957
|
exports.useItemInteraction = useItemInteraction;
|