@jupyterlab/cells 4.0.0-alpha.1 → 4.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/collapser.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/inputarea.d.ts +4 -0
- package/lib/inputarea.js +6 -0
- package/lib/inputarea.js.map +1 -1
- package/lib/model.d.ts +5 -0
- package/lib/model.js +23 -19
- package/lib/model.js.map +1 -1
- package/lib/resizeHandle.d.ts +0 -1
- package/lib/resizeHandle.js +9 -11
- package/lib/resizeHandle.js.map +1 -1
- package/lib/searchprovider.d.ts +142 -0
- package/lib/searchprovider.js +600 -0
- package/lib/searchprovider.js.map +1 -0
- package/lib/widget.d.ts +48 -8
- package/lib/widget.js +144 -63
- package/lib/widget.js.map +1 -1
- package/package.json +24 -22
- package/style/collapser.css +21 -4
- package/style/headerfooter.css +3 -3
- package/style/index.css +4 -2
- package/style/index.js +4 -2
- package/style/inputarea.css +19 -17
- package/style/placeholder.css +1 -1
- package/style/widget.css +97 -7
package/lib/widget.d.ts
CHANGED
|
@@ -3,17 +3,16 @@ import { IChangedArgs } from '@jupyterlab/coreutils';
|
|
|
3
3
|
import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
|
|
4
4
|
import { IObservableJSON, IObservableMap } from '@jupyterlab/observables';
|
|
5
5
|
import { IOutputPrompt, IStdin, OutputArea, Stdin } from '@jupyterlab/outputarea';
|
|
6
|
-
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
6
|
+
import { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
7
7
|
import { KernelMessage } from '@jupyterlab/services';
|
|
8
8
|
import { ITranslator } from '@jupyterlab/translation';
|
|
9
9
|
import { JSONObject, JSONValue, PartialJSONValue } from '@lumino/coreutils';
|
|
10
10
|
import { Message } from '@lumino/messaging';
|
|
11
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
11
12
|
import { Widget } from '@lumino/widgets';
|
|
12
13
|
import { ICellFooter, ICellHeader } from './headerfooter';
|
|
13
14
|
import { IInputPrompt, InputArea } from './inputarea';
|
|
14
15
|
import { IAttachmentsCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from './model';
|
|
15
|
-
import { Signal } from '@lumino/signaling';
|
|
16
|
-
export declare const MARKDOWN_HEADING_COLLAPSED = "jp-MarkdownHeadingCollapsed";
|
|
17
16
|
/** ****************************************************************************
|
|
18
17
|
* Cell
|
|
19
18
|
******************************************************************************/
|
|
@@ -37,6 +36,10 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
|
|
|
37
36
|
* The content factory used by the widget.
|
|
38
37
|
*/
|
|
39
38
|
readonly contentFactory: Cell.IContentFactory;
|
|
39
|
+
/**
|
|
40
|
+
* Signal to indicate that widget has changed visibly (in size, in type, etc)
|
|
41
|
+
*/
|
|
42
|
+
get displayChanged(): ISignal<this, void>;
|
|
40
43
|
/**
|
|
41
44
|
* Get the prompt node used by the cell.
|
|
42
45
|
*/
|
|
@@ -62,6 +65,10 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
|
|
|
62
65
|
*/
|
|
63
66
|
get readOnly(): boolean;
|
|
64
67
|
set readOnly(value: boolean);
|
|
68
|
+
/**
|
|
69
|
+
* Whether the cell is a placeholder that differ rendering
|
|
70
|
+
*/
|
|
71
|
+
isPlaceholder(): boolean;
|
|
65
72
|
/**
|
|
66
73
|
* Save view editable state to model
|
|
67
74
|
*/
|
|
@@ -127,9 +134,9 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
|
|
|
127
134
|
*/
|
|
128
135
|
protected onActivateRequest(msg: Message): void;
|
|
129
136
|
/**
|
|
130
|
-
* Handle `
|
|
137
|
+
* Handle `resize` messages.
|
|
131
138
|
*/
|
|
132
|
-
protected
|
|
139
|
+
protected onResize(msg: Widget.ResizeMessage): void;
|
|
133
140
|
/**
|
|
134
141
|
* Handle `update-request` messages.
|
|
135
142
|
*/
|
|
@@ -139,14 +146,17 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
|
|
|
139
146
|
*/
|
|
140
147
|
protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<PartialJSONValue | undefined>): void;
|
|
141
148
|
protected translator: ITranslator;
|
|
149
|
+
protected _displayChanged: Signal<this, void>;
|
|
142
150
|
private _readOnly;
|
|
143
151
|
private _model;
|
|
144
152
|
private _inputHidden;
|
|
145
153
|
private _input;
|
|
146
154
|
private _inputWrapper;
|
|
147
155
|
private _inputPlaceholder;
|
|
156
|
+
private _isPlaceholder;
|
|
148
157
|
private _syncCollapse;
|
|
149
158
|
private _syncEditable;
|
|
159
|
+
private _resizeDebouncer;
|
|
150
160
|
}
|
|
151
161
|
/**
|
|
152
162
|
* The namespace for the `Cell` class statics.
|
|
@@ -459,23 +469,43 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
|
|
|
459
469
|
*/
|
|
460
470
|
get ready(): Promise<void>;
|
|
461
471
|
/**
|
|
462
|
-
* Text that represents the heading if cell is a heading.
|
|
472
|
+
* Text that represents the highest heading (i.e. lowest level) if cell is a heading.
|
|
463
473
|
* Returns empty string if not a heading.
|
|
464
474
|
*/
|
|
465
475
|
get headingInfo(): {
|
|
466
476
|
text: string;
|
|
467
477
|
level: number;
|
|
468
478
|
};
|
|
479
|
+
/**
|
|
480
|
+
* Whether the heading is collapsed or not.
|
|
481
|
+
*/
|
|
469
482
|
get headingCollapsed(): boolean;
|
|
470
483
|
set headingCollapsed(value: boolean);
|
|
484
|
+
/**
|
|
485
|
+
* Number of collapsed sub cells.
|
|
486
|
+
*/
|
|
471
487
|
get numberChildNodes(): number;
|
|
472
488
|
set numberChildNodes(value: number);
|
|
473
|
-
|
|
489
|
+
/**
|
|
490
|
+
* Signal emitted when the cell collapsed state changes.
|
|
491
|
+
*/
|
|
492
|
+
get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
|
|
474
493
|
/**
|
|
475
494
|
* Whether the cell is rendered.
|
|
476
495
|
*/
|
|
477
496
|
get rendered(): boolean;
|
|
478
497
|
set rendered(value: boolean);
|
|
498
|
+
/**
|
|
499
|
+
* Signal emitted when the markdown cell rendered state changes
|
|
500
|
+
*/
|
|
501
|
+
get renderedChanged(): ISignal<MarkdownCell, boolean>;
|
|
502
|
+
get showEditorForReadOnly(): boolean;
|
|
503
|
+
set showEditorForReadOnly(value: boolean);
|
|
504
|
+
/**
|
|
505
|
+
* Renderer
|
|
506
|
+
*/
|
|
507
|
+
get renderer(): IRenderMime.IRenderer;
|
|
508
|
+
dispose(): void;
|
|
479
509
|
protected maybeCreateCollapseButton(): void;
|
|
480
510
|
/**
|
|
481
511
|
* Create, update or remove the hidden cells button.
|
|
@@ -516,12 +546,14 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
|
|
|
516
546
|
private _monitor;
|
|
517
547
|
private _numberChildNodes;
|
|
518
548
|
private _headingCollapsed;
|
|
519
|
-
private
|
|
549
|
+
private _headingCollapsedChanged;
|
|
520
550
|
private _renderer;
|
|
521
551
|
private _rendermime;
|
|
522
552
|
private _rendered;
|
|
553
|
+
private _renderedChanged;
|
|
523
554
|
private _prevText;
|
|
524
555
|
private _ready;
|
|
556
|
+
private _showEditorForReadOnlyMarkdown;
|
|
525
557
|
}
|
|
526
558
|
/**
|
|
527
559
|
* The namespace for the `CodeCell` class statics.
|
|
@@ -535,7 +567,15 @@ export declare namespace MarkdownCell {
|
|
|
535
567
|
* The mime renderer for the cell widget.
|
|
536
568
|
*/
|
|
537
569
|
rendermime: IRenderMimeRegistry;
|
|
570
|
+
/**
|
|
571
|
+
* Show editor for read-only Markdown cells.
|
|
572
|
+
*/
|
|
573
|
+
showEditorForReadOnlyMarkdown?: boolean;
|
|
538
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Default value for showEditorForReadOnlyMarkdown.
|
|
577
|
+
*/
|
|
578
|
+
const defaultShowEditorForReadOnlyMarkdown = true;
|
|
539
579
|
}
|
|
540
580
|
/** ****************************************************************************
|
|
541
581
|
* RawCell
|
package/lib/widget.js
CHANGED
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
| Copyright (c) Jupyter Development Team.
|
|
3
3
|
| Distributed under the terms of the Modified BSD License.
|
|
4
4
|
|----------------------------------------------------------------------------*/
|
|
5
|
-
import marked from 'marked';
|
|
6
5
|
import { AttachmentsResolver } from '@jupyterlab/attachments';
|
|
7
6
|
import { ActivityMonitor, URLExt } from '@jupyterlab/coreutils';
|
|
8
7
|
import { OutputArea, OutputPrompt, SimplifiedOutputArea, Stdin } from '@jupyterlab/outputarea';
|
|
9
8
|
import { imageRendererFactory, MimeModel } from '@jupyterlab/rendermime';
|
|
9
|
+
import { TableOfContentsUtils } from '@jupyterlab/toc';
|
|
10
10
|
import { nullTranslator } from '@jupyterlab/translation';
|
|
11
|
+
import { addIcon } from '@jupyterlab/ui-components';
|
|
11
12
|
import { PromiseDelegate, UUID } from '@lumino/coreutils';
|
|
12
13
|
import { filter, some, toArray } from '@lumino/algorithm';
|
|
14
|
+
import { Debouncer } from '@lumino/polling';
|
|
15
|
+
import { Signal } from '@lumino/signaling';
|
|
13
16
|
import { Panel, PanelLayout, Widget } from '@lumino/widgets';
|
|
14
17
|
import { InputCollapser, OutputCollapser } from './collapser';
|
|
15
18
|
import { CellFooter, CellHeader } from './headerfooter';
|
|
16
19
|
import { InputArea, InputPrompt } from './inputarea';
|
|
17
20
|
import { InputPlaceholder, OutputPlaceholder } from './placeholder';
|
|
18
21
|
import { ResizeHandle } from './resizeHandle';
|
|
19
|
-
import { Signal } from '@lumino/signaling';
|
|
20
|
-
import { addIcon } from '@jupyterlab/ui-components';
|
|
21
22
|
/**
|
|
22
23
|
* The CSS class added to cell widgets.
|
|
23
24
|
*/
|
|
@@ -74,7 +75,7 @@ const MARKDOWN_CELL_CLASS = 'jp-MarkdownCell';
|
|
|
74
75
|
* The class name added to rendered markdown output widgets.
|
|
75
76
|
*/
|
|
76
77
|
const MARKDOWN_OUTPUT_CLASS = 'jp-MarkdownOutput';
|
|
77
|
-
|
|
78
|
+
const MARKDOWN_HEADING_COLLAPSED = 'jp-MarkdownHeadingCollapsed';
|
|
78
79
|
const HEADING_COLLAPSER_CLASS = 'jp-collapseHeadingButton';
|
|
79
80
|
const SHOW_HIDDEN_CELLS_CLASS = 'jp-showHiddenCellsButton';
|
|
80
81
|
/**
|
|
@@ -109,11 +110,17 @@ export class Cell extends Widget {
|
|
|
109
110
|
* Construct a new base cell widget.
|
|
110
111
|
*/
|
|
111
112
|
constructor(options) {
|
|
113
|
+
var _a;
|
|
112
114
|
super();
|
|
115
|
+
this._displayChanged = new Signal(this);
|
|
113
116
|
this._readOnly = false;
|
|
114
117
|
this._inputHidden = false;
|
|
118
|
+
this._isPlaceholder = false;
|
|
115
119
|
this._syncCollapse = false;
|
|
116
120
|
this._syncEditable = false;
|
|
121
|
+
this._resizeDebouncer = new Debouncer(() => {
|
|
122
|
+
this._displayChanged.emit();
|
|
123
|
+
}, 0);
|
|
117
124
|
this.addClass(CELL_CLASS);
|
|
118
125
|
const model = (this._model = options.model);
|
|
119
126
|
const contentFactory = (this.contentFactory =
|
|
@@ -147,14 +154,10 @@ export class Cell extends Widget {
|
|
|
147
154
|
const footer = this.contentFactory.createCellFooter();
|
|
148
155
|
footer.addClass(CELL_FOOTER_CLASS);
|
|
149
156
|
this.layout.addWidget(footer);
|
|
157
|
+
this._isPlaceholder = (_a = options.placeholder) !== null && _a !== void 0 ? _a : false;
|
|
150
158
|
// Editor settings
|
|
151
159
|
if (options.editorConfig) {
|
|
152
|
-
|
|
153
|
-
Object.keys(options.editorConfig).forEach((key) => {
|
|
154
|
-
var _a, _b;
|
|
155
|
-
editorOptions[key] = (_b = (_a = options.editorConfig) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : null;
|
|
156
|
-
});
|
|
157
|
-
this.editor.setOptions(editorOptions);
|
|
160
|
+
this.editor.setOptions(Object.assign({}, options.editorConfig));
|
|
158
161
|
}
|
|
159
162
|
model.metadata.changed.connect(this.onMetadataChanged, this);
|
|
160
163
|
}
|
|
@@ -170,6 +173,12 @@ export class Cell extends Widget {
|
|
|
170
173
|
this.loadEditableState();
|
|
171
174
|
return this;
|
|
172
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Signal to indicate that widget has changed visibly (in size, in type, etc)
|
|
178
|
+
*/
|
|
179
|
+
get displayChanged() {
|
|
180
|
+
return this._displayChanged;
|
|
181
|
+
}
|
|
173
182
|
/**
|
|
174
183
|
* Get the prompt node used by the cell.
|
|
175
184
|
*/
|
|
@@ -222,6 +231,12 @@ export class Cell extends Widget {
|
|
|
222
231
|
}
|
|
223
232
|
this.update();
|
|
224
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Whether the cell is a placeholder that differ rendering
|
|
236
|
+
*/
|
|
237
|
+
isPlaceholder() {
|
|
238
|
+
return this._isPlaceholder;
|
|
239
|
+
}
|
|
225
240
|
/**
|
|
226
241
|
* Save view editable state to model
|
|
227
242
|
*/
|
|
@@ -372,6 +387,7 @@ export class Cell extends Widget {
|
|
|
372
387
|
if (this.isDisposed) {
|
|
373
388
|
return;
|
|
374
389
|
}
|
|
390
|
+
this._resizeDebouncer.dispose();
|
|
375
391
|
this._input = null;
|
|
376
392
|
this._model = null;
|
|
377
393
|
this._inputWrapper = null;
|
|
@@ -391,11 +407,10 @@ export class Cell extends Widget {
|
|
|
391
407
|
this.editor.focus();
|
|
392
408
|
}
|
|
393
409
|
/**
|
|
394
|
-
* Handle `
|
|
410
|
+
* Handle `resize` messages.
|
|
395
411
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
this.editor.refresh();
|
|
412
|
+
onResize(msg) {
|
|
413
|
+
void this._resizeDebouncer.invoke();
|
|
399
414
|
}
|
|
400
415
|
/**
|
|
401
416
|
* Handle `update-request` messages.
|
|
@@ -1119,13 +1134,14 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1119
1134
|
* Construct a Markdown cell widget.
|
|
1120
1135
|
*/
|
|
1121
1136
|
constructor(options) {
|
|
1122
|
-
var _a, _b;
|
|
1137
|
+
var _a, _b, _c;
|
|
1123
1138
|
super(options);
|
|
1124
|
-
this.
|
|
1125
|
-
this._renderer = null;
|
|
1139
|
+
this._headingCollapsedChanged = new Signal(this);
|
|
1126
1140
|
this._rendered = true;
|
|
1141
|
+
this._renderedChanged = new Signal(this);
|
|
1127
1142
|
this._prevText = '';
|
|
1128
1143
|
this._ready = new PromiseDelegate();
|
|
1144
|
+
this._showEditorForReadOnlyMarkdown = true;
|
|
1129
1145
|
this.addClass(MARKDOWN_CELL_CLASS);
|
|
1130
1146
|
const trans = this.translator.load('jupyterlab');
|
|
1131
1147
|
this.node.setAttribute('aria-label', trans.__('Markdown Cell Content'));
|
|
@@ -1136,6 +1152,8 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1136
1152
|
model: this.model.attachments
|
|
1137
1153
|
})
|
|
1138
1154
|
});
|
|
1155
|
+
this._renderer = this._rendermime.createRenderer('text/markdown');
|
|
1156
|
+
this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
|
|
1139
1157
|
// Stop codemirror handling paste
|
|
1140
1158
|
this.editor.setOption('handlePaste', false);
|
|
1141
1159
|
// Check if heading cell is set to be collapsed
|
|
@@ -1155,6 +1173,8 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1155
1173
|
});
|
|
1156
1174
|
this.renderCollapseButtons(this._renderer);
|
|
1157
1175
|
this.renderInput(this._renderer);
|
|
1176
|
+
this._showEditorForReadOnlyMarkdown =
|
|
1177
|
+
(_c = options.showEditorForReadOnlyMarkdown) !== null && _c !== void 0 ? _c : MarkdownCell.defaultShowEditorForReadOnlyMarkdown;
|
|
1158
1178
|
}
|
|
1159
1179
|
/**
|
|
1160
1180
|
* A promise that resolves when the widget renders for the first time.
|
|
@@ -1163,45 +1183,55 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1163
1183
|
return this._ready.promise;
|
|
1164
1184
|
}
|
|
1165
1185
|
/**
|
|
1166
|
-
* Text that represents the heading if cell is a heading.
|
|
1186
|
+
* Text that represents the highest heading (i.e. lowest level) if cell is a heading.
|
|
1167
1187
|
* Returns empty string if not a heading.
|
|
1168
1188
|
*/
|
|
1169
1189
|
get headingInfo() {
|
|
1170
|
-
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
return { text: '', level: -1 };
|
|
1183
|
-
}
|
|
1190
|
+
// Use table of content algorithm for consistency
|
|
1191
|
+
const headings = TableOfContentsUtils.Markdown.getHeadings(this.model.value.text, {
|
|
1192
|
+
maximalDepth: 6,
|
|
1193
|
+
numberHeaders: false
|
|
1194
|
+
});
|
|
1195
|
+
if (headings.length > 0) {
|
|
1196
|
+
// Return the highest level
|
|
1197
|
+
const { text, level } = headings.reduce((prev, curr) => (prev.level <= curr.level ? prev : curr), headings[0]);
|
|
1198
|
+
return { text, level };
|
|
1199
|
+
}
|
|
1200
|
+
else {
|
|
1201
|
+
return { text: '', level: -1 };
|
|
1184
1202
|
}
|
|
1185
|
-
return { text: '', level: -1 };
|
|
1186
1203
|
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Whether the heading is collapsed or not.
|
|
1206
|
+
*/
|
|
1187
1207
|
get headingCollapsed() {
|
|
1188
1208
|
return this._headingCollapsed;
|
|
1189
1209
|
}
|
|
1190
1210
|
set headingCollapsed(value) {
|
|
1191
|
-
this._headingCollapsed
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
this.model.metadata.
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
collapseButton
|
|
1201
|
-
|
|
1211
|
+
if (this._headingCollapsed !== value) {
|
|
1212
|
+
this._headingCollapsed = value;
|
|
1213
|
+
if (value) {
|
|
1214
|
+
this.model.metadata.set(MARKDOWN_HEADING_COLLAPSED, value);
|
|
1215
|
+
}
|
|
1216
|
+
else if (this.model.metadata.has(MARKDOWN_HEADING_COLLAPSED)) {
|
|
1217
|
+
this.model.metadata.delete(MARKDOWN_HEADING_COLLAPSED);
|
|
1218
|
+
}
|
|
1219
|
+
const collapseButton = this.inputArea.promptNode.getElementsByClassName(HEADING_COLLAPSER_CLASS)[0];
|
|
1220
|
+
if (collapseButton) {
|
|
1221
|
+
if (value) {
|
|
1222
|
+
collapseButton.classList.add('jp-mod-collapsed');
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
collapseButton.classList.remove('jp-mod-collapsed');
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
this.renderCollapseButtons(this._renderer);
|
|
1229
|
+
this._headingCollapsedChanged.emit(this._headingCollapsed);
|
|
1202
1230
|
}
|
|
1203
|
-
this.renderCollapseButtons(this._renderer);
|
|
1204
1231
|
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Number of collapsed sub cells.
|
|
1234
|
+
*/
|
|
1205
1235
|
get numberChildNodes() {
|
|
1206
1236
|
return this._numberChildNodes;
|
|
1207
1237
|
}
|
|
@@ -1209,8 +1239,11 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1209
1239
|
this._numberChildNodes = value;
|
|
1210
1240
|
this.renderCollapseButtons(this._renderer);
|
|
1211
1241
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1242
|
+
/**
|
|
1243
|
+
* Signal emitted when the cell collapsed state changes.
|
|
1244
|
+
*/
|
|
1245
|
+
get headingCollapsedChanged() {
|
|
1246
|
+
return this._headingCollapsedChanged;
|
|
1214
1247
|
}
|
|
1215
1248
|
/**
|
|
1216
1249
|
* Whether the cell is rendered.
|
|
@@ -1219,30 +1252,65 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1219
1252
|
return this._rendered;
|
|
1220
1253
|
}
|
|
1221
1254
|
set rendered(value) {
|
|
1255
|
+
// Show cell as rendered when cell is not editable
|
|
1256
|
+
if (this.readOnly && this._showEditorForReadOnlyMarkdown === false) {
|
|
1257
|
+
value = true;
|
|
1258
|
+
}
|
|
1222
1259
|
if (value === this._rendered) {
|
|
1223
1260
|
return;
|
|
1224
1261
|
}
|
|
1225
1262
|
this._rendered = value;
|
|
1226
1263
|
this._handleRendered();
|
|
1227
|
-
//
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1264
|
+
// If the rendered state changed, raise an event.
|
|
1265
|
+
this._displayChanged.emit();
|
|
1266
|
+
this._renderedChanged.emit(this._rendered);
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Signal emitted when the markdown cell rendered state changes
|
|
1270
|
+
*/
|
|
1271
|
+
get renderedChanged() {
|
|
1272
|
+
return this._renderedChanged;
|
|
1273
|
+
}
|
|
1274
|
+
/*
|
|
1275
|
+
* Whether the Markdown editor is visible in read-only mode.
|
|
1276
|
+
*/
|
|
1277
|
+
get showEditorForReadOnly() {
|
|
1278
|
+
return this._showEditorForReadOnlyMarkdown;
|
|
1279
|
+
}
|
|
1280
|
+
set showEditorForReadOnly(value) {
|
|
1281
|
+
this._showEditorForReadOnlyMarkdown = value;
|
|
1282
|
+
if (value === false) {
|
|
1283
|
+
this.rendered = true;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Renderer
|
|
1288
|
+
*/
|
|
1289
|
+
get renderer() {
|
|
1290
|
+
return this._renderer;
|
|
1291
|
+
}
|
|
1292
|
+
dispose() {
|
|
1293
|
+
if (this.isDisposed) {
|
|
1294
|
+
return;
|
|
1232
1295
|
}
|
|
1296
|
+
this._monitor.dispose();
|
|
1297
|
+
super.dispose();
|
|
1233
1298
|
}
|
|
1234
1299
|
maybeCreateCollapseButton() {
|
|
1235
1300
|
if (this.headingInfo.level > 0 &&
|
|
1236
1301
|
this.inputArea.promptNode.getElementsByClassName(HEADING_COLLAPSER_CLASS)
|
|
1237
1302
|
.length == 0) {
|
|
1238
1303
|
let collapseButton = this.inputArea.promptNode.appendChild(document.createElement('button'));
|
|
1239
|
-
collapseButton.className = `jp-Button
|
|
1240
|
-
collapseButton.
|
|
1241
|
-
|
|
1242
|
-
|
|
1304
|
+
collapseButton.className = `jp-Button ${HEADING_COLLAPSER_CLASS}`;
|
|
1305
|
+
collapseButton.setAttribute('data-heading-level', this.headingInfo.level.toString());
|
|
1306
|
+
if (this._headingCollapsed) {
|
|
1307
|
+
collapseButton.classList.add('jp-mod-collapsed');
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
collapseButton.classList.remove('jp-mod-collapsed');
|
|
1311
|
+
}
|
|
1243
1312
|
collapseButton.onclick = (event) => {
|
|
1244
1313
|
this.headingCollapsed = !this.headingCollapsed;
|
|
1245
|
-
this._toggleCollapsedSignal.emit(this._headingCollapsed);
|
|
1246
1314
|
};
|
|
1247
1315
|
}
|
|
1248
1316
|
}
|
|
@@ -1266,7 +1334,6 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1266
1334
|
newShowHiddenCellsButton.appendChild(buttonTextElement);
|
|
1267
1335
|
newShowHiddenCellsButton.onclick = () => {
|
|
1268
1336
|
this.headingCollapsed = false;
|
|
1269
|
-
this._toggleCollapsedSignal.emit(this._headingCollapsed);
|
|
1270
1337
|
};
|
|
1271
1338
|
this.node.appendChild(newShowHiddenCellsButton);
|
|
1272
1339
|
}
|
|
@@ -1307,6 +1374,15 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1307
1374
|
showEditor() {
|
|
1308
1375
|
this.removeClass(RENDERED_CLASS);
|
|
1309
1376
|
this.inputArea.showEditor();
|
|
1377
|
+
// if this is going to be a heading, place the cursor accordingly
|
|
1378
|
+
let numHashAtStart = (this.model.value.text.match(/^#+/g) || [''])[0]
|
|
1379
|
+
.length;
|
|
1380
|
+
if (numHashAtStart > 0) {
|
|
1381
|
+
this.inputArea.editor.setCursorPosition({
|
|
1382
|
+
column: numHashAtStart + 1,
|
|
1383
|
+
line: 0
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1310
1386
|
}
|
|
1311
1387
|
/*
|
|
1312
1388
|
* Handle `update-request` messages.
|
|
@@ -1347,14 +1423,10 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1347
1423
|
// Do not re-render if the text has not changed.
|
|
1348
1424
|
if (text !== this._prevText) {
|
|
1349
1425
|
const mimeModel = new MimeModel({ data: { 'text/markdown': text } });
|
|
1350
|
-
if (!this._renderer) {
|
|
1351
|
-
this._renderer = this._rendermime.createRenderer('text/markdown');
|
|
1352
|
-
this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
|
|
1353
|
-
}
|
|
1354
1426
|
this._prevText = text;
|
|
1355
1427
|
return this._renderer.renderModel(mimeModel);
|
|
1356
1428
|
}
|
|
1357
|
-
return Promise.resolve(
|
|
1429
|
+
return Promise.resolve();
|
|
1358
1430
|
}
|
|
1359
1431
|
/**
|
|
1360
1432
|
* Clone the cell, using the same model.
|
|
@@ -1370,6 +1442,15 @@ export class MarkdownCell extends AttachmentsCell {
|
|
|
1370
1442
|
});
|
|
1371
1443
|
}
|
|
1372
1444
|
}
|
|
1445
|
+
/**
|
|
1446
|
+
* The namespace for the `CodeCell` class statics.
|
|
1447
|
+
*/
|
|
1448
|
+
(function (MarkdownCell) {
|
|
1449
|
+
/**
|
|
1450
|
+
* Default value for showEditorForReadOnlyMarkdown.
|
|
1451
|
+
*/
|
|
1452
|
+
MarkdownCell.defaultShowEditorForReadOnlyMarkdown = true;
|
|
1453
|
+
})(MarkdownCell || (MarkdownCell = {}));
|
|
1373
1454
|
/** ****************************************************************************
|
|
1374
1455
|
* RawCell
|
|
1375
1456
|
******************************************************************************/
|