How to use the @jupyterlab/docregistry.MimeDocumentFactory function in @jupyterlab/docregistry

To help you get started, we’ve selected a few @jupyterlab/docregistry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / application / src / mimerenderers.ts View on Github external
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 widget tracker if restore data needs to update.
github jupyterlab / jupyterlab / packages / markdownviewer-extension / src / index.ts View on Github external
function activate(app: JupyterLab, restorer: ILayoutRestorer, rendermime: IRenderMimeRegistry) {
    const primaryFileType = app.docRegistry.getFileType('markdown');
    const factory = new MimeDocumentFactory({
      name: FACTORY,
      primaryFileType,
      fileTypes: ['markdown'],
      rendermime
    });
    const { commands } = app;
    const namespace = 'rendered-markdown';
    const tracker = new InstanceTracker>({ namespace });

    app.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
github yuvipanda / simplest-notebook / packages / application / src / mimerenderers.ts View on Github external
activate: (app: JupyterLab, restorer: ILayoutRestorer) => {
      // Add the mime renderer.
      if (item.rank !== undefined) {
        app.rendermime.addFactory(
          item.rendererFactory, item.rank
        );
      } else {
        app.rendermime.addFactory(item.rendererFactory);
      }

      // Handle the widget factory.
      if (!item.documentWidgetFactoryOptions) {
        return;
      }

      let factory = new MimeDocumentFactory({
        mimeType: item.mimeType,
        renderTimeout: item.renderTimeout,
        dataType: item.dataType,
        rendermime: app.rendermime,
        ...item.documentWidgetFactoryOptions,
      });
      app.docRegistry.addWidgetFactory(factory);

      const factoryName = factory.name;
      const namespace = `${factoryName}-renderer`;
      const tracker = new InstanceTracker({ namespace });

      // Handle state restoration.
      restorer.restore(tracker, {
        command: 'docmanager:open',
        args: widget => ({ path: widget.context.path, factory: factoryName }),
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / application / src / mimerenderers.ts View on Github external
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.
github yuvipanda / simplest-notebook / packages / markdownviewer-extension / src / index.ts View on Github external
function activate(app: JupyterLab, restorer: ILayoutRestorer) {
    const factory = new MimeDocumentFactory({
      name: FACTORY,
      fileExtensions: ['.md'],
      mimeType: 'text/markdown',
      rendermime: app.rendermime
    });
    app.docRegistry.addWidgetFactory(factory);

    const { commands } = app;
    const namespace = 'rendered-markdown';
    const tracker = new InstanceTracker({ namespace });

    // Handle state restoration.
    restorer.restore(tracker, {
      command: 'docmanager:open',
      args: widget => ({ path: widget.context.path, factory: FACTORY }),
      name: widget => widget.context.path
github jupyterlab / jupyterlab-data-explorer / tests / test-docregistry / src / mimedocument.spec.ts View on Github external
it('should require a context parameter', () => {
        const widgetFactory = new MimeDocumentFactory({
          name: 'markdown',
          fileTypes: ['markdown'],
          rendermime: RENDERMIME,
          primaryFileType: DocumentRegistry.defaultTextFileType
        });
        expect(widgetFactory.createNew(dContext)).to.be.an.instanceof(
          MimeDocument
        );
      });
    });
github jupyterlab / jupyterlab / tests / test-docregistry / src / mimedocument.spec.ts View on Github external
it('should require a context parameter', () => {
        const widgetFactory = new MimeDocumentFactory({
          name: 'markdown',
          fileTypes: ['markdown'],
          rendermime: RENDERMIME,
          primaryFileType: DocumentRegistry.defaultTextFileType
        });
        expect(widgetFactory.createNew(dContext)).to.be.an.instanceof(
          MimeDocument
        );
      });
    });
github yuvipanda / simplest-notebook / test / src / docregistry / default.spec.ts View on Github external
it('should require a context parameter', () => {
        let widgetFactory = new MimeDocumentFactory({
          name: 'markdown',
          fileExtensions: ['.md'],
          rendermime: RENDERMIME,
          mimeType: 'text/markdown'
        });
        expect(widgetFactory.createNew(context)).to.be.a(MimeDocument);
      });
github jupyterlab / jupyterlab / packages / vdom-extension / src / index.ts View on Github external
safe: false,
          mimeTypes: [MIME_TYPE],
          createRenderer: options => new RenderedVDOM(options, context)
        },
        0
      );
    });

    app.docRegistry.addFileType({
      name: 'vdom',
      mimeTypes: [MIME_TYPE],
      extensions: ['.vdom', '.vdom.json'],
      iconClass: CSS_ICON_CLASS
    });

    const factory = new MimeDocumentFactory({
      renderTimeout: 1000,
      dataType: 'json',
      rendermime,
      name: FACTORY_NAME,
      primaryFileType: app.docRegistry.getFileType('vdom'),
      fileTypes: ['vdom', 'json'],
      defaultFor: ['vdom']
    });

    factory.widgetCreated.connect((sender, widget) => {
      widget.context.pathChanged.connect(() => {
        void tracker.save(widget);
      });
      void tracker.add(widget);
    });