@@ -5,9 +5,8 @@ import { once } from '../misc';
5
5
6
6
const getlazy = client . import ( 'getlazy' ) ;
7
7
8
- let views ;
9
- export default views = {
10
- dom ( { tag, attrs, contents} , opts ) {
8
+
9
+ export function dom ( { tag, attrs, contents} , opts ) {
11
10
const view = document . createElement ( tag ) ;
12
11
for ( let k in attrs ) {
13
12
let v = attrs [ k ] ;
@@ -19,65 +18,65 @@ export default views = {
19
18
contents = [ contents ] ;
20
19
}
21
20
for ( let child of contents ) {
22
- view . appendChild ( this . render ( child , opts ) ) ;
21
+ view . appendChild ( render ( child , opts ) ) ;
23
22
}
24
23
}
25
24
return view ;
26
- } ,
25
+ }
27
26
28
- html ( ...args ) {
27
+ export function html ( ...args ) {
29
28
const obj = args [ 0 ] ,
30
29
{
31
30
content
32
31
} = obj ,
33
32
val = obj . block ,
34
33
block = val != null ? val : false ;
35
- let view = this . render ( block ? this . tags . div ( ) : this . tags . span ( ) ) ;
34
+ let view = render ( block ? tags . div ( ) : tags . span ( ) ) ;
36
35
view . innerHTML = content ;
37
36
return view = view . children . length === 1 ? view . children [ 0 ] : view ;
38
- } ,
37
+ }
39
38
40
- tree ( { head, children, expand} , opts ) {
41
- this . ink . tree . treeView ( this . render ( head , opts ) ,
42
- children . map ( x => this . render ( this . tags . div ( [ x ] ) , opts ) ) ,
39
+ export function tree ( { head, children, expand} , opts ) {
40
+ this . ink . tree . treeView ( render ( head , opts ) ,
41
+ children . map ( x => render ( tags . div ( [ x ] ) , opts ) ) ,
43
42
{ expand} ) ;
44
- } ,
43
+ }
45
44
46
- lazy ( { head, id} , opts ) {
45
+ export function lazy ( { head, id} , opts ) {
47
46
const conn = client . conn ;
48
47
if ( opts . registerLazy != null ) {
49
48
opts . registerLazy ( id ) ;
50
49
} else {
51
50
console . warn ( 'Unregistered lazy view' ) ;
52
51
}
53
52
let view ;
54
- return view = this . ink . tree . treeView ( this . render ( head , opts ) , [ ] , {
53
+ return view = this . ink . tree . treeView ( render ( head , opts ) , [ ] , {
55
54
onToggle : once ( ( ) => {
56
55
if ( client . conn !== conn ) { return ; }
57
56
getlazy ( id ) . then ( children => {
58
57
const body = view . querySelector ( ':scope > .body' ) ;
59
- children . map ( x => this . render ( this . tags . div ( [ x ] ) , opts ) ) . forEach ( x => {
58
+ children . map ( x => render ( tags . div ( [ x ] ) , opts ) ) . forEach ( x => {
60
59
body . appendChild ( this . ink . ansiToHTML ( x ) ) ;
61
60
} ) ;
62
61
} ) ;
63
62
} )
64
63
}
65
64
) ;
66
- } ,
65
+ }
67
66
68
- subtree ( { label, child} , opts ) {
69
- return this . render ( ( child . type === "tree" ?{
67
+ export function subtree ( { label, child} , opts ) {
68
+ return render ( ( child . type === "tree" ?{
70
69
type : "tree" ,
71
- head : this . tags . span ( [ label , child . head ] ) ,
70
+ head : tags . span ( [ label , child . head ] ) ,
72
71
children : child . children
73
72
}
74
73
// children: child.children.map((x) => @tags.span "gutted", x)
75
74
:
76
- this . tags . span ( "gutted" , [ label , child ] ) ) , opts ) ;
77
- } ,
75
+ tags . span ( "gutted" , [ label , child ] ) ) , opts ) ;
76
+ }
78
77
79
- copy ( { view, text} , opts ) {
80
- view = this . render ( view , opts ) ;
78
+ export function copy ( { view, text} , opts ) {
79
+ view = render ( view , opts ) ;
81
80
atom . commands . add ( view , {
82
81
'core:copy' ( e ) {
83
82
atom . clipboard . write ( text ) ;
@@ -86,10 +85,10 @@ export default views = {
86
85
}
87
86
) ;
88
87
return view ;
89
- } ,
88
+ }
90
89
91
- link ( { file, line, contents} ) {
92
- const view = this . render ( this . tags . a ( { href : '#' } , contents ) ) ;
90
+ export function link ( { file, line, contents} ) {
91
+ const view = render ( tags . a ( { href : '#' } , contents ) ) ;
93
92
// TODO: maybe need to dispose of the tooltip onclick and readd them, but
94
93
// that doesn't seem to be necessary
95
94
let tt ;
@@ -108,35 +107,35 @@ export default views = {
108
107
tt . dispose ( ) ;
109
108
} ) ;
110
109
return view ;
111
- } ,
110
+ }
112
111
113
- number ( { value, full} ) {
112
+ export function number ( { value, full} ) {
114
113
let rounded = value . toPrecision ( 3 ) ;
115
114
if ( rounded . toString ( ) . length < full . length ) { rounded += '…' ; }
116
- const view = this . render ( this . tags . span ( 'syntax--constant syntax--numeric' , rounded ) ) ;
115
+ const view = render ( tags . span ( 'syntax--constant syntax--numeric' , rounded ) ) ;
117
116
let isfull = false ;
118
117
view . onclick = function ( e ) {
119
118
view . innerText = ! isfull ? full : rounded ;
120
119
isfull = ! isfull ;
121
120
e . stopPropagation ( ) ;
122
121
} ;
123
122
return view ;
124
- } ,
123
+ }
125
124
126
- code ( { text, attrs, scope} ) {
125
+ export function code ( { text, attrs, scope} ) {
127
126
const grammar = atom . grammars . grammarForScopeName ( "source.julia" ) ;
128
127
const block = ( attrs != null ? attrs . block : undefined ) || false ; // attrs?.block || false
129
128
const highlighted = Highlighter . highlight ( text , grammar , { scopePrefix : 'syntax--' , block} ) ;
130
- return this . render ( { type : 'html' , block, content : highlighted } ) ;
131
- } ,
129
+ return render ( { type : 'html' , block, content : highlighted } ) ;
130
+ }
132
131
133
- latex ( { attrs, text} ) {
132
+ export function latex ( { attrs, text} ) {
134
133
const block = ( attrs != null ? attrs . block : undefined ) || false ; // attrs?.block || false
135
134
const latex = this . ink . KaTeX . texify ( text , block ) ;
136
- return this . render ( { type : 'html' , block, content : latex } ) ;
137
- } ,
135
+ return render ( { type : 'html' , block, content : latex } ) ;
136
+ }
138
137
139
- views : {
138
+ export const views = {
140
139
// TODO Remove unnecessary use of Array.from
141
140
dom ( ...a ) { return views . dom ( ...Array . from ( a || [ ] ) ) ; } ,
142
141
html ( ...a ) { return views . html ( ...Array . from ( a || [ ] ) ) ; } ,
@@ -148,21 +147,21 @@ export default views = {
148
147
number ( ...a ) { return views . number ( ...Array . from ( a || [ ] ) ) ; } ,
149
148
code ( ...a ) { return views . code ( ...Array . from ( a || [ ] ) ) ; } ,
150
149
latex ( ...a ) { return views . latex ( ...Array . from ( a || [ ] ) ) ; }
151
- } ,
150
+ }
152
151
153
- render ( data , opts = { } ) {
154
- if ( this . views . hasOwnProperty ( data . type ) ) {
155
- const r = this . views [ data . type ] ( data , opts ) ;
152
+ export function render ( data , opts = { } ) {
153
+ if ( views . hasOwnProperty ( data . type ) ) {
154
+ const r = views [ data . type ] ( data , opts ) ;
156
155
this . ink . ansiToHTML ( r ) ;
157
156
return r ;
158
157
} else if ( ( data != null ? data . constructor : undefined ) === String ) { // data?.constructor === String
159
158
return new Text ( data ) ;
160
159
} else {
161
- return this . render ( `julia-client: can't render ${ ( data != null ? data . type : undefined ) } ` ) ; // data?.type
160
+ return render ( `julia-client: can't render ${ ( data != null ? data . type : undefined ) } ` ) ; // data?.type
162
161
}
163
- } ,
162
+ }
164
163
165
- tag ( tag , attrs , contents ) {
164
+ export function tag ( tag , attrs , contents ) {
166
165
if ( ( attrs != null ? attrs . constructor : undefined ) === String ) { // attrs?.constructor === String
167
166
attrs = { class : attrs } ;
168
167
}
@@ -175,9 +174,10 @@ export default views = {
175
174
attrs,
176
175
contents
177
176
} ;
178
- } ,
179
-
180
- tags : { }
181
- } ;
177
+ }
182
178
183
- [ 'div' , 'span' , 'a' , 'strong' , 'table' , 'tr' , 'td' , 'webview' ] . forEach ( tag => views . tags [ tag ] = ( attrs , contents ) => views . tag ( tag , attrs , contents ) ) ;
179
+ export let tags = { }
180
+ const tags_arr = [ 'div' , 'span' , 'a' , 'strong' , 'table' , 'tr' , 'td' , 'webview' ]
181
+ for ( let _tag of tags_arr ) {
182
+ tags [ _tag ] = ( attrs , contents ) => tag ( _tag , attrs , contents )
183
+ }
0 commit comments