@netless/forge-slide 1.0.10 → 1.1.0-beta.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/build.mjs +2 -2
- package/dist/Slide.d.ts +10 -0
- package/dist/Slide.d.ts.map +1 -1
- package/dist/SlideApplication.d.ts +2 -1
- package/dist/SlideApplication.d.ts.map +1 -1
- package/dist/slide.esm.js +140 -18
- package/dist/slide.esm.js.map +4 -4
- package/dist/slide.js +140 -18
- package/dist/slide.js.map +4 -4
- package/package.json +5 -5
- package/src/Slide.ts +11 -0
- package/src/SlideApplication.ts +34 -28
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/forge-slide",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"module": "dist/
|
|
5
|
+
"main": "dist/slide.js",
|
|
6
|
+
"module": "dist/slide.esm.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@netless/slide": "^1.4.21"
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"eventemitter3": "^5.0.1",
|
|
13
13
|
"yjs": "^13.6.18",
|
|
14
14
|
"uuid": "^11.0.5",
|
|
15
|
-
"@netless/forge-room": "1.0.
|
|
16
|
-
"@netless/forge-whiteboard": "1.0.
|
|
15
|
+
"@netless/forge-room": "1.1.0-beta.2",
|
|
16
|
+
"@netless/forge-whiteboard": "1.1.0-beta.2"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [],
|
|
19
19
|
"author": "",
|
package/src/Slide.ts
CHANGED
|
@@ -93,4 +93,15 @@ export class SlideForge extends EventEmitter<SlideEvents> implements Application
|
|
|
93
93
|
* @param {number} index 页面索引
|
|
94
94
|
*/
|
|
95
95
|
public imgSize!: (index: number) => Promise<{width: number, height: number}>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 冻结当前幻灯片, 释放资源
|
|
99
|
+
* @param {() => void} [callback] 冻结完成回调
|
|
100
|
+
*/
|
|
101
|
+
public frozen!: (callback?: () => void) => void;
|
|
102
|
+
/**
|
|
103
|
+
* 解冻冻结的幻灯片, 重新获取资源
|
|
104
|
+
* @param {() => void} [callback] 解冻完成回调
|
|
105
|
+
*/
|
|
106
|
+
public release!: (callback?: () => void) => void;
|
|
96
107
|
}
|
package/src/SlideApplication.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { FooterView } from './FooterView';
|
|
|
7
7
|
import * as Y from 'yjs';
|
|
8
8
|
import { SideBarView } from './SiderBarView';
|
|
9
9
|
import { deepEqual } from './utils';
|
|
10
|
+
import { SlidePool } from './SlidePool';
|
|
10
11
|
|
|
11
12
|
export interface SlideApplicationOption {
|
|
12
13
|
prefix: string;
|
|
@@ -30,6 +31,7 @@ export const Slide_APP_NAME = 'forge_slide';
|
|
|
30
31
|
export class SlideApplication extends AbstractApplication<SlideApplicationOption, SlideForge> {
|
|
31
32
|
|
|
32
33
|
static applicationName = Slide_APP_NAME;
|
|
34
|
+
static slidePool: SlidePool = new SlidePool();
|
|
33
35
|
|
|
34
36
|
public readonly name: string = Slide_APP_NAME;
|
|
35
37
|
public readonly emitter: SlideForge = new SlideForge();
|
|
@@ -228,7 +230,20 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
228
230
|
return this.getImageSize(pageIndex);
|
|
229
231
|
},
|
|
230
232
|
});
|
|
231
|
-
this.
|
|
233
|
+
Object.defineProperty(this.emitter, 'frozen', {
|
|
234
|
+
writable: false,
|
|
235
|
+
enumerable: false,
|
|
236
|
+
value: (callback?: () => void) => {
|
|
237
|
+
return this.slide.frozen(callback);
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(this.emitter, 'release', {
|
|
241
|
+
writable: false,
|
|
242
|
+
enumerable: false,
|
|
243
|
+
value: (callback?: () => void) => {
|
|
244
|
+
return this.slide.release(callback);
|
|
245
|
+
},
|
|
246
|
+
});
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
private getPreviewImageUrl (pageIndex: number) {
|
|
@@ -276,27 +291,19 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
276
291
|
return preview.src;
|
|
277
292
|
}
|
|
278
293
|
|
|
279
|
-
private
|
|
280
|
-
this.isSyncing = false;
|
|
281
|
-
requestAnimationFrame(() => {
|
|
282
|
-
this.applySlideState().catch((error) => {
|
|
283
|
-
console.error('Error in applySlideState:', error);
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
private applySlideState = async () => {
|
|
294
|
+
private applySlideState = async (): Promise<void> => {
|
|
289
295
|
if (this.isSyncing) {
|
|
296
|
+
requestAnimationFrame(this.applySlideState);
|
|
290
297
|
return;
|
|
291
298
|
}
|
|
292
299
|
|
|
293
300
|
const lastSyncMessage = this.syncMessageQueue.pop();
|
|
294
301
|
if (!lastSyncMessage) {
|
|
295
|
-
return
|
|
302
|
+
return;
|
|
296
303
|
}
|
|
297
304
|
|
|
298
|
-
this.syncMessageQueue = [];
|
|
299
305
|
this.isSyncing = true;
|
|
306
|
+
this.syncMessageQueue = [];
|
|
300
307
|
const { state, dispatch } = lastSyncMessage;
|
|
301
308
|
let ignoreKeys: string[] | undefined = undefined;
|
|
302
309
|
if ( dispatch.type === 'mediaPlay' || dispatch.type === 'mediaPause' || dispatch.type === 'mediaFullscreen') {
|
|
@@ -305,7 +312,6 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
305
312
|
if (this.slide.slideState.currentSlideIndex < 0 || state.currentSlideIndex < 0) {
|
|
306
313
|
// @ts-ignore
|
|
307
314
|
await this.slide.receiveSyncHandler(dispatch);
|
|
308
|
-
return this.nextTick();
|
|
309
315
|
} else if (!deepEqual(this.slide.slideState, state, ignoreKeys)) {
|
|
310
316
|
await this.slide.setSlideState(state);
|
|
311
317
|
// @ts-ignore
|
|
@@ -313,7 +319,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
313
319
|
} else {
|
|
314
320
|
this.slide.emit(SLIDE_EVENTS.syncReceive, dispatch);
|
|
315
321
|
}
|
|
316
|
-
|
|
322
|
+
this.isSyncing = false;
|
|
317
323
|
|
|
318
324
|
};
|
|
319
325
|
|
|
@@ -358,7 +364,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
358
364
|
|
|
359
365
|
private async onFocusInstance() {
|
|
360
366
|
this.bindKeyBoardEvent();
|
|
361
|
-
|
|
367
|
+
await SlideApplication.slidePool.active(this.appId, this.slide);
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
private onRefocusInstance() {
|
|
@@ -380,6 +386,8 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
380
386
|
whiteboardApp.userManager = this.userManager;
|
|
381
387
|
// @ts-ignore
|
|
382
388
|
whiteboardApp.deleteSubDoc = this.deleteSubDoc;
|
|
389
|
+
// @ts-ignore
|
|
390
|
+
whiteboardApp.writableManager = this.writableManager;
|
|
383
391
|
|
|
384
392
|
const json = await fetch(`${option.prefix}/${option.taskId}/jsonOutput/slide-1.json`).then(res => res.json());
|
|
385
393
|
this.slideCount = json.slideCount;
|
|
@@ -419,11 +427,14 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
419
427
|
}
|
|
420
428
|
|
|
421
429
|
this.whiteboard.setViewModeToMain();
|
|
422
|
-
|
|
430
|
+
for (let i = 0; i < json.slideCount; i++) {
|
|
431
|
+
this.whiteboardApp.addPage(String(i), true);
|
|
432
|
+
}
|
|
433
|
+
this.whiteboard.setViewModeToFree();
|
|
423
434
|
|
|
424
435
|
this.slideContainer.setAttribute('builder', 'slide-builder');
|
|
425
436
|
|
|
426
|
-
|
|
437
|
+
await SlideApplication.slidePool.waitUntilReady(this.appId);
|
|
427
438
|
this.slide = new Slide({
|
|
428
439
|
...option.options,
|
|
429
440
|
interactive: true,
|
|
@@ -471,8 +482,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
471
482
|
if (slideIndex >= 0) {
|
|
472
483
|
this.sideBar.pauseGetPreviewImageSchedule();
|
|
473
484
|
this.whiteboardApp.emitter.view.style.opacity = '0';
|
|
474
|
-
this.whiteboardApp.emitter.
|
|
475
|
-
this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
|
|
485
|
+
this.whiteboardApp.emitter.gotoPage(String(slideIndex));
|
|
476
486
|
this.sideBar.hidden();
|
|
477
487
|
this.footer.changeIconToPause();
|
|
478
488
|
this.emitter.emit('renderStart', slideIndex);
|
|
@@ -485,8 +495,8 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
485
495
|
this.currentSlideIndex = slideIndex;
|
|
486
496
|
this.whiteboardApp.emitter.view.style.opacity = '1';
|
|
487
497
|
this.footer.setCurrentPageIndex(slideIndex);
|
|
488
|
-
|
|
489
|
-
|
|
498
|
+
SlideApplication.slidePool.active(this.appId, this.slide);
|
|
499
|
+
SlideApplication.slidePool.onRenderEnd(this.appId, this.window?.focused ?? false);
|
|
490
500
|
this.footer.changeIconToNextStep();
|
|
491
501
|
this.emitter.emit('renderEnd', slideIndex);
|
|
492
502
|
}
|
|
@@ -512,7 +522,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
512
522
|
} else {
|
|
513
523
|
this.slide.renderSlide(1);
|
|
514
524
|
}
|
|
515
|
-
this.permissions = new ForgeSlidePermissions(this.userManager, (userId: string) => {
|
|
525
|
+
this.permissions = new ForgeSlidePermissions(this.writableManager, this.userManager, (userId: string) => {
|
|
516
526
|
return this.userMap(userId);
|
|
517
527
|
});
|
|
518
528
|
this.permissions.on('change', (userId, flags, value) => {
|
|
@@ -551,10 +561,6 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
551
561
|
});
|
|
552
562
|
this.bindKeyBoardEvent();
|
|
553
563
|
}
|
|
554
|
-
// @ts-ignore
|
|
555
|
-
window.__forge_slide = this;
|
|
556
|
-
// @ts-ignore
|
|
557
|
-
window.slidePermissions = this.permissions;
|
|
558
564
|
return Promise.resolve(undefined);
|
|
559
565
|
}
|
|
560
566
|
|
|
@@ -573,7 +579,7 @@ export class SlideApplication extends AbstractApplication<SlideApplicationOption
|
|
|
573
579
|
this.getMap(this.name).unobserve(this.onSlideEventHandler);
|
|
574
580
|
this.permissions.dispose();
|
|
575
581
|
this.footer.dispose();
|
|
576
|
-
|
|
582
|
+
SlideApplication.slidePool.remove(this.appId);
|
|
577
583
|
}
|
|
578
584
|
|
|
579
585
|
}
|