|
| 1 | +import { Editor, Extension, getSchema, Mark, Node } from "@tiptap/core"; |
| 2 | +import { describe, expect, it } from "vite-plus/test"; |
| 3 | +import { CommentMark } from "../comments/mark.js"; |
| 4 | +import { defaultStyleSpecs } from "./defaultBlocks.js"; |
| 5 | + |
| 6 | +const extensions = [ |
| 7 | + Node.create({ name: "doc", topNode: true, content: "text*" }), |
| 8 | + Node.create({ name: "text", group: "inline" }), |
| 9 | + ...Object.values(defaultStyleSpecs).map((style) => style.implementation.mark), |
| 10 | +]; |
| 11 | + |
| 12 | +describe("inline code mark exclusions", () => { |
| 13 | + it.each([false, true])( |
| 14 | + "builds exclusions from enabled marks (comments enabled: %s)", |
| 15 | + (withComments) => { |
| 16 | + const editor = new Editor({ |
| 17 | + element: null, |
| 18 | + extensions: [ |
| 19 | + ...extensions, |
| 20 | + Extension.create({ |
| 21 | + name: "customMarks", |
| 22 | + addExtensions() { |
| 23 | + return [ |
| 24 | + Mark.create({ name: "customStyle" }), |
| 25 | + ...(withComments ? [CommentMark] : []), |
| 26 | + ]; |
| 27 | + }, |
| 28 | + }), |
| 29 | + ], |
| 30 | + }); |
| 31 | + |
| 32 | + try { |
| 33 | + const { marks } = editor.schema; |
| 34 | + const code = marks.code; |
| 35 | + expect(code.spec.excludes).not.toBe("_"); |
| 36 | + for (const mark of Object.values(marks)) { |
| 37 | + expect(code.excludes(mark)).toBe(mark.name !== "comment"); |
| 38 | + } |
| 39 | + |
| 40 | + if (withComments) { |
| 41 | + const codeMark = code.create(); |
| 42 | + const commentMark = marks.comment.create({ threadId: "thread" }); |
| 43 | + expect(codeMark.addToSet([commentMark])).toHaveLength(2); |
| 44 | + expect(commentMark.addToSet([codeMark])).toHaveLength(2); |
| 45 | + } |
| 46 | + } finally { |
| 47 | + editor.destroy(); |
| 48 | + } |
| 49 | + }, |
| 50 | + ); |
| 51 | + |
| 52 | + it("supports schema creation without an editor", () => { |
| 53 | + const { marks } = getSchema(extensions); |
| 54 | + expect(marks.code.excludes(marks.bold)).toBe(true); |
| 55 | + }); |
| 56 | +}); |
0 commit comments