diff --git a/frontend/common/parse_launch_params.js b/frontend/common/parse_launch_params.js new file mode 100644 index 0000000000..fe801ec0d9 --- /dev/null +++ b/frontend/common/parse_launch_params.js @@ -0,0 +1,38 @@ +/** + * + * @return {import("../components/Editor.js").LaunchParameters} + */ +export const parse_launch_params = () => { + const url_params = new URLSearchParams(window.location.search) + + return { + //@ts-ignore + notebook_id: url_params.get("id") ?? window.pluto_notebook_id, + //@ts-ignore + statefile: url_params.get("statefile") ?? window.pluto_statefile, + //@ts-ignore + statefile_integrity: url_params.get("statefile_integrity") ?? window.pluto_statefile_integrity, + //@ts-ignore + notebookfile: url_params.get("notebookfile") ?? window.pluto_notebookfile, + //@ts-ignore + notebookfile_integrity: url_params.get("notebookfile_integrity") ?? window.pluto_notebookfile_integrity, + //@ts-ignore + disable_ui: !!(url_params.get("disable_ui") ?? window.pluto_disable_ui), + //@ts-ignore + preamble_html: url_params.get("preamble_html") ?? window.pluto_preamble_html, + //@ts-ignore + isolated_cell_ids: url_params.has("isolated_cell_id") ? url_params.getAll("isolated_cell_id") : window.pluto_isolated_cell_ids, + //@ts-ignore + binder_url: url_params.get("binder_url") ?? window.pluto_binder_url, + //@ts-ignore + pluto_server_url: url_params.get("pluto_server_url") ?? window.pluto_pluto_server_url, + //@ts-ignore + slider_server_url: url_params.get("slider_server_url") ?? window.pluto_slider_server_url, + //@ts-ignore + recording_url: url_params.get("recording_url") ?? window.pluto_recording_url, + //@ts-ignore + recording_url_integrity: url_params.get("recording_url_integrity") ?? window.pluto_recording_url_integrity, + //@ts-ignore + recording_audio_url: url_params.get("recording_audio_url") ?? window.pluto_recording_audio_url, + } +} diff --git a/frontend/editor.js b/frontend/editor.js index 42a73b6300..bdddaf85ca 100644 --- a/frontend/editor.js +++ b/frontend/editor.js @@ -6,6 +6,7 @@ import { FetchProgress, read_Uint8Array_with_progress } from "./components/Fetch import { unpack } from "./common/MsgPack.js" import { RawHTMLContainer } from "./components/CellOutput.js" import { ProcessStatus } from "./common/ProcessStatus.js" +import { parse_launch_params } from "./common/parse_launch_params.js" const url_params = new URLSearchParams(window.location.search) @@ -25,40 +26,7 @@ export const set_disable_ui_css = (val) => { ///////////// // the rest: -/** - * - * @type {import("./components/Editor.js").LaunchParameters} - */ -const launch_params = { - //@ts-ignore - notebook_id: url_params.get("id") ?? window.pluto_notebook_id, - //@ts-ignore - statefile: url_params.get("statefile") ?? window.pluto_statefile, - //@ts-ignore - statefile_integrity: url_params.get("statefile_integrity") ?? window.pluto_statefile_integrity, - //@ts-ignore - notebookfile: url_params.get("notebookfile") ?? window.pluto_notebookfile, - //@ts-ignore - notebookfile_integrity: url_params.get("notebookfile_integrity") ?? window.pluto_notebookfile_integrity, - //@ts-ignore - disable_ui: !!(url_params.get("disable_ui") ?? window.pluto_disable_ui), - //@ts-ignore - preamble_html: url_params.get("preamble_html") ?? window.pluto_preamble_html, - //@ts-ignore - isolated_cell_ids: url_params.has("isolated_cell_id") ? url_params.getAll("isolated_cell_id") : window.pluto_isolated_cell_ids, - //@ts-ignore - binder_url: url_params.get("binder_url") ?? window.pluto_binder_url, - //@ts-ignore - pluto_server_url: url_params.get("pluto_server_url") ?? window.pluto_pluto_server_url, - //@ts-ignore - slider_server_url: url_params.get("slider_server_url") ?? window.pluto_slider_server_url, - //@ts-ignore - recording_url: url_params.get("recording_url") ?? window.pluto_recording_url, - //@ts-ignore - recording_url_integrity: url_params.get("recording_url_integrity") ?? window.pluto_recording_url_integrity, - //@ts-ignore - recording_audio_url: url_params.get("recording_audio_url") ?? window.pluto_recording_audio_url, -} +const launch_params = parse_launch_params() const truthy = (x) => x === "" || x === "true" const falsey = (x) => x === "false"