@angular-wave/angular.ts 0.0.57 → 0.0.59

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.
@@ -10,3 +10,105 @@ test("unit tests contain no errors", async ({ page }) => {
10
10
  /0 failures/,
11
11
  );
12
12
  });
13
+
14
+ test.describe("animations", () => {
15
+ test("it should add enter and leave classes when animation is enabled", async ({
16
+ page,
17
+ }) => {
18
+ await page.goto("src/directive/if/if-animate-css.html");
19
+ await page.content();
20
+ // when if attribute has `data-animate` set to true
21
+ await page.click('button:has-text("Fade In!")');
22
+ let animated = await page.locator("#data-animate");
23
+
24
+ await expect(animated).toBeVisible();
25
+ await expect(animated).toHaveClass(/ng-enter/);
26
+ await expect(animated).toHaveClass(/ng-enter-active/);
27
+
28
+ // Wait for the transition to complete
29
+ await page.waitForTimeout(500);
30
+ await expect(animated).not.toHaveClass(/ng-enter/);
31
+ await expect(animated).not.toHaveClass(/ng-enter-active/);
32
+
33
+ await page.click('button:has-text("Fade Out!")');
34
+ await expect(animated).toHaveClass(/ng-leave/);
35
+ await expect(animated).toHaveClass(/ng-leave-active/);
36
+ await page.waitForTimeout(500);
37
+ // should be invisible
38
+ await expect(animated).not.toBeVisible();
39
+
40
+ // when if attribute has `animate` set to true
41
+ await page.click('button:has-text("Fade In!")');
42
+ animated = await page.locator("#animate");
43
+
44
+ await expect(animated).toBeVisible();
45
+ await expect(animated).toHaveClass(/ng-enter/);
46
+ await expect(animated).toHaveClass(/ng-enter-active/);
47
+
48
+ // Wait for the transition to complete
49
+ await page.waitForTimeout(500);
50
+ await expect(animated).not.toHaveClass(/ng-enter/);
51
+ await expect(animated).not.toHaveClass(/ng-enter-active/);
52
+
53
+ await page.click('button:has-text("Fade Out!")');
54
+ await expect(animated).toHaveClass(/ng-leave/);
55
+ await expect(animated).toHaveClass(/ng-leave-active/);
56
+ await page.waitForTimeout(500);
57
+ // should be invisible
58
+ await expect(animated).not.toBeVisible();
59
+
60
+ // when if attribute has no animate antributes
61
+ await page.click('button:has-text("Fade In!")');
62
+ let nonAnimated = await page.locator("#no-animate");
63
+
64
+ await expect(nonAnimated).toBeVisible();
65
+ await expect(nonAnimated).not.toHaveClass(/ng-enter/);
66
+ await expect(nonAnimated).not.toHaveClass(/ng-enter-active/);
67
+
68
+ // Wait for the transition to complete
69
+ await page.waitForTimeout(100);
70
+
71
+ await page.click('button:has-text("Fade Out!")');
72
+ // should be instantly invisible
73
+ await expect(nonAnimated).not.toBeVisible();
74
+ });
75
+
76
+ test("should destroy the previous leave animation if a new one takes place", async ({
77
+ page,
78
+ }) => {
79
+ await page.goto("src/directive/if/if-animate-css.html");
80
+ await page.content();
81
+ // when if attribute has `data-animate` set to true
82
+ await page.click('button:has-text("Fade In!")');
83
+ let animated = await page.locator("#data-animate");
84
+
85
+ await expect(animated).toBeVisible();
86
+ await expect(animated).toHaveClass(/ng-enter/);
87
+ await expect(animated).toHaveClass(/ng-enter-active/);
88
+
89
+ // Wait for the transition to complete
90
+ await page.waitForTimeout(500);
91
+ await expect(animated).not.toHaveClass(/ng-enter/);
92
+ await expect(animated).not.toHaveClass(/ng-enter-active/);
93
+
94
+ await page.click('button:has-text("Fade Out!")');
95
+ await page.click('button:has-text("Fade In!")');
96
+ // should be visible
97
+ await page.waitForTimeout(500);
98
+ await expect(animated).toBeVisible();
99
+ await expect(animated).not.toHaveClass(/ng-leave/);
100
+ await expect(animated).not.toHaveClass(/ng-leave-active/);
101
+ });
102
+
103
+ test("should work with svg elements when the svg container is transcluded", async ({
104
+ page,
105
+ }) => {
106
+ await page.goto("src/directive/if/if-animate-css.html");
107
+ await page.content();
108
+ await page.click('button:has-text("Fade In!")');
109
+ await page.waitForTimeout(600);
110
+ let animated = await page.locator("#circle");
111
+ await expect(animated).not.toHaveClass(/ng-enter/);
112
+ await expect(animated).not.toHaveClass(/ng-enter-active/);
113
+ });
114
+ });
@@ -1,5 +1,7 @@
1
1
  import { isDefined } from "../../shared/utils";
2
2
  import { buildFragment } from "../../shared/jqlite/jqlite";
3
+ import { hasAnimate } from "../../shared/utils";
4
+ import { domInsert } from "../../core/animate/animate";
3
5
 
4
6
  export const ngIncludeDirective = [
5
7
  "$templateRequest",
@@ -17,6 +19,15 @@ export const ngIncludeDirective = [
17
19
  const autoScrollExp = attr.autoscroll;
18
20
 
19
21
  return (scope, $element, _$attr, ctrl, $transclude) => {
22
+ function maybeScroll() {
23
+ if (
24
+ isDefined(autoScrollExp) &&
25
+ (!autoScrollExp || scope.$eval(autoScrollExp))
26
+ ) {
27
+ $anchorScroll();
28
+ }
29
+ }
30
+
20
31
  let changeCounter = 0;
21
32
  let currentScope;
22
33
  let previousElement;
@@ -31,9 +42,14 @@ export const ngIncludeDirective = [
31
42
  currentScope = null;
32
43
  }
33
44
  if (currentElement) {
34
- $animate.leave(currentElement).done((response) => {
35
- if (response !== false) previousElement = null;
36
- });
45
+ if (hasAnimate(currentElement[0])) {
46
+ $animate.leave(currentElement).done((response) => {
47
+ if (response !== false) previousElement = null;
48
+ });
49
+ } else {
50
+ currentElement.remove();
51
+ }
52
+
37
53
  previousElement = currentElement;
38
54
  currentElement = null;
39
55
  }
@@ -41,13 +57,7 @@ export const ngIncludeDirective = [
41
57
 
42
58
  scope.$watch(srcExp, (src) => {
43
59
  const afterAnimation = function (response) {
44
- if (
45
- response !== false &&
46
- isDefined(autoScrollExp) &&
47
- (!autoScrollExp || scope.$eval(autoScrollExp))
48
- ) {
49
- $anchorScroll();
50
- }
60
+ response !== false && maybeScroll();
51
61
  };
52
62
 
53
63
  const thisChangeId = ++changeCounter;
@@ -70,7 +80,12 @@ export const ngIncludeDirective = [
70
80
  // directives to non existing elements.
71
81
  const clone = $transclude(newScope, (clone) => {
72
82
  cleanupLastIncludeContent();
73
- $animate.enter(clone, null, $element).done(afterAnimation);
83
+ if (hasAnimate(clone[0])) {
84
+ $animate.enter(clone, null, $element).done(afterAnimation);
85
+ } else {
86
+ domInsert(clone, null, $element);
87
+ maybeScroll();
88
+ }
74
89
  });
75
90
 
76
91
  currentScope = newScope;
@@ -1,6 +1,5 @@
1
1
  /\*\*
2
2
 
3
- - @ngdoc directive
4
3
  - @name ngInclude
5
4
  - @restrict ECA
6
5
  - @scope
@@ -22,7 +21,9 @@
22
21
  - policy may further restrict whether the template is successfully loaded.
23
22
  - For example, `ngInclude` won't work for cross-domain requests on all browsers and for `file://`
24
23
  - access on some browsers.
25
- -
24
+ - The `enter` and `leave` animation effects can be enabled for the element by
25
+ setting data attribute (`data-*`) or custom attribute `animate` to `true` attribute.
26
+
26
27
  - @animations
27
28
  - | Animation | Occurs |
28
29
  - |----------------------------------|-------------------------------------|
@@ -15,6 +15,7 @@ import {
15
15
  isPromiseLike,
16
16
  isUndefined,
17
17
  isFunction,
18
+ hasAnimate,
18
19
  } from "../../shared/utils";
19
20
  import {
20
21
  addSetValidityMethod,
@@ -335,11 +336,21 @@ NgModelController.prototype = {
335
336
 
336
337
  $$updateEmptyClasses(value) {
337
338
  if (this.$isEmpty(value)) {
338
- this.$$animate.removeClass(this.$$element, NOT_EMPTY_CLASS);
339
- this.$$animate.addClass(this.$$element, EMPTY_CLASS);
339
+ if (hasAnimate(this.$$element[0])) {
340
+ this.$$animate.removeClass(this.$$element, NOT_EMPTY_CLASS);
341
+ this.$$animate.addClass(this.$$element, EMPTY_CLASS);
342
+ } else {
343
+ this.$$element[0].classList.remove(NOT_EMPTY_CLASS);
344
+ this.$$element[0].classList.add(EMPTY_CLASS);
345
+ }
340
346
  } else {
341
- this.$$animate.removeClass(this.$$element, EMPTY_CLASS);
342
- this.$$animate.addClass(this.$$element, NOT_EMPTY_CLASS);
347
+ if (hasAnimate(this.$$element[0])) {
348
+ this.$$animate.removeClass(this.$$element, EMPTY_CLASS);
349
+ this.$$animate.addClass(this.$$element, NOT_EMPTY_CLASS);
350
+ } else {
351
+ this.$$element[0].classList.remove(EMPTY_CLASS);
352
+ this.$$element[0].classList.add(NOT_EMPTY_CLASS);
353
+ }
343
354
  }
344
355
  },
345
356
 
@@ -357,8 +368,13 @@ NgModelController.prototype = {
357
368
  $setPristine() {
358
369
  this.$dirty = false;
359
370
  this.$pristine = true;
360
- this.$$animate.removeClass(this.$$element, DIRTY_CLASS);
361
- this.$$animate.addClass(this.$$element, PRISTINE_CLASS);
371
+ if (hasAnimate(this.$$element[0])) {
372
+ this.$$animate.removeClass(this.$$element, EMPTY_CLASS);
373
+ this.$$animate.addClass(this.$$element, PRISTINE_CLASS);
374
+ } else {
375
+ this.$$element[0].classList.remove(EMPTY_CLASS);
376
+ this.$$element[0].classList.add(PRISTINE_CLASS);
377
+ }
362
378
  },
363
379
 
364
380
  /**
@@ -375,8 +391,13 @@ NgModelController.prototype = {
375
391
  $setDirty() {
376
392
  this.$dirty = true;
377
393
  this.$pristine = false;
378
- this.$$animate.removeClass(this.$$element, PRISTINE_CLASS);
379
- this.$$animate.addClass(this.$$element, DIRTY_CLASS);
394
+ if (hasAnimate(this.$$element[0])) {
395
+ this.$$animate.removeClass(this.$$element, PRISTINE_CLASS);
396
+ this.$$animate.addClass(this.$$element, DIRTY_CLASS);
397
+ } else {
398
+ this.$$element[0].classList.remove(PRISTINE_CLASS);
399
+ this.$$element[0].classList.add(DIRTY_CLASS);
400
+ }
380
401
  this.$$parentForm.$setDirty();
381
402
  },
382
403
 
@@ -395,7 +416,12 @@ NgModelController.prototype = {
395
416
  $setUntouched() {
396
417
  this.$touched = false;
397
418
  this.$untouched = true;
398
- this.$$animate.setClass(this.$$element, UNTOUCHED_CLASS, TOUCHED_CLASS);
419
+ if (hasAnimate(this.$$element[0])) {
420
+ this.$$animate.setClass(this.$$element, UNTOUCHED_CLASS, TOUCHED_CLASS);
421
+ } else {
422
+ this.$$element[0].classList.remove(TOUCHED_CLASS);
423
+ this.$$element[0].classList.add(UNTOUCHED_CLASS);
424
+ }
399
425
  },
400
426
 
401
427
  /**
@@ -412,7 +438,12 @@ NgModelController.prototype = {
412
438
  $setTouched() {
413
439
  this.$touched = true;
414
440
  this.$untouched = false;
415
- this.$$animate.setClass(this.$$element, TOUCHED_CLASS, UNTOUCHED_CLASS);
441
+ if (hasAnimate(this.$$element[0])) {
442
+ this.$$animate.setClass(this.$$element, TOUCHED_CLASS, UNTOUCHED_CLASS);
443
+ } else {
444
+ this.$$element[0].classList.remove(UNTOUCHED_CLASS);
445
+ this.$$element[0].classList.add(TOUCHED_CLASS);
446
+ }
416
447
  },
417
448
 
418
449
  /**
@@ -1209,7 +1209,7 @@ export function startingTag(elementStr) {
1209
1209
 
1210
1210
  /**
1211
1211
  * Return the DOM siblings between the first and last node in the given array.
1212
- * @param {Array} nodes An array-like object
1212
+ * @param {JQLite|Array} nodes An array-like object
1213
1213
  * @returns {JQLite} the inputted object or a JQLite collection containing the nodes
1214
1214
  */
1215
1215
  export function getBlockNodes(nodes) {
@@ -1,6 +1,6 @@
1
1
  export function $AnimateCssProvider(): void;
2
2
  export class $AnimateCssProvider {
3
- $get: (string | (($$AnimateRunner: any, $timeout: any, $$animateCache: any, $$rAFScheduler: any, $$animateQueue: any) => (element: any, initialOptions: any) => {
3
+ $get: (string | (($$AnimateRunner: any, $timeout: any, $$animateCache: any, $$rAFScheduler: import("./raf-scheduler").RafScheduler, $$animateQueue: any) => (element: any, initialOptions: any) => {
4
4
  $$willAnimate: boolean;
5
5
  start(): any;
6
6
  end: () => void;
@@ -1,5 +1,5 @@
1
1
  export function $$AnimationProvider(): void;
2
2
  export class $$AnimationProvider {
3
3
  drivers: any[];
4
- $get: (string | (($rootScope: any, $injector: any, $$AnimateRunner: any, $$rAFScheduler: any, $$animateCache: any) => (element: any, event: any, options: any) => any))[];
4
+ $get: (string | (($rootScope: any, $injector: any, $$AnimateRunner: any, $$rAFScheduler: import("./raf-scheduler").RafScheduler, $$animateCache: any) => (element: any, event: any, options: any) => any))[];
5
5
  }
@@ -1,5 +1,19 @@
1
- export const $$rAFSchedulerFactory: (() => {
2
- (tasks: any): void;
3
- queue: any[];
4
- waitUntilQuiet(fn: any): void;
5
- })[];
1
+ /**
2
+ * @typedef {Function} RafSchedulerFunction
3
+ * @typedef {Object} RafSchedulerObject
4
+ * @property {Function} waitUntilQuiet - Function to wait until the animation frame is quiet.
5
+ * @typedef {RafSchedulerObject & RafSchedulerFunction} RafScheduler
6
+ */
7
+ /**
8
+ * Creates a requestAnimationFrame scheduler.
9
+ * @returns {RafScheduler} The scheduler object.
10
+ */
11
+ export function $$rAFSchedulerFactory(): RafScheduler;
12
+ export type RafSchedulerFunction = Function;
13
+ export type RafSchedulerObject = {
14
+ /**
15
+ * - Function to wait until the animation frame is quiet.
16
+ */
17
+ waitUntilQuiet: Function;
18
+ };
19
+ export type RafScheduler = RafSchedulerObject & RafSchedulerFunction;
@@ -8,7 +8,7 @@
8
8
  * @property {function(any, any): any} assign - Assigns a value to a context. If value is not provided,
9
9
  */
10
10
  /**
11
- * @typedef {function } CompiledExpressionFunction
11
+ * @typedef {function} CompiledExpressionFunction
12
12
  * @param {import('../scope/scope').Scope} context - An object against which any expressions embedded in the strings are evaluated against (typically a scope object).
13
13
  * @param {object} [locals] - local variables context object, useful for overriding values in `context`.
14
14
  * @param {any} [assign]
@@ -1,11 +1,10 @@
1
- export function ngIfDirective($animate: any): {
2
- multiElement: boolean;
3
- transclude: string;
4
- priority: number;
5
- terminal: boolean;
6
- restrict: string;
7
- link($scope: any, $element: any, $attr: any, _ctrl: any, $transclude: any): void;
8
- };
1
+ /**
2
+ *
3
+ * TODO // Add type for animate service
4
+ * @param {*} $animate
5
+ * @returns {import("../../types").Directive}
6
+ */
7
+ export function ngIfDirective($animate: any): import("../../types").Directive;
9
8
  export namespace ngIfDirective {
10
9
  let $inject: string[];
11
10
  }
@@ -193,10 +193,10 @@ export function removeElement(element: Element, keepData?: boolean): void;
193
193
  export function startingTag(elementStr: string): string;
194
194
  /**
195
195
  * Return the DOM siblings between the first and last node in the given array.
196
- * @param {Array} nodes An array-like object
196
+ * @param {JQLite|Array} nodes An array-like object
197
197
  * @returns {JQLite} the inputted object or a JQLite collection containing the nodes
198
198
  */
199
- export function getBlockNodes(nodes: any[]): JQLite;
199
+ export function getBlockNodes(nodes: JQLite | any[]): JQLite;
200
200
  export function getBooleanAttrName(element: any, name: any): any;
201
201
  /**
202
202
  * Takes an array of elements, calls any `$destroy` event handlers, removes any data in cache, and finally removes any