Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/code-edit

Lightweight code editor Web Component with syntax highlighting
https://github.com/stagas/code-edit

code custom-element editor html syntax-highlight web-component

Last synced: 5 days ago
JSON representation

Lightweight code editor Web Component with syntax highlighting

Awesome Lists containing this project

README

        


code-edit

Lightweight code editor Web Component with syntax highlighting



npm i code-edit

pnpm add code-edit

yarn add code-edit

## Examples

# web

    # view source example/web.ts

    ```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*/ `
    export interface HTMLCodeEditElement {
    value?: string
    language?: string
    syntax?: SyntaxDefinition | Promise<{ default: SyntaxDefinition }>
    theme?: string
    tabsize?: number
    tabstyle?: 'tabs' | 'spaces'
    comments?: string
    }
    `
    ```


## API

# CodeEditElement src/code-edit.tsx#L172

} & __module & {

# Boolean


    undefined | boolean

# Number

    undefined | number

# String

    undefined | string

}, "transition">> # CodeSyntax  =  ... src/code-edit.tsx#L211

    Component<CodeSyntaxElement, HTMLElement>

# SuperImpose  =  ... src/code-edit.tsx#L212

    Component<SuperImposeElement, HTMLElement>

# TextAreaCode  =  ... src/code-edit.tsx#L213

    Component<TextAreaCodeElement, HTMLElement>

# TextShadow src/code-edit.tsx#L215 # autoFocus  =  false src/code-edit.tsx#L193

    boolean

# autoResize  =  false src/code-edit.tsx#L195

    boolean

# caretBlink  =  'none' src/code-edit.tsx#L263

    "blink" | "none"

# caretBlinkTimeout  =  -1 src/code-edit.tsx#L264

    any

# caretIndex  =  0 src/code-edit.tsx#L261

    number

# caretShift  =  'none' src/code-edit.tsx#L262

    "forward" | "backward" | "none"

# comments  =  '// /* */' src/code-edit.tsx#L205

    string

# context

    ContextClass<CodeEditElement & JsxContext<CodeEditElement> & Omit<{


    # ctor


      Class<T>


    <T>(ctor)  =>



      CleanClass<T>
    # ctx

      T | Class<T>

    <T>(ctx)  =>



      Wrapper<T>
    } & __module & {

    # Boolean


      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }, "transition">>
# dispatch

    Dispatch<# (name, detail, init)

      # name


        Event | Narrow<K, string>

      # detail # init

        CustomEventInit<any>


      <K, E>(name, detail, init)  =>


        any

> # fontSize  =  9.5 src/code-edit.tsx#L191

    number

# hasFocus  =  false src/code-edit.tsx#L209

    boolean

# height src/code-edit.tsx#L222

    HTMLPreElement

# host # hoveringMarker src/code-edit.tsx#L227 # language  =  '' src/code-edit.tsx#L197

    string

# layout src/code-edit.tsx#L221

    SuperImposeElement

# lenses  =  [] src/code-edit.tsx#L230 # markers  =  [] src/code-edit.tsx#L225 # markersCss  =  ... src/code-edit.tsx#L226

    # (selector)

      # selector


        string


      (selector)  =>


        string

# onInput  =  ... src/code-edit.tsx#L241

    # ()


      ()  =>


        void

# onScroll  =  ... src/code-edit.tsx#L247

    # ()


      ()  =>


        void

# onWheel  =  ... src/code-edit.tsx#L251

    EventHandler<SuperImposeElement, WheelEvent>

# onmounted # onunmounted # root  =  ... src/code-edit.tsx#L232

    ShadowRoot

# syntax  =  {} src/code-edit.tsx#L218 # tabSize  =  2 src/code-edit.tsx#L201

    number

# tabStyle  =  'spaces' src/code-edit.tsx#L203

    "spaces" | "tabs"

# textShadow  =  false src/code-edit.tsx#L207

    boolean

# textarea src/code-edit.tsx#L220

    TextAreaCodeElement

# theme  =  '' src/code-edit.tsx#L199

    string

# updateCaret  =  ... src/code-edit.tsx#L266

    # ()


      ()  =>


        void

# value  =  '' src/code-edit.tsx#L189

    string

# scrollLeft src/code-edit.tsx#L234
# scrollTop src/code-edit.tsx#L237
# created(ctx)

    # ctx

    # ctx

      T | Class<T>

    <T>(ctx)  =>



      Wrapper<T>
    } & __module & {

    # Boolean


      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }, "transition">>

created(ctx)  =>

    void
# mounted($) src/code-edit.tsx#L283

    # $

    # ctx

      T | Class<T>

    <T>(ctx)  =>



      Wrapper<T>
    } & __module & {

    # Boolean


      undefined | boolean

    # Number

      undefined | number

    # String

      undefined | string

    }, "transition">>

mounted($)  =>

    void
# on(name)

    # name


    on<K>(name)  =>


# toJSON() # Lens src/code-edit.tsx#L37 # Marker src/code-edit.tsx#L23 # onenter src/code-edit.tsx#L32

    # (el)

      # el


        HTMLSpanElement


      (el)  =>


        void

# onleave src/code-edit.tsx#L33

    # (el)

      # el


        HTMLSpanElement


      (el)  =>


        void

# onwheel src/code-edit.tsx#L34

    $.EventHandler<any, WheelEvent>

# rect src/code-edit.tsx#L30

    DOMRect

# size src/code-edit.tsx#L26

    number

# source src/code-edit.tsx#L27

    string

} # SyntaxOrImport

    SyntaxDefinition | Promise<{


    # default


      SyntaxDefinition

    }>
# languages

## Credits

- [code-syntax](https://npmjs.org/package/code-syntax) by [stagas](https://github.com/stagas) – Code syntax highlight Web Component
- [get-element-offset](https://npmjs.org/package/get-element-offset) by [stagas](https://github.com/stagas) – Get accurate DOM element offset.
- [relative-mouse](https://npmjs.org/package/relative-mouse) by [stagas](https://github.com/stagas) – Get mouse position relative to a DOM element.
- [sigl](https://npmjs.org/package/sigl) by [stagas](https://github.com/stagas) – Web framework
- [super-impose](https://npmjs.org/package/super-impose) by [stagas](https://github.com/stagas) – Web Component that super imposes one child over another to the same scroll position
- [textarea-code](https://npmjs.org/package/textarea-code) by [stagas](https://github.com/stagas) – Web Component that extends a textarea element with code editor behavior.

## Contributing

[Fork](https://github.com/stagas/code-edit/fork) or [edit](https://github.dev/stagas/code-edit) and submit a PR.

All contributions are welcome!

## License

MIT © 2022 [stagas](https://github.com/stagas)