260703_01_FST: First Commit
This commit is contained in:
31
registry/components/kri-editor/extensions/div.ts
Normal file
31
registry/components/kri-editor/extensions/div.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Node, mergeAttributes } from "@tiptap/core";
|
||||
|
||||
export const Div = Node.create({
|
||||
name: "divBlock",
|
||||
group: "block",
|
||||
content: "block+",
|
||||
defining: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
class: {
|
||||
default: null as string | null,
|
||||
parseHTML: (el) => (el as HTMLElement).getAttribute("class"),
|
||||
renderHTML: (attrs) => (attrs.class ? { class: attrs.class } : {}),
|
||||
},
|
||||
style: {
|
||||
default: null as string | null,
|
||||
parseHTML: (el) => (el as HTMLElement).getAttribute("style"),
|
||||
renderHTML: (attrs) => (attrs.style ? { style: attrs.style } : {}),
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [{ tag: "div" }];
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ["div", mergeAttributes(HTMLAttributes), 0];
|
||||
},
|
||||
});
|
||||
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