mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 11:50:52 +08:00

* feat: image setting * opti: inline image * add imageSelectAction * remove axios from muya * update image selector * finish image selector ui * add load success style * delete image by click delete icon * opti structure of image html * handle arrow key * enter to edit * image preview by press space * handle backspace when the previous element is image wrapper * update codes for change another PC * emable select all in input * handle arrow and backspace key * create a new paragraph after the last paragraph if its not empty * handle backspace when the previous element is image wrapper * handle enter event in image selector * rewrite auto show image selector * modify image folder * copy file to folder * select image * handle paste image * picgo * guess image path from clipboard * drag and drop image to Mark Text * add github uploader * remove unused codes * remove unused codes * rewrite image path auto complete * support `path` imageInsertAction * doc: add image uploader doc * remove debug codes * set init value in image uploader page * fix typo * remove unused codes * drag web image to Mark Text * add save notification * opti uploading process * fix did not close image selector bug * check image content type when drag web link image * fix: unable to preview relative path image. * emit change event after paste/drop image * add url map in image selector * feat: screenshot and auto insert the screenshot image * update error handler * feat: use the native screencapture command line on macOs system * opti: drop image * fix: handle enter error when cursor is after a image * fix: hasOwnProperty error * remove debug codes * fix: backspace when the previous ele is image * fix: CI error and optimize some codes * use hash of file path to generate the copied filename * change default imageInsertAction to `path` * fix: typo * remove some unused codes and opti get image file name * fix some bugs and opti codes * update image edit icon * romove screen capture on Linux and Windows * fix: conflict * fix error that can not insert image after the existed image or before existed image
95 lines
2.3 KiB
JavaScript
95 lines
2.3 KiB
JavaScript
import BaseScrollFloat from '../baseScrollFloat'
|
|
import { patch, h } from '../../parser/render/snabbdom'
|
|
import FolderIcon from '../../assets/icons/folder.svg'
|
|
import ImageIcon from '../../assets/icons/image.svg'
|
|
import UploadIcon from '../../assets/icons/upload.svg'
|
|
|
|
import './index.css'
|
|
|
|
const iconhash = {
|
|
'icon-image': ImageIcon,
|
|
'icon-folder': FolderIcon,
|
|
'icon-upload': UploadIcon
|
|
}
|
|
|
|
class ImagePathPicker extends BaseScrollFloat {
|
|
static pluginName = 'imagePathPicker'
|
|
constructor (muya) {
|
|
const name = 'ag-list-picker'
|
|
super(muya, name)
|
|
this.renderArray = []
|
|
this.oldVnode = null
|
|
this.activeItem = null
|
|
this.floatBox.classList.add('ag-image-picker-wrapper')
|
|
this.listen()
|
|
}
|
|
|
|
listen () {
|
|
super.listen()
|
|
const { eventCenter } = this.muya
|
|
eventCenter.subscribe('muya-image-picker', ({ reference, list, cb }) => {
|
|
if (list.length) {
|
|
this.show(reference, cb)
|
|
this.renderArray = list
|
|
this.activeItem = list[0]
|
|
this.render()
|
|
} else {
|
|
this.hide()
|
|
}
|
|
})
|
|
}
|
|
|
|
render () {
|
|
const { renderArray, oldVnode, scrollElement, activeItem } = this
|
|
let children = renderArray.map((item) => {
|
|
const { text, iconClass } = item
|
|
const icon = h('div.icon-wrapper', h('svg', {
|
|
attrs: {
|
|
viewBox: iconhash[iconClass].viewBox,
|
|
'aria-hidden': 'true'
|
|
},
|
|
hook: {
|
|
prepatch (oldvnode, vnode) {
|
|
// cheat snabbdom that the pre block is changed!!!
|
|
oldvnode.children = []
|
|
oldvnode.elm.innerHTML = ''
|
|
}
|
|
}
|
|
}, h('use', {
|
|
attrs: {
|
|
'xlink:href': iconhash[iconClass].url
|
|
}
|
|
}))
|
|
)
|
|
const textEle = h('div.language', text)
|
|
const selector = activeItem === item ? 'li.item.active' : 'li.item'
|
|
return h(selector, {
|
|
dataset: {
|
|
label: item.text
|
|
},
|
|
on: {
|
|
click: () => {
|
|
this.selectItem(item)
|
|
}
|
|
}
|
|
}, [icon, textEle])
|
|
})
|
|
|
|
const vnode = h('ul', children)
|
|
|
|
if (oldVnode) {
|
|
patch(oldVnode, vnode)
|
|
} else {
|
|
patch(scrollElement, vnode)
|
|
}
|
|
this.oldVnode = vnode
|
|
}
|
|
|
|
getItemElement (item) {
|
|
const { text } = item
|
|
return this.floatBox.querySelector(`[data-label="${text}"]`)
|
|
}
|
|
}
|
|
|
|
export default ImagePathPicker
|