@microsoft/connected-workbooks 3.0.0 → 3.1.1-beta.2
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 +17 -4
- package/dist/generators.js +7 -12
- package/dist/index.js +4 -30
- package/dist/main.js +383 -0
- package/dist/src/types.d.ts +54 -0
- package/dist/src/utils/documentUtils.js +2 -1
- package/dist/src/utils/index.d.ts +8 -0
- package/dist/src/utils/mashupDocumentParser.js +5 -5
- package/dist/src/utils/pqUtils.js +4 -3
- package/dist/src/utils/tableUtils.js +9 -8
- package/dist/src/utils/xmlInnerPartsUtils.js +18 -17
- package/dist/tests/mocks/index.d.ts +3 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +6 -9
- package/dist/utils/arrayUtils.js +28 -26
- package/dist/utils/constants.js +73 -68
- package/dist/utils/documentUtils.js +88 -52
- package/dist/utils/gridUtils.js +27 -29
- package/dist/utils/htmlUtils.js +8 -10
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +8 -22
- package/dist/utils/mashupDocumentParser.js +128 -108
- package/dist/utils/pqUtils.js +143 -71
- package/dist/utils/tableUtils.js +140 -101
- package/dist/utils/xmlInnerPartsUtils.js +228 -172
- package/dist/utils/xmlPartsUtils.js +116 -55
- package/dist/workbookManager.d.ts +1 -0
- package/dist/workbookManager.js +174 -72
- package/dist/workbookTemplate.js +2 -5
- package/package.json +1 -1
- package/dist/gridParser.js +0 -58
- package/dist/gridUtils.js +0 -58
package/dist/utils/tableUtils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright (c) Microsoft Corporation.
|
|
3
2
|
// Licensed under the MIT license.
|
|
4
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
@@ -10,134 +9,174 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
9
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
10
|
});
|
|
12
11
|
};
|
|
13
|
-
var
|
|
14
|
-
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
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;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
15
38
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
import { defaults, element, elementAttributes, queryTableNotFoundErr, queryTableXmlPath, sheetsNotFoundErr, sheetsXmlPath, tableNotFoundErr, tableXmlPath, textResultType, workbookXmlPath, xmlTextResultType, } from "./constants";
|
|
40
|
+
import documentUtils from "./documentUtils";
|
|
41
|
+
import { v4 } from "uuid";
|
|
42
|
+
var updateTableInitialDataIfNeeded = function (zip, tableData, updateQueryTable) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
+
var sheetsXmlString, newSheet, queryTableXmlString, newQueryTable, workbookXmlString, newWorkbook, tableXmlString, newTable;
|
|
21
44
|
var _a, _b, _c, _d;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
return __generator(this, function (_e) {
|
|
46
|
+
switch (_e.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
if (!tableData) {
|
|
49
|
+
return [2 /*return*/];
|
|
50
|
+
}
|
|
51
|
+
return [4 /*yield*/, ((_a = zip.file(sheetsXmlPath)) === null || _a === void 0 ? void 0 : _a.async(textResultType))];
|
|
52
|
+
case 1:
|
|
53
|
+
sheetsXmlString = _e.sent();
|
|
54
|
+
if (sheetsXmlString === undefined) {
|
|
55
|
+
throw new Error(sheetsNotFoundErr);
|
|
56
|
+
}
|
|
57
|
+
newSheet = updateSheetsInitialData(sheetsXmlString, tableData);
|
|
58
|
+
zip.file(sheetsXmlPath, newSheet);
|
|
59
|
+
if (!updateQueryTable) return [3 /*break*/, 5];
|
|
60
|
+
return [4 /*yield*/, ((_b = zip.file(queryTableXmlPath)) === null || _b === void 0 ? void 0 : _b.async(textResultType))];
|
|
61
|
+
case 2:
|
|
62
|
+
queryTableXmlString = _e.sent();
|
|
63
|
+
if (queryTableXmlString === undefined) {
|
|
64
|
+
throw new Error(queryTableNotFoundErr);
|
|
65
|
+
}
|
|
66
|
+
return [4 /*yield*/, updateQueryTablesInitialData(queryTableXmlString, tableData)];
|
|
67
|
+
case 3:
|
|
68
|
+
newQueryTable = _e.sent();
|
|
69
|
+
zip.file(queryTableXmlPath, newQueryTable);
|
|
70
|
+
return [4 /*yield*/, ((_c = zip.file(workbookXmlPath)) === null || _c === void 0 ? void 0 : _c.async(textResultType))];
|
|
71
|
+
case 4:
|
|
72
|
+
workbookXmlString = _e.sent();
|
|
73
|
+
if (workbookXmlString === undefined) {
|
|
74
|
+
throw new Error(sheetsNotFoundErr);
|
|
75
|
+
}
|
|
76
|
+
newWorkbook = updateWorkbookInitialData(workbookXmlString, tableData);
|
|
77
|
+
zip.file(workbookXmlPath, newWorkbook);
|
|
78
|
+
_e.label = 5;
|
|
79
|
+
case 5: return [4 /*yield*/, ((_d = zip.file(tableXmlPath)) === null || _d === void 0 ? void 0 : _d.async(textResultType))];
|
|
80
|
+
case 6:
|
|
81
|
+
tableXmlString = _e.sent();
|
|
82
|
+
if (tableXmlString === undefined) {
|
|
83
|
+
throw new Error(tableNotFoundErr);
|
|
84
|
+
}
|
|
85
|
+
newTable = updateTablesInitialData(tableXmlString, tableData, updateQueryTable);
|
|
86
|
+
zip.file(tableXmlPath, newTable);
|
|
87
|
+
return [2 /*return*/];
|
|
42
88
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
zip.file(constants_1.tableXmlPath, newTable);
|
|
52
|
-
});
|
|
53
|
-
const updateTablesInitialData = (tableXmlString, tableData, updateQueryTable = false) => {
|
|
54
|
-
const parser = new DOMParser();
|
|
55
|
-
const serializer = new XMLSerializer();
|
|
56
|
-
const tableDoc = parser.parseFromString(tableXmlString, constants_1.xmlTextResultType);
|
|
57
|
-
const tableColumns = tableDoc.getElementsByTagName(constants_1.element.tableColumns)[0];
|
|
89
|
+
});
|
|
90
|
+
}); };
|
|
91
|
+
var updateTablesInitialData = function (tableXmlString, tableData, updateQueryTable) {
|
|
92
|
+
if (updateQueryTable === void 0) { updateQueryTable = false; }
|
|
93
|
+
var parser = new DOMParser();
|
|
94
|
+
var serializer = new XMLSerializer();
|
|
95
|
+
var tableDoc = parser.parseFromString(tableXmlString, xmlTextResultType);
|
|
96
|
+
var tableColumns = tableDoc.getElementsByTagName(element.tableColumns)[0];
|
|
58
97
|
tableColumns.textContent = "";
|
|
59
|
-
tableData.columnNames.forEach((column, columnIndex)
|
|
60
|
-
|
|
61
|
-
tableColumn.setAttribute(
|
|
62
|
-
tableColumn.setAttribute(
|
|
98
|
+
tableData.columnNames.forEach(function (column, columnIndex) {
|
|
99
|
+
var tableColumn = tableDoc.createElementNS(tableDoc.documentElement.namespaceURI, element.tableColumn);
|
|
100
|
+
tableColumn.setAttribute(elementAttributes.id, (columnIndex + 1).toString());
|
|
101
|
+
tableColumn.setAttribute(elementAttributes.name, column);
|
|
63
102
|
tableColumns.appendChild(tableColumn);
|
|
64
|
-
tableColumn.setAttribute(
|
|
103
|
+
tableColumn.setAttribute(elementAttributes.xr3uid, "{" + v4().toUpperCase() + "}");
|
|
65
104
|
if (updateQueryTable) {
|
|
66
|
-
tableColumn.setAttribute(
|
|
67
|
-
tableColumn.setAttribute(
|
|
105
|
+
tableColumn.setAttribute(elementAttributes.uniqueName, (columnIndex + 1).toString());
|
|
106
|
+
tableColumn.setAttribute(elementAttributes.queryTableFieldId, (columnIndex + 1).toString());
|
|
68
107
|
}
|
|
69
108
|
});
|
|
70
|
-
tableColumns.setAttribute(
|
|
109
|
+
tableColumns.setAttribute(elementAttributes.count, tableData.columnNames.length.toString());
|
|
71
110
|
tableDoc
|
|
72
|
-
.getElementsByTagName(
|
|
73
|
-
.setAttribute(
|
|
111
|
+
.getElementsByTagName(element.table)[0]
|
|
112
|
+
.setAttribute(elementAttributes.reference, "A1:".concat(documentUtils.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)));
|
|
74
113
|
tableDoc
|
|
75
|
-
.getElementsByTagName(
|
|
76
|
-
.setAttribute(
|
|
114
|
+
.getElementsByTagName(element.autoFilter)[0]
|
|
115
|
+
.setAttribute(elementAttributes.reference, "A1:".concat(documentUtils.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)));
|
|
77
116
|
return serializer.serializeToString(tableDoc);
|
|
78
117
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
118
|
+
var updateWorkbookInitialData = function (workbookXmlString, tableData) {
|
|
119
|
+
var newParser = new DOMParser();
|
|
120
|
+
var newSerializer = new XMLSerializer();
|
|
121
|
+
var workbookDoc = newParser.parseFromString(workbookXmlString, xmlTextResultType);
|
|
122
|
+
var definedName = workbookDoc.getElementsByTagName(element.definedName)[0];
|
|
84
123
|
definedName.textContent =
|
|
85
|
-
|
|
124
|
+
defaults.sheetName + "!$A$1:".concat(documentUtils.getCellReferenceAbsolute(tableData.columnNames.length - 1, tableData.rows.length + 1));
|
|
86
125
|
return newSerializer.serializeToString(workbookDoc);
|
|
87
126
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
127
|
+
var updateQueryTablesInitialData = function (queryTableXmlString, tableData) {
|
|
128
|
+
var parser = new DOMParser();
|
|
129
|
+
var serializer = new XMLSerializer();
|
|
130
|
+
var queryTableDoc = parser.parseFromString(queryTableXmlString, xmlTextResultType);
|
|
131
|
+
var queryTableFields = queryTableDoc.getElementsByTagName(element.queryTableFields)[0];
|
|
93
132
|
queryTableFields.textContent = "";
|
|
94
|
-
tableData.columnNames.forEach((column, columnIndex)
|
|
95
|
-
|
|
96
|
-
queryTableField.setAttribute(
|
|
97
|
-
queryTableField.setAttribute(
|
|
98
|
-
queryTableField.setAttribute(
|
|
133
|
+
tableData.columnNames.forEach(function (column, columnIndex) {
|
|
134
|
+
var queryTableField = queryTableDoc.createElementNS(queryTableDoc.documentElement.namespaceURI, element.queryTableField);
|
|
135
|
+
queryTableField.setAttribute(elementAttributes.id, (columnIndex + 1).toString());
|
|
136
|
+
queryTableField.setAttribute(elementAttributes.name, column);
|
|
137
|
+
queryTableField.setAttribute(elementAttributes.tableColumnId, (columnIndex + 1).toString());
|
|
99
138
|
queryTableFields.appendChild(queryTableField);
|
|
100
139
|
});
|
|
101
|
-
queryTableFields.setAttribute(
|
|
102
|
-
queryTableDoc.getElementsByTagName(
|
|
140
|
+
queryTableFields.setAttribute(elementAttributes.count, tableData.columnNames.length.toString());
|
|
141
|
+
queryTableDoc.getElementsByTagName(element.queryTableRefresh)[0].setAttribute(elementAttributes.nextId, (tableData.columnNames.length + 1).toString());
|
|
103
142
|
return serializer.serializeToString(queryTableDoc);
|
|
104
143
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
144
|
+
var updateSheetsInitialData = function (sheetsXmlString, tableData) {
|
|
145
|
+
var parser = new DOMParser();
|
|
146
|
+
var serializer = new XMLSerializer();
|
|
147
|
+
var sheetsDoc = parser.parseFromString(sheetsXmlString, xmlTextResultType);
|
|
148
|
+
var sheetData = sheetsDoc.getElementsByTagName(element.sheetData)[0];
|
|
110
149
|
sheetData.textContent = "";
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
columnRow.setAttribute(
|
|
114
|
-
columnRow.setAttribute(
|
|
115
|
-
columnRow.setAttribute(
|
|
116
|
-
tableData.columnNames.forEach((col, colIndex)
|
|
117
|
-
columnRow.appendChild(
|
|
150
|
+
var rowIndex = 0;
|
|
151
|
+
var columnRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, element.row);
|
|
152
|
+
columnRow.setAttribute(elementAttributes.row, (rowIndex + 1).toString());
|
|
153
|
+
columnRow.setAttribute(elementAttributes.spans, "1:" + tableData.columnNames.length);
|
|
154
|
+
columnRow.setAttribute(elementAttributes.x14acDyDescent, "0.3");
|
|
155
|
+
tableData.columnNames.forEach(function (col, colIndex) {
|
|
156
|
+
columnRow.appendChild(documentUtils.createCell(sheetsDoc, colIndex, rowIndex, col));
|
|
118
157
|
});
|
|
119
158
|
sheetData.appendChild(columnRow);
|
|
120
159
|
rowIndex++;
|
|
121
|
-
tableData.rows.forEach((row)
|
|
122
|
-
|
|
123
|
-
newRow.setAttribute(
|
|
124
|
-
newRow.setAttribute(
|
|
125
|
-
newRow.setAttribute(
|
|
126
|
-
row.forEach((cellContent, colIndex)
|
|
127
|
-
newRow.appendChild(
|
|
160
|
+
tableData.rows.forEach(function (row) {
|
|
161
|
+
var newRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, element.row);
|
|
162
|
+
newRow.setAttribute(elementAttributes.row, (rowIndex + 1).toString());
|
|
163
|
+
newRow.setAttribute(elementAttributes.spans, "1:" + row.length);
|
|
164
|
+
newRow.setAttribute(elementAttributes.x14acDyDescent, "0.3");
|
|
165
|
+
row.forEach(function (cellContent, colIndex) {
|
|
166
|
+
newRow.appendChild(documentUtils.createCell(sheetsDoc, colIndex, rowIndex, cellContent));
|
|
128
167
|
});
|
|
129
168
|
sheetData.appendChild(newRow);
|
|
130
169
|
rowIndex++;
|
|
131
170
|
});
|
|
132
|
-
|
|
133
|
-
sheetsDoc.getElementsByTagName(
|
|
134
|
-
sheetsDoc.getElementsByTagName(
|
|
171
|
+
var reference = documentUtils.getTableReference(tableData.rows[0].length - 1, tableData.rows.length + 1);
|
|
172
|
+
sheetsDoc.getElementsByTagName(element.dimension)[0].setAttribute(elementAttributes.reference, reference);
|
|
173
|
+
sheetsDoc.getElementsByTagName(element.selection)[0].setAttribute(elementAttributes.sqref, reference);
|
|
135
174
|
return serializer.serializeToString(sheetsDoc);
|
|
136
175
|
};
|
|
137
|
-
|
|
138
|
-
updateTableInitialDataIfNeeded,
|
|
139
|
-
updateSheetsInitialData,
|
|
140
|
-
updateWorkbookInitialData,
|
|
141
|
-
updateTablesInitialData,
|
|
142
|
-
updateQueryTablesInitialData,
|
|
176
|
+
export default {
|
|
177
|
+
updateTableInitialDataIfNeeded: updateTableInitialDataIfNeeded,
|
|
178
|
+
updateSheetsInitialData: updateSheetsInitialData,
|
|
179
|
+
updateWorkbookInitialData: updateWorkbookInitialData,
|
|
180
|
+
updateTablesInitialData: updateTablesInitialData,
|
|
181
|
+
updateQueryTablesInitialData: updateQueryTablesInitialData,
|
|
143
182
|
};
|