-
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 #12 from tidbcloud/doc
doc: add READMEs
- Loading branch information
Showing
17 changed files
with
610 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 PingCAP | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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 |
---|---|---|
@@ -1 +1,88 @@ | ||
# @tidbcloud/tisqleditor | ||
|
||
This package provides the `SQLEditorInstance` and `EditorCache` implementation. | ||
|
||
`SQLEditorInstance` creates EditorView instance with pre-configured extensions to make it available to edit SQL code. | ||
|
||
`EditorCache` stores the `SQLEditorInstance` in a map. | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/tisqleditor | ||
``` | ||
|
||
You need to install its peer dependencies as well. | ||
|
||
```shell | ||
npm install @codemirror/view @codemirror/state @codemirror/lang-sql @codemirror/language @codemirror/search | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import { EditorCache, createSQLEditorInstance } from '@tidbcloud/tisqleditor' | ||
|
||
const cache = new EditorCache() | ||
const editorId = '1' | ||
const editorInst = createSQLEditorInstance({ | ||
editorId, | ||
doc: 'select * from test;' | ||
}) | ||
|
||
cache.addEditor(editorId, editorInst) | ||
``` | ||
|
||
## API | ||
|
||
### createSQLEditorInstance | ||
|
||
```js | ||
type CreateSQLEditorOptions = { | ||
editorId: string; | ||
doc: string; | ||
|
||
basicSetupOptions?: BasicSetupOptions; | ||
sqlConfig?: SQLConfig; | ||
theme?: Extension; | ||
extraExts?: Extension; | ||
extraData?: {}; | ||
}; | ||
|
||
const createSQLEditorInstance: (options: CreateSQLEditorOptions) => SQLEditorInstance; | ||
``` | ||
|
||
### SQLEditorInstance | ||
|
||
```js | ||
class SQLEditorInstance { | ||
editorId: string; | ||
editorView: EditorView; | ||
themeCompartment: Compartment; | ||
sqlCompartment: Compartment; | ||
extraData: {}; | ||
|
||
constructor(editorId: string, editorView: EditorView, themeCompartment: Compartment, sqlCompartment: Compartment, extraData: {}); | ||
|
||
changeTheme(theme: Extension): void; | ||
changeSQLConfig(sqlConfig: SQLConfig): void; | ||
|
||
/* get all statements */ | ||
getAllStatements(): SqlStatement[]; | ||
/* get selected statements */ | ||
getCurStatements(): SqlStatement[]; | ||
/* get the nearest statement before the cursor */ | ||
getNearbyStatement(): SqlStatement | undefined; | ||
} | ||
``` | ||
### EditorCache | ||
```js | ||
class EditorCache { | ||
addEditor: (editorId: string, editor: SQLEditorInstance) => void; | ||
getEditor: (editorId: string) => SQLEditorInstance | undefined; | ||
deleteEditor: (editorId: string) => void; | ||
clearEditors: () => void; | ||
} | ||
``` |
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,34 @@ | ||
# @tidbcloud/tisqleditor-extension-autocomplete | ||
|
||
// TODO: desc | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/tisqleditor-extension-autocomplete | ||
``` | ||
|
||
You need to install its peer dependencies as well: | ||
|
||
```shell | ||
npm install @codemirror/view @codemirror/state @codemirror/autocomplete @codemirror/commands | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { autoCompletion } from '@tidbcloud/tisqleditor-extension-autocomplete' | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [autoCompletion()] | ||
}) | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
// TODO |
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,50 @@ | ||
# @tidbcloud/tisqleditor-extension-cur-sql-gutter | ||
|
||
This extension listens the editor selection change, and shows gutter for the selected statements to make it highlight. | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/tisqleditor-extension-cur-sql-gutter | ||
``` | ||
|
||
You need to install its peer dependencies as well: | ||
|
||
```shell | ||
npm install @codemirror/view @codemirror/state | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { curSqlGutter } from '@tidbcloud/tisqleditor-extension-cur-sql-gutter' | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [curSqlGutter()] | ||
}) | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
```js | ||
interface CurSqlGutterConfig { | ||
// gutter background | ||
backgroundColor?: string; | ||
|
||
// gutter width | ||
width?: number; | ||
|
||
// gutter extra css class | ||
className?: string; | ||
|
||
// control gutter to hide when some cases happen | ||
whenHide?: (view: EditorView) => boolean; | ||
} | ||
|
||
const curSqlGutter: (config?: CurSqlGutterConfig) => 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,41 @@ | ||
# @tidbcloud/tisqleditor-extension-cur-sql | ||
|
||
This extension listens the editor selection change, return the selected statements. | ||
|
||
This extension is installed internally inside the `SQLEditorInstance`. | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install @tidbcloud/tisqleditor-extension-cur-sql | ||
``` | ||
|
||
You need to install its peer dependencies as well: | ||
|
||
```shell | ||
npm install @codemirror/view @codemirror/state | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import { EditorView } from '@codemirror/view' | ||
import { EditorState } from '@codemirror/state' | ||
import { curSql } from '@tidbcloud/tisqleditor-extension-cur-sql' | ||
|
||
const editorView = new EditorView({ | ||
state: EditorState.create({ | ||
doc, | ||
extensions: [curSql()] | ||
}) | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
```js | ||
function curSql(): Extension; | ||
|
||
/* get selected statements */ | ||
function getCurStatements(state: EditorState): SqlStatement[]; | ||
``` |
Oops, something went wrong.