react-sync-board 0.3.3 → 0.3.4

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/esm/index.js CHANGED
@@ -4689,7 +4689,7 @@ var es6 = function equal(a, b) {
4689
4689
 
4690
4690
  var img = "data:image/svg+xml,%3c%3fxml version='1.0' encoding='UTF-8' standalone='no'%3f%3e%3csvg xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:cc='http://creativecommons.org/ns%23' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape' version='1.1' x='0px' y='0px' viewBox='0 0 75.601318 94.9' xml:space='preserve' id='svg26' sodipodi:docname='lock.svg' width='75.601318' height='94.900002' inkscape:version='0.92.5 (2060ec1f9f%2c 2020-04-08)'%3e%3cmetadata id='metadata32'%3e%3crdf:RDF%3e%3ccc:Work rdf:about=''%3e%3cdc:format%3eimage/svg%2bxml%3c/dc:format%3e%3cdc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage' /%3e%3cdc:title%3e%3c/dc:title%3e%3c/cc:Work%3e%3c/rdf:RDF%3e%3c/metadata%3e%3cdefs id='defs30' /%3e%3csodipodi:namedview pagecolor='black' bordercolor='%23666666' borderopacity='1' objecttolerance='10' gridtolerance='10' guidetolerance='10' inkscape:pageopacity='0' inkscape:pageshadow='2' inkscape:window-width='1848' inkscape:window-height='1016' id='namedview28' showgrid='false' fit-margin-top='0' fit-margin-left='0' fit-margin-right='0' fit-margin-bottom='0' inkscape:zoom='5.3400704' inkscape:cx='3.2640013' inkscape:cy='45.072152' inkscape:window-x='1512' inkscape:window-y='27' inkscape:window-maximized='1' inkscape:current-layer='g16' /%3e%3cg id='g16' transform='translate(-12.2%2c-2.5)'%3e%3cpath d='M 75.4%2c36.8 H 34.1 V 24.6 c 0%2c-8.8 7.1%2c-15.9 15.9%2c-15.9 8.8%2c0 15.9%2c7.1 15.9%2c15.9 0%2c1.7 1.4%2c3.1 3.1%2c3.1 1.7%2c0 3.1%2c-1.4 3.1%2c-3.1 C 72.1%2c12.4 62.2%2c2.5 50%2c2.5 37.8%2c2.5 27.9%2c12.4 27.9%2c24.6 v 12.2 h -3.3 c -6.9%2c0 -12.4%2c5.6 -12.4%2c12.4 V 85 c 0%2c6.9 5.6%2c12.4 12.4%2c12.4 h 50.8 c 6.9%2c0 12.4%2c-5.6 12.4%2c-12.4 V 49.2 C 87.9%2c42.3 82.3%2c36.8 75.4%2c36.8 Z m 6.2%2c48.3 c 0%2c3.4 -2.8%2c6.2 -6.2%2c6.2 H 24.6 c -3.4%2c0 -6.2%2c-2.8 -6.2%2c-6.2 V 49.2 c 0%2c-3.4 2.8%2c-6.2 6.2%2c-6.2 h 50.8 c 3.4%2c0 6.2%2c2.8 6.2%2c6.2 z' id='path12' inkscape:connector-curvature='0' style='fill:white%3bfill-opacity:1' /%3e%3cpath d='m 59.8%2c57.6 -12.5%2c12.5 -7%2c-7 c -1.2%2c-1.2 -3.2%2c-1.2 -4.4%2c0 -1.2%2c1.2 -1.2%2c3.2 0%2c4.4 l 9.2%2c9.2 c 0.6%2c0.6 1.4%2c0.9 2.2%2c0.9 0.8%2c0 1.6%2c-0.3 2.2%2c-0.9 L 64.2%2c62 c 1.2%2c-1.2 1.2%2c-3.2 0%2c-4.4 -1.2%2c-1.2 -3.2%2c-1.2 -4.4%2c0 z' id='path14' inkscape:connector-curvature='0' style='fill:white%3bfill-opacity:1' /%3e%3c/g%3e%3c/svg%3e";
4691
4691
 
4692
- var _excluded$1 = ["type", "rotation", "id", "locked", "layer"],
4692
+ var _excluded$2 = ["type", "rotation", "id", "locked", "layer"],
4693
4693
  _excluded2 = ["x", "y", "layer", "moving"],
4694
4694
  _excluded3 = ["state"];
4695
4695
 
@@ -4699,23 +4699,101 @@ var ItemWrapper = newStyled.div(_templateObject$2 || (_templateObject$2 = _tagge
4699
4699
  return rotation;
4700
4700
  }, img);
4701
4701
 
4702
- var Item = function Item(_ref2) {
4703
- var setState = _ref2.setState,
4704
- _ref2$state = _ref2.state;
4705
- _ref2$state = _ref2$state === void 0 ? {} : _ref2$state;
4706
-
4707
- var type = _ref2$state.type,
4708
- _ref2$state$rotation = _ref2$state.rotation,
4709
- rotation = _ref2$state$rotation === void 0 ? 0 : _ref2$state$rotation,
4710
- id = _ref2$state.id,
4711
- locked = _ref2$state.locked,
4712
- layer = _ref2$state.layer,
4713
- rest = _objectWithoutProperties(_ref2$state, _excluded$1),
4714
- _ref2$animate = _ref2.animate,
4715
- animate = _ref2$animate === void 0 ? "hvr-pop" : _ref2$animate,
4716
- isSelected = _ref2.isSelected,
4717
- itemMap = _ref2.itemMap,
4718
- unlocked = _ref2.unlocked;
4702
+ var DefaultErrorComponent = function DefaultErrorComponent(_ref2) {
4703
+ var onReload = _ref2.onReload;
4704
+ return /*#__PURE__*/React.createElement("div", {
4705
+ style: {
4706
+ width: "100px",
4707
+ display: "flex",
4708
+ flexDirection: "column",
4709
+ justifyContent: "center",
4710
+ textAlign: "center",
4711
+ color: "red"
4712
+ },
4713
+ className: "syncboard-error-item"
4714
+ }, "Sorry, this item seems broken.", /*#__PURE__*/React.createElement("button", {
4715
+ onClick: onReload
4716
+ }, "Reload it"));
4717
+ };
4718
+ /* Error boundary for broken item */
4719
+
4720
+
4721
+ var ItemErrorBoundary = /*#__PURE__*/function (_React$Component) {
4722
+ _inherits(ItemErrorBoundary, _React$Component);
4723
+
4724
+ var _super = _createSuper(ItemErrorBoundary);
4725
+
4726
+ function ItemErrorBoundary(props) {
4727
+ var _this;
4728
+
4729
+ _classCallCheck(this, ItemErrorBoundary);
4730
+
4731
+ _this = _super.call(this, props);
4732
+ _this.state = {
4733
+ hasError: false,
4734
+ itemId: props.itemId
4735
+ };
4736
+ _this.onReload = _this.onReload.bind(_assertThisInitialized(_this));
4737
+ return _this;
4738
+ }
4739
+
4740
+ _createClass(ItemErrorBoundary, [{
4741
+ key: "componentDidCatch",
4742
+ value: function componentDidCatch(error) {
4743
+ // eslint-disable-next-line no-console
4744
+ console.log("Error for item ".concat(this.state.itemId), error, this.props.state);
4745
+ }
4746
+ }, {
4747
+ key: "onReload",
4748
+ value: function onReload() {
4749
+ this.setState({
4750
+ hasError: false
4751
+ });
4752
+ }
4753
+ }, {
4754
+ key: "render",
4755
+ value: function render() {
4756
+ var ErrorComponent = this.props.ErrorComponent;
4757
+
4758
+ if (this.state.hasError) {
4759
+ return /*#__PURE__*/React.createElement(ErrorComponent, {
4760
+ onReload: this.onReload
4761
+ });
4762
+ }
4763
+
4764
+ return this.props.children;
4765
+ }
4766
+ }], [{
4767
+ key: "getDerivedStateFromError",
4768
+ value: function getDerivedStateFromError() {
4769
+ return {
4770
+ hasError: true
4771
+ };
4772
+ }
4773
+ }]);
4774
+
4775
+ return ItemErrorBoundary;
4776
+ }(React.Component);
4777
+
4778
+ var Item = function Item(_ref3) {
4779
+ var _itemMap$error;
4780
+
4781
+ var setState = _ref3.setState,
4782
+ _ref3$state = _ref3.state;
4783
+ _ref3$state = _ref3$state === void 0 ? {} : _ref3$state;
4784
+
4785
+ var type = _ref3$state.type,
4786
+ _ref3$state$rotation = _ref3$state.rotation,
4787
+ rotation = _ref3$state$rotation === void 0 ? 0 : _ref3$state$rotation,
4788
+ id = _ref3$state.id,
4789
+ locked = _ref3$state.locked,
4790
+ layer = _ref3$state.layer,
4791
+ rest = _objectWithoutProperties(_ref3$state, _excluded$2),
4792
+ _ref3$animate = _ref3.animate,
4793
+ animate = _ref3$animate === void 0 ? "hvr-pop" : _ref3$animate,
4794
+ isSelected = _ref3.isSelected,
4795
+ itemMap = _ref3.itemMap,
4796
+ unlocked = _ref3.unlocked;
4719
4797
 
4720
4798
  var isMountedRef = React.useRef(false);
4721
4799
  var animateRef = React.useRef(null);
@@ -4765,10 +4843,15 @@ var Item = function Item(_ref2) {
4765
4843
  onKeyUp: function onKeyUp(e) {
4766
4844
  return e.stopPropagation();
4767
4845
  }
4846
+ }, /*#__PURE__*/React.createElement(ItemErrorBoundary, {
4847
+ itemId: id,
4848
+ state: rest,
4849
+ setState: updateState,
4850
+ ErrorComponent: (itemMap === null || itemMap === void 0 ? void 0 : (_itemMap$error = itemMap.error) === null || _itemMap$error === void 0 ? void 0 : _itemMap$error.component) || DefaultErrorComponent
4768
4851
  }, /*#__PURE__*/React.createElement(Component, _extends$1({}, rest, {
4769
4852
  id: id,
4770
4853
  setState: updateState
4771
- })), /*#__PURE__*/React.createElement("div", {
4854
+ }))), /*#__PURE__*/React.createElement("div", {
4772
4855
  className: "corner top-left"
4773
4856
  }), /*#__PURE__*/React.createElement("div", {
4774
4857
  className: "corner top-right"
@@ -4779,30 +4862,30 @@ var Item = function Item(_ref2) {
4779
4862
  })));
4780
4863
  };
4781
4864
 
4782
- var MemoizedItem = /*#__PURE__*/memo(Item, function (_ref3, _ref4) {
4783
- var prevState = _ref3.state,
4784
- prevSetState = _ref3.setState,
4785
- prevIsSelected = _ref3.isSelected,
4786
- prevUnlocked = _ref3.unlocked;
4787
- var nextState = _ref4.state,
4788
- nextSetState = _ref4.setState,
4789
- nextIsSelected = _ref4.isSelected,
4790
- nextUnlocked = _ref4.unlocked;
4865
+ var MemoizedItem = /*#__PURE__*/memo(Item, function (_ref4, _ref5) {
4866
+ var prevState = _ref4.state,
4867
+ prevSetState = _ref4.setState,
4868
+ prevIsSelected = _ref4.isSelected,
4869
+ prevUnlocked = _ref4.unlocked;
4870
+ var nextState = _ref5.state,
4871
+ nextSetState = _ref5.setState,
4872
+ nextIsSelected = _ref5.isSelected,
4873
+ nextUnlocked = _ref5.unlocked;
4791
4874
  return prevIsSelected === nextIsSelected && prevUnlocked === nextUnlocked && prevSetState === nextSetState && JSON.stringify(prevState) === JSON.stringify(nextState);
4792
4875
  }); // Exclude positionning from memoization
4793
4876
 
4794
- var PositionedItem = function PositionedItem(_ref5) {
4795
- var _ref5$state = _ref5.state;
4796
- _ref5$state = _ref5$state === void 0 ? {} : _ref5$state;
4877
+ var PositionedItem = function PositionedItem(_ref6) {
4878
+ var _ref6$state = _ref6.state;
4879
+ _ref6$state = _ref6$state === void 0 ? {} : _ref6$state;
4797
4880
 
4798
- var _ref5$state$x = _ref5$state.x,
4799
- x = _ref5$state$x === void 0 ? 0 : _ref5$state$x,
4800
- _ref5$state$y = _ref5$state.y,
4801
- y = _ref5$state$y === void 0 ? 0 : _ref5$state$y,
4802
- layer = _ref5$state.layer,
4803
- moving = _ref5$state.moving,
4804
- stateRest = _objectWithoutProperties(_ref5$state, _excluded2),
4805
- rest = _objectWithoutProperties(_ref5, _excluded3);
4881
+ var _ref6$state$x = _ref6$state.x,
4882
+ x = _ref6$state$x === void 0 ? 0 : _ref6$state$x,
4883
+ _ref6$state$y = _ref6$state.y,
4884
+ y = _ref6$state$y === void 0 ? 0 : _ref6$state$y,
4885
+ layer = _ref6$state.layer,
4886
+ moving = _ref6$state.moving,
4887
+ stateRest = _objectWithoutProperties(_ref6$state, _excluded2),
4888
+ rest = _objectWithoutProperties(_ref6, _excluded3);
4806
4889
 
4807
4890
  return /*#__PURE__*/React.createElement("div", {
4808
4891
  style: {
@@ -5992,7 +6075,7 @@ var Selector = function Selector(_ref) {
5992
6075
  var stateRef = React.useRef({
5993
6076
  moving: false
5994
6077
  });
5995
- var config = useRecoilValue(BoardConfigAtom); // Reset selection on game loading
6078
+ var config = useRecoilValue(BoardConfigAtom); // Reset selection on board loading
5996
6079
 
5997
6080
  React.useEffect(function () {
5998
6081
  setSelected(emptySelection);
@@ -6652,32 +6735,26 @@ function F(t) {
6652
6735
  return w(t) > .179;
6653
6736
  }
6654
6737
 
6738
+ var _excluded$1 = ["pos"];
6739
+
6655
6740
  var _templateObject$1, _templateObject2;
6656
- var StyledCursor = newStyled.div(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n top: 0;\n left: 0;\n transform: ", ";\n position: fixed;\n display: flex;\n flex-direction: row;\n align-items: center;\n z-index: 210;\n"])), function (_ref) {
6657
- var top = _ref.top,
6658
- left = _ref.left;
6659
- return "translate(".concat(left, "px, ").concat(top, "px)");
6660
- });
6661
- 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 (_ref2) {
6662
- var textColor = _ref2.textColor;
6741
+ 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"])));
6742
+ 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) {
6743
+ var textColor = _ref.textColor;
6663
6744
  return textColor;
6664
- }, function (_ref3) {
6665
- var color = _ref3.color;
6745
+ }, function (_ref2) {
6746
+ var color = _ref2.color;
6666
6747
  return color;
6667
6748
  });
6668
6749
 
6669
- var Cursor = function Cursor(_ref4) {
6670
- var _ref4$color = _ref4.color,
6671
- color = _ref4$color === void 0 ? "#666" : _ref4$color,
6672
- _ref4$size = _ref4.size,
6673
- size = _ref4$size === void 0 ? 40 : _ref4$size,
6674
- pos = _ref4.pos,
6675
- text = _ref4.text;
6750
+ var Cursor = function Cursor(_ref3) {
6751
+ var _ref3$color = _ref3.color,
6752
+ color = _ref3$color === void 0 ? "#666" : _ref3$color,
6753
+ _ref3$size = _ref3.size,
6754
+ size = _ref3$size === void 0 ? 40 : _ref3$size,
6755
+ text = _ref3.text;
6676
6756
  var textColor = F(color) ? "#222" : "#EEE";
6677
- return /*#__PURE__*/React.createElement(StyledCursor, {
6678
- top: pos.y - 10,
6679
- left: pos.x - 5
6680
- }, /*#__PURE__*/React.createElement("svg", {
6757
+ return /*#__PURE__*/React.createElement(StyledCursor, null, /*#__PURE__*/React.createElement("svg", {
6681
6758
  version: "1.1",
6682
6759
  id: "Layer_1",
6683
6760
  xmlns: "http://www.w3.org/2000/svg",
@@ -6702,6 +6779,23 @@ var Cursor = function Cursor(_ref4) {
6702
6779
  }, text));
6703
6780
  };
6704
6781
 
6782
+ var MemoizedCursor = /*#__PURE__*/React.memo(Cursor);
6783
+
6784
+ var PositionnedCursor = function PositionnedCursor(_ref4) {
6785
+ var pos = _ref4.pos,
6786
+ rest = _objectWithoutProperties(_ref4, _excluded$1);
6787
+
6788
+ return /*#__PURE__*/React.createElement("div", {
6789
+ style: {
6790
+ transform: "translate(".concat(pos.x - 5, "px, ").concat(pos.y - 3, "px)"),
6791
+ top: 0,
6792
+ left: 0,
6793
+ zIndex: 210,
6794
+ position: "fixed"
6795
+ }
6796
+ }, /*#__PURE__*/React.createElement(MemoizedCursor, rest));
6797
+ };
6798
+
6705
6799
  var Cursors = function Cursors(_ref) {
6706
6800
  var users = _ref.users;
6707
6801
 
@@ -6777,7 +6871,7 @@ var Cursors = function Cursors(_ref) {
6777
6871
  userId = _ref5[0],
6778
6872
  pos = _ref5[1];
6779
6873
 
6780
- return /*#__PURE__*/React.createElement(Cursor, {
6874
+ return /*#__PURE__*/React.createElement(PositionnedCursor, {
6781
6875
  key: userId,
6782
6876
  pos: pos,
6783
6877
  text: usersById[userId].name,
@@ -7316,7 +7410,12 @@ var PanZoomRotate = function PanZoomRotate(_ref) {
7316
7410
 
7317
7411
  var config = useRecoilValue(BoardConfigAtom);
7318
7412
  var setBoardState = useSetRecoilState(BoardStateAtom);
7319
- var prevDim = usePrevious(dim); // Hooks to save/restore position
7413
+ var prevDim = usePrevious(dim);
7414
+ var mouseRef = React.useRef({
7415
+ hover: false,
7416
+ x: 0,
7417
+ y: 0
7418
+ }); // Hooks to save/restore position
7320
7419
 
7321
7420
  usePositionNavigator();
7322
7421
 
@@ -7351,7 +7450,7 @@ var PanZoomRotate = function PanZoomRotate(_ref) {
7351
7450
  translateY: prevDimension.translateY + deltaY
7352
7451
  });
7353
7452
  });
7354
- }, [scale, setDim]); // Center board on game loading
7453
+ }, [scale, setDim]); // Center board on board loading
7355
7454
 
7356
7455
  React.useEffect(function () {
7357
7456
  var _boardRef$current$get = boardRef.current.getBoundingClientRect(),
@@ -7618,9 +7717,11 @@ var PanZoomRotate = function PanZoomRotate(_ref) {
7618
7717
  e.preventDefault();
7619
7718
 
7620
7719
  case 31:
7621
- // Temporally zoom
7720
+ // Temporary zoom
7622
7721
  if (e.key === " " && !e.repeat) {
7623
- zoomTo(3);
7722
+ if (mouseRef.current.hover) {
7723
+ zoomTo(3, mouseRef.current);
7724
+ }
7624
7725
  }
7625
7726
 
7626
7727
  case 32:
@@ -7640,10 +7741,23 @@ var PanZoomRotate = function PanZoomRotate(_ref) {
7640
7741
  // Ignore text in Input or Textarea
7641
7742
  if (["INPUT", "TEXTAREA"].includes(e.target.tagName)) return; // Zoom out on release
7642
7743
 
7643
- if (e.key === " ") {
7644
- zoomTo(1 / 3);
7744
+ if (e.key === " " && mouseRef.current.hover) {
7745
+ zoomTo(1 / 3, mouseRef.current);
7645
7746
  }
7646
- }, [zoomTo]);
7747
+ }, [zoomTo]); // Save mouse position for temporary zoom
7748
+
7749
+ var onMouseMove = React.useCallback(function (e) {
7750
+ var clientX = e.clientX,
7751
+ clientY = e.clientY;
7752
+ mouseRef.current.x = clientX;
7753
+ mouseRef.current.y = clientY;
7754
+ }, []);
7755
+ var onMouseEnter = React.useCallback(function () {
7756
+ mouseRef.current.hover = true;
7757
+ }, []);
7758
+ var onMouseLeave = React.useCallback(function () {
7759
+ mouseRef.current.hover = false;
7760
+ }, []);
7647
7761
  React.useEffect(function () {
7648
7762
  document.addEventListener("keydown", onKeyDown);
7649
7763
  document.addEventListener("keyup", onKeyUp);
@@ -7666,7 +7780,10 @@ var PanZoomRotate = function PanZoomRotate(_ref) {
7666
7780
  ref: wrappedRef,
7667
7781
  onContextMenu: function onContextMenu(e) {
7668
7782
  e.preventDefault();
7669
- }
7783
+ },
7784
+ onMouseMove: onMouseMove,
7785
+ onMouseEnter: onMouseEnter,
7786
+ onMouseLeave: onMouseLeave
7670
7787
  }, children));
7671
7788
  };
7672
7789