mirror of https://github.com/fantasticit/think.git
resolve extensions
This commit is contained in:
parent
d835c947db
commit
93f82f1113
|
@ -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();
|
||||
}
|
||||
},
|
||||
}),
|
||||
];
|
||||
},
|
||||
});
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue