import {avatarTemplate, escapeText, localizeDate} from "fwtoolkit" import type {Node} from "prosemirror-model" import {READ_ONLY_ROLES} from "../index.js" import {serializeHelp} from "../document_template/index.js" import {serializeComment} from "../comments/editors/index.js" import type {DocInfo, EditorUser} from "../types.js" export interface MarginBoxFilterOptions { track?: boolean comments?: boolean info?: boolean help?: boolean warning?: boolean commentsResolved?: boolean commentsOnlyMajor?: boolean commentsAuthor?: number trackAuthor?: number author?: number assigned?: number } export interface CommentAnswer { id: number | string user: number username: string date: number answer: unknown[] } export interface Comment { id: number user: number username: string date: number comment: unknown[] answers?: CommentAnswer[] isMajor?: boolean resolved?: boolean hidden?: boolean isGlobal?: boolean assignedUser?: number assignedUsername?: string } export interface TrackData { user: number username: string date: number before?: | string[] | {type: string; attrs?: {order?: number; level?: number}} after?: string[] } export interface Participant { id: number name: string } interface ContactPerson { id: number | string type?: string name?: string avatar?: string } export interface CommentMarginBox { type: "comment" data: Comment view: string active: boolean pos?: number } export interface TrackMarginBox { type: "insertion" | "deletion" | "format_change" | "block_change" data: TrackData node: Node view: string active: boolean pos?: number } export interface HelpMarginBox { type: "help" data: {active?: boolean; help: unknown} active?: boolean } export interface WarningMarginBox { type: "warning" data: {active?: boolean; warning: string} active?: boolean } export type MarginBox = | CommentMarginBox | TrackMarginBox | HelpMarginBox | WarningMarginBox interface MarginBoxOptionComment { answer?: boolean id: number | string commentId?: number | string user: number resolved?: boolean } /** A template for an answer to a comment */ const COMMENT_SHOW_MORE_THRESHOLD = 120 const COMMENT_TRUNCATE_LENGTH = 110 function commentContentTemplate({ serialized, isGlobal }: { serialized: {html: string; text: string} isGlobal: boolean }): string { if (isGlobal || serialized.text.length <= COMMENT_SHOW_MORE_THRESHOLD) { return `
${serialized.html}
` } const truncatedText = `${escapeText( serialized.text.slice(0, COMMENT_TRUNCATE_LENGTH - 1) )}…` return `` } /** A template for an answer to a comment */ const answerCommentTemplate = ({ answer, author, commentId, activeCommentAnswerId, active, user, isGlobal }: { answer: CommentAnswer author: ContactPerson | undefined commentId: number | string activeCommentAnswerId: number | string | undefined active: boolean user: EditorUser isGlobal: boolean }) => { const serialized = serializeComment(answer.answer) return `${localizeDate(answer.date)}
${localizeDate(comment.date)}
${localizeDate(comment.date)}
${node.type.name === "text" ? `${gettext("ca.")} ` : ""}${localizeDate(data.date * 60000, "minutes")}
${truncatedText}