@angular-wave/angular.ts 0.4.6 → 0.6.0

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.
@@ -22,31 +22,37 @@ describe("ngStateRef", () => {
22
22
  window.location.hash = "";
23
23
  window.angular = new Angular();
24
24
  let module = window.angular.module("defaultModule", []);
25
- module.config(($stateProvider, $locationProvider) => {
26
- _locationProvider = $locationProvider;
27
- $locationProvider.hashPrefix("");
28
- $stateProvider
29
- .state({ name: "top", url: "" })
30
- .state({ name: "other", url: "/other/:id", template: "other" })
31
- .state({ name: "other.detail", url: "/detail", template: "detail" })
32
- .state({
33
- name: "contacts",
34
- url: "/contacts",
35
- template:
36
- '<a ng-sref=".item({ id: 5 })" class="item">Person</a> <ng-view></ng-view>',
37
- })
38
- .state({
39
- name: "contacts.item",
40
- url: "/{id:int}",
41
- template:
42
- '<a ng-sref=".detail" class="item-detail">Detail</a> | <a ng-sref="^" class="item-parent">Parent</a> | <ng-view></ng-view>',
43
- })
44
- .state({
45
- name: "contacts.item.detail",
46
- template:
47
- '<div class="title">Detail</div> | <a ng-sref="^" class="item-parent2">Item</a>',
48
- });
49
- });
25
+ module.config(
26
+ /**
27
+ * @param $stateProvider
28
+ * @param {import('../../core/location/location.js').LocationProvider} $locationProvider
29
+ */
30
+ ($stateProvider, $locationProvider) => {
31
+ _locationProvider = $locationProvider;
32
+ $locationProvider.setHashPrefix("");
33
+ $stateProvider
34
+ .state({ name: "top", url: "" })
35
+ .state({ name: "other", url: "/other/:id", template: "other" })
36
+ .state({ name: "other.detail", url: "/detail", template: "detail" })
37
+ .state({
38
+ name: "contacts",
39
+ url: "/contacts",
40
+ template:
41
+ '<a ng-sref=".item({ id: 5 })" class="item">Person</a> <ng-view></ng-view>',
42
+ })
43
+ .state({
44
+ name: "contacts.item",
45
+ url: "/{id:int}",
46
+ template:
47
+ '<a ng-sref=".detail" class="item-detail">Detail</a> | <a ng-sref="^" class="item-parent">Parent</a> | <ng-view></ng-view>',
48
+ })
49
+ .state({
50
+ name: "contacts.item.detail",
51
+ template:
52
+ '<div class="title">Detail</div> | <a ng-sref="^" class="item-parent2">Item</a>',
53
+ });
54
+ },
55
+ );
50
56
  $injector = window.angular.bootstrap(document.getElementById("dummy"), [
51
57
  "defaultModule",
52
58
  ]);
@@ -51,7 +51,7 @@ export class ParamType {
51
51
  }
52
52
  $subPattern() {
53
53
  const sub = this.pattern.toString();
54
- return sub.substr(1, sub.length - 2);
54
+ return sub.substring(1, sub.length - 2);
55
55
  }
56
56
  toString() {
57
57
  return `{ParamType:${this.name}}`;
@@ -0,0 +1,32 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>AngularTS</title>
6
+ <link rel="shortcut icon" type="image/png" href="images/favicon.ico" />
7
+ <script type="module" src="../index.js"></script>
8
+ <script>
9
+ document.addEventListener("DOMContentLoaded", () => {
10
+ window.angular.module("router", []).config([
11
+ "$stateProvider",
12
+ "$locationProvider",
13
+ ($stateProvider, $locationProvider) => {
14
+ $locationProvider.html5ModeConf = {
15
+ enabled: true,
16
+ requireBase: false,
17
+ rewriteLinks: false,
18
+ };
19
+ $stateProvider.state({
20
+ name: "home",
21
+ url: "/src/router/router-test.html",
22
+ template: "<h3>Success</h3>",
23
+ });
24
+ },
25
+ ]);
26
+ });
27
+ </script>
28
+ </head>
29
+ <body ng-app="router">
30
+ <ng-view></ng-view>
31
+ </body>
32
+ </html>
@@ -177,7 +177,7 @@ export class Ng1ViewConfig {
177
177
  ngViewName = relativeViewNameSugar[2]; // set view-name to "foo.bar"
178
178
  }
179
179
  if (ngViewName.charAt(0) === "!") {
180
- ngViewName = ngViewName.substr(1);
180
+ ngViewName = ngViewName.substring(1);
181
181
  ngViewContextAnchor = ""; // target absolutely from root
182
182
  }
183
183
  // handle parent relative targeting "^.^.^"
@@ -21,6 +21,9 @@ export class UrlService {
21
21
 
22
22
  /**
23
23
  * @param {import("../../core/location/location").LocationProvider} $locationProvider
24
+ * @param {import("../../router/state/state-service.js").StateProvider} stateService
25
+ * @param globals
26
+ * @param {import("../../router/url/url-config.js").UrlConfigProvider} urlConfigProvider
24
27
  */
25
28
  constructor($locationProvider, stateService, globals, urlConfigProvider) {
26
29
  this.stateService = stateService;
@@ -30,9 +33,6 @@ export class UrlService {
30
33
  this.$location = undefined;
31
34
  this.$browser = undefined;
32
35
 
33
- /** @type {boolean} */
34
- this.interceptDeferred = false;
35
-
36
36
  /** Provides services related to the URL */
37
37
  this.urlRuleFactory = new UrlRuleFactory(this, this.stateService, globals);
38
38
 
@@ -91,7 +91,7 @@ export class UrlService {
91
91
  * @param {import('../../core/location/location').Location} $location
92
92
  * @param {import('../../services/browser').Browser} $browser
93
93
  * @param {import('../../core/scope/scope').Scope} $rootScope
94
- * @returns
94
+ * @returns {UrlService}
95
95
  */
96
96
  ($location, $browser, $rootScope) => {
97
97
  this.$location = $location;
@@ -104,10 +104,14 @@ export class UrlService {
104
104
  },
105
105
  ];
106
106
 
107
+ /**
108
+ * @returns {boolean}
109
+ */
107
110
  html5Mode() {
108
- let html5Mode = this.$locationProvider.html5Mode();
109
- html5Mode = isObject(html5Mode) ? html5Mode.enabled : html5Mode;
110
- return html5Mode && typeof history !== "undefined";
111
+ return (
112
+ this.$locationProvider.getHtml5Mode().enabled &&
113
+ typeof history !== "undefined"
114
+ );
111
115
  }
112
116
 
113
117
  baseHref() {
@@ -214,7 +218,6 @@ export class UrlService {
214
218
  *
215
219
  * #### Example:
216
220
  * ```js
217
- * urlService.deferIntercept();
218
221
  *
219
222
  * fetch('/states.json').then(resp => resp.json()).then(data => {
220
223
  * data.forEach(state => $stateRegistry.register(state));
@@ -261,7 +264,6 @@ export class UrlService {
261
264
  *
262
265
  * #### Example:
263
266
  * ```js
264
- * urlService.deferIntercept();
265
267
  *
266
268
  * fetch('/states.json').then(resp => resp.json()).then(data => {
267
269
  * data.forEach(state => $stateRegistry.register(state));
@@ -282,34 +284,7 @@ export class UrlService {
282
284
  this._stopListeningFn || this.onChange((evt) => this.sync(evt)));
283
285
  }
284
286
  }
285
- /**
286
- * Disables monitoring of the URL.
287
- *
288
- * Call this method before ng-router has bootstrapped.
289
- * It will stop ng-router from performing the initial url sync.
290
- *
291
- * This can be useful to perform some asynchronous initialization before the router starts.
292
- * Once the initialization is complete, call [[listen]] to tell ng-router to start watching and synchronizing the URL.
293
- *
294
- * #### Example:
295
- * ```js
296
- * // Prevent ng-router from automatically intercepting URL changes when it starts;
297
- * urlService.deferIntercept();
298
- *
299
- * fetch('/states.json').then(resp => resp.json()).then(data => {
300
- * data.forEach(state => $stateRegistry.register(state));
301
- * urlService.listen();
302
- * urlService.sync();
303
- * });
304
- * ```
305
- *
306
- * @param defer Indicates whether to defer location change interception.
307
- * Passing no parameter is equivalent to `true`.
308
- */
309
- deferIntercept(defer) {
310
- if (defer === undefined) defer = true;
311
- this.interceptDeferred = defer;
312
- }
287
+
313
288
  /**
314
289
  * Matches a URL
315
290
  *
@@ -394,7 +369,7 @@ export class UrlService {
394
369
  options = options || { absolute: false };
395
370
  const isHtml5 = this.html5Mode();
396
371
  if (!isHtml5 && url !== null) {
397
- url = "#" + this.$locationProvider.hashPrefix() + url;
372
+ url = "#" + this.$locationProvider.getHashPrefix() + url;
398
373
  }
399
374
  url = appendBasePath(url, isHtml5, options.absolute, this.baseHref());
400
375
  if (!options.absolute || !url) {
@@ -20,7 +20,7 @@ import { pattern, val } from "./hof";
20
20
  */
21
21
  export function maxLength(max, str) {
22
22
  if (str.length <= max) return str;
23
- return str.substr(0, max - 3) + "...";
23
+ return str.substring(0, max - 3) + "...";
24
24
  }
25
25
  /**
26
26
  * Returns a string, with spaces added to the end, up to a desired str length
@@ -46,7 +46,7 @@ export function functionToString(fn) {
46
46
  const toStr = namedFunctionMatch ? namedFunctionMatch[1] : fnStr;
47
47
  const fnName = fn["name"] || "";
48
48
  if (fnName && toStr.match(/function \(/)) {
49
- return "function " + fnName + toStr.substr(9);
49
+ return "function " + fnName + toStr.substring(9);
50
50
  }
51
51
  return toStr;
52
52
  }
@@ -97,7 +97,7 @@ export const beforeAfterSubstr = (char) => (str) => {
97
97
  if (!str) return ["", ""];
98
98
  const idx = str.indexOf(char);
99
99
  if (idx === -1) return [str, ""];
100
- return [str.substr(0, idx), str.substr(idx + 1)];
100
+ return [str.substring(0, idx), str.substring(idx + 1)];
101
101
  };
102
102
  export const hostRegex = new RegExp("^(?:[a-z]+:)?//[^/]+/");
103
103
  export const stripLastPathElement = (str) => str.replace(/\/[^/]*$/, "");
@@ -244,39 +244,33 @@ export class LocationHashbangUrl extends Location {
244
244
  $$parseLinkUrl(url: string): boolean;
245
245
  }
246
246
  export class LocationProvider {
247
- hashPrefixValue: string;
248
- html5ModeConfig: {
249
- enabled: boolean;
250
- requireBase: boolean;
251
- rewriteLinks: boolean;
252
- };
247
+ /** @type {string} */
248
+ hashPrefixConf: string;
249
+ /** @type {Html5Mode} */
250
+ html5ModeConf: Html5Mode;
253
251
  /**
254
252
  * The default value for the prefix is `'!'`.
255
- * @param {string=} prefix - Prefix for hash part (containing path and search)
256
- * @returns {string|LocationProvider} current value if used as getter or itself (chaining) if used as setter
257
- */
258
- hashPrefix(prefix?: string | undefined): string | LocationProvider;
259
- /**
260
- * @param {(boolean|Object)=} mode If boolean, sets `html5Mode.enabled` to value.
261
- * If object, sets `enabled`, `requireBase` and `rewriteLinks` to respective values. Supported
262
- * properties:
263
- * - **enabled** – `{boolean}` – (default: false) If true, will rely on `history.pushState` to
264
- * change urls where supported. Will fall back to hash-prefixed paths in browsers that do not
265
- * support `pushState`.
266
- * - **requireBase** - `{boolean}` - (default: `true`) When html5Mode is enabled, specifies
267
- * whether or not a <base> tag is required to be present. If `enabled` and `requireBase` are
268
- * true, and a base tag is not present, an error will be thrown when `$location` is injected.
269
- * See the {@link guide/$location $location guide for more information}
270
- * - **rewriteLinks** - `{boolean|string}` - (default: `true`) When html5Mode is enabled,
271
- * enables/disables URL rewriting for relative links. If set to a string, URL rewriting will
272
- * only happen on links with an attribute that matches the given string. For example, if set
273
- * to `'internal-link'`, then the URL will only be rewritten for `<a internal-link>` links.
274
- * Note that [attribute name normalization](guide/directive#normalization) does not apply
275
- * here, so `'internalLink'` will **not** match `'internal-link'`.
253
+ * @param {string=} prefix Prefix for hash part (containing path and search)
254
+ * @returns {void}
255
+ */
256
+ setHashPrefix(prefix?: string | undefined): void;
257
+ /**
258
+ * Current hash prefix
259
+ * @returns {string}
260
+ */
261
+ getHashPrefix(): string;
262
+ /**
263
+ * Configures html5 mode
264
+ * @param {(boolean|Html5Mode)=} mode If boolean, sets `html5Mode.enabled` to value. Otherwise, accepts html5Mode object
276
265
  *
277
- * @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter
266
+ * @returns {void}
267
+ */
268
+ setHtml5Mode(mode?: (boolean | Html5Mode) | undefined): void;
269
+ /**
270
+ * Returns html5 mode cofiguration
271
+ * @returns {Html5Mode}
278
272
  */
279
- html5Mode(mode?: (boolean | any) | undefined): any;
273
+ getHtml5Mode(): Html5Mode;
280
274
  $get: (string | (($rootScope: import("../scope/scope").Scope, $browser: import("../../services/browser").Browser, $rootElement: JQLite) => Location))[];
281
275
  }
282
276
  export type DefaultPorts = {
@@ -284,9 +278,30 @@ export type DefaultPorts = {
284
278
  https: number;
285
279
  ftp: number;
286
280
  };
281
+ /**
282
+ * Represents the configuration options for HTML5 mode.
283
+ */
287
284
  export type Html5Mode = {
285
+ /**
286
+ * - (default: false) If true, will rely on `history.pushState` to
287
+ * change URLs where supported. Falls back to hash-prefixed paths in browsers that do not
288
+ * support `pushState`.
289
+ */
288
290
  enabled: boolean;
291
+ /**
292
+ * - (default: `true`) When html5Mode is enabled, specifies
293
+ * whether or not a `<base>` tag is required to be present. If both `enabled` and `requireBase`
294
+ * are true, and a `<base>` tag is not present, an error will be thrown when `$location` is injected.
295
+ * See the {@link guide /$location $location guide} for more information.
296
+ */
289
297
  requireBase: boolean;
298
+ /**
299
+ * - (default: `true`) When html5Mode is enabled, enables or
300
+ * disables URL rewriting for relative links. If set to a string, URL rewriting will only apply to links
301
+ * with an attribute that matches the given string. For example, if set to `'internal-link'`, URL rewriting
302
+ * will only occur for `<a internal-link>` links. Note that [attribute name normalization](guide/directive#normalization)
303
+ * does not apply here, so `'internalLink'` will **not** match `'internal-link'`.
304
+ */
290
305
  rewriteLinks: boolean | string;
291
306
  };
292
307
  import { JQLite } from "../../shared/jqlite/jqlite";
@@ -1,4 +1,6 @@
1
1
  /**
2
- * @returns {import("../../types").Directive}
2
+ * @param {string} source - the name of the attribute to be observed
3
+ * @param {string} prop - the scope property to be updated with attribute value
4
+ * @returns {import("../../types.js").Directive}
3
5
  */
4
- export function ngObserveDirective(): import("../../types").Directive;
6
+ export function ngObserveDirective(source: string, prop: string): import("../../types.js").Directive;
@@ -5,14 +5,15 @@ export class UrlService {
5
5
  static $inject: string[];
6
6
  /**
7
7
  * @param {import("../../core/location/location").LocationProvider} $locationProvider
8
+ * @param {import("../../router/state/state-service.js").StateProvider} stateService
9
+ * @param globals
10
+ * @param {import("../../router/url/url-config.js").UrlConfigProvider} urlConfigProvider
8
11
  */
9
- constructor($locationProvider: import("../../core/location/location").LocationProvider, stateService: any, globals: any, urlConfigProvider: any);
10
- stateService: any;
12
+ constructor($locationProvider: import("../../core/location/location").LocationProvider, stateService: import("../../router/state/state-service.js").StateProvider, globals: any, urlConfigProvider: import("../../router/url/url-config.js").UrlConfigProvider);
13
+ stateService: import("../../router/state/state-service.js").StateProvider;
11
14
  $locationProvider: import("../../core/location/location").LocationProvider;
12
15
  $location: import("../../core/location/location").Location;
13
16
  $browser: import("../../services/browser").Browser;
14
- /** @type {boolean} */
15
- interceptDeferred: boolean;
16
17
  /** Provides services related to the URL */
17
18
  urlRuleFactory: UrlRuleFactory;
18
19
  /**
@@ -56,7 +57,10 @@ export class UrlService {
56
57
  */
57
58
  hash: () => string | import("../../core/location/location").Location;
58
59
  _urlListeners: any[];
59
- $get: (string | (($location: import("../../core/location/location").Location, $browser: import("../../services/browser").Browser, $rootScope: import("../../core/scope/scope").Scope) => this))[];
60
+ $get: (string | (($location: import("../../core/location/location").Location, $browser: import("../../services/browser").Browser, $rootScope: import("../../core/scope/scope").Scope) => UrlService))[];
61
+ /**
62
+ * @returns {boolean}
63
+ */
60
64
  html5Mode(): boolean;
61
65
  baseHref(): string;
62
66
  _baseHref: string;
@@ -149,7 +153,6 @@ export class UrlService {
149
153
  *
150
154
  * #### Example:
151
155
  * ```js
152
- * urlService.deferIntercept();
153
156
  *
154
157
  * fetch('/states.json').then(resp => resp.json()).then(data => {
155
158
  * data.forEach(state => $stateRegistry.register(state));
@@ -170,7 +173,6 @@ export class UrlService {
170
173
  *
171
174
  * #### Example:
172
175
  * ```js
173
- * urlService.deferIntercept();
174
176
  *
175
177
  * fetch('/states.json').then(resp => resp.json()).then(data => {
176
178
  * data.forEach(state => $stateRegistry.register(state));
@@ -184,31 +186,6 @@ export class UrlService {
184
186
  */
185
187
  listen(enabled: any): any;
186
188
  _stopListeningFn: any;
187
- /**
188
- * Disables monitoring of the URL.
189
- *
190
- * Call this method before ng-router has bootstrapped.
191
- * It will stop ng-router from performing the initial url sync.
192
- *
193
- * This can be useful to perform some asynchronous initialization before the router starts.
194
- * Once the initialization is complete, call [[listen]] to tell ng-router to start watching and synchronizing the URL.
195
- *
196
- * #### Example:
197
- * ```js
198
- * // Prevent ng-router from automatically intercepting URL changes when it starts;
199
- * urlService.deferIntercept();
200
- *
201
- * fetch('/states.json').then(resp => resp.json()).then(data => {
202
- * data.forEach(state => $stateRegistry.register(state));
203
- * urlService.listen();
204
- * urlService.sync();
205
- * });
206
- * ```
207
- *
208
- * @param defer Indicates whether to defer location change interception.
209
- * Passing no parameter is equivalent to `true`.
210
- */
211
- deferIntercept(defer: any): void;
212
189
  /**
213
190
  * Matches a URL
214
191
  *
@@ -1,98 +0,0 @@
1
- import { Angular } from "../loader";
2
- import { createInjector } from "./di/injector";
3
-
4
- describe("$$cookieReader", () => {
5
- let $$cookieReader;
6
- let document;
7
-
8
- describe("with access to `document.cookie`", () => {
9
- function deleteAllCookies() {
10
- const cookies = document.cookie.split(";");
11
- const path = window.location.pathname;
12
-
13
- for (let i = 0; i < cookies.length; i++) {
14
- const cookie = cookies[i];
15
- const eqPos = cookie.indexOf("=");
16
- const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
17
- const parts = path.split("/");
18
- while (parts.length) {
19
- document.cookie = `${name}=;path=${parts.join("/") || "/"};expires=Thu, 01 Jan 1970 00:00:00 GMT`;
20
- parts.pop();
21
- }
22
- }
23
- }
24
-
25
- beforeEach(() => {
26
- document = window.document;
27
- deleteAllCookies();
28
- expect(document.cookie).toEqual("");
29
-
30
- window.angular = new Angular();
31
- const injector = createInjector(["ng"]);
32
- $$cookieReader = injector.get("$$cookieReader");
33
- });
34
-
35
- afterEach(() => {
36
- deleteAllCookies();
37
- expect(document.cookie).toEqual("");
38
- });
39
-
40
- describe("get via $$cookieReader()[cookieName]", () => {
41
- it("should return undefined for nonexistent cookie", () => {
42
- expect($$cookieReader().nonexistent).not.toBeDefined();
43
- });
44
-
45
- it("should return a value for an existing cookie", () => {
46
- document.cookie = "foo=bar=baz;path=/";
47
- expect($$cookieReader().foo).toEqual("bar=baz");
48
- });
49
-
50
- it("should return the the first value provided for a cookie", () => {
51
- // For a cookie that has different values that differ by path, the
52
- // value for the most specific path appears first. $$cookieReader()
53
- // should provide that value for the cookie.
54
- document.cookie = 'foo="first"; foo="second"';
55
- expect($$cookieReader().foo).toBe('"first"');
56
- });
57
-
58
- it("should decode cookie values that were encoded by puts", () => {
59
- document.cookie = "cookie2%3Dbar%3Bbaz=val%3Due;path=/";
60
- expect($$cookieReader()["cookie2=bar;baz"]).toEqual("val=ue");
61
- });
62
-
63
- it("should preserve leading & trailing spaces in names and values", () => {
64
- document.cookie = "%20cookie%20name%20=%20cookie%20value%20";
65
- expect($$cookieReader()[" cookie name "]).toEqual(" cookie value ");
66
- expect($$cookieReader()["cookie name"]).not.toBeDefined();
67
- });
68
-
69
- it("should decode special characters in cookie values", () => {
70
- document.cookie = "cookie_name=cookie_value_%E2%82%AC";
71
- expect($$cookieReader().cookie_name).toEqual("cookie_value_€");
72
- });
73
-
74
- it("should not decode cookie values that do not appear to be encoded", () => {
75
- // see #9211 - sometimes cookies contain a value that causes decodeURIComponent to throw
76
- document.cookie = "cookie_name=cookie_value_%XX";
77
- expect($$cookieReader().cookie_name).toEqual("cookie_value_%XX");
78
- });
79
- });
80
-
81
- describe("getAll via $$cookieReader()", () => {
82
- it("should return cookies as hash", () => {
83
- document.cookie = "foo1=bar1;path=/";
84
- document.cookie = "foo2=bar2;path=/";
85
- expect($$cookieReader()).toEqual({ foo1: "bar1", foo2: "bar2" });
86
- });
87
-
88
- it("should return empty hash if no cookies exist", () => {
89
- expect($$cookieReader()).toEqual({});
90
- });
91
- });
92
-
93
- it("should initialize cookie cache with existing cookies", () => {
94
- document.cookie = "existingCookie=existingValue;path=/";
95
- expect($$cookieReader()).toEqual({ existingCookie: "existingValue" });
96
- });
97
- });
98
- });