UNPKG

@anjuna/angular-core

Version:

<p align="center"> <img src="//cdn.zuora.com/theme/0.6.0/assets/anjuna/anjuna-logo.svg"/> <br/><br/> </p>

1,155 lines (1,112 loc) 79.7 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@anjuna/core'), require('@angular/forms'), require('rxjs')) : typeof define === 'function' && define.amd ? define('@anjuna/angular-core', ['exports', '@angular/core', '@anjuna/core', '@angular/forms', 'rxjs'], factory) : (global = global || self, factory((global.anjuna = global.anjuna || {}, global.anjuna['angular-core'] = {}), global.ng.core, global.core$1, global.ng.forms, global.rxjs)); }(this, (function (exports, core, core$1, forms, rxjs) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { 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) { 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) : new P(function (resolve) { resolve(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 }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } 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; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } 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 __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; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } var LANGUAGE_CODE = new core.InjectionToken('LanguageCode'); var BaseTranslationPipe = /** @class */ (function () { function BaseTranslationPipe(language) { this.language = language; } BaseTranslationPipe.prototype.transform = function (value) { if (!this.translations[this.language]) { console.warn("Translation file for '" + this.language + "' does not exist."); return value; } return this.translations[this.language][value] || value; }; BaseTranslationPipe = __decorate([ __param(0, core.Optional()), __param(0, core.Inject(LANGUAGE_CODE)), __metadata("design:paramtypes", [Object]) ], BaseTranslationPipe); return BaseTranslationPipe; }()); /** * @description A wrapper around the HTML 5 Drag API. */ var DraggableDirective = /** @class */ (function () { function DraggableDirective(element) { var _this = this; this.element = element; this.dataFn = function () { return _this.getData(); }; this.controller = new core$1.DragController(this.element.nativeElement, this.dataFn).connect(); } DraggableDirective.prototype.getData = function () { return this.anjDraggable; }; DraggableDirective.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; __decorate([ core.Input(), __metadata("design:type", Object) ], DraggableDirective.prototype, "anjDraggable", void 0); DraggableDirective = __decorate([ core.Directive({ selector: '[anjDraggable]' }), __metadata("design:paramtypes", [core.ElementRef]) ], DraggableDirective); return DraggableDirective; }()); /** * @description A wrapper around the HTML 5 Drop API. */ var DroppableDirective = /** @class */ (function () { function DroppableDirective(element) { this.element = element; this.controller = new core$1.DropController(this.element.nativeElement).connect(); } DroppableDirective.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; DroppableDirective = __decorate([ core.Directive({ selector: '[anjDroppable]' }), __metadata("design:paramtypes", [core.ElementRef]) ], DroppableDirective); return DroppableDirective; }()); var DomOutlet = /** @class */ (function () { function DomOutlet(targetElement) { this.targetElement = targetElement; } DomOutlet.prototype.attachTemplate = function (template) { var _this = this; if (this.template.zone.isStable) { this._viewRef = this.template.zone.run(function () { return template.viewContainerRef.createEmbeddedView(template.templateRef, template.context); }); } else { this._viewRef = template.viewContainerRef.createEmbeddedView(template.templateRef, template.context); } this._viewRef.rootNodes.forEach(function (rootNode) { return _this.targetElement.appendChild(rootNode); }); this._viewRef.detectChanges(); this.setDisposeFn((function () { var index = template.viewContainerRef.indexOf(_this._viewRef); if (index !== -1) { template.viewContainerRef.remove(index); } })); return this._viewRef; }; DomOutlet.prototype.updateContext = function (context) { for (var prop in context) { if (context.hasOwnProperty(prop)) { this._viewRef.context[prop] = context[prop]; } } this._viewRef.detectChanges(); }; DomOutlet.prototype.setDisposeFn = function (fn) { this.disposeFn = fn; }; DomOutlet.prototype.attach = function (template) { this.template = template; return this.attachTemplate(template); }; DomOutlet.prototype.detach = function () { if (this.template) { this.template.setAttachedHost(null); this.template = null; } this.invokeDisposeFn(); }; DomOutlet.prototype.dispose = function (removeParent) { if (removeParent === void 0) { removeParent = true; } this.disposeFn(); if (removeParent && this.targetElement.parentNode != null) { this.targetElement.parentNode.removeChild(this.targetElement); } return undefined; }; DomOutlet.prototype.invokeDisposeFn = function () { if (this.disposeFn) { this.disposeFn(); this.disposeFn = null; } }; return DomOutlet; }()); var Template = /** @class */ (function () { function Template(templateDirective, context) { this.templateDirective = templateDirective; this.context = context; } Object.defineProperty(Template.prototype, "origin", { get: function () { return this.templateDirective.template.elementRef; }, enumerable: true, configurable: true }); Object.defineProperty(Template.prototype, "templateRef", { get: function () { return this.templateDirective.template; }, enumerable: true, configurable: true }); Object.defineProperty(Template.prototype, "viewContainerRef", { get: function () { return this.templateDirective.viewContainerRef; }, enumerable: true, configurable: true }); Object.defineProperty(Template.prototype, "zone", { get: function () { return this.templateDirective.zone; }, enumerable: true, configurable: true }); Template.prototype.attach = function (host, context) { if (context === void 0) { context = this.context; } this.context = context; this.host = host; return host.attach(this); }; Template.prototype.detach = function () { this.context = undefined; if (this.host) { var host = this.host; this.host = null; host.detach(); } }; Template.prototype.setAttachedHost = function (host) { this.host = host; }; return Template; }()); var TemplateDirective = /** @class */ (function () { function TemplateDirective(_template, _viewRef, _zone) { this._template = _template; this._viewRef = _viewRef; this._zone = _zone; } Object.defineProperty(TemplateDirective.prototype, "anjTemplateOf", { set: function (name) { this._name = name; }, enumerable: true, configurable: true }); Object.defineProperty(TemplateDirective.prototype, "name", { get: function () { return this._name; }, enumerable: true, configurable: true }); Object.defineProperty(TemplateDirective.prototype, "template", { get: function () { return this._template; }, enumerable: true, configurable: true }); Object.defineProperty(TemplateDirective.prototype, "viewContainerRef", { get: function () { return this._viewRef; }, enumerable: true, configurable: true }); Object.defineProperty(TemplateDirective.prototype, "zone", { get: function () { return this._zone; }, enumerable: true, configurable: true }); TemplateDirective.ctorParameters = function () { return [ { type: core.TemplateRef }, { type: core.ViewContainerRef }, { type: core.NgZone } ]; }; __decorate([ core.Input(), __metadata("design:type", String), __metadata("design:paramtypes", [String]) ], TemplateDirective.prototype, "anjTemplateOf", null); TemplateDirective = __decorate([ core.Directive({ selector: '[anjTemplate]' }), __metadata("design:paramtypes", [core.TemplateRef, core.ViewContainerRef, core.NgZone]) ], TemplateDirective); return TemplateDirective; }()); /* tslint:disable:directive-selector */ var AnjTable = /** @class */ (function () { function AnjTable(elRef) { this.outletRows = []; this.element = elRef.nativeElement; this.element.renderer = this; } AnjTable_1 = AnjTable; AnjTable.rowContext = function (row, index, column) { return { $implicit: row, column: column, index: index }; }; AnjTable.updateContext = function (outlet, context) { outlet.updateContext(context); }; AnjTable.prototype.ngOnDestroy = function () { this.outletRows.map(function (rowMap) { for (var templateName in rowMap) { if (rowMap[templateName]) { rowMap[templateName] = rowMap[templateName].dispose(); } } return rowMap; }); }; /** * Fixes https://git.zias.io/ui-foundation/anjuna/issues/876 * When the columns change, destory all portals without killing the parent node */ AnjTable.prototype.onColumnsUpdated = function () { this.outletRows.map(function (rowMap) { for (var templateName in rowMap) { if (rowMap[templateName]) { rowMap[templateName] = rowMap[templateName].dispose(false); } } return rowMap; }); }; /* These next three methods are a mess of duplicated logic - they will probably stay that way until feature complete, then I'll clean em up */ AnjTable.prototype.cellTemplate = function (cell, offset, col, row, rowIndex, template) { var rowMap = this.outletRows[rowIndex] || {}; var outlet = rowMap[col.name]; if (!cell) { /** * Removing the line: * rowMap[col.name] = outlet ? outlet.dispose() : undefined; * which fixes https://git.zias.io/ui-foundation/anjuna/issues/850. * Like the detail situation, I do not understand why this works.. */ return; } if (outlet) { if (cell !== outlet.targetElement) { this.updateOutlet(outlet, template, cell, AnjTable_1.rowContext(row, rowIndex, col)); } else { AnjTable_1.updateContext(outlet, AnjTable_1.rowContext(row, rowIndex, col)); } } else { rowMap[col.name] = this.createOutlet(cell, template, AnjTable_1.rowContext(row, rowIndex, col)); this.outletRows[rowIndex] = rowMap; } col.initCell(cell, offset); }; AnjTable.prototype.rowTemplate = function (templateName, targetEl, row, rowIndex) { // Dispose row template no longer used for that index this.outletRows[rowIndex] = this.filterRowTemplates(this.outletRows[rowIndex], templateName); var outlet = this.outletRows[rowIndex][templateName]; if (!targetEl) { this.outletRows[rowIndex][templateName] = outlet ? outlet.dispose() : undefined; return; } if (outlet) { if (targetEl !== outlet.targetElement) { this.updateOutlet(outlet, templateName, targetEl, AnjTable_1.rowContext(row, rowIndex)); } else { AnjTable_1.updateContext(outlet, AnjTable_1.rowContext(row, rowIndex)); } } else { this.outletRows[rowIndex][templateName] = this.createOutlet(targetEl, templateName, AnjTable_1.rowContext(row, rowIndex)); this.outletRows[rowIndex] = this.outletRows[rowIndex]; } }; AnjTable.prototype.fromTemplate = function (templateName, targetEl, row, rowIndex) { var rowMap = this.outletRows[rowIndex] || {}; var outlet = rowMap[templateName]; if (!targetEl) { /** * Removing the line: * rowMap[templateName] = outlet ? outlet.dispose() : undefined; * is part of the fix for https://git.zias.io/ui-foundation/anjuna/issues/750 * However, I don't grok at all how/why this works. I don't buy it. * So when we eventually get an issue related to master detail, start here. * Put that line back, and fix it right. */ return; } if (outlet) { if (targetEl !== outlet.targetElement) { this.updateOutlet(outlet, templateName, targetEl, AnjTable_1.rowContext(row, rowIndex)); } else { AnjTable_1.updateContext(outlet, AnjTable_1.rowContext(row, rowIndex)); } } else { rowMap[templateName] = this.createOutlet(targetEl, templateName, AnjTable_1.rowContext(row, rowIndex)); this.outletRows[rowIndex] = rowMap; } }; AnjTable.prototype.createOutlet = function (target, templateName, context) { var outlet = new DomOutlet(target); outlet.attach(this.createTemplate(templateName, context)); return outlet; }; AnjTable.prototype.createTemplate = function (templateName, context) { var templateRef = this.templates.find(function (t) { return t.name === templateName; }); return new Template(templateRef, context); }; AnjTable.prototype.updateOutlet = function (outlet, templateName, targetEl, context) { outlet.targetElement = targetEl; outlet.detach(); outlet.attach(this.createTemplate(templateName, context)); }; /** * Disposes of row templates no longer used in a given row. This ONLY happens if they have specified more than one * Template and the end user sorts or filters or otherwise changes the order. If only one template is specified, * the output will always match the input -r */ AnjTable.prototype.filterRowTemplates = function (rowMap, templateName) { if (rowMap === void 0) { rowMap = {}; } var updated = {}; Object.keys(rowMap).forEach(function (k) { if (k === templateName) { updated[k] = rowMap[k]; } else { rowMap[k].dispose(false); } }); return updated; }; var AnjTable_1; AnjTable.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; __decorate([ core.ContentChildren(TemplateDirective), __metadata("design:type", core.QueryList) ], AnjTable.prototype, "templates", void 0); __decorate([ core.HostListener('anjColumnsDidUpdate'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], AnjTable.prototype, "onColumnsUpdated", null); AnjTable = AnjTable_1 = __decorate([ core.Directive({ selector: 'anj-table:not([anjIgnore])', }), __metadata("design:paramtypes", [core.ElementRef]) ], AnjTable); return AnjTable; }()); (function (TransitionState) { TransitionState[TransitionState["Enter"] = 0] = "Enter"; TransitionState[TransitionState["Leave"] = 1] = "Leave"; TransitionState[TransitionState["EnterTo"] = 2] = "EnterTo"; TransitionState[TransitionState["Inactive"] = 3] = "Inactive"; })(exports.TransitionState || (exports.TransitionState = {})); var TransitionDirective = /** @class */ (function () { function TransitionDirective(renderer, element, mode, name) { this.renderer = renderer; this.element = element; this.mode = mode; this.name = name; this.state = exports.TransitionState.EnterTo; this.end = new core.EventEmitter(); this.mode = this.mode ? this.mode : 'in-out'; this.name = this.name ? this.name : 'transition'; } TransitionDirective_1 = TransitionDirective; TransitionDirective.prototype.ngOnChanges = function (changes) { this.endTransition(); if (!changes.anjTransition.previousValue && !changes.anjTransition.currentValue && this.mode !== 'out') { this.initEnter(); } else if (!changes.anjTransition.previousValue && changes.anjTransition.currentValue) { this.transitionIn(); } else { this.transitionOut(); } }; TransitionDirective.prototype.handleTransition = function (event) { if (event.target === this.element.nativeElement && TransitionDirective_1.supportedTransitions.indexOf(event.propertyName) > -1) { event.stopPropagation(); this.end.emit(this.state); if (this.state === exports.TransitionState.Enter) { this.endTransition(); } else { if (this.mode !== 'out' && this.anjTransition) { this.transitionIn(); } else { this.endTransition(); } } } }; TransitionDirective.prototype.initEnter = function () { this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-enter-to"); }; TransitionDirective.prototype.transitionIn = function () { if (this.mode !== 'out') { this.state = exports.TransitionState.Enter; this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-enter-to"); this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-leave"); this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-leave-active"); this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-enter-active"); this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-enter"); } else { this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-enter-to"); this.endTransition(); } }; TransitionDirective.prototype.transitionOut = function () { var _this = this; this.state = exports.TransitionState.Leave; if (this.mode !== 'in') { this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-leave-active"); this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-leave"); } else { this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-enter-to"); this.state = exports.TransitionState.EnterTo; if (this.anjTransition) { window.setTimeout(function () { _this.transitionIn(); }); } } }; TransitionDirective.prototype.endTransition = function () { this.state = exports.TransitionState.Inactive; this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-enter-active"); this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-leave-active"); this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-enter"); this.renderer.removeClass(this.element.nativeElement, "anj-" + this.name + "-leave"); if (!this.anjTransition) { this.renderer.addClass(this.element.nativeElement, "anj-" + this.name + "-enter-to"); } }; var TransitionDirective_1; TransitionDirective.supportedTransitions = ['opacity', 'transform']; TransitionDirective.ctorParameters = function () { return [ { type: core.Renderer2 }, { type: core.ElementRef }, { type: undefined, decorators: [{ type: core.Attribute, args: ['mode',] }] }, { type: String, decorators: [{ type: core.Attribute, args: ['name',] }] } ]; }; __decorate([ core.Input(), __metadata("design:type", Object) ], TransitionDirective.prototype, "anjTransition", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], TransitionDirective.prototype, "end", void 0); __decorate([ core.HostListener('transitiend', ['$event']), __metadata("design:type", Function), __metadata("design:paramtypes", [TransitionEvent]), __metadata("design:returntype", void 0) ], TransitionDirective.prototype, "handleTransition", null); TransitionDirective = TransitionDirective_1 = __decorate([ core.Directive({ selector: '[anjTransition]' }), __param(2, core.Attribute('mode')), __param(3, core.Attribute('name')), __metadata("design:paramtypes", [core.Renderer2, core.ElementRef, String, String]) ], TransitionDirective); return TransitionDirective; }()); var TIME_TIMEZONE_STRING = new core.InjectionToken('TimeTimezoneString'); var TIME_MERIDIEM = new core.InjectionToken('TimeMeridiem'); var DATE_TIMEZONE_OVERRIDE = new core.InjectionToken('DateTimezoneOverride'); /* tslint:disable:directive-selector */ var LocaleDirective = /** @class */ (function () { function LocaleDirective(changeRef, _locale, _lang, _timezone) { this.changeRef = changeRef; if (_locale) { this._locale = _locale; this._lang = _lang ? _lang : this._locale ? this._locale.split('-')[0] : 'en'; } if (_timezone) { this._timezone = _timezone; } this.changeRef.markForCheck(); } LocaleDirective.ctorParameters = function () { return [ { type: core.ChangeDetectorRef }, { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [core.LOCALE_ID,] }] }, { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [LANGUAGE_CODE,] }] }, { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [DATE_TIMEZONE_OVERRIDE,] }] } ]; }; __decorate([ core.HostBinding('attr.locale'), __metadata("design:type", String) ], LocaleDirective.prototype, "_locale", void 0); __decorate([ core.HostBinding('attr.lang'), __metadata("design:type", String) ], LocaleDirective.prototype, "_lang", void 0); __decorate([ core.HostBinding('attr.timezone'), __metadata("design:type", String) ], LocaleDirective.prototype, "_timezone", void 0); LocaleDirective = __decorate([ core.Directive({ selector: 'anj-locale:not([manual])', }), __param(1, core.Optional()), __param(1, core.Inject(core.LOCALE_ID)), __param(2, core.Optional()), __param(2, core.Inject(LANGUAGE_CODE)), __param(3, core.Optional()), __param(3, core.Inject(DATE_TIMEZONE_OVERRIDE)), __metadata("design:paramtypes", [core.ChangeDetectorRef, String, String, String]) ], LocaleDirective); return LocaleDirective; }()); var ValueAccessor = /** @class */ (function () { function ValueAccessor(element, parentForm, parentGroup, injector, changeRef) { this.element = element; this.injector = injector; this.changeRef = changeRef; /** * Enable two-way binding */ this.valueChange = new core.EventEmitter(); this.onChange = function () { }; this.onTouched = function () { }; this.parent = parentForm ? parentForm : parentGroup ? parentGroup : null; } Object.defineProperty(ValueAccessor.prototype, "isInvalid", { get: function () { if (!this.ngControl) { return false; } var isSubmitted = (this.parent && this.parent.submitted); return this.ngControl.invalid && (this.ngControl.touched || isSubmitted); }, enumerable: true, configurable: true }); ValueAccessor.prototype.ngAfterViewInit = function () { var _this = this; var control = this.injector.get(forms.NgControl, null); if (control) { this.ngControl = control.control; this.element.nativeElement.validationStrategy = this; } if (this.parent && this.parent.statusChanges) { this.parentSubscription = this.parent.statusChanges.subscribe({ next: function () { _this.changeRef.markForCheck(); } }); } }; ValueAccessor.prototype.ngOnDestroy = function () { if (this.parentSubscription) { this.parentSubscription.unsubscribe(); } }; ValueAccessor.prototype.onAnjBlur = function () { this.onTouched(); }; ValueAccessor.prototype.writeValue = function (value) { this.element.nativeElement.value = this.lastValue = value == null ? '' : value; }; ValueAccessor.prototype.onChangeEvent = function (value) { if (value !== this.lastValue) { this.lastValue = value; this.onChange(value); this.valueChange.emit(value); } }; ValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; }; ValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; ValueAccessor.prototype.setDisabledState = function (isDisabled) { this.element.nativeElement.disabled = isDisabled; }; // Called by Anjuna Element, so needs to exist, but Angular does all the hoof-work ValueAccessor.prototype.onValidChange = function () { }; ValueAccessor.ctorParameters = function () { return [ { type: core.ElementRef }, { type: forms.NgForm }, { type: forms.FormGroupDirective }, { type: core.Injector }, { type: core.ChangeDetectorRef, decorators: [{ type: core.Optional }] } ]; }; __decorate([ core.HostBinding('attr.invalid'), __metadata("design:type", Boolean), __metadata("design:paramtypes", []) ], ValueAccessor.prototype, "isInvalid", null); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], ValueAccessor.prototype, "valueChange", void 0); __decorate([ core.HostListener('anjBlur'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], ValueAccessor.prototype, "onAnjBlur", null); ValueAccessor = __decorate([ core.Directive(), __param(4, core.Optional()), __metadata("design:paramtypes", [core.ElementRef, forms.NgForm, forms.FormGroupDirective, core.Injector, core.ChangeDetectorRef]) ], ValueAccessor); return ValueAccessor; }()); /* tslint:disable:directive-selector */ var BooleanValueDirective = /** @class */ (function (_super) { __extends(BooleanValueDirective, _super); function BooleanValueDirective(parentForm, parentFormGroup, element, injector, changeRef) { return _super.call(this, element, parentForm, parentFormGroup, injector, changeRef) || this; } BooleanValueDirective_1 = BooleanValueDirective; BooleanValueDirective.prototype.writeValue = function (value) { this.element.nativeElement.checked = this.lastValue = value == null ? false : value; }; BooleanValueDirective.prototype.onAnjChange = function (value) { this.onChangeEvent(value); }; var BooleanValueDirective_1; BooleanValueDirective.ctorParameters = function () { return [ { type: forms.NgForm, decorators: [{ type: core.Optional }] }, { type: forms.FormGroupDirective, decorators: [{ type: core.Optional }] }, { type: core.ElementRef }, { type: core.Injector }, { type: core.ChangeDetectorRef } ]; }; __decorate([ core.HostListener('anjChange', ['$event.target.checked']), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], BooleanValueDirective.prototype, "onAnjChange", null); BooleanValueDirective = BooleanValueDirective_1 = __decorate([ core.Directive({ selector: 'anj-checkbox, anj-toggle', providers: [ { provide: forms.NG_VALUE_ACCESSOR, useExisting: BooleanValueDirective_1, multi: true } ] }), __param(0, core.Optional()), __param(1, core.Optional()), __metadata("design:paramtypes", [forms.NgForm, forms.FormGroupDirective, core.ElementRef, core.Injector, core.ChangeDetectorRef]) ], BooleanValueDirective); return BooleanValueDirective; }(ValueAccessor)); /** @dynamic */ var AnjunaValidators = /** @class */ (function () { function AnjunaValidators() { } AnjunaValidators.date = function (c) { if (!c.value) { return; } var isValid = true; // Handle obvious Invalid Date if (c.value.toString() === 'Invalid Date') { isValid = false; // Handle Moment Date } else if (typeof c.value._isValid === 'boolean') { isValid = c.value._isValid; // Handle Native Date } else { isValid = !isNaN(new Date(c.value).getTime()); } if (isValid || c.value === '') { return null; } else { return { date: { valid: false } }; } }; AnjunaValidators.requiredCheck = function (c) { if (c.value) { return null; } else { return { required: { valid: false } }; } }; AnjunaValidators.unique = function (c) { if (!c.value || !Array.isArray(c.value)) { return; } var testArray = c.value.filter(Boolean); var isValid = testArray.length === Array.from(new Set(testArray)).length; if (isValid) { return null; } else { return { unique: { valid: false } }; } }; AnjunaValidators.minDate = function (min) { return function (c) { if (!c.value) { return; } if (c.value < new Date(min)) { return { min: { valid: false } }; } else { return null; } }; }; AnjunaValidators.maxDate = function (max) { return function (c) { if (!c.value) { return; } if (c.value > new Date(max)) { return { max: { valid: false } }; } else { return null; } }; }; return AnjunaValidators; }()); /* tslint:disable:directive-selector */ var DateValidatorDirective = /** @class */ (function () { function DateValidatorDirective() { } DateValidatorDirective_1 = DateValidatorDirective; DateValidatorDirective.prototype.validate = function (c) { return AnjunaValidators.date(c); }; var DateValidatorDirective_1; DateValidatorDirective = DateValidatorDirective_1 = __decorate([ core.Directive({ selector: '[date][ngModel],[date][formControl]', providers: [ { provide: forms.NG_VALIDATORS, useExisting: DateValidatorDirective_1, multi: true } ] }) ], DateValidatorDirective); return DateValidatorDirective; }()); var PickerAbstract = /** @class */ (function () { function PickerAbstract(_element, changeRef, ngControl) { this._element = _element; this.changeRef = changeRef; this.ngControl = ngControl; this.onChange = function () { }; this.onTouch = function () { }; this.valueChange = new core.EventEmitter(); if (this.ngControl) { this.ngControl.valueAccessor = this; } } PickerAbstract.prototype.ngAfterViewInit = function () { this.picker = this._element.nativeElement.querySelector(this.pickerSelector); if (this.picker) { this.picker.setInputValue(this.innerDateValue); this.outerValue = this._element.nativeElement.value; } }; // // Start: ControlValueAccessor requirement PickerAbstract.prototype.writeValue = function (newValue) { if (this.picker && this.innerDateValue !== newValue) { this.picker.setInputValue(newValue); this.outerValue = this._element.nativeElement.value; } this.innerDateValue = newValue; }; PickerAbstract.prototype.registerOnChange = function (fn) { this.onChange = fn; }; PickerAbstract.prototype.registerOnTouched = function (fn) { this.onTouch = fn; }; // // End: ControlValueAccessor requirements PickerAbstract.prototype.changeHandler = function (changedVal) { if (changedVal.refreshOuter) { this.outerValue = changedVal.outer; } this.innerDateValue = changedVal.inner; this.propogateInnerValueChange(); this.changeRef.markForCheck(); // Handle for keyup if (changedVal.inner) { this.onTouch(); } }; PickerAbstract.prototype.propogateInnerValueChange = function () { if (this.ngControl) { this.ngControl.control.setValue(this.innerDateValue); } this.valueChange.emit(this.innerDateValue); }; PickerAbstract.ctorParameters = function () { return [ { type: core.ElementRef }, { type: core.ChangeDetectorRef }, { type: forms.NgControl, decorators: [{ type: core.Optional }, { type: core.Self }] } ]; }; __decorate([ core.Input(), __metadata("design:type", forms.NgModel) ], PickerAbstract.prototype, "ngModel", void 0); __decorate([ core.HostBinding('value'), __metadata("design:type", String) ], PickerAbstract.prototype, "outerValue", void 0); PickerAbstract = __decorate([ core.Directive(), __param(2, core.Optional()), __param(2, core.Self()), __metadata("design:paramtypes", [core.ElementRef, core.ChangeDetectorRef, forms.NgControl]) ], PickerAbstract); return PickerAbstract; }()); var DatePickerDirective = /** @class */ (function (_super) { __extends(DatePickerDirective, _super); function DatePickerDirective(_element, changeRef, ngControl) { var _this = _super.call(this, _element, changeRef, ngControl) || this; _this.pickerSelector = 'anj-date-picker'; return _this; } DatePickerDirective.prototype.onAnjBlur = function () { this.onTouch(); }; DatePickerDirective.prototype.onAnjDateChange = function (event) { this.changeHandler(event.detail); }; DatePickerDirective.ctorParameters = function () { return [ { type: core.ElementRef }, { type: core.ChangeDetectorRef }, { type: forms.NgControl, decorators: [{ type: core.Optional }, { type: core.Self }]