本文档涵盖 Plate 直至 v48 版本的重大破坏性变更。最新迁移指南请参阅最新迁移文档。补丁和次要版本变更请参考各包的 CHANGELOG.md 文件或访问 GitHub Releases 页面。
48.0.0
@udecode/plate-core@48.0.0
-
PlateElement、PlateLeaf和PlateText的 HTML 属性从顶层 props 移至attributesprop,除了className、style和as。迁移方式:
// 之前 <PlateElement {...props} ref={ref} contentEditable={false} > {children} </PlateElement> // 之后 <PlateElement {...props} ref={ref} attributes={{ ...props.attributes, contentEditable: false, }} > {children} </PlateElement>- 移除
PlateElement、PlateLeaf、PlateText的nodePropsprop,已合并至attributesprop。 - 插件的
node.props应直接返回 props 而非包裹在nodeProps对象中。迁移方式:
// 之前 node: { props: ({ element }) => ({ nodeProps: { colSpan: element?.attributes?.colspan, rowSpan: element?.attributes?.rowspan, }, }); } // 之后 node: { props: ({ element }) => ({ colSpan: element?.attributes?.colspan, rowSpan: element?.attributes?.rowspan, }); }- 移除
PlateElement、PlateLeaf、PlateText的asChildprop,改用asprop。 - 移除
PlateElement、PlateLeaf、PlateText的elementToAttributes、leafToAttributes、textToAttributesprops。 - 移除
DefaultElement、DefaultLeaf、DefaultText,改用PlateElement、PlateLeaf、PlateText。 - 类型:移除
PlateRenderElementProps、PlateRenderLeafProps、PlateRenderTextProps,改用PlateElementProps、PlateLeafProps、PlateTextProps。
@udecode/plate-utils@48.0.0
- #4281 by @zbeyens –
- 将
PlateElement、PlateLeaf、PlateText移至@udecode/plate-core。若从@udecode/plate导入则无需迁移。
- 将
@udecode/plate-yjs@48.0.0
-
#4225 by @bbyiringiro –
- 新增多 provider 支持以增强协作功能:现可同时使用 Hocuspocus 和 WebRTC,共享同一个 Y.Doc。
- 迁移:将
hocuspocusProviderOptions替换为新的providers数组。示例如下。
- 迁移:将
之前:
YjsPlugin.configure({ options: { cursorOptions: { /* ... */ }, hocuspocusProviderOptions: { url: 'wss://hocuspocus.example.com', name: 'document-1', // ... 其他 Hocuspocus 选项 }, }, });之后(仅 Hocuspocus):
YjsPlugin.configure({ options: { cursors: { /* ... */ }, providers: [ { type: 'hocuspocus', options: { url: 'wss://hocuspocus.example.com', name: 'document-1', // ... 其他 Hocuspocus 选项 }, }, ], }, });之后(Hocuspocus + WebRTC):
YjsPlugin.configure({ options: { cursors: { /* ... */ }, providers: [ { type: 'hocuspocus', options: { url: 'wss://hocuspocus.example.com', name: 'document-1', }, }, { type: 'webrtc', options: { roomName: 'document-1', // signaling: ['wss://signaling.example.com'], // 可选 }, }, ], }, });- 引入
UnifiedProvider接口,支持自定义 provider 实现(如 IndexedDB 用于离线持久化)。 - 将
cursorOptions重命名为cursors。 - 将
yjsOptions合并至options。- 迁移:将原先位于
yjsOptions下的选项直接移至主options对象。
- 迁移:将原先位于
- 移除
YjsAboveEditable。现在需要手动调用init和destroy:
React.useEffect(() => { if (!mounted) return; // 初始化 Yjs 连接和同步 editor.getApi(YjsPlugin).yjs.init({ id: roomName, // 或你的文档标识符 value: INITIAL_VALUE, // 编辑器初始内容 }); // 组件卸载时销毁连接 return () => { editor.getApi(YjsPlugin).yjs.destroy(); }; }, [editor, mounted, roomName]); // 添加相关依赖 - 新增多 provider 支持以增强协作功能:现可同时使用 Hocuspocus 和 WebRTC,共享同一个 Y.Doc。
47.0.0
@udecode/plate-markdown
-
#4174 by @felixfeng33 – #### 新特性
- 新增数学类型反序列化支持
- 默认下划线标记序列化为
<u>underline</u> - 改进序列化流程:
- 现采用两步流程:
slate nodes => MDAST nodes => markdown string - 之前:直接从 Slate 节点转换为 markdown 字符串
- 结果更可靠且健壮
- 现采用两步流程:
- 新增节点过滤选项:
allowedNodes:白名单特定节点disallowedNodes:黑名单特定节点allowNode:自定义过滤函数
- 新增
rules选项用于自定义序列化和反序列化规则,包括自定义 mdx 支持 - 新增
remarkPlugins选项以使用 remark 插件
破坏性变更
插件选项
移除的选项:
elementRules改用rulestextRules改用rulesindentList现自动检测是否使用了 IndentList 插件splitLineBreaks仅用于反序列化
反序列化
- 移除
elementRules和textRules选项- 改用
rules.key.deserialize - 参见 节点文档
- 改用
迁移示例:
export const markdownPlugin = MarkdownPlugin.configure({ options: { disallowedNodes: [SuggestionPlugin.key], rules: { // 对应 textRules [BoldPlugin.key]: { mark: true, deserialize: (mdastNode) => ({ bold: true, text: node.value || '', }), }, // 对应 elementRules [EquationPlugin.key]: { deserialize: (mdastNode, options) => ({ children: [{ text: '' }], texExpression: node.value, type: EquationPlugin.key, }), }, }, remarkPlugins: [remarkMath, remarkGfm], }, });- 移除
editor.api.markdown.deserialize中的 processor- 改用
remarkPlugins
- 改用
序列化
- 移除
serializeMdNodes- 改用
editor.markdown.serialize({ value: nodes })
- 改用
- 移除
SerializeMdOptions因采用新序列化流程- 之前流程:
slate nodes => md - 新流程:
slate nodes => md-ast => md
- 之前流程:
- 移除的选项:
nodesbreakTagcustomNodesignoreParagraphNewlinelistDepthmarkFormatsulListStyleTypesignoreSuggestionType
迁移
SerializeMdOptions.customNodes和SerializeMdOptions.nodes的示例:export const markdownPlugin = MarkdownPlugin.configure({ options: { rules: { // 忽略所有 `insert` 类型的建议 [SuggestionPlugin.key]: { mark: true, serialize: (slateNode: TSuggestionText, options): mdast.Text => { const suggestionData = options.editor .getApi(SuggestionPlugin) .suggestion.suggestionData(node); return suggestionData?.type === 'insert' ? { type: 'text', value: '' } : { type: 'text', value: node.text }; }, }, // 对应 elementRules [EquationPlugin.key]: { serialize: (slateNode) => ({ type: 'math', value: node.texExpression, }), }, }, remarkPlugins: [remarkMath, remarkGfm], }, });
46.0.0
@udecode/plate-code-block@46.0.0
-
#4122 by @zbeyens – 从
prismjs迁移至highlight.js+lowlight实现语法高亮。- 修复多行标记的高亮问题。之前是按行计算标记,现在是对整个代码块一次性计算。
- 显著减少包体积。
CodeBlockPlugin:移除prism选项,改用lowlight选项:
import { all, createLowlight } from 'lowlight'; const lowlight = createLowlight(all); CodeBlockPlugin.configure({ options: { lowlight, }, });- 新增选项:
defaultLanguage - 移除
syntax选项。省略lowlight选项即可禁用语法高亮。 - 移除
syntaxPopularFirst选项。在自定义组件中控制此行为。 - 修复在代码块内粘贴代码的问题。
- 移除
useCodeBlockCombobox、useCodeBlockElement、useCodeSyntaxLeaf、useToggleCodeBlockButton。相关逻辑已移至组件中。
45.0.0
@udecode/plate-comments@45.0.0
-
#4064 by @felixfeng33 – 本次重写移除了评论插件的 UI 逻辑(无头化)。
插件选项
- 移除插件选项中的配置项,改为组件级控制:
options.commentsoptions.myUserIdoptions.users
组件
- 移除旧组件:
CommentDeleteButtonCommentEditActionsCommentEditButtonCommentEditCancelButtonCommentEditSaveButtonCommentEditTextareaCommentNewSubmitButtonCommentNewTextareaCommentResolveButtonCommentsPositionerCommentUserName
API
- 移除以下函数,改用新 API 方法:
findCommentNode→api.comment.node()findCommentNodeById→api.comment.node({ id })getCommentNodeEntries→api.comment.nodes()getCommentNodesById→api.comment.nodes({ id })removeCommentMark→tf.comment.remove()unsetCommentNodesById→tf.comment.unsetMark({ id })
- 移除未使用的函数:
getCommentFragmentgetCommentUrlgetElementAbsolutePositiongetCommentPosition
- 更新
getCommentCount以排除草稿评论
状态管理
- 移除
CommentProvider- 用户应自行实现状态管理 –block-discussion.tsx - 将
useHooksComments移至 UI 注册表 –comments-plugin.tsx - 移除新 UI 不再需要的钩子:
useActiveCommentNodeuseCommentsResolveduseCommentAddButtonuseCommentItemContentuseCommentLeafuseCommentsShowResolvedButtonuseFloatingCommentsContentStateuseFloatingCommentsState
类型
- 移除
CommentUser - 将
TComment移至 UI 注册表 –comment.tsx
- 移除插件选项中的配置项,改为组件级控制:
@udecode/plate-suggestion@45.0.0
-
#4064 by @felixfeng33 – 注意:此插件目前处于实验阶段,可能在不升级主版本的情况下引入破坏性变更。
- 新增 Suggestion UI
- 移除:
findSuggestionNode改用findSuggestionProps.ts - 移除
addSuggestionMark.ts - 移除
useHooksSuggestion.ts因我们已更新 activeId 逻辑不再依赖 useEditorSelector
44.0.1
@udecode/plate-core@44.0.0
-
- 支持 React 19
- 升级至
zustand-x@6eventEditorSelectors->EventEditorStore.geteventEditorActions->EventEditorStore.setuseEventEditorSelectors->useEventEditorValue(key)
- 升级至
jotai-x@2usePlateEditorStore->usePlateStoreusePlateActions->usePlateSet- 移除
editor.setPlateState,改用usePlateSet usePlateSelectors->usePlateValueusePlateStates->usePlateState
- 将插件选项钩子拆分为独立钩子以兼容 React Compiler
editor.useOption,ctx.useOption->usePluginOption(plugin, key, ...args)editor.useOptions,ctx.useOptions->usePluginOption(plugin, 'state')- 新钩子
usePluginOptions(plugin, selector)用于选择插件选项(Zustand 方式)。
- 我们之前支持通过
extendOptions向插件添加选择器。这些选择器与选项状态混合,可能导致冲突和混淆。- 插件方法重命名为
extendSelectors - 选择器现在内部存储在
plugin.selectors而非plugin.options中,但访问方式不变:使用editor.getOption(plugin, 'selectorName')、ctx.getOption('selectorName')或上述钩子。 - 选择器类型不再位于
PluginConfig的第二个泛型参数中,我们新增第五个泛型参数用于此。
- 插件方法重命名为
// 之前: export type BlockSelectionConfig = PluginConfig< 'blockSelection', { selectedIds?: Set<string>; } & BlockSelectionSelectors, >; // 之后: export type BlockSelectionConfig = PluginConfig< 'blockSelection', { selectedIds?: Set<string>; }, {}, // API {}, // Transforms BlockSelectionSelectors, // Selectors }>
@udecode/plate-comments@44.0.0
@udecode/plate-media@44.0.0
On This Page
48.0.0@udecode/plate-core@48.0.0@udecode/plate-utils@48.0.0@udecode/plate-yjs@48.0.047.0.0@udecode/plate-markdown破坏性变更反序列化序列化46.0.0@udecode/plate-code-block@46.0.045.0.0@udecode/plate-comments@45.0.0@udecode/plate-suggestion@45.0.044.0.1@udecode/plate-core@44.0.0@udecode/plate-comments@44.0.0@udecode/plate-media@44.0.0