Skip to content

Commit

Permalink
Merge pull request #14 from tidbcloud/chore/rename-extension-package-…
Browse files Browse the repository at this point in the history
…name

chore: rename extensions package name
  • Loading branch information
baurine authored Jun 25, 2024
2 parents 898390b + c457d0b commit 33cb15d
Show file tree
Hide file tree
Showing 30 changed files with 190 additions and 171 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ TiSQLEditor is a CodeMirror6 based SQL code editor which is used in TiDB Cloud C

## Packages

- @tidbcloud/tisqleditor
- @tidbcloud/tisqleditor - SQLEditorInstance with pre-configured extensions
- @tidbcloud/tisqleditor-react - React component wrapper
- @tidbcloud/tisqleditor-extension-sql-parser
- @tidbcloud/tisqleditor-extension-cur-sql
- @tidbcloud/tisqleditor-extension-cur-sql-gutter
- @tidbcloud/tisqleditor-extension-save-helper
- @tidbcloud/tisqleditor-extension-autocomplete
- @tidbcloud/tisqleditor-extension-linters
- @tidbcloud/tisqleditor-extension-events
- @tidbcloud/tisqleditor-extension-themes - 2 simple builtin theme, `bbedit` for light mode, `oneDark` for dark mode
- @tidbcloud/tisqleditor-extension-basic-setup
- @tidbcloud/codemirror-extension-sql-parser - parse the editor content to SQL statements
- @tidbcloud/codemirror-extension-cur-sql - get the selected SQL statements
- @tidbcloud/codemirror-extension-cur-sql-gutter - show gutter for the selected SQL statements
- @tidbcloud/codemirror-extension-save-helper - save the editor content if it changes
- @tidbcloud/codemirror-extension-autocomplete
- @tidbcloud/codemirror-extension-linters
- @tidbcloud/codemirror-extension-events
- @tidbcloud/codemirror-extension-themes - 2 simple builtin themes, `bbedit` for light mode, `oneDark` for dark mode
- @tidbcloud/codemirror-extension-basic-setup

## Usage

See [editor.tsx](./packages/playground/src/components/biz/editor-panel/editor.tsx) to get more details.

```tsx
import { SQLEditor } from '@tidbcloud/tisqleditor-react'
import { saveHelper } from '@tidbcloud/tisqleditor-extension-save-helper'
import { bbedit, oneDark } from '@tidbcloud/tisqleditor-extension-themes'
import { curSqlGutter } from '@tidbcloud/tisqleditor-extension-cur-sql-gutter'
import { saveHelper } from '@tidbcloud/codemirror-extension-save-helper'
import { bbedit, oneDark } from '@tidbcloud/codemirror-extension-themes'
import { curSqlGutter } from '@tidbcloud/codemirror-extension-cur-sql-gutter'
import {
useDbLinter,
fullWidthCharLinter
} from '@tidbcloud/tisqleditor-extension-linters'
import { autoCompletion } from '@tidbcloud/tisqleditor-extension-autocomplete'
} from '@tidbcloud/codemirror-extension-linters'
import { autoCompletion } from '@tidbcloud/codemirror-extension-autocomplete'

export function Editor() {
const {
Expand Down
78 changes: 43 additions & 35 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ npm install @codemirror/view @codemirror/state @codemirror/lang-sql @codemirror/

## Usage

```js
```ts
import { EditorCache, createSQLEditorInstance } from '@tidbcloud/tisqleditor'

const cache = new EditorCache()
Expand All @@ -37,52 +37,60 @@ cache.addEditor(editorId, editorInst)

### createSQLEditorInstance

```js
```ts
type CreateSQLEditorOptions = {
editorId: string;
doc: string;

basicSetupOptions?: BasicSetupOptions;
sqlConfig?: SQLConfig;
theme?: Extension;
extraExts?: Extension;
extraData?: {};
};
editorId: string
doc: string

basicSetupOptions?: BasicSetupOptions
sqlConfig?: SQLConfig
theme?: Extension
extraExts?: Extension
extraData?: {}
}

const createSQLEditorInstance: (options: CreateSQLEditorOptions) => SQLEditorInstance;
const createSQLEditorInstance: (
options: CreateSQLEditorOptions
) => SQLEditorInstance
```
### SQLEditorInstance
```js
```ts
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;
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
```ts
class EditorCache {
addEditor: (editorId: string, editor: SQLEditorInstance) => void;
getEditor: (editorId: string) => SQLEditorInstance | undefined;
deleteEditor: (editorId: string) => void;
clearEditors: () => void;
addEditor: (editorId: string, editor: SQLEditorInstance) => void
getEditor: (editorId: string) => SQLEditorInstance | undefined
deleteEditor: (editorId: string) => void
clearEditors: () => void
}
```
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@codemirror/view": "^6.26.3"
},
"dependencies": {
"@tidbcloud/tisqleditor-extension-basic-setup": "workspace:^",
"@tidbcloud/tisqleditor-extension-cur-sql": "workspace:^",
"@tidbcloud/tisqleditor-extension-sql-parser": "workspace:^"
"@tidbcloud/codemirror-extension-basic-setup": "workspace:^",
"@tidbcloud/codemirror-extension-cur-sql": "workspace:^",
"@tidbcloud/codemirror-extension-sql-parser": "workspace:^"
}
}
6 changes: 3 additions & 3 deletions packages/core/src/editor-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { search } from '@codemirror/search'
import {
BasicSetupOptions,
basicSetup
} from '@tidbcloud/tisqleditor-extension-basic-setup'
} from '@tidbcloud/codemirror-extension-basic-setup'
import {
sqlParser,
getSqlStatements,
getNearbyStatement
} from '@tidbcloud/tisqleditor-extension-sql-parser'
} from '@tidbcloud/codemirror-extension-sql-parser'
import {
curSql,
getCurStatements
} from '@tidbcloud/tisqleditor-extension-cur-sql'
} from '@tidbcloud/codemirror-extension-cur-sql'

const langSql = (config: SQLConfig) =>
sql({
Expand Down
8 changes: 4 additions & 4 deletions packages/extensions/autocomplete/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# @tidbcloud/tisqleditor-extension-autocomplete
# @tidbcloud/codemirror-extension-autocomplete

// TODO: desc

## Installation

```shell
npm install @tidbcloud/tisqleditor-extension-autocomplete
npm install @tidbcloud/codemirror-extension-autocomplete
```

You need to install its peer dependencies as well:
Expand All @@ -16,10 +16,10 @@ npm install @codemirror/view @codemirror/state @codemirror/autocomplete @codemir

## Usage

```js
```ts
import { EditorView } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import { autoCompletion } from '@tidbcloud/tisqleditor-extension-autocomplete'
import { autoCompletion } from '@tidbcloud/codemirror-extension-autocomplete'

const editorView = new EditorView({
state: EditorState.create({
Expand Down
2 changes: 1 addition & 1 deletion packages/extensions/autocomplete/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tidbcloud/tisqleditor-extension-autocomplete",
"name": "@tidbcloud/codemirror-extension-autocomplete",
"version": "0.0.1",
"description": "tisqleditor extensions",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/extensions/basic-setup/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tidbcloud/tisqleditor-extension-basic-setup",
"name": "@tidbcloud/codemirror-extension-basic-setup",
"version": "0.0.1",
"description": "tisqleditor extensions",
"type": "module",
Expand Down
28 changes: 14 additions & 14 deletions packages/extensions/cur-sql-gutter/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# @tidbcloud/tisqleditor-extension-cur-sql-gutter
# @tidbcloud/codemirror-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
npm install @tidbcloud/codemirror-extension-cur-sql-gutter
```

You need to install its peer dependencies as well:
Expand All @@ -16,10 +16,10 @@ npm install @codemirror/view @codemirror/state

## Usage

```js
```ts
import { EditorView } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import { curSqlGutter } from '@tidbcloud/tisqleditor-extension-cur-sql-gutter'
import { curSqlGutter } from '@tidbcloud/codemirror-extension-cur-sql-gutter'

const editorView = new EditorView({
state: EditorState.create({
Expand All @@ -31,20 +31,20 @@ const editorView = new EditorView({

## API

```js
```ts
interface CurSqlGutterConfig {
// gutter background
backgroundColor?: string;
/* gutter background */
backgroundColor?: string

// gutter width
width?: number;
/* gutter width */
width?: number

// gutter extra css class
className?: string;
/* gutter extra css class */
className?: string

// control gutter to hide when some cases happen
whenHide?: (view: EditorView) => boolean;
/* control gutter to hide when some cases happen */
whenHide?: (view: EditorView) => boolean
}

const curSqlGutter: (config?: CurSqlGutterConfig) => Extension;
function curSqlGutter(config?: CurSqlGutterConfig): Extension
```
6 changes: 3 additions & 3 deletions packages/extensions/cur-sql-gutter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tidbcloud/tisqleditor-extension-cur-sql-gutter",
"name": "@tidbcloud/codemirror-extension-cur-sql-gutter",
"version": "0.0.1",
"description": "tisqleditor extensions",
"type": "module",
Expand Down Expand Up @@ -40,7 +40,7 @@
"@codemirror/view": "^6.26.3"
},
"dependencies": {
"@tidbcloud/tisqleditor-extension-sql-parser": "workspace:^",
"@tidbcloud/tisqleditor-extension-cur-sql": "workspace:^"
"@tidbcloud/codemirror-extension-sql-parser": "workspace:^",
"@tidbcloud/codemirror-extension-cur-sql": "workspace:^"
}
}
4 changes: 2 additions & 2 deletions packages/extensions/cur-sql-gutter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RangeSet } from '@codemirror/state'
import { EditorView, gutter, GutterMarker } from '@codemirror/view'
import { getCurStatements } from '@tidbcloud/tisqleditor-extension-cur-sql'
import { getNearbyStatement } from '@tidbcloud/tisqleditor-extension-sql-parser'
import { getCurStatements } from '@tidbcloud/codemirror-extension-cur-sql'
import { getNearbyStatement } from '@tidbcloud/codemirror-extension-sql-parser'

export interface CurSqlGutterConfig {
backgroundColor?: string
Expand Down
16 changes: 8 additions & 8 deletions packages/extensions/cur-sql/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @tidbcloud/tisqleditor-extension-cur-sql
# @tidbcloud/codemirror-extension-cur-sql

This extension listens the editor selection change, return the selected statements.

Expand All @@ -7,7 +7,7 @@ This extension is installed internally inside the `SQLEditorInstance`.
## Installation

```shell
npm install @tidbcloud/tisqleditor-extension-cur-sql
npm install @tidbcloud/codemirror-extension-cur-sql
```

You need to install its peer dependencies as well:
Expand All @@ -18,10 +18,10 @@ npm install @codemirror/view @codemirror/state

## Usage

```js
```ts
import { EditorView } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import { curSql } from '@tidbcloud/tisqleditor-extension-cur-sql'
import { curSql } from '@tidbcloud/codemirror-extension-cur-sql'

const editorView = new EditorView({
state: EditorState.create({
Expand All @@ -33,9 +33,9 @@ const editorView = new EditorView({

## API

```js
function curSql(): Extension;

```ts
/* get selected statements */
function getCurStatements(state: EditorState): SqlStatement[];
function getCurStatements(state: EditorState): SqlStatement[]

function curSql(): Extension
```
4 changes: 2 additions & 2 deletions packages/extensions/cur-sql/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tidbcloud/tisqleditor-extension-cur-sql",
"name": "@tidbcloud/codemirror-extension-cur-sql",
"version": "0.0.1",
"description": "tisqleditor extensions",
"type": "module",
Expand Down Expand Up @@ -40,6 +40,6 @@
"@codemirror/view": "^6.26.3"
},
"dependencies": {
"@tidbcloud/tisqleditor-extension-sql-parser": "workspace:^"
"@tidbcloud/codemirror-extension-sql-parser": "workspace:^"
}
}
2 changes: 1 addition & 1 deletion packages/extensions/cur-sql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EditorView, ViewUpdate } from '@codemirror/view'
import {
SqlStatement,
getSqlStatements
} from '@tidbcloud/tisqleditor-extension-sql-parser'
} from '@tidbcloud/codemirror-extension-sql-parser'

// state effect
const curStatementsEffect = StateEffect.define<SqlStatement[]>()
Expand Down
6 changes: 3 additions & 3 deletions packages/extensions/events/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tidbcloud/tisqleditor-extension-events",
"name": "@tidbcloud/codemirror-extension-events",
"version": "0.0.1",
"description": "tisqleditor extensions",
"type": "module",
Expand Down Expand Up @@ -38,7 +38,7 @@
"@codemirror/view": "^6.26.3"
},
"dependencies": {
"@tidbcloud/tisqleditor-extension-cur-sql": "workspace:^",
"@tidbcloud/tisqleditor-extension-sql-parser": "workspace:^"
"@tidbcloud/codemirror-extension-cur-sql": "workspace:^",
"@tidbcloud/codemirror-extension-sql-parser": "workspace:^"
}
}
Loading

0 comments on commit 33cb15d

Please sign in to comment.