Skip to content

Commit 8a9ae7d

Browse files
authored
Merge pull request #3948 from udecode/fix/indent-list
Fix/indent list
2 parents 9f378d0 + f37dbd1 commit 8a9ae7d

File tree

130 files changed

+1369
-1684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1369
-1684
lines changed

.changeset/lazy-cats-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@udecode/plate-core': patch
3+
---
4+
5+
Fix: deserialization should work with custom node types

.changeset/sharp-bats-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@udecode/plate-indent-list': patch
3+
---
4+
5+
Fix merging and renumbering of lists when deleting empty paragraphs between them (both backward and forward deletion)

.changeset/slate.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@udecode/slate': patch
3+
---
4+
5+
- Fix `deselect`, `deselectDOM` methods
6+
- Remove all `LegacyEditorMethods` from `Editor`

BREAKING_CHANGES.md

Lines changed: 625 additions & 0 deletions
Large diffs are not rendered by default.

apps/www/content/docs/cn/api/core.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ description: udecode/plate-core的 API 参考。
455455

456456
有关更多详细信息,请参阅[调试](/docs/debugging)
457457

458-
### SlateNextPlugin
458+
### SlateExtensionPlugin & SlateReactExtensionPlugin
459459
扩展核心 API 并改进默认功能。
460460

461461
### DOMPlugin & ReactPlugin
@@ -485,9 +485,6 @@ description: udecode/plate-core的 API 参考。
485485
### EventEditorPlugin
486486
管理编辑器事件,如焦点和模糊。
487487

488-
### PlateApiPlugin
489-
提供 Plate 编辑器功能的核心 API。
490-
491488
## Utils
492489

493490
### isType

apps/www/content/docs/cn/api/core/plate-editor.mdx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,55 +36,55 @@ description: Plate 编辑器的 API 参考。
3636
## API Methods
3737

3838
<APIParameters>
39-
<APIItem name="getApi" type="<C extends AnyPluginConfig = PluginConfig>(plugin?: WithRequiredKey<C>) => InferApi<C>">
39+
<APIItem name="getApi" type="(plugin: PlatePlugin) => EditorApi & PlatePlugin['api']">
4040
获取插件的类型化 API。
4141
</APIItem>
42-
<APIItem name="getTransforms" type="<C extends AnyPluginConfig = PluginConfig>(plugin?: WithRequiredKey<C>) => InferTransforms<C>">
42+
<APIItem name="getTransforms" type="(plugin: PlatePlugin) => EditorTransforms & PlatePlugin['transforms']">
4343
获取插件的类型化变换。
4444
</APIItem>
45-
<APIItem name="getPlugin" type="<C extends AnyPluginConfig = PluginConfig>(plugin: WithRequiredKey<C>) => C extends { node: any } ? C : EditorPlatePlugin<C>">
45+
<APIItem name="getPlugin" type="(plugin: PlatePlugin) => PlatePlugin">
4646
通过键或基础插件获取编辑器插件实例。
4747
</APIItem>
48-
<APIItem name="getType" type="(plugin: WithRequiredKey) => string">
48+
<APIItem name="getType" type="(plugin: PlatePlugin) => string">
4949
获取插件的节点类型。
5050
</APIItem>
5151
</APIParameters>
5252

5353
## Option Methods
5454

5555
<APIParameters>
56-
<APIItem name="getOption" type="<C extends AnyPluginConfig, K extends keyof InferOptions<C>, F extends InferOptions<C>[K]>(plugin: WithRequiredKey<C>, optionKey: K, ...args: F extends (...args: infer A) => any ? A : never) => F extends (...args: any[]) => infer R ? R : F">
56+
<APIItem name="getOption" type="(plugin: PlatePlugin, optionKey: string) => any">
5757
获取插件的特定选项值。
5858
</APIItem>
59-
<APIItem name="getOptions" type="<C extends AnyPluginConfig = PluginConfig>(plugin: WithRequiredKey<C>) => InferOptions<C>">
59+
<APIItem name="getOptions" type="(plugin: PlatePlugin) => any">
6060
获取插件的所有选项。
6161
</APIItem>
62-
<APIItem name="setOption" type="<C extends AnyPluginConfig, K extends keyof InferOptions<C>>(plugin: WithRequiredKey<C>, optionKey: K, value: InferOptions<C>[K]) => void">
62+
<APIItem name="setOption" type="(plugin: PlatePlugin, optionKey: string, value: any) => void">
6363
设置插件的特定选项值。
6464
</APIItem>
65-
<APIItem name="setOptions" type="<C extends AnyPluginConfig>(plugin: WithRequiredKey<C>, options: Parameters<SetImmerState<InferOptions<C>>>[0] | Partial<InferOptions<C>>) => void">
65+
<APIItem name="setOptions" type="(plugin: PlatePlugin, options: (draft: object) => void | Partial<object>) => void">
6666
设置插件的多个选项。
6767
</APIItem>
68-
<APIItem name="getOptionsStore" type="<C extends AnyPluginConfig>(plugin: WithRequiredKey<C>) => StoreApi<C['key'], InferOptions<C>>">
68+
<APIItem name="getOptionsStore" type="(plugin: PlatePlugin) => any">
6969
获取插件的 zustand-x 选项存储。
7070
</APIItem>
7171
</APIParameters>
7272

7373
## React Hooks
7474

7575
<APIParameters>
76-
<APIItem name="useOption" type="<C extends AnyPluginConfig, K extends keyof InferOptions<C>, F extends InferOptions<C>[K], Args extends Parameters<((...args: any[]) => any) & F>>(plugin: WithRequiredKey<C>, optionKey: K, ...args: Args) => F extends (...args: any[]) => any ? ReturnType<F> : F">
76+
<APIItem name="useOption" type="(plugin: PlatePlugin, optionKey: string) => any">
7777
在 React 组件中订阅特定选项值。
7878
</APIItem>
79-
<APIItem name="useOptions" type="<C extends AnyPluginConfig, U>(plugin: WithRequiredKey<C>, selector?: (s: InferOptions<C>) => U, equalityFn?: EqualityChecker<U>) => U | InferOptions<C>">
79+
<APIItem name="useOptions" type="(plugin: PlatePlugin) => any">
8080
在 React 组件中订阅插件选项或派生自选项的值。
8181
</APIItem>
8282
</APIParameters>
8383

8484
## Plate Store Methods
8585

8686
<APIParameters>
87-
<APIItem name="setPlateState" type="<K extends (typeof EXPOSED_STORE_KEYS)[number]>(optionKey: K, value: PlateStoreState[K]) => void">
87+
<APIItem name="setPlateState" type="(optionKey: string, value: PlateStoreState[K]) => void">
8888
更新全局 Plate 状态。
8989
</APIItem>
9090
</APIParameters>
@@ -108,17 +108,6 @@ description: Plate 编辑器的 API 参考。
108108
</APIItem>
109109
</APIParameters>
110110

111-
### SlateNextPlugin
112-
113-
<APIParameters>
114-
<APIItem name="editor.tf.toggle.block" type="(options: ToggleBlockOptions) => void">
115-
切换一个块元素。
116-
</APIItem>
117-
<APIItem name="editor.tf.toggle.mark" type="(options: ToggleMarkOptions) => void">
118-
切换选中文本上的标记。
119-
</APIItem>
120-
</APIParameters>
121-
122111
### HtmlPlugin
123112

124113
<APIParameters>
@@ -135,7 +124,7 @@ description: Plate 编辑器的 API 参考。
135124
</APIItem>
136125
</APIParameters>
137126

138-
### PlateApiPlugin
127+
### SlateReactExtensionPlugin
139128

140129
<APIParameters>
141130
<APIItem name="editor.api.redecorate" type="() => void">

apps/www/content/docs/cn/api/core/plate-plugin.mdx

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ const MyPlugin = createPlatePlugin<MyPluginConfig>({
3939
Plate 用于存储插件的唯一标识符,通过 `editor.plugins` 键。
4040
</APIItem>
4141

42-
<APIItem name="api" type="UnionToIntersection<InferApi<C>>">
42+
<APIItem name="api" type="Record<string, Function>">
4343
插件提供的 API 函数对象。这些函数通过 `editor.api[key]` 访问。
4444
</APIItem>
4545

46-
<APIItem name="transforms" type="UnionToIntersection<InferTransforms<C>>">
46+
<APIItem name="transforms" type="Record<string, Function>">
4747
插件提供的变换函数,用于修改编辑器状态。这些函数通过 `editor.tf[key]` 访问。
4848
</APIItem>
4949

50-
<APIItem name="options" type="InferOptions<C>">
50+
<APIItem name="options" type="Record<string, any>">
5151
插件作为选项使用的扩展属性。
5252
</APIItem>
5353

54-
<APIItem name="handlers" type="Nullable<DOMHandlers<WithAnyKey<C>> & { onChange?: OnChange<WithAnyKey<C>> }>">
54+
<APIItem name="handlers" type="{ onChange?: (editor: PlateEditor) => void } & Record<string, Function>">
5555
各种编辑器事件的事件处理程序,包括 `onChange`
5656
</APIItem>
5757

58-
<APIItem name="inject" type="Nullable<{...}>">
58+
<APIItem name="inject" type="object">
5959
定义插件如何将功能注入其他插件或编辑器。
6060

6161
<APISubList>
62-
<APISubListItem parent="inject" name="nodeProps" type="InjectNodeProps<WithAnyKey<C>>" optional>
62+
<APISubListItem parent="inject" name="nodeProps" type="Record<string, any>" optional>
6363
Plate 用于将属性注入任何节点组件的属性。
6464
</APISubListItem>
6565

@@ -84,7 +84,7 @@ Plate 用于将属性注入任何节点组件的属性。
8484
<APISubListItem parent="inject" name="maxLevel" type="number" optional>
8585
节点属性注入的最大嵌套级别。深度大于此级别的节点将不会接收注入的属性。
8686
</APISubListItem>
87-
<APISubListItem parent="inject" name="plugins" type="Record<string, Partial<EditorPlatePlugin<AnyPluginConfig>>>" optional>
87+
<APISubListItem parent="inject" name="plugins" type="Record<string, Partial<PlatePlugin>>" optional>
8888
插件可以使用的属性,用于允许其他插件注入代码。
8989
</APISubListItem>
9090
<APISubListItem parent="inject" name="targetPluginToInject" type="function" optional>
@@ -98,7 +98,7 @@ Plate 用于将属性注入任何节点组件的属性。
9898
</APISubList>
9999
</APIItem>
100100

101-
<APIItem name="node" type="BasePluginNode">
101+
<APIItem name="node" type="object">
102102
定义插件的节点特定配置。
103103

104104
<APISubList>
@@ -164,14 +164,14 @@ HTML React 序列化器配置。
164164
</APISubList>
165165
</APIItem>
166166

167-
<APIItem name="render" type="Nullable<{...}>">
168-
定义编辑器各个部分的渲染函数
167+
<APIItem name="render" type="object">
168+
定义插件如何渲染组件
169169

170170
<APISubList>
171-
<APISubListItem parent="render" name="aboveEditable" type="React.FC<{ children: React.ReactNode }>" optional>
171+
<APISubListItem parent="render" name="aboveEditable" type="Component" optional>
172172
`Editable` 组件上方但在 `Slate` 包装器内渲染组件。
173173
</APISubListItem>
174-
<APISubListItem parent="render" name="aboveNodes" type="NodeWrapperComponent<WithAnyKey<C>>" optional>
174+
<APISubListItem parent="render" name="aboveNodes" type="Component" optional>
175175
在所有其他插件的 `node` 组件上方渲染组件。
176176
</APISubListItem>
177177
<APISubListItem parent="render" name="aboveSlate" type="React.FC<{ children: React.ReactNode }>" optional>
@@ -222,30 +222,40 @@ HTML React 序列化器配置。
222222
Plate 用来装饰编辑器范围的属性。
223223
</APIItem>
224224

225-
<APIItem name="useHooks" type="UseHooks<WithAnyKey<C>>" optional>
226-
Hook called when the editor is initialized.
225+
<APIItem name="extendEditor" type="ExtendEditor<WithAnyKey<C>>" optional>
226+
用于扩展编辑器实例的函数。主要用于集成需要直接编辑器变更的传统 Slate 插件。每个插件只允许一个 `extendEditor`
227+
228+
```ts
229+
extendEditor: ({ editor }) => {
230+
// 示例:集成传统 Slate 插件
231+
return withYjs(editor);
232+
}}
233+
</APIItem>
234+
235+
<APIItem name="useHooks" type="() => void" optional>
236+
当编辑器初始化时调用的钩子。
227237
</APIItem>
228238
</APIAttributes>
229239

230240
## Plugin Methods
231241

232242
<APIAttributes>
233-
<APIItem name="configure" type="function">
243+
<APIItem name="configure" type="(config: PlatePluginConfig | ((ctx: PlatePluginContext) => PlatePluginConfig)) => PlatePlugin">
234244
创建一个具有更新选项的新插件实例。
235245

236246
```ts
237247
(config: PlatePluginConfig<C['key'], InferOptions<C>, InferApi<C>, InferTransforms<C>> | ((ctx: PlatePluginContext<C>) => PlatePluginConfig<C['key'], InferOptions<C>, InferApi<C>, InferTransforms<C>>)) => PlatePlugin<C>
238248
```
239249
</APIItem>
240250

241-
<APIItem name="extend" type="function">
251+
<APIItem name="extend" type="(config: Partial<PlatePlugin> | ((ctx: PlatePluginContext) => Partial<PlatePlugin>)) => PlatePlugin">
242252
创建一个具有附加配置的新插件实例。可以接受一个对象或一个函数。
243253

244254
```ts
245255
(extendConfig: Partial<PlatePlugin> | ((ctx: PlatePluginContext<AnyPluginConfig>) => Partial<PlatePlugin>)) => PlatePlugin
246256
```
247257
</APIItem>
248-
<APIItem name="extendPlugin" type="function">
258+
<APIItem name="extendPlugin" type="(key: string, config: Partial<PlatePlugin> | ((ctx: PlatePluginContext) => Partial<PlatePlugin>)) => PlatePlugin">
249259
扩展一个现有的嵌套插件或添加一个新的插件,如果未找到。支持深度嵌套。
250260

251261
```ts
@@ -261,45 +271,71 @@ Hook called when the editor is initialized.
261271
```
262272
</APIItem>
263273

264-
<APIItem name="extendApi" type="function">
274+
<APIItem name="extendApi" type="(api: (ctx: PlatePluginContext) => Record<string, Function>) => PlatePlugin">
265275
扩展插件的 API
266276

267277
```ts
268278
(api: (ctx: PlatePluginContext<AnyPluginConfig>) => any) => PlatePlugin<C>
269279
```
270280
</APIItem>
271281

272-
<APIItem name="extendEditorApi" type="function">
282+
<APIItem name="extendEditorApi" type="(api: (ctx: PlatePluginContext) => Record<string, Function>) => PlatePlugin">
273283
使用插件特定的方法扩展编辑器的 API
274284

275285
```ts
276286
(api: (ctx: PlatePluginContext<AnyPluginConfig>) => any) => PlatePlugin<C>
277287
```
278288
</APIItem>
279289

280-
<APIItem name="extendTransforms" type="function">
281-
使用插件特定的方法扩展插件的变换
290+
<APIItem name="extendTransforms" type="(transforms: (ctx: PlatePluginContext) => Record<string, Function>) => PlatePlugin">
291+
扩展插件的变换
282292

283293
```ts
284294
(transforms: (ctx: PlatePluginContext<AnyPluginConfig>) => any) => PlatePlugin<C>
285295
```
286296
</APIItem>
287297

288-
<APIItem name="extendEditorTransforms" type="function">
298+
<APIItem name="extendEditorTransforms" type="(transforms: (ctx: PlatePluginContext) => Record<string, Function>) => PlatePlugin">
289299
使用插件特定的方法扩展编辑器的变换。
290300

291301
```ts
292302
(transforms: (ctx: PlatePluginContext<AnyPluginConfig>) => any) => PlatePlugin<C>
293303
```
294304
</APIItem>
295305

296-
<APIItem name="extendOptions" type="function">
306+
<APIItem name="extendOptions" type="(options: (ctx: PlatePluginContext) => Record<string, any>) => PlatePlugin">
297307
使用选择器扩展插件选项。
298308

299309
```ts
300310
(options: (ctx: PlatePluginContext<AnyPluginConfig>) => any) => PlatePlugin<C>
301311
```
302312
</APIItem>
313+
314+
<APIItem name="overrideEditor" type="function">
315+
创建一个具有覆盖编辑器方法的新插件实例。通过 `tf``api` 参数提供对原始方法的访问。可以多次调用以层叠不同的覆盖。
316+
317+
```ts
318+
overrideEditor(({ editor, tf: { deleteForward }, api: { isInline } }) => ({
319+
transforms: {
320+
// 覆盖 transforms
321+
deleteForward(options) {
322+
deleteForward(options);
323+
},
324+
},
325+
api: {
326+
// 覆盖 API 方法
327+
isInline(element) {
328+
return isInline(element);
329+
},
330+
},
331+
})) => PlatePlugin<C>
332+
```
333+
334+
- 修改编辑器行为的首选方法
335+
- 对原始方法的类型安全访问
336+
-transformsAPI 之间清晰分离
337+
- 可以多次链式调用
338+
</APIItem>
303339
</APIAttributes>
304340

305341
## Plugin Context

apps/www/content/docs/cn/plugin-methods.mdx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,39 +299,53 @@ editor.tf.editorTransform();
299299

300300
```ts
301301
const CodeBlockPlugin = toPlatePlugin(createSlatePlugin({ key: 'code_block' }), {
302-
extendEditor: ({ api, editor }) => {
303-
api.plugin.getSyntaxState();
304-
return editor;
305-
},
306302
handlers: {},
307303
options: { hotkey: ['mod+opt+8', 'mod+shift+8'] },
308304
});
309305
```
310306

311307
### .overrideEditor
312308

313-
`overrideEditor` 方法专门用于覆盖现有的编辑器方法:
309+
`overrideEditor` 方法专门用于覆盖现有的编辑器方法,同时保持对原始实现的访问
314310

315311
```ts
316312
const MyPlugin = createPlatePlugin({
317313
key: 'myPlugin',
318314
}).overrideEditor(({ editor, tf: { insertText }, api: { isInline } }) => ({
319315
transforms: {
320316
insertText(text) {
321-
// 覆盖 insertText 行为
317+
// 自定义逻辑
318+
console.log('Inserting:', text);
319+
320+
// 调用原始方法
322321
insertText(text);
322+
323+
// 后续逻辑
324+
console.log('Inserted:', text);
323325
},
324326
},
325327
api: {
326328
isInline(element) {
327-
// 覆盖 isInline 行为
329+
// 自定义内联元素检查
330+
if (element.type === 'custom-inline') {
331+
return true;
332+
}
333+
334+
// 回退到原始行为
328335
return isInline(element);
329336
},
330337
},
331338
}));
332339
```
333340

334-
- 专门用于覆盖现有的编辑器方法
335-
- 返回的覆盖方法需要包装在 `transforms``api` 对象中
341+
- 修改编辑器行为的首选方法
342+
- 对原始方法的类型安全访问(通过 `tf``api` 参数)
343+
- 在 transforms 和 API 之间清晰分离
344+
- 可以多次链式调用以层叠不同的覆盖
336345
- 不能添加新方法(请改用 `extendEditorTransforms``extendEditorApi`
337-
- 通过上下文提供对原始方法的访问
346+
347+
<Callout>
348+
`extendEditor``overrideEditor` 的区别:
349+
- 使用 `extendEditor` 来集成需要直接编辑器变更的传统 Slate 插件,如 `withYjs`。每个插件只能有一个 `extendEditor`
350+
- 优先使用 `overrideEditor` 来修改编辑器行为,因为它具有单一职责和更好的类型安全性。它可以多次调用以层叠不同的覆盖。
351+
</Callout>

0 commit comments

Comments
 (0)