Lightweight code editor Web Component with syntax highlighting
# web
# view source
example/web.ts
import 'code-syntax/themes/default.css'
import 'plenty-themes/laser.css'
import { CodeEditElement, languages } from 'code-edit'
languages.js = import('code-syntax/languages/js.js')
customElements.define('code-edit', CodeEditElement)
const style = document.createElement('style')
style.textContent = /*css*/ `
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
background: #333;
}
pre {
color: var(--color);
background: var(--background);
}
code-edit {
margin: 15px;
padding: 15px;
width: 300px;
height: 100px;
font-family: monospace;
resize: both;
}
`
document.head.appendChild(style)
document.body.innerHTML = /*html*/ `
<code-edit id="demo" autoresize autofocus language="js" theme="laser">export interface HTMLCodeEditElement {
value?: string
language?: string
syntax?: SyntaxDefinition | Promise<{ default: SyntaxDefinition }>
theme?: string
tabsize?: number
tabstyle?: 'tabs' | 'spaces'
comments?: string
}</code-edit>
`
# CodeEditElement
src/code-edit.tsx#L172
# $
Context<CodeEditElement & JsxContext<CodeEditElement> & Omit<{
<T>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- Wrapper<T>
},
"transition"
>> # TextShadow
src/code-edit.tsx#L215 # context
ContextClass<CodeEditElement & JsxContext<CodeEditElement> & Omit<{
<T>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- Wrapper<T>
},
"transition"
>> # onmounted
EventHandler<CodeEditElement, CustomEvent<any>>
# onunmounted
EventHandler<CodeEditElement, CustomEvent<any>>
# created
(ctx)
# ctx
Context<CodeEditElement & JsxContext<CodeEditElement> & Omit<{
<T>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- Wrapper<T>
},
"transition"
>> created(ctx) =>
- void
# mounted
($)
src/code-edit.tsx#L283
# $
Context<CodeEditElement & JsxContext<CodeEditElement> & Omit<{
<T>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- Wrapper<T>
},
"transition"
>> mounted($) =>
- void
# on
(name)
on<K>(name) =>
- On<Fn<[ EventHandler<CodeEditElement, LifecycleEvents & object [K]> ], Off>>
- code-syntax by stagas – Code syntax highlight Web Component
- get-element-offset by stagas – Get accurate DOM element offset.
- relative-mouse by stagas – Get mouse position relative to a DOM element.
- sigl by stagas – Web framework
- super-impose by stagas – Web Component that super imposes one child over another to the same scroll position
- textarea-code by stagas – Web Component that extends a textarea element with code editor behavior.
All contributions are welcome!