-
Notifications
You must be signed in to change notification settings - Fork 20
/
LensReader.js
144 lines (124 loc) · 4.27 KB
/
LensReader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
var LensController = require('./LensController');
var BibliographyComponent = require('./packages/bibliography/BibliographyComponent');
var ContainerAnnotator = require('substance/ui/ContainerAnnotator');
var SplitPane = require("substance/ui/SplitPane");
var ScrollPane = require("substance/ui/ScrollPane");
var Cover = require('./packages/reader/Cover');
var Component = require('substance/ui/Component');
var $$ = Component.$$;
var CONFIG = {
controller: {
commands: [
require('substance/ui/UndoCommand'),
require('substance/ui/RedoCommand'),
require('substance/ui/SaveCommand')
],
components: {
"paragraph": require('substance/packages/paragraph/ParagraphComponent'),
"heading": require('substance/packages/heading/HeadingComponent'),
"blockquote": require('substance/packages/blockquote/BlockquoteComponent'),
"codeblock": require('substance/packages/codeblock/CodeblockComponent'),
"embed": require('substance/packages/embed/EmbedComponent'),
"image": require('substance/packages/image/ImageComponent'),
// "table": require('substance/packages/table/TableComponent'),
"image-figure": require('substance/packages/figure/FigureComponent'),
// "table-figure": require('substance/packages/figure/FigureComponent'),
"bib-item-citation": require('./packages/citations/CitationComponent'),
"image-figure-citation": require('./packages/citations/CitationComponent'),
// "table-figure-citation": require('./packages/citations/CitationComponent'),
// Panels
"toc": require('substance/ui/TOCPanel'),
"cite": require('./packages/citations/CitePanel'),
"bib-items": require('./packages/bibliography/BibItemsPanel'),
// We use different states for the same panel, so we can distinguish
// the citation type based on state.contextId
"cite-bib-item": require('./packages/citations/CitePanel'),
"cite-image-figure": require('./packages/citations/CitePanel'),
// "cite-table-figure": require('./packages/citations/CitePanel'),
"bib-item-entry": require('./packages/bibliography/BibItemEntry'),
"image-figure-entry": require('./packages/figures/ImageFigureEntry'),
},
},
main: {
commands: [],
},
cover: {
commands: []
},
panels: {
'toc': {
},
'bib-items': {
}
},
tabOrder: ['toc', 'bib-items'],
containerId: 'main',
isEditable: false
};
function LensReader() {
LensReader.super.apply(this, arguments);
this.connect(this, {
'citation:selected': this.onCitationSelected
});
}
LensReader.Prototype = function() {
var _super = Object.getPrototypeOf(this);
this.dispose = function() {
LensController.prototype.dispose.call(this);
this.disconnect(this);
};
this.render = function() {
return _super.render.call(this)
.addClass('sc-lens sc-lens-reader sc-controller');
};
this._renderMainSection = function() {
var config = this.getConfig();
return $$('div').ref('main').addClass('se-main-section').append(
// Content Panel below
$$(ScrollPane, {
scrollbarType: 'substance',
scrollbarPosition: 'left',
toc: this.toc,
highlights: this.contentHighlights
}).ref('contentPanel').append(
$$(Cover, {
name: 'cover',
commands: config.cover.commands
}).ref('coverView'),
// The full fledged document (ContainerEditor)
$$("div").ref('main').addClass('document-content').append(
$$(ContainerAnnotator, {
name: 'main',
editable: false,
containerId: config.containerId,
commands: config.main.commands
}).ref('mainEditor')
),
$$(BibliographyComponent).ref('bib')
)
);
};
this.onCitationSelected = function(citation) {
if (this.state.citationId === citation.id) {
this.setState({
contextId: 'toc'
});
return;
}
if (citation.type === 'bib-item-citation') {
this.setState({
contextId: 'bib-items',
citationId: citation.id
});
} else {
this.setState({
contextId: 'toc',
citationId: citation.id
});
}
};
};
LensController.extend(LensReader);
LensReader.static.config = CONFIG;
module.exports = LensReader;