Files
edgeever/packages/shared/src/document-extensions.ts
T
tianma-if 99e9c2820c refactor: share editor schema and drop RN iOS builds
Editors now take document TipTap nodes from a shared factory. Workspace and editor helpers move out of the large panes. Store iOS no longer builds from Expo EAS.
2026-09-15 12:56:44 +08:00

53 lines
2.0 KiB
TypeScript

import type { AnyExtension } from "@tiptap/core";
import Image from "@tiptap/extension-image";
import { TaskItem, TaskList } from "@tiptap/extension-list";
import { TableKit } from "@tiptap/extension-table";
import { Markdown } from "@tiptap/markdown";
import StarterKit from "@tiptap/starter-kit";
import { FileAttachment } from "./file-attachment";
import { ImageGallery } from "./image-gallery";
import { MergeDivider } from "./merge-divider";
import { PdfAttachment } from "./pdf-attachment";
import { PluginEmbed } from "./plugin-embed";
export type CreateEdgeEverDocumentExtensionsOptions = {
mathematics: AnyExtension[];
starterKit?: Parameters<typeof StarterKit.configure>[0];
image?: AnyExtension | false;
gallery?: AnyExtension | false;
pdf?: AnyExtension | false;
file?: AnyExtension | false;
pluginEmbed?: AnyExtension | false;
table?: Parameters<typeof TableKit.configure>[0];
markdown?: boolean;
};
const withOptional = (value: AnyExtension | false | undefined, fallback: AnyExtension) => {
if (value === false) return [];
return [value ?? fallback];
};
/**
* Document-schema TipTap extensions shared by Markdown codecs and editors.
* Pass KaTeX math from `@edgeever/shared/mathematics` in browsers; Worker
* codecs must keep using `createEdgeEverMarkdownMathematics()`.
*/
export const createEdgeEverDocumentExtensions = (
options: CreateEdgeEverDocumentExtensionsOptions,
): AnyExtension[] => [
options.starterKit === undefined ? StarterKit : StarterKit.configure(options.starterKit),
TaskList,
TaskItem.configure({ nested: true }),
options.table === undefined ? TableKit : TableKit.configure(options.table),
...withOptional(options.image, Image),
...withOptional(options.gallery, ImageGallery),
...withOptional(options.pdf, PdfAttachment),
...withOptional(options.file, FileAttachment),
MergeDivider,
...withOptional(options.pluginEmbed, PluginEmbed),
...options.mathematics,
...(options.markdown
? [Markdown.configure({ markedOptions: { gfm: true } })]
: []),
];