|
| 1 | +<!--rehype:ignore:start--> |
| 2 | + |
| 3 | +# Basic Setup Extensions |
| 4 | + |
| 5 | +<!--rehype:ignore:end--> |
| 6 | + |
| 7 | +[](https://www.npmjs.com/package/@uiw/codemirror-extensions-basic-setup) |
| 8 | + |
| 9 | +Basic configuration for the CodeMirror6 code editor. This is the official [basic-setup](https://github.com/codemirror/basic-setup) package fork, making configuration optional. |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install @uiw/codemirror-extensions-basic-setup --save |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +⚠️ Integrated into **@uiw/react-codemirror** package |
| 20 | + |
| 21 | +```jsx |
| 22 | +import CodeMirror from '@uiw/react-codemirror'; |
| 23 | + |
| 24 | +function App() { |
| 25 | + return ( |
| 26 | + <CodeMirror |
| 27 | + value="console.log('hello world!');" |
| 28 | + height="200px" |
| 29 | + basicSetup={{ |
| 30 | + foldGutter: false, |
| 31 | + dropCursor: false, |
| 32 | + allowMultipleSelections: false, |
| 33 | + indentOnInput: false, |
| 34 | + }} |
| 35 | + /> |
| 36 | + ); |
| 37 | +} |
| 38 | +export default App; |
| 39 | +``` |
| 40 | + |
| 41 | +```js |
| 42 | +import { EditorView } from '@codemirror/view'; |
| 43 | +import { EditorState } from '@codemirror/state'; |
| 44 | +import { basicSetup, minimalSetup } from '@uiw/codemirror-extensions-basic-setup'; |
| 45 | + |
| 46 | +const state = EditorState.create({ |
| 47 | + doc: 'my source code', |
| 48 | + extensions: [ |
| 49 | + basicSetup({ |
| 50 | + foldGutter: false, |
| 51 | + dropCursor: false, |
| 52 | + allowMultipleSelections: false, |
| 53 | + indentOnInput: false, |
| 54 | + }), |
| 55 | + ], |
| 56 | +}); |
| 57 | + |
| 58 | +const view = new EditorView({ |
| 59 | + parent: document.querySelector('#editor'), |
| 60 | + state, |
| 61 | +}); |
| 62 | +``` |
| 63 | + |
| 64 | +```diff |
| 65 | +import { EditorView } from '@codemirror/view'; |
| 66 | +import { EditorState } from '@codemirror/state'; |
| 67 | +- import { basicSetup, minimalSetup } from 'codemirror'; |
| 68 | ++ import { basicSetup, minimalSetup } from '@uiw/codemirror-extensions-basic-setup'; |
| 69 | + |
| 70 | +const state = EditorState.create({ |
| 71 | + doc: 'my source code', |
| 72 | + extensions: [ |
| 73 | +- basicSetup |
| 74 | ++ basicSetup({ |
| 75 | ++ foldGutter: false, |
| 76 | ++ dropCursor: false, |
| 77 | ++ }) |
| 78 | + ], |
| 79 | +}); |
| 80 | + |
| 81 | +const view = new EditorView({ |
| 82 | + parent: document.querySelector('#editor'), |
| 83 | + state, |
| 84 | +}); |
| 85 | +``` |
| 86 | + |
| 87 | +## API |
| 88 | + |
| 89 | +```ts |
| 90 | +import { Extension } from '@codemirror/state'; |
| 91 | +export interface BasicSetupOptions extends MinimalSetupOptions { |
| 92 | + lineNumbers?: boolean; |
| 93 | + highlightActiveLineGutter?: boolean; |
| 94 | + foldGutter?: boolean; |
| 95 | + dropCursor?: boolean; |
| 96 | + allowMultipleSelections?: boolean; |
| 97 | + indentOnInput?: boolean; |
| 98 | + bracketMatching?: boolean; |
| 99 | + closeBrackets?: boolean; |
| 100 | + autocompletion?: boolean; |
| 101 | + rectangularSelection?: boolean; |
| 102 | + crosshairCursor?: boolean; |
| 103 | + highlightActiveLine?: boolean; |
| 104 | + highlightSelectionMatches?: boolean; |
| 105 | + closeBracketsKeymap?: boolean; |
| 106 | + searchKeymap?: boolean; |
| 107 | + foldKeymap?: boolean; |
| 108 | + completionKeymap?: boolean; |
| 109 | + lintKeymap?: boolean; |
| 110 | +} |
| 111 | +/** |
| 112 | +This is an extension value that just pulls together a number of |
| 113 | +extensions that you might want in a basic editor. It is meant as a |
| 114 | +convenient helper to quickly set up CodeMirror without installing |
| 115 | +and importing a lot of separate packages. |
| 116 | +
|
| 117 | +Specifically, it includes... |
| 118 | +
|
| 119 | +- [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap) |
| 120 | +- [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers) |
| 121 | +- [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars) |
| 122 | +- [the undo history](https://codemirror.net/6/docs/ref/#commands.history) |
| 123 | +- [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) |
| 124 | +- [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection) |
| 125 | +- [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor) |
| 126 | +- [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections) |
| 127 | +- [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput) |
| 128 | +- [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback) |
| 129 | +- [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching) |
| 130 | +- [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) |
| 131 | +- [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion) |
| 132 | +- [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor) |
| 133 | +- [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine) |
| 134 | +- [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter) |
| 135 | +- [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches) |
| 136 | +- [search](https://codemirror.net/6/docs/ref/#search.searchKeymap) |
| 137 | +- [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap) |
| 138 | +
|
| 139 | +(You'll probably want to add some language package to your setup |
| 140 | +too.) |
| 141 | +
|
| 142 | +This extension does not allow customization. The idea is that, |
| 143 | +once you decide you want to configure your editor more precisely, |
| 144 | +you take this package's source (which is just a bunch of imports |
| 145 | +and an array literal), copy it into your own code, and adjust it |
| 146 | +as desired. |
| 147 | +*/ |
| 148 | +export declare const basicSetup: (options?: BasicSetupOptions) => Extension[]; |
| 149 | +export interface MinimalSetupOptions { |
| 150 | + highlightSpecialChars?: boolean; |
| 151 | + history?: boolean; |
| 152 | + drawSelection?: boolean; |
| 153 | + syntaxHighlighting?: boolean; |
| 154 | + defaultKeymap?: boolean; |
| 155 | + historyKeymap?: boolean; |
| 156 | +} |
| 157 | +/** |
| 158 | +A minimal set of extensions to create a functional editor. Only |
| 159 | +includes [the default keymap](https://codemirror.net/6/docs/ref/#commands.defaultKeymap), [undo |
| 160 | +history](https://codemirror.net/6/docs/ref/#commands.history), [special character |
| 161 | +highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars), [custom selection |
| 162 | +drawing](https://codemirror.net/6/docs/ref/#view.drawSelection), and [default highlight |
| 163 | +style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle). |
| 164 | +*/ |
| 165 | +export declare const minimalSetup: (options?: MinimalSetupOptions) => Extension[]; |
| 166 | +``` |
| 167 | + |
| 168 | +## Contributors |
| 169 | + |
| 170 | +As always, thanks to our amazing contributors! |
| 171 | + |
| 172 | +<a href="https://github.com/uiwjs/react-codemirror/graphs/contributors"> |
| 173 | + <img src="https://uiwjs.github.io/react-codemirror/CONTRIBUTORS.svg" /> |
| 174 | +</a> |
| 175 | + |
| 176 | +Made with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors). |
| 177 | + |
| 178 | +## License |
| 179 | + |
| 180 | +Licensed under the MIT License. |
0 commit comments