remons-markdown-editor 1.0.0-beta.2 → 1.0.0-beta.21

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 (34) hide show
  1. package/dist/App.d.ts +2 -0
  2. package/dist/MarkdownEditor.d.ts +23 -0
  3. package/dist/components/Dialog/EditDialog.d.ts +21 -0
  4. package/dist/components/Editor/codemirrorExtensions.d.ts +12 -0
  5. package/dist/components/Editor/containerWidget.d.ts +20 -0
  6. package/dist/components/Editor/index.d.ts +16 -0
  7. package/dist/components/Icon/index.d.ts +2 -0
  8. package/dist/components/Panel/SplitPanels.d.ts +7 -0
  9. package/dist/components/Preview/index.d.ts +10 -0
  10. package/dist/components/Toolbar/buttons.d.ts +59 -0
  11. package/dist/components/Toolbar/config.d.ts +6 -0
  12. package/dist/components/Toolbar/hooks/useToolbar.d.ts +14 -0
  13. package/dist/components/Toolbar/index.d.ts +13 -0
  14. package/dist/components/Toolbar/renderers/TablePicker/TableDropdown.d.ts +5 -0
  15. package/dist/components/Toolbar/renderers/TablePicker/index.d.ts +9 -0
  16. package/dist/components/Toolbar/renderers/ToolbarItemRenderer.d.ts +7 -0
  17. package/dist/hooks/useFullscreen.d.ts +4 -0
  18. package/dist/hooks/useRegisterToolbar.d.ts +101 -0
  19. package/dist/hooks/useScrollSync.d.ts +6 -0
  20. package/dist/index.cjs +1612 -1202
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.css +184 -113
  23. package/dist/index.d.ts +5 -98
  24. package/dist/index.js +1588 -1182
  25. package/dist/index.js.map +1 -1
  26. package/dist/main.d.ts +0 -0
  27. package/dist/registry/componentRegistry.d.ts +34 -0
  28. package/dist/types/index.d.ts +148 -0
  29. package/dist/utils/parseContainer.d.ts +18 -0
  30. package/dist/utils/writeContainer.d.ts +16 -0
  31. package/package.json +77 -81
  32. package/readme.md +309 -91
  33. package/dist/index.css.map +0 -1
  34. package/dist/index.d.cts +0 -98
package/dist/App.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function App(): import('react').JSX.Element;
2
+ export default App;
@@ -0,0 +1,23 @@
1
+ import { ImageUploadConfig } from './types';
2
+ import { PreviewOptions } from './components/Preview';
3
+ export interface MarkdownEditorRef {
4
+ getContent: () => string;
5
+ }
6
+ export interface MarkdownEditorProps {
7
+ /** 初始内容 */
8
+ defaultValue?: string;
9
+ /** 受控内容 */
10
+ value?: string;
11
+ /** 内容变化回调 */
12
+ onChange?: (value: string) => void;
13
+ /** 是否显示预览面板 */
14
+ showPreview?: boolean;
15
+ /** 是否支持全屏 */
16
+ fullscreen?: boolean;
17
+ /** Preview 渲染配置 */
18
+ previewOptions?: PreviewOptions;
19
+ /** 图片上传配置 */
20
+ uploadConfig?: ImageUploadConfig;
21
+ }
22
+ declare const _default: import('react').ForwardRefExoticComponent<MarkdownEditorProps & import('react').RefAttributes<MarkdownEditorRef>>;
23
+ export default _default;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 弹窗编辑容器属性的组件
3
+ */
4
+ interface EditDialogProps {
5
+ /** 弹窗是否显示 */
6
+ visible: boolean;
7
+ /** 容器类型名称 */
8
+ typeName: string;
9
+ /** 当前属性值 */
10
+ currentProps: Record<string, string>;
11
+ /** 保存回调 */
12
+ onSave: (props: Record<string, string>) => void;
13
+ /** 关闭回调 */
14
+ onClose: () => void;
15
+ }
16
+ /**
17
+ * 属性编辑弹窗组件
18
+ * 根据组件 schema 的 renderDialog 函数渲染弹窗内容
19
+ */
20
+ export default function EditDialog({ visible, typeName, currentProps, onSave, onClose }: EditDialogProps): import('react').JSX.Element | null;
21
+ export {};
@@ -0,0 +1,12 @@
1
+ import { OnEditContainer } from './containerWidget';
2
+ import { ImageUploadConfig } from '../../types';
3
+ interface GetCodeMirrorExtensionsOptions {
4
+ /** 编辑容器属性的回调函数 */
5
+ onEditContainer?: OnEditContainer;
6
+ /** 图片上传配置 */
7
+ uploadConfig?: ImageUploadConfig;
8
+ /** 未配置上传时的提示回调 */
9
+ onMessageNoUploadConfig?: () => void;
10
+ }
11
+ export declare const getCodeMirrorExtensions: (opts?: GetCodeMirrorExtensionsOptions) => import('@codemirror/state').Extension[];
12
+ export default getCodeMirrorExtensions;
@@ -0,0 +1,20 @@
1
+ import { ViewPlugin, DecorationSet } from '@codemirror/view';
2
+ import { Facet } from '@codemirror/state';
3
+ /**
4
+ * 编辑容器属性的回调函数类型
5
+ */
6
+ export interface OnEditContainer {
7
+ (view: any, typeName: string, propsLineFrom: number, propsLineTo: number, currentProps: Record<string, string>): void;
8
+ }
9
+ /**
10
+ * 自定义 facet 用于传递编辑回调
11
+ */
12
+ export declare const containerEditCallback: Facet<any, OnEditContainer>;
13
+ /**
14
+ * 容器编辑 ViewPlugin
15
+ * 将容器的 ::: 头行和 {} 属性行替换为只读 widget,使其无法在编辑器中直接编辑
16
+ */
17
+ export declare const containerWidgetPlugin: ViewPlugin<{
18
+ decorations: DecorationSet;
19
+ update(update: any): void;
20
+ }, undefined>;
@@ -0,0 +1,16 @@
1
+ import { EditorView } from 'codemirror';
2
+ import { ImageUploadConfig } from '../../types';
3
+ interface EditorProps {
4
+ value: string;
5
+ onChange: (value: string) => void;
6
+ onScrollReady?: (scrollDOM: HTMLElement) => void;
7
+ onViewReady?: (view: EditorView) => void;
8
+ /** 编辑容器属性的回调 */
9
+ onEditContainer?: (view: any, typeName: string, propsLineFrom: number, propsLineTo: number, currentProps: Record<string, string>) => void;
10
+ /** 图片上传配置 */
11
+ uploadConfig?: ImageUploadConfig;
12
+ /** 未配置上传时的提示回调 */
13
+ onMessageNoUploadConfig?: () => void;
14
+ }
15
+ export default function Editor({ value, onChange, onScrollReady, onViewReady, onEditContainer, uploadConfig, onMessageNoUploadConfig }: EditorProps): import('react').JSX.Element;
16
+ export {};
@@ -0,0 +1,2 @@
1
+ declare function IconComponent(type: string, className?: string): import('react').JSX.Element;
2
+ export default IconComponent;
@@ -0,0 +1,7 @@
1
+ import { default as React } from 'react';
2
+ interface SplitPanelsProps {
3
+ leftPanel: React.ReactNode;
4
+ rightPanel: React.ReactNode;
5
+ }
6
+ export default function SplitPanels({ leftPanel, rightPanel }: SplitPanelsProps): React.JSX.Element;
7
+ export {};
@@ -0,0 +1,10 @@
1
+ import { RenderMarkdownProps } from 'remons-render-markdown';
2
+ export type PreviewOptions = Omit<RenderMarkdownProps, 'content'> & {
3
+ languages?: Record<string, any> | null | undefined;
4
+ };
5
+ export interface PreviewProps {
6
+ content: string;
7
+ previewOptions?: PreviewOptions;
8
+ }
9
+ declare const Preview: import('react').ForwardRefExoticComponent<PreviewProps & import('react').RefAttributes<HTMLDivElement>>;
10
+ export default Preview;
@@ -0,0 +1,59 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { ImageUploadConfig } from '../../types';
3
+ /**
4
+ * 在光标位置插入文本
5
+ */
6
+ export declare function insertAtCursor(view: EditorView, before: string, after?: string, placeholder?: string): void;
7
+ /**
8
+ * 在当前行行首插入文本
9
+ */
10
+ export declare function insertAtLineStart(view: EditorView, text: string): void;
11
+ /**
12
+ * 切换标题:
13
+ * - 当前行已是目标级别标题 → 移除行首 # 前缀(变回普通文本)
14
+ * - 当前行是其他级别标题 → 替换为目标级别
15
+ * - 当前行是普通文本 → 插入目标级别前缀
16
+ * @param view - CodeMirror 编辑器实例
17
+ * @param level - 标题级别(1-6)
18
+ */
19
+ export declare function toggleHeading(view: EditorView, level: number): void;
20
+ /**
21
+ * 切换任务列表(checkbox 待办)
22
+ * - 支持多行:对选区内每一行应用 `- [ ] `
23
+ * - 普通列表项(如 `- 内容`)直接转换为 `- [ ] 内容`
24
+ * - 切换:若所有目标行都已是任务项,则移除行首前缀
25
+ */
26
+ export declare function toggleTaskList(view: EditorView): void;
27
+ /**
28
+ * 切换行首前缀(支持多行选区)
29
+ * - 已是对应前缀的行 → 移除前缀(变回普通文本)
30
+ * - 未加前缀的行 → 在行首插入前缀
31
+ * @param view - CodeMirror 编辑器实例
32
+ * @param pattern - 匹配行首前缀的正则
33
+ * @param insertText - 未匹配时插入的前缀文本
34
+ */
35
+ export declare function toggleLinePrefix(view: EditorView, pattern: RegExp, insertText: string): void;
36
+ /**
37
+ * 上传图片
38
+ * @param file - 要上传的文件
39
+ * @param uploadConfig - 上传配置
40
+ */
41
+ export declare function uploadFileToServer(file: File, uploadConfig: ImageUploadConfig): Promise<string | null>;
42
+ /**
43
+ * 判断是否配置了图片上传
44
+ */
45
+ export declare function isUploadConfigured(uploadConfig?: ImageUploadConfig): boolean;
46
+ /**
47
+ * 图片上传:创建隐藏的 file input 触发选择,上传后插入 markdown 图片语法
48
+ * @param view - CodeMirror 编辑器实例
49
+ * @param uploadConfig - 上传配置(包含 uploadUrl 或 onUploadImage)
50
+ */
51
+ export declare function uploadImage(view: EditorView, uploadConfig: ImageUploadConfig): void;
52
+ /**
53
+ * 用前缀和后缀包裹选中文本
54
+ */
55
+ export declare function wrapSelection(view: EditorView, prefix: string, suffix: string): void;
56
+ /**
57
+ * 切换包裹:选中的文本已包含标签则移除,否则添加
58
+ */
59
+ export declare function toggleWrap(view: EditorView, openTag: string, closeTag: string): void;
@@ -0,0 +1,6 @@
1
+ import { ToolbarButtonConfig, ImageUploadConfig } from '../../types';
2
+ /**
3
+ * 创建工具栏配置
4
+ * @param options - 配置选项
5
+ */
6
+ export declare function createToolbarConfig(options?: ImageUploadConfig): ToolbarButtonConfig[];
@@ -0,0 +1,14 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { ToolbarButtonConfig, ImageUploadConfig } from '../../../types';
3
+ export interface UseToolbarOptions {
4
+ /** 第三方扩展的按钮配置,将追加到工具栏末尾 */
5
+ extraItems?: ToolbarButtonConfig[];
6
+ /** 图片上传配置 */
7
+ uploadConfig?: ImageUploadConfig;
8
+ }
9
+ export interface UseToolbarReturn {
10
+ config: ToolbarButtonConfig[];
11
+ extraItemsConfig: ToolbarButtonConfig[];
12
+ handleClick: (button: ToolbarButtonConfig) => void;
13
+ }
14
+ export declare function useToolbar(editorView: EditorView | null, options?: UseToolbarOptions): UseToolbarReturn;
@@ -0,0 +1,13 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { ToolbarButtonConfig, ImageUploadConfig } from '../../types';
3
+ interface ToolbarProps {
4
+ editorView: EditorView | null;
5
+ fullscreen?: boolean;
6
+ onToggleFullscreen?: () => void;
7
+ /** 第三方扩展的按钮配置,将追加到工具栏末尾 */
8
+ extraItems?: ToolbarButtonConfig[];
9
+ /** 图片上传配置 */
10
+ uploadConfig?: ImageUploadConfig;
11
+ }
12
+ export default function Toolbar({ editorView, fullscreen, onToggleFullscreen, extraItems, uploadConfig }: ToolbarProps): import('react').JSX.Element;
13
+ export {};
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+ import { EditorView } from '@codemirror/view';
3
+ export default function TableDropdown({ editorView }: {
4
+ editorView: EditorView | null;
5
+ }): React.JSX.Element;
@@ -0,0 +1,9 @@
1
+ interface TableSize {
2
+ rows: number;
3
+ cols: number;
4
+ }
5
+ interface TablePickerProps {
6
+ onSelect: (size: TableSize) => void;
7
+ }
8
+ export default function TablePicker({ onSelect }: TablePickerProps): import('react').JSX.Element;
9
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ToolbarButtonConfig } from '../../../types';
2
+ interface Props {
3
+ item: ToolbarButtonConfig;
4
+ onClick: (item: ToolbarButtonConfig) => void;
5
+ }
6
+ export declare function ToolbarItemRenderer({ item, onClick }: Props): import('react').JSX.Element;
7
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare function useFullscreen(): {
2
+ fullscreen: boolean;
3
+ toggleFullscreen: () => void;
4
+ };
@@ -0,0 +1,101 @@
1
+ import { ComponentSchema } from '../types';
2
+ /**
3
+ * 注册自定义容器组件到工具栏。支持单个或批量注册。
4
+ * 支持两种模式:
5
+ *
6
+ * 1. 容器模式(linkCard):name + fields + renderDialog
7
+ * 插入 :::name 格式的容器,支持弹窗编辑属性
8
+ *
9
+ * 2. 标签包裹模式:name + wrapTags
10
+ * 插入简单的标签包裹文本,如 <plugin-container>...</plugin-container>
11
+ *
12
+ * @example 容器模式 - 使用 fields 自动生成表单(最简)
13
+ * ```tsx
14
+ * const schema: ComponentSchema = {
15
+ * name: 'alert',
16
+ * label: '警告框',
17
+ * icon: <AlertOutlined />,
18
+ * fields: [
19
+ * { key: 'type', name: '类型', componentType: 'select',
20
+ * componentProps: { options: [{ value: 'price', label: '价格' }, { value: 'info', label: '信息' }] } },
21
+ * { key: 'content', name: '内容', componentType: 'textarea',
22
+ * componentProps: { rows: 3 } },
23
+ * { key: 'enabled', name: '启用', componentType: 'switch' },
24
+ * ],
25
+ * }
26
+ * // 支持的 componentType: 'input' | 'textarea' | 'number' | 'select' | 'switch' | 'slider' | 'rate' | 'color' | 'date' | 'dateRange'
27
+ * ```
28
+ *
29
+ * @example 容器模式 - 使用 Form.Item 自动绑定(推荐)
30
+ * ```tsx
31
+ * const schema: ComponentSchema = {
32
+ * name: 'alert',
33
+ * label: '警告框',
34
+ * icon: <AlertOutlined />,
35
+ * fields: [{ key: 'level', defaultValue: 'info' }],
36
+ * renderDialog: ({ form }) => (
37
+ * <Form form={form} layout="vertical">
38
+ * <Form.Item name="level" label="级别">
39
+ * <Input />
40
+ * </Form.Item>
41
+ * </Form>
42
+ * ),
43
+ * }
44
+ *
45
+ * function MyPage() {
46
+ * useRegisterToolbar(schema)
47
+ * return <MarkdownEditor />
48
+ * }
49
+ * ```
50
+ *
51
+ * @example 容器模式 - 手动控制
52
+ * ```tsx
53
+ * const schema: ComponentSchema = {
54
+ * name: 'alert',
55
+ * label: '警告框',
56
+ * icon: <AlertOutlined />,
57
+ * fields: [{ key: 'level', defaultValue: 'info' }],
58
+ * renderDialog: ({ props, onChange }) => (
59
+ * <Input value={props.level} onChange={e => onChange('level', e.target.value)} />
60
+ * ),
61
+ * }
62
+ * ```
63
+ *
64
+ * @example 容器模式 - 完全自定义弹窗
65
+ * ```tsx
66
+ * const schema: ComponentSchema = {
67
+ * name: 'alert',
68
+ * label: '警告框',
69
+ * icon: <AlertOutlined />,
70
+ * fields: [{ key: 'level', defaultValue: 'info' }],
71
+ * renderDialog: ({ props, onSave }) => (
72
+ * <MyCustomEditor
73
+ * value={props.level}
74
+ * onSave={({ level }) => onSave({ level })}
75
+ * />
76
+ * ),
77
+ * }
78
+ * ```
79
+ *
80
+ * @example 标签包裹模式
81
+ * ```tsx
82
+ * function MyPage() {
83
+ * useRegisterToolbar({
84
+ * name: 'plugin-container',
85
+ * label: '自定义容器',
86
+ * icon: <AlertOutlined />,
87
+ * wrapTags: ['<plugin-container>', '</plugin-container>'],
88
+ * })
89
+ * return <MarkdownEditor />
90
+ * }
91
+ * ```
92
+ *
93
+ * @example 批量注册
94
+ * ```tsx
95
+ * function MyPage() {
96
+ * useRegisterToolbar([schema1, schema2, schema3])
97
+ * return <MarkdownEditor />
98
+ * }
99
+ * ```
100
+ */
101
+ export declare function useRegisterToolbar(schemas: ComponentSchema | ComponentSchema[]): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 双向滚动同步 Hook
3
+ * 编辑器与预览区互相同步滚动位置(基于比例)
4
+ * 使用 síncing 锁防止双向循环触发
5
+ */
6
+ export declare function useScrollSync(sourceRef: React.RefObject<HTMLElement | null>, targetRef: React.RefObject<HTMLDivElement | null>): void;