git ssb

16+

Dominic / patchbay



Tree: a67310f0467e9b58b0c980e5f8c2e806b4239eee

Files: a67310f0467e9b58b0c980e5f8c2e806b4239eee / message / html / meta / raw.js

1337 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3
4exports.gives = nest('message.html.meta')
5
6exports.needs = nest({
7 'about.obs.name': 'first',
8 'message.obs.likes': 'first'
9})
10
11exports.create = (api) => {
12 return nest('message.html.meta', raw)
13
14 function raw (msg, { rawMessage } = {}) {
15 return h('i.toggle-raw-msg.fa.fa-plus', {
16 title: 'View raw data',
17 style: {
18 order: 99,
19 color: '#a8a8a8',
20 cursor: 'pointer'
21 },
22 'ev-click': () => (rawMessage() === null)
23 ? rawMessage.set(buildRawMsg(msg))
24 : rawMessage.set(null)
25 })
26 }
27}
28
29function buildRawMsg (msg) {
30 return h('pre',
31 colorKeys(linkify(
32 JSON.stringify({ key: msg.key, value: msg.value }, 0, 2)
33 ))
34 )
35}
36
37function colorKeys (chunks) {
38 var newArray = []
39 chunks.forEach(chunk => {
40 if (typeof chunk !== 'string') return newArray.push(chunk)
41
42 var arr = chunk.split(/("[^"]+":)/)
43 for (var i = 1; i < arr.length; i += 2) {
44 arr[i] = h('span', arr[i])
45 }
46 newArray = [...newArray, ...arr]
47 })
48
49 return newArray
50}
51
52function linkify (text) {
53 // from ssb-ref
54 var refRegex = /((?:@|%|&)[A-Za-z0-9/+]{43}=\.[\w\d]+)/g
55
56 var arr = text.split(refRegex)
57 for (var i = 1; i < arr.length; i += 2) {
58 arr[i] = h('a', {href: arr[i]}, arr[i])
59 }
60 return arr
61}
62

Built with git-ssb-web