Skip to content

Commit cb3c1d8

Browse files
committed
wip: docs
1 parent 148fac5 commit cb3c1d8

File tree

5 files changed

+101
-7
lines changed

5 files changed

+101
-7
lines changed

apps/site/docs/guide/plugins/_meta.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"code-block-plugin/index",
55
"commands-plugin/index",
66
"dnd-plugin/index",
7-
"floating-menu-plugin/index"
7+
"floating-menu-plugin/index",
8+
"headings-plugin/index",
9+
"highlights-plugin/index"
810
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: HeadingsPlugin
3+
---
4+
5+
## Description
6+
7+
Adds three levels of headings to the editor.
8+
9+
10+
## Usage
11+
### Example
12+
```tsx
13+
import { KonaEditor, HeadingsPlugin } from "@kona/editor";
14+
15+
const headingsPlugin = new HeadingsPlugin();
16+
17+
return (
18+
<KonaEditor
19+
plugins={[headingsPlugin]}
20+
/>
21+
)
22+
```
23+
24+
## Static methods
25+
You can check if a heading is active or toggle it with static methods of this plugin
26+
27+
### `HeadingsPlugin.isHeading1Active()`
28+
### `HeadingsPlugin.isHeading2Active()`
29+
### `HeadingsPlugin.isHeading3Active()`
30+
31+
Checks if the current node is a heading of this level.
32+
33+
### `HeadingsPlugin.toggleHeading1()`
34+
### `HeadingsPlugin.toggleHeading2()`
35+
### `HeadingsPlugin.toggleHeading3()`
36+
37+
Converts the current node to the heading of this level.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: HighlightsPlugin
3+
---
4+
5+
## Description
6+
7+
Allows highlighting the text with a set of pre-defined colors;
8+
9+
10+
## Usage
11+
### Example
12+
```tsx
13+
import { KonaEditor, HighlightsPlugin } from "@kona/editor";
14+
15+
export enum Color {
16+
Red = 'red',
17+
Blue = 'blue',
18+
Yellow = 'yellow',
19+
}
20+
21+
export const colors = {
22+
[Color.Red]: '#ff000055',
23+
[Color.Blue]: '#0000ff55',
24+
[Color.Yellow]: '#ffff0055',
25+
};
26+
27+
28+
const highlightsPlugin = new HighlightsPlugin({
29+
color,
30+
});
31+
32+
return (
33+
<KonaEditor
34+
plugins={[highlightsPlugin]}
35+
/>
36+
)
37+
```
38+
39+
## Static methods
40+
41+
42+
### `HighlightsPlugin.isHighlightActive(editor, color)`
43+
Returns true if the currently selected text is highlighted with this particular color.
44+
45+
### `HighlightsPlugin.toggleHighlight(editor, color)`
46+
Highlights the selected text with this color.

apps/site/rspress.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export default defineConfig({
5757
{
5858
text: 'FloatingMenuPlugin',
5959
link: '/guide/plugins/floating-menu-plugin',
60+
},
61+
{
62+
text: 'HeadingsPlugin',
63+
link: '/guide/plugins/headings-plugin',
64+
},
65+
{
66+
text: 'HighlightsPlugin',
67+
link: '/guide/plugins/highlights-plugin',
6068
}
6169
]
6270
}

packages/editor/src/plugins/HeadingsPlugin/HeadingsPlugin.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { IPlugin } from '../../types';
2-
import { RenderElementProps } from 'slate-react';
31
import { Editor, Element, Transforms } from 'slate';
2+
import { RenderElementProps } from 'slate-react';
3+
import { IPlugin } from '../../types';
44

55
export class HeadingsPlugin implements IPlugin {
66
static HeadingLevel1 = 'h1';
@@ -46,15 +46,15 @@ export class HeadingsPlugin implements IPlugin {
4646
}
4747

4848
static toggleHeading1(editor: Editor) {
49-
this.toggleHeading(editor, HeadingsPlugin.HeadingLevel1);
49+
HeadingsPlugin.toggleHeading(editor, HeadingsPlugin.HeadingLevel1);
5050
}
5151

5252
static toggleHeading2(editor: Editor) {
53-
this.toggleHeading(editor, HeadingsPlugin.HeadingLevel2);
53+
HeadingsPlugin.toggleHeading(editor, HeadingsPlugin.HeadingLevel2);
5454
}
5555

5656
static toggleHeading3(editor: Editor) {
57-
this.toggleHeading(editor, HeadingsPlugin.HeadingLevel3);
57+
HeadingsPlugin.toggleHeading(editor, HeadingsPlugin.HeadingLevel3);
5858
}
5959
}
6060

@@ -66,7 +66,8 @@ const isBlockActive = (editor, type) => {
6666
const [match] = Array.from(
6767
Editor.nodes(editor, {
6868
at: Editor.unhangRange(editor, selection),
69-
match: (node) => !Editor.isEditor(node) && Element.isElement(node) && node.type === type,
69+
match: (node) =>
70+
!Editor.isEditor(node) && Element.isElement(node) && node.type === type,
7071
}),
7172
);
7273

0 commit comments

Comments
 (0)