"use strict";
(self["webpackChunk_JUPYTERLAB_CORE_OUTPUT"] = self["webpackChunk_JUPYTERLAB_CORE_OUTPUT"] || []).push([["9393"], {
77965(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
  "default": () => (__rspack_default_export)
});
/* import */ var _jupyterlab_application__rspack_import_0 = __webpack_require__(58889);
/* import */ var _jupyterlab_application__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_application__rspack_import_0);
/* import */ var _jupyterlab_apputils__rspack_import_1 = __webpack_require__(36992);
/* import */ var _jupyterlab_apputils__rspack_import_1_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_apputils__rspack_import_1);
/* import */ var _jupyterlab_console__rspack_import_2 = __webpack_require__(22239);
/* import */ var _jupyterlab_console__rspack_import_2_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_console__rspack_import_2);
/* import */ var _jupyterlab_coreutils__rspack_import_3 = __webpack_require__(62611);
/* import */ var _jupyterlab_coreutils__rspack_import_3_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_coreutils__rspack_import_3);
/* import */ var _jupyterlab_notebook__rspack_import_4 = __webpack_require__(73995);
/* import */ var _jupyterlab_notebook__rspack_import_4_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_notebook__rspack_import_4);
/* import */ var _jupyterlab_translation__rspack_import_5 = __webpack_require__(86211);
/* import */ var _jupyterlab_translation__rspack_import_5_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_translation__rspack_import_5);
/* import */ var _jupyterlab_ui_components__rspack_import_6 = __webpack_require__(18179);
/* import */ var _jupyterlab_ui_components__rspack_import_6_default = /*#__PURE__*/__webpack_require__.n(_jupyterlab_ui_components__rspack_import_6);
/* import */ var _jupyter_notebook_application__rspack_import_7 = __webpack_require__(90755);
/* import */ var _jupyter_notebook_application__rspack_import_7_default = /*#__PURE__*/__webpack_require__.n(_jupyter_notebook_application__rspack_import_7);
/* import */ var _lumino_algorithm__rspack_import_8 = __webpack_require__(86554);
/* import */ var _lumino_algorithm__rspack_import_8_default = /*#__PURE__*/__webpack_require__.n(_lumino_algorithm__rspack_import_8);
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.









/**
 * A plugin to open consoles in a new tab
 */
const opener = {
    id: '@jupyter-notebook/console-extension:opener',
    requires: [_jupyterlab_application__rspack_import_0.IRouter],
    autoStart: true,
    description: 'A plugin to open consoles in a new tab',
    activate: (app, router) => {
        const { commands } = app;
        const consolePattern = new RegExp('/consoles/(.*)');
        const command = 'router:console';
        commands.addCommand(command, {
            execute: (args) => {
                const parsed = args;
                const matches = parsed.path.match(consolePattern);
                if (!matches) {
                    return;
                }
                const [, match] = matches;
                if (!match) {
                    return;
                }
                const path = decodeURIComponent(match);
                commands.execute('console:create', { path });
            },
        });
        router.register({ command, pattern: consolePattern });
    },
};
/**
 * Open consoles in a new tab or in the side panel (scratchpad like).
 */
const redirect = {
    id: '@jupyter-notebook/console-extension:redirect',
    requires: [_jupyterlab_console__rspack_import_2.IConsoleTracker],
    optional: [_jupyter_notebook_application__rspack_import_7.INotebookPathOpener, _jupyter_notebook_application__rspack_import_7.INotebookShell, _jupyterlab_notebook__rspack_import_4.INotebookTracker],
    autoStart: true,
    description: 'Open consoles in a new tab',
    activate: (app, tracker, notebookPathOpener, notebookShell, notebookTracker) => {
        const baseUrl = _jupyterlab_coreutils__rspack_import_3.PageConfig.getBaseUrl();
        const opener = notebookPathOpener !== null && notebookPathOpener !== void 0 ? notebookPathOpener : _jupyter_notebook_application__rspack_import_7.defaultNotebookPathOpener;
        tracker.widgetAdded.connect(async (send, console) => {
            var _a, _b, _c, _d;
            // Check if we should open the console in side panel:
            //  - this is a notebook view
            //  - the notebook and the console share the same kernel
            // Otherwise, the console opens in a new tab.
            if (notebookShell && notebookTracker) {
                const notebook = notebookTracker.currentWidget;
                // Wait for the notebook and console to be ready.
                await Promise.all([
                    notebook === null || notebook === void 0 ? void 0 : notebook.sessionContext.ready,
                    console.sessionContext.ready,
                ]);
                const notebookKernelId = (_b = (_a = notebook === null || notebook === void 0 ? void 0 : notebook.sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel) === null || _b === void 0 ? void 0 : _b.id;
                const consoleKernelId = (_d = (_c = console.sessionContext.session) === null || _c === void 0 ? void 0 : _c.kernel) === null || _d === void 0 ? void 0 : _d.id;
                if (notebookKernelId === consoleKernelId) {
                    notebookShell.add(console, 'right');
                    notebookShell.expandRight(console.id);
                    return;
                }
            }
            const { sessionContext } = console;
            await sessionContext.ready;
            const widget = (0,_lumino_algorithm__rspack_import_8.find)(app.shell.widgets('main'), (w) => w.id === console.id);
            if (widget) {
                // bail if the console is already added to the main area
                return;
            }
            opener.open({
                prefix: _jupyterlab_coreutils__rspack_import_3.URLExt.join(baseUrl, 'consoles'),
                path: sessionContext.path,
                target: '_blank',
            });
            // the widget is not needed anymore
            console.dispose();
        });
    },
};
/**
 * Open consoles in the side panel.
 */
const scratchpadConsole = {
    id: '@jupyter-notebook/console-extension:scratchpad-console',
    requires: [_jupyterlab_notebook__rspack_import_4.INotebookTracker],
    optional: [_jupyter_notebook_application__rspack_import_7.INotebookShell, _jupyterlab_apputils__rspack_import_1.ICommandPalette, _jupyterlab_translation__rspack_import_5.ITranslator],
    autoStart: true,
    description: 'Open scratchpad console in side panel',
    activate: (app, tracker, notebookShell, palette, translator) => {
        const { commands } = app;
        const manager = app.serviceManager;
        const trans = (translator !== null && translator !== void 0 ? translator : _jupyterlab_translation__rspack_import_5.nullTranslator).load('notebook');
        const command = 'scratchpad-console:open';
        commands.addCommand(command, {
            label: (args) => args['isPalette']
                ? trans.__('Open a scratchpad console')
                : trans.__('Scratchpad console'),
            isVisible: () => !!tracker.currentWidget,
            icon: (args) => (args['isPalette'] ? undefined : _jupyterlab_ui_components__rspack_import_6.consoleIcon),
            execute: async (args) => {
                var _a, _b, _c, _d;
                if (!notebookShell) {
                    return;
                }
                const consoleId = scratchpadConsole.id;
                const sidebar = notebookShell.rightHandler;
                // Close the console if it is already opened (shortcut only).
                if (sidebar.isVisible && ((_a = sidebar.currentWidget) === null || _a === void 0 ? void 0 : _a.id) === consoleId) {
                    if (!args.isPalette && !args.isMenu) {
                        notebookShell.collapseRight();
                        (_b = notebookShell.currentWidget) === null || _b === void 0 ? void 0 : _b.activate();
                    }
                    return;
                }
                let panel = sidebar.widgets.find((w) => w.id === consoleId);
                // Create the widget if it is not already in the right area.
                if (!panel) {
                    const notebook = tracker.currentWidget;
                    if (!notebook) {
                        return;
                    }
                    const notebookSessionContext = notebook.sessionContext;
                    await Promise.all([notebookSessionContext.ready, manager.ready]);
                    const id = (_d = (_c = notebookSessionContext.session) === null || _c === void 0 ? void 0 : _c.kernel) === null || _d === void 0 ? void 0 : _d.id;
                    const kernelPref = notebookSessionContext.kernelPreference;
                    panel = await commands.execute('console:create', {
                        kernelPreference: { ...kernelPref, id },
                    });
                    if (!panel) {
                        console.error('An error occurred during scratchpad console creation');
                        return;
                    }
                    panel.title.caption = trans.__('Console');
                    panel.id = consoleId;
                }
                else {
                    notebookShell.expandRight(consoleId);
                }
            },
            describedBy: {
                args: {
                    type: 'object',
                    properties: {
                        isPalette: {
                            type: 'boolean',
                            description: trans.__('Whether the command is executed from the palette'),
                        },
                        isMenu: {
                            type: 'boolean',
                            description: trans.__('Whether the command is executed from the menu'),
                        },
                    },
                },
            },
        });
        if (palette) {
            palette.addItem({
                category: 'Notebook Console',
                command,
                args: { isPalette: true },
            });
        }
    },
};
/**
 * Export the plugins as default.
 */
const plugins = [
    opener,
    redirect,
    scratchpadConsole,
];
/* export default */ const __rspack_default_export = (plugins);


},

}]);
//# sourceMappingURL=9393.289f58c10192d413.js.map?v=289f58c10192d413