md-tiptap 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -142,6 +142,8 @@ function EditorExample() {
142
142
  | `disabled` | `boolean` | 否 | `false` | 是否禁用编辑器(只读) |
143
143
  | `onChangeDebounceMs` | `number` | 否 | `300` | `onChange` 防抖延迟(毫秒) |
144
144
  | `border` | `boolean` | 否 | `true` | 是否显示编辑器容器边框 |
145
+ | `imageMaxSizeBytes` | `number` | 否 | `5242880`(5MB) | 图片上传最大体积(字节),超过则拒绝并提示 |
146
+ | `formulaCategories` | `FormulaPickerCategory[]` | 否 | 内置默认分类 | 公式选择器的分类列表。不传则使用内置分类;传入时可完全自定义或在默认基础上扩展(见下方「扩展公式分类」) |
145
147
 
146
148
  ### Headless 模式下的工具栏显示
147
149
 
@@ -212,6 +214,30 @@ function EditorExample() {
212
214
  - **编辑公式**:点击已插入的公式可以打开编辑对话框修改
213
215
  - **实时预览**:编辑时实时渲染公式效果
214
216
 
217
+ **扩展公式分类**:可通过 `formulaCategories` 自定义或扩展公式选择器中的分类与片段。库会导出 `FORMULA_CATEGORIES`、`FormulaPickerCategory`、`FormulaSnippetItem`,便于在默认基础上追加分类:
218
+
219
+ ```tsx
220
+ import {
221
+ TiptapEditor,
222
+ FORMULA_CATEGORIES,
223
+ type FormulaPickerCategory,
224
+ type FormulaSnippetItem,
225
+ } from 'md-tiptap'
226
+ import 'md-tiptap/style.css'
227
+
228
+ const customCategory: FormulaPickerCategory = {
229
+ id: 'custom',
230
+ title: '自定义',
231
+ items: [
232
+ { id: 'my-1', label: '我的公式', latex: '\\mycommand{x}' },
233
+ ] as FormulaSnippetItem[],
234
+ }
235
+
236
+ <TiptapEditor
237
+ formulaCategories={[...FORMULA_CATEGORIES, customCategory]}
238
+ />
239
+ ```
240
+
215
241
  ### 图片上传
216
242
 
217
243
  支持两种方式插入图片:
@@ -4,6 +4,8 @@ interface ImageUploadDialogProps {
4
4
  onConfirm: (src: string, alt?: string) => void;
5
5
  onCancel: () => void;
6
6
  onUpload?: (file: File) => Promise<string>;
7
+ /** 图片最大体积(字节),超过则拒绝 */
8
+ imageMaxSizeBytes?: number;
7
9
  }
8
- declare const ImageUploadDialog: ({ isOpen, onConfirm, onCancel, onUpload }: ImageUploadDialogProps) => import("react/jsx-runtime").JSX.Element;
10
+ declare const ImageUploadDialog: ({ isOpen, onConfirm, onCancel, onUpload, imageMaxSizeBytes, }: ImageUploadDialogProps) => import("react/jsx-runtime").JSX.Element;
9
11
  export default ImageUploadDialog;
@@ -0,0 +1,9 @@
1
+ import { type FormulaPickerCategory } from '@/config/formulaCategories';
2
+ import './FormulaPicker.css';
3
+ export type { FormulaPickerCategory } from '@/config/formulaCategories';
4
+ export interface FormulaPickerProps {
5
+ handlePickSnippet: (latex: string) => void;
6
+ /** 不传则使用默认 FORMULA_CATEGORIES */
7
+ categories?: FormulaPickerCategory[];
8
+ }
9
+ export declare function FormulaPicker({ handlePickSnippet, categories }: FormulaPickerProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ export interface FormulaSnippetItem {
2
+ id: string;
3
+ label: string;
4
+ latex: string;
5
+ previewLatex?: string;
6
+ }
7
+ interface FormulaSnippetButtonProps {
8
+ item: FormulaSnippetItem;
9
+ onInsert: (latex: string) => void;
10
+ }
11
+ export declare function FormulaSnippetButton({ item, onInsert }: FormulaSnippetButtonProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -1,10 +1,12 @@
1
- import './MathDialog.css';
1
+ import type { FormulaPickerCategory } from "@/config/formulaCategories";
2
+ import "./MathDialog.css";
2
3
  interface MathDialogProps {
3
4
  isOpen: boolean;
4
5
  initialValue?: string;
5
- type: 'inline' | 'block';
6
+ type: "inline" | "block";
6
7
  onConfirm: (latex: string) => void;
7
8
  onCancel: () => void;
9
+ formulaCategories?: FormulaPickerCategory[];
8
10
  }
9
- declare const MathDialog: ({ isOpen, initialValue, type, onConfirm, onCancel }: MathDialogProps) => import("react/jsx-runtime").JSX.Element;
11
+ declare const MathDialog: ({ isOpen, initialValue, type, onConfirm, onCancel, formulaCategories, }: MathDialogProps) => import("react/jsx-runtime").JSX.Element;
10
12
  export default MathDialog;
@@ -14,4 +14,5 @@ export declare function unsetHighlight(editor: Editor): void;
14
14
  export declare function setHeading(editor: Editor, level: 1 | 2 | 3): void;
15
15
  export declare function toggleBulletList(editor: Editor): void;
16
16
  export declare function toggleOrderedList(editor: Editor): void;
17
+ export declare function toggleTaskList(editor: Editor): void;
17
18
  export declare function insertTable(editor: Editor): void;
@@ -0,0 +1 @@
1
+ export declare const ImageWithDelete: import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any>;
@@ -1,4 +1,4 @@
1
1
  import "./TiptapEditor.css";
2
2
  import type { TiptapEditorProps } from "./types";
3
- declare const TiptapEditor: ({ editorMode, headlessToolbarMode, value, onChange, onImageUpload, commandMenuMaxHeight, commandMenuMinHeight, placeholder, disabled, onChangeDebounceMs, border, }: TiptapEditorProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const TiptapEditor: ({ editorMode, headlessToolbarMode, value, onChange, onImageUpload, commandMenuMaxHeight, commandMenuMinHeight, placeholder, disabled, onChangeDebounceMs, border, imageMaxSizeBytes, formulaCategories, }: TiptapEditorProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default TiptapEditor;
@@ -1,3 +1,4 @@
1
+ import type { FormulaPickerCategory } from '@/config/formulaCategories';
1
2
  export declare const MenuPlacement: {
2
3
  readonly Top: "top";
3
4
  readonly Bottom: "bottom";
@@ -69,4 +70,14 @@ export interface TiptapEditorProps {
69
70
  * @default 'always'
70
71
  */
71
72
  headlessToolbarMode?: HeadlessToolbarMode;
73
+ /**
74
+ * 图片上传最大体积(字节),超过则拒绝并提示
75
+ * @default config.IMAGE_MAX_SIZE_BYTES(5MB)
76
+ */
77
+ imageMaxSizeBytes?: number;
78
+ /**
79
+ * 公式选择器的分类列表。不传则使用默认 FORMULA_CATEGORIES;
80
+ * 传入时可完全自定义或通过 [...FORMULA_CATEGORIES, ...extra] 扩展默认列表。
81
+ */
82
+ formulaCategories?: FormulaPickerCategory[];
72
83
  }
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ import { Tabs as TabsPrimitive } from "radix-ui";
4
+ declare function Tabs({ className, orientation, ...props }: React.ComponentProps<typeof TabsPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
5
+ declare const tabsListVariants: (props?: ({
6
+ variant?: "line" | "default" | null | undefined;
7
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
+ declare function TabsList({ className, variant, ...props }: React.ComponentProps<typeof TabsPrimitive.List> & VariantProps<typeof tabsListVariants>): import("react/jsx-runtime").JSX.Element;
9
+ declare function TabsTrigger({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
10
+ declare function TabsContent({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
11
+ export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants };
@@ -0,0 +1,7 @@
1
+ import type { FormulaSnippetItem } from '@/components/TiptapEditor/MathDialog/FormulaSnippetButton';
2
+ export type FormulaPickerCategory = {
3
+ id: string;
4
+ title: string;
5
+ items: FormulaSnippetItem[];
6
+ };
7
+ export declare const FORMULA_CATEGORIES: FormulaPickerCategory[];
@@ -1,7 +1,14 @@
1
+ export interface ColorOption {
2
+ name: string;
3
+ value: string;
4
+ }
1
5
  export declare const config: {
2
6
  COMMAND_MENU_DEFAULT_MAX_HEIGHT: number;
3
7
  COMMAND_MENU_DEFAULT_MIN_HEIGHT: number;
4
8
  DEFAULT_ON_CHANGE_DEBOUNCE_MS: number;
5
9
  DEFAULT_PLACEHOLDER: string;
6
10
  PLACEHOLDER_HEADLESS: string;
11
+ IMAGE_MAX_SIZE_BYTES: number;
12
+ TEXT_COLORS: ColorOption[];
13
+ HIGHLIGHT_COLORS: ColorOption[];
7
14
  };
@@ -1,3 +1,4 @@
1
+ export { useBlockMathDeleteButton } from "./useBlockMathDeleteButton";
1
2
  export { useCommandMenu } from "./useCommandMenu";
2
3
  export { useMathDialog } from "./useMathDialog";
3
4
  export { useImageUploadDialog } from "./useImageUploadDialog";
@@ -0,0 +1,10 @@
1
+ import type { Editor } from "@tiptap/react";
2
+ export interface UseBlockMathDeleteButtonOptions {
3
+ editor: Editor | null;
4
+ editorWrapperRef: React.RefObject<HTMLDivElement | null>;
5
+ disabled: boolean;
6
+ }
7
+ /**
8
+ * 在块级公式上注入 hover 时显示的删除按钮,点击可删除该公式节点。
9
+ */
10
+ export declare function useBlockMathDeleteButton({ editor, editorWrapperRef, disabled, }: UseBlockMathDeleteButtonOptions): void;
@@ -30,6 +30,7 @@ export declare function useEditorCommands(editor: Editor | null, options?: UseEd
30
30
  setHeading: (level: 1 | 2 | 3) => void;
31
31
  toggleBulletList: () => void;
32
32
  toggleOrderedList: () => void;
33
+ toggleTaskList: () => void;
33
34
  insertTable: () => void;
34
35
  };
35
36
  dialogs: {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export { default as TiptapEditor } from "./components/TiptapEditor";
2
2
  export type { TiptapEditorProps, EditorMode, HeadlessToolbarMode, } from "./components/TiptapEditor/types";
3
+ export { FORMULA_CATEGORIES } from "./config/formulaCategories";
4
+ export type { FormulaPickerCategory } from "./config/formulaCategories";
5
+ export type { FormulaSnippetItem } from "./components/TiptapEditor/MathDialog/FormulaSnippetButton";
3
6
  import "./style.css";
@@ -1,2 +1,7 @@
1
1
  import { type ClassValue } from "clsx";
2
2
  export declare function cn(...inputs: ClassValue[]): string;
3
+ /**
4
+ * 将字节数格式化为带合适单位的字符串(如 300KB、5MB、1.5MB)
5
+ * 避免小体积用 MB 显示成 0MB
6
+ */
7
+ export declare function formatFileSize(bytes: number): string;