UNPKG

mcs-ng-material

Version:

MCS NG-Meterial is based on mcs-web.

1,382 lines (1,370 loc) 420 kB
/** * State-based routing for AngularJS 1.x * NOTICE: This monolithic bundle also bundles the @uirouter/core code. * This causes it to be incompatible with plugins that depend on @uirouter/core. * We recommend switching to the ui-router-core.js and ui-router-angularjs.js bundles instead. * For more information, see https://ui-router.github.io/blog/uirouter-for-angularjs-umd-bundles * @version v1.0.13 * @link https://ui-router.github.io * @license MIT License, http://www.opensource.org/licenses/MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('angular')) : typeof define === 'function' && define.amd ? define(['exports', 'angular'], factory) : (factory((global['@uirouter/angularjs'] = {}),global.angular)); }(this, (function (exports,ng_from_import) { 'use strict'; var ng_from_global = angular; var ng = (ng_from_import && ng_from_import.module) ? ng_from_import : ng_from_global; /** * Higher order functions * * These utility functions are exported, but are subject to change without notice. * * @module common_hof */ /** */ /** * Returns a new function for [Partial Application](https://en.wikipedia.org/wiki/Partial_application) of the original function. * * Given a function with N parameters, returns a new function that supports partial application. * The new function accepts anywhere from 1 to N parameters. When that function is called with M parameters, * where M is less than N, it returns a new function that accepts the remaining parameters. It continues to * accept more parameters until all N parameters have been supplied. * * * This contrived example uses a partially applied function as an predicate, which returns true * if an object is found in both arrays. * @example * ``` * // returns true if an object is in both of the two arrays * function inBoth(array1, array2, object) { * return array1.indexOf(object) !== -1 && * array2.indexOf(object) !== 1; * } * let obj1, obj2, obj3, obj4, obj5, obj6, obj7 * let foos = [obj1, obj3] * let bars = [obj3, obj4, obj5] * * // A curried "copy" of inBoth * let curriedInBoth = curry(inBoth); * // Partially apply both the array1 and array2 * let inFoosAndBars = curriedInBoth(foos, bars); * * // Supply the final argument; since all arguments are * // supplied, the original inBoth function is then called. * let obj1InBoth = inFoosAndBars(obj1); // false * * // Use the inFoosAndBars as a predicate. * // Filter, on each iteration, supplies the final argument * let allObjs = [ obj1, obj2, obj3, obj4, obj5, obj6, obj7 ]; * let foundInBoth = allObjs.filter(inFoosAndBars); // [ obj3 ] * * ``` * * Stolen from: http://stackoverflow.com/questions/4394747/javascript-curry-function * * @param fn * @returns {*|function(): (*|any)} */ function curry(fn) { var initial_args = [].slice.apply(arguments, [1]); var func_args_length = fn.length; function curried(args) { if (args.length >= func_args_length) return fn.apply(null, args); return function () { return curried(args.concat([].slice.apply(arguments))); }; } return curried(initial_args); } /** * Given a varargs list of functions, returns a function that composes the argument functions, right-to-left * given: f(x), g(x), h(x) * let composed = compose(f,g,h) * then, composed is: f(g(h(x))) */ function compose() { var args = arguments; var start = args.length - 1; return function () { var i = start, result = args[start].apply(this, arguments); while (i--) result = args[i].call(this, result); return result; }; } /** * Given a varargs list of functions, returns a function that is composes the argument functions, left-to-right * given: f(x), g(x), h(x) * let piped = pipe(f,g,h); * then, piped is: h(g(f(x))) */ function pipe() { var funcs = []; for (var _i = 0; _i < arguments.length; _i++) { funcs[_i] = arguments[_i]; } return compose.apply(null, [].slice.call(arguments).reverse()); } /** * Given a property name, returns a function that returns that property from an object * let obj = { foo: 1, name: "blarg" }; * let getName = prop("name"); * getName(obj) === "blarg" */ var prop = function (name) { return function (obj) { return obj && obj[name]; }; }; /** * Given a property name and a value, returns a function that returns a boolean based on whether * the passed object has a property that matches the value * let obj = { foo: 1, name: "blarg" }; * let getName = propEq("name", "blarg"); * getName(obj) === true */ var propEq = curry(function (name, _val, obj) { return obj && obj[name] === _val; }); /** * Given a dotted property name, returns a function that returns a nested property from an object, or undefined * let obj = { id: 1, nestedObj: { foo: 1, name: "blarg" }, }; * let getName = prop("nestedObj.name"); * getName(obj) === "blarg" * let propNotFound = prop("this.property.doesnt.exist"); * propNotFound(obj) === undefined */ var parse = function (name) { return pipe.apply(null, name.split('.').map(prop)); }; /** * Given a function that returns a truthy or falsey value, returns a * function that returns the opposite (falsey or truthy) value given the same inputs */ var not = function (fn) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return !fn.apply(null, args); }; }; /** * Given two functions that return truthy or falsey values, returns a function that returns truthy * if both functions return truthy for the given arguments */ function and(fn1, fn2) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return fn1.apply(null, args) && fn2.apply(null, args); }; } /** * Given two functions that return truthy or falsey values, returns a function that returns truthy * if at least one of the functions returns truthy for the given arguments */ function or(fn1, fn2) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return fn1.apply(null, args) || fn2.apply(null, args); }; } /** * Check if all the elements of an array match a predicate function * * @param fn1 a predicate function `fn1` * @returns a function which takes an array and returns true if `fn1` is true for all elements of the array */ var all = function (fn1) { return function (arr) { return arr.reduce(function (b, x) { return b && !!fn1(x); }, true); }; }; // tslint:disable-next-line:variable-name var any = function (fn1) { return function (arr) { return arr.reduce(function (b, x) { return b || !!fn1(x); }, false); }; }; /** Given a class, returns a Predicate function that returns true if the object is of that class */ var is = function (ctor) { return function (obj) { return (obj != null && obj.constructor === ctor || obj instanceof ctor); }; }; /** Given a value, returns a Predicate function that returns true if another value is === equal to the original value */ var eq = function (value) { return function (other) { return value === other; }; }; /** Given a value, returns a function which returns the value */ var val = function (v) { return function () { return v; }; }; function invoke(fnName, args) { return function (obj) { return obj[fnName].apply(obj, args); }; } /** * Sorta like Pattern Matching (a functional programming conditional construct) * * See http://c2.com/cgi/wiki?PatternMatching * * This is a conditional construct which allows a series of predicates and output functions * to be checked and then applied. Each predicate receives the input. If the predicate * returns truthy, then its matching output function (mapping function) is provided with * the input and, then the result is returned. * * Each combination (2-tuple) of predicate + output function should be placed in an array * of size 2: [ predicate, mapFn ] * * These 2-tuples should be put in an outer array. * * @example * ``` * * // Here's a 2-tuple where the first element is the isString predicate * // and the second element is a function that returns a description of the input * let firstTuple = [ angular.isString, (input) => `Heres your string ${input}` ]; * * // Second tuple: predicate "isNumber", mapfn returns a description * let secondTuple = [ angular.isNumber, (input) => `(${input}) That's a number!` ]; * * let third = [ (input) => input === null, (input) => `Oh, null...` ]; * * let fourth = [ (input) => input === undefined, (input) => `notdefined` ]; * * let descriptionOf = pattern([ firstTuple, secondTuple, third, fourth ]); * * console.log(descriptionOf(undefined)); // 'notdefined' * console.log(descriptionOf(55)); // '(55) That's a number!' * console.log(descriptionOf("foo")); // 'Here's your string foo' * ``` * * @param struct A 2D array. Each element of the array should be an array, a 2-tuple, * with a Predicate and a mapping/output function * @returns {function(any): *} */ function pattern(struct) { return function (x) { for (var i = 0; i < struct.length; i++) { if (struct[i][0](x)) return struct[i][1](x); } }; } /** * @coreapi * @module core */ /** * Matches state names using glob-like pattern strings. * * Globs can be used in specific APIs including: * * - [[StateService.is]] * - [[StateService.includes]] * - The first argument to Hook Registration functions like [[TransitionService.onStart]] * - [[HookMatchCriteria]] and [[HookMatchCriterion]] * * A `Glob` string is a pattern which matches state names. * Nested state names are split into segments (separated by a dot) when processing. * The state named `foo.bar.baz` is split into three segments ['foo', 'bar', 'baz'] * * Globs work according to the following rules: * * ### Exact match: * * The glob `'A.B'` matches the state named exactly `'A.B'`. * * | Glob |Matches states named|Does not match state named| * |:------------|:--------------------|:---------------------| * | `'A'` | `'A'` | `'B'` , `'A.C'` | * | `'A.B'` | `'A.B'` | `'A'` , `'A.B.C'` | * | `'foo'` | `'foo'` | `'FOO'` , `'foo.bar'`| * * ### Single star (`*`) * * A single star (`*`) is a wildcard that matches exactly one segment. * * | Glob |Matches states named |Does not match state named | * |:------------|:---------------------|:--------------------------| * | `'*'` | `'A'` , `'Z'` | `'A.B'` , `'Z.Y.X'` | * | `'A.*'` | `'A.B'` , `'A.C'` | `'A'` , `'A.B.C'` | * | `'A.*.*'` | `'A.B.C'` , `'A.X.Y'`| `'A'`, `'A.B'` , `'Z.Y.X'`| * * ### Double star (`**`) * * A double star (`'**'`) is a wildcard that matches *zero or more segments* * * | Glob |Matches states named |Does not match state named | * |:------------|:----------------------------------------------|:----------------------------------| * | `'**'` | `'A'` , `'A.B'`, `'Z.Y.X'` | (matches all states) | * | `'A.**'` | `'A'` , `'A.B'` , `'A.C.X'` | `'Z.Y.X'` | * | `'**.X'` | `'X'` , `'A.X'` , `'Z.Y.X'` | `'A'` , `'A.login.Z'` | * | `'A.**.X'` | `'A.X'` , `'A.B.X'` , `'A.B.C.X'` | `'A'` , `'A.B.C'` | * */ var Glob = /** @class */ (function () { function Glob(text) { this.text = text; this.glob = text.split('.'); var regexpString = this.text.split('.') .map(function (seg) { if (seg === '**') return '(?:|(?:\\.[^.]*)*)'; if (seg === '*') return '\\.[^.]*'; return '\\.' + seg; }).join(''); this.regexp = new RegExp('^' + regexpString + '$'); } /** Returns true if the string has glob-like characters in it */ Glob.is = function (text) { return !!/[!,*]+/.exec(text); }; /** Returns a glob from the string, or null if the string isn't Glob-like */ Glob.fromString = function (text) { return Glob.is(text) ? new Glob(text) : null; }; Glob.prototype.matches = function (name) { return this.regexp.test('.' + name); }; return Glob; }()); /** * Internal representation of a UI-Router state. * * Instances of this class are created when a [[StateDeclaration]] is registered with the [[StateRegistry]]. * * A registered [[StateDeclaration]] is augmented with a getter ([[StateDeclaration.$$state]]) which returns the corresponding [[StateObject]] object. * * This class prototypally inherits from the corresponding [[StateDeclaration]]. * Each of its own properties (i.e., `hasOwnProperty`) are built using builders from the [[StateBuilder]]. */ var StateObject = /** @class */ (function () { /** @deprecated use State.create() */ function StateObject(config) { return StateObject.create(config || {}); } /** * Create a state object to put the private/internal implementation details onto. * The object's prototype chain looks like: * (Internal State Object) -> (Copy of State.prototype) -> (State Declaration object) -> (State Declaration's prototype...) * * @param stateDecl the user-supplied State Declaration * @returns {StateObject} an internal State object */ StateObject.create = function (stateDecl) { stateDecl = StateObject.isStateClass(stateDecl) ? new stateDecl() : stateDecl; var state = inherit(inherit(stateDecl, StateObject.prototype)); stateDecl.$$state = function () { return state; }; state.self = stateDecl; state.__stateObjectCache = { nameGlob: Glob.fromString(state.name), }; return state; }; /** * Returns true if the provided parameter is the same state. * * Compares the identity of the state against the passed value, which is either an object * reference to the actual `State` instance, the original definition object passed to * `$stateProvider.state()`, or the fully-qualified name. * * @param ref Can be one of (a) a `State` instance, (b) an object that was passed * into `$stateProvider.state()`, (c) the fully-qualified name of a state as a string. * @returns Returns `true` if `ref` matches the current `State` instance. */ StateObject.prototype.is = function (ref) { return this === ref || this.self === ref || this.fqn() === ref; }; /** * @deprecated this does not properly handle dot notation * @returns Returns a dot-separated name of the state. */ StateObject.prototype.fqn = function () { if (!this.parent || !(this.parent instanceof this.constructor)) return this.name; var name = this.parent.fqn(); return name ? name + '.' + this.name : this.name; }; /** * Returns the root node of this state's tree. * * @returns The root of this state's tree. */ StateObject.prototype.root = function () { return this.parent && this.parent.root() || this; }; /** * Gets the state's `Param` objects * * Gets the list of [[Param]] objects owned by the state. * If `opts.inherit` is true, it also includes the ancestor states' [[Param]] objects. * If `opts.matchingKeys` exists, returns only `Param`s whose `id` is a key on the `matchingKeys` object * * @param opts options */ StateObject.prototype.parameters = function (opts) { opts = defaults(opts, { inherit: true, matchingKeys: null }); var inherited = opts.inherit && this.parent && this.parent.parameters() || []; return inherited.concat(values(this.params)) .filter(function (param) { return !opts.matchingKeys || opts.matchingKeys.hasOwnProperty(param.id); }); }; /** * Returns a single [[Param]] that is owned by the state * * If `opts.inherit` is true, it also searches the ancestor states` [[Param]]s. * @param id the name of the [[Param]] to return * @param opts options */ StateObject.prototype.parameter = function (id, opts) { if (opts === void 0) { opts = {}; } return (this.url && this.url.parameter(id, opts) || find(values(this.params), propEq('id', id)) || opts.inherit && this.parent && this.parent.parameter(id)); }; StateObject.prototype.toString = function () { return this.fqn(); }; /** Predicate which returns true if the object is an class with @State() decorator */ StateObject.isStateClass = function (stateDecl) { return isFunction(stateDecl) && stateDecl['__uiRouterState'] === true; }; /** Predicate which returns true if the object is an internal [[StateObject]] object */ StateObject.isState = function (obj) { return isObject(obj['__stateObjectCache']); }; return StateObject; }()); /** Predicates * * These predicates return true/false based on the input. * Although these functions are exported, they are subject to change without notice. * * @module common_predicates */ /** */ var toStr = Object.prototype.toString; var tis = function (t) { return function (x) { return typeof (x) === t; }; }; var isUndefined = tis('undefined'); var isDefined = not(isUndefined); var isNull = function (o) { return o === null; }; var isNullOrUndefined = or(isNull, isUndefined); var isFunction = tis('function'); var isNumber = tis('number'); var isString = tis('string'); var isObject = function (x) { return x !== null && typeof x === 'object'; }; var isArray = Array.isArray; var isDate = (function (x) { return toStr.call(x) === '[object Date]'; }); var isRegExp = (function (x) { return toStr.call(x) === '[object RegExp]'; }); var isState = StateObject.isState; /** * Predicate which checks if a value is injectable * * A value is "injectable" if it is a function, or if it is an ng1 array-notation-style array * where all the elements in the array are Strings, except the last one, which is a Function */ function isInjectable(val$$1) { if (isArray(val$$1) && val$$1.length) { var head = val$$1.slice(0, -1), tail = val$$1.slice(-1); return !(head.filter(not(isString)).length || tail.filter(not(isFunction)).length); } return isFunction(val$$1); } /** * Predicate which checks if a value looks like a Promise * * It is probably a Promise if it's an object, and it has a `then` property which is a Function */ var isPromise = and(isObject, pipe(prop('then'), isFunction)); var notImplemented = function (fnname) { return function () { throw new Error(fnname + "(): No coreservices implementation for UI-Router is loaded."); }; }; var services = { $q: undefined, $injector: undefined, }; /** * Random utility functions used in the UI-Router code * * These functions are exported, but are subject to change without notice. * * @preferred * @module common */ /** for typedoc */ var root = (typeof self === 'object' && self.self === self && self) || (typeof global === 'object' && global.global === global && global) || undefined; var angular$1 = root.angular || {}; var fromJson = angular$1.fromJson || JSON.parse.bind(JSON); var toJson = angular$1.toJson || JSON.stringify.bind(JSON); var forEach = angular$1.forEach || _forEach; var extend = Object.assign || _extend; var equals = angular$1.equals || _equals; function identity(x) { return x; } function noop() { } /** * Builds proxy functions on the `to` object which pass through to the `from` object. * * For each key in `fnNames`, creates a proxy function on the `to` object. * The proxy function calls the real function on the `from` object. * * * #### Example: * This example creates an new class instance whose functions are prebound to the new'd object. * ```js * class Foo { * constructor(data) { * // Binds all functions from Foo.prototype to 'this', * // then copies them to 'this' * bindFunctions(Foo.prototype, this, this); * this.data = data; * } * * log() { * console.log(this.data); * } * } * * let myFoo = new Foo([1,2,3]); * var logit = myFoo.log; * logit(); // logs [1, 2, 3] from the myFoo 'this' instance * ``` * * #### Example: * This example creates a bound version of a service function, and copies it to another object * ``` * * var SomeService = { * this.data = [3, 4, 5]; * this.log = function() { * console.log(this.data); * } * } * * // Constructor fn * function OtherThing() { * // Binds all functions from SomeService to SomeService, * // then copies them to 'this' * bindFunctions(SomeService, this, SomeService); * } * * let myOtherThing = new OtherThing(); * myOtherThing.log(); // logs [3, 4, 5] from SomeService's 'this' * ``` * * @param source A function that returns the source object which contains the original functions to be bound * @param target A function that returns the target object which will receive the bound functions * @param bind A function that returns the object which the functions will be bound to * @param fnNames The function names which will be bound (Defaults to all the functions found on the 'from' object) * @param latebind If true, the binding of the function is delayed until the first time it's invoked */ function createProxyFunctions(source, target, bind, fnNames, latebind) { if (latebind === void 0) { latebind = false; } var bindFunction = function (fnName) { return source()[fnName].bind(bind()); }; var makeLateRebindFn = function (fnName) { return function lateRebindFunction() { target[fnName] = bindFunction(fnName); return target[fnName].apply(null, arguments); }; }; fnNames = fnNames || Object.keys(source()); return fnNames.reduce(function (acc, name) { acc[name] = latebind ? makeLateRebindFn(name) : bindFunction(name); return acc; }, target); } /** * prototypal inheritance helper. * Creates a new object which has `parent` object as its prototype, and then copies the properties from `extra` onto it */ var inherit = function (parent, extra) { return extend(Object.create(parent), extra); }; /** Given an array, returns true if the object is found in the array, (using indexOf) */ var inArray = curry(_inArray); function _inArray(array, obj) { return array.indexOf(obj) !== -1; } /** * Given an array, and an item, if the item is found in the array, it removes it (in-place). * The same array is returned */ var removeFrom = curry(_removeFrom); function _removeFrom(array, obj) { var idx = array.indexOf(obj); if (idx >= 0) array.splice(idx, 1); return array; } /** pushes a values to an array and returns the value */ var pushTo = curry(_pushTo); function _pushTo(arr, val$$1) { return (arr.push(val$$1), val$$1); } /** Given an array of (deregistration) functions, calls all functions and removes each one from the source array */ var deregAll = function (functions) { return functions.slice().forEach(function (fn) { typeof fn === 'function' && fn(); removeFrom(functions, fn); }); }; /** * Applies a set of defaults to an options object. The options object is filtered * to only those properties of the objects in the defaultsList. * Earlier objects in the defaultsList take precedence when applying defaults. */ function defaults(opts) { var defaultsList = []; for (var _i = 1; _i < arguments.length; _i++) { defaultsList[_i - 1] = arguments[_i]; } var _defaultsList = defaultsList.concat({}).reverse(); var defaultVals = extend.apply(null, _defaultsList); return extend({}, defaultVals, pick(opts || {}, Object.keys(defaultVals))); } /** Reduce function that merges each element of the list into a single object, using extend */ var mergeR = function (memo, item) { return extend(memo, item); }; /** * Finds the common ancestor path between two states. * * @param {Object} first The first state. * @param {Object} second The second state. * @return {Array} Returns an array of state names in descending order, not including the root. */ function ancestors(first, second) { var path = []; for (var n in first.path) { if (first.path[n] !== second.path[n]) break; path.push(first.path[n]); } return path; } /** * Return a copy of the object only containing the whitelisted properties. * * #### Example: * ``` * var foo = { a: 1, b: 2, c: 3 }; * var ab = pick(foo, ['a', 'b']); // { a: 1, b: 2 } * ``` * @param obj the source object * @param propNames an Array of strings, which are the whitelisted property names */ function pick(obj, propNames) { var objCopy = {}; for (var _prop in obj) { if (propNames.indexOf(_prop) !== -1) { objCopy[_prop] = obj[_prop]; } } return objCopy; } /** * Return a copy of the object omitting the blacklisted properties. * * @example * ``` * * var foo = { a: 1, b: 2, c: 3 }; * var ab = omit(foo, ['a', 'b']); // { c: 3 } * ``` * @param obj the source object * @param propNames an Array of strings, which are the blacklisted property names */ function omit(obj, propNames) { return Object.keys(obj) .filter(not(inArray(propNames))) .reduce(function (acc, key) { return (acc[key] = obj[key], acc); }, {}); } /** * Maps an array, or object to a property (by name) */ function pluck(collection, propName) { return map(collection, prop(propName)); } /** Filters an Array or an Object's properties based on a predicate */ function filter(collection, callback) { var arr = isArray(collection), result = arr ? [] : {}; var accept = arr ? function (x) { return result.push(x); } : function (x, key) { return result[key] = x; }; forEach(collection, function (item, i) { if (callback(item, i)) accept(item, i); }); return result; } /** Finds an object from an array, or a property of an object, that matches a predicate */ function find(collection, callback) { var result; forEach(collection, function (item, i) { if (result) return; if (callback(item, i)) result = item; }); return result; } /** Given an object, returns a new object, where each property is transformed by the callback function */ var mapObj = map; /** Maps an array or object properties using a callback function */ function map(collection, callback) { var result = isArray(collection) ? [] : {}; forEach(collection, function (item, i) { return result[i] = callback(item, i); }); return result; } /** * Given an object, return its enumerable property values * * @example * ``` * * let foo = { a: 1, b: 2, c: 3 } * let vals = values(foo); // [ 1, 2, 3 ] * ``` */ var values = function (obj) { return Object.keys(obj).map(function (key) { return obj[key]; }); }; /** * Reduce function that returns true if all of the values are truthy. * * @example * ``` * * let vals = [ 1, true, {}, "hello world"]; * vals.reduce(allTrueR, true); // true * * vals.push(0); * vals.reduce(allTrueR, true); // false * ``` */ var allTrueR = function (memo, elem) { return memo && elem; }; /** * Reduce function that returns true if any of the values are truthy. * * * @example * ``` * * let vals = [ 0, null, undefined ]; * vals.reduce(anyTrueR, true); // false * * vals.push("hello world"); * vals.reduce(anyTrueR, true); // true * ``` */ var anyTrueR = function (memo, elem) { return memo || elem; }; /** * Reduce function which un-nests a single level of arrays * @example * ``` * * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; * input.reduce(unnestR, []) // [ "a", "b", "c", "d", [ "double, "nested" ] ] * ``` */ var unnestR = function (memo, elem) { return memo.concat(elem); }; /** * Reduce function which recursively un-nests all arrays * * @example * ``` * * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; * input.reduce(unnestR, []) // [ "a", "b", "c", "d", "double, "nested" ] * ``` */ var flattenR = function (memo, elem) { return isArray(elem) ? memo.concat(elem.reduce(flattenR, [])) : pushR(memo, elem); }; /** * Reduce function that pushes an object to an array, then returns the array. * Mostly just for [[flattenR]] and [[uniqR]] */ function pushR(arr, obj) { arr.push(obj); return arr; } /** Reduce function that filters out duplicates */ var uniqR = function (acc, token) { return inArray(acc, token) ? acc : pushR(acc, token); }; /** * Return a new array with a single level of arrays unnested. * * @example * ``` * * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; * unnest(input) // [ "a", "b", "c", "d", [ "double, "nested" ] ] * ``` */ var unnest = function (arr) { return arr.reduce(unnestR, []); }; /** * Return a completely flattened version of an array. * * @example * ``` * * let input = [ [ "a", "b" ], [ "c", "d" ], [ [ "double", "nested" ] ] ]; * flatten(input) // [ "a", "b", "c", "d", "double, "nested" ] * ``` */ var flatten = function (arr) { return arr.reduce(flattenR, []); }; /** * Given a .filter Predicate, builds a .filter Predicate which throws an error if any elements do not pass. * @example * ``` * * let isNumber = (obj) => typeof(obj) === 'number'; * let allNumbers = [ 1, 2, 3, 4, 5 ]; * allNumbers.filter(assertPredicate(isNumber)); //OK * * let oneString = [ 1, 2, 3, 4, "5" ]; * oneString.filter(assertPredicate(isNumber, "Not all numbers")); // throws Error(""Not all numbers""); * ``` */ var assertPredicate = assertFn; /** * Given a .map function, builds a .map function which throws an error if any mapped elements do not pass a truthyness test. * @example * ``` * * var data = { foo: 1, bar: 2 }; * * let keys = [ 'foo', 'bar' ] * let values = keys.map(assertMap(key => data[key], "Key not found")); * // values is [1, 2] * * let keys = [ 'foo', 'bar', 'baz' ] * let values = keys.map(assertMap(key => data[key], "Key not found")); * // throws Error("Key not found") * ``` */ var assertMap = assertFn; function assertFn(predicateOrMap, errMsg) { if (errMsg === void 0) { errMsg = 'assert failure'; } return function (obj) { var result = predicateOrMap(obj); if (!result) { throw new Error(isFunction(errMsg) ? errMsg(obj) : errMsg); } return result; }; } /** * Like _.pairs: Given an object, returns an array of key/value pairs * * @example * ``` * * pairs({ foo: "FOO", bar: "BAR }) // [ [ "foo", "FOO" ], [ "bar": "BAR" ] ] * ``` */ var pairs = function (obj) { return Object.keys(obj).map(function (key) { return [key, obj[key]]; }); }; /** * Given two or more parallel arrays, returns an array of tuples where * each tuple is composed of [ a[i], b[i], ... z[i] ] * * @example * ``` * * let foo = [ 0, 2, 4, 6 ]; * let bar = [ 1, 3, 5, 7 ]; * let baz = [ 10, 30, 50, 70 ]; * arrayTuples(foo, bar); // [ [0, 1], [2, 3], [4, 5], [6, 7] ] * arrayTuples(foo, bar, baz); // [ [0, 1, 10], [2, 3, 30], [4, 5, 50], [6, 7, 70] ] * ``` */ function arrayTuples() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (args.length === 0) return []; var maxArrayLen = args.reduce(function (min, arr) { return Math.min(arr.length, min); }, 9007199254740991); // aka 2^53 − 1 aka Number.MAX_SAFE_INTEGER var result = []; var _loop_1 = function (i) { // This is a hot function // Unroll when there are 1-4 arguments switch (args.length) { case 1: result.push([args[0][i]]); break; case 2: result.push([args[0][i], args[1][i]]); break; case 3: result.push([args[0][i], args[1][i], args[2][i]]); break; case 4: result.push([args[0][i], args[1][i], args[2][i], args[3][i]]); break; default: result.push(args.map(function (array) { return array[i]; })); break; } }; for (var i = 0; i < maxArrayLen; i++) { _loop_1(i); } return result; } /** * Reduce function which builds an object from an array of [key, value] pairs. * * Each iteration sets the key/val pair on the memo object, then returns the memo for the next iteration. * * Each keyValueTuple should be an array with values [ key: string, value: any ] * * @example * ``` * * var pairs = [ ["fookey", "fooval"], ["barkey", "barval"] ] * * var pairsToObj = pairs.reduce((memo, pair) => applyPairs(memo, pair), {}) * // pairsToObj == { fookey: "fooval", barkey: "barval" } * * // Or, more simply: * var pairsToObj = pairs.reduce(applyPairs, {}) * // pairsToObj == { fookey: "fooval", barkey: "barval" } * ``` */ function applyPairs(memo, keyValTuple) { var key, value; if (isArray(keyValTuple)) key = keyValTuple[0], value = keyValTuple[1]; if (!isString(key)) throw new Error('invalid parameters to applyPairs'); memo[key] = value; return memo; } /** Get the last element of an array */ function tail(arr) { return arr.length && arr[arr.length - 1] || undefined; } /** * shallow copy from src to dest */ function copy(src, dest) { if (dest) Object.keys(dest).forEach(function (key) { return delete dest[key]; }); if (!dest) dest = {}; return extend(dest, src); } /** Naive forEach implementation works with Objects or Arrays */ function _forEach(obj, cb, _this) { if (isArray(obj)) return obj.forEach(cb, _this); Object.keys(obj).forEach(function (key) { return cb(obj[key], key); }); } function _extend(toObj) { for (var i = 1; i < arguments.length; i++) { var obj = arguments[i]; if (!obj) continue; var keys = Object.keys(obj); for (var j = 0; j < keys.length; j++) { toObj[keys[j]] = obj[keys[j]]; } } return toObj; } function _equals(o1, o2) { if (o1 === o2) return true; if (o1 === null || o2 === null) return false; if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN var t1 = typeof o1, t2 = typeof o2; if (t1 !== t2 || t1 !== 'object') return false; var tup = [o1, o2]; if (all(isArray)(tup)) return _arraysEq(o1, o2); if (all(isDate)(tup)) return o1.getTime() === o2.getTime(); if (all(isRegExp)(tup)) return o1.toString() === o2.toString(); if (all(isFunction)(tup)) return true; // meh var predicates = [isFunction, isArray, isDate, isRegExp]; if (predicates.map(any).reduce(function (b, fn) { return b || !!fn(tup); }, false)) return false; var keys = {}; for (var key in o1) { if (!_equals(o1[key], o2[key])) return false; keys[key] = true; } for (var key in o2) { if (!keys[key]) return false; } return true; } function _arraysEq(a1, a2) { if (a1.length !== a2.length) return false; return arrayTuples(a1, a2).reduce(function (b, t) { return b && _equals(t[0], t[1]); }, true); } // issue #2676 var silenceUncaughtInPromise = function (promise) { return promise.catch(function (e) { return 0; }) && promise; }; var silentRejection = function (error) { return silenceUncaughtInPromise(services.$q.reject(error)); }; /** * @module common */ /** for typedoc */ var Queue = /** @class */ (function () { function Queue(_items, _limit) { if (_items === void 0) { _items = []; } if (_limit === void 0) { _limit = null; } this._items = _items; this._limit = _limit; } Queue.prototype.enqueue = function (item) { var items = this._items; items.push(item); if (this._limit && items.length > this._limit) items.shift(); return item; }; Queue.prototype.dequeue = function () { if (this.size()) return this._items.splice(0, 1)[0]; }; Queue.prototype.clear = function () { var current = this._items; this._items = []; return current; }; Queue.prototype.size = function () { return this._items.length; }; Queue.prototype.remove = function (item) { var idx = this._items.indexOf(item); return idx > -1 && this._items.splice(idx, 1)[0]; }; Queue.prototype.peekTail = function () { return this._items[this._items.length - 1]; }; Queue.prototype.peekHead = function () { if (this.size()) return this._items[0]; }; return Queue; }()); /** * @coreapi * @module transition */ /** for typedoc */ (function (RejectType) { RejectType[RejectType["SUPERSEDED"] = 2] = "SUPERSEDED"; RejectType[RejectType["ABORTED"] = 3] = "ABORTED"; RejectType[RejectType["INVALID"] = 4] = "INVALID"; RejectType[RejectType["IGNORED"] = 5] = "IGNORED"; RejectType[RejectType["ERROR"] = 6] = "ERROR"; })(exports.RejectType || (exports.RejectType = {})); /** @hidden */ var id = 0; var Rejection = /** @class */ (function () { function Rejection(type, message, detail) { this.$id = id++; this.type = type; this.message = message; this.detail = detail; } /** Returns true if the obj is a rejected promise created from the `asPromise` factory */ Rejection.isRejectionPromise = function (obj) { return obj && (typeof obj.then === 'function') && is(Rejection)(obj._transitionRejection); }; /** Returns a Rejection due to transition superseded */ Rejection.superseded = function (detail, options) { var message = 'The transition has been superseded by a different transition'; var rejection = new Rejection(exports.RejectType.SUPERSEDED, message, detail); if (options && options.redirected) { rejection.redirected = true; } return rejection; }; /** Returns a Rejection due to redirected transition */ Rejection.redirected = function (detail) { return Rejection.superseded(detail, { redirected: true }); }; /** Returns a Rejection due to invalid transition */ Rejection.invalid = function (detail) { var message = 'This transition is invalid'; return new Rejection(exports.RejectType.INVALID, message, detail); }; /** Returns a Rejection due to ignored transition */ Rejection.ignored = function (detail) { var message = 'The transition was ignored'; return new Rejection(exports.RejectType.IGNORED, message, detail); }; /** Returns a Rejection due to aborted transition */ Rejection.aborted = function (detail) { var message = 'The transition has been aborted'; return new Rejection(exports.RejectType.ABORTED, message, detail); }; /** Returns a Rejection due to aborted transition */ Rejection.errored = function (detail) { var message = 'The transition errored'; return new Rejection(exports.RejectType.ERROR, message, detail); }; /** * Returns a Rejection * * Normalizes a value as a Rejection. * If the value is already a Rejection, returns it. * Otherwise, wraps and returns the value as a Rejection (Rejection type: ERROR). * * @returns `detail` if it is already a `Rejection`, else returns an ERROR Rejection. */ Rejection.normalize = function (detail) { return is(Rejection)(detail) ? detail : Rejection.errored(detail); }; Rejection.prototype.toString = function () { var detailString = function (d) { return d && d.toString !== Object.prototype.toString ? d.toString() : stringify(d); }; var detail = detailString(this.detail); var _a = this, $id = _a.$id, type = _a.type, message = _a.message; return "Transition Rejection($id: " + $id + " type: " + type + ", message: " + message + ", detail: " + detail + ")"; }; Rejection.prototype.toPromise = function () { return extend(silentRejection(this), { _transitionRejection: this }); }; return Rejection; }()); /** * # Transition tracing (debug) * * Enable transition tracing to print transition information to the console, * in order to help debug your application. * Tracing logs detailed information about each Transition to your console. * * To enable tracing, import the [[Trace]] singleton and enable one or more categories. * * ### ES6 * ```js * import {trace} from "ui-router-ng2"; // or "angular-ui-router" * trace.enable(1, 5); // TRANSITION and VIEWCONFIG * ``` * * ### CJS * ```js * let trace = require("angular-ui-router").trace; // or "ui-router-ng2" * trace.enable("TRANSITION", "VIEWCONFIG"); * ``` * * ### Globals * ```js * let trace = window["angular-ui-router"].trace; // or "ui-router-ng2" * trace.enable(); // Trace everything (very verbose) * ``` * * ### Angular 1: * ```js * app.run($trace => $trace.enable()); * ``` * * @coreapi * @module trace */ /* tslint:disable:no-console */ /** @hidden */ function uiViewString(uiview) { if (!uiview) return 'ui-view (defunct)'; var state = uiview.creationContext ? uiview.creationContext.name || '(root)' : '(none)'; return "[ui-view#" + uiview.id + " " + uiview.$type + ":" + uiview.fqn + " (" + uiview.name + "@" + state + ")]"; } /** @hidden */ var viewConfigString = function (viewConfig) { var view = viewConfig.viewDecl; var state = view.$context.name || '(root)'; return "[View#" + viewConfig.$id + " from '" + state + "' state]: target ui-view: '" + view.$uiViewName + "@" + view.$uiViewContextAnchor + "'"; }; /** @hidden */ function normalizedCat(input) { return isNumber(input) ? exports.Category[input] : exports.Category[exports.Category[input]]; } /** @hidden */ var consoleLog = Function.prototype.bind.call(console.log, console); /** @hidden */ var consoletable = isFunction(console.table) ? console.table.bind(console) : consoleLog.bind(console); /** * Trace categories Enum * * Enable or disable a category using [[Trace.enable]] or [[Trace.disable]] * * `trace.enable(Category.TRANSITION)` * * These can also be provided using a matching string, or position ordinal * * `trace.enable("TRANSITION")` * * `trace.enable(1)` */ (function (Category) { Category[Category["RESOLVE"] = 0] = "RESOLVE"; Category[Category["TRANSITION"] = 1] = "TRANSITION"; Category[Category["HOOK"] = 2] = "HOOK"; Category[Category["UIVIEW"] = 3] = "UIVIEW"; Category[Category["VIEWCONFIG"] = 4] = "VIEWCONFIG"; })(exports.Category || (exports.Category = {})); /** @hidden */ var _tid = parse('$id'); /** @hidden */ var _rid = parse('router.$id'); /** @hidden */ var transLbl = function (trans) { return "Transition #" + _tid(trans) + "-" + _rid(trans); }; /** * Prints UI-Router Transition trace information to the console. */ var Trace = /** @class */ (function () { /** @hidden */ function Trace() { /** @hidden */ this._enabled = {}; this.approximateDigests = 0; } /** @hidden */ Trace.prototype._set = function (enabled, categories) { var _this = this; if (!categories.length) { categories = Object.keys(exports.Category) .map(function (k) { return parseInt(k, 10); }) .filter(function (k) { return !isNaN(k); }) .map(function (key) { return exports.Category[key]; }); } categories.map(normalizedCat).forEach(function (category) { return _this._enabled[category] = enabled; }); }; Trace.prototype.enable = function () { var categories = []; for (var _i = 0; _i < arguments.length; _i++) { categories[_i] = arguments[_i]; } this._set(true, categories); }; Trace.prototype.disable = function () { var categories = []; for (var _i = 0; _i < arguments.length; _i++) { categories[_i] = arguments[_i]; } this._set(false, categories); }; /** * Retrieves the enabled stateus of a [[Category]] * * ```js * trace.enabled("VIEWCONFIG"); // true or false * ``` * * @returns boolean true if the category is enabled */ Trace.prototype.enabled = function (category) { return !!this._enabled[normalizedCat(category)]; }; /** @internalapi called by ui-router code */ Trace.prototype.traceTransitionStart = function (trans) { if (!this.enabled(exports.Category.TRANSITION)) return; console.log(transLbl(trans) + ": Started -> " + stringify(trans)); }; /** @internalapi called by ui-router code */ Trace.prototype.traceTransitionIgnored = function (trans) { if (!this.enabled(exports.Category.TRANSITION)) return; console.log(transLbl(trans) + ": Ignored <> " + stringify(trans)); }; /** @internalapi called by ui-router code */ Trace.prototype.traceHookInvocation = function (step, trans, options) { if (!this.enabled(exports.Category.HOOK)) return; var event = parse('traceData.hookType')(options) || 'internal', context = parse('traceData.context.state.name')(options) || parse('traceData.context')(options) || 'unknown', name = functionToString(step.registeredHook.callback); console.log(transLbl(trans) + ": Hook -> " + event + " context: " + context + ", " + maxLength(200, name)); }; /** @internalapi called by ui-router code */ Trace.prototype.traceHookResult = function (hookResult, trans, transitionOptions) { if (!this.enabled(exports.Category.HOOK)) return; console.log(transLbl(trans) + ": <- Hook returned: " + maxLength(200, stringify(hookResult))); }; /** @internalapi called by ui-router code */ Trace.prototype.traceResolvePath = function (path, when, trans) { if (!this.enabled(exports.Category.RESOLVE)) return; console.log(transLbl(trans) + ": Resolving " + path + " (" + when + ")"); }; /** @internalapi called by ui-router code */ Trace.prototype.traceResolvableResolved = function (resolvable, trans) { if (!this.enabled(exports.Category.RESOLVE)) return; console.log(transLbl(trans) + ": <- Resolved " + resolvable + " to: " + maxLength(200, stringify(resolvable.data))); }; /** @internalapi called by ui-router code */ Trace.prototype.traceError = function (reason, trans) { if (!this.enabled(exports.Category.TRANSITION)) return; console.log(transLbl(trans) + ": <- Rejected " + stringify(trans) + ", reason: " + reason); }; /** @internalapi called by ui-router code */ Trace.prototype.traceSuccess = function (finalState, trans) { if (!this.enabled(exports.Category.TRANSITION)) return; console.log(transLbl(trans) + ": <- Success " + stringify(trans) + ", final state: " + finalState.name); }; /** @internalapi called by ui-router code */ Trace.prototype.traceUIViewEvent = function (event, viewData, extra) { if (extra === void 0) { extra = ''; } if (!this.enabled(exports.Category.UIVIEW)) return; console.log("ui-view: " + padString(30, event) + " " + uiViewString(viewData) + extra); }; /** @internalapi called by ui-router code */ Trace.prototype.traceUIViewConfigUpdated = function (viewData, context) { if (!this.enabled(exports.Category.UIVIEW)) return; this.traceUIViewEvent('Updating', viewData, " with ViewConfig from context='" + context + "'"); }; /** @internalapi called by ui-router code */ Trace.prototype.traceUIViewFill = function (viewData, html) { if (!this.enabled(exports.Category.UIVIEW)) return; this.traceUIViewEvent('Fill', viewData, " with: " + maxLength(200, html)); }; /** @internalapi called by ui-router code */ Trace.prototype.traceViewSync = function (pairs) { if (!this.enabled(exports.Category.VIEWCONFIG)) return; var uivheader = 'uiview component fqn'; var cfgheader = 'view config state (view name)'; var mapping = pairs.map(function (_a) { var uiView = _a.uiView, viewConfig = _a.viewConfig; var uiv = uiView && uiView.fqn; var cfg = viewConfig && viewConfig.viewDecl.$context.name + ": (" + viewConfig.viewDecl.$name + ")"; return _b = {}, _b[uivheader] = uiv, _b[cfgheader] = cfg, _b; var _b; }).sort(function (a, b) { return (a[uivheader] || '').localeCompare(b[uivheader] || ''); }); consoletable(mapping); }; /** @internalapi called by ui-router code */ Trace.prototype.traceViewServiceEvent = function (event, viewConfig) { if (!this.enabled(exports.Category.VIEWCONFIG)) return; console.log("VIEWCONFIG: " + event + " " + viewConfigString(viewConfig)); }; /** @internalapi called by ui-router code */ Trace.prototype.traceViewServiceUIViewEvent = function (event, viewData) { if (!this.enabled(exports.Category.VIEWCONFIG)) return; console.log