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";
|
|
|
|
import { LiveSocket } from "phoenix_live_view";
|
2022-03-16 18:33:53 +08:00
|
|
|
|
|
|
|
import hooks from "./hooks";
|
|
|
|
import { morphdomOptions } from "./dom";
|
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";
|
2022-03-16 18:33:53 +08:00
|
|
|
import { registerTopbar, registerGlobalEventHandlers } from "./events";
|
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,
|
2022-03-16 18:33:53 +08:00
|
|
|
dom: morphdomOptions,
|
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
|
2022-03-16 18:33:53 +08:00
|
|
|
registerTopbar();
|
2022-02-03 22:05:16 +08:00
|
|
|
|
2022-03-16 18:33:53 +08:00
|
|
|
// Handle custom events dispatched with JS.dispatch/3
|
|
|
|
registerGlobalEventHandlers();
|
2022-02-03 22:05:16 +08:00
|
|
|
|
2022-03-16 18:33:53 +08:00
|
|
|
// Reflect global configuration in attributes to enable CSS rules
|
|
|
|
settingsStore.getAndSubscribe((settings) => {
|
|
|
|
document.body.setAttribute("data-editor-theme", settings.editor_theme);
|
2022-02-03 22:05:16 +08:00
|
|
|
});
|
2021-01-08 04:16:54 +08:00
|
|
|
|
2022-03-16 18:33:53 +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
|
|
|
|
2022-03-16 18:33:53 +08:00
|
|
|
// Expose liveSocket on window for web console debug logs and latency simulation:
|
2021-01-08 04:16:54 +08:00
|
|
|
// >> liveSocket.enableDebug()
|
2022-03-16 18:33:53 +08:00
|
|
|
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
|
2021-01-08 04:16:54 +08:00
|
|
|
// >> liveSocket.disableLatencySim()
|
2021-01-08 05:13:17 +08:00
|
|
|
window.liveSocket = liveSocket;
|