@talqui-oss/tiptap-extension-variable
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

tiptap-extension-variable

Introduction

Tiptap is a headless wrapper around ProseMirror – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as New York Times, The Guardian or Atlassian.

Official Documentation

Documentation can be found on the Tiptap website.

License

Tiptap is open sourced software licensed under the MIT license.

Usage

//es-6
import { VueRenderer } from "@tiptap/vue-3";
import tippy from "tippy.js";
import VariableList from "./VariableList.vue";

new Editor({
  extensions: [
    Variable.configure({
      suggestion: {
        render: () => {
          let component;
          let popup;

          return {
            onStart: (props) => {
              component = new VueRenderer(VariableList, {
                props,
                editor: props.editor,
              });

              if (!props.clientRect) {
                return;
              }

              popup = tippy("body", {
                getReferenceClientRect: props.clientRect,
                content: component.element,
                showOnCreate: true,
                interactive: true,
                trigger: "manual",
                placement: "bottom-start",
              });
            },

            onUpdate(props) {
              component.updateProps(props);

              if (!props.clientRect) {
                return;
              }

              popup[0].setProps({
                getReferenceClientRect: props.clientRect,
              });
            },

            onKeyDown(props) {
              if (props.event.key === "Escape") {
                popup[0].hide();

                return true;
              }

              return component?.ref?.onKeyDown(props);
            },

            onExit() {
              popup[0]?.destroy();
              component.destroy();
            },
          };
        },
      },
    }),
  ]
});

Package Sidebar

Install

npm i @talqui-oss/tiptap-extension-variable

Homepage

talqui.chat

Weekly Downloads

41

Version

0.0.4

License

MIT

Unpacked Size

67.8 kB

Total Files

12

Last publish

Collaborators

  • talqui-developer