Comparing version 3.5.0 to 3.6.0
@@ -382,4 +382,2 @@ "use strict"; | ||
} | ||
/* eslint-disable no-unused-vars */ | ||
}, { | ||
@@ -386,0 +384,0 @@ key: "addRow", |
@@ -42,23 +42,15 @@ "use strict"; | ||
key: "parseOpen", | ||
value: function parseOpen() | ||
/* node */ | ||
{// Sax Open Node event | ||
value: function parseOpen(node) {// XML node opened | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText() | ||
/* node */ | ||
{// Sax Text event | ||
value: function parseText(text) {// chunk of text encountered for current node | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose() | ||
/* name */ | ||
{// Sax Close Node event | ||
value: function parseClose(name) {// XML node closed | ||
} | ||
}, { | ||
key: "reconcile", | ||
value: function reconcile() | ||
/* model, options */ | ||
{} // optional post-parse step (opposite to prepare) | ||
value: function reconcile(model, options) {} // optional post-parse step (opposite to prepare) | ||
// ============================================================ | ||
@@ -105,2 +97,3 @@ | ||
try { | ||
// console.log('opentag', node.name); | ||
_this.parseOpen(node); | ||
@@ -120,2 +113,3 @@ } catch (error) { | ||
try { | ||
// console.log('closetag', name); | ||
if (!_this.parseClose(name)) { | ||
@@ -129,2 +123,3 @@ resolve(_this.model); | ||
parser.on('end', function () { | ||
// console.log('end'); | ||
resolve(_this.model); | ||
@@ -164,3 +159,9 @@ }); | ||
value: function toAttribute(value, dflt) { | ||
if (value !== undefined && value !== dflt) { | ||
var allways = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if (value === undefined) { | ||
if (allways) { | ||
return dflt; | ||
} | ||
} else if (allways || value !== dflt) { | ||
return value.toString(); | ||
@@ -174,7 +175,4 @@ } | ||
value: function toStringAttribute(value, dflt) { | ||
if (value !== dflt) { | ||
return value; | ||
} | ||
return undefined; | ||
var allways = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
return BaseXform.toAttribute(value, dflt, allways); | ||
} | ||
@@ -189,3 +187,9 @@ }, { | ||
value: function toBoolAttribute(value, dflt) { | ||
if (value !== undefined && value !== dflt) { | ||
var allways = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if (value === undefined) { | ||
if (allways) { | ||
return dflt; | ||
} | ||
} else if (allways || value !== dflt) { | ||
return value ? '1' : '0'; | ||
@@ -204,3 +208,4 @@ } | ||
value: function toIntAttribute(value, dflt) { | ||
return BaseXform.toAttribute(value, dflt); | ||
var allways = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
return BaseXform.toAttribute(value, dflt, allways); | ||
} | ||
@@ -215,3 +220,4 @@ }, { | ||
value: function toFloatAttribute(value, dflt) { | ||
return BaseXform.toAttribute(value, dflt); | ||
var allways = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
return BaseXform.toAttribute(value, dflt, allways); | ||
} | ||
@@ -218,0 +224,0 @@ }, { |
@@ -87,9 +87,11 @@ "use strict"; | ||
if (sheet.pageSetup && sheet.pageSetup.printArea) { | ||
var printArea = sheet.pageSetup.printArea.split(':'); | ||
var definedName = { | ||
name: '_xlnm.Print_Area', | ||
ranges: ["'".concat(sheet.name, "'!$").concat(printArea[0], ":$").concat(printArea[1])], | ||
localSheetId: index | ||
}; | ||
printAreas.push(definedName); | ||
sheet.pageSetup.printArea.split('&&').forEach(function (printArea) { | ||
var printAreaComponents = printArea.split(':'); | ||
var definedName = { | ||
name: '_xlnm.Print_Area', | ||
ranges: ["'".concat(sheet.name, "'!$").concat(printAreaComponents[0], ":$").concat(printAreaComponents[1])], | ||
localSheetId: index | ||
}; | ||
printAreas.push(definedName); | ||
}); | ||
} | ||
@@ -110,3 +112,3 @@ | ||
var _definedName = { | ||
var definedName = { | ||
name: '_xlnm.Print_Titles', | ||
@@ -116,3 +118,3 @@ ranges: ranges, | ||
}; | ||
printAreas.push(_definedName); | ||
printAreas.push(definedName); | ||
} | ||
@@ -249,3 +251,3 @@ | ||
var range = colCache.decodeEx(definedName.ranges[0]); | ||
worksheet.pageSetup.printArea = range.dimensions; | ||
worksheet.pageSetup.printArea = worksheet.pageSetup.printArea ? "".concat(worksheet.pageSetup.printArea, "&&").concat(range.dimensions) : range.dimensions; | ||
} | ||
@@ -252,0 +254,0 @@ } else if (definedName.name === '_xlnm.Print_Titles') { |
@@ -22,3 +22,9 @@ "use strict"; | ||
var BaseXform = require('./base-xform'); | ||
/* 'virtual' methods used as a form of documentation */ | ||
/* eslint-disable class-methods-use-this */ | ||
// base class for xforms that are composed of other xforms | ||
// offers some default implementations | ||
var CompositeXform = | ||
@@ -29,59 +35,27 @@ /*#__PURE__*/ | ||
function CompositeXform(options) { | ||
var _this; | ||
function CompositeXform() { | ||
_classCallCheck(this, CompositeXform); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CompositeXform).call(this)); | ||
_this.tag = options.tag; | ||
_this.attrs = options.attrs; | ||
_this.children = options.children; | ||
_this.map = _this.children.reduce(function (map, child) { | ||
var name = child.name || child.tag; | ||
var tag = child.tag || child.name; | ||
map[tag] = child; | ||
child.name = name; | ||
child.tag = tag; | ||
return map; | ||
}, {}); | ||
return _this; | ||
return _possibleConstructorReturn(this, _getPrototypeOf(CompositeXform).apply(this, arguments)); | ||
} | ||
_createClass(CompositeXform, [{ | ||
key: "prepare", | ||
value: function prepare(model, options) { | ||
this.children.forEach(function (child) { | ||
child.xform.prepare(model[child.tag], options); | ||
}); | ||
key: "createNewModel", | ||
value: function createNewModel(node) { | ||
return {}; | ||
} | ||
}, { | ||
key: "render", | ||
value: function render(xmlStream, model) { | ||
xmlStream.openNode(this.tag, this.attrs); | ||
this.children.forEach(function (child) { | ||
child.xform.render(xmlStream, model[child.name]); | ||
}); | ||
xmlStream.closeNode(); | ||
} | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
// Typical pattern for composite xform | ||
this.parser = this.parser || this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.xform.parseOpen(node); | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = {}; | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.xform.parseOpen(node); | ||
return true; | ||
} | ||
if (node.name === this.tag) { | ||
this.model = this.createNewModel(node); | ||
return true; | ||
} | ||
@@ -94,12 +68,21 @@ | ||
value: function parseText(text) { | ||
// Default implementation. Send text to child parser | ||
if (this.parser) { | ||
this.parser.xform.parseText(text); | ||
this.parser.parseText(text); | ||
} | ||
} | ||
}, { | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
// parseClose has seen a child parser close | ||
// now need to incorporate into this.model somehow | ||
this.model[name] = parser.model; | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
// Default implementation | ||
if (this.parser) { | ||
if (!this.parser.xform.parseClose(name)) { | ||
this.model[this.parser.name] = this.parser.xform.model; | ||
if (!this.parser.parseClose(name)) { | ||
this.onParserClose(name, this.parser); | ||
this.parser = undefined; | ||
@@ -111,11 +94,4 @@ } | ||
return false; | ||
return name !== this.tag; | ||
} | ||
}, { | ||
key: "reconcile", | ||
value: function reconcile(model, options) { | ||
this.children.forEach(function (child) { | ||
child.xform.prepare(model[child.tag], options); | ||
}); | ||
} | ||
}]); | ||
@@ -122,0 +98,0 @@ |
@@ -27,6 +27,6 @@ "use strict"; | ||
var uuid = require('uuid'); | ||
var BaseXform = require('../../base-xform'); | ||
var CompositeXform = require('../../composite-xform'); | ||
var Range = require('../../../../doc/range'); | ||
@@ -123,5 +123,5 @@ | ||
var opType = function opType(attr) { | ||
var type = attr.type, | ||
operator = attr.operator; | ||
var opType = function opType(attributes) { | ||
var type = attributes.type, | ||
operator = attributes.operator; | ||
@@ -149,4 +149,4 @@ switch (type) { | ||
/*#__PURE__*/ | ||
function (_BaseXform) { | ||
_inherits(CfRuleXform, _BaseXform); | ||
function (_CompositeXform) { | ||
_inherits(CfRuleXform, _CompositeXform); | ||
@@ -161,3 +161,3 @@ function CfRuleXform() { | ||
dataBar: _this.databarXform = new DatabarXform(), | ||
extLst: _this.extLstXform = new ExtLstRefXform(), | ||
extLst: _this.extLstRefXform = new ExtLstRefXform(), | ||
formula: _this.formulaXform = new FormulaXform(), | ||
@@ -245,5 +245,5 @@ colorScale: _this.colorScaleXform = new ColorScaleXform(), | ||
priority: model.priority, | ||
percent: model.percent ? '1' : undefined, | ||
bottom: model.bottom ? '1' : undefined, | ||
rank: model.rank || 10 | ||
percent: BaseXform.toBoolAttribute(model.percent, false), | ||
bottom: BaseXform.toBoolAttribute(model.bottom, false), | ||
rank: BaseXform.toIntValue(model.rank, 10, true) | ||
}); | ||
@@ -258,3 +258,3 @@ } | ||
priority: model.priority, | ||
aboveAverage: model.aboveAverage === false ? '0' : undefined | ||
aboveAverage: BaseXform.toBoolAttribute(model.aboveAverage, true) | ||
}); | ||
@@ -270,4 +270,3 @@ } | ||
this.databarXform.render(xmlStream, model); | ||
model.x14Id = "{".concat(uuid.v4(), "}"); | ||
this.extLstXform.render(xmlStream, model); | ||
this.extLstRefXform.render(xmlStream, model); | ||
xmlStream.closeNode(); | ||
@@ -307,3 +306,3 @@ } | ||
priority: model.priority, | ||
operator: model.operator === 'containsText' ? model.operator : undefined | ||
operator: BaseXform.toStringAttribute(model.operator, 'containsText') | ||
}); | ||
@@ -336,69 +335,33 @@ var formula = getTextFormula(model); | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = _objectSpread({}, opType(node.attributes), { | ||
dxfId: BaseXform.toIntValue(node.attributes.dxfId), | ||
priority: BaseXform.toIntValue(node.attributes.priority), | ||
timePeriod: node.attributes.timePeriod, | ||
percent: BaseXform.toBoolValue(node.attributes.percent), | ||
bottom: BaseXform.toBoolValue(node.attributes.bottom), | ||
rank: BaseXform.toIntValue(node.attributes.rank), | ||
aboveAverage: BaseXform.toBoolValue(node.attributes.aboveAverage) | ||
}); | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
key: "createNewModel", | ||
value: function createNewModel(_ref) { | ||
var attributes = _ref.attributes; | ||
return _objectSpread({}, opType(attributes), { | ||
dxfId: BaseXform.toIntValue(attributes.dxfId), | ||
priority: BaseXform.toIntValue(attributes.priority), | ||
timePeriod: attributes.timePeriod, | ||
percent: BaseXform.toBoolValue(attributes.percent), | ||
bottom: BaseXform.toBoolValue(attributes.bottom), | ||
rank: BaseXform.toIntValue(attributes.rank), | ||
aboveAverage: BaseXform.toBoolValue(attributes.aboveAverage) | ||
}); | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
switch (name) { | ||
case 'dataBar': | ||
case 'extLst': | ||
case 'colorScale': | ||
case 'iconSet': | ||
// merge parser model with ours | ||
Object.assign(this.model, this.parser.model); | ||
break; | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
switch (name) { | ||
case 'dataBar': | ||
case 'extLst': | ||
case 'colorScale': | ||
case 'iconSet': | ||
// merge parser model with ours | ||
Object.assign(this.model, parser.model); | ||
break; | ||
case 'formula': | ||
// except - formula is a string and appends to formulae | ||
this.model.formulae = this.model.formulae || []; | ||
this.model.formulae.push(this.parser.model); | ||
break; | ||
} | ||
this.parser = null; | ||
} | ||
return true; | ||
case 'formula': | ||
// except - formula is a string and appends to formulae | ||
this.model.formulae = this.model.formulae || []; | ||
this.model.formulae.push(parser.model); | ||
break; | ||
} | ||
return name !== this.tag; | ||
} | ||
@@ -425,5 +388,5 @@ }, { | ||
return CfRuleXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = CfRuleXform; | ||
//# sourceMappingURL=cf-rule-xform.js.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
var BaseXform = require('../../base-xform'); | ||
var CompositeXform = require('../../composite-xform'); | ||
@@ -30,4 +30,4 @@ var ColorXform = require('../../style/color-xform'); | ||
/*#__PURE__*/ | ||
function (_BaseXform) { | ||
_inherits(ColorScaleXform, _BaseXform); | ||
function (_CompositeXform) { | ||
_inherits(ColorScaleXform, _CompositeXform); | ||
@@ -62,51 +62,15 @@ function ColorScaleXform() { | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
cfvo: [], | ||
color: [] | ||
}; | ||
break; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
key: "createNewModel", | ||
value: function createNewModel(node) { | ||
return { | ||
cfvo: [], | ||
color: [] | ||
}; | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
this.model[name].push(parser.model); | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model[name].push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
}, { | ||
key: "tag", | ||
@@ -119,5 +83,5 @@ get: function get() { | ||
return ColorScaleXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = ColorScaleXform; | ||
//# sourceMappingURL=color-scale-xform.js.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
var BaseXform = require('../../base-xform'); | ||
var CompositeXform = require('../../composite-xform'); | ||
@@ -28,4 +28,4 @@ var CfRuleXform = require('./cf-rule-xform'); | ||
/*#__PURE__*/ | ||
function (_BaseXform) { | ||
_inherits(ConditionalFormattingXform, _BaseXform); | ||
function (_CompositeXform) { | ||
_inherits(ConditionalFormattingXform, _CompositeXform); | ||
@@ -67,43 +67,16 @@ function ConditionalFormattingXform() { | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
this.parser = this.parser || this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
if (node.name === this.tag) { | ||
this.model = { | ||
ref: node.attributes.sqref, | ||
rules: [] | ||
}; | ||
return true; | ||
} | ||
return false; | ||
key: "createNewModel", | ||
value: function createNewModel(_ref) { | ||
var attributes = _ref.attributes; | ||
return { | ||
ref: attributes.sqref, | ||
rules: [] | ||
}; | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
this.model.rules.push(parser.model); | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model.rules.push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
}, { | ||
key: "tag", | ||
@@ -116,5 +89,5 @@ get: function get() { | ||
return ConditionalFormattingXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = ConditionalFormattingXform; | ||
//# sourceMappingURL=conditional-formatting-xform.js.map |
@@ -44,8 +44,3 @@ "use strict"; | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ConditionalFormattingsXform).call(this)); | ||
_this.cfXform = new ConditionalFormattingXform(); // thanks to Excel, conditionalFormatting nodes are directly inside | ||
// <worksheet>, not inside some <conditionalFormattings> node so | ||
// we create initial model here | ||
_this.reset(); | ||
_this.cfXform = new ConditionalFormattingXform(); | ||
return _this; | ||
@@ -52,0 +47,0 @@ } |
@@ -21,3 +21,3 @@ "use strict"; | ||
var BaseXform = require('../../base-xform'); | ||
var CompositeXform = require('../../composite-xform'); | ||
@@ -30,4 +30,4 @@ var ColorXform = require('../../style/color-xform'); | ||
/*#__PURE__*/ | ||
function (_BaseXform) { | ||
_inherits(DatabarXform, _BaseXform); | ||
function (_CompositeXform) { | ||
_inherits(DatabarXform, _CompositeXform); | ||
@@ -56,55 +56,24 @@ function DatabarXform() { | ||
}); | ||
model.color.forEach(function (color) { | ||
_this2.colorXform.render(xmlStream, color); | ||
}); | ||
this.colorXform.render(xmlStream, model.color); | ||
xmlStream.closeNode(); | ||
} | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
cfvo: [], | ||
color: [] | ||
}; | ||
break; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
key: "createNewModel", | ||
value: function createNewModel() { | ||
return { | ||
cfvo: [] | ||
}; | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model[name].push(this.parser.model); | ||
this.parser = null; | ||
} | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
switch (name) { | ||
case 'cfvo': | ||
this.model.cfvo.push(parser.model); | ||
break; | ||
return true; | ||
case 'color': | ||
this.model.color = parser.model; | ||
break; | ||
} | ||
return name !== this.tag; | ||
} | ||
@@ -119,5 +88,5 @@ }, { | ||
return DatabarXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = DatabarXform; | ||
//# sourceMappingURL=databar-xform.js.map |
@@ -24,2 +24,4 @@ "use strict"; | ||
var CompositeXform = require('../../composite-xform'); | ||
var X14IdXform = | ||
@@ -68,4 +70,4 @@ /*#__PURE__*/ | ||
/*#__PURE__*/ | ||
function (_BaseXform2) { | ||
_inherits(ExtXform, _BaseXform2); | ||
function (_CompositeXform) { | ||
_inherits(ExtXform, _CompositeXform); | ||
@@ -79,3 +81,3 @@ function ExtXform() { | ||
_this.map = { | ||
'x14:id': new X14IdXform() | ||
'x14:id': _this.idXform = new X14IdXform() | ||
}; | ||
@@ -92,49 +94,16 @@ return _this; | ||
}); | ||
this.map['x14:id'].render(model.x14Id); | ||
this.idXform.render(xmlStream, model.x14Id); | ||
xmlStream.closeNode(); | ||
} | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = {}; | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
} | ||
return true; | ||
} | ||
key: "createNewModel", | ||
value: function createNewModel() { | ||
return {}; | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
this.model.x14Id = parser.model; | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.parser = undefined; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
}, { | ||
key: "tag", | ||
@@ -147,8 +116,8 @@ get: function get() { | ||
return ExtXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
var ExtLstRefXform = | ||
/*#__PURE__*/ | ||
function (_BaseXform3) { | ||
_inherits(ExtLstRefXform, _BaseXform3); | ||
function (_CompositeXform2) { | ||
_inherits(ExtLstRefXform, _CompositeXform2); | ||
@@ -175,13 +144,10 @@ function ExtLstRefXform() { | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
this.model = { | ||
type: node.attributes.type, | ||
value: node.attributes.val | ||
}; | ||
key: "createNewModel", | ||
value: function createNewModel() { | ||
return {}; | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
return name !== this.tag; | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
Object.assign(this.model, parser.model); | ||
} | ||
@@ -196,5 +162,5 @@ }, { | ||
return ExtLstRefXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = ExtLstRefXform; | ||
//# sourceMappingURL=ext-lst-ref-xform.js.map |
@@ -23,2 +23,4 @@ "use strict"; | ||
var CompositeXform = require('../../composite-xform'); | ||
var CfvoXform = require('./cfvo-xform'); | ||
@@ -28,4 +30,4 @@ | ||
/*#__PURE__*/ | ||
function (_BaseXform) { | ||
_inherits(IconSetXform, _BaseXform); | ||
function (_CompositeXform) { | ||
_inherits(IconSetXform, _CompositeXform); | ||
@@ -60,53 +62,18 @@ function IconSetXform() { | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
iconSet: BaseXform.toStringValue(node.attributes.iconSet, '3TrafficLights'), | ||
reverse: BaseXform.toBoolValue(node.attributes.reverse), | ||
showValue: BaseXform.toBoolValue(node.attributes.showValue), | ||
cfvo: [] | ||
}; | ||
break; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
key: "createNewModel", | ||
value: function createNewModel(_ref) { | ||
var attributes = _ref.attributes; | ||
return { | ||
iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'), | ||
reverse: BaseXform.toBoolValue(attributes.reverse), | ||
showValue: BaseXform.toBoolValue(attributes.showValue), | ||
cfvo: [] | ||
}; | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
this.model[name].push(parser.model); | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model[name].push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
}, { | ||
key: "tag", | ||
@@ -119,5 +86,5 @@ get: function get() { | ||
return IconSetXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = IconSetXform; | ||
//# sourceMappingURL=icon-set-xform.js.map |
@@ -21,19 +21,20 @@ "use strict"; | ||
var BaseXform = require('../base-xform'); | ||
/* eslint-disable max-classes-per-file */ | ||
var CompositeXform = require('../composite-xform'); | ||
var ConditionalFormattingsExt = require('./cf/conditional-formattings-ext-xform'); | ||
var ConditionalFormattingsExt = require('./cf-ext/conditional-formattings-ext-xform'); | ||
var ExtLstXform = | ||
var ExtXform = | ||
/*#__PURE__*/ | ||
function (_BaseXform) { | ||
_inherits(ExtLstXform, _BaseXform); | ||
function (_CompositeXform) { | ||
_inherits(ExtXform, _CompositeXform); | ||
function ExtLstXform() { | ||
function ExtXform() { | ||
var _this; | ||
_classCallCheck(this, ExtLstXform); | ||
_classCallCheck(this, ExtXform); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ExtLstXform).call(this)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ExtXform).call(this)); | ||
_this.map = { | ||
'x14:conditionalFormattings': new ConditionalFormattingsExt() | ||
'x14:conditionalFormattings': _this.conditionalFormattings = new ConditionalFormattingsExt() | ||
}; | ||
@@ -43,9 +44,15 @@ return _this; | ||
_createClass(ExtLstXform, [{ | ||
_createClass(ExtXform, [{ | ||
key: "hasContent", | ||
value: function hasContent(model) { | ||
return this.conditionalFormattings.hasContent(model.conditionalFormattings); | ||
} | ||
}, { | ||
key: "prepare", | ||
value: function prepare(model, options) { | ||
this.conditionalFormattings.prepare(model.conditionalFormattings, options); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render(xmlStream, model) { | ||
var hasContent = false; | ||
xmlStream.addRollback(); | ||
xmlStream.openNode('extLst'); // conditional formatting | ||
xmlStream.openNode('ext', { | ||
@@ -55,61 +62,74 @@ uri: '{78C0D931-6437-407d-A8EE-F0AAD7539E65}', | ||
}); | ||
var cfCursor = xmlStream.cursor; | ||
this.map['x14:conditionalFormattings'].render(model.conditionalFormattings); | ||
hasContent = hasContent || cfCursor !== xmlStream.cursor; | ||
this.conditionalFormattings.render(xmlStream, model.conditionalFormattings); | ||
xmlStream.closeNode(); | ||
xmlStream.closeNode(); | ||
if (hasContent) { | ||
xmlStream.commit(); | ||
} else { | ||
xmlStream.rollback(); | ||
} | ||
} | ||
}, { | ||
key: "parseOpen", | ||
value: function parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
key: "createNewModel", | ||
value: function createNewModel() { | ||
return {}; | ||
} | ||
}, { | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
this.model[name] = parser.model; | ||
} | ||
}, { | ||
key: "tag", | ||
get: function get() { | ||
return 'ext'; | ||
} | ||
}]); | ||
switch (node.name) { | ||
case 'extLst': | ||
this.model = {}; | ||
return true; | ||
return ExtXform; | ||
}(CompositeXform); | ||
case 'ext': | ||
return true; | ||
var ExtLstXform = | ||
/*#__PURE__*/ | ||
function (_CompositeXform2) { | ||
_inherits(ExtLstXform, _CompositeXform2); | ||
default: | ||
this.parser = this.map[node.name]; | ||
function ExtLstXform() { | ||
var _this2; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
} | ||
_classCallCheck(this, ExtLstXform); | ||
return true; | ||
} | ||
_this2 = _possibleConstructorReturn(this, _getPrototypeOf(ExtLstXform).call(this)); | ||
_this2.map = { | ||
'ext': _this2.ext = new ExtXform() | ||
}; | ||
return _this2; | ||
} | ||
_createClass(ExtLstXform, [{ | ||
key: "prepare", | ||
value: function prepare(model, options) { | ||
this.ext.prepare(model, options); | ||
} | ||
}, { | ||
key: "parseText", | ||
value: function parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
key: "hasContent", | ||
value: function hasContent(model) { | ||
return this.ext.hasContent(model); | ||
} | ||
}, { | ||
key: "parseClose", | ||
value: function parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.parser = undefined; | ||
} | ||
return true; | ||
key: "render", | ||
value: function render(xmlStream, model) { | ||
if (!this.hasContent(model)) { | ||
return; | ||
} | ||
return name !== 'extList'; | ||
xmlStream.openNode('extLst'); | ||
this.ext.render(xmlStream, model); | ||
xmlStream.closeNode(); | ||
} | ||
}, { | ||
key: "createNewModel", | ||
value: function createNewModel() { | ||
return {}; | ||
} | ||
}, { | ||
key: "onParserClose", | ||
value: function onParserClose(name, parser) { | ||
Object.assign(this.model, parser.model); | ||
} | ||
}, { | ||
key: "tag", | ||
@@ -122,5 +142,5 @@ get: function get() { | ||
return ExtLstXform; | ||
}(BaseXform); | ||
}(CompositeXform); | ||
module.exports = ExtLstXform; | ||
//# sourceMappingURL=ext-lst-xform.js.map |
@@ -75,2 +75,63 @@ "use strict"; | ||
var ExtListXform = require('./ext-lst-xform'); | ||
var mergeRule = function mergeRule(rule, extRule) { | ||
Object.keys(extRule).forEach(function (key) { | ||
var value = rule[key]; | ||
var extValue = extRule[key]; | ||
if (value === undefined && extValue !== undefined) { | ||
rule[key] = extValue; | ||
} | ||
}); | ||
}; | ||
var mergeConditionalFormattings = function mergeConditionalFormattings(model, extModel) { | ||
// conditional formattings are rendered in worksheet.conditionalFormatting and also in | ||
// worksheet.extLst.ext.x14:conditionalFormattings | ||
// some (e.g. dataBar) are even spread across both! | ||
if (!extModel || !extModel.length) { | ||
return model; | ||
} | ||
if (!model || !model.length) { | ||
return extModel; | ||
} // index model rules by x14Id | ||
var cfMap = {}; | ||
var ruleMap = {}; | ||
model.forEach(function (cf) { | ||
cfMap[cf.ref] = cf; | ||
cf.rules.forEach(function (rule) { | ||
var x14Id = rule.x14Id; | ||
if (x14Id) { | ||
ruleMap[x14Id] = rule; | ||
} | ||
}); | ||
}); | ||
extModel.forEach(function (extCf) { | ||
extCf.rules.forEach(function (extRule) { | ||
var rule = ruleMap[extRule.x14Id]; | ||
if (rule) { | ||
// merge with matching rule | ||
mergeRule(rule, extRule); | ||
} else if (cfMap[extCf.ref]) { | ||
// reuse existing cf ref | ||
cfMap[extCf.ref].rules.push(extRule); | ||
} else { | ||
// create new cf | ||
model.push({ | ||
ref: extCf.ref, | ||
rules: [extRule] | ||
}); | ||
} | ||
}); | ||
}); // need to cope with rules in extModel that don't exist in model | ||
return model; | ||
}; | ||
var WorkSheetXform = | ||
@@ -140,3 +201,4 @@ /*#__PURE__*/ | ||
}), | ||
conditionalFormatting: new ConditionalFormattingsXform() | ||
conditionalFormatting: new ConditionalFormattingsXform(), | ||
extLst: new ExtListXform() | ||
}; | ||
@@ -270,3 +332,5 @@ return _this; | ||
}); | ||
}); | ||
}); // prepare ext items | ||
this.map.extLst.prepare(model, options); | ||
} | ||
@@ -323,2 +387,3 @@ }, { | ||
this.map.tableParts.render(xmlStream, model.tables); | ||
this.map.extLst.render(xmlStream, model); | ||
@@ -398,2 +463,3 @@ if (model.rels) { | ||
var pageSetup = Object.assign(sheetProperties, this.map.pageSetup.model, this.map.printOptions.model); | ||
var conditionalFormattings = mergeConditionalFormattings(this.map.conditionalFormatting.model, this.map.extLst.model && this.map.extLst.model['x14:conditionalFormattings']); | ||
this.model = { | ||
@@ -413,3 +479,3 @@ dimensions: this.map.dimension.model, | ||
tables: this.map.tableParts.model, | ||
conditionalFormattings: this.map.conditionalFormatting.model | ||
conditionalFormattings: conditionalFormattings | ||
}; | ||
@@ -416,0 +482,0 @@ |
@@ -439,3 +439,3 @@ declare interface Buffer extends ArrayBuffer { } | ||
*/ | ||
comment: Comment; | ||
note: Comment; | ||
@@ -442,0 +442,0 @@ /** |
@@ -309,3 +309,2 @@ /* eslint-disable max-classes-per-file */ | ||
/* eslint-disable no-unused-vars */ | ||
addRow(values, rowNumber) { | ||
@@ -312,0 +311,0 @@ // Add a row of data, either insert at rowNumber or append |
@@ -22,15 +22,15 @@ const Sax = require('sax'); | ||
parseOpen(/* node */) { | ||
// Sax Open Node event | ||
parseOpen(node) { | ||
// XML node opened | ||
} | ||
parseText(/* node */) { | ||
// Sax Text event | ||
parseText(text) { | ||
// chunk of text encountered for current node | ||
} | ||
parseClose(/* name */) { | ||
// Sax Close Node event | ||
parseClose(name) { | ||
// XML node closed | ||
} | ||
reconcile(/* model, options */) { | ||
reconcile(model, options) { | ||
// optional post-parse step (opposite to prepare) | ||
@@ -73,2 +73,3 @@ } | ||
try { | ||
// console.log('opentag', node.name); | ||
this.parseOpen(node); | ||
@@ -88,2 +89,3 @@ } catch (error) { | ||
try { | ||
// console.log('closetag', name); | ||
if (!this.parseClose(name)) { | ||
@@ -97,2 +99,3 @@ resolve(this.model); | ||
parser.on('end', () => { | ||
// console.log('end'); | ||
resolve(this.model); | ||
@@ -128,4 +131,8 @@ }); | ||
// Useful Utilities | ||
static toAttribute(value, dflt) { | ||
if ((value !== undefined) && (value !== dflt)) { | ||
static toAttribute(value, dflt, allways = false) { | ||
if (value === undefined) { | ||
if (allways) { | ||
return dflt; | ||
} | ||
} else if (allways || (value !== dflt)) { | ||
return value.toString(); | ||
@@ -137,7 +144,4 @@ } | ||
static toStringAttribute(value, dflt) { | ||
if (value !== dflt) { | ||
return value; | ||
} | ||
return undefined; | ||
static toStringAttribute(value, dflt, allways = false) { | ||
return BaseXform.toAttribute(value, dflt, allways); | ||
} | ||
@@ -149,4 +153,8 @@ | ||
static toBoolAttribute(value, dflt) { | ||
if ((value !== undefined) && (value !== dflt)) { | ||
static toBoolAttribute(value, dflt, allways = false) { | ||
if (value === undefined) { | ||
if (allways) { | ||
return dflt; | ||
} | ||
} else if (allways || (value !== dflt)) { | ||
return value ? '1' : '0'; | ||
@@ -161,4 +169,4 @@ } | ||
static toIntAttribute(value, dflt) { | ||
return BaseXform.toAttribute(value, dflt); | ||
static toIntAttribute(value, dflt, allways = false) { | ||
return BaseXform.toAttribute(value, dflt, allways); | ||
} | ||
@@ -170,4 +178,4 @@ | ||
static toFloatAttribute(value, dflt) { | ||
return BaseXform.toAttribute(value, dflt); | ||
static toFloatAttribute(value, dflt, allways = false) { | ||
return BaseXform.toAttribute(value, dflt, allways); | ||
} | ||
@@ -174,0 +182,0 @@ |
@@ -37,10 +37,13 @@ const _ = require('../../../utils/under-dash'); | ||
if (sheet.pageSetup && sheet.pageSetup.printArea) { | ||
const printArea = sheet.pageSetup.printArea.split(':'); | ||
const definedName = { | ||
name: '_xlnm.Print_Area', | ||
ranges: [`'${sheet.name}'!$${printArea[0]}:$${printArea[1]}`], | ||
localSheetId: index, | ||
}; | ||
printAreas.push(definedName); | ||
} | ||
sheet.pageSetup.printArea.split('&&').forEach(printArea => { | ||
const printAreaComponents = printArea.split(':'); | ||
const definedName = { | ||
name: '_xlnm.Print_Area', | ||
ranges: [`'${sheet.name}'!$${printAreaComponents[0]}:$${printAreaComponents[1]}`], | ||
localSheetId: index, | ||
}; | ||
printAreas.push(definedName); | ||
}); | ||
} | ||
if (sheet.pageSetup && (sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)) { | ||
@@ -183,3 +186,5 @@ const ranges = []; | ||
const range = colCache.decodeEx(definedName.ranges[0]); | ||
worksheet.pageSetup.printArea = range.dimensions; | ||
worksheet.pageSetup.printArea = worksheet.pageSetup.printArea ? | ||
`${worksheet.pageSetup.printArea}&&${range.dimensions}` : | ||
range.dimensions; | ||
} | ||
@@ -186,0 +191,0 @@ } else if (definedName.name === '_xlnm.Print_Titles') { |
const BaseXform = require('./base-xform'); | ||
/* 'virtual' methods used as a form of documentation */ | ||
/* eslint-disable class-methods-use-this */ | ||
// base class for xforms that are composed of other xforms | ||
// offers some default implementations | ||
class CompositeXform extends BaseXform { | ||
constructor(options) { | ||
super(); | ||
this.tag = options.tag; | ||
this.attrs = options.attrs; | ||
this.children = options.children; | ||
this.map = this.children.reduce((map, child) => { | ||
const name = child.name || child.tag; | ||
const tag = child.tag || child.name; | ||
map[tag] = child; | ||
child.name = name; | ||
child.tag = tag; | ||
return map; | ||
}, {}); | ||
createNewModel(node) { | ||
return {}; | ||
} | ||
prepare(model, options) { | ||
this.children.forEach(child => { | ||
child.xform.prepare(model[child.tag], options); | ||
}); | ||
} | ||
render(xmlStream, model) { | ||
xmlStream.openNode(this.tag, this.attrs); | ||
this.children.forEach(child => { | ||
child.xform.render(xmlStream, model[child.name]); | ||
}); | ||
xmlStream.closeNode(); | ||
} | ||
parseOpen(node) { | ||
// Typical pattern for composite xform | ||
this.parser = this.parser || this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.xform.parseOpen(node); | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = {}; | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.xform.parseOpen(node); | ||
return true; | ||
} | ||
if (node.name === this.tag) { | ||
this.model = this.createNewModel(node); | ||
return true; | ||
} | ||
return false; | ||
@@ -54,11 +30,19 @@ } | ||
parseText(text) { | ||
// Default implementation. Send text to child parser | ||
if (this.parser) { | ||
this.parser.xform.parseText(text); | ||
this.parser.parseText(text); | ||
} | ||
} | ||
onParserClose(name, parser) { | ||
// parseClose has seen a child parser close | ||
// now need to incorporate into this.model somehow | ||
this.model[name] = parser.model; | ||
} | ||
parseClose(name) { | ||
// Default implementation | ||
if (this.parser) { | ||
if (!this.parser.xform.parseClose(name)) { | ||
this.model[this.parser.name] = this.parser.xform.model; | ||
if (!this.parser.parseClose(name)) { | ||
this.onParserClose(name, this.parser); | ||
this.parser = undefined; | ||
@@ -68,9 +52,4 @@ } | ||
} | ||
return false; | ||
} | ||
reconcile(model, options) { | ||
this.children.forEach(child => { | ||
child.xform.prepare(model[child.tag], options); | ||
}); | ||
return (name !== this.tag); | ||
} | ||
@@ -77,0 +56,0 @@ } |
@@ -1,3 +0,4 @@ | ||
const uuid = require('uuid'); | ||
const BaseXform = require('../../base-xform'); | ||
const CompositeXform = require('../../composite-xform'); | ||
const Range = require('../../../../doc/range'); | ||
@@ -73,4 +74,4 @@ | ||
const opType = attr => { | ||
const {type, operator} = attr; | ||
const opType = attributes => { | ||
const {type, operator} = attributes; | ||
switch (type) { | ||
@@ -92,3 +93,3 @@ case 'containsText': | ||
class CfRuleXform extends BaseXform { | ||
class CfRuleXform extends CompositeXform { | ||
constructor() { | ||
@@ -99,3 +100,3 @@ super(); | ||
dataBar: this.databarXform = new DatabarXform(), | ||
extLst: this.extLstXform = new ExtLstRefXform(), | ||
extLst: this.extLstRefXform = new ExtLstRefXform(), | ||
formula: this.formulaXform = new FormulaXform(), | ||
@@ -186,5 +187,5 @@ colorScale: this.colorScaleXform = new ColorScaleXform(), | ||
priority: model.priority, | ||
percent: model.percent ? '1' : undefined, | ||
bottom: model.bottom ? '1' : undefined, | ||
rank: model.rank || 10, | ||
percent: BaseXform.toBoolAttribute(model.percent, false), | ||
bottom: BaseXform.toBoolAttribute(model.bottom, false), | ||
rank: BaseXform.toIntValue(model.rank, 10, true), | ||
}); | ||
@@ -198,3 +199,3 @@ } | ||
priority: model.priority, | ||
aboveAverage: (model.aboveAverage === false) ? '0' : undefined, | ||
aboveAverage: BaseXform.toBoolAttribute(model.aboveAverage, true), | ||
}); | ||
@@ -210,6 +211,4 @@ } | ||
this.databarXform.render(xmlStream, model); | ||
this.extLstRefXform.render(xmlStream, model); | ||
model.x14Id = `{${uuid.v4()}}`; | ||
this.extLstXform.render(xmlStream, model); | ||
xmlStream.closeNode(); | ||
@@ -250,3 +249,3 @@ } | ||
priority: model.priority, | ||
operator: model.operator === 'containsText' ? model.operator : undefined, | ||
operator: BaseXform.toStringAttribute(model.operator, 'containsText'), | ||
}); | ||
@@ -278,62 +277,31 @@ | ||
parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
...opType(node.attributes), | ||
dxfId: BaseXform.toIntValue(node.attributes.dxfId), | ||
priority: BaseXform.toIntValue(node.attributes.priority), | ||
timePeriod: node.attributes.timePeriod, | ||
percent: BaseXform.toBoolValue(node.attributes.percent), | ||
bottom: BaseXform.toBoolValue(node.attributes.bottom), | ||
rank: BaseXform.toIntValue(node.attributes.rank), | ||
aboveAverage: BaseXform.toBoolValue(node.attributes.aboveAverage), | ||
}; | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
createNewModel({attributes}) { | ||
return { | ||
...opType(attributes), | ||
dxfId: BaseXform.toIntValue(attributes.dxfId), | ||
priority: BaseXform.toIntValue(attributes.priority), | ||
timePeriod: attributes.timePeriod, | ||
percent: BaseXform.toBoolValue(attributes.percent), | ||
bottom: BaseXform.toBoolValue(attributes.bottom), | ||
rank: BaseXform.toIntValue(attributes.rank), | ||
aboveAverage: BaseXform.toBoolValue(attributes.aboveAverage), | ||
}; | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
} | ||
onParserClose(name, parser) { | ||
switch(name) { | ||
case 'dataBar': | ||
case 'extLst': | ||
case 'colorScale': | ||
case 'iconSet': | ||
// merge parser model with ours | ||
Object.assign(this.model, parser.model); | ||
break; | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
switch(name) { | ||
case 'dataBar': | ||
case 'extLst': | ||
case 'colorScale': | ||
case 'iconSet': | ||
// merge parser model with ours | ||
Object.assign(this.model, this.parser.model); | ||
break; | ||
case 'formula': | ||
// except - formula is a string and appends to formulae | ||
this.model.formulae = this.model.formulae || []; | ||
this.model.formulae.push(this.parser.model); | ||
break; | ||
} | ||
this.parser = null; | ||
} | ||
return true; | ||
case 'formula': | ||
// except - formula is a string and appends to formulae | ||
this.model.formulae = this.model.formulae || []; | ||
this.model.formulae.push(parser.model); | ||
break; | ||
} | ||
return name !== this.tag; | ||
} | ||
@@ -340,0 +308,0 @@ } |
@@ -1,2 +0,2 @@ | ||
const BaseXform = require('../../base-xform'); | ||
const CompositeXform = require('../../composite-xform'); | ||
@@ -6,3 +6,3 @@ const ColorXform = require('../../style/color-xform'); | ||
class ColorScaleXform extends BaseXform { | ||
class ColorScaleXform extends CompositeXform { | ||
constructor() { | ||
@@ -34,44 +34,14 @@ super(); | ||
parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
cfvo: [], | ||
color: [], | ||
}; | ||
break; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
createNewModel(node) { | ||
return { | ||
cfvo: [], | ||
color: [], | ||
}; | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
onParserClose(name, parser) { | ||
this.model[name].push(parser.model); | ||
} | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model[name].push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
} | ||
module.exports = ColorScaleXform; |
@@ -1,6 +0,6 @@ | ||
const BaseXform = require('../../base-xform'); | ||
const CompositeXform = require('../../composite-xform'); | ||
const CfRuleXform = require('./cf-rule-xform'); | ||
class ConditionalFormattingXform extends BaseXform { | ||
class ConditionalFormattingXform extends CompositeXform { | ||
constructor() { | ||
@@ -36,38 +36,14 @@ super(); | ||
parseOpen(node) { | ||
this.parser = this.parser || this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
if (node.name === this.tag) { | ||
this.model = { | ||
ref: node.attributes.sqref, | ||
rules: [], | ||
}; | ||
return true; | ||
} | ||
return false; | ||
createNewModel({attributes}) { | ||
return { | ||
ref: attributes.sqref, | ||
rules: [], | ||
}; | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
onParserClose(name, parser) { | ||
this.model.rules.push(parser.model); | ||
} | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model.rules.push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
} | ||
module.exports = ConditionalFormattingXform; |
@@ -10,7 +10,2 @@ const BaseXform = require('../../base-xform'); | ||
this.cfXform = new ConditionalFormattingXform(); | ||
// thanks to Excel, conditionalFormatting nodes are directly inside | ||
// <worksheet>, not inside some <conditionalFormattings> node so | ||
// we create initial model here | ||
this.reset(); | ||
} | ||
@@ -17,0 +12,0 @@ |
@@ -1,2 +0,2 @@ | ||
const BaseXform = require('../../base-xform'); | ||
const CompositeXform = require('../../composite-xform'); | ||
@@ -6,3 +6,3 @@ const ColorXform = require('../../style/color-xform'); | ||
class DatabarXform extends BaseXform { | ||
class DatabarXform extends CompositeXform { | ||
constructor() { | ||
@@ -27,5 +27,3 @@ super(); | ||
}); | ||
model.color.forEach(color => { | ||
this.colorXform.render(xmlStream, color); | ||
}); | ||
this.colorXform.render(xmlStream, model.color); | ||
@@ -35,44 +33,20 @@ xmlStream.closeNode(); | ||
parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
createNewModel() { | ||
return { | ||
cfvo: [], | ||
}; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
cfvo: [], | ||
color: [], | ||
}; | ||
onParserClose(name, parser) { | ||
switch (name) { | ||
case 'cfvo': | ||
this.model.cfvo.push(parser.model); | ||
break; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
case 'color': | ||
this.model.color = parser.model; | ||
break; | ||
} | ||
return false; | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
} | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model[name].push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
} | ||
module.exports = DatabarXform; |
/* eslint-disable max-classes-per-file */ | ||
const BaseXform = require('../../base-xform'); | ||
const CompositeXform = require('../../composite-xform'); | ||
@@ -26,3 +27,3 @@ class X14IdXform extends BaseXform { | ||
class ExtXform extends BaseXform { | ||
class ExtXform extends CompositeXform { | ||
constructor() { | ||
@@ -32,3 +33,3 @@ super(); | ||
this.map = { | ||
'x14:id': new X14IdXform(), | ||
'x14:id': this.idXform = new X14IdXform(), | ||
}; | ||
@@ -47,3 +48,3 @@ } | ||
this.map['x14:id'].render(model.x14Id); | ||
this.idXform.render(xmlStream, model.x14Id); | ||
@@ -53,41 +54,12 @@ xmlStream.closeNode(); | ||
parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = {}; | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
} | ||
return true; | ||
} | ||
createNewModel() { | ||
return {}; | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
onParserClose(name, parser) { | ||
this.model.x14Id = parser.model; | ||
} | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.parser = undefined; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
} | ||
class ExtLstRefXform extends BaseXform { | ||
class ExtLstRefXform extends CompositeXform { | ||
constructor() { | ||
@@ -110,11 +82,8 @@ super(); | ||
parseOpen(node) { | ||
this.model = { | ||
type: node.attributes.type, | ||
value: node.attributes.val, | ||
}; | ||
createNewModel() { | ||
return {}; | ||
} | ||
parseClose(name) { | ||
return name !== this.tag; | ||
onParserClose(name, parser) { | ||
Object.assign(this.model, parser.model); | ||
} | ||
@@ -121,0 +90,0 @@ } |
const BaseXform = require('../../base-xform'); | ||
const CompositeXform = require('../../composite-xform'); | ||
const CfvoXform = require('./cfvo-xform'); | ||
class IconSetXform extends BaseXform { | ||
class IconSetXform extends CompositeXform { | ||
constructor() { | ||
@@ -32,46 +33,16 @@ super(); | ||
parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
switch (node.name) { | ||
case this.tag: | ||
this.model = { | ||
iconSet: BaseXform.toStringValue(node.attributes.iconSet, '3TrafficLights'), | ||
reverse: BaseXform.toBoolValue(node.attributes.reverse), | ||
showValue: BaseXform.toBoolValue(node.attributes.showValue), | ||
cfvo: [], | ||
}; | ||
break; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
} | ||
return false; | ||
createNewModel({attributes}) { | ||
return { | ||
iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'), | ||
reverse: BaseXform.toBoolValue(attributes.reverse), | ||
showValue: BaseXform.toBoolValue(attributes.showValue), | ||
cfvo: [], | ||
}; | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
onParserClose(name, parser) { | ||
this.model[name].push(parser.model); | ||
} | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.model[name].push(this.parser.model); | ||
this.parser = null; | ||
} | ||
return true; | ||
} | ||
return name !== this.tag; | ||
} | ||
} | ||
module.exports = IconSetXform; |
@@ -1,10 +0,11 @@ | ||
const BaseXform = require('../base-xform'); | ||
/* eslint-disable max-classes-per-file */ | ||
const CompositeXform = require('../composite-xform'); | ||
const ConditionalFormattingsExt = require('./cf/conditional-formattings-ext-xform'); | ||
const ConditionalFormattingsExt = require('./cf-ext/conditional-formattings-ext-xform'); | ||
class ExtLstXform extends BaseXform { | ||
class ExtXform extends CompositeXform { | ||
constructor() { | ||
super(); | ||
this.map = { | ||
'x14:conditionalFormattings': new ConditionalFormattingsExt(), | ||
'x14:conditionalFormattings': this.conditionalFormattings = new ConditionalFormattingsExt(), | ||
}; | ||
@@ -14,11 +15,14 @@ } | ||
get tag() { | ||
return 'extLst'; | ||
return 'ext'; | ||
} | ||
hasContent(model) { | ||
return this.conditionalFormattings.hasContent(model.conditionalFormattings); | ||
} | ||
prepare(model, options) { | ||
this.conditionalFormattings.prepare(model.conditionalFormattings, options); | ||
} | ||
render(xmlStream, model) { | ||
let hasContent = false; | ||
xmlStream.addRollback(); | ||
xmlStream.openNode('extLst'); | ||
// conditional formatting | ||
xmlStream.openNode('ext', { | ||
@@ -28,54 +32,57 @@ uri: '{78C0D931-6437-407d-A8EE-F0AAD7539E65}', | ||
}); | ||
const cfCursor = xmlStream.cursor; | ||
this.map['x14:conditionalFormattings'].render(model.conditionalFormattings); | ||
hasContent = hasContent || (cfCursor !== xmlStream.cursor); | ||
xmlStream.closeNode(); | ||
this.conditionalFormattings.render(xmlStream, model.conditionalFormattings); | ||
xmlStream.closeNode(); | ||
if (hasContent) { | ||
xmlStream.commit(); | ||
} else { | ||
xmlStream.rollback(); | ||
} | ||
} | ||
parseOpen(node) { | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
return true; | ||
} | ||
createNewModel() { | ||
return {}; | ||
} | ||
switch (node.name) { | ||
case 'extLst': | ||
this.model = {}; | ||
return true; | ||
case 'ext': | ||
return true; | ||
default: | ||
this.parser = this.map[node.name]; | ||
if (this.parser) { | ||
this.parser.parseOpen(node); | ||
} | ||
return true; | ||
} | ||
onParserClose(name, parser) { | ||
this.model[name] = parser.model; | ||
} | ||
} | ||
parseText(text) { | ||
if (this.parser) { | ||
this.parser.parseText(text); | ||
} | ||
class ExtLstXform extends CompositeXform { | ||
constructor() { | ||
super(); | ||
this.map = { | ||
'ext': this.ext = new ExtXform(), | ||
}; | ||
} | ||
parseClose(name) { | ||
if (this.parser) { | ||
if (!this.parser.parseClose(name)) { | ||
this.parser = undefined; | ||
} | ||
return true; | ||
get tag() { | ||
return 'extLst'; | ||
} | ||
prepare(model, options) { | ||
this.ext.prepare(model, options); | ||
} | ||
hasContent(model) { | ||
return this.ext.hasContent(model); | ||
} | ||
render(xmlStream, model) { | ||
if (!this.hasContent(model)) { | ||
return; | ||
} | ||
return (name !== 'extList'); | ||
xmlStream.openNode('extLst'); | ||
this.ext.render(xmlStream, model); | ||
xmlStream.closeNode(); | ||
} | ||
createNewModel() { | ||
return {}; | ||
} | ||
onParserClose(name, parser) { | ||
Object.assign(this.model, parser.model); | ||
} | ||
} | ||
module.exports = ExtLstXform; |
@@ -32,3 +32,61 @@ const _ = require('../../../utils/under-dash'); | ||
const ConditionalFormattingsXform = require('./cf/conditional-formattings-xform'); | ||
const ExtListXform = require('./ext-lst-xform'); | ||
const mergeRule = (rule, extRule) => { | ||
Object.keys(extRule).forEach(key => { | ||
const value = rule[key]; | ||
const extValue = extRule[key]; | ||
if ((value === undefined) && (extValue !== undefined)) { | ||
rule[key] = extValue; | ||
} | ||
}); | ||
}; | ||
const mergeConditionalFormattings = (model, extModel) => { | ||
// conditional formattings are rendered in worksheet.conditionalFormatting and also in | ||
// worksheet.extLst.ext.x14:conditionalFormattings | ||
// some (e.g. dataBar) are even spread across both! | ||
if (!extModel || !extModel.length) { | ||
return model; | ||
} | ||
if (!model || !model.length) { | ||
return extModel; | ||
} | ||
// index model rules by x14Id | ||
const cfMap = {}; | ||
const ruleMap = {}; | ||
model.forEach(cf => { | ||
cfMap[cf.ref] = cf; | ||
cf.rules.forEach(rule => { | ||
const {x14Id} = rule; | ||
if (x14Id) { | ||
ruleMap[x14Id] = rule; | ||
} | ||
}); | ||
}); | ||
extModel.forEach(extCf => { | ||
extCf.rules.forEach(extRule => { | ||
const rule = ruleMap[extRule.x14Id]; | ||
if (rule) { | ||
// merge with matching rule | ||
mergeRule(rule, extRule); | ||
} else if (cfMap[extCf.ref]) { | ||
// reuse existing cf ref | ||
cfMap[extCf.ref].rules.push(extRule); | ||
} else { | ||
// create new cf | ||
model.push({ | ||
ref: extCf.ref, | ||
rules: [extRule], | ||
}); | ||
} | ||
}); | ||
}); | ||
// need to cope with rules in extModel that don't exist in model | ||
return model; | ||
}; | ||
class WorkSheetXform extends BaseXform { | ||
@@ -66,2 +124,3 @@ constructor(options) { | ||
conditionalFormatting: new ConditionalFormattingsXform(), | ||
extLst: new ExtListXform(), | ||
}; | ||
@@ -196,2 +255,5 @@ } | ||
}); | ||
// prepare ext items | ||
this.map.extLst.prepare(model, options); | ||
} | ||
@@ -254,2 +316,4 @@ | ||
this.map.extLst.render(xmlStream, model); | ||
if (model.rels) { | ||
@@ -314,2 +378,6 @@ // add a <legacyDrawing /> node for each comment | ||
const pageSetup = Object.assign(sheetProperties, this.map.pageSetup.model, this.map.printOptions.model); | ||
const conditionalFormattings = mergeConditionalFormattings( | ||
this.map.conditionalFormatting.model, | ||
this.map.extLst.model && this.map.extLst.model['x14:conditionalFormattings'] | ||
); | ||
this.model = { | ||
@@ -329,3 +397,3 @@ dimensions: this.map.dimension.model, | ||
tables: this.map.tableParts.model, | ||
conditionalFormattings: this.map.conditionalFormatting.model, | ||
conditionalFormattings, | ||
}; | ||
@@ -332,0 +400,0 @@ |
{ | ||
"name": "exceljs", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "Excel Workbook Manager - Read and Write xlsx and csv Files.", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9598598
470
179340
2592