28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
;(function (global) {
|
|
'use strict'
|
|
const React = global.React
|
|
if (!React || !React.createElement) return
|
|
const el = React.createElement
|
|
function ResultImg(props) {
|
|
const useState = React.useState
|
|
const [hover, setHover] = useState(false)
|
|
const item = props.item || {}
|
|
const doCopyRef = () => { props.onCopyRef && props.onCopyRef(item.url) }
|
|
const doCopyLink = () => {
|
|
try { if (global.navigator && global.navigator.clipboard) global.navigator.clipboard.writeText(item.url) } catch (e) { /* ignore */ }
|
|
}
|
|
return el('div', {
|
|
className: 'iwb-rimg',
|
|
onMouseEnter: () => setHover(true),
|
|
onMouseLeave: () => setHover(false),
|
|
},
|
|
el('img', { className: props.cls || 'iwb-result-thumb', src: item.url, alt: 'img', loading: 'lazy', title: '点击放大', onClick: () => props.onPreview && props.onPreview(item.url) }),
|
|
hover ? el('div', { className: 'iwb-rimg-actions' },
|
|
el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制为参考图节点', onClick: doCopyRef }, props.copyIcon || '⧉', ' 复制到画布'),
|
|
el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制图片链接', onClick: doCopyLink }, '🔗 链接'),
|
|
) : null,
|
|
)
|
|
}
|
|
global.IWBResultImg = ResultImg
|
|
})(typeof window !== 'undefined' ? window : globalThis)
|