Skip to content

Commit 51948fc

Browse files
committed
feat: refactor code, dynamic bubble, toolbar, fix error
1 parent 849a1cb commit 51948fc

File tree

278 files changed

+9507
-8105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+9507
-8105
lines changed

docs/.vitepress/components/HomePage.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const members = computed(() => [
1818
title: t('Contributor'),
1919
links: [{ icon: 'github', link: 'https://github.com/condorheroblog' }],
2020
},
21+
{
22+
avatar: 'https://github.com/meliora.png',
23+
name: 'Meliora',
24+
title: t('Contributor'),
25+
links: [{ icon: 'github', link: 'https://github.com/meliora' }],
26+
},
2127
]);
2228
</script>
2329

docs/.vitepress/config.ts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,61 +42,61 @@ export default defineConfig({
4242
hostname: docsLink,
4343
},
4444
transformHead,
45-
markdown: {
46-
codeTransformers: [
47-
{
48-
// Render custom themes with codeblocks
49-
name: 'shiki:inline-theme',
50-
preprocess(code, options) {
51-
const reg = /\btheme:([\w,-]+)\b/;
52-
const match = options.meta?.__raw?.match(reg);
53-
if (!match?.[1]) return;
54-
const theme = match[1];
55-
const themes = theme.split(',').map((i) => i.trim());
56-
if (!themes.length) return;
57-
if (themes.length === 1) {
58-
// @ts-expect-error anyway
59-
delete options.themes;
60-
// @ts-expect-error anyway
61-
options.theme = themes[0];
62-
} else if (themes.length === 2) {
63-
// @ts-expect-error anyway
64-
delete options.theme;
65-
// @ts-expect-error anyway
66-
options.themes = {
67-
light: themes[0],
68-
dark: themes[1],
69-
};
70-
} else {
71-
throw new Error(`Only 1 or 2 themes are supported, got ${themes.length}`);
72-
}
73-
return code;
74-
},
75-
},
76-
{
77-
name: 'shiki:inline-decorations',
78-
preprocess(code, options) {
79-
const reg = /^\/\/ @decorations:(.*)\n/;
80-
code = code.replace(reg, (match, decorations) => {
81-
options.decorations ||= [];
82-
options.decorations.push(...JSON.parse(decorations));
83-
return '';
84-
});
85-
return code;
86-
},
87-
},
88-
transformerTwoslash({
89-
// errorRendering: 'hover',
90-
processHoverInfo(info) {
91-
return (
92-
defaultHoverInfoProcessor(info)
93-
// Remove shiki_core namespace
94-
.replace(/_shikijs_core\w*\./g, '')
95-
);
96-
},
97-
}),
98-
transformerRemoveNotationEscape(),
99-
transformerNotationDiff(),
100-
],
101-
},
45+
// markdown: {
46+
// codeTransformers: [
47+
// {
48+
// // Render custom themes with codeblocks
49+
// name: 'shiki:inline-theme',
50+
// preprocess(code, options) {
51+
// const reg = /\btheme:([\w,-]+)\b/;
52+
// const match = options.meta?.__raw?.match(reg);
53+
// if (!match?.[1]) return;
54+
// const theme = match[1];
55+
// const themes = theme.split(',').map((i) => i.trim());
56+
// if (!themes.length) return;
57+
// if (themes.length === 1) {
58+
// // @ts-expect-error anyway
59+
// delete options.themes;
60+
// // @ts-expect-error anyway
61+
// options.theme = themes[0];
62+
// } else if (themes.length === 2) {
63+
// // @ts-expect-error anyway
64+
// delete options.theme;
65+
// // @ts-expect-error anyway
66+
// options.themes = {
67+
// light: themes[0],
68+
// dark: themes[1],
69+
// };
70+
// } else {
71+
// throw new Error(`Only 1 or 2 themes are supported, got ${themes.length}`);
72+
// }
73+
// return code;
74+
// },
75+
// },
76+
// {
77+
// name: 'shiki:inline-decorations',
78+
// preprocess(code, options) {
79+
// const reg = /^\/\/ @decorations:(.*)\n/;
80+
// code = code.replace(reg, (match, decorations) => {
81+
// options.decorations ||= [];
82+
// options.decorations.push(...JSON.parse(decorations));
83+
// return '';
84+
// });
85+
// return code;
86+
// },
87+
// },
88+
// transformerTwoslash({
89+
// // errorRendering: 'hover',
90+
// processHoverInfo(info) {
91+
// return (
92+
// defaultHoverInfoProcessor(info)
93+
// // Remove shiki_core namespace
94+
// .replace(/_shikijs_core\w*\./g, '')
95+
// );
96+
// },
97+
// }),
98+
// transformerRemoveNotationEscape(),
99+
// transformerNotationDiff(),
100+
// ],
101+
// },
102102
});

docs/.vitepress/locale.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ export function getLocaleConfig(lang: string) {
7070
text: t('Bubble Menu'),
7171
link: `${urlPrefix}/guide/bubble-menu`,
7272
},
73-
{
74-
text: t('Customize'),
75-
link: `${urlPrefix}/guide/customize.md`,
76-
},
7773
{
7874
text: t('Internationalization'),
7975
link: `${urlPrefix}/guide/internationalization`,
@@ -85,8 +81,8 @@ export function getLocaleConfig(lang: string) {
8581
items: [
8682

8783
{
88-
text: 'BaseKit',
89-
link: '/extensions/BaseKit/index.md',
84+
text: 'Attachment',
85+
link: '/extensions/Attachment/index.md',
9086
},
9187
{
9288
text: 'Blockquote',
@@ -112,13 +108,17 @@ export function getLocaleConfig(lang: string) {
112108
text: 'CodeBlock',
113109
link: '/extensions/CodeBlock/index.md',
114110
},
111+
{
112+
text: 'CodeView',
113+
link: '/extensions/CodeView/index.md',
114+
},
115115
{
116116
text: 'Color',
117117
link: '/extensions/Color/index.md',
118118
},
119119
{
120-
text: 'Document',
121-
link: '/extensions/Document/index.md',
120+
text: 'Column',
121+
link: '/extensions/Column/index.md',
122122
},
123123
{
124124
text: 'FontFamily',
@@ -288,10 +288,7 @@ export function getLocaleConfig(lang: string) {
288288
text: 'Twitter',
289289
link: '/extensions/Twitter/index.md',
290290
},
291-
{
292-
text: 'Drawer',
293-
link: '/extensions/Drawer/index.md',
294-
},
291+
295292
],
296293
},
297294
];

docs/.vitepress/theme/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Theme from 'vitepress/theme'
2-
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
2+
// import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
33
import type { EnhanceAppContext } from 'vitepress'
44
import './style.css'
55
// import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
6-
import '@shikijs/vitepress-twoslash/style.css'
6+
// import '@shikijs/vitepress-twoslash/style.css'
77
import Contributors from '../components/Contributors.vue'
88
import Changelog from '../components/Changelog.vue'
99
import Layout from './Layout.vue'
@@ -16,6 +16,6 @@ export default {
1616
app.component('Contributors', Contributors)
1717
app.component('Changelog', Changelog)
1818

19-
app.use(TwoslashFloatingVue)
19+
// app.use(TwoslashFloatingVue)
2020
},
2121
}

docs/extensions/Attachment/index.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,75 @@ Attachment is a node extension that allows you to add an Attachment to your edit
1212

1313
## Usage
1414

15+
1516
```tsx
16-
import { Attachment } from 'reactjs-tiptap-editor/attachment'; // [!code ++]
17+
import { RichTextProvider } from 'reactjs-tiptap-editor'
18+
19+
// Base Kit
20+
import { Document } from '@tiptap/extension-document'
21+
import { Text } from '@tiptap/extension-text'
22+
import { Paragraph } from '@tiptap/extension-paragraph'
23+
import { Dropcursor, Gapcursor, Placeholder, TrailingNode } from '@tiptap/extensions'
24+
import { HardBreak } from '@tiptap/extension-hard-break'
25+
import { TextStyle } from '@tiptap/extension-text-style';
26+
import { ListItem } from '@tiptap/extension-list';
27+
28+
// Extension
29+
import { Attachment, RichTextAttachment } from 'reactjs-tiptap-editor/attachment'; // [!code ++]
30+
// ... other extensions
31+
32+
33+
// Import CSS
34+
import 'reactjs-tiptap-editor/style.css';
1735

1836
const extensions = [
19-
...,
37+
// Base Extensions
38+
Document,
39+
Text,
40+
Dropcursor,
41+
Gapcursor,
42+
HardBreak,
43+
Paragraph,
44+
TrailingNode,
45+
ListItem,
46+
TextStyle,
47+
Placeholder.configure({
48+
placeholder: 'Press \'/\' for commands',
49+
})
50+
51+
...
2052
// Import Extensions Here
2153
Attachment.configure({// [!code ++]
2254
upload: (file: any) => {// [!code ++]
2355
// upload file to server return url
2456
},// [!code ++]
2557
}),// [!code ++]
2658
];
59+
60+
const RichTextToolbar = () => {
61+
return (
62+
<div className="flex items-center gap-2 flex-wrap border-b border-solid">
63+
<RichTextAttachment /> {/* [!code ++] */}
64+
</div>
65+
)
66+
}
67+
68+
const App = () => {
69+
const editor = useEditor({
70+
textDirection: 'auto', // global text direction
71+
extensions,
72+
});
73+
74+
return (
75+
<RichTextProvider
76+
editor={editor}
77+
>
78+
<RichTextToolbar />
79+
80+
<EditorContent
81+
editor={editor}
82+
/>
83+
</RichTextProvider>
84+
);
85+
};
2786
```

docs/extensions/BaseKit/index.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/extensions/Blockquote/index.md

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,71 @@ The Blockquote extension allows you to add blockquotes to your editor.
1414

1515
## Usage
1616

17+
1718
```tsx
18-
import { Blockquote } from 'reactjs-tiptap-editor/blockquote'; // [!code ++]
19+
import { RichTextProvider } from 'reactjs-tiptap-editor'
20+
21+
// Base Kit
22+
import { Document } from '@tiptap/extension-document'
23+
import { Text } from '@tiptap/extension-text'
24+
import { Paragraph } from '@tiptap/extension-paragraph'
25+
import { Dropcursor, Gapcursor, Placeholder, TrailingNode } from '@tiptap/extensions'
26+
import { HardBreak } from '@tiptap/extension-hard-break'
27+
import { TextStyle } from '@tiptap/extension-text-style';
28+
import { ListItem } from '@tiptap/extension-list';
29+
30+
// Extension
31+
import { Blockquote, RichTextBlockquote } from 'reactjs-tiptap-editor/blockquote'; // [!code ++]
32+
// ... other extensions
33+
34+
35+
// Import CSS
36+
import 'reactjs-tiptap-editor/style.css';
1937

2038
const extensions = [
21-
...,
39+
// Base Extensions
40+
Document,
41+
Text,
42+
Dropcursor,
43+
Gapcursor,
44+
HardBreak,
45+
Paragraph,
46+
TrailingNode,
47+
ListItem,
48+
TextStyle,
49+
Placeholder.configure({
50+
placeholder: 'Press \'/\' for commands',
51+
})
52+
53+
...
2254
// Import Extensions Here
23-
Blockquote // [!code ++]
55+
Blockquote// [!code ++]
2456
];
25-
```
2657

27-
## Options
58+
const RichTextToolbar = () => {
59+
return (
60+
<div className="flex items-center gap-2 flex-wrap border-b border-solid">
61+
<RichTextBlockquote /> {/* [!code ++] */}
62+
</div>
63+
)
64+
}
2865

29-
### shortcutKeys
66+
const App = () => {
67+
const editor = useEditor({
68+
textDirection: 'auto', // global text direction
69+
extensions,
70+
});
3071

31-
Type: `string[]`\
32-
Default: `['shift', 'mod', 'B']`
72+
return (
73+
<RichTextProvider
74+
editor={editor}
75+
>
76+
<RichTextToolbar />
3377

34-
Keyboard shortcuts for the extension.
78+
<EditorContent
79+
editor={editor}
80+
/>
81+
</RichTextProvider>
82+
);
83+
};
84+
```

0 commit comments

Comments
 (0)