@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
|
@@ -10,55 +10,99 @@ 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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
42
|
};
|
|
16
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
44
|
+
var constants_1 = require("./constants");
|
|
45
|
+
var documentUtils_1 = __importDefault(require("./documentUtils"));
|
|
46
|
+
var uuid_1 = require("uuid");
|
|
47
|
+
var xmldom_qsa_1 = require("xmldom-qsa");
|
|
48
|
+
var updateTableInitialDataIfNeeded = function (zip, tableData, updateQueryTable) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
var sheetsXmlString, newSheet, queryTableXmlString, newQueryTable, workbookXmlString, newWorkbook, tableXmlString, newTable;
|
|
22
50
|
var _a, _b, _c, _d;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
return __generator(this, function (_e) {
|
|
52
|
+
switch (_e.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
if (!tableData) {
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
}
|
|
57
|
+
return [4 /*yield*/, ((_a = zip.file(constants_1.sheetsXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType))];
|
|
58
|
+
case 1:
|
|
59
|
+
sheetsXmlString = _e.sent();
|
|
60
|
+
if (sheetsXmlString === undefined) {
|
|
61
|
+
throw new Error(constants_1.sheetsNotFoundErr);
|
|
62
|
+
}
|
|
63
|
+
newSheet = updateSheetsInitialData(sheetsXmlString, tableData);
|
|
64
|
+
zip.file(constants_1.sheetsXmlPath, newSheet);
|
|
65
|
+
if (!updateQueryTable) return [3 /*break*/, 5];
|
|
66
|
+
return [4 /*yield*/, ((_b = zip.file(constants_1.queryTableXmlPath)) === null || _b === void 0 ? void 0 : _b.async(constants_1.textResultType))];
|
|
67
|
+
case 2:
|
|
68
|
+
queryTableXmlString = _e.sent();
|
|
69
|
+
if (queryTableXmlString === undefined) {
|
|
70
|
+
throw new Error(constants_1.queryTableNotFoundErr);
|
|
71
|
+
}
|
|
72
|
+
return [4 /*yield*/, updateQueryTablesInitialData(queryTableXmlString, tableData)];
|
|
73
|
+
case 3:
|
|
74
|
+
newQueryTable = _e.sent();
|
|
75
|
+
zip.file(constants_1.queryTableXmlPath, newQueryTable);
|
|
76
|
+
return [4 /*yield*/, ((_c = zip.file(constants_1.workbookXmlPath)) === null || _c === void 0 ? void 0 : _c.async(constants_1.textResultType))];
|
|
77
|
+
case 4:
|
|
78
|
+
workbookXmlString = _e.sent();
|
|
79
|
+
if (workbookXmlString === undefined) {
|
|
80
|
+
throw new Error(constants_1.sheetsNotFoundErr);
|
|
81
|
+
}
|
|
82
|
+
newWorkbook = updateWorkbookInitialData(workbookXmlString, tableData);
|
|
83
|
+
zip.file(constants_1.workbookXmlPath, newWorkbook);
|
|
84
|
+
_e.label = 5;
|
|
85
|
+
case 5: return [4 /*yield*/, ((_d = zip.file(constants_1.tableXmlPath)) === null || _d === void 0 ? void 0 : _d.async(constants_1.textResultType))];
|
|
86
|
+
case 6:
|
|
87
|
+
tableXmlString = _e.sent();
|
|
88
|
+
if (tableXmlString === undefined) {
|
|
89
|
+
throw new Error(constants_1.tableNotFoundErr);
|
|
90
|
+
}
|
|
91
|
+
newTable = updateTablesInitialData(tableXmlString, tableData, updateQueryTable);
|
|
92
|
+
zip.file(constants_1.tableXmlPath, newTable);
|
|
93
|
+
return [2 /*return*/];
|
|
36
94
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
zip.file(constants_1.workbookXmlPath, newWorkbook);
|
|
46
|
-
}
|
|
47
|
-
const tableXmlString = yield ((_d = zip.file(constants_1.tableXmlPath)) === null || _d === void 0 ? void 0 : _d.async(constants_1.textResultType));
|
|
48
|
-
if (tableXmlString === undefined) {
|
|
49
|
-
throw new Error(constants_1.tableNotFoundErr);
|
|
50
|
-
}
|
|
51
|
-
const newTable = updateTablesInitialData(tableXmlString, tableData, updateQueryTable);
|
|
52
|
-
zip.file(constants_1.tableXmlPath, newTable);
|
|
53
|
-
});
|
|
54
|
-
const updateTablesInitialData = (tableXmlString, tableData, updateQueryTable = false) => {
|
|
55
|
-
const parser = new xmldom_1.DOMParser();
|
|
56
|
-
const serializer = new xmldom_1.XMLSerializer();
|
|
57
|
-
const tableDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
58
|
-
const tableColumns = tableDoc.getElementsByTagName(constants_1.element.tableColumns)[0];
|
|
95
|
+
});
|
|
96
|
+
}); };
|
|
97
|
+
var updateTablesInitialData = function (tableXmlString, tableData, updateQueryTable) {
|
|
98
|
+
if (updateQueryTable === void 0) { updateQueryTable = false; }
|
|
99
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
100
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
101
|
+
var tableDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
102
|
+
var tableColumns = tableDoc.getElementsByTagName(constants_1.element.tableColumns)[0];
|
|
59
103
|
tableColumns.textContent = "";
|
|
60
|
-
tableData.columnNames.forEach((column, columnIndex)
|
|
61
|
-
|
|
104
|
+
tableData.columnNames.forEach(function (column, columnIndex) {
|
|
105
|
+
var tableColumn = tableDoc.createElementNS(tableDoc.documentElement.namespaceURI, constants_1.element.tableColumn);
|
|
62
106
|
tableColumn.setAttribute(constants_1.elementAttributes.id, (columnIndex + 1).toString());
|
|
63
107
|
tableColumn.setAttribute(constants_1.elementAttributes.name, column);
|
|
64
108
|
tableColumns.appendChild(tableColumn);
|
|
@@ -71,29 +115,29 @@ const updateTablesInitialData = (tableXmlString, tableData, updateQueryTable = f
|
|
|
71
115
|
tableColumns.setAttribute(constants_1.elementAttributes.count, tableData.columnNames.length.toString());
|
|
72
116
|
tableDoc
|
|
73
117
|
.getElementsByTagName(constants_1.element.table)[0]
|
|
74
|
-
.setAttribute(constants_1.elementAttributes.reference,
|
|
118
|
+
.setAttribute(constants_1.elementAttributes.reference, "A1:".concat(documentUtils_1.default.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)));
|
|
75
119
|
tableDoc
|
|
76
120
|
.getElementsByTagName(constants_1.element.autoFilter)[0]
|
|
77
|
-
.setAttribute(constants_1.elementAttributes.reference,
|
|
121
|
+
.setAttribute(constants_1.elementAttributes.reference, "A1:".concat(documentUtils_1.default.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)));
|
|
78
122
|
return serializer.serializeToString(tableDoc);
|
|
79
123
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
124
|
+
var updateWorkbookInitialData = function (workbookXmlString, tableData) {
|
|
125
|
+
var newParser = new xmldom_qsa_1.DOMParser();
|
|
126
|
+
var newSerializer = new xmldom_qsa_1.XMLSerializer();
|
|
127
|
+
var workbookDoc = newParser.parseFromString(workbookXmlString, constants_1.xmlTextResultType);
|
|
128
|
+
var definedName = workbookDoc.getElementsByTagName(constants_1.element.definedName)[0];
|
|
85
129
|
definedName.textContent =
|
|
86
|
-
constants_1.defaults.sheetName +
|
|
130
|
+
constants_1.defaults.sheetName + "!$A$1:".concat(documentUtils_1.default.getCellReferenceAbsolute(tableData.columnNames.length - 1, tableData.rows.length + 1));
|
|
87
131
|
return newSerializer.serializeToString(workbookDoc);
|
|
88
132
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
133
|
+
var updateQueryTablesInitialData = function (queryTableXmlString, tableData) {
|
|
134
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
135
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
136
|
+
var queryTableDoc = parser.parseFromString(queryTableXmlString, constants_1.xmlTextResultType);
|
|
137
|
+
var queryTableFields = queryTableDoc.getElementsByTagName(constants_1.element.queryTableFields)[0];
|
|
94
138
|
queryTableFields.textContent = "";
|
|
95
|
-
tableData.columnNames.forEach((column, columnIndex)
|
|
96
|
-
|
|
139
|
+
tableData.columnNames.forEach(function (column, columnIndex) {
|
|
140
|
+
var queryTableField = queryTableDoc.createElementNS(queryTableDoc.documentElement.namespaceURI, constants_1.element.queryTableField);
|
|
97
141
|
queryTableField.setAttribute(constants_1.elementAttributes.id, (columnIndex + 1).toString());
|
|
98
142
|
queryTableField.setAttribute(constants_1.elementAttributes.name, column);
|
|
99
143
|
queryTableField.setAttribute(constants_1.elementAttributes.tableColumnId, (columnIndex + 1).toString());
|
|
@@ -103,42 +147,42 @@ const updateQueryTablesInitialData = (queryTableXmlString, tableData) => {
|
|
|
103
147
|
queryTableDoc.getElementsByTagName(constants_1.element.queryTableRefresh)[0].setAttribute(constants_1.elementAttributes.nextId, (tableData.columnNames.length + 1).toString());
|
|
104
148
|
return serializer.serializeToString(queryTableDoc);
|
|
105
149
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
150
|
+
var updateSheetsInitialData = function (sheetsXmlString, tableData) {
|
|
151
|
+
var parser = new xmldom_qsa_1.DOMParser();
|
|
152
|
+
var serializer = new xmldom_qsa_1.XMLSerializer();
|
|
153
|
+
var sheetsDoc = parser.parseFromString(sheetsXmlString, constants_1.xmlTextResultType);
|
|
154
|
+
var sheetData = sheetsDoc.getElementsByTagName(constants_1.element.sheetData)[0];
|
|
111
155
|
sheetData.textContent = "";
|
|
112
|
-
|
|
113
|
-
|
|
156
|
+
var rowIndex = 0;
|
|
157
|
+
var columnRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, constants_1.element.row);
|
|
114
158
|
columnRow.setAttribute(constants_1.elementAttributes.row, (rowIndex + 1).toString());
|
|
115
159
|
columnRow.setAttribute(constants_1.elementAttributes.spans, "1:" + tableData.columnNames.length);
|
|
116
160
|
columnRow.setAttribute(constants_1.elementAttributes.x14acDyDescent, "0.3");
|
|
117
|
-
tableData.columnNames.forEach((col, colIndex)
|
|
161
|
+
tableData.columnNames.forEach(function (col, colIndex) {
|
|
118
162
|
columnRow.appendChild(documentUtils_1.default.createCell(sheetsDoc, colIndex, rowIndex, col));
|
|
119
163
|
});
|
|
120
164
|
sheetData.appendChild(columnRow);
|
|
121
165
|
rowIndex++;
|
|
122
|
-
tableData.rows.forEach((row)
|
|
123
|
-
|
|
166
|
+
tableData.rows.forEach(function (row) {
|
|
167
|
+
var newRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, constants_1.element.row);
|
|
124
168
|
newRow.setAttribute(constants_1.elementAttributes.row, (rowIndex + 1).toString());
|
|
125
169
|
newRow.setAttribute(constants_1.elementAttributes.spans, "1:" + row.length);
|
|
126
170
|
newRow.setAttribute(constants_1.elementAttributes.x14acDyDescent, "0.3");
|
|
127
|
-
row.forEach((cellContent, colIndex)
|
|
171
|
+
row.forEach(function (cellContent, colIndex) {
|
|
128
172
|
newRow.appendChild(documentUtils_1.default.createCell(sheetsDoc, colIndex, rowIndex, cellContent));
|
|
129
173
|
});
|
|
130
174
|
sheetData.appendChild(newRow);
|
|
131
175
|
rowIndex++;
|
|
132
176
|
});
|
|
133
|
-
|
|
177
|
+
var reference = documentUtils_1.default.getTableReference(tableData.rows[0].length - 1, tableData.rows.length + 1);
|
|
134
178
|
sheetsDoc.getElementsByTagName(constants_1.element.dimension)[0].setAttribute(constants_1.elementAttributes.reference, reference);
|
|
135
179
|
sheetsDoc.getElementsByTagName(constants_1.element.selection)[0].setAttribute(constants_1.elementAttributes.sqref, reference);
|
|
136
180
|
return serializer.serializeToString(sheetsDoc);
|
|
137
181
|
};
|
|
138
182
|
exports.default = {
|
|
139
|
-
updateTableInitialDataIfNeeded,
|
|
140
|
-
updateSheetsInitialData,
|
|
141
|
-
updateWorkbookInitialData,
|
|
142
|
-
updateTablesInitialData,
|
|
143
|
-
updateQueryTablesInitialData,
|
|
183
|
+
updateTableInitialDataIfNeeded: updateTableInitialDataIfNeeded,
|
|
184
|
+
updateSheetsInitialData: updateSheetsInitialData,
|
|
185
|
+
updateWorkbookInitialData: updateWorkbookInitialData,
|
|
186
|
+
updateTablesInitialData: updateTablesInitialData,
|
|
187
|
+
updateQueryTablesInitialData: updateQueryTablesInitialData,
|
|
144
188
|
};
|