UNPKG

kui-shell

Version:

This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool

82 lines 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Row { constructor(row) { Object.assign(this, row); } } exports.Row = Row; class Cell { constructor(cell) { Object.assign(this, cell); } } exports.Cell = Cell; var TableStyle; (function (TableStyle) { TableStyle[TableStyle["Light"] = 0] = "Light"; TableStyle[TableStyle["Medium"] = 1] = "Medium"; TableStyle[TableStyle["Heavy"] = 2] = "Heavy"; })(TableStyle = exports.TableStyle || (exports.TableStyle = {})); class Table { constructor(table) { Object.assign(this, table); } } exports.Table = Table; function isTable(model) { return (model !== undefined && (model instanceof Table || (model.body && Array.isArray(model.body)))); } exports.isTable = isTable; function isMultiTable(model) { return (model !== undefined && model.tables !== undefined && Array.isArray(model.tables) && model.tables.length >= 1 && model.tables.filter(table => !isTable(table)).length === 0); } exports.isMultiTable = isMultiTable; function formatWatchableTable(model, watch) { if (isTable(model) || isMultiTable(model)) { return Object.assign(model, watch); } else { throw new Error('models other than table(s) are not supported in watch mode yet'); } } exports.formatWatchableTable = formatWatchableTable; exports.sortBody = (rows) => { return rows.sort((a, b) => (a.prettyType || a.type || '').localeCompare(b.prettyType || b.type || '') || (a.packageName || '').localeCompare(b.packageName || '') || a.name.localeCompare(b.name)); }; class Icon { constructor(icon) { Object.assign(this, icon); } } exports.Icon = Icon; function diffTableRows(existingRows, refreshRows) { const rowDeletion = existingRows .map((row, index) => { return { deleteIndex: index, model: row }; }) .filter(_ => !refreshRows.find(row => row.name === _.model.name)); const rowUpdate = refreshRows .filter(row => existingRows.some(_ => _.name === row.name)) .map(row => { const index = existingRows.findIndex(_ => _.name === row.name); const doUpdate = JSON.stringify(row) !== JSON.stringify(existingRows[index]); if (doUpdate) return { updateIndex: index, model: row }; }) .filter(x => x); const rowInsertion = exports.sortBody(refreshRows.filter(row => !existingRows.some(_ => _.name === row.name)).concat(existingRows)) .map((row, index) => { return { insertBeforeIndex: index + 1, model: row }; }) .filter(row => !existingRows.some(_ => _.name === row.model.name)); return { rowUpdate, rowDeletion, rowInsertion }; } exports.diffTableRows = diffTableRows; //# sourceMappingURL=table.js.map