|
1 | | -// @ts-nocheck |
2 | 1 | import { |
3 | | - Cell, |
4 | 2 | CodeCell, |
5 | | - CellModel, |
6 | | - CodeCellModel, |
7 | | - MarkdownCellModel, |
8 | | - RawCellModel |
| 3 | + CodeCellModel |
9 | 4 | } from '@jupyterlab/cells'; |
10 | 5 | import { NotebookPanel } from '@jupyterlab/notebook'; |
11 | | -import { KernelMessage } from '@jupyterlab/services'; |
12 | 6 | import { |
13 | 7 | CellChange, |
14 | 8 | createMutex, |
15 | | - ISharedCodeCell, |
16 | | - ISharedMarkdownCell, |
17 | | - ISharedRawCell, |
18 | | - YCodeCell |
| 9 | + ISharedCodeCell |
19 | 10 | } from '@jupyter/ydoc'; |
20 | 11 | import { IOutputAreaModel, OutputAreaModel } from '@jupyterlab/outputarea'; |
| 12 | +import { IOutputModel } from '@jupyterlab/rendermime'; |
21 | 13 | import { requestAPI } from './handler'; |
22 | | -import { CellList } from '@jupyterlab/notebook'; |
23 | 14 |
|
24 | 15 | import { ObservableList } from '@jupyterlab/observables'; |
25 | 16 |
|
@@ -130,84 +121,59 @@ CodeCellModel.prototype.onOutputsChange = function ( |
130 | 121 | event: IOutputAreaModel.ChangedArgs |
131 | 122 | ) { |
132 | 123 | console.debug('Inside onOutputsChange, called with event: ', event); |
133 | | - return |
134 | | - // @ts-ignore |
135 | | - const codeCell = this.sharedModel as YCodeCell; |
136 | | - globalModelDBMutex(() => { |
137 | | - if (event.type == 'remove') { |
138 | | - codeCell.updateOutputs(event.oldIndex, event.oldValues.length, []); |
139 | | - } |
140 | | - }); |
141 | 124 | }; |
142 | 125 |
|
| 126 | + |
| 127 | +/* A new OutputAreaModel that loads outputs from outputs service */ |
143 | 128 | class RtcOutputAreaModel extends OutputAreaModel implements IOutputAreaModel{ |
144 | | - /** |
145 | | - * Construct a new observable outputs instance. |
146 | | - */ |
147 | 129 | constructor(options: IOutputAreaModel.IOptions = {}) { |
148 | 130 | super({...options, values: []}) |
| 131 | + // @ts-ignore |
149 | 132 | this._trusted = !!options.trusted; |
| 133 | + // @ts-ignore |
150 | 134 | this.contentFactory = |
151 | 135 | options.contentFactory || OutputAreaModel.defaultContentFactory; |
152 | 136 | this.list = new ObservableList<IOutputModel>(); |
| 137 | + // @ts-ignore |
| 138 | + this.list.changed.connect(this._onListChanged, this); |
153 | 139 | if (options.values) { |
154 | 140 | // Create an array to store promises for each value |
155 | | - const valuePromises = options.values.map((value, originalIndex) => { |
156 | | - console.log("originalIndex: ", originalIndex, ", value: ", value); |
157 | | - // If value has a URL, fetch the data, otherwise just use the value directly |
| 141 | + const valuePromises = options.values.map((value, index) => { |
| 142 | + console.debug("output #${index}, value: ${value}"); |
| 143 | + // @ts-ignore |
158 | 144 | if (value.metadata?.url) { |
| 145 | + // @ts-ignore |
159 | 146 | return requestAPI(value.metadata.url) |
160 | 147 | .then(data => { |
161 | | - console.log("data from outputs service: " , data) |
162 | | - return {data, originalIndex} |
| 148 | + return data |
163 | 149 | }) |
164 | 150 | .catch(error => { |
165 | 151 | console.error('Error fetching output:', error); |
166 | | - // If fetch fails, return original value to maintain order |
167 | | - return { data: null, originalIndex }; |
| 152 | + return null; |
168 | 153 | }); |
169 | 154 | } else { |
170 | 155 | // For values without url, return immediately with original value |
171 | | - return Promise.resolve({ data: value, originalIndex }); |
| 156 | + return Promise.resolve(value); |
172 | 157 | } |
173 | 158 | }); |
174 | 159 |
|
175 | 160 | // Wait for all promises to resolve and add values in original order |
176 | 161 | Promise.all(valuePromises) |
177 | 162 | .then(results => { |
178 | | - // Sort by original index to maintain order |
179 | | - results.sort((a, b) => a.originalIndex - b.originalIndex); |
180 | | - |
181 | | - console.log("After fetching outputs...") |
| 163 | + console.log("After fetching from outputs service:") |
182 | 164 | // Add each value in order |
183 | | - results.forEach((result) => { |
184 | | - console.log("originalIndex: ", result.originalIndex, ", data: ", result.data) |
185 | | - if(result.data && !this.isDisposed){ |
186 | | - const index = this._add(result.data) - 1; |
| 165 | + results.forEach((data, index) => { |
| 166 | + console.debug("output #${index}, data: ${data}"); |
| 167 | + if(data && !this.isDisposed){ |
| 168 | + // @ts-ignore |
| 169 | + const index = this._add(data) - 1; |
187 | 170 | const item = this.list.get(index); |
| 171 | + // @ts-ignore |
188 | 172 | item.changed.connect(this._onGenericChange, this); |
189 | 173 | } |
190 | 174 | }); |
191 | | - |
192 | | - // Connect the list changed handler after all items are added |
193 | | - //this.list.changed.connect(this._onListChanged, this); |
194 | | - })/* |
195 | | - .catch(error => { |
196 | | - console.error('Error processing values:', error); |
197 | | - // If something goes wrong, fall back to original behavior |
198 | | - options.values.forEach(value => { |
199 | | - const index = this._add(value) - 1; |
200 | | - const item = this.list.get(index); |
201 | | - item.changed.connect(this._onGenericChange, this); |
202 | | - }); |
203 | | - this.list.changed.connect(this._onListChanged, this); |
204 | | - });*/ |
205 | | - } else { |
206 | | - // If no values, just connect the list changed handler |
207 | | - //this.list.changed.connect(this._onListChanged, this); |
| 175 | + }); |
208 | 176 | } |
209 | | - |
210 | | - this.list.changed.connect(this._onListChanged, this); |
211 | 177 | } |
212 | 178 | } |
213 | 179 |
|
|
0 commit comments