/** The one place that decides which nodes and marks a note may contain. */ import StarterKit from "@tiptap/starter-kit"; import Underline from "@tiptap/extension-underline"; import Link from "@tiptap/extension-link"; import Placeholder from "@tiptap/extension-placeholder"; import TaskList from "@tiptap/extension-task-list"; import TaskItem from "@tiptap/extension-task-item"; import Table from "@tiptap/extension-table"; import TableRow from "@tiptap/extension-table-row"; import TableHeader from "@tiptap/extension-table-header"; import TableCell from "@tiptap/extension-table-cell"; import { NoteLink } from "./noteLink.js"; import { TextAlign } from "./textAlign.js"; import { Highlight, TextColor } from "./textMarks.js"; import { Pagination } from "./pagination.js"; import { AttachmentImage } from "./attachmentImage.js"; export function buildExtensions({ search = () => [], placeholder = "Start writing...", // Where the page ends, read fresh on every measurement so a resize is enough // to re-break the text. Absent when there is no page to break against — the // static list used for parsing, for one. getGeometry = null, } = {}) { return [ StarterKit.configure({ heading: { levels: [1, 2, 3] }, // History is on by default; the drawing layer keeps its own undo stack. codeBlock: { HTMLAttributes: { class: "note-code-block" } }, }), Underline, Link.configure({ openOnClick: false, // the app decides what a click does autolink: true, protocols: ["http", "https", "mailto"], HTMLAttributes: { rel: "noopener noreferrer nofollow", target: "_blank" }, }), // allowBase64 stays on so notes written before attachments still render. AttachmentImage.configure({ inline: false, allowBase64: true }), Placeholder.configure({ placeholder }), TaskList, TaskItem.configure({ nested: true }), Table.configure({ resizable: true, lastColumnResizable: false, allowTableNodeSelection: true }), TableRow, TableHeader, TableCell, NoteLink.configure({ search }), TextAlign.configure({ types: ["paragraph", "heading"] }), // A marker pen and a colour for the letters. Marks rather than a node, so // they nest with bold and italic like every other emphasis. Highlight, TextColor, Pagination.configure({ getGeometry }), ]; } /** * A static extension list for parsing stored HTML outside of a live editor * (`generateJSON`). It must accept everything `buildExtensions` produces, or * migrating an old note would silently drop nodes. */ export const parsingExtensions = buildExtensions();