@platform/cell.typesystem
Version:
The 'strongly typed sheets' system of the CellOS.
48 lines (47 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectToCells = void 0;
var tslib_1 = require("tslib");
var common_1 = require("../common");
var TypeTarget_1 = require("../TypeSystem.core/TypeTarget");
function objectToCells(input) {
var types = Array.isArray(input) ? input : (input === null || input === void 0 ? void 0 : input.columns) || [];
var api = {
row: function (index, data) {
var cells = {};
Object.keys(data)
.map(function (key) {
var value = data[key];
var type = types.find(function (type) { return type.prop === key; });
return { key: key, value: value, type: type };
})
.filter(function (_a) {
var type = _a.type;
return Boolean(type);
})
.forEach(function (_a) {
var value = _a.value, type = _a.type;
var target = TypeTarget_1.TypeTarget.parse(type.target);
var cell = {};
if (target.path === 'value') {
cell.value = value;
}
if (target.path.startsWith('props:')) {
var path = target.path.substring('props:'.length);
cell.props = cell.props || {};
cell.props[path] = value;
}
var pos = common_1.coord.cell.toCell("" + type.column + (index + 1));
cells[pos.key] = cell;
});
return cells;
},
rows: function (index, items) {
var cells = {};
(items || []).forEach(function (item, i) { return (cells = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, cells), api.row(index + i, item))); });
return cells;
},
};
return api;
}
exports.objectToCells = objectToCells;