diff --git a/packages/slate-commons/src/types/Extension.ts b/packages/slate-commons/src/types/Extension.ts index aa76324cd..7f4d5c73d 100644 --- a/packages/slate-commons/src/types/Extension.ts +++ b/packages/slate-commons/src/types/Extension.ts @@ -6,7 +6,6 @@ import type { Normalize } from './Normalize'; import type { OnKeyDown } from './OnKeyDown'; import type { RenderElement } from './RenderElement'; import type { RenderLeaf } from './RenderLeaf'; -import type { Serialize } from './Serialize'; import type { WithOverrides } from './WithOverrides'; export interface Extension { @@ -26,6 +25,5 @@ export interface Extension { onKeyDown?: OnKeyDown | null; renderElement?: RenderElement; renderLeaf?: RenderLeaf; - serialize?: Serialize; withOverrides?: WithOverrides; } diff --git a/packages/slate-commons/src/types/Serialize.ts b/packages/slate-commons/src/types/Serialize.ts deleted file mode 100644 index f5034a9f7..000000000 --- a/packages/slate-commons/src/types/Serialize.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Descendant } from 'slate'; - -/** - * Cleanup editor value before reporting it to the outer world. - * Useful to clean up internal temporary nodes and properties. - */ -export type Serialize = (nodes: Descendant[]) => Descendant[]; diff --git a/packages/slate-editor/src/index.ts b/packages/slate-editor/src/index.ts index ed646b37b..a543e4b44 100644 --- a/packages/slate-editor/src/index.ts +++ b/packages/slate-editor/src/index.ts @@ -31,7 +31,6 @@ import type { DefaultTextBlockEditor, ElementsEqualityCheckEditor, RichBlocksAwareEditor, - SerializingEditor, } from '#modules/editor'; type Editor = BaseEditor & @@ -39,7 +38,6 @@ type Editor = BaseEditor & DefaultTextBlockEditor & ElementsEqualityCheckEditor & RichBlocksAwareEditor & - SerializingEditor & FlashEditor; declare module 'slate' { diff --git a/packages/slate-editor/src/modules/editor/createEditor.ts b/packages/slate-editor/src/modules/editor/createEditor.ts index 5100ff7c7..8a7b16f7d 100644 --- a/packages/slate-editor/src/modules/editor/createEditor.ts +++ b/packages/slate-editor/src/modules/editor/createEditor.ts @@ -18,7 +18,6 @@ import { withDeserializeHtml, withElementsEqualityCheck, withRichBlocks, - withSerialization, } from './plugins'; export function createEditor( @@ -42,7 +41,6 @@ export function createEditor( withDeserializeHtml(getExtensions), withRichBlocks(getExtensions), withElementsEqualityCheck(getExtensions), - withSerialization(getExtensions), ...overrides, ])(baseEditor); } diff --git a/packages/slate-editor/src/modules/editor/index.ts b/packages/slate-editor/src/modules/editor/index.ts index 0e899e93e..ac1745aa7 100644 --- a/packages/slate-editor/src/modules/editor/index.ts +++ b/packages/slate-editor/src/modules/editor/index.ts @@ -6,13 +6,11 @@ export { withDeserializeHtml, withElementsEqualityCheck, withRichBlocks, - withSerialization, } from './plugins'; export type { DefaultTextBlockEditor, ElementsEqualityCheckEditor, RichBlocksAwareEditor, - SerializingEditor, } from './plugins'; export type { EditorRef, EditorProps, Value } from './types'; export { useEditorEvents } from './useEditorEvents'; diff --git a/packages/slate-editor/src/modules/editor/lib/isEditorValueEqual.test.ts b/packages/slate-editor/src/modules/editor/lib/isEditorValueEqual.test.ts index 019508bea..b339d8942 100644 --- a/packages/slate-editor/src/modules/editor/lib/isEditorValueEqual.test.ts +++ b/packages/slate-editor/src/modules/editor/lib/isEditorValueEqual.test.ts @@ -1,5 +1,3 @@ -import { withoutNodes } from '@prezly/slate-commons'; -import { isQuoteNode } from '@prezly/slate-types'; import { createEditor as createSlateEditor } from 'slate'; import { createEditor } from '#modules/editor'; @@ -63,21 +61,4 @@ describe('isEditorValueEqual', () => { expect(isEditorValueEqual(editor, a, b)).toBe(true); }); - - it('should run pre-serialization cleanup from extensions', () => { - const editor = createEditor(createSlateEditor(), () => [ - { - id: 'PreSerializationCleanup', - serialize: (nodes) => withoutNodes(nodes, isQuoteNode), - }, - ]); - - const a = [ - { type: 'paragraph', children: [{ text: 'A wise man once said:' }] }, - { type: 'block-quote', children: [{ text: 'Hello' }] }, - ]; - const b = [{ type: 'paragraph', children: [{ text: 'A wise man once said:' }] }]; - - expect(isEditorValueEqual(editor, a, b)).toBe(true); - }); }); diff --git a/packages/slate-editor/src/modules/editor/plugins/index.ts b/packages/slate-editor/src/modules/editor/plugins/index.ts index 0f8197aec..4acb31d67 100644 --- a/packages/slate-editor/src/modules/editor/plugins/index.ts +++ b/packages/slate-editor/src/modules/editor/plugins/index.ts @@ -5,4 +5,3 @@ export { withElementsEqualityCheck, } from './withElementsEqualityCheck'; export { type RichBlocksAwareEditor, withRichBlocks } from './withRichBlocks'; -export { type SerializingEditor, withSerialization } from './withSerialization'; diff --git a/packages/slate-editor/src/modules/editor/plugins/withSerialization.ts b/packages/slate-editor/src/modules/editor/plugins/withSerialization.ts deleted file mode 100644 index fce712343..000000000 --- a/packages/slate-editor/src/modules/editor/plugins/withSerialization.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Extension } from '@prezly/slate-commons'; -import type { SlateEditor } from '@udecode/plate-common'; -import type { Descendant } from 'slate'; - -export interface SerializingEditor { - serialize(nodes: Descendant[]): Descendant[]; -} - -export function withSerialization(getExtensions: () => Extension[]) { - return function (editor: T): T & SerializingEditor { - return Object.assign(editor, { - serialize(nodes: Descendant[]) { - return getExtensions().reduce( - (result, extension) => extension.serialize?.(result) ?? result, - nodes, - ); - }, - }); - }; -}