4 CommentThreadInterface,
5 EditorRequiresClientMethods,
6 InternalEventBusInterface,
9 } from '@proton/docs-shared'
10 import type { WordCountInfoCollection } from '@proton/docs-shared'
11 import type { UserState } from '@lexical/yjs'
12 import type { EditorOrchestratorInterface } from '../Services/Orchestrator/EditorOrchestratorInterface'
13 import type { ErrorInfo } from 'react'
14 import { ApplicationEvent } from '../Application/ApplicationEvent'
15 import { WordCountEvent } from './WordCountEvent'
16 import type { EditorEvent, EditorEventData } from '@proton/docs-shared'
18 /** Handle messages sent by the editor to the client */
19 export class EditorToClientRequestHandler implements EditorRequiresClientMethods {
21 private editorFrame: HTMLIFrameElement,
22 private readonly docOrchestrator: EditorOrchestratorInterface,
23 private readonly eventBus: InternalEventBusInterface,
26 async editorRequestsPropagationOfUpdate(message: RtsMessagePayload, debugSource: BroadcastSource): Promise<void> {
27 return this.docOrchestrator.editorRequestsPropagationOfUpdate(message, debugSource)
30 async editorReportingEvent(event: EditorEvent, data: EditorEventData[EditorEvent]): Promise<void> {
31 return this.docOrchestrator.editorReportingEvent(event, data)
34 async getTypersExcludingSelf(threadId: string): Promise<string[]> {
35 return this.docOrchestrator.getTypersExcludingSelf(threadId)
38 async createComment(content: string, threadID: string): Promise<CommentInterface | undefined> {
39 return this.docOrchestrator.createComment(content, threadID)
42 async beganTypingInThread(threadID: string): Promise<void> {
43 return this.docOrchestrator.beganTypingInThread(threadID)
46 async stoppedTypingInThread(threadID: string): Promise<void> {
47 return this.docOrchestrator.stoppedTypingInThread(threadID)
50 async unresolveThread(threadId: string): Promise<boolean> {
51 return this.docOrchestrator.unresolveThread(threadId)
54 async editComment(threadID: string, commentID: string, content: string): Promise<boolean> {
55 return this.docOrchestrator.editComment(threadID, commentID, content)
58 async deleteComment(threadID: string, commentID: string): Promise<boolean> {
59 return this.docOrchestrator.deleteComment(threadID, commentID)
62 async getAllThreads(): Promise<CommentThreadInterface[]> {
63 return this.docOrchestrator.getAllThreads()
66 async createCommentThread(
67 commentContent: string,
69 createMarkNode?: boolean,
70 ): Promise<CommentThreadInterface | undefined> {
71 return this.docOrchestrator.createCommentThread(commentContent, markID, createMarkNode)
74 async createSuggestionThread(
76 commentContent: string,
77 suggestionType: SuggestionSummaryType,
78 ): Promise<CommentThreadInterface | undefined> {
79 return this.docOrchestrator.createSuggestionThread(suggestionID, commentContent, suggestionType)
82 async resolveThread(threadId: string): Promise<boolean> {
83 return this.docOrchestrator.resolveThread(threadId)
86 async acceptSuggestion(threadId: string, summary: string): Promise<boolean> {
87 return this.docOrchestrator.acceptSuggestion(threadId, summary)
90 async rejectSuggestion(threadId: string, summary?: string): Promise<boolean> {
91 return this.docOrchestrator.rejectSuggestion(threadId, summary)
94 async reopenSuggestion(threadId: string): Promise<boolean> {
95 return this.docOrchestrator.reopenSuggestion(threadId)
98 async deleteThread(id: string): Promise<boolean> {
99 return this.docOrchestrator.deleteThread(id)
102 async markThreadAsRead(id: string): Promise<void> {
103 return this.docOrchestrator.markThreadAsRead(id)
106 async handleAwarenessStateUpdate(states: UserState[]): Promise<void> {
107 return this.docOrchestrator.handleAwarenessStateUpdate(states)
110 async openLink(url: string): Promise<void> {
111 const link = document.createElement('a')
113 link.target = '_blank'
114 link.rel = 'noopener noreferrer'
119 async reportUserInterfaceError(
121 extraInfo?: { irrecoverable?: boolean; errorInfo?: ErrorInfo; lockEditor?: boolean },
123 this.docOrchestrator.editorReportingError(error.message, {
124 irrecoverable: extraInfo?.irrecoverable,
125 lockEditor: extraInfo?.lockEditor,
129 async reportWordCount(wordCountInfo: WordCountInfoCollection): Promise<void> {
130 this.eventBus.publish({
131 type: WordCountEvent,
132 payload: wordCountInfo,
136 updateFrameSize(size: number): void {
137 if (this.editorFrame) {
138 this.editorFrame.style.setProperty('--print-min-height', `${size}px`)
142 showGenericAlertModal(message: string): void {
143 this.eventBus.publish({
144 type: ApplicationEvent.GeneralUserDisplayableErrorOccurred,
146 translatedError: message,
151 async fetchExternalImageAsBase64(url: string): Promise<string | undefined> {
152 return this.docOrchestrator.fetchExternalImageAsBase64(url)