import {Element, booleanAttribute, element, stringAttribute, type ElementAttributes} from '@lume/element' import html from 'solid-js/html' import {onCleanup} from 'solid-js' import {signal, Effectful} from 'classy-solid' import {EditorView} from '@codemirror/view' import {javascript as jsLang} from '@codemirror/lang-javascript' import {html as htmlLang} from '@codemirror/lang-html' import {LanguageSupport} from '@codemirror/language' import {type Extension, Compartment} from '@codemirror/state' import {noctisLilac as theme} from '@uiw/codemirror-theme-noctis-lilac' import {stripIndent} from './stripIndent.js' import {CodeMirrorContentchangedEvent} from './CodeMirrorContentchangedEvent.js' export type CodeMirrorAttributes = | 'basicSetup' | 'content' | 'stripIndent' | 'trim' | 'language' | 'stylesheet' | 'theme' | 'extensions' export @element('code-mirror') class CodeMirror extends Effectful(Element) { /** When true (when the attribute exists), CM's basicSetup will be applied. */ @booleanAttribute basicSetup = false /** A string to set the content of the editor to. */ @stringAttribute content = '' /** * When true (default) common indentation will be removed. Useful for * example if the `content` property is being set with a template string and * the content is indented to make the outer code more readable but the * indentation is undersired in the result. Set the attribute * `strip-indent="false"` to disable. */ @booleanAttribute stripIndent = true /** * When true (default) trims leading and trailing whitespace from `content`. */ @booleanAttribute trim = true /** * The language to use. It should be a LanguageSupport object, an empty * extension (for plain text mode), or the strings "html", "js", or "text" * which are shortcuts for `html()`, `javascript()`, and `[]`, respectively. * Defaults to "js". */ @stringAttribute language: 'html' | 'js' | 'text' | LanguageSupport = 'text' /** * CSS styles to apply in 's ShadowRoot. Useful for overriding * CM styles. Defaults to a style that hard codes the activeLine style to * overcome issues with selections not being visible on the active line * (https://github.com/vadimdemedes/thememirror/issues/8). * * The value can be * * - a string containing CSS code * - a `