"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["5287"],{4892:function(e,t,s){s.r(t),s.d(t,{default:()=>h,frontMatter:()=>i,metadata:()=>o,assets:()=>c,toc:()=>d,contentTitle:()=>l});var o=JSON.parse('{"id":"features/read-only","title":"Read-Only","description":"In case you need to embed a playground in your web page to show case some code and want users to read through the code and not allow edits, you may use the readonly setting.","source":"@site/docs/features/read-only.mdx","sourceDirName":"features","slug":"/features/read-only","permalink":"/docs/features/read-only","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/read-only.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Lite Mode","permalink":"/docs/features/lite"},"next":{"title":"Permanent URL","permalink":"/docs/features/permanent-url"}}'),n=s("5893"),r=s("65"),a=s("3365");let i={},l="Read-Only",c={},d=[{value:"Using SDK",id:"using-sdk",level:2},{value:"Using query params",id:"using-query-params",level:2},{value:"Related",id:"related",level:2}];function u(e){let t={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.header,{children:(0,n.jsx)(t.h1,{id:"read-only",children:"Read-Only"})}),"\n","\n",(0,n.jsxs)(t.p,{children:["In case you need to embed a playground in your web page to show case some code and want users to read through the code and not allow edits, you may use the ",(0,n.jsx)(t.code,{children:"readonly"})," setting."]}),"\n",(0,n.jsxs)(t.p,{children:["Code editing, ",(0,n.jsx)(t.a,{href:"/docs/features/code-format",children:"formatting"}),", and ",(0,n.jsx)(t.a,{href:"/docs/features/console",children:"console input"})," are not available. However, any language supported by LiveCodes can be used, with syntax highlighting. Code can be ",(0,n.jsx)(t.a,{href:"/docs/features/code-prefill",children:"prefilled"}),", and is compiled and shown in the ",(0,n.jsx)(t.a,{href:"/docs/features/result",children:"result page"})," as usual."]}),"\n",(0,n.jsxs)(t.p,{children:["By default, a light-weight, minimal ",(0,n.jsx)(t.a,{href:"/docs/features/editor-settings#code-editor",children:"code editor"})," is used. This can be changed by explicitly setting the ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object",children:"configuration object"})," property ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object#editor",children:(0,n.jsx)(t.code,{children:"editor"})})," (e.g. to show hover intellisense)."]}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(a.Z,{template:"javascript",config:{readonly:!0}}),"\n",(0,n.jsx)(t.h2,{id:"using-sdk",children:"Using SDK"}),"\n",(0,n.jsxs)(t.p,{children:["set the ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object",children:"configuration object"})," property ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object#readonly",children:(0,n.jsx)(t.code,{children:"readonly"})})," to ",(0,n.jsx)(t.code,{children:"true"}),"."]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"import { createPlayground } from 'livecodes';\n\ncreatePlayground('#container', { template: 'javascript', config: { readonly: true } });\n"})}),"\n",(0,n.jsx)(t.h2,{id:"using-query-params",children:"Using query params"}),"\n",(0,n.jsxs)(t.p,{children:["add the ",(0,n.jsx)(t.a,{href:"/docs/configuration/query-params",children:"query parameter"})," ",(0,n.jsx)(t.code,{children:"readonly"})," (no need to set a value)."]}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.a,{href:"https://livecodes.io?template=javascript&readonly",children:"https://livecodes.io?template=javascript&readonly"})}),"\n",(0,n.jsx)(t.h2,{id:"related",children:"Related"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"/docs/features/code-prefill",children:"Code prefill"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"/docs/features/lite",children:"Lite mode"})}),"\n"]})]})}function h(e={}){let{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},3365:function(e,t,s){s.d(t,{Z:()=>m});var o=s("5893"),n=s("4200"),r=s("7294"),a=s("8294");function i(e){let t=(0,r.useRef)(null),[s,n]=(0,r.useState)(e.className||""),[i,l]=(0,r.useState)(e.style||{}),[c,d]=(0,r.useState)(e.height),[u,h]=(0,r.useState)(),[f,p]=(0,r.useState)(JSON.stringify(e.config||"")),[g,m]=(0,r.useState)("");return(0,r.useEffect)(()=>{if(!t.current)return;let{className:s,style:o,height:r,sdkReady:i,config:c,...y}=e;if(n(s||""),l(o||{}),d(r),u&&g===JSON.stringify(y)){if(f===JSON.stringify(c))return;p(JSON.stringify(c)),"string"==typeof c?fetch(c).then(e=>e.json()).then(e=>{u?.setConfig(e)}):c&&u.setConfig(c)}else m(JSON.stringify(y)),u?.destroy(),(0,a.T)(t.current,{config:c,...y}).then(e=>{h(e),"function"==typeof i&&i(e)})},[e]),(0,r.useEffect)(()=>()=>{u?.destroy()},[]),(0,o.jsx)("div",{ref:t,className:s,style:i,"data-height":c})}var l=s("1858"),c=s("3262"),d=s("1705"),u=s("7645"),h=s("8168"),f=s("8228"),p=s("5050");function g(e){let[t,s]=(0,r.useState)(e.js),[n,a]=(0,r.useState)(e.ts),[i,l]=(0,r.useState)(e.react),[g,m]=(0,r.useState)(e.vue),[y,v]=(0,r.useState)(e.svelte),j="3.7rem",[w,b]=(0,r.useState)(!0),[x,S]=(0,r.useState)(j),C=(0,r.useRef)(null),P=()=>{setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${j})`)},5),setTimeout(()=>{S(`calc(${C.current.offsetHeight}px + ${j})`)},255)};return(0,r.useEffect)(()=>{if(c.Z.canUseDOM){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};s(e(t,"js")),a(e(n,"ts")),l(e(i,"jsx")),m(e(g,"html")),v(e(y,"html"))}},[]),(0,o.jsxs)("details",{className:`alert alert--info ${p.Z.details} ${f.Z.details}`,"data-collapsed":w,style:{height:w?j:x,overflow:"hidden",willChange:"height",transition:`height ${w?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,o.jsx)("summary",{onClick:()=>{b(!w),P()},children:"show code"}),(0,o.jsx)("div",{ref:C,style:{display:"block",overflow:"hidden"},children:(0,o.jsx)("div",{className:p.Z.collapsibleContent,children:(0,o.jsxs)(h.Z,{groupId:"sdk-code",children:[(0,o.jsx)(u.Z,{value:"js",label:"JS",attributes:{onMouseDown:P},children:(0,o.jsx)(d.Z,{language:"js",children:t})}),(0,o.jsx)(u.Z,{value:"ts",label:"TS",attributes:{onMouseDown:P},children:(0,o.jsx)(d.Z,{language:"ts",children:n})}),(0,o.jsx)(u.Z,{value:"react",label:"React",attributes:{onMouseDown:P},children:(0,o.jsx)(d.Z,{language:"jsx",children:i})}),(0,o.jsx)(u.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:P},children:(0,o.jsx)(d.Z,{language:"html",children:g})}),(0,o.jsx)(u.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:P},children:(0,o.jsx)(d.Z,{language:"html",children:y})})]})})})]})}function m(e){let{className:t,style:s,showCode:r,height:a,...c}=e,{colorMode:d}=(0,n.I)(),u=e=>JSON.stringify(e,null,2),h=`
import { createPlayground } from 'livecodes';
const options = ${u(c)};
createPlayground('#container', options);
`.trimStart(),f=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${u(c)};
createPlayground('#container', options);
`.trimStart(),p=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${u(c)};
return (