You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defmoduleKinoJsonInputdouseKino.JSuseKino.JS.Livedefnew(code)doKino.JS.Live.new(__MODULE__,code)enddefread(kino)doKino.JS.Live.call(kino,:read)end@impltruedefinit(code,ctx)do{:ok,assign(ctx,code: code)}end@impltruedefhandle_connect(ctx)do{:ok,ctx.assigns.code,ctx}end@impltruedefhandle_event("update_code",code,ctx)do{:noreply,assign(ctx,code: code)}end@impltruedefhandle_call(:read,_from,ctx)do{:reply,ctx.assigns.code,ctx}endasset"main.js"do""" export async function init(ctx, code) { await ctx.importCSS("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css"); await ctx.importJS("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"); await ctx.importJS("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"); await ctx.importCSS("https://cdn.jsdelivr.net/gh/WebCoder49/[email protected]/code-input.min.css"); await ctx.importJS("https://cdn.jsdelivr.net/gh/WebCoder49/[email protected]/code-input.min.js"); await ctx.importJS("https://cdn.jsdelivr.net/gh/WebCoder49/[email protected]/plugins/indent.min.js"); // This is needed because the CodeInput lib is activated // on window.load (https://github.com/WebCoder49/code-input/blob/v2.2.1/code-input.js#L983-L985) // but by the time this JS code is executed, the original load event has already been fired. window.dispatchEvent(new Event("load")); codeInput.registerTemplate("syntax-highlighted", codeInput.templates.prism(Prism, [new codeInput.plugins.Indent()])); ctx.root.innerHTML = ` <code-input id="input-json" language="json" template="syntax-highlighted" placeholder="JSON">${code}</code-input> `; const codeInputEl = document.getElementById("input-json"); codeInputEl.addEventListener("change", (event) => { ctx.pushEvent("update_code", event.target.value); }); } """endend
kino_json_input=KinoJsonInput.new("")
ifKinoJsonInput.read(kino_json_input)==""doKino.interrupt!(:normal,"fill in the JSON input")end
importKino.Shorts
json=kino_json_input|>KinoJsonInput.read()|>Jason.decode!()grid([markdown("### Here's the preview of your JSON"),Kino.Tree.new(json)])