@ngqp/core
Version:
2,269 lines • 102 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@angular/forms'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('@ngqp/core', ['exports', '@angular/core', '@angular/router', 'rxjs', 'rxjs/operators', '@angular/forms', '@angular/common'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ngqp = global.ngqp || {}, global.ngqp.core = {}), global.ng.core, global.ng.router, global.rxjs, global.rxjs.operators, global.ng.forms, global.ng.common));
}(this, (function (exports, i0, router, rxjs, operators, forms, common) { 'use strict';
/** @internal */
// tslint:disable-next-line:triple-equals
var LOOSE_IDENTITY_COMPARATOR = function (a, b) { return a == b; };
/** @internal */
var NOP = function () { };
/** @internal */
function isMissing(obj) {
return obj === undefined || obj === null;
}
/** @internal */
function undefinedToNull(obj) {
if (obj === undefined) {
return null;
}
return obj;
}
/** @internal */
function isPresent(obj) {
return !isMissing(obj);
}
/** @internal */
function isFunction(obj) {
return isPresent(obj) && typeof obj === 'function';
}
/** @internal */
function wrapTryCatch(fn, msg) {
return function () {
try {
return fn.apply(this, arguments);
}
catch (err) {
console.error(msg, err);
return null;
}
};
}
/** @internal */
function areEqualUsing(first, second, comparator) {
var comparison = comparator(first, second);
if (typeof comparison === 'boolean') {
return comparison;
}
return comparison === 0;
}
/** @internal */
function filterParamMap(paramMap, keys) {
var params = {};
keys
.filter(function (key) { return paramMap.keys.includes(key); })
.forEach(function (key) { return params[key] = paramMap.getAll(key); });
return router.convertToParamMap(params);
}
/** @internal */
function compareParamMaps(first, second) {
if ((first && !second) || (second && !first)) {
return false;
}
if (!compareStringArraysUnordered(first.keys, second.keys)) {
return false;
}
return first.keys.every(function (key) { return compareStringArraysUnordered(first.getAll(key), second.getAll(key)); });
}
/** @internal */
function compareStringArraysUnordered(first, second) {
if (!first && !second) {
return true;
}
if ((first && !second) || (second && !first)) {
return false;
}
if (first.length !== second.length) {
return false;
}
var sortedFirst = first.sort();
var sortedSecond = second.sort();
return sortedFirst.every(function (firstKey, index) { return firstKey === sortedSecond[index]; });
}
/** @internal */
function wrapIntoObservable(input) {
if (rxjs.isObservable(input)) {
return input;
}
return rxjs.of(input);
}
/**
* Creates a serializer for parameters of type `string`.
*
* @param defaultValue Optional default value to return if the value to serialize is `undefined` or `null`.
*/
function createStringSerializer(defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
return function (model) { return isMissing(model) ? defaultValue : model; };
}
/**
* Creates a deserializer for parameters of type `string`.
*
* @param defaultValue Optional default value to return if the value to deserialize is `undefined` or `null`.
*/
function createStringDeserializer(defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
return function (value) { return isMissing(value) ? defaultValue : value; };
}
/**
* Creates a serializer for parameters of type `number`.
*
* @param defaultValue Optional default value to return if the value to serialize is `undefined` or `null`.
*/
function createNumberSerializer(defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
return function (model) { return isMissing(model) ? defaultValue : "" + model; };
}
/**
* Creates a deserializer for parameters of type `number`.
*
* @param defaultValue Optional default value to return if the value to deserialize is `undefined` or `null`.
*/
function createNumberDeserializer(defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
return function (value) { return isMissing(value) ? defaultValue : parseFloat(value); };
}
/**
* Creates a serializer for parameters of type `boolean`.
*
* @param defaultValue Optional default value to return if the value to serialize is `undefined` or `null`.
*/
function createBooleanSerializer(defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
return function (model) { return isMissing(model) ? defaultValue : "" + model; };
}
/**
* Creates a deserializer for parameters of type `boolean`.
*
* @param defaultValue Optional default value to return if the value to deserialize is `undefined` or `null`.
*/
function createBooleanDeserializer(defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
return function (value) { return isMissing(value) ? defaultValue : (value === 'true' || value === '1'); };
}
/** @internal */
var DEFAULT_STRING_SERIALIZER = createStringSerializer();
/** @internal */
var DEFAULT_STRING_DESERIALIZER = createStringDeserializer();
/** @internal */
var DEFAULT_NUMBER_SERIALIZER = createNumberSerializer();
/** @internal */
var DEFAULT_NUMBER_DESERIALIZER = createNumberDeserializer();
/** @internal */
var DEFAULT_BOOLEAN_SERIALIZER = createBooleanSerializer();
/** @internal */
var DEFAULT_BOOLEAN_DESERIALIZER = createBooleanDeserializer();
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
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;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
/** @internal */
var AbstractQueryParamBase = /** @class */ (function () {
function AbstractQueryParamBase() {
this.parent = null;
this._valueChanges = new rxjs.Subject();
this.changeFunctions = [];
/**
* Emits the current value of this parameter whenever it changes.
*
* NOTE: This observable does not complete on its own, so ensure to unsubscribe from it.
*/
this.valueChanges = this._valueChanges.asObservable();
}
AbstractQueryParamBase.prototype._registerOnChange = function (fn) {
this.changeFunctions.push(fn);
};
AbstractQueryParamBase.prototype._clearChangeFunctions = function () {
this.changeFunctions = [];
};
AbstractQueryParamBase.prototype._setParent = function (parent) {
if (this.parent && parent) {
throw new Error("Parameter already belongs to a QueryParamGroup.");
}
this.parent = parent;
};
return AbstractQueryParamBase;
}());
/**
* Abstract base for {@link QueryParam} and {@link MultiQueryParam}.
*
* This base class holds most of the parameter's options, but is unaware of
* how to actually (de-)serialize any values.
*/
var AbstractQueryParam = /** @class */ (function (_super) {
__extends(AbstractQueryParam, _super);
function AbstractQueryParam(urlParam, opts) {
if (opts === void 0) { opts = {}; }
var _this = _super.call(this) || this;
/**
* The current value of this parameter.
*/
_this.value = null;
var serialize = opts.serialize, deserialize = opts.deserialize, debounceTime = opts.debounceTime, compareWith = opts.compareWith, emptyOn = opts.emptyOn, combineWith = opts.combineWith;
if (isMissing(urlParam)) {
throw new Error("Please provide a URL parameter name for each query parameter.");
}
if (!isFunction(serialize)) {
throw new Error("serialize must be a function, but received " + serialize);
}
if (!isFunction(deserialize)) {
throw new Error("deserialize must be a function, but received " + deserialize);
}
if (emptyOn !== undefined && !isFunction(compareWith)) {
throw new Error("compareWith must be a function, but received " + compareWith);
}
if (isPresent(combineWith) && !isFunction(combineWith)) {
throw new Error("combineWith must be a function, but received " + combineWith);
}
_this.urlParam = urlParam;
_this.serialize = wrapTryCatch(serialize, "Error while serializing value for " + _this.urlParam);
_this.deserialize = wrapTryCatch(deserialize, "Error while deserializing value for " + _this.urlParam);
_this.debounceTime = undefinedToNull(debounceTime);
_this.emptyOn = emptyOn;
_this.compareWith = compareWith;
_this.combineWith = combineWith;
return _this;
}
/**
* Updates the value of this parameter.
*
* If wired up with a {@link QueryParamGroup}, this will also synchronize
* the value to the URL.
*/
AbstractQueryParam.prototype.setValue = function (value, opts) {
if (opts === void 0) { opts = {}; }
this.value = value;
if (opts.emitModelToViewChange !== false) {
this.changeFunctions.forEach(function (changeFn) { return changeFn(value); });
}
if (opts.emitEvent !== false) {
this._valueChanges.next(this.value);
}
if (isPresent(this.parent) && !opts.onlySelf) {
this.parent._updateValue({
emitEvent: opts.emitEvent,
emitModelToViewChange: false,
});
}
};
return AbstractQueryParam;
}(AbstractQueryParamBase));
/**
* Describes a single parameter.
*
* This is the description of a single parameter and essentially serves
* as the glue between its representation in the URL and its connection
* to a form control.
*/
var QueryParam = /** @class */ (function (_super) {
__extends(QueryParam, _super);
function QueryParam(urlParam, opts) {
var _this = _super.call(this, urlParam, opts) || this;
/** See {@link QueryParamOpts}. */
_this.multi = false;
return _this;
}
/** @internal */
QueryParam.prototype.serializeValue = function (value) {
if (this.emptyOn !== undefined && areEqualUsing(value, this.emptyOn, this.compareWith)) {
return null;
}
return this.serialize(value);
};
/** @internal */
QueryParam.prototype.deserializeValue = function (value) {
if (this.emptyOn !== undefined && value === null) {
return rxjs.of(this.emptyOn);
}
return wrapIntoObservable(this.deserialize(value)).pipe(operators.first());
};
return QueryParam;
}(AbstractQueryParam));
/**
* Like {@link QueryParam}, but for array-typed parameters
*/
var MultiQueryParam = /** @class */ (function (_super) {
__extends(MultiQueryParam, _super);
function MultiQueryParam(urlParam, opts) {
var _this = _super.call(this, urlParam, opts) || this;
/** See {@link QueryParamOpts}. */
_this.multi = true;
var serializeAll = opts.serializeAll, deserializeAll = opts.deserializeAll;
if (serializeAll !== undefined) {
if (!isFunction(serializeAll)) {
throw new Error("serializeAll must be a function, but received " + serializeAll);
}
_this.serializeAll = wrapTryCatch(serializeAll, "Error while serializing value for " + _this.urlParam);
}
if (deserializeAll !== undefined) {
if (!isFunction(deserializeAll)) {
throw new Error("deserializeAll must be a function, but received " + deserializeAll);
}
_this.deserializeAll = wrapTryCatch(deserializeAll, "Error while deserializing value for " + _this.urlParam);
}
return _this;
}
/** @internal */
MultiQueryParam.prototype.serializeValue = function (value) {
if (this.emptyOn !== undefined && areEqualUsing(value, this.emptyOn, this.compareWith)) {
return null;
}
if (this.serializeAll !== undefined) {
return this.serializeAll(value);
}
return (value || []).map(this.serialize.bind(this));
};
/** @internal */
MultiQueryParam.prototype.deserializeValue = function (values) {
var _this = this;
if (this.emptyOn !== undefined && (values || []).length === 0) {
return rxjs.of(this.emptyOn);
}
if (this.deserializeAll !== undefined) {
return wrapIntoObservable(this.deserializeAll(values));
}
if (!values || values.length === 0) {
return rxjs.of([]);
}
return rxjs.forkJoin.apply(void 0, __spread(values
.map(function (value) { return wrapIntoObservable(_this.deserialize(value)).pipe(operators.first()); })));
};
return MultiQueryParam;
}(AbstractQueryParam));
/**
* Describes a partitioned query parameter.
*
* This encapsulates a list of query parameters such that a single form control
* can be bound against multiple URL parameters. To achieve this, functions must
* be defined which can convert the models between the parameters.
*/
var PartitionedQueryParam = /** @class */ (function (_super) {
__extends(PartitionedQueryParam, _super);
function PartitionedQueryParam(queryParams, opts) {
var _this = _super.call(this) || this;
if (queryParams.length === 0) {
throw new Error("Partitioned parameters must contain at least one parameter.");
}
if (!isFunction(opts.partition)) {
throw new Error("partition must be a function, but received " + opts.partition);
}
if (!isFunction(opts.reduce)) {
throw new Error("reduce must be a function, but received " + opts.reduce);
}
_this.queryParams = queryParams;
_this.partition = opts.partition;
_this.reduce = opts.reduce;
return _this;
}
Object.defineProperty(PartitionedQueryParam.prototype, "value", {
get: function () {
return this.reduce(this.queryParams.map(function (queryParam) { return queryParam.value; }));
},
enumerable: false,
configurable: true
});
PartitionedQueryParam.prototype.setValue = function (value, opts) {
var _this = this;
if (opts === void 0) { opts = {}; }
var partitioned = this.partition(value);
this.queryParams.forEach(function (queryParam, index) { return queryParam.setValue(partitioned[index], {
emitEvent: opts.emitEvent,
onlySelf: true,
emitModelToViewChange: false,
}); });
if (opts.emitModelToViewChange !== false) {
this.changeFunctions.forEach(function (changeFn) { return changeFn(_this.value); });
}
if (opts.emitEvent !== false) {
this._valueChanges.next(this.value);
}
};
return PartitionedQueryParam;
}(AbstractQueryParamBase));
/**
* Groups multiple {@link QueryParam} instances to a single unit.
*
* This "bundles" multiple parameters together such that changes can be emitted as a
* complete unit. Collecting parameters into a group is required for the synchronization
* to and from the URL.
*/
var QueryParamGroup = /** @class */ (function () {
function QueryParamGroup(queryParams, extras) {
var _this = this;
if (extras === void 0) { extras = {}; }
/** @internal */
this._valueChanges = new rxjs.Subject();
/**
* Emits the values of all parameters in this group whenever at least one changes.
*
* This observable emits an object keyed by the {@QueryParam} names where each key
* carries the current value of the represented parameter. It emits whenever at least
* one parameter's value is changed.
*
* NOTE: This observable does not complete on its own, so ensure to unsubscribe from it.
*/
this.valueChanges = this._valueChanges.asObservable();
/** @internal */
this._queryParamAdded$ = new rxjs.Subject();
/** @internal */
this.queryParamAdded$ = this._queryParamAdded$.asObservable();
this.changeFunctions = [];
this.queryParams = queryParams;
this.routerOptions = extras;
this.options = extras;
Object.values(this.queryParams).forEach(function (queryParam) { return queryParam._setParent(_this); });
}
/** @internal */
QueryParamGroup.prototype._registerOnChange = function (fn) {
this.changeFunctions.push(fn);
};
/** @internal */
QueryParamGroup.prototype._clearChangeFunctions = function () {
this.changeFunctions = [];
};
/**
* Retrieves a specific parameter from this group by name.
*
* This returns an instance of either {@link QueryParam}, {@link MultiQueryParam}
* or {@link PartitionedQueryParam} depending on the configuration, or `null`
* if no parameter with that name is found in this group.
*
* @param queryParamName The name of the parameter instance to retrieve.
*/
QueryParamGroup.prototype.get = function (queryParamName) {
var param = this.queryParams[queryParamName];
if (!param) {
return null;
}
return param;
};
/**
* Adds a new {@link QueryParam} to this group.
*
* This adds the parameter under the given name to this group. The current
* URL will be evaluated to synchronize its value initially. Afterwards
* it is treated just like any other parameter in this group.
*
* @param queryParamName Name of the parameter to reference it with.
* @param queryParam The new parameter to add.
*/
QueryParamGroup.prototype.add = function (queryParamName, queryParam) {
if (this.get(queryParamName)) {
throw new Error("A parameter with name " + queryParamName + " already exists.");
}
this.queryParams[queryParamName] = queryParam;
queryParam._setParent(this);
this._queryParamAdded$.next(queryParamName);
};
/**
* Removes a {@link QueryParam} from this group.
*
* This removes the parameter defined by the provided name from this group.
* No further synchronization with this parameter will occur and it will not
* be reported in the value of this group anymore.
*
* @param queryParamName The name of the parameter to remove.
*/
QueryParamGroup.prototype.remove = function (queryParamName) {
var queryParam = this.get(queryParamName);
if (!queryParam) {
throw new Error("No parameter with name " + queryParamName + " found.");
}
delete this.queryParams[queryParamName];
queryParam._setParent(null);
queryParam._clearChangeFunctions();
};
Object.defineProperty(QueryParamGroup.prototype, "value", {
/**
* The current value of this group.
*
* See {@link QueryParamGroup#valueChanges} for a description of the format of
* the value.
*/
get: function () {
var _this = this;
var value = {};
Object.keys(this.queryParams).forEach(function (queryParamName) { return value[queryParamName] = _this.queryParams[queryParamName].value; });
return value;
},
enumerable: false,
configurable: true
});
/**
* Updates the value of this group by merging it in.
*
* This sets the value of each provided parameter to the respective provided
* value. If a parameter is not listed, its value remains unchanged.
*
* @param value See {@link QueryParamGroup#valueChanges} for a description of the format.
* @param opts Additional options
*/
QueryParamGroup.prototype.patchValue = function (value, opts) {
var _this = this;
if (opts === void 0) { opts = {}; }
Object.keys(value).forEach(function (queryParamName) {
var queryParam = _this.queryParams[queryParamName];
if (isMissing(queryParam)) {
return;
}
queryParam.setValue(value[queryParamName], {
emitEvent: opts.emitEvent,
onlySelf: true,
emitModelToViewChange: false,
});
});
this._updateValue(opts);
};
/**
* Updates the value of this group by overwriting it.
*
* This sets the value of each provided parameter to the respective provided
* value. If a parameter is not listed, its value is set to `undefined`.
*
* @param value See {@link QueryParamGroup#valueChanges} for a description of the format.
* @param opts Additional options
*/
QueryParamGroup.prototype.setValue = function (value, opts) {
var _this = this;
if (opts === void 0) { opts = {}; }
Object.keys(this.queryParams).forEach(function (queryParamName) {
_this.queryParams[queryParamName].setValue(undefinedToNull(value === null || value === void 0 ? void 0 : value[queryParamName]), {
emitEvent: opts.emitEvent,
onlySelf: true,
emitModelToViewChange: false,
});
});
this._updateValue(opts);
};
/** @internal */
QueryParamGroup.prototype._updateValue = function (opts) {
var _this = this;
if (opts === void 0) { opts = {}; }
if (opts.emitModelToViewChange !== false) {
this.changeFunctions.forEach(function (changeFn) { return changeFn(_this.value); });
}
if (opts.emitEvent !== false) {
this._valueChanges.next(this.value);
}
};
return QueryParamGroup;
}());
function isMultiOpts(opts) {
return opts.multi === true;
}
/**
* Service to create parameters and groups.
*
* This service provides a simple API to create {@link QueryParamGroup} and {@link QueryParam}
* instances and is the recommended way to set them up.
*/
var QueryParamBuilder = /** @class */ (function () {
function QueryParamBuilder() {
}
/**
* Creates a new {@link QueryParamGroup}.
*
* This is the primary method to create a new group of parameters. Pass a list of
* {@link QueryParam} instances by using the `xxxParam` methods.
*
* @param queryParams List of {@link QueryParam}s keyed by a unique name.
* @param extras Additional parameters for this group, overriding global configuration.
* @returns The new {@link QueryParamGroup}.
*/
QueryParamBuilder.prototype.group = function (queryParams, extras) {
if (extras === void 0) { extras = {}; }
// TODO Maybe we should first validate that no two queryParams defined the same "param".
return new QueryParamGroup(queryParams, extras);
};
/**
* Partition a query parameter into multiple others.
*
* Partitioning is useful if you need to bind a single form control to multiple query parameters.
* For example, consider a {@code <select>} which represents both a field to sort by and the
* direction to sort in. If you want to encode these two information on separate URL parameters,
* you can define a single query parameter that is partitioned into two others.
*
* @param queryParams The query parameters making up this partition.
* @param opts See {@link PartitionedQueryParamOpts}.
*/
QueryParamBuilder.prototype.partition = function (queryParams, opts) {
return new PartitionedQueryParam(queryParams, opts);
};
/**
* Create a new parameter of type `string`.
*
* See {@link QueryParamOpts}.
*/
QueryParamBuilder.prototype.stringParam = function (urlParam, opts) {
if (opts === void 0) { opts = {}; }
opts = Object.assign({ serialize: DEFAULT_STRING_SERIALIZER, deserialize: DEFAULT_STRING_DESERIALIZER, compareWith: LOOSE_IDENTITY_COMPARATOR }, opts);
if (isMultiOpts(opts)) {
return new MultiQueryParam(urlParam, opts);
}
else {
return new QueryParam(urlParam, opts);
}
};
/**
* Create a new parameter of type `number`.
*
* See {@link QueryParamOpts}.
*/
QueryParamBuilder.prototype.numberParam = function (urlParam, opts) {
if (opts === void 0) { opts = {}; }
opts = Object.assign({ serialize: DEFAULT_NUMBER_SERIALIZER, deserialize: DEFAULT_NUMBER_DESERIALIZER, compareWith: LOOSE_IDENTITY_COMPARATOR }, opts);
if (isMultiOpts(opts)) {
return new MultiQueryParam(urlParam, opts);
}
else {
return new QueryParam(urlParam, opts);
}
};
/**
* Create a new parameter of type `boolean`.
*
* See {@link QueryParamOpts}.
*/
QueryParamBuilder.prototype.booleanParam = function (urlParam, opts) {
if (opts === void 0) { opts = {}; }
opts = Object.assign({ serialize: DEFAULT_BOOLEAN_SERIALIZER, deserialize: DEFAULT_BOOLEAN_DESERIALIZER, compareWith: LOOSE_IDENTITY_COMPARATOR }, opts);
if (isMultiOpts(opts)) {
return new MultiQueryParam(urlParam, opts);
}
else {
return new QueryParam(urlParam, opts);
}
};
/**
* Create a new parameter for a complex type.
*
* See {@link QueryParamOpts}.
*/
QueryParamBuilder.prototype.param = function (urlParam, opts) {
if (opts === void 0) { opts = {}; }
opts = Object.assign({ compareWith: LOOSE_IDENTITY_COMPARATOR }, opts);
if (isMultiOpts(opts)) {
return new MultiQueryParam(urlParam, opts);
}
else {
return new QueryParam(urlParam, opts);
}
};
return QueryParamBuilder;
}());
QueryParamBuilder.ɵprov = i0.ɵɵdefineInjectable({ factory: function QueryParamBuilder_Factory() { return new QueryParamBuilder(); }, token: QueryParamBuilder, providedIn: "root" });
QueryParamBuilder.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/**
* See {@link RouterOptions}.
*/
var DefaultRouterOptions = {
replaceUrl: true,
preserveFragment: true,
};
/** @internal */
var NGQP_ROUTER_ADAPTER = new i0.InjectionToken('NGQP_ROUTER_ADAPTER');
/** Injection token to provide {@link RouterOptions}. */
var NGQP_ROUTER_OPTIONS = new i0.InjectionToken('NGQP_ROUTER_OPTIONS');
/** @internal */
function isMultiQueryParam(queryParam) {
return queryParam.multi;
}
/** @internal */
var NavigationData = /** @class */ (function () {
function NavigationData(params, synthetic) {
if (synthetic === void 0) { synthetic = false; }
this.params = params;
this.synthetic = synthetic;
}
return NavigationData;
}());
/**
* Service implementing the synchronization logic
*
* This service is the key to the synchronization process by binding a {@link QueryParamGroup}
* to the router.
*
* @internal
*/
var QueryParamGroupService = /** @class */ (function () {
function QueryParamGroupService(routerAdapter, globalRouterOptions) {
this.routerAdapter = routerAdapter;
this.globalRouterOptions = globalRouterOptions;
/** The {@link QueryParamGroup} to bind. */
this.queryParamGroup = null;
/** List of {@link QueryParamAccessor} registered to this service. */
this.directives = new Map();
/**
* Queue of navigation parameters
*
* A queue is used for navigations as we need to make sure all parameter changes
* are executed in sequence as otherwise navigations might overwrite each other.
*/
this.queue$ = new rxjs.Subject();
/** @ignore */
this.synchronizeRouter$ = new rxjs.Subject();
/** @ignore */
this.destroy$ = new rxjs.Subject();
this.setupNavigationQueue();
}
/** @ignore */
QueryParamGroupService.prototype.ngOnDestroy = function () {
var _this = this;
var _a, _b, _c;
this.destroy$.next();
this.destroy$.complete();
this.synchronizeRouter$.complete();
(_a = this.queryParamGroup) === null || _a === void 0 ? void 0 : _a._clearChangeFunctions();
if ((_c = (_b = this.queryParamGroup) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.clearOnDestroy) {
var nullParams = Object.values(this.queryParamGroup.queryParams)
.map(function (queryParam) { return _this.wrapIntoPartition(queryParam); })
.map(function (partitionedQueryParam) { return partitionedQueryParam.queryParams.map(function (queryParam) { return queryParam.urlParam; }); })
.reduce(function (a, b) { return __spread(a, b); }, [])
.map(function (urlParam) {
var _d;
return (_d = {}, _d[urlParam] = null, _d);
})
.reduce(function (a, b) { return (Object.assign(Object.assign({}, a), b)); }, {});
this.routerAdapter.navigate(nullParams, {
replaceUrl: true,
}).then();
}
};
/**
* Uses the given {@link QueryParamGroup} for synchronization.
*/
QueryParamGroupService.prototype.setQueryParamGroup = function (queryParamGroup) {
// FIXME: If this is called when we already have a group, we probably need to do
// some cleanup first.
if (this.queryParamGroup) {
throw new Error("A QueryParamGroup has already been setup. Changing the group is currently not supported.");
}
this.queryParamGroup = queryParamGroup;
this.startSynchronization();
};
/**
* Registers a {@link QueryParamAccessor}.
*/
QueryParamGroupService.prototype.registerQueryParamDirective = function (directive) {
var _this = this;
if (!directive.valueAccessor) {
throw new Error("No value accessor found for the form control. Please make sure to implement ControlValueAccessor on this component.");
}
// Capture the name here, particularly for the queue below to avoid re-evaluating
// it as it might change over time.
var queryParamName = directive.name;
var partitionedQueryParam = this.getQueryParamAsPartition(queryParamName);
// Chances are that we read the initial route before a directive has been registered here.
// The value in the model will be correct, but we need to sync it to the view once initially.
directive.valueAccessor.writeValue(partitionedQueryParam.value);
// Proxy updates from the view to debounce them (if needed).
var queues = partitionedQueryParam.queryParams.map(function () { return new rxjs.Subject(); });
rxjs.zip.apply(void 0, __spread(queues.map(function (queue$, index) {
var queryParam = partitionedQueryParam.queryParams[index];
return queue$.pipe(isPresent(queryParam.debounceTime) ? operators.debounceTime(queryParam.debounceTime) : operators.tap());
}))).pipe(
// Do not synchronize while the param is detached from the group
operators.filter(function () { return !!_this.getQueryParamGroup().get(queryParamName); }), operators.map(function (newValue) { return _this.getParamsForValue(partitionedQueryParam, partitionedQueryParam.reduce(newValue)); }), operators.takeUntil(this.destroy$)).subscribe(function (params) { return _this.enqueueNavigation(new NavigationData(params)); });
directive.valueAccessor.registerOnChange(function (newValue) {
var partitioned = partitionedQueryParam.partition(newValue);
queues.forEach(function (queue$, index) { return queue$.next(partitioned[index]); });
});
this.directives.set(queryParamName, __spread((this.directives.get(queryParamName) || []), [directive]));
};
/**
* Deregisters a {@link QueryParamAccessor} by referencing its name.
*/
QueryParamGroupService.prototype.deregisterQueryParamDirective = function (queryParamName) {
if (!queryParamName) {
return;
}
var directives = this.directives.get(queryParamName);
if (!directives) {
return;
}
directives.forEach(function (directive) {
directive.valueAccessor.registerOnChange(NOP);
directive.valueAccessor.registerOnTouched(NOP);
});
this.directives.delete(queryParamName);
var queryParam = this.getQueryParamGroup().get(queryParamName);
if (queryParam) {
queryParam._clearChangeFunctions();
}
};
QueryParamGroupService.prototype.startSynchronization = function () {
this.setupGroupChangeListener();
this.setupParamChangeListeners();
this.setupRouterListener();
this.watchNewParams();
};
/** Listens for programmatic changes on group level and synchronizes to the router. */
QueryParamGroupService.prototype.setupGroupChangeListener = function () {
var _this = this;
this.getQueryParamGroup()._registerOnChange(function (newValue) {
if (newValue === null) {
throw new Error("Received null value from QueryParamGroup.");
}
var params = {};
Object.keys(newValue).forEach(function (queryParamName) {
var queryParam = _this.getQueryParamGroup().get(queryParamName);
if (isMissing(queryParam)) {
return;
}
params = Object.assign(Object.assign({}, params), _this.getParamsForValue(queryParam, newValue[queryParamName]));
});
_this.enqueueNavigation(new NavigationData(params, true));
});
};
/** Listens for programmatic changes on parameter level and synchronizes to the router. */
QueryParamGroupService.prototype.setupParamChangeListeners = function () {
var _this = this;
Object.keys(this.getQueryParamGroup().queryParams)
.forEach(function (queryParamName) { return _this.setupParamChangeListener(queryParamName); });
};
QueryParamGroupService.prototype.setupParamChangeListener = function (queryParamName) {
var _this = this;
var queryParam = this.getQueryParamGroup().get(queryParamName);
if (!queryParam) {
throw new Error("No param in group found for name " + queryParamName);
}
queryParam._registerOnChange(function (newValue) { return _this.enqueueNavigation(new NavigationData(_this.getParamsForValue(queryParam, newValue), true)); });
};
/** Listens for changes in the router and synchronizes to the model. */
QueryParamGroupService.prototype.setupRouterListener = function () {
var _this = this;
this.synchronizeRouter$.pipe(operators.startWith(undefined), operators.switchMap(function () { return _this.routerAdapter.queryParamMap.pipe(
// We want to ignore changes to query parameters which aren't related to this
// particular group; however, we do need to react if one of our parameters has
// vanished when it was set before.
operators.distinctUntilChanged(function (previousMap, currentMap) {
var keys = Object.values(_this.getQueryParamGroup().queryParams)
.map(function (queryParam) { return _this.wrapIntoPartition(queryParam); })
.map(function (partitionedQueryParam) { return partitionedQueryParam.queryParams.map(function (queryParam) { return queryParam.urlParam; }); })
.reduce(function (a, b) { return __spread(a, b); }, []);
// It is important that we filter the maps only here so that both are filtered
// with the same set of keys; otherwise, e.g. removing a parameter from the group
// would interfere.
return compareParamMaps(filterParamMap(previousMap, keys), filterParamMap(currentMap, keys));
})); }), operators.switchMap(function (queryParamMap) {
// We need to capture this right here since this is only set during the on-going navigation.
var synthetic = _this.isSyntheticNavigation();
var queryParamNames = Object.keys(_this.getQueryParamGroup().queryParams);
return rxjs.forkJoin.apply(void 0, __spread(queryParamNames
.map(function (queryParamName) {
var partitionedQueryParam = _this.getQueryParamAsPartition(queryParamName);
return rxjs.forkJoin.apply(void 0, __spread(partitionedQueryParam.queryParams
.map(function (queryParam) { return isMultiQueryParam(queryParam)
? queryParam.deserializeValue(queryParamMap.getAll(queryParam.urlParam))
: queryParam.deserializeValue(queryParamMap.get(queryParam.urlParam)); }))).pipe(operators.map(function (newValues) { return partitionedQueryParam.reduce(newValues); }), operators.tap(function (newValue) {
var directives = _this.directives.get(queryParamName);
if (directives) {
directives.forEach(function (directive) { return directive.valueAccessor.writeValue(newValue); });
}
}), operators.map(function (newValue) {
var _d;
return _d = {}, _d[queryParamName] = newValue, _d;
}), operators.takeUntil(_this.destroy$));
}))).pipe(operators.map(function (values) { return values.reduce(function (groupValue, value) {
return Object.assign(Object.assign({}, groupValue), value);
}, {}); }), operators.tap(function (groupValue) { return _this.getQueryParamGroup().setValue(groupValue, {
emitEvent: !synthetic,
emitModelToViewChange: false,
}); }));
}), operators.takeUntil(this.destroy$)).subscribe();
};
/** Listens for newly added parameters and starts synchronization for them. */
QueryParamGroupService.prototype.watchNewParams = function () {
var _this = this;
this.getQueryParamGroup().queryParamAdded$.pipe(operators.takeUntil(this.destroy$)).subscribe(function (queryParamName) {
_this.setupParamChangeListener(queryParamName);
_this.synchronizeRouter$.next();
});
};
/** Returns true if the current navigation is synthetic. */
QueryParamGroupService.prototype.isSyntheticNavigation = function () {
var navigation = this.routerAdapter.getCurrentNavigation();
if (!navigation || navigation.trigger !== 'imperative') {
// When using the back / forward buttons, the state is passed along with it, even though
// for us it's now a navigation initiated by the user. Therefore, a navigation can only
// be synthetic if it has been triggered imperatively.
// See https://github.com/angular/angular/issues/28108.
return false;
}
return navigation.extras && navigation.extras.state && navigation.extras.state['synthetic'];
};
/** Subscribes to the parameter queue and executes navigations in sequence. */
QueryParamGroupService.prototype.setupNavigationQueue = function () {
var _this = this;
this.queue$.pipe(operators.takeUntil(this.destroy$), operators.concatMap(function (data) { return _this.navigateSafely(data); })).subscribe();
};
QueryParamGroupService.prototype.navigateSafely = function (data) {
return rxjs.from(this.routerAdapter.navigate(data.params, Object.assign(Object.assign({}, this.routerOptions), { state: { synthetic: data.synthetic } }))).pipe(operators.catchError(function (err) {
if (i0.isDevMode()) {
console.error("There was an error while navigating", err);
}
return rxjs.EMPTY;
}));
};
/** Sends a change of parameters to the queue. */
QueryParamGroupService.prototype.enqueueNavigation = function (data) {
this.queue$.next(data);
};
/**
* Returns the full set of parameters given a value for a parameter model.
*
* This consists mainly of properly serializing the model value and ensuring to take
* side effect changes into account that may have been configured.
*/
QueryParamGroupService.prototype.getParamsForValue = function (queryParam, value) {
var partitionedQueryParam = this.wrapIntoPartition(queryParam);
var partitioned = partitionedQueryParam.partition(value);
var combinedParams = partitionedQueryParam.queryParams
.map(function (current, index) { return isMissing(current.combineWith) ? null : current.combineWith(partitioned[index]); })
.reduce(function (a, b) {
return Object.assign(Object.assign({}, (a || {})), (b || {}));
}, {});
var newValues = partitionedQueryParam.queryParams
.map(function (current, index) {
var _d;
return _d = {},
_d[current.urlParam] = current.serializeValue(partitioned[index]),
_d;
})
.reduce(function (a, b) {
return Object.assign(Object.assign({}, a), b);
}, {});
// Note that we list the side-effect parameters first so that our actual parameter can't be
// overridden by it.
return Object.assign(Object.assign({}, combinedParams), newValues);
};
Object.defineProperty(QueryParamGroupService.prototype, "routerOptions", {
/**
* Returns the current set of options to pass to the router.
*
* This merges the global configuration with the group specific configuration.
*/
get: function () {
var groupOptions = this.getQueryParamGroup().routerOptions;
return Object.assign(Object.assign({}, (this.globalRouterOptions || {})), (groupOptions || {}));
},
enumerable: false,
configurable: true
});
/**
* Returns the query parameter with the given name as a partition.
*
* If the query parameter is partitioned, it is returned unchanged. Otherwise
* it is wrapped into a noop partition. This makes it easy to operate on
* query parameters independent of whether they are partitioned.
*/
QueryParamGroupService.prototype.getQueryParamAsPartition = function (queryParamName) {
var queryParam = this.getQueryParamGroup().get(queryParamName);
if (!queryParam) {
throw new Error("Could not find query param with name " + queryParamName + ". Did you forget to add it to your QueryParamGroup?");
}
return this.wrapIntoPartition(queryParam);
};
/**
* Wraps a query parameter into a partition if it isn't already.
*/
QueryParamGroupService.prototype.wrapIntoPartition = function (queryParam) {
if (queryParam instanceof PartitionedQueryParam) {
return queryParam;
}
return new PartitionedQueryParam([queryParam], {
partition: function (value) { return [value]; },
reduce: function (values) { return values[0]; },
});
};
QueryParamGroupService.prototype.getQueryParamGroup = function () {
if (!this.queryParamGroup) {
throw new Error("No QueryParamGroup has been registered yet.");
}
return this.queryParamGroup;
};
return QueryParamGroupService;
}());
QueryParamGroupService.decorators = [
{ type: i0.Injectable }
];
QueryParamGroupService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: i0.Inject, args: [NGQP_ROUTER_ADAPTER,] }] },
{ type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [NGQP_ROUTER_OPTIONS,] }] }
]; };
/** @ignore */
var NGQP_DEFAULT_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return DefaultControlValueAccessorDirective; }),
multi: true
};
/** @ignore */
function isAndroid(navigator) {
return /android (\d+)/.test(navigator.userAgent.toLowerCase());
}
/** @ignore */
var DefaultControlValueAccessorDirective = /** @class */ (function () {
function DefaultControlValueAccessorDirective(platformId, renderer, elementRef) {
this.platformId = platformId;
this.renderer = renderer;
this.elementRef = elementRef;
this.composing = false;
this.fnChange = function (_) { };
this.fnTouched = function () { };
this.supportsComposition = common.isPlatformBrowser(this.platformId || '') && !isAndroid(window.navigator);
}
DefaultControlValueAccessorDirective.prototype.onInput = function (event) {
if (this.supportsComposition && this.composing) {
return;
}
this.fnChange(event.target.value);
};
DefaultControlValueAccessorDirective.prototype.onBlur = function () {
this.fnTouched();
};
DefaultControlValueAccessorDirective.prototype.onCompositionStart = function () {
this.composing = true;
};
DefaultControlValueAccessorDirective.prototype.onCompositionEnd = function (event) {
this.composing = false;
if (this.supportsComposition) {
this.fnChange(event.target.value);
}
};
DefaultControlValueAccessorDirective.prototype.writeValue = function (value) {
var normalizedValue = value === null ? '' : value;
this.renderer.setProperty(this.elementRef.nativeElement, 'value', normalizedValue);
};
DefaultControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
DefaultControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
DefaultControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
};
return DefaultControlValueAccessorDirective;
}());
DefaultControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'input:not([type=checkbox]):not([type=radio])[queryParamName],textarea[queryParamName],' +
'input:not([type=checkbox]):not([type=radio])[queryParam],textarea[queryParam]',
providers: [NGQP_DEFAULT_VALUE_ACCESSOR],
},] }
];
DefaultControlValueAccessorDirective.ctorParameters = function () { return [
{ type: String, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [i0.PLATFORM_ID,] }] },
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
DefaultControlValueAccessorDirective.propDecorators = {
onInput: [{ type: i0.HostListener, args: ['input', ['$event'],] }],
onBlur: [{ type: i0.HostListener, args: ['blur',] }],
onCompositionStart: [{ type: i0.HostListener, args: ['compositionstart',] }],
onCompositionEnd: [{ type: i0.HostListener, args: ['compositionend', ['$event'],] }]
};
/** @ignore */
var NGQP_RANGE_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return RangeControlValueAccessorDirective; }),
multi: true
};
/** @ignore */
var RangeControlValueAccessorDirective = /** @class */ (function () {
function RangeControlValueAccessorDirective(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.fnChange = function (_) { };
this.fnTouched = function () { };
}
RangeControlValueAccessorDirective.prototype.onInput = function (event) {
var value = event.target.value;
this.fnChange(value === '' ? null : parseFloat(value));
};
RangeControlValueAccessorDirective.prototype.onBlur = function () {
this.fnTouched();
};
RangeControlValueAccessorDirective.prototype.writeValue = function (value) {
this.renderer.setProperty(this.elementRef.nativeElement, 'value', parseFloat(value));
};
RangeControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
RangeControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
RangeControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
};
return RangeControlValueAccessorDirective;
}());
RangeControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'input[type=range][queryParamName],input[type=range][queryParam]',
providers: [NGQP_RANGE_VALUE_ACCESSOR],
},] }
];
RangeControlValueAccessorDirective.ctorParameters = function () { return [
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
RangeControlValueAccessorDirective.propDecorators = {
onInput: [{ type: i0.HostListener, args: ['input', ['$event'],] }],
onBlur: [{ type: i0.HostListener, args: ['blur',] }]
};
/** @ignore */
var NGQP_NUMBER_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return NumberControlValueAccessorDirective; }),
multi: true
};
/** @ignore */
var NumberControlValueAccessorDirective = /** @class */ (function () {
function NumberControlValueAccessorDirective(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.fnChange = function (_) { };
this.fnTouched = function () { };
}
NumberControlValueAccessorDirective.prototype.onInput = function (event) {
var value = event.target.value;
this.fnChange(value === '' ? null : parseFloat(value));
};
NumberControlValueAccessorDirective.prototype.onBlur = function () {
this.fnTouched();
};
NumberControlValueAccessorDirective.prototype.writeValue = function (value) {
var normalizedValue = value === null ? '' : value;
this.renderer.setProperty(this.elementRef.nativeElement, 'value', normalizedValue);
};
NumberControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
NumberControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
NumberControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
};
return NumberControlValueAccessorDirective;
}());
NumberControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'input[type=number][queryParamName],input[type=number][queryParam]',
providers: [NGQP_NUMBER_VALUE_ACCESSOR],
},] }
];
NumberControlValueAccessorDirective.ctorParameters = function () { return [
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
NumberControlValueAccessorDirective.propDecorators = {
onInput: [{ type: i0.HostListener, args: ['input', ['$event'],] }],
onBlur: [{ type: i0.HostListener, args: ['blur',] }]
};
/** @ignore */
var NGQP_CHECKBOX_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return CheckboxControlValueAccessorDirective; }),
multi: true
};
/** @ignore */
var CheckboxControlValueAccessorDirective = /** @class */ (function () {
function CheckboxControlValueAccessorDirective(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.fnChange = function (_) { };
this.fnTouched = function () { };
}
CheckboxControlValueAccessorDirective.prototype.onInput = function (event) {
this.fnChange(event.target.checked);
};
CheckboxControlValueAccessorDirective.prototype.onBlur = function () {
this.fnTouched();
};
CheckboxControlValueAccessorDirective.prototype.writeValue = function (value) {
this.renderer.setProperty(this.elementRef.nativeElement, 'checked', value);
};
CheckboxControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
CheckboxControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
CheckboxControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
};
return CheckboxControlValueAccessorDirective;
}());
CheckboxControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'input[type=checkbox][queryParamName],input[type=checkbox][queryParam]',
providers: [NGQP_CHECKBOX_VALUE_ACCESSOR],
},] }
];
CheckboxControlValueAccessorDirective.ctorParameters = function () { return [
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
CheckboxControlValueAccessorDirective.propDecorators = {
onInput: [{ type: i0.HostListener, args: ['change', ['$event'],] }],
onBlur: [{ type: i0.HostListener, args: ['blur',] }]
};
/** @ignore */
var NGQP_SELECT_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return SelectControlValueAccessorDirective; }),
multi: true
};
/** @ignore */
var SelectControlValueAccessorDirective = /** @class */ (function () {
function SelectControlValueAccessorDirective(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.value = null;
this.selectedId = null;
this.optionMap = new Map();
this.idCounter = 0;
this.fnChange = function (_) { };
this.fnTouched = function () { };
}
SelectControlValueAccessorDirective.prototype.onChange = function (event) {
this.selectedId = event.target.value;
this.value = undefinedToNull(this.optionMap.get(this.selectedId));
this.fnChange(this.value);
};
SelectControlValueAccessorDirective.prototype.onTouched = function () {
this.fnTouched();
};
SelectControlValueAccessorDirective.prototype.writeValue = function (value) {
this.value = value;
this.selectedId = value === null ? null : this.getOptionId(value);
if (this.selectedId === null) {
this.renderer.setProperty(this.elementRef.nativeElement, 'selectedIndex', -1);
}
this.renderer.setProperty(this.elementRef.nativeElement, 'value', this.selectedId);
};
SelectControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
SelectControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
SelectControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
};
SelectControlValueAccessorDirective.prototype.registerOption = function () {
return (this.idCounter++).toString();
};
SelectControlValueAccessorDirective.prototype.deregisterOption = function (id) {
this.optionMap.delete(id);
};
SelectControlValueAccessorDirective.prototype.updateOptionValue = function (id, value) {
this.optionMap.set(id, value);
if (this.selectedId === id) {
this.fnChange(value);
}
};
SelectControlValueAccessorDirective.prototype.getOptionId = function (value) {
var e_1, _a;
try {
for (var _b = __values(Array.from(this.optionMap.keys())), _c = _b.next(); !_c.done; _c = _b.next()) {
var id = _c.value;
if (this.optionMap.get(id) === value) {
return id;
}
}
}
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; }
}
return null;
};
return SelectControlValueAccessorDirective;
}());
SelectControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'select:not([multiple])[queryParamName],select:not([multiple])[queryParam]',
providers: [NGQP_SELECT_VALUE_ACCESSOR],
},] }
];
SelectControlValueAccessorDirective.ctorParameters = function () { return [
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
SelectControlValueAccessorDirective.propDecorators = {
onChange: [{ type: i0.HostListener, args: ['change', ['$event'],] }],
onTouched: [{ type: i0.HostListener, args: ['blur',] }]
};
/** @ignore */
var NGQP_MULTI_SELECT_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return MultiSelectControlValueAccessorDirective; }),
multi: true
};
/** @ignore */
var MultiSelectControlValueAccessorDirective = /** @class */ (function () {
function MultiSelectControlValueAccessorDirective(renderer, elementRef) {
this.renderer = renderer;
this.elementRef = elementRef;
this.selectedIds = [];
this.options = new Map();
this.optionMap = new Map();
this.idCounter = 0;
this.fnChange = function (_) { };
this.fnTouched = function () { };
}
MultiSelectControlValueAccessorDirective.prototype.onChange = function () {
var _this = this;
this.selectedIds = Array.from(this.options.entries())
.filter(function (_a) {
var _b = __read(_a, 2), id = _b[0], option = _b[1];
return option.selected;
})
.map(function (_a) {
var _b = __read(_a, 1), id = _b[0];
return id;
});
var values = this.selectedIds.map(function (id) { return _this.optionMap.get(id); });
this.fnChange(values);
};
MultiSelectControlValueAccessorDirective.prototype.onTouched = function () {
this.fnTouched();
};
MultiSelectControlValueAccessorDirective.prototype.writeValue = function (values) {
var _this = this;
values = values === null ? [] : values;
if (!Array.isArray(values)) {
throw new Error("Provided a non-array value to select[multiple]: " + values);
}
this.selectedIds = values
.map(function (value) { return _this.getOptionId(value); })
.filter(function (id) { return id !== null; });
this.options.forEach(function (option, id) { return option.selected = _this.selectedIds.includes(id); });
};
MultiSelectControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
MultiSelectControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
MultiSelectControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
};
MultiSelectControlValueAccessorDirective.prototype.registerOption = function (option) {
var newId = (this.idCounter++).toString();
this.options.set(newId, option);
return newId;
};
MultiSelectControlValueAccessorDirective.prototype.deregisterOption = function (id) {
this.optionMap.delete(id);
};
MultiSelectControlValueAccessorDirective.prototype.updateOptionValue = function (id, value) {
this.optionMap.set(id, value);
if (this.selectedIds.includes(id)) {
this.onChange();
}
};
MultiSelectControlValueAccessorDirective.prototype.getOptionId = function (value) {
var e_1, _a;
try {
for (var _b = __values(Array.from(this.optionMap.keys())), _c = _b.next(); !_c.done; _c = _b.next()) {
var id = _c.value;
if (this.optionMap.get(id) === value) {
return id;
}
}
}
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; }
}
return null;
};
return MultiSelectControlValueAccessorDirective;
}());
MultiSelectControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'select[multiple][queryParamName],select[multiple][queryParam]',
providers: [NGQP_MULTI_SELECT_VALUE_ACCESSOR],
},] }
];
MultiSelectControlValueAccessorDirective.ctorParameters = function () { return [
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
MultiSelectControlValueAccessorDirective.propDecorators = {
onChange: [{ type: i0.HostListener, args: ['change',] }],
onTouched: [{ type: i0.HostListener, args: ['blur',] }]
};
/** @ignore */
var NGQP_BUILT_IN_ACCESSORS = [
DefaultControlValueAccessorDirective,
NumberControlValueAccessorDirective,
RangeControlValueAccessorDirective,
CheckboxControlValueAccessorDirective,
SelectControlValueAccessorDirective,
MultiSelectControlValueAccessorDirective,
];
/**
* This resembles the selectControlValueAccessor function from
* https://github.com/angular/angular/blob/7.1.2/packages/forms/src/directives/shared.ts#L186
* We can't use it directly since it isn't exported in the public API, but let's hope choosing
* any accessor is good enough for our purposes.
*
* @internal
*/
function selectValueAccessor(valueAccessors) {
if (!valueAccessors || !Array.isArray(valueAccessors)) {
throw new Error("No matching ControlValueAccessor has been found for this form control");
}
var defaultAccessor = null;
var builtInAccessor = null;
var customAccessor = null;
valueAccessors.forEach(function (valueAccessor) {
if (valueAccessor.constructor === DefaultControlValueAccessorDirective) {
defaultAccessor = valueAccessor;
}
else if (NGQP_BUILT_IN_ACCESSORS.some(function (current) { return valueAccessor.constructor === current; })) {
if (builtInAccessor !== null) {
throw new Error("More than one built-in ControlValueAccessor matches");
}
builtInAccessor = valueAccessor;
}
else {
if (customAccessor !== null) {
throw new Error("More than one custom ControlValueAccessor has been found on the form control");
}
customAccessor = valueAccessor;
}
});
if (customAccessor !== null) {
return customAccessor;
}
if (builtInAccessor !== null) {
return builtInAccessor;
}
if (defaultAccessor !== null) {
return defaultAccessor;
}
throw new Error("No matching ControlValueAccessor has been found for this form control");
}
/**
* Binds a {@link QueryParam} to a component directly.
*
* This directive accepts a {@link QueryParam} without requiring an outer {@link QueryParamGroup}.
* It binds this parameter to the host component, which is required to have a [ControlValueAccessor]
* {@link https://angular.io/api/forms/ControlValueAccessor}.
*/
var QueryParamDirective = /** @class */ (function () {
/** @internal */
function QueryParamDirective(groupService, valueAccessors) {
this.groupService = groupService;
/**
* The {@link QueryParam} to bind to the host component.
*/
this.queryParam = null;
/** @internal */
this.name = 'param';
/** @internal */
this.group = new QueryParamGroup({});
this.valueAccessor = selectValueAccessor(valueAccessors);
this.groupService.setQueryParamGroup(this.group);
}
/** @ignore */
QueryParamDirective.prototype.ngOnChanges = function (changes) {
var paramChange = changes['queryParam'];
if (paramChange) {
if (this.group.get(this.name)) {
this.groupService.deregisterQueryParamDirective(this.name);
this.group.remove(this.name);
}
if (paramChange.currentValue) {
this.group.add(this.name, paramChange.currentValue);
this.groupService.registerQueryParamDirective(this);
}
}
};
/** @ignore */
QueryParamDirective.prototype.ngOnDestroy = function () {
if (this.groupService) {
this.groupService.deregisterQueryParamDirective(this.name);
}
};
return QueryParamDirective;
}());
QueryParamDirective.decorators = [
{ type: i0.Directive, args: [{
selector: '[queryParam]',
providers: [QueryParamGroupService],
},] }
];
QueryParamDirective.ctorParameters = function () { return [
{ type: QueryParamGroupService, decorators: [{ type: i0.Optional }] },
{ type: Array, decorators: [{ type: i0.Optional }, { type: i0.Self }, { type: i0.Inject, args: [forms.NG_VALUE_ACCESSOR,] }] }
]; };
QueryParamDirective.propDecorators = {
queryParam: [{ type: i0.Input, args: ['queryParam',] }]
};
/**
* Binds a {@link QueryParam} to a DOM element.
*
* This directive accepts the name of a {@link QueryParam} inside its parent {@link QueryParamGroup}.
* It binds this parameter to the host element, which is required to have a [ControlValueAccessor]
* {@link https://angular.io/api/forms/ControlValueAccessor}.
*/
var QueryParamNameDirective = /** @class */ (function () {
/** @internal */
function QueryParamNameDirective(groupService, valueAccessors) {
this.groupService = groupService;
this._name = null;
if (!this.groupService) {
throw new Error("No parent configuration found. Did you forget to add [queryParamGroup]?");
}
this.valueAccessor = selectValueAccessor(valueAccessors);
}
Object.defineProperty(QueryParamNameDirective.prototype, "name", {
get: function () {
if (!this._name) {
throw new Error("No queryParamName has been specified.");
}
return this._name;
},
/**
* The name of the {@link QueryParam} inside its parent {@link QueryParamGroup}.
* Note that this does not refer to the [parameter name]{@link QueryParam#urlParam}.
*/
set: function (name) {
this._name = name;
},
enumerable: false,
configurable: true
});
/** @ignore */
QueryParamNameDirective.prototype.ngOnChanges = function (changes) {
var nameChange = changes['name'];
if (nameChange) {
if (!nameChange.firstChange) {
this.groupService.deregisterQueryParamDirective(nameChange.previousValue);
}
if (nameChange.currentValue) {
this.groupService.registerQueryParamDirective(this);
}
}
};
/** @ignore */
QueryParamNameDirective.prototype.ngOnDestroy = function () {
if (this.groupService) {
this.groupService.deregisterQueryParamDirective(this.name);
}
};
return QueryParamNameDirective;
}());
QueryParamNameDirective.decorators = [
{ type: i0.Directive, args: [{
selector: '[queryParamName]',
},] }
];
QueryParamNameDirective.ctorParameters = function () { return [
{ type: QueryParamGroupService, decorators: [{ type: i0.Optional }] },
{ type: Array, decorators: [{ type: i0.Optional }, { type: i0.Self }, { type: i0.Inject, args: [forms.NG_VALUE_ACCESSOR,] }] }
]; };
QueryParamNameDirective.propDecorators = {
name: [{ type: i0.Input, args: ['queryParamName',] }]
};
/**
* Binds a {@link QueryParamGroup} to a DOM element.
*
* This directive accepts an instance of {@link QueryParamGroup}. Any child using
* {@link QueryParamNameDirective} will then be matched against this group, and the
* synchronization process can take place.
*/
var QueryParamGroupDirective = /** @class */ (function () {
/** @internal */
function QueryParamGroupDirective(groupService) {
this.groupService = groupService;
/**
* The {@link QueryParamGroup} to bind.
*/
this.queryParamGroup = null;
}
/** @ignore */
QueryParamGroupDirective.prototype.ngOnChanges = function (changes) {
var groupChange = changes['queryParamGroup'];
if (groupChange) {
if (!groupChange.firstChange) {
throw new Error("Binding a different QueryParamGroup during runtime is currently not supported.");
}
var queryParamGroup = groupChange.currentValue;
if (!queryParamGroup) {
throw new Error("You added the queryParamGroup directive, but haven't supplied a group to use.");
}
this.groupService.setQueryParamGroup(queryParamGroup);
}
};
return QueryParamGroupDirective;
}());
QueryParamGroupDirective.decorators = [
{ type: i0.Directive, args: [{
selector: '[queryParamGroup]',
providers: [QueryParamGroupService],
},] }
];
QueryParamGroupDirective.ctorParameters = function () { return [
{ type: QueryParamGroupService }
]; };
QueryParamGroupDirective.propDecorators = {
queryParamGroup: [{ type: i0.Input, args: ['queryParamGroup',] }]
};
/**
* Provides an ad-hoc ControlValueAccessor to a component.
*
* This directive provides a ControlValueAccessor for the host on which it is applied
* by proxying the required interface through events and an API.
*
*
* <app-item-selector #ctrl
* controlValueAccessor #accessor="controlValueAccessor"
* (itemChange)="accessor.notifyChange($event)"
* (controlValueChange)="ctrl.item = $event">
* </app-item-selector>
*/
var ControlValueAccessorDirective = /** @class */ (function () {
function ControlValueAccessorDirective() {
/**
* Fired when a value should be written (model -> view).
*
* From the ControlValueAccessor perspective, this is the equivalent of
* writeValue. You should bind to this event and update your component's
* state with the given value.
*/
this.controlValueChange = new i0.EventEmitter();
/**
* Fired when the control's disabled change should change.
*
* From the ControlValueAccessor perspective, this is the equivalent of
* setDisabledState.
*
* This is currently not used by ngqp.
*/
this.disabledChange = new i0.EventEmitter();
this.fnChange = function (_) { };
this.fnTouched = function () { };
}
/**
* Write a new value to the model (view -> model)
*
* When your component's value changes, call this method to inform
* the model about the change.
*/
ControlValueAccessorDirective.prototype.notifyChange = function (value) {
this.fnChange(value);
};
/**
* Inform that the component has been touched by the user.
*
* This is currently not used by ngqp.
*/
ControlValueAccessorDirective.prototype.notifyTouched = function () {
this.fnTouched();
};
/** @internal */
ControlValueAccessorDirective.prototype.writeValue = function (value) {
this.controlValueChange.emit(value);
};
/** @internal */
ControlValueAccessorDirective.prototype.registerOnChange = function (fn) {
this.fnChange = fn;
};
/** @internal */
ControlValueAccessorDirective.prototype.registerOnTouched = function (fn) {
this.fnTouched = fn;
};
/** @internal */
ControlValueAccessorDirective.prototype.setDisabledState = function (isDisabled) {
this.disabledChange.emit(isDisabled);
};
return ControlValueAccessorDirective;
}());
ControlValueAccessorDirective.decorators = [
{ type: i0.Directive, args: [{
selector: '[controlValueAccessor]',
exportAs: 'controlValueAccessor',
providers: [
{
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return ControlValueAccessorDirective; }),
multi: true
}
],
},] }
];
ControlValueAccessorDirective.propDecorators = {
controlValueChange: [{ type: i0.Output, args: ['controlValueChange',] }],
disabledChange: [{ type: i0.Output, args: ['disabledChange',] }]
};
/** @ignore */
var SelectOptionDirective = /** @class */ (function () {
function SelectOptionDirective(parent, renderer, elementRef) {
this.parent = parent;
this.renderer = renderer;
this.elementRef = elementRef;
this.id = null;
if (this.parent) {
this.id = this.parent.registerOption();
}
}
SelectOptionDirective.prototype.ngOnInit = function () {
if (this.parent) {
this.renderer.setProperty(this.elementRef.nativeElement, 'value', this.id);
}
};
SelectOptionDirective.prototype.ngOnDestroy = function () {
if (this.parent) {
this.parent.deregisterOption(this.id);
this.parent.writeValue(this.parent.value);
}
};
Object.defineProperty(SelectOptionDirective.prototype, "value", {
set: function (value) {
if (this.parent) {
this.parent.updateOptionValue(this.id, value);
this.parent.writeValue(this.parent.value);
}
},
enumerable: false,
configurable: true
});
return SelectOptionDirective;
}());
SelectOptionDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'option',
},] }
];
SelectOptionDirective.ctorParameters = function () { return [
{ type: SelectControlValueAccessorDirective, decorators: [{ type: i0.Optional }, { type: i0.Host }] },
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
SelectOptionDirective.propDecorators = {
value: [{ type: i0.Input, args: ['value',] }]
};
/** @ignore */
var MultiSelectOptionDirective = /** @class */ (function () {
function MultiSelectOptionDirective(parent, renderer, elementRef) {
this.parent = parent;
this.renderer = renderer;
this.elementRef = elementRef;
this.id = null;
if (this.parent) {
this.id = this.parent.registerOption(this);
}
}
MultiSelectOptionDirective.prototype.ngOnInit = function () {
if (this.parent) {
this.renderer.setProperty(this.elementRef.nativeElement, 'value', this.id);
}
};
MultiSelectOptionDirective.prototype.ngOnDestroy = function () {
if (this.parent) {
this.parent.deregisterOption(this.id);
}
};
Object.defineProperty(MultiSelectOptionDirective.prototype, "value", {
set: function (value) {
if (this.parent) {
this.parent.updateOptionValue(this.id, value);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(MultiSelectOptionDirective.prototype, "selected", {
get: function () {
return this.elementRef.nativeElement.selected;
},
set: function (selected) {
if (this.parent) {
this.renderer.setProperty(this.elementRef.nativeElement, 'selected', selected);
}
},
enumerable: false,
configurable: true
});
return MultiSelectOptionDirective;
}());
MultiSelectOptionDirective.decorators = [
{ type: i0.Directive, args: [{
selector: 'option',
},] }
];
MultiSelectOptionDirective.ctorParameters = function () { return [
{ type: MultiSelectControlValueAccessorDirective, decorators: [{ type: i0.Optional }, { type: i0.Host }] },
{ type: i0.Renderer2 },
{ type: i0.ElementRef }
]; };
MultiSelectOptionDirective.propDecorators = {
value: [{ type: i0.Input, args: ['value',] }]
};
/** @internal */
var DefaultRouterAdapter = /** @class */ (function () {
function DefaultRouterAdapter(router, route) {
this.router = router;
this.route = route;
}
Object.defineProperty(DefaultRouterAdapter.prototype, "url", {
get: function () {
return this.router.url;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DefaultRouterAdapter.prototype, "queryParamMap", {
get: function () {
return this.route.queryParamMap;
},
enumerable: false,
configurable: true
});
DefaultRouterAdapter.prototype.navigate = function (queryParams, extras) {
if (extras === void 0) { extras = {}; }
return this.router.navigate([], Object.assign({ relativeTo: this.route, queryParamsHandling: 'merge', queryParams: queryParams }, extras));
};
DefaultRouterAdapter.prototype.getCurrentNavigation = function () {
return this.router.getCurrentNavigation();
};
return DefaultRouterAdapter;
}());
DefaultRouterAdapter.decorators = [
{ type: i0.Injectable }
];
DefaultRouterAdapter.ctorParameters = function () { return [
{ type: router.Router },
{ type: router.ActivatedRoute }
]; };
/** @ignore */
var DIRECTIVES = [
QueryParamDirective,
QueryParamNameDirective,
QueryParamGroupDirective,
ControlValueAccessorDirective,
// Accessors
DefaultControlValueAccessorDirective,
NumberControlValueAccessorDirective,
RangeControlValueAccessorDirective,
CheckboxControlValueAccessorDirective,
SelectControlValueAccessorDirective,
SelectOptionDirective,
MultiSelectControlValueAccessorDirective,
MultiSelectOptionDirective,
];
var ɵ0 = DefaultRouterOptions;
var QueryParamModule = /** @class */ (function () {
function QueryParamModule() {
}
QueryParamModule.withConfig = function (config) {
if (config === void 0) { config = {}; }
return {
ngModule: QueryParamModule,
providers: [
{
provide: NGQP_ROUTER_OPTIONS,
useValue: Object.assign(Object.assign({}, DefaultRouterOptions), config.routerOptions),
},
],
};
};
return QueryParamModule;
}());
QueryParamModule.decorators = [
{ type: i0.NgModule, args: [{
imports: [],
declarations: [DIRECTIVES],
exports: [DIRECTIVES],
providers: [
{
provide: NGQP_ROUTER_ADAPTER,
useClass: DefaultRouterAdapter
},
{
provide: NGQP_ROUTER_OPTIONS,
useValue: ɵ0,
},
],
},] }
];
/**
* Generated bundle index. Do not edit.
*/
exports.AbstractQueryParam = AbstractQueryParam;
exports.CheckboxControlValueAccessorDirective = CheckboxControlValueAccessorDirective;
exports.ControlValueAccessorDirective = ControlValueAccessorDirective;
exports.DefaultControlValueAccessorDirective = DefaultControlValueAccessorDirective;
exports.DefaultRouterAdapter = DefaultRouterAdapter;
exports.DefaultRouterOptions = DefaultRouterOptions;
exports.MultiQueryParam = MultiQueryParam;
exports.MultiSelectControlValueAccessorDirective = MultiSelectControlValueAccessorDirective;
exports.MultiSelectOptionDirective = MultiSelectOptionDirective;
exports.NGQP_BUILT_IN_ACCESSORS = NGQP_BUILT_IN_ACCESSORS;
exports.NGQP_ROUTER_ADAPTER = NGQP_ROUTER_ADAPTER;
exports.NGQP_ROUTER_OPTIONS = NGQP_ROUTER_OPTIONS;
exports.NumberControlValueAccessorDirective = NumberControlValueAccessorDirective;
exports.PartitionedQueryParam = PartitionedQueryParam;
exports.QueryParam = QueryParam;
exports.QueryParamBuilder = QueryParamBuilder;
exports.QueryParamDirective = QueryParamDirective;
exports.QueryParamGroup = QueryParamGroup;
exports.QueryParamGroupDirective = QueryParamGroupDirective;
exports.QueryParamModule = QueryParamModule;
exports.QueryParamNameDirective = QueryParamNameDirective;
exports.RangeControlValueAccessorDirective = RangeControlValueAccessorDirective;
exports.SelectControlValueAccessorDirective = SelectControlValueAccessorDirective;
exports.SelectOptionDirective = SelectOptionDirective;
exports.createBooleanDeserializer = createBooleanDeserializer;
exports.createBooleanSerializer = createBooleanSerializer;
exports.createNumberDeserializer = createNumberDeserializer;
exports.createNumberSerializer = createNumberSerializer;
exports.createStringDeserializer = createStringDeserializer;
exports.createStringSerializer = createStringSerializer;
exports.ɵc = QueryParamGroupService;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngqp-core.umd.js.map