import { Sheet, Workbook, WorkbookInstance, Cell } from '../sheet-engine/react'; import { ComponentProps, RefObject } from 'react'; import { ERROR_MESSAGES_FLAG } from './constants/shared-constants'; import { SmartContractQueryHandler } from './utils/after-update-cell'; import { CollaborationProps } from '../sync-local/types'; import * as Y from 'yjs'; export interface SheetUpdateData { data: Sheet[]; } export interface EditorValues { sheetEditorRef: RefObject; currentDataRef: React.MutableRefObject; ydocRef: React.RefObject; } export type OnboardingHandlerType = (params: { row: number; column: number; sheetEditorRef: React.RefObject; }) => { row: number; column: number; }; export type DataBlockApiKeyHandlerType = (params: { data: ErrorMessageHandlerReturnType; sheetEditorRef: React.RefObject; executeStringFunction: ({ functionCallString, sheetEditorRef, dataBlockRow, dataBlockColumn, handleSmartContractQuery, }: { functionCallString: string; sheetEditorRef: React.RefObject; dataBlockRow: number; dataBlockColumn: number; handleSmartContractQuery: SmartContractQueryHandler; }) => Promise; row: number; column: number; newValue: Cell; formulaResponseUiSync: (params: { row: number; column: number; newValue: Record; apiData: Array>; sheetEditorRef: React.RefObject; }) => void; }) => void; export interface DsheetProps { isNewSheet: boolean; setSelectedTemplate?: React.Dispatch>; setShowSmartContractModal?: React.Dispatch>; getDocumentTitle?: (dsheetId: string) => Promise; updateDocumentTitle?: (title: string) => void; isAuthorized: boolean; setShowFetchURLModal?: React.Dispatch>; setFetchingURLData?: (fetching: boolean) => void; setInputFetchURLDataBlock?: React.Dispatch>; renderNavbar?: (editorValues?: EditorValues) => JSX.Element; enableIndexeddbSync?: boolean; dsheetId: string; onChange?: (updateData: SheetUpdateData, encodedUpdate?: string) => void; collaboration?: CollaborationProps; username?: string; portalContent?: string; isReadOnly?: boolean; allowSheetDownload?: boolean; isTemplateOpen?: boolean; selectedTemplate?: string; onboardingComplete?: boolean; /** When `onboardingComplete` is omitted, read `localStorage.getItem(key)==='true'` (default key `onboardingComplete`). */ onboardingCompleteLocalStorageKey?: string; onboardingHandler?: OnboardingHandlerType; dataBlockApiKeyHandler?: DataBlockApiKeyHandlerType; setForceSheetRender?: React.Dispatch>; getCommentCellUI?: ComponentProps['getCommentCellUI']; commentData?: Object; toggleTemplateSidebar?: () => void; sheetEditorRef?: RefObject Promise; }>; storeApiKey?: (apiKeyName: string) => void; allowComments?: boolean; onDataBlockApiResponse?: (dataBlockName: string) => void; onDuneChartEmbed?: () => void; onSheetCountChange?: (sheetCount: number) => void; editorStateRef?: React.MutableRefObject<{ refreshIndexedDB: () => Promise; } | null>; handleSmartContractQuery?: SmartContractQueryHandler; enableLiveQuery?: boolean; liveQueryRefreshRate?: number; } export type BaseError = { message: string; functionName?: string; type: (typeof ERROR_MESSAGES_FLAG)[keyof typeof ERROR_MESSAGES_FLAG]; }; export type CustomError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.CUSTOM; reason: string; }; export type InvalidParamError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.INVALID_PARAM; }; export type MissingKeyError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.MISSING_KEY; }; export type EnsResolveError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.ENS; }; export type InvalidApiKeyError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.INVALID_API_KEY; apiKeyName?: string; }; export type RateLimitError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.RATE_LIMIT; apiKeyName?: string; }; export type NetworkError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.NETWORK_ERROR; apiKeyName?: string; }; export type DefaultError = BaseError & { type: typeof ERROR_MESSAGES_FLAG.DEFAULT; reason: string; }; export type ErrorMessageHandlerReturnType = InvalidParamError | MissingKeyError | RateLimitError | NetworkError | EnsResolveError | InvalidApiKeyError | CustomError | DefaultError;