first commit

This commit is contained in:
Mateusz Gruszczyński
2026-07-17 15:29:08 +02:00
commit 771494671b
35 changed files with 5020 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
const VIEWS = new Set(["edit", "split", "preview"]);
const MODES = new Set(["markdown", "text"]);
export function readEditorState() {
const params = new URLSearchParams(window.location.search);
return {
view: VIEWS.has(params.get("view")) ? params.get("view") : "split",
mode: MODES.has(params.get("mode")) ? params.get("mode") : "markdown",
};
}
export function writeEditorState(state, { replace = false } = {}) {
const url = new URL(window.location.href);
url.searchParams.set("view", state.view);
url.searchParams.set("mode", state.mode);
const method = replace ? "replaceState" : "pushState";
window.history[method]({ ...state }, "", `${url.pathname}${url.search}${url.hash}`);
window.dispatchEvent(new CustomEvent("rustpad:urlchange", { detail: { url: url.href } }));
return url.href;
}
export function currentShareUrl(state) {
const url = new URL(window.location.href);
url.searchParams.set("view", state.view);
url.searchParams.set("mode", state.mode);
return url.href;
}