Skip to content

Commit bf2bbb9

Browse files
committed
0.1.2 - Fixed/added some type definitions
1 parent c0d76eb commit bf2bbb9

File tree

10 files changed

+58
-35
lines changed

10 files changed

+58
-35
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
### [0.1.1](N/A) - 2016-05-31
7+
### [0.1.2](N/A) - 2016-06-01
8+
#### Changed
9+
* Corrected/added some type definitions
10+
11+
12+
--------
13+
### [0.1.1](https://github.com/TeamworkGuy2/excel-builder-ts/commit/c0d76ebed850b73aeb7eed4c52830f27e1df7bae) - 2016-05-31
814
#### Changed
915
* Switched all applicable strings from single to double quotes
1016
* Added some missing and best guess data types

Drawings.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ var Drawings = (function () {
2626
var drawingsElem = doc.documentElement;
2727
//drawings.setAttribute('xmlns:xdr', util.schemas.spreadsheetDrawing);
2828
drawingsElem.setAttribute("xmlns:a", Util.schemas.drawing);
29-
var existingRelationships = {};
3029
for (var i = 0, l = this.drawings.length; i < l; i++) {
31-
var rId = this.relations.getRelationshipId(this.drawings[i].getMediaData());
30+
var drwI = this.drawings[i];
31+
var rId = this.relations.getRelationshipId(drwI.getMediaData());
3232
if (!rId) {
33-
rId = this.relations.addRelation(this.drawings[i].getMediaData(), this.drawings[i].getMediaType()); //chart
33+
rId = this.relations.addRelation(drwI.getMediaData(), drwI.getMediaType()); //chart
3434
}
35-
this.drawings[i].setRelationshipId(rId);
36-
drawingsElem.appendChild(this.drawings[i].toXML(doc));
35+
drwI.setRelationshipId(rId);
36+
drawingsElem.appendChild(drwI.toXML(doc));
3737
}
3838
return doc;
3939
};

Drawings.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ class Drawings {
3939
//drawings.setAttribute('xmlns:xdr', util.schemas.spreadsheetDrawing);
4040
drawingsElem.setAttribute("xmlns:a", Util.schemas.drawing);
4141

42-
var existingRelationships = {};
43-
4442
for (var i = 0, l = this.drawings.length; i < l; i++) {
45-
46-
var rId = this.relations.getRelationshipId(this.drawings[i].getMediaData());
43+
var drwI = this.drawings[i];
44+
var rId = this.relations.getRelationshipId(drwI.getMediaData());
4745
if (!rId) {
48-
rId = this.relations.addRelation(this.drawings[i].getMediaData(), this.drawings[i].getMediaType()); //chart
46+
rId = this.relations.addRelation(drwI.getMediaData(), drwI.getMediaType()); //chart
4947
}
50-
this.drawings[i].setRelationshipId(rId);
51-
drawingsElem.appendChild(this.drawings[i].toXML(doc));
48+
drwI.setRelationshipId(rId);
49+
drawingsElem.appendChild(drwI.toXML(doc));
5250
}
5351
return doc;
5452
}
@@ -58,10 +56,10 @@ class Drawings {
5856
module Drawings {
5957

6058
export interface Drawing {
61-
getMediaData();
62-
getMediaType();
59+
getMediaData(): { id: string; schema?: string; };
60+
getMediaType(): string;
6361
setRelationshipId(rId: string): void;
64-
toXML(doc: XmlDom);
62+
toXML(doc: XmlDom): XmlDom.NodeBase;
6563
}
6664

6765
}

XmlDom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ module XmlDom {
4141

4242

4343
export interface NodeConfig {
44-
type: "XML" | "TEXT";
4544
nodeValue?: string;
45+
type: "XML" | "TEXT";
4646
}
4747

4848

4949
export interface NodeBase {
5050
nodeValue?: string;
51-
toJSON(): NodeConfig;
51+
toJSON?(): NodeConfig;
5252
}
5353

5454

drawings/AbsoluteAnchor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Util = require("../Util");
2+
import XmlDom = require("../XmlDom");
23

34
class AbsoluteAnchor {
45
x: number;
@@ -49,7 +50,7 @@ class AbsoluteAnchor {
4950
}
5051

5152

52-
public toXML(xmlDoc: XMLDocument, content: Node) {
53+
public toXML(xmlDoc: XmlDom, content: XmlDom.NodeBase) {
5354
var root = Util.createElement(xmlDoc, "xdr:absoluteAnchor");
5455
var pos = Util.createElement(xmlDoc, "xdr:pos");
5556
pos.setAttribute("x", <any>this.x);

drawings/Drawing.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import Util = require("../Util");
2+
import XmlDom = require("../XmlDom");
3+
import Drawings = require("../Drawings");
24
import AbsoluteAnchor = require("./AbsoluteAnchor");
35
import OneCellAnchor = require("./OneCellAnchor");
46
import TwoCellAnchor = require("./TwoCellAnchor");
57

6-
7-
type AnchorLike = AbsoluteAnchor | OneCellAnchor | TwoCellAnchor;
8-
9-
108
/** This is mostly a global spot where all of the relationship managers can get and set
119
* path information from/to.
1210
* @module Excel/Drawing
1311
*/
14-
class Drawing {
15-
anchor: AnchorLike;
12+
abstract class Drawing implements Drawings.Drawing {
13+
anchor: Drawing.AnchorLike;
1614
id: string;
1715

1816

@@ -46,6 +44,21 @@ class Drawing {
4644
return this.anchor;
4745
}
4846

47+
48+
public abstract setRelationshipId(rId: string): void;
49+
50+
public abstract toXML(xmlDoc: XmlDom): XmlDom.NodeBase;
51+
52+
public abstract getMediaData(): { id: string; schema?: string; };
53+
54+
public abstract getMediaType(): string;
55+
56+
}
57+
58+
module Drawing {
59+
60+
export type AnchorLike = AbsoluteAnchor | OneCellAnchor | TwoCellAnchor;
61+
4962
}
5063

5164
export = Drawing;

drawings/OneCellAnchor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Util = require("../Util");
2+
import XmlDom = require("../XmlDom");
23

34
class OneCellAnchor {
45
x: number;
@@ -49,7 +50,7 @@ class OneCellAnchor {
4950
}
5051

5152

52-
public toXML(xmlDoc: XMLDocument, content: Node) {
53+
public toXML(xmlDoc: XmlDom, content: XmlDom.NodeBase) {
5354
var root = Util.createElement(xmlDoc, "xdr:oneCellAnchor");
5455
var from = Util.createElement(xmlDoc, "xdr:from");
5556
var fromCol = Util.createElement(xmlDoc, "xdr:col");

drawings/Picture.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import Util = require("../Util");
2+
import XmlDom = require("../XmlDom");
23
import Drawing = require("./Drawing");
4+
import Drawings = require("../Drawings");
35

46
class Picture {
57
static Cctor = (function () {
68
var thisProto = Picture.prototype;
7-
Picture.prototype = <any>new Drawing();
9+
Picture.prototype = new (<any>Drawing)();
810
Object.assign(Picture.prototype, thisProto);
911
} ());
1012

11-
anchor: any;
13+
anchor: Drawing.AnchorLike;
1214
description: string;
1315
fill: any;
1416
id: string;
1517
media: any;
16-
mediaData: { rId: string; fileName: string; };
18+
mediaData: { rId?: string; id: string; fileName: string; };
1719
pictureId: number;
1820

1921

@@ -26,7 +28,7 @@ class Picture {
2628
}
2729

2830

29-
public setMedia(mediaRef: { rId: string; fileName: string; [id: string]: any }) {
31+
public setMedia(mediaRef: { rId?: string; id: string; fileName: string; [id: string]: any }) {
3032
this.mediaData = mediaRef;
3133
}
3234

@@ -51,7 +53,7 @@ class Picture {
5153
}
5254

5355

54-
public getMediaData() {
56+
public getMediaData(): { id: string; schema?: string; } {
5557
return this.mediaData;
5658
}
5759

@@ -61,7 +63,7 @@ class Picture {
6163
}
6264

6365

64-
public toXML(xmlDoc: XMLDocument) {
66+
public toXML(xmlDoc: XmlDom): XmlDom.NodeBase {
6567
var pictureNode = Util.createElement(xmlDoc, "xdr:pic");
6668

6769
var nonVisibleProperties = Util.createElement(xmlDoc, "xdr:nvPicPr");
@@ -128,4 +130,5 @@ class Picture {
128130

129131
}
130132

131-
export = <{ new (): Picture & Drawing }><any>Picture;
133+
interface PictureDrawing extends Picture, Drawing, Drawings.Drawing { }
134+
export = <{ new (): PictureDrawing }><any>Picture;

drawings/TwoCellAnchor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Util = require("../Util");
2+
import XmlDom = require("../XmlDom");
23

34
class TwoCellAnchor {
45
from: Util.OffsetConfig;
@@ -39,7 +40,7 @@ class TwoCellAnchor {
3940
}
4041

4142

42-
public toXML(xmlDoc: XMLDocument, content: Node) {
43+
public toXML(xmlDoc: XmlDom, content: XmlDom.NodeBase) {
4344
var root = Util.createElement(xmlDoc, "xdr:twoCellAnchor");
4445

4546
var from = Util.createElement(xmlDoc, "xdr:from");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "excel-builder-ts",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "TypeScript Port of the excel-builder.js Library - 'A way to build excel files with javascript'",
55
"dependencies": {
66
},

0 commit comments

Comments
 (0)