@netless/forge-slide 0.1.1-alpha.6 → 0.1.1-alpha.8

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/forge-slide",
3
- "version": "0.1.1-alpha.6",
3
+ "version": "0.1.1-alpha.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -7,6 +7,7 @@ interface SideBarViewEvents {
7
7
 
8
8
  export class SideBarView extends EventEmitter<SideBarViewEvents> {
9
9
  public readonly root: HTMLDivElement = document.createElement("div");
10
+ private isShow: boolean = false;
10
11
  private itemList: HTMLDivElement[] = [];
11
12
 
12
13
  public constructor() {
@@ -21,13 +22,14 @@ export class SideBarView extends EventEmitter<SideBarViewEvents> {
21
22
  this.root.style.zIndex = "5";
22
23
  this.root.style.transition = "left 0.3s ease-in-out";
23
24
  this.root.style.overflow = "auto";
24
- this.root.style.border = "1px solid #ccc";
25
- this.root.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.1)";
26
25
  this.root.style.display = "flex";
27
26
  this.root.style.flexDirection = "column";
28
27
  this.root.style.justifyContent = "flex-start";
29
28
  this.root.style.alignItems = "center";
29
+ }
30
30
 
31
+ get isShowSideBar(): boolean {
32
+ return this.isShow;
31
33
  }
32
34
 
33
35
  private onMouseOver = (itemContainer: HTMLDivElement) => {
@@ -50,7 +52,6 @@ export class SideBarView extends EventEmitter<SideBarViewEvents> {
50
52
  itemContainer.style.display = "flex";
51
53
  itemContainer.style.justifyContent = "center";
52
54
  itemContainer.style.alignItems = "flex-start";
53
- itemContainer.style.border = "7px solid transparent";
54
55
  itemContainer.style.position = "relative";
55
56
  itemContainer.style.borderRadius = "4px"
56
57
  itemContainer.style.transition = "border-color .3s";
@@ -81,6 +82,26 @@ export class SideBarView extends EventEmitter<SideBarViewEvents> {
81
82
  }
82
83
  }
83
84
 
85
+ public hidden() {
86
+ if (!this.root) {
87
+ return;
88
+ }
89
+ this.root.style.left = "-240px";
90
+ this.root.style.border = "none";
91
+ this.root.style.boxShadow = "none";
92
+ this.isShow = false;
93
+ }
94
+
95
+ public show() {
96
+ if (!this.root) {
97
+ return;
98
+ }
99
+ this.root.style.left = "0";
100
+ this.root.style.border = "1px solid #ccc";
101
+ this.root.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.1)";
102
+ this.isShow = true;
103
+ }
104
+
84
105
  public dispose() {
85
106
  this.itemList.forEach(item => {
86
107
  item.removeEventListener("mouseover", () => this.onMouseOver(item))
package/src/Slide.ts CHANGED
@@ -42,6 +42,8 @@ export class SlideForge extends EventEmitter<SlideEvents> implements Application
42
42
  public readonly view!: HTMLDivElement;
43
43
  public readonly permissions!: ForgeSlidePermissions;
44
44
  public readonly footView!: HTMLDivElement;
45
+ public readonly sideBarView!: HTMLDivElement;
46
+ public readonly whiteboardView!: HTMLDivElement;
45
47
  /**
46
48
  * 当前页面索引, 从 0 开始
47
49
  */
@@ -119,10 +119,10 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
119
119
  if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
120
120
  return;
121
121
  }
122
- if (this.sideBar.root.style.left === "0px") {
123
- this.sideBar.root.style.left = "-240px";
122
+ if (this.sideBar.isShowSideBar) {
123
+ this.sideBar.hidden();
124
124
  } else {
125
- this.sideBar.root.style.left = "0px";
125
+ this.sideBar.show();
126
126
  }
127
127
  })
128
128
 
@@ -131,97 +131,91 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
131
131
  this.emitter.on("renderStart", pageIndex => {
132
132
  this.footer.prevPageState(pageIndex !== 0);
133
133
  });
134
-
135
- const that = this;
136
- Object.defineProperty(this.emitter, "view", {
137
- get(): any {
138
- return that.rootView;
139
- }
140
- });
141
- Object.defineProperty(this.emitter, "permissions", {
142
- get(): any {
143
- return that.permissions;
144
- }
145
- });
146
- Object.defineProperty(this.emitter, "footView", {
147
- get(): any {
148
- return that.footer.root;
149
- }
150
- })
151
- Object.defineProperty(this.emitter, "pageIndex", {
152
- get(): any {
153
- return that.currentSlideIndex;
154
- }
155
- });
156
- Object.defineProperty(this.emitter, "pageCount", {
157
- get(): any {
158
- return that.slideCount;
159
- }
160
- });
161
- Object.defineProperty(this.emitter, "goto", {
162
- writable: false,
163
- enumerable: false,
164
- value: (pageIndex: number) => {
165
- this.sideBar.emit("pageChange", pageIndex);
166
- }
167
- });
168
- Object.defineProperty(this.emitter, "nextStep", {
169
- writable: false,
170
- enumerable: false,
171
- value: () => {
172
- this.footer.emit("nextStep");
173
- }
174
- })
175
- Object.defineProperty(this.emitter, "prevStep", {
176
- writable: false,
177
- enumerable: false,
178
- value: () => {
179
- this.footer.emit("prevStep");
180
- }
181
- })
182
- Object.defineProperty(this.emitter, "nextPage", {
183
- writable: false,
184
- enumerable: false,
185
- value: () => {
186
- this.footer.emit("nextPage");
187
- }
188
- })
189
- Object.defineProperty(this.emitter, "prevPage", {
190
- writable: false,
191
- enumerable: false,
192
- value: () => {
193
- this.footer.emit("prevPage");
194
- }
195
- })
196
- Object.defineProperty(this.emitter, "sideBarToggle", {
197
- writable: false,
198
- enumerable: false,
199
- value: () => {
200
- this.footer.emit("sideBarToggle");
201
- }
202
- })
203
- Object.defineProperty(this.emitter, "imgContent", {
204
- writable: false,
205
- enumerable: false,
206
- value: (pageIndex: number) => {
207
- return this.getImageContent(pageIndex);
208
- }
209
- })
210
-
211
- Object.defineProperty(this.emitter, "imgUrl", {
212
- writable: false,
134
+ const propertyConfig = {
135
+ configurable: false,
213
136
  enumerable: false,
214
- value: (pageIndex: number) => {
215
- return this.getImageUrl(pageIndex);
216
- }
217
- })
218
-
219
- Object.defineProperty(this.emitter, "imgSize", {
220
- writable: false,
221
- enumerable: false,
222
- value: (pageIndex: number) => {
223
- return this.getImageSize(pageIndex);
224
- }
137
+ writable: false
138
+ }
139
+ const that = this;
140
+ Object.defineProperties(this.emitter, {
141
+ view: {
142
+ get(): HTMLDivElement { return that.rootView }
143
+ },
144
+ permissions: {
145
+ get(): ForgeSlidePermissions { return that.permissions }
146
+ },
147
+ footView: {
148
+ get(): HTMLDivElement { return that.footer.root }
149
+ },
150
+ sidebarView: {
151
+ get(): HTMLDivElement { return that.sideBar.root }
152
+ },
153
+ whiteboardView: {
154
+ get(): HTMLDivElement { return that.whiteboard.view }
155
+ },
156
+ slideView: {
157
+ get(): HTMLDivElement { return that.slideContainer }
158
+ },
159
+ pageIndex: {
160
+ get(): number { return that.currentSlideIndex }
161
+ },
162
+ pageCount: {
163
+ get(): number { return that.slideCount }
164
+ },
165
+ goto: {
166
+ ...propertyConfig,
167
+ value: (pageIndex: number) => {
168
+ this.sideBar.emit("pageChange", pageIndex);
169
+ }
170
+ },
171
+ nextStep: {
172
+ ...propertyConfig,
173
+ value: () => {
174
+ this.footer.emit("nextStep");
175
+ }
176
+ },
177
+ prevStep: {
178
+ ...propertyConfig,
179
+ value: () => {
180
+ this.footer.emit("prevStep");
181
+ }
182
+ },
183
+ nextPage: {
184
+ ...propertyConfig,
185
+ value: () => {
186
+ this.footer.emit("nextPage");
187
+ }
188
+ },
189
+ prevPage: {
190
+ ...propertyConfig,
191
+ value: () => {
192
+ this.footer.emit("prevPage");
193
+ }
194
+ },
195
+ sideBarToggle: {
196
+ ...propertyConfig,
197
+ value: () => {
198
+ this.footer.emit("sideBarToggle");
199
+ }
200
+ },
201
+ imgContent: {
202
+ ...propertyConfig,
203
+ value: (pageIndex: number) => {
204
+ return this.getImageContent(pageIndex);
205
+ }
206
+ },
207
+ imgUrl: {
208
+ ...propertyConfig,
209
+ value: (pageIndex: number) => {
210
+ return this.getImageUrl(pageIndex);
211
+ }
212
+ },
213
+ imgSize: {
214
+ ...propertyConfig,
215
+ value: (pageIndex: number) => {
216
+ return this.getImageSize(pageIndex);
217
+ }
218
+ },
225
219
  })
226
220
  }
227
221
 
@@ -318,6 +312,26 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
318
312
  }
319
313
  }
320
314
 
315
+ private keyBoardEvents = (event: KeyboardEvent) => {
316
+ if (event.key === "ArrowLeft") {
317
+ this.footer.emit("prevStep");
318
+ } else if (event.key === "ArrowRight") {
319
+ this.footer.emit("nextStep");
320
+ } else if (event.key === "ArrowUp") {
321
+ this.footer.emit("prevPage");
322
+ } else if (event.key === "ArrowDown") {
323
+ this.footer.emit("nextPage");
324
+ }
325
+ }
326
+
327
+ private bindKeyBoardEvent() {
328
+ document.addEventListener("keydown", this.keyBoardEvents);
329
+ }
330
+
331
+ private unbindKeyBoarEvent() {
332
+ document.removeEventListener("keydown", this.keyBoardEvents);
333
+ }
334
+
321
335
  public async initialize(option: SlideApplicationOption): Promise<void> {
322
336
  this.prefix = option.prefix;
323
337
  this.taskId = option.taskId;
@@ -385,35 +399,40 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
385
399
  this.slide.setResource(option.taskId, option.prefix);
386
400
  this.sideBar.initialize(json.slideCount, option);
387
401
 
388
- this.slide.on("syncDispatch", event => {
402
+ this.slide.on(SLIDE_EVENTS.syncDispatch, event => {
389
403
  this.getMap(this.name).set("syncSlide", {
390
404
  slideState: this.slide.slideState,
391
405
  dispatch: event,
392
406
  })
393
407
  })
394
408
 
395
- this.slide.on("mainSeqStepStart", (animateIndex: number) => {
409
+ this.slide.on(SLIDE_EVENTS.mainSeqStepStart, (animateIndex: number) => {
396
410
  this.emitter.emit("mainSeqStepStart", animateIndex);
397
411
  })
398
412
 
399
- this.slide.on("mainSeqStepEnd", (animateIndex: number) => {
413
+ this.slide.on(SLIDE_EVENTS.mainSeqStepEnd, (animateIndex: number) => {
400
414
  this.emitter.emit("mainSeqStepEnd", animateIndex);
401
415
  })
402
416
 
403
- this.slide.on("renderStart", (slideIndex) => {
417
+ this.slide.on(SLIDE_EVENTS.animateStart, () => {
418
+ this.sideBar.hidden();
419
+ })
420
+
421
+ this.slide.on(SLIDE_EVENTS.renderStart, (slideIndex) => {
404
422
  this.whiteboardApp.emitter.view.style.opacity = "0";
405
423
  this.whiteboardApp.emitter.addPage(`${slideIndex}`);
406
424
  this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
407
425
  this.emitter.emit("renderStart", slideIndex);
426
+ this.sideBar.hidden();
408
427
  })
409
428
 
410
- this.slide.on("renderEnd", (slideIndex) => {
429
+ this.slide.on(SLIDE_EVENTS.renderEnd, (slideIndex) => {
411
430
  this.currentSlideIndex = slideIndex;
412
431
  this.whiteboardApp.emitter.view.style.opacity = "1";
413
432
  this.emitter.emit("renderEnd", slideIndex);
414
433
  });
415
434
 
416
- this.slide.on("stateChange", (state) => {
435
+ this.slide.on(SLIDE_EVENTS.stateChange, (state) => {
417
436
  this.getMap(this.name).set("slideState", state)
418
437
  })
419
438
 
@@ -442,8 +461,30 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
442
461
  }
443
462
  }
444
463
  });
445
- this.permissions.addPermission(ForgeSlidePermissionFlag.all);
446
464
  this.whiteboardApp.disableViewModel();
465
+ if (this.window) {
466
+ let prevStatus = "normal";
467
+ this.window.on("statusChange", (status) => {
468
+ if (prevStatus === "minimized") {
469
+ this.bindKeyBoardEvent();
470
+ prevStatus = status;
471
+ return;
472
+ }
473
+ prevStatus = status;
474
+ if (status === "normal") {
475
+ this.bindKeyBoardEvent();
476
+ } else if (status === "minimized") {
477
+ this.unbindKeyBoarEvent();
478
+ }
479
+ })
480
+ this.window.on("focusedChange", (status) => {
481
+ if (status) {
482
+ this.bindKeyBoardEvent();
483
+ } else {
484
+ this.unbindKeyBoarEvent();
485
+ }
486
+ })
487
+ }
447
488
  // @ts-ignore
448
489
  window.__forge_slide = this;
449
490
  // @ts-ignore
@@ -461,7 +502,6 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
461
502
  this.slide.destroy();
462
503
  this.sideBar.dispose();
463
504
  this.getMap(this.name).unobserve(this.onSlideEventHandler)
464
- return Promise.resolve(undefined);
465
505
  }
466
506
 
467
507
  }