• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript rendermime.IRenderMimeRegistry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
        });
      });
    }
开发者ID:7125messi,项目名称:jupyterlab,代码行数:60,代码来源:mimerenderers.ts


示例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);
        });
      });
    }
开发者ID:afshin,项目名称:jupyterlab,代码行数:57,代码来源:mimerenderers.ts


示例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;
 }
开发者ID:vidartf,项目名称:nbdime,代码行数:44,代码来源:cell.ts


示例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,
//.........这里部分代码省略.........
开发者ID:SylvainCorlay,项目名称:ipywidgets,代码行数:101,代码来源:plugin.ts


示例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;
}
开发者ID:afshin,项目名称:jupyterlab,代码行数:98,代码来源:index.ts


示例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);
 };
开发者ID:7125messi,项目名称:jupyterlab,代码行数:9,代码来源:index.ts


示例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;
 };
开发者ID:afshin,项目名称:jupyterlab,代码行数:12,代码来源:index.ts


示例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
      );
    });
开发者ID:afshin,项目名称:jupyterlab,代码行数:14,代码来源:index.ts



注:本文中的@jupyterlab/rendermime.IRenderMimeRegistry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript rendermime.MimeModel类代码示例发布时间:2022-05-28
下一篇:
TypeScript rendermime.removeMath函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap