MCPcopy Index your code
hub / github.com/resend/react-email / createImageExtension

Function createImageExtension

packages/editor/src/plugins/image/extension.tsx:7–92  ·  view source on GitHub ↗
(options: UseEditorImageOptions)

Source from the content-addressed store, hash-verified

5import { executeUploadFlow } from './upload-flow';
6
7export function createImageExtension(options: UseEditorImageOptions) {
8 return EmailNode.create({
9 name: 'image',
10 group: 'block',
11 atom: true,
12 draggable: true,
13
14 addAttributes() {
15 return {
16 src: { default: '' },
17 alt: { default: '' },
18 width: { default: 'auto' },
19 height: { default: 'auto' },
20 alignment: { default: 'center' },
21 href: { default: null },
22 };
23 },
24
25 parseHTML() {
26 return [{ tag: 'img[src]' }];
27 },
28
29 renderHTML({ HTMLAttributes }) {
30 return ['img', HTMLAttributes];
31 },
32
33 addCommands() {
34 return {
35 setImage:
36 (attrs) =>
37 ({ commands }) => {
38 return commands.insertContent({
39 type: this.name,
40 attrs,
41 });
42 },
43
44 uploadImage:
45 () =>
46 ({ editor }) => {
47 const input = document.createElement('input');
48 input.type = 'file';
49 input.accept = 'image/*';
50 input.onchange = () => {
51 const file = input.files?.[0];
52 if (file) {
53 void executeUploadFlow({
54 editor,
55 file,
56 uploadImage: options.uploadImage,
57 });
58 }
59 };
60 input.click();
61 return true;
62 },
63 };
64 },

Callers 4

email-editor.tsxFile · 0.90
useEditorImageFunction · 0.90
extension.spec.tsxFile · 0.90
createEditorFunction · 0.90

Calls 1

createMethod · 0.45

Tested by 1

createEditorFunction · 0.72