@angular-wave/angular.ts 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/angular-ts.esm.js +1 -1
  2. package/dist/angular-ts.umd.js +1 -1
  3. package/package.json +4 -1
  4. package/src/exts/messages.md +30 -30
  5. package/src/index.js +1 -0
  6. package/src/public.js +2 -0
  7. package/src/router/adapter/directives/stateDirectives.js +695 -0
  8. package/src/router/adapter/directives/viewDirective.js +514 -0
  9. package/src/router/adapter/injectables.js +314 -0
  10. package/src/router/adapter/interface.js +1 -0
  11. package/src/router/adapter/locationServices.js +84 -0
  12. package/src/router/adapter/services.js +126 -0
  13. package/src/router/adapter/stateFilters.js +43 -0
  14. package/src/router/adapter/stateProvider.js +137 -0
  15. package/src/router/adapter/statebuilders/onEnterExitRetain.js +30 -0
  16. package/src/router/adapter/statebuilders/views.js +146 -0
  17. package/src/router/adapter/templateFactory.js +218 -0
  18. package/src/router/adapter/viewScroll.js +31 -0
  19. package/src/router/core/common/common.js +496 -0
  20. package/src/router/core/common/coreservices.js +15 -0
  21. package/src/router/core/common/glob.js +75 -0
  22. package/src/router/core/common/hof.js +194 -0
  23. package/src/router/core/common/predicates.js +44 -0
  24. package/src/router/core/common/queue.js +41 -0
  25. package/src/router/core/common/safeConsole.js +38 -0
  26. package/src/router/core/common/strings.js +141 -0
  27. package/src/router/core/common/trace.js +232 -0
  28. package/src/router/core/globals.js +29 -0
  29. package/src/router/core/hooks/coreResolvables.js +33 -0
  30. package/src/router/core/hooks/ignoredTransition.js +25 -0
  31. package/src/router/core/hooks/invalidTransition.js +14 -0
  32. package/src/router/core/hooks/lazyLoad.js +102 -0
  33. package/src/router/core/hooks/onEnterExitRetain.js +55 -0
  34. package/src/router/core/hooks/redirectTo.js +36 -0
  35. package/src/router/core/hooks/resolve.js +57 -0
  36. package/src/router/core/hooks/updateGlobals.js +30 -0
  37. package/src/router/core/hooks/url.js +25 -0
  38. package/src/router/core/hooks/views.js +39 -0
  39. package/src/router/core/interface.js +3 -0
  40. package/src/router/core/params/README.md +8 -0
  41. package/src/router/core/params/param.js +232 -0
  42. package/src/router/core/params/paramType.js +139 -0
  43. package/src/router/core/params/paramTypes.js +163 -0
  44. package/src/router/core/params/stateParams.js +35 -0
  45. package/src/router/core/path/pathNode.js +77 -0
  46. package/src/router/core/path/pathUtils.js +199 -0
  47. package/src/router/core/resolve/interface.js +10 -0
  48. package/src/router/core/resolve/resolvable.js +124 -0
  49. package/src/router/core/resolve/resolveContext.js +211 -0
  50. package/src/router/core/router.js +203 -0
  51. package/src/router/core/state/README.md +21 -0
  52. package/src/router/core/state/stateBuilder.js +332 -0
  53. package/src/router/core/state/stateMatcher.js +65 -0
  54. package/src/router/core/state/stateObject.js +117 -0
  55. package/src/router/core/state/stateQueueManager.js +89 -0
  56. package/src/router/core/state/stateRegistry.js +175 -0
  57. package/src/router/core/state/stateService.js +592 -0
  58. package/src/router/core/state/targetState.js +159 -0
  59. package/src/router/core/transition/hookBuilder.js +127 -0
  60. package/src/router/core/transition/hookRegistry.js +175 -0
  61. package/src/router/core/transition/interface.js +14 -0
  62. package/src/router/core/transition/rejectFactory.js +122 -0
  63. package/src/router/core/transition/transition.js +739 -0
  64. package/src/router/core/transition/transitionEventType.js +27 -0
  65. package/src/router/core/transition/transitionHook.js +199 -0
  66. package/src/router/core/transition/transitionService.js +311 -0
  67. package/src/router/core/url/interface.js +1 -0
  68. package/src/router/core/url/urlConfig.js +165 -0
  69. package/src/router/core/url/urlMatcher.js +548 -0
  70. package/src/router/core/url/urlMatcherFactory.js +123 -0
  71. package/src/router/core/url/urlRouter.js +115 -0
  72. package/src/router/core/url/urlRule.js +202 -0
  73. package/src/router/core/url/urlRules.js +348 -0
  74. package/src/router/core/url/urlService.js +268 -0
  75. package/src/router/core/view/interface.js +1 -0
  76. package/src/router/core/view/view.js +312 -0
  77. package/src/router/router.js +58 -0
  78. package/test/module-test.html +6 -2
  79. package/test/module-test.js +0 -0
@@ -0,0 +1,117 @@
1
+ import { defaults, find, inherit } from "../common/common";
2
+ import { propEq } from "../common/hof";
3
+ import { Glob } from "../common/glob";
4
+ import { isObject, isFunction } from "../common/predicates";
5
+ /**
6
+ * Internal representation of a UI-Router state.
7
+ *
8
+ * Instances of this class are created when a [[StateDeclaration]] is registered with the [[StateRegistry]].
9
+ *
10
+ * A registered [[StateDeclaration]] is augmented with a getter ([[StateDeclaration.$$state]]) which returns the corresponding [[StateObject]] object.
11
+ *
12
+ * This class prototypally inherits from the corresponding [[StateDeclaration]].
13
+ * Each of its own properties (i.e., `hasOwnProperty`) are built using builders from the [[StateBuilder]].
14
+ */
15
+ export class StateObject {
16
+ /**
17
+ * Create a state object to put the private/internal implementation details onto.
18
+ * The object's prototype chain looks like:
19
+ * (Internal State Object) -> (Copy of State.prototype) -> (State Declaration object) -> (State Declaration's prototype...)
20
+ *
21
+ * @param stateDecl the user-supplied State Declaration
22
+ * @returns {StateObject} an internal State object
23
+ */
24
+ static create(stateDecl) {
25
+ stateDecl = StateObject.isStateClass(stateDecl)
26
+ ? new stateDecl()
27
+ : stateDecl;
28
+ const state = inherit(inherit(stateDecl, StateObject.prototype));
29
+ stateDecl.$$state = () => state;
30
+ state.self = stateDecl;
31
+ state.__stateObjectCache = {
32
+ nameGlob: Glob.fromString(state.name), // might return null
33
+ };
34
+ return state;
35
+ }
36
+ /** @deprecated use State.create() */
37
+ constructor(config) {
38
+ return StateObject.create(config || {});
39
+ }
40
+ /**
41
+ * Returns true if the provided parameter is the same state.
42
+ *
43
+ * Compares the identity of the state against the passed value, which is either an object
44
+ * reference to the actual `State` instance, the original definition object passed to
45
+ * `$stateProvider.state()`, or the fully-qualified name.
46
+ *
47
+ * @param ref Can be one of (a) a `State` instance, (b) an object that was passed
48
+ * into `$stateProvider.state()`, (c) the fully-qualified name of a state as a string.
49
+ * @returns Returns `true` if `ref` matches the current `State` instance.
50
+ */
51
+ is(ref) {
52
+ return this === ref || this.self === ref || this.fqn() === ref;
53
+ }
54
+ /**
55
+ * @deprecated this does not properly handle dot notation
56
+ * @returns Returns a dot-separated name of the state.
57
+ */
58
+ fqn() {
59
+ if (!this.parent || !(this.parent instanceof this.constructor))
60
+ return this.name;
61
+ const name = this.parent.fqn();
62
+ return name ? name + "." + this.name : this.name;
63
+ }
64
+ /**
65
+ * Returns the root node of this state's tree.
66
+ *
67
+ * @returns The root of this state's tree.
68
+ */
69
+ root() {
70
+ return (this.parent && this.parent.root()) || this;
71
+ }
72
+ /**
73
+ * Gets the state's `Param` objects
74
+ *
75
+ * Gets the list of [[Param]] objects owned by the state.
76
+ * If `opts.inherit` is true, it also includes the ancestor states' [[Param]] objects.
77
+ * If `opts.matchingKeys` exists, returns only `Param`s whose `id` is a key on the `matchingKeys` object
78
+ *
79
+ * @param opts options
80
+ */
81
+ parameters(opts) {
82
+ opts = defaults(opts, { inherit: true, matchingKeys: null });
83
+ const inherited =
84
+ (opts.inherit && this.parent && this.parent.parameters()) || [];
85
+ return inherited
86
+ .concat(Object.values(this.params))
87
+ .filter(
88
+ (param) =>
89
+ !opts.matchingKeys ||
90
+ Object.prototype.hasOwnProperty.call(opts.matchingKeys, param.id),
91
+ );
92
+ }
93
+ /**
94
+ * Returns a single [[Param]] that is owned by the state
95
+ *
96
+ * If `opts.inherit` is true, it also searches the ancestor states` [[Param]]s.
97
+ * @param id the name of the [[Param]] to return
98
+ * @param opts options
99
+ */
100
+ parameter(id, opts = {}) {
101
+ return (
102
+ (this.url && this.url.parameter(id, opts)) ||
103
+ find(Object.values(this.params), propEq("id", id)) ||
104
+ (opts.inherit && this.parent && this.parent.parameter(id))
105
+ );
106
+ }
107
+ toString() {
108
+ return this.fqn();
109
+ }
110
+ }
111
+ /** Predicate which returns true if the object is an class with @State() decorator */
112
+ StateObject.isStateClass = (stateDecl) =>
113
+ isFunction(stateDecl) && stateDecl["__uiRouterState"] === true;
114
+ /** Predicate which returns true if the object is a [[StateDeclaration]] object */
115
+ StateObject.isStateDeclaration = (obj) => isFunction(obj["$$state"]);
116
+ /** Predicate which returns true if the object is an internal [[StateObject]] object */
117
+ StateObject.isState = (obj) => isObject(obj["__stateObjectCache"]);
@@ -0,0 +1,89 @@
1
+ import { inArray } from "../common/common";
2
+ import { prop } from "../common/hof";
3
+ import { isString } from "../common/predicates";
4
+ import { StateObject } from "./stateObject";
5
+ export class StateQueueManager {
6
+ constructor(router, states, builder, listeners) {
7
+ this.router = router;
8
+ this.states = states;
9
+ this.builder = builder;
10
+ this.listeners = listeners;
11
+ this.queue = [];
12
+ }
13
+ dispose() {
14
+ this.queue = [];
15
+ }
16
+ register(stateDecl) {
17
+ const queue = this.queue;
18
+ const state = StateObject.create(stateDecl);
19
+ const name = state.name;
20
+ if (!isString(name)) throw new Error("State must have a valid name");
21
+ if (
22
+ Object.prototype.hasOwnProperty.call(this.states, name) ||
23
+ inArray(queue.map(prop("name")), name)
24
+ )
25
+ throw new Error(`State '${name}' is already defined`);
26
+ queue.push(state);
27
+ this.flush();
28
+ return state;
29
+ }
30
+ flush() {
31
+ const { queue, states, builder } = this;
32
+ const registered = [], // states that got registered
33
+ orphans = [], // states that don't yet have a parent registered
34
+ previousQueueLength = {}; // keep track of how long the queue when an orphan was first encountered
35
+ const getState = (name) =>
36
+ this.states.hasOwnProperty(name) && this.states[name];
37
+ const notifyListeners = () => {
38
+ if (registered.length) {
39
+ this.listeners.forEach((listener) =>
40
+ listener(
41
+ "registered",
42
+ registered.map((s) => s.self),
43
+ ),
44
+ );
45
+ }
46
+ };
47
+ while (queue.length > 0) {
48
+ const state = queue.shift();
49
+ const name = state.name;
50
+ const result = builder.build(state);
51
+ const orphanIdx = orphans.indexOf(state);
52
+ if (result) {
53
+ const existingState = getState(name);
54
+ if (existingState && existingState.name === name) {
55
+ throw new Error(`State '${name}' is already defined`);
56
+ }
57
+ const existingFutureState = getState(name + ".**");
58
+ if (existingFutureState) {
59
+ // Remove future state of the same name
60
+ this.router.stateRegistry.deregister(existingFutureState);
61
+ }
62
+ states[name] = state;
63
+ this.attachRoute(state);
64
+ if (orphanIdx >= 0) orphans.splice(orphanIdx, 1);
65
+ registered.push(state);
66
+ continue;
67
+ }
68
+ const prev = previousQueueLength[name];
69
+ previousQueueLength[name] = queue.length;
70
+ if (orphanIdx >= 0 && prev === queue.length) {
71
+ // Wait until two consecutive iterations where no additional states were dequeued successfully.
72
+ // throw new Error(`Cannot register orphaned state '${name}'`);
73
+ queue.push(state);
74
+ notifyListeners();
75
+ return states;
76
+ } else if (orphanIdx < 0) {
77
+ orphans.push(state);
78
+ }
79
+ queue.push(state);
80
+ }
81
+ notifyListeners();
82
+ return states;
83
+ }
84
+ attachRoute(state) {
85
+ if (state.abstract || !state.url) return;
86
+ const rulesApi = this.router.urlService.rules;
87
+ rulesApi.rule(rulesApi.urlRuleFactory.create(state));
88
+ }
89
+ }
@@ -0,0 +1,175 @@
1
+ import { StateMatcher } from "./stateMatcher";
2
+ import { StateBuilder } from "./stateBuilder";
3
+ import { StateQueueManager } from "./stateQueueManager";
4
+ import { removeFrom } from "../common/common";
5
+ import { propEq } from "../common/hof";
6
+ /**
7
+ * A registry for all of the application's [[StateDeclaration]]s
8
+ *
9
+ * This API is found at `router.stateRegistry` ([[UIRouter.stateRegistry]])
10
+ */
11
+ export class StateRegistry {
12
+ /** @internal */
13
+ constructor(router) {
14
+ this.router = router;
15
+ this.states = {};
16
+ /** @internal */
17
+ this.listeners = [];
18
+ this.matcher = new StateMatcher(this.states);
19
+ this.builder = new StateBuilder(this.matcher, router.urlMatcherFactory);
20
+ this.stateQueue = new StateQueueManager(
21
+ router,
22
+ this.states,
23
+ this.builder,
24
+ this.listeners,
25
+ );
26
+ this._registerRoot();
27
+ }
28
+ /** @internal */
29
+ _registerRoot() {
30
+ const rootStateDef = {
31
+ name: "",
32
+ url: "^",
33
+ views: null,
34
+ params: {
35
+ "#": { value: null, type: "hash", dynamic: true },
36
+ },
37
+ abstract: true,
38
+ };
39
+ const _root = (this._root = this.stateQueue.register(rootStateDef));
40
+ _root.navigable = null;
41
+ }
42
+ /** @internal */
43
+ dispose() {
44
+ this.stateQueue.dispose();
45
+ this.listeners = [];
46
+ this.get().forEach((state) => this.get(state) && this.deregister(state));
47
+ }
48
+ /**
49
+ * Listen for a State Registry events
50
+ *
51
+ * Adds a callback that is invoked when states are registered or deregistered with the StateRegistry.
52
+ *
53
+ * #### Example:
54
+ * ```js
55
+ * let allStates = registry.get();
56
+ *
57
+ * // Later, invoke deregisterFn() to remove the listener
58
+ * let deregisterFn = registry.onStatesChanged((event, states) => {
59
+ * switch(event) {
60
+ * case: 'registered':
61
+ * states.forEach(state => allStates.push(state));
62
+ * break;
63
+ * case: 'deregistered':
64
+ * states.forEach(state => {
65
+ * let idx = allStates.indexOf(state);
66
+ * if (idx !== -1) allStates.splice(idx, 1);
67
+ * });
68
+ * break;
69
+ * }
70
+ * });
71
+ * ```
72
+ *
73
+ * @param listener a callback function invoked when the registered states changes.
74
+ * The function receives two parameters, `event` and `state`.
75
+ * See [[StateRegistryListener]]
76
+ * @return a function that deregisters the listener
77
+ */
78
+ onStatesChanged(listener) {
79
+ this.listeners.push(listener);
80
+ return function deregisterListener() {
81
+ removeFrom(this.listeners)(listener);
82
+ }.bind(this);
83
+ }
84
+ /**
85
+ * Gets the implicit root state
86
+ *
87
+ * Gets the root of the state tree.
88
+ * The root state is implicitly created by UI-Router.
89
+ * Note: this returns the internal [[StateObject]] representation, not a [[StateDeclaration]]
90
+ *
91
+ * @return the root [[StateObject]]
92
+ */
93
+ root() {
94
+ return this._root;
95
+ }
96
+ /**
97
+ * Adds a state to the registry
98
+ *
99
+ * Registers a [[StateDeclaration]] or queues it for registration.
100
+ *
101
+ * Note: a state will be queued if the state's parent isn't yet registered.
102
+ *
103
+ * @param stateDefinition the definition of the state to register.
104
+ * @returns the internal [[StateObject]] object.
105
+ * If the state was successfully registered, then the object is fully built (See: [[StateBuilder]]).
106
+ * If the state was only queued, then the object is not fully built.
107
+ */
108
+ register(stateDefinition) {
109
+ return this.stateQueue.register(stateDefinition);
110
+ }
111
+ /** @internal */
112
+ _deregisterTree(state) {
113
+ const all = this.get().map((s) => s.$$state());
114
+ const getChildren = (states) => {
115
+ const _children = all.filter((s) => states.indexOf(s.parent) !== -1);
116
+ return _children.length === 0
117
+ ? _children
118
+ : _children.concat(getChildren(_children));
119
+ };
120
+ const children = getChildren([state]);
121
+ const deregistered = [state].concat(children).reverse();
122
+ deregistered.forEach((_state) => {
123
+ const rulesApi = this.router.urlService.rules;
124
+ // Remove URL rule
125
+ rulesApi
126
+ .rules()
127
+ .filter(propEq("state", _state))
128
+ .forEach((rule) => rulesApi.removeRule(rule));
129
+ // Remove state from registry
130
+ delete this.states[_state.name];
131
+ });
132
+ return deregistered;
133
+ }
134
+ /**
135
+ * Removes a state from the registry
136
+ *
137
+ * This removes a state from the registry.
138
+ * If the state has children, they are are also removed from the registry.
139
+ *
140
+ * @param stateOrName the state's name or object representation
141
+ * @returns {StateObject[]} a list of removed states
142
+ */
143
+ deregister(stateOrName) {
144
+ const _state = this.get(stateOrName);
145
+ if (!_state)
146
+ throw new Error("Can't deregister state; not found: " + stateOrName);
147
+ const deregisteredStates = this._deregisterTree(_state.$$state());
148
+ this.listeners.forEach((listener) =>
149
+ listener(
150
+ "deregistered",
151
+ deregisteredStates.map((s) => s.self),
152
+ ),
153
+ );
154
+ return deregisteredStates;
155
+ }
156
+ get(stateOrName, base) {
157
+ if (arguments.length === 0)
158
+ return Object.keys(this.states).map((name) => this.states[name].self);
159
+ const found = this.matcher.find(stateOrName, base);
160
+ return (found && found.self) || null;
161
+ }
162
+ /**
163
+ * Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`).
164
+ * More than one BuilderFunction can be registered for a given property.
165
+ *
166
+ * The BuilderFunction(s) will be used to define the property on any subsequently built [[StateObject]] objects.
167
+ *
168
+ * @param property The name of the State property being registered for.
169
+ * @param builderFunction The BuilderFunction which will be used to build the State property
170
+ * @returns a function which deregisters the BuilderFunction
171
+ */
172
+ decorator(property, builderFunction) {
173
+ return this.builder.builder(property, builderFunction);
174
+ }
175
+ }