@netless/fastboard-react 0.2.2 → 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.
- package/dist/index.js +193 -188
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/components/Toolbar/Toolbar.scss +13 -0
- package/src/components/Toolbar/components/ShapesButton.tsx +2 -3
- package/src/components/Toolbar/hooks.ts +13 -1
- package/src/components/ZoomControl/hooks.ts +2 -4
- package/src/components/hooks.ts +8 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/fastboard-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "A UI kit built on top of @netless/fastboard.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"white-web-sdk": ">=2.16.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@netless/fastboard-core": "0.2.
|
|
26
|
-
"@netless/window-manager": "^0.4.0
|
|
25
|
+
"@netless/fastboard-core": "0.2.6",
|
|
26
|
+
"@netless/window-manager": "^0.4.0",
|
|
27
27
|
"@types/react": "^17.0.38",
|
|
28
28
|
"@types/react-dom": "^17.0.11",
|
|
29
29
|
"sass": "^1.49.0",
|
|
30
30
|
"tippy.js": "^6.3.7",
|
|
31
31
|
"tsup": "^5.11.11",
|
|
32
|
-
"white-web-sdk": "^2.16.
|
|
32
|
+
"white-web-sdk": "^2.16.6"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"main": "dist/index.js",
|
|
@@ -152,6 +152,17 @@ $name: "fastboard-toolbar";
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
&-section + &-mask {
|
|
156
|
+
opacity: 0;
|
|
157
|
+
transition: 0.5s opacity 0.4s;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&-section:hover + &-mask,
|
|
161
|
+
&-mask:hover {
|
|
162
|
+
opacity: 1;
|
|
163
|
+
transition: 0.2s opacity;
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
&-panel {
|
|
156
167
|
width: 136px - 8px * 2;
|
|
157
168
|
padding: 0;
|
|
@@ -268,6 +279,7 @@ $name: "fastboard-toolbar";
|
|
|
268
279
|
left: calc(100% + 1px);
|
|
269
280
|
top: 50%;
|
|
270
281
|
transform: translateY(-50%);
|
|
282
|
+
opacity: 0.85;
|
|
271
283
|
&.dark {
|
|
272
284
|
left: calc(100%);
|
|
273
285
|
}
|
|
@@ -277,6 +289,7 @@ $name: "fastboard-toolbar";
|
|
|
277
289
|
width: 17px;
|
|
278
290
|
height: 62px;
|
|
279
291
|
cursor: pointer;
|
|
292
|
+
opacity: 0.85;
|
|
280
293
|
&.dark {
|
|
281
294
|
filter: invert(0.8);
|
|
282
295
|
}
|
|
@@ -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[
|
|
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.
|
|
8
|
-
|
|
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) {
|
package/src/components/hooks.ts
CHANGED
|
@@ -43,12 +43,19 @@ export function useMaximized() {
|
|
|
43
43
|
return useBoxState() === "maximized";
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const AppsShouldShowToolbar = /* @__PURE__ */ (() => [BuiltinApps.DocsViewer, "Slide"])();
|
|
47
|
+
|
|
46
48
|
export function useHideControls() {
|
|
49
|
+
const writable = useWritable();
|
|
47
50
|
const maximized = useMaximized();
|
|
48
51
|
const focusedApp = useFocusedApp();
|
|
49
52
|
|
|
53
|
+
if (!writable) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
if (maximized) {
|
|
51
|
-
if (
|
|
58
|
+
if (AppsShouldShowToolbar.some(kind => focusedApp?.includes(kind))) {
|
|
52
59
|
return "toolbar-only";
|
|
53
60
|
} else {
|
|
54
61
|
return true;
|