Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(msg-left-item):support json highlight #1381

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ const plugins = [
styleLibraryName: 'theme-chalk',
},
],
[
'prismjs',
{
languages: ['javascript'],
plugins: ['line-numbers'],
theme: 'okaidia',
css: true,
},
],
]
if (process.env.NODE_ENV === 'development') {
plugins.push('dynamic-import-node')
}
module.exports = {
presets: [
'@vue/app',
],
presets: ['@vue/app'],
plugins,
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"moment": "^2.29.4",
"monaco-editor": "^0.25.2",
"mqtt": "4.3.7",
"prismjs": "^1.29.0",
"protobufjs": "^7.2.4",
"reflect-metadata": "^0.1.13",
"rxjs": "6.2.0",
Expand Down Expand Up @@ -78,6 +79,7 @@
"@types/lodash": "^4.14.142",
"@types/mocha": "^5.2.7",
"@types/node": "^14.16.0",
"@types/prismjs": "^1.26.0",
"@types/sqlite3": "^3.1.8",
"@types/ws": "^8.2.1",
"@typescript-eslint/eslint-plugin": "^3.8.0",
Expand All @@ -90,6 +92,7 @@
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-plugin-component": "^1.1.1",
"babel-plugin-prismjs": "^2.1.0",
"chai": "^4.1.2",
"electron": "^13.6.6",
"electron-devtools-installer": "^3.2.0",
Expand Down
18 changes: 17 additions & 1 deletion src/components/MsgLeftItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
/>
</p>
</div>
<pre>{{ payload }}</pre>
<pre v-if="!hightlight">{{ payload }}</pre>
<pre v-else><code class="language-js line-numbers" >{{ payload }}</code></pre>
</div>
<p class="left-time time">{{ createAt }}</p>
</div>
Expand All @@ -63,6 +64,7 @@
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator'
import KeyValueEditor from './KeyValueEditor.vue'
import Prism from 'prismjs'

@Component({
components: {
Expand All @@ -78,6 +80,7 @@ export default class MsgLeftItem extends Vue {
@Prop({ required: false, default: false }) public retain!: boolean
@Prop({ required: false, default: () => ({}) }) public properties!: PushPropertiesModel
@Prop({ required: false, default: '' }) public color!: string
private hightlight: boolean = false

private customMenu(event: MouseEvent) {
this.$emit('showmenu', this.payload, event)
Expand All @@ -90,6 +93,19 @@ export default class MsgLeftItem extends Vue {
get schemaName() {
return this.meta ? JSON.parse(this.meta).schemaName : null
}

private mounted() {
try {
if (this.payload && JSON.parse(this.payload)) {
this.hightlight = true
this.$nextTick(() => {
Prism.highlightAll()
})
}
} catch (e) {
this.hightlight = false
}
}
}
</script>

Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,11 @@
"@types/node" "*"
xmlbuilder ">=11.0.1"

"@types/prismjs@^1.26.0":
version "1.26.0"
resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.26.0.tgz#a1c3809b0ad61c62cac6d4e0c56d610c910b7654"
integrity sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==

"@types/q@^1.5.1":
version "1.5.4"
resolved "https://registry.npmjs.org/@types/q/-/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24"
Expand Down Expand Up @@ -2515,6 +2520,11 @@ babel-plugin-polyfill-regenerator@^0.2.2:
dependencies:
"@babel/helper-define-polyfill-provider" "^0.2.2"

babel-plugin-prismjs@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/babel-plugin-prismjs/-/babel-plugin-prismjs-2.1.0.tgz#ade627896106326ad04d6d77fba92877618de571"
integrity sha512-ehzSKYfeAz4U78zi/sfwsjDPlq0LvDKxNefcZTJ/iKBu+plsHsLqZhUeGf1+82LAcA35UZGbU6ksEx2Utphc/g==

babel-runtime@6.x, babel-runtime@^6.18.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
Expand Down Expand Up @@ -9719,6 +9729,11 @@ printj@~1.1.0, printj@~1.1.2:
resolved "https://registry.npmjs.org/printj/-/printj-1.1.2.tgz#d90deb2975a8b9f600fb3a1c94e3f4c53c78a222"
integrity sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==

prismjs@^1.29.0:
version "1.29.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
integrity sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==

process-nextick-args@^2.0.1, process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down
Loading