Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/features/editor/components/Editor/extensions/Image.ext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import Image from '@tiptap/extension-image'

export const ImageExt = Image.configure({
export const ImageExt = Image.extend({
addAttributes() {
return {
...this.parent?.(),
width: {
default: null,
parseHTML: (element) => element.getAttribute('width'),
renderHTML: (attributes) => {
if (!attributes.width) {
return {}
}
return {
width: attributes.width,
}
},
},
height: {
default: null,
parseHTML: (element) => element.getAttribute('height'),
renderHTML: (attributes) => {
if (!attributes.height) {
return {}
}
return {
height: attributes.height,
}
},
},
}
},
}).configure({
resize: {
enabled: true,
alwaysPreserveAspectRatio: true,
Expand Down
1 change: 0 additions & 1 deletion src/features/editor/hooks/useAppControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { usePrimaryCta, useSecondaryCta } from '@app-bridge/hooks'
import { useEditorStore } from '@editor/stores/editorStore'
import { useSettingsMutation } from '@settings/hooks/useSettingsMutation'
import type { SettingsUpdateDto } from '@settings/lib/settings-actions.dto'
import { useSettingsStore } from '@settings/providers/settings.provider'
Expand Down
14 changes: 13 additions & 1 deletion src/features/editor/hooks/useFileHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ export const useFileHandlers = () => {
}

const signedUrl = await uploadFileToSupabase(file, token)
setContent(currentEditor.getHTML().replaceAll(fileReader.result as string, signedUrl))
const { doc } = currentEditor.state
let imagePos: number | null = null
doc.descendants((node, pos) => {
if (node.type.name === 'image' && node.attrs.title === randId) {
imagePos = pos
return false //short circuit the search for image position.
}
})

if (imagePos !== null) {
currentEditor.chain().focus().setNodeSelection(imagePos).updateAttributes('image', { src: signedUrl }).run()
setContent(currentEditor.getHTML())
}
}
})
}
Expand Down