@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.
@@ -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
- const xmldom_1 = require("xmldom");
18
- const constants_1 = require("./constants");
19
- const documentUtils_1 = __importDefault(require("./documentUtils"));
20
- const uuid_1 = require("uuid");
21
- const updateTableInitialDataIfNeeded = (zip, tableData, updateQueryTable) => __awaiter(void 0, void 0, void 0, function* () {
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
- if (!tableData) {
24
- return;
25
- }
26
- const sheetsXmlString = yield ((_a = zip.file(constants_1.sheetsXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType));
27
- if (sheetsXmlString === undefined) {
28
- throw new Error(constants_1.sheetsNotFoundErr);
29
- }
30
- const newSheet = updateSheetsInitialData(sheetsXmlString, tableData);
31
- zip.file(constants_1.sheetsXmlPath, newSheet);
32
- if (updateQueryTable) {
33
- const queryTableXmlString = yield ((_b = zip.file(constants_1.queryTableXmlPath)) === null || _b === void 0 ? void 0 : _b.async(constants_1.textResultType));
34
- if (queryTableXmlString === undefined) {
35
- throw new Error(constants_1.queryTableNotFoundErr);
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
- const newQueryTable = yield updateQueryTablesInitialData(queryTableXmlString, tableData);
38
- zip.file(constants_1.queryTableXmlPath, newQueryTable);
39
- // update defined name
40
- const workbookXmlString = yield ((_c = zip.file(constants_1.workbookXmlPath)) === null || _c === void 0 ? void 0 : _c.async(constants_1.textResultType));
41
- if (workbookXmlString === undefined) {
42
- throw new Error(constants_1.sheetsNotFoundErr);
43
- }
44
- const newWorkbook = updateWorkbookInitialData(workbookXmlString, tableData);
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
- const tableColumn = tableDoc.createElementNS(tableDoc.documentElement.namespaceURI, constants_1.element.tableColumn);
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, `A1:${documentUtils_1.default.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)}`);
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, `A1:${documentUtils_1.default.getCellReferenceRelative(tableData.columnNames.length - 1, tableData.rows.length + 1)}`);
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
- const updateWorkbookInitialData = (workbookXmlString, tableData) => {
81
- const newParser = new xmldom_1.DOMParser();
82
- const newSerializer = new xmldom_1.XMLSerializer();
83
- const workbookDoc = newParser.parseFromString(workbookXmlString, constants_1.xmlTextResultType);
84
- const definedName = workbookDoc.getElementsByTagName(constants_1.element.definedName)[0];
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 + `!$A$1:${documentUtils_1.default.getCellReferenceAbsolute(tableData.columnNames.length - 1, tableData.rows.length + 1)}`;
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
- const updateQueryTablesInitialData = (queryTableXmlString, tableData) => {
90
- const parser = new xmldom_1.DOMParser();
91
- const serializer = new xmldom_1.XMLSerializer();
92
- const queryTableDoc = parser.parseFromString(queryTableXmlString, constants_1.xmlTextResultType);
93
- const queryTableFields = queryTableDoc.getElementsByTagName(constants_1.element.queryTableFields)[0];
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
- const queryTableField = queryTableDoc.createElementNS(queryTableDoc.documentElement.namespaceURI, constants_1.element.queryTableField);
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
- const updateSheetsInitialData = (sheetsXmlString, tableData) => {
107
- const parser = new xmldom_1.DOMParser();
108
- const serializer = new xmldom_1.XMLSerializer();
109
- const sheetsDoc = parser.parseFromString(sheetsXmlString, constants_1.xmlTextResultType);
110
- const sheetData = sheetsDoc.getElementsByTagName(constants_1.element.sheetData)[0];
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
- let rowIndex = 0;
113
- const columnRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, constants_1.element.row);
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
- const newRow = sheetsDoc.createElementNS(sheetsDoc.documentElement.namespaceURI, constants_1.element.row);
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
- const reference = documentUtils_1.default.getTableReference(tableData.rows[0].length - 1, tableData.rows.length + 1);
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
  };