@angular-wave/angular.ts 0.0.4 → 0.0.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "license": "MIT",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "main": "dist/angular-ts.cjs.js",
7
7
  "module": "dist/angular-ts.esm.js",
@@ -24,6 +24,7 @@
24
24
  "@playwright/test": "^1.44.0",
25
25
  "@rollup/plugin-commonjs": "latest",
26
26
  "@rollup/plugin-node-resolve": "latest",
27
+ "@rollup/plugin-terser": "^0.4.4",
27
28
  "@types/jasmine": "latest",
28
29
  "@types/node": "latest",
29
30
  "eslint": "latest",
@@ -40,8 +41,5 @@
40
41
  "sinon": "latest",
41
42
  "typescript": "latest",
42
43
  "vite": "latest"
43
- },
44
- "dependencies": {
45
-
46
44
  }
47
45
  }
package/rollup.config.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import resolve from '@rollup/plugin-node-resolve';
2
2
  import commonjs from '@rollup/plugin-commonjs';
3
3
  import pkg from './package.json' assert { type: 'json' };
4
+ import terser from '@rollup/plugin-terser';
4
5
 
5
6
  export default [
6
7
  // browser-friendly UMD build
@@ -11,7 +12,7 @@ export default [
11
12
  file: pkg.browser,
12
13
  format: 'umd',
13
14
  },
14
- plugins: [resolve(), commonjs()],
15
+ plugins: [resolve(), commonjs(), terser()],
15
16
  },
16
17
 
17
18
  // CommonJS (for Node) and ES module (for bundlers) build.
@@ -27,5 +28,6 @@ export default [
27
28
  { file: pkg.main, format: 'cjs' },
28
29
  { file: pkg.module, format: 'es' },
29
30
  ],
31
+ plugins: [terser()],
30
32
  },
31
33
  ];
package/src/core/utils.js CHANGED
@@ -617,6 +617,14 @@ export function includes(array, obj) {
617
617
  return Array.prototype.indexOf.call(array, obj) !== -1;
618
618
  }
619
619
 
620
+ /**
621
+ * Removes the first occurrence of a specified value from an array.
622
+ *
623
+ * @template T
624
+ * @param {Array<T>} array - The array from which to remove the value.
625
+ * @param {T} value - The value to remove.
626
+ * @returns {number} - The index of the removed value, or -1 if the value was not found.
627
+ */
620
628
  export function arrayRemove(array, value) {
621
629
  const index = array.indexOf(value);
622
630
  if (index >= 0) {
@@ -1,66 +1,6 @@
1
1
  import { forEach } from "../core/utils";
2
2
  import { getBlockNodes } from "../jqLite";
3
3
 
4
- /**
5
- * @ngdoc directive
6
- * @name ngSwitch
7
- * @restrict EA
8
- *
9
- * @description
10
- * The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a scope expression.
11
- * Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be preserved at the location
12
- * as specified in the template.
13
- *
14
- * The directive itself works similar to ngInclude, however, instead of downloading template code (or loading it
15
- * from the template cache), `ngSwitch` simply chooses one of the nested elements and makes it visible based on which element
16
- * matches the value obtained from the evaluated expression. In other words, you define a container element
17
- * (where you place the directive), place an expression on the **`on="..."` attribute**
18
- * (or the **`ng-switch="..."` attribute**), define any inner elements inside of the directive and place
19
- * a when attribute per element. The when attribute is used to inform ngSwitch which element to display when the on
20
- * expression is evaluated. If a matching expression is not found via a when attribute then an element with the default
21
- * attribute is displayed.
22
- *
23
- * <div class="alert alert-info">
24
- * Be aware that the attribute values to match against cannot be expressions. They are interpreted
25
- * as literal string values to match against.
26
- * For example, **`ng-switch-when="someVal"`** will match against the string `"someVal"` not against the
27
- * value of the expression `$scope.someVal`.
28
- * </div>
29
-
30
- * @animations
31
- * | Animation | Occurs |
32
- * |----------------------------------|-------------------------------------|
33
- * | {@link ng.$animate#enter enter} | after the ngSwitch contents change and the matched child element is placed inside the container |
34
- * | {@link ng.$animate#leave leave} | after the ngSwitch contents change and just before the former contents are removed from the DOM |
35
- *
36
- * @usage
37
- *
38
- * ```
39
- * <ANY ng-switch="expression">
40
- * <ANY ng-switch-when="matchValue1">...</ANY>
41
- * <ANY ng-switch-when="matchValue2">...</ANY>
42
- * <ANY ng-switch-default>...</ANY>
43
- * </ANY>
44
- * ```
45
- *
46
- *
47
- * @scope
48
- * @priority 1200
49
- * @param {*} ngSwitch|on expression to match against <code>ng-switch-when</code>.
50
- * On child elements add:
51
- *
52
- * * `ngSwitchWhen`: the case statement to match against. If match then this
53
- * case will be displayed. If the same match appears multiple times, all the
54
- * elements will be displayed. It is possible to associate multiple values to
55
- * the same `ngSwitchWhen` by defining the optional attribute
56
- * `ngSwitchWhenSeparator`. The separator will be used to split the value of
57
- * the `ngSwitchWhen` attribute into multiple tokens, and the element will show
58
- * if any of the `ngSwitch` evaluates to any of these tokens.
59
- * * `ngSwitchDefault`: the default case when no other case match. If there
60
- * are multiple default cases, all of them will be displayed when no other
61
- * case match.
62
- *
63
- */
64
4
  export const ngSwitchDirective = [
65
5
  "$animate",
66
6
  "$compile",
@@ -70,11 +10,13 @@ export const ngSwitchDirective = [
70
10
  // asks for $scope to fool the BC controller module
71
11
  controller: [
72
12
  "$scope",
73
- function NgSwitchController() {
74
- this.cases = {};
13
+ class {
14
+ constructor() {
15
+ this.cases = {};
16
+ }
75
17
  },
76
18
  ],
77
- link(scope, element, attr, ngSwitchController) {
19
+ link(scope, _element, attr, ngSwitchController) {
78
20
  const watchExpr = attr.ngSwitch || attr.on;
79
21
  let selectedTranscludes = [];
80
22
  const selectedElements = [];
@@ -0,0 +1,66 @@
1
+ /\*\*
2
+
3
+ - @ngdoc directive
4
+ - @name ngSwitch
5
+ - @restrict EA
6
+ -
7
+ - @description
8
+ - The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a scope expression.
9
+ - Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be preserved at the location
10
+ - as specified in the template.
11
+ -
12
+ - The directive itself works similar to ngInclude, however, instead of downloading template code (or loading it
13
+ - from the template cache), `ngSwitch` simply chooses one of the nested elements and makes it visible based on which element
14
+ - matches the value obtained from the evaluated expression. In other words, you define a container element
15
+ - (where you place the directive), place an expression on the **`on="..."` attribute**
16
+ - (or the **`ng-switch="..."` attribute**), define any inner elements inside of the directive and place
17
+ - a when attribute per element. The when attribute is used to inform ngSwitch which element to display when the on
18
+ - expression is evaluated. If a matching expression is not found via a when attribute then an element with the default
19
+ - attribute is displayed.
20
+ -
21
+ - <div class="alert alert-info">
22
+ - Be aware that the attribute values to match against cannot be expressions. They are interpreted
23
+ - as literal string values to match against.
24
+ - For example, **`ng-switch-when="someVal"`** will match against the string `"someVal"` not against the
25
+ - value of the expression `$scope.someVal`.
26
+ - </div>
27
+
28
+ - @animations
29
+ - | Animation | Occurs |
30
+ - |----------------------------------|-------------------------------------|
31
+ - | {@link ng.$animate#enter enter} | after the ngSwitch contents change and the matched child element is placed inside the container |
32
+ - | {@link ng.$animate#leave leave} | after the ngSwitch contents change and just before the former contents are removed from the DOM |
33
+ -
34
+ - @usage
35
+ -
36
+ - ```
37
+
38
+ ```
39
+
40
+ - <ANY ng-switch="expression">
41
+ - <ANY ng-switch-when="matchValue1">...</ANY>
42
+ - <ANY ng-switch-when="matchValue2">...</ANY>
43
+ - <ANY ng-switch-default>...</ANY>
44
+ - </ANY>
45
+ - ```
46
+
47
+ ```
48
+
49
+ -
50
+ -
51
+ - @scope
52
+ - @priority 1200
53
+ - @param {\*} ngSwitch|on expression to match against <code>ng-switch-when</code>.
54
+ - On child elements add:
55
+ -
56
+ - - `ngSwitchWhen`: the case statement to match against. If match then this
57
+ - case will be displayed. If the same match appears multiple times, all the
58
+ - elements will be displayed. It is possible to associate multiple values to
59
+ - the same `ngSwitchWhen` by defining the optional attribute
60
+ - `ngSwitchWhenSeparator`. The separator will be used to split the value of
61
+ - the `ngSwitchWhen` attribute into multiple tokens, and the element will show
62
+ - if any of the `ngSwitch` evaluates to any of these tokens.
63
+ - - `ngSwitchDefault`: the default case when no other case match. If there
64
+ - are multiple default cases, all of them will be displayed when no other
65
+ - case match.
66
+ - \*/
package/src/jqLite.js CHANGED
@@ -94,17 +94,8 @@ import { CACHE, EXPANDO } from "./core/cache";
94
94
  * @returns {Object} jQuery object.
95
95
  */
96
96
 
97
- JQLite.cache = CACHE;
98
-
99
97
  let jqId = 1;
100
98
 
101
- /**
102
- * !!! This is an undocumented "private" function !!!
103
- * @param {JQLite|Element} node
104
- * @returns
105
- */
106
- JQLite._data = (node) => JQLite.cache.get(node[EXPANDO]) || {};
107
-
108
99
  function jqNextId() {
109
100
  return ++jqId;
110
101
  }
@@ -289,6 +280,11 @@ export function JQLite(element) {
289
280
  }
290
281
  export var jqLite = JQLite;
291
282
 
283
+ /**
284
+ * @param {Element} element
285
+ * @param {boolean} [onlyDescendants]
286
+ * @returns {void}
287
+ */
292
288
  export function dealoc(element, onlyDescendants) {
293
289
  if (!element) return;
294
290
  if (!onlyDescendants && elementAcceptsData(element))
@@ -307,13 +303,13 @@ export function dealoc(element, onlyDescendants) {
307
303
  */
308
304
  function removeIfEmptyData(element) {
309
305
  const expandoId = element[EXPANDO];
310
- const { events, data } = JQLite.cache.get(expandoId);
306
+ const { events, data } = CACHE.get(expandoId);
311
307
 
312
308
  if (
313
309
  (!data || !Object.keys(data).length) &&
314
310
  (!events || !Object.keys(events).length)
315
311
  ) {
316
- JQLite.cache.delete(expandoId);
312
+ CACHE.delete(expandoId);
317
313
  element[EXPANDO] = undefined; // don't delete DOM expandos. IE and Chrome don't like it
318
314
  }
319
315
  }
@@ -341,8 +337,8 @@ function jqLiteOff(element, type, fn, unsupported) {
341
337
  } else {
342
338
  const removeHandler = function (type) {
343
339
  const listenerFns = events[type];
344
- if (isDefined(fn)) {
345
- arrayRemove(listenerFns || [], fn);
340
+ if (isDefined(fn) && isArray(listenerFns)) {
341
+ arrayRemove(listenerFns, fn);
346
342
  }
347
343
  if (!(isDefined(fn) && listenerFns && listenerFns.length > 0)) {
348
344
  element.removeEventListener(type, handle);
@@ -370,7 +366,7 @@ function jqLiteOff(element, type, fn, unsupported) {
370
366
  */
371
367
  function jqLiteRemoveData(element, name) {
372
368
  const expandoId = element[EXPANDO];
373
- const expandoStore = expandoId && JQLite.cache.get(expandoId);
369
+ const expandoStore = expandoId && CACHE.get(expandoId);
374
370
 
375
371
  if (expandoStore) {
376
372
  if (name) {
@@ -391,7 +387,7 @@ function jqLiteRemoveData(element, name) {
391
387
  */
392
388
  function jqLiteExpandoStore(element, createIfNecessary = false) {
393
389
  let expandoId = element[EXPANDO];
394
- let expandoStore = expandoId && JQLite.cache.get(expandoId);
390
+ let expandoStore = expandoId && CACHE.get(expandoId);
395
391
 
396
392
  if (createIfNecessary && !expandoStore) {
397
393
  element[EXPANDO] = expandoId = jqNextId();
@@ -400,7 +396,7 @@ function jqLiteExpandoStore(element, createIfNecessary = false) {
400
396
  data: {},
401
397
  handle: null,
402
398
  };
403
- JQLite.cache.set(expandoId, expandoStore);
399
+ CACHE.set(expandoId, expandoStore);
404
400
  }
405
401
 
406
402
  return expandoStore;
@@ -417,15 +413,12 @@ function jqLiteData(element, key, value) {
417
413
  const data = expandoStore && expandoStore.data;
418
414
 
419
415
  if (isSimpleSetter) {
420
- // data('key', value)
421
416
  data[kebabToCamel(key)] = value;
422
417
  } else {
423
418
  if (massGetter) {
424
- // data()
425
419
  return data;
426
420
  }
427
421
  if (isSimpleGetter) {
428
- // data('key')
429
422
  // don't force creation of expandoStore if it doesn't exist yet
430
423
  return data && data[kebabToCamel(key)];
431
424
  }
@@ -572,7 +565,7 @@ export function getBooleanAttrName(element, name) {
572
565
 
573
566
  export function jqLiteCleanData(nodes) {
574
567
  for (let i = 0, ii = nodes.length; i < ii; i++) {
575
- var events = (jqLite._data(nodes[i]) || {}).events;
568
+ var events = (CACHE.get(nodes[i][EXPANDO]) || {}).events;
576
569
  if (events && events.$destroy) {
577
570
  jqLite(nodes[i]).triggerHandler("$destroy");
578
571
  }
@@ -707,8 +700,6 @@ forEach(
707
700
  let key;
708
701
  const nodeCount = this.length;
709
702
 
710
- // jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
711
- // in a way that survives minification.
712
703
  // jqLiteEmpty takes no arguments but is a setter.
713
704
  if (
714
705
  fn !== jqLiteEmpty &&
@@ -718,7 +709,6 @@ forEach(
718
709
  // we are a write, but the object properties are the key/values
719
710
  for (i = 0; i < nodeCount; i++) {
720
711
  if (fn === jqLiteData) {
721
- // data() takes the whole object in jQuery
722
712
  fn(this[i], arg1);
723
713
  } else {
724
714
  for (key in arg1) {
@@ -228,18 +228,6 @@ describe("jqLite", () => {
228
228
  });
229
229
  });
230
230
 
231
- describe("_data", () => {
232
- it("should provide access to the events present on the element", () => {
233
- const element = jqLite("<i>foo</i>");
234
- // TODO: REMOVE angular becomes TESTED
235
- angular.element = jqLite;
236
- expect(angular.element._data(element[0]).events).toBeUndefined();
237
-
238
- element.on("click", () => {});
239
- expect(angular.element._data(element[0]).events.click).toBeDefined();
240
- });
241
- });
242
-
243
231
  describe("inheritedData", () => {
244
232
  it("should retrieve data attached to the current element", () => {
245
233
  const element = jqLite("<i>foo</i>");
@@ -541,7 +529,7 @@ describe("jqLite", () => {
541
529
 
542
530
  it("should not break on cleanData(), if element has no data", () => {
543
531
  const selected = jqLite([a, b, c]);
544
- spyOn(jqLite, "_data").and.returnValue(undefined);
532
+ spyOn(CACHE, "get").and.returnValue(undefined);
545
533
  expect(() => {
546
534
  jqLite.cleanData(selected);
547
535
  }).not.toThrow();
@@ -13903,7 +13903,7 @@ describe("$compile", () => {
13903
13903
  firstRepeatedElem = element.children(".ng-scope").eq(0);
13904
13904
 
13905
13905
  expect(firstRepeatedElem.data("$scope")).toBeDefined();
13906
- privateData = JQLite._data(firstRepeatedElem[0]);
13906
+ privateData = CACHE.get(firstRepeatedElem[0]);
13907
13907
  expect(privateData.events).toBeDefined();
13908
13908
 
13909
13909
  expect(privateData.events.click).toBeDefined();
@@ -13919,7 +13919,7 @@ describe("$compile", () => {
13919
13919
 
13920
13920
  expect(destroyCount).toBe(2);
13921
13921
  expect(firstRepeatedElem.data("$scope")).not.toBeDefined();
13922
- privateData = JQLite._data(firstRepeatedElem[0]);
13922
+ privateData = CACHE.get(firstRepeatedElem[0]);
13923
13923
  expect(privateData && privateData.events).not.toBeDefined();
13924
13924
  }
13925
13925