2020-07-21 13:20:51 +00:00
|
|
|
import {ActionGroup} from 'app/common/ActionGroup';
|
|
|
|
import {TableDataAction} from 'app/common/DocActions';
|
|
|
|
import {LocalPlugin} from 'app/common/plugin';
|
|
|
|
import {StringUnion} from 'app/common/StringUnion';
|
|
|
|
|
|
|
|
// Possible flavors of items in a list of documents.
|
|
|
|
export type DocEntryTag = ''|'sample'|'invite'|'shared';
|
|
|
|
|
|
|
|
export const OpenDocMode = StringUnion(
|
|
|
|
'default', // open doc with user's maximal access level
|
2020-08-14 16:40:39 +00:00
|
|
|
'view', // open doc limited to view access (if user has at least that level of access)
|
|
|
|
'fork', // as for 'view', but suggest a fork on any attempt to edit - the client will
|
|
|
|
// enable the editing UI experience and trigger a fork on any edit.
|
2020-07-21 13:20:51 +00:00
|
|
|
);
|
|
|
|
export type OpenDocMode = typeof OpenDocMode.type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an entry in the DocList.
|
|
|
|
*/
|
|
|
|
export interface DocEntry {
|
|
|
|
docId?: string; // Set for shared docs and invites
|
|
|
|
name: string;
|
|
|
|
mtime?: Date;
|
|
|
|
size?: number;
|
|
|
|
tag: DocEntryTag;
|
|
|
|
senderName?: string;
|
|
|
|
senderEmail?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DocCreationInfo {
|
|
|
|
id: string;
|
|
|
|
title: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This documents the members of the structure returned when a local
|
|
|
|
* grist document is opened.
|
|
|
|
*/
|
|
|
|
export interface OpenLocalDocResult {
|
|
|
|
docFD: number;
|
|
|
|
clientId: string; // the docFD is meaningful only in the context of this session
|
|
|
|
doc: {[tableId: string]: TableDataAction};
|
|
|
|
log: ActionGroup[];
|
|
|
|
plugins: LocalPlugin[];
|
2020-12-14 17:42:09 +00:00
|
|
|
recoveryMode?: boolean;
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface DocListAPI {
|
|
|
|
/**
|
|
|
|
* Returns a all known Grist documents and document invites to show in the doc list.
|
|
|
|
*/
|
|
|
|
getDocList(): Promise<{docs: DocEntry[], docInvites: DocEntry[]}>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new document, fetches it, and adds a table to it. Returns its name.
|
|
|
|
*/
|
|
|
|
createNewDoc(): Promise<string>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a copy of the given sample doc. Returns the name of the new document.
|
|
|
|
*/
|
|
|
|
importSampleDoc(sampleDocName: string): Promise<string>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes an upload, containing possibly multiple files, to create a single new document, and
|
|
|
|
* returns the new document's name.
|
|
|
|
*/
|
|
|
|
importDoc(uploadId: number): Promise<string>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a Grist document. Returns the name of the deleted document. If `deletePermanently` is
|
|
|
|
* true, the doc is deleted permanently rather than just moved to the trash.
|
|
|
|
*/
|
|
|
|
deleteDoc(docName: string, deletePermanently: boolean): Promise<string>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renames a document.
|
|
|
|
*/
|
|
|
|
renameDoc(oldName: string, newName: string): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a document, loads it, subscribes to its userAction events, and returns its metadata.
|
|
|
|
*/
|
2020-12-09 13:57:35 +00:00
|
|
|
openDoc(userDocName: string, openMode?: OpenDocMode,
|
|
|
|
linkParameters?: Record<string, string>): Promise<OpenLocalDocResult>;
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|