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.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: {
root: {
data: {
@ -21,8 +22,8 @@
lang: 'zh',
localConfig: null
}
const setTakeOverAppMethods = data => {
window.takeOverAppMethods = {}
// 获取思维导图数据的函数
@ -51,35 +52,44 @@
}
}
function isBase64(str) {
if (str === '' || str.trim() === '') {
return false
}
try {
return btoa(atob(str)) == str
} catch (err) {
return false
}
}
function decodeBase64(base64String) {
// 将Base64字符串分成每64个字符一组
const padding =
base64String.length % 4 === 0 ? 0 : 4 - (base64String.length % 4)
base64String += '='.repeat(padding)
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)
// 使用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
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)
}
// 将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
@ -88,14 +98,24 @@ function decodeBase64(base64String) {
//setTakeOverAppMethods(initData)
return;
}
initData.mindMapData = JSON.parse(decodeBase64(data.content))
//console.log(initData.mindMapData)
//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 () => {
if (!window.takeOverApp) return
// 请求数据
//const data = await getDataFromBackend()
window.parent.postMessage({ type: 'initSuccess' }, '*')
@ -113,4 +133,4 @@ function decodeBase64(base64String) {
}
window.addEventListener('unload', () => {
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>
<!-- built files will be auto injected -->
<script>
// markdown from 'simple-mind-map/src/parse/markdown.js'
var initData = {
mindMapData: {
root: {
@ -75,10 +75,71 @@
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 () => {
if (!window.takeOverApp) return
// 请求数据
//const data = await getDataFromBackend()
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 i18n from './i18n'
import { getLang } from '@/api'
import markdown from 'simple-mind-map/src/parse/markdown.js';
// import VConsole from 'vconsole'
// const vConsole = new VConsole()
window.markdownParse = markdown;
Vue.config.productionTip = false
const bus = new Vue()
Vue.prototype.$bus = bus

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

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

Loading…
Cancel
Save