2021-01-08 05:13:17 +08:00
|
|
|
import "../css/app.css";
|
2021-03-12 23:40:37 +08:00
|
|
|
import "remixicon/fonts/remixicon.css";
|
2021-04-08 21:31:46 +08:00
|
|
|
import "katex/dist/katex.min.css";
|
2021-03-12 18:57:01 +08:00
|
|
|
|
|
|
|
import "@fontsource/inter";
|
|
|
|
import "@fontsource/inter/500.css";
|
|
|
|
import "@fontsource/inter/600.css";
|
|
|
|
import "@fontsource/jetbrains-mono";
|
2021-01-08 03:55:45 +08:00
|
|
|
|
2021-01-08 05:13:17 +08:00
|
|
|
import "phoenix_html";
|
|
|
|
import { Socket } from "phoenix";
|
2021-04-21 00:48:50 +08:00
|
|
|
import topbar from "topbar";
|
2021-01-08 05:13:17 +08:00
|
|
|
import { LiveSocket } from "phoenix_live_view";
|
2021-11-17 04:57:10 +08:00
|
|
|
import Headline from "./headline";
|
2021-01-30 07:33:04 +08:00
|
|
|
import Cell from "./cell";
|
|
|
|
import Session from "./session";
|
2021-02-21 23:54:44 +08:00
|
|
|
import FocusOnUpdate from "./focus_on_update";
|
2021-02-27 03:53:29 +08:00
|
|
|
import ScrollOnUpdate from "./scroll_on_update";
|
2021-03-05 05:09:57 +08:00
|
|
|
import VirtualizedLines from "./virtualized_lines";
|
2021-05-04 02:03:19 +08:00
|
|
|
import UserForm from "./user_form";
|
2021-12-04 04:57:21 +08:00
|
|
|
import EditorSettings from "./editor_settings";
|
2021-06-20 23:06:30 +08:00
|
|
|
import Timer from "./timer";
|
2021-06-26 22:47:52 +08:00
|
|
|
import MarkdownRenderer from "./markdown_renderer";
|
2021-06-30 23:48:27 +08:00
|
|
|
import Highlight from "./highlight";
|
2021-12-02 02:44:42 +08:00
|
|
|
import DragAndDrop from "./drag_and_drop";
|
2021-11-01 23:04:11 +08:00
|
|
|
import PasswordToggle from "./password_toggle";
|
2021-12-02 23:45:00 +08:00
|
|
|
import KeyboardControl from "./keyboard_control";
|
2021-03-20 21:10:15 +08:00
|
|
|
import morphdomCallbacks from "./morphdom_callbacks";
|
2021-12-24 21:18:34 +08:00
|
|
|
import JSOutput from "./js_output";
|
2021-05-04 02:03:19 +08:00
|
|
|
import { loadUserData } from "./lib/user";
|
2022-01-16 20:50:44 +08:00
|
|
|
import { settingsStore } from "./lib/settings";
|
2021-01-18 05:03:03 +08:00
|
|
|
|
2021-03-20 21:10:15 +08:00
|
|
|
const hooks = {
|
2021-11-17 04:57:10 +08:00
|
|
|
Headline,
|
2021-01-30 07:33:04 +08:00
|
|
|
Cell,
|
|
|
|
Session,
|
2021-02-21 23:54:44 +08:00
|
|
|
FocusOnUpdate,
|
2021-02-27 03:53:29 +08:00
|
|
|
ScrollOnUpdate,
|
2021-03-05 05:09:57 +08:00
|
|
|
VirtualizedLines,
|
2021-05-04 02:03:19 +08:00
|
|
|
UserForm,
|
2021-12-04 04:57:21 +08:00
|
|
|
EditorSettings,
|
2021-06-20 23:06:30 +08:00
|
|
|
Timer,
|
2021-06-26 22:47:52 +08:00
|
|
|
MarkdownRenderer,
|
2021-06-30 23:48:27 +08:00
|
|
|
Highlight,
|
2021-11-01 20:59:39 +08:00
|
|
|
DragAndDrop,
|
2021-11-01 23:04:11 +08:00
|
|
|
PasswordToggle,
|
2021-12-02 23:45:00 +08:00
|
|
|
KeyboardControl,
|
2021-12-24 21:18:34 +08:00
|
|
|
JSOutput,
|
2021-01-18 05:03:03 +08:00
|
|
|
};
|
2021-01-08 04:16:54 +08:00
|
|
|
|
2021-01-08 05:13:17 +08:00
|
|
|
const csrfToken = document
|
|
|
|
.querySelector("meta[name='csrf-token']")
|
|
|
|
.getAttribute("content");
|
|
|
|
|
|
|
|
const liveSocket = new LiveSocket("/live", Socket, {
|
2021-05-04 02:03:19 +08:00
|
|
|
params: (liveViewName) => {
|
|
|
|
return {
|
|
|
|
_csrf_token: csrfToken,
|
|
|
|
// Pass the most recent user data to the LiveView in `connect_params`
|
|
|
|
user_data: loadUserData(),
|
|
|
|
};
|
|
|
|
},
|
2021-03-20 21:10:15 +08:00
|
|
|
hooks: hooks,
|
|
|
|
dom: morphdomCallbacks,
|
2021-01-08 05:13:17 +08:00
|
|
|
});
|
2021-01-08 04:16:54 +08:00
|
|
|
|
|
|
|
// Show progress bar on live navigation and form submits
|
2021-04-21 01:29:12 +08:00
|
|
|
topbar.config({
|
|
|
|
barColors: { 0: "#b2c1ff" },
|
|
|
|
shadowColor: "rgba(0, 0, 0, .3)",
|
|
|
|
});
|
2021-04-21 00:48:50 +08:00
|
|
|
window.addEventListener("phx:page-loading-start", () => topbar.show());
|
|
|
|
window.addEventListener("phx:page-loading-stop", () => topbar.hide());
|
2021-01-08 04:16:54 +08:00
|
|
|
|
|
|
|
// connect if there are any LiveViews on the page
|
2021-01-08 05:13:17 +08:00
|
|
|
liveSocket.connect();
|
2021-01-08 04:16:54 +08:00
|
|
|
|
|
|
|
// expose liveSocket on window for web console debug logs and latency simulation:
|
|
|
|
// >> liveSocket.enableDebug()
|
|
|
|
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
|
|
|
|
// >> liveSocket.disableLatencySim()
|
2021-01-08 05:13:17 +08:00
|
|
|
window.liveSocket = liveSocket;
|
2021-11-04 00:16:09 +08:00
|
|
|
|
|
|
|
// Handling custom events dispatched with JS.dispatch/3
|
|
|
|
|
|
|
|
window.addEventListener("lb:focus", (event) => {
|
|
|
|
event.target.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener("lb:set_value", (event) => {
|
|
|
|
event.target.value = event.detail.value;
|
|
|
|
});
|
2021-11-11 02:28:09 +08:00
|
|
|
|
2022-01-29 04:45:04 +08:00
|
|
|
window.addEventListener("lb:check", (event) => {
|
|
|
|
event.target.checked = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener("lb:uncheck", (event) => {
|
|
|
|
event.target.checked = false;
|
|
|
|
});
|
|
|
|
|
2022-01-24 18:21:13 +08:00
|
|
|
window.addEventListener("lb:clipcopy", (event) => {
|
|
|
|
if ("clipboard" in navigator) {
|
2021-11-11 03:17:32 +08:00
|
|
|
const text = event.target.textContent;
|
|
|
|
navigator.clipboard.writeText(text);
|
2022-01-24 18:21:13 +08:00
|
|
|
} else {
|
|
|
|
alert(
|
|
|
|
"Sorry, your browser does not support clipboard copy.\nThis generally requires a secure origin — either HTTPS or localhost."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2021-11-11 03:17:32 +08:00
|
|
|
|
2021-11-11 02:28:09 +08:00
|
|
|
// Other global handlers
|
|
|
|
|
|
|
|
window.addEventListener("contextmenu", (event) => {
|
|
|
|
const target = event.target.closest("[data-contextmenu-trigger-click]");
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
event.preventDefault();
|
|
|
|
target.dispatchEvent(new Event("click", { bubbles: true }));
|
|
|
|
}
|
|
|
|
});
|
2022-01-16 20:50:44 +08:00
|
|
|
|
2022-01-29 04:45:04 +08:00
|
|
|
window.addEventListener("lb:session_list:on_selection_change", () => {
|
|
|
|
const anySessionSelected = !!document.querySelector(
|
|
|
|
"[name='session_ids[]']:checked"
|
|
|
|
);
|
|
|
|
const disconnect = document.querySelector(
|
|
|
|
"#edit-sessions [name='disconnect']"
|
|
|
|
);
|
|
|
|
const closeAll = document.querySelector("#edit-sessions [name='close_all']");
|
|
|
|
disconnect.disabled = !anySessionSelected;
|
|
|
|
closeAll.disabled = !anySessionSelected;
|
|
|
|
});
|
|
|
|
|
2022-01-16 20:50:44 +08:00
|
|
|
// Global configuration
|
|
|
|
|
|
|
|
settingsStore.getAndSubscribe((settings) => {
|
|
|
|
document.body.setAttribute("data-editor-theme", settings.editor_theme);
|
|
|
|
});
|