@lightweightform/theme-common
Version:
Common utilities for Lightweightform themes
1,063 lines (1,051 loc) • 50.6 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('mobx'), require('mobx-angular'), require('@lightweightform/storage')) :
typeof define === 'function' && define.amd ? define('@lightweightform/theme-common', ['exports', '@angular/common', '@angular/core', 'mobx', 'mobx-angular', '@lightweightform/storage'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lightweightform = global.lightweightform || {}, global.lightweightform["theme-common"] = {}), global.ng.common, global.ng.core, global.mobx, global["mobx-angular"], global.lightweightform.storage));
})(this, (function (exports, common, i0, mobx, mobxAngular, storage) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
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;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
/**
* Class that represents a container of columns: super class of both the table
* header and of the column (which may have sub-columns as children).
*/
// tslint:disable-next-line: directive-class-suffix
var TableColumnContainer = /** @class */ (function () {
function TableColumnContainer(parentTableColumnContainer, elementRef) {
Object.defineProperty(this, "parentTableColumnContainer", {
enumerable: true,
configurable: true,
writable: true,
value: parentTableColumnContainer
});
Object.defineProperty(this, "elementRef", {
enumerable: true,
configurable: true,
writable: true,
value: elementRef
});
Object.defineProperty(this, "_childrenColumns", {
enumerable: true,
configurable: true,
writable: true,
value: mobxAngular.observable.array()
});
mobx.makeObservable(this);
}
Object.defineProperty(TableColumnContainer.prototype, "childrenColumns", {
/**
* List of column controllers that are direct children of this table column
* container.
* @returns List of column children.
*/
get: function () {
return this._childrenColumns.slice();
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableColumnContainer.prototype, "height", {
/**
* Height of a column container (height of the tree represented by the column
* container as root, and its columns as children).
* @returns Height of the column container.
*/
get: function () {
return (this._childrenColumns.reduce(function (height, column) { return Math.max(height, column.height); }, 0) + 1);
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableColumnContainer.prototype, "width", {
/**
* Width of a column container (width of the tree represented by the column
* container as root, and its columns as children).
* @returns Width of the column container.
*/
get: function () {
// Use the `colspan` of a leaf column as its width
return this instanceof TableColumnDirective &&
this.childrenColumns.length === 0
? this.colspan != null
? +this.colspan
: 1
: this._childrenColumns.reduce(function (sum, column) { return sum + column.width; }, 0);
},
enumerable: false,
configurable: true
});
TableColumnContainer.prototype.ngOnInit = function () {
// Register column in parent column container in same order as declared
if (this.parentTableColumnContainer) {
var childrenColumns = this.parentTableColumnContainer._childrenColumns;
// Find the index of the column which has an index in the parent container
// greater than this column and insert this column before it; if no such
// column is found, insert this column at the end
var indexInParentEl = this.columnIndexInParentEl();
var insertionIndex = -1;
for (var i = 0, l = childrenColumns.length; i < l; ++i) {
if (this.columnIndexInParentEl(childrenColumns[i]) > indexInParentEl) {
insertionIndex = i;
break;
}
}
if (insertionIndex === -1) {
childrenColumns.push(this);
}
else {
childrenColumns.splice(insertionIndex, 0, this);
}
}
};
TableColumnContainer.prototype.ngOnDestroy = function () {
// Unregister column
if (this.parentTableColumnContainer) {
this.parentTableColumnContainer._childrenColumns.splice(this.parentTableColumnContainer._childrenColumns.indexOf(this), 1);
}
};
/**
* Index of the column's element in the parent container's element. Used to
* make sure that we're inserting columns in the order declared in the HTML
* file (needed when conditionally rendering columns).
* @param column Column for which to get index.
* @returns Index of column in parent container's element.
*/
TableColumnContainer.prototype.columnIndexInParentEl = function (column) {
if (column === void 0) { column = this; }
return Array.from(column.parentTableColumnContainer.elementRef.nativeElement.children).indexOf(column.elementRef.nativeElement);
};
return TableColumnContainer;
}());
Object.defineProperty(TableColumnContainer, "\u0275fac", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TableColumnContainer, deps: [{ token: TableColumnContainer }, { token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Directive })
});
Object.defineProperty(TableColumnContainer, "\u0275dir", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: TableColumnContainer, ngImport: i0__namespace })
});
__decorate([
mobxAngular.computed
], TableColumnContainer.prototype, "childrenColumns", null);
__decorate([
mobxAngular.computed
], TableColumnContainer.prototype, "height", null);
__decorate([
mobxAngular.computed
], TableColumnContainer.prototype, "width", null);
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TableColumnContainer, decorators: [{
type: i0.Directive
}], ctorParameters: function () { return [{ type: TableColumnContainer }, { type: i0__namespace.ElementRef }]; }, propDecorators: { childrenColumns: [], height: [], width: [] } });
/**
* Directive representing a table column (which may have sub-columns). Leaf
* columns (columns with no sub-columns) may specify `minWidth` and `fixed` to
* impose sizing restrictions on their respective table columns.
*/
var TableColumnDirective = /** @class */ (function (_super) {
__extends(TableColumnDirective, _super);
function TableColumnDirective(parentTableColumnContainer, elementRef) {
if (parentTableColumnContainer === void 0) { parentTableColumnContainer = null; }
var _this = _super.call(this, parentTableColumnContainer, elementRef) || this;
Object.defineProperty(_this, "elementRef", {
enumerable: true,
configurable: true,
writable: true,
value: elementRef
});
/**
* Identifier of this column (used, for example, to set a label on the
* respective table-header cell).
*/
Object.defineProperty(_this, "id", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/**
* Colspan of the column; this binding only has an effect if the column is a
* leaf column.
*/
Object.defineProperty(_this, "colspan", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/**
* Minimum width of a column (in pixels); this binding is only relevant when
* applied to leaf columns. Note that the actual width of a column will be
* relative the minimum width of all other columns; as an example a column
* with a `minWidth` of `200` should always be twice as large as a column with
* a `minWidth` of `100`.
*
* An array may be provided (with a length matching `colspan`) to specify the
* `minWidth` of each column that this column spans over.
*/
Object.defineProperty(_this, "minWidth", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/**
* `fixed` columns have their width set to `minWidth` and their width won't
* ever vary.
*/
Object.defineProperty(_this, "fixed", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
mobx.makeObservable(_this);
return _this;
}
Object.defineProperty(TableColumnDirective.prototype, "rowSpan", {
/**
* `rowSpan` that should be set on the header table cell that represents this
* column.
* @returns`rowSpan` of the cell representing this column.
*/
get: function () {
// Iterate until `columnContainer` is a `TableHeaderDirective` and
// `rowIndex` represents the index of the header row (`<tr>`) to which the
// cell (`<th>`) representing this column belongs
var columnContainer;
var rowIndex = 0;
for (columnContainer = this.parentTableColumnContainer; columnContainer.parentTableColumnContainer; columnContainer = columnContainer.parentTableColumnContainer) {
++rowIndex;
}
return this.height > 1 ? 1 : columnContainer.numberOfRows - rowIndex;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableColumnDirective.prototype, "colSpan", {
/**
* `colSpan` that should be set on the header table cell that represents this
* column.colSpan
* @returns `colSpan` of the cell representing this column.
*/
get: function () {
return this.width;
},
enumerable: false,
configurable: true
});
return TableColumnDirective;
}(TableColumnContainer));
Object.defineProperty(TableColumnDirective, "\u0275fac", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TableColumnDirective, deps: [{ token: TableColumnContainer, skipSelf: true }, { token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Directive })
});
Object.defineProperty(TableColumnDirective, "\u0275dir", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: TableColumnDirective, selector: "lf-table-column, [lfTableColumn]", inputs: { id: "id", colspan: "colspan", minWidth: "minWidth", fixed: "fixed" }, providers: [
{ provide: TableColumnContainer, useExisting: TableColumnDirective },
], exportAs: ["lfTableColumn"], usesInheritance: true, ngImport: i0__namespace })
});
__decorate([
mobxAngular.observable
], TableColumnDirective.prototype, "id", void 0);
__decorate([
mobxAngular.observable
], TableColumnDirective.prototype, "colspan", void 0);
__decorate([
mobxAngular.observable
], TableColumnDirective.prototype, "minWidth", void 0);
__decorate([
mobxAngular.observable
], TableColumnDirective.prototype, "fixed", void 0);
__decorate([
mobxAngular.computed
], TableColumnDirective.prototype, "rowSpan", null);
__decorate([
mobxAngular.computed
], TableColumnDirective.prototype, "colSpan", null);
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TableColumnDirective, decorators: [{
type: i0.Directive,
args: [{
selector: 'lf-table-column, [lfTableColumn]',
exportAs: 'lfTableColumn',
providers: [
{ provide: TableColumnContainer, useExisting: TableColumnDirective },
],
}]
}], ctorParameters: function () {
return [{ type: TableColumnContainer, decorators: [{
type: i0.SkipSelf
}] }, { type: i0__namespace.ElementRef }];
}, propDecorators: { id: [{
type: i0.Input
}], colspan: [{
type: i0.Input
}], minWidth: [{
type: i0.Input
}], fixed: [{
type: i0.Input
}], rowSpan: [], colSpan: [] } });
/**
* Directive used to simplify the creation of table headers and manage the size
* of a table's max width, min width, and all columns. Tables using these
* functionalities should have their `table-layout` CSS property set to `fixed`.
*
* This directive provides utilities to transform the following:
* ```html
* <lf-table-header>
* <lf-table-column id="id" [fixed]="true" [minWidth]="40"></lf-table-column>
* <lf-table-column id="name">
* <lf-table-column id="first"></lf-table-column>
* <lf-table-column id="last"></lf-table-column>
* </lf-table-column>
* <lf-table-column id="age"></lf-table-column>
* </lf-table-header>
* ```
* Into a table header similar to the following diagram, where the `id` column
* has a fixed size and the remaining columns expand (with similar width) to the
* table's width.
* ```
* | | name | |
* | id |---------------------| age |
* | | first | last | |
* ```
*
* The directive provides utilities to help a table set its minimum and maximum
* widths, as well as column sizes (using `<colgroup>`) when necessary. The
* following example shows the creation of a table that uses an instance of this
* directive (named `header`) to manage width and column sizes. The example
* assumes that the table's `table-layout` CSS property is set to `fixed`:
* ```html
* <table
* [style.minWidth]="header.tableMinWidth + 'px'"
* [style.maxWidth]="header.tableMaxWidth + 'px'"
* >
* <colgroup>
* <col *ngFor="let width of header.columnWidths" [attr.width]="width"/>
* </colgroup>
*
* <thead>
* <tr *ngFor="let row of header.rows">
* <th
* *ngFor="let column of row"
* [attr.rowSpan]="column.rowSpan"
* [attr.colSpan]="column.colSpan"
* >
* {{ column.id }} <!-- Can be used to fetch a label, for example -->
* </th>
* </tr>
* </thead>
*
* <tbody><!-- ... --></tbody>
* </table>
* ```
*/
var TableHeaderDirective = /** @class */ (function (_super) {
__extends(TableHeaderDirective, _super);
function TableHeaderDirective(elementRef) {
var _this = _super.call(this, null, elementRef) || this;
Object.defineProperty(_this, "elementRef", {
enumerable: true,
configurable: true,
writable: true,
value: elementRef
});
/**
* Default min width (in `px`) of columns.
*/
Object.defineProperty(_this, "defaultColumnsMinWidth", {
enumerable: true,
configurable: true,
writable: true,
value: 100
}); // Sane default
mobx.makeObservable(_this);
return _this;
}
Object.defineProperty(TableHeaderDirective.prototype, "numberOfRows", {
/**
* Total number of rows of the header (should map to the number of `<tr>` of
* the actual header).
* @returns Number of rows of the header.
*/
get: function () {
return this.height - 1;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableHeaderDirective.prototype, "numberOfColumns", {
/**
* Number of (leaf) columns of the header (number of columns actually
* representing table cells/that don't have sub-columns).
* @returns Number of leaf columns of the header.
*/
get: function () {
return this.width;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableHeaderDirective.prototype, "rows", {
/**
* List of rows of the header, where each row contains a list of its columns.
* This should directly map each row to a `<tr>` of the header, and each
* column to a `<th>`. For the example depicted in the class description, this
* method would return: `[[id, name, age], [first, last]]`.
* @returns List of rows, where each row is a list of columns.
*/
get: function () {
var rows = [];
for (var i = 0; i < this.numberOfRows; ++i) {
rows.push(this.columnsOfRow(i));
}
return rows;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableHeaderDirective.prototype, "tableMinWidth", {
/**
* Minimum width (in pixels) that should be set on the table that contains
* this header. If the table does not have a min width, then the columns will
* collapse indefinitely, we thus provide a minimum width that amounts to the
* sum of the minimum width of all columns.
* @returns Minimum width (in pixels) that should be set on the table.
*/
get: function () {
var _this = this;
return this.leafColumns().reduce(function (sum, column) { return sum + _this.columnMinWidth(column); }, 0);
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableHeaderDirective.prototype, "tableMaxWidth", {
/**
* Maximum width (in pixels) that should be set on the table that contains
* this header. Tables where all the columns have a fixed width cannot ever
* expand, for that we must set a max width on the table, otherwise this
* method returns `Infinity`.
* @returns Maximum width (in pixels) that should be set on the table.
*/
get: function () {
return this.leafColumns().every(function (column) { return column.fixed; })
? this.tableMinWidth
: Infinity;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TableHeaderDirective.prototype, "columnWidths", {
/**
* Width for all table columns, as they should be set in CSS (strings ending
* in `'px'` or `'%'` depending on whether the column is fixed). Each of these
* widths should be put on a `<col>` element inside a `<colgroup>` before the
* definition of the `<thead>` within a `<table>` with the `table-layout` CSS
* property set to `fixed`
* @returns List of widths of each leaf column.
*/
get: function () {
var _this = this;
var leaves = this.leafColumns();
// Columns not set as `fixed` should expand as necessary, as such we provide
// them with widths that together add up to `100%`
var dynamicMinWidthSum = leaves.reduce(function (sum, column) { return sum + (column.fixed ? 0 : _this.columnMinWidth(column)); }, 0);
return leaves.reduce(function (array, column) {
var _a, _b;
var colSpan = (_a = column.colSpan) !== null && _a !== void 0 ? _a : 1;
// Determine the widths of each column being spanned by `column`
var colMinWidthArray = storage.isArrayLike(column.minWidth)
? column.minWidth
: // Distribute the width amongst the columns being spanned
__spreadArray([], __read(Array(colSpan))).map(function () { return _this.columnMinWidth(column) / colSpan; });
for (var i = 0; i < colSpan; ++i) {
// Columns will end up with a width of `0` when a `minWidth` array is
// provided with length smaller than `colSpan`
var colMinWidth = (_b = colMinWidthArray[i]) !== null && _b !== void 0 ? _b : 0;
array.push(column.fixed
? colMinWidth + "px"
: (colMinWidth / dynamicMinWidthSum) * 100 + "%");
}
return array;
}, []);
},
enumerable: false,
configurable: true
});
/**
* Method that returns the list of leaf columns: columns whose label directly
* represents a table cell/columns that contain no sub-columns. For the
* example depicted in the class description, this method would return:
* `[id, first, last, age]`.
* @param columnContainer For internal use only (to recurse over columns).
* @returns List of columns that are leaves.
*/
TableHeaderDirective.prototype.leafColumns = function (columnContainer) {
var _this = this;
if (columnContainer === void 0) { columnContainer = this; }
return columnContainer.childrenColumns.reduce(function (leaves, column) { return leaves.concat(column.childrenColumns.length === 0
? [column]
: _this.leafColumns(column)); }, []);
};
/**
* Method that returns the list of columns of a given row (`<tr>`) of the
* table header. For the example depicted in the class description, for row
* `0` this method would return `[id, name, age]`; for row `1` it would return
* `[first, last]`.
* @param index Index of row from which to fetch columns.
* @param columnContainer For internal use only (to recurse over columns).
* @returns List of columns of row with index `index`.
*/
TableHeaderDirective.prototype.columnsOfRow = function (index, columnContainer) {
var _this = this;
if (columnContainer === void 0) { columnContainer = this; }
return index === 0
? columnContainer.childrenColumns
: columnContainer.childrenColumns.reduce(function (rowColumns, column) { return rowColumns.concat(_this.columnsOfRow(index - 1, column)); }, []);
};
/**
* Minimum width of a column (or a default minimum width when none has been
* created).
* @param column Column whose minimum width we are interested in.
* @returns Minimum width of the column.
*/
TableHeaderDirective.prototype.columnMinWidth = function (column) {
var _a;
return storage.isArrayLike(column.minWidth)
? column.minWidth.reduce(function (sum, width) { return sum + width; }, 0)
: (_a = column.minWidth) !== null && _a !== void 0 ? _a : this.defaultColumnsMinWidth * column.colSpan;
};
return TableHeaderDirective;
}(TableColumnContainer));
Object.defineProperty(TableHeaderDirective, "\u0275fac", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TableHeaderDirective, deps: [{ token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Directive })
});
Object.defineProperty(TableHeaderDirective, "\u0275dir", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: TableHeaderDirective, selector: "lf-table-header, [lfTableHeader]", inputs: { defaultColumnsMinWidth: "defaultColumnsMinWidth" }, providers: [
{ provide: TableColumnContainer, useExisting: TableHeaderDirective },
], exportAs: ["lfTableHeader"], usesInheritance: true, ngImport: i0__namespace })
});
__decorate([
mobxAngular.observable
], TableHeaderDirective.prototype, "defaultColumnsMinWidth", void 0);
__decorate([
mobxAngular.computed
], TableHeaderDirective.prototype, "numberOfRows", null);
__decorate([
mobxAngular.computed
], TableHeaderDirective.prototype, "numberOfColumns", null);
__decorate([
mobxAngular.computed
], TableHeaderDirective.prototype, "rows", null);
__decorate([
mobxAngular.computed
], TableHeaderDirective.prototype, "tableMinWidth", null);
__decorate([
mobxAngular.computed
], TableHeaderDirective.prototype, "tableMaxWidth", null);
__decorate([
mobxAngular.computed
], TableHeaderDirective.prototype, "columnWidths", null);
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TableHeaderDirective, decorators: [{
type: i0.Directive,
args: [{
selector: 'lf-table-header, [lfTableHeader]',
exportAs: 'lfTableHeader',
providers: [
{ provide: TableColumnContainer, useExisting: TableHeaderDirective },
],
}]
}], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }]; }, propDecorators: { defaultColumnsMinWidth: [{
type: i0.Input
}], numberOfRows: [], numberOfColumns: [], rows: [], tableMinWidth: [], tableMaxWidth: [], columnWidths: [] } });
/**
* Exported/declared components and directives.
*/
var DECLARATIONS = [TableColumnDirective, TableHeaderDirective];
/**
* LF table header module.
*/
var LfTableHeaderModule = /** @class */ (function () {
function LfTableHeaderModule() {
}
return LfTableHeaderModule;
}());
Object.defineProperty(LfTableHeaderModule, "\u0275fac", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: LfTableHeaderModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule })
});
Object.defineProperty(LfTableHeaderModule, "\u0275mod", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: LfTableHeaderModule, declarations: [TableColumnDirective, TableHeaderDirective], imports: [common.CommonModule], exports: [TableColumnDirective, TableHeaderDirective] })
});
Object.defineProperty(LfTableHeaderModule, "\u0275inj", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: LfTableHeaderModule, providers: [], imports: [[common.CommonModule]] })
});
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: LfTableHeaderModule, decorators: [{
type: i0.NgModule,
args: [{
imports: [common.CommonModule],
declarations: DECLARATIONS,
exports: DECLARATIONS,
providers: [],
}]
}] });
// Module
/**
* Service providing scrolling-related utilities.
*/
var ScrollbarUtils = /** @class */ (function () {
function ScrollbarUtils() {
}
/**
* Computes the width/height (in px) of vertical/horizontal scrollbars in the
* user's browser and caches the results. This method should only ever be
* called once.
*/
ScrollbarUtils.computeScrollbarSizes = function () {
var div = document.createElement('div');
div.innerHTML = "<div style=\"overflow:auto; position:absolute; top:0;\n width:100px; height:100px;\">\n <div style=\"width:200px; height:200px;\"></div>\n </div>";
var child = div.firstChild;
document.body.appendChild(div);
ScrollbarUtils.scrollbarWidth = child.offsetWidth - child.clientWidth;
ScrollbarUtils.scrollbarHeight = child.offsetHeight - child.clientHeight;
document.body.removeChild(div);
};
Object.defineProperty(ScrollbarUtils.prototype, "verticalScrollbarWidth", {
/**
* Width (in px) of a vertical scrollbar in the user's browser. This value is
* only computed once and cached for subsequent calls.
* @returns Width of the vertical scrollbar in the user's browser.
*/
get: function () {
if (ScrollbarUtils.scrollbarWidth === undefined) {
ScrollbarUtils.computeScrollbarSizes();
}
return ScrollbarUtils.scrollbarWidth;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ScrollbarUtils.prototype, "horizontalScrollbarHeight", {
/**
* Height (in px) of a horizontal scrollbar in the user's browser. This value
* is only computed once and cached for subsequent calls.
* @returns Height of the horizontal scrollbar in the user's browser.
*/
get: function () {
if (ScrollbarUtils.scrollbarHeight === undefined) {
ScrollbarUtils.computeScrollbarSizes();
}
return ScrollbarUtils.scrollbarHeight;
},
enumerable: false,
configurable: true
});
/**
* Whether a given DOM element has a vertical scrollbar.
* @param element Element to check for vertical scrollbar.
* @returns Whether the provided element has a vertical scrollbar.
*/
// FIXME: Unreliable in IE/Edge
ScrollbarUtils.prototype.hasVerticalOverflow = function (element) {
return element.scrollHeight > element.clientHeight;
};
/**
* Whether a given DOM element has a horizontal scrollbar.
* @param element Element to check for horizontal scrollbar.
* @returns Whether the provided element has a horizontal scrollbar.
*/
// FIXME: Unreliable in IE/Edge
ScrollbarUtils.prototype.hasHorizontalOverflow = function (element) {
return element.scrollWidth > element.clientWidth;
};
return ScrollbarUtils;
}());
// Only compute sizes once (this assumes that browser scrollbar sizes don't
// change over time, which seems like a valid assumption)
Object.defineProperty(ScrollbarUtils, "scrollbarWidth", {
enumerable: true,
configurable: true,
writable: true,
value: undefined
});
Object.defineProperty(ScrollbarUtils, "scrollbarHeight", {
enumerable: true,
configurable: true,
writable: true,
value: undefined
});
Object.defineProperty(ScrollbarUtils, "\u0275fac", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: ScrollbarUtils, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable })
});
Object.defineProperty(ScrollbarUtils, "\u0275prov", {
enumerable: true,
configurable: true,
writable: true,
value: i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: ScrollbarUtils, providedIn: 'root' })
});
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: ScrollbarUtils, decorators: [{
type: i0.Injectable,
args: [{ providedIn: 'root' }]
}] });
/**
* Executes a task as soon as possible.
* @param task Function or any object that implements `call()`.
*/
// There doesn't seem to be a way of importing this module using ES6 syntax that
// both TypeScript and Rollup ac