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

Function swapImageSrc

packages/editor/src/plugins/image/upload-flow.ts:53–70  ·  view source on GitHub ↗
(editor: Editor, oldSrc: string, newSrc: string)

Source from the content-addressed store, hash-verified

51}
52
53function swapImageSrc(editor: Editor, oldSrc: string, newSrc: string): void {
54 const { state } = editor;
55 const { tr } = state;
56 let found = false;
57
58 state.doc.descendants((node, pos) => {
59 if (found) return false;
60 if (node.type.name === 'image' && node.attrs.src === oldSrc) {
61 tr.setNodeMarkup(pos, undefined, { ...node.attrs, src: newSrc });
62 found = true;
63 return false;
64 }
65 });
66
67 if (found) {
68 editor.view.dispatch(tr);
69 }
70}
71
72function removeImageBySrc(editor: Editor, src: string): void {
73 const { state } = editor;

Callers 1

executeUploadFlowFunction · 0.85

Calls 1

dispatchMethod · 0.80

Tested by

no test coverage detected