SVeditor 文档
API 参考

类型定义

SVeditor 导出的 TypeScript 类型定义。

类型定义

所有类型均从主包入口导出:

import type {
  EditorOptions,
  EditorInstance,
  AutoSaveOptions,
  MetaOptions,
  FetchMetaObject,
  SaveStatus,
  FetchStatus,
  CollaborationExtensionOptions,
  CollabStatus,
  AiTextResolverOptions,
  VersionHistoryOptions,
  VersionSnapshot,
} from '@wztlink1013/sveditor';

核心类型

EditorOptions

完整文档参见 EditorOptions

interface EditorOptions {
  el: string | HTMLElement;
  content?: string;
  editable?: boolean;
  classNames?: ClassNames;
  autoSave?: AutoSaveOptions;
  extensionsOptions?: ExtensionOptions;
  versionHistory?: VersionHistoryOptions;
  onCreate?: (instance: EditorInstance) => void;
  onUpdate?: (instance: EditorInstance) => void;
  onDestroy?: () => void;
}

EditorInstance

完整文档参见 EditorInstance

interface EditorInstance {
  getHTML(): string;
  setHTML(html: string): void;
  getText(): string;
  getJSON(): object;
  setJSON(json: object | string): void;
  getMeta(): FetchMetaObject;
  setMeta(meta: Partial<FetchMetaObject>): void;
  destroy(): void;
}

元数据持久化与变更通知通过 MetaOptionsextensionsOptions.meta)配置。详见 EditorInstanceEditorOptions

自动保存类型

SaveStatus

type SaveStatus = 'idle' | 'saving' | 'saved' | 'error';

FetchStatus

type FetchStatus = 'idle' | 'fetching' | 'success' | 'error';

FetchMetaObject

interface FetchMetaObject {
  name?: string;
  description?: string;
  contentStr?: string;
  emojiInfo?: string;
  coverImage?: string;
  coverBlock?: string;
  coverPos?: string;
}

emojiInfo 一般为内置表情控件序列化后的 JSON 字符串(需要结构化字段时可自行 JSON.parse)。

MetaOptions

interface MetaOptions {
  onFetchMeta?: () => Promise<FetchMetaObject>;
  onSaveMeta?: (meta: FetchMetaObject) => Promise<void>;
  onMetaChange?: (meta: FetchMetaObject) => void;
}

协作类型

CollabStatus

type CollabStatus = 'disconnected' | 'connecting' | 'connected' | 'error';

AI 类型

AiTextResolverOptions

interface AiTextResolverOptions {
  editor: Editor;
  action: string;
  text: string;
  textOptions: {
    format?: 'plain-text' | 'rich-text';
  };
  extensionOptions: AiOptions;
  aborter?: AbortController;
}

版本历史类型

VersionSnapshot

interface VersionSnapshot {
  id: string;
  label?: string;
  createdAt: number;
  content: string;
}