@netless/fastboard-react 0.2.5 → 0.2.6

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.
@@ -8,7 +8,6 @@ import { ApplianceNames } from "white-web-sdk";
8
8
  import { useTranslation } from "../../../i18n";
9
9
  import { RightOffset } from "../../../theme";
10
10
  import { ApplianceShapes, Shapes, ShapesMap } from "../const";
11
- import { Icons } from "../icons";
12
11
  import { ToolbarContext } from "../Toolbar";
13
12
  import { Button } from "./Button";
14
13
  import { ColorBox } from "./ColorBox";
@@ -19,7 +18,7 @@ const ShapeTypes = new Set([...ApplianceShapes, ...Shapes]);
19
18
 
20
19
  export function ShapesButton() {
21
20
  const { t } = useTranslation();
22
- const { theme, memberState } = useContext(ToolbarContext);
21
+ const { theme, memberState, lastShape } = useContext(ToolbarContext);
23
22
 
24
23
  const appliance = memberState?.currentApplianceName;
25
24
  const shape = memberState?.shapeType;
@@ -28,7 +27,7 @@ export function ShapesButton() {
28
27
 
29
28
  const active = ShapeTypes.has(key);
30
29
 
31
- const CurrentIcon = ShapesMap[key] || Icons.Rectangle;
30
+ const CurrentIcon = ShapesMap[lastShape];
32
31
 
33
32
  return (
34
33
  <span className="fastboard-toolbar-btn-interactive">
@@ -1,13 +1,17 @@
1
1
  import type { ApplianceNames, Color, MemberState, ShapeType } from "white-web-sdk";
2
2
 
3
- import { useCallback } from "react";
3
+ import { useCallback, useState } from "react";
4
4
 
5
5
  import { noop } from "../../internal";
6
6
  import { useFastboardApp, useFastboardValue, useWritable } from "../hooks";
7
+ import { ShapesMap } from "./const";
8
+
9
+ export type UnifiedShape = keyof typeof ShapesMap;
7
10
 
8
11
  export interface ToolbarHook {
9
12
  readonly writable: boolean;
10
13
  readonly memberState: MemberState | undefined;
14
+ readonly lastShape: UnifiedShape;
11
15
  cleanCurrentScene(): void;
12
16
  setAppliance(appliance: ApplianceNames, shape?: ShapeType): void;
13
17
  setStrokeWidth(width: number): void;
@@ -22,6 +26,7 @@ export function useToolbar(): ToolbarHook {
22
26
  const app = useFastboardApp();
23
27
  const writable = useWritable();
24
28
  const memberState = useRoomState();
29
+ const [lastShape, setLastShape] = useState<UnifiedShape>("rectangle" as ApplianceNames.rectangle);
25
30
 
26
31
  const cleanCurrentScene = useCallback(() => {
27
32
  app.cleanCurrentScene();
@@ -30,6 +35,11 @@ export function useToolbar(): ToolbarHook {
30
35
  const setAppliance = useCallback(
31
36
  (appliance: ApplianceNames, shape?: ShapeType) => {
32
37
  app.setAppliance(appliance, shape);
38
+ if (shape) {
39
+ setLastShape(shape);
40
+ } else if (appliance in ShapesMap) {
41
+ setLastShape(appliance as UnifiedShape);
42
+ }
33
43
  },
34
44
  [app]
35
45
  );
@@ -51,6 +61,7 @@ export function useToolbar(): ToolbarHook {
51
61
  return {
52
62
  writable,
53
63
  memberState,
64
+ lastShape,
54
65
  cleanCurrentScene,
55
66
  setAppliance,
56
67
  setStrokeWidth,
@@ -61,6 +72,7 @@ export function useToolbar(): ToolbarHook {
61
72
  export const EmptyToolbarHook: ToolbarHook = {
62
73
  writable: false,
63
74
  memberState: undefined,
75
+ lastShape: "rectangle" as ApplianceNames.rectangle,
64
76
  cleanCurrentScene: noop,
65
77
  setAppliance: noop,
66
78
  setStrokeWidth: noop,
@@ -4,10 +4,8 @@ import { clamp } from "../../internal";
4
4
  import { useFastboardApp, useFastboardValue } from "../hooks";
5
5
 
6
6
  export const ScalePoints: readonly number[] = [
7
- 0.10737418240000011, 0.13421772800000012, 0.16777216000000014, 0.20971520000000016, 0.26214400000000015,
8
- 0.3276800000000002, 0.4096000000000002, 0.5120000000000001, 0.6400000000000001, 0.8, 1, 1.26,
9
- 1.5876000000000001, 2.000376, 2.5204737600000002, 3.1757969376000004, 4.001504141376, 5.041895218133761,
10
- 6.352787974848539, 8.00451284830916, 10,
7
+ 0.3, 0.4096000000000002, 0.5120000000000001, 0.6400000000000001, 0.8, 1, 1.26, 1.5876000000000001, 2.000376,
8
+ 2.5204737600000002, 3,
11
9
  ];
12
10
 
13
11
  function nextScale(scale: number, delta: 1 | -1) {