diff --git a/javascript/src/api.ts b/javascript/src/api.ts index a20b301..3eaf995 100644 --- a/javascript/src/api.ts +++ b/javascript/src/api.ts @@ -494,6 +494,8 @@ export interface ISharedBaseCell< toJSON(): nbformat.IBaseCell; } +export type IExecutionState = 'running' | 'idle'; + /** * Implements an API for nbformat.ICodeCell. */ @@ -509,6 +511,11 @@ export interface ISharedCodeCell */ execution_count: nbformat.ExecutionCount; + /** + * The code cell's execution state. + */ + executionState: IExecutionState; + /** * Cell outputs */ @@ -746,6 +753,13 @@ export type CellChange = SourceChange & { oldValue?: number; newValue?: number; }; + /** + * Cell execution state change + */ + executionStateChange?: { + oldValue?: IExecutionState; + newValue?: IExecutionState; + }; /** * Cell metadata change */ diff --git a/javascript/src/ycell.ts b/javascript/src/ycell.ts index 381fd3b..e60b3a1 100644 --- a/javascript/src/ycell.ts +++ b/javascript/src/ycell.ts @@ -10,6 +10,7 @@ import { Awareness } from 'y-protocols/awareness'; import * as Y from 'yjs'; import type { CellChange, + IExecutionState, IMapChange, ISharedAttachmentsCell, ISharedBaseCell, @@ -752,10 +753,10 @@ export class YCodeCell /** * The code cell's execution state. */ - get executionState(): 'running' | 'idle' { + get executionState(): IExecutionState { return this.ymodel.get('execution_state') ?? 'idle'; } - set executionState(state: 'running' | 'idle') { + set executionState(state: IExecutionState) { if (this.ymodel.get('execution_state') !== state) { this.transact(() => { this.ymodel.set('execution_state', state); @@ -913,6 +914,14 @@ export class YCodeCell }; } + if (modelEvent && modelEvent.keysChanged.has('execution_state')) { + const change = modelEvent.changes.keys.get('execution_state'); + changes.executionStateChange = { + oldValue: change!.oldValue, + newValue: this.ymodel.get('execution_state') + }; + } + return changes; }