@netless/app-slide 0.3.0-canary.1 → 0.3.0-canary.2

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.3.0-canary.1",
3
+ "version": "0.3.0-canary.2",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -371,7 +371,10 @@ function on_visibility_change(callback: (visible: boolean) => void) {
371
371
  return noop;
372
372
  }
373
373
 
374
- export type SlideViewerOptions = Omit<ISlideConfig, "anchor"> & SlideAttributes;
374
+ export type SlideViewerOptions = Omit<ISlideConfig, "anchor" | "mode" | "interactive"> & {
375
+ mode?: ISlideConfig["mode"];
376
+ interactive?: ISlideConfig["interactive"];
377
+ } & SlideAttributes;
375
378
 
376
379
  export interface SlideViewerInfoResponse {
377
380
  width: number;
@@ -443,6 +446,8 @@ export class SlideViewer {
443
446
  this.slide = new Slide({
444
447
  anchor: this.$slide,
445
448
  resize: true,
449
+ mode: "local",
450
+ interactive: true,
446
451
  enableGlobalClick: true,
447
452
  ...options,
448
453
  });
@@ -453,6 +458,11 @@ export class SlideViewer {
453
458
  resolveFetching = resolve;
454
459
  });
455
460
 
461
+ this.slide.on("slideChange", page => {
462
+ if (this._destroyed) return;
463
+ this.setPage(page);
464
+ });
465
+
456
466
  this.slide.on("renderEnd", () => {
457
467
  if (!this._ready)
458
468
  setTimeout(() => {
package/src/index.ts CHANGED
@@ -8,7 +8,6 @@ import ColorString from "color-string";
8
8
  import { SideEffectManager } from "side-effect-manager";
9
9
  import { SlideViewer } from "./SlideViewer";
10
10
  import { refrigerator, addHooks } from "./Refrigerator";
11
- import { noop } from "./utils";
12
11
 
13
12
  export { SlideViewer, refrigerator, addHooks };
14
13
 
@@ -25,10 +24,12 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
25
24
 
26
25
  const options = context.getAppOptions() || {};
27
26
  const debug = Boolean(options.debug);
27
+ const logger = make_logger(context);
28
+ logger.info("[Slide] setup @ " + __APP_VERSION__);
28
29
 
29
30
  const sideEffect = new SideEffectManager();
30
31
 
31
- // create ui
32
+ // Create UI
32
33
  const viewer = new SlideViewer({
33
34
  interactive: true,
34
35
  mode: "interactive",
@@ -36,7 +37,7 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
36
37
  enableGlobalClick: true,
37
38
  controller: debug,
38
39
  timestamp: make_timestamp(context),
39
- logger: make_logger(context),
40
+ logger,
40
41
  renderOptions: {
41
42
  minFPS: options.minFPS || 25,
42
43
  maxFPS: options.maxFPS || 30,
@@ -61,18 +62,18 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
61
62
  (window as any).slideViewer = viewer;
62
63
  }
63
64
 
64
- // mount ui
65
+ // Mount UI
65
66
  context.box.mountStyles(SlideViewer.styles);
66
67
  context.box.mountStage(viewer.$slide);
67
68
  context.box.mountFooter(viewer.$footer);
68
69
  context.box.mountContent(viewer.$content);
69
70
  sideEffect.addDisposer(() => viewer.destroy());
70
71
 
71
- // connect ui with netless app
72
- connect({ context, viewer, sideEffect, debug });
72
+ // Connect UI with Netless App
73
+ connect({ context, viewer, sideEffect, logger });
73
74
 
74
75
  onUnmount(context, () => {
75
- console.log("[Slide] destroy");
76
+ logger.info("[Slide] destroy");
76
77
  sideEffect.flushAll();
77
78
  });
78
79
  },
@@ -88,7 +89,6 @@ export function previewSlide(options: SlideViewerOptions & { container: HTMLElem
88
89
  container.appendChild(viewer.$content);
89
90
  container.appendChild(viewer.$footer);
90
91
  viewer.prepare(() => viewer.slide.renderSlide(1));
91
- viewer.slide.on("slideChange", page => viewer.setPage(page));
92
92
  return viewer;
93
93
  }
94
94
 
@@ -104,7 +104,7 @@ function make_timestamp(context: AppContext): () => number {
104
104
  }
105
105
  }
106
106
 
107
- function make_logger(context: AppContext) {
107
+ function make_logger(context: AppContext): { info: (msg: string) => void } {
108
108
  if (import.meta.env.DEV) {
109
109
  return { info: console.debug.bind(console) };
110
110
  }
@@ -155,11 +155,11 @@ interface ConnectParams {
155
155
  context: AppContext;
156
156
  viewer: SlideViewer;
157
157
  sideEffect: SideEffectManager;
158
- debug: boolean;
158
+ logger: { info: (msg: string) => void };
159
159
  }
160
160
 
161
- function connect({ context, viewer, sideEffect, debug }: ConnectParams) {
162
- const log = debug ? console.log.bind(console) : noop;
161
+ function connect({ context, viewer, sideEffect, logger }: ConnectParams) {
162
+ const log = import.meta.env.DEV ? console.log.bind(console) : logger.info.bind(logger);
163
163
 
164
164
  let whiteboard: WhiteBoardView | null = null;
165
165
 
@@ -229,9 +229,10 @@ function connect({ context, viewer, sideEffect, debug }: ConnectParams) {
229
229
 
230
230
  // save state
231
231
  slide.on("slideChange", page => {
232
- log("[Slide] page to", page);
233
- whiteboard && whiteboard.jumpPage(page - 1);
234
- viewer.setPage(page);
232
+ if (context.isWritable && whiteboard) {
233
+ log("[Slide] page to", page);
234
+ whiteboard.jumpPage(page - 1);
235
+ }
235
236
  });
236
237
 
237
238
  // handle ui events