2023-06-01 09:49:27 +00:00
|
|
|
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
|
|
|
|
// to get started and then uncomment the line below.
|
|
|
|
// import "./user_socket.js"
|
|
|
|
|
|
|
|
import "phoenix_html"
|
2023-12-16 20:40:57 +00:00
|
|
|
import { Socket } from "phoenix"
|
|
|
|
import { LiveSocket } from "phoenix_live_view"
|
2023-06-01 09:49:27 +00:00
|
|
|
import topbar from "../vendor/topbar"
|
2023-11-23 22:56:38 +00:00
|
|
|
import Alpine from "alpinejs"
|
2023-12-16 20:40:57 +00:00
|
|
|
import { Terminal } from "xterm"
|
|
|
|
import { FitAddon } from "@xterm/addon-fit"
|
2023-11-23 22:56:38 +00:00
|
|
|
|
2023-12-16 20:40:57 +00:00
|
|
|
let Hooks = {}
|
|
|
|
|
|
|
|
// TODO: Move this code and xterm into a separate generated file, and load that file only when needed
|
|
|
|
Hooks.Terminal = {
|
|
|
|
mounted() {
|
|
|
|
const term = new Terminal({
|
|
|
|
fontFamily: '"Courier New", "DejaVu Sans Mono", "Everson Mono", monospace',
|
|
|
|
fontSize: 13,
|
|
|
|
convertEol: true,
|
|
|
|
theme: {
|
|
|
|
background: "#24273a",
|
|
|
|
foreground: "#cad3f5",
|
|
|
|
cursor: "#f4dbd6",
|
|
|
|
black: "#494D64",
|
|
|
|
red: "#ed8796",
|
|
|
|
green: "#a6da95",
|
|
|
|
yellow: "#eed49f",
|
|
|
|
blue: "#8aadf4",
|
|
|
|
magenta: "#f5bde6",
|
|
|
|
cyan: "#8bd5ca",
|
|
|
|
white: "#b8c0e0",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const fitAddon = new FitAddon()
|
|
|
|
const resizeObserver = new ResizeObserver(() => fitAddon.fit())
|
|
|
|
|
|
|
|
term.loadAddon(fitAddon)
|
|
|
|
term.open(this.el)
|
|
|
|
term.onData(data => this.pushEventTo(this.el, "data_event", data))
|
|
|
|
term.onResize(resize => this.pushEventTo(this.el, "resize_event", resize))
|
|
|
|
|
|
|
|
this.handleEvent("data", payload => term.write(payload.data || ""))
|
|
|
|
|
|
|
|
fitAddon.fit()
|
|
|
|
resizeObserver.observe(this.el)
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 09:49:27 +00:00
|
|
|
|
|
|
|
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
|
2023-11-23 22:56:38 +00:00
|
|
|
let liveSocket = new LiveSocket("/live", Socket, {
|
2023-12-16 20:40:57 +00:00
|
|
|
params: { _csrf_token: csrfToken },
|
2023-11-23 22:56:38 +00:00
|
|
|
dom: {
|
|
|
|
onBeforeElUpdated(from, to) {
|
|
|
|
if (from._x_dataStack) {
|
|
|
|
window.Alpine.clone(from, to)
|
|
|
|
}
|
|
|
|
}
|
2023-12-16 20:40:57 +00:00
|
|
|
},
|
|
|
|
hooks: Hooks,
|
2023-11-23 22:56:38 +00:00
|
|
|
})
|
2023-06-01 09:49:27 +00:00
|
|
|
|
|
|
|
// Show progress bar on live navigation and form submits
|
2023-12-16 20:40:57 +00:00
|
|
|
topbar.config({ barColors: { 0: "#29d" }, shaDowColor: "rgba(0, 0, 0, .3)" })
|
2023-06-01 09:49:27 +00:00
|
|
|
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
|
|
|
|
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
|
|
|
|
|
|
|
|
// connect if there are any LiveViews on the page
|
|
|
|
liveSocket.connect()
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
window.liveSocket = liveSocket
|
|
|
|
|
2023-12-16 20:40:57 +00:00
|
|
|
Alpine.start()
|
|
|
|
window.Alpine = Alpine
|