@netless/forge-imagery-doc 0.1.1 → 0.1.3-appha.1
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/changelog.md +4 -0
- package/dist/Container.d.ts +1 -1
- package/dist/Container.d.ts.map +1 -1
- package/dist/ContinuousContainer.d.ts +5 -5
- package/dist/ContinuousContainer.d.ts.map +1 -1
- package/dist/FooterView.d.ts +7 -1
- package/dist/FooterView.d.ts.map +1 -1
- package/dist/ImageryDoc.d.ts +22 -18
- package/dist/ImageryDoc.d.ts.map +1 -1
- package/dist/ImageryDocApplication.d.ts +4 -4
- package/dist/ImageryDocApplication.d.ts.map +1 -1
- package/dist/ImageryDocPermissions.d.ts +7 -46
- package/dist/ImageryDocPermissions.d.ts.map +1 -1
- package/dist/InfinityScroll.d.ts +1 -1
- package/dist/InfinityScroll.d.ts.map +1 -1
- package/dist/LazyImage.d.ts.map +1 -1
- package/dist/SingleContainer.d.ts +6 -6
- package/dist/SingleContainer.d.ts.map +1 -1
- package/dist/imagery-doc.esm.js +163 -228
- package/dist/imagery-doc.esm.js.map +3 -3
- package/dist/imagery-doc.js +165 -230
- package/dist/imagery-doc.js.map +3 -3
- package/dist/index.d.ts +4 -4
- package/package.json +5 -4
- package/src/Container.ts +6 -6
- package/src/ContinuousContainer.ts +134 -135
- package/src/FooterView.ts +157 -125
- package/src/ImageryDoc.ts +22 -17
- package/src/ImageryDocApplication.ts +208 -198
- package/src/ImageryDocPermissions.ts +12 -118
- package/src/InfinityScroll.ts +43 -42
- package/src/LazyImage.ts +55 -55
- package/src/SingleContainer.ts +237 -226
- package/src/icons.ts +3 -3
- package/src/index.ts +4 -4
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {AbstractApplication} from
|
|
2
|
-
import {Whiteboard, WhiteboardApplication, WhiteboardPermissionFlag} from
|
|
3
|
-
import * as Y from
|
|
4
|
-
|
|
5
|
-
import {ImageryDoc} from
|
|
6
|
-
import {LazyImage} from
|
|
7
|
-
import {Container} from
|
|
8
|
-
import {ImageryDocPermissionFlag, ImageryDocPermissions} from
|
|
9
|
-
import {FooterView} from
|
|
10
|
-
import {ContinuousContainer} from
|
|
11
|
-
import {SingleContainer} from
|
|
1
|
+
import { AbstractApplication } from '@netless/forge-room';
|
|
2
|
+
import { Whiteboard, WhiteboardApplication, WhiteboardPermissionFlag } from '@netless/forge-whiteboard';
|
|
3
|
+
import * as Y from 'yjs';
|
|
4
|
+
|
|
5
|
+
import { ImageryDoc } from './ImageryDoc';
|
|
6
|
+
import { LazyImage } from './LazyImage';
|
|
7
|
+
import { Container } from './Container';
|
|
8
|
+
import { ImageryDocPermissionFlag, ImageryDocPermissions } from './ImageryDocPermissions';
|
|
9
|
+
import { FooterView } from './FooterView';
|
|
10
|
+
import { ContinuousContainer } from './ContinuousContainer';
|
|
11
|
+
import { SingleContainer } from './SingleContainer';
|
|
12
12
|
|
|
13
13
|
export interface ImageryDocOption {
|
|
14
14
|
images: {
|
|
@@ -20,206 +20,216 @@ export interface ImageryDocOption {
|
|
|
20
20
|
* 从指定的白板 id 继承白板权限以及工具栏配置
|
|
21
21
|
*/
|
|
22
22
|
inheritWhiteboardId?: string;
|
|
23
|
-
displayMode:
|
|
23
|
+
displayMode: 'continuous' | 'single';
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export const IMAGERY_DOC_APP_NAME =
|
|
26
|
+
export const IMAGERY_DOC_APP_NAME = 'imagery_doc';
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* 需用户自行保证 ImageryDocApplication.view 的高宽比一致
|
|
30
30
|
*/
|
|
31
31
|
export class ImageryDocApplication extends AbstractApplication<ImageryDocOption, ImageryDoc> {
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
33
|
+
static applicationName = IMAGERY_DOC_APP_NAME;
|
|
34
|
+
|
|
35
|
+
public readonly name: string = IMAGERY_DOC_APP_NAME;
|
|
36
|
+
|
|
37
|
+
public emitter: ImageryDoc = new ImageryDoc();
|
|
38
|
+
|
|
39
|
+
private whiteboardApp!: WhiteboardApplication;
|
|
40
|
+
private whiteboard!: Whiteboard;
|
|
41
|
+
private container!: Container;
|
|
42
|
+
private rootView: HTMLDivElement = document.createElement('div');
|
|
43
|
+
private contentContainer: HTMLDivElement = document.createElement('div');
|
|
44
|
+
private whiteboardContainer: HTMLDivElement = document.createElement('div');
|
|
45
|
+
private footerContainer: HTMLDivElement = document.createElement('div');
|
|
46
|
+
private permissions!: ImageryDocPermissions;
|
|
47
|
+
private footer: FooterView;
|
|
48
|
+
private images: LazyImage[] = [];
|
|
49
|
+
|
|
50
|
+
public constructor() {
|
|
51
|
+
super();
|
|
52
|
+
this.rootView.setAttribute('data-forge-app', 'imagery-doc');
|
|
53
|
+
this.rootView.style.overflow = 'hidden';
|
|
54
|
+
this.rootView.style.userSelect = 'none';
|
|
55
|
+
this.rootView.style.backgroundColor = '#f9f9fc';
|
|
56
|
+
|
|
57
|
+
this.contentContainer.style.width = '100%';
|
|
58
|
+
this.contentContainer.style.height = '100%';
|
|
59
|
+
this.contentContainer.style.display = 'flex';
|
|
60
|
+
this.contentContainer.style.flexDirection = 'column';
|
|
61
|
+
|
|
62
|
+
this.footer = new FooterView(this.emitter);
|
|
63
|
+
this.rootView.appendChild(this.contentContainer);
|
|
64
|
+
|
|
65
|
+
this.emitter.on('renderStart', pageIndex => {
|
|
66
|
+
this.footer.prevPageState(pageIndex !== 0);
|
|
67
|
+
this.footer.nextPageState(pageIndex !== this.images.length - 1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
71
|
+
const that = this;
|
|
72
|
+
Object.defineProperty(this.emitter, 'footView', {
|
|
73
|
+
get(): HTMLDivElement {
|
|
74
|
+
return that.footerContainer;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this.emitter, 'view', {
|
|
78
|
+
get(): any {
|
|
79
|
+
return that.rootView;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this.emitter, 'permissions', {
|
|
83
|
+
get(): any {
|
|
84
|
+
return that.permissions;
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this.emitter, 'pageIndex', {
|
|
88
|
+
get(): any {
|
|
89
|
+
return that.container.pageIndex;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this.emitter, 'pageCount', {
|
|
93
|
+
get(): any {
|
|
94
|
+
return that.images.length;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(this.emitter, 'goto', {
|
|
98
|
+
get(): any {
|
|
99
|
+
return (index: number) => {
|
|
100
|
+
if (that.permissions.hasPermission(ImageryDocPermissionFlag.switchPage)) {
|
|
101
|
+
that.container.goto(index);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(this.emitter, 'imgContent', {
|
|
107
|
+
get(): any {
|
|
108
|
+
return (index: number) => {
|
|
109
|
+
return that.images[index].getImgContent();
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this.emitter, 'imgSize', {
|
|
114
|
+
get(): any {
|
|
115
|
+
return (index: number) => {
|
|
116
|
+
return {
|
|
117
|
+
width: that.images[index].width,
|
|
118
|
+
height: that.images[index].height,
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public async initialize(option: ImageryDocOption): Promise<void> {
|
|
126
|
+
const whiteboardApp = new WhiteboardApplication();
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
whiteboardApp.appDoc = this.appDoc;
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
whiteboardApp.appId = `${this.appId}_wb`;
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
whiteboardApp.userId = this.userId;
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
whiteboardApp.userManager = this.userManager;
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
whiteboardApp.deleteSubDoc = this.deleteSubDoc;
|
|
137
|
+
await whiteboardApp.initialize({
|
|
138
|
+
width: -1,
|
|
139
|
+
height: -1,
|
|
140
|
+
});
|
|
141
|
+
this.whiteboardApp = whiteboardApp;
|
|
142
|
+
this.whiteboard = whiteboardApp.emitter;
|
|
143
|
+
this.whiteboard.enableCameraByMouse = false;
|
|
144
|
+
this.whiteboard.enableCameraByTouch = false;
|
|
145
|
+
this.whiteboard.view.style.width = '100%';
|
|
146
|
+
this.whiteboard.view.style.height = '100%';
|
|
147
|
+
this.whiteboard.view.style.position = 'absolute';
|
|
148
|
+
this.whiteboard.view.style.top = '0';
|
|
149
|
+
this.whiteboard.view.style.left = '0';
|
|
150
|
+
this.whiteboard.setCanvasBackgroundColor('#f0f0f000');
|
|
151
|
+
|
|
152
|
+
if (option.displayMode === 'single') {
|
|
153
|
+
this.container = new SingleContainer(
|
|
154
|
+
this.getMap('single-container'),
|
|
155
|
+
whiteboardApp,
|
|
156
|
+
this.whiteboardContainer,
|
|
157
|
+
this.emitter,
|
|
158
|
+
);
|
|
159
|
+
} else {
|
|
160
|
+
this.container = new ContinuousContainer(
|
|
161
|
+
this.getMap('continuous-container'),
|
|
162
|
+
whiteboardApp,
|
|
163
|
+
this.whiteboardContainer,
|
|
164
|
+
this.emitter,
|
|
165
|
+
);
|
|
121
166
|
}
|
|
122
167
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.whiteboard.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this.whiteboard.view.style.height = "100%";
|
|
145
|
-
this.whiteboard.view.style.position = "absolute";
|
|
146
|
-
this.whiteboard.view.style.top = "0";
|
|
147
|
-
this.whiteboard.view.style.left = "0";
|
|
148
|
-
this.whiteboard.setCanvasBackgroundColor("#f0f0f000");
|
|
149
|
-
|
|
150
|
-
if (option.displayMode === "single") {
|
|
151
|
-
this.container = new SingleContainer(
|
|
152
|
-
this.getMap("single-container"),
|
|
153
|
-
whiteboardApp,
|
|
154
|
-
this.whiteboardContainer,
|
|
155
|
-
this.emitter,
|
|
156
|
-
);
|
|
157
|
-
} else {
|
|
158
|
-
this.container = new ContinuousContainer(
|
|
159
|
-
this.getMap("continuous-container"),
|
|
160
|
-
whiteboardApp,
|
|
161
|
-
this.whiteboardContainer,
|
|
162
|
-
this.emitter,
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
this.whiteboardContainer.style.position = "relative";
|
|
167
|
-
this.whiteboardContainer.style.flex = "1 1 auto";
|
|
168
|
-
this.whiteboardContainer.style.overflow = "hidden";
|
|
169
|
-
this.whiteboardContainer.appendChild(this.container.view);
|
|
170
|
-
this.whiteboardContainer.appendChild(this.whiteboard.view);
|
|
171
|
-
|
|
172
|
-
this.contentContainer.appendChild(this.whiteboardContainer);
|
|
173
|
-
this.contentContainer.appendChild(this.footerContainer);
|
|
174
|
-
this.footerContainer.appendChild(this.footer.root);
|
|
175
|
-
|
|
176
|
-
this.whiteboard.setViewModeToMain();
|
|
177
|
-
|
|
178
|
-
let i = 0;
|
|
179
|
-
this.whiteboard.permissions.addPermission(WhiteboardPermissionFlag.mainView);
|
|
180
|
-
while (i < option.images.length) {
|
|
181
|
-
const image = option.images[i];
|
|
182
|
-
this.images[i] = new LazyImage(image.src, image.width, image.height);
|
|
183
|
-
this.container.append(this.images[i]);
|
|
184
|
-
if (option.displayMode === "single") {
|
|
185
|
-
this.whiteboard.addPage(`doc_${i}`);
|
|
186
|
-
}
|
|
187
|
-
i += 1;
|
|
188
|
-
}
|
|
189
|
-
if (option.displayMode === "continuous") {
|
|
190
|
-
this.whiteboard.addPage("doc_continuous");
|
|
191
|
-
this.whiteboard.gotoPage("doc_continuous");
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (option.displayMode === "single") {
|
|
195
|
-
this.whiteboard.setViewModeToMain();
|
|
196
|
-
} else {
|
|
197
|
-
this.whiteboard.setViewModeToFree();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.permissions = new ImageryDocPermissions(this.userManager, (userId: string) => {
|
|
201
|
-
return this.userMap(userId);
|
|
202
|
-
});
|
|
203
|
-
this.permissions.addPermission(ImageryDocPermissionFlag.all);
|
|
204
|
-
this.whiteboardApp.disableViewModel();
|
|
205
|
-
this.container.init();
|
|
206
|
-
|
|
207
|
-
this.whiteboard.permissions.removePermission(WhiteboardPermissionFlag.mainView);
|
|
208
|
-
if (option.inheritWhiteboardId) {
|
|
209
|
-
whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return Promise.resolve(undefined);
|
|
168
|
+
this.whiteboardContainer.style.position = 'relative';
|
|
169
|
+
this.whiteboardContainer.style.flex = '1 1 auto';
|
|
170
|
+
this.whiteboardContainer.style.overflow = 'hidden';
|
|
171
|
+
this.whiteboardContainer.appendChild(this.container.view);
|
|
172
|
+
this.whiteboardContainer.appendChild(this.whiteboard.view);
|
|
173
|
+
|
|
174
|
+
this.contentContainer.appendChild(this.whiteboardContainer);
|
|
175
|
+
this.contentContainer.appendChild(this.footerContainer);
|
|
176
|
+
this.footerContainer.appendChild(this.footer.root);
|
|
177
|
+
|
|
178
|
+
let i = 0;
|
|
179
|
+
this.whiteboard.permissions.addPermission(WhiteboardPermissionFlag.mainView);
|
|
180
|
+
this.whiteboard.setViewModeToMain();
|
|
181
|
+
while (i < option.images.length) {
|
|
182
|
+
const image = option.images[i];
|
|
183
|
+
this.images[i] = new LazyImage(image.src, image.width, image.height);
|
|
184
|
+
this.container.append(this.images[i]);
|
|
185
|
+
if (option.displayMode === 'single') {
|
|
186
|
+
this.whiteboard.addPage(`doc_${i}`);
|
|
187
|
+
}
|
|
188
|
+
i += 1;
|
|
213
189
|
}
|
|
190
|
+
if (option.displayMode === 'continuous') {
|
|
191
|
+
this.whiteboard.addPage('doc_continuous');
|
|
192
|
+
this.whiteboard.gotoPage('doc_continuous');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.whiteboard.setViewModeToFree();
|
|
196
|
+
|
|
197
|
+
this.permissions = new ImageryDocPermissions(this.userManager, (userId: string) => {
|
|
198
|
+
return this.userMap(userId);
|
|
199
|
+
});
|
|
200
|
+
this.permissions.on('change', (userId: string, flags: ImageryDocPermissionFlag[], value: number) => {
|
|
201
|
+
this.emitter.emit('permissionChange', userId, flags, value);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
this.permissions.setPermission(ImageryDocPermissionFlag.all);
|
|
205
|
+
this.whiteboardApp.disableViewModel();
|
|
206
|
+
this.container.init();
|
|
214
207
|
|
|
215
|
-
|
|
216
|
-
|
|
208
|
+
this.whiteboard.permissions.removePermission(WhiteboardPermissionFlag.mainView);
|
|
209
|
+
if (option.inheritWhiteboardId) {
|
|
210
|
+
whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
|
|
217
211
|
}
|
|
218
212
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
213
|
+
this.emitter.emit('ready');
|
|
214
|
+
return Promise.resolve(undefined);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private userMap(userId: string): Y.Map<any> {
|
|
218
|
+
return this.getMap(`user/${userId}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public async dispose(removeSubDoc: boolean): Promise<void> {
|
|
222
|
+
if (removeSubDoc) {
|
|
223
|
+
this.deleteSubDoc(this.appId);
|
|
224
224
|
}
|
|
225
|
+
await this.whiteboardApp.dispose(removeSubDoc);
|
|
226
|
+
this.whiteboardApp.emitter.view.remove();
|
|
227
|
+
this.container.dispose();
|
|
228
|
+
this.permissions.dispose();
|
|
229
|
+
this.emitter.removeAllListeners();
|
|
230
|
+
return Promise.resolve(undefined);
|
|
231
|
+
}
|
|
225
232
|
}
|
|
233
|
+
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
window.__ImageryDocApplication = ImageryDocApplication;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import EventEmitter from "eventemitter3";
|
|
3
|
-
import * as Y from "yjs";
|
|
1
|
+
import { AbstractApplicationPermissions, ApplicationPermissionEvents } from '@netless/forge-room';
|
|
4
2
|
|
|
5
3
|
export enum ImageryDocPermissionFlag {
|
|
6
4
|
/**
|
|
@@ -27,7 +25,7 @@ export enum ImageryDocPermissionFlag {
|
|
|
27
25
|
ImageryDocPermissionFlag.sideBar
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
export interface ImageryDocPermissionEvents {
|
|
28
|
+
export interface ImageryDocPermissionEvents extends ApplicationPermissionEvents {
|
|
31
29
|
/**
|
|
32
30
|
* 当用户权限变更时触发
|
|
33
31
|
* @param { string } userId 对应 userId
|
|
@@ -37,123 +35,19 @@ export interface ImageryDocPermissionEvents {
|
|
|
37
35
|
change: (userId: string, flags: ImageryDocPermissionFlag[], value: number) => void;
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
export class ImageryDocPermissions extends
|
|
38
|
+
export class ImageryDocPermissions extends AbstractApplicationPermissions<ImageryDocPermissionFlag, ImageryDocPermissionEvents> {
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
private userManager: UserManager;
|
|
44
|
-
private observers: Map<string, any> = new Map();
|
|
45
|
-
|
|
46
|
-
public constructor(
|
|
47
|
-
userManager: UserManager,
|
|
48
|
-
requestUserMap: (userId: string) => Y.Map<any>,
|
|
49
|
-
) {
|
|
50
|
-
super();
|
|
51
|
-
this.userManager = userManager;
|
|
52
|
-
this.requestUserMap = requestUserMap;
|
|
53
|
-
this.createModel(this.userManager.selfId);
|
|
54
|
-
this.userManager.userIdList().forEach((userId) => {
|
|
55
|
-
this.addObserve(userId);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
this.userManager.on("join", this.handleUserJoin);
|
|
59
|
-
this.userManager.on("leave", this.handleUserLeave);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private handleUserLeave = (user: RoomUser) => {
|
|
63
|
-
const cb = this.observers.get(user.id);
|
|
64
|
-
if (cb) {
|
|
65
|
-
this.requestUserMap(user.id).unobserve(cb);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
private handleUserJoin = (user: RoomUser) => {
|
|
70
|
-
this.addObserve(user.id);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
private addObserve(userId: string) {
|
|
74
|
-
const observer = (evt: Y.YMapEvent<any>) => {
|
|
75
|
-
this.handleUserPermissionChange(userId, evt);
|
|
76
|
-
};
|
|
77
|
-
this.observers.set(userId, observer);
|
|
78
|
-
this.requestUserMap(userId).observe(observer)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private createModel(userId: string) {
|
|
82
|
-
const userMap = this.requestUserMap(userId);
|
|
83
|
-
if (!userMap.has("permission")) {
|
|
84
|
-
userMap.set("permission", 0);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private handleUserPermissionChange(userId: string, evt: Y.YMapEvent<any>) {
|
|
89
|
-
for (const [key, value] of evt.changes.keys.entries()) {
|
|
90
|
-
if (key === "permission") {
|
|
91
|
-
if (value.action === "add" || value.action === "update") {
|
|
92
|
-
const newValue = this.requestUserMap(userId).get("permission");
|
|
93
|
-
this.emit("change", userId, this.resolveFlags(newValue), newValue);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
40
|
+
/**
|
|
100
41
|
* 解析权限列表组合
|
|
101
42
|
* @param {number} value - 权限数字值
|
|
102
43
|
* @return {WhiteboardPermissionFlag[]} - 权限列表
|
|
103
44
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 获取权限列表组合对应的数值
|
|
114
|
-
* @param { string } userId 不传表示获取自己
|
|
115
|
-
*/
|
|
116
|
-
public getPermissionValue(userId?: string): number {
|
|
117
|
-
return this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* 获取权限列表
|
|
122
|
-
* @param {string=} userId 可选, 不传表示获取自己
|
|
123
|
-
*/
|
|
124
|
-
public getPermissionFlags(userId?: string): ImageryDocPermissionFlag[] {
|
|
125
|
-
const value = this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
|
|
126
|
-
return this.resolveFlags(value);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 返回对应 userId 是否有相应权限
|
|
131
|
-
* @param {string=} userId 可选, 不传表示返回自己是否有相应权限
|
|
132
|
-
* @param {WhiteboardPermissionFlag} flag
|
|
133
|
-
*/
|
|
134
|
-
public hasPermission(flag: ImageryDocPermissionFlag, userId?: string): boolean {
|
|
135
|
-
return ((this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0) & flag) !== 0;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 添加权限
|
|
140
|
-
* @param {WhiteboardPermissionFlag} flag 权限标记
|
|
141
|
-
* @param {string=} userId 可选, 为 userId 添加权限, 不传表示为自己添加权限
|
|
142
|
-
*/
|
|
143
|
-
public addPermission(flag: ImageryDocPermissionFlag, userId?: string) {
|
|
144
|
-
const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
|
|
145
|
-
const oldValue = userMap.get("permission") ?? 0;
|
|
146
|
-
this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue | flag);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 移除权限
|
|
151
|
-
* @param {WhiteboardPermissionFlag} flag 权限标记
|
|
152
|
-
* @param {string=} userId 可选, 为 userId 移除权限, 不传表示为自己移除权限
|
|
153
|
-
*/
|
|
154
|
-
public removePermission(flag: ImageryDocPermissionFlag, userId?: string) {
|
|
155
|
-
const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
|
|
156
|
-
const oldValue = userMap.get("permission") ?? 0;
|
|
157
|
-
this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue & (~flag));
|
|
158
|
-
}
|
|
45
|
+
public resolveFlags(value: number): ImageryDocPermissionFlag[] {
|
|
46
|
+
return [
|
|
47
|
+
ImageryDocPermissionFlag.switchPage,
|
|
48
|
+
ImageryDocPermissionFlag.sideBar,
|
|
49
|
+
ImageryDocPermissionFlag.camera,
|
|
50
|
+
].filter(v => (v & value) !== 0);
|
|
51
|
+
}
|
|
52
|
+
|
|
159
53
|
}
|