@angular-wave/angular.ts 0.6.5 → 0.6.6

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/package.json CHANGED
@@ -2,9 +2,10 @@
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.6.5",
5
+ "version": "0.6.6",
6
6
  "type": "module",
7
7
  "main": "dist/angular-ts.esm.js",
8
+ "types": "types/index.d.ts",
8
9
  "browser": "dist/angular-ts.umd.js",
9
10
  "repository": {
10
11
  "type": "git",
@@ -3664,7 +3664,6 @@ describe("$compile", () => {
3664
3664
  return {
3665
3665
  transclude: "element",
3666
3666
  link: function (scope, el, attrs, ctrl, transclude) {
3667
- debugger;
3668
3667
  const res = transclude();
3669
3668
  el.after(res);
3670
3669
  },
@@ -13061,7 +13060,7 @@ describe("$compile", () => {
13061
13060
  describe("content transclusion", () => {
13062
13061
  it("should support transclude directive", () => {
13063
13062
  module.directive("trans", () => ({
13064
- transclude: "content",
13063
+ transclude: true,
13065
13064
  replace: true,
13066
13065
  scope: {},
13067
13066
  link(scope) {
@@ -13087,7 +13086,7 @@ describe("$compile", () => {
13087
13086
  .directive(
13088
13087
  "book",
13089
13088
  valueFn({
13090
- transclude: "content",
13089
+ transclude: true,
13091
13090
  template:
13092
13091
  "<div>book-<div chapter>(<div ng-transclude></div>)</div></div>",
13093
13092
  }),
@@ -13095,14 +13094,14 @@ describe("$compile", () => {
13095
13094
  .directive(
13096
13095
  "chapter",
13097
13096
  valueFn({
13098
- transclude: "content",
13097
+ transclude: true,
13099
13098
  templateUrl: "chapter.html",
13100
13099
  }),
13101
13100
  )
13102
13101
  .directive(
13103
13102
  "section",
13104
13103
  valueFn({
13105
- transclude: "content",
13104
+ transclude: true,
13106
13105
  template:
13107
13106
  "<div>section-!<div ng-transclude></div>!</div></div>",
13108
13107
  }),
@@ -13165,7 +13164,7 @@ describe("$compile", () => {
13165
13164
  module.directive(
13166
13165
  "foo",
13167
13166
  valueFn({
13168
- transclude: "content",
13167
+ transclude: true,
13169
13168
  template: "<div>This is before {{before}}. </div>",
13170
13169
  link(scope, element, attr, ctrls, $transclude) {
13171
13170
  const futureParent = element.children().eq(0);
@@ -13234,7 +13233,7 @@ describe("$compile", () => {
13234
13233
  .directive(
13235
13234
  "trans",
13236
13235
  valueFn({
13237
- transclude: "content",
13236
+ transclude: true,
13238
13237
  link(scope, element, attr, ctrl, $transclude) {
13239
13238
  $transclude((clone) => {
13240
13239
  element.append(clone);
@@ -13266,7 +13265,7 @@ describe("$compile", () => {
13266
13265
  .directive(
13267
13266
  "trans",
13268
13267
  valueFn({
13269
- transclude: "content",
13268
+ transclude: true,
13270
13269
  link(scope, element, attr, ctrl, $transclude) {
13271
13270
  $transclude((clone) => {
13272
13271
  element.append(clone);
@@ -13862,7 +13861,7 @@ describe("$compile", () => {
13862
13861
  module.directive(
13863
13862
  "transclude",
13864
13863
  valueFn({
13865
- transclude: "content",
13864
+ transclude: true,
13866
13865
  controller($transclude) {
13867
13866
  transcludeCtrl = this;
13868
13867
  },
@@ -13899,7 +13898,7 @@ describe("$compile", () => {
13899
13898
  module.directive(
13900
13899
  "transclude",
13901
13900
  valueFn({
13902
- transclude: "content",
13901
+ transclude: true,
13903
13902
  controller($transclude) {
13904
13903
  ctrlTransclude = $transclude;
13905
13904
  },
@@ -13927,7 +13926,7 @@ describe("$compile", () => {
13927
13926
  module.directive(
13928
13927
  "transclude",
13929
13928
  valueFn({
13930
- transclude: "content",
13929
+ transclude: true,
13931
13930
  link(scope, element, attr, ctrl, $transclude) {
13932
13931
  $transclude(scope, (clone) => {
13933
13932
  element.append(clone);
@@ -13947,7 +13946,7 @@ describe("$compile", () => {
13947
13946
  .directive(
13948
13947
  "transclude",
13949
13948
  valueFn({
13950
- transclude: "content",
13949
+ transclude: true,
13951
13950
  controller() {},
13952
13951
  link(scope, element, attr, ctrl, $transclude) {
13953
13952
  $transclude((clone) => {
@@ -14766,7 +14765,7 @@ describe("$compile", () => {
14766
14765
  .directive(
14767
14766
  "transclude",
14768
14767
  valueFn({
14769
- transclude: "content",
14768
+ transclude: true,
14770
14769
  controller($transclude) {
14771
14770
  transclude = $transclude;
14772
14771
  },
@@ -48,16 +48,18 @@ export const errorHandler = (exception, cause) => {
48
48
  * @constructor
49
49
  * @this {import('../types').ServiceProvider}
50
50
  */
51
- export function ExceptionHandlerProvider() {
52
- this.$get = [
53
- "$log",
54
- /**
55
- * @param {import('../services/log').LogService} $log
56
- * @returns {ErrorHandler}
57
- */
58
- function ($log) {
59
- log = $log;
60
- return errorHandler;
61
- },
62
- ];
51
+ export class ExceptionHandlerProvider {
52
+ constructor() {
53
+ this.$get = [
54
+ "$log",
55
+ /**
56
+ * @param {import('../services/log').LogService} $log
57
+ * @returns {ErrorHandler}
58
+ */
59
+ function ($log) {
60
+ log = $log;
61
+ return errorHandler;
62
+ },
63
+ ];
64
+ }
63
65
  }
@@ -1,5 +1,4 @@
1
1
  import { createInjector } from "../../core/di/injector";
2
- import { forEach } from "../../shared/utils.js";
3
2
  import { Angular } from "../../loader";
4
3
 
5
4
  describe("ngBindHtml", () => {
@@ -11,6 +11,7 @@
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
13
  <script type="module" src="/src/directive/bind/bind.spec.js"></script>
14
+ <script type="module" src="/src/directive/bind/bind-html.spec.js"></script>
14
15
  </head>
15
16
  <body>
16
17
  <div id="dummy"></div>
@@ -159,65 +159,71 @@ describe("ngOptions", () => {
159
159
  beforeEach(() => {
160
160
  window.angular = new Angular();
161
161
  window.angular
162
- .module("myModule", ["ng"])
163
- .decorator("$exceptionHandler", function () {
164
- return (exception, cause) => {
165
- throw new Error(exception.message);
166
- };
167
- });
168
- injector = createInjector([
169
- "myModule",
170
- ($compileProvider, $provide) => {
171
- linkLog = [];
172
-
173
- $compileProvider
174
- .directive("customSelect", () => ({
175
- restrict: "E",
176
- replace: true,
177
- scope: {
178
- ngModel: "=",
179
- options: "=",
180
- },
181
- templateUrl: "select_template.html",
182
- link(scope, $element, attributes) {
183
- scope.selectable_options = scope.options;
184
- },
185
- }))
162
+ .module("myModule", [
163
+ "ng",
164
+ ($compileProvider, $provide) => {
165
+ linkLog = [];
166
+
167
+ $compileProvider
168
+ .directive("customSelect", () => ({
169
+ restrict: "E",
170
+ replace: true,
171
+ scope: {
172
+ ngModel: "=",
173
+ options: "=",
174
+ },
175
+ templateUrl: "select_template.html",
176
+ link(scope, $element, attributes) {
177
+ scope.selectable_options = scope.options;
178
+ },
179
+ }))
186
180
 
187
- .directive("oCompileContents", () => ({
188
- link(scope, element) {
189
- linkLog.push("linkCompileContents");
190
- $compile(JQLite(element[0].childNodes))(scope);
191
- },
192
- }))
181
+ .directive("oCompileContents", () => ({
182
+ link(scope, element) {
183
+ linkLog.push("linkCompileContents");
184
+ $compile(JQLite(element[0].childNodes))(scope);
185
+ },
186
+ }))
193
187
 
194
- .directive("observeChildList", () => ({
195
- link(scope, element) {
196
- const config = { childList: true };
188
+ .directive("observeChildList", () => ({
189
+ link(scope, element) {
190
+ const config = { childList: true };
197
191
 
198
- childListMutationObserver = new window.MutationObserver(() => {});
199
- childListMutationObserver.observe(element[0], config);
200
- },
201
- }));
202
-
203
- $provide.decorator("ngOptionsDirective", ($delegate) => {
204
- const origPreLink = $delegate[0].link.pre;
205
- const origPostLink = $delegate[0].link.post;
206
-
207
- $delegate[0].compile = function () {
208
- return {
209
- pre: origPreLink,
210
- post() {
211
- linkLog.push("linkNgOptions");
212
- origPostLink.apply(this, arguments);
192
+ childListMutationObserver = new window.MutationObserver(
193
+ () => {},
194
+ );
195
+ childListMutationObserver.observe(element[0], config);
213
196
  },
197
+ }));
198
+
199
+ $provide.decorator("ngOptionsDirective", ($delegate) => {
200
+ const origPreLink = $delegate[0].link.pre;
201
+ const origPostLink = $delegate[0].link.post;
202
+
203
+ $delegate[0].compile = function () {
204
+ return {
205
+ pre: origPreLink,
206
+ post() {
207
+ linkLog.push("linkNgOptions");
208
+ origPostLink.apply(this, arguments);
209
+ },
210
+ };
214
211
  };
215
- };
216
212
 
217
- return $delegate;
218
- });
219
- },
213
+ return $delegate;
214
+ });
215
+ },
216
+ ])
217
+ .decorator("$exceptionHandler", function () {
218
+ return (exception, cause) => {
219
+ throw new Error(exception.message);
220
+ };
221
+ });
222
+
223
+ injector = window.angular.bootstrap(document.getElementById("dummy"), [
224
+ "myModule",
220
225
  ]);
226
+
221
227
  $compile = injector.get("$compile");
222
228
  scope = injector.get("$rootScope").$new(); // create a child scope because the root scope can't be $destroy-ed
223
229
  formElement = element = null;
@@ -2992,7 +2998,7 @@ describe("ngOptions", () => {
2992
2998
  const addSpiesOnProto =
2993
2999
  originalSelectedDescriptor && originalSelectedDescriptor.configurable;
2994
3000
 
2995
- Object.entries(options).forEach(([i, option]) => {
3001
+ options.elements().forEach((option, i) => {
2996
3002
  const setSelected = function (value) {
2997
3003
  _selected[i] = value;
2998
3004
  };
@@ -3003,7 +3009,7 @@ describe("ngOptions", () => {
3003
3009
  });
3004
3010
 
3005
3011
  if (!addSpiesOnProto) {
3006
- Object.entries(options).forEach(([i, option]) => {
3012
+ options.elements().forEach((option, i) => {
3007
3013
  Object.defineProperty(option, "selected", {
3008
3014
  get() {
3009
3015
  return _selected[i];
@@ -21,8 +21,11 @@ export function ngSetterDirective($parse) {
21
21
  }
22
22
 
23
23
  const updateModel = (value) => {
24
- assignModel(scope, value);
25
- scope.$digest();
24
+ if (value !== "") {
25
+ const maybeNumber = convertToNumberOrString(value);
26
+ assignModel(scope, maybeNumber);
27
+ scope.$digest();
28
+ }
26
29
  };
27
30
 
28
31
  const observer = new MutationObserver((mutationsList) => {
@@ -54,7 +57,19 @@ export function ngSetterDirective($parse) {
54
57
  }
55
58
 
56
59
  scope.$on("$destroy", () => observer.disconnect());
57
- updateModel(element.html());
60
+ const content = element.html();
61
+ updateModel(content);
58
62
  },
59
63
  };
60
64
  }
65
+
66
+ /**
67
+ * Converts the input to a number if possible, otherwise returns the input as a string.
68
+ *
69
+ * @param {string} input - The input to be converted or returned.
70
+ * @returns {number|string} The converted number if valid, or the original string if not convertible.
71
+ */
72
+ function convertToNumberOrString(input) {
73
+ const converted = Number(input);
74
+ return isNaN(converted) ? input : converted;
75
+ }
@@ -21,7 +21,6 @@ describe("setter", () => {
21
21
  });
22
22
 
23
23
  it("should update the scope model when the element content changes", async () => {
24
- $rootScope.testModel = "";
25
24
  const element = $compile('<div ng-setter="testModel"></div>')($rootScope);
26
25
  $rootScope.$digest();
27
26
 
@@ -32,16 +31,40 @@ describe("setter", () => {
32
31
  expect($rootScope.testModel).toBe("New content");
33
32
  });
34
33
 
34
+ it("should update the scope model for objects when the element content changes", async () => {
35
+ const element = $compile('<div ng-setter="testModel.a">1</div>')(
36
+ $rootScope,
37
+ );
38
+ $rootScope.$digest();
39
+
40
+ element.html("New content");
41
+ await wait();
42
+ $rootScope.$digest();
43
+
44
+ expect($rootScope.testModel.a).toBe("New content");
45
+ });
46
+
35
47
  it("should handle initial content in the element", () => {
36
- $rootScope.testModel = "";
37
- const element = $compile(
38
- '<div ng-setter="testModel">Initial content</div>',
39
- )($rootScope);
48
+ $compile('<div ng-setter="testModel">Initial content</div>')($rootScope);
40
49
  $rootScope.$digest();
41
50
 
42
51
  expect($rootScope.testModel).toBe("Initial content");
43
52
  });
44
53
 
54
+ it("should handle initial content in the element for objects", () => {
55
+ $compile('<div ng-setter="testModel.a">Initial content</div>')($rootScope);
56
+ $rootScope.$digest();
57
+
58
+ expect($rootScope.testModel.a).toBe("Initial content");
59
+ });
60
+
61
+ it("should convert initial content in the element to numbers if possible", () => {
62
+ $compile('<div ng-setter="testModel.a">1</div>')($rootScope);
63
+ $rootScope.$digest();
64
+
65
+ expect($rootScope.testModel.a).toBe(1);
66
+ });
67
+
45
68
  it("should warn if no model expression is provided", () => {
46
69
  spyOn(console, "warn");
47
70
 
@@ -55,9 +78,7 @@ describe("setter", () => {
55
78
 
56
79
  it("should clean up the MutationObserver on scope destruction", async () => {
57
80
  spyOn(window, "MutationObserver").and.returnValue(observerSpy);
58
- const element = $compile('<div ng-setter="testModel"></div>')($rootScope);
59
- const isolateScope = element.isolateScope();
60
-
81
+ $compile('<div ng-setter="testModel"></div>')($rootScope);
61
82
  $rootScope.$destroy();
62
83
  await wait();
63
84
  expect(observerSpy.disconnect).toHaveBeenCalled();