node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

593
server/node_modules/@uiw/react-codemirror/README.md generated vendored Normal file
View File

@@ -0,0 +1,593 @@
<p align="center">
<a href="https://uiwjs.github.io/react-codemirror/">
<img alt="react-codemirror logo" src="https://user-images.githubusercontent.com/1680273/177491470-c31a6d7e-f676-4914-a027-2fbeebfeb5b4.svg">
</a>
</p>
# react-codemirror
[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)
[![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-codemirror.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-codemirror)
[![Build & Deploy](https://github.com/uiwjs/react-codemirror/actions/workflows/ci.yml/badge.svg)](https://github.com/uiwjs/react-codemirror/actions)
[![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-codemirror/file/README.md)
[![npm version](https://img.shields.io/npm/v/@uiw/react-codemirror.svg)](https://www.npmjs.com/package/@uiw/react-codemirror)
[![Coverage Status](https://uiwjs.github.io/react-codemirror/coverage/badges.svg)](https://uiwjs.github.io/react-codemirror/coverage/lcov-report/)
[![Open in Gitpod](https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod)](https://gitpod.io/#https://github.com/uiwjs/react-codemirror)
CodeMirror component for React. Demo Preview: [@uiwjs.github.io/react-codemirror](https://uiwjs.github.io/react-codemirror/)
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
**Features:**
🚀 Quickly and easily configure the API.
🌱 Versions after `@uiw/react-codemirror@v4`<!--rehype:style=background-color: #ffe564; padding: 1px 4px;--> use [codemirror 6](https://codemirror.net/). [#88](https://github.com/uiwjs/react-codemirror/issues/88#issuecomment-914185563).
⚛️ Support the features of React Hook(requires React 16.8+).
📚 Use Typescript to write, better code hints.
🌐 The bundled version supports use directly in the browser [#267](https://github.com/uiwjs/react-codemirror/issues/267#issuecomment-1041227592).
🌎 There are better [sample previews](https://uiwjs.github.io/react-codemirror).
🎨 Support [theme](https://uiwjs.github.io/react-codemirror/#/theme/data/dracula) customization, provide theme [editor](https://uiwjs.github.io/react-codemirror/#/editor/theme).
## Install
**Not dependent on uiw.**
```bash
npm install @uiw/react-codemirror --save
```
**All Packages**
| Name | NPM Version |
| :-------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`@uiw/react-codemirror`](https://uiwjs.github.io/react-codemirror) | [![npm version](https://img.shields.io/npm/v/@uiw/react-codemirror.svg)](https://www.npmjs.com/package/@uiw/react-codemirror) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-codemirror.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-codemirror) |
| [`react-codemirror-merge`](https://uiwjs.github.io/react-codemirror/#/merge/document) | [![npm version](https://img.shields.io/npm/v/react-codemirror-merge.svg)](https://www.npmjs.com/package/react-codemirror-merge) [![NPM Downloads](https://img.shields.io/npm/dm/react-codemirror-merge.svg?style=flat)](https://www.npmjs.com/package/react-codemirror-merge) |
| [`@uiw/codemirror-extensions-basic-setup`](https://uiwjs.github.io/react-codemirror/#/extensions/basic-setup) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-basic-setup.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-basic-setup) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-basic-setup.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-basic-setup) |
| [`@uiw/codemirror-extensions-color`](https://uiwjs.github.io/react-codemirror/#/extensions/color) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-color.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-color) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-color.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-color) |
| [`@uiw/codemirror-extensions-classname`](https://uiwjs.github.io/react-codemirror/#/extensions/classname) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-classname.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-classname) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-classname.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-classname) |
| [`@uiw/codemirror-extensions-events`](https://uiwjs.github.io/react-codemirror/#/extensions/events) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-events.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-events) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-events.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-events) |
| [`@uiw/codemirror-extensions-hyper-link`](https://uiwjs.github.io/react-codemirror/#/extensions/hyper-link) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-hyper-link.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-hyper-link) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-hyper-link.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-hyper-link) |
| [`@uiw/codemirror-extensions-langs`](https://uiwjs.github.io/react-codemirror/#/extensions/languages) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-langs.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-langs) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-langs.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-langs) |
| [`@uiw/codemirror-extensions-line-numbers-relative`](https://uiwjs.github.io/react-codemirror/#/extensions/line-numbers-relative) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-line-numbers-relative.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-line-numbers-relative) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-line-numbers-relative.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-line-numbers-relative) |
| [`@uiw/codemirror-extensions-mentions`](https://uiwjs.github.io/react-codemirror/#/extensions/mentions) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-mentions.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-mentions) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-mentions.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-mentions) |
| [`@uiw/codemirror-extensions-zebra-stripes`](https://uiwjs.github.io/react-codemirror/#/extensions/zebra-stripes) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-extensions-zebra-stripes.svg)](https://www.npmjs.com/package/@uiw/codemirror-extensions-zebra-stripes) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-extensions-zebra-stripes.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-extensions-zebra-stripes) |
| [`@uiw/codemirror-themes`](https://uiwjs.github.io/react-codemirror/#/theme/doc) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-themes.svg)](https://www.npmjs.com/package/@uiw/codemirror-themes) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-themes.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-themes) |
| Name | NPM Version |
| :----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`@uiw/codemirror-themes-all`](https://uiwjs.github.io/react-codemirror/#/theme/all) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-themes-all.svg)](https://www.npmjs.com/package/@uiw/codemirror-themes-all) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-themes-all.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-themes-all) |
| [`@uiw/codemirror-theme-abcdef`](https://uiwjs.github.io/react-codemirror/#/theme/data/abcdef) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-abcdef.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-abcdef) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-abcdef.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-abcdef) |
| [`@uiw/codemirror-theme-abyss`](https://uiwjs.github.io/react-codemirror/#/theme/data/abyss) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-abyss.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-abyss) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-abyss.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-abyss) |
| [`@uiw/codemirror-theme-androidstudio`](https://uiwjs.github.io/react-codemirror/#/theme/data/androidstudio) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-androidstudio.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-androidstudio) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-androidstudio.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-androidstudio) |
| [`@uiw/codemirror-theme-andromeda`](https://uiwjs.github.io/react-codemirror/#/theme/data/andromeda) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-andromeda.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-andromeda) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-andromeda.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-andromeda) |
| [`@uiw/codemirror-theme-atomone`](https://uiwjs.github.io/react-codemirror/#/theme/data/atomone) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-atomone.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-atomone) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-atomone.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-atomone) |
| [`@uiw/codemirror-theme-aura`](https://uiwjs.github.io/react-codemirror/#/theme/data/aura) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-aura.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-aura) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-aura.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-aura) |
| [`@uiw/codemirror-theme-basic`](https://uiwjs.github.io/react-codemirror/#/theme/data/bbedit) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-basic.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-basic) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-basic.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-basic) |
| [`@uiw/codemirror-theme-bbedit`](https://uiwjs.github.io/react-codemirror/#/theme/data/bbedit) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-bbedit.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-bbedit) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-bbedit.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-bbedit) |
| [`@uiw/codemirror-theme-bespin`](https://uiwjs.github.io/react-codemirror/#/theme/data/bespin) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-bespin.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-bespin) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-bespin.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-bespin) |
| [`@uiw/codemirror-theme-console`](https://uiwjs.github.io/react-codemirror/#/theme/data/console) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-console.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-console) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-console.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-console) |
| [`@uiw/codemirror-theme-copilot`](https://uiwjs.github.io/react-codemirror/#/theme/data/copilot) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-copilot.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-copilot) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-copilot.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-copilot) |
| [`@uiw/codemirror-theme-duotone`](https://uiwjs.github.io/react-codemirror/#/theme/data/duotone/light) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-duotone.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-duotone) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-duotone.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-duotone) |
| [`@uiw/codemirror-theme-dracula`](https://uiwjs.github.io/react-codemirror/#/theme/data/dracula) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-dracula.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-dracula) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-dracula.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-dracula) |
| [`@uiw/codemirror-theme-darcula`](https://uiwjs.github.io/react-codemirror/#/theme/data/darcula) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-darcula.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-darcula) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-darcula.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-darcula) |
| [`@uiw/codemirror-theme-eclipse`](https://uiwjs.github.io/react-codemirror/#/theme/data/eclipse) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-eclipse.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-eclipse) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-eclipse.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-eclipse) |
| [`@uiw/codemirror-theme-github`](https://uiwjs.github.io/react-codemirror/#/theme/data/github) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-github.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-github) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-github.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-github) |
| [`@uiw/codemirror-theme-gruvbox-dark`](https://uiwjs.github.io/react-codemirror/#/theme/data/gruvbox/dark) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-gruvbox-dark.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-gruvbox-dark) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-gruvbox-dark.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-gruvbox-dark) |
| [`@uiw/codemirror-theme-kimbie`](https://uiwjs.github.io/react-codemirror/#/theme/data/kimbie/dark) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-kimbie.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-kimbie) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-kimbie.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-kimbie) |
| [`@uiw/codemirror-theme-kimbie`](https://uiwjs.github.io/react-codemirror/#/theme/data/kimbie/dark) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-kimbie.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-kimbie) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-kimbie.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-kimbie) |
| [`@uiw/codemirror-theme-material`](https://uiwjs.github.io/react-codemirror/#/theme/data/material/dark) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-material.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-material) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-material.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-material) |
| [`@uiw/codemirror-theme-monokai`](https://uiwjs.github.io/react-codemirror/#/theme/data/monokai) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-monokai.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-monokai) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-monokai.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-monokai) |
| [`@uiw/codemirror-theme-noctis-lilac`](https://uiwjs.github.io/react-codemirror/#/theme/data/noctis-lilac) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-noctis-lilac.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-noctis-lilac) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-noctis-lilac.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-noctis-lilac) |
| [`@uiw/codemirror-theme-nord`](https://uiwjs.github.io/react-codemirror/#/theme/data/nord) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-nord.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-nord) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-nord.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-nord) |
| [`@uiw/codemirror-theme-okaidia`](https://uiwjs.github.io/react-codemirror/#/theme/data/okaidia) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-okaidia.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-okaidia) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-okaidia.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-okaidia) |
| [`@uiw/codemirror-theme-quietlight`](https://uiwjs.github.io/react-codemirror/#/theme/data/quietlight) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-quietlight.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-quietlight) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-quietlight.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-quietlight) |
| [`@uiw/codemirror-theme-red`](https://uiwjs.github.io/react-codemirror/#/theme/data/red) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-red.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-red) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-red.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-red) |
| [`@uiw/codemirror-theme-solarized`](https://uiwjs.github.io/react-codemirror/#/theme/data/solarized/dark) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-solarized.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-solarized) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-solarized.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-solarized) |
| [`@uiw/codemirror-theme-sublime`](https://uiwjs.github.io/react-codemirror/#/theme/data/sublime) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-sublime.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-sublime) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-sublime.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-sublime) |
| [`@uiw/codemirror-theme-tokyo-night`](https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tokyo-night.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night) |
| [`@uiw/codemirror-theme-tokyo-night-storm`](https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-storm) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night-storm.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-storm) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tokyo-night-storm.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-storm) |
| [`@uiw/codemirror-theme-tokyo-night-day`](https://uiwjs.github.io/react-codemirror/#/theme/data/tokyo-night-day) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tokyo-night-day.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-day) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tokyo-night-day.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tokyo-night-day) |
| [`@uiw/codemirror-theme-vscode`](https://uiwjs.github.io/react-codemirror/#/theme/data/vscode) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-vscode.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-vscode) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-vscode.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-vscode) |
| [`@uiw/codemirror-theme-white`](https://uiwjs.github.io/react-codemirror/#/theme/data/white/light) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-white.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-white) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-white.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-white) |
| [`@uiw/codemirror-theme-tomorrow-night-blue`](https://uiwjs.github.io/react-codemirror/#/theme/data/tomorrow-night-blue) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-tomorrow-night-blue.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-tomorrow-night-blue) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-tomorrow-night-blue.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-tomorrow-night-blue) |
| [`@uiw/codemirror-theme-xcode`](https://uiwjs.github.io/react-codemirror/#/theme/data/xcode) | [![npm version](https://img.shields.io/npm/v/@uiw/codemirror-theme-xcode.svg)](https://www.npmjs.com/package/@uiw/codemirror-theme-xcode) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/codemirror-theme-xcode.svg?style=flat)](https://www.npmjs.com/package/@uiw/codemirror-theme-xcode) |
<!--rehype:style=width: 100%; display: inline-table;-->
## Usage
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-slvju?fontsize=14&hidenavigation=1&theme=dark)
```jsx mdx:preview
import React from 'react';
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
function App() {
const [value, setValue] = React.useState("console.log('hello world!');");
const onChange = React.useCallback((val, viewUpdate) => {
console.log('val:', val);
setValue(val);
}, []);
return <CodeMirror value={value} height="200px" extensions={[javascript({ jsx: true })]} onChange={onChange} />;
}
export default App;
```
## Support Language
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-language-rz4rh?fontsize=14&hidenavigation=1&theme=dark)
```jsx
import CodeMirror from '@uiw/react-codemirror';
import { StreamLanguage } from '@codemirror/language';
import { go } from '@codemirror/legacy-modes/mode/go';
const goLang = `package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}`;
export default function App() {
return <CodeMirror value={goLang} height="200px" extensions={[StreamLanguage.define(go)]} />;
}
```
- ~~`@codemirror/legacy-modes/mode/cpp`~~ => [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
- ~~`@codemirror/legacy-modes/mode/html`~~ => [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
- ~~`@codemirror/legacy-modes/mode/java`~~ => [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
- ~~`@codemirror/legacy-modes/mode/javascript`~~ => [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
- ~~`@codemirror/legacy-modes/mode/json`~~ => [`@codemirror/lang-json`](https://www.npmjs.com/package/@codemirror/lang-json)
- ~~`@codemirror/legacy-modes/mode/lezer`~~ => [`@codemirror/lang-lezer`](https://www.npmjs.com/package/@codemirror/lang-lezer)
- ~~`@codemirror/legacy-modes/mode/markdown`~~ => [`@codemirror/lang-markdown`](https://www.npmjs.com/package/@codemirror/lang-markdown)
- ~~`@codemirror/legacy-modes/mode/php`~~ => [`@codemirror/lang-php`](https://www.npmjs.com/package/@codemirror/lang-php)
- ~~`@codemirror/legacy-modes/mode/python`~~ => [`@codemirror/lang-python`](https://www.npmjs.com/package/@codemirror/lang-python)
- ~~`@codemirror/legacy-modes/mode/rust`~~ => [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
- ~~`@codemirror/legacy-modes/mode/sql`~~ => [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
- ~~`@codemirror/legacy-modes/mode/xml`~~ => [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
- ~~`@codemirror/legacy-modes/mode/css`~~ => [`@codemirror/lang-less`](https://www.npmjs.com/package/@codemirror/lang-less)
- ~~`@codemirror/legacy-modes/mode/sass`~~ => [`@codemirror/lang-sass`](https://www.npmjs.com/package/@codemirror/lang-sass)
- ~~`@codemirror/legacy-modes/mode/clojure`~~ => [`@nextjournal/lang-clojure`](https://www.npmjs.com/package/@nextjournal/lang-clojure)
- ~~`@codemirror/legacy-modes/mode/clike`~~ => [`@replit/codemirror-lang-csharp`](https://www.npmjs.com/package/@replit/codemirror-lang-csharp)
### Markdown Example
Markdown language code is automatically highlighted.
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-markdown-auto-languages-iudnj?fontsize=14&hidenavigation=1&theme=dark)
```jsx
import CodeMirror from '@uiw/react-codemirror';
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
import { languages } from '@codemirror/language-data';
const code = `## Title
\`\`\`jsx
function Demo() {
return <div>demo</div>
}
\`\`\`
\`\`\`bash
# Not dependent on uiw.
npm install @codemirror/lang-markdown --save
npm install @codemirror/language-data --save
\`\`\`
[weisit ulr](https://uiwjs.github.io/react-codemirror/)
\`\`\`go
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
\`\`\`
`;
export default function App() {
return <CodeMirror value={code} extensions={[markdown({ base: markdownLanguage, codeLanguages: languages })]} />;
}
```
## Codemirror Merge
A component that highlights the changes between two versions of a file in a side-by-side view, highlighting added, modified, or deleted lines of code.
```bash
npm install react-codemirror-merge --save
```
```jsx
import CodeMirrorMerge from 'react-codemirror-merge';
import { EditorView } from 'codemirror';
import { EditorState } from '@codemirror/state';
const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
let doc = `one
two
three
four
five`;
export const Example = () => {
return (
<CodeMirrorMerge>
<Original value={doc} />
<Modified
value={doc.replace(/t/g, 'T') + 'Six'}
extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
/>
</CodeMirrorMerge>
);
};
```
## Support Hook
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-hook-yr4vg?fontsize=14&hidenavigation=1&theme=dark)
```jsx
import { useEffect, useMemo, useRef } from 'react';
import { useCodeMirror } from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
const code = "console.log('hello world!');\n\n\n";
// Define the extensions outside the component for the best performance.
// If you need dynamic extensions, use React.useMemo to minimize reference changes
// which cause costly re-renders.
const extensions = [javascript()];
export default function App() {
const editor = useRef();
const { setContainer } = useCodeMirror({
container: editor.current,
extensions,
value: code,
});
useEffect(() => {
if (editor.current) {
setContainer(editor.current);
}
}, [editor.current]);
return <div ref={editor} />;
}
```
## Using Theme
We have created a [`theme editor`](https://uiwjs.github.io/react-codemirror/#/editor/theme) where you can define your own theme. We have also defined [some themes](https://uiwjs.github.io/react-codemirror/#/theme/data/okaidia) ourselves, which can be installed and used directly. Below is a usage example:
```jsx
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { okaidia } from '@uiw/codemirror-theme-okaidia';
const extensions = [javascript({ jsx: true })];
export default function App() {
return (
<CodeMirror
value="console.log('hello world!');"
height="200px"
theme={okaidia}
extensions={[javascript({ jsx: true })]}
/>
);
}
```
## Using custom theme
```jsx
import CodeMirror from '@uiw/react-codemirror';
import { createTheme } from '@uiw/codemirror-themes';
import { javascript } from '@codemirror/lang-javascript';
import { tags as t } from '@lezer/highlight';
const myTheme = createTheme({
theme: 'light',
settings: {
background: '#ffffff',
backgroundImage: '',
foreground: '#75baff',
caret: '#5d00ff',
selection: '#036dd626',
selectionMatch: '#036dd626',
lineHighlight: '#8a91991a',
gutterBackground: '#fff',
gutterForeground: '#8a919966',
},
styles: [
{ tag: t.comment, color: '#787b8099' },
{ tag: t.variableName, color: '#0080ff' },
{ tag: [t.string, t.special(t.brace)], color: '#5c6166' },
{ tag: t.number, color: '#5c6166' },
{ tag: t.bool, color: '#5c6166' },
{ tag: t.null, color: '#5c6166' },
{ tag: t.keyword, color: '#5c6166' },
{ tag: t.operator, color: '#5c6166' },
{ tag: t.className, color: '#5c6166' },
{ tag: t.definition(t.typeName), color: '#5c6166' },
{ tag: t.typeName, color: '#5c6166' },
{ tag: t.angleBracket, color: '#5c6166' },
{ tag: t.tagName, color: '#5c6166' },
{ tag: t.attributeName, color: '#5c6166' },
],
});
const extensions = [javascript({ jsx: true })];
export default function App() {
const onChange = React.useCallback((value, viewUpdate) => {
console.log('value:', value);
}, []);
return (
<CodeMirror
value="console.log('hello world!');"
height="200px"
theme={myTheme}
extensions={extensions}
onChange={onChange}
/>
);
}
```
## Use `initialState` to restore state from JSON-serialized representation
CodeMirror allows to serialize editor state to JSON representation with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function for persistency or other needs. This JSON representation can be later used to recreate ReactCodeMirror component with the same internal state.
For example, this is how undo history can be saved in the local storage, so that it remains after the page reloads
```jsx
import CodeMirror from '@uiw/react-codemirror';
import { historyField } from '@codemirror/commands';
// When custom fields should be serialized, you can pass them in as an object mapping property names to fields.
// See [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) documentation for more details
const stateFields = { history: historyField };
export function EditorWithInitialState() {
const serializedState = localStorage.getItem('myEditorState');
const value = localStorage.getItem('myValue') || '';
return (
<CodeMirror
value={value}
initialState={
serializedState
? {
json: JSON.parse(serializedState || ''),
fields: stateFields,
}
: undefined
}
onChange={(value, viewUpdate) => {
localStorage.setItem('myValue', value);
const state = viewUpdate.state.toJSON(stateFields);
localStorage.setItem('myEditorState', JSON.stringify(state));
}}
/>
);
}
```
## Props
<!--rehype:style=background-color: #ffe564; display: inline-block; border-bottom: 0; padding: 3px 12px;-->
- `value?: string` value of the auto created model in the editor.
- `width?: string` width of editor. Defaults to `auto`.
- `height?: string` height of editor. Defaults to `auto`.
- `theme?`: `'light'` / `'dark'` / `Extension` Defaults to `'light'`.
```ts
import React from 'react';
import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
import { EditorView, ViewUpdate } from '@codemirror/view';
export * from '@codemirror/view';
export * from '@codemirror/basic-setup';
export * from '@codemirror/state';
export interface UseCodeMirror extends ReactCodeMirrorProps {
container?: HTMLDivElement | null;
}
export declare function useCodeMirror(props: UseCodeMirror): {
state: EditorState | undefined;
setState: import('react').Dispatch<import('react').SetStateAction<EditorState | undefined>>;
view: EditorView | undefined;
setView: import('react').Dispatch<import('react').SetStateAction<EditorView | undefined>>;
container: HTMLDivElement | null | undefined;
setContainer: import('react').Dispatch<import('react').SetStateAction<HTMLDivElement | null | undefined>>;
};
export interface ReactCodeMirrorProps
extends Omit<EditorStateConfig, 'doc' | 'extensions'>,
Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
/** value of the auto created model in the editor. */
value?: string;
height?: string;
minHeight?: string;
maxHeight?: string;
width?: string;
minWidth?: string;
maxWidth?: string;
/** focus on the editor. */
autoFocus?: boolean;
/** Enables a placeholder—a piece of example content to show when the editor is empty. */
placeholder?: string | HTMLElement;
/**
* `light` / `dark` / `Extension` Defaults to `light`.
* @default light
*/
theme?: 'light' | 'dark' | Extension;
/**
* Whether to optional basicSetup by default
* @default true
*/
basicSetup?: boolean | BasicSetupOptions;
/**
* This disables editing of the editor content by the user.
* @default true
*/
editable?: boolean;
/**
* This disables editing of the editor content by the user.
* @default false
*/
readOnly?: boolean;
/**
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
* or behaves according to the browser's default behavior (`false`).
* @default true
*/
indentWithTab?: boolean;
/** Fired whenever a change occurs to the document. */
onChange?(value: string, viewUpdate: ViewUpdate): void;
/** Some data on the statistics editor. */
onStatistics?(data: Statistics): void;
/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
onUpdate?(viewUpdate: ViewUpdate): void;
/**
* Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
* They can either be built-in extension-providing objects,
* such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
*/
extensions?: Extension[];
/**
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
*/
root?: ShadowRoot | Document;
/**
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
*/
initialState?: {
json: any;
fields?: Record<'string', StateField<any>>;
};
}
export interface ReactCodeMirrorRef {
editor?: HTMLDivElement | null;
state?: EditorState;
view?: EditorView;
}
declare const ReactCodeMirror: React.ForwardRefExoticComponent<
ReactCodeMirrorProps & React.RefAttributes<ReactCodeMirrorRef>
>;
export default ReactCodeMirror;
export interface BasicSetupOptions {
lineNumbers?: boolean;
highlightActiveLineGutter?: boolean;
highlightSpecialChars?: boolean;
history?: boolean;
foldGutter?: boolean;
drawSelection?: boolean;
dropCursor?: boolean;
allowMultipleSelections?: boolean;
indentOnInput?: boolean;
syntaxHighlighting?: boolean;
bracketMatching?: boolean;
closeBrackets?: boolean;
autocompletion?: boolean;
rectangularSelection?: boolean;
crosshairCursor?: boolean;
highlightActiveLine?: boolean;
highlightSelectionMatches?: boolean;
closeBracketsKeymap?: boolean;
defaultKeymap?: boolean;
searchKeymap?: boolean;
historyKeymap?: boolean;
foldKeymap?: boolean;
completionKeymap?: boolean;
lintKeymap?: boolean;
}
```
```ts
import { EditorSelection, SelectionRange } from '@codemirror/state';
import { ViewUpdate } from '@codemirror/view';
export interface Statistics {
/** Get the number of lines in the editor. */
lineCount: number;
/** total length of the document */
length: number;
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
lineBreak: string;
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
readOnly: boolean;
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
tabSize: number;
/** Cursor Position */
selection: EditorSelection;
/** Make sure the selection only has one range. */
selectionAsSingle: SelectionRange;
/** Retrieves a list of all current selections. */
ranges: readonly SelectionRange[];
/** Get the currently selected code. */
selectionCode: string;
/**
* The length of the given array should be the same as the number of active selections.
* Replaces the content of the selections with the strings in the array.
*/
selections: string[];
/** Return true if any text is selected. */
selectedText: boolean;
}
export declare const getStatistics: (view: ViewUpdate) => Statistics;
```
## Development
1. Install dependencies
```bash
$ npm install # Installation dependencies
$ npm run build # Compile all package
```
2. Development `@uiw/react-codemirror` package:
```bash
$ cd core
# listen to the component compile and output the .js file
# listen for compilation output type .d.ts file
$ npm run watch # Monitor the compiled package `@uiw/react-codemirror`
```
3. Launch documentation site
```bash
npm run start
```
## Related
- [@uiw/react-textarea-code-editor](https://github.com/uiwjs/react-textarea-code-editor): A simple code editor with syntax highlighting.
- [@uiw/react-md-editor](https://github.com/uiwjs/react-md-editor): A simple markdown editor with preview, implemented with React.js and TypeScript.
- [@uiw/react-monacoeditor](https://github.com/jaywcjlove/react-monacoeditor): Monaco Editor component for React.
- [@uiw/react-markdown-editor](https://github.com/uiwjs/react-markdown-editor): A markdown editor with preview, implemented with React.js and TypeScript.
- [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview): React component preview markdown text in web browser.
- [Online JSON Viewer](https://github.com/uiwjs/json-viewer) Online JSON Viewer, JSON Beautifier to beautify and tree view of JSON data - It works as JSON Pretty Print to pretty print JSON data.
## Contributors
As always, thanks to our amazing contributors!
<a href="https://github.com/uiwjs/react-codemirror/graphs/contributors">
<img src="https://uiwjs.github.io/react-codemirror/CONTRIBUTORS.svg" />
</a>
Made with [contributors](https://github.com/jaywcjlove/github-action-contributors).
## License
Licensed under the MIT License.

View File

@@ -0,0 +1,13 @@
import { type Extension } from '@codemirror/state';
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
export * from '@codemirror/theme-one-dark';
export * from './theme/light';
export interface DefaultExtensionsOptions {
indentWithTab?: boolean;
basicSetup?: boolean | BasicSetupOptions;
placeholder?: string | HTMLElement;
theme?: 'light' | 'dark' | 'none' | Extension;
readOnly?: boolean;
editable?: boolean;
}
export declare const getDefaultExtensions: (optios?: DefaultExtensionsOptions) => Extension[];

View File

@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
getDefaultExtensions: true
};
exports.getDefaultExtensions = void 0;
var _commands = require("@codemirror/commands");
var _codemirrorExtensionsBasicSetup = require("@uiw/codemirror-extensions-basic-setup");
var _view = require("@codemirror/view");
var _themeOneDark = require("@codemirror/theme-one-dark");
Object.keys(_themeOneDark).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _themeOneDark[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _themeOneDark[key];
}
});
});
var _state = require("@codemirror/state");
var _light = require("./theme/light");
Object.keys(_light).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _light[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _light[key];
}
});
});
var getDefaultExtensions = exports.getDefaultExtensions = function getDefaultExtensions() {
var optios = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _optios$indentWithTab = optios.indentWithTab,
defaultIndentWithTab = _optios$indentWithTab === void 0 ? true : _optios$indentWithTab,
_optios$editable = optios.editable,
editable = _optios$editable === void 0 ? true : _optios$editable,
_optios$readOnly = optios.readOnly,
readOnly = _optios$readOnly === void 0 ? false : _optios$readOnly,
_optios$theme = optios.theme,
theme = _optios$theme === void 0 ? 'light' : _optios$theme,
_optios$placeholder = optios.placeholder,
placeholderStr = _optios$placeholder === void 0 ? '' : _optios$placeholder,
_optios$basicSetup = optios.basicSetup,
defaultBasicSetup = _optios$basicSetup === void 0 ? true : _optios$basicSetup;
var getExtensions = [];
if (defaultIndentWithTab) {
getExtensions.unshift(_view.keymap.of([_commands.indentWithTab]));
}
if (defaultBasicSetup) {
if (typeof defaultBasicSetup === 'boolean') {
getExtensions.unshift((0, _codemirrorExtensionsBasicSetup.basicSetup)());
} else {
getExtensions.unshift((0, _codemirrorExtensionsBasicSetup.basicSetup)(defaultBasicSetup));
}
}
if (placeholderStr) {
getExtensions.unshift((0, _view.placeholder)(placeholderStr));
}
switch (theme) {
case 'light':
getExtensions.push(_light.defaultLightThemeOption);
break;
case 'dark':
getExtensions.push(_themeOneDark.oneDark);
break;
case 'none':
break;
default:
getExtensions.push(theme);
break;
}
if (editable === false) {
getExtensions.push(_view.EditorView.editable.of(false));
}
if (readOnly) {
getExtensions.push(_state.EditorState.readOnly.of(true));
}
return [].concat(getExtensions);
};

View File

@@ -0,0 +1,85 @@
import React from 'react';
import type { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';
import type { EditorView, ViewUpdate } from '@codemirror/view';
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
import { type Statistics } from './utils';
export * from '@codemirror/view';
export * from '@codemirror/state';
export * from '@uiw/codemirror-extensions-basic-setup';
export * from './useCodeMirror';
export * from './getDefaultExtensions';
export * from './utils';
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
/** value of the auto created model in the editor. */
value?: string;
height?: string;
minHeight?: string;
maxHeight?: string;
width?: string;
minWidth?: string;
maxWidth?: string;
/** focus on the editor. */
autoFocus?: boolean;
/** Enables a placeholder—a piece of example content to show when the editor is empty. */
placeholder?: string | HTMLElement;
/**
* `light` / `dark` / `Extension` Defaults to `light`.
* @default light
*/
theme?: 'light' | 'dark' | 'none' | Extension;
/**
* Whether to optional basicSetup by default
* @default true
*/
basicSetup?: boolean | BasicSetupOptions;
/**
* This disables editing of the editor content by the user.
* @default true
*/
editable?: boolean;
/**
* This disables editing of the editor content by the user.
* @default false
*/
readOnly?: boolean;
/**
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
* or behaves according to the browser's default behavior (`false`).
* @default true
*/
indentWithTab?: boolean;
/** Fired whenever a change occurs to the document. */
onChange?(value: string, viewUpdate: ViewUpdate): void;
/** Some data on the statistics editor. */
onStatistics?(data: Statistics): void;
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
onUpdate?(viewUpdate: ViewUpdate): void;
/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;
/**
* Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
* They can either be built-in extension-providing objects,
* such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
*/
extensions?: Extension[];
/**
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
*/
root?: ShadowRoot | Document;
/**
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
*/
initialState?: {
json: any;
fields?: Record<string, StateField<any>>;
};
}
export interface ReactCodeMirrorRef {
editor?: HTMLDivElement | null;
state?: EditorState;
view?: EditorView;
}
declare const ReactCodeMirror: React.ForwardRefExoticComponent<ReactCodeMirrorProps & React.RefAttributes<ReactCodeMirrorRef>>;
export default ReactCodeMirror;

164
server/node_modules/@uiw/react-codemirror/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,164 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {};
exports["default"] = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _useCodeMirror2 = require("./useCodeMirror");
Object.keys(_useCodeMirror2).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useCodeMirror2[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _useCodeMirror2[key];
}
});
});
var _jsxRuntime = require("react/jsx-runtime");
var _view = require("@codemirror/view");
Object.keys(_view).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _view[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _view[key];
}
});
});
var _state = require("@codemirror/state");
Object.keys(_state).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _state[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _state[key];
}
});
});
var _codemirrorExtensionsBasicSetup = require("@uiw/codemirror-extensions-basic-setup");
Object.keys(_codemirrorExtensionsBasicSetup).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _codemirrorExtensionsBasicSetup[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _codemirrorExtensionsBasicSetup[key];
}
});
});
var _getDefaultExtensions = require("./getDefaultExtensions");
Object.keys(_getDefaultExtensions).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _getDefaultExtensions[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _getDefaultExtensions[key];
}
});
});
var _utils = require("./utils");
Object.keys(_utils).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _utils[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _utils[key];
}
});
});
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onStatistics", "onCreateEditor", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root", "initialState"];
var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
var className = props.className,
_props$value = props.value,
value = _props$value === void 0 ? '' : _props$value,
selection = props.selection,
_props$extensions = props.extensions,
extensions = _props$extensions === void 0 ? [] : _props$extensions,
onChange = props.onChange,
onStatistics = props.onStatistics,
onCreateEditor = props.onCreateEditor,
onUpdate = props.onUpdate,
autoFocus = props.autoFocus,
_props$theme = props.theme,
theme = _props$theme === void 0 ? 'light' : _props$theme,
height = props.height,
minHeight = props.minHeight,
maxHeight = props.maxHeight,
width = props.width,
minWidth = props.minWidth,
maxWidth = props.maxWidth,
basicSetup = props.basicSetup,
placeholder = props.placeholder,
indentWithTab = props.indentWithTab,
editable = props.editable,
readOnly = props.readOnly,
root = props.root,
initialState = props.initialState,
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
var editor = (0, _react.useRef)(null);
var _useCodeMirror = (0, _useCodeMirror2.useCodeMirror)({
container: editor.current,
root: root,
value: value,
autoFocus: autoFocus,
theme: theme,
height: height,
minHeight: minHeight,
maxHeight: maxHeight,
width: width,
minWidth: minWidth,
maxWidth: maxWidth,
basicSetup: basicSetup,
placeholder: placeholder,
indentWithTab: indentWithTab,
editable: editable,
readOnly: readOnly,
selection: selection,
onChange: onChange,
onStatistics: onStatistics,
onCreateEditor: onCreateEditor,
onUpdate: onUpdate,
extensions: extensions,
initialState: initialState
}),
state = _useCodeMirror.state,
view = _useCodeMirror.view,
container = _useCodeMirror.container;
(0, _react.useImperativeHandle)(ref, function () {
return {
editor: editor.current,
state: state,
view: view
};
}, [editor, container, state, view]);
// check type of value
if (typeof value !== 'string') {
throw new Error("value must be typeof string but got ".concat((0, _typeof2["default"])(value)));
}
var defaultClassNames = typeof theme === 'string' ? "cm-theme-".concat(theme) : 'cm-theme';
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({
ref: editor,
className: "".concat(defaultClassNames).concat(className ? " ".concat(className) : '')
}, other));
});
ReactCodeMirror.displayName = 'CodeMirror';
var _default = exports["default"] = ReactCodeMirror;

View File

@@ -0,0 +1 @@
export declare const defaultLightThemeOption: import("@codemirror/state").Extension;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.defaultLightThemeOption = void 0;
var _view = require("@codemirror/view");
var defaultLightThemeOption = exports.defaultLightThemeOption = _view.EditorView.theme({
'&': {
backgroundColor: '#fff'
}
}, {
dark: false
});

View File

@@ -0,0 +1,14 @@
import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { type ReactCodeMirrorProps } from '.';
export interface UseCodeMirror extends ReactCodeMirrorProps {
container?: HTMLDivElement | null;
}
export declare function useCodeMirror(props: UseCodeMirror): {
state: EditorState | undefined;
setState: import("react").Dispatch<import("react").SetStateAction<EditorState | undefined>>;
view: EditorView | undefined;
setView: import("react").Dispatch<import("react").SetStateAction<EditorView | undefined>>;
container: HTMLDivElement | null | undefined;
setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null | undefined>>;
};

View File

@@ -0,0 +1,178 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useCodeMirror = useCodeMirror;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _state = require("@codemirror/state");
var _view = require("@codemirror/view");
var _getDefaultExtensions = require("./getDefaultExtensions");
var _utils = require("./utils");
var External = _state.Annotation.define();
var emptyExtensions = [];
function useCodeMirror(props) {
var value = props.value,
selection = props.selection,
onChange = props.onChange,
onStatistics = props.onStatistics,
onCreateEditor = props.onCreateEditor,
onUpdate = props.onUpdate,
_props$extensions = props.extensions,
extensions = _props$extensions === void 0 ? emptyExtensions : _props$extensions,
autoFocus = props.autoFocus,
_props$theme = props.theme,
theme = _props$theme === void 0 ? 'light' : _props$theme,
_props$height = props.height,
height = _props$height === void 0 ? null : _props$height,
_props$minHeight = props.minHeight,
minHeight = _props$minHeight === void 0 ? null : _props$minHeight,
_props$maxHeight = props.maxHeight,
maxHeight = _props$maxHeight === void 0 ? null : _props$maxHeight,
_props$width = props.width,
width = _props$width === void 0 ? null : _props$width,
_props$minWidth = props.minWidth,
minWidth = _props$minWidth === void 0 ? null : _props$minWidth,
_props$maxWidth = props.maxWidth,
maxWidth = _props$maxWidth === void 0 ? null : _props$maxWidth,
_props$placeholder = props.placeholder,
placeholderStr = _props$placeholder === void 0 ? '' : _props$placeholder,
_props$editable = props.editable,
editable = _props$editable === void 0 ? true : _props$editable,
_props$readOnly = props.readOnly,
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
_props$indentWithTab = props.indentWithTab,
defaultIndentWithTab = _props$indentWithTab === void 0 ? true : _props$indentWithTab,
_props$basicSetup = props.basicSetup,
defaultBasicSetup = _props$basicSetup === void 0 ? true : _props$basicSetup,
root = props.root,
initialState = props.initialState;
var _useState = (0, _react.useState)(),
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
container = _useState2[0],
setContainer = _useState2[1];
var _useState3 = (0, _react.useState)(),
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
view = _useState4[0],
setView = _useState4[1];
var _useState5 = (0, _react.useState)(),
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
state = _useState6[0],
setState = _useState6[1];
var defaultThemeOption = _view.EditorView.theme({
'&': {
height: height,
minHeight: minHeight,
maxHeight: maxHeight,
width: width,
minWidth: minWidth,
maxWidth: maxWidth
},
'& .cm-scroller': {
height: '100% !important'
}
});
var updateListener = _view.EditorView.updateListener.of(function (vu) {
if (vu.docChanged && typeof onChange === 'function' &&
// Fix echoing of the remote changes:
// If transaction is market as remote we don't have to call `onChange` handler again
!vu.transactions.some(function (tr) {
return tr.annotation(External);
})) {
var doc = vu.state.doc;
var _value = doc.toString();
onChange(_value, vu);
}
onStatistics && onStatistics((0, _utils.getStatistics)(vu));
});
var defaultExtensions = (0, _getDefaultExtensions.getDefaultExtensions)({
theme: theme,
editable: editable,
readOnly: readOnly,
placeholder: placeholderStr,
indentWithTab: defaultIndentWithTab,
basicSetup: defaultBasicSetup
});
var getExtensions = [updateListener, defaultThemeOption].concat((0, _toConsumableArray2["default"])(defaultExtensions));
if (onUpdate && typeof onUpdate === 'function') {
getExtensions.push(_view.EditorView.updateListener.of(onUpdate));
}
getExtensions = getExtensions.concat(extensions);
(0, _react.useEffect)(function () {
if (container && !state) {
var config = {
doc: value,
selection: selection,
extensions: getExtensions
};
var stateCurrent = initialState ? _state.EditorState.fromJSON(initialState.json, config, initialState.fields) : _state.EditorState.create(config);
setState(stateCurrent);
if (!view) {
var viewCurrent = new _view.EditorView({
state: stateCurrent,
parent: container,
root: root
});
setView(viewCurrent);
onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);
}
}
return function () {
if (view) {
setState(undefined);
setView(undefined);
}
};
}, [container, state]);
(0, _react.useEffect)(function () {
return setContainer(props.container);
}, [props.container]);
(0, _react.useEffect)(function () {
return function () {
if (view) {
view.destroy();
setView(undefined);
}
};
}, [view]);
(0, _react.useEffect)(function () {
if (autoFocus && view) {
view.focus();
}
}, [autoFocus, view]);
(0, _react.useEffect)(function () {
if (view) {
view.dispatch({
effects: _state.StateEffect.reconfigure.of(getExtensions)
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [theme, extensions, height, minHeight, maxHeight, width, minWidth, maxWidth, placeholderStr, editable, readOnly, defaultIndentWithTab, defaultBasicSetup, onChange, onUpdate]);
(0, _react.useEffect)(function () {
if (value === undefined) {
return;
}
var currentValue = view ? view.state.doc.toString() : '';
if (view && value !== currentValue) {
view.dispatch({
changes: {
from: 0,
to: currentValue.length,
insert: value || ''
},
annotations: [External.of(true)]
});
}
}, [value, view]);
return {
state: state,
setState: setState,
view: view,
setView: setView,
container: container,
setContainer: setContainer
};
}

View File

@@ -0,0 +1,32 @@
import type { EditorSelection, SelectionRange, Line } from '@codemirror/state';
import type { ViewUpdate } from '@codemirror/view';
export interface Statistics {
/** total length of the document */
length: number;
/** Get the number of lines in the editor. */
lineCount: number;
/** Get the currently line description around the given position. */
line: Line;
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
lineBreak: string;
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
readOnly: boolean;
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
tabSize: number;
/** Cursor Position */
selection: EditorSelection;
/** Make sure the selection only has one range. */
selectionAsSingle: SelectionRange;
/** Retrieves a list of all current selections. */
ranges: readonly SelectionRange[];
/** Get the currently selected code. */
selectionCode: string;
/**
* The length of the given array should be the same as the number of active selections.
* Replaces the content of the selections with the strings in the array.
*/
selections: string[];
/** Return true if any text is selected. */
selectedText: boolean;
}
export declare const getStatistics: (view: ViewUpdate) => Statistics;

26
server/node_modules/@uiw/react-codemirror/cjs/utils.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getStatistics = void 0;
var getStatistics = exports.getStatistics = function getStatistics(view) {
return {
line: view.state.doc.lineAt(view.state.selection.main.from),
lineCount: view.state.doc.lines,
lineBreak: view.state.lineBreak,
length: view.state.doc.length,
readOnly: view.state.readOnly,
tabSize: view.state.tabSize,
selection: view.state.selection,
selectionAsSingle: view.state.selection.asSingle().main,
ranges: view.state.selection.ranges,
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
selections: view.state.selection.ranges.map(function (r) {
return view.state.sliceDoc(r.from, r.to);
}),
selectedText: view.state.selection.ranges.some(function (r) {
return !r.empty;
})
};
};

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,13 @@
import { type Extension } from '@codemirror/state';
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
export * from '@codemirror/theme-one-dark';
export * from './theme/light';
export interface DefaultExtensionsOptions {
indentWithTab?: boolean;
basicSetup?: boolean | BasicSetupOptions;
placeholder?: string | HTMLElement;
theme?: 'light' | 'dark' | 'none' | Extension;
readOnly?: boolean;
editable?: boolean;
}
export declare const getDefaultExtensions: (optios?: DefaultExtensionsOptions) => Extension[];

View File

@@ -0,0 +1,55 @@
import { indentWithTab } from '@codemirror/commands';
import { basicSetup } from '@uiw/codemirror-extensions-basic-setup';
import { EditorView, keymap, placeholder } from '@codemirror/view';
import { oneDark } from '@codemirror/theme-one-dark';
import { EditorState } from '@codemirror/state';
import { defaultLightThemeOption } from './theme/light';
export * from '@codemirror/theme-one-dark';
export * from './theme/light';
export var getDefaultExtensions = function getDefaultExtensions(optios) {
if (optios === void 0) {
optios = {};
}
var {
indentWithTab: defaultIndentWithTab = true,
editable = true,
readOnly = false,
theme = 'light',
placeholder: placeholderStr = '',
basicSetup: defaultBasicSetup = true
} = optios;
var getExtensions = [];
if (defaultIndentWithTab) {
getExtensions.unshift(keymap.of([indentWithTab]));
}
if (defaultBasicSetup) {
if (typeof defaultBasicSetup === 'boolean') {
getExtensions.unshift(basicSetup());
} else {
getExtensions.unshift(basicSetup(defaultBasicSetup));
}
}
if (placeholderStr) {
getExtensions.unshift(placeholder(placeholderStr));
}
switch (theme) {
case 'light':
getExtensions.push(defaultLightThemeOption);
break;
case 'dark':
getExtensions.push(oneDark);
break;
case 'none':
break;
default:
getExtensions.push(theme);
break;
}
if (editable === false) {
getExtensions.push(EditorView.editable.of(false));
}
if (readOnly) {
getExtensions.push(EditorState.readOnly.of(true));
}
return [...getExtensions];
};

View File

@@ -0,0 +1,85 @@
import React from 'react';
import type { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';
import type { EditorView, ViewUpdate } from '@codemirror/view';
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
import { type Statistics } from './utils';
export * from '@codemirror/view';
export * from '@codemirror/state';
export * from '@uiw/codemirror-extensions-basic-setup';
export * from './useCodeMirror';
export * from './getDefaultExtensions';
export * from './utils';
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
/** value of the auto created model in the editor. */
value?: string;
height?: string;
minHeight?: string;
maxHeight?: string;
width?: string;
minWidth?: string;
maxWidth?: string;
/** focus on the editor. */
autoFocus?: boolean;
/** Enables a placeholder—a piece of example content to show when the editor is empty. */
placeholder?: string | HTMLElement;
/**
* `light` / `dark` / `Extension` Defaults to `light`.
* @default light
*/
theme?: 'light' | 'dark' | 'none' | Extension;
/**
* Whether to optional basicSetup by default
* @default true
*/
basicSetup?: boolean | BasicSetupOptions;
/**
* This disables editing of the editor content by the user.
* @default true
*/
editable?: boolean;
/**
* This disables editing of the editor content by the user.
* @default false
*/
readOnly?: boolean;
/**
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
* or behaves according to the browser's default behavior (`false`).
* @default true
*/
indentWithTab?: boolean;
/** Fired whenever a change occurs to the document. */
onChange?(value: string, viewUpdate: ViewUpdate): void;
/** Some data on the statistics editor. */
onStatistics?(data: Statistics): void;
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
onUpdate?(viewUpdate: ViewUpdate): void;
/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;
/**
* Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
* They can either be built-in extension-providing objects,
* such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
*/
extensions?: Extension[];
/**
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
*/
root?: ShadowRoot | Document;
/**
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
*/
initialState?: {
json: any;
fields?: Record<string, StateField<any>>;
};
}
export interface ReactCodeMirrorRef {
editor?: HTMLDivElement | null;
state?: EditorState;
view?: EditorView;
}
declare const ReactCodeMirror: React.ForwardRefExoticComponent<ReactCodeMirrorProps & React.RefAttributes<ReactCodeMirrorRef>>;
export default ReactCodeMirror;

87
server/node_modules/@uiw/react-codemirror/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,87 @@
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onStatistics", "onCreateEditor", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root", "initialState"];
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
import { useCodeMirror } from './useCodeMirror';
import { jsx as _jsx } from "react/jsx-runtime";
export * from '@codemirror/view';
export * from '@codemirror/state';
export * from '@uiw/codemirror-extensions-basic-setup';
export * from './useCodeMirror';
export * from './getDefaultExtensions';
export * from './utils';
var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
var {
className,
value = '',
selection,
extensions = [],
onChange,
onStatistics,
onCreateEditor,
onUpdate,
autoFocus,
theme = 'light',
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
basicSetup,
placeholder,
indentWithTab,
editable,
readOnly,
root,
initialState
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
var editor = useRef(null);
var {
state,
view,
container
} = useCodeMirror({
container: editor.current,
root,
value,
autoFocus,
theme,
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
basicSetup,
placeholder,
indentWithTab,
editable,
readOnly,
selection,
onChange,
onStatistics,
onCreateEditor,
onUpdate,
extensions,
initialState
});
useImperativeHandle(ref, () => ({
editor: editor.current,
state: state,
view: view
}), [editor, container, state, view]);
// check type of value
if (typeof value !== 'string') {
throw new Error("value must be typeof string but got " + typeof value);
}
var defaultClassNames = typeof theme === 'string' ? "cm-theme-" + theme : 'cm-theme';
return /*#__PURE__*/_jsx("div", _extends({
ref: editor,
className: "" + defaultClassNames + (className ? " " + className : '')
}, other));
});
ReactCodeMirror.displayName = 'CodeMirror';
export default ReactCodeMirror;

View File

@@ -0,0 +1 @@
export declare const defaultLightThemeOption: import("@codemirror/state").Extension;

View File

@@ -0,0 +1,8 @@
import { EditorView } from '@codemirror/view';
export var defaultLightThemeOption = EditorView.theme({
'&': {
backgroundColor: '#fff'
}
}, {
dark: false
});

View File

@@ -0,0 +1,14 @@
import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { type ReactCodeMirrorProps } from '.';
export interface UseCodeMirror extends ReactCodeMirrorProps {
container?: HTMLDivElement | null;
}
export declare function useCodeMirror(props: UseCodeMirror): {
state: EditorState | undefined;
setState: import("react").Dispatch<import("react").SetStateAction<EditorState | undefined>>;
view: EditorView | undefined;
setView: import("react").Dispatch<import("react").SetStateAction<EditorView | undefined>>;
container: HTMLDivElement | null | undefined;
setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null | undefined>>;
};

View File

@@ -0,0 +1,143 @@
import { useEffect, useState } from 'react';
import { Annotation, EditorState, StateEffect } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { getDefaultExtensions } from './getDefaultExtensions';
import { getStatistics } from './utils';
var External = Annotation.define();
var emptyExtensions = [];
export function useCodeMirror(props) {
var {
value,
selection,
onChange,
onStatistics,
onCreateEditor,
onUpdate,
extensions = emptyExtensions,
autoFocus,
theme = 'light',
height = null,
minHeight = null,
maxHeight = null,
width = null,
minWidth = null,
maxWidth = null,
placeholder: placeholderStr = '',
editable = true,
readOnly = false,
indentWithTab: defaultIndentWithTab = true,
basicSetup: defaultBasicSetup = true,
root,
initialState
} = props;
var [container, setContainer] = useState();
var [view, setView] = useState();
var [state, setState] = useState();
var defaultThemeOption = EditorView.theme({
'&': {
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth
},
'& .cm-scroller': {
height: '100% !important'
}
});
var updateListener = EditorView.updateListener.of(vu => {
if (vu.docChanged && typeof onChange === 'function' &&
// Fix echoing of the remote changes:
// If transaction is market as remote we don't have to call `onChange` handler again
!vu.transactions.some(tr => tr.annotation(External))) {
var doc = vu.state.doc;
var _value = doc.toString();
onChange(_value, vu);
}
onStatistics && onStatistics(getStatistics(vu));
});
var defaultExtensions = getDefaultExtensions({
theme,
editable,
readOnly,
placeholder: placeholderStr,
indentWithTab: defaultIndentWithTab,
basicSetup: defaultBasicSetup
});
var getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions];
if (onUpdate && typeof onUpdate === 'function') {
getExtensions.push(EditorView.updateListener.of(onUpdate));
}
getExtensions = getExtensions.concat(extensions);
useEffect(() => {
if (container && !state) {
var config = {
doc: value,
selection,
extensions: getExtensions
};
var stateCurrent = initialState ? EditorState.fromJSON(initialState.json, config, initialState.fields) : EditorState.create(config);
setState(stateCurrent);
if (!view) {
var viewCurrent = new EditorView({
state: stateCurrent,
parent: container,
root
});
setView(viewCurrent);
onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);
}
}
return () => {
if (view) {
setState(undefined);
setView(undefined);
}
};
}, [container, state]);
useEffect(() => setContainer(props.container), [props.container]);
useEffect(() => () => {
if (view) {
view.destroy();
setView(undefined);
}
}, [view]);
useEffect(() => {
if (autoFocus && view) {
view.focus();
}
}, [autoFocus, view]);
useEffect(() => {
if (view) {
view.dispatch({
effects: StateEffect.reconfigure.of(getExtensions)
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [theme, extensions, height, minHeight, maxHeight, width, minWidth, maxWidth, placeholderStr, editable, readOnly, defaultIndentWithTab, defaultBasicSetup, onChange, onUpdate]);
useEffect(() => {
if (value === undefined) {
return;
}
var currentValue = view ? view.state.doc.toString() : '';
if (view && value !== currentValue) {
view.dispatch({
changes: {
from: 0,
to: currentValue.length,
insert: value || ''
},
annotations: [External.of(true)]
});
}
}, [value, view]);
return {
state,
setState,
view,
setView,
container,
setContainer
};
}

View File

@@ -0,0 +1,32 @@
import type { EditorSelection, SelectionRange, Line } from '@codemirror/state';
import type { ViewUpdate } from '@codemirror/view';
export interface Statistics {
/** total length of the document */
length: number;
/** Get the number of lines in the editor. */
lineCount: number;
/** Get the currently line description around the given position. */
line: Line;
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
lineBreak: string;
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
readOnly: boolean;
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
tabSize: number;
/** Cursor Position */
selection: EditorSelection;
/** Make sure the selection only has one range. */
selectionAsSingle: SelectionRange;
/** Retrieves a list of all current selections. */
ranges: readonly SelectionRange[];
/** Get the currently selected code. */
selectionCode: string;
/**
* The length of the given array should be the same as the number of active selections.
* Replaces the content of the selections with the strings in the array.
*/
selections: string[];
/** Return true if any text is selected. */
selectedText: boolean;
}
export declare const getStatistics: (view: ViewUpdate) => Statistics;

16
server/node_modules/@uiw/react-codemirror/esm/utils.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
export var getStatistics = view => {
return {
line: view.state.doc.lineAt(view.state.selection.main.from),
lineCount: view.state.doc.lines,
lineBreak: view.state.lineBreak,
length: view.state.doc.length,
readOnly: view.state.readOnly,
tabSize: view.state.tabSize,
selection: view.state.selection,
selectionAsSingle: view.state.selection.asSingle().main,
ranges: view.state.selection.ranges,
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
selections: view.state.selection.ranges.map(r => view.state.sliceDoc(r.from, r.to)),
selectedText: view.state.selection.ranges.some(r => !r.empty)
};
};

61
server/node_modules/@uiw/react-codemirror/package.json generated vendored Normal file
View File

@@ -0,0 +1,61 @@
{
"name": "@uiw/react-codemirror",
"version": "4.22.2",
"description": "CodeMirror component for React.",
"homepage": "https://uiwjs.github.io/react-codemirror",
"funding": "https://jaywcjlove.github.io/#/sponsor",
"author": "kenny wong <wowohoo@qq.com>",
"license": "MIT",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"scripts": {
"bundle": "ncc build src/index.tsx --target web --filename codemirror && npm run bundle:min",
"bundle:watch": "ncc watch src/index.tsx --target web --filename codemirror",
"bundle:min": "ncc build src/index.tsx --target web --filename codemirror --minify",
"watch": "tsbb watch src/*.tsx --use-babel",
"build": "tsbb build src/*.tsx --use-babel"
},
"repository": {
"type": "git",
"url": "https://github.com/uiwjs/react-codemirror.git"
},
"files": [
"dist",
"src",
"esm",
"cjs"
],
"peerDependencies": {
"@babel/runtime": ">=7.11.0",
"@codemirror/state": ">=6.0.0",
"@codemirror/theme-one-dark": ">=6.0.0",
"@codemirror/view": ">=6.0.0",
"codemirror": ">=6.0.0",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"dependencies": {
"@babel/runtime": "^7.18.6",
"@codemirror/commands": "^6.1.0",
"@codemirror/state": "^6.1.1",
"@codemirror/theme-one-dark": "^6.0.0",
"@uiw/codemirror-extensions-basic-setup": "4.22.2",
"codemirror": "^6.0.0"
},
"keywords": [
"react",
"codemirror",
"codemirror6",
"react-codemirror",
"editor",
"syntax",
"ide",
"code"
],
"jest": {
"coverageReporters": [
"lcov",
"json-summary"
]
}
}

View File

@@ -0,0 +1,91 @@
/* eslint-disable jest/no-conditional-expect */
import React, { useEffect, useRef } from 'react';
import renderer from 'react-test-renderer';
import { render, fireEvent, screen } from '@testing-library/react';
// import userEvent from '@testing-library/user-event';
// import '@testing-library/jest-dom';
import CodeMirror, { ReactCodeMirrorRef } from '..';
it('CodeMirror', async () => {
const component = renderer.create(<CodeMirror />);
let tree = component.toJSON();
if (tree && !Array.isArray(tree)) {
expect(tree.type).toEqual('div');
expect(tree.props.className).toEqual('cm-theme-light');
}
});
it('CodeMirror onChange', async () => {
const handleChange = jest.fn((value) => {
expect(value).toEqual('# title');
return Array.isArray(value) ? value.join() : value;
});
render(<CodeMirror autoFocus value="console.log('Hello world!')" onChange={handleChange} />);
const input = await screen.findByRole<HTMLInputElement>('textbox'); // findByRole('textbox');
fireEvent.change(input, { target: { textContent: '# title' } });
const elm = screen.queryByText('# title');
expect((elm as any).cmView.dom.innerHTML).toEqual('# title');
});
it('CodeMirror onUpdate', async () => {
render(
<CodeMirror
value="console.log('Hello world!')"
autoFocus
onUpdate={(viewUpdate) => {
expect(viewUpdate.state.doc.length).toEqual(27);
}}
/>,
);
});
it('CodeMirror ref', async () => {
function Demo() {
const ref = useRef<ReactCodeMirrorRef>(null);
useEffect(() => {
expect(Object.keys(ref.current!)).toEqual(['editor', 'state', 'view']);
}, [ref]);
return <CodeMirror ref={ref} value="console.log('Hello world!')" />;
}
render(<Demo />);
});
it('CodeMirror theme', async () => {
const component = renderer.create(<CodeMirror theme="dark" />);
let tree = component.toJSON();
if (tree && !Array.isArray(tree)) {
expect(tree.type).toEqual('div');
expect(tree.props.className).toEqual('cm-theme-dark');
}
});
it('CodeMirror className', async () => {
const component = renderer.create(<CodeMirror className="test" />);
let tree = component.toJSON();
if (tree && !Array.isArray(tree)) {
expect(tree.type).toEqual('div');
expect(tree.props.className).toEqual('cm-theme-light test');
}
});
it('CodeMirror placeholder', async () => {
render(<CodeMirror placeholder="Hello World" className="test" />);
const elm = screen.queryByText('Hello World');
expect(elm!.style['pointerEvents']).toEqual('none');
expect(elm!.className).toEqual('cm-placeholder');
});
it('CodeMirror editable', async () => {
render(<CodeMirror editable={false} className="test" />);
const text = screen.getByRole('textbox');
expect(text.className).toEqual('cm-content');
expect(text.tagName).toEqual('DIV');
});
it("CodeMirror doesn't echo changes", async () => {
const handleChange = jest.fn();
const { rerender } = render(<CodeMirror value="value a" onChange={handleChange} />);
rerender(<CodeMirror value="value b" onChange={handleChange} />);
expect(handleChange).not.toHaveBeenCalled();
});

View File

@@ -0,0 +1,65 @@
import { type Extension } from '@codemirror/state';
import { indentWithTab } from '@codemirror/commands';
import { basicSetup, type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
import { EditorView, keymap, placeholder } from '@codemirror/view';
import { oneDark } from '@codemirror/theme-one-dark';
import { EditorState } from '@codemirror/state';
import { defaultLightThemeOption } from './theme/light';
export * from '@codemirror/theme-one-dark';
export * from './theme/light';
export interface DefaultExtensionsOptions {
indentWithTab?: boolean;
basicSetup?: boolean | BasicSetupOptions;
placeholder?: string | HTMLElement;
theme?: 'light' | 'dark' | 'none' | Extension;
readOnly?: boolean;
editable?: boolean;
}
export const getDefaultExtensions = (optios: DefaultExtensionsOptions = {}): Extension[] => {
const {
indentWithTab: defaultIndentWithTab = true,
editable = true,
readOnly = false,
theme = 'light',
placeholder: placeholderStr = '',
basicSetup: defaultBasicSetup = true,
} = optios;
const getExtensions: Extension[] = [];
if (defaultIndentWithTab) {
getExtensions.unshift(keymap.of([indentWithTab]));
}
if (defaultBasicSetup) {
if (typeof defaultBasicSetup === 'boolean') {
getExtensions.unshift(basicSetup());
} else {
getExtensions.unshift(basicSetup(defaultBasicSetup));
}
}
if (placeholderStr) {
getExtensions.unshift(placeholder(placeholderStr));
}
switch (theme) {
case 'light':
getExtensions.push(defaultLightThemeOption);
break;
case 'dark':
getExtensions.push(oneDark);
break;
case 'none':
break;
default:
getExtensions.push(theme);
break;
}
if (editable === false) {
getExtensions.push(EditorView.editable.of(false));
}
if (readOnly) {
getExtensions.push(EditorState.readOnly.of(true));
}
return [...getExtensions];
};

164
server/node_modules/@uiw/react-codemirror/src/index.tsx generated vendored Normal file
View File

@@ -0,0 +1,164 @@
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
import type { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';
import type { EditorView, ViewUpdate } from '@codemirror/view';
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
import { useCodeMirror } from './useCodeMirror';
import { type Statistics } from './utils';
export * from '@codemirror/view';
export * from '@codemirror/state';
export * from '@uiw/codemirror-extensions-basic-setup';
export * from './useCodeMirror';
export * from './getDefaultExtensions';
export * from './utils';
export interface ReactCodeMirrorProps
extends Omit<EditorStateConfig, 'doc' | 'extensions'>,
Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
/** value of the auto created model in the editor. */
value?: string;
height?: string;
minHeight?: string;
maxHeight?: string;
width?: string;
minWidth?: string;
maxWidth?: string;
/** focus on the editor. */
autoFocus?: boolean;
/** Enables a placeholder—a piece of example content to show when the editor is empty. */
placeholder?: string | HTMLElement;
/**
* `light` / `dark` / `Extension` Defaults to `light`.
* @default light
*/
theme?: 'light' | 'dark' | 'none' | Extension;
/**
* Whether to optional basicSetup by default
* @default true
*/
basicSetup?: boolean | BasicSetupOptions;
/**
* This disables editing of the editor content by the user.
* @default true
*/
editable?: boolean;
/**
* This disables editing of the editor content by the user.
* @default false
*/
readOnly?: boolean;
/**
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
* or behaves according to the browser's default behavior (`false`).
* @default true
*/
indentWithTab?: boolean;
/** Fired whenever a change occurs to the document. */
onChange?(value: string, viewUpdate: ViewUpdate): void;
/** Some data on the statistics editor. */
onStatistics?(data: Statistics): void;
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
onUpdate?(viewUpdate: ViewUpdate): void;
/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;
/**
* Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
* They can either be built-in extension-providing objects,
* such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
*/
extensions?: Extension[];
/**
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
*/
root?: ShadowRoot | Document;
/**
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
*/
initialState?: {
json: any;
fields?: Record<string, StateField<any>>;
};
}
export interface ReactCodeMirrorRef {
editor?: HTMLDivElement | null;
state?: EditorState;
view?: EditorView;
}
const ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {
const {
className,
value = '',
selection,
extensions = [],
onChange,
onStatistics,
onCreateEditor,
onUpdate,
autoFocus,
theme = 'light',
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
basicSetup,
placeholder,
indentWithTab,
editable,
readOnly,
root,
initialState,
...other
} = props;
const editor = useRef<HTMLDivElement>(null);
const { state, view, container } = useCodeMirror({
container: editor.current,
root,
value,
autoFocus,
theme,
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
basicSetup,
placeholder,
indentWithTab,
editable,
readOnly,
selection,
onChange,
onStatistics,
onCreateEditor,
onUpdate,
extensions,
initialState,
});
useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [
editor,
container,
state,
view,
]);
// check type of value
if (typeof value !== 'string') {
throw new Error(`value must be typeof string but got ${typeof value}`);
}
const defaultClassNames = typeof theme === 'string' ? `cm-theme-${theme}` : 'cm-theme';
return <div ref={editor} className={`${defaultClassNames}${className ? ` ${className}` : ''}`} {...other}></div>;
});
ReactCodeMirror.displayName = 'CodeMirror';
export default ReactCodeMirror;

View File

@@ -0,0 +1,12 @@
import { EditorView } from '@codemirror/view';
export const defaultLightThemeOption = EditorView.theme(
{
'&': {
backgroundColor: '#fff',
},
},
{
dark: false,
},
);

View File

@@ -0,0 +1,172 @@
import { useEffect, useState } from 'react';
import { Annotation, EditorState, StateEffect, type Extension } from '@codemirror/state';
import { EditorView, type ViewUpdate } from '@codemirror/view';
import { getDefaultExtensions } from './getDefaultExtensions';
import { getStatistics } from './utils';
import { type ReactCodeMirrorProps } from '.';
const External = Annotation.define<boolean>();
export interface UseCodeMirror extends ReactCodeMirrorProps {
container?: HTMLDivElement | null;
}
const emptyExtensions: Extension[] = [];
export function useCodeMirror(props: UseCodeMirror) {
const {
value,
selection,
onChange,
onStatistics,
onCreateEditor,
onUpdate,
extensions = emptyExtensions,
autoFocus,
theme = 'light',
height = null,
minHeight = null,
maxHeight = null,
width = null,
minWidth = null,
maxWidth = null,
placeholder: placeholderStr = '',
editable = true,
readOnly = false,
indentWithTab: defaultIndentWithTab = true,
basicSetup: defaultBasicSetup = true,
root,
initialState,
} = props;
const [container, setContainer] = useState<HTMLDivElement | null>();
const [view, setView] = useState<EditorView>();
const [state, setState] = useState<EditorState>();
const defaultThemeOption = EditorView.theme({
'&': {
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
},
'& .cm-scroller': {
height: '100% !important',
},
});
const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {
if (
vu.docChanged &&
typeof onChange === 'function' &&
// Fix echoing of the remote changes:
// If transaction is market as remote we don't have to call `onChange` handler again
!vu.transactions.some((tr) => tr.annotation(External))
) {
const doc = vu.state.doc;
const value = doc.toString();
onChange(value, vu);
}
onStatistics && onStatistics(getStatistics(vu));
});
const defaultExtensions = getDefaultExtensions({
theme,
editable,
readOnly,
placeholder: placeholderStr,
indentWithTab: defaultIndentWithTab,
basicSetup: defaultBasicSetup,
});
let getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions];
if (onUpdate && typeof onUpdate === 'function') {
getExtensions.push(EditorView.updateListener.of(onUpdate));
}
getExtensions = getExtensions.concat(extensions);
useEffect(() => {
if (container && !state) {
const config = {
doc: value,
selection,
extensions: getExtensions,
};
const stateCurrent = initialState
? EditorState.fromJSON(initialState.json, config, initialState.fields)
: EditorState.create(config);
setState(stateCurrent);
if (!view) {
const viewCurrent = new EditorView({
state: stateCurrent,
parent: container,
root,
});
setView(viewCurrent);
onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);
}
}
return () => {
if (view) {
setState(undefined);
setView(undefined);
}
};
}, [container, state]);
useEffect(() => setContainer(props.container), [props.container]);
useEffect(
() => () => {
if (view) {
view.destroy();
setView(undefined);
}
},
[view],
);
useEffect(() => {
if (autoFocus && view) {
view.focus();
}
}, [autoFocus, view]);
useEffect(() => {
if (view) {
view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
theme,
extensions,
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
placeholderStr,
editable,
readOnly,
defaultIndentWithTab,
defaultBasicSetup,
onChange,
onUpdate,
]);
useEffect(() => {
if (value === undefined) {
return;
}
const currentValue = view ? view.state.doc.toString() : '';
if (view && value !== currentValue) {
view.dispatch({
changes: { from: 0, to: currentValue.length, insert: value || '' },
annotations: [External.of(true)],
});
}
}, [value, view]);
return { state, setState, view, setView, container, setContainer };
}

49
server/node_modules/@uiw/react-codemirror/src/utils.ts generated vendored Normal file
View File

@@ -0,0 +1,49 @@
import type { EditorSelection, SelectionRange, Line } from '@codemirror/state';
import type { ViewUpdate } from '@codemirror/view';
export interface Statistics {
/** total length of the document */
length: number;
/** Get the number of lines in the editor. */
lineCount: number;
/** Get the currently line description around the given position. */
line: Line;
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
lineBreak: string;
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
readOnly: boolean;
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
tabSize: number;
/** Cursor Position */
selection: EditorSelection;
/** Make sure the selection only has one range. */
selectionAsSingle: SelectionRange;
/** Retrieves a list of all current selections. */
ranges: readonly SelectionRange[];
/** Get the currently selected code. */
selectionCode: string;
/**
* The length of the given array should be the same as the number of active selections.
* Replaces the content of the selections with the strings in the array.
*/
selections: string[];
/** Return true if any text is selected. */
selectedText: boolean;
}
export const getStatistics = (view: ViewUpdate): Statistics => {
return {
line: view.state.doc.lineAt(view.state.selection.main.from),
lineCount: view.state.doc.lines,
lineBreak: view.state.lineBreak,
length: view.state.doc.length,
readOnly: view.state.readOnly,
tabSize: view.state.tabSize,
selection: view.state.selection,
selectionAsSingle: view.state.selection.asSingle().main,
ranges: view.state.selection.ranges,
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),
selectedText: view.state.selection.ranges.some((r) => !r.empty),
};
};