@netless/app-slide 0.0.33 → 0.0.38

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.33",
3
+ "version": "0.0.38",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,9 +11,9 @@
11
11
  ],
12
12
  "devDependencies": {
13
13
  "@netless/app-shared": "^0.1.1",
14
- "@netless/slide": "^0.1.37",
14
+ "@netless/slide": "^0.1.40",
15
15
  "@types/color-string": "^1.5.2",
16
- "color-string": "^1.8.2",
16
+ "color-string": "^1.9.0",
17
17
  "side-effect-manager": "^0.1.5",
18
18
  "vanilla-lazyload": "^17.5.0"
19
19
  },
@@ -1,9 +1,11 @@
1
+ import { SideEffectManager } from "side-effect-manager";
1
2
  import { Slide, SLIDE_EVENTS } from "@netless/slide";
2
3
  import { DocsViewer } from "../DocsViewer";
3
4
  import { createDocsViewerPages, DefaultUrl } from "../SlideController";
4
5
  import { cachedGetBgColor } from "../utils/bgcolor";
5
6
  import { clamp } from "../utils/helpers";
6
7
  import { log } from "../utils/logger";
8
+ import style from "../style.scss?inline";
7
9
 
8
10
  export interface PreviewParams {
9
11
  container: HTMLElement;
@@ -44,9 +46,12 @@ export class SlidePreviewer {
44
46
  public debug = import.meta.env.DEV;
45
47
 
46
48
  public $slide!: HTMLDivElement;
49
+
50
+ private readonly sideEffect = new SideEffectManager();
51
+
47
52
  public ready = false;
48
53
  private resolveReady!: () => void;
49
- public readonly readyPromise = new Promise<void>((resolve) => {
54
+ public readonly readyPromise = new Promise<void>(resolve => {
50
55
  this.resolveReady = () => {
51
56
  this.ready = true;
52
57
  resolve();
@@ -66,9 +71,29 @@ export class SlidePreviewer {
66
71
 
67
72
  public render() {
68
73
  this.viewer.$content.appendChild(this.renderSlideContainer());
74
+ this.sideEffect.addEventListener(window, "keydown", ev => {
75
+ if (this.slide) {
76
+ switch (ev.key) {
77
+ case "ArrowUp":
78
+ case "ArrowLeft": {
79
+ this.slide.prevStep();
80
+ break;
81
+ }
82
+ case "ArrowRight":
83
+ case "ArrowDown": {
84
+ this.slide.nextStep();
85
+ break;
86
+ }
87
+ default: {
88
+ break;
89
+ }
90
+ }
91
+ }
92
+ });
69
93
  }
70
94
 
71
95
  public mount(taskId: string, url: string) {
96
+ this.target.appendChild(this.renderStyle());
72
97
  this.target.appendChild(this.viewer.$content);
73
98
  this.target.appendChild(this.viewer.$footer);
74
99
 
@@ -93,6 +118,12 @@ export class SlidePreviewer {
93
118
  this.slide.renderSlide(1);
94
119
  }
95
120
 
121
+ protected renderStyle(): HTMLElement {
122
+ const element = document.createElement("style");
123
+ element.appendChild(document.createTextNode(style));
124
+ return element;
125
+ }
126
+
96
127
  protected registerEventListeners() {
97
128
  if (!this.slide) return;
98
129
  const { slide } = this;
@@ -127,6 +158,7 @@ export class SlidePreviewer {
127
158
 
128
159
  private destroyed = false;
129
160
  public destroy() {
161
+ this.sideEffect.flushAll();
130
162
  if (this.slide && !this.destroyed) {
131
163
  log("[Slide] destroy slide (once)");
132
164
  this.slide.destroy();
@@ -138,7 +170,7 @@ export class SlidePreviewer {
138
170
  protected refreshPages = () => {
139
171
  if (this.slide) {
140
172
  this.viewer.pages = createDocsViewerPages(this.slide);
141
- this.viewer.setPageIndex(this.getPageIndex(this.slide.slideCount));
173
+ this.viewer.setPageIndex(this.getPageIndex(this.slide.slideState.currentSlideIndex));
142
174
  }
143
175
  };
144
176
 
package/src/index.ts CHANGED
@@ -22,11 +22,15 @@ export { SlidePreviewer, default as previewSlide } from "./SlidePreviewer";
22
22
 
23
23
  export type { Attributes, AddHooks, FreezableSlide };
24
24
 
25
+ export const version = "0.0.37";
26
+
25
27
  export { DefaultUrl, apps, FreezerLength, addHooks };
26
28
 
27
29
  const SlideApp: NetlessApp<Attributes> = {
28
30
  kind: "Slide",
29
31
  setup(context) {
32
+ console.log("[Slide] setup @ " + version);
33
+
30
34
  if (context.getIsWritable()) {
31
35
  ensureAttributes(context, EmptyAttributes);
32
36
  }
@@ -44,6 +48,11 @@ const SlideApp: NetlessApp<Attributes> = {
44
48
 
45
49
  const box = context.getBox();
46
50
  box.mountStyles(styles);
51
+ try {
52
+ box.$content.dataset.appSlideVersion = version;
53
+ } catch {
54
+ // ignore
55
+ }
47
56
 
48
57
  // must exist because of view
49
58
  const baseScenePath = context.getInitScenePath() as string;