document-util.ts


Overview

The document-util.ts file provides a set of utility functions designed for handling document-related operations within the application. These utilities primarily focus on:

This utility module supports features related to document viewing, annotation, and file handling workflows, integrating with constants, interface definitions, and external libraries like antd and lodash.


Functions

1. buildChunkHighlights

buildChunkHighlights(
  selectedChunk: IChunk | IReferenceChunk,
  size: { width: number; height: number }
): Array<{
  id: string;
  comment: { text: string; emoji: string };
  content: { text: string };
  position: { boundingRect: object; rects: object[]; pageNumber: number };
}>

2. isFileUploadDone

isFileUploadDone(file: UploadFile): boolean

3. getExtension

getExtension(name: string): string

4. isPdf

isPdf(name: string): boolean

5. getUnSupportedFilesCount

getUnSupportedFilesCount(message: string): number

6. isSupportedPreviewDocumentType

isSupportedPreviewDocumentType(fileExtension: string): boolean

7. isImage

isImage(image: string): boolean

Important Implementation Details


Interaction with Other Parts of the System

This file is a utility layer enabling document preview, annotation, and upload workflows, likely invoked by document viewer components, file upload handlers, and annotation managers.


Diagram: Function Flowchart

flowchart TD
    A[buildChunkHighlights] -->|uses| B[lodash.get]
    A -->|generates| C[UUID for id]
    D[isFileUploadDone] --> E[Checks file.status === 'done']
    F[getExtension] --> G[Extracts extension from filename]
    H[isPdf] --> F
    I[getUnSupportedFilesCount] --> J[Counts lines in message]
    K[isSupportedPreviewDocumentType] --> L[Checks SupportedPreviewDocumentTypes]
    M[isImage] --> N[Checks Images + 'svg']

Summary

The document-util.ts file encapsulates essential helper functions for document chunk highlighting, file type validation, and upload status checking. It integrates with key interface definitions and constants, supporting document preview and annotation features in the application. The utilities are designed for robustness, extensibility, and easy integration with UI components and backend data structures.