@reearth/core 0.0.7-alpha.31 → 0.0.7-alpha.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.31",
3
+ "version": "0.0.7-alpha.32",
4
4
  "author": "Re:Earth contributors <community@reearth.io>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A library that abstracts a map engine as one common API.",
@@ -16,6 +16,7 @@ import { v4 as uuidv4 } from "uuid";
16
16
  import { InterpreterFrom, StateFrom } from "xstate";
17
17
 
18
18
  import { ControlPointMouseEventHandler } from "../../engines/Cesium/Sketch";
19
+ import { useWindowEvent } from "../../utils/use-window-event";
19
20
  import { InteractionModeType } from "../../Visualizer/interactionMode";
20
21
  import { Feature, EngineRef, LayersRef, SketchRef } from "../types";
21
22
  import { useGet } from "../utils";
@@ -34,7 +35,6 @@ import {
34
35
  import usePluginSketchLayer from "./usePluginSketchLayer";
35
36
  import useSketch from "./useSketch";
36
37
  import useSketchFeature from "./useSketchFeature";
37
- import { useWindowEvent } from "./utils";
38
38
 
39
39
  import { OnLayerSelectType } from ".";
40
40
 
@@ -10,6 +10,7 @@ import {
10
10
  } from "react";
11
11
  import { v4 as uuid } from "uuid";
12
12
 
13
+ import { useWindowEvent } from "../../utils/use-window-event";
13
14
  import { InteractionModeType } from "../../Visualizer";
14
15
  import { EngineRef, MouseEventProps } from "../types";
15
16
 
@@ -48,6 +49,7 @@ export default ({
48
49
  const [verticalSpaceIndicator, setVerticalSpaceIndicator] =
49
50
  useState<VerticalSpaceIndicatorType | null>(null);
50
51
  const [coordinateSelector, setCoordinateSelector] = useState<CoordinateSelectorType | null>(null);
52
+ const lastCoordinateSelector = useRef<CoordinateSelectorType | null>(null);
51
53
  const [spaceSelector, setSpaceSelector] = useState<SpatialIdSpaceType | null>(null);
52
54
 
53
55
  const [basePosition, setBasePosition] = useState<[number, number, number] | null>(null);
@@ -114,6 +116,7 @@ export default ({
114
116
  setBaseCoordinate(null);
115
117
  setSpaceSelector(null);
116
118
  setCoordinateSelector(null);
119
+ lastCoordinateSelector.current = null;
117
120
  setVerticalSpaceIndicator(null);
118
121
  overrideInteractionMode?.(
119
122
  interactionModeRef.current === "spatialId"
@@ -141,6 +144,7 @@ export default ({
141
144
  }) ?? null,
142
145
  );
143
146
 
147
+ lastCoordinateSelector.current = coordinateSelector;
144
148
  setCoordinateSelector(null);
145
149
 
146
150
  const initialSpaceSelectorSpace = createSpatialIdSpace(
@@ -271,7 +275,7 @@ export default ({
271
275
  ],
272
276
  );
273
277
 
274
- const handleMouseRightClick = useCallback(() => {
278
+ const cancel = useCallback(() => {
275
279
  if (state === "idle") return;
276
280
  if (state === "coordinate" && pickOptions.rightClickToExit) {
277
281
  finishPicking();
@@ -280,11 +284,22 @@ export default ({
280
284
  setBasePosition(null);
281
285
  setBaseCoordinate(null);
282
286
  setVerticalSpaceIndicator(null);
287
+ setCoordinateSelector(lastCoordinateSelector.current);
283
288
  setState("coordinate");
284
289
  }
285
290
  engineRef.current?.requestRender();
286
291
  }, [state, pickOptions, engineRef, finishPicking]);
287
292
 
293
+ const handleMouseRightClick = useCallback(() => {
294
+ cancel();
295
+ }, [cancel]);
296
+
297
+ useWindowEvent("keydown", event => {
298
+ if (event.code === "Escape") {
299
+ cancel();
300
+ }
301
+ });
302
+
288
303
  // bind mouse events
289
304
  const eventsBinded = useRef(false);
290
305