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

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.
@@ -1,13 +1,13 @@
1
- import {Whiteboard, WhiteboardApplication, WhiteboardPermissionFlag} from "@netless/forge-whiteboard";
2
- import {ISlideConfig, Slide, SLIDE_EVENTS} from "@netless/slide";
3
- import {AbstractApplication} from "@netless/forge-room";
4
- import {SlideForge} from "./Slide";
5
- import {ForgeSlidePermissionFlag, ForgeSlidePermissions} from "./ForgeSlidePermession";
6
- import {FooterView} from "./FooterView";
7
- import * as Y from "yjs";
8
- import {SideBarView} from "./SiderBarView";
9
- import {deepEqual, delay} from "./utils";
10
- import { kvStore } from "@netless/forge-room";
1
+ import { Whiteboard, WhiteboardApplication, WhiteboardPermissionFlag } from '@netless/forge-whiteboard';
2
+ import { ISlideConfig, Slide, SLIDE_EVENTS } from '@netless/slide';
3
+ import { AbstractApplication, kvStore } from '@netless/forge-room';
4
+ import { SlideForge } from './Slide';
5
+ import { ForgeSlidePermissionFlag, ForgeSlidePermissions } from './ForgeSlidePermession';
6
+ import { FooterView } from './FooterView';
7
+ import * as Y from 'yjs';
8
+ import { SideBarView } from './SiderBarView';
9
+ import { deepEqual, delay } from './utils';
10
+ // import { slidePool } from './SlidePool';
11
11
 
12
12
  export interface SlideApplicationOption {
13
13
  prefix: string;
@@ -26,482 +26,520 @@ interface PreviewImage {
26
26
  height: number;
27
27
  }
28
28
 
29
- export const Slide_APP_NAME = "forge_slide";
29
+ export const Slide_APP_NAME = 'forge_slide';
30
30
 
31
31
  export class SlideApplication extends AbstractApplication<SlideApplicationOption, SlideForge> {
32
32
 
33
- static applicationName = Slide_APP_NAME;
34
-
35
- public readonly name: string = Slide_APP_NAME;
36
- public readonly emitter: SlideForge = new SlideForge();
37
-
38
- private whiteboardApp!: WhiteboardApplication;
39
- private whiteboard!: Whiteboard;
40
- private rootView: HTMLDivElement = document.createElement("div");
41
- private contentContainer: HTMLDivElement = document.createElement("div");
42
- private whiteboardContainer: HTMLDivElement = document.createElement("div");
43
- private slideContainer: HTMLDivElement = document.createElement("div");
44
- private permissions!: ForgeSlidePermissions;
45
- private footer: FooterView;
46
- private sideBar: SideBarView;
47
- private slide!: Slide;
48
- private currentSlideIndex: number = 0;
49
- private taskId: string = "";
50
- private prefix: string = "";
51
- private slideCount: number = 0;
52
-
53
- constructor() {
54
- super();
55
- (window as any).emitter = this.emitter;
56
- this.rootView.setAttribute("data-forge-app", Slide_APP_NAME);
57
- this.rootView.style.background = "#f0f0f0f0";
58
- this.rootView.style.overflow = "hidden";
59
-
60
- this.contentContainer.style.width = "100%";
61
- this.contentContainer.style.height = "100%";
62
- this.contentContainer.style.display = "flex";
63
- this.contentContainer.style.flexDirection = "column";
64
-
65
- this.slideContainer.style.width = "100%";
66
- this.slideContainer.style.height = "100%";
67
-
68
- this.footer = new FooterView();
69
- this.sideBar = new SideBarView();
70
- this.sideBar.on("pageChange", index => {
71
- if (index > 0 && index <= this.slideCount) {
72
- this.slide.renderSlide(index);
73
- }
74
- });
75
- this.footer.on("prevStep", () => {
76
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changeStep)) {
77
- return;
78
- }
79
- if (this.slide.mainSeqStep > 0 || this.slide.mainSeqState !== "idle") {
80
- this.slide.prevStep();
81
- } else if (this.currentSlideIndex > 1){
82
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
83
- return;
84
- }
85
- this.slide.renderSlide(this.currentSlideIndex - 1)
86
- }
87
- });
88
- this.footer.on("nextStep", () => {
89
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changeStep)) {
90
- return;
91
- }
92
- if (this.slide.mainSeqStep < this.slide.mainSeqLength) {
93
- this.slide.nextStep()
94
- } else {
95
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
96
- return;
97
- }
98
- this.slide.renderSlide(this.currentSlideIndex + 1)
99
- }
100
- });
101
- this.footer.on("prevPage", () => {
102
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
103
- return;
104
- }
105
- if (this.currentSlideIndex > 1) {
106
- this.slide.renderSlide(this.currentSlideIndex - 1);
107
- }
108
- });
109
- this.footer.on("nextPage", () => {
110
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
111
- return;
112
- }
113
- if (this.currentSlideIndex < this.slideCount) {
114
- this.slide.renderSlide(this.currentSlideIndex + 1);
115
- }
116
- });
117
-
118
- this.footer.on("sideBarToggle", () => {
119
- if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
120
- return;
121
- }
122
- if (this.sideBar.isShowSideBar) {
123
- this.sideBar.hidden();
124
- } else {
125
- this.sideBar.show();
126
- }
127
- })
128
-
129
- this.rootView.appendChild(this.contentContainer);
130
-
131
- this.emitter.on("renderStart", pageIndex => {
132
- this.footer.prevPageState(pageIndex !== 0);
133
- });
134
- const propertyConfig = {
135
- configurable: false,
136
- enumerable: false,
137
- writable: false
33
+ static applicationName = Slide_APP_NAME;
34
+
35
+ public readonly name: string = Slide_APP_NAME;
36
+ public readonly emitter: SlideForge = new SlideForge();
37
+
38
+ private whiteboardApp!: WhiteboardApplication;
39
+ private whiteboard!: Whiteboard;
40
+ private rootView: HTMLDivElement = document.createElement('div');
41
+ private contentContainer: HTMLDivElement = document.createElement('div');
42
+ private whiteboardContainer: HTMLDivElement = document.createElement('div');
43
+ private slideContainer: HTMLDivElement = document.createElement('div');
44
+ private permissions!: ForgeSlidePermissions;
45
+ private footer: FooterView;
46
+ private sideBar: SideBarView;
47
+ private slide!: Slide;
48
+ private currentSlideIndex: number = 0;
49
+ private taskId: string = '';
50
+ private prefix: string = '';
51
+ private slideCount: number = 0;
52
+
53
+ constructor() {
54
+ super();
55
+ (window as any).emitter = this.emitter;
56
+ this.rootView.setAttribute('data-forge-app', Slide_APP_NAME);
57
+ this.rootView.style.background = '#f0f0f0f0';
58
+ this.rootView.style.overflow = 'hidden';
59
+
60
+ this.contentContainer.style.width = '100%';
61
+ this.contentContainer.style.height = '100%';
62
+ this.contentContainer.style.display = 'flex';
63
+ this.contentContainer.style.flexDirection = 'column';
64
+
65
+ this.slideContainer.style.width = '100%';
66
+ this.slideContainer.style.height = '100%';
67
+
68
+ this.footer = new FooterView();
69
+ this.sideBar = new SideBarView();
70
+ this.sideBar.on('pageChange', index => {
71
+ if (index > 0 && index <= this.slideCount) {
72
+ this.slide.renderSlide(index);
73
+ }
74
+ });
75
+ this.footer.on('prevStep', () => {
76
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changeStep)) {
77
+ return;
78
+ }
79
+ if (this.slide.mainSeqStep > 0 || this.slide.mainSeqState !== 'idle') {
80
+ this.slide.prevStep();
81
+ } else if (this.currentSlideIndex > 1){
82
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
83
+ return;
138
84
  }
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
- },
219
- })
220
- }
221
-
222
- private getPreviewImageUrl (pageIndex: number) {
223
- if (pageIndex < 1 || pageIndex > this.slideCount) {
224
- throw new Error("pageIndex out of range");
85
+ this.slide.renderSlide(this.currentSlideIndex - 1);
86
+ }
87
+ });
88
+ this.footer.on('nextStep', () => {
89
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changeStep)) {
90
+ return;
91
+ }
92
+ if (this.slide.mainSeqStep < this.slide.mainSeqLength) {
93
+ this.slide.nextStep();
94
+ } else {
95
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
96
+ return;
225
97
  }
226
- return `${this.prefix}/${this.taskId}/preview/${pageIndex}.png`;
98
+ this.slide.renderSlide(this.currentSlideIndex + 1);
99
+ }
100
+ });
101
+ this.footer.on('prevPage', () => {
102
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
103
+ return;
104
+ }
105
+ if (this.currentSlideIndex > 1) {
106
+ this.slide.renderSlide(this.currentSlideIndex - 1);
107
+ }
108
+ });
109
+ this.footer.on('nextPage', () => {
110
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
111
+ return;
112
+ }
113
+ if (this.currentSlideIndex < this.slideCount) {
114
+ this.slide.renderSlide(this.currentSlideIndex + 1);
115
+ }
116
+ });
117
+
118
+ this.footer.on('sideBarToggle', () => {
119
+ if (!this.permissions.hasPermission(ForgeSlidePermissionFlag.changePage)) {
120
+ return;
121
+ }
122
+ if (this.sideBar.isShowSideBar) {
123
+ this.sideBar.hidden();
124
+ } else {
125
+ this.sideBar.show();
126
+ }
127
+ });
128
+
129
+ this.rootView.appendChild(this.contentContainer);
130
+
131
+ this.emitter.on('renderStart', pageIndex => {
132
+ this.footer.prevPageState(pageIndex !== 0);
133
+ });
134
+
135
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
136
+ const that = this;
137
+ Object.defineProperty(this.emitter, 'view', {
138
+ get(): any {
139
+ return that.rootView;
140
+ },
141
+ });
142
+ Object.defineProperty(this.emitter, 'permissions', {
143
+ get(): any {
144
+ return that.permissions;
145
+ },
146
+ });
147
+ Object.defineProperty(this.emitter, 'footView', {
148
+ get(): any {
149
+ return that.footer.root;
150
+ },
151
+ });
152
+ Object.defineProperty(this.emitter, 'sidebarView', {
153
+ get(): any {
154
+ return that.sideBar.root;
155
+ },
156
+ });
157
+ Object.defineProperty(this.emitter, 'pageIndex', {
158
+ get(): any {
159
+ return that.currentSlideIndex;
160
+ },
161
+ });
162
+ Object.defineProperty(this.emitter, 'pageCount', {
163
+ get(): any {
164
+ return that.slideCount;
165
+ },
166
+ });
167
+ Object.defineProperty(this.emitter, 'goto', {
168
+ writable: false,
169
+ enumerable: false,
170
+ value: (pageIndex: number) => {
171
+ this.sideBar.emit('pageChange', pageIndex);
172
+ },
173
+ });
174
+ Object.defineProperty(this.emitter, 'nextStep', {
175
+ writable: false,
176
+ enumerable: false,
177
+ value: () => {
178
+ this.footer.emit('nextStep');
179
+ },
180
+ });
181
+ Object.defineProperty(this.emitter, 'prevStep', {
182
+ writable: false,
183
+ enumerable: false,
184
+ value: () => {
185
+ this.footer.emit('prevStep');
186
+ },
187
+ });
188
+ Object.defineProperty(this.emitter, 'nextPage', {
189
+ writable: false,
190
+ enumerable: false,
191
+ value: () => {
192
+ this.footer.emit('nextPage');
193
+ },
194
+ });
195
+ Object.defineProperty(this.emitter, 'prevPage', {
196
+ writable: false,
197
+ enumerable: false,
198
+ value: () => {
199
+ this.footer.emit('prevPage');
200
+ },
201
+ });
202
+ Object.defineProperty(this.emitter, 'sideBarToggle', {
203
+ writable: false,
204
+ enumerable: false,
205
+ value: () => {
206
+ this.footer.emit('sideBarToggle');
207
+ },
208
+ });
209
+ Object.defineProperty(this.emitter, 'imgContent', {
210
+ writable: false,
211
+ enumerable: false,
212
+ value: (pageIndex: number) => {
213
+ return this.getImageContent(pageIndex);
214
+ },
215
+ });
216
+
217
+ Object.defineProperty(this.emitter, 'imgUrl', {
218
+ writable: false,
219
+ enumerable: false,
220
+ value: (pageIndex: number) => {
221
+ return this.getImageUrl(pageIndex);
222
+ },
223
+ });
224
+
225
+ Object.defineProperty(this.emitter, 'imgSize', {
226
+ writable: false,
227
+ enumerable: false,
228
+ value: (pageIndex: number) => {
229
+ return this.getImageSize(pageIndex);
230
+ },
231
+ });
232
+ }
233
+
234
+ private getPreviewImageUrl (pageIndex: number) {
235
+ if (pageIndex < 1 || pageIndex > this.slideCount) {
236
+ throw new Error('pageIndex out of range');
227
237
  }
228
-
229
- private async getPreviewImage(imageUrl: string) {
230
- const image = fetch(imageUrl);
231
- return await image.then(res => res.blob()).then(blob => {
232
- return new Promise<PreviewImage>(resolve => {
233
- const reader = new FileReader();
234
- reader.onloadend = () => {
235
- const base64Data = reader.result as string;
236
- const img = document.createElement("img");
237
- img.src = base64Data;
238
- img.onload = () => {
239
- resolve({
240
- url: imageUrl,
241
- src: base64Data,
242
- width: img.width,
243
- height: img.height,
244
- });
245
- }
246
- }
247
- reader.readAsDataURL(blob);
248
- })
249
- });
238
+ return `${this.prefix}/${this.taskId}/preview/${pageIndex}.png`;
239
+ }
240
+
241
+ private async getPreviewImage(imageUrl: string) {
242
+ const image = fetch(imageUrl);
243
+ return await image.then(res => res.blob()).then(blob => {
244
+ return new Promise<PreviewImage>(resolve => {
245
+ const reader = new FileReader();
246
+ reader.onloadend = () => {
247
+ const base64Data = reader.result as string;
248
+ const img = document.createElement('img');
249
+ img.src = base64Data;
250
+ img.onload = () => {
251
+ resolve({
252
+ url: imageUrl,
253
+ src: base64Data,
254
+ width: img.width,
255
+ height: img.height,
256
+ });
257
+ };
258
+ };
259
+ reader.readAsDataURL(blob);
260
+ });
261
+ });
262
+ }
263
+
264
+ private async getImageUrl(pageIndex: number) {
265
+ return this.getPreviewImageUrl(pageIndex);
266
+ }
267
+
268
+ private async getImageSize(pageIndex: number) {
269
+ const imageUrl = this.getPreviewImageUrl(pageIndex);
270
+ let preview: PreviewImage | null = null;
271
+ try {
272
+ const result = await kvStore.getItem(imageUrl);
273
+ preview = result ? JSON.parse(result) : null;
274
+ } catch (e) {
275
+ console.warn('kvStore getItem error', e);
250
276
  }
251
-
252
- private async getImageUrl(pageIndex: number) {
253
- return this.getPreviewImageUrl(pageIndex);
277
+ if (preview) {
278
+ return { width: preview.width, height: preview.height };
254
279
  }
255
-
256
- private async getImageSize(pageIndex: number) {
257
- const imageUrl = this.getPreviewImageUrl(pageIndex);
258
- let preview: PreviewImage | null = null;
259
- try {
260
- const result = await kvStore.getItem(imageUrl);
261
- preview = result ? JSON.parse(result) : null;
262
- } catch (e) {
263
- console.warn("kvStore getItem error", e);
264
- }
265
- if (preview) {
266
- return { width: preview.width, height: preview.height };
267
- }
268
- preview = await this.getPreviewImage(imageUrl);
269
- await kvStore.setItem(imageUrl, JSON.stringify(preview));
270
- return { width: preview.width, height: preview.height };
280
+ preview = await this.getPreviewImage(imageUrl);
281
+ await kvStore.setItem(imageUrl, JSON.stringify(preview));
282
+ return { width: preview.width, height: preview.height };
283
+ }
284
+
285
+ private async getImageContent(pageIndex: number) {
286
+ const imageUrl = this.getPreviewImageUrl(pageIndex);
287
+ let preview: PreviewImage | null = null;
288
+ try {
289
+ const result = await kvStore.getItem(imageUrl);
290
+ preview = result ? JSON.parse(result) : null;
291
+ } catch (e) {
292
+ console.warn('kvStore getItem error', e);
271
293
  }
272
-
273
- private async getImageContent(pageIndex: number) {
274
- const imageUrl = this.getPreviewImageUrl(pageIndex);
275
- let preview: PreviewImage | null = null;
276
- try {
277
- const result = await kvStore.getItem(imageUrl);
278
- preview = result ? JSON.parse(result) : null;
279
- } catch (e) {
280
- console.warn("kvStore getItem error", e);
281
- }
282
- if (preview) {
283
- return preview.src;
284
- }
285
- preview = await this.getPreviewImage(imageUrl);
286
- await kvStore.setItem(imageUrl, JSON.stringify(preview));
287
- return preview.src;
294
+ if (preview) {
295
+ return preview.src;
288
296
  }
289
-
290
- private applySlideState = async (slideState: any, lastDispatch: any) => {
291
- if (this.slide.slideState.currentSlideIndex < 0) {
292
- this.slide.emit(SLIDE_EVENTS.syncReceive, lastDispatch);
293
- return;
294
- }
295
- if (this.slide.slideState.currentSlideIndex > 0 && deepEqual(this.slide.slideState, slideState)) {
296
- this.slide.emit(SLIDE_EVENTS.syncReceive, lastDispatch);
297
- } else {
298
- await this.slide.setSlideState(slideState);
299
- await delay(200);
300
- this.slide.emit(SLIDE_EVENTS.syncReceive, lastDispatch);
301
- }
297
+ preview = await this.getPreviewImage(imageUrl);
298
+ await kvStore.setItem(imageUrl, JSON.stringify(preview));
299
+ return preview.src;
300
+ }
301
+
302
+ private applySlideState = async (slideState: any, lastDispatch: any) => {
303
+ if (this.slide.slideState.currentSlideIndex < 0) {
304
+ this.slide.emit(SLIDE_EVENTS.syncReceive, lastDispatch);
305
+ return;
302
306
  }
303
-
304
- private onSlideEventHandler = async (event: Y.YMapEvent<any>) => {
305
- for (const [key, value] of event.changes.keys.entries()) {
306
- if (key === "syncSlide") {
307
- if (value.action === "add" || value.action === "update") {
308
- const { slideState: slideStateFromServer, dispatch: dispatchFromServer } = this.getMap(this.name).get("syncSlide");
309
- this.applySlideState(slideStateFromServer, dispatchFromServer);
310
- }
311
- }
312
- }
307
+ if (this.slide.slideState.currentSlideIndex > 0 && deepEqual(this.slide.slideState, slideState)) {
308
+ this.slide.emit(SLIDE_EVENTS.syncReceive, lastDispatch);
309
+ } else {
310
+ await this.slide.setSlideState(slideState);
311
+ await delay(200);
312
+ this.slide.emit(SLIDE_EVENTS.syncReceive, lastDispatch);
313
313
  }
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");
314
+ };
315
+
316
+ private onSlideEventHandler = async (event: Y.YMapEvent<any>) => {
317
+ for (const [key, value] of event.changes.keys.entries()) {
318
+ if (key === 'syncSlide') {
319
+ if (value.action === 'add' || value.action === 'update') {
320
+ const { slideState: slideStateFromServer, dispatch: dispatchFromServer } = this.getMap(this.name).get('syncSlide');
321
+ this.applySlideState(slideStateFromServer, dispatchFromServer);
324
322
  }
323
+ }
325
324
  }
326
-
327
- private bindKeyBoardEvent() {
328
- document.addEventListener("keydown", this.keyBoardEvents);
325
+ };
326
+
327
+ private keyBoardEvents = (event: KeyboardEvent) => {
328
+ if (event.key === 'ArrowLeft') {
329
+ this.footer.emit('prevStep');
330
+ } else if (event.key === 'ArrowRight') {
331
+ this.footer.emit('nextStep');
332
+ } else if (event.key === 'ArrowUp') {
333
+ this.footer.emit('prevPage');
334
+ } else if (event.key === 'ArrowDown') {
335
+ this.footer.emit('nextPage');
329
336
  }
330
-
331
- private unbindKeyBoarEvent() {
332
- document.removeEventListener("keydown", this.keyBoardEvents);
337
+ };
338
+
339
+ private bindKeyBoardEvent() {
340
+ document.addEventListener('keydown', this.keyBoardEvents);
341
+ }
342
+
343
+ private unbindKeyBoardEvent() {
344
+ document.removeEventListener('keydown', this.keyBoardEvents);
345
+ }
346
+
347
+ private async onFocusInstance() {
348
+ this.bindKeyBoardEvent();
349
+ // await slidePool.active(this.appId, this.slide);
350
+ }
351
+
352
+ private onRefocusInstance() {
353
+ this.unbindKeyBoardEvent();
354
+ }
355
+
356
+
357
+ public async initialize(option: SlideApplicationOption): Promise<void> {
358
+ this.prefix = option.prefix;
359
+ this.taskId = option.taskId;
360
+ const whiteboardApp = new WhiteboardApplication();
361
+ // @ts-ignore
362
+ whiteboardApp.roomDoc = this.roomDoc;
363
+ // @ts-ignore
364
+ whiteboardApp.appId = `${option.taskId}_${this.appId}_wb`;
365
+ // @ts-ignore
366
+ whiteboardApp.userId = this.userId;
367
+ // @ts-ignore
368
+ whiteboardApp.userManager = this.userManager;
369
+ // @ts-ignore
370
+ whiteboardApp.applicationManager = this.applicationManager;
371
+
372
+ const json = await fetch(`${option.prefix}/${option.taskId}/jsonOutput/slide-1.json`).then(res => res.json());
373
+ this.slideCount = json.slideCount;
374
+ await whiteboardApp.initialize({
375
+ width: json.width,
376
+ height: json.height,
377
+ });
378
+ this.whiteboardApp = whiteboardApp;
379
+ this.whiteboard = whiteboardApp.emitter;
380
+ this.whiteboard.enableCameraByMouse = false;
381
+ this.whiteboard.enableCameraByTouch = false;
382
+ this.whiteboard.view.style.width = '100%';
383
+ this.whiteboard.view.style.height = '100%';
384
+ this.whiteboard.view.style.position = 'absolute';
385
+ this.whiteboard.view.style.top = '0';
386
+ this.whiteboard.view.style.left = '0';
387
+ this.whiteboard.view.style.zIndex = '4';
388
+ this.whiteboard.view.classList.add('slide-whiteboard');
389
+ this.whiteboard.permissions.addPermission(WhiteboardPermissionFlag.all);
390
+ this.whiteboard.setCanvasBackgroundColor('#f0f0f000');
391
+ this.whiteboardContainer.style.position = 'relative';
392
+ this.whiteboardContainer.style.flex = '0 0 auto';
393
+ this.whiteboardContainer.style.height = 'calc(100% - 24px)';
394
+ this.whiteboardContainer.classList.add('forge-slide-whiteboard-container');
395
+ this.whiteboardContainer.appendChild(this.whiteboard.view);
396
+ this.whiteboardContainer.appendChild(this.slideContainer);
397
+
398
+ this.contentContainer.appendChild(this.whiteboardContainer);
399
+ this.contentContainer.appendChild(this.footer.root);
400
+ this.contentContainer.appendChild(this.sideBar.root);
401
+
402
+ if (option.inheritWhiteboardId) {
403
+ whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
333
404
  }
334
405
 
335
- public async initialize(option: SlideApplicationOption): Promise<void> {
336
- this.prefix = option.prefix;
337
- this.taskId = option.taskId;
338
- const whiteboardApp = new WhiteboardApplication();
339
- // @ts-ignore
340
- whiteboardApp.roomDoc = this.roomDoc;
341
- // @ts-ignore
342
- whiteboardApp.appId = `${option.taskId}_wb`;
343
- // @ts-ignore
344
- whiteboardApp.userId = this.userId;
345
- // @ts-ignore
346
- whiteboardApp.userManager = this.userManager;
347
- // @ts-ignore
348
- whiteboardApp.applicationManager = this.applicationManager;
349
-
350
- const json = await fetch(`${option.prefix}/${option.taskId}/jsonOutput/slide-1.json`).then(res => res.json())
351
- this.slideCount = json.slideCount;
352
- await whiteboardApp.initialize({
353
- width: json.width,
354
- height: json.height,
355
- });
356
- this.whiteboardApp = whiteboardApp;
357
- this.whiteboard = whiteboardApp.emitter;
358
- this.whiteboard.enableCameraByMouse = false;
359
- this.whiteboard.enableCameraByTouch = false;
360
- this.whiteboard.view.style.width = "100%";
361
- this.whiteboard.view.style.height = "100%";
362
- this.whiteboard.view.style.position = "absolute";
363
- this.whiteboard.view.style.top = "0";
364
- this.whiteboard.view.style.left = "0";
365
- this.whiteboard.view.style.zIndex = "4";
366
- this.whiteboard.view.classList.add("slide-whiteboard");
367
- this.whiteboard.permissions.addPermission(WhiteboardPermissionFlag.all);
368
- this.whiteboard.setCanvasBackgroundColor("#f0f0f000");
369
- this.whiteboardContainer.style.position = "relative";
370
- this.whiteboardContainer.style.flex = "0 0 auto";
371
- this.whiteboardContainer.style.height = "calc(100% - 24px)";
372
- this.whiteboardContainer.classList.add("forge-slide-whiteboard-container");
373
- this.whiteboardContainer.appendChild(this.whiteboard.view);
374
- this.whiteboardContainer.appendChild(this.slideContainer);
375
-
376
- this.contentContainer.appendChild(this.whiteboardContainer);
377
- this.contentContainer.appendChild(this.footer.root);
378
- this.contentContainer.appendChild(this.sideBar.root);
379
-
380
- if (option.inheritWhiteboardId) {
381
- whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
382
- }
383
-
384
- this.whiteboard.setViewModeToMain();
385
-
386
-
387
- this.slideContainer.setAttribute("builder", "slide-builder")
388
- this.slide = new Slide({
389
- ...option.options,
390
- interactive: true,
391
- anchor: this.slideContainer,
392
- mode: "interactive",
393
- // logger: {
394
- // info: console.log,
395
- // warn: console.warn,
396
- // error: console.error,
397
- // },
398
- })
399
- this.slide.setResource(option.taskId, option.prefix);
400
- this.sideBar.initialize(json.slideCount, option);
401
-
402
- this.slide.on(SLIDE_EVENTS.syncDispatch, event => {
403
- this.getMap(this.name).set("syncSlide", {
404
- slideState: this.slide.slideState,
405
- dispatch: event,
406
- })
407
- })
408
-
409
- this.slide.on(SLIDE_EVENTS.mainSeqStepStart, (animateIndex: number) => {
410
- this.emitter.emit("mainSeqStepStart", animateIndex);
411
- })
412
-
413
- this.slide.on(SLIDE_EVENTS.mainSeqStepEnd, (animateIndex: number) => {
414
- this.emitter.emit("mainSeqStepEnd", animateIndex);
415
- })
416
-
417
- this.slide.on(SLIDE_EVENTS.animateStart, () => {
418
- this.sideBar.hidden();
419
- })
420
-
421
- this.slide.on(SLIDE_EVENTS.renderStart, (slideIndex) => {
422
- this.whiteboardApp.emitter.view.style.opacity = "0";
423
- this.whiteboardApp.emitter.addPage(`${slideIndex}`);
424
- this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
425
- this.emitter.emit("renderStart", slideIndex);
426
- this.sideBar.hidden();
427
- })
428
-
429
- this.slide.on(SLIDE_EVENTS.renderEnd, (slideIndex) => {
430
- this.currentSlideIndex = slideIndex;
431
- this.whiteboardApp.emitter.view.style.opacity = "1";
432
- this.emitter.emit("renderEnd", slideIndex);
433
- });
434
-
435
- this.slide.on(SLIDE_EVENTS.stateChange, (state) => {
436
- this.getMap(this.name).set("slideState", state)
437
- })
438
-
439
- this.getMap(this.name).observe(this.onSlideEventHandler);
440
-
441
- (window as any).slide = this.slide;
442
- (window as any).slideWhiteboard = this.whiteboardApp;
443
- (window as any).forgeSlide = this;
444
-
445
- const syncSlide = this.getMap(this.name).get("slideState");
446
- if (syncSlide && syncSlide.taskId === option.taskId) {
447
- this.slide.setSlideState(syncSlide)
406
+ this.whiteboard.setViewModeToMain();
407
+
408
+
409
+ this.slideContainer.setAttribute('builder', 'slide-builder');
410
+
411
+ // await slidePool.waitUntilReady(this.appId);
412
+ this.slide = new Slide({
413
+ ...option.options,
414
+ interactive: true,
415
+ anchor: this.slideContainer,
416
+ mode: 'interactive',
417
+ // logger: {
418
+ // info: console.log,
419
+ // warn: console.warn,
420
+ // error: console.error,
421
+ // },
422
+ });
423
+ this.slide.setResource(option.taskId, option.prefix);
424
+ this.sideBar.initialize(json.slideCount, option);
425
+
426
+ this.slide.on(SLIDE_EVENTS.syncDispatch, event => {
427
+ this.getMap(this.name).set('syncSlide', {
428
+ slideState: this.slide.slideState,
429
+ dispatch: event,
430
+ });
431
+ });
432
+
433
+ this.slide.on(SLIDE_EVENTS.mainSeqStepStart, (animateIndex: number) => {
434
+ this.emitter.emit('mainSeqStepStart', animateIndex);
435
+ });
436
+
437
+ this.slide.on(SLIDE_EVENTS.mainSeqStepEnd, (animateIndex: number) => {
438
+ this.emitter.emit('mainSeqStepEnd', animateIndex);
439
+ });
440
+
441
+ this.slide.on(SLIDE_EVENTS.animateStart, () => {
442
+ this.sideBar.hidden();
443
+ });
444
+
445
+ this.slide.on(SLIDE_EVENTS.renderError, ({ error, index }) => {
446
+ if (error.errorType === 'CANVAS_CRASH') {
447
+ this.slide.renderSlide(index);
448
+ }
449
+ });
450
+
451
+ this.slide.on(SLIDE_EVENTS.renderStart, (slideIndex) => {
452
+ this.whiteboardApp.emitter.view.style.opacity = '0';
453
+ this.whiteboardApp.emitter.addPage(`${slideIndex}`);
454
+ this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
455
+ this.sideBar.hidden();
456
+ const { slideState: slideStateFromServer, dispatch: dispatchFromServer } = this.getMap(this.name).get('syncSlide');
457
+ this.applySlideState(slideStateFromServer, dispatchFromServer);
458
+ this.emitter.emit('renderStart', slideIndex);
459
+ });
460
+
461
+ this.slide.on(SLIDE_EVENTS.renderEnd, (slideIndex) => {
462
+ this.currentSlideIndex = slideIndex;
463
+ this.whiteboardApp.emitter.view.style.opacity = '1';
464
+ // slidePool.active(this.appId, this.slide);
465
+ // slidePool.onRenderEnd(this.appId, this.window?.focused ?? false);
466
+ this.emitter.emit('renderEnd', slideIndex);
467
+ });
468
+
469
+ this.slide.on(SLIDE_EVENTS.stateChange, (state) => {
470
+ this.getMap(this.name).set('slideState', state);
471
+ });
472
+
473
+ this.getMap(this.name).observe(this.onSlideEventHandler);
474
+
475
+ (window as any).slide = this.slide;
476
+ (window as any).slideWhiteboard = this.whiteboardApp;
477
+ (window as any).forgeSlide = this;
478
+
479
+ const syncSlide = this.getMap(this.name).get('slideState');
480
+ if (syncSlide && syncSlide.taskId === option.taskId) {
481
+ this.slide.setSlideState(syncSlide);
482
+ } else {
483
+ this.slide.renderSlide(1);
484
+ }
485
+ this.permissions = new ForgeSlidePermissions(this.userManager, (userId: string) => {
486
+ return this.userMap(userId);
487
+ });
488
+ this.permissions.on('change', (userId, flags, value) => {
489
+ this.emitter.emit('permissionChange', userId, flags, value);
490
+ if (this.userId === userId) {
491
+ if (flags.includes(ForgeSlidePermissionFlag.clickAnim)) {
492
+ this.slideContainer.style.pointerEvents = 'auto';
448
493
  } else {
449
- this.slide.renderSlide(1);
494
+ this.slideContainer.style.pointerEvents = 'none';
450
495
  }
451
- this.permissions = new ForgeSlidePermissions(this.userManager, (userId: string) => {
452
- return this.userMap(userId);
453
- });
454
- this.permissions.on("change", (userId, flags, value) => {
455
- this.emitter.emit("permissionChange", userId, flags, value);
456
- if (this.userId === userId) {
457
- if (flags.includes(ForgeSlidePermissionFlag.clickAnim)) {
458
- this.slideContainer.style.pointerEvents = "auto";
459
- } else {
460
- this.slideContainer.style.pointerEvents = "none";
461
- }
462
- }
463
- });
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
- })
496
+ }
497
+ });
498
+ this.permissions.setPermission(ForgeSlidePermissionFlag.all);
499
+ this.whiteboardApp.disableViewModel();
500
+ if (this.window) {
501
+ let prevStatus = 'normal';
502
+ this.window.on('statusChange', (status) => {
503
+ if (prevStatus === 'minimized') {
504
+ this.onFocusInstance();
505
+ prevStatus = status;
506
+ return;
487
507
  }
488
- // @ts-ignore
489
- window.__forge_slide = this;
490
- // @ts-ignore
491
- window.slidePermissions = this.permissions;
492
- return Promise.resolve(undefined);
493
- }
494
-
495
- private userMap(userId: string): Y.Map<any> {
496
- return this.getMap(`user/${userId}`);
497
- }
498
-
499
- public async dispose(): Promise<void> {
500
- await this.whiteboardApp.dispose();
501
- this.rootView.parentElement?.removeChild(this.rootView);
502
- this.slide.destroy();
503
- this.sideBar.dispose();
504
- this.getMap(this.name).unobserve(this.onSlideEventHandler)
508
+ prevStatus = status;
509
+ if (status === 'normal') {
510
+ this.onFocusInstance();
511
+ } else if (status === 'minimized') {
512
+ this.onRefocusInstance();
513
+ }
514
+ });
515
+ this.window.on('focusedChange', (status) => {
516
+ if (status) {
517
+ this.onFocusInstance();
518
+ } else {
519
+ this.onRefocusInstance();
520
+ }
521
+ });
505
522
  }
523
+ // @ts-ignore
524
+ window.__forge_slide = this;
525
+ // @ts-ignore
526
+ window.slidePermissions = this.permissions;
527
+ return Promise.resolve(undefined);
528
+ }
529
+
530
+ private userMap(userId: string): Y.Map<any> {
531
+ return this.getMap(`user/${userId}`);
532
+ }
533
+
534
+ public async dispose(): Promise<void> {
535
+ await this.whiteboardApp.dispose();
536
+ this.rootView.parentElement?.removeChild(this.rootView);
537
+ this.slide.destroy();
538
+ this.sideBar.dispose();
539
+ this.getMap(this.name).unobserve(this.onSlideEventHandler);
540
+ this.permissions.dispose();
541
+ this.footer.dispose();
542
+ // slidePool.remove(this.appId);
543
+ }
506
544
 
507
545
  }