Skip to content

Commit

Permalink
Merge pull request #91 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
update MarkMap
  • Loading branch information
GuoXiCheng authored Jun 28, 2024
2 parents af44d89 + 8dd8dee commit 692822e
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
108 changes: 106 additions & 2 deletions src/MarkMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,111 @@
</div>
</template>

<script>
<script setup lang="ts">
import { onMounted } from 'vue';
import { Transformer } from 'markmap-lib';
import { Markmap, loadCSS, loadJS } from 'markmap-view';
import { Toolbar } from 'markmap-toolbar';
let markmapInstance: Markmap | null = null;
const props = defineProps({
markdown: String
})
onMounted(() => {
const markmapFormat = convertMarkdown(props.markdown);
localStorage.setItem('markmap-state-raw', JSON.stringify(markmapFormat));
createOrUpdateMarkmap(markmapFormat);
addToolbar(markmapInstance);
});
const createOrUpdateMarkmap = (markmapFormat) => {
if (markmapInstance) {
markmapInstance.destroy();
}
markmapInstance = Markmap.create('#markmap', undefined, markmapFormat);
}
const convertMarkdown = (markdown) => {
const transformer = new Transformer();
const { root, features } = transformer.transform(markdown);
const assets = transformer.getAssets();
if (assets.styles) loadCSS(assets.styles);
if (assets.scripts) loadJS(assets.scripts, { getMarkmap: () => (window as any).markmap });
return root;
}
const addToolbar = (markmap) => {
Toolbar.defaultItems = [{
content: createElementImg('Docker'),
title: 'Docker',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[3].children[0]);
}
}, {
content: createElementImg('React'),
title: 'React',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[1].children[1]);
}
}, {
content: createElementImg('NodeJS'),
title: 'NodeJS',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[2].children[0]);
}
}, {
content: createElementImg('JavaScript'),
title: 'JavaScript',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[0]);
}
}, {
content: createElementImg('Vue'),
title: 'Vue',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[1].children[0]);
}
}, {
content: createElementImg('All'),
title: 'All',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw));
}
}];
const toolbar = Toolbar.create(markmap);
toolbar.setBrand(false)
toolbar.el.style.position = 'absolute';
toolbar.el.style.bottom = '0.5rem';
toolbar.el.style.right = '0.5rem';
document.getElementById('container')?.appendChild(toolbar.el);
}
const createElementImg = (filename) => {
const img = document.createElement('img');
img.src = `/images/svg/${filename}.svg`;
img.style.width = '1.5rem';
img.style.height = '1.5rem';
img.style.cursor = 'pointer';
return img;
}
</script>

<!-- <script>
import { onMounted } from 'vue';
import { Transformer } from 'markmap-lib';
import { Markmap, loadCSS, loadJS } from 'markmap-view';
Expand Down Expand Up @@ -100,4 +204,4 @@ export default {
}
}
};
</script>
</script> -->
1 change: 1 addition & 0 deletions src/public/images/svg/All.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/public/images/svg/Docker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/public/images/svg/JavaScript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/public/images/svg/NodeJS.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/public/images/svg/React.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/public/images/svg/Vue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 692822e

Please sign in to comment.