@angular-wave/angular.ts 0.5.0 → 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.
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/core/compile/compile.js +10 -1
- package/src/core/core.html +0 -1
- package/src/core/location/location.js +75 -67
- package/src/core/location/location.spec.js +15 -15
- package/src/core/prop.spec.js +1 -1
- package/src/directive/observe/observe.js +8 -7
- package/src/directive/observe/observe.spec.js +3 -5
- package/src/directive/observe/test.html +4 -8
- package/src/loader.js +2 -2
- package/src/public.js +0 -2
- package/src/router/directives/state-directives.spec.js +31 -25
- package/src/router/router-test.html +32 -0
- package/src/router/url/url-service.js +13 -38
- package/types/core/location/location.d.ts +44 -29
- package/types/directive/observe/observe.d.ts +4 -2
- package/types/router/url/url-service.d.ts +9 -32
- package/src/core/cookie-reader.spec.js +0 -98
|
@@ -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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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.
|
|
372
|
+
url = "#" + this.$locationProvider.getHashPrefix() + url;
|
|
398
373
|
}
|
|
399
374
|
url = appendBasePath(url, isHtml5, options.absolute, this.baseHref());
|
|
400
375
|
if (!options.absolute || !url) {
|
|
@@ -244,39 +244,33 @@ export class LocationHashbangUrl extends Location {
|
|
|
244
244
|
$$parseLinkUrl(url: string): boolean;
|
|
245
245
|
}
|
|
246
246
|
export class LocationProvider {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
|
256
|
-
* @returns {
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
*
|
|
266
|
-
*
|
|
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 {
|
|
266
|
+
* @returns {void}
|
|
267
|
+
*/
|
|
268
|
+
setHtml5Mode(mode?: (boolean | Html5Mode) | undefined): void;
|
|
269
|
+
/**
|
|
270
|
+
* Returns html5 mode cofiguration
|
|
271
|
+
* @returns {Html5Mode}
|
|
278
272
|
*/
|
|
279
|
-
|
|
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
|
-
* @
|
|
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:
|
|
10
|
-
stateService:
|
|
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) =>
|
|
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.substring(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
|
-
});
|