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/esm/index.js
CHANGED
|
@@ -4684,11 +4684,35 @@ var isItemInsideElement = function isItemInsideElement(itemElement, otherElem) {
|
|
|
4684
4684
|
}, rect);
|
|
4685
4685
|
});
|
|
4686
4686
|
};
|
|
4687
|
+
var getItemElem = function getItemElem(wrapper, itemId) {
|
|
4688
|
+
var elems = wrapper.getElementsByClassName("item ".concat(itemId));
|
|
4689
|
+
var elem = elems[0];
|
|
4690
|
+
|
|
4691
|
+
if (!elem) {
|
|
4692
|
+
// eslint-disable-next-line no-console
|
|
4693
|
+
console.error("Missing item ".concat(itemId));
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4696
|
+
return elem;
|
|
4697
|
+
};
|
|
4698
|
+
var getIdFromElem = function getIdFromElem(elem) {
|
|
4699
|
+
var _elem$dataset;
|
|
4700
|
+
|
|
4701
|
+
var value = elem === null || elem === void 0 ? void 0 : (_elem$dataset = elem.dataset) === null || _elem$dataset === void 0 ? void 0 : _elem$dataset.id;
|
|
4702
|
+
|
|
4703
|
+
if (!value) {
|
|
4704
|
+
var _elem$dataset2;
|
|
4705
|
+
|
|
4706
|
+
// eslint-disable-next-line no-console
|
|
4707
|
+
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);
|
|
4708
|
+
}
|
|
4709
|
+
|
|
4710
|
+
return value;
|
|
4711
|
+
};
|
|
4687
4712
|
var getItemBoundingBox = function getItemBoundingBox(items) {
|
|
4688
4713
|
var wrapper = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
|
|
4689
4714
|
var result = items.reduce(function (prev, itemId) {
|
|
4690
|
-
var
|
|
4691
|
-
var elem = elems[0];
|
|
4715
|
+
var elem = getItemElem(wrapper, itemId);
|
|
4692
4716
|
if (!elem) return null;
|
|
4693
4717
|
|
|
4694
4718
|
var _elem$getBoundingClie = elem.getBoundingClientRect(),
|
|
@@ -4774,23 +4798,53 @@ var computeDistance = function computeDistance(_ref, _ref2) {
|
|
|
4774
4798
|
|
|
4775
4799
|
var empty = function empty() {};
|
|
4776
4800
|
|
|
4777
|
-
var
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4801
|
+
var protect = function protect(fn) {
|
|
4802
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
4803
|
+
var _args = arguments;
|
|
4804
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
4805
|
+
while (1) {
|
|
4806
|
+
switch (_context.prev = _context.next) {
|
|
4807
|
+
case 0:
|
|
4808
|
+
_context.prev = 0;
|
|
4809
|
+
_context.next = 3;
|
|
4810
|
+
return fn.apply(void 0, _args);
|
|
4811
|
+
|
|
4812
|
+
case 3:
|
|
4813
|
+
_context.next = 8;
|
|
4814
|
+
break;
|
|
4815
|
+
|
|
4816
|
+
case 5:
|
|
4817
|
+
_context.prev = 5;
|
|
4818
|
+
_context.t0 = _context["catch"](0);
|
|
4819
|
+
// eslint-disable-next-line no-console
|
|
4820
|
+
console.error(_context.t0);
|
|
4821
|
+
|
|
4822
|
+
case 8:
|
|
4823
|
+
case "end":
|
|
4824
|
+
return _context.stop();
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
}, _callee, null, [[0, 5]]);
|
|
4828
|
+
}));
|
|
4829
|
+
};
|
|
4830
|
+
|
|
4831
|
+
var Gesture = function Gesture(_ref6) {
|
|
4832
|
+
var children = _ref6.children,
|
|
4833
|
+
_ref6$onDrag = _ref6.onDrag,
|
|
4834
|
+
onDrag = _ref6$onDrag === void 0 ? empty : _ref6$onDrag,
|
|
4835
|
+
_ref6$onDragStart = _ref6.onDragStart,
|
|
4836
|
+
onDragStart = _ref6$onDragStart === void 0 ? empty : _ref6$onDragStart,
|
|
4837
|
+
_ref6$onDragEnd = _ref6.onDragEnd,
|
|
4838
|
+
onDragEnd = _ref6$onDragEnd === void 0 ? empty : _ref6$onDragEnd,
|
|
4839
|
+
_ref6$onPan = _ref6.onPan,
|
|
4840
|
+
onPan = _ref6$onPan === void 0 ? empty : _ref6$onPan,
|
|
4841
|
+
_ref6$onTap = _ref6.onTap,
|
|
4842
|
+
onTap = _ref6$onTap === void 0 ? empty : _ref6$onTap,
|
|
4843
|
+
_ref6$onLongTap = _ref6.onLongTap,
|
|
4844
|
+
onLongTap = _ref6$onLongTap === void 0 ? empty : _ref6$onLongTap,
|
|
4845
|
+
_ref6$onDoubleTap = _ref6.onDoubleTap,
|
|
4846
|
+
onDoubleTap = _ref6$onDoubleTap === void 0 ? empty : _ref6$onDoubleTap,
|
|
4847
|
+
onZoom = _ref6.onZoom;
|
|
4794
4848
|
var wrapperRef = React.useRef(null);
|
|
4795
4849
|
var stateRef = React.useRef({
|
|
4796
4850
|
moving: false,
|
|
@@ -4799,36 +4853,36 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4799
4853
|
});
|
|
4800
4854
|
var queueRef = React.useRef([]); // Queue event to avoid async mess
|
|
4801
4855
|
|
|
4802
|
-
var queue = React.useCallback(function (callback) {
|
|
4803
|
-
queueRef.current.push( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
4804
|
-
return regeneratorRuntime.wrap(function
|
|
4856
|
+
var queue = React.useCallback(function (callback, args) {
|
|
4857
|
+
queueRef.current.push( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
4858
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
4805
4859
|
while (1) {
|
|
4806
|
-
switch (
|
|
4860
|
+
switch (_context2.prev = _context2.next) {
|
|
4807
4861
|
case 0:
|
|
4808
|
-
|
|
4809
|
-
return callback();
|
|
4862
|
+
_context2.next = 2;
|
|
4863
|
+
return protect(callback)(args);
|
|
4810
4864
|
|
|
4811
4865
|
case 2:
|
|
4812
4866
|
queueRef.current.shift();
|
|
4813
4867
|
|
|
4814
4868
|
if (!(queueRef.current.length !== 0)) {
|
|
4815
|
-
|
|
4869
|
+
_context2.next = 6;
|
|
4816
4870
|
break;
|
|
4817
4871
|
}
|
|
4818
4872
|
|
|
4819
|
-
|
|
4820
|
-
return queueRef.current[0]();
|
|
4873
|
+
_context2.next = 6;
|
|
4874
|
+
return protect(queueRef.current[0])();
|
|
4821
4875
|
|
|
4822
4876
|
case 6:
|
|
4823
4877
|
case "end":
|
|
4824
|
-
return
|
|
4878
|
+
return _context2.stop();
|
|
4825
4879
|
}
|
|
4826
4880
|
}
|
|
4827
|
-
},
|
|
4881
|
+
}, _callee2);
|
|
4828
4882
|
})));
|
|
4829
4883
|
|
|
4830
4884
|
if (queueRef.current.length === 1) {
|
|
4831
|
-
queueRef.current[0]();
|
|
4885
|
+
protect(queueRef.current[0])();
|
|
4832
4886
|
}
|
|
4833
4887
|
}, []);
|
|
4834
4888
|
var onWheel = React.useCallback(function (e) {
|
|
@@ -4853,16 +4907,14 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4853
4907
|
|
|
4854
4908
|
|
|
4855
4909
|
if (isMacOS() && !ctrlKey) {
|
|
4856
|
-
queue(
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
event: e
|
|
4865
|
-
});
|
|
4910
|
+
queue(onPan, {
|
|
4911
|
+
deltaX: -2 * deltaX,
|
|
4912
|
+
deltaY: -2 * deltaY,
|
|
4913
|
+
button: 1,
|
|
4914
|
+
ctrlKey: ctrlKey,
|
|
4915
|
+
metaKey: metaKey,
|
|
4916
|
+
target: target,
|
|
4917
|
+
event: e
|
|
4866
4918
|
});
|
|
4867
4919
|
} else {
|
|
4868
4920
|
// Quit if onZoom is not set
|
|
@@ -4884,26 +4936,24 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4884
4936
|
scale *= 2;
|
|
4885
4937
|
}
|
|
4886
4938
|
|
|
4887
|
-
queue(
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
event: e
|
|
4893
|
-
});
|
|
4939
|
+
queue(onZoom, {
|
|
4940
|
+
scale: scale,
|
|
4941
|
+
clientX: clientX,
|
|
4942
|
+
clientY: clientY,
|
|
4943
|
+
event: e
|
|
4894
4944
|
});
|
|
4895
4945
|
}
|
|
4896
4946
|
}, [onPan, onZoom, queue]);
|
|
4897
|
-
var onPointerDown = React.useCallback(function (
|
|
4898
|
-
var target =
|
|
4899
|
-
button =
|
|
4900
|
-
clientX =
|
|
4901
|
-
clientY =
|
|
4902
|
-
pointerId =
|
|
4903
|
-
altKey =
|
|
4904
|
-
ctrlKey =
|
|
4905
|
-
metaKey =
|
|
4906
|
-
isPrimary =
|
|
4947
|
+
var onPointerDown = React.useCallback(function (_ref8) {
|
|
4948
|
+
var target = _ref8.target,
|
|
4949
|
+
button = _ref8.button,
|
|
4950
|
+
clientX = _ref8.clientX,
|
|
4951
|
+
clientY = _ref8.clientY,
|
|
4952
|
+
pointerId = _ref8.pointerId,
|
|
4953
|
+
altKey = _ref8.altKey,
|
|
4954
|
+
ctrlKey = _ref8.ctrlKey,
|
|
4955
|
+
metaKey = _ref8.metaKey,
|
|
4956
|
+
isPrimary = _ref8.isPrimary;
|
|
4907
4957
|
// Add pointer to map
|
|
4908
4958
|
stateRef.current.pointers[pointerId] = {
|
|
4909
4959
|
clientX: clientX,
|
|
@@ -4939,6 +4989,7 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4939
4989
|
prevDistance: distance
|
|
4940
4990
|
});
|
|
4941
4991
|
} catch (e) {
|
|
4992
|
+
// eslint-disable-next-line no-console
|
|
4942
4993
|
console.log("Error while getting other pointer. Ignoring", e); // eslint-disable-next-line no-unused-expressions
|
|
4943
4994
|
|
|
4944
4995
|
stateRef.current.mainPointer === undefined;
|
|
@@ -4962,35 +5013,34 @@ var Gesture = function Gesture(_ref5) {
|
|
|
4962
5013
|
currentButton: button,
|
|
4963
5014
|
target: target,
|
|
4964
5015
|
timeStart: Date.now(),
|
|
4965
|
-
longTapTimeout: setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
4966
|
-
return regeneratorRuntime.wrap(function
|
|
5016
|
+
longTapTimeout: setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
5017
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
4967
5018
|
while (1) {
|
|
4968
|
-
switch (
|
|
5019
|
+
switch (_context3.prev = _context3.next) {
|
|
4969
5020
|
case 0:
|
|
4970
5021
|
stateRef.current.noTap = true;
|
|
4971
|
-
queue(
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
target: target
|
|
4979
|
-
});
|
|
5022
|
+
queue(onLongTap, {
|
|
5023
|
+
clientX: clientX,
|
|
5024
|
+
clientY: clientY,
|
|
5025
|
+
altKey: altKey,
|
|
5026
|
+
ctrlKey: ctrlKey,
|
|
5027
|
+
metaKey: metaKey,
|
|
5028
|
+
target: target
|
|
4980
5029
|
});
|
|
4981
5030
|
|
|
4982
5031
|
case 2:
|
|
4983
5032
|
case "end":
|
|
4984
|
-
return
|
|
5033
|
+
return _context3.stop();
|
|
4985
5034
|
}
|
|
4986
5035
|
}
|
|
4987
|
-
},
|
|
5036
|
+
}, _callee3);
|
|
4988
5037
|
})), 750)
|
|
4989
5038
|
});
|
|
4990
5039
|
|
|
4991
5040
|
try {
|
|
4992
5041
|
target.setPointerCapture(pointerId);
|
|
4993
5042
|
} catch (e) {
|
|
5043
|
+
// eslint-disable-next-line no-console
|
|
4994
5044
|
console.log("Fail to capture pointer", e);
|
|
4995
5045
|
}
|
|
4996
5046
|
}, [onLongTap, queue]);
|
|
@@ -5050,38 +5100,13 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5050
5100
|
stateRef.current.gestureStart = true; // Clear tap timeout
|
|
5051
5101
|
|
|
5052
5102
|
clearTimeout(stateRef.current.longTapTimeout);
|
|
5053
|
-
queue(
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
deltaY: 0,
|
|
5057
|
-
startX: stateRef.current.startX,
|
|
5058
|
-
startY: stateRef.current.startY,
|
|
5059
|
-
distanceX: 0,
|
|
5060
|
-
distanceY: 0,
|
|
5061
|
-
button: stateRef.current.currentButton,
|
|
5062
|
-
altKey: altKey,
|
|
5063
|
-
ctrlKey: ctrlKey,
|
|
5064
|
-
metaKey: metaKey,
|
|
5065
|
-
target: stateRef.current.target,
|
|
5066
|
-
event: e
|
|
5067
|
-
});
|
|
5068
|
-
});
|
|
5069
|
-
} // Create closure
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
var deltaX = clientX - stateRef.current.prevX;
|
|
5073
|
-
var deltaY = clientY - stateRef.current.prevY;
|
|
5074
|
-
var distanceX = clientX - stateRef.current.startX;
|
|
5075
|
-
var distanceY = clientY - stateRef.current.startY; // Drag event
|
|
5076
|
-
|
|
5077
|
-
queue(function () {
|
|
5078
|
-
return onDrag({
|
|
5079
|
-
deltaX: deltaX,
|
|
5080
|
-
deltaY: deltaY,
|
|
5103
|
+
queue(onDragStart, {
|
|
5104
|
+
deltaX: 0,
|
|
5105
|
+
deltaY: 0,
|
|
5081
5106
|
startX: stateRef.current.startX,
|
|
5082
5107
|
startY: stateRef.current.startY,
|
|
5083
|
-
distanceX:
|
|
5084
|
-
distanceY:
|
|
5108
|
+
distanceX: 0,
|
|
5109
|
+
distanceY: 0,
|
|
5085
5110
|
button: stateRef.current.currentButton,
|
|
5086
5111
|
altKey: altKey,
|
|
5087
5112
|
ctrlKey: ctrlKey,
|
|
@@ -5089,6 +5114,27 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5089
5114
|
target: stateRef.current.target,
|
|
5090
5115
|
event: e
|
|
5091
5116
|
});
|
|
5117
|
+
} // Create closure
|
|
5118
|
+
|
|
5119
|
+
|
|
5120
|
+
var deltaX = clientX - stateRef.current.prevX;
|
|
5121
|
+
var deltaY = clientY - stateRef.current.prevY;
|
|
5122
|
+
var distanceX = clientX - stateRef.current.startX;
|
|
5123
|
+
var distanceY = clientY - stateRef.current.startY; // Drag event
|
|
5124
|
+
|
|
5125
|
+
queue(onDrag, {
|
|
5126
|
+
deltaX: deltaX,
|
|
5127
|
+
deltaY: deltaY,
|
|
5128
|
+
startX: stateRef.current.startX,
|
|
5129
|
+
startY: stateRef.current.startY,
|
|
5130
|
+
distanceX: distanceX,
|
|
5131
|
+
distanceY: distanceY,
|
|
5132
|
+
button: stateRef.current.currentButton,
|
|
5133
|
+
altKey: altKey,
|
|
5134
|
+
ctrlKey: ctrlKey,
|
|
5135
|
+
metaKey: metaKey,
|
|
5136
|
+
target: stateRef.current.target,
|
|
5137
|
+
event: e
|
|
5092
5138
|
});
|
|
5093
5139
|
} else {
|
|
5094
5140
|
if (!stateRef.current.gestureStart) {
|
|
@@ -5105,30 +5151,26 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5105
5151
|
|
|
5106
5152
|
var target = stateRef.current.target; // Pan event
|
|
5107
5153
|
|
|
5108
|
-
queue(
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
event: e
|
|
5118
|
-
});
|
|
5154
|
+
queue(onPan, {
|
|
5155
|
+
deltaX: _deltaX,
|
|
5156
|
+
deltaY: _deltaY,
|
|
5157
|
+
button: stateRef.current.currentButton,
|
|
5158
|
+
altKey: altKey,
|
|
5159
|
+
ctrlKey: ctrlKey,
|
|
5160
|
+
metaKey: metaKey,
|
|
5161
|
+
target: target,
|
|
5162
|
+
event: e
|
|
5119
5163
|
});
|
|
5120
5164
|
|
|
5121
5165
|
if (twoFingers && distance !== stateRef.current.prevDistance && onZoom) {
|
|
5122
5166
|
var scale = stateRef.current.prevDistance - distance;
|
|
5123
5167
|
|
|
5124
5168
|
if (Math.abs(scale) > 0) {
|
|
5125
|
-
queue(
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
event: e
|
|
5131
|
-
});
|
|
5169
|
+
queue(onZoom, {
|
|
5170
|
+
scale: scale,
|
|
5171
|
+
clientX: clientX,
|
|
5172
|
+
clientY: clientY,
|
|
5173
|
+
event: e
|
|
5132
5174
|
});
|
|
5133
5175
|
stateRef.current.prevDistance = distance;
|
|
5134
5176
|
}
|
|
@@ -5170,6 +5212,7 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5170
5212
|
stateRef.current.target.setPointerCapture(stateRef.current.mainPointer);
|
|
5171
5213
|
return;
|
|
5172
5214
|
} catch (error) {
|
|
5215
|
+
// eslint-disable-next-line no-console
|
|
5173
5216
|
console.log("Fails to set pointer capture", error);
|
|
5174
5217
|
stateRef.current.mainPointer = undefined;
|
|
5175
5218
|
delete stateRef.current.pointers[Object.keys(stateRef.current.pointers)[0]];
|
|
@@ -5184,20 +5227,18 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5184
5227
|
if (stateRef.current.moving) {
|
|
5185
5228
|
// If we were moving, send drag end event
|
|
5186
5229
|
stateRef.current.moving = false;
|
|
5187
|
-
queue(
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
event: e
|
|
5200
|
-
});
|
|
5230
|
+
queue(onDragEnd, {
|
|
5231
|
+
deltaX: clientX - stateRef.current.prevX,
|
|
5232
|
+
deltaY: clientY - stateRef.current.prevY,
|
|
5233
|
+
startX: stateRef.current.startX,
|
|
5234
|
+
startY: stateRef.current.startY,
|
|
5235
|
+
distanceX: clientX - stateRef.current.startX,
|
|
5236
|
+
distanceY: clientY - stateRef.current.startY,
|
|
5237
|
+
button: stateRef.current.currentButton,
|
|
5238
|
+
altKey: altKey,
|
|
5239
|
+
ctrlKey: ctrlKey,
|
|
5240
|
+
metaKey: metaKey,
|
|
5241
|
+
event: e
|
|
5201
5242
|
});
|
|
5202
5243
|
wrapperRef.current.style.cursor = "auto";
|
|
5203
5244
|
} else {
|
|
@@ -5207,22 +5248,20 @@ var Gesture = function Gesture(_ref5) {
|
|
|
5207
5248
|
stateRef.current.noTap = false;
|
|
5208
5249
|
} // Send tap event only if time less than 300ms
|
|
5209
5250
|
else if (stateRef.current.timeStart - now < 300) {
|
|
5210
|
-
queue(
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
target: target
|
|
5218
|
-
});
|
|
5251
|
+
queue(onTap, {
|
|
5252
|
+
clientX: clientX,
|
|
5253
|
+
clientY: clientY,
|
|
5254
|
+
altKey: altKey,
|
|
5255
|
+
ctrlKey: ctrlKey,
|
|
5256
|
+
metaKey: metaKey,
|
|
5257
|
+
target: target
|
|
5219
5258
|
});
|
|
5220
5259
|
}
|
|
5221
5260
|
}
|
|
5222
5261
|
}, [onDragEnd, onTap, queue]);
|
|
5223
5262
|
var onDoubleTapHandler = React.useCallback(function (event) {
|
|
5224
|
-
onDoubleTap
|
|
5225
|
-
}, [onDoubleTap]);
|
|
5263
|
+
queue(onDoubleTap, event);
|
|
5264
|
+
}, [onDoubleTap, queue]);
|
|
5226
5265
|
return /*#__PURE__*/React.createElement("div", {
|
|
5227
5266
|
onWheel: onWheel,
|
|
5228
5267
|
onPointerDown: onPointerDown,
|
|
@@ -5255,22 +5294,16 @@ var findSelected = function findSelected(itemMap, wrapper) {
|
|
|
5255
5294
|
|
|
5256
5295
|
var selector = selectors[0];
|
|
5257
5296
|
return Array.from(wrapper.getElementsByClassName("item")).filter(function (elem) {
|
|
5258
|
-
var id = elem
|
|
5297
|
+
var id = getIdFromElem(elem);
|
|
5259
5298
|
var item = itemMap[id];
|
|
5260
5299
|
|
|
5261
|
-
if (!item) {
|
|
5262
|
-
// Avoid to find item that are not yet removed from DOM
|
|
5263
|
-
console.error("Missing item ".concat(id));
|
|
5264
|
-
return false;
|
|
5265
|
-
}
|
|
5266
|
-
|
|
5267
|
-
if (item.locked) {
|
|
5300
|
+
if (!item || item.locked) {
|
|
5268
5301
|
return false;
|
|
5269
5302
|
}
|
|
5270
5303
|
|
|
5271
5304
|
return isItemInsideElement(elem, selector);
|
|
5272
5305
|
}).map(function (elem) {
|
|
5273
|
-
return elem
|
|
5306
|
+
return getIdFromElem(elem);
|
|
5274
5307
|
});
|
|
5275
5308
|
};
|
|
5276
5309
|
|
|
@@ -5448,7 +5481,8 @@ var Selector = function Selector(_ref) {
|
|
|
5448
5481
|
var foundElement = insideClass(target, "item");
|
|
5449
5482
|
|
|
5450
5483
|
if (foundElement) {
|
|
5451
|
-
|
|
5484
|
+
var id = getIdFromElem(foundElement);
|
|
5485
|
+
setSelected([id]);
|
|
5452
5486
|
}
|
|
5453
5487
|
}, [setSelected]);
|
|
5454
5488
|
var onTap = useRecoilCallback(function (_ref9) {
|
|
@@ -5469,15 +5503,25 @@ var Selector = function Selector(_ref) {
|
|
|
5469
5503
|
}
|
|
5470
5504
|
|
|
5471
5505
|
setSelected([]);
|
|
5472
|
-
_context3.next =
|
|
5506
|
+
_context3.next = 14;
|
|
5473
5507
|
break;
|
|
5474
5508
|
|
|
5475
5509
|
case 6:
|
|
5476
|
-
itemId = foundItem
|
|
5477
|
-
|
|
5510
|
+
itemId = getIdFromElem(foundItem); // Being defensive here to avoid bug
|
|
5511
|
+
|
|
5512
|
+
if (itemId) {
|
|
5513
|
+
_context3.next = 10;
|
|
5514
|
+
break;
|
|
5515
|
+
}
|
|
5516
|
+
|
|
5517
|
+
setSelected([]);
|
|
5518
|
+
return _context3.abrupt("return");
|
|
5519
|
+
|
|
5520
|
+
case 10:
|
|
5521
|
+
_context3.next = 12;
|
|
5478
5522
|
return snapshot.getPromise(SelectedItemsAtom);
|
|
5479
5523
|
|
|
5480
|
-
case
|
|
5524
|
+
case 12:
|
|
5481
5525
|
selectedItems = _context3.sent;
|
|
5482
5526
|
|
|
5483
5527
|
if (foundItem && !selectedItems.includes(itemId)) {
|
|
@@ -5490,7 +5534,7 @@ var Selector = function Selector(_ref) {
|
|
|
5490
5534
|
}
|
|
5491
5535
|
}
|
|
5492
5536
|
|
|
5493
|
-
case
|
|
5537
|
+
case 14:
|
|
5494
5538
|
case "end":
|
|
5495
5539
|
return _context3.stop();
|
|
5496
5540
|
}
|
|
@@ -5569,7 +5613,7 @@ var ActionPane = function ActionPane(_ref) {
|
|
|
5569
5613
|
case 8:
|
|
5570
5614
|
selectedItems = _context.sent;
|
|
5571
5615
|
selectedItemRef.current.items = selectedItems;
|
|
5572
|
-
itemId = foundElement
|
|
5616
|
+
itemId = getIdFromElem(foundElement);
|
|
5573
5617
|
|
|
5574
5618
|
if (!selectedItems.includes(itemId)) {
|
|
5575
5619
|
if (ctrlKey || metaKey) {
|
|
@@ -5962,8 +6006,8 @@ function F(t) {
|
|
|
5962
6006
|
var _excluded$1 = ["pos"];
|
|
5963
6007
|
|
|
5964
6008
|
var _templateObject$1, _templateObject2;
|
|
5965
|
-
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"])));
|
|
5966
|
-
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) {
|
|
6009
|
+
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"])));
|
|
6010
|
+
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) {
|
|
5967
6011
|
var textColor = _ref.textColor;
|
|
5968
6012
|
return textColor;
|
|
5969
6013
|
}, function (_ref2) {
|
|
@@ -6015,7 +6059,8 @@ var PositionnedCursor = function PositionnedCursor(_ref4) {
|
|
|
6015
6059
|
top: 0,
|
|
6016
6060
|
left: 0,
|
|
6017
6061
|
zIndex: 210,
|
|
6018
|
-
position: "fixed"
|
|
6062
|
+
position: "fixed",
|
|
6063
|
+
pointerEvents: "none"
|
|
6019
6064
|
}
|
|
6020
6065
|
}, /*#__PURE__*/React.createElement(MemoizedCursor, rest));
|
|
6021
6066
|
};
|
|
@@ -6145,6 +6190,21 @@ var usersAtom = atom({
|
|
|
6145
6190
|
key: "users",
|
|
6146
6191
|
"default": []
|
|
6147
6192
|
});
|
|
6193
|
+
var localUsersAtom = selector({
|
|
6194
|
+
key: "localUsersAtom",
|
|
6195
|
+
get: function get(_ref) {
|
|
6196
|
+
var _get = _ref.get;
|
|
6197
|
+
|
|
6198
|
+
var currentUser = _get(userAtom);
|
|
6199
|
+
|
|
6200
|
+
var users = _get(usersAtom);
|
|
6201
|
+
|
|
6202
|
+
return users.filter(function (_ref2) {
|
|
6203
|
+
var space = _ref2.space;
|
|
6204
|
+
return space === currentUser.space;
|
|
6205
|
+
});
|
|
6206
|
+
}
|
|
6207
|
+
});
|
|
6148
6208
|
|
|
6149
6209
|
var useUsers = function useUsers() {
|
|
6150
6210
|
var _useRecoilState = useRecoilState(userAtom),
|
|
@@ -6153,6 +6213,7 @@ var useUsers = function useUsers() {
|
|
|
6153
6213
|
setCurrentUserState = _useRecoilState2[1];
|
|
6154
6214
|
|
|
6155
6215
|
var users = useRecoilValue(usersAtom);
|
|
6216
|
+
var localUsers = useRecoilValue(localUsersAtom);
|
|
6156
6217
|
var setCurrentUser = React.useCallback(function (callbackOrUser) {
|
|
6157
6218
|
var callback = callbackOrUser;
|
|
6158
6219
|
|
|
@@ -6172,12 +6233,10 @@ var useUsers = function useUsers() {
|
|
|
6172
6233
|
return newUser;
|
|
6173
6234
|
});
|
|
6174
6235
|
}, [setCurrentUserState]);
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
});
|
|
6180
|
-
}, [currentUser.space, users]);
|
|
6236
|
+
React.useEffect(function () {
|
|
6237
|
+
// eslint-disable-next-line no-console
|
|
6238
|
+
console.debug("Curent user is in space ".concat(currentUser.space));
|
|
6239
|
+
}, [currentUser.space]);
|
|
6181
6240
|
return {
|
|
6182
6241
|
currentUser: currentUser,
|
|
6183
6242
|
setCurrentUser: setCurrentUser,
|
|
@@ -6969,10 +7028,16 @@ var useDim = function useDim() {
|
|
|
6969
7028
|
var _useRecoilValue = useRecoilValue(ConfigurationAtom),
|
|
6970
7029
|
itemExtentGlobal = _useRecoilValue.itemExtent;
|
|
6971
7030
|
|
|
6972
|
-
var
|
|
7031
|
+
var getDim = useRecoilCallback(function (_ref2) {
|
|
6973
7032
|
var snapshot = _ref2.snapshot;
|
|
7033
|
+
return function () {
|
|
7034
|
+
return snapshot.getPromise(BoardTransformAtom);
|
|
7035
|
+
};
|
|
7036
|
+
}, []);
|
|
7037
|
+
var setDimSafe = useRecoilCallback(function (_ref3) {
|
|
7038
|
+
var snapshot = _ref3.snapshot;
|
|
6974
7039
|
return /*#__PURE__*/function () {
|
|
6975
|
-
var
|
|
7040
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(fn) {
|
|
6976
7041
|
var _yield$snapshot$getPr, itemExtent, boardWrapperRect, boardSize;
|
|
6977
7042
|
|
|
6978
7043
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -7044,14 +7109,14 @@ var useDim = function useDim() {
|
|
|
7044
7109
|
}));
|
|
7045
7110
|
|
|
7046
7111
|
return function (_x) {
|
|
7047
|
-
return
|
|
7112
|
+
return _ref4.apply(this, arguments);
|
|
7048
7113
|
};
|
|
7049
7114
|
}();
|
|
7050
7115
|
}, [setDim]);
|
|
7051
|
-
var zoomTo = useRecoilCallback(function (
|
|
7052
|
-
var snapshot =
|
|
7116
|
+
var zoomTo = useRecoilCallback(function (_ref5) {
|
|
7117
|
+
var snapshot = _ref5.snapshot;
|
|
7053
7118
|
return /*#__PURE__*/function () {
|
|
7054
|
-
var
|
|
7119
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(factor, zoomCenter) {
|
|
7055
7120
|
var _yield$snapshot$getPr2, itemExtent, boardWrapperRect, boardSize, center;
|
|
7056
7121
|
|
|
7057
7122
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
@@ -7123,12 +7188,12 @@ var useDim = function useDim() {
|
|
|
7123
7188
|
}));
|
|
7124
7189
|
|
|
7125
7190
|
return function (_x2, _x3) {
|
|
7126
|
-
return
|
|
7191
|
+
return _ref6.apply(this, arguments);
|
|
7127
7192
|
};
|
|
7128
7193
|
}();
|
|
7129
7194
|
}, [setDim]);
|
|
7130
|
-
var updateScaleBoundaries = useRecoilCallback(function (
|
|
7131
|
-
var snapshot =
|
|
7195
|
+
var updateScaleBoundaries = useRecoilCallback(function (_ref7) {
|
|
7196
|
+
var snapshot = _ref7.snapshot;
|
|
7132
7197
|
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
7133
7198
|
var _yield$snapshot$getPr3, _yield$snapshot$getPr4, width, height, boardWrapperRect, scaleX, scaleY, newScale;
|
|
7134
7199
|
|
|
@@ -7158,8 +7223,8 @@ var useDim = function useDim() {
|
|
|
7158
7223
|
}, _callee3);
|
|
7159
7224
|
}));
|
|
7160
7225
|
}, []);
|
|
7161
|
-
var getCenterCoordinates = useRecoilCallback(function (
|
|
7162
|
-
var snapshot =
|
|
7226
|
+
var getCenterCoordinates = useRecoilCallback(function (_ref9) {
|
|
7227
|
+
var snapshot = _ref9.snapshot;
|
|
7163
7228
|
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
7164
7229
|
var _yield$snapshot$getPr5, boardWrapperRect, boardSize, _yield$snapshot$getPr6, translateX, translateY, scale;
|
|
7165
7230
|
|
|
@@ -7195,11 +7260,11 @@ var useDim = function useDim() {
|
|
|
7195
7260
|
}, _callee4);
|
|
7196
7261
|
}));
|
|
7197
7262
|
}, []);
|
|
7198
|
-
var updateItemExtent = useRecoilCallback(function (
|
|
7199
|
-
var snapshot =
|
|
7200
|
-
set =
|
|
7263
|
+
var updateItemExtent = useRecoilCallback(function (_ref11) {
|
|
7264
|
+
var snapshot = _ref11.snapshot,
|
|
7265
|
+
set = _ref11.set;
|
|
7201
7266
|
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
7202
|
-
var itemIds, _yield$snapshot$getPr7, boardWrapperRect, boardWrapper, boardSize, _yield$snapshot$getPr8, scale, translateX, translateY,
|
|
7267
|
+
var itemIds, _yield$snapshot$getPr7, boardWrapperRect, boardWrapper, boardSize, _yield$snapshot$getPr8, scale, translateX, translateY, _ref13, left, top, width, height, relativeExtent, delta, _delta;
|
|
7203
7268
|
|
|
7204
7269
|
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
7205
7270
|
while (1) {
|
|
@@ -7226,12 +7291,12 @@ var useDim = function useDim() {
|
|
|
7226
7291
|
scale = _yield$snapshot$getPr8.scale;
|
|
7227
7292
|
translateX = _yield$snapshot$getPr8.translateX;
|
|
7228
7293
|
translateY = _yield$snapshot$getPr8.translateY;
|
|
7229
|
-
|
|
7294
|
+
_ref13 = getItemBoundingBox(itemIds, boardWrapper) || {
|
|
7230
7295
|
left: boardSize / 2 * scale + boardWrapperRect.left + translateX,
|
|
7231
7296
|
top: boardSize / 2 * scale + boardWrapperRect.top + translateY,
|
|
7232
7297
|
width: 0,
|
|
7233
7298
|
height: 0
|
|
7234
|
-
}, left =
|
|
7299
|
+
}, left = _ref13.left, top = _ref13.top, width = _ref13.width, height = _ref13.height;
|
|
7235
7300
|
relativeExtent = {
|
|
7236
7301
|
left: (left - boardWrapperRect.left - translateX) / scale,
|
|
7237
7302
|
top: (top - boardWrapperRect.top - translateY) / scale,
|
|
@@ -7277,6 +7342,7 @@ var useDim = function useDim() {
|
|
|
7277
7342
|
}, [updateScaleBoundaries, itemExtentGlobal]);
|
|
7278
7343
|
return {
|
|
7279
7344
|
setDim: setDimSafe,
|
|
7345
|
+
getDim: getDim,
|
|
7280
7346
|
zoomTo: zoomTo,
|
|
7281
7347
|
getCenter: getCenterCoordinates,
|
|
7282
7348
|
updateItemExtent: debouncedUpdateItemExtent
|
|
@@ -7454,6 +7520,11 @@ var useItemActions = function useItemActions() {
|
|
|
7454
7520
|
|
|
7455
7521
|
itemIds.forEach(function (id) {
|
|
7456
7522
|
var item = prevItemMap[id];
|
|
7523
|
+
|
|
7524
|
+
if (!item) {
|
|
7525
|
+
return;
|
|
7526
|
+
}
|
|
7527
|
+
|
|
7457
7528
|
result[id] = _objectSpread2(_objectSpread2({}, item), {}, {
|
|
7458
7529
|
x: (item.x || 0) + posDelta.x,
|
|
7459
7530
|
y: (item.y || 0) + posDelta.y,
|
|
@@ -7490,120 +7561,155 @@ var useItemActions = function useItemActions() {
|
|
|
7490
7561
|
return result;
|
|
7491
7562
|
});
|
|
7492
7563
|
}, [setItemList, wire]);
|
|
7493
|
-
var stickOnGrid =
|
|
7494
|
-
var
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7564
|
+
var stickOnGrid = useRecoilCallback(function (_ref4) {
|
|
7565
|
+
var snapshot = _ref4.snapshot;
|
|
7566
|
+
return /*#__PURE__*/function () {
|
|
7567
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(itemIds) {
|
|
7568
|
+
var _ref6,
|
|
7569
|
+
globalType,
|
|
7570
|
+
globalSize,
|
|
7571
|
+
sync,
|
|
7572
|
+
_yield$snapshot$getPr,
|
|
7573
|
+
boardWrapper,
|
|
7574
|
+
updatedItems,
|
|
7575
|
+
_args2 = arguments;
|
|
7502
7576
|
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7577
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
7578
|
+
while (1) {
|
|
7579
|
+
switch (_context2.prev = _context2.next) {
|
|
7580
|
+
case 0:
|
|
7581
|
+
_ref6 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, globalType = _ref6.type, globalSize = _ref6.size;
|
|
7582
|
+
sync = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : true;
|
|
7583
|
+
_context2.next = 4;
|
|
7584
|
+
return snapshot.getPromise(ConfigurationAtom);
|
|
7507
7585
|
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7586
|
+
case 4:
|
|
7587
|
+
_yield$snapshot$getPr = _context2.sent;
|
|
7588
|
+
boardWrapper = _yield$snapshot$getPr.boardWrapper;
|
|
7589
|
+
updatedItems = {};
|
|
7590
|
+
setItemMap(function (prevItemMap) {
|
|
7591
|
+
var result = _objectSpread2({}, prevItemMap);
|
|
7511
7592
|
|
|
7512
|
-
|
|
7513
|
-
|
|
7593
|
+
itemIds.forEach(function (id) {
|
|
7594
|
+
var item = prevItemMap[id];
|
|
7595
|
+
var elem = getItemElem(boardWrapper, id);
|
|
7514
7596
|
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
}
|
|
7597
|
+
if (!elem) {
|
|
7598
|
+
return;
|
|
7599
|
+
}
|
|
7519
7600
|
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
var newY;
|
|
7524
|
-
var sizeX;
|
|
7525
|
-
var sizeY;
|
|
7526
|
-
var px1;
|
|
7527
|
-
var px2;
|
|
7528
|
-
var py1;
|
|
7529
|
-
var py2;
|
|
7530
|
-
var diff1;
|
|
7531
|
-
var diff2;
|
|
7532
|
-
var h = size / 1.1547;
|
|
7533
|
-
|
|
7534
|
-
switch (type) {
|
|
7535
|
-
case "grid":
|
|
7536
|
-
newX = Math.round(centerX / size) * size;
|
|
7537
|
-
newY = Math.round(centerY / size) * size;
|
|
7538
|
-
break;
|
|
7601
|
+
var _ref7 = item.grid || {},
|
|
7602
|
+
itemType = _ref7.type,
|
|
7603
|
+
itemSize = _ref7.size;
|
|
7539
7604
|
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
sizeY = 3 * size;
|
|
7543
|
-
px1 = Math.round(centerX / sizeX) * sizeX;
|
|
7544
|
-
py1 = Math.round(centerY / sizeY) * sizeY;
|
|
7545
|
-
px2 = px1 > centerX ? px1 - h : px1 + h;
|
|
7546
|
-
py2 = py1 > centerY ? py1 - 1.5 * size : py1 + 1.5 * size;
|
|
7547
|
-
diff1 = Math.hypot.apply(Math, [px1 - centerX, py1 - centerY]);
|
|
7548
|
-
diff2 = Math.hypot.apply(Math, [px2 - centerX, py2 - centerY]);
|
|
7549
|
-
|
|
7550
|
-
if (diff1 < diff2) {
|
|
7551
|
-
newX = px1;
|
|
7552
|
-
newY = py1;
|
|
7553
|
-
} else {
|
|
7554
|
-
newX = px2;
|
|
7555
|
-
newY = py2;
|
|
7556
|
-
}
|
|
7605
|
+
var type = globalType;
|
|
7606
|
+
var size = globalSize || 1; // If item specific
|
|
7557
7607
|
|
|
7558
|
-
|
|
7608
|
+
if (itemType) {
|
|
7609
|
+
type = itemType;
|
|
7610
|
+
size = itemSize || 1;
|
|
7611
|
+
}
|
|
7559
7612
|
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7613
|
+
var centerX = item.x + elem.clientWidth / 2,
|
|
7614
|
+
centerY = item.y + elem.clientHeight / 2;
|
|
7615
|
+
var newX;
|
|
7616
|
+
var newY;
|
|
7617
|
+
var sizeX;
|
|
7618
|
+
var sizeY;
|
|
7619
|
+
var px1;
|
|
7620
|
+
var px2;
|
|
7621
|
+
var py1;
|
|
7622
|
+
var py2;
|
|
7623
|
+
var diff1;
|
|
7624
|
+
var diff2;
|
|
7625
|
+
var h = size / 1.1547;
|
|
7626
|
+
|
|
7627
|
+
switch (type) {
|
|
7628
|
+
case "grid":
|
|
7629
|
+
newX = Math.round(centerX / size) * size;
|
|
7630
|
+
newY = Math.round(centerY / size) * size;
|
|
7631
|
+
break;
|
|
7632
|
+
|
|
7633
|
+
case "hexH":
|
|
7634
|
+
sizeX = 2 * h;
|
|
7635
|
+
sizeY = 3 * size;
|
|
7636
|
+
px1 = Math.round(centerX / sizeX) * sizeX;
|
|
7637
|
+
py1 = Math.round(centerY / sizeY) * sizeY;
|
|
7638
|
+
px2 = px1 > centerX ? px1 - h : px1 + h;
|
|
7639
|
+
py2 = py1 > centerY ? py1 - 1.5 * size : py1 + 1.5 * size;
|
|
7640
|
+
diff1 = Math.hypot.apply(Math, [px1 - centerX, py1 - centerY]);
|
|
7641
|
+
diff2 = Math.hypot.apply(Math, [px2 - centerX, py2 - centerY]);
|
|
7642
|
+
|
|
7643
|
+
if (diff1 < diff2) {
|
|
7644
|
+
newX = px1;
|
|
7645
|
+
newY = py1;
|
|
7646
|
+
} else {
|
|
7647
|
+
newX = px2;
|
|
7648
|
+
newY = py2;
|
|
7649
|
+
}
|
|
7650
|
+
|
|
7651
|
+
break;
|
|
7652
|
+
|
|
7653
|
+
case "hexV":
|
|
7654
|
+
sizeX = 3 * size;
|
|
7655
|
+
sizeY = 2 * h;
|
|
7656
|
+
px1 = Math.round(centerX / sizeX) * sizeX;
|
|
7657
|
+
py1 = Math.round(centerY / sizeY) * sizeY;
|
|
7658
|
+
px2 = px1 > centerX ? px1 - 1.5 * size : px1 + 1.5 * size;
|
|
7659
|
+
py2 = py1 > centerY ? py1 - h : py1 + h;
|
|
7660
|
+
diff1 = Math.hypot.apply(Math, [px1 - centerX, py1 - centerY]);
|
|
7661
|
+
diff2 = Math.hypot.apply(Math, [px2 - centerX, py2 - centerY]);
|
|
7662
|
+
|
|
7663
|
+
if (diff1 < diff2) {
|
|
7664
|
+
newX = px1;
|
|
7665
|
+
newY = py1;
|
|
7666
|
+
} else {
|
|
7667
|
+
newX = px2;
|
|
7668
|
+
newY = py2;
|
|
7669
|
+
}
|
|
7670
|
+
|
|
7671
|
+
break;
|
|
7672
|
+
|
|
7673
|
+
default:
|
|
7674
|
+
newX = item.x + elem.clientWidth / 2;
|
|
7675
|
+
newY = item.y + elem.clientHeight / 2;
|
|
7676
|
+
}
|
|
7577
7677
|
|
|
7578
|
-
|
|
7678
|
+
result[id] = _objectSpread2(_objectSpread2({}, item), {}, {
|
|
7679
|
+
x: newX - elem.clientWidth / 2,
|
|
7680
|
+
y: newY - elem.clientHeight / 2
|
|
7681
|
+
});
|
|
7682
|
+
updatedItems[id] = result[id];
|
|
7683
|
+
});
|
|
7684
|
+
return result;
|
|
7685
|
+
});
|
|
7579
7686
|
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
}
|
|
7687
|
+
if (sync) {
|
|
7688
|
+
wire.publish("batchItemsUpdate", updatedItems);
|
|
7689
|
+
}
|
|
7584
7690
|
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
});
|
|
7691
|
+
case 9:
|
|
7692
|
+
case "end":
|
|
7693
|
+
return _context2.stop();
|
|
7694
|
+
}
|
|
7695
|
+
}
|
|
7696
|
+
}, _callee2);
|
|
7697
|
+
}));
|
|
7593
7698
|
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7699
|
+
return function (_x3) {
|
|
7700
|
+
return _ref5.apply(this, arguments);
|
|
7701
|
+
};
|
|
7702
|
+
}();
|
|
7597
7703
|
}, [wire, setItemMap]);
|
|
7598
7704
|
var placeItems = React.useCallback( /*#__PURE__*/function () {
|
|
7599
|
-
var
|
|
7705
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(itemIds, gridConfig) {
|
|
7600
7706
|
var sync,
|
|
7601
|
-
|
|
7602
|
-
return regeneratorRuntime.wrap(function
|
|
7707
|
+
_args3 = arguments;
|
|
7708
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
7603
7709
|
while (1) {
|
|
7604
|
-
switch (
|
|
7710
|
+
switch (_context3.prev = _context3.next) {
|
|
7605
7711
|
case 0:
|
|
7606
|
-
sync =
|
|
7712
|
+
sync = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : true;
|
|
7607
7713
|
// Put moved items on top
|
|
7608
7714
|
putItemsOnTop(itemIds, sync); // Remove moving state
|
|
7609
7715
|
|
|
@@ -7619,14 +7725,14 @@ var useItemActions = function useItemActions() {
|
|
|
7619
7725
|
|
|
7620
7726
|
case 6:
|
|
7621
7727
|
case "end":
|
|
7622
|
-
return
|
|
7728
|
+
return _context3.stop();
|
|
7623
7729
|
}
|
|
7624
7730
|
}
|
|
7625
|
-
},
|
|
7731
|
+
}, _callee3);
|
|
7626
7732
|
}));
|
|
7627
7733
|
|
|
7628
|
-
return function (
|
|
7629
|
-
return
|
|
7734
|
+
return function (_x4, _x5) {
|
|
7735
|
+
return _ref8.apply(this, arguments);
|
|
7630
7736
|
};
|
|
7631
7737
|
}(), [batchUpdateItems, callPlaceInteractions, putItemsOnTop, stickOnGrid, updateItemExtent]);
|
|
7632
7738
|
var updateItemOrder = React.useCallback(function (newOrder) {
|
|
@@ -7665,27 +7771,27 @@ var useItemActions = function useItemActions() {
|
|
|
7665
7771
|
return reversed;
|
|
7666
7772
|
});
|
|
7667
7773
|
}, [setItemList, wire, setSelectItems]);
|
|
7668
|
-
var swapItems = useRecoilCallback(function (
|
|
7669
|
-
var snapshot =
|
|
7774
|
+
var swapItems = useRecoilCallback(function (_ref9) {
|
|
7775
|
+
var snapshot = _ref9.snapshot;
|
|
7670
7776
|
return /*#__PURE__*/function () {
|
|
7671
|
-
var
|
|
7777
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(fromIds, toIds) {
|
|
7672
7778
|
var sync,
|
|
7673
7779
|
itemMap,
|
|
7674
7780
|
fromItems,
|
|
7675
7781
|
toItems,
|
|
7676
7782
|
replaceMapItems,
|
|
7677
7783
|
replaceMap,
|
|
7678
|
-
|
|
7679
|
-
return regeneratorRuntime.wrap(function
|
|
7784
|
+
_args4 = arguments;
|
|
7785
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
7680
7786
|
while (1) {
|
|
7681
|
-
switch (
|
|
7787
|
+
switch (_context4.prev = _context4.next) {
|
|
7682
7788
|
case 0:
|
|
7683
|
-
sync =
|
|
7684
|
-
|
|
7789
|
+
sync = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : true;
|
|
7790
|
+
_context4.next = 3;
|
|
7685
7791
|
return snapshot.getPromise(ItemMapAtom);
|
|
7686
7792
|
|
|
7687
7793
|
case 3:
|
|
7688
|
-
itemMap =
|
|
7794
|
+
itemMap = _context4.sent;
|
|
7689
7795
|
fromItems = fromIds.map(function (id) {
|
|
7690
7796
|
return itemMap[id];
|
|
7691
7797
|
});
|
|
@@ -7740,38 +7846,38 @@ var useItemActions = function useItemActions() {
|
|
|
7740
7846
|
|
|
7741
7847
|
case 10:
|
|
7742
7848
|
case "end":
|
|
7743
|
-
return
|
|
7849
|
+
return _context4.stop();
|
|
7744
7850
|
}
|
|
7745
7851
|
}
|
|
7746
|
-
},
|
|
7852
|
+
}, _callee4);
|
|
7747
7853
|
}));
|
|
7748
7854
|
|
|
7749
|
-
return function (
|
|
7750
|
-
return
|
|
7855
|
+
return function (_x6, _x7) {
|
|
7856
|
+
return _ref10.apply(this, arguments);
|
|
7751
7857
|
};
|
|
7752
7858
|
}();
|
|
7753
7859
|
}, [wire, setItemList, setItemMap]);
|
|
7754
7860
|
var pushItems = React.useCallback( /*#__PURE__*/function () {
|
|
7755
|
-
var
|
|
7861
|
+
var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(itemsToInsert, beforeId) {
|
|
7756
7862
|
var sync,
|
|
7757
|
-
|
|
7758
|
-
return regeneratorRuntime.wrap(function
|
|
7863
|
+
_args6 = arguments;
|
|
7864
|
+
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
7759
7865
|
while (1) {
|
|
7760
|
-
switch (
|
|
7866
|
+
switch (_context6.prev = _context6.next) {
|
|
7761
7867
|
case 0:
|
|
7762
|
-
sync =
|
|
7868
|
+
sync = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : true;
|
|
7763
7869
|
itemsToInsert.forEach( /*#__PURE__*/function () {
|
|
7764
|
-
var
|
|
7870
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(item, index) {
|
|
7765
7871
|
var center, newItem;
|
|
7766
|
-
return regeneratorRuntime.wrap(function
|
|
7872
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
7767
7873
|
while (1) {
|
|
7768
|
-
switch (
|
|
7874
|
+
switch (_context5.prev = _context5.next) {
|
|
7769
7875
|
case 0:
|
|
7770
|
-
|
|
7876
|
+
_context5.next = 2;
|
|
7771
7877
|
return getCenter();
|
|
7772
7878
|
|
|
7773
7879
|
case 2:
|
|
7774
|
-
center =
|
|
7880
|
+
center = _context5.sent;
|
|
7775
7881
|
newItem = _objectSpread2({}, item);
|
|
7776
7882
|
|
|
7777
7883
|
if (!newItem.x || !newItem.y) {
|
|
@@ -7803,28 +7909,28 @@ var useItemActions = function useItemActions() {
|
|
|
7803
7909
|
|
|
7804
7910
|
case 8:
|
|
7805
7911
|
case "end":
|
|
7806
|
-
return
|
|
7912
|
+
return _context5.stop();
|
|
7807
7913
|
}
|
|
7808
7914
|
}
|
|
7809
|
-
},
|
|
7915
|
+
}, _callee5);
|
|
7810
7916
|
}));
|
|
7811
7917
|
|
|
7812
|
-
return function (
|
|
7813
|
-
return
|
|
7918
|
+
return function (_x10, _x11) {
|
|
7919
|
+
return _ref12.apply(this, arguments);
|
|
7814
7920
|
};
|
|
7815
7921
|
}());
|
|
7816
7922
|
updateItemExtent();
|
|
7817
7923
|
|
|
7818
7924
|
case 3:
|
|
7819
7925
|
case "end":
|
|
7820
|
-
return
|
|
7926
|
+
return _context6.stop();
|
|
7821
7927
|
}
|
|
7822
7928
|
}
|
|
7823
|
-
},
|
|
7929
|
+
}, _callee6);
|
|
7824
7930
|
}));
|
|
7825
7931
|
|
|
7826
|
-
return function (
|
|
7827
|
-
return
|
|
7932
|
+
return function (_x8, _x9) {
|
|
7933
|
+
return _ref11.apply(this, arguments);
|
|
7828
7934
|
};
|
|
7829
7935
|
}(), [updateItemExtent, getCenter, setItemMap, setItemList, wire]);
|
|
7830
7936
|
var pushItem = React.useCallback(function (itemToInsert, beforeId) {
|
|
@@ -7857,40 +7963,40 @@ var useItemActions = function useItemActions() {
|
|
|
7857
7963
|
wire.publish("removeItems", itemsIdToRemove);
|
|
7858
7964
|
}
|
|
7859
7965
|
}, [wire, setItemList, setItemMap, setSelectItems]);
|
|
7860
|
-
var getItemList = useRecoilCallback(function (
|
|
7861
|
-
var snapshot =
|
|
7966
|
+
var getItemList = useRecoilCallback(function (_ref13) {
|
|
7967
|
+
var snapshot = _ref13.snapshot;
|
|
7862
7968
|
return function () {
|
|
7863
7969
|
return snapshot.getPromise(AllItemsSelector);
|
|
7864
7970
|
};
|
|
7865
7971
|
}, []);
|
|
7866
|
-
var getItems = useRecoilCallback(function (
|
|
7867
|
-
var snapshot =
|
|
7972
|
+
var getItems = useRecoilCallback(function (_ref14) {
|
|
7973
|
+
var snapshot = _ref14.snapshot;
|
|
7868
7974
|
return /*#__PURE__*/function () {
|
|
7869
|
-
var
|
|
7975
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(itemIds) {
|
|
7870
7976
|
var itemMap;
|
|
7871
|
-
return regeneratorRuntime.wrap(function
|
|
7977
|
+
return regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
7872
7978
|
while (1) {
|
|
7873
|
-
switch (
|
|
7979
|
+
switch (_context7.prev = _context7.next) {
|
|
7874
7980
|
case 0:
|
|
7875
|
-
|
|
7981
|
+
_context7.next = 2;
|
|
7876
7982
|
return snapshot.getPromise(ItemMapAtom);
|
|
7877
7983
|
|
|
7878
7984
|
case 2:
|
|
7879
|
-
itemMap =
|
|
7880
|
-
return
|
|
7985
|
+
itemMap = _context7.sent;
|
|
7986
|
+
return _context7.abrupt("return", itemIds.map(function (id) {
|
|
7881
7987
|
return itemMap[id];
|
|
7882
7988
|
}));
|
|
7883
7989
|
|
|
7884
7990
|
case 4:
|
|
7885
7991
|
case "end":
|
|
7886
|
-
return
|
|
7992
|
+
return _context7.stop();
|
|
7887
7993
|
}
|
|
7888
7994
|
}
|
|
7889
|
-
},
|
|
7995
|
+
}, _callee7);
|
|
7890
7996
|
}));
|
|
7891
7997
|
|
|
7892
|
-
return function (
|
|
7893
|
-
return
|
|
7998
|
+
return function (_x12) {
|
|
7999
|
+
return _ref15.apply(this, arguments);
|
|
7894
8000
|
};
|
|
7895
8001
|
}();
|
|
7896
8002
|
}, []);
|
|
@@ -8832,5 +8938,5 @@ var ConnectedSyncRoom = function ConnectedSyncRoom(_ref) {
|
|
|
8832
8938
|
}, /*#__PURE__*/React.createElement(SubscribeUserEvents, null), children));
|
|
8833
8939
|
};
|
|
8834
8940
|
|
|
8835
|
-
export { Board, ConnectedSyncBoard as BoardWrapper, ConnectedSyncRoom as RoomWrapper, useAvailableActions, useBoardConfig, useBoardState, useItemActions, useItemInteraction, useItemList as useItems, useMessage, useSelectedItems, useSelectionBox, useUsers, useWire };
|
|
8941
|
+
export { Board, ConnectedSyncBoard as BoardWrapper, ConnectedSyncRoom as RoomWrapper, useAvailableActions, useBoardConfig, useDim as useBoardPosition, useBoardState, useItemActions, useItemInteraction, useItemList as useItems, useMessage, useSelectedItems, useSelectionBox, useUsers, useWire };
|
|
8836
8942
|
//# sourceMappingURL=index.js.map
|