resolve extensions

This commit is contained in:
fantasticit 2022-11-19 12:23:15 +08:00
parent d835c947db
commit 93f82f1113
3 changed files with 1 additions and 57 deletions

View File

@ -1,52 +0,0 @@
import { Editor, Extension } from '@tiptap/core';
import { throttle } from 'helpers/throttle';
import { Plugin, PluginKey, Transaction } from 'prosemirror-state';
export const scrollIntoViewPluginKey = new PluginKey('scrollIntoViewPlugin');
type TransactionWithScroll = Transaction & { scrolledIntoView: boolean };
interface IScrollIntoViewOptions {
/**
*
*
*/
onScroll: (editor: Editor) => void;
}
export const ScrollIntoView = Extension.create<IScrollIntoViewOptions>({
name: 'scrollIntoView',
addOptions() {
return {
onScroll: () => {},
};
},
addProseMirrorPlugins() {
const { editor } = this;
const onScroll = this.options.onScroll ? throttle(this.options.onScroll, 200) : (editor) => {};
return [
new Plugin({
key: scrollIntoViewPluginKey,
appendTransaction: (transactions, oldState, newState) => {
if (!transactions.length || !editor.isEditable) {
return;
}
const tr = transactions[0] as TransactionWithScroll;
if (
(tr.docChanged || tr.storedMarksSet) &&
!tr.scrolledIntoView &&
tr.getMeta('scrollIntoView') !== false &&
tr.getMeta('addToHistory') !== false
) {
onScroll(editor);
return newState.tr.scrollIntoView();
}
},
}),
];
},
});

View File

@ -47,7 +47,6 @@ import { Paragraph } from 'tiptap/core/extensions/paragraph';
import { Paste } from 'tiptap/core/extensions/paste';
import { Placeholder } from 'tiptap/core/extensions/placeholder';
import { QuickInsert } from 'tiptap/core/extensions/quick-insert';
import { ScrollIntoView } from 'tiptap/core/extensions/scroll-into-view';
import { SearchNReplace } from 'tiptap/core/extensions/search';
import { SelectionExtension } from 'tiptap/core/extensions/selection';
import { Status } from 'tiptap/core/extensions/status';
@ -138,8 +137,7 @@ export const CollaborationKit = [
ListItem,
Loading,
OrderedList,
SelectionExtension,
ScrollIntoView,
// SelectionExtension,
Strike,
Subscript,
Superscript,

View File

@ -30,7 +30,6 @@ import { OrderedList } from 'tiptap/core/extensions/ordered-list';
import { Paragraph } from 'tiptap/core/extensions/paragraph';
import { Paste } from 'tiptap/core/extensions/paste';
import { Placeholder } from 'tiptap/core/extensions/placeholder';
import { ScrollIntoView } from 'tiptap/core/extensions/scroll-into-view';
import { Strike } from 'tiptap/core/extensions/strike';
import { Subscript } from 'tiptap/core/extensions/subscript';
import { Superscript } from 'tiptap/core/extensions/superscript';
@ -93,7 +92,6 @@ export const CommentKit = [
showOnlyWhenEditable: true,
}),
Strike,
ScrollIntoView,
Subscript,
Superscript,
Table,