How to use @jupyterlab/coreutils - 10 common examples

To help you get started, we’ve selected a few @jupyterlab/coreutils 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 krassowski / jupyterlab-lsp / packages / jupyterlab-lsp / src / connection_manager.ts View on Github external
private connect_socket(options: ISocketConnectionOptions): LSPConnection {
    let { virtual_document, language } = options;

    const wsBase = PageConfig.getBaseUrl().replace(/^http/, 'ws');
    const rootUri = PageConfig.getOption('rootUri');
    const documentUri = URLExt.join(rootUri, virtual_document.uri);
    const serverUri = URLExt.join('ws://jupyter-lsp', language);
    let socket = new WebSocket(URLExt.join(wsBase, 'lsp', language));

    let connection = new LSPConnection({
      languageId: language,
      serverUri,
      rootUri,
      documentUri,
      documentText: () => {
        // NOTE: Update is async now and this is not really used, as an alternative method
        // which is compatible with async is used.
        // This should be only used in the initialization step.
        // if (main_connection.isConnected) {
        //  console.warn('documentText is deprecated for use in JupyterLab LSP');
        // }
        return virtual_document.value;
      }
    }).connect(socket);
github krassowski / jupyterlab-lsp / packages / jupyterlab-lsp / src / connection_manager.ts View on Github external
private connect_socket(options: ISocketConnectionOptions): LSPConnection {
    let { virtual_document, language } = options;

    const wsBase = PageConfig.getBaseUrl().replace(/^http/, 'ws');
    const rootUri = PageConfig.getOption('rootUri');
    const documentUri = URLExt.join(rootUri, virtual_document.uri);
    const serverUri = URLExt.join('ws://jupyter-lsp', language);
    let socket = new WebSocket(URLExt.join(wsBase, 'lsp', language));

    let connection = new LSPConnection({
      languageId: language,
      serverUri,
      rootUri,
      documentUri,
      documentText: () => {
        // NOTE: Update is async now and this is not really used, as an alternative method
        // which is compatible with async is used.
        // This should be only used in the initialization step.
        // if (main_connection.isConnected) {
        //  console.warn('documentText is deprecated for use in JupyterLab LSP');
        // }
github wandb / client / wandb / jupyter / lab / js / src / index.ts View on Github external
});
            } else {
                widget = new IFrameWidget(path);
                app.shell.add(widget);
                app.shell.activateById(widget.id);
            }
        },
        isEnabled: () => true,
        label: "Open IFrame"
    });

    // Add the command to the palette.
    palette.addItem({ command: open_command, category: "Sites" });

    // grab sites from serverextension
    request("get", PageConfig.getBaseUrl() + "wandb/").then(
        (res: IRequestResult) => {
            if (res.ok) {
                const jsn = res.json() as { [key: string]: string };
                const sites = jsn.sites;

                for (const site of sites) {
                    // tslint:disable-next-line: no-console
                    console.log("adding quicklink for " + site);
                }
            }
        }
    );
    // tslint:disable-next-line: no-console
    console.log("JupyterLab extension @jupyterlab/wandb is activated!");
}
github jupyterlab / jupyterlab-metadata-service / frontend / src / metadata_concrete / apollo_connection.ts View on Github external
constructor() {
    console.log('Starting MetadataApolloGraphQlConnection ...');
    console.log(PageConfig);

    // Construct URL of our proxied service
    let baseUrl = PageConfig.getBaseUrl();
    let serviceUrl = baseUrl + 'metadata/';

    console.log('Instatiating Apollo Client at: ' + serviceUrl);
    this.client = new ApolloClient({
      uri: serviceUrl,
      credentials: 'same-origin'    // See: https://www.apollographql.com/docs/react/recipes/authentication.html
    });
    console.log(this.client);
  }
github wandb / client / wandb / jupyter / lab / js / src / index.ts View on Github external
function activate(
    app: JupyterFrontEnd,
    docManager: IDocumentManager,
    palette: ICommandPalette,
    restorer: ILayoutRestorer
) {
    // Declare a widget variable
    let widget: IFrameWidget;
    const rootEl = document.querySelector("#root");
    const dataEl = document.querySelector("#jupyter-config-data");
    const config = readConfig(rootEl, dataEl);
    config.root = PageConfig.getBaseUrl();
    const handshake = new Postmate.Model({
        height: () => document.body.offsetHeight,
        setContext: (ctx: any) => {
            request(
                "post",
                PageConfig.getBaseUrl() + "wandb/context",
                { token: config.token }, // TODO: maybe using other auth
                ctx
            ).then((res: IRequestResult) => {
                if (res.ok) {
                    console.log("Config set", ctx);
                } else {
                    console.warn(res);
                }
            });
        }
github jupyter / nbdime / packages / labextension / src / plugin.ts View on Github external
function hasGitNotebook(): boolean {
    if (!baseEnabled()) {
      return false;
    }

    let path = tracker.currentWidget!.context.path;
    let dir = PathExt.dirname(path);
    let known_git = lut_known_git[dir];
    if (known_git === undefined) {
      const inGitPromise = isNbInGit({path: dir});
      inGitPromise.then(inGit => {
        networkRetry = INITIAL_NETWORK_RETRY;
        lut_known_git[dir] = inGit;
        // Only update if false, since it is left enabled while waiting
        if (!inGit) {
          commands.notifyCommandChanged(CommandIDs.diffNotebookGit);
        }
      });
      inGitPromise.catch((reason) => {
        hasAPI = reason.status !== undefined && reason.status !== 404;
        setTimeout(() => {
          networkRetry *= 2;
          commands.notifyCommandChanged(CommandIDs.diffNotebook);
github yuvipanda / simplest-notebook / packages / rendermime / src / renderers.ts View on Github external
function handleAttr(
    node: HTMLElement,
    name: 'src' | 'href',
    resolver: IRenderMime.IResolver
  ): Promise {
    let source = node.getAttribute(name);
    const isLocal = resolver.isLocal
      ? resolver.isLocal(source)
      : URLExt.isLocal(source);
    if (!source || !isLocal) {
      return Promise.resolve(undefined);
    }
    node.setAttribute(name, '');
    return resolver
      .resolveUrl(source)
      .then(path => {
        return resolver.getDownloadUrl(path);
      })
      .then(url => {
        // Check protocol again in case it changed:
        if (URLExt.parse(url).protocol !== 'data:') {
          // Bust caching for local src attrs.
          // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
          url += (/\?/.test(url) ? '&' : '?') + new Date().getTime();
        }
github jupyterlab / jupyterlab-data-explorer / packages / rendermime / src / renderers.ts View on Github external
function handleAttr(
    node: HTMLElement,
    name: 'src' | 'href',
    resolver: IRenderMime.IResolver
  ): Promise {
    let source = node.getAttribute(name) || '';
    const isLocal = resolver.isLocal
      ? resolver.isLocal(source)
      : URLExt.isLocal(source);
    if (!source || !isLocal) {
      return Promise.resolve(undefined);
    }
    node.setAttribute(name, '');
    return resolver
      .resolveUrl(source)
      .then(urlPath => {
        return resolver.getDownloadUrl(urlPath);
      })
      .then(url => {
        // Check protocol again in case it changed:
        if (URLExt.parse(url).protocol !== 'data:') {
          // Bust caching for local src attrs.
          // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
          url += (/\?/.test(url) ? '&' : '?') + new Date().getTime();
        }
github OpenGeoscience / jupyterlab_geojs / packages / geojsonviewer / src / widget.ts View on Github external
constructor(context: DocumentRegistry.Context, rendermime: RenderMime) {
    super();
    this.addClass(GEOJSON_CLASS);
    this.layout = new PanelLayout();
    this.title.label = context.path.split('/').pop();
    this._rendermime = rendermime;
    rendermime.resolver = context;
    this._context = context;

    context.pathChanged.connect(this._onPathChanged, this);

    // Throttle the rendering rate of the widget.
    this._monitor = new ActivityMonitor({
      signal: context.model.contentChanged,
      timeout: RENDER_TIMEOUT
    });
    this._monitor.activityStopped.connect(this.update, this);    
  }
github OpenGeoscience / jupyterlab_geojs / packages / jsonviewer / src / widget.tsx View on Github external
constructor(context: DocumentRegistry.Context, rendermime: RenderMime) {
    super();
    this.addClass(JSON_CLASS);
    this.layout = new PanelLayout();
    this.title.label = context.path.split('/').pop();
    this._rendermime = rendermime;
    rendermime.resolver = context;
    this._context = context;

    context.pathChanged.connect(this._onPathChanged, this);

    // Throttle the rendering rate of the widget.
    this._monitor = new ActivityMonitor({
      signal: context.model.contentChanged,
      timeout: RENDER_TIMEOUT
    });
    this._monitor.activityStopped.connect(this.update, this);    
  }