mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
feat(editor-ext): add BaseEmbed TipTap node with pageId attribute
This commit is contained in:
@@ -30,4 +30,4 @@ export * from "./lib/columns";
|
|||||||
export * from "./lib/status";
|
export * from "./lib/status";
|
||||||
export * from "./lib/pdf";
|
export * from "./lib/pdf";
|
||||||
export * from "./lib/resizable-nodeview";
|
export * from "./lib/resizable-nodeview";
|
||||||
|
export * from "./lib/base-embed";
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { Node, mergeAttributes } from '@tiptap/core';
|
||||||
|
|
||||||
|
export interface BaseEmbedOptions {
|
||||||
|
HTMLAttributes: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '@tiptap/core' {
|
||||||
|
interface Commands<ReturnType> {
|
||||||
|
baseEmbed: {
|
||||||
|
insertBaseEmbed: (attrs: { pageId: string }) => ReturnType;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const BaseEmbed = Node.create<BaseEmbedOptions>({
|
||||||
|
name: 'baseEmbed',
|
||||||
|
group: 'block',
|
||||||
|
atom: true,
|
||||||
|
selectable: true,
|
||||||
|
draggable: true,
|
||||||
|
|
||||||
|
addOptions() {
|
||||||
|
return { HTMLAttributes: {} };
|
||||||
|
},
|
||||||
|
|
||||||
|
addAttributes() {
|
||||||
|
return {
|
||||||
|
pageId: {
|
||||||
|
default: null,
|
||||||
|
parseHTML: (el) => el.getAttribute('data-page-id'),
|
||||||
|
renderHTML: (attrs) =>
|
||||||
|
attrs.pageId ? { 'data-page-id': attrs.pageId } : {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
parseHTML() {
|
||||||
|
return [{ tag: 'div[data-type="base-embed"]' }];
|
||||||
|
},
|
||||||
|
|
||||||
|
renderHTML({ HTMLAttributes }) {
|
||||||
|
return [
|
||||||
|
'div',
|
||||||
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
||||||
|
'data-type': 'base-embed',
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
addCommands() {
|
||||||
|
return {
|
||||||
|
insertBaseEmbed:
|
||||||
|
(attrs) =>
|
||||||
|
({ commands }) =>
|
||||||
|
commands.insertContent({
|
||||||
|
type: this.name,
|
||||||
|
attrs,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { BaseEmbed } from './base-embed';
|
||||||
|
export type { BaseEmbedOptions } from './base-embed';
|
||||||
Reference in New Issue
Block a user