2021-01-08 05:13:17 +08:00
|
|
|
import "../css/app.css";
|
2021-01-08 03:55:45 +08:00
|
|
|
|
2021-01-08 05:13:17 +08:00
|
|
|
import "phoenix_html";
|
|
|
|
import { Socket } from "phoenix";
|
|
|
|
import NProgress from "nprogress";
|
|
|
|
import { LiveSocket } from "phoenix_live_view";
|
2021-01-18 05:03:03 +08:00
|
|
|
import ContentEditable from "./content_editable";
|
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-01-18 05:03:03 +08:00
|
|
|
|
|
|
|
const Hooks = {
|
|
|
|
ContentEditable,
|
2021-01-30 07:33:04 +08:00
|
|
|
Cell,
|
|
|
|
Session,
|
2021-02-21 23:54:44 +08:00
|
|
|
FocusOnUpdate,
|
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, {
|
|
|
|
params: { _csrf_token: csrfToken },
|
2021-01-18 05:03:03 +08:00
|
|
|
hooks: Hooks,
|
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-01-08 05:13:17 +08:00
|
|
|
window.addEventListener("phx:page-loading-start", (info) => NProgress.start());
|
|
|
|
window.addEventListener("phx:page-loading-stop", (info) => NProgress.done());
|
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;
|