Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[DEV-19138] Refactor - Drop unused extension interface methods #579

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/slate-commons/src/types/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import type { Element, Node } from 'slate';
import type { DecorateFactory } from './DecorateFactory';
import type { DeserializeHtml } from './DeserializeHtml';
import type { Normalize } from './Normalize';
import type { OnDOMBeforeInput } from './OnDOMBeforeInput';
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 {
Expand All @@ -24,10 +22,8 @@ export interface Extension {
isRichBlock?: (node: Node) => boolean;
isVoid?: (node: Node) => boolean;
normalizeNode?: Normalize | Normalize[];
onDOMBeforeInput?: OnDOMBeforeInput;
onKeyDown?: OnKeyDown | null;
renderElement?: RenderElement;
renderLeaf?: RenderLeaf;
serialize?: Serialize;
withOverrides?: WithOverrides;
}
3 changes: 0 additions & 3 deletions packages/slate-commons/src/types/OnDOMBeforeInput.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/slate-commons/src/types/Serialize.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/slate-commons/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export type { DecorateFactory } from './DecorateFactory';
export type { DeserializeHtml, DeserializeElement, DeserializeMarks } from './DeserializeHtml';
export type { Extension } from './Extension';
export type { Normalize } from './Normalize';
export type { OnDOMBeforeInput } from './OnDOMBeforeInput';
export type { OnKeyDown } from './OnKeyDown';
export type { RenderElement } from './RenderElement';
export type { RenderLeaf } from './RenderLeaf';
Expand Down
2 changes: 0 additions & 2 deletions packages/slate-editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ import type {
DefaultTextBlockEditor,
ElementsEqualityCheckEditor,
RichBlocksAwareEditor,
SerializingEditor,
} from '#modules/editor';

type Editor = BaseEditor &
HistoryEditor &
DefaultTextBlockEditor<ParagraphNode> &
ElementsEqualityCheckEditor &
RichBlocksAwareEditor &
SerializingEditor &
FlashEditor;

declare module 'slate' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type {
Decorate,
Extension,
OnDOMBeforeInput,
OnKeyDown,
RenderElement,
RenderLeaf,
Expand All @@ -14,7 +13,6 @@ import React, { useCallback, useMemo } from 'react';

import {
combineDecorate,
combineOnDOMBeforeInput,
combineOnKeyDown,
combineRenderElement,
combineRenderLeaf,
Expand All @@ -37,9 +35,7 @@ export interface Props {
*/
extensions?: Extension[];
onCut?: (event: React.ClipboardEvent<HTMLDivElement>) => void;
onDOMBeforeInput?: OnDOMBeforeInput[];
// Dependencies of `onDOMBeforeInput`
onDOMBeforeInputDeps?: any[];
onDOMBeforeInput?: (event: InputEvent) => void;
/**
* Handlers when we press a key
*/
Expand Down Expand Up @@ -73,8 +69,7 @@ export function EditableWithExtensions({
decorate,
editor,
extensions = [],
onDOMBeforeInput: onDOMBeforeInputList = [],
onDOMBeforeInputDeps = [],
onDOMBeforeInput,
onKeyDown: onKeyDownList = [],
onKeyDownDeps = [],
renderElement: renderElementList = [],
Expand All @@ -90,10 +85,6 @@ export function EditableWithExtensions({
},
[decorate, editor, extensions],
);
const combinedOnDOMBeforeInput = useCallback(
combineOnDOMBeforeInput(editor, extensions, onDOMBeforeInputList),
onDOMBeforeInputDeps,
);
const combinedOnKeyDown = useCallback(
combineOnKeyDown(editor, extensions, onKeyDownList),
onKeyDownDeps,
Expand All @@ -113,7 +104,7 @@ export function EditableWithExtensions({
className={classNames(className, 'notranslate')}
translate="no"
decorate={combinedDecorate}
onDOMBeforeInput={combinedOnDOMBeforeInput}
onDOMBeforeInput={onDOMBeforeInput}
onKeyDown={combinedOnKeyDown}
renderElement={combinedRenderElement}
renderLeaf={combinedRenderLeaf}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/slate-editor/src/modules/editable/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { combineDecorate } from './combineDecorate';
export { combineOnDOMBeforeInput } from './combineOnDOMBeforeInput';
export { combineOnKeyDown } from './combineOnKeyDown';
export { combineRenderElement } from './combineRenderElement';
export { combineRenderLeaf } from './combineRenderLeaf';
Expand Down
4 changes: 1 addition & 3 deletions packages/slate-editor/src/modules/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,7 @@ export const Editor = forwardRef<EditorRef, EditorProps>((props, forwardedRef) =
const hasCustomPlaceholder =
withFloatingAddMenu && (isEditorFocused(editor) || isFloatingAddMenuOpen);

const onChange = useOnChange((value) => {
props.onChange(editor.serialize(value) as Value);
});
const onChange = useOnChange(props.onChange);

const floatingSnippetRenderInput = useFunction(() => {
return (
Expand Down
2 changes: 0 additions & 2 deletions packages/slate-editor/src/modules/editor/createEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
withDeserializeHtml,
withElementsEqualityCheck,
withRichBlocks,
withSerialization,
} from './plugins';

export function createEditor(
Expand All @@ -42,7 +41,6 @@ export function createEditor(
withDeserializeHtml(getExtensions),
withRichBlocks(getExtensions),
withElementsEqualityCheck(getExtensions),
withSerialization(getExtensions),
...overrides,
])(baseEditor);
}
2 changes: 0 additions & 2 deletions packages/slate-editor/src/modules/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function isEditorValueEqual<T extends Descendant>(
);
}

return a === b || compareLists(editor.serialize(a), editor.serialize(b));
return a === b || compareLists(a, b);
}

function isText(node: Descendant): node is Text {
Expand Down
1 change: 0 additions & 1 deletion packages/slate-editor/src/modules/editor/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export {
withElementsEqualityCheck,
} from './withElementsEqualityCheck';
export { type RichBlocksAwareEditor, withRichBlocks } from './withRichBlocks';
export { type SerializingEditor, withSerialization } from './withSerialization';

This file was deleted.

Loading