Skip to content

Commit cfec528

Browse files
committed
feat: enhance image handling and update Topic interface
1 parent 5e38a6a commit cfec528

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mind-elixir",
3-
"version": "4.3.0",
3+
"version": "4.3.1",
44
"type": "module",
55
"description": "Mind elixir is a free open source mind map core.",
66
"keywords": [

src/exampleData/1.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const aboutMindElixir: MindElixirData = {
1818
topic: 'mind-elixir',
1919
image: {
2020
url: 'https://raw.githubusercontent.com/ssshooter/mind-elixir-core/master/images/logo2.png',
21-
height: 90,
21+
height: 100,
2222
width: 90,
23+
fit: 'contain',
2324
},
2425
},
2526
],

src/nodeOperation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const rmSubline = function (tpc: Topic) {
1717
if (lc?.tagName === 'svg') lc?.remove() // clear svg group of main node
1818
}
1919

20-
export const reshapeNode = function (this: MindElixirInstance, tpc: Topic, patchData: NodeObj) {
20+
export const reshapeNode = function (this: MindElixirInstance, tpc: Topic, patchData: Partial<NodeObj>) {
2121
const nodeObj = tpc.nodeObj
2222
const origin = deepClone(nodeObj)
2323
// merge styles

src/types/dom.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface Topic extends HTMLElement {
3737
text: HTMLSpanElement
3838
expander?: Expander
3939

40-
linkContainer?: HTMLElement
40+
link?: HTMLElement
4141
image?: HTMLImageElement
4242
icons?: HTMLSpanElement
4343
tags?: HTMLDivElement

src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export type NodeObj = {
174174
url: string
175175
width: number
176176
height: number
177+
fit?: 'fill' | 'contain' | 'cover'
177178
}
178179
// main node specific properties
179180
branchColor?: string

src/utils/dom.ts

+32-31
Original file line numberDiff line numberDiff line change
@@ -31,55 +31,56 @@ export const shapeTpc = function (tpc: Topic, nodeObj: NodeObj) {
3131
if (nodeObj.image) {
3232
const img = nodeObj.image
3333
if (img.url && img.width && img.height) {
34-
const imgContainer = $d.createElement('img')
35-
imgContainer.src = img.url
36-
imgContainer.style.width = img.width + 'px'
37-
imgContainer.style.height = img.height + 'px'
38-
tpc.appendChild(imgContainer)
39-
tpc.image = imgContainer
34+
const imgEl = $d.createElement('img')
35+
imgEl.src = img.url
36+
imgEl.style.width = img.width + 'px'
37+
imgEl.style.height = img.height + 'px'
38+
if (img.fit) imgEl.style.objectFit = img.fit
39+
tpc.appendChild(imgEl)
40+
tpc.image = imgEl
4041
} else {
41-
console.warn('image url/width/height are required')
42+
console.warn('Image url/width/height are required')
4243
}
4344
} else if (tpc.image) {
4445
tpc.image = undefined
4546
}
4647

4748
{
48-
const textContainer = $d.createElement('span')
49-
textContainer.className = 'text'
50-
textContainer.textContent = nodeObj.topic
51-
tpc.appendChild(textContainer)
52-
tpc.text = textContainer
49+
const textEl = $d.createElement('span')
50+
textEl.className = 'text'
51+
textEl.textContent = nodeObj.topic
52+
tpc.appendChild(textEl)
53+
tpc.text = textEl
5354
}
5455

5556
if (nodeObj.hyperLink) {
56-
const linkContainer = $d.createElement('a')
57-
linkContainer.className = 'hyper-link'
58-
linkContainer.target = '_blank'
59-
linkContainer.innerText = '🔗'
60-
linkContainer.href = nodeObj.hyperLink
61-
tpc.appendChild(linkContainer)
62-
tpc.linkContainer = linkContainer
63-
} else if (tpc.linkContainer) {
64-
tpc.linkContainer = undefined
57+
const linkEl = $d.createElement('a')
58+
linkEl.className = 'hyper-link'
59+
linkEl.target = '_blank'
60+
linkEl.innerText = '🔗'
61+
linkEl.href = nodeObj.hyperLink
62+
tpc.appendChild(linkEl)
63+
tpc.link = linkEl
64+
} else if (tpc.link) {
65+
tpc.link = undefined
6566
}
6667

6768
if (nodeObj.icons && nodeObj.icons.length) {
68-
const iconsContainer = $d.createElement('span')
69-
iconsContainer.className = 'icons'
70-
iconsContainer.innerHTML = nodeObj.icons.map(icon => `<span>${encodeHTML(icon)}</span>`).join('')
71-
tpc.appendChild(iconsContainer)
72-
tpc.icons = iconsContainer
69+
const iconsEl = $d.createElement('span')
70+
iconsEl.className = 'icons'
71+
iconsEl.innerHTML = nodeObj.icons.map(icon => `<span>${encodeHTML(icon)}</span>`).join('')
72+
tpc.appendChild(iconsEl)
73+
tpc.icons = iconsEl
7374
} else if (tpc.icons) {
7475
tpc.icons = undefined
7576
}
7677

7778
if (nodeObj.tags && nodeObj.tags.length) {
78-
const tagsContainer = $d.createElement('div')
79-
tagsContainer.className = 'tags'
80-
tagsContainer.innerHTML = nodeObj.tags.map(tag => `<span>${encodeHTML(tag)}</span>`).join('')
81-
tpc.appendChild(tagsContainer)
82-
tpc.tags = tagsContainer
79+
const tagsEl = $d.createElement('div')
80+
tagsEl.className = 'tags'
81+
tagsEl.innerHTML = nodeObj.tags.map(tag => `<span>${encodeHTML(tag)}</span>`).join('')
82+
tpc.appendChild(tagsEl)
83+
tpc.tags = tagsEl
8384
} else if (tpc.tags) {
8485
tpc.tags = undefined
8586
}

0 commit comments

Comments
 (0)