/
effective_wiki
/
web-client
Обзор
Документация
Войти
/
effective_wiki
/
web-client
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
src/extensions/database-button/database-button.ts
76 строк
2 KB
Andrey Lila
fix: fix creation and deletion database logic
19 дек 2025, 10:46
19 дек 2025, 10:46
937c2c5
Код
Авторство
О чём код?
import { Node } from "@tiptap/core"; import { ReactNodeViewRenderer } from "@tiptap/react"; import DatabaseButtonView from "./database-button-view"; import { DATABASE_BUTTON_NAME } from "@/helpers/database"; declare module "@tiptap/core" { interface Commands<ReturnType> { databaseButton: { insertDatabaseButton: (options: { pageId: string; databaseId: string }) => ReturnType; }; } } export const DatabaseButton = Node.create({ name: DATABASE_BUTTON_NAME, inline: true, group: "inline", selectable: false, atom: true, addAttributes() { return { pageId: { default: null, }, databaseId: { default: null, }, }; }, parseHTML() { return [ { tag: "button[data-node-type=database-button]", }, ]; }, renderHTML({ HTMLAttributes }) { return [ "button", { ...HTMLAttributes, "data-node-type": "database-button", type: "button", contenteditable: "false", }, 0, ]; }, addNodeView() { return ReactNodeViewRenderer(DatabaseButtonView); }, addCommands() { return { insertDatabaseButton: (options: { pageId: string; databaseId: string }) => ({ chain }) => { if (!options.pageId) return false; return chain() .focus() .insertContent({ type: this.name, attrs: { pageId: options.pageId, databaseId: options.databaseId }, }) .run(); }, }; }, });