efficient html canvas-based code text editor
# basic
# view source
example/basic.ts
import { add, sub } from 'canvy'
console.log(add(1, 2)) // => 3
console.log(sub(2, 5)) // => -3
# jsx
# view source
example/jsx.tsx
const h = (canvy.args: unknown[]) => args
console.log(<foo bar="baz" />)
// => [ 'foo', { bar: 'baz' } ]
# web
# view source
example/web.tsx
/** @jsxImportSource sigl */
import $ from 'sigl'
import { CanvyElement, EditorScene, File } from 'canvy'
const scene = new EditorScene(document.body)
const Canvy = $.element(CanvyElement)
const canvy = {
current: null as null | CanvyElement,
}
$.render(
<Canvy
ref={canvy}
scene={scene}
files={[
new File({
value: `\\ hello
\\ world
f()=sin(330);
`,
}),
]}
/>,
document.body
)
queueMicrotask(() => {
canvy.current!.$.effect(({ worker }) => {
worker.postMessage({
call: 'onmarkers',
markers: [
{ index: 4, size: 4 },
{ index: 10, size: 3 },
],
})
})
})
# CanvyElement
src/editor.tsx#L130
# $
Context<CanvyElement & JsxContext<CanvyElement> & {
<T extends Class<T>>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- ElementWrapper<T>
<T extends Reactive<any>>(ctx) =>
- ReactiveWrapper<T>
}>
# _onentermarker
= ...
src/editor.tsx#L268 # ({ marker, markerIndex })
{
}
({ marker, markerIndex }) =>
- void
# _onleavemarker
= ...
src/editor.tsx#L277 # ({ marker, markerIndex })
{
}
({ marker, markerIndex }) =>
- void
# context
ContextClass<CanvyElement & JsxContext<CanvyElement> & {
<T extends Class<T>>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- ElementWrapper<T>
<T extends Reactive<any>>(ctx) =>
- ReactiveWrapper<T>
}>
# onedit
EventHandler<CanvyElement, CustomEvent<any>>
# onentermarker
EventHandler<CanvyElement, CustomEvent<{
}>>
# onevent
EventHandler<CanvyElement, CustomEvent<{
}>>
# onleavemarker
EventHandler<CanvyElement, CustomEvent<{
}>>
# onmounted
EventHandler<CanvyElement, CustomEvent<any>>
# onunmounted
EventHandler<CanvyElement, CustomEvent<any>>
# replaceChunk
= ...
src/editor.tsx#L285 # created
(ctx)
# ctx
Context<CanvyElement & JsxContext<CanvyElement> & {
<T extends Class<T>>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- ElementWrapper<T>
<T extends Reactive<any>>(ctx) =>
- ReactiveWrapper<T>
}>
created(ctx) =>
- void
# handleEvent
(eventName, data)
src/editor.tsx#L738 # mounted
($)
src/editor.tsx#L309
# $
Context<CanvyElement & JsxContext<CanvyElement> & {
<T extends Class<T>>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- ElementWrapper<T>
<T extends Reactive<any>>(ctx) =>
- ReactiveWrapper<T>
}>
mounted($) =>
- void
# on
(name)
on<K>(name) =>
- On<Fn<[ EventHandler<CanvyElement, LifecycleEvents & CanvyEvents [K]> ], Off>>
# EditorScene
src/editor-scene.ts#L6
# $
Context<EditorScene & {
<T extends Class<T>>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- ElementWrapper<T>
<T extends Reactive<any>>(ctx) =>
- ReactiveWrapper<T>
}>
# context
ContextClass<EditorScene & {
<T extends Class<T>>(ctor) =>
- CleanClass<T>
<T>(ctx) =>
- ElementWrapper<T>
<T extends Reactive<any>>(ctx) =>
- ReactiveWrapper<T>
}>
# created
($)
src/editor-scene.ts#L32 # File
src/editor.tsx#L33
# CanvyEvents
src/editor.tsx#L123
# Canvy
(props)
src/editor.tsx#L757
# props
ComponentProps<CanvyElement, HTMLElement>
Canvy(props) =>
- VKid
- everyday-utils by stagas – Everyday utilities
- geometrik by stagas – Geometry classes and utils.
- get-element-offset by stagas – Get accurate DOM element offset.
- immutable-map-set by stagas – Immutable Map and Set objects
- minimal-view by stagas – Minimal reactive component view library.
- rpc-mini by stagas – A mini RPC for MessagePort interfaces.
- sigl by stagas – Web framework
- zerolag by stagas – a highly efficient text buffer for editors with very large buffers
All contributions are welcome!