hoàn thành tích hợp FSRS
This commit is contained in:
@@ -30,4 +30,5 @@ export * from "./lib/columns";
|
||||
export * from "./lib/status";
|
||||
export * from "./lib/pdf";
|
||||
export * from "./lib/resizable-nodeview";
|
||||
export * from "./lib/cloze";
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { Mark, mergeAttributes } from "@tiptap/core";
|
||||
|
||||
export interface ClozeOptions {
|
||||
HTMLAttributes: Record<string, any>;
|
||||
}
|
||||
|
||||
declare module "@tiptap/core" {
|
||||
interface Commands<ReturnType> {
|
||||
cloze: {
|
||||
/**
|
||||
* Set a cloze mark
|
||||
*/
|
||||
setCloze: () => ReturnType;
|
||||
/**
|
||||
* Toggle a cloze mark
|
||||
*/
|
||||
toggleCloze: () => ReturnType;
|
||||
/**
|
||||
* Unset a cloze mark
|
||||
*/
|
||||
unsetCloze: () => ReturnType;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const Cloze = Mark.create<ClozeOptions>({
|
||||
name: "cloze",
|
||||
|
||||
addOptions() {
|
||||
return {
|
||||
HTMLAttributes: {
|
||||
class: "docmost-cloze",
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: "span.docmost-cloze",
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return [
|
||||
"span",
|
||||
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
||||
0,
|
||||
];
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setCloze:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.setMark(this.name);
|
||||
},
|
||||
toggleCloze:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.toggleMark(this.name);
|
||||
},
|
||||
unsetCloze:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.unsetMark(this.name);
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
"Mod-Shift-c": () => this.editor.commands.toggleCloze(),
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user