github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/editor/src/extensions/quick-edit/quick-edit-ext.ts (about)

     1  import { getMarkRange, Extension } from '@tiptap/core';
     2  import { Plugin, TextSelection } from 'prosemirror-state';
     3  import { QuickEditPlugin, QuickEditPluginProps } from './quick-edit'
     4  
     5  export type QuickEditOptions = Omit<QuickEditPluginProps, 'editor' | 'element'>
     6  
     7  export const QuickEdit = Extension.create<QuickEditOptions>({
     8    name: 'quickEdit',
     9  
    10    addOptions() {
    11      return {
    12        tippyOptions: {},
    13        pluginKey: 'quickEdit',
    14        shouldShow: null,
    15      }
    16    },
    17  
    18    addProseMirrorPlugins() {
    19      return [
    20        new Plugin({
    21          props: {
    22            handleClick(view, pos) {
    23              const range = getMarkRange(view.state.doc.resolve(pos), view.state.schema.marks.link);
    24              if (!range) return false;
    25  
    26              const $start = view.state.doc.resolve(range.from);
    27              const $end = view.state.doc.resolve(range.to);
    28              const transaction = view.state.tr.setSelection(new TextSelection($start, $end));
    29              view.dispatch(transaction);
    30  
    31              return true;
    32            },
    33          },
    34        }),
    35        QuickEditPlugin({
    36          pluginKey: this.options.pluginKey,
    37          editor: this.editor,
    38          tippyOptions: this.options.tippyOptions,
    39          shouldShow: this.options.shouldShow,
    40        }),
    41      ]
    42    },
    43  })