@netless/fastboard 0.0.5 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/fastboard",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
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,11 +10,6 @@ export type { WhiteboardAppConfig, InsertDocsParams };
10
10
  export class WhiteboardApp {
11
11
  private readonly _instance: Instance;
12
12
 
13
- private _target: HTMLElement | null = null;
14
- public get target(): HTMLElement | null {
15
- return this._target;
16
- }
17
-
18
13
  constructor(readonly config: WhiteboardAppConfig) {
19
14
  this._instance = new Instance(config);
20
15
  }
@@ -35,9 +30,23 @@ export class WhiteboardApp {
35
30
  return this._instance.i18n;
36
31
  }
37
32
 
38
- public bindElement(target?: HTMLElement | null) {
33
+ private _target: HTMLElement | null = null;
34
+ public get target(): HTMLElement | null {
35
+ return this._target;
36
+ }
37
+
38
+ private _collector: HTMLElement | null = null;
39
+ public get collector(): HTMLElement | null {
40
+ return this._collector;
41
+ }
42
+
43
+ public bindElement(
44
+ target?: HTMLElement | null,
45
+ collector?: HTMLElement | null
46
+ ) {
39
47
  this._target = target || null;
40
- this._instance.target = target || null;
48
+ this._collector = collector || null;
49
+ this._instance.bindElement(this._target, this._collector);
41
50
  }
42
51
 
43
52
  public insertDocs(params: InsertDocsParams) {
@@ -36,14 +36,14 @@ export function PageControl({
36
36
  if (manager && room) {
37
37
  await manager.switchMainViewToWriter();
38
38
  const path = room.state.sceneState.contextPath;
39
- room.putScenes(path, [{}], pageCount);
40
- await manager.setMainViewSceneIndex(pageIndex);
39
+ room.putScenes(path, [{}], pageIndex + 1);
40
+ await manager.setMainViewSceneIndex(pageIndex + 1);
41
41
  } else if (!manager && room) {
42
42
  const path = room.state.sceneState.contextPath;
43
- room.putScenes(path, [{}], pageCount);
44
- room.setSceneIndex(pageIndex);
43
+ room.putScenes(path, [{}], pageIndex + 1);
44
+ room.setSceneIndex(pageIndex + 1);
45
45
  }
46
- }, [room, manager, pageCount, pageIndex]);
46
+ }, [room, manager, pageIndex]);
47
47
 
48
48
  const prevPage = useCallback(() => {
49
49
  if (room?.isWritable) {
package/src/hooks.ts CHANGED
@@ -15,13 +15,16 @@ export type FastBoardConfig = WhiteboardAppConfig;
15
15
  */
16
16
  export function useFastboard(config: FastBoardConfig): readonly [
17
17
  app: WhiteboardApp | null,
18
- ref: (div: HTMLDivElement | null) => void
18
+ ref: (div: HTMLDivElement | null) => void,
19
+ collectorRef: (div: HTMLDivElement | null) => void
19
20
  ] & {
20
21
  readonly app: WhiteboardApp | null;
21
22
  readonly ref: (div: HTMLDivElement | null) => void;
23
+ readonly collectorRef: (div: HTMLDivElement | null) => void;
22
24
  } {
23
25
  const [app, setApp] = useState<WhiteboardApp | null>(null);
24
26
  const [currentTarget, ref] = useState<HTMLDivElement | null>(null);
27
+ const [collector, collectorRef] = useState<HTMLDivElement | null>(null);
25
28
 
26
29
  useEffect(() => {
27
30
  let isMounted = true;
@@ -38,9 +41,13 @@ export function useFastboard(config: FastBoardConfig): readonly [
38
41
 
39
42
  useEffect(() => {
40
43
  if (app) {
41
- app.bindElement(currentTarget);
44
+ app.bindElement(currentTarget, collector);
42
45
  }
43
- }, [app, currentTarget]);
46
+ }, [app, collector, currentTarget]);
44
47
 
45
- return Object.assign([app, ref] as const, { app, ref });
48
+ return Object.assign([app, ref, collectorRef] as const, {
49
+ app,
50
+ ref,
51
+ collectorRef,
52
+ });
46
53
  }
@@ -112,6 +112,14 @@ export class Instance {
112
112
  this.forceUpdate();
113
113
  }
114
114
 
115
+ collector: HTMLElement | null = null;
116
+
117
+ bindElement(target: HTMLElement | null, collector: HTMLElement | null) {
118
+ this.target = target;
119
+ this.collector = collector;
120
+ this.forceUpdate();
121
+ }
122
+
115
123
  async forceUpdate() {
116
124
  await this.readyPromise;
117
125
  if (this.target) {
@@ -139,7 +147,12 @@ export class Instance {
139
147
 
140
148
  async mount(node: HTMLElement) {
141
149
  await this.readyPromise;
142
- if (this.manager) {
150
+ if (!this.manager) {
151
+ throw new Error(`[WhiteboardApp] mounted, but not found window manager`);
152
+ }
153
+ if (this.collector) {
154
+ this.manager.bindContainer(node, this.collector);
155
+ } else {
143
156
  this.manager.bindContainer(node);
144
157
  }
145
158
  }