Skip to content

Commit

Permalink
Update to latest Substance.
Browse files Browse the repository at this point in the history
Warning: There may still be some regressions.
  • Loading branch information
Michael Aufreiter committed Mar 15, 2016
1 parent 5d97c8d commit 93eab45
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 29 deletions.
8 changes: 4 additions & 4 deletions LensReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ var CONFIG = {
"codeblock": require('substance/packages/codeblock/CodeblockComponent'),
"embed": require('substance/packages/embed/EmbedComponent'),
"image": require('substance/packages/image/ImageComponent'),
"table": require('substance/packages/table/TableComponent'),
// "table": require('substance/packages/table/TableComponent'),

"image-figure": require('substance/packages/figure/FigureComponent'),
"table-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'),
// "table-figure-citation": require('./packages/citations/CitationComponent'),

// Panels
"toc": require('substance/ui/TOCPanel'),
Expand All @@ -41,7 +41,7 @@ var CONFIG = {
// 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'),
// "cite-table-figure": require('./packages/citations/CitePanel'),

"bib-item-entry": require('./packages/bibliography/BibItemEntry'),
"image-figure-entry": require('./packages/figures/ImageFigureEntry'),
Expand Down
8 changes: 4 additions & 4 deletions LensWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ var CONFIG = {
"codeblock": require('substance/packages/codeblock/CodeblockComponent'),
"embed": require('substance/packages/embed/EmbedComponent'),
"image": require('substance/packages/image/ImageComponent'),
"table": require('substance/packages/table/TableComponent'),
// "table": require('substance/packages/table/TableComponent'),

"image-figure": require('substance/packages/figure/FigureComponent'),
"table-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'),
// "table-figure-citation": require('./packages/citations/CitationComponent'),

// Panels
"toc": require('substance/ui/TOCPanel'),
Expand All @@ -46,7 +46,7 @@ var CONFIG = {
// 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'),
// "cite-table-figure": require('./packages/citations/CitePanel'),

"bib-item-entry": require('./packages/bibliography/BibItemEntry'),
"image-figure-entry": require('./packages/figures/ImageFigureEntry'),
Expand Down
20 changes: 11 additions & 9 deletions model/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Takes care of generating labels and keeping them up to date

var _ = require('substance/util/helpers');
var pluck = require('substance/util/pluck');
var oo = require('substance/util/oo');

function Collection(doc, containerId, itemType, labelPrefix) {
Expand Down Expand Up @@ -92,7 +93,7 @@ Collection.Prototype = function() {
}
var targetPos = _item.index + 1;
targetPositions.push(targetPos);
}, this);
}.bind(this));
targetPositions.sort();
// generate a label by concatenating numbers
// and provide a special label for empty citations.
Expand All @@ -111,15 +112,15 @@ Collection.Prototype = function() {
var label = this.createItemLabel(_item);
// console.log('generated item label', label);
_item.item.setLabel(label);
}, this);
}.bind(this));
};

this.updateCitationLabels = function() {
// console.log('citations', this.citations);
_.each(this._citations, function(_citation) {
var label = this.createCitationLabel(_citation);
_citation.citation.setLabel(label);
}, this);
}.bind(this));
};

// get citation nodes sorted by occurence in container.
Expand Down Expand Up @@ -156,10 +157,10 @@ Collection.Prototype = function() {
this._items = this.determineItems();
// Note: doing this right away allows us to easily find the
// position of an item
this.items = _.pluck(this._items, 'item');
this.items = pluck(this._items, 'item');

this._citations = this.determineCitations();
this.citations = _.pluck(this._citations, 'citation');
this.citations = pluck(this._citations, 'citation');

// compile labels
this.updateItemLabels();
Expand All @@ -175,6 +176,7 @@ Collection.Prototype = function() {
this.onDocumentChanged = function(change) {
var doc = this.doc;
var needsUpdate = false;
var node, deletedNode;

_.each(change.ops, function(op) {

Expand All @@ -184,7 +186,7 @@ Collection.Prototype = function() {

if (op.isCreate() || op.isSet() || op.isUpdate()) {
var nodeId = op.path[0];
var node = doc.get(nodeId);
node = doc.get(nodeId);
if (!node) return;

if (op.isCreate()) {
Expand All @@ -202,7 +204,7 @@ Collection.Prototype = function() {
}
} else if (op.isDelete()) {
// Delete
var deletedNode = op.val;
deletedNode = op.val;
if (deletedNode.type === 'image-figure-citation' || deletedNode.type === 'table-figure-citation') {
needsUpdate = true;
}
Expand All @@ -221,7 +223,7 @@ Collection.Prototype = function() {
// which have the inserted or removed value as `val`.
if (op.type === "update") {
var id = op.diff.val;
var node = doc.get(id);
node = doc.get(id);
// ATTENTION: as these are intermediate ops
// it may happen that the node itself has been
// deleted by a later op in this change
Expand All @@ -236,7 +238,7 @@ Collection.Prototype = function() {

// When node of this.itemType has been deleted
if (op.isDelete()) {
var deletedNode = op.val;
deletedNode = op.val;
if (deletedNode.type === this.itemType) {
needsUpdate = true;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"version": "0.2.0",
"dependencies": {
"body-parser": "1.14.1",
"browserify": "12.0.1",
"browserify": "substance/node-browserify#d3caeb6dcdaa97a258d099c7231a57f0f60ec876",
"cheerio": "0.19.0",
"ejs": "2.3.4",
"express": "4.13.3",
"font-awesome": "4.4.0",
"lodash": "3.10.1",
"node-sass": "3.4.2",
"substance": "substance/substance#1ca06abb701e2dcfd7a35b2a5f0802fc5d45e151"
"substance": "substance/substance#fcc5dbb5dcadb12aeef8db3ccef5805a2f07bf06"
},
"devDependencies": {
"gulp": "3.9.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/bibliography/Bibliography.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Bibliography.Prototype = function() {
data.id = bibItem.id;
compiler.addRecord(data);
this.bibitemsByGuid[bibItem.guid] = bibItem;
}, this);
}.bind(this));

// get citation nodes sorted by occurrence position.
var citations = doc.getIndex('type').get('bib-item-citation');
Expand Down Expand Up @@ -126,7 +126,7 @@ Bibliography.Prototype = function() {
} else {
citation.setLabel('???');
}
}, this);
}.bind(this));

var compiledBibItems = this.getCompiler().makeBibliography();
compiledBibItems = _.sortBy(compiledBibItems, "rank");
Expand All @@ -135,7 +135,7 @@ Bibliography.Prototype = function() {
bibItem.setLabel(item.label);
bibItem.setText(item.content);
return bibItem;
}, this);
}.bind(this));

this.emit('bibliography:updated');
};
Expand Down
12 changes: 7 additions & 5 deletions packages/reader/Cover.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var Component = require('substance/ui/Component');
var TextPropertyAnnotator = require('substance/ui/TextPropertyAnnotator');
var TextPropertyEditor = require('substance/ui/TextPropertyEditor');
var $$ = require('substance/ui/Component').$$;

function Cover() {
Expand All @@ -15,18 +15,20 @@ Cover.Prototype = function() {
var metaNode = doc.getDocumentMeta();
return $$("div").addClass("document-cover")
.append(
$$(TextPropertyAnnotator, {
$$(TextPropertyEditor, {
name: 'title',
tagName: "div",
path: [metaNode.id, "title"]
path: [metaNode.id, "title"],
editing: 'readonly'
}).addClass('title'),

// Abstract
$$('div').addClass('abstract').append(
$$(TextPropertyAnnotator, {
$$(TextPropertyEditor, {
name: 'abstract',
tagName: "div",
path: [metaNode.id, "abstract"]
path: [metaNode.id, "abstract"],
editing: 'readonly'
}).addClass('abstract')
)
);
Expand Down
6 changes: 4 additions & 2 deletions packages/writer/CoverEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ CoverEditor.Prototype = function() {
name: 'title',
tagName: "div",
commands: config.title.commands,
path: [metaNode.id, "title"]
path: [metaNode.id, "title"],
editing: 'full'
}).addClass('title'),

// Editable abstract
Expand All @@ -31,7 +32,8 @@ CoverEditor.Prototype = function() {
name: 'abstract',
tagName: 'div',
commands: config.abstract.commands,
path: [metaNode.id, 'abstract']
path: [metaNode.id, 'abstract'],
editing: 'full'
}).addClass('abstract')
)
);
Expand Down

0 comments on commit 93eab45

Please sign in to comment.