JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 183
  • Score
    100M100P100Q73803F
  • License MIT

CodeMirror v6 as React Component, with hooks and stuff - but only the necessities.

Package Exports

  • @ui-schema/kit-codemirror
  • @ui-schema/kit-codemirror/CodeMirror
  • @ui-schema/kit-codemirror/createEditorView
  • @ui-schema/kit-codemirror/isRemoteChange
  • @ui-schema/kit-codemirror/package.json
  • @ui-schema/kit-codemirror/useCodeMirror
  • @ui-schema/kit-codemirror/useExtension

Readme

UI-Schema: Kit Code

Thin-wrapper for CodeMirror v6 to use as React Component, with hooks and stuff to build more advanced editors easily.

import { useState, useCallback } from 'react'
import { CodeMirror } from '@ui-schema/kit-codemirror/CodeMirror'
import { isRemoteChange } from '@ui-schema/kit-codemirror/isRemoteChange'
import type { CodeMirrorOnChange } from '@ui-schema/kit-codemirror/useCodeMirror'
import type { CodeMirrorComponentProps, CodeMirrorProps } from '@ui-schema/kit-codemirror/CodeMirror'

const DemoComponent = () => {
    const [value, setValue] = useState('')

    const onChange: CodeMirrorOnChange = useCallback((update, newValue) => {
        if(!update.docChanged || typeof newValue !== 'string' || isRemoteChange(update)) {
            return
        }
        setValue(newValue)
    }, [setValue])

    return <CodeMirror
        value={value}
        onChange={onChange}
    />
}

License

Released under the MIT License.