Skip to content

Commit

Permalink
feat: support keymap props to register keymap
Browse files Browse the repository at this point in the history
provide `registerKeymap` and `unregisterKeymap` through `configuratior`

close #52
  • Loading branch information
lastnigtic committed Sep 17, 2021
1 parent 8e10fc5 commit 05c3596
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 141 deletions.
36 changes: 30 additions & 6 deletions docs/en/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,27 +415,51 @@ interface IGetSelectionInfo extends Types.IRangeStatic {
}
```

### TKeymapHandler

```typescript
// https://prosemirror.net/docs/ref/#keymap.keymap,handle keyboard shortcuts
type TKeymapHandler = (
editor: SylApi,
state: EditorState,
dispatch: EditorView['dispatch'],
view: EditorView,
) => boolean;
```

## Configurator

`configurator`是挂载在`SylApi`上的配置对象,可用于配置一些能力.
`Configurator` is a configuration object mounted on `SylApi`, which can be used to configure some capabilities.

### setLocale

`setLocale(locale?: Types.StringMap<any>): boolean | undefined;`

用于设置`locale`对象。
Used to set the `locale` config.

### registerEventHandler

`(event: IEventHandler) => void;`
`(eventHandler: IEventHandler) => void;`

用于配置事件监听。
Used to add event handlers.

### unregisterEventHandler

`(event: IEventHandler) => void;`
`(eventHandler: IEventHandler) => void;`

Used to remove event handlers.

### registerKeymap

`(keymap: Types.StringMap<TKeymapHandler>) => void;`

Used to add keymap handlers.

### unregisterKeymap

`(keymap: Types.StringMap<TKeymapHandler>) => void;`

用于移除事件监听。
Used to remove keymap handlers.

## Event

Expand Down
35 changes: 18 additions & 17 deletions docs/en/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ import { SylEditor } from '@syllepsis/access-react';

## Props

| Name | Type | Description |
| -------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| plugins | `Array<SylPlugin>` | Optional, [`SylPlugin`](/en/plugins/README) instance list |
| module | `Record<string, ModuleMap>` | Optional, extension modules, such as toolbars. Refer to [link](/en/modules/README.md) etc. |
| content | `HTML string` \| `object` | Optional, the default content of the editor |
| getEditor | `function` | Optional, get the editor instance: `(editor: SylApi) => any` |
| placeholder | `string` | Optional, empty content placeholder, accept string or html |
| onFocus | `function` | Optional, editor focus callback |
| onBlur | `function` | Optional, editor defocus callback |
| locale | `object` | Optional, see [Internationalization](/en/others/i18n) |
| keepLastLine | `boolean` | Optional, whether to keep the last blank line, the default is `true` |
| dropCursor | `{ color: string, width: number} \| false` | Optional, when the drag indicator bar style defaults to `color` is `#000000`, `width` is `1`, and the value is `false` Close instructions |
| spellCheck | `boolean` | Optional, whether to enable spell check, the default is `false` |
| autoFocus | `boolean` | Optional, whether to auto focus after the initialization is complete, the default is `false` |
| onError | `() => any` | Optional, error event capture when calling `SylApi`, thrown by default |
| keepWhiteSpace | `full \| undefined` | Optional, whether to fold white space characters, default fold. `full` needs to cooperate with `white-space: pre-wrap;` to take effect. |
| eventHandler | [`IEventHandler`](https://bytedance.github.io/syllepsis/#/en/chapters/syl-plugin?id=controller) | Optional, used to add some event handler. |
| Name | Type | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| plugins | `Array<SylPlugin>` | Optional, [`SylPlugin`](/en/plugins/README) instance list |
| module | `Record<string, ModuleMap>` | Optional, extension modules, such as toolbars. Refer to [link](/en/modules/README.md) etc. |
| content | `HTML string` \| `object` | Optional, the default content of the editor |
| getEditor | `function` | Optional, get the editor instance: `(editor: SylApi) => any` |
| placeholder | `string` | Optional, empty content placeholder, accept string or html |
| onFocus | `function` | Optional, editor focus callback |
| onBlur | `function` | Optional, editor defocus callback |
| locale | `object` | Optional, see [Internationalization](/en/others/i18n) |
| keepLastLine | `boolean` | Optional, whether to keep the last blank line, the default is `true` |
| dropCursor | `{ color: string, width: number} \| false` | Optional, when the drag indicator bar style defaults to `color` is `#000000`, `width` is `1`, and the value is `false` Close instructions |
| spellCheck | `boolean` | Optional, whether to enable spell check, the default is `false` |
| autoFocus | `boolean` | Optional, whether to auto focus after the initialization is complete, the default is `false` |
| onError | `() => any` | Optional, error event capture when calling `SylApi`, thrown by default |
| keepWhiteSpace | `full \| undefined` | Optional, whether to fold white space characters, default fold. `full` needs to cooperate with `white-space: pre-wrap;` to take effect. |
| eventHandler | [`IEventHandler`](https://bytedance.github.io/syllepsis/#/en/chapters/syl-plugin?id=controller) | Optional, used to add some event handler. |
| keymap | [`Record<string, TKeymapHandler>`](https://bytedance.github.io/syllepsis/#/en/chapters/syl-plugin?id=controller) | Optional, used to add keyboard shortcuts handler. |
32 changes: 28 additions & 4 deletions docs/zh-cn/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,27 +414,51 @@ interface IGetSelectionInfo extends Types.IRangeStatic {
}
```

### TKeymapHandler

```typescript
// https://prosemirror.net/docs/ref/#keymap.keymap,处理快捷键
type TKeymapHandler = (
editor: SylApi,
state: EditorState,
dispatch: EditorView['dispatch'],
view: EditorView,
) => boolean;
```

## Configurator

`Configurator` is a configuration object mounted on `SylApi`, which can be used to configure some capabilities.
`configurator`是挂载在`SylApi`上的配置对象,可用于配置一些能力.

### setLocale

`setLocale(locale?: Types.StringMap<any>): boolean | undefined;`

Used to set the `locale` config.
用于设置`locale`对象。

### registerEventHandler

`(event: IEventHandler) => void;`

Used to add event handlers.
用于配置事件监听。

### unregisterEventHandler

`(event: IEventHandler) => void;`

Used to remove event handlers.
用于移除事件监听。

### registerKeymap

`(keymap: Types.StringMap<TKeymapHandler>) => void;`

用于设置快捷键监听。

### unregisterKeymap

`(keymap: Types.StringMap<TKeymapHandler>) => void;`

用于移除快捷键监听。

## Event

Expand Down
35 changes: 18 additions & 17 deletions docs/zh-cn/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ import { SylEditor } from '@syllepsis/access-react';

## Props

| 名称 | 类型 | 说明 |
| -------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| plugins | `Array<SylPlugin>` | 可选,[`SylPlugin`](/zh-cn/plugins/README)实例列表 |
| module | `Record<string, ModuleMap>` | 可选,扩展模块,如工具栏等,详见[链接](/zh-cn/modules/README.md)|
| content | `HTML string` \| `object` | 可选,编辑器默认内容 |
| getEditor | `function` | 可选,获取编辑器实例: `(editor: SylApi) => any` |
| placeholder | `string` | 可选,空内容占位符,接受字符串或 html |
| onFocus | `function` | 可选,编辑器聚焦回调 |
| onBlur | `function` | 可选,编辑器失焦回调 |
| locale | `object` | 可选,详情见[国际化配置](/zh-cn/others/i18n) |
| keepLastLine | `boolean` | 可选,是否保留最后一行空行,默认为`true` |
| dropCursor | `{ color: string, width: number } \| false` | 可选,拖拽指示条样式默认`color``#000000``width``1`,值为`false`时关闭指示 |
| spellCheck | `boolean` | 可选,是否开启拼写检查,默认为`false` |
| autoFocus | `boolean` | 可选,是否在初始化完成后自动聚焦,默认为`false` |
| onError | `() => any` | 可选,调用`SylApi`时的错误事件捕获,默认抛出 |
| keepWhiteSpace | `full \| undefined` | 可选,是否折叠空白字符,默认折叠。`full`需要配合`white-space: pre-wrap;`生效。 |
| eventHandler | [`IEventHandler`](https://bytedance.github.io/syllepsis/#/zh-cn/chapters/syl-plugin?id=controller) | 可选,用于配置事件处理函数. |
| 名称 | 类型 | 说明 |
| -------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| plugins | `Array<SylPlugin>` | 可选,[`SylPlugin`](/zh-cn/plugins/README)实例列表 |
| module | `Record<string, ModuleMap>` | 可选,扩展模块,如工具栏等,详见[链接](/zh-cn/modules/README.md)|
| content | `HTML string` \| `object` | 可选,编辑器默认内容 |
| getEditor | `function` | 可选,获取编辑器实例: `(editor: SylApi) => any` |
| placeholder | `string` | 可选,空内容占位符,接受字符串或 html |
| onFocus | `function` | 可选,编辑器聚焦回调 |
| onBlur | `function` | 可选,编辑器失焦回调 |
| locale | `object` | 可选,详情见[国际化配置](/zh-cn/others/i18n) |
| keepLastLine | `boolean` | 可选,是否保留最后一行空行,默认为`true` |
| dropCursor | `{ color: string, width: number } \| false` | 可选,拖拽指示条样式默认`color``#000000``width``1`,值为`false`时关闭指示 |
| spellCheck | `boolean` | 可选,是否开启拼写检查,默认为`false` |
| autoFocus | `boolean` | 可选,是否在初始化完成后自动聚焦,默认为`false` |
| onError | `() => any` | 可选,调用`SylApi`时的错误事件捕获,默认抛出 |
| keepWhiteSpace | `full \| undefined` | 可选,是否折叠空白字符,默认折叠。`full`需要配合`white-space: pre-wrap;`生效。 |
| eventHandler | [`IEventHandler`](https://bytedance.github.io/syllepsis/#/zh-cn/chapters/syl-plugin?id=controller) | 可选,用于配置事件处理函数。 |
| keymap | [`Record<string, TKeymapHandler>`](https://bytedance.github.io/syllepsis/#/zh-cn/chapters/syl-plugin?id=controller) | 可选,用于设置`keymap`(快捷键)处理函数。 |
Loading

0 comments on commit 05c3596

Please sign in to comment.