@graphty/graphty-element / index / ProjectApi
Interface: ProjectApi ​
Defined in: graphty-element/src/session/projectFile.ts:181
Saving the whole session to one file, and opening one again.
Properties ​
dirty ​
readonlydirty:boolean
Defined in: graphty-element/src/session/projectFile.ts:188
Whether anything the file saves has changed since the last save or open. Undoing back to that point makes it false again. The selection and the extensions never set it.
name ​
readonlyname:string|null
Defined in: graphty-element/src/session/projectFile.ts:183
The project's name: from the file it was opened from, or rename. Null until one is given.
Methods ​
markSaved() ​
markSaved(
saved):void
Defined in: graphty-element/src/session/projectFile.ts:218
Record that a file save({ markSaved: false }) produced has been written. dirty clears unless something changed since that save, and undo returns to it as the save point.
Marking a save older than the last one marked, or than the last open, does nothing, and so does marking one twice or one save already marked.
Parameters ​
saved ​
What save returned.
Returns ​
void
Example ​
const saved = await session.project.save({ markSaved: false });
await writable.write(saved.text); // a failed write throws, and the project stays dirty
await writable.close();
session.project.markSaved(saved);open() ​
open(
source,options?):Promise<ProjectOpenReport>
Defined in: graphty-element/src/session/projectFile.ts:236
Open a graphty document or a data file: the one intake verb for an "Open..." door, so the caller never decides what a file is. A project replaces the session, with a fresh history; any other graphty document (a style, notes) is added as one undoable step; a data file is read into a load draft (opened: "graph", draft), as session.data.prepare reads it, and loads when the caller calls draft.load().
Parameters ​
source ​
The file, its bytes, or its text. Never a URL: nothing is fetched.
options? ​
Whether to discard unsaved changes, the file's name, the size limit.
Returns ​
Promise<ProjectOpenReport>
What came back and what did not.
Throws ​
A GraphtyError (as a rejection), leaving the session as it was: E_UNSAVED_CHANGES for a project over unsaved changes without discard, E_TOO_LARGE past the size limit, the codes session.data.prepare refuses a data file with (E_UNKNOWN_FORMAT for a file no format reads, E_PARSE_FAILED for one its format cannot read), E_UNKNOWN_FORMAT for embedded data in a dialect other than node-link, E_BAD_DOCUMENT for a malformed document, E_UNSUPPORTED_VERSION for a newer one, and E_UNSUPPORTED for one that requires a member kind this element does not read.
rename() ​
rename(
name):Promise<void>
Defined in: graphty-element/src/session/projectFile.ts:194
Rename the project. One undoable step, which sets dirty.
Parameters ​
name ​
string | null
The name, at most 256 characters; blank or null clears it.
Returns ​
Promise<void>
Settles once the step is recorded.
save() ​
save(
options?):Promise<SavedProject>
Defined in: graphty-element/src/session/projectFile.ts:202
Save the whole session as a graphty document. Clears dirty, unless markSaved is false.
Parameters ​
options? ​
What to leave out, and your own extensions.
Returns ​
Promise<SavedProject>
The file's text, and what it holds.
Throws ​
A GraphtyError (as a rejection) with E_BAD_COMMAND for an extension name that is not reverse-domain or a value over 64 KB.