本文整理匯總了TypeScript中@jupyterlab/rendermime.IRenderMimeRegistry類的典型用法代碼示例。如果您正苦於以下問題:TypeScript IRenderMimeRegistry類的具體用法?TypeScript IRenderMimeRegistry怎麽用?TypeScript IRenderMimeRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IRenderMimeRegistry類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: MimeDocumentFactory
activate: (app: JupyterLab, restorer: ILayoutRestorer, rendermime: IRenderMimeRegistry) => {
// Add the mime renderer.
if (item.rank !== undefined) {
rendermime.addFactory(
item.rendererFactory, item.rank
);
} else {
rendermime.addFactory(item.rendererFactory);
}
// Handle the widget factory.
if (!item.documentWidgetFactoryOptions) {
return;
}
let registry = app.docRegistry;
let options: IRenderMime.IDocumentWidgetFactoryOptions[] = [];
if (Array.isArray(item.documentWidgetFactoryOptions)) {
options = item.documentWidgetFactoryOptions;
} else {
options = [item.documentWidgetFactoryOptions as IRenderMime.IDocumentWidgetFactoryOptions];
}
if (item.fileTypes) {
item.fileTypes.forEach(ft => {
app.docRegistry.addFileType(ft as DocumentRegistry.IFileType);
});
}
options.forEach(option => {
let factory = new MimeDocumentFactory({
renderTimeout: item.renderTimeout,
dataType: item.dataType,
rendermime,
modelName: option.modelName,
name: option.name,
primaryFileType: registry.getFileType(option.primaryFileType),
fileTypes: option.fileTypes,
defaultFor: option.defaultFor
});
registry.addWidgetFactory(factory);
const factoryName = factory.name;
const namespace = `${factoryName}-renderer`;
const tracker = new InstanceTracker<MimeDocument>({ namespace });
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: factoryName }),
name: widget => widget.context.path
});
factory.widgetCreated.connect((sender, widget) => {
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
tracker.add(widget);
});
});
}
示例2: MimeDocumentFactory
activate: (app: JupyterFrontEnd, rendermime: IRenderMimeRegistry) => {
// Add the mime renderer.
if (item.rank !== undefined) {
rendermime.addFactory(item.rendererFactory, item.rank);
} else {
rendermime.addFactory(item.rendererFactory);
}
// Handle the widget factory.
if (!item.documentWidgetFactoryOptions) {
return;
}
let registry = app.docRegistry;
let options: IRenderMime.IDocumentWidgetFactoryOptions[] = [];
if (Array.isArray(item.documentWidgetFactoryOptions)) {
options = item.documentWidgetFactoryOptions;
} else {
options = [
item.documentWidgetFactoryOptions as IRenderMime.IDocumentWidgetFactoryOptions
];
}
if (item.fileTypes) {
item.fileTypes.forEach(ft => {
app.docRegistry.addFileType(ft as DocumentRegistry.IFileType);
});
}
options.forEach(option => {
const toolbarFactory = option.toolbarFactory
? (w: MimeDocument) => option.toolbarFactory(w.content.renderer)
: undefined;
let factory = new MimeDocumentFactory({
renderTimeout: item.renderTimeout,
dataType: item.dataType,
rendermime,
modelName: option.modelName,
name: option.name,
primaryFileType: registry.getFileType(option.primaryFileType),
fileTypes: option.fileTypes,
defaultFor: option.defaultFor,
defaultRendered: option.defaultRendered,
toolbarFactory
});
registry.addWidgetFactory(factory);
factory.widgetCreated.connect((sender, widget) => {
Private.factoryNameProperty.set(widget, factory.name);
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});
void tracker.add(widget);
});
});
}
示例3: createView
/**
* Create a new sub-view.
*/
static
createView(model: IDiffModel, parent: CellDiffModel,
editorClasses: string[], rendermime: IRenderMimeRegistry): Panel {
let view: Panel;
if (model instanceof StringDiffModel) {
let inner: Widget | null = null;
if (model.unchanged && parent.cellType === 'markdown') {
let mimeModel = new MimeModel({ data: {'text/markdown': model.base!} });
let mimeType = rendermime.preferredMimeType(mimeModel.data, 'ensure');
if (!mimeType) {
throw new Error('No renderer for output');
}
let renderer = rendermime.createRenderer(mimeType);
renderer.renderModel(mimeModel);
inner = renderer;
} else {
inner = createNbdimeMergeView(model);
}
if (model.collapsible) {
view = new CollapsiblePanel(
inner, model.collapsibleHeader, model.startCollapsed);
} else {
view = new Panel();
view.addWidget(inner);
}
} else if (model instanceof OutputDiffModel) {
view = new OutputPanel(model, parent, editorClasses, rendermime);
if (model.added) {
view.addClass(ADDED_DIFF_CLASS);
} else if (model.deleted) {
view.addClass(DELETED_DIFF_CLASS);
} else if (model.unchanged) {
view.addClass(UNCHANGED_DIFF_CLASS);
} else {
view.addClass(TWOWAY_DIFF_CLASS);
}
} else {
throw new Error('Unrecognized model type.');
}
return view;
}
示例4: activateWidgetExtension
/**
* Activate the widget extension.
*/
function activateWidgetExtension(app: JupyterFrontEnd, tracker: INotebookTracker, rendermime: IRenderMimeRegistry, settingRegistry: ISettingRegistry, menu: IMainMenu | null): base.IJupyterWidgetRegistry {
const {commands} = app;
settingRegistry.load(plugin.id).then((settings: ISettingRegistry.ISettings) => {
settings.changed.connect(updateSettings);
updateSettings(settings);
}).catch((reason: Error) => {
console.error(reason.message);
});
// Add a placeholder widget renderer.
rendermime.addFactory(
{
safe: false,
mimeTypes: [WIDGET_VIEW_MIMETYPE],
createRenderer: options => new WidgetRenderer(options)
},
0
);
tracker.forEach(panel => {
registerWidgetManager(
panel.context,
panel.content.rendermime,
chain(
widgetRenderers(panel.content),
outputViews(app, panel.context.path)
)
);
});
tracker.widgetAdded.connect((sender, panel) => {
registerWidgetManager(
panel.context,
panel.content.rendermime,
chain(
widgetRenderers(panel.content),
outputViews(app, panel.context.path)
)
);
});
// Add a command for creating a new Markdown file.
commands.addCommand('@jupyter-widgets/jupyterlab-manager:saveWidgetState', {
label: 'Save Widget State Automatically',
execute: args => {
return settingRegistry
.set(plugin.id, 'saveState', !SETTINGS.saveState)
.catch((reason: Error) => {
console.error(`Failed to set ${plugin.id}: ${reason.message}`);
});
},
isToggled: () => SETTINGS.saveState
});
if (menu) {
menu.settingsMenu.addGroup([
{command: '@jupyter-widgets/jupyterlab-manager:saveWidgetState'}
]);
}
WIDGET_REGISTRY.push({
name: '@jupyter-widgets/base',
version: base.JUPYTER_WIDGETS_VERSION,
exports: {
WidgetModel: base.WidgetModel,
WidgetView: base.WidgetView,
DOMWidgetView: base.DOMWidgetView,
DOMWidgetModel: base.DOMWidgetModel,
LayoutModel: base.LayoutModel,
LayoutView: base.LayoutView,
StyleModel: base.StyleModel,
StyleView: base.StyleView
}
});
WIDGET_REGISTRY.push({
name: '@jupyter-widgets/controls',
version: JUPYTER_CONTROLS_VERSION,
exports: () => {
return new Promise((resolve, reject) => {
(require as any).ensure(['@jupyter-widgets/controls'], (require: NodeRequire) => {
resolve(require('@jupyter-widgets/controls'));
},
(err: any) => {
reject(err);
},
'@jupyter-widgets/controls'
);
});
}
});
WIDGET_REGISTRY.push({
name: '@jupyter-widgets/output',
version: OUTPUT_WIDGET_VERSION,
//.........這裏部分代碼省略.........
示例5: activate
/**
* Activate the markdown viewer plugin.
*/
function activate(
app: JupyterFrontEnd,
restorer: ILayoutRestorer,
rendermime: IRenderMimeRegistry,
settingRegistry: ISettingRegistry
): IMarkdownViewerTracker {
const { commands, docRegistry } = app;
// Add the markdown renderer factory.
rendermime.addFactory(markdownRendererFactory);
const namespace = 'markdownviewer-widget';
const tracker = new InstanceTracker<MarkdownDocument>({
namespace
});
let config: Partial<MarkdownViewer.IConfig> = {
...MarkdownViewer.defaultConfig
};
/**
* Update the settings of a widget.
*/
function updateWidget(widget: MarkdownViewer): void {
Object.keys(config).forEach((k: keyof MarkdownViewer.IConfig) => {
widget.setOption(k, config[k]);
});
}
/**
* Update the setting values.
*/
function updateSettings(settings: ISettingRegistry.ISettings) {
config = settings.composite as Partial<MarkdownViewer.IConfig>;
tracker.forEach(widget => {
updateWidget(widget.content);
});
}
// Fetch the initial state of the settings.
settingRegistry
.load(plugin.id)
.then((settings: ISettingRegistry.ISettings) => {
settings.changed.connect(() => {
updateSettings(settings);
});
updateSettings(settings);
})
.catch((reason: Error) => {
console.error(reason.message);
});
// Register the MarkdownViewer factory.
const factory = new MarkdownViewerFactory({
rendermime,
name: FACTORY,
primaryFileType: docRegistry.getFileType('markdown'),
fileTypes: ['markdown'],
defaultRendered: ['markdown']
});
factory.widgetCreated.connect((sender, widget) => {
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});
// Handle the settings of new widgets.
updateWidget(widget.content);
void tracker.add(widget);
});
docRegistry.addWidgetFactory(factory);
// Handle state restoration.
restorer.restore(tracker, {
command: 'docmanager:open',
args: widget => ({ path: widget.context.path, factory: FACTORY }),
name: widget => widget.context.path
});
commands.addCommand(CommandIDs.markdownPreview, {
label: 'Markdown Preview',
execute: args => {
let path = args['path'];
if (typeof path !== 'string') {
return;
}
return commands.execute('docmanager:open', {
path,
factory: FACTORY,
options: args['options']
});
}
});
return tracker;
}
示例6: FAQWidget
let createWidget = () => {
let content = rendermime.createRenderer('text/markdown');
const model = rendermime.createModel({
data: { 'text/markdown': SOURCE }
});
content.renderModel(model);
content.addClass('jp-FAQ-content');
return new FAQWidget(content);
};
示例7: MainAreaWidget
let createWidget = () => {
let content = rendermime.createRenderer('text/markdown');
const model = rendermime.createModel({
data: { 'text/markdown': SOURCE }
});
void content.renderModel(model);
content.addClass('jp-FAQ-content');
let widget = new MainAreaWidget({ content });
widget.addClass('jp-FAQ');
widget.title.label = 'FAQ';
return widget;
};
示例8: RenderedVDOM
notebooks.widgetAdded.connect((sender, panel) => {
// Get the notebook's context and rendermime;
const { context, rendermime } = panel;
// Add the renderer factory to the notebook's rendermime registry;
rendermime.addFactory(
{
safe: false,
mimeTypes: [MIME_TYPE],
createRenderer: options => new RenderedVDOM(options, context)
},
0
);
});