{"version":3,"file":"code-editor.cjs","sources":["../../app/code-editor.tsx"],"sourcesContent":["import { EditorView, ViewUpdate } from \"@codemirror/view\"\nimport { Extension } from \"@codemirror/state\"\nimport { forwardRef, useImperativeHandle } from \"react\"\nimport { tcx } from \"@choiceform/design-system\"\nimport { useCodeEditor } from \"./hooks\"\n\nimport \"./styles/style.scss\"\n\nexport interface CursorPosition {\n  column: number\n  line: number\n}\n\nexport interface CodeEditorProps {\n  autoFocus?: boolean\n  className?: string\n  customExtensions?: Extension[]\n  lineWrapping?: boolean\n  onChange?(value: string, viewUpdate: ViewUpdate): void\n  onCursorChange?(position: CursorPosition): void\n  onEditorUpdate?: (update: ViewUpdate) => void\n  onFormat?: (formattedCode: string) => void\n  onSelectionChange?(characterCount: number): void\n  placeholder?: string | HTMLElement\n  readonly?: boolean\n  value?: string\n}\n\nexport interface CodeEditorRef {\n  getCursorPosition: () => CursorPosition | null\n  getEditor: () => EditorView | null\n  getSelectedCharacterCount: () => number\n}\n\nexport const CodeEditor = forwardRef<CodeEditorRef, CodeEditorProps>((props, ref) => {\n  const { \n    value, \n    onChange, \n    autoFocus, \n    className, \n    readonly, \n    lineWrapping,\n    onEditorUpdate, \n    onFormat, \n    onCursorChange,\n    onSelectionChange,\n  } = props\n\n  const { containerRef, editorViewRef, getCursorPosition, getSelectedCharacterCount } = useCodeEditor({\n    value,\n    onChange,\n    autoFocus,\n    readonly,\n    lineWrapping,\n    onEditorUpdate,\n    onFormat,\n    onCursorChange,\n    onSelectionChange,\n  })\n\n  useImperativeHandle(ref, () => ({\n    getCursorPosition,\n    getEditor: () => editorViewRef.current,\n    getSelectedCharacterCount,\n  }), [getCursorPosition, editorViewRef, getSelectedCharacterCount])\n\n  return (\n    <div\n      ref={containerRef}\n      className={tcx(\"relative h-full\", className)}\n    />\n  )\n})\n\nCodeEditor.displayName = \"CodeEditor\"\n"],"names":["forwardRef","useCodeEditor","useImperativeHandle","jsx","tcx"],"mappings":";;;;;;;AAkCO,MAAM,aAAaA,MAAAA,WAA2C,CAAC,OAAO,QAAQ;AACnF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,EAAE,cAAc,eAAe,mBAAmB,0BAAA,IAA8BC,cAAAA,cAAc;AAAA,IAClG;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAEDC,QAAAA,oBAAoB,KAAK,OAAO;AAAA,IAC9B;AAAA,IACA,WAAW,MAAM,cAAc;AAAA,IAC/B;AAAA,EAAA,IACE,CAAC,mBAAmB,eAAe,yBAAyB,CAAC;AAEjE,SACEC,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAWC,aAAAA,IAAI,mBAAmB,SAAS;AAAA,IAAA;AAAA,EAAA;AAGjD,CAAC;AAED,WAAW,cAAc;;"}