A `<live-code>` element for editable code with live output.
npm install @lume/live-codeA HTML element that gives you a code editor with live results as you type.
#### npm install @lume/live-code
Compatible with Solid.js, Svelte, Vue, Angular, Ember, jQuery, React, Astro, Qwik.js, and every other web framework or library for creating HTML-based applications.
- CodePen: https://codepen.io/trusktr/pen/PogvVBj
- Live demos on Lume's docs site are made with : https://docs.lume.io/examples/hello-world/
```
npm install && npm start
Specify content with the content attribute:
`html
`
Specify content with the content property:
`html
`
The content attribute or JS property is more useful for short pieces of text,
or for programmatically setting from a string, and with template systems that
set attributes from JS variables.
Here's a JSX example (useful in React, Preact, Solid.js, etc, requires using a compiler such as Babel, TypeScript, or ESBuild):
`js`
function SomeComponent(props) {
// Set the content from a variable.
return
}
Here's a Lit html example (does not require any build step):
`js
render() {
return html`
}
Here's a Solid.js html example in a Lume Element (does not require any build step):
`js
template() {
return html`
}
Etc. can be used in Vue, Svelte, Angular, and all the rest.
Specify a file with the src attribute or JS property, and text content will be fetched from that file:
`html`
Lastly, use a to specify text content inline. This can be cleanercontent
than placing multiline text inside the attribute by hand:
`html`
Example
Note that if src or content are specified, those take priority over the method.
Note that currently only works when it is initially present, butcontent
not if it is added later. If you're doing things programmatically, then send the
content in via the property instead of appending a (f.e.editor.content = template.innerHTML).
Each attribute has a respective JS property of the same name.
- content - Either a string of text, or a class or ID selector starting with.
or #. The given text string, or the text content of the selected element,reset()
will appear in the editor. Any time the user resets the editor with the Reset
button or method, the text in the editor will reset to the initial""
value specified by this. Default: which is ignored.src
- - Specify a file from which to get text content from. If content issrc
also specified, content loaded from will have priority and content will""
be overridden. Default: which is ignored.autorun
- - A boolean. If true, editing the text will cause the preview areaRerun
to automatically re-run based on the new content. The button will always force atrue
rerun. Default: .stripIndent
- - A boolean. If true, the given code will be unindented, whichtrue
is useful for template strings that are indented within the source where they
are defined. Default: .trim
- - A boolean. If true, leading and trailing white space will be removed.true
Default: .debounce
- - A number. If autorun is true, then autorun is debounced by1000
this amount in milliseconds after a user types into the code editor. Defaults:
.mode
- - The mode specifies which type of content the editor will execute.
Possible values are the following strings:
- "html>iframe" - The content will be treated as HTML and placed in an iframe."script>iframe"
- - The content is executed as a