From 761bff788536df9ef3977186b41d0170d2e9fa00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?wifi=E6=AD=AAf?= <1402772884@qq.com> Date: Sat, 8 Feb 2025 00:41:52 +0800 Subject: [PATCH] =?UTF-8?q?docs(mini-editor-docs):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=96=87=E6=A1=A3api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/api.mdx | 79 ++++++++++++++++++++++++++++++++++++++++--- docs/theme/index.tsx | 11 ++++++ docs/theme/styles.css | 11 ++++++ 3 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 docs/theme/index.tsx create mode 100644 docs/theme/styles.css diff --git a/docs/guide/api.mdx b/docs/guide/api.mdx index a2ad6d9..9c8822e 100644 --- a/docs/guide/api.mdx +++ b/docs/guide/api.mdx @@ -90,6 +90,17 @@ const App = () => { ``` +### enableShortcuts + +- 类型:`boolean` +- 默认值:`true` + +是否开启快捷键支持,默认开启。 + +```tsx + +``` + ## 事件 ### onChange @@ -110,7 +121,7 @@ const App = () => { ### onSave -- 类型:`(value: string, editorView: ViewUpdate) => void` +- 类型:`(value: string, editorView: EditorView) => void` 保存事件,当点击 `保存按钮` / `按下快捷键` 时触发。 @@ -143,7 +154,6 @@ const App: FC = () => { const handleUpload = async (file: File, callback: Callback) => { await new Promise((resolve) => { setTimeout(() => { - console.log("settimeout 上传成功", file); resolve({}); }, 1500); }); @@ -160,9 +170,21 @@ const App: FC = () => { ### onDragUpload -- 类型:`(files: File, callback: Callback) => void` +- 类型:`(file: File, callback: Callback) => void` + - file:`File` 对象 + - callback:`Callback` + +```ts +type Callback = (param: { url: string; alt?: string }) => void; +``` + +拖拽上传图片时触发,务必将上传后的 url 作为 callback 入参回传。 + +> callback的alt是可选项,如果没传的话就是nanoid生成的8位随机数字英文。 + +### onPatseUpload -拖拽上传图片事件(同上)。 +同 `onDragUpload` 事件。 ## 类型 @@ -225,15 +247,62 @@ import type { ToolbarType } from "mini-markdown-editor"; ```ts interface GlobalConfig { + /** + * 需要渲染的 toolbar,默认全部渲染 + * @type {ToolbarType[]} 需要渲染的 toolbar 数组 + * @type {Record} 需要渲染的 toolbar 对象,值为 true 时渲染,false 时不渲染 + */ toolbar?: ToolbarType[] | Record; + /** + * 底部状态栏是否显示,默认显示 + * @type {boolean} + */ status?: boolean; + /** + * 编辑器主题 + * @type {"light" | "dark"} + */ theme?: "light" | "dark"; + /** + * 是否开启本地存储 + * @type {boolean} + */ local?: boolean; // 是否开启本地存储 + /** + * 编辑区是否显示行号 + * @type {boolean} + */ lineNumbers?: boolean; + /** + * 是否开启快捷键支持 + * @type {boolean} + */ + enableShortcuts?: boolean; + /** + * 改变编辑器内容时触发 + * @type {(value: string, editorView: ViewUpdate) => void} + */ onChange?: (value: string, editorView: ViewUpdate) => void; + /** + * 上传图片时触发 + * @type {(file: File, callback: Callback) => void} + */ onUpload?: (file: File, callback: Callback) => void; + /** + * 拖拽上传图片时触发 + * @type {(file: File, callback: Callback) => void} + */ onDragUpload?: (file: File, callback: Callback) => void; - onSave?: (value: string, editorView: ViewUpdate) => void; + /** + * 粘贴上传图片时触发 + * @type {(file: File, callback: Callback) => void} + */ + onPatseUpload?: (file: File, callback: Callback) => void; + /** + * 保存触发 + * @type {(value: string, editorView: EditorView) => void} + */ + onSave?: (value: string, editorView: EditorView) => void; } type Callback = (param: { url: string; alt?: string }) => void; diff --git a/docs/theme/index.tsx b/docs/theme/index.tsx new file mode 100644 index 0000000..598aacc --- /dev/null +++ b/docs/theme/index.tsx @@ -0,0 +1,11 @@ +import Theme from "rspress/theme"; +import "./styles.css"; + +const Layout = () => ; + +export default { + ...Theme, + Layout, +}; + +export * from "rspress/theme"; diff --git a/docs/theme/styles.css b/docs/theme/styles.css new file mode 100644 index 0000000..bba7cce --- /dev/null +++ b/docs/theme/styles.css @@ -0,0 +1,11 @@ +@media screen and (min-width: 960px) { + .rspress-doc-container .list-disc li { + font-size: 18px; + } + .rspress-doc-container .list-decimal li { + font-size: 18px; + } + .rspress-doc-container p { + font-size: 18px; + } +} -- Gitee