UNPKG

@bi8/am-dyn-form

Version:

ng update @angular/cli yarn add @angular/cli

1,630 lines 82.5 kB
(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/router'), require('@angular/platform-browser/animations'), require('@angular/forms'), require('@angular/material'), require('rxjs/operators'), require('rxjs/internal/util/pipe'), require('@ng-select/ng-select'), require('rxjs'), require('@bi8/am-io'), require('@angular/cdk/coercion'), require('@angular/flex-layout'), require('lodash'), require('moment'), require('rxjs/internal/observable/of')) :
    typeof define === 'function' && define.amd ? define('@bi8/am-dyn-form', ['exports', '@angular/core', '@angular/common', '@angular/router', '@angular/platform-browser/animations', '@angular/forms', '@angular/material', 'rxjs/operators', 'rxjs/internal/util/pipe', '@ng-select/ng-select', 'rxjs', '@bi8/am-io', '@angular/cdk/coercion', '@angular/flex-layout', 'lodash', 'moment', 'rxjs/internal/observable/of'], factory) :
    (global = global || self, factory((global.bi8 = global.bi8 || {}, global.bi8['am-dyn-form'] = {}), global.ng.core, global.ng.common, global.ng.router, global.ng.platformBrowser.animations, global.ng.forms, global.ng.material, global.rxjs.operators, global.rxjs['internal/util/pipe'], global.ngSelect, global.rxjs, global.amIo, global.ng.cdk.coercion, global.ng['flex-layout'], global._, global.moment_, global.rxjs['internal/observable/of']));
}(this, function (exports, core, common, router, animations, forms, material, operators, pipe, ngSelect, rxjs, amIo, coercion, flexLayout, lodash, moment_, of) { '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 DynFormService = /** @class */ (function () {
        function DynFormService() {
        }
        DynFormService = __decorate([
            core.Injectable(),
            __metadata("design:paramtypes", [])
        ], DynFormService);
        return DynFormService;
    }());

    var DynFormGroup = /** @class */ (function (_super) {
        __extends(DynFormGroup, _super);
        function DynFormGroup(options, controls) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, controls) || this;
            _this.config = {};
            if (options) {
                _this.key = options.key || '';
                _this.dir = options.dir || '';
            }
            return _this;
        }
        DynFormGroup.prototype.addSlaveObserver = function (master, slave, options) {
            var masterField = this.get(master);
            var slaveField = this.get(slave);
            if (!options) {
                options = { disable: true, reset: true, apply: true };
            }
            else {
                if (options.reset === undefined) {
                    options.reset = true;
                }
                if (options.disable === undefined) {
                    options.disable = true;
                }
                if (options.apply === undefined) {
                    options.apply = options.disable;
                }
            }
            var ops = [];
            if (options.reset) {
                ops.push(operators.tap(function () { return slaveField.reset(); }));
            }
            if (options.disable) {
                ops.push(operators.tap(function () { return slaveField.disable(); }));
                if (options.apply) {
                    slaveField.disable({ onlySelf: true });
                }
            }
            ops.push(operators.filter(function (value) {
                if (!value) {
                    return false;
                }
                else {
                    return value instanceof Array ? value.length > 0 : true;
                }
            }));
            if (options.disable) {
                ops.push(operators.tap(function () { return slaveField.enable(); }));
            }
            if (options.ops) {
                ops.push.apply(ops, __spread(options.ops));
            }
            return masterField.valueChanges.pipe(pipe.pipeFromArray(__spread(ops)));
        };
        return DynFormGroup;
    }(forms.FormGroup));

    var DynFormArray = /** @class */ (function (_super) {
        __extends(DynFormArray, _super);
        function DynFormArray(options, controls) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, controls) || this;
            _this.config = {};
            if (options) {
                _this.key = options.key || '';
                _this.dir = options.dir || '';
            }
            return _this;
        }
        DynFormArray.prototype.add = function (values) {
        };
        return DynFormArray;
    }(forms.FormArray));

    var DynFormControl = /** @class */ (function (_super) {
        __extends(DynFormControl, _super);
        function DynFormControl(options, validator, asyncValidator) {
            var e_1, _a;
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options.defaultValue != undefined ? options.defaultValue : null, validator, asyncValidator) || this;
            _this.config = {};
            _this.key = options.key || '';
            if (options) {
                _this.config.required = options.required != undefined ? options.required : false;
                _this.config.hint = options.hint;
                _this.config.placeholder = options.placeholder;
                _this.config.dir = options.dir || 'ltr';
                _this.config.messages = options.messages || [];
                _this.config.useDefaultErrorMessages = options.useDefaultErrorMessages || false;
                _this.config.loadFn = options.loadFn || null;
                _this.config.disable = options.disable || false;
                _this.config.appearance = options.appearance || 'standard';
                _this.config.compact = options.compact === undefined ? true : options.compact;
                if (_this.config.loadFn) {
                    _this.loadValue(options.defaultValue, _this.config.loadFn, { onlySelf: true });
                }
                if (_this.config.disable) {
                    _this.disable({ onlySelf: true });
                }
                if (validator) {
                    if (validator instanceof Array) {
                        try {
                            for (var validator_1 = __values(validator), validator_1_1 = validator_1.next(); !validator_1_1.done; validator_1_1 = validator_1.next()) {
                                var v = validator_1_1.value;
                                if (v == forms.Validators.required) {
                                    _this.config.required = true;
                                    break;
                                }
                            }
                        }
                        catch (e_1_1) { e_1 = { error: e_1_1 }; }
                        finally {
                            try {
                                if (validator_1_1 && !validator_1_1.done && (_a = validator_1.return)) _a.call(validator_1);
                            }
                            finally { if (e_1) throw e_1.error; }
                        }
                    }
                    else if (validator == forms.Validators.required) {
                        _this.config.required = true;
                    }
                }
            }
            return _this;
        }
        DynFormControl.prototype.removeRequired = function () {
            this.config.required = false;
            this.removeValidator(forms.Validators.required);
            this.updateValueAndValidity();
        };
        DynFormControl.prototype.addRequired = function () {
            this.config.required = true;
            this.setValidator(forms.Validators.required);
            this.updateValueAndValidity();
        };
        DynFormControl.prototype.isRequired = function () {
            return this.isValidator(forms.Validators.required);
        };
        DynFormControl.prototype.isValidator = function (validator) {
            if (!this.validator) {
                return false;
            }
            if (this.validator instanceof Array) {
                return this.validator.find(function (v) { return v == validator; }) != undefined;
            }
            else {
                return this.validator = validator;
            }
        };
        DynFormControl.prototype.setValidator = function (validator) {
            if (!this.isValidator(validator)) {
                if (this.validator instanceof Array) {
                    return this.validator.push(validator);
                }
                else {
                    return this.validator = validator;
                }
            }
        };
        DynFormControl.prototype.removeValidator = function (validator) {
            if (this.isValidator(validator)) {
                if (this.validator instanceof Array) {
                    this.setValidators(this.validator.filter(function (v) { return v != validator; }));
                }
                else {
                    this.setValidators([]);
                }
            }
        };
        DynFormControl.prototype.setLogicalError = function (message) {
            this.logicalErrorMessage = message;
            this.markAsTouched();
            var errors = this.errors;
            if (!errors) {
                errors = {};
            }
            errors.logical = true;
            this.setErrors(errors);
        };
        DynFormControl.prototype.clearLogicalError = function () {
            this.logicalErrorMessage = null;
            if (this.errors) {
                this.errors.logical = false;
                this.setErrors(this.errors);
            }
        };
        DynFormControl.prototype.activateValidators = function () {
        };
        DynFormControl.prototype.setValue = function (value, options) {
            var _this = this;
            if (options && options.loadFn) {
                options.loadFn(value).subscribe(function (result) {
                    _super.prototype.setValue.call(_this, result, options);
                });
            }
            else {
                if (value == null) {
                    _super.prototype.setValue.call(this, '', options);
                }
                else {
                    _super.prototype.setValue.call(this, value, options);
                }
            }
        };
        DynFormControl.prototype.loadValue = function (param, loadFn, options) {
            var _this = this;
            loadFn(param).subscribe(function (result) {
                _super.prototype.setValue.call(_this, result, options);
            });
        };
        return DynFormControl;
    }(forms.FormControl));

    var DynAutoSelectControl = /** @class */ (function (_super) {
        __extends(DynAutoSelectControl, _super);
        function DynAutoSelectControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'autoselect';
            _this.hasValue = false;
            _this.loading = false;
            _this.multiple = false;
            _this.searchable = true;
            _this.clearToggle = false;
            _this.showNone = options['showNone'] || false;
            _this.noneLabel = options['noneLabel'];
            _this.multiple = options['multiple'] || false;
            _this.debounce = options['debounce'] || 500;
            _this.searchable = options['searchable'] || false;
            var debounceOp = operators.debounceTime(200);
            var showTappet = operators.tap(function () { return _this.loading = true; });
            var hideTappet = operators.tap(function () { return _this.loading = false; });
            if (options['bindLabel']) {
                _this.bindLabel = options['bindLabel'];
            }
            else {
                _this.bindLabel = 'name';
            }
            if (options['bindValue']) {
                _this.bindValue = options['bindValue'];
            }
            _this.labelTemplate = options['labelTemplate'];
            _this.optionTemplate = options['optionTemplate'];
            if (options['channel']) {
                _this.channel = options['channel'];
                _this.channel.asEventObservable().subscribe(function (event) {
                    switch (event.observeType) {
                        case amIo.EventType.on_next:
                            _this.loading = true;
                            break;
                        default:
                            _this.loading = false;
                            break;
                    }
                });
                if (_this.searchable) {
                    _this.typeahead$ = new rxjs.Subject();
                    _this.typeahead$.pipe(operators.debounceTime(_this.debounce), operators.distinctUntilChanged()).subscribe(_this.channel);
                }
                else {
                    _this.typeahead$ = null;
                }
                _this.items$ = _this.channel.asObservable();
            }
            _this.valueChanges.subscribe(function (value) {
                _this.checkHasValue(value);
                _this.hasValue = !(!value);
            });
            _this.channel.next();
            return _this;
        }
        DynAutoSelectControl.prototype.checkHasValue = function (value) {
            var _this = this;
            setTimeout(function () {
                if (_this.element) {
                    if (!value || value.length === 0) {
                        _this.element.classList.remove("ng-has-value");
                    }
                    else {
                        _this.element.classList.add("ng-has-value");
                    }
                }
            });
        };
        DynAutoSelectControl.prototype.reload = function (param) {
            this.channel.next(param);
        };
        DynAutoSelectControl.prototype.getCustomPlaceholder = function () {
            return this.isRequired() ? this.config.placeholder + ' *' : this.config.placeholder;
        };
        return DynAutoSelectControl;
    }(DynFormControl));

    //import {LogService, Logger} from "@bi8/am-logger";
    /*@Directive({selector: '[class]'})
    export class Class  {
      @HostBinding('class') @Input('class') className: string = '';
    }*/
    var DynFieldComponent = /** @class */ (function () {
        //@ContentChild('.ng-has-value') stuff;
        //@ViewChildren(Class, {read: ElementRef}) classes: QueryList<ElementRef>;
        function DynFieldComponent(controlContainer, elRef) {
            this.controlContainer = controlContainer;
            this.elRef = elRef;
            this.paths = [];
            this.messages = new Map();
        }
        DynFieldComponent.prototype.ngAfterContentInit = function () {
        };
        DynFieldComponent.prototype.ngAfterViewInit = function () {
            var bling = this.elRef.nativeElement.querySelector('.ng-select-container');
            if (bling) {
                if (this.dfc instanceof DynAutoSelectControl) {
                    this.dfc.element = bling;
                }
            }
            if (this.ngSelect && this.dfc instanceof DynAutoSelectControl) {
                this.dfc.ngSelectComponent = this.ngSelect;
            }
        };
        /*removeClass(){
          if ( this.classes && this.classes.length ) {
            return this
              .classes
              .map((elRef:ElementRef):Element => elRef.nativeElement)
              .filter( (element: Element) => element.classList.remove('ng-has-value'));
          }
        }*/
        DynFieldComponent.prototype.ngOnInit = function () {
            var e_1, _a;
            this.dfc = this.controlContainer.control.get(this.name);
            this.placeholder = this.dfc.config.placeholder;
            this.hint = this.dfc.config.hint;
            try {
                for (var _b = __values(this.dfc.config.messages), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var entry = _c.value;
                    this.messages.set(entry.key, entry.value);
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
            this.path = this.resolvePath();
        };
        DynFieldComponent.prototype.resolvePath = function () {
            var _this = this;
            var paths = [this.dfc.key];
            this.resolveParentPath(this.dfc.parent, paths);
            var resolvedPath = '';
            paths.reverse().forEach(function (path, index) {
                if (path) {
                    if (resolvedPath) {
                        resolvedPath += '.';
                    }
                    resolvedPath += path;
                    _this.paths.push(resolvedPath);
                }
            });
            return resolvedPath;
        };
        DynFieldComponent.prototype.resolveParentPath = function (control, paths) {
            if (control instanceof DynFormGroup) {
                paths.push(control.key);
            }
            else if (control instanceof DynFormArray) {
                paths.push(control.key);
            }
            if (control.parent) {
                this.resolveParentPath(control.parent, paths);
            }
        };
        DynFieldComponent.prototype.resolveValidationMessage = function (type) {
            var message = '';
            if (this.messages.has(type)) {
                message = this.messages.get(type);
            }
            else if (this.dfc.config.useDefaultErrorMessages) {
                switch (type) {
                    case 'required':
                        message = 'Value required';
                        break;
                    case 'pattern':
                        message = 'Invalid format';
                        break;
                    case 'email':
                        message = 'Invalid email';
                        break;
                }
            }
            return message;
        };
        DynFieldComponent.ctorParameters = function () { return [
            { type: forms.ControlContainer, decorators: [{ type: core.Optional }, { type: core.Host }, { type: core.SkipSelf }] },
            { type: core.ElementRef }
        ]; };
        __decorate([
            core.Input(),
            __metadata("design:type", Object)
        ], DynFieldComponent.prototype, "name", void 0);
        __decorate([
            core.ViewChild('ngselect', { static: false }),
            __metadata("design:type", ngSelect.NgSelectComponent)
        ], DynFieldComponent.prototype, "ngSelect", void 0);
        DynFieldComponent = __decorate([
            core.Component({
                selector: 'dyn-field',
                template: "<ng-container [ngSwitch]=\"dfc.type\">\r\n  <div fxLayout=\"row\" class=\"am-field-row\">\r\n    <!--=====[ AUTO SELECT FIELD ]=====-->\r\n    <ng-container *ngSwitchCase=\"'autoselect'\">\r\n      <div class=\"am-field-container\" fxLayout=\"row\" fxFlex>\r\n        <ng-select #ngselect [items]=\"dfc.items$ | async\"\r\n                   [formControl]=\"dfc\"\r\n                   [placeholder]=\"dfc.getCustomPlaceholder()\"\r\n                   [bindLabel]=\"dfc.bindLabel\"\r\n                   [typeahead]=\"dfc.typeahead$\"\r\n                   [loading]=\"dfc.loading\"\r\n                   [bindValue]=\"dfc.bindValue\"\r\n                   [multiple]=\"dfc.multiple\"\r\n                   [searchable]=\"dfc.searchable\"\r\n                   fxFlex=\"1 1 auto\"\r\n                   [ngClass]=\"{'am-has-value': dfc.hasValue, 'am-no-value' : !dfc.hasValue}\"\r\n                   style=\"width: 100px;\">\r\n          <ng-template ng-label-tmp let-item=\"item\" *ngIf=\"dfc.labelTemplate\" let-clear=\"clear\">\r\n            <ng-container [ngTemplateOutlet]=\"dfc.labelTemplate\" [ngTemplateOutletContext]=\"{item: item, clear: clear}\"></ng-container>\r\n          </ng-template>\r\n\r\n          <ng-template ng-option-tmp let-item=\"item\" let-index=\"index\" let-search=\"searchTerm\" *ngIf=\"dfc.optionTemplate\">\r\n            <ng-container [ngTemplateOutlet]=\"dfc.optionTemplate\" [ngTemplateOutletContext]=\"{item: item, index: index, search: search}\"></ng-container>\r\n          </ng-template>\r\n        </ng-select>\r\n        <span class=\"am-select-error\" *ngIf=\"dfc.hasError('required') && dfc.touched\">{{resolveValidationMessage('required')}}</span>\r\n        <span class=\"am-select-error\" *ngIf=\"dfc.hasError('pattern') && dfc.touched\">{{resolveValidationMessage('pattern')}}</span>\r\n        <span class=\"am-select-error\" *ngIf=\"dfc.hasError('email') && dfc.touched\">{{resolveValidationMessage('email')}}</span>\r\n        <span class=\"am-select-error\" *ngIf=\"dfc.hasError('match') && dfc.touched\">{{resolveValidationMessage('match')}}</span>\r\n        <span class=\"am-select-error\" *ngIf=\"dfc.hasError('time') && dfc.touched\">{{resolveValidationMessage('time')}}</span>\r\n        <span class=\"am-select-error\" *ngIf=\"dfc.hasError('logical') && dfc.touched\">{{dfc.logicalErrorMessage}}</span>\r\n      </div>\r\n    </ng-container>\r\n\r\n    <!--=====[ TEXT FIELD ]=====-->\r\n    <mat-form-field *ngSwitchCase=\"'text'\" [hintLabel]=\"hint\" fxFlex>\r\n      <input matInput\r\n             hideRequiredMarker=\"false\"\r\n             [name]=\"dfc.key\"\r\n             [formControl]=\"dfc\"\r\n             [type]=\"dfc.config.format\"\r\n             [placeholder]=\"placeholder\"\r\n             [maxlength]=\"dfc.config.maxlimit\"\r\n             [required]=\"dfc.config.required\"\r\n             [dir]=\"dfc.config.dir\">\r\n\r\n      <mat-hint *ngIf=\"dfc.config.counter && dfc.config.maxlimit\" align=\"end\" class=\"no-text-wrap\">{{dfc.value ? dfc.value.length : 0}} / {{dfc.config.maxlimit}}</mat-hint>\r\n\r\n      <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('pattern')\">{{resolveValidationMessage('pattern')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('email')\">{{resolveValidationMessage('email')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('time')\">{{resolveValidationMessage('time')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n    </mat-form-field>\r\n\r\n    <!--=====[ TEXTAREA FIELD ]=====-->\r\n    <mat-form-field *ngSwitchCase=\"'textarea'\" [hintLabel]=\"hint\" fxFlex>\r\n      <textarea matInput\r\n                hideRequiredMarker=\"false\"\r\n                matTextareaAutosize\r\n                [matAutosizeMinRows]=\"dfc.config.minRows\"\r\n                [matAutosizeMaxRows]=\"dfc.config.maxRows\"\r\n                [name]=\"dfc.key\"\r\n                [formControl]=\"dfc\"\r\n                [placeholder]=\"placeholder\"\r\n                [maxlength]=\"dfc.config.maxlimit\"\r\n                [required]=\"dfc.config.required\"\r\n                [dir]=\"dfc.config.dir\"></textarea>\r\n\r\n      <mat-hint *ngIf=\"dfc.config.counter && dfc.config.maxlimit\" align=\"end\" class=\"no-text-wrap\">{{dfc.value ? dfc.value.length : 0}} / {{dfc.config.maxlimit}}</mat-hint>\r\n      <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('pattern')\">{{resolveValidationMessage('pattern')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('email')\">{{resolveValidationMessage('email')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n      <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n    </mat-form-field>\r\n\r\n    <!--=====[ AUTOCOMPLETE ]=====-->\r\n    <ng-container *ngSwitchCase=\"'auto-complete'\">\r\n      <mat-form-field fxFlex>\r\n        <input matInput\r\n               [name]=\"dfc.key\"\r\n               [placeholder]=\"placeholder\"\r\n               [matAutocomplete]=\"auto\"\r\n               [formControl]=\"dfc\"\r\n               [required]=\"dfc.config.required\"\r\n               [dir]=\"dfc.config.dir\">\r\n\r\n        <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n        <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n        <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n\r\n        <mat-autocomplete #auto=\"matAutocomplete\" [displayWith]=\"dfc.displayFn.bind(dfc)\">\r\n          <mat-option *ngFor=\"let opt of dfc.selectOptions$ | async\" [value]=\"opt\">\r\n            {{dfc.displayFn(opt)}}\r\n          </mat-option>\r\n        </mat-autocomplete>\r\n      </mat-form-field>\r\n    </ng-container>\r\n\r\n    <!--=====[ DATE ]=====-->\r\n    <ng-container *ngSwitchCase=\"'date'\">\r\n      <mat-form-field fxFlex>\r\n        <input matInput\r\n               hideRequiredMarker=\"false\"\r\n               [name]=\"dfc.key\"\r\n               [formControl]=\"dfc\"\r\n               type=\"text\"\r\n               [min]=\"dfc.minDate\"\r\n               [max]=\"dfc.maxDate\"\r\n               [required]=\"dfc.config.required\"\r\n               [matDatepicker]=\"picker\"\r\n               [placeholder]=\"placeholder\"\r\n               style=\"pointer-events:none;\" />\r\n\r\n        <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n        <mat-datepicker #picker></mat-datepicker>\r\n\r\n        <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n        <mat-error *ngIf=\"dfc.hasError('pattern')\">{{resolveValidationMessage('pattern')}}</mat-error>\r\n        <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n        <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n      </mat-form-field>\r\n    </ng-container>\r\n\r\n    <!--=====[ DATE ]=====-->\r\n    <ng-container *ngSwitchCase=\"'time'\">\r\n      <am-timepicker [formControl]=\"dfc\"></am-timepicker>\r\n    </ng-container>\r\n\r\n    <!--=====[ SELECT FIELD ]=====-->\r\n    <ng-container *ngSwitchCase=\"'select'\" >\r\n      <mat-form-field fxFlex>\r\n        <mat-select [formControl]=\"dfc\"\r\n                   [placeholder]=\"placeholder\"\r\n                   [required]=\"dfc.config.required\"\r\n                   required=\"true\"\r\n                   [multiple]=\"dfc.multiple\">\r\n          <mat-option *ngIf=\"dfc.showNone\" (click)=\"dfc.reset()\">{{dfc.noneLabel}}</mat-option>\r\n          <mat-option *ngFor=\"let opt of dfc.selectOptions$ | async\" [value]=\"opt.code\">{{opt.value}}</mat-option>\r\n        </mat-select>\r\n        <mat-error *ngIf=\"dfc.hasError('required') && dfc.touched\">This option is required</mat-error>\r\n      </mat-form-field>\r\n    </ng-container>\r\n\r\n    <!--=====[ CHECK BOX ]=====-->\r\n    <ng-container *ngSwitchCase=\"'checkbox'\">\r\n      <mat-checkbox [formControl]=\"dfc\" fxFlex>\r\n        {{placeholder}}\r\n      </mat-checkbox>\r\n    </ng-container>\r\n\r\n    <!--=====[ LABEL ]=====-->\r\n    <ng-container *ngSwitchCase=\"'label'\">\r\n      <div fxFlex>{{placeholder}}</div>\r\n    </ng-container>\r\n  </div>\r\n</ng-container>\r\n",
                styles: [""]
            }),
            __param(0, core.Optional()), __param(0, core.Host()), __param(0, core.SkipSelf()),
            __metadata("design:paramtypes", [forms.ControlContainer, core.ElementRef])
        ], DynFieldComponent);
        return DynFieldComponent;
    }());

    var DynToolbarPanelComponent = /** @class */ (function () {
        function DynToolbarPanelComponent() {
        }
        DynToolbarPanelComponent.prototype.ngOnInit = function () {
        };
        __decorate([
            core.Input(),
            __metadata("design:type", String)
        ], DynToolbarPanelComponent.prototype, "header", void 0);
        DynToolbarPanelComponent = __decorate([
            core.Component({
                selector: 'dyn-toolbar-panel',
                template: "<mat-card class=\"container\">\r\n  <mat-toolbar *ngIf=\"header\" color=\"primary\"> {{header}}</mat-toolbar>\r\n  <div class=\"body\">\r\n    <ng-content></ng-content>\r\n  </div>\r\n</mat-card>\r\n",
                styles: [""]
            }),
            __metadata("design:paramtypes", [])
        ], DynToolbarPanelComponent);
        return DynToolbarPanelComponent;
    }());

    var DynFieldSetComponent = /** @class */ (function () {
        function DynFieldSetComponent() {
        }
        DynFieldSetComponent.prototype.ngOnInit = function () {
        };
        __decorate([
            core.Input(),
            __metadata("design:type", String)
        ], DynFieldSetComponent.prototype, "header", void 0);
        DynFieldSetComponent = __decorate([
            core.Component({
                selector: 'dyn-field-set',
                template: "<fieldset>\r\n  <legend *ngIf=\"header\">{{header}}</legend>\r\n  <ng-content></ng-content>\r\n</fieldset>\r\n",
                styles: [""]
            }),
            __metadata("design:paramtypes", [])
        ], DynFieldSetComponent);
        return DynFieldSetComponent;
    }());

    var AmTimepickerComponent = /** @class */ (function () {
        function AmTimepickerComponent(_elementRef) {
            this._elementRef = _elementRef;
            this._cvaOnChange = function () { };
            this._validatorOnChange = function () { };
            this._onTouched = function () { };
            this.timeForm = new forms.FormGroup({
                hours: new forms.FormControl(),
                minutes: new forms.FormControl(),
                amPm: new forms.FormControl()
            });
        }
        AmTimepickerComponent_1 = AmTimepickerComponent;
        Object.defineProperty(AmTimepickerComponent.prototype, "minHours", {
            set: function (minHours) {
                this._minHours = minHours;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AmTimepickerComponent.prototype, "maxHours", {
            set: function (maxHours) {
                this._maxHours = maxHours;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AmTimepickerComponent.prototype, "disabled", {
            get: function () { return !!this._disabled; },
            set: function (value) {
                var newValue = coercion.coerceBooleanProperty(value);
                if (this._disabled !== newValue) {
                    this._disabled = newValue;
                }
            },
            enumerable: true,
            configurable: true
        });
        AmTimepickerComponent.prototype.ngAfterContentInit = function () {
        };
        AmTimepickerComponent.prototype.ngOnDestroy = function () {
        };
        AmTimepickerComponent.prototype.writeValue = function (value) {
            this._data = value;
            console.log("writeValue: ", value);
        };
        AmTimepickerComponent.prototype.registerOnChange = function (fn) {
            this._cvaOnChange = fn;
            console.log("registerOnChange:", fn);
        };
        AmTimepickerComponent.prototype.registerOnTouched = function (fn) {
            this._onTouched = fn;
            console.log("registerOnTouch: ", fn);
        };
        AmTimepickerComponent.prototype.setDisabledState = function (disabled) {
            this.disabled = disabled;
            console.log("setDisabled: ", disabled);
        };
        var AmTimepickerComponent_1;
        AmTimepickerComponent.ctorParameters = function () { return [
            { type: core.ElementRef }
        ]; };
        __decorate([
            core.Input(),
            __metadata("design:type", Number),
            __metadata("design:paramtypes", [Number])
        ], AmTimepickerComponent.prototype, "minHours", null);
        __decorate([
            core.Input(),
            __metadata("design:type", Number),
            __metadata("design:paramtypes", [Number])
        ], AmTimepickerComponent.prototype, "maxHours", null);
        __decorate([
            core.Input(),
            __metadata("design:type", Object),
            __metadata("design:paramtypes", [Object])
        ], AmTimepickerComponent.prototype, "disabled", null);
        AmTimepickerComponent = AmTimepickerComponent_1 = __decorate([
            core.Component({
                selector: 'am-timepicker',
                template: "<form [formGroup]=\"timeForm\" novalidate style=\"display: flex; flex-direction: row;\">\r\n  <mat-form-field style=\"width: 40px; padding-right: 5px;\">\r\n    <mat-select formControlName=\"hours\">\r\n      <mat-option value=\"1\">&nbsp;1</mat-option>\r\n      <mat-option value=\"2\">2</mat-option>\r\n      <mat-option value=\"3\">3</mat-option>\r\n      <mat-option value=\"4\">4</mat-option>\r\n      <mat-option value=\"5\">5</mat-option>\r\n      <mat-option value=\"6\">6</mat-option>\r\n      <mat-option value=\"7\">7</mat-option>\r\n      <mat-option value=\"8\">8</mat-option>\r\n      <mat-option value=\"9\">9</mat-option>\r\n      <mat-option value=\"10\">10</mat-option>\r\n      <mat-option value=\"11\">11</mat-option>\r\n      <mat-option value=\"12\">12</mat-option>\r\n    </mat-select>\r\n  </mat-form-field>\r\n  <mat-form-field style=\"width: 40px; padding-right: 5px;\">\r\n    <mat-select formControlName=\"minutes\">\r\n      <mat-option value=\"1\">00</mat-option>\r\n      <mat-option value=\"1\">05</mat-option>\r\n      <mat-option value=\"2\">10</mat-option>\r\n      <mat-option value=\"3\">15</mat-option>\r\n      <mat-option value=\"4\">20</mat-option>\r\n      <mat-option value=\"5\">25</mat-option>\r\n      <mat-option value=\"6\">30</mat-option>\r\n      <mat-option value=\"7\">35</mat-option>\r\n      <mat-option value=\"8\">40</mat-option>\r\n      <mat-option value=\"9\">45</mat-option>\r\n      <mat-option value=\"10\">50</mat-option>\r\n      <mat-option value=\"11\">55</mat-option>\r\n    </mat-select>\r\n  </mat-form-field>\r\n  <mat-form-field style=\"width: 50px;\">\r\n    <mat-select formControlName=\"amPm\">\r\n      <mat-option value=\"am\">AM</mat-option>\r\n      <mat-option value=\"pm\">PM</mat-option>\r\n    </mat-select>\r\n  </mat-form-field>\r\n</form>\r\n",
                providers: [
                    {
                        provide: forms.NG_VALUE_ACCESSOR,
                        useExisting: core.forwardRef(function () { return AmTimepickerComponent_1; }),
                        multi: true
                    }
                ]
            }),
            __metadata("design:paramtypes", [core.ElementRef])
        ], AmTimepickerComponent);
        return AmTimepickerComponent;
    }());

    var AmDynFormModule = /** @class */ (function () {
        function AmDynFormModule() {
        }
        AmDynFormModule = __decorate([
            core.NgModule({
                imports: [
                    common.CommonModule,
                    router.RouterModule,
                    animations.BrowserAnimationsModule,
                    forms.FormsModule,
                    forms.ReactiveFormsModule,
                    flexLayout.FlexLayoutModule,
                    material.MatAutocompleteModule,
                    material.MatCardModule,
                    material.MatButtonModule,
                    material.MatCheckboxModule,
                    material.MatDatepickerModule,
                    material.MatNativeDateModule,
                    material.MatTooltipModule,
                    material.MatInputModule,
                    material.MatSelectModule,
                    material.MatOptionModule,
                    material.MatDialogModule,
                    material.MatToolbarModule,
                    material.MatIconModule,
                    material.MatSidenavModule,
                    material.MatMenuModule,
                    material.MatTableModule,
                    material.MatListModule,
                    ngSelect.NgSelectModule
                ],
                exports: [
                    DynFieldComponent,
                    DynFieldSetComponent,
                    DynToolbarPanelComponent,
                    AmTimepickerComponent
                ],
                declarations: [
                    DynFieldComponent,
                    DynFieldSetComponent,
                    DynToolbarPanelComponent,
                    AmTimepickerComponent
                ],
                providers: [DynFormService]
            })
        ], AmDynFormModule);
        return AmDynFormModule;
    }());

    var DynTextControl = /** @class */ (function (_super) {
        __extends(DynTextControl, _super);
        function DynTextControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'text';
            _this.config.format = options['format'] || 'text';
            _this.config.counter = options['counter'] != undefined ? options['counter'] : true;
            _this.config.maxlimit = options['maxlimit'];
            return _this;
        }
        return DynTextControl;
    }(DynFormControl));

    var DynTextareaControl = /** @class */ (function (_super) {
        __extends(DynTextareaControl, _super);
        function DynTextareaControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'textarea';
            _this.config.minRows = options['minRows'] || null;
            _this.config.maxRows = options['maxRows'] || null;
            _this.config.maxlimit = options['maxlimit'];
            return _this;
        }
        return DynTextareaControl;
    }(DynFormControl));

    var DynAutoCompleteControl = /** @class */ (function (_super) {
        __extends(DynAutoCompleteControl, _super);
        function DynAutoCompleteControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'auto-complete';
            _this.selectOptions$ = new rxjs.Subject();
            _this.total = 0;
            _this.items = [];
            _this.loader = options['loader'];
            // load the initial values after the first tick
            setTimeout(function () {
                _this.loadValues(null);
            }, 0);
            _this.valueChanges.subscribe(function (value) {
                _this.loadValues(value);
            });
            return _this;
        }
        DynAutoCompleteControl.prototype.loadValues = function (value) {
            var _this = this;
            //console.log("loading values: ", value);
            this.loader.prepare({
                value: value
            }).subscribe(function (result) {
                _this.total = result.total;
                _this.items = result.items;
                _this.selectOptions$.next(_this.items);
            });
        };
        DynAutoCompleteControl.prototype.displayFn = function (item) {
            return lodash.get(item, this.loader.valueProperty);
        };
        return DynAutoCompleteControl;
    }(DynFormControl));
    var ArrayAutoCompleteLoader = /** @class */ (function () {
        function ArrayAutoCompleteLoader(items, filterFn, options) {
            this.items = items;
            this.filterFn = filterFn;
            this.size = !lodash.isNil(options.size) ? options.size : 15;
            this.page = !lodash.isNil(options.page) ? options.page : 0;
            this.codeProperty = !lodash.isNil(options.codeProperty) ? options.codeProperty : 'code';
            this.valueProperty = !lodash.isNil(options.valueProperty) ? options.valueProperty : 'value';
        }
        ArrayAutoCompleteLoader.prototype.prepare = function (value) {
            var _this = this;
            return rxjs.of(this.items).pipe(operators.map(function (items) {
                var filteredList = [];
                // note that when the actual selection takes place, the value will be the actual selected object
                // and not the string that we expect.  If it is an object, there is no reason for loading the list
                var isObject$1 = lodash.isObject(value);
                items.forEach(function (item, index) {
                    var itemValue = lodash.get(item, _this.valueProperty);
                    if (isObject$1 || _this.filterFn(item, value.value)) {
                        filteredList.push(item);
                    }
                });
                return _this.processResponse({
                    total: filteredList.length,
                    items: filteredList.length > 0 ? lodash.chunk(filteredList, _this.size)[_this.page] : filteredList
                });
            }));
        };
        ArrayAutoCompleteLoader.prototype.processResponse = function (response) {
            return response;
        };
        return ArrayAutoCompleteLoader;
    }());
    var ObservableAutoCompleteLoader = /** @class */ (function () {
        function ObservableAutoCompleteLoader(loadFn, options) {
            this.loadFn = loadFn;
            if (options) {
                this.size = lodash.isNil(options.size) ? options.size : 15;
                this.page = lodash.isNil(options.page) ? options.page : 0;
            }
        }
        ObservableAutoCompleteLoader.prototype.prepare = function (value) {
            var _this = this;
            var ctx = {
                size: this.size,
                page: this.page,
                value: value
            };
            return this.loadFn(ctx).pipe(operators.map(function (response) {
                return _this.processResponse(response);
            }));
        };
        ObservableAutoCompleteLoader.prototype.processResponse = function (response) {
            return {
                total: response.total,
                items: response.results
            };
        };
        return ObservableAutoCompleteLoader;
    }());
    var KeywordAutoCompleteCriteriaLoader = /** @class */ (function () {
        function KeywordAutoCompleteCriteriaLoader(loadFn, options) {
            this.loadFn = loadFn;
            if (options) {
                this.size = lodash.isNil(options.size) ? options.size : 50;
                this.page = lodash.isNil(options.page) ? options.page : 0;
                this.inclusive = lodash.isNil(options.inclusive) ? options.inclusive : true;
                this.keywordProperty = options.keywordProperty;
                this.codeProperty = !lodash.isNil(options.codeProperty) ? options.codeProperty : 'code';
                this.valueProperty = !lodash.isNil(options.valueProperty) ? options.valueProperty : 'value';
            }
        }
        KeywordAutoCompleteCriteriaLoader.prototype.resolveContext = function (value) {
            var ctx = {
                size: this.size,
                page: this.page,
                inclusive: this.inclusive,
                criteria: []
            };
            if (this.keywordProperty && !lodash.isObject(value)) {
                ctx[this.keywordProperty] = value;
            }
            return ctx;
        };
        KeywordAutoCompleteCriteriaLoader.prototype.prepare = function (value) {
            var _this = this;
            var ctx = this.resolveContext(value);
            return this.loadFn(ctx).pipe(operators.map(function (response) {
                return _this.processResponse(response);
            }));
        };
        KeywordAutoCompleteCriteriaLoader.prototype.processResponse = function (response) {
            return {
                total: response.total,
                items: response.results
            };
        };
        return KeywordAutoCompleteCriteriaLoader;
    }());

    var DynCheckboxControl = /** @class */ (function (_super) {
        __extends(DynCheckboxControl, _super);
        function DynCheckboxControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'checkbox';
            _this.config.leadingLabel = options['leadingLabel'];
            return _this;
        }
        return DynCheckboxControl;
    }(DynFormControl));

    var DynDateControl = /** @class */ (function (_super) {
        __extends(DynDateControl, _super);
        function DynDateControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'date';
            _this.minDate = options['minDate'] || null;
            _this.maxDate = options['maxDate'] || null;
            return _this;
        }
        return DynDateControl;
    }(DynFormControl));

    var DynSelectControl = /** @class */ (function (_super) {
        __extends(DynSelectControl, _super);
        function DynSelectControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'select';
            _this.selectOptions$ = options['selectOptions'] || [];
            _this.showNone = options['showNone'] || false;
            _this.noneLabel = options['noneLabel'];
            _this.multiple = options['multiple'] || false;
            return _this;
        }
        DynSelectControl.prototype.setValue = function (value, options) {
            if (value == null) {
                _super.prototype.setValue.call(this, '', options);
            }
            else {
                _super.prototype.setValue.call(this, value, options);
            }
        };
        return DynSelectControl;
    }(DynFormControl));

    var moment = moment_;
    function DynMatchValidator(otherControlName) {
        var thisControl;
        var otherControl;
        return function matchOtherValidate(control) {
            if (!control.parent) {
                return null;
            }
            // Initializing the validator.
            if (!thisControl) {
                thisControl = control;
                otherControl = control.parent.get(otherControlName);
                if (!otherControl) {
                    throw new Error('matchOtherValidator(): other control is not found in parent group');
                }
                otherControl.valueChanges.subscribe(function () {
                    thisControl.updateValueAndValidity();
                });
            }
            if (!otherControl) {
                return null;
            }
            if (otherControl.value !== thisControl.value) {
                return {
                    match: true
                };
            }
            return null;
        };
    }
    function BusinessLogicValidator() {
        return function matchOtherValidate(control) {
            if (!control.parent) {
                return null;
            }
            return null;
        };
    }
    var TimeUtils = /** @class */ (function () {
        function TimeUtils() {
        }
        TimeUtils.parseTime = function (value) {
            var e_1, _a, e_2, _b;
            if (!value) {
                return null;
            }
            var formats = ['HH:mm', 'H:mm'];
            try {
                for (var formats_1 = __values(formats), formats_1_1 = formats_1.next(); !formats_1_1.done; formats_1_1 = formats_1.next()) {
                    var format = formats_1_1.value;
                    var dt = moment(value, format, true);
                    if (dt.isValid()) {
                        return {
                            hours: dt.hours(),
                            minutes: dt.minutes(),
                            is24Hour: true
                        };
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (formats_1_1 && !formats_1_1.done && (_a = formats_1.return)) _a.call(formats_1);
                }
                finally { if (e_1) throw e_1.error; }
            }
            formats = ['hh:mm a', 'hh:mma', 'h:mm a', 'h:mma', 'h:m a', 'h:ma'];
            try {
                for (var formats_2 = __values(formats), formats_2_1 = formats_2.next(); !formats_2_1.done; formats_2_1 = formats_2.next()) {
                    var format = formats_2_1.value;
                    var dt = moment(value, format, true);
                    if (dt.isValid()) {
                        return {
                            hours: dt.hours(),
                            minutes: dt.minutes(),
                            is24Hour: false
                        };
                    }
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (formats_2_1 && !formats_2_1.done && (_b = formats_2.return)) _b.call(formats_2);
                }
                finally { if (e_2) throw e_2.error; }
            }
            return null;
        };
        TimeUtils.formatTime = function (date) {
            if (date) {
                return date.format('hh:mm a');
            }
            else if (date) {
                return moment(date).format('hh:mm a');
            }
        };
        TimeUtils.applyTime = function (date, time) {
            if (date) {
                var md = date;
                md.hours(time.hours);
                md.minutes(time.minutes);
            }
            else if (date) {
                var md = moment(date);
                md.hours(time.hours);
                md.minutes(time.minutes);
            }
        };
        return TimeUtils;
    }());
    function TimeValidator() {
        return function (control) {
            var value = control.value;
            if (value) {
                var td = TimeUtils.parseTime(value);
                if (td != null) {
                    return null;
                }
                else {
                    return { time: true };
                }
            }
            else {
                return null;
            }
        };
    }

    var DynHiddenControl = /** @class */ (function (_super) {
        __extends(DynHiddenControl, _super);
        function DynHiddenControl(options, validator, asyncValidator) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, options, validator, asyncValidator) || this;
            _this.type = 'hidden';
            return _this;
        }
        return DynHiddenControl;
    }(DynFormControl));


    (function (NotificationType) {
        NotificationType["init"] = "init";
        NotificationType["busy"] = "busy";
        NotificationType["idle"] = "idle";
        NotificationType["paramFunc"] = "paramFunc";
        NotificationType["inputNext"] = "inputNext";
        NotificationType["inputComplete"] = "inputComplete";
        NotificationType["inputError"] = "inputError";
        NotificationType["outputFuncError"] = "outputFuncError";
        NotificationType["outputNext"] = "outputNext";
        NotificationType["outputError"] = "outputError";
        NotificationType["outputComplete"] = "outputComplete";
        NotificationType["close"] = "close";
        NotificationType["enable"] = "enable";
        NotificationType["disable"] = "disable";
    })(exports.NotificationType || (exports.NotificationType = {}));
    var Channel = /** @class */ (function () {
        function Channel(fn, options) {
            var _this = this;
            this.fn = fn;
            this.closed = false;
            this.enabled = true;
            if (options) {
                this.input = options.input || new rxjs.Subject();
                this.output = options.output || new rxjs.ReplaySubject(1);
                this.enabled = options.enabled || true;
                this.name = options.name || 'channel';
                this.debug = options.debug || false;
                this.paramFn = options.paramFn;
                this.notificationFn = options.notificationFn;
            }
            else {
                this.input = new rxjs.Subject();
                this.output = new rxjs.ReplaySubject(1);
                this.enabled = true;
                this.name = 'channel';
                this.debug = false;
            }
            this.notifications = new rxjs.BehaviorSubject({ type: exports.NotificationType.init });
            //this.observeNotifications().subscribe();
            if (this.notificationFn) {
                this.observeNotifications().subscribe(this.notificationFn);
            }
            this.input.pipe(operators.takeWhile(function (value) { return !_this.closed; }), operators.filter(function (value) { return _this.enabled; }), operators.map(function (input) {
                _this.emitNotification({ type: exports.NotificationType.busy });
                if (_this.paramFn) {
                    var result = _this.paramFn(input);
                    _this.emitNotification({ type: exports.NotificationType.paramFunc, data: { before: input, after: result } });
                    return result;
                }
                else {
                    return input;
                }
            }), operators.tap(function (data) {
                _this.inputBusy = true;
                _this.emitNotification({ type: exports.NotificationType.inputNext, data: data });
            })).subscribe({
                next: function (value) {
                    try {
                        _this.outputBusy = true;
                        var observable = _this.fn(value);
                        observable.pipe(operators.tap(function (data) {
                            _this.emitNotification({ type: exports.NotificationType.outputNext, data: data });
                        })).subscribe({
                            next: function (response) { return _this.output.next(response); },
                            error: function (err) {
                                _this.emitNotification({ type: exports.NotificationType.outputError, error: err });
                                _this.output.error(err);
                            },
                            complete: function () {
                                _this.outputBusy = false;
                                _this.emitNotification({ type: exports.NotificationType.outputComplete });
                                _this.emitNotification({ type: exports.NotificationType.idle });
                            }
                        });
                    }
                    catch (err) {
                        _this.emitNotification({ type: exports.NotificationType.outputFuncError, error: err });
                        _this.outputBusy = false;
                    }
                },
                error: function (err) {
                    _this.emitNotification({ type: exports.NotificationType.outputFuncError, error: err });
                },
                complete: function () {
                    _this.inputBusy = false;
                }
            });
        }
        Channel.prototype.isBusy = function () {
            return this.inputBusy || this.outputBusy;
        };
        Channel.prototype.isInputBusy = function () {
            return this.inputBusy;
        };
        Channel.prototype.isOutputBusy = function () {
            return this.outputBusy;
        };
        Channel.prototype.next = function (value) {
            this.input.next(value);
            return this;
        };
        Channel.prototype.emit = function (value) {
            this.output.next(value);
        };
        Channel.prototype.observe = function (value) {
            var _this = this;
            var ops = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                ops[_i - 1] = arguments[_i];
            }
            setInterval(function () {
                _this.next(value);
            });
            return this.output.pipe(pipe.pipeFromArray(__spread(ops)));
        };
        Channel.prototype.link = function (observer) {
            var _this = this;
            var ops = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                ops[_i - 1] = arguments[_i];
            }
            observer.pipe(pipe.pipeFromArray(__spread(ops))).subscribe(function (value) { return _this.next(value); });
        };
        Channel.prototype.pipe = function (observer) {
            var _this = this;
            var ops = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                ops[_i - 1] = arguments[_i];
            }
            observer.pipe(pipe.pipeFromArray(__spread(ops))).subscribe(function (value) { return _this.emit(value); });
        };
        Channel.prototype.asObservable = function () {
            return this.output.asObservable();
        };
        Channel.prototype.observeNotifications = function () {
            return this.notifications.asObservable();
        };
        Channel.prototype.emitNotification = function (notification) {
            notification.name = this.name;
            if (this.debug) {
                switch (notification.type) {
                    case exports.NotificationType.inputError:
                    case exports.NotificationType.outputError:
                    case exports.NotificationType.outputFuncError:
                        console.error("[" + notification.name + ":" + notification.type + "] ", notification.error || '');
                        break;
                    default:
                        console.debug("[" + notification.name + ":" + notification.type + "] ", notification.data || '');
                        break;
                }
            }
            this.notifications.next(notification);
        };
        Channel.prototype.enable = function () {
            this.enabled = false;
            return this;
        };
        Channel.prototype.disable = function () {
            this.enabled = true;
            return this;
        };
        Channel.prototype.close = function () {
            this.closed = true;
            this.input.unsubscribe();
            this.output.unsubscribe();
        };
        return Channel;
    }());
    var ChannelSwitch = /** @class */ (function () {
        function ChannelSwitch() {
            var _this = this;
            var channels = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                channels[_i] = arguments[_i];
            }
            this.channels = new Map();
            channels.forEach(function (config) {
                _this.channels.set(config.key, config.channel);
            });
        }
        ChannelSwitch.prototype.set = function (key, channel) {
            this.channels.set(key, channel);
            return channel;
        };
        ChannelSwitch.prototype.get = function (key) {
            return this.channels.get(key);
        };
        ChannelSwitch.prototype.isBusy = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.isBusy() : false;
        };
        ChannelSwitch.prototype.isInputBusy = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.isInputBusy() : false;
        };
        ChannelSwitch.prototype.isOutputBusy = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.isOutputBusy() : false;
        };
        ChannelSwitch.prototype.next = function (key, value) {
            var channel = this.channels.get(key);
            return channel ? channel.next(value) : null;
        };
        ChannelSwitch.prototype.emit = function (key, value) {
            var channel = this.channels.get(key);
            return channel ? channel.emit(value) : false;
        };
        ChannelSwitch.prototype.observe = function (key, value) {
            var ops = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                ops[_i - 2] = arguments[_i];
            }
            var channel = this.channels.get(key);
            return channel ? channel.observe.apply(channel, __spread([value], ops)) : null;
        };
        ChannelSwitch.prototype.link = function (key, observer) {
            var ops = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                ops[_i - 2] = arguments[_i];
            }
            var channel = this.channels.get(key);
            if (channel) {
                channel.link.apply(channel, __spread([observer], ops));
            }
        };
        ChannelSwitch.prototype.pipe = function (key, observer) {
            var ops = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                ops[_i - 2] = arguments[_i];
            }
            var channel = this.channels.get(key);
            if (channel) {
                channel.pipe.apply(channel, __spread([observer], ops));
            }
        };
        ChannelSwitch.prototype.asObservable = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.asObservable() : null;
        };
        ChannelSwitch.prototype.observeNotifications = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.observeNotifications() : null;
        };
        ChannelSwitch.prototype.enable = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.enable() : null;
        };
        ChannelSwitch.prototype.disable = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.disable() : null;
        };
        ChannelSwitch.prototype.close = function (key) {
            var channel = this.channels.get(key);
            return channel ? channel.close() : null;
        };
        return ChannelSwitch;
    }());
    var DSPipe = /** @class */ (function () {
        function DSPipe(ds, key, obs, ops, enabled) {
            if (enabled === void 0) { enabled = true; }
            this.ds = ds;
            this.key = key;
            this.obs = obs;
            this.ops = ops;
            this.enabled = enabled;
            this.connect();
        }
        DSPipe.prototype.isConnected = function () {
            return !(!this.sub);
        };
        DSPipe.prototype.connect = function () {
            var _this = this;
            if (this.isConnected()) {
                return;
            }
            this.sub = this.obs.pipe(pipe.pipeFromArray(__spread(this.ops))).subscribe(function (value) {
                console.log("----> pipe (" + _this.key + ")", value);
                _this.ds.next(_this.key, value);
            });
        };
        DSPipe.prototype.disconnect = function () {
            if (!this.isConnected()) {
                return;
            }
            this.sub.unsubscribe();
        };
        DSPipe.prototype.setOperators = function () {
            var ops = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                ops[_i] = arguments[_i];
            }
            this.disconnect();
            this.ops = ops;
            this.connect();
        };
        DSPipe.prototype.enable = function () {
            this.enabled = true;
        };
        DSPipe.prototype.disable = function () {
            this.enabled = false;
        };
        return DSPipe;
    }());
    var ObservableDS = /** @class */ (function () {
        function ObservableDS(options) {
            this.connected = false;
            this.fnMap = new Map();
            this.subjectMap = new Map();
            this.input$ = new rxjs.Subject();
            this.inputSub = null;
            this.events$ = new rxjs.Subject();
            this.pipes = [];
            if (options) {
                if (options.autoconnect) {
                    this.connect();
                }
                if (options.key && options.obs) {
                    this.addObservable(options.key, options.obs);
                }
            }
            else {
                // we connect by default
                this.connect();
            }
        }
        ObservableDS.prototype.isConnected = function () {
            return !(!this.inputSub);
        };
        ObservableDS.prototype.connect = function () {
            var _this = this;
            if (this.isConnected()) {
                return;
            }
            this.inputSub = this.input$.pipe(operators.filter(function (input) {
                if (_this.fnMap.has(input.id)) {
                    return true;
                }
                console.error("[obs] observable with id '" + input.id + "' not found");
                return false;
            }), operators.map(function (input) {
                var obsFn = _this.fnMap.get(input.id);
                return { event: input, fn: obsFn(input.value), sub: _this.subjectMap.get(input.id) };
            }))
                .subscribe(function (input) { return _this.relay(input.event, input.fn, input.sub); });
            this.connected = true;
        };
        ObservableDS.prototype.relay = function (event, obs, subject) {
            var _this = this;
            //console.log(`-----> relay (${subject}: `, event);
            obs.pipe(operators.takeWhile(function () { return _this.connected; }), 
            //tap((response) => { console.log(`-----> tap relay: `, response); subject.next(response) }),
            operators.tap(function (response) { return _this.emit({ input: event, output: response }); })).subscribe();
        };
        ObservableDS.prototype.emit = function (event) {
            this.events$.next(event);
        };
        ObservableDS.prototype.asObservable = function () {
            return this.events$.asObservable();
        };
        ObservableDS.prototype.disconnect = function () {
            if (!this.isConnected()) {
                return;
            }
            this.inputSub.unsubscribe();
            var bla = of.of([1, 2, 3]);
            var blaf = bla.subscribe();
            blaf.add(blaf);
            var duff = new rxjs.Subject();
            blaf.add(duff.asObservable().subscribe());
        };
        ObservableDS.prototype.next = function (key, value, options) {
            if (!this.connected) {
                return;
            }
            var event = { id: key, options: options, value: value };
            //console.log(`-----> next (${event})`, event);
            this.input$.next(event);
        };
        ObservableDS.prototype.addPipe = function (obs, key) {
            var operators = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                operators[_i - 2] = arguments[_i];
            }
            var pipe = new DSPipe(this, key, obs, operators);
            this.pipes.push(pipe);
            return pipe;
        };
        ObservableDS.prototype.clearPipes = function () {
            var pipes = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                pipes[_i] = arguments[_i];
            }
            pipes.forEach(function (pipe, index) {
                pipe.disconnect();
                pipes = pipes.splice(index, 1);
            });
        };
        ObservableDS.prototype.clearAllPipes = function () {
            this.clearPipes.apply(this, __spread(this.pipes));
        };
        ObservableDS.prototype.getPipes = function () {
            return this.pipes;
        };
        ObservableDS.prototype.addObservable = function (key, obs, options) {
            if (!options) {
                options = { behave: true };
            }
            this.fnMap.set(key, obs instanceof rxjs.Observable ? function () { return obs; } : obs);
            this.subjectMap.set(key, options.behave ? new rxjs.BehaviorSubject([]) : new rxjs.Subject());
        };
        ObservableDS.prototype.observe = function (key, value, options) {
            var subject = this.subjectMap.get(key);
            try {
                return subject.asObservable();
            }
            finally {
                if (value) {
                    this.next(key, value);
                }
            }
        };
        ObservableDS.prototype.destroy = function () {
        };
        return ObservableDS;
    }());

    exports.AmDynFormModule = AmDynFormModule;
    exports.ArrayAutoCompleteLoader = ArrayAutoCompleteLoader;
    exports.BusinessLogicValidator = BusinessLogicValidator;
    exports.Channel = Channel;
    exports.ChannelSwitch = ChannelSwitch;
    exports.DSPipe = DSPipe;
    exports.DynAutoCompleteControl = DynAutoCompleteControl;
    exports.DynAutoSelectControl = DynAutoSelectControl;
    exports.DynCheckboxControl = DynCheckboxControl;
    exports.DynDateControl = DynDateControl;
    exports.DynFieldComponent = DynFieldComponent;
    exports.DynFieldSetComponent = DynFieldSetComponent;
    exports.DynFormArray = DynFormArray;
    exports.DynFormControl = DynFormControl;
    exports.DynFormGroup = DynFormGroup;
    exports.DynFormService = DynFormService;
    exports.DynHiddenControl = DynHiddenControl;
    exports.DynMatchValidator = DynMatchValidator;
    exports.DynSelectControl = DynSelectControl;
    exports.DynTextControl = DynTextControl;
    exports.DynTextareaControl = DynTextareaControl;
    exports.DynToolbarPanelComponent = DynToolbarPanelComponent;
    exports.KeywordAutoCompleteCriteriaLoader = KeywordAutoCompleteCriteriaLoader;
    exports.ObservableAutoCompleteLoader = ObservableAutoCompleteLoader;
    exports.ObservableDS = ObservableDS;
    exports.TimeUtils = TimeUtils;
    exports.TimeValidator = TimeValidator;
    exports.ɵa = AmTimepickerComponent;

    Object.defineProperty(exports, '__esModule', { value: true });

}));
//# sourceMappingURL=bi8-am-dyn-form.umd.js.map