@netless/fastboard 0.0.6 → 0.0.7

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": "@netless/fastboard",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "An open sourced sdk based on white-web-sdk.",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.es.js",
@@ -10,7 +10,7 @@ export interface RootProps {
10
10
  instance: Instance;
11
11
  }
12
12
 
13
- export default function Root({ instance: app }: RootProps) {
13
+ export function Root({ instance: app }: RootProps) {
14
14
  const [mux] = useState(() => new Lock());
15
15
 
16
16
  const useWhiteboard = useCallback(
@@ -21,21 +21,40 @@ export default function Root({ instance: app }: RootProps) {
21
21
  [app, mux]
22
22
  );
23
23
 
24
+ const {
25
+ Toolbar: toolbar = true,
26
+ RedoUndo: redo_undo = true,
27
+ ZoomControl: zoom_control = true,
28
+ PageControl: page_control = true,
29
+ } = app.config.layout || {};
30
+
31
+ const props = {
32
+ room: app.room,
33
+ manager: app.manager,
34
+ i18n: app.i18n,
35
+ };
36
+
24
37
  return (
25
38
  <Instance.Context.Provider value={app}>
26
39
  <div className="fastboard-root">
27
40
  {!app.room && <div className="fastboard-loading">Loading&hellip;</div>}
28
41
  <div className="fastboard-view" ref={useWhiteboard} />
29
- <div className="fastboard-left">
30
- <Toolbar room={app.room} manager={app.manager} i18n={app.i18n} />
31
- </div>
32
- <div className="fastboard-bottom-left">
33
- <RedoUndo room={app.room} manager={app.manager} i18n={app.i18n} />
34
- <ZoomControl room={app.room} manager={app.manager} i18n={app.i18n} />
35
- </div>
36
- <div className="fastboard-bottom-right">
37
- <PageControl room={app.room} manager={app.manager} i18n={app.i18n} />
38
- </div>
42
+ {toolbar && (
43
+ <div className="fastboard-left">
44
+ <Toolbar {...props} />
45
+ </div>
46
+ )}
47
+ {(redo_undo || zoom_control) && (
48
+ <div className="fastboard-bottom-left">
49
+ {redo_undo && <RedoUndo {...props} />}
50
+ {zoom_control && <ZoomControl {...props} />}
51
+ </div>
52
+ )}
53
+ {page_control && (
54
+ <div className="fastboard-bottom-right">
55
+ <PageControl {...props} />
56
+ </div>
57
+ )}
39
58
  </div>
40
59
  </Instance.Context.Provider>
41
60
  );
@@ -1,3 +1,4 @@
1
+ import type { Mutable } from "type-fest";
1
2
  import type { WindowManager } from "@netless/window-manager";
2
3
  import type { Room, SceneDefinition, WhiteWebSdk } from "white-web-sdk";
3
4
  import type { JoinRoom, ManagerConfig, SdkConfig } from "./mount-whiteboard";
@@ -6,7 +7,7 @@ import type { i18n } from "i18next";
6
7
  import React, { createContext, useContext } from "react";
7
8
  import ReactDOM from "react-dom";
8
9
 
9
- import Root from "../components/Root";
10
+ import { Root } from "../components/Root";
10
11
  import { mountWhiteboard } from "./mount-whiteboard";
11
12
  import { noop } from "./helpers";
12
13
 
@@ -36,10 +37,18 @@ export type InsertDocsParams = InsertDocsStatic | InsertDocsDynamic;
36
37
 
37
38
  export type Language = "zh-CN" | "en-US";
38
39
 
40
+ export interface Layout {
41
+ Toolbar?: boolean;
42
+ PageControl?: boolean;
43
+ RedoUndo?: boolean;
44
+ ZoomControl?: boolean;
45
+ }
46
+
39
47
  export interface WhiteboardAppConfig {
40
48
  readonly sdkConfig: SdkConfig;
41
49
  readonly joinRoom: JoinRoom;
42
50
  readonly managerConfig?: Omit<ManagerConfig, "container">;
51
+ readonly layout?: Layout;
43
52
  readonly toolbar?: {
44
53
  apps?: {
45
54
  enable?: boolean;
@@ -60,7 +69,7 @@ export interface Essentials {
60
69
  export class Instance {
61
70
  static readonly Context = createContext<Instance | null>(null);
62
71
 
63
- readonly config: WhiteboardAppConfig;
72
+ config: Mutable<WhiteboardAppConfig>;
64
73
 
65
74
  sdk: WhiteWebSdk | null = null;
66
75
  room: Room | null = null;
@@ -82,13 +91,11 @@ export class Instance {
82
91
  }
83
92
 
84
93
  constructor(config: WhiteboardAppConfig) {
85
- this.config = config;
94
+ this.config = { ...config };
86
95
  this.refreshReadyPromise();
87
96
  this.initialize();
88
97
  }
89
98
 
90
- private _target: HTMLElement | null = null;
91
-
92
99
  async initialize() {
93
100
  const essentials = await mountWhiteboard(
94
101
  this.config.sdkConfig,
@@ -100,26 +107,23 @@ export class Instance {
100
107
  this.resolveReady();
101
108
  }
102
109
 
103
- get target(): HTMLElement | null {
104
- return this._target;
105
- }
106
-
107
- set target(value: HTMLElement | null) {
108
- if (this._target && value) {
109
- ReactDOM.unmountComponentAtNode(this._target);
110
- }
111
- this._target = value;
112
- this.forceUpdate();
113
- }
114
-
110
+ target: HTMLElement | null = null;
115
111
  collector: HTMLElement | null = null;
116
112
 
117
113
  bindElement(target: HTMLElement | null, collector: HTMLElement | null) {
114
+ if (this.target && target) {
115
+ ReactDOM.unmountComponentAtNode(this.target);
116
+ }
118
117
  this.target = target;
119
118
  this.collector = collector;
120
119
  this.forceUpdate();
121
120
  }
122
121
 
122
+ updateLayout(layout: Layout) {
123
+ this.config.layout = layout;
124
+ this.forceUpdate();
125
+ }
126
+
123
127
  async forceUpdate() {
124
128
  await this.readyPromise;
125
129
  if (this.target) {
@@ -4,7 +4,7 @@ import type {
4
4
  RoomCallbacks,
5
5
  WhiteWebSdkConfiguration,
6
6
  } from "white-web-sdk";
7
- import type { Essentials, Language } from "./instance";
7
+ import type { Essentials, Language } from "./Instance";
8
8
 
9
9
  import { WindowManager } from "@netless/window-manager";
10
10
  import { DefaultHotKeys, WhiteWebSdk } from "white-web-sdk";