@microsoft/connected-workbooks 3.1.2-beta.2 → 3.2.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/main.js +357 -106
- package/dist/src/generators.js +7 -6
- package/dist/src/types.d.ts +1 -0
- package/dist/src/utils/arrayUtils.js +26 -21
- package/dist/src/utils/constants.js +20 -8
- package/dist/src/utils/documentUtils.js +92 -42
- package/dist/src/utils/gridUtils.js +23 -23
- package/dist/src/utils/htmlUtils.js +8 -8
- package/dist/src/utils/mashupDocumentParser.js +110 -67
- package/dist/src/utils/pqUtils.js +158 -65
- package/dist/src/utils/tableUtils.js +118 -74
- package/dist/src/utils/xmlInnerPartsUtils.js +213 -152
- package/dist/src/utils/xmlPartsUtils.js +116 -50
- package/dist/tests/arrayUtils.test.js +21 -21
- package/dist/tests/documentUtils.test.js +37 -8
- package/dist/tests/gridUtils.test.js +9 -9
- package/dist/tests/htmlUtils.test.js +48 -47
- package/dist/tests/mashupDocumentParser.test.js +91 -38
- package/dist/tests/mocks/PqMock.js +1 -1
- package/dist/tests/mocks/section1mSimpleQueryMock.js +5 -15
- package/dist/tests/mocks/xmlMocks.js +2 -2
- package/dist/tests/tableUtils.test.js +18 -18
- package/dist/tests/workbookQueryTemplate.test.js +127 -45
- package/dist/tests/workbookTableTemplate.test.js +104 -33
- package/dist/tests/xmlInnerPartsUtils.test.js +118 -37
- package/dist/utils/constants.js +3 -1
- package/dist/utils/pqUtils.js +63 -45
- package/dist/workbookManager.d.ts +1 -0
- package/dist/workbookManager.js +31 -9
- package/package.json +1 -1
package/dist/src/generators.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.generateCustomXmlFilePath = exports.generateSingleQueryMashup = exports.generateMashupXMLTemplate = void 0;
|
|
6
|
-
|
|
6
|
+
var generateMashupXMLTemplate = function (base64) {
|
|
7
|
+
return "<?xml version=\"1.0\" encoding=\"utf-16\"?><DataMashup xmlns=\"http://schemas.microsoft.com/DataMashup\">".concat(base64, "</DataMashup>");
|
|
8
|
+
};
|
|
7
9
|
exports.generateMashupXMLTemplate = generateMashupXMLTemplate;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
${query};`;
|
|
10
|
+
var generateSingleQueryMashup = function (queryName, query) {
|
|
11
|
+
return "section Section1;\n \n shared #\"".concat(queryName, "\" = \n ").concat(query, ";");
|
|
12
|
+
};
|
|
12
13
|
exports.generateSingleQueryMashup = generateSingleQueryMashup;
|
|
13
|
-
|
|
14
|
+
var generateCustomXmlFilePath = function (i) { return "customXml/item".concat(i, ".xml"); };
|
|
14
15
|
exports.generateCustomXmlFilePath = generateCustomXmlFilePath;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -3,44 +3,49 @@
|
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.ArrayReader = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
var ArrayReader = /** @class */ (function () {
|
|
7
|
+
function ArrayReader(array) {
|
|
8
8
|
this._array = array;
|
|
9
9
|
this._position = 0;
|
|
10
10
|
}
|
|
11
|
-
getInt32() {
|
|
12
|
-
|
|
11
|
+
ArrayReader.prototype.getInt32 = function () {
|
|
12
|
+
var retVal = new DataView(this._array, this._position, 4).getInt32(0, true);
|
|
13
13
|
this._position += 4;
|
|
14
14
|
return retVal;
|
|
15
|
-
}
|
|
16
|
-
getBytes(bytes) {
|
|
17
|
-
|
|
15
|
+
};
|
|
16
|
+
ArrayReader.prototype.getBytes = function (bytes) {
|
|
17
|
+
var retVal = this._array.slice(this._position, bytes ? bytes + this._position : bytes);
|
|
18
18
|
this._position += retVal.byteLength;
|
|
19
19
|
return new Uint8Array(retVal);
|
|
20
|
-
}
|
|
21
|
-
reset() {
|
|
20
|
+
};
|
|
21
|
+
ArrayReader.prototype.reset = function () {
|
|
22
22
|
this._position = 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
23
|
+
};
|
|
24
|
+
return ArrayReader;
|
|
25
|
+
}());
|
|
25
26
|
exports.ArrayReader = ArrayReader;
|
|
26
27
|
function getInt32Buffer(val) {
|
|
27
|
-
|
|
28
|
+
var packageSizeBuffer = new ArrayBuffer(4);
|
|
28
29
|
new DataView(packageSizeBuffer).setInt32(0, val, true);
|
|
29
30
|
return new Uint8Array(packageSizeBuffer);
|
|
30
31
|
}
|
|
31
|
-
function concatArrays(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
function concatArrays() {
|
|
33
|
+
var args = [];
|
|
34
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
35
|
+
args[_i] = arguments[_i];
|
|
36
|
+
}
|
|
37
|
+
var size = 0;
|
|
38
|
+
args.forEach(function (arr) { return (size += arr.byteLength); });
|
|
39
|
+
var retVal = new Uint8Array(size);
|
|
40
|
+
var position = 0;
|
|
41
|
+
args.forEach(function (arr) {
|
|
37
42
|
retVal.set(arr, position);
|
|
38
43
|
position += arr.byteLength;
|
|
39
44
|
});
|
|
40
45
|
return retVal;
|
|
41
46
|
}
|
|
42
47
|
exports.default = {
|
|
43
|
-
ArrayReader,
|
|
44
|
-
getInt32Buffer,
|
|
45
|
-
concatArrays,
|
|
48
|
+
ArrayReader: ArrayReader,
|
|
49
|
+
getInt32Buffer: getInt32Buffer,
|
|
50
|
+
concatArrays: concatArrays,
|
|
46
51
|
};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.maxQueryLength = exports.divider = exports.section1PathPrefix = exports.emptyValue = exports.falseValue = exports.trueValue = exports.pivotCachesPathPrefix = exports.xmlTextResultType = exports.textResultType = exports.application = exports.uint8ArrayType = exports.blobFileType = exports.
|
|
6
|
-
exports.URLS = exports.defaults = exports.elementAttributesValues = exports.dataTypeKind = exports.elementAttributes = exports.element = exports.BOM = exports.falseStr = exports.trueStr = void 0;
|
|
5
|
+
exports.maxQueryLength = exports.divider = exports.section1PathPrefix = exports.emptyValue = exports.falseValue = exports.trueValue = exports.pivotCachesPathPrefix = exports.xmlTextResultType = exports.textResultType = exports.application = exports.uint8ArrayType = exports.blobFileType = exports.columnIndexOutOfRangeErr = exports.relsNotFoundErr = exports.arrayIsntMxNErr = exports.unexpectedErr = exports.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr = exports.InvalidColumnNameErr = exports.stylesNotFoundErr = exports.EmptyQueryNameErr = exports.QueryNameInvalidCharsErr = exports.QueryNameMaxLengthErr = exports.invalidDataTypeErr = exports.headerNotFoundErr = exports.invalidValueInColumnErr = exports.tableNotFoundErr = exports.queryTableNotFoundErr = exports.templateWithInitialDataErr = exports.formulaSectionNotFoundErr = exports.queryConnectionNotFoundErr = exports.queryAndPivotTableNotFoundErr = exports.queryNameNotFoundErr = exports.emptyQueryMashupErr = exports.base64NotFoundErr = exports.sheetsNotFoundErr = exports.connectionsNotFoundErr = exports.sharedStringsNotFoundErr = exports.docPropsRootElement = exports.docMetadataXmlPath = exports.relsXmlPath = exports.docPropsCoreXmlPath = exports.section1mPath = exports.pivotCachesPath = exports.queryTablesPath = exports.workbookXmlPath = exports.queryTableXmlPath = exports.tableXmlPath = exports.sheetsXmlPath = exports.sharedStringsXmlPath = exports.connectionsXmlPath = void 0;
|
|
6
|
+
exports.OFU = exports.headers = exports.URLS = exports.defaults = exports.elementAttributesValues = exports.dataTypeKind = exports.elementAttributes = exports.element = exports.BOM = exports.falseStr = exports.trueStr = void 0;
|
|
7
7
|
exports.connectionsXmlPath = "xl/connections.xml";
|
|
8
8
|
exports.sharedStringsXmlPath = "xl/sharedStrings.xml";
|
|
9
9
|
exports.sheetsXmlPath = "xl/worksheets/sheet1.xml";
|
|
@@ -40,8 +40,8 @@ exports.InvalidColumnNameErr = "Invalid column name";
|
|
|
40
40
|
exports.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr = "Headers cannot be promoted without adjusting column names";
|
|
41
41
|
exports.unexpectedErr = "Unexpected error";
|
|
42
42
|
exports.arrayIsntMxNErr = "Array isn't MxN";
|
|
43
|
-
exports.templateFileNotSupportedErr = "Template file is not supported for this API call";
|
|
44
43
|
exports.relsNotFoundErr = ".rels were not found in template";
|
|
44
|
+
exports.columnIndexOutOfRangeErr = "Column index out of range";
|
|
45
45
|
exports.blobFileType = "blob";
|
|
46
46
|
exports.uint8ArrayType = "uint8array";
|
|
47
47
|
exports.application = "application/xlsx";
|
|
@@ -116,6 +116,7 @@ exports.elementAttributes = {
|
|
|
116
116
|
spans: "spans",
|
|
117
117
|
x14acDyDescent: "x14ac:dyDescent",
|
|
118
118
|
xr3uid: "xr3:uid",
|
|
119
|
+
space: "xml:space",
|
|
119
120
|
};
|
|
120
121
|
exports.dataTypeKind = {
|
|
121
122
|
string: "str",
|
|
@@ -123,11 +124,11 @@ exports.dataTypeKind = {
|
|
|
123
124
|
boolean: "b",
|
|
124
125
|
};
|
|
125
126
|
exports.elementAttributesValues = {
|
|
126
|
-
connectionName: (queryName)
|
|
127
|
-
connectionDescription: (queryName)
|
|
128
|
-
connection: (queryName)
|
|
129
|
-
connectionCommand: (queryName)
|
|
130
|
-
tableResultType: ()
|
|
127
|
+
connectionName: function (queryName) { return "Query - ".concat(queryName); },
|
|
128
|
+
connectionDescription: function (queryName) { return "Connection to the '".concat(queryName, "' query in the workbook."); },
|
|
129
|
+
connection: function (queryName) { return "Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=\"".concat(queryName, "\";"); },
|
|
130
|
+
connectionCommand: function (queryName) { return "SELECT * FROM [".concat(queryName, "]"); },
|
|
131
|
+
tableResultType: function () { return "sTable"; },
|
|
131
132
|
};
|
|
132
133
|
exports.defaults = {
|
|
133
134
|
queryName: "Query1",
|
|
@@ -143,3 +144,14 @@ exports.URLS = {
|
|
|
143
144
|
],
|
|
144
145
|
CONNECTED_WORKBOOK: "http://schemas.microsoft.com/ConnectedWorkbook",
|
|
145
146
|
};
|
|
147
|
+
// Content-Type header to indicate that the content is an Excel document
|
|
148
|
+
exports.headers = {
|
|
149
|
+
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
150
|
+
};
|
|
151
|
+
exports.OFU = {
|
|
152
|
+
ViewUrl: "https://view.officeapps.live.com/op/view.aspx?src=http://connectedWorkbooks.excel/",
|
|
153
|
+
PostUrl: "https://view.officeapps.live.com/op/viewpost.aspx?src=http://connectedWorkbooks.excel/",
|
|
154
|
+
AllowTyping: "AllowTyping",
|
|
155
|
+
WdOrigin: "wdOrigin",
|
|
156
|
+
OpenInExcelOririgin: "OpenInExcel",
|
|
157
|
+
};
|
|
@@ -10,61 +10,106 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
13
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
41
|
+
var constants_1 = require("./constants");
|
|
42
|
+
var types_1 = require("../types");
|
|
43
|
+
var xmldom_qsa_1 = require("xmldom-qsa");
|
|
44
|
+
var createOrUpdateProperty = function (doc, parent, property, value) {
|
|
18
45
|
if (value === undefined) {
|
|
19
46
|
return;
|
|
20
47
|
}
|
|
21
|
-
|
|
48
|
+
var elements = parent.getElementsByTagName(property);
|
|
22
49
|
if ((elements === null || elements === void 0 ? void 0 : elements.length) === 0) {
|
|
23
|
-
|
|
50
|
+
var newElement = doc.createElement(property);
|
|
24
51
|
newElement.textContent = value;
|
|
25
52
|
parent.appendChild(newElement);
|
|
26
53
|
}
|
|
27
54
|
else if (elements.length > 1) {
|
|
28
|
-
throw new Error(
|
|
55
|
+
throw new Error("Invalid DocProps core.xml, multiple ".concat(property, " elements"));
|
|
29
56
|
}
|
|
30
57
|
else if ((elements === null || elements === void 0 ? void 0 : elements.length) > 0) {
|
|
31
58
|
elements[0].textContent = value;
|
|
32
59
|
}
|
|
33
60
|
};
|
|
34
|
-
|
|
61
|
+
var getDocPropsProperties = function (zip) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
var docPropsCoreXmlString, parser, doc, properties;
|
|
35
63
|
var _a;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
64
|
+
return __generator(this, function (_b) {
|
|
65
|
+
switch (_b.label) {
|
|
66
|
+
case 0: return [4 /*yield*/, ((_a = zip.file(constants_1.docPropsCoreXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
67
|
+
case 1:
|
|
68
|
+
docPropsCoreXmlString = _b.sent();
|
|
69
|
+
if (docPropsCoreXmlString === undefined) {
|
|
70
|
+
throw new Error("DocProps core.xml was not found in template");
|
|
71
|
+
}
|
|
72
|
+
parser = new xmldom_qsa_1.DOMParser();
|
|
73
|
+
doc = parser.parseFromString(docPropsCoreXmlString, constants_1.xmlTextResultType);
|
|
74
|
+
properties = doc.getElementsByTagName(constants_1.docPropsRootElement).item(0);
|
|
75
|
+
if (properties === null) {
|
|
76
|
+
throw new Error("Invalid DocProps core.xml");
|
|
77
|
+
}
|
|
78
|
+
return [2 /*return*/, { doc: doc, properties: properties }];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}); };
|
|
82
|
+
var getCellReferenceAbsolute = function (col, row) {
|
|
83
|
+
return "$" + convertToExcelColumn(col) + "$" + row.toString();
|
|
84
|
+
};
|
|
85
|
+
var getCellReferenceRelative = function (col, row) {
|
|
86
|
+
return convertToExcelColumn(col) + row.toString();
|
|
87
|
+
};
|
|
88
|
+
var convertToExcelColumn = function (index) {
|
|
89
|
+
if (index >= 16384) {
|
|
90
|
+
throw new Error(constants_1.columnIndexOutOfRangeErr);
|
|
39
91
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
92
|
+
var columnStr = "";
|
|
93
|
+
var base = 26; // number of letters in the alphabet
|
|
94
|
+
while (index >= 0) {
|
|
95
|
+
var remainder = index % base;
|
|
96
|
+
columnStr = String.fromCharCode(remainder + 65) + columnStr; // ASCII 'A' is 65
|
|
97
|
+
index = Math.floor(index / base) - 1;
|
|
45
98
|
}
|
|
46
|
-
return
|
|
47
|
-
});
|
|
48
|
-
const getCellReferenceAbsolute = (col, row) => {
|
|
49
|
-
// 65 is the ascii value of first column 'A'
|
|
50
|
-
return "$" + String.fromCharCode(col + 65) + "$" + row.toString();
|
|
99
|
+
return columnStr;
|
|
51
100
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return String.fromCharCode(col + 65) + row.toString();
|
|
101
|
+
var getTableReference = function (numberOfCols, numberOfRows) {
|
|
102
|
+
return "A1:".concat(getCellReferenceRelative(numberOfCols, numberOfRows));
|
|
55
103
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
const createCellElement = (doc, colIndex, rowIndex, data) => {
|
|
60
|
-
const cell = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.kindCell);
|
|
104
|
+
var createCellElement = function (doc, colIndex, rowIndex, data) {
|
|
105
|
+
var cell = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.kindCell);
|
|
61
106
|
cell.setAttribute(constants_1.elementAttributes.row, getCellReferenceRelative(colIndex, rowIndex + 1));
|
|
62
|
-
|
|
107
|
+
var cellData = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.cellValue);
|
|
63
108
|
updateCellData(data, cell, cellData, rowIndex === 0);
|
|
64
109
|
cell.appendChild(cellData);
|
|
65
110
|
return cell;
|
|
66
111
|
};
|
|
67
|
-
|
|
112
|
+
var updateCellData = function (data, cell, cellData, rowHeader) {
|
|
68
113
|
switch (resolveType(data, rowHeader)) {
|
|
69
114
|
case types_1.DataTypes.string:
|
|
70
115
|
cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.string);
|
|
@@ -76,15 +121,18 @@ const updateCellData = (data, cell, cellData, rowHeader) => {
|
|
|
76
121
|
cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.boolean);
|
|
77
122
|
break;
|
|
78
123
|
}
|
|
124
|
+
if (data.startsWith(" ") || data.endsWith(" ")) {
|
|
125
|
+
cellData.setAttribute(constants_1.elementAttributes.space, "preserve");
|
|
126
|
+
}
|
|
79
127
|
cellData.textContent = data;
|
|
80
128
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (rowHeader) {
|
|
84
|
-
// Headers should be string by default.
|
|
129
|
+
var resolveType = function (originalData, rowHeader) {
|
|
130
|
+
var data = originalData;
|
|
131
|
+
if (rowHeader || data.trim() === "") {
|
|
132
|
+
// Headers and whitespace should be string by default.
|
|
85
133
|
return types_1.DataTypes.string;
|
|
86
134
|
}
|
|
87
|
-
|
|
135
|
+
var dataType = isNaN(Number(data)) ? types_1.DataTypes.string : types_1.DataTypes.number;
|
|
88
136
|
if (dataType == types_1.DataTypes.string) {
|
|
89
137
|
if (data.trim() == constants_1.trueStr || data.trim() == constants_1.falseStr) {
|
|
90
138
|
dataType = types_1.DataTypes.boolean;
|
|
@@ -93,11 +141,13 @@ const resolveType = (originalData, rowHeader) => {
|
|
|
93
141
|
return dataType;
|
|
94
142
|
};
|
|
95
143
|
exports.default = {
|
|
96
|
-
createOrUpdateProperty,
|
|
97
|
-
getDocPropsProperties,
|
|
98
|
-
getCellReferenceRelative,
|
|
99
|
-
getCellReferenceAbsolute,
|
|
144
|
+
createOrUpdateProperty: createOrUpdateProperty,
|
|
145
|
+
getDocPropsProperties: getDocPropsProperties,
|
|
146
|
+
getCellReferenceRelative: getCellReferenceRelative,
|
|
147
|
+
getCellReferenceAbsolute: getCellReferenceAbsolute,
|
|
100
148
|
createCell: createCellElement,
|
|
101
|
-
getTableReference,
|
|
102
|
-
|
|
149
|
+
getTableReference: getTableReference,
|
|
150
|
+
updateCellData: updateCellData,
|
|
151
|
+
resolveType: resolveType,
|
|
152
|
+
convertToExcelColumn: convertToExcelColumn,
|
|
103
153
|
};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var constants_1 = require("../utils/constants");
|
|
6
|
+
var parseToTableData = function (grid) {
|
|
7
7
|
var _a, _b, _c, _d;
|
|
8
8
|
if (grid === null || grid === undefined) {
|
|
9
9
|
grid = { data: [] };
|
|
@@ -11,16 +11,16 @@ const parseToTableData = (grid) => {
|
|
|
11
11
|
if (grid.data === null || grid.data === undefined) {
|
|
12
12
|
grid.data = [];
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
var mergedGrid = {
|
|
15
15
|
config: {
|
|
16
16
|
promoteHeaders: (_b = (_a = grid.config) === null || _a === void 0 ? void 0 : _a.promoteHeaders) !== null && _b !== void 0 ? _b : false,
|
|
17
17
|
adjustColumnNames: (_d = (_c = grid.config) === null || _c === void 0 ? void 0 : _c.adjustColumnNames) !== null && _d !== void 0 ? _d : true,
|
|
18
18
|
},
|
|
19
|
-
data: grid.data.map((row)
|
|
19
|
+
data: grid.data.map(function (row) { return row.map(function (value) { var _a; return (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : ""; }); }),
|
|
20
20
|
};
|
|
21
21
|
correctGrid(mergedGrid);
|
|
22
22
|
validateGrid(mergedGrid);
|
|
23
|
-
|
|
23
|
+
var columnNames = [];
|
|
24
24
|
if (mergedGrid.config.promoteHeaders && mergedGrid.config.adjustColumnNames) {
|
|
25
25
|
columnNames = getAdjustedColumnNames(mergedGrid.data.shift());
|
|
26
26
|
}
|
|
@@ -29,23 +29,23 @@ const parseToTableData = (grid) => {
|
|
|
29
29
|
columnNames = mergedGrid.data.shift();
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
columnNames = Array.from({ length: mergedGrid.data[0].length }, (_, index)
|
|
32
|
+
columnNames = Array.from({ length: mergedGrid.data[0].length }, function (_, index) { return "".concat(constants_1.defaults.columnName, " ").concat(index + 1); });
|
|
33
33
|
}
|
|
34
34
|
return { columnNames: columnNames, rows: mergedGrid.data };
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
var correctGrid = function (grid) {
|
|
37
37
|
if (grid.data.length === 0) {
|
|
38
38
|
// empty grid fix
|
|
39
39
|
grid.config.promoteHeaders = false;
|
|
40
40
|
grid.data.push([""]);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
var getEmptyArray = function (n) { return Array.from({ length: n }, function () { return ""; }); };
|
|
44
44
|
if (grid.data[0].length === 0) {
|
|
45
45
|
grid.data[0] = [""];
|
|
46
46
|
}
|
|
47
47
|
// replace empty rows
|
|
48
|
-
grid.data.forEach((row, index)
|
|
48
|
+
grid.data.forEach(function (row, index) {
|
|
49
49
|
if (row.length === 0) {
|
|
50
50
|
grid.data[index] = getEmptyArray(grid.data[0].length);
|
|
51
51
|
}
|
|
@@ -61,43 +61,43 @@ const correctGrid = (grid) => {
|
|
|
61
61
|
* - MxN structure.
|
|
62
62
|
* - If promoteHeaders is true - has at least 1 row, and in case adjustColumnNames is false, first row is unique and non empty.
|
|
63
63
|
*/
|
|
64
|
-
|
|
64
|
+
var validateGrid = function (grid) {
|
|
65
65
|
validateDataArrayDimensions(grid.data);
|
|
66
66
|
if (grid.config.promoteHeaders && grid.config.adjustColumnNames === false && !validateUniqueAndValidDataArray(grid.data[0])) {
|
|
67
67
|
throw new Error(constants_1.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr);
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
var validateDataArrayDimensions = function (arr) {
|
|
71
71
|
if (arr.length === 0 || arr[0].length === 0) {
|
|
72
72
|
throw new Error(constants_1.unexpectedErr);
|
|
73
73
|
}
|
|
74
|
-
if (!arr.every((innerArr)
|
|
74
|
+
if (!arr.every(function (innerArr) { return innerArr.length === arr[0].length; })) {
|
|
75
75
|
throw new Error(constants_1.arrayIsntMxNErr);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
|
|
79
|
-
if (arr.some((element)
|
|
78
|
+
var validateUniqueAndValidDataArray = function (arr) {
|
|
79
|
+
if (arr.some(function (element) { return element === ""; })) {
|
|
80
80
|
return false; // Array contains empty elements
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
var uniqueSet = new Set(arr);
|
|
83
83
|
return uniqueSet.size === arr.length;
|
|
84
84
|
};
|
|
85
|
-
|
|
85
|
+
var getAdjustedColumnNames = function (columnNames) {
|
|
86
86
|
if (columnNames === undefined) {
|
|
87
87
|
throw new Error(constants_1.unexpectedErr);
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
var i = 1;
|
|
90
90
|
// replace empty column names with default names, can still conflict if columns exist, but we handle that later
|
|
91
|
-
columnNames = columnNames.map((columnName)
|
|
92
|
-
|
|
93
|
-
return columnNames.map((name)
|
|
94
|
-
|
|
91
|
+
columnNames = columnNames.map(function (columnName) { return columnName || "".concat(constants_1.defaults.columnName, " ").concat(i++); });
|
|
92
|
+
var uniqueNames = new Set();
|
|
93
|
+
return columnNames.map(function (name) {
|
|
94
|
+
var uniqueName = name;
|
|
95
95
|
i = 1;
|
|
96
96
|
while (uniqueNames.has(uniqueName)) {
|
|
97
|
-
uniqueName =
|
|
97
|
+
uniqueName = "".concat(name, " (").concat(i++, ")");
|
|
98
98
|
}
|
|
99
99
|
uniqueNames.add(uniqueName);
|
|
100
100
|
return uniqueName;
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
|
-
exports.default = { parseToTableData };
|
|
103
|
+
exports.default = { parseToTableData: parseToTableData };
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var extractTableValues = function (table) {
|
|
6
|
+
var rows = [];
|
|
7
7
|
// Extract values from each row
|
|
8
|
-
for (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (
|
|
12
|
-
|
|
8
|
+
for (var i = 0; i < table.rows.length; i++) {
|
|
9
|
+
var row = table.rows[i];
|
|
10
|
+
var rowData = [];
|
|
11
|
+
for (var j = 0; j < row.cells.length; j++) {
|
|
12
|
+
var cell = row.cells[j];
|
|
13
13
|
rowData.push(cell.textContent || "");
|
|
14
14
|
}
|
|
15
15
|
rows.push(rowData);
|
|
16
16
|
}
|
|
17
17
|
return rows;
|
|
18
18
|
};
|
|
19
|
-
exports.default = { extractTableValues };
|
|
19
|
+
exports.default = { extractTableValues: extractTableValues };
|