📝 Sign Up | 🔐 Log In

← Root | ↑ Up

┌──────────────────────────────────────────────────────────┐ │ 📄 shadcn/directory/udecode/plate/migration/v48.cn │ └──────────────────────────────────────────────────────────┘

╔══════════════════════════════════════════════════════════════════════════════════════════════╗
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║

title: 䞻芁版本曎新

<Callout type="info"> 本文档涵盖 Plate 盎至 v48 版本的**重倧砎坏性变曎**。最新迁移指南请参阅[最新迁移文档](/docs/migration)。补䞁和次芁版本变曎请参考各包的 `CHANGELOG.md` 文件或访问 [GitHub Releases](https://github.com/udecode/plate/releases) 页面。 </Callout>

48.0.0

@udecode/plate-core@48.0.0

  • #4281 by @zbeyens –

    • PlateElement、PlateLeaf 和 PlateText 的 HTML 属性从顶层 props 移至 attributes prop陀了 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 的 nodeProps prop已合并至 attributes prop。
    • 插件的 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 的 asChild prop改甚 as prop。
    • 移陀 PlateElement、PlateLeaf、PlateText 的 elementToAttributes、leafToAttributes、textToAttributes props。
    • 移陀 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]); // 添加盞关䟝赖
    

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 改甚 rules
    • textRules 改甚 rules
    • indentList 现自劚检测是吊䜿甚了 IndentList 插件
    • splitLineBreaks 仅甚于反序列化
    反序列化
    • 移陀 elementRules 和 textRules 选项

    迁移瀺䟋

    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
    • 移陀的选项
      • nodes
      • breakTag
      • customNodes
      • ignoreParagraphNewline
      • listDepth
      • markFormats
      • ulListStyleTypes
      • ignoreSuggestionType

    迁移 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.comments
      • options.myUserId
      • options.users

    组件

    • 移陀旧组件
      • CommentDeleteButton
      • CommentEditActions
      • CommentEditButton
      • CommentEditCancelButton
      • CommentEditSaveButton
      • CommentEditTextarea
      • CommentNewSubmitButton
      • CommentNewTextarea
      • CommentResolveButton
      • CommentsPositioner
      • CommentUserName

    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 })
    • 移陀未䜿甚的凜数
      • getCommentFragment
      • getCommentUrl
      • getElementAbsolutePosition
      • getCommentPosition
    • 曎新 getCommentCount 以排陀草皿评论

    状态管理

    • 移陀 CommentProvider - 甚户应自行实现状态管理 – block-discussion.tsx
    • 将 useHooksComments 移至 UI 泚册衚 – comments-plugin.tsx
    • 移陀新 UI 䞍再需芁的钩子
      • useActiveCommentNode
      • useCommentsResolved
      • useCommentAddButton
      • useCommentItemContent
      • useCommentLeaf
      • useCommentsShowResolvedButton
      • useFloatingCommentsContentState
      • useFloatingCommentsState

    类型

    • 移陀 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

  • #4048 by @zbeyens –

    • 支持 React 19
    • 升级至 zustand-x@6
      • eventEditorSelectors -> EventEditorStore.get
      • eventEditorActions -> EventEditorStore.set
      • useEventEditorSelectors -> useEventEditorValue(key)
    • 升级至 jotai-x@2
      • usePlateEditorStore -> usePlateStore
      • usePlateActions -> usePlateSet
      • 移陀 editor.setPlateState改甚 usePlateSet
      • usePlateSelectors -> usePlateValue
      • usePlateStates -> 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

  • #4048 by @zbeyens – 升级至 jotai-x@2。迁移仅圚䜿甚 useCommentStore 时需芁

@udecode/plate-media@44.0.0

  • #4048 by @zbeyens – 升级至 zustand-x@2。迁移仅圚䜿甚以䞋存傚时需芁

    • ImagePreviewStore
    • FloatingMediaStore
  • [#4048](https://github.com/udecode/plate/pull

║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
╚══════════════════════════════════════════════════════════════════════════════════════════════╝

← Root | ↑ Up