kc-plate-editor 0.0.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +162 -9
  2. package/dist/components/editor/plate-editor.d.ts +10 -0
  3. package/dist/components/editor/plugins/block-placeholder-kit.d.ts +14 -0
  4. package/dist/components/editor/plugins/configurable-toolbar-kit.d.ts +5 -0
  5. package/dist/components/editor/plugins/responsive-toolbar-kit.d.ts +1 -0
  6. package/dist/components/editor/use-chat.d.ts +1 -1
  7. package/dist/components/ui/configurable-toolbar.d.ts +5 -0
  8. package/dist/components/ui/responsive-toolbar-buttons.d.ts +1 -0
  9. package/dist/components/ui/turn-into-toolbar-button.d.ts +0 -11
  10. package/dist/hooks/use-file-upload.d.ts +20 -0
  11. package/dist/hooks/use-media-query.d.ts +4 -0
  12. package/dist/{index-BK_chGlb.js → index-BUIarKlp.js} +1 -1
  13. package/dist/{index-BJkTV5_G.mjs → index-C6rL9ZQM.mjs} +1 -1
  14. package/dist/{index-CorI7Cc4.js → index-CP58iz5v.js} +333 -342
  15. package/dist/{index-CD4hikbu.mjs → index-Neyiy2eB.mjs} +38005 -38119
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.ts +17 -1
  18. package/dist/index.mjs +36 -10
  19. package/dist/lib/config-generator.d.ts +25 -0
  20. package/dist/lib/config-provider.d.ts +2 -0
  21. package/dist/lib/html-utils.d.ts +21 -0
  22. package/dist/lib/i18n-provider.d.ts +17 -0
  23. package/dist/lib/toolbar-features.d.ts +45 -0
  24. package/dist/locales/en-US.d.ts +369 -0
  25. package/dist/locales/index.d.ts +743 -0
  26. package/dist/locales/zh-CN.d.ts +369 -0
  27. package/dist/pages/Configurator.d.ts +1 -0
  28. package/dist/pages/Examples.d.ts +1 -0
  29. package/dist/style.css +1 -1
  30. package/dist/types/toolbar-config.d.ts +30 -0
  31. package/package.json +1 -3
  32. package/dist/hooks/use-upload-file.d.ts +0 -19
  33. package/dist/lib/uploadthing.d.ts +0 -3
package/README.md CHANGED
@@ -10,6 +10,10 @@ A powerful and customizable rich text editor built on [Plate](https://platejs.or
10
10
  - 📝 **Markdown Support**: Import/export markdown content
11
11
  - 🎭 **Media Support**: Images, videos, and embeds
12
12
  - 💬 **Collaboration**: Comments and suggestions
13
+ - 🌐 **Internationalization**: Built-in i18n support (English & Chinese)
14
+ - 📱 **Responsive**: Adaptive toolbar for mobile and desktop
15
+ - ⚙️ **Configurable Toolbar**: Flexible toolbar configuration system with visual configurator
16
+ - 🔌 **Extended API**: Markdown/HTML import/export, text extraction
13
17
  - 🎨 **Customizable**: Extensive plugin system and theming support
14
18
  - 📦 **TypeScript**: Full TypeScript support with type definitions
15
19
  - ⚡ **Modern Stack**: Built with React 19, Vite, and Tailwind CSS
@@ -65,6 +69,7 @@ import { PlateEditor, ConfigProvider } from 'kc-plate-editor';
65
69
  import 'kc-plate-editor/styles.css';
66
70
 
67
71
  const editorConfig = {
72
+ locale: 'zh-CN', // or 'en-US'
68
73
  aiApiUrl: '/api/ai/copilot',
69
74
  uploadApiUrl: '/api/upload',
70
75
  baseURL: 'https://your-api.com',
@@ -79,6 +84,72 @@ function App() {
79
84
  }
80
85
  ```
81
86
 
87
+ ### Configurable Toolbar
88
+
89
+ Configure exactly which toolbar features you need:
90
+
91
+ ```tsx
92
+ import { PlateEditor, createMinimalConfig, createFullConfig } from 'kc-plate-editor';
93
+ import type { ToolbarConfig } from 'kc-plate-editor';
94
+
95
+ function App() {
96
+ // Minimal configuration
97
+ const minimalConfig: ToolbarConfig = {
98
+ history: true,
99
+ textFormat: ['bold', 'italic', 'underline'],
100
+ insert: ['link'],
101
+ };
102
+
103
+ // Comment editor configuration
104
+ const commentConfig: ToolbarConfig = {
105
+ history: true,
106
+ textFormat: ['bold', 'italic'],
107
+ insert: ['link', 'emoji'],
108
+ };
109
+
110
+ // Full configuration (all features)
111
+ const fullConfig = createFullConfig();
112
+
113
+ return (
114
+ <>
115
+ {/* Minimal editor */}
116
+ <PlateEditor toolbarConfig={minimalConfig} />
117
+
118
+ {/* Comment editor */}
119
+ <PlateEditor toolbarConfig={commentConfig} />
120
+
121
+ {/* Full featured editor */}
122
+ <PlateEditor toolbarConfig={fullConfig} />
123
+
124
+ {/* Default editor (all features) */}
125
+ <PlateEditor />
126
+ </>
127
+ );
128
+ }
129
+ ```
130
+
131
+ ### Visual Toolbar Configurator
132
+
133
+ Use the visual configurator to build your toolbar configuration:
134
+
135
+ 1. Visit `/configurator` in the playground
136
+ 2. Select the features you need
137
+ 3. Preview the editor in real-time
138
+ 4. Copy the generated configuration code
139
+ 5. Paste into your project
140
+
141
+ Available feature groups:
142
+ - **history**: Undo, Redo
143
+ - **textFormat**: Bold, Italic, Underline, Strikethrough, Code
144
+ - **color**: Text Color, Background Color, Highlight
145
+ - **align**: Left, Center, Right, Justify
146
+ - **list**: Bulleted List, Numbered List, Todo List
147
+ - **insert**: Link, Image, Video, Table, Emoji, Equation
148
+ - **advanced**: AI, Comment, Export, Import
149
+ - **typography**: Font Size, Line Height
150
+ - **extraFormat**: Superscript, Subscript, Keyboard
151
+ - **blockOps**: Indent, Outdent, Toggle
152
+
82
153
  ### Controlled Mode
83
154
 
84
155
  ```tsx
@@ -110,20 +181,73 @@ function App() {
110
181
  |------|------|---------|-------------|
111
182
  | value | Value | - | Editor content (controlled) |
112
183
  | onChange | (value: Value) => void | - | Content change callback |
113
- | plugins | any[] | EditorKit | Custom plugin list |
184
+ | plugins | any[] | - | Custom plugin list |
185
+ | toolbarConfig | ToolbarConfig | - | Toolbar configuration (see below) |
114
186
  | className | string | - | Custom CSS class |
115
187
  | disabled | boolean | false | Disable editor |
116
188
  | readOnly | boolean | false | Read-only mode |
117
189
  | autoFocus | boolean | false | Auto focus on mount |
118
190
 
191
+ ### ToolbarConfig
192
+
193
+ ```typescript
194
+ interface ToolbarConfig {
195
+ history?: boolean | ('undo' | 'redo')[];
196
+ textFormat?: boolean | ('bold' | 'italic' | 'underline' | 'strikethrough' | 'code')[];
197
+ color?: boolean | ('textColor' | 'backgroundColor' | 'highlight')[];
198
+ align?: boolean | ('left' | 'center' | 'right' | 'justify')[];
199
+ list?: boolean | ('bulleted' | 'numbered' | 'todo')[];
200
+ insert?: boolean | ('link' | 'image' | 'video' | 'table' | 'emoji' | 'equation')[];
201
+ advanced?: boolean | ('ai' | 'comment' | 'export' | 'import')[];
202
+ typography?: boolean | ('fontSize' | 'lineHeight')[];
203
+ extraFormat?: boolean | ('superscript' | 'subscript' | 'keyboard')[];
204
+ blockOps?: boolean | ('indent' | 'outdent' | 'toggle')[];
205
+ }
206
+ ```
207
+
208
+ **Examples:**
209
+
210
+ ```typescript
211
+ // All text formatting features
212
+ { textFormat: true }
213
+
214
+ // Only bold and italic
215
+ { textFormat: ['bold', 'italic'] }
216
+
217
+ // Multiple groups
218
+ {
219
+ history: true,
220
+ textFormat: ['bold', 'italic', 'underline'],
221
+ insert: ['link', 'image'],
222
+ list: true
223
+ }
224
+ ```
225
+
119
226
  ### PlateEditorRef Methods
120
227
 
121
228
  ```typescript
122
229
  interface PlateEditorRef {
123
- getContent: () => Value; // Get editor content
230
+ // Content management
231
+ getContent: () => Value; // Get editor content (JSON)
124
232
  setContent: (content: Value) => void; // Set editor content
125
233
  resetContent: () => void; // Reset to initial content
126
234
  getEditor: () => any; // Get editor instance (advanced)
235
+
236
+ // Markdown support
237
+ getMarkdown: () => string; // Export as Markdown
238
+ setMarkdown: (markdown: string) => void; // Load from Markdown
239
+
240
+ // HTML support
241
+ getHtml: () => Promise<string>; // Export as HTML
242
+ setHtml: (html: string) => void; // Load from HTML
243
+
244
+ // Text utilities
245
+ getText: () => string; // Get plain text
246
+ isEmpty: () => boolean; // Check if empty
247
+
248
+ // Editor control
249
+ focus: () => void; // Focus editor
250
+ blur: () => void; // Blur editor
127
251
  }
128
252
  ```
129
253
 
@@ -131,12 +255,13 @@ interface PlateEditorRef {
131
255
 
132
256
  ```typescript
133
257
  interface EditorConfig {
134
- aiApiUrl?: string; // AI API endpoint
135
- aiApiKey?: string; // AI API key
136
- uploadApiUrl?: string; // Upload API endpoint
137
- uploadToken?: string; // Upload token
138
- authorization?: string; // Authorization header
139
- baseURL?: string; // Base URL for API calls
258
+ locale?: 'zh-CN' | 'en-US'; // UI language
259
+ aiApiUrl?: string; // AI API endpoint
260
+ aiApiKey?: string; // AI API key
261
+ uploadApiUrl?: string; // Upload API endpoint
262
+ uploadToken?: string; // Upload token
263
+ authorization?: string; // Authorization header
264
+ baseURL?: string; // Base URL for API calls
140
265
  }
141
266
  ```
142
267
 
@@ -170,7 +295,8 @@ function App() {
170
295
 
171
296
  const handleSave = () => {
172
297
  const content = editorRef.current?.getContent();
173
- console.log('Saving:', content);
298
+ const markdown = editorRef.current?.getMarkdown();
299
+ console.log('Saving:', { content, markdown });
174
300
  };
175
301
 
176
302
  const handleLoad = () => {
@@ -178,11 +304,22 @@ function App() {
178
304
  { type: 'p', children: [{ text: 'Loaded content' }] }
179
305
  ]);
180
306
  };
307
+
308
+ const handleLoadMarkdown = () => {
309
+ editorRef.current?.setMarkdown('# Hello World\n\nThis is **bold**');
310
+ };
311
+
312
+ const handleExportHtml = async () => {
313
+ const html = await editorRef.current?.getHtml();
314
+ console.log('HTML:', html);
315
+ };
181
316
 
182
317
  return (
183
318
  <>
184
319
  <button onClick={handleSave}>Save</button>
185
320
  <button onClick={handleLoad}>Load</button>
321
+ <button onClick={handleLoadMarkdown}>Load Markdown</button>
322
+ <button onClick={handleExportHtml}>Export HTML</button>
186
323
  <PlateEditor ref={editorRef} />
187
324
  </>
188
325
  );
@@ -234,6 +371,22 @@ MIT © [Your Name]
234
371
 
235
372
  Built with [Plate](https://platejs.org/) - a plugin framework for building rich text editors with React and Slate.
236
373
 
374
+ ## Documentation
375
+
376
+ ### Usage Guides
377
+
378
+ - 📖 [中文使用手册](./docs/USAGE_GUIDE_CN.md) - 完整的中文使用指南
379
+ - 📖 [English Usage Guide](./docs/USAGE_GUIDE_EN.md) - Complete English usage guide
380
+ - 🔧 [API 实现指南](./docs/API_IMPLEMENTATION_GUIDE.md) - Backend API implementation guide
381
+ - 🔌 [后端 API 文档](./docs/BACKEND_API.md) - Backend API documentation
382
+
383
+ ### Examples
384
+
385
+ For complete examples, check out:
386
+ - `/examples` - Playground examples with various use cases
387
+ - `FEATURES.md` - Detailed feature documentation
388
+ - `CHANGELOG.md` - Version history and updates
389
+
237
390
  ## Support
238
391
 
239
392
  - [Documentation](https://github.com/yourusername/kc-plate-editor#readme)
@@ -1,4 +1,5 @@
1
1
  import { Value } from 'platejs';
2
+ import { ToolbarConfig } from '../../types/toolbar-config';
2
3
  import * as React from 'react';
3
4
  export interface PlateEditorProps {
4
5
  value?: Value;
@@ -8,11 +9,20 @@ export interface PlateEditorProps {
8
9
  disabled?: boolean;
9
10
  readOnly?: boolean;
10
11
  autoFocus?: boolean;
12
+ toolbarConfig?: ToolbarConfig;
11
13
  }
12
14
  export interface PlateEditorRef {
13
15
  getContent: () => Value;
14
16
  setContent: (content: Value) => void;
15
17
  resetContent: () => void;
16
18
  getEditor: () => any;
19
+ getMarkdown: () => string;
20
+ setMarkdown: (markdown: string) => void;
21
+ getHtml: () => Promise<string>;
22
+ setHtml: (html: string) => void;
23
+ getText: () => string;
24
+ isEmpty: () => boolean;
25
+ focus: () => void;
26
+ blur: () => void;
17
27
  }
18
28
  export declare const PlateEditor: React.ForwardRefExoticComponent<PlateEditorProps & React.RefAttributes<PlateEditorRef>>;
@@ -1,3 +1,17 @@
1
+ export declare const createBlockPlaceholderKit: (locale?: "zh-CN" | "en-US") => import('platejs/react').PlatePlugin<import('platejs').PluginConfig<"blockPlaceholder", {
2
+ _target: {
3
+ node: import('platejs').TElement;
4
+ placeholder: string;
5
+ } | null;
6
+ placeholders: Record<string, string>;
7
+ query: (context: import('platejs/react').PlatePluginContext<import('platejs/react').BlockPlaceholderConfig> & {
8
+ node: import('platejs').TElement;
9
+ path: import('platejs').Path;
10
+ }) => boolean;
11
+ className?: string;
12
+ }, {}, {}, {
13
+ placeholder: (node: import('platejs').TElement) => string | undefined;
14
+ }>>[];
1
15
  export declare const BlockPlaceholderKit: import('platejs/react').PlatePlugin<import('platejs').PluginConfig<"blockPlaceholder", {
2
16
  _target: {
3
17
  node: import('platejs').TElement;
@@ -0,0 +1,5 @@
1
+ import { ToolbarConfig } from '../../../types/toolbar-config';
2
+ /**
3
+ * Create a configurable toolbar plugin
4
+ */
5
+ export declare function createConfigurableToolbarKit(config: ToolbarConfig): any[];
@@ -0,0 +1 @@
1
+ export declare const ResponsiveToolbarKit: import('platejs/react').PlatePlugin<import('platejs').PluginConfig<"responsive-toolbar", {}, {}, {}, {}>>[];
@@ -22,6 +22,7 @@ export declare const useChat: () => {
22
22
  error: Error | undefined;
23
23
  stop: () => Promise<void>;
24
24
  status: import('ai').ChatStatus;
25
+ messages: ChatMessage[];
25
26
  sendMessage: (message?: (Omit<ChatMessage, "id" | "role"> & {
26
27
  id?: string | undefined;
27
28
  role?: "user" | "system" | "assistant" | undefined;
@@ -50,6 +51,5 @@ export declare const useChat: () => {
50
51
  toolCallId: string;
51
52
  output: unknown;
52
53
  }) => Promise<void>;
53
- messages: ChatMessage[];
54
54
  clearError: () => void;
55
55
  };
@@ -0,0 +1,5 @@
1
+ import { ToolbarConfig } from '../../types/toolbar-config';
2
+ export interface ConfigurableToolbarProps {
3
+ config: ToolbarConfig;
4
+ }
5
+ export declare function ConfigurableToolbar({ config }: ConfigurableToolbarProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function ResponsiveToolbarButtons(): import("react/jsx-runtime").JSX.Element;
@@ -1,13 +1,2 @@
1
1
  import { DropdownMenuProps } from '@radix-ui/react-dropdown-menu';
2
- export declare const turnIntoItems: ({
3
- icon: import("react/jsx-runtime").JSX.Element;
4
- keywords: string[];
5
- label: string;
6
- value: string;
7
- } | {
8
- icon: import("react/jsx-runtime").JSX.Element;
9
- label: string;
10
- value: string;
11
- keywords?: undefined;
12
- })[];
13
2
  export declare function TurnIntoToolbarButton(props: DropdownMenuProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ export interface UploadedFile {
2
+ url: string;
3
+ name: string;
4
+ size: number;
5
+ type: string;
6
+ key?: string;
7
+ }
8
+ interface UseFileUploadProps {
9
+ onUploadComplete?: (file: UploadedFile) => void;
10
+ onUploadError?: (error: unknown) => void;
11
+ onUploadProgress?: (progress: number) => void;
12
+ }
13
+ export declare function useFileUpload({ onUploadComplete, onUploadError, onUploadProgress, }?: UseFileUploadProps): {
14
+ uploadFile: (file: File) => Promise<UploadedFile | undefined>;
15
+ isUploading: boolean;
16
+ progress: number;
17
+ uploadedFile: UploadedFile | undefined;
18
+ uploadingFile: File | undefined;
19
+ };
20
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Custom hook to detect media query matches
3
+ */
4
+ export declare function useMediaQuery(query: string): boolean;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fl=require("./index-CorI7Cc4.js");/*! *****************************************************************************
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fl=require("./index-CP58iz5v.js");/*! *****************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -1,4 +1,4 @@
1
- import { g as Xu } from "./index-CD4hikbu.mjs";
1
+ import { g as Xu } from "./index-Neyiy2eB.mjs";
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4