Skip to content

add option to disable animations #1062

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2024
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
9 changes: 6 additions & 3 deletions docs/pages/docs/editor-basics/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type BlockNoteEditorOptions = {
dictionary?: Dictionary;
schema?: BlockNoteSchema;
trailingBlock?: boolean;
animations?: boolean;
};
```

Expand All @@ -50,6 +51,8 @@ The hook takes two optional parameters:

`trailingBlock`: An option which user can pass with `false` value to disable the automatic creation of a trailing new block on the next line when the user types or edits any block. Defaults to `true` if undefined.

`animations`: Whether changes to blocks (like indentation, creating lists, changing headings) should be animated or not. Defaults to `true`.

**deps:** Dependency array that's internally passed to `useMemo`. A new editor will only be created when this array changes.

<Callout type="info" emoji={"💡"}>
Expand All @@ -58,9 +61,9 @@ The hook takes two optional parameters:
The `useCreateBlockNote` hook is actually a simple `useMemo` wrapper around
the `BlockNoteEditor.create` method. You can use this method directly if you
want to control the editor lifecycle manually. For example, we do this in
the [Saving & Loading example](/examples/backend/saving-loading) to delay the
editor creation until some content has been fetched from an external data
source.
the [Saving & Loading example](/examples/backend/saving-loading) to delay
the editor creation until some content has been fetched from an external
data source.
</p>
</Callout>

Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/editor/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { en } from "../i18n/locales";

import { Transaction } from "@tiptap/pm/state";
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer";
import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin";
import "../style.css";
import { initializeESMDependencies } from "../util/esmDependencies";

Expand All @@ -75,6 +76,13 @@ export type BlockNoteEditorOptions<
ISchema extends InlineContentSchema,
SSchema extends StyleSchema
> = {
/**
* Whether changes to blocks (like indentation, creating lists, changing headings) should be animated or not. Defaults to `true`.
*
* @default true
*/
animations?: boolean;

disableExtensions: string[];
/**
* A dictionary object containing translations for the editor.
Expand Down Expand Up @@ -353,6 +361,9 @@ export class BlockNoteEditor<
...(this.filePanel ? [this.filePanel.plugin] : []),
...(this.tableHandles ? [this.tableHandles.plugin] : []),
PlaceholderPlugin(this, newOptions.placeholders),
...(this.options.animations ?? true
? [PreviousBlockTypePlugin()]
: []),
];
},
});
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/pm-nodes/BlockContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { PartialBlock } from "../blocks/defaultBlocks";
import type { BlockNoteEditor } from "../editor/BlockNoteEditor";
import { NonEditableBlockPlugin } from "../extensions/NonEditableBlocks/NonEditableBlockPlugin";
import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin";
import {
BlockNoteDOMAttributes,
BlockSchema,
Expand Down Expand Up @@ -492,7 +491,7 @@ export const BlockContainer = Node.create<{
},

addProseMirrorPlugins() {
return [PreviousBlockTypePlugin(), NonEditableBlockPlugin()];
return [NonEditableBlockPlugin()];
},

addKeyboardShortcuts() {
Expand Down
Loading