remons-markdown-editor 1.0.0-beta.4 → 1.0.0-beta.5
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.
- package/dist/App.d.ts +2 -0
- package/dist/MarkdownEditor.d.ts +23 -0
- package/dist/components/Dialog/EditDialog.d.ts +21 -0
- package/dist/components/Editor/codemirrorExtensions.d.ts +12 -0
- package/dist/components/Editor/containerWidget.d.ts +20 -0
- package/dist/components/Editor/index.d.ts +16 -0
- package/dist/components/Panel/SplitPanels.d.ts +7 -0
- package/dist/components/Preview/index.d.ts +10 -0
- package/dist/components/Toolbar/buttons.d.ts +34 -0
- package/dist/components/Toolbar/config.d.ts +6 -0
- package/dist/components/Toolbar/hooks/useToolbar.d.ts +13 -0
- package/dist/components/Toolbar/index.d.ts +13 -0
- package/dist/components/Toolbar/renderers/TablePicker/TableDropdown.d.ts +5 -0
- package/dist/components/Toolbar/renderers/TablePicker/index.d.ts +9 -0
- package/dist/components/Toolbar/renderers/ToolbarItemRenderer.d.ts +7 -0
- package/dist/hooks/useFullscreen.d.ts +4 -0
- package/dist/hooks/useRegisterToolbar.d.ts +51 -0
- package/dist/hooks/useScrollSync.d.ts +5 -0
- package/dist/index.cjs +1305 -1191
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +248 -8
- package/dist/index.d.ts +5 -157
- package/dist/index.js +1280 -1169
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +0 -0
- package/dist/registry/componentRegistry.d.ts +34 -0
- package/dist/types/index.d.ts +76 -0
- package/dist/utils/parseContainer.d.ts +18 -0
- package/dist/utils/writeContainer.d.ts +16 -0
- package/package.json +7 -7
- package/dist/index.css.map +0 -1
- package/dist/index.d.cts +0 -157
package/dist/App.d.ts
ADDED
|
@@ -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,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,34 @@
|
|
|
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
|
+
* @param file - 要上传的文件
|
|
14
|
+
* @param uploadConfig - 上传配置
|
|
15
|
+
*/
|
|
16
|
+
export declare function uploadFileToServer(file: File, uploadConfig: ImageUploadConfig): Promise<string | null>;
|
|
17
|
+
/**
|
|
18
|
+
* 判断是否配置了图片上传
|
|
19
|
+
*/
|
|
20
|
+
export declare function isUploadConfigured(uploadConfig?: ImageUploadConfig): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 图片上传:创建隐藏的 file input 触发选择,上传后插入 markdown 图片语法
|
|
23
|
+
* @param view - CodeMirror 编辑器实例
|
|
24
|
+
* @param uploadConfig - 上传配置(包含 uploadUrl 或 onUploadImage)
|
|
25
|
+
*/
|
|
26
|
+
export declare function uploadImage(view: EditorView, uploadConfig: ImageUploadConfig): void;
|
|
27
|
+
/**
|
|
28
|
+
* 用前缀和后缀包裹选中文本
|
|
29
|
+
*/
|
|
30
|
+
export declare function wrapSelection(view: EditorView, prefix: string, suffix: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* 切换包裹:选中的文本已包含标签则移除,否则添加
|
|
33
|
+
*/
|
|
34
|
+
export declare function toggleWrap(view: EditorView, openTag: string, closeTag: string): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
handleClick: (button: ToolbarButtonConfig) => void;
|
|
12
|
+
}
|
|
13
|
+
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,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,51 @@
|
|
|
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 容器模式
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const schema: ComponentSchema = {
|
|
15
|
+
* name: 'alert',
|
|
16
|
+
* label: '警告框',
|
|
17
|
+
* icon: <AlertOutlined />,
|
|
18
|
+
* fields: [{ key: 'level', defaultValue: 'info' }],
|
|
19
|
+
* renderDialog: (props, onChange) => (
|
|
20
|
+
* <Input value={props.level} onChange={e => onChange('level', e.target.value)} />
|
|
21
|
+
* ),
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* function MyPage() {
|
|
25
|
+
* useRegisterToolbar(schema)
|
|
26
|
+
* return <MarkdownEditor />
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example 标签包裹模式
|
|
31
|
+
* ```tsx
|
|
32
|
+
* function MyPage() {
|
|
33
|
+
* useRegisterToolbar({
|
|
34
|
+
* name: 'plugin-container',
|
|
35
|
+
* label: '自定义容器',
|
|
36
|
+
* icon: <AlertOutlined />,
|
|
37
|
+
* wrapTags: ['<plugin-container>', '</plugin-container>'],
|
|
38
|
+
* })
|
|
39
|
+
* return <MarkdownEditor />
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example 批量注册
|
|
44
|
+
* ```tsx
|
|
45
|
+
* function MyPage() {
|
|
46
|
+
* useRegisterToolbar([schema1, schema2, schema3])
|
|
47
|
+
* return <MarkdownEditor />
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function useRegisterToolbar(schemas: ComponentSchema | ComponentSchema[]): void;
|