diff --git a/e2e/src/image-block/style.css b/e2e/src/image-block/style.css index d2a19b4b188..43ddacd8013 100644 --- a/e2e/src/image-block/style.css +++ b/e2e/src/image-block/style.css @@ -44,9 +44,10 @@ milkdown-image-block > .caption-input { milkdown-image-block > .image-edit { align-items: center; - padding: 24px 40px; + padding: 16px 24px; gap: 16px; background: oldlace; + height: 56px; } milkdown-image-block > .image-edit .image-icon { @@ -54,8 +55,8 @@ milkdown-image-block > .image-edit .image-icon { } milkdown-image-block > .image-edit .image-icon svg { - width: 48px; - height: 48px; + width: 24px; + height: 24px; } milkdown-image-block > .image-edit .link-importer .placeholder { @@ -63,7 +64,7 @@ milkdown-image-block > .image-edit .link-importer .placeholder { } milkdown-image-block > .image-edit .link-importer .link-input-area { - line-height: 48px; + line-height: 24px; } milkdown-image-block > .image-edit .link-importer .placeholder .uploader { @@ -88,6 +89,8 @@ milkdown-image-block > .image-edit .link-importer .placeholder .text { milkdown-image-block > .image-edit .confirm { background: darkgray; color: antiquewhite; - padding: 6px 24px; + height: 40px; + padding: 0 24px; border-radius: 100px; + font-size: 14px; } diff --git a/packages/components/src/image-block/config.ts b/packages/components/src/image-block/config.ts index 5b9acdc6e00..c14b0b5a01f 100644 --- a/packages/components/src/image-block/config.ts +++ b/packages/components/src/image-block/config.ts @@ -1,11 +1,10 @@ /* Copyright 2021, Milkdown by Mirone. */ import { $ctx } from '@milkdown/utils' import { html } from 'atomico' -import { chatBubble, edit, image, upload } from '../__internal__/icons' +import { chatBubble, image } from '../__internal__/icons' export type ImageBlockConfig = { imageIcon: () => ReturnType - editIcon: () => ReturnType captionIcon: () => ReturnType uploadButton: () => ReturnType confirmButton: () => ReturnType @@ -16,9 +15,8 @@ export type ImageBlockConfig = { export const defaultConfig: ImageBlockConfig = { imageIcon: () => image, - editIcon: () => edit, captionIcon: () => chatBubble, - uploadButton: () => html`${upload} Upload file`, + uploadButton: () => html`Upload file`, confirmButton: () => html`Confirm ⏎`, uploadPlaceholderText: 'or paste the image link ...', captionPlaceholderText: 'Image caption', diff --git a/packages/components/src/image-block/view/component.ts b/packages/components/src/image-block/view/component.ts index 18d56c23eb3..09c861b085b 100644 --- a/packages/components/src/image-block/view/component.ts +++ b/packages/components/src/image-block/view/component.ts @@ -31,10 +31,10 @@ export const imageComponent: Component = ({ const resizeHandle = useRef() const linkInput = useRef() const [showCaption, setShowCaption] = useState(caption.length > 0) - const [editing, setEditing] = useState(src.length === 0) const [hidePlaceholder, setHidePlaceholder] = useState(src.length !== 0) - const [uuid, setUuid] = useState('') + const [uuid] = useState(crypto.randomUUID()) const [focusLinkInput, setFocusLinkInput] = useState(false) + const [currentLink, setCurrentLink] = useState(src) useCssLightDom(style) useBlockEffect({ @@ -45,15 +45,10 @@ export const imageComponent: Component = ({ src, }) - useEffect(() => { - setUuid(crypto.randomUUID()) - }, []) - useEffect(() => { if (selected) return - setEditing(src.length === 0) setShowCaption(caption.length > 0) }, [selected]) @@ -63,16 +58,11 @@ export const imageComponent: Component = ({ setAttr?.('caption', value) } - const onEdit = () => { - setEditing(true) - } - const onEditLink = (e: InputEvent) => { const target = e.target as HTMLInputElement const value = target.value setHidePlaceholder(value.length !== 0) - - setAttr?.('src', value) + setCurrentLink(value) } const onUpload = async (e: InputEvent) => { @@ -85,7 +75,6 @@ export const imageComponent: Component = ({ return setAttr?.('src', url) - setEditing(false) setHidePlaceholder(true) } @@ -93,13 +82,17 @@ export const imageComponent: Component = ({ setShowCaption(x => !x) } + const onConfirmLinkInput = () => { + setAttr?.('src', linkInput.current?.value ?? '') + } + const onKeydown = (e: KeyboardEvent) => { if (e.key === 'Enter') - setEditing(false) + onConfirmLinkInput() } - return html` -
+ return html` +
0 && 'hidden')}>
${config?.imageIcon()}
@@ -107,7 +100,7 @@ export const imageComponent: Component = ({ setFocusLinkInput(true)} @@ -124,22 +117,21 @@ export const imageComponent: Component = ({
-
+
-
${config?.editIcon()}
${config?.captionIcon()}
${caption}
.image-edit { + :host > .image-edit { display: flex; }