"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["5951"],{8607:function(e,n,t){t.r(n),t.d(n,{default:()=>u,frontMatter:()=>a,metadata:()=>o,assets:()=>l,toc:()=>d,contentTitle:()=>c});var o=JSON.parse('{"id":"configuration/query-params","title":"Query Parameters","description":"A flexible and convenient way to configure the app is to use URL query parameters.","source":"@site/docs/configuration/query-params.mdx","sourceDirName":"configuration","slug":"/configuration/query-params","permalink":"/docs/configuration/query-params","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/configuration/query-params.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Configuration Object","permalink":"/docs/configuration/configuration-object"},"next":{"title":"LiveCodes SDK","permalink":"/docs/sdk/"}}'),s=t("5893"),i=t("65"),r=t("3365");let a={},c="Query Parameters",l={},d=[{value:"Usage",id:"usage",level:2}];function h(e){let n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"query-parameters",children:"Query Parameters"})}),"\n","\n",(0,s.jsxs)(n.p,{children:["A flexible and convenient way to configure the app is to use URL query parameters.\nIt allows configuration of a wide range of options, including those of the ",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object",children:"configuration object"})," and ",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#embed-options",children:"embed options"}),"."]}),"\n",(0,s.jsx)("div",{style:{clear:"both"}}),"\n",(0,s.jsx)(n.p,{children:"Example:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"https://livecodes.io?js=console.log('Hello World!')&console=open\n"})}),"\n",(0,s.jsx)(r.Z,{params:{js:"console.log('Hello World!')",console:"open"}}),"\n",(0,s.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["All properties of ",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object",children:"configuration object"})," and ",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#embed-options",children:"embed options"})," that have values of primitive types (e.g. string, number, boolean) can be assigned to a query parameter with the same name."]}),"\n",(0,s.jsxs)(n.p,{children:["These include:\n",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#config",children:"config"}),",\n",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#import",children:"import"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#mode",children:"lite"}),",\n",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#loading",children:"loading"}),",\n",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#template",children:"template"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#view",children:"view"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#title",children:"title"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#description",children:"description"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#activeeditor",children:"activeEditor"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#csspreset",children:"cssPreset"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#readonly",children:"readonly"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#allowlangchange",children:"allowLangChange"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#mode",children:"mode"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#autoupdate",children:"autoupdate"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#autosave",children:"autosave"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#delay",children:"delay"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#formatonsave",children:"formatOnsave"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#theme",children:"theme"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#themecolor",children:"themeColor"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#applanguage",children:"appLanguage"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#recoverunsaved",children:"recoverUnsaved"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#welcome",children:"welcome"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#showspacing",children:"showSpacing"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#layout",children:"layout"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#editor",children:"editor"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#editortheme",children:"editorTheme"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#fontfamily",children:"fontFamily"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#fontsize",children:"fontSize"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#usetabs",children:"useTabs"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#tabsize",children:"tabSize"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#linenumbers",children:"lineNumbers"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#wordwrap",children:"wordWrap"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#closebrackets",children:"closeBrackets"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#emmet",children:"emmet"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#editormode",children:"editorMode"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#semicolons",children:"semicolons"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#singlequote",children:"singleQuote"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#trailingcomma",children:"trailingComma"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"Example:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"?theme=light&delay=500&lineNumbers=false\n"})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Any value given for booleans except ",(0,s.jsx)(n.code,{children:'"false"'})," (including no value) will be considered ",(0,s.jsx)(n.code,{children:"true"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["Example: all these are considered ",(0,s.jsx)(n.code,{children:"true"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"?lite=true\n?lite=1\n?lite=any\n?lite\n"})}),"\n",(0,s.jsxs)(n.p,{children:["while this is considered ",(0,s.jsx)(n.code,{children:"false"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"?lite=false\n"})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Parameters that expect array of values can be supplied with comma separated values. These include:\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#tags",children:"tags"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#languages",children:"languages"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#processors",children:"processors"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#stylesheets",children:"stylesheets"}),",\n",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#scripts",children:"scripts"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"Example:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"?languages=html,md,css,ts\n"})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Values set in the URL query parameters override those set in ",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object",children:"configuration object"}),"."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Unlike ",(0,s.jsx)(n.a,{href:"/docs/features/user-settings",children:"user settings"})," that are set in the UI which are saved and subsequently used, those that are set in query parameters are not automatically saved."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"Additional query parameters include:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"no-defaults"}),": ",(0,s.jsx)(n.code,{children:"boolean"})," (Default: ",(0,s.jsx)(n.code,{children:"false"}),")."]}),"\n",(0,s.jsxs)(n.p,{children:["If ",(0,s.jsx)(n.code,{children:"true"}),", the app will not load the ",(0,s.jsx)(n.a,{href:"/docs/features/default-template-language",children:"default template/language"}),"."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"x"}),": ",(0,s.jsx)(n.code,{children:"string"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["Alias to ",(0,s.jsx)(n.a,{href:"/docs/sdk/js-ts#import",children:(0,s.jsx)(n.code,{children:"import"})})," (a URL to ",(0,s.jsx)(n.a,{href:"/docs/features/import",children:"import"}),")."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"files"}),": ",(0,s.jsx)(n.code,{children:"string"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["A comma-separated ",(0,s.jsx)(n.a,{href:"/docs/features/import#file-selection",children:"list of files to import"}),"."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"raw"}),": ",(0,s.jsx)(n.a,{href:"/docs/api/type-aliases/Language",children:(0,s.jsx)(n.code,{children:"Language"})}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["When used with ",(0,s.jsx)(n.code,{children:"import"})," or ",(0,s.jsx)(n.code,{children:"x"}),", imports the URL as code of the provided language."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"language"}),": ",(0,s.jsx)(n.a,{href:"/docs/api/type-aliases/Language",children:(0,s.jsx)(n.code,{children:"Language"})}),"."]}),"\n",(0,s.jsx)(n.p,{children:"The language to load by default in the editor."}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"lang"}),": ",(0,s.jsx)(n.a,{href:"/docs/api/type-aliases/Language",children:(0,s.jsx)(n.code,{children:"Language"})}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["Alias to ",(0,s.jsx)(n.code,{children:"language"}),"."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"active"}),": ",(0,s.jsx)(n.code,{children:'"markup" | "style" | "script" | 0 | 1 | 2'}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["Alias to ",(0,s.jsx)(n.a,{href:"/docs/configuration/configuration-object#activeeditor",children:(0,s.jsx)(n.code,{children:"activeEditor"})}),"."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"tools"}),": ",(0,s.jsx)(n.code,{children:'"open" | "full" | "closed" | "console" | "compiled" | "tests" | "none"'})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"/docs/features/tools-pane",children:"tools pane"})," status."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"console"}),": ",(0,s.jsx)(n.code,{children:'"open" | "full" | "closed" | "none"'})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"/docs/features/console",children:"console"})," status."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"compiled"}),": ",(0,s.jsx)(n.code,{children:'"open" | "full" | "closed" | "none"'})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"/docs/features/compiled-code",children:"compiled code viewer"})," status."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"tests"}),": ",(0,s.jsx)(n.code,{children:'"open" | "full" | "closed" | "none"'})]}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.a,{href:"/docs/features/tests",children:"tests panel"})," status."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"scrollPosition"}),": ",(0,s.jsx)(n.code,{children:"boolean"})," (Default: ",(0,s.jsx)(n.code,{children:"true"}),")."]}),"\n",(0,s.jsxs)(n.p,{children:["If ",(0,s.jsx)(n.code,{children:"false"}),", the ",(0,s.jsx)(n.a,{href:"/docs/features/result",children:"result page"})," ",(0,s.jsx)(n.a,{href:"/docs/features/result#scroll-position",children:"scroll position"})," will not be maintained after reload."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Any ",(0,s.jsx)(n.a,{href:"/docs/api/type-aliases/Language",children:(0,s.jsx)(n.code,{children:"Language"})})," can used as a query parameter, and the value will be used as its code."]}),"\n",(0,s.jsx)(n.p,{children:"Example:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"https://livecodes.io?js=console.log('Hello World!')\n"})}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.admonition,{title:"Examples",type:"info",children:(0,s.jsxs)(n.p,{children:["For usage examples, check ",(0,s.jsx)(n.a,{href:"pathname:///../stories/?path=/story/embed-options-params--select-language",children:"storybook"})," and ",(0,s.jsx)(n.a,{href:"https://github.com/live-codes/livecodes/blob/develop/src/livecodes/config/__tests__/build-config.spec.ts",children:"unit tests"}),"."]})})]})}function u(e={}){let{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},3365:function(e,n,t){t.d(n,{Z:()=>j});var o=t("5893"),s=t("4200"),i=t("7294"),r=t("8294");function a(e){let n=(0,i.useRef)(null),[t,s]=(0,i.useState)(e.className||""),[a,c]=(0,i.useState)(e.style||{}),[l,d]=(0,i.useState)(e.height),[h,u]=(0,i.useState)(),[f,g]=(0,i.useState)(JSON.stringify(e.config||"")),[p,j]=(0,i.useState)("");return(0,i.useEffect)(()=>{if(!n.current)return;let{className:t,style:o,height:i,sdkReady:a,config:l,...m}=e;if(s(t||""),c(o||{}),d(i),h&&p===JSON.stringify(m)){if(f===JSON.stringify(l))return;g(JSON.stringify(l)),"string"==typeof l?fetch(l).then(e=>e.json()).then(e=>{h?.setConfig(e)}):l&&h.setConfig(l)}else j(JSON.stringify(m)),h?.destroy(),(0,r.T)(n.current,{config:l,...m}).then(e=>{u(e),"function"==typeof a&&a(e)})},[e]),(0,i.useEffect)(()=>()=>{h?.destroy()},[]),(0,o.jsx)("div",{ref:n,className:t,style:a,"data-height":l})}var c=t("1858"),l=t("3262"),d=t("1705"),h=t("7645"),u=t("8168"),f=t("8228"),g=t("5050");function p(e){let[n,t]=(0,i.useState)(e.js),[s,r]=(0,i.useState)(e.ts),[a,c]=(0,i.useState)(e.react),[p,j]=(0,i.useState)(e.vue),[m,x]=(0,i.useState)(e.svelte),y="3.7rem",[b,v]=(0,i.useState)(!0),[w,S]=(0,i.useState)(y),E=(0,i.useRef)(null),C=()=>{setTimeout(()=>{S(`calc(${E.current.offsetHeight}px + ${y})`)},5),setTimeout(()=>{S(`calc(${E.current.offsetHeight}px + ${y})`)},255)};return(0,i.useEffect)(()=>{if(l.Z.canUseDOM){let e=function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===n?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};t(e(n,"js")),r(e(s,"ts")),c(e(a,"jsx")),j(e(p,"html")),x(e(m,"html"))}},[]),(0,o.jsxs)("details",{className:`alert alert--info ${g.Z.details} ${f.Z.details}`,"data-collapsed":b,style:{height:b?y:w,overflow:"hidden",willChange:"height",transition:`height ${b?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,o.jsx)("summary",{onClick:()=>{v(!b),C()},children:"show code"}),(0,o.jsx)("div",{ref:E,style:{display:"block",overflow:"hidden"},children:(0,o.jsx)("div",{className:g.Z.collapsibleContent,children:(0,o.jsxs)(u.Z,{groupId:"sdk-code",children:[(0,o.jsx)(h.Z,{value:"js",label:"JS",attributes:{onMouseDown:C},children:(0,o.jsx)(d.Z,{language:"js",children:n})}),(0,o.jsx)(h.Z,{value:"ts",label:"TS",attributes:{onMouseDown:C},children:(0,o.jsx)(d.Z,{language:"ts",children:s})}),(0,o.jsx)(h.Z,{value:"react",label:"React",attributes:{onMouseDown:C},children:(0,o.jsx)(d.Z,{language:"jsx",children:a})}),(0,o.jsx)(h.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:C},children:(0,o.jsx)(d.Z,{language:"html",children:p})}),(0,o.jsx)(h.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:C},children:(0,o.jsx)(d.Z,{language:"html",children:m})})]})})})]})}function j(e){let{className:n,style:t,showCode:i,height:r,...l}=e,{colorMode:d}=(0,s.I)(),h=e=>JSON.stringify(e,null,2),u=`
import { createPlayground } from 'livecodes';
const options = ${h(l)};
createPlayground('#container', options);
`.trimStart(),f=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${h(l)};
createPlayground('#container', options);
`.trimStart(),g=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${h(l)};
return (