260703_01_FST: First Commit
This commit is contained in:
46
registry/components/kri-editor/extensions/font-size.ts
Normal file
46
registry/components/kri-editor/extensions/font-size.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Extension } from "@tiptap/core";
|
||||
|
||||
declare module "@tiptap/core" {
|
||||
interface Commands<ReturnType> {
|
||||
fontSize: {
|
||||
setFontSize: (fontSize: string) => ReturnType;
|
||||
unsetFontSize: () => ReturnType;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const FontSize = Extension.create({
|
||||
name: "fontSize",
|
||||
addGlobalAttributes() {
|
||||
return [
|
||||
{
|
||||
types: ["textStyle"],
|
||||
attributes: {
|
||||
fontSize: {
|
||||
default: null as string | null,
|
||||
parseHTML: (element) => (element).style.fontSize || null,
|
||||
renderHTML: (attributes) => {
|
||||
if (!attributes.fontSize) return {};
|
||||
return { style: `font-size:${attributes.fontSize}` };
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setFontSize:
|
||||
(fontSize) =>
|
||||
({ chain }) => {
|
||||
return chain().setMark("textStyle", { fontSize }).run();
|
||||
},
|
||||
unsetFontSize:
|
||||
() =>
|
||||
({ chain }) => {
|
||||
return chain().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run();
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user