参考 组件与 Hooks
组件与 Hooks
@rebodocs/react 导出的全部内容:四个组件、十三个 hooks、配套的函数,以及不用 React 的使用方式。
我需要哪一个?
选择你要构建的东西。右侧的编辑器示意图显示了哪些部分由 Rebodocs 提供、哪些由你实现。
'use client';
import { DocsEditor } from '@rebodocs/react';
export function Receipt({ file }: { file: Uint8Array }) {
return (
<div className="h-screen">
<DocsEditor docx={file} name="receipt.docx" onSave={save} />
</div>
);
}给它一个高度。 编辑器和页面会填满容器并自带滚动。使用 h-full,或在纵向布局中使用 flex-1 min-h-0。
组件
完整的编辑器:工具栏、标尺、侧边栏、页面和状态栏。
- 填满容器
- 需要高度
- 接受 DocsProvider 的属性
新增的属性
featuresversionsclassNamestyleonReadyref此外还接受 的全部属性,但 bubble、onLinkKey 和 onFindKey 除外:这些由它自己处理。修改 features、versions 或是否提供 onSave,会用当前文档(包括未保存的修改)重新创建编辑器;传入另一个 docx 或房间则会打开它。features 能开关什么。
句柄(ref / onReady)
exportDocx()save()dirtynameeditorcollabsetNamesetAuthorsetLocalesetThemesetLetterheadshowPanelhidePanelfocus使用
'use client';
import { useRef } from 'react';
import { DocsEditor, type DocsHandle } from '@rebodocs/react';
export function Contract({ file }: { file: Uint8Array }) {
const editor = useRef<DocsHandle>(undefined);
// The handle, for what your own buttons do with the document.
const send = () => upload(editor.current!.exportDocx(), 'contract.docx');
return (
<div className="flex h-screen flex-col">
<button onClick={send}>Send for signature</button>
<div className="min-h-0 flex-1">
<DocsEditor ref={editor} docx={file} name="contract.docx" locale="en" onReady={(handle) => handle?.focus()} />
</div>
</div>
);
}为子组件持有一份文档。自身不绘制任何内容。
- 用它包裹你自己的界面
- 保持 docx 不变
- 以最新的回调为准
docxUint8Array | ArrayBufferunsavedbooleannamestringlocalestringlocalesRecord<string, Texts>letterheadBlob | { bytes, type } | string | nullfontsFontSource[]embedFontsboolean | 'subset'spellcheckSpellCheckertheme'light' | 'dark' | 'auto'languagestringonSave(docx, name) => voidonChange(editor) => voidonError(message) => voidonLinkKey() => voidonFindKey(replace) => voidbubblebooleanslashboolean | { builtIns?, commands? }variableSuggestionsboolean | { variables?, fromDocument?, allowNew? }formsbooleancollab{ url, room, ticket? }onCollab(state, peers) => void为什么我的文档被重置了?
当 docx 变化、collab 的房间变化(其 url、room 或 ticket),或 onSave 从无到有、从有到无时,文档会被重新创建,已输入但未保存的内容随之丢失。请在多次渲染之间保持 docx 为同一个值:把 Uint8Array 保存在 state 中,而不是在组件函数体中构建。你传入的函数在每次渲染时都可以是新的;调用的总是最后传入的那个。
使用
// State a key must reach lives outside the provider, or in a child of it.
function Editor({ file }: { file: Uint8Array }) {
const [finding, setFinding] = useState(false);
return (
<DocsProvider docx={file} name="contract.docx" onSave={upload} onFindKey={() => setFinding(true)}>
<MyToolbar />
{finding && <FindBar onClose={() => setFinding(false)} />}
<DocsSurface className="h-full" />
</DocsProvider>
);
}文档的页面。每个 provider 有且只有一个。
- 自带滚动
- 需要高度
- className · style
用 CSS 变量设置样式
--dx-canvas页面背后#efede8--dx-page-shadow每页的阴影0 1px 2px rgba(47,46,43,.08), 0 10px 28px -10px rgba(47,46,43,.22)--dx-selection选区rgba(11,87,208,.2)--dx-caret光标#000--dx-handle触屏上的拖动手柄#0b57d0
- 给它一个高度:放在有高度的容器中用 h-full,或在纵向 flex 布局中用 flex-1 min-h-0。
- 把变量设置在 surface 或其任意祖先元素上,用 CSS 或 style 都可以。
- 页面本身不应通过样式修改:每个字符的位置都是计算出来的,而不是交给浏览器决定。
使用
<DocsSurface
className="min-h-0 flex-1"
style={{ '--dx-canvas': '#f6eedf', '--dx-selection': '#fbe3a6', '--dx-caret': '#b07a00' } as CSSProperties}
/>/* Or in your CSS, on the surface or on anything above it */
.editor {
--dx-canvas: #f6eedf;
--dx-page-shadow: 0 2px 10px rgb(120 80 20 / 0.16);
}标尺:以厘米显示页面,可以拖动页边距和缩进。
- 绘制在 canvas 上
- className · style
- 窄窗口中不要显示
用 CSS 变量设置样式
--dx-ruler背景#fbfaf8--dx-ruler-line底部的线#e6e3dc--dx-ruler-margin文字区域之外的页面#e6e3dc--dx-ruler-text文字区域#fff--dx-ruler-ink数字和标记#5f5d58--dx-ruler-on正在拖动的标记#0b57d0
- 把它放在 surface 正上方,宽度相同:它会自动与下方的页面对齐。
- 调用 setLocale 后,给它一个随语言变化的 key,这样标记就会使用新语言。
- 窄窗口放不下标尺,这时不要显示它。
使用
function Pages() {
const { narrow } = useDocsResponsive();
const locale = useSyncExternalStore(onLocaleChange, getLocale);
return (
<div className="flex h-full flex-col" style={{ '--dx-ruler': '#fffbf2', '--dx-ruler-on': '#b07a00' } as CSSProperties}>
{!narrow && <DocsRuler key={locale} />}
<DocsSurface className="min-h-0 flex-1" />
</div>
);
}Hooks
在 DocsProvider 内使用它们来构建你自己的界面。选一个试试看——右侧的值就是 hook 的返回值。
试一试
正在打开编辑器…
Hook 的实时返回值
全部返回内容
- ready
- 在服务器上以及页面挂载前为 false
- state
- 要显示的内容,以普通值表示;ready 之前为中性值
- commands
- 按钮调用的命令:toggleMark(mark)、setRunProps(props)…
- docs
- save()、download()、exportDocx()、openFile()、share()、setName()…
- editor
- Editor 实例本身:exportPdf()、exportMarkdown()…
解构
const { ready, state, commands, docs, editor } = useDocs();颜色是不带 # 的十六进制,字号以磅为单位。每个命令执行后都会把键盘焦点交还给文档。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocs } from '@rebodocs/react';
const button = 'rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm aria-pressed:bg-blue-100 disabled:opacity-40';
function Bold() {
const { state, commands } = useDocs();
return (
<button className={`${button} font-bold`} aria-pressed={state.bold} onClick={() => commands.toggleMark('bold')}>
B
</button>
);
}
function FontSize() {
const { state, commands } = useDocs();
return (
<select aria-label="Font size" className={button} value={state.fontSize} onChange={(e) => commands.setRunProps({ fontSize: Number(e.target.value) })}>
{[10, 11, 12, 14, 18, 24, 26].map((size) => (
<option key={size}>{size}</option>
))}
</select>
);
}
function Save() {
const { state, docs } = useDocs();
return (
<>
<button className={button} disabled={!state.dirty} onClick={() => docs?.save()}>
Save
</button>
<button className={button} disabled={!docs} onClick={() => docs?.download()}>
Word
</button>
</>
);
}试一试
Hook 的实时返回值
全部返回内容
- value
- select 返回的任意值,以 JSON 比较
解构
const pages = useDocsValue((editor) => editor.pageCount, 1);
const hasToc = useDocsValue((editor) => editor.hasToc, false);
const cell = useDocsValue((editor) => editor.activeCellProps() ?? null, null);返回普通数据;编辑器返回 undefined 的地方请返回 null。只保留第一次传入的 fallback。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocs, useDocsValue } from '@rebodocs/react';
function SpaceAfter() {
const { commands } = useDocs();
const spaced = useDocsValue((e) => e.activeParagraphProps().spacingAfter > 0, false);
return (
<button
className="rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm aria-pressed:bg-blue-100"
aria-pressed={spaced}
onClick={() => commands.setParagraphProps({ spacingAfter: spaced ? 0 : 8 })}
>
Space after
</button>
);
}试一试
Hook 的实时返回值
全部返回内容
- words
- 文档字数
- characters
- 文档字符数
- selected
- 选区的相同统计,或 undefined
解构
const { words, characters, selected } = useDocsCount();使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsCount } from '@rebodocs/react';
function Count() {
const { words, characters, selected } = useDocsCount();
return (
<span className="text-sm text-neutral-600">
{selected ? `${selected.words} of ${words} words` : `${words} words`} · {characters} characters
</span>
);
}试一试
Hook 的实时返回值
全部返回内容
- query · setQuery(text)
- 搜索内容
- options · setOptions(o)
- { matchCase, wholeWord }
- count · index
- 匹配数量,以及当前选中的是第几个(从 1 开始)
- next() · previous()
- 跳到另一个
- replace(text) · replaceAll(text)
- 替换当前项,或一次替换全部(可一步撤销)
- close()
- 结束搜索并交还键盘焦点
解构
const { query, setQuery, options, setOptions, count, index, next, previous, replace, replaceAll, close } = useDocsFind();query 和 options 由调用它的组件保存:只在查找栏中调用一次,再向下传递。count 和 index 属于文档。在 provider 上设置 onFindKey,即可用 ⌘F 打开查找栏。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsFind } from '@rebodocs/react';
import { useState } from 'react';
const field = 'w-32 rounded-md border border-neutral-300 px-2 py-1 text-sm';
const button = 'rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm aria-pressed:bg-blue-100 disabled:opacity-40';
function FindBar({ onClose }: { onClose: () => void }) {
const find = useDocsFind();
const [replacement, setReplacement] = useState('');
const close = () => {
find.close();
onClose();
};
return (
<div role="search" className="flex flex-wrap items-center gap-1.5">
<input
aria-label="Find"
className={field}
value={find.query}
onChange={(e) => find.setQuery(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') (e.shiftKey ? find.previous : find.next)();
if (e.key === 'Escape') close();
}}
/>
<button className={button} aria-pressed={!!find.options.matchCase} onClick={() => find.setOptions({ ...find.options, matchCase: !find.options.matchCase })}>
Aa
</button>
<span className="text-sm text-neutral-600">{find.count ? `${find.index} of ${find.count}` : 'Nothing found'}</span>
<input aria-label="Replace with" className={field} value={replacement} onChange={(e) => setReplacement(e.target.value)} />
<button className={button} disabled={!find.count} onClick={() => find.replace(replacement)}>
Replace
</button>
<button className={button} disabled={!find.count} onClick={() => find.replaceAll(replacement)}>
All
</button>
<button className={button} onClick={close}>
Close
</button>
</div>
);
}试一试
Hook 的实时返回值
全部返回内容
- active
- 光标处链接的 { href, text }
- possible
- 是否有可以添加链接的内容
- set(address)
- 为选区添加链接;不是有效地址时返回 false
- remove() · open()
- 移除链接;在新标签页中打开
解构
const { active, possible, set, remove, open } = useDocsLink();使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsLink } from '@rebodocs/react';
function LinkButton() {
const link = useDocsLink();
const ask = () => {
const address = window.prompt('Address', link.active?.href ?? 'https://');
if (address === null) return;
if (address === '') link.remove();
else if (!link.set(address)) window.alert('That is not an address.');
};
return (
<button
className="rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm aria-pressed:bg-blue-100 disabled:opacity-40"
aria-pressed={!!link.active}
disabled={!link.possible}
onClick={ask}
>
Link
</button>
);
}试一试
Hook 的实时返回值
全部返回内容
- notes
- 每条为 { id, author, date, text, excerpt, color }
- active
- 光标所在批注的 id
- add(text)
- 在选区上添加批注;返回其 id
- setText(id, text) · setColor(id, color) · remove(id)
- 修改某条批注
- removeAll()
- 删除所有批注,一步即可撤销
- select(id)
- 选中批注对应的文字并滚动到可见位置
解构
const { notes, active, add, setText, setColor, remove, removeAll, select } = useDocsNotes();同时导出了 NOTE_COLORS。commands.setShowNotes(true) 会在页面旁显示批注。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { NOTE_COLORS, useDocsNotes } from '@rebodocs/react';
function Notes() {
const notes = useDocsNotes();
return (
<div className="grid gap-2">
<button className="rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm" onClick={() => notes.add('Check this')}>
Note on the selection
</button>
{notes.notes.length > 0 && (
<button className="rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm text-red-700" onClick={() => notes.removeAll()}>
Delete all notes
</button>
)}
{notes.notes.map((note) => (
<article key={note.id} className="grid gap-1.5 rounded-md border border-neutral-200 p-2" style={{ borderLeft: `4px solid #${note.color}` }}>
<button className="truncate text-left text-xs text-neutral-600" onClick={() => notes.select(note.id)}>
“{note.excerpt}”
</button>
<textarea aria-label="Note" className="rounded border border-neutral-300 p-1 text-sm" value={note.text} onChange={(e) => notes.setText(note.id, e.target.value)} />
<div className="flex gap-1">
{NOTE_COLORS.map((color) => (
<button key={color} aria-label={`#${color}`} className="size-5 rounded-full" style={{ background: `#${color}` }} onClick={() => notes.setColor(note.id, color)} />
))}
<button className="ml-auto text-xs text-red-700" onClick={() => notes.remove(note.id)}>
Delete
</button>
</div>
</article>
))}
</div>
);
}试一试
Hook 的实时返回值
全部返回内容
- names · active
- 每个变量各一次,以及光标处的变量
- insert(name) · select(name)
- 在光标处插入变量;跳到变量所在位置
- fill(values)
- 一次填写全部变量(可一步撤销)
- blocks
- {{#名称}} … {{/名称}} 区块:每个包含名称和类型
- formats · uses
- 按名称:格式,以及使用次数
- setFormat(name, id, on, arg?)
- date、number、currency、upper、bold…
- preview(name, value)
- { text, bad }:值最终会写成什么样
解构
const { names, active, insert, select, fill, blocks, formats, uses, setFormat, preview } = useDocsVariables();使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsVariables } from '@rebodocs/react';
import { useState } from 'react';
function Variables() {
const variables = useDocsVariables();
const [values, setValues] = useState<Record<string, string>>({});
return (
<form
className="grid gap-2"
onSubmit={(e) => {
e.preventDefault();
variables.fill(values);
}}
>
{variables.names.map((name) => {
const money = variables.formats[name]?.some((format) => format.id === 'currency') ?? false;
const { text, bad } = variables.preview(name, values[name] ?? '');
return (
<label key={name} className="grid gap-0.5 text-xs text-neutral-600">
{name}
<span className="flex gap-1">
<input
className="min-w-0 flex-1 rounded border border-neutral-300 px-1.5 py-0.5 text-sm text-black"
value={values[name] ?? ''}
onFocus={() => variables.select(name)}
onChange={(e) => setValues({ ...values, [name]: e.target.value })}
/>
<button type="button" className="rounded border border-neutral-300 px-1.5 aria-pressed:bg-blue-100" aria-pressed={money} onClick={() => variables.setFormat(name, 'currency', !money)}>
$
</button>
</span>
<small className={bad ? 'text-red-700' : ''}>{bad ? 'Not what its format is for' : text}</small>
</label>
);
})}
<button className="rounded-md bg-blue-700 px-2.5 py-1 text-sm text-white">Fill</button>
</form>
);
}试一试
Hook 的实时返回值
全部返回内容
- styles
- 每个为 { id, name },默认样式排在最前
- active
- 选区的样式;混合时为 undefined
- set(id)
- 为段落应用样式
解构
const { styles, active, set } = useDocsStyles();使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsStyles } from '@rebodocs/react';
function Style() {
const { styles, active, set } = useDocsStyles();
return (
<select aria-label="Style" className="rounded-md border border-neutral-300 bg-white px-2 py-1 text-sm" value={active ?? ''} onChange={(e) => set(e.target.value)}>
{active === undefined && <option value="">Mixed</option>}
{styles.map((style) => (
<option key={style.id} value={style.id}>
{style.name}
</option>
))}
</select>
);
}试一试
Hook 的实时返回值
全部返回内容
- items
- 每项为 { para, level, text };level 0 为文档标题
- active
- 光标所在的那一项,或 -1
- goTo(item)
- 把光标移到该处
- move(item, before?)
- 移动某个标题及其下的全部内容
解构
const { items, active, goTo, move } = useDocsOutline();commands.insertToc() 和 commands.updateToc() 负责目录。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsOutline } from '@rebodocs/react';
function Outline() {
const { items, active, goTo } = useDocsOutline();
return (
<nav className="grid">
{items.map((item, i) => (
<button
key={item.para}
aria-current={i === active}
className="truncate rounded px-1.5 py-1 text-left text-sm aria-[current=true]:bg-blue-100 aria-[current=true]:font-semibold"
style={{ paddingLeft: 6 + item.level * 12 }}
onClick={() => goTo(item)}
>
{item.text}
</button>
))}
</nav>
);
}试一试
Hook 的实时返回值
全部返回内容
- page · set(patch, everywhere?)
- 宽度、高度和页边距,以磅为单位
- sections · section
- 分节数量,以及正在编辑的是哪一节
- ownHeaders · setOwnHeaders(on)
- 本节独立的页眉和页脚
- numbering · setNumbering(n)
- { place, align, format },或 undefined
- firstPageDifferent · setFirstPageDifferent(on)
- 首页使用不同的页眉
- endnotesAt · setEndnotesAt(at)
- 'document' 或 'sections':尾注放在哪里
- noteNumbering · setNoteNumbering(kind, n)
- 本节脚注和尾注的编号方式:{ format, start, restart },或 undefined
- letterhead · setLetterhead(file, fit?)
- 是否有信头;用 PNG 或 JPG 设置信头
- fitLetterheadMargins() · removeLetterhead() · letterheadFile()
- 调整页边距避开信头;移除信头;获取信头图片以便下载
解构
const { page, set, sections, section, ownHeaders, setOwnHeaders, numbering, setNumbering, firstPageDifferent, setFirstPageDifferent, endnotesAt, setEndnotesAt, noteNumbering, setNoteNumbering, letterhead, setLetterhead, fitLetterheadMargins, removeLetterhead, letterheadFile } = useDocsPage();Letter 为 612 × 792 磅,A4 为 595.3 × 841.9 磅。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsPage } from '@rebodocs/react';
const CM = 72 / 2.54;
const button = 'rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm aria-pressed:bg-blue-100';
function PageSetup() {
const { page, set, numbering, setNumbering } = useDocsPage();
if (!page) return null;
return (
<div className="flex flex-wrap items-center gap-1.5">
<button className={button} onClick={() => set({ width: page.height, height: page.width })}>
Turn
</button>
<label className="text-sm text-neutral-600">
Left margin, cm{' '}
<input
type="number"
step="0.1"
className="w-16 rounded border border-neutral-300 px-1 py-0.5"
value={(page.marginLeft / CM).toFixed(1)}
onChange={(e) => set({ marginLeft: e.target.valueAsNumber * CM })}
/>
</label>
<button className={button} aria-pressed={!!numbering} onClick={() => setNumbering(numbering ? undefined : { place: 'footer', align: 'center', format: 'pageOfTotal' })}>
Page numbers
</button>
</div>
);
}试一试
Hook 的实时返回值
全部返回内容
- top · left · width · height
- 以像素为单位;没有选区时为 undefined
解构
const box = useDocsSelectionBox();
if (!box) return null;
// put your popover at box.top - 44, box.left在你的工具条上设置 onMouseDown={(e) => e.preventDefault()},可防止点击时丢失选区。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocs, useDocsSelectionBox } from '@rebodocs/react';
function FloatingBar() {
const box = useDocsSelectionBox();
const { state, commands } = useDocs();
if (!box || state.collapsed) return null;
return (
<div className="fixed z-10 flex gap-1 rounded-lg bg-neutral-900 p-1 shadow-lg" style={{ top: box.top - 44, left: box.left }} onMouseDown={(e) => e.preventDefault()}>
<button className="rounded px-2 py-0.5 text-sm font-bold text-white hover:bg-white/15" onClick={() => commands.toggleMark('bold')}>
B
</button>
<button className="rounded px-2 py-0.5 text-sm text-white hover:bg-white/15" onClick={() => commands.copy()}>
Copy
</button>
</div>
);
}试一试
Hook 的实时返回值
全部返回内容
- open() · close() · toggle()
- 显示和隐藏
- ask(kind)
- 'variable'、'note' 或 'link'
解构
const bubble = useDocsBubble(); // undefined without bubble
bubble?.ask('note');它自带外观,并放在 document.body 中:请在那里用 --dx-ui-… 变量设置颜色(参见“样式”)。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { useDocsBubble } from '@rebodocs/react';
const button = 'rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm';
function Insert() {
const bubble = useDocsBubble();
return (
<div className="flex gap-1.5">
<button className={button} onClick={() => bubble?.ask('variable')}>
Variable
</button>
<button className={button} onClick={() => bubble?.ask('note')}>
Note
</button>
<button className={button} onClick={() => bubble?.ask('link')}>
Link
</button>
</div>
);
}
// Its colours, through variables on the body, where it is put:
// body { --dx-ui-bg: #323232; --dx-ui-ink: #eee; --dx-ui-line: #505050; --dx-ui-active: #4a4a4a; }试一试
Hook 的实时返回值
全部返回内容
- narrow
- surface 宽度小于给定值时为 true
- keyboard
- 屏幕键盘遮挡的像素数
解构
const { narrow, keyboard } = useDocsResponsive(600);用媒体查询决定布局,而不是用 narrow:否则两者会相互抵消。
使用
上方运行的部件,与其文件中的代码一致:可以放在 DocsProvider 内的任何位置。
import { DocsSurface, useDocsResponsive } from '@rebodocs/react';
import type { ReactNode } from 'react';
function Editor({ toolbar }: { toolbar: ReactNode }) {
const { keyboard } = useDocsResponsive(600);
return (
<div className="flex h-dvh flex-col" style={{ paddingBottom: keyboard }}>
{toolbar}
<DocsSurface className="min-h-0 flex-1" />
</div>
);
}语言与字体
它们不是 hooks,但常与 hooks 配合使用:库所输出文字的语言,以及可用的字体。参见语言和字体。
setLocale(code)getLocale()onLocaleChange(fn)addLocale(code, texts)locales()messages(locale)t(key)plural(key, n)fontFamilies()addFont(source)addFonts(sources)onFontsChange(fn)createSpellChecker(options)版本与助手
在 DocsEditor 上提供 versions 后,侧边栏可以对比和还原版本。如果要自己绘制这个面板,或把一个 DOCX 作为共享房间中的一次普通修改打开,请使用这些函数;createAssistantChat 则会把 Claude 放进你自己的聊天中处理文档。参见版本和AI 助手。
createVersionView(editor, versions)loadVersion(versions, id)compareDocs(before, after)createAssistantChat(editor, options)不用 React
mountDocs(来自 @rebodocs/react/mount)会把完整编辑器放进一个元素,并返回带有 destroy() 的句柄。createDocs 只放入页面,提供 state()、commands、editor、subscribe(fn) 和 setKeys。