UNPKG

@schoolbelle/common

Version:

1,641 lines (1,634 loc) 154 kB
import { ObjectChangeTrackerWithHistory } from '@schoolbelle/common/object-change-tracker'; import { padStart, times, filter, uniq, min, max, intersection, identity, difference, reduce, sortedIndexBy, sortedLastIndexBy, cloneDeep, flatten, defaults } from 'lodash-es'; import { v4 } from 'uuid'; import { EventsService } from '@schoolbelle/common/events'; import { differenceBy, intersectionBy, isEqual, max as max$1, min as min$1, times as times$1 } from 'lodash'; import 'ngx-bootstrap/tooltip'; import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { __spread, __read, __extends, __assign } from 'tslib'; import { Subject, BehaviorSubject, merge, concat, of, Subscription, timer } from 'rxjs'; import { debounceTime, map, switchMap, distinctUntilChanged, filter as filter$1, pairwise, share, startWith, takeUntil, tap } from 'rxjs/operators'; import { Injectable, Directive, Input, ElementRef, NgModule, Component, ChangeDetectorRef, Renderer2, ChangeDetectionStrategy, EventEmitter, ContentChild, TemplateRef, Output, defineInjectable, inject, ViewChild } from '@angular/core'; import { CommonModule } from '@angular/common'; import { VirtualScrollerModule } from 'ngx-virtual-scroller'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var N_DIGIT_NUMBER_OF_CELLS_PER_AXIS = 4; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Cell = /** @class */ (function (_super) { __extends(Cell, _super); function Cell(table, x, y) { var _this = _super.call(this, table, [x + "x" + y]) || this; _this.table = table; _this.x = x; _this.y = y; _this.id = v4(); _this._locked = false; _this.lockedEvent = new Subject(); _this._selected = false; _this.selectedEvent = new Subject(); _this._focused = false; _this.focusedEvent = new Subject(); _this._hovered = false; _this.hoveredEvent = new Subject(); _this._invalid = false; _this.invalidEvent = new Subject(); _this._matched = false; _this.matchedEvent = new Subject(); // this.cord = `${padStart(''+this.x, N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0')}x${padStart(''+this.y, N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0')}`; _this.cord = padStart('' + _this.y, N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0') + "x" + padStart('' + _this.x, N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0'); return _this; } Object.defineProperty(Cell.prototype, "onLocked", { /** * observable that emits the selected state when it's changed */ get: /** * observable that emits the selected state when it's changed * @return {?} */ function () { return this.lockedEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "locked", { /** * whether this cell is locked * if locked, cell value update is disabled. */ get: /** * whether this cell is locked * if locked, cell value update is disabled. * @return {?} */ function () { return this._locked; }, set: /** * @param {?} v * @return {?} */ function (v) { if (this._locked === v) return; this._locked = v; this.lockedEvent.next(v); }, enumerable: true, configurable: true }); /** * @param {?} path * @param {?} value * @param {?=} options * @return {?} */ Cell.prototype.set = /** * @param {?} path * @param {?} value * @param {?=} options * @return {?} */ function (path, value, options) { if (options === void 0) { options = undefined; } if (this.locked) console.debug('Cell is locked.'); else _super.prototype.set.call(this, path, value, options); }; Object.defineProperty(Cell.prototype, "onSelected", { /** * observable that emits the selected state when it's changed */ get: /** * observable that emits the selected state when it's changed * @return {?} */ function () { return this.selectedEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "selected", { /** * whether this cell is selected */ get: /** * whether this cell is selected * @return {?} */ function () { return this._selected; }, set: /** * @param {?} v * @return {?} */ function (v) { this.select(v); }, enumerable: true, configurable: true }); /** * update 'selected' state * @param v */ /** * update 'selected' state * @param {?=} v * @return {?} */ Cell.prototype.select = /** * update 'selected' state * @param {?=} v * @return {?} */ function (v) { if (typeof v === 'undefined') v = !this.selected; if (this._selected !== v) { this._selected = v; this.selectedEvent.next(v); } }; Object.defineProperty(Cell.prototype, "onFocused", { /** * observable that emits the focused state when it's changed */ get: /** * observable that emits the focused state when it's changed * @return {?} */ function () { return this.focusedEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "focused", { /** * whether this cell is focused */ get: /** * whether this cell is focused * @return {?} */ function () { return this._focused; }, set: /** * @param {?} v * @return {?} */ function (v) { this.focus(v); }, enumerable: true, configurable: true }); /** * move focus to this cell * focus(true) will cancel the focused state from the former focused cell. * Only one cell can have focus status. * @param v */ /** * move focus to this cell * focus(true) will cancel the focused state from the former focused cell. * Only one cell can have focus status. * @param {?=} v * @return {?} */ Cell.prototype.focus = /** * move focus to this cell * focus(true) will cancel the focused state from the former focused cell. * Only one cell can have focus status. * @param {?=} v * @return {?} */ function (v) { if (typeof v === 'undefined') v = !this.focused; if (this._focused === v) return; if (v) { /** @type {?} */ var cell_to_cancel_focus = this.table.cells.find((/** * @param {?} c * @return {?} */ function (c) { return c.focused; })); if (cell_to_cancel_focus) cell_to_cancel_focus.focus(false); } this._focused = v; this.focusedEvent.next(v); }; Object.defineProperty(Cell.prototype, "onHovered", { /** * observable that emits the hovered state when it's changed */ get: /** * observable that emits the hovered state when it's changed * @return {?} */ function () { return this.hoveredEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "hovered", { /** * whether this cell is being hovered */ get: /** * whether this cell is being hovered * @return {?} */ function () { return this._hovered; }, set: /** * @param {?} v * @return {?} */ function (v) { this.hover(v); }, enumerable: true, configurable: true }); /** * toggle hovered state of this cell * @param v */ /** * toggle hovered state of this cell * @param {?=} v * @return {?} */ Cell.prototype.hover = /** * toggle hovered state of this cell * @param {?=} v * @return {?} */ function (v) { if (typeof v === 'undefined') v = !this.hovered; if (this._hovered !== v) { this._hovered = v; this.hoveredEvent.next(v); } }; Object.defineProperty(Cell.prototype, "onInvalid", { /** * observable that emits the invalid state when it's changed */ get: /** * observable that emits the invalid state when it's changed * @return {?} */ function () { return this.invalidEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "invalid", { get: /** * @return {?} */ function () { return this._invalid; }, set: /** * @param {?} v * @return {?} */ function (v) { if (this._invalid !== v) { this._invalid = v; this.invalidEvent.next(v); } }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "onMatched", { /** * observable that emits the matched state when it's changed */ get: /** * observable that emits the matched state when it's changed * @return {?} */ function () { return this.matchedEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "matched", { get: /** * @return {?} */ function () { return this._matched; }, set: /** * @param {?} v * @return {?} */ function (v) { if (this._matched !== v) { this._matched = v; this.matchedEvent.next(v); } }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "changed", { get: /** * @return {?} */ function () { return this.getChildTracker('val').isChanged; }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "isChanged", { /** * shadow parent's property. */ get: /** * shadow parent's property. * @return {?} */ function () { return this.changed; }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "onChanged", { get: /** * @return {?} */ function () { return this.getChildTracker('val').onContentUpdate; }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "val", { /** * Excel cell contains val, style, fomula, format...etc * currently only val property is supported. */ get: /** * Excel cell contains val, style, fomula, format...etc * currently only val property is supported. * @return {?} */ function () { return this.get('val'); }, set: /** * @param {?} v * @return {?} */ function (v) { this.set('val', v); }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "col", { get: /** * @return {?} */ function () { return this.table.cols[this.x]; }, enumerable: true, configurable: true }); Object.defineProperty(Cell.prototype, "row", { get: /** * @return {?} */ function () { return this.table.rows[this.y]; }, enumerable: true, configurable: true }); return Cell; }(ObjectChangeTrackerWithHistory)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Shared = /** @class */ (function () { function Shared() { var _this = this; this.id = v4(); /** * whether this col is hidden or not */ this._hidden = false; this.hiddenEvent = new Subject(); this.onSizeChange = new BehaviorSubject(null); this.onSelected = (/** @type {?} */ (this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onSelected; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.selected; }))))); this.onInvalid = (/** @type {?} */ (this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onInvalid; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.invalid; }))))); this.onChanged = (/** @type {?} */ (this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onChanged; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.changed; }))))); this.onHovered = (/** @type {?} */ (this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onHovered; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.hovered; }))))); this.onMatched = (/** @type {?} */ (this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onMatched; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.matched; }))))); } Object.defineProperty(Shared.prototype, "onHidden", { get: /** * @return {?} */ function () { return this.hiddenEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "hidden", { get: /** * @return {?} */ function () { return this._hidden; }, set: /** * @param {?} v * @return {?} */ function (v) { if (this._hidden === v) return; this._hidden = v; this.hiddenEvent.next(v); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "cells", { /** * get all cells in the column. */ get: /** * get all cells in the column. * @return {?} */ function () { return []; }, enumerable: true, configurable: true }); /** * @protected * @param {?} list * @return {?} */ Shared.prototype.compressCells = /** * @protected * @param {?} list * @return {?} */ function (list) { if (this.cells.length === 0 || list.length === 0) return []; else if (this.cells.length !== list.length) return (/** @type {?} */ (list)); else return [(/** @type {?} */ (this))]; }; Object.defineProperty(Shared.prototype, "selected", { get: /** * @return {?} */ function () { return this.compressCells(this.cells.filter((/** * @param {?} c * @return {?} */ function (c) { return c.selected; }))); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "hovered", { get: /** * @return {?} */ function () { return this.compressCells(this.cells.filter((/** * @param {?} c * @return {?} */ function (c) { return c.hovered; }))); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "invalid", { get: /** * @return {?} */ function () { return this.compressCells(this.cells.filter((/** * @param {?} c * @return {?} */ function (c) { return c.invalid; }))); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "changed", { get: /** * @return {?} */ function () { return this.compressCells(this.cells.filter((/** * @param {?} c * @return {?} */ function (c) { return c.changed; }))); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "matched", { get: /** * @return {?} */ function () { return this.compressCells(this.cells.filter((/** * @param {?} c * @return {?} */ function (c) { return c.matched; }))); }, enumerable: true, configurable: true }); Object.defineProperty(Shared.prototype, "isChanged", { /** * for compatibility */ get: /** * for compatibility * @return {?} */ function () { return this.changed; }, enumerable: true, configurable: true }); /** * @param {?=} bool * @return {?} */ Shared.prototype.select = /** * @param {?=} bool * @return {?} */ function (bool) { if (typeof bool === 'undefined') bool = this.selected[0] !== this; this.cells.forEach((/** * @param {?} c * @return {?} */ function (c) { return c.selected = bool; })); }; /** * @param {?=} bool * @return {?} */ Shared.prototype.hover = /** * @param {?=} bool * @return {?} */ function (bool) { if (typeof bool === 'undefined') bool = this.hovered[0] !== this; this.cells.forEach((/** * @param {?} c * @return {?} */ function (c) { return c.hovered = bool; })); }; return Shared; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Row = /** @class */ (function (_super) { __extends(Row, _super); function Row(table, y) { var _this = _super.call(this) || this; _this.table = table; _this.y = y; _this.onSizeChange = _this.table.onSizeChange.pipe(distinctUntilChanged((/** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { return a.x === b.x; }))); _this.cord = padStart('' + _this.y, N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0') + "x" + padStart('-1', N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0'); return _this; } Object.defineProperty(Row.prototype, "x", { get: /** * @return {?} */ function () { return this.table.x; }, enumerable: true, configurable: true }); Object.defineProperty(Row.prototype, "cells", { /** * get all cells in this row */ get: /** * get all cells in this row * @return {?} */ function () { return this.table.getCells(undefined, this.y); }, enumerable: true, configurable: true }); return Row; }(Shared)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Col = /** @class */ (function (_super) { __extends(Col, _super); function Col(table, x) { var _this = _super.call(this) || this; _this.table = table; _this.x = x; _this.onSizeChange = _this.table.onSizeChange.pipe(distinctUntilChanged((/** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { return a.y === b.y; }))); _this.cord = padStart('-1', N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0') + "x" + padStart('' + _this.x, N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0'); return _this; } Object.defineProperty(Col.prototype, "y", { /** * length of this col */ get: /** * length of this col * @return {?} */ function () { return this.table.y; }, enumerable: true, configurable: true }); Object.defineProperty(Col.prototype, "cells", { /** * get all cells in the column. */ get: /** * get all cells in the column. * @return {?} */ function () { return this.table.getCells(this.x); }, enumerable: true, configurable: true }); return Col; }(Shared)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Utlities = /** @class */ (function () { function Utlities() { } //addToSelectedArea //addToSelectedArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @return {?} */ Utlities.addToSelectedArea = //addToSelectedArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @return {?} */ function (areaA, areaB, x, y) { /** @type {?} */ var areaAMinCompressionDepth = this.getCompressionDepth(areaA, 'min'); /** @type {?} */ var areaBMinCompressionDepth = this.getCompressionDepth(areaB, 'min'); /** @type {?} */ var commonMinCompressionDepth = areaAMinCompressionDepth <= areaBMinCompressionDepth ? areaAMinCompressionDepth : areaBMinCompressionDepth; /** @type {?} */ var neededDecompressionDepth = (/** @type {?} */ ((3 - commonMinCompressionDepth))); /** @type {?} */ var decompressedAreaA = this.decompressSelectedArea(areaA, x, y, neededDecompressionDepth).split(','); /** @type {?} */ var decompressedAreaB = this.decompressSelectedArea(areaB, x, y, neededDecompressionDepth).split(','); return this.compressSelectedArea(decompressedAreaA.concat(decompressedAreaB).join(','), x, y); }; //compressSelectedArea //compressSelectedArea /** * @param {?=} spread_area * @param {?=} x * @param {?=} y * @param {?=} depth * @return {?} */ Utlities.compressSelectedArea = //compressSelectedArea /** * @param {?=} spread_area * @param {?=} x * @param {?=} y * @param {?=} depth * @return {?} */ function (spread_area, x, y, depth) { if (spread_area === void 0) { spread_area = ''; } if (depth === void 0) { depth = 3; } switch (depth) { case 3: // spread_area = this.compressSelectedAreaFromCellsToRows(spread_area, x, y); // spread_area = this.compressSelectedAreaFromCellsToCols(spread_area, x, y); spread_area = this.compressSelectedAreaFromCellsToCols(spread_area, x, y); spread_area = this.compressSelectedAreaFromCellsToRows(spread_area, x, y); spread_area = this.compressSelectedAreaFromColsAndRowsToTable(spread_area, x, y); case 2: spread_area = this.compressSelectedAreaFromCellsToCols(spread_area, x, y); spread_area = this.compressSelectedAreaFromCellsToRows(spread_area, x, y); break; case 1: spread_area = this.compressSelectedAreaFromCellsToRows(spread_area, x, y); break; } return spread_area; }; /** * @param {?} spread_area * @param {?} x * @param {?} y * @return {?} */ Utlities.compressSelectedAreaFromColsAndRowsToTable = /** * @param {?} spread_area * @param {?} x * @param {?} y * @return {?} */ function (spread_area, x, y) { /** @type {?} */ var area = uniq(filter(spread_area.split(','), (/** * @param {?} scope * @return {?} */ function (scope) { return scope; }))); /** @type {?} */ var col_area = times(x, (/** * @param {?} i * @return {?} */ function (i) { return "col_" + (i + 1); })); /** @type {?} */ var row_area = times(y, (/** * @param {?} i * @return {?} */ function (i) { return "row_" + (i + 1); })); if (col_area.length !== 0 && filter(col_area, (/** * @param {?} col_scope * @return {?} */ function (col_scope) { return area.indexOf(col_scope) !== -1; })) .length === col_area.length) { area = ['all']; } else if (row_area.length !== 0 && filter(row_area, (/** * @param {?} row_scope * @return {?} */ function (row_scope) { return area.indexOf(row_scope) !== -1; })) .length === row_area.length) { area = ['all']; } return uniq(area).join(','); }; /** * @param {?} spread_area * @param {?} x * @param {?} y * @return {?} */ Utlities.compressSelectedAreaFromCellsToCols = /** * @param {?} spread_area * @param {?} x * @param {?} y * @return {?} */ function (spread_area, x, y) { /** @type {?} */ var area = uniq(spread_area.split(',').filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope; }))); // to cols times(x, (/** * @param {?} i * @return {?} */ function (i) { /** @type {?} */ var cell_in_col_regex = new RegExp("^col_" + (i + 1) + "_of_row_[\\d]+$"); /** @type {?} */ var cell_cnt = area.filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope.match(cell_in_col_regex); })) .length; if (cell_cnt !== 0 && cell_cnt === y) { area = area.filter((/** * @param {?} scope * @return {?} */ function (scope) { return !scope.match(cell_in_col_regex); })); area.push("col_" + (i + 1)); } })); return uniq(area).join(','); }; /** * @param {?} spread_area * @param {?} x * @param {?} y * @return {?} */ Utlities.compressSelectedAreaFromCellsToRows = /** * @param {?} spread_area * @param {?} x * @param {?} y * @return {?} */ function (spread_area, x, y) { /** @type {?} */ var area = uniq(spread_area.split(',').filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope; }))); // to rows times(y, (/** * @param {?} i * @return {?} */ function (i) { /** @type {?} */ var cell_in_row_regrex = new RegExp("^col_[\\d]+_of_row_" + (i + 1) + "$"); /** @type {?} */ var cell_cnt = filter(area, (/** * @param {?} scope * @return {?} */ function (scope) { return scope.match(cell_in_row_regrex); })).length; if (cell_cnt !== 0 && cell_cnt === x) { area = filter(area, (/** * @param {?} scope * @return {?} */ function (scope) { return !scope.match(cell_in_row_regrex); })); area.push("row_" + (i + 1)); } })); return uniq(area).join(','); }; //decompressSelectedArea //decompressSelectedArea /** * @param {?=} compressed_area * @param {?=} x * @param {?=} y * @param {?=} depth * @return {?} */ Utlities.decompressSelectedArea = //decompressSelectedArea /** * @param {?=} compressed_area * @param {?=} x * @param {?=} y * @param {?=} depth * @return {?} */ function (compressed_area, x, y, depth) { if (compressed_area === void 0) { compressed_area = ''; } if (depth === void 0) { depth = 3; } switch (depth) { case 3: // to cell compressed_area = this.decompressSelectedAreaFromTableToCols(compressed_area, x); compressed_area = this.decompressSelectedAreaFromColsToCells(compressed_area, y); compressed_area = this.decompressSelectedAreaFromRowsToCells(compressed_area, x); case 2: // to row compressed_area = this.decompressSelectedAreaFromTableToRows(compressed_area, y); break; case 1: // to col compressed_area = this.decompressSelectedAreaFromTableToCols(compressed_area, x); break; } return compressed_area; }; /** * @param {?} compressed_area * @param {?} x * @return {?} */ Utlities.decompressSelectedAreaFromRowsToCells = /** * @param {?} compressed_area * @param {?} x * @return {?} */ function (compressed_area, x) { var _this = this; /** @type {?} */ var area = compressed_area.split(',').filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope; })); area = area.map((/** * @param {?} scope * @return {?} */ function (scope) { /** @type {?} */ var match; // decompress row into cells if ((match = scope.match(_this.row_area_reg))) { // parent row selection return times(x, (/** * @param {?} i * @return {?} */ function (i) { return "col_" + (i + 1) + "_of_row_" + match[1]; })).join(','); } else { return scope; } })); return filter(uniq(area), (/** * @param {?} area * @return {?} */ function (area) { return area; })).join(','); }; /** * @param {?} compressed_area * @param {?} y * @return {?} */ Utlities.decompressSelectedAreaFromColsToCells = /** * @param {?} compressed_area * @param {?} y * @return {?} */ function (compressed_area, y) { var _this = this; /** @type {?} */ var area = compressed_area.split(',').filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope; })); area = area.map((/** * @param {?} scope * @return {?} */ function (scope) { /** @type {?} */ var match; // decompress col into cells if ((match = scope.match(_this.col_area_reg))) { // col selection return times(y, (/** * @param {?} i * @return {?} */ function (i) { return "col_" + match[1] + "_of_row_" + (i + 1); })).join(','); } else { return scope; } })); return filter(uniq(area), (/** * @param {?} area * @return {?} */ function (area) { return area; })).join(','); }; /** * @param {?} compressed_area * @param {?} x * @return {?} */ Utlities.decompressSelectedAreaFromTableToCols = /** * @param {?} compressed_area * @param {?} x * @return {?} */ function (compressed_area, x) { var _this = this; /** @type {?} */ var area = compressed_area.split(',').filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope; })); area = area.map((/** * @param {?} scope * @return {?} */ function (scope) { /** @type {?} */ var match; if ((match = scope.match(_this.table_all_area_reg))) { // all selection return times(x, (/** * @param {?} i * @return {?} */ function (i) { return "col_" + (i + 1); })).join(','); } else { return scope; } })); return filter(uniq(area), (/** * @param {?} area * @return {?} */ function (area) { return area; })).join(','); }; /** * @param {?} compressed_area * @param {?} y * @return {?} */ Utlities.decompressSelectedAreaFromTableToRows = /** * @param {?} compressed_area * @param {?} y * @return {?} */ function (compressed_area, y) { var _this = this; /** @type {?} */ var area = compressed_area.split(',').filter((/** * @param {?} scope * @return {?} */ function (scope) { return scope; })); area = area.map((/** * @param {?} scope * @return {?} */ function (scope) { /** @type {?} */ var match; if ((match = scope.match(_this.table_all_area_reg))) { // all selection return times(y, (/** * @param {?} i * @return {?} */ function (i) { return "row_" + (i + 1); })).join(','); } else { return scope; } })); return filter(uniq(area), (/** * @param {?} area * @return {?} */ function (area) { return area; })).join(','); }; //getCompressionDepth //getCompressionDepth /** * @param {?=} area * @param {?=} type * @return {?} */ Utlities.getCompressionDepth = //getCompressionDepth /** * @param {?=} area * @param {?=} type * @return {?} */ function (area, type) { var _this = this; if (area === void 0) { area = ''; } if (type === void 0) { type = 'max'; } /** @type {?} */ var depths = area.split(',').map((/** * @param {?} scope * @return {?} */ function (scope) { if (scope.match(_this.table_area_reg)) return 3; else if (scope.match(_this.col_area_reg)) return 2; else if (scope.match(_this.row_area_reg)) return 1; else if (scope.match(_this.cell_area_reg)) return 0; else return undefined; })); if (type === 'max') { return max(depths); } else { return min(depths); } }; //hasInSelectedArea //hasInSelectedArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @return {?} */ Utlities.hasInSelectedArea = //hasInSelectedArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @return {?} */ function (areaA, areaB, x, y) { /** @type {?} */ var intersect = []; /** @type {?} */ var decompressedAreaA; /** @type {?} */ var decompressedAreaB; /** @type {?} */ var scopeAMinCompressionDepth = this.getCompressionDepth(areaA, 'min'); /** @type {?} */ var scopeBMinCompressionDepth = this.getCompressionDepth(areaB, 'min'); /** @type {?} */ var commonMinCompressionDepth = scopeAMinCompressionDepth <= scopeBMinCompressionDepth ? scopeAMinCompressionDepth : scopeBMinCompressionDepth; /** @type {?} */ var neededDecompressionDepth = (/** @type {?} */ ((3 - commonMinCompressionDepth))); decompressedAreaA = filter(this.decompressSelectedArea(areaA, x, y, neededDecompressionDepth).split(','), identity); decompressedAreaB = filter(this.decompressSelectedArea(areaB, x, y, neededDecompressionDepth).split(','), identity); intersect = intersection(decompressedAreaA, decompressedAreaB); return intersect.length === 0 ? 0 : intersect.length !== decompressedAreaA.length ? 1 : 2; }; //removeFromSelectedArea //removeFromSelectedArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @return {?} */ Utlities.removeFromSelectedArea = //removeFromSelectedArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @return {?} */ function (areaA, areaB, x, y) { /** @type {?} */ var areaAMinCompressionDepth = this.getCompressionDepth(areaA, 'min'); /** @type {?} */ var areaBMinCompressionDepth = this.getCompressionDepth(areaB, 'min'); /** @type {?} */ var commonMinCompressionDepth = areaAMinCompressionDepth <= areaBMinCompressionDepth ? areaAMinCompressionDepth : areaBMinCompressionDepth; /** @type {?} */ var neededDecompressionDepth = (/** @type {?} */ ((3 - commonMinCompressionDepth))); /** @type {?} */ var decompressedAreaA = this.decompressSelectedArea(areaA, x, y, neededDecompressionDepth).split(','); /** @type {?} */ var decompressedAreaB = this.decompressSelectedArea(areaB, x, y, neededDecompressionDepth).split(','); return this.compressSelectedArea(difference(decompressedAreaB, decompressedAreaA).join(','), x, y); }; //toggleArea //toggleArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @param {?=} bool * @return {?} */ Utlities.toggleArea = //toggleArea /** * @param {?} areaA * @param {?} areaB * @param {?} x * @param {?} y * @param {?=} bool * @return {?} */ function (areaA, areaB, x, y, bool) { if (bool === void 0) { bool = undefined; } if (typeof bool === 'undefined') bool = this.hasInSelectedArea(areaA, areaB, x, y) !== 2; // if (bool === true) return this.addToSelectedArea(areaA, areaB, x, y); // else return this.removeFromSelectedArea(areaA, areaB, x, y); /** @type {?} */ var area; if (bool === true) area = this.addToSelectedArea(areaA, areaB, x, y); else area = this.removeFromSelectedArea(areaA, areaB, x, y); return this.compressSelectedArea(area, x, y); }; //regular-expressions Utlities.table_all_area_reg = "^all$"; Utlities.table_area_reg = "^\(all\|\)$"; Utlities.col_area_reg = "^col_\(\[\\d\]\+\)$"; Utlities.row_area_reg = "^row_\(\[\\d\]\+\)$"; Utlities.cell_area_reg = "^col_\(\[\\d\]\+\)_of_row_\(\[\\d\]\+\)$"; return Utlities; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Table = /** @class */ (function (_super) { __extends(Table, _super); function Table() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.id = v4(); _this.cord = padStart('-1', N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0') + "x" + padStart('-1', N_DIGIT_NUMBER_OF_CELLS_PER_AXIS, '0'); _this.cells = []; _this.rows = []; _this.cols = []; _this._x = 0; _this._y = 0; _this.sizeChangeEvent = new BehaviorSubject({ x: _this.x, y: _this.y }); _this.onSelected = (/** @type {?} */ (_this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onSelected; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.selected; }))))); _this.onInvalid = (/** @type {?} */ (_this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onInvalid; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.invalid; }))))); _this.onChanged = (/** @type {?} */ (_this.onContentUpdate.pipe(map((/** * @return {?} */ function () { return _this.changed; }))))); _this.onHovered = (/** @type {?} */ (_this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onHovered; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.hovered; }))))); _this.onMatched = (/** @type {?} */ (_this.onSizeChange.pipe(switchMap((/** * @return {?} */ function () { return merge.apply(void 0, __spread(_this.cells.map((/** * @param {?} c * @return {?} */ function (c) { return c.onMatched; })))); })), debounceTime(0), map((/** * @return {?} */ function () { return _this.matched; }))))); return _this; } Object.defineProperty(Table.prototype, "onSizeChange", { get: /** * @return {?} */ function () { return this.sizeChangeEvent.asObservable(); }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "x", { /** * get x length of the table */ get: /** * get x length of the table * @return {?} */ function () { return this.cols.filter((/** * @param {?} c * @return {?} */ function (c) { return !c.hidden; })).length; // return this._x; }, set: /** * @param {?} v_n * @return {?} */ function (v_n) { this.setX(v_n, { notifyResize: true, updateDiff: true, saveToHistory: true }); }, enumerable: true, configurable: true }); /** * external cord does not take into consideration the hidden cols and rows * while internal one does. * @param x * @param y */ /** * external cord does not take into consideration the hidden cols and rows * while internal one does. * @private * @param {?=} external_x * @param {?=} external_y * @return {?} */ Table.prototype.translateExternalCordIntoInternalCord = /** * external cord does not take into consideration the hidden cols and rows * while internal one does. * @private * @param {?=} external_x * @param {?=} external_y * @return {?} */ function (external_x, external_y) { var _this = this; /** @type {?} */ var internal_x; /** @type {?} */ var internal_y; if (external_x !== undefined) { /** * if cols' visiblities are like these : * * visibility : o x o o o o * internal index : 0 1 2 3 4 5 .... * external index : 0 - 1 2 3 4 .... * * external 3 to in * calculation : * external 3 will be intermal 5 */ internal_x = -1; times(external_x + 1).forEach((/** * @return {?} */ function () { internal_x++; while (_this.cols[internal_x] && _this.cols[internal_x].hidden) { internal_x++; } })); } if (external_y !== undefined) { internal_y = -1; times(external_y + 1).forEach((/** * @return {?} */ function () { internal_y++; while (_this.rows[internal_y] && _this.rows[internal_y].hidden) { internal_y++; } })); } return [internal_x, internal_y]; }; /** * @param {?} v_n * @param {?=} opts * @return {?} */ Table.prototype.setX = /** * @param {?} v_n * @param {?=} opts * @return {?} */ function (v_n, opts) { var _this = this; opts = defaults(opts, { notifyResize: false, updateDiff: false, saveToHistory: false }); // if 7 is given when there are 3 hidden columns, it should increas to 10 columns; v_n = this.translateExternalCordIntoInternalCord(v_n)[0]; /** @type {?} */ var v_o = this._x; /** @type {?} */ var diff = v_n - v_o; if (diff === 0) return; else { if (diff > 0) { //startswith => see if string starts with given option... startswith('abc', 'a')=> true... //times => its like for loop... times(index, thing for repeat...) times(diff, (/** * @param {?} i * @return {?} */ function (i) { return _this.createColumn(i + v_o); })); } else if (diff < 0) { //abs => returns absolute... times(Math.abs(diff), (/** * @param {?} i * @return {?} */ function (i) { return _this.deleteColumn(i + v_n); })); } this._x = v_n; if (opts.notifyResize) this.sizeChangeEvent.next({ x: this.x, y: this.y }); if (opts.updateDiff) this.updateDiff(); if (opts.saveToHistory) this.save(); } }; Object.defineProperty(Table.prototype, "y", { /** * get y length of the table */ get: /** * get y length of the table * @return {?} */ function () { return this._y; }, set: /** * @param {?} v_n * @return {?} */ function (v_n) { this.setY(v_n, { notifyResize: true, updateDiff: true, saveToHistory: true }); }, enumerable: true, configurable: true }); /** * @param {?} v_n * @param {?=} opts * @return {?} */ Table.prototype.setY = /** * @param {?} v_n * @param {?=} opts * @return {?} */ function (v_n, opts) { var _this = this; opts = defaults(opts, { notifyResize: false, updateDiff: false, saveToHistory: false }); // see setX v_n = this.translateExternalCordIntoInternalCord(undefined, v_n)[1]; /** @type {?} */ var v_o = this._y; /** @type {?} */ var diff = v_n - v_o; if (diff === 0) return; else { if (diff > 0) { times(diff, (/** * @param {?} i * @return {?} */ function (i) { return _this.createRow(i + v_o); })); } e