@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
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@angular-wave/angular.ts",
|
|
3
3
|
"description": "A modern, optimized and typesafe version of AngularJS",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.6.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/angular-ts.esm.js",
|
|
8
8
|
"browser": "dist/angular-ts.umd.js",
|
|
@@ -37,6 +37,7 @@ import { PREFIX_REGEXP } from "../../shared/constants";
|
|
|
37
37
|
import { createEventDirective } from "../../directive/events/events";
|
|
38
38
|
import { CACHE, EXPANDO } from "../cache/cache";
|
|
39
39
|
import { Attributes } from "./attributes";
|
|
40
|
+
import { ngObserveDirective } from "../../directive/observe/observe";
|
|
40
41
|
|
|
41
42
|
let ttl = TTL;
|
|
42
43
|
|
|
@@ -586,7 +587,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
586
587
|
? (x) => x
|
|
587
588
|
: (x) => x.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
|
|
588
589
|
|
|
589
|
-
const NG_PREFIX_BINDING = /^ng(Attr|Prop|On)([A-Z].*)$/;
|
|
590
|
+
const NG_PREFIX_BINDING = /^ng(Attr|Prop|On|Observe)([A-Z].*)$/;
|
|
590
591
|
const MULTI_ELEMENT_DIR_RE = /^(.+)Start$/;
|
|
591
592
|
return compile;
|
|
592
593
|
|
|
@@ -992,6 +993,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
992
993
|
let isNgAttr = false;
|
|
993
994
|
let isNgProp = false;
|
|
994
995
|
let isNgEvent = false;
|
|
996
|
+
let isNgObserve = false;
|
|
995
997
|
let multiElementMatch;
|
|
996
998
|
|
|
997
999
|
attr = nAttrs[j];
|
|
@@ -1005,6 +1007,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1005
1007
|
isNgAttr = ngPrefixMatch[1] === "Attr";
|
|
1006
1008
|
isNgProp = ngPrefixMatch[1] === "Prop";
|
|
1007
1009
|
isNgEvent = ngPrefixMatch[1] === "On";
|
|
1010
|
+
isNgObserve = ngPrefixMatch[1] === "Observe";
|
|
1008
1011
|
|
|
1009
1012
|
// Normalize the non-prefixed name
|
|
1010
1013
|
name = name
|
|
@@ -1032,6 +1035,8 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1032
1035
|
} else {
|
|
1033
1036
|
addEventDirective(directives, nName, name);
|
|
1034
1037
|
}
|
|
1038
|
+
} else if (isNgObserve) {
|
|
1039
|
+
addObserveDirective(directives, name, value);
|
|
1035
1040
|
} else {
|
|
1036
1041
|
// Update nName for cases where a prefix was removed
|
|
1037
1042
|
// NOTE: the .toLowerCase() is unnecessary and causes https://github.com/angular/angular.js/issues/16624 for ng-attr-*
|
|
@@ -2651,6 +2656,10 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2651
2656
|
);
|
|
2652
2657
|
}
|
|
2653
2658
|
|
|
2659
|
+
function addObserveDirective(directives, source, prop) {
|
|
2660
|
+
directives.push(ngObserveDirective(source, prop));
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2654
2663
|
function addAttrInterpolateDirective(
|
|
2655
2664
|
node,
|
|
2656
2665
|
directives,
|
package/src/core/core.html
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
<script src="/jasmine/jasmine-5.1.2/jasmine-html.js"></script>
|
|
11
11
|
<script src="/jasmine/jasmine-5.1.2/boot0.js"></script>
|
|
12
12
|
<script src="/jasmine/jasmine-5.1.2/boot1.js"></script>
|
|
13
|
-
<script type="module" src="/src/core/cookie-reader.spec.js"></script>
|
|
14
13
|
<script type="module" src="/src/core/on.spec.js"></script>
|
|
15
14
|
<script type="module" src="/src/core/prop.spec.js"></script>
|
|
16
15
|
<script type="module" src="/src/core/root-element.spec.js"></script>
|
|
@@ -23,10 +23,21 @@ import { ScopePhase } from "../scope/scope";
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
+
* Represents the configuration options for HTML5 mode.
|
|
27
|
+
*
|
|
26
28
|
* @typedef {Object} Html5Mode
|
|
27
|
-
* @property {boolean} enabled
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* @property {boolean} enabled - (default: false) If true, will rely on `history.pushState` to
|
|
30
|
+
* change URLs where supported. Falls back to hash-prefixed paths in browsers that do not
|
|
31
|
+
* support `pushState`.
|
|
32
|
+
* @property {boolean} requireBase - (default: `true`) When html5Mode is enabled, specifies
|
|
33
|
+
* whether or not a `<base>` tag is required to be present. If both `enabled` and `requireBase`
|
|
34
|
+
* are true, and a `<base>` tag is not present, an error will be thrown when `$location` is injected.
|
|
35
|
+
* See the {@link guide/$location $location guide} for more information.
|
|
36
|
+
* @property {boolean|string} rewriteLinks - (default: `true`) When html5Mode is enabled, enables or
|
|
37
|
+
* disables URL rewriting for relative links. If set to a string, URL rewriting will only apply to links
|
|
38
|
+
* with an attribute that matches the given string. For example, if set to `'internal-link'`, URL rewriting
|
|
39
|
+
* will only occur for `<a internal-link>` links. Note that [attribute name normalization](guide/directive#normalization)
|
|
40
|
+
* does not apply here, so `'internalLink'` will **not** match `'internal-link'`.
|
|
30
41
|
*/
|
|
31
42
|
|
|
32
43
|
/** @type {DefaultPorts} */
|
|
@@ -542,71 +553,77 @@ export class LocationHashbangUrl extends Location {
|
|
|
542
553
|
}
|
|
543
554
|
}
|
|
544
555
|
|
|
545
|
-
export
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
556
|
+
export class LocationProvider {
|
|
557
|
+
constructor() {
|
|
558
|
+
/** @type {string} */
|
|
559
|
+
this.hashPrefixConf = "!";
|
|
560
|
+
|
|
561
|
+
/** @type {Html5Mode} */
|
|
562
|
+
this.html5ModeConf = {
|
|
563
|
+
enabled: false,
|
|
564
|
+
requireBase: true,
|
|
565
|
+
rewriteLinks: true,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
552
568
|
|
|
553
569
|
/**
|
|
554
570
|
* The default value for the prefix is `'!'`.
|
|
555
571
|
* @param {string=} prefix Prefix for hash part (containing path and search)
|
|
556
|
-
* @returns {
|
|
572
|
+
* @returns {void}
|
|
557
573
|
*/
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
574
|
+
setHashPrefix(prefix) {
|
|
575
|
+
this.hashPrefixConf = prefix;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Current hash prefix
|
|
580
|
+
* @returns {string}
|
|
581
|
+
*/
|
|
582
|
+
getHashPrefix() {
|
|
583
|
+
return this.hashPrefixConf;
|
|
584
|
+
}
|
|
565
585
|
|
|
566
586
|
/**
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* properties:
|
|
570
|
-
* - **enabled** – `{boolean}` – (default: false) If true, will rely on `history.pushState` to
|
|
571
|
-
* change urls where supported. Will fall back to hash-prefixed paths in browsers that do not
|
|
572
|
-
* support `pushState`.
|
|
573
|
-
* - **requireBase** - `{boolean}` - (default: `true`) When html5Mode is enabled, specifies
|
|
574
|
-
* whether or not a <base> tag is required to be present. If `enabled` and `requireBase` are
|
|
575
|
-
* true, and a base tag is not present, an error will be thrown when `$location` is injected.
|
|
576
|
-
* See the {@link guide/$location $location guide for more information}
|
|
577
|
-
* - **rewriteLinks** - `{boolean|string}` - (default: `true`) When html5Mode is enabled,
|
|
578
|
-
* enables/disables URL rewriting for relative links. If set to a string, URL rewriting will
|
|
579
|
-
* only happen on links with an attribute that matches the given string. For example, if set
|
|
580
|
-
* to `'internal-link'`, then the URL will only be rewritten for `<a internal-link>` links.
|
|
581
|
-
* Note that [attribute name normalization](guide/directive#normalization) does not apply
|
|
582
|
-
* here, so `'internalLink'` will **not** match `'internal-link'`.
|
|
587
|
+
* Configures html5 mode
|
|
588
|
+
* @param {(boolean|Html5Mode)=} mode If boolean, sets `html5Mode.enabled` to value. Otherwise, accepts html5Mode object
|
|
583
589
|
*
|
|
584
|
-
* @returns {
|
|
590
|
+
* @returns {void}
|
|
585
591
|
*/
|
|
586
|
-
|
|
592
|
+
setHtml5Mode(mode) {
|
|
587
593
|
if (isBoolean(mode)) {
|
|
588
|
-
|
|
589
|
-
return this;
|
|
594
|
+
this.html5ModeConf.enabled = /** @type {boolean} */ (mode);
|
|
590
595
|
}
|
|
591
596
|
if (isObject(mode)) {
|
|
592
|
-
|
|
593
|
-
|
|
597
|
+
const html5Mode = /** @type {Html5Mode} */ (mode);
|
|
598
|
+
if (isDefined(html5Mode.enabled) && isBoolean(html5Mode.enabled)) {
|
|
599
|
+
this.html5ModeConf.enabled = html5Mode.enabled;
|
|
594
600
|
}
|
|
595
601
|
|
|
596
|
-
if (
|
|
597
|
-
html5Mode.requireBase
|
|
602
|
+
if (
|
|
603
|
+
isDefined(html5Mode.requireBase) &&
|
|
604
|
+
isBoolean(html5Mode.requireBase)
|
|
605
|
+
) {
|
|
606
|
+
this.html5ModeConf.requireBase = html5Mode.requireBase;
|
|
598
607
|
}
|
|
599
608
|
|
|
600
|
-
if (
|
|
601
|
-
html5Mode.rewriteLinks
|
|
609
|
+
if (
|
|
610
|
+
isDefined(html5Mode.rewriteLinks) &&
|
|
611
|
+
(isBoolean(html5Mode.rewriteLinks) || isString(html5Mode.rewriteLinks))
|
|
612
|
+
) {
|
|
613
|
+
this.html5ModeConf.rewriteLinks = html5Mode.rewriteLinks;
|
|
602
614
|
}
|
|
603
|
-
|
|
604
|
-
return this;
|
|
605
615
|
}
|
|
606
|
-
|
|
607
|
-
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Returns html5 mode cofiguration
|
|
620
|
+
* @returns {Html5Mode}
|
|
621
|
+
*/
|
|
622
|
+
getHtml5Mode() {
|
|
623
|
+
return this.html5ModeConf;
|
|
624
|
+
}
|
|
608
625
|
|
|
609
|
-
|
|
626
|
+
$get = [
|
|
610
627
|
"$rootScope",
|
|
611
628
|
"$browser",
|
|
612
629
|
"$rootElement",
|
|
@@ -617,7 +634,7 @@ export function LocationProvider() {
|
|
|
617
634
|
* @param {JQLite} $rootElement
|
|
618
635
|
* @returns
|
|
619
636
|
*/
|
|
620
|
-
|
|
637
|
+
($rootScope, $browser, $rootElement) => {
|
|
621
638
|
/** @type {Location} */
|
|
622
639
|
let $location;
|
|
623
640
|
let LocationMode;
|
|
@@ -625,8 +642,8 @@ export function LocationProvider() {
|
|
|
625
642
|
const initialUrl = /** @type {string} */ ($browser.url());
|
|
626
643
|
let appBase;
|
|
627
644
|
|
|
628
|
-
if (
|
|
629
|
-
if (!baseHref &&
|
|
645
|
+
if (this.getHtml5Mode().enabled) {
|
|
646
|
+
if (!baseHref && this.getHtml5Mode().requireBase) {
|
|
630
647
|
throw $locationMinErr(
|
|
631
648
|
"nobase",
|
|
632
649
|
"$location in HTML5 mode requires a <base> tag to be present!",
|
|
@@ -640,7 +657,11 @@ export function LocationProvider() {
|
|
|
640
657
|
}
|
|
641
658
|
const appBaseNoFile = stripFile(appBase);
|
|
642
659
|
|
|
643
|
-
$location = new LocationMode(
|
|
660
|
+
$location = new LocationMode(
|
|
661
|
+
appBase,
|
|
662
|
+
appBaseNoFile,
|
|
663
|
+
`#${this.getHashPrefix()}`,
|
|
664
|
+
);
|
|
644
665
|
$location.$$parseLinkUrl(initialUrl, initialUrl);
|
|
645
666
|
|
|
646
667
|
$location.$$state = $browser.state();
|
|
@@ -667,7 +688,7 @@ export function LocationProvider() {
|
|
|
667
688
|
}
|
|
668
689
|
|
|
669
690
|
$rootElement.on("click", (event) => {
|
|
670
|
-
const
|
|
691
|
+
const rewriteLinks = this.getHtml5Mode().rewriteLinks;
|
|
671
692
|
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
|
|
672
693
|
// currently we open nice url link and redirect then
|
|
673
694
|
|
|
@@ -882,19 +903,6 @@ function normalizePath(pathValue, searchValue, hashValue) {
|
|
|
882
903
|
return path + (search ? `?${search}` : "") + hash;
|
|
883
904
|
}
|
|
884
905
|
|
|
885
|
-
/**
|
|
886
|
-
* @param {string} absoluteUrl
|
|
887
|
-
* @param {Location} locationObj
|
|
888
|
-
*/
|
|
889
|
-
function parseAbsoluteUrl(absoluteUrl, locationObj) {
|
|
890
|
-
const parsedUrl = urlResolve(absoluteUrl);
|
|
891
|
-
|
|
892
|
-
locationObj.$$protocol = parsedUrl.protocol;
|
|
893
|
-
locationObj.$$host = parsedUrl.hostname;
|
|
894
|
-
locationObj.$$port =
|
|
895
|
-
toInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
906
|
function parseAppUrl(url, locationObj, html5Mode) {
|
|
899
907
|
if (/^\s*[\\/]{2,}/.test(url)) {
|
|
900
908
|
throw $locationMinErr("badpath", 'Invalid url "{0}".', url);
|
|
@@ -15,7 +15,7 @@ describe("$location", () => {
|
|
|
15
15
|
|
|
16
16
|
// function initService(options) {
|
|
17
17
|
// module.config(($provide, $locationProvider) => {
|
|
18
|
-
// $locationProvider.
|
|
18
|
+
// $locationProvider.setHtml5Mode(options.html5Mode);
|
|
19
19
|
// $locationProvider.hashPrefix(options.hashPrefix);
|
|
20
20
|
// $provide.value("$sniffer", { history: options.supportHistory });
|
|
21
21
|
// });
|
|
@@ -24,12 +24,12 @@ describe("$location", () => {
|
|
|
24
24
|
describe("defaults", () => {
|
|
25
25
|
it('should have hashPrefix of "!"', () => {
|
|
26
26
|
let provider = new LocationProvider();
|
|
27
|
-
expect(provider.
|
|
27
|
+
expect(provider.getHashPrefix()).toBe("!");
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
it("should not be html5 mode", () => {
|
|
31
31
|
let provider = new LocationProvider();
|
|
32
|
-
expect(provider.
|
|
32
|
+
expect(provider.getHtml5Mode().enabled).toBeFalse();
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -2947,7 +2947,7 @@ describe("$location", () => {
|
|
|
2947
2947
|
|
|
2948
2948
|
// it("should listen on click events on href and prevent browser default in html5 mode", () => {
|
|
2949
2949
|
// module(($locationProvider, $provide) => {
|
|
2950
|
-
// $locationProvider.
|
|
2950
|
+
// $locationProvider.setHtml5Mode(true);
|
|
2951
2951
|
// return function ($rootElement, $compile, $rootScope) {
|
|
2952
2952
|
// $rootElement.html('<a href="http://server/somePath">link</a>');
|
|
2953
2953
|
// $compile($rootElement)($rootScope);
|
|
@@ -3011,12 +3011,12 @@ describe("$location", () => {
|
|
|
3011
3011
|
describe("html5Mode", () => {
|
|
3012
3012
|
it("should set enabled, requireBase and rewriteLinks when called with object", () => {
|
|
3013
3013
|
module.config(($locationProvider) => {
|
|
3014
|
-
$locationProvider.
|
|
3014
|
+
$locationProvider.setHtml5Mode({
|
|
3015
3015
|
enabled: true,
|
|
3016
3016
|
requireBase: false,
|
|
3017
3017
|
rewriteLinks: false,
|
|
3018
3018
|
});
|
|
3019
|
-
expect($locationProvider.
|
|
3019
|
+
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3020
3020
|
enabled: true,
|
|
3021
3021
|
requireBase: false,
|
|
3022
3022
|
rewriteLinks: false,
|
|
@@ -3027,13 +3027,13 @@ describe("$location", () => {
|
|
|
3027
3027
|
|
|
3028
3028
|
it("should only overwrite existing properties if values are of the correct type", () => {
|
|
3029
3029
|
module.config(($locationProvider) => {
|
|
3030
|
-
$locationProvider.
|
|
3030
|
+
$locationProvider.setHtml5Mode({
|
|
3031
3031
|
enabled: "duh",
|
|
3032
3032
|
requireBase: "probably",
|
|
3033
3033
|
rewriteLinks: 0,
|
|
3034
3034
|
});
|
|
3035
3035
|
|
|
3036
|
-
expect($locationProvider.
|
|
3036
|
+
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3037
3037
|
enabled: false,
|
|
3038
3038
|
requireBase: true,
|
|
3039
3039
|
rewriteLinks: true,
|
|
@@ -3045,11 +3045,11 @@ describe("$location", () => {
|
|
|
3045
3045
|
|
|
3046
3046
|
it("should support setting rewriteLinks to a string", () => {
|
|
3047
3047
|
module.config(($locationProvider) => {
|
|
3048
|
-
$locationProvider.
|
|
3048
|
+
$locationProvider.setHtml5Mode({
|
|
3049
3049
|
rewriteLinks: "yes-rewrite",
|
|
3050
3050
|
});
|
|
3051
3051
|
|
|
3052
|
-
expect($locationProvider.
|
|
3052
|
+
expect($locationProvider.getHtml5Mode().rewriteLinks).toEqual(
|
|
3053
3053
|
"yes-rewrite",
|
|
3054
3054
|
);
|
|
3055
3055
|
});
|
|
@@ -3059,11 +3059,11 @@ describe("$location", () => {
|
|
|
3059
3059
|
|
|
3060
3060
|
it("should not set unknown input properties to html5Mode object", () => {
|
|
3061
3061
|
module.config(($locationProvider) => {
|
|
3062
|
-
$locationProvider.
|
|
3062
|
+
$locationProvider.setHtml5Mode({
|
|
3063
3063
|
someProp: "foo",
|
|
3064
3064
|
});
|
|
3065
3065
|
|
|
3066
|
-
expect($locationProvider.
|
|
3066
|
+
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3067
3067
|
enabled: false,
|
|
3068
3068
|
requireBase: true,
|
|
3069
3069
|
rewriteLinks: true,
|
|
@@ -3075,7 +3075,7 @@ describe("$location", () => {
|
|
|
3075
3075
|
|
|
3076
3076
|
it("should default to enabled:false, requireBase:true and rewriteLinks:true", () => {
|
|
3077
3077
|
module.config(($locationProvider) => {
|
|
3078
|
-
expect($locationProvider.
|
|
3078
|
+
expect($locationProvider.getHtml5Mode()).toEqual({
|
|
3079
3079
|
enabled: false,
|
|
3080
3080
|
requireBase: true,
|
|
3081
3081
|
rewriteLinks: true,
|
|
@@ -3178,7 +3178,7 @@ describe("$location", () => {
|
|
|
3178
3178
|
// it("should complain if no base tag present", () => {
|
|
3179
3179
|
// let module = window.angular.module("test1", ["ng"]);
|
|
3180
3180
|
// module.config((_$locationProvider_) => {
|
|
3181
|
-
// $locationProvider.
|
|
3181
|
+
// $locationProvider.setHtml5Mode(true);
|
|
3182
3182
|
// });
|
|
3183
3183
|
|
|
3184
3184
|
// createInjector(["test1"]).invoke(($browser, $injector) => {
|
|
@@ -3191,7 +3191,7 @@ describe("$location", () => {
|
|
|
3191
3191
|
|
|
3192
3192
|
// it("should not complain if baseOptOut set to true in html5Mode", () => {
|
|
3193
3193
|
// module.config(($locationProvider) => {
|
|
3194
|
-
// $locationProvider.
|
|
3194
|
+
// $locationProvider.setHtml5Mode({
|
|
3195
3195
|
// enabled: true,
|
|
3196
3196
|
// requireBase: false,
|
|
3197
3197
|
// });
|
package/src/core/prop.spec.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createInjector } from "./di/injector";
|
|
|
3
3
|
import { valueFn } from "../shared/utils";
|
|
4
4
|
import { dealoc } from "../shared/jqlite/jqlite";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
describe("ngProp*", () => {
|
|
7
7
|
let $compile, $rootScope, compileProvider, $sce;
|
|
8
8
|
let logs = [];
|
|
9
9
|
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { isUndefined } from "../../shared/utils.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* @
|
|
4
|
+
* @param {string} source - the name of the attribute to be observed
|
|
5
|
+
* @param {string} prop - the scope property to be updated with attribute value
|
|
6
|
+
* @returns {import("../../types.js").Directive}
|
|
3
7
|
*/
|
|
4
|
-
export function ngObserveDirective() {
|
|
8
|
+
export function ngObserveDirective(source, prop) {
|
|
5
9
|
return {
|
|
6
10
|
restrict: "A",
|
|
7
|
-
|
|
11
|
+
compile: () => (scope, element) => {
|
|
8
12
|
const targetElement = element[0];
|
|
9
|
-
|
|
10
|
-
let prop = targetElement.dataset["update"];
|
|
11
|
-
if (!prop) {
|
|
13
|
+
if (isUndefined(prop) || prop == "") {
|
|
12
14
|
prop = source;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
16
|
if (!scope[prop]) {
|
|
16
17
|
scope[prop] = targetElement.getAttribute(source);
|
|
17
18
|
}
|
|
@@ -23,16 +23,14 @@ describe("observe", () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
function createDirective(attributeValue, updateProp) {
|
|
26
|
-
const template = `<div ng-observe
|
|
26
|
+
const template = `<div ng-observe-${attributeValue}="${updateProp}"></div>`;
|
|
27
27
|
element = $compile(template)($scope);
|
|
28
28
|
$scope.$digest();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
it("should set the scope property to the attribute value before any changes", () => {
|
|
32
32
|
const scope = $rootScope.$new();
|
|
33
|
-
const element = JQLite(
|
|
34
|
-
'<div data-update="testProp" ng-observe="sourceAttr"></div>',
|
|
35
|
-
);
|
|
33
|
+
const element = JQLite('<div ng-observe-sourceAttr="testProp"></div>');
|
|
36
34
|
element.attr("sourceAttr", "initialValue");
|
|
37
35
|
$compile(element)(scope);
|
|
38
36
|
|
|
@@ -92,7 +90,7 @@ describe("observe", () => {
|
|
|
92
90
|
|
|
93
91
|
it("should observe attribute changes and update the same scope name if data-update attribute is absent", () => {
|
|
94
92
|
$scope.myProp = "";
|
|
95
|
-
const template = `<div ng-observe
|
|
93
|
+
const template = `<div ng-observe-test-attribute></div>`;
|
|
96
94
|
element = $compile(template)($scope);
|
|
97
95
|
$scope.$digest();
|
|
98
96
|
spyOn($scope, "$digest").and.callThrough();
|
|
@@ -74,11 +74,7 @@
|
|
|
74
74
|
<test-component greeting="{{ greeting }}"></test-component>
|
|
75
75
|
<div>{{ greeting }}</div>
|
|
76
76
|
|
|
77
|
-
<fluent-select
|
|
78
|
-
ng-observe="current-value"
|
|
79
|
-
data-update="greeting"
|
|
80
|
-
title="Select a section"
|
|
81
|
-
>
|
|
77
|
+
<fluent-select ng-observe-current-value="greeting" title="Select a section">
|
|
82
78
|
<fluent-option value="Beginning">Beginning</fluent-option>
|
|
83
79
|
<fluent-option value="Middle">Middle</fluent-option>
|
|
84
80
|
<fluent-option value="End">End</fluent-option>
|
|
@@ -86,7 +82,7 @@
|
|
|
86
82
|
<br />
|
|
87
83
|
|
|
88
84
|
{{ activeid }}
|
|
89
|
-
<fluent-tabs ng-observe
|
|
85
|
+
<fluent-tabs ng-observe-activeid activeid="entrees">
|
|
90
86
|
<fluent-tab id="apps">Appetizers</fluent-tab>
|
|
91
87
|
<fluent-tab id="entrees">Entrees</fluent-tab>
|
|
92
88
|
<fluent-tab id="desserts">Desserts</fluent-tab>
|
|
@@ -171,7 +167,7 @@
|
|
|
171
167
|
|
|
172
168
|
{{ value }}
|
|
173
169
|
|
|
174
|
-
<fluent-radio-group ng-observe
|
|
170
|
+
<fluent-radio-group ng-observe-value orientation="vertical">
|
|
175
171
|
<fluent-radio value="1">18-24</fluent-radio>
|
|
176
172
|
<fluent-radio value="2">25-33</fluent-radio>
|
|
177
173
|
<fluent-radio value="3">34-44</fluent-radio>
|
|
@@ -180,7 +176,7 @@
|
|
|
180
176
|
|
|
181
177
|
{{ checked }}
|
|
182
178
|
|
|
183
|
-
<fluent-switch ng-observe
|
|
179
|
+
<fluent-switch ng-observe-aria-checked="checked">
|
|
184
180
|
<span slot="checked-message">On</span>
|
|
185
181
|
<span slot="unchecked-message">Off</span>
|
|
186
182
|
<label for="cap-switch">Captions:</label>
|
package/src/loader.js
CHANGED
|
@@ -146,14 +146,14 @@ export class Angular {
|
|
|
146
146
|
* @param {import("./core/di/internal-injector").InjectorService} $injector
|
|
147
147
|
*/
|
|
148
148
|
function (scope, el, compile, $injector) {
|
|
149
|
-
|
|
149
|
+
// ng-route deps
|
|
150
150
|
services.$injector = $injector;
|
|
151
151
|
services.$q = $injector.get("$q");
|
|
152
152
|
scope.$apply(() => {
|
|
153
153
|
el.data("$injector", $injector);
|
|
154
154
|
compile(el)(scope);
|
|
155
155
|
});
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
// https://github.com/angular-ui/ui-router/issues/3678
|
|
158
158
|
if (!Object.prototype.hasOwnProperty.call($injector, "strictDi")) {
|
|
159
159
|
try {
|
package/src/public.js
CHANGED
|
@@ -130,7 +130,6 @@ import {
|
|
|
130
130
|
$ViewDirectiveFill,
|
|
131
131
|
ngView,
|
|
132
132
|
} from "./router/directives/view-directive.js";
|
|
133
|
-
import { ngObserveDirective } from "./directive/observe/observe.js";
|
|
134
133
|
import { ngChannelDirective } from "./directive/channel/channel.js";
|
|
135
134
|
|
|
136
135
|
/**
|
|
@@ -191,7 +190,6 @@ export function publishExternalAPI(angular) {
|
|
|
191
190
|
ngSwitch: ngSwitchDirective,
|
|
192
191
|
ngSwitchWhen: ngSwitchWhenDirective,
|
|
193
192
|
ngSwitchDefault: ngSwitchDefaultDirective,
|
|
194
|
-
ngObserve: ngObserveDirective,
|
|
195
193
|
ngOptions: ngOptionsDirective,
|
|
196
194
|
ngTransclude: ngTranscludeDirective,
|
|
197
195
|
ngModel: ngModelDirective,
|
|
@@ -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(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
url: "
|
|
35
|
-
template:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
]);
|
|
@@ -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>
|