-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from tidbcloud/feat/docs
feat: extension readme
- Loading branch information
Showing
5 changed files
with
264 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# @tidbcloud/codemirror-extension-basic-setup | ||
|
||
Basic configuration for the CodeMirror6 code editor. | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/codemirror-extension-basic-setup | ||
``` | ||
|
||
You need to install its peer dependencies as well: | ||
|
||
```shell | ||
npm install @codemirror/autocomplete @codemirror/commands @codemirror/lang-sql @codemirror/language @codemirror/lint @codemirror/search @codemirror/state @codemirror/view @lezer/highlight | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { | ||
BasicSetupOptions, | ||
basicSetup | ||
} from '@tidbcloud/codemirror-extension-basic-setup' | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [ | ||
basicSetup({ | ||
foldGutter: false, | ||
foldKeymap: false, | ||
searchKeymap: true, | ||
autocompletion: false | ||
}) | ||
] | ||
}) | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
```ts | ||
export interface MinimalSetupOptions { | ||
highlightSpecialChars?: boolean | ||
history?: boolean | ||
drawSelection?: boolean | ||
syntaxHighlighting?: boolean | ||
|
||
defaultKeymap?: boolean | ||
historyKeymap?: boolean | ||
} | ||
|
||
export interface BasicSetupOptions extends MinimalSetupOptions { | ||
lineNumbers?: boolean | ||
highlightActiveLineGutter?: boolean | ||
foldGutter?: boolean | ||
dropCursor?: boolean | ||
allowMultipleSelections?: boolean | ||
indentOnInput?: boolean | ||
bracketMatching?: boolean | ||
closeBrackets?: boolean | ||
autocompletion?: boolean | ||
rectangularSelection?: boolean | ||
crosshairCursor?: boolean | ||
highlightActiveLine?: boolean | ||
highlightSelectionMatches?: boolean | ||
|
||
closeBracketsKeymap?: boolean | ||
searchKeymap?: boolean | ||
foldKeymap?: boolean | ||
completionKeymap?: boolean | ||
lintKeymap?: boolean | ||
} | ||
|
||
function minimalSetup(options?: MinimalSetupOptions) => Extension[] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# @tidbcloud/codemirror-extension-events | ||
|
||
Events extensions for CodeMirror6. This extension provides 3 default events: onChange, onFocusChange and onSelectionChange. | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/codemirror-extension-events | ||
``` | ||
|
||
You need to install its peer dependencies as well: | ||
|
||
```shell | ||
npm install @codemirror/view @codemirror/state | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { onChange, onFocusChange, onSelectionChange } from '@tidbcloud/codemirror-extension-events' | ||
|
||
const onChangeHandler = (sql: string, view: EditorView) => { | ||
console.log(sql, view) | ||
} | ||
|
||
const onFocusChangeHandler = (sql: string) => { | ||
console.log(sql) | ||
} | ||
|
||
const onSelectionChangeHandler = (selectedRange: {from: number, to: numer}) => { | ||
console.log(selectedRange.from, selectedRange.to) | ||
} | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [ | ||
onChange(onChangeHandler), | ||
focusChangeHelper(onFocusChangeHandler), | ||
onSelectionChange: (onSelectionChangeHandler) | ||
] | ||
}) | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# @tidbcloud/codemirror-extension-linters | ||
|
||
This extension provides 3 linters: | ||
|
||
- fullWidthCharLinter: lint all the chinese characters | ||
- useDbLinter: use statement linter, the first statement should be use dbName; | ||
- regexMatchLinter: configurable by regular expression | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/codemirror-extension-linters | ||
``` | ||
|
||
You need to install its peer dependencies as well: | ||
|
||
```shell | ||
npm install @codemirror/view @codemirror/state @codemirror/lint | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { fullWidthCharLinter } from '@tidbcloud/codemirror-extension-linters' | ||
|
||
interface charLinterConfig { | ||
title?: string | ||
message?: string | ||
} | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [ | ||
fullWidthCharLinter({ | ||
title: 'the title when error', | ||
message: 'error content' | ||
}) | ||
] | ||
}) | ||
}) | ||
``` | ||
|
||
```ts | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { useDbLinter } from '@tidbcloud/codemirror-extension-linters' | ||
|
||
type DBLinterOptions = { | ||
level?: 'error' | 'warning' | ||
title?: string | ||
message?: string | ||
whenDisable?: (view: EditorView) => boolean // the linter will be hidden when return false | ||
} | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [ | ||
useDbLinter({ | ||
level: 'warning', | ||
title: 'the title when error', | ||
message: 'error content' | ||
}) | ||
] | ||
}) | ||
}) | ||
``` | ||
|
||
```ts | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { regexMatchLinter } from '@tidbcloud/codemirror-extension-linters' | ||
|
||
interface RegexpItem { | ||
reg: RegExp | ||
title: string | ||
message: string | ||
} | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [ | ||
regexMatchLinter([ | ||
{ | ||
reg: /[a-z]/, | ||
title: 'test reg error', | ||
message: 'test reg error content' | ||
} | ||
]) | ||
] | ||
}) | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
```ts | ||
function fullWidthCharLinter(config?: charLinterConfig): Extension | ||
function useDbLinter(config?: DBLinterOptions): Extension | ||
function regexMatchLinter(config?: RegexpItem[]): Extension | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters