Add unsend campaign feature (#45)
* Add unsend email editor Add email editor Add more email editor Add renderer partial Add more marketing email features * Add more campaign feature * Add variables * Getting there * campaign is there mfs * Add migration
This commit is contained in:
92
packages/email-editor/src/extensions/ButtonExtension.ts
Normal file
92
packages/email-editor/src/extensions/ButtonExtension.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { mergeAttributes, Node } from "@tiptap/core";
|
||||
import { ReactNodeViewRenderer } from "@tiptap/react";
|
||||
import { AllowedAlignments } from "../types";
|
||||
|
||||
import { ButtonComponent } from "../nodes/button";
|
||||
// import { AllowedLogoAlignment } from '../nodes/logo';
|
||||
|
||||
declare module "@tiptap/core" {
|
||||
interface Commands<ReturnType> {
|
||||
button: {
|
||||
setButton: () => ReturnType;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const ButtonExtension = Node.create({
|
||||
name: "button",
|
||||
group: "block",
|
||||
atom: true,
|
||||
draggable: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
component: {
|
||||
default: "button",
|
||||
},
|
||||
text: {
|
||||
default: "Button",
|
||||
},
|
||||
url: {
|
||||
default: "",
|
||||
},
|
||||
alignment: {
|
||||
default: "left",
|
||||
},
|
||||
borderRadius: {
|
||||
default: "4",
|
||||
},
|
||||
borderWidth: {
|
||||
default: "1",
|
||||
},
|
||||
buttonColor: {
|
||||
default: "rgb(0, 0, 0)",
|
||||
},
|
||||
borderColor: {
|
||||
default: "rgb(0, 0, 0)",
|
||||
},
|
||||
textColor: {
|
||||
default: "rgb(255, 255, 255)",
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: `a[data-unsend-component="${this.name}"]`,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return [
|
||||
"a",
|
||||
mergeAttributes(
|
||||
{
|
||||
"data-unsend-component": this.name,
|
||||
},
|
||||
HTMLAttributes
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setButton:
|
||||
() =>
|
||||
({ commands }) => {
|
||||
return commands.insertContent({
|
||||
type: this.name,
|
||||
attrs: {
|
||||
unsendComponent: this.name,
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
addNodeView() {
|
||||
return ReactNodeViewRenderer(ButtonComponent);
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user