Browse Source

add md to mind

master
godo 7 months ago
parent
commit
9dfbd3b088
  1. 2
      frontend/public/mind/css/chunk-b15d02c4.css
  2. 84
      frontend/public/mind/index.html
  3. 2
      frontend/public/mind/js/app.js
  4. 65
      frontend/public/mind/js/chunk-482daa00.js
  5. 65
      frontend/public/mind/js/chunk-b15d02c4.js
  6. 14
      frontend/public/mind/js/chunk-vendors.js
  7. 67
      packages/mind/public/index.html
  8. 2
      packages/mind/src/main.js
  9. 437
      packages/mind/src/pages/Edit/components/Toolbar.vue

2
frontend/public/mind/css/chunk-482daa00.css → frontend/public/mind/css/chunk-b15d02c4.css

File diff suppressed because one or more lines are too long

84
frontend/public/mind/index.html

@ -2,7 +2,8 @@
window.externalPublicPath = './' window.externalPublicPath = './'
// 接管应用 // 接管应用
window.takeOverApp = true window.takeOverApp = true
window.isSave = false</script><link href="css/chunk-vendors.css?f6765d552217b21768b4" rel="stylesheet"><link href="css/app.css?f6765d552217b21768b4" rel="stylesheet"></head><body><noscript><strong>We're sorry but thoughts doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script>var initData = { window.isSave = false</script><link href="css/chunk-vendors.css?11388431daeea24e08ab" rel="stylesheet"><link href="css/app.css?11388431daeea24e08ab" rel="stylesheet"></head><body><noscript><strong>We're sorry but thoughts doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script>// markdown from 'simple-mind-map/src/parse/markdown.js'
var initData = {
mindMapData: { mindMapData: {
root: { root: {
data: { data: {
@ -21,8 +22,8 @@
lang: 'zh', lang: 'zh',
localConfig: null localConfig: null
} }
const setTakeOverAppMethods = data => { const setTakeOverAppMethods = data => {
window.takeOverAppMethods = {} window.takeOverAppMethods = {}
// 获取思维导图数据的函数 // 获取思维导图数据的函数
@ -51,35 +52,44 @@
} }
} }
function isBase64(str) { function isBase64(str) {
if (str === '' || str.trim() === '') { if (str === '' || str.trim() === '') {
return false return false
} }
try { try {
return btoa(atob(str)) == str return btoa(atob(str)) == str
} catch (err) { } catch (err) {
return false return false
} }
} }
function decodeBase64(base64String) { function isJson(str) {
// 将Base64字符串分成每64个字符一组 try {
const padding = return JSON.parse(str) && !!str
base64String.length % 4 === 0 ? 0 : 4 - (base64String.length % 4) } catch (e) {
base64String += '='.repeat(padding) return false
}
}
function decodeBase64(base64String) {
//console.log(base64String)
// 将Base64字符串分成每64个字符一组
const padding =
base64String.length % 4 === 0 ? 0 : 4 - (base64String.length % 4)
base64String += '='.repeat(padding)
// 使用atob()函数解码Base64字符串 // 使用atob()函数解码Base64字符串
const binaryString = atob(base64String) const binaryString = atob(base64String)
// 将二进制字符串转换为TypedArray // 将二进制字符串转换为TypedArray
const bytes = new Uint8Array(binaryString.length) const bytes = new Uint8Array(binaryString.length)
for (let i = 0; i < binaryString.length; i++) { for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i) bytes[i] = binaryString.charCodeAt(i)
} }
// 将TypedArray转换为字符串 // 将TypedArray转换为字符串
return new TextDecoder('utf-8').decode(bytes) return new TextDecoder('utf-8').decode(bytes)
} }
const eventHandler = e => { const eventHandler = e => {
const eventData = e.data const eventData = e.data
//console.log(eventData)
if (eventData.type === 'init') { if (eventData.type === 'init') {
//markdownTitle = eventData.title ? eventData.title : '未命名文稿' //markdownTitle = eventData.title ? eventData.title : '未命名文稿'
const data = eventData.data const data = eventData.data
@ -88,14 +98,24 @@ function decodeBase64(base64String) {
//setTakeOverAppMethods(initData) //setTakeOverAppMethods(initData)
return; return;
} }
initData.mindMapData = JSON.parse(decodeBase64(data.content)) //console.log(data.content)
//console.log(initData.mindMapData) if (typeof data.content === 'string' && isBase64(data.content)) {
data.content = decodeBase64(data.content)
}
if (isJson(data.content)) {
initData.mindMapData = JSON.parse(data.content)
} else {
//console.log(data.content)
initData.mindMapData.root = markdownParse.transformMarkdownTo(data.content)
}
//initData.mindMapData = JSON.parse(data.content)
//console.log(initData.mindMapData)
} }
} }
window.onload = async () => { window.onload = async () => {
if (!window.takeOverApp) return if (!window.takeOverApp) return
// 请求数据 // 请求数据
//const data = await getDataFromBackend() //const data = await getDataFromBackend()
window.parent.postMessage({ type: 'initSuccess' }, '*') window.parent.postMessage({ type: 'initSuccess' }, '*')
@ -113,4 +133,4 @@ function decodeBase64(base64String) {
} }
window.addEventListener('unload', () => { window.addEventListener('unload', () => {
window.removeEventListener('message', eventHandler) window.removeEventListener('message', eventHandler)
})</script><script src="js/chunk-vendors.js?f6765d552217b21768b4"></script><script src="js/app.js?f6765d552217b21768b4"></script></body></html> })</script><script src="js/chunk-vendors.js?11388431daeea24e08ab"></script><script src="js/app.js?11388431daeea24e08ab"></script></body></html>

2
frontend/public/mind/js/app.js

File diff suppressed because one or more lines are too long

65
frontend/public/mind/js/chunk-482daa00.js

File diff suppressed because one or more lines are too long

65
frontend/public/mind/js/chunk-b15d02c4.js

File diff suppressed because one or more lines are too long

14
frontend/public/mind/js/chunk-vendors.js

File diff suppressed because one or more lines are too long

67
packages/mind/public/index.html

@ -26,7 +26,7 @@
<div id="app"></div> <div id="app"></div>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
<script> <script>
// markdown from 'simple-mind-map/src/parse/markdown.js'
var initData = { var initData = {
mindMapData: { mindMapData: {
root: { root: {
@ -75,10 +75,71 @@
console.log(config) console.log(config)
} }
} }
function isBase64(str) {
if (str === '' || str.trim() === '') {
return false
}
try {
return btoa(atob(str)) == str
} catch (err) {
return false
}
}
function isJson(str) {
try {
return JSON.parse(str) && !!str
} catch (e) {
return false
}
}
function decodeBase64(base64String) {
//console.log(base64String)
// 将Base64字符串分成每64个字符一组
const padding =
base64String.length % 4 === 0 ? 0 : 4 - (base64String.length % 4)
base64String += '='.repeat(padding)
// 使用atob()函数解码Base64字符串
const binaryString = atob(base64String)
// 将二进制字符串转换为TypedArray
const bytes = new Uint8Array(binaryString.length)
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i)
}
// 将TypedArray转换为字符串
return new TextDecoder('utf-8').decode(bytes)
}
const eventHandler = e => {
const eventData = e.data
//console.log(eventData)
if (eventData.type === 'init') {
//markdownTitle = eventData.title ? eventData.title : '未命名文稿'
const data = eventData.data
//console.log(data)
if (!data) {
//setTakeOverAppMethods(initData)
return;
}
//console.log(data.content)
if (typeof data.content === 'string' && isBase64(data.content)) {
data.content = decodeBase64(data.content)
}
if (isJson(data.content)) {
initData.mindMapData = JSON.parse(data.content)
} else {
//console.log(data.content)
initData.mindMapData.root = markdownParse.transformMarkdownTo(data.content)
}
//initData.mindMapData = JSON.parse(data.content)
//console.log(initData.mindMapData)
}
}
window.onload = async () => { window.onload = async () => {
if (!window.takeOverApp) return if (!window.takeOverApp) return
// 请求数据 // 请求数据
//const data = await getDataFromBackend() //const data = await getDataFromBackend()
window.parent.postMessage({ type: 'initSuccess' }, '*') window.parent.postMessage({ type: 'initSuccess' }, '*')

2
packages/mind/src/main.js

@ -9,9 +9,11 @@ import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer' import VueViewer from 'v-viewer'
import i18n from './i18n' import i18n from './i18n'
import { getLang } from '@/api' import { getLang } from '@/api'
import markdown from 'simple-mind-map/src/parse/markdown.js';
// import VConsole from 'vconsole' // import VConsole from 'vconsole'
// const vConsole = new VConsole() // const vConsole = new VConsole()
window.markdownParse = markdown;
Vue.config.productionTip = false Vue.config.productionTip = false
const bus = new Vue() const bus = new Vue()
Vue.prototype.$bus = bus Vue.prototype.$bus = bus

437
packages/mind/src/pages/Edit/components/Toolbar.vue

@ -297,7 +297,7 @@ export default {
} }
}, },
created() { created() {
this.$bus.$on('write_local_file', this.onWriteLocalFile) //this.$bus.$on('write_local_file', this.onWriteLocalFile)
}, },
mounted() { mounted() {
this.computeToolbarShow() this.computeToolbarShow()
@ -309,7 +309,7 @@ export default {
}, },
beforeDestroy() { beforeDestroy() {
this.$bus.$off('write_local_file', this.onWriteLocalFile) // this.$bus.$off('write_local_file', this.onWriteLocalFile)
window.removeEventListener('resize', this.computeToolbarShowThrottle) window.removeEventListener('resize', this.computeToolbarShowThrottle)
this.$bus.$off('lang_change', this.computeToolbarShowThrottle) this.$bus.$off('lang_change', this.computeToolbarShowThrottle)
window.removeEventListener('beforeunload', this.onUnload) window.removeEventListener('beforeunload', this.onUnload)
@ -343,219 +343,196 @@ export default {
}, },
// //
onWriteLocalFile(content) { // onWriteLocalFile(content) {
clearTimeout(this.timer) // clearTimeout(this.timer)
if (fileHandle && this.isHandleLocalFile) { // if (fileHandle && this.isHandleLocalFile) {
this.waitingWriteToLocalFile = true // this.waitingWriteToLocalFile = true
} // }
this.timer = setTimeout(() => { // this.timer = setTimeout(() => {
this.writeLocalFile(content) // this.writeLocalFile(content)
}, 1000) // }, 1000)
}, // },
onUnload(e) { onUnload(e) {
if (this.waitingWriteToLocalFile) { // if (this.waitingWriteToLocalFile) {
const msg = '存在未保存的数据' // const msg = ''
e.returnValue = msg // e.returnValue = msg
return msg // return msg
} // }
}, },
// //
async loadFileTreeNode(node, resolve) { // async loadFileTreeNode(node, resolve) {
try { // try {
let dirHandle // let dirHandle
if (node.level === 0) { // if (node.level === 0) {
dirHandle = await window.showDirectoryPicker() // dirHandle = await window.showDirectoryPicker()
this.rootDirName = dirHandle.name // this.rootDirName = dirHandle.name
} else { // } else {
dirHandle = node.data.handle // dirHandle = node.data.handle
} // }
const dirList = [] // const dirList = []
const fileList = [] // const fileList = []
for await (const [key, value] of dirHandle.entries()) { // for await (const [key, value] of dirHandle.entries()) {
const isFile = value.kind === 'file' // const isFile = value.kind === 'file'
if (isFile && !/\.(smm|xmind|md|json)$/.test(value.name)) { // if (isFile && !/\.(smm|xmind|md|json)$/.test(value.name)) {
continue // continue
} // }
const enableEdit = isFile && /\.smm$/.test(value.name) // const enableEdit = isFile && /\.smm$/.test(value.name)
const data = { // const data = {
id: key, // id: key,
name: value.name, // name: value.name,
type: value.kind, // type: value.kind,
handle: value, // handle: value,
leaf: isFile, // leaf: isFile,
enableEdit // enableEdit
} // }
if (isFile) { // if (isFile) {
fileList.push(data) // fileList.push(data)
} else { // } else {
dirList.push(data) // dirList.push(data)
} // }
} // }
resolve([...dirList, ...fileList]) // resolve([...dirList, ...fileList])
} catch (error) { // } catch (error) {
console.log(error) // console.log(error)
this.fileTreeVisible = false // this.fileTreeVisible = false
resolve([]) // resolve([])
if (error.toString().includes('aborted')) { // if (error.toString().includes('aborted')) {
return // return
} // }
this.$message.warning(this.$t('toolbar.notSupportTip')) // this.$message.warning(this.$t('toolbar.notSupportTip'))
} // }
}, // },
// //
openDirectory() { // openDirectory() {
this.fileTreeVisible = false // this.fileTreeVisible = false
this.fileTreeExpand = true // this.fileTreeExpand = true
this.rootDirName = '' // this.rootDirName = ''
this.$nextTick(() => { // this.$nextTick(() => {
this.fileTreeVisible = true // this.fileTreeVisible = true
}) // })
}, // },
// //
editLocalFile(data) { // editLocalFile(data) {
if (data.handle) { // if (data.handle) {
fileHandle = data.handle // fileHandle = data.handle
this.readFile() // this.readFile()
} // }
}, // },
// //
async importLocalFile(data) { // async importLocalFile(data) {
try { // try {
const file = await data.handle.getFile() // const file = await data.handle.getFile()
this.$refs.ImportRef.onChange({ // this.$refs.ImportRef.onChange({
raw: file, // raw: file,
name: file.name // name: file.name
}) // })
this.$refs.ImportRef.confirm() // this.$refs.ImportRef.confirm()
} catch (error) { // } catch (error) {
console.log(error) // console.log(error)
} // }
}, // },
// //
async openLocalFile() { // async openLocalFile() {
try { // try {
let [_fileHandle] = await window.showOpenFilePicker({ // let [_fileHandle] = await window.showOpenFilePicker({
types: [ // types: [
{ // {
description: '', // description: '',
accept: { // accept: {
'application/json': ['.smm'] // 'application/json': ['.smm']
} // }
} // }
], // ],
excludeAcceptAllOption: true, // excludeAcceptAllOption: true,
multiple: false // multiple: false
}) // })
if (!_fileHandle) { // if (!_fileHandle) {
return // return
} // }
fileHandle = _fileHandle // fileHandle = _fileHandle
if (fileHandle.kind === 'directory') { // if (fileHandle.kind === 'directory') {
this.$message.warning(this.$t('toolbar.selectFileTip')) // this.$message.warning(this.$t('toolbar.selectFileTip'))
return // return
} // }
this.readFile() // this.readFile()
} catch (error) { // } catch (error) {
console.log(error) // console.log(error)
if (error.toString().includes('aborted')) { // if (error.toString().includes('aborted')) {
return // return
} // }
this.$message.warning(this.$t('toolbar.notSupportTip')) // this.$message.warning(this.$t('toolbar.notSupportTip'))
} // }
}, // },
// // //
async readFile() { // async readFile() {
let file = await fileHandle.getFile() // let file = await fileHandle.getFile()
let fileReader = new FileReader() // let fileReader = new FileReader()
fileReader.onload = async () => { // fileReader.onload = async () => {
this.$store.commit('setIsHandleLocalFile', true) // this.$store.commit('setIsHandleLocalFile', true)
this.setData(fileReader.result) // this.setData(fileReader.result)
Notification.closeAll() // Notification.closeAll()
Notification({ // Notification({
title: this.$t('toolbar.tip'), // title: this.$t('toolbar.tip'),
message: `${this.$t('toolbar.editingLocalFileTipFront')}${file.name // message: `${this.$t('toolbar.editingLocalFileTipFront')}${file.name
}${this.$t('toolbar.editingLocalFileTipEnd')}`, // }${this.$t('toolbar.editingLocalFileTipEnd')}`,
duration: 0, // duration: 0,
showClose: true // showClose: true
}) // })
} // }
fileReader.readAsText(file) // fileReader.readAsText(file)
}, // },
// //
setData(str) { // setData(str) {
try { // try {
let data = JSON.parse(str) // let data = JSON.parse(str)
if (typeof data !== 'object') { // if (typeof data !== 'object') {
throw new Error(this.$t('toolbar.fileContentError')) // throw new Error(this.$t('toolbar.fileContentError'))
} // }
if (data.root) { // if (data.root) {
this.isFullDataFile = true // this.isFullDataFile = true
} else { // } else {
this.isFullDataFile = false // this.isFullDataFile = false
data = { // data = {
...exampleData, // ...exampleData,
root: data // root: data
} // }
} // }
this.$bus.$emit('setData', data) // this.$bus.$emit('setData', data)
} catch (error) { // } catch (error) {
console.log(error) // console.log(error)
this.$message.error(this.$t('toolbar.fileOpenFailed')) // this.$message.error(this.$t('toolbar.fileOpenFailed'))
} // }
}, // },
// //
async writeLocalFile(content) { // async writeLocalFile(content) {
if (!fileHandle || !this.isHandleLocalFile) { // if (!fileHandle || !this.isHandleLocalFile) {
this.waitingWriteToLocalFile = false // this.waitingWriteToLocalFile = false
return // return
} // }
if (!this.isFullDataFile) { // if (!this.isFullDataFile) {
content = content.root // content = content.root
} // }
let string = JSON.stringify(content) // let string = JSON.stringify(content)
const writable = await fileHandle.createWritable() // const writable = await fileHandle.createWritable()
await writable.write(string) // await writable.write(string)
await writable.close() // await writable.close()
this.waitingWriteToLocalFile = false // this.waitingWriteToLocalFile = false
}, // },
// //
async createNewLocalFile() { // async createNewLocalFile() {
await this.createLocalFile(exampleData) // await this.createLocalFile(exampleData)
}, // },
eventHandler(e) {
const eventData = e.data
let mindData = getData()
if (eventData.type === 'init') {
//markdownTitle = eventData.title ? eventData.title : '稿'
const data = eventData.data
//console.log(data)
if (!data) {
//setTakeOverAppMethods(initData)
return;
}
if (isBase64(data.content)) {
data.content = decodeBase64(data.content)
}
if(isJson(data.content)) {
mindData.mindMapData = JSON.parse(data.content)
}else{
mindData.mindMapData = markdown.transformMarkdownTo(data.content)
}
//initData.mindMapData = JSON.parse(data.content)
console.log(mindData.mindMapData)
}
},
// //
async saveLocalFile() { async saveLocalFile() {
let data = getData() let data = getData()
@ -577,40 +554,40 @@ export default {
} }
}, },
// //
async createLocalFile(content) { // async createLocalFile(content) {
try { // try {
let _fileHandle = await window.showSaveFilePicker({ // let _fileHandle = await window.showSaveFilePicker({
types: [ // types: [
{ // {
description: '', // description: '',
accept: { 'application/json': ['.smm'] } // accept: { 'application/json': ['.smm'] }
} // }
], // ],
suggestedName: this.$t('toolbar.defaultFileName') // suggestedName: this.$t('toolbar.defaultFileName')
}) // })
if (!_fileHandle) { // if (!_fileHandle) {
return // return
} // }
const loading = this.$loading({ // const loading = this.$loading({
lock: true, // lock: true,
text: this.$t('toolbar.creatingTip'), // text: this.$t('toolbar.creatingTip'),
spinner: 'el-icon-loading', // spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)' // background: 'rgba(0, 0, 0, 0.7)'
}) // })
fileHandle = _fileHandle // fileHandle = _fileHandle
this.$store.commit('setIsHandleLocalFile', true) // this.$store.commit('setIsHandleLocalFile', true)
this.isFullDataFile = true // this.isFullDataFile = true
await this.writeLocalFile(content) // await this.writeLocalFile(content)
await this.readFile() // await this.readFile()
loading.close() // loading.close()
} catch (error) { // } catch (error) {
console.log(error) // console.log(error)
if (error.toString().includes('aborted')) { // if (error.toString().includes('aborted')) {
return // return
} // }
this.$message.warning(this.$t('toolbar.notSupportTip')) // this.$message.warning(this.$t('toolbar.notSupportTip'))
} // }
} // }
} }
} }
</script> </script>

Loading…
Cancel
Save