import { sandbox } from "$sb/plugos-syscall/mod.ts"; import { editor, markdown, sandbox as serverSandbox, system, } from "$sb/silverbullet-syscall/mod.ts"; export async function parsePageCommand() { console.log( "AST", JSON.stringify( await markdown.parseMarkdown(await editor.getText()), null, 2, ), ); } export async function showLogsCommand() { // Running in client/server mode? const clientServer = !!(await system.getEnv()); if (clientServer) { const clientLogs = await sandbox.getLogs(); const serverLogs = await serverSandbox.getServerLogs(); await editor.showPanel( "bhs", 1, `
Client logs (max 100)
${
        clientLogs
          .map((le) => `[${le.level}] ${le.message}`)
          .join("\n")
      }
Server logs (max 100)
${
        serverLogs
          .map((le) => `[${le.level}] ${le.message}`)
          .join("\n")
      }
`, ` var clientDiv = document.getElementById("client-log"); clientDiv.scrollTop = clientDiv.scrollHeight; var serverDiv = document.getElementById("server-log"); serverDiv.scrollTop = serverDiv.scrollHeight; self.reloadLogs = () => { sendEvent("log:reload"); }; self.close = () => { sendEvent("log:hide"); }; `, ); } else { const logs = await sandbox.getLogs(); await editor.showPanel( "bhs", 1, `
Logs (max 100)
${
        logs
          .map((le) => `[${le.level}] ${le.message}`)
          .join("\n")
      }
`, ` var clientDiv = document.getElementById("log"); clientDiv.scrollTop = clientDiv.scrollHeight; self.reloadLogs = () => { sendEvent("log:reload"); }; self.close = () => { sendEvent("log:hide"); }; `, ); } } export async function hideBhsCommand() { await editor.hidePanel("bhs"); }