Skip to content

Commit 4c70f27

Browse files
committed
feat: When a user has the permission to write, they just readonly the ppt \ docsview
1 parent fd7d104 commit 4c70f27

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/app-pdfjs.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface PDFjsAppOptions extends Pick<PDFViewerOptions, "pdfjsLib" | "wo
3030
maxCameraScale?: number
3131
/** Custom logger. Default: a logger that reports to the whiteboard server. */
3232
readonly log?: Logger
33+
/** justDocsViewReadonly is used to set the docs view readonly, it will be used in the docs view, and the docs view will be readonly when the app is initialized */
34+
justDocsViewReadonly?: true;
3335
}
3436

3537
const DefaultMaxCameraScale = 3
@@ -71,6 +73,10 @@ export class AppPDFViewer extends PDFViewer {
7173
super.onRenderError(reason)
7274
this.log && this.log(`[PDFjs]: render error ${reason}`)
7375
}
76+
77+
setDocsViewReadonly(bol:boolean) {
78+
this.docsViewReadonly = bol
79+
}
7480
}
7581

7682
const createPDFViewer = (
@@ -247,6 +253,10 @@ export const NetlessAppPDFjs: NetlessApp<PDFjsAppAttributes, {}, PDFjsAppOptions
247253
app.syncPDFView = syncPDFView
248254
app.log = log
249255

256+
if (options.justDocsViewReadonly) {
257+
app.setDocsViewReadonly(true)
258+
}
259+
250260
// Prepare scenes.
251261
if (context.isAddApp) app.ready.then(() => {
252262
const pagesLength = app.numPages()

src/pdf-viewer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ export class PDFViewer implements IDisposable<void> {
155155
touched: { [page: number]: true } = Object.create(null)
156156
pageIndex = 0
157157

158+
protected docsViewReadonly = false
159+
158160
constructor(options: PDFViewerOptions) {
159161
const pdfjsLib = options.pdfjsLib || 'https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.min.mjs'
160162
const workerSrc = options.workerSrc || inferWorkerSrc(pdfjsLib)
@@ -334,7 +336,7 @@ export class PDFViewer implements IDisposable<void> {
334336
pageNumber.appendChild(this.totalPageDOM)
335337

336338
this.dispose.add(listen(window, 'keydown', ev => {
337-
if (this.readonly || this.isEditable(ev.target)) return
339+
if (this.readonly || this.isEditable(ev.target) || this.docsViewReadonly) return
338340
if (ev.key == 'ArrowUp' || ev.key == 'ArrowLeft')
339341
this.onNewPageIndex(this.pageIndex - 1, 'keydown')
340342
else if (ev.key == 'ArrowDown' || ev.key == 'ArrowRight')

0 commit comments

Comments
 (0)