@netless/app-slide 0.0.57 → 0.1.1

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/app-slide",
3
- "version": "0.0.57",
3
+ "version": "0.1.1",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,11 +11,11 @@
11
11
  ],
12
12
  "devDependencies": {
13
13
  "@netless/app-shared": "^0.1.1",
14
- "@netless/slide": "^0.2.7",
14
+ "@netless/slide": "^0.2.9",
15
15
  "@types/color-string": "^1.5.2",
16
16
  "color-string": "^1.9.0",
17
17
  "side-effect-manager": "^0.1.5",
18
- "vanilla-lazyload": "^17.5.0"
18
+ "vanilla-lazyload": "^17.6.1"
19
19
  },
20
20
  "scripts": {
21
21
  "types": "cross-env NODE_ENV=production tsc --declaration --emitDeclarationOnly --outDir dist",
@@ -14,7 +14,7 @@ import type { Attributes, MagixEvents, MagixPayload, SlideState } from "../typin
14
14
 
15
15
  import { SideEffectManager } from "side-effect-manager";
16
16
  import { Slide, SLIDE_EVENTS } from "@netless/slide";
17
- import { clamp, deepClone, isObj } from "../utils/helpers";
17
+ import { clamp } from "../utils/helpers";
18
18
  import { cachedGetBgColor } from "../utils/bgcolor";
19
19
  import { logger, log, verbose } from "../utils/logger";
20
20
  export { syncSceneWithSlide, createDocsViewerPages } from "./helpers";
@@ -100,13 +100,16 @@ export class SlideController {
100
100
 
101
101
  private kickStart() {
102
102
  const { context, slide } = this;
103
- const { taskId, url, state } = { ...EmptyAttributes, ...this.context.getAttributes() };
103
+ if (context.getIsWritable()) {
104
+ context.storage.ensureState(EmptyAttributes);
105
+ }
106
+ const { taskId, url, state } = context.storage.state;
104
107
  slide.setResource(taskId, url || DefaultUrl);
105
108
  if (state) {
106
109
  // if we already have state, try restore from it
107
- log("[Slide] init with state", deepClone(state));
110
+ log("[Slide] init with state", state);
108
111
  this.syncStateOnceFlag = false;
109
- slide.setSlideState(deepClone(state));
112
+ slide.setSlideState(state);
110
113
  } else if (context.isAddApp) {
111
114
  // otherwise, maybe this slide is just added, let the adder kick start first render
112
115
  log("[Slide] init by renderSlide", 1);
@@ -124,19 +127,14 @@ export class SlideController {
124
127
  // it is possible that we miss the first `renderSlide(1)` event
125
128
  // and the attributes has no value yet, so we need to sync state
126
129
  // when there's state change. we only have to do it once
127
- this.sideEffect.add(() => {
128
- const disposer = context.mobxUtils.reaction(
129
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
130
- () => context.getAttributes()!.state,
131
- () => {
130
+ const disposerId = this.sideEffect.addDisposer(
131
+ context.storage.addStateChangedListener(() => {
132
+ if (context.storage.state.state) {
132
133
  this.syncStateOnce();
133
- disposer();
134
+ this.sideEffect.flush(disposerId);
134
135
  }
135
- );
136
- // mobx already has a "disposed" flag in reaction,
137
- // so we don't need to check it here
138
- return disposer;
139
- });
136
+ })
137
+ );
140
138
 
141
139
  this.sideEffect.add(() =>
142
140
  context.addMagixEventListener(SLIDE_EVENTS.syncDispatch, this.magixEventListener, {
@@ -168,23 +166,24 @@ export class SlideController {
168
166
  };
169
167
 
170
168
  private magixEventListener: MagixEventListener = ev => {
171
- if (ev.event === SLIDE_EVENTS.syncDispatch && isObj(ev.payload)) {
172
- const { type, payload } = ev.payload as MagixPayload;
173
- if (type === SLIDE_EVENTS.syncDispatch) {
174
- this.syncStateOnce();
175
- log("[Slide] receive", payload);
176
- this.slide.emit(SLIDE_EVENTS.syncReceive, payload);
177
- }
169
+ const { type, payload } = ev.payload;
170
+ if (type === SLIDE_EVENTS.syncDispatch) {
171
+ this.syncStateOnce();
172
+ log("[Slide] receive", payload);
173
+ this.slide.emit(SLIDE_EVENTS.syncReceive, payload);
178
174
  }
179
175
  };
180
176
 
181
177
  private syncStateOnce() {
182
178
  // sync state before the first event, so that they can be in the correct order
183
179
  if (this.syncStateOnceFlag) {
184
- const { state } = { ...EmptyAttributes, ...this.context.storage.state };
180
+ if (this.context.getIsWritable()) {
181
+ this.context.storage.ensureState(EmptyAttributes);
182
+ }
183
+ const { state } = this.context.storage.state;
185
184
  if (state) {
186
- log("[Slide] sync with state (once)", deepClone(state));
187
- this.slide.setSlideState(deepClone(state));
185
+ log("[Slide] sync with state (once)", state);
186
+ this.slide.setSlideState(state);
188
187
  this.syncStateOnceFlag = false;
189
188
  }
190
189
  }
@@ -169,6 +169,15 @@ export class SlideDocsViewer {
169
169
  height,
170
170
  animationMode: "immediately" as AnimationMode.Immediately,
171
171
  });
172
+ this.whiteboardView.setCameraBound({
173
+ damping: 1,
174
+ maxContentMode: () => this.whiteboardView.camera.scale,
175
+ minContentMode: () => this.whiteboardView.camera.scale,
176
+ centerX: 0,
177
+ centerY: 0,
178
+ width,
179
+ height,
180
+ });
172
181
  if (!this.isViewMounted) {
173
182
  this.isViewMounted = true;
174
183
  console.log("[Slide] mount whiteboard view");