Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions javascript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface ISharedBase extends IObservableDisposable {
* Implement an API for Context information on the shared information.
* This is used by, for example, docregistry to share the file-path of the edited content.
*/
export interface ISharedDocument extends ISharedBase {
interface ISharedDocumentNoSource extends ISharedBase {
/**
* Document version
*/
Expand Down Expand Up @@ -117,6 +117,26 @@ export interface ISharedDocument extends ISharedBase {
readonly changed: ISignal<this, DocumentChange>;
}

/**
* Implement an API for Context information on the shared information.
* This is used by, for example, docregistry to share the file-path of the edited content.
*/
export interface ISharedDocument extends ISharedDocumentNoSource {
/**
* Get the document source.
*
* @returns Source.
*/
getSource(): string | JSONValue;

/**
* Set the document source.
*
* @param value New source.
*/
setSource(value: string | JSONValue): void;
}

/**
* The ISharedText interface defines models that can be bound to a text editor like CodeMirror.
*/
Expand Down Expand Up @@ -158,7 +178,7 @@ export interface ISharedText extends ISharedBase {
/**
* Text/Markdown/Code files are represented as ISharedFile
*/
export interface ISharedFile extends ISharedDocument, ISharedText {
export interface ISharedFile extends ISharedDocumentNoSource, ISharedText {
/**
* The changed signal.
*/
Expand Down
32 changes: 32 additions & 0 deletions javascript/src/ydocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,38 @@ export abstract class YDocument<T extends DocumentChange>
}
}

/**
* Get the document source
*
* @returns The source
*/
get source(): JSONValue | string {
return this.getSource();
}

/**
* Set the document source
*
* @param value The source to set
*/
set source(value: JSONValue | string) {
this.setSource(value);
}

/**
* Get the document source
*
* @returns The source
*/
abstract getSource(): JSONValue | string;

/**
* Set the document source
*
* @param value The source to set
*/
abstract setSource(value: JSONValue | string): void;

/**
* Undo an operation.
*/
Expand Down
20 changes: 19 additions & 1 deletion javascript/src/ynotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
|----------------------------------------------------------------------------*/

import type * as nbformat from '@jupyterlab/nbformat';
import { JSONExt, PartialJSONValue } from '@lumino/coreutils';
import { JSONExt, JSONValue, PartialJSONValue } from '@lumino/coreutils';
import { ISignal, Signal } from '@lumino/signaling';
import * as Y from 'yjs';
import type {
Expand Down Expand Up @@ -404,6 +404,24 @@ export class YNotebook
});
}

/**
* Get the notebook source
*
* @returns The notebook
*/
getSource(): JSONValue {
return this.toJSON() as JSONValue;
}

/**
* Set the notebook source
*
* @param value The notebook
*/
setSource(value: JSONValue): void {
this.fromJSON(value as nbformat.INotebookContent);
}

/**
* Override the notebook with a JSON-serialized document.
*
Expand Down
Loading