@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.
@@ -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,93 +9,130 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
9
  step((generator = generator.apply(thisArg, _arguments || [])).next());
11
10
  });
12
11
  };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const constants_1 = require("./constants");
15
- const types_1 = require("../types");
16
- const createOrUpdateProperty = (doc, parent, property, value) => {
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
+ }
38
+ };
39
+ import { dataTypeKind, docPropsCoreXmlPath, docPropsRootElement, element, elementAttributes, falseStr, textResultType, trueStr, xmlTextResultType, } from "./constants";
40
+ import { DataTypes } from "../types";
41
+ var createOrUpdateProperty = function (doc, parent, property, value) {
17
42
  if (value === undefined) {
18
43
  return;
19
44
  }
20
- const elements = parent.getElementsByTagName(property);
45
+ var elements = parent.getElementsByTagName(property);
21
46
  if ((elements === null || elements === void 0 ? void 0 : elements.length) === 0) {
22
- const newElement = doc.createElement(property);
47
+ var newElement = doc.createElement(property);
23
48
  newElement.textContent = value;
24
49
  parent.appendChild(newElement);
25
50
  }
26
51
  else if (elements.length > 1) {
27
- throw new Error(`Invalid DocProps core.xml, multiple ${property} elements`);
52
+ throw new Error("Invalid DocProps core.xml, multiple ".concat(property, " elements"));
28
53
  }
29
54
  else if ((elements === null || elements === void 0 ? void 0 : elements.length) > 0) {
30
55
  elements[0].textContent = value;
31
56
  }
32
57
  };
33
- const getDocPropsProperties = (zip) => __awaiter(void 0, void 0, void 0, function* () {
58
+ var getDocPropsProperties = function (zip) { return __awaiter(void 0, void 0, void 0, function () {
59
+ var docPropsCoreXmlString, parser, doc, properties;
34
60
  var _a;
35
- const docPropsCoreXmlString = yield ((_a = zip.file(constants_1.docPropsCoreXmlPath)) === null || _a === void 0 ? void 0 : _a.async(constants_1.textResultType));
36
- if (docPropsCoreXmlString === undefined) {
37
- throw new Error("DocProps core.xml was not found in template");
38
- }
39
- const parser = new DOMParser();
40
- const doc = parser.parseFromString(docPropsCoreXmlString, constants_1.xmlTextResultType);
41
- const properties = doc.getElementsByTagName(constants_1.docPropsRootElement).item(0);
42
- if (properties === null) {
43
- throw new Error("Invalid DocProps core.xml");
44
- }
45
- return { doc, properties };
46
- });
47
- const getCellReferenceAbsolute = (col, row) => {
61
+ return __generator(this, function (_b) {
62
+ switch (_b.label) {
63
+ case 0: return [4 /*yield*/, ((_a = zip.file(docPropsCoreXmlPath)) === null || _a === void 0 ? void 0 : _a.async(textResultType))];
64
+ case 1:
65
+ docPropsCoreXmlString = _b.sent();
66
+ if (docPropsCoreXmlString === undefined) {
67
+ throw new Error("DocProps core.xml was not found in template");
68
+ }
69
+ parser = new DOMParser();
70
+ doc = parser.parseFromString(docPropsCoreXmlString, xmlTextResultType);
71
+ properties = doc.getElementsByTagName(docPropsRootElement).item(0);
72
+ if (properties === null) {
73
+ throw new Error("Invalid DocProps core.xml");
74
+ }
75
+ return [2 /*return*/, { doc: doc, properties: properties }];
76
+ }
77
+ });
78
+ }); };
79
+ var getCellReferenceAbsolute = function (col, row) {
48
80
  // 65 is the ascii value of first column 'A'
49
81
  return "$" + String.fromCharCode(col + 65) + "$" + row.toString();
50
82
  };
51
- const getCellReferenceRelative = (col, row) => {
83
+ var getCellReferenceRelative = function (col, row) {
52
84
  // 65 is the ascii value of first column 'A'
53
85
  return String.fromCharCode(col + 65) + row.toString();
54
86
  };
55
- const getTableReference = (numberOfCols, numberOfRows) => {
56
- return `A1:${getCellReferenceRelative(numberOfCols, numberOfRows)}`;
87
+ var getTableReference = function (numberOfCols, numberOfRows) {
88
+ return "A1:".concat(getCellReferenceRelative(numberOfCols, numberOfRows));
57
89
  };
58
- const createCellElement = (doc, colIndex, rowIndex, data) => {
59
- const cell = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.kindCell);
60
- cell.setAttribute(constants_1.elementAttributes.row, getCellReferenceRelative(colIndex, rowIndex + 1));
61
- const cellData = doc.createElementNS(doc.documentElement.namespaceURI, constants_1.element.cellValue);
90
+ var createCellElement = function (doc, colIndex, rowIndex, data) {
91
+ var cell = doc.createElementNS(doc.documentElement.namespaceURI, element.kindCell);
92
+ cell.setAttribute(elementAttributes.row, getCellReferenceRelative(colIndex, rowIndex + 1));
93
+ var cellData = doc.createElementNS(doc.documentElement.namespaceURI, element.cellValue);
62
94
  updateCellData(data, cell, cellData, rowIndex === 0);
63
95
  cell.appendChild(cellData);
64
96
  return cell;
65
97
  };
66
- const updateCellData = (data, cell, cellData, rowHeader) => {
98
+ var updateCellData = function (data, cell, cellData, rowHeader) {
67
99
  switch (resolveType(data, rowHeader)) {
68
- case types_1.DataTypes.string:
69
- cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.string);
100
+ case DataTypes.string:
101
+ cell.setAttribute(element.text, dataTypeKind.string);
70
102
  break;
71
- case types_1.DataTypes.number:
72
- cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.number);
103
+ case DataTypes.number:
104
+ cell.setAttribute(element.text, dataTypeKind.number);
73
105
  break;
74
- case types_1.DataTypes.boolean:
75
- cell.setAttribute(constants_1.element.text, constants_1.dataTypeKind.boolean);
106
+ case DataTypes.boolean:
107
+ cell.setAttribute(element.text, dataTypeKind.boolean);
76
108
  break;
77
109
  }
110
+ if (data.startsWith(" ") || data.endsWith(" ")) {
111
+ cellData.setAttribute(elementAttributes.space, "preserve");
112
+ }
78
113
  cellData.textContent = data;
79
114
  };
80
- const resolveType = (originalData, rowHeader) => {
81
- const data = originalData;
82
- if (rowHeader) {
83
- // Headers should be string by default.
84
- return types_1.DataTypes.string;
115
+ var resolveType = function (originalData, rowHeader) {
116
+ var data = originalData;
117
+ if ((rowHeader) || (data.trim() === "")) {
118
+ // Headers and whitespace should be string by default.
119
+ return DataTypes.string;
85
120
  }
86
- let dataType = isNaN(Number(data)) ? types_1.DataTypes.string : types_1.DataTypes.number;
87
- if (dataType == types_1.DataTypes.string) {
88
- if (data.trim() == constants_1.trueStr || data.trim() == constants_1.falseStr) {
89
- dataType = types_1.DataTypes.boolean;
121
+ var dataType = isNaN(Number(data)) ? DataTypes.string : DataTypes.number;
122
+ if (dataType == DataTypes.string) {
123
+ if (data.trim() == trueStr || data.trim() == falseStr) {
124
+ dataType = DataTypes.boolean;
90
125
  }
91
126
  }
92
127
  return dataType;
93
128
  };
94
- exports.default = {
95
- createOrUpdateProperty,
96
- getDocPropsProperties,
97
- getCellReferenceRelative,
98
- getCellReferenceAbsolute,
129
+ export default {
130
+ createOrUpdateProperty: createOrUpdateProperty,
131
+ getDocPropsProperties: getDocPropsProperties,
132
+ getCellReferenceRelative: getCellReferenceRelative,
133
+ getCellReferenceAbsolute: getCellReferenceAbsolute,
99
134
  createCell: createCellElement,
100
- getTableReference,
101
- resolveType,
135
+ getTableReference: getTableReference,
136
+ updateCellData: updateCellData,
137
+ resolveType: resolveType,
102
138
  };
@@ -1,9 +1,7 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const constants_1 = require("../utils/constants");
6
- const parseToTableData = (grid) => {
3
+ import { arrayIsntMxNErr, defaults, promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr, unexpectedErr } from "../utils/constants";
4
+ var parseToTableData = function (grid) {
7
5
  var _a, _b, _c, _d;
8
6
  if (grid === null || grid === undefined) {
9
7
  grid = { data: [] };
@@ -11,16 +9,16 @@ const parseToTableData = (grid) => {
11
9
  if (grid.data === null || grid.data === undefined) {
12
10
  grid.data = [];
13
11
  }
14
- const mergedGrid = {
12
+ var mergedGrid = {
15
13
  config: {
16
14
  promoteHeaders: (_b = (_a = grid.config) === null || _a === void 0 ? void 0 : _a.promoteHeaders) !== null && _b !== void 0 ? _b : false,
17
15
  adjustColumnNames: (_d = (_c = grid.config) === null || _c === void 0 ? void 0 : _c.adjustColumnNames) !== null && _d !== void 0 ? _d : true,
18
16
  },
19
- data: grid.data.map((row) => row.map((value) => { var _a; return (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : ""; })),
17
+ 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
18
  };
21
19
  correctGrid(mergedGrid);
22
20
  validateGrid(mergedGrid);
23
- let columnNames = [];
21
+ var columnNames = [];
24
22
  if (mergedGrid.config.promoteHeaders && mergedGrid.config.adjustColumnNames) {
25
23
  columnNames = getAdjustedColumnNames(mergedGrid.data.shift());
26
24
  }
@@ -29,23 +27,23 @@ const parseToTableData = (grid) => {
29
27
  columnNames = mergedGrid.data.shift();
30
28
  }
31
29
  else {
32
- columnNames = Array.from({ length: mergedGrid.data[0].length }, (_, index) => `${constants_1.defaults.columnName} ${index + 1}`);
30
+ columnNames = Array.from({ length: mergedGrid.data[0].length }, function (_, index) { return "".concat(defaults.columnName, " ").concat(index + 1); });
33
31
  }
34
32
  return { columnNames: columnNames, rows: mergedGrid.data };
35
33
  };
36
- const correctGrid = (grid) => {
34
+ var correctGrid = function (grid) {
37
35
  if (grid.data.length === 0) {
38
36
  // empty grid fix
39
37
  grid.config.promoteHeaders = false;
40
38
  grid.data.push([""]);
41
39
  return;
42
40
  }
43
- const getEmptyArray = (n) => Array.from({ length: n }, () => "");
41
+ var getEmptyArray = function (n) { return Array.from({ length: n }, function () { return ""; }); };
44
42
  if (grid.data[0].length === 0) {
45
43
  grid.data[0] = [""];
46
44
  }
47
45
  // replace empty rows
48
- grid.data.forEach((row, index) => {
46
+ grid.data.forEach(function (row, index) {
49
47
  if (row.length === 0) {
50
48
  grid.data[index] = getEmptyArray(grid.data[0].length);
51
49
  }
@@ -61,43 +59,43 @@ const correctGrid = (grid) => {
61
59
  * - MxN structure.
62
60
  * - If promoteHeaders is true - has at least 1 row, and in case adjustColumnNames is false, first row is unique and non empty.
63
61
  */
64
- const validateGrid = (grid) => {
62
+ var validateGrid = function (grid) {
65
63
  validateDataArrayDimensions(grid.data);
66
64
  if (grid.config.promoteHeaders && grid.config.adjustColumnNames === false && !validateUniqueAndValidDataArray(grid.data[0])) {
67
- throw new Error(constants_1.promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr);
65
+ throw new Error(promotedHeadersCannotBeUsedWithoutAdjustingColumnNamesErr);
68
66
  }
69
67
  };
70
- const validateDataArrayDimensions = (arr) => {
68
+ var validateDataArrayDimensions = function (arr) {
71
69
  if (arr.length === 0 || arr[0].length === 0) {
72
- throw new Error(constants_1.unexpectedErr);
70
+ throw new Error(unexpectedErr);
73
71
  }
74
- if (!arr.every((innerArr) => innerArr.length === arr[0].length)) {
75
- throw new Error(constants_1.arrayIsntMxNErr);
72
+ if (!arr.every(function (innerArr) { return innerArr.length === arr[0].length; })) {
73
+ throw new Error(arrayIsntMxNErr);
76
74
  }
77
75
  };
78
- const validateUniqueAndValidDataArray = (arr) => {
79
- if (arr.some((element) => element === "")) {
76
+ var validateUniqueAndValidDataArray = function (arr) {
77
+ if (arr.some(function (element) { return element === ""; })) {
80
78
  return false; // Array contains empty elements
81
79
  }
82
- const uniqueSet = new Set(arr);
80
+ var uniqueSet = new Set(arr);
83
81
  return uniqueSet.size === arr.length;
84
82
  };
85
- const getAdjustedColumnNames = (columnNames) => {
83
+ var getAdjustedColumnNames = function (columnNames) {
86
84
  if (columnNames === undefined) {
87
- throw new Error(constants_1.unexpectedErr);
85
+ throw new Error(unexpectedErr);
88
86
  }
89
- let i = 1;
87
+ var i = 1;
90
88
  // replace empty column names with default names, can still conflict if columns exist, but we handle that later
91
- columnNames = columnNames.map((columnName) => columnName || `${constants_1.defaults.columnName} ${i++}`);
92
- const uniqueNames = new Set();
93
- return columnNames.map((name) => {
94
- let uniqueName = name;
89
+ columnNames = columnNames.map(function (columnName) { return columnName || "".concat(defaults.columnName, " ").concat(i++); });
90
+ var uniqueNames = new Set();
91
+ return columnNames.map(function (name) {
92
+ var uniqueName = name;
95
93
  i = 1;
96
94
  while (uniqueNames.has(uniqueName)) {
97
- uniqueName = `${name} (${i++})`;
95
+ uniqueName = "".concat(name, " (").concat(i++, ")");
98
96
  }
99
97
  uniqueNames.add(uniqueName);
100
98
  return uniqueName;
101
99
  });
102
100
  };
103
- exports.default = { parseToTableData };
101
+ export default { parseToTableData: parseToTableData };
@@ -1,19 +1,17 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const extractTableValues = (table) => {
6
- const rows = [];
3
+ var extractTableValues = function (table) {
4
+ var rows = [];
7
5
  // Extract values from each row
8
- for (let i = 0; i < table.rows.length; i++) {
9
- const row = table.rows[i];
10
- const rowData = [];
11
- for (let j = 0; j < row.cells.length; j++) {
12
- const cell = row.cells[j];
6
+ for (var i = 0; i < table.rows.length; i++) {
7
+ var row = table.rows[i];
8
+ var rowData = [];
9
+ for (var j = 0; j < row.cells.length; j++) {
10
+ var cell = row.cells[j];
13
11
  rowData.push(cell.textContent || "");
14
12
  }
15
13
  rows.push(rowData);
16
14
  }
17
15
  return rows;
18
16
  };
19
- exports.default = { extractTableValues };
17
+ export default { extractTableValues: extractTableValues };
@@ -0,0 +1,8 @@
1
+ export { default as pqUtils } from "./pqUtils";
2
+ export { default as arrayUtils } from "./arrayUtils";
3
+ export { default as documentUtils } from "./documentUtils";
4
+ export { default as xmlPartsUtils } from "./xmlPartsUtils";
5
+ export { default as xmlInnerPartsUtils } from "./xmlInnerPartsUtils";
6
+ export { default as tableUtils } from "./tableUtils";
7
+ export { default as htmlUtils } from "./htmlUtils";
8
+ export { default as gridUtils } from "./gridUtils";
@@ -1,24 +1,10 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.gridUtils = exports.htmlUtils = exports.tableUtils = exports.xmlInnerPartsUtils = exports.xmlPartsUtils = exports.documentUtils = exports.arrayUtils = exports.pqUtils = void 0;
9
- var pqUtils_1 = require("./pqUtils");
10
- Object.defineProperty(exports, "pqUtils", { enumerable: true, get: function () { return __importDefault(pqUtils_1).default; } });
11
- var arrayUtils_1 = require("./arrayUtils");
12
- Object.defineProperty(exports, "arrayUtils", { enumerable: true, get: function () { return __importDefault(arrayUtils_1).default; } });
13
- var documentUtils_1 = require("./documentUtils");
14
- Object.defineProperty(exports, "documentUtils", { enumerable: true, get: function () { return __importDefault(documentUtils_1).default; } });
15
- var xmlPartsUtils_1 = require("./xmlPartsUtils");
16
- Object.defineProperty(exports, "xmlPartsUtils", { enumerable: true, get: function () { return __importDefault(xmlPartsUtils_1).default; } });
17
- var xmlInnerPartsUtils_1 = require("./xmlInnerPartsUtils");
18
- Object.defineProperty(exports, "xmlInnerPartsUtils", { enumerable: true, get: function () { return __importDefault(xmlInnerPartsUtils_1).default; } });
19
- var tableUtils_1 = require("./tableUtils");
20
- Object.defineProperty(exports, "tableUtils", { enumerable: true, get: function () { return __importDefault(tableUtils_1).default; } });
21
- var htmlUtils_1 = require("./htmlUtils");
22
- Object.defineProperty(exports, "htmlUtils", { enumerable: true, get: function () { return __importDefault(htmlUtils_1).default; } });
23
- var gridUtils_1 = require("./gridUtils");
24
- Object.defineProperty(exports, "gridUtils", { enumerable: true, get: function () { return __importDefault(gridUtils_1).default; } });
3
+ export { default as pqUtils } from "./pqUtils";
4
+ export { default as arrayUtils } from "./arrayUtils";
5
+ export { default as documentUtils } from "./documentUtils";
6
+ export { default as xmlPartsUtils } from "./xmlPartsUtils";
7
+ export { default as xmlInnerPartsUtils } from "./xmlInnerPartsUtils";
8
+ export { default as tableUtils } from "./tableUtils";
9
+ export { default as htmlUtils } from "./htmlUtils";
10
+ export { default as gridUtils } from "./gridUtils";