From c22666b4c11e383ea06a73ab67862da31447c995 Mon Sep 17 00:00:00 2001 From: Geert Plaisier Date: Wed, 13 Nov 2024 16:19:51 +0100 Subject: [PATCH] feat: add selectUpload config option to ImageBlock --- packages/components/src/image-block/config.ts | 1 + .../src/image-block/view/component.ts | 17 ++++++++++- .../stories/components/image-block.stories.ts | 29 ++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/components/src/image-block/config.ts b/packages/components/src/image-block/config.ts index 89673bbf0dde..ad4445645e1f 100644 --- a/packages/components/src/image-block/config.ts +++ b/packages/components/src/image-block/config.ts @@ -10,6 +10,7 @@ export interface ImageBlockConfig { uploadPlaceholderText: string captionPlaceholderText: string onUpload: (file: File) => Promise + selectUpload?: () => Promise } export const defaultImageBlockConfig: ImageBlockConfig = { diff --git a/packages/components/src/image-block/view/component.ts b/packages/components/src/image-block/view/component.ts index 93d96aaf381b..ef13a1c34558 100644 --- a/packages/components/src/image-block/view/component.ts +++ b/packages/components/src/image-block/view/component.ts @@ -122,6 +122,21 @@ export const imageComponent: Component = ({ e.preventDefault() } + const handleUpload = async (e: PointerEvent) => { + if (readonly) { + return; + } + if (typeof config?.selectUpload !== 'undefined') { + e.stopPropagation(); + e.preventDefault(); + const url = await config.selectUpload(); + if (url) { + setAttr?.('src', url) + setHidePlaceholder(true); + } + } + } + return html`
0 && 'hidden')}>
@@ -142,7 +157,7 @@ export const imageComponent: Component = ({ />
-