-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendermime Refactor #2555
Rendermime Refactor #2555
Conversation
packages/docregistry/src/default.ts
Outdated
if (layout.widgets.length === 2) { | ||
// The toolbar is layout.widgets[0] | ||
layout.widgets[1].dispose(); | ||
this._mimeModel.data.set(this._mimeType, model.toJSON()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not of a fan of this mutation here, then passing the same mime model back into the renderer. If the renderer is expecting the model to be immutable, it might not re-render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good to me, modulo a few likely oversights during the refactoring.
packages/rendermime/src/widgets.ts
Outdated
if (!this.trusted) { | ||
source = this.sanitizer.sanitize(source); | ||
} | ||
Private.appendHtml(this.node, source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to clear the node content first?
packages/rendermime/src/widgets.ts
Outdated
if (!this.trusted) { | ||
content = this.sanitizer.sanitize(content); | ||
} | ||
Private.appendHtml(this.node, content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to clear the node content first?
* The options used to initialize a document widget factory. | ||
*/ | ||
export | ||
interface IWidgetFactoryOptions { | ||
interface IDocumentWidgetFactoryOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the name "document widget" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this:
* These are options used to open a rendered view of a given file type
* using a rendermime factory.
* Add the default renderer factories to a rendermime instance. | ||
*/ | ||
export | ||
function addDefaultFactories(rendermime: RenderMime): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were not going to do this, and have the app add the default factories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed for outside uses of the rendermime (such as our standalone notebook example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some minor comments/changes inline.
@@ -24,6 +28,11 @@ import { | |||
export | |||
interface IOutputModel extends IRenderMime.IMimeModel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sccolbert will this IOutputModel
class get moved to the outputarea in your work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
* Negative indices count from the end, so -1 refers to the last index. | ||
* Use the index of `.order.length` to add to the end of the render precedence list, | ||
* which would make the new renderer the last choice. | ||
* @param rank - The rank of the renderer. Defaults to 100. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better note indicating what low/high rank means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
this._renderers[mimeType] = renderer; | ||
ArrayExt.insert(this._order, index, mimeType); | ||
addFactory(factory: IRenderMime.IRendererFactory, mimeType: string, rank?: number): void { | ||
this._addFactory(factory, mimeType, rank); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this indirection needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are needed so we don't call a public method in the constructor.
delete this._renderers[mimeType]; | ||
ArrayExt.removeFirstOf(this._order, mimeType); | ||
removeFactory(mimeType: string): void { | ||
this._removeFactory(mimeType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this indirection needed?
packages/cells/src/widget.ts
Outdated
@@ -166,7 +170,7 @@ const RENDER_TIMEOUT = 1000; | |||
* A base cell widget. | |||
*/ | |||
export | |||
class Cell extends Widget implements IRenderMime.IReadyWidget { | |||
class Cell extends Widget implements DocumentRegistry.IReadyWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit surprised that cell depends on the document registry. At least conceptually, cells shouldnn't know anything about documents. The IReadyWidget
is really simply, can we put it somewhere else that cell can depend on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this to implement the interface explicitly, I'll just remove it.
packages/docregistry/src/default.ts
Outdated
@@ -451,6 +452,11 @@ class MimeRenderer extends Widget implements IRenderMime.IReadyWidget { | |||
} | |||
|
|||
/** | |||
* The renderime instance associated with the widget. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rendermime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
|
||
.jp-MarkdownViewer .jp-Toolbar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the new widget we are using for rendering MIME based documents have the micro toolbar at the top?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
z-index: 1; | ||
} | ||
|
||
.jp-MarkdownViewer .jp-RenderedMarkdown { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this CSS is missing now. We probably have the CSS classes needed to keep it, but we will need to add it as something like jp-Document.jp-MimeRenderer jp.RenderedMarkdown
.
|
||
.jp-MarkdownViewer { | ||
border-top: var(--jp-border-width) solid var(--jp-border-color2); | ||
outline: none; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to make sure the overflow is working properly so that it wraps/scrolls as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this branch, the markdown won't scroll at all.
I have tried this locally and things seem to be mostly working. I have added a few more comments based on those tests. Given the size of this, we should probably merge soon and continue to iterate. |
Looks like real test failures |
@blink1073 I can clean up the markdown preview CSS later so we can merge this once the tests are passing. |
Merging and iterating. |
Refactors rendermime with the following top level ideas:
IRenderers
are nowIRendererFactories
, and the returned widgets have arenderModel(model): Promise
method. This allows us to re-render by updating the model and calling that method.rendermime
,docregistry
, andcommandLinker
properties, which were already being considered singletons.rendermime-extension
anddocregistry-extension
packages as well as the command linker plugin inapputils-extension
.markdownviewer
extension in favor of using theMimeRenderer
inDocumentRegistry
.