@reearth/core 0.0.7-alpha.11 → 0.0.7-alpha.13

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.11",
3
+ "version": "0.0.7-alpha.13",
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.",
@@ -32,6 +32,13 @@
32
32
  "react-dom": "^18.2.0"
33
33
  },
34
34
  "dependencies": {
35
+ "@radix-ui/react-checkbox": "1.1.1",
36
+ "@radix-ui/react-select": "2.1.1",
37
+ "@radix-ui/react-separator": "1.1.0",
38
+ "@radix-ui/react-switch": "1.1.0",
39
+ "@radix-ui/react-dialog": "1.1.1",
40
+ "@radix-ui/react-icons": "1.3.0",
41
+ "@radix-ui/react-slot": "1.1.0",
35
42
  "@reearth/cesium-mvt-imagery-provider": "1.5.4",
36
43
  "@rot1024/use-transition": "1.0.0",
37
44
  "@seznam/compose-react-refs": "1.0.6",
@@ -61,8 +68,11 @@
61
68
  "react-error-boundary": "4.0.11",
62
69
  "react-nl2br": "1.0.4",
63
70
  "react-use": "17.5.0",
64
- "resium": "1.18.1",
71
+ "resium": "1.18.2",
65
72
  "suspend-react": "0.1.3",
73
+ "tailwind-merge": "2.5.2",
74
+ "tailwindcss": "3.4.10",
75
+ "tailwindcss-animate": "1.0.7",
66
76
  "tiny-invariant": "1.3.3",
67
77
  "use-callback-ref": "1.3.2",
68
78
  "use-custom-compare": "1.4.0",
@@ -91,17 +101,22 @@
91
101
  "@types/pbf": "3.0.5",
92
102
  "@types/react": "18.3.0",
93
103
  "@types/react-dom": "18.3.0",
104
+ "@types/scheduler": "0.23.0",
94
105
  "@types/uuid": "9.0.8",
95
106
  "@typescript-eslint/eslint-plugin": "7.2.0",
96
107
  "@typescript-eslint/parser": "7.2.0",
97
108
  "@vitejs/plugin-react": "4.2.1",
109
+ "autoprefixer": "10.4.20",
98
110
  "cesium": "1.118.0",
111
+ "class-variance-authority": "0.7.0",
112
+ "clsx": "2.1.1",
99
113
  "eslint": "8.57.0",
100
114
  "eslint-config-reearth": "0.3.0",
101
115
  "eslint-plugin-react-hooks": "4.6.0",
102
116
  "eslint-plugin-react-refresh": "0.4.6",
103
117
  "eslint-plugin-storybook": "0.8.0",
104
118
  "jsdom": "22.1.0",
119
+ "postcss": "8.4.41",
105
120
  "prettier": "3.2.5",
106
121
  "react": "18.2.0",
107
122
  "react-dom": "18.2.0",
@@ -17,15 +17,16 @@ import {
17
17
  GroundPrimitive,
18
18
  } from "cesium";
19
19
  import md5 from "js-md5";
20
- import { isEqual, pick } from "lodash-es";
20
+ import { pick } from "lodash-es";
21
21
  import {
22
22
  ComponentProps,
23
23
  ComponentType,
24
24
  ForwardedRef,
25
25
  forwardRef,
26
+ useCallback,
26
27
  useLayoutEffect,
27
28
  useMemo,
28
- useRef,
29
+ useState,
29
30
  } from "react";
30
31
  import { type CesiumComponentRef, Entity } from "resium";
31
32
 
@@ -86,19 +87,11 @@ function EntityExtComponent(
86
87
  }: ComponentProps<typeof Entity> & Tag,
87
88
  ref: ForwardedRef<CesiumComponentRef<CesiumEntity>>,
88
89
  ) {
89
- const r = useRef<CesiumComponentRef<CesiumEntity>>(null);
90
- const entityRef = useRef<CesiumEntity | undefined>(r?.current?.cesiumElement);
90
+ const [entity, setEntity] = useState<CesiumComponentRef<CesiumEntity> | null>(null);
91
91
 
92
92
  useLayoutEffect(() => {
93
- // Note: Sketch feature's tag cannot be attached properly when first load
94
- // The cesiumElement is undefined when attach, and doesn't have a chance to attach again.
95
- // Root cause is still not clear.
96
- // Here we add r.current as a dependency and check cesiumElement instead.
97
- if (entityRef.current !== undefined && isEqual(entityRef.current, r.current?.cesiumElement))
98
- return;
99
- entityRef.current = r.current?.cesiumElement;
100
-
101
- attachTag(r.current?.cesiumElement, {
93
+ if (!entity?.cesiumElement) return;
94
+ attachTag(entity.cesiumElement, {
102
95
  layerId: layerId || props.id,
103
96
  featureId,
104
97
  draggable,
@@ -106,7 +99,6 @@ function EntityExtComponent(
106
99
  legacyLocationPropertyKey,
107
100
  hideIndicator,
108
101
  });
109
- // eslint-disable-next-line react-hooks/exhaustive-deps
110
102
  }, [
111
103
  draggable,
112
104
  featureId,
@@ -115,10 +107,12 @@ function EntityExtComponent(
115
107
  props.id,
116
108
  unselectable,
117
109
  hideIndicator,
118
- r.current,
110
+ entity,
119
111
  ]);
120
112
 
121
- return <Entity ref={composeRefs(ref, r)} {...props} />;
113
+ const handleRef = useCallback((r: CesiumComponentRef<CesiumEntity>) => setEntity(r), []);
114
+
115
+ return <Entity ref={composeRefs(ref, handleRef)} {...props} />;
122
116
  }
123
117
 
124
118
  export function attachTag(
@@ -36,7 +36,7 @@ import {
36
36
  CameraEventType,
37
37
  KeyboardEventModifier,
38
38
  } from "cesium";
39
- import { useCallback, MutableRefObject } from "react";
39
+ import { MutableRefObject, useMemo } from "react";
40
40
 
41
41
  import type { Camera, Clock } from "..";
42
42
  import { ClassificationType } from "../../mantle";
@@ -48,7 +48,7 @@ import type {
48
48
  OverideKeyboardEventModifier,
49
49
  ScreenSpaceCameraControllerOptions,
50
50
  } from "../../types";
51
- import { tweenInterval, useCanvas, useImage, LatLngHeight } from "../../utils";
51
+ import { tweenInterval, useImage, LatLngHeight } from "../../utils";
52
52
 
53
53
  import { DEFAULT_SCREEN_SPACE_CAMERA_ASSIGNMENTS } from "./constants";
54
54
 
@@ -56,8 +56,7 @@ export const layerIdField = `__reearth_layer_id`;
56
56
 
57
57
  const defaultImageSize = 50;
58
58
 
59
- export const drawIcon = (
60
- c: HTMLCanvasElement,
59
+ const drawIcon = (
61
60
  image: HTMLImageElement | undefined,
62
61
  w: number,
63
62
  h: number,
@@ -68,6 +67,7 @@ export const drawIcon = (
68
67
  shadowOffsetX = 0,
69
68
  shadowOffsetY = 0,
70
69
  ) => {
70
+ const c = document.createElement("canvas");
71
71
  const ctx = c.getContext("2d");
72
72
  if (!image || !ctx) return;
73
73
 
@@ -104,6 +104,7 @@ export const drawIcon = (
104
104
  }
105
105
 
106
106
  ctx.restore();
107
+ return c.toDataURL();
107
108
  };
108
109
 
109
110
  export const useIcon = ({
@@ -138,13 +139,11 @@ export const useIcon = ({
138
139
  ? Math.floor(img.height * imageSize)
139
140
  : Math.floor((w / img.width) * img.height);
140
141
 
141
- const draw = useCallback(
142
- (can: HTMLCanvasElement) =>
143
- drawIcon(can, img, w, h, crop, shadow, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY),
142
+ const canvas = useMemo(
143
+ () => drawIcon(img, w, h, crop, shadow, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY),
144
144
  [crop, h, img, shadow, shadowBlur, shadowColor, shadowOffsetX, shadowOffsetY, w],
145
145
  );
146
- const canvas = useCanvas(draw);
147
- return [canvas, w, h];
146
+ return [canvas ?? "", w, h];
148
147
  };
149
148
 
150
149
  export const ho = (o: "left" | "center" | "right" | undefined): HorizontalOrigin | undefined =>
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useMemo, useRef } from "react";
1
+ import { useState, useEffect, useRef } from "react";
2
2
 
3
3
  export const useImage = (src?: string): HTMLImageElement | undefined => {
4
4
  const imgRef = useRef<HTMLImageElement>();
@@ -23,13 +23,3 @@ export const useImage = (src?: string): HTMLImageElement | undefined => {
23
23
 
24
24
  return img;
25
25
  };
26
-
27
- export const useCanvas = (cb: (canvas: HTMLCanvasElement) => void): string => {
28
- const can = useMemo(() => document.createElement("canvas"), []);
29
- const [data, setData] = useState<string>("");
30
- useEffect(() => {
31
- cb(can);
32
- setData(can.toDataURL());
33
- }, [can, cb]);
34
- return data;
35
- };